[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/ -> printthread.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$
  10   */
  11  
  12  define("IN_MYBB", 1);
  13  define('THIS_SCRIPT', 'printthread.php');
  14  
  15  $templatelist = "printthread,printthread_post,forumdisplay_password_wrongpass,forumdisplay_password";
  16  
  17  require_once  "./global.php";
  18  require_once  MYBB_ROOT."inc/functions_post.php";
  19  require_once  MYBB_ROOT."inc/class_parser.php";
  20  $parser = new postParser;
  21  
  22  // Load global language phrases
  23  $lang->load("printthread");
  24  
  25  $plugins->run_hooks("printthread_start");
  26  
  27  $query = $db->query("
  28      SELECT t.*, p.prefix AS threadprefix, p.displaystyle
  29      FROM ".TABLE_PREFIX."threads t
  30      LEFT JOIN ".TABLE_PREFIX."threadprefixes p ON (p.pid=t.prefix)
  31      WHERE t.tid='".intval($mybb->input['tid'])."' AND t.closed NOT LIKE 'moved|%'
  32  ");
  33  $thread = $db->fetch_array($query);
  34  
  35  $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
  36  
  37  $fid = $thread['fid'];
  38  $tid = $thread['tid'];
  39  
  40  // Is the currently logged in user a moderator of this forum?
  41  if(is_moderator($fid))
  42  {
  43      $ismod = true;
  44  }
  45  else
  46  {
  47      $ismod = false;
  48  }
  49  
  50  // Make sure we are looking at a real thread here.
  51  if(!$tid || ($thread['visible'] != 1 && $ismod == false) || ($thread['visible'] > 1 && $ismod == true))
  52  {
  53      error($lang->error_invalidthread);
  54  }
  55  
  56  // Get forum info
  57  $forum = get_forum($fid);
  58  if(!$forum)
  59  {
  60      error($lang->error_invalidforum);
  61  }
  62  
  63  $breadcrumb = makeprintablenav();
  64  
  65  $parentsexp = explode(",", $forum['parentlist']);
  66  $numparents = count($parentsexp);
  67  $tdepth = "-";
  68  for($i = 0; $i < $numparents; ++$i)
  69  {
  70      $tdepth .= "-";
  71  }
  72  $forumpermissions = forum_permissions($forum['fid']);
  73  
  74  if($forum['type'] != "f")
  75  {
  76      error($lang->error_invalidforum);
  77  }
  78  if($forumpermissions['canview'] == 0 || $forumpermissions['canviewthreads'] == 0 || ($forumpermissions['canonlyviewownthreads'] != 0 && $thread['uid'] != $mybb->user['uid']))
  79  {
  80      error_no_permission();
  81  }
  82  
  83  // Check if this forum is password protected and we have a valid password
  84  check_forum_password($forum['fid']);
  85  
  86  $page = intval($mybb->input['page']);
  87  
  88  // Paginate this thread
  89  $perpage = $mybb->settings['postsperpage'];
  90  $postcount = intval($thread['replies'])+1;
  91  $pages = ceil($postcount/$perpage);
  92  
  93  if($page > $pages)
  94  {
  95      $page = 1;
  96  }
  97  if($page > 0)
  98  {
  99      $start = ($page-1) * $perpage;
 100  }
 101  else
 102  {
 103      $start = 0;
 104      $page = 1;
 105  }
 106  
 107  if($postcount > $perpage)
 108  {
 109      $multipage = printthread_multipage($postcount, $perpage, $page, "printthread.php?tid={$tid}");
 110  }
 111  
 112  $thread['threadlink'] = get_thread_link($tid);
 113  
 114  $postrows = '';
 115  if(is_moderator($forum['fid']))
 116  {
 117      $visible = "AND (p.visible='0' OR p.visible='1')";
 118  }
 119  else
 120  {
 121      $visible = "AND p.visible='1'";
 122  }
 123  $query = $db->query("
 124      SELECT u.*, u.username AS userusername, p.*
 125      FROM ".TABLE_PREFIX."posts p
 126      LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
 127      WHERE p.tid='$tid' {$visible}
 128      ORDER BY p.dateline
 129      LIMIT {$start}, {$perpage}
 130  "); 
 131  while($postrow = $db->fetch_array($query))
 132  {
 133      if($postrow['userusername'])
 134      {
 135          $postrow['username'] = $postrow['userusername'];
 136      }
 137      $postrow['subject'] = htmlspecialchars_uni($parser->parse_badwords($postrow['subject']));
 138      $postrow['date'] = my_date($mybb->settings['dateformat'], $postrow['dateline']);
 139      $postrow['time'] = my_date($mybb->settings['timeformat'], $postrow['dateline']);
 140      $postrow['profilelink'] = build_profile_link($postrow['username'], $postrow['uid']);
 141      $parser_options = array(
 142          "allow_html" => $forum['allowhtml'],
 143          "allow_mycode" => $forum['allowmycode'],
 144          "allow_smilies" => $forum['allowsmilies'],
 145          "allow_imgcode" => $forum['allowimgcode'],
 146          "allow_videocode" => $forum['allowvideocode'],
 147          "me_username" => $postrow['username'],
 148          "shorten_urls" => 0,
 149          "filter_badwords" => 1
 150      );
 151      if($postrow['smilieoff'] == 1)
 152      {
 153          $parser_options['allow_smilies'] = 0;
 154      }
 155  
 156      $postrow['message'] = $parser->parse_message($postrow['message'], $parser_options);
 157      $plugins->run_hooks("printthread_post");
 158      eval("\$postrows .= \"".$templates->get("printthread_post")."\";");
 159  }
 160  
 161  $plugins->run_hooks("printthread_end");
 162  
 163  eval("\$printable = \"".$templates->get("printthread")."\";");
 164  output_page($printable);
 165  
 166  function makeprintablenav($pid="0", $depth="--")
 167  {
 168      global $db, $pforumcache, $fid, $forum, $lang;
 169      if(!is_array($pforumcache))
 170      {
 171          $parlist = build_parent_list($fid, "fid", "OR", $forum['parentlist']);
 172          $query = $db->simple_select("forums", "name, fid, pid", "$parlist", array('order_by' => 'pid, disporder'));
 173          while($forumnav = $db->fetch_array($query))
 174          {
 175              $pforumcache[$forumnav['pid']][$forumnav['fid']] = $forumnav;
 176          }
 177          unset($forumnav);
 178      }
 179      if(is_array($pforumcache[$pid]))
 180      {
 181          foreach($pforumcache[$pid] as $key => $forumnav)
 182          {
 183              $forums .= "+".$depth." $lang->forum {$forumnav['name']} (<i>".$mybb->settings['bburl']."/".get_forum_link($forumnav['fid'])."</i>)<br />\n";
 184              if($pforumcache[$forumnav['fid']])
 185              {
 186                  $newdepth = $depth."-";
 187                  $forums .= makeprintablenav($forumnav['fid'], $newdepth);
 188              }
 189          }
 190      }
 191      return $forums;
 192  }
 193  
 194  /**
 195   * Output multipage navigation.
 196   *
 197   * @param int The total number of items.
 198   * @param int The items per page.
 199   * @param int The current page.
 200   * @param string The URL base.
 201  */
 202  function printthread_multipage($count, $perpage, $page, $url)
 203  {
 204      global $lang;
 205      $multipage = "";
 206      if($count > $perpage)
 207      {
 208          $pages = $count / $perpage;
 209          $pages = ceil($pages);
 210  
 211          for($i = 1; $i <= $pages; ++$i)
 212          {
 213              if($i == $page)
 214              {
 215                  $mppage .= "<strong>$i</strong> ";
 216              }
 217              else
 218              {
 219                  $mppage .= "<a href=\"$url&amp;page=$i\">$i</a> ";
 220              }
 221          }
 222          $multipage = "<div class=\"multipage\">{$lang->pages} <strong>".$lang->archive_pages."</strong> $mppage</div>";
 223      }
 224      return $multipage;
 225  }
 226  
 227  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1