false, 'page' => 1, ]; // Prepare request $request->query = isset($_GET['query']) ? urldecode((string) $_GET['query']) : ''; $request->page = isset($_GET['page']) && $_GET['page'] > 0 ? (int) $_GET['page'] : 1; // Define response $response = (object) [ 'success' => true, 'message' => false, 'magnets' => [], ]; // Yggdrasil connections only if (!preg_match(YGGDRASIL_URL_REGEX, $_SERVER['REMOTE_ADDR'])) { $response->success = false; $response->message = _('Yggdrasil connection required to enable resource features'); } // Init session else if (!$userId = $db->initUserId($_SERVER['REMOTE_ADDR'], USER_DEFAULT_APPROVED, time())) { $response->success = false; $response->message = _('Could not init user session'); } // Get user else if (!$user = $db->getUser($userId)) { $response->success = false; $response->message = _('Could not init user info'); } // Request valid else { // Query is magnet link if ($magnet = Yggverse\Parser\Magnet::is($request->query)) { header( sprintf('Location: %s/action.php?target=new&magnet=%s', WEBSITE_URL, base64_encode($request->query)) ); } // Get index $response->total = $sphinx->searchMagnetsTotal($request->query); $results = $sphinx->searchMagnets( $request->query, $request->page * WEBSITE_PAGINATION_LIMIT - WEBSITE_PAGINATION_LIMIT, WEBSITE_PAGINATION_LIMIT, $response->total ); foreach ($results as $result) { if ($magnet = $db->getMagnet($result->magnetid)) { // Get access info $accessRead = ($user->address == $db->getUser($magnet->userId)->address || in_array($user->address, MODERATOR_IP_LIST) || ($magnet->public && $magnet->approved)); $accessEdit = ($user->address == $db->getUser($magnet->userId)->address || in_array($user->address, MODERATOR_IP_LIST)); // Update magnet viewed if ($accessRead) { $db->addMagnetView($magnet->magnetId, $userId, time()); } // Keywords $keywords = []; foreach ($db->findKeywordTopicByMagnetId($magnet->magnetId) as $keyword) { $keywords[] = $db->getKeywordTopic($keyword->keywordTopicId)->value; } // Scrapes $localScrape = (object) [ 'seeders' => 0, 'completed' => 0, 'leechers' => 0, ]; $totalScrape = (object) [ 'seeders' => 0, 'completed' => 0, 'leechers' => 0, ]; $trackers = []; foreach (TRACKER_LINKS as $tracker) { $trackers[] = $tracker->announce; } foreach ($db->findAddressTrackerByMagnetId($magnet->magnetId) as $magnetToAddressTracker) { if ($addressTracker = $db->getAddressTracker($magnetToAddressTracker->addressTrackerId)) { $scheme = $db->getScheme($addressTracker->schemeId); $host = $db->getHost($addressTracker->hostId); $port = $db->getPort($addressTracker->portId); $uri = $db->getUri($addressTracker->uriId); $url = $port->value ? sprintf('%s://%s:%s%s', $scheme->value, $host->value, $port->value, $uri->value) : sprintf('%s://%s%s', $scheme->value, $host->value, $uri->value); if (in_array($url, $trackers)) { $localScrape->seeders += (int) $magnetToAddressTracker->seeders; $localScrape->completed += (int) $magnetToAddressTracker->completed; $localScrape->leechers += (int) $magnetToAddressTracker->leechers; } $totalScrape->seeders += (int) $magnetToAddressTracker->seeders; $totalScrape->completed += (int) $magnetToAddressTracker->completed; $totalScrape->leechers += (int) $magnetToAddressTracker->leechers; } } $response->magnets[] = (object) [ 'magnetId' => $magnet->magnetId, 'metaTitle' => $magnet->metaTitle ? htmlentities($magnet->metaTitle) : ($magnet->dn ? htmlentities($magnet->dn): false), 'metaDescription' => $magnet->metaDescription ? nl2br( htmlentities( substr($magnet->metaDescription, 0, WEBSITE_MAGNET_SHORT_META_DESCRIPTION_LENGTH) ) ) : false, 'approved' => (bool) $magnet->approved, 'public' => (bool) $magnet->public, 'sensitive' => (bool) $magnet->sensitive, 'comments' => (bool) $magnet->comments, 'timeAdded' => $magnet->timeAdded ? Time::ago((int) $magnet->timeAdded) : false, 'timeUpdated' => $magnet->timeUpdated ? Time::ago((int) $magnet->timeUpdated) : false, 'keywords' => $keywords, 'comment' => (object) [ 'total' => $db->getMagnetCommentsTotal($magnet->magnetId), 'status' => $db->findMagnetCommentsTotalByUserId($magnet->magnetId, $userId), ], 'download' => (object) [ 'total' => $db->getMagnetDownloadsTotalByUserId($magnet->magnetId), 'status' => $db->findMagnetDownloadsTotalByUserId($magnet->magnetId, $userId), ], 'star' => (object) [ 'total' => $db->getMagnetStarsTotal($magnet->magnetId), 'status' => $db->findMagnetStarsTotalByUserId($magnet->magnetId, $userId), ], 'access' => (object) [ 'read' => $accessRead, 'edit' => $accessEdit, ], 'scrape' => (object) [ 'local' => $localScrape, 'total' => $totalScrape ] ]; } } } if (isset($_GET['rss']) && $response->success) { ?>' . PHP_EOL ?> <?php echo WEBSITE_NAME ?> /index.phpquery ? sprintf('?query=%s', urlencode($request->query)) : false ?> magnets as $magnet) { ?> access->read) { ?> <?php echo htmlspecialchars($magnet->metaTitle, ENT_QUOTES, 'UTF-8') ?> #magnet-magnetId ?> metaDescription), ENT_QUOTES, 'UTF-8') ?> #magnet-magnetId ?> <?php echo sprintf(_('%s - BitTorrent Catalog for Yggdrasil'), WEBSITE_NAME) ?>
success) { ?> magnets) { ?> magnets as $magnet) { ?> access->read) { ?>

metaTitle ?>

public) { ?> approved) { ?> access->edit) { ?>
metaDescription) { ?>
metaDescription ?>
keywords) { ?>
keywords as $keyword) { ?> #
timeUpdated ? _('Updated') : _('Added') ?> timeUpdated ? $magnet->timeUpdated : $magnet->timeAdded ?> scrape->local->seeders ?> / scrape->total->seeders ?> scrape->local->completed ?> / scrape->total->completed ?> scrape->local->leechers ?> / scrape->total->leechers ?> star->status) { ?> star->total ?> comment->status) { ?> comment->total ?> download->status) { ?> download->total ?>

message ?>
total > WEBSITE_PAGINATION_LIMIT) { ?>
page, ceil($response->total / WEBSITE_PAGINATION_LIMIT)) ?> page > 1) { ?> page < ceil($response->total / WEBSITE_PAGINATION_LIMIT)) { ?>