Browse Source

Page, Validator, View

Visman 8 years ago
parent
commit
1481a2d889

+ 122 - 134
app/Core/Validator.php

@@ -7,13 +7,6 @@ use RuntimeException;
 
 
 class Validator
 class Validator
 {
 {
-    const T_UNKNOWN = 0;
-    const T_STRING = 1;
-    const T_NUMERIC = 2;
-    const T_INT = 3;
-    const T_ARRAY = 4;
-    const T_BOOLEAN = 5;
-
     /**
     /**
      * Контейнер
      * Контейнер
      * @var Container
      * @var Container
@@ -21,42 +14,63 @@ class Validator
     protected $c;
     protected $c;
 
 
     /**
     /**
+     * Массив валидаторов
+     * @var array
+     */
+    protected $validators = [];
+
+    /**
+     * Массив правил для текущей проверки данных
      * @var array
      * @var array
      */
      */
-    protected $validators;
+    protected $rules = [];
 
 
     /**
     /**
+     * Массив результатов проверенных данных
      * @var array
      * @var array
      */
      */
-    protected $rules;
+    protected $result = [];
 
 
     /**
     /**
+     * Массив дополнительных аргументов для валидаторов и конкретных полей/правил
      * @var array
      * @var array
      */
      */
-    protected $result;
+    protected $arguments = [];
 
 
     /**
     /**
+     * Массив сообщений об ошибках для конкретных полей/правил
      * @var array
      * @var array
      */
      */
-    protected $arguments;
+    protected $messages = [];
 
 
     /**
     /**
+     * Массив псевдонимов имен полей для вывода в ошибках
      * @var array
      * @var array
      */
      */
-    protected $messages;
+    protected $aliases = [];
 
 
     /**
     /**
+     * Массив ошибок валидации
      * @var array
      * @var array
      */
      */
-    protected $aliases;
+    protected $errors = [];
 
 
     /**
     /**
+     * Массив имен полей для обработки
      * @var array
      * @var array
      */
      */
-    protected $errors;
+    protected $fields = [];
 
 
-    protected $fields;
-    protected $status;
+    /**
+     * Массив состояний проверки полей
+     * @var array
+     */
+    protected $status = [];
+
+    /**
+     * Массив входящих данных для обработки
+     * @var array
+     */
     protected $raw;
     protected $raw;
 
 
     /**
     /**
@@ -181,7 +195,7 @@ class Validator
         $this->status = [];
         $this->status = [];
         $this->raw = $raw;
         $this->raw = $raw;
         foreach ($this->fields as $field) {
         foreach ($this->fields as $field) {
-            $this->$field;
+            $this->__get($field);
         }
         }
         $this->raw = null;
         $this->raw = null;
         return empty($this->errors);
         return empty($this->errors);
@@ -223,15 +237,12 @@ class Validator
         }
         }
 
 
         $error = false;
         $error = false;
-        $type = self::T_UNKNOWN;
         foreach ($rules as $validator => $attr) {
         foreach ($rules as $validator => $attr) {
             $args = $this->getArguments($field, $validator);
             $args = $this->getArguments($field, $validator);
-            list($value, $type, $error) = $this->validators[$validator]($this, $value, $type, $attr, $args);
-            // ошибок нет
-            if (false === $error) {
-                continue;
+            list($value, $error) = $this->validators[$validator]($this, $value, $attr, $args);
+            if (false !== $error) {
+                break;
             }
             }
-            break;
         }
         }
 
 
         if (! is_bool($error)) {
         if (! is_bool($error)) {
@@ -296,7 +307,7 @@ class Validator
     public function getStatus($field)
     public function getStatus($field)
     {
     {
         if (! isset($this->status[$field])) {
         if (! isset($this->status[$field])) {
-            $this->$field;
+            $this->__get($field);
         }
         }
         return $this->status[$field];
         return $this->status[$field];
     }
     }
@@ -324,229 +335,206 @@ class Validator
         return $this->errors;
         return $this->errors;
     }
     }
 
 
-    protected function vRequired($v, $value, $type)
+    protected function vRequired($v, $value)
     {
     {
         if (is_string($value)) {
         if (is_string($value)) {
-            if (strlen(trim($value)) > 0) {
-                return [$value, $v::T_STRING, false];
+            if (strlen(preg_replace('%^\s+|\s+$%u', '', $value)) > 0) {
+                return [$value, false];
             }
             }
         } elseif (is_array($value)) {
         } elseif (is_array($value)) {
             if (! empty($value)) {
             if (! empty($value)) {
-                return [$value, $v::T_ARRAY, false];
+                return [$value, false];
             }
             }
         } elseif (null !== $value) {
         } elseif (null !== $value) {
-            if (is_int($value)) {
-                $type = $v::T_INT;
-            } elseif (is_numeric($value)) {
-                $type = $v::T_NUMERIC;
-            }
-            return [$value, $type, false];
+            return [$value, false];
         }
         }
-        return [null, $type, 'The :alias is required'];
+        return [null, 'The :alias is required'];
     }
     }
 
 
-    protected function vRequiredWith($v, $value, $type, $attr)
+    protected function vRequiredWith($v, $value, $attr)
     {
     {
         foreach (explode(',', $attr) as $field) {
         foreach (explode(',', $attr) as $field) {
-            if (null !== $v->$field) {
-                return $this->vRequired($v, $value, $type);
+            if (null !== $this->__get($field) {
+                return $this->vRequired($v, $value);
             }
             }
         }
         }
-        list(, , $error) = $this->vRequired($v, $value, $type);
+        list(, $error) = $this->vRequired($v, $value);
         if (false === $error) {
         if (false === $error) {
-            return [null, $type, 'The :alias is not required'];
+            return [null, 'The :alias is not required'];
         } else {
         } else {
-            return [$value, $type, true];
+            return [$value, true];
         }
         }
     }
     }
 
 
-    protected function vString($v, $value, $type, $attr)
+    protected function vString($v, $value, $attr)
     {
     {
         if (null === $value) {
         if (null === $value) {
-            return [null, $type, false];
+            return [null, false];
         } elseif (is_string($value)) {
         } elseif (is_string($value)) {
             foreach(explode(',', $attr) as $action) {
             foreach(explode(',', $attr) as $action) {
                 switch ($action) {
                 switch ($action) {
                     case 'trim':
                     case 'trim':
-                        $value = preg_replace('%^\s+|\s+$%u', '', $value); // trim($value);
+                        $value = preg_replace('%^\s+|\s+$%u', '', $value);
                         break;
                         break;
                     case 'lower':
                     case 'lower':
                         $value = mb_strtolower($value, 'UTF-8');
                         $value = mb_strtolower($value, 'UTF-8');
                         break;
                         break;
                 }
                 }
             }
             }
-            return [$value, $v::T_STRING, false];
+            return [$value, false];
         } else {
         } else {
-            return [null, $type, 'The :alias must be string'];
+            return [null, 'The :alias must be string'];
         }
         }
     }
     }
 
 
-    protected function vNumeric($v, $value, $type)
+    protected function vNumeric($v, $value)
     {
     {
         if (null === $value) {
         if (null === $value) {
-            return [null, $type, false];
+            return [null, false];
         } elseif (is_numeric($value)) {
         } elseif (is_numeric($value)) {
-            return [0 + $value, $v::T_NUMERIC, false];
+            return [0 + $value, false];
         } else {
         } else {
-            return [null, $type, 'The :alias must be numeric'];
+            return [null, 'The :alias must be numeric'];
         }
         }
     }
     }
 
 
-    protected function vInteger($v, $value, $type)
+    protected function vInteger($v, $value)
     {
     {
         if (null === $value) {
         if (null === $value) {
-            return [null, $type, false];
+            return [null, false];
         } elseif (is_numeric($value) && is_int(0 + $value)) {
         } elseif (is_numeric($value) && is_int(0 + $value)) {
-            return [(int) $value, $v::T_INT, false];
+            return [(int) $value, false];
         } else {
         } else {
-            return [null, $type, 'The :alias must be integer'];
+            return [null, 'The :alias must be integer'];
         }
         }
     }
     }
 
 
-    protected function vArray($v, $value, $type)
+    protected function vArray($v, $value)
     {
     {
         if (null === $value) {
         if (null === $value) {
-            return [null, $type, false];
+            return [null, false];
         } elseif (is_array($value)) {
         } elseif (is_array($value)) {
-            return [$value, $v::T_ARRAY, false];
+            return [$value, false];
         } else {
         } else {
-            return [null, $type, 'The :alias must be array'];
+            return [null, 'The :alias must be array'];
         }
         }
     }
     }
 
 
-    protected function vMin($v, $value, $type, $attr)
+    protected function vMin($v, $value, $attr)
     {
     {
-        if (null === $value) {
-            return [null, $type, false];
-        }
-        switch ($type) {
-            case self::T_STRING:
-                if (mb_strlen($value, 'UTF-8') < $attr) {
-                    return [$value, $type, 'The :alias minimum is :attr characters'];
-                }
-                break;
-            case self::T_NUMERIC:
-            case self::T_INT:
-                if ($value < $attr) {
-                    return [$value, $type, 'The :alias minimum is :attr'];
-                }
-                break;
-            case self::T_ARRAY:
-                if (count($value) < $attr) {
-                    return [$value, $type, 'The :alias minimum is :attr elements'];
-                }
-                break;
-            default:
-                return [null, $type, 'The :alias minimum is :attr'];
-                break;
+        if (is_numeric($value)) {
+            if (0 + $value < $attr) {
+                return [$value, 'The :alias minimum is :attr'];
+            }
+        } elseif (is_string($value)) {
+            if (mb_strlen($value, 'UTF-8') < $attr) {
+                return [$value, 'The :alias minimum is :attr characters'];
+            }
+        } elseif (is_array($value)) {
+            if (count($value) < $attr) {
+                return [$value, 'The :alias minimum is :attr elements'];
+            }
+        } else {
+            return [null, null === $value ? false : 'The :alias minimum is :attr'];
         }
         }
-        return [$value, $type, false];
+        return [$value, false];
     }
     }
 
 
-    protected function vMax($v, $value, $type, $attr)
+    protected function vMax($v, $value, $attr)
     {
     {
-        if (null === $value) {
-            return [null, $type, false];
-        }
-        switch ($type) {
-            case self::T_STRING:
-                if (mb_strlen($value, 'UTF-8') > $attr) {
-                    return [$value, $type, 'The :alias maximum is :attr characters'];
-                }
-                break;
-            case self::T_NUMERIC:
-            case self::T_INT:
-                if ($value > $attr) {
-                    return [$value, $type, 'The :alias maximum is :attr'];
-                }
-                break;
-            case self::T_ARRAY:
-                if (count($value) > $attr) {
-                    return [$value, $type, 'The :alias maximum is :attr elements'];
-                }
-                break;
-            default:
-                return [null, $type, 'The :alias maximum is :attr'];
-                break;
+        if (is_numeric($value)) {
+            if (0 + $value > $attr) {
+                return [$value, 'The :alias maximum is :attr'];
+            }
+        } elseif (is_string($value)) {
+            if (mb_strlen($value, 'UTF-8') > $attr) {
+                return [$value, 'The :alias maximum is :attr characters'];
+            }
+        } elseif (is_array($value)) {
+            if (count($value) > $attr) {
+                return [$value, 'The :alias maximum is :attr elements'];
+            }
+        } else {
+            return [null, null === $value ? false : 'The :alias maximum is :attr'];
         }
         }
-        return [$value, $type, false];
+        return [$value, false];
     }
     }
 
 
-    protected function vToken($v, $value, $type, $attr, $args)
+    protected function vToken($v, $value, $attr, $args)
     {
     {
         if (! is_array($args)) {
         if (! is_array($args)) {
             $args = [];
             $args = [];
         }
         }
         $value = (string) $value;
         $value = (string) $value;
         if ($this->c->Csrf->verify($value, $attr, $args)) {
         if ($this->c->Csrf->verify($value, $attr, $args)) {
-            return [$value, $type, false];
+            return [$value, false];
         } else {
         } else {
-            return [$value, $type, ['Bad token', 'e']];
+            return [$value, ['Bad token', 'e']];
         }
         }
     }
     }
 
 
     protected function vCheckbox($v, $value)
     protected function vCheckbox($v, $value)
     {
     {
-        return [! empty($value), $v::T_BOOLEAN, false];
+        return [! empty($value), false];
     }
     }
 
 
-    protected function vReferer($v, $value, $type, $attr, $args)
+    protected function vReferer($v, $value, $attr, $args)
     {
     {
         if (! is_array($args)) {
         if (! is_array($args)) {
             $args = [];
             $args = [];
         }
         }
-        return [$this->c->Router->validate($value, $attr, $args), $type, false];
+        return [$this->c->Router->validate($value, $attr, $args), false];
     }
     }
 
 
-    protected function vEmail($v, $value, $type)
+    protected function vEmail($v, $value)
     {
     {
         if (null === $value) {
         if (null === $value) {
-            return [$value, $type, false];
+            return [$value, false];
         }
         }
         $email = $this->c->Mail->valid($value, true);
         $email = $this->c->Mail->valid($value, true);
         if (false === $email) {
         if (false === $email) {
-            return [(string) $value, $type, 'The :alias is not valid email'];
+            return [(string) $value, 'The :alias is not valid email'];
         } else {
         } else {
-            return [$email, $type, false];
+            return [$email, false];
         }
         }
     }
     }
 
 
-    protected function vSame($v, $value, $type, $attr)
+    protected function vSame($v, $value, $attr)
     {
     {
-        if (! $v->getStatus($attr) || $value === $v->$attr) {
-            return [$value, $type, false];
+        if (! $this->getStatus($attr) || $value === $this->__get($attr)) {
+            return [$value, false];
         } else {
         } else {
-            return [null, $type, 'The :alias must be same with original'];
+            return [null, 'The :alias must be same with original'];
         }
         }
     }
     }
 
 
-    protected function vRegex($v, $value, $type, $attr)
+    protected function vRegex($v, $value, $attr)
     {
     {
         if (null === $value) {
         if (null === $value) {
-            return [$value, $type, false];
-        } elseif ($type === $v::T_STRING && preg_match($attr, $value)) {
-            return [$value, $type, false];
+            return [$value, false];
+        } elseif (is_string($value) && preg_match($attr, $value)) {
+            return [$value, false];
         } else {
         } else {
-            return [null, $type, 'The :alias is not valid format'];
+            return [null, 'The :alias is not valid format'];
         }
         }
     }
     }
 
 
-    protected function vPassword($v, $value, $type)
+    protected function vPassword($v, $value)
     {
     {
-        return $this->vRegex($v, $value, $type, '%[^\x20][\x20][^\x20]%');
+        return $this->vRegex($v, $value, '%[^\x20][\x20][^\x20]%');
     }
     }
 
 
-    protected function vLogin($v, $value, $type)
+    protected function vLogin($v, $value)
     {
     {
-        return $this->vRegex($v, $value, $type, '%^\p{L}[\p{L}\p{N}\x20\._-]+$%uD');
+        return $this->vRegex($v, $value, '%^\p{L}[\p{L}\p{N}\x20\._-]+$%uD');
     }
     }
 
 
-    protected function vIn($v, $value, $type, $attr)
+    protected function vIn($v, $value, $attr)
     {
     {
         if (null === $value || in_array($value, explode(',', $attr))) {
         if (null === $value || in_array($value, explode(',', $attr))) {
-            return [$value, $type, false];
+            return [$value, false];
         } else {
         } else {
-            return [null, $type, 'The :alias contains an invalid value'];
+            return [null, 'The :alias contains an invalid value'];
         }
         }
     }
     }
 }
 }

+ 5 - 16
app/Core/View.php

@@ -8,8 +8,6 @@ use RuntimeException;
 
 
 class View extends Dirk
 class View extends Dirk
 {
 {
-    protected $page;
-
     public function __construct ($cache, $views)
     public function __construct ($cache, $views)
     {
     {
         $config = [
         $config = [
@@ -42,32 +40,23 @@ class View extends Dirk
             $value);
             $value);
     }
     }
 
 
-    public function setPage(Page $page)
+    public function rendering(Page $page)
     {
     {
-        if (true !== $page->isReady()) {
+        if (! $page->isReady()) {
             throw new RuntimeException('The page model does not contain data ready');
             throw new RuntimeException('The page model does not contain data ready');
         }
         }
-        $this->page = $page;
-        return $this;
-    }
-
-    public function outputPage()
-    {
-        if (empty($this->page)) {
-            throw new RuntimeException('The page model isn\'t set');
-        }
 
 
-        $headers = $this->page->getHeaders();
+        $headers = $page->httpHeaders();
         foreach ($headers as $header) {
         foreach ($headers as $header) {
             header($header);
             header($header);
         }
         }
 
 
-        $tpl = $this->page->getNameTpl();
+        $tpl = $page->getNameTpl();
         // переадресация
         // переадресация
         if (null === $tpl) {
         if (null === $tpl) {
             return null;
             return null;
         }
         }
 
 
-        return $this->fetch($tpl, $this->page->getData());
+        return $this->fetch($tpl, $page->getData());
     }
     }
 }
 }

+ 12 - 2
app/Models/Pages/Admin/Admin.php

@@ -33,7 +33,6 @@ abstract class Admin extends Page
     {
     {
         parent::__construct($container);
         parent::__construct($container);
         $container->Lang->load('admin');
         $container->Lang->load('admin');
-        $this->titles = [__('Admin title')];
     }
     }
 
 
     /**
     /**
@@ -48,6 +47,18 @@ abstract class Admin extends Page
         return $data;
         return $data;
     }
     }
 
 
+    /**
+     * Формирует title страницы
+     * @param array $titles
+     * @return string
+     */
+    protected function pageTitle(array $titles = [])
+    {
+        $titles = $this->titles;
+        $titles[] = __('Admin title');
+        return parent::pageTitle($titles);
+    }
+
     /**
     /**
      * Возвращает массив ссылок с описанием для построения навигации админки
      * Возвращает массив ссылок с описанием для построения навигации админки
      * @return array
      * @return array
@@ -82,7 +93,6 @@ abstract class Admin extends Page
             ];
             ];
         }
         }
 
 
-
         return $nav;
         return $nav;
     }
     }
 
 

+ 0 - 1
app/Models/Pages/Admin/Statistics.php

@@ -38,7 +38,6 @@ class Statistics extends Admin
     public function statistics()
     public function statistics()
     {
     {
         $this->c->Lang->load('admin_index');
         $this->c->Lang->load('admin_index');
-        $this->data = [];
         $this->titles[] = __('Server statistics');
         $this->titles[] = __('Server statistics');
         $this->data['isAdmin'] = $this->c->user->isAdmin;
         $this->data['isAdmin'] = $this->c->user->isAdmin;
         $this->data['linkInfo'] = $this->c->Router->link('AdminInfo');
         $this->data['linkInfo'] = $this->c->Router->link('AdminInfo');

+ 8 - 16
app/Models/Pages/Auth.php

@@ -45,7 +45,7 @@ class Auth extends Page
      */
      */
     public function logout($args)
     public function logout($args)
     {
     {
-        if (! $this->c->Csrf->verify($args['token'], 'Logout', $args)) {
+        if (empty($args['token']) || ! $this->c->Csrf->verify($args['token'], 'Logout', $args)) {
             return $this->c->Redirect->setPage('Index')->setMessage(__('Bad token'));
             return $this->c->Redirect->setPage('Index')->setMessage(__('Bad token'));
         }
         }
 
 
@@ -74,9 +74,7 @@ class Auth extends Page
             $args['_redirect'] = $this->c->Router->validate($args['_redirect'], 'Index');
             $args['_redirect'] = $this->c->Router->validate($args['_redirect'], 'Index');
         }
         }
 
 
-        $this->titles = [
-            __('Login'),
-        ];
+        $this->titles[] = __('Login');
         $this->data = [
         $this->data = [
             'formAction' => $this->c->Router->link('Login'),
             'formAction' => $this->c->Router->link('Login'),
             'formToken' => $this->c->Csrf->create('Login'),
             'formToken' => $this->c->Csrf->create('Login'),
@@ -126,10 +124,9 @@ class Auth extends Page
      * Проверка по базе и вход на форум
      * Проверка по базе и вход на форум
      * @param Validator $v
      * @param Validator $v
      * @param string $password
      * @param string $password
-     * @param int $type
      * @return array
      * @return array
      */
      */
-    public function vLoginProcess(Validator $v, $password, $type)
+    public function vLoginProcess(Validator $v, $password)
     {
     {
         $error = false;
         $error = false;
         if (! empty($v->getErrors())) {
         if (! empty($v->getErrors())) {
@@ -169,7 +166,7 @@ class Auth extends Page
                 $this->c->UserCookie->setUserCookie($user->id, $hash, $v->save);
                 $this->c->UserCookie->setUserCookie($user->id, $hash, $v->save);
             }
             }
         }
         }
-        return [$password, $type, $error];
+        return [$password, $error];
     }
     }
 
 
     /**
     /**
@@ -188,9 +185,7 @@ class Auth extends Page
 
 
         $this->c->Lang->load('auth');
         $this->c->Lang->load('auth');
 
 
-        $this->titles = [
-            __('Passphrase reset'),
-        ];
+        $this->titles[] = __('Passphrase reset');
         $this->data = [
         $this->data = [
             'formAction' => $this->c->Router->link('Forget'),
             'formAction' => $this->c->Router->link('Forget'),
             'formToken' => $this->c->Csrf->create('Forget'),
             'formToken' => $this->c->Csrf->create('Forget'),
@@ -259,10 +254,9 @@ class Auth extends Page
      * Дополнительная проверка email
      * Дополнительная проверка email
      * @param Validator $v
      * @param Validator $v
      * @param string $username
      * @param string $username
-     * @param int $type
      * @return array
      * @return array
      */
      */
-    public function vCheckEmail(Validator $v, $email, $type)
+    public function vCheckEmail(Validator $v, $email)
     {
     {
         $error = false;
         $error = false;
         // есть ошибки
         // есть ошибки
@@ -279,7 +273,7 @@ class Auth extends Page
         } else {
         } else {
             $this->tmpUser = $user;
             $this->tmpUser = $user;
         }
         }
-        return [$email, $type, $error];
+        return [$email, $error];
     }
     }
 
 
     /**
     /**
@@ -314,9 +308,7 @@ class Auth extends Page
             $this->iswev['i'][] = __('Account activated');
             $this->iswev['i'][] = __('Account activated');
         }
         }
 
 
-        $this->titles = [
-            __('Change pass'),
-        ];
+        $this->titles[] = __('Change pass');
         $this->data = [
         $this->data = [
             'formAction' => $this->c->Router->link('ChangePassword', $args),
             'formAction' => $this->c->Router->link('ChangePassword', $args),
             'formToken' => $this->c->Csrf->create('ChangePassword', $args),
             'formToken' => $this->c->Csrf->create('ChangePassword', $args),

+ 2 - 3
app/Models/Pages/Ban.php

@@ -29,9 +29,8 @@ class Ban extends Page
      */
      */
     public function ban(array $banned)
     public function ban(array $banned)
     {
     {
-        $this->titles = [
-            __('Info'),
-        ];
+        $this->titles[] = __('Info');
+
         if (! empty($banned['expire'])) {
         if (! empty($banned['expire'])) {
              $banned['expire'] = strtolower($this->time($banned['expire'], true));
              $banned['expire'] = strtolower($this->time($banned['expire'], true));
         }
         }

+ 1 - 10
app/Models/Pages/Debug.php

@@ -38,20 +38,11 @@ class Debug extends Page
         return $this;
         return $this;
     }
     }
 
 
-    /**
-     * Возвращает массив ссылок с описанием для построения навигации
-     * @return array
-     */
-    protected function fNavigation()
-    {
-        return [];
-    }
-
     /**
     /**
      * Возвращает HTTP заголовки страницы
      * Возвращает HTTP заголовки страницы
      * @return array
      * @return array
      */
      */
-    public function getHeaders()
+    public function httpHeaders()
     {
     {
         return [];
         return [];
     }
     }

+ 1 - 2
app/Models/Pages/Forum.php

@@ -188,13 +188,12 @@ class Forum extends Page
             || ($user->isAdmMod && isset($moders[$user->id]));
             || ($user->isAdmMod && isset($moders[$user->id]));
 
 
         $this->onlinePos = 'forum-' . $args['id'];
         $this->onlinePos = 'forum-' . $args['id'];
-        $this->titles = [];
         $crumbs = [];
         $crumbs = [];
         $id = $args['id'];
         $id = $args['id'];
         $activ = true;
         $activ = true;
         while (true) {
         while (true) {
             $name = $fDesc[$id]['forum_name'];
             $name = $fDesc[$id]['forum_name'];
-            array_unshift($this->titles, $name);
+            $this->titles[] = $name;
             $crumbs[] = [
             $crumbs[] = [
                 $this->c->Router->link('Forum', ['id' => $id, 'name' => $name]),
                 $this->c->Router->link('Forum', ['id' => $id, 'name' => $name]),
                 $name, 
                 $name, 

+ 0 - 2
app/Models/Pages/Install.php

@@ -53,8 +53,6 @@ class Install extends Page
     {
     {
         return $this->data + [
         return $this->data + [
             'pageHeads' => $this->pageHeads(),
             'pageHeads' => $this->pageHeads(),
-            'fLang' => __('lang_identifier'),
-            'fDirection' => __('lang_direction'),
             'fIswev' => $this->getIswev(),
             'fIswev' => $this->getIswev(),
         ];
         ];
     }
     }

+ 19 - 28
app/Models/Pages/Maintenance.php

@@ -24,12 +24,6 @@ class Maintenance extends Page
      */
      */
     protected $httpStatus = 503;
     protected $httpStatus = 503;
 
 
-    /**
-     * Подготовленные данные для шаблона
-     * @var array
-     */
-    protected $data = [];
-
     /**
     /**
      * Конструктор
      * Конструктор
      * @param Container $container
      * @param Container $container
@@ -42,35 +36,32 @@ class Maintenance extends Page
     }
     }
 
 
     /**
     /**
-     * Возвращает данные для шаблона
-     * @return array
+     * Возвращает флаг готовности данных
+     * @return bool
      */
      */
-    public function getData()
+    public function isReady()
     {
     {
-        $this->titles = [
-            __('Maintenance'),
-        ];
-        $this->data = [
-            'maintenanceMessage' => $this->config['o_maintenance_message'],
-        ];
-        return parent::getData();
+        return true;
     }
     }
 
 
     /**
     /**
-     * Возвращает массив ссылок с описанием для построения навигации
-     * @return array
-     */
-    protected function fNavigation()
-    {
-        return [];
-    }
-
-    /**
-     * Возврат info, success, warning, error, validation информации
+     * Возвращает данные для шаблона
      * @return array
      * @return array
      */
      */
-    protected function getIswev()
+    public function getData()
     {
     {
-        return [];
+        $this->titles[] = __('Maintenance');
+        return [
+            'maintenanceMessage' => $this->config['o_maintenance_message'],
+            'pageTitle' => $this->pageTitle(),
+            'pageHeaders' => $this->pageHeaders(),
+            'fTitle' => $this->config['o_board_title'],
+            'fDescription' => $this->config['o_board_desc'],
+            'fNavigation' => null,
+            'fIndex' => $this->index,
+            'fAnnounce' => null,
+            'fRootLink' => $this->c->Router->link('Index'),
+            'fIswev' => null,
+        ];
     }
     }
 }
 }

+ 1 - 3
app/Models/Pages/Message.php

@@ -21,9 +21,7 @@ class Message extends Page
     {
     {
         $this->httpStatus = $status;
         $this->httpStatus = $status;
         $this->httpHeaders = $headers;
         $this->httpHeaders = $headers;
-        $this->titles = [
-            __('Info'),
-        ];
+        $this->titles[] = __('Info');
         $this->data = [
         $this->data = [
             'message' => __($message),
             'message' => __($message),
             'back' => $back,
             'back' => $back,

+ 35 - 39
app/Models/Pages/Page.php

@@ -47,13 +47,13 @@ abstract class Page
      * Массив титула страницы
      * Массив титула страницы
      * @var array
      * @var array
      */
      */
-    protected $titles;
+    protected $titles = [];
 
 
     /**
     /**
      * Подготовленные данные для шаблона
      * Подготовленные данные для шаблона
      * @var array
      * @var array
      */
      */
-    protected $data;
+    protected $data = [];
 
 
     /**
     /**
      * Массив info, success, warning, error, validation информации
      * Массив info, success, warning, error, validation информации
@@ -110,10 +110,10 @@ abstract class Page
      * Возвращает HTTP заголовки страницы
      * Возвращает HTTP заголовки страницы
      * @return array
      * @return array
      */
      */
-    public function getHeaders()
+    public function httpHeaders()
     {
     {
         $headers = $this->httpHeaders;
         $headers = $this->httpHeaders;
-        if (! empty($status = $this->getStatus())) {
+        if (! empty($status = $this->httpStatus())) {
             $headers[] = $status;
             $headers[] = $status;
         }
         }
         return $headers;
         return $headers;
@@ -123,7 +123,7 @@ abstract class Page
      * Возвращает HTTP статус страницы или null
      * Возвращает HTTP статус страницы или null
      * @return null|string
      * @return null|string
      */
      */
-    protected function getStatus()
+    protected function httpStatus()
     {
     {
         $list = [
         $list = [
             403 => '403 Forbidden',
             403 => '403 Forbidden',
@@ -152,7 +152,7 @@ abstract class Page
      */
      */
     public function isReady()
     public function isReady()
     {
     {
-        return is_array($this->data);
+        return ! empty($this->data);
     }
     }
 
 
     /**
     /**
@@ -170,14 +170,9 @@ abstract class Page
      */
      */
     public function getData()
     public function getData()
     {
     {
-        if (empty($this->data)) {
-            $this->data = [];
-        }
-        return $this->data + [
+        return [
             'pageTitle' => $this->pageTitle(),
             'pageTitle' => $this->pageTitle(),
             'pageHeaders' => $this->pageHeaders(),
             'pageHeaders' => $this->pageHeaders(),
-            'fLang' => __('lang_identifier'),
-            'fDirection' => __('lang_direction'),
             'fTitle' => $this->config['o_board_title'],
             'fTitle' => $this->config['o_board_title'],
             'fDescription' => $this->config['o_board_desc'],
             'fDescription' => $this->config['o_board_desc'],
             'fNavigation' => $this->fNavigation(),
             'fNavigation' => $this->fNavigation(),
@@ -185,7 +180,7 @@ abstract class Page
             'fAnnounce' => $this->fAnnounce(),
             'fAnnounce' => $this->fAnnounce(),
             'fRootLink' => $this->c->Router->link('Index'),
             'fRootLink' => $this->c->Router->link('Index'),
             'fIswev' => $this->getIswev(),
             'fIswev' => $this->getIswev(),
-        ];
+        ] + $this->data;
     }
     }
 
 
     /**
     /**
@@ -194,10 +189,8 @@ abstract class Page
      */
      */
     protected function getIswev()
     protected function getIswev()
     {
     {
-        if ($this->config['o_maintenance'] == '1') {
-            if ($this->c->user->isAdmin) {
-                $this->iswev['w'][] = __('Maintenance mode enabled', $this->c->Router->link('AdminOptions', ['#' => 'maintenance']));
-            }
+        if ($this->config['o_maintenance'] == '1' && $this->c->user->isAdmin) {
+            $this->iswev['w']['maintenance'] = __('Maintenance mode enabled', $this->c->Router->link('AdminOptions', ['#' => 'maintenance']));
         }
         }
         return $this->iswev;
         return $this->iswev;
     }
     }
@@ -215,13 +208,16 @@ abstract class Page
 
 
     /**
     /**
      * Формирует title страницы
      * Формирует title страницы
+     * @param array $titles
      * @return string
      * @return string
      */
      */
-    protected function pageTitle()
+    protected function pageTitle(array $titles = [])
     {
     {
-        $arr = empty($this->titles) ? [] : array_reverse($this->titles);
-        $arr[] = $this->config['o_board_title'];
-        return implode(__('Title separator'), $arr);
+        if (empty($titles)) {
+            $titles = $this->titles;
+        }
+        $titles[] = $this->config['o_board_title'];
+        return implode(__('Title separator'), $titles);
     }
     }
 
 
     /**
     /**
@@ -321,14 +317,15 @@ abstract class Page
     }
     }
 
 
     /**
     /**
-     * Заглушка
-     * @param string $name
-     * @param array $arguments
-     * @throws \RuntimeException
+     * Возращает данные для управления обработкой пользователей онлайн
+     * @param bool $short
+     * @return bool|array
      */
      */
-    public function __call($name, array $arguments)
+    public function getDataForOnline($short = false)
     {
     {
-        throw new RuntimeException("'{$name}' method not found.");
+        return $short
+            ? null !== $this->onlinePos
+            : [$this->onlinePos, $this->onlineType, $this->onlineFilter];
     }
     }
 
 
     /**
     /**
@@ -347,18 +344,6 @@ abstract class Page
         return __('Size unit '.$units[$i], round($size, 2));
         return __('Size unit '.$units[$i], round($size, 2));
     }
     }
 
 
-    /**
-     * Возращает данные для управления обработкой пользователей онлайн
-     * @param bool $short
-     * @return bool|array
-     */
-    public function getDataForOnline($short = false)
-    {
-        return $short
-            ? null !== $this->onlinePos
-            : [$this->onlinePos, $this->onlineType, $this->onlineFilter];
-    }
-
     /**
     /**
      * Возвращает число в формате языка текущего пользователя
      * Возвращает число в формате языка текущего пользователя
      * @param mixed $number
      * @param mixed $number
@@ -421,4 +406,15 @@ abstract class Page
             return $date . ' ' . gmdate($timeFormat, $timestamp);
             return $date . ' ' . gmdate($timeFormat, $timestamp);
         }
         }
     }
     }
+
+    /**
+     * Заглушка
+     * @param string $name
+     * @param array $arguments
+     * @throws \RuntimeException
+     */
+    public function __call($name, array $arguments)
+    {
+        throw new RuntimeException("'{$name}' method not found.");
+    }
 }
 }

+ 6 - 8
app/Models/Pages/Redirect.php

@@ -82,12 +82,10 @@ class Redirect extends Page
         }
         }
 
 
         $this->nameTpl = 'layouts/redirect';
         $this->nameTpl = 'layouts/redirect';
-        $this->titles = [
-            __('Redirecting'),
-        ];
+        $this->titles[] = __('Redirecting');
         $this->data = [
         $this->data = [
-            'Message' => $message,
-            'Timeout' => (int) $this->config['o_redirect_delay'],  //???? перенести в заголовки?
+            'message' => $message,
+            'timeout' => (int) $this->config['o_redirect_delay'],  //???? перенести в заголовки?
         ];
         ];
         return $this;
         return $this;
     }
     }
@@ -96,7 +94,7 @@ class Redirect extends Page
      * Возвращает HTTP заголовки страницы
      * Возвращает HTTP заголовки страницы
      * @return array
      * @return array
      */
      */
-    public function getHeaders()
+    public function httpHeaders()
     {
     {
         // переадресация без вывода сообщения
         // переадресация без вывода сообщения
         if (empty($this->data)) {
         if (empty($this->data)) {
@@ -104,7 +102,7 @@ class Redirect extends Page
                 'Location: ' . $this->link, //????
                 'Location: ' . $this->link, //????
             ];
             ];
         }
         }
-        return parent::getHeaders();
+        return parent::httpHeaders();
     }
     }
 
 
     /**
     /**
@@ -113,7 +111,7 @@ class Redirect extends Page
      */
      */
     public function getData()
     public function getData()
     {
     {
-        $this->data['Link'] = $this->link;
+        $this->data['link'] = $this->link;
         return parent::getData();
         return parent::getData();
     }
     }
 }
 }

+ 5 - 9
app/Models/Pages/Register.php

@@ -69,9 +69,7 @@ class Register extends Page
             return $this->c->Redirect->setPage('Index')->setMessage(__('Reg cancel redirect'));
             return $this->c->Redirect->setPage('Index')->setMessage(__('Reg cancel redirect'));
         }
         }
 
 
-        $this->titles = [
-            __('Register'),
-        ];
+        $this->titles[] = __('Register');
         $this->data = [
         $this->data = [
             'formAction' => $this->c->Router->link('RegisterForm'),
             'formAction' => $this->c->Router->link('RegisterForm'),
             'formToken' => $this->c->Csrf->create('RegisterForm'),
             'formToken' => $this->c->Csrf->create('RegisterForm'),
@@ -88,10 +86,9 @@ class Register extends Page
      * Дополнительная проверка email
      * Дополнительная проверка email
      * @param Validator $v
      * @param Validator $v
      * @param string $username
      * @param string $username
-     * @param int $type
      * @return array
      * @return array
      */
      */
-    public function vCheckEmail(Validator $v, $email, $type)
+    public function vCheckEmail(Validator $v, $email)
     {
     {
         $error = false;
         $error = false;
         // email забанен
         // email забанен
@@ -101,17 +98,16 @@ class Register extends Page
         } elseif (empty($v->getErrors()) && $this->c->UserMapper->getUser($email, 'email') !== 0) {
         } elseif (empty($v->getErrors()) && $this->c->UserMapper->getUser($email, 'email') !== 0) {
             $error = __('Dupe email');
             $error = __('Dupe email');
         }
         }
-        return [$email, $type, $error];
+        return [$email, $error];
     }
     }
 
 
     /**
     /**
      * Дополнительная проверка username
      * Дополнительная проверка username
      * @param Validator $v
      * @param Validator $v
      * @param string $username
      * @param string $username
-     * @param int $type
      * @return array
      * @return array
      */
      */
-    public function vCheckUsername(Validator $v, $username, $type)
+    public function vCheckUsername(Validator $v, $username)
     {
     {
         $username = preg_replace('%\s+%su', ' ', $username);
         $username = preg_replace('%\s+%su', ' ', $username);
         $error = false;
         $error = false;
@@ -130,7 +126,7 @@ class Register extends Page
         } elseif (empty($v->getErrors()) && ! $this->c->UserMapper->isUnique($username)) {
         } elseif (empty($v->getErrors()) && ! $this->c->UserMapper->isUnique($username)) {
             $error = __('Username not unique');
             $error = __('Username not unique');
         }
         }
-        return [$username, $type, $error];
+        return [$username, $error];
     }
     }
 
 
     /**
     /**

+ 2 - 6
app/Models/Pages/Rules.php

@@ -28,9 +28,7 @@ class Rules extends Page
      */
      */
     public function view()
     public function view()
     {
     {
-        $this->titles = [
-            __('Forum rules'),
-        ];
+        $this->titles[] = __('Forum rules');
         $this->data = [
         $this->data = [
             'title' => __('Forum rules'),
             'title' => __('Forum rules'),
             'rules' => $this->config['o_rules_message'],
             'rules' => $this->config['o_rules_message'],
@@ -49,9 +47,7 @@ class Rules extends Page
         $this->robots = 'noindex';
         $this->robots = 'noindex';
         $this->c->Lang->load('register');
         $this->c->Lang->load('register');
 
 
-        $this->titles = [
-            __('Forum rules'),
-        ];
+        $this->titles[] = __('Forum rules');
         $this->data = [
         $this->data = [
             'title' => __('Forum rules'),
             'title' => __('Forum rules'),
             'rules' => $this->config['o_rules'] == '1' ?
             'rules' => $this->config['o_rules'] == '1' ?

+ 2 - 2
app/bootstrap.php

@@ -51,10 +51,10 @@ while (! $page instanceof Page && $cur = array_pop($controllers)) {
 if ($page->getDataForOnline(true)) {
 if ($page->getDataForOnline(true)) {
     $c->Online->handle($page);
     $c->Online->handle($page);
 }
 }
-$tpl = $c->View->setPage($page)->outputPage();
+$tpl = $c->View->rendering($page);
 if ($c->DEBUG > 0) {
 if ($c->DEBUG > 0) {
     $debug = $c->Debug->debug();
     $debug = $c->Debug->debug();
-    $debug = $c->View->setPage($debug)->outputPage();
+    $debug = $c->View->rendering($debug);
     $tpl = str_replace('<!-- debuginfo -->', $debug, $tpl);
     $tpl = str_replace('<!-- debuginfo -->', $debug, $tpl);
 }
 }
 exit($tpl);
 exit($tpl);

+ 1 - 1
app/templates/layouts/install.tpl

@@ -1,5 +1,5 @@
 <!DOCTYPE html>
 <!DOCTYPE html>
-<html lang="{!! $fLang !!}" dir="{!! $fDirection !!}">
+<html lang="{!! __('lang_identifier') !!}" dir="{!! __('lang_direction') !!}">
 <head>
 <head>
   <meta charset="utf-8">
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">

+ 1 - 1
app/templates/layouts/main.tpl

@@ -1,5 +1,5 @@
 <!DOCTYPE html>
 <!DOCTYPE html>
-<html lang="{!! $fLang !!}" dir="{!! $fDirection !!}">
+<html lang="{!! __('lang_identifier') !!}" dir="{!! __('lang_direction') !!}">
 <head>
 <head>
   <meta charset="utf-8">
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">

+ 5 - 5
app/templates/layouts/redirect.tpl

@@ -1,11 +1,11 @@
 <!DOCTYPE html>
 <!DOCTYPE html>
-<html lang="{!! $fLang !!} dir="{!! $fDirection !!}">
+<html lang="{!! __('lang_identifier') !!} dir="{!! __('lang_direction') !!}">
 <head>
 <head>
   <meta charset="utf-8">
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
-  <meta http-equiv="refresh" content="{!! $Timeout !!};URL={{ $Link }}">
+  <meta http-equiv="refresh" content="{!! $timeout !!};URL={{ $link }}">
   <title>{{ $pageTitle }}</title>
   <title>{{ $pageTitle }}</title>
-@foreach($pageHeads as $cur)
+@foreach($pageHeaders as $cur)
   <{!! $cur !!}>
   <{!! $cur !!}>
 @endforeach
 @endforeach
 </head>
 </head>
@@ -13,8 +13,8 @@
   <div class="f-wrap">
   <div class="f-wrap">
     <section class="f-main f-redirect">
     <section class="f-main f-redirect">
       <h2>{!! __('Redirecting') !!}</h2>
       <h2>{!! __('Redirecting') !!}</h2>
-      <p>{!! $Message !!}</p>
-      <p><a href="{{ $Link }}">{!! __('Click redirect') !!}</a></p>
+      <p>{!! $message !!}</p>
+      <p><a href="{{ $link }}">{!! __('Click redirect') !!}</a></p>
     </section>
     </section>
 <!-- debuginfo -->
 <!-- debuginfo -->
   </div>
   </div>