[ Index ] |
PHP Cross Reference of MyBB 1.8.38 |
[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 /** 12 * Disk Cache Handler 13 */ 14 class diskCacheHandler implements CacheHandlerInterface 15 { 16 /** 17 * Connect and initialize this handler. 18 * 19 * @return boolean True if successful, false on failure 20 */ 21 function connect() 22 { 23 if(!@is_writable(MYBB_ROOT."cache")) 24 { 25 return false; 26 } 27 28 return true; 29 } 30 31 /** 32 * Retrieve an item from the cache. 33 * 34 * @param string $name The name of the cache 35 * @return mixed Cache data if successful, false if failure 36 */ 37 function fetch($name) 38 { 39 if(!@file_exists(MYBB_ROOT."/cache/{$name}.php")) 40 { 41 return false; 42 } 43 44 @include(MYBB_ROOT."/cache/{$name}.php"); 45 46 // Return data 47 return $$name; 48 } 49 50 /** 51 * Write an item to the cache. 52 * 53 * @param string $name The name of the cache 54 * @param mixed $contents The data to write to the cache item 55 * @return boolean True on success, false on failure 56 */ 57 function put($name, $contents) 58 { 59 global $mybb; 60 if(!is_writable(MYBB_ROOT."cache")) 61 { 62 $mybb->trigger_generic_error("cache_no_write"); 63 return false; 64 } 65 66 $cache_file = fopen(MYBB_ROOT."cache/{$name}.php", "w") or $mybb->trigger_generic_error("cache_no_write"); 67 flock($cache_file, LOCK_EX); 68 $cache_contents = "<?php\ndeclare(encoding='UTF-8');\n\n/** MyBB Generated Cache - Do Not Alter\n * Cache Name: $name\n * Generated: ".gmdate("r")."\n*/\n\n"; 69 $cache_contents .= "\$$name = ".var_export($contents, true).";\n\n?>"; 70 fwrite($cache_file, $cache_contents); 71 flock($cache_file, LOCK_UN); 72 fclose($cache_file); 73 74 return true; 75 } 76 77 /** 78 * Delete a cache 79 * 80 * @param string $name The name of the cache 81 * @return boolean True on success, false on failure 82 */ 83 function delete($name) 84 { 85 return @unlink(MYBB_ROOT."/cache/{$name}.php"); 86 } 87 88 /** 89 * Disconnect from the cache 90 * 91 * @return bool 92 */ 93 function disconnect() 94 { 95 return true; 96 } 97 98 /** 99 * Select the size of the disk cache 100 * 101 * @param string $name The name of the cache 102 * @return integer the size of the disk cache 103 */ 104 function size_of($name='') 105 { 106 if($name != '') 107 { 108 return @filesize(MYBB_ROOT."/cache/{$name}.php"); 109 } 110 else 111 { 112 $total = 0; 113 $dir = opendir(MYBB_ROOT."/cache"); 114 while(($file = readdir($dir)) !== false) 115 { 116 if($file == "." || $file == ".." || $file == ".svn" || !is_file(MYBB_ROOT."/cache/{$file}")) 117 { 118 continue; 119 } 120 121 $total += filesize(MYBB_ROOT."/cache/{$file}"); 122 } 123 return $total; 124 } 125 } 126 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
2005 - 2021 © MyBB.de | Alle Rechte vorbehalten! | Sponsor: netcup | Cross-referenced by PHPXref |