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, '');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue