|
|
|
@ -4,68 +4,163 @@ class AppControllerPage
@@ -4,68 +4,163 @@ class AppControllerPage
|
|
|
|
|
{ |
|
|
|
|
private $_database; |
|
|
|
|
private $_validator; |
|
|
|
|
private $_locale; |
|
|
|
|
private $_website; |
|
|
|
|
private $_session; |
|
|
|
|
|
|
|
|
|
public function __construct( |
|
|
|
|
AppModelDatabase $database, |
|
|
|
|
AppModelValidator $validator, |
|
|
|
|
AppModelLocale $locale, |
|
|
|
|
AppModelWebsite $website, |
|
|
|
|
AppModelSession $session, |
|
|
|
|
) |
|
|
|
|
{ |
|
|
|
|
$this->_database = $database; |
|
|
|
|
$this->_validator = $validator; |
|
|
|
|
$this->_locale = $locale; |
|
|
|
|
$this->_website = $website; |
|
|
|
|
$this->_session = $session; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private $_user; |
|
|
|
|
private function _response(string $title, string $h1, mixed $data, int $code = 200) |
|
|
|
|
{ |
|
|
|
|
require_once __DIR__ . '/response.php'; |
|
|
|
|
|
|
|
|
|
public function __construct() |
|
|
|
|
if (is_array($data)) |
|
|
|
|
{ |
|
|
|
|
require_once __DIR__ . '/../model/database.php'; |
|
|
|
|
$data = implode('<br />', $data); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$this->_database = new AppModelDatabase( |
|
|
|
|
Environment::config('database') |
|
|
|
|
$appControllerResponse = new AppControllerResponse( |
|
|
|
|
$title, |
|
|
|
|
$h1, |
|
|
|
|
$data, |
|
|
|
|
$code |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../model/validator.php'; |
|
|
|
|
$appControllerResponse->render(); |
|
|
|
|
|
|
|
|
|
exit; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$this->_validator = new AppModelValidator( |
|
|
|
|
Environment::config('validator') |
|
|
|
|
private function _initUser(string $address) |
|
|
|
|
{ |
|
|
|
|
if (empty($address)) |
|
|
|
|
{ |
|
|
|
|
$this->_response( |
|
|
|
|
sprintf( |
|
|
|
|
_('Error - %s'), |
|
|
|
|
$this->_website->getName() |
|
|
|
|
), |
|
|
|
|
_('500'), |
|
|
|
|
_('Could not init session'), |
|
|
|
|
500 |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
require_once __DIR__ . '/user.php'; |
|
|
|
|
$error = []; |
|
|
|
|
if (!$this->_validator->host($address, $error)) |
|
|
|
|
{ |
|
|
|
|
$this->_response( |
|
|
|
|
sprintf( |
|
|
|
|
_('Error - %s'), |
|
|
|
|
$this->_website->getName() |
|
|
|
|
), |
|
|
|
|
_('406'), |
|
|
|
|
$error, |
|
|
|
|
406 |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$this->_user = new AppControllerUser( |
|
|
|
|
$_SERVER['REMOTE_ADDR'] |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
$this->_database->beginTransaction(); |
|
|
|
|
|
|
|
|
|
$user = $this->_database->getUser( |
|
|
|
|
$this->_database->initUserId( |
|
|
|
|
$address, |
|
|
|
|
$this->_website->getDefaultUserStatus(), |
|
|
|
|
$this->_website->getDefaultUserApproved(), |
|
|
|
|
time() |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
$this->_database->commit(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function _response(string $title, string $h1, string $text, int $code = 200) |
|
|
|
|
catch (Exception $error) |
|
|
|
|
{ |
|
|
|
|
require_once __DIR__ . '/response.php'; |
|
|
|
|
$this->_database->rollback(); |
|
|
|
|
|
|
|
|
|
$appControllerResponse = new AppControllerResponse( |
|
|
|
|
$title, |
|
|
|
|
$h1, |
|
|
|
|
$text, |
|
|
|
|
$code |
|
|
|
|
$this->_response( |
|
|
|
|
sprintf( |
|
|
|
|
_('Error - %s'), |
|
|
|
|
$this->_website->getName() |
|
|
|
|
), |
|
|
|
|
_('500'), |
|
|
|
|
$error, |
|
|
|
|
500 |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$appControllerResponse->render(); |
|
|
|
|
// Access denied |
|
|
|
|
if (!$user->status) |
|
|
|
|
{ |
|
|
|
|
$this->_response( |
|
|
|
|
sprintf( |
|
|
|
|
_('Error - %s'), |
|
|
|
|
$this->_website->getName() |
|
|
|
|
), |
|
|
|
|
_('403'), |
|
|
|
|
_('Access denied'), |
|
|
|
|
403 |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
exit; |
|
|
|
|
// Require account type selection |
|
|
|
|
if (is_null($user->public)) |
|
|
|
|
{ |
|
|
|
|
header( |
|
|
|
|
sprintf( |
|
|
|
|
'Location: %s/welcome', |
|
|
|
|
trim($this->_website->getUrl(), '/') |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function renderFormDescription() |
|
|
|
|
|
|
|
|
|
public function get(int $pageId) |
|
|
|
|
{ |
|
|
|
|
// Prepare locales |
|
|
|
|
$locales = []; |
|
|
|
|
return $this->_database->getPage($pageId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
foreach (Environment::config('locales') as $key => $value) |
|
|
|
|
public function add(int $timeAdded) |
|
|
|
|
{ |
|
|
|
|
$locales[$key] = (object) |
|
|
|
|
[ |
|
|
|
|
'key' => $key, |
|
|
|
|
'value' => $value[0], |
|
|
|
|
'active' => false !== stripos($_SERVER['HTTP_ACCEPT_LANGUAGE'], $key) ? true : false, |
|
|
|
|
]; |
|
|
|
|
return $this->_database->addPage($timeAdded); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function commitTitle(int $localeId, string $value) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function renderFormSubmit() |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
$user = $this->_initUser( |
|
|
|
|
$this->_session->getAddress() |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// Init form |
|
|
|
|
$form = (object) |
|
|
|
|
[ |
|
|
|
|
'locale' => (object) |
|
|
|
|
[ |
|
|
|
|
'error' => [], |
|
|
|
|
'values' => $locales, |
|
|
|
|
'values' => $this->_locale->getLocales(), |
|
|
|
|
'attribute' => (object) |
|
|
|
|
[ |
|
|
|
|
'value' => null, |
|
|
|
@ -134,6 +229,18 @@ class AppControllerPage
@@ -134,6 +229,18 @@ class AppControllerPage
|
|
|
|
|
// Submit request |
|
|
|
|
if (isset($_POST)) |
|
|
|
|
{ |
|
|
|
|
if (isset($_POST['locale'])) |
|
|
|
|
{ |
|
|
|
|
if (!$this->_locale->localeKeyExists($_POST['locale'])) |
|
|
|
|
{ |
|
|
|
|
$form->locale->error[] = [ |
|
|
|
|
_('Locale not supported') |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$form->locale->attribute->value = htmlentities($_POST['locale']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isset($_POST['title'])) |
|
|
|
|
{ |
|
|
|
|
$error = []; |
|
|
|
@ -141,11 +248,16 @@ class AppControllerPage
@@ -141,11 +248,16 @@ class AppControllerPage
|
|
|
|
|
if (!$this->_validator->pageTitle($_POST['title'], $error)) |
|
|
|
|
{ |
|
|
|
|
$form->title->error[] = $error; |
|
|
|
|
|
|
|
|
|
$form->title->attribute->value = htmlentities($_POST['title']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// @TODO check for page duplicates |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
$this->commitTitle($_POST['locale'], $_POST['title']); |
|
|
|
|
|
|
|
|
|
$form->title->attribute->value = htmlentities($_POST['title']); |
|
|
|
|
$form->title->attribute->value = $this->getTitle(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isset($_POST['description'])) |
|
|
|
@ -180,6 +292,26 @@ class AppControllerPage
@@ -180,6 +292,26 @@ class AppControllerPage
|
|
|
|
|
// Request valid |
|
|
|
|
if (empty($error)) |
|
|
|
|
{ |
|
|
|
|
// Init page |
|
|
|
|
if (isset($_GET['pageId'])) |
|
|
|
|
{ |
|
|
|
|
$page = $this->_database->getPage((int) $_GET['pageId']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else if (isset($_POST['pageId'])) |
|
|
|
|
{ |
|
|
|
|
$page = $this->_database->getPage((int) $_POST['pageId']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
$page = $this->_database->getPage( |
|
|
|
|
$this->_database->addPage( |
|
|
|
|
time() |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// @TODO redirect |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -188,10 +320,10 @@ class AppControllerPage
@@ -188,10 +320,10 @@ class AppControllerPage
|
|
|
|
|
require_once __DIR__ . '/module/head.php'; |
|
|
|
|
|
|
|
|
|
$appControllerModuleHead = new AppControllerModuleHead( |
|
|
|
|
Environment::config('website')->url, |
|
|
|
|
$this->_website->getUrl(), |
|
|
|
|
sprintf( |
|
|
|
|
_('Submit - %s'), |
|
|
|
|
Environment::config('website')->name |
|
|
|
|
$this->_website->getName() |
|
|
|
|
), |
|
|
|
|
[ |
|
|
|
|
[ |
|
|
|
@ -216,7 +348,7 @@ class AppControllerPage
@@ -216,7 +348,7 @@ class AppControllerPage
|
|
|
|
|
require_once __DIR__ . '/module/profile.php'; |
|
|
|
|
|
|
|
|
|
$appControllerModuleProfile = new AppControllerModuleProfile( |
|
|
|
|
$this->_user |
|
|
|
|
$user |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
require_once __DIR__ . '/module/header.php'; |
|
|
|
@ -227,6 +359,6 @@ class AppControllerPage
@@ -227,6 +359,6 @@ class AppControllerPage
|
|
|
|
|
|
|
|
|
|
$appControllerModuleFooter = new AppControllerModuleFooter(); |
|
|
|
|
|
|
|
|
|
include __DIR__ . '../../view/theme/default/page/form/description.phtml'; |
|
|
|
|
include __DIR__ . '../../view/theme/default/page/form/submit.phtml'; |
|
|
|
|
} |
|
|
|
|
} |