mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-06-17 07:10:48 +03:00
Упрощение системы работы с делегатами плагинов, правка некоторых методов работы с шаблонами экшенов из плагинов.
This commit is contained in:
parent
dc06c05409
commit
dbc85c87a8
|
@ -221,12 +221,27 @@ abstract class Action extends Object {
|
|||
/**
|
||||
* Получить шаблон
|
||||
* Если шаблон не определен то возвращаем дефолтный шаблон евента: action/{Action}.{event}.tpl
|
||||
* Внимание! По умолчанию, шаблон будет получен без учета делегирования экшена.
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
public function GetTemplate() {
|
||||
if (is_null($this->sActionTemplate)) {
|
||||
$this->sActionTemplate='actions/'.$this->GetActionClass().'/'.$this->sCurrentEvent.'.tpl';
|
||||
$sActionClass=$this->GetActionClass();
|
||||
/**
|
||||
* Если класс не является делегатом плагина, устанавлваем шаблон по умолчанию.
|
||||
* В случае делегирования, проверяем сначала имеет ли указанный плагин замену для шаблона.
|
||||
*/
|
||||
if(!$this->Plugin_isDelegated('action',$sActionClass)) {
|
||||
$this->sActionTemplate='actions/'.$sActionClass.'/'.$this->sCurrentEvent.'.tpl';
|
||||
} else {
|
||||
$sDelegater = $this->Plugin_GetDelegater('action',$sActionClass);
|
||||
$sTemplatePath = Plugin::GetTemplatePath($this->Plugin_GetDelegateSign('action',$sDelegater));
|
||||
|
||||
$this->sActionTemplate = is_file($sFile=$sTemplatePath.'actions/'.$sDelegater.'/'.$this->sCurrentEvent.'.tpl')
|
||||
? $sFile
|
||||
: 'actions/'.$sDelegater.'/'.$this->sCurrentEvent.'.tpl';
|
||||
}
|
||||
}
|
||||
return $this->sActionTemplate;
|
||||
}
|
||||
|
|
|
@ -51,11 +51,20 @@ abstract class ActionPlugin extends Action {
|
|||
* Проверяем в списке шаблонов
|
||||
*/
|
||||
$aMatches[1]=strtolower($aMatches[1]);
|
||||
$sTemplateName=in_array(Config::Get('view.skin'),array_map('basename',glob(Config::Get('path.root.server').'/plugins/'.$aMatches[1].'/templates/skin/*',GLOB_ONLYDIR)))
|
||||
$sTemplateName=in_array(
|
||||
Config::Get('view.skin'),
|
||||
array_map(
|
||||
create_function(
|
||||
'$sPath',
|
||||
'preg_match("/skin\/([\w]+)\/actions/i",$sPath,$aMatches); return $aMatches[1];'
|
||||
),
|
||||
glob(Config::Get('path.root.server').'/plugins/'.$aMatches[1].'/templates/skin/*/actions/Action'.ucfirst($aMatches[2]),GLOB_ONLYDIR)
|
||||
)
|
||||
)
|
||||
? Config::Get('view.skin')
|
||||
: 'default';
|
||||
|
||||
$sDir=Config::Get('path.root.server')."/plugins/{$aMatches[1]}/templates/skin/{$sTemplateName}";
|
||||
$sDir=Config::Get('path.root.server')."/plugins/{$aMatches[1]}/templates/skin/{$sTemplateName}/";
|
||||
$this->sTemplatePathPlugin = is_dir($sDir) ? $sDir : null;
|
||||
}
|
||||
|
||||
|
@ -79,9 +88,13 @@ abstract class ActionPlugin extends Action {
|
|||
* @param string $sTemplate Путь до шаблона относительно каталога шаблонов экшена
|
||||
*/
|
||||
protected function SetTemplateAction($sTemplate) {
|
||||
$this->sActionTemplate=preg_match('/^Plugin([\w]+)_Action([\w]+)$/i',$this->GetActionClass(),$aMatches)
|
||||
? $this->getTemplatePathPlugin().'/actions/Action'.ucfirst($aMatches[2]).'/'.$sTemplate.'.tpl'
|
||||
: null;
|
||||
if($sActionTemplate=preg_match('/^Plugin([\w]+)_Action([\w]+)$/i',$this->GetActionClass(),$aMatches)) {
|
||||
$sTemplatePath = 'actions/Action'.ucfirst($aMatches[2]).'/'.$sTemplate.'.tpl';
|
||||
$sActionTemplate = is_file($sPluginTemplatePath=$this->getTemplatePathPlugin().$sTemplatePath)
|
||||
? $sPluginTemplatePath
|
||||
: $sTemplatePath;
|
||||
}
|
||||
$this->sActionTemplate = $sActionTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,9 +105,7 @@ abstract class ActionPlugin extends Action {
|
|||
*/
|
||||
public function GetTemplate() {
|
||||
if (is_null($this->sActionTemplate)) {
|
||||
$this->sActionTemplate=preg_match('/^Plugin([\w]+)_Action([\w]+)$/i',$this->GetActionClass(),$aMatches)
|
||||
? $this->getTemplatePathPlugin().'/actions/Action'.ucfirst($aMatches[2]).'/'.$this->sCurrentEvent.'.tpl'
|
||||
: null;
|
||||
$this->SetTemplateAction($this->sCurrentEvent);
|
||||
}
|
||||
|
||||
return $this->sActionTemplate;
|
||||
|
|
|
@ -73,6 +73,15 @@ abstract class Plugin extends Object {
|
|||
foreach($aObjects as $sObjectName) {
|
||||
if(is_array($data=$oXml->xpath("delegate/{$sObjectName}/item"))) {
|
||||
foreach($data as $aDelegate) {
|
||||
/**
|
||||
* Если не указан параметр FROM, копируем значение всего ITEM
|
||||
*/
|
||||
if(!$aDelegate->from) $aDelegate->from=$aDelegate;
|
||||
/**
|
||||
* Если не указан делегат TO, считаем, что делегатом является
|
||||
* одноименный объект текущего плагина
|
||||
*/
|
||||
if(!$aDelegate->to) $aDelegate->to = get_class($this).'_'.$aDelegate->from;
|
||||
$this->Plugin_Delegate($sObjectName,$aDelegate->from,$aDelegate->to,get_class($this));
|
||||
}
|
||||
}
|
||||
|
@ -146,7 +155,7 @@ abstract class Plugin extends Object {
|
|||
if(!$bResult) $aErrors[] = mysql_error();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Возвращаем результат выполнения, взависимости от количества ошибок
|
||||
*/
|
||||
|
@ -174,7 +183,7 @@ abstract class Plugin extends Object {
|
|||
? Config::Get('view.skin')
|
||||
: 'default';
|
||||
|
||||
$sDir=Config::Get('path.root.server')."/plugins/{$sName}/templates/skin/{$sTemplateName}";
|
||||
$sDir=Config::Get('path.root.server')."/plugins/{$sName}/templates/skin/{$sTemplateName}/";
|
||||
self::$aTemplatePath[$sName] = is_dir($sDir) ? $sDir : null;
|
||||
}
|
||||
|
||||
|
@ -195,7 +204,7 @@ abstract class Plugin extends Object {
|
|||
? Config::Get('view.skin')
|
||||
: 'default';
|
||||
|
||||
self::$aTemplateWebPath[$sName]=Config::Get('path.root.web')."/plugins/{$sName}/templates/skin/{$sTemplateName}";
|
||||
self::$aTemplateWebPath[$sName]=Config::Get('path.root.web')."/plugins/{$sName}/templates/skin/{$sTemplateName}/";
|
||||
}
|
||||
|
||||
return self::$aTemplateWebPath[$sName];
|
||||
|
|
|
@ -328,9 +328,33 @@ class LsPlugin extends Module {
|
|||
* @return string
|
||||
*/
|
||||
public function GetDelegate($sType,$sFrom) {
|
||||
return $this->isDelegated($sType,$sFrom)?$this->aDelegates[$sType][$sFrom]['delegate']:$sFrom;
|
||||
return $this->isDelegater($sType,$sFrom)?$this->aDelegates[$sType][$sFrom]['delegate']:$sFrom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает делегирующий объект по имени делегата
|
||||
*
|
||||
* @param string $sType Объект
|
||||
* @param string $sTo Делегат
|
||||
* @return string
|
||||
*/
|
||||
public function GetDelegater($sType,$sTo) {
|
||||
/**
|
||||
* Фильтруем меппер делегатов
|
||||
* @var array
|
||||
*/
|
||||
$aDelegateMapper=array_filter(
|
||||
$this->aDelegates[$sType],
|
||||
create_function('$item','return $item["delegate"]=="'.$sTo.'";')
|
||||
);
|
||||
if(!is_array($aDelegateMapper) and !count($aDelegateMapper)) return $sTo;
|
||||
|
||||
/**
|
||||
* Получаем ключ первого элемента массива (это название делегирующего экшена)
|
||||
*/
|
||||
return array_shift(array_keys($aDelegateMapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает подпись делегата модуля, экшена, сущности.
|
||||
*
|
||||
|
@ -339,21 +363,41 @@ class LsPlugin extends Module {
|
|||
* @return string|null
|
||||
*/
|
||||
public function GetDelegateSign($sType,$sFrom) {
|
||||
return $this->isDelegated($sType,$sFrom)?$this->aDelegates[$sType][$sFrom]['sign']:null;
|
||||
return $this->isDelegater($sType,$sFrom)?$this->aDelegates[$sType][$sFrom]['sign']:null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает true, если установлено правило делегирования
|
||||
* Возвращает true, если установлено правило делегирования
|
||||
* и класс является базовым в данном правиле
|
||||
*
|
||||
* @param string $sType
|
||||
* @param string $sFrom
|
||||
* @return bool
|
||||
*/
|
||||
public function isDelegated($sType,$sFrom) {
|
||||
public function isDelegater($sType,$sFrom) {
|
||||
if(!in_array($sType,array_keys($this->aDelegates)) or !$sFrom) return false;
|
||||
return isset($this->aDelegates[$sType][$sFrom]['delegate']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает true, если устано
|
||||
*
|
||||
* @param string $sType
|
||||
* @param string $sTo
|
||||
* @return bool
|
||||
*/
|
||||
public function isDelegated($sType,$sTo) {
|
||||
/**
|
||||
* Фильтруем меппер делегатов
|
||||
* @var array
|
||||
*/
|
||||
$aDelegateMapper=array_filter(
|
||||
$this->aDelegates[$sType],
|
||||
create_function('$item','return $item["delegate"]=="'.$sTo.'";')
|
||||
);
|
||||
return (is_array($aDelegateMapper) and count($aDelegateMapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает список объектов, доступных для делегирования
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue