Advertisement
Guest User

pene

a guest
Feb 7th, 2015
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 51.84 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @package phpBB3
  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. /**
  12. * @ignore
  13. */
  14. if (!defined('IN_PHPBB'))
  15. {
  16.     exit;
  17. }
  18.  
  19. /**
  20. * Display Forums
  21. */
  22. function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
  23. {
  24.     global $db, $auth, $user, $template;
  25.     global $phpbb_root_path, $phpEx, $config;
  26.     if (isset($config['phpbbasic_forumid']) && $config['phpbbasic_forumid'])
  27.     {
  28.         if (!function_exists('display_phpbbasic_forum_topics'))
  29.         {
  30.             include($phpbb_root_path . 'includes/functions_phpbbasic.' . $phpEx);
  31.         }
  32.         display_phpbbasic_forum_topics();
  33.         return;
  34.     }
  35.     // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  36.     global $phpbb_seo;
  37.     // www.phpBB-SEO.com SEO TOOLKIT END
  38.     $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
  39.     $parent_id = $visible_forums = 0;
  40.     $sql_from = '';
  41.  
  42.     // Mark forums read?
  43.     $mark_read = request_var('mark', '');
  44.  
  45.     if ($mark_read == 'all')
  46.     {
  47.         $mark_read = '';
  48.     }
  49.  
  50.     if (!$root_data)
  51.     {
  52.         if ($mark_read == 'forums')
  53.         {
  54.             $mark_read = 'all';
  55.         }
  56.  
  57.         $root_data = array('forum_id' => 0);
  58.         $sql_where = '';
  59.     }
  60.     else
  61.     {
  62.         $sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
  63.     }
  64.  
  65.     // Handle marking everything read
  66.     if ($mark_read == 'all')
  67.     {
  68.         $redirect = build_url(array('mark', 'hash'));
  69.         meta_refresh(3, $redirect);
  70.  
  71.         if (check_link_hash(request_var('hash', ''), 'global'))
  72.         {
  73.             markread('all');
  74.  
  75.             trigger_error(
  76.                 $user->lang['FORUMS_MARKED'] . '<br /><br />' .
  77.                 sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>')
  78.             );
  79.         }
  80.         else
  81.         {
  82.             trigger_error(sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
  83.         }
  84.     }
  85.  
  86.     // Display list of active topics for this category?
  87.     $show_active = (isset($root_data['forum_flags']) && ($root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
  88.  
  89.     $sql_array = array(
  90.         'SELECT'    => 'f.*',
  91.         'FROM'      => array(
  92.             FORUMS_TABLE        => 'f'
  93.         ),
  94.         'LEFT_JOIN' => array(),
  95.     );
  96.  
  97.     if ($config['load_db_lastread'] && $user->data['is_registered'])
  98.     {
  99.         $sql_array['LEFT_JOIN'][] = array('FROM' => array(FORUMS_TRACK_TABLE => 'ft'), 'ON' => 'ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id');
  100.         $sql_array['SELECT'] .= ', ft.mark_time';
  101.     }
  102.     else if ($config['load_anon_lastread'] || $user->data['is_registered'])
  103.     {
  104.         $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
  105.         $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
  106.  
  107.         if (!$user->data['is_registered'])
  108.         {
  109.             $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
  110.         }
  111.     }
  112.  
  113.     if ($show_active)
  114.     {
  115.         $sql_array['LEFT_JOIN'][] = array(
  116.             'FROM'  => array(FORUMS_ACCESS_TABLE => 'fa'),
  117.             'ON'    => "fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "'"
  118.         );
  119.  
  120.         $sql_array['SELECT'] .= ', fa.user_id';
  121.     }
  122.     // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe
  123.     if (!empty($phpbb_seo->seo_opt['no_dupe']['on'])) {
  124.         $sql_array['SELECT'] .= ', t.topic_id, t.topic_title, t.topic_replies, t.topic_replies_real, t.topic_status, t.topic_type, t.topic_moved_id' . (!empty($phpbb_seo->seo_opt['sql_rewrite']) ? ', t.topic_url ' : ' ');
  125.         $sql_array['LEFT_JOIN'][] = array(
  126.             'FROM'  => array(TOPICS_TABLE => 't'),
  127.             'ON'    => "f.forum_last_post_id = t.topic_last_post_id"
  128.         );
  129.     }
  130.     // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe
  131.     $sql = $db->sql_build_query('SELECT', array(
  132.         'SELECT'    => $sql_array['SELECT'],
  133.         'FROM'      => $sql_array['FROM'],
  134.         'LEFT_JOIN' => $sql_array['LEFT_JOIN'],
  135.  
  136.         'WHERE'     => $sql_where,
  137.  
  138.         'ORDER_BY'  => 'f.left_id',
  139.     ));
  140.  
  141.     $result = $db->sql_query($sql);
  142.  
  143.     $forum_tracking_info = array();
  144.     $branch_root_id = $root_data['forum_id'];
  145.  
  146.     // Check for unread global announcements (index page only)
  147.     $ga_unread = false;
  148.     if ($root_data['forum_id'] == 0)
  149.     {
  150.         $unread_ga_list = get_unread_topics($user->data['user_id'], 'AND t.forum_id = 0', '', 1);
  151.  
  152.         if (!empty($unread_ga_list))
  153.         {
  154.             $ga_unread = true;
  155.         }
  156.     }
  157.  
  158.     while ($row = $db->sql_fetchrow($result))
  159.     {
  160.         $forum_id = $row['forum_id'];
  161.         // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  162.         $phpbb_seo->set_url($row['forum_name'], $forum_id, 'forum');
  163.         // www.phpBB-SEO.com SEO TOOLKIT END
  164.         // Mark forums read?
  165.         if ($mark_read == 'forums')
  166.         {
  167.             if ($auth->acl_get('f_list', $forum_id))
  168.             {
  169.                 $forum_ids[] = $forum_id;
  170.             }
  171.  
  172.             continue;
  173.         }
  174.  
  175.         // Category with no members
  176.         if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
  177.         {
  178.             continue;
  179.         }
  180.  
  181.         // Skip branch
  182.         if (isset($right_id))
  183.         {
  184.             if ($row['left_id'] < $right_id)
  185.             {
  186.                 continue;
  187.             }
  188.             unset($right_id);
  189.         }
  190.  
  191.         if (!$auth->acl_get('f_list', $forum_id))
  192.         {
  193.             // if the user does not have permissions to list this forum, skip everything until next branch
  194.             $right_id = $row['right_id'];
  195.             continue;
  196.         }
  197.  
  198.         if ($config['load_db_lastread'] && $user->data['is_registered'])
  199.         {
  200.             $forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
  201.         }
  202.         else if ($config['load_anon_lastread'] || $user->data['is_registered'])
  203.         {
  204.             if (!$user->data['is_registered'])
  205.             {
  206.                 $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
  207.             }
  208.             $forum_tracking_info[$forum_id] = (isset($tracking_topics['f'][$forum_id])) ? (int) (base_convert($tracking_topics['f'][$forum_id], 36, 10) + $config['board_startdate']) : $user->data['user_lastmark'];
  209.         }
  210.  
  211.         // Count the difference of real to public topics, so we can display an information to moderators
  212.         $row['forum_id_unapproved_topics'] = ($auth->acl_get('m_approve', $forum_id) && ($row['forum_topics_real'] != $row['forum_topics'])) ? $forum_id : 0;
  213.         // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe
  214.         if (!empty($phpbb_seo->seo_opt['no_dupe']['on'])) {
  215.             if ($row['topic_status'] == ITEM_MOVED) {
  216.                 $row['topic_id'] = $row['topic_moved_id'];
  217.             }
  218.             $phpbb_seo->seo_opt['topic_forum_name'][$row['topic_id']] = $row['forum_name'];
  219.             if ($auth->acl_get('m_approve', $forum_id)) {
  220.                 $row['forum_topics'] = $row['forum_topics_real'];
  221.                 $replies = $row['topic_replies_real'];
  222.             } else {
  223.                 $row['forum_topics'] = $row['forum_topics'];
  224.                 $replies = $row['topic_replies'];
  225.             }
  226.             if (($replies + 1) > $phpbb_seo->seo_opt['topic_per_page']) {
  227.                 $phpbb_seo->seo_opt['topic_last_page'][$row['topic_id']] = floor($replies / $phpbb_seo->seo_opt['topic_per_page']) * $phpbb_seo->seo_opt['topic_per_page'];
  228.             }
  229.         } else {
  230.             $row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics'];
  231.         }
  232.         // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe
  233.  
  234.         // Display active topics from this forum?
  235.         if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS))
  236.         {
  237.             if (!isset($active_forum_ary['forum_topics']))
  238.             {
  239.                 $active_forum_ary['forum_topics'] = 0;
  240.             }
  241.  
  242.             if (!isset($active_forum_ary['forum_posts']))
  243.             {
  244.                 $active_forum_ary['forum_posts'] = 0;
  245.             }
  246.  
  247.             $active_forum_ary['forum_id'][]     = $forum_id;
  248.             $active_forum_ary['enable_icons'][] = $row['enable_icons'];
  249.             $active_forum_ary['forum_topics']   += $row['forum_topics'];
  250.             $active_forum_ary['forum_posts']    += $row['forum_posts'];
  251.  
  252.             // If this is a passworded forum we do not show active topics from it if the user is not authorised to view it...
  253.             if ($row['forum_password'] && $row['user_id'] != $user->data['user_id'])
  254.             {
  255.                 $active_forum_ary['exclude_forum_id'][] = $forum_id;
  256.             }
  257.         }
  258.  
  259.         //
  260.         if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id)
  261.         {
  262.             if ($row['forum_type'] != FORUM_CAT)
  263.             {
  264.                 $forum_ids_moderator[] = (int) $forum_id;
  265.             }
  266.  
  267.             // Direct child of current branch
  268.             $parent_id = $forum_id;
  269.             $forum_rows[$forum_id] = $row;
  270.  
  271.             if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id'])
  272.             {
  273.                 $branch_root_id = $forum_id;
  274.             }
  275.             $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
  276.             $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
  277.         }
  278.         else if ($row['forum_type'] != FORUM_CAT)
  279.         {
  280.             $subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index']) ? true : false;
  281.             $subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
  282.             $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
  283.             $subforums[$parent_id][$forum_id]['children'] = array();
  284.  
  285.             if (isset($subforums[$parent_id][$row['parent_id']]) && !$row['display_on_index'])
  286.             {
  287.                 $subforums[$parent_id][$row['parent_id']]['children'][] = $forum_id;
  288.             }
  289.  
  290.             if (!$forum_rows[$parent_id]['forum_id_unapproved_topics'] && $row['forum_id_unapproved_topics'])
  291.             {
  292.                 $forum_rows[$parent_id]['forum_id_unapproved_topics'] = $forum_id;
  293.             }
  294.  
  295.             $forum_rows[$parent_id]['forum_topics'] += $row['forum_topics'];
  296.  
  297.             // Do not list redirects in LINK Forums as Posts.
  298.             if ($row['forum_type'] != FORUM_LINK)
  299.             {
  300.                 $forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
  301.             }
  302.  
  303.             if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time'])
  304.             {
  305.                 $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
  306.                 $forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject'];
  307.                 $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
  308.                 $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
  309.                 $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
  310.                 $forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour'];
  311.                 $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
  312.                 // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe
  313.                 if (!empty($phpbb_seo->seo_opt['no_dupe']['on'])) {
  314.                     $forum_rows[$parent_id]['topic_id'] = $row['topic_id'];
  315.                     $forum_rows[$parent_id]['topic_title'] = $row['topic_title'];
  316.                     $forum_rows[$parent_id]['topic_type'] = $row['topic_type'];
  317.                     $forum_rows[$parent_id]['forum_password'] = $row['forum_password'];
  318.                     $forum_rows[$parent_id]['topic_url'] = isset($row['topic_url']) ? $row['topic_url'] : '';
  319.                 }
  320.                 // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe
  321.             }
  322.         }
  323.     }
  324.     $db->sql_freeresult($result);
  325.  
  326.     // Handle marking posts
  327.     if ($mark_read == 'forums')
  328.     {
  329.         $redirect = build_url(array('mark', 'hash'));
  330.         $token = request_var('hash', '');
  331.         if (check_link_hash($token, 'global'))
  332.         {
  333.             // Add 0 to forums array to mark global announcements correctly
  334.             $forum_ids[] = 0;
  335.             markread('topics', $forum_ids);
  336.             $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
  337.             meta_refresh(3, $redirect);
  338.             trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message);
  339.         }
  340.         else
  341.         {
  342.             $message = sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>');
  343.             meta_refresh(3, $redirect);
  344.             trigger_error($message);
  345.         }
  346.  
  347.     }
  348.  
  349.     // Grab moderators ... if necessary
  350.     if ($display_moderators)
  351.     {
  352.         if ($return_moderators)
  353.         {
  354.             $forum_ids_moderator[] = $root_data['forum_id'];
  355.         }
  356.         get_moderators($forum_moderators, $forum_ids_moderator);
  357.     }
  358.  
  359.     // Used to tell whatever we have to create a dummy category or not.
  360.     $last_catless = true;
  361.     foreach ($forum_rows as $row)
  362.     {
  363.         // Empty category
  364.         if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT)
  365.         {
  366.             $template->assign_block_vars('forumrow', array(
  367.                 'S_IS_CAT'              => true,
  368.                 'FORUM_ID'              => $row['forum_id'],
  369.                 'FORUM_NAME'            => $row['forum_name'],
  370.                 'FORUM_DESC'            => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
  371.                 'FORUM_FOLDER_IMG'      => '',
  372.                 'FORUM_FOLDER_IMG_SRC'  => '',
  373.                 'FORUM_IMAGE'           => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '',
  374.                 'FORUM_IMAGE_SRC'       => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
  375.                 'U_VIEWFORUM'           => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
  376.             );
  377.  
  378.             continue;
  379.         }
  380.  
  381.         $visible_forums++;
  382.         $forum_id = $row['forum_id'];
  383.  
  384.         $forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false;
  385.  
  386.         // Mark the first visible forum on index as unread if there's any unread global announcement
  387.         if ($ga_unread && !empty($forum_ids_moderator) && $forum_id == $forum_ids_moderator[0])
  388.         {
  389.             $forum_unread = true;
  390.         }
  391.  
  392.         $folder_image = $folder_alt = $l_subforums = '';
  393.         $subforums_list = array();
  394.  
  395.         // Generate list of subforums if we need to
  396.         if (isset($subforums[$forum_id]))
  397.         {
  398.             foreach ($subforums[$forum_id] as $subforum_id => $subforum_row)
  399.             {
  400.                 $subforum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ? true : false;
  401.  
  402.                 if (!$subforum_unread && !empty($subforum_row['children']))
  403.                 {
  404.                     foreach ($subforum_row['children'] as $child_id)
  405.                     {
  406.                         if (isset($forum_tracking_info[$child_id]) && $subforums[$forum_id][$child_id]['orig_forum_last_post_time'] > $forum_tracking_info[$child_id])
  407.                         {
  408.                             // Once we found an unread child forum, we can drop out of this loop
  409.                             $subforum_unread = true;
  410.                             break;
  411.                         }
  412.                     }
  413.                 }
  414.  
  415.                 if ($subforum_row['display'] && $subforum_row['name'])
  416.                 {
  417.                     $subforums_list[] = array(
  418.                         'link'      => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $subforum_id),
  419.                         'name'      => $subforum_row['name'],
  420.                         'unread'    => $subforum_unread,
  421.                     );
  422.                 }
  423.                 else
  424.                 {
  425.                     unset($subforums[$forum_id][$subforum_id]);
  426.                 }
  427.  
  428.                 // If one subforum is unread the forum gets unread too...
  429.                 if ($subforum_unread)
  430.                 {
  431.                     $forum_unread = true;
  432.                 }
  433.             }
  434.  
  435.             $l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
  436.             $folder_image = ($forum_unread) ? 'forum_unread_subforum' : 'forum_read_subforum';
  437.         }
  438.         else
  439.         {
  440.             switch ($row['forum_type'])
  441.             {
  442.                 case FORUM_POST:
  443.                     $folder_image = ($forum_unread) ? 'forum_unread' : 'forum_read';
  444.                 break;
  445.  
  446.                 case FORUM_LINK:
  447.                     $folder_image = 'forum_link';
  448.                 break;
  449.             }
  450.         }
  451.  
  452.         // Which folder should we display?
  453.         if ($row['forum_status'] == ITEM_LOCKED)
  454.         {
  455.             $folder_image = ($forum_unread) ? 'forum_unread_locked' : 'forum_read_locked';
  456.             $folder_alt = 'FORUM_LOCKED';
  457.         }
  458.         else
  459.         {
  460.             $folder_alt = ($forum_unread) ? 'UNREAD_POSTS' : 'NO_UNREAD_POSTS';
  461.         }
  462.  
  463.         // Create last post link information, if appropriate
  464.         if ($row['forum_last_post_id'])
  465.         {
  466.             $last_post_subject = $row['forum_last_post_subject'];
  467.             $last_post_time = $user->format_date($row['forum_last_post_time']);
  468.             // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe
  469.             if (!empty($phpbb_seo->seo_opt['no_dupe']['on']) && !$row['forum_password'] && $auth->acl_get('f_read', $row['forum_id_last_post'])) {
  470.                 $phpbb_seo->prepare_iurl($row, 'topic', $row['topic_type'] == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$row['forum_id_last_post']]);
  471.                 $last_post_url =  append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&amp;t=' . $row['topic_id'] . '&amp;start=' . @intval($phpbb_seo->seo_opt['topic_last_page'][$row['topic_id']]) ) . '#p' . $row['forum_last_post_id'];
  472.                 $topic_title = censor_text($row['topic_title']);
  473.                 // Limit in chars for the last post link text.
  474.                 $char_limit = 25;
  475.                 // Limit topic text link to $char_limit, without breacking words
  476.                 $topic_text_lilnk = $char_limit > 0 && ( ( $length = utf8_strlen($topic_title) ) > $char_limit ) ? ( utf8_strlen($fragment = utf8_substr($topic_title, 0, $char_limit + 1 - 4)) < $length + 1 ? preg_replace('`\s*\S*$`', '', $fragment) . ' ...' : $topic_title ) : $topic_title;
  477.                 $last_post_link = '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&amp;t=' . $row['topic_id']) . '" title="' . $topic_title . ' : ' . $phpbb_seo->seo_opt['topic_forum_name'][$row['topic_id']] . '">' . $topic_text_lilnk . '</a>';
  478.             } else {
  479.                 $last_post_url =  append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id_last_post'] . '&amp;p=' . $row['forum_last_post_id']) . '#p' . $row['forum_last_post_id'];
  480.                 $last_post_link = '';
  481.             }
  482.         }
  483.         else
  484.         {
  485.             $last_post_subject = $last_post_time = $last_post_url = $last_post_link = '';
  486.             // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe
  487.         }
  488.  
  489.         // Output moderator listing ... if applicable
  490.         $l_moderator = $moderators_list = '';
  491.         if ($display_moderators && !empty($forum_moderators[$forum_id]))
  492.         {
  493.             $l_moderator = (sizeof($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
  494.             $moderators_list = implode(', ', $forum_moderators[$forum_id]);
  495.         }
  496.  
  497.         $l_post_click_count = ($row['forum_type'] == FORUM_LINK) ? 'CLICKS' : 'POSTS';
  498.         $post_click_count = ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? $row['forum_posts'] : '';
  499.  
  500.         $s_subforums_list = array();
  501.         foreach ($subforums_list as $subforum)
  502.         {
  503.             $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>';
  504.         }
  505.         $s_subforums_list = (string) implode(', ', $s_subforums_list);
  506.         $catless = ($row['parent_id'] == $root_data['forum_id']) ? true : false;
  507.  
  508.         if ($row['forum_type'] != FORUM_LINK)
  509.         {
  510.             $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
  511.         }
  512.         else
  513.         {
  514.             // If the forum is a link and we count redirects we need to visit it
  515.             // If the forum is having a password or no read access we do not expose the link, but instead handle it in viewforum
  516.             if (($row['forum_flags'] & FORUM_FLAG_LINK_TRACK) || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id))
  517.             {
  518.                 $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
  519.             }
  520.             else
  521.             {
  522.                 $u_viewforum = $row['forum_link'];
  523.             }
  524.         }
  525.  
  526.         $template->assign_block_vars('forumrow', array(
  527.             'S_IS_CAT'          => false,
  528.             'S_NO_CAT'          => $catless && !$last_catless,
  529.             'S_IS_LINK'         => ($row['forum_type'] == FORUM_LINK) ? true : false,
  530.             'S_UNREAD_FORUM'    => $forum_unread,
  531.             'S_AUTH_READ'       => $auth->acl_get('f_read', $row['forum_id']),
  532.             'S_LOCKED_FORUM'    => ($row['forum_status'] == ITEM_LOCKED) ? true : false,
  533.             'S_LIST_SUBFORUMS'  => ($row['display_subforum_list']) ? true : false,
  534.             'S_SUBFORUMS'       => (sizeof($subforums_list)) ? true : false,
  535.             'S_FEED_ENABLED'    => ($config['feed_forum'] && !phpbb_optionget(FORUM_OPTION_FEED_EXCLUDE, $row['forum_options']) && $row['forum_type'] == FORUM_POST) ? true : false,
  536.  
  537.             'FORUM_ID'              => $row['forum_id'],
  538.             'FORUM_NAME'            => $row['forum_name'],
  539.             'FORUM_DESC'            => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
  540.             'TOPICS'                => $row['forum_topics'],
  541.             $l_post_click_count     => $post_click_count,
  542.             'FORUM_FOLDER_IMG'      => $user->img($folder_image, $folder_alt),
  543.             'FORUM_FOLDER_IMG_SRC'  => $user->img($folder_image, $folder_alt, false, '', 'src'),
  544.             'FORUM_FOLDER_IMG_ALT'  => isset($user->lang[$folder_alt]) ? $user->lang[$folder_alt] : '',
  545.             'FORUM_IMAGE'           => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
  546.             'FORUM_IMAGE_SRC'       => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
  547.             'LAST_POST_SUBJECT'     => censor_text($last_post_subject),
  548.             'LAST_POST_TIME'        => $last_post_time,
  549.             'LAST_POSTER'           => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  550.             'LAST_POSTER_COLOUR'    => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  551.             'LAST_POSTER_FULL'      => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  552.             'MODERATORS'            => $moderators_list,
  553.             'SUBFORUMS'             => $s_subforums_list,
  554.  
  555.             'L_SUBFORUM_STR'        => $l_subforums,
  556.             'L_MODERATOR_STR'       => $l_moderator,
  557.  
  558.             'U_UNAPPROVED_TOPICS'   => ($row['forum_id_unapproved_topics']) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=unapproved_topics&amp;f=' . $row['forum_id_unapproved_topics']) : '',
  559.             'U_VIEWFORUM'       => $u_viewforum,
  560.             'U_LAST_POSTER'     => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
  561.             // www.phpBB-SEO.com SEO TOOLKIT BEGIN -> no dupe
  562.             'LAST_POST_LINK'    => $last_post_link,
  563.             // www.phpBB-SEO.com SEO TOOLKIT END -> no dupe
  564.             'U_LAST_POST'       => $last_post_url)
  565.         );
  566.  
  567.         // Assign subforums loop for style authors
  568.         foreach ($subforums_list as $subforum)
  569.         {
  570.             $template->assign_block_vars('forumrow.subforum', array(
  571.                 'U_SUBFORUM'    => $subforum['link'],
  572.                 'SUBFORUM_NAME' => $subforum['name'],
  573.                 'S_UNREAD'      => $subforum['unread'])
  574.             );
  575.         }
  576.  
  577.         $last_catless = $catless;
  578.     }
  579.  
  580.     $template->assign_vars(array(
  581.         'U_MARK_FORUMS'     => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'hash=' . generate_link_hash('global') . '&amp;f=' . $root_data['forum_id'] . '&amp;mark=forums') : '',
  582.         'S_HAS_SUBFORUM'    => ($visible_forums) ? true : false,
  583.         'L_SUBFORUM'        => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'],
  584.         'LAST_POST_IMG'     => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'),
  585.         'UNAPPROVED_IMG'    => $user->img('icon_topic_unapproved', 'TOPICS_UNAPPROVED'),
  586.     ));
  587.  
  588.     if ($return_moderators)
  589.     {
  590.         return array($active_forum_ary, $forum_moderators);
  591.     }
  592.  
  593.     return array($active_forum_ary, array());
  594. }
  595.  
  596. /**
  597. * Create forum rules for given forum
  598. */
  599. function generate_forum_rules(&$forum_data)
  600. {
  601.     if (!$forum_data['forum_rules'] && !$forum_data['forum_rules_link'])
  602.     {
  603.         return;
  604.     }
  605.  
  606.     global $template, $phpbb_root_path, $phpEx;
  607.  
  608.     if ($forum_data['forum_rules'])
  609.     {
  610.         $forum_data['forum_rules'] = generate_text_for_display($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options']);
  611.     }
  612.  
  613.     $template->assign_vars(array(
  614.         'S_FORUM_RULES' => true,
  615.         'U_FORUM_RULES' => $forum_data['forum_rules_link'],
  616.         'FORUM_RULES'   => $forum_data['forum_rules'])
  617.     );
  618. }
  619.  
  620. /**
  621. * Create forum navigation links for given forum, create parent
  622. * list if currently null, assign basic forum info to template
  623. */
  624. function generate_forum_nav(&$forum_data)
  625. {
  626.     global $db, $user, $template, $auth, $config;
  627.     global $phpEx, $phpbb_root_path;
  628.     // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  629.     global $phpbb_seo;
  630.     // www.phpBB-SEO.com SEO TOOLKIT END
  631.     if (!$auth->acl_get('f_list', $forum_data['forum_id']))
  632.     {
  633.         return;
  634.     }
  635. if (!isset($config['phpbbasic_forumid']) || !$config['phpbbasic_forumid'])
  636.     {
  637.     // Get forum parents
  638.     $forum_parents = get_forum_parents($forum_data);
  639.  
  640.     // Build navigation links
  641.     if (!empty($forum_parents))
  642.     {
  643.         foreach ($forum_parents as $parent_forum_id => $parent_data)
  644.         {
  645.             list($parent_name, $parent_type) = array_values($parent_data);
  646.             // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  647.             $phpbb_seo->set_url($parent_name, $parent_forum_id, 'forum');
  648.             // www.phpBB-SEO.com SEO TOOLKIT END
  649.             // Skip this parent if the user does not have the permission to view it
  650.             if (!$auth->acl_get('f_list', $parent_forum_id))
  651.             {
  652.                 continue;
  653.             }
  654.  
  655.             $template->assign_block_vars('navlinks', array(
  656.                 'S_IS_CAT'      => ($parent_type == FORUM_CAT) ? true : false,
  657.                 'S_IS_LINK'     => ($parent_type == FORUM_LINK) ? true : false,
  658.                 'S_IS_POST'     => ($parent_type == FORUM_POST) ? true : false,
  659.                 'FORUM_NAME'    => $parent_name,
  660.                 'FORUM_ID'      => $parent_forum_id,
  661.                 'U_VIEW_FORUM'  => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id))
  662.             );
  663.            
  664.     else if ((int) $forum_data['forum_id'] != (int) $config['phpbbasic_forumid'])
  665.     {
  666.         $template->assign_block_vars('navlinks', array(
  667.             'S_IS_CAT'      => false,
  668.             'S_IS_LINK'     => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
  669.             'S_IS_POST'     => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
  670.             'FORUM_NAME'    => $forum_data['forum_name'],
  671.             'FORUM_ID'      => $forum_data['forum_id'],
  672.             'U_VIEW_FORUM'  => append_sid("{$phpbb_root_path}index.$phpEx", 'f=' . $forum_data['forum_id']))
  673.         );
  674.     }
  675.         }
  676.     }
  677.  
  678.     $template->assign_block_vars('navlinks', array(
  679.         'S_IS_CAT'      => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
  680.         'S_IS_LINK'     => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
  681.         'S_IS_POST'     => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
  682.         'FORUM_NAME'    => $forum_data['forum_name'],
  683.         'FORUM_ID'      => $forum_data['forum_id'],
  684.         'U_VIEW_FORUM'  => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data['forum_id']))
  685.     );
  686.  
  687.     $template->assign_vars(array(
  688.         'FORUM_ID'      => $forum_data['forum_id'],
  689.         'FORUM_NAME'    => $forum_data['forum_name'],
  690.         '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']),
  691.  
  692.         '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,
  693.     ));
  694.  
  695.     return;
  696. }
  697.  
  698. /**
  699. * Returns forum parents as an array. Get them from forum_data if available, or update the database otherwise
  700. */
  701. function get_forum_parents(&$forum_data)
  702. {
  703.     global $db;
  704.  
  705.     $forum_parents = array();
  706.  
  707.     if ($forum_data['parent_id'] > 0)
  708.     {
  709.         if ($forum_data['forum_parents'] == '')
  710.         {
  711.             $sql = 'SELECT forum_id, forum_name, forum_type
  712.                 FROM ' . FORUMS_TABLE . '
  713.                 WHERE left_id < ' . $forum_data['left_id'] . '
  714.                     AND right_id > ' . $forum_data['right_id'] . '
  715.                 ORDER BY left_id ASC';
  716.             $result = $db->sql_query($sql);
  717.  
  718.             while ($row = $db->sql_fetchrow($result))
  719.             {
  720.                 $forum_parents[$row['forum_id']] = array($row['forum_name'], (int) $row['forum_type']);
  721.             }
  722.             $db->sql_freeresult($result);
  723.  
  724.             $forum_data['forum_parents'] = serialize($forum_parents);
  725.  
  726.             $sql = 'UPDATE ' . FORUMS_TABLE . "
  727.                 SET forum_parents = '" . $db->sql_escape($forum_data['forum_parents']) . "'
  728.                 WHERE parent_id = " . $forum_data['parent_id'];
  729.             $db->sql_query($sql);
  730.         }
  731.         else
  732.         {
  733.             $forum_parents = unserialize($forum_data['forum_parents']);
  734.         }
  735.     }
  736.  
  737.     return $forum_parents;
  738. }
  739.  
  740. /**
  741. * Generate topic pagination
  742. */
  743. function topic_generate_pagination($replies, $url)
  744. {
  745.     global $config, $user;
  746.     // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  747.     global $phpbb_seo, $phpEx;
  748.     // www.phpBB-SEO.com SEO TOOLKIT END
  749.     // Make sure $per_page is a valid value
  750.     $per_page = ($config['posts_per_page'] <= 0) ? 1 : $config['posts_per_page'];
  751.  
  752.     if (($replies + 1) > $per_page)
  753.     {
  754.         $total_pages = ceil(($replies + 1) / $per_page);
  755.         $pagination = '';
  756.  
  757.         $times = 1;
  758.         for ($j = 0; $j < $replies + 1; $j += $per_page)
  759.         {
  760.             $pagination .= '<a href="' . $url . ($j == 0 ? '' : '&amp;start=' . $j) . '">' . $times . '</a>';
  761.             if ($times == 1 && $total_pages > 5)
  762.             {
  763.                 $pagination .= '<span class="page-dots"> ... </span>';
  764.  
  765.                 // Display the last three pages
  766.                 $times = $total_pages - 3;
  767.                 $j += ($total_pages - 4) * $per_page;
  768.             }
  769.             else if ($times < $total_pages)
  770.             {
  771.                 $pagination .= '<span class="page-sep">' . $user->lang['COMMA_SEPARATOR'] . '</span>';
  772.             }
  773.             $times++;
  774.         }
  775.         // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  776.         if (!empty($phpbb_seo->seo_opt['url_rewrite'])) {
  777.             static $pagin_find = array();
  778.             static $pagin_replace = array();
  779.             if (empty($pagin_find)) {
  780.                 $pagin_find = array(
  781.                     // http://example.com/a_n-y/d.i.r/with.ext
  782.                     '`(https?\://[a-z0-9_/\.-]+/[a-z0-9_\.-]+)(\.[a-z0-9]+)(\?[\w$%&~\-;:=,@+\. ]+)?(#[a-z0-9_\.-]+)?(&amp;|\?)start=([0-9]+)`i',
  783.                     // http://example.com/a_n-y/d.i.r/withoutext
  784.                     '`(https?\://[a-z0-9_/\.-]+/[a-z0-9_-]+)/?(\?[\w$%&~\-;:=,@+\. ]+)?(#[a-z0-9_\.-]+)?(&amp;|\?)start=([0-9]+)`i'
  785.                 );
  786.                 $pagin_replace = array(
  787.                     // http://example.com/a_n-y/d.i.r/with-xx.ext
  788.                     '\1' . $phpbb_seo->seo_delim['start'] . '\6\2\3\4',
  789.                     // http://example.com/a_n-y/d.i.r/withoutext/pagexx.html
  790.                     '\1/' . $phpbb_seo->seo_static['pagination'] . '\5' . $phpbb_seo->seo_ext['pagination'] . '\2\3'
  791.                 );
  792.             }
  793.             $pagination = preg_replace( $pagin_find, $pagin_replace, $pagination );
  794.         }
  795.         // www.phpBB-SEO.com SEO TOOLKIT END
  796.     }
  797.     else
  798.     {
  799.         $pagination = '';
  800.     }
  801.  
  802.     return $pagination;
  803. }
  804.  
  805. /**
  806. * Obtain list of moderators of each forum
  807. */
  808. function get_moderators(&$forum_moderators, $forum_id = false)
  809. {
  810.     global $config, $template, $db, $phpbb_root_path, $phpEx, $user, $auth;
  811.     // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  812.     global $phpbb_seo;
  813.     // www.phpBB-SEO.com SEO TOOLKIT END
  814.     $forum_id_ary = array();
  815.  
  816.     if ($forum_id !== false)
  817.     {
  818.         if (!is_array($forum_id))
  819.         {
  820.             $forum_id = array($forum_id);
  821.         }
  822.  
  823.         // Exchange key/value pair to be able to faster check for the forum id existence
  824.         $forum_id_ary = array_flip($forum_id);
  825.     }
  826.  
  827.     $sql_array = array(
  828.         'SELECT'    => 'm.*, u.user_colour, g.group_colour, g.group_type',
  829.  
  830.         'FROM'      => array(
  831.             MODERATOR_CACHE_TABLE   => 'm',
  832.         ),
  833.  
  834.         'LEFT_JOIN' => array(
  835.             array(
  836.                 'FROM'  => array(USERS_TABLE => 'u'),
  837.                 'ON'    => 'm.user_id = u.user_id',
  838.             ),
  839.             array(
  840.                 'FROM'  => array(GROUPS_TABLE => 'g'),
  841.                 'ON'    => 'm.group_id = g.group_id',
  842.             ),
  843.         ),
  844.  
  845.         'WHERE'     => 'm.display_on_index = 1',
  846.     );
  847.  
  848.     // We query every forum here because for caching we should not have any parameter.
  849.     $sql = $db->sql_build_query('SELECT', $sql_array);
  850.     $result = $db->sql_query($sql, 3600);
  851.  
  852.     while ($row = $db->sql_fetchrow($result))
  853.     {
  854.         $f_id = (int) $row['forum_id'];
  855.  
  856.         if (!isset($forum_id_ary[$f_id]))
  857.         {
  858.             continue;
  859.         }
  860.  
  861.         if (!empty($row['user_id']))
  862.         {
  863.             $forum_moderators[$f_id][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
  864.         }
  865.         else
  866.         {
  867.             // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  868.             $phpbb_seo->prepare_url('group', $row['group_name'], $row['group_id']);
  869.             // www.phpBB-SEO.com SEO TOOLKIT END
  870.             $group_name = (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']);
  871.  
  872.             if ($user->data['user_id'] != ANONYMOUS && !$auth->acl_get('u_viewprofile'))
  873.             {
  874.                 $forum_moderators[$f_id][] = '<span' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . '>' . $group_name . '</span>';
  875.             }
  876.             else
  877.             {
  878.                 $forum_moderators[$f_id][] = '<a' . (($row['group_colour']) ? ' style="color:#' . $row['group_colour'] . ';"' : '') . ' href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']) . '">' . $group_name . '</a>';
  879.             }
  880.         }
  881.     }
  882.     $db->sql_freeresult($result);
  883.  
  884.     return;
  885. }
  886.  
  887. /**
  888. * User authorisation levels output
  889. *
  890. * @param    string  $mode           Can be forum or topic. Not in use at the moment.
  891. * @param    int     $forum_id       The current forum the user is in.
  892. * @param    int     $forum_status   The forums status bit.
  893. */
  894. function gen_forum_auth_level($mode, $forum_id, $forum_status)
  895. {
  896.     global $template, $auth, $user, $config;
  897.  
  898.     $locked = ($forum_status == ITEM_LOCKED && !$auth->acl_get('m_edit', $forum_id)) ? true : false;
  899.  
  900.     $rules = array(
  901.         ($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'],
  902.         ($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'],
  903.         ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'],
  904.         ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'],
  905.     );
  906.  
  907.     if ($config['allow_attachments'])
  908.     {
  909.         $rules[] = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && !$locked) ? $user->lang['RULES_ATTACH_CAN'] : $user->lang['RULES_ATTACH_CANNOT'];
  910.     }
  911.  
  912.     foreach ($rules as $rule)
  913.     {
  914.         $template->assign_block_vars('rules', array('RULE' => $rule));
  915.     }
  916.  
  917.     return;
  918. }
  919.  
  920. /**
  921. * Generate topic status
  922. */
  923. function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$folder_alt, &$topic_type)
  924. {
  925.     global $user, $config;
  926.  
  927.     $folder = $folder_new = '';
  928.  
  929.     if ($topic_row['topic_status'] == ITEM_MOVED)
  930.     {
  931.         $topic_type = $user->lang['VIEW_TOPIC_MOVED'];
  932.         $folder_img = 'topic_moved';
  933.         $folder_alt = 'TOPIC_MOVED';
  934.     }
  935.     else
  936.     {
  937.         switch ($topic_row['topic_type'])
  938.         {
  939.             case POST_GLOBAL:
  940.                 $topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
  941.                 $folder = 'global_read';
  942.                 $folder_new = 'global_unread';
  943.             break;
  944.  
  945.             case POST_ANNOUNCE:
  946.                 $topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'];
  947.                 $folder = 'announce_read';
  948.                 $folder_new = 'announce_unread';
  949.             break;
  950.  
  951.             case POST_STICKY:
  952.                 $topic_type = $user->lang['VIEW_TOPIC_STICKY'];
  953.                 $folder = 'sticky_read';
  954.                 $folder_new = 'sticky_unread';
  955.             break;
  956.  
  957.             default:
  958.                 $topic_type = '';
  959.                 $folder = 'topic_read';
  960.                 $folder_new = 'topic_unread';
  961.  
  962.                 // Hot topic threshold is for posts in a topic, which is replies + the first post. ;)
  963.                 if ($config['hot_threshold'] && ($replies + 1) >= $config['hot_threshold'] && $topic_row['topic_status'] != ITEM_LOCKED)
  964.                 {
  965.                     $folder .= '_hot';
  966.                     $folder_new .= '_hot';
  967.                 }
  968.             break;
  969.         }
  970.  
  971.         if ($topic_row['topic_status'] == ITEM_LOCKED)
  972.         {
  973.             $topic_type = $user->lang['VIEW_TOPIC_LOCKED'];
  974.             $folder .= '_locked';
  975.             $folder_new .= '_locked';
  976.         }
  977.  
  978.  
  979.         $folder_img = ($unread_topic) ? $folder_new : $folder;
  980.         $folder_alt = ($unread_topic) ? 'UNREAD_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_UNREAD_POSTS');
  981.  
  982.         // Posted image?
  983.         if (!empty($topic_row['topic_posted']) && $topic_row['topic_posted'])
  984.         {
  985.             $folder_img .= '_mine';
  986.         }
  987.     }
  988.  
  989.     if ($topic_row['poll_start'] && $topic_row['topic_status'] != ITEM_MOVED)
  990.     {
  991.         $topic_type = $user->lang['VIEW_TOPIC_POLL'];
  992.     }
  993. }
  994.  
  995. /**
  996. * Assign/Build custom bbcodes for display in screens supporting using of bbcodes
  997. * The custom bbcodes buttons will be placed within the template block 'custom_codes'
  998. */
  999. function display_custom_bbcodes()
  1000. {
  1001.     global $db, $template, $user;
  1002.  
  1003.     // Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
  1004.     $num_predefined_bbcodes = 22;
  1005.  
  1006.     $sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline
  1007.         FROM ' . BBCODES_TABLE . '
  1008.         WHERE display_on_posting = 1
  1009.         ORDER BY bbcode_tag';
  1010.     $result = $db->sql_query($sql);
  1011.  
  1012.     $i = 0;
  1013.     while ($row = $db->sql_fetchrow($result))
  1014.     {
  1015.         // If the helpline is defined within the language file, we will use the localised version, else just use the database entry...
  1016.         if (isset($user->lang[strtoupper($row['bbcode_helpline'])]))
  1017.         {
  1018.             $row['bbcode_helpline'] = $user->lang[strtoupper($row['bbcode_helpline'])];
  1019.         }
  1020.  
  1021.         $template->assign_block_vars('custom_tags', array(
  1022.             'BBCODE_NAME'       => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
  1023.             'BBCODE_ID'         => $num_predefined_bbcodes + ($i * 2),
  1024.             'BBCODE_TAG'        => $row['bbcode_tag'],
  1025.             'BBCODE_HELPLINE'   => $row['bbcode_helpline'],
  1026.             'A_BBCODE_HELPLINE' => str_replace(array('&amp;', '&quot;', "'", '&lt;', '&gt;'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']),
  1027.         ));
  1028.  
  1029.         $i++;
  1030.     }
  1031.     $db->sql_freeresult($result);
  1032. }
  1033.  
  1034. /**
  1035. * Display reasons
  1036. */
  1037. function display_reasons($reason_id = 0)
  1038. {
  1039.     global $db, $user, $template;
  1040.  
  1041.     $sql = 'SELECT *
  1042.         FROM ' . REPORTS_REASONS_TABLE . '
  1043.         ORDER BY reason_order ASC';
  1044.     $result = $db->sql_query($sql);
  1045.  
  1046.     while ($row = $db->sql_fetchrow($result))
  1047.     {
  1048.         // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
  1049.         if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
  1050.         {
  1051.             $row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
  1052.             $row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
  1053.         }
  1054.  
  1055.         $template->assign_block_vars('reason', array(
  1056.             'ID'            => $row['reason_id'],
  1057.             'TITLE'         => $row['reason_title'],
  1058.             'DESCRIPTION'   => $row['reason_description'],
  1059.             'S_SELECTED'    => ($row['reason_id'] == $reason_id) ? true : false)
  1060.         );
  1061.     }
  1062.     $db->sql_freeresult($result);
  1063. }
  1064.  
  1065. /**
  1066. * Display user activity (action forum/topic)
  1067. */
  1068. function display_user_activity(&$userdata)
  1069. {
  1070.     global $auth, $template, $db, $user;
  1071.     global $phpbb_root_path, $phpEx;
  1072.     // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  1073.     global $phpbb_seo;
  1074.     // www.phpBB-SEO.com SEO TOOLKIT END
  1075.     // Do not display user activity for users having more than 5000 posts...
  1076.     if ($userdata['user_posts'] > 5000)
  1077.     {
  1078.         return;
  1079.     }
  1080.  
  1081.     $forum_ary = array();
  1082.  
  1083.     // Do not include those forums the user is not having read access to...
  1084.     $forum_read_ary = $auth->acl_getf('!f_read');
  1085.  
  1086.     foreach ($forum_read_ary as $forum_id => $not_allowed)
  1087.     {
  1088.         if ($not_allowed['f_read'])
  1089.         {
  1090.             $forum_ary[] = (int) $forum_id;
  1091.         }
  1092.     }
  1093.  
  1094.     $forum_ary = array_unique($forum_ary);
  1095.     $forum_sql = (sizeof($forum_ary)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary, true) : '';
  1096.  
  1097.     $fid_m_approve = $auth->acl_getf('m_approve', true);
  1098.     $sql_m_approve = (!empty($fid_m_approve)) ? 'OR ' . $db->sql_in_set('forum_id', array_keys($fid_m_approve)) : '';
  1099.  
  1100.     // Obtain active forum
  1101.     $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts
  1102.         FROM ' . POSTS_TABLE . '
  1103.         WHERE poster_id = ' . $userdata['user_id'] . "
  1104.             AND post_postcount = 1
  1105.             AND (post_approved = 1
  1106.                 $sql_m_approve)
  1107.             $forum_sql
  1108.         GROUP BY forum_id
  1109.         ORDER BY num_posts DESC";
  1110.     $result = $db->sql_query_limit($sql, 1);
  1111.     $active_f_row = $db->sql_fetchrow($result);
  1112.     $db->sql_freeresult($result);
  1113.  
  1114.     if (!empty($active_f_row))
  1115.     {
  1116.         $sql = 'SELECT forum_name
  1117.             FROM ' . FORUMS_TABLE . '
  1118.             WHERE forum_id = ' . $active_f_row['forum_id'];
  1119.         $result = $db->sql_query($sql, 3600);
  1120.         $active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name');
  1121.         $db->sql_freeresult($result);
  1122.     }
  1123.  
  1124.     // Obtain active topic
  1125.     // We need to exclude passworded forums here so we do not leak the topic title
  1126.     $forum_ary_topic = array_unique(array_merge($forum_ary, $user->get_passworded_forums()));
  1127.     $forum_sql_topic = (!empty($forum_ary_topic)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary_topic, true) : '';
  1128.  
  1129.     $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts
  1130.         FROM ' . POSTS_TABLE . '
  1131.         WHERE poster_id = ' . $userdata['user_id'] . "
  1132.             AND post_postcount = 1
  1133.             AND (post_approved = 1
  1134.                 $sql_m_approve)
  1135.             $forum_sql_topic
  1136.         GROUP BY topic_id
  1137.         ORDER BY num_posts DESC";
  1138.     $result = $db->sql_query_limit($sql, 1);
  1139.     $active_t_row = $db->sql_fetchrow($result);
  1140.     $db->sql_freeresult($result);
  1141.  
  1142.     if (!empty($active_t_row))
  1143.     {
  1144.         // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  1145.         $sql_array = array(
  1146.             'SELECT'    => 't.topic_title, t.topic_type ' . (!empty($phpbb_seo->seo_opt['sql_rewrite']) ? ', t.topic_url' : '') . ', f.forum_id, f.forum_name',
  1147.             'FROM'      => array(
  1148.                 TOPICS_TABLE    => 't',
  1149.             ),
  1150.             'LEFT_JOIN' => array(
  1151.                 array(
  1152.                     'FROM'  => array(FORUMS_TABLE => 'f'),
  1153.                     'ON'    => 'f.forum_id = t.forum_id',
  1154.                 ),
  1155.             ),
  1156.             'WHERE' => 't.topic_id = ' . (int) $active_t_row['topic_id']
  1157.         );
  1158.         $result = $db->sql_query($db->sql_build_query('SELECT', $sql_array));
  1159.         $seo_active_t_row = $db->sql_fetchrow($result);
  1160.         $db->sql_freeresult($result);
  1161.         if ($seo_active_t_row) {
  1162.             $active_t_row = array_merge($active_t_row, $seo_active_t_row);
  1163.         }
  1164.         // www.phpBB-SEO.com SEO TOOLKIT END
  1165.     }
  1166.  
  1167.     $userdata['active_t_row'] = $active_t_row;
  1168.     $userdata['active_f_row'] = $active_f_row;
  1169.  
  1170.     $active_f_name = $active_f_id = $active_f_count = $active_f_pct = '';
  1171.     if (!empty($active_f_row['num_posts']))
  1172.     {
  1173.         $active_f_name = $active_f_row['forum_name'];
  1174.         $active_f_id = $active_f_row['forum_id'];
  1175.         $active_f_count = $active_f_row['num_posts'];
  1176.         $active_f_pct = ($userdata['user_posts']) ? ($active_f_count / $userdata['user_posts']) * 100 : 0;
  1177.         // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  1178.         $phpbb_seo->set_url($active_f_name, $active_f_id, 'forum');
  1179.         // www.phpBB-SEO.com SEO TOOLKIT END
  1180.     }
  1181.  
  1182.     $active_t_name = $active_t_id = $active_t_count = $active_t_pct = '';
  1183.     if (!empty($active_t_row['num_posts']))
  1184.     {
  1185.         $active_t_name = $active_t_row['topic_title'];
  1186.         $active_t_id = $active_t_row['topic_id'];
  1187.         $active_t_count = $active_t_row['num_posts'];
  1188.         $active_t_pct = ($userdata['user_posts']) ? ($active_t_count / $userdata['user_posts']) * 100 : 0;
  1189.         // www.phpBB-SEO.com SEO TOOLKIT BEGIN
  1190.         if (!empty($seo_active_t_row)) {
  1191.             $active_t_forum_id = (int) $active_t_row['forum_id'];
  1192.             $phpbb_seo->set_url($active_t_row['forum_name'], $active_t_forum_id, 'forum');
  1193.             $phpbb_seo->prepare_iurl($active_t_row, 'topic', $active_t_row['topic_type'] == POST_GLOBAL ? $phpbb_seo->seo_static['global_announce'] : $phpbb_seo->seo_url['forum'][$active_t_forum_id]);
  1194.         }
  1195.         // www.phpBB-SEO.com SEO TOOLKIT END
  1196.     }
  1197.  
  1198.     $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'];
  1199.  
  1200.     $template->assign_vars(array(
  1201.         'ACTIVE_FORUM'          => $active_f_name,
  1202.         'ACTIVE_FORUM_POSTS'    => ($active_f_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_f_count),
  1203.         'ACTIVE_FORUM_PCT'      => sprintf($l_active_pct, $active_f_pct),
  1204.         'ACTIVE_TOPIC'          => censor_text($active_t_name),
  1205.         'ACTIVE_TOPIC_POSTS'    => ($active_t_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_t_count),
  1206.         'ACTIVE_TOPIC_PCT'      => sprintf($l_active_pct, $active_t_pct),
  1207.         'U_ACTIVE_FORUM'        => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),
  1208.         'U_ACTIVE_TOPIC'        => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id),
  1209.         'S_SHOW_ACTIVITY'       => true)
  1210.     );
  1211. }
  1212.  
  1213. /**
  1214. * Topic and forum watching common code
  1215. */
  1216. function watch_topic_forum($mode, &$s_watching, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0, $item_title = '')
  1217. {
  1218.     global $template, $db, $user, $phpEx, $start, $phpbb_root_path;
  1219.  
  1220.     $table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE;
  1221.     $where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id';
  1222.     $match_id = ($mode == 'forum') ? $forum_id : $topic_id;
  1223.     $u_url = "uid={$user->data['user_id']}";
  1224.     $u_url .= ($mode == 'forum') ? '&amp;f' : '&amp;f=' . $forum_id . '&amp;t';
  1225.     $is_watching = 0;
  1226.  
  1227.     // Is user watching this thread?
  1228.     if ($user_id != ANONYMOUS)
  1229.     {
  1230.         $can_watch = true;
  1231.  
  1232.         if ($notify_status == 'unset')
  1233.         {
  1234.             $sql = "SELECT notify_status
  1235.                 FROM $table_sql
  1236.                 WHERE $where_sql = $match_id
  1237.                     AND user_id = $user_id";
  1238.             $result = $db->sql_query($sql);
  1239.  
  1240.             $notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL;
  1241.             $db->sql_freeresult($result);
  1242.         }
  1243.  
  1244.         if (!is_null($notify_status) && $notify_status !== '')
  1245.         {
  1246.  
  1247.             if (isset($_GET['unwatch']))
  1248.             {
  1249.                 $uid = request_var('uid', 0);
  1250.                 $token = request_var('hash', '');
  1251.  
  1252.                 if ($token && check_link_hash($token, "{$mode}_$match_id") || confirm_box(true))
  1253.                 {
  1254.                     if ($uid != $user_id || $_GET['unwatch'] != $mode)
  1255.                     {
  1256.                         $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
  1257.                         $message = $user->lang['ERR_UNWATCHING'] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
  1258.                         trigger_error($message);
  1259.                     }
  1260.  
  1261.                     $sql = 'DELETE FROM ' . $table_sql . "
  1262.                         WHERE $where_sql = $match_id
  1263.                             AND user_id = $user_id";
  1264.                     $db->sql_query($sql);
  1265.  
  1266.                     $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
  1267.                     $message = $user->lang['NOT_WATCHING_' . strtoupper($mode)] . '<br /><br />';
  1268.                     $message .= sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
  1269.                     meta_refresh(3, $redirect_url);
  1270.                     trigger_error($message);
  1271.                 }
  1272.                 else
  1273.                 {
  1274.                     $s_hidden_fields = array(
  1275.                         'uid'       => $user->data['user_id'],
  1276.                         'unwatch'   => $mode,
  1277.                         'start'     => $start,
  1278.                         'f'         => $forum_id,
  1279.                     );
  1280.                     if ($mode != 'forum')
  1281.                     {
  1282.                         $s_hidden_fields['t'] = $topic_id;
  1283.                     }
  1284.  
  1285.                     if ($item_title == '')
  1286.                     {
  1287.                         $confirm_box_message = 'UNWATCH_' . strtoupper($mode);
  1288.                     }
  1289.                     else
  1290.                     {
  1291.                         $confirm_box_message = $user->lang('UNWATCH_' . strtoupper($mode) . '_DETAILED', $item_title);
  1292.                     }
  1293.                     confirm_box(false, $confirm_box_message, build_hidden_fields($s_hidden_fields));
  1294.                 }
  1295.             }
  1296.             else
  1297.             {
  1298.                 $is_watching = true;
  1299.  
  1300.                 if ($notify_status != NOTIFY_YES)
  1301.                 {
  1302.                     $sql = 'UPDATE ' . $table_sql . "
  1303.                         SET notify_status = " . NOTIFY_YES . "
  1304.                         WHERE $where_sql = $match_id
  1305.                             AND user_id = $user_id";
  1306.                     $db->sql_query($sql);
  1307.                 }
  1308.             }
  1309.         }
  1310.         else
  1311.         {
  1312.             if (isset($_GET['watch']))
  1313.             {
  1314.                 $uid = request_var('uid', 0);
  1315.                 $token = request_var('hash', '');
  1316.  
  1317.                 if ($token && check_link_hash($token, "{$mode}_$match_id") || confirm_box(true))
  1318.                 {
  1319.                     if ($uid != $user_id || $_GET['watch'] != $mode)
  1320.                     {
  1321.                         $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
  1322.                         $message = $user->lang['ERR_WATCHING'] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
  1323.                         trigger_error($message);
  1324.                     }
  1325.  
  1326.                     $is_watching = true;
  1327.  
  1328.                     $sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status)
  1329.                         VALUES ($user_id, $match_id, " . NOTIFY_YES . ')';
  1330.                     $db->sql_query($sql);
  1331.  
  1332.                     $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
  1333.                     $message = $user->lang['ARE_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
  1334.                     meta_refresh(3, $redirect_url);
  1335.                     trigger_error($message);
  1336.                 }
  1337.                 else
  1338.                 {
  1339.                     $s_hidden_fields = array(
  1340.                         'uid'       => $user->data['user_id'],
  1341.                         'watch'     => $mode,
  1342.                         'start'     => $start,
  1343.                         'f'         => $forum_id,
  1344.                     );
  1345.                     if ($mode != 'forum')
  1346.                     {
  1347.                         $s_hidden_fields['t'] = $topic_id;
  1348.                     }
  1349.  
  1350.                     $confirm_box_message = (($item_title == '') ? 'WATCH_' . strtoupper($mode) : $user->lang('WATCH_' . strtoupper($mode) . '_DETAILED', $item_title));
  1351.                     confirm_box(false, $confirm_box_message, build_hidden_fields($s_hidden_fields));
  1352.                 }
  1353.             }
  1354.             else
  1355.             {
  1356.                 $is_watching = 0;
  1357.             }
  1358.         }
  1359.     }
  1360.     else
  1361.     {
  1362.         if ((isset($_GET['unwatch']) && $_GET['unwatch'] == $mode) || (isset($_GET['watch']) && $_GET['watch'] == $mode))
  1363.         {
  1364.             login_box();
  1365.         }
  1366.         else
  1367.         {
  1368.             $can_watch = 0;
  1369.             $is_watching = 0;
  1370.         }
  1371.     }
  1372.  
  1373.     if ($can_watch)
  1374.     {
  1375.         $s_watching['link'] = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;" . (($is_watching) ? 'unwatch' : 'watch') . "=$mode&amp;start=$start&amp;hash=" . generate_link_hash("{$mode}_$match_id"));
  1376.         $s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
  1377.         $s_watching['is_watching'] = $is_watching;
  1378.     }
  1379.  
  1380.     return;
  1381. }
  1382.  
  1383. /**
  1384. * Get user rank title and image
  1385. *
  1386. * @param int $user_rank the current stored users rank id
  1387. * @param int $user_posts the users number of posts
  1388. * @param string &$rank_title the rank title will be stored here after execution
  1389. * @param string &$rank_img the rank image as full img tag is stored here after execution
  1390. * @param string &$rank_img_src the rank image source is stored here after execution
  1391. *
  1392. * 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
  1393. */
  1394. function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src)
  1395. {
  1396.     global $ranks, $config, $phpbb_root_path;
  1397.  
  1398.     if (empty($ranks))
  1399.     {
  1400.         global $cache;
  1401.         $ranks = $cache->obtain_ranks();
  1402.     }
  1403.  
  1404.     if (!empty($user_rank))
  1405.     {
  1406.         $rank_title = (isset($ranks['special'][$user_rank]['rank_title'])) ? $ranks['special'][$user_rank]['rank_title'] : '';
  1407.         $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'] . '" />' : '';
  1408.         $rank_img_src = (!empty($ranks['special'][$user_rank]['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] : '';
  1409.     }
  1410.     else if ($user_posts !== false)
  1411.     {
  1412.         if (!empty($ranks['normal']))
  1413.         {
  1414.             foreach ($ranks['normal'] as $rank)
  1415.             {
  1416.                 if ($user_posts >= $rank['rank_min'])
  1417.                 {
  1418.                     $rank_title = $rank['rank_title'];
  1419.                     $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'] . '" />' : '';
  1420.                     $rank_img_src = (!empty($rank['rank_image'])) ? $phpbb_root_path . $config['ranks_path'] . '/' . $rank['rank_image'] : '';
  1421.                     break;
  1422.                 }
  1423.             }
  1424.         }
  1425.     }
  1426. }
  1427.  
  1428. /**
  1429. * Get user avatar
  1430. *
  1431. * @param string $avatar Users assigned avatar name
  1432. * @param int $avatar_type Type of avatar
  1433. * @param string $avatar_width Width of users avatar
  1434. * @param string $avatar_height Height of users avatar
  1435. * @param string $alt Optional language string for alt tag within image, can be a language key or text
  1436. * @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP
  1437. *
  1438. * @return string Avatar image
  1439. */
  1440. function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR', $ignore_config = false)
  1441. {
  1442.     global $user, $config, $phpbb_root_path, $phpEx;
  1443.  
  1444.     if (empty($avatar) || !$avatar_type || (!$config['allow_avatar'] && !$ignore_config))
  1445.     {
  1446.         return '';
  1447.     }
  1448.  
  1449.     $avatar_img = '';
  1450.  
  1451.     switch ($avatar_type)
  1452.     {
  1453.         case AVATAR_UPLOAD:
  1454.             if (!$config['allow_avatar_upload'] && !$ignore_config)
  1455.             {
  1456.                 return '';
  1457.             }
  1458.             $avatar_img = $phpbb_root_path . "download/file.$phpEx?avatar=";
  1459.         break;
  1460.  
  1461.         case AVATAR_GALLERY:
  1462.             if (!$config['allow_avatar_local'] && !$ignore_config)
  1463.             {
  1464.                 return '';
  1465.             }
  1466.             $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
  1467.         break;
  1468.  
  1469.         case AVATAR_REMOTE:
  1470.             if (!$config['allow_avatar_remote'] && !$ignore_config)
  1471.             {
  1472.                 return '';
  1473.             }
  1474.         break;
  1475.     }
  1476.  
  1477.     $avatar_img .= $avatar;
  1478.     return '<img src="' . (str_replace(' ', '%20', $avatar_img)) . '" width="' . $avatar_width . '" height="' . $avatar_height . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
  1479. }
  1480.  
  1481. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement