Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. <?php
  2.  
  3. function rebuild_stats()
  4. {
  5. global $db;
  6.  
  7. $query = $db->simple_select("forums", "SUM(threads) AS numthreads");
  8. $stats['numthreads'] = $db->fetch_field($query, 'numthreads');
  9.  
  10. if(!$stats['numthreads'])
  11. {
  12. $stats['numthreads'] = 0;
  13. }
  14.  
  15. $query = $db->simple_select("forums", "SUM(posts) AS numposts");
  16. $stats['numposts'] = $db->fetch_field($query, 'numposts');
  17.  
  18. if(!$stats['numposts'])
  19. {
  20. $stats['numposts'] = 0;
  21. }
  22.  
  23. $query = $db->simple_select("forums", "SUM(unapprovedthreads) AS numunapprovedthreads");
  24. $stats['numunapprovedthreads'] = $db->fetch_field($query, 'numunapprovedthreads');
  25.  
  26. if(!$stats['numunapprovedthreads'])
  27. {
  28. $stats['numunapprovedthreads'] = 0;
  29. }
  30.  
  31. $query = $db->simple_select("forums", "SUM(unapprovedposts) AS numunapprovedposts");
  32. $stats['numunapprovedposts'] = $db->fetch_field($query, 'numunapprovedposts');
  33.  
  34. if(!$stats['numunapprovedposts'])
  35. {
  36. $stats['numunapprovedposts'] = 0;
  37. }
  38.  
  39. $query = $db->simple_select("users", "COUNT(uid) AS users");
  40. $stats['numusers'] = $db->fetch_field($query, 'users');
  41.  
  42. if(!$stats['numusers'])
  43. {
  44. $stats['numusers'] = 0;
  45. }
  46.  
  47. update_stats($stats);
  48. }
  49.  
  50. function rebuild_forum_counters($fid)
  51. {
  52. global $db;
  53.  
  54. // Fetch the number of threads and replies in this forum (Approved only)
  55. $query = $db->query("
  56. SELECT COUNT(tid) AS threads, SUM(replies) AS replies
  57. FROM ".TABLE_PREFIX."threads
  58. WHERE fid='$fid' AND visible='1' AND closed NOT LIKE 'moved|%'
  59. ");
  60. $count = $db->fetch_array($query);
  61. $count['posts'] = $count['threads'] + $count['replies'];
  62.  
  63. if(!$count['posts'])
  64. {
  65. $count['posts'] = 0;
  66. }
  67.  
  68. // Fetch the number of threads and replies in this forum (Unapproved only)
  69. $query = $db->query("
  70. SELECT COUNT(tid) AS threads, SUM(replies) AS impliedunapproved
  71. FROM ".TABLE_PREFIX."threads
  72. WHERE fid='$fid' AND visible='0' AND closed NOT LIKE 'moved|%'
  73. ");
  74. $count2 = $db->fetch_array($query);
  75. $count['unapprovedthreads'] = $count2['threads'];
  76. $count['unapprovedposts'] = $count2['impliedunapproved']+$count2['threads'];
  77.  
  78. if(!$count['unapprovedthreads'])
  79. {
  80. $count['unapprovedthreads'] = 0;
  81. }
  82.  
  83. $query = $db->query("
  84. SELECT SUM(unapprovedposts) AS posts
  85. FROM ".TABLE_PREFIX."threads
  86. WHERE fid='$fid' AND closed NOT LIKE 'moved|%'
  87. ");
  88. $count['unapprovedposts'] += $db->fetch_field($query, "posts");
  89.  
  90. if(!$count['unapprovedposts'])
  91. {
  92. $count['unapprovedposts'] = 0;
  93. }
  94.  
  95. update_forum_counters($fid, $count);
  96. }
  97.  
  98. function rebuild_thread_counters($tid)
  99. {
  100. global $db;
  101.  
  102. if(!$thread['tid'])
  103. {
  104. $thread = get_thread($tid);
  105. }
  106.  
  107. $query = $db->simple_select("posts", "COUNT(*) AS replies", "tid='{$tid}' AND pid!='{$thread['firstpost']}' AND visible='1'");
  108. $count['replies'] = $db->fetch_field($query, "replies");
  109. if($count['replies'] < 0)
  110. {
  111. $count['replies'] = 0;
  112. }
  113.  
  114. // Unapproved posts
  115. $query = $db->simple_select("posts", "COUNT(pid) AS totunposts", "tid='{$tid}' AND pid != '{$thread['firstpost']}' AND visible='0'");
  116. $count['unapprovedposts'] = $db->fetch_field($query, "totunposts");
  117.  
  118. if(!$count['unapprovedposts'])
  119. {
  120. $count['unapprovedposts'] = 0;
  121. }
  122.  
  123. // Attachment count
  124. $query = $db->query("
  125. SELECT COUNT(aid) AS attachment_count
  126. FROM ".TABLE_PREFIX."attachments a
  127. LEFT JOIN ".TABLE_PREFIX."posts p ON (a.pid=p.pid)
  128. WHERE p.tid='$tid'
  129. ");
  130. $count['attachmentcount'] = $db->fetch_field($query, "attachment_count");
  131.  
  132. if(!$count['attachmentcount'])
  133. {
  134. $count['attachmentcount'] = 0;
  135. }
  136.  
  137. update_thread_counters($tid, $count);
  138. }
  139. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement