diff --git a/callseed.php b/library/ajax/callseed.php similarity index 81% rename from callseed.php rename to library/ajax/callseed.php index 88b860d40..f822c4fb9 100644 --- a/callseed.php +++ b/library/ajax/callseed.php @@ -7,24 +7,31 @@ * @license https://github.com/torrentpier/torrentpier/blob/master/LICENSE MIT License */ -define('BB_SCRIPT', 'callseed'); +if (!defined('IN_AJAX')) { + die(basename(__FILE__)); +} -require __DIR__ . '/common.php'; +global $bb_cfg, $userdata, $lang; -// Init userdata -$user->session_start(array('req_login' => true)); +if (!$bb_cfg['callseed']) { + $this->ajax_die($lang['MODULE_OFF']); +} + +if (!$topic_id = (int)$this->request['topic_id']) { + $this->ajax_die($lang['INVALID_TOPIC_ID']); +} + +if (!$t_data = topic_info($topic_id)) { + $this->ajax_die($lang['INVALID_TOPIC_ID_DB']); +} -$topic_id = (int)request_var('t', 0); -$t_data = topic_info($topic_id); $forum_id = $t_data['forum_id']; -set_die_append_msg($forum_id, $topic_id); - if ($t_data['seeders'] > 2) { - bb_die(sprintf($lang['CALLSEED_HAVE_SEED'], $t_data['seeders'])); + $this->ajax_die(sprintf($lang['CALLSEED_HAVE_SEED'], $t_data['seeders'])); } elseif ($t_data['call_seed_time'] > (TIMENOW - 86400)) { $time_left = delta_time($t_data['call_seed_time'] + 86400, TIMENOW, 'days'); - bb_die(sprintf($lang['CALLSEED_MSG_SPAM'], $time_left)); + $this->ajax_die(sprintf($lang['CALLSEED_MSG_SPAM'], $time_left)); } $ban_user_id = []; @@ -67,9 +74,6 @@ if ($user_list) { DB()->query("UPDATE " . BB_BT_TORRENTS . " SET call_seed_time = " . TIMENOW . " WHERE topic_id = $topic_id"); -meta_refresh(TOPIC_URL . $topic_id); -bb_die($lang['CALLSEED_MSG_OK']); - function topic_info($topic_id) { global $lang; @@ -90,3 +94,5 @@ function topic_info($topic_id) return $torrent; } + +$this->response['response'] = $lang['CALLSEED_MSG_OK']; diff --git a/src/Ajax.php b/src/Ajax.php index b6311bafc..dde736338 100644 --- a/src/Ajax.php +++ b/src/Ajax.php @@ -39,6 +39,7 @@ class Ajax 'change_torrent' => ['user'], 'change_tor_status' => ['user'], 'manage_group' => ['user'], + 'callseed' => ['user'], 'view_post' => ['guest'], 'view_torrent' => ['guest'], @@ -470,4 +471,14 @@ class Ajax { require AJAX_DIR . '/sitemap.php'; } + + /** + * Call seed actions + * + * @return void + */ + public function callseed() + { + require AJAX_DIR . '/callseed.php'; + } } diff --git a/styles/templates/default/viewtopic_torrent.tpl b/styles/templates/default/viewtopic_torrent.tpl index 36a9c6ecc..b32fd1909 100644 --- a/styles/templates/default/viewtopic_torrent.tpl +++ b/styles/templates/default/viewtopic_torrent.tpl @@ -9,6 +9,17 @@ $(document).ready(function(){ sortList: [[4,1]] }); }); + +// callseed +ajax.callseed = function (topic_id) { + ajax.exec({ + action: 'callseed', + topic_id: topic_id, + }); +}; +ajax.callback.callseed = function (data) { + alert(data.response); +};