diff --git a/src/app/controller/module/footer.php b/src/app/controller/module/footer.php index d1a1f81..a512e0e 100644 --- a/src/app/controller/module/footer.php +++ b/src/app/controller/module/footer.php @@ -4,21 +4,9 @@ class AppControllerModuleFooter { public function render() { - $response['trackers'] = []; + $trackers = Environment::config('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, - ]; - } - } - } + $api = Environment::config('website')->api->export; include __DIR__ . '../../../view/theme/default/module/footer.phtml'; } diff --git a/src/app/controller/module/header.php b/src/app/controller/module/header.php index df162b1..293a268 100644 --- a/src/app/controller/module/header.php +++ b/src/app/controller/module/header.php @@ -7,7 +7,7 @@ public function render() $name = str_replace( 'YGG', 'YGG', - WEBSITE_NAME + Environment::config('website')->name ); require_once __DIR__ . '/search.php'; diff --git a/src/app/controller/page.php b/src/app/controller/page.php new file mode 100644 index 0000000..0d0d873 --- /dev/null +++ b/src/app/controller/page.php @@ -0,0 +1,209 @@ +_database = new AppModelDatabase( + Environment::config('database') + ); + + require_once __DIR__ . '/../model/validator.php'; + + $this->_validator = new AppModelValidator( + Environment::config('validator') + ); + + require_once __DIR__ . '/user.php'; + + $this->_user = new AppControllerUser( + $_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 renderFormDescription() + { + // Init form + $form = (object) + [ + 'title' => (object) + [ + 'error' => [], + 'attribute' => (object) + [ + 'value' => null, + 'required' => $this->_validator->getPageTitleRequired(), + 'minlength' => $this->_validator->getPageTitleLengthMin(), + 'maxlength' => $this->_validator->getPageTitleLengthMax(), + 'placeholder' => sprintf( + _('Page subject (%s-%s chars)'), + number_format($this->_validator->getPageTitleLengthMin()), + number_format($this->_validator->getPageTitleLengthMax()) + ), + ] + ], + 'description' => (object) + [ + 'error' => [], + 'attribute' => (object) + [ + 'value' => null, + 'required' => $this->_validator->getPageDescriptionRequired(), + 'minlength' => $this->_validator->getPageDescriptionLengthMin(), + 'maxlength' => $this->_validator->getPageDescriptionLengthMax(), + 'placeholder' => sprintf( + _('Page description text (%s-%s chars)'), + number_format($this->_validator->getPageDescriptionLengthMin()), + number_format($this->_validator->getPageDescriptionLengthMax()) + ), + ] + ], + 'keywords' => (object) + [ + 'error' => [], + 'attribute' => (object) + [ + 'value' => null, + 'required' => $this->_validator->getPageKeywordsRequired(), + 'placeholder' => sprintf( + _('Page keywords (%s-%s total / %s-%s chars per item)'), + number_format($this->_validator->getPageKeywordsQuantityMin()), + number_format($this->_validator->getPageKeywordsQuantityMax()), + number_format($this->_validator->getPageKeywordLengthMin()), + number_format($this->_validator->getPageKeywordLengthMax()) + ), + ] + ], + 'sensitive' => (object) + [ + 'error' => [], + 'attribute' => (object) + [ + 'value' => null, + 'placeholder' => _('Apply NSFW filters for this publication'), + ] + ] + ]; + + // Submit request + if (isset($_POST)) + { + if (isset($_POST['title'])) + { + $error = []; + + if (!$this->_validator->pageTitle($_POST['title'], $error)) + { + $form->title->error[] = $error; + } + + // @TODO check for page duplicates + + $form->title->attribute->value = htmlentities($_POST['title']); + } + + if (isset($_POST['description'])) + { + $error = []; + + if (!$this->_validator->pageDescription($_POST['description'], $error)) + { + $form->description->error[] = $error; + } + + $form->description->attribute->value = htmlentities($_POST['description']); + } + + if (isset($_POST['keywords'])) + { + $error = []; + + if (!$this->_validator->pageKeywords($_POST['keywords'], $error)) + { + $form->keywords->error[] = $error; + } + + $form->keywords->attribute->value = htmlentities($_POST['keywords']); + } + + if (isset($_POST['sensitive'])) + { + $form->sensitive->attribute->value = (bool) $_POST['sensitive']; + } + + // Request valid + if (empty($error)) + { + // @TODO redirect + } + } + + // Render template + require_once __DIR__ . '/module/head.php'; + + $appControllerModuleHead = new AppControllerModuleHead( + Environment::config('website')->url, + sprintf( + _('Submit - %s'), + Environment::config('website')->name + ), + [ + [ + 'rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => sprintf( + 'assets/theme/default/css/common.css?%s', + CSS_VERSION + ), + ], + [ + 'rel' => 'stylesheet', + 'type' => 'text/css', + 'href' => sprintf( + 'assets/theme/default/css/framework.css?%s', + CSS_VERSION + ), + ], + ] + ); + + require_once __DIR__ . '/module/profile.php'; + + $appControllerModuleProfile = new AppControllerModuleProfile( + $this->_user + ); + + require_once __DIR__ . '/module/header.php'; + + $appControllerModuleHeader = new AppControllerModuleHeader(); + + require_once __DIR__ . '/module/footer.php'; + + $appControllerModuleFooter = new AppControllerModuleFooter(); + + include __DIR__ . '../../view/theme/default/page/form/description.phtml'; + } +} \ No newline at end of file diff --git a/src/app/controller/user.php b/src/app/controller/user.php index 0f6b883..85a83a2 100644 --- a/src/app/controller/user.php +++ b/src/app/controller/user.php @@ -3,48 +3,33 @@ class AppControllerUser { private $_database; + private $_validator; 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 - ); - } + $this->_database = new AppModelDatabase( + Environment::config('database') + ); - catch (Exception $error) - { - $this->_response( - sprintf( - _('Error - %s'), - WEBSITE_NAME - ), - _('500'), - print_r($error, true), - 500 - ); - } + require_once __DIR__ . '/../model/validator.php'; - // Validate user address - require_once __DIR__ . '/../../library/valid.php'; + $this->_validator = new AppModelValidator( + Environment::config('validator') + ); + // Validate address $error = []; - if (!Valid::host($address, $error)) + + if (!$this->_validator->host($address, $error)) { $this->_response( sprintf( _('Error - %s'), - WEBSITE_NAME + Environment::config('website')->name ), _('406'), print_r($error, true), @@ -60,7 +45,7 @@ public function __construct(string $address) $this->_user = $this->_database->getUser( $this->_database->initUserId( $address, - USER_DEFAULT_APPROVED, + Environment::config('website')->default->user->approved, time() ) ); @@ -75,13 +60,24 @@ public function __construct(string $address) $this->_response( sprintf( _('Error - %s'), - WEBSITE_NAME + Environment::config('website')->name ), _('500'), print_r($error, true), 500 ); } + + // Require account type selection + if (is_null($this->getPublic())) + { + header( + sprintf( + 'Location: %s/welcome', + trim($this->_config->url, '/') + ) + ); + } } private function _response(string $title, string $h1, string $text, int $code = 200) diff --git a/src/app/view/theme/default/module/footer.phtml b/src/app/view/theme/default/module/footer.phtml index 75aeaf3..0064221 100644 --- a/src/app/view/theme/default/module/footer.phtml +++ b/src/app/view/theme/default/module/footer.phtml @@ -13,7 +13,7 @@ | - + | diff --git a/src/app/view/theme/default/module/profile.phtml b/src/app/view/theme/default/module/profile.phtml index 6b774fc..a3062dc 100644 --- a/src/app/view/theme/default/module/profile.phtml +++ b/src/app/view/theme/default/module/profile.phtml @@ -152,7 +152,7 @@ - + diff --git a/src/app/view/theme/default/page/form/description.phtml b/src/app/view/theme/default/page/form/description.phtml new file mode 100644 index 0000000..33df21b --- /dev/null +++ b/src/app/view/theme/default/page/form/description.phtml @@ -0,0 +1,115 @@ + + + render() ?> + + render() ?> +
+
+
+
+ render() ?> +
+
+

+
+
+
+ + + + + + + title->error as $errors) { ?> + +
+ +
+ + + title->attribute->required ? 'required="required"' : false ?> + value="title->attribute->value ?>" + placeholder="title->attribute->placeholder ?>" + minlength="title->attribute->minlength ?>" + maxlength="title->attribute->maxlength ?>" /> +
+
+ + + + + + + description->error as $errors) { ?> + +
+ +
+ + + +
+
+ + + + + + + keywords->error as $errors) { ?> + +
+ +
+ + + +
+
+ sensitive->attribute->value ? 'checked="checked"' : false ?> /> + + + + + + +
+
+ +
+
+
+
+
+
+
+ render() ?> + + \ No newline at end of file diff --git a/src/config/bootstrap.php b/src/config/bootstrap.php index 9617217..23f0708 100644 --- a/src/config/bootstrap.php +++ b/src/config/bootstrap.php @@ -90,21 +90,9 @@ require_once __DIR__ . '/../app/controller/page.php'; - $appControllerPage = new AppControllerPage( - Environment::config('website') - ); - - require_once __DIR__ . '/../app/model/database.php'; - require_once __DIR__ . '/../app/model/validator.php'; + $appControllerPage = new AppControllerPage(); - $appControllerPage->renderFormDescription( - new AppModelDatabase( - Environment::config('database') - ), - new AppModelValidator( - Environment::config('validator') - ) - ); + $appControllerPage->renderFormDescription(); break;