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=magnet&toggle=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; } $response->magnets[] = (object) [ 'magnetId' => $magnet->magnetId, 'metaTitle' => $magnet->metaTitle ? htmlentities($magnet->metaTitle) : ($magnet->dn ? htmlentities($magnet->dn): false), 'metaDescription' => $magnet->metaDescription ? nl2br( htmlentities( $magnet->metaDescription ) ) : 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, ], 'seeders' => $db->getMagnetToAddressTrackerSeedersSumByMagnetId($magnet->magnetId), 'completed' => $db->getMagnetToAddressTrackerCompletedSumByMagnetId($magnet->magnetId), 'leechers' => $db->getMagnetToAddressTrackerLeechersSumByMagnetId($magnet->magnetId) ]; } } } if (isset($_GET['rss']) && $response->success) { ?>' . PHP_EOL ?> <?php echo WEBSITE_NAME ?> query ? sprintf('?query=%s', urlencode($request->query)) : false) ?> magnets as $magnet) { ?> access->read) { ?> <?php echo htmlspecialchars($magnet->metaTitle, ENT_QUOTES, 'UTF-8') ?> metaDescription), ENT_QUOTES, 'UTF-8') ?> magnetId) ?> 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 ?> seeders ?> completed ?> 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)) { ?>