| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
<span class="code-comment">* |
|---|
| 4 |
* @package acm |
|---|
| 5 |
* @version $Id: cache.php,v 1.7 2007/01/26 16:05:14 acydburn Exp $ |
|---|
| 6 |
* @copyright (c) 2005 phpBB Group |
|---|
| 7 |
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|---|
| 8 |
* |
|---|
| 9 |
*/ |
|---|
| 10 |
|
|---|
| 11 |
/** |
|---|
| 12 |
*/ |
|---|
| 13 |
|
|---|
| 14 |
/** |
|---|
| 15 |
* Class for grabbing/handling cached entries, extends acm_file or acm_db depending on the setup |
|---|
| 16 |
* @package acm |
|---|
| 17 |
*/ |
|---|
| 18 |
|
|---|
| 19 |
$cache_type = ( isset($cache_type) && !empty($cache_type) ? $cache_type : 'filecache' );</span> |
|---|
| 20 |
<span class="code-lang">require_once($root_path . 'include/class.' . $cache_type . '.php'); |
|---|
| 21 |
|
|---|
| 22 |
class cache extends adv_cache |
|---|
| 23 |
{</span> |
|---|
| 24 |
<span class="code-keyword"> |
|---|
| 25 |
|
|---|
| 26 |
* Ceck if a given sql query exist in cache |
|---|
| 27 |
*/ |
|---|
| 28 |
function sql_exists($query_id) |
|---|
| 29 |
{ |
|---|
| 30 |
return isset($this->sql_rowset[$query_id]); |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
* Fetch row from cache (database) |
|---|
| 35 |
*/ |
|---|
| 36 |
function sql_fetchrow($query_id) |
|---|
| 37 |
{ |
|---|
| 38 |
if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id])) |
|---|
| 39 |
{ |
|---|
| 40 |
return $this->sql_rowset[$query_id][$this->sql_row_pointer[$query_id]++]; |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
return false; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
* Fetch a field from the current row of a cached database result (database) |
|---|
| 48 |
*/ |
|---|
| 49 |
function sql_fetchfield($query_id, $field) |
|---|
| 50 |
{ |
|---|
| 51 |
if ($this->sql_row_pointer[$query_id] < sizeof($this->sql_rowset[$query_id])) |
|---|
| 52 |
{ |
|---|
| 53 |
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; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
return false; |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
* Seek a specific row in an a cached database result (database) |
|---|
| 61 |
*/ |
|---|
| 62 |
function sql_rowseek($rownum, $query_id) |
|---|
| 63 |
{ |
|---|
| 64 |
if ($rownum >= sizeof($this->sql_rowset[$query_id])) |
|---|
| 65 |
{ |
|---|
| 66 |
return false; |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
$this->sql_row_pointer[$query_id] = $rownum; |
|---|
| 70 |
return true; |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
* Free memory used for a cached database result (database) |
|---|
| 75 |
*/ |
|---|
| 76 |
function sql_freeresult($query_id) |
|---|
| 77 |
{ |
|---|
| 78 |
if (!isset($this->sql_rowset[$query_id])) |
|---|
| 79 |
{ |
|---|
| 80 |
return false; |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
unset($this->sql_rowset[$query_id]); |
|---|
| 84 |
unset($this->sql_row_pointer[$query_id]); |
|---|
| 85 |
|
|---|
| 86 |
return true; |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
* Get config values |
|---|
| 91 |
*/ |
|---|
| 92 |
function obtain_config() |
|---|
| 93 |
{ |
|---|
| 94 |
global $db; |
|---|
| 95 |
if (($config = $this->get('config')) !== false) |
|---|
| 96 |
{ |
|---|
| 97 |
if ( !defined('IN_ANNOUNCE') ) { |
|---|
| 98 |
$sql = 'SELECT name, value |
|---|
| 99 |
FROM ' . CONFIG_TABLE . ' |
|---|
| 100 |
WHERE is_dynamic = 1'; |
|---|
| 101 |
$result = $db->sql_query($sql); |
|---|
| 102 |
|
|---|
| 103 |
while ($row = $db->sql_fetchrow($result)) |
|---|
| 104 |
{ |
|---|
| 105 |
$config[$row['name']] = $row['value']; |
|---|
| 106 |
} |
|---|
| 107 |
$db->sql_freeresult($result); |
|---|
| 108 |
} |
|---|
| 109 |
} |
|---|
| 110 |
else |
|---|
| 111 |
{ |
|---|
| 112 |
$config = $cached_config = array(); |
|---|
| 113 |
|
|---|
| 114 |
$sql = 'SELECT name, value, is_dynamic |
|---|
| 115 |
FROM ' . CONFIG_TABLE; |
|---|
| 116 |
$result = $db->sql_query($sql); |
|---|
| 117 |
|
|---|
| 118 |
while ($row = $db->sql_fetchrow($result)) |
|---|
| 119 |
{ |
|---|
| 120 |
if (!$row['is_dynamic']) |
|---|
| 121 |
{ |
|---|
| 122 |
$cached_config[$row['name']] = $row['value']; |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
$config[$row['name']] = $row['value']; |
|---|
| 126 |
} |
|---|
| 127 |
$db->sql_freeresult($result); |
|---|
| 128 |
|
|---|
| 129 |
$this->put('config', $cached_config); |
|---|
| 130 |
} |
|---|
| 131 |
|
|---|
| 132 |
return $config; |
|---|
| 133 |
} |
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
* Obtain list of naughty words and build preg style replacement arrays for use by the |
|---|
| 137 |
* calling script |
|---|
| 138 |
*/ |
|---|
| 139 |
function obtain_word_list() |
|---|
| 140 |
{ |
|---|
| 141 |
global $db; |
|---|
| 142 |
|
|---|
| 143 |
if (($censors = $this->get('_word_censors')) === false) |
|---|
| 144 |
{ |
|---|
| 145 |
$sql = 'SELECT word, replacement |
|---|
| 146 |
FROM ' . WORDS_TABLE; |
|---|
| 147 |
$result = $db->sql_query($sql); |
|---|
| 148 |
|
|---|
| 149 |
$censors = array(); |
|---|
| 150 |
while ($row = $db->sql_fetchrow($result)) |
|---|
| 151 |
{ |
|---|
| 152 |
$censors['match'][] = '#(?<!\w)(' . str_replace('\*', '\w*?', preg_quote($row['word'], '#')) . ')(?!\w)#i'; |
|---|
| 153 |
$censors['replace'][] = $row['replacement']; |
|---|
| 154 |
} |
|---|
| 155 |
$db->sql_freeresult($result); |
|---|
| 156 |
|
|---|
| 157 |
$this->put('_word_censors', $censors); |
|---|
| 158 |
} |
|---|
| 159 |
|
|---|
| 160 |
return $censors; |
|---|
| 161 |
} |
|---|
| 162 |
|
|---|
| 163 |
function obtain_smilies() |
|---|
| 164 |
{ |
|---|
| 165 |
if (($smilies = $this->get('_smilies')) === false) |
|---|
| 166 |
{ |
|---|
| 167 |
global $db; |
|---|
| 168 |
|
|---|
| 169 |
$sql = 'SELECT * FROM ' . SMILIES_TABLE; |
|---|
| 170 |
$result = $db->sql_query($sql); |
|---|
| 171 |
|
|---|
| 172 |
$smilies = array(); |
|---|
| 173 |
while ($row = $db->sql_fetchrow($result)) |
|---|
| 174 |
{ |
|---|
| 175 |
$smilies[$row['smilies_id']] = $row; |
|---|
| 176 |
} |
|---|
| 177 |
$db->sql_freeresult($result); |
|---|
| 178 |
|
|---|
| 179 |
$this->put('_smilies', $smilies); |
|---|
| 180 |
} |
|---|
| 181 |
|
|---|
| 182 |
return $smilies; |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
function obtain_ranks() |
|---|
| 186 |
{ |
|---|
| 187 |
global $db; |
|---|
| 188 |
|
|---|
| 189 |
if (($ranks = $this->get('_ranks')) === false) |
|---|
| 190 |
{ |
|---|
| 191 |
$sql = 'SELECT * |
|---|
| 192 |
FROM ' . RANKS_TABLE . ' ORDER BY rank_points'; |
|---|
| 193 |
$result = $db->sql_query($sql); |
|---|
| 194 |
|
|---|
| 195 |
$ranks = array(); |
|---|
| 196 |
while ($row = $db->sql_fetchrow($result)) |
|---|
| 197 |
{ |
|---|
| 198 |
$ranks[$row['rank_id']] = $row; |
|---|
| 199 |
} |
|---|
| 200 |
$db->sql_freeresult($result); |
|---|
| 201 |
|
|---|
| 202 |
$this->put('_ranks', $ranks); |
|---|
| 203 |
} |
|---|
| 204 |
|
|---|
| 205 |
return $ranks; |
|---|
| 206 |
} |
|---|
| 207 |
|
|---|
| 208 |
function obtain_cats() |
|---|
| 209 |
{ |
|---|
| 210 |
global $db; |
|---|
| 211 |
|
|---|
| 212 |
if (($cats = $this->get('_cats')) === false) |
|---|
| 213 |
{ |
|---|
| 214 |
$sql = 'SELECT id AS cat_id, name AS cat_name, image AS cat_pic, cat_parent_id AS cat_parent, torrents_limit, anonymous_view, allow_upload |
|---|
| 215 |
FROM ' . CATEGORIES_TABLE . ' ORDER BY name'; |
|---|
| 216 |
$result = $db->sql_query($sql); |
|---|
| 217 |
|
|---|
| 218 |
$cats = array(); |
|---|
| 219 |
while ($row = $db->sql_fetchrow($result)) |
|---|
| 220 |
{ |
|---|
| 221 |
$cats[$row['cat_id']] = $row; |
|---|
| 222 |
} |
|---|
| 223 |
$db->sql_freeresult($result); |
|---|
| 224 |
|
|---|
| 225 |
$this->put('_cats', $cats); |
|---|
| 226 |
} |
|---|
| 227 |
|
|---|
| 228 |
return $cats; |
|---|
| 229 |
} |
|---|
| 230 |
|
|---|
| 231 |
function obtainForumCats() |
|---|
| 232 |
{ |
|---|
| 233 |
global $db; |
|---|
| 234 |
|
|---|
| 235 |
if (($cats = $this->get('_forumCats')) === false) |
|---|
| 236 |
{ |
|---|
| 237 |
$sql = 'SELECT * |
|---|
| 238 |
FROM ' . FORUM_CATEGORIES_TABLE . ' c |
|---|
| 239 |
ORDER BY c.cat_order'; |
|---|
| 240 |
$result = $db->sql_query($sql); |
|---|
| 241 |
|
|---|
| 242 |
$cats = array(); |
|---|
| 243 |
while ($row = $db->sql_fetchrow($result)) |
|---|
| 244 |
{ |
|---|
| 245 |
$cats[$row['cat_id']] = $row; |
|---|
| 246 |
} |
|---|
| 247 |
$db->sql_freeresult($result); |
|---|
| 248 |
|
|---|
| 249 |
$this->put('_forumCats', $cats); |
|---|
| 250 |
} |
|---|
| 251 |
|
|---|
| 252 |
return $cats; |
|---|
| 253 |
} |
|---|
| 254 |
|
|---|
| 255 |
function obtainForums() |
|---|
| 256 |
{ |
|---|
| 257 |
global $db; |
|---|
| 258 |
|
|---|
| 259 |
$forums_parent = $this->get('_forumsParent'); |
|---|
| 260 |
$forums = $this->get('_forums'); |
|---|
| 261 |
|
|---|
| 262 |
if ( !$forums_parent || !$forums ) |
|---|
| 263 |
{ |
|---|
| 264 |
$sql = 'SELECT * |
|---|
| 265 |
FROM ' . FORUMS_TABLE; |
|---|
| 266 |
$result = $db->sql_query($sql); |
|---|
| 267 |
|
|---|
| 268 |
$forums = $forums_parent = array(); |
|---|
| 269 |
while ($row = $db->sql_fetchrow($result)) |
|---|
| 270 |
{ |
|---|
| 271 |
$forums[$row['forum_id']] = $row; |
|---|
| 272 |
$forums_parent[$row['forum_parent']] = $row; |
|---|
| 273 |
} |
|---|
| 274 |
$db->sql_freeresult($result); |
|---|
| 275 |
|
|---|
| 276 |
$this->put('_forums', $forums); |
|---|
| 277 |
$this->put('_forumsParent', $forums_parent); |
|---|
| 278 |
} |
|---|
| 279 |
|
|---|
| 280 |
return array($forums, $forums_parent); |
|---|
| 281 |
} |
|---|
| 282 |
|
|---|
| 283 |
} |
|---|
| 284 |
?> |
|---|