[ Index ]

PHP Cross Reference of MyBB 1.8.30

title

Body

[close]

/inc/ -> functions_forumlist.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 list of forum bits.
  13  *
  14  * @param int $pid The parent forum to fetch the child forums for (0 assumes all)
  15  * @param int $depth The depth to return forums with.
  16  * @return array Array of information regarding the child forums of this parent forum
  17  */
  18  function build_forumbits($pid=0, $depth=1)
  19  {
  20      global $db, $fcache, $moderatorcache, $forumpermissions, $theme, $mybb, $templates, $bgcolor, $collapsed, $lang, $showdepth, $plugins, $parser, $forum_viewers;
  21      static $private_forums;
  22  
  23      $forum_listing = '';
  24  
  25      // If no forums exist with this parent, do nothing
  26      if(empty($fcache[$pid]) || !is_array($fcache[$pid]))
  27      {
  28          return;
  29      }
  30  
  31      $parent_counters['threads'] = 0;
  32      $parent_counters['posts'] = 0;
  33      $parent_counters['unapprovedposts'] = 0;
  34      $parent_counters['unapprovedthreads'] = 0;
  35      $parent_counters['viewers'] = 0;
  36      $forum_list = $comma = '';
  37      $donecount = 0;
  38  
  39      // Foreach of the forums in this parent
  40      foreach($fcache[$pid] as $parent)
  41      {
  42          foreach($parent as $forum)
  43          {
  44              $forum['viewers'] = 0;
  45              $subforums = $sub_forums = '';
  46              $lastpost_data = array(
  47                  'lastpost' => 0,
  48                  'lastposter' => '',
  49              );
  50              $forum_viewers_text = '';
  51              $forum_viewers_text_plain = '';
  52  
  53              // Get the permissions for this forum
  54              $permissions = $forumpermissions[$forum['fid']];
  55  
  56              // If this user doesnt have permission to view this forum and we're hiding private forums, skip this forum
  57              if($permissions['canview'] != 1 && $mybb->settings['hideprivateforums'] == 1)
  58              {
  59                  continue;
  60              }
  61  
  62              $forum = $plugins->run_hooks("build_forumbits_forum", $forum);
  63  
  64              // Build the link to this forum
  65              $forum_url = get_forum_link($forum['fid']);
  66  
  67              $hideinfo = $hidecounters = false;
  68              $hidelastpostinfo = false;
  69              $showlockicon = 0;
  70  
  71              // Hide post info if user cannot view forum or cannot view threads
  72              if($permissions['canview'] != 1 || (isset($permissions['canviewthreads']) && $permissions['canviewthreads'] != 1))
  73              {
  74                  $hideinfo = true;
  75              }
  76  
  77              if(isset($permissions['canonlyviewownthreads']) && $permissions['canonlyviewownthreads'] == 1)
  78              {
  79                  $hidecounters = true;
  80  
  81                  // If we only see our own threads, find out if there's a new post in one of them so the lightbulb shows
  82                  if(!is_array($private_forums))
  83                  {
  84                      $private_forums = $fids = array();
  85                      foreach($fcache as $fcache_p)
  86                      {
  87                          foreach($fcache_p as $parent_p)
  88                          {
  89                              foreach($parent_p as $forum_p)
  90                              {
  91                                  if($forumpermissions[$forum_p['fid']]['canonlyviewownthreads'])
  92                                  {
  93                                      $fids[] = $forum_p['fid'];
  94                                  }
  95                              }
  96                          }
  97                      }
  98  
  99                      if(!empty($fids))
 100                      {
 101                          $fids = implode(',', $fids);
 102                          $query = $db->simple_select("threads", "tid, fid, subject, lastpost, lastposter, lastposteruid", "uid = '{$mybb->user['uid']}' AND fid IN ({$fids}) AND visible != '-2'", array("order_by" => "lastpost", "order_dir" => "desc"));
 103  
 104                          while($thread = $db->fetch_array($query))
 105                          {
 106                              if(!$private_forums[$thread['fid']])
 107                              {
 108                                  $private_forums[$thread['fid']] = $thread;
 109                              }
 110                          }
 111                      }
 112                  }
 113  
 114                  if(!empty($private_forums[$forum['fid']]['lastpost']))
 115                  {
 116                      $forum['lastpost'] = $private_forums[$forum['fid']]['lastpost'];
 117  
 118                      if(!$private_forums[$forum['fid']]['lastposteruid'] && !$private_forums[$forum['fid']]['lastposter'])
 119                      {
 120                          $private_forums[$forum['fid']]['lastposter'] = $lang->guest; // htmlspecialchars_uni'd when formatted later
 121                      }
 122  
 123                      $lastpost_data = array(
 124                          "lastpost" => $private_forums[$forum['fid']]['lastpost'],
 125                          "lastpostsubject" => $private_forums[$forum['fid']]['subject'],
 126                          "lastposter" => $private_forums[$forum['fid']]['lastposter'],
 127                          "lastposttid" => $private_forums[$forum['fid']]['tid'],
 128                          "lastposteruid" => $private_forums[$forum['fid']]['lastposteruid']
 129                      );
 130                  }
 131              }
 132              else
 133              {
 134                  if(!$forum['lastposteruid'] && !$forum['lastposter'])
 135                  {
 136                      $forum['lastposter'] = $lang->guest; // htmlspecialchars_uni'd when formatted later
 137                  }
 138  
 139                  $lastpost_data = array(
 140                      "lastpost" => $forum['lastpost'],
 141                      "lastpostsubject" => $forum['lastpostsubject'],
 142                      "lastposter" => $forum['lastposter'],
 143                      "lastposttid" => $forum['lastposttid'],
 144                      "lastposteruid" => $forum['lastposteruid']
 145                  );
 146              }
 147  
 148              // This forum has a password, and the user isn't authenticated with it - hide post information
 149              if(!forum_password_validated($forum, true))
 150              {
 151                  $hideinfo = true;
 152                  $showlockicon = 1;
 153              }
 154  
 155              if(is_array($forum_viewers) && isset($forum_viewers[$forum['fid']]) && $forum_viewers[$forum['fid']] > 0)
 156              {
 157                  $forum['viewers'] = $forum_viewers[$forum['fid']];
 158              }
 159  
 160              // Fetch subforums of this forum
 161              if(isset($fcache[$forum['fid']]))
 162              {
 163                  $forum_info = build_forumbits($forum['fid'], $depth+1);
 164  
 165                  // Increment forum counters with counters from child forums
 166                  $forum['threads'] += $forum_info['counters']['threads'];
 167                  $forum['posts'] += $forum_info['counters']['posts'];
 168                  $forum['unapprovedthreads'] += $forum_info['counters']['unapprovedthreads'];
 169                  $forum['unapprovedposts'] += $forum_info['counters']['unapprovedposts'];
 170  
 171                  if(!empty($forum_info['counters']['viewers']))
 172                  {
 173                      $forum['viewers'] += $forum_info['counters']['viewers'];
 174                  }
 175  
 176                  // If the child forums' lastpost is greater than the one for this forum, set it as the child forums greatest.
 177                  if(isset($forum_info['lastpost']['lastpost']) && $forum_info['lastpost']['lastpost'] > $lastpost_data['lastpost'])
 178                  {
 179                      $lastpost_data = $forum_info['lastpost'];
 180  
 181                      /*
 182                      // If our subforum is unread, then so must be our parents. Force our parents to unread as well
 183                      if(strstr($forum_info['lightbulb']['folder'], "on") !== false)
 184                      {
 185                          $forum['lastread'] = 0;
 186                      }
 187                      // Otherwise, if we  have an explicit record in the db, we must make sure that it is explicitly set
 188                      else
 189                      {
 190                          $lastpost_data['lastpost'] = $forum['lastpost'];
 191                      }*/
 192                  }
 193  
 194                  $sub_forums = $forum_info['forum_list'];
 195              }
 196  
 197              // If we are hiding information (lastpost) because we aren't authenticated against the password for this forum, remove them
 198              if($hideinfo == true || $hidelastpostinfo == true)
 199              {
 200                  // Used later for get_forum_lightbulb function call - Setting to 0 prevents the bulb from being lit up
 201                  // If hiding info or hiding lastpost info no "unread" posts indication should be shown to the user.
 202                  $lastpost_data = array(
 203                      'lastpost' => 0,
 204                      'lastposter' => '',
 205                  );
 206              }
 207  
 208              // If the current forums lastpost is greater than other child forums of the current parent and forum info isn't hidden, overwrite it
 209              if((!isset($parent_lastpost) || $lastpost_data['lastpost'] > $parent_lastpost['lastpost']) && $hideinfo != true)
 210              {
 211                  $parent_lastpost = $lastpost_data;
 212              }
 213  
 214              // Increment the counters for the parent forum (returned later)
 215              if($hideinfo != true && $hidecounters != true)
 216              {
 217                  $parent_counters['threads'] += $forum['threads'];
 218                  $parent_counters['posts'] += $forum['posts'];
 219                  $parent_counters['unapprovedposts'] += $forum['unapprovedposts'];
 220                  $parent_counters['unapprovedthreads'] += $forum['unapprovedthreads'];
 221  
 222                  if(!empty($forum['viewers']))
 223                  {
 224                      $parent_counters['viewers'] += $forum['viewers'];
 225                  }
 226              }
 227  
 228              // Done with our math, lets talk about displaying - only display forums which are under a certain depth
 229              if($depth > $showdepth)
 230              {
 231                  continue;
 232              }
 233  
 234              // Get the lightbulb status indicator for this forum based on the lastpost
 235              $lightbulb = get_forum_lightbulb($forum, $lastpost_data, $showlockicon);
 236  
 237              // Fetch the number of unapproved threads and posts for this forum
 238              if($hideinfo == true)
 239              {
 240                  $unapproved = array(
 241                      "unapproved_posts" => '',
 242                      "unapproved_threads" => '',
 243                  );
 244              }
 245              else
 246              {
 247                  $unapproved = get_forum_unapproved($forum);
 248              }
 249  
 250              // Sanitize name and description of forum.
 251              $forum['name'] = preg_replace("#&(?!\#[0-9]+;)#si", "&amp;", $forum['name']); // Fix & but allow unicode
 252              $forum['description'] = preg_replace("#&(?!\#[0-9]+;)#si", "&amp;", $forum['description']); // Fix & but allow unicode
 253              $forum['name'] = preg_replace("#&([^\#])(?![a-z1-4]{1,10};)#i", "&#038;$1", $forum['name']);
 254              $forum['description'] = preg_replace("#&([^\#])(?![a-z1-4]{1,10};)#i", "&#038;$1", $forum['description']);
 255  
 256              // If this is a forum and we've got subforums of it, load the subforums list template
 257              if($depth == 2 && $sub_forums)
 258              {
 259                  eval("\$subforums = \"".$templates->get("forumbit_subforums")."\";");
 260              }
 261              // A depth of three indicates a comma separated list of forums within a forum
 262              else if($depth == 3)
 263              {
 264                  if($donecount < $mybb->settings['subforumsindex'])
 265                  {
 266                      $statusicon = '';
 267  
 268                      // Showing mini status icons for this forum
 269                      if($mybb->settings['subforumsstatusicons'] == 1)
 270                      {
 271                          $lightbulb['folder'] = "mini".$lightbulb['folder'];
 272                          eval("\$statusicon = \"".$templates->get("forumbit_depth3_statusicon", 1, 0)."\";");
 273                      }
 274  
 275                      // Fetch the template and append it to the list
 276                      eval("\$forum_list .= \"".$templates->get("forumbit_depth3", 1, 0)."\";");
 277                      $comma = $lang->comma;
 278                  }
 279  
 280                  // Have we reached our max visible subforums? put a nice message and break out of the loop
 281                  ++$donecount;
 282                  if($donecount == $mybb->settings['subforumsindex'])
 283                  {
 284                      if(subforums_count($fcache[$pid]) > $donecount)
 285                      {
 286                          $forum_list .= $comma.$lang->sprintf($lang->more_subforums, (subforums_count($fcache[$pid]) - $donecount));
 287                      }
 288                  }
 289                  continue;
 290              }
 291  
 292              // Forum is a category, set template type
 293              if($forum['type'] == 'c')
 294              {
 295                  $forumcat = '_cat';
 296              }
 297              // Forum is a standard forum, set template type
 298              else
 299              {
 300                  $forumcat = '_forum';
 301              }
 302  
 303              if($forum['linkto'] == '')
 304              {
 305                  // No posts have been made in this forum - show never text
 306                  if($lastpost_data['lastpost'] == 0 && $hideinfo != true)
 307                  {
 308                      eval("\$lastpost = \"".$templates->get("forumbit_depth2_forum_lastpost_never")."\";");
 309                  }
 310                  elseif($hideinfo != true)
 311                  {
 312                      // Format lastpost date and time
 313                      $lastpost_date = my_date('relative', $lastpost_data['lastpost']);
 314  
 315                      // Set up the last poster, last post thread id, last post subject and format appropriately
 316                      $lastpost_data['lastposter'] = htmlspecialchars_uni($lastpost_data['lastposter']);
 317                      $lastpost_profilelink = build_profile_link($lastpost_data['lastposter'], $lastpost_data['lastposteruid']);
 318                      $lastpost_link = get_thread_link($lastpost_data['lastposttid'], 0, "lastpost");
 319                      $lastpost_subject = $full_lastpost_subject = $parser->parse_badwords($lastpost_data['lastpostsubject']);
 320                      if(my_strlen($lastpost_subject) > 25)
 321                      {
 322                          $lastpost_subject = my_substr($lastpost_subject, 0, 25)."...";
 323                      }
 324                      $lastpost_subject = htmlspecialchars_uni($lastpost_subject);
 325                      $full_lastpost_subject = htmlspecialchars_uni($full_lastpost_subject);
 326  
 327                      // Call lastpost template
 328                      if($depth != 1)
 329                      {
 330                          eval("\$lastpost = \"".$templates->get("forumbit_depth{$depth}_forum_lastpost")."\";");
 331                      }
 332                  }
 333  
 334                  if($mybb->settings['showforumviewing'] != 0 && $forum['viewers'] > 0)
 335                  {
 336                      if($forum['viewers'] == 1)
 337                      {
 338                          $forum_viewers_text = $lang->viewing_one;
 339                      }
 340                      else
 341                      {
 342                          $forum_viewers_text = $lang->sprintf($lang->viewing_multiple, $forum['viewers']);
 343                      }
 344                      $forum_viewers_text_plain = $forum_viewers_text;
 345                      eval("\$forum_viewers_text = \"".$templates->get("forumbit_depth2_forum_viewers")."\";");
 346                  }
 347              }
 348              // If this forum is a link or is password protected and the user isn't authenticated, set counters to "-"
 349              if($forum['linkto'] != '' || $hideinfo == true || $hidecounters == true)
 350              {
 351                  $posts = "-";
 352                  $threads = "-";
 353              }
 354              // Otherwise, format thread and post counts
 355              else
 356              {
 357                  $posts = my_number_format($forum['posts']);
 358                  $threads = my_number_format($forum['threads']);
 359              }
 360  
 361              // If this forum is a link or is password protected and the user isn't authenticated, set lastpost to "-"
 362              if($forum['linkto'] != '' || $hideinfo == true || $hidelastpostinfo == true)
 363              {
 364                  eval("\$lastpost = \"".$templates->get("forumbit_depth2_forum_lastpost_hidden")."\";");
 365              }
 366  
 367              // Moderator column is not off
 368              if($mybb->settings['modlist'] != 0)
 369              {
 370                  $done_moderators = array(
 371                      "users" => array(),
 372                      "groups" => array()
 373                  );
 374                  $moderators = '';
 375                  // Fetch list of moderators from this forum and its parents
 376                  $parentlistexploded = explode(',', $forum['parentlist']);
 377                  foreach($parentlistexploded as $mfid)
 378                  {
 379                      // This forum has moderators
 380                      if(isset($moderatorcache[$mfid]) && is_array($moderatorcache[$mfid]))
 381                      {
 382                          // Fetch each moderator from the cache and format it, appending it to the list
 383                          foreach($moderatorcache[$mfid] as $modtype)
 384                          {
 385                              foreach($modtype as $moderator)
 386                              {
 387                                  if($moderator['isgroup'])
 388                                  {
 389                                      if(in_array($moderator['id'], $done_moderators['groups']))
 390                                      {
 391                                          continue;
 392                                      }
 393  
 394                                      $moderator['title'] = htmlspecialchars_uni($moderator['title']);
 395  
 396                                      eval("\$moderators .= \"".$templates->get("forumbit_moderators_group", 1, 0)."\";");
 397                                      $done_moderators['groups'][] = $moderator['id'];
 398                                  }
 399                                  else
 400                                  {
 401                                      if(in_array($moderator['id'], $done_moderators['users']))
 402                                      {
 403                                          continue;
 404                                      }
 405  
 406                                      $moderator['profilelink'] = get_profile_link($moderator['id']);
 407                                      $moderator['username'] = htmlspecialchars_uni($moderator['username']);
 408  
 409                                      eval("\$moderators .= \"".$templates->get("forumbit_moderators_user", 1, 0)."\";");
 410                                      $done_moderators['users'][] = $moderator['id'];
 411                                  }
 412                                  $comma = $lang->comma;
 413                              }
 414                          }
 415                      }
 416                  }
 417                  $comma = '';
 418  
 419                  // If we have a moderators list, load the template
 420                  if($moderators)
 421                  {
 422                      eval("\$modlist = \"".$templates->get("forumbit_moderators")."\";");
 423                  }
 424                  else
 425                  {
 426                      $modlist = '';
 427                  }
 428              }
 429  
 430              // Descriptions aren't being shown - blank them
 431              if($mybb->settings['showdescriptions'] == 0)
 432              {
 433                  $forum['description'] = '';
 434              }
 435  
 436              // Check if this category is either expanded or collapsed and hide it as necessary.
 437              $expdisplay = '';
 438              $collapsed_name = "cat_{$forum['fid']}_e";
 439              if(isset($collapsed[$collapsed_name]) && $collapsed[$collapsed_name] == "display: none;")
 440              {
 441                  $expcolimage = "collapse_collapsed.png";
 442                  $expdisplay = "display: none;";
 443                  $expthead = " thead_collapsed";
 444                  $expaltext = $lang->expcol_expand;
 445              }
 446              else
 447              {
 448                  $expcolimage = "collapse.png";
 449                  $expthead = "";
 450                  $expaltext = $lang->expcol_collapse;
 451              }
 452  
 453              // Swap over the alternate backgrounds
 454              $bgcolor = alt_trow();
 455  
 456              // Add the forum to the list
 457              eval("\$forum_list .= \"".$templates->get("forumbit_depth$depth$forumcat")."\";");
 458          }
 459      }
 460  
 461      if(!isset($parent_lastpost))
 462      {
 463          $parent_lastpost = 0;
 464      }
 465  
 466      if(!isset($lightbulb))
 467      {
 468          $lightbulb = '';
 469      }
 470  
 471      // Return an array of information to the parent forum including child forums list, counters and lastpost information
 472      return array(
 473          "forum_list" => $forum_list,
 474          "counters" => $parent_counters,
 475          "lastpost" => $parent_lastpost,
 476          "lightbulb" => $lightbulb,
 477      );
 478  }
 479  
 480  /**
 481   * Fetch the status indicator for a forum based on its last post and the read date
 482   *
 483   * @param array $forum Array of information about the forum
 484   * @param array $lastpost Array of information about the lastpost date
 485   * @param int $locked Whether or not this forum is locked or not
 486   * @return array Array of the folder image to be shown and the alt text
 487   */
 488  function get_forum_lightbulb($forum, $lastpost, $locked=0)
 489  {
 490      global $mybb, $lang, $db, $unread_forums;
 491  
 492      // This forum is a redirect, so override the folder icon with the "offlink" icon.
 493      if($forum['linkto'] != '')
 494      {
 495          $folder = "offlink";
 496          $altonoff = $lang->forum_redirect;
 497      }
 498      // This forum is closed, so override the folder icon with the "offclose" icon.
 499      elseif($forum['open'] == 0 || $locked)
 500      {
 501          $folder = "offclose";
 502          $altonoff = $lang->forum_closed;
 503      }
 504      else
 505      {
 506          // Fetch the last read date for this forum
 507          if(!empty($forum['lastread']))
 508          {
 509              $forum_read = $forum['lastread'];
 510          }
 511          elseif(!empty($mybb->cookies['mybb']['readallforums']))
 512          {
 513              // We've hit the read all forums as a guest, so use the lastvisit of the user
 514              $forum_read = $mybb->cookies['mybb']['lastvisit'];
 515          }
 516          else
 517          {
 518              $forum_read = 0;
 519              $threadcut = TIME_NOW - 60*60*24*$mybb->settings['threadreadcut'];
 520  
 521              // If the user is a guest, do they have a forumsread cookie?
 522              if(!$mybb->user['uid'] && isset($mybb->cookies['mybb']['forumread']))
 523              {
 524                  // If they've visited us before, then they'll have this cookie - otherwise everything is unread...
 525                  $forum_read = my_get_array_cookie("forumread", $forum['fid']);
 526              }
 527              else if($mybb->user['uid'] && $mybb->settings['threadreadcut'] > 0 && $threadcut > $lastpost['lastpost'])
 528              {
 529                  // We have a user, the forum's unread and we're over our threadreadcut limit for the lastpost - we mark these as read
 530                  $forum_read = $lastpost['lastpost'] + 1;
 531              }
 532          }
 533  
 534          //if(!$forum_read)
 535          //{
 536              //$forum_read = $mybb->user['lastvisit'];
 537          //}
 538  
 539           // If the lastpost is greater than the last visit and is greater than the forum read date, we have a new post
 540          if($lastpost['lastpost'] > $forum_read && $lastpost['lastpost'] != 0)
 541          {
 542              $unread_forums++;
 543              $folder = "on";
 544              $altonoff = $lang->new_posts;
 545          }
 546          // Otherwise, no new posts
 547          else
 548          {
 549              $folder = "off";
 550              $altonoff = $lang->no_new_posts;
 551          }
 552      }
 553  
 554      return array(
 555          "folder" => $folder,
 556          "altonoff" => $altonoff
 557      );
 558  }
 559  
 560  /**
 561   * Fetch the number of unapproved posts, formatted, from a forum
 562   *
 563   * @param array $forum Array of information about the forum
 564   * @return array Array containing formatted string for posts and string for threads
 565   */
 566  function get_forum_unapproved($forum)
 567  {
 568      global $lang, $templates;
 569  
 570      $unapproved_threads = $unapproved_posts = '';
 571  
 572      // If the user is a moderator we need to fetch the count
 573      if(is_moderator($forum['fid'], "canviewunapprove"))
 574      {
 575          // Forum has one or more unaproved posts, format language string accordingly
 576          if($forum['unapprovedposts'])
 577          {
 578              if($forum['unapprovedposts'] > 1)
 579              {
 580                  $unapproved_posts_count = $lang->sprintf($lang->forum_unapproved_posts_count, $forum['unapprovedposts']);
 581              }
 582              else
 583              {
 584                  $unapproved_posts_count = $lang->sprintf($lang->forum_unapproved_post_count, 1);
 585              }
 586  
 587              $forum['unapprovedposts'] = my_number_format($forum['unapprovedposts']);
 588              eval("\$unapproved_posts = \"".$templates->get("forumbit_depth2_forum_unapproved_posts")."\";");
 589          }
 590          // Forum has one or more unapproved threads, format language string accordingly
 591          if($forum['unapprovedthreads'])
 592          {
 593              if($forum['unapprovedthreads'] > 1)
 594              {
 595                  $unapproved_threads_count = $lang->sprintf($lang->forum_unapproved_threads_count, $forum['unapprovedthreads']);
 596              }
 597              else
 598              {
 599                  $unapproved_threads_count = $lang->sprintf($lang->forum_unapproved_thread_count, 1);
 600              }
 601  
 602              $forum['unapprovedthreads'] = my_number_format($forum['unapprovedthreads']);
 603              eval("\$unapproved_threads = \"".$templates->get("forumbit_depth2_forum_unapproved_threads")."\";");
 604          }
 605      }
 606      return array(
 607          "unapproved_posts" => $unapproved_posts,
 608          "unapproved_threads" => $unapproved_threads
 609      );
 610  }


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