diff options
Diffstat (limited to 'phpBB/includes/functions_display.php')
-rw-r--r-- | phpBB/includes/functions_display.php | 629 |
1 files changed, 419 insertions, 210 deletions
diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index e663ac90c5..afda10ebee 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1,9 +1,13 @@ <?php /** * -* @package phpBB3 -* @copyright (c) 2005 phpBB Group -* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -26,10 +30,9 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array(); $parent_id = $visible_forums = 0; - $sql_from = ''; // Mark forums read? - $mark_read = request_var('mark', ''); + $mark_read = $request->variable('mark', ''); if ($mark_read == 'all') { @@ -57,9 +60,9 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $redirect = build_url(array('mark', 'hash', 'mark_time')); meta_refresh(3, $redirect); - if (check_link_hash(request_var('hash', ''), 'global')) + if (check_link_hash($request->variable('hash', ''), 'global')) { - markread('all', false, false, request_var('mark_time', 0)); + markread('all', false, false, $request->variable('mark_time', 0)); if ($request->is_ajax()) { @@ -138,7 +141,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod * * @event core.display_forums_modify_sql * @var array sql_ary The SQL array to get the data of the forums - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('sql_ary'); extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_sql', compact($vars))); @@ -146,9 +149,10 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query($sql); - $forum_tracking_info = array(); + $forum_tracking_info = $valid_categories = array(); $branch_root_id = $root_data['forum_id']; + /* @var $phpbb_content_visibility \phpbb\content_visibility */ $phpbb_content_visibility = $phpbb_container->get('content.visibility'); while ($row = $db->sql_fetchrow($result)) @@ -161,7 +165,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod * @event core.display_forums_modify_row * @var int branch_root_id Last top-level forum * @var array row The data of the forum - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('branch_root_id', 'row'); extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_row', compact($vars))); @@ -246,6 +250,12 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod } } + // Fill list of categories with forums + if (isset($forum_rows[$row['parent_id']])) + { + $valid_categories[$row['parent_id']] = true; + } + // if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id) { @@ -263,6 +273,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $branch_root_id = $forum_id; } $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id']; + $forum_rows[$parent_id]['forum_password_last_post'] = $row['forum_password']; $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time']; } else if ($row['forum_type'] != FORUM_CAT) @@ -304,6 +315,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name']; $forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour']; $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id; + $forum_rows[$parent_id]['forum_password_last_post'] = $row['forum_password']; } } @@ -318,7 +330,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod * @var int branch_root_id Current top-level forum * @var int parent_id Current parent forum * @var array row The data of the forum - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('forum_rows', 'subforums', 'branch_root_id', 'parent_id', 'row'); extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_forum_rows', compact($vars))); @@ -329,10 +341,10 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod if ($mark_read == 'forums') { $redirect = build_url(array('mark', 'hash', 'mark_time')); - $token = request_var('hash', ''); + $token = $request->variable('hash', ''); if (check_link_hash($token, 'global')) { - markread('topics', $forum_ids, false, request_var('mark_time', 0)); + markread('topics', $forum_ids, false, $request->variable('mark_time', 0)); $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>'); meta_refresh(3, $redirect); @@ -371,14 +383,42 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod get_moderators($forum_moderators, $forum_ids_moderator); } + /** + * Event to perform additional actions before the forum list is being generated + * + * @event core.display_forums_before + * @var array active_forum_ary Array with forum data to display active topics + * @var bool display_moderators Flag indicating if we display forum moderators + * @var array forum_moderators Array with forum moderators list + * @var array forum_rows Data array of all forums we display + * @var bool return_moderators Flag indicating if moderators list should be returned + * @var array root_data Array with the root forum data + * @since 3.1.4-RC1 + */ + $vars = array( + 'active_forum_ary', + 'display_moderators', + 'forum_moderators', + 'forum_rows', + 'return_moderators', + 'root_data', + ); + extract($phpbb_dispatcher->trigger_event('core.display_forums_before', compact($vars))); + // Used to tell whatever we have to create a dummy category or not. $last_catless = true; foreach ($forum_rows as $row) { - // Empty category + // Category if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT) { - $template->assign_block_vars('forumrow', array( + // Do not display categories without any forums to display + if (!isset($valid_categories[$row['forum_id']])) + { + continue; + } + + $cat_row = array( 'S_IS_CAT' => true, 'FORUM_ID' => $row['forum_id'], 'FORUM_NAME' => $row['forum_name'], @@ -387,8 +427,31 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod 'FORUM_FOLDER_IMG_SRC' => '', 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '', 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '', - 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id'])) + 'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']), + ); + + /** + * Modify the template data block of the 'category' + * + * This event is triggered once per 'category' + * + * @event core.display_forums_modify_category_template_vars + * @var array cat_row Template data of the 'category' + * @var bool last_catless The flag indicating whether the last forum had a parent category + * @var array root_data Array with the root forum data + * @var array row The data of the 'category' + * @since 3.1.0-RC4 + * @change 3.1.7-RC1 Removed undefined catless variable + */ + $vars = array( + 'cat_row', + 'last_catless', + 'root_data', + 'row', ); + extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_category_template_vars', compact($vars))); + + $template->assign_block_vars('forumrow', $cat_row); continue; } @@ -441,7 +504,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod } } - $l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': '; + $l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS']; $folder_image = ($forum_unread) ? 'forum_unread_subforum' : 'forum_read_subforum'; } else @@ -472,8 +535,15 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod // Create last post link information, if appropriate if ($row['forum_last_post_id']) { - $last_post_subject = $row['forum_last_post_subject']; - $last_post_subject_truncated = truncate_string(censor_text($last_post_subject), 30, 255, false, $user->lang['ELLIPSIS']); + if ($row['forum_password_last_post'] === '' && $auth->acl_get('f_read', $row['forum_id_last_post'])) + { + $last_post_subject = censor_text($row['forum_last_post_subject']); + $last_post_subject_truncated = truncate_string($last_post_subject, 30, 255, false, $user->lang['ELLIPSIS']); + } + else + { + $last_post_subject = $last_post_subject_truncated = ''; + } $last_post_time = $user->format_date($row['forum_last_post_time']); $last_post_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id']; } @@ -493,10 +563,15 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod $l_post_click_count = ($row['forum_type'] == FORUM_LINK) ? 'CLICKS' : 'POSTS'; $post_click_count = ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? $row['forum_posts'] : ''; - $s_subforums_list = array(); + $s_subforums_list = $subforums_row = array(); foreach ($subforums_list as $subforum) { $s_subforums_list[] = '<a href="' . $subforum['link'] . '" class="subforum ' . (($subforum['unread']) ? 'unread' : 'read') . '" title="' . (($subforum['unread']) ? $user->lang['UNREAD_POSTS'] : $user->lang['NO_UNREAD_POSTS']) . '">' . $subforum['name'] . '</a>'; + $subforums_row[] = array( + 'U_SUBFORUM' => $subforum['link'], + 'SUBFORUM_NAME' => $subforum['name'], + 'S_UNREAD' => $subforum['unread'], + ); } $s_subforums_list = (string) implode($user->lang['COMMA_SEPARATOR'], $s_subforums_list); $catless = ($row['parent_id'] == $root_data['forum_id']) ? true : false; @@ -528,7 +603,7 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod 'S_LOCKED_FORUM' => ($row['forum_status'] == ITEM_LOCKED) ? true : false, 'S_LIST_SUBFORUMS' => ($row['display_subforum_list']) ? true : false, 'S_SUBFORUMS' => (sizeof($subforums_list)) ? true : false, - 'S_DISPLAY_SUBJECT' => ($last_post_subject && $config['display_last_subject'] && !$row['forum_password'] && $auth->acl_get('f_read', $row['forum_id'])) ? true : false, + 'S_DISPLAY_SUBJECT' => ($last_post_subject !== '' && $config['display_last_subject']) ? true : false, 'S_FEED_ENABLED' => ($config['feed_forum'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options']) && $row['forum_type'] == FORUM_POST) ? true : false, 'FORUM_ID' => $row['forum_id'], @@ -541,8 +616,8 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod 'FORUM_FOLDER_IMG_ALT' => isset($user->lang[$folder_alt]) ? $user->lang[$folder_alt] : '', 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '', 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '', - 'LAST_POST_SUBJECT' => (!$row['forum_password'] && $auth->acl_get('f_read', $row['forum_id'])) ? censor_text($last_post_subject) : "", - 'LAST_POST_SUBJECT_TRUNCATED' => (!$row['forum_password'] && $auth->acl_get('f_read', $row['forum_id'])) ? $last_post_subject_truncated : "", + 'LAST_POST_SUBJECT' => $last_post_subject, + 'LAST_POST_SUBJECT_TRUNCATED' => $last_post_subject_truncated, 'LAST_POST_TIME' => $last_post_time, 'LAST_POSTER' => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), 'LAST_POSTER_COLOUR' => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']), @@ -568,22 +643,41 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod * @event core.display_forums_modify_template_vars * @var array forum_row Template data of the forum * @var array row The data of the forum - * @since 3.1-A1 + * @var array subforums_row Template data of subforums + * @since 3.1.0-a1 + * @change 3.1.0-b5 Added var subforums_row */ - $vars = array('forum_row', 'row'); + $vars = array('forum_row', 'row', 'subforums_row'); extract($phpbb_dispatcher->trigger_event('core.display_forums_modify_template_vars', compact($vars))); $template->assign_block_vars('forumrow', $forum_row); // Assign subforums loop for style authors - foreach ($subforums_list as $subforum) - { - $template->assign_block_vars('forumrow.subforum', array( - 'U_SUBFORUM' => $subforum['link'], - 'SUBFORUM_NAME' => $subforum['name'], - 'S_UNREAD' => $subforum['unread']) - ); - } + $template->assign_block_vars_array('forumrow.subforum', $subforums_row); + + /** + * Modify and/or assign additional template data for the forum + * after forumrow loop has been assigned. This can be used + * to create additional forumrow subloops in extensions. + * + * This event is triggered once per forum + * + * @event core.display_forums_add_template_data + * @var array forum_row Template data of the forum + * @var array row The data of the forum + * @var array subforums_list The data of subforums + * @var array subforums_row Template data of subforums + * @var bool catless The flag indicating whether a forum has a parent category + * @since 3.1.0-b5 + */ + $vars = array( + 'forum_row', + 'row', + 'subforums_list', + 'subforums_row', + 'catless', + ); + extract($phpbb_dispatcher->trigger_event('core.display_forums_add_template_data', compact($vars))); $last_catless = $catless; } @@ -594,9 +688,31 @@ function display_forums($root_data = '', $display_moderators = true, $return_mod 'L_SUBFORUM' => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'], 'LAST_POST_IMG' => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'), 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', 'TOPICS_UNAPPROVED'), - 'UNAPPROVED_POST_IMG' => $user->img('icon_topic_unapproved', 'POSTS_UNAPPROVED'), + 'UNAPPROVED_POST_IMG' => $user->img('icon_topic_unapproved', 'POSTS_UNAPPROVED_FORUM'), )); + /** + * Event to perform additional actions after the forum list has been generated + * + * @event core.display_forums_after + * @var array active_forum_ary Array with forum data to display active topics + * @var bool display_moderators Flag indicating if we display forum moderators + * @var array forum_moderators Array with forum moderators list + * @var array forum_rows Data array of all forums we display + * @var bool return_moderators Flag indicating if moderators list should be returned + * @var array root_data Array with the root forum data + * @since 3.1.0-RC5 + */ + $vars = array( + 'active_forum_ary', + 'display_moderators', + 'forum_moderators', + 'forum_rows', + 'return_moderators', + 'root_data', + ); + extract($phpbb_dispatcher->trigger_event('core.display_forums_after', compact($vars))); + if ($return_moderators) { return array($active_forum_ary, $forum_moderators); @@ -615,7 +731,7 @@ function generate_forum_rules(&$forum_data) return; } - global $template, $phpbb_root_path, $phpEx; + global $template; if ($forum_data['forum_rules']) { @@ -633,18 +749,22 @@ function generate_forum_rules(&$forum_data) * Create forum navigation links for given forum, create parent * list if currently null, assign basic forum info to template */ -function generate_forum_nav(&$forum_data) +function generate_forum_nav(&$forum_data_ary) { - global $db, $user, $template, $auth, $config; - global $phpEx, $phpbb_root_path; + global $template, $auth, $config; + global $phpEx, $phpbb_root_path, $phpbb_dispatcher; - if (!$auth->acl_get('f_list', $forum_data['forum_id'])) + if (!$auth->acl_get('f_list', $forum_data_ary['forum_id'])) { return; } + $navlinks_parents = $forum_template_data = array(); + // Get forum parents - $forum_parents = get_forum_parents($forum_data); + $forum_parents = get_forum_parents($forum_data_ary); + + $microdata_attr = 'data-forum-id'; // Build navigation links if (!empty($forum_parents)) @@ -659,33 +779,62 @@ function generate_forum_nav(&$forum_data) continue; } - $template->assign_block_vars('navlinks', array( + $navlinks_parents[] = array( 'S_IS_CAT' => ($parent_type == FORUM_CAT) ? true : false, 'S_IS_LINK' => ($parent_type == FORUM_LINK) ? true : false, 'S_IS_POST' => ($parent_type == FORUM_POST) ? true : false, 'FORUM_NAME' => $parent_name, 'FORUM_ID' => $parent_forum_id, - 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id)) + 'MICRODATA' => $microdata_attr . '="' . $parent_forum_id . '"', + 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id), ); } } - $template->assign_block_vars('navlinks', array( - 'S_IS_CAT' => ($forum_data['forum_type'] == FORUM_CAT) ? true : false, - 'S_IS_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false, - 'S_IS_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false, - 'FORUM_NAME' => $forum_data['forum_name'], - 'FORUM_ID' => $forum_data['forum_id'], - 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data['forum_id'])) + $navlinks = array( + 'S_IS_CAT' => ($forum_data_ary['forum_type'] == FORUM_CAT) ? true : false, + 'S_IS_LINK' => ($forum_data_ary['forum_type'] == FORUM_LINK) ? true : false, + 'S_IS_POST' => ($forum_data_ary['forum_type'] == FORUM_POST) ? true : false, + 'FORUM_NAME' => $forum_data_ary['forum_name'], + 'FORUM_ID' => $forum_data_ary['forum_id'], + 'MICRODATA' => $microdata_attr . '="' . $forum_data_ary['forum_id'] . '"', + 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data_ary['forum_id']), ); - $template->assign_vars(array( - 'FORUM_ID' => $forum_data['forum_id'], - 'FORUM_NAME' => $forum_data['forum_name'], - 'FORUM_DESC' => generate_text_for_display($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options']), + $forum_template_data = array( + 'FORUM_ID' => $forum_data_ary['forum_id'], + 'FORUM_NAME' => $forum_data_ary['forum_name'], + 'FORUM_DESC' => generate_text_for_display($forum_data_ary['forum_desc'], $forum_data_ary['forum_desc_uid'], $forum_data_ary['forum_desc_bitfield'], $forum_data_ary['forum_desc_options']), - 'S_ENABLE_FEEDS_FORUM' => ($config['feed_forum'] && $forum_data['forum_type'] == FORUM_POST && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $forum_data['forum_options'])) ? true : false, - )); + 'S_ENABLE_FEEDS_FORUM' => ($config['feed_forum'] && $forum_data_ary['forum_type'] == FORUM_POST && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $forum_data_ary['forum_options'])) ? true : false, + ); + + $forum_data = $forum_data_ary; + /** + * Event to modify the navlinks text + * + * @event core.generate_forum_nav + * @var array forum_data Array with the forum data + * @var array forum_template_data Array with generic forum template data + * @var string microdata_attr The microdata attribute + * @var array navlinks_parents Array with the forum parents navlinks data + * @var array navlinks Array with the forum navlinks data + * @since 3.1.5-RC1 + */ + $vars = array( + 'forum_data', + 'forum_template_data', + 'microdata_attr', + 'navlinks_parents', + 'navlinks', + ); + extract($phpbb_dispatcher->trigger_event('core.generate_forum_nav', compact($vars))); + $forum_data_ary = $forum_data; + unset($forum_data); + + $template->assign_block_vars_array('navlinks', $navlinks_parents); + $template->assign_block_vars('navlinks', $navlinks); + $template->assign_vars($forum_template_data); return; } @@ -737,7 +886,8 @@ function get_forum_parents(&$forum_data) */ function get_moderators(&$forum_moderators, $forum_id = false) { - global $config, $template, $db, $phpbb_root_path, $phpEx, $user, $auth; + global $db, $phpbb_root_path, $phpEx, $user, $auth; + global $phpbb_container; $forum_id_ary = array(); @@ -773,6 +923,9 @@ function get_moderators(&$forum_moderators, $forum_id = false) 'WHERE' => 'm.display_on_index = 1', ); + /** @var \phpbb\group\helper $group_helper */ + $group_helper = $phpbb_container->get('group_helper'); + // We query every forum here because for caching we should not have any parameter. $sql = $db->sql_build_query('SELECT', $sql_array); $result = $db->sql_query($sql, 3600); @@ -792,7 +945,7 @@ function get_moderators(&$forum_moderators, $forum_id = false) } else { - $group_name = (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']); + $group_name = $group_helper->get_name($row['group_name']); if ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile')) { @@ -849,8 +1002,6 @@ function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$fold { global $user, $config; - $folder = $folder_new = ''; - if ($topic_row['topic_status'] == ITEM_MOVED) { $topic_type = $user->lang['VIEW_TOPIC_MOVED']; @@ -900,7 +1051,6 @@ function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$fold $folder_new .= '_locked'; } - $folder_img = ($unread_topic) ? $folder_new : $folder; $folder_alt = ($unread_topic) ? 'UNREAD_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_UNREAD_POSTS'); @@ -962,6 +1112,7 @@ function display_custom_bbcodes() 'BBCODE_NAME' => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'", 'BBCODE_ID' => $num_predefined_bbcodes + ($i * 2), 'BBCODE_TAG' => $row['bbcode_tag'], + 'BBCODE_TAG_CLEAN' => str_replace('=', '-', $row['bbcode_tag']), 'BBCODE_HELPLINE' => $row['bbcode_helpline'], 'A_BBCODE_HELPLINE' => str_replace(array('&', '"', "'", '<', '>'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']), ); @@ -974,7 +1125,7 @@ function display_custom_bbcodes() * @event core.display_custom_bbcodes_modify_row * @var array custom_tags Template data of the bbcode * @var array row The data of the bbcode - * @since 3.1-A1 + * @since 3.1.0-a1 */ $vars = array('custom_tags', 'row'); extract($phpbb_dispatcher->trigger_event('core.display_custom_bbcodes_modify_row', compact($vars))); @@ -989,52 +1140,34 @@ function display_custom_bbcodes() * Display custom bbcodes * * @event core.display_custom_bbcodes - * @since 3.1-A1 + * @since 3.1.0-a1 */ $phpbb_dispatcher->dispatch('core.display_custom_bbcodes'); } /** * Display reasons +* +* @deprecated 3.2.0-dev */ function display_reasons($reason_id = 0) { - global $db, $user, $template; - - $sql = 'SELECT * - FROM ' . REPORTS_REASONS_TABLE . ' - ORDER BY reason_order ASC'; - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - // If the reason is defined within the language file, we will use the localized version, else just use the database entry... - if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])])) - { - $row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]; - $row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]; - } + global $phpbb_container; - $template->assign_block_vars('reason', array( - 'ID' => $row['reason_id'], - 'TITLE' => $row['reason_title'], - 'DESCRIPTION' => $row['reason_description'], - 'S_SELECTED' => ($row['reason_id'] == $reason_id) ? true : false) - ); - } - $db->sql_freeresult($result); + $phpbb_container->get('phpbb.report.report_reason_list_provider')->display_reasons($reason_id); } /** * Display user activity (action forum/topic) */ -function display_user_activity(&$userdata) +function display_user_activity(&$userdata_ary) { global $auth, $template, $db, $user; - global $phpbb_root_path, $phpEx, $phpbb_container; + global $phpbb_root_path, $phpEx; + global $phpbb_container, $phpbb_dispatcher; // Do not display user activity for users having more than 5000 posts... - if ($userdata['user_posts'] > 5000) + if ($userdata_ary['user_posts'] > 5000) { return; } @@ -1055,12 +1188,13 @@ function display_user_activity(&$userdata) $active_f_row = $active_t_row = array(); if (!empty($forum_ary)) { + /* @var $phpbb_content_visibility \phpbb\content_visibility */ $phpbb_content_visibility = $phpbb_container->get('content.visibility'); // Obtain active forum $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts FROM ' . POSTS_TABLE . ' - WHERE poster_id = ' . $userdata['user_id'] . ' + WHERE poster_id = ' . $userdata_ary['user_id'] . ' AND post_postcount = 1 AND ' . $phpbb_content_visibility->get_forums_visibility_sql('post', $forum_ary) . ' GROUP BY forum_id @@ -1082,7 +1216,7 @@ function display_user_activity(&$userdata) // Obtain active topic $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts FROM ' . POSTS_TABLE . ' - WHERE poster_id = ' . $userdata['user_id'] . ' + WHERE poster_id = ' . $userdata_ary['user_id'] . ' AND post_postcount = 1 AND ' . $phpbb_content_visibility->get_forums_visibility_sql('post', $forum_ary) . ' GROUP BY topic_id @@ -1102,8 +1236,23 @@ function display_user_activity(&$userdata) } } - $userdata['active_t_row'] = $active_t_row; - $userdata['active_f_row'] = $active_f_row; + $userdata = $userdata_ary; + /** + * Alter list of forums and topics to display as active + * + * @event core.display_user_activity_modify_actives + * @var array userdata User's data + * @var array active_f_row List of active forums + * @var array active_t_row List of active posts + * @since 3.1.0-RC3 + */ + $vars = array('userdata', 'active_f_row', 'active_t_row'); + extract($phpbb_dispatcher->trigger_event('core.display_user_activity_modify_actives', compact($vars))); + $userdata_ary = $userdata; + unset($userdata); + + $userdata_ary['active_t_row'] = $active_t_row; + $userdata_ary['active_f_row'] = $active_f_row; $active_f_name = $active_f_id = $active_f_count = $active_f_pct = ''; if (!empty($active_f_row['num_posts'])) @@ -1111,7 +1260,7 @@ function display_user_activity(&$userdata) $active_f_name = $active_f_row['forum_name']; $active_f_id = $active_f_row['forum_id']; $active_f_count = $active_f_row['num_posts']; - $active_f_pct = ($userdata['user_posts']) ? ($active_f_count / $userdata['user_posts']) * 100 : 0; + $active_f_pct = ($userdata_ary['user_posts']) ? ($active_f_count / $userdata_ary['user_posts']) * 100 : 0; } $active_t_name = $active_t_id = $active_t_count = $active_t_pct = ''; @@ -1120,10 +1269,10 @@ function display_user_activity(&$userdata) $active_t_name = $active_t_row['topic_title']; $active_t_id = $active_t_row['topic_id']; $active_t_count = $active_t_row['num_posts']; - $active_t_pct = ($userdata['user_posts']) ? ($active_t_count / $userdata['user_posts']) * 100 : 0; + $active_t_pct = ($userdata_ary['user_posts']) ? ($active_t_count / $userdata_ary['user_posts']) * 100 : 0; } - $l_active_pct = ($userdata['user_id'] != ANONYMOUS && $userdata['user_id'] == $user->data['user_id']) ? $user->lang['POST_PCT_ACTIVE_OWN'] : $user->lang['POST_PCT_ACTIVE']; + $l_active_pct = ($userdata_ary['user_id'] != ANONYMOUS && $userdata_ary['user_id'] == $user->data['user_id']) ? $user->lang['POST_PCT_ACTIVE_OWN'] : $user->lang['POST_PCT_ACTIVE']; $template->assign_vars(array( 'ACTIVE_FORUM' => $active_f_name, @@ -1143,7 +1292,7 @@ function display_user_activity(&$userdata) */ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0, $item_title = '') { - global $template, $db, $user, $phpEx, $start, $phpbb_root_path; + global $db, $user, $phpEx, $start, $phpbb_root_path; global $request; $table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE; @@ -1153,7 +1302,7 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, $u_url .= ($mode == 'forum') ? '&f' : '&f=' . $forum_id . '&t'; $is_watching = 0; - // Is user watching this thread? + // Is user watching this topic? if ($user_id != ANONYMOUS) { $can_watch = true; @@ -1174,8 +1323,8 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, { if (isset($_GET['unwatch'])) { - $uid = request_var('uid', 0); - $token = request_var('hash', ''); + $uid = $request->variable('uid', 0); + $token = $request->variable('hash', ''); if ($token && check_link_hash($token, "{$mode}_$match_id") || confirm_box(true)) { @@ -1248,8 +1397,8 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, { if (isset($_GET['watch'])) { - $uid = request_var('uid', 0); - $token = request_var('hash', ''); + $uid = $request->variable('uid', 0); + $token = $request->variable('hash', ''); if ($token && check_link_hash($token, "{$mode}_$match_id") || confirm_box(true)) { @@ -1333,17 +1482,34 @@ function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, /** * Get user rank title and image * -* @param int $user_rank the current stored users rank id +* @param array $user_data the current stored users data * @param int $user_posts the users number of posts -* @param string &$rank_title the rank title will be stored here after execution -* @param string &$rank_img the rank image as full img tag is stored here after execution -* @param string &$rank_img_src the rank image source is stored here after execution +* +* @return array An associative array containing the rank title (title), the rank image as full img tag (img) and the rank image source (img_src) * * Note: since we do not want to break backwards-compatibility, this function will only properly assign ranks to guests if you call it for them with user_posts == false */ -function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src) +function phpbb_get_user_rank($user_data, $user_posts) { - global $ranks, $config, $phpbb_root_path; + global $ranks, $config, $phpbb_root_path, $phpbb_path_helper, $phpbb_dispatcher; + + $user_rank_data = array( + 'title' => null, + 'img' => null, + 'img_src' => null, + ); + + /** + * Preparing a user's rank before displaying + * + * @event core.modify_user_rank + * @var array user_data Array with user's data + * @var int user_posts User_posts to change + * @since 3.1.0-RC4 + */ + + $vars = array('user_data', 'user_posts'); + extract($phpbb_dispatcher->trigger_event('core.modify_user_rank', compact($vars))); if (empty($ranks)) { @@ -1351,11 +1517,14 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank $ranks = $cache->obtain_ranks(); } - if (!empty($user_rank)) + if (!empty($user_data['user_rank'])) { - $rank_title = (isset($ranks['special'][$user_rank]['rank_title'])) ? $ranks['special'][$user_rank]['rank_title'] : ''; - $rank_img = (!empty($ranks['special'][$user_rank]['rank_image'])) ? '<img src="' . $phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] . '" alt="' . $ranks['special'][$user_rank]['rank_title'] . '" title="' . $ranks['special'][$user_rank]['rank_title'] . '" />' : ''; - $rank_img_src = (!empty($ranks['special'][$user_rank]['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] : ''; + + $user_rank_data['title'] = (isset($ranks['special'][$user_data['user_rank']]['rank_title'])) ? $ranks['special'][$user_data['user_rank']]['rank_title'] : ''; + + $user_rank_data['img_src'] = (!empty($ranks['special'][$user_data['user_rank']]['rank_image'])) ? $phpbb_path_helper->update_web_root_path($phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_data['user_rank']]['rank_image']) : ''; + + $user_rank_data['img'] = (!empty($ranks['special'][$user_data['user_rank']]['rank_image'])) ? '<img src="' . $user_rank_data['img_src'] . '" alt="' . $ranks['special'][$user_data['user_rank']]['rank_title'] . '" title="' . $ranks['special'][$user_data['user_rank']]['rank_title'] . '" />' : ''; } else if ($user_posts !== false) { @@ -1365,136 +1534,176 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank { if ($user_posts >= $rank['rank_min']) { - $rank_title = $rank['rank_title']; - $rank_img = (!empty($rank['rank_image'])) ? '<img src="' . $phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" />' : ''; - $rank_img_src = (!empty($rank['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image'] : ''; + $user_rank_data['title'] = $rank['rank_title']; + $user_rank_data['img_src'] = (!empty($rank['rank_image'])) ? $phpbb_path_helper->update_web_root_path($phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image']) : ''; + $user_rank_data['img'] = (!empty($rank['rank_image'])) ? '<img src="' . $user_rank_data['img_src'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" />' : ''; break; } } } } -} -/** -* Get user avatar -* -* @param array $user_row Row from the users table -* @param string $alt Optional language string for alt tag within image, can be a language key or text -* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP -* -* @return string Avatar html -*/ -function phpbb_get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false) -{ - $row = \phpbb\avatar\manager::clean_row($user_row, 'user'); - return phpbb_get_avatar($row, $alt, $ignore_config); + return $user_rank_data; } /** -* Get group avatar -* -* @param array $group_row Row from the groups table -* @param string $alt Optional language string for alt tag within image, can be a language key or text -* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP -* -* @return string Avatar html +* Prepare profile data */ -function phpbb_get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false) +function phpbb_show_profile($data, $user_notes_enabled = false, $warn_user_enabled = false, $check_can_receive_pm = true) { - $row = \phpbb\avatar\manager::clean_row($user_row, 'group'); - return phpbb_get_avatar($row, $alt, $ignore_config); -} + global $config, $auth, $user, $phpEx, $phpbb_root_path, $phpbb_dispatcher; -/** -* Get avatar -* -* @param array $row Row cleaned by \phpbb\avatar\driver\driver::clean_row -* @param string $alt Optional language string for alt tag within image, can be a language key or text -* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP -* -* @return string Avatar html -*/ -function phpbb_get_avatar($row, $alt, $ignore_config = false) -{ - global $user, $config, $cache, $phpbb_root_path, $phpEx; - global $request; - global $phpbb_container; + $username = $data['username']; + $user_id = $data['user_id']; - if (!$config['allow_avatar'] && !$ignore_config) + $user_rank_data = phpbb_get_user_rank($data, (($user_id == ANONYMOUS) ? false : $data['user_posts'])); + + if ((!empty($data['user_allow_viewemail']) && $auth->acl_get('u_sendemail')) || $auth->acl_get('a_user')) { - return ''; + $email = ($config['board_email_form'] && $config['email_enable']) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=email&u=' . $user_id) : (($config['board_hide_emails'] && !$auth->acl_get('a_user')) ? '' : 'mailto:' . $data['user_email']); + } + else + { + $email = ''; } - $avatar_data = array( - 'src' => $row['avatar'], - 'width' => $row['avatar_width'], - 'height' => $row['avatar_height'], - ); - - $phpbb_avatar_manager = $phpbb_container->get('avatar.manager'); - $driver = $phpbb_avatar_manager->get_driver($row['avatar_type'], $ignore_config); - $html = ''; - - if ($driver) + if ($config['load_onlinetrack']) { - $html = $driver->get_custom_html($user, $row, $alt); - if (!empty($html)) - { - return $html; - } + $update_time = $config['load_online_time'] * 60; + $online = (time() - $update_time < $data['session_time'] && ((isset($data['session_viewonline']) && $data['session_viewonline']) || $auth->acl_get('u_viewonline'))) ? true : false; + } + else + { + $online = false; + } - $avatar_data = $driver->get_data($row, $ignore_config); + if ($data['user_allow_viewonline'] || $auth->acl_get('u_viewonline')) + { + $last_active = (!empty($data['session_time'])) ? $data['session_time'] : $data['user_lastvisit']; } else { - $avatar_data['src'] = ''; + $last_active = ''; } - if (!empty($avatar_data['src'])) + $age = ''; + + if ($config['allow_birthdays'] && $data['user_birthday']) + { + list($bday_day, $bday_month, $bday_year) = array_map('intval', explode('-', $data['user_birthday'])); + + if ($bday_year) + { + $now = $user->create_datetime(); + $now = phpbb_gmgetdate($now->getTimestamp() + $now->getOffset()); + + $diff = $now['mon'] - $bday_month; + if ($diff == 0) + { + $diff = ($now['mday'] - $bday_day < 0) ? 1 : 0; + } + else + { + $diff = ($diff < 0) ? 1 : 0; + } + + $age = max(0, (int) ($now['year'] - $bday_year - $diff)); + } + } + + if (!function_exists('phpbb_get_banned_user_ids')) { - $html = '<img src="' . $avatar_data['src'] . '" ' . - ($avatar_data['width'] ? ('width="' . $avatar_data['width'] . '" ') : '') . - ($avatar_data['height'] ? ('height="' . $avatar_data['height'] . '" ') : '') . - 'alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />'; + include($phpbb_root_path . 'includes/functions_user.' . $phpEx); } - return $html; + // Can this user receive a Private Message? + $can_receive_pm = $check_can_receive_pm && ( + // They must be a "normal" user + $data['user_type'] != USER_IGNORE && + + // They must not be deactivated by the administrator + ($data['user_type'] != USER_INACTIVE || $data['user_inactive_reason'] != INACTIVE_MANUAL) && + + // They must be able to read PMs + sizeof($auth->acl_get_list($user_id, 'u_readpm')) && + + // They must not be permanently banned + !sizeof(phpbb_get_banned_user_ids($user_id, false)) && + + // They must allow users to contact via PM + (($auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')) || $data['user_allow_pm']) + ); + + // Dump it out to the template + $template_data = array( + 'AGE' => $age, + 'RANK_TITLE' => $user_rank_data['title'], + 'JOINED' => $user->format_date($data['user_regdate']), + 'LAST_ACTIVE' => (empty($last_active)) ? ' - ' : $user->format_date($last_active), + 'POSTS' => ($data['user_posts']) ? $data['user_posts'] : 0, + 'WARNINGS' => isset($data['user_warnings']) ? $data['user_warnings'] : 0, + + 'USERNAME_FULL' => get_username_string('full', $user_id, $username, $data['user_colour']), + 'USERNAME' => get_username_string('username', $user_id, $username, $data['user_colour']), + 'USER_COLOR' => get_username_string('colour', $user_id, $username, $data['user_colour']), + 'U_VIEW_PROFILE' => get_username_string('profile', $user_id, $username, $data['user_colour']), + + 'A_USERNAME' => addslashes(get_username_string('username', $user_id, $username, $data['user_colour'])), + + 'AVATAR_IMG' => phpbb_get_user_avatar($data), + 'ONLINE_IMG' => (!$config['load_onlinetrack']) ? '' : (($online) ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE')), + 'S_ONLINE' => ($config['load_onlinetrack'] && $online) ? true : false, + 'RANK_IMG' => $user_rank_data['img'], + 'RANK_IMG_SRC' => $user_rank_data['img_src'], + 'S_JABBER_ENABLED' => ($config['jab_enable']) ? true : false, + + 'S_WARNINGS' => ($auth->acl_getf_global('m_') || $auth->acl_get('m_warn')) ? true : false, + + 'U_SEARCH_USER' => ($auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id=$user_id&sr=posts") : '', + 'U_NOTES' => ($user_notes_enabled && $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&mode=user_notes&u=' . $user_id, true, $user->session_id) : '', + 'U_WARN' => ($warn_user_enabled && $auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&mode=warn_user&u=' . $user_id, true, $user->session_id) : '', + 'U_PM' => ($config['allow_privmsg'] && $auth->acl_get('u_sendpm') && $can_receive_pm) ? append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=compose&u=' . $user_id) : '', + 'U_EMAIL' => $email, + 'U_JABBER' => ($data['user_jabber'] && $auth->acl_get('u_sendim')) ? append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=contact&action=jabber&u=' . $user_id) : '', + + 'USER_JABBER' => ($config['jab_enable']) ? $data['user_jabber'] : '', + 'USER_JABBER_IMG' => ($config['jab_enable'] && $data['user_jabber']) ? $user->img('icon_contact_jabber', $data['user_jabber']) : '', + + 'L_SEND_EMAIL_USER' => $user->lang('SEND_EMAIL_USER', $username), + 'L_CONTACT_USER' => $user->lang('CONTACT_USER', $username), + 'L_VIEWING_PROFILE' => $user->lang('VIEWING_PROFILE', $username), + ); + + /** + * Preparing a user's data before displaying it in profile and memberlist + * + * @event core.memberlist_prepare_profile_data + * @var array data Array with user's data + * @var array template_data Template array with user's data + * @since 3.1.0-a1 + */ + $vars = array('data', 'template_data'); + extract($phpbb_dispatcher->trigger_event('core.memberlist_prepare_profile_data', compact($vars))); + + return $template_data; } -/** -* Generate a list of archive types available for compressing attachments -* -* @param string $param_key Either topic_id or post_id -* @param string $param_val The value of the topic or post id -* @param string $phpbb_root_path The root path of the phpBB installation -* @param string $phpEx The PHP extension -* -* @return array Array containing the link and the type of compression -*/ -function phpbb_gen_download_links($param_key, $param_val, $phpbb_root_path, $phpEx) +function phpbb_sort_last_active($first, $second) { - if (!class_exists('compress')) - { - require $phpbb_root_path . 'includes/functions_compress.' . $phpEx; - } + global $id_cache, $sort_dir; - $methods = compress::methods(); - // Sort by preferred type. - $methods = array_intersect(array('.zip', '.tar.bz2', '.tar.gz', '.tar'), $methods); - $links = array(); + $lesser_than = ($sort_dir === 'd') ? -1 : 1; - foreach ($methods as $method) + if (isset($id_cache[$first]['group_leader']) && $id_cache[$first]['group_leader'] && (!isset($id_cache[$second]['group_leader']) || !$id_cache[$second]['group_leader'])) { - $exploded = explode('.', $method); - $type = array_pop($exploded); - $params = array('archive' => $method); - $params[$param_key] = $param_val; - - $links[] = array( - 'LINK' => append_sid("{$phpbb_root_path}download/file.$phpEx", $params), - 'TYPE' => $type, - ); + return -1; + } + else if (isset($id_cache[$second]['group_leader']) && (!isset($id_cache[$first]['group_leader']) || !$id_cache[$first]['group_leader']) && $id_cache[$second]['group_leader']) + { + return 1; + } + else + { + return $lesser_than * (int) ($id_cache[$first]['last_visit'] - $id_cache[$second]['last_visit']); } - - return $links; } |