| [ Index ] |
PHP Cross Reference of MyBB 1.6.5 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * MyBB 1.6 4 * Copyright 2010 MyBB Group, All Rights Reserved 5 * 6 * Website: http://mybb.com 7 * License: http://mybb.com/about/license 8 * 9 * $Id: functions_post.php 5651 2011-11-14 08:45:52Z Tomm $ 10 */ 11 12 /** 13 * Build a post bit 14 * 15 * @param array The post data 16 * @param int The type of post bit we're building (1 = preview, 2 = pm, 3 = announcement, else = post) 17 * @return string The built post bit 18 */ 19 function build_postbit($post, $post_type=0) 20 { 21 global $db, $altbg, $theme, $mybb, $postcounter; 22 global $titlescache, $page, $templates, $forumpermissions, $attachcache; 23 global $lang, $ismod, $inlinecookie, $inlinecount, $groupscache, $fid; 24 global $plugins, $parser, $cache, $ignored_users, $hascustomtitle; 25 26 $hascustomtitle = 0; 27 28 // Set up the message parser if it doesn't already exist. 29 if(!$parser) 30 { 31 require_once MYBB_ROOT."inc/class_parser.php"; 32 $parser = new postParser; 33 } 34 35 $unapproved_shade = ''; 36 if($post['visible'] == 0 && $post_type == 0) 37 { 38 $altbg = $unapproved_shade = 'trow_shaded'; 39 } 40 elseif($altbg == 'trow1') 41 { 42 $altbg = 'trow2'; 43 } 44 else 45 { 46 $altbg = 'trow1'; 47 } 48 $post['fid'] = $fid; 49 switch($post_type) 50 { 51 case 1: // Message preview 52 global $forum; 53 $parser_options['allow_html'] = $forum['allowhtml']; 54 $parser_options['allow_mycode'] = $forum['allowmycode']; 55 $parser_options['allow_smilies'] = $forum['allowsmilies']; 56 $parser_options['allow_imgcode'] = $forum['allowimgcode']; 57 $parser_options['allow_videocode'] = $forum['allowvideocode']; 58 $parser_options['me_username'] = $post['username']; 59 $parser_options['filter_badwords'] = 1; 60 $id = 0; 61 break; 62 case 2: // Private message 63 global $message, $pmid; 64 $parser_options['allow_html'] = $mybb->settings['pmsallowhtml']; 65 $parser_options['allow_mycode'] = $mybb->settings['pmsallowmycode']; 66 $parser_options['allow_smilies'] = $mybb->settings['pmsallowsmilies']; 67 $parser_options['allow_imgcode'] = $mybb->settings['pmsallowimgcode']; 68 $parser_options['allow_videocode'] = $mybb->settings['pmsallowvideocode']; 69 $parser_options['me_username'] = $post['username']; 70 $parser_options['filter_badwords'] = 1; 71 $id = $pmid; 72 break; 73 case 3: // Announcement 74 global $announcementarray, $message; 75 $parser_options['allow_html'] = $announcementarray['allowhtml']; 76 $parser_options['allow_mycode'] = $announcementarray['allowmycode']; 77 $parser_options['allow_smilies'] = $announcementarray['allowsmilies']; 78 $parser_options['allow_imgcode'] = 1; 79 $parser_options['allow_videocode'] = 1; 80 $parser_options['me_username'] = $post['username']; 81 $parser_options['filter_badwords'] = 1; 82 break; 83 default: // Regular post 84 global $forum, $thread, $tid; 85 $oldforum = $forum; 86 $id = intval($post['pid']); 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['filter_badwords'] = 1; 93 94 if(!$post['username']) 95 { 96 $post['username'] = $lang->guest; 97 } 98 99 if($post['userusername']) 100 { 101 $parser_options['me_username'] = $post['userusername']; 102 } 103 else 104 { 105 $parser_options['me_username'] = $post['username']; 106 } 107 break; 108 } 109 110 // Sanatize our custom profile fields for use in templates, if people choose to use them 111 foreach($post as $post_field => $field_value) 112 { 113 if(substr($post_field, 0, 3) != 'fid') 114 { 115 continue; 116 } 117 $post[$post_field] = htmlspecialchars_uni($field_value); 118 } 119 120 if(!$postcounter) 121 { // Used to show the # of the post 122 if($page > 1) 123 { 124 if(!$mybb->settings['postsperpage']) 125 { 126 $mybb->settings['postperpage'] = 20; 127 } 128 129 $postcounter = $mybb->settings['postsperpage']*($page-1); 130 } 131 else 132 { 133 $postcounter = 0; 134 } 135 $post_extra_style = "border-top-width: 0;"; 136 } 137 elseif($mybb->input['mode'] == "threaded") 138 { 139 $post_extra_style = "border-top-width: 0;"; 140 } 141 else 142 { 143 $post_extra_style = "margin-top: 5px;"; 144 } 145 146 if(!$altbg) 147 { // Define the alternate background colour if this is the first post 148 $altbg = "trow1"; 149 } 150 $postcounter++; 151 152 // Format the post date and time using my_date 153 $post['postdate'] = my_date($mybb->settings['dateformat'], $post['dateline']); 154 $post['posttime'] = my_date($mybb->settings['timeformat'], $post['dateline']); 155 156 // Dont want any little 'nasties' in the subject 157 $post['subject'] = $parser->parse_badwords($post['subject']); 158 159 // Pm's have been htmlspecialchars_uni()'ed already. 160 if($post_type != 2) 161 { 162 $post['subject'] = htmlspecialchars_uni($post['subject']); 163 } 164 165 if(empty($post['subject'])) 166 { 167 $post['subject'] = ' '; 168 } 169 170 $post['author'] = $post['uid']; 171 172 // Get the usergroup 173 if($post['userusername']) 174 { 175 if(!$post['displaygroup']) 176 { 177 $post['displaygroup'] = $post['usergroup']; 178 } 179 $usergroup = $groupscache[$post['displaygroup']]; 180 } 181 else 182 { 183 $usergroup = $groupscache[1]; 184 } 185 186 if(!is_array($titlescache)) 187 { 188 $cached_titles = $cache->read("usertitles"); 189 if(!empty($cached_titles)) 190 { 191 foreach($cached_titles as $usertitle) 192 { 193 $titlescache[$usertitle['posts']] = $usertitle; 194 } 195 } 196 197 if(is_array($titlescache)) 198 { 199 krsort($titlescache); 200 } 201 unset($usertitle, $cached_titles); 202 } 203 204 // Work out the usergroup/title stuff 205 if(!empty($usergroup['image'])) 206 { 207 if(!empty($mybb->user['language'])) 208 { 209 $language = $mybb->user['language']; 210 } 211 else 212 { 213 $language = $mybb->settings['bblanguage']; 214 } 215 $usergroup['image'] = str_replace("{lang}", $language, $usergroup['image']); 216 $usergroup['image'] = str_replace("{theme}", $theme['imgdir'], $usergroup['image']); 217 eval("\$post['groupimage'] = \"".$templates->get("postbit_groupimage")."\";"); 218 if($mybb->settings['postlayout'] == "classic") 219 { 220 $post['groupimage'] .= "<br />"; 221 } 222 } 223 224 if($post['userusername']) 225 { // This post was made by a registered user 226 227 $post['username'] = $post['userusername']; 228 $post['profilelink_plain'] = get_profile_link($post['uid']); 229 $post['username_formatted'] = format_name($post['username'], $post['usergroup'], $post['displaygroup']); 230 $post['profilelink'] = build_profile_link($post['username_formatted'], $post['uid']); 231 232 if(trim($post['usertitle']) != "") 233 { 234 $hascustomtitle = 1; 235 } 236 237 if($usergroup['usertitle'] != "" && !$hascustomtitle) 238 { 239 $post['usertitle'] = $usergroup['usertitle']; 240 } 241 elseif(is_array($titlescache) && !$usergroup['usertitle']) 242 { 243 reset($titlescache); 244 foreach($titlescache as $key => $titleinfo) 245 { 246 if($post['postnum'] >= $key) 247 { 248 if(!$hascustomtitle) 249 { 250 $post['usertitle'] = $titleinfo['title']; 251 } 252 $post['stars'] = $titleinfo['stars']; 253 $post['starimage'] = $titleinfo['starimage']; 254 break; 255 } 256 } 257 } 258 259 if($usergroup['stars']) 260 { 261 $post['stars'] = $usergroup['stars']; 262 } 263 264 if(!$post['starimage']) 265 { 266 $post['starimage'] = $usergroup['starimage']; 267 } 268 269 if($post['starimage'] && $post['stars']) 270 { 271 // Only display stars if we have an image to use... 272 $post['starimage'] = str_replace("{theme}", $theme['imgdir'], $post['starimage']); 273 274 for($i = 0; $i < $post['stars']; ++$i) 275 { 276 $post['userstars'] .= "<img src=\"".$post['starimage']."\" border=\"0\" alt=\"*\" />"; 277 } 278 279 $post['userstars'] .= "<br />"; 280 } 281 282 $postnum = $post['postnum']; 283 $post['postnum'] = my_number_format($post['postnum']); 284 285 // Determine the status to show for the user (Online/Offline/Away) 286 $timecut = TIME_NOW - $mybb->settings['wolcutoff']; 287 if($post['lastactive'] > $timecut && ($post['invisible'] != 1 || $mybb->usergroup['canviewwolinvis'] == 1) && $post['lastvisit'] != $post['lastactive']) 288 { 289 eval("\$post['onlinestatus'] = \"".$templates->get("postbit_online")."\";"); 290 } 291 else 292 { 293 if($post['away'] == 1 && $mybb->settings['allowaway'] != 0) 294 { 295 eval("\$post['onlinestatus'] = \"".$templates->get("postbit_away")."\";"); 296 } 297 else 298 { 299 eval("\$post['onlinestatus'] = \"".$templates->get("postbit_offline")."\";"); 300 } 301 } 302 303 if($post['avatar'] != "" && ($mybb->user['showavatars'] != 0 || !$mybb->user['uid'])) 304 { 305 $post['avatar'] = htmlspecialchars_uni($post['avatar']); 306 $avatar_dimensions = explode("|", $post['avatardimensions']); 307 308 if($avatar_dimensions[0] && $avatar_dimensions[1]) 309 { 310 list($max_width, $max_height) = explode("x", my_strtolower($mybb->settings['postmaxavatarsize'])); 311 if($avatar_dimensions[0] > $max_width || $avatar_dimensions[1] > $max_height) 312 { 313 require_once MYBB_ROOT."inc/functions_image.php"; 314 $scaled_dimensions = scale_image($avatar_dimensions[0], $avatar_dimensions[1], $max_width, $max_height); 315 $avatar_width_height = "width=\"{$scaled_dimensions['width']}\" height=\"{$scaled_dimensions['height']}\""; 316 } 317 else 318 { 319 $avatar_width_height = "width=\"{$avatar_dimensions[0]}\" height=\"{$avatar_dimensions[1]}\""; 320 } 321 } 322 323 eval("\$post['useravatar'] = \"".$templates->get("postbit_avatar")."\";"); 324 $post['avatar_padding'] = "padding-right: 10px;"; 325 } 326 else 327 { 328 $post['useravatar'] = ""; 329 } 330 331 eval("\$post['button_find'] = \"".$templates->get("postbit_find")."\";"); 332 333 if($mybb->settings['enablepms'] == 1 && $post['receivepms'] != 0 && $mybb->usergroup['cansendpms'] == 1 && my_strpos(",".$post['ignorelist'].",", ",".$mybb->user['uid'].",") === false) 334 { 335 eval("\$post['button_pm'] = \"".$templates->get("postbit_pm")."\";"); 336 } 337 338 if($mybb->settings['enablereputation'] == 1 && $mybb->settings['postrep'] == 1 && $mybb->usergroup['cangivereputations'] == 1 && $usergroup['usereputationsystem'] == 1 && ($mybb->settings['posrep'] || $mybb->settings['neurep'] || $mybb->settings['negrep'])) 339 { 340 if(!$post['pid']) 341 { 342 $post['pid'] = 0; 343 } 344 345 eval("\$post['button_rep'] = \"".$templates->get("postbit_rep_button")."\";"); 346 } 347 348 if($post['website'] != "") 349 { 350 $post['website'] = htmlspecialchars_uni($post['website']); 351 eval("\$post['button_www'] = \"".$templates->get("postbit_www")."\";"); 352 } 353 else 354 { 355 $post['button_www'] = ""; 356 } 357 358 if($post['hideemail'] != 1 && $mybb->usergroup['cansendemail'] == 1) 359 { 360 eval("\$post['button_email'] = \"".$templates->get("postbit_email")."\";"); 361 } 362 else 363 { 364 $post['button_email'] = ""; 365 } 366 367 $post['userregdate'] = my_date($mybb->settings['regdateformat'], $post['regdate']); 368 369 // Work out the reputation this user has (only show if not announcement) 370 if($post_type != 3 && $usergroup['usereputationsystem'] != 0 && $mybb->settings['enablereputation'] == 1 && ($mybb->settings['posrep'] || $mybb->settings['neurep'] || $mybb->settings['negrep'])) 371 { 372 $post['userreputation'] = get_reputation($post['reputation'], $post['uid']); 373 eval("\$post['replink'] = \"".$templates->get("postbit_reputation")."\";"); 374 } 375 376 // Showing the warning level? (only show if not announcement) 377 if($post_type != 3 && $mybb->settings['enablewarningsystem'] != 0 && $usergroup['canreceivewarnings'] != 0 && ($mybb->usergroup['canwarnusers'] != 0 || ($mybb->user['uid'] == $post['uid'] && $mybb->settings['canviewownwarning'] != 0))) 378 { 379 $warning_level = round($post['warningpoints']/$mybb->settings['maxwarningpoints']*100); 380 if($warning_level > 100) 381 { 382 $warning_level = 100; 383 } 384 $warning_level = get_colored_warning_level($warning_level); 385 386 // If we can warn them, it's not the same person, and we're in a PM or a post. 387 if($mybb->usergroup['canwarnusers'] != 0 && $post['uid'] != $mybb->user['uid'] && ($post_type == 0 || $post_type == 2)) 388 { 389 eval("\$post['button_warn'] = \"".$templates->get("postbit_warn")."\";"); 390 $warning_link = "warnings.php?uid={$post['uid']}"; 391 } 392 else 393 { 394 $warning_link = "usercp.php"; 395 } 396 eval("\$post['warninglevel'] = \"".$templates->get("postbit_warninglevel")."\";"); 397 } 398 399 eval("\$post['user_details'] = \"".$templates->get("postbit_author_user")."\";"); 400 } 401 else 402 { // Message was posted by a guest or an unknown user 403 $post['username'] = $post['username']; 404 $post['profilelink'] = format_name($post['username'], 1); 405 406 if($usergroup['usertitle']) 407 { 408 $post['usertitle'] = $usergroup['usertitle']; 409 } 410 else 411 { 412 $post['usertitle'] = $lang->guest; 413 } 414 415 $usergroup['title'] = $lang->na; 416 417 $post['userregdate'] = $lang->na; 418 $post['postnum'] = $lang->na; 419 $post['button_profile'] = ''; 420 $post['button_email'] = ''; 421 $post['button_www'] = ''; 422 $post['signature'] = ''; 423 $post['button_pm'] = ''; 424 $post['button_find'] = ''; 425 $post['onlinestatus'] = ''; 426 $post['replink'] = ''; 427 eval("\$post['user_details'] = \"".$templates->get("postbit_author_guest")."\";"); 428 } 429 430 $post['button_edit'] = ''; 431 $post['button_quickdelete'] = ''; 432 $post['button_quote'] = ''; 433 $post['button_quickquote'] = ''; 434 $post['button_report'] = ''; 435 436 // For private messages, fetch the reply/forward/delete icons 437 if($post_type == 2 && $post['pmid']) 438 { 439 global $replyall; 440 441 eval("\$post['button_reply_pm'] = \"".$templates->get("postbit_reply_pm")."\";"); 442 eval("\$post['button_forward_pm'] = \"".$templates->get("postbit_forward_pm")."\";"); 443 eval("\$post['button_delete_pm'] = \"".$templates->get("postbit_delete_pm")."\";"); 444 445 if($replyall == true) 446 { 447 eval("\$post['button_replyall_pm'] = \"".$templates->get("postbit_replyall_pm")."\";"); 448 } 449 } 450 451 if(!$post_type) 452 { 453 // Figure out if we need to show an "edited by" message 454 if($post['edituid'] != 0 && $post['edittime'] != 0 && $post['editusername'] != "" && ($mybb->settings['showeditedby'] != 0 && $usergroup['cancp'] == 0 || $mybb->settings['showeditedbyadmin'] != 0 && $usergroup['cancp'] == 1)) 455 { 456 $post['editdate'] = my_date($mybb->settings['dateformat'], $post['edittime']); 457 $post['edittime'] = my_date($mybb->settings['timeformat'], $post['edittime']); 458 $post['editnote'] = $lang->sprintf($lang->postbit_edited, $post['editdate'], $post['edittime']); 459 $post['editedprofilelink'] = build_profile_link($post['editusername'], $post['edituid']); 460 eval("\$post['editedmsg'] = \"".$templates->get("postbit_editedby")."\";"); 461 } 462 463 if((is_moderator($fid, "caneditposts") || ($forumpermissions['caneditposts'] == 1 && $mybb->user['uid'] == $post['uid'])) && $mybb->user['uid'] != 0) 464 { 465 eval("\$post['button_edit'] = \"".$templates->get("postbit_edit")."\";"); 466 } 467 468 // Quick Delete button 469 $can_delete = 0; 470 if($mybb->user['uid'] == $post['uid']) 471 { 472 if($forumpermissions['candeletethreads'] == 1 && $postcounter == 1) 473 { 474 $can_delete = 1; 475 } 476 else if($forumpermissions['candeleteposts'] == 1 && $postcounter != 1) 477 { 478 $can_delete = 1; 479 } 480 } 481 482 if((is_moderator($fid, "candeleteposts") || $can_delete == 1) && $mybb->user['uid'] != 0) 483 { 484 eval("\$post['button_quickdelete'] = \"".$templates->get("postbit_quickdelete")."\";"); 485 } 486 487 // Inline moderation stuff 488 if($ismod) 489 { 490 if(my_strpos($mybb->cookies[$inlinecookie], "|".$post['pid']."|")) 491 { 492 $inlinecheck = "checked=\"checked\""; 493 $inlinecount++; 494 } 495 else 496 { 497 $inlinecheck = ""; 498 } 499 500 eval("\$post['inlinecheck'] = \"".$templates->get("postbit_inlinecheck")."\";"); 501 502 if($post['visible'] == 0) 503 { 504 $invisiblepost = 1; 505 } 506 } 507 else 508 { 509 $post['inlinecheck'] = ""; 510 } 511 $post['postlink'] = get_post_link($post['pid'], $post['tid']); 512 eval("\$post['posturl'] = \"".$templates->get("postbit_posturl")."\";"); 513 global $forum, $thread; 514 515 if($forum['open'] != 0 && ($thread['closed'] != 1 || is_moderator($forum['fid']))) 516 { 517 eval("\$post['button_quote'] = \"".$templates->get("postbit_quote")."\";"); 518 } 519 520 if($forumpermissions['canpostreplys'] != 0 && ($thread['closed'] != 1 || is_moderator($fid)) && $mybb->settings['multiquote'] != 0 && $forum['open'] != 0 && !$post_type) 521 { 522 eval("\$post['button_multiquote'] = \"".$templates->get("postbit_multiquote")."\";"); 523 } 524 525 if($mybb->user['uid'] != "0") 526 { 527 eval("\$post['button_report'] = \"".$templates->get("postbit_report")."\";"); 528 } 529 530 if($mybb->settings['logip'] != "no") 531 { 532 if($mybb->settings['logip'] == "show") 533 { 534 eval("\$post['iplogged'] = \"".$templates->get("postbit_iplogged_show")."\";"); 535 } 536 else if($mybb->settings['logip'] == "hide" && is_moderator($fid, "canviewips")) 537 { 538 eval("\$post['iplogged'] = \"".$templates->get("postbit_iplogged_hiden")."\";"); 539 } 540 else 541 { 542 $post['iplogged'] = ""; 543 } 544 } 545 else 546 { 547 $post['iplogged'] = ""; 548 } 549 } 550 elseif($post_type == 3) // announcement 551 { 552 if($mybb->usergroup['issupermod'] == 1 || is_moderator($fid)) 553 { 554 eval("\$post['button_edit'] = \"".$templates->get("announcement_edit")."\";"); 555 eval("\$post['button_quickdelete'] = \"".$templates->get("announcement_quickdelete")."\";"); 556 } 557 } 558 559 if($post['smilieoff'] == 1) 560 { 561 $parser_options['allow_smilies'] = 0; 562 } 563 564 // If we have incoming search terms to highlight - get it done. 565 if($mybb->input['highlight']) 566 { 567 $parser_options['highlight'] = $mybb->input['highlight']; 568 $post['subject'] = $parser->highlight_message($post['subject'], $parser_options['highlight']); 569 } 570 571 $post['message'] = $parser->parse_message($post['message'], $parser_options); 572 573 get_post_attachments($id, $post); 574 575 if($post['includesig'] != 0 && $post['username'] && $post['signature'] != "" && ($mybb->user['uid'] == 0 || $mybb->user['showsigs'] != 0) && ($post['suspendsignature'] == 0 || $post['suspendsignature'] == 1 && $post['suspendsigtime'] != 0 && $post['suspendsigtime'] < TIME_NOW) && $usergroup['canusesig'] == 1 && ($usergroup['canusesigxposts'] == 0 || $usergroup['canusesigxposts'] > 0 && $postnum > $usergroup['canusesigxposts'])) 576 { 577 $sig_parser = array( 578 "allow_html" => $mybb->settings['sightml'], 579 "allow_mycode" => $mybb->settings['sigmycode'], 580 "allow_smilies" => $mybb->settings['sigsmilies'], 581 "allow_imgcode" => $mybb->settings['sigimgcode'], 582 "me_username" => $post['username'] 583 ); 584 585 if($usergroup['signofollow']) 586 { 587 $sig_parser['nofollow_on'] = 1; 588 } 589 590 $post['signature'] = $parser->parse_message($post['signature'], $sig_parser); 591 eval("\$post['signature'] = \"".$templates->get("postbit_signature")."\";"); 592 } 593 else 594 { 595 $post['signature'] = ""; 596 } 597 598 $icon_cache = $cache->read("posticons"); 599 600 if($post['icon'] > 0 && $icon_cache[$post['icon']]) 601 { 602 $icon = $icon_cache[$post['icon']]; 603 604 $icon['path'] = htmlspecialchars_uni($icon['path']); 605 $icon['name'] = htmlspecialchars_uni($icon['name']); 606 $post['icon'] = "<img src=\"{$icon['path']}\" alt=\"{$icon['name']}\" style=\"vertical-align: middle;\" /> "; 607 } 608 else 609 { 610 $post['icon'] = ""; 611 } 612 613 $post_visibility = ''; 614 switch($post_type) 615 { 616 case 1: // Message preview 617 $post = $plugins->run_hooks("postbit_prev", $post); 618 break; 619 case 2: // Private message 620 $post = $plugins->run_hooks("postbit_pm", $post); 621 break; 622 case 3: // Announcement 623 $post = $plugins->run_hooks("postbit_announcement", $post); 624 break; 625 default: // Regular post 626 $post = $plugins->run_hooks("postbit", $post); 627 628 // Is this author on the ignore list of the current user? Hide this post 629 if(is_array($ignored_users) && $post['uid'] != 0 && $ignored_users[$post['uid']] == 1) 630 { 631 $ignored_message = $lang->sprintf($lang->postbit_currently_ignoring_user, $post['username']); 632 eval("\$ignore_bit = \"".$templates->get("postbit_ignored")."\";"); 633 $post_visibility = "display: none;"; 634 } 635 break; 636 } 637 638 if($mybb->settings['postlayout'] == "classic") 639 { 640 eval("\$postbit = \"".$templates->get("postbit_classic")."\";"); 641 } 642 else 643 { 644 eval("\$postbit = \"".$templates->get("postbit")."\";"); 645 } 646 $GLOBALS['post'] = ""; 647 648 return $postbit; 649 } 650 651 /** 652 * Fetch the attachments for a specific post and parse inline [attachment=id] code. 653 * Note: assumes you have $attachcache, an array of attachments set up. 654 * 655 * @param int The ID of the item. 656 * @param array The post or item passed by reference. 657 */ 658 function get_post_attachments($id, &$post) 659 { 660 global $attachcache, $mybb, $theme, $templates, $forumpermissions, $lang; 661 662 $validationcount = 0; 663 $tcount = 0; 664 if(is_array($attachcache[$id])) 665 { // This post has 1 or more attachments 666 foreach($attachcache[$id] as $aid => $attachment) 667 { 668 if($attachment['visible']) 669 { // There is an attachment thats visible! 670 $attachment['filename'] = htmlspecialchars_uni($attachment['filename']); 671 $attachment['filesize'] = get_friendly_size($attachment['filesize']); 672 $ext = get_extension($attachment['filename']); 673 if($ext == "jpeg" || $ext == "gif" || $ext == "bmp" || $ext == "png" || $ext == "jpg") 674 { 675 $isimage = true; 676 } 677 else 678 { 679 $isimage = false; 680 } 681 $attachment['icon'] = get_attachment_icon($ext); 682 // Support for [attachment=id] code 683 if(stripos($post['message'], "[attachment=".$attachment['aid']."]") !== false) 684 { 685 // Show as thumbnail IF image is big && thumbnail exists && setting=='thumb' 686 // Show as full size image IF setting=='fullsize' || (image is small && permissions allow) 687 // Show as download for all other cases 688 if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != "" && $mybb->settings['attachthumbnails'] == "yes") 689 { 690 eval("\$attbit = \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";"); 691 } 692 elseif((($attachment['thumbnail'] == "SMALL" && $forumpermissions['candlattachments'] == 1) || $mybb->settings['attachthumbnails'] == "no") && $isimage) 693 { 694 eval("\$attbit = \"".$templates->get("postbit_attachments_images_image")."\";"); 695 } 696 else 697 { 698 eval("\$attbit = \"".$templates->get("postbit_attachments_attachment")."\";"); 699 } 700 $post['message'] = preg_replace("#\[attachment=".$attachment['aid']."]#si", $attbit, $post['message']); 701 } 702 else 703 { 704 // Show as thumbnail IF image is big && thumbnail exists && setting=='thumb' 705 // Show as full size image IF setting=='fullsize' || (image is small && permissions allow) 706 // Show as download for all other cases 707 if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != "" && $mybb->settings['attachthumbnails'] == "yes") 708 { 709 eval("\$post['thumblist'] .= \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";"); 710 if($tcount == 5) 711 { 712 $thumblist .= "<br />"; 713 $tcount = 0; 714 } 715 ++$tcount; 716 } 717 elseif((($attachment['thumbnail'] == "SMALL" && $forumpermissions['candlattachments'] == 1) || $mybb->settings['attachthumbnails'] == "no") && $isimage) 718 { 719 eval("\$post['imagelist'] .= \"".$templates->get("postbit_attachments_images_image")."\";"); 720 } 721 else 722 { 723 eval("\$post['attachmentlist'] .= \"".$templates->get("postbit_attachments_attachment")."\";"); 724 } 725 } 726 } 727 else 728 { 729 $validationcount++; 730 } 731 } 732 if($validationcount > 0 && is_moderator($post['fid'])) 733 { 734 if($validationcount == 1) 735 { 736 $postbit_unapproved_attachments = $lang->postbit_unapproved_attachment; 737 } 738 else 739 { 740 $postbit_unapproved_attachments = $lang->sprintf($lang->postbit_unapproved_attachments, $validationcount); 741 } 742 eval("\$post['attachmentlist'] .= \"".$templates->get("postbit_attachments_attachment_unapproved")."\";"); 743 } 744 if($post['thumblist']) 745 { 746 eval("\$post['attachedthumbs'] = \"".$templates->get("postbit_attachments_thumbnails")."\";"); 747 } 748 if($post['imagelist']) 749 { 750 eval("\$post['attachedimages'] = \"".$templates->get("postbit_attachments_images")."\";"); 751 } 752 if($post['attachmentlist'] || $post['thumblist'] || $post['imagelist']) 753 { 754 eval("\$post['attachments'] = \"".$templates->get("postbit_attachments")."\";"); 755 } 756 } 757 } 758 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Dec 11 14:16:27 2011 | Cross-referenced by PHPXref 0.7.1 |