PageRenderTime 60ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/mcp.php

https://bitbucket.org/cmwdosp/cmwbb3
PHP | 326 lines | 214 code | 44 blank | 68 comment | 68 complexity | b79cf8870618d8dbf051fa575142f20b MD5 | raw file
Possible License(s): BSD-3-Clause
  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->variable('i', '');
  32. $mode = $request->variable('mode', array(''));
  33. $mode = sizeof($mode) ? array_shift($mode) : $request->variable('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->variable('action', '');
  45. $action_ary = $request->variable('action', array('' => 0));
  46. $forum_action = $request->variable('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->variable('p', 0);
  62. $topic_id = $request->variable('t', 0);
  63. $forum_id = $request->variable('f', 0);
  64. $report_id = $request->variable('r', 0);
  65. $user_id = $request->variable('u', 0);
  66. $username = $request->variable('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_global',
  98. 'make_normal' => array('f_announce', 'f_announce_global', '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. send_status_line(403, 'Forbidden');
  112. trigger_error('NOT_AUTHORISED');
  113. }
  114. }
  115. // if the user cannot read the forum he tries to access then we won't allow mcp access either
  116. if ($forum_id && !$auth->acl_get('f_read', $forum_id))
  117. {
  118. send_status_line(403, 'Forbidden');
  119. trigger_error('NOT_AUTHORISED');
  120. }
  121. /**
  122. * Allow applying additional permissions to MCP access besides f_read
  123. *
  124. * @event core.mcp_global_f_read_auth_after
  125. * @var string action The action the user tried to execute
  126. * @var int forum_id The forum the user tried to access
  127. * @var string mode The MCP module the user is trying to access
  128. * @var p_master module Module system class
  129. * @var bool quickmod True if the user is accessing using quickmod tools
  130. * @var int topic_id The topic the user tried to access
  131. * @since 3.1.3-RC1
  132. */
  133. $vars = array(
  134. 'action',
  135. 'forum_id',
  136. 'mode',
  137. 'module',
  138. 'quickmod',
  139. 'topic_id',
  140. );
  141. extract($phpbb_dispatcher->trigger_event('core.mcp_global_f_read_auth_after', compact($vars)));
  142. if ($forum_id)
  143. {
  144. $module->acl_forum_id = $forum_id;
  145. }
  146. // Instantiate module system and generate list of available modules
  147. $module->list_modules('mcp');
  148. if ($quickmod)
  149. {
  150. $mode = 'quickmod';
  151. switch ($action)
  152. {
  153. case 'lock':
  154. case 'unlock':
  155. case 'lock_post':
  156. case 'unlock_post':
  157. case 'make_sticky':
  158. case 'make_announce':
  159. case 'make_global':
  160. case 'make_normal':
  161. case 'fork':
  162. case 'move':
  163. case 'delete_post':
  164. case 'delete_topic':
  165. case 'restore_topic':
  166. $module->load('mcp', 'main', 'quickmod');
  167. return;
  168. break;
  169. case 'topic_logs':
  170. // Reset start parameter if we jumped from the quickmod dropdown
  171. if ($request->variable('start', 0))
  172. {
  173. $request->overwrite('start', 0);
  174. }
  175. $module->set_active('logs', 'topic_logs');
  176. break;
  177. case 'merge_topic':
  178. $module->set_active('main', 'forum_view');
  179. break;
  180. case 'split':
  181. case 'merge':
  182. $module->set_active('main', 'topic_view');
  183. break;
  184. default:
  185. // If needed, the flag can be set to true within event listener
  186. // to indicate that the action was handled properly
  187. // and to pass by the trigger_error() call below
  188. $is_valid_action = false;
  189. /**
  190. * This event allows you to add custom quickmod options
  191. *
  192. * @event core.modify_quickmod_options
  193. * @var object module Instance of module system class
  194. * @var string action Quickmod option
  195. * @var bool is_valid_action Flag indicating if the action was handled properly
  196. * @since 3.1.0-a4
  197. */
  198. $vars = array('module', 'action', 'is_valid_action');
  199. extract($phpbb_dispatcher->trigger_event('core.modify_quickmod_options', compact($vars)));
  200. if (!$is_valid_action)
  201. {
  202. trigger_error($user->lang('QUICKMOD_ACTION_NOT_ALLOWED', $action), E_USER_ERROR);
  203. }
  204. break;
  205. }
  206. }
  207. else
  208. {
  209. // Select the active module
  210. $module->set_active($id, $mode);
  211. }
  212. // Hide some of the options if we don't have the relevant information to use them
  213. if (!$post_id)
  214. {
  215. $module->set_display('main', 'post_details', false);
  216. $module->set_display('warn', 'warn_post', false);
  217. }
  218. if ($mode == '' || $mode == 'unapproved_topics' || $mode == 'unapproved_posts' || $mode == 'deleted_topics' || $mode == 'deleted_posts')
  219. {
  220. $module->set_display('queue', 'approve_details', false);
  221. }
  222. if ($mode == '' || $mode == 'reports' || $mode == 'reports_closed' || $mode == 'pm_reports' || $mode == 'pm_reports_closed' || $mode == 'pm_report_details')
  223. {
  224. $module->set_display('reports', 'report_details', false);
  225. }
  226. if ($mode == '' || $mode == 'reports' || $mode == 'reports_closed' || $mode == 'pm_reports' || $mode == 'pm_reports_closed' || $mode == 'report_details')
  227. {
  228. $module->set_display('pm_reports', 'pm_report_details', false);
  229. }
  230. if (!$topic_id)
  231. {
  232. $module->set_display('main', 'topic_view', false);
  233. $module->set_display('logs', 'topic_logs', false);
  234. }
  235. if (!$forum_id)
  236. {
  237. $module->set_display('main', 'forum_view', false);
  238. $module->set_display('logs', 'forum_logs', false);
  239. }
  240. if (!$user_id && $username == '')
  241. {
  242. $module->set_display('notes', 'user_notes', false);
  243. $module->set_display('warn', 'warn_user', false);
  244. }
  245. /**
  246. * This event allows you to set display option for custom MCP modules
  247. *
  248. * @event core.modify_mcp_modules_display_option
  249. * @var p_master module Module system class
  250. * @var string mode MCP mode
  251. * @var int user_id User id
  252. * @var int forum_id Forum id
  253. * @var int topic_id Topic id
  254. * @var int post_id Post id
  255. * @var string username User name
  256. * @var int id Parent module id
  257. * @since 3.1.0-b2
  258. */
  259. $vars = array(
  260. 'module',
  261. 'mode',
  262. 'user_id',
  263. 'forum_id',
  264. 'topic_id',
  265. 'post_id',
  266. 'username',
  267. 'id',
  268. );
  269. extract($phpbb_dispatcher->trigger_event('core.modify_mcp_modules_display_option', compact($vars)));
  270. // Load and execute the relevant module
  271. $module->load_active();
  272. // Assign data to the template engine for the list of modules
  273. $module->assign_tpl_vars(append_sid("{$phpbb_root_path}mcp.$phpEx"));
  274. // Generate urls for letting the moderation control panel being accessed in different modes
  275. $template->assign_vars(array(
  276. 'U_MCP' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main'),
  277. 'U_MCP_FORUM' => ($forum_id) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=forum_view&amp;f=$forum_id") : '',
  278. 'U_MCP_TOPIC' => ($forum_id && $topic_id) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=topic_view&amp;t=$topic_id") : '',
  279. '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") : '',
  280. ));
  281. // Generate the page, do not display/query online list
  282. $module->display($module->get_page_title());