Please select To the mobile version | Continue to access the desktop computer version
| |
| | |

CodersClub

 Forgot password?
 Register
Search
View: 4977|Reply: 4
Collapse the left

[Usage] How to add discuz thread views randomly

[Copy link]
Post time: 2019-03-27 06:05
| Show all posts |Read mode
本帖最后由 roxmake 于 2019-3-27 06:07 编辑

Find: the source/module/forum/forum_viewthread.php file
Search code:
  1. function viewthread_updateviews($tableid)
Copy the Code
Find the code:
  1. function viewthread_updateviews($tableid) {
  2.         global $_G;
  3.         if(!$_G['setting']['preventrefresh'] || $_G['cookie']['viewid'] != 'tid_'.$_G['tid']) {
  4.                 if(!$tableid && $_G['setting']['optimizeviews']) {
  5.                         if($_G['forum_thread']['addviews']) {
  6.                                 if($_G['forum_thread']['addviews'] < 100) {
  7.                                         C::t('forum_threadaddviews')->update_by_tid($_G['tid']);
  8.                                 } else {
  9.                                         if(!discuz_process::islocked('update_thread_view')) {
  10.                                                 $row = C::t('forum_threadaddviews')->fetch($_G['tid']);
  11.                                                 C::t('forum_threadaddviews')->update($_G['tid'], array('addviews' => 0));
  12.                                                 C::t('forum_thread')->increase($_G['tid'], array('views' => $row['addviews']+1), true);
  13.                                                 discuz_process::unlock('update_thread_view');
  14.                                         }
  15.                                 }
  16.                         } else {
  17.                                 C::t('forum_threadaddviews')->insert(array('tid' => $_G['tid'], 'addviews' => 1), false, true);
  18.                         }
  19.                 } else {
  20.                         C::t('forum_thread')->increase($_G['tid'], array('views' => 1), true, $tableid);
  21.                 }
  22.         }
  23.         dsetcookie('viewid', 'tid_'.$_G['tid']);
  24. }
Copy the Code
Modify to:
  1. function viewthread_updateviews($tableid) {
  2.         global $_G;
  3.         $viewrand = rand(2,10);
  4.         if(!$_G['setting']['preventrefresh'] || $_G['cookie']['viewid'] != 'tid_'.$_G['tid']) {
  5.                 if(!$tableid && $_G['setting']['optimizeviews']) {
  6.                         if($_G['forum_thread']['addviews']) {
  7.                                 if($_G['forum_thread']['addviews'] < 100) {
  8.                                         C::t('forum_threadaddviews')->update_by_tid($_G['tid']);
  9.                                 } else {
  10.                                         if(!discuz_process::islocked('update_thread_view')) {
  11.                                                 $row = C::t('forum_threadaddviews')->fetch($_G['tid']);
  12.                                                 C::t('forum_threadaddviews')->update($_G['tid'], array('addviews' => $viewrand));
  13.                                                 C::t('forum_thread')->increase($_G['tid'], array('views' => $row['addviews']+$viewrand), true);
  14.                                                 discuz_process::unlock('update_thread_view');
  15.                                         }
  16.                                 }
  17.                         } else {
  18.                                 C::t('forum_threadaddviews')->insert(array('tid' => $_G['tid'], 'addviews' => $viewrand), false, true);
  19.                         }
  20.                 } else {
  21.                         C::t('forum_thread')->increase($_G['tid'], array('views' => $viewrand), true, $tableid);
  22.                 }
  23.         }
  24.         dsetcookie('viewid', 'tid_'.$_G['tid']);
  25. }
Copy the Code
The main changes are:
1. Create random number variables:

$viewrand = rand(2,10);

Rand (2,10) represents a random number between 2 and 10;

2. Modify the original update methods:
Respectively is:
  1. C::t('forum_thread')->increase($_G['tid'], array('views' => $row['addviews']+1), true);
  2. C::t('forum_threadaddviews')->insert(array('tid' => $_G['tid'], 'addviews' => 1), false, true);
  3. C::t('forum_thread')->increase($_G['tid'], array('views' => 1), true, $tableid);
Copy the Code

Modify to:
  1. C::t('forum_thread')->increase($_G['tid'], array('views' => $row['addviews']+$viewrand), true);
  2.   C::t('forum_threadaddviews')->insert(array('tid' => $_G['tid'], 'addviews' => $viewrand), false, true);
  3.   C::t('forum_thread')->increase($_G['tid'], array('views' => $viewrand), true, $tableid);
Copy the Code
Done!

 Russia

Post time: 2019-03-28 20:30
| Show all posts
I did not understand.
What is the goal of this modification?
 Author| Post time: 2019-03-29 08:20
| Show all posts
vot 2019-3-28 20:30
I did not understand.
What is the goal of this modification?


This post contains more resources

You have to Login for download or view attachment(s). No Account? Register

x
Post time: 2019-03-29 16:58
| Show all posts
Ah! Fake views!

 Russia

Post time: 2019-03-29 21:12
| Show all posts
Trump: Fake news again?
You have to log in before you can reply Login | Register

Points Rules

Archive|Mobile|Dark room|CodersClub

Top.Mail.Ru
Top.Mail.Ru

2024-03-28 11:28 GMT+3 , Processed in 0.056274 sec., 8 queries .

Powered by Discuz! X3.4 Release 20230520

© 2001-2024 Discuz! Team.

MultiLingual version, Rev. 4301, © codersclub.org

Quick Reply To Top Return to the list