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

/forum/mcp.php

https://github.com/AJenbo/ubuntudanmark.dk
PHP | 324 lines | 212 code | 44 blank | 68 comment | 68 complexity | 10371a4dbbb31586d3f049c66cbe69fc MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * This file is part of the phpBB Forum Software package.
  5. *
  6. * @copyright (c) phpBB Limited <https://www.phpbb.com>
  7. * @license GNU General Public License, version 2 (GPL-2.0)
  8. *
  9. * For full copyright and license information, please see
  10. * the docs/CREDITS.txt file.
  11. *
  12. */
  13. /**
  14. * @ignore
  15. */
  16. define('IN_PHPBB', true);
  17. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  18. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  19. include($phpbb_root_path . 'common.' . $phpEx);
  20. include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
  21. include($phpbb_root_path . 'includes/functions_mcp.' . $phpEx);
  22. require($phpbb_root_path . 'includes/functions_module.' . $phpEx);
  23. // Start session management
  24. $user->session_begin();
  25. $auth->acl($user->data);
  26. $user->setup('mcp');
  27. $module = new p_master();
  28. // Setting a variable to let the style designer know where he is...
  29. $template->assign_var('S_IN_MCP', true);
  30. // Basic parameter data
  31. $id = request_var('i', '');
  32. $mode = request_var('mode', array(''));
  33. $mode = sizeof($mode) ? array_shift($mode) : request_var('mode', '');
  34. // Only Moderators can go beyond this point
  35. if (!$user->data['is_registered'])
  36. {
  37. if ($user->data['is_bot'])
  38. {
  39. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  40. }
  41. login_box('', $user->lang['LOGIN_EXPLAIN_MCP']);
  42. }
  43. $quickmod = (isset($_REQUEST['quickmod'])) ? true : false;
  44. $action = request_var('action', '');
  45. $action_ary = request_var('action', array('' => 0));
  46. $forum_action = request_var('forum_action', '');
  47. if ($forum_action !== '' && $request->variable('sort', false, false, \phpbb\request\request_interface::POST))
  48. {
  49. $action = $forum_action;
  50. }
  51. if (sizeof($action_ary))
  52. {
  53. list($action, ) = each($action_ary);
  54. }
  55. unset($action_ary);
  56. if ($mode == 'topic_logs')
  57. {
  58. $id = 'logs';
  59. $quickmod = false;
  60. }
  61. $post_id = request_var('p', 0);
  62. $topic_id = request_var('t', 0);
  63. $forum_id = request_var('f', 0);
  64. $report_id = request_var('r', 0);
  65. $user_id = request_var('u', 0);
  66. $username = utf8_normalize_nfc(request_var('username', '', true));
  67. if ($post_id)
  68. {
  69. // We determine the topic and forum id here, to make sure the moderator really has moderative rights on this post
  70. $sql = 'SELECT topic_id, forum_id
  71. FROM ' . POSTS_TABLE . "
  72. WHERE post_id = $post_id";
  73. $result = $db->sql_query($sql);
  74. $row = $db->sql_fetchrow($result);
  75. $db->sql_freeresult($result);
  76. $topic_id = (int) $row['topic_id'];
  77. $forum_id = (int) $row['forum_id'];
  78. }
  79. else if ($topic_id)
  80. {
  81. $sql = 'SELECT forum_id
  82. FROM ' . TOPICS_TABLE . "
  83. WHERE topic_id = $topic_id";
  84. $result = $db->sql_query($sql);
  85. $row = $db->sql_fetchrow($result);
  86. $db->sql_freeresult($result);
  87. $forum_id = (int) $row['forum_id'];
  88. }
  89. // If the user doesn't have any moderator powers (globally or locally) he can't access the mcp
  90. if (!$auth->acl_getf_global('m_'))
  91. {
  92. // Except he is using one of the quickmod tools for users
  93. $user_quickmod_actions = array(
  94. 'lock' => 'f_user_lock',
  95. 'make_sticky' => 'f_sticky',
  96. 'make_announce' => 'f_announce',
  97. 'make_global' => 'f_announce',
  98. 'make_normal' => array('f_announce', 'f_sticky')
  99. );
  100. $allow_user = false;
  101. if ($quickmod && isset($user_quickmod_actions[$action]) && $user->data['is_registered'] && $auth->acl_gets($user_quickmod_actions[$action], $forum_id))
  102. {
  103. $topic_info = phpbb_get_topic_data(array($topic_id));
  104. if ($topic_info[$topic_id]['topic_poster'] == $user->data['user_id'])
  105. {
  106. $allow_user = true;
  107. }
  108. }
  109. if (!$allow_user)
  110. {
  111. trigger_error('NOT_AUTHORISED');
  112. }
  113. }
  114. // if the user cannot read the forum he tries to access then we won't allow mcp access either
  115. if ($forum_id && !$auth->acl_get('f_read', $forum_id))
  116. {
  117. trigger_error('NOT_AUTHORISED');
  118. }
  119. /**
  120. * Allow applying additional permissions to MCP access besides f_read
  121. *
  122. * @event core.mcp_global_f_read_auth_after
  123. * @var string action The action the user tried to execute
  124. * @var int forum_id The forum the user tried to access
  125. * @var string mode The MCP module the user is trying to access
  126. * @var p_master module Module system class
  127. * @var bool quickmod True if the user is accessing using quickmod tools
  128. * @var int topic_id The topic the user tried to access
  129. * @since 3.1.3-RC1
  130. */
  131. $vars = array(
  132. 'action',
  133. 'forum_id',
  134. 'mode',
  135. 'module',
  136. 'quickmod',
  137. 'topic_id',
  138. );
  139. extract($phpbb_dispatcher->trigger_event('core.mcp_global_f_read_auth_after', compact($vars)));
  140. if ($forum_id)
  141. {
  142. $module->acl_forum_id = $forum_id;
  143. }
  144. // Instantiate module system and generate list of available modules
  145. $module->list_modules('mcp');
  146. if ($quickmod)
  147. {
  148. $mode = 'quickmod';
  149. switch ($action)
  150. {
  151. case 'lock':
  152. case 'unlock':
  153. case 'lock_post':
  154. case 'unlock_post':
  155. case 'make_sticky':
  156. case 'make_announce':
  157. case 'make_global':
  158. case 'make_normal':
  159. case 'fork':
  160. case 'move':
  161. case 'delete_post':
  162. case 'delete_topic':
  163. case 'restore_topic':
  164. $module->load('mcp', 'main', 'quickmod');
  165. return;
  166. break;
  167. case 'topic_logs':
  168. // Reset start parameter if we jumped from the quickmod dropdown
  169. if (request_var('start', 0))
  170. {
  171. $request->overwrite('start', 0);
  172. }
  173. $module->set_active('logs', 'topic_logs');
  174. break;
  175. case 'merge_topic':
  176. $module->set_active('main', 'forum_view');
  177. break;
  178. case 'split':
  179. case 'merge':
  180. $module->set_active('main', 'topic_view');
  181. break;
  182. default:
  183. // If needed, the flag can be set to true within event listener
  184. // to indicate that the action was handled properly
  185. // and to pass by the trigger_error() call below
  186. $is_valid_action = false;
  187. /**
  188. * This event allows you to add custom quickmod options
  189. *
  190. * @event core.modify_quickmod_options
  191. * @var object module Instance of module system class
  192. * @var string action Quickmod option
  193. * @var bool is_valid_action Flag indicating if the action was handled properly
  194. * @since 3.1.0-a4
  195. */
  196. $vars = array('module', 'action', 'is_valid_action');
  197. extract($phpbb_dispatcher->trigger_event('core.modify_quickmod_options', compact($vars)));
  198. if (!$is_valid_action)
  199. {
  200. trigger_error($user->lang('QUICKMOD_ACTION_NOT_ALLOWED', $action), E_USER_ERROR);
  201. }
  202. break;
  203. }
  204. }
  205. else
  206. {
  207. // Select the active module
  208. $module->set_active($id, $mode);
  209. }
  210. // Hide some of the options if we don't have the relevant information to use them
  211. if (!$post_id)
  212. {
  213. $module->set_display('main', 'post_details', false);
  214. $module->set_display('warn', 'warn_post', false);
  215. }
  216. if ($mode == '' || $mode == 'unapproved_topics' || $mode == 'unapproved_posts' || $mode == 'deleted_topics' || $mode == 'deleted_posts')
  217. {
  218. $module->set_display('queue', 'approve_details', false);
  219. }
  220. if ($mode == '' || $mode == 'reports' || $mode == 'reports_closed' || $mode == 'pm_reports' || $mode == 'pm_reports_closed' || $mode == 'pm_report_details')
  221. {
  222. $module->set_display('reports', 'report_details', false);
  223. }
  224. if ($mode == '' || $mode == 'reports' || $mode == 'reports_closed' || $mode == 'pm_reports' || $mode == 'pm_reports_closed' || $mode == 'report_details')
  225. {
  226. $module->set_display('pm_reports', 'pm_report_details', false);
  227. }
  228. if (!$topic_id)
  229. {
  230. $module->set_display('main', 'topic_view', false);
  231. $module->set_display('logs', 'topic_logs', false);
  232. }
  233. if (!$forum_id)
  234. {
  235. $module->set_display('main', 'forum_view', false);
  236. $module->set_display('logs', 'forum_logs', false);
  237. }
  238. if (!$user_id && $username == '')
  239. {
  240. $module->set_display('notes', 'user_notes', false);
  241. $module->set_display('warn', 'warn_user', false);
  242. }
  243. /**
  244. * This event allows you to set display option for custom MCP modules
  245. *
  246. * @event core.modify_mcp_modules_display_option
  247. * @var p_master module Module system class
  248. * @var string mode MCP mode
  249. * @var int user_id User id
  250. * @var int forum_id Forum id
  251. * @var int topic_id Topic id
  252. * @var int post_id Post id
  253. * @var string username User name
  254. * @var int id Parent module id
  255. * @since 3.1.0-b2
  256. */
  257. $vars = array(
  258. 'module',
  259. 'mode',
  260. 'user_id',
  261. 'forum_id',
  262. 'topic_id',
  263. 'post_id',
  264. 'username',
  265. 'id',
  266. );
  267. extract($phpbb_dispatcher->trigger_event('core.modify_mcp_modules_display_option', compact($vars)));
  268. // Load and execute the relevant module
  269. $module->load_active();
  270. // Assign data to the template engine for the list of modules
  271. $module->assign_tpl_vars(append_sid("{$phpbb_root_path}mcp.$phpEx"));
  272. // Generate urls for letting the moderation control panel being accessed in different modes
  273. $template->assign_vars(array(
  274. 'U_MCP' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main'),
  275. 'U_MCP_FORUM' => ($forum_id) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=forum_view&amp;f=$forum_id") : '',
  276. 'U_MCP_TOPIC' => ($forum_id && $topic_id) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=topic_view&amp;t=$topic_id") : '',
  277. 'U_MCP_POST' => ($forum_id && $topic_id && $post_id) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=post_details&amp;t=$topic_id&amp;p=$post_id") : '',
  278. ));
  279. // Generate the page, do not display/query online list
  280. $module->display($module->get_page_title());