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