Merge branch 'master' into noglob
This commit is contained in:
commit
7d35a8f3f0
27 changed files with 430 additions and 288 deletions
|
|
@ -1,77 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace ctiso\View;
|
||||
use ctiso\View\View,
|
||||
ctiso\Controller\SiteInterface,
|
||||
ctiso\Controller\Component,
|
||||
ctiso\HttpRequest;
|
||||
|
||||
class Page extends View
|
||||
{
|
||||
private $counter;
|
||||
public $text;
|
||||
public $site/*: SiteInterface*/;
|
||||
|
||||
function __construct($data, $site)
|
||||
{
|
||||
$this->site = $site;
|
||||
// Вставка компонентов на странице
|
||||
$pattern = '/<(\w+)(\s+[a-zA-Z\-]+=\"[^\"]*\")*\s+tal:replace="structure\s+component:([^\"]*)"[^>]*>/u';
|
||||
$matches = array();
|
||||
preg_match_all($pattern, $data, $matches, PREG_OFFSET_CAPTURE, 0);
|
||||
|
||||
$split = array();
|
||||
$offset = 0;
|
||||
foreach ($matches[0] as $key => $match) {
|
||||
$text = $this->fixHTML(substr($data, $offset, $match[1] - $offset));
|
||||
if (trim($text)) {
|
||||
$split[] = array('type' => 'page-text', 'content' => $text, 'component' => '', 'module' => '');
|
||||
}
|
||||
$offset = $match[1] + strlen($match[0]);
|
||||
$split[] = $this->replaceContent($matches[3][$key][0], $matches[3][$key][1]);
|
||||
}
|
||||
$text = $this->fixHTML(substr($data, $offset));
|
||||
if (trim($text)) {
|
||||
$split[] = array('type' => 'page-text', 'content' => $text, 'component' => '', 'module' => '');
|
||||
}
|
||||
|
||||
$this->text = $this->merge($split);
|
||||
}
|
||||
|
||||
function fixHTML($fragment) {
|
||||
return $fragment;
|
||||
}
|
||||
|
||||
function merge($data) {
|
||||
if (count($data) == 0) {
|
||||
$data[] = array('type' => 'page-text', 'content' =>"<p>Добавьте текст<p>", 'component' => '', 'module' => '');
|
||||
}
|
||||
$result = array();
|
||||
foreach($data as $key => $part) {
|
||||
$result[] = $part['content'];
|
||||
}
|
||||
return implode("", $result);
|
||||
}
|
||||
|
||||
function replaceContent($match, $offset)
|
||||
{
|
||||
$component/*: Component*/ = $this->site->loadComponent($match);
|
||||
|
||||
$req = new HttpRequest();
|
||||
unset($req['active_page']);
|
||||
|
||||
$info = $component->getInfo();
|
||||
$result = $component->execute($req);
|
||||
|
||||
if (is_string($result)) {
|
||||
return array('type' => 'page-component', 'content' => $result, 'component' => $match);
|
||||
} else {
|
||||
$this->setView('view' . $this->counter++, $result);
|
||||
return array('type' => 'page-component', 'content' => $result->execute(), 'component' => $match);
|
||||
}
|
||||
}
|
||||
|
||||
function execute() {
|
||||
return $this->text;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace ctiso\View;
|
||||
|
||||
use ctiso\View\Composite;
|
||||
|
||||
class Top extends Composite {
|
||||
class Top extends Composite
|
||||
{
|
||||
/**
|
||||
* Общая строка заголовка
|
||||
*/
|
||||
public $mid = 0;
|
||||
public $require = array();
|
||||
public $mid = 0;
|
||||
public $require = array();
|
||||
public $deps = array();
|
||||
|
||||
public function getTitle()
|
||||
|
|
@ -18,8 +20,8 @@ class Top extends Composite {
|
|||
|
||||
private function findGroup($groups, $file)
|
||||
{
|
||||
foreach($groups as $key => $group) {
|
||||
if(in_array($file, $group)) {
|
||||
foreach ($groups as $key => $group) {
|
||||
if (in_array($file, $group)) {
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
|
|
@ -28,7 +30,7 @@ class Top extends Composite {
|
|||
|
||||
private function groupFiles(array $list, $debugMode = true)
|
||||
{
|
||||
$debug = ($debugMode) ? 'debug=1' : '';
|
||||
$debug = ($debugMode) ? 'debug=1' : '';
|
||||
$path = parse_url($this->config->get('system', 'web'), PHP_URL_PATH);
|
||||
|
||||
$groups = array();
|
||||
|
|
@ -37,7 +39,7 @@ class Top extends Composite {
|
|||
$result = array();
|
||||
foreach ($list as $file) {
|
||||
$name = $this->findGroup($groups, $file);
|
||||
if($name) {
|
||||
if ($name) {
|
||||
$use[$name] = 1;
|
||||
} else {
|
||||
$result[] = $file;
|
||||
|
|
@ -52,17 +54,18 @@ class Top extends Composite {
|
|||
}
|
||||
|
||||
|
||||
function getId($pref) {
|
||||
$this->mid++;
|
||||
return $pref.$this->mid;
|
||||
}
|
||||
function getId($pref)
|
||||
{
|
||||
$this->mid++;
|
||||
return $pref . $this->mid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Обработка шаблона
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
public function render()
|
||||
{
|
||||
|
||||
$alias = $this->doTree('alias');
|
||||
|
|
@ -72,51 +75,52 @@ class Top extends Composite {
|
|||
$this->set('scripts', array_unique($this->groupFiles($this->getScripts(), false)));
|
||||
$this->set('stylesheet', array_unique($this->groupFiles($this->getStyleSheet(), false)));
|
||||
|
||||
$this->require = array('admin' => 'ma');
|
||||
$this->deps = array();
|
||||
$this->require = array('admin' => 'ma');
|
||||
$this->deps = array();
|
||||
|
||||
$startup = array();
|
||||
foreach($this->_section as $s) {
|
||||
$startup = array();
|
||||
foreach ($this->_section as $s) {
|
||||
if (is_string($s)) {
|
||||
continue;
|
||||
}
|
||||
$moduleName = explode('_', $s->active_module, 2);
|
||||
$moduleName = explode('_', $s->active_module, 2);
|
||||
if (count($moduleName) < 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$module = $moduleName[1];
|
||||
|
||||
$name = mb_strtolower($module);
|
||||
$fname = $name . '/' . $name;
|
||||
$name = mb_strtolower($module);
|
||||
$fname = $name . '/' . $name;
|
||||
|
||||
$current = $this->getId('m');
|
||||
$this->require[$fname] = $current;
|
||||
$current = $this->getId('m');
|
||||
$this->require[$fname] = $current;
|
||||
|
||||
$value = $this->getId('v');
|
||||
$value = $this->getId('v');
|
||||
|
||||
$script = "var " . $value . " = new " . $current . '.' . $module . "();\n";
|
||||
foreach($s->_values as $key => $v) {
|
||||
$script .= $value . "." . $key . " = " . json_encode($v/*, JSON_PRETTY_PRINT*/) . ";\n";
|
||||
}
|
||||
$script = "var " . $value . " = new " . $current . '.' . $module . "();\n";
|
||||
foreach ($s->_values as $key => $v) {
|
||||
$script .= $value . "." . $key . " = " . json_encode($v /*, JSON_PRETTY_PRINT*/) . ";\n";
|
||||
}
|
||||
|
||||
$init = array();
|
||||
foreach($s->_section as $key => $item) {
|
||||
$ss/*: View*/ = $item;
|
||||
$init = array();
|
||||
foreach ($s->_section as $key => $item) {
|
||||
$ss /*: View*/= $item;
|
||||
if ($ss->codeGenerator !== null) {
|
||||
// функцию которая вычисляет а не результат
|
||||
$part = call_user_func($ss->codeGenerator, $this, $key, $value);
|
||||
$init [] = $part;
|
||||
}
|
||||
}
|
||||
// функцию которая вычисляет а не результат
|
||||
$part = call_user_func($ss->codeGenerator, $this, $key, $value);
|
||||
$init[] = $part;
|
||||
}
|
||||
}
|
||||
|
||||
$script .= $value . ".execute('" . $s->module_action . "', " . json_encode($init) .");\n";
|
||||
$startup[] = $script;
|
||||
}
|
||||
$script .= $value . ".execute('" . $s->module_action . "', " . json_encode($init) . ");\n";
|
||||
$startup[] = $script;
|
||||
}
|
||||
|
||||
|
||||
$this->set('startup', implode("", $startup) . $this->getScriptStartup());
|
||||
$this->set('require', implode(",", array_map(function ($x) { return "'$x'";}, array_keys($this->require))));
|
||||
$this->set('require', implode(",", array_map(function ($x) {
|
||||
return "'$x'"; }, array_keys($this->require))));
|
||||
$this->set('deps', implode(",", array_values($this->require)));
|
||||
|
||||
$this->set('title', $this->getTitle());
|
||||
|
|
@ -160,4 +164,4 @@ class Top extends Composite {
|
|||
return $this->doTree('_stylesheet');
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue