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'); } // 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 $total = $sphinx->searchMagnetsTotal($request->query); $results = $sphinx->searchMagnets( $request->query, $request->page * WEBSITE_PAGINATION_LIMIT - WEBSITE_PAGINATION_LIMIT, WEBSITE_PAGINATION_LIMIT, $total ); foreach ($results as $result) { if ($magnet = $db->getMagnet($result->magnetid)) { $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( 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' => Time::ago($magnet->timeAdded), 'timeUpdated' => Time::ago($magnet->timeUpdated), 'keywords' => $keywords, 'comment' => (object) [ 'total' => $db->getMagnetCommentsTotal($magnet->magnetId), 'status' => $db->findMagnetCommentsTotalByUserId($magnet->magnetId, $userId), ], 'download' => (object) [ 'total' => $db->getMagnetDownloadsTotal($magnet->magnetId), 'status' => $db->findMagnetDownloadsTotalByUserId($magnet->magnetId, $userId), ], 'star' => (object) [ 'total' => $db->getMagnetStarsTotal($magnet->magnetId), 'status' => $db->findMagnetStarsTotalByUserId($magnet->magnetId, $userId), ], 'access' => (object) [ 'read' => ($_SERVER['REMOTE_ADDR'] == $db->getUser($magnet->userId)->address || in_array($_SERVER['REMOTE_ADDR'], MODERATOR_IP_LIST) || ($magnet->public && $magnet->approved)), 'edit' => ($_SERVER['REMOTE_ADDR'] == $db->getUser($magnet->userId)->address || in_array($_SERVER['REMOTE_ADDR'], MODERATOR_IP_LIST)), ], ]; } } } 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 ?>

access->edit) { ?>
metaDescription) { ?>
metaDescription ?>
keywords) { ?>
keywords as $keyword) { ?> #
public) { ?> approved) { ?> timeUpdated ? sprintf('Updated %s', $magnet->timeUpdated) : sprintf('Added %s', $magnet->timeAdded) ?> star->status) { ?> star->total ?> download->status) { ?> download->total ?>

message ?>