From 0c9ae85fdc1636c430897fa91ca3d5a71cc33bf2 Mon Sep 17 00:00:00 2001 From: "CORP\\phedor" Date: Fri, 6 Apr 2018 11:40:37 +0300 Subject: [PATCH 01/33] =?UTF-8?q?=D0=BD=D0=B5=20=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=D1=8C=D0=BD=D0=BE=20=D0=B2=D1=8B=D0=B7=D1=8B=D0=B2?= =?UTF-8?q?=D0=B0=D0=BB=D0=B0=D1=81=D1=8C=20=D1=84=D1=83=D0=BD=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Database/PDOStatement.php | 2 +- src/Tools/String.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Database/PDOStatement.php b/src/Database/PDOStatement.php index 1274e6e..4561611 100644 --- a/src/Database/PDOStatement.php +++ b/src/Database/PDOStatement.php @@ -86,7 +86,7 @@ class Database_PDOStatement extends PDOStatement implements IteratorAggregate } function getArray($name) { - return strToArray($this->fields[$name]); + return Tools_String::strToArray($this->fields[$name]); } function getRecordCount() { diff --git a/src/Tools/String.php b/src/Tools/String.php index bd6c2de..41fd465 100644 --- a/src/Tools/String.php +++ b/src/Tools/String.php @@ -15,7 +15,7 @@ class Tools_String { if ($in_subarr > 0) { // already in sub-array? $subarr[$in_subarr][] = $tok; if ('}' === substr($tok, -1, 1)) { // check to see if we just added last component - $res[] = strToArray(implode(',', $subarr[$in_subarr])); + $res[] = static::strToArray(implode(',', $subarr[$in_subarr])); $in_subarr--; } } elseif ($tok{0} === '{') { // we're inside a new sub-array @@ -25,7 +25,7 @@ class Tools_String { $subarr[$in_subarr] = array(); $subarr[$in_subarr][] = $tok; } else { - $res[] = strToArray($tok); + $res[] = static::strToArray($tok); } } else { // not sub-array $val = trim($tok, '"'); // remove " (surrounding strings) From dbac85204f3ffdfa869f4336e2baec20a7f0905e Mon Sep 17 00:00:00 2001 From: Anatoly Date: Thu, 7 Jun 2018 13:33:18 +0300 Subject: [PATCH 02/33] whitelist --- src/Filter/Login.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Filter/Login.php b/src/Filter/Login.php index 70ad01d..2891e2e 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -17,7 +17,8 @@ class Filter_Login extends Filter_Filter //AJAX-Реквесты для которых не требуется авторизация, потребовалось для сбора статистики public $whiteRequestList = [['module' => "requiredcontent", "action" => "getcount"], ['module' => "requiredcontent", "action" => "teststructure"], - ['module' => "requiredcontent", "action" => "specialdump"] + ['module' => "requiredcontent", "action" => "specialdump"], + ['module' => "requiredcontent", "action" => "MDOUMonitoring"] ]; /** * Проверка авторизации From cbd50862ce920c74a6093561de0a802e49a3514b Mon Sep 17 00:00:00 2001 From: "CORP\\phedor" Date: Fri, 8 Jun 2018 15:20:43 +0300 Subject: [PATCH 03/33] =?UTF-8?q?schema=20=D0=B4=D0=BB=D1=8F=20bd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Component.php | 2 +- src/Controller/Service.php | 5 ++++- src/Database.php | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Controller/Component.php b/src/Controller/Component.php index efc3cdf..e5a4bc2 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -273,7 +273,7 @@ class Controller_Component $instance->componentsConfig[] = $editor; } else { global $componentsConfig; - $componentsConfig[] = $editor; + $componentsConfig[] = $editor; } } diff --git a/src/Controller/Service.php b/src/Controller/Service.php index 46f96aa..5bc439f 100644 --- a/src/Controller/Service.php +++ b/src/Controller/Service.php @@ -5,11 +5,14 @@ */ class Controller_Service { - public $viewPath = array(); + public $viewPath = []; + public $webPath = []; public $registry; // Registry->getInstance public $template; public $templatePath; public $COMPONENTS_WEB; + + public $db; public function getTemplatePath($name) { diff --git a/src/Database.php b/src/Database.php index 415619d..9544526 100644 --- a/src/Database.php +++ b/src/Database.php @@ -35,6 +35,10 @@ class Database extends PDO if ($dsn['phptype'] == 'pgsql') { $connection->query('SET client_encoding="UTF-8"'); } + + if (isset($dsn['schema'])) { + $connection->query('SET search_path TO ' . $dsn['schema']); + } } if ($dsn['phptype'] == 'sqlite') { /*.Database.*/$connection = new static("{$dsn['phptype']}:{$dsn['database']}"); From aa61c2ddc10c4a1f5bccd7f217561637ac0b76d1 Mon Sep 17 00:00:00 2001 From: Origami11 Date: Tue, 14 Jan 2020 10:40:01 +0300 Subject: [PATCH 04/33] =?UTF-8?q?=D0=A1=D0=B8=D0=BD=D1=85=D1=80=D0=BE?= =?UTF-8?q?=D0=BD=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=81=20=D1=81?= =?UTF-8?q?=D0=B5=D1=80=D0=B2=D0=B5=D1=80=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Component.php | 3 ++- src/Controller/Service.php | 9 +++++++++ src/Database.php | 6 ++++++ src/Database/PDOStatement.php | 8 +++++++- src/Database/Statement.php | 18 ++++++------------ src/Excel/Number.php | 2 +- src/Filter/Login.php | 16 +++++++++++----- src/Filter/UserAccess.php | 2 +- src/Tools/TemplateImage.php | 2 +- src/Validator/Rule/Date.php | 1 + src/View/Page.php | 4 ++-- 11 files changed, 47 insertions(+), 24 deletions(-) diff --git a/src/Controller/Component.php b/src/Controller/Component.php index e5a4bc2..65587fb 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -23,7 +23,8 @@ class ComponentRequest { if ($key == 'active_page') { return $this->r->get($key); } - if ($arr = $this->r->get($key)) { + $arr = $this->r->get($key); + if ($arr !== NULL) { if (is_array($arr)) { return Arr::get($arr, $this->component_id, $default); } else { diff --git a/src/Controller/Service.php b/src/Controller/Service.php index 5bc439f..a1f7185 100644 --- a/src/Controller/Service.php +++ b/src/Controller/Service.php @@ -61,5 +61,14 @@ class Controller_Service } return $result; } + + function getInfo() { + $filename = Path::join($this->viewPath[0], 'install.json'); + if (file_exists($filename)) { + $settings = json_decode(File::getContents($filename), true); + return $settings; + } + return array(); + } } diff --git a/src/Database.php b/src/Database.php index 9544526..def3072 100644 --- a/src/Database.php +++ b/src/Database.php @@ -13,8 +13,14 @@ class Database extends PDO { parent::__construct($dsn, $username, $password); $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $this->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Database_PDOStatement', array())); } + + function prepare($sql, $args = []) { + $result = parent::prepare($sql, $args); + return $result; + } public function getDSN() { diff --git a/src/Database/PDOStatement.php b/src/Database/PDOStatement.php index 4561611..43c7564 100644 --- a/src/Database/PDOStatement.php +++ b/src/Database/PDOStatement.php @@ -74,7 +74,7 @@ class Database_PDOStatement extends PDOStatement implements IteratorAggregate } function getString($name) { - return $this->fields[$name]; + return isset($this->fields[$name]) ? $this->fields[$name]: null; } function getBoolean($name) { @@ -92,4 +92,10 @@ class Database_PDOStatement extends PDOStatement implements IteratorAggregate function getRecordCount() { return count($this->cache); } + + function execute($args = null) { + $result = parent::execute($args); + return $result; + } + } diff --git a/src/Database/Statement.php b/src/Database/Statement.php index 80b77da..dbcee3a 100644 --- a/src/Database/Statement.php +++ b/src/Database/Statement.php @@ -17,33 +17,27 @@ class Database_Statement $this->conn = $conn; } - function setInt($n, $value) - { + function setInt($n, $value) { $this->binds [] = array($n, $value, PDO::PARAM_INT); } - function setString($n, $value) - { + function setString($n, $value) { $this->binds [] = array($n, $value, PDO::PARAM_STR); } - function setBlob($n, $value) - { + function setBlob($n, $value) { $this->binds [] = array($n, $value, PDO::PARAM_LOB); } - function setLimit($limit) - { + function setLimit($limit) { $this->limit = $limit; } - function setOffset($offset) - { + function setOffset($offset) { $this->offset = $offset; } - function executeQuery() - { + function executeQuery() { if ($this->limit) { $this->query .= " LIMIT {$this->limit} OFFSET {$this->offset}"; } diff --git a/src/Excel/Number.php b/src/Excel/Number.php index 66dd6b6..dfc220a 100644 --- a/src/Excel/Number.php +++ b/src/Excel/Number.php @@ -6,7 +6,7 @@ class Excel_Number function __construct($value) { - $this->value = intval($value); + $this->value = (int)($value); } function getString() diff --git a/src/Filter/Login.php b/src/Filter/Login.php index 2891e2e..b7e9cac 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -13,13 +13,18 @@ class Filter_Login extends Filter_Filter const SESSION_BROWSER_SIGN_SECRET = '@w3dsju45Msk#'; const SESSION_BROWSER_SIGN_KEYNAME = 'session.app.browser.sign'; public $mode = 'ajax'; + public $user; //AJAX-Реквесты для которых не требуется авторизация, потребовалось для сбора статистики - public $whiteRequestList = [['module' => "requiredcontent", "action" => "getcount"], - ['module' => "requiredcontent", "action" => "teststructure"], - ['module' => "requiredcontent", "action" => "specialdump"], - ['module' => "requiredcontent", "action" => "MDOUMonitoring"] - ]; + public $whiteRequestList = [ + ['module' => "requiredcontent", "action" => "getcount"], + ['module' => "requiredcontent", "action" => "teststructure"], + ['module' => "requiredcontent", "action" => "specialdump"], + ['module' => "requiredcontent", "action" => "OrgMonitoring"], + ['module' => "requiredcontent", "action" => "OrgMonitoringSchema"], + ['module' => "appeals", "action" => "changestatus"], + ['module' => "appeals", "action" => "savestatus"] + ]; /** * Проверка авторизации * @return Boolean Авторизовани пользователь или нет @@ -30,6 +35,7 @@ class Filter_Login extends Filter_Filter session_start(); $db = $this->getConnection(); Filter_UserAccess::setUp($db); // Соединение + switch ($request->getAction()) { // Авторизация по постоянному паролю case 'login': diff --git a/src/Filter/UserAccess.php b/src/Filter/UserAccess.php index ce27a66..fbf97b4 100644 --- a/src/Filter/UserAccess.php +++ b/src/Filter/UserAccess.php @@ -62,7 +62,7 @@ class Filter_UserAccess $time = time(); if ($time - $lasttime > self::LIFE_TIME) return null; // Вышло время сессии $id = self::$id; - self::$db->executeQuery("UPDATE users SET lasttime = $time WHERE id_user = $id"); // Время последнего обращения входа + // self::$db->executeQuery("UPDATE users SET lasttime = $time WHERE id_user = $id"); // Время последнего обращения входа } return $result; } diff --git a/src/Tools/TemplateImage.php b/src/Tools/TemplateImage.php index 6ce9a33..171f285 100644 --- a/src/Tools/TemplateImage.php +++ b/src/Tools/TemplateImage.php @@ -134,7 +134,7 @@ class Tools_TemplateImage } if ($value->valign[0]) { - $valign = Drawing::ALIGN_TOP; + $valign = Tools_Drawing::ALIGN_TOP; } elseif ($value->valign[1]) { $valign = Tools_Drawing::ALIGN_CENTER; } else { diff --git a/src/Validator/Rule/Date.php b/src/Validator/Rule/Date.php index be8e17e..166907a 100644 --- a/src/Validator/Rule/Date.php +++ b/src/Validator/Rule/Date.php @@ -15,6 +15,7 @@ class Validator_Rule_Date extends Validator_Rule_Abstract public function isValid(Collection $container, $status = null) { $pattern = "/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})$/"; + $matches = []; return (preg_match($pattern, $container->get($this->field), $matches) && checkdate($matches[2], $matches[1], $matches[3])); } diff --git a/src/View/Page.php b/src/View/Page.php index a280f26..1982fcb 100644 --- a/src/View/Page.php +++ b/src/View/Page.php @@ -8,7 +8,7 @@ class View_Page extends View_View function __construct($data) { // Вставка компонентов на странице - $pattern = '/<(\w+)(\s+[a-zA-Z\-]+=\"[^\"]*\")*\s+tal:replace="structure\s+component:([^\"]*)"[^>]*>/u'; + $pattern = '/<(\w+)(\s+[a-zA-Z\-]+(=\"[^\"]*\")?)*\s+tal:replace="structure\s+component:([^\"]*)"[^>]*>/u'; $matches = array(); preg_match_all($pattern, $data, $matches, PREG_OFFSET_CAPTURE, 0); @@ -20,7 +20,7 @@ class View_Page extends View_View $split[] = array('type' => 'page-text', 'content' => $text, 'component' => '', 'module' => ''); } $offset = $match[1] + strlen($match[0]); - $split[] = $this->replaceContent($matches[3][$key][0], $matches[3][$key][1]); + $split[] = $this->replaceContent($matches[4][$key][0], $matches[4][$key][1]); } $text = $this->fixHTML(substr($data, $offset)); if (trim($text)) { From ea40d10f60af9e46dbdef9c3c3f9e2eeff89ab4f Mon Sep 17 00:00:00 2001 From: Anatoly Date: Fri, 17 Jan 2020 11:33:23 +0300 Subject: [PATCH 05/33] edits --- src/Database.php | 1 - src/Filter/Login.php | 8 +++-- src/View/Page.php | 78 -------------------------------------------- 3 files changed, 5 insertions(+), 82 deletions(-) delete mode 100644 src/View/Page.php diff --git a/src/Database.php b/src/Database.php index 415619d..8b73743 100644 --- a/src/Database.php +++ b/src/Database.php @@ -126,7 +126,6 @@ class Database extends PDO $sql = "INSERT INTO $table (" . implode(",", array_keys($values)) . ") VALUES (" . implode(",", array_keys($prep)). ")"; - if ($return_id) { if ($this->isPostgres()){ $sql = $sql." RETURNING $index"; diff --git a/src/Filter/Login.php b/src/Filter/Login.php index 70ad01d..4ab48e8 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -17,7 +17,8 @@ class Filter_Login extends Filter_Filter //AJAX-Реквесты для которых не требуется авторизация, потребовалось для сбора статистики public $whiteRequestList = [['module' => "requiredcontent", "action" => "getcount"], ['module' => "requiredcontent", "action" => "teststructure"], - ['module' => "requiredcontent", "action" => "specialdump"] + ['module' => "requiredcontent", "action" => "specialdump"], + ['module' => "requiredcontent", "action" => "OrgMonitoringSchema"] ]; /** * Проверка авторизации @@ -51,9 +52,10 @@ class Filter_Login extends Filter_Filter if (md5($password) == $userPassword) { // password $this->enter($db, $result); return true; - } + } else { + $request->set('error', true); + } } - $request->set('error', true); break; case 'logout': // Выход session_destroy(); diff --git a/src/View/Page.php b/src/View/Page.php deleted file mode 100644 index a280f26..0000000 --- a/src/View/Page.php +++ /dev/null @@ -1,78 +0,0 @@ -]*>/u'; - $matches = array(); - preg_match_all($pattern, $data, $matches, PREG_OFFSET_CAPTURE, 0); - - $split = array(); - $offset = 0; - foreach ($matches[0] as $key => $match) { - $text = $this->fixHTML(substr($data, $offset, $match[1] - $offset)); - if (trim($text)) { - $split[] = array('type' => 'page-text', 'content' => $text, 'component' => '', 'module' => ''); - } - $offset = $match[1] + strlen($match[0]); - $split[] = $this->replaceContent($matches[3][$key][0], $matches[3][$key][1]); - } - $text = $this->fixHTML(substr($data, $offset)); - if (trim($text)) { - $split[] = array('type' => 'page-text', 'content' => $text, 'component' => '', 'module' => ''); - } - - $this->text = $this->merge($split); - } - - function fixHTML($fragment) { - return $fragment; - } - - function merge($data) { - if (count($data) == 0) { - $data[] = array('type' => 'page-text', 'content' =>"

Добавьте текст

", 'component' => '', 'module' => ''); - } - $result = array(); - foreach($data as $key => $part) { - $result[] = $part['content']; - } - return implode("", $result); - } - - function replaceContent($match, $offset) - { - //$result = phptal_component($match, $offset); - /*.Controller_Component.*/$component = null; - - - if(class_exists("Controller_Site")){ //Если мы в CMS2 - $component = Controller_Site::loadComponent($match); - } else { - global $db, $registry; // - $component = Controller_Component::loadComponent($match, $db, $registry); - } - - $req = new HttpRequest(); - unset($req['active_page']); - - $info = $component->getInfo(); - $result = $component->execute($req); - - if (is_string($result)) { - return array('type' => 'page-component', 'content' => $result, 'component' => $match); - } else { - $this->setView('view' . $this->counter++, $result); - return array('type' => 'page-component', 'content' => $result->execute(), 'component' => $match); - } - } - - function execute() { - return $this->text; - } -} From 82c129305eb51974a68ae6b028cc3202d005936e Mon Sep 17 00:00:00 2001 From: Origami11 Date: Mon, 2 Nov 2020 18:00:14 +0300 Subject: [PATCH 06/33] =?UTF-8?q?=D0=90=D0=BB=D1=8C=D1=82=D0=B5=D1=80?= =?UTF-8?q?=D0=BD=D0=B0=D1=82=D0=B8=D0=B2=D0=BD=D1=8B=D0=B9=20=D0=B1=D0=B5?= =?UTF-8?q?=D0=BB=D1=8B=D0=B9=20=D1=81=D0=BF=D0=B8=D1=81=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Action.php | 1 + src/Controller/Component.php | 16 +++++-- src/Controller/Service.php | 14 ++++++- src/Database.php | 13 +++++- src/Database/PDOStatement.php | 12 ++++-- src/Database/Statement.php | 18 +++----- src/Excel/Number.php | 2 +- src/Filter/Filter.php | 2 +- src/Filter/Login.php | 18 ++++---- src/Filter/UserAccess.php | 2 +- src/Form/Form.php | 4 +- src/Path.php | 4 +- src/Registry.php | 2 +- src/Tools/String.php | 4 +- src/Tools/TemplateImage.php | 18 ++++---- src/Validator/Rule/Date.php | 1 + src/Validator/Validator.php | 2 +- src/View/Page.php | 78 ----------------------------------- src/tales.php | 2 +- 19 files changed, 82 insertions(+), 131 deletions(-) delete mode 100644 src/View/Page.php diff --git a/src/Controller/Action.php b/src/Controller/Action.php index 5d2d13e..6045d5b 100644 --- a/src/Controller/Action.php +++ b/src/Controller/Action.php @@ -331,6 +331,7 @@ class Controller_Action if ($this->view instanceof View_View) { $this->view->assignValues($this->ctrlValues); + /*.Widgets_Widget.*/$node = null; foreach ($this->childNodes as $name => $node) { $node->make($this); $this->view->setView($name, $node->view); diff --git a/src/Controller/Component.php b/src/Controller/Component.php index c389198..d77392e 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -23,7 +23,8 @@ class ComponentRequest { if ($key == 'active_page') { return $this->r->get($key); } - if ($arr = $this->r->get($key)) { + $arr = $this->r->get($key); + if ($arr !== NULL) { if (is_array($arr)) { return Arr::get($arr, $this->component_id, $default); } else { @@ -127,6 +128,14 @@ class Controller_Component } public function getTemplatePath($name) { + /*.Settings.*/$registry = $this->registry; + $template = ($this->template) ? $this->template : $registry->readKey(array('system', 'template')); + foreach ($this->viewPath as $index => $viewPath) { + if(is_dir(Path::join($this->viewPath[$index], 'templates', $template))) { + return Path::join($this->viewPath[$index], 'templates', $template, $name); + } + } + return Path::join($this->viewPath[0], 'templates', 'modern', $name); } @@ -182,7 +191,7 @@ class Controller_Component $options = new Form_OptionFactory($this->db, $this->registry); $settings = $this->getInfo(); - $form->addFieldList($settings['parameter'], $options); + $form->addFieldList($settings['parameter'], $options); $view->form = $form; $view->component = $settings['component']; @@ -271,10 +280,9 @@ class Controller_Component if(class_exists("Controller_Site")){ //Если мы в CMS2 $instance = Controller_Site::getInstance(); $instance->componentsConfig[] = $editor; - }else{ + } else { global $componentsConfig; $componentsConfig[] = $editor; - } } diff --git a/src/Controller/Service.php b/src/Controller/Service.php index 46f96aa..a1f7185 100644 --- a/src/Controller/Service.php +++ b/src/Controller/Service.php @@ -5,11 +5,14 @@ */ class Controller_Service { - public $viewPath = array(); + public $viewPath = []; + public $webPath = []; public $registry; // Registry->getInstance public $template; public $templatePath; public $COMPONENTS_WEB; + + public $db; public function getTemplatePath($name) { @@ -58,5 +61,14 @@ class Controller_Service } return $result; } + + function getInfo() { + $filename = Path::join($this->viewPath[0], 'install.json'); + if (file_exists($filename)) { + $settings = json_decode(File::getContents($filename), true); + return $settings; + } + return array(); + } } diff --git a/src/Database.php b/src/Database.php index b08d864..def3072 100644 --- a/src/Database.php +++ b/src/Database.php @@ -1,6 +1,7 @@ require_once "Database/PDOStatement.php"; + /** * Класс оболочка для PDO для замены Creole */ @@ -12,8 +13,14 @@ class Database extends PDO { parent::__construct($dsn, $username, $password); $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + $this->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Database_PDOStatement', array())); } + + function prepare($sql, $args = []) { + $result = parent::prepare($sql, $args); + return $result; + } public function getDSN() { @@ -34,6 +41,10 @@ class Database extends PDO if ($dsn['phptype'] == 'pgsql') { $connection->query('SET client_encoding="UTF-8"'); } + + if (isset($dsn['schema'])) { + $connection->query('SET search_path TO ' . $dsn['schema']); + } } if ($dsn['phptype'] == 'sqlite') { /*.Database.*/$connection = new static("{$dsn['phptype']}:{$dsn['database']}"); @@ -81,7 +92,7 @@ class Database extends PDO /** * Извлекает из базы первый элемент по запросу */ - public function fetchOneArray($query,$values=null) + public function fetchOneArray($query, $values = null) { /*.Database_PDOStatement.*/$sth = $this->prepare($query); $prep = $this->prepareValues($values); diff --git a/src/Database/PDOStatement.php b/src/Database/PDOStatement.php index 0cbd058..43c7564 100644 --- a/src/Database/PDOStatement.php +++ b/src/Database/PDOStatement.php @@ -1,7 +1,5 @@ fields[$name]; + return isset($this->fields[$name]) ? $this->fields[$name]: null; } function getBoolean($name) { @@ -88,10 +86,16 @@ class Database_PDOStatement extends PDOStatement implements IteratorAggregate } function getArray($name) { - return strToArray($this->fields[$name]); + return Tools_String::strToArray($this->fields[$name]); } function getRecordCount() { return count($this->cache); } + + function execute($args = null) { + $result = parent::execute($args); + return $result; + } + } diff --git a/src/Database/Statement.php b/src/Database/Statement.php index 80b77da..dbcee3a 100644 --- a/src/Database/Statement.php +++ b/src/Database/Statement.php @@ -17,33 +17,27 @@ class Database_Statement $this->conn = $conn; } - function setInt($n, $value) - { + function setInt($n, $value) { $this->binds [] = array($n, $value, PDO::PARAM_INT); } - function setString($n, $value) - { + function setString($n, $value) { $this->binds [] = array($n, $value, PDO::PARAM_STR); } - function setBlob($n, $value) - { + function setBlob($n, $value) { $this->binds [] = array($n, $value, PDO::PARAM_LOB); } - function setLimit($limit) - { + function setLimit($limit) { $this->limit = $limit; } - function setOffset($offset) - { + function setOffset($offset) { $this->offset = $offset; } - function executeQuery() - { + function executeQuery() { if ($this->limit) { $this->query .= " LIMIT {$this->limit} OFFSET {$this->offset}"; } diff --git a/src/Excel/Number.php b/src/Excel/Number.php index 66dd6b6..dfc220a 100644 --- a/src/Excel/Number.php +++ b/src/Excel/Number.php @@ -6,7 +6,7 @@ class Excel_Number function __construct($value) { - $this->value = intval($value); + $this->value = (int)($value); } function getString() diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index 8140e8f..e5135dc 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -6,7 +6,7 @@ class Filter_Filter { public $processor; - public function __construct(/*.Filter_Filter.*/$processor) + public function __construct(/*.Controller_Action.*/$processor) { $this->processor = $processor; } diff --git a/src/Filter/Login.php b/src/Filter/Login.php index 70ad01d..e2b5cff 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -13,12 +13,8 @@ class Filter_Login extends Filter_Filter const SESSION_BROWSER_SIGN_SECRET = '@w3dsju45Msk#'; const SESSION_BROWSER_SIGN_KEYNAME = 'session.app.browser.sign'; public $mode = 'ajax'; + public $user; - //AJAX-Реквесты для которых не требуется авторизация, потребовалось для сбора статистики - public $whiteRequestList = [['module' => "requiredcontent", "action" => "getcount"], - ['module' => "requiredcontent", "action" => "teststructure"], - ['module' => "requiredcontent", "action" => "specialdump"] - ]; /** * Проверка авторизации * @return Boolean Авторизовани пользователь или нет @@ -29,6 +25,7 @@ class Filter_Login extends Filter_Filter session_start(); $db = $this->getConnection(); Filter_UserAccess::setUp($db); // Соединение + switch ($request->getAction()) { // Авторизация по постоянному паролю case 'login': @@ -142,7 +139,7 @@ class Filter_Login extends Filter_Filter // Параметры при неправильной авторизации // Действия по умолчанию !! Возможно переход на форму регистрации if ($request->get('mode') == 'ajax') { - if (!$this->requestIsWhite($request, $this->whiteRequestList)) { + if (!$this->requestIsWhite($request)) { return json_encode(array('result' => 'fail', 'message' =>"NOT_AUTHORIZED")); } } else { @@ -165,11 +162,14 @@ class Filter_Login extends Filter_Filter * Проверка на попадание реквеста в белый список */ - public function requestIsWhite(Collection $request, $whiteRequestList){ + public function requestIsWhite(Collection $request) { $module = $request->get('module'); $action = $request->get('action'); - foreach ($whiteRequestList as $whiteRequest) { - if ($module == $whiteRequest['module'] && $action == $whiteRequest['action']) { + + $file = Path::join(CMS_PATH, 'modules', $module, 'filters', 'white.php'); + if (file_exists($file)) { + $whiteList = include $file; + if (in_array($action, $whiteList)) { return true; } } diff --git a/src/Filter/UserAccess.php b/src/Filter/UserAccess.php index ce27a66..fbf97b4 100644 --- a/src/Filter/UserAccess.php +++ b/src/Filter/UserAccess.php @@ -62,7 +62,7 @@ class Filter_UserAccess $time = time(); if ($time - $lasttime > self::LIFE_TIME) return null; // Вышло время сессии $id = self::$id; - self::$db->executeQuery("UPDATE users SET lasttime = $time WHERE id_user = $id"); // Время последнего обращения входа + // self::$db->executeQuery("UPDATE users SET lasttime = $time WHERE id_user = $id"); // Время последнего обращения входа } return $result; } diff --git a/src/Form/Form.php b/src/Form/Form.php index 47a1854..2d6baab 100644 --- a/src/Form/Form.php +++ b/src/Form/Form.php @@ -105,8 +105,8 @@ class Form_Form extends View_View { public function addFieldClass($name, $class) { $this->constructor [$name] = $class; - } - + } + /** * Добавляет одно поле ввода на форму */ diff --git a/src/Path.php b/src/Path.php index 9835f88..ba78789 100644 --- a/src/Path.php +++ b/src/Path.php @@ -126,7 +126,7 @@ class Path * * @return array */ - public static function listFromString ($path) + public static function listFromString($path) { assert(is_string($path)); @@ -287,7 +287,7 @@ class Path $result [] = $parts->getParts(); } // При обьединении ссылок можно обьеденить path, query, fragment - $path = implode(self::SEPARATOR, call_user_func_array('array_merge', $result)); + $path = implode(self::SEPARATOR, self::optimize(call_user_func_array('array_merge', $result))); $parts0->url['path'] = ($parts0->isAbsolute()) ? '/' . $path : $path; return $parts0; } diff --git a/src/Registry.php b/src/Registry.php index f2b7673..5a2d871 100644 --- a/src/Registry.php +++ b/src/Registry.php @@ -1,6 +1,6 @@ +/// /** * http://www.patternsforphp.com/wiki/Registry diff --git a/src/Tools/String.php b/src/Tools/String.php index bd6c2de..41fd465 100644 --- a/src/Tools/String.php +++ b/src/Tools/String.php @@ -15,7 +15,7 @@ class Tools_String { if ($in_subarr > 0) { // already in sub-array? $subarr[$in_subarr][] = $tok; if ('}' === substr($tok, -1, 1)) { // check to see if we just added last component - $res[] = strToArray(implode(',', $subarr[$in_subarr])); + $res[] = static::strToArray(implode(',', $subarr[$in_subarr])); $in_subarr--; } } elseif ($tok{0} === '{') { // we're inside a new sub-array @@ -25,7 +25,7 @@ class Tools_String { $subarr[$in_subarr] = array(); $subarr[$in_subarr][] = $tok; } else { - $res[] = strToArray($tok); + $res[] = static::strToArray($tok); } } else { // not sub-array $val = trim($tok, '"'); // remove " (surrounding strings) diff --git a/src/Tools/TemplateImage.php b/src/Tools/TemplateImage.php index 31bdfcc..171f285 100644 --- a/src/Tools/TemplateImage.php +++ b/src/Tools/TemplateImage.php @@ -122,28 +122,26 @@ class Tools_TemplateImage $text = strtr($text, $this->context); $size = $value->fontSize; - fb('font-style'); - fb($value->fontStyle); $fontfile = $this->getFontFile($value->fontFamily . $this->fontSuffix($value->fontStyle)); $color = intval(substr($value->color, 1), 16); if ($value->align[0]) { - $align = Drawing::ALIGN_LEFT; + $align = Tools_Drawing::ALIGN_LEFT; } elseif ($value->align[2]) { - $align = Drawing::ALIGN_RIGHT; + $align = Tools_Drawing::ALIGN_RIGHT; } else { - $align = Drawing::ALIGN_CENTER; + $align = Tools_Drawing::ALIGN_CENTER; } if ($value->valign[0]) { - $valign = Drawing::ALIGN_TOP; + $valign = Tools_Drawing::ALIGN_TOP; } elseif ($value->valign[1]) { - $valign = Drawing::ALIGN_CENTER; + $valign = Tools_Drawing::ALIGN_CENTER; } else { - $valign = Drawing::ALIGN_BOTTOM; + $valign = Tools_Drawing::ALIGN_BOTTOM; } - Drawing::imagettftextbox($this->image, $size, 0, $value->left, $value->top, $color, $fontfile, $text, + Tools_Drawing::imagettftextbox($this->image, $size, 0, $value->left, $value->top, $color, $fontfile, $text, $value->width, $value->height, $align, $valign); } @@ -154,7 +152,7 @@ class Tools_TemplateImage function encode($text) { assert(is_string($text)); - return iconv("WINDOWS-1251", "UTF-8", $text); + return $text; //iconv("WINDOWS-1251", "UTF-8", $text); } function setSize($new_width, $new_height) diff --git a/src/Validator/Rule/Date.php b/src/Validator/Rule/Date.php index be8e17e..166907a 100644 --- a/src/Validator/Rule/Date.php +++ b/src/Validator/Rule/Date.php @@ -15,6 +15,7 @@ class Validator_Rule_Date extends Validator_Rule_Abstract public function isValid(Collection $container, $status = null) { $pattern = "/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{4})$/"; + $matches = []; return (preg_match($pattern, $container->get($this->field), $matches) && checkdate($matches[2], $matches[1], $matches[3])); } diff --git a/src/Validator/Validator.php b/src/Validator/Validator.php index 0af90e3..c6d52f9 100644 --- a/src/Validator/Validator.php +++ b/src/Validator/Validator.php @@ -1,6 +1,6 @@ +/// /** * Проверка коллекции diff --git a/src/View/Page.php b/src/View/Page.php deleted file mode 100644 index a280f26..0000000 --- a/src/View/Page.php +++ /dev/null @@ -1,78 +0,0 @@ -]*>/u'; - $matches = array(); - preg_match_all($pattern, $data, $matches, PREG_OFFSET_CAPTURE, 0); - - $split = array(); - $offset = 0; - foreach ($matches[0] as $key => $match) { - $text = $this->fixHTML(substr($data, $offset, $match[1] - $offset)); - if (trim($text)) { - $split[] = array('type' => 'page-text', 'content' => $text, 'component' => '', 'module' => ''); - } - $offset = $match[1] + strlen($match[0]); - $split[] = $this->replaceContent($matches[3][$key][0], $matches[3][$key][1]); - } - $text = $this->fixHTML(substr($data, $offset)); - if (trim($text)) { - $split[] = array('type' => 'page-text', 'content' => $text, 'component' => '', 'module' => ''); - } - - $this->text = $this->merge($split); - } - - function fixHTML($fragment) { - return $fragment; - } - - function merge($data) { - if (count($data) == 0) { - $data[] = array('type' => 'page-text', 'content' =>"

Добавьте текст

", 'component' => '', 'module' => ''); - } - $result = array(); - foreach($data as $key => $part) { - $result[] = $part['content']; - } - return implode("", $result); - } - - function replaceContent($match, $offset) - { - //$result = phptal_component($match, $offset); - /*.Controller_Component.*/$component = null; - - - if(class_exists("Controller_Site")){ //Если мы в CMS2 - $component = Controller_Site::loadComponent($match); - } else { - global $db, $registry; // - $component = Controller_Component::loadComponent($match, $db, $registry); - } - - $req = new HttpRequest(); - unset($req['active_page']); - - $info = $component->getInfo(); - $result = $component->execute($req); - - if (is_string($result)) { - return array('type' => 'page-component', 'content' => $result, 'component' => $match); - } else { - $this->setView('view' . $this->counter++, $result); - return array('type' => 'page-component', 'content' => $result->execute(), 'component' => $match); - } - } - - function execute() { - return $this->text; - } -} diff --git a/src/tales.php b/src/tales.php index 0d727e8..2c9bc91 100644 --- a/src/tales.php +++ b/src/tales.php @@ -48,7 +48,7 @@ function phptal_component ($expression) { $begin = floatval(microtime(true)); /*.Controller_Component.*/$component = null; - if(class_exists("Controller_Site")){ //Если мы в CMS2 + if (class_exists("Controller_Site")) { //Если мы в CMS2 $component = Controller_Site::loadComponent($expression); } else { global $db, $registry; // Иначе обращаемся к глобальным переменным From cdf7527c4383f8cd28ff3c597640863a82a63fed Mon Sep 17 00:00:00 2001 From: Origami11 Date: Mon, 16 Nov 2020 14:46:18 +0300 Subject: [PATCH 07/33] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Front.php | 1 + src/HttpRequest.php | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Controller/Front.php b/src/Controller/Front.php index af064ad..0d42d4d 100644 --- a/src/Controller/Front.php +++ b/src/Controller/Front.php @@ -56,6 +56,7 @@ class Controller_Front extends Controller_Action $module = $this->loadClass($moduleFile, null, 'Module_'); if ($module) { // Инициализация модуля + $module->front = $this; $module->viewPath = Shortcut::getUrl('modulepath', $name); $module->name = $name; diff --git a/src/HttpRequest.php b/src/HttpRequest.php index 7693177..d34accf 100644 --- a/src/HttpRequest.php +++ b/src/HttpRequest.php @@ -18,11 +18,12 @@ class HttpRequest extends Collection implements ArrayAccess */ public function __construct() { - $list = array ( + $list = [ 'data' => $_REQUEST, 'get' => $_GET, 'post' => $_POST, - 'cookie' => $_COOKIE); + 'cookie' => $_COOKIE + ]; $ajax = $this->isAjax(); foreach ($list as $key => $value) { From b467451c9e222768c2b1472b5c314e0a2dd5d0cf Mon Sep 17 00:00:00 2001 From: origami11 Date: Fri, 29 Jan 2021 16:45:04 +0300 Subject: [PATCH 08/33] =?UTF-8?q?=D0=9E=D0=B1=D1=8C=D1=8F=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=BE?= =?UTF-8?q?=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=B8=D0=BC=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B8=20=D1=81=20php=208?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Database/PDOStatement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Database/PDOStatement.php b/src/Database/PDOStatement.php index 43c7564..68c7622 100644 --- a/src/Database/PDOStatement.php +++ b/src/Database/PDOStatement.php @@ -6,7 +6,7 @@ class Database_PDOStatement extends PDOStatement implements IteratorAggregate public $cache = array(); public $fields; - function getIterator() { + function getIterator(): Iterator { return new Database_StatementIterator($this); } From f570da257da21965cdd0d67e95031b28cf6d9731 Mon Sep 17 00:00:00 2001 From: origami11 Date: Sun, 21 Feb 2021 21:05:39 +0300 Subject: [PATCH 09/33] =?UTF-8?q?=D0=9E=D0=B1=D1=80=D0=B0=D1=89=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=20=D1=8D=D0=BB=D0=B5=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D1=83=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D1=83=D1=8F=20=D1=83=D1=81=D1=82=D0=B0=D1=80=D0=B5=D0=B2=D1=88?= =?UTF-8?q?=D0=B8=D0=B9=20=D1=81=D0=B8=D0=BD=D1=82=D0=B0=D0=BA=D1=81=D0=B8?= =?UTF-8?q?=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Tools/String.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tools/String.php b/src/Tools/String.php index 41fd465..678fd26 100644 --- a/src/Tools/String.php +++ b/src/Tools/String.php @@ -18,7 +18,7 @@ class Tools_String { $res[] = static::strToArray(implode(',', $subarr[$in_subarr])); $in_subarr--; } - } elseif ($tok{0} === '{') { // we're inside a new sub-array + } elseif ($tok[0] === '{') { // we're inside a new sub-array if ('}' !== substr($tok, -1, 1)) { $in_subarr++; // if sub-array has more than one element From 6173eb4892f34f7bea82fc9d5755a30747c8efa9 Mon Sep 17 00:00:00 2001 From: origami11 Date: Mon, 22 Feb 2021 14:07:51 +0300 Subject: [PATCH 10/33] =?UTF-8?q?=D0=A2=D0=B8=D0=BF=D1=8B=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20php-lint=20v2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Collection.php | 6 +++--- src/Connection/HttpResponse.php | 10 +++++----- src/Controller/Action.php | 8 ++++---- src/Controller/Component.php | 26 +++++++++++++------------- src/Controller/Front.php | 2 +- src/Controller/Request.php | 6 +++++- src/Database.php | 12 ++++++------ src/Database/JsonInstall.php | 2 +- src/Database/Manager.php | 14 +++++++------- src/Database/PDOStatement.php | 2 +- src/Database/Statement.php | 4 ++-- src/Database/StatementIterator.php | 2 +- src/Excel/Document.php | 2 +- src/Excel/Table.php | 12 ++++++------ src/Filter/ActionAccess.php | 2 +- src/Filter/ActionLogger.php | 2 +- src/Filter/Filter.php | 2 +- src/Form/Field.php | 2 +- src/Functions.php | 4 ++-- src/HttpRequest.php | 2 +- src/MailAlt.php | 2 +- src/Model/Factory.php | 2 +- src/Path.php | 4 ++-- src/Setup.php | 6 +++--- src/Tools/SQLStatementExtractor.php | 6 +++--- src/Tools/TemplateImage.php | 6 ++++-- src/Validator/Validator.php | 4 ++-- src/View/Pages.php | 2 +- src/View/Top.php | 2 +- src/config.php | 1 + src/tales.php | 2 +- 31 files changed, 83 insertions(+), 76 deletions(-) diff --git a/src/Collection.php b/src/Collection.php index 467175e..1370be3 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -39,7 +39,7 @@ class Collection implements ArrayAccess * * @return void */ - public function set(/*.string.*/$key, /*.any.*/$value) + public function set($key/*: string*/, $value/*: any*/) { $this->data[$key] = $value; } @@ -58,7 +58,7 @@ class Collection implements ArrayAccess public function getInt($key, $default = 0) { - return intval($this->get($key, $default)); + return (int)$this->get($key, $default); } public function getString($key, $default = '') @@ -68,7 +68,7 @@ class Collection implements ArrayAccess public function getNat($key, $default = 1) { - $result = intval($this->get($key, $default)); + $result = (int)$this->get($key, $default); return (($result > 0) ? $result : $default); } diff --git a/src/Connection/HttpResponse.php b/src/Connection/HttpResponse.php index 9e94c9f..7f78bb0 100644 --- a/src/Connection/HttpResponse.php +++ b/src/Connection/HttpResponse.php @@ -36,12 +36,12 @@ class Connection_HttpResponse if (isset($this->param['Transfer-Encoding']) && $this->param['Transfer-Encoding'] == 'chunked') { //$this->data = substr($this->response, $this->offset); - $line = hexdec($this->getLine()); + $nline = hexdec($this->getLine()); $chunk = array(); - while ($line > 0) { - $chunk [] = substr($this->response, $this->offset, $line); - $this->offset += $line; - $line = hexdec($this->getLine()); + while ($nline > 0) { + $chunk [] = substr($this->response, $this->offset, $nline); + $this->offset += $nline; + $nline = hexdec($this->getLine()); } $this->data = implode("", $chunk); diff --git a/src/Controller/Action.php b/src/Controller/Action.php index 6045d5b..df0de65 100644 --- a/src/Controller/Action.php +++ b/src/Controller/Action.php @@ -40,7 +40,7 @@ class Controller_Action private $helpers = array(); // Помошники для действий public $param = array(); // Параметры для ссылки - public /*.Registry.*/$_registry; // Ссылка на реестр + public $_registry/*: Registry*/; // Ссылка на реестр public $_shortcut; public $modulePrefix = ''; public $iconPath = ''; @@ -114,7 +114,7 @@ class Controller_Action if(file_exists($template)) { break; } } - /*.View_Composite.*/$tpl = new $viewClass($template); + $tpl/*: View_Composite*/ = new $viewClass($template); $assets = Path::join(enableHttps(WWW_PATH), "assets", "css"); $tpl->set('icons', $this->iconPath); // Путь к файлам текущей темы @@ -207,7 +207,7 @@ class Controller_Action */ public function nUrl($name, array $param = array()) { - /*.Filter_ActionAccess.*/$access = $this->access; + $access/*: Filter_ActionAccess*/ = $this->access; if ($access == null || $access->checkAction($name)) { return Functions::lcurry(array($this, 'postUrl'), $name, $param); @@ -331,7 +331,7 @@ class Controller_Action if ($this->view instanceof View_View) { $this->view->assignValues($this->ctrlValues); - /*.Widgets_Widget.*/$node = null; + $node/*: Widgets_Widget*/ = null; foreach ($this->childNodes as $name => $node) { $node->make($this); $this->view->setView($name, $node->view); diff --git a/src/Controller/Component.php b/src/Controller/Component.php index d77392e..e4db790 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -54,9 +54,9 @@ class Controller_Component public $component_title; public $COMPONENTS_WEB; - public /*.Settings.*/$registry; - public /*.Database.*/$db; - public /*.Collection.*/$parameter; + public $registry/*: Settings*/; + public $db/*: Database*/; + public $parameter/*: Collection*/; public $module; public $item_module; @@ -88,7 +88,7 @@ class Controller_Component public function getView($name) { // - /*.Settings.*/$registry = $this->registry; + $registry/*: Settings*/ = $this->registry; $template = ($this->template) ? $this->template : $registry->readKey(array('system', 'template')); $selected = null; @@ -128,7 +128,7 @@ class Controller_Component } public function getTemplatePath($name) { - /*.Settings.*/$registry = $this->registry; + $registry/*: Settings*/ = $this->registry; $template = ($this->template) ? $this->template : $registry->readKey(array('system', 'template')); foreach ($this->viewPath as $index => $viewPath) { if(is_dir(Path::join($this->viewPath[$index], 'templates', $template))) { @@ -157,7 +157,7 @@ class Controller_Component return $model; } - public function options($key, $val, /*.Database_PDOStatement.*/$res) { + public function options($key, $val, $res/*: Database_PDOStatement*/) { $result = array(); while($res->next()) { $result[] = array('value' => $res->getString($key), 'name' => $res->getString($val)); @@ -185,7 +185,7 @@ class Controller_Component /** * Генерация интерфейса для выбора галлереи фотографии */ - public function setParameters(/*.View_Composite.*/$view) + public function setParameters($view/*: View_Composite*/) { $form = new Form_Form(); $options = new Form_OptionFactory($this->db, $this->registry); @@ -198,7 +198,7 @@ class Controller_Component $view->component_title = $settings['title']; } - static function loadComponent($expression, Database $db, /*.Registry.*/ $registry) + static function loadComponent($expression, Database $db, $registry/*: Registry*/) { $expression = htmlspecialchars_decode($expression); @@ -218,7 +218,7 @@ class Controller_Component $path = Path::join (BASE_PATH, 'components', $name, $name . '.php'); $className = 'Component_' . $name; - /*.Controller_Component.*/$component = null; + $component/*: Controller_Component*/ = null; if (file_exists($path)) { require_once ($path); @@ -293,12 +293,12 @@ class Controller_Component return null; } - function raw_query(/*.ComponentRequest.*/ $request) + function raw_query($request/*: ComponentRequest*/) { $arr = $request->r->export('get'); $param = array(); - /*.Collection.*/$parameter = $this->parameter; + $parameter/*: Collection*/ = $this->parameter; foreach($parameter->export() as $key => $value) { $param[$key] = $value; } @@ -316,7 +316,7 @@ class Controller_Component } - function query(/*.ComponentRequest.*/ $request, $list) + function query($request/*: ComponentRequest*/, $list) { $arr = $request->r->export('get'); @@ -336,7 +336,7 @@ class Controller_Component Controller_Site::addRequireJsPath($name, $path, $shim); } - function actionIndex(/*.ComponentRequest.*/ $request) { + function actionIndex($request/*: ComponentRequest*/) { } } diff --git a/src/Controller/Front.php b/src/Controller/Front.php index 0d42d4d..6574d04 100644 --- a/src/Controller/Front.php +++ b/src/Controller/Front.php @@ -94,7 +94,7 @@ class Controller_Front extends Controller_Action $this->default = $name; } - public function execute(HTTPRequest $request) + public function execute(HttpRequest $request) { $name = explode("_", $request->get($this->_param, $this->default)); if (count($name) >= 2) { diff --git a/src/Controller/Request.php b/src/Controller/Request.php index 01822e1..6567ad7 100644 --- a/src/Controller/Request.php +++ b/src/Controller/Request.php @@ -1,13 +1,17 @@ r = $request; $this->id = $id; } - function get($name) { + function get($name, $def = null) { $v = $this->r->get($name); + $id = $this->id; if ($id && is_array($v)) { return isset($v[$id]) ? $v[$id] : $def; } diff --git a/src/Database.php b/src/Database.php index 6dc72e9..acd8c59 100644 --- a/src/Database.php +++ b/src/Database.php @@ -5,7 +5,7 @@ require_once "Database/PDOStatement.php"; /** * Класс оболочка для PDO для замены Creole */ -class Database extends PDO +class Database/**/ extends PDO { public $dsn; @@ -37,7 +37,7 @@ class Database extends PDO if ($dsn['phptype'] == 'pgsql' || $dsn['phptype'] == 'mysql') { $port = (isset($dsn['port'])) ? "port={$dsn['port']};" : ""; - /*.Database.*/$connection = new static("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']); + $connection/*: Database*/ = new static("{$dsn['phptype']}:host={$dsn['hostspec']}; $port dbname={$dsn['database']}", $dsn['username'], $dsn['password']); if ($dsn['phptype'] == 'pgsql') { $connection->query('SET client_encoding="UTF-8"'); } @@ -47,7 +47,7 @@ class Database extends PDO } } if ($dsn['phptype'] == 'sqlite') { - /*.Database.*/$connection = new static("{$dsn['phptype']}:{$dsn['database']}"); + $connection/*: Database*/ = new static("{$dsn['phptype']}:{$dsn['database']}"); $connection->setAttribute(PDO::ATTR_TIMEOUT, 5); $mode = defined('SQLITE_JOURNAL_MODE') ? SQLITE_JOURNAL_MODE : 'WAL'; $connection->query("PRAGMA journal_mode=$mode"); @@ -65,7 +65,7 @@ class Database extends PDO public function executeQuery($query, $values=null) { - /*.Database_PDOStatement.*/$stmt = $this->prepare($query); + $stmt/*: Database_PDOStatement*/ = $this->prepare($query); $stmt->execute($values); $stmt->cache = $stmt->fetchAll(PDO::FETCH_ASSOC); @@ -83,7 +83,7 @@ class Database extends PDO */ public function fetchAllArray($query, $values = null) { - /*.Database_PDOStatement.*/$sth = $this->prepare($query); + $sth/*: Database_PDOStatement*/ = $this->prepare($query); $prep = $this->prepareValues($values); $sth->execute($prep); return $sth->fetchAll(PDO::FETCH_ASSOC); @@ -94,7 +94,7 @@ class Database extends PDO */ public function fetchOneArray($query, $values = null) { - /*.Database_PDOStatement.*/$sth = $this->prepare($query); + $sth/*: Database_PDOStatement*/ = $this->prepare($query); $prep = $this->prepareValues($values); $sth->execute($prep); return $sth->fetch(PDO::FETCH_ASSOC); diff --git a/src/Database/JsonInstall.php b/src/Database/JsonInstall.php index 54a7d6f..078113b 100644 --- a/src/Database/JsonInstall.php +++ b/src/Database/JsonInstall.php @@ -40,7 +40,7 @@ class Database_JsonInstall { } //Создать таблицы - function initDataBase(/*.array.*/$initActions, $dbinit_path) { + function initDataBase($initActions/*: array*/, $dbinit_path) { $pg = $this->db_manager->db->isPostgres(); if (!$pg) { $refs = []; diff --git a/src/Database/Manager.php b/src/Database/Manager.php index ec354c7..f5bdaf0 100644 --- a/src/Database/Manager.php +++ b/src/Database/Manager.php @@ -2,13 +2,13 @@ class Database_Manager { - public /*.Database.*/$db; + public $db/*: Database*/; function __construct(Database $db) { $this->db = $db; } - public function ExecuteAction(/*.array.*/$action, $db_file = "") { + public function ExecuteAction($action/*: array*/, $db_file = "") { switch($action["type"]) { case "dropTable": $this->DropTableQuery($action["table_name"], true); @@ -94,7 +94,7 @@ class Database_Manager return; } - /*.array.*/$data = $this->DumpTable($table); + $data/*: array*/ = $this->DumpTable($table); $this->db->query("ALTER TABLE ".$table." RENAME TO ".$tmp_table.";"); $table_info[$new_name] = $table_info[$old_name]; @@ -141,7 +141,7 @@ class Database_Manager $this->db->query($q); } - function getConstraintDef(/*.array.*/$c) { + function getConstraintDef($c/*: array*/) { if ($c['type'] == 'unique') { return "UNIQUE(" . implode(", ", $c['fields']) . ")"; } @@ -169,8 +169,8 @@ class Database_Manager public function DumpTable($table_name) { $pg = $this->db->isPostgres(); - /*.array.*/$result = array(); - /*.array.*/$data = $this->db->fetchAllArray("SELECT * FROM ".$table_name.";"); + $result/*: array*/ = array(); + $data/*: array*/ = $this->db->fetchAllArray("SELECT * FROM ".$table_name.";"); if (!$pg) { $table_fields = $this->TableInfo($table_name); @@ -178,7 +178,7 @@ class Database_Manager $type = strtolower($value['type']); if ($type == "boolean") { foreach ($data as &$row) { - /*.array.*/$row = $row; + $row/*: array*/ = $row; if (isset($row[$name])) { $row[$name] = boolval($row[$name]); } diff --git a/src/Database/PDOStatement.php b/src/Database/PDOStatement.php index 68c7622..0ee8e6b 100644 --- a/src/Database/PDOStatement.php +++ b/src/Database/PDOStatement.php @@ -66,7 +66,7 @@ class Database_PDOStatement extends PDOStatement implements IteratorAggregate } function getInt($name) { - return intval($this->fields[$name]); + return (int)$this->fields[$name]; } function getBlob($name) { diff --git a/src/Database/Statement.php b/src/Database/Statement.php index dbcee3a..ae42fc7 100644 --- a/src/Database/Statement.php +++ b/src/Database/Statement.php @@ -12,7 +12,7 @@ class Database_Statement protected $conn; protected $query; - function __construct($query, /*.Database.*/ $conn) { + function __construct($query, $conn/*: Database*/) { $this->query = $query; $this->conn = $conn; } @@ -41,7 +41,7 @@ class Database_Statement if ($this->limit) { $this->query .= " LIMIT {$this->limit} OFFSET {$this->offset}"; } - /*.Database_PDOStatement.*/$stmt = $this->conn->prepare($this->query); + $stmt/*: Database_PDOStatement*/ = $this->conn->prepare($this->query); foreach ($this->binds as $bind) { list($n, $value, $type) = $bind; $stmt->bindValue($n, $value, (int) $type); diff --git a/src/Database/StatementIterator.php b/src/Database/StatementIterator.php index cc2cc05..8e6c970 100644 --- a/src/Database/StatementIterator.php +++ b/src/Database/StatementIterator.php @@ -8,7 +8,7 @@ class Database_StatementIterator implements Iterator private $fetchmode; private $row_count; - public function __construct(/*.Database_PDOStatement.*/ $rs) { + public function __construct($rs/*: Database_PDOStatement*/) { $this->result = $rs; $this->row_count = $rs->getRecordCount(); } diff --git a/src/Excel/Document.php b/src/Excel/Document.php index 365dba3..4600fad 100644 --- a/src/Excel/Document.php +++ b/src/Excel/Document.php @@ -39,7 +39,7 @@ class Excel_Document { if ($type == 'Borders') { $doc->startElement('Borders'); foreach ($s as $border) { - /*.array.*/$border = $border; + $border/*: array*/ = $border; $doc->startElement('Border'); foreach ($border as $key => $value) { $doc->writeAttribute('ss:' . $key, $value); diff --git a/src/Excel/Table.php b/src/Excel/Table.php index 162c823..6bc61db 100644 --- a/src/Excel/Table.php +++ b/src/Excel/Table.php @@ -64,7 +64,7 @@ class Excel_Table if(! isset($this->rows[$x])) { $this->rows[$x] = new TableRow(); } - /*.TableRow.*/$row = $this->rows[$x]; + $row/*: TableRow*/ = $this->rows[$x]; $row->setCell($y, $value); } @@ -118,7 +118,7 @@ class Excel_Table assert(is_numeric($x) && $x > 0); assert(is_numeric($cell) && $cell > 0); - /*.TableRow.*/$row = $this->rows[$x]; + $row/*: TableRow*/ = $this->rows[$x]; $row->cells[$cell]->merge = $merge; } @@ -153,7 +153,7 @@ class Excel_Table */ function getRows() { - /*.array.*/$keys = array_keys($this->rows); + $keys/*: array*/ = array_keys($this->rows); return max($keys); } @@ -164,7 +164,7 @@ class Excel_Table */ function getRowCells(TableRow $row) { - /*.array.*/$keys = array_keys($row->cells); + $keys/*: array*/ = array_keys($row->cells); return max($keys); } @@ -202,7 +202,7 @@ class Excel_Table /** * Генерация клетки таблицы (Переработать) */ - function createCell (TableCell $ncell, XMLWriter $doc, $j, /*.any.*/$value, $setIndex) { + function createCell (TableCell $ncell, XMLWriter $doc, $j, $value/*: any*/, $setIndex) { $doc->startElement("Cell"); if ($ncell->style) { @@ -262,7 +262,7 @@ class Excel_Table $doc->writeAttribute('ss:Height', $this->rows[$i]->height); } - /*.TableRow.*/$nrow = $this->rows[$i]; + $nrow/*: TableRow*/ = $this->rows[$i]; // Флаг индикатор подстановки номера столбца $setIndex = false; for ($j = 1; $j <= $columns; $j++) { diff --git a/src/Filter/ActionAccess.php b/src/Filter/ActionAccess.php index 7d4936f..9b0b9f0 100644 --- a/src/Filter/ActionAccess.php +++ b/src/Filter/ActionAccess.php @@ -8,7 +8,7 @@ class Filter_ActionAccess public $access = array(); public $processor; - function __construct(/*.Filter_Filter.*/$processor) { + function __construct($processor/*: Filter_Filter*/) { $this->processor = $processor; } diff --git a/src/Filter/ActionLogger.php b/src/Filter/ActionLogger.php index a71d5f5..5a15641 100644 --- a/src/Filter/ActionLogger.php +++ b/src/Filter/ActionLogger.php @@ -7,7 +7,7 @@ class Filter_ActionLogger public $action; public $processor; - function __construct(/*.Filter_Filter.*/$processor) { + function __construct($processor/*: Filter_Filter*/) { $this->processor = $processor; $this->file = fopen(Shortcut::getUrl('access.log'), "a"); } diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index e5135dc..645f624 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -6,7 +6,7 @@ class Filter_Filter { public $processor; - public function __construct(/*.Controller_Action.*/$processor) + public function __construct($processor/*: Controller_Action*/) { $this->processor = $processor; } diff --git a/src/Form/Field.php b/src/Form/Field.php index bb756cb..4fdf5fd 100644 --- a/src/Form/Field.php +++ b/src/Form/Field.php @@ -38,7 +38,7 @@ class Form_Field } } - function setValue(/*.any.*/$value) + function setValue($value/*: any*/) { $this->value = $value; } diff --git a/src/Functions.php b/src/Functions.php index 3f888e7..b7b6d99 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -256,7 +256,7 @@ class Functions { return $result; } - static function _get($key, /*.any.*/$value, /*.array.*/$array) { + static function _get($key, $value/*: any*/, $array/*: array*/) { foreach ($array as $item) { if ($item[$key] == $value) return $item; } @@ -368,7 +368,7 @@ class Functions { * Преобразует ключи элементов для многомерного массива * @return mixed */ - static function hash_key ($key_name,/*. array .*/ $array) { + static function hash_key ($key_name,$array/*: array*/) { $result = array(); foreach($array as $value) { diff --git a/src/HttpRequest.php b/src/HttpRequest.php index d34accf..25890a5 100644 --- a/src/HttpRequest.php +++ b/src/HttpRequest.php @@ -55,7 +55,7 @@ class HttpRequest extends Collection implements ArrayAccess return $this->_session; } - function set($key, /*.any.*/$value) + function set($key, $value/*: any*/) { return parent::get('data')->set($key, $value); } diff --git a/src/MailAlt.php b/src/MailAlt.php index 99b296d..098d921 100644 --- a/src/MailAlt.php +++ b/src/MailAlt.php @@ -48,7 +48,7 @@ class MailAlt /** * Тема письма */ - function subject(/*.string.*/$subject) + function subject($subject/*: string*/) { $this->mailer->Subject = $subject; } diff --git a/src/Model/Factory.php b/src/Model/Factory.php index 30ceb8c..43c770f 100644 --- a/src/Model/Factory.php +++ b/src/Model/Factory.php @@ -7,7 +7,7 @@ class Model_Factory public $_registry; public $_shortcut; - public function __construct (/*.Database.*/ $db, Settings $_registry = null) + public function __construct ($db/*: Database*/, Settings $_registry = null) { $this->db = $db; $this->_registry = $_registry; diff --git a/src/Path.php b/src/Path.php index ba78789..926f1a8 100644 --- a/src/Path.php +++ b/src/Path.php @@ -158,7 +158,7 @@ class Path } // Сравнение двух путей на равентство - public function equal(/*.Path.*/ $path) + public function equal($path/*: Path*/) { if (count($this->path) == count($path->path)) { for ($i = 0; $i < count($this->path); $i++) { @@ -202,7 +202,7 @@ class Path * * @return boolean */ - public function isParent(/*.Path.*/ $path) + public function isParent($path/*: Path*/) { if (isset($this->url['host']) && isset($path->url['host']) && ($this->url['host'] != $path->url['host'])) return false; diff --git a/src/Setup.php b/src/Setup.php index 52a5a0f..6e5dfa9 100644 --- a/src/Setup.php +++ b/src/Setup.php @@ -119,7 +119,7 @@ class Setup return; } - /*.SimpleXMLElement.*/$item = $this->stack[count($this->stack) - 1]; + $item/*: SimpleXMLElement*/ = $this->stack[count($this->stack) - 1]; $root = $item->children(); foreach ($root as $node) { @@ -196,7 +196,7 @@ class Setup /** * Выполнение Списка SQL команд */ - function batchSQLZip(/*.Database.*/ $conn, $file) + function batchSQLZip($conn/*: Database*/, $file) { $stmtList = Tools_SQLStatementExtractor::extract($this->zip->getFromName($file)); foreach ($stmtList as $stmt) { @@ -204,7 +204,7 @@ class Setup } } - static function batchSQL(/*.Database.*/ $conn, $file) + static function batchSQL($conn/*: Database*/, $file) { $stmtList = Tools_SQLStatementExtractor::extractFile($file); foreach ($stmtList as $stmt) { diff --git a/src/Tools/SQLStatementExtractor.php b/src/Tools/SQLStatementExtractor.php index 739f6c7..78d2d89 100644 --- a/src/Tools/SQLStatementExtractor.php +++ b/src/Tools/SQLStatementExtractor.php @@ -111,7 +111,7 @@ class Tools_SQLStatementExtractor { if ($check === "" || $check === $string) { return true; } else { - return (strpos($string, $check) === 0) ? true : false; + return (strpos($string, $check) === 0); } } @@ -121,11 +121,11 @@ class Tools_SQLStatementExtractor { * @param string $string The string to check in (haystack). * @return boolean True if $string ends with $check, or they are equal, or $check is empty. */ - protected static function endsWith(/*.string.*/$check, $string) { + protected static function endsWith($check/*: string*/, $string) { if ($check === "" || $check === $string) { return true; } else { - return (strpos(strrev($string), strrev($check)) === 0) ? true : false; + return (strpos(strrev($string), strrev($check)) === 0); } } diff --git a/src/Tools/TemplateImage.php b/src/Tools/TemplateImage.php index 171f285..0c0f489 100644 --- a/src/Tools/TemplateImage.php +++ b/src/Tools/TemplateImage.php @@ -26,7 +26,7 @@ class Tools_TemplateImage 'miriad' => 'MyriadPro-Cond.ttf', 'miriadbd' => 'MyriadPro-BoldCond.ttf' -); + ); protected $src; protected $context = array(); @@ -35,6 +35,8 @@ class Tools_TemplateImage protected $image; protected $prepare = true; public $debug = false; + public $filename; + public $resource; function __construct ($template = false) { @@ -116,7 +118,7 @@ class Tools_TemplateImage return ""; } - function imageText($text, $value) + function imageText($text, $value/*: stdClass*/) { assert(is_string($text)); diff --git a/src/Validator/Validator.php b/src/Validator/Validator.php index c6d52f9..d01c001 100644 --- a/src/Validator/Validator.php +++ b/src/Validator/Validator.php @@ -69,7 +69,7 @@ class Validator_Validator } } - public function addRule(/*.any.*/$rule) { + public function addRule($rule/*: any*/) { if (is_array($rule)) { $this->chain = array_merge($this->chain, $rule); } else { @@ -77,7 +77,7 @@ class Validator_Validator } } - public function skip(/*.Validator_Rule_Abstract.*/$rule, /*.Collection.*/$container) // -> Rule_Abstract + public function skip($rule/*: Validator_Rule_Abstract*/, $container/*: Collection*/) // -> Rule_Abstract { if ($rule->skipEmpty()) { $data = $container->get($rule->field); diff --git a/src/View/Pages.php b/src/View/Pages.php index 736a861..704629a 100644 --- a/src/View/Pages.php +++ b/src/View/Pages.php @@ -31,7 +31,7 @@ class View_Pages * @param $onpage int количество элем на странице * @return string */ - static function getLimit(/*.number.*/$page, /*.number.*/$onpage) { + static function getLimit($page/*: number*/, $onpage/*: number*/) { if ($page <= 0) { $page = 1; } return "LIMIT $onpage OFFSET " . ($page - 1) * $onpage; } diff --git a/src/View/Top.php b/src/View/Top.php index d28fca0..75667e1 100644 --- a/src/View/Top.php +++ b/src/View/Top.php @@ -99,7 +99,7 @@ class View_Top extends View_Composite { $init = array(); foreach($s->_section as $key => $item) { - /*.View_View.*/$ss = $item; + $ss/*: View_View*/ = $item; if ($ss->codeGenerator !== null) { // функцию которая вычисляет а не результат $part = call_user_func($ss->codeGenerator, $this, $key, $value); diff --git a/src/config.php b/src/config.php index 3bbc19a..86c7dfb 100644 --- a/src/config.php +++ b/src/config.php @@ -1,6 +1,7 @@ Date: Fri, 21 May 2021 11:36:47 +0300 Subject: [PATCH 11/33] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D1=80=D0=B5=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B0=20-=20=D0=B2=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B8=20=D1=84=D0=B0=D0=B9?= =?UTF-8?q?=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Tools/Image.php | 10 ++-- src/Tools/String.php | 94 ++++++++++++++++++------------------- src/Tools/TemplateImage.php | 47 +++++++++---------- 3 files changed, 75 insertions(+), 76 deletions(-) diff --git a/src/Tools/Image.php b/src/Tools/Image.php index c9c10ef..e750540 100644 --- a/src/Tools/Image.php +++ b/src/Tools/Image.php @@ -1,7 +1,7 @@ 1 && !$force) $percent = 1; $new_width = $width * $percent; $new_height = $height * $percent; - + $image_p = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); @@ -36,4 +36,4 @@ class Tools_Image case 'gif': imagegif($image, $uri); break; } } -} +} \ No newline at end of file diff --git a/src/Tools/String.php b/src/Tools/String.php index 678fd26..8380c77 100644 --- a/src/Tools/String.php +++ b/src/Tools/String.php @@ -4,55 +4,55 @@ class Tools_String { // from creole static function strToArray($str) { - $str = substr($str, 1, -1); // remove { } - $res = array(); - - $subarr = array(); - $in_subarr = 0; - - $toks = explode(',', $str); - foreach($toks as $tok) { - if ($in_subarr > 0) { // already in sub-array? - $subarr[$in_subarr][] = $tok; - if ('}' === substr($tok, -1, 1)) { // check to see if we just added last component - $res[] = static::strToArray(implode(',', $subarr[$in_subarr])); - $in_subarr--; - } - } elseif ($tok[0] === '{') { // we're inside a new sub-array - if ('}' !== substr($tok, -1, 1)) { - $in_subarr++; - // if sub-array has more than one element - $subarr[$in_subarr] = array(); - $subarr[$in_subarr][] = $tok; - } else { - $res[] = static::strToArray($tok); - } - } else { // not sub-array - $val = trim($tok, '"'); // remove " (surrounding strings) - // perform type castng here? - $res[] = $val; - } - } - - return $res; + $str = substr($str, 1, -1); // remove { } + $res = array(); + + $subarr = array(); + $in_subarr = 0; + + $toks = explode(',', $str); + foreach($toks as $tok) { + if ($in_subarr > 0) { // already in sub-array? + $subarr[$in_subarr][] = $tok; + if ('}' === substr($tok, -1, 1)) { // check to see if we just added last component + $res[] = static::strToArray(implode(',', $subarr[$in_subarr])); + $in_subarr--; + } + } elseif ($tok[0] === '{') { // we're inside a new sub-array + if ('}' !== substr($tok, -1, 1)) { + $in_subarr++; + // if sub-array has more than one element + $subarr[$in_subarr] = array(); + $subarr[$in_subarr][] = $tok; + } else { + $res[] = static::strToArray($tok); + } + } else { // not sub-array + $val = trim($tok, '"'); // remove " (surrounding strings) + // perform type castng here? + $res[] = $val; + } + } + + return $res; } //Нормализация строк на русском static function normalizeRussian($str) { $result = preg_replace('/\s+/',' ', $str); if (is_string($result)) { - $result = trim($result); //Замена длинных пробелов на одинарные, пробелы по краям - $result = mb_strtolower($result); - $result = preg_replace('/ё/','е', $str); //е на ё + $result = trim($result); //Замена длинных пробелов на одинарные, пробелы по краям + $result = mb_strtolower($result); + $result = preg_replace('/ё/','е', $str); //е на ё } - return $result; + return $result; } - + //Проверка равенства двух строк на русском языке. static function equalRussianCheck($str1,$str2) { - return self::normalizeRussian($str1) == self::normalizeRussian($str2); + return self::normalizeRussian($str1) == self::normalizeRussian($str2); } - + /** * Попадает ли строка в список вариантов @@ -60,7 +60,7 @@ class Tools_String { * output: true * input: $str="foo" $variants="foo1|foo2|foo3" * output: false -*/ +*/ static function compare_string_to_variants($str, $variants){ $variants_array = explode('|', $variants); $founded = false; @@ -69,17 +69,17 @@ class Tools_String { } return $founded; } - + static function mb_str_split($str) { return preg_split('~~u', $str, null, PREG_SPLIT_NO_EMPTY); } - + static function mb_strtr($str, $from, $to) { return str_replace(self::mb_str_split($from), self::mb_str_split($to), $str); - } - + } + static function encodestring($st) { - $st = self::mb_strtr($st,"абвгдеёзийклмнопрстуфхъыэ !+-()", "abvgdeeziyklmnoprstufh_ie______"); + $st = self::mb_strtr($st,"абвгдеёзийклмнопрстуфхъыэ !+()", "abvgdeeziyklmnoprstufh_ie_____"); $st = self::mb_strtr($st,"АБВГДЕЁЗИЙКЛМНОПРСТУФХЪЫЭ", "ABVGDEEZIYKLMNOPRSTUFH_IE"); $st = strtr($st, array( " " => '_', @@ -94,8 +94,8 @@ class Tools_String { "#" => '_', "*" => '_', "ж"=>"zh", "ц"=>"ts", "ч"=>"ch", "ш"=>"sh", - "щ"=>"shch","ь"=>"", "ю"=>"yu", "я"=>"ya", - "Ж"=>"ZH", "Ц"=>"TS", "Ч"=>"CH", "Ш"=>"SH", + "щ"=>"shch","ь"=>"", "ю"=>"yu", "я"=>"ya", + "Ж"=>"ZH", "Ц"=>"TS", "Ч"=>"CH", "Ш"=>"SH", "Щ"=>"SHCH","Ь"=>"", "Ю"=>"YU", "Я"=>"YA", "Й"=>"i", "й"=>"ie", "ё"=>"Ye", "№"=>"N" @@ -107,4 +107,4 @@ class Tools_String { $enc_st = self::encodestring($st); return preg_match('/^[\w_-]+(\.[\w_-]+)?$/', $enc_st); } -} +} \ No newline at end of file diff --git a/src/Tools/TemplateImage.php b/src/Tools/TemplateImage.php index 0c0f489..cdf97ca 100644 --- a/src/Tools/TemplateImage.php +++ b/src/Tools/TemplateImage.php @@ -7,14 +7,14 @@ class Tools_TemplateImage { static $listfiles = array('jpg' => 'jpeg', 'gif' => 'gif', 'png' => 'png', 'bmp' => 'wbmp'); static $listfonts = array( - 'georgia' => 'georgia.ttf', - 'georgiabd' => 'georgiab.ttf', - 'georgiaz' => 'georgiaz.ttf', - 'times' => 'times.ttf', - 'timesbd' => 'timesbd.ttf', - 'arial' => 'arial.ttf', - 'arialbd' => 'arialbd.ttf', - 'tahoma' => 'tahoma.ttf', + 'georgia' => 'georgia.ttf', + 'georgiabd' => 'georgiab.ttf', + 'georgiaz' => 'georgiaz.ttf', + 'times' => 'times.ttf', + 'timesbd' => 'timesbd.ttf', + 'arial' => 'arial.ttf', + 'arialbd' => 'arialbd.ttf', + 'tahoma' => 'tahoma.ttf', 'calibri' => 'calibri.ttf', 'calibribd' => 'calibrib.ttf', 'calibrii' => 'calibrii.ttf', @@ -59,14 +59,14 @@ class Tools_TemplateImage /** * Путь у шрифтам */ - function fontPath($path) + function fontPath($path) { assert(is_string($path)); $this->base = $path; } - - function set($name, $value) + + function set($name, $value) { assert(is_string($name)); @@ -87,11 +87,11 @@ class Tools_TemplateImage /** * Создает изображение из файла */ - function imagefromfile($file) + function imagefromfile($file) { assert(is_string($file)); - $suffix = pathinfo($file, PATHINFO_EXTENSION); + $suffix = pathinfo($file, PATHINFO_EXTENSION); if (array_key_exists($suffix, self::$listfiles)) { return call_user_func('imagecreatefrom' . self::$listfiles[$suffix], $file); } @@ -99,12 +99,12 @@ class Tools_TemplateImage } function getFontFile($name) - { + { assert(is_string($name)); if(array_key_exists(strtolower($name), self::$listfonts)) { return $this->base . self::$listfonts[$name]; - } + } return $this->base . 'arial.ttf'; } @@ -127,23 +127,23 @@ class Tools_TemplateImage $fontfile = $this->getFontFile($value->fontFamily . $this->fontSuffix($value->fontStyle)); $color = intval(substr($value->color, 1), 16); - if ($value->align[0]) { + if ($value->align[0]) { $align = Tools_Drawing::ALIGN_LEFT; - } elseif ($value->align[2]) { + } elseif ($value->align[2]) { $align = Tools_Drawing::ALIGN_RIGHT; } else { $align = Tools_Drawing::ALIGN_CENTER; } - if ($value->valign[0]) { + if ($value->valign[0]) { $valign = Tools_Drawing::ALIGN_TOP; - } elseif ($value->valign[1]) { + } elseif ($value->valign[1]) { $valign = Tools_Drawing::ALIGN_CENTER; } else { $valign = Tools_Drawing::ALIGN_BOTTOM; } - Tools_Drawing::imagettftextbox($this->image, $size, 0, $value->left, $value->top, $color, $fontfile, $text, + Tools_Drawing::imagettftextbox($this->image, $size, 0, $value->left, $value->top, $color, $fontfile, $text, $value->width, $value->height, $align, $valign); } @@ -158,8 +158,8 @@ class Tools_TemplateImage } function setSize($new_width, $new_height) - { - $width = imagesx($this->image); + { + $width = imagesx($this->image); $height = imagesy($this->image); if($new_height == false) { $new_height = ceil($height * $new_width / $width); @@ -170,7 +170,7 @@ class Tools_TemplateImage imagecopyresampled($image_p, $this->image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // imagecopyresized($image_p, $this->image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); $this->image = $image_p; - } + } function prepare() { if($this->prepare) { @@ -201,4 +201,3 @@ class Tools_TemplateImage } } } - From e5dd6bded26702a82f34d4fd9010a7e81efad69c Mon Sep 17 00:00:00 2001 From: Podlesnov Phedor Date: Wed, 26 May 2021 15:33:52 +0300 Subject: [PATCH 12/33] =?UTF-8?q?=D0=A0=D0=B0=D0=B7=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=B0=D0=B2=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=D0=BC=20=D0=BC=D0=BE?= =?UTF-8?q?=D0=B4=D1=83=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Front.php | 8 +++----- src/Filter/ActionAccess.php | 4 +++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Controller/Front.php b/src/Controller/Front.php index 6574d04..ed5aee2 100644 --- a/src/Controller/Front.php +++ b/src/Controller/Front.php @@ -47,11 +47,8 @@ class Controller_Front extends Controller_Action return $module->access->execute($request); } - if ($controller) { - $moduleFile = Shortcut::getUrl($this->shortcut, $name, $controller); // ModuleLoader (2) - } else { - $moduleFile = Shortcut::getUrl($this->shortcut, $name, $name); // ModuleLoader (2) - } + $suffix = ($controller) ? $controller : $name; + $moduleFile = Shortcut::getUrl($this->shortcut, $name, $suffix); // ModuleLoader (2) $module = $this->loadClass($moduleFile, null, 'Module_'); if ($module) { @@ -75,6 +72,7 @@ class Controller_Front extends Controller_Action $logger->before = $this->loadSettings(Shortcut::getUrl('logger', $name)); // Управление доступом $module->access = $this->loadClass(__DIR__ . '/../Filter/ActionAccess.php', $logger, 'Filter_'); + $module->access->name = $suffix; $module->access->access = $this->loadSettings(Shortcut::getUrl('access', $name)); $module->setUp(); diff --git a/src/Filter/ActionAccess.php b/src/Filter/ActionAccess.php index 9b0b9f0..8f21d21 100644 --- a/src/Filter/ActionAccess.php +++ b/src/Filter/ActionAccess.php @@ -7,6 +7,7 @@ class Filter_ActionAccess { public $access = array(); public $processor; + public $name; function __construct($processor/*: Filter_Filter*/) { $this->processor = $processor; @@ -19,7 +20,8 @@ class Filter_ActionAccess */ function checkAction($action) { // Импликация !! http://ru.wikipedia.org/wiki/Импликация - return (!isset($this->access[$action]) || in_array(Filter_UserAccess::$access, $this->access[$action])); + $name = $this->name; + return (!isset($this->access[$name][$action]) || in_array(Filter_UserAccess::$access, $this->access[$name][$action])); } function execute(HttpRequest $request) { From 713c00c20d8a3d60645bcc35057ac3c7a95d7822 Mon Sep 17 00:00:00 2001 From: Podlesnov Phedor Date: Mon, 31 May 2021 16:20:21 +0300 Subject: [PATCH 13/33] =?UTF-8?q?=D0=9B=D0=BE=D0=B3=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D1=8C=D1=8E=20=D0=B2=20json=20=D1=84?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Filter/ActionLogger.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Filter/ActionLogger.php b/src/Filter/ActionLogger.php index 5a15641..5a2cbab 100644 --- a/src/Filter/ActionLogger.php +++ b/src/Filter/ActionLogger.php @@ -15,7 +15,8 @@ class Filter_ActionLogger function execute(HttpRequest $request) { $action = $request->getAction(); if(in_array($action, $this->before)) { - fwrite($this->file, "time: " . date("r", time()) . " query: ". json_encode(array_merge($_POST, $_GET)) . " by: " . Filter_UserAccess::$name . "\n"); + $line = ['time' => time(), 'user' => Filter_UserAccess::$name, 'sid' => session_id(), 'query' => array_merge($_POST, $_GET)]; + fwrite($this->file, json_encode($line) . "\n"); } return $this->processor->execute($request); } From 7b2827e96f7a1aa42a997918fa865b2adaaae8dc Mon Sep 17 00:00:00 2001 From: Podlesnov Phedor Date: Thu, 3 Jun 2021 13:12:27 +0300 Subject: [PATCH 14/33] =?UTF-8?q?=D0=9F=D1=83=D1=82=D1=8C=20=D0=BA=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=D0=BC=20=D0=B2=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Component.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Controller/Component.php b/src/Controller/Component.php index e4db790..12ba059 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -243,6 +243,8 @@ class Controller_Component if (defined('COMPONENTS_WEB')) { $component->webPath = array(COMPONENTS_WEB . '/' . $name, SITE_WWW_PATH . '/components/' . $name); $component->COMPONENTS_WEB = COMPONENTS_WEB; + } else { + $component->webPath = array('', SITE_WWW_PATH . '/components/' . $name, ''); } } From d24561c652e120474c77300f5990953253e91260 Mon Sep 17 00:00:00 2001 From: Podlesnov Phedor Date: Wed, 23 Jun 2021 15:32:30 +0300 Subject: [PATCH 15/33] =?UTF-8?q?=D0=9D=D0=B0=D0=B7=D0=BD=D0=B0=D1=87?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Settings.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Settings.php b/src/Settings.php index 661cbb2..5ba0767 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -14,9 +14,9 @@ class Settings extends Collection protected $file; protected $format = 'php'; - public function __construct ($file = null) + public function __construct ($file = null, $format = false) { - $this->format = pathinfo($file, PATHINFO_EXTENSION); + $this->format = $format ? $format : pathinfo($file, PATHINFO_EXTENSION); $this->file = $file; } From 61bc5e570949f6d371245c78a5a4e9a484371e1f Mon Sep 17 00:00:00 2001 From: Podlesnov Phedor Date: Mon, 28 Jun 2021 15:10:15 +0300 Subject: [PATCH 16/33] =?UTF-8?q?=D0=A1=D0=B2=D0=BE=D0=B9=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=BE=20=D0=BF=D0=BE=20=D1=83=D0=BC=D0=BE=D0=BB=D1=87?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Form/OptionFactory.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Form/OptionFactory.php b/src/Form/OptionFactory.php index 41a8447..0e5303b 100644 --- a/src/Form/OptionFactory.php +++ b/src/Form/OptionFactory.php @@ -3,6 +3,7 @@ class Form_OptionFactory { public $db; public $registry; + function __construct($db, $registry = null) { $this->db = $db; $this->registry = $registry; @@ -45,6 +46,9 @@ class Form_OptionFactory { } else { $field->options = $input['options']; } + if (isset($input['default'])) { + array_unshift($field->options, ['value' => 0, 'name' => $input['default']]); + } } public function optionsDB($key, $val, $res) { From 9aa5f0fa091cc9221a3637cb0923ecc4de70eb26 Mon Sep 17 00:00:00 2001 From: Podlesnov Phedor Date: Thu, 8 Jul 2021 19:43:27 +0300 Subject: [PATCH 17/33] =?UTF-8?q?=D0=A1=D0=BE=D0=BE=D1=82=D0=B2=D0=B5?= =?UTF-8?q?=D1=82=D1=81=D0=B2=D0=B8=D0=B5=20=D1=80=D0=B0=D1=81=D1=88=D0=B8?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0?= =?UTF-8?q?=20=D0=B8=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Settings.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Settings.php b/src/Settings.php index 5ba0767..dacdb13 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -16,7 +16,10 @@ class Settings extends Collection public function __construct ($file = null, $format = false) { - $this->format = $format ? $format : pathinfo($file, PATHINFO_EXTENSION); + $fileFormat = ['theme' => 'json']; + $extname = pathinfo($file, PATHINFO_EXTENSION); + + $this->format = $format ? $format : Arr::get($fileFormat, $extname, $extname); $this->file = $file; } From dfb800682b97af28b60ac3438111393034a87262 Mon Sep 17 00:00:00 2001 From: Podlesnov Phedor Date: Mon, 12 Jul 2021 12:47:06 +0300 Subject: [PATCH 18/33] =?UTF-8?q?fix=20=D1=84=D0=B8=D0=B3=D1=83=D1=80?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20=D1=81=D0=BA=D0=BE=D0=B1=D0=BE=D0=BA=20?= =?UTF-8?q?=D1=83=20=D1=81=D1=82=D1=80=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Tools/SQLStatementExtractor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Tools/SQLStatementExtractor.php b/src/Tools/SQLStatementExtractor.php index 78d2d89..fd4e068 100644 --- a/src/Tools/SQLStatementExtractor.php +++ b/src/Tools/SQLStatementExtractor.php @@ -143,7 +143,7 @@ class Tools_SQLStatementExtractor { trigger_error("substring(), Endindex out of bounds must be $startpos Date: Thu, 15 Jul 2021 16:41:07 +0300 Subject: [PATCH 19/33] =?UTF-8?q?=D0=9D=D0=B0=D1=81=D1=82=D1=80=D0=BE?= =?UTF-8?q?=D0=B9=D0=BA=D0=B0=20=D0=B4=D0=BE=D1=81=D1=82=D1=83=D0=BF=D0=BD?= =?UTF-8?q?=D1=8B=D1=85=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B2=20json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Filter/Login.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Filter/Login.php b/src/Filter/Login.php index e2b5cff..63c7ff5 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -166,9 +166,9 @@ class Filter_Login extends Filter_Filter $module = $request->get('module'); $action = $request->get('action'); - $file = Path::join(CMS_PATH, 'modules', $module, 'filters', 'white.php'); + $file = Path::join(CMS_PATH, 'modules', $module, 'filters', 'white.json'); if (file_exists($file)) { - $whiteList = include $file; + $whiteList = json_decode(file_get_contents($file), true); if (in_array($action, $whiteList)) { return true; } From d3cce26fbb853e093a76c69ee7bbfdedb9dbdd7a Mon Sep 17 00:00:00 2001 From: Podlesnov Phedor Date: Thu, 9 Sep 2021 15:24:56 +0300 Subject: [PATCH 20/33] fix path --- src/Database/PDOStatement.php | 3 +++ src/Path.php | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Database/PDOStatement.php b/src/Database/PDOStatement.php index 0ee8e6b..11ccdd9 100644 --- a/src/Database/PDOStatement.php +++ b/src/Database/PDOStatement.php @@ -66,6 +66,9 @@ class Database_PDOStatement extends PDOStatement implements IteratorAggregate } function getInt($name) { + if (!$this->fields) { + throw new Error('no fields'); + } return (int)$this->fields[$name]; } diff --git a/src/Path.php b/src/Path.php index 926f1a8..785ed95 100644 --- a/src/Path.php +++ b/src/Path.php @@ -173,11 +173,14 @@ class Path public static function makeUrl($path) { + $slash = (isset($path['host']) && strlen($path['path'] > 0) && ($path['path'][0] != '/')) ? '/' : ''; + return (isset($path['scheme']) ? $path['scheme'] . ':/' : '') . (isset($path['host']) ? ('/' . (isset($path['user']) ? $path['user'] . (isset($path['pass']) ? ':' . $path['pass'] : '') . '@' : '') . $path['host'] . (isset($path['port']) ? ':' . $path['port'] : '')) : '') + . $slash . $path['path'] . (isset($path['query']) ? '?' . $path['query'] : '') . (isset($path['fragment']) ? '#' . $path['fragment'] : ''); @@ -286,8 +289,9 @@ class Path $parts = new Path($file); $result [] = $parts->getParts(); } + // При обьединении ссылок можно обьеденить path, query, fragment - $path = implode(self::SEPARATOR, self::optimize(call_user_func_array('array_merge', $result))); + $path = implode(self::SEPARATOR, self::optimize(call_user_func_array('array_merge', $result))); $parts0->url['path'] = ($parts0->isAbsolute()) ? '/' . $path : $path; return $parts0; } From e558d712cddda1f18778c5999bfbdb86118719bd Mon Sep 17 00:00:00 2001 From: Podlesnov Phedor Date: Thu, 9 Sep 2021 16:15:02 +0300 Subject: [PATCH 21/33] =?UTF-8?q?=D0=91=D0=B0=D0=B3=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=20=D0=BE=D0=BF=D1=80=D0=B5=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B8=20=D0=B0=D0=B1=D1=81=D0=BE=D0=BB=D1=8E=D1=82=D0=BD=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D0=BF=D1=83=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Path.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Path.php b/src/Path.php index 785ed95..b58ae26 100644 --- a/src/Path.php +++ b/src/Path.php @@ -173,7 +173,7 @@ class Path public static function makeUrl($path) { - $slash = (isset($path['host']) && strlen($path['path'] > 0) && ($path['path'][0] != '/')) ? '/' : ''; + $slash = (isset($path['host']) && (strlen($path['path']) > 0) && ($path['path'][0] != '/')) ? '/' : ''; return (isset($path['scheme']) ? $path['scheme'] . ':/' : '') . (isset($path['host']) ? ('/' From a1613d9291d2bc805f0dfb2de7b5d5895078f905 Mon Sep 17 00:00:00 2001 From: anatoly Date: Tue, 11 Jan 2022 14:22:31 +0300 Subject: [PATCH 22/33] whitelist for submodules --- src/Filter/Login.php | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Filter/Login.php b/src/Filter/Login.php index 63c7ff5..cf19381 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -3,10 +3,10 @@ /** * Фильтр для проверки авторизации * - * action: login(password, login) + * action: login(password, login) * action: logout() */ -// В класс авторизации передавать обьект для управления пользователем +// В класс авторизации передавать обьект для управления пользователем // Вынести в отдельный файл class Filter_Login extends Filter_Filter { @@ -28,8 +28,8 @@ class Filter_Login extends Filter_Filter switch ($request->getAction()) { // Авторизация по постоянному паролю - case 'login': - $login = $request->get('login'); + case 'login': + $login = $request->get('login'); $password = $request->get('password'); $result = Filter_UserAccess::getUserByLogin($login); // Поиск по логину @@ -48,7 +48,7 @@ class Filter_Login extends Filter_Filter if (md5($password) == $userPassword) { // password $this->enter($db, $result); return true; - } + } } $request->set('error', true); break; @@ -57,15 +57,15 @@ class Filter_Login extends Filter_Filter break; // Вход по временному паролю case 'enter': - $login = $request->get('login'); + $login = $request->get('login'); $password = $request->get('sid'); $result = Filter_UserAccess::getUserByLogin($login); // Поиск по логину if ($result) { $temp = md5($result->getString('password') . $result->getString('login') . $result->getString('sid')); - if ($password == $temp) { + if ($password == $temp) { $this->enter($db, $result); return true; - } + } } break; default: @@ -98,13 +98,13 @@ class Filter_Login extends Filter_Filter return md5($rawSign); } - private function enter($db, $result) + private function enter($db, $result) { $this->user = $result; $random = rand(0, 1024 * 1024); $db->executeQuery("UPDATE users SET sid = '$random' WHERE id_user = " . $result->getInt('id_user')); - $_SESSION["group"] = $result->getInt('access'); + $_SESSION["group"] = $result->getInt('access'); $_SESSION["access"] = $result->getInt('id_user'); // id_user $_SESSION["random"] = $random; // id_user $_SESSION[self::SESSION_BROWSER_SIGN_KEYNAME] = $this->getBrowserSign(); @@ -131,13 +131,13 @@ class Filter_Login extends Filter_Filter if ($logged) { return json_encode(array('result' => 'ok', 'message' => "Авторизация успешна")); } else { - return json_encode(array('result' => 'fail', 'message' => "Неправильное имя пользователя или пароль")); + return json_encode(array('result' => 'fail', 'message' => "Неправильное имя пользователя или пароль")); } } if (!$logged) { // Параметры при неправильной авторизации - // Действия по умолчанию !! Возможно переход на форму регистрации + // Действия по умолчанию !! Возможно переход на форму регистрации if ($request->get('mode') == 'ajax') { if (!$this->requestIsWhite($request)) { return json_encode(array('result' => 'fail', 'message' =>"NOT_AUTHORIZED")); @@ -157,7 +157,7 @@ class Filter_Login extends Filter_Filter $text = $this->processor->execute($request); return $text; } - + /* --------------------- * Проверка на попадание реквеста в белый список */ @@ -166,9 +166,11 @@ class Filter_Login extends Filter_Filter $module = $request->get('module'); $action = $request->get('action'); - $file = Path::join(CMS_PATH, 'modules', $module, 'filters', 'white.json'); + $moduleDir = explode('_',$module)[0]; + $file = Path::join(CMS_PATH, 'modules', $moduleDir, 'filters', 'white.json'); if (file_exists($file)) { $whiteList = json_decode(file_get_contents($file), true); + if (in_array($action, $whiteList)) { return true; } @@ -177,4 +179,3 @@ class Filter_Login extends Filter_Filter return false; } } - From fb68128fd8a0c2738523107d24a107283d48516a Mon Sep 17 00:00:00 2001 From: Daniil Date: Thu, 20 Jan 2022 13:22:57 +0300 Subject: [PATCH 23/33] form for chooser --- src/Form/Form.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Form/Form.php b/src/Form/Form.php index 2d6baab..ee409ca 100644 --- a/src/Form/Form.php +++ b/src/Form/Form.php @@ -93,6 +93,7 @@ class Form_Form extends View_View { 'radio' => 'Form_SelectOne', 'filebrowser' => 'TComponentBrowserInput', 'documents' => 'TComponentBrowserInput', + 'chooser' => 'Form_Input' ); } From 479c26dc291af78ec0ad688df67c74418a01c07f Mon Sep 17 00:00:00 2001 From: Daniil Date: Fri, 21 Jan 2022 16:39:39 +0300 Subject: [PATCH 24/33] select + chooser form, main-folder on top of select list --- src/Form/Form.php | 3 ++- src/Form/OptionFactory.php | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Form/Form.php b/src/Form/Form.php index ee409ca..898e18d 100644 --- a/src/Form/Form.php +++ b/src/Form/Form.php @@ -93,7 +93,8 @@ class Form_Form extends View_View { 'radio' => 'Form_SelectOne', 'filebrowser' => 'TComponentBrowserInput', 'documents' => 'TComponentBrowserInput', - 'chooser' => 'Form_Input' + 'chooser' => 'Form_Input', + 'select_chooser' => 'Form_SelectOne' ); } diff --git a/src/Form/OptionFactory.php b/src/Form/OptionFactory.php index 0e5303b..724b3e6 100644 --- a/src/Form/OptionFactory.php +++ b/src/Form/OptionFactory.php @@ -49,6 +49,16 @@ class Form_OptionFactory { if (isset($input['default'])) { array_unshift($field->options, ['value' => 0, 'name' => $input['default']]); } + + // Ставим корневой каталог в начало списка (скорее всего он будет в конце массива) + if ($field->options) + { + $root_elem = array_pop($field->options); + if ($root_elem['value'] == '/') + array_unshift($field->options, $root_elem); + else + array_push($field->options, $root_elem); + } } public function optionsDB($key, $val, $res) { From 517dc477ed8b9477512048fc0e8137d4173d7e41 Mon Sep 17 00:00:00 2001 From: Podlesnov Phedor Date: Tue, 1 Feb 2022 14:44:53 +0300 Subject: [PATCH 25/33] =?UTF-8?q?=D0=9E=D0=BF=D1=80=D0=B5=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D0=BE=20cookie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Component.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Controller/Component.php b/src/Controller/Component.php index 12ba059..7077175 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -85,11 +85,15 @@ class Controller_Component } } + public function getTemplateName($_registry/*: Settings*/) { + return (isset($_COOKIE['with_template']) && preg_match('/^[\w\d-]{3,20}$/', $_COOKIE['with_template'])) ? $_COOKIE['with_template'] : $_registry->readKey(array('system', 'template')); + } + public function getView($name) { // $registry/*: Settings*/ = $this->registry; - $template = ($this->template) ? $this->template : $registry->readKey(array('system', 'template')); + $template = ($this->template) ? $this->template : $this->getTemplateName($registry); $selected = null; foreach ($this->viewPath as $index => $viewPath) { @@ -129,7 +133,8 @@ class Controller_Component public function getTemplatePath($name) { $registry/*: Settings*/ = $this->registry; - $template = ($this->template) ? $this->template : $registry->readKey(array('system', 'template')); + // Брать настройки из куков если есть + $template = ($this->template) ? $this->template : $this->getTemplateName($registry); foreach ($this->viewPath as $index => $viewPath) { if(is_dir(Path::join($this->viewPath[$index], 'templates', $template))) { return Path::join($this->viewPath[$index], 'templates', $template, $name); From fa4adbb75fd1ea266775488299b9f3571973fbfa Mon Sep 17 00:00:00 2001 From: Podlesnov Phedor Date: Wed, 6 Apr 2022 14:20:30 +0300 Subject: [PATCH 26/33] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D1=80=D0=B5=D0=B5=D1=81=D1=82=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Filter/Login.php | 14 +++++++++++--- src/Registry.php | 18 +++++++++++++++++- src/Settings.php | 8 -------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/Filter/Login.php b/src/Filter/Login.php index cf19381..4a993a1 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -42,8 +42,14 @@ class Filter_Login extends Filter_Filter $db = Database::getConnection($dsn); $user = $db->fetchOneArray("SELECT * FROM users WHERE login = :login", ['login' => $login]); - $userPassword = $user['password']; - } + $userPassword = $user['password']; + } /*else if (time() - $result->getInt('lastupdate') > 60*60*24*60) { + // Проверить давность пароля, 60 дней + $request->set('error', true); + $request->set('lastupdate', true); + return false; + }*/ + // Извлечнеие пользователя из родительской CMS, для проверки пароля if (md5($password) == $userPassword) { // password $this->enter($db, $result); @@ -55,7 +61,8 @@ class Filter_Login extends Filter_Filter case 'logout': // Выход session_destroy(); break; - // Вход по временному паролю + // Вход по временному паролю, не используется + /* case 'enter': $login = $request->get('login'); $password = $request->get('sid'); @@ -68,6 +75,7 @@ class Filter_Login extends Filter_Filter } } break; + */ default: $hash = $this->getBrowserSign(); // Если $hash не совпадает $_SESSION['hash'] то удаляем сессию diff --git a/src/Registry.php b/src/Registry.php index 5a2d871..a4d9b62 100644 --- a/src/Registry.php +++ b/src/Registry.php @@ -14,11 +14,27 @@ class Registry extends Settings /** */ - static public function getInstance () + static public function getInstance() { if (self::$instance == null) { self::$instance = new Registry(); } return self::$instance; } + + /** + * Список модулей + */ + public function getModules() + { + return array_keys($this->data); + } + + /** + * Проверка наличия модуля + */ + public function hasModule($name) + { + return isset($this->data[$name]); + } } diff --git a/src/Settings.php b/src/Settings.php index dacdb13..eca24eb 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -172,12 +172,4 @@ class Settings extends Collection } file_put_contents (($file) ? $file : $this->file, $result); } - - /** - * Список модулей - */ - public function getModules() - { - return array_keys($this->data); - } } From 03cd37109582cdde4987d3c0c8df64a45e5679c6 Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Wed, 20 Jul 2022 17:30:53 +0300 Subject: [PATCH 27/33] =?UTF-8?q?=D0=91=D0=B0=D0=B3=20=D0=B2=20=D1=81?= =?UTF-8?q?=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B8=20site=5Ftemplate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Component.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/Component.php b/src/Controller/Component.php index 7077175..97315f4 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -120,7 +120,7 @@ class Controller_Component $tpl->set('script', Path::join(WWW_PATH, 'js')); $tpl->set('media', Path::join(TEMPLATE_WEB, $template)); if ($registry) { - $tpl->set('site_template', SITE_WWW_PATH . '/templates' . $registry->readKey(array('system', 'template'))); + $tpl->set('site_template', SITE_WWW_PATH . '/templates/' . $registry->readKey(array('system', 'template'))); } $tpl->set('base', SITE_WWW_PATH); From 95fc1b28c8a0ea60cf3c8aadc77d61feec985757 Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Wed, 21 Sep 2022 18:11:58 +0300 Subject: [PATCH 28/33] =?UTF-8?q?=D0=9F=D0=BE=D0=B8=D1=81=D0=BA=20=D1=88?= =?UTF-8?q?=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BC=D0=BF?= =?UTF-8?q?=D0=BE=D0=BD=D0=B5=D0=BD=D1=82=D0=B0=20=D0=B2=20=D0=BF=D0=B0?= =?UTF-8?q?=D0=BF=D0=BA=D0=B5=20=D0=BE=D1=81=D0=BD=D0=BE=D0=B2=D0=BD=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=B0.=20?= =?UTF-8?q?=D0=94=D0=BB=D1=8F=20=D1=83=D0=BF=D1=80=D0=B0=D1=89=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=80=D0=B0=D0=B7=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE=20=D1=88?= =?UTF-8?q?=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=D0=B0=20=D1=81=D0=BE=D0=B2=D0=BC?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=BD=D0=BE=20=D1=81=20=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Collection.php | 6 +++--- src/Controller/Component.php | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Collection.php b/src/Collection.php index 1370be3..8a4ba7d 100644 --- a/src/Collection.php +++ b/src/Collection.php @@ -1,7 +1,7 @@ data[$key]) && $this->data[$key] != '' ? $this->data[$key] : $default; } - public function getInt($key, $default = 0) + public function getInt($key, $default = 0) { return (int)$this->get($key, $default); } @@ -69,7 +69,7 @@ class Collection implements ArrayAccess public function getNat($key, $default = 1) { $result = (int)$this->get($key, $default); - return (($result > 0) ? $result : $default); + return (($result > 0) ? $result : $default); } public function clear() diff --git a/src/Controller/Component.php b/src/Controller/Component.php index 97315f4..bb8938f 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -244,14 +244,26 @@ class Controller_Component $component->db = $db; $component->registry = $registry; - $component->viewPath = array(COMPONENTS . '/' . $name . '/', BASE_PATH . '/components/' . $name . '/'); + $template = $component->getTemplateName($registry); + + $component->viewPath = array( + COMPONENTS . '/' . $name . '/', + BASE_PATH . '/components/' . $name . '/', + CMS_PATH . '/../templates/' . $template . '/_components/' . $name . '/', + BASE_PATH . '/templates/' . $template . '/_components/' . $name . '/' + ); if (defined('COMPONENTS_WEB')) { - $component->webPath = array(COMPONENTS_WEB . '/' . $name, SITE_WWW_PATH . '/components/' . $name); + $component->webPath = array( + COMPONENTS_WEB . '/' . $name, + SITE_WWW_PATH . '/components/' . $name, + TEMPLATE_WEB . '/' . $template . '/_components/' . $name, + SITE_WWW_PATH . '/templates/' . $template . '/_components/' . $name + ); $component->COMPONENTS_WEB = COMPONENTS_WEB; } else { $component->webPath = array('', SITE_WWW_PATH . '/components/' . $name, ''); } - } + } $stmt = $db->prepareStatement("SELECT * FROM component WHERE code = ?"); $stmt->setString(1, $expression); From 282fff8276478fc511c4aa91c331339321036c7c Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Fri, 30 Sep 2022 11:46:52 +0300 Subject: [PATCH 29/33] =?UTF-8?q?fix=20=D0=9E=D0=BF=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=88=D0=B0=D0=B1=D0=BB?= =?UTF-8?q?=D0=BE=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Component.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Controller/Component.php b/src/Controller/Component.php index bb8938f..3672a57 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -247,17 +247,21 @@ class Controller_Component $template = $component->getTemplateName($registry); $component->viewPath = array( - COMPONENTS . '/' . $name . '/', + // Сначало ищем локально + BASE_PATH . '/templates/' . $template . '/_components/' . $name . '/', BASE_PATH . '/components/' . $name . '/', - CMS_PATH . '/../templates/' . $template . '/_components/' . $name . '/', - BASE_PATH . '/templates/' . $template . '/_components/' . $name . '/' + // Потом в общем хранилище + CMS_PATH . '/../templates/' . $template . '/_components/' . $name . '/', + COMPONENTS . '/' . $name . '/', ); if (defined('COMPONENTS_WEB')) { $component->webPath = array( - COMPONENTS_WEB . '/' . $name, + // Сначало локально + SITE_WWW_PATH . '/templates/' . $template . '/_components/' . $name, SITE_WWW_PATH . '/components/' . $name, - TEMPLATE_WEB . '/' . $template . '/_components/' . $name, - SITE_WWW_PATH . '/templates/' . $template . '/_components/' . $name + // Потом в общем хранилище + TEMPLATE_WEB . '/' . $template . '/_components/' . $name, + COMPONENTS_WEB . '/' . $name, ); $component->COMPONENTS_WEB = COMPONENTS_WEB; } else { From fdc13fd6be2b55e78e08def91226f882095f3a67 Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Fri, 30 Sep 2022 16:21:42 +0300 Subject: [PATCH 30/33] =?UTF-8?q?fix=20=D0=9E=D0=BF=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=88=D0=B0=D0=B1=D0=BB?= =?UTF-8?q?=D0=BE=D0=BD=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Component.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Controller/Component.php b/src/Controller/Component.php index 3672a57..1f1e18e 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -98,7 +98,8 @@ class Controller_Component $selected = null; foreach ($this->viewPath as $index => $viewPath) { // Загружать шаблон по умолчанию если не найден текущий - if(is_dir(Path::join($this->viewPath[$index], 'templates', $template))) { + $dir = Path::join($this->viewPath[$index], 'templates', $template); + if(is_dir($dir)) { $tpl = new PHPTAL(Path::join($this->viewPath[$index], 'templates', $template, $name)); $tpl->setPhpCodeDestination(PHPTAL_PHP_CODE_DESTINATION); $selected = $index; @@ -107,10 +108,11 @@ class Controller_Component } if ($selected === null) { - $tpl = new PHPTAL(Path::join($this->viewPath[0], 'templates', 'modern', $name)); + // Последний вариант viewPath, путь к папке компонента + $selected = count($this->viewPath) - 1; + $tpl = new PHPTAL(Path::join($this->viewPath[$selected], 'templates', 'modern', $name)); $tpl->setPhpCodeDestination(PHPTAL_PHP_CODE_DESTINATION); $template = 'modern'; - $selected = 0; } $tpl->stripComments(true); From b60398acd79ca961900a130518b721a535b78bed Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Mon, 3 Oct 2022 17:26:18 +0300 Subject: [PATCH 31/33] =?UTF-8?q?fix=20=D0=9F=D1=83=D1=82=D1=8C=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D1=83=D0=BC=D0=BE=D0=BB=D1=87=D0=B0=D0=BD=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Component.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Controller/Component.php b/src/Controller/Component.php index 1f1e18e..a528190 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -133,6 +133,10 @@ class Controller_Component return $tpl; } + function _getDefaultPath() { + return $this->viewPath[count($this->viewPath) - 1]; + } + public function getTemplatePath($name) { $registry/*: Settings*/ = $this->registry; // Брать настройки из куков если есть @@ -143,12 +147,12 @@ class Controller_Component } } - return Path::join($this->viewPath[0], 'templates', 'modern', $name); + return Path::join($this->viewPath[count($this->viewPath) - 1], 'templates', 'modern', $name); } public function getTemplateWebPath() { - return Path::join($this->webPath[0], 'templates', 'modern'); + return Path::join($this->webPath[count($this->webPath) - 1], 'templates', 'modern'); } /** @@ -181,7 +185,7 @@ class Controller_Component } function getInfo() { - $filename = Path::join($this->viewPath[0], 'install.json'); + $filename = Path::join($this->viewPath[count($this->viewPath) - 1], 'install.json'); if (file_exists($filename)) { $settings = json_decode(File::getContents($filename), true); return $settings; From df08cfaa60bfc5afcf86e882624ef3a9f438fa6c Mon Sep 17 00:00:00 2001 From: "origami11@yandex.ru" Date: Tue, 4 Oct 2022 14:43:36 +0300 Subject: [PATCH 32/33] =?UTF-8?q?=D0=A8=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=83=D0=BC=D0=BE=D0=BB=D1=87=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Component.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Controller/Component.php b/src/Controller/Component.php index a528190..209d765 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -86,7 +86,8 @@ class Controller_Component } public function getTemplateName($_registry/*: Settings*/) { - return (isset($_COOKIE['with_template']) && preg_match('/^[\w\d-]{3,20}$/', $_COOKIE['with_template'])) ? $_COOKIE['with_template'] : $_registry->readKey(array('system', 'template')); + return (isset($_COOKIE['with_template']) && preg_match('/^[\w\d-]{3,20}$/', $_COOKIE['with_template'])) + ? $_COOKIE['with_template'] : ($_registry ? $_registry->readKey(array('system', 'template')) : 'modern'); } public function getView($name) From 2cee29d7a0fba6d984f1ba114c6e88b7bc49c92d Mon Sep 17 00:00:00 2001 From: denis Date: Wed, 26 Oct 2022 17:46:00 +0300 Subject: [PATCH 33/33] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D1=81=D1=87=D0=B5?= =?UTF-8?q?=D1=82=20=D0=BA=D0=BE=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D1=82=D0=B2?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B5=D1=83=D0=B4=D0=B0=D1=87=D0=BD=D1=8B=D1=85?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BF=D1=8B=D1=82=D0=BE=D0=BA=20=D0=B0=D0=B2?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Filter/Login.php | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Filter/Login.php b/src/Filter/Login.php index 4a993a1..6d724bc 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -12,6 +12,8 @@ class Filter_Login extends Filter_Filter { const SESSION_BROWSER_SIGN_SECRET = '@w3dsju45Msk#'; const SESSION_BROWSER_SIGN_KEYNAME = 'session.app.browser.sign'; + const AUTH_MAX_ATTEMPT = 10; + const AUTH_LAST_ATTEMPT_TIMER = 600; public $mode = 'ajax'; public $user; @@ -42,18 +44,38 @@ class Filter_Login extends Filter_Filter $db = Database::getConnection($dsn); $user = $db->fetchOneArray("SELECT * FROM users WHERE login = :login", ['login' => $login]); - $userPassword = $user['password']; + $userPassword = $user['password']; } /*else if (time() - $result->getInt('lastupdate') > 60*60*24*60) { - // Проверить давность пароля, 60 дней + // Проверить давность пароля, 60 дней $request->set('error', true); $request->set('lastupdate', true); return false; }*/ - + // Проверка на количества попыток авторизации + $lastAttempt = $db->fetchOneArray( + "SELECT trie_count, trie_time FROM users WHERE login = :login", ['login' => $request->get('login')]); + if ($lastAttempt['trie_count'] >= self::AUTH_MAX_ATTEMPT /*&& time() - $lastAttempt['trie_time'] < self::AUTH_LAST_ATTEMPT_TIMER*/) { + if (time() - $lastAttempt['trie_time'] < self::AUTH_LAST_ATTEMPT_TIMER) { + $request->set('timeout_error', true); + break; + } else { + $db->executeQuery( + "UPDATE users SET trie_count = :count WHERE login = :login", + ['count' => 0, 'login' => $request->get('login')] + ); + } + } // Извлечнеие пользователя из родительской CMS, для проверки пароля if (md5($password) == $userPassword) { // password $this->enter($db, $result); return true; + } else { + // Обновление количества неудачных попыток входа + $user = $db->fetchOneArray("SELECT id_user, trie_count FROM users WHERE login = :login", ['login' => $login]); + $db->executeQuery( + "UPDATE users SET trie_time = :cur_time, trie_count = :count WHERE id_user = :id_user", + ['cur_time' => time(), 'count' => $user['trie_count']+=1, 'id_user' => $user['id_user']] + ); } } $request->set('error', true); @@ -110,7 +132,7 @@ class Filter_Login extends Filter_Filter { $this->user = $result; $random = rand(0, 1024 * 1024); - $db->executeQuery("UPDATE users SET sid = '$random' WHERE id_user = " . $result->getInt('id_user')); + $db->executeQuery("UPDATE users SET sid = '$random', trie_count = 0 WHERE id_user = " . $result->getInt('id_user')); $_SESSION["group"] = $result->getInt('access'); $_SESSION["access"] = $result->getInt('id_user'); // id_user