Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Exclude plugin uuid from template function name #90

Open
wants to merge 3 commits into
base: 1.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/Dwoo/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,11 @@ public function getUsedPlugins()
* @param string $uuid unique id of the function
* @param string $body function php code
*/
public function addTemplatePlugin($name, array $params, $uuid, $body = null)
public function addTemplatePlugin($name, array $params, $uuid, $body = null, Dwoo_ITemplate $sourceTpl = null)
{
$this->templatePlugins[$name] = array('params' => $params, 'body' => $body, 'uuid' => $uuid);
if (!array_key_exists($name, $this->templatePlugins) || $this->templatePlugins[$name]['uuid'] == $uuid) {
$this->templatePlugins[$name] = array('params'=> $params, 'body' => $body, 'uuid' => $uuid, 'sourceTpl' => $sourceTpl);
}
}

/**
Expand Down Expand Up @@ -2031,7 +2033,7 @@ protected function parseFunction($in, $from, $to, $parsingParams = false, $curBl
} elseif ($pluginType & Dwoo_Core::TEMPLATE_PLUGIN) {
array_unshift($params, '$this');
$params = self::implode_r($params);
$output = 'Dwoo_Plugin_'.$func.'_'.$this->templatePlugins[$func]['uuid'].'('.$params.')';
$output = 'Dwoo_Plugin_'.$func.'('.$params.')';
$this->templatePlugins[$func]['called'] = true;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Dwoo/Template/String.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ public function getCompiledTemplate(Dwoo_Core $dwoo, Dwoo_ICompiler $compiler =

if (extension_loaded('Zend OPcache')) {
opcache_invalidate($compiledFile);
} elseif (extension_loaded('apc') && ini_get('apc.enabled')) {
apc_delete_file($compiledFile);
} elseif (function_exists('apc_compile_file')) {
apc_compile_file($compiledFile);
}

self::$cache['compiled'][$this->compileId] = true;
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/builtin/blocks/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function postProcessing(Dwoo_Compiler $compiler, array $params, $p
}
$init .= '/* -- template start output */';

$funcName = 'Dwoo_Plugin_'.$params['name'].'_'.$params['uuid'];
$funcName = 'Dwoo_Plugin_'.$params['name'];

$search = array(
'$this->charset',
Expand Down
42 changes: 29 additions & 13 deletions lib/plugins/builtin/functions/load_templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,46 @@ function Dwoo_Plugin_load_templates_compile(Dwoo_Compiler $compiler, $file)

$cmp = clone $compiler;
$cmp->compile($compiler->getDwoo(), $tpl);
foreach ($cmp->getTemplatePlugins() as $template => $args) {
$compiler->addTemplatePlugin($template, $args['params'], $args['uuid'], $args['body']);
$usedTemplates = array($tpl);
foreach ($cmp->getTemplatePlugins() as $template=>$args) {
if (isset($args['sourceTpl'])) {
$sourceTpl = $args['sourceTpl'];
} else {
$sourceTpl = $tpl;
}

$compiler->addTemplatePlugin($template, $args['params'], $args['uuid'], $args['body'], $sourceTpl);

if (!in_array($sourceTpl, $usedTemplates, true)) {
$usedTemplates[] = $sourceTpl;
}
}
foreach ($cmp->getUsedPlugins() as $plugin => $type) {
foreach ($cmp->getUsedPlugins() as $plugin=>$type) {
$compiler->addUsedPlugin($plugin, $type);
}

$out = '\'\';// checking for modification in '.$resource.':'.$identifier."\r\n";

$modCheck = $tpl->getIsModifiedCode();
foreach ($usedTemplates AS $usedTemplate) {
$modCheck = $usedTemplate->getIsModifiedCode();

if ($modCheck) {
$out .= 'if (!('.$modCheck.')) { ob_end_clean(); return false; }';
} else {
$out .= 'try {
$tpl = $this->templateFactory("'.$resource.'", "'.$identifier.'");
if ($modCheck) {
$out .= 'if (!('.$modCheck.')) { ob_end_clean(); return false; }';
} else {
$usedTemplateResourceName = $usedTemplate->getResourceName();
$usedTemplateResourceIdentifier = $usedTemplate->getResourceIdentifier();
$out .= '
try {
$tpl = $this->templateFactory("'.$usedTemplateResourceName.'", "'.$usedTemplateResourceIdentifier.'");
} catch (Dwoo_Exception $e) {
$this->triggerError(\'Load Templates : Resource <em>'.$resource.'</em> was not added to Dwoo, can not extend <em>'.$identifier.'</em>\', E_USER_WARNING);
$this->triggerError(\'Load Templates : Resource <em>'.$usedTemplateResourceName.'</em> was not added to Dwoo, can not extend <em>'.$usedTemplateResourceIdentifier.'</em>\', E_USER_WARNING);
}
if ($tpl === null)
$this->triggerError(\'Load Templates : Resource "'.$resource.':'.$identifier.'" was not found.\', E_USER_WARNING);
$this->triggerError(\'Load Templates : Resource "'.$usedTemplateResourceName.':'.$usedTemplateResourceIdentifier.'" was not found.\', E_USER_WARNING);
elseif ($tpl === false)
$this->triggerError(\'Load Templates : Resource "'.$resource.'" does not support extends.\', E_USER_WARNING);
if ($tpl->getUid() != "'.$tpl->getUid().'") { ob_end_clean(); return false; }';
$this->triggerError(\'Load Templates : Resource "'.$usedTemplateResourceName.'" does not support extends.\', E_USER_WARNING);
if ($tpl->getUid() != "'.$usedTemplate->getUid().'") { ob_end_clean(); return false; }';
}
}

return $out;
Expand Down