PageRenderTime 66ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/acp/acp_thanks.php

https://github.com/Vexilurz/phpbb_forum
PHP | 171 lines | 136 code | 22 blank | 13 comment | 18 complexity | 59f4173743a746b3606d749287b205ae MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package acp
  5. * @version $Id: acp_thanks.php,v 123 2009-06-11 10:02:51 Палыч$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. */
  9. /**
  10. * @ignore
  11. */
  12. if (!defined('IN_PHPBB'))
  13. {
  14. exit;
  15. }
  16. /**
  17. * @package acp
  18. */
  19. class acp_thanks
  20. {
  21. var $u_action;
  22. function main($id, $mode)
  23. {
  24. global $db, $user, $auth, $template;
  25. global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx;
  26. $config_vars = array(
  27. 'thanks_postlist_view' => 'THANKS_POSTLIST_VIEW',
  28. 'thanks_profilelist_view' => 'THANKS_PROFILELIST_VIEW',
  29. 'thanks_number' => 'THANKS_NUMBER',
  30. 'remove_thanks' => 'REMOVE_THANKS'
  31. );
  32. $this->tpl_name = 'acp_thanks';
  33. $this->page_title = 'ACP_THANKS';
  34. $form_key = 'acp_thanks';
  35. add_form_key($form_key);
  36. $submit = request_var('submit', false);
  37. $refresh = request_var('refresh', false);
  38. if ($submit && check_form_key($form_key))
  39. {
  40. $config_vars = array_keys($config_vars);
  41. foreach ($config_vars as $config_var)
  42. {
  43. set_config($config_var, request_var($config_var, ''));
  44. }
  45. trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
  46. }
  47. else if($submit)
  48. {
  49. trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action));
  50. }
  51. else
  52. {
  53. foreach ($config_vars as $config_var => $template_var)
  54. {
  55. $template->assign_var($template_var, (isset($_REQUEST[$config_var])) ? request_var($config_var, '') : $config[$config_var]);
  56. }
  57. }
  58. if ($refresh)
  59. {
  60. refresh();
  61. }
  62. }
  63. }
  64. function refresh()
  65. {
  66. global $db, $user, $auth, $template;
  67. $posts_thanks = array();
  68. $posts_delete = array();
  69. $all_thanks_posts = $del_posts = $postmin = $maxid = 0;
  70. $sql = 'SELECT DISTINCT post_id
  71. FROM ' . THANKS_TABLE;
  72. $result = $db->sql_query($sql);
  73. while ($row = $db->sql_fetchrow($result))
  74. {
  75. $posts_thanks[] = $row['post_id'];
  76. $all_thanks_posts++;
  77. }
  78. natsort ($posts_thanks);
  79. $sql = 'SELECT MAX(post_id) AS maxid
  80. FROM ' . POSTS_TABLE;
  81. $result = $db->sql_query($sql);
  82. $row = $db->sql_fetchrow($result);
  83. $maxid = $row['maxid'];
  84. $db->sql_freeresult($result);
  85. for ($i=1; $i < 200; $i++)
  86. {
  87. $postmax = 5000;
  88. $posts_posts = array();
  89. $sql = 'SELECT post_id
  90. FROM ' . POSTS_TABLE;
  91. $result = $db->sql_query_limit($sql, $postmax, $postmin);
  92. if (!$db->sql_fetchrow($result))
  93. {
  94. break;
  95. }
  96. $numberpost = 0;
  97. while ($row = $db->sql_fetchrow($result))
  98. {
  99. $posts_posts[$row['post_id']] = $row['post_id'];
  100. $numberpost++;
  101. }
  102. $db->sql_freeresult($result);
  103. $max = end($posts_posts);
  104. $min = reset($posts_posts);
  105. for ($j=0; $j < $all_thanks_posts; $j++)
  106. {
  107. if ($posts_thanks[$j] > $min)
  108. {
  109. if ($posts_thanks[$j] < $max)
  110. {
  111. if (!isset($posts_posts[$posts_thanks[$j]]))
  112. {
  113. $posts_delete[] = $posts_thanks[$j];
  114. $del_posts++;
  115. }
  116. }
  117. }
  118. }
  119. UnSet($posts_posts);
  120. $posts = $postmin;
  121. $postmin = $postmin + $postmax - 1;
  122. }
  123. for ($i=0, $end = count($posts_thanks); $i < $end; $i++)
  124. {
  125. if ($posts_thanks[$i] > $maxid)
  126. {
  127. $posts_delete[] = $posts_thanks[$i];
  128. $del_posts++;
  129. }
  130. }
  131. if(!empty($posts_delete))
  132. {
  133. $sql_where = 'post_id = '.$posts_delete[0];
  134. for ($i=1; $i < $del_posts; $i++)
  135. {
  136. $sql_where .= ' OR post_id = '.$posts_delete[$i];
  137. }
  138. $sql = 'DELETE FROM ' . THANKS_TABLE ."
  139. WHERE " . $sql_where;
  140. $result = $db->sql_query($sql);
  141. }
  142. $all_posts = $posts + $numberpost + 1;
  143. $template->assign_vars(array(
  144. 'POST' => $all_posts,
  145. 'THANKSPOST' => $all_thanks_posts,
  146. 'DELPOST' => $del_posts,
  147. ));
  148. }
  149. ?>