1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-26 03:30:48 +03:00

Fix block templates finding

This commit is contained in:
Alexey Kachayev 2010-01-01 15:31:04 +00:00
parent f01d8c1d38
commit 5c45be5788
4 changed files with 19 additions and 35 deletions

View file

@ -138,7 +138,7 @@ class PluginProfiler_ActionProfiler extends ActionPlugin {
$this->Viewer_Assign('aPaging',$aPaging);
$this->Viewer_Assign('aReports',$aReports);
$this->Viewer_Assign('aDatabaseStat',($aData=$this->PluginProfiler_Profiler_GetDatabaseStat())?$aData:array('max_date'=>'','count'=>''));
$this->Viewer_AddBlock('right',$this->getTemplatePathAction().'/actions/ActionProfiler/sidebar.tpl',array('plugin'=>'profiler'));
$this->Viewer_AddBlock('right',$this->getTemplatePathAction().'/actions/ActionProfiler/sidebar.tpl');
$this->Viewer_AddHtmlTitle($this->Lang_Get('profiler_report_page_title'));
}

View file

@ -28,6 +28,17 @@ abstract class ActionPlugin extends Action {
*/
protected $sTemplatePathAction=null;
/**
* Конструктор
*
* @param Engine $oEngine
* @param string $sAction
*/
public function __construct(Engine $oEngine, $sAction) {
parent::__construct($oEngine, $sAction);
$this->Viewer_Assign('sTemplateActionPath',$this->getTemplatePathAction());
}
public function getTemplatePathAction() {
if(is_null($this->sTemplatePathAction)) {
preg_match('/^Plugin([\w]+)_Action([\w]+)$/i',$this->GetActionClass(),$aMatches);

View file

@ -350,13 +350,7 @@ class LsViewer extends Module {
* @param string $sTemplate
* @return string
*/
public function Fetch($sTemplate,$sPlugin=null) {
/**
* Если указан шаблон плагина, то производим замену ключа [skin_name]
*/
if($sPlugin) {
$sTemplate=$this->ReplacePluginSkinName($sTemplate);
}
public function Fetch($sTemplate) {
return $this->oSmarty->fetch($sTemplate);
}
/**
@ -389,13 +383,13 @@ class LsViewer extends Module {
/**
* Если смогли определить тип блока то добавляем его
*/
$sType=$this->DefineTypeBlock($sName,isset($aParams['plugin'])?$aParams['plugin']:null);
$sType=$this->DefineTypeBlock($sName,isset($aParams['dir'])?$aParams['dir']:null);
if ($sType=='undefined') {
return false;
}
$this->aBlocks[$sGroup][$sName]=array(
'type' => $sType,
'name' => ($sType=='template' and isset($aParams['plugin']))?$this->ReplacePluginSkinName($sName,$aParams['plugin']):$sName,
'name' => $sName,
'params' => $aParams,
'priority' => $iPriority,
);
@ -441,13 +435,13 @@ class LsViewer extends Module {
* @param string $sName
* @return string('block','template','undefined')
*/
protected function DefineTypeBlock($sName,$sPlugin=null) {
if ($this->TemplateExists(($sPlugin)?$this->ReplacePluginSkinName($sPlugin.'/templates/skin/[skin_name]/block'.$sName.'.tpl',$sPlugin):'block.'.$sName.'.tpl')) {
protected function DefineTypeBlock($sName,$sDir=null) {
if ($this->TemplateExists(is_null($sDir)?'block.'.$sName.'.tpl':rtrim($sDir,'/').'/block.'.$sName.'.tpl')) {
/**
* Если найден шаблон вида block.name.tpl то считаем что тип 'block'
*/
return 'block';
} elseif ($this->TemplateExists(($sPlugin)?$this->ReplacePluginSkinName($sName,$sPlugin):$sName)) {
} elseif ($this->TemplateExists($sName)) {
/**
* Если найден шаблон по имени блока то считаем его простым шаблоном
*/
@ -1118,26 +1112,6 @@ class LsViewer extends Module {
);
return $aPaging;
}
/**
* Заменяет [skin_name] в пути к шаблону путем анализа
* наличия текущего скина в директории шаблонов плагина
*
* @param string $sTemplate
* @return string
*/
public function ReplacePluginSkinName($sTemplate,$sPlugin) {
if(substr_count($sTemplate,'[skin_name]')==0) return $sTemplate;
/**
* Проверяем в списке шаблонов
*/
$sReplaceName=in_array(Config::Get('view.skin'),array_map('basename',glob(Config::Get('path.root.server').'/classes/plugins/'.$sPlugin.'/templates/skin/*',GLOB_ONLYDIR)))
? Config::Get('view.skin')
: 'default';
return str_replace('[skin_name]',$sReplaceName,$sTemplate);
}
/**
* Загружаем переменные в шаблон при завершении модуля

View file

@ -35,8 +35,7 @@ function smarty_insert_block($aParams,&$oSmarty) {
if(isset($aParams['params']) and isset($aParams['params']['plugin'])) {
require_once(Config::Get('path.root.server').'/engine/classes/ActionPlugin.class.php');
$sBlockTemplate = $aParams['params']['plugin'].'/plugins/templates/skin/'.ActionPlugin::SKIN_NAME_KEY.'/block.'.$aParams['block'].'.tpl';
$sBlockTemplate = Engine::getInstance()->Viewer_ReplacePluginSkinName($sBlockTemplate,$aParams['params']['plugin']);
$sBlockTemplate = rtrim($aParams['params']['dir'],'/').'/block.'.$aParams['block'].'.tpl';
$sBlockClass = Config::Get('path.root.server').'/classes/plugins/'.$aParams['params']['plugin'].'/blocks/Block'.$sBlock.'.class.php';
$sCmd='$oBlock=new Plugin'.ucfirst($aParams['params']['plugin']).'_Block'.$sBlock.'($aParamsBlock);';
} else {