PageRenderTime 54ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/ucp.php

https://github.com/Vexilurz/phpbb_forum
PHP | 362 lines | 246 code | 82 blank | 34 comment | 45 complexity | a2d8bb832aaf34dba1fd95f9297ab02b MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package ucp
  5. * @version $Id$
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. define('IN_PHPBB', true);
  14. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  15. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  16. require($phpbb_root_path . 'common.' . $phpEx);
  17. require($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  18. require($phpbb_root_path . 'includes/functions_module.' . $phpEx);
  19. // Basic parameter data
  20. $id = request_var('i', '');
  21. $mode = request_var('mode', '');
  22. if (in_array($mode, array('login', 'logout', 'confirm', 'sendpassword', 'activate')))
  23. {
  24. define('IN_LOGIN', true);
  25. }
  26. // Start session management
  27. $user->session_begin();
  28. $auth->acl($user->data);
  29. $user->setup('ucp');
  30. $user->add_lang('mods/quick_reply');
  31. // Setting a variable to let the style designer know where he is...
  32. $template->assign_var('S_IN_UCP', true);
  33. $module = new p_master();
  34. $default = false;
  35. // Basic "global" modes
  36. switch ($mode)
  37. {
  38. case 'activate':
  39. $module->load('ucp', 'activate');
  40. $module->display($user->lang['UCP_ACTIVATE']);
  41. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  42. break;
  43. case 'resend_act':
  44. $module->load('ucp', 'resend');
  45. $module->display($user->lang['UCP_RESEND']);
  46. break;
  47. case 'sendpassword':
  48. $module->load('ucp', 'remind');
  49. $module->display($user->lang['UCP_REMIND']);
  50. break;
  51. case 'register':
  52. if ($user->data['is_registered'] || isset($_REQUEST['not_agreed']))
  53. {
  54. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  55. }
  56. $module->load('ucp', 'register');
  57. $module->display($user->lang['REGISTER']);
  58. break;
  59. case 'confirm':
  60. $module->load('ucp', 'confirm');
  61. break;
  62. case 'login':
  63. if ($user->data['is_registered'])
  64. {
  65. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  66. }
  67. login_box(request_var('redirect', "index.$phpEx"));
  68. break;
  69. case 'logout':
  70. if ($user->data['user_id'] != ANONYMOUS && isset($_GET['sid']) && !is_array($_GET['sid']) && $_GET['sid'] === $user->session_id)
  71. {
  72. $user->session_kill();
  73. $user->session_begin();
  74. $message = $user->lang['LOGOUT_REDIRECT'];
  75. }
  76. else
  77. {
  78. $message = ($user->data['user_id'] == ANONYMOUS) ? $user->lang['LOGOUT_REDIRECT'] : $user->lang['LOGOUT_FAILED'];
  79. }
  80. meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
  81. $message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a> ');
  82. trigger_error($message);
  83. break;
  84. case 'terms':
  85. case 'privacy':
  86. $message = ($mode == 'terms') ? 'TERMS_OF_USE_CONTENT' : 'PRIVACY_POLICY';
  87. $title = ($mode == 'terms') ? 'TERMS_USE' : 'PRIVACY';
  88. if (empty($user->lang[$message]))
  89. {
  90. if ($user->data['is_registered'])
  91. {
  92. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  93. }
  94. login_box();
  95. }
  96. $template->set_filenames(array(
  97. 'body' => 'ucp_agreement.html')
  98. );
  99. // Disable online list
  100. page_header($user->lang[$title], false);
  101. $template->assign_vars(array(
  102. 'S_AGREEMENT' => true,
  103. 'AGREEMENT_TITLE' => $user->lang[$title],
  104. 'AGREEMENT_TEXT' => sprintf($user->lang[$message], $config['sitename'], generate_board_url()),
  105. 'U_BACK' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'),
  106. 'L_BACK' => $user->lang['BACK_TO_LOGIN'],
  107. ));
  108. page_footer();
  109. break;
  110. case 'delete_cookies':
  111. // Delete Cookies with dynamic names (do NOT delete poll cookies)
  112. if (confirm_box(true))
  113. {
  114. $set_time = time() - 31536000;
  115. foreach ($_COOKIE as $cookie_name => $cookie_data)
  116. {
  117. // Only delete board cookies, no other ones...
  118. if (strpos($cookie_name, $config['cookie_name'] . '_') !== 0)
  119. {
  120. continue;
  121. }
  122. $cookie_name = str_replace($config['cookie_name'] . '_', '', $cookie_name);
  123. // Polls are stored as {cookie_name}_poll_{topic_id}, cookie_name_ got removed, therefore checking for poll_
  124. if (strpos($cookie_name, 'poll_') !== 0)
  125. {
  126. $user->set_cookie($cookie_name, '', $set_time);
  127. }
  128. }
  129. $user->set_cookie('track', '', $set_time);
  130. $user->set_cookie('u', '', $set_time);
  131. $user->set_cookie('k', '', $set_time);
  132. $user->set_cookie('sid', '', $set_time);
  133. // We destroy the session here, the user will be logged out nevertheless
  134. $user->session_kill();
  135. $user->session_begin();
  136. meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
  137. $message = $user->lang['COOKIES_DELETED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
  138. trigger_error($message);
  139. }
  140. else
  141. {
  142. confirm_box(false, 'DELETE_COOKIES', '');
  143. }
  144. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  145. break;
  146. case 'switch_perm':
  147. $user_id = request_var('u', 0);
  148. $sql = 'SELECT *
  149. FROM ' . USERS_TABLE . '
  150. WHERE user_id = ' . (int) $user_id;
  151. $result = $db->sql_query($sql);
  152. $user_row = $db->sql_fetchrow($result);
  153. $db->sql_freeresult($result);
  154. if (!$auth->acl_get('a_switchperm') || !$user_row || $user_id == $user->data['user_id'] || !check_link_hash(request_var('hash', ''), 'switchperm'))
  155. {
  156. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  157. }
  158. include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
  159. $auth_admin = new auth_admin();
  160. if (!$auth_admin->ghost_permissions($user_id, $user->data['user_id']))
  161. {
  162. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  163. }
  164. add_log('admin', 'LOG_ACL_TRANSFER_PERMISSIONS', $user_row['username']);
  165. $message = sprintf($user->lang['PERMISSIONS_TRANSFERRED'], $user_row['username']) . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
  166. trigger_error($message);
  167. break;
  168. case 'restore_perm':
  169. if (!$user->data['user_perm_from'] || !$auth->acl_get('a_switchperm'))
  170. {
  171. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  172. }
  173. $auth->acl_cache($user->data);
  174. $sql = 'SELECT username
  175. FROM ' . USERS_TABLE . '
  176. WHERE user_id = ' . $user->data['user_perm_from'];
  177. $result = $db->sql_query($sql);
  178. $username = $db->sql_fetchfield('username');
  179. $db->sql_freeresult($result);
  180. add_log('admin', 'LOG_ACL_RESTORE_PERMISSIONS', $username);
  181. $message = $user->lang['PERMISSIONS_RESTORED'] . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
  182. trigger_error($message);
  183. break;
  184. default:
  185. $default = true;
  186. break;
  187. }
  188. // We use this approach because it does not impose large code changes
  189. if (!$default)
  190. {
  191. return true;
  192. }
  193. // Only registered users can go beyond this point
  194. if (!$user->data['is_registered'])
  195. {
  196. if ($user->data['is_bot'])
  197. {
  198. redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
  199. }
  200. if ($id == 'pm' && $mode == 'view' && isset($_GET['p']))
  201. {
  202. $redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx?i=pm&p=" . request_var('p', 0));
  203. login_box($redirect_url, $user->lang['LOGIN_EXPLAIN_UCP']);
  204. }
  205. login_box('', $user->lang['LOGIN_EXPLAIN_UCP']);
  206. }
  207. // Instantiate module system and generate list of available modules
  208. $module->list_modules('ucp');
  209. // Check if the zebra module is set
  210. if ($module->is_active('zebra', 'friends'))
  211. {
  212. // Output listing of friends online
  213. $update_time = $config['load_online_time'] * 60;
  214. $sql = $db->sql_build_query('SELECT_DISTINCT', array(
  215. 'SELECT' => 'u.user_id, u.username, u.username_clean, u.user_colour, MAX(s.session_time) as online_time, MIN(s.session_viewonline) AS viewonline',
  216. 'FROM' => array(
  217. USERS_TABLE => 'u',
  218. ZEBRA_TABLE => 'z'
  219. ),
  220. 'LEFT_JOIN' => array(
  221. array(
  222. 'FROM' => array(SESSIONS_TABLE => 's'),
  223. 'ON' => 's.session_user_id = z.zebra_id'
  224. )
  225. ),
  226. 'WHERE' => 'z.user_id = ' . $user->data['user_id'] . '
  227. AND z.friend = 1
  228. AND u.user_id = z.zebra_id',
  229. 'GROUP_BY' => 'z.zebra_id, u.user_id, u.username_clean, u.user_colour, u.username',
  230. 'ORDER_BY' => 'u.username_clean ASC',
  231. ));
  232. $result = $db->sql_query($sql);
  233. while ($row = $db->sql_fetchrow($result))
  234. {
  235. $which = (time() - $update_time < $row['online_time'] && ($row['viewonline'] || $auth->acl_get('u_viewonline'))) ? 'online' : 'offline';
  236. $template->assign_block_vars("friends_{$which}", array(
  237. 'USER_ID' => $row['user_id'],
  238. 'U_PROFILE' => get_username_string('profile', $row['user_id'], $row['username'], $row['user_colour']),
  239. 'USER_COLOUR' => get_username_string('colour', $row['user_id'], $row['username'], $row['user_colour']),
  240. 'USERNAME' => get_username_string('username', $row['user_id'], $row['username'], $row['user_colour']),
  241. 'USERNAME_FULL' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']))
  242. );
  243. }
  244. $db->sql_freeresult($result);
  245. }
  246. // Do not display subscribed topics/forums if not allowed
  247. if (!$config['allow_topic_notify'] && !$config['allow_forum_notify'])
  248. {
  249. $module->set_display('main', 'subscribed', false);
  250. }
  251. // Do not display signature panel if not authed to do so
  252. if (!$auth->acl_get('u_sig'))
  253. {
  254. $module->set_display('profile', 'signature', false);
  255. }
  256. // Select the active module
  257. $module->set_active($id, $mode);
  258. // Load and execute the relevant module
  259. $module->load_active();
  260. // Assign data to the template engine for the list of modules
  261. $module->assign_tpl_vars(append_sid("{$phpbb_root_path}ucp.$phpEx"));
  262. // Generate the page, do not display/query online list
  263. $module->display($module->get_page_title(), false);
  264. /**
  265. * Function for assigning a template var if the zebra module got included
  266. */
  267. function _module_zebra($mode, &$module_row)
  268. {
  269. global $template;
  270. $template->assign_var('S_ZEBRA_ENABLED', true);
  271. if ($mode == 'friends')
  272. {
  273. $template->assign_var('S_ZEBRA_FRIENDS_ENABLED', true);
  274. }
  275. if ($mode == 'foes')
  276. {
  277. $template->assign_var('S_ZEBRA_FOES_ENABLED', true);
  278. }
  279. }
  280. ?>