mirror of
https://github.com/YGGverse/YGGtracker.git
synced 2026-03-31 17:15:38 +00:00
implement API, init data distribution features #1
This commit is contained in:
parent
536ead0441
commit
0a8f1ecf56
17 changed files with 647 additions and 27 deletions
14
.gitignore
vendored
14
.gitignore
vendored
|
|
@ -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*
|
||||
10
README.md
10
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
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -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
|
||||
|
|
@ -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');
|
||||
// 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);
|
||||
7
src/config/nodes.json
Normal file
7
src/config/nodes.json
Normal file
|
|
@ -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"
|
||||
}
|
||||
]
|
||||
458
src/crontab/export/feed.php
Normal file
458
src/crontab/export/feed.php
Normal file
|
|
@ -0,0 +1,458 @@
|
|||
<?php
|
||||
|
||||
// Lock multi-thread execution
|
||||
$semaphore = sem_get(crc32('yggtracker.crontab.export.feed'), 1);
|
||||
|
||||
if (false === sem_acquire($semaphore, true))
|
||||
{
|
||||
exit (PHP_EOL . 'yggtracker.crontab.export.feed process locked by another thread.' . PHP_EOL);
|
||||
}
|
||||
|
||||
// Load system dependencies
|
||||
require_once(__DIR__ . '/../../config/app.php');
|
||||
require_once(__DIR__ . '/../../library/database.php');
|
||||
|
||||
// Init Debug
|
||||
$debug =
|
||||
[
|
||||
'time' => [
|
||||
'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,
|
||||
]
|
||||
]
|
||||
])
|
||||
);
|
||||
3
src/crontab/export/push.php
Normal file
3
src/crontab/export/push.php
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<?php
|
||||
|
||||
// @TODO implementation for active API sync using push notifications from memcache
|
||||
|
|
@ -1266,6 +1266,15 @@ class Database {
|
|||
return $query->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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
|||
<a href="<?php echo WEBSITE_URL ?>/node.php"><?php echo _('Node') ?></a>
|
||||
|
|
||||
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/index.php?rss"><?php echo _('RSS') ?></a>
|
||||
<?php if (API_ENABLED) { ?>
|
||||
|
|
||||
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/api/manifest.json"><?php echo _('API') ?></a>
|
||||
<?php } ?>
|
||||
|
|
||||
<a href="https://github.com/YGGverse/YGGtracker"><?php echo _('GitHub') ?></a>
|
||||
</div>
|
||||
|
|
|
|||
0
src/public/api/index.html
Normal file
0
src/public/api/index.html
Normal file
|
|
@ -311,6 +311,10 @@ else
|
|||
<a href="<?php echo WEBSITE_URL ?>/node.php"><?php echo _('Node') ?></a>
|
||||
|
|
||||
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/index.php?rss"><?php echo _('RSS') ?></a>
|
||||
<?php if (API_ENABLED) { ?>
|
||||
|
|
||||
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/api/manifest.json"><?php echo _('API') ?></a>
|
||||
<?php } ?>
|
||||
|
|
||||
<a href="https://github.com/YGGverse/YGGtracker"><?php echo _('GitHub') ?></a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -864,6 +864,10 @@ else {
|
|||
<a href="<?php echo WEBSITE_URL ?>/node.php"><?php echo _('Node') ?></a>
|
||||
|
|
||||
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/index.php?rss"><?php echo _('RSS') ?></a>
|
||||
<?php if (API_ENABLED) { ?>
|
||||
|
|
||||
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/api/manifest.json"><?php echo _('API') ?></a>
|
||||
<?php } ?>
|
||||
|
|
||||
<a href="https://github.com/YGGverse/YGGtracker"><?php echo _('GitHub') ?></a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -228,6 +228,10 @@ else if (is_null($user->public))
|
|||
<a href="<?php echo WEBSITE_URL ?>/node.php"><?php echo _('Node') ?></a>
|
||||
|
|
||||
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/index.php?rss"><?php echo _('RSS') ?></a>
|
||||
<?php if (API_ENABLED) { ?>
|
||||
|
|
||||
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/api/manifest.json"><?php echo _('API') ?></a>
|
||||
<?php } ?>
|
||||
|
|
||||
<a href="https://github.com/YGGverse/YGGtracker"><?php echo _('GitHub') ?></a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -426,6 +426,10 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
|
|||
<a href="<?php echo WEBSITE_URL ?>/node.php"><?php echo _('Node') ?></a>
|
||||
|
|
||||
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/index.php?rss<?php echo $request->query ? sprintf('&query=%s', urlencode($request->query)) : false ?>"><?php echo _('RSS') ?></a>
|
||||
<?php if (API_ENABLED) { ?>
|
||||
|
|
||||
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/api/manifest.json"><?php echo _('API') ?></a>
|
||||
<?php } ?>
|
||||
|
|
||||
<a href="https://github.com/YGGverse/YGGtracker"><?php echo _('GitHub') ?></a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
|
|||
<link><?php echo sprintf('%s/magnet.php?magnetId=%s#comment', WEBSITE_URL, $response->magnet->magnetId) ?></link>
|
||||
<title><?php echo sprintf(_('%s - Comments - %s'), htmlentities($response->magnet->title), WEBSITE_NAME) ?></title>
|
||||
<description><?php echo _('BitTorrent Registry for Yggdrasil') ?></description>
|
||||
<?php foreach ($db->getMagnetComments($response->magnet->magnetId) as $magnetComment) { ?>
|
||||
<?php foreach ($db->findMagnetComments($response->magnet->magnetId) as $magnetComment) { ?>
|
||||
<?php if ($response->user->address == $db->getUser($magnetComment->userId)->address || in_array($response->user->address, MODERATOR_IP_LIST)) { ?>
|
||||
<item>
|
||||
<title><?php echo sprintf('%s - comment #%s', htmlspecialchars($magnet->title, ENT_QUOTES, 'UTF-8'), $magnetComment->magnetCommentId) ?></title>
|
||||
|
|
@ -388,7 +388,7 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
|
|||
<sup><small><a href="<?php echo sprintf('%s/magnet.php?rss&magnetId=%s&target=comment', WEBSITE_URL, $response->magnet->magnetId) ?>"><?php echo _('RSS') ?></a></small></sup>
|
||||
</div>
|
||||
<div class="padding-x-16">
|
||||
<?php foreach ($db->getMagnetComments($response->magnet->magnetId) as $magnetComment) { ?>
|
||||
<?php foreach ($db->findMagnetComments($response->magnet->magnetId) as $magnetComment) { ?>
|
||||
<div class="padding-x-16 padding-t-16 padding-b-8 margin-t-8 border-radius-3 background-color-night <?php echo !$magnetComment->approved || !$magnetComment->public ? 'opacity-06 opacity-hover-1' : false ?>">
|
||||
<a name="comment-<?php echo $magnetComment->magnetCommentId ?>"></a>
|
||||
<?php if ($response->user->address == $db->getUser($magnetComment->userId)->address ||
|
||||
|
|
@ -463,8 +463,8 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
|
|||
name="comment"
|
||||
value=""
|
||||
placeholder="<?php echo _('Enter your comment') ?>"
|
||||
minlength="<?php echo COMMENT_MIN_LENGTH ?>"
|
||||
maxlength="<?php echo COMMENT_MAX_LENGTH ?>"></textarea>
|
||||
minlength="<?php echo MAGNET_COMMENT_MIN_LENGTH ?>"
|
||||
maxlength="<?php echo MAGNET_COMMENT_MAX_LENGTH ?>"></textarea>
|
||||
</div>
|
||||
<div class="padding-b-8 text-right">
|
||||
<input type="submit" value="<?php echo _('send') ?>" />
|
||||
|
|
@ -503,6 +503,10 @@ echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
|
|||
<a href="<?php echo WEBSITE_URL ?>/node.php"><?php echo _('Node') ?></a>
|
||||
|
|
||||
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/index.php?rss"><?php echo _('RSS') ?></a>
|
||||
<?php if (API_ENABLED) { ?>
|
||||
|
|
||||
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/api/manifest.json"><?php echo _('API') ?></a>
|
||||
<?php } ?>
|
||||
|
|
||||
<a href="https://github.com/YGGverse/YGGtracker"><?php echo _('GitHub') ?></a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -146,6 +146,10 @@ else if (isset($_POST['public']))
|
|||
<a href="<?php echo WEBSITE_URL ?>/node.php"><?php echo _('Node') ?></a>
|
||||
|
|
||||
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/index.php?rss"><?php echo _('RSS') ?></a>
|
||||
<?php if (API_ENABLED) { ?>
|
||||
|
|
||||
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/api/manifest.json"><?php echo _('API') ?></a>
|
||||
<?php } ?>
|
||||
|
|
||||
<a href="https://github.com/YGGverse/YGGtracker"><?php echo _('GitHub') ?></a>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue