[ Index ]

PHP Cross Reference of MyBB 1.6.5

title

Body

[close]

/inc/ -> class_datacache.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id: class_datacache.php 5473 2011-06-23 11:12:10Z Tomm $
  10   */
  11  
  12  class datacache
  13  {
  14      /**
  15       * Cache contents.
  16       *
  17       * @var array
  18       */
  19      public $cache = array();
  20      
  21      /**
  22       * The current cache handler we're using
  23       *
  24       * @var object
  25       */
  26      public $handler = null;
  27  
  28      /**
  29       * Whether or not to exit the script if we cannot load the specified extension
  30       *
  31       * @var boolean
  32       */
  33      var $silent = false;
  34  
  35      /**
  36       * Build cache data.
  37       *
  38       */
  39  	function cache()
  40      {
  41          global $db, $mybb;
  42          
  43          switch($mybb->config['cache_store'])
  44          {
  45              // Disk cache
  46              case "files":
  47                  require_once  MYBB_ROOT."/inc/cachehandlers/disk.php";
  48                  $this->handler = new diskCacheHandler($this->silent);
  49                  break;
  50              // Memcache cache
  51              case "memcache":
  52                  require_once  MYBB_ROOT."/inc/cachehandlers/memcache.php";
  53                  $this->handler = new memcacheCacheHandler($this->silent);
  54                  break;
  55              // eAccelerator cache
  56              case "eaccelerator":
  57                  require_once  MYBB_ROOT."/inc/cachehandlers/eaccelerator.php";
  58                  $this->handler = new eacceleratorCacheHandler($this->silent);
  59                  break;
  60              // Xcache cache
  61              case "xcache":
  62                  require_once  MYBB_ROOT."/inc/cachehandlers/xcache.php";
  63                  $this->handler = new xcacheCacheHandler($this->silent);
  64                  break;
  65          }
  66          
  67          if(is_object($this->handler))
  68          {
  69              if(method_exists($this->handler, "connect"))
  70              {
  71                  if(!$this->handler->connect())
  72                  {
  73                      $this->handler = null;
  74                  }
  75              }
  76          }
  77          else
  78          {
  79              // Database cache
  80              $query = $db->simple_select("datacache", "title,cache");
  81              while($data = $db->fetch_array($query))
  82              {
  83                  $this->cache[$data['title']] = unserialize($data['cache']);
  84              }
  85          }
  86      }
  87      
  88      /**
  89       * Read cache from files or db.
  90       *
  91       * @param string The cache component to read.
  92       * @param boolean If true, cannot be overwritten during script execution.
  93       * @return unknown
  94       */
  95  	function read($name, $hard=false)
  96      {
  97          global $db, $mybb;
  98          
  99          // Already have this cache and we're not doing a hard refresh? Return cached copy
 100          if(isset($this->cache[$name]) && $hard == false)
 101          {
 102              return $this->cache[$name];
 103          }
 104          // If we're not hard refreshing, and this cache doesn't exist, return false
 105          // It would have been loaded pre-global if it did exist anyway...
 106          else if($hard == false && !is_object($this->handler))
 107          {
 108              return false;
 109          }
 110  
 111          if(is_object($this->handler))
 112          {
 113              $data = $this->handler->fetch($name);
 114              
 115              // No data returned - cache gone bad?
 116              if($data === false)
 117              {
 118                  // Fetch from database
 119                  $query = $db->simple_select("datacache", "title,cache", "title='".$db->escape_string($name)."'");
 120                  $cache_data = $db->fetch_array($query);
 121                  $data = @unserialize($cache_data['cache']);
 122                  
 123                  if($data == null)
 124                  {
 125                      $data = '';
 126                  }
 127                  
 128                  // Update cache for handler
 129                  $this->handler->put($name, $data);
 130              }
 131          }        
 132          // Else, using internal database cache
 133          else
 134          {
 135              $query = $db->simple_select("datacache", "title,cache", "title='$name'");
 136              $cache_data = $db->fetch_array($query);
 137              if(!$cache_data['title'])
 138              {
 139                  $data = false;
 140              }
 141              else
 142              {
 143                  $data = @unserialize($cache_data['cache']);
 144              }
 145          }
 146  
 147          // Cache locally
 148          $this->cache[$name] = $data;
 149          
 150          if($data !== false)
 151          {
 152              return $data;
 153          }
 154          else
 155          {
 156              return false;
 157          }
 158      }
 159  
 160      /**
 161       * Update cache contents.
 162       *
 163       * @param string The cache content identifier.
 164       * @param string The cache content.
 165       */
 166  	function update($name, $contents)
 167      {
 168          global $db, $mybb;
 169          
 170          $this->cache[$name] = $contents;
 171  
 172          // We ALWAYS keep a running copy in the db just incase we need it
 173          $dbcontents = $db->escape_string(serialize($contents));
 174          
 175          $replace_array = array(
 176              "title" => $db->escape_string($name),
 177              "cache" => $dbcontents
 178          );        
 179          $db->replace_query("datacache", $replace_array, "", false);
 180  
 181          // Do we have a cache handler we're using?
 182          if(is_object($this->handler))
 183          {
 184              $this->handler->put($name, $contents);
 185          }
 186      }
 187      
 188      /**
 189       * Select the size of the cache 
 190       *
 191       * @param string The name of the cache
 192       * @return integer the size of the cache
 193       */
 194  	function size_of($name='')
 195      {
 196          global $db;
 197  
 198          if(is_object($this->handler))
 199          {
 200              $size = $this->handler->size_of($name);
 201              if(!$size)
 202              {
 203                  if($name)
 204                  {
 205                      $query = $db->simple_select("datacache", "cache", "title='{$name}'");
 206                      return strlen($db->fetch_field($query, "cache"));
 207                  }
 208                  else
 209                  {
 210                      return $db->fetch_size("datacache");
 211                  }
 212              }
 213              else
 214              {
 215                  return $size;
 216              }
 217          }
 218          // Using MySQL as cache
 219          else
 220          {
 221              if($name)
 222              {
 223                  $query = $db->simple_select("datacache", "cache", "title='{$name}'");
 224                  return strlen($db->fetch_field($query, "cache"));
 225              }
 226              else
 227              {
 228                  return $db->fetch_size("datacache");
 229              }
 230          }
 231      }
 232  
 233      /**
 234       * Update the MyBB version in the cache.
 235       *
 236       */
 237  	function update_version()
 238      {
 239          global $mybb;
 240          
 241          $version = array(
 242              "version" => $mybb->version,
 243              "version_code" => $mybb->version_code
 244          );
 245          
 246          $this->update("version", $version);
 247      }
 248  
 249      /**
 250       * Update the attachment type cache.
 251       *
 252       */
 253  	function update_attachtypes()
 254      {
 255          global $db;
 256          
 257          $types = array();
 258  
 259          $query = $db->simple_select("attachtypes", "*");
 260          while($type = $db->fetch_array($query))
 261          {
 262              $type['extension'] = my_strtolower($type['extension']);
 263              $types[$type['extension']] = $type;
 264          }
 265          
 266          $this->update("attachtypes", $types);
 267      }
 268  
 269      /**
 270       * Update the smilies cache.
 271       *
 272       */
 273  	function update_smilies()
 274      {
 275          global $db;
 276          
 277          $smilies = array();
 278  
 279          $query = $db->simple_select("smilies", "*", "", array('order_by' => 'disporder', 'order_dir' => 'ASC'));
 280          while($smilie = $db->fetch_array($query))
 281          {
 282              $smilies[$smilie['sid']] = $smilie;
 283          }
 284          
 285          $this->update("smilies", $smilies);
 286      }
 287  
 288      /**
 289       * Update the posticon cache.
 290       *
 291       */
 292  	function update_posticons()
 293      {
 294          global $db;
 295          
 296          $icons = array();
 297  
 298          $query = $db->simple_select("icons", "iid, name, path");
 299          while($icon = $db->fetch_array($query))
 300          {
 301              $icons[$icon['iid']] = $icon;
 302          }
 303          
 304          $this->update("posticons", $icons);
 305      }
 306  
 307      /**
 308       * Update the badwords cache.
 309       *
 310       */
 311  	function update_badwords()
 312      {
 313          global $db;
 314          
 315          $badwords = array();
 316  
 317          $query = $db->simple_select("badwords", "*");
 318          while($badword = $db->fetch_array($query)) 
 319          {
 320              $badwords[$badword['bid']] = $badword;
 321          }
 322          
 323          $this->update("badwords", $badwords);
 324      }
 325  
 326      /**
 327       * Update the usergroups cache.
 328       *
 329       */
 330  	function update_usergroups()
 331      {
 332          global $db;
 333          
 334          $query = $db->simple_select("usergroups");
 335          while($g = $db->fetch_array($query))
 336          {
 337              $gs[$g['gid']] = $g;
 338          }
 339          
 340          $this->update("usergroups", $gs);
 341      }
 342  
 343      /**
 344       * Update the forum permissions cache.
 345       *
 346       * @return false When failed, returns false.
 347       */
 348  	function update_forumpermissions()
 349      {
 350          global $forum_cache, $db;
 351  
 352          $this->built_forum_permissions = array(0);
 353  
 354          // Get our forum list
 355          cache_forums(true);
 356          if(!is_array($forum_cache))
 357          {
 358              return false;
 359          }
 360          
 361          reset($forum_cache);
 362          $fcache = array();
 363          
 364          // Resort in to the structure we require
 365          foreach($forum_cache as $fid => $forum)
 366          {
 367              $this->forum_permissions_forum_cache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;
 368          }
 369          
 370          // Sort children
 371          foreach($fcache as $pid => $value)
 372          {
 373              ksort($fcache[$pid]);
 374          }
 375          ksort($fcache);
 376      
 377          // Fetch forum permissions from the database
 378          $query = $db->simple_select("forumpermissions");
 379          while($forum_permission = $db->fetch_array($query))
 380          {
 381              $this->forum_permissions[$forum_permission['fid']][$forum_permission['gid']] = $forum_permission;
 382          }
 383  
 384          $this->build_forum_permissions();
 385          $this->update("forumpermissions", $this->built_forum_permissions);
 386      }
 387  
 388      /**
 389       * Build the forum permissions array
 390       *
 391       * @access private
 392       * @param array An optional permissions array.
 393       * @param int An optional permission id.
 394       */
 395  	private function build_forum_permissions($permissions=array(), $pid=0)
 396      {
 397          $usergroups = array_keys($this->read("usergroups", true));
 398          if($this->forum_permissions_forum_cache[$pid])
 399          {
 400              foreach($this->forum_permissions_forum_cache[$pid] as $main)
 401              {
 402                  foreach($main as $forum)
 403                  {
 404                      $perms = $permissions;
 405                      foreach($usergroups as $gid)
 406                      {
 407                          if($this->forum_permissions[$forum['fid']][$gid])
 408                          {
 409                              $perms[$gid] = $this->forum_permissions[$forum['fid']][$gid];
 410                          }
 411                          if($perms[$gid])
 412                          {
 413                              $perms[$gid]['fid'] = $forum['fid'];
 414                              $this->built_forum_permissions[$forum['fid']][$gid] = $perms[$gid];
 415                          }
 416                      }
 417                      $this->build_forum_permissions($perms, $forum['fid']);
 418                  }
 419              }
 420          }
 421      }
 422  
 423      /**
 424       * Update the stats cache (kept for the sake of being able to rebuild this cache via the cache interface)
 425       *
 426       */
 427  	function update_stats()
 428      {
 429          global $db;
 430          require_once  MYBB_ROOT."inc/functions_rebuild.php";
 431          rebuild_stats();
 432      }
 433  
 434      /**
 435       * Update the moderators cache.
 436       *
 437       */
 438  	function update_moderators()
 439      {
 440          global $forum_cache, $db;
 441          
 442          $this->built_moderators = array(0);
 443  
 444          // Get our forum list
 445          cache_forums(true);
 446          if(!is_array($forum_cache))
 447          {
 448              return false;
 449          }
 450          
 451          reset($forum_cache);
 452          $fcache = array();
 453          
 454          // Resort in to the structure we require
 455          foreach($forum_cache as $fid => $forum)
 456          {
 457              $this->moderators_forum_cache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum;
 458          }
 459          
 460          // Sort children
 461          foreach($fcache as $pid => $value)
 462          {
 463              ksort($fcache[$pid]);
 464          }
 465          ksort($fcache);
 466      
 467          // Fetch moderators from the database
 468          $query = $db->query("
 469              SELECT m.*, u.username, u.usergroup, u.displaygroup
 470              FROM ".TABLE_PREFIX."moderators m
 471              LEFT JOIN ".TABLE_PREFIX."users u ON (m.id=u.uid)
 472              WHERE m.isgroup = '0'
 473              ORDER BY u.username
 474          ");
 475          while($moderator = $db->fetch_array($query))
 476          {
 477              $this->moderators[$moderator['fid']]['users'][$moderator['id']] = $moderator;
 478          }
 479  
 480          if(!function_exists("sort_moderators_by_usernames"))
 481          {
 482  			function sort_moderators_by_usernames($a, $b)
 483              {
 484                  return strcasecmp($a['username'], $b['username']);
 485              }
 486          }
 487  
 488          //Fetch moderating usergroups from the database
 489          $query = $db->query("
 490              SELECT m.*, u.title
 491              FROM ".TABLE_PREFIX."moderators m
 492              LEFT JOIN ".TABLE_PREFIX."usergroups u ON (m.id=u.gid)
 493              WHERE m.isgroup = '1'
 494              ORDER BY u.title
 495          ");
 496          while($moderator = $db->fetch_array($query))
 497          {
 498              $this->moderators[$moderator['fid']]['usergroups'][$moderator['id']] = $moderator;
 499          }
 500          
 501          if(is_array($this->moderators))
 502          {
 503              foreach(array_keys($this->moderators) as $fid)
 504              {
 505                  uasort($this->moderators[$fid], 'sort_moderators_by_usernames');
 506              }
 507          }
 508          
 509          $this->build_moderators();
 510          
 511          $this->update("moderators", $this->built_moderators);
 512      }
 513  
 514      /**
 515       * Build the moderators array
 516       *
 517       * @access private
 518       * @param array An optional moderators array (moderators of the parent forum for example).
 519       * @param int An optional parent ID.
 520       */
 521  	private function build_moderators($moderators=array(), $pid=0)
 522      {
 523          if($this->moderators_forum_cache[$pid])
 524          {
 525              foreach($this->moderators_forum_cache[$pid] as $main)
 526              {
 527                  foreach($main as $forum)
 528                  {
 529                      $forum_mods = '';
 530                      if(count($moderators))
 531                      {
 532                          $forum_mods = $moderators;
 533                      }
 534                      // Append - local settings override that of a parent - array_merge works here
 535                      if($this->moderators[$forum['fid']])
 536                      {
 537                          if(is_array($forum_mods) && count($forum_mods))
 538                          {
 539                              $forum_mods = array_merge($forum_mods, $this->moderators[$forum['fid']]);
 540                          }
 541                          else
 542                          {
 543                              $forum_mods = $this->moderators[$forum['fid']];
 544                          }
 545                      }
 546                      $this->built_moderators[$forum['fid']] = $forum_mods;
 547                      $this->build_moderators($forum_mods, $forum['fid']);
 548                  }
 549              }
 550          }
 551      }
 552  
 553      /**
 554       * Update the forums cache.
 555       *
 556       */
 557  	function update_forums()
 558      {
 559          global $db;
 560          $forums = array();
 561          
 562          // Things we don't want to cache
 563          $exclude = array("unapprovedthreads","unapprovedposts", "threads", "posts", "lastpost", "lastposter", "lastposttid");
 564          
 565          $query = $db->simple_select("forums", "*", "", array('order_by' => 'pid,disporder'));
 566          while($forum = $db->fetch_array($query))
 567          {
 568              foreach($forum as $key => $val)
 569              {
 570                  if(in_array($key, $exclude))
 571                  {
 572                      unset($forum[$key]);
 573                  }
 574              }
 575              $forums[$forum['fid']] = $forum;
 576          }
 577          
 578          $this->update("forums", $forums);
 579      }
 580      
 581      /**
 582       * Update usertitles cache.
 583       *
 584       */
 585  	function update_usertitles()
 586      {
 587          global $db;
 588          $usertitles = array();
 589          $query = $db->simple_select("usertitles", "utid, posts, title, stars, starimage", "", array('order_by' => 'posts', 'order_dir' => 'DESC'));
 590          while($usertitle = $db->fetch_array($query))
 591          {
 592              $usertitles[] = $usertitle;
 593          }
 594          
 595          $this->update("usertitles", $usertitles);
 596      }
 597  
 598      /**
 599       * Update reported posts cache.
 600       *
 601       */
 602  	function update_reportedposts()
 603      {
 604          global $db;
 605          $reports = array();
 606          $query = $db->simple_select("reportedposts", "COUNT(rid) AS unreadcount", "reportstatus='0'");
 607          $num = $db->fetch_array($query);
 608          
 609          $query = $db->simple_select("reportedposts", "COUNT(rid) AS reportcount");
 610          $total = $db->fetch_array($query);
 611          
 612          $query = $db->simple_select("reportedposts", "dateline", "reportstatus='0'", array('order_by' => 'dateline', 'order_dir' => 'DESC'));
 613          $latest = $db->fetch_array($query);
 614          
 615          $reports = array(
 616              "unread" => $num['unreadcount'],
 617              "total" => $total['reportcount'],
 618              "lastdateline" => $latest['dateline']
 619          );
 620          
 621          $this->update("reportedposts", $reports);
 622      }
 623  
 624  
 625      /**
 626       * Update mycode cache.
 627       *
 628       */
 629  	function update_mycode()
 630      {
 631          global $db;
 632          $mycodes = array();
 633          $query = $db->simple_select("mycode", "regex, replacement", "active=1", array('order_by' => 'parseorder'));
 634          while($mycode = $db->fetch_array($query))
 635          {
 636              $mycodes[] = $mycode;
 637          }
 638          
 639          $this->update("mycode", $mycodes);
 640      }
 641      /**
 642       * Update the mailqueue cache
 643       *
 644       */
 645  	function update_mailqueue($last_run=0, $lock_time=0)
 646      {
 647          global $db;
 648          
 649          $query = $db->simple_select("mailqueue", "COUNT(*) AS queue_size");
 650          $queue_size = $db->fetch_field($query, "queue_size");
 651          
 652          $mailqueue = $this->read("mailqueue");
 653          if(!is_array($mailqueue))
 654          {
 655              $mailqueue = array();
 656          }
 657          $mailqueue['queue_size'] = $queue_size;
 658          if($last_run > 0)
 659          {
 660              $mailqueue['last_run'] = $last_run;
 661          }
 662          $mailqueue['locked'] = $lock_time;
 663          
 664          $this->update("mailqueue", $mailqueue);
 665      }
 666      
 667      /**
 668       * Update update_check cache (dummy function used by upgrade/install scripts)
 669       */
 670  	function update_update_check()
 671      {
 672          $update_cache = array(
 673              "dateline" => TIME_NOW
 674          );
 675          
 676          $this->update("update_check", $update_cache);
 677      }
 678  
 679      /**
 680       * Updates the tasks cache saving the next run time
 681       */
 682  	function update_tasks()
 683      {
 684          global $db;
 685          $query = $db->simple_select("tasks", "nextrun", "enabled=1", array("order_by" => "nextrun", "order_dir" => "asc", "limit" => 1));
 686          $next_task = $db->fetch_array($query);
 687          
 688          $task_cache = $this->read("tasks");
 689          if(!is_array($task_cache))
 690          {
 691              $task_cache = array();
 692          }
 693          $task_cache['nextrun'] = $next_task['nextrun'];
 694  
 695          if(!$task_cache['nextrun'])
 696          {
 697              $task_cache['nextrun'] = TIME_NOW+3600;
 698          }
 699  
 700          $this->update("tasks", $task_cache);
 701      }
 702  
 703  
 704      /**
 705       * Updates the banned IPs cache
 706       */
 707  	function update_bannedips()
 708      {
 709          global $db;
 710          $banned_ips = array();
 711          $query = $db->simple_select("banfilters", "fid,filter", "type=1");
 712          while($banned_ip = $db->fetch_array($query))
 713          {
 714              $banned_ips[$banned_ip['fid']] = $banned_ip;
 715          }
 716          $this->update("bannedips", $banned_ips);
 717      }
 718  
 719      /**
 720       * Updates the banned emails cache
 721       */
 722  	function update_bannedemails()
 723      {
 724          global $db;
 725  
 726          $banned_emails = array();
 727          $query = $db->simple_select("banfilters", "fid, filter", "type = '3'");
 728  
 729          while($banned_email = $db->fetch_array($query))
 730          {
 731              $banned_emails[$banned_email['fid']] = $banned_email;
 732          }
 733  
 734          $this->update("bannedemails", $banned_emails);
 735      }
 736  
 737      /**
 738       * Updates the search engine spiders cache
 739       */
 740  	function update_spiders()
 741      {
 742          global $db;
 743          $spiders = array();
 744          $query = $db->simple_select("spiders", "sid, name, useragent, usergroup", "", array("order_by" => "LENGTH(useragent)", "order_dir" => "DESC")); 
 745          while($spider = $db->fetch_array($query))
 746          {
 747              $spiders[$spider['sid']] = $spider;
 748          }
 749          $this->update("spiders", $spiders);
 750      }
 751      
 752  	function update_most_replied_threads()
 753      {
 754          global $db, $mybb;
 755          
 756          $threads = array();
 757          
 758          $query = $db->simple_select("threads", "tid, subject, replies, fid", "visible='1'", array('order_by' => 'replies', 'order_dir' => 'DESC', 'limit_start' => 0, 'limit' => $mybb->settings['statslimit']));
 759          while($thread = $db->fetch_array($query))
 760          {
 761              $threads[] = $thread;
 762          }
 763          
 764          $this->update("most_replied_threads", $threads);
 765      }
 766      
 767  	function update_most_viewed_threads()
 768      {
 769          global $db, $mybb;
 770          
 771          $threads = array();
 772          
 773          $query = $db->simple_select("threads", "tid, subject, views, fid", "visible='1'", array('order_by' => 'views', 'order_dir' => 'DESC', 'limit_start' => 0, 'limit' => $mybb->settings['statslimit']));
 774          while($thread = $db->fetch_array($query))
 775          {
 776              $threads[] = $thread;
 777          }
 778          
 779          $this->update("most_viewed_threads", $threads);
 780      }
 781      
 782  	function update_banned()
 783      {
 784          global $db;
 785          
 786          $bans = array();
 787          
 788          $query = $db->simple_select("banned");
 789          while($ban = $db->fetch_array($query))
 790          {
 791              $bans[$ban['uid']] = $ban;
 792          }
 793          
 794          $this->update("banned", $bans);
 795      }
 796      
 797  	function update_birthdays()
 798      {
 799          global $db;
 800          
 801          $birthdays = array();
 802          
 803          // Get today, yesturday, and tomorrow's time (for different timezones)
 804          $bdaytime = TIME_NOW;
 805          $bdaydate = my_date("j-n", $bdaytime, '', 0);
 806          $bdaydatetomorrow = my_date("j-n", ($bdaytime+86400), '', 0);
 807          $bdaydateyesterday = my_date("j-n", ($bdaytime-86400), '', 0);
 808          
 809          $query = $db->simple_select("users", "uid, username, usergroup, displaygroup, birthday, birthdayprivacy", "birthday LIKE '$bdaydate-%' OR birthday LIKE '$bdaydateyesterday-%' OR birthday LIKE '$bdaydatetomorrow-%'");
 810          while($bday = $db->fetch_array($query))
 811          {
 812              // Pop off the year from the birthday because we don't need it.
 813              $bday['bday'] = explode('-', $bday['birthday']);
 814              array_pop($bday['bday']);
 815              $bday['bday'] = implode('-', $bday['bday']);
 816              
 817              if($bday['birthdayprivacy'] != 'all')
 818              {
 819                  ++$birthdays[$bday['bday']]['hiddencount'];
 820                  continue;
 821              }
 822              
 823              // We don't need any excess caleries in the cache
 824              unset($bday['birthdayprivacy']);
 825              
 826              $birthdays[$bday['bday']]['users'][] = $bday;
 827          }
 828          
 829          $this->update("birthdays", $birthdays);
 830      }
 831      
 832  	function update_groupleaders()
 833      {
 834          global $db;
 835          
 836          $groupleaders = array();
 837          
 838          $query = $db->simple_select("groupleaders");
 839          while($groupleader = $db->fetch_array($query))
 840          {
 841              $groupleaders[$groupleader['uid']][] = $groupleader;
 842          }
 843          
 844          $this->update("groupleaders", $groupleaders);
 845      }
 846  
 847  	function update_threadprefixes()
 848      {
 849          global $db;
 850  
 851          $prefixes = array();
 852          $query = $db->simple_select("threadprefixes", "*", "", array("order_by" => "pid"));
 853  
 854          while($prefix = $db->fetch_array($query))
 855          {
 856              $prefixes[$prefix['pid']] = $prefix;
 857          }
 858  
 859          $this->update("threadprefixes", $prefixes);
 860      }
 861  
 862  	function update_forumsdisplay()
 863      {
 864          global $db;
 865  
 866          $fd_statistics = array();
 867  
 868          $time = TIME_NOW; // Look for announcements that don't end, or that are ending some time in the future
 869          $query = $db->simple_select("announcements", "fid", "enddate = '0' OR enddate > '{$time}'", array("order_by" => "aid"));
 870  
 871          if($db->num_rows($query))
 872          {
 873              while($forum = $db->fetch_array($query))
 874              {
 875                  if(!isset($fd_statistics[$forum['fid']]['announcements']))
 876                  {
 877                      $fd_statistics[$forum['fid']]['announcements'] = 1;
 878                  }
 879              }
 880          }
 881  
 882          // Do we have any mod tools to use in our forums?
 883          $query = $db->simple_select("modtools", "forums, tid", "type = 't'", array("order_by" => "tid"));
 884  
 885          if($db->num_rows($query))
 886          {
 887              unset($forum);
 888              while($tool = $db->fetch_array($query))
 889              {
 890                  $forums = explode(",", $tool['forums']);
 891  
 892                  foreach($forums as $forum)
 893                  {
 894                      if(!$forum)
 895                      {
 896                          $forum = -1;
 897                      }
 898  
 899                      if(!isset($fd_statistics[$forum]['modtools']))
 900                      {
 901                          $fd_statistics[$forum]['modtools'] = 1;
 902                      }
 903                  }
 904              }
 905          }
 906  
 907          $this->update("forumsdisplay", $fd_statistics);
 908      }
 909  
 910      /* Other, extra functions for reloading caches if we just changed to another cache extension (i.e. from db -> xcache) */
 911  	function reload_mostonline()
 912      {
 913          global $db;
 914  
 915          $query = $db->simple_select("datacache", "title,cache", "title='mostonline'");
 916          $this->update("mostonline", @unserialize($db->fetch_field($query, "cache")));
 917      }
 918  
 919  	function reload_plugins()
 920      {
 921          global $db;
 922  
 923          $query = $db->simple_select("datacache", "title,cache", "title='plugins'");
 924          $this->update("plugins", @unserialize($db->fetch_field($query, "cache")));
 925      }
 926      
 927  	function reload_last_backup()
 928      {
 929          global $db;
 930  
 931          $query = $db->simple_select("datacache", "title,cache", "title='last_backup'");
 932          $this->update("last_backup", @unserialize($db->fetch_field($query, "cache")));
 933      }
 934      
 935  	function reload_internal_settings()
 936      {
 937          global $db;
 938  
 939          $query = $db->simple_select("datacache", "title,cache", "title='internal_settings'");
 940          $this->update("internal_settings", @unserialize($db->fetch_field($query, "cache")));
 941      }
 942      
 943  	function reload_version_history()
 944      {
 945          global $db;
 946  
 947          $query = $db->simple_select("datacache", "title,cache", "title='version_history'");
 948          $this->update("version_history", @unserialize($db->fetch_field($query, "cache")));
 949      }
 950  }
 951  ?>


Generated: Sun Dec 11 14:16:27 2011 Cross-referenced by PHPXref 0.7.1