Gazelle/sections/bookmarks/add.php

112 lines
3.1 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
2013-05-27 08:00:58 +00:00
include(SERVER_ROOT.'/classes/feed.class.php'); // RSS feeds
include(SERVER_ROOT.'/classes/text.class.php'); // strip_bbcode
2012-02-08 08:00:20 +00:00
2011-03-28 14:21:28 +00:00
authorize();
2013-05-05 08:00:31 +00:00
if (!Bookmarks::can_bookmark($_GET['type'])) {
error(404);
}
2012-02-08 08:00:20 +00:00
$Feed = new FEED;
$Text = new TEXT;
$Type = $_GET['type'];
2013-03-29 08:00:08 +00:00
list($Table, $Col) = Bookmarks::bookmark_schema($Type);
2013-05-05 08:00:31 +00:00
if (!is_number($_GET['id'])) {
2011-03-28 14:21:28 +00:00
error(0);
}
2013-09-13 08:00:53 +00:00
$PageID = $_GET['id'];
2013-05-05 08:00:31 +00:00
$DB->query("
SELECT UserID
FROM $Table
2013-09-13 08:00:53 +00:00
WHERE UserID = '$LoggedUser[ID]'
AND $Col = $PageID");
2013-07-10 00:08:53 +00:00
if (!$DB->has_results()) {
2012-10-27 08:00:09 +00:00
if ($Type === 'torrent') {
2013-09-13 08:00:53 +00:00
$DB->query("
2013-07-10 00:08:53 +00:00
SELECT MAX(Sort)
FROM `bookmarks_torrents`
2013-09-13 08:00:53 +00:00
WHERE UserID = $LoggedUser[ID]");
2012-10-27 08:00:09 +00:00
list($Sort) = $DB->next_record();
2013-09-13 08:00:53 +00:00
if (!$Sort) {
$Sort = 0;
}
2012-10-27 08:00:09 +00:00
$Sort += 1;
2013-05-05 08:00:31 +00:00
$DB->query("
INSERT IGNORE INTO $Table (UserID, $Col, Time, Sort)
2013-09-13 08:00:53 +00:00
VALUES ('$LoggedUser[ID]', $PageID, '".sqltime()."', $Sort)");
2012-10-27 08:00:09 +00:00
} else {
2013-05-05 08:00:31 +00:00
$DB->query("
INSERT IGNORE INTO $Table (UserID, $Col, Time)
2013-09-13 08:00:53 +00:00
VALUES ('$LoggedUser[ID]', $PageID, '".sqltime()."')");
2012-10-27 08:00:09 +00:00
}
$Cache->delete_value('bookmarks_'.$Type.'_'.$LoggedUser['ID']);
if ($Type == 'torrent') {
2013-09-13 08:00:53 +00:00
$Cache->delete_value("bookmarks_group_ids_$UserID");
2012-10-27 08:00:09 +00:00
2013-05-05 08:00:31 +00:00
$DB->query("
SELECT Name, Year, WikiBody, TagList
FROM torrents_group
2013-09-13 08:00:53 +00:00
WHERE ID = $PageID");
2012-02-08 08:00:20 +00:00
list($GroupTitle, $Year, $Body, $TagList) = $DB->next_record();
2013-07-10 00:08:53 +00:00
$TagList = str_replace('_', '.', $TagList);
2012-10-27 08:00:09 +00:00
2013-05-05 08:00:31 +00:00
$DB->query("
SELECT ID, Format, Encoding, HasLog, HasCue, LogScore, Media, Scene, FreeTorrent, UserID
FROM torrents
2013-09-13 08:00:53 +00:00
WHERE GroupID = $PageID");
2012-02-08 08:00:20 +00:00
// RSS feed stuff
while ($Torrent = $DB->next_record()) {
$Title = $GroupTitle;
list($TorrentID, $Format, $Bitrate, $HasLog, $HasCue, $LogScore, $Media, $Scene, $Freeleech, $UploaderID) = $Torrent;
2013-05-05 08:00:31 +00:00
$Title .= " [$Year] - ";
2013-07-10 00:08:53 +00:00
$Title .= "$Format / $Bitrate";
2013-05-05 08:00:31 +00:00
if ($HasLog == "'1'") {
2013-07-10 00:08:53 +00:00
$Title .= ' / Log';
2013-05-05 08:00:31 +00:00
}
if ($HasLog) {
2013-07-10 00:08:53 +00:00
$Title .= " / $LogScore%";
2013-05-05 08:00:31 +00:00
}
if ($HasCue == "'1'") {
2013-07-10 00:08:53 +00:00
$Title .= ' / Cue';
2013-05-05 08:00:31 +00:00
}
2013-07-10 00:08:53 +00:00
$Title .= ' / '.trim($Media);
2013-05-05 08:00:31 +00:00
if ($Scene == '1') {
2013-07-10 00:08:53 +00:00
$Title .= ' / Scene';
2013-05-05 08:00:31 +00:00
}
if ($Freeleech == '1') {
2013-07-10 00:08:53 +00:00
$Title .= ' / Freeleech!';
2013-05-05 08:00:31 +00:00
}
if ($Freeleech == '2') {
2013-07-10 00:08:53 +00:00
$Title .= ' / Neutral leech!';
2013-05-05 08:00:31 +00:00
}
2012-10-27 08:00:09 +00:00
2012-10-11 08:00:15 +00:00
$UploaderInfo = Users::user_info($UploaderID);
2012-10-27 08:00:09 +00:00
$Item = $Feed->item($Title,
2012-02-08 08:00:20 +00:00
$Text->strip_bbcode($Body),
'torrents.php?action=download&amp;authkey=[[AUTHKEY]]&amp;torrent_pass=[[PASSKEY]]&amp;id='.$TorrentID,
$UploaderInfo['Username'],
2013-09-13 08:00:53 +00:00
"torrents.php?id=$PageID",
2012-02-08 08:00:20 +00:00
trim($TagList));
$Feed->populate('torrents_bookmarks_t_'.$LoggedUser['torrent_pass'], $Item);
}
} elseif ($Type == 'request') {
2013-07-10 00:08:53 +00:00
$DB->query("
SELECT UserID
FROM $Table
2013-09-13 08:00:53 +00:00
WHERE $Col = '".db_string($PageID)."'");
if ($DB->record_count() < 100) {
// Sphinx doesn't like huge MVA updates. Update sphinx_requests_delta
// and live with the <= 1 minute delay if we have more than 100 bookmarkers
$Bookmarkers = implode(',', $DB->collect('UserID'));
$SphQL = new SphinxqlQuery();
$SphQL->raw_query("UPDATE requests, requests_delta SET bookmarker = ($Bookmarkers) WHERE id = $PageID");
} else {
Requests::update_sphinx_requests($PageID);
}
}
2013-05-05 08:00:31 +00:00
}