From f0414885543232bf0f4e80fc5eb286f79f5cd9ae Mon Sep 17 00:00:00 2001 From: "CORP\\phedor" Date: Wed, 28 Mar 2018 12:43:06 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F?= =?UTF-8?q?=D0=B5=D0=BC=D1=81=D1=8F=20=D0=BE=D1=82=20=D0=BA=D0=BE=D0=BD?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=BD=D1=82=20=D0=B8=20=D0=B3=D0=BB=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D1=85=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/Action.php | 21 +++++++++++++-------- src/Controller/Front.php | 23 ++++++++++++----------- src/Database.php | 2 +- src/Database/PDOStatement.php | 6 ++---- src/Filter/ActionLogger.php | 12 ++++++------ src/Filter/Filter.php | 2 +- src/Filter/Login.php | 2 +- src/HttpRequest.php | 1 + src/Layout/{Empty.php => Blank.php} | 2 +- src/Layout/Manager.php | 1 + 10 files changed, 39 insertions(+), 33 deletions(-) rename src/Layout/{Empty.php => Blank.php} (90%) diff --git a/src/Controller/Action.php b/src/Controller/Action.php index 300eb99..d833f55 100644 --- a/src/Controller/Action.php +++ b/src/Controller/Action.php @@ -52,7 +52,6 @@ class Action public $param = array(); // Параметры для ссылки public /*.Registry.*/$_registry; // Ссылка на реестр - public $_shortcut; public $modulePrefix = ''; public $iconPath = ''; @@ -69,10 +68,12 @@ class Action } public function loadConfig($name) { - $filename = Shortcut::getUrl('config', $name); + $basePath = $this->settings['base']; + + $filename = Path::join($basePath, 'modules', $name); $settings = []; if (file_exists($filename)) { - include($filename); + $settings = include($filename); } else { throw new Exception('Невозможно загрузить файл настроек ' . $name); } @@ -86,7 +87,8 @@ class Action public function installPath($name) { - return Path::join(CMS_PATH, "modules", $name); + $basePath = $this->settings['base']; + return Path::join($basePath, "modules", $name); } public function addSuggest(View $view, $name) @@ -110,13 +112,16 @@ class Action * @param $viewClass String * @return View_Composite */ - public function getView($name, $viewClass = 'View_Composite') + public function getView($name, $viewClass = 'ctiso\\View\\Composite') { $file = $name . self::TEMPLATE_EXTENSION; + $basePath = $this->settings['base']; + $webPath = $this->settings['web']; + $list = array( - Path::join($this->viewPath, TEMPLATES, $this->viewPathPrefix) => Path::join(WWW_PATH, "modules", $this->name, TEMPLATES, $this->viewPathPrefix), - Path::join(CMS_PATH, "templates") => Path::join(WWW_PATH, "templates") + Path::join($this->viewPath, 'templates', $this->viewPathPrefix) => Path::join($webPath, "modules", $this->name, 'templates', $this->viewPathPrefix), + Path::join($basePath, "templates") => Path::join($webPath, "templates") ); // Поиск файла для шаблона @@ -127,7 +132,7 @@ class Action /*.View_Composite.*/$tpl = new $viewClass($template); - $assets = Path::join(enableHttps(WWW_PATH), "assets", "css"); + $assets = Path::join($webPath, "assets", "css"); $tpl->set('icons', $this->iconPath); // Путь к файлам текущей темы $tpl->set('media', $this->themePath); // Путь к файлам текущей темы $tpl->set('assets', $assets); diff --git a/src/Controller/Front.php b/src/Controller/Front.php index f2ff867..5453892 100644 --- a/src/Controller/Front.php +++ b/src/Controller/Front.php @@ -11,28 +11,26 @@ use ctiso\Controller\Action, ctiso\Collection, ctiso\Filter\ActionAccess, ctiso\Filter\ActionLogger, - ctiso\Path; + ctiso\Path, ctiso\UserMessageException, ctiso\HttpRequest; class Front extends Action { - /** @var Shortcut */ - protected $shortcut; // Ярлык к модулю protected $_param; // Параметр по которому выбирается модуль protected $default; // Значение параметра по умолчанию protected $modules = array(); /** - * @param Settings $_registry - * @param Shortcut $_shortcut + * @param Settings $settings */ - public function __construct($db, $settings, $default) { + public function __construct($db, $settings, $user, $default) { parent::__construct(); $this->settings = $settings; $this->db = $db; + $this->user = $user; $this->default = $default; } @@ -52,23 +50,26 @@ class Front extends Action $module = $this->modules[$name]; return $module->access->execute($request); } + + $system = $this->settings['system']; - $basePath = $this->settings['system']->readKey(['path', 'modules']); - $moduleFile = Path::join($basePath, $name, 'classes', $controller ? $controller : $name); + $moulesPath = $system->readKey(['path', 'modules']); + $logPath = Path::join($this->settings['site'], $system->readKey(['path', 'access.log'])); + $moduleFile = Path::join($this->settings['base'], $moulesPath, $name, 'classes', $controller ? $controller : $name); $ucname = ucfirst($name); - $moduleClass = "Module\\$ucname\\$ucname"; + $moduleClass = "Modules\\$ucname\\$ucname"; $module = new $moduleClass(); if ($module) { // Инициализация модуля - $modPath = Path::join($basePath, $name); + $modPath = Path::join($moulesPath, $name); $module->viewPath = $modPath; $module->name = $name; // $module->settings = $this->settings; $module->db = $this->db; // Ведение лога - $logger = new ActionLogger($module); + $logger = new ActionLogger($module, $logPath, $this->user); $logger->before = $this->loadSettings(Path::join($modPath, 'filter', 'logger.php')); // Управление доступом $module->access = new ActionAccess($logger); diff --git a/src/Database.php b/src/Database.php index f3d0800..cd196f8 100644 --- a/src/Database.php +++ b/src/Database.php @@ -17,7 +17,7 @@ class Database extends PDO { parent::__construct($dsn, $username, $password); $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('Database_PDOStatement', array())); + $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array('ctiso\\Database\\PDOStatement', array())); } public function getDSN() diff --git a/src/Database/PDOStatement.php b/src/Database/PDOStatement.php index c284683..48e591a 100644 --- a/src/Database/PDOStatement.php +++ b/src/Database/PDOStatement.php @@ -1,11 +1,9 @@ processor = $processor; - $this->file = fopen(Shortcut::getUrl('access.log'), "a"); + $this->user = $user; + $this->file = fopen($logPath, "a"); } 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: " . UserAccess::$name . "\n"); + fwrite($this->file, "time: " . date("r", time()) . " query: ". json_encode(array_merge($_POST, $_GET)) . " by: " . $this->user->name . "\n"); } return $this->processor->execute($request); } diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index 233a9f3..b61b5c8 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -19,7 +19,7 @@ class Filter return $this->processor->execute($request); } - public function getView($name, $class = 'View_Top') + public function getView($name, $class = 'ctiso\\View\\Top') { return $this->processor->getView($name, $class); } diff --git a/src/Filter/Login.php b/src/Filter/Login.php index 92f0b47..6e5f242 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -74,7 +74,7 @@ class Login extends Filter // Если $hash не совпадает $_SESSION['hash'] то удаляем сессию if (isset($_SESSION ['access']) && isset($_SESSION[self::SESSION_BROWSER_SIGN_KEYNAME])) { if ($hash == $_SESSION[self::SESSION_BROWSER_SIGN_KEYNAME]) { - $this->user = $user = $role->getUserById($_SESSION['access']); // Поиск по идентификатору + $this->user = $user = $this->role->getUserById($_SESSION['access']); // Поиск по идентификатору if ($user && isset($_SESSION['random']) && ($user->get('sid') == $_SESSION['random'])) { return true; } diff --git a/src/HttpRequest.php b/src/HttpRequest.php index 21efe01..f88fb0c 100644 --- a/src/HttpRequest.php +++ b/src/HttpRequest.php @@ -5,6 +5,7 @@ */ namespace ctiso; use Exception, + ArrayAccess, ctiso\Collection, ctiso\Session; diff --git a/src/Layout/Empty.php b/src/Layout/Blank.php similarity index 90% rename from src/Layout/Empty.php rename to src/Layout/Blank.php index 202f0d2..f731df3 100644 --- a/src/Layout/Empty.php +++ b/src/Layout/Blank.php @@ -7,7 +7,7 @@ namespace ctiso\Layout; use ctiso\Filter\Filter, ctiso\HttpRequest; -class Empty extends Filter +class Blank extends Filter { function execute(HttpRequest $request) { diff --git a/src/Layout/Manager.php b/src/Layout/Manager.php index 63ccb0a..884fb3b 100644 --- a/src/Layout/Manager.php +++ b/src/Layout/Manager.php @@ -67,6 +67,7 @@ class Manager extends Filter */ public function execute(HttpRequest $request) { +// print_r($request->get('mode')); foreach ($this->condition as $condition) { if (call_user_func($condition[0], $request)) { $layout = $condition[1];