[ Index ]

PHP Cross Reference of MyBB 1.8.39

title

Body

[close]

/inc/ -> functions_post.php (source)

   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'] = '&nbsp;';
 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                                  eval("\$post['fieldvalue_option'] .= \"".$templates->get("postbit_profilefield_multiselect_value")."\";");
 496                              }
 497                          }
 498                          if($post['fieldvalue_option'] != '')
 499                          {
 500                              eval("\$post['fieldvalue'] .= \"".$templates->get("postbit_profilefield_multiselect")."\";");
 501                          }
 502                      }
 503                      else
 504                      {
 505                          $field_parser_options = array(
 506                              "allow_html" => $field['allowhtml'],
 507                              "allow_mycode" => $field['allowmycode'],
 508                              "allow_smilies" => $field['allowsmilies'],
 509                              "allow_imgcode" => $field['allowimgcode'],
 510                              "allow_videocode" => $field['allowvideocode'],
 511                              #"nofollow_on" => 1,
 512                              "filter_badwords" => 1
 513                          );
 514  
 515                          if($field['type'] == "textarea")
 516                          {
 517                              $field_parser_options['me_username'] = $post['username'];
 518                          }
 519                          else
 520                          {
 521                              $field_parser_options['nl2br'] = 0;
 522                          }
 523  
 524                          if($mybb->user['uid'] != 0 && $mybb->user['showimages'] != 1 || $mybb->settings['guestimages'] != 1 && $mybb->user['uid'] == 0)
 525                          {
 526                              $field_parser_options['allow_imgcode'] = 0;
 527                          }
 528  
 529                          $post['fieldvalue'] = $parser->parse_message($post[$fieldfid], $field_parser_options);
 530                      }
 531  
 532                      eval("\$post['profilefield'] .= \"".$templates->get("postbit_profilefield")."\";");
 533                  }
 534              }
 535          }
 536  
 537          eval("\$post['user_details'] = \"".$templates->get("postbit_author_user")."\";");
 538      }
 539      else
 540      { // Message was posted by a guest or an unknown user
 541          $post['profilelink'] = format_name($post['username'], 1);
 542  
 543          if($usergroup['usertitle'])
 544          {
 545              $post['usertitle'] = $usergroup['usertitle'];
 546          }
 547          else
 548          {
 549              $post['usertitle'] = $lang->guest;
 550          }
 551  
 552          $post['usertitle'] = htmlspecialchars_uni($post['usertitle']);
 553          $post['userstars'] = '';
 554          $post['useravatar'] = '';
 555  
 556          $usergroup['title'] = $lang->na;
 557  
 558          $post['userregdate'] = $lang->na;
 559          $post['postnum'] = $lang->na;
 560          $post['button_profile'] = '';
 561          $post['button_email'] = '';
 562          $post['button_www'] = '';
 563          $post['signature'] = '';
 564          $post['button_pm'] = '';
 565          $post['button_find'] = '';
 566          $post['onlinestatus'] = '';
 567          $post['replink'] = '';
 568          eval("\$post['user_details'] = \"".$templates->get("postbit_author_guest")."\";");
 569      }
 570  
 571      $post['input_editreason'] = '';
 572      $post['button_edit'] = '';
 573      $post['button_quickdelete'] = '';
 574      $post['button_quickrestore'] = '';
 575      $post['button_quote'] = '';
 576      $post['button_quickquote'] = '';
 577      $post['button_report'] = '';
 578      $post['button_reply_pm'] = '';
 579      $post['button_replyall_pm'] = '';
 580      $post['button_forward_pm']  = '';
 581      $post['button_delete_pm'] = '';
 582  
 583      // For private messages, fetch the reply/forward/delete icons
 584      if($post_type == 2 && $post['pmid'])
 585      {
 586          global $replyall;
 587  
 588          eval("\$post['button_reply_pm'] = \"".$templates->get("postbit_reply_pm")."\";");
 589          eval("\$post['button_forward_pm'] = \"".$templates->get("postbit_forward_pm")."\";");
 590          eval("\$post['button_delete_pm'] = \"".$templates->get("postbit_delete_pm")."\";");
 591  
 592          if($replyall == true)
 593          {
 594              eval("\$post['button_replyall_pm'] = \"".$templates->get("postbit_replyall_pm")."\";");
 595          }
 596      }
 597  
 598      $post['editedmsg'] = '';
 599      if(!$post_type)
 600      {
 601          if(!isset($forumpermissions))
 602          {
 603              $forumpermissions = forum_permissions($fid);
 604          }
 605  
 606          // Figure out if we need to show an "edited by" message
 607          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'])))))
 608          {
 609              $post['editdate'] = my_date('relative', $post['edittime']);
 610              $post['editnote'] = $lang->sprintf($lang->postbit_edited, $post['editdate']);
 611              $post['editusername'] = htmlspecialchars_uni($post['editusername']);
 612              $post['editedprofilelink'] = build_profile_link($post['editusername'], $post['edituid']);
 613              $editreason = "";
 614              if($post['editreason'] != "")
 615              {
 616                  $post['editreason'] = $parser->parse_badwords($post['editreason']);
 617                  $post['editreason'] = htmlspecialchars_uni($post['editreason']);
 618                  eval("\$editreason = \"".$templates->get("postbit_editedby_editreason")."\";");
 619              }
 620              eval("\$post['editedmsg'] = \"".$templates->get("postbit_editedby")."\";");
 621          }
 622  
 623          $time = TIME_NOW;
 624          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)
 625          {
 626              eval("\$post['input_editreason'] = \"".$templates->get("postbit_editreason")."\";");
 627              eval("\$post['button_edit'] = \"".$templates->get("postbit_edit")."\";");
 628          }
 629  
 630          // Quick Delete button
 631          $can_delete_thread = $can_delete_post = 0;
 632          if($mybb->user['uid'] == $post['uid'] && $thread['closed'] == 0)
 633          {
 634              if($forumpermissions['candeletethreads'] == 1 && $postcounter == 1)
 635              {
 636                  $can_delete_thread = 1;
 637              }
 638              else if($forumpermissions['candeleteposts'] == 1 && $postcounter != 1)
 639              {
 640                  $can_delete_post = 1;
 641              }
 642          }
 643  
 644          $postbit_qdelete = $postbit_qrestore = '';
 645          if($mybb->user['uid'] != 0)
 646          {
 647              if((is_moderator($fid, "candeleteposts") || is_moderator($fid, "cansoftdeleteposts") || $can_delete_post == 1) && $postcounter != 1)
 648              {
 649                  $postbit_qdelete = $lang->postbit_qdelete_post;
 650                  $display = '';
 651                  if($post['visible'] == -1)
 652                  {
 653                      $display = "none";
 654                  }
 655                  eval("\$post['button_quickdelete'] = \"".$templates->get("postbit_quickdelete")."\";");
 656              }
 657              else if((is_moderator($fid, "candeletethreads") || is_moderator($fid, "cansoftdeletethreads") || $can_delete_thread == 1) && $postcounter == 1)
 658              {
 659                  $postbit_qdelete = $lang->postbit_qdelete_thread;
 660                  $display = '';
 661                  if($post['visible'] == -1)
 662                  {
 663                      $display = "none";
 664                  }
 665                  eval("\$post['button_quickdelete'] = \"".$templates->get("postbit_quickdelete")."\";");
 666              }
 667  
 668              // Restore Post
 669              if(is_moderator($fid, "canrestoreposts") && $postcounter != 1)
 670              {
 671                  $display = "none";
 672                  if($post['visible'] == -1)
 673                  {
 674                      $display = '';
 675                  }
 676                  $postbit_qrestore = $lang->postbit_qrestore_post;
 677                  eval("\$post['button_quickrestore'] = \"".$templates->get("postbit_quickrestore")."\";");
 678              }
 679  
 680              // Restore Thread
 681              else if(is_moderator($fid, "canrestorethreads") && $postcounter == 1)
 682              {
 683                  $display = "none";
 684                  if($post['visible'] == -1)
 685                  {
 686                      $display = "";
 687                  }
 688                  $postbit_qrestore = $lang->postbit_qrestore_thread;
 689                  eval("\$post['button_quickrestore'] = \"".$templates->get("postbit_quickrestore")."\";");
 690              }
 691          }
 692  
 693          if(!isset($ismod))
 694          {
 695              $ismod = is_moderator($fid);
 696          }
 697  
 698          // Inline moderation stuff
 699          if($ismod)
 700          {
 701              if(isset($mybb->cookies[$inlinecookie]) && my_strpos($mybb->cookies[$inlinecookie], "|".$post['pid']."|") !== false)
 702              {
 703                  $inlinecheck = "checked=\"checked\"";
 704                  $inlinecount++;
 705              }
 706              else
 707              {
 708                  $inlinecheck = "";
 709              }
 710  
 711              eval("\$post['inlinecheck'] = \"".$templates->get("postbit_inlinecheck")."\";");
 712  
 713              if($post['visible'] == 0)
 714              {
 715                  $invisiblepost = 1;
 716              }
 717          }
 718          else
 719          {
 720              $post['inlinecheck'] = "";
 721          }
 722          $post['postlink'] = get_post_link($post['pid'], $post['tid']);
 723          $post_number = my_number_format($postcounter);
 724          eval("\$post['posturl'] = \"".$templates->get("postbit_posturl")."\";");
 725          global $forum, $thread;
 726  
 727          if($forum['open'] != 0 && ($thread['closed'] != 1 || is_moderator($forum['fid'], "canpostclosedthreads")) && ($thread['uid'] == $mybb->user['uid'] || empty($forumpermissions['canonlyreplyownthreads'])))
 728          {
 729              eval("\$post['button_quote'] = \"".$templates->get("postbit_quote")."\";");
 730          }
 731  
 732          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)
 733          {
 734              eval("\$post['button_multiquote'] = \"".$templates->get("postbit_multiquote")."\";");
 735          }
 736  
 737          if(isset($post['reporters']))
 738          {
 739              $skip_report = my_unserialize($post['reporters']);
 740              if(is_array($skip_report))
 741              {
 742                  $skip_report[] = 0;
 743              }
 744              else
 745              {
 746                  $skip_report = array(0);
 747              }
 748          }
 749          else
 750          {
 751              $skip_report = array(0);
 752          }
 753  
 754          $reportable = user_permissions($post['uid']);
 755          if(!in_array($mybb->user['uid'], $skip_report) && !empty($reportable['canbereported']))
 756          {
 757              eval("\$post['button_report'] = \"".$templates->get("postbit_report")."\";");
 758          }
 759      }
 760      elseif($post_type == 3) // announcement
 761      {
 762          if($mybb->usergroup['canmodcp'] == 1 && $mybb->usergroup['canmanageannounce'] == 1 && is_moderator($fid, "canmanageannouncements"))
 763          {
 764              eval("\$post['button_edit'] = \"".$templates->get("announcement_edit")."\";");
 765              eval("\$post['button_quickdelete'] = \"".$templates->get("announcement_quickdelete")."\";");
 766          }
 767      }
 768  
 769      $post['iplogged'] = '';
 770      $show_ips = $mybb->settings['logip'];
 771      
 772      // Show post IP addresses... PMs now can have IP addresses too as of 1.8!
 773      if($post_type == 2)
 774      {
 775          $show_ips = $mybb->settings['showpmip'];
 776      }
 777      if(!$post_type || $post_type == 2)
 778      {
 779          if($show_ips != "no" && !empty($post['ipaddress']))
 780          {
 781              $ipaddress = my_inet_ntop($db->unescape_binary($post['ipaddress']));
 782  
 783              if($show_ips == "show")
 784              {
 785                  eval("\$post['iplogged'] = \"".$templates->get("postbit_iplogged_show")."\";");
 786              }
 787              else if($show_ips == "hide" && (is_moderator($fid, "canviewips") || $mybb->usergroup['issupermod']))
 788              {
 789                  $action = 'getip';
 790                  $javascript = 'getIP';
 791  
 792                  if($post_type == 2)
 793                  {
 794                      $action = 'getpmip';
 795                      $javascript = 'getPMIP';
 796                  }
 797  
 798                  eval("\$post['iplogged'] = \"".$templates->get("postbit_iplogged_hiden")."\";");
 799              }
 800          }
 801      }
 802  
 803      $post['poststatus'] = '';
 804      if(!$post_type && $post['visible'] != 1)
 805      {
 806          $status_type = '';
 807          if(is_moderator($fid, "canviewdeleted") && $postcounter != 1 && $post['visible'] == -1)
 808          {
 809              $status_type = $lang->postbit_post_deleted;
 810          }
 811          else if(is_moderator($fid, "canviewunapprove") && $postcounter != 1 && $post['visible'] == 0)
 812          {
 813              $status_type = $lang->postbit_post_unapproved;
 814          }
 815          else if(is_moderator($fid, "canviewdeleted") && $postcounter == 1 && $post['visible'] == -1)
 816          {
 817              $status_type = $lang->postbit_thread_deleted;
 818          }
 819          else if(is_moderator($fid, "canviewunapprove") && $postcounter == 1 && $post['visible'] == 0)
 820          {
 821              $status_type = $lang->postbit_thread_unapproved;
 822          }
 823  
 824          eval("\$post['poststatus'] = \"".$templates->get("postbit_status")."\";");
 825      }
 826  
 827      if(isset($post['smilieoff']) && $post['smilieoff'] == 1)
 828      {
 829          $parser_options['allow_smilies'] = 0;
 830      }
 831  
 832      if($mybb->user['uid'] != 0 && $mybb->user['showimages'] != 1 || $mybb->settings['guestimages'] != 1 && $mybb->user['uid'] == 0)
 833      {
 834          $parser_options['allow_imgcode'] = 0;
 835      }
 836  
 837      if($mybb->user['uid'] != 0 && $mybb->user['showvideos'] != 1 || $mybb->settings['guestvideos'] != 1 && $mybb->user['uid'] == 0)
 838      {
 839          $parser_options['allow_videocode'] = 0;
 840      }
 841  
 842      // If we have incoming search terms to highlight - get it done.
 843      if(!empty($mybb->input['highlight']))
 844      {
 845          $parser_options['highlight'] = $mybb->input['highlight'];
 846          $post['subject'] = $parser->highlight_message($post['subject'], $parser_options['highlight']);
 847      }
 848  
 849      $post['message'] = $parser->parse_message($post['message'], $parser_options);
 850  
 851      $post['attachments'] = '';
 852      if($mybb->settings['enableattachments'] != 0)
 853      {
 854          get_post_attachments($id, $post);
 855      }
 856  
 857      if(isset($post['includesig']) && $post['includesig'] != 0 && $post['username'] && $post['signature'] != "" && ($mybb->user['uid'] == 0 || $mybb->user['showsigs'] != 0)
 858      && ($post['suspendsignature'] == 0 || $post['suspendsignature'] == 1 && $post['suspendsigtime'] != 0 && $post['suspendsigtime'] < TIME_NOW) && $usergroup['canusesig'] == 1
 859      && ($usergroup['canusesigxposts'] == 0 || $usergroup['canusesigxposts'] > 0 && $postnum > $usergroup['canusesigxposts']) && !is_member($mybb->settings['hidesignatures']))
 860      {
 861          $sig_parser = array(
 862              "allow_html" => $mybb->settings['sightml'],
 863              "allow_mycode" => $mybb->settings['sigmycode'],
 864              "allow_smilies" => $mybb->settings['sigsmilies'],
 865              "allow_imgcode" => $mybb->settings['sigimgcode'],
 866              "me_username" => $parser_options['me_username'],
 867              "filter_badwords" => 1
 868          );
 869  
 870          if($usergroup['signofollow'])
 871          {
 872              $sig_parser['nofollow_on'] = 1;
 873          }
 874  
 875          if($mybb->user['uid'] != 0 && $mybb->user['showimages'] != 1 || $mybb->settings['guestimages'] != 1 && $mybb->user['uid'] == 0)
 876          {
 877              $sig_parser['allow_imgcode'] = 0;
 878          }
 879  
 880          $post['signature'] = $parser->parse_message($post['signature'], $sig_parser);
 881          eval("\$post['signature'] = \"".$templates->get("postbit_signature")."\";");
 882      }
 883      else
 884      {
 885          $post['signature'] = "";
 886      }
 887  
 888      $icon_cache = $cache->read("posticons");
 889  
 890      if(isset($post['icon']) && $post['icon'] > 0 && $icon_cache[$post['icon']])
 891      {
 892          $icon = $icon_cache[$post['icon']];
 893  
 894          $icon['path'] = htmlspecialchars_uni($icon['path']);
 895          $icon['path'] = str_replace("{theme}", $theme['imgdir'], $icon['path']);
 896          $icon['name'] = htmlspecialchars_uni($icon['name']);
 897          eval("\$post['icon'] = \"".$templates->get("postbit_icon")."\";");
 898      }
 899      else
 900      {
 901          $post['icon'] = "";
 902      }
 903  
 904      $post_visibility = $ignore_bit = $deleted_bit = '';
 905      switch($post_type)
 906      {
 907          case 1: // Message preview
 908              $post = $plugins->run_hooks("postbit_prev", $post);
 909              break;
 910          case 2: // Private message
 911              $post = $plugins->run_hooks("postbit_pm", $post);
 912              break;
 913          case 3: // Announcement
 914              $post = $plugins->run_hooks("postbit_announcement", $post);
 915              break;
 916          default: // Regular post
 917              $post = $plugins->run_hooks("postbit", $post);
 918  
 919              if(!isset($ignored_users))
 920              {
 921                  $ignored_users = array();
 922                  if($mybb->user['uid'] > 0 && $mybb->user['ignorelist'] != "")
 923                  {
 924                      $ignore_list = explode(',', $mybb->user['ignorelist']);
 925                      foreach($ignore_list as $uid)
 926                      {
 927                          $ignored_users[$uid] = 1;
 928                      }
 929                  }
 930              }
 931  
 932              // Has this post been deleted but can be viewed? Hide this post
 933              if($post['visible'] == -1 && is_moderator($fid, "canviewdeleted"))
 934              {
 935                  $deleted_message = $lang->sprintf($lang->postbit_deleted_post_user, $post['username']);
 936                  eval("\$deleted_bit = \"".$templates->get("postbit_deleted")."\";");
 937                  $post_visibility = "display: none;";
 938              }
 939  
 940              // Is the user (not moderator) logged in and have unapproved posts?
 941              if($mybb->user['uid'] && $post['visible'] == 0 && $post['uid'] == $mybb->user['uid'] && !is_moderator($fid, "canviewunapprove"))
 942              {
 943                  $ignored_message = $lang->sprintf($lang->postbit_post_under_moderation, $post['username']);
 944                  eval("\$ignore_bit = \"".$templates->get("postbit_ignored")."\";");
 945                  $post_visibility = "display: none;";
 946              }
 947  
 948              // Is this author on the ignore list of the current user? Hide this post
 949              if(is_array($ignored_users) && $post['uid'] != 0 && isset($ignored_users[$post['uid']]) && $ignored_users[$post['uid']] == 1 && empty($deleted_bit))
 950              {
 951                  $ignored_message = $lang->sprintf($lang->postbit_currently_ignoring_user, $post['username']);
 952                  eval("\$ignore_bit = \"".$templates->get("postbit_ignored")."\";");
 953                  $post_visibility = "display: none;";
 954              }
 955              break;
 956      }
 957  
 958      if($post_type == 0 && $forumpermissions['canviewdeletionnotice'] == 1 && $post['visible'] == -1 && !is_moderator($fid, "canviewdeleted"))
 959      {
 960          eval("\$postbit = \"".$templates->get("postbit_deleted_member")."\";");
 961      }
 962      else
 963      {
 964          if($mybb->settings['postlayout'] == "classic")
 965          {
 966              eval("\$postbit = \"".$templates->get("postbit_classic")."\";");
 967          }
 968          else
 969          {
 970              eval("\$postbit = \"".$templates->get("postbit")."\";");
 971          }
 972      }
 973  
 974      $GLOBALS['post'] = "";
 975  
 976      return $postbit;
 977  }
 978  
 979  /**
 980   * Fetch the attachments for a specific post and parse inline [attachment=id] code.
 981   * Note: assumes you have $attachcache, an array of attachments set up.
 982   *
 983   * @param int $id The ID of the item.
 984   * @param array $post The post or item passed by reference.
 985   */
 986  function get_post_attachments($id, &$post)
 987  {
 988      global $attachcache, $mybb, $theme, $templates, $forumpermissions, $lang;
 989  
 990      $validationcount = 0;
 991      $tcount = 0;
 992      $post['attachmentlist'] = $post['thumblist'] = $post['imagelist'] = '';
 993      if(!isset($forumpermissions))
 994      {
 995          $forumpermissions = forum_permissions($post['fid']);
 996      }
 997  
 998      if(isset($attachcache[$id]) && is_array($attachcache[$id]))
 999      { // This post has 1 or more attachments
1000          foreach($attachcache[$id] as $aid => $attachment)
1001          {
1002              if($attachment['visible'])
1003              { // There is an attachment thats visible!
1004                  $attachment['filename'] = htmlspecialchars_uni($attachment['filename']);
1005                  $attachment['filesize'] = get_friendly_size($attachment['filesize']);
1006                  $ext = get_extension($attachment['filename']);
1007                  if($ext == "jpeg" || $ext == "gif" || $ext == "bmp" || $ext == "png" || $ext == "jpg")
1008                  {
1009                      $isimage = true;
1010                  }
1011                  else
1012                  {
1013                      $isimage = false;
1014                  }
1015                  $attachment['icon'] = get_attachment_icon($ext);
1016                  $attachment['downloads'] = my_number_format($attachment['downloads']);
1017  
1018                  if(!$attachment['dateuploaded'])
1019                  {
1020                      $attachment['dateuploaded'] = $post['dateline'];
1021                  }
1022                  $attachdate = my_date('normal', $attachment['dateuploaded']);
1023                  // Support for [attachment=id] code
1024                  if(stripos($post['message'], "[attachment=".$attachment['aid']."]") !== false)
1025                  {
1026                      // Show as thumbnail IF image is big && thumbnail exists && setting=='thumb'
1027                      // Show as full size image IF setting=='fullsize' || (image is small && permissions allow)
1028                      // Show as download for all other cases
1029                      if($attachment['thumbnail'] != "SMALL" && $attachment['thumbnail'] != "" && $mybb->settings['attachthumbnails'] == "yes")
1030                      {
1031                          eval("\$attbit = \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
1032                      }
1033                      elseif((($attachment['thumbnail'] == "SMALL" && $forumpermissions['candlattachments'] == 1) || $mybb->settings['attachthumbnails'] == "no") && $isimage)
1034                      {
1035                          eval("\$attbit = \"".$templates->get("postbit_attachments_images_image")."\";");
1036                      }
1037                      else
1038                      {
1039                          eval("\$attbit = \"".$templates->get("postbit_attachments_attachment")."\";");
1040                      }
1041                      $post['message'] = preg_replace("#\[attachment=".$attachment['aid']."]#si", $attbit, $post['message']);
1042                  }
1043                  else
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("\$post['thumblist'] .= \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
1051                          if($tcount == 5)
1052                          {
1053                              $post['thumblist'] .= "<br />";
1054                              $tcount = 0;
1055                          }
1056                          ++$tcount;
1057                      }
1058                      elseif((($attachment['thumbnail'] == "SMALL" && $forumpermissions['candlattachments'] == 1) || $mybb->settings['attachthumbnails'] == "no") && $isimage)
1059                      {
1060                          if ($forumpermissions['candlattachments'])
1061                          {
1062                              eval("\$post['imagelist'] .= \"".$templates->get("postbit_attachments_images_image")."\";");
1063                          } 
1064                          else 
1065                          {
1066                              eval("\$post['thumblist'] .= \"".$templates->get("postbit_attachments_thumbnails_thumbnail")."\";");
1067                              if($tcount == 5)
1068                              {
1069                                  $post['thumblist'] .= "<br />";
1070                                  $tcount = 0;
1071                              }
1072                              ++$tcount;
1073                          }
1074                      }
1075                      else
1076                      {
1077                          eval("\$post['attachmentlist'] .= \"".$templates->get("postbit_attachments_attachment")."\";");
1078                      }
1079                  }
1080              }
1081              else
1082              {
1083                  $validationcount++;
1084              }
1085          }
1086          if($validationcount > 0 && is_moderator($post['fid'], "canviewunapprove"))
1087          {
1088              if($validationcount == 1)
1089              {
1090                  $postbit_unapproved_attachments = $lang->postbit_unapproved_attachment;
1091              }
1092              else
1093              {
1094                  $postbit_unapproved_attachments = $lang->sprintf($lang->postbit_unapproved_attachments, $validationcount);
1095              }
1096              eval("\$post['attachmentlist'] .= \"".$templates->get("postbit_attachments_attachment_unapproved")."\";");
1097          }
1098          if($post['thumblist'])
1099          {
1100              eval("\$post['attachedthumbs'] = \"".$templates->get("postbit_attachments_thumbnails")."\";");
1101          }
1102          else
1103          {
1104              $post['attachedthumbs'] = '';
1105          }
1106          if($post['imagelist'])
1107          {
1108              eval("\$post['attachedimages'] = \"".$templates->get("postbit_attachments_images")."\";");
1109          }
1110          else
1111          {
1112              $post['attachedimages'] = '';
1113          }
1114          if($post['attachmentlist'] || $post['thumblist'] || $post['imagelist'])
1115          {
1116              eval("\$post['attachments'] = \"".$templates->get("postbit_attachments")."\";");
1117          }
1118      }
1119  }
1120  
1121  /**
1122   * Returns bytes count from human readable string
1123   * Used to parse ini_get human-readable values to int
1124   *
1125   * @param string $val Human-readable value
1126   */
1127  function return_bytes($val) {
1128      $val = trim($val);
1129      if ($val == "")
1130      {
1131          return 0;
1132      }
1133  
1134      $last = strtolower($val[strlen($val)-1]);
1135  
1136      $val = intval($val);
1137  
1138      switch($last)
1139      {
1140          case 'g':
1141              $val *= 1024;
1142          case 'm':
1143              $val *= 1024;
1144          case 'k':
1145              $val *= 1024;
1146      }
1147  
1148      return $val;
1149  }
1150  
1151  /**
1152   * Detects whether an attachment removal/approval/unapproval
1153   * submit button was pressed (without triggering an AJAX request)
1154   * and sets inputs accordingly (as for an AJAX request).
1155   */
1156  function detect_attachmentact()
1157  {
1158      global $mybb;
1159  
1160      foreach($mybb->input as $key => $val)
1161      {
1162          if(strpos($key, 'rem_') === 0)
1163          {
1164              $mybb->input['attachmentaid'] = (int)substr($key, 4);
1165              $mybb->input['attachmentact'] = 'remove';
1166              break;
1167          }
1168          elseif(strpos($key, 'approveattach_') === 0)
1169          {
1170              $mybb->input['attachmentaid'] = (int)substr($key, 14);
1171              $mybb->input['attachmentact'] = 'approve';
1172              break;
1173          }
1174          elseif(strpos($key, 'unapproveattach_') === 0)
1175          {
1176              $mybb->input['attachmentaid'] = (int)substr($key, 16);
1177              $mybb->input['attachmentact'] = 'unapprove';
1178              break;
1179          }
1180      }
1181  }


2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup Cross-referenced by PHPXref