diff --git a/src/app/controller/index.php b/src/app/controller/index.php new file mode 100644 index 0000000..6be1c5b --- /dev/null +++ b/src/app/controller/index.php @@ -0,0 +1,116 @@ +_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'; + } +} \ No newline at end of file diff --git a/src/app/controller/module/footer.php b/src/app/controller/module/footer.php new file mode 100644 index 0000000..d1a1f81 --- /dev/null +++ b/src/app/controller/module/footer.php @@ -0,0 +1,25 @@ +announce) && !empty($tracker->stats)) + { + $response['trackers'][] = [ + 'announce' => $tracker->announce, + 'stats' => $tracker->stats, + ]; + } + } + } + + include __DIR__ . '../../../view/theme/default/module/footer.phtml'; + } +} \ No newline at end of file diff --git a/src/app/controller/module/head.php b/src/app/controller/module/head.php new file mode 100644 index 0000000..781873b --- /dev/null +++ b/src/app/controller/module/head.php @@ -0,0 +1,54 @@ +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'; + } +} \ No newline at end of file diff --git a/src/app/controller/module/header.php b/src/app/controller/module/header.php new file mode 100644 index 0000000..df162b1 --- /dev/null +++ b/src/app/controller/module/header.php @@ -0,0 +1,19 @@ +YGG', + WEBSITE_NAME + ); + + require_once __DIR__ . '/search.php'; + + $appControllerModuleSearch = new AppControllerModuleSearch(); + + include __DIR__ . '../../../view/theme/default/module/header.phtml'; + } +} \ No newline at end of file diff --git a/src/app/controller/module/page.php b/src/app/controller/module/page.php new file mode 100644 index 0000000..036a6e7 --- /dev/null +++ b/src/app/controller/module/page.php @@ -0,0 +1,9 @@ + $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 + } + } +} \ No newline at end of file diff --git a/src/app/controller/module/search.php b/src/app/controller/module/search.php new file mode 100644 index 0000000..cf5ea4a --- /dev/null +++ b/src/app/controller/module/search.php @@ -0,0 +1,11 @@ +_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'; + } +} \ No newline at end of file diff --git a/src/app/controller/submit.php b/src/app/controller/submit.php new file mode 100644 index 0000000..dddf4fc --- /dev/null +++ b/src/app/controller/submit.php @@ -0,0 +1,96 @@ +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'; + } +} \ No newline at end of file diff --git a/src/app/controller/user.php b/src/app/controller/user.php new file mode 100644 index 0000000..ba58cdb --- /dev/null +++ b/src/app/controller/user.php @@ -0,0 +1,152 @@ +_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 + ); + } +} \ No newline at end of file diff --git a/src/app/controller/welcome.php b/src/app/controller/welcome.php new file mode 100644 index 0000000..611be0d --- /dev/null +++ b/src/app/controller/welcome.php @@ -0,0 +1,119 @@ +_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'; + } +} \ No newline at end of file diff --git a/src/library/database.php b/src/app/model/database.php similarity index 96% rename from src/library/database.php rename to src/app/model/database.php index ccb6c0e..ec435cb 100644 --- a/src/library/database.php +++ b/src/app/model/database.php @@ -1,6 +1,6 @@ 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, diff --git a/src/library/sphinx.php b/src/app/model/sphinx.php similarity index 99% rename from src/library/sphinx.php rename to src/app/model/sphinx.php index 6cb15ae..db2f8be 100644 --- a/src/library/sphinx.php +++ b/src/app/model/sphinx.php @@ -1,6 +1,6 @@ + + render() ?> + + render() ?> +
+
+
+
+ render() ?> + + + render($page->pageId) ?> + + render() ?> + +
+

+ +

