[ Index ]

PHP Cross Reference of MyBB 1.8.37

title

Body

[close]

/ -> printthread.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.8
   4   * Copyright 2014 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://www.mybb.com
   7   * License: http://www.mybb.com/about/license
   8   *
   9   */
  10  
  11  define("IN_MYBB", 1);
  12  define('THIS_SCRIPT', 'printthread.php');
  13  
  14  $templatelist = "printthread,printthread_post,printthread_nav,forumdisplay_password_wrongpass,forumdisplay_password,printthread_multipage,printthread_multipage_page,printthread_multipage_page_current";
  15  
  16  require_once  "./global.php";
  17  require_once  MYBB_ROOT."inc/functions_post.php";
  18  require_once  MYBB_ROOT."inc/class_parser.php";
  19  $parser = new postParser;
  20  
  21  // Load global language phrases
  22  $lang->load("printthread");
  23  
  24  $plugins->run_hooks("printthread_start");
  25  
  26  $thread = get_thread($mybb->get_input('tid', MyBB::INPUT_INT));
  27  
  28  if(!$thread || $thread['visible'] == -1)
  29  {
  30      error($lang->error_invalidthread);
  31  }
  32  
  33  $plugins->run_hooks("printthread_start");
  34  
  35  $thread['threadprefix'] = $thread['displaystyle'] = '';
  36  if($thread['prefix'])
  37  {
  38      $threadprefix = build_prefixes($thread['prefix']);
  39      if(!empty($threadprefix))
  40      {
  41          $thread['threadprefix'] = $threadprefix['prefix'];
  42          $thread['displaystyle'] = $threadprefix['displaystyle'];
  43      }
  44  }
  45  
  46  $thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
  47  
  48  $fid = $thread['fid'];
  49  $tid = $thread['tid'];
  50  
  51  // Is the currently logged in user a moderator of this forum?
  52  $ismod = is_moderator($fid);
  53  
  54  // Make sure we are looking at a real thread here.
  55  if(($thread['visible'] != 1 && $ismod == false) || ($thread['visible'] > 1 && $ismod == true))
  56  {
  57      error($lang->error_invalidthread);
  58  }
  59  
  60  // Get forum info
  61  $forum = get_forum($fid);
  62  if(!$forum)
  63  {
  64      error($lang->error_invalidforum);
  65  }
  66  
  67  $breadcrumb = makeprintablenav();
  68  
  69  $parentsexp = explode(",", $forum['parentlist']);
  70  $numparents = count($parentsexp);
  71  $tdepth = "-";
  72  for($i = 0; $i < $numparents; ++$i)
  73  {
  74      $tdepth .= "-";
  75  }
  76  $forumpermissions = forum_permissions($forum['fid']);
  77  
  78  if($forum['type'] != "f")
  79  {
  80      error($lang->error_invalidforum);
  81  }
  82  if($forumpermissions['canview'] == 0 || $forumpermissions['canviewthreads'] == 0 || (isset($forumpermissions['canonlyviewownthreads']) && $forumpermissions['canonlyviewownthreads'] != 0 && $thread['uid'] != $mybb->user['uid']))
  83  {
  84      error_no_permission();
  85  }
  86  
  87  // Check if this forum is password protected and we have a valid password
  88  check_forum_password($forum['fid']);
  89  
  90  $page = $mybb->get_input('page', MyBB::INPUT_INT);
  91  
  92  // Paginate this thread
  93  if(!$mybb->settings['postsperpage'] || (int)$mybb->settings['postsperpage'] < 1)
  94  {
  95      $mybb->settings['postsperpage'] = 20;
  96  }
  97  $perpage = $mybb->settings['postsperpage'];
  98  $postcount = (int)$thread['replies']+1;
  99  $pages = ceil($postcount/$perpage);
 100  
 101  if($page > $pages)
 102  {
 103      $page = 1;
 104  }
 105  if($page > 0)
 106  {
 107      $start = ($page-1) * $perpage;
 108  }
 109  else
 110  {
 111      $start = 0;
 112      $page = 1;
 113  }
 114  
 115  if($postcount > $perpage)
 116  {
 117      $multipage = printthread_multipage($postcount, $perpage, $page, "printthread.php?tid={$tid}");
 118  }
 119  else
 120  {
 121      $multipage = '';
 122  }
 123  
 124  $thread['threadlink'] = get_thread_link($tid);
 125  
 126  $postrows = '';
 127  if(is_moderator($forum['fid'], "canviewunapprove"))
 128  {
 129      $visible = "AND (p.visible='0' OR p.visible='1')";
 130  }
 131  else
 132  {
 133      $visible = "AND p.visible='1'";
 134  }
 135  
 136  $postrow_cache = $attachcache = array();
 137  
 138  $query = $db->query("
 139      SELECT u.*, u.username AS userusername, p.*
 140      FROM ".TABLE_PREFIX."posts p
 141      LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
 142      WHERE p.tid='$tid' {$visible}
 143      ORDER BY p.dateline, p.pid
 144      LIMIT {$start}, {$perpage}
 145  ");
 146  
 147  while($postrow = $db->fetch_array($query))
 148  {
 149      $postrow_cache[$postrow['pid']] = $postrow;
 150  }
 151  
 152  $postrow_cache = array_filter($postrow_cache);
 153  
 154  $pids = implode("','", array_keys($postrow_cache));
 155  
 156  // Get the attachments for all posst.
 157  if($mybb->settings['enableattachments'])
 158  {
 159      $queryAttachments = $db->simple_select("attachments", "*", "pid IN ('{$pids}')");
 160  
 161      while($attachment = $db->fetch_array($queryAttachments))
 162      {
 163          $attachcache[$attachment['pid']][$attachment['aid']] = $attachment;
 164      }
 165  }
 166  
 167  foreach($postrow_cache as $postrow)
 168  {
 169      $parser_options = array(
 170          "allow_html" => $forum['allowhtml'],
 171          "allow_mycode" => $forum['allowmycode'],
 172          "allow_smilies" => $forum['allowsmilies'],
 173          "allow_imgcode" => $forum['allowimgcode'],
 174          "allow_videocode" => $forum['allowvideocode'],
 175          "me_username" => $postrow['username'],
 176          "shorten_urls" => 0,
 177          "filter_badwords" => 1
 178      );
 179      if($postrow['smilieoff'] == 1)
 180      {
 181          $parser_options['allow_smilies'] = 0;
 182      }
 183  
 184      if($mybb->user['uid'] != 0 && $mybb->user['showimages'] != 1 || $mybb->settings['guestimages'] != 1 && $mybb->user['uid'] == 0)
 185      {
 186          $parser_options['allow_imgcode'] = 0;
 187      }
 188  
 189      if($mybb->user['uid'] != 0 && $mybb->user['showvideos'] != 1 || $mybb->settings['guestvideos'] != 1 && $mybb->user['uid'] == 0)
 190      {
 191          $parser_options['allow_videocode'] = 0;
 192      }
 193  
 194      if($postrow['userusername'])
 195      {
 196          $postrow['username'] = $postrow['userusername'];
 197      }
 198      $postrow['username'] = htmlspecialchars_uni($postrow['username']);
 199      $postrow['subject'] = htmlspecialchars_uni($parser->parse_badwords($postrow['subject']));
 200      $postrow['date'] = my_date($mybb->settings['dateformat'], $postrow['dateline'], null, 0);
 201      $postrow['profilelink'] = build_profile_link($postrow['username'], $postrow['uid']);
 202  
 203      $postrow['message'] = $parser->parse_message($postrow['message'], $parser_options);
 204  
 205      if($mybb->settings['enableattachments'] == 1 && !empty($attachcache[$postrow['pid']]) && $thread['attachmentcount'] > 0 || is_moderator($fid, 'caneditposts'))
 206      {
 207          get_post_attachments($postrow['pid'], $postrow);
 208      }
 209  
 210      $plugins->run_hooks("printthread_post");
 211      eval("\$postrows .= \"".$templates->get("printthread_post")."\";");
 212  }
 213  
 214  $plugins->run_hooks("printthread_end");
 215  
 216  eval("\$printable = \"".$templates->get("printthread")."\";");
 217  output_page($printable);
 218  
 219  /**
 220   * @param int $pid
 221   * @param string $depth
 222   *
 223   * @return string
 224   */
 225  function makeprintablenav($pid=0, $depth="--")
 226  {
 227      global $mybb, $db, $pforumcache, $fid, $forum, $lang, $templates;
 228      if(!is_array($pforumcache))
 229      {
 230          $parlist = build_parent_list($fid, "fid", "OR", $forum['parentlist']);
 231          $query = $db->simple_select("forums", "name, fid, pid", "$parlist", array('order_by' => 'pid, disporder'));
 232          while($forumnav = $db->fetch_array($query))
 233          {
 234              $pforumcache[$forumnav['pid']][$forumnav['fid']] = $forumnav;
 235          }
 236          unset($forumnav);
 237      }
 238      $forums = '';
 239      if(is_array($pforumcache[$pid]))
 240      {
 241          foreach($pforumcache[$pid] as $key => $forumnav)
 242          {
 243              $forumnav['link'] = get_forum_link($forumnav['fid']);
 244              eval("\$forums .= \"".$templates->get("printthread_nav")."\";");
 245              if(!empty($pforumcache[$forumnav['fid']]))
 246              {
 247                  $newdepth = $depth."-";
 248                  $forums .= makeprintablenav($forumnav['fid'], $newdepth);
 249              }
 250          }
 251      }
 252      return $forums;
 253  }
 254  
 255  /**
 256   * Output multipage navigation.
 257   *
 258   * @param int $count The total number of items.
 259   * @param int $perpage The items per page.
 260   * @param int $current_page The current page.
 261   * @param string $url The URL base.
 262   *
 263   * @return string
 264  */
 265  function printthread_multipage($count, $perpage, $current_page, $url)
 266  {
 267      global $lang, $templates;
 268      $multipage = "";
 269      if($count > $perpage)
 270      {
 271          $pages = $count / $perpage;
 272          $pages = ceil($pages);
 273  
 274          $mppage = null;
 275          for($page = 1; $page <= $pages; ++$page)
 276          {
 277              if($page == $current_page)
 278              {
 279                  eval("\$mppage .= \"".$templates->get("printthread_multipage_page_current")."\";");
 280              }
 281              else
 282              {
 283                  eval("\$mppage .= \"".$templates->get("printthread_multipage_page")."\";");
 284              }
 285          }
 286  
 287          eval("\$multipage = \"".$templates->get("printthread_multipage")."\";");
 288      }
 289      return $multipage;
 290  }
 291  


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref