Browse Source

init MVC framework refactory #14

main
ghost 1 year ago
parent
commit
a600a08a28
  1. 116
      src/app/controller/index.php
  2. 25
      src/app/controller/module/footer.php
  3. 54
      src/app/controller/module/head.php
  4. 19
      src/app/controller/module/header.php
  5. 9
      src/app/controller/module/page.php
  6. 43
      src/app/controller/module/pagination.php
  7. 11
      src/app/controller/module/search.php
  8. 65
      src/app/controller/response.php
  9. 96
      src/app/controller/submit.php
  10. 152
      src/app/controller/user.php
  11. 119
      src/app/controller/welcome.php
  12. 61
      src/app/model/database.php
  13. 2
      src/app/model/sphinx.php
  14. 32
      src/app/view/theme/default/index.phtml
  15. 27
      src/app/view/theme/default/module/footer.phtml
  16. 7
      src/app/view/theme/default/module/head.phtml
  17. 10
      src/app/view/theme/default/module/header.phtml
  18. 126
      src/app/view/theme/default/module/page.phtml
  19. 15
      src/app/view/theme/default/module/pagination.phtml
  20. 4
      src/app/view/theme/default/module/search.phtml
  21. 24
      src/app/view/theme/default/response.phtml
  22. 35
      src/app/view/theme/default/submit.phtml
  23. 39
      src/app/view/theme/default/welcome.phtml
  24. 102
      src/config/bootstrap.php
  25. 77
      src/public/assets/theme/default/css/framework.css
  26. 303
      src/public/import.php
  27. 431
      src/public/index.php
  28. 146
      src/public/welcome.php

116
src/app/controller/index.php

@ -0,0 +1,116 @@ @@ -0,0 +1,116 @@
<?php
class AppControllerIndex
{
private $_db;
private $_sphinx;
private $_memory;
public function __construct()
{
require_once __DIR__ . '/../../library/database.php';
require_once __DIR__ . '/../../library/sphinx.php';
require_once __DIR__ . '/../../library/scrapeer.php';
require_once __DIR__ . '/../../library/time.php';
require_once __DIR__ . '/../../library/curl.php';
require_once __DIR__ . '/../../library/valid.php';
require_once __DIR__ . '/../../library/filter.php';
require_once __DIR__ . '/../../../vendor/autoload.php';
try
{
$this->_db = new Database(
DB_HOST,
DB_PORT,
DB_NAME,
DB_USERNAME,
DB_PASSWORD
);
$this->_sphinx = new Sphinx(
SPHINX_HOST,
SPHINX_PORT
);
$this->_memory = new \Yggverse\Cache\Memory(
MEMCACHED_HOST,
MEMCACHED_PORT,
MEMCACHED_NAMESPACE,
MEMCACHED_TIMEOUT + time()
);
}
catch (Exception $error)
{
require_once __DIR__ . '/error/500.php';
$controller = new AppControllerError500(
print_r($error, true)
);
$controller->render();
exit;
}
}
public function render()
{
$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$pages = [];
require_once __DIR__ . '/module/pagination.php';
$appControllerModulePagination = new appControllerModulePagination();
require_once __DIR__ . '/module/head.php';
$appControllerModuleHead = new AppControllerModuleHead(
WEBSITE_URL,
$page > 1 ?
sprintf(
_('Page %s - BitTorrent Registry for Yggdrasil - %s'),
$page,
WEBSITE_NAME
) :
sprintf(
_('%s - BitTorrent Registry for Yggdrasil'),
WEBSITE_NAME
),
[
[
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => sprintf(
'assets/theme/default/css/common.css?%s',
WEBSITE_CSS_VERSION
),
],
[
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => sprintf(
'assets/theme/default/css/framework.css?%s',
WEBSITE_CSS_VERSION
),
],
]
);
require_once __DIR__ . '/module/profile.php';
$appControllerModuleProfile = new AppControllerModuleProfile($user->userId);
require_once __DIR__ . '/module/header.php';
$appControllerModuleHeader = new AppControllerModuleHeader();
require_once __DIR__ . '/module/footer.php';
$appControllerModuleFooter = new AppControllerModuleFooter();
include __DIR__ . '/../view/theme/default/index.phtml';
}
}

25
src/app/controller/module/footer.php

@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
<?php
class AppControllerModuleFooter
{
public function render()
{
$response['trackers'] = [];
if ($trackers = json_decode(file_get_contents(__DIR__ . '/../../../config/trackers.json')))
{
foreach ($trackers as $tracker)
{
if (!empty($tracker->announce) && !empty($tracker->stats))
{
$response['trackers'][] = [
'announce' => $tracker->announce,
'stats' => $tracker->stats,
];
}
}
}
include __DIR__ . '../../../view/theme/default/module/footer.phtml';
}
}

54
src/app/controller/module/head.php

@ -0,0 +1,54 @@ @@ -0,0 +1,54 @@
<?php
class AppControllerModuleHead
{
private $_title;
private $_base;
private $_links = [];
public function __construct(string $base, string $title, array $links = [])
{
$this->setBase($base);
$this->setTitle($title);
foreach ($links as $link)
{
$this->addLink(
$link['rel'],
$link['type'],
$link['href'],
);
}
}
public function setBase(string $base) : void
{
$this->_base = $base;
}
public function setTitle(string $title) : void
{
$this->_title = $title;
}
public function addLink(string $rel, string $type, string $href) : void
{
$this->_links[] = (object)
[
'rel' => $rel,
'type' => $type,
'href' => $href,
];
}
public function render()
{
$base = $this->_base;
$links = $this->_links;
$title = htmlentities($this->_title);
include __DIR__ . '../../../view/theme/default/module/head.phtml';
}
}

19
src/app/controller/module/header.php

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
<?php
class AppControllerModuleHeader
{
public function render()
{
$name = str_replace(
'YGG',
'<span>YGG</span>',
WEBSITE_NAME
);
require_once __DIR__ . '/search.php';
$appControllerModuleSearch = new AppControllerModuleSearch();
include __DIR__ . '../../../view/theme/default/module/header.phtml';
}
}

9
src/app/controller/module/page.php

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
<?php
class AppControllerCommonPage
{
public function render(int $pageId)
{
include __DIR__ . '../../../view/theme/default/common/page.phtml';
}
}

43
src/app/controller/module/pagination.php

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
<?php
class AppControllerModulePagination
{
public function render(string $url, int $total, int $limit)
{
if ($total > $limit)
{
parse_str($url, $query);
$pagination->page = isset($query['total']) ? (int) $query['total'] : 1;
$pagination->pages = ceil($total / $limit);
// Previous
if ($page > 1)
{
$query['page'] = $page - 1;
$pagination->back = sprintf('%s', WEBSITE_URL, http_build_query($query));
}
else
{
$pagination->back = false;
}
// Next
if ($page < ceil($total / $limit))
{
$query['page'] = $page + 1;
$pagination->next = sprintf('%s', WEBSITE_URL, http_build_query($query));
}
else
{
$pagination->next = false;
}
// Render
}
}
}

11
src/app/controller/module/search.php

@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
<?php
class AppControllerModuleSearch
{
public function render()
{
$query = empty($_GET['query']) ? false : urldecode($_GET['query']);
include __DIR__ . '../../../view/theme/default/module/search.phtml';
}
}

65
src/app/controller/response.php

@ -0,0 +1,65 @@ @@ -0,0 +1,65 @@
<?php
class AppControllerResponse
{
private $_title;
private $_h1;
private $_text;
private $_code;
public function __construct(string $title, string $h1, string $text, int $code = 200)
{
$this->_title = $title;
$this->_h1 = $h1;
$this->_text = $text;
$this->_code = $code;
}
public function render()
{
header(
sprintf(
'HTTP/1.0 %s Not Found',
$this->_code
)
);
$h1 = $this->_h1;
$text = $this->_text;
require_once __DIR__ . '/module/head.php';
$appControllerModuleHead = new AppControllerModuleHead(
WEBSITE_URL,
$this->_title,
[
[
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => sprintf(
'assets/theme/default/css/common.css?%s',
WEBSITE_CSS_VERSION
),
],
[
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => sprintf(
'assets/theme/default/css/framework.css?%s',
WEBSITE_CSS_VERSION
),
],
]
);
require_once __DIR__ . '/module/header.php';
$appControllerModuleHeader = new AppControllerModuleHeader();
require_once __DIR__ . '/module/footer.php';
$appControllerModuleFooter = new AppControllerModuleFooter();
include __DIR__ . '../../view/theme/default/response.phtml';
}
}

96
src/app/controller/submit.php

@ -0,0 +1,96 @@ @@ -0,0 +1,96 @@
<?php
class AppControllerSubmit
{
private function _response(string $title, string $h1, string $text, int $code = 200)
{
require_once __DIR__ . '/response.php';
$appControllerResponse = new AppControllerResponse(
$title,
$h1,
$text,
$code
);
$appControllerResponse->render();
exit;
}
public function render()
{
require_once __DIR__ . '/user.php';
$appControllerUser = new AppControllerUser(
$_SERVER['REMOTE_ADDR']
);
// Get user info
if (!$user = $appControllerUser->getUser())
{
$this->_response(
sprintf(
_('Error - %s'),
WEBSITE_NAME
),
_('500'),
_('Could not init user'),
500
);
}
// Require account type selection
if (is_null($user->public))
{
header(
sprintf('Location: %s/welcome', trim(WEBSITE_URL, '/'))
);
}
// Render
require_once __DIR__ . '/module/head.php';
$appControllerModuleHead = new AppControllerModuleHead(
WEBSITE_URL,
sprintf(
_('Submit - %s'),
WEBSITE_NAME
),
[
[
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => sprintf(
'assets/theme/default/css/common.css?%s',
WEBSITE_CSS_VERSION
),
],
[
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => sprintf(
'assets/theme/default/css/framework.css?%s',
WEBSITE_CSS_VERSION
),
],
]
);
require_once __DIR__ . '/module/profile.php';
$appControllerModuleProfile = new AppControllerModuleProfile(
$appControllerUser
);
require_once __DIR__ . '/module/header.php';
$appControllerModuleHeader = new AppControllerModuleHeader();
require_once __DIR__ . '/module/footer.php';
$appControllerModuleFooter = new AppControllerModuleFooter();
include __DIR__ . '../../view/theme/default/submit.phtml';
}
}

152
src/app/controller/user.php

@ -0,0 +1,152 @@ @@ -0,0 +1,152 @@
<?php
class AppControllerUser
{
private $_database;
private $_user;
public function __construct(string $address)
{
// Connect DB
require_once __DIR__ . '/../model/database.php';
try
{
$this->_database = new AppModelDatabase(
DB_HOST,
DB_PORT,
DB_NAME,
DB_USERNAME,
DB_PASSWORD
);
}
catch (Exception $error)
{
$this->_response(
sprintf(
_('Error - %s'),
WEBSITE_NAME
),
_('500'),
print_r($error, true),
500
);
}
// Validate user address
require_once __DIR__ . '/../../library/valid.php';
$error = [];
if (!Valid::host($address, $error))
{
$this->_response(
sprintf(
_('Error - %s'),
WEBSITE_NAME
),
_('406'),
print_r($error, true),
406
);
}
// Init user session
try
{
$this->_database->beginTransaction();
$this->_user = $this->_database->getUser(
$this->_database->initUserId(
$address,
USER_DEFAULT_APPROVED,
time()
)
);
$this->_database->commit();
}
catch (Exception $error)
{
$this->_database->rollback();
$this->_response(
sprintf(
_('Error - %s'),
WEBSITE_NAME
),
_('500'),
print_r($error, true),
500
);
}
}
private function _response(string $title, string $h1, string $text, int $code = 200)
{
require_once __DIR__ . '/response.php';
$appControllerResponse = new AppControllerResponse(
$title,
$h1,
$text,
$code
);
$appControllerResponse->render();
exit;
}
public function getUser()
{
return $this->_user;
}
public function findUserPageStarsDistinctTotalByValue(bool $value) : int
{
return $this->_database->findUserPageStarsDistinctTotal(
$this->_user->userId,
$value
);
}
public function findUserPageViewsDistinctTotal() : int
{
return $this->_database->findUserPageViewsDistinctTotal(
$this->_user->userId
);
}
public function findUserPageDownloadsDistinctTotal() : int
{
return $this->_database->findUserPageDownloadsDistinctTotal(
$this->_user->userId
);
}
public function findUserPageCommentsDistinctTotal() : int
{
return $this->_database->findUserPageCommentsDistinctTotal(
$this->_user->userId
);
}
public function findUserPageEditionsDistinctTotal() : int
{
return $this->_database->findUserPageEditionsDistinctTotal(
$this->_user->userId
);
}
public function updateUserPublic(bool $public, int $time) : int
{
return $this->_database->updateUserPublic(
$this->_user->userId,
$public,
$time
);
}
}

119
src/app/controller/welcome.php

@ -0,0 +1,119 @@ @@ -0,0 +1,119 @@
<?php
class AppControllerWelcome
{
private $_user;
public function __construct()
{
require_once __DIR__ . '/../model/user.php';
$this->_user = new AppModelUser(
$_SERVER['REMOTE_ADDR']
);
}
private function _response(string $title, string $h1, string $text, int $code = 200)
{
require_once __DIR__ . '/response.php';
$appControllerResponse = new AppControllerResponse(
$title,
$h1,
$text,
$code
);
$appControllerResponse->render();
exit;
}
public function render()
{
if (!$user = $this->_user->get())
{
$this->_response(
sprintf(
_('Error - %s'),
WEBSITE_NAME
),
_('500'),
_('Could not init user'),
500
);
}
if (!is_null($user->public))
{
$this->_response(
sprintf(
_('Welcome back - %s'),
WEBSITE_NAME
),
_('Welcome back!'),
sprintf(
_('You already have selected account type to %s'),
$user->public ? _('Distributed') : _('Local')
),
405
);
}
if (isset($_POST['public']))
{
if ($this->_user->updateUserPublic((bool) $_POST['public'], time()))
{
$this->_response(
sprintf(
_('Success - %s'),
WEBSITE_NAME
),
_('Success!'),
sprintf(
_('Account type successfully changed to %s'),
$_POST['public'] ? _('Distributed') : _('Local')
),
);
}
}
require_once __DIR__ . '/module/head.php';
$appControllerModuleHead = new AppControllerModuleHead(
WEBSITE_URL,
sprintf(
_('Welcome to %s'),
WEBSITE_NAME
),
[
[
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => sprintf(
'assets/theme/default/css/common.css?%s',
WEBSITE_CSS_VERSION
),
],
[
'rel' => 'stylesheet',
'type' => 'text/css',
'href' => sprintf(
'assets/theme/default/css/framework.css?%s',
WEBSITE_CSS_VERSION
),
],
]
);
require_once __DIR__ . '/module/header.php';
$appControllerModuleHeader = new AppControllerModuleHeader();
require_once __DIR__ . '/module/footer.php';
$appControllerModuleFooter = new AppControllerModuleFooter();
include __DIR__ . '../../view/theme/default/welcome.phtml';
}
}

61
src/library/database.php → src/app/model/database.php

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
<?php
class Database {
class AppModelDatabase {
private PDO $_db;
@ -597,6 +597,65 @@ class Database { @@ -597,6 +597,65 @@ class Database {
return $query->rowCount();
}
public function findUserPageStarsDistinctTotal(int $userId, bool $value) : int {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT COUNT(DISTINCT `pageId`) AS `result` FROM `userPageStar` WHERE `userId` = ? AND `value` = ?');
$query->execute([$userId, (int) $value]);
return $query->fetch()->result;
}
public function findUserPageViewsDistinctTotal(int $userId) : int {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT COUNT(DISTINCT `pageId`) AS `result` FROM `userPageView` WHERE `userId` = ?');
$query->execute([$userId]);
return $query->fetch()->result;
}
public function findUserPageDownloadsDistinctTotal(int $userId) : int {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT COUNT(DISTINCT `pageId`) AS `result` FROM `userPageDownload` WHERE `userId` = ?');
$query->execute([$userId]);
return $query->fetch()->result;
}
public function findUserPageCommentsDistinctTotal(int $userId) : int {
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT COUNT(DISTINCT `pageId`) AS `result` FROM `userPageComment` WHERE `userId` = ?');
$query->execute([$userId]);
return $query->fetch()->result;
}
public function findUserPageEditionsDistinctTotal(int $userId) : int {
return 0;
/* @TODO
$this->_debug->query->select->total++;
$query = $this->_db->prepare('SELECT COUNT(DISTINCT `pageId`) AS `result` FROM `userPageEdition` WHERE `userId` = ?');
$query->execute([$userId]);
return $query->fetch()->result;
*/
}
// Magnet
public function addMagnet(int $userId,
int $xl,

2
src/library/sphinx.php → src/app/model/sphinx.php

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
<?php
class Sphinx {
class AppModelSphinx {
private $_sphinx;

32
src/app/view/theme/default/index.phtml

@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<?php $appControllerModuleHead->render() ?>
<body>
<?php $appControllerModuleHeader->render() ?>
<main>
<div class="container">
<div class="row">
<div class="column width-100">
<?php $appControllerModuleProfile->render() ?>
<?php if ($pages) { ?>
<?php foreach ($pages as $page) { ?>
<?php $appControllerModulePage->render($page->pageId) ?>
<?php } ?>
<?php $appControllerModulePagination->render() ?>
<?php } else { ?>
<div class="padding-16 margin-y-8 border-radius-3 background-color-night text-center">
<h1 class="margin-b-8">
<?php echo _('Nothing found') ?>
</h1>
<div class="text-color-night">
<?php echo _('* share your magnet links to change it') ?>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
</main>
<?php $appControllerModuleFooter->render() ?>
</body>
</html>

27
src/app/view/theme/default/module/footer.phtml

@ -0,0 +1,27 @@ @@ -0,0 +1,27 @@
<footer>
<div class="container">
<div class="row">
<div class="column width-100 text-center margin-y-8">
<?php foreach ($trackers as $i => $tracker) { ?>
<a href="<?php echo $tracker->announce ?>"><?php echo sprintf('Tracker %s', $i + 1) ?></a>
/
<a href="<?php echo $tracker->stats ?>"><?php echo _('Stats') ?></a>
|
<?php } ?>
<a href="faq"><?php echo _('F.A.Q') ?></a>
|
<a href="node"><?php echo _('Node') ?></a>
|
<a rel="nofollow" href="rss"><?php echo _('RSS') ?></a>
<?php if (API_EXPORT_ENABLED) { ?>
|
<a rel="nofollow" href="api/manifest.json"><?php echo _('API') ?></a>
<?php } ?>
|
<a href="https://github.com/YGGverse/YGGtracker"><?php echo _('GitHub') ?></a>
</div>
</div>
</div>
</footer>
</body>
</html>

7
src/app/view/theme/default/module/head.phtml

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
<head>
<base href="<?php echo $base ?>" />
<title><?php echo $title ?></title>
<?php foreach ($links as $link) { ?>
<link rel="<?php echo $link->rel ?>" type="<?php echo $link->type ?>" href="<?php echo $link->href ?>" />
<?php } ?>
</head>

10
src/app/view/theme/default/module/header.phtml

@ -0,0 +1,10 @@ @@ -0,0 +1,10 @@
<header>
<div class="container">
<div class="row margin-t-8 text-center">
<a class="logo" href="">
<?php echo $name ?>
</a>
<?php $appControllerModuleSearch->render() ?>
</div>
</div>
</header>

126
src/app/view/theme/default/module/page.phtml

@ -0,0 +1,126 @@ @@ -0,0 +1,126 @@
<a name="magnet-<?php echo $pageId ?>"></a>
<div class="margin-y-8 border-radius-3 background-color-night <?php echo !$approved ? 'opacity-06 opacity-hover-1' : false ?>">
<div class="padding-16 <?php echo $sensitive ? 'blur-2 blur-hover-0' : false ?>">
<a href="<?php echo sprintf('%s/magnet.php?magnetId=%s', WEBSITE_URL, $pageId) ?>">
<h2 class="margin-b-8"><?php echo $title ?></h2>
<?php if ($leechers && !$seeders) { ?>
<span class="label label-green margin-x-4 font-size-10 position-relative top--2 cursor-default"
title="<?php echo _('Active leechers waiting for seeds') ?>">
<?php echo _('wanted') ?>
</span>
<?php } ?>
</a>
<div class="float-right opacity-0 parent-hover-opacity-09">
<?php if (!$approved) { ?>
<span class="margin-l-8" title="<?php echo _('Waiting for approve') ?>">
<svg class="width-13px" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-hourglass-split" viewBox="0 0 16 16">
<path d="M2.5 15a.5.5 0 1 1 0-1h1v-1a4.5 4.5 0 0 1 2.557-4.06c.29-.139.443-.377.443-.59v-.7c0-.213-.154-.451-.443-.59A4.5 4.5 0 0 1 3.5 3V2h-1a.5.5 0 0 1 0-1h11a.5.5 0 0 1 0 1h-1v1a4.5 4.5 0 0 1-2.557 4.06c-.29.139-.443.377-.443.59v.7c0 .213.154.451.443.59A4.5 4.5 0 0 1 12.5 13v1h1a.5.5 0 0 1 0 1h-11zm2-13v1c0 .537.12 1.045.337 1.5h6.326c.216-.455.337-.963.337-1.5V2h-7zm3 6.35c0 .701-.478 1.236-1.011 1.492A3.5 3.5 0 0 0 4.5 13s.866-1.299 3-1.48V8.35zm1 0v3.17c2.134.181 3 1.48 3 1.48a3.5 3.5 0 0 0-1.989-3.158C8.978 9.586 8.5 9.052 8.5 8.351z"/>
</svg>
</span>
<?php } ?>
<a class="text-color-green margin-l-12" href="<?php echo WEBSITE_URL ?>/edit.php?magnetId=<?php echo $magnet->magnetId ?>" title="<?php echo _('Edit') ?>">
<svg class="text-color-green" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pencil-square" viewBox="0 0 16 16">
<path d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z"/>
<path fill-rule="evenodd" d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z"/>
</svg>
</a>
</div>
<?php if ($magnet->preview) { ?>
<div class="margin-y-8"><?php echo $magnet->preview ?></div>
<?php } ?>
<?php if ($magnet->keywords) { ?>
<div class="margin-y-8">
<?php foreach ($magnet->keywords as $keyword) { ?>
<small>
<a href="<?php echo WEBSITE_URL ?>/search.php?query=<?php echo urlencode($keyword) ?>">#<?php echo htmlentities($keyword) ?></a>
</small>
<?php } ?>
</div>
<?php } ?>
<div class="width-100 padding-y-4"></div>
<span class="margin-t-8 margin-r-8 cursor-default">
<sup>
<?php echo $magnet->timeUpdated ? _('Updated') : _('Added') ?>
<?php echo $magnet->timeUpdated ? $magnet->timeUpdated : $magnet->timeAdded ?>
</sup>
</span>
<span class="margin-t-8 margin-r-8 cursor-default opacity-0 parent-hover-opacity-09" title="<?php echo _('Seeds') ?>">
<svg class="width-13px" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-up" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 15a.5.5 0 0 0 .5-.5V2.707l3.146 3.147a.5.5 0 0 0 .708-.708l-4-4a.5.5 0 0 0-.708 0l-4 4a.5.5 0 1 0 .708.708L7.5 2.707V14.5a.5.5 0 0 0 .5.5z"/>
</svg>
<sup><?php echo $magnet->seeders ?></sup>
</span>
<span class="margin-t-8 margin-r-8 cursor-default opacity-0 parent-hover-opacity-09" title="<?php echo _('Peers') ?>">
<svg class="width-13px" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
</svg>
<sup><?php echo $magnet->completed ?></sup>
</span>
<span class="margin-t-8 margin-r-8 cursor-default opacity-0 parent-hover-opacity-09" title="<?php echo _('Leechers') ?>">
<svg class="width-13px" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-cup-hot" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M.5 6a.5.5 0 0 0-.488.608l1.652 7.434A2.5 2.5 0 0 0 4.104 16h5.792a2.5 2.5 0 0 0 2.44-1.958l.131-.59a3 3 0 0 0 1.3-5.854l.221-.99A.5.5 0 0 0 13.5 6H.5ZM13 12.5a2.01 2.01 0 0 1-.316-.025l.867-3.898A2.001 2.001 0 0 1 13 12.5ZM2.64 13.825 1.123 7h11.754l-1.517 6.825A1.5 1.5 0 0 1 9.896 15H4.104a1.5 1.5 0 0 1-1.464-1.175Z"/>
<path d="m4.4.8-.003.004-.014.019a4.167 4.167 0 0 0-.204.31 2.327 2.327 0 0 0-.141.267c-.026.06-.034.092-.037.103v.004a.593.593 0 0 0 .091.248c.075.133.178.272.308.445l.01.012c.118.158.26.347.37.543.112.2.22.455.22.745 0 .188-.065.368-.119.494a3.31 3.31 0 0 1-.202.388 5.444 5.444 0 0 1-.253.382l-.018.025-.005.008-.002.002A.5.5 0 0 1 3.6 4.2l.003-.004.014-.019a4.149 4.149 0 0 0 .204-.31 2.06 2.06 0 0 0 .141-.267c.026-.06.034-.092.037-.103a.593.593 0 0 0-.09-.252A4.334 4.334 0 0 0 3.6 2.8l-.01-.012a5.099 5.099 0 0 1-.37-.543A1.53 1.53 0 0 1 3 1.5c0-.188.065-.368.119-.494.059-.138.134-.274.202-.388a5.446 5.446 0 0 1 .253-.382l.025-.035A.5.5 0 0 1 4.4.8Zm3 0-.003.004-.014.019a4.167 4.167 0 0 0-.204.31 2.327 2.327 0 0 0-.141.267c-.026.06-.034.092-.037.103v.004a.593.593 0 0 0 .091.248c.075.133.178.272.308.445l.01.012c.118.158.26.347.37.543.112.2.22.455.22.745 0 .188-.065.368-.119.494a3.31 3.31 0 0 1-.202.388 5.444 5.444 0 0 1-.253.382l-.018.025-.005.008-.002.002A.5.5 0 0 1 6.6 4.2l.003-.004.014-.019a4.149 4.149 0 0 0 .204-.31 2.06 2.06 0 0 0 .141-.267c.026-.06.034-.092.037-.103a.593.593 0 0 0-.09-.252A4.334 4.334 0 0 0 6.6 2.8l-.01-.012a5.099 5.099 0 0 1-.37-.543A1.53 1.53 0 0 1 6 1.5c0-.188.065-.368.119-.494.059-.138.134-.274.202-.388a5.446 5.446 0 0 1 .253-.382l.025-.035A.5.5 0 0 1 7.4.8Zm3 0-.003.004-.014.019a4.077 4.077 0 0 0-.204.31 2.337 2.337 0 0 0-.141.267c-.026.06-.034.092-.037.103v.004a.593.593 0 0 0 .091.248c.075.133.178.272.308.445l.01.012c.118.158.26.347.37.543.112.2.22.455.22.745 0 .188-.065.368-.119.494a3.198 3.198 0 0 1-.202.388 5.385 5.385 0 0 1-.252.382l-.019.025-.005.008-.002.002A.5.5 0 0 1 9.6 4.2l.003-.004.014-.019a4.149 4.149 0 0 0 .204-.31 2.06 2.06 0 0 0 .141-.267c.026-.06.034-.092.037-.103a.593.593 0 0 0-.09-.252A4.334 4.334 0 0 0 9.6 2.8l-.01-.012a5.099 5.099 0 0 1-.37-.543A1.53 1.53 0 0 1 9 1.5c0-.188.065-.368.119-.494.059-.138.134-.274.202-.388a5.446 5.446 0 0 1 .253-.382l.025-.035A.5.5 0 0 1 10.4.8Z"/>
</svg>
<sup><?php echo $magnet->leechers ?></sup>
</span>
<?php if ($magnet->directs) { ?>
<span class="margin-t-8 margin-r-8 cursor-default opacity-0 parent-hover-opacity-09" title="<?php echo _('Direct') ?>">
<svg class="width-13px" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-database" viewBox="0 0 16 16">
<path d="M4.318 2.687C5.234 2.271 6.536 2 8 2s2.766.27 3.682.687C12.644 3.125 13 3.627 13 4c0 .374-.356.875-1.318 1.313C10.766 5.729 9.464 6 8 6s-2.766-.27-3.682-.687C3.356 4.875 3 4.373 3 4c0-.374.356-.875 1.318-1.313ZM13 5.698V7c0 .374-.356.875-1.318 1.313C10.766 8.729 9.464 9 8 9s-2.766-.27-3.682-.687C3.356 7.875 3 7.373 3 7V5.698c.271.202.58.378.904.525C4.978 6.711 6.427 7 8 7s3.022-.289 4.096-.777A4.92 4.92 0 0 0 13 5.698ZM14 4c0-1.007-.875-1.755-1.904-2.223C11.022 1.289 9.573 1 8 1s-3.022.289-4.096.777C2.875 2.245 2 2.993 2 4v9c0 1.007.875 1.755 1.904 2.223C4.978 15.71 6.427 16 8 16s3.022-.289 4.096-.777C13.125 14.755 14 14.007 14 13V4Zm-1 4.698V10c0 .374-.356.875-1.318 1.313C10.766 11.729 9.464 12 8 12s-2.766-.27-3.682-.687C3.356 10.875 3 10.373 3 10V8.698c.271.202.58.378.904.525C4.978 9.71 6.427 10 8 10s3.022-.289 4.096-.777A4.92 4.92 0 0 0 13 8.698Zm0 3V13c0 .374-.356.875-1.318 1.313C10.766 14.729 9.464 15 8 15s-2.766-.27-3.682-.687C3.356 13.875 3 13.373 3 13v-1.302c.271.202.58.378.904.525C4.978 12.71 6.427 13 8 13s3.022-.289 4.096-.777c.324-.147.633-.323.904-.525Z"/>
</svg>
<sup><?php echo $magnet->directs ?></sup>
</span>
<?php } ?>
<span class="float-right margin-l-12">
<a rel="nofollow" href="<?php echo sprintf('%s/action.php?target=magnet&toggle=star&magnetId=%s&callback=%s',
WEBSITE_URL,
$magnet->magnetId,
base64_encode(sprintf('%s/search.php?%s#magnet-%s',
WEBSITE_URL,
($request->query ? sprintf('&query=%s', urlencode($request->query)) : false).
($request->page ? sprintf('&page=%s', urlencode($request->page)) : false),
$magnet->magnetId))) ?>" title="<?php echo _('Star') ?>">
<?php if ($magnet->star->status) { ?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-star-fill" viewBox="0 0 16 16">
<path d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.282.95l-3.522 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z"/>
</svg>
<?php } else { ?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-star" viewBox="0 0 16 16">
<path d="M2.866 14.85c-.078.444.36.791.746.593l4.39-2.256 4.389 2.256c.386.198.824-.149.746-.592l-.83-4.73 3.522-3.356c.33-.314.16-.888-.282-.95l-4.898-.696L8.465.792a.513.513 0 0 0-.927 0L5.354 5.12l-4.898.696c-.441.062-.612.636-.283.95l3.523 3.356-.83 4.73zm4.905-2.767-3.686 1.894.694-3.957a.565.565 0 0 0-.163-.505L1.71 6.745l4.052-.576a.525.525 0 0 0 .393-.288L8 2.223l1.847 3.658a.525.525 0 0 0 .393.288l4.052.575-2.906 2.77a.565.565 0 0 0-.163.506l.694 3.957-3.686-1.894a.503.503 0 0 0-.461 0z"/>
</svg>
<?php } ?>
</a>
<sup><?php echo $magnet->star->total ?></sup>
</span>
<?php if ($magnet->comments) { ?>
<span class="float-right margin-l-12">
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/magnet.php?magnetId=<?php echo $magnet->magnetId ?>#comment" title="<?php echo _('Comment') ?>">
<?php if ($magnet->comment->status) { ?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chat-fill" viewBox="0 0 16 16">
<path d="M8 15c4.418 0 8-3.134 8-7s-3.582-7-8-7-8 3.134-8 7c0 1.76.743 3.37 1.97 4.6-.097 1.016-.417 2.13-.771 2.966-.079.186.074.394.273.362 2.256-.37 3.597-.938 4.18-1.234A9.06 9.06 0 0 0 8 15z"/>
</svg>
<?php } else { ?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chat" viewBox="0 0 16 16">
<path d="M2.678 11.894a1 1 0 0 1 .287.801 10.97 10.97 0 0 1-.398 2c1.395-.323 2.247-.697 2.634-.893a1 1 0 0 1 .71-.074A8.06 8.06 0 0 0 8 14c3.996 0 7-2.807 7-6 0-3.192-3.004-6-7-6S1 4.808 1 8c0 1.468.617 2.83 1.678 3.894zm-.493 3.905a21.682 21.682 0 0 1-.713.129c-.2.032-.352-.176-.273-.362a9.68 9.68 0 0 0 .244-.637l.003-.01c.248-.72.45-1.548.524-2.319C.743 11.37 0 9.76 0 8c0-3.866 3.582-7 8-7s8 3.134 8 7-3.582 7-8 7a9.06 9.06 0 0 1-2.347-.306c-.52.263-1.639.742-3.468 1.105z"/>
</svg>
<?php } ?>
</a>
<sup><?php echo $magnet->comment->total ?></sup>
</span>
<?php } ?>
<span class="float-right margin-l-12">
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/download.php?magnetId=<?php echo $magnet->magnetId ?>" title="<?php echo _('Download') ?>">
<?php if ($magnet->download->status) { ?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down-circle-fill" viewBox="0 0 16 16">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.5 4.5a.5.5 0 0 0-1 0v5.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V4.5z"/>
</svg>
<?php } else { ?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down-circle" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M1 8a7 7 0 1 0 14 0A7 7 0 0 0 1 8zm15 0A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.5 4.5a.5.5 0 0 0-1 0v5.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V4.5z"/>
</svg>
<?php } ?>
</a>
<sup><?php echo $magnet->download->total ?></sup>
</span>
</div>
</div>

15
src/app/view/theme/default/module/pagination.phtml

@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
<div class="row">
<div class="column width-100 text-right">
<?php echo sprintf(_('page %s / %s'), $pagination->page, $pagination->total) ?>
<?php if ($pagination->back) { ?>
<a class="button margin-l-8" rel="nofollow" href="<?php echo $pagination->back ?>">
<?php echo _('back') ?>
</a>
<?php } ?>
<?php if ($pagination->next) { ?>
<a class="button margin-l-4" rel="nofollow" href="<?php echo $pagination->next ?>">
<?php echo _('next') ?>
</a>
<?php } ?>
</div>
</div>

4
src/app/view/theme/default/module/search.phtml

@ -0,0 +1,4 @@ @@ -0,0 +1,4 @@
<form class="margin-t-8" name="search" method="get" action="search">
<input type="text" name="query" value="<?php echo $query ?>" placeholder="<?php echo _('search or submit magnet link') ?>" />
<input type="submit" value="<?php echo _('submit') ?>" />
</form>

24
src/app/view/theme/default/response.phtml

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<?php $appControllerModuleHead->render() ?>
<body>
<?php $appControllerModuleHeader->render() ?>
<main>
<div class="container">
<div class="row">
<div class="column width-100">
<div class="padding-16 margin-y-8 border-radius-3 background-color-night text-center">
<h1 class="margin-b-8">
<?php echo $h1 ?>
</h1>
<div>
<?php echo $text ?>
</div>
</div>
</div>
</div>
</div>
</main>
<?php $appControllerModuleFooter->render() ?>
</body>
</html>

35
src/app/view/theme/default/submit.phtml

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
<!DOCTYPE html>
<html>
<?php $appControllerModuleHead->render() ?>
<body>
<?php $appControllerModuleHeader->render() ?>
<main>
<div class="container">
<div class="row">
<div class="column width-100">
<?php $appControllerModuleProfile->render() ?>
<div class="padding-16 margin-y-8 border-radius-3 background-color-night">
<div class="margin-b-24 padding-b-16 border-bottom-default">
<h2><?php echo _('Submit') ?></h2>
</div>
<form class="margin-t-8" name="search" method="post" action="submit">
<div class="margin-b-16">
<label class="margin-b-16 display-block" for="magnet"><?php echo _('Magnet URL') ?></label>
<textarea class="width-100" name="magnet" id="magnet" placeholder="<?php echo _('magnet: ...') ?>"></textarea>
</div>
<div class="margin-b-16">
<label class="margin-b-16 display-block" for="torrent"><?php echo _('Torrent file') ?></label>
<input class="width-100" type="file" name="torrent" id="torrent" value="" />
</div>
<div class="text-right">
<input type="submit" value="<?php echo _('submit') ?>" />
</div>
</form>
</div>
</div>
</div>
</div>
</main>
<?php $appControllerModuleFooter->render() ?>
</body>
</html>

39
src/app/view/theme/default/welcome.phtml

@ -0,0 +1,39 @@ @@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<?php $appControllerModuleHead->render() ?>
<body>
<?php $appControllerModuleHeader->render() ?>
<main>
<div class="container">
<div class="row">
<div class="column width-100">
<div class="padding-16 margin-y-8 border-radius-3 background-color-night text-center">
<div class="margin-b-24 padding-b-16 border-bottom-default">
<h1 class=""><?php echo _('Welcome, stranger!') ?></h1>
</div>
<p class="margin-b-8"><?php echo _('YGGtracker uses Yggdrasil address to identify users without registration') ?></p>
<p class="margin-b-16"><?php echo _('address below could be shared with independent nodes to allow you manage own content everywhere') ?></p>
<h2 class="margin-b-16"><?php echo $user->address ?></h2>
<form name="public" action="welcome" method="post">
<div class="margin-b-16">
<label class="text-color-green margin-y-8 margin-x-4" for="public-1">
<input type="radio" id="public-1" name="public" value="1" checked="checked" />
<?php echo _('Allow address distribution') ?>
</label>
<label class="text-color-pink margin-y-8 margin-x-4" for="public-0">
<input type="radio" id="public-0" name="public" value="0" />
<?php echo _('Keep activity local') ?>
</label>
</div>
<div class="text-center">
<input type="submit" value="<?php echo _('confirm') ?>" />
</div>
</form>
</div>
</div>
</div>
</div>
</main>
<?php $appControllerModuleFooter->render() ?>
</body>
</html>

102
src/config/bootstrap.php

@ -38,50 +38,90 @@ if (!file_exists(__DIR__ . '/env.' . PHP_ENV . '.php')) @@ -38,50 +38,90 @@ if (!file_exists(__DIR__ . '/env.' . PHP_ENV . '.php'))
// Load environment
require_once __DIR__ . '/env.' . PHP_ENV . '.php';
// Local internal dependencies
require_once __DIR__ . '/../library/database.php';
require_once __DIR__ . '/../library/sphinx.php';
require_once __DIR__ . '/../library/scrapeer.php';
require_once __DIR__ . '/../library/time.php';
require_once __DIR__ . '/../library/curl.php';
require_once __DIR__ . '/../library/valid.php';
require_once __DIR__ . '/../library/filter.php';
// Route
parse_str($_SERVER['QUERY_STRING'], $request);
// Vendors autoload
require_once __DIR__ . '/../../vendor/autoload.php';
if (isset($request['_route_']))
{
switch ($request['_route_'])
{
case 'stars':
// Connect database
try {
require_once(__DIR__ . '/../app/controller/stars.php');
$db = new Database(DB_HOST, DB_PORT, DB_NAME, DB_USERNAME, DB_PASSWORD);
$controller = new AppControllerStars();
} catch (Exception $e) {
break;
var_dump($e);
case 'views':
exit;
}
require_once(__DIR__ . '/../app/controller/views.php');
// Connect Sphinx
try {
$controller = new AppControllerViews();
$sphinx = new Sphinx(SPHINX_HOST, SPHINX_PORT);
break;
} catch(Exception $e) {
case 'downloads':
var_dump($e);
require_once(__DIR__ . '/../app/controller/downloads.php');
exit;
}
$controller = new AppControllerDownloads();
break;
case 'comments':
require_once(__DIR__ . '/../app/controller/comments.php');
$controller = new AppControllerComments();
break;
case 'editions':
require_once(__DIR__ . '/../app/controller/editions.php');
$controller = new AppControllerEditions();
break;
// Connect memcached
try {
case 'welcome':
$memory = new Yggverse\Cache\Memory(MEMCACHED_HOST, MEMCACHED_PORT, MEMCACHED_NAMESPACE, MEMCACHED_TIMEOUT + time());
require_once(__DIR__ . '/../app/controller/welcome.php');
} catch(Exception $e) {
$controller = new AppControllerWelcome();
var_dump($e);
break;
case 'submit':
require_once(__DIR__ . '/../app/controller/submit.php');
$controller = new AppControllerSubmit();
break;
default:
require_once(__DIR__ . '/../app/controller/response.php');
$controller = new AppControllerResponse(
sprintf(
_('404 - Not found - %s'),
WEBSITE_NAME
),
_('404'),
_('Page not found'),
404
);
}
}
else
{
require_once(__DIR__ . '/../app/controller/index.php');
$controller = new AppControllerIndex();
}
exit;
}
$controller->render();

77
src/public/assets/theme/default/css/framework.css

@ -32,22 +32,46 @@ @@ -32,22 +32,46 @@
text-align: right;
}
.text-color-green {
.text-color-green,
a.text-color-green,
a.text-color-green:active,
a.text-color-green:visited,
a.text-color-green:hover {
color: #96d9a1;
}
.text-color-red {
.text-color-red,
a.text-color-red,
a.text-color-red:active,
a.text-color-red:visited,
a.text-color-red:hover {
color: #d77575;
}
.text-color-pink {
.text-color-pink,
a.text-color-pink,
a.text-color-pink:active,
a.text-color-pink:visited,
a.text-color-pink:hover {
color: #b55cab;
}
.text-color-default {
.text-color-default,
a.text-color-default,
a.text-color-default:active,
a.text-color-default:visited,
a.text-color-default:hover {
color: #ccc;
}
.text-color-white,
a.text-color-white,
a.text-color-white:active,
a.text-color-white:visited,
a.text-color-white:hover {
color: #fff;
}
/*
.text-color-pink {
color: #a44399;
@ -67,7 +91,11 @@ @@ -67,7 +91,11 @@
border-radius: 3px;
}
.label-green {
.label-green,
a.label-green,
a.label-green:active,
a.label-green:visited,
a.label-green:hover {
color: #fff;
background-color: #65916d;
}
@ -76,6 +104,10 @@ @@ -76,6 +104,10 @@
position: relative;
}
.position-fixed {
position: fixed;
}
.top--2 {
top: -2px;
}
@ -120,11 +152,17 @@ @@ -120,11 +152,17 @@
background-color: #34384f;
}
/*
.background-color-hover-night-light:hover {
background-color: #363a51;
.background-color-green {
background-color: #65916d;
}
.background-color-hover-night-light:hover,
a.background-color-hover-night-light:hover,
a:active.background-color-hover-night-light:hover,
a:visited.background-color-hover-night-light:hover {
/*color: #fff;*/
background-color: #3d4159;
}
*/
.background-color-red {
background-color: #9b4a4a;
@ -186,6 +224,11 @@ @@ -186,6 +224,11 @@
padding-right: 8px;
}
.padding-y-6 {
padding-top: 6px;
padding-bottom: 6px;
}
.padding-8 {
padding: 8px;
}
@ -254,6 +297,10 @@ @@ -254,6 +297,10 @@
margin-left: 12px;
}
.margin-l--176 {
margin-left: -176px;
}
.margin-y-8 {
margin-top: 8px;
margin-bottom: 8px;
@ -319,10 +366,22 @@ @@ -319,10 +366,22 @@
width: 50%;
}
.width-20 {
width: 20%;
}
.width-80 {
width: 80%;
}
.width-13px {
width: 13px;
}
.width-160-px {
width: 160px;
}
@media (max-width: 1220px) {
.width-tablet-100 {

303
src/public/import.php

@ -1,303 +0,0 @@ @@ -1,303 +0,0 @@
<?php
// Bootstrap
require_once __DIR__ . '/../config/bootstrap.php';
// Define response
$response = (object)
[
'success' => true,
'message' => _('Internal server error'),
];
// Yggdrasil connections only
if (!Valid::host($_SERVER['REMOTE_ADDR']))
{
$response->success = false;
$response->message = _('Yggdrasil connection required for this action');
}
// Init session
else if (!$userId = $db->initUserId($_SERVER['REMOTE_ADDR'], USER_DEFAULT_APPROVED, time()))
{
$response->success = false;
$response->message = _('Could not init user session');
}
// Init user
else if (!$user = $db->getUser($userId))
{
$response->success = false;
$response->message = _('Could not get user session');
}
// On first visit, redirect user to the welcome page with access level question
else if (is_null($user->public))
{
header(
sprintf('Location: %s/welcome.php', WEBSITE_URL)
);
}
// Import form magnet link request
else if (!empty($_POST['magnet']))
{
// Validate magnet
if (!$magnet = Yggverse\Parser\Magnet::parse($_POST['magnet']))
{
$response->success = false;
$response->message = _('Could not parse magnet link');
}
// Request valid
else
{
// Begin magnet registration
try
{
$db->beginTransaction();
// Init magnet
if ($magnetId = $db->addMagnet( $user->userId,
$magnet->xl,
$magnet->dn,
'', // @TODO deprecated, remove
MAGNET_DEFAULT_PUBLIC,
MAGNET_DEFAULT_COMMENTS,
MAGNET_DEFAULT_SENSITIVE,
$user->approved ? true : MAGNET_DEFAULT_APPROVED,
time()))
{
foreach ($magnet as $key => $value)
{
switch ($key)
{
case 'xt':
foreach ($value as $xt)
{
if (Yggverse\Parser\Magnet::isXTv1($xt))
{
$db->addMagnetToInfoHash(
$magnetId,
$db->initInfoHashId(
Yggverse\Parser\Magnet::filterInfoHash($xt), 1
)
);
}
if (Yggverse\Parser\Magnet::isXTv2($xt))
{
$db->addMagnetToInfoHash(
$magnetId,
$db->initInfoHashId(
Yggverse\Parser\Magnet::filterInfoHash($xt), 2
)
);
}
}
break;
case 'tr':
foreach ($value as $tr)
{
if (Valid::url($tr))
{
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)
)
);
}
}
}
break;
case 'ws':
foreach ($value as $ws)
{
// @TODO
}
break;
case 'as':
foreach ($value as $as)
{
if (Valid::url($as))
{
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)
)
);
}
}
}
break;
case 'xs':
foreach ($value as $xs)
{
if (Valid::url($xs))
{
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)
)
);
}
}
}
break;
case 'mt':
foreach ($value as $mt)
{
// @TODO
}
break;
case 'x.pe':
foreach ($value as $xPe)
{
// @TODO
}
break;
case 'kt':
foreach ($value as $kt)
{
$db->initMagnetToKeywordTopicId(
$magnetId,
$db->initKeywordTopicId(trim(mb_strtolower(strip_tags(html_entity_decode($kt)))))
);
}
break;
}
}
$db->commit();
}
}
catch (Exception $error)
{
$response->success = false;
$response->message = sprintf(
_('Internal server error: %s'),
print_r($error, true)
);
$db->rollBack();
}
}
// Redirect to edit page on success
if ($response->success)
{
header(sprintf('Location: %s/edit.php?magnetId=%s', trim(WEBSITE_URL, '/'), $magnetId));
}
}
// Import form torrent file request
else if (!empty($_FILE['torrent']))
{
// @TODO
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" type="text/css" href="<?php echo WEBSITE_URL ?>/assets/theme/default/css/common.css?<?php echo WEBSITE_CSS_VERSION ?>" />
<link rel="stylesheet" type="text/css" href="<?php echo WEBSITE_URL ?>/assets/theme/default/css/framework.css?<?php echo WEBSITE_CSS_VERSION ?>" />
<title>
<?php echo sprintf(_('Add - %s'), WEBSITE_NAME) ?>
</title>
<meta name="robots" content="noindex,nofollow"/>
<meta name="author" content="YGGtracker" />
<meta charset="UTF-8" />
</head>
<body>
<header>
<div class="container">
<div class="row margin-t-8 text-center">
<a class="logo" href="<?php echo WEBSITE_URL ?>"><?php echo str_replace('YGG', '<span>YGG</span>', WEBSITE_NAME) ?></a>
<form class="margin-t-8" name="search" method="get" action="<?php echo WEBSITE_URL ?>/index.php">
<input type="text" name="query" value="" placeholder="<?php echo _('search or submit magnet link') ?>" />
<input type="submit" value="<?php echo _('submit') ?>" />
</form>
</div>
</div>
</header>
<main>
<div class="container">
<div class="row">
<div class="column width-100">
<div class="padding-16 margin-y-8 border-radius-3 background-color-night">
<?php if ($response->success) { ?>
<div class="margin-b-24 padding-b-16 border-bottom-default">
<h2><?php echo _('Import') ?></h2>
</div>
<form class="margin-t-8" name="search" method="post" action="<?php echo WEBSITE_URL ?>/import.php">
<div class="margin-b-16">
<label class="margin-b-16 display-block" for="magnet"><?php echo _('Magnet URL') ?></label>
<textarea class="width-100" name="magnet" id="magnet" placeholder="<?php echo _('magnet: ...') ?>"></textarea>
</div>
<div class="margin-b-16">
<label class="margin-b-16 display-block" for="torrent"><?php echo _('Torrent file') ?></label>
<input class="width-100" type="file" name="torrent" id="torrent" value="" />
</div>
<div class="text-right">
<input type="submit" value="<?php echo _('import') ?>" />
</div>
</form>
<?php } else { ?>
<div class="text-center">
<?php echo $response->message ?>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
</main>
<footer>
<div class="container">
<div class="row">
<div class="column width-100 text-center margin-y-8">
<?php foreach (json_decode(file_get_contents(__DIR__ . '/../config/trackers.json')) as $i => $tracker) { ?>
<?php if (!empty($tracker->announce) && !empty($tracker->stats)) { ?>
<a href="<?php echo $tracker->announce ?>"><?php echo sprintf('Tracker %s', $i + 1) ?></a>
/
<a href="<?php echo $tracker->stats ?>"><?php echo _('Stats') ?></a>
|
<?php } ?>
<?php } ?>
<a href="<?php echo WEBSITE_URL ?>/faq.php"><?php echo _('F.A.Q') ?></a>
|
<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_EXPORT_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>
</div>
</div>
</footer>
</body>
</html>

431
src/public/index.php

@ -1,431 +1,4 @@ @@ -1,431 +1,4 @@
<?php
// Bootstrap dependencies
require_once __DIR__ . '/../config/bootstrap.php';
// Define variables
$request = (object)
[
'query' => 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 (!Valid::host($_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');
}
// On first visit, redirect user to the welcome page with access level question
else if (is_null($user->public) && !isset($_GET['rss']))
{
header(
sprintf('Location: %s/welcome.php', WEBSITE_URL)
);
}
// 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, urlencode($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));
// Keywords
$keywords = [];
foreach ($db->findKeywordTopicByMagnetId($magnet->magnetId) as $keyword)
{
$keywords[] = $db->getKeywordTopic($keyword->keywordTopicId)->value;
}
$response->magnets[] = (object)
[
'magnetId' => $magnet->magnetId,
'title' => $magnet->title ? htmlentities($magnet->title) : ($magnet->dn ? htmlentities($magnet->dn): false),
'preview' => $magnet->preview ? nl2br(
htmlentities(
$magnet->preview
)
) : 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->findMagnetCommentsTotalByMagnetId($magnet->magnetId),
'status' => $db->findMagnetCommentsTotal($magnet->magnetId, $userId),
],
'download' => (object)
[
'total' => $db->findMagnetDownloadsTotalByMagnetId($magnet->magnetId),
'status' => $db->findMagnetDownloadsTotal($magnet->magnetId, $userId),
],
'star' => (object)
[
'total' => $db->findMagnetStarsTotalByMagnetId($magnet->magnetId, true),
'status' => $db->findLastMagnetStarValue($magnet->magnetId, $userId),
],
'access' => (object)
[
'read' => $accessRead,
'edit' => $accessEdit,
],
'seeders' => $db->getMagnetToAddressTrackerSeedersSumByMagnetId($magnet->magnetId),
'completed' => $db->getMagnetToAddressTrackerCompletedSumByMagnetId($magnet->magnetId),
'leechers' => $db->getMagnetToAddressTrackerLeechersSumByMagnetId($magnet->magnetId),
'directs' => $db->getMagnetToAcceptableSourceTotalByMagnetId($magnet->magnetId)
];
}
}
}
if (isset($_GET['rss']) && $response->success) { ?><?php
header('Content-type: text/xml;charset=UTF-8');
echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
<atom:link href="<?php echo WEBSITE_URL ?>/index.php<?php echo $request->query ? sprintf('?query=%s', urlencode($request->query)) : false ?>" rel="self" type="application/rss+xml"></atom:link>
<title><?php echo !empty($request->query) ? sprintf(_('%s - Search - %s'), htmlspecialchars($request->query, ENT_QUOTES, 'UTF-8'), WEBSITE_NAME)
: WEBSITE_NAME ?></title>
<description><?php echo _('BitTorrent Registry for Yggdrasil') ?></description>
<link><?php echo sprintf('%s/index.php%s', WEBSITE_URL, $request->query ? sprintf('?query=%s', urlencode($request->query)) : false) ?></link>
<?php foreach ($response->magnets as $magnet) { ?>
<?php if ($magnet->access->read) { ?>
<item>
<title><?php echo htmlspecialchars($magnet->title, ENT_QUOTES, 'UTF-8') ?></title>
<description><?php echo htmlspecialchars(strip_tags($magnet->preview), ENT_QUOTES, 'UTF-8') ?></description>
<guid><?php echo sprintf('%s/magnet.php?magnetId=%s', WEBSITE_URL, $magnet->magnetId) ?></guid>
<link><?php echo sprintf('%s/magnet.php?magnetId=%s', WEBSITE_URL, $magnet->magnetId) ?></link>
</item>
<?php } ?>
<?php } ?>
</channel>
</rss>
<?php } else { ?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" type="text/css" href="<?php echo WEBSITE_URL ?>/assets/theme/default/css/common.css?<?php echo WEBSITE_CSS_VERSION ?>" />
<link rel="stylesheet" type="text/css" href="<?php echo WEBSITE_URL ?>/assets/theme/default/css/framework.css?<?php echo WEBSITE_CSS_VERSION ?>" />
<title>
<?php echo !empty($request->query) ? sprintf(_('%s - Search - %s'), htmlspecialchars($request->query, ENT_QUOTES, 'UTF-8'), WEBSITE_NAME)
: sprintf(_('%s - BitTorrent Registry for Yggdrasil'), WEBSITE_NAME) ?>
</title>
<meta name="description" content="<?php echo _('BitTorrent Registry for Yggdrasil') ?>" />
<meta name="keywords" content="yggdrasil, yggverse, yggtracker, bittorrent, magnet, catalog" />
<meta name="author" content="YGGtracker" />
<meta charset="UTF-8" />
</head>
<body>
<header>
<div class="container">
<div class="row margin-t-8 text-center">
<a class="logo" href="<?php echo WEBSITE_URL ?>"><?php echo str_replace('YGG', '<span>YGG</span>', WEBSITE_NAME) ?></a>
<form class="margin-t-8" name="search" method="get" action="<?php echo WEBSITE_URL ?>/index.php">
<input type="text" name="query" value="<?php echo htmlentities($request->query) ?>" placeholder="<?php echo _('search or submit magnet link') ?>" />
<input type="submit" value="<?php echo _('submit') ?>" />
</form>
</div>
</div>
</header>
<main>
<div class="container">
<div class="row">
<div class="column width-100">
<?php if ($response->success) { ?>
<?php if ($response->magnets) { ?>
<?php foreach ($response->magnets as $magnet) { ?>
<?php if ($magnet->access->read) { ?>
<a name="magnet-<?php echo $magnet->magnetId ?>"></a>
<div class="margin-y-8
border-radius-3
background-color-night
<?php echo !$magnet->public || !$magnet->approved ? 'opacity-06 opacity-hover-1' : false ?>">
<div class="padding-16 <?php echo $magnet->sensitive ? 'blur-2 blur-hover-0' : false ?>">
<a href="<?php echo sprintf('%s/magnet.php?magnetId=%s', WEBSITE_URL, $magnet->magnetId) ?>">
<h2 class="margin-b-8"><?php echo $magnet->title ?></h2>
<?php if ($magnet->leechers && !$magnet->seeders) { ?>
<span class="label label-green margin-x-4 font-size-10 position-relative top--2 cursor-default"
title="<?php echo _('Active leechers waiting for seeds') ?>">
<?php echo _('wanted') ?>
</span>
<?php } ?>
</a>
<div class="float-right opacity-0 parent-hover-opacity-09">
<?php if (!$magnet->public) { ?>
<span class="margin-l-8" title="<?php echo _('Private') ?>">
<svg class="width-13px" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-eye-slash-fill" viewBox="0 0 16 16">
<path d="m10.79 12.912-1.614-1.615a3.5 3.5 0 0 1-4.474-4.474l-2.06-2.06C.938 6.278 0 8 0 8s3 5.5 8 5.5a7.029 7.029 0 0 0 2.79-.588zM5.21 3.088A7.028 7.028 0 0 1 8 2.5c5 0 8 5.5 8 5.5s-.939 1.721-2.641 3.238l-2.062-2.062a3.5 3.5 0 0 0-4.474-4.474L5.21 3.089z"/>
<path d="M5.525 7.646a2.5 2.5 0 0 0 2.829 2.829l-2.83-2.829zm4.95.708-2.829-2.83a2.5 2.5 0 0 1 2.829 2.829zm3.171 6-12-12 .708-.708 12 12-.708.708z"/>
</svg>
</span>
<?php } ?>
<?php if (!$magnet->approved) { ?>
<span class="margin-l-8" title="<?php echo _('Waiting for approve') ?>">
<svg class="width-13px" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-hourglass-split" viewBox="0 0 16 16">
<path d="M2.5 15a.5.5 0 1 1 0-1h1v-1a4.5 4.5 0 0 1 2.557-4.06c.29-.139.443-.377.443-.59v-.7c0-.213-.154-.451-.443-.59A4.5 4.5 0 0 1 3.5 3V2h-1a.5.5 0 0 1 0-1h11a.5.5 0 0 1 0 1h-1v1a4.5 4.5 0 0 1-2.557 4.06c-.29.139-.443.377-.443.59v.7c0 .213.154.451.443.59A4.5 4.5 0 0 1 12.5 13v1h1a.5.5 0 0 1 0 1h-11zm2-13v1c0 .537.12 1.045.337 1.5h6.326c.216-.455.337-.963.337-1.5V2h-7zm3 6.35c0 .701-.478 1.236-1.011 1.492A3.5 3.5 0 0 0 4.5 13s.866-1.299 3-1.48V8.35zm1 0v3.17c2.134.181 3 1.48 3 1.48a3.5 3.5 0 0 0-1.989-3.158C8.978 9.586 8.5 9.052 8.5 8.351z"/>
</svg>
</span>
<?php } ?>
<?php if ($magnet->access->edit) { ?>
<a class="text-color-green margin-l-12" href="<?php echo WEBSITE_URL ?>/edit.php?magnetId=<?php echo $magnet->magnetId ?>" title="<?php echo _('Edit') ?>">
<svg class="text-color-green" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-pencil-square" viewBox="0 0 16 16">
<path d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z"/>
<path fill-rule="evenodd" d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z"/>
</svg>
</a>
<?php } ?>
</div>
<?php if ($magnet->preview) { ?>
<div class="margin-y-8"><?php echo $magnet->preview ?></div>
<?php } ?>
<?php if ($magnet->keywords) { ?>
<div class="margin-y-8">
<?php foreach ($magnet->keywords as $keyword) { ?>
<small>
<a href="<?php echo WEBSITE_URL ?>/index.php?query=<?php echo urlencode($keyword) ?>">#<?php echo htmlentities($keyword) ?></a>
</small>
<?php } ?>
</div>
<?php } ?>
<div class="width-100 padding-y-4"></div>
<!-- DOUBTS
<span class="margin-t-8 margin-r-8 cursor-default" title="<?php echo $magnet->timeUpdated ? _('Updated') : _('Added') ?>">
<svg class="width-13px" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-clock" viewBox="0 0 16 16">
<path d="M8 3.5a.5.5 0 0 0-1 0V9a.5.5 0 0 0 .252.434l3.5 2a.5.5 0 0 0 .496-.868L8 8.71V3.5z"/>
<path d="M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16zm7-8A7 7 0 1 1 1 8a7 7 0 0 1 14 0z"/>
</svg>
<sup><?php echo $magnet->timeUpdated ? $magnet->timeUpdated : $magnet->timeAdded ?></sup>
</span>
-->
<span class="margin-t-8 margin-r-8 cursor-default">
<sup>
<?php echo $magnet->timeUpdated ? _('Updated') : _('Added') ?>
<?php echo $magnet->timeUpdated ? $magnet->timeUpdated : $magnet->timeAdded ?>
</sup>
</span>
<span class="margin-t-8 margin-r-8 cursor-default opacity-0 parent-hover-opacity-09" title="<?php echo _('Seeds') ?>">
<svg class="width-13px" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-up" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 15a.5.5 0 0 0 .5-.5V2.707l3.146 3.147a.5.5 0 0 0 .708-.708l-4-4a.5.5 0 0 0-.708 0l-4 4a.5.5 0 1 0 .708.708L7.5 2.707V14.5a.5.5 0 0 0 .5.5z"/>
</svg>
<sup><?php echo $magnet->seeders ?></sup>
</span>
<span class="margin-t-8 margin-r-8 cursor-default opacity-0 parent-hover-opacity-09" title="<?php echo _('Peers') ?>">
<svg class="width-13px" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M8 1a.5.5 0 0 1 .5.5v11.793l3.146-3.147a.5.5 0 0 1 .708.708l-4 4a.5.5 0 0 1-.708 0l-4-4a.5.5 0 0 1 .708-.708L7.5 13.293V1.5A.5.5 0 0 1 8 1z"/>
</svg>
<sup><?php echo $magnet->completed ?></sup>
</span>
<span class="margin-t-8 margin-r-8 cursor-default opacity-0 parent-hover-opacity-09" title="<?php echo _('Leechers') ?>">
<svg class="width-13px" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-cup-hot" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M.5 6a.5.5 0 0 0-.488.608l1.652 7.434A2.5 2.5 0 0 0 4.104 16h5.792a2.5 2.5 0 0 0 2.44-1.958l.131-.59a3 3 0 0 0 1.3-5.854l.221-.99A.5.5 0 0 0 13.5 6H.5ZM13 12.5a2.01 2.01 0 0 1-.316-.025l.867-3.898A2.001 2.001 0 0 1 13 12.5ZM2.64 13.825 1.123 7h11.754l-1.517 6.825A1.5 1.5 0 0 1 9.896 15H4.104a1.5 1.5 0 0 1-1.464-1.175Z"/>
<path d="m4.4.8-.003.004-.014.019a4.167 4.167 0 0 0-.204.31 2.327 2.327 0 0 0-.141.267c-.026.06-.034.092-.037.103v.004a.593.593 0 0 0 .091.248c.075.133.178.272.308.445l.01.012c.118.158.26.347.37.543.112.2.22.455.22.745 0 .188-.065.368-.119.494a3.31 3.31 0 0 1-.202.388 5.444 5.444 0 0 1-.253.382l-.018.025-.005.008-.002.002A.5.5 0 0 1 3.6 4.2l.003-.004.014-.019a4.149 4.149 0 0 0 .204-.31 2.06 2.06 0 0 0 .141-.267c.026-.06.034-.092.037-.103a.593.593 0 0 0-.09-.252A4.334 4.334 0 0 0 3.6 2.8l-.01-.012a5.099 5.099 0 0 1-.37-.543A1.53 1.53 0 0 1 3 1.5c0-.188.065-.368.119-.494.059-.138.134-.274.202-.388a5.446 5.446 0 0 1 .253-.382l.025-.035A.5.5 0 0 1 4.4.8Zm3 0-.003.004-.014.019a4.167 4.167 0 0 0-.204.31 2.327 2.327 0 0 0-.141.267c-.026.06-.034.092-.037.103v.004a.593.593 0 0 0 .091.248c.075.133.178.272.308.445l.01.012c.118.158.26.347.37.543.112.2.22.455.22.745 0 .188-.065.368-.119.494a3.31 3.31 0 0 1-.202.388 5.444 5.444 0 0 1-.253.382l-.018.025-.005.008-.002.002A.5.5 0 0 1 6.6 4.2l.003-.004.014-.019a4.149 4.149 0 0 0 .204-.31 2.06 2.06 0 0 0 .141-.267c.026-.06.034-.092.037-.103a.593.593 0 0 0-.09-.252A4.334 4.334 0 0 0 6.6 2.8l-.01-.012a5.099 5.099 0 0 1-.37-.543A1.53 1.53 0 0 1 6 1.5c0-.188.065-.368.119-.494.059-.138.134-.274.202-.388a5.446 5.446 0 0 1 .253-.382l.025-.035A.5.5 0 0 1 7.4.8Zm3 0-.003.004-.014.019a4.077 4.077 0 0 0-.204.31 2.337 2.337 0 0 0-.141.267c-.026.06-.034.092-.037.103v.004a.593.593 0 0 0 .091.248c.075.133.178.272.308.445l.01.012c.118.158.26.347.37.543.112.2.22.455.22.745 0 .188-.065.368-.119.494a3.198 3.198 0 0 1-.202.388 5.385 5.385 0 0 1-.252.382l-.019.025-.005.008-.002.002A.5.5 0 0 1 9.6 4.2l.003-.004.014-.019a4.149 4.149 0 0 0 .204-.31 2.06 2.06 0 0 0 .141-.267c.026-.06.034-.092.037-.103a.593.593 0 0 0-.09-.252A4.334 4.334 0 0 0 9.6 2.8l-.01-.012a5.099 5.099 0 0 1-.37-.543A1.53 1.53 0 0 1 9 1.5c0-.188.065-.368.119-.494.059-.138.134-.274.202-.388a5.446 5.446 0 0 1 .253-.382l.025-.035A.5.5 0 0 1 10.4.8Z"/>
</svg>
<sup><?php echo $magnet->leechers ?></sup>
</span>
<?php if ($magnet->directs) { ?>
<span class="margin-t-8 margin-r-8 cursor-default opacity-0 parent-hover-opacity-09" title="<?php echo _('Direct') ?>">
<svg class="width-13px" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-database" viewBox="0 0 16 16">
<path d="M4.318 2.687C5.234 2.271 6.536 2 8 2s2.766.27 3.682.687C12.644 3.125 13 3.627 13 4c0 .374-.356.875-1.318 1.313C10.766 5.729 9.464 6 8 6s-2.766-.27-3.682-.687C3.356 4.875 3 4.373 3 4c0-.374.356-.875 1.318-1.313ZM13 5.698V7c0 .374-.356.875-1.318 1.313C10.766 8.729 9.464 9 8 9s-2.766-.27-3.682-.687C3.356 7.875 3 7.373 3 7V5.698c.271.202.58.378.904.525C4.978 6.711 6.427 7 8 7s3.022-.289 4.096-.777A4.92 4.92 0 0 0 13 5.698ZM14 4c0-1.007-.875-1.755-1.904-2.223C11.022 1.289 9.573 1 8 1s-3.022.289-4.096.777C2.875 2.245 2 2.993 2 4v9c0 1.007.875 1.755 1.904 2.223C4.978 15.71 6.427 16 8 16s3.022-.289 4.096-.777C13.125 14.755 14 14.007 14 13V4Zm-1 4.698V10c0 .374-.356.875-1.318 1.313C10.766 11.729 9.464 12 8 12s-2.766-.27-3.682-.687C3.356 10.875 3 10.373 3 10V8.698c.271.202.58.378.904.525C4.978 9.71 6.427 10 8 10s3.022-.289 4.096-.777A4.92 4.92 0 0 0 13 8.698Zm0 3V13c0 .374-.356.875-1.318 1.313C10.766 14.729 9.464 15 8 15s-2.766-.27-3.682-.687C3.356 13.875 3 13.373 3 13v-1.302c.271.202.58.378.904.525C4.978 12.71 6.427 13 8 13s3.022-.289 4.096-.777c.324-.147.633-.323.904-.525Z"/>
</svg>
<sup><?php echo $magnet->directs ?></sup>
</span>
<?php } ?>
<!-- @TODO doubts
<?php if ($user->public && $magnet->public) { ?>
<span class="margin-t-8 margin-r-8 cursor-default opacity-0 parent-hover-opacity-09" title="<?php echo _('Distributed') ?>">
<svg class="width-13px" xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-check-all" viewBox="0 0 16 16">
<path d="M8.97 4.97a.75.75 0 0 1 1.07 1.05l-3.99 4.99a.75.75 0 0 1-1.08.02L2.324 8.384a.75.75 0 1 1 1.06-1.06l2.094 2.093L8.95 4.992a.252.252 0 0 1 .02-.022zm-.92 5.14.92.92a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 1 0-1.091-1.028L9.477 9.417l-.485-.486-.943 1.179z"/>
</svg>
<a href="<?php echo sprintf('%s/node.php#nodes', WEBSITE_URL) ?>">
<sup><?php echo 2 ?></sup>
</a>
</span>
<?php } ?>
-->
<span class="float-right margin-l-12">
<a rel="nofollow" href="<?php echo sprintf('%s/action.php?target=magnet&toggle=star&magnetId=%s&callback=%s',
WEBSITE_URL,
$magnet->magnetId,
base64_encode(sprintf('%s/index.php?%s#magnet-%s',
WEBSITE_URL,
($request->query ? sprintf('&query=%s', urlencode($request->query)) : false).
($request->page ? sprintf('&page=%s', urlencode($request->page)) : false),
$magnet->magnetId))) ?>" title="<?php echo _('Star') ?>">
<?php if ($magnet->star->status) { ?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-star-fill" viewBox="0 0 16 16">
<path d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.282.95l-3.522 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z"/>
</svg>
<?php } else { ?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-star" viewBox="0 0 16 16">
<path d="M2.866 14.85c-.078.444.36.791.746.593l4.39-2.256 4.389 2.256c.386.198.824-.149.746-.592l-.83-4.73 3.522-3.356c.33-.314.16-.888-.282-.95l-4.898-.696L8.465.792a.513.513 0 0 0-.927 0L5.354 5.12l-4.898.696c-.441.062-.612.636-.283.95l3.523 3.356-.83 4.73zm4.905-2.767-3.686 1.894.694-3.957a.565.565 0 0 0-.163-.505L1.71 6.745l4.052-.576a.525.525 0 0 0 .393-.288L8 2.223l1.847 3.658a.525.525 0 0 0 .393.288l4.052.575-2.906 2.77a.565.565 0 0 0-.163.506l.694 3.957-3.686-1.894a.503.503 0 0 0-.461 0z"/>
</svg>
<?php } ?>
</a>
<sup><?php echo $magnet->star->total ?></sup>
</span>
<?php if ($magnet->comments) { ?>
<span class="float-right margin-l-12">
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/magnet.php?magnetId=<?php echo $magnet->magnetId ?>#comment" title="<?php echo _('Comment') ?>">
<?php if ($magnet->comment->status) { ?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chat-fill" viewBox="0 0 16 16">
<path d="M8 15c4.418 0 8-3.134 8-7s-3.582-7-8-7-8 3.134-8 7c0 1.76.743 3.37 1.97 4.6-.097 1.016-.417 2.13-.771 2.966-.079.186.074.394.273.362 2.256-.37 3.597-.938 4.18-1.234A9.06 9.06 0 0 0 8 15z"/>
</svg>
<?php } else { ?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-chat" viewBox="0 0 16 16">
<path d="M2.678 11.894a1 1 0 0 1 .287.801 10.97 10.97 0 0 1-.398 2c1.395-.323 2.247-.697 2.634-.893a1 1 0 0 1 .71-.074A8.06 8.06 0 0 0 8 14c3.996 0 7-2.807 7-6 0-3.192-3.004-6-7-6S1 4.808 1 8c0 1.468.617 2.83 1.678 3.894zm-.493 3.905a21.682 21.682 0 0 1-.713.129c-.2.032-.352-.176-.273-.362a9.68 9.68 0 0 0 .244-.637l.003-.01c.248-.72.45-1.548.524-2.319C.743 11.37 0 9.76 0 8c0-3.866 3.582-7 8-7s8 3.134 8 7-3.582 7-8 7a9.06 9.06 0 0 1-2.347-.306c-.52.263-1.639.742-3.468 1.105z"/>
</svg>
<?php } ?>
</a>
<sup><?php echo $magnet->comment->total ?></sup>
</span>
<?php } ?>
<span class="float-right margin-l-12">
<a rel="nofollow" href="<?php echo WEBSITE_URL ?>/download.php?magnetId=<?php echo $magnet->magnetId ?>" title="<?php echo _('Download') ?>">
<?php if ($magnet->download->status) { ?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down-circle-fill" viewBox="0 0 16 16">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.5 4.5a.5.5 0 0 0-1 0v5.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V4.5z"/>
</svg>
<?php } else { ?>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-down-circle" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M1 8a7 7 0 1 0 14 0A7 7 0 0 0 1 8zm15 0A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM8.5 4.5a.5.5 0 0 0-1 0v5.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V4.5z"/>
</svg>
<?php } ?>
</a>
<sup><?php echo $magnet->download->total ?></sup>
</span>
</div>
</div>
<?php } else { ?>
<!-- DOUBTS
<div class="padding-16 margin-y-8 border-radius-3 background-color-night">
<div><?php echo _('Hidden content') ?></div>
</div>
-->
<?php } ?>
<?php } ?>
<?php } else { ?>
<div class="padding-16 margin-y-8 border-radius-3 background-color-night text-center">
<h2 class="margin-b-8">
<?php echo _('Nothing found') ?>
</h2>
<div class="text-color-night"><?php echo _('* share your magnet links above to change it') ?></div>
</div>
<?php } ?>
<?php } else { ?>
<div class="padding-16 margin-y-8 border-radius-3 background-color-night">
<div class="text-center"><?php echo $response->message ?></div>
</div>
<?php } ?>
</div>
</div>
<?php if ($response->total > WEBSITE_PAGINATION_LIMIT) { ?>
<div class="row">
<div class="column width-100 text-right">
<?php echo sprintf(_('page %s / %s'), $request->page, ceil($response->total / WEBSITE_PAGINATION_LIMIT)) ?>
<?php if ($request->page > 1) { ?>
<a class="button margin-l-8"
rel="nofollow"
href="<?php echo sprintf('%s/index.php?page=%s', WEBSITE_URL,
$request->page - 1,
$request->query ? sprintf('&query=%s', urlencode($request->query)) : false) ?>">
<?php echo _('back') ?>
</a>
<?php } ?>
<?php if ($request->page < ceil($response->total / WEBSITE_PAGINATION_LIMIT)) { ?>
<a class="button margin-l-4"
rel="nofollow"
href="<?php echo sprintf('%s/index.php?page=%s', WEBSITE_URL,
$request->page + 1,
$request->query ? sprintf('&query=%s', urlencode($request->query)) : false) ?>">
<?php echo _('next') ?>
</a>
<?php } ?>
</div>
</div>
<?php } ?>
</div>
</main>
<footer>
<div class="container">
<div class="row">
<div class="column width-100 text-center margin-y-8">
<?php foreach (json_decode(file_get_contents(__DIR__ . '/../config/trackers.json')) as $i => $tracker) { ?>
<?php if (!empty($tracker->announce) && !empty($tracker->stats)) { ?>
<a href="<?php echo $tracker->announce ?>"><?php echo sprintf('Tracker %s', $i + 1) ?></a>
/
<a href="<?php echo $tracker->stats ?>"><?php echo _('Stats') ?></a>
|
<?php } ?>
<?php } ?>
<a href="<?php echo WEBSITE_URL ?>/faq.php"><?php echo _('F.A.Q') ?></a>
|
<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_EXPORT_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>
</div>
</div>
</footer>
</body>
</html>
<?php } ?>
// Bootstrap application
require_once __DIR__ . '/../config/bootstrap.php';

146
src/public/welcome.php

@ -1,146 +0,0 @@ @@ -1,146 +0,0 @@
<?php
// Bootstrap
require_once __DIR__ . '/../config/bootstrap.php';
// Define response
$response = (object)
[
'success' => true,
'message' => _('Internal server error'),
];
// Yggdrasil connections only
if (!Valid::host($_SERVER['REMOTE_ADDR']))
{
$response->success = false;
$response->message = _('Yggdrasil connection required for this action');
}
// Init session
else if (!$userId = $db->initUserId($_SERVER['REMOTE_ADDR'], USER_DEFAULT_APPROVED, time()))
{
$response->success = false;
$response->message = _('Could not init user session');
}
// Init user
else if (!$user = $db->getUser($userId))
{
$response->success = false;
$response->message = _('Could not get user session');
}
// User can change public level once, because by agreement data could be already sent
// Otherwise, local access level could be changed to public on settings page later
// Redirect to website features
else if (!is_null($user->public))
{
header(
sprintf('Location: %s', WEBSITE_URL)
);
}
// Apply answer on form submit
else if (isset($_POST['public']))
{
if ($db->updateUserPublic($user->userId, (bool) $_POST['public'], time()))
{
header(
sprintf('Location: %s', WEBSITE_URL)
);
}
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" type="text/css" href="<?php echo WEBSITE_URL ?>/assets/theme/default/css/common.css?<?php echo WEBSITE_CSS_VERSION ?>" />
<link rel="stylesheet" type="text/css" href="<?php echo WEBSITE_URL ?>/assets/theme/default/css/framework.css?<?php echo WEBSITE_CSS_VERSION ?>" />
<title>
<?php echo sprintf(_('Welcome to %s'), WEBSITE_NAME) ?>
</title>
<meta name="robots" content="noindex,nofollow"/>
<meta name="author" content="YGGtracker" />
<meta charset="UTF-8" />
</head>
<body>
<header>
<div class="container">
<div class="row margin-t-8 text-center">
<a class="logo" href="<?php echo WEBSITE_URL ?>"><?php echo str_replace('YGG', '<span>YGG</span>', WEBSITE_NAME) ?></a>
<form class="margin-t-8" name="search" method="get" action="<?php echo WEBSITE_URL ?>/index.php">
<input type="text" name="query" value="" placeholder="<?php echo _('search or submit magnet link') ?>" />
<input type="submit" value="<?php echo _('submit') ?>" />
</form>
</div>
</div>
</header>
<main>
<div class="container">
<div class="row">
<div class="column width-100">
<div class="padding-16 margin-y-8 border-radius-3 background-color-night">
<?php if ($response->success) { ?>
<div class="text-center">
<div class="margin-b-24 padding-b-16 border-bottom-default">
<h1 class=""><?php echo _('Welcome, stranger!') ?></h1>
</div>
<p class="margin-b-8"><?php echo _('YGGtracker uses Yggdrasil address to identify users without registration') ?></p>
<p class="margin-b-16"><?php echo _('address below could be shared with independent nodes to allow you manage own content everywhere') ?></p>
<h2 class="margin-b-16"><?php echo $user->address ?></h2>
<form name="public" action="<?php echo sprintf('%s/welcome.php', WEBSITE_URL) ?>" method="post">
<div class="margin-b-16">
<label class="text-color-green margin-y-8 margin-x-4" for="public-1">
<input type="radio" id="public-1" name="public" value="1" checked="checked" />
<?php echo _('Allow address distribution') ?>
</label>
<label class="text-color-pink margin-y-8 margin-x-4" for="public-0">
<input type="radio" id="public-0" name="public" value="0" />
<?php echo _('Keep activity local') ?>
</label>
</div>
<div class="text-center">
<input type="submit" value="<?php echo _('confirm') ?>" />
</div>
</form>
</div>
<?php } else { ?>
<div class="text-center"><?php echo $response->message ?></div>
<?php } ?>
</div>
</div>
</div>
</div>
</main>
<footer>
<div class="container">
<div class="row">
<div class="column width-100 text-center margin-y-8">
<?php foreach (json_decode(file_get_contents(__DIR__ . '/../config/trackers.json')) as $i => $tracker) { ?>
<?php if (!empty($tracker->announce) && !empty($tracker->stats)) { ?>
<a href="<?php echo $tracker->announce ?>"><?php echo sprintf('Tracker %s', $i + 1) ?></a>
/
<a href="<?php echo $tracker->stats ?>"><?php echo _('Stats') ?></a>
|
<?php } ?>
<?php } ?>
<a href="<?php echo WEBSITE_URL ?>/faq.php"><?php echo _('F.A.Q') ?></a>
|
<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_EXPORT_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>
</div>
</div>
</footer>
</body>
</html>
Loading…
Cancel
Save