Merge branch 'master' into noglob
This commit is contained in:
commit
7d35a8f3f0
27 changed files with 430 additions and 288 deletions
|
|
@ -88,6 +88,11 @@ class Component
|
|||
}
|
||||
}
|
||||
|
||||
public function getTemplateName($_registry/*: Settings*/) {
|
||||
return (isset($_COOKIE['with_template']) && preg_match('/^[\w\d-]{3,20}$/', $_COOKIE['with_template']))
|
||||
? $_COOKIE['with_template'] : ($_registry ? $_registry->get('site', 'template') : 'modern');
|
||||
}
|
||||
|
||||
public function getView($name)
|
||||
{
|
||||
if ($this->output == 'json') {
|
||||
|
|
@ -96,12 +101,13 @@ class Component
|
|||
|
||||
$config/*: Registry*/ = $this->config;
|
||||
$default = $config->get('site', 'template');
|
||||
$template = ($this->template) ? $this->template : $default;
|
||||
$template = ($this->template) ? $this->template : $this->getTemplateName($config);
|
||||
|
||||
$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;
|
||||
|
|
@ -110,10 +116,11 @@ class 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);
|
||||
|
|
@ -135,13 +142,26 @@ class Component
|
|||
return $tpl;
|
||||
}
|
||||
|
||||
function _getDefaultPath() {
|
||||
return $this->viewPath[count($this->viewPath) - 1];
|
||||
}
|
||||
|
||||
public function getTemplatePath($name) {
|
||||
return Path::join($this->viewPath[0], 'templates', 'modern', $name);
|
||||
$registry/*: Settings*/ = $this->config;
|
||||
// Брать настройки из куков если есть
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -184,7 +204,7 @@ class Component
|
|||
}
|
||||
|
||||
function getInfo() {
|
||||
$filename = $this->findFile($this->viewPath, '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;
|
||||
|
|
@ -197,10 +217,10 @@ class Component
|
|||
*/
|
||||
public function setParameters($view/*: Composite*/, $options = null)
|
||||
{
|
||||
$form = new Form();
|
||||
$form = new Form();
|
||||
|
||||
$settings = $this->getInfo();
|
||||
$form->addFieldList($settings['parameter'], $options);
|
||||
$form->addFieldList($settings['parameter'], $options);
|
||||
|
||||
$view->form = $form;
|
||||
$view->component = $settings['component'];
|
||||
|
|
@ -224,7 +244,7 @@ class Component
|
|||
}
|
||||
$name = $path;
|
||||
|
||||
$path = Path::join ($this->config->get('site', 'path'), 'components', $name, $name . '.php');
|
||||
$path = Path::join ($site->config->get('site', 'path'), 'components', $name, $name . '.php');
|
||||
$className = 'Component_' . $name;
|
||||
|
||||
$component/*: Component*/ = null;
|
||||
|
|
@ -233,19 +253,37 @@ class Component
|
|||
require_once ($path);
|
||||
$component = new $className();
|
||||
|
||||
$component->viewPath = array($this->config->get('site', 'path') . '/components/' . $name . '/');
|
||||
$component->webPath = array($this->config->get('site', 'web') . '/components/' . $name);
|
||||
$component->COMPONENTS_WEB = $this->config->get('site', 'web') . '/components/';
|
||||
$component->viewPath = array($site->config->get('site', 'path') . '/components/' . $name . '/');
|
||||
$component->webPath = array($site->config->get('site', 'web') . '/components/' . $name);
|
||||
$component->COMPONENTS_WEB = $site->config->get('site', 'web') . '/components/';
|
||||
|
||||
} else {
|
||||
$path = Path::join ($this->config->get('system', 'components'), $name, $name . '.php');
|
||||
$path = Path::join ($site->config->get('system', 'components'), $name, $name . '.php');
|
||||
require_once ($path);
|
||||
$component = new $className();
|
||||
|
||||
$component->viewPath = array($this->config->get('system', 'components') . '/' . $name . '/', $this->config->get('site', 'path') . '/components/' . $name . '/');
|
||||
$template = $component->getTemplateName($registry);
|
||||
|
||||
$component->viewPath = array(
|
||||
// Сначало ищем локально
|
||||
$site->config->get('site', 'path') . '/templates/' . $template . '/_components/' . $name . '/',
|
||||
$site->config->get('site', 'path') . '/components/' . $name . '/',
|
||||
// Потом в общем хранилище
|
||||
CMS_PATH . '/../templates/' . $template . '/_components/' . $name . '/',
|
||||
$site->config->get('system', 'components') . '/' . $name . '/',
|
||||
);
|
||||
if (defined('COMPONENTS_WEB')) {
|
||||
$component->webPath = array($this->config->get('system', 'components_web') . '/' . $name, $this->config->get('site', 'web') . '/components/' . $name);
|
||||
$component->COMPONENTS_WEB = $this->config->get('system', 'components_web');
|
||||
$component->webPath = array(
|
||||
// Сначало локально
|
||||
$site->config->get('site', 'web') . '/templates/' . $template . '/_components/' . $name,
|
||||
$site->config->get('site', 'web') . '/components/' . $name,
|
||||
// Потом в общем хранилище
|
||||
TEMPLATE_WEB . '/' . $template . '/_components/' . $name,
|
||||
COMPONENTS_WEB . '/' . $name,
|
||||
);
|
||||
$component->COMPONENTS_WEB = COMPONENTS_WEB;
|
||||
} else {
|
||||
$component->webPath = array('', $site->config->get('site', 'web') . '/components/' . $name, '');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class Front extends Action
|
|||
/**
|
||||
* Создает экземпляр модуля и выполняет действия для него
|
||||
* @param string $name Имя модуля
|
||||
* @param request $request Имя модуля
|
||||
* @param Request $request Имя модуля
|
||||
* @return string
|
||||
*/
|
||||
public function loadModule($name, Collection $request, $controller = null)
|
||||
|
|
@ -55,8 +55,6 @@ class Front extends Action
|
|||
$moulesPath = Path::join($config->get('system', 'path'), 'modules');
|
||||
$logPath = Path::join($config->get('site', 'path'), $config->get('system', 'access.log'));
|
||||
|
||||
$moduleFile = Path::join($moulesPath, $name, 'classes', $controller ? $controller : $name);
|
||||
|
||||
$ucname = ucfirst($name);
|
||||
$moduleClass = "Modules\\$ucname\\$ucname";
|
||||
$module = new $moduleClass();
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class Request {
|
|||
$this->id = $id;
|
||||
}
|
||||
|
||||
function get($name, $def) {
|
||||
function get($name, $def = null) {
|
||||
$v = $this->r->get($name);
|
||||
$id = $this->id;
|
||||
if ($id && is_array($v)) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
namespace ctiso\Controller;
|
||||
use ctiso\Path,
|
||||
ctiso\File,
|
||||
ctiso\Registry,
|
||||
ctiso\Database\PDOStatement;
|
||||
|
||||
|
|
@ -16,7 +17,7 @@ class Service
|
|||
public $template;
|
||||
public $templatePath;
|
||||
public $COMPONENTS_WEB;
|
||||
|
||||
|
||||
public $db;
|
||||
|
||||
public function getTemplatePath($name)
|
||||
|
|
@ -30,7 +31,7 @@ class Service
|
|||
}
|
||||
|
||||
/**
|
||||
* @param $name Имя модели
|
||||
* @param string $name Имя модели
|
||||
*/
|
||||
private function getModelPath($name)
|
||||
{
|
||||
|
|
@ -40,7 +41,7 @@ class Service
|
|||
/**
|
||||
* Создает модель
|
||||
* @param string $name
|
||||
* @return model
|
||||
* @return Model
|
||||
*/
|
||||
public function getModel($name)
|
||||
{
|
||||
|
|
@ -66,5 +67,14 @@ class 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue