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

Возможность создавать хуки внутри шаблонов

This commit is contained in:
Mzhelskiy Maxim 2010-04-18 12:42:42 +00:00
parent 932d0ef733
commit be2fe70c70
6 changed files with 52 additions and 5 deletions

View file

@ -80,6 +80,7 @@ class LsHook extends Module {
public function Run($sName,&$aVars=array()) {
$result=array();
$sName=strtolower($sName);
$bTemplateHook=strpos($sName,'template_')===0 ? true : false;
if (isset($this->aHooks[$sName])) {
$aHookNum=array();
$aHookNumDelegate=array();
@ -100,7 +101,14 @@ class LsHook extends Module {
*/
foreach ($aHookNum as $iKey => $iPr) {
$aHook=$this->aHooks[$sName][$iKey];
$this->RunType($aHook,$aVars);
if ($bTemplateHook) {
/**
* Если это шаблонных хук то сохраняем результат
*/
$result['template_result'][]=$this->RunType($aHook,$aVars);
} else {
$this->RunType($aHook,$aVars);
}
}
/**
* Теперь запускаем делигирующие

View file

@ -0,0 +1,39 @@
<?php
/*-------------------------------------------------------
*
* LiveStreet Engine Social Networking
* Copyright © 2008 Mzhelskiy Maxim
*
*--------------------------------------------------------
*
* Official site: www.livestreet.ru
* Contact e-mail: rus.engine@gmail.com
*
* GNU General Public License, version 2:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
---------------------------------------------------------
*/
/**
* Плагин для смарти
* Запускает хуки из шаблона на выполнение
*
* @param array $aParams
* @param Smarty $oSmarty
* @return string
*/
function smarty_function_hook($aParams,&$oSmarty) {
if(empty($aParams['run'])) {
$oSmarty->trigger_error("Hook: missing 'run' parametr");
return;
}
$sHookName='template_'.strtolower($aParams['run']);
$aResultHook=Engine::getInstance()->Hook_Run($sHookName);
if (array_key_exists('template_result',$aResultHook)) {
return join('',$aResultHook['template_result']);
}
return '';
}
?>

View file

@ -1,4 +1,4 @@
</div>
{hook run='body_end'}
</body>
</html>

View file

@ -17,6 +17,6 @@
<!-- /Footer -->
</div>
{hook run='body_end'}
</body>
</html>

View file

@ -15,7 +15,7 @@
</head>
<body>
{hook run='body_begin'}
<div id="container">
<h1 class="lite-header"><a href="{cfg name='path.root.web'}">Live<span>Street</span></a></h1>

View file

@ -76,7 +76,7 @@ var msgNoticeBox=new Roar({
<body onload="prettyPrint()">
{hook run='body_begin'}
<div id="debug" style="border: 2px #dd0000 solid; display: none;"></div>