PageRenderTime 27ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Upload/admin/modules/tools/recount_rebuild.php

https://gitlab.com/mybbpl/ppm-1.6
PHP | 339 lines | 261 code | 63 blank | 15 comment | 39 complexity | bebdf1c79eda9079e74e93024027883c MD5 | raw file
  1. <?php
  2. /**
  3. * MyBB 1.6
  4. * Copyright 2010 MyBB Group, All Rights Reserved
  5. *
  6. * Website: http://mybb.com
  7. * License: http://mybb.com/about/license
  8. *
  9. * $Id$
  10. */
  11. // Disallow direct access to this file for security reasons
  12. if(!defined("IN_MYBB"))
  13. {
  14. die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
  15. }
  16. $page->add_breadcrumb_item($lang->recount_rebuild, "index.php?module=tools-recount_rebuild");
  17. $plugins->run_hooks("admin_tools_recount_rebuild");
  18. function acp_rebuild_forum_counters()
  19. {
  20. global $db, $mybb, $lang;
  21. $query = $db->simple_select("forums", "COUNT(*) as num_forums");
  22. $num_forums = $db->fetch_field($query, 'num_forums');
  23. $page = intval($mybb->input['page']);
  24. $per_page = intval($mybb->input['forumcounters']);
  25. if($per_page <= 0)
  26. {
  27. $per_page = 50;
  28. }
  29. $start = ($page-1) * $per_page;
  30. $end = $start + $per_page;
  31. $query = $db->simple_select("forums", "fid", '', array('order_by' => 'fid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
  32. while($forum = $db->fetch_array($query))
  33. {
  34. $update['parentlist'] = make_parent_list($forum['fid']);
  35. $db->update_query("forums", $update, "fid='{$forum['fid']}'");
  36. rebuild_forum_counters($forum['fid']);
  37. }
  38. check_proceed($num_forums, $end, ++$page, $per_page, "forumcounters", "do_rebuildforumcounters", $lang->success_rebuilt_forum_counters);
  39. }
  40. function acp_rebuild_thread_counters()
  41. {
  42. global $db, $mybb, $lang;
  43. $query = $db->simple_select("threads", "COUNT(*) as num_threads");
  44. $num_threads = $db->fetch_field($query, 'num_threads');
  45. $page = intval($mybb->input['page']);
  46. $per_page = intval($mybb->input['threadcounters']);
  47. if($per_page <= 0)
  48. {
  49. $per_page = 500;
  50. }
  51. $start = ($page-1) * $per_page;
  52. $end = $start + $per_page;
  53. $query = $db->simple_select("threads", "tid", '', array('order_by' => 'tid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
  54. while($thread = $db->fetch_array($query))
  55. {
  56. rebuild_thread_counters($thread['tid']);
  57. }
  58. check_proceed($num_threads, $end, ++$page, $per_page, "threadcounters", "do_rebuildthreadcounters", $lang->success_rebuilt_thread_counters);
  59. }
  60. function acp_recount_user_posts()
  61. {
  62. global $db, $mybb, $lang;
  63. $query = $db->simple_select("users", "COUNT(uid) as num_users");
  64. $num_users = $db->fetch_field($query, 'num_users');
  65. $page = intval($mybb->input['page']);
  66. $per_page = intval($mybb->input['userposts']);
  67. if($per_page <= 0)
  68. {
  69. $per_page = 500;
  70. }
  71. $start = ($page-1) * $per_page;
  72. $end = $start + $per_page;
  73. $query = $db->simple_select("forums", "fid", "usepostcounts = 0");
  74. while($forum = $db->fetch_array($query))
  75. {
  76. $fids[] = $forum['fid'];
  77. }
  78. if(is_array($fids))
  79. {
  80. $fids = implode(',', $fids);
  81. }
  82. if($fids)
  83. {
  84. $fids = " AND p.fid NOT IN($fids)";
  85. }
  86. else
  87. {
  88. $fids = "";
  89. }
  90. $query = $db->simple_select("users", "uid", '', array('order_by' => 'uid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
  91. while($user = $db->fetch_array($query))
  92. {
  93. $query2 = $db->query("
  94. SELECT COUNT(p.pid) AS post_count
  95. FROM ".TABLE_PREFIX."posts p
  96. LEFT JOIN ".TABLE_PREFIX."threads t ON (t.tid=p.tid)
  97. WHERE p.uid='{$user['uid']}' AND t.visible > 0 AND p.visible > 0{$fids}
  98. ");
  99. $num_posts = $db->fetch_field($query2, "post_count");
  100. $db->update_query("users", array("postnum" => intval($num_posts)), "uid='{$user['uid']}'");
  101. }
  102. check_proceed($num_users, $end, ++$page, $per_page, "userposts", "do_recountuserposts", $lang->success_rebuilt_user_counters);
  103. }
  104. function acp_rebuild_attachment_thumbnails()
  105. {
  106. global $db, $mybb, $lang;
  107. $query = $db->simple_select("attachments", "COUNT(aid) as num_attachments");
  108. $num_attachments = $db->fetch_field($query, 'num_attachments');
  109. $page = intval($mybb->input['page']);
  110. $per_page = intval($mybb->input['attachmentthumbs']);
  111. if($per_page <= 0)
  112. {
  113. $per_page = 20;
  114. }
  115. $start = ($page-1) * $per_page;
  116. $end = $start + $per_page;
  117. require_once MYBB_ROOT."inc/functions_image.php";
  118. $query = $db->simple_select("attachments", "*", '', array('order_by' => 'aid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));
  119. while($attachment = $db->fetch_array($query))
  120. {
  121. $ext = my_strtolower(my_substr(strrchr($attachment['filename'], "."), 1));
  122. if($ext == "gif" || $ext == "png" || $ext == "jpg" || $ext == "jpeg" || $ext == "jpe")
  123. {
  124. $thumbname = str_replace(".attach", "_thumb.$ext", $attachment['attachname']);
  125. $thumbnail = generate_thumbnail(MYBB_ROOT."uploads/".$attachment['attachname'], MYBB_ROOT."uploads/", $thumbname, $mybb->settings['attachthumbh'], $mybb->settings['attachthumbw']);
  126. if($thumbnail['code'] == 4)
  127. {
  128. $thumbnail['filename'] = "SMALL";
  129. }
  130. $db->update_query("attachments", array("thumbnail" => $thumbnail['filename']), "aid='{$attachment['aid']}'");
  131. }
  132. }
  133. check_proceed($num_attachments, $end, ++$page, $per_page, "attachmentthumbs", "do_rebuildattachmentthumbs", $lang->success_rebuilt_attachment_thumbnails);
  134. }
  135. function check_proceed($current, $finish, $next_page, $per_page, $name, $name2, $message)
  136. {
  137. global $page, $lang, $plugins;
  138. if($finish >= $current)
  139. {
  140. flash_message($message, 'success');
  141. admin_redirect("index.php?module=tools-recount_rebuild");
  142. }
  143. else
  144. {
  145. $page->output_header();
  146. $form = new Form("index.php?module=tools-recount_rebuild", 'post');
  147. echo $form->generate_hidden_field("page", $next_page);
  148. echo $form->generate_hidden_field($name, $per_page);
  149. echo $form->generate_hidden_field($name2, $lang->go);
  150. echo "<div class=\"confirm_action\">\n";
  151. echo "<p>{$lang->confirm_proceed_rebuild}</p>\n";
  152. echo "<br />\n";
  153. echo "<script type=\"text/javascript\">window.onload = function() { var button = $$('#proceed_button'); if(button[0]) { button[0].value = '{$lang->automatically_redirecting}'; button[0].disabled = true; button[0].style.color = '#aaa'; button[0].style.borderColor = '#aaa'; document.forms[0].submit(); }}</script>";
  154. echo "<p class=\"buttons\">\n";
  155. echo $form->generate_submit_button($lang->proceed, array('class' => 'button_yes', 'id' => 'proceed_button'));
  156. echo "</p>\n";
  157. echo "</div>\n";
  158. $form->end();
  159. $page->output_footer();
  160. exit;
  161. }
  162. }
  163. if(!$mybb->input['action'])
  164. {
  165. $plugins->run_hooks("admin_tools_recount_rebuild_start");
  166. if($mybb->request_method == "post")
  167. {
  168. require_once MYBB_ROOT."inc/functions_rebuild.php";
  169. if(!isset($mybb->input['page']) || intval($mybb->input['page']) < 1)
  170. {
  171. $mybb->input['page'] = 1;
  172. }
  173. if(isset($mybb->input['do_rebuildforumcounters']))
  174. {
  175. $plugins->run_hooks("admin_tools_recount_rebuild_forum_counters");
  176. if($mybb->input['page'] == 1)
  177. {
  178. // Log admin action
  179. log_admin_action("forum");
  180. }
  181. if(!intval($mybb->input['forumcounters']))
  182. {
  183. $mybb->input['forumcounters'] = 50;
  184. }
  185. acp_rebuild_forum_counters();
  186. }
  187. elseif(isset($mybb->input['do_rebuildthreadcounters']))
  188. {
  189. $plugins->run_hooks("admin_tools_recount_rebuild_thread_counters");
  190. if($mybb->input['page'] == 1)
  191. {
  192. // Log admin action
  193. log_admin_action("thread");
  194. }
  195. if(!intval($mybb->input['threadcounters']))
  196. {
  197. $mybb->input['threadcounters'] = 500;
  198. }
  199. acp_rebuild_thread_counters();
  200. }
  201. elseif(isset($mybb->input['do_recountuserposts']))
  202. {
  203. $plugins->run_hooks("admin_tools_recount_rebuild_user_posts");
  204. if($mybb->input['page'] == 1)
  205. {
  206. // Log admin action
  207. log_admin_action("userposts");
  208. }
  209. if(!intval($mybb->input['userposts']))
  210. {
  211. $mybb->input['userposts'] = 500;
  212. }
  213. acp_recount_user_posts();
  214. }
  215. elseif(isset($mybb->input['do_rebuildattachmentthumbs']))
  216. {
  217. $plugins->run_hooks("admin_tools_recount_rebuild_attachment_thumbs");
  218. if($mybb->input['page'] == 1)
  219. {
  220. // Log admin action
  221. log_admin_action("attachmentthumbs");
  222. }
  223. if(!intval($mybb->input['attachmentthumbs']))
  224. {
  225. $mybb->input['attachmentthumbs'] = 500;
  226. }
  227. acp_rebuild_attachment_thumbnails();
  228. }
  229. else
  230. {
  231. $cache->update_stats();
  232. $plugins->run_hooks("admin_tools_recount_rebuild_stats");
  233. // Log admin action
  234. log_admin_action("stats");
  235. flash_message($lang->success_rebuilt_forum_stats, 'success');
  236. admin_redirect("index.php?module=tools-recount_rebuild");
  237. }
  238. }
  239. $page->output_header($lang->recount_rebuild);
  240. $sub_tabs['recount_rebuild'] = array(
  241. 'title' => $lang->recount_rebuild,
  242. 'link' => "index.php?module=tools-recount_rebuild",
  243. 'description' => $lang->recount_rebuild_desc
  244. );
  245. $page->output_nav_tabs($sub_tabs, 'recount_rebuild');
  246. $form = new Form("index.php?module=tools-recount_rebuild", "post");
  247. $form_container = new FormContainer($lang->recount_rebuild);
  248. $form_container->output_row_header($lang->name);
  249. $form_container->output_row_header($lang->data_per_page, array('width' => 50));
  250. $form_container->output_row_header("&nbsp;");
  251. $form_container->output_cell("<label>{$lang->rebuild_forum_counters}</label><div class=\"description\">{$lang->rebuild_forum_counters_desc}</div>");
  252. $form_container->output_cell($form->generate_text_box("forumcounters", 50, array('style' => 'width: 150px;')));
  253. $form_container->output_cell($form->generate_submit_button($lang->go, array("name" => "do_rebuildforumcounters")));
  254. $form_container->construct_row();
  255. $form_container->output_cell("<label>{$lang->rebuild_thread_counters}</label><div class=\"description\">{$lang->rebuild_thread_counters_desc}</div>");
  256. $form_container->output_cell($form->generate_text_box("threadcounters", 500, array('style' => 'width: 150px;')));
  257. $form_container->output_cell($form->generate_submit_button($lang->go, array("name" => "do_rebuildthreadcounters")));
  258. $form_container->construct_row();
  259. $form_container->output_cell("<label>{$lang->recount_user_posts}</label><div class=\"description\">{$lang->recount_user_posts_desc}</div>");
  260. $form_container->output_cell($form->generate_text_box("userposts", 500, array('style' => 'width: 150px;')));
  261. $form_container->output_cell($form->generate_submit_button($lang->go, array("name" => "do_recountuserposts")));
  262. $form_container->construct_row();
  263. $form_container->output_cell("<label>{$lang->rebuild_attachment_thumbs}</label><div class=\"description\">{$lang->rebuild_attachment_thumbs_desc}</div>");
  264. $form_container->output_cell($form->generate_text_box("attachmentthumbs", 20, array('style' => 'width: 150px;')));
  265. $form_container->output_cell($form->generate_submit_button($lang->go, array("name" => "do_rebuildattachmentthumbs")));
  266. $form_container->construct_row();
  267. $form_container->output_cell("<label>{$lang->recount_stats}</label><div class=\"description\">{$lang->recount_stats_desc}</div>");
  268. $form_container->output_cell($lang->na);
  269. $form_container->output_cell($form->generate_submit_button($lang->go, array("name" => "do_recountstats")));
  270. $form_container->construct_row();
  271. $plugins->run_hooks("admin_tools_recount_rebuild_output_list");
  272. $form_container->end();
  273. $form->end();
  274. $page->output_footer();
  275. }
  276. ?>