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