diff --git a/src/Controller/Component.php b/src/Controller/Component.php index f698f50..c8429da 100644 --- a/src/Controller/Component.php +++ b/src/Controller/Component.php @@ -177,7 +177,7 @@ class Controller_Component public function setParameters(/*.View_Composite.*/$view) { $form = new Form_Form(); - $options = new OptionFactory($this->db); + $options = new OptionFactory($this->db, $this->registry); $settings = $this->getInfo(); $form->addFieldList($settings['parameter'], $options); @@ -262,10 +262,16 @@ class Controller_Component $component->parameter = $params; $component->template = $params->get('template', false); - global $componentsConfig; $editor = $component->getEditUrl(); if ($editor) { - $componentsConfig[] = $editor; + if(class_exists("Controller_Site")){ //Если мы в CMS2 + $instance = Controller_Site::getInstance(); + $instance->componentsConfig[] = $editor; + }else{ + global $componentsConfig; + $componentsConfig[] = $editor; + + } } return $component; @@ -310,6 +316,10 @@ class Controller_Component return '?' . http_build_query($arr); } + /** + * @deprecated В CMS2 перенесено в контроллер сайта! + */ + function addRequireJsPath($name, $path, $shim = null) { Controller_Site::addRequireJsPath($name, $path, $shim); } diff --git a/src/Controller/Front.php b/src/Controller/Front.php index d317e2a..af064ad 100644 --- a/src/Controller/Front.php +++ b/src/Controller/Front.php @@ -101,6 +101,15 @@ class Controller_Front extends Controller_Action } else { $controller = false; } - return $this->loadModule($name[0], $request, $controller); + try{ + return $this->loadModule($name[0], $request, $controller); + } catch (UserMessageException $ex) { //Исключение с понятным пользователю сообщением + $mode = $request->get('mode'); + if($mode == 'ajax' || $mode == 'json'){ + return json_encode(['result'=>'fail', 'message'=> $ex->userMessage]); + } else { + return $ex->userMessage; + } + } } } diff --git a/src/Filter/ActionAccess.php b/src/Filter/ActionAccess.php index dc39ba0..7d4936f 100644 --- a/src/Filter/ActionAccess.php +++ b/src/Filter/ActionAccess.php @@ -26,7 +26,8 @@ class Filter_ActionAccess $action = $request->getAction(); if(! $this->checkAction($action)) { $request->set('action', 'index'); - } + $request->setAction('index'); + } return $this->processor->execute($request); } } diff --git a/src/Filter/Login.php b/src/Filter/Login.php index 4ce7302..82e53d8 100644 --- a/src/Filter/Login.php +++ b/src/Filter/Login.php @@ -15,7 +15,8 @@ class Filter_Login extends Filter_Filter public $mode = 'ajax'; //AJAX-Реквесты для которых не требуется авторизация, потребовалось для сбора статистики - public $whiteRequestList = array(array('module' => "requiredcontent", "action" => "getcount")); + public $whiteRequestList = [['module' => "requiredcontent", "action" => "getcount"], + ['module' => "requiredcontent", "action" => "teststructure"]]; /** * Проверка авторизации * @return Boolean Авторизовани пользователь или нет diff --git a/src/Form/Form.php b/src/Form/Form.php index f79c9f3..458e8fa 100644 --- a/src/Form/Form.php +++ b/src/Form/Form.php @@ -190,9 +190,10 @@ class TDateTime extends TInput { class OptionFactory { public $db; - - function __construct($db) { + public $registry; + function __construct($db, $registry = null) { $this->db = $db; + $this->registry = $registry; } function create(TSelect $field, $input) { @@ -225,6 +226,10 @@ class OptionFactory { $field->options = $this->optionsDB($key, $value, $query_result); } elseif (isset($input['options.pair'])) { $field->options = $this->optionsPair($input['options.pair']); + } elseif (isset($input['options.model'])) { + $factory = new Model_Factory($this->db, $this->registry); + $model = $factory->getModel($input['options.model']); + $field->options = $model->getAllAsOptions(); } else { $field->options = $input['options']; } diff --git a/src/UserMessageException.php b/src/UserMessageException.php new file mode 100644 index 0000000..88286de --- /dev/null +++ b/src/UserMessageException.php @@ -0,0 +1,17 @@ +userMessage = $message; + } +} \ No newline at end of file diff --git a/src/View/Page.php b/src/View/Page.php index acddc60..847061c 100644 --- a/src/View/Page.php +++ b/src/View/Page.php @@ -49,10 +49,14 @@ class View_Page extends View_View { //$result = phptal_component($match, $offset); - //* - global $db, $registry; // Нужно как-то передавать параметры - - $component = Controller_Component::loadComponent($match, $db, $registry); + + 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']); diff --git a/src/tales.php b/src/tales.php index 416263b..5739bef 100644 --- a/src/tales.php +++ b/src/tales.php @@ -45,10 +45,14 @@ function phptal_time ($e) * Функция подключения компонента */ function phptal_component ($expression) { - global $db, $registry; // Нужно как-то передавать параметры - $begin = microtime(true); - $component = Controller_Component::loadComponent($expression, $db, $registry); + + if(class_exists("Controller_Site")){ //Если мы в CMS2 + $component = Controller_Site::loadComponent($expression); + }else{ + global $db, $registry; // Иначе обращаемся к глобальным переменным + $component = Controller_Component::loadComponent($expression, $db, $registry); + } $req = new HttpRequest(); $result = $component->execute($req);