PageRenderTime 24ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Upload/printthread.php

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