From 459e5e161f8f2089359e575f7e2a9960fb16fca4 Mon Sep 17 00:00:00 2001 From: Roman Kelesidis Date: Sat, 28 Oct 2023 17:15:41 +0700 Subject: [PATCH] Some cleanup (#1003) --- bt/announce.php | 2 +- library/ajax/manage_admin.php | 4 +--- library/includes/functions.php | 14 ++++++++++++++ library/includes/init_bb.php | 14 -------------- src/Legacy/Cache/Sqlite.php | 1 + src/Legacy/Cache/SqliteCommon.php | 17 ----------------- src/Legacy/Caches.php | 20 -------------------- src/Legacy/Datastore/SqliteCommon.php | 17 ----------------- 8 files changed, 17 insertions(+), 72 deletions(-) diff --git a/bt/announce.php b/bt/announce.php index cec592bb1..2b58f8726 100644 --- a/bt/announce.php +++ b/bt/announce.php @@ -70,7 +70,7 @@ if (!isset($info_hash)) { $info_hash_hex = bin2hex($info_hash); // Store peer id -$peer_id_sql = rtrim(DB()->escape(htmlspecialchars($peer_id, ENT_QUOTES, 'UTF-8', false)), ' '); +$peer_id_sql = rtrim(DB()->escape(htmlCHR($peer_id)), ' '); // Check info_hash version if (strlen($info_hash) === 32) { diff --git a/library/ajax/manage_admin.php b/library/ajax/manage_admin.php index 02789fcf1..869eebcd6 100644 --- a/library/ajax/manage_admin.php +++ b/library/ajax/manage_admin.php @@ -20,9 +20,7 @@ if (!$mode = (string)$this->request['mode']) { switch ($mode) { case 'clear_cache': foreach ($bb_cfg['cache']['engines'] as $cache_name => $cache_val) { - if (!in_array('db_sqlite', $cache_val)) { - CACHE($cache_name)->rm(); - } + CACHE($cache_name)->rm(); } $this->response['cache_html'] = '' . $lang['ALL_CACHE_CLEARED'] . ''; diff --git a/library/includes/functions.php b/library/includes/functions.php index a90fd7fd5..b57c96c9e 100644 --- a/library/includes/functions.php +++ b/library/includes/functions.php @@ -787,6 +787,20 @@ function wbr($text, $max_word_length = HTML_WBR_LENGTH) return preg_replace("/([\w\->;:.,~!?(){}@#$%^*\/\\\\]{" . $max_word_length . "})/ui", '$1', $text); } +/** + * Convert special characters to HTML entities + * + * @param $txt + * @param bool $double_encode + * @param int $quote_style + * @param ?string $charset + * @return string + */ +function htmlCHR($txt, bool $double_encode = false, int $quote_style = ENT_QUOTES, ?string $charset = 'UTF-8'): string +{ + return (string)htmlspecialchars($txt ?? '', $quote_style, $charset, $double_encode); +} + function generate_user_info($row, bool $have_auth = IS_ADMIN): array { global $userdata, $lang, $images, $bb_cfg; diff --git a/library/includes/init_bb.php b/library/includes/init_bb.php index cee5db6d2..2f585d85e 100644 --- a/library/includes/init_bb.php +++ b/library/includes/init_bb.php @@ -321,20 +321,6 @@ function send_no_cache_headers() header('Pragma: no-cache'); } -/** - * Convert special characters to HTML entities - * - * @param $txt - * @param bool $double_encode - * @param int $quote_style - * @param ?string $charset - * @return string - */ -function htmlCHR($txt, bool $double_encode = false, int $quote_style = ENT_QUOTES, ?string $charset = 'UTF-8'): string -{ - return (string)htmlspecialchars($txt ?? '', $quote_style, $charset, $double_encode); -} - /** * Adds commas between every group of thousands * diff --git a/src/Legacy/Cache/Sqlite.php b/src/Legacy/Cache/Sqlite.php index b4cfc46c8..c6f365773 100644 --- a/src/Legacy/Cache/Sqlite.php +++ b/src/Legacy/Cache/Sqlite.php @@ -20,6 +20,7 @@ class Sqlite extends Common public $used = true; public $db; public $prefix; + public $engine = 'SQLite'; public $cfg = [ 'db_file_path' => '/path/to/cache.db.sqlite', 'table_name' => 'cache', diff --git a/src/Legacy/Cache/SqliteCommon.php b/src/Legacy/Cache/SqliteCommon.php index 91f3ad0e6..4a256b36e 100644 --- a/src/Legacy/Cache/SqliteCommon.php +++ b/src/Legacy/Cache/SqliteCommon.php @@ -157,23 +157,6 @@ class SqliteCommon extends Common return 'SQLite error #' . $this->dbh->lastErrorCode() . ': ' . $this->dbh->lastErrorMsg(); } - public function rm($name = '') - { - if ($name) { - $this->db->shard($this->prefix . $name); - $result = $this->db->query("DELETE FROM " . $this->cfg['table_name'] . " WHERE cache_name = '" . SQLite3::escapeString($this->prefix . $name) . "'"); - } else { - $result = $this->db->query("DELETE FROM " . $this->cfg['table_name']); - } - return (bool)$result; - } - - public function gc($expire_time = TIMENOW) - { - $result = $this->db->query("DELETE FROM " . $this->cfg['table_name'] . " WHERE cache_expire_time < $expire_time"); - return $result ? sqlite_changes($this->db->dbh) : 0; - } - public function trigger_error($msg = 'DB Error') { if (error_reporting()) { diff --git a/src/Legacy/Caches.php b/src/Legacy/Caches.php index 993952bf3..2e4d0524f 100644 --- a/src/Legacy/Caches.php +++ b/src/Legacy/Caches.php @@ -41,7 +41,6 @@ class Caches } $this->ref[$cache_name] =& $this->obj[$cache_name]; break; - case 'sqlite': if (!isset($this->obj[$cache_name])) { $cache_cfg['pconnect'] = $this->cfg['pconnect']; @@ -51,26 +50,12 @@ class Caches } $this->ref[$cache_name] =& $this->obj[$cache_name]; break; - - case 'db_sqlite': - if (!isset($this->obj[$cache_name])) { - $cache_cfg['pconnect'] = $this->cfg['pconnect']; - $cache_cfg['db_file_path'] = $this->get_db_path($cache_name, $cache_cfg, '.sqlite.db'); - $cache_cfg['table_name'] = $cache_name; - $cache_cfg['table_schema'] = $this->get_table_schema($cache_cfg); - - $this->obj[$cache_name] = new Cache\SqliteCommon($cache_cfg); - } - $this->ref[$cache_name] =& $this->obj[$cache_name]; - break; - case 'redis': if (!isset($this->obj[$cache_name])) { $this->obj[$cache_name] = new Cache\Redis($this->cfg['redis'], $this->cfg['prefix']); } $this->ref[$cache_name] =& $this->obj[$cache_name]; break; - case 'filecache': default: if (!isset($this->obj[$cache_name])) { @@ -93,9 +78,4 @@ class Caches return $this->cfg['db_dir'] . $name . $ext; } - - public function get_table_schema($cfg) - { - return "CREATE TABLE {$cfg['table_name']} ( {$cfg['columns']} )"; - } } diff --git a/src/Legacy/Datastore/SqliteCommon.php b/src/Legacy/Datastore/SqliteCommon.php index 7ce6c6bb6..610298f4c 100644 --- a/src/Legacy/Datastore/SqliteCommon.php +++ b/src/Legacy/Datastore/SqliteCommon.php @@ -157,23 +157,6 @@ class SqliteCommon extends Common return 'SQLite error #' . $this->dbh->lastErrorCode() . ': ' . $this->dbh->lastErrorMsg(); } - public function rm($name = '') - { - if ($name) { - $this->db->shard($this->prefix . $name); - $result = $this->db->query("DELETE FROM " . $this->cfg['table_name'] . " WHERE cache_name = '" . SQLite3::escapeString($this->prefix . $name) . "'"); - } else { - $result = $this->db->query("DELETE FROM " . $this->cfg['table_name']); - } - return (bool)$result; - } - - public function gc($expire_time = TIMENOW) - { - $result = $this->db->query("DELETE FROM " . $this->cfg['table_name'] . " WHERE cache_expire_time < $expire_time"); - return $result ? sqlite_changes($this->db->dbh) : 0; - } - public function trigger_error($msg = 'DB Error') { if (error_reporting()) {