diff --git a/src/config/app.php.example b/src/config/app.php.example index 451aca6..c38aa62 100644 --- a/src/config/app.php.example +++ b/src/config/app.php.example @@ -103,8 +103,6 @@ define('MAGNET_STOP_WORDS_SIMILAR', ] ); -define('MAGNET_DOWNLOAD_YGGDRASIL_URL_ONLY', true); - // Comment define('COMMENT_DEFAULT_APPROVED', false); define('COMMENT_DEFAULT_PUBLIC', false); @@ -116,17 +114,17 @@ define('TRACKER_LINKS', (object) [ 'Tracker 1' => (object) [ + 'url' => 'http://[201:23b4:991a:634d:8359:4521:5576:15b7]/yggtracker', 'announce' => 'http://[201:23b4:991a:634d:8359:4521:5576:15b7]/announce', 'stats' => 'http://[201:23b4:991a:634d:8359:4521:5576:15b7]/stats', 'scrape' => 'http://[201:23b4:991a:634d:8359:4521:5576:15b7]/scrape', - 'rules' => 'yggdrasil only', ], 'Tracker 2' => (object) [ + 'url' => false, 'announce' => 'http://[200:1e2f:e608:eb3a:2bf:1e62:87ba:e2f7]/announce', 'stats' => 'http://[200:1e2f:e608:eb3a:2bf:1e62:87ba:e2f7]/stats', 'scrape' => 'http://[200:1e2f:e608:eb3a:2bf:1e62:87ba:e2f7]/scrape', - 'rules' => 'yggdrasil only', ], // ... ] diff --git a/src/library/database.php b/src/library/database.php index 382f7e8..8196850 100644 --- a/src/library/database.php +++ b/src/library/database.php @@ -827,8 +827,40 @@ class Database { return $this->addMagnetToAddressTracker($magnetId, $addressTrackerId); } - /* - public function getMagnetToAddressTrackerSeedersSum() { + public function getMagnetToAddressTrackerSeedersSumByMagnetId(int $magnetId) : int { + + $this->_debug->query->select->total++; + + $query = $this->_db->prepare('SELECT SUM(`seeders`) AS `result` FROM `magnetToAddressTracker` WHERE `magnetId` = ?'); + + $query->execute([$magnetId]); + + return (int) $query->fetch()->result; + } + + public function getMagnetToAddressTrackerCompletedSumByMagnetId(int $magnetId) : int { + + $this->_debug->query->select->total++; + + $query = $this->_db->prepare('SELECT SUM(`completed`) AS `result` FROM `magnetToAddressTracker` WHERE `magnetId` = ?'); + + $query->execute([$magnetId]); + + return (int) $query->fetch()->result; + } + + public function getMagnetToAddressTrackerLeechersSumByMagnetId(int $magnetId) : int { + + $this->_debug->query->select->total++; + + $query = $this->_db->prepare('SELECT SUM(`leechers`) AS `result` FROM `magnetToAddressTracker` WHERE `magnetId` = ?'); + + $query->execute([$magnetId]); + + return (int) $query->fetch()->result; + } + + public function getMagnetToAddressTrackerSeedersSum() : int { $this->_debug->query->select->total++; @@ -836,10 +868,10 @@ class Database { $query->execute(); - return $query->fetch()->result; + return (int) $query->fetch()->result; } - public function getMagnetToAddressTrackerCompletedSum() { + public function getMagnetToAddressTrackerCompletedSum() : int { $this->_debug->query->select->total++; @@ -847,10 +879,10 @@ class Database { $query->execute(); - return $query->fetch()->result; + return (int) $query->fetch()->result; } - public function getMagnetToAddressTrackerLeechersSum() { + public function getMagnetToAddressTrackerLeechersSum() : int { $this->_debug->query->select->total++; @@ -858,9 +890,8 @@ class Database { $query->execute(); - return $query->fetch()->result; + return (int) $query->fetch()->result; } - */ // Magnet to AcceptableSource public function addMagnetToAcceptableSource(int $magnetId, int $acceptableSourceId) : int { diff --git a/src/public/action.php b/src/public/action.php index 7859a7d..adb2d24 100644 --- a/src/public/action.php +++ b/src/public/action.php @@ -463,8 +463,8 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) $host->value, $uri->value))); - // Yggdrasil url only settings enabled - if (MAGNET_DOWNLOAD_YGGDRASIL_URL_ONLY && !preg_match(YGGDRASIL_URL_REGEX, $url)) + // Yggdrasil url only + if (!preg_match(YGGDRASIL_URL_REGEX, $url)) { continue; } @@ -494,8 +494,8 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) $host->value, $uri->value))); - // Yggdrasil url only settings enabled - if (MAGNET_DOWNLOAD_YGGDRASIL_URL_ONLY && !preg_match(YGGDRASIL_URL_REGEX, $url)) + // Yggdrasil url only + if (!preg_match(YGGDRASIL_URL_REGEX, $url)) { continue; } @@ -520,8 +520,8 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) $host->value, $uri->value))); - // Yggdrasil url only settings enabled - if (MAGNET_DOWNLOAD_YGGDRASIL_URL_ONLY && !preg_match(YGGDRASIL_URL_REGEX, $url)) + // Yggdrasil url only + if (!preg_match(YGGDRASIL_URL_REGEX, $url)) { continue; } @@ -612,15 +612,18 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) { if ($url = Yggverse\Parser\Url::parse($tr)) { - $db->initMagnetToAddressTrackerId( - $magnetId, - $db->initAddressTrackerId( - $db->initSchemeId($url->host->scheme), - $db->initHostId($url->host->name), - $db->initPortId($url->host->port), - $db->initUriId($url->page->uri) - ) - ); + if (preg_match(YGGDRASIL_URL_REGEX, str_replace(['[',']'], false, $url->host->name))) + { + $db->initMagnetToAddressTrackerId( + $magnetId, + $db->initAddressTrackerId( + $db->initSchemeId($url->host->scheme), + $db->initHostId($url->host->name), + $db->initPortId($url->host->port), + $db->initUriId($url->page->uri) + ) + ); + } } } break; @@ -635,15 +638,18 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) { if ($url = Yggverse\Parser\Url::parse($as)) { - $db->initMagnetToAcceptableSourceId( - $magnetId, - $db->initAcceptableSourceId( - $db->initSchemeId($url->host->scheme), - $db->initHostId($url->host->name), - $db->initPortId($url->host->port), - $db->initUriId($url->page->uri) - ) - ); + if (preg_match(YGGDRASIL_URL_REGEX, str_replace(['[',']'], false, $url->host->name))) + { + $db->initMagnetToAcceptableSourceId( + $magnetId, + $db->initAcceptableSourceId( + $db->initSchemeId($url->host->scheme), + $db->initHostId($url->host->name), + $db->initPortId($url->host->port), + $db->initUriId($url->page->uri) + ) + ); + } } } break; @@ -652,15 +658,18 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) { if ($url = Yggverse\Parser\Url::parse($xs)) { - $db->initMagnetToExactSourceId( - $magnetId, - $db->initExactSourceId( - $db->initSchemeId($url->host->scheme), - $db->initHostId($url->host->name), - $db->initPortId($url->host->port), - $db->initUriId($url->page->uri) - ) - ); + if (preg_match(YGGDRASIL_URL_REGEX, str_replace(['[',']'], false, $url->host->name))) + { + $db->initMagnetToExactSourceId( + $magnetId, + $db->initExactSourceId( + $db->initSchemeId($url->host->scheme), + $db->initHostId($url->host->name), + $db->initPortId($url->host->port), + $db->initUriId($url->page->uri) + ) + ); + } } } break; diff --git a/src/public/edit.php b/src/public/edit.php index 4d2e0e3..88c1df4 100644 --- a/src/public/edit.php +++ b/src/public/edit.php @@ -287,18 +287,18 @@ else { { if ($url = Yggverse\Parser\Url::parse($tr)) { - $db->initMagnetToAddressTrackerId( - $magnet->magnetId, - $db->initAddressTrackerId( - $db->initSchemeId($url->host->scheme), - $db->initHostId($url->host->name), - $db->initPortId($url->host->port), - $db->initUriId($url->page->uri) - ) - ); - if (preg_match(YGGDRASIL_URL_REGEX, str_replace(['[',']'], false, $url->host->name))) { + $db->initMagnetToAddressTrackerId( + $magnet->magnetId, + $db->initAddressTrackerId( + $db->initSchemeId($url->host->scheme), + $db->initHostId($url->host->name), + $db->initPortId($url->host->port), + $db->initUriId($url->page->uri) + ) + ); + $response->form->tr->valid->success = true; $response->form->tr->valid->message = false; } @@ -323,18 +323,18 @@ else { { if ($url = Yggverse\Parser\Url::parse($as)) { - $db->initMagnetToAcceptableSourceId( - $magnet->magnetId, - $db->initAcceptableSourceId( - $db->initSchemeId($url->host->scheme), - $db->initHostId($url->host->name), - $db->initPortId($url->host->port), - $db->initUriId($url->page->uri) - ) - ); - if (preg_match(YGGDRASIL_URL_REGEX, str_replace(['[',']'], false, $url->host->name))) { + $db->initMagnetToAcceptableSourceId( + $magnet->magnetId, + $db->initAcceptableSourceId( + $db->initSchemeId($url->host->scheme), + $db->initHostId($url->host->name), + $db->initPortId($url->host->port), + $db->initUriId($url->page->uri) + ) + ); + $response->form->as->valid->success = true; $response->form->as->valid->message = false; } @@ -359,18 +359,18 @@ else { { if ($url = Yggverse\Parser\Url::parse($xs)) { - $db->initMagnetToExactSourceId( - $magnet->magnetId, - $db->initExactSourceId( - $db->initSchemeId($url->host->scheme), - $db->initHostId($url->host->name), - $db->initPortId($url->host->port), - $db->initUriId($url->page->uri) - ) - ); - if (preg_match(YGGDRASIL_URL_REGEX, str_replace(['[',']'], false, $url->host->name))) { + $db->initMagnetToExactSourceId( + $magnet->magnetId, + $db->initExactSourceId( + $db->initSchemeId($url->host->scheme), + $db->initHostId($url->host->name), + $db->initPortId($url->host->port), + $db->initUriId($url->page->uri) + ) + ); + $response->form->xs->valid->success = true; $response->form->xs->valid->message = false; } diff --git a/src/public/index.php b/src/public/index.php index 8ce69df..8704bb9 100644 --- a/src/public/index.php +++ b/src/public/index.php @@ -113,57 +113,6 @@ else $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, @@ -200,11 +149,9 @@ else 'read' => $accessRead, 'edit' => $accessEdit, ], - 'scrape' => (object) - [ - 'local' => $localScrape, - 'total' => $totalScrape - ] + 'seeders' => $db->getMagnetToAddressTrackerSeedersSumByMagnetId($magnet->magnetId), + 'completed' => $db->getMagnetToAddressTrackerCompletedSumByMagnetId($magnet->magnetId), + 'leechers' => $db->getMagnetToAddressTrackerLeechersSumByMagnetId($magnet->magnetId) ]; } } @@ -335,24 +282,24 @@ echo '' . PHP_EOL ?> timeUpdated ? $magnet->timeUpdated : $magnet->timeAdded ?> - + - scrape->local->seeders ?> / scrape->total->seeders ?> + seeders ?> - + - scrape->local->completed ?> / scrape->total->completed ?> + completed ?> - + - scrape->local->leechers ?> / scrape->total->leechers ?> + leechers ?> diff --git a/src/public/magnet.php b/src/public/magnet.php index ff81ea4..fd5f75c 100644 --- a/src/public/magnet.php +++ b/src/public/magnet.php @@ -89,57 +89,6 @@ else $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->user = $user; $response->magnet = (object) [ @@ -182,11 +131,9 @@ else 'read' => $accessRead, 'edit' => $accessEdit, ], - 'scrape' => (object) - [ - 'local' => $localScrape, - 'total' => $totalScrape - ] + 'seeders' => $db->getMagnetToAddressTrackerSeedersSumByMagnetId($magnet->magnetId), + 'completed' => $db->getMagnetToAddressTrackerCompletedSumByMagnetId($magnet->magnetId), + 'leechers' => $db->getMagnetToAddressTrackerLeechersSumByMagnetId($magnet->magnetId) ]; } @@ -316,24 +263,24 @@ echo '' . PHP_EOL ?> magnet->timeUpdated ? $response->magnet->timeUpdated : $response->magnet->timeAdded ?> - + - magnet->scrape->local->seeders ?> / magnet->scrape->total->seeders ?> + magnet->seeders ?> - + - magnet->scrape->local->completed ?> / magnet->scrape->total->completed ?> + magnet->completed ?> - + - magnet->scrape->local->leechers ?> / magnet->scrape->total->leechers ?> + magnet->leechers ?> diff --git a/src/public/node.php b/src/public/node.php index 4a7a8f5..fde05cc 100644 --- a/src/public/node.php +++ b/src/public/node.php @@ -39,64 +39,6 @@ else if (!$userId = $db->initUserId($_SERVER['REMOTE_ADDR'], USER_DEFAULT_APPROV $response->message = _('Could not init user session'); } -else -{ - - // 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->getMagnets() as $magnet) - { - 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; - } - } - } -} - ?> @@ -144,10 +86,6 @@ else - - - - @@ -171,15 +109,15 @@ else - seeders, $totalScrape->seeders) ?> + getMagnetToAddressTrackerSeedersSum() ?> - completed, $totalScrape->completed) ?> + getMagnetToAddressTrackerCompletedSum() ?> - leechers, $totalScrape->leechers) ?> + getMagnetToAddressTrackerLeechersSum() ?>