+
+ +
+
+ +
+
+
+
+ render() ?> + + \ No newline at end of file diff --git a/src/app/view/theme/default/module/footer.phtml b/src/app/view/theme/default/module/footer.phtml new file mode 100644 index 0000000..75aeaf3 --- /dev/null +++ b/src/app/view/theme/default/module/footer.phtml @@ -0,0 +1,27 @@ + + + \ No newline at end of file diff --git a/src/app/view/theme/default/module/head.phtml b/src/app/view/theme/default/module/head.phtml new file mode 100644 index 0000000..70c6452 --- /dev/null +++ b/src/app/view/theme/default/module/head.phtml @@ -0,0 +1,7 @@ + + + <?php echo $title ?> + + + + \ No newline at end of file diff --git a/src/app/view/theme/default/module/header.phtml b/src/app/view/theme/default/module/header.phtml new file mode 100644 index 0000000..1c622e9 --- /dev/null +++ b/src/app/view/theme/default/module/header.phtml @@ -0,0 +1,10 @@ +
+
+
+ + render() ?> +
+
+
\ No newline at end of file diff --git a/src/app/view/theme/default/module/page.phtml b/src/app/view/theme/default/module/page.phtml new file mode 100644 index 0000000..f242004 --- /dev/null +++ b/src/app/view/theme/default/module/page.phtml @@ -0,0 +1,126 @@ + +
+
+ +

