PageRenderTime 59ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/wwwroot/phpbb/includes/cache.php

https://github.com/abma/spring-website
PHP | 444 lines | 317 code | 71 blank | 56 comment | 42 complexity | 19fd0f175703ba94413032f4ad84f47a MD5 | raw file
  1. <?php
  2. /**
  3. *
  4. * @package acm
  5. * @version $Id: cache.php 9726 2009-07-07 12:59:30Z rxu $
  6. * @copyright (c) 2005 phpBB Group
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. * @ignore
  12. */
  13. if (!defined('IN_PHPBB'))
  14. {
  15. exit;
  16. }
  17. /**
  18. * Class for grabbing/handling cached entries, extends acm_file or acm_db depending on the setup
  19. * @package acm
  20. */
  21. class cache extends acm
  22. {
  23. /**
  24. * Get config values
  25. */
  26. function obtain_config()
  27. {
  28. global $db;
  29. if (($config = $this->get('config')) !== false)
  30. {
  31. $sql = 'SELECT config_name, config_value
  32. FROM ' . CONFIG_TABLE . '
  33. WHERE is_dynamic = 1';
  34. $result = $db->sql_query($sql);
  35. while ($row = $db->sql_fetchrow($result))
  36. {
  37. $config[$row['config_name']] = $row['config_value'];
  38. }
  39. $db->sql_freeresult($result);
  40. }
  41. else
  42. {
  43. $config = $cached_config = array();
  44. $sql = 'SELECT config_name, config_value, is_dynamic
  45. FROM ' . CONFIG_TABLE;
  46. $result = $db->sql_query($sql);
  47. while ($row = $db->sql_fetchrow($result))
  48. {
  49. if (!$row['is_dynamic'])
  50. {
  51. $cached_config[$row['config_name']] = $row['config_value'];
  52. }
  53. $config[$row['config_name']] = $row['config_value'];
  54. }
  55. $db->sql_freeresult($result);
  56. $this->put('config', $cached_config);
  57. }
  58. return $config;
  59. }
  60. /**
  61. * Obtain list of naughty words and build preg style replacement arrays for use by the
  62. * calling script
  63. */
  64. function obtain_word_list()
  65. {
  66. global $db;
  67. if (($censors = $this->get('_word_censors')) === false)
  68. {
  69. $sql = 'SELECT word, replacement
  70. FROM ' . WORDS_TABLE;
  71. $result = $db->sql_query($sql);
  72. $censors = array();
  73. while ($row = $db->sql_fetchrow($result))
  74. {
  75. if ((version_compare(PHP_VERSION, '5.1.0', '>=') || (version_compare(PHP_VERSION, '5.0.0-dev', '<=') && version_compare(PHP_VERSION, '4.4.0', '>='))) && @preg_match('/\p{L}/u', 'a') !== false)
  76. {
  77. $censors['match'][] = '#(?<![\p{Nd}\p{L}_])(' . str_replace('\*', '[\p{Nd}\p{L}_]*?', preg_quote($row['word'], '#')) . ')(?![\p{Nd}\p{L}_])#u';
  78. }
  79. else
  80. {
  81. $censors['match'][] = '#(?<!\S)(' . str_replace('\*', '\S*?', preg_quote($row['word'], '#')) . ')(?!\S)#iu';
  82. }
  83. $censors['replace'][] = $row['replacement'];
  84. }
  85. $db->sql_freeresult($result);
  86. $this->put('_word_censors', $censors);
  87. }
  88. return $censors;
  89. }
  90. /**
  91. * Obtain currently listed icons
  92. */
  93. function obtain_icons()
  94. {
  95. if (($icons = $this->get('_icons')) === false)
  96. {
  97. global $db;
  98. // Topic icons
  99. $sql = 'SELECT *
  100. FROM ' . ICONS_TABLE . '
  101. ORDER BY icons_order';
  102. $result = $db->sql_query($sql);
  103. $icons = array();
  104. while ($row = $db->sql_fetchrow($result))
  105. {
  106. $icons[$row['icons_id']]['img'] = $row['icons_url'];
  107. $icons[$row['icons_id']]['width'] = (int) $row['icons_width'];
  108. $icons[$row['icons_id']]['height'] = (int) $row['icons_height'];
  109. $icons[$row['icons_id']]['display'] = (bool) $row['display_on_posting'];
  110. }
  111. $db->sql_freeresult($result);
  112. $this->put('_icons', $icons);
  113. }
  114. return $icons;
  115. }
  116. /**
  117. * Obtain ranks
  118. */
  119. function obtain_ranks()
  120. {
  121. if (($ranks = $this->get('_ranks')) === false)
  122. {
  123. global $db;
  124. $sql = 'SELECT *
  125. FROM ' . RANKS_TABLE . '
  126. ORDER BY rank_min DESC';
  127. $result = $db->sql_query($sql);
  128. $ranks = array();
  129. while ($row = $db->sql_fetchrow($result))
  130. {
  131. if ($row['rank_special'])
  132. {
  133. $ranks['special'][$row['rank_id']] = array(
  134. 'rank_title' => $row['rank_title'],
  135. 'rank_image' => $row['rank_image']
  136. );
  137. }
  138. else
  139. {
  140. $ranks['normal'][] = array(
  141. 'rank_title' => $row['rank_title'],
  142. 'rank_min' => $row['rank_min'],
  143. 'rank_image' => $row['rank_image']
  144. );
  145. }
  146. }
  147. $db->sql_freeresult($result);
  148. $this->put('_ranks', $ranks);
  149. }
  150. return $ranks;
  151. }
  152. /**
  153. * Obtain allowed extensions
  154. *
  155. * @param mixed $forum_id If false then check for private messaging, if int then check for forum id. If true, then only return extension informations.
  156. *
  157. * @return array allowed extensions array.
  158. */
  159. function obtain_attach_extensions($forum_id)
  160. {
  161. if (($extensions = $this->get('_extensions')) === false)
  162. {
  163. global $db;
  164. $extensions = array(
  165. '_allowed_post' => array(),
  166. '_allowed_pm' => array(),
  167. );
  168. // The rule is to only allow those extensions defined. ;)
  169. $sql = 'SELECT e.extension, g.*
  170. FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g
  171. WHERE e.group_id = g.group_id
  172. AND (g.allow_group = 1 OR g.allow_in_pm = 1)';
  173. $result = $db->sql_query($sql);
  174. while ($row = $db->sql_fetchrow($result))
  175. {
  176. $extension = strtolower(trim($row['extension']));
  177. $extensions[$extension] = array(
  178. 'display_cat' => (int) $row['cat_id'],
  179. 'download_mode' => (int) $row['download_mode'],
  180. 'upload_icon' => trim($row['upload_icon']),
  181. 'max_filesize' => (int) $row['max_filesize'],
  182. 'allow_group' => $row['allow_group'],
  183. 'allow_in_pm' => $row['allow_in_pm'],
  184. );
  185. $allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array();
  186. // Store allowed extensions forum wise
  187. if ($row['allow_group'])
  188. {
  189. $extensions['_allowed_post'][$extension] = (!sizeof($allowed_forums)) ? 0 : $allowed_forums;
  190. }
  191. if ($row['allow_in_pm'])
  192. {
  193. $extensions['_allowed_pm'][$extension] = 0;
  194. }
  195. }
  196. $db->sql_freeresult($result);
  197. $this->put('_extensions', $extensions);
  198. }
  199. // Forum post
  200. if ($forum_id === false)
  201. {
  202. // We are checking for private messages, therefore we only need to get the pm extensions...
  203. $return = array('_allowed_' => array());
  204. foreach ($extensions['_allowed_pm'] as $extension => $check)
  205. {
  206. $return['_allowed_'][$extension] = 0;
  207. $return[$extension] = $extensions[$extension];
  208. }
  209. $extensions = $return;
  210. }
  211. else if ($forum_id === true)
  212. {
  213. return $extensions;
  214. }
  215. else
  216. {
  217. $forum_id = (int) $forum_id;
  218. $return = array('_allowed_' => array());
  219. foreach ($extensions['_allowed_post'] as $extension => $check)
  220. {
  221. // Check for allowed forums
  222. if (is_array($check))
  223. {
  224. $allowed = (!in_array($forum_id, $check)) ? false : true;
  225. }
  226. else
  227. {
  228. $allowed = true;
  229. }
  230. if ($allowed)
  231. {
  232. $return['_allowed_'][$extension] = 0;
  233. $return[$extension] = $extensions[$extension];
  234. }
  235. }
  236. $extensions = $return;
  237. }
  238. if (!isset($extensions['_allowed_']))
  239. {
  240. $extensions['_allowed_'] = array();
  241. }
  242. return $extensions;
  243. }
  244. /**
  245. * Obtain active bots
  246. */
  247. function obtain_bots()
  248. {
  249. if (($bots = $this->get('_bots')) === false)
  250. {
  251. global $db;
  252. switch ($db->sql_layer)
  253. {
  254. case 'mssql':
  255. case 'mssql_odbc':
  256. $sql = 'SELECT user_id, bot_agent, bot_ip
  257. FROM ' . BOTS_TABLE . '
  258. WHERE bot_active = 1
  259. ORDER BY LEN(bot_agent) DESC';
  260. break;
  261. case 'firebird':
  262. $sql = 'SELECT user_id, bot_agent, bot_ip
  263. FROM ' . BOTS_TABLE . '
  264. WHERE bot_active = 1
  265. ORDER BY CHAR_LENGTH(bot_agent) DESC';
  266. break;
  267. // LENGTH supported by MySQL, IBM DB2 and Oracle for sure...
  268. default:
  269. $sql = 'SELECT user_id, bot_agent, bot_ip
  270. FROM ' . BOTS_TABLE . '
  271. WHERE bot_active = 1
  272. ORDER BY LENGTH(bot_agent) DESC';
  273. break;
  274. }
  275. $result = $db->sql_query($sql);
  276. $bots = array();
  277. while ($row = $db->sql_fetchrow($result))
  278. {
  279. $bots[] = $row;
  280. }
  281. $db->sql_freeresult($result);
  282. $this->put('_bots', $bots);
  283. }
  284. return $bots;
  285. }
  286. /**
  287. * Obtain cfg file data
  288. */
  289. function obtain_cfg_items($theme)
  290. {
  291. global $config, $phpbb_root_path;
  292. $parsed_items = array(
  293. 'theme' => array(),
  294. 'template' => array(),
  295. 'imageset' => array()
  296. );
  297. foreach ($parsed_items as $key => $parsed_array)
  298. {
  299. $parsed_array = $this->get('_cfg_' . $key . '_' . $theme[$key . '_path']);
  300. if ($parsed_array === false)
  301. {
  302. $parsed_array = array();
  303. }
  304. $reparse = false;
  305. $filename = $phpbb_root_path . 'styles/' . $theme[$key . '_path'] . '/' . $key . '/' . $key . '.cfg';
  306. if (!file_exists($filename))
  307. {
  308. continue;
  309. }
  310. if (!isset($parsed_array['filetime']) || (($config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime'])))
  311. {
  312. $reparse = true;
  313. }
  314. // Re-parse cfg file
  315. if ($reparse)
  316. {
  317. $parsed_array = parse_cfg_file($filename);
  318. $parsed_array['filetime'] = @filemtime($filename);
  319. $this->put('_cfg_' . $key . '_' . $theme[$key . '_path'], $parsed_array);
  320. }
  321. $parsed_items[$key] = $parsed_array;
  322. }
  323. return $parsed_items;
  324. }
  325. /**
  326. * Obtain disallowed usernames
  327. */
  328. function obtain_disallowed_usernames()
  329. {
  330. if (($usernames = $this->get('_disallowed_usernames')) === false)
  331. {
  332. global $db;
  333. $sql = 'SELECT disallow_username
  334. FROM ' . DISALLOW_TABLE;
  335. $result = $db->sql_query($sql);
  336. $usernames = array();
  337. while ($row = $db->sql_fetchrow($result))
  338. {
  339. $usernames[] = str_replace('%', '.*?', preg_quote(utf8_clean_string($row['disallow_username']), '#'));
  340. }
  341. $db->sql_freeresult($result);
  342. $this->put('_disallowed_usernames', $usernames);
  343. }
  344. return $usernames;
  345. }
  346. /**
  347. * Obtain hooks...
  348. */
  349. function obtain_hooks()
  350. {
  351. global $phpbb_root_path, $phpEx;
  352. if (($hook_files = $this->get('_hooks')) === false)
  353. {
  354. $hook_files = array();
  355. // Now search for hooks...
  356. $dh = @opendir($phpbb_root_path . 'includes/hooks/');
  357. if ($dh)
  358. {
  359. while (($file = readdir($dh)) !== false)
  360. {
  361. if (strpos($file, 'hook_') === 0 && substr($file, -(strlen($phpEx) + 1)) === '.' . $phpEx)
  362. {
  363. $hook_files[] = substr($file, 0, -(strlen($phpEx) + 1));
  364. }
  365. }
  366. closedir($dh);
  367. }
  368. $this->put('_hooks', $hook_files);
  369. }
  370. return $hook_files;
  371. }
  372. }
  373. ?>