Advertisement
Guest User

Untitled

a guest
Mar 5th, 2016
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.59 KB | None | 0 0
  1. <?php
  2. error_reporting(0);
  3. $serveradress ='localhost';
  4. $serverusername = 'root';
  5. $serverpassword = 'ascent';
  6. $serverdatabase = 'warcry';
  7. if (!defined('init_pages'))
  8. {
  9. header('HTTP/1.0 404 not found');
  10. exit;
  11. }
  12.  
  13. $CORE->load_CoreModule('forums.parser');
  14. $CORE->load_CoreModule('pagination.forum');
  15.  
  16. //$CORE->loggedInOrReturn();
  17.  
  18. $topicId = isset($_GET['id']) ? (int)$_GET['id'] : false;
  19. $p = isset($_GET['p']) ? (int)$_GET['p'] : 1;
  20.  
  21. //Let's setup our pagination
  22. $pagies = new Pagination();
  23. $pagies->addToLink('?page='.$pageName.'&id='.$topicId);
  24.  
  25. $perPage = $config['FORUM']['Posts_Limit'];
  26.  
  27. //make sure we have the forum id
  28. if (!$topicId)
  29. {
  30. WCF::SetupNotification('Please make sure you have selected a valid topic.');
  31. header("Location: ".$config['BaseURL']."/forums.php");
  32. die;
  33. }
  34.  
  35. $res = $DB->prepare("SELECT * FROM `wcf_topics` WHERE `id` = :id LIMIT 1;");
  36. $res->bindParam(':id', $topicId, PDO::PARAM_INT);
  37. $res->execute();
  38.  
  39. if ($res->rowCount() == 0)
  40. {
  41. WCF::SetupNotification('The selected topic does not exist or was deleted.');
  42. header("Location: ".$config['BaseURL']."/forums.php");
  43. die;
  44. }
  45.  
  46. //save the last viewd topic
  47. WCF::setLastViewedTopic($topicId);
  48.  
  49. //Fetch the post record
  50. $row = $res->fetch();
  51.  
  52. //format the time
  53. $row['added'] = date('D M j, Y, h:i A', strtotime($row['added']));
  54.  
  55. //Set the title
  56. $TPL->SetTitle(WCF::parseTitle($row['name']));
  57. $TPL->SetParameter('topbar', true);
  58. //Add CSS to the loader
  59. $TPL->AddCss('template/style/select.css');
  60. //Print the header
  61. $TPL->LoadHeader();
  62.  
  63. if ($forumRow = WCF::getForumInfo($row['forum']))
  64. {
  65. if ($catName = WCF::getCategoryName($forumRow['category']))
  66. {
  67. $forumRow['category_name'] = $catName;
  68. }
  69. else
  70. {
  71. $forumRow['category_name'] = 'Unknown';
  72. }
  73. }
  74. else
  75. {
  76. $forumRow['id'] = 0;
  77. $forumRow['name'] = 'Unknown';
  78. $forumRow['category'] = 0;
  79. $forumRow['category_name'] = 'Unknown';
  80. }
  81.  
  82. //Staff memebers should be able to see deleted posts
  83. $IncludeDeleted = (($CURUSER->isOnline() && $CURUSER->getRank()->int() >= $config['FORUM']['Min_Rank_Post_View_Deleted']) ? true : false);
  84.  
  85. //count the total topics
  86. $count = WCF::getPostsCount($row['id'], $IncludeDeleted);
  87.  
  88. //Get the topics on this page
  89. if ($count > 0)
  90. {
  91. //calculate the pages
  92. $pages = $pagies->calculate_pages($count, $perPage, $p);
  93.  
  94. $posts_res = $DB->prepare("SELECT * FROM `wcf_posts` WHERE `topic` = :topic ".($IncludeDeleted ? '' : "AND `deleted_by` = '0'")." ORDER BY `id` ASC LIMIT ".$pages['limit'].";");
  95. $posts_res->bindParam(':topic', $row['id'], PDO::PARAM_INT);
  96. $posts_res->execute();
  97.  
  98. $countOnPage = $posts_res->rowCount();
  99. }
  100. else
  101. {
  102. $countOnPage = 0;
  103. }
  104.  
  105. ?>
  106.  
  107. <!--<a href="#" class="important_notice"><p>Please read and accept the rules and regulations before communicating with other members!</p></a>-->
  108.  
  109. <div class="page-header-navigation">
  110. <a href="<?php echo $config['BaseURL'], '/forums.php'; ?>">Board Index</a>
  111. <a href="<?php echo $config['BaseURL'], '/forums.php?category=', $forumRow['category']; ?>"><?php echo WCF::parseTitle($forumRow['category_name']); ?></a>
  112. <a href="<?php echo $config['BaseURL'], '/forums.php?page=forum&id=', $forumRow['id']; ?>"><?php echo WCF::parseTitle($forumRow['name']); ?></a>
  113. <a href="<?php echo $config['BaseURL'], '/forums.php?page=topic&id=', $row['id']; ?>"><?php echo WCF::parseTitle($row['name']); ?></a>
  114. </div>
  115.  
  116. <div class="container main-wide">
  117. <div class="forum-padding">
  118.  
  119. <!-- Forum Header -->
  120. <div class="topic_header">
  121. <div class="topic_title">
  122. <h1><?php echo WCF::parseTitle($row['name']); ?></h1>
  123. <h3><?php echo $row['added']; ?></h3>
  124. </div>
  125. <h4><b><?php echo $count; ?></b> posts</h4>
  126. </div>
  127. <!-- Forum Header.End -->
  128.  
  129. <?php
  130. if (($countOnPage > 2 && $count > $perPage) || $CURUSER->isOnline())
  131. {
  132. echo '
  133. <!-- Actions -->
  134. <div class="actions_c">';
  135.  
  136. if ($CURUSER->isOnline())
  137. {
  138. echo '<a href="', $config['BaseURL'], '/forums.php?page=post_reply" class="forum_btn_large">Post Reply</a>';
  139. }
  140.  
  141. if ($countOnPage > 2 && $count > $perPage)
  142. {
  143. echo '
  144. <ul class="pagination">
  145. ', $pages['previous'], '
  146. ', $pages['pages'], '
  147. ', $pages['next'], '
  148. </ul>';
  149. }
  150.  
  151. echo '
  152. </div>
  153. <!-- Actions.End -->';
  154. }
  155.  
  156. if ($countOnPage > 0)
  157. {
  158. //loop the records
  159. while ($arr = $posts_res->fetch())
  160. {
  161. if (($text = $CACHE->get('forums/posts/post_' . $arr['id'])) === false)
  162. {
  163. // create the BBCode parser
  164. $parser = new SBBCodeParser_Document(true, false);
  165. //Strip slashes
  166. $text = stripslashes($arr['text']);
  167. //Parse
  168. $text = $parser->parse($text)->detect_links()->detect_emails()->detect_emoticons()->get_html(true);
  169. //fix multiple break lines
  170. $text = preg_replace("/<br\s*\/?>\s<br\s*\/?>\s+/", "<br/>", $text);
  171.  
  172. unset($parser);
  173.  
  174. //Store the parsed post in the cache for a month
  175. $CACHE->store('forums/posts/post_' . $arr['id'], $text, "2592000");
  176. }
  177.  
  178. if ($userInfo = WCF::getAuthorInfo($arr['author']))
  179. {
  180. $userRank = new UserRank($userInfo['rank']);
  181. $arr['author_str'] = $userInfo['displayName'];
  182.  
  183. //prepare the avatar
  184. if ((int)$userInfo['avatarType'] == AVATAR_TYPE_GALLERY)
  185. {
  186. $gallery = new AvatarGallery();
  187. $Avatar = $gallery->get((int)$userInfo['avatar']);
  188. unset($gallery);
  189. }
  190. else if ((int)$userInfo['avatarType'] == AVATAR_TYPE_UPLOAD)
  191. {
  192. $Avatar = new Avatar(0, $userInfo['avatar'], 0, AVATAR_TYPE_UPLOAD);
  193. }
  194. }
  195. else
  196. {
  197. $userRank = new UserRank(0);
  198. $arr['author_str'] = 'Unknown';
  199. $arr['author_rank'] = 'Unknown';
  200. $gallery = new AvatarGallery();
  201. $Avatar = $gallery->get(0);
  202. unset($gallery);
  203. }
  204.  
  205. //format the time
  206. $arr['added'] = date('D M j, Y, h:i A', strtotime($arr['added']));
  207.  
  208. //Is staff post
  209. $staffPost = $CORE->hasFlag((int)$arr['flags'], WCF_FLAGS_STAFF_POST);
  210. //Is deleted
  211. $deletedPost = ((int)$arr['deleted_by'] > 0 ? true : false);
  212.  
  213. //Resolve the deletion author
  214. if ($deletedPost)
  215. {
  216. $userInfo = WCF::getAuthorInfo($arr['deleted_by']);
  217. $arr['deleted_by_str'] = $userInfo['displayName'];
  218. unset($userInfo);
  219. $arr['deleted_time'] = date('D M j, Y, h:i A', strtotime($arr['deleted_time']));
  220. }
  221.  
  222. echo '
  223. <!-- Topic Post -->
  224. <div class="topic_post', ($staffPost ? ' admin_post' : ''), ($deletedPost ? ' deleted_post' : ''), '" id="post-', $arr['id'], '">';
  225.  
  226. if ($staffPost)
  227. {
  228. echo '<!-- Admin example post -->
  229. <div class="admin_post_logo_wc"></div>';
  230. }
  231.  
  232. echo '
  233. <div class="left_side">
  234.  
  235. <div class="user_avatar">';
  236.  
  237. //handle avatars
  238. if ($Avatar->type() == AVATAR_TYPE_GALLERY)
  239. {
  240. echo '<span style="background:url(./resources/avatars/', $Avatar->string(), ') no-repeat; background-size: 100%;">';
  241. }
  242. else
  243. {
  244. echo '<span style="background:url(', $Avatar->string(), ') no-repeat; background-size: 100%;">';
  245. }
  246.  
  247. echo '
  248. </div>
  249.  
  250. <div class="user_info">
  251. <div class="usr_and_pr">
  252. <a href="', $config['BaseURL'], '/index.php?page=profile&uid=', $arr['author'], '" class="username">', $arr['author_str'], '</a>
  253.  
  254. <div class="drop_down_profile">
  255. <span class="profile">Profile</span>
  256. <a href="" class="arrow"></a>
  257. <div class="drop_down_container">
  258. <h1>', $arr['author_str'], '</h1>
  259. <h3>', $userRank->string(), '</h3>
  260. <ul class="user_menu">
  261. <li><a href="', $config['BaseURL'], '/index.php?page=profile&uid=', $arr['author'], '">Profile</a></li>
  262. <li><a href="#">View Posts</a></li>
  263. <li><a href="#">Ignore</a></li>
  264. </ul>
  265. </div>
  266. </div>
  267.  
  268. </div>
  269.  
  270. <h3>', $userRank->string(), '</h3>
  271. </div>
  272.  
  273. </div>
  274. <div class="right_side">
  275. <div class="post_container">
  276. ', ($deletedPost ? '<p style="color: red;">This post has been deleted by '.$arr['deleted_by_str'].' on '.$arr['deleted_time'].'.</p><br>' : ''), '
  277. ', $text, '
  278. </div>
  279. <ul class="post_controls">
  280. <li class="post_date">', $arr['added'], '</li>';
  281.  
  282. //Check if we can edit the post
  283. if ($CURUSER->isOnline() && !$deletedPost && ($CURUSER->get('id') == $arr['author'] || ($CURUSER->getRank()->int() >= $config['FORUM']['Min_Rank_Post_Edit'] && $CURUSER->getRank()->int() > $userRank->int())))
  284. echo '<li><a class="edit" href="', $config['BaseURL'], '/forums.php?page=edit_reply&id=', $arr['id'], '" title="Edit">Edit</a></li>';
  285.  
  286. //Check if we can delete the post
  287. if ($CURUSER->isOnline() && !$deletedPost && ($CURUSER->get('id') == $arr['author'] || ($CURUSER->getRank()->int() >= $config['FORUM']['Min_Rank_Post_Delete'] && $CURUSER->getRank()->int() > $userRank->int())));
  288. echo' <li><a class="delete post-delete-button" data-post-id="', $arr['id'], '" href="template/forums/pages/deleteok.php?id='.$arr['id'].'" title="Delete">Delete</a></li>';
  289.  
  290.  
  291. //Staff is not reportable
  292. if (!$staffPost)
  293. echo '<!--<li><a class="report" href="', $config['BaseURL'], '" title="Report">Report</a></li>-->';
  294.  
  295. echo '<!--<li><a class="warn" href="', $config['BaseURL'], '" title="Warn">Warn</a></li>-->';
  296.  
  297. //Can quote only if online and the post is not deleted
  298. if ($CURUSER->isOnline() && !$deletedPost)
  299. echo '<li><a class="quote post-quote-button" data-post-id="', $arr['id'], '" href="', $config['BaseURL'], '" title="Quote">Quote</a></li>';
  300.  
  301. echo '
  302. </ul>
  303. </div>
  304. <div class="clear"></div>
  305. </div>
  306. <!-- Topic Post.End -->';
  307. }
  308. unset($topics_res, $arr);
  309. }
  310.  
  311. //those should show only if we have more than once page
  312. if ($count > $perPage)
  313. {
  314. echo '
  315. <!-- Actions -->
  316. <div class="actions_c bottom">
  317. <div>
  318. <select name="action" styled="true">
  319. <option value="edit">Edit the Topic</option>
  320. </select>
  321. </div>
  322. <ul class="pagination">
  323. ', $pages['previous'], '
  324. ', $pages['pages'], '
  325. ', $pages['next'], '
  326. </ul>
  327. </div>
  328. <!-- Actions.End -->
  329. <br /><br /><br />';
  330. }
  331.  
  332. //Quick Reply if online
  333. if ($CURUSER->isOnline())
  334. {
  335.  
  336. $connect = mysql_connect("$serveradress", "$serverusername", "$serverpassword")
  337. OR die(mysql_error());
  338. mysql_select_db("$serverdatabase", $connect);
  339. //ALWAYS ESCAPE STRINGS IF YOU HAVE RECEIVED THEM FROM USERS
  340. //FIND AND GET THE ROW
  341. $q = mysql_query("SELECT * FROM wcf_topics WHERE id = $topicId") or die(mysql_error());
  342.  
  343. $result = mysql_fetch_array($q);
  344.  
  345. if ($result['lock'] != 0)
  346. {
  347. echo("[Topic Locked]");
  348. }
  349. else {
  350. echo'<div class="quick_reply topic_post">
  351. <form method="post" action="', $config['BaseURL'], '/execute.php?take=post_reply">
  352. <h2>Quick Reply</h2>
  353. <textarea id="quick_reply_textarea" name="text"></textarea>
  354. <input type="hidden" name="topic" value="', $topicId, '" />
  355. ', (($CURUSER->getRank()->int() >= RANK_STAFF_MEMBER) ? '<input type="hidden" value="1" name="staff_post" />' : ''), '
  356. <input type="submit" value="Post">
  357. <a href="', $config['BaseURL'], '/forums.php?page=post_reply" class="forum_btn_large advanced_post" id="go-advanced-post">Advanced post</a>
  358. </form>
  359. </div>';
  360. ;
  361. }}
  362. ?>
  363.  
  364. </div>
  365. </div>
  366.  
  367. <?php
  368.  
  369. $TPL->LoadFooter();
  370.  
  371. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement