[ Index ]

PHP Cross Reference of MyBB 1.8.12

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)
  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  $query = $db->query("
 136      SELECT u.*, u.username AS userusername, p.*
 137      FROM ".TABLE_PREFIX."posts p
 138      LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=p.uid)
 139      WHERE p.tid='$tid' {$visible}
 140      ORDER BY p.dateline
 141      LIMIT {$start}, {$perpage}
 142  ");
 143  while($postrow = $db->fetch_array($query))
 144  {
 145      $parser_options = array(
 146          "allow_html" => $forum['allowhtml'],
 147          "allow_mycode" => $forum['allowmycode'],
 148          "allow_smilies" => $forum['allowsmilies'],
 149          "allow_imgcode" => $forum['allowimgcode'],
 150          "allow_videocode" => $forum['allowvideocode'],
 151          "me_username" => $postrow['username'],
 152          "shorten_urls" => 0,
 153          "filter_badwords" => 1
 154      );
 155      if($postrow['smilieoff'] == 1)
 156      {
 157          $parser_options['allow_smilies'] = 0;
 158      }
 159  
 160      if($mybb->user['showimages'] != 1 && $mybb->user['uid'] != 0 || $mybb->settings['guestimages'] != 1 && $mybb->user['uid'] == 0)
 161      {
 162          $parser_options['allow_imgcode'] = 0;
 163      }
 164  
 165      if($mybb->user['showvideos'] != 1 && $mybb->user['uid'] != 0 || $mybb->settings['guestvideos'] != 1 && $mybb->user['uid'] == 0)
 166      {
 167          $parser_options['allow_videocode'] = 0;
 168      }
 169  
 170      if($postrow['userusername'])
 171      {
 172          $postrow['username'] = $postrow['userusername'];
 173      }
 174      $postrow['username'] = htmlspecialchars_uni($postrow['username']);
 175      $postrow['subject'] = htmlspecialchars_uni($parser->parse_badwords($postrow['subject']));
 176      $postrow['date'] = my_date($mybb->settings['dateformat'], $postrow['dateline'], null, 0);
 177      $postrow['profilelink'] = build_profile_link($postrow['username'], $postrow['uid']);
 178  
 179      $postrow['message'] = $parser->parse_message($postrow['message'], $parser_options);
 180      $plugins->run_hooks("printthread_post");
 181      eval("\$postrows .= \"".$templates->get("printthread_post")."\";");
 182  }
 183  
 184  $plugins->run_hooks("printthread_end");
 185  
 186  eval("\$printable = \"".$templates->get("printthread")."\";");
 187  output_page($printable);
 188  
 189  /**
 190   * @param int $pid
 191   * @param string $depth
 192   *
 193   * @return string
 194   */
 195  function makeprintablenav($pid=0, $depth="--")
 196  {
 197      global $mybb, $db, $pforumcache, $fid, $forum, $lang, $templates;
 198      if(!is_array($pforumcache))
 199      {
 200          $parlist = build_parent_list($fid, "fid", "OR", $forum['parentlist']);
 201          $query = $db->simple_select("forums", "name, fid, pid", "$parlist", array('order_by' => 'pid, disporder'));
 202          while($forumnav = $db->fetch_array($query))
 203          {
 204              $pforumcache[$forumnav['pid']][$forumnav['fid']] = $forumnav;
 205          }
 206          unset($forumnav);
 207      }
 208      $forums = '';
 209      if(is_array($pforumcache[$pid]))
 210      {
 211          foreach($pforumcache[$pid] as $key => $forumnav)
 212          {
 213              $forumnav['link'] = get_forum_link($forumnav['fid']);
 214              eval("\$forums .= \"".$templates->get("printthread_nav")."\";");
 215              if(!empty($pforumcache[$forumnav['fid']]))
 216              {
 217                  $newdepth = $depth."-";
 218                  $forums .= makeprintablenav($forumnav['fid'], $newdepth);
 219              }
 220          }
 221      }
 222      return $forums;
 223  }
 224  
 225  /**
 226   * Output multipage navigation.
 227   *
 228   * @param int $count The total number of items.
 229   * @param int $perpage The items per page.
 230   * @param int $current_page The current page.
 231   * @param string $url The URL base.
 232   *
 233   * @return string
 234  */
 235  function printthread_multipage($count, $perpage, $current_page, $url)
 236  {
 237      global $lang, $templates;
 238      $multipage = "";
 239      if($count > $perpage)
 240      {
 241          $pages = $count / $perpage;
 242          $pages = ceil($pages);
 243  
 244          $mppage = null;
 245          for($page = 1; $page <= $pages; ++$page)
 246          {
 247              if($page == $current_page)
 248              {
 249                  eval("\$mppage .= \"".$templates->get("printthread_multipage_page_current")."\";");
 250              }
 251              else
 252              {
 253                  eval("\$mppage .= \"".$templates->get("printthread_multipage_page")."\";");
 254              }
 255          }
 256  
 257          eval("\$multipage = \"".$templates->get("printthread_multipage")."\";");
 258      }
 259      return $multipage;
 260  }
 261  


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