[ Index ]

PHP Cross Reference of phpBB 3.0 Beta 3

title

Body

[close]

/includes/ -> functions_display.php (source)

   1  <?php
   2  /** 
   3  *
   4  * @package phpBB3
   5  * @version $Id: functions_display.php,v 1.127 2006/11/12 19:24:30 acydburn Exp $
   6  * @copyright (c) 2005 phpBB Group 
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
   8  *
   9  */
  10  
  11  /**
  12  * Display Forums
  13  */
  14  function display_forums($root_data = '', $display_moderators = true, $return_moderators = false)
  15  {
  16      global $db, $auth, $user, $template;
  17      global $phpbb_root_path, $phpEx, $config;
  18  
  19      $forum_rows = $subforums = $forum_ids = $forum_ids_moderator = $forum_moderators = $active_forum_ary = array();
  20      $parent_id = $visible_forums = 0;
  21      $sql_from = $lastread_select = '';
  22      
  23      // Mark forums read?
  24      $mark_read = request_var('mark', '');
  25  
  26      if ($mark_read == 'all')
  27      {
  28          $mark_read = '';
  29      }
  30  
  31      if (!$root_data)
  32      {
  33          if ($mark_read == 'forums')
  34          {
  35              $mark_read = 'all';
  36          }
  37  
  38          $root_data = array('forum_id' => 0);
  39          $sql_where = '';
  40      }
  41      else
  42      {
  43          $sql_where = ' WHERE left_id > ' . $root_data['left_id'] . ' AND left_id < ' . $root_data['right_id'];
  44      }
  45  
  46      // Display list of active topics for this category?
  47      $show_active = (isset($root_data['forum_flags']) && ($root_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS)) ? true : false;
  48  
  49      $sql_from = FORUMS_TABLE . ' f ';
  50      $lastread_select = $sql_lastread = '';
  51  
  52      if ($config['load_db_lastread'] && $user->data['is_registered'])
  53      {
  54          $sql_from = FORUMS_TABLE . ' f LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . ' AND ft.forum_id = f.forum_id)';
  55          $lastread_select = ', ft.mark_time ';
  56      }
  57      else if ($config['load_anon_lastread'] || $user->data['is_registered'])
  58      {
  59          $tracking_topics = (isset($_COOKIE[$config['cookie_name'] . '_track'])) ? ((STRIP) ? stripslashes($_COOKIE[$config['cookie_name'] . '_track']) : $_COOKIE[$config['cookie_name'] . '_track']) : '';
  60          $tracking_topics = ($tracking_topics) ? unserialize($tracking_topics) : array();
  61  
  62          if (!$user->data['is_registered'])
  63          {
  64              $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
  65          }
  66      }
  67  
  68      $sql = "SELECT f.* $lastread_select
  69          FROM $sql_from
  70          $sql_where
  71          ORDER BY f.left_id";
  72      $result = $db->sql_query($sql);
  73  
  74      $forum_tracking_info = array();
  75      $branch_root_id = $root_data['forum_id'];
  76      while ($row = $db->sql_fetchrow($result))
  77      {
  78          $forum_id = $row['forum_id'];
  79  
  80          // Mark forums read?
  81          if ($mark_read == 'forums' || $mark_read == 'all')
  82          {
  83              if ($auth->acl_get('f_list', $forum_id))
  84              {
  85                  $forum_ids[] = $forum_id;
  86                  continue;
  87              }
  88          }
  89  
  90          // Category with no members
  91          if ($row['forum_type'] == FORUM_CAT && ($row['left_id'] + 1 == $row['right_id']))
  92          {
  93              continue;
  94          }
  95  
  96          // Skip branch
  97          if (isset($right_id))
  98          {
  99              if ($row['left_id'] < $right_id)
 100              {
 101                  continue;
 102              }
 103              unset($right_id);
 104          }
 105  
 106          if (!$auth->acl_get('f_list', $forum_id))
 107          {
 108              // if the user does not have permissions to list this forum, skip everything until next branch
 109              $right_id = $row['right_id'];
 110              continue;
 111          }
 112  
 113          $forum_ids[] = $forum_id;
 114  
 115          if ($config['load_db_lastread'] && $user->data['is_registered'])
 116          {
 117              $forum_tracking_info[$forum_id] = (!empty($row['mark_time'])) ? $row['mark_time'] : $user->data['user_lastmark'];
 118          }
 119          else if ($config['load_anon_lastread'] || $user->data['is_registered'])
 120          {
 121              if (!$user->data['is_registered'])
 122              {
 123                  $user->data['user_lastmark'] = (isset($tracking_topics['l'])) ? (int) (base_convert($tracking_topics['l'], 36, 10) + $config['board_startdate']) : 0;
 124              }
 125              $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'];
 126          }
 127  
 128          // Display active topics from this forum?
 129          if ($show_active && $row['forum_type'] == FORUM_POST && $auth->acl_get('f_read', $forum_id) && ($row['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS))
 130          {
 131              if (!isset($active_forum_ary['forum_topics']))
 132              {
 133                  $active_forum_ary['forum_topics'] = 0;
 134              }
 135  
 136              if (!isset($active_forum_ary['forum_posts']))
 137              {
 138                  $active_forum_ary['forum_posts'] = 0;
 139              }
 140  
 141              $active_forum_ary['forum_id'][]        = $forum_id;
 142              $active_forum_ary['enable_icons'][]    = $row['enable_icons'];
 143              $active_forum_ary['forum_topics']    += ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics'];
 144              $active_forum_ary['forum_posts']    += $row['forum_posts'];
 145          }
 146  
 147          //
 148          if ($row['parent_id'] == $root_data['forum_id'] || $row['parent_id'] == $branch_root_id)
 149          {
 150              if ($row['forum_type'] != FORUM_CAT)
 151              {
 152                  $forum_ids_moderator[] = $forum_id;
 153              }
 154  
 155              // Direct child of current branch
 156              $parent_id = $forum_id;
 157              $forum_rows[$forum_id] = $row;
 158  
 159              if ($row['forum_type'] == FORUM_CAT && $row['parent_id'] == $root_data['forum_id'])
 160              {
 161                  $branch_root_id = $forum_id;
 162              }
 163              $forum_rows[$parent_id]['forum_id_last_post'] = $row['forum_id'];
 164              $forum_rows[$parent_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
 165          }
 166          else if ($row['forum_type'] != FORUM_CAT)
 167          {
 168              $subforums[$parent_id][$forum_id]['display'] = ($row['display_on_index']) ? true : false;
 169              $subforums[$parent_id][$forum_id]['name'] = $row['forum_name'];
 170              $subforums[$parent_id][$forum_id]['orig_forum_last_post_time'] = $row['forum_last_post_time'];
 171  
 172              $forum_rows[$parent_id]['forum_topics'] += ($auth->acl_get('m_approve', $forum_id)) ? $row['forum_topics_real'] : $row['forum_topics'];
 173  
 174              // Do not list redirects in LINK Forums as Posts.
 175              if ($row['forum_type'] != FORUM_LINK)
 176              {
 177                  $forum_rows[$parent_id]['forum_posts'] += $row['forum_posts'];
 178              }
 179  
 180              if ($row['forum_last_post_time'] > $forum_rows[$parent_id]['forum_last_post_time'])
 181              {
 182                  $forum_rows[$parent_id]['forum_last_post_id'] = $row['forum_last_post_id'];
 183                  $forum_rows[$parent_id]['forum_last_post_subject'] = $row['forum_last_post_subject'];
 184                  $forum_rows[$parent_id]['forum_last_post_time'] = $row['forum_last_post_time'];
 185                  $forum_rows[$parent_id]['forum_last_poster_id'] = $row['forum_last_poster_id'];
 186                  $forum_rows[$parent_id]['forum_last_poster_name'] = $row['forum_last_poster_name'];
 187                  $forum_rows[$parent_id]['forum_last_poster_colour'] = $row['forum_last_poster_colour'];
 188                  $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
 189              }
 190              else
 191              {
 192                  $forum_rows[$parent_id]['forum_id_last_post'] = $forum_id;
 193              }
 194          }
 195      }
 196      $db->sql_freeresult($result);
 197  
 198      // Handle marking posts
 199      if ($mark_read == 'forums' || $mark_read == 'all')
 200      {
 201          $redirect = build_url('mark');
 202  
 203          if ($mark_read == 'all')
 204          {
 205              markread('all');
 206  
 207              $message = sprintf($user->lang['RETURN_INDEX'], '<a href="' . $redirect . '">', '</a>');
 208          }
 209          else
 210          {
 211              markread('topics', $forum_ids);
 212  
 213              $message = sprintf($user->lang['RETURN_FORUM'], '<a href="' . $redirect . '">', '</a>');
 214          }
 215  
 216          meta_refresh(3, $redirect);
 217          trigger_error($user->lang['FORUMS_MARKED'] . '<br /><br />' . $message);
 218      }
 219  
 220      // Grab moderators ... if necessary
 221      if ($display_moderators)
 222      {
 223          if ($return_moderators)
 224          {
 225              $forum_ids_moderator[] = $root_data['forum_id'];
 226          }
 227          get_moderators($forum_moderators, $forum_ids_moderator);
 228      }
 229  
 230      foreach ($forum_rows as $row)
 231      {
 232          // Empty category
 233          if ($row['parent_id'] == $root_data['forum_id'] && $row['forum_type'] == FORUM_CAT)
 234          {
 235              $template->assign_block_vars('forumrow', array(
 236                  'S_IS_CAT'                => true,
 237                  'FORUM_ID'                => $row['forum_id'],
 238                  'FORUM_NAME'            => $row['forum_name'],
 239                  'FORUM_DESC'            => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
 240                  'FORUM_FOLDER_IMG'        => '',
 241                  'FORUM_FOLDER_IMG_SRC'    => '',
 242                  'FORUM_IMAGE'            => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang['FORUM_CAT'] . '" />' : '',
 243                  'FORUM_IMAGE_SRC'        => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
 244                  'U_VIEWFORUM'            => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))
 245              );
 246  
 247              continue;
 248          }
 249  
 250          $visible_forums++;
 251          $forum_id = $row['forum_id'];
 252  
 253          $forum_unread = (isset($forum_tracking_info[$forum_id]) && $row['orig_forum_last_post_time'] > $forum_tracking_info[$forum_id]) ? true : false;
 254  
 255          $folder_image = $folder_alt = $subforums_list = $l_subforums = '';
 256  
 257          // Generate list of subforums if we need to
 258          if (isset($subforums[$forum_id]))
 259          {
 260              foreach ($subforums[$forum_id] as $subforum_id => $subforum_row)
 261              {
 262                  // Update unread information if needed
 263                  if (!$forum_unread)
 264                  {
 265                      $forum_unread = (isset($forum_tracking_info[$subforum_id]) && $subforum_row['orig_forum_last_post_time'] > $forum_tracking_info[$subforum_id]) ? true : false;
 266                  }
 267  
 268                  if ($subforum_row['display'] && $subforum_row['name'])
 269                  {
 270                      $subforums_list .= ($subforums_list == '') ? '' : ', ';
 271                      $subforums_list .= '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $subforum_id) . '">' . $subforum_row['name'] . '</a>';
 272                  }
 273                  else
 274                  {
 275                      unset($subforums[$forum_id][$subforum_id]);
 276                  }
 277              }
 278  
 279              $l_subforums = (sizeof($subforums[$forum_id]) == 1) ? $user->lang['SUBFORUM'] . ': ' : $user->lang['SUBFORUMS'] . ': ';
 280              $folder_image = ($forum_unread) ? 'forum_unread_subforum' : 'forum_read_subforum';
 281          }
 282          else
 283          {
 284              switch ($row['forum_type'])
 285              {
 286                  case FORUM_POST:
 287                      $folder_image = ($forum_unread) ? 'forum_unread' : 'forum_read';
 288                  break;
 289  
 290                  case FORUM_LINK:
 291                      $folder_image = 'forum_link';
 292                  break;
 293              }
 294          }
 295  
 296          // Which folder should we display?
 297          if ($row['forum_status'] == ITEM_LOCKED)
 298          {
 299              $folder_image = ($forum_unread) ? 'forum_unread_locked' : 'forum_read_locked';
 300              $folder_alt = 'FORUM_LOCKED';
 301          }
 302          else
 303          {
 304              $folder_alt = ($forum_unread) ? 'NEW_POSTS' : 'NO_NEW_POSTS';
 305          }
 306  
 307          // Create last post link information, if appropriate
 308          if ($row['forum_last_post_id'])
 309          {
 310              $last_post_subject = $row['forum_last_post_subject'];
 311              $last_post_time = $user->format_date($row['forum_last_post_time']);
 312  
 313              $last_poster = ($row['forum_last_poster_name'] != '') ? $row['forum_last_poster_name'] : $user->lang['GUEST'];
 314              $last_poster_colour = ($row['forum_last_poster_colour']) ? '#' . $row['forum_last_poster_colour'] : '';
 315              $last_poster_url = ($row['forum_last_poster_id'] == ANONYMOUS) ? '' : append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['forum_last_poster_id']);
 316  
 317              $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'];
 318          }
 319          else
 320          {
 321              $last_post_subject = $last_post_time = $last_poster = $last_poster_colour = $last_poster_url = $last_post_url = '';
 322          }
 323  
 324          // Output moderator listing ... if applicable
 325          $l_moderator = $moderators_list = '';
 326          if ($display_moderators && !empty($forum_moderators[$forum_id]))
 327          {
 328              $l_moderator = (sizeof($forum_moderators[$forum_id]) == 1) ? $user->lang['MODERATOR'] : $user->lang['MODERATORS'];
 329              $moderators_list = implode(', ', $forum_moderators[$forum_id]);
 330          }
 331  
 332          $l_post_click_count = ($row['forum_type'] == FORUM_LINK) ? 'CLICKS' : 'POSTS';
 333          $post_click_count = ($row['forum_type'] != FORUM_LINK || $row['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? $row['forum_posts'] : '';
 334  
 335          $template->assign_block_vars('forumrow', array(
 336              'S_IS_CAT'            => false,
 337              'S_IS_LINK'            => ($row['forum_type'] == FORUM_LINK) ? true : false,
 338              'S_UNREAD_FORUM'    => $forum_unread,
 339              'S_LOCKED_FORUM'    => ($row['forum_status'] == ITEM_LOCKED) ? true : false,
 340  
 341              'FORUM_ID'                => $row['forum_id'],
 342              'FORUM_NAME'            => $row['forum_name'],
 343              'FORUM_DESC'            => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
 344              'TOPICS'                => $row['forum_topics'],
 345              $l_post_click_count        => $post_click_count,
 346              'FORUM_FOLDER_IMG'        => $user->img($folder_image, $folder_alt),
 347              'FORUM_FOLDER_IMG_SRC'    => $user->img($folder_image, $folder_alt, false, '', 'src'),
 348              'FORUM_IMAGE'            => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
 349              'FORUM_IMAGE_SRC'        => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
 350              'SUBFORUMS'                => $subforums_list,
 351              'LAST_POST_SUBJECT'        => censor_text($last_post_subject),
 352              'LAST_POST_TIME'        => $last_post_time,
 353              'LAST_POSTER'            => $last_poster,
 354              'LAST_POSTER_COLOUR'    => $last_poster_colour,
 355              'MODERATORS'            => $moderators_list,
 356  
 357              'L_SUBFORUM_STR'        => $l_subforums,
 358              'L_FORUM_FOLDER_ALT'    => $folder_alt,
 359              'L_MODERATOR_STR'        => $l_moderator,
 360  
 361              'U_VIEWFORUM'        => ($row['forum_type'] != FORUM_LINK || ($row['forum_flags'] & FORUM_FLAG_LINK_TRACK)) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']) : $row['forum_link'],
 362              'U_LAST_POSTER'        => $last_poster_url,
 363              'U_LAST_POST'        => $last_post_url)
 364          );
 365      }
 366  
 367      $template->assign_vars(array(
 368          'U_MARK_FORUMS'        => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $root_data['forum_id'] . '&amp;mark=forums'),
 369          'S_HAS_SUBFORUM'    => ($visible_forums) ? true : false,
 370          'L_SUBFORUM'        => ($visible_forums == 1) ? $user->lang['SUBFORUM'] : $user->lang['SUBFORUMS'],
 371          'LAST_POST_IMG'        => $user->img('icon_topic_latest', 'VIEW_LATEST_POST'))
 372      );
 373  
 374      if ($return_moderators)
 375      {
 376          return array($active_forum_ary, $forum_moderators);
 377      }
 378  
 379      return array($active_forum_ary, array());
 380  }
 381  
 382  /**
 383  * Create forum rules for given forum
 384  */
 385  function generate_forum_rules(&$forum_data)
 386  {
 387      if (!$forum_data['forum_rules'] && !$forum_data['forum_rules_link'])
 388      {
 389          return;
 390      }
 391  
 392      global $template, $phpbb_root_path, $phpEx;
 393  
 394      if ($forum_data['forum_rules'])
 395      {
 396          $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']);
 397      }
 398  
 399      $template->assign_vars(array(
 400          'S_FORUM_RULES'    => true,
 401          'U_FORUM_RULES'    => $forum_data['forum_rules_link'],
 402          'FORUM_RULES'    => $forum_data['forum_rules'])
 403      );
 404  }
 405  
 406  /**
 407  * Create forum navigation links for given forum, create parent
 408  * list if currently null, assign basic forum info to template
 409  */
 410  function generate_forum_nav(&$forum_data)
 411  {
 412      global $db, $user, $template, $auth;
 413      global $phpEx, $phpbb_root_path;
 414  
 415      if (!$auth->acl_get('f_list', $forum_data['forum_id']))
 416      {
 417          return;
 418      }
 419  
 420      // Get forum parents
 421      $forum_parents = get_forum_parents($forum_data);
 422  
 423      // Build navigation links
 424      foreach ($forum_parents as $parent_forum_id => $parent_data)
 425      {
 426          list($parent_name, $parent_type) = array_values($parent_data);
 427  
 428          // Skip this parent if the user does not have the permission to view it
 429          if (!$auth->acl_get('f_list', $parent_forum_id))
 430          {
 431              continue;
 432          }
 433  
 434          $template->assign_block_vars('navlinks', array(
 435              'S_IS_CAT'        => ($parent_type == FORUM_CAT) ? true : false,
 436              'S_IS_LINK'        => ($parent_type == FORUM_LINK) ? true : false,
 437              'S_IS_POST'        => ($parent_type == FORUM_POST) ? true : false,
 438              'FORUM_NAME'    => $parent_name,
 439              'FORUM_ID'        => $parent_forum_id,
 440              'U_VIEW_FORUM'    => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id))
 441          );
 442      }
 443  
 444      $template->assign_block_vars('navlinks', array(
 445          'S_IS_CAT'        => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
 446          'S_IS_LINK'        => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
 447          'S_IS_POST'        => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
 448          'FORUM_NAME'    => $forum_data['forum_name'],
 449          'FORUM_ID'        => $forum_data['forum_id'],
 450          'U_VIEW_FORUM'    => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data['forum_id']))
 451      );
 452  
 453      $template->assign_vars(array(
 454          'FORUM_ID'         => $forum_data['forum_id'],
 455          'FORUM_NAME'    => $forum_data['forum_name'],
 456          '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']))
 457      );
 458  
 459      return;
 460  }
 461  
 462  /**
 463  * Returns forum parents as an array. Get them from forum_data if available, or update the database otherwise
 464  */
 465  function get_forum_parents(&$forum_data)
 466  {
 467      global $db;
 468  
 469      $forum_parents = array();
 470  
 471      if ($forum_data['parent_id'] > 0)
 472      {
 473          if ($forum_data['forum_parents'] == '')
 474          {
 475              $sql = 'SELECT forum_id, forum_name, forum_type
 476                  FROM ' . FORUMS_TABLE . '
 477                  WHERE left_id < ' . $forum_data['left_id'] . '
 478                      AND right_id > ' . $forum_data['right_id'] . '
 479                  ORDER BY left_id ASC';
 480              $result = $db->sql_query($sql);
 481  
 482              while ($row = $db->sql_fetchrow($result))
 483              {
 484                  $forum_parents[$row['forum_id']] = array($row['forum_name'], (int) $row['forum_type']);
 485              }
 486              $db->sql_freeresult($result);
 487  
 488              $forum_data['forum_parents'] = serialize($forum_parents);
 489  
 490              $sql = 'UPDATE ' . FORUMS_TABLE . "
 491                  SET forum_parents = '" . $db->sql_escape($forum_data['forum_parents']) . "'
 492                  WHERE parent_id = " . $forum_data['parent_id'];
 493              $db->sql_query($sql);
 494          }
 495          else
 496          {
 497              $forum_parents = unserialize($forum_data['forum_parents']);
 498          }
 499      }
 500  
 501      return $forum_parents;
 502  }
 503  
 504  /**
 505  * Generate topic pagination
 506  */
 507  function topic_generate_pagination($replies, $url)
 508  {
 509      global $config, $user;
 510  
 511      if (($replies + 1) > $config['posts_per_page'])
 512      {
 513          $total_pages = ceil(($replies + 1) / $config['posts_per_page']);
 514          $pagination = '';
 515  
 516          $times = 1;
 517          for ($j = 0; $j < $replies + 1; $j += $config['posts_per_page'])
 518          {
 519              $pagination .= '<a href="' . $url . '&amp;start=' . $j . '">' . $times . '</a>';
 520              if ($times == 1 && $total_pages > 4)
 521              {
 522                  $pagination .= ' ... ';
 523                  $times = $total_pages - 3;
 524                  $j += ($total_pages - 4) * $config['posts_per_page'];
 525              }
 526              else if ($times < $total_pages)
 527              {
 528                  $pagination .= $user->theme['pagination_sep'];
 529              }
 530              $times++;
 531          }
 532      }
 533      else
 534      {
 535          $pagination = '';
 536      }
 537  
 538      return $pagination;
 539  }
 540  
 541  /**
 542  * Obtain list of moderators of each forum
 543  */
 544  function get_moderators(&$forum_moderators, $forum_id = false)
 545  {
 546      global $config, $template, $db, $phpbb_root_path, $phpEx;
 547  
 548      // Have we disabled the display of moderators? If so, then return
 549      // from whence we came ...
 550      if (!$config['load_moderators'])
 551      {
 552          return;
 553      }
 554  
 555      $forum_sql = '';
 556  
 557      if ($forum_id !== false)
 558      {
 559          if (!is_array($forum_id))
 560          {
 561              $forum_id = array($forum_id);
 562          }
 563  
 564          // If we don't have a forum then we can't have a moderator
 565          if (!sizeof($forum_id))
 566          {
 567              return;
 568          }
 569  
 570          $forum_sql = 'AND ' . $db->sql_in_set('forum_id', $forum_id);
 571      }
 572  
 573      $sql = 'SELECT *
 574          FROM ' . MODERATOR_CACHE_TABLE . "
 575          WHERE display_on_index = 1
 576              $forum_sql";
 577      $result = $db->sql_query($sql, 3600);
 578  
 579      while ($row = $db->sql_fetchrow($result))
 580      {
 581          $forum_moderators[$row['forum_id']][] = (!empty($row['user_id'])) ? '<a href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['user_id']) . '">' . $row['username'] . '</a>' : '<a href="' . append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&amp;g=' . $row['group_id']) . '">' . $row['group_name'] . '</a>';
 582      }
 583      $db->sql_freeresult($result);
 584  
 585      return;
 586  }
 587  
 588  /**
 589  * User authorisation levels output
 590  */
 591  function gen_forum_auth_level($mode, $forum_id, $forum_status)
 592  {
 593      global $template, $auth, $user, $config;
 594  
 595      $locked = ($forum_status == ITEM_LOCKED && !$auth->acl_get('m_edit', $forum_id)) ? true : false;
 596  
 597      $rules = array(
 598          ($auth->acl_get('f_post', $forum_id) && !$locked) ? $user->lang['RULES_POST_CAN'] : $user->lang['RULES_POST_CANNOT'],
 599          ($auth->acl_get('f_reply', $forum_id) && !$locked) ? $user->lang['RULES_REPLY_CAN'] : $user->lang['RULES_REPLY_CANNOT'],
 600          ($auth->acl_gets('f_edit', 'm_edit', $forum_id) && !$locked) ? $user->lang['RULES_EDIT_CAN'] : $user->lang['RULES_EDIT_CANNOT'],
 601          ($auth->acl_gets('f_delete', 'm_delete', $forum_id) && !$locked) ? $user->lang['RULES_DELETE_CAN'] : $user->lang['RULES_DELETE_CANNOT'],
 602      );
 603  
 604      if ($config['allow_attachments'])
 605      {
 606          $rules[] = ($auth->acl_get('f_attach', $forum_id) && $auth->acl_get('u_attach') && !$locked) ? $user->lang['RULES_ATTACH_CAN'] : $user->lang['RULES_ATTACH_CANNOT'];
 607      }
 608  
 609      foreach ($rules as $rule)
 610      {
 611          $template->assign_block_vars('rules', array('RULE' => $rule));
 612      }
 613  
 614      return;
 615  }
 616  
 617  /**
 618  * Generate topic status
 619  */
 620  function topic_status(&$topic_row, $replies, $unread_topic, &$folder_img, &$folder_alt, &$topic_type)
 621  {
 622      global $user, $config;
 623  
 624      $folder = $folder_new = '';
 625  
 626      if ($topic_row['topic_status'] == ITEM_MOVED)
 627      {
 628          $topic_type = $user->lang['VIEW_TOPIC_MOVED'];
 629          $folder_img = 'topic_moved';
 630          $folder_alt = 'VIEW_TOPIC_MOVED';
 631      }
 632      else
 633      {
 634          switch ($topic_row['topic_type'])
 635          {
 636              case POST_GLOBAL:
 637                  $topic_type = $user->lang['VIEW_TOPIC_GLOBAL'];
 638                  $folder = 'global_read';
 639                  $folder_new = 'global_unread';
 640              break;
 641  
 642              case POST_ANNOUNCE:
 643                  $topic_type = $user->lang['VIEW_TOPIC_ANNOUNCEMENT'];
 644                  $folder = 'announce_read';
 645                  $folder_new = 'announce_unread';
 646              break;
 647  
 648              case POST_STICKY:
 649                  $topic_type = $user->lang['VIEW_TOPIC_STICKY'];
 650                  $folder = 'sticky_read';
 651                  $folder_new = 'sticky_unread';
 652              break;
 653  
 654              default:
 655                  $topic_type = '';
 656                  $folder = 'topic_read';
 657                  $folder_new = 'topic_unread';
 658  
 659                  if ($config['hot_threshold'] && $replies >= $config['hot_threshold'] && $topic_row['topic_status'] != ITEM_LOCKED)
 660                  {
 661                      $folder .= '_hot';
 662                      $folder_new .= '_hot';
 663                  }
 664              break;
 665          }
 666  
 667          if ($topic_row['topic_status'] == ITEM_LOCKED)
 668          {
 669              $topic_type = $user->lang['VIEW_TOPIC_LOCKED'];
 670              $folder .= '_locked';
 671              $folder_new .= '_locked';
 672          }
 673  
 674  
 675          $folder_img = ($unread_topic) ? $folder_new : $folder;
 676          $folder_alt = ($unread_topic) ? 'NEW_POSTS' : (($topic_row['topic_status'] == ITEM_LOCKED) ? 'TOPIC_LOCKED' : 'NO_NEW_POSTS');
 677  
 678          // Posted image?
 679          if (!empty($topic_row['topic_posted']) && $topic_row['topic_posted'])
 680          {
 681              $folder_img .= '_mine';
 682          }
 683      }
 684  
 685      if ($topic_row['poll_start'])
 686      {
 687          $topic_type .= $user->lang['VIEW_TOPIC_POLL'];
 688      }
 689  }
 690  
 691  /**
 692  * Display Attachments
 693  */
 694  function display_attachments($forum_id, $blockname, &$attachment_data, &$update_count, $force_physical = false, $return = false)
 695  {
 696      global $template, $cache, $user;
 697      global $extensions, $config, $phpbb_root_path, $phpEx;
 698  
 699      $return_tpl = array();
 700  
 701      $template->set_filenames(array(
 702          'attachment_tpl'    => 'attachment.html')
 703      );
 704  
 705      if (!sizeof($attachment_data))
 706      {
 707          return array();
 708      }
 709  
 710      if (empty($extensions) || !is_array($extensions))
 711      {
 712          $extensions = $cache->obtain_attach_extensions();
 713      }
 714  
 715      // Look for missing attachment informations...
 716      $attach_ids = array();
 717      foreach ($attachment_data as $pos => $attachment)
 718      {
 719          // If is_orphan is set, we need to retrieve the attachments again...
 720          if (!isset($attachment['extension']) && !isset($attachment['physical_filename']))
 721          {
 722              $attach_ids[(int) $attachment['attach_id']] = $pos;
 723          }
 724      }
 725  
 726      if (sizeof($attach_ids))
 727      {
 728          global $db;
 729  
 730          $attachment_data = array();
 731  
 732          $sql = 'SELECT *
 733              FROM ' . ATTACHMENTS_TABLE . '
 734              WHERE ' . $db->sql_in_set('attach_id', array_keys($attach_ids));
 735          $result = $db->sql_query($sql);
 736  
 737          while ($row = $db->sql_fetchrow($result))
 738          {
 739              if (!isset($attach_ids[$row['attach_id']]))
 740              {
 741                  continue;
 742              }
 743  
 744              $attachment_data[$attach_ids[$row['attach_id']]] = $row;
 745          }
 746          $db->sql_freeresult($result);
 747  
 748          ksort($attachment_data);
 749      }
 750  
 751      foreach ($attachment_data as $attachment)
 752      {
 753          if (!sizeof($attachment))
 754          {
 755              continue;
 756          }
 757  
 758          // We need to reset/empty the _file block var, because this function might be called more than once
 759          $template->destroy_block_vars('_file');
 760  
 761          $block_array = array();
 762          
 763          // Some basics...
 764          $attachment['extension'] = strtolower(trim($attachment['extension']));
 765          $filename = $phpbb_root_path . $config['upload_path'] . '/' . basename($attachment['physical_filename']);
 766          $thumbnail_filename = $phpbb_root_path . $config['upload_path'] . '/thumb_' . basename($attachment['physical_filename']);
 767  
 768          $upload_icon = '';
 769  
 770          if (isset($extensions[$attachment['extension']]))
 771          {
 772              if ($user->img('icon_topic_attach', '') && !$extensions[$attachment['extension']]['upload_icon'])
 773              {
 774                  $upload_icon = $user->img('icon_topic_attach', '');
 775              }
 776              else if ($extensions[$attachment['extension']]['upload_icon'])
 777              {
 778                  $upload_icon = '<img src="' . $phpbb_root_path . $config['upload_icons_path'] . '/' . trim($extensions[$attachment['extension']]['upload_icon']) . '" alt="" />';
 779              }
 780          }
 781  
 782          $filesize = $attachment['filesize'];
 783          $size_lang = ($filesize >= 1048576) ? $user->lang['MB'] : ( ($filesize >= 1024) ? $user->lang['KB'] : $user->lang['BYTES'] );
 784          $filesize = ($filesize >= 1048576) ? round((round($filesize / 1048576 * 100) / 100), 2) : (($filesize >= 1024) ? round((round($filesize / 1024 * 100) / 100), 2) : $filesize);
 785  
 786          $comment = str_replace("\n", '<br />', censor_text($attachment['attach_comment']));
 787  
 788          $block_array += array(
 789              'UPLOAD_ICON'        => $upload_icon,
 790              'FILESIZE'            => $filesize,
 791              'SIZE_LANG'            => $size_lang,
 792              'DOWNLOAD_NAME'        => basename($attachment['real_filename']),
 793              'COMMENT'            => $comment,
 794          );
 795  
 796          $denied = false;
 797  
 798          if (!extension_allowed($forum_id, $attachment['extension'], $extensions))
 799          {
 800              $denied = true;
 801  
 802              $block_array += array(
 803                  'S_DENIED'            => true,
 804                  'DENIED_MESSAGE'    => sprintf($user->lang['EXTENSION_DISABLED_AFTER_POSTING'], $attachment['extension'])
 805              );
 806          }
 807  
 808          if (!$denied)
 809          {
 810              $l_downloaded_viewed = $download_link = '';
 811              $display_cat = $extensions[$attachment['extension']]['display_cat'];
 812  
 813              if ($display_cat == ATTACHMENT_CATEGORY_IMAGE)
 814              {
 815                  if ($attachment['thumbnail'])
 816                  {
 817                      $display_cat = ATTACHMENT_CATEGORY_THUMB;
 818                  }
 819                  else
 820                  {
 821                      if ($config['img_display_inlined'])
 822                      {
 823                          if ($config['img_link_width'] || $config['img_link_height'])
 824                          {
 825                              list($width, $height) = @getimagesize($filename);
 826  
 827                              $display_cat = (!$width && !$height) ? ATTACHMENT_CATEGORY_IMAGE : (($width <= $config['img_link_width'] && $height <= $config['img_link_height']) ? ATTACHMENT_CATEGORY_IMAGE : ATTACHMENT_CATEGORY_NONE);
 828                          }
 829                      }
 830                      else
 831                      {
 832                          $display_cat = ATTACHMENT_CATEGORY_NONE;
 833                      }
 834                  }
 835              }
 836  
 837              $download_link = (!$force_physical && $attachment['attach_id']) ? append_sid("{$phpbb_root_path}download.$phpEx", 'id=' . $attachment['attach_id'] . '&amp;f=' . $forum_id) : $filename;
 838  
 839              $download_link_full = (!$force_physical && $attachment['attach_id']) ? generate_board_url() . append_sid("/download.$phpEx", 'id=' . $attachment['attach_id'] . '&amp;f=' . $forum_id) : generate_board_url() . $filename;
 840  
 841              switch ($display_cat)
 842              {
 843                  // Images
 844                  case ATTACHMENT_CATEGORY_IMAGE:
 845                      $l_downloaded_viewed = $user->lang['VIEWED'];
 846  
 847                      $block_array += array(
 848                          'S_IMAGE'        => true,
 849                      );
 850  
 851                      $update_count[] = $attachment['attach_id'];
 852                  break;
 853  
 854                  // Images, but display Thumbnail
 855                  case ATTACHMENT_CATEGORY_THUMB:
 856                      $l_downloaded_viewed = $user->lang['VIEWED'];
 857                      $thumbnail_link = (!$force_physical && $attachment['attach_id']) ? append_sid("{$phpbb_root_path}download.$phpEx", 'id=' . $attachment['attach_id'] . '&amp;t=1&amp;f=' . $forum_id) : $thumbnail_filename;
 858  
 859                      $block_array += array(
 860                          'S_THUMBNAIL'        => true,
 861                          'THUMB_IMAGE'        => $thumbnail_link,
 862                      );
 863                  break;
 864  
 865                  // Windows Media Streams
 866                  case ATTACHMENT_CATEGORY_WM:
 867                      $l_downloaded_viewed = $user->lang['VIEWED'];
 868  
 869                      // Giving the filename directly because within the wm object all variables are in local context making it impossible
 870                      // to validate against a valid session (all params can differ)
 871                      $download_link = $filename;
 872  
 873                      $block_array += array(
 874                          'U_FORUM'        => generate_board_url(),
 875                          'S_WM_FILE'        => true,
 876                      );
 877  
 878                      // Viewed/Heared File ... update the download count
 879                      $update_count[] = $attachment['attach_id'];
 880                  break;
 881  
 882                  // Real Media Streams
 883                  case ATTACHMENT_CATEGORY_RM:
 884                  case ATTACHMENT_CATEGORY_QUICKTIME:
 885                      $l_downloaded_viewed = $user->lang['VIEWED'];
 886  
 887                      $block_array += array(
 888                          'S_RM_FILE'            => ($display_cat == ATTACHMENT_CATEGORY_RM) ? true : false,
 889                          'S_QUICKTIME_FILE'    => ($display_cat == ATTACHMENT_CATEGORY_QUICKTIME) ? true : false,
 890                          'U_FORUM'            => generate_board_url(),
 891                          'ATTACH_ID'            => $attachment['attach_id'],
 892                      );
 893  
 894                      // Viewed/Heared File ... update the download count
 895                      $update_count[] = $attachment['attach_id'];
 896                  break;
 897  
 898                  // Macromedia Flash Files
 899                  case ATTACHMENT_CATEGORY_FLASH:
 900                      list($width, $height) = @getimagesize($filename);
 901  
 902                      $l_downloaded_viewed = $user->lang['VIEWED'];
 903  
 904                      $block_array += array(
 905                          'S_FLASH_FILE'    => true,
 906                          'WIDTH'            => $width,
 907                          'HEIGHT'        => $height,
 908                      );
 909  
 910                      // Viewed/Heared File ... update the download count
 911                      $update_count[] = $attachment['attach_id'];
 912                  break;
 913  
 914                  default:
 915                      $l_downloaded_viewed = $user->lang['DOWNLOADED'];
 916  
 917                      $block_array += array(
 918                          'S_FILE'        => true,
 919                      );
 920                  break;
 921              }
 922  
 923              $l_download_count = (!isset($attachment['download_count']) || $attachment['download_count'] == 0) ? $user->lang['DOWNLOAD_NONE'] : (($attachment['download_count'] == 1) ? sprintf($user->lang['DOWNLOAD_COUNT'], $attachment['download_count']) : sprintf($user->lang['DOWNLOAD_COUNTS'], $attachment['download_count']));
 924  
 925              $block_array += array(
 926                  'U_DOWNLOAD_LINK'        => $download_link,
 927                  'L_DOWNLOADED_VIEWED'    => $l_downloaded_viewed,
 928                  'L_DOWNLOAD_COUNT'        => $l_download_count
 929              );
 930          }
 931  
 932          $template->assign_block_vars('_file', $block_array);
 933  
 934          $tpl = $template->assign_display('attachment_tpl');
 935  
 936          if (!$return)
 937          {
 938              $template->assign_block_vars($blockname, array(
 939                  'DISPLAY_ATTACHMENT' => $tpl)
 940              );
 941          }
 942          else
 943          {
 944              $return_tpl[] = $tpl;
 945          }
 946      }
 947  
 948      return $return_tpl;
 949  }
 950  
 951  /**
 952  * Assign/Build custom bbcodes for display in screens supporting using of bbcodes
 953  * The custom bbcodes buttons will be placed within the template block 'custom_codes'
 954  */
 955  function display_custom_bbcodes()
 956  {
 957      global $db, $template;
 958  
 959      // Start counting from 22 for the bbcode ids (every bbcode takes two ids - opening/closing)
 960      $num_predefined_bbcodes = 22;
 961  
 962      /*
 963      * @todo while adjusting custom bbcodes, think about caching this query as well as correct ordering
 964      */
 965      $sql = 'SELECT bbcode_id, bbcode_tag, bbcode_helpline
 966          FROM ' . BBCODES_TABLE . '
 967          WHERE display_on_posting = 1';
 968      $result = $db->sql_query($sql);
 969  
 970      $i = 0;
 971      while ($row = $db->sql_fetchrow($result))
 972      {
 973          $template->assign_block_vars('custom_tags', array(
 974              'BBCODE_NAME'        => "'[{$row['bbcode_tag']}]', '[/" . str_replace('=', '', $row['bbcode_tag']) . "]'",
 975              'BBCODE_ID'            => $num_predefined_bbcodes + ($i * 2),
 976              'BBCODE_TAG'        => $row['bbcode_tag'],
 977              'BBCODE_HELPLINE'    => str_replace(array('&amp;', '&quot;', '&#039;', '&lt;', '&gt;'), array('\&', '\"', '\\\'', '<', '>'), $row['bbcode_helpline']))
 978          );
 979  
 980          $i++;
 981      }
 982      $db->sql_freeresult($result);
 983  }
 984  
 985  /**
 986  * Display reasons
 987  */
 988  function display_reasons($reason_id = 0)
 989  {
 990      global $db, $user, $template;
 991  
 992      $sql = 'SELECT * 
 993          FROM ' . REPORTS_REASONS_TABLE . ' 
 994          ORDER BY reason_order ASC';
 995      $result = $db->sql_query($sql);
 996  
 997      while ($row = $db->sql_fetchrow($result))
 998      {
 999          // If the reason is defined within the language file, we will use the localized version, else just use the database entry...
1000          if (isset($user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])]))
1001          {
1002              $row['reson_description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($row['reason_title'])];
1003              $row['reason_title'] = $user->lang['report_reasons']['TITLE'][strtoupper($row['reason_title'])];
1004          }
1005  
1006          $template->assign_block_vars('reason', array(
1007              'ID'            => $row['reason_id'],
1008              'TITLE'            => $row['reason_title'],
1009              'DESCRIPTION'    => $row['reason_description'],
1010              'S_SELECTED'    => ($row['reason_id'] == $reason_id) ? true : false)
1011          );
1012      }
1013      $db->sql_freeresult($result);
1014  }
1015  
1016  /**
1017  * Display user activity (action forum/topic)
1018  */
1019  function display_user_activity(&$userdata)
1020  {
1021      global $auth, $template, $db, $user;
1022      global $phpbb_root_path, $phpEx;
1023  
1024      // Do not display user activity for users having more than 5000 posts...
1025      if ($userdata['user_posts'] > 5000)
1026      {
1027          return;
1028      }
1029  
1030      $forum_ary = array();
1031  
1032      // Do not include those forums the user is not having read access to...
1033      $forum_read_ary = $auth->acl_getf('!f_read');
1034  
1035      foreach ($forum_read_ary as $forum_id => $not_allowed)
1036      {
1037          if ($not_allowed['f_read'])
1038          {
1039              $forum_ary[] = (int) $forum_id;
1040          }
1041      }
1042  
1043      $forum_ary = array_unique($forum_ary);
1044      $forum_sql = (sizeof($forum_ary)) ? 'AND ' . $db->sql_in_set('forum_id', $forum_ary, true) : '';
1045  
1046      // Obtain active forum
1047      $sql = 'SELECT forum_id, COUNT(post_id) AS num_posts
1048          FROM ' . POSTS_TABLE . '
1049          WHERE poster_id = ' . $userdata['user_id'] . "
1050              AND post_postcount = 1
1051              $forum_sql
1052          GROUP BY forum_id
1053          ORDER BY num_posts DESC";
1054      $result = $db->sql_query_limit($sql, 1, 0, 3600);
1055      $active_f_row = $db->sql_fetchrow($result);
1056      $db->sql_freeresult($result);
1057  
1058      if (!empty($active_f_row))
1059      {
1060          $sql = 'SELECT forum_name
1061              FROM ' . FORUMS_TABLE . '
1062              WHERE forum_id = ' . $active_f_row['forum_id'];
1063          $result = $db->sql_query($sql, 3600);
1064          $active_f_row['forum_name'] = (string) $db->sql_fetchfield('forum_name');
1065          $db->sql_freeresult($result);
1066      }
1067  
1068      // Obtain active topic
1069      $sql = 'SELECT topic_id, COUNT(post_id) AS num_posts
1070          FROM ' . POSTS_TABLE . '
1071          WHERE poster_id = ' . $userdata['user_id'] . "
1072              AND post_postcount = 1
1073              $forum_sql
1074          GROUP BY topic_id
1075          ORDER BY num_posts DESC";
1076      $result = $db->sql_query_limit($sql, 1, 0, 3600);
1077      $active_t_row = $db->sql_fetchrow($result);
1078      $db->sql_freeresult($result);
1079  
1080      if (!empty($active_t_row))
1081      {
1082          $sql = 'SELECT topic_title
1083              FROM ' . TOPICS_TABLE . '
1084              WHERE topic_id = ' . $active_t_row['topic_id'];
1085          $result = $db->sql_query($sql);
1086          $active_t_row['topic_title'] = (string) $db->sql_fetchfield('topic_title');
1087          $db->sql_freeresult($result);
1088      }
1089  
1090      $userdata['active_t_row'] = $active_t_row;
1091      $userdata['active_f_row'] = $active_f_row;
1092  
1093      $active_f_name = $active_f_id = $active_f_count = $active_f_pct = '';
1094      if (!empty($active_f_row['num_posts']))
1095      {
1096          $active_f_name = $active_f_row['forum_name'];
1097          $active_f_id = $active_f_row['forum_id'];
1098          $active_f_count = $active_f_row['num_posts'];
1099          $active_f_pct = ($userdata['user_posts']) ? ($active_f_count / $userdata['user_posts']) * 100 : 0;
1100      }
1101  
1102      $active_t_name = $active_t_id = $active_t_count = $active_t_pct = '';
1103      if (!empty($active_t_row['num_posts']))
1104      {
1105          $active_t_name = $active_t_row['topic_title'];
1106          $active_t_id = $active_t_row['topic_id'];
1107          $active_t_count = $active_t_row['num_posts'];
1108          $active_t_pct = ($userdata['user_posts']) ? ($active_t_count / $userdata['user_posts']) * 100 : 0;
1109      }
1110  
1111      $template->assign_vars(array(
1112          'ACTIVE_FORUM'            => $active_f_name,
1113          'ACTIVE_FORUM_POSTS'    => ($active_f_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_f_count),
1114          'ACTIVE_FORUM_PCT'        => sprintf($user->lang['POST_PCT_ACTIVE'], $active_f_pct),
1115          'ACTIVE_TOPIC'            => censor_text($active_t_name),
1116          'ACTIVE_TOPIC_POSTS'    => ($active_t_count == 1) ? sprintf($user->lang['USER_POST'], 1) : sprintf($user->lang['USER_POSTS'], $active_t_count),
1117          'ACTIVE_TOPIC_PCT'        => sprintf($user->lang['POST_PCT_ACTIVE'], $active_t_pct),
1118          'U_ACTIVE_FORUM'        => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),
1119          'U_ACTIVE_TOPIC'        => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id),
1120          'S_SHOW_ACTIVITY'        => true)
1121      );
1122  }
1123  
1124  /**
1125  * Topic and forum watching common code
1126  */
1127  function watch_topic_forum($mode, &$s_watching, &$s_watching_img, $user_id, $forum_id, $topic_id, $notify_status = 'unset', $start = 0)
1128  {
1129      global $template, $db, $user, $phpEx, $start, $phpbb_root_path;
1130  
1131      $table_sql = ($mode == 'forum') ? FORUMS_WATCH_TABLE : TOPICS_WATCH_TABLE;
1132      $where_sql = ($mode == 'forum') ? 'forum_id' : 'topic_id';
1133      $match_id = ($mode == 'forum') ? $forum_id : $topic_id;
1134  
1135      $u_url = ($mode == 'forum') ? 'f' : 'f=' . $forum_id . '&amp;t';
1136  
1137      // Is user watching this thread?
1138      if ($user_id != ANONYMOUS)
1139      {
1140          $can_watch = true;
1141  
1142          if ($notify_status == 'unset')
1143          {
1144              $sql = "SELECT notify_status
1145                  FROM $table_sql
1146                  WHERE $where_sql = $match_id
1147                      AND user_id = $user_id";
1148              $result = $db->sql_query($sql);
1149  
1150              $notify_status = ($row = $db->sql_fetchrow($result)) ? $row['notify_status'] : NULL;
1151              $db->sql_freeresult($result);
1152          }
1153  
1154          if (!is_null($notify_status))
1155          {
1156              if (isset($_GET['unwatch']))
1157              {
1158                  if ($_GET['unwatch'] == $mode)
1159                  {
1160                      $is_watching = 0;
1161  
1162                      $sql = 'DELETE FROM ' . $table_sql . "
1163                          WHERE $where_sql = $match_id
1164                              AND user_id = $user_id";
1165                      $db->sql_query($sql);
1166                  }
1167  
1168                  $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
1169  
1170                  meta_refresh(3, $redirect_url);
1171  
1172                  $message = $user->lang['NOT_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1173                  trigger_error($message);
1174              }
1175              else
1176              {
1177                  $is_watching = true;
1178  
1179                  if ($notify_status)
1180                  {
1181                      $sql = 'UPDATE ' . $table_sql . "
1182                          SET notify_status = 0
1183                          WHERE $where_sql = $match_id
1184                              AND user_id = $user_id";
1185                      $db->sql_query($sql);
1186                  }
1187              }
1188          }
1189          else
1190          {
1191              if (isset($_GET['watch']))
1192              {
1193                  if ($_GET['watch'] == $mode)
1194                  {
1195                      $is_watching = true;
1196  
1197                      $sql = 'INSERT INTO ' . $table_sql . " (user_id, $where_sql, notify_status)
1198                          VALUES ($user_id, $match_id, 0)";
1199                      $db->sql_query($sql);
1200                  }
1201  
1202                  $redirect_url = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;start=$start");
1203                  meta_refresh(3, $redirect_url);
1204  
1205                  $message = $user->lang['ARE_WATCHING_' . strtoupper($mode)] . '<br /><br />' . sprintf($user->lang['RETURN_' . strtoupper($mode)], '<a href="' . $redirect_url . '">', '</a>');
1206                  trigger_error($message);
1207              }
1208              else
1209              {
1210                  $is_watching = 0;
1211              }
1212          }
1213      }
1214      else
1215      {
1216          if (isset($_GET['unwatch']) && $_GET['unwatch'] == $mode)
1217          {
1218              login_box();
1219          }
1220          else
1221          {
1222              $can_watch = 0;
1223              $is_watching = 0;
1224          }
1225      }
1226  
1227      if ($can_watch)
1228      {
1229          $s_watching['link'] = append_sid("{$phpbb_root_path}view$mode.$phpEx", "$u_url=$match_id&amp;" . (($is_watching) ? 'unwatch' : 'watch') . "=$mode&amp;start=$start");
1230          $s_watching['title'] = $user->lang[(($is_watching) ? 'STOP' : 'START') . '_WATCHING_' . strtoupper($mode)];
1231      }
1232  
1233      return;
1234  }
1235  
1236  ?>


Generated: Wed Nov 22 00:35:05 2006 Cross-referenced by PHPXref 0.6