[ Index ]

PHP Cross Reference of MyBB 1.8.27

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


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