PageRenderTime 62ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/admincp/post_thanks_admin.php

https://gitlab.com/elasa/vb-elasa.ir
PHP | 359 lines | 272 code | 71 blank | 16 comment | 34 complexity | 0c8fc7a06e984dd276a4503fa5484c3b MD5 | raw file
  1. <?php
  2. /*======================================*\
  3. || #################################### ||
  4. || # Post Thank You Hack version 7.83 # ||
  5. || # Original version by Abe1 # ||
  6. || # Updated by Phaedrus # ||
  7. || #################################### ||
  8. \*======================================*/
  9. // ######################## SET PHP ENVIRONMENT ###########################
  10. error_reporting(E_ALL & ~E_NOTICE);
  11. @set_time_limit(0);
  12. ignore_user_abort(1);
  13. // ##################### DEFINE IMPORTANT CONSTANTS #######################
  14. // #################### PRE-CACHE TEMPLATES AND DATA ######################
  15. $phrasegroups = array('maintenance');
  16. // ########################## REQUIRE BACK-END ############################
  17. require_once('./global.php');
  18. require_once(DIR . '/includes/functions_post_thanks.php');
  19. // ######################## CHECK ADMIN PERMISSIONS #######################
  20. if (!can_administer('canadminthreads'))
  21. {
  22. print_cp_no_permission();
  23. }
  24. // ############################# LOG ACTION ###############################
  25. log_admin_action();
  26. // ########################################################################
  27. // ######################### START MAIN SCRIPT ############################
  28. // ########################################################################
  29. print_cp_header($vbphrase['maintenance']);
  30. if (empty($_REQUEST['do']))
  31. {
  32. $_REQUEST['do'] = 'recounters';
  33. }
  34. $vbulletin->input->clean_array_gpc('r', array(
  35. 'perpage' => TYPE_UINT,
  36. 'startat' => TYPE_UINT
  37. ));
  38. ($hook = vBulletinHook::fetch_hook('post_thanks_admin_start')) ? eval($hook) : false;
  39. if ($_REQUEST['do'] == 'recounters')
  40. {
  41. ($hook = vBulletinHook::fetch_hook('post_thanks_admin_recounters_start')) ? eval($hook) : false;
  42. print_form_header('post_thanks_admin', 'post_thanks_user_amount');
  43. print_table_header($vbphrase['post_thanks_user_amount'], 2, 0);
  44. print_description_row($vbphrase['post_thanks_user_amount_help']);
  45. print_input_row($vbphrase['number_of_users_to_process_per_cycle'], 'perpage', 1000);
  46. print_submit_row($vbphrase['post_thanks_user_amount']);
  47. print_form_header('post_thanks_admin', 'post_thanks_thanked_posts');
  48. print_table_header($vbphrase['post_thanks_thanked_posts'], 2, 0);
  49. print_description_row($vbphrase['post_thanks_thanked_posts_help']);
  50. print_input_row($vbphrase['number_of_users_to_process_per_cycle'], 'perpage', 1000);
  51. print_submit_row($vbphrase['post_thanks_thanked_posts']);
  52. print_form_header('post_thanks_admin', 'post_thanks_thanked_times');
  53. print_table_header($vbphrase['post_thanks_thanked_times'], 2, 0);
  54. print_description_row($vbphrase['post_thanks_thanked_times_help']);
  55. print_input_row($vbphrase['number_of_users_to_process_per_cycle'], 'perpage', 1000);
  56. print_submit_row($vbphrase['post_thanks_thanked_times']);
  57. print_form_header('post_thanks_admin', 'post_thanks_post_amount');
  58. print_table_header($vbphrase['post_thanks_post_amount'], 2, 0);
  59. print_description_row($vbphrase['post_thanks_post_amount_help']);
  60. print_input_row($vbphrase['number_of_posts_to_process_per_cycle'], 'perpage', 1000);
  61. print_submit_row($vbphrase['post_thanks_post_amount']);
  62. ($hook = vBulletinHook::fetch_hook('post_thanks_admin_recounters_end')) ? eval($hook) : false;
  63. }
  64. if ($_REQUEST['do'] == 'post_thanks_user_amount')
  65. {
  66. if (empty($vbulletin->GPC['perpage']))
  67. {
  68. $vbulletin->GPC['perpage'] = 1000;
  69. }
  70. $finishat = $vbulletin->GPC['startat'] + $vbulletin->GPC['perpage'];
  71. ($hook = vBulletinHook::fetch_hook('post_thanks_admin_user_amount_start')) ? eval($hook) : false;
  72. echo '<p>' . $vbphrase['post_thanks_user_amount'] . '</p>';
  73. $users = $db->query_read("
  74. SELECT *
  75. FROM " . TABLE_PREFIX . "user
  76. WHERE userid >= " . $vbulletin->GPC['startat'] . " AND userid < $finishat
  77. ORDER BY userid
  78. ");
  79. while ($user = $db->fetch_array($users))
  80. {
  81. $total = $db->query_first("
  82. SELECT COUNT(*) AS post_thanks_user_amount FROM " . TABLE_PREFIX . "post_thanks
  83. WHERE userid = $user[userid]
  84. ");
  85. if (!($total[post_thanks_user_amount]))
  86. {
  87. $total[post_thanks_user_amount] = 0;
  88. }
  89. $db->query_write("
  90. UPDATE " . TABLE_PREFIX . "user
  91. SET post_thanks_user_amount = $total[post_thanks_user_amount]
  92. WHERE userid = $user[userid]
  93. ");
  94. echo construct_phrase($vbphrase['processing_x'], $user['userid']) . "<br />\n";
  95. vbflush();
  96. }
  97. ($hook = vBulletinHook::fetch_hook('post_thanks_admin_user_amount_end')) ? eval($hook) : false;
  98. if ($checkmore = $db->query_first("SELECT userid FROM " . TABLE_PREFIX . "user WHERE userid >= $finishat LIMIT 1"))
  99. {
  100. print_cp_redirect("post_thanks_admin.php?" . $vbulletin->session->vars['sessionurl'] . "do=post_thanks_user_amount&startat=$finishat&pp=" . $vbulletin->GPC['perpage']);
  101. echo "<p><a href=\"post_thanks_admin.php?" . $vbulletin->session->vars['sessionurl'] . "do=post_thanks_user_amount&amp;startat=$finishat&amp;pp=" . $vbulletin->GPC['perpage'] . "\">" . $vbphrase['click_here_to_continue_processing'] . "</a></p>";
  102. }
  103. else
  104. {
  105. define('CP_REDIRECT', 'post_thanks_admin.php');
  106. print_stop_message('updated_post_counts_successfully');
  107. }
  108. }
  109. if ($_REQUEST['do'] == 'post_thanks_thanked_posts')
  110. {
  111. if (empty($vbulletin->GPC['perpage']))
  112. {
  113. $vbulletin->GPC['perpage'] = 1000;
  114. }
  115. $finishat = $vbulletin->GPC['startat'] + $vbulletin->GPC['perpage'];
  116. ($hook = vBulletinHook::fetch_hook('post_thanks_admin_thanked_posts_start')) ? eval($hook) : false;
  117. echo '<p>' . $vbphrase['post_thanks_thanked_posts'] . '</p>';
  118. $users = $db->query_read("
  119. SELECT *
  120. FROM " . TABLE_PREFIX . "user
  121. WHERE userid >= " . $vbulletin->GPC['startat'] . " AND userid < $finishat
  122. ORDER BY userid
  123. ");
  124. while ($user = $db->fetch_array($users))
  125. {
  126. $total = $db->query_first("
  127. SELECT COUNT(*) AS post_thanks_thanked_posts FROM " . TABLE_PREFIX . "post
  128. WHERE userid = $user[userid] AND post_thanks_amount > 0
  129. ");
  130. if (!($total[post_thanks_thanked_posts]))
  131. {
  132. $total[post_thanks_thanked_posts] = 0;
  133. }
  134. $db->query_write("
  135. UPDATE " . TABLE_PREFIX . "user
  136. SET post_thanks_thanked_posts = $total[post_thanks_thanked_posts]
  137. WHERE userid = $user[userid]
  138. ");
  139. echo construct_phrase($vbphrase['processing_x'], $user['userid']) . "<br />\n";
  140. vbflush();
  141. }
  142. ($hook = vBulletinHook::fetch_hook('post_thanks_admin_thanked_posts_end')) ? eval($hook) : false;
  143. if ($checkmore = $db->query_first("SELECT userid FROM " . TABLE_PREFIX . "user WHERE userid >= $finishat LIMIT 1"))
  144. {
  145. print_cp_redirect("post_thanks_admin.php?" . $vbulletin->session->vars['sessionurl'] . "do=post_thanks_thanked_posts&startat=$finishat&pp=" . $vbulletin->GPC['perpage']);
  146. echo "<p><a href=\"post_thanks_admin.php?" . $vbulletin->session->vars['sessionurl'] . "do=post_thanks_thanked_posts&amp;startat=$finishat&amp;pp=" . $vbulletin->GPC['perpage'] . "\">" . $vbphrase['click_here_to_continue_processing'] . "</a></p>";
  147. }
  148. else
  149. {
  150. define('CP_REDIRECT', 'post_thanks_admin.php');
  151. print_stop_message('updated_post_counts_successfully');
  152. }
  153. }
  154. if ($_REQUEST['do'] == 'post_thanks_thanked_times')
  155. {
  156. if (empty($vbulletin->GPC['perpage']))
  157. {
  158. $vbulletin->GPC['perpage'] = 1000;
  159. }
  160. $finishat = $vbulletin->GPC['startat'] + $vbulletin->GPC['perpage'];
  161. ($hook = vBulletinHook::fetch_hook('post_thanks_admin_thanked_times_start')) ? eval($hook) : false;
  162. echo '<p>' . $vbphrase['post_thanks_thanked_times'] . '</p>';
  163. $users = $db->query_read("
  164. SELECT *
  165. FROM " . TABLE_PREFIX . "user
  166. WHERE userid >= " . $vbulletin->GPC['startat'] . " AND userid < $finishat
  167. ORDER BY userid
  168. ");
  169. while ($user = $db->fetch_array($users))
  170. {
  171. $total = $db->query_first("
  172. SELECT SUM(post_thanks_amount) AS post_thanks_thanked_times FROM " . TABLE_PREFIX . "post
  173. WHERE userid = $user[userid] AND post_thanks_amount > 0
  174. ");
  175. if (!($total[post_thanks_thanked_times]))
  176. {
  177. $total[post_thanks_thanked_times] = 0;
  178. }
  179. $db->query_write("
  180. UPDATE " . TABLE_PREFIX . "user
  181. SET post_thanks_thanked_times = $total[post_thanks_thanked_times]
  182. WHERE userid = $user[userid]
  183. ");
  184. echo construct_phrase($vbphrase['processing_x'], $user['userid']) . "<br />\n";
  185. vbflush();
  186. }
  187. ($hook = vBulletinHook::fetch_hook('post_thanks_admin_thanked_times_end')) ? eval($hook) : false;
  188. if ($checkmore = $db->query_first("SELECT userid FROM " . TABLE_PREFIX . "user WHERE userid >= $finishat LIMIT 1"))
  189. {
  190. print_cp_redirect("post_thanks_admin.php?" . $vbulletin->session->vars['sessionurl'] . "do=post_thanks_thanked_times&startat=$finishat&pp=" . $vbulletin->GPC['perpage']);
  191. echo "<p><a href=\"post_thanks_admin.php?" . $vbulletin->session->vars['sessionurl'] . "do=post_thanks_thanked_times&amp;startat=$finishat&amp;pp=" . $vbulletin->GPC['perpage'] . "\">" . $vbphrase['click_here_to_continue_processing'] . "</a></p>";
  192. }
  193. else
  194. {
  195. define('CP_REDIRECT', 'post_thanks_admin.php');
  196. print_stop_message('updated_post_counts_successfully');
  197. }
  198. }
  199. if ($_REQUEST['do'] == 'post_thanks_post_amount')
  200. {
  201. if (empty($vbulletin->GPC['perpage']))
  202. {
  203. $vbulletin->GPC['perpage'] = 1000;
  204. }
  205. $finishat = $vbulletin->GPC['startat'] + $vbulletin->GPC['perpage'];
  206. ($hook = vBulletinHook::fetch_hook('post_thanks_admin_post_amount_start')) ? eval($hook) : false;
  207. echo '<p>' . $vbphrase['post_thanks_post_amount'] . '</p>';
  208. $posts = $db->query_read("
  209. SELECT *
  210. FROM " . TABLE_PREFIX . "post
  211. WHERE postid >= " . $vbulletin->GPC['startat'] . " AND postid < $finishat
  212. ORDER BY postid
  213. ");
  214. while ($post = $db->fetch_array($posts))
  215. {
  216. $total = $db->query_first("
  217. SELECT COUNT(*) AS post_thanks_amount FROM " . TABLE_PREFIX . "post_thanks
  218. WHERE postid = $post[postid]
  219. ");
  220. if (!($total[post_thanks_amount]))
  221. {
  222. $total[post_thanks_amount] = 0;
  223. }
  224. $db->query_write("
  225. UPDATE " . TABLE_PREFIX . "post
  226. SET post_thanks_amount = $total[post_thanks_amount]
  227. WHERE postid = $post[postid]
  228. ");
  229. echo construct_phrase($vbphrase['processing_x'], $post['postid']) . "<br />\n";
  230. vbflush();
  231. }
  232. ($hook = vBulletinHook::fetch_hook('post_thanks_admin_post_amount_end')) ? eval($hook) : false;
  233. if ($checkmore = $db->query_first("SELECT postid FROM " . TABLE_PREFIX . "post WHERE postid >= $finishat LIMIT 1"))
  234. {
  235. print_cp_redirect("post_thanks_admin.php?" . $vbulletin->session->vars['sessionurl'] . "do=post_thanks_post_amount&startat=$finishat&pp=" . $vbulletin->GPC['perpage']);
  236. echo "<p><a href=\"post_thanks_admin.php?" . $vbulletin->session->vars['sessionurl'] . "do=post_thanks_post_amount&amp;startat=$finishat&amp;pp=" . $vbulletin->GPC['perpage'] . "\">" . $vbphrase['click_here_to_continue_processing'] . "</a></p>";
  237. }
  238. else
  239. {
  240. define('CP_REDIRECT', 'post_thanks_admin.php');
  241. print_stop_message('updated_post_counts_successfully');
  242. }
  243. }
  244. if ($_REQUEST['do'] == 'special_actions')
  245. {
  246. ($hook = vBulletinHook::fetch_hook('post_thanks_admin_special_actions_start')) ? eval($hook) : false;
  247. print_form_header('post_thanks_admin', 'delete_all_users_thanks');
  248. print_table_header($vbphrase['post_thanks_delete_all_users_thanks'], 2, 0);
  249. print_description_row($vbphrase['post_thanks_delete_all_users_thanks_help']);
  250. print_input_row($vbphrase['userid'], 'userid');
  251. print_submit_row($vbphrase['post_thanks_delete_all_users_thanks']);
  252. ($hook = vBulletinHook::fetch_hook('post_thanks_admin_special_actions_end')) ? eval($hook) : false;
  253. }
  254. if ($_REQUEST['do'] == 'delete_all_users_thanks')
  255. {
  256. $vbulletin->input->clean_array_gpc('r', array(
  257. 'userid' => TYPE_UINT
  258. ));
  259. $userid = $vbulletin->GPC['userid'];
  260. ($hook = vBulletinHook::fetch_hook('post_thanks_admin_delete_all_users_thanks_start')) ? eval($hook) : false;
  261. echo '<p>' . $vbphrase['post_thanks_delete_all_users_thanks'] . '</p>';
  262. $thanks = $db->query_read("
  263. SELECT *
  264. FROM " . TABLE_PREFIX . "post_thanks
  265. WHERE userid = $userid
  266. ORDER BY postid
  267. ");
  268. while ($thank = $db->fetch_array($thanks))
  269. {
  270. $postinfo = fetch_postinfo($thank['postid']);
  271. if ($postinfo === false)
  272. {
  273. $vbulletin->db->query_write("DELETE FROM ". TABLE_PREFIX ."post_thanks WHERE postid = '$thank[postid]' AND userid = '$userid'");
  274. }
  275. else
  276. {
  277. delete_thanks($postinfo, $userid);
  278. }
  279. echo construct_phrase($vbphrase['processing_x'], $thank['postid']) . "<br />\n";
  280. vbflush();
  281. }
  282. ($hook = vBulletinHook::fetch_hook('post_thanks_admin_delete_all_users_thanks_end')) ? eval($hook) : false;
  283. define('CP_REDIRECT', 'post_thanks_admin.php?do=special_actions');
  284. print_stop_message('post_thanks_delete_all_users_thanks_successfully');
  285. }
  286. ($hook = vBulletinHook::fetch_hook('post_thanks_admin_end')) ? eval($hook) : false;
  287. print_cp_footer();
  288. ?>