mirror of
https://github.com/torrentpier/torrentpier
synced 2025-08-21 13:54:02 -07:00
Реформат в PSR-2 + добавление заголовков лицензии MIT в файлы
This commit is contained in:
parent
a04df19607
commit
3730bed000
207 changed files with 44327 additions and 43119 deletions
|
@ -1,71 +1,92 @@
|
|||
<?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__));
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
class datastore_apc extends datastore_common
|
||||
{
|
||||
public $engine = 'APC';
|
||||
public $prefix = null;
|
||||
public $engine = 'APC';
|
||||
public $prefix = null;
|
||||
|
||||
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 __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;
|
||||
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++;
|
||||
$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);
|
||||
}
|
||||
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++;
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
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++;
|
||||
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);
|
||||
}
|
||||
}
|
||||
$this->data[$item] = apc_fetch($this->prefix . $item);
|
||||
}
|
||||
}
|
||||
|
||||
public function is_installed ()
|
||||
{
|
||||
return function_exists('apc_fetch');
|
||||
}
|
||||
public function is_installed()
|
||||
{
|
||||
return function_exists('apc_fetch');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,42 @@
|
|||
<?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__));
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
// Don't count on forbidden extensions table, because it is not allowed to allow forbidden extensions at all
|
||||
$extensions = DB()->fetch_rowset("
|
||||
SELECT
|
||||
e.extension, g.cat_id, g.download_mode, g.upload_icon
|
||||
FROM
|
||||
". BB_EXTENSIONS ." e,
|
||||
". BB_EXTENSION_GROUPS ." g
|
||||
" . BB_EXTENSIONS . " e,
|
||||
" . BB_EXTENSION_GROUPS . " g
|
||||
WHERE
|
||||
e.group_id = g.group_id
|
||||
AND g.allow_group = 1
|
||||
");
|
||||
|
||||
$this->store('attach_extensions', $extensions);
|
||||
$this->store('attach_extensions', $extensions);
|
||||
|
|
|
@ -1,6 +1,31 @@
|
|||
<?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__));
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
global $bf, $bb_cfg;
|
||||
|
||||
|
@ -8,96 +33,87 @@ global $bf, $bb_cfg;
|
|||
// cat_forums
|
||||
//
|
||||
$data = array(
|
||||
'not_auth_forums' => array(
|
||||
'guest_view' => array(),
|
||||
'guest_read' => array(),
|
||||
'user_view' => array(),
|
||||
'user_read' => array(),
|
||||
),
|
||||
'tracker_forums' => array(),
|
||||
'cat_title_html' => array(),
|
||||
'forum_name_html' => array(),
|
||||
'c' => array(), // also has $data['c']['cat_id']['forums'] key
|
||||
'f' => array(), // also has $data['f']['forum_id']['subforums'] key
|
||||
'not_auth_forums' => array(
|
||||
'guest_view' => array(),
|
||||
'guest_read' => array(),
|
||||
'user_view' => array(),
|
||||
'user_read' => array(),
|
||||
),
|
||||
'tracker_forums' => array(),
|
||||
'cat_title_html' => array(),
|
||||
'forum_name_html' => array(),
|
||||
'c' => array(), // also has $data['c']['cat_id']['forums'] key
|
||||
'f' => array(), // also has $data['f']['forum_id']['subforums'] key
|
||||
);
|
||||
|
||||
// Store only these fields from BB_FORUMS in $data['f']
|
||||
$forum_store_fields = array_flip(array_keys($bf['forum_perm']));
|
||||
$forum_store_fields += array_flip(array(
|
||||
'forum_id',
|
||||
'cat_id',
|
||||
'forum_name',
|
||||
'forum_desc',
|
||||
'forum_status',
|
||||
'forum_posts',
|
||||
'forum_topics',
|
||||
'forum_parent',
|
||||
'forum_id',
|
||||
'cat_id',
|
||||
'forum_name',
|
||||
'forum_desc',
|
||||
'forum_status',
|
||||
'forum_posts',
|
||||
'forum_topics',
|
||||
'forum_parent',
|
||||
));
|
||||
|
||||
// Categories
|
||||
$sql = "SELECT * FROM ". BB_CATEGORIES ." ORDER BY cat_order";
|
||||
$sql = "SELECT * FROM " . BB_CATEGORIES . " ORDER BY cat_order";
|
||||
|
||||
foreach(DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
$data['c'][$row['cat_id']] = $row;
|
||||
$data['cat_title_html'][$row['cat_id']] = htmlCHR($row['cat_title']);
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
$data['c'][$row['cat_id']] = $row;
|
||||
$data['cat_title_html'][$row['cat_id']] = htmlCHR($row['cat_title']);
|
||||
}
|
||||
|
||||
$sql = "
|
||||
SELECT f.*
|
||||
FROM ". BB_FORUMS ." f, ". BB_CATEGORIES ." c
|
||||
FROM " . BB_FORUMS . " f, " . BB_CATEGORIES . " c
|
||||
WHERE f.cat_id = c.cat_id
|
||||
ORDER BY c.cat_order, f.forum_order
|
||||
";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
$fid = $row['forum_id'];
|
||||
$not_auth =& $data['not_auth_forums'];
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
$fid = $row['forum_id'];
|
||||
$not_auth =& $data['not_auth_forums'];
|
||||
|
||||
// Find not auth forums
|
||||
if ($row['auth_view'] != AUTH_ALL)
|
||||
{
|
||||
$not_auth['guest_view'][] = $fid;
|
||||
}
|
||||
if ($row['auth_view'] != AUTH_ALL && $row['auth_view'] != AUTH_REG)
|
||||
{
|
||||
$not_auth['user_view'][] = $fid;
|
||||
}
|
||||
if ($row['auth_read'] != AUTH_ALL)
|
||||
{
|
||||
$not_auth['guest_read'][] = $fid;
|
||||
}
|
||||
if ($row['auth_read'] != AUTH_ALL && $row['auth_read'] != AUTH_REG)
|
||||
{
|
||||
$not_auth['user_read'][] = $fid;
|
||||
}
|
||||
// Find not auth forums
|
||||
if ($row['auth_view'] != AUTH_ALL) {
|
||||
$not_auth['guest_view'][] = $fid;
|
||||
}
|
||||
if ($row['auth_view'] != AUTH_ALL && $row['auth_view'] != AUTH_REG) {
|
||||
$not_auth['user_view'][] = $fid;
|
||||
}
|
||||
if ($row['auth_read'] != AUTH_ALL) {
|
||||
$not_auth['guest_read'][] = $fid;
|
||||
}
|
||||
if ($row['auth_read'] != AUTH_ALL && $row['auth_read'] != AUTH_REG) {
|
||||
$not_auth['user_read'][] = $fid;
|
||||
}
|
||||
|
||||
$data['forum'][$fid] = $row;
|
||||
$data['forum'][$fid] = $row;
|
||||
|
||||
// Store forums data
|
||||
if ($parent_id = $row['forum_parent'])
|
||||
{
|
||||
$parent =& $data['f'][$parent_id];
|
||||
// Store forums data
|
||||
if ($parent_id = $row['forum_parent']) {
|
||||
$parent =& $data['f'][$parent_id];
|
||||
|
||||
$parent['subforums'][] = $fid;
|
||||
$parent['forum_posts'] += $row['forum_posts'];
|
||||
$parent['forum_topics'] += $row['forum_topics'];
|
||||
}
|
||||
if ($row['allow_reg_tracker'])
|
||||
{
|
||||
$data['tracker_forums'][] = $fid;
|
||||
}
|
||||
$parent['subforums'][] = $fid;
|
||||
$parent['forum_posts'] += $row['forum_posts'];
|
||||
$parent['forum_topics'] += $row['forum_topics'];
|
||||
}
|
||||
if ($row['allow_reg_tracker']) {
|
||||
$data['tracker_forums'][] = $fid;
|
||||
}
|
||||
|
||||
$data['f'][$fid] = array_intersect_key($row, $forum_store_fields);
|
||||
$data['forum_name_html'][$fid] = htmlCHR($row['forum_name']);
|
||||
$data['f'][$fid] = array_intersect_key($row, $forum_store_fields);
|
||||
$data['forum_name_html'][$fid] = htmlCHR($row['forum_name']);
|
||||
|
||||
// Forum ids in cat
|
||||
$data['c'][$row['cat_id']]['forums'][] = $fid;
|
||||
// Forum ids in cat
|
||||
$data['c'][$row['cat_id']]['forums'][] = $fid;
|
||||
}
|
||||
foreach ($data['not_auth_forums'] as $key => $val)
|
||||
{
|
||||
$data['not_auth_forums'][$key] = join(',', $val);
|
||||
foreach ($data['not_auth_forums'] as $key => $val) {
|
||||
$data['not_auth_forums'][$key] = join(',', $val);
|
||||
}
|
||||
$data['tracker_forums'] = join(',', $data['tracker_forums']);
|
||||
|
||||
|
@ -107,20 +123,20 @@ $this->store('cat_forums', $data);
|
|||
// jumpbox
|
||||
//
|
||||
$data = array(
|
||||
'guest' => get_forum_select('guest', 'f', null, null, null, 'id="jumpbox" onchange="window.location.href=\'viewforum.php?f=\'+this.value;"'),
|
||||
'user' => get_forum_select('user', 'f', null, null, null, 'id="jumpbox" onchange="window.location.href=\'viewforum.php?f=\'+this.value;"'),
|
||||
'guest' => get_forum_select('guest', 'f', null, null, null, 'id="jumpbox" onchange="window.location.href=\'viewforum.php?f=\'+this.value;"'),
|
||||
'user' => get_forum_select('user', 'f', null, null, null, 'id="jumpbox" onchange="window.location.href=\'viewforum.php?f=\'+this.value;"'),
|
||||
);
|
||||
|
||||
$this->store('jumpbox', $data);
|
||||
|
||||
file_write($data['guest'], AJAX_HTML_DIR .'jumpbox_guest.html', false, true, true);
|
||||
file_write($data['user'], AJAX_HTML_DIR .'jumpbox_user.html', false, true, true);
|
||||
file_write($data['guest'], AJAX_HTML_DIR . 'jumpbox_guest.html', false, true, true);
|
||||
file_write($data['user'], AJAX_HTML_DIR . 'jumpbox_user.html', false, true, true);
|
||||
|
||||
//
|
||||
// viewtopic_forum_select
|
||||
//
|
||||
$data = array(
|
||||
'viewtopic_forum_select' => get_forum_select('admin', 'new_forum_id'),
|
||||
'viewtopic_forum_select' => get_forum_select('admin', 'new_forum_id'),
|
||||
);
|
||||
|
||||
$this->store('viewtopic_forum_select', $data);
|
||||
|
@ -128,68 +144,62 @@ $this->store('viewtopic_forum_select', $data);
|
|||
//
|
||||
// latest_news
|
||||
//
|
||||
if ($bb_cfg['show_latest_news'] AND $news_forum_ids = $bb_cfg['latest_news_forum_id'])
|
||||
{
|
||||
$news_count = max($bb_cfg['latest_news_count'], 1);
|
||||
if ($bb_cfg['show_latest_news'] and $news_forum_ids = $bb_cfg['latest_news_forum_id']) {
|
||||
$news_count = max($bb_cfg['latest_news_count'], 1);
|
||||
|
||||
$data = DB()->fetch_rowset("
|
||||
$data = DB()->fetch_rowset("
|
||||
SELECT topic_id, topic_time, topic_title, forum_id
|
||||
FROM ". BB_TOPICS ."
|
||||
FROM " . BB_TOPICS . "
|
||||
WHERE forum_id IN ($news_forum_ids)
|
||||
AND topic_moved_id = 0
|
||||
ORDER BY topic_time DESC
|
||||
LIMIT $news_count
|
||||
");
|
||||
|
||||
$this->store('latest_news', $data);
|
||||
$this->store('latest_news', $data);
|
||||
}
|
||||
|
||||
//
|
||||
// Network_news
|
||||
//
|
||||
if ($bb_cfg['show_network_news'] AND $net_forum_ids = $bb_cfg['network_news_forum_id'])
|
||||
{
|
||||
$net_count = max($bb_cfg['network_news_count'], 1);
|
||||
if ($bb_cfg['show_network_news'] and $net_forum_ids = $bb_cfg['network_news_forum_id']) {
|
||||
$net_count = max($bb_cfg['network_news_count'], 1);
|
||||
|
||||
$data = DB()->fetch_rowset("
|
||||
$data = DB()->fetch_rowset("
|
||||
SELECT topic_id, topic_time, topic_title, forum_id
|
||||
FROM ". BB_TOPICS ."
|
||||
FROM " . BB_TOPICS . "
|
||||
WHERE forum_id IN ($net_forum_ids)
|
||||
AND topic_moved_id = 0
|
||||
ORDER BY topic_time DESC
|
||||
LIMIT $net_count
|
||||
");
|
||||
|
||||
$this->store('network_news', $data);
|
||||
$this->store('network_news', $data);
|
||||
}
|
||||
|
||||
//
|
||||
// Ads
|
||||
//
|
||||
if ($bb_cfg['show_ads'])
|
||||
{
|
||||
$ad_html = $ad_block_assignment = array();
|
||||
if ($bb_cfg['show_ads']) {
|
||||
$ad_html = $ad_block_assignment = array();
|
||||
|
||||
$active_ads = DB()->fetch_rowset("
|
||||
$active_ads = DB()->fetch_rowset("
|
||||
SELECT *
|
||||
FROM ". BB_ADS ."
|
||||
FROM " . BB_ADS . "
|
||||
WHERE ad_status = 1
|
||||
AND ad_start_time < NOW()
|
||||
AND DATE_ADD(ad_start_time, INTERVAL ad_active_days DAY) > NOW()
|
||||
");
|
||||
|
||||
foreach ($active_ads as $ad)
|
||||
{
|
||||
if ($ad['ad_block_ids'])
|
||||
{
|
||||
foreach(explode(',', $ad['ad_block_ids']) as $block_id)
|
||||
{
|
||||
$ad_block_assignment[$block_id][] = $ad['ad_id'];
|
||||
}
|
||||
}
|
||||
$ad_html[$ad['ad_id']] = $ad['ad_html'];
|
||||
}
|
||||
foreach ($active_ads as $ad) {
|
||||
if ($ad['ad_block_ids']) {
|
||||
foreach (explode(',', $ad['ad_block_ids']) as $block_id) {
|
||||
$ad_block_assignment[$block_id][] = $ad['ad_id'];
|
||||
}
|
||||
}
|
||||
$ad_html[$ad['ad_id']] = $ad['ad_html'];
|
||||
}
|
||||
|
||||
$this->store('ads', $ad_html);
|
||||
bb_update_config(array('active_ads' => serialize($ad_block_assignment)));
|
||||
}
|
||||
$this->store('ads', $ad_html);
|
||||
bb_update_config(array('active_ads' => serialize($ad_block_assignment)));
|
||||
}
|
||||
|
|
|
@ -1,14 +1,39 @@
|
|||
<?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__));
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'name_users' => array(), // only by personal permissions
|
||||
'name_groups' => array(), // only visible to all users
|
||||
'mod_users' => array(), // only by personal permissions
|
||||
'mod_groups' => array(), // only visible to all users
|
||||
'moderators' => array(), // all moderators
|
||||
'admins' => array(), // all admins
|
||||
'name_users' => array(), // only by personal permissions
|
||||
'name_groups' => array(), // only visible to all users
|
||||
'mod_users' => array(), // only by personal permissions
|
||||
'mod_groups' => array(), // only visible to all users
|
||||
'moderators' => array(), // all moderators
|
||||
'admins' => array(), // all admins
|
||||
);
|
||||
|
||||
// name_users
|
||||
|
@ -17,12 +42,12 @@ $sql = "
|
|||
SELECT
|
||||
aa.forum_id, u.user_id, u.username
|
||||
FROM
|
||||
". BB_AUTH_ACCESS ." aa,
|
||||
". BB_USER_GROUP ." ug,
|
||||
". BB_GROUPS ." g,
|
||||
". BB_USERS ." u
|
||||
" . BB_AUTH_ACCESS . " aa,
|
||||
" . BB_USER_GROUP . " ug,
|
||||
" . BB_GROUPS . " g,
|
||||
" . BB_USERS . " u
|
||||
WHERE
|
||||
aa.forum_perm & ". BF_AUTH_MOD ."
|
||||
aa.forum_perm & " . BF_AUTH_MOD . "
|
||||
AND ug.group_id = aa.group_id
|
||||
AND ug.user_pending = 0
|
||||
AND g.group_id = ug.group_id
|
||||
|
@ -34,10 +59,9 @@ $sql = "
|
|||
u.username
|
||||
";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
$data['name_users'][$row['user_id']] = $row['username'];
|
||||
$data['mod_users'][$row['forum_id']][] = $row['user_id'];
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
$data['name_users'][$row['user_id']] = $row['username'];
|
||||
$data['mod_users'][$row['forum_id']][] = $row['user_id'];
|
||||
}
|
||||
|
||||
// name_groups
|
||||
|
@ -46,23 +70,22 @@ $sql = "
|
|||
SELECT
|
||||
aa.forum_id, g.group_id, g.group_name
|
||||
FROM
|
||||
". BB_AUTH_ACCESS ." aa,
|
||||
". BB_GROUPS ." g
|
||||
" . BB_AUTH_ACCESS . " aa,
|
||||
" . BB_GROUPS . " g
|
||||
WHERE
|
||||
aa.forum_perm & ". BF_AUTH_MOD ."
|
||||
aa.forum_perm & " . BF_AUTH_MOD . "
|
||||
AND g.group_id = aa.group_id
|
||||
AND g.group_single_user = 0
|
||||
AND g.group_type != ". GROUP_HIDDEN ."
|
||||
AND g.group_type != " . GROUP_HIDDEN . "
|
||||
GROUP BY
|
||||
aa.forum_id, g.group_id
|
||||
ORDER BY
|
||||
g.group_name
|
||||
";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
$data['name_groups'][$row['group_id']] = $row['group_name'];
|
||||
$data['mod_groups'][$row['forum_id']][] = $row['group_id'];
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
$data['name_groups'][$row['group_id']] = $row['group_name'];
|
||||
$data['mod_groups'][$row['forum_id']][] = $row['group_id'];
|
||||
}
|
||||
|
||||
// moderators
|
||||
|
@ -70,12 +93,12 @@ $sql = "
|
|||
SELECT
|
||||
u.user_id, u.username
|
||||
FROM
|
||||
". BB_AUTH_ACCESS ." aa,
|
||||
". BB_USER_GROUP ." ug,
|
||||
". BB_GROUPS ." g,
|
||||
". BB_USERS ." u
|
||||
" . BB_AUTH_ACCESS . " aa,
|
||||
" . BB_USER_GROUP . " ug,
|
||||
" . BB_GROUPS . " g,
|
||||
" . BB_USERS . " u
|
||||
WHERE
|
||||
aa.forum_perm & ". BF_AUTH_MOD ."
|
||||
aa.forum_perm & " . BF_AUTH_MOD . "
|
||||
AND ug.group_id = aa.group_id
|
||||
AND ug.user_pending = 0
|
||||
AND g.group_id = ug.group_id
|
||||
|
@ -86,22 +109,20 @@ $sql = "
|
|||
u.username
|
||||
";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
$data['moderators'][$row['user_id']] = $row['username'];
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
$data['moderators'][$row['user_id']] = $row['username'];
|
||||
}
|
||||
|
||||
// admins
|
||||
$sql = "
|
||||
SELECT user_id, username
|
||||
FROM ". BB_USERS ."
|
||||
WHERE user_level = ". ADMIN ."
|
||||
FROM " . BB_USERS . "
|
||||
WHERE user_level = " . ADMIN . "
|
||||
ORDER BY username
|
||||
";
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
$data['admins'][$row['user_id']] = $row['username'];
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
$data['admins'][$row['user_id']] = $row['username'];
|
||||
}
|
||||
|
||||
$this->store('moderators', $data);
|
||||
$this->store('moderators', $data);
|
||||
|
|
|
@ -1,14 +1,38 @@
|
|||
<?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__));
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
$ranks = array();
|
||||
|
||||
$sql = "SELECT rank_id, rank_title, rank_image, rank_style FROM ". BB_RANKS;
|
||||
$sql = "SELECT rank_id, rank_title, rank_image, rank_style FROM " . BB_RANKS;
|
||||
|
||||
foreach (DB()->fetch_rowset($sql) as $row)
|
||||
{
|
||||
$ranks[$row['rank_id']] = $row;
|
||||
foreach (DB()->fetch_rowset($sql) as $row) {
|
||||
$ranks[$row['rank_id']] = $row;
|
||||
}
|
||||
|
||||
$this->store('ranks', $ranks);
|
||||
$this->store('ranks', $ranks);
|
||||
|
|
|
@ -1,19 +1,43 @@
|
|||
<?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__));
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
global $bb_cfg;
|
||||
|
||||
$smilies = array();
|
||||
|
||||
$rowset = DB()->fetch_rowset("SELECT * FROM ". BB_SMILIES);
|
||||
$rowset = DB()->fetch_rowset("SELECT * FROM " . BB_SMILIES);
|
||||
sort($rowset);
|
||||
|
||||
foreach ($rowset as $smile)
|
||||
{
|
||||
$smilies['orig'][] = '#(?<=^|\W)'. preg_quote($smile['code'], '#') .'(?=$|\W)#';
|
||||
$smilies['repl'][] = ' <img class="smile" src="'. $bb_cfg['smilies_path'] .'/'. $smile['smile_url'] .'" alt="'. $smile['emoticon'] .'" align="absmiddle" border="0" />';
|
||||
$smilies['smile'][] = $smile;
|
||||
foreach ($rowset as $smile) {
|
||||
$smilies['orig'][] = '#(?<=^|\W)' . preg_quote($smile['code'], '#') . '(?=$|\W)#';
|
||||
$smilies['repl'][] = ' <img class="smile" src="' . $bb_cfg['smilies_path'] . '/' . $smile['smile_url'] . '" alt="' . $smile['emoticon'] . '" align="absmiddle" border="0" />';
|
||||
$smilies['smile'][] = $smile;
|
||||
}
|
||||
|
||||
$this->store('smile_replacements', $smilies);
|
||||
$this->store('smile_replacements', $smilies);
|
||||
|
|
|
@ -1,96 +1,114 @@
|
|||
<?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__));
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
global $bb_cfg;
|
||||
|
||||
$data = array();
|
||||
|
||||
// usercount
|
||||
$row = DB()->fetch_row("SELECT COUNT(*) AS usercount FROM ". BB_USERS ." WHERE user_id NOT IN(". EXCLUDED_USERS_CSV .")");
|
||||
$row = DB()->fetch_row("SELECT COUNT(*) AS usercount FROM " . BB_USERS . " WHERE user_id NOT IN(" . EXCLUDED_USERS_CSV . ")");
|
||||
$data['usercount'] = number_format($row['usercount']);
|
||||
|
||||
// newestuser
|
||||
$row = DB()->fetch_row("SELECT user_id, username, user_rank FROM ". BB_USERS ." WHERE user_active = 1 ORDER BY user_id DESC LIMIT 1");
|
||||
$row = DB()->fetch_row("SELECT user_id, username, user_rank FROM " . BB_USERS . " WHERE user_active = 1 ORDER BY user_id DESC LIMIT 1");
|
||||
$data['newestuser'] = $row;
|
||||
|
||||
// post/topic count
|
||||
$row = DB()->fetch_row("SELECT SUM(forum_topics) AS topiccount, SUM(forum_posts) AS postcount FROM ". BB_FORUMS);
|
||||
$row = DB()->fetch_row("SELECT SUM(forum_topics) AS topiccount, SUM(forum_posts) AS postcount FROM " . BB_FORUMS);
|
||||
$data['postcount'] = number_format($row['postcount']);
|
||||
$data['topiccount'] = number_format($row['topiccount']);
|
||||
|
||||
// Tracker stats
|
||||
if ($bb_cfg['tor_stats'])
|
||||
{
|
||||
// torrents stat
|
||||
$row = DB()->fetch_row("SELECT COUNT(topic_id) AS torrentcount, SUM(size) AS size FROM ". BB_BT_TORRENTS);
|
||||
$data['torrentcount'] = number_format($row['torrentcount']);
|
||||
$data['size'] = $row['size'];
|
||||
if ($bb_cfg['tor_stats']) {
|
||||
// torrents stat
|
||||
$row = DB()->fetch_row("SELECT COUNT(topic_id) AS torrentcount, SUM(size) AS size FROM " . BB_BT_TORRENTS);
|
||||
$data['torrentcount'] = number_format($row['torrentcount']);
|
||||
$data['size'] = $row['size'];
|
||||
|
||||
// peers stat
|
||||
$row = DB()->fetch_row("SELECT SUM(seeders) AS seeders, SUM(leechers) AS leechers, ((SUM(speed_up) + SUM(speed_down))/2) AS speed FROM ". BB_BT_TRACKER_SNAP);
|
||||
$data['seeders'] = number_format($row['seeders']);
|
||||
$data['leechers'] = number_format($row['leechers']);
|
||||
$data['peers'] = number_format($row['seeders'] + $row['leechers']);
|
||||
$data['speed'] = $row['speed'];
|
||||
// peers stat
|
||||
$row = DB()->fetch_row("SELECT SUM(seeders) AS seeders, SUM(leechers) AS leechers, ((SUM(speed_up) + SUM(speed_down))/2) AS speed FROM " . BB_BT_TRACKER_SNAP);
|
||||
$data['seeders'] = number_format($row['seeders']);
|
||||
$data['leechers'] = number_format($row['leechers']);
|
||||
$data['peers'] = number_format($row['seeders'] + $row['leechers']);
|
||||
$data['speed'] = $row['speed'];
|
||||
}
|
||||
|
||||
// gender stat
|
||||
if ($bb_cfg['gender'])
|
||||
{
|
||||
$male = DB()->fetch_row("SELECT COUNT(user_id) AS male FROM ". BB_USERS ." WHERE user_gender = ". MALE ." AND user_id NOT IN(". EXCLUDED_USERS_CSV .")");
|
||||
$female = DB()->fetch_row("SELECT COUNT(user_id) AS female FROM ". BB_USERS ." WHERE user_gender = ". FEMALE ." AND user_id NOT IN(". EXCLUDED_USERS_CSV .")");
|
||||
$unselect = DB()->fetch_row("SELECT COUNT(user_id) AS unselect FROM ". BB_USERS ." WHERE user_gender = 0 AND user_id NOT IN(". EXCLUDED_USERS_CSV .")");
|
||||
if ($bb_cfg['gender']) {
|
||||
$male = DB()->fetch_row("SELECT COUNT(user_id) AS male FROM " . BB_USERS . " WHERE user_gender = " . MALE . " AND user_id NOT IN(" . EXCLUDED_USERS_CSV . ")");
|
||||
$female = DB()->fetch_row("SELECT COUNT(user_id) AS female FROM " . BB_USERS . " WHERE user_gender = " . FEMALE . " AND user_id NOT IN(" . EXCLUDED_USERS_CSV . ")");
|
||||
$unselect = DB()->fetch_row("SELECT COUNT(user_id) AS unselect FROM " . BB_USERS . " WHERE user_gender = 0 AND user_id NOT IN(" . EXCLUDED_USERS_CSV . ")");
|
||||
|
||||
$data['male'] = $male['male'];
|
||||
$data['female'] = $female['female'];
|
||||
$data['unselect'] = $unselect['unselect'];
|
||||
$data['male'] = $male['male'];
|
||||
$data['female'] = $female['female'];
|
||||
$data['unselect'] = $unselect['unselect'];
|
||||
}
|
||||
|
||||
// birthday stat
|
||||
if ($bb_cfg['birthday_check_day'] && $bb_cfg['birthday_enabled'])
|
||||
{
|
||||
$sql = DB()->fetch_rowset("SELECT user_id, username, user_rank , user_birthday
|
||||
FROM ". BB_USERS ."
|
||||
WHERE user_id NOT IN(". EXCLUDED_USERS_CSV .")
|
||||
if ($bb_cfg['birthday_check_day'] && $bb_cfg['birthday_enabled']) {
|
||||
$sql = DB()->fetch_rowset("SELECT user_id, username, user_rank , user_birthday
|
||||
FROM " . BB_USERS . "
|
||||
WHERE user_id NOT IN(" . EXCLUDED_USERS_CSV . ")
|
||||
AND user_birthday != '0000-00-00'
|
||||
AND user_active = 1
|
||||
ORDER BY user_level DESC, username
|
||||
");
|
||||
|
||||
$date_today = bb_date(TIMENOW, 'md', false);
|
||||
$date_forward = bb_date(TIMENOW + ($bb_cfg['birthday_check_day']*86400), 'md', false);
|
||||
$date_today = bb_date(TIMENOW, 'md', false);
|
||||
$date_forward = bb_date(TIMENOW + ($bb_cfg['birthday_check_day'] * 86400), 'md', false);
|
||||
|
||||
$birthday_today_list = $birthday_week_list = array();
|
||||
$birthday_today_list = $birthday_week_list = array();
|
||||
|
||||
foreach ($sql as $row)
|
||||
{
|
||||
$user_birthday = date('md', strtotime($row['user_birthday']));
|
||||
foreach ($sql as $row) {
|
||||
$user_birthday = date('md', strtotime($row['user_birthday']));
|
||||
|
||||
if ($user_birthday > $date_today && $user_birthday <= $date_forward)
|
||||
{
|
||||
// user are having birthday within the next days
|
||||
$birthday_week_list[] = array(
|
||||
'user_id' => $row['user_id'],
|
||||
'username' => $row['username'],
|
||||
'user_rank' => $row['user_rank'],
|
||||
'user_birthday' => $row['user_birthday'],
|
||||
);
|
||||
}
|
||||
elseif ($user_birthday == $date_today)
|
||||
{
|
||||
//user have birthday today
|
||||
$birthday_today_list[] = array(
|
||||
'user_id' => $row['user_id'],
|
||||
'username' => $row['username'],
|
||||
'user_rank' => $row['user_rank'],
|
||||
'user_birthday' => $row['user_birthday'],
|
||||
);
|
||||
}
|
||||
}
|
||||
if ($user_birthday > $date_today && $user_birthday <= $date_forward) {
|
||||
// user are having birthday within the next days
|
||||
$birthday_week_list[] = array(
|
||||
'user_id' => $row['user_id'],
|
||||
'username' => $row['username'],
|
||||
'user_rank' => $row['user_rank'],
|
||||
'user_birthday' => $row['user_birthday'],
|
||||
);
|
||||
} elseif ($user_birthday == $date_today) {
|
||||
//user have birthday today
|
||||
$birthday_today_list[] = array(
|
||||
'user_id' => $row['user_id'],
|
||||
'username' => $row['username'],
|
||||
'user_rank' => $row['user_rank'],
|
||||
'user_birthday' => $row['user_birthday'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$data['birthday_today_list'] = $birthday_today_list;
|
||||
$data['birthday_week_list'] = $birthday_week_list;
|
||||
$data['birthday_today_list'] = $birthday_today_list;
|
||||
$data['birthday_week_list'] = $birthday_week_list;
|
||||
}
|
||||
|
||||
$this->store('stats', $data);
|
||||
$this->store('stats', $data);
|
||||
|
|
|
@ -1,175 +1,194 @@
|
|||
<?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__));
|
||||
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();
|
||||
/**
|
||||
* Директория с 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',
|
||||
);
|
||||
/**
|
||||
* '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 () {}
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @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 &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 store($item_name, $item_data)
|
||||
{
|
||||
}
|
||||
|
||||
public function rm ($items)
|
||||
{
|
||||
foreach ((array) $items as $item)
|
||||
{
|
||||
unset($this->data[$item]);
|
||||
}
|
||||
}
|
||||
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 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();
|
||||
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);
|
||||
}
|
||||
}
|
||||
foreach ($this->queued_items as $title) {
|
||||
if (!isset($this->data[$title]) || $this->data[$title] === false) {
|
||||
$this->_build_item($title);
|
||||
}
|
||||
}
|
||||
|
||||
$this->queued_items = array();
|
||||
}
|
||||
$this->queued_items = array();
|
||||
}
|
||||
|
||||
public function _fetch_from_store () {}
|
||||
public function _fetch_from_store()
|
||||
{
|
||||
}
|
||||
|
||||
public function _build_item ($title)
|
||||
{
|
||||
if (!empty($this->known_items[$title]))
|
||||
{
|
||||
require(INC_DIR . $this->ds_dir . $this->known_items[$title]);
|
||||
}
|
||||
else
|
||||
{
|
||||
trigger_error("Unknown datastore item: $title", E_USER_ERROR);
|
||||
}
|
||||
}
|
||||
public function _build_item($title)
|
||||
{
|
||||
if (!empty($this->known_items[$title])) {
|
||||
require(INC_DIR . $this->ds_dir . $this->known_items[$title]);
|
||||
} 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 $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 = null;
|
||||
public $dbg = array();
|
||||
public $dbg_id = 0;
|
||||
public $dbg_enabled = false;
|
||||
public $cur_query = null;
|
||||
|
||||
public function debug ($mode, $cur_query = null)
|
||||
{
|
||||
if (!$this->dbg_enabled) return;
|
||||
public function debug($mode, $cur_query = null)
|
||||
{
|
||||
if (!$this->dbg_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
$id =& $this->dbg_id;
|
||||
$dbg =& $this->dbg[$id];
|
||||
$id =& $this->dbg_id;
|
||||
$dbg =& $this->dbg[$id];
|
||||
|
||||
if ($mode == 'start')
|
||||
{
|
||||
$this->sql_starttime = utime();
|
||||
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'] = '';
|
||||
}
|
||||
else if ($mode == 'stop')
|
||||
{
|
||||
$this->cur_query_time = utime() - $this->sql_starttime;
|
||||
$this->sql_timetotal += $this->cur_query_time;
|
||||
$dbg['time'] = $this->cur_query_time;
|
||||
$id++;
|
||||
}
|
||||
}
|
||||
$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';
|
||||
}
|
||||
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,87 +1,105 @@
|
|||
<?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__));
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
class datastore_file extends datastore_common
|
||||
{
|
||||
public $dir = null;
|
||||
public $prefix = null;
|
||||
public $engine = 'Filecache';
|
||||
public $dir = null;
|
||||
public $prefix = null;
|
||||
public $engine = 'Filecache';
|
||||
|
||||
public function __construct ($dir, $prefix = null)
|
||||
{
|
||||
$this->prefix = $prefix;
|
||||
$this->dir = $dir;
|
||||
$this->dbg_enabled = sql_dbg_enabled();
|
||||
}
|
||||
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');
|
||||
public function store($title, $var)
|
||||
{
|
||||
$this->cur_query = "cache->set('$title')";
|
||||
$this->debug('start');
|
||||
|
||||
$this->data[$title] = $var;
|
||||
$this->data[$title] = $var;
|
||||
|
||||
$filename = $this->dir . clean_filename($this->prefix . $title) . '.php';
|
||||
$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 .= '?>';
|
||||
$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++;
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
$this->num_queries++;
|
||||
|
||||
return (bool) file_write($filecache, $filename, false, true, true);
|
||||
}
|
||||
return (bool)file_write($filecache, $filename, false, true, true);
|
||||
}
|
||||
|
||||
public function clean ()
|
||||
{
|
||||
$dir = $this->dir;
|
||||
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;
|
||||
if (is_dir($dir)) {
|
||||
if ($dh = opendir($dir)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
if ($file != "." && $file != "..") {
|
||||
$filename = $dir . $file;
|
||||
|
||||
unlink($filename);
|
||||
}
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
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';
|
||||
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++;
|
||||
$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);
|
||||
if (file_exists($filename)) {
|
||||
require($filename);
|
||||
|
||||
$this->data[$item] = $filecache;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->data[$item] = $filecache;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,103 +1,130 @@
|
|||
<?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__));
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
class datastore_memcache extends datastore_common
|
||||
{
|
||||
public $cfg = null;
|
||||
public $memcache = null;
|
||||
public $connected = false;
|
||||
public $engine = 'Memcache';
|
||||
public $prefix = null;
|
||||
public $cfg = null;
|
||||
public $memcache = null;
|
||||
public $connected = false;
|
||||
public $engine = 'Memcache';
|
||||
public $prefix = null;
|
||||
|
||||
public function __construct ($cfg, $prefix = null)
|
||||
{
|
||||
if (!$this->is_installed())
|
||||
{
|
||||
die('Error: Memcached extension not installed');
|
||||
}
|
||||
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();
|
||||
}
|
||||
$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';
|
||||
public function connect()
|
||||
{
|
||||
$connect_type = ($this->cfg['pconnect']) ? 'pconnect' : 'connect';
|
||||
|
||||
$this->cur_query = $connect_type .' '. $this->cfg['host'] .':'. $this->cfg['port'];
|
||||
$this->debug('start');
|
||||
$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 (@$this->memcache->$connect_type($this->cfg['host'], $this->cfg['port'])) {
|
||||
$this->connected = true;
|
||||
}
|
||||
|
||||
if (DBG_LOG) dbg_log(' ', 'CACHE-connect'. ($this->connected ? '' : '-FAIL'));
|
||||
if (DBG_LOG) {
|
||||
dbg_log(' ', 'CACHE-connect' . ($this->connected ? '' : '-FAIL'));
|
||||
}
|
||||
|
||||
if (!$this->connected && $this->cfg['con_required'])
|
||||
{
|
||||
die('Could not connect to memcached server');
|
||||
}
|
||||
if (!$this->connected && $this->cfg['con_required']) {
|
||||
die('Could not connect to memcached server');
|
||||
}
|
||||
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
}
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
}
|
||||
|
||||
public function store ($title, $var)
|
||||
{
|
||||
if (!$this->connected) $this->connect();
|
||||
$this->data[$title] = $var;
|
||||
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++;
|
||||
$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);
|
||||
}
|
||||
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++;
|
||||
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);
|
||||
}
|
||||
}
|
||||
$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);
|
||||
}
|
||||
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++;
|
||||
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);
|
||||
}
|
||||
}
|
||||
$this->data[$item] = $this->memcache->get($this->prefix . $item);
|
||||
}
|
||||
}
|
||||
|
||||
public function is_installed ()
|
||||
{
|
||||
return class_exists('Memcache');
|
||||
}
|
||||
public function is_installed()
|
||||
{
|
||||
return class_exists('Memcache');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,99 +1,124 @@
|
|||
<?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__));
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
class datastore_redis extends datastore_common
|
||||
{
|
||||
public $cfg = null;
|
||||
public $redis = null;
|
||||
public $prefix = null;
|
||||
public $connected = false;
|
||||
public $engine = 'Redis';
|
||||
public $cfg = null;
|
||||
public $redis = null;
|
||||
public $prefix = null;
|
||||
public $connected = false;
|
||||
public $engine = 'Redis';
|
||||
|
||||
public function __construct ($cfg, $prefix = null)
|
||||
{
|
||||
if (!$this->is_installed())
|
||||
{
|
||||
die('Error: Redis extension not installed');
|
||||
}
|
||||
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;
|
||||
}
|
||||
$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');
|
||||
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->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');
|
||||
}
|
||||
if (!$this->connected && $this->cfg['con_required']) {
|
||||
die('Could not connect to redis server');
|
||||
}
|
||||
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
}
|
||||
$this->debug('stop');
|
||||
$this->cur_query = null;
|
||||
}
|
||||
|
||||
public function store ($title, $var)
|
||||
{
|
||||
if (!$this->connected) $this->connect();
|
||||
$this->data[$title] = $var;
|
||||
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++;
|
||||
$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));
|
||||
}
|
||||
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++;
|
||||
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);
|
||||
}
|
||||
}
|
||||
$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);
|
||||
}
|
||||
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++;
|
||||
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));
|
||||
}
|
||||
}
|
||||
$this->data[$item] = unserialize($this->redis->get($this->prefix . $item));
|
||||
}
|
||||
}
|
||||
|
||||
public function is_installed ()
|
||||
{
|
||||
return class_exists('Redis');
|
||||
}
|
||||
public function is_installed()
|
||||
{
|
||||
return class_exists('Redis');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,66 +1,92 @@
|
|||
<?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__));
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
class datastore_sqlite extends datastore_common
|
||||
{
|
||||
public $engine = 'SQLite';
|
||||
public $db = null;
|
||||
public $prefix = null;
|
||||
public $cfg = array(
|
||||
'db_file_path' => '/path/to/datastore.db.sqlite',
|
||||
'table_name' => 'datastore',
|
||||
'table_schema' => 'CREATE TABLE datastore (
|
||||
public $engine = 'SQLite';
|
||||
public $db = null;
|
||||
public $prefix = null;
|
||||
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',
|
||||
);
|
||||
'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 __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;
|
||||
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));
|
||||
$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')");
|
||||
$result = $this->db->query("REPLACE INTO " . $this->cfg['table_name'] . " (ds_title, ds_data) VALUES ('$ds_title', '$ds_data')");
|
||||
|
||||
return (bool) $result;
|
||||
}
|
||||
return (bool)$result;
|
||||
}
|
||||
|
||||
public function clean ()
|
||||
{
|
||||
$this->db->query("DELETE FROM ". $this->cfg['table_name']);
|
||||
}
|
||||
public function clean()
|
||||
{
|
||||
$this->db->query("DELETE FROM " . $this->cfg['table_name']);
|
||||
}
|
||||
|
||||
public function _fetch_from_store ()
|
||||
{
|
||||
if (!$items = $this->queued_items) return;
|
||||
public function _fetch_from_store()
|
||||
{
|
||||
if (!$items = $this->queued_items) {
|
||||
return;
|
||||
}
|
||||
|
||||
$prefix_len = strlen($this->prefix);
|
||||
$prefix_sql = SQLite3::escapeString($this->prefix);
|
||||
$prefix_len = strlen($this->prefix);
|
||||
$prefix_sql = SQLite3::escapeString($this->prefix);
|
||||
|
||||
array_deep($items, 'SQLite3::escapeString');
|
||||
$items_list = $prefix_sql . join("','$prefix_sql", $items);
|
||||
array_deep($items, 'SQLite3::escapeString');
|
||||
$items_list = $prefix_sql . join("','$prefix_sql", $items);
|
||||
|
||||
$rowset = $this->db->fetch_rowset("SELECT ds_title, ds_data FROM ". $this->cfg['table_name'] ." WHERE ds_title IN ('$items_list')");
|
||||
$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');
|
||||
}
|
||||
$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,72 +1,93 @@
|
|||
<?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__));
|
||||
if (!defined('BB_ROOT')) {
|
||||
die(basename(__FILE__));
|
||||
}
|
||||
|
||||
class datastore_xcache extends datastore_common
|
||||
{
|
||||
public $prefix = null;
|
||||
public $engine = 'XCache';
|
||||
public $prefix = null;
|
||||
public $engine = 'XCache';
|
||||
|
||||
public function __construct ($prefix = null)
|
||||
{
|
||||
if (!$this->is_installed())
|
||||
{
|
||||
die('Error: XCache extension not installed');
|
||||
}
|
||||
public function __construct($prefix = null)
|
||||
{
|
||||
if (!$this->is_installed()) {
|
||||
die('Error: XCache extension not installed');
|
||||
}
|
||||
|
||||
$this->dbg_enabled = sql_dbg_enabled();
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
$this->dbg_enabled = sql_dbg_enabled();
|
||||
$this->prefix = $prefix;
|
||||
}
|
||||
|
||||
public function store ($title, $var)
|
||||
{
|
||||
$this->data[$title] = $var;
|
||||
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++;
|
||||
$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);
|
||||
}
|
||||
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++;
|
||||
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);
|
||||
}
|
||||
}
|
||||
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);
|
||||
}
|
||||
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++;
|
||||
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);
|
||||
}
|
||||
}
|
||||
$this->data[$item] = xcache_get($this->prefix . $item);
|
||||
}
|
||||
}
|
||||
|
||||
public function is_installed ()
|
||||
{
|
||||
return function_exists('xcache_get');
|
||||
}
|
||||
public function is_installed()
|
||||
{
|
||||
return function_exists('xcache_get');
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue