[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\cache\driver; 15 16 abstract class base implements \phpbb\cache\driver\driver_interface 17 { 18 var $vars = array(); 19 var $is_modified = false; 20 21 var $sql_rowset = array(); 22 var $sql_row_pointer = array(); 23 var $cache_dir = ''; 24 25 /** 26 * {@inheritDoc} 27 */ 28 function purge() 29 { 30 // Purge all phpbb cache files 31 try 32 { 33 $iterator = new \DirectoryIterator($this->cache_dir); 34 } 35 catch (\Exception $e) 36 { 37 return; 38 } 39 40 foreach ($iterator as $fileInfo) 41 { 42 if ($fileInfo->isDot()) 43 { 44 continue; 45 } 46 $filename = $fileInfo->getFilename(); 47 if ($fileInfo->isDir()) 48 { 49 $this->remove_dir($fileInfo->getPathname()); 50 } 51 else if (strpos($filename, 'container_') === 0 || 52 strpos($filename, 'url_matcher') === 0 || 53 strpos($filename, 'sql_') === 0 || 54 strpos($filename, 'data_') === 0) 55 { 56 $this->remove_file($fileInfo->getPathname()); 57 } 58 } 59 60 unset($this->vars); 61 unset($this->sql_rowset); 62 unset($this->sql_row_pointer); 63 64 if (function_exists('opcache_reset')) 65 { 66 @opcache_reset(); 67 } 68 69 $this->vars = array(); 70 $this->sql_rowset = array(); 71 $this->sql_row_pointer = array(); 72 73 $this->is_modified = false; 74 } 75 76 /** 77 * {@inheritDoc} 78 */ 79 function unload() 80 { 81 $this->save(); 82 unset($this->vars); 83 unset($this->sql_rowset); 84 unset($this->sql_row_pointer); 85 86 $this->vars = array(); 87 $this->sql_rowset = array(); 88 $this->sql_row_pointer = array(); 89 } 90 91 /** 92 * {@inheritDoc} 93 */ 94 function sql_load($query) 95 { 96 // Remove extra spaces and tabs 97 $query = preg_replace('/[\n\r\s\t]+/', ' ', $query); 98 99 if (($rowset = $this->_read('sql_' . md5($query))) === false) 100 { 101 return false; 102 } 103 104 $query_id = sizeof($this->sql_rowset); 105 $this->sql_rowset[$query_id] = $rowset; 106 $this->sql_row_pointer[$query_id] = 0; 107 108 return $query_id; 109 } 110 111 /** 112 * {@inheritDoc} 113 */ 114 function sql_exists($query_id) 115 { 116 return isset($this->sql_rowset[$query_id]); 117 } 118 119 /** 120 * {@inheritDoc} 121 */ 122 function sql_fetchrow($query_id) 123 { 124 if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id])) 125 { 126 return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++]; 127 } 128 129 return false; 130 } 131 132 /** 133 * {@inheritDoc} 134 */ 135 function sql_fetchfield($query_id, $field) 136 { 137 if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id])) 138 { 139 return (isset($this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]][$field])) ? $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++][$field] : false; 140 } 141 142 return false; 143 } 144 145 /** 146 * {@inheritDoc} 147 */ 148 function sql_rowseek($rownum, $query_id) 149 { 150 if ($rownum >= sizeof($this->sql_rowset[$query_id])) 151 { 152 return false; 153 } 154 155 $this->sql_row_pointer[$query_id] = $rownum; 156 return true; 157 } 158 159 /** 160 * {@inheritDoc} 161 */ 162 function sql_freeresult($query_id) 163 { 164 if (!isset($this->sql_rowset[$query_id])) 165 { 166 return false; 167 } 168 169 unset($this->sql_rowset[$query_id]); 170 unset($this->sql_row_pointer[$query_id]); 171 172 return true; 173 } 174 175 /** 176 * Removes/unlinks file 177 * 178 * @param string $filename Filename to remove 179 * @param bool $check Check file permissions 180 * @return bool True if the file was successfully removed, otherwise false 181 */ 182 function remove_file($filename, $check = false) 183 { 184 if (!function_exists('phpbb_is_writable')) 185 { 186 global $phpbb_root_path, $phpEx; 187 include($phpbb_root_path . 'includes/functions.' . $phpEx); 188 } 189 190 if ($check && !phpbb_is_writable($this->cache_dir)) 191 { 192 // E_USER_ERROR - not using language entry - intended. 193 trigger_error('Unable to remove files within ' . $this->cache_dir . '. Please check directory permissions.', E_USER_ERROR); 194 } 195 196 return @unlink($filename); 197 } 198 199 /** 200 * Remove directory 201 * 202 * @param string $dir Directory to remove 203 * 204 * @return null 205 */ 206 protected function remove_dir($dir) 207 { 208 try 209 { 210 $iterator = new \DirectoryIterator($dir); 211 } 212 catch (\Exception $e) 213 { 214 return; 215 } 216 217 foreach ($iterator as $fileInfo) 218 { 219 if ($fileInfo->isDot()) 220 { 221 continue; 222 } 223 224 if ($fileInfo->isDir()) 225 { 226 $this->remove_dir($fileInfo->getPathname()); 227 } 228 else 229 { 230 $this->remove_file($fileInfo->getPathname()); 231 } 232 } 233 234 @rmdir($dir); 235 } 236 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |