Verzeichnisstruktur phpBB-3.0.0


Veröffentlicht
12.12.2007

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

functions_display.php

Zuletzt modifiziert: 09.10.2024, 12:50 - Dateigröße: 35.82 KiB


 0001  <?php
 0002  /**
 0003  *
 0004  * @package phpBB3
 0005  * @version $Id$
 0006  * @copyright (c) 2005 phpBB Group
 0007  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 0008  *
 0009  */
 0010   
 0011  /**
 0012  * @ignore
 0013  */
 0014  if (!defined('IN_PHPBB'))
 0015  {
 0016      exit;
 0017  }
 0018   
 0019  /**
 0020  * Display Forums
 0021  */
 0022  function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
 0023  {
 0024      global $db, $auth, $user, $template;
 0025      global $phpbb_root_path, $phpEx, $config;
 0026   
 0027      $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
 0028      $parent_id = $visible_forums = 0;
 0029      $sql_from = '';
 0030      
 0031      // Mark forums read?
 0032      $mark_read = request_var('mark', '');
 0033   
 0034      if ($mark_read == 'all')
 0035      {
 0036          $mark_read = '';
 0037      }
 0038   
 0039      if (!$root_data)
 0040      {
 0041          if ($mark_read == 'forums')
 0042          {
 0043              $mark_read = 'all';
 0044          }
 0045   
 0046          $root_data = array('forum_id' => 0);
 0047          $sql_where = '';
 0048      }
 0049      else
 0050      {
 0051          $sql_where = 'left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
 0052      }
 0053   
 0054      // Display list of active topics for this category?
 0055      $show_active = (isset($root_data['forum_flags']) && ($root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
 0056   
 0057      $sql_array = array(
 0058          'SELECT'    => 'f.*',
 0059          'FROM'        => array(
 0060              FORUMS_TABLE        => 'f'
 0061          ),
 0062          'LEFT_JOIN'    => array(),
 0063      );
 0064   
 0065      if ($config['load_db_lastread'] && $user->data['is_registered'])
 0066      {
 0067          $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');
 0068          $sql_array['SELECT'] .= ', ft.mark_time';
 0069      }
 0070      else if ($config['load_anon_lastread'] || $user->data['is_registered'])
 0071      {
 0072          $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
 0073          $tracking_topics = ($tracking_topics) ? tracking_unserialize($tracking_topics) : array();
 0074   
 0075          if (!$user->data['is_registered'])
 0076          {
 0077              $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
 0078          }
 0079      }
 0080   
 0081      if ($show_active)
 0082      {
 0083          $sql_array['LEFT_JOIN'][] = array(
 0084              'FROM'    => array(FORUMS_ACCESS_TABLE => 'fa'),
 0085              'ON'    => "fa.forum_id = f.forum_id AND fa.session_id = '" . $db->sql_escape($user->session_id) . "'"
 0086          );
 0087   
 0088          $sql_array['SELECT'] .= ', fa.user_id';
 0089      }
 0090   
 0091      $sql = $db->sql_build_query('SELECT', array(
 0092          'SELECT'    => $sql_array['SELECT'],
 0093          'FROM'        => $sql_array['FROM'],
 0094          'LEFT_JOIN'    => $sql_array['LEFT_JOIN'],
 0095   
 0096          'WHERE'        => $sql_where,
 0097   
 0098          'ORDER_BY'    => 'f.left_id',
 0099      ));
 0100   
 0101      $result = $db->sql_query($sql);
 0102   
 0103      $forum_tracking_info = array();
 0104      $branch_root_id = $root_data['forum_id'];
 0105      while ($row = $db->sql_fetchrow($result))
 0106      {
 0107          $forum_id = $row['forum_id'];
 0108   
 0109          // Mark forums read?
 0110          if ($mark_read == 'forums' || $mark_read == 'all')
 0111          {
 0112              if ($auth->acl_get('f_list', $forum_id))
 0113              {
 0114                  $forum_ids[] = $forum_id;
 0115                  continue;
 0116              }
 0117          }
 0118   
 0119          // Category with no members
 0120          if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
 0121          {
 0122              continue;
 0123          }
 0124   
 0125          // Skip branch
 0126          if (isset($right_id))
 0127          {
 0128              if ($row['left_id'] < $right_id)
 0129              {
 0130                  continue;
 0131              }
 0132              unset($right_id);
 0133          }
 0134   
 0135          if (!$auth->acl_get('f_list', $forum_id))
 0136          {
 0137              // if the user does not have permissions to list this forum, skip everything until next branch
 0138              $right_id = $row['right_id'];
 0139              continue;
 0140          }
 0141   
 0142          $forum_ids[] = $forum_id;
 0143   
 0144          if ($config['load_db_lastread'] && $user->data['is_registered'])
 0145          {
 0146              $forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
 0147          }
 0148          else if ($config['load_anon_lastread'] || $user->data['is_registered'])
 0149          {
 0150              if (!$user->data['is_registered'])
 0151              {
 0152                  $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
 0153              }
 0154              $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'];
 0155          }
 0156   
 0157          $row['forum_topics'] = ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics'];
 0158   
 0159          // Display active topics from this forum?
 0160          if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS))
 0161          {
 0162              if (!isset($active_forum_ary['forum_topics']))
 0163              {
 0164                  $active_forum_ary['forum_topics'] = 0;
 0165              }
 0166   
 0167              if (!isset($active_forum_ary['forum_posts']))
 0168              {
 0169                  $active_forum_ary['forum_posts'] = 0;
 0170              }
 0171   
 0172              $active_forum_ary['forum_id'][]        = $forum_id;
 0173              $active_forum_ary['enable_icons'][]    = $row['enable_icons'];
 0174              $active_forum_ary['forum_topics']    += $row['forum_topics'];
 0175              $active_forum_ary['forum_posts']    += $row['forum_posts'];
 0176   
 0177              // If this is a passworded forum we do not show active topics from it if the user is not authorised to view it...
 0178              if ($row['forum_password'] && $row['user_id'] != $user->data['user_id'])
 0179              {
 0180                  $active_forum_ary['exclude_forum_id'][] = $forum_id;
 0181              }
 0182          }
 0183   
 0184          //
 0185          if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id)
 0186          {
 0187              if ($row['forum_type'] != FORUM_CAT)
 0188              {
 0189                  $forum_ids_moderator[] = (int) $forum_id;
 0190              }
 0191   
 0192              // Direct child of current branch
 0193              $parent_id = $forum_id;
 0194              $forum_rows[$forum_id] = $row;
 0195   
 0196              if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id'])
 0197              {
 0198                  $branch_root_id = $forum_id;
 0199              }
 0200              $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
 0201              $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
 0202          }
 0203          else if ($row['forum_type'] != FORUM_CAT)
 0204          {
 0205              $subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index']) ? true : false;
 0206              $subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
 0207              $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
 0208   
 0209              $forum_rows[$parent_id]['forum_topics'] += $row['forum_topics'];
 0210   
 0211              // Do not list redirects in LINK Forums as Posts.
 0212              if ($row['forum_type'] != FORUM_LINK)
 0213              {
 0214                  $forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
 0215              }
 0216   
 0217              if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time'])
 0218              {
 0219                  $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
 0220                  $forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject'];
 0221                  $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
 0222                  $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
 0223                  $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
 0224                  $forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour'];
 0225                  $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
 0226              }
 0227          }
 0228      }
 0229      $db->sql_freeresult($result);
 0230   
 0231      // Handle marking posts
 0232      if ($mark_read == 'forums' || $mark_read == 'all')
 0233      {
 0234          $redirect = build_url('mark');
 0235   
 0236          if ($mark_read == 'all')
 0237          {
 0238              markread('all');
 0239   
 0240              $message = sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>');
 0241          }
 0242          else
 0243          {
 0244              markread('topics', $forum_ids);
 0245   
 0246              $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
 0247          }
 0248   
 0249          meta_refresh(3, $redirect);
 0250          trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message);
 0251      }
 0252   
 0253      // Grab moderators ... if necessary
 0254      if ($display_moderators)
 0255      {
 0256          if ($return_moderators)
 0257          {
 0258              $forum_ids_moderator[] = $root_data['forum_id'];
 0259          }
 0260          get_moderators($forum_moderators, $forum_ids_moderator);
 0261      }
 0262   
 0263      // Used to tell whatever we have to create a dummy category or not.
 0264      $last_catless = true;
 0265      foreach ($forum_rows as $row)
 0266      {
 0267          // Empty category
 0268          if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT)
 0269          {
 0270              $template->assign_block_vars('forumrow', array(
 0271                  'S_IS_CAT'                => true,
 0272                  'FORUM_ID'                => $row['forum_id'],
 0273                  'FORUM_NAME'            => $row['forum_name'],
 0274                  'FORUM_DESC'            => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
 0275                  'FORUM_FOLDER_IMG'        => '',
 0276                  'FORUM_FOLDER_IMG_SRC'    => '',
 0277                  'FORUM_IMAGE'            => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '',
 0278                  'FORUM_IMAGE_SRC'        => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
 0279                  'U_VIEWFORUM'            => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
 0280              );
 0281   
 0282              continue;
 0283          }
 0284   
 0285          $visible_forums++;
 0286          $forum_id = $row['forum_id'];
 0287   
 0288          $forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false;
 0289   
 0290          $folder_image = $folder_alt = $l_subforums = '';
 0291          $subforums_list = array();
 0292   
 0293          // Generate list of subforums if we need to
 0294          if (isset($subforums[$forum_id]))
 0295          {
 0296              foreach ($subforums[$forum_id] as $subforum_id => $subforum_row)
 0297              {
 0298                  $subforum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ? true : false;
 0299   
 0300                  if ($subforum_row['display'] && $subforum_row['name'])
 0301                  {
 0302                      $subforums_list[] = array(
 0303                          'link'        => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $subforum_id),
 0304                          'name'        => $subforum_row['name'],
 0305                          'unread'    => $subforum_unread,
 0306                      );
 0307                  }
 0308                  else
 0309                  {
 0310                      unset($subforums[$forum_id][$subforum_id]);
 0311                  }
 0312   
 0313                  // If one subforum is unread the forum gets unread too...
 0314                  if ($subforum_unread)
 0315                  {
 0316                      $forum_unread = true;
 0317                  }
 0318              }
 0319   
 0320              $l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
 0321              $folder_image = ($forum_unread) ? 'forum_unread_subforum' : 'forum_read_subforum';
 0322          }
 0323          else
 0324          {
 0325              switch ($row['forum_type'])
 0326              {
 0327                  case FORUM_POST:
 0328                      $folder_image = ($forum_unread) ? 'forum_unread' : 'forum_read';
 0329                  break;
 0330   
 0331                  case FORUM_LINK:
 0332                      $folder_image = 'forum_link';
 0333                  break;
 0334              }
 0335          }
 0336   
 0337          // Which folder should we display?
 0338          if ($row['forum_status'] == ITEM_LOCKED)
 0339          {
 0340              $folder_image = ($forum_unread) ? 'forum_unread_locked' : 'forum_read_locked';
 0341              $folder_alt = 'FORUM_LOCKED';
 0342          }
 0343          else
 0344          {
 0345              $folder_alt = ($forum_unread) ? 'NEW_POSTS' : 'NO_NEW_POSTS';
 0346          }
 0347   
 0348          // Create last post link information, if appropriate
 0349          if ($row['forum_last_post_id'])
 0350          {
 0351              $last_post_subject = $row['forum_last_post_subject'];
 0352              $last_post_time = $user->format_date($row['forum_last_post_time']);
 0353              $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'];
 0354          }
 0355          else
 0356          {
 0357              $last_post_subject = $last_post_time = $last_post_url = '';
 0358          }
 0359   
 0360          // Output moderator listing ... if applicable
 0361          $l_moderator = $moderators_list = '';
 0362          if ($display_moderators && !empty($forum_moderators[$forum_id]))
 0363          {
 0364              $l_moderator = (sizeof($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
 0365              $moderators_list = implode(', ', $forum_moderators[$forum_id]);
 0366          }
 0367   
 0368          $l_post_click_count = ($row['forum_type'] == FORUM_LINK) ? 'CLICKS' : 'POSTS';
 0369          $post_click_count = ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? $row['forum_posts'] : '';
 0370   
 0371          $s_subforums_list = array();
 0372          foreach ($subforums_list as $subforum)
 0373          {
 0374              $s_subforums_list[] = '<a href="' . $subforum['link'] . '" class="subforum ' . (($subforum['unread']) ? 'unread' : 'read') . '">' . $subforum['name'] . '</a>';
 0375          }
 0376          $s_subforums_list = (string) implode(', ', $s_subforums_list);
 0377          $catless = ($row['parent_id'] == $root_data['forum_id']) ? true : false;
 0378   
 0379          if ($row['forum_type'] != FORUM_LINK)
 0380          {
 0381              $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
 0382          }
 0383          else
 0384          {
 0385              // If the forum is a link and we count redirects we need to visit it
 0386              // If the forum is having a password or no read access we do not expose the link, but instead handle it in viewforum
 0387              if (($row['forum_flags'] & FORUM_FLAG_LINK_TRACK) || $row['forum_password'] || !$auth->acl_get('f_read', $forum_id))
 0388              {
 0389                  $u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
 0390              }
 0391              else
 0392              {
 0393                  $u_viewforum = $row['forum_link'];
 0394              }
 0395          }
 0396   
 0397          $template->assign_block_vars('forumrow', array(
 0398              'S_IS_CAT'            => false,
 0399              'S_NO_CAT'            => $catless && !$last_catless,
 0400              'S_IS_LINK'            => ($row['forum_type'] == FORUM_LINK) ? true : false,
 0401              'S_UNREAD_FORUM'    => $forum_unread,
 0402              'S_LOCKED_FORUM'    => ($row['forum_status'] == ITEM_LOCKED) ? true : false,
 0403              'S_SUBFORUMS'        => (sizeof($subforums_list)) ? true : false,
 0404   
 0405              'FORUM_ID'                => $row['forum_id'],
 0406              'FORUM_NAME'            => $row['forum_name'],
 0407              'FORUM_DESC'            => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
 0408              'TOPICS'                => $row['forum_topics'],
 0409              $l_post_click_count        => $post_click_count,
 0410              'FORUM_FOLDER_IMG'        => $user->img($folder_image, $folder_alt),
 0411              'FORUM_FOLDER_IMG_SRC'    => $user->img($folder_image, $folder_alt, false, '', 'src'),
 0412              'FORUM_IMAGE'            => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
 0413              'FORUM_IMAGE_SRC'        => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
 0414              'LAST_POST_SUBJECT'        => censor_text($last_post_subject),
 0415              'LAST_POST_TIME'        => $last_post_time,
 0416              'LAST_POSTER'            => get_username_string('username', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
 0417              'LAST_POSTER_COLOUR'    => get_username_string('colour', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
 0418              'LAST_POSTER_FULL'        => get_username_string('full', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
 0419              'MODERATORS'            => $moderators_list,
 0420              'SUBFORUMS'                => $s_subforums_list,
 0421   
 0422              'L_SUBFORUM_STR'        => $l_subforums,
 0423              'L_FORUM_FOLDER_ALT'    => $folder_alt,
 0424              'L_MODERATOR_STR'        => $l_moderator,
 0425   
 0426              'U_VIEWFORUM'        => $u_viewforum,
 0427              'U_LAST_POSTER'        => get_username_string('profile', $row['forum_last_poster_id'], $row['forum_last_poster_name'], $row['forum_last_poster_colour']),
 0428              'U_LAST_POST'        => $last_post_url)
 0429          );
 0430   
 0431          // Assign subforums loop for style authors
 0432          foreach ($subforums_list as $subforum)
 0433          {
 0434              $template->assign_block_vars('forumrow.subforum', array(
 0435                  'U_SUBFORUM'    => $subforum['link'],
 0436                  'SUBFORUM_NAME'    => $subforum['name'],
 0437                  'S_UNREAD'        => $subforum['unread'])
 0438              );
 0439          }
 0440          
 0441          $last_catless = $catless;
 0442      }
 0443   
 0444      $template->assign_vars(array(
 0445          'U_MARK_FORUMS'        => ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $root_data['forum_id'] . '&amp;mark=forums') : '',
 0446          'S_HAS_SUBFORUM'    => ($visible_forums) ? true : false,
 0447          'L_SUBFORUM'        => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'],
 0448          'LAST_POST_IMG'        => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'))
 0449      );
 0450   
 0451      if ($return_moderators)
 0452      {
 0453          return array($active_forum_ary, $forum_moderators);
 0454      }
 0455   
 0456      return array($active_forum_ary, array());
 0457  }
 0458   
 0459  /**
 0460  * Create forum rules for given forum
 0461  */
 0462  function generate_forum_rules(&$forum_data)
 0463  {
 0464      if (!$forum_data['forum_rules'] && !$forum_data['forum_rules_link'])
 0465      {
 0466          return;
 0467      }
 0468   
 0469      global $template, $phpbb_root_path, $phpEx;
 0470   
 0471      if ($forum_data['forum_rules'])
 0472      {
 0473          $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']);
 0474      }
 0475   
 0476      $template->assign_vars(array(
 0477          'S_FORUM_RULES'    => true,
 0478          'U_FORUM_RULES'    => $forum_data['forum_rules_link'],
 0479          'FORUM_RULES'    => $forum_data['forum_rules'])
 0480      );
 0481  }
 0482   
 0483  /**
 0484  * Create forum navigation links for given forum, create parent
 0485  * list if currently null, assign basic forum info to template
 0486  */
 0487  function generate_forum_nav(&$forum_data)
 0488  {
 0489      global $db, $user, $template, $auth;
 0490      global $phpEx, $phpbb_root_path;
 0491   
 0492      if (!$auth->acl_get('f_list', $forum_data['forum_id']))
 0493      {
 0494          return;
 0495      }
 0496   
 0497      // Get forum parents
 0498      $forum_parents = get_forum_parents($forum_data);
 0499   
 0500      // Build navigation links
 0501      if (!empty($forum_parents))
 0502      {
 0503          foreach ($forum_parents as $parent_forum_id => $parent_data)
 0504          {
 0505              list($parent_name, $parent_type) = array_values($parent_data);
 0506   
 0507              // Skip this parent if the user does not have the permission to view it
 0508              if (!$auth->acl_get('f_list', $parent_forum_id))
 0509              {
 0510                  continue;
 0511              }
 0512   
 0513              $template->assign_block_vars('navlinks', array(
 0514                  'S_IS_CAT'        => ($parent_type == FORUM_CAT) ? true : false,
 0515                  'S_IS_LINK'        => ($parent_type == FORUM_LINK) ? true : false,
 0516                  'S_IS_POST'        => ($parent_type == FORUM_POST) ? true : false,
 0517                  'FORUM_NAME'    => $parent_name,
 0518                  'FORUM_ID'        => $parent_forum_id,
 0519                  'U_VIEW_FORUM'    => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id))
 0520              );
 0521          }
 0522      }
 0523   
 0524      $template->assign_block_vars('navlinks', array(
 0525          'S_IS_CAT'        => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
 0526          'S_IS_LINK'        => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
 0527          'S_IS_POST'        => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
 0528          'FORUM_NAME'    => $forum_data['forum_name'],
 0529          'FORUM_ID'        => $forum_data['forum_id'],
 0530          'U_VIEW_FORUM'    => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data['forum_id']))
 0531      );
 0532   
 0533      $template->assign_vars(array(
 0534          'FORUM_ID'         => $forum_data['forum_id'],
 0535          'FORUM_NAME'    => $forum_data['forum_name'],
 0536          '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']))
 0537      );
 0538   
 0539      return;
 0540  }
 0541   
 0542  /**
 0543  * Returns forum parents as an array. Get them from forum_data if available, or update the database otherwise
 0544  */
 0545  function get_forum_parents(&$forum_data)
 0546  {
 0547      global $db;
 0548   
 0549      $forum_parents = array();
 0550   
 0551      if ($forum_data['parent_id'] > 0)
 0552      {
 0553          if ($forum_data['forum_parents'] == '')
 0554          {
 0555              $sql = 'SELECT forum_id, forum_name, forum_type
 0556                  FROM ' . FORUMS_TABLE . '
 0557                  WHERE left_id < ' . $forum_data['left_id'] . '
 0558                      AND right_id > ' . $forum_data['right_id'] . '
 0559                  ORDER BY left_id ASC';
 0560              $result = $db->sql_query($sql);
 0561   
 0562              while ($row = $db->sql_fetchrow($result))
 0563              {
 0564                  $forum_parents[$row['forum_id']] = array($row['forum_name'], (int) $row['forum_type']);
 0565              }
 0566              $db->sql_freeresult($result);
 0567   
 0568              $forum_data['forum_parents'] = serialize($forum_parents);
 0569   
 0570              $sql = 'UPDATE ' . FORUMS_TABLE . "
 0571                  SET forum_parents = '" . $db->sql_escape($forum_data['forum_parents']) . "'
 0572                  WHERE parent_id = " . $forum_data['parent_id'];
 0573              $db->sql_query($sql);
 0574          }
 0575          else
 0576          {
 0577              $forum_parents = unserialize($forum_data['forum_parents']);
 0578          }
 0579      }
 0580   
 0581      return $forum_parents;
 0582  }
 0583   
 0584  /**
 0585  * Generate topic pagination
 0586  */
 0587  function topic_generate_pagination($replies, $url)
 0588  {
 0589      global $config, $user;
 0590   
 0591      // Make sure $per_page is a valid value
 0592      $per_page = ($config['posts_per_page'] <= 0) ? 1 : $config['posts_per_page'];
 0593   
 0594      if (($replies + 1) > $per_page)
 0595      {
 0596          $total_pages = ceil(($replies + 1) / $per_page);
 0597          $pagination = '';
 0598   
 0599          $times = 1;
 0600          for ($j = 0; $j < $replies + 1; $j += $per_page)
 0601          {
 0602              $pagination .= '<a href="' . $url . '&amp;start=' . $j . '">' . $times . '</a>';
 0603              if ($times == 1 && $total_pages > 5)
 0604              {
 0605                  $pagination .= ' ... ';
 0606   
 0607                  // Display the last three pages
 0608                  $times = $total_pages - 3;
 0609                  $j += ($total_pages - 4) * $per_page;
 0610              }
 0611              else if ($times < $total_pages)
 0612              {
 0613                  $pagination .= '<span class="page-sep">' . $user->lang['COMMA_SEPARATOR'] . '</span>';
 0614              }
 0615              $times++;
 0616          }
 0617      }
 0618      else
 0619      {
 0620          $pagination = '';
 0621      }
 0622   
 0623      return $pagination;
 0624  }
 0625   
 0626  /**
 0627  * Obtain list of moderators of each forum
 0628  */
 0629  function get_moderators(&$forum_moderators, $forum_id = false)
 0630  {
 0631      global $config, $template, $db, $phpbb_root_path, $phpEx;
 0632   
 0633      // Have we disabled the display of moderators? If so, then return
 0634      // from whence we came ...
 0635      if (!$config['load_moderators'])
 0636      {
 0637          return;
 0638      }
 0639   
 0640      $forum_sql = '';
 0641   
 0642      if ($forum_id !== false)
 0643      {
 0644          if (!is_array($forum_id))
 0645          {
 0646              $forum_id = array($forum_id);
 0647          }
 0648   
 0649          // If we don't have a forum then we can't have a moderator
 0650          if (!sizeof($forum_id))
 0651          {
 0652              return;
 0653          }
 0654   
 0655          $forum_sql = 'AND m.' . $db->sql_in_set('forum_id', $forum_id);
 0656      }
 0657   
 0658      $sql_array = array(
 0659          'SELECT'    => 'm.*, u.user_colour, g.group_colour, g.group_type',
 0660   
 0661          'FROM'        => array(
 0662              MODERATOR_CACHE_TABLE    => 'm',
 0663          ),
 0664   
 0665          'LEFT_JOIN'    => array(
 0666              array(
 0667                  'FROM'    => array(USERS_TABLE => 'u'),
 0668                  'ON'    => 'm.user_id = u.user_id',
 0669              ),
 0670              array(
 0671                  'FROM'    => array(GROUPS_TABLE => 'g'),
 0672                  'ON'    => 'm.group_id = g.group_id',
 0673              ),
 0674          ),
 0675   
 0676          'WHERE'        => "m.display_on_index = 1 $forum_sql",
 0677      );
 0678   
 0679      $sql = $db->sql_build_query('SELECT', $sql_array);
 0680      $result = $db->sql_query($sql, 3600);
 0681   
 0682      while ($row = $db->sql_fetchrow($result))
 0683      {
 0684          if (!empty($row['user_id']))
 0685          {
 0686              $forum_moderators[$row['forum_id']][] = get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']);
 0687          }
 0688          else
 0689          {
 0690              $forum_moderators[$row['forum_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']) . '">' . (($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</a>';
 0691          }
 0692      }
 0693      $db->sql_freeresult($result);
 0694   
 0695      return;
 0696  }
 0697   
 0698  /**
 0699  * User authorisation levels output
 0700  *
 0701  * @param    string    $mode            Can be forum or topic. Not in use at the moment.
 0702  * @param    int        $forum_id        The current forum the user is in.
 0703  * @param    int        $forum_status    The forums status bit.
 0704  */
 0705  function gen_forum_auth_level($mode, $forum_id, $forum_status)
 0706  {
 0707      global $template, $auth, $user, $config;
 0708   
 0709      $locked = ($forum_status == ITEM_LOCKED && !$auth->acl_get('m_edit', $forum_id)) ? true : false;
 0710   
 0711      $rules = array(
 0712          ($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'],
 0713          ($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'],
 0714          ($user->data['is_registered'] && $auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'],
 0715          ($user->data['is_registered'] && $auth->acl_gets('f_delete', 'm_delete', $forum_id) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'],
 0716      );
 0717   
 0718      if ($config['allow_attachments'])
 0719      {
 0720          $rules[] = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && !$locked) ? $user->lang['RULES_ATTACH_CAN'] : $user->lang['RULES_ATTACH_CANNOT'];
 0721      }
 0722   
 0723      foreach ($rules as $rule)
 0724      {
 0725          $template->assign_block_vars('rules', array('RULE' => $rule));
 0726      }
 0727   
 0728      return;
 0729  }
 0730   
 0731  /**
 0732  * Generate topic status
 0733  */
 0734  function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$folder_alt, &$topic_type)
 0735  {
 0736      global $user, $config;
 0737   
 0738      $folder = $folder_new = '';
 0739   
 0740      if ($topic_row['topic_status'] == ITEM_MOVED)
 0741      {
 0742          $topic_type = $user->lang['VIEW_TOPIC_MOVED'];
 0743          $folder_img = 'topic_moved';
 0744          $folder_alt = 'TOPIC_MOVED';
 0745      }
 0746      else
 0747      {
 0748          switch ($topic_row['topic_type'])
 0749          {
 0750              case POST_GLOBAL:
 0751                  $topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
 0752                  $folder = 'global_read';
 0753                  $folder_new = 'global_unread';
 0754              break;
 0755   
 0756              case POST_ANNOUNCE:
 0757                  $topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'];
 0758                  $folder = 'announce_read';
 0759                  $folder_new = 'announce_unread';
 0760              break;
 0761   
 0762              case POST_STICKY:
 0763                  $topic_type = $user->lang['VIEW_TOPIC_STICKY'];
 0764                  $folder = 'sticky_read';
 0765                  $folder_new = 'sticky_unread';
 0766              break;
 0767   
 0768              default:
 0769                  $topic_type = '';
 0770                  $folder = 'topic_read';
 0771                  $folder_new = 'topic_unread';
 0772   
 0773                  if ($config['hot_threshold'] && $replies >= $config['hot_threshold'] && $topic_row['topic_status'] != ITEM_LOCKED)
 0774                  {
 0775                      $folder .= '_hot';
 0776                      $folder_new .= '_hot';
 0777                  }
 0778              break;
 0779          }
 0780   
 0781          if ($topic_row['topic_status'] == ITEM_LOCKED)
 0782          {
 0783              $topic_type = $user->lang['VIEW_TOPIC_LOCKED'];
 0784              $folder .= '_locked';
 0785              $folder_new .= '_locked';
 0786          }
 0787   
 0788   
 0789          $folder_img = ($unread_topic) ? $folder_new : $folder;
 0790          $folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS');
 0791   
 0792          // Posted image?
 0793          if (!empty($topic_row['topic_posted']) && $topic_row['topic_posted'])
 0794          {
 0795              $folder_img .= '_mine';
 0796          }
 0797      }
 0798   
 0799      if ($topic_row['poll_start'] && $topic_row['topic_status'] != ITEM_MOVED)
 0800      {
 0801          $topic_type = $user->lang['VIEW_TOPIC_POLL'];
 0802      }
 0803  }
 0804   
 0805  /**
 0806  * Assign/Build custom bbcodes for display in screens supporting using of bbcodes
 0807  * The custom bbcodes buttons will be placed within the template block 'custom_codes'
 0808  */
 0809  function display_custom_bbcodes()
 0810  {
 0811      global $db, $template;
 0812   
 0813      // Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
 0814      $num_predefined_bbcodes = 22;
 0815   
 0816      $sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline
 0817          FROM ' . BBCODES_TABLE . '
 0818          WHERE display_on_posting = 1
 0819          ORDER BY bbcode_tag';
 0820      $result = $db->sql_query($sql);
 0821   
 0822      $i = 0;
 0823      while ($row = $db->sql_fetchrow($result))
 0824      {
 0825          $template->assign_block_vars('custom_tags', array(
 0826              'BBCODE_NAME'        => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
 0827              'BBCODE_ID'            => $num_predefined_bbcodes + ($i * 2),
 0828              'BBCODE_TAG'        => $row['bbcode_tag'],
 0829              'BBCODE_HELPLINE'    => $row['bbcode_helpline'],
 0830              'A_BBCODE_HELPLINE'    => str_replace(array('&amp;', '&quot;', "'", '&lt;', '&gt;'), array('&', '"', "\'", '<', '>'), $row['bbcode_helpline']),
 0831          ));
 0832   
 0833          $i++;
 0834      }
 0835      $db->sql_freeresult($result);
 0836  }
 0837   
 0838  /**
 0839  * Display reasons
 0840  */
 0841  function display_reasons($reason_id = 0)
 0842  {
 0843      global $db, $user, $template;
 0844   
 0845      $sql = 'SELECT *
 0846          FROM ' . REPORTS_REASONS_TABLE . '
 0847          ORDER BY reason_order ASC';
 0848      $result = $db->sql_query($sql);
 0849   
 0850      while ($row = $db->sql_fetchrow($result))
 0851      {
 0852          // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
 0853          if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
 0854          {
 0855              $row['reason_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
 0856              $row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
 0857          }
 0858   
 0859          $template->assign_block_vars('reason', array(
 0860              'ID'            => $row['reason_id'],
 0861              'TITLE'            => $row['reason_title'],
 0862              'DESCRIPTION'    => $row['reason_description'],
 0863              'S_SELECTED'    => ($row['reason_id'] == $reason_id) ? true : false)
 0864          );
 0865      }
 0866      $db->sql_freeresult($result);
 0867  }
 0868   
 0869  /**
 0870  * Display user activity (action forum/topic)
 0871  */
 0872  function display_user_activity(&$userdata)
 0873  {
 0874      global $auth, $template, $db, $user;
 0875      global $phpbb_root_path, $phpEx;
 0876   
 0877      // Do not display user activity for users having more than 5000 posts...
 0878      if ($userdata['user_posts'] > 5000)
 0879      {
 0880          return;
 0881      }
 0882   
 0883      $forum_ary = array();
 0884   
 0885      // Do not include those forums the user is not having read access to...
 0886      $forum_read_ary = $auth->acl_getf('!f_read');
 0887   
 0888      foreach ($forum_read_ary as $forum_id => $not_allowed)
 0889      {
 0890          if ($not_allowed['f_read'])
 0891          {
 0892              $forum_ary[] = (int) $forum_id;
 0893          }
 0894      }
 0895   
 0896      $forum_ary = array_unique($forum_ary);
 0897      $forum_sql = (sizeof($forum_ary)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary, true) : '';
 0898   
 0899      // Obtain active forum
 0900      $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts
 0901          FROM ' . POSTS_TABLE . '
 0902          WHERE poster_id = ' . $userdata['user_id'] . "
 0903              AND post_postcount = 1
 0904              $forum_sql
 0905          GROUP BY forum_id
 0906          ORDER BY num_posts DESC";
 0907      $result = $db->sql_query_limit($sql, 1);
 0908      $active_f_row = $db->sql_fetchrow($result);
 0909      $db->sql_freeresult($result);
 0910   
 0911      if (!empty($active_f_row))
 0912      {
 0913          $sql = 'SELECT forum_name
 0914              FROM ' . FORUMS_TABLE . '
 0915              WHERE forum_id = ' . $active_f_row['forum_id'];
 0916          $result = $db->sql_query($sql, 3600);
 0917          $active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name');
 0918          $db->sql_freeresult($result);
 0919      }
 0920   
 0921      // Obtain active topic
 0922      $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts
 0923          FROM ' . POSTS_TABLE . '
 0924          WHERE poster_id = ' . $userdata['user_id'] . "
 0925              AND post_postcount = 1
 0926              $forum_sql
 0927          GROUP BY topic_id
 0928          ORDER BY num_posts DESC";
 0929      $result = $db->sql_query_limit($sql, 1);
 0930      $active_t_row = $db->sql_fetchrow($result);
 0931      $db->sql_freeresult($result);
 0932   
 0933      if (!empty($active_t_row))
 0934      {
 0935          $sql = 'SELECT topic_title
 0936              FROM ' . TOPICS_TABLE . '
 0937              WHERE topic_id = ' . $active_t_row['topic_id'];
 0938          $result = $db->sql_query($sql);
 0939          $active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title');
 0940          $db->sql_freeresult($result);
 0941      }
 0942   
 0943      $userdata['active_t_row'] = $active_t_row;
 0944      $userdata['active_f_row'] = $active_f_row;
 0945   
 0946      $active_f_name = $active_f_id = $active_f_count = $active_f_pct = '';
 0947      if (!empty($active_f_row['num_posts']))
 0948      {
 0949          $active_f_name = $active_f_row['forum_name'];
 0950          $active_f_id = $active_f_row['forum_id'];
 0951          $active_f_count = $active_f_row['num_posts'];
 0952          $active_f_pct = ($userdata['user_posts']) ? ($active_f_count / $userdata['user_posts']) * 100 : 0;
 0953      }
 0954   
 0955      $active_t_name = $active_t_id = $active_t_count = $active_t_pct = '';
 0956      if (!empty($active_t_row['num_posts']))
 0957      {
 0958          $active_t_name = $active_t_row['topic_title'];
 0959          $active_t_id = $active_t_row['topic_id'];
 0960          $active_t_count = $active_t_row['num_posts'];
 0961          $active_t_pct = ($userdata['user_posts']) ? ($active_t_count / $userdata['user_posts']) * 100 : 0;
 0962      }
 0963   
 0964      $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'];
 0965   
 0966      $template->assign_vars(array(
 0967          'ACTIVE_FORUM'            => $active_f_name,
 0968          'ACTIVE_FORUM_POSTS'    => ($active_f_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_f_count),
 0969          'ACTIVE_FORUM_PCT'        => sprintf($l_active_pct, $active_f_pct),
 0970          'ACTIVE_TOPIC'            => censor_text($active_t_name),
 0971          'ACTIVE_TOPIC_POSTS'    => ($active_t_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_t_count),
 0972          'ACTIVE_TOPIC_PCT'        => sprintf($l_active_pct, $active_t_pct),
 0973          'U_ACTIVE_FORUM'        => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),
 0974          'U_ACTIVE_TOPIC'        => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id),
 0975          'S_SHOW_ACTIVITY'        => true)
 0976      );
 0977  }
 0978   
 0979  /**
 0980  * Topic and forum watching common code
 0981  */
 0982  function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0)
 0983  {
 0984      global $template, $db, $user, $phpEx, $start, $phpbb_root_path;
 0985   
 0986      $table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE;
 0987      $where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id';
 0988      $match_id = ($mode == 'forum') ? $forum_id : $topic_id;
 0989   
 0990      $u_url = ($mode == 'forum') ? 'f' : 'f=' . $forum_id . '&amp;t';
 0991   
 0992      // Is user watching this thread?
 0993      if ($user_id != ANONYMOUS)
 0994      {
 0995          $can_watch = true;
 0996   
 0997          if ($notify_status == 'unset')
 0998          {
 0999              $sql = "SELECT notify_status
 1000                  FROM $table_sql
 1001                  WHERE $where_sql = $match_id
 1002                      AND user_id = $user_id";
 1003              $result = $db->sql_query($sql);
 1004   
 1005              $notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL;
 1006              $db->sql_freeresult($result);
 1007          }
 1008   
 1009          if (!is_null($notify_status) && $notify_status !== '')
 1010          {
 1011              if (isset($_GET['unwatch']))
 1012              {
 1013                  if ($_GET['unwatch'] == $mode)
 1014                  {
 1015                      $is_watching = 0;
 1016   
 1017                      $sql = 'DELETE FROM ' . $table_sql . "
 1018                          WHERE $where_sql = $match_id
 1019                              AND user_id = $user_id";
 1020                      $db->sql_query($sql);
 1021                  }
 1022   
 1023                  $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
 1024   
 1025                  meta_refresh(3, $redirect_url);
 1026   
 1027                  $message = $user->lang['NOT_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
 1028                  trigger_error($message);
 1029              }
 1030              else
 1031              {
 1032                  $is_watching = true;
 1033   
 1034                  if ($notify_status)
 1035                  {
 1036                      $sql = 'UPDATE ' . $table_sql . "
 1037                          SET notify_status = 0
 1038                          WHERE $where_sql = $match_id
 1039                              AND user_id = $user_id";
 1040                      $db->sql_query($sql);
 1041                  }
 1042              }
 1043          }
 1044          else
 1045          {
 1046              if (isset($_GET['watch']))
 1047              {
 1048                  if ($_GET['watch'] == $mode)
 1049                  {
 1050                      $is_watching = true;
 1051   
 1052                      $sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status)
 1053                          VALUES ($user_id, $match_id, 0)";
 1054                      $db->sql_query($sql);
 1055                  }
 1056   
 1057                  $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
 1058                  meta_refresh(3, $redirect_url);
 1059   
 1060                  $message = $user->lang['ARE_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
 1061                  trigger_error($message);
 1062              }
 1063              else
 1064              {
 1065                  $is_watching = 0;
 1066              }
 1067          }
 1068      }
 1069      else
 1070      {
 1071          if (isset($_GET['unwatch']) && $_GET['unwatch'] == $mode)
 1072          {
 1073              login_box();
 1074          }
 1075          else
 1076          {
 1077              $can_watch = 0;
 1078              $is_watching = 0;
 1079          }
 1080      }
 1081   
 1082      if ($can_watch)
 1083      {
 1084          $s_watching['link'] = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;" . (($is_watching) ? 'unwatch' : 'watch') . "=$mode&amp;start=$start");
 1085          $s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
 1086          $s_watching['is_watching'] = $is_watching;
 1087      }
 1088   
 1089      return;
 1090  }
 1091   
 1092  /**
 1093  * Get user rank title and image
 1094  *
 1095  * @param int $user_rank the current stored users rank id
 1096  * @param int $user_posts the users number of posts
 1097  * @param string &$rank_title the rank title will be stored here after execution
 1098  * @param string &$rank_img the rank image as full img tag is stored here after execution
 1099  * @param string &$rank_img_src the rank image source is stored here after execution
 1100  *
 1101  */
 1102  function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank_img_src)
 1103  {
 1104      global $ranks, $config;
 1105   
 1106      if (empty($ranks))
 1107      {
 1108          global $cache;
 1109          $ranks = $cache->obtain_ranks();
 1110      }
 1111   
 1112      if (!empty($user_rank))
 1113      {
 1114          $rank_title = (isset($ranks['special'][$user_rank]['rank_title'])) ? $ranks['special'][$user_rank]['rank_title'] : '';
 1115          $rank_img = (!empty($ranks['special'][$user_rank]['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] . '" alt="' . $ranks['special'][$user_rank]['rank_title'] . '" title="' . $ranks['special'][$user_rank]['rank_title'] . '" />' : '';
 1116          $rank_img_src = (!empty($ranks['special'][$user_rank]['rank_image'])) ? $config['ranks_path'] . '/' . $ranks['special'][$user_rank]['rank_image'] : '';
 1117      }
 1118      else
 1119      {
 1120          if (!empty($ranks['normal']))
 1121          {
 1122              foreach ($ranks['normal'] as $rank)
 1123              {
 1124                  if ($user_posts >= $rank['rank_min'])
 1125                  {
 1126                      $rank_title = $rank['rank_title'];
 1127                      $rank_img = (!empty($rank['rank_image'])) ? '<img src="' . $config['ranks_path'] . '/' . $rank['rank_image'] . '" alt="' . $rank['rank_title'] . '" title="' . $rank['rank_title'] . '" />' : '';
 1128                      $rank_img_src = (!empty($rank['rank_image'])) ? $config['ranks_path'] . '/' . $rank['rank_image'] : '';
 1129                      break;
 1130                  }
 1131              }
 1132          }
 1133      }
 1134  }
 1135   
 1136  /**
 1137  * Get user avatar
 1138  *
 1139  * @param string $avatar Users assigned avatar name
 1140  * @param int $avatar_type Type of avatar
 1141  * @param string $avatar_width Width of users avatar
 1142  * @param string $avatar_height Height of users avatar
 1143  * @param string $alt Optional language string for alt tag within image, can be a language key or text
 1144  *
 1145  * @return string Avatar image
 1146  */
 1147  function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $alt = 'USER_AVATAR')
 1148  {
 1149      global $user, $config, $phpbb_root_path, $phpEx;
 1150   
 1151      if (empty($avatar) || !$avatar_type)
 1152      {
 1153          return '';
 1154      }
 1155   
 1156      $avatar_img = '';
 1157   
 1158      switch ($avatar_type)
 1159      {
 1160          case AVATAR_UPLOAD:
 1161              $avatar_img = $phpbb_root_path . "download/file.$phpEx?avatar=";
 1162          break;
 1163   
 1164          case AVATAR_GALLERY:
 1165              $avatar_img = $phpbb_root_path . $config['avatar_gallery_path'] . '/';
 1166          break;
 1167      }
 1168   
 1169      $avatar_img .= $avatar;
 1170      return '<img src="' . $avatar_img . '" width="' . $avatar_width . '" height="' . $avatar_height . '" alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
 1171  }
 1172   
 1173  ?>