Advertisement
Guest User

functions_display.php

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