diff --git a/.gitignore b/.gitignore index 20ae7f6..23d0c29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,19 @@ -/.vscode/ -/vendor/ +/.vscode + +/vendor /database/yggtracker.mwb.bak + /src/config/app.php +/src/public/api/manifest.json +/src/public/api/users.json +/src/public/api/magnets.json +/src/public/api/downloads.json +/src/public/api/comments.json +/src/public/api/stars.json +/src/public/api/views.json + /composer.lock *test* \ No newline at end of file diff --git a/README.md b/README.md index aace4da..341ca75 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ sphinxsearch * Deploy the database using [MySQL Workbench](https://www.mysql.com/products/workbench) project presented in the `/database` folder * Install [Sphinx Search Server](https://sphinxsearch.com) * Configuration examples presented at `/config` folder +* Make sure `/src/api` folder writable * Set up the `/src/crontab` by following [example](https://github.com/YGGverse/YGGtracker/blob/main/example/environment/crontab) #### Contribute @@ -100,7 +101,14 @@ git checkout -b my-pr-branch-name + [x] Sitemap + [x] RSS + [x] Moderation - + [ ] Federative API + + [x] API + + [x] Manifest + + [x] Users + + [x] Magnets + + [x] Downloads + + [x] Comments + + [x] Stars + + [x] Views #### Donate to contributors diff --git a/database/yggtracker.mwb b/database/yggtracker.mwb index d38ddfe..e860e06 100644 Binary files a/database/yggtracker.mwb and b/database/yggtracker.mwb differ diff --git a/example/environment/crontab b/example/environment/crontab index 378d952..42201b6 100644 --- a/example/environment/crontab +++ b/example/environment/crontab @@ -4,4 +4,7 @@ * * * * * indexer magnet --rotate * * * * * /usr/bin/php /YGGtracker/src/crontab/scrape.php +* 5 * * * /usr/bin/php /YGGtracker/src/crontab/import/feed.php +* 0 * * * /usr/bin/php /YGGtracker/src/crontab/export/feed.php +* * * * * /usr/bin/php /YGGtracker/src/crontab/export/push.php 0 0 * * * /usr/bin/php /YGGtracker/src/crontab/sitemap.php \ No newline at end of file diff --git a/src/config/app.php.example b/src/config/app.php.example index abcf5f5..ac96c7c 100644 --- a/src/config/app.php.example +++ b/src/config/app.php.example @@ -104,10 +104,10 @@ define('MAGNET_STOP_WORDS_SIMILAR', ); // Comment -define('COMMENT_DEFAULT_APPROVED', false); -define('COMMENT_DEFAULT_PUBLIC', false); -define('COMMENT_MIN_LENGTH', 1); -define('COMMENT_MAX_LENGTH', 1000); +define('MAGNET_COMMENT_DEFAULT_APPROVED', false); +define('MAGNET_COMMENT_DEFAULT_PUBLIC', false); +define('MAGNET_COMMENT_MIN_LENGTH', 1); +define('MAGNET_COMMENT_MAX_LENGTH', 1000); // Yggdrasil define('YGGDRASIL_HOST_REGEX', '/^0{0,1}[2-3][a-f0-9]{0,2}:/'); // thanks to @ygguser (https://github.com/YGGverse/YGGo/issues/1#issuecomment-1498182228 ) @@ -116,6 +116,18 @@ define('YGGDRASIL_HOST_REGEX', '/^0{0,1}[2-3][a-f0-9]{0,2}:/'); // thanks to @yg define('CRAWLER_SCRAPE_QUEUE_LIMIT', 1); define('CRAWLER_SCRAPE_TIME_OFFLINE_TIMEOUT', 60*60*24); -// Rules -define('RULE_SUBJECT', 'Common'); -define('RULE_LANGUAGES', 'All'); \ No newline at end of file +// Node +define('NODE_RULE_SUBJECT', 'Common'); +define('NODE_RULE_LANGUAGES', 'All'); + +// API +define('API_VERSION', 1); + +define('API_ENABLED', true); + +define('API_FEED_USERS_ENABLED', true); +define('API_FEED_MAGNETS_ENABLED', true); +define('API_FEED_DOWNLOADS_ENABLED', true); +define('API_FEED_COMMENTS_ENABLED', true); +define('API_FEED_STARS_ENABLED', true); +define('API_FEED_VIEWS_ENABLED', true); \ No newline at end of file diff --git a/src/config/nodes.json b/src/config/nodes.json new file mode 100644 index 0000000..700e9f2 --- /dev/null +++ b/src/config/nodes.json @@ -0,0 +1,7 @@ +[ + { + "description":"YGGtracker instance for main branch tests", + "url":"http://[201:23b4:991a:634d:8359:4521:5576:15b7]/yggtracker", + "manifest":"http://[201:23b4:991a:634d:8359:4521:5576:15b7]/yggtracker/api/manifest.json" + } +] \ No newline at end of file diff --git a/src/crontab/export/feed.php b/src/crontab/export/feed.php new file mode 100644 index 0000000..b2bf0d0 --- /dev/null +++ b/src/crontab/export/feed.php @@ -0,0 +1,458 @@ + [ + 'ISO8601' => date('c'), + 'total' => microtime(true), + ], +]; + +// Define public registry +$public = [ + 'user' => [], + 'magnet' => [], +]; + +// Begin export +try +{ + // Connect DB + $db = new Database(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD); + + // Init API folder if not exists + @mkdir(__DIR__ . '/../public/api'); + + // Delete cached feeds + @unlink(__DIR__ . '/../public/api/manifest.json'); + + @unlink(__DIR__ . '/../public/api/users.json'); + @unlink(__DIR__ . '/../public/api/magnets.json'); + @unlink(__DIR__ . '/../public/api/comments.json'); + @unlink(__DIR__ . '/../public/api/downloads.json'); + @unlink(__DIR__ . '/../public/api/stars.json'); + @unlink(__DIR__ . '/../public/api/views.json'); + + if (API_ENABLED) + { + // Manifest + $manifest = + [ + 'version' => API_VERSION, + + 'settings' => + [ + 'YGGDRASIL_HOST_REGEX' => YGGDRASIL_HOST_REGEX, + + 'NODE_RULE_SUBJECT' => NODE_RULE_SUBJECT, + 'NODE_RULE_LANGUAGES' => NODE_RULE_LANGUAGES, + + 'USER_DEFAULT_APPROVED' => USER_DEFAULT_APPROVED, + 'USER_AUTO_APPROVE_ON_MAGNET_APPROVE' => USER_AUTO_APPROVE_ON_MAGNET_APPROVE, + 'USER_AUTO_APPROVE_ON_COMMENT_APPROVE' => USER_AUTO_APPROVE_ON_COMMENT_APPROVE, + 'USER_DEFAULT_IDENTICON' => USER_DEFAULT_IDENTICON, + 'USER_IDENTICON_FIELD' => USER_IDENTICON_FIELD, + + 'MAGNET_DEFAULT_APPROVED' => MAGNET_DEFAULT_APPROVED, + 'MAGNET_DEFAULT_PUBLIC' => MAGNET_DEFAULT_PUBLIC, + 'MAGNET_DEFAULT_COMMENTS' => MAGNET_DEFAULT_COMMENTS, + 'MAGNET_DEFAULT_SENSITIVE' => MAGNET_DEFAULT_SENSITIVE, + + 'MAGNET_EDITOR_LOCK_TIMEOUT' => MAGNET_EDITOR_LOCK_TIMEOUT, + + 'MAGNET_TITLE_MIN_LENGTH' => MAGNET_TITLE_MIN_LENGTH, + 'MAGNET_TITLE_MAX_LENGTH' => MAGNET_TITLE_MAX_LENGTH, + + 'MAGNET_PREVIEW_MIN_LENGTH' => MAGNET_PREVIEW_MIN_LENGTH, + 'MAGNET_PREVIEW_MAX_LENGTH' => MAGNET_PREVIEW_MAX_LENGTH, + + 'MAGNET_DESCRIPTION_MIN_LENGTH' => MAGNET_DESCRIPTION_MIN_LENGTH, + 'MAGNET_DESCRIPTION_MAX_LENGTH' => MAGNET_DESCRIPTION_MAX_LENGTH, + + 'MAGNET_COMMENT_DEFAULT_APPROVED' => MAGNET_COMMENT_DEFAULT_APPROVED, + 'MAGNET_COMMENT_DEFAULT_PUBLIC' => MAGNET_COMMENT_DEFAULT_PUBLIC, + 'MAGNET_COMMENT_DEFAULT_PUBLIC' => MAGNET_COMMENT_DEFAULT_PUBLIC, + 'MAGNET_COMMENT_MIN_LENGTH' => MAGNET_COMMENT_MIN_LENGTH, + 'MAGNET_COMMENT_MAX_LENGTH' => MAGNET_COMMENT_MAX_LENGTH, + + 'MAGNET_STOP_WORDS_SIMILAR' => MAGNET_STOP_WORDS_SIMILAR, + ], + + 'users' => API_FEED_USERS_ENABLED ? sprintf('%s/api/users.json', WEBSITE_URL) : false, + 'magnets' => API_FEED_MAGNETS_ENABLED ? sprintf('%s/api/magnets.json', WEBSITE_URL) : false, + 'downloads' => API_FEED_DOWNLOADS_ENABLED ? sprintf('%s/api/downloads.json', WEBSITE_URL) : false, + 'comments' => API_FEED_COMMENTS_ENABLED ? sprintf('%s/api/comments.json', WEBSITE_URL) : false, + 'stars' => API_FEED_STARS_ENABLED ? sprintf('%s/api/stars.json', WEBSITE_URL) : false, + 'views' => API_FEED_VIEWS_ENABLED ? sprintf('%s/api/views.json', WEBSITE_URL) : false, + + 'totals' => + [ + 'magnets' => + [ + 'total' => $db->getMagnetsTotal(), + 'distributed' => $db->getMagnetsTotalByUsersPublic(true), + 'local' => $db->getMagnetsTotalByUsersPublic(false), + ], + 'downloads' => + [ + 'total' => $db->getMagnetDownloadsTotal(), + 'distributed' => $db->findMagnetDownloadsTotalByUsersPublic(true), + 'local' => $db->findMagnetDownloadsTotalByUsersPublic(false), + ], + 'comments' => + [ + 'total' => $db->getMagnetCommentsTotal(), + 'distributed' => $db->findMagnetCommentsTotalByUsersPublic(true), + 'local' => $db->findMagnetCommentsTotalByUsersPublic(false), + ], + 'stars' => + [ + 'total' => $db->getMagnetStarsTotal(), + 'distributed' => $db->findMagnetStarsTotalByUsersPublic(true), + 'local' => $db->findMagnetStarsTotalByUsersPublic(false), + ], + 'views' => + [ + 'total' => $db->getMagnetViewsTotal(), + 'distributed' => $db->findMagnetViewsTotalByUsersPublic(true), + 'local' => $db->findMagnetViewsTotalByUsersPublic(false), + ], + ], + + 'trackers' => json_decode(file_get_contents(__DIR__ . '/../../config/trackers.json')), + 'nodes' => json_decode(file_get_contents(__DIR__ . '/../../config/nodes.json')), + ]; + + /// Dump manifest manifest + if ($handle = fopen(__DIR__ . '/../../public/api/manifest.json', 'w+')) + { + fwrite($handle, json_encode($manifest)); + fclose($handle); + } + + // Users + if (API_FEED_USERS_ENABLED) + { + $users = []; + + foreach ($db->getUsers() as $user) + { + // Dump public data only + if ($user->public === '1') + { + $users[] = (object) + [ + 'userId' => $user->userId, + 'address' => $user->address, + 'timeAdded' => $user->timeAdded, + 'timeUpdated' => $user->timeUpdated, + 'approved' => (bool) $user->approved, + 'magnets' => $db->findMagnetsTotalByUserId($user->userId), + 'downloads' => $db->findMagnetDownloadsTotalByUserId($user->userId), + 'comments' => $db->findMagnetCommentsTotalByUserId($user->userId), + 'stars' => $db->findMagnetStarsTotalByUserId($user->userId), + 'views' => $db->findMagnetViewsTotalByUserId($user->userId), + ]; + } + + // Cache public status + $public['user'][$user->userId] = $user->public; + } + + /// Dump users feed + if ($handle = fopen(__DIR__ . '/../../public/api/users.json', 'w+')) + { + fwrite($handle, json_encode($users)); + fclose($handle); + } + } + + // Magnets + if (API_FEED_MAGNETS_ENABLED) + { + $magnets = []; + + foreach ($db->getMagnets($user->userId) as $magnet) + { + // Dump public data only + if ($magnet->public === '1') + { + // Info Hash + $xt = []; + foreach ($db->findMagnetToInfoHashByMagnetId($magnet->magnetId) as $result) + { + if ($infoHash = $db->getInfoHash($result->infoHashId)) + { + $xt[$infoHash->version] = $infoHash->value; + } + } + + // Keyword Topic + $kt = []; + + foreach ($db->findKeywordTopicByMagnetId($magnet->magnetId) as $result) + { + $kt[] = $db->getKeywordTopic($result->keywordTopicId)->value; + } + + // Address Tracker + $tr = []; + foreach ($db->findAddressTrackerByMagnetId($magnet->magnetId) as $result) + { + $addressTracker = $db->getAddressTracker($result->addressTrackerId); + + $scheme = $db->getScheme($addressTracker->schemeId); + $host = $db->getHost($addressTracker->hostId); + $port = $db->getPort($addressTracker->portId); + $uri = $db->getUri($addressTracker->uriId); + + // Yggdrasil host only + if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $host->value))) + { + continue; + } + + $tr[] = $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); + } + + // Acceptable Source + $as = []; + + foreach ($db->findAcceptableSourceByMagnetId($magnet->magnetId) as $result) + { + $acceptableSource = $db->getAcceptableSource($result->acceptableSourceId); + + $scheme = $db->getScheme($acceptableSource->schemeId); + $host = $db->getHost($acceptableSource->hostId); + $port = $db->getPort($acceptableSource->portId); + $uri = $db->getUri($acceptableSource->uriId); + + // Yggdrasil host only + if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $host->value))) + { + continue; + } + + $as[] = $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); + } + + // Exact Source + $xs = []; + + foreach ($db->findExactSourceByMagnetId($magnet->magnetId) as $result) + { + $eXactSource = $db->getExactSource($result->eXactSourceId); + + $scheme = $db->getScheme($eXactSource->schemeId); + $host = $db->getHost($eXactSource->hostId); + $port = $db->getPort($eXactSource->portId); + $uri = $db->getUri($eXactSource->uriId); + + // Yggdrasil host only + if (!preg_match(YGGDRASIL_HOST_REGEX, str_replace(['[',']'], false, $host->value))) + { + continue; + } + + $xs[] = $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); + } + + $magnets[] = (object) + [ + 'magnetId' => $magnet->magnetId, + 'userId' => $magnet->userId, + 'title' => $magnet->title, + 'preview' => $magnet->preview, + 'description' => $magnet->description, + 'comments' => $magnet->comments, + 'sensitive' => $magnet->sensitive, + 'approved' => $magnet->approved, + 'timeAdded' => $magnet->timeAdded, + 'timeUpdated' => $magnet->timeUpdated, + 'dn' => $magnet->dn, + 'xl' => $magnet->xl, + 'xt' => $xt, + 'kt' => $kt, + 'tr' => $tr, + 'as' => $as, + 'xs' => $xs, + ]; + } + + // Cache public status + $public['magnet'][$magnet->magnetId] = $magnet->public; + } + + /// Dump magnets feed + if ($handle = fopen(__DIR__ . '/../../public/api/magnets.json', 'w+')) + { + fwrite($handle, json_encode($magnets)); + fclose($handle); + } + } + + // Downloads + if (API_FEED_DOWNLOADS_ENABLED) + { + $downloads = []; + + foreach ($db->getMagnetDownloads() as $download) + { + // Dump public data only + if (isset($public['magnet'][$download->magnetId]) && $public['magnet'][$download->magnetId] === '1' && + isset($public['user'][$download->userId]) && $public['user'][$download->userId] === '1') + { + $downloads[] = (object) + [ + 'magnetDownloadId' => $download->magnetDownloadId, + 'userId' => $download->userId, + 'magnetId' => $download->magnetId, + 'timeAdded' => $download->timeAdded, + ]; + } + } + + /// Dump downloads feed + if ($handle = fopen(__DIR__ . '/../../public/api/downloads.json', 'w+')) + { + fwrite($handle, json_encode($downloads)); + fclose($handle); + } + } + + // Comments + if (API_FEED_COMMENTS_ENABLED) + { + $comments = []; + + foreach ($db->getMagnetComments() as $comment) + { + // Dump public data only + if (isset($public['magnet'][$comment->magnetId]) && $public['magnet'][$comment->magnetId] === '1' && + isset($public['user'][$comment->userId]) && $public['user'][$comment->userId] === '1') + { + $comments[] = (object) + [ + 'magnetCommentId' => $comment->magnetCommentId, + 'userId' => $comment->userId, + 'magnetId' => $comment->magnetId, + 'timeAdded' => $comment->timeAdded, + ]; + } + } + + /// Dump comments feed + if ($handle = fopen(__DIR__ . '/../../public/api/comments.json', 'w+')) + { + fwrite($handle, json_encode($comments)); + fclose($handle); + } + } + + // Stars + if (API_FEED_STARS_ENABLED) + { + $stars = []; + + foreach ($db->getMagnetStars() as $star) + { + // Dump public data only + if (isset($public['magnet'][$star->magnetId]) && $public['magnet'][$star->magnetId] === '1' && + isset($public['user'][$star->userId]) && $public['user'][$star->userId] === '1') + { + $stars[] = (object) + [ + 'magnetStarId' => $star->magnetStarId, + 'userId' => $star->userId, + 'magnetId' => $star->magnetId, + 'value' => $star->value, + 'timeAdded' => $star->timeAdded, + ]; + } + } + + /// Dump stars feed + if ($handle = fopen(__DIR__ . '/../../public/api/stars.json', 'w+')) + { + fwrite($handle, json_encode($stars)); + fclose($handle); + } + } + // Views + if (API_FEED_VIEWS_ENABLED) + { + $views = []; + + foreach ($db->getMagnetViews() as $view) + { + // Dump public data only + if (isset($public['magnet'][$view->magnetId]) && $public['magnet'][$view->magnetId] === '1' && + isset($public['user'][$view->userId]) && $public['user'][$view->userId] === '1') + { + $views[] = (object) + [ + 'magnetViewId' => $view->magnetViewId, + 'userId' => $view->userId, + 'magnetId' => $view->magnetId, + 'timeAdded' => $view->timeAdded, + ]; + } + } + + /// Dump views feed + if ($handle = fopen(__DIR__ . '/../../public/api/views.json', 'w+')) + { + fwrite($handle, json_encode($views)); + fclose($handle); + } + } + } + +} catch (EXception $e) { + + var_dump($e); +} + +// Debug output +$debug['time']['total'] = microtime(true) - $debug['time']['total']; + +print_r( + array_merge($debug, [ + 'db' => [ + 'total' => [ + 'select' => $db->getDebug()->query->select->total, + 'insert' => $db->getDebug()->query->insert->total, + 'update' => $db->getDebug()->query->update->total, + 'delete' => $db->getDebug()->query->delete->total, + ] + ] + ]) +); \ No newline at end of file diff --git a/src/crontab/export/push.php b/src/crontab/export/push.php new file mode 100644 index 0000000..a46a2f5 --- /dev/null +++ b/src/crontab/export/push.php @@ -0,0 +1,3 @@ +fetch()->result; } + public function getMagnetComments() { + + $this->_debug->query->select->total++; + + $query = $this->_db->query('SELECT * FROM `magnetComment`'); + + return $query->fetchAll(); + } + public function findMagnetCommentsTotalByMagnetId(int $magnetId) : int { $this->_debug->query->select->total++; @@ -1288,18 +1297,18 @@ class Database { return $query->fetch()->result; } - public function findMagnetCommentsTotal(int $userId, int $magnetId) : int { + public function findMagnetCommentsTotal(int $magnetId, int $userId) : int { $this->_debug->query->select->total++; - $query = $this->_db->prepare('SELECT COUNT(*) AS `result` FROM `magnetComment` WHERE `userId` = ? AND `magnetId` = ?'); + $query = $this->_db->prepare('SELECT COUNT(*) AS `result` FROM `magnetComment` WHERE `magnetId` = ? AND `userId` = ?'); - $query->execute([$userId, $magnetId]); + $query->execute([$magnetId, $userId]); return $query->fetch()->result; } - public function getMagnetCommentsTotalByUsersPublic(bool $public) : int { + public function findMagnetCommentsTotalByUsersPublic(bool $public) : int { $this->_debug->query->select->total++; @@ -1312,7 +1321,7 @@ class Database { return $query->fetch()->result; } - public function getMagnetComments(int $magnetId, mixed $magnetCommentIdParent = null) { + public function findMagnetComments(int $magnetId, mixed $magnetCommentIdParent = null) { $this->_debug->query->select->total++; @@ -1355,6 +1364,24 @@ class Database { return $this->_db->lastInsertId(); } + public function getMagnetStars() { + + $this->_debug->query->select->total++; + + $query = $this->_db->query('SELECT * FROM `magnetStar`'); + + return $query->fetchAll(); + } + + public function getMagnetStarsTotal() : int { + + $this->_debug->query->select->total++; + + $query = $this->_db->query('SELECT COUNT(*) AS `result` FROM `magnetStar`'); + + return $query->fetch()->result; + } + public function findMagnetStarsTotalByMagnetId(int $magnetId) : int { $this->_debug->query->select->total++; @@ -1388,6 +1415,19 @@ class Database { return $query->rowCount() ? (bool) $query->fetch()->value : false; } + public function findMagnetStarsTotalByUsersPublic(bool $public) : int { + + $this->_debug->query->select->total++; + + $query = $this->_db->prepare('SELECT COUNT(*) AS `result` FROM `magnetStar` + JOIN `user` ON (`user`.`userId` = `magnetStar`.`userId`) + WHERE `user`.`public` = ?'); + + $query->execute([(int) $public]); + + return $query->fetch()->result; + } + // Magnet download public function addMagnetDownload(int $magnetId, int $userId, int $timeAdded) : int { @@ -1400,6 +1440,24 @@ class Database { return $this->_db->lastInsertId(); } + public function getMagnetDownloads() { + + $this->_debug->query->select->total++; + + $query = $this->_db->query('SELECT * FROM `magnetDownload`'); + + return $query->fetchAll(); + } + + public function getMagnetDownloadsTotal() : int { + + $this->_debug->query->select->total++; + + $query = $this->_db->query('SELECT COUNT(*) AS `result` FROM `magnetDownload`'); + + return $query->fetch()->result; + } + public function findMagnetDownloadsTotal(int $magnetId, int $userId) : int { $this->_debug->query->select->total++; @@ -1433,6 +1491,19 @@ class Database { return $query->fetch()->result; } + public function findMagnetDownloadsTotalByUsersPublic(bool $public) : int { + + $this->_debug->query->select->total++; + + $query = $this->_db->prepare('SELECT COUNT(*) AS `result` FROM `magnetDownload` + JOIN `user` ON (`user`.`userId` = `magnetDownload`.`userId`) + WHERE `user`.`public` = ?'); + + $query->execute([(int) $public]); + + return $query->fetch()->result; + } + // Magnet view public function addMagnetView(int $magnetId, int $userId, int $timeAdded) : int { @@ -1445,13 +1516,20 @@ class Database { return $this->_db->lastInsertId(); } - public function getMagnetViewsTotal(int $magnetId) : int { + public function getMagnetViews() { $this->_debug->query->select->total++; - $query = $this->_db->prepare('SELECT COUNT(*) AS `result` FROM `magnetView` WHERE `magnetId` = ?'); + $query = $this->_db->query('SELECT * FROM `magnetView`'); - $query->execute([$magnetId]); + return $query->fetchAll(); + } + + public function getMagnetViewsTotal() : int { + + $this->_debug->query->select->total++; + + $query = $this->_db->query('SELECT COUNT(*) AS `result` FROM `magnetView`'); return $query->fetch()->result; } @@ -1466,4 +1544,17 @@ class Database { return $query->fetch()->result; } + + public function findMagnetViewsTotalByUsersPublic(bool $public) : int { + + $this->_debug->query->select->total++; + + $query = $this->_db->prepare('SELECT COUNT(*) AS `result` FROM `magnetView` + JOIN `user` ON (`user`.`userId` = `magnetView`.`userId`) + WHERE `user`.`public` = ?'); + + $query->execute([(int) $public]); + + return $query->fetch()->result; + } } \ No newline at end of file diff --git a/src/public/action.php b/src/public/action.php index 818eb22..416b381 100644 --- a/src/public/action.php +++ b/src/public/action.php @@ -318,11 +318,11 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) // Validate comment value else if (empty($_POST['comment']) || - mb_strlen($_POST['comment']) < COMMENT_MIN_LENGTH || - mb_strlen($_POST['comment']) > COMMENT_MAX_LENGTH) + mb_strlen($_POST['comment']) < MAGNET_COMMENT_MIN_LENGTH || + mb_strlen($_POST['comment']) > MAGNET_COMMENT_MAX_LENGTH) { $response->success = false; - $response->message = sprintf(_('Valid comment value required, %s-%s chars allowed'), COMMENT_MIN_LENGTH, COMMENT_MAX_LENGTH); + $response->message = sprintf(_('Valid comment value required, %s-%s chars allowed'), MAGNET_COMMENT_MIN_LENGTH, MAGNET_COMMENT_MAX_LENGTH); } // Request valid @@ -332,8 +332,8 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) $user->userId, null, // @TODO implement threads trim($_POST['comment']), - $user->approved || in_array($user->address, MODERATOR_IP_LIST) ? true : COMMENT_DEFAULT_APPROVED, - COMMENT_DEFAULT_PUBLIC, + $user->approved || in_array($user->address, MODERATOR_IP_LIST) ? true : MAGNET_COMMENT_DEFAULT_APPROVED, + MAGNET_COMMENT_DEFAULT_PUBLIC, time())) { // Redirect to referrer page @@ -709,6 +709,10 @@ switch (isset($_GET['target']) ? urldecode($_GET['target']) : false) | + + | + + | diff --git a/src/public/api/index.html b/src/public/api/index.html new file mode 100644 index 0000000..e69de29 diff --git a/src/public/download.php b/src/public/download.php index 3cd7599..0742d93 100644 --- a/src/public/download.php +++ b/src/public/download.php @@ -311,6 +311,10 @@ else | + + | + + | diff --git a/src/public/edit.php b/src/public/edit.php index 34adbd7..5ba9305 100644 --- a/src/public/edit.php +++ b/src/public/edit.php @@ -864,6 +864,10 @@ else { | + + | + + | diff --git a/src/public/faq.php b/src/public/faq.php index 551b672..54cb6f7 100644 --- a/src/public/faq.php +++ b/src/public/faq.php @@ -228,6 +228,10 @@ else if (is_null($user->public)) | + + | + + | diff --git a/src/public/index.php b/src/public/index.php index 52be2da..6b34508 100644 --- a/src/public/index.php +++ b/src/public/index.php @@ -426,6 +426,10 @@ echo '' . PHP_EOL ?> | + + | + + | diff --git a/src/public/magnet.php b/src/public/magnet.php index e5c680a..45e0968 100644 --- a/src/public/magnet.php +++ b/src/public/magnet.php @@ -155,7 +155,7 @@ echo '' . PHP_EOL ?> magnet->magnetId) ?> <?php echo sprintf(_('%s - Comments - %s'), htmlentities($response->magnet->title), WEBSITE_NAME) ?> - getMagnetComments($response->magnet->magnetId) as $magnetComment) { ?> + findMagnetComments($response->magnet->magnetId) as $magnetComment) { ?> user->address == $db->getUser($magnetComment->userId)->address || in_array($response->user->address, MODERATOR_IP_LIST)) { ?> <?php echo sprintf('%s - comment #%s', htmlspecialchars($magnet->title, ENT_QUOTES, 'UTF-8'), $magnetComment->magnetCommentId) ?> @@ -388,7 +388,7 @@ echo '' . PHP_EOL ?>
- getMagnetComments($response->magnet->magnetId) as $magnetComment) { ?> + findMagnetComments($response->magnet->magnetId) as $magnetComment) { ?>
user->address == $db->getUser($magnetComment->userId)->address || @@ -463,8 +463,8 @@ echo '' . PHP_EOL ?> name="comment" value="" placeholder="" - minlength="" - maxlength=""> + minlength="" + maxlength="">
@@ -503,6 +503,10 @@ echo '' . PHP_EOL ?> | + + | + + |
diff --git a/src/public/welcome.php b/src/public/welcome.php index 984aed5..2159f87 100644 --- a/src/public/welcome.php +++ b/src/public/welcome.php @@ -146,6 +146,10 @@ else if (isset($_POST['public'])) | + + | + + |