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