[ Index ]

PHP Cross Reference of MyBB

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


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