diff --git a/bootstrap.php b/bootstrap.php
index d8072bc3c..be196101f 100644
--- a/bootstrap.php
+++ b/bootstrap.php
@@ -33,6 +33,7 @@ $di = new Di();
$di->register(new ServiceProviders\ConfigServiceProvider, [
'file.system.main' => __DIR__ . '/configs/main.php',
'file.local.main' => __DIR__ . '/configs/local.php',
+ 'config.dbQuery' => "SELECT config_name, config_value FROM bb_config"
]);
//// Application
diff --git a/callseed.php b/callseed.php
index a9d5d6770..51805ec08 100644
--- a/callseed.php
+++ b/callseed.php
@@ -23,6 +23,8 @@
* SOFTWARE.
*/
+use \TorrentPier\Di;
+
define('BB_SCRIPT', 'callseed');
define('BB_ROOT', './');
require_once __DIR__ . '/common.php';
@@ -48,18 +50,18 @@ if ($t_data['seeders'] > 2) {
$ban_user_id = [];
-$sql = DB()->fetch_rowset("SELECT ban_userid FROM " . BB_BANLIST . " WHERE ban_userid != 0");
+$sql = Di::getInstance()->db->fetch_rowset("SELECT ban_userid FROM " . BB_BANLIST . " WHERE ban_userid != 0");
foreach ($sql as $row) {
$ban_user_id[] = ',' . $row['ban_userid'];
}
$ban_user_id = join('', $ban_user_id);
-$user_list = DB()->fetch_rowset("
+$user_list = Di::getInstance()->db->fetch_rowset("
SELECT DISTINCT dl.user_id, u.user_opt, tr.user_id as active_dl
FROM " . BB_BT_DLSTATUS . " dl
- LEFT JOIN " . BB_USERS . " u ON(u.user_id = dl.user_id)
- LEFT JOIN " . BB_BT_TRACKER . " tr ON(tr.user_id = dl.user_id)
+ LEFT JOIN bb_users u ON(u.user_id = dl.user_id)
+ LEFT JOIN bb_bt_tracker tr ON(tr.user_id = dl.user_id)
WHERE dl.topic_id = $topic_id
AND dl.user_status IN (" . DL_STATUS_COMPLETE . ", " . DL_STATUS_DOWN . ")
AND dl.user_id NOT IN ({$userdata['user_id']}, " . EXCLUDED_USERS . $ban_user_id . ")
@@ -84,7 +86,7 @@ if ($user_list) {
send_pm($t_data['poster_id'], $subject, $message, BOT_UID);
}
-DB()->query("UPDATE " . BB_BT_TORRENTS . " SET call_seed_time = " . TIMENOW . " WHERE topic_id = $topic_id LIMIT 1");
+Di::getInstance()->db->query("UPDATE bb_bt_torrents SET call_seed_time = " . TIMENOW . " WHERE topic_id = $topic_id LIMIT 1");
meta_refresh(TOPIC_URL . $topic_id);
bb_die($lang['CALLSEED_MSG_OK']);
@@ -97,13 +99,13 @@ function topic_info($topic_id)
SELECT
tor.poster_id, tor.forum_id, tor.call_seed_time,
t.topic_title, sn.seeders
- FROM " . BB_BT_TORRENTS . " tor
- LEFT JOIN " . BB_TOPICS . " t USING(topic_id)
- LEFT JOIN " . BB_BT_TRACKER_SNAP . " sn USING(topic_id)
+ FROM bb_bt_torrents tor
+ LEFT JOIN bb_topics t USING(topic_id)
+ LEFT JOIN bb_bt_tracker_snap sn USING(topic_id)
WHERE tor.topic_id = $topic_id
";
- if (!$torrent = DB()->fetch_row($sql)) {
+ if (!$torrent = Di::getInstance()->db->fetch_row($sql)) {
bb_die($lang['TOPIC_POST_NOT_EXIST']);
}
diff --git a/common.php b/common.php
index fbe2978f6..eadab9244 100644
--- a/common.php
+++ b/common.php
@@ -23,6 +23,9 @@
* SOFTWARE.
*/
+use TorrentPier\Di;
+use TorrentPier\ServiceProviders;
+
if (isset($_REQUEST['GLOBALS'])) {
die();
}
@@ -64,16 +67,17 @@ require_once(BB_ROOT . 'vendor/autoload.php');
// Get initial config
require_once(BB_ROOT . 'library/config.php');
-$di = new \TorrentPier\Di();
+$di = new Di();
// TODO: Need to get locale from settings
$di['settings.locale'] = function ($di) {
return 'en';
};
-$di->register(new \TorrentPier\ServiceProviders\ConfigServiceProvider, [
- 'file.system.main' => __DIR__ . '/library/config.php',
- 'file.local.main' => __DIR__ . '/library/config.local.php',
+$di->register(new ServiceProviders\ConfigServiceProvider, [
+ 'file.system.main' => __DIR__ . '/configs/main.php',
+ 'file.local.main' => __DIR__ . '/configs/local.php',
+ 'config.dbQuery' => "SELECT config_name, config_value FROM bb_config"
]);
$di->register(new \TorrentPier\ServiceProviders\LogServiceProvider());
@@ -86,9 +90,9 @@ $di->register(new \TorrentPier\ServiceProviders\TranslationServiceProvider());
$di->register(new \TorrentPier\ServiceProviders\TwigServiceProvider());
$di->register(new \TorrentPier\ServiceProviders\CaptchaServiceProvider());
-$page_cfg = $di->config->page->toArray();
-$tr_cfg = $di->config->tracker->toArray();
-$rating_limits = $di->config->rating->toArray();
+$page_cfg = $di->config->page;
+$tr_cfg = $di->config->tracker;
+$rating_limits = $di->config->rating;
define('BB_CFG_LOADED', true);
// Load Zend Framework
@@ -141,28 +145,17 @@ require(CORE_DIR . 'dbs.php');
$DBS = new DBS([
'db' => [
'db' => [
- $di->config->services->db->hostname,
- $di->config->services->db->database,
- $di->config->services->db->username,
- $di->config->services->db->password,
- $di->config->services->db->charset,
+ $di->config->get("services.db.hostname"),
+ $di->config->get("services.db.database"),
+ $di->config->get("services.db.username"),
+ $di->config->get("services.db.password"),
+ $di->config->get("services.db.charset"),
false
]
],
'db_alias' => $di->config->get('db_alias')
]);
-/**
- * TODO: @deprecated
- * @param string $db_alias
- * @return mixed
- */
-function DB($db_alias = 'db')
-{
- global $DBS;
- return $DBS->get_db_obj($db_alias);
-}
-
/**
* Datastore
* TODO: @deprecated
diff --git a/configs/main.php b/configs/main.php
index 5a5b97763..c2ad60a8c 100644
--- a/configs/main.php
+++ b/configs/main.php
@@ -30,11 +30,11 @@ return [
// Database
'db' => [
'debug' => '{self.debug}',
- 'driver' => 'Pdo_Mysql',
+ 'type' => 'mysql',
'hostname' => '127.0.0.1',
'database' => 'tp_220',
'username' => 'user',
- 'password' => 'pass',
+ 'password' => function() { return 'pass'; },
'charset' => 'utf8'
],
diff --git a/dl_list.php b/dl_list.php
index 229eb8bda..7ef6c2cdf 100644
--- a/dl_list.php
+++ b/dl_list.php
@@ -23,6 +23,8 @@
* SOFTWARE.
*/
+use \TorrentPier\Di;
+
define('BB_SCRIPT', 'dl_list');
define('BB_ROOT', './');
require_once __DIR__ . '/common.php';
@@ -83,9 +85,9 @@ if (isset($_POST['cancel']) && $_POST['cancel']) {
// Delete DL-list
if ($mode == 'dl_delete' && $topic_id) {
if (!IS_ADMIN) {
- $sql = "SELECT forum_id FROM " . BB_TOPICS . " WHERE topic_id = $topic_id LIMIT 1";
+ $sql = "SELECT forum_id FROM bb_topics WHERE topic_id = $topic_id LIMIT 1";
- if (!$row = DB()->sql_fetchrow(DB()->sql_query($sql))) {
+ if (!$row = Di::getInstance()->db->sql_fetchrow(Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not obtain forum_id for this topic');
}
@@ -131,9 +133,9 @@ if ($mode == 'set_topics_dl_status') {
// Get existing topics
if ($req_topics_sql = join(',', $req_topics_ary)) {
- $sql = "SELECT topic_id FROM " . BB_TOPICS . " WHERE topic_id IN($req_topics_sql)";
+ $sql = "SELECT topic_id FROM bb_topics WHERE topic_id IN($req_topics_sql)";
- foreach (DB()->fetch_rowset($sql) as $row) {
+ foreach (Di::getInstance()->db->fetch_rowset($sql) as $row) {
$topics_ary[] = $row['topic_id'];
}
}
@@ -148,9 +150,9 @@ if ($topics_ary && ($mode == 'set_dl_status' || $mode == 'set_topics_dl_status')
'user_status' => (int)$new_dl_status,
);
}
- $new_dlstatus_sql = DB()->build_array('MULTI_INSERT', $new_dlstatus_ary);
+ $new_dlstatus_sql = Di::getInstance()->db->build_array('MULTI_INSERT', $new_dlstatus_ary);
- DB()->query("REPLACE INTO " . BB_BT_DLSTATUS . " $new_dlstatus_sql");
+ Di::getInstance()->db->query("REPLACE INTO " . BB_BT_DLSTATUS . " $new_dlstatus_sql");
redirect("$redirect_type?$redirect");
}
diff --git a/group.php b/group.php
index 971f2c1d3..2d5d7b144 100644
--- a/group.php
+++ b/group.php
@@ -23,6 +23,8 @@
* SOFTWARE.
*/
+use \TorrentPier\Di;
+
define('BB_SCRIPT', 'group');
define('BB_ROOT', './');
require(BB_ROOT . 'common.php');
@@ -113,7 +115,7 @@ if (!$group_id) {
" . BB_USER_GROUP . " ug2 ON
ug2.group_id = g.group_id
LEFT JOIN
- " . BB_USERS . " u ON g.group_moderator = u.user_id
+ bb_users u ON g.group_moderator = u.user_id
WHERE
g.group_single_user = 0
GROUP BY g.group_id
@@ -124,7 +126,7 @@ if (!$group_id) {
g.group_name ASC
";
- foreach (DB()->fetch_rowset($sql) as $row) {
+ foreach (Di::getInstance()->db->fetch_rowset($sql) as $row) {
if ($row['is_group_mod']) {
$type = 'MOD';
} elseif ($row['membership'] == $member) {
@@ -198,14 +200,14 @@ if (!$group_id) {
$sql = "SELECT g.group_id, g.group_name, ug.user_id, u.user_email, u.username, u.user_lang
FROM " . BB_GROUPS . " g
- LEFT JOIN " . BB_USERS . " u ON(u.user_id = g.group_moderator)
+ LEFT JOIN bb_users u ON(u.user_id = g.group_moderator)
LEFT JOIN " . BB_USER_GROUP . " ug ON(ug.group_id = g.group_id AND ug.user_id = {$userdata['user_id']})
WHERE g.group_id = $group_id
AND group_single_user = 0
AND g.group_type = " . GROUP_OPEN . "
LIMIT 1";
- $row = $moderator = DB()->fetch_row($sql);
+ $row = $moderator = Di::getInstance()->db->fetch_row($sql);
if (!$row['group_id']) {
bb_die($lang['NO_GROUPS_EXIST']);
@@ -291,7 +293,7 @@ if (!$group_id) {
}
if (!empty($_POST['approve'])) {
- DB()->query("
+ Di::getInstance()->db->query("
UPDATE " . BB_USER_GROUP . " SET
user_pending = 0
WHERE user_id IN($sql_in)
@@ -300,7 +302,7 @@ if (!$group_id) {
update_user_level($sql_in);
} elseif (!empty($_POST['deny']) || !empty($_POST['remove'])) {
- DB()->query("
+ Di::getInstance()->db->query("
DELETE FROM " . BB_USER_GROUP . "
WHERE user_id IN($sql_in)
AND group_id = $group_id
@@ -313,10 +315,10 @@ if (!$group_id) {
// Email users when they are approved
if (!empty($_POST['approve']) && $di->config->get('group_send_email')) {
$sql_select = "SELECT username, user_email, user_lang
- FROM " . BB_USERS . "
+ FROM bb_users
WHERE user_id IN($sql_in)";
- if (!$result = DB()->sql_query($sql_select)) {
+ if (!$result = Di::getInstance()->db->sql_query($sql_select)) {
bb_die('Could not get user email information');
}
@@ -325,7 +327,7 @@ if (!$group_id) {
$emailer->from($di->config->get('sitename') . " <{$di->config->get('board_email')}>");
- foreach (DB()->fetch_rowset($sql_select) as $row) {
+ foreach (Di::getInstance()->db->fetch_rowset($sql_select) as $row) {
$emailer->use_template('group_approved', $row['user_lang']);
$emailer->email_address($row['username'] . " <{$row['user_email']}>");
}
@@ -345,9 +347,9 @@ if (!$group_id) {
// END approve or deny
// Get moderator details for this group
- $group_moderator = DB()->fetch_row("
+ $group_moderator = Di::getInstance()->db->fetch_row("
SELECT *
- FROM " . BB_USERS . "
+ FROM bb_users
WHERE user_id = " . $group_info['group_moderator'] . "
");
@@ -360,7 +362,7 @@ if (!$group_id) {
AND user_id = " . $userdata['user_id'] . "
LIMIT 1";
- if ($row = DB()->fetch_row($sql)) {
+ if ($row = Di::getInstance()->db->fetch_row($sql)) {
if ($row['user_pending'] == 0) {
$is_group_member = true;
} else {
@@ -462,12 +464,12 @@ if (!$group_id) {
}
// Count releases for pagination
- $all_releases = DB()->fetch_rowset("
+ $all_releases = Di::getInstance()->db->fetch_rowset("
SELECT p.topic_id, p.forum_id, p.poster_id, t.topic_title, t.topic_time, f.forum_name, u.username, u.avatar_ext_id, u.user_opt, u.user_rank
FROM " . BB_POSTS . " p
- LEFT JOIN " . BB_TOPICS . " t ON(p.topic_id = t.topic_id)
- LEFT JOIN " . BB_FORUMS . " f ON(p.forum_id= f.forum_id)
- LEFT JOIN " . BB_USERS . " u ON(p.poster_id = u.user_id)
+ LEFT JOIN bb_topics t ON(p.topic_id = t.topic_id)
+ LEFT JOIN bb_forums f ON(p.forum_id= f.forum_id)
+ LEFT JOIN bb_users u ON(p.poster_id = u.user_id)
WHERE p.poster_rg_id = $group_id
ORDER BY t.topic_time DESC
LIMIT $rel_limit
@@ -479,15 +481,15 @@ if (!$group_id) {
$sql = "
SELECT p.topic_id, p.forum_id, p.poster_id, t.topic_title, t.topic_time, f.forum_name, u.username, u.avatar_ext_id, u.user_opt, u.user_rank
FROM " . BB_POSTS . " p
- LEFT JOIN " . BB_TOPICS . " t ON(p.topic_id = t.topic_id)
- LEFT JOIN " . BB_FORUMS . " f ON(p.forum_id= f.forum_id)
- LEFT JOIN " . BB_USERS . " u ON(p.poster_id = u.user_id)
+ LEFT JOIN bb_topics t ON(p.topic_id = t.topic_id)
+ LEFT JOIN bb_forums f ON(p.forum_id= f.forum_id)
+ LEFT JOIN bb_users u ON(p.poster_id = u.user_id)
WHERE p.poster_rg_id = $group_id
ORDER BY t.topic_time DESC
LIMIT $start, $per_page
";
- if (!$releases = DB()->fetch_rowset($sql)) {
+ if (!$releases = Di::getInstance()->db->fetch_rowset($sql)) {
set_die_append_msg(false, false, $group_id);
bb_die($lang['NO_SEARCH_MATCH']);
}
@@ -516,9 +518,9 @@ if (!$group_id) {
default:
// Members
- $count_members = DB()->fetch_rowset("
+ $count_members = Di::getInstance()->db->fetch_rowset("
SELECT u.username, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email, ug.user_pending, ug.user_time
- FROM " . BB_USER_GROUP . " ug, " . BB_USERS . " u
+ FROM " . BB_USER_GROUP . " ug, bb_users u
WHERE ug.group_id = $group_id
AND ug.user_pending = 0
AND ug.user_id <> " . $group_moderator['user_id'] . "
@@ -531,9 +533,9 @@ if (!$group_id) {
$modgroup_pending_count = 0;
// Members
- $group_members = DB()->fetch_rowset("
+ $group_members = Di::getInstance()->db->fetch_rowset("
SELECT u.username, u.avatar_ext_id, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email, ug.user_pending, ug.user_time
- FROM " . BB_USER_GROUP . " ug, " . BB_USERS . " u
+ FROM " . BB_USER_GROUP . " ug, bb_users u
WHERE ug.group_id = $group_id
AND ug.user_pending = 0
AND ug.user_id <> " . $group_moderator['user_id'] . "
@@ -587,9 +589,9 @@ if (!$group_id) {
// Pending
if ($is_moderator) {
- $modgroup_pending_list = DB()->fetch_rowset("
+ $modgroup_pending_list = Di::getInstance()->db->fetch_rowset("
SELECT u.username, u.avatar_ext_id, u.user_rank, u.user_id, u.user_opt, u.user_posts, u.user_regdate, u.user_from, u.user_website, u.user_email
- FROM " . BB_USER_GROUP . " ug, " . BB_USERS . " u
+ FROM " . BB_USER_GROUP . " ug, bb_users u
WHERE ug.group_id = $group_id
AND ug.user_pending = 1
AND u.user_id = ug.user_id
diff --git a/group_edit.php b/group_edit.php
index ad3f84c9e..49d60d5d1 100644
--- a/group_edit.php
+++ b/group_edit.php
@@ -23,6 +23,8 @@
* SOFTWARE.
*/
+use \TorrentPier\Di;
+
define('BB_SCRIPT', 'group_edit');
define('BB_ROOT', './');
require(BB_ROOT . 'common.php');
@@ -65,7 +67,7 @@ if ($is_moderator) {
bb_die(implode($upload->errors));
}
- DB()->query("UPDATE " . BB_GROUPS . " SET avatar_ext_id = $avatar_ext_id WHERE group_id = $group_id LIMIT 1");
+ Di::getInstance()->db->query("UPDATE " . BB_GROUPS . " SET avatar_ext_id = $avatar_ext_id WHERE group_id = $group_id LIMIT 1");
}
}
diff --git a/index.php b/index.php
index 5c4eddd19..c2d0d4153 100644
--- a/index.php
+++ b/index.php
@@ -23,6 +23,8 @@
* SOFTWARE.
*/
+use \TorrentPier\Di;
+
define('BB_SCRIPT', 'index');
define('BB_ROOT', './');
require_once __DIR__ . '/common.php';
@@ -132,11 +134,11 @@ $sql = "
t.topic_id AS last_topic_id, t.topic_title AS last_topic_title,
u.user_id AS last_post_user_id, u.user_rank AS last_post_user_rank,
IF(p.poster_id = $anon, p.post_username, u.username) AS last_post_username
- FROM " . BB_CATEGORIES . " c
- INNER JOIN " . BB_FORUMS . " f ON($forums_join_sql)
+ FROM bb_categories c
+ INNER JOIN bb_forums f ON($forums_join_sql)
$join_p_type " . BB_POSTS . " p ON($posts_join_sql)
- $join_t_type " . BB_TOPICS . " t ON($topics_join_sql)
- LEFT JOIN " . BB_USERS . " u ON(u.user_id = p.poster_id)
+ $join_t_type bb_topics t ON($topics_join_sql)
+ LEFT JOIN bb_users u ON(u.user_id = p.poster_id)
ORDER BY c.cat_order, f.forum_order
";
@@ -153,7 +155,7 @@ $replace_in_parent = array(
$cache_name = 'index_sql_' . md5($sql);
if (!$cache->has($cache_name)) {
$cat_forums = [];
- foreach (DB()->fetch_rowset($sql) as $row) {
+ foreach (Di::getInstance()->db->fetch_rowset($sql) as $row) {
if (!($cat_id = $row['cat_id']) || !($forum_id = $row['forum_id'])) {
continue;
}
@@ -290,13 +292,30 @@ $template->assign_vars(array(
'TOTAL_TOPICS' => sprintf($lang['POSTED_TOPICS_TOTAL'], $stats['topiccount']),
'TOTAL_POSTS' => sprintf($lang['POSTED_ARTICLES_TOTAL'], $stats['postcount']),
'TOTAL_USERS' => sprintf($lang['REGISTERED_USERS_TOTAL'], $stats['usercount']),
- 'TOTAL_GENDER' => ($di->config->get('gender')) ? sprintf($lang['USERS_TOTAL_GENDER'], $stats['male'], $stats['female'], $stats['unselect']) : '',
+ 'TOTAL_GENDER' => ($di->config->get('gender')) ? sprintf(
+ $lang['USERS_TOTAL_GENDER'],
+ $stats['male'] ?? 0,
+ $stats['female'] ?? 0,
+ $stats['unselect'] ?? 0
+ ) : '',
'NEWEST_USER' => sprintf($lang['NEWEST_USER'], profile_url($stats['newestuser'])),
// Tracker stats
- 'TORRENTS_STAT' => ($di->config->get('tor_stats')) ? sprintf($lang['TORRENTS_STAT'], $stats['torrentcount'], humn_size($stats['size'])) : '',
- 'PEERS_STAT' => ($di->config->get('tor_stats')) ? sprintf($lang['PEERS_STAT'], $stats['peers'], $stats['seeders'], $stats['leechers']) : '',
- 'SPEED_STAT' => ($di->config->get('tor_stats')) ? sprintf($lang['SPEED_STAT'], humn_size($stats['speed']) . '/s') : '',
+ 'TORRENTS_STAT' => ($di->config->get('tor_stats')) ? sprintf(
+ $lang['TORRENTS_STAT'],
+ $stats['torrentcount'] ?? 0,
+ humn_size($stats['size'] ?? 0)
+ ) : '',
+ 'PEERS_STAT' => ($di->config->get('tor_stats')) ? sprintf(
+ $lang['PEERS_STAT'],
+ $stats['peers'] ?? 0,
+ $stats['seeders'] ?? 0,
+ $stats['leechers'] ?? 0
+ ) : '',
+ 'SPEED_STAT' => ($di->config->get('tor_stats')) ? sprintf(
+ $lang['SPEED_STAT'],
+ humn_size($stats['speed'] ?? 0) . '/s'
+ ) : '',
'SHOW_MOD_INDEX' => $di->config->get('show_mod_index'),
'FORUM_IMG' => $images['forum'],
'FORUM_NEW_IMG' => $images['forum_new'],
@@ -365,7 +384,7 @@ if ($di->config->get('birthday_check_day') && $di->config->get('birthday_enabled
$week_list = $today_list = array();
$week_all = $today_all = false;
- if ($stats['birthday_week_list']) {
+ if (isset($stats['birthday_week_list'])) {
shuffle($stats['birthday_week_list']);
foreach ($stats['birthday_week_list'] as $i => $week) {
if ($i >= 5) {
@@ -380,7 +399,7 @@ if ($di->config->get('birthday_check_day') && $di->config->get('birthday_enabled
$week_list = sprintf($lang['NOBIRTHDAY_WEEK'], $di->config->get('birthday_check_day'));
}
- if ($stats['birthday_today_list']) {
+ if (isset($stats['birthday_today_list'])) {
shuffle($stats['birthday_today_list']);
foreach ($stats['birthday_today_list'] as $i => $today) {
if ($i >= 5) {
diff --git a/library/includes/cron/jobs/tr_maintenance.php b/library/includes/cron/jobs/tr_maintenance.php
index e6184b7ec..92bfe614c 100644
--- a/library/includes/cron/jobs/tr_maintenance.php
+++ b/library/includes/cron/jobs/tr_maintenance.php
@@ -22,6 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+use \TorrentPier\Di;
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
@@ -41,26 +42,26 @@ $limit_sql = 3000;
$topics_sql = [];
$sql = "SELECT topic_id
- FROM " . BB_BT_TORRENTS . "
+ FROM bb_bt_torrents
WHERE reg_time < $never_seen_time
AND seeder_last_seen < $last_seen_time
LIMIT $limit_sql";
-foreach (DB()->fetch_rowset($sql) as $row) {
+foreach (Di::getInstance()->db->fetch_rowset($sql) as $row) {
$topics_sql[] = $row['topic_id'];
}
$dead_tor_sql = join(',', $topics_sql);
if ($dead_tor_sql) {
// Delete torstat
- DB()->query("
+ Di::getInstance()->db->query("
DELETE FROM " . BB_BT_TORSTAT . "
WHERE topic_id IN($dead_tor_sql)
");
// Remove torrents
- DB()->query("
- DELETE FROM " . BB_BT_TORRENTS . "
+ Di::getInstance()->db->query("
+ DELETE FROM bb_bt_torrents
WHERE topic_id IN($dead_tor_sql)
");
}
diff --git a/library/includes/cron/jobs/tr_make_snapshot.php b/library/includes/cron/jobs/tr_make_snapshot.php
index 7d063aae1..a3110831a 100644
--- a/library/includes/cron/jobs/tr_make_snapshot.php
+++ b/library/includes/cron/jobs/tr_make_snapshot.php
@@ -22,6 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+use \TorrentPier\Di;
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
@@ -30,7 +31,7 @@ if (!defined('BB_ROOT')) {
/** @var \TorrentPier\Di $di */
$di = \TorrentPier\Di::getInstance();
-DB()->expect_slow_query(600);
+Di::getInstance()->db->expect_slow_query(600);
//
// Make tracker snapshot
diff --git a/library/includes/cron/jobs/tr_update_seeder_last_seen.php b/library/includes/cron/jobs/tr_update_seeder_last_seen.php
index 17e48122e..c4ee7a490 100644
--- a/library/includes/cron/jobs/tr_update_seeder_last_seen.php
+++ b/library/includes/cron/jobs/tr_update_seeder_last_seen.php
@@ -22,19 +22,20 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+use \TorrentPier\Di;
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
}
-DB()->query("
+Di::getInstance()->db->query("
UPDATE
" . BUF_LAST_SEEDER . " b,
- " . BB_BT_TORRENTS . " tor
+ bb_bt_torrents tor
SET
tor.seeder_last_seen = b.seeder_last_seen
WHERE
tor.topic_id = b.topic_id
");
-DB()->query("TRUNCATE TABLE " . BUF_LAST_SEEDER);
+Di::getInstance()->db->query("TRUNCATE TABLE " . BUF_LAST_SEEDER);
diff --git a/library/includes/cron/jobs/update_forums_atom.php b/library/includes/cron/jobs/update_forums_atom.php
index 7e62274ed..96b725dfb 100644
--- a/library/includes/cron/jobs/update_forums_atom.php
+++ b/library/includes/cron/jobs/update_forums_atom.php
@@ -22,6 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+use \TorrentPier\Di;
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
@@ -33,7 +34,7 @@ $di = \TorrentPier\Di::getInstance();
require_once(INC_DIR . 'functions_atom.php');
$timecheck = TIMENOW - 600;
-$forums_data = DB()->fetch_rowset("SELECT forum_id, allow_reg_tracker, forum_name FROM " . BB_FORUMS);
+$forums_data = Di::getInstance()->db->fetch_rowset("SELECT forum_id, allow_reg_tracker, forum_name FROM " . BB_FORUMS);
if (file_exists($di->config->get('atom.path') . '/f/0.atom')) {
if (filemtime($di->config->get('atom.path') . '/f/0.atom') <= $timecheck) {
diff --git a/library/includes/datastore/build_ranks.php b/library/includes/datastore/build_ranks.php
index ee3e530dd..d1dcb185a 100644
--- a/library/includes/datastore/build_ranks.php
+++ b/library/includes/datastore/build_ranks.php
@@ -22,6 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+use \TorrentPier\Di;
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
@@ -31,7 +32,7 @@ $ranks = array();
$sql = "SELECT rank_id, rank_title, rank_image, rank_style FROM " . BB_RANKS;
-foreach (DB()->fetch_rowset($sql) as $row) {
+foreach (Di::getInstance()->db->fetch_rowset($sql) as $row) {
$ranks[$row['rank_id']] = $row;
}
diff --git a/library/includes/datastore/build_stats.php b/library/includes/datastore/build_stats.php
index e0955e016..e037d79b1 100644
--- a/library/includes/datastore/build_stats.php
+++ b/library/includes/datastore/build_stats.php
@@ -22,6 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+use \TorrentPier\Di;
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
@@ -33,27 +34,27 @@ $di = \TorrentPier\Di::getInstance();
$data = [];
// usercount
-$row = DB()->fetch_row("SELECT COUNT(*) AS usercount FROM " . BB_USERS . " WHERE user_id NOT IN(" . EXCLUDED_USERS . ")");
+$row = Di::getInstance()->db->fetch_row("SELECT COUNT(*) AS usercount FROM bb_users WHERE user_id NOT IN(" . EXCLUDED_USERS . ")");
$data['usercount'] = commify($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 = Di::getInstance()->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 = Di::getInstance()->db->fetch_row("SELECT SUM(forum_topics) AS topiccount, SUM(forum_posts) AS postcount FROM " . BB_FORUMS);
$data['postcount'] = commify($row['postcount']);
$data['topiccount'] = commify($row['topiccount']);
// Tracker stats
if ($di->config->get('tor_stats')) {
// torrents stat
- $row = DB()->fetch_row("SELECT COUNT(topic_id) AS torrentcount, SUM(size) AS size FROM " . BB_BT_TORRENTS);
+ $row = Di::getInstance()->db->fetch_row("SELECT COUNT(topic_id) AS torrentcount, SUM(size) AS size FROM " . BB_BT_TORRENTS);
$data['torrentcount'] = commify($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);
+ $row = Di::getInstance()->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'] = commify($row['seeders']);
$data['leechers'] = commify($row['leechers']);
$data['peers'] = commify($row['seeders'] + $row['leechers']);
@@ -62,9 +63,9 @@ if ($di->config->get('tor_stats')) {
// gender stat
if ($di->config->get('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 . ")");
- $female = DB()->fetch_row("SELECT COUNT(user_id) AS female FROM " . BB_USERS . " WHERE user_gender = " . FEMALE . " AND user_id NOT IN(" . EXCLUDED_USERS . ")");
- $unselect = DB()->fetch_row("SELECT COUNT(user_id) AS unselect FROM " . BB_USERS . " WHERE user_gender = 0 AND user_id NOT IN(" . EXCLUDED_USERS . ")");
+ $male = Di::getInstance()->db->fetch_row("SELECT COUNT(user_id) AS male FROM bb_users WHERE user_gender = " . MALE . " AND user_id NOT IN(" . EXCLUDED_USERS . ")");
+ $female = Di::getInstance()->db->fetch_row("SELECT COUNT(user_id) AS female FROM bb_users WHERE user_gender = " . FEMALE . " AND user_id NOT IN(" . EXCLUDED_USERS . ")");
+ $unselect = Di::getInstance()->db->fetch_row("SELECT COUNT(user_id) AS unselect FROM bb_users WHERE user_gender = 0 AND user_id NOT IN(" . EXCLUDED_USERS . ")");
$data['male'] = $male['male'];
$data['female'] = $female['female'];
@@ -73,8 +74,8 @@ if ($di->config->get('gender')) {
// birthday stat
if ($di->config->get('birthday_check_day') && $di->config->get('birthday_enabled')) {
- $sql = DB()->fetch_rowset("SELECT user_id, username, user_rank , user_birthday
- FROM " . BB_USERS . "
+ $sql = Di::getInstance()->db->fetch_rowset("SELECT user_id, username, user_rank , user_birthday
+ FROM bb_users
WHERE user_id NOT IN(" . EXCLUDED_USERS . ")
AND user_birthday != '0000-00-00'
AND user_active = 1
diff --git a/library/includes/ucp/activate.php b/library/includes/ucp/activate.php
index 8b62b4afc..43e114934 100644
--- a/library/includes/ucp/activate.php
+++ b/library/includes/ucp/activate.php
@@ -22,6 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+use \TorrentPier\Di;
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
@@ -32,22 +33,22 @@ if (empty($_GET['u']) || empty($_GET['act_key'])) {
}
$sql = "SELECT user_active, user_id, username, user_email, user_newpasswd, user_lang, user_actkey
- FROM " . BB_USERS . "
+ FROM bb_users
WHERE user_id = " . intval($_GET[POST_USERS_URL]);
-if (!($result = DB()->sql_query($sql))) {
+if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not obtain user information');
}
-if ($row = DB()->sql_fetchrow($result)) {
+if ($row = Di::getInstance()->db->sql_fetchrow($result)) {
if ($row['user_active'] && trim($row['user_actkey']) == '') {
bb_die($lang['ALREADY_ACTIVATED']);
} elseif ((trim($row['user_actkey']) == trim($_GET['act_key'])) && (trim($row['user_actkey']) != '')) {
$sql_update_pass = ($row['user_newpasswd'] != '') ? ", user_password = '" . md5(md5($row['user_newpasswd'])) . "', user_newpasswd = ''" : '';
- $sql = "UPDATE " . BB_USERS . "
+ $sql = "UPDATE bb_users
SET user_active = 1, user_actkey = ''" . $sql_update_pass . "
WHERE user_id = " . $row['user_id'];
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not update users table');
}
diff --git a/library/includes/ucp/bonus.php b/library/includes/ucp/bonus.php
index 190636790..2e4e2d091 100644
--- a/library/includes/ucp/bonus.php
+++ b/library/includes/ucp/bonus.php
@@ -22,6 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+use \TorrentPier\Di;
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
@@ -62,7 +63,7 @@ if (isset($_POST['bonus_id'])) {
bb_die($message);
}
- DB()->query("UPDATE " . BB_BT_USERS . " bu, " . BB_USERS . " u
+ Di::getInstance()->db->query("UPDATE " . BB_BT_USERS . " bu, bb_users u
SET
bu.u_up_total = u_up_total + $upload,
u.user_points = u.user_points - $points
diff --git a/library/includes/ucp/email.php b/library/includes/ucp/email.php
index 525a5d02b..744be9e0b 100644
--- a/library/includes/ucp/email.php
+++ b/library/includes/ucp/email.php
@@ -22,6 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+use \TorrentPier\Di;
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
@@ -50,11 +51,11 @@ if (!$userdata['session_logged_in']) {
$errors = array();
$sql = "SELECT username, user_id, user_rank, user_email, user_lang
- FROM " . BB_USERS . "
+ FROM bb_users
WHERE user_id = $user_id
";
-if ($row = DB()->fetch_row($sql)) {
+if ($row = Di::getInstance()->db->fetch_row($sql)) {
$username = $row['username'];
$user_email = $row['user_email'];
$user_lang = $row['user_lang'];
diff --git a/library/includes/ucp/register.php b/library/includes/ucp/register.php
index fc5671818..bdcd371e1 100644
--- a/library/includes/ucp/register.php
+++ b/library/includes/ucp/register.php
@@ -22,6 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+use \TorrentPier\Di;
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
@@ -74,7 +75,7 @@ switch ($mode) {
if (!IS_ADMIN) {
// Ограничение по ip
if ($di->config->get('unique_ip')) {
- if ($users = DB()->fetch_row("SELECT user_id, username FROM " . BB_USERS . " WHERE user_reg_ip = '" . USER_IP . "' LIMIT 1")) {
+ if ($users = Di::getInstance()->db->fetch_row("SELECT user_id, username FROM bb_users WHERE user_reg_ip = '" . USER_IP . "' LIMIT 1")) {
bb_die(sprintf($lang['ALREADY_REG_IP'], '' . $users['username'] . '', $di->config->get('tech_admin_email')));
}
}
@@ -157,11 +158,11 @@ switch ($mode) {
user_rank,
user_level,
$profile_fields_sql
- FROM " . BB_USERS . "
+ FROM bb_users
WHERE user_id = $pr_user_id
LIMIT 1
";
- if (!$pr_data = DB()->fetch_row($sql)) {
+ if (!$pr_data = Di::getInstance()->db->fetch_row($sql)) {
bb_die($lang['PROFILE_NOT_FOUND']);
}
break;
@@ -576,10 +577,10 @@ if ($submit && !$errors) {
$db_data['tpl_name'] = (string)$di->config->get('tpl_name');
}
- $sql_args = DB()->build_array('INSERT', $db_data);
+ $sql_args = Di::getInstance()->db->build_array('INSERT', $db_data);
- DB()->query("INSERT INTO " . BB_USERS . $sql_args);
- $new_user_id = DB()->sql_nextid();
+ Di::getInstance()->db->query("INSERT INTO " . BB_USERS . $sql_args);
+ $new_user_id = Di::getInstance()->db->sql_nextid();
if (IS_ADMIN) {
set_pr_die_append_msg($new_user_id);
@@ -648,9 +649,9 @@ if ($submit && !$errors) {
$message = $lang['PROFILE_UPDATED'];
}
- $sql_args = DB()->build_array('UPDATE', $db_data);
+ $sql_args = Di::getInstance()->db->build_array('UPDATE', $db_data);
- DB()->query("UPDATE " . BB_USERS . " SET $sql_args WHERE user_id = {$pr_data['user_id']} LIMIT 1");
+ Di::getInstance()->db->query("UPDATE bb_users SET $sql_args WHERE user_id = {$pr_data['user_id']} LIMIT 1");
if ($pr_data['user_id'] != $userdata['user_id']) {
if ($pr_data['user_level'] == MOD && !empty($db_data['username'])) {
diff --git a/library/includes/ucp/sendpasswd.php b/library/includes/ucp/sendpasswd.php
index ec32fd661..3b78961c4 100644
--- a/library/includes/ucp/sendpasswd.php
+++ b/library/includes/ucp/sendpasswd.php
@@ -22,6 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+use \TorrentPier\Di;
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
@@ -43,9 +44,9 @@ if (isset($_POST['submit'])) {
bb_die($lang['CAPTCHA_WRONG']);
}
$email = (!empty($_POST['email'])) ? trim(strip_tags(htmlspecialchars($_POST['email']))) : '';
- $sql = "SELECT * FROM " . BB_USERS . " WHERE user_email = '" . DB()->escape($email) . "'";
- if ($result = DB()->sql_query($sql)) {
- if ($row = DB()->sql_fetchrow($result)) {
+ $sql = "SELECT * FROM bb_users WHERE user_email = '" . Di::getInstance()->db->escape($email) . "'";
+ if ($result = Di::getInstance()->db->sql_query($sql)) {
+ if ($row = Di::getInstance()->db->sql_fetchrow($result)) {
if (!$row['user_active']) {
bb_die($lang['NO_SEND_ACCOUNT_INACTIVE']);
}
@@ -59,10 +60,10 @@ if (isset($_POST['submit'])) {
$user_actkey = make_rand_str(12);
$user_password = make_rand_str(8);
- $sql = "UPDATE " . BB_USERS . "
+ $sql = "UPDATE bb_users
SET user_newpasswd = '$user_password', user_actkey = '$user_actkey'
WHERE user_id = " . $row['user_id'];
- if (!DB()->sql_query($sql)) {
+ if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not update new password information');
}
diff --git a/library/includes/ucp/topic_watch.php b/library/includes/ucp/topic_watch.php
index 57b589cc0..e1c58768b 100644
--- a/library/includes/ucp/topic_watch.php
+++ b/library/includes/ucp/topic_watch.php
@@ -22,6 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+use \TorrentPier\Di;
/** @var \TorrentPier\Di $di */
$di = \TorrentPier\Di::getInstance();
@@ -41,7 +42,7 @@ $per_page = $di->config->get('topics_per_page');
if (isset($_POST['topic_id_list'])) {
$topic_ids = implode(",", $_POST['topic_id_list']);
$sql = "DELETE FROM " . BB_TOPICS_WATCH . " WHERE topic_id IN(" . $topic_ids . ") AND user_id = $user_id";
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not delete topic watch information #1');
}
}
@@ -52,17 +53,17 @@ $template->assign_vars(array(
));
$sql = "SELECT COUNT(topic_id) as watch_count FROM " . BB_TOPICS_WATCH . " WHERE user_id = $user_id";
-if (!($result = DB()->sql_query($sql))) {
+if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not obtain watch topic information #2');
}
-$row = DB()->sql_fetchrow($result);
+$row = Di::getInstance()->db->sql_fetchrow($result);
$watch_count = ($row['watch_count']) ? $row['watch_count'] : 0;
-DB()->sql_freeresult($result);
+Di::getInstance()->db->sql_freeresult($result);
if ($watch_count > 0) {
$sql = "SELECT w.*, t.*, f.*, u.*, u2.username as last_username, u2.user_id as last_user_id,
u2.user_level as last_user_level, u2.user_rank as last_user_rank
- FROM " . BB_TOPICS_WATCH . " w, " . BB_TOPICS . " t, " . BB_USERS . " u, " . BB_FORUMS . " f, " . BB_POSTS . " p, " . BB_USERS . " u2
+ FROM " . BB_TOPICS_WATCH . " w, bb_topics t, bb_users u, bb_forums f, " . BB_POSTS . " p, bb_users u2
WHERE w.topic_id = t.topic_id
AND t.forum_id = f.forum_id
AND p.post_id = t.topic_last_post_id
@@ -71,10 +72,10 @@ if ($watch_count > 0) {
AND w.user_id = $user_id
GROUP BY t.topic_last_post_time DESC
LIMIT $start, $per_page";
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not obtain watch topic information #3');
}
- $watch = DB()->sql_fetchrowset($result);
+ $watch = Di::getInstance()->db->sql_fetchrowset($result);
if ($watch) {
for ($i = 0; $i < count($watch); $i++) {
@@ -107,7 +108,7 @@ if ($watch_count > 0) {
'PER_PAGE' => $per_page,
));
}
- DB()->sql_freeresult($result);
+ Di::getInstance()->db->sql_freeresult($result);
} else {
meta_refresh('index.php', 3);
bb_die($lang['NO_WATCHED_TOPICS']);
diff --git a/library/includes/ucp/viewprofile.php b/library/includes/ucp/viewprofile.php
index 0471a2dbe..74488a723 100644
--- a/library/includes/ucp/viewprofile.php
+++ b/library/includes/ucp/viewprofile.php
@@ -22,6 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+use \TorrentPier\Di;
if (!defined('BB_ROOT')) {
die(basename(__FILE__));
@@ -145,7 +146,7 @@ if (IS_ADMIN) {
GROUP BY ug.user_id, g.group_single_user, ug.user_pending
ORDER BY NULL
";
- if ($rowset = DB()->fetch_rowset($sql)) {
+ if ($rowset = Di::getInstance()->db->fetch_rowset($sql)) {
$member = $pending = $single = 0;
foreach ($rowset as $row) {
if (!$row['group_single_user'] && !$row['user_pending']) {
diff --git a/library/includes/ucp/viewtorrent.php b/library/includes/ucp/viewtorrent.php
index fd9aaf842..508527daa 100644
--- a/library/includes/ucp/viewtorrent.php
+++ b/library/includes/ucp/viewtorrent.php
@@ -22,6 +22,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+use \TorrentPier\Di;
if (!defined('IN_PROFILE')) {
die(basename(__FILE__));
@@ -37,12 +38,12 @@ $not_auth_forums_sql = ($excluded_forums_csv) ? "
AND f.forum_parent NOT IN($excluded_forums_csv)
" : '';
-$sql = DB()->fetch_rowset("
+$sql = Di::getInstance()->db->fetch_rowset("
SELECT
f.forum_id, f.forum_name, t.topic_title,
tor.tor_type, tor.size,
sn.seeders, sn.leechers, tr.*
- FROM " . BB_FORUMS . " f, " . BB_TOPICS . " t, " . BB_BT_TRACKER . " tr, " . BB_BT_TORRENTS . " tor, " . BB_BT_TRACKER_SNAP . " sn
+ FROM bb_forums f, bb_topics t, bb_bt_tracker tr, bb_bt_torrents tor, bb_bt_tracker_snap sn
WHERE tr.user_id = {$profiledata['user_id']}
AND tr.topic_id = tor.topic_id
AND sn.topic_id = tor.topic_id
diff --git a/memberlist.php b/memberlist.php
index 1d3aa5955..a9bbb5f07 100644
--- a/memberlist.php
+++ b/memberlist.php
@@ -23,6 +23,8 @@
* SOFTWARE.
*/
+use \TorrentPier\Di;
+
define('BB_SCRIPT', 'memberlist');
define('BB_ROOT', './');
require(BB_ROOT . 'common.php');
@@ -138,7 +140,7 @@ if ($by_letter_req) {
$by_letter = 'others';
$letter_sql = "username REGEXP '^[!-@\\[-`].*$'";
} elseif ($letter_req = preg_replace("#[^$letters_range]#ui", '', iconv('windows-1251', 'UTF-8', $by_letter_req[0]))) {
- $by_letter = DB()->escape($letter_req);
+ $by_letter = Di::getInstance()->db->escape($letter_req);
$letter_sql = "LOWER(username) LIKE '$by_letter%'";
}
}
@@ -164,15 +166,15 @@ $template->assign_vars(array(
));
// per-letter selection end
-$sql = "SELECT username, user_id, user_rank, user_opt, user_posts, user_regdate, user_from, user_website, user_email FROM " . BB_USERS . " WHERE user_id NOT IN(" . EXCLUDED_USERS . ")";
+$sql = "SELECT username, user_id, user_rank, user_opt, user_posts, user_regdate, user_from, user_website, user_email FROM bb_users WHERE user_id NOT IN(" . EXCLUDED_USERS . ")";
if ($username) {
$username = preg_replace('/\*/', '%', clean_username($username));
- $letter_sql = "username LIKE '" . DB()->escape($username) . "'";
+ $letter_sql = "username LIKE '" . Di::getInstance()->db->escape($username) . "'";
}
$sql .= ($letter_sql) ? " AND $letter_sql" : '';
$sql .= " ORDER BY $order_by";
-if ($result = DB()->fetch_rowset($sql)) {
+if ($result = Di::getInstance()->db->fetch_rowset($sql)) {
foreach ($result as $i => $row) {
$user_id = $row['user_id'];
$from = $row['user_from'];
@@ -221,14 +223,14 @@ if ($paginationusername) {
if ($mode != 'topten' || $di->config->get('topics_per_page') < 10) {
$sql = "SELECT COUNT(*) AS total FROM " . BB_USERS;
$sql .= ($letter_sql) ? " WHERE $letter_sql" : '';
- if (!$result = DB()->sql_query($sql)) {
+ if (!$result = Di::getInstance()->db->sql_query($sql)) {
bb_die('Error getting total users');
}
- if ($total = DB()->sql_fetchrow($result)) {
+ if ($total = Di::getInstance()->db->sql_fetchrow($result)) {
$total_members = $total['total'];
generate_pagination($paginationurl, $total_members, $di->config->get('topics_per_page'), $start) . ' ';
}
- DB()->sql_freeresult($result);
+ Di::getInstance()->db->sql_freeresult($result);
}
$template->assign_vars(array(
diff --git a/modcp.php b/modcp.php
index b83d2675f..c79efb4f1 100644
--- a/modcp.php
+++ b/modcp.php
@@ -23,6 +23,8 @@
* SOFTWARE.
*/
+use \TorrentPier\Di;
+
define('BB_SCRIPT', 'modcp');
define('BB_ROOT', './');
require(BB_ROOT . 'common.php');
@@ -65,9 +67,9 @@ function validate_topics($forum_id, &$req_topics, &$topic_titles)
$valid_topics = $valid_titles = array();
if ($topic_csv = get_id_csv($req_topics)) {
- $sql = "SELECT topic_id, topic_title FROM " . BB_TOPICS . " WHERE topic_id IN($topic_csv) AND forum_id = $forum_id";
+ $sql = "SELECT topic_id, topic_title FROM bb_topics WHERE topic_id IN($topic_csv) AND forum_id = $forum_id";
- foreach (DB()->fetch_rowset($sql) as $row) {
+ foreach (Di::getInstance()->db->fetch_rowset($sql) as $row) {
$valid_topics[] = $row['topic_id'];
$valid_titles[] = $row['topic_title'];
}
@@ -124,13 +126,13 @@ if ($topic_id) {
SELECT
f.forum_id, f.forum_name, f.forum_topics, f.self_moderated,
t.topic_first_post_id, t.topic_poster
- FROM " . BB_TOPICS . " t, " . BB_FORUMS . " f
+ FROM bb_topics t, bb_forums f
WHERE t.topic_id = $topic_id
AND f.forum_id = t.forum_id
LIMIT 1
";
- if (!$topic_row = DB()->fetch_row($sql)) {
+ if (!$topic_row = Di::getInstance()->db->fetch_row($sql)) {
bb_die('Topic post not exist');
}
@@ -138,9 +140,9 @@ if ($topic_id) {
$forum_name = $topic_row['forum_name'];
$forum_topics = (!$topic_row['forum_topics']) ? 1 : $topic_row['forum_topics'];
} elseif ($forum_id) {
- $sql = "SELECT forum_name, forum_topics FROM " . BB_FORUMS . " WHERE forum_id = $forum_id LIMIT 1";
+ $sql = "SELECT forum_name, forum_topics FROM bb_forums WHERE forum_id = $forum_id LIMIT 1";
- if (!$topic_row = DB()->fetch_row($sql)) {
+ if (!$topic_row = Di::getInstance()->db->fetch_row($sql)) {
bb_die('Forum not exist');
}
@@ -325,7 +327,7 @@ switch ($mode) {
$sql = "
SELECT topic_id, topic_title
- FROM " . BB_TOPICS . "
+ FROM bb_topics
WHERE topic_id IN($topic_csv)
AND forum_id = $forum_id
AND topic_status != " . TOPIC_MOVED . "
@@ -334,7 +336,7 @@ switch ($mode) {
$topic_csv = array();
- foreach (DB()->fetch_rowset($sql) as $row) {
+ foreach (Di::getInstance()->db->fetch_rowset($sql) as $row) {
$topic_csv[] = $row['topic_id'];
$log_topics[$row['topic_id']] = $row['topic_title'];
}
@@ -343,8 +345,8 @@ switch ($mode) {
bb_die($lang['NONE_SELECTED']);
}
- DB()->query("
- UPDATE " . BB_TOPICS . " SET
+ Di::getInstance()->db->query("
+ UPDATE bb_topics SET
topic_status = $new_topic_status
WHERE topic_id IN($topic_csv)
");
@@ -371,8 +373,8 @@ switch ($mode) {
$set_download = ($mode == 'set_download');
$new_dl_type = ($set_download) ? 1 : 0;
- DB()->query("
- UPDATE " . BB_TOPICS . " SET
+ Di::getInstance()->db->query("
+ UPDATE bb_topics SET
tracker_status = $new_dl_type
WHERE topic_id IN($topic_csv)
AND forum_id = $forum_id
@@ -413,10 +415,10 @@ switch ($mode) {
AND topic_id = $topic_id
AND forum_id = $forum_id";
- if (!$result = DB()->sql_query($sql)) {
+ if (!$result = Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not get post id information');
}
- if ($rowset = DB()->sql_fetchrowset($result)) {
+ if ($rowset = Di::getInstance()->db->sql_fetchrowset($result)) {
foreach ($rowset as $rid => $row) {
$post_id_sql[] = $row['post_id'];
}
@@ -432,11 +434,11 @@ switch ($mode) {
FROM " . BB_POSTS . "
WHERE post_id IN ($post_id_sql)
ORDER BY post_time ASC";
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not get post information');
}
- if ($row = DB()->sql_fetchrow($result)) {
+ if ($row = Di::getInstance()->db->sql_fetchrow($result)) {
$first_poster = $row['poster_id'];
$topic_id = $row['topic_id'];
$post_time = $row['post_time'];
@@ -446,7 +448,7 @@ switch ($mode) {
do {
$user_id_sql .= (($user_id_sql != '') ? ', ' : '') . intval($row['poster_id']);
$post_id_sql .= (($post_id_sql != '') ? ', ' : '') . intval($row['post_id']);
- } while ($row = DB()->sql_fetchrow($result));
+ } while ($row = Di::getInstance()->db->sql_fetchrow($result));
$post_subject = clean_title($_POST['subject']);
if (empty($post_subject)) {
@@ -457,25 +459,25 @@ switch ($mode) {
$topic_time = TIMENOW;
$sql = 'SELECT forum_id FROM ' . BB_FORUMS . ' WHERE forum_id = ' . $new_forum_id;
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not select from forums table');
}
- if (!DB()->sql_fetchrow($result)) {
+ if (!Di::getInstance()->db->sql_fetchrow($result)) {
bb_die('New forum does not exist');
}
- DB()->sql_freeresult($result);
+ Di::getInstance()->db->sql_freeresult($result);
$first_post_id = min(explode(',', $post_id_sql));
- $sql = "INSERT INTO " . BB_TOPICS . " (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_first_post_id)
- VALUES ('" . DB()->escape($post_subject) . "', $first_poster, " . $topic_time . ", $new_forum_id, " . TOPIC_UNLOCKED . ", " . POST_NORMAL . ", $first_post_id)";
- if (!(DB()->sql_query($sql))) {
+ $sql = "INSERT INTO bb_topics (topic_title, topic_poster, topic_time, forum_id, topic_status, topic_type, topic_first_post_id)
+ VALUES ('" . Di::getInstance()->db->escape($post_subject) . "', $first_poster, " . $topic_time . ", $new_forum_id, " . TOPIC_UNLOCKED . ", " . POST_NORMAL . ", $first_post_id)";
+ if (!(Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not insert new topic');
}
- $new_topic_id = DB()->sql_nextid();
+ $new_topic_id = Di::getInstance()->db->sql_nextid();
// Update topic watch table, switch users whose posts
// have moved, over to watching the new topic
@@ -483,14 +485,14 @@ switch ($mode) {
SET topic_id = $new_topic_id
WHERE topic_id = $topic_id
AND user_id IN ($user_id_sql)";
- if (!DB()->sql_query($sql)) {
+ if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not update topics watch table');
}
$sql_where = (!empty($_POST['split_type_beyond'])) ? " post_time >= $post_time AND topic_id = $topic_id" : "post_id IN ($post_id_sql)";
$sql = "UPDATE " . BB_POSTS . " SET topic_id = $new_topic_id, forum_id = $new_forum_id WHERE $sql_where";
- if (!DB()->sql_query($sql)) {
+ if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not update posts table');
}
@@ -533,19 +535,19 @@ switch ($mode) {
bb_die(return_msg_mcp($msg));
} else {
$sql = "SELECT u.username, p.*, pt.post_text, p.post_username
- FROM " . BB_POSTS . " p, " . BB_USERS . " u, " . BB_POSTS_TEXT . " pt
+ FROM " . BB_POSTS . " p, bb_users u, " . BB_POSTS_TEXT . " pt
WHERE p.topic_id = $topic_id
AND p.poster_id = u.user_id
AND p.post_id = pt.post_id
ORDER BY p.post_time ASC";
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not get topic / post information');
}
$s_hidden_fields = '';
- if (($total_posts = DB()->num_rows($result)) > 0) {
- $postrow = DB()->sql_fetchrowset($result);
+ if (($total_posts = Di::getInstance()->db->num_rows($result)) > 0) {
+ $postrow = Di::getInstance()->db->sql_fetchrowset($result);
$template->assign_vars(array(
'FORUM_NAME' => htmlCHR($forum_name),
@@ -603,11 +605,11 @@ switch ($mode) {
// Look up relevant data for this post
$sql = "SELECT * FROM " . BB_POSTS . " WHERE post_id = $post_id AND forum_id = $forum_id";
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not get poster IP information');
}
- if (!($post_row = DB()->sql_fetchrow($result))) {
+ if (!($post_row = Di::getInstance()->db->sql_fetchrow($result))) {
bb_die($lang['NO_SUCH_POST']);
}
@@ -628,11 +630,11 @@ switch ($mode) {
$where_sql = ($poster_id == $anon) ? "post_username = '{$post_row['post_username']}'" : "poster_id = $poster_id";
$sql = "SELECT poster_ip, COUNT(*) AS postings FROM " . BB_POSTS . " WHERE $where_sql GROUP BY poster_ip ORDER BY postings DESC LIMIT 100";
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not get IP information for this user');
}
- if ($row = DB()->sql_fetchrow($result)) {
+ if ($row = Di::getInstance()->db->sql_fetchrow($result)) {
$i = 0;
do {
if ($row['poster_ip'] == $post_row['poster_ip']) {
@@ -653,7 +655,7 @@ switch ($mode) {
));
$i++;
- } while ($row = DB()->sql_fetchrow($result));
+ } while ($row = Di::getInstance()->db->sql_fetchrow($result));
}
//
@@ -663,17 +665,17 @@ switch ($mode) {
u.user_id,
IF(u.user_id = $anon, p.post_username, u.username) AS username,
COUNT(*) as postings
- FROM " . BB_USERS . " u, " . BB_POSTS . " p
+ FROM bb_users u, " . BB_POSTS . " p
WHERE p.poster_id = u.user_id
AND p.poster_ip = '" . $post_row['poster_ip'] . "'
GROUP BY u.user_id, p.post_username
ORDER BY postings DESC
LIMIT 100";
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not get posters information based on IP');
}
- if ($row = DB()->sql_fetchrow($result)) {
+ if ($row = Di::getInstance()->db->sql_fetchrow($result)) {
$i = 0;
do {
$id = $row['user_id'];
@@ -688,7 +690,7 @@ switch ($mode) {
));
$i++;
- } while ($row = DB()->sql_fetchrow($result));
+ } while ($row = Di::getInstance()->db->sql_fetchrow($result));
}
$template->set_filenames(array('body' => 'modcp.tpl'));
@@ -702,7 +704,7 @@ switch ($mode) {
if (count($topic_csv)) {
$sql = "
SELECT topic_id, topic_title
- FROM " . BB_TOPICS . "
+ FROM bb_topics
WHERE topic_id IN($topic_csv)
AND forum_id = $forum_id
AND topic_show_first_post != " . TOPIC_MOVED . "
@@ -711,7 +713,7 @@ switch ($mode) {
$topic_csv = array();
- foreach (DB()->fetch_rowset($sql) as $row) {
+ foreach (Di::getInstance()->db->fetch_rowset($sql) as $row) {
$topic_csv[] = $row['topic_id'];
$log_topics[$row['topic_id']] = $row['topic_title'];
}
@@ -720,8 +722,8 @@ switch ($mode) {
bb_die($lang['NONE_SELECTED']);
}
- DB()->query("
- UPDATE " . BB_TOPICS . " SET
+ Di::getInstance()->db->query("
+ UPDATE bb_topics SET
topic_show_first_post = $new_topic_status
WHERE topic_id IN($topic_csv)
");
@@ -731,7 +733,7 @@ switch ($mode) {
} elseif ($topic_id) {
$sql = "
SELECT topic_id, topic_title
- FROM " . BB_TOPICS . "
+ FROM bb_topics
WHERE topic_id = $topic_id
AND forum_id = $forum_id
AND topic_show_first_post != " . TOPIC_MOVED . "
@@ -741,7 +743,7 @@ switch ($mode) {
$topic_csv = array();
- foreach (DB()->fetch_rowset($sql) as $row) {
+ foreach (Di::getInstance()->db->fetch_rowset($sql) as $row) {
$topic_csv[] = $row['topic_id'];
$log_topics[$row['topic_id']] = $row['topic_title'];
}
@@ -750,8 +752,8 @@ switch ($mode) {
bb_die($lang['NONE_SELECTED']);
}
- DB()->query("
- UPDATE " . BB_TOPICS . " SET
+ Di::getInstance()->db->query("
+ UPDATE bb_topics SET
topic_show_first_post = $new_topic_status
WHERE topic_id IN($topic_csv)
");
diff --git a/poll.php b/poll.php
index 9f26fbd17..11854b95c 100644
--- a/poll.php
+++ b/poll.php
@@ -23,6 +23,8 @@
* SOFTWARE.
*/
+use \TorrentPier\Di;
+
define('BB_SCRIPT', 'vote');
define('BB_ROOT', './');
require_once __DIR__ . '/common.php';
@@ -51,7 +53,7 @@ $poll = new bb_poll();
if (!$topic_id) {
bb_die('Invalid topic_id');
}
-if (!$t_data = DB()->fetch_row("SELECT * FROM " . BB_TOPICS . " WHERE topic_id = $topic_id LIMIT 1")) {
+if (!$t_data = Di::getInstance()->db->fetch_row("SELECT * FROM bb_topics WHERE topic_id = $topic_id LIMIT 1")) {
bb_die('Topic not found');
}
@@ -89,22 +91,22 @@ switch ($mode) {
if (!$vote_id) {
bb_die($lang['NO_VOTE_OPTION']);
}
- if (DB()->fetch_row("SELECT 1 FROM " . BB_POLL_USERS . " WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']} LIMIT 1")) {
+ if (Di::getInstance()->db->fetch_row("SELECT 1 FROM " . BB_POLL_USERS . " WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']} LIMIT 1")) {
bb_die($lang['ALREADY_VOTED']);
}
- DB()->query("
+ Di::getInstance()->db->query("
UPDATE " . BB_POLL_VOTES . " SET
vote_result = vote_result + 1
WHERE topic_id = $topic_id
AND vote_id = $vote_id
LIMIT 1
");
- if (DB()->affected_rows() != 1) {
+ if (Di::getInstance()->db->affected_rows() != 1) {
bb_die($lang['NO_VOTE_OPTION']);
}
- DB()->query("INSERT IGNORE INTO " . BB_POLL_USERS . " (topic_id, user_id, vote_ip, vote_dt) VALUES ($topic_id, {$userdata['user_id']}, '" . USER_IP . "', " . TIMENOW . ")");
+ Di::getInstance()->db->query("INSERT IGNORE INTO " . BB_POLL_USERS . " (topic_id, user_id, vote_ip, vote_dt) VALUES ($topic_id, {$userdata['user_id']}, '" . USER_IP . "', " . TIMENOW . ")");
$cache->delete('poll_' . $topic_id);
@@ -116,7 +118,7 @@ switch ($mode) {
if (!$t_data['topic_vote']) {
bb_die($lang['POST_HAS_NO_POLL']);
}
- DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = 1 WHERE topic_id = $topic_id LIMIT 1");
+ Di::getInstance()->db->query("UPDATE bb_topics SET topic_vote = 1 WHERE topic_id = $topic_id LIMIT 1");
bb_die($lang['NEW_POLL_START']);
break;
@@ -125,7 +127,7 @@ switch ($mode) {
if (!$t_data['topic_vote']) {
bb_die($lang['POST_HAS_NO_POLL']);
}
- DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = " . POLL_FINISHED . " WHERE topic_id = $topic_id LIMIT 1");
+ Di::getInstance()->db->query("UPDATE bb_topics SET topic_vote = " . POLL_FINISHED . " WHERE topic_id = $topic_id LIMIT 1");
bb_die($lang['NEW_POLL_END']);
break;
@@ -225,16 +227,16 @@ class bb_poll
'vote_result' => (int)0,
);
}
- $sql_args = DB()->build_array('MULTI_INSERT', $sql_ary);
+ $sql_args = Di::getInstance()->db->build_array('MULTI_INSERT', $sql_ary);
- DB()->query("REPLACE INTO " . BB_POLL_VOTES . $sql_args);
+ Di::getInstance()->db->query("REPLACE INTO " . BB_POLL_VOTES . $sql_args);
- DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = 1 WHERE topic_id = $topic_id LIMIT 1");
+ Di::getInstance()->db->query("UPDATE bb_topics SET topic_vote = 1 WHERE topic_id = $topic_id LIMIT 1");
}
public function delete_poll($topic_id)
{
- DB()->query("UPDATE " . BB_TOPICS . " SET topic_vote = 0 WHERE topic_id = $topic_id LIMIT 1");
+ Di::getInstance()->db->query("UPDATE bb_topics SET topic_vote = 0 WHERE topic_id = $topic_id LIMIT 1");
$this->delete_votes_data($topic_id);
}
@@ -246,8 +248,8 @@ class bb_poll
/** @var \TorrentPier\Cache\Adapter $cache */
$cache = $di->cache;
- DB()->query("DELETE FROM " . BB_POLL_VOTES . " WHERE topic_id = $topic_id");
- DB()->query("DELETE FROM " . BB_POLL_USERS . " WHERE topic_id = $topic_id");
+ Di::getInstance()->db->query("DELETE FROM " . BB_POLL_VOTES . " WHERE topic_id = $topic_id");
+ Di::getInstance()->db->query("DELETE FROM " . BB_POLL_USERS . " WHERE topic_id = $topic_id");
$cache->delete('poll_' . $topic_id);
}
diff --git a/posting.php b/posting.php
index fbddbd8cf..f6a412f26 100644
--- a/posting.php
+++ b/posting.php
@@ -23,6 +23,8 @@
* SOFTWARE.
*/
+use \TorrentPier\Di;
+
define('BB_SCRIPT', 'posting');
define('BB_ROOT', './');
require(BB_ROOT . "common.php");
@@ -118,7 +120,7 @@ switch ($mode) {
if (!$forum_id) {
bb_simple_die($lang['FORUM_NOT_EXIST']);
}
- $sql = "SELECT * FROM " . BB_FORUMS . " WHERE forum_id = $forum_id LIMIT 1";
+ $sql = "SELECT * FROM bb_forums WHERE forum_id = $forum_id LIMIT 1";
break;
case 'reply':
@@ -126,7 +128,7 @@ switch ($mode) {
bb_simple_die($lang['NO_TOPIC_ID']);
}
$sql = "SELECT f.*, t.*
- FROM " . BB_FORUMS . " f, " . BB_TOPICS . " t
+ FROM bb_forums f, bb_topics t
WHERE t.topic_id = $topic_id
AND f.forum_id = t.forum_id
LIMIT 1";
@@ -142,8 +144,8 @@ switch ($mode) {
$select_sql = 'SELECT f.*, t.*, p.*';
$select_sql .= (!$submit) ? ', pt.*, u.username, u.user_id' : '';
- $from_sql = "FROM " . BB_POSTS . " p, " . BB_TOPICS . " t, " . BB_FORUMS . " f";
- $from_sql .= (!$submit) ? ", " . BB_POSTS_TEXT . " pt, " . BB_USERS . " u" : '';
+ $from_sql = "FROM " . BB_POSTS . " p, bb_topics t, bb_forums f";
+ $from_sql .= (!$submit) ? ", " . BB_POSTS_TEXT . " pt, bb_users u" : '';
$where_sql = "
WHERE p.post_id = $post_id
@@ -162,7 +164,7 @@ switch ($mode) {
bb_simple_die($lang['NO_VALID_MODE']);
}
-if ($post_info = DB()->fetch_row($sql)) {
+if ($post_info = Di::getInstance()->db->fetch_row($sql)) {
$forum_id = $post_info['forum_id'];
$forum_name = $post_info['forum_name'];
@@ -242,8 +244,8 @@ if (!$is_auth[$is_auth_type]) {
if ($mode == 'new_rel') {
if ($tor_status = join(',', $di->config->get('tor_cannot_new'))) {
- $sql = DB()->fetch_rowset("SELECT t.topic_title, t.topic_id, tor.tor_status
- FROM " . BB_BT_TORRENTS . " tor, " . BB_TOPICS . " t
+ $sql = Di::getInstance()->db->fetch_rowset("SELECT t.topic_title, t.topic_id, tor.tor_status
+ FROM bb_bt_torrents tor, bb_topics t
WHERE poster_id = {$userdata['user_id']}
AND tor.topic_id = t.topic_id
AND tor.tor_status IN ($tor_status)
@@ -269,7 +271,7 @@ if ($submit || $preview) {
$notify_user = bf($userdata['user_opt'], 'user_opt', 'user_notify');
if (!IS_GUEST && $mode != 'newtopic' && !$notify_user) {
- $notify_user = (int)DB()->fetch_row("SELECT topic_id FROM " . BB_TOPICS_WATCH . " WHERE topic_id = $topic_id AND user_id = " . $userdata['user_id']);
+ $notify_user = (int)Di::getInstance()->db->fetch_row("SELECT topic_id FROM " . BB_TOPICS_WATCH . " WHERE topic_id = $topic_id AND user_id = " . $userdata['user_id']);
}
}
@@ -281,7 +283,7 @@ $topic_has_new_posts = false;
if (!IS_GUEST && $mode != 'newtopic' && ($submit || $preview || $mode == 'quote' || $mode == 'reply') && isset($_COOKIE[COOKIE_TOPIC])) {
if ($topic_last_read = max(intval($tracking_topics[$topic_id]), intval($tracking_forums[$forum_id]))) {
$sql = "SELECT p.*, pt.post_text, u.username, u.user_rank
- FROM " . BB_POSTS . " p, " . BB_POSTS_TEXT . " pt, " . BB_USERS . " u
+ FROM " . BB_POSTS . " p, " . BB_POSTS_TEXT . " pt, bb_users u
WHERE p.topic_id = " . (int)$topic_id . "
AND u.user_id = p.poster_id
AND pt.post_id = p.post_id
@@ -289,7 +291,7 @@ if (!IS_GUEST && $mode != 'newtopic' && ($submit || $preview || $mode == 'quote'
ORDER BY p.post_time
LIMIT " . $di->config->get('posts_per_page');
- if ($rowset = DB()->fetch_rowset($sql)) {
+ if ($rowset = Di::getInstance()->db->fetch_rowset($sql)) {
$topic_has_new_posts = true;
foreach ($rowset as $i => $row) {
@@ -347,7 +349,7 @@ if ($mode == 'delete' && !$confirm) {
if (!$error_msg) {
$topic_type = (isset($post_data['topic_type']) && $topic_type != $post_data['topic_type'] && !$is_auth['auth_sticky'] && !$is_auth['auth_announce']) ? $post_data['topic_type'] : $topic_type;
- submit_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $topic_type, DB()->escape($username), DB()->escape($subject), DB()->escape($message), $update_post_time, $poster_rg_id, $attach_rg_sig);
+ submit_post($mode, $post_data, $return_message, $return_meta, $forum_id, $topic_id, $post_id, $topic_type, Di::getInstance()->db->escape($username), Di::getInstance()->db->escape($subject), Di::getInstance()->db->escape($message), $update_post_time, $poster_rg_id, $attach_rg_sig);
$post_url = POST_URL . "$post_id#$post_id";
$post_msg = ($mode == 'editpost') ? $lang['EDITED'] : $lang['STORED'];
@@ -386,8 +388,8 @@ if ($mode == 'delete' && !$confirm) {
$upload = new upload_common();
if ($upload->init($di->config->get('attach'), $_FILES['attach']) && $upload->store('attach', array('topic_id' => $topic_id))) {
- DB()->query("
- UPDATE " . BB_TOPICS . " SET
+ Di::getInstance()->db->query("
+ UPDATE bb_topics SET
attach_ext_id = " . (int)$upload->file_ext_id . ",
filesize = " . (int)$upload->file_size . "
WHERE topic_id = $topic_id
@@ -401,7 +403,7 @@ if ($mode == 'delete' && !$confirm) {
if ($post_info['forum_parent']) {
$forum_parent = $post_info['forum_parent'];
}
- $count_rowset = DB()->fetch_rowset("SELECT forum_id FROM " . BB_FORUMS . " WHERE forum_parent = $forum_parent");
+ $count_rowset = Di::getInstance()->db->fetch_rowset("SELECT forum_id FROM bb_forums WHERE forum_parent = $forum_parent");
$sub_forums = array();
foreach ($count_rowset as $count_row) {
if ($count_row['forum_id'] != $forum_id) {
@@ -411,7 +413,7 @@ if ($mode == 'delete' && !$confirm) {
$sub_forums[] = $forum_id;
$sub_forums = join(',', $sub_forums);
// Подсчет проверенных релизов в форумах раздела
- $count_checked_releases = DB()->fetch_row("SELECT COUNT(*) AS checked_releases FROM " . BB_BT_TORRENTS . " WHERE poster_id = " . $userdata['user_id'] . " AND forum_id IN($sub_forums) AND tor_status IN(" . TOR_APPROVED . "," . TOR_DOUBTFUL . "," . TOR_TMP . ") LIMIT 1", 'checked_releases');
+ $count_checked_releases = Di::getInstance()->db->fetch_row("SELECT COUNT(*) AS checked_releases FROM bb_bt_torrents WHERE poster_id = " . $userdata['user_id'] . " AND forum_id IN($sub_forums) AND tor_status IN(" . TOR_APPROVED . "," . TOR_DOUBTFUL . "," . TOR_TMP . ") LIMIT 1", 'checked_releases');
if ($count_checked_releases || IS_AM) {
tracker_register($topic_id, 'newtopic', TOR_NOT_APPROVED);
} else {
@@ -571,7 +573,7 @@ if ($userdata['user_level'] == GROUP_MEMBER || IS_AM) {
AND g.release_group = 1
ORDER BY g.group_name";
- foreach (DB()->fetch_rowset($sql) as $row) {
+ foreach (Di::getInstance()->db->fetch_rowset($sql) as $row) {
$selected_opt = ($row['group_id'] == $selected_rg) ? 'selected' : '';
$poster_rgroups .= '';
}
diff --git a/privmsg.php b/privmsg.php
index 9316b1654..7602324d0 100644
--- a/privmsg.php
+++ b/privmsg.php
@@ -23,6 +23,8 @@
* SOFTWARE.
*/
+use \TorrentPier\Di;
+
define('BB_SCRIPT', 'pm');
define('IN_PM', true);
define('BB_ROOT', './');
@@ -160,20 +162,20 @@ if ($mode == 'read') {
$sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_email, u.user_regdate, u.user_rank,
u2.username AS to_username, u2.user_id AS to_user_id, u2.user_rank as to_user_rank,
pm.*, pmt.privmsgs_text
- FROM " . BB_PRIVMSGS . " pm, " . BB_PRIVMSGS_TEXT . " pmt, " . BB_USERS . " u, " . BB_USERS . " u2
+ FROM " . BB_PRIVMSGS . " pm, " . BB_PRIVMSGS_TEXT . " pmt, bb_users u, bb_users u2
WHERE pm.privmsgs_id = $privmsgs_id
AND pmt.privmsgs_text_id = pm.privmsgs_id
$pm_sql_user
AND u.user_id = pm.privmsgs_from_userid
AND u2.user_id = pm.privmsgs_to_userid";
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not query private message post information');
}
//
// Did the query return any data?
//
- if (!($privmsg = DB()->sql_fetchrow($result))) {
+ if (!($privmsg = Di::getInstance()->db->sql_fetchrow($result))) {
redirect(PM_URL . "?folder=$folder");
}
@@ -194,18 +196,18 @@ if ($mode == 'read') {
break;
}
- $sql = "UPDATE " . BB_USERS . " SET $sql WHERE user_id = " . $userdata['user_id'];
- if (!DB()->sql_query($sql)) {
+ $sql = "UPDATE bb_users SET $sql WHERE user_id = " . $userdata['user_id'];
+ if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not update private message read status for user');
}
- if (DB()->affected_rows()) {
+ if (Di::getInstance()->db->affected_rows()) {
cache_rm_userdata($userdata);
}
$sql = "UPDATE " . BB_PRIVMSGS . "
SET privmsgs_type = " . PRIVMSGS_READ_MAIL . "
WHERE privmsgs_id = " . $privmsg['privmsgs_id'];
- if (!DB()->sql_query($sql)) {
+ if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not update private message read status');
}
@@ -214,29 +216,29 @@ if ($mode == 'read') {
FROM " . BB_PRIVMSGS . "
WHERE privmsgs_type = " . PRIVMSGS_SENT_MAIL . "
AND privmsgs_from_userid = " . $privmsg['privmsgs_from_userid'];
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not obtain sent message info for sender');
}
- if ($sent_info = DB()->sql_fetchrow($result)) {
+ if ($sent_info = Di::getInstance()->db->sql_fetchrow($result)) {
if ($di->config->get('max_sentbox_privmsgs') && $sent_info['sent_items'] >= $di->config->get('max_sentbox_privmsgs')) {
$sql = "SELECT privmsgs_id FROM " . BB_PRIVMSGS . "
WHERE privmsgs_type = " . PRIVMSGS_SENT_MAIL . "
AND privmsgs_date = " . $sent_info['oldest_post_time'] . "
AND privmsgs_from_userid = " . $privmsg['privmsgs_from_userid'];
- if (!$result = DB()->sql_query($sql)) {
+ if (!$result = Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not find oldest privmsgs');
}
- $old_privmsgs_id = DB()->sql_fetchrow($result);
+ $old_privmsgs_id = Di::getInstance()->db->sql_fetchrow($result);
$old_privmsgs_id = (int)$old_privmsgs_id['privmsgs_id'];
$sql = "DELETE FROM " . BB_PRIVMSGS . " WHERE privmsgs_id = $old_privmsgs_id";
- if (!DB()->sql_query($sql)) {
+ if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not delete oldest privmsgs (sent)');
}
$sql = "DELETE FROM " . BB_PRIVMSGS_TEXT . " WHERE privmsgs_text_id = $old_privmsgs_id";
- if (!DB()->sql_query($sql)) {
+ if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not delete oldest privmsgs text (sent)');
}
}
@@ -248,16 +250,16 @@ if ($mode == 'read') {
// set limits on numbers of storable posts for users ... hopefully!
//
$sql = "INSERT INTO " . BB_PRIVMSGS . " (privmsgs_type, privmsgs_subject, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date, privmsgs_ip)
- VALUES (" . PRIVMSGS_SENT_MAIL . ", '" . DB()->escape($privmsg['privmsgs_subject']) . "', " . $privmsg['privmsgs_from_userid'] . ", " . $privmsg['privmsgs_to_userid'] . ", " . $privmsg['privmsgs_date'] . ", '" . $privmsg['privmsgs_ip'] . "')";
- if (!DB()->sql_query($sql)) {
+ VALUES (" . PRIVMSGS_SENT_MAIL . ", '" . Di::getInstance()->db->escape($privmsg['privmsgs_subject']) . "', " . $privmsg['privmsgs_from_userid'] . ", " . $privmsg['privmsgs_to_userid'] . ", " . $privmsg['privmsgs_date'] . ", '" . $privmsg['privmsgs_ip'] . "')";
+ if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not insert private message sent info');
}
- $privmsg_sent_id = DB()->sql_nextid();
+ $privmsg_sent_id = Di::getInstance()->db->sql_nextid();
$sql = "INSERT INTO " . BB_PRIVMSGS_TEXT . " (privmsgs_text_id, privmsgs_text)
- VALUES ($privmsg_sent_id, '" . DB()->escape($privmsg['privmsgs_text']) . "')";
- if (!DB()->sql_query($sql)) {
+ VALUES ($privmsg_sent_id, '" . Di::getInstance()->db->escape($privmsg['privmsgs_text']) . "')";
+ if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not insert private message sent text');
}
}
@@ -482,12 +484,12 @@ if ($mode == 'read') {
}
$sql = "SELECT privmsgs_id FROM " . BB_PRIVMSGS . " WHERE $delete_type $delete_sql_id";
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not obtain id list to delete messages');
}
$mark_list = array();
- while ($row = DB()->sql_fetchrow($result)) {
+ while ($row = Di::getInstance()->db->sql_fetchrow($result)) {
$mark_list[] = $row['privmsgs_id'];
}
@@ -516,11 +518,11 @@ if ($mode == 'read') {
WHERE privmsgs_id IN ($delete_sql_id)
AND $sql
AND privmsgs_type IN (" . PRIVMSGS_NEW_MAIL . ", " . PRIVMSGS_UNREAD_MAIL . ")";
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not obtain user id list for outbox messages');
}
- if ($row = DB()->sql_fetchrow($result)) {
+ if ($row = Di::getInstance()->db->sql_fetchrow($result)) {
$update_users = $update_list = array();
do {
@@ -533,7 +535,7 @@ if ($mode == 'read') {
$update_users['unread'][$row['privmsgs_to_userid']]++;
break;
}
- } while ($row = DB()->sql_fetchrow($result));
+ } while ($row = Di::getInstance()->db->sql_fetchrow($result));
if (sizeof($update_users)) {
while (list($type, $users) = each($update_users)) {
@@ -557,10 +559,10 @@ if ($mode == 'read') {
while (list($dec, $user_ary) = each($dec_ary)) {
$user_ids = join(', ', $user_ary);
- $sql = "UPDATE " . BB_USERS . "
+ $sql = "UPDATE bb_users
SET $type = $type - $dec
WHERE user_id IN ($user_ids)";
- if (!DB()->sql_query($sql)) {
+ if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not update user pm counters');
}
}
@@ -568,7 +570,7 @@ if ($mode == 'read') {
unset($update_list);
}
}
- DB()->sql_freeresult($result);
+ Di::getInstance()->db->sql_freeresult($result);
}
// Delete the messages
@@ -601,11 +603,11 @@ if ($mode == 'read') {
break;
}
- if (!DB()->sql_query($delete_sql)) {
+ if (!Di::getInstance()->db->sql_query($delete_sql)) {
bb_die('Could not delete private message info');
}
- if (!DB()->sql_query($delete_text_sql)) {
+ if (!Di::getInstance()->db->sql_query($delete_text_sql)) {
bb_die('Could not delete private message text');
}
@@ -623,11 +625,11 @@ if ($mode == 'read') {
AND privmsgs_type = " . PRIVMSGS_SAVED_IN_MAIL . " )
OR ( privmsgs_from_userid = " . $userdata['user_id'] . "
AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ") )";
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not obtain sent message info for sender');
}
- if ($saved_info = DB()->sql_fetchrow($result)) {
+ if ($saved_info = Di::getInstance()->db->sql_fetchrow($result)) {
if ($di->config->get('max_savebox_privmsgs') && $saved_info['savebox_items'] >= $di->config->get('max_savebox_privmsgs')) {
$sql = "SELECT privmsgs_id FROM " . BB_PRIVMSGS . "
WHERE ( ( privmsgs_to_userid = " . $userdata['user_id'] . "
@@ -635,19 +637,19 @@ if ($mode == 'read') {
OR ( privmsgs_from_userid = " . $userdata['user_id'] . "
AND privmsgs_type = " . PRIVMSGS_SAVED_OUT_MAIL . ") )
AND privmsgs_date = " . $saved_info['oldest_post_time'];
- if (!$result = DB()->sql_query($sql)) {
+ if (!$result = Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not find oldest privmsgs (save)');
}
- $old_privmsgs_id = DB()->sql_fetchrow($result);
+ $old_privmsgs_id = Di::getInstance()->db->sql_fetchrow($result);
$old_privmsgs_id = (int)$old_privmsgs_id['privmsgs_id'];
$sql = "DELETE FROM " . BB_PRIVMSGS . " WHERE privmsgs_id = $old_privmsgs_id";
- if (!DB()->sql_query($sql)) {
+ if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not delete oldest privmsgs (save)');
}
$sql = "DELETE FROM " . BB_PRIVMSGS_TEXT . " WHERE privmsgs_text_id = $old_privmsgs_id";
- if (!DB()->sql_query($sql)) {
+ if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not delete oldest privmsgs text (save)');
}
}
@@ -679,11 +681,11 @@ if ($mode == 'read') {
WHERE privmsgs_id IN ($saved_sql_id)
AND $sql
AND privmsgs_type IN (" . PRIVMSGS_NEW_MAIL . ", " . PRIVMSGS_UNREAD_MAIL . ")";
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not obtain user id list for outbox messages');
}
- if ($row = DB()->sql_fetchrow($result)) {
+ if ($row = Di::getInstance()->db->sql_fetchrow($result)) {
$update_users = $update_list = array();
do {
@@ -696,7 +698,7 @@ if ($mode == 'read') {
$update_users['unread'][$row['privmsgs_to_userid']]++;
break;
}
- } while ($row = DB()->sql_fetchrow($result));
+ } while ($row = Di::getInstance()->db->sql_fetchrow($result));
if (sizeof($update_users)) {
while (list($type, $users) = each($update_users)) {
@@ -720,8 +722,8 @@ if ($mode == 'read') {
while (list($dec, $user_ary) = each($dec_ary)) {
$user_ids = join(', ', $user_ary);
- $sql = "UPDATE " . BB_USERS . " SET $type = $type - $dec WHERE user_id IN ($user_ids)";
- if (!DB()->sql_query($sql)) {
+ $sql = "UPDATE bb_users SET $type = $type - $dec WHERE user_id IN ($user_ids)";
+ if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not update user pm counters');
}
}
@@ -729,7 +731,7 @@ if ($mode == 'read') {
unset($update_list);
}
}
- DB()->sql_freeresult($result);
+ Di::getInstance()->db->sql_freeresult($result);
}
switch ($folder) {
@@ -757,7 +759,7 @@ if ($mode == 'read') {
$saved_sql .= " AND privmsgs_id IN ($saved_sql_id)";
- if (!DB()->sql_query($saved_sql)) {
+ if (!Di::getInstance()->db->sql_query($saved_sql)) {
bb_die('Could not save private messages');
}
@@ -767,8 +769,8 @@ if ($mode == 'read') {
if (IS_USER && $submit && $mode != 'edit') {
// Flood control
$sql = "SELECT MAX(privmsgs_date) AS last_post_time FROM " . BB_PRIVMSGS . " WHERE privmsgs_from_userid = " . $userdata['user_id'];
- if ($result = DB()->sql_query($sql)) {
- $db_row = DB()->sql_fetchrow($result);
+ if ($result = Di::getInstance()->db->sql_query($sql)) {
+ $db_row = Di::getInstance()->db->sql_fetchrow($result);
$last_post_time = $db_row['last_post_time'];
$current_time = TIMENOW;
@@ -785,14 +787,14 @@ if ($mode == 'read') {
WHERE privmsgs_id = ' . (int)$privmsg_id . '
AND privmsgs_from_userid = ' . $userdata['user_id'];
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not obtain message details');
}
- if (!($row = DB()->sql_fetchrow($result))) {
+ if (!($row = Di::getInstance()->db->sql_fetchrow($result))) {
bb_die($lang['NO_SUCH_POST']);
}
- DB()->sql_freeresult($result);
+ Di::getInstance()->db->sql_freeresult($result);
unset($row);
}
@@ -800,7 +802,7 @@ if ($mode == 'read') {
if ($submit) {
if (!empty($_POST['username'])) {
$to_username = clean_username($_POST['username']);
- $to_username_sql = DB()->escape($to_username);
+ $to_username_sql = Di::getInstance()->db->escape($to_username);
$to_userdata = get_userdata($to_username_sql);
if (!$to_userdata || $to_userdata['user_id'] == GUEST_UID) {
@@ -846,11 +848,11 @@ if ($mode == 'read') {
OR privmsgs_type = " . PRIVMSGS_READ_MAIL . "
OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )
AND privmsgs_to_userid = " . $to_userdata['user_id'];
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die($lang['NO_SUCH_USER']);
}
- if ($inbox_info = DB()->sql_fetchrow($result)) {
+ if ($inbox_info = Di::getInstance()->db->sql_fetchrow($result)) {
if ($di->config->get('max_inbox_privmsgs') && $inbox_info['inbox_items'] >= $di->config->get('max_inbox_privmsgs')) {
$sql = "SELECT privmsgs_id FROM " . BB_PRIVMSGS . "
WHERE ( privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
@@ -858,62 +860,62 @@ if ($mode == 'read') {
OR privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )
AND privmsgs_date = " . $inbox_info['oldest_post_time'] . "
AND privmsgs_to_userid = " . $to_userdata['user_id'];
- if (!$result = DB()->sql_query($sql)) {
+ if (!$result = Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not find oldest privmsgs (inbox)');
}
- $old_privmsgs_id = DB()->sql_fetchrow($result);
+ $old_privmsgs_id = Di::getInstance()->db->sql_fetchrow($result);
$old_privmsgs_id = (int)$old_privmsgs_id['privmsgs_id'];
$sql = "DELETE FROM " . BB_PRIVMSGS . " WHERE privmsgs_id = $old_privmsgs_id";
- if (!DB()->sql_query($sql)) {
+ if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not delete oldest privmsgs (inbox)');
}
$sql = "DELETE FROM " . BB_PRIVMSGS_TEXT . " WHERE privmsgs_text_id = $old_privmsgs_id";
- if (!DB()->sql_query($sql)) {
+ if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not delete oldest privmsgs text (inbox)');
}
}
}
$sql_info = "INSERT INTO " . BB_PRIVMSGS . " (privmsgs_type, privmsgs_subject, privmsgs_from_userid, privmsgs_to_userid, privmsgs_date, privmsgs_ip)
- VALUES (" . PRIVMSGS_NEW_MAIL . ", '" . DB()->escape($privmsg_subject) . "', " . $userdata['user_id'] . ", " . $to_userdata['user_id'] . ", $msg_time, '" . USER_IP . "')";
+ VALUES (" . PRIVMSGS_NEW_MAIL . ", '" . Di::getInstance()->db->escape($privmsg_subject) . "', " . $userdata['user_id'] . ", " . $to_userdata['user_id'] . ", $msg_time, '" . USER_IP . "')";
} else {
$sql_info = "UPDATE " . BB_PRIVMSGS . "
- SET privmsgs_type = " . PRIVMSGS_NEW_MAIL . ", privmsgs_subject = '" . DB()->escape($privmsg_subject) . "', privmsgs_from_userid = " . $userdata['user_id'] . ", privmsgs_to_userid = " . $to_userdata['user_id'] . ", privmsgs_date = $msg_time, privmsgs_ip = '" . USER_IP . "'
+ SET privmsgs_type = " . PRIVMSGS_NEW_MAIL . ", privmsgs_subject = '" . Di::getInstance()->db->escape($privmsg_subject) . "', privmsgs_from_userid = " . $userdata['user_id'] . ", privmsgs_to_userid = " . $to_userdata['user_id'] . ", privmsgs_date = $msg_time, privmsgs_ip = '" . USER_IP . "'
WHERE privmsgs_id = $privmsg_id";
}
- if (!($result = DB()->sql_query($sql_info))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql_info))) {
bb_die('Could not insert / update private message sent info');
}
if ($mode != 'edit') {
- $privmsg_sent_id = DB()->sql_nextid();
+ $privmsg_sent_id = Di::getInstance()->db->sql_nextid();
$sql = "INSERT INTO " . BB_PRIVMSGS_TEXT . " (privmsgs_text_id, privmsgs_text)
- VALUES ($privmsg_sent_id, '" . DB()->escape($privmsg_message) . "')";
+ VALUES ($privmsg_sent_id, '" . Di::getInstance()->db->escape($privmsg_message) . "')";
} else {
$sql = "UPDATE " . BB_PRIVMSGS_TEXT . "
- SET privmsgs_text = '" . DB()->escape($privmsg_message) . "'
+ SET privmsgs_text = '" . Di::getInstance()->db->escape($privmsg_message) . "'
WHERE privmsgs_text_id = $privmsg_id";
}
- if (!DB()->sql_query($sql)) {
+ if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not insert / update private message sent text');
}
if ($mode != 'edit') {
$timenow = TIMENOW;
// Add to the users new pm counter
- $sql = "UPDATE " . BB_USERS . " SET
+ $sql = "UPDATE bb_users SET
user_new_privmsg = user_new_privmsg + 1,
user_last_privmsg = $timenow,
user_newest_pm_id = $privmsg_sent_id
WHERE user_id = {$to_userdata['user_id']}
LIMIT 1";
- if (!$status = DB()->sql_query($sql)) {
+ if (!$status = Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not update private message new / read status for user');
}
@@ -964,14 +966,14 @@ if ($mode == 'read') {
$page_title = $lang['EDIT_PM'];
$sql = "SELECT u.user_id
- FROM " . BB_PRIVMSGS . " pm, " . BB_USERS . " u
+ FROM " . BB_PRIVMSGS . " pm, bb_users u
WHERE pm.privmsgs_id = $privmsg_id
AND u.user_id = pm.privmsgs_from_userid";
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not obtain post and post text');
}
- if ($postrow = DB()->sql_fetchrow($result)) {
+ if ($postrow = Di::getInstance()->db->sql_fetchrow($result)) {
if ($userdata['user_id'] != $postrow['user_id']) {
bb_die($lang['EDIT_OWN_POSTS']);
}
@@ -985,29 +987,29 @@ if ($mode == 'read') {
if (!empty($_GET[POST_USERS_URL])) {
$user_id = intval($_GET[POST_USERS_URL]);
- $sql = "SELECT username FROM " . BB_USERS . " WHERE user_id = $user_id AND user_id <> " . GUEST_UID;
- if (!($result = DB()->sql_query($sql))) {
+ $sql = "SELECT username FROM bb_users WHERE user_id = $user_id AND user_id <> " . GUEST_UID;
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
$error = true;
$error_msg = $lang['NO_SUCH_USER'];
}
- if ($row = DB()->sql_fetchrow($result)) {
+ if ($row = Di::getInstance()->db->sql_fetchrow($result)) {
$to_username = $row['username'];
}
} elseif ($mode == 'edit') {
$sql = "SELECT pm.*, pmt.privmsgs_text, u.username, u.user_id
- FROM " . BB_PRIVMSGS . " pm, " . BB_PRIVMSGS_TEXT . " pmt, " . BB_USERS . " u
+ FROM " . BB_PRIVMSGS . " pm, " . BB_PRIVMSGS_TEXT . " pmt, bb_users u
WHERE pm.privmsgs_id = $privmsg_id
AND pmt.privmsgs_text_id = pm.privmsgs_id
AND pm.privmsgs_from_userid = " . $userdata['user_id'] . "
AND ( pm.privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
OR pm.privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . " )
AND u.user_id = pm.privmsgs_to_userid";
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not obtain private message for editing #1');
}
- if (!($privmsg = DB()->sql_fetchrow($result))) {
+ if (!($privmsg = Di::getInstance()->db->sql_fetchrow($result))) {
redirect(PM_URL . "?folder=$folder");
}
@@ -1018,16 +1020,16 @@ if ($mode == 'read') {
$to_userid = $privmsg['user_id'];
} elseif ($mode == 'reply' || $mode == 'quote') {
$sql = "SELECT pm.privmsgs_subject, pm.privmsgs_date, pmt.privmsgs_text, u.username, u.user_id
- FROM " . BB_PRIVMSGS . " pm, " . BB_PRIVMSGS_TEXT . " pmt, " . BB_USERS . " u
+ FROM " . BB_PRIVMSGS . " pm, " . BB_PRIVMSGS_TEXT . " pmt, bb_users u
WHERE pm.privmsgs_id = $privmsg_id
AND pmt.privmsgs_text_id = pm.privmsgs_id
AND pm.privmsgs_to_userid = " . $userdata['user_id'] . "
AND u.user_id = pm.privmsgs_from_userid";
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not obtain private message for editing #2');
}
- if (!($privmsg = DB()->sql_fetchrow($result))) {
+ if (!($privmsg = Di::getInstance()->db->sql_fetchrow($result))) {
redirect(PM_URL . "?folder=$folder");
}
@@ -1181,7 +1183,7 @@ if ($mode == 'read') {
SET privmsgs_type = " . PRIVMSGS_UNREAD_MAIL . "
WHERE privmsgs_type = " . PRIVMSGS_NEW_MAIL . "
AND privmsgs_to_userid = " . $userdata['user_id'];
- if (!DB()->sql_query($sql)) {
+ if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not update private message new / read status (2) for user');
}
@@ -1211,7 +1213,7 @@ if ($mode == 'read') {
$sql_tot = "SELECT COUNT(privmsgs_id) AS total
FROM " . BB_PRIVMSGS . " ";
$sql = "SELECT pm.privmsgs_type, pm.privmsgs_id, pm.privmsgs_date, pm.privmsgs_subject, u.user_id, u.username, u.user_rank
- FROM " . BB_PRIVMSGS . " pm, " . BB_USERS . " u ";
+ FROM " . BB_PRIVMSGS . " pm, bb_users u ";
switch ($folder) {
case 'inbox':
$sql_tot .= "WHERE privmsgs_to_userid = " . $userdata['user_id'] . "
@@ -1289,17 +1291,17 @@ if ($mode == 'read') {
//
// Get messages
//
- if (!($result = DB()->sql_query($sql_tot))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql_tot))) {
bb_die('Could not query private message information #1');
}
- $pm_total = ($row = DB()->sql_fetchrow($result)) ? $row['total'] : 0;
+ $pm_total = ($row = Di::getInstance()->db->sql_fetchrow($result)) ? $row['total'] : 0;
- if (!($result = DB()->sql_query($sql_all_tot))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql_all_tot))) {
bb_die('Could not query private message information #2');
}
- $pm_all_total = ($row = DB()->sql_fetchrow($result)) ? $row['total'] : 0;
+ $pm_all_total = ($row = Di::getInstance()->db->sql_fetchrow($result)) ? $row['total'] : 0;
//
// Build select box
@@ -1395,11 +1397,11 @@ if ($mode == 'read') {
//
// Okay, let's build the correct folder
//
- if (!($result = DB()->sql_query($sql))) {
+ if (!($result = Di::getInstance()->db->sql_query($sql))) {
bb_die('Could not query private messages');
}
- if ($row = DB()->sql_fetchrow($result)) {
+ if ($row = Di::getInstance()->db->sql_fetchrow($result)) {
$i = 0;
do {
$privmsg_id = $row['privmsgs_id'];
@@ -1445,7 +1447,7 @@ if ($mode == 'read') {
'U_READ' => $u_subject,
));
- } while ($row = DB()->sql_fetchrow($result));
+ } while ($row = Di::getInstance()->db->sql_fetchrow($result));
generate_pagination(PM_URL . "?folder=$folder", $pm_total, $di->config->get('topics_per_page'), $start);
} else {
diff --git a/search.php b/search.php
index 7b8718239..5d308a3e7 100644
--- a/search.php
+++ b/search.php
@@ -23,6 +23,8 @@
* SOFTWARE.
*/
+use \TorrentPier\Di;
+
define('BB_SCRIPT', 'search');
define('BB_ROOT', './');
require(BB_ROOT . 'common.php');
@@ -53,9 +55,9 @@ if (isset($_POST['del_my_post'])) {
bb_die($lang['NONE_SELECTED']);
}
- DB()->query("UPDATE " . BB_POSTS . " SET user_post = 0 WHERE poster_id = {$user->id} AND topic_id IN($topic_csv)");
+ Di::getInstance()->db->query("UPDATE " . BB_POSTS . " SET user_post = 0 WHERE poster_id = {$user->id} AND topic_id IN($topic_csv)");
- if (DB()->affected_rows()) {
+ if (Di::getInstance()->db->affected_rows()) {
//bb_die('Выбранные темы ['. count($_POST['topic_id_list']) .' шт.] удалены из списка "Мои сообщения"');
bb_die($lang['DEL_MY_MESSAGE']);
} else {
@@ -72,7 +74,7 @@ if (isset($_POST['del_my_post'])) {
redirect('index.php');
}
- DB()->query("UPDATE " . BB_POSTS . " SET user_post = 1 WHERE poster_id = {$user->id}");
+ Di::getInstance()->db->query("UPDATE " . BB_POSTS . " SET user_post = 1 WHERE poster_id = {$user->id}");
redirect("search.php?u={$user->id}");
}
@@ -121,7 +123,7 @@ $forums_tbl = BB_FORUMS . ' f';
$posts_tbl = BB_POSTS . ' p';
$posts_text_tbl = BB_POSTS_TEXT . ' pt';
$posts_html_tbl = BB_POSTS_HTML . ' h';
-$tr_snap_tbl = BB_BT_TRACKER_SNAP . ' sn';
+$tr_snap_tbl = 'bb_bt_tracker_snap sn';
$topics_tbl = BB_TOPICS . ' t';
$torrents_tbl = BB_BT_TORRENTS . ' tor';
$tracker_tbl = BB_BT_TRACKER . ' tr';
@@ -338,7 +340,7 @@ $datastore->rm('cat_forums');
// Restore previously found items list and search settings if we have valid $search_id
if ($search_id) {
- $row = DB()->fetch_row("
+ $row = Di::getInstance()->db->fetch_row("
SELECT search_array, search_settings
FROM " . BB_SEARCH . "
WHERE session_id = '$session_id'
@@ -451,7 +453,7 @@ $title_match = ($text_match_sql && ($title_only_val || $di->config->get('disable
$post_mode = (!$dl_search && ($display_as_val == $as_posts || isset($_GET['search_author'])));
// Start building SQL
-$SQL = DB()->get_empty_sql_array();
+$SQL = Di::getInstance()->db->get_empty_sql_array();
// Displaying "as posts" mode
if ($post_mode) {
@@ -565,7 +567,7 @@ if ($post_mode) {
";
// Fetch posts data
- if (!$unsorted_rows = DB()->fetch_rowset($sql)) {
+ if (!$unsorted_rows = Di::getInstance()->db->fetch_rowset($sql)) {
bb_die($lang['NO_SEARCH_MATCH']);
}
$tmp = $sorted_rows = array();
@@ -759,7 +761,7 @@ else {
}
// Build SQL for displaying topics
- $SQL = DB()->get_empty_sql_array();
+ $SQL = Di::getInstance()->db->get_empty_sql_array();
$join_dl = ($di->config->get('show_dl_status_in_search') && !IS_GUEST);
$SQL['SELECT'][] = "
@@ -790,7 +792,7 @@ else {
// Fetch topics data
$topic_rows = array();
- foreach (DB()->fetch_rowset($SQL) as $row) {
+ foreach (Di::getInstance()->db->fetch_rowset($SQL) as $row) {
$topic_rows[$row['topic_id']] = $row;
}
if (!$topic_rows) {
@@ -865,7 +867,7 @@ function fetch_search_ids($sql, $search_type = SEARCH_TYPE_POST)
global $lang, $search_id, $session_id, $items_found, $per_page;
$items_found = array();
- foreach (DB()->fetch_rowset($sql) as $row) {
+ foreach (Di::getInstance()->db->fetch_rowset($sql) as $row) {
$items_found[] = $row['item_id'];
}
if (!$items_count = count($items_found)) {
@@ -901,12 +903,12 @@ function fetch_search_ids($sql, $search_type = SEARCH_TYPE_POST)
foreach ($save_in_db as $name) {
$curr_set[$GLOBALS["{$name}_key"]] = $GLOBALS["{$name}_val"];
}
- $search_settings = DB()->escape(serialize($curr_set));
+ $search_settings = Di::getInstance()->db->escape(serialize($curr_set));
$columns = 'session_id, search_type, search_id, search_time, search_settings, search_array';
$values = "'$session_id', $search_type, '$search_id', " . TIMENOW . ", '$search_settings', '$search_array'";
- DB()->query("REPLACE INTO " . BB_SEARCH . " ($columns) VALUES ($values)");
+ Di::getInstance()->db->query("REPLACE INTO " . BB_SEARCH . " ($columns) VALUES ($values)");
}
return array_slice($items_found, 0, $per_page);
@@ -922,9 +924,9 @@ function prevent_huge_searches($SQL)
$SQL['ORDER BY'] = array();
$SQL['LIMIT'] = array('0');
- if (DB()->query($SQL) && ($row = DB()->fetch_row("SELECT FOUND_ROWS() AS rows_count"))) {
+ if (Di::getInstance()->db->query($SQL) && ($row = Di::getInstance()->db->fetch_row("SELECT FOUND_ROWS() AS rows_count"))) {
if ($row['rows_count'] > $di->config->get('limit_max_search_results')) {
- # bb_log(str_compact(DB()->build_sql($SQL)) ." [{$row['rows_count']} rows]". LOG_LF, 'sql_huge_search');
+ # bb_log(str_compact(Di::getInstance()->db->build_sql($SQL)) ." [{$row['rows_count']} rows]". LOG_LF, 'sql_huge_search');
bb_die('Too_many_search_results');
}
}
@@ -942,14 +944,14 @@ function username_search($search_match)
$sql = "
SELECT username
- FROM " . BB_USERS . "
- WHERE username LIKE '" . DB()->escape($username_search) . "'
+ FROM bb_users
+ WHERE username LIKE '" . Di::getInstance()->db->escape($username_search) . "'
AND user_id <> " . GUEST_UID . "
ORDER BY username
LIMIT 200
";
- foreach (DB()->fetch_rowset($sql) as $row) {
+ foreach (Di::getInstance()->db->fetch_rowset($sql) as $row) {
$username = htmlCHR(stripslashes(html_entity_decode($row['username'])));
$username_list .= '';
}
diff --git a/src/Config.php b/src/Config.php
index f060babd4..d3f362b39 100644
--- a/src/Config.php
+++ b/src/Config.php
@@ -2,7 +2,7 @@
/**
* MIT License
*
- * Copyright (c) 2005-2016 TorrentPier
+ * 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
@@ -25,101 +25,149 @@
namespace TorrentPier;
-use Zend\Config\Config as ZendConfig;
+use \Exception;
-/**
- * Class Config
- * @package TorrentPier
- */
-class Config extends ZendConfig
+class Config implements \ArrayAccess
{
- protected $root;
+ public $dbQuery;
- /**
- * Config constructor.
- *
- * @param array $array
- * @param bool $allowModifications
- * @param Config|null $root
- */
- public function __construct(array $array, $allowModifications = false, Config &$root = null)
+ protected $data;
+ protected $mutableData = [];
+ protected $dbLoaded = false;
+
+ public function __construct(array $data)
{
- $this->allowModifications = (bool)$allowModifications;
-
- $this->root = $root;
-
- foreach ($array as $key => $value) {
- if (is_array($value)) {
- $this->data[$key] = new static($value, $this->allowModifications, $this);
- } else {
- $this->data[$key] = $value;
- }
- }
+ $this->data = $data;
}
- /**
- * @inheritdoc
- */
- public function get($name, $default = null)
+ public function __set($name, $value)
{
- $result = parent::get($name, null);
+ $this->set($name, $value);
+ }
- if ($result === null) {
- if (strpos($name, '.')) {
- $keys = explode('.', $name);
- $result = $this;
- foreach ($keys as $key) {
- $result = $result->get($key);
- if (null === $result) {
- break;
+ public function __get($name)
+ {
+ return $this->get($name);
+ }
+
+ public function offsetExists($offset)
+ {
+ return isset($this->data[$offset]) || isset($this->mutableData[$offset]);
+ }
+
+ public function offsetGet($name)
+ {
+ $default = null;
+ if (array_key_exists($name, $this->data)) {
+ return $this->data[$name];
+ } elseif (array_key_exists($name, $this->mutableData)) {
+ return $this->mutableData[$name];
+ } elseif (strpos($name, '.') !== false) {
+ return $this->getByPath(explode('.', $name), $default);
+ } else {
+ $ret = $default;
+ if (!$this->dbLoaded && isset($this->dbQuery)) {
+ $this->dbLoaded = true;
+ // TODO: cache
+ $db = Di::getInstance()->db;
+ foreach ($db->query($this->dbQuery)->fetchAll($db::FETCH_NUM) as $row) {
+ if (!array_key_exists($row[0], $this->data)) {
+ if ($row[0] == $name) {
+ $ret = $row[1];
+ }
+ $this->data[$row[0]] = $row[1];
}
}
}
-
- $result = $result ?: $default;
+ return $ret;
}
+ }
- return $this->prepareValue($result);
+ public function offsetSet($offset, $value)
+ {
+ $this->set($offset, $value);
+ }
+
+ public function offsetUnset($offset)
+ {
+ $this->delete($offset);
+ }
+
+ public function isExists($name)
+ {
+ return isset($this->data[$name]) || isset($this->mutableData[$name]);
}
/**
- * Parse value
- *
- * @param mixed $value
- * @return mixed
+ * @param $name
+ * @param $value
+ * @throws Exception
*/
- protected function prepareValue($value)
+ public function set($name, $value)
{
- if (is_string($value)) {
- $strPos = strpos($value, '{self.');
- if ($strPos !== false) {
- $strPos += 6;
- $key = substr($value, $strPos, (strpos($value, '}') - $strPos));
-
- $value = str_replace('{self.' . $key . '}', $this->root->get($key, ''), $value);
- }
+ if (isset($this->data[$name])) {
+ throw new Exception("$name is read only");
}
-
- return $value;
+ $this->mutableData[$name] = $value;
}
/**
- * @inheritdoc
+ * @param $name
+ * @throws Exception
*/
- public function toArray()
+ public function delete($name)
{
- $array = [];
- $data = $this->data;
+ if (isset($this->data[$name])) {
+ throw new Exception("$name is read only");
+ }
+ unset($this->mutableData[$name]);
+ }
- /** @var self $value */
- foreach ($data as $key => $value) {
- if ($value instanceof self) {
- $array[$key] = $value->toArray();
- } else {
- $array[$key] = $this->prepareValue($value);
+ public function get($name, $default = null)
+ {
+ if (array_key_exists($name, $this->data)) {
+ return $this->data[$name];
+ } elseif (array_key_exists($name, $this->mutableData)) {
+ return $this->mutableData[$name];
+ } elseif (strpos($name, '.') !== false) {
+ return $this->getByPath(explode('.', $name), $default);
+ } else {
+ $ret = $default;
+ if (!$this->dbLoaded && isset($this->dbQuery)) {
+ $this->dbLoaded = true;
+ // TODO: cache
+ foreach (Di::getInstance()->db->query($this->dbQuery)->fetchAll() as $row) {
+ if (!array_key_exists($row['config_name'], $this->data)) {
+ if ($row['config_name'] == $name) {
+ $ret = $row['config_value'];
+ }
+ $this->data[$row['config_name']] = $row['config_value'];
+ }
+ }
+ }
+ return $ret;
+ }
+ }
+
+ public function getByPath(array $path, $default = null)
+ {
+ $ret = $default;
+ $last = count($path) - 1;
+ $tmp = $this->data;
+ foreach ($path as $k => $part) {
+ if (array_key_exists($part, $tmp)) {
+ if ($k == $last) {
+ $ret = $tmp[$part];
+ } else {
+ $tmp = $tmp[$part];
+ }
}
}
+ return $ret;
+ }
- return $array;
+ public function merge(array $data)
+ {
+ $this->data = array_replace_recursive($this->data, $data);
}
}
diff --git a/src/Db.php b/src/Db.php
new file mode 100644
index 000000000..e489c84d9
--- /dev/null
+++ b/src/Db.php
@@ -0,0 +1,311 @@
+ PDO::ERRMODE_EXCEPTION,
+ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
+ ];
+
+ public $type;
+ public $stat;
+ public $sqlTimeTotal = 0;
+ public $numQueries = 0;
+
+ public function __construct(array $config)
+ {
+ $this->stat = $config['stat'] ?? true;
+ $type = $this->type = $config['type'] ?? 'mysql';
+ $options = $config['options'] ?? [];
+ $hostname = $config['hostname'] ?? '127.0.0.1';
+ $database = $config['database'] ?? null;
+ $username = $config['username'] ?? null;
+ $password = $config['password'] ?? null;
+ if (is_callable($password)) {
+ $password = $password();
+ }
+ $socket = $config['socket'] ?? null;
+ $port = $config['port'] ?? null;
+ $charset = $config['charset'] ?? null;
+
+ $dsn = null;
+ switch ($this->type) {
+ /** @noinspection PhpMissingBreakStatementInspection */
+ case 'mariadb':
+ $type = 'mysql';
+ // no break
+
+ case 'mysql':
+ if (isset($socket)) {
+ if ($socket === true) {
+ $socket = ini_get('pdo_mysql.default_socket');
+ }
+ $dsn = "$type:unix_socket=$socket;dbname=$database";
+ } else {
+ $dsn = "$type:host=$hostname" . (isset($port) ? ";port=$port" : '') . ";dbname=$database";
+ }
+ break;
+
+ case 'pgsql':
+ $dsn = "$type:host=$hostname" . (isset($port) ? ";port=$port" : '') . ";dbname=$database";
+ break;
+
+ case 'sybase':
+ $dsn = "dblib:host=$hostname" . (isset($port) ? ":$port" : '') . ";dbname=$database";
+ break;
+
+ case 'oracle':
+ $dbname = isset($hostname) ?
+ "//$hostname" . (isset($port) ? ":$port" : ':1521') . "/$database" :
+ $database;
+
+ $dsn = "oci:dbname=$dbname" . (isset($charset) ? ";charset=$charset" : '');
+ break;
+
+ case 'mssql':
+ $dsn = strstr(PHP_OS, 'WIN') ?
+ "sqlsrv:server=$hostname" . (isset($port) ? ",$port" : '') . ";database=$database" :
+ "dblib:host=$hostname" . (isset($port) ? ":$port" : '') . ";dbname=$database";
+ break;
+
+ case 'sqlite':
+ $dsn = "$type:$database";
+ $username = null;
+ $password = null;
+ break;
+
+ case 'default':
+ throw new PDOException("Unknown database driver");
+ }
+ $dsn .= ";charset=utf8";
+
+ parent::__construct(
+ $dsn,
+ $username,
+ is_callable($password) ? $password() : $password,
+ array_replace_recursive(
+ static::DEFAULT_OPTIONS,
+ $options
+ )
+ );
+ $this->setAttribute(static::ATTR_STATEMENT_CLASS, ['\\TorrentPier\\Db\\Statement', [$this]]);
+ }
+
+ public function prepare($statement, $options = [])
+ {
+ if (!$this->stat) {
+ return parent::prepare($statement);
+ }
+ $t = microtime(true);
+ $ret = parent::prepare($statement);
+ $this->sqlTimeTotal += microtime(true) - $t;
+ return $ret;
+ }
+
+ public function query($statement, ...$args)
+ {
+ if (!$this->stat) {
+ return parent::query($statement, ...$args);
+ }
+ $t = microtime(true);
+ $ret = parent::query($statement, ...$args);
+ $this->sqlTimeTotal += microtime(true) - $t;
+ $this->numQueries++;
+ return $ret;
+ }
+
+ public function exec($statement)
+ {
+ if (!$this->stat) {
+ return parent::exec($statement);
+ }
+ $t = microtime(true);
+ $ret = parent::exec($statement);
+ $this->sqlTimeTotal += microtime(true) - $t;
+ $this->numQueries++;
+ return $ret;
+ }
+
+ /** @deprecated
+ * @param $statement
+ * @return mixed
+ */
+ public function fetch_row($statement)
+ {
+ return $this->sql_fetchrow($this->sql_query($statement));
+ }
+
+ /** @deprecated
+ * @param $statement
+ * @return array
+ */
+ public function fetch_rowset($statement)
+ {
+ return $this->sql_fetchrowset($this->sql_query($statement));
+ }
+
+ /** @deprecated
+ * @param PDOStatement $statement
+ * @return array
+ */
+ public function sql_fetchrow(PDOStatement $statement)
+ {
+ return $statement->fetch();
+ }
+
+ /** @deprecated
+ * @param PDOStatement $statement
+ * @return array
+ */
+ public function sql_fetchrowset(PDOStatement $statement)
+ {
+ return $statement->fetchAll();
+ }
+
+ /** @deprecated
+ * @param $statement
+ * @return \PDOStatement
+ */
+ public function sql_query($statement)
+ {
+ if (is_array($statement)) {
+ $statement = $this->build_sql($statement);
+ }
+ return $this->query($statement);
+ }
+
+ /**
+ * @deprecated
+ * Escape data used in sql query
+ * @param $v
+ * @param bool $check_type
+ * @param bool $dont_escape
+ * @return string
+ */
+ public function escape($v, $check_type = false, $dont_escape = false)
+ {
+ if ($dont_escape) {
+ return $v;
+ }
+ if (!$check_type) {
+ return $this->quote($v);
+ }
+
+ switch (true) {
+ case is_string($v):
+ return $this->quote($v);
+ case is_int($v):
+ return "$v";
+ case is_bool($v):
+ return ($v) ? '1' : '0';
+ case is_float($v):
+ return "'$v'";
+ case is_null($v):
+ return 'NULL';
+ }
+ // if $v has unsuitable type
+ throw new PDOException(__FUNCTION__ . ' - wrong params');
+ }
+
+ /**
+ * @deprecated
+ * Return number of rows
+ * @param PDOStatement $result
+ * @return int
+ */
+ public function num_rows(PDOStatement $result)
+ {
+ return $result->rowCount();
+ }
+
+ /** @deprecated
+ * @param $sql_ary
+ * @return string
+ */
+ public function build_sql($sql_ary)
+ {
+ $sql = '';
+ array_deep($sql_ary, 'array_unique', false, true);
+
+ foreach ($sql_ary as $clause => $ary) {
+ switch ($clause) {
+ case 'SELECT':
+ $sql .= ($ary) ? ' SELECT ' . join(' ', $sql_ary['select_options']) . ' ' . join(', ', $ary) : '';
+ break;
+ case 'FROM':
+ $sql .= ($ary) ? ' FROM ' . join(', ', $ary) : '';
+ break;
+ case 'INNER JOIN':
+ $sql .= ($ary) ? ' INNER JOIN ' . join(' INNER JOIN ', $ary) : '';
+ break;
+ case 'LEFT JOIN':
+ $sql .= ($ary) ? ' LEFT JOIN ' . join(' LEFT JOIN ', $ary) : '';
+ break;
+ case 'WHERE':
+ $sql .= ($ary) ? ' WHERE ' . join(' AND ', $ary) : '';
+ break;
+ case 'GROUP BY':
+ $sql .= ($ary) ? ' GROUP BY ' . join(', ', $ary) : '';
+ break;
+ case 'HAVING':
+ $sql .= ($ary) ? ' HAVING ' . join(' AND ', $ary) : '';
+ break;
+ case 'ORDER BY':
+ $sql .= ($ary) ? ' ORDER BY ' . join(', ', $ary) : '';
+ break;
+ case 'LIMIT':
+ $sql .= ($ary) ? ' LIMIT ' . join(', ', $ary) : '';
+ break;
+ }
+ }
+
+ return trim($sql);
+ }
+
+ /** @deprecated */
+ public function get_empty_sql_array()
+ {
+ return [
+ 'SELECT' => [],
+ 'select_options' => [],
+ 'FROM' => [],
+ 'INNER JOIN' => [],
+ 'LEFT JOIN' => [],
+ 'WHERE' => [],
+ 'GROUP BY' => [],
+ 'HAVING' => [],
+ 'ORDER BY' => [],
+ 'LIMIT' => []
+ ];
+ }
+
+}
diff --git a/src/Db/Adapter.php b/src/Db/Adapter.php
deleted file mode 100644
index aa997c74a..000000000
--- a/src/Db/Adapter.php
+++ /dev/null
@@ -1,261 +0,0 @@
-toArray();
- }
-
- if ($profiler === null && is_array($driver) && !empty($driver['debug'])) {
- $profiler = new Profiler();
- }
-
- parent::__construct($driver, $platform, $queryResultPrototype, $profiler);
- }
-
- /**
- * Get sql object.
- *
- * @return Sql
- */
- protected function getSql()
- {
- return new Sql($this);
- }
-
- /**
- * Prepare table name.
- *
- * @param $table
- * @return mixed
- */
- protected function prepareTable($table)
- {
- $this->resultWrapper = null;
-
- if (is_string($table) && class_exists($table)) {
- $this->resultWrapper = new $table;
- $table = $this->resultWrapper->table();
- }
-
- return $table;
- }
-
- /**
- * Insert row to database.
- *
- * @param $table
- * @param array $values
- * @return mixed|null
- * @throws InvalidArgumentException
- */
- public function insert($table, array $values)
- {
- $table = $this->prepareTable($table);
- $sql = $this->getSql();
-
- /** @var Insert $sqlInsert */
- $sqlInsert = $sql->insert($table);
- $sqlInsert->values($values);
-
- $statementContainer = $sql->prepareStatementForSqlObject($sqlInsert);
- /** @var ResultInterface $result */
- $result = $statementContainer->execute();
- return $result->getGeneratedValue();
- }
-
- /**
- * Update rows in database.
- *
- * @param $table
- * @param array $values
- * @param Where|\Closure|string|array $where
- * @return int
- * @throws InvalidArgumentException
- */
- public function update($table, array $values, $where)
- {
- $table = $this->prepareTable($table);
- $sql = $this->getSql();
-
- /** @var Update $sqlUpdate */
- $sqlUpdate = $sql->update($table);
- $sqlUpdate->set($values);
- $sqlUpdate->where($where);
-
- $statementContainer = $sql->prepareStatementForSqlObject($sqlUpdate);
- /** @var ResultInterface $result */
- $result = $statementContainer->execute();
- return $result->getAffectedRows();
- }
-
- /**
- * Delete rows from database.
- *
- * @param string $table
- * @param array $where
- * @return int
- */
- public function delete($table, array $where)
- {
- $table = $this->prepareTable($table);
- $sql = $this->getSql();
-
- /** @var Delete $sqlDelete */
- $sqlDelete = $sql->delete($table);
- $sqlDelete->where($where);
-
- $statementContainer = $sql->prepareStatementForSqlObject($sqlDelete);
- /** @var ResultInterface $result */
- $result = $statementContainer->execute();
- return $result->getAffectedRows();
- }
-
- /**
- * Select rows from database.
- *
- * @param $table
- * @param null|\Closure|array $queryCallback
- * @return PrepareStatement
- * @throws InvalidArgumentException
- */
- public function select($table, $queryCallback = null)
- {
- $table = $this->prepareTable($table);
- $sql = $this->getSql();
-
- /** @var Select $sqlDelete */
- $sqlSelect = $sql->select($table);
-
- if ($queryCallback instanceof \Closure) {
- call_user_func($queryCallback, $sqlSelect);
- } elseif (is_array($queryCallback)) {
- $sqlSelect->where($queryCallback);
- }
-
- $statementContainer = $sql->prepareStatementForSqlObject($sqlSelect);
- return new PrepareStatement($statementContainer, $this->resultWrapper);
- }
-
- /**
- * Count rows in database.
- *
- * @param $table
- * @param null|\Closure|array $queryCallback
- * @return int
- * @throws InvalidArgumentException
- */
- public function count($table, $queryCallback = null)
- {
- $table = $this->prepareTable($table);
- $sql = $this->getSql();
-
- /** @var Select $sqlDelete */
- $sqlSelect = $sql->select($table);
-
- if ($queryCallback instanceof \Closure) {
- call_user_func($queryCallback, $sqlSelect);
- } elseif (is_array($queryCallback)) {
- $sqlSelect->where($queryCallback);
- }
-
- $sqlSelect->columns(['count' => new Expression('COUNT(*)')]);
-
- $statementContainer = $sql->prepareStatementForSqlObject($sqlSelect);
- /** @var ResultInterface $result */
- $result = $statementContainer->execute();
- return $result->current()['count'];
- }
-
- /**
- * Increment field by query.
- *
- * @param string $table
- * @param string $field
- * @param Where|\Closure|string|array $where
- * @param int $num
- * @return int
- * @throws InvalidArgumentException
- */
- public function increment($table, $field, $where = null, $num = 1)
- {
- return $this->update($table, [
- $field => new Expression('? + ?', [$field, $num], [Expression::TYPE_IDENTIFIER, Expression::TYPE_VALUE])
- ], $where);
- }
-
- /**
- * Decrement field by query.
- *
- * @param string $table
- * @param string $field
- * @param Where|\Closure|string|array $where
- * @param int $num
- * @return int
- * @throws InvalidArgumentException
- */
- public function decrement($table, $field, $where = null, $num = 1)
- {
- return $this->update($table, [
- $field => new Expression('? - ?', [$field, $num], [Expression::TYPE_IDENTIFIER, Expression::TYPE_VALUE])
- ], $where);
- }
-}
diff --git a/src/Db/PrepareStatement.php b/src/Db/PrepareStatement.php
deleted file mode 100644
index d7c70633d..000000000
--- a/src/Db/PrepareStatement.php
+++ /dev/null
@@ -1,101 +0,0 @@
-statementContainer = $statementContainer;
- $this->resultWrapper = $resultWrapper;
- }
-
- /**
- * Executing a query and wrapping a result.
- *
- * @return HydratingResultSet|ResultSet
- * @throws InvalidArgumentException
- */
- protected function execute()
- {
- $result = $this->statementContainer->execute();
-
- if ($this->resultWrapper) {
- $entityClass = $this->resultWrapper;
- $resultSet = new HydratingResultSet(new Reflection(), new $entityClass);
- $resultSet->initialize($result);
- } else {
- $resultSet = new ResultSet();
- $resultSet->initialize($result);
- }
-
- return $resultSet;
- }
-
- /**
- * Current result.
- *
- * @return array|null
- * @throws InvalidArgumentException
- */
- public function one()
- {
- return $this->execute()->current() ?: null;
- }
-
- /**
- * All results.
- *
- * @return HydratingResultSet|ResultSet
- * @throws InvalidArgumentException
- */
- public function all()
- {
- return $this->execute();
- }
-}
diff --git a/src/Db/Entity.php b/src/Db/Statement.php
similarity index 67%
rename from src/Db/Entity.php
rename to src/Db/Statement.php
index 925ca4fa1..8a47868e2 100644
--- a/src/Db/Entity.php
+++ b/src/Db/Statement.php
@@ -2,7 +2,7 @@
/**
* MIT License
*
- * Copyright (c) 2005-2016 TorrentPier
+ * 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
@@ -25,12 +25,27 @@
namespace TorrentPier\Db;
-abstract class Entity
-{
- protected $table;
+use \PDOStatement;
+use TorrentPier\Db;
- public function table()
+class Statement extends PDOStatement
+{
+ protected $db = null;
+
+ protected function __construct(Db $db)
{
- return $this->table;
+ $this->db = $db;
+ }
+
+ public function execute($input_parameters = null)
+ {
+ if (!$this->db->stat) {
+ return parent::execute($input_parameters);
+ }
+ $t = microtime(true);
+ $ret = parent::execute($input_parameters);
+ $this->db->sqlTimeTotal += microtime(true) - $t;
+ $this->db->numQueries++;
+ return $ret;
}
}
diff --git a/src/Di.php b/src/Di.php
index 252816c2b..fca8b5432 100644
--- a/src/Di.php
+++ b/src/Di.php
@@ -30,6 +30,9 @@ use Pimple\Container;
/**
* Class Di
* Dependency Injection Container.
+ *
+ * @property Config $config
+ * @property Db $db
*/
class Di extends Container
{
diff --git a/src/ServiceProviders/CacheServiceProvider.php b/src/ServiceProviders/CacheServiceProvider.php
index 3b7daf5d4..203628e95 100644
--- a/src/ServiceProviders/CacheServiceProvider.php
+++ b/src/ServiceProviders/CacheServiceProvider.php
@@ -41,10 +41,10 @@ class CacheServiceProvider implements ServiceProviderInterface
public function register(Container $container)
{
$container['cache'] = function (Container $container) {
- $setting = $container['config.services.cache'];
+ $setting = $container['config']->get('services.cache');
/** @var Adapter $adapter */
$adapter = new $setting['adapter']();
- $adapter->setOptions($setting['options']->toArray());
+ $adapter->setOptions($setting['options']);
return $adapter;
};
}
diff --git a/src/ServiceProviders/ConfigServiceProvider.php b/src/ServiceProviders/ConfigServiceProvider.php
index 140c59baa..886b79413 100644
--- a/src/ServiceProviders/ConfigServiceProvider.php
+++ b/src/ServiceProviders/ConfigServiceProvider.php
@@ -41,11 +41,15 @@ class ConfigServiceProvider implements ServiceProviderInterface
*/
public function register(Container $container)
{
- $container['config'] = function ($container) {
+ $container['config'] = function (Container $container) {
$config = new Config(Factory::fromFile($container['file.system.main']));
if (isset($container['file.local.main']) && file_exists($container['file.local.main'])) {
- $config->merge(new Config(Factory::fromFile($container['file.local.main'])));
+ $config->merge(Factory::fromFile($container['file.local.main']));
+ }
+
+ if (isset($container['config.dbQuery'])) {
+ $config->dbQuery = $container['config.dbQuery'];
}
return $config;
diff --git a/src/ServiceProviders/DbServiceProvider.php b/src/ServiceProviders/DbServiceProvider.php
index fa46ed95d..1a920e505 100644
--- a/src/ServiceProviders/DbServiceProvider.php
+++ b/src/ServiceProviders/DbServiceProvider.php
@@ -27,7 +27,7 @@ namespace TorrentPier\ServiceProviders;
use Pimple\Container;
use Pimple\ServiceProviderInterface;
-use TorrentPier\Db\Adapter;
+use TorrentPier\Db;
/**
* Class DbServiceProvider
@@ -40,10 +40,8 @@ class DbServiceProvider implements ServiceProviderInterface
*/
public function register(Container $container)
{
- $container['db'] = function ($container) {
- $adapter = new Adapter($container['config.services.db']);
- unset($container['config.services.db']);
- return $adapter;
+ $container['db'] = function (Container $container) {
+ return new Db($container['config']->get('services.db'));
};
}
}
diff --git a/tests/src/ConfigTest.php b/tests/src/ConfigTest.php
index d8e6344c0..29f004362 100644
--- a/tests/src/ConfigTest.php
+++ b/tests/src/ConfigTest.php
@@ -45,8 +45,6 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
'key1' => 'value1',
'key2' => [
'key3' => 'value2',
- 'key4' => '{self.key1}',
- 'key5' => '{self.key2.key4}',
]
];
@@ -62,31 +60,10 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
{
static::assertEquals($this->config->get('key1'), 'value1');
static::assertEquals($this->config->get('key2.key3'), 'value2');
- static::assertEquals($this->config->get('key2.key4'), 'value1');
- static::assertEquals($this->config->get('key2.key5'), 'value1');
- static::assertEquals($this->config->get('key2')->get('key3'), 'value2');
static::assertEquals($this->config['key1'], 'value1');
static::assertEquals($this->config['key2.key3'], 'value2');
- static::assertEquals($this->config['key2.key4'], 'value1');
- static::assertEquals($this->config['key2.key5'], 'value1');
static::assertEquals($this->config['key2']['key3'], 'value2');
-
- static::assertEquals($this->config['key2.key6'], null);
}
- /**
- * @covers \TorrentPier\Config::toArray
- */
- public function testToArray()
- {
- static::assertEquals($this->config->toArray(), [
- 'key1' => 'value1',
- 'key2' => [
- 'key3' => 'value2',
- 'key4' => 'value1',
- 'key5' => 'value1',
- ]
- ]);
- }
}
diff --git a/tests/src/Db/AdapterTest.php b/tests/src/Db/AdapterTest.php
deleted file mode 100644
index cafa0cf72..000000000
--- a/tests/src/Db/AdapterTest.php
+++ /dev/null
@@ -1,234 +0,0 @@
-getMock(Result::class, ['getGeneratedValue', 'getAffectedRows']);
- $resultMock->method('getGeneratedValue')->willReturn(self::AFFECTED_ROWS);
- $resultMock->method('getAffectedRows')->willReturn(self::AFFECTED_ROWS);
-
- $this->statementMock = $this->getMock(Statement::class, ['execute']);
- $this->statementMock->method('execute')->willReturn($resultMock);
-
- $this->adapterMock = $this->getMockBuilder(Adapter::class)
- ->setMethods(['getSql', 'getPlatform', 'getDriver'])
- ->disableOriginalConstructor()
- ->getMock();
-
- $platformMock = $this->getMock(AbstractPlatform::class, ['getName', 'quoteIdentifier', 'quoteValue']);
- $platformMock->method('quoteIdentifier')->willReturnCallback(function ($v) {
- return '`' . $v . '`';
- });
- $platformMock->method('quoteValue')->willReturnCallback(function ($v) {
- if (is_int($v)) {
- return $v;
- } elseif ($v instanceof \DateTime) {
- $v = $v->format('Y-m-d H:i:s');
- }
-
- return '\'' . $v . '\'';
- });
- $platformMock->method('getName')->willReturn('platform name');
- $this->adapterMock->method('getPlatform')->willReturn($platformMock);
-
- $connectionMock = $this->getMock(Connection::class);
-
- $driverMock = $this->getMock(Pdo::class, [], [
- $connectionMock,
- $this->statementMock,
- $resultMock,
- ]);
- $this->adapterMock->method('getDriver')->willReturn($driverMock);
-
- $this->sqlMock = $this->getMockBuilder(Sql::class)
- ->setMethods(['prepareStatementForSqlObject'])
- ->setConstructorArgs([$this->adapterMock])
- ->getMock();
- $this->adapterMock->method('getSql')->willReturn($this->sqlMock);
- }
-
- /**
- * Create sql insert query.
- * @covers \TorrentPier\Db\Adapter::insert
- */
- public function testInsert()
- {
- $date = new \DateTime('now', new \DateTimeZone('UTC'));
-
- $this->sqlMock->expects(static::once())
- ->method('prepareStatementForSqlObject')
- ->willReturnCallback(function (Insert $sqlObject) use ($date) {
- static::assertEquals(
- join(' ', [
- "INSERT INTO",
- "`tableName` (`field_int`, `field_str`, `field_date`)",
- "VALUES (123, 'string', '{$date->format('Y-m-d H:i:s')}')",
- ]),
- $this->sqlMock->buildSqlString($sqlObject)
- );
- return $this->statementMock;
- });
-
- $actual = $this->adapterMock->insert('tableName', [
- 'field_int' => 123,
- 'field_str' => 'string',
- 'field_date' => $date,
- ]);
-
- static::assertEquals(self::AFFECTED_ROWS, $actual);
- }
-
- /**
- * Create sql update query.
- * @covers \TorrentPier\Db\Adapter::update
- */
- public function testUpdate()
- {
- $date = new \DateTime('now', new \DateTimeZone('UTC'));
-
- $this->sqlMock->expects(static::once())
- ->method('prepareStatementForSqlObject')
- ->willReturnCallback(function (Update $sqlObject) use ($date) {
- static::assertEquals(
- join(' ', [
- "UPDATE `tableName` SET",
- "`field_int` = 123, `field_str` = 'string', `field_date` = '{$date->format('Y-m-d H:i:s')}'",
- "WHERE \"field_id\" = 1"
- ]),
- $this->sqlMock->buildSqlString($sqlObject)
- );
- return $this->statementMock;
- });
-
- $actual = $this->adapterMock->update('tableName', [
- 'field_int' => 123,
- 'field_str' => 'string',
- 'field_date' => $date,
- ], [
- 'field_id' => 1
- ]);
-
- static::assertEquals(self::AFFECTED_ROWS, $actual);
- }
-
- /**
- * Create sql delete query.
- * @covers \TorrentPier\Db\Adapter::delete
- */
- public function testDelete()
- {
- $this->sqlMock->expects(static::once())
- ->method('prepareStatementForSqlObject')
- ->willReturnCallback(function (Delete $sqlObject) {
- static::assertEquals(
- "DELETE FROM `tableName` WHERE \"field_id\" = 1",
- $this->sqlMock->buildSqlString($sqlObject)
- );
- return $this->statementMock;
- });
-
- $actual = $this->adapterMock->delete('tableName', [
- 'field_id' => 1
- ]);
-
- static::assertEquals(self::AFFECTED_ROWS, $actual);
- }
-
- /**
- * Create sql increment query.
- * @covers \TorrentPier\Db\Adapter::increment
- */
- public function testIncrement()
- {
- $this->sqlMock->expects(static::once())
- ->method('prepareStatementForSqlObject')
- ->willReturnCallback(function (Update $sqlObject) {
- static::assertEquals(
- "UPDATE `tableName` SET `inc` = \"inc\" + 1 WHERE \"field_id\" = 1",
- $this->sqlMock->buildSqlString($sqlObject)
- );
- return $this->statementMock;
- });
-
- $actual = $this->adapterMock->increment('tableName', 'inc', ['field_id' => 1]);
-
- static::assertEquals(self::AFFECTED_ROWS, $actual);
- }
-
- /**
- * Create sql decrement query.
- * @covers \TorrentPier\Db\Adapter::decrement
- */
- public function testDecrement()
- {
- $this->sqlMock->expects(static::once())
- ->method('prepareStatementForSqlObject')
- ->willReturnCallback(function (Update $sqlObject) {
- static::assertEquals(
- "UPDATE `tableName` SET `inc` = \"inc\" - 1 WHERE \"field_id\" = 1",
- $this->sqlMock->buildSqlString($sqlObject)
- );
- return $this->statementMock;
- });
-
- $actual = $this->adapterMock->decrement('tableName', 'inc', ['field_id' => 1]);
-
- static::assertEquals(self::AFFECTED_ROWS, $actual);
- }
-}
diff --git a/tracker.php b/tracker.php
index 94a55643c..d2b9e9740 100644
--- a/tracker.php
+++ b/tracker.php
@@ -23,6 +23,8 @@
* SOFTWARE.
*/
+use \TorrentPier\Di;
+
define('BB_SCRIPT', 'tracker');
define('BB_ROOT', './');
require(BB_ROOT . 'common.php');
@@ -79,7 +81,7 @@ $posts_tbl = BB_POSTS . ' p';
$topics_tbl = BB_TOPICS . ' t';
$users_tbl = BB_USERS . ' u';
$tracker_tbl = BB_BT_TRACKER . ' tr';
-$tr_snap_tbl = BB_BT_TRACKER_SNAP . ' sn';
+$tr_snap_tbl = 'bb_bt_tracker_snap sn';
$dl_stat_tbl = BB_BT_DLSTATUS . ' dl';
//
@@ -321,7 +323,7 @@ $tor_list_ary = array();
$tor_list_sql = '';
if ($search_id) {
- $row = DB()->fetch_row("
+ $row = Di::getInstance()->db->fetch_row("
SELECT search_array, search_settings
FROM " . BB_SEARCH . "
WHERE session_id = '$session_id'
@@ -516,7 +518,7 @@ if ($allowed_forums) {
foreach ($save_in_db as $name) {
$curr_set[${"{$name}_key"}] = ${"{$name}_val"};
}
- $curr_set_sql = DB()->escape(serialize($curr_set));
+ $curr_set_sql = Di::getInstance()->db->escape(serialize($curr_set));
// Text search
$search_match_topics_csv = '';
@@ -547,7 +549,7 @@ if ($allowed_forums) {
$join_dl = $dl_search;
// Start building SQL
- $SQL = DB()->get_empty_sql_array();
+ $SQL = Di::getInstance()->db->get_empty_sql_array();
// SELECT
$SQL['SELECT'][] = "tor.topic_id";
@@ -621,7 +623,7 @@ if ($allowed_forums) {
$tor_list_sql = '';
$tor_count = 0;
} else {
- foreach (DB()->fetch_rowset($SQL) as $row) {
+ foreach (Di::getInstance()->db->fetch_rowset($SQL) as $row) {
$tor_list_ary[] = $row['topic_id'];
}
$tor_list_sql = join(',', $tor_list_ary);
@@ -643,7 +645,7 @@ if ($allowed_forums) {
$columns = 'session_id, search_type, search_id, search_time, search_settings, search_array';
$values = "'$session_id', $search_type, '$search_id', " . TIMENOW . ", '$curr_set_sql', '$tor_list_sql'";
- DB()->query("REPLACE INTO " . BB_SEARCH . " ($columns) VALUES ($values)");
+ Di::getInstance()->db->query("REPLACE INTO " . BB_SEARCH . " ($columns) VALUES ($values)");
}
unset($columns, $values, $curr_set_sql, $tor_list_sql);
@@ -704,9 +706,9 @@ if ($allowed_forums) {
$limit
";
- $passkey = DB()->fetch_row("SELECT auth_key FROM " . BB_BT_USERS . " WHERE user_id = " . (int)$user_id . " LIMIT 1");
+ $passkey = Di::getInstance()->db->fetch_row("SELECT auth_key FROM " . BB_BT_USERS . " WHERE user_id = " . (int)$user_id . " LIMIT 1");
// Build torrents table
- foreach (DB()->fetch_rowset($sql) as $tor) {
+ foreach (Di::getInstance()->db->fetch_rowset($sql) as $tor) {
$dl = isset($tor['speed_down']) ? $tor['speed_down'] : 0;
$ul = isset($tor['speed_up']) ? $tor['speed_up'] : 0;
diff --git a/viewforum.php b/viewforum.php
index c776298ad..cfd1bcd57 100644
--- a/viewforum.php
+++ b/viewforum.php
@@ -23,6 +23,8 @@
* SOFTWARE.
*/
+use \TorrentPier\Di;
+
define('BB_SCRIPT', 'forum');
define('BB_ROOT', './');
require(BB_ROOT . 'common.php');
@@ -162,17 +164,17 @@ if (!$forum_data['forum_parent'] && isset($forums['f'][$forum_id]['subforums'])
f.forum_id, f.forum_status, f.forum_last_post_id, f.forum_posts, f.forum_topics,
t.topic_last_post_time, t.topic_id AS last_topic_id, t.topic_title AS last_topic_title,
p.poster_id AS sf_last_user_id, IF(p.poster_id = $anon, p.post_username, u.username) AS sf_last_username, u.user_rank
- FROM " . BB_FORUMS . " f
- LEFT JOIN " . BB_TOPICS . " t ON(f.forum_last_post_id = t.topic_last_post_id)
+ FROM bb_forums f
+ LEFT JOIN bb_topics t ON(f.forum_last_post_id = t.topic_last_post_id)
LEFT JOIN " . BB_POSTS . " p ON(f.forum_last_post_id = p.post_id)
- LEFT JOIN " . BB_USERS . " u ON(p.poster_id = u.user_id)
+ LEFT JOIN bb_users u ON(p.poster_id = u.user_id)
WHERE f.forum_parent = $forum_id
$only_new_sql
$ignore_forum_sql
ORDER BY f.forum_order
";
- if ($rowset = DB()->fetch_rowset($sql)) {
+ if ($rowset = Di::getInstance()->db->fetch_rowset($sql)) {
$template->assign_vars(array(
'SHOW_SUBFORUMS' => true,
'FORUM_IMG' => $images['forum'],
@@ -269,12 +271,12 @@ if (!empty($_REQUEST['topicdays'])) {
if (($req_topic_days = $di->request->query->getInt('topicdays')) && isset($sel_previous_days[$req_topic_days])) {
$sql = "
SELECT COUNT(*) AS forum_topics
- FROM " . BB_TOPICS . "
+ FROM bb_topics
WHERE forum_id = $forum_id
AND topic_last_post_time > " . (TIMENOW - 86400 * $req_topic_days) . "
";
- if ($row = DB()->fetch_row($sql)) {
+ if ($row = Di::getInstance()->db->fetch_row($sql)) {
$topic_days = $req_topic_days;
$forum_topics = $row['forum_topics'];
}
@@ -316,9 +318,9 @@ if ($forum_data['allow_reg_tracker']) {
$select_tor_sql .= ($join_dl) ? ', dl.user_status AS dl_status' : '';
$join_tor_sql = "
- LEFT JOIN " . BB_BT_TORRENTS . " tor ON(t.topic_id = tor.topic_id)
+ LEFT JOIN bb_bt_torrents tor ON(t.topic_id = tor.topic_id)
LEFT JOIN " . BB_BT_USERS . " bt ON(bt.user_id = {$userdata['user_id']})
- LEFT JOIN " . BB_BT_TRACKER_SNAP . " sn ON(tor.topic_id = sn.topic_id)
+ LEFT JOIN bb_bt_tracker_snap sn ON(tor.topic_id = sn.topic_id)
";
$join_tor_sql .= ($join_dl) ? " LEFT JOIN " . BB_BT_DLSTATUS . " dl ON(dl.user_id = {$userdata['user_id']} AND dl.topic_id = t.topic_id)" : '';
}
@@ -343,7 +345,7 @@ $topic_ids = $topic_rowset = array();
// IDs
$sql = "
SELECT t.topic_id
- FROM " . BB_TOPICS . " t
+ FROM bb_topics t
WHERE t.forum_id = $forum_id
$only_new_sql
$title_match_sql
@@ -351,24 +353,24 @@ $sql = "
$order_sql
LIMIT $start, $topics_per_page
";
-foreach (DB()->fetch_rowset($sql) as $row) {
+foreach (Di::getInstance()->db->fetch_rowset($sql) as $row) {
$topic_ids[] = $row['topic_id'];
}
// Titles, posters etc.
if ($topics_csv = join(',', $topic_ids)) {
- $topic_rowset = DB()->fetch_rowset("
+ $topic_rowset = Di::getInstance()->db->fetch_rowset("
SELECT
t.*, t.topic_poster AS first_user_id, u1.user_rank as first_user_rank,
IF(t.topic_poster = $anon, p1.post_username, u1.username) AS first_username,
p2.poster_id AS last_user_id, u2.user_rank as last_user_rank,
IF(p2.poster_id = $anon, p2.post_username, u2.username) AS last_username
$select_tor_sql
- FROM " . BB_TOPICS . " t
+ FROM bb_topics t
LEFT JOIN " . BB_POSTS . " p1 ON(t.topic_first_post_id = p1.post_id)
- LEFT JOIN " . BB_USERS . " u1 ON(t.topic_poster = u1.user_id)
+ LEFT JOIN bb_users u1 ON(t.topic_poster = u1.user_id)
LEFT JOIN " . BB_POSTS . " p2 ON(t.topic_last_post_id = p2.post_id)
- LEFT JOIN " . BB_USERS . " u2 ON(p2.poster_id = u2.user_id)
+ LEFT JOIN bb_users u2 ON(p2.poster_id = u2.user_id)
$join_tor_sql
WHERE t.topic_id IN($topics_csv)
$where_tor_sql
diff --git a/viewtopic.php b/viewtopic.php
index bd969b229..1213cd012 100644
--- a/viewtopic.php
+++ b/viewtopic.php
@@ -23,6 +23,8 @@
* SOFTWARE.
*/
+use \TorrentPier\Di;
+
define('BB_SCRIPT', 'topic');
define('BB_ROOT', './');
require(BB_ROOT . 'common.php');
@@ -83,15 +85,15 @@ $tracking_forums = get_tracks('forum');
// Get forum/topic data
if ($topic_id) {
$sql = "SELECT t.*, f.*, tw.notify_status
- FROM " . BB_TOPICS . " t
- LEFT JOIN " . BB_FORUMS . " f USING(forum_id)
+ FROM bb_topics t
+ LEFT JOIN bb_forums f USING(forum_id)
LEFT JOIN " . BB_TOPICS_WATCH . " tw ON(tw.topic_id = t.topic_id AND tw.user_id = {$userdata['user_id']})
WHERE t.topic_id = $topic_id
";
} elseif ($post_id) {
$sql = "SELECT t.*, f.*, p.post_time, tw.notify_status
- FROM " . BB_TOPICS . " t
- LEFT JOIN " . BB_FORUMS . " f USING(forum_id)
+ FROM bb_topics t
+ LEFT JOIN bb_forums f USING(forum_id)
LEFT JOIN " . BB_POSTS . " p USING(topic_id)
LEFT JOIN " . BB_TOPICS_WATCH . " tw ON(tw.topic_id = t.topic_id AND tw.user_id = {$userdata['user_id']})
WHERE p.post_id = $post_id
@@ -100,7 +102,7 @@ if ($topic_id) {
bb_die($lang['TOPIC_POST_NOT_EXIST']);
}
-if (!$t_data = DB()->fetch_row($sql)) {
+if (!$t_data = Di::getInstance()->db->fetch_row($sql)) {
meta_refresh('index.php', 10);
bb_die($lang['TOPIC_POST_NOT_EXIST']);
}
@@ -132,7 +134,7 @@ if (isset($_GET['view']) && $_GET['view'] === 'newest' && !IS_GUEST && $topic_id
ORDER BY post_time ASC
LIMIT 1";
- if ($row = DB()->fetch_row($sql)) {
+ if ($row = Di::getInstance()->db->fetch_row($sql)) {
$post_id = $newest = $row['post_id'];
$t_data['post_time'] = $row['post_time'];
}
@@ -144,7 +146,7 @@ if ($post_id && !empty($t_data['post_time']) && ($t_data['topic_replies'] + 1) >
WHERE topic_id = $topic_id
AND post_time <= {$t_data['post_time']}";
- if ($row = DB()->fetch_row($sql)) {
+ if ($row = Di::getInstance()->db->fetch_row($sql)) {
$t_data['prev_posts'] = $row['prev_posts'];
}
}
@@ -225,21 +227,21 @@ if ($di->config->get('topic_notify_enabled')) {
if (isset($_GET['unwatch'])) {
if ($_GET['unwatch'] == 'topic') {
$is_watching_topic = 0;
- DB()->query("DELETE FROM " . BB_TOPICS_WATCH . " WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']}");
+ Di::getInstance()->db->query("DELETE FROM " . BB_TOPICS_WATCH . " WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']}");
}
set_die_append_msg($forum_id, $topic_id);
bb_die($lang['NO_LONGER_WATCHING']);
} else {
$is_watching_topic = true;
if (!$t_data['notify_status']) {
- DB()->query("UPDATE " . BB_TOPICS_WATCH . " SET notify_status = " . TOPIC_WATCH_NOTIFIED . " WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']}");
+ Di::getInstance()->db->query("UPDATE " . BB_TOPICS_WATCH . " SET notify_status = " . TOPIC_WATCH_NOTIFIED . " WHERE topic_id = $topic_id AND user_id = {$userdata['user_id']}");
}
}
} else {
if (isset($_GET['watch'])) {
if ($_GET['watch'] == 'topic') {
$is_watching_topic = true;
- DB()->query("
+ Di::getInstance()->db->query("
INSERT INTO " . BB_TOPICS_WATCH . " (user_id, topic_id, notify_status)
VALUES (" . $userdata['user_id'] . ", $topic_id, " . TOPIC_WATCH_NOTIFIED . ")
");
@@ -274,12 +276,12 @@ if (!empty($_REQUEST['postdays'])) {
$min_post_time = TIMENOW - ($post_days * 86400);
$sql = "SELECT COUNT(p.post_id) AS num_posts
- FROM " . BB_TOPICS . " t, " . BB_POSTS . " p
+ FROM bb_topics t, " . BB_POSTS . " p
WHERE t.topic_id = $topic_id
AND p.topic_id = t.topic_id
AND p.post_time > $min_post_time";
- $total_replies = ($row = DB()->fetch_row($sql)) ? $row['num_posts'] : 0;
+ $total_replies = ($row = Di::getInstance()->db->fetch_row($sql)) ? $row['num_posts'] : 0;
$limit_posts_time = "AND p.post_time >= $min_post_time ";
}
}
@@ -293,7 +295,7 @@ $post_order = (isset($_POST['postorder']) && $_POST['postorder'] !== 'asc') ? 'd
// 1. Add first post of topic if it pinned and page of topic not first
$first_post = false;
if ($t_data['topic_show_first_post'] && $start) {
- $first_post = DB()->fetch_rowset("
+ $first_post = Di::getInstance()->db->fetch_rowset("
SELECT
u.username, u.user_id, u.user_rank, u.user_posts, u.user_from,
u.user_regdate, u.user_sig,
@@ -303,10 +305,10 @@ if ($t_data['topic_show_first_post'] && $start) {
u2.username as mc_username, u2.user_rank as mc_user_rank,
h.post_html, IF(h.post_html IS NULL, pt.post_text, NULL) AS post_text
FROM " . BB_POSTS . " p
- LEFT JOIN " . BB_USERS . " u ON(u.user_id = p.poster_id)
+ LEFT JOIN bb_users u ON(u.user_id = p.poster_id)
LEFT JOIN " . BB_POSTS_TEXT . " pt ON(pt.post_id = p.post_id)
LEFT JOIN " . BB_POSTS_HTML . " h ON(h.post_id = p.post_id)
- LEFT JOIN " . BB_USERS . " u2 ON(u2.user_id = p.mc_user_id)
+ LEFT JOIN bb_users u2 ON(u2.user_id = p.mc_user_id)
LEFT JOIN " . BB_GROUPS . " g ON(g.group_id = p.poster_rg_id)
WHERE
p.post_id = {$t_data['topic_first_post_id']}
@@ -324,10 +326,10 @@ $sql = "
u2.username as mc_username, u2.user_rank as mc_user_rank,
h.post_html, IF(h.post_html IS NULL, pt.post_text, NULL) AS post_text
FROM " . BB_POSTS . " p
- LEFT JOIN " . BB_USERS . " u ON(u.user_id = p.poster_id)
+ LEFT JOIN bb_users u ON(u.user_id = p.poster_id)
LEFT JOIN " . BB_POSTS_TEXT . " pt ON(pt.post_id = p.post_id)
LEFT JOIN " . BB_POSTS_HTML . " h ON(h.post_id = p.post_id)
- LEFT JOIN " . BB_USERS . " u2 ON(u2.user_id = p.mc_user_id)
+ LEFT JOIN bb_users u2 ON(u2.user_id = p.mc_user_id)
LEFT JOIN " . BB_GROUPS . " g ON(g.group_id = p.poster_rg_id)
WHERE p.topic_id = $topic_id
$limit_posts_time
@@ -336,7 +338,7 @@ $sql = "
LIMIT $start, $posts_per_page
";
-if ($postrow = DB()->fetch_rowset($sql)) {
+if ($postrow = Di::getInstance()->db->fetch_rowset($sql)) {
if ($first_post) {
$postrow = array_merge($first_post, $postrow);
}
@@ -498,7 +500,7 @@ require(INC_DIR . 'torrent_show_dl_list.php');
// Update the topic view counter
//
$sql = "INSERT INTO " . BUF_TOPIC_VIEW . " (topic_id, topic_views) VALUES ($topic_id, 1) ON DUPLICATE KEY UPDATE topic_views = topic_views + 1";
-if (!DB()->sql_query($sql)) {
+if (!Di::getInstance()->db->sql_query($sql)) {
bb_die('Could not update topic views');
}