PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/phpBB/index.php

http://github.com/phpbb/phpbb
PHP | 252 lines | 156 code | 38 blank | 58 comment | 25 complexity | 34eafc926af1512d251adc15ccc39e15 MD5 | raw file
Possible License(s): GPL-3.0, AGPL-1.0
  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. */
  15. /**
  16. * @ignore
  17. */
  18. define('IN_PHPBB', true);
  19. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
  20. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  21. include($phpbb_root_path . 'common.' . $phpEx);
  22. include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
  23. // Start session management
  24. $user->session_begin();
  25. $auth->acl($user->data);
  26. $user->setup('viewforum');
  27. // Mark notifications read
  28. if (($mark_notification = $request->variable('mark_notification', 0)))
  29. {
  30. if ($user->data['user_id'] == ANONYMOUS)
  31. {
  32. if ($request->is_ajax())
  33. {
  34. trigger_error('LOGIN_REQUIRED');
  35. }
  36. login_box('', $user->lang['LOGIN_REQUIRED']);
  37. }
  38. if (check_link_hash($request->variable('hash', ''), 'mark_notification_read'))
  39. {
  40. /* @var $phpbb_notifications \phpbb\notification\manager */
  41. $phpbb_notifications = $phpbb_container->get('notification_manager');
  42. $notification = $phpbb_notifications->load_notifications('notification.method.board', array(
  43. 'notification_id' => $mark_notification,
  44. ));
  45. if (isset($notification['notifications'][$mark_notification]))
  46. {
  47. $notification = $notification['notifications'][$mark_notification];
  48. $notification->mark_read();
  49. /**
  50. * You can use this event to perform additional tasks or redirect user elsewhere.
  51. *
  52. * @event core.index_mark_notification_after
  53. * @var int mark_notification Notification ID
  54. * @var \phpbb\notification\type\type_interface notification Notification instance
  55. * @since 3.2.6-RC1
  56. */
  57. $vars = array('mark_notification', 'notification');
  58. extract($phpbb_dispatcher->trigger_event('core.index_mark_notification_after', compact($vars)));
  59. if ($request->is_ajax())
  60. {
  61. $json_response = new \phpbb\json_response();
  62. $json_response->send(array(
  63. 'success' => true,
  64. ));
  65. }
  66. if (($redirect = $request->variable('redirect', '')))
  67. {
  68. redirect(append_sid($phpbb_root_path . $redirect));
  69. }
  70. redirect($notification->get_redirect_url());
  71. }
  72. }
  73. }
  74. display_forums('', $config['load_moderators']);
  75. $order_legend = ($config['legend_sort_groupname']) ? 'group_name' : 'group_legend';
  76. // Grab group details for legend display
  77. if ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel'))
  78. {
  79. $sql = 'SELECT group_id, group_name, group_colour, group_type, group_legend
  80. FROM ' . GROUPS_TABLE . '
  81. WHERE group_legend > 0
  82. ORDER BY ' . $order_legend . ' ASC';
  83. }
  84. else
  85. {
  86. $sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_type, g.group_legend
  87. FROM ' . GROUPS_TABLE . ' g
  88. LEFT JOIN ' . USER_GROUP_TABLE . ' ug
  89. ON (
  90. g.group_id = ug.group_id
  91. AND ug.user_id = ' . $user->data['user_id'] . '
  92. AND ug.user_pending = 0
  93. )
  94. WHERE g.group_legend > 0
  95. AND (g.group_type <> ' . GROUP_HIDDEN . ' OR ug.user_id = ' . $user->data['user_id'] . ')
  96. ORDER BY g.' . $order_legend . ' ASC';
  97. }
  98. $result = $db->sql_query($sql);
  99. /** @var \phpbb\group\helper $group_helper */
  100. $group_helper = $phpbb_container->get('group_helper');
  101. $legend = array();
  102. while ($row = $db->sql_fetchrow($result))
  103. {
  104. $colour_text = ($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . '"' : '';
  105. $group_name = $group_helper->get_name($row['group_name']);
  106. if ($row['group_name'] == 'BOTS' || ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile')))
  107. {
  108. $legend[] = '<span' . $colour_text . '>' . $group_name . '</span>';
  109. }
  110. else
  111. {
  112. $legend[] = '<a' . $colour_text . ' href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']) . '">' . $group_name . '</a>';
  113. }
  114. }
  115. $db->sql_freeresult($result);
  116. $legend = implode($user->lang['COMMA_SEPARATOR'], $legend);
  117. // Generate birthday list if required ...
  118. $show_birthdays = ($config['load_birthdays'] && $config['allow_birthdays'] && $auth->acl_gets('u_viewprofile', 'a_user', 'a_useradd', 'a_userdel'));
  119. $birthdays = $birthday_list = array();
  120. if ($show_birthdays)
  121. {
  122. $time = $user->create_datetime();
  123. $now = phpbb_gmgetdate($time->getTimestamp() + $time->getOffset());
  124. // Display birthdays of 29th february on 28th february in non-leap-years
  125. $leap_year_birthdays = '';
  126. if ($now['mday'] == 28 && $now['mon'] == 2 && !$time->format('L'))
  127. {
  128. $leap_year_birthdays = " OR u.user_birthday LIKE '" . $db->sql_escape(sprintf('%2d-%2d-', 29, 2)) . "%'";
  129. }
  130. $sql_ary = array(
  131. 'SELECT' => 'u.user_id, u.username, u.user_colour, u.user_birthday',
  132. 'FROM' => array(
  133. USERS_TABLE => 'u',
  134. ),
  135. 'LEFT_JOIN' => array(
  136. array(
  137. 'FROM' => array(BANLIST_TABLE => 'b'),
  138. 'ON' => 'u.user_id = b.ban_userid',
  139. ),
  140. ),
  141. 'WHERE' => "(b.ban_id IS NULL OR b.ban_exclude = 1)
  142. AND (u.user_birthday LIKE '" . $db->sql_escape(sprintf('%2d-%2d-', $now['mday'], $now['mon'])) . "%' $leap_year_birthdays)
  143. AND u.user_type IN (" . USER_NORMAL . ', ' . USER_FOUNDER . ')',
  144. );
  145. /**
  146. * Event to modify the SQL query to get birthdays data
  147. *
  148. * @event core.index_modify_birthdays_sql
  149. * @var array now The assoc array with the 'now' local timestamp data
  150. * @var array sql_ary The SQL array to get the birthdays data
  151. * @var object time The user related Datetime object
  152. * @since 3.1.7-RC1
  153. */
  154. $vars = array('now', 'sql_ary', 'time');
  155. extract($phpbb_dispatcher->trigger_event('core.index_modify_birthdays_sql', compact($vars)));
  156. $sql = $db->sql_build_query('SELECT', $sql_ary);
  157. $result = $db->sql_query($sql);
  158. $rows = $db->sql_fetchrowset($result);
  159. $db->sql_freeresult($result);
  160. foreach ($rows as $row)
  161. {
  162. $birthday_username = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
  163. $birthday_year = (int) substr($row['user_birthday'], -4);
  164. $birthday_age = ($birthday_year) ? max(0, $now['year'] - $birthday_year) : '';
  165. $birthdays[] = array(
  166. 'USERNAME' => $birthday_username,
  167. 'AGE' => $birthday_age,
  168. );
  169. // For 3.0 compatibility
  170. $birthday_list[] = $birthday_username . (($birthday_age) ? " ({$birthday_age})" : '');
  171. }
  172. /**
  173. * Event to modify the birthdays list
  174. *
  175. * @event core.index_modify_birthdays_list
  176. * @var array birthdays Array with the users birthdays data
  177. * @var array rows Array with the birthdays SQL query result
  178. * @since 3.1.7-RC1
  179. */
  180. $vars = array('birthdays', 'rows');
  181. extract($phpbb_dispatcher->trigger_event('core.index_modify_birthdays_list', compact($vars)));
  182. $template->assign_block_vars_array('birthdays', $birthdays);
  183. }
  184. // Assign index specific vars
  185. $template->assign_vars(array(
  186. 'TOTAL_POSTS' => $user->lang('TOTAL_POSTS_COUNT', (int) $config['num_posts']),
  187. 'TOTAL_TOPICS' => $user->lang('TOTAL_TOPICS', (int) $config['num_topics']),
  188. 'TOTAL_USERS' => $user->lang('TOTAL_USERS', (int) $config['num_users']),
  189. 'NEWEST_USER' => $user->lang('NEWEST_USER', get_username_string('full', $config['newest_user_id'], $config['newest_username'], $config['newest_user_colour'])),
  190. 'LEGEND' => $legend,
  191. 'BIRTHDAY_LIST' => (empty($birthday_list)) ? '' : implode($user->lang['COMMA_SEPARATOR'], $birthday_list),
  192. 'S_LOGIN_ACTION' => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'),
  193. 'U_SEND_PASSWORD' => ($config['email_enable']) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=sendpassword') : '',
  194. 'S_DISPLAY_BIRTHDAY_LIST' => $show_birthdays,
  195. 'S_INDEX' => true,
  196. 'U_MARK_FORUMS' => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&amp;mark=forums&amp;mark_time=' . time()) : '',
  197. 'U_MCP' => ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=front', true, $user->session_id) : '')
  198. );
  199. $page_title = ($config['board_index_text'] !== '') ? $config['board_index_text'] : $user->lang['INDEX'];
  200. /**
  201. * You can use this event to modify the page title and load data for the index
  202. *
  203. * @event core.index_modify_page_title
  204. * @var string page_title Title of the index page
  205. * @since 3.1.0-a1
  206. */
  207. $vars = array('page_title');
  208. extract($phpbb_dispatcher->trigger_event('core.index_modify_page_title', compact($vars)));
  209. // Output page
  210. page_header($page_title, true);
  211. $template->set_filenames(array(
  212. 'body' => 'index_body.html')
  213. );
  214. page_footer();