diff --git a/src/app/controller/index.php b/src/app/controller/index.php index 819a532..00e8c0f 100644 --- a/src/app/controller/index.php +++ b/src/app/controller/index.php @@ -2,57 +2,15 @@ class AppControllerIndex { - private $_db; - private $_sphinx; - private $_memory; + private $_user; 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; - } + require_once __DIR__ . '/user.php'; + + $this->_user = new AppControllerUser( + $_SERVER['REMOTE_ADDR'] + ); } public function render() @@ -68,16 +26,16 @@ class AppControllerIndex require_once __DIR__ . '/module/head.php'; $appControllerModuleHead = new AppControllerModuleHead( - WEBSITE_URL, + Environment::config('website')->url, $page > 1 ? sprintf( _('Page %s - BitTorrent Registry for Yggdrasil - %s'), $page, - WEBSITE_NAME + Environment::config('website')->name ) : sprintf( _('%s - BitTorrent Registry for Yggdrasil'), - WEBSITE_NAME + Environment::config('website')->name ), [ [ @@ -101,7 +59,9 @@ class AppControllerIndex require_once __DIR__ . '/module/profile.php'; - $appControllerModuleProfile = new AppControllerModuleProfile($user->userId); + $appControllerModuleProfile = new AppControllerModuleProfile( + $this->_user + ); require_once __DIR__ . '/module/header.php'; diff --git a/src/app/controller/response.php b/src/app/controller/response.php index 3961e4b..eec6b53 100644 --- a/src/app/controller/response.php +++ b/src/app/controller/response.php @@ -30,7 +30,7 @@ class AppControllerResponse require_once __DIR__ . '/module/head.php'; $appControllerModuleHead = new AppControllerModuleHead( - WEBSITE_URL, + Environment::config('website')->url, $this->_title, [ [ diff --git a/src/app/controller/welcome.php b/src/app/controller/welcome.php index 0f034dd..0200894 100644 --- a/src/app/controller/welcome.php +++ b/src/app/controller/welcome.php @@ -6,13 +6,14 @@ class AppControllerWelcome public function __construct() { - require_once __DIR__ . '/../model/user.php'; + require_once __DIR__ . '/user.php'; - $this->_user = new AppModelUser( + $this->_user = new AppControllerUser( $_SERVER['REMOTE_ADDR'] ); } + private function _response(string $title, string $h1, string $text, int $code = 200) { require_once __DIR__ . '/response.php'; @@ -31,12 +32,12 @@ class AppControllerWelcome public function render() { - if (!$user = $this->_user->get()) + if (!$address = $this->_user->getAddress()) { $this->_response( sprintf( _('Error - %s'), - WEBSITE_NAME + Environment::config('website')->name ), _('500'), _('Could not init user'), @@ -44,17 +45,17 @@ class AppControllerWelcome ); } - if (!is_null($user->public)) + if (!is_null($this->_user->getPublic())) { $this->_response( sprintf( _('Welcome back - %s'), - WEBSITE_NAME + Environment::config('website')->name ), _('Welcome back!'), sprintf( _('You already have selected account type to %s'), - $user->public ? _('Distributed') : _('Local') + $this->_user->getPublic() ? _('Distributed') : _('Local') ), 405 ); @@ -67,7 +68,7 @@ class AppControllerWelcome $this->_response( sprintf( _('Success - %s'), - WEBSITE_NAME + Environment::config('website')->name ), _('Success!'), sprintf( @@ -81,10 +82,10 @@ class AppControllerWelcome require_once __DIR__ . '/module/head.php'; $appControllerModuleHead = new AppControllerModuleHead( - WEBSITE_URL, + Environment::config('website')->url, sprintf( _('Welcome to %s'), - WEBSITE_NAME + Environment::config('website')->name ), [ [ diff --git a/src/app/view/theme/default/welcome.phtml b/src/app/view/theme/default/welcome.phtml index af9aa03..dd6bd83 100644 --- a/src/app/view/theme/default/welcome.phtml +++ b/src/app/view/theme/default/welcome.phtml @@ -13,7 +13,7 @@
-