Частичная синхронизация с CMS
This commit is contained in:
parent
312f18a20a
commit
b26e521657
62 changed files with 827 additions and 5992 deletions
|
|
@ -1,40 +1,203 @@
|
|||
<?php
|
||||
|
||||
// Класс отображения
|
||||
// CompositeView !! Composite pattern
|
||||
|
||||
// View_Top => View_Base + View_List + View_Template
|
||||
class View_View
|
||||
{
|
||||
protected $document;
|
||||
protected $values;
|
||||
protected $_section = array(); // Вложенные шаблоны
|
||||
// Блоки
|
||||
protected $_stylesheet = array(); // Массив стилей текущего шаблона
|
||||
protected $_script = array(); // Массив скриптов текущего шаблона
|
||||
protected $_scriptstring = array();
|
||||
protected $_startup = array();
|
||||
protected $_values = array();
|
||||
|
||||
public function __construct ($document)
|
||||
{
|
||||
$this->document = $document;
|
||||
protected $_title = null; // Заголовок текущего шаблона
|
||||
|
||||
public $active_module;
|
||||
public $module_action;
|
||||
|
||||
public $suggestions; //подсказки
|
||||
|
||||
public $alias = array();
|
||||
public $codeGenerator = null;
|
||||
public $parent_view = null;
|
||||
|
||||
function __construct() {
|
||||
}
|
||||
|
||||
public function set($key, $value)
|
||||
/**
|
||||
* Связывет переменную с вложенным шаблоном
|
||||
*
|
||||
* @param string $section переменная шаблона
|
||||
* @param CompositeView $view вложенный шаблон
|
||||
*/
|
||||
public function setView($section, View_View $view)
|
||||
{
|
||||
$this->values[$key] = $value;
|
||||
$this->_section [$section] = $view;
|
||||
$view->parent_view = $this;
|
||||
}
|
||||
|
||||
public function __set($key, $value)
|
||||
public function assignValues($values)
|
||||
{
|
||||
$this->set($key, $value);
|
||||
$this->_values = $values;
|
||||
$this->_values["suggestions"] = $this->suggestions;
|
||||
}
|
||||
|
||||
public function execute()
|
||||
public function jGrowl($message, $args)
|
||||
{
|
||||
$result = $this->values;
|
||||
return self::getTemplateContent ($this->document, $result);
|
||||
$this->addScriptRaw('$.jGrowl("' . $message . '", ' . json_encode($args) . ");\n", true);
|
||||
}
|
||||
|
||||
static function getTemplateContent($document, $result)
|
||||
public function setGlobal($name, $args)
|
||||
{
|
||||
ob_start ();
|
||||
include ($document);
|
||||
$result = ob_get_contents ();
|
||||
ob_clean ();
|
||||
$this->addScriptRaw("var " . $name . " = " . json_encode($args) . ";\n", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавляет скипт к текущему шаблону
|
||||
*
|
||||
* @param string $name путь к скрипту
|
||||
*/
|
||||
public function addScript($name)
|
||||
{
|
||||
$output = $this->resolveName($this->alias, $name);
|
||||
$this->_script [] = $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавляет код скипта к текущему шаблону
|
||||
*
|
||||
* @param string $name строка javascript кода
|
||||
*/
|
||||
public function addScriptRaw($name, $startup = false)
|
||||
{
|
||||
if ($startup) {
|
||||
$this->_startup [] = $name;
|
||||
} else {
|
||||
$this->_scriptstring [] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавляет стили к текущему шаблону
|
||||
*
|
||||
* @param string $name путь к стилю
|
||||
*/
|
||||
public function addStyleSheet($name)
|
||||
{
|
||||
$output = $this->resolveName($this->alias, $name);
|
||||
$this->_stylesheet [] = $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Рекурсивно извлекает из значение свойства обьекта
|
||||
*
|
||||
* @param string $list Имя свойства
|
||||
* @param boolean $flatten
|
||||
*/
|
||||
protected function doTree($list, $flatten = true)
|
||||
{
|
||||
$result = ($flatten == true) ? $this->$list : array($this->$list);
|
||||
foreach ($this->_section as $value) {
|
||||
if (is_object($value)) {
|
||||
if ($list == '_script' || $list == '_stylesheet') {
|
||||
$result = array_merge($result, $value->doTree($list, $flatten));
|
||||
} else {
|
||||
$result = array_merge($value->doTree($list, $flatten), $result);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/*abstract*/ public function set($key, $value)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Обработка всех вложенных шаблонов
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
foreach ($this->_section as $key => $value) {
|
||||
$this->set($key, (is_object($value)) ? $value->execute() : $value); // ?
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Установка заголовка шаблона
|
||||
*
|
||||
* @param string $title
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->_title = $title;
|
||||
}
|
||||
|
||||
protected function isNotNull($title)
|
||||
{
|
||||
return $title !== null;
|
||||
}
|
||||
|
||||
function setAlias($alias)
|
||||
{
|
||||
$this->alias = $alias;
|
||||
}
|
||||
|
||||
function addAlias($name, $path)
|
||||
{
|
||||
$this->alias[$name] = $path;
|
||||
$this->set($name, $path);
|
||||
}
|
||||
|
||||
function find_file($pathlist, $file) {
|
||||
foreach($pathlist as $key => $www) {
|
||||
if (file_exists($key . '/' . $file)) {
|
||||
return $www . '/' . $file;
|
||||
}
|
||||
}
|
||||
throw new Exception("file not found: $file");
|
||||
}
|
||||
|
||||
function resolveName($alias, $file) {
|
||||
list($type, $filename) = explode(":", $file, 2);
|
||||
|
||||
// Сделать поиск а не просто замену папки при совпадении имени
|
||||
if (is_array($alias[$type])) {
|
||||
$output = $this->find_file($alias[$type], $filename);
|
||||
} else {
|
||||
$output = $alias[$type] . '/' . $filename;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
function loadImports($importFile)
|
||||
{
|
||||
$types = array(
|
||||
'js' => array($this, 'addScript'),
|
||||
'css' => array($this, 'addStyleSheet')
|
||||
);
|
||||
// Подключение стилей и скриптов
|
||||
if (file_exists($importFile)) {
|
||||
$files = file($importFile);
|
||||
foreach ($files as $file) {
|
||||
// Получить расширение вместо strpos
|
||||
$file = trim($file);
|
||||
if (!empty($file)) {
|
||||
$ext = pathinfo($file, PATHINFO_EXTENSION);
|
||||
call_user_func($types[$ext], $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function resolveAllNames($alias, $list) {
|
||||
$result = array();
|
||||
foreach($list as $item) {
|
||||
$result [] = $this->resolveName($alias, $item);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue