Другая интерпретация реестра

This commit is contained in:
CORP\phedor 2018-04-20 18:03:39 +03:00
parent 40fad0e75b
commit aaa9c2e1bf
21 changed files with 156 additions and 92 deletions

View file

@ -12,20 +12,11 @@ use ctiso\HttpRequest,
ctiso\Database,
ctiso\Database\PDOStatement,
ctiso\Collection,
ctiso\Settings,
ctiso\Registry,
App\Controller\Site,
PHPTAL,
PHPTAL_PreFilter_Normalize;
function replaceContent($match) {
$result = Tales\Component::phptal_component(htmlspecialchars_decode($match[3]));
return $result;
}
function applyComponents($text) {
return preg_replace_callback('/<(\w+)(\s+[a-zA-Z\-]+=\"[^\"]*\")*\s+tal:replace="structure\s+component:([^\"]*)"[^>]*>/u', 'replaceContent', $text);
}
class FakeTemplate {
public $_data = [];
public $_name = '';
@ -56,11 +47,13 @@ class Component
public $component_id;
public $component_title;
public $COMPONENTS_WEB;
public /*.Settings.*/$registry;
public /*.Registry.*/$config;
public /*.Database.*/$db;
public /*.Collection.*/$parameter;
public $output = 'html';
public $module;
@ -70,7 +63,12 @@ class Component
function before() {
}
function get($request, $key, $default) {
static function replaceContent($match) {
return \ctiso\Tales::phptal_component(htmlspecialchars_decode($match[3]));
}
static function applyComponents($text) {
return preg_replace_callback('/<(\w+)(\s+[a-zA-Z\-]+=\"[^\"]*\")*\s+tal:replace="structure\s+component:([^\"]*)"[^>]*>/u', 'ctiso\\Controller\\Component::replaceContent', $text);
}
function execute(HttpRequest $request, $has_id = true) {
@ -97,8 +95,9 @@ class Component
return new FakeTemplate($name);
}
/*.Settings.*/$registry = $this->registry;
$template = ($this->template) ? $this->template : $registry->readKey(array('system', 'template'));
/*.Registry.*/$config = $this->config;
$default = $config->get('site', 'template');
$template = ($this->template) ? $this->template : $default;
$selected = null;
foreach ($this->viewPath as $index => $viewPath) {
@ -121,13 +120,14 @@ class Component
$tpl->stripComments(true);
$tpl->addPreFilter(new PHPTAL_PreFilter_Normalize());
$tpl->set('common', Path::join(WWW_PATH, '../', 'common'));
$tpl->set('script', Path::join(WWW_PATH, 'js'));
$tpl->set('media', Path::join(TEMPLATE_WEB, $template));
if ($registry) {
$tpl->set('site_template', SITE_WWW_PATH . '/templates' . $registry->readKey(array('system', 'template')));
$tpl->set('common', Path::join($this->config->get('system', 'web'), '../', 'common'));
$tpl->set('script', Path::join($this->config->get('system', 'web'), 'js'));
$tpl->set('media', Path::join($this->config->get('system', 'templates_web'), $template));
if ($default) {
$tpl->set('site_template', $this->config->get('site', 'web') . '/templates/' . $default);
}
$tpl->set('base', SITE_WWW_PATH);
$tpl->set('base', $this->config->get('site', 'web'));
$tpl->set('component_base', $this->webPath[$selected]);
$tpl->set('component', Path::join($this->webPath[$selected], 'templates', $template));
@ -199,7 +199,7 @@ class Component
public function setParameters(/*.Composite.*/ $view)
{
$form = new Form();
$options = new OptionFactory($this->db, $this->registry);
$options = new OptionFactory($this->db, $this->config);
$settings = $this->getInfo();
$form->addFieldList($settings['parameter'], $options);
@ -226,7 +226,7 @@ class Component
}
$name = $path;
$path = Path::join (BASE_PATH, 'components', $name, $name . '.php');
$path = Path::join ($this->config->get('site', 'path'), 'components', $name, $name . '.php');
$className = 'Component_' . $name;
/*.Component.*/$component = null;
@ -235,26 +235,26 @@ class Component
require_once ($path);
$component = new $className();
$component->viewPath = array(BASE_PATH . '/components/' . $name . '/');
$component->webPath = array(SITE_WWW_PATH . '/components/' . $name);
$component->COMPONENTS_WEB = SITE_WWW_PATH . '/components/';
$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/';
} else {
$path = Path::join (COMPONENTS, $name, $name . '.php');
$path = Path::join ($this->config->get('system', 'components'), $name, $name . '.php');
require_once ($path);
$component = new $className();
$component->viewPath = array(COMPONENTS . '/' . $name . '/', BASE_PATH . '/components/' . $name . '/');
$component->viewPath = array($this->config->get('system', 'components') . '/' . $name . '/', $this->config->get('site', 'path') . '/components/' . $name . '/');
if (defined('COMPONENTS_WEB')) {
$component->webPath = array(COMPONENTS_WEB . '/' . $name, SITE_WWW_PATH . '/components/' . $name);
$component->COMPONENTS_WEB = 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');
}
}
$db = $site->db;
$component->db = $db;
$component->registry = $site->registry;
$component->config = $site->config;
$component->site = $site;
$stmt = $db->prepareStatement("SELECT * FROM component WHERE code = ?");