Advertisement
Guest User

functions_post.php v.0

a guest
Sep 13th, 2016
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.43 KB | None | 0 0
  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. /**
  12. * Build a post bit
  13. *
  14. * @param array $post The post data
  15. * @param int $post_type The type of post bit we're building (1 = preview, 2 = pm, 3 = announcement, 4 = reddit thread type post. else = linear post)
  16. * @return string The built post bit
  17. */
  18. function build_postbit($post, $post_type=0, $indentsize = 0)
  19. {
  20. global $db, $altbg, $theme, $mybb, $postcounter, $profile_fields;
  21. global $titlescache, $page, $templates, $forumpermissions, $attachcache;
  22. global $lang, $ismod, $inlinecookie, $inlinecount, $groupscache, $fid;
  23. global $plugins, $parser, $cache, $ignored_users, $hascustomtitle;
  24. // global $plugins, $parser, $cache, $ignored_users, $hascustomtitle, $indentsize;
  25.  
  26. $hascustomtitle = 0;
  27.  
  28. // Set default values for any fields not provided here
  29. foreach(array('pid', 'aid', 'pmid', 'posturl', 'button_multiquote', 'subject_extra', 'attachments', 'button_rep', 'button_warn', 'button_purgespammer', 'button_pm', 'button_reply_pm', 'button_replyall_pm', 'button_forward_pm', 'button_delete_pm', 'replink', 'warninglevel') as $post_field)
  30. {
  31. if(empty($post[$post_field]))
  32. {
  33. $post[$post_field] = '';
  34. }
  35. }
  36.  
  37. // Set up the message parser if it doesn't already exist.
  38. if(!$parser)
  39. {
  40. require_once MYBB_ROOT."inc/class_parser.php";
  41. $parser = new postParser;
  42. }
  43.  
  44. if(!function_exists("purgespammer_show"))
  45. {
  46. require_once MYBB_ROOT."inc/functions_user.php";
  47. }
  48.  
  49. $unapproved_shade = '';
  50. if(isset($post['visible']) && $post['visible'] == 0 && ($post_type == 0 || $post_type == 4))
  51. {
  52. $altbg = $unapproved_shade = 'unapproved_post';
  53. }
  54. elseif(isset($post['visible']) && $post['visible'] == -1 && ($post_type == 0 || $post_type == 4))
  55. {
  56. $altbg = $unapproved_shade = 'unapproved_post deleted_post';
  57. }
  58. elseif($altbg == 'trow1')
  59. {
  60. $altbg = 'trow2';
  61. }
  62. else
  63. {
  64. $altbg = 'trow1';
  65. }
  66. $post['fid'] = $fid;
  67. switch($post_type)
  68. {
  69. case 1: // Message preview
  70. global $forum;
  71. $parser_options['allow_html'] = $forum['allowhtml'];
  72. $parser_options['allow_mycode'] = $forum['allowmycode'];
  73. $parser_options['allow_smilies'] = $forum['allowsmilies'];
  74. $parser_options['allow_imgcode'] = $forum['allowimgcode'];
  75. $parser_options['allow_videocode'] = $forum['allowvideocode'];
  76. $parser_options['me_username'] = $post['username'];
  77. $parser_options['filter_badwords'] = 1;
  78. $id = 0;
  79. break;
  80. case 2: // Private message
  81. global $message, $pmid;
  82. $idtype = 'pmid';
  83. $parser_options['allow_html'] = $mybb->settings['pmsallowhtml'];
  84. $parser_options['allow_mycode'] = $mybb->settings['pmsallowmycode'];
  85. $parser_options['allow_smilies'] = $mybb->settings['pmsallowsmilies'];
  86. $parser_options['allow_imgcode'] = $mybb->settings['pmsallowimgcode'];
  87. $parser_options['allow_videocode'] = $mybb->settings['pmsallowvideocode'];
  88. $parser_options['me_username'] = $post['username'];
  89. $parser_options['filter_badwords'] = 1;
  90. $id = $pmid;
  91. break;
  92. case 3: // Announcement
  93. global $announcementarray, $message;
  94. $parser_options['allow_html'] = $announcementarray['allowhtml'];
  95. $parser_options['allow_mycode'] = $announcementarray['allowmycode'];
  96. $parser_options['allow_smilies'] = $announcementarray['allowsmilies'];
  97. $parser_options['allow_imgcode'] = 1;
  98. $parser_options['allow_videocode'] = 1;
  99. $parser_options['me_username'] = $post['username'];
  100. $parser_options['filter_badwords'] = 1;
  101. $id = $announcementarray['aid'];
  102. break;
  103. default: // Regular post
  104. global $forum, $thread, $tid;
  105. $oldforum = $forum;
  106. $id = (int)$post['pid'];
  107. $idtype = 'pid';
  108. $parser_options['allow_html'] = $forum['allowhtml'];
  109. $parser_options['allow_mycode'] = $forum['allowmycode'];
  110. $parser_options['allow_smilies'] = $forum['allowsmilies'];
  111. $parser_options['allow_imgcode'] = $forum['allowimgcode'];
  112. $parser_options['allow_videocode'] = $forum['allowvideocode'];
  113. $parser_options['filter_badwords'] = 1;
  114.  
  115. if(!$post['username'])
  116. {
  117. $post['username'] = $lang->guest;
  118. }
  119.  
  120. if($post['userusername'])
  121. {
  122. $parser_options['me_username'] = $post['userusername'];
  123. }
  124. else
  125. {
  126. $parser_options['me_username'] = $post['username'];
  127. }
  128. break;
  129. }
  130.  
  131. if(!$postcounter)
  132. { // Used to show the # of the post
  133. if($page > 1)
  134. {
  135. if(!$mybb->settings['postsperpage'] || (int)$mybb->settings['postsperpage'] < 1)
  136. {
  137. $mybb->settings['postsperpage'] = 20;
  138. }
  139.  
  140. $postcounter = $mybb->settings['postsperpage']*($page-1);
  141. }
  142. else
  143. {
  144. $postcounter = 0;
  145. }
  146. $post_extra_style = "border-top-width: 0;";
  147. }
  148. elseif($mybb->input['mode'] == "threaded")
  149. {
  150. $post_extra_style = "border-top-width: 0;";
  151. }
  152. else
  153. {
  154. $post_extra_style = "margin-top: 5px;";
  155. }
  156.  
  157. if(!$altbg)
  158. { // Define the alternate background colour if this is the first post
  159. $altbg = "trow1";
  160. }
  161. $postcounter++;
  162.  
  163. // Format the post date and time using my_date
  164. $post['postdate'] = my_date('relative', $post['dateline']);
  165.  
  166. // Dont want any little 'nasties' in the subject
  167. $post['subject'] = $parser->parse_badwords($post['subject']);
  168.  
  169. // Pm's have been htmlspecialchars_uni()'ed already.
  170. if($post_type != 2)
  171. {
  172. $post['subject'] = htmlspecialchars_uni($post['subject']);
  173. }
  174.  
  175. if(empty($post['subject']))
  176. {
  177. $post['subject'] = '&nbsp;';
  178. }
  179.  
  180. $post['author'] = $post['uid'];
  181. $post['subject_title'] = $post['subject'];
  182.  
  183. // Get the usergroup
  184. if($post['userusername'])
  185. {
  186. if(!$post['displaygroup'])
  187. {
  188. $post['displaygroup'] = $post['usergroup'];
  189. }
  190. $usergroup = $groupscache[$post['displaygroup']];
  191. }
  192. else
  193. {
  194. $usergroup = $groupscache[1];
  195. }
  196.  
  197. if(!is_array($titlescache))
  198. {
  199. $cached_titles = $cache->read("usertitles");
  200. if(!empty($cached_titles))
  201. {
  202. foreach($cached_titles as $usertitle)
  203. {
  204. $titlescache[$usertitle['posts']] = $usertitle;
  205. }
  206. }
  207.  
  208. if(is_array($titlescache))
  209. {
  210. krsort($titlescache);
  211. }
  212. unset($usertitle, $cached_titles);
  213. }
  214.  
  215. // Work out the usergroup/title stuff
  216. $post['groupimage'] = '';
  217. if(!empty($usergroup['image']))
  218. {
  219. $language = $mybb->settings['bblanguage'];
  220. if(!empty($mybb->user['language']))
  221. {
  222. $language = $mybb->user['language'];
  223. }
  224.  
  225. $usergroup['image'] = str_replace("{lang}", $language, $usergroup['image']);
  226. $usergroup['image'] = str_replace("{theme}", $theme['imgdir'], $usergroup['image']);
  227. eval("\$post['groupimage'] = \"".$templates->get("postbit_groupimage")."\";");
  228.  
  229. if($mybb->settings['postlayout'] == "classic")
  230. {
  231. $post['groupimage'] .= "<br />";
  232. }
  233. }
  234.  
  235. if($post['userusername'])
  236. {
  237. // This post was made by a registered user
  238. $post['username'] = $post['userusername'];
  239. $post['profilelink_plain'] = get_profile_link($post['uid']);
  240. $post['username_formatted'] = format_name($post['username'], $post['usergroup'], $post['displaygroup']);
  241. $post['profilelink'] = build_profile_link($post['username_formatted'], $post['uid']);
  242.  
  243. if(trim($post['usertitle']) != "")
  244. {
  245. $hascustomtitle = 1;
  246. }
  247.  
  248. if($usergroup['usertitle'] != "" && !$hascustomtitle)
  249. {
  250. $post['usertitle'] = $usergroup['usertitle'];
  251. }
  252. elseif(is_array($titlescache) && !$usergroup['usertitle'])
  253. {
  254. reset($titlescache);
  255. foreach($titlescache as $key => $titleinfo)
  256. {
  257. if($post['postnum'] >= $key)
  258. {
  259. if(!$hascustomtitle)
  260. {
  261. $post['usertitle'] = $titleinfo['title'];
  262. }
  263. $post['stars'] = $titleinfo['stars'];
  264. $post['starimage'] = $titleinfo['starimage'];
  265. break;
  266. }
  267. }
  268. }
  269.  
  270. $post['usertitle'] = htmlspecialchars_uni($post['usertitle']);
  271.  
  272. if($usergroup['stars'])
  273. {
  274. $post['stars'] = $usergroup['stars'];
  275. }
  276.  
  277. if(empty($post['starimage']))
  278. {
  279. $post['starimage'] = $usergroup['starimage'];
  280. }
  281.  
  282. if($post['starimage'] && $post['stars'])
  283. {
  284. // Only display stars if we have an image to use...
  285. $post['starimage'] = str_replace("{theme}", $theme['imgdir'], $post['starimage']);
  286.  
  287. $post['userstars'] = '';
  288. for($i = 0; $i < $post['stars']; ++$i)
  289. {
  290. eval("\$post['userstars'] .= \"".$templates->get("postbit_userstar", 1, 0)."\";");
  291. }
  292.  
  293. $post['userstars'] .= "<br />";
  294. }
  295.  
  296. $postnum = $post['postnum'];
  297. $post['postnum'] = my_number_format($post['postnum']);
  298. $post['threadnum'] = my_number_format($post['threadnum']);
  299.  
  300. // Determine the status to show for the user (Online/Offline/Away)
  301. $timecut = TIME_NOW - $mybb->settings['wolcutoff'];
  302. if($post['lastactive'] > $timecut && ($post['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1) && $post['lastvisit'] != $post['lastactive'])
  303. {
  304. eval("\$post['onlinestatus'] = \"".$templates->get("postbit_online")."\";");
  305. }
  306. else
  307. {
  308. if($post['away'] == 1 && $mybb->settings['allowaway'] != 0)
  309. {
  310. eval("\$post['onlinestatus'] = \"".$templates->get("postbit_away")."\";");
  311. }
  312. else
  313. {
  314. eval("\$post['onlinestatus'] = \"".$templates->get("postbit_offline")."\";");
  315. }
  316. }
  317.  
  318. $post['useravatar'] = '';
  319. if(isset($mybb->user['showavatars']) && $mybb->user['showavatars'] != 0 || $mybb->user['uid'] == 0)
  320. {
  321. $useravatar = format_avatar($post['avatar'], $post['avatardimensions'], $mybb->settings['postmaxavatarsize']);
  322. eval("\$post['useravatar'] = \"".$templates->get("postbit_avatar")."\";");
  323. }
  324.  
  325. $post['button_find'] = '';
  326. if($mybb->usergroup['cansearch'] == 1)
  327. {
  328. eval("\$post['button_find'] = \"".$templates->get("postbit_find")."\";");
  329. }
  330.  
  331. if($mybb->settings['enablepms'] == 1 && $post['receivepms'] != 0 && $mybb->usergroup['cansendpms'] == 1 && my_strpos(",".$post['ignorelist'].",", ",".$mybb->user['uid'].",") === false)
  332. {
  333. eval("\$post['button_pm'] = \"".$templates->get("postbit_pm")."\";");
  334. }
  335.  
  336. $post['button_rep'] = '';
  337. if($post_type != 3 && $mybb->settings['enablereputation'] == 1 && $mybb->settings['postrep'] == 1 && $mybb->usergroup['cangivereputations'] == 1 && $usergroup['usereputationsystem'] == 1 && ($mybb->settings['posrep'] || $mybb->settings['neurep'] || $mybb->settings['negrep']) && $post['uid'] != $mybb->user['uid'] && (!isset($post['visible']) || $post['visible'] == 1) && (!isset($thread['visible']) || $thread['visible'] == 1))
  338. {
  339. if(!$post['pid'])
  340. {
  341. $post['pid'] = 0;
  342. }
  343.  
  344. eval("\$post['button_rep'] = \"".$templates->get("postbit_rep_button")."\";");
  345. }
  346.  
  347. if($post['website'] != "" && !is_member($mybb->settings['hidewebsite']) && $usergroup['canchangewebsite'] == 1)
  348. {
  349. $post['website'] = htmlspecialchars_uni($post['website']);
  350. eval("\$post['button_www'] = \"".$templates->get("postbit_www")."\";");
  351. }
  352. else
  353. {
  354. $post['button_www'] = "";
  355. }
  356.  
  357. if($post['hideemail'] != 1 && $mybb->usergroup['cansendemail'] == 1)
  358. {
  359. eval("\$post['button_email'] = \"".$templates->get("postbit_email")."\";");
  360. }
  361. else
  362. {
  363. $post['button_email'] = "";
  364. }
  365.  
  366. $post['userregdate'] = my_date($mybb->settings['regdateformat'], $post['regdate']);
  367.  
  368. // Work out the reputation this user has (only show if not announcement)
  369. if($post_type != 3 && $usergroup['usereputationsystem'] != 0 && $mybb->settings['enablereputation'] == 1)
  370. {
  371. $post['userreputation'] = get_reputation($post['reputation'], $post['uid']);
  372. eval("\$post['replink'] = \"".$templates->get("postbit_reputation")."\";");
  373. }
  374.  
  375. // Showing the warning level? (only show if not announcement)
  376. if($post_type != 3 && $mybb->settings['enablewarningsystem'] != 0 && $usergroup['canreceivewarnings'] != 0 && ($mybb->usergroup['canwarnusers'] != 0 || ($mybb->user['uid'] == $post['uid'] && $mybb->settings['canviewownwarning'] != 0)))
  377. {
  378. if($mybb->settings['maxwarningpoints'] < 1)
  379. {
  380. $mybb->settings['maxwarningpoints'] = 10;
  381. }
  382.  
  383. $warning_level = round($post['warningpoints']/$mybb->settings['maxwarningpoints']*100);
  384. if($warning_level > 100)
  385. {
  386. $warning_level = 100;
  387. }
  388. $warning_level = get_colored_warning_level($warning_level);
  389.  
  390. // If we can warn them, it's not the same person, and we're in a PM or a post.
  391. if($mybb->usergroup['canwarnusers'] != 0 && $post['uid'] != $mybb->user['uid'] && ($post_type == 0 || $post_type == 2 || $post_type == 4))
  392. {
  393. eval("\$post['button_warn'] = \"".$templates->get("postbit_warn")."\";");
  394. $warning_link = "warnings.php?uid={$post['uid']}";
  395. }
  396. else
  397. {
  398. $post['button_warn'] = '';
  399. $warning_link = "usercp.php";
  400. }
  401. eval("\$post['warninglevel'] = \"".$templates->get("postbit_warninglevel")."\";");
  402. }
  403.  
  404. if($post_type != 3 && $post_type != 1 && purgespammer_show($post['postnum'], $post['usergroup'], $post['uid']))
  405. {
  406. eval("\$post['button_purgespammer'] = \"".$templates->get('postbit_purgespammer')."\";");
  407. }
  408.  
  409. // Display profile fields on posts - only if field is filled in
  410. if(is_array($profile_fields))
  411. {
  412. foreach($profile_fields as $field)
  413. {
  414. $fieldfid = "fid{$field['fid']}";
  415. if(!empty($post[$fieldfid]))
  416. {
  417. $post['fieldvalue'] = '';
  418. $post['fieldname'] = htmlspecialchars_uni($field['name']);
  419.  
  420. $thing = explode("\n", $field['type'], "2");
  421. $type = trim($thing[0]);
  422. $useropts = explode("\n", $post[$fieldfid]);
  423.  
  424. if(is_array($useropts) && ($type == "multiselect" || $type == "checkbox"))
  425. {
  426. foreach($useropts as $val)
  427. {
  428. if($val != '')
  429. {
  430. eval("\$post['fieldvalue_option'] .= \"".$templates->get("postbit_profilefield_multiselect_value")."\";");
  431. }
  432. }
  433. if($post['fieldvalue_option'] != '')
  434. {
  435. eval("\$post['fieldvalue'] .= \"".$templates->get("postbit_profilefield_multiselect")."\";");
  436. }
  437. }
  438. else
  439. {
  440. $field_parser_options = array(
  441. "allow_html" => $field['allowhtml'],
  442. "allow_mycode" => $field['allowmycode'],
  443. "allow_smilies" => $field['allowsmilies'],
  444. "allow_imgcode" => $field['allowimgcode'],
  445. "allow_videocode" => $field['allowvideocode'],
  446. #"nofollow_on" => 1,
  447. "filter_badwords" => 1
  448. );
  449.  
  450. if($customfield['type'] == "textarea")
  451. {
  452. $field_parser_options['me_username'] = $post['username'];
  453. }
  454. else
  455. {
  456. $field_parser_options['nl2br'] = 0;
  457. }
  458.  
  459. if($mybb->user['showimages'] != 1 && $mybb->user['uid'] != 0 || $mybb->settings['guestimages'] != 1 && $mybb->user['uid'] == 0)
  460. {
  461. $field_parser_options['allow_imgcode'] = 0;
  462. }
  463.  
  464. $post['fieldvalue'] = $parser->parse_message($post[$fieldfid], $field_parser_options);
  465. }
  466.  
  467. eval("\$post['profilefield'] .= \"".$templates->get("postbit_profilefield")."\";");
  468. }
  469. }
  470. }
  471.  
  472. eval("\$post['user_details'] = \"".$templates->get("postbit_author_user")."\";");
  473. }
  474. else
  475. { // Message was posted by a guest or an unknown user
  476. $post['profilelink'] = format_name($post['username'], 1);
  477.  
  478. if($usergroup['usertitle'])
  479. {
  480. $post['usertitle'] = $usergroup['usertitle'];
  481. }
  482. else
  483. {
  484. $post['usertitle'] = $lang->guest;
  485. }
  486.  
  487. $post['usertitle'] = htmlspecialchars_uni($post['usertitle']);
  488.  
  489. $usergroup['title'] = $lang->na;
  490.  
  491. $post['userregdate'] = $lang->na;
  492. $post['postnum'] = $lang->na;
  493. $post['button_profile'] = '';
  494. $post['button_email'] = '';
  495. $post['button_www'] = '';
  496. $post['signature'] = '';
  497. $post['button_pm'] = '';
  498. $post['button_find'] = '';
  499. $post['onlinestatus'] = '';
  500. $post['replink'] = '';
  501. eval("\$post['user_details'] = \"".$templates->get("postbit_author_guest")."\";");
  502. }
  503.  
  504. $post['button_edit'] = '';
  505. $post['button_quickdelete'] = '';
  506. $post['button_quickrestore'] = '';
  507. $post['button_quote'] = '';
  508. $post['button_quickquote'] = '';
  509. $post['button_report'] = '';
  510. $post['button_reply_pm'] = '';
  511. $post['button_replyall_pm'] = '';
  512. $post['button_forward_pm'] = '';
  513. $post['button_delete_pm'] = '';
  514.  
  515. // For private messages, fetch the reply/forward/delete icons
  516. if($post_type == 2 && $post['pmid'])
  517. {
  518. global $replyall;
  519.  
  520. eval("\$post['button_reply_pm'] = \"".$templates->get("postbit_reply_pm")."\";");
  521. eval("\$post['button_forward_pm'] = \"".$templates->get("postbit_forward_pm")."\";");
  522. eval("\$post['button_delete_pm'] = \"".$templates->get("postbit_delete_pm")."\";");
  523.  
  524. if($replyall == true)
  525. {
  526. eval("\$post['button_replyall_pm'] = \"".$templates->get("postbit_replyall_pm")."\";");
  527. }
  528. }
  529.  
  530. $post['editedmsg'] = '';
  531. if($post_type == 0 || $post_type == 4)
  532. {
  533. if(!isset($forumpermissions))
  534. {
  535. $forumpermissions = forum_permissions($fid);
  536. }
  537.  
  538. // Figure out if we need to show an "edited by" message
  539. if($post['edituid'] != 0 && $post['edittime'] != 0 && $post['editusername'] != "" && (($mybb->settings['showeditedby'] != 0 && $usergroup['cancp'] == 0) || ($mybb->settings['showeditedbyadmin'] != 0 && $usergroup['cancp'] == 1)))
  540. {
  541. $post['editdate'] = my_date('relative', $post['edittime']);
  542. $post['editnote'] = $lang->sprintf($lang->postbit_edited, $post['editdate']);
  543. $post['editedprofilelink'] = build_profile_link($post['editusername'], $post['edituid']);
  544. $editreason = "";
  545. if($post['editreason'] != "")
  546. {
  547. $post['editreason'] = $parser->parse_badwords($post['editreason']);
  548. $post['editreason'] = htmlspecialchars_uni($post['editreason']);
  549. eval("\$editreason = \"".$templates->get("postbit_editedby_editreason")."\";");
  550. }
  551. eval("\$post['editedmsg'] = \"".$templates->get("postbit_editedby")."\";");
  552. }
  553.  
  554. $time = TIME_NOW;
  555. if((is_moderator($fid, "caneditposts") || ($forumpermissions['caneditposts'] == 1 && $mybb->user['uid'] == $post['uid'] && $thread['closed'] != 1 && ($mybb->usergroup['edittimelimit'] == 0 || $mybb->usergroup['edittimelimit'] != 0 && $post['dateline'] > ($time-($mybb->usergroup['edittimelimit']*60))))) && $mybb->user['uid'] != 0)
  556. {
  557. eval("\$post['button_edit'] = \"".$templates->get("postbit_edit")."\";");
  558. }
  559.  
  560. // Quick Delete button
  561. $can_delete_thread = $can_delete_post = 0;
  562. if($mybb->user['uid'] == $post['uid'] && $thread['closed'] == 0)
  563. {
  564. if($forumpermissions['candeletethreads'] == 1 && $postcounter == 1)
  565. {
  566. $can_delete_thread = 1;
  567. }
  568. else if($forumpermissions['candeleteposts'] == 1 && $postcounter != 1)
  569. {
  570. $can_delete_post = 1;
  571. }
  572. }
  573.  
  574. $postbit_qdelete = $postbit_qrestore = '';
  575. if($mybb->user['uid'] != 0)
  576. {
  577. if((is_moderator($fid, "candeleteposts") || is_moderator($fid, "cansoftdeleteposts") || $can_delete_post == 1) && $postcounter != 1)
  578. {
  579. $postbit_qdelete = $lang->postbit_qdelete_post;
  580. $display = '';
  581. if($post['visible'] == -1)
  582. {
  583. $display = "none";
  584. }
  585. eval("\$post['button_quickdelete'] = \"".$templates->get("postbit_quickdelete")."\";");
  586. }
  587. else if((is_moderator($fid, "candeletethreads") || is_moderator($fid, "cansoftdeletethreads") || $can_delete_thread == 1) && $postcounter == 1)
  588. {
  589. $postbit_qdelete = $lang->postbit_qdelete_thread;
  590. $display = '';
  591. if($post['visible'] == -1)
  592. {
  593. $display = "none";
  594. }
  595. eval("\$post['button_quickdelete'] = \"".$templates->get("postbit_quickdelete")."\";");
  596. }
  597.  
  598. // Restore Post
  599. if(is_moderator($fid, "canrestoreposts") && $postcounter != 1)
  600. {
  601. $display = "none";
  602. if($post['visible'] == -1)
  603. {
  604. $display = '';
  605. }
  606. $postbit_qrestore = $lang->postbit_qrestore_post;
  607. eval("\$post['button_quickrestore'] = \"".$templates->get("postbit_quickrestore")."\";");
  608. }
  609.  
  610. // Restore Thread
  611. else if(is_moderator($fid, "canrestorethreads") && $postcounter == 1)
  612. {
  613. $display = "none";
  614. if($post['visible'] == -1)
  615. {
  616. $display = "";
  617. }
  618. $postbit_qrestore = $lang->postbit_qrestore_thread;
  619. eval("\$post['button_quickrestore'] = \"".$templates->get("postbit_quickrestore")."\";");
  620. }
  621. }
  622.  
  623. if(!isset($ismod))
  624. {
  625. $ismod = is_moderator($fid);
  626. }
  627.  
  628. // Inline moderation stuff
  629. if($ismod)
  630. {
  631. if(isset($mybb->cookies[$inlinecookie]) && my_strpos($mybb->cookies[$inlinecookie], "|".$post['pid']."|"))
  632. {
  633. $inlinecheck = "checked=\"checked\"";
  634. $inlinecount++;
  635. }
  636. else
  637. {
  638. $inlinecheck = "";
  639. }
  640.  
  641. eval("\$post['inlinecheck'] = \"".$templates->get("postbit_inlinecheck")."\";");
  642.  
  643. if($post['visible'] == 0)
  644. {
  645. $invisiblepost = 1;
  646. }
  647. }
  648. else
  649. {
  650. $post['inlinecheck'] = "";
  651. }
  652. $post['postlink'] = get_post_link($post['pid'], $post['tid']);
  653. $post_number = my_number_format($postcounter);
  654. eval("\$post['posturl'] = \"".$templates->get("postbit_posturl")."\";");
  655. global $forum, $thread;
  656.  
  657. if($forum['open'] != 0 && ($thread['closed'] != 1 || is_moderator($forum['fid'], "canpostclosedthreads")) && ($thread['uid'] == $mybb->user['uid'] || $forumpermissions['canonlyreplyownthreads'] != 1))
  658. {
  659. eval("\$post['button_quote'] = \"".$templates->get("postbit_quote")."\";");
  660. }
  661.  
  662. if($forumpermissions['canpostreplys'] != 0 && ($thread['uid'] == $mybb->user['uid'] || $forumpermissions['canonlyreplyownthreads'] != 1) && ($thread['closed'] != 1 || is_moderator($fid, "canpostclosedthreads")) && $mybb->settings['multiquote'] != 0 && $forum['open'] != 0 && !$post_type)
  663. {
  664. eval("\$post['button_multiquote'] = \"".$templates->get("postbit_multiquote")."\";");
  665. }
  666.  
  667. if($mybb->user['uid'] != "0")
  668. {
  669. eval("\$post['button_report'] = \"".$templates->get("postbit_report")."\";");
  670. }
  671. }
  672. elseif($post_type == 3) // announcement
  673. {
  674. if($mybb->usergroup['canmodcp'] == 1 && $mybb->usergroup['canmanageannounce'] == 1 && is_moderator($fid, "canmanageannouncements"))
  675. {
  676. eval("\$post['button_edit'] = \"".$templates->get("announcement_edit")."\";");
  677. eval("\$post['button_quickdelete'] = \"".$templates->get("announcement_quickdelete")."\";");
  678. }
  679. }
  680.  
  681. $post['iplogged'] = '';
  682. $show_ips = $mybb->settings['logip'];
  683. $ipaddress = my_inet_ntop($db->unescape_binary($post['ipaddress']));
  684.  
  685. // Show post IP addresses... PMs now can have IP addresses too as of 1.8!
  686. if($post_type == 2)
  687. {
  688. $show_ips = $mybb->settings['showpmip'];
  689. }
  690. if($post_type == 0 || $post_type == 2 || $post_type == 4)
  691. {
  692. if($show_ips != "no" && !empty($post['ipaddress']))
  693. {
  694. if($show_ips == "show")
  695. {
  696. eval("\$post['iplogged'] = \"".$templates->get("postbit_iplogged_show")."\";");
  697. }
  698. else if($show_ips == "hide" && (is_moderator($fid, "canviewips") || $mybb->usergroup['issupermod']))
  699. {
  700. $action = 'getip';
  701. if($post_type == 2)
  702. {
  703. $action = 'getpmip';
  704. }
  705. eval("\$post['iplogged'] = \"".$templates->get("postbit_iplogged_hiden")."\";");
  706. }
  707. }
  708. }
  709.  
  710. if(isset($post['smilieoff']) && $post['smilieoff'] == 1)
  711. {
  712. $parser_options['allow_smilies'] = 0;
  713. }
  714.  
  715. if($mybb->user['showimages'] != 1 && $mybb->user['uid'] != 0 || $mybb->settings['guestimages'] != 1 && $mybb->user['uid'] == 0)
  716. {
  717. $parser_options['allow_imgcode'] = 0;
  718. }
  719.  
  720. if($mybb->user['showvideos'] != 1 && $mybb->user['uid'] != 0 || $mybb->settings['guestvideos'] != 1 && $mybb->user['uid'] == 0)
  721. {
  722. $parser_options['allow_videocode'] = 0;
  723. }
  724.  
  725. // If we have incoming search terms to highlight - get it done.
  726. if(!empty($mybb->input['highlight']))
  727. {
  728. $parser_options['highlight'] = $mybb->input['highlight'];
  729. $post['subject'] = $parser->highlight_message($post['subject'], $parser_options['highlight']);
  730. }
  731.  
  732. $post['message'] = $parser->parse_message($post['message'], $parser_options);
  733.  
  734. $post['attachments'] = '';
  735. if($mybb->settings['enableattachments'] != 0)
  736. {
  737. get_post_attachments($id, $post);
  738. }
  739.  
  740. if(isset($post['includesig']) && $post['includesig'] != 0 && $post['username'] && $post['signature'] != "" && ($mybb->user['uid'] == 0 || $mybb->user['showsigs'] != 0)
  741. && ($post['suspendsignature'] == 0 || $post['suspendsignature'] == 1 && $post['suspendsigtime'] != 0 && $post['suspendsigtime'] < TIME_NOW) && $usergroup['canusesig'] == 1
  742. && ($usergroup['canusesigxposts'] == 0 || $usergroup['canusesigxposts'] > 0 && $postnum > $usergroup['canusesigxposts']) && !is_member($mybb->settings['hidesignatures']))
  743. {
  744. $sig_parser = array(
  745. "allow_html" => $mybb->settings['sightml'],
  746. "allow_mycode" => $mybb->settings['sigmycode'],
  747. "allow_smilies" => $mybb->settings['sigsmilies'],
  748. "allow_imgcode" => $mybb->settings['sigimgcode'],
  749. "me_username" => $post['username'],
  750. "filter_badwords" => 1
  751. );
  752.  
  753. if($usergroup['signofollow'])
  754. {
  755. $sig_parser['nofollow_on'] = 1;
  756. }
  757.  
  758. if($mybb->user['showimages'] != 1 && $mybb->user['uid'] != 0 || $mybb->settings['guestimages'] != 1 && $mybb->user['uid'] == 0)
  759. {
  760. $sig_parser['allow_imgcode'] = 0;
  761. }
  762.  
  763. $post['signature'] = $parser->parse_message($post['signature'], $sig_parser);
  764. eval("\$post['signature'] = \"".$templates->get("postbit_signature")."\";");
  765. }
  766. else
  767. {
  768. $post['signature'] = "";
  769. }
  770.  
  771. $icon_cache = $cache->read("posticons");
  772.  
  773. if(isset($post['icon']) && $post['icon'] > 0 && $icon_cache[$post['icon']])
  774. {
  775. $icon = $icon_cache[$post['icon']];
  776.  
  777. $icon['path'] = htmlspecialchars_uni($icon['path']);
  778. $icon['path'] = str_replace("{theme}", $theme['imgdir'], $icon['path']);
  779. $icon['name'] = htmlspecialchars_uni($icon['name']);
  780. eval("\$post['icon'] = \"".$templates->get("postbit_icon")."\";");
  781. }
  782. else
  783. {
  784. $post['icon'] = "";
  785. }
  786.  
  787. $post_visibility = $ignore_bit = '';
  788. switch($post_type)
  789. {
  790. case 1: // Message preview
  791. $post = $plugins->run_hooks("postbit_prev", $post);
  792. break;
  793. case 2: // Private message
  794. $post = $plugins->run_hooks("postbit_pm", $post);
  795. break;
  796. case 3: // Announcement
  797. $post = $plugins->run_hooks("postbit_announcement", $post);
  798. break;
  799. default: // Regular post
  800. if ($post_type == 4) { // reddit threaded style
  801. $post = $plugins->run_hooks("postbit_threaded", $post);
  802. } else {
  803. $post = $plugins->run_hooks("postbit", $post);
  804. }
  805.  
  806. if(!isset($ignored_users))
  807. {
  808. $ignored_users = array();
  809. if($mybb->user['uid'] > 0 && $mybb->user['ignorelist'] != "")
  810. {
  811. $ignore_list = explode(',', $mybb->user['ignorelist']);
  812. foreach($ignore_list as $uid)
  813. {
  814. $ignored_users[$uid] = 1;
  815. }
  816. }
  817. }
  818.  
  819. // Is this author on the ignore list of the current user? Hide this post
  820. if(is_array($ignored_users) && $post['uid'] != 0 && isset($ignored_users[$post['uid']]) && $ignored_users[$post['uid']] == 1)
  821. {
  822. $ignored_message = $lang->sprintf($lang->postbit_currently_ignoring_user, $post['username']);
  823. eval("\$ignore_bit = \"".$templates->get("postbit_ignored")."\";");
  824. $post_visibility = "display: none;";
  825. }
  826. break;
  827. }
  828.  
  829. if($mybb->settings['postlayout'] == "classic")
  830. {
  831. eval("\$postbit = \"".$templates->get("postbit_classic")."\";");
  832. }
  833. else if ($post_type == 4) // reddit threaded style
  834. {
  835. eval("\$postbit = \"".$templates->get("postbit_threaded")."\";");
  836. }
  837. else
  838. {
  839. eval("\$postbit = \"".$templates->get("postbit")."\";");
  840. }
  841. $GLOBALS['post'] = "";
  842.  
  843. return $postbit;
  844. }
  845.  
  846. /**
  847. * Fetch the attachments for a specific post and parse inline [attachment=id] code.
  848. * Note: assumes you have $attachcache, an array of attachments set up.
  849. *
  850. * @param int $id The ID of the item.
  851. * @param array $post The post or item passed by reference.
  852. */
  853. function get_post_attachments($id, &$post)
  854. {
  855. global $attachcache, $mybb, $theme, $templates, $forumpermissions, $lang;
  856.  
  857. $validationcount = 0;
  858. $tcount = 0;
  859. $post['attachmentlist'] = $post['thumblist'] = $post['imagelist'] = '';
  860. if(!isset($forumpermissions))
  861. {
  862. $forumpermissions = forum_permissions($post['fid']);
  863. }
  864.  
  865. if(isset($attachcache[$id]) && is_array($attachcache[$id]))
  866. { // This post has 1 or more attachments
  867. foreach($attachcache[$id] as $aid => $attachment)
  868. {
  869. if($attachment['visible'])
  870. { // There is an attachment thats visible!
  871. $attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
  872. $attachment['filesize'] = get_friendly_size($attachment['filesize']);
  873. $ext = get_extension($attachment['filename']);
  874. if($ext == "jpeg" || $ext == "gif" || $ext == "bmp" || $ext == "png" || $ext == "jpg")
  875. {
  876. $isimage = true;
  877. }
  878. else
  879. {
  880. $isimage = false;
  881. }
  882. $attachment['icon'] = get_attachment_icon($ext);
  883. $attachment['downloads'] = my_number_format($attachment['downloads']);
  884.  
  885. if(!$attachment['dateuploaded'])
  886. {
  887. $attachment['dateuploaded'] = $attachment['dateline'];
  888. }
  889. $attachdate = my_date('relative', $attachment['dateuploaded']);
  890. // Support for [attachment=id] code
  891. if(stripos($post['message'], "[attachment=".$attachment['aid']."]") !== false)
  892. {
  893. // Show as thumbnail IF image is big && thumbnail exists && setting=='thumb'
  894. // Show as full size image IF setting=='fullsize' || (image is small && permissions allow)
  895. // Show as download for all other cases
  896. if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != "" && $mybb->settings['attachthumbnails'] == "yes")
  897. {
  898. eval("\$attbit = \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
  899. }
  900. elseif((($attachment['thumbnail'] == "SMALL" && $forumpermissions['candlattachments'] == 1) || $mybb->settings['attachthumbnails'] == "no") && $isimage)
  901. {
  902. eval("\$attbit = \"".$templates->get("postbit_attachments_images_image")."\";");
  903. }
  904. else
  905. {
  906. eval("\$attbit = \"".$templates->get("postbit_attachments_attachment")."\";");
  907. }
  908. $post['message'] = preg_replace("#\[attachment=".$attachment['aid']."]#si", $attbit, $post['message']);
  909. }
  910. else
  911. {
  912. // Show as thumbnail IF image is big && thumbnail exists && setting=='thumb'
  913. // Show as full size image IF setting=='fullsize' || (image is small && permissions allow)
  914. // Show as download for all other cases
  915. if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != "" && $mybb->settings['attachthumbnails'] == "yes")
  916. {
  917. eval("\$post['thumblist'] .= \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
  918. if($tcount == 5)
  919. {
  920. $thumblist .= "<br />";
  921. $tcount = 0;
  922. }
  923. ++$tcount;
  924. }
  925. elseif((($attachment['thumbnail'] == "SMALL" && $forumpermissions['candlattachments'] == 1) || $mybb->settings['attachthumbnails'] == "no") && $isimage)
  926. {
  927. eval("\$post['imagelist'] .= \"".$templates->get("postbit_attachments_images_image")."\";");
  928. }
  929. else
  930. {
  931. eval("\$post['attachmentlist'] .= \"".$templates->get("postbit_attachments_attachment")."\";");
  932. }
  933. }
  934. }
  935. else
  936. {
  937. $validationcount++;
  938. }
  939. }
  940. if($validationcount > 0 && is_moderator($post['fid'], "canviewunapprove"))
  941. {
  942. if($validationcount == 1)
  943. {
  944. $postbit_unapproved_attachments = $lang->postbit_unapproved_attachment;
  945. }
  946. else
  947. {
  948. $postbit_unapproved_attachments = $lang->sprintf($lang->postbit_unapproved_attachments, $validationcount);
  949. }
  950. eval("\$post['attachmentlist'] .= \"".$templates->get("postbit_attachments_attachment_unapproved")."\";");
  951. }
  952. if($post['thumblist'])
  953. {
  954. eval("\$post['attachedthumbs'] = \"".$templates->get("postbit_attachments_thumbnails")."\";");
  955. }
  956. else
  957. {
  958. $post['attachedthumbs'] = '';
  959. }
  960. if($post['imagelist'])
  961. {
  962. eval("\$post['attachedimages'] = \"".$templates->get("postbit_attachments_images")."\";");
  963. }
  964. else
  965. {
  966. $post['attachedimages'] = '';
  967. }
  968. if($post['attachmentlist'] || $post['thumblist'] || $post['imagelist'])
  969. {
  970. eval("\$post['attachments'] = \"".$templates->get("postbit_attachments")."\";");
  971. }
  972. }
  973. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement