From ef7363930f4331760dec7c814bb78a93403d80fe Mon Sep 17 00:00:00 2001 From: Exile Date: Fri, 18 Mar 2016 03:33:58 +0300 Subject: [PATCH] Rework of feed.php and some other files --- admin/admin_bt_forum_cfg.php | 2 +- admin/admin_bt_tracker_cfg.php | 2 +- callseed.php | 9 ++- composer.json | 4 +- dl.php | 1 + dl_list.php | 21 ++--- feed.php | 118 ++++++++++++++-------------- library/includes/functions_atom.php | 6 +- messages/en.php | 6 ++ styleguide.php | 2 +- terms.php | 1 + 11 files changed, 94 insertions(+), 78 deletions(-) diff --git a/admin/admin_bt_forum_cfg.php b/admin/admin_bt_forum_cfg.php index 64b996204..bf113b660 100644 --- a/admin/admin_bt_forum_cfg.php +++ b/admin/admin_bt_forum_cfg.php @@ -19,7 +19,7 @@ $cfg = array(); // All config names with default values $default_cfg_str = array( - 'bt_announce_url' => 'https://demo.torrentpier.me/bt/', + 'bt_announce_url' => 'http://demo.torrentpier.me/bt/', ); $default_cfg_bool = array( diff --git a/admin/admin_bt_tracker_cfg.php b/admin/admin_bt_tracker_cfg.php index 4ae1828bd..9406a5b89 100644 --- a/admin/admin_bt_tracker_cfg.php +++ b/admin/admin_bt_tracker_cfg.php @@ -17,7 +17,7 @@ $confirmed = isset($_POST['confirm']); // All config names with default values $default_cfg_str = array( 'off_reason' => 'Tracker is disabled', - 'browser_redirect_url' => 'https://demo.torrentpier.me/', + 'browser_redirect_url' => 'http://demo.torrentpier.me/', ); $default_cfg_bool = array( diff --git a/callseed.php b/callseed.php index 4e79857cb..f94063431 100644 --- a/callseed.php +++ b/callseed.php @@ -2,12 +2,15 @@ define('BB_SCRIPT', 'callseed'); define('BB_ROOT', './'); -require(BB_ROOT . 'common.php'); +require_once __DIR__ . '/common.php'; + +/** @var \TorrentPier\Di $di */ +$di = \TorrentPier\Di::getInstance(); -// Init userdata $user->session_start(['req_login' => true]); -$topic_id = (int) request_var('t', 0); +$topic_id = $di->request->query->getInt('t'); + $t_data = topic_info($topic_id); $forum_id = $t_data['forum_id']; diff --git a/composer.json b/composer.json index 2f8ef80e6..1b65fb7f1 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,7 @@ "ext-curl": "*", "ext-mbstring": "*", "google/recaptcha": "^1.0", + "monolog/monolog": "^1.18", "pimple/pimple": "^3.0", "ripaclub/sphinxsearch": "^0.8.0", "rych/bencode": "^1.0", @@ -41,8 +42,7 @@ "zendframework/zend-loader": "^2.5", "zendframework/zend-mail": "^2.5", "zendframework/zend-session": "^2.5", - "zendframework/zend-version": "^2.5", - "monolog/monolog": "^1.18" + "zendframework/zend-version": "^2.5" }, "require-dev": { "phpunit/phpunit": "^4.8" diff --git a/dl.php b/dl.php index d17a86dca..766a32439 100644 --- a/dl.php +++ b/dl.php @@ -4,6 +4,7 @@ define('BB_SCRIPT', 'dl'); define('BB_ROOT', './'); require_once __DIR__ . '/common.php'; +/** @var \TorrentPier\Di $di */ $di = \TorrentPier\Di::getInstance(); /** @var \TorrentPier\Db\Adapter $db */ diff --git a/dl_list.php b/dl_list.php index 99523984f..5e4a70800 100644 --- a/dl_list.php +++ b/dl_list.php @@ -2,32 +2,35 @@ define('BB_SCRIPT', 'dl_list'); define('BB_ROOT', './'); -require(BB_ROOT .'common.php'); +require_once __DIR__ . '/common.php'; -$forum_id = isset($_REQUEST[POST_FORUM_URL]) ? (int) $_REQUEST[POST_FORUM_URL] : 0; -$topic_id = isset($_REQUEST[POST_TOPIC_URL]) ? (int) $_REQUEST[POST_TOPIC_URL] : 0; -$mode = isset($_REQUEST['mode']) ? (string) $_REQUEST['mode'] : ''; -$confirmed = isset($_POST['confirm']); +/** @var \TorrentPier\Di $di */ +$di = \TorrentPier\Di::getInstance(); + +$forum_id = $di->request->request->getInt(POST_FORUM_URL, 0); +$topic_id = $di->request->request->getInt(POST_TOPIC_URL, 0); +$mode = $di->request->request->get('mode'); +$confirmed = $di->request->request->has('confirm'); // Get new DL-status if ($mode == 'set_dl_status' || $mode == 'set_topics_dl_status') { - if (isset($_POST['dl_set_will'])) + if ($di->request->request->has('dl_set_will')) { $new_dl_status = DL_STATUS_WILL; $dl_key = 'dlw'; } - elseif (isset($_POST['dl_set_down'])) + elseif ($di->request->request->has('dl_set_down')) { $new_dl_status = DL_STATUS_DOWN; $dl_key = 'dld'; } - elseif (isset($_POST['dl_set_complete'])) + elseif ($di->request->request->has('dl_set_complete')) { $new_dl_status = DL_STATUS_COMPLETE; $dl_key = 'dlc'; } - elseif (isset($_POST['dl_set_cancel'])) + elseif ($di->request->request->has('dl_set_cancel')) { $new_dl_status = DL_STATUS_CANCEL; $dl_key = 'dla'; diff --git a/feed.php b/feed.php index 7a6e9eef6..43af8da5f 100644 --- a/feed.php +++ b/feed.php @@ -2,66 +2,68 @@ define('BB_SCRIPT', 'feed'); define('BB_ROOT', './'); -require(BB_ROOT .'common.php'); +require_once __DIR__ . '/common.php'; +require_once(INC_DIR . 'functions_atom.php'); -$user->session_start(array('req_login' => true)); +/** @var \TorrentPier\Di $di */ +$di = \TorrentPier\Di::getInstance(); -$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : ''; -$type = isset($_POST['type']) ? $_POST['type'] : ''; -$id = isset($_POST['id']) ? $_POST['id'] : 0; -$timecheck = TIMENOW - 600; +/** @var \TorrentPier\Db\Adapter $db */ +$db = $di->db; -if (!$mode) bb_simple_die($lang['ATOM_NO_MODE']); +$user->session_start(['req_login' => true]); -if ($mode == 'get_feed_url' && ($type == 'f' || $type == 'u') && $id >= 0) -{ - if ($type == 'f') - { - // Check if the user has actually sent a forum ID - $sql = "SELECT allow_reg_tracker, forum_name FROM ". BB_FORUMS ." WHERE forum_id = $id LIMIT 1"; - if (!$forum_data = DB()->fetch_row($sql)) - { - if ($id == 0) - { - $forum_data = array(); - } - else bb_simple_die($lang['ATOM_ERROR'].' #1'); - } - if (file_exists($bb_cfg['atom']['path'] .'/f/'. $id .'.atom') && filemtime($bb_cfg['atom']['path'] .'/f/'. $id .'.atom') > $timecheck) - { - redirect($bb_cfg['atom']['url'] .'/f/'. $id .'.atom'); - } - else - { - require_once(INC_DIR .'functions_atom.php'); - if (update_forum_feed($id, $forum_data)) redirect($bb_cfg['atom']['url'] .'/f/'. $id .'.atom'); - else bb_simple_die($lang['ATOM_NO_FORUM']); - } - } - if ($type == 'u') - { - // Check if the user has actually sent a user ID - if ($id < 1) - { - bb_simple_die($lang['ATOM_ERROR'].' #2'); - } - if (!$username = get_username($id)) - { - bb_simple_die($lang['ATOM_ERROR'].' #3'); - } - if (file_exists($bb_cfg['atom']['path'] .'/u/'. floor($id/5000) .'/'. ($id % 100) .'/'. $id .'.atom') && filemtime($bb_cfg['atom']['path'] .'/u/'. floor($id/5000) .'/'. ($id % 100) .'/'. $id .'.atom') > $timecheck) - { - redirect($bb_cfg['atom']['url'] .'/u/'. floor($id/5000) .'/'. ($id % 100) .'/'. $id .'.atom'); - } - else - { - require_once(INC_DIR .'functions_atom.php'); - if (update_user_feed($id, $username)) redirect($bb_cfg['atom']['url'] .'/u/'. floor($id/5000) .'/'. ($id % 100) .'/'. $id .'.atom'); - else bb_simple_die($lang['ATOM_NO_USER']); - } - } +$mode = $di->request->request->get('mode'); +$type = $di->request->request->get('type'); +$id = $di->request->query->getInt('id'); + +if (!$mode) bb_simple_die($di->translator->trans('Do not specify a mode for the feed')); + +if ($mode == 'get_feed_url' && ($type == 'f' || $type == 'u') && $id >= 0) { + if ($type == 'f') { + /** @var \TorrentPier\Db\PrepareStatement $result */ + $forum_data = $db->select(BB_FORUMS, function (\Zend\Db\Sql\Select $select) use ($id) { + $select->columns(['atom_tr_allowed' => 'allow_reg_tracker', 'atom_forum_name' => 'forum_name']); + $select->where(function (\Zend\Db\Sql\Where $where) use ($id) { + $where->equalTo('forum_id', $id); + }); + })->one(); + + if (!$forum_data) { + if ($id == 0) { + $forum_data = []; + } else { + \TorrentPier\Log::error('No forum data to atom feed'); + } + } + if (file_exists($di->config->get('atom.path') . '/f/' . $id . '.atom') && filemtime($di->config->get('atom.path') . '/f/' . $id . '.atom') > TIMENOW - 600) { + redirect($di->config->get('atom.url') . '/f/' . $id . '.atom'); + } else { + if (update_forum_feed($id, $forum_data)) { + redirect($di->config->get('atom.url') . '/f/' . $id . '.atom'); + } else { + bb_simple_die($di->translator->trans('This forum does not have a feed')); + } + } + } + + if ($type == 'u') { + if ($id < 1) { + \TorrentPier\Log::error('Incorrect atom feed user_id'); + } + if (!$username = get_username($id)) { + \TorrentPier\Log::error('Can not receive the username for atom feed'); + } + if (file_exists($di->config->get('atom.path') . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom') && filemtime($di->config->get('atom.path') . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom') > TIMENOW - 600) { + redirect($di->config->get('atom.url') . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom'); + } else { + if (update_user_feed($id, $username)) { + redirect($di->config->get('atom.url') . '/u/' . floor($id / 5000) . '/' . ($id % 100) . '/' . $id . '.atom'); + } else { + bb_simple_die($di->translator->trans('This user does not have a feed')); + } + } + } +} else { + \TorrentPier\Log::error('Unknown atom feed mode'); } -else -{ - bb_simple_die($lang['ATOM_ERROR'].' #4'); -} \ No newline at end of file diff --git a/library/includes/functions_atom.php b/library/includes/functions_atom.php index b3053617d..503e43fd3 100644 --- a/library/includes/functions_atom.php +++ b/library/includes/functions_atom.php @@ -10,8 +10,8 @@ function update_forum_feed ($forum_id, $forum_data) global $bb_cfg; $file_path = $bb_cfg['atom']['path'] .'/f/'. $forum_id .'.atom'; $select_tor_sql = $join_tor_sql = ''; - if ($forum_id == 0) $forum_data['forum_name'] = 'Общая по всем разделам'; - if ($forum_id > 0 && $forum_data['allow_reg_tracker']) + if ($forum_id == 0) $forum_data['atom_forum_name'] = 'Общая по всем разделам'; + if ($forum_id > 0 && $forum_data['atom_tr_allowed']) { $select_tor_sql = ', tor.size AS tor_size, tor.tor_status'; $join_tor_sql = "LEFT JOIN ". BB_BT_TORRENTS ." tor ON(t.topic_id = tor.topic_id)"; @@ -72,7 +72,7 @@ function update_forum_feed ($forum_id, $forum_data) unlink($file_path); return false; } - if (create_atom($file_path, 'f', $forum_id, htmlCHR($forum_data['forum_name']), $topics)) return true; + if (create_atom($file_path, 'f', $forum_id, htmlCHR($forum_data['atom_forum_name']), $topics)) return true; else return false; } diff --git a/messages/en.php b/messages/en.php index a4a23af7e..3878a448c 100644 --- a/messages/en.php +++ b/messages/en.php @@ -14,6 +14,12 @@ return [ 'File not found: %location%' => 'File not found: %location%', 'Invalid request: not specified %data%' => 'Invalid request: not specified %data%', + // Feed + 'Feed' => 'Feed', + 'Do not specify a mode for the feed' => 'Do not specify a mode for the feed', + 'This forum does not have a feed' => 'This forum does not have a feed', + 'This user does not have a feed' => 'This user does not have a feed', + // Style guide (styleguide.php) 'Hello, %name%' => 'Hello, %name%', 'Style guide' => 'Style guide', diff --git a/styleguide.php b/styleguide.php index a81fea6b0..18eb86b40 100644 --- a/styleguide.php +++ b/styleguide.php @@ -4,6 +4,7 @@ define('BB_SCRIPT', 'styleguide'); define('BB_ROOT', './'); require_once __DIR__ . '/common.php'; +/** @var \TorrentPier\Di $di */ $di = \TorrentPier\Di::getInstance(); /** @var \TorrentPier\Db\Adapter $db */ @@ -13,7 +14,6 @@ $db = $di->db; //$request = $di->request; //$request->request->has() - //$id = $db->insert(BB_USERS, [ // 'username' => 'user_' . rand(1, 50) //]); diff --git a/terms.php b/terms.php index d38b3697e..65d02aa4f 100644 --- a/terms.php +++ b/terms.php @@ -5,6 +5,7 @@ define('BB_ROOT', './'); require_once __DIR__ . '/common.php'; require_once(INC_DIR . 'bbcode.php'); +/** @var \TorrentPier\Di $di */ $di = \TorrentPier\Di::getInstance(); $user->session_start();