[ Index ] |
PHP Cross Reference of MyBB 1.8.36 |
[Summary view] [Print] [Text view]
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 class datacache 12 { 13 /** 14 * Cache contents. 15 * 16 * @var array 17 */ 18 public $cache = array(); 19 20 /** 21 * The current cache handler we're using 22 * 23 * @var CacheHandlerInterface 24 */ 25 public $handler = null; 26 27 /** 28 * A count of the number of calls. 29 * 30 * @var int 31 */ 32 public $call_count = 0; 33 34 /** 35 * A list of the performed calls. 36 * 37 * @var array 38 */ 39 public $calllist = array(); 40 41 /** 42 * The time spent on cache operations 43 * 44 * @var float 45 */ 46 public $call_time = 0; 47 48 /** 49 * Explanation of a cache call. 50 * 51 * @var string 52 */ 53 public $cache_debug; 54 55 /** 56 * @var array 57 */ 58 public $moderators; 59 60 /** 61 * @var array 62 */ 63 public $built_moderators; 64 65 /** 66 * @var array 67 */ 68 public $moderators_forum_cache; 69 70 /** 71 * Build cache data. 72 * 73 */ 74 function cache() 75 { 76 global $db, $mybb; 77 78 require_once MYBB_ROOT."/inc/cachehandlers/interface.php"; 79 80 switch($mybb->config['cache_store']) 81 { 82 // Disk cache 83 case "files": 84 require_once MYBB_ROOT."/inc/cachehandlers/disk.php"; 85 $this->handler = new diskCacheHandler(); 86 break; 87 // Memcache cache 88 case "memcache": 89 require_once MYBB_ROOT."/inc/cachehandlers/memcache.php"; 90 $this->handler = new memcacheCacheHandler(); 91 break; 92 // Memcached cache 93 case "memcached": 94 require_once MYBB_ROOT."/inc/cachehandlers/memcached.php"; 95 $this->handler = new memcachedCacheHandler(); 96 break; 97 // eAccelerator cache 98 case "eaccelerator": 99 require_once MYBB_ROOT."/inc/cachehandlers/eaccelerator.php"; 100 $this->handler = new eacceleratorCacheHandler(); 101 break; 102 // Xcache cache 103 case "xcache": 104 require_once MYBB_ROOT."/inc/cachehandlers/xcache.php"; 105 $this->handler = new xcacheCacheHandler(); 106 break; 107 // APC cache 108 case "apc": 109 require_once MYBB_ROOT."/inc/cachehandlers/apc.php"; 110 $this->handler = new apcCacheHandler(); 111 break; 112 // APCu cache 113 case "apcu": 114 require_once MYBB_ROOT."/inc/cachehandlers/apcu.php"; 115 $this->handler = new apcuCacheHandler(); 116 break; 117 // Redis cache 118 case "redis": 119 require_once MYBB_ROOT."/inc/cachehandlers/redis.php"; 120 $this->handler = new redisCacheHandler(); 121 break; 122 } 123 124 if($this->handler instanceof CacheHandlerInterface) 125 { 126 if(!$this->handler->connect()) 127 { 128 $this->handler = null; 129 } 130 } 131 else 132 { 133 // Database cache 134 $query = $db->simple_select("datacache", "title,cache"); 135 while($data = $db->fetch_array($query)) 136 { 137 // use native_unserialize() over my_unserialize() for performance reasons 138 $this->cache[$data['title']] = native_unserialize($data['cache']); 139 } 140 } 141 } 142 143 /** 144 * Read cache from files or db. 145 * 146 * @param string $name The cache component to read. 147 * @param boolean $hard If true, cannot be overwritten during script execution. 148 * @return mixed 149 */ 150 function read($name, $hard=false) 151 { 152 global $db, $mybb; 153 154 // Already have this cache and we're not doing a hard refresh? Return cached copy 155 if(isset($this->cache[$name]) && $hard == false) 156 { 157 return $this->cache[$name]; 158 } 159 // If we're not hard refreshing, and this cache doesn't exist, return false 160 // It would have been loaded pre-global if it did exist anyway... 161 else if($hard == false && !($this->handler instanceof CacheHandlerInterface)) 162 { 163 return false; 164 } 165 166 if($this->handler instanceof CacheHandlerInterface) 167 { 168 get_execution_time(); 169 170 $data = $this->handler->fetch($name); 171 172 $call_time = get_execution_time(); 173 $this->call_time += $call_time; 174 $this->call_count++; 175 176 if($mybb->debug_mode) 177 { 178 $hit = true; 179 if($data === false) 180 { 181 $hit = false; 182 } 183 $this->debug_call('read:'.$name, $call_time, $hit); 184 } 185 186 // No data returned - cache gone bad? 187 if($data === false) 188 { 189 // Fetch from database 190 $query = $db->simple_select("datacache", "title,cache", "title='".$db->escape_string($name)."'"); 191 $cache_data = $db->fetch_array($query); 192 193 // use native_unserialize() over my_unserialize() for performance reasons 194 $data = native_unserialize($cache_data['cache']); 195 196 // Update cache for handler 197 get_execution_time(); 198 199 $hit = $this->handler->put($name, $data); 200 201 $call_time = get_execution_time(); 202 $this->call_time += $call_time; 203 $this->call_count++; 204 205 if($mybb->debug_mode) 206 { 207 $this->debug_call('set:'.$name, $call_time, $hit); 208 } 209 } 210 } 211 // Else, using internal database cache 212 else 213 { 214 $query = $db->simple_select("datacache", "title,cache", "title='$name'"); 215 $cache_data = $db->fetch_array($query); 216 217 if(empty($cache_data['title'])) 218 { 219 $data = false; 220 } 221 else 222 { 223 // use native_unserialize() over my_unserialize() for performance reasons 224 $data = native_unserialize($cache_data['cache']); 225 } 226 } 227 228 // Cache locally 229 $this->cache[$name] = $data; 230 231 if($data !== false) 232 { 233 return $data; 234 } 235 else 236 { 237 return false; 238 } 239 } 240 241 /** 242 * Update cache contents. 243 * 244 * @param string $name The cache content identifier. 245 * @param mixed $contents The cache content. 246 */ 247 function update($name, $contents) 248 { 249 global $db, $mybb; 250 251 $this->cache[$name] = $contents; 252 253 // We ALWAYS keep a running copy in the db just incase we need it 254 $dbcontents = $db->escape_string(my_serialize($contents)); 255 256 $replace_array = array( 257 "title" => $db->escape_string($name), 258 "cache" => $dbcontents 259 ); 260 $db->replace_query("datacache", $replace_array, "", false); 261 262 // Do we have a cache handler we're using? 263 if($this->handler instanceof CacheHandlerInterface) 264 { 265 get_execution_time(); 266 267 $hit = $this->handler->put($name, $contents); 268 269 $call_time = get_execution_time(); 270 $this->call_time += $call_time; 271 $this->call_count++; 272 273 if($mybb->debug_mode) 274 { 275 $this->debug_call('update:'.$name, $call_time, $hit); 276 } 277 } 278 } 279 280 /** 281 * Delete cache contents. 282 * Originally from frostschutz's PluginLibrary 283 * github.com/frostschutz 284 * 285 * @param string $name Cache name or title 286 * @param boolean $greedy To delete a cache starting with name_ 287 */ 288 function delete($name, $greedy = false) 289 { 290 global $db, $mybb, $cache; 291 292 // Prepare for database query. 293 $dbname = $db->escape_string($name); 294 $where = "title = '{$dbname}'"; 295 296 // Delete on-demand or handler cache 297 if($this->handler instanceof CacheHandlerInterface) 298 { 299 get_execution_time(); 300 301 $hit = $this->handler->delete($name); 302 303 $call_time = get_execution_time(); 304 $this->call_time += $call_time; 305 $this->call_count++; 306 307 if($mybb->debug_mode) 308 { 309 $this->debug_call('delete:'.$name, $call_time, $hit); 310 } 311 } 312 313 // Greedy? 314 if($greedy) 315 { 316 $name .= '_'; 317 $names = array(); 318 $keys = array_keys($cache->cache); 319 320 foreach($keys as $key) 321 { 322 if(strpos($key, $name) === 0) 323 { 324 $names[$key] = 0; 325 } 326 } 327 328 $ldbname = strtr($dbname, 329 array( 330 '%' => '=%', 331 '=' => '==', 332 '_' => '=_' 333 ) 334 ); 335 336 $where .= " OR title LIKE '{$ldbname}=_%' ESCAPE '='"; 337 338 if($this->handler instanceof CacheHandlerInterface) 339 { 340 $query = $db->simple_select("datacache", "title", $where); 341 342 while($row = $db->fetch_array($query)) 343 { 344 $names[$row['title']] = 0; 345 } 346 347 // ...from the filesystem... 348 $start = strlen(MYBB_ROOT."cache/"); 349 foreach((array)@glob(MYBB_ROOT."cache/{$name}*.php") as $filename) 350 { 351 if($filename) 352 { 353 $filename = substr($filename, $start, strlen($filename)-4-$start); 354 $names[$filename] = 0; 355 } 356 } 357 358 foreach($names as $key => $val) 359 { 360 get_execution_time(); 361 362 $hit = $this->handler->delete($key); 363 364 $call_time = get_execution_time(); 365 $this->call_time += $call_time; 366 $this->call_count++; 367 368 if($mybb->debug_mode) 369 { 370 $this->debug_call('delete:'.$name, $call_time, $hit); 371 } 372 } 373 } 374 } 375 376 // Delete database cache 377 $db->delete_query("datacache", $where); 378 } 379 380 /** 381 * Debug a cache call to a non-database cache handler 382 * 383 * @param string $string The cache key 384 * @param string $qtime The time it took to perform the call. 385 * @param boolean $hit Hit or miss status 386 */ 387 function debug_call($string, $qtime, $hit) 388 { 389 global $mybb, $plugins; 390 391 $debug_extra = ''; 392 if($plugins->current_hook) 393 { 394 $debug_extra = "<div style=\"float_right\">(Plugin Hook: {$plugins->current_hook})</div>"; 395 } 396 397 if($hit) 398 { 399 $hit_status = 'HIT'; 400 } 401 else 402 { 403 $hit_status = 'MISS'; 404 } 405 406 $cache_data = explode(':', $string); 407 $cache_method = $cache_data[0]; 408 $cache_key = $cache_data[1]; 409 410 $this->cache_debug = "<table style=\"background-color: #666;\" width=\"95%\" cellpadding=\"4\" cellspacing=\"1\" align=\"center\"> 411 <tr> 412 <td style=\"background-color: #ccc;\">{$debug_extra}<div><strong>#{$this->call_count} - ".ucfirst($cache_method)." Call</strong></div></td> 413 </tr> 414 <tr style=\"background-color: #fefefe;\"> 415 <td><span style=\"font-family: Courier; font-size: 14px;\">({$mybb->config['cache_store']}) [{$hit_status}] ".htmlspecialchars_uni($cache_key)."</span></td> 416 </tr> 417 <tr> 418 <td bgcolor=\"#ffffff\">Call Time: ".format_time_duration($qtime)."</td> 419 </tr> 420 </table> 421 <br />\n"; 422 423 $this->calllist[$this->call_count]['key'] = $string; 424 $this->calllist[$this->call_count]['time'] = $qtime; 425 } 426 427 /** 428 * Select the size of the cache 429 * 430 * @param string $name The name of the cache 431 * @return integer the size of the cache 432 */ 433 function size_of($name='') 434 { 435 global $db; 436 437 if($this->handler instanceof CacheHandlerInterface) 438 { 439 $size = $this->handler->size_of($name); 440 if(!$size) 441 { 442 if($name) 443 { 444 $query = $db->simple_select("datacache", "cache", "title='{$name}'"); 445 return strlen($db->fetch_field($query, "cache")); 446 } 447 else 448 { 449 return $db->fetch_size("datacache"); 450 } 451 } 452 else 453 { 454 return $size; 455 } 456 } 457 // Using MySQL as cache 458 else 459 { 460 if($name) 461 { 462 $query = $db->simple_select("datacache", "cache", "title='{$name}'"); 463 return strlen($db->fetch_field($query, "cache")); 464 } 465 else 466 { 467 return $db->fetch_size("datacache"); 468 } 469 } 470 } 471 472 /** 473 * Update the MyBB version in the cache. 474 * 475 */ 476 function update_version() 477 { 478 global $mybb; 479 480 $version = array( 481 "version" => $mybb->version, 482 "version_code" => $mybb->version_code 483 ); 484 485 $this->update("version", $version); 486 } 487 488 /** 489 * Update the attachment type cache. 490 * 491 */ 492 function update_attachtypes() 493 { 494 global $db; 495 496 $types = array(); 497 498 $query = $db->simple_select('attachtypes', '*', 'enabled=1'); 499 while($type = $db->fetch_array($query)) 500 { 501 $type['extension'] = my_strtolower($type['extension']); 502 $types[$type['extension']] = $type; 503 } 504 505 $this->update("attachtypes", $types); 506 } 507 508 /** 509 * Update the smilies cache. 510 * 511 */ 512 function update_smilies() 513 { 514 global $db; 515 516 $smilies = array(); 517 518 $query = $db->simple_select("smilies", "*", "", array('order_by' => 'disporder', 'order_dir' => 'ASC')); 519 while($smilie = $db->fetch_array($query)) 520 { 521 $smilies[$smilie['sid']] = $smilie; 522 } 523 524 $this->update("smilies", $smilies); 525 } 526 527 /** 528 * Update the posticon cache. 529 * 530 */ 531 function update_posticons() 532 { 533 global $db; 534 535 $icons = array(); 536 537 $query = $db->simple_select("icons", "iid, name, path"); 538 while($icon = $db->fetch_array($query)) 539 { 540 $icons[$icon['iid']] = $icon; 541 } 542 543 $this->update("posticons", $icons); 544 } 545 546 /** 547 * Update the badwords cache. 548 * 549 */ 550 function update_badwords() 551 { 552 global $db; 553 554 $badwords = array(); 555 556 $query = $db->simple_select("badwords", "*"); 557 while($badword = $db->fetch_array($query)) 558 { 559 $badwords[$badword['bid']] = $badword; 560 } 561 562 $this->update("badwords", $badwords); 563 } 564 565 /** 566 * Update the usergroups cache. 567 * 568 */ 569 function update_usergroups() 570 { 571 global $db; 572 573 $query = $db->simple_select("usergroups"); 574 575 $gs = array(); 576 while($g = $db->fetch_array($query)) 577 { 578 $gs[$g['gid']] = $g; 579 } 580 581 $this->update("usergroups", $gs); 582 } 583 584 /** 585 * Update the forum permissions cache. 586 * 587 * @return bool When failed, returns false. 588 */ 589 function update_forumpermissions() 590 { 591 global $forum_cache, $db; 592 593 $this->forum_permissions = $this->built_forum_permissions = array(0); 594 595 // Get our forum list 596 cache_forums(true); 597 if(!is_array($forum_cache)) 598 { 599 return false; 600 } 601 602 reset($forum_cache); 603 $fcache = array(); 604 605 // Resort in to the structure we require 606 foreach($forum_cache as $fid => $forum) 607 { 608 $this->forum_permissions_forum_cache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum; 609 } 610 611 // Sort children 612 foreach($fcache as $pid => $value) 613 { 614 ksort($fcache[$pid]); 615 } 616 ksort($fcache); 617 618 // Fetch forum permissions from the database 619 $query = $db->simple_select("forumpermissions"); 620 while($forum_permission = $db->fetch_array($query)) 621 { 622 $this->forum_permissions[$forum_permission['fid']][$forum_permission['gid']] = $forum_permission; 623 } 624 625 $this->build_forum_permissions(); 626 $this->update("forumpermissions", $this->built_forum_permissions); 627 628 return true; 629 } 630 631 /** 632 * Build the forum permissions array 633 * 634 * @access private 635 * @param array $permissions An optional permissions array. 636 * @param int $pid An optional permission id. 637 */ 638 private function build_forum_permissions($permissions=array(), $pid=0) 639 { 640 $usergroups = array_keys($this->read("usergroups", true)); 641 if(!empty($this->forum_permissions_forum_cache[$pid])) 642 { 643 foreach($this->forum_permissions_forum_cache[$pid] as $main) 644 { 645 foreach($main as $forum) 646 { 647 $perms = $permissions; 648 foreach($usergroups as $gid) 649 { 650 if(isset($this->forum_permissions[$forum['fid']][$gid]) && $this->forum_permissions[$forum['fid']][$gid]) 651 { 652 $perms[$gid] = $this->forum_permissions[$forum['fid']][$gid]; 653 } 654 if(!empty($perms[$gid])) 655 { 656 $perms[$gid]['fid'] = $forum['fid']; 657 $this->built_forum_permissions[$forum['fid']][$gid] = $perms[$gid]; 658 } 659 } 660 $this->build_forum_permissions($perms, $forum['fid']); 661 } 662 } 663 } 664 } 665 666 /** 667 * Update the stats cache (kept for the sake of being able to rebuild this cache via the cache interface) 668 * 669 */ 670 function update_stats() 671 { 672 require_once MYBB_ROOT."inc/functions_rebuild.php"; 673 rebuild_stats(); 674 } 675 676 /** 677 * Update the statistics cache 678 * 679 */ 680 function update_statistics() 681 { 682 global $db; 683 684 $query = $db->simple_select('users', 'uid, username, referrals', 'referrals>0', array('order_by' => 'referrals', 'order_dir' => 'DESC', 'limit' => 1)); 685 $topreferrer = $db->fetch_array($query); 686 687 $timesearch = TIME_NOW - 86400; 688 689 $query = $db->query(" 690 SELECT u.uid, u.username, COUNT(*) AS poststoday 691 FROM {$db->table_prefix}posts p 692 LEFT JOIN {$db->table_prefix}users u ON (p.uid=u.uid) 693 WHERE p.dateline > {$timesearch} AND p.visible=1 694 GROUP BY u.uid, u.username 695 ORDER BY poststoday DESC 696 "); 697 698 $most_posts = 0; 699 $topposter = array(); 700 while($user = $db->fetch_array($query)) 701 { 702 if($user['poststoday'] > $most_posts) 703 { 704 $most_posts = $user['poststoday']; 705 $topposter = $user; 706 } 707 } 708 709 $query = $db->simple_select('users', 'COUNT(uid) AS posters', 'postnum>0'); 710 $posters = $db->fetch_field($query, 'posters'); 711 712 $statistics = array( 713 'time' => TIME_NOW, 714 'top_referrer' => (array)$topreferrer, 715 'top_poster' => (array)$topposter, 716 'posters' => $posters 717 ); 718 719 $this->update('statistics', $statistics); 720 } 721 722 /** 723 * Update the moderators cache. 724 * 725 * @return bool Returns false on failure 726 */ 727 function update_moderators() 728 { 729 global $forum_cache, $db; 730 731 $this->built_moderators = array(0); 732 733 // Get our forum list 734 cache_forums(true); 735 if(!is_array($forum_cache)) 736 { 737 return false; 738 } 739 740 reset($forum_cache); 741 $fcache = array(); 742 743 // Resort in to the structure we require 744 foreach($forum_cache as $fid => $forum) 745 { 746 $this->moderators_forum_cache[$forum['pid']][$forum['disporder']][$forum['fid']] = $forum; 747 } 748 749 // Sort children 750 foreach($fcache as $pid => $value) 751 { 752 ksort($fcache[$pid]); 753 } 754 ksort($fcache); 755 756 $this->moderators = array(); 757 758 // Fetch moderators from the database 759 $query = $db->query(" 760 SELECT m.*, u.username, u.usergroup, u.displaygroup 761 FROM ".TABLE_PREFIX."moderators m 762 LEFT JOIN ".TABLE_PREFIX."users u ON (m.id=u.uid) 763 WHERE m.isgroup = '0' 764 ORDER BY u.username 765 "); 766 while($moderator = $db->fetch_array($query)) 767 { 768 $this->moderators[$moderator['fid']]['users'][$moderator['id']] = $moderator; 769 } 770 771 if(!function_exists("sort_moderators_by_usernames")) 772 { 773 function sort_moderators_by_usernames($a, $b) 774 { 775 return strcasecmp($a['username'], $b['username']); 776 } 777 } 778 779 //Fetch moderating usergroups from the database 780 $query = $db->query(" 781 SELECT m.*, u.title 782 FROM ".TABLE_PREFIX."moderators m 783 LEFT JOIN ".TABLE_PREFIX."usergroups u ON (m.id=u.gid) 784 WHERE m.isgroup = '1' 785 ORDER BY u.title 786 "); 787 while($moderator = $db->fetch_array($query)) 788 { 789 $this->moderators[$moderator['fid']]['usergroups'][$moderator['id']] = $moderator; 790 } 791 792 foreach(array_keys($this->moderators) as $fid) 793 { 794 if(isset($this->moderators[$fid]['users'])) 795 { 796 uasort($this->moderators[$fid]['users'], 'sort_moderators_by_usernames'); 797 } 798 } 799 800 $this->build_moderators(); 801 802 $this->update("moderators", $this->built_moderators); 803 804 return true; 805 } 806 807 /** 808 * Update the users awaiting activation cache. 809 * 810 */ 811 function update_awaitingactivation() 812 { 813 global $db; 814 815 $query = $db->simple_select('users', 'COUNT(uid) AS awaitingusers', 'usergroup=\'5\''); 816 $awaitingusers = (int)$db->fetch_field($query, 'awaitingusers'); 817 818 $data = array( 819 'users' => $awaitingusers, 820 'time' => TIME_NOW 821 ); 822 823 $this->update('awaitingactivation', $data); 824 } 825 826 /** 827 * Build the moderators array 828 * 829 * @access private 830 * @param array $moderators An optional moderators array (moderators of the parent forum for example). 831 * @param int $pid An optional parent ID. 832 */ 833 private function build_moderators($moderators=array(), $pid=0) 834 { 835 if(isset($this->moderators_forum_cache[$pid])) 836 { 837 foreach($this->moderators_forum_cache[$pid] as $main) 838 { 839 foreach($main as $forum) 840 { 841 $forum_mods = array(); 842 if(count($moderators)) 843 { 844 $forum_mods = $moderators; 845 } 846 // Append - local settings override that of a parent - array_merge works here 847 if(isset($this->moderators[$forum['fid']])) 848 { 849 if(is_array($forum_mods) && count($forum_mods)) 850 { 851 $forum_mods = array_merge($forum_mods, $this->moderators[$forum['fid']]); 852 } 853 else 854 { 855 $forum_mods = $this->moderators[$forum['fid']]; 856 } 857 } 858 $this->built_moderators[$forum['fid']] = $forum_mods; 859 $this->build_moderators($forum_mods, $forum['fid']); 860 } 861 } 862 } 863 } 864 865 /** 866 * Update the forums cache. 867 * 868 */ 869 function update_forums() 870 { 871 global $db; 872 873 $forums = array(); 874 875 // Things we don't want to cache 876 $exclude = array("unapprovedthreads", "unapprovedposts", "threads", "posts", "lastpost", "lastposter", "lastposttid", "lastposteruid", "lastpostsubject", "deletedthreads", "deletedposts"); 877 878 $query = $db->simple_select("forums", "*", "", array('order_by' => 'pid,disporder')); 879 while($forum = $db->fetch_array($query)) 880 { 881 foreach($forum as $key => $val) 882 { 883 if(in_array($key, $exclude)) 884 { 885 unset($forum[$key]); 886 } 887 } 888 $forums[$forum['fid']] = $forum; 889 } 890 891 $this->update("forums", $forums); 892 } 893 894 /** 895 * Update usertitles cache. 896 * 897 */ 898 function update_usertitles() 899 { 900 global $db; 901 902 $usertitles = array(); 903 $query = $db->simple_select("usertitles", "utid, posts, title, stars, starimage", "", array('order_by' => 'posts', 'order_dir' => 'DESC')); 904 while($usertitle = $db->fetch_array($query)) 905 { 906 $usertitles[] = $usertitle; 907 } 908 909 $this->update("usertitles", $usertitles); 910 } 911 912 /** 913 * Update reported content cache. 914 * 915 */ 916 function update_reportedcontent() 917 { 918 global $db; 919 920 $query = $db->simple_select("reportedcontent", "COUNT(rid) AS unreadcount", "reportstatus='0'"); 921 $unreadcount = $db->fetch_field($query, 'unreadcount'); 922 923 $query = $db->simple_select("reportedcontent", "COUNT(rid) AS reportcount"); 924 $reportcount = $db->fetch_field($query, 'reportcount'); 925 926 $query = $db->simple_select("reportedcontent", "dateline", "reportstatus='0'", array('order_by' => 'dateline', 'order_dir' => 'DESC', 'limit' => 1)); 927 $dateline = $db->fetch_field($query, 'dateline'); 928 929 $reports = array( 930 'unread' => $unreadcount, 931 'total' => $reportcount, 932 'lastdateline' => $dateline, 933 ); 934 935 $this->update("reportedcontent", $reports); 936 } 937 938 /** 939 * Update mycode cache. 940 * 941 */ 942 function update_mycode() 943 { 944 global $db; 945 946 $mycodes = array(); 947 $query = $db->simple_select("mycode", "regex, replacement", "active=1", array('order_by' => 'parseorder')); 948 while($mycode = $db->fetch_array($query)) 949 { 950 $mycodes[] = $mycode; 951 } 952 953 $this->update("mycode", $mycodes); 954 } 955 956 /** 957 * Update the mailqueue cache 958 * 959 * @param int $last_run 960 * @param int $lock_time 961 */ 962 function update_mailqueue($last_run=0, $lock_time=0) 963 { 964 global $db; 965 966 $query = $db->simple_select("mailqueue", "COUNT(*) AS queue_size"); 967 $queue_size = $db->fetch_field($query, "queue_size"); 968 969 $mailqueue = $this->read("mailqueue"); 970 if(!is_array($mailqueue)) 971 { 972 $mailqueue = array(); 973 } 974 $mailqueue['queue_size'] = $queue_size; 975 if($last_run > 0) 976 { 977 $mailqueue['last_run'] = $last_run; 978 } 979 $mailqueue['locked'] = $lock_time; 980 981 $this->update("mailqueue", $mailqueue); 982 } 983 984 /** 985 * Update update_check cache (dummy function used by upgrade/install scripts) 986 */ 987 function update_update_check() 988 { 989 $update_cache = array( 990 "dateline" => TIME_NOW 991 ); 992 993 $this->update("update_check", $update_cache); 994 } 995 996 /** 997 * Update default_theme cache 998 */ 999 function update_default_theme() 1000 { 1001 global $db; 1002 1003 $query = $db->simple_select("themes", "name, tid, properties, stylesheets", "def='1'", array('limit' => 1)); 1004 $theme = $db->fetch_array($query); 1005 $this->update("default_theme", $theme); 1006 } 1007 1008 /** 1009 * Updates the tasks cache saving the next run time 1010 */ 1011 function update_tasks() 1012 { 1013 global $db; 1014 1015 $query = $db->simple_select("tasks", "nextrun", "enabled=1", array("order_by" => "nextrun", "order_dir" => "asc", "limit" => 1)); 1016 $next_task = $db->fetch_array($query); 1017 1018 $task_cache = $this->read("tasks"); 1019 if(!is_array($task_cache)) 1020 { 1021 $task_cache = array(); 1022 } 1023 $task_cache['nextrun'] = $next_task['nextrun']; 1024 1025 if(!$task_cache['nextrun']) 1026 { 1027 $task_cache['nextrun'] = TIME_NOW+3600; 1028 } 1029 1030 $this->update("tasks", $task_cache); 1031 } 1032 1033 /** 1034 * Updates the banned IPs cache 1035 */ 1036 function update_bannedips() 1037 { 1038 global $db; 1039 1040 $banned_ips = array(); 1041 $query = $db->simple_select("banfilters", "fid,filter", "type=1"); 1042 while($banned_ip = $db->fetch_array($query)) 1043 { 1044 $banned_ips[$banned_ip['fid']] = $banned_ip; 1045 } 1046 $this->update("bannedips", $banned_ips); 1047 } 1048 1049 /** 1050 * Updates the banned emails cache 1051 */ 1052 function update_bannedemails() 1053 { 1054 global $db; 1055 1056 $banned_emails = array(); 1057 $query = $db->simple_select("banfilters", "fid, filter", "type = '3'"); 1058 1059 while($banned_email = $db->fetch_array($query)) 1060 { 1061 $banned_emails[$banned_email['fid']] = $banned_email; 1062 } 1063 1064 $this->update("bannedemails", $banned_emails); 1065 } 1066 1067 /** 1068 * Updates the search engine spiders cache 1069 */ 1070 function update_spiders() 1071 { 1072 global $db; 1073 1074 $spiders = array(); 1075 $query = $db->simple_select("spiders", "sid, name, useragent, usergroup", "", array("order_by" => "LENGTH(useragent)", "order_dir" => "DESC")); 1076 while($spider = $db->fetch_array($query)) 1077 { 1078 $spiders[$spider['sid']] = $spider; 1079 } 1080 $this->update("spiders", $spiders); 1081 } 1082 1083 function update_most_replied_threads() 1084 { 1085 global $db, $mybb; 1086 1087 $threads = array(); 1088 1089 $query = $db->simple_select("threads", "tid, subject, replies, fid, uid", "visible='1'", array('order_by' => 'replies', 'order_dir' => 'DESC', 'limit_start' => 0, 'limit' => $mybb->settings['statslimit'])); 1090 while($thread = $db->fetch_array($query)) 1091 { 1092 $threads[] = $thread; 1093 } 1094 1095 $this->update("most_replied_threads", $threads); 1096 } 1097 1098 function update_most_viewed_threads() 1099 { 1100 global $db, $mybb; 1101 1102 $threads = array(); 1103 1104 $query = $db->simple_select("threads", "tid, subject, views, fid, uid", "visible='1'", array('order_by' => 'views', 'order_dir' => 'DESC', 'limit_start' => 0, 'limit' => $mybb->settings['statslimit'])); 1105 while($thread = $db->fetch_array($query)) 1106 { 1107 $threads[] = $thread; 1108 } 1109 1110 $this->update("most_viewed_threads", $threads); 1111 } 1112 1113 /** 1114 * @deprecated 1115 */ 1116 function update_banned() 1117 { 1118 // "banned" cache removed 1119 } 1120 1121 function update_birthdays() 1122 { 1123 global $db; 1124 1125 $birthdays = array(); 1126 1127 // Get today, yesterday, and tomorrow's time (for different timezones) 1128 $bdaytime = TIME_NOW; 1129 $bdaydate = my_date("j-n", $bdaytime, '', 0); 1130 $bdaydatetomorrow = my_date("j-n", ($bdaytime+86400), '', 0); 1131 $bdaydateyesterday = my_date("j-n", ($bdaytime-86400), '', 0); 1132 1133 $query = $db->simple_select("users", "uid, username, usergroup, displaygroup, birthday, birthdayprivacy", "birthday LIKE '$bdaydate-%' OR birthday LIKE '$bdaydateyesterday-%' OR birthday LIKE '$bdaydatetomorrow-%'"); 1134 while($bday = $db->fetch_array($query)) 1135 { 1136 // Pop off the year from the birthday because we don't need it. 1137 $bday['bday'] = explode('-', $bday['birthday']); 1138 array_pop($bday['bday']); 1139 $bday['bday'] = implode('-', $bday['bday']); 1140 1141 if($bday['birthdayprivacy'] != 'all') 1142 { 1143 if(isset($birthdays[$bday['bday']]['hiddencount'])) 1144 { 1145 ++$birthdays[$bday['bday']]['hiddencount']; 1146 } 1147 else 1148 { 1149 $birthdays[$bday['bday']]['hiddencount'] = 1; 1150 } 1151 continue; 1152 } 1153 1154 // We don't need any excess caleries in the cache 1155 unset($bday['birthdayprivacy']); 1156 1157 if(!isset($birthdays[$bday['bday']]['users'])) 1158 { 1159 $birthdays[$bday['bday']]['users'] = array(); 1160 } 1161 1162 $birthdays[$bday['bday']]['users'][] = $bday; 1163 } 1164 1165 $this->update("birthdays", $birthdays); 1166 } 1167 1168 function update_groupleaders() 1169 { 1170 global $db; 1171 1172 $groupleaders = array(); 1173 1174 $query = $db->simple_select("groupleaders"); 1175 while($groupleader = $db->fetch_array($query)) 1176 { 1177 $groupleaders[$groupleader['uid']][] = $groupleader; 1178 } 1179 1180 $this->update("groupleaders", $groupleaders); 1181 } 1182 1183 function update_threadprefixes() 1184 { 1185 global $db; 1186 1187 $prefixes = array(); 1188 $query = $db->simple_select("threadprefixes", "*", "", array('order_by' => 'prefix', 'order_dir' => 'ASC')); 1189 1190 while($prefix = $db->fetch_array($query)) 1191 { 1192 $prefixes[$prefix['pid']] = $prefix; 1193 } 1194 1195 $this->update("threadprefixes", $prefixes); 1196 } 1197 1198 function update_forumsdisplay() 1199 { 1200 global $db; 1201 1202 $fd_statistics = array(); 1203 1204 $time = TIME_NOW; // Look for announcements that don't end, or that are ending some time in the future 1205 $query = $db->simple_select("announcements", "fid", "enddate = '0' OR enddate > '{$time}'", array("order_by" => "aid")); 1206 1207 if($db->num_rows($query)) 1208 { 1209 while($forum = $db->fetch_array($query)) 1210 { 1211 if(!isset($fd_statistics[$forum['fid']]['announcements'])) 1212 { 1213 $fd_statistics[$forum['fid']]['announcements'] = 1; 1214 } 1215 } 1216 } 1217 1218 // Do we have any mod tools to use in our forums? 1219 $query = $db->simple_select("modtools", "forums, tid", '', array("order_by" => "tid")); 1220 1221 if($db->num_rows($query)) 1222 { 1223 unset($forum); 1224 while($tool = $db->fetch_array($query)) 1225 { 1226 $forums = explode(",", $tool['forums']); 1227 1228 foreach($forums as $forum) 1229 { 1230 if(!$forum) 1231 { 1232 $forum = -1; 1233 } 1234 1235 if(!isset($fd_statistics[$forum]['modtools'])) 1236 { 1237 $fd_statistics[$forum]['modtools'] = 1; 1238 } 1239 } 1240 } 1241 } 1242 1243 $this->update("forumsdisplay", $fd_statistics); 1244 } 1245 1246 /** 1247 * Update profile fields cache. 1248 * 1249 */ 1250 function update_profilefields() 1251 { 1252 global $db; 1253 1254 $fields = array(); 1255 $query = $db->simple_select("profilefields", "*", "", array('order_by' => 'disporder')); 1256 while($field = $db->fetch_array($query)) 1257 { 1258 $fields[] = $field; 1259 } 1260 1261 $this->update("profilefields", $fields); 1262 } 1263 1264 /** 1265 * Update the report reasons cache. 1266 * 1267 */ 1268 function update_reportreasons($no_plugins = false) 1269 { 1270 global $db; 1271 1272 $content_types = array('post', 'profile', 'reputation'); 1273 if(!$no_plugins) 1274 { 1275 global $plugins; 1276 $content_types = $plugins->run_hooks("report_content_types", $content_types); 1277 } 1278 1279 $reasons = array(); 1280 1281 $query = $db->simple_select("reportreasons", "*", "", array('order_by' => 'disporder')); 1282 while($reason = $db->fetch_array($query)) 1283 { 1284 if($reason['appliesto'] == 'all') 1285 { 1286 foreach($content_types as $content) 1287 { 1288 $reasons[$content][] = array( 1289 'rid' => $reason['rid'], 1290 'title' => $reason['title'], 1291 'extra' => $reason['extra'], 1292 ); 1293 } 1294 } 1295 elseif($reason['appliesto'] != '') 1296 { 1297 $appliesto = explode(",", $reason['appliesto']); 1298 foreach($appliesto as $content) 1299 { 1300 $reasons[$content][] = array( 1301 'rid' => $reason['rid'], 1302 'title' => $reason['title'], 1303 'extra' => $reason['extra'], 1304 ); 1305 } 1306 } 1307 } 1308 1309 $this->update("reportreasons", $reasons); 1310 } 1311 1312 /* Other, extra functions for reloading caches if we just changed to another cache extension (i.e. from db -> xcache) */ 1313 function reload_mostonline() 1314 { 1315 global $db; 1316 1317 $query = $db->simple_select("datacache", "title,cache", "title='mostonline'"); 1318 $this->update("mostonline", my_unserialize($db->fetch_field($query, "cache"))); 1319 } 1320 1321 function reload_plugins() 1322 { 1323 global $db; 1324 1325 $query = $db->simple_select("datacache", "title,cache", "title='plugins'"); 1326 $this->update("plugins", my_unserialize($db->fetch_field($query, "cache"))); 1327 } 1328 1329 function reload_last_backup() 1330 { 1331 global $db; 1332 1333 $query = $db->simple_select("datacache", "title,cache", "title='last_backup'"); 1334 $this->update("last_backup", my_unserialize($db->fetch_field($query, "cache"))); 1335 } 1336 1337 function reload_internal_settings() 1338 { 1339 global $db; 1340 1341 $query = $db->simple_select("datacache", "title,cache", "title='internal_settings'"); 1342 $this->update("internal_settings", my_unserialize($db->fetch_field($query, "cache"))); 1343 } 1344 1345 function reload_version_history() 1346 { 1347 global $db; 1348 1349 $query = $db->simple_select("datacache", "title,cache", "title='version_history'"); 1350 $this->update("version_history", my_unserialize($db->fetch_field($query, "cache"))); 1351 } 1352 1353 function reload_modnotes() 1354 { 1355 global $db; 1356 1357 $query = $db->simple_select("datacache", "title,cache", "title='modnotes'"); 1358 $this->update("modnotes", my_unserialize($db->fetch_field($query, "cache"))); 1359 } 1360 1361 function reload_adminnotes() 1362 { 1363 global $db; 1364 1365 $query = $db->simple_select("datacache", "title,cache", "title='adminnotes'"); 1366 $this->update("adminnotes", my_unserialize($db->fetch_field($query, "cache"))); 1367 } 1368 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup | Cross-referenced by PHPXref |