From 7030578bbe9e11c18b5becaf8b06e670e3c2e3cd Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 14 Jul 2013 01:32:34 -0400 Subject: [ticket/11698] Moving all autoloadable files to phpbb/ PHPBB3-11698 --- phpBB/phpbb/cache/service.php | 406 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 406 insertions(+) create mode 100644 phpBB/phpbb/cache/service.php (limited to 'phpBB/phpbb/cache/service.php') diff --git a/phpBB/phpbb/cache/service.php b/phpBB/phpbb/cache/service.php new file mode 100644 index 0000000000..69c5e0fdd0 --- /dev/null +++ b/phpBB/phpbb/cache/service.php @@ -0,0 +1,406 @@ +set_driver($driver); + $this->config = $config; + $this->db = $db; + $this->phpbb_root_path = $phpbb_root_path; + $this->php_ext = $php_ext; + } + + /** + * Returns the cache driver used by this cache service. + * + * @return phpbb_cache_driver_interface The cache driver + */ + public function get_driver() + { + return $this->driver; + } + + /** + * Replaces the cache driver used by this cache service. + * + * @param phpbb_cache_driver_interface $driver The cache driver + */ + public function set_driver(phpbb_cache_driver_interface $driver) + { + $this->driver = $driver; + } + + public function __call($method, $arguments) + { + return call_user_func_array(array($this->driver, $method), $arguments); + } + + /** + * Obtain list of naughty words and build preg style replacement arrays for use by the + * calling script + */ + function obtain_word_list() + { + if (($censors = $this->driver->get('_word_censors')) === false) + { + $sql = 'SELECT word, replacement + FROM ' . WORDS_TABLE; + $result = $this->db->sql_query($sql); + + $censors = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $censors['match'][] = get_censor_preg_expression($row['word']); + $censors['replace'][] = $row['replacement']; + } + $this->db->sql_freeresult($result); + + $this->driver->put('_word_censors', $censors); + } + + return $censors; + } + + /** + * Obtain currently listed icons + */ + function obtain_icons() + { + if (($icons = $this->driver->get('_icons')) === false) + { + // Topic icons + $sql = 'SELECT * + FROM ' . ICONS_TABLE . ' + ORDER BY icons_order'; + $result = $this->db->sql_query($sql); + + $icons = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $icons[$row['icons_id']]['img'] = $row['icons_url']; + $icons[$row['icons_id']]['width'] = (int) $row['icons_width']; + $icons[$row['icons_id']]['height'] = (int) $row['icons_height']; + $icons[$row['icons_id']]['display'] = (bool) $row['display_on_posting']; + } + $this->db->sql_freeresult($result); + + $this->driver->put('_icons', $icons); + } + + return $icons; + } + + /** + * Obtain ranks + */ + function obtain_ranks() + { + if (($ranks = $this->driver->get('_ranks')) === false) + { + $sql = 'SELECT * + FROM ' . RANKS_TABLE . ' + ORDER BY rank_min DESC'; + $result = $this->db->sql_query($sql); + + $ranks = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + if ($row['rank_special']) + { + $ranks['special'][$row['rank_id']] = array( + 'rank_title' => $row['rank_title'], + 'rank_image' => $row['rank_image'] + ); + } + else + { + $ranks['normal'][] = array( + 'rank_title' => $row['rank_title'], + 'rank_min' => $row['rank_min'], + 'rank_image' => $row['rank_image'] + ); + } + } + $this->db->sql_freeresult($result); + + $this->driver->put('_ranks', $ranks); + } + + return $ranks; + } + + /** + * Obtain allowed extensions + * + * @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. + * + * @return array allowed extensions array. + */ + function obtain_attach_extensions($forum_id) + { + if (($extensions = $this->driver->get('_extensions')) === false) + { + $extensions = array( + '_allowed_post' => array(), + '_allowed_pm' => array(), + ); + + // The rule is to only allow those extensions defined. ;) + $sql = 'SELECT e.extension, g.* + FROM ' . EXTENSIONS_TABLE . ' e, ' . EXTENSION_GROUPS_TABLE . ' g + WHERE e.group_id = g.group_id + AND (g.allow_group = 1 OR g.allow_in_pm = 1)'; + $result = $this->db->sql_query($sql); + + while ($row = $this->db->sql_fetchrow($result)) + { + $extension = strtolower(trim($row['extension'])); + + $extensions[$extension] = array( + 'display_cat' => (int) $row['cat_id'], + 'download_mode' => (int) $row['download_mode'], + 'upload_icon' => trim($row['upload_icon']), + 'max_filesize' => (int) $row['max_filesize'], + 'allow_group' => $row['allow_group'], + 'allow_in_pm' => $row['allow_in_pm'], + 'group_name' => $row['group_name'], + ); + + $allowed_forums = ($row['allowed_forums']) ? unserialize(trim($row['allowed_forums'])) : array(); + + // Store allowed extensions forum wise + if ($row['allow_group']) + { + $extensions['_allowed_post'][$extension] = (!sizeof($allowed_forums)) ? 0 : $allowed_forums; + } + + if ($row['allow_in_pm']) + { + $extensions['_allowed_pm'][$extension] = 0; + } + } + $this->db->sql_freeresult($result); + + $this->driver->put('_extensions', $extensions); + } + + // Forum post + if ($forum_id === false) + { + // We are checking for private messages, therefore we only need to get the pm extensions... + $return = array('_allowed_' => array()); + + foreach ($extensions['_allowed_pm'] as $extension => $check) + { + $return['_allowed_'][$extension] = 0; + $return[$extension] = $extensions[$extension]; + } + + $extensions = $return; + } + else if ($forum_id === true) + { + return $extensions; + } + else + { + $forum_id = (int) $forum_id; + $return = array('_allowed_' => array()); + + foreach ($extensions['_allowed_post'] as $extension => $check) + { + // Check for allowed forums + if (is_array($check)) + { + $allowed = (!in_array($forum_id, $check)) ? false : true; + } + else + { + $allowed = true; + } + + if ($allowed) + { + $return['_allowed_'][$extension] = 0; + $return[$extension] = $extensions[$extension]; + } + } + + $extensions = $return; + } + + if (!isset($extensions['_allowed_'])) + { + $extensions['_allowed_'] = array(); + } + + return $extensions; + } + + /** + * Obtain active bots + */ + function obtain_bots() + { + if (($bots = $this->driver->get('_bots')) === false) + { + switch ($this->db->sql_layer) + { + case 'mssql': + case 'mssql_odbc': + case 'mssqlnative': + $sql = 'SELECT user_id, bot_agent, bot_ip + FROM ' . BOTS_TABLE . ' + WHERE bot_active = 1 + ORDER BY LEN(bot_agent) DESC'; + break; + + case 'firebird': + $sql = 'SELECT user_id, bot_agent, bot_ip + FROM ' . BOTS_TABLE . ' + WHERE bot_active = 1 + ORDER BY CHAR_LENGTH(bot_agent) DESC'; + break; + + // LENGTH supported by MySQL, IBM DB2 and Oracle for sure... + default: + $sql = 'SELECT user_id, bot_agent, bot_ip + FROM ' . BOTS_TABLE . ' + WHERE bot_active = 1 + ORDER BY LENGTH(bot_agent) DESC'; + break; + } + $result = $this->db->sql_query($sql); + + $bots = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $bots[] = $row; + } + $this->db->sql_freeresult($result); + + $this->driver->put('_bots', $bots); + } + + return $bots; + } + + /** + * Obtain cfg file data + */ + function obtain_cfg_items($style) + { + $parsed_array = $this->driver->get('_cfg_' . $style['style_path']); + + if ($parsed_array === false) + { + $parsed_array = array(); + } + + $filename = $this->phpbb_root_path . 'styles/' . $style['style_path'] . '/style.cfg'; + + if (!file_exists($filename)) + { + return $parsed_array; + } + + if (!isset($parsed_array['filetime']) || (($this->config['load_tplcompile'] && @filemtime($filename) > $parsed_array['filetime']))) + { + // Re-parse cfg file + $parsed_array = parse_cfg_file($filename); + $parsed_array['filetime'] = @filemtime($filename); + + $this->driver->put('_cfg_' . $style['style_path'], $parsed_array); + } + + return $parsed_array; + } + + /** + * Obtain disallowed usernames + */ + function obtain_disallowed_usernames() + { + if (($usernames = $this->driver->get('_disallowed_usernames')) === false) + { + $sql = 'SELECT disallow_username + FROM ' . DISALLOW_TABLE; + $result = $this->db->sql_query($sql); + + $usernames = array(); + while ($row = $this->db->sql_fetchrow($result)) + { + $usernames[] = str_replace('%', '.*?', preg_quote(utf8_clean_string($row['disallow_username']), '#')); + } + $this->db->sql_freeresult($result); + + $this->driver->put('_disallowed_usernames', $usernames); + } + + return $usernames; + } +} -- cgit v1.2.1 From da2752e4004b296ae5acdd08b7c0a758d8f61e9d Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 14 Jul 2013 13:30:52 -0400 Subject: [ticket/11700] Modify all code to use the new interface names PHPBB3-11700 --- phpBB/phpbb/cache/service.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/cache/service.php') diff --git a/phpBB/phpbb/cache/service.php b/phpBB/phpbb/cache/service.php index 69c5e0fdd0..02dd3d48a9 100644 --- a/phpBB/phpbb/cache/service.php +++ b/phpBB/phpbb/cache/service.php @@ -24,7 +24,7 @@ class phpbb_cache_service /** * Cache driver. * - * @var phpbb_cache_driver_interface + * @var phpbb_cache_driver_driver_interface */ protected $driver; @@ -59,13 +59,13 @@ class phpbb_cache_service /** * Creates a cache service around a cache driver * - * @param phpbb_cache_driver_interface $driver The cache driver + * @param phpbb_cache_driver_driver_interface $driver The cache driver * @param phpbb_config $config The config * @param phpbb_db_driver $db Database connection * @param string $phpbb_root_path Root path * @param string $php_ext PHP extension */ - public function __construct(phpbb_cache_driver_interface $driver, phpbb_config $config, phpbb_db_driver $db, $phpbb_root_path, $php_ext) + public function __construct(phpbb_cache_driver_driver_interface $driver, phpbb_config $config, phpbb_db_driver $db, $phpbb_root_path, $php_ext) { $this->set_driver($driver); $this->config = $config; @@ -77,7 +77,7 @@ class phpbb_cache_service /** * Returns the cache driver used by this cache service. * - * @return phpbb_cache_driver_interface The cache driver + * @return phpbb_cache_driver_driver_interface The cache driver */ public function get_driver() { @@ -87,9 +87,9 @@ class phpbb_cache_service /** * Replaces the cache driver used by this cache service. * - * @param phpbb_cache_driver_interface $driver The cache driver + * @param phpbb_cache_driver_driver_interface $driver The cache driver */ - public function set_driver(phpbb_cache_driver_interface $driver) + public function set_driver(phpbb_cache_driver_driver_interface $driver) { $this->driver = $driver; } -- cgit v1.2.1 From b95fdacdd378877d277e261465da73deb06e50da Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 10 Sep 2013 14:01:09 +0200 Subject: [ticket/11700] Move all recent code to namespaces PHPBB3-11700 --- phpBB/phpbb/cache/service.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'phpBB/phpbb/cache/service.php') diff --git a/phpBB/phpbb/cache/service.php b/phpBB/phpbb/cache/service.php index 02dd3d48a9..da8f4eb8d8 100644 --- a/phpBB/phpbb/cache/service.php +++ b/phpBB/phpbb/cache/service.php @@ -7,6 +7,8 @@ * */ +namespace phpbb\cache; + /** * @ignore */ @@ -19,26 +21,26 @@ if (!defined('IN_PHPBB')) * Class for grabbing/handling cached entries * @package acm */ -class phpbb_cache_service +class service { /** * Cache driver. * - * @var phpbb_cache_driver_driver_interface + * @var \phpbb\cache\driver\driver_interface */ protected $driver; /** * The config. * - * @var phpbb_config + * @var \phpbb\config\config */ protected $config; /** * Database connection. * - * @var phpbb_db_driver + * @var \phpbb\db\driver\driver */ protected $db; @@ -59,13 +61,13 @@ class phpbb_cache_service /** * Creates a cache service around a cache driver * - * @param phpbb_cache_driver_driver_interface $driver The cache driver - * @param phpbb_config $config The config - * @param phpbb_db_driver $db Database connection + * @param \phpbb\cache\driver\driver_interface $driver The cache driver + * @param \phpbb\config\config $config The config + * @param \phpbb\db\driver\driver $db Database connection * @param string $phpbb_root_path Root path * @param string $php_ext PHP extension */ - public function __construct(phpbb_cache_driver_driver_interface $driver, phpbb_config $config, phpbb_db_driver $db, $phpbb_root_path, $php_ext) + public function __construct(\phpbb\cache\driver\driver_interface $driver, \phpbb\config\config $config, \phpbb\db\driver\driver $db, $phpbb_root_path, $php_ext) { $this->set_driver($driver); $this->config = $config; @@ -77,7 +79,7 @@ class phpbb_cache_service /** * Returns the cache driver used by this cache service. * - * @return phpbb_cache_driver_driver_interface The cache driver + * @return \phpbb\cache\driver\driver_interface The cache driver */ public function get_driver() { @@ -87,9 +89,9 @@ class phpbb_cache_service /** * Replaces the cache driver used by this cache service. * - * @param phpbb_cache_driver_driver_interface $driver The cache driver + * @param \phpbb\cache\driver\driver_interface $driver The cache driver */ - public function set_driver(phpbb_cache_driver_driver_interface $driver) + public function set_driver(\phpbb\cache\driver\driver_interface $driver) { $this->driver = $driver; } -- cgit v1.2.1 From 7aa8f6461f1e85cf91931f56b95384e54fec07c2 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 30 Oct 2013 13:05:28 +0100 Subject: [task/code-sniffer] Remove the IN_PHPBB check side-effect from class files. PHPBB3-11980 --- phpBB/phpbb/cache/service.php | 8 -------- 1 file changed, 8 deletions(-) (limited to 'phpBB/phpbb/cache/service.php') diff --git a/phpBB/phpbb/cache/service.php b/phpBB/phpbb/cache/service.php index da8f4eb8d8..ebbcfb8cdb 100644 --- a/phpBB/phpbb/cache/service.php +++ b/phpBB/phpbb/cache/service.php @@ -9,14 +9,6 @@ namespace phpbb\cache; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - /** * Class for grabbing/handling cached entries * @package acm -- cgit v1.2.1 From 11a9104b8a50cbc62cba0c242dee554b5209a327 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 17 Mar 2014 13:29:35 +0100 Subject: [ticket/12282] Use interface for type hinting PHPBB3-12282 --- phpBB/phpbb/cache/service.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/cache/service.php') diff --git a/phpBB/phpbb/cache/service.php b/phpBB/phpbb/cache/service.php index ebbcfb8cdb..f9b6324b05 100644 --- a/phpBB/phpbb/cache/service.php +++ b/phpBB/phpbb/cache/service.php @@ -32,7 +32,7 @@ class service /** * Database connection. * - * @var \phpbb\db\driver\driver + * @var \phpbb\db\driver\driver_interface */ protected $db; @@ -55,11 +55,11 @@ class service * * @param \phpbb\cache\driver\driver_interface $driver The cache driver * @param \phpbb\config\config $config The config - * @param \phpbb\db\driver\driver $db Database connection + * @param \phpbb\db\driver\driver_interface $db Database connection * @param string $phpbb_root_path Root path * @param string $php_ext PHP extension */ - public function __construct(\phpbb\cache\driver\driver_interface $driver, \phpbb\config\config $config, \phpbb\db\driver\driver $db, $phpbb_root_path, $php_ext) + public function __construct(\phpbb\cache\driver\driver_interface $driver, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, $phpbb_root_path, $php_ext) { $this->set_driver($driver); $this->config = $config; -- cgit v1.2.1 From a759704b39fc1c1353f865a633759b1369589b67 Mon Sep 17 00:00:00 2001 From: Yuriy Rusko Date: Tue, 27 May 2014 20:18:06 +0200 Subject: [ticket/12594] Remove @package tags and update file headers PHPBB3-12594 --- phpBB/phpbb/cache/service.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/cache/service.php') diff --git a/phpBB/phpbb/cache/service.php b/phpBB/phpbb/cache/service.php index f9b6324b05..c9aa6525c0 100644 --- a/phpBB/phpbb/cache/service.php +++ b/phpBB/phpbb/cache/service.php @@ -1,9 +1,13 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ @@ -11,7 +15,6 @@ namespace phpbb\cache; /** * Class for grabbing/handling cached entries -* @package acm */ class service { -- cgit v1.2.1 From 04164affe672be6feea676fd05cf9761bf2e477a Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 20 Jun 2014 12:35:42 +0200 Subject: [ticket/12747] Drop support for Firebird PHPBB3-12747 --- phpBB/phpbb/cache/service.php | 7 ------- 1 file changed, 7 deletions(-) (limited to 'phpBB/phpbb/cache/service.php') diff --git a/phpBB/phpbb/cache/service.php b/phpBB/phpbb/cache/service.php index c9aa6525c0..e47177758a 100644 --- a/phpBB/phpbb/cache/service.php +++ b/phpBB/phpbb/cache/service.php @@ -316,13 +316,6 @@ class service ORDER BY LEN(bot_agent) DESC'; break; - case 'firebird': - $sql = 'SELECT user_id, bot_agent, bot_ip - FROM ' . BOTS_TABLE . ' - WHERE bot_active = 1 - ORDER BY CHAR_LENGTH(bot_agent) DESC'; - break; - // LENGTH supported by MySQL, IBM DB2 and Oracle for sure... default: $sql = 'SELECT user_id, bot_agent, bot_ip -- cgit v1.2.1 From ff6e026a403a622bd1aa498bff396a737735faed Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 26 Jun 2014 17:17:35 +0200 Subject: [ticket/12446] Unnecessary db connect inphpbb_bootstrap_enabled_exts PHPBB3-12446 --- phpBB/phpbb/cache/service.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/cache/service.php') diff --git a/phpBB/phpbb/cache/service.php b/phpBB/phpbb/cache/service.php index e47177758a..d6bf150384 100644 --- a/phpBB/phpbb/cache/service.php +++ b/phpBB/phpbb/cache/service.php @@ -305,7 +305,7 @@ class service { if (($bots = $this->driver->get('_bots')) === false) { - switch ($this->db->sql_layer) + switch ($this->db->get_sql_layer()) { case 'mssql': case 'mssql_odbc': -- cgit v1.2.1 From 08264ec3af0a372ae25a7ccbe318e939b76c30ba Mon Sep 17 00:00:00 2001 From: PayBas Date: Thu, 10 Jul 2014 17:54:08 +0200 Subject: [ticket/12838] Allow for extra columns in cache obtain_ranks() PHPBB3-12838 --- phpBB/phpbb/cache/service.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'phpBB/phpbb/cache/service.php') diff --git a/phpBB/phpbb/cache/service.php b/phpBB/phpbb/cache/service.php index d6bf150384..a86e8c31de 100644 --- a/phpBB/phpbb/cache/service.php +++ b/phpBB/phpbb/cache/service.php @@ -166,20 +166,21 @@ class service $ranks = array(); while ($row = $this->db->sql_fetchrow($result)) { - if ($row['rank_special']) + foreach ($row as $field => $data) { - $ranks['special'][$row['rank_id']] = array( - 'rank_title' => $row['rank_title'], - 'rank_image' => $row['rank_image'] - ); - } - else - { - $ranks['normal'][] = array( - 'rank_title' => $row['rank_title'], - 'rank_min' => $row['rank_min'], - 'rank_image' => $row['rank_image'] - ); + if ($field == 'rank_special' || ($row['rank_special'] && $field == 'rank_min')) + { + continue; + } + + if ($row['rank_special']) + { + $ranks['special'][$row['rank_id']][$field] = $data; + } + else + { + $ranks['normal'][$row['rank_id']][$field] = $data; + } } } $this->db->sql_freeresult($result); -- cgit v1.2.1 From 80067467805d4b1664777cf3553c39fc32cfdb65 Mon Sep 17 00:00:00 2001 From: n-aleha Date: Thu, 7 Aug 2014 13:19:49 +0300 Subject: [ticket/12557] Fix php file description PHPBB3-12557 --- phpBB/phpbb/cache/service.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/cache/service.php') diff --git a/phpBB/phpbb/cache/service.php b/phpBB/phpbb/cache/service.php index d6bf150384..b890d90558 100644 --- a/phpBB/phpbb/cache/service.php +++ b/phpBB/phpbb/cache/service.php @@ -47,7 +47,7 @@ class service protected $phpbb_root_path; /** - * PHP extension. + * PHP file extension. * * @var string */ @@ -60,7 +60,7 @@ class service * @param \phpbb\config\config $config The config * @param \phpbb\db\driver\driver_interface $db Database connection * @param string $phpbb_root_path Root path - * @param string $php_ext PHP extension + * @param string $php_ext PHP file extension */ public function __construct(\phpbb\cache\driver\driver_interface $driver, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, $phpbb_root_path, $php_ext) { -- cgit v1.2.1 From d8d09e0df2729df000ac8384c48262f8b2d333ac Mon Sep 17 00:00:00 2001 From: PayBas Date: Thu, 7 Aug 2014 14:24:21 +0200 Subject: [ticket/12838] Simplify normal special rank array creation PHPBB3-12838 --- phpBB/phpbb/cache/service.php | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'phpBB/phpbb/cache/service.php') diff --git a/phpBB/phpbb/cache/service.php b/phpBB/phpbb/cache/service.php index a86e8c31de..b06462fcf0 100644 --- a/phpBB/phpbb/cache/service.php +++ b/phpBB/phpbb/cache/service.php @@ -166,21 +166,14 @@ class service $ranks = array(); while ($row = $this->db->sql_fetchrow($result)) { - foreach ($row as $field => $data) + if ($row['rank_special']) { - if ($field == 'rank_special' || ($row['rank_special'] && $field == 'rank_min')) - { - continue; - } - - if ($row['rank_special']) - { - $ranks['special'][$row['rank_id']][$field] = $data; - } - else - { - $ranks['normal'][$row['rank_id']][$field] = $data; - } + unset($row['rank_min']); + $ranks['special'][$row['rank_id']] = $row; + } + else + { + $ranks['normal'][$row['rank_id']] = $row; } } $this->db->sql_freeresult($result); -- cgit v1.2.1