mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-21 13:54:02 -07:00
PSR-4 compatible legacy code autoloading.
This commit is contained in:
parent
e463fee20f
commit
80a035d191
50 changed files with 5296 additions and 4522 deletions
|
@ -1,92 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2005-2017 TorrentPier
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
class datastore_apc extends datastore_common
|
||||
{
|
||||
public $engine = 'APC';
|
||||
public $prefix;
|
||||
|
||||
public function __construct($prefix = null)
|
||||
{
|
||||
if (!$this->is_installed()) {
|
||||
die('Error: APC extension not installed');
|
||||
}
|
||||
$this->dbg_enabled = sql_dbg_enabled();
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
||||
public function store($title, $var)
|
||||
{
|
||||
$this->data[$title] = $var;
|
||||
|
||||
$this->cur_query = "cache->set('$title')";
|
||||
$this->debug('start');
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
$this->num_queries++;
|
||||
|
||||
return (bool)apc_store($this->prefix . $title, $var);
|
||||
}
|
||||
|
||||
public function clean()
|
||||
{
|
||||
foreach ($this->known_items as $title => $script_name) {
|
||||
$this->cur_query = "cache->rm('$title')";
|
||||
$this->debug('start');
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
$this->num_queries++;
|
||||
|
||||
apc_delete($this->prefix . $title);
|
||||
}
|
||||
}
|
||||
|
||||
public function _fetch_from_store()
|
||||
{
|
||||
if (!$items = $this->queued_items) {
|
||||
$src = $this->_debug_find_caller('enqueue');
|
||||
trigger_error("Datastore: item '$item' already enqueued [$src]", E_USER_ERROR);
|
||||
}
|
||||
|
||||
foreach ($items as $item) {
|
||||
$this->cur_query = "cache->get('$item')";
|
||||
$this->debug('start');
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
$this->num_queries++;
|
||||
|
||||
$this->data[$item] = apc_fetch($this->prefix . $item);
|
||||
}
|
||||
}
|
||||
|
||||
public function is_installed()
|
||||
{
|
||||
return function_exists('apc_fetch');
|
||||
}
|
||||
}
|
|
@ -1,195 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2005-2017 TorrentPier
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
class datastore_common
|
||||
{
|
||||
/**
|
||||
* Директория с builder-скриптами (внутри INC_DIR)
|
||||
*/
|
||||
public $ds_dir = 'datastore';
|
||||
/**
|
||||
* Готовая к употреблению data
|
||||
* array('title' => data)
|
||||
*/
|
||||
public $data = array();
|
||||
/**
|
||||
* Список элементов, которые будут извлечены из хранилища при первом же запросе get()
|
||||
* до этого момента они ставятся в очередь $queued_items для дальнейшего извлечения _fetch()'ем
|
||||
* всех элементов одним запросом
|
||||
* array('title1', 'title2'...)
|
||||
*/
|
||||
public $queued_items = array();
|
||||
|
||||
/**
|
||||
* 'title' => 'builder script name' inside "includes/datastore" dir
|
||||
*/
|
||||
public $known_items = array(
|
||||
'cat_forums' => 'build_cat_forums.php',
|
||||
'jumpbox' => 'build_cat_forums.php',
|
||||
'viewtopic_forum_select' => 'build_cat_forums.php',
|
||||
'latest_news' => 'build_cat_forums.php',
|
||||
'network_news' => 'build_cat_forums.php',
|
||||
'ads' => 'build_cat_forums.php',
|
||||
'moderators' => 'build_moderators.php',
|
||||
'stats' => 'build_stats.php',
|
||||
'ranks' => 'build_ranks.php',
|
||||
'attach_extensions' => 'build_attach_extensions.php',
|
||||
'smile_replacements' => 'build_smilies.php',
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array(item1_title, item2_title...) or single item's title
|
||||
*/
|
||||
public function enqueue($items)
|
||||
{
|
||||
foreach ((array)$items as $item) {
|
||||
// игнор уже поставленного в очередь либо уже извлеченного
|
||||
if (!in_array($item, $this->queued_items) && !isset($this->data[$item])) {
|
||||
$this->queued_items[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function &get($title)
|
||||
{
|
||||
if (!isset($this->data[$title])) {
|
||||
$this->enqueue($title);
|
||||
$this->_fetch();
|
||||
}
|
||||
return $this->data[$title];
|
||||
}
|
||||
|
||||
public function store($item_name, $item_data)
|
||||
{
|
||||
}
|
||||
|
||||
public function rm($items)
|
||||
{
|
||||
foreach ((array)$items as $item) {
|
||||
unset($this->data[$item]);
|
||||
}
|
||||
}
|
||||
|
||||
public function update($items)
|
||||
{
|
||||
if ($items == 'all') {
|
||||
$items = array_keys(array_unique($this->known_items));
|
||||
}
|
||||
foreach ((array)$items as $item) {
|
||||
$this->_build_item($item);
|
||||
}
|
||||
}
|
||||
|
||||
public function _fetch()
|
||||
{
|
||||
$this->_fetch_from_store();
|
||||
|
||||
foreach ($this->queued_items as $title) {
|
||||
if (!isset($this->data[$title]) || $this->data[$title] === false) {
|
||||
$this->_build_item($title);
|
||||
}
|
||||
}
|
||||
|
||||
$this->queued_items = array();
|
||||
}
|
||||
|
||||
public function _fetch_from_store()
|
||||
{
|
||||
}
|
||||
|
||||
public function _build_item($title)
|
||||
{
|
||||
$file = INC_DIR . '/' . $this->ds_dir . '/' . $this->known_items[$title];
|
||||
if (isset($this->known_items[$title]) && file_exists($file)) {
|
||||
require $file;
|
||||
} else {
|
||||
trigger_error("Unknown datastore item: $title", E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
public $num_queries = 0;
|
||||
public $sql_starttime = 0;
|
||||
public $sql_inittime = 0;
|
||||
public $sql_timetotal = 0;
|
||||
public $cur_query_time = 0;
|
||||
|
||||
public $dbg = array();
|
||||
public $dbg_id = 0;
|
||||
public $dbg_enabled = false;
|
||||
public $cur_query;
|
||||
|
||||
public function debug($mode, $cur_query = null)
|
||||
{
|
||||
if (!$this->dbg_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id =& $this->dbg_id;
|
||||
$dbg =& $this->dbg[$id];
|
||||
|
||||
if ($mode == 'start') {
|
||||
$this->sql_starttime = utime();
|
||||
|
||||
$dbg['sql'] = isset($cur_query) ? short_query($cur_query) : short_query($this->cur_query);
|
||||
$dbg['src'] = $this->debug_find_source();
|
||||
$dbg['file'] = $this->debug_find_source('file');
|
||||
$dbg['line'] = $this->debug_find_source('line');
|
||||
$dbg['time'] = '';
|
||||
} elseif ($mode == 'stop') {
|
||||
$this->cur_query_time = utime() - $this->sql_starttime;
|
||||
$this->sql_timetotal += $this->cur_query_time;
|
||||
$dbg['time'] = $this->cur_query_time;
|
||||
$id++;
|
||||
}
|
||||
}
|
||||
|
||||
public function debug_find_source($mode = '')
|
||||
{
|
||||
foreach (debug_backtrace() as $trace) {
|
||||
if ($trace['file'] !== __FILE__) {
|
||||
switch ($mode) {
|
||||
case 'file':
|
||||
return $trace['file'];
|
||||
case 'line':
|
||||
return $trace['line'];
|
||||
default:
|
||||
return hide_bb_path($trace['file']) . '(' . $trace['line'] . ')';
|
||||
}
|
||||
}
|
||||
}
|
||||
return 'src not found';
|
||||
}
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2005-2017 TorrentPier
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
class datastore_file extends datastore_common
|
||||
{
|
||||
public $dir;
|
||||
public $prefix;
|
||||
public $engine = 'Filecache';
|
||||
|
||||
public function __construct($dir, $prefix = null)
|
||||
{
|
||||
$this->prefix = $prefix;
|
||||
$this->dir = $dir;
|
||||
$this->dbg_enabled = sql_dbg_enabled();
|
||||
}
|
||||
|
||||
public function store($title, $var)
|
||||
{
|
||||
$this->cur_query = "cache->set('$title')";
|
||||
$this->debug('start');
|
||||
|
||||
$this->data[$title] = $var;
|
||||
|
||||
$filename = $this->dir . clean_filename($this->prefix . $title) . '.php';
|
||||
|
||||
$filecache = "<?php\n";
|
||||
$filecache .= "if (!defined('BB_ROOT')) die(basename(__FILE__));\n";
|
||||
$filecache .= '$filecache = ' . var_export($var, true) . ";\n";
|
||||
$filecache .= '?>';
|
||||
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
$this->num_queries++;
|
||||
|
||||
return (bool)file_write($filecache, $filename, false, true, true);
|
||||
}
|
||||
|
||||
public function clean()
|
||||
{
|
||||
$dir = $this->dir;
|
||||
|
||||
if (is_dir($dir)) {
|
||||
if ($dh = opendir($dir)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
if ($file != "." && $file != "..") {
|
||||
$filename = $dir . $file;
|
||||
|
||||
unlink($filename);
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function _fetch_from_store()
|
||||
{
|
||||
if (!$items = $this->queued_items) {
|
||||
$src = $this->_debug_find_caller('enqueue');
|
||||
trigger_error("Datastore: item '$item' already enqueued [$src]", E_USER_ERROR);
|
||||
}
|
||||
|
||||
foreach ($items as $item) {
|
||||
$filename = $this->dir . $this->prefix . $item . '.php';
|
||||
|
||||
$this->cur_query = "cache->get('$item')";
|
||||
$this->debug('start');
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
$this->num_queries++;
|
||||
|
||||
if (file_exists($filename)) {
|
||||
require($filename);
|
||||
|
||||
$this->data[$item] = $filecache;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,130 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2005-2017 TorrentPier
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
class datastore_memcache extends datastore_common
|
||||
{
|
||||
public $cfg;
|
||||
public $memcache;
|
||||
public $connected = false;
|
||||
public $engine = 'Memcache';
|
||||
public $prefix;
|
||||
|
||||
public function __construct($cfg, $prefix = null)
|
||||
{
|
||||
if (!$this->is_installed()) {
|
||||
die('Error: Memcached extension not installed');
|
||||
}
|
||||
|
||||
$this->cfg = $cfg;
|
||||
$this->prefix = $prefix;
|
||||
$this->memcache = new Memcache;
|
||||
$this->dbg_enabled = sql_dbg_enabled();
|
||||
}
|
||||
|
||||
public function connect()
|
||||
{
|
||||
$connect_type = ($this->cfg['pconnect']) ? 'pconnect' : 'connect';
|
||||
|
||||
$this->cur_query = $connect_type . ' ' . $this->cfg['host'] . ':' . $this->cfg['port'];
|
||||
$this->debug('start');
|
||||
|
||||
if (@$this->memcache->$connect_type($this->cfg['host'], $this->cfg['port'])) {
|
||||
$this->connected = true;
|
||||
}
|
||||
|
||||
if (DBG_LOG) {
|
||||
dbg_log(' ', 'CACHE-connect' . ($this->connected ? '' : '-FAIL'));
|
||||
}
|
||||
|
||||
if (!$this->connected && $this->cfg['con_required']) {
|
||||
die('Could not connect to memcached server');
|
||||
}
|
||||
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
}
|
||||
|
||||
public function store($title, $var)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
$this->connect();
|
||||
}
|
||||
$this->data[$title] = $var;
|
||||
|
||||
$this->cur_query = "cache->set('$title')";
|
||||
$this->debug('start');
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
$this->num_queries++;
|
||||
|
||||
return (bool)$this->memcache->set($this->prefix . $title, $var);
|
||||
}
|
||||
|
||||
public function clean()
|
||||
{
|
||||
if (!$this->connected) {
|
||||
$this->connect();
|
||||
}
|
||||
foreach ($this->known_items as $title => $script_name) {
|
||||
$this->cur_query = "cache->rm('$title')";
|
||||
$this->debug('start');
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
$this->num_queries++;
|
||||
|
||||
$this->memcache->delete($this->prefix . $title, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public function _fetch_from_store()
|
||||
{
|
||||
if (!$items = $this->queued_items) {
|
||||
$src = $this->_debug_find_caller('enqueue');
|
||||
trigger_error("Datastore: item '$item' already enqueued [$src]", E_USER_ERROR);
|
||||
}
|
||||
|
||||
if (!$this->connected) {
|
||||
$this->connect();
|
||||
}
|
||||
foreach ($items as $item) {
|
||||
$this->cur_query = "cache->get('$item')";
|
||||
$this->debug('start');
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
$this->num_queries++;
|
||||
|
||||
$this->data[$item] = $this->memcache->get($this->prefix . $item);
|
||||
}
|
||||
}
|
||||
|
||||
public function is_installed()
|
||||
{
|
||||
return class_exists('Memcache');
|
||||
}
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2005-2017 TorrentPier
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
class datastore_redis extends datastore_common
|
||||
{
|
||||
public $cfg;
|
||||
public $redis;
|
||||
public $prefix;
|
||||
public $connected = false;
|
||||
public $engine = 'Redis';
|
||||
|
||||
public function __construct($cfg, $prefix = null)
|
||||
{
|
||||
if (!$this->is_installed()) {
|
||||
die('Error: Redis extension not installed');
|
||||
}
|
||||
|
||||
$this->cfg = $cfg;
|
||||
$this->redis = new Redis();
|
||||
$this->dbg_enabled = sql_dbg_enabled();
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
||||
public function connect()
|
||||
{
|
||||
$this->cur_query = 'connect ' . $this->cfg['host'] . ':' . $this->cfg['port'];
|
||||
$this->debug('start');
|
||||
|
||||
if (@$this->redis->connect($this->cfg['host'], $this->cfg['port'])) {
|
||||
$this->connected = true;
|
||||
}
|
||||
|
||||
if (!$this->connected && $this->cfg['con_required']) {
|
||||
die('Could not connect to redis server');
|
||||
}
|
||||
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
}
|
||||
|
||||
public function store($title, $var)
|
||||
{
|
||||
if (!$this->connected) {
|
||||
$this->connect();
|
||||
}
|
||||
$this->data[$title] = $var;
|
||||
|
||||
$this->cur_query = "cache->set('$title')";
|
||||
$this->debug('start');
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
$this->num_queries++;
|
||||
|
||||
return (bool)$this->redis->set($this->prefix . $title, serialize($var));
|
||||
}
|
||||
|
||||
public function clean()
|
||||
{
|
||||
if (!$this->connected) {
|
||||
$this->connect();
|
||||
}
|
||||
foreach ($this->known_items as $title => $script_name) {
|
||||
$this->cur_query = "cache->rm('$title')";
|
||||
$this->debug('start');
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
$this->num_queries++;
|
||||
|
||||
$this->redis->del($this->prefix . $title);
|
||||
}
|
||||
}
|
||||
|
||||
public function _fetch_from_store()
|
||||
{
|
||||
if (!$items = $this->queued_items) {
|
||||
$src = $this->_debug_find_caller('enqueue');
|
||||
trigger_error("Datastore: item '$item' already enqueued [$src]", E_USER_ERROR);
|
||||
}
|
||||
|
||||
if (!$this->connected) {
|
||||
$this->connect();
|
||||
}
|
||||
foreach ($items as $item) {
|
||||
$this->cur_query = "cache->get('$item')";
|
||||
$this->debug('start');
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
$this->num_queries++;
|
||||
|
||||
$this->data[$item] = unserialize($this->redis->get($this->prefix . $item));
|
||||
}
|
||||
}
|
||||
|
||||
public function is_installed()
|
||||
{
|
||||
return class_exists('Redis');
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2005-2017 TorrentPier
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
class datastore_sqlite extends datastore_common
|
||||
{
|
||||
public $engine = 'SQLite';
|
||||
public $db;
|
||||
public $prefix;
|
||||
public $cfg = array(
|
||||
'db_file_path' => '/path/to/datastore.db.sqlite',
|
||||
'table_name' => 'datastore',
|
||||
'table_schema' => 'CREATE TABLE datastore (
|
||||
ds_title VARCHAR(255),
|
||||
ds_data TEXT,
|
||||
PRIMARY KEY (ds_title)
|
||||
)',
|
||||
'pconnect' => true,
|
||||
'con_required' => true,
|
||||
'log_name' => 'DATASTORE',
|
||||
);
|
||||
|
||||
public function __construct($cfg, $prefix = null)
|
||||
{
|
||||
$this->cfg = array_merge($this->cfg, $cfg);
|
||||
$this->db = new sqlite_common($this->cfg);
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
||||
public function store($item_name, $item_data)
|
||||
{
|
||||
$this->data[$item_name] = $item_data;
|
||||
|
||||
$ds_title = SQLite3::escapeString($this->prefix . $item_name);
|
||||
$ds_data = SQLite3::escapeString(serialize($item_data));
|
||||
|
||||
$result = $this->db->query("REPLACE INTO " . $this->cfg['table_name'] . " (ds_title, ds_data) VALUES ('$ds_title', '$ds_data')");
|
||||
|
||||
return (bool)$result;
|
||||
}
|
||||
|
||||
public function clean()
|
||||
{
|
||||
$this->db->query("DELETE FROM " . $this->cfg['table_name']);
|
||||
}
|
||||
|
||||
public function _fetch_from_store()
|
||||
{
|
||||
if (!$items = $this->queued_items) {
|
||||
return;
|
||||
}
|
||||
|
||||
$prefix_len = strlen($this->prefix);
|
||||
$prefix_sql = SQLite3::escapeString($this->prefix);
|
||||
|
||||
array_deep($items, 'SQLite3::escapeString');
|
||||
$items_list = $prefix_sql . implode("','$prefix_sql", $items);
|
||||
|
||||
$rowset = $this->db->fetch_rowset("SELECT ds_title, ds_data FROM " . $this->cfg['table_name'] . " WHERE ds_title IN ('$items_list')");
|
||||
|
||||
$this->db->debug('start', "unserialize()");
|
||||
foreach ($rowset as $row) {
|
||||
$this->data[substr($row['ds_title'], $prefix_len)] = unserialize($row['ds_data']);
|
||||
}
|
||||
$this->db->debug('stop');
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2005-2017 TorrentPier
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
class datastore_xcache extends datastore_common
|
||||
{
|
||||
public $prefix;
|
||||
public $engine = 'XCache';
|
||||
|
||||
public function __construct($prefix = null)
|
||||
{
|
||||
if (!$this->is_installed()) {
|
||||
die('Error: XCache extension not installed');
|
||||
}
|
||||
|
||||
$this->dbg_enabled = sql_dbg_enabled();
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
||||
public function store($title, $var)
|
||||
{
|
||||
$this->data[$title] = $var;
|
||||
|
||||
$this->cur_query = "cache->set('$title')";
|
||||
$this->debug('start');
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
$this->num_queries++;
|
||||
|
||||
return (bool)xcache_set($this->prefix . $title, $var);
|
||||
}
|
||||
|
||||
public function clean()
|
||||
{
|
||||
foreach ($this->known_items as $title => $script_name) {
|
||||
$this->cur_query = "cache->rm('$title')";
|
||||
$this->debug('start');
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
$this->num_queries++;
|
||||
|
||||
xcache_unset($this->prefix . $title);
|
||||
}
|
||||
}
|
||||
|
||||
public function _fetch_from_store()
|
||||
{
|
||||
if (!$items = $this->queued_items) {
|
||||
$src = $this->_debug_find_caller('enqueue');
|
||||
trigger_error("Datastore: item '$item' already enqueued [$src]", E_USER_ERROR);
|
||||
}
|
||||
|
||||
foreach ($items as $item) {
|
||||
$this->cur_query = "cache->set('$item')";
|
||||
$this->debug('start');
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
$this->num_queries++;
|
||||
|
||||
$this->data[$item] = xcache_get($this->prefix . $item);
|
||||
}
|
||||
}
|
||||
|
||||
public function is_installed()
|
||||
{
|
||||
return function_exists('xcache_get');
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue