123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- declare(strict_types = 1);
-
- authorize();
-
- if (!Bookmarks::can_bookmark($_GET['type'])) {
- error(404);
- }
-
- include SERVER_ROOT.'/classes/feed.class.php'; // RSS feeds
- $Feed = new Feed;
-
- $Type = $_GET['type'];
- list($Table, $Col) = Bookmarks::bookmark_schema($Type);
-
- if (!is_number($_GET['id'])) {
- error(0);
- }
-
- $PageID = $_GET['id'];
- $DB->query("
- SELECT
- `UserID`
- FROM
- $Table
- WHERE
- `UserID` = '$LoggedUser[ID]' AND $Col = $PageID
- ");
-
- if (!$DB->has_results()) {
- if ($Type === 'torrent') {
- $DB->query("
- SELECT
- MAX(`Sort`)
- FROM
- `bookmarks_torrents`
- WHERE
- `UserID` = $LoggedUser[ID]
- ");
-
- list($Sort) = $DB->next_record();
- if (!$Sort) {
- $Sort = 0;
- }
-
- $Sort += 1;
- $DB->query("
- INSERT IGNORE
- INTO $Table(`UserID`, $Col, `Time`, `Sort`)
- VALUES(
- '$LoggedUser[ID]',
- $PageID,
- NOW(),
- $Sort
- )
- ");
- } else {
- $DB->query("
- INSERT IGNORE
- INTO $Table(`UserID`, $Col, `Time`)
- VALUES(
- '$LoggedUser[ID]',
- $PageID,
- NOW()
- )
- ");
- }
-
- $Cache->delete_value('bookmarks_'.$Type.'_'.$LoggedUser['ID']);
- if ($Type === 'torrent') {
- $Cache->delete_value("bookmarks_group_ids_$UserID");
- $DB->query("
- SELECT
- `title`,
- `year`,
- `description`,
- `tag_list`
- FROM
- `torrents_group`
- WHERE
- `id` = $PageID
- ");
-
- list($GroupTitle, $Year, $Body, $TagList) = $DB->next_record();
- $TagList = str_replace('_', '.', $TagList);
-
- $DB->prepare_query("
- SELECT
- `ID`,
- `Media`,
- `FreeTorrent`,
- `UserID`,
- `Anonymous`
- FROM
- `torrents`
- WHERE
- `GroupID` = '$PageID'
- ");
- $DB->exec_prepared_query();
-
- // RSS feed stuff
- while ($Torrent = $DB->next_record()) {
- $Title = $GroupTitle;
- list($TorrentID, $Media, $Freeleech, $UploaderID, $Anonymous) = $Torrent;
- $UploaderInfo = Users::user_info($UploaderID);
-
- $Item = $Feed->item(
- $Title,
- Text::strip_bbcode($Body),
- 'torrents.php?action=download&authkey=[[AUTHKEY]]&torrent_pass=[[PASSKEY]]&id='.$TorrentID,
- ($Anonymous === 0 ? $UploaderInfo['Username'] : 'Anonymous'),
- "torrents.php?id=$PageID",
- trim($TagList)
- );
- $Feed->populate('torrents_bookmarks_t_'.$LoggedUser['torrent_pass'], $Item);
- }
- } elseif ($Type === 'request') {
- $DB->query("
- SELECT
- `UserID`
- FROM
- $Table
- 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);
- }
- }
- }
|