[ Index ]

PHP Cross Reference of MyBB 1.6.5

title

Body

[close]

/archive/ -> index.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id: index.php 5368 2011-02-17 10:37:01Z MattR $
  10   */
  11  
  12  define("IN_MYBB", 1);
  13  define("IN_ARCHIVE", 1);
  14  
  15  require_once  "./global.php";
  16  require_once  MYBB_ROOT."inc/functions_post.php";
  17  // Load global language phrases
  18  $lang->load("index");
  19  
  20  $plugins->run_hooks("archive_start");
  21  
  22  switch($action)
  23  {
  24      // Display an announcement.
  25      case "announcement":
  26          // Fetch the forum this thread is in
  27          if($announcement['fid'] != -1)
  28          {
  29              $forum = get_forum($announcement['fid']);
  30              if(!$forum['fid'] || $forum['password'] != '')
  31              {
  32                  archive_error($lang->error_invalidforum);
  33              }
  34  
  35              // Check if we have permission to view this thread
  36              $forumpermissions = forum_permissions($forum['fid']);
  37              if($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1)
  38              {
  39                  archive_error_no_permission();
  40              }
  41              
  42              check_forum_password_archive($forum['fid']);
  43          }
  44  
  45          $announcement['subject'] = htmlspecialchars_uni($parser->parse_badwords($announcement['subject']));
  46  
  47          $parser_options = array(
  48              "allow_html" => $announcement['allowhtml'],
  49              "allow_mycode" => $announcement['allowmycode'],
  50              "allow_smilies" => $announcement['allowsmilies'],
  51              "allow_imgcode" => $announcement['allowimgcode'],
  52              "allow_videocode" => $announcement['allowvideocode'],
  53              "me_username" => $announcement['username'],
  54              "filter_badwords" => 1
  55          );
  56  
  57          $announcement['message'] = $parser->parse_message($announcement['message'], $parser_options);
  58  
  59          $profile_link = build_profile_link($announcement['username'], $announcement['uid']);
  60  
  61          // Build the navigation
  62          add_breadcrumb($announcement['subject']);
  63          archive_header($announcement['subject'], $announcement['subject'], $mybb->settings['bburl']."/announcements.php?aid={$id}");
  64  
  65          // Format announcement contents.
  66          $announcement['startdate'] = my_date($mybb->settings['dateformat'].", ".$mybb->settings['timeformat'], $announcement['startdate']);
  67  
  68          $plugins->run_hooks("archive_announcement_start");
  69  
  70          echo "<div class=\"post\">\n<div class=\"header\">\n<h2>{$announcement['subject']} - {$profile_link}</h2>";
  71          echo "<div class=\"dateline\">{$announcement['startdate']}</div>\n</div>\n<div class=\"message\">{$announcement['message']}</div>\n</div>\n";
  72  
  73          $plugins->run_hooks("archive_announcement_end");
  74  
  75          archive_footer();
  76          break;
  77  
  78      // Display a thread.
  79      case "thread":
  80          $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
  81  
  82          // Fetch the forum this thread is in
  83          $forum = get_forum($thread['fid']);
  84          if(!$forum['fid'] || $forum['password'] != '')
  85          {
  86              archive_error($lang->error_invalidforum);
  87          }
  88  
  89          // Check if we have permission to view this thread
  90          $forumpermissions = forum_permissions($forum['fid']);
  91          if($forumpermissions['canview'] != 1 || $forumpermissions['canviewthreads'] != 1)
  92          {
  93              archive_error_no_permission();
  94          }
  95          
  96          if($thread['visible'] != 1)
  97          {
  98              if(is_moderator($forum['fid']))
  99              {
 100                  archive_error($lang->sprintf($lang->error_unapproved_thread, $mybb->settings['bburl']."/".get_thread_link($thread['tid'])));
 101              }
 102              else
 103              {
 104                  archive_error($lang->error_invalidthread);
 105              }
 106          }
 107          
 108          if($forumpermissions['canonlyviewownthreads'] == 1 && $thread['uid'] != $mybb->user['uid'])
 109          {
 110              archive_error_no_permission();
 111          }
 112          
 113          check_forum_password_archive($forum['fid']);
 114          
 115          // Build the navigation
 116          build_forum_breadcrumb($forum['fid'], 1);
 117          add_breadcrumb($thread['subject']);
 118  
 119          archive_header($thread['subject'], $thread['subject'], $mybb->settings['bburl']."/".get_thread_link($thread['tid']));
 120  
 121          $plugins->run_hooks("archive_thread_start");
 122  
 123          // Paginate this thread
 124          $perpage = $mybb->settings['postsperpage'];
 125          $postcount = intval($thread['replies'])+1;
 126          $pages = ceil($postcount/$perpage);
 127  
 128          if($page > $pages)
 129          {
 130              $page = 1;
 131          }
 132          if($page)
 133          {
 134              $start = ($page-1) * $perpage;
 135          }
 136          else
 137          {
 138              $start = 0;
 139              $page = 1;
 140          }
 141  
 142          $pids = array();
 143          // Fetch list of post IDs to be shown
 144          $query = $db->simple_select("posts", "pid", "tid='{$id}' AND visible='1'", array('order_by' => 'dateline', 'limit_start' => $start, 'limit' => $perpage));
 145          while($post = $db->fetch_array($query))
 146          {
 147              $pids[$post['pid']] = $post['pid'];
 148          }
 149          
 150          if(empty($pids))
 151          {
 152              archive_error($lang->error_invalidthread);
 153          }
 154          
 155          archive_multipage($postcount, $perpage, $page, "{$base_url}thread-$id");
 156  
 157          $pids = implode(",", $pids);
 158  
 159          if($pids)
 160          {
 161              // Build attachments cache
 162              $query = $db->simple_select("attachments", "*", "pid IN ({$pids})");
 163              while($attachment = $db->fetch_array($query))
 164              {
 165                  $acache[$attachment['pid']][$attachment['aid']] = $attachment;
 166              }
 167          }
 168  
 169          // Start fetching the posts
 170          $query = $db->query("
 171              SELECT u.*, u.username AS userusername, p.*
 172              FROM ".TABLE_PREFIX."posts p
 173              LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
 174              WHERE p.pid IN ({$pids})
 175              ORDER BY p.dateline
 176          ");
 177          while($post = $db->fetch_array($query))
 178          {
 179              $post['date'] = my_date($mybb->settings['dateformat'].", ".$mybb->settings['timeformat'], $post['dateline'], "", 0);
 180              if($post['userusername'])
 181              {
 182                  $post['username'] = $post['userusername'];
 183              }
 184  
 185              // Parse the message
 186              $parser_options = array(
 187                  "allow_html" => $forum['allowhtml'],
 188                  "allow_mycode" => $forum['allowmycode'],
 189                  "allow_smilies" => $forum['allowsmilies'],
 190                  "allow_imgcode" => $forum['allowimgcode'],
 191                  "allow_videocode" => $forum['allowvideocode'],
 192                  "me_username" => $post['username'],
 193                  "filter_badwords" => 1
 194              );
 195              if($post['smilieoff'] == 1)
 196              {
 197                  $parser_options['allow_smilies'] = 0;
 198              }
 199  
 200              $post['message'] = $parser->parse_message($post['message'], $parser_options);
 201  
 202              // Is there an attachment in this post?
 203              if(is_array($acache[$post['pid']]))
 204              {
 205                  foreach($acache[$post['pid']] as $aid => $attachment)
 206                  {
 207                      $post['message'] = str_replace("[attachment={$attachment['aid']}]", "[<a href=\"".$mybb->settings['bburl']."/attachment.php?aid={$attachment['aid']}\">attachment={$attachment['aid']}</a>]", $post['message']);
 208                  }
 209              }
 210  
 211              // Damn thats a lot of parsing, now to determine which username to show..
 212              if($post['userusername'])
 213              {
 214                  $post['username'] = $post['userusername'];
 215              }
 216              $post['username'] = build_profile_link($post['username'], $post['uid']);
 217  
 218              $plugins->run_hooks("archive_thread_post");
 219  
 220              // Finally show the post
 221              echo "<div class=\"post\">\n<div class=\"header\">\n<div class=\"author\"><h2>{$post['username']}</h2></div>";
 222              echo "<div class=\"dateline\">{$post['date']}</div>\n</div>\n<div class=\"message\">{$post['message']}</div>\n</div>\n";
 223          }
 224          archive_multipage($postcount, $perpage, $page, "{$base_url}thread-$id");
 225  
 226          $plugins->run_hooks("archive_thread_end");
 227  
 228          archive_footer();
 229          break;
 230  
 231      // Display a category or a forum.
 232      case "forum":
 233          // Check if we have permission to view this forum
 234          $forumpermissions = forum_permissions($forum['fid']);
 235          if($forumpermissions['canview'] != 1)
 236          {
 237              archive_error_no_permission();
 238          }
 239          
 240          check_forum_password_archive($forum['fid']);
 241          
 242          $useronly = "";
 243          if($forumpermissions['canonlyviewownthreads'] == 1)
 244          {
 245              $useronly = "AND uid={$mybb->user['uid']}";
 246          }
 247  
 248          // Paginate this forum
 249          $query = $db->simple_select("threads", "COUNT(tid) AS threads", "fid='{$id}' AND visible='1' {$useronly}");
 250          $threadcount = $db->fetch_field($query, "threads");
 251  
 252          // Build the navigation
 253          build_forum_breadcrumb($forum['fid'], 1);
 254  
 255          // No threads and not a category? Error!
 256          if($threadcount < 1 && $forum['type'] != 'c')
 257          {
 258              archive_header(strip_tags($forum['name']), $forum['name'], $mybb->settings['bburl']."/".get_forum_link($id)."");
 259              archive_error($lang->error_nothreads);
 260          }
 261  
 262          // Build the archive header.
 263          archive_header(strip_tags($forum['name']), $forum['name'], $mybb->settings['bburl']."/".get_forum_link($id.""), 1);
 264  
 265          $plugins->run_hooks("archive_forum_start");
 266  
 267          if(!$mybb->settings['threadsperpage'])
 268          {
 269              $mybb->settings['threadsperpage'] = 20;
 270          }
 271  
 272          $perpage = $mybb->settings['threadsperpage'];
 273          $pages = ceil($threadcount/$perpage);
 274          if($page > $pages)
 275          {
 276              $page = 1;
 277          }
 278          
 279          if($page > 0)
 280          {
 281              $start = ($page-1) * $perpage;
 282          }
 283          else
 284          {
 285              $start = 0;
 286              $page = 1;
 287          }
 288  
 289          // Decide what type of listing to show.
 290          if($forum['type'] == 'f')
 291          {
 292              echo "<div class=\"listing\">\n<div class=\"header\"><h2>{$forum['name']}</h2></div>\n";
 293          }
 294          elseif($forum['type'] == 'c')
 295          {
 296              echo "<div class=\"listing\">\n<div class=\"header\"><h2>{$forum['name']}</h2></div>\n";
 297          }
 298  
 299          // Show subforums.
 300          $query = $db->simple_select("forums", "COUNT(fid) AS subforums", "pid='{$id}' AND status='1'");
 301          $subforumcount = $db->fetch_field($query, "subforums");
 302          if($subforumcount > 0)
 303          {
 304              echo "<div class=\"forumlist\">\n";
 305              echo "<h3>{$lang->subforums}</h3>\n";
 306              echo "<ol>\n";
 307              $forums = build_archive_forumbits($forum['fid']);
 308              echo $forums;
 309              echo "</ol>\n</div>\n";
 310          }
 311          
 312          archive_multipage($threadcount, $perpage, $page, "{$base_url}forum-$id");
 313      
 314          // Get the announcements if the forum is not a category.
 315          if($forum['type'] == 'f')
 316          {
 317              $sql = build_parent_list($forum['fid'], "fid", "OR", $forum['parentlist']);
 318              $time = TIME_NOW;
 319              $query = $db->simple_select("announcements", "*", "startdate < '{$time}' AND (enddate > '{$time}' OR enddate=0) AND ({$sql} OR fid='-1')");
 320              if($db->num_rows($query) > 0)
 321              {
 322                  echo "<div class=\"announcementlist\">\n";
 323                  echo "<h3>{$lang->forumbit_announcements}</h3>";
 324                  echo "<ol>\n";
 325                  while($announcement = $db->fetch_array($query))
 326                  {
 327                      echo "<li><a href=\"{$base_url}announcement-{$announcement['aid']}.html\">".htmlspecialchars_uni($announcement['subject'])."</a></li>";
 328                  }
 329                  echo "</ol>\n</div>\n";
 330              }
 331  
 332          }
 333  
 334          // Get the stickies if the forum is not a category.
 335          if($forum['type'] == 'f')
 336          {
 337              $options = array(
 338                  'order_by' => 'sticky, lastpost',
 339                  'order_dir' => 'desc',
 340                  'limit_start' => $start,
 341                  'limit' => $perpage
 342              );
 343              $query = $db->simple_select("threads", "*", "fid='{$id}' AND visible='1' AND sticky='1' AND closed NOT LIKE 'moved|%' {$useronly}", $options);
 344              if($db->num_rows($query) > 0)
 345              {
 346                  echo "<div class=\"threadlist\">\n";
 347                  echo "<h3>{$lang->forumbit_stickies}</h3>";
 348                  echo "<ol>\n";
 349                  while($sticky = $db->fetch_array($query))
 350                  {
 351                      $sticky['subject'] = htmlspecialchars_uni($parser->parse_badwords($sticky['subject']));
 352                      if($sticky['replies'] != 1)
 353                      {
 354                          $lang_reply_text = $lang->archive_replies;
 355                      }
 356                      else
 357                      {
 358                          $lang_reply_text = $lang->archive_reply;
 359                      }
 360  
 361                      $plugins->run_hooks("archive_forum_thread");
 362  
 363                      echo "<li><a href=\"{$base_url}thread-{$sticky['tid']}.html\">{$sticky['subject']}</a>";
 364                      echo "<span class=\"replycount\"> ({$sticky['replies']} {$lang_reply_text})</span></li>";
 365                  }
 366                  echo "</ol>\n</div>\n";
 367              }
 368          }
 369  
 370          // Get the threads if the forum is not a category.
 371          if($forum['type'] == 'f')
 372          {
 373              $options = array(
 374                  'order_by' => 'sticky, lastpost',
 375                  'order_dir' => 'desc',
 376                  'limit_start' => $start,
 377                  'limit' => $perpage
 378              );
 379              $query = $db->simple_select("threads", "*", "fid='{$id}' AND visible='1' AND sticky='0' AND closed NOT LIKE 'moved|%' {$useronly}", $options);
 380              if($db->num_rows($query) > 0)
 381              {
 382                  echo "<div class=\"threadlist\">\n";
 383                  echo "<h3>{$lang->forumbit_threads}</h3>";
 384                  echo "<ol>\n";
 385                  while($thread = $db->fetch_array($query))
 386                  {
 387                      $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
 388                      if($thread['replies'] != 1)
 389                      {
 390                          $lang_reply_text = $lang->archive_replies;
 391                      }
 392                      else
 393                      {
 394                          $lang_reply_text = $lang->archive_reply;
 395                      }
 396  
 397                      $plugins->run_hooks("archive_forum_thread");
 398  
 399                      echo "<li><a href=\"{$base_url}thread-{$thread['tid']}.html\">{$thread['subject']}</a>";
 400                      echo "<span class=\"replycount\"> ({$thread['replies']} {$lang_reply_text})</span></li>";
 401                  }
 402                  echo "</ol>\n</div>\n";
 403              }
 404          }
 405  
 406          echo "</div>\n";
 407  
 408          archive_multipage($threadcount, $perpage, $page, "{$base_url}forum-$id");
 409  
 410          $plugins->run_hooks("archive_forum_end");
 411  
 412          archive_footer();
 413          break;
 414  
 415      // Display the board home.
 416      case "index":
 417          // Build our forum listing
 418          $forums = build_archive_forumbits(0);
 419          archive_header("", $mybb->settings['bbname_orig'], $mybb->settings['bburl']."/index.php");
 420  
 421          $plugins->run_hooks("archive_index_start");
 422  
 423          echo "<div class=\"listing forumlist\">\n<div class=\"header\">{$mybb->settings['bbname']}</div>\n<div class=\"forums\">\n<ul>\n";
 424          echo $forums;
 425          echo "\n</ul>\n</div>\n</div>";
 426  
 427          $plugins->run_hooks("archive_index_end");
 428  
 429          archive_footer();
 430          break;
 431      default:
 432          header("HTTP/1.0 404 Not Found");
 433          switch($action2)
 434          {
 435              case "announcement":
 436                  archive_error($lang->error_invalidannouncement);
 437              case "thread":
 438                  archive_error($lang->error_invalidthread);
 439              case "forum":
 440                  archive_error($lang->error_invalidforum);
 441              default:
 442                  archive_error($lang->archive_not_found);
 443          }
 444  }
 445  
 446  $plugins->run_hooks("archive_end");
 447  
 448  /**
 449  * Gets a list of forums and possibly subforums.
 450  *
 451  * @param int The parent forum to get the childforums for.
 452  * @return array Array of information regarding the child forums of this parent forum
 453  */
 454  function build_archive_forumbits($pid=0)
 455  {
 456      global $db, $forumpermissions, $mybb, $lang, $archiveurl, $base_url;
 457  
 458      // Sort out the forum cache first.
 459      static $fcache;
 460      if(!is_array($fcache))
 461      {
 462          // Fetch forums
 463          $query = $db->simple_select("forums", "*", "active!=0 AND password=''", array('order_by' =>'pid, disporder'));
 464          while($forum = $db->fetch_array($query))
 465          {
 466              $fcache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;
 467          }
 468          $forumpermissions = forum_permissions();
 469      }
 470  
 471      // Start the process.
 472      if(is_array($fcache[$pid]))
 473      {
 474          foreach($fcache[$pid] as $key => $main)
 475          {
 476              foreach($main as $key => $forum)
 477              {
 478                  $perms = $forumpermissions[$forum['fid']];
 479                  if(($perms['canview'] == 1 || $mybb->settings['hideprivateforums'] == 0) && $forum['active'] != 0)
 480                  {
 481                      if($forum['linkto'])
 482                      {
 483                          $forums .= "<li><a href=\"{$forum['linkto']}\">{$forum['name']}</a>";
 484                      }
 485                      elseif($forum['type'] == "c")
 486                      {
 487                          $forums .= "<li><strong><a href=\"{$base_url}forum-{$forum['fid']}.html\">{$forum['name']}</a></strong>";
 488                      }
 489                      else
 490                      {
 491                          $forums .= "<li><a href=\"{$base_url}forum-{$forum['fid']}.html\">{$forum['name']}</a>";
 492                      }
 493                      if($fcache[$forum['fid']])
 494                      {
 495                          $forums .= "\n<ol>\n";
 496                          $forums .= build_archive_forumbits($forum['fid']);
 497                          $forums .= "</ol>\n";
 498                      }
 499                      $forums .= "</li>\n";
 500                  }
 501              }
 502          }
 503      }
 504      return $forums;
 505  }
 506  ?>


Generated: Sun Dec 11 14:16:27 2011 Cross-referenced by PHPXref 0.7.1