diff --git a/src/Controller/Action.php b/src/Controller/Action.php index ca3a547..2078409 100644 --- a/src/Controller/Action.php +++ b/src/Controller/Action.php @@ -5,12 +5,12 @@ use ctiso\Shortcut, Exception, ctiso\Path, ctiso\Url, - ctiso\View\View, ctiso\Model\Factory, ctiso\HttpRequest, ctiso\Functions, ctiso\Settings, ctiso\View\Composite, + ctiso\Filter\ActionAccess, ctiso\View\View, ctiso\Controller\State; @@ -43,7 +43,7 @@ class Action private $factory = null; // Ссылка на обьект создания модели private $helpers = array(); // Помошники для действий - public $param = array(); // Параметры для ссылки + public $part = null; // Параметры для ссылки public /*.Settings.*/$settings; // Ссылка на настройки public $user; // Обьект пользователя @@ -55,6 +55,7 @@ class Action public $childViews = array(); function __construct() { + $this->part = new Url(); } public function setUp() { @@ -198,6 +199,10 @@ class Action return ""; } + public function addUrlPart($key, $value) { + $this->part->addQueryParam($key, $value); + } + /** * Генерация ссылки c учетом прав пользователя на ссылки * @param string $name Действие @@ -208,16 +213,20 @@ class Action public function nUrl($name, array $param = array()) { /*.ActionAccess.*/$access = $this->access; + $url = new Url(); if ($access == null || $access->checkAction($name)) { $param = array_merge(array( 'module' => strtr($this->modulePrefix . strtolower(get_class($this)), array('module_' => '')), "action" => $name + ), $param); - return new Url($param); + $url->setParent($this->part); + $url->setQuery($param); } - return new Url(); + + return $url; } /** @@ -318,7 +327,7 @@ class Action */ public function render() { - if ($this->view instanceof View_View) { + if ($this->view instanceof View) { $this->view->assignValues($this->ctrlValues); /*.Composite.*/$node = null; diff --git a/src/Controller/Component.php b/src/Controller/Component.php index 1e94b27..c87cf59 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -8,6 +8,7 @@ use ctiso\HttpRequest, ctiso\File, ctiso\Form\Form, ctiso\Form\OptionFactory, + ctiso\View\Composite, ctiso\Database, ctiso\Database\PDOStatement, ctiso\Collection, @@ -38,7 +39,7 @@ class FakeTemplate { } function execute() { - return $this->_data; + return json_encode($this->_data); } } @@ -64,6 +65,7 @@ class Component public $module; public $item_module; + public $site; function before() { } @@ -95,7 +97,6 @@ class Component return new FakeTemplate($name); } - // /*.Settings.*/$registry = $this->registry; $template = ($this->template) ? $this->template : $registry->readKey(array('system', 'template')); @@ -195,7 +196,7 @@ class Component /** * Генерация интерфейса для выбора галлереи фотографии */ - public function setParameters(/*.Composite.*/$view) + public function setParameters(/*.Composite.*/ $view) { $form = new Form(); $options = new OptionFactory($this->db, $this->registry); @@ -208,7 +209,7 @@ class Component $view->component_title = $settings['title']; } - static function loadComponent($expression, Database $db, /*.Settings.*/ $registry) + static function loadComponent($expression, /*.Site.*/ $site) { $expression = htmlspecialchars_decode($expression); @@ -232,22 +233,16 @@ class Component if (file_exists($path)) { require_once ($path); - $component = new $className(); - $component->db = $db; - $component->registry = $registry; $component->viewPath = array(BASE_PATH . '/components/' . $name . '/'); $component->webPath = array(SITE_WWW_PATH . '/components/' . $name); - $component->COMPONENTS_WEB = SITE_WWW_PATH . '/components/'; } else { $path = Path::join (COMPONENTS, $name, $name . '.php'); require_once ($path); $component = new $className(); - $component->db = $db; - $component->registry = $registry; $component->viewPath = array(COMPONENTS . '/' . $name . '/', BASE_PATH . '/components/' . $name . '/'); if (defined('COMPONENTS_WEB')) { @@ -255,6 +250,12 @@ class Component $component->COMPONENTS_WEB = COMPONENTS_WEB; } } + + $db = $site->db; + + $component->db = $db; + $component->registry = $site->registry; + $component->site = $site; $stmt = $db->prepareStatement("SELECT * FROM component WHERE code = ?"); $stmt->setString(1, $expression); @@ -282,18 +283,13 @@ class Component $params = new Collection(); $params->import($arguments); + $component->parameter = $params; $component->template = $params->get('template', false); $editor = $component->getEditUrl(); if ($editor) { - if (class_exists("Controller_Site")) { //Если мы в CMS2 - $instance = Site::getInstance(); - $instance->componentsConfig[] = $editor; - } else { - global $componentsConfig; - $componentsConfig[] = $editor; - } + $site->componentsConfig[] = $editor; } return $component; @@ -338,12 +334,8 @@ class Component return '?' . http_build_query($arr); } - /** - * @deprecated В CMS2 перенесено в контроллер сайта! - */ - function addRequireJsPath($name, $path, $shim = null) { - Site::addRequireJsPath($name, $path, $shim); + $this->site->addRequireJsPath($name, $path, $shim); } function actionIndex(/*.ComponentRequest.*/ $request) { diff --git a/src/Controller/Front.php b/src/Controller/Front.php index 9e55c82..5f243af 100644 --- a/src/Controller/Front.php +++ b/src/Controller/Front.php @@ -51,7 +51,7 @@ class Front extends Action return $module->access->execute($request); } - $system = $this->settings['system']; + /*.Settings.*/$system = $this->settings['system']; $moulesPath = Path::join($this->settings['base'], $system->readKey(['path', 'modules'])); $logPath = Path::join($this->settings['site'], $system->readKey(['path', 'access.log'])); diff --git a/src/Database.php b/src/Database.php index bd013e0..9ac4c6d 100644 --- a/src/Database.php +++ b/src/Database.php @@ -181,8 +181,8 @@ class Database extends PDO return $result['nextval']; } - function prepare($query) { - /*.PDOStatement.*/$result = $this->prepare($query); + function prepare($query, $options = NULL) { + /*.PDOStatement.*/$result = parent::prepare($query); return $result; } diff --git a/src/Filter/ActionLogger.php b/src/Filter/ActionLogger.php index d7da199..93c11e7 100644 --- a/src/Filter/ActionLogger.php +++ b/src/Filter/ActionLogger.php @@ -3,6 +3,7 @@ namespace ctiso\Filter; use ctiso\HttpRequest; +/* Переделать формат Логов на список json */ class ActionLogger { public $before = array(); @@ -14,13 +15,19 @@ class ActionLogger function __construct(/*.Filter.*/$processor, $logPath, $user) { $this->processor = $processor; $this->user = $user; - $this->file = fopen($logPath, "a"); + $file = fopen($logPath, "a"); + if (is_resource($file)) { + $this->file = $file; + } else { + throw new \Exception('Ошибка открытия файла ' . $logPath); + } } 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: " . $this->user->name . "\n"); + $message = ["time" => date("r", time()), "query" => array_merge($_POST, $_GET), "user" => $this->user->name]; + fwrite($this->file, json_encode($message) . "\n"); } return $this->processor->execute($request); } diff --git a/src/Filter/Login.php b/src/Filter/Login.php index 851e966..74f2259 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -162,7 +162,7 @@ class Login extends Filter /* --------------------- * Проверка на попадание реквеста в белый список */ - public function requestIsWhite(Collection $request, $whiteRequestList){ + public function requestIsWhite(HttpRequest $request, $whiteRequestList){ $module = $request->get('module'); $action = $request->get('action'); foreach ($whiteRequestList as $whiteRequest) { diff --git a/src/HttpRequest.php b/src/HttpRequest.php index f88fb0c..5e1b519 100644 --- a/src/HttpRequest.php +++ b/src/HttpRequest.php @@ -9,10 +9,6 @@ use Exception, ctiso\Collection, ctiso\Session; -class WrongRequestException extends Exception -{ -} - // HTTPRequest = ArrayAccess class HttpRequest extends Collection implements ArrayAccess { @@ -132,4 +128,8 @@ class HttpRequest extends Collection implements ArrayAccess public function offsetGet($key) { } + + static function getProtocol() { + return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://"; + } } diff --git a/src/Tales.php b/src/Tales.php index 58a341d..c0e09d4 100644 --- a/src/Tales.php +++ b/src/Tales.php @@ -14,11 +14,11 @@ use PHPTAL_Php_TalesInternal, class Tales_DateTime implements PHPTAL_Tales { static public function date($expression, $nothrow = false) { - return "ctiso\\Tales::phptal_date(".PHPTAL_Php_TalesInternal::path ($expression).")"; + return "ctiso\\Tales::phptal_date(".PHPTAL_Php_TalesInternal::path($expression).")"; } static public function time($expression, $nothrow = false) { - return "ctiso\\Tales::phptal_time(".PHPTAL_Php_TalesInternal::path ($expression).")"; + return "ctiso\\Tales::phptal_time(".PHPTAL_Php_TalesInternal::path($expression).")"; } } @@ -32,8 +32,7 @@ class Tales_Component implements PHPTAL_Tales } class Tales { - static $db; - static $registry; + static $site; static function phptal_date ($e) { return date("d.m.Y", $e); @@ -50,11 +49,7 @@ class Tales { $begin = floatval(microtime(true)); /*.Component.*/$component = null; - if (class_exists("ctiso\\Controller\\Site")) { //Если мы в CMS2 - $component = Site::loadComponent($expression); - } else { - $component = Component::loadComponent($expression, self::$db, self::$registry); - } + $component = self::$site->loadComponent($expression); $req = new HttpRequest(); $result = $component->execute($req); @@ -63,9 +58,8 @@ class Tales { } - static function register($db, $registry) { - self::$db = $db; - self::$registry = $registry; + static function register($site) { + self::$site = $site; /* Регистрация нового префикса для подключения компонента */ $tales = PHPTAL_TalesRegistry::getInstance(); diff --git a/src/Url.php b/src/Url.php index f52baec..3b879ef 100644 --- a/src/Url.php +++ b/src/Url.php @@ -3,13 +3,25 @@ namespace ctiso; class Url { - public $parts; + public $parts = []; + public $parent; - function __construct($parts = []) { + function __construct() { + } + + function setParent($parent) { + $this->parent = $parent; + } + + function setQuery($parts) { $this->parts = $parts; } + function addQueryParam($key, $value) { + $this->parts[$key] = $value; + } + function toString() { - return '?' . http_build_query($this->parts); + return '?' . http_build_query(array_merge($this->parts, $this->parent->parts)); } } \ No newline at end of file diff --git a/src/View/Page.php b/src/View/Page.php index 10e40ec..4ccb457 100644 --- a/src/View/Page.php +++ b/src/View/Page.php @@ -10,9 +10,11 @@ class Page extends View { private $counter; public $text; + public $site; - function __construct($data) + function __construct($data, $site) { + $this->site = $site; // Вставка компонентов на странице $pattern = '/<(\w+)(\s+[a-zA-Z\-]+=\"[^\"]*\")*\s+tal:replace="structure\s+component:([^\"]*)"[^>]*>/u'; $matches = array(); @@ -53,15 +55,8 @@ class Page extends View function replaceContent($match, $offset) { - //$result = phptal_component($match, $offset); /*.Component.*/$component = null; - - if (class_exists("App\\Controller\\Site")) { //Если мы в CMS2 - $component = Site::loadComponent($match); - } else { - global $db, $registry; // - $component = Component::loadComponent($match, $db, $registry); - } + $component = $this->site->loadComponent($match); $req = new HttpRequest(); unset($req['active_page']); diff --git a/src/WrongRequestException.php b/src/WrongRequestException.php new file mode 100644 index 0000000..6ebddfc --- /dev/null +++ b/src/WrongRequestException.php @@ -0,0 +1,7 @@ +