+ + + + + +
+
+ + + + + + + + + + + + + +
+ preview) { ?> +
preview ?>
+ + keywords) { ?> +
+ keywords as $keyword) { ?> + + # + + +
+ +
+ + + timeUpdated ? _('Updated') : _('Added') ?> + timeUpdated ? $magnet->timeUpdated : $magnet->timeAdded ?> + + + + + + + seeders ?> + + + + + + completed ?> + + + + + + + leechers ?> + + directs) { ?> + + + + + directs ?> + + + + + star->status) { ?> + + + + + + + + + + star->total ?> + + comments) { ?> + + + comment->status) { ?> + + + + + + + + + + comment->total ?> + + + + + download->status) { ?> + + + + + + + + + + download->total ?> + +
+
\ No newline at end of file diff --git a/src/app/view/theme/default/module/pagination.phtml b/src/app/view/theme/default/module/pagination.phtml new file mode 100644 index 0000000..1f8422a --- /dev/null +++ b/src/app/view/theme/default/module/pagination.phtml @@ -0,0 +1,15 @@ +
+
+ page, $pagination->total) ?> + back) { ?> + + + + + next) { ?> + + + + +
+
\ No newline at end of file diff --git a/src/app/view/theme/default/module/search.phtml b/src/app/view/theme/default/module/search.phtml new file mode 100644 index 0000000..540e606 --- /dev/null +++ b/src/app/view/theme/default/module/search.phtml @@ -0,0 +1,4 @@ +
+ + +
\ No newline at end of file diff --git a/src/app/view/theme/default/response.phtml b/src/app/view/theme/default/response.phtml new file mode 100644 index 0000000..2438208 --- /dev/null +++ b/src/app/view/theme/default/response.phtml @@ -0,0 +1,24 @@ + + + render() ?> + + render() ?> +
+
+
+
+
+

+ +

+
+ +
+
+
+
+
+
+ render() ?> + + \ No newline at end of file diff --git a/src/app/view/theme/default/submit.phtml b/src/app/view/theme/default/submit.phtml new file mode 100644 index 0000000..9b28efa --- /dev/null +++ b/src/app/view/theme/default/submit.phtml @@ -0,0 +1,35 @@ + + + render() ?> + + render() ?> +
+
+
+
+ render() ?> +
+
+

+
+
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+
+
+ render() ?> + + \ No newline at end of file diff --git a/src/app/view/theme/default/welcome.phtml b/src/app/view/theme/default/welcome.phtml new file mode 100644 index 0000000..af9aa03 --- /dev/null +++ b/src/app/view/theme/default/welcome.phtml @@ -0,0 +1,39 @@ + + + render() ?> + + render() ?> +
+
+
+
+
+
+

+
+

+

+

address ?>

+
+
+ + +
+
+ +
+
+
+
+
+
+
+ render() ?> + + \ No newline at end of file diff --git a/src/config/bootstrap.php b/src/config/bootstrap.php index 70679bd..cd88737 100644 --- a/src/config/bootstrap.php +++ b/src/config/bootstrap.php @@ -38,50 +38,90 @@ // 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; -} \ No newline at end of file +$controller->render(); \ No newline at end of file diff --git a/src/public/assets/theme/default/css/framework.css b/src/public/assets/theme/default/css/framework.css index 9b3ebff..4f5968b 100644 --- a/src/public/assets/theme/default/css/framework.css +++ b/src/public/assets/theme/default/css/framework.css @@ -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 @@ 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 @@ position: relative; } +.position-fixed { + position: fixed; +} + .top--2 { top: -2px; } @@ -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 @@ padding-right: 8px; } +.padding-y-6 { + padding-top: 6px; + padding-bottom: 6px; +} + .padding-8 { padding: 8px; } @@ -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 @@ 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 { diff --git a/src/public/import.php b/src/public/import.php deleted file mode 100644 index a233cd9..0000000 --- a/src/public/import.php +++ /dev/null @@ -1,303 +0,0 @@ - - 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 -} - -?> - - - - - - - <?php echo sprintf(_('Add - %s'), WEBSITE_NAME) ?> - - - - - - -
-
- -
-
-
-
-
-
-
- success) { ?> -
-

-
-
-
- - -
-
- - -
-
- -
-
- -
- message ?> -
- -
-
-
-
-
- - - \ No newline at end of file diff --git a/src/public/index.php b/src/public/index.php index 13cf940..6a9b6e3 100644 --- a/src/public/index.php +++ b/src/public/index.php @@ -1,431 +1,4 @@ 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_EOL ?> - - - - <?php echo !empty($request->query) ? sprintf(_('%s - Search - %s'), htmlspecialchars($request->query, ENT_QUOTES, 'UTF-8'), WEBSITE_NAME) - : WEBSITE_NAME ?> - - query ? sprintf('?query=%s', urlencode($request->query)) : false) ?> - magnets as $magnet) { ?> - access->read) { ?> - - <?php echo htmlspecialchars($magnet->title, ENT_QUOTES, 'UTF-8') ?> - preview), ENT_QUOTES, 'UTF-8') ?> - magnetId) ?> - magnetId) ?> - - - - - - - - - - - - - <?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) ?> - - - - - - - -
-
- -
-
-
-
-
-
- success) { ?> - magnets) { ?> - magnets as $magnet) { ?> - access->read) { ?> - -
-
- -

title ?>

- leechers && !$magnet->seeders) { ?> - - - - -
-
- public) { ?> - - - - - - - - approved) { ?> - - - - - - - access->edit) { ?> - - - - - - - -
- preview) { ?> -
preview ?>
- - keywords) { ?> -
- keywords as $keyword) { ?> - - # - - -
- -
- - - - timeUpdated ? _('Updated') : _('Added') ?> - timeUpdated ? $magnet->timeUpdated : $magnet->timeAdded ?> - - - - - - - seeders ?> - - - - - - completed ?> - - - - - - - leechers ?> - - directs) { ?> - - - - - directs ?> - - - - - - star->status) { ?> - - - - - - - - - - star->total ?> - - comments) { ?> - - - comment->status) { ?> - - - - - - - - - - comment->total ?> - - - - - download->status) { ?> - - - - - - - - - - download->total ?> - -
-
- - - - - -
-

- -

-
-
- - -
-
message ?>
-
- -
-
- total > WEBSITE_PAGINATION_LIMIT) { ?> -
-
- page, ceil($response->total / WEBSITE_PAGINATION_LIMIT)) ?> - page > 1) { ?> - - - - - page < ceil($response->total / WEBSITE_PAGINATION_LIMIT)) { ?> - - - - -
-
- -
-
- - - - \ No newline at end of file +// Bootstrap application +require_once __DIR__ . '/../config/bootstrap.php'; \ No newline at end of file diff --git a/src/public/welcome.php b/src/public/welcome.php deleted file mode 100644 index aaac011..0000000 --- a/src/public/welcome.php +++ /dev/null @@ -1,146 +0,0 @@ - - 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) - ); - } -} - -?> - - - - - - - <?php echo sprintf(_('Welcome to %s'), WEBSITE_NAME) ?> - - - - - - -
-
- -
-
-
-
-
-
-
- success) { ?> -
-
-

-
-

-

-

address ?>

-
-
- - -
-
- -
-
-
- -
message ?>
- -
-
-
-
-
- - - \ No newline at end of file