mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-14 18:48:21 -07:00
Some cleanup (#1003)
This commit is contained in:
parent
9dc9453ba7
commit
459e5e161f
8 changed files with 17 additions and 72 deletions
|
@ -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) {
|
||||
|
|
|
@ -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'] = '<span class="seed bold">' . $lang['ALL_CACHE_CLEARED'] . '</span>';
|
||||
|
|
|
@ -787,6 +787,20 @@ function wbr($text, $max_word_length = HTML_WBR_LENGTH)
|
|||
return preg_replace("/([\w\->;:.,~!?(){}@#$%^*\/\\\\]{" . $max_word_length . "})/ui", '$1<wbr>', $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;
|
||||
|
|
|
@ -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
|
||||
*
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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']} )";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue