[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/inc/ -> functions_post.php (source)

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


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1