| [ Index ] |
PHP Cross Reference of MyBB 1.8.40 |
[Summary view] [Print] [Text view]
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, else = post) 16 * @return string The built post bit 17 */ 18 function build_postbit($post, $post_type=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 25 $hascustomtitle = 0; 26 27 // These will be unset when a guest is previewing a post that they're posting *as* a guest. 28 // In that case, set them to empty values to avert PHP 8 warnings re unset variables ahead. 29 if(!isset($post['userusername'])) 30 { 31 $post['userusername'] = ''; 32 } 33 34 if(!isset($post['uid'])) 35 { 36 $post['uid'] = 0; 37 } 38 39 if(!isset($post['usergroup'])) 40 { 41 $post['usergroup'] = 0; 42 } 43 44 // Set default values for any fields not provided here 45 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) 46 { 47 if(empty($post[$post_field])) 48 { 49 $post[$post_field] = ''; 50 } 51 } 52 53 // Set up the message parser if it doesn't already exist. 54 if(!$parser) 55 { 56 require_once MYBB_ROOT."inc/class_parser.php"; 57 $parser = new postParser; 58 } 59 60 if(!function_exists("purgespammer_show")) 61 { 62 require_once MYBB_ROOT."inc/functions_user.php"; 63 } 64 65 $unapproved_shade = ''; 66 if(isset($post['visible']) && $post['visible'] == 0 && $post_type == 0) 67 { 68 $altbg = $unapproved_shade = 'unapproved_post'; 69 } 70 elseif(isset($post['visible']) && $post['visible'] == -1 && $post_type == 0) 71 { 72 $altbg = $unapproved_shade = 'unapproved_post deleted_post'; 73 } 74 elseif($altbg == 'trow1') 75 { 76 $altbg = 'trow2'; 77 } 78 else 79 { 80 $altbg = 'trow1'; 81 } 82 $post['fid'] = $fid; 83 switch($post_type) 84 { 85 case 1: // Message preview 86 global $forum; 87 $parser_options['allow_html'] = $forum['allowhtml']; 88 $parser_options['allow_mycode'] = $forum['allowmycode']; 89 $parser_options['allow_smilies'] = $forum['allowsmilies']; 90 $parser_options['allow_imgcode'] = $forum['allowimgcode']; 91 $parser_options['allow_videocode'] = $forum['allowvideocode']; 92 $parser_options['me_username'] = $post['username']; 93 $parser_options['filter_badwords'] = 1; 94 $id = 0; 95 break; 96 case 2: // Private message 97 global $message, $pmid; 98 $idtype = 'pmid'; 99 $parser_options['allow_html'] = $mybb->settings['pmsallowhtml']; 100 $parser_options['allow_mycode'] = $mybb->settings['pmsallowmycode']; 101 $parser_options['allow_smilies'] = $mybb->settings['pmsallowsmilies']; 102 $parser_options['allow_imgcode'] = $mybb->settings['pmsallowimgcode']; 103 $parser_options['allow_videocode'] = $mybb->settings['pmsallowvideocode']; 104 $parser_options['me_username'] = $post['username']; 105 $parser_options['filter_badwords'] = 1; 106 $id = $pmid; 107 break; 108 case 3: // Announcement 109 global $announcementarray, $message; 110 $parser_options['allow_html'] = $mybb->settings['announcementshtml'] && $announcementarray['allowhtml']; 111 $parser_options['allow_mycode'] = $announcementarray['allowmycode']; 112 $parser_options['allow_smilies'] = $announcementarray['allowsmilies']; 113 $parser_options['allow_imgcode'] = 1; 114 $parser_options['allow_videocode'] = 1; 115 $parser_options['me_username'] = $post['username']; 116 $parser_options['filter_badwords'] = 1; 117 $id = $announcementarray['aid']; 118 break; 119 default: // Regular post 120 global $forum, $thread, $tid; 121 $oldforum = $forum; 122 $id = (int)$post['pid']; 123 $idtype = 'pid'; 124 $parser_options['allow_html'] = $forum['allowhtml']; 125 $parser_options['allow_mycode'] = $forum['allowmycode']; 126 $parser_options['allow_smilies'] = $forum['allowsmilies']; 127 $parser_options['allow_imgcode'] = $forum['allowimgcode']; 128 $parser_options['allow_videocode'] = $forum['allowvideocode']; 129 $parser_options['filter_badwords'] = 1; 130 break; 131 } 132 133 if(!$post['username']) 134 { 135 $post['username'] = $lang->guest; // htmlspecialchars_uni'd below 136 } 137 138 if($post['userusername']) 139 { 140 $parser_options['me_username'] = $post['userusername']; 141 } 142 else 143 { 144 $parser_options['me_username'] = $post['username']; 145 } 146 147 $post['username'] = htmlspecialchars_uni($post['username']); 148 $post['userusername'] = htmlspecialchars_uni($post['userusername']); 149 150 if(!$postcounter) 151 { // Used to show the # of the post 152 if($page > 1) 153 { 154 if(!$mybb->settings['postsperpage'] || (int)$mybb->settings['postsperpage'] < 1) 155 { 156 $mybb->settings['postsperpage'] = 20; 157 } 158 159 $postcounter = $mybb->settings['postsperpage']*($page-1); 160 } 161 else 162 { 163 $postcounter = 0; 164 } 165 $post_extra_style = "border-top-width: 0;"; 166 } 167 elseif($mybb->get_input('mode') == "threaded") 168 { 169 $post_extra_style = "border-top-width: 0;"; 170 } 171 else 172 { 173 $post_extra_style = "margin-top: 5px;"; 174 } 175 176 if(!$altbg) 177 { // Define the alternate background colour if this is the first post 178 $altbg = "trow1"; 179 } 180 $postcounter++; 181 182 // Format the post date and time using my_date 183 $post['postdate'] = my_date('relative', $post['dateline']); 184 185 // Dont want any little 'nasties' in the subject 186 $post['subject'] = $parser->parse_badwords($post['subject']); 187 188 // Pm's have been htmlspecialchars_uni()'ed already. 189 if($post_type != 2) 190 { 191 $post['subject'] = htmlspecialchars_uni($post['subject']); 192 } 193 194 if(empty($post['subject'])) 195 { 196 $post['subject'] = ' '; 197 } 198 199 $post['author'] = $post['uid']; 200 $post['subject_title'] = $post['subject']; 201 202 // Get the usergroup 203 if($post['usergroup']) 204 { 205 $usergroup = usergroup_permissions($post['usergroup']); 206 } 207 else 208 { 209 $usergroup = usergroup_permissions(1); 210 } 211 212 // Fetch display group data. 213 $displaygroupfields = array("title", "description", "namestyle", "usertitle", "stars", "starimage", "image"); 214 215 if(empty($post['displaygroup'])) 216 { 217 $post['displaygroup'] = $post['usergroup']; 218 } 219 220 // Set to hardcoded Guest usergroup ID (1) for guest author or deleted user. 221 if(empty($post['usergroup'])) 222 { 223 $post['usergroup'] = 1; 224 } 225 if(empty($post['displaygroup'])) 226 { 227 $post['displaygroup'] = 1; 228 } 229 230 $displaygroup = usergroup_displaygroup($post['displaygroup']); 231 if(is_array($displaygroup)) 232 { 233 $usergroup = array_merge($usergroup, $displaygroup); 234 } 235 236 if(!is_array($titlescache)) 237 { 238 $cached_titles = $cache->read("usertitles"); 239 if(!empty($cached_titles)) 240 { 241 foreach($cached_titles as $usertitle) 242 { 243 $titlescache[$usertitle['posts']] = $usertitle; 244 } 245 } 246 247 if(is_array($titlescache)) 248 { 249 krsort($titlescache); 250 } 251 unset($usertitle, $cached_titles); 252 } 253 254 // Work out the usergroup/title stuff 255 $post['groupimage'] = ''; 256 if(!empty($usergroup['image'])) 257 { 258 $language = $mybb->settings['bblanguage']; 259 if(!empty($mybb->user['language'])) 260 { 261 $language = $mybb->user['language']; 262 } 263 264 $usergroup['image'] = str_replace("{lang}", $language, $usergroup['image']); 265 $usergroup['image'] = str_replace("{theme}", $theme['imgdir'], $usergroup['image']); 266 eval("\$post['groupimage'] = \"".$templates->get("postbit_groupimage")."\";"); 267 268 if($mybb->settings['postlayout'] == "classic") 269 { 270 $post['groupimage'] .= "<br />"; 271 } 272 } 273 274 $post['profilelink_plain'] = $post['username_formatted'] = ''; 275 276 if($post['userusername']) 277 { 278 // This post was made by a registered user 279 $post['username'] = $post['userusername']; 280 $post['profilelink_plain'] = get_profile_link($post['uid']); 281 $post['username_formatted'] = format_name($post['username'], $post['usergroup'], $post['displaygroup']); 282 $post['profilelink'] = build_profile_link($post['username_formatted'], $post['uid']); 283 284 if(trim($post['usertitle']) != "") 285 { 286 $hascustomtitle = 1; 287 } 288 289 if($usergroup['usertitle'] != "" && !$hascustomtitle) 290 { 291 $post['usertitle'] = $usergroup['usertitle']; 292 } 293 elseif(is_array($titlescache) && !$usergroup['usertitle']) 294 { 295 reset($titlescache); 296 foreach($titlescache as $key => $titleinfo) 297 { 298 if($post['postnum'] >= $key) 299 { 300 if(!$hascustomtitle) 301 { 302 $post['usertitle'] = $titleinfo['title']; 303 } 304 $post['stars'] = $titleinfo['stars']; 305 $post['starimage'] = $titleinfo['starimage']; 306 break; 307 } 308 } 309 } 310 311 $post['usertitle'] = htmlspecialchars_uni($post['usertitle']); 312 313 if($usergroup['stars']) 314 { 315 $post['stars'] = $usergroup['stars']; 316 } 317 318 if(empty($post['starimage'])) 319 { 320 $post['starimage'] = $usergroup['starimage']; 321 } 322 323 $post['userstars'] = ''; 324 if($post['starimage'] && isset($post['stars'])) 325 { 326 // Only display stars if we have an image to use... 327 $post['starimage'] = str_replace("{theme}", $theme['imgdir'], $post['starimage']); 328 329 for($i = 0; $i < $post['stars']; ++$i) 330 { 331 eval("\$post['userstars'] .= \"".$templates->get("postbit_userstar", 1, 0)."\";"); 332 } 333 334 $post['userstars'] .= "<br />"; 335 } 336 337 $postnum = $post['postnum']; 338 $post['postnum'] = my_number_format($post['postnum']); 339 $post['threadnum'] = my_number_format($post['threadnum']); 340 341 // Determine the status to show for the user (Online/Offline/Away) 342 $timecut = TIME_NOW - $mybb->settings['wolcutoff']; 343 if($post['lastactive'] > $timecut && ($post['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1) && $post['lastvisit'] != $post['lastactive']) 344 { 345 eval("\$post['onlinestatus'] = \"".$templates->get("postbit_online")."\";"); 346 } 347 else 348 { 349 if($post['away'] == 1 && $mybb->settings['allowaway'] != 0) 350 { 351 eval("\$post['onlinestatus'] = \"".$templates->get("postbit_away")."\";"); 352 } 353 else 354 { 355 eval("\$post['onlinestatus'] = \"".$templates->get("postbit_offline")."\";"); 356 } 357 } 358 359 $post['useravatar'] = ''; 360 if(isset($mybb->user['showavatars']) && $mybb->user['showavatars'] != 0 || $mybb->user['uid'] == 0) 361 { 362 $useravatar = format_avatar($post['avatar'], $post['avatardimensions'], $mybb->settings['postmaxavatarsize']); 363 eval("\$post['useravatar'] = \"".$templates->get("postbit_avatar")."\";"); 364 } 365 366 $post['button_find'] = ''; 367 if($mybb->usergroup['cansearch'] == 1) 368 { 369 eval("\$post['button_find'] = \"".$templates->get("postbit_find")."\";"); 370 } 371 372 if($mybb->settings['enablepms'] == 1 && $post['uid'] != $mybb->user['uid'] && (($post['receivepms'] != 0 && $usergroup['canusepms'] != 0 && $mybb->usergroup['cansendpms'] == 1 && my_strpos(",".$post['ignorelist'].",", ",".$mybb->user['uid'].",") === false) || $mybb->usergroup['canoverridepm'] == 1)) 373 { 374 eval("\$post['button_pm'] = \"".$templates->get("postbit_pm")."\";"); 375 } 376 377 $post['button_rep'] = ''; 378 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)) 379 { 380 if(empty($post['pid'])) 381 { 382 $post['pid'] = 0; 383 } 384 385 eval("\$post['button_rep'] = \"".$templates->get("postbit_rep_button")."\";"); 386 } 387 388 if($post['website'] != "" && !is_member($mybb->settings['hidewebsite']) && $usergroup['canchangewebsite'] == 1) 389 { 390 $post['website'] = htmlspecialchars_uni($post['website']); 391 eval("\$post['button_www'] = \"".$templates->get("postbit_www")."\";"); 392 } 393 else 394 { 395 $post['button_www'] = ""; 396 } 397 398 if($post['hideemail'] != 1 && $post['uid'] != $mybb->user['uid'] && $mybb->usergroup['cansendemail'] == 1) 399 { 400 eval("\$post['button_email'] = \"".$templates->get("postbit_email")."\";"); 401 } 402 else 403 { 404 $post['button_email'] = ""; 405 } 406 407 $post['userregdate'] = my_date($mybb->settings['regdateformat'], $post['regdate']); 408 409 // Work out the reputation this user has (only show if not announcement) 410 if($post_type != 3 && $usergroup['usereputationsystem'] != 0 && $mybb->settings['enablereputation'] == 1) 411 { 412 $post['userreputation'] = get_reputation($post['reputation'], $post['uid']); 413 eval("\$post['replink'] = \"".$templates->get("postbit_reputation")."\";"); 414 } 415 416 // Showing the warning level? (only show if not announcement) 417 if($post_type != 3 && $mybb->settings['enablewarningsystem'] != 0 && $usergroup['canreceivewarnings'] != 0 && ($mybb->usergroup['canwarnusers'] != 0 || ($mybb->user['uid'] == $post['uid'] && $mybb->settings['canviewownwarning'] != 0))) 418 { 419 if($mybb->settings['maxwarningpoints'] < 1) 420 { 421 $mybb->settings['maxwarningpoints'] = 10; 422 } 423 424 $warning_level = round($post['warningpoints']/$mybb->settings['maxwarningpoints']*100); 425 if($warning_level > 100) 426 { 427 $warning_level = 100; 428 } 429 $warning_level = get_colored_warning_level($warning_level); 430 431 // If we can warn them, it's not the same person, and we're in a PM or a post. 432 if($mybb->usergroup['canwarnusers'] != 0 && $post['uid'] != $mybb->user['uid'] && ($post_type == 0 || $post_type == 2)) 433 { 434 eval("\$post['button_warn'] = \"".$templates->get("postbit_warn")."\";"); 435 $warning_link = "warnings.php?uid={$post['uid']}"; 436 } 437 else 438 { 439 $post['button_warn'] = ''; 440 $warning_link = "usercp.php"; 441 } 442 eval("\$post['warninglevel'] = \"".$templates->get("postbit_warninglevel")."\";"); 443 } 444 445 if($post_type != 3 && $post_type != 1 && purgespammer_show($post['postnum'], $post['usergroup'], $post['uid'])) 446 { 447 eval("\$post['button_purgespammer'] = \"".$templates->get('postbit_purgespammer')."\";"); 448 } 449 450 if(!isset($profile_fields)) 451 { 452 $profile_fields = array(); 453 454 // Fetch profile fields to display 455 $pfcache = $cache->read('profilefields'); 456 457 if(is_array($pfcache)) 458 { 459 foreach($pfcache as $profilefield) 460 { 461 if($profilefield['postbit'] != 1) 462 { 463 continue; 464 } 465 466 $profile_fields[$profilefield['fid']] = $profilefield; 467 } 468 } 469 } 470 471 // Display profile fields on posts - only if field is filled in 472 $post['profilefield'] = ''; 473 if(!empty($profile_fields)) 474 { 475 foreach($profile_fields as $field) 476 { 477 $fieldfid = "fid{$field['fid']}"; 478 if(!empty($post[$fieldfid])) 479 { 480 $post['fieldvalue'] = ''; 481 $post['fieldname'] = htmlspecialchars_uni($field['name']); 482 483 $thing = explode("\n", $field['type'], "2"); 484 $type = trim($thing[0]); 485 $useropts = explode("\n", $post[$fieldfid]); 486 487 if(is_array($useropts) && ($type == "multiselect" || $type == "checkbox")) 488 { 489 $post['fieldvalue_option'] = ''; 490 491 foreach($useropts as $val) 492 { 493 if($val != '') 494 { 495 $val = htmlspecialchars_uni($val); 496 497 eval("\$post['fieldvalue_option'] .= \"".$templates->get("postbit_profilefield_multiselect_value")."\";"); 498 } 499 } 500 if($post['fieldvalue_option'] != '') 501 { 502 eval("\$post['fieldvalue'] .= \"".$templates->get("postbit_profilefield_multiselect")."\";"); 503 } 504 } 505 else 506 { 507 $field_parser_options = array( 508 "allow_html" => $field['allowhtml'], 509 "allow_mycode" => $field['allowmycode'], 510 "allow_smilies" => $field['allowsmilies'], 511 "allow_imgcode" => $field['allowimgcode'], 512 "allow_videocode" => $field['allowvideocode'], 513 #"nofollow_on" => 1, 514 "filter_badwords" => 1 515 ); 516 517 if($field['type'] == "textarea") 518 { 519 $field_parser_options['me_username'] = $post['username']; 520 } 521 else 522 { 523 $field_parser_options['nl2br'] = 0; 524 } 525 526 if($mybb->user['uid'] != 0 && $mybb->user['showimages'] != 1 || $mybb->settings['guestimages'] != 1 && $mybb->user['uid'] == 0) 527 { 528 $field_parser_options['allow_imgcode'] = 0; 529 } 530 531 $post['fieldvalue'] = $parser->parse_message($post[$fieldfid], $field_parser_options); 532 } 533 534 eval("\$post['profilefield'] .= \"".$templates->get("postbit_profilefield")."\";"); 535 } 536 } 537 } 538 539 eval("\$post['user_details'] = \"".$templates->get("postbit_author_user")."\";"); 540 } 541 else 542 { // Message was posted by a guest or an unknown user 543 $post['profilelink'] = format_name($post['username'], 1); 544 545 if($usergroup['usertitle']) 546 { 547 $post['usertitle'] = $usergroup['usertitle']; 548 } 549 else 550 { 551 $post['usertitle'] = $lang->guest; 552 } 553 554 $post['usertitle'] = htmlspecialchars_uni($post['usertitle']); 555 $post['userstars'] = ''; 556 $post['useravatar'] = ''; 557 558 $usergroup['title'] = $lang->na; 559 560 $post['userregdate'] = $lang->na; 561 $post['postnum'] = $lang->na; 562 $post['button_profile'] = ''; 563 $post['button_email'] = ''; 564 $post['button_www'] = ''; 565 $post['signature'] = ''; 566 $post['button_pm'] = ''; 567 $post['button_find'] = ''; 568 $post['onlinestatus'] = ''; 569 $post['replink'] = ''; 570 eval("\$post['user_details'] = \"".$templates->get("postbit_author_guest")."\";"); 571 } 572 573 $post['input_editreason'] = ''; 574 $post['button_edit'] = ''; 575 $post['button_quickdelete'] = ''; 576 $post['button_quickrestore'] = ''; 577 $post['button_quote'] = ''; 578 $post['button_quickquote'] = ''; 579 $post['button_report'] = ''; 580 $post['button_reply_pm'] = ''; 581 $post['button_replyall_pm'] = ''; 582 $post['button_forward_pm'] = ''; 583 $post['button_delete_pm'] = ''; 584 585 // For private messages, fetch the reply/forward/delete icons 586 if($post_type == 2 && $post['pmid']) 587 { 588 global $replyall; 589 590 eval("\$post['button_reply_pm'] = \"".$templates->get("postbit_reply_pm")."\";"); 591 eval("\$post['button_forward_pm'] = \"".$templates->get("postbit_forward_pm")."\";"); 592 eval("\$post['button_delete_pm'] = \"".$templates->get("postbit_delete_pm")."\";"); 593 594 if($replyall == true) 595 { 596 eval("\$post['button_replyall_pm'] = \"".$templates->get("postbit_replyall_pm")."\";"); 597 } 598 } 599 600 $post['editedmsg'] = ''; 601 if(!$post_type) 602 { 603 if(!isset($forumpermissions)) 604 { 605 $forumpermissions = forum_permissions($fid); 606 } 607 608 // Figure out if we need to show an "edited by" message 609 if($post['edituid'] != 0 && $post['edittime'] != 0 && $post['editusername'] != "" && ($mybb->settings['showeditedby'] != 0 && $usergroup['cancp'] == 0 && !is_moderator($post['fid'], "", $post['uid']) || ($mybb->settings['showeditedbyadmin'] != 0 && ($usergroup['cancp'] == 1 || is_moderator($post['fid'], "", $post['uid']))))) 610 { 611 $post['editdate'] = my_date('relative', $post['edittime']); 612 $post['editnote'] = $lang->sprintf($lang->postbit_edited, $post['editdate']); 613 $post['editusername'] = htmlspecialchars_uni($post['editusername']); 614 $post['editedprofilelink'] = build_profile_link($post['editusername'], $post['edituid']); 615 $editreason = ""; 616 if($post['editreason'] != "") 617 { 618 $post['editreason'] = $parser->parse_badwords($post['editreason']); 619 $post['editreason'] = htmlspecialchars_uni($post['editreason']); 620 eval("\$editreason = \"".$templates->get("postbit_editedby_editreason")."\";"); 621 } 622 eval("\$post['editedmsg'] = \"".$templates->get("postbit_editedby")."\";"); 623 } 624 625 $time = TIME_NOW; 626 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) 627 { 628 eval("\$post['input_editreason'] = \"".$templates->get("postbit_editreason")."\";"); 629 eval("\$post['button_edit'] = \"".$templates->get("postbit_edit")."\";"); 630 } 631 632 // Quick Delete button 633 $can_delete_thread = $can_delete_post = 0; 634 if($mybb->user['uid'] == $post['uid'] && empty($thread['closed'])) 635 { 636 if($forumpermissions['candeletethreads'] == 1 && $postcounter == 1) 637 { 638 $can_delete_thread = 1; 639 } 640 else if($forumpermissions['candeleteposts'] == 1 && $postcounter != 1) 641 { 642 $can_delete_post = 1; 643 } 644 } 645 646 $postbit_qdelete = $postbit_qrestore = ''; 647 if($mybb->user['uid'] != 0) 648 { 649 if((is_moderator($fid, "candeleteposts") || is_moderator($fid, "cansoftdeleteposts") || $can_delete_post == 1) && $postcounter != 1) 650 { 651 $postbit_qdelete = $lang->postbit_qdelete_post; 652 $display = ''; 653 if($post['visible'] == -1) 654 { 655 $display = "none"; 656 } 657 eval("\$post['button_quickdelete'] = \"".$templates->get("postbit_quickdelete")."\";"); 658 } 659 else if((is_moderator($fid, "candeletethreads") || is_moderator($fid, "cansoftdeletethreads") || $can_delete_thread == 1) && $postcounter == 1) 660 { 661 $postbit_qdelete = $lang->postbit_qdelete_thread; 662 $display = ''; 663 if($post['visible'] == -1) 664 { 665 $display = "none"; 666 } 667 eval("\$post['button_quickdelete'] = \"".$templates->get("postbit_quickdelete")."\";"); 668 } 669 670 // Restore Post 671 if(is_moderator($fid, "canrestoreposts") && $postcounter != 1) 672 { 673 $display = "none"; 674 if($post['visible'] == -1) 675 { 676 $display = ''; 677 } 678 $postbit_qrestore = $lang->postbit_qrestore_post; 679 eval("\$post['button_quickrestore'] = \"".$templates->get("postbit_quickrestore")."\";"); 680 } 681 682 // Restore Thread 683 else if(is_moderator($fid, "canrestorethreads") && $postcounter == 1) 684 { 685 $display = "none"; 686 if($post['visible'] == -1) 687 { 688 $display = ""; 689 } 690 $postbit_qrestore = $lang->postbit_qrestore_thread; 691 eval("\$post['button_quickrestore'] = \"".$templates->get("postbit_quickrestore")."\";"); 692 } 693 } 694 695 if(!isset($ismod)) 696 { 697 $ismod = is_moderator($fid); 698 } 699 700 // Inline moderation stuff 701 if($ismod) 702 { 703 if(isset($mybb->cookies[$inlinecookie]) && my_strpos($mybb->cookies[$inlinecookie], "|".$post['pid']."|") !== false) 704 { 705 $inlinecheck = "checked=\"checked\""; 706 $inlinecount++; 707 } 708 else 709 { 710 $inlinecheck = ""; 711 } 712 713 eval("\$post['inlinecheck'] = \"".$templates->get("postbit_inlinecheck")."\";"); 714 715 if($post['visible'] == 0) 716 { 717 $invisiblepost = 1; 718 } 719 } 720 else 721 { 722 $post['inlinecheck'] = ""; 723 } 724 $post['postlink'] = get_post_link($post['pid'], $post['tid']); 725 $post_number = my_number_format($postcounter); 726 eval("\$post['posturl'] = \"".$templates->get("postbit_posturl")."\";"); 727 global $forum, $thread; 728 729 if($forum['open'] != 0 && ($thread['closed'] != 1 || is_moderator($forum['fid'], "canpostclosedthreads")) && ($thread['uid'] == $mybb->user['uid'] || empty($forumpermissions['canonlyreplyownthreads']))) 730 { 731 eval("\$post['button_quote'] = \"".$templates->get("postbit_quote")."\";"); 732 } 733 734 if($forumpermissions['canpostreplys'] != 0 && ($thread['uid'] == $mybb->user['uid'] || empty($forumpermissions['canonlyreplyownthreads'])) && ($thread['closed'] != 1 || is_moderator($fid, "canpostclosedthreads")) && $mybb->settings['multiquote'] != 0 && $forum['open'] != 0 && !$post_type) 735 { 736 eval("\$post['button_multiquote'] = \"".$templates->get("postbit_multiquote")."\";"); 737 } 738 739 if(isset($post['reporters'])) 740 { 741 $skip_report = my_unserialize($post['reporters']); 742 if(is_array($skip_report)) 743 { 744 $skip_report[] = 0; 745 } 746 else 747 { 748 $skip_report = array(0); 749 } 750 } 751 else 752 { 753 $skip_report = array(0); 754 } 755 756 $reportable = user_permissions($post['uid']); 757 if(!in_array($mybb->user['uid'], $skip_report) && !empty($reportable['canbereported'])) 758 { 759 eval("\$post['button_report'] = \"".$templates->get("postbit_report")."\";"); 760 } 761 } 762 elseif($post_type == 3) // announcement 763 { 764 if($mybb->usergroup['canmodcp'] == 1 && $mybb->usergroup['canmanageannounce'] == 1 && is_moderator($fid, "canmanageannouncements")) 765 { 766 eval("\$post['button_edit'] = \"".$templates->get("announcement_edit")."\";"); 767 eval("\$post['button_quickdelete'] = \"".$templates->get("announcement_quickdelete")."\";"); 768 } 769 } 770 771 $post['iplogged'] = ''; 772 $show_ips = $mybb->settings['logip']; 773 774 // Show post IP addresses... PMs now can have IP addresses too as of 1.8! 775 if($post_type == 2) 776 { 777 $show_ips = $mybb->settings['showpmip']; 778 } 779 if(!$post_type || $post_type == 2) 780 { 781 if($show_ips != "no" && !empty($post['ipaddress'])) 782 { 783 $ipaddress = my_inet_ntop($db->unescape_binary($post['ipaddress'])); 784 785 if($show_ips == "show") 786 { 787 eval("\$post['iplogged'] = \"".$templates->get("postbit_iplogged_show")."\";"); 788 } 789 else if($show_ips == "hide" && (is_moderator($fid, "canviewips") || $mybb->usergroup['issupermod'])) 790 { 791 $action = 'getip'; 792 $javascript = 'getIP'; 793 794 if($post_type == 2) 795 { 796 $action = 'getpmip'; 797 $javascript = 'getPMIP'; 798 } 799 800 eval("\$post['iplogged'] = \"".$templates->get("postbit_iplogged_hiden")."\";"); 801 } 802 } 803 } 804 805 $post['poststatus'] = ''; 806 if(!$post_type && $post['visible'] != 1) 807 { 808 $status_type = ''; 809 if(is_moderator($fid, "canviewdeleted") && $postcounter != 1 && $post['visible'] == -1) 810 { 811 $status_type = $lang->postbit_post_deleted; 812 } 813 else if(is_moderator($fid, "canviewunapprove") && $postcounter != 1 && $post['visible'] == 0) 814 { 815 $status_type = $lang->postbit_post_unapproved; 816 } 817 else if(is_moderator($fid, "canviewdeleted") && $postcounter == 1 && $post['visible'] == -1) 818 { 819 $status_type = $lang->postbit_thread_deleted; 820 } 821 else if(is_moderator($fid, "canviewunapprove") && $postcounter == 1 && $post['visible'] == 0) 822 { 823 $status_type = $lang->postbit_thread_unapproved; 824 } 825 826 eval("\$post['poststatus'] = \"".$templates->get("postbit_status")."\";"); 827 } 828 829 if(isset($post['smilieoff']) && $post['smilieoff'] == 1) 830 { 831 $parser_options['allow_smilies'] = 0; 832 } 833 834 if($mybb->user['uid'] != 0 && $mybb->user['showimages'] != 1 || $mybb->settings['guestimages'] != 1 && $mybb->user['uid'] == 0) 835 { 836 $parser_options['allow_imgcode'] = 0; 837 } 838 839 if($mybb->user['uid'] != 0 && $mybb->user['showvideos'] != 1 || $mybb->settings['guestvideos'] != 1 && $mybb->user['uid'] == 0) 840 { 841 $parser_options['allow_videocode'] = 0; 842 } 843 844 // If we have incoming search terms to highlight - get it done. 845 if(!empty($mybb->input['highlight'])) 846 { 847 $parser_options['highlight'] = $mybb->input['highlight']; 848 $post['subject'] = $parser->highlight_message($post['subject'], $parser_options['highlight']); 849 } 850 851 $post['message'] = $parser->parse_message($post['message'], $parser_options); 852 853 $post['attachments'] = ''; 854 if($mybb->settings['enableattachments'] != 0) 855 { 856 get_post_attachments($id, $post); 857 } 858 859 if(isset($post['includesig']) && $post['includesig'] != 0 && $post['username'] && $post['signature'] != "" && ($mybb->user['uid'] == 0 || $mybb->user['showsigs'] != 0) 860 && ($post['suspendsignature'] == 0 || $post['suspendsignature'] == 1 && $post['suspendsigtime'] != 0 && $post['suspendsigtime'] < TIME_NOW) && $usergroup['canusesig'] == 1 861 && ($usergroup['canusesigxposts'] == 0 || $usergroup['canusesigxposts'] > 0 && $postnum > $usergroup['canusesigxposts']) && !is_member($mybb->settings['hidesignatures'])) 862 { 863 $sig_parser = array( 864 "allow_html" => $mybb->settings['sightml'], 865 "allow_mycode" => $mybb->settings['sigmycode'], 866 "allow_smilies" => $mybb->settings['sigsmilies'], 867 "allow_imgcode" => $mybb->settings['sigimgcode'], 868 "me_username" => $parser_options['me_username'], 869 "filter_badwords" => 1 870 ); 871 872 if($usergroup['signofollow']) 873 { 874 $sig_parser['nofollow_on'] = 1; 875 } 876 877 if($mybb->user['uid'] != 0 && $mybb->user['showimages'] != 1 || $mybb->settings['guestimages'] != 1 && $mybb->user['uid'] == 0) 878 { 879 $sig_parser['allow_imgcode'] = 0; 880 } 881 882 $post['signature'] = $parser->parse_message($post['signature'], $sig_parser); 883 eval("\$post['signature'] = \"".$templates->get("postbit_signature")."\";"); 884 } 885 else 886 { 887 $post['signature'] = ""; 888 } 889 890 $icon_cache = array(); 891 892 if($mybb->settings['allowposticons'] == 1) 893 { 894 switch($post_type) 895 { 896 case 2: // Private message 897 $icon_cache = (array)$cache->read("posticons"); 898 break; 899 default: 900 global $forum; 901 902 if($forum['allowpicons'] != 0) 903 { 904 $icon_cache = (array)$cache->read("posticons"); 905 } 906 } 907 } 908 909 if(isset($post['icon']) && $post['icon'] > 0 && !empty($icon_cache[$post['icon']])) 910 { 911 $icon = $icon_cache[$post['icon']]; 912 913 $icon['path'] = htmlspecialchars_uni($icon['path']); 914 $icon['path'] = str_replace("{theme}", $theme['imgdir'], $icon['path']); 915 $icon['name'] = htmlspecialchars_uni($icon['name']); 916 eval("\$post['icon'] = \"".$templates->get("postbit_icon")."\";"); 917 } 918 else 919 { 920 $post['icon'] = ""; 921 } 922 923 $post_visibility = $ignore_bit = $deleted_bit = ''; 924 switch($post_type) 925 { 926 case 1: // Message preview 927 $post = $plugins->run_hooks("postbit_prev", $post); 928 break; 929 case 2: // Private message 930 $post = $plugins->run_hooks("postbit_pm", $post); 931 break; 932 case 3: // Announcement 933 $post = $plugins->run_hooks("postbit_announcement", $post); 934 break; 935 default: // Regular post 936 $post = $plugins->run_hooks("postbit", $post); 937 938 if(!isset($ignored_users)) 939 { 940 $ignored_users = array(); 941 if($mybb->user['uid'] > 0 && $mybb->user['ignorelist'] != "") 942 { 943 $ignore_list = explode(',', $mybb->user['ignorelist']); 944 foreach($ignore_list as $uid) 945 { 946 $ignored_users[$uid] = 1; 947 } 948 } 949 } 950 951 // Has this post been deleted but can be viewed? Hide this post 952 if($post['visible'] == -1 && is_moderator($fid, "canviewdeleted")) 953 { 954 $deleted_message = $lang->sprintf($lang->postbit_deleted_post_user, $post['username']); 955 eval("\$deleted_bit = \"".$templates->get("postbit_deleted")."\";"); 956 $post_visibility = "display: none;"; 957 } 958 959 // Is the user (not moderator) logged in and have unapproved posts? 960 if($mybb->user['uid'] && $post['visible'] == 0 && $post['uid'] == $mybb->user['uid'] && !is_moderator($fid, "canviewunapprove")) 961 { 962 $ignored_message = $lang->sprintf($lang->postbit_post_under_moderation, $post['username']); 963 eval("\$ignore_bit = \"".$templates->get("postbit_ignored")."\";"); 964 $post_visibility = "display: none;"; 965 } 966 967 // Is this author on the ignore list of the current user? Hide this post 968 if(is_array($ignored_users) && $post['uid'] != 0 && isset($ignored_users[$post['uid']]) && $ignored_users[$post['uid']] == 1 && empty($deleted_bit)) 969 { 970 $ignored_message = $lang->sprintf($lang->postbit_currently_ignoring_user, $post['username']); 971 eval("\$ignore_bit = \"".$templates->get("postbit_ignored")."\";"); 972 $post_visibility = "display: none;"; 973 } 974 break; 975 } 976 977 if($post_type == 0 && $forumpermissions['canviewdeletionnotice'] == 1 && $post['visible'] == -1 && !is_moderator($fid, "canviewdeleted")) 978 { 979 eval("\$postbit = \"".$templates->get("postbit_deleted_member")."\";"); 980 } 981 else 982 { 983 if($mybb->settings['postlayout'] == "classic") 984 { 985 eval("\$postbit = \"".$templates->get("postbit_classic")."\";"); 986 } 987 else 988 { 989 eval("\$postbit = \"".$templates->get("postbit")."\";"); 990 } 991 } 992 993 $GLOBALS['post'] = ""; 994 995 return $postbit; 996 } 997 998 /** 999 * Fetch the attachments for a specific post and parse inline [attachment=id] code. 1000 * Note: assumes you have $attachcache, an array of attachments set up. 1001 * 1002 * @param int $id The ID of the item. 1003 * @param array $post The post or item passed by reference. 1004 */ 1005 function get_post_attachments($id, &$post) 1006 { 1007 global $attachcache, $mybb, $theme, $templates, $forumpermissions, $lang; 1008 1009 $validationcount = 0; 1010 $tcount = 0; 1011 $post['attachmentlist'] = $post['thumblist'] = $post['imagelist'] = ''; 1012 if(!isset($forumpermissions)) 1013 { 1014 $forumpermissions = forum_permissions($post['fid']); 1015 } 1016 1017 if(isset($attachcache[$id]) && is_array($attachcache[$id])) 1018 { // This post has 1 or more attachments 1019 foreach($attachcache[$id] as $aid => $attachment) 1020 { 1021 if($attachment['visible']) 1022 { // There is an attachment thats visible! 1023 $attachment['filename'] = htmlspecialchars_uni($attachment['filename']); 1024 $attachment['filesize'] = get_friendly_size($attachment['filesize']); 1025 $ext = get_extension($attachment['filename']); 1026 if($ext == "jpeg" || $ext == "gif" || $ext == "bmp" || $ext == "png" || $ext == "jpg") 1027 { 1028 $isimage = true; 1029 } 1030 else 1031 { 1032 $isimage = false; 1033 } 1034 $attachment['icon'] = get_attachment_icon($ext); 1035 $attachment['downloads'] = my_number_format($attachment['downloads']); 1036 1037 if(!$attachment['dateuploaded']) 1038 { 1039 $attachment['dateuploaded'] = $post['dateline']; 1040 } 1041 $attachdate = my_date('normal', $attachment['dateuploaded']); 1042 // Support for [attachment=id] code 1043 if(stripos($post['message'], "[attachment=".$attachment['aid']."]") !== false) 1044 { 1045 // Show as thumbnail IF image is big && thumbnail exists && setting=='thumb' 1046 // Show as full size image IF setting=='fullsize' || (image is small && permissions allow) 1047 // Show as download for all other cases 1048 if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != "" && $mybb->settings['attachthumbnails'] == "yes") 1049 { 1050 eval("\$attbit = \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";"); 1051 } 1052 elseif((($attachment['thumbnail'] == "SMALL" && $forumpermissions['candlattachments'] == 1) || $mybb->settings['attachthumbnails'] == "no") && $isimage) 1053 { 1054 eval("\$attbit = \"".$templates->get("postbit_attachments_images_image")."\";"); 1055 } 1056 else 1057 { 1058 eval("\$attbit = \"".$templates->get("postbit_attachments_attachment")."\";"); 1059 } 1060 $post['message'] = preg_replace("#\[attachment=".$attachment['aid']."]#si", $attbit, $post['message']); 1061 } 1062 else 1063 { 1064 // Show as thumbnail IF image is big && thumbnail exists && setting=='thumb' 1065 // Show as full size image IF setting=='fullsize' || (image is small && permissions allow) 1066 // Show as download for all other cases 1067 if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != "" && $mybb->settings['attachthumbnails'] == "yes") 1068 { 1069 eval("\$post['thumblist'] .= \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";"); 1070 if($tcount == 5) 1071 { 1072 $post['thumblist'] .= "<br />"; 1073 $tcount = 0; 1074 } 1075 ++$tcount; 1076 } 1077 elseif((($attachment['thumbnail'] == "SMALL" && $forumpermissions['candlattachments'] == 1) || $mybb->settings['attachthumbnails'] == "no") && $isimage) 1078 { 1079 if ($forumpermissions['candlattachments']) 1080 { 1081 eval("\$post['imagelist'] .= \"".$templates->get("postbit_attachments_images_image")."\";"); 1082 } 1083 else 1084 { 1085 eval("\$post['thumblist'] .= \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";"); 1086 if($tcount == 5) 1087 { 1088 $post['thumblist'] .= "<br />"; 1089 $tcount = 0; 1090 } 1091 ++$tcount; 1092 } 1093 } 1094 else 1095 { 1096 eval("\$post['attachmentlist'] .= \"".$templates->get("postbit_attachments_attachment")."\";"); 1097 } 1098 } 1099 } 1100 else 1101 { 1102 $validationcount++; 1103 } 1104 } 1105 if($validationcount > 0 && is_moderator($post['fid'], "canviewunapprove")) 1106 { 1107 if($validationcount == 1) 1108 { 1109 $postbit_unapproved_attachments = $lang->postbit_unapproved_attachment; 1110 } 1111 else 1112 { 1113 $postbit_unapproved_attachments = $lang->sprintf($lang->postbit_unapproved_attachments, $validationcount); 1114 } 1115 eval("\$post['attachmentlist'] .= \"".$templates->get("postbit_attachments_attachment_unapproved")."\";"); 1116 } 1117 if($post['thumblist']) 1118 { 1119 eval("\$post['attachedthumbs'] = \"".$templates->get("postbit_attachments_thumbnails")."\";"); 1120 } 1121 else 1122 { 1123 $post['attachedthumbs'] = ''; 1124 } 1125 if($post['imagelist']) 1126 { 1127 eval("\$post['attachedimages'] = \"".$templates->get("postbit_attachments_images")."\";"); 1128 } 1129 else 1130 { 1131 $post['attachedimages'] = ''; 1132 } 1133 if($post['attachmentlist'] || $post['thumblist'] || $post['imagelist']) 1134 { 1135 eval("\$post['attachments'] = \"".$templates->get("postbit_attachments")."\";"); 1136 } 1137 } 1138 } 1139 1140 /** 1141 * Returns bytes count from human readable string 1142 * Used to parse ini_get human-readable values to int 1143 * 1144 * @param string $val Human-readable value 1145 */ 1146 function return_bytes($val) { 1147 $val = trim($val); 1148 if ($val == "") 1149 { 1150 return 0; 1151 } 1152 1153 $last = strtolower($val[strlen($val)-1]); 1154 1155 $val = intval($val); 1156 1157 switch($last) 1158 { 1159 case 'g': 1160 $val *= 1024; 1161 case 'm': 1162 $val *= 1024; 1163 case 'k': 1164 $val *= 1024; 1165 } 1166 1167 return $val; 1168 } 1169 1170 /** 1171 * Detects whether an attachment removal/approval/unapproval 1172 * submit button was pressed (without triggering an AJAX request) 1173 * and sets inputs accordingly (as for an AJAX request). 1174 */ 1175 function detect_attachmentact() 1176 { 1177 global $mybb; 1178 1179 foreach($mybb->input as $key => $val) 1180 { 1181 if(strpos($key, 'rem_') === 0) 1182 { 1183 $mybb->input['attachmentaid'] = (int)substr($key, 4); 1184 $mybb->input['attachmentact'] = 'remove'; 1185 break; 1186 } 1187 elseif(strpos($key, 'approveattach_') === 0) 1188 { 1189 $mybb->input['attachmentaid'] = (int)substr($key, 14); 1190 $mybb->input['attachmentact'] = 'approve'; 1191 break; 1192 } 1193 elseif(strpos($key, 'unapproveattach_') === 0) 1194 { 1195 $mybb->input['attachmentaid'] = (int)substr($key, 16); 1196 $mybb->input['attachmentact'] = 'unapprove'; 1197 break; 1198 } 1199 } 1200 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| 2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup | Cross-referenced by PHPXref |