Rework of feed.php and some other files

This commit is contained in:
Exile 2016-03-18 03:33:58 +03:00 committed by Yuriy Pikhtarev
commit ef7363930f
No known key found for this signature in database
GPG key ID: 3A9B5A757B48ECC6
11 changed files with 94 additions and 78 deletions

View file

@ -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(

View file

@ -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(

View file

@ -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'];

View file

@ -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"

1
dl.php
View file

@ -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 */

View file

@ -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';

118
feed.php
View file

@ -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');
}

View file

@ -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;
}

View file

@ -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',

View file

@ -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)
//]);

View file

@ -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();