1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-02 12:48:26 +02:00

Issue #2678 - Fix merging of theme plugin template when a key is provided.

This commit is contained in:
Cameron
2018-01-18 16:19:40 -08:00
parent fb7e9668e7
commit 3b5b64195e
3 changed files with 30 additions and 16 deletions

View File

@@ -2743,7 +2743,7 @@ class e107
$path = self::coreTemplatePath($id, $override); $path = self::coreTemplatePath($id, $override);
$id = str_replace('/', '_', $id); $id = str_replace('/', '_', $id);
$ret = self::_getTemplate($id, $key, $reg_path, $path, $info); $ret = self::_getTemplate($id, $key, $reg_path, $path, $info);
### Attempt to fix merge issues; in case we override - template array not found in theme, ### Attempt to fix merge issues; in case we override - template array not found in theme,
### so we need to continue and merge with core templates ### so we need to continue and merge with core templates
if($merge && $override && empty($ret)) if($merge && $override && empty($ret))
@@ -2751,7 +2751,7 @@ class e107
$ret = array(); $ret = array();
} }
if((!$merge && !$override) || is_string($ret)) if((!$merge && !$override) || is_string($ret))
{ {
return $ret; return $ret;
} }
@@ -2762,7 +2762,7 @@ class e107
$id = str_replace('/', '_', $id); $id = str_replace('/', '_', $id);
// Introducing noWrapper when merging // Introducing noWrapper when merging
$ret_core = self::_getTemplate($id, $key, $reg_path, $path, $info, true); $ret_core = self::_getTemplate($id, $key, $reg_path, $path, $info, true);
return (is_array($ret_core) ? array_merge($ret_core, $ret) : $ret); return (is_array($ret_core) ? array_merge($ret_core, $ret) : $ret);
} }
@@ -2812,22 +2812,30 @@ class e107
$id = str_replace('/', '_', $id); $id = str_replace('/', '_', $id);
$ret = self::_getTemplate($id, $key, $reg_path, $path, $info); $ret = self::_getTemplate($id, $key, $reg_path, $path, $info);
if(!$merge || !$override || !is_array($ret))
if($merge === false || $override === false)
{ {
return $ret; return ($ret === false) ? '' : $ret;
} }
// merge // merge
$reg_path = 'plugin/'.$plug_name.'/templates/'.$id; $reg_path = 'plugin/'.$plug_name.'/templates/'.$id;
$path = self::templatePath($plug_name, $id, false); $path = self::templatePath($plug_name, $id, false);
$id = str_replace('/', '_', $id); $id = str_replace('/', '_', $id);
// Introduced noWrapper when merging // Introduced noWrapper when merging
$ret_plug = self::_getTemplate($id, $key, $reg_path, $path, $info, true); $ret_plug = self::_getTemplate($id, $key, $reg_path, $path, $info, true);
if($merge === true && $key !== null && $ret === false) // key not set, so send 'core' version instead.
{
return $ret_plug;
}
if($ret === false)
{
return '';
}
return (is_array($ret_plug) ? array_merge($ret_plug, $ret) : $ret); return (is_array($ret_plug) ? array_merge($ret_plug, $ret) : $ret);
} }
@@ -3041,12 +3049,13 @@ class e107
} }
$ret = (!$info ? self::getRegistry($regPath) : self::getRegistry($regPathInfo)); $ret = (!$info ? self::getRegistry($regPath) : self::getRegistry($regPathInfo));
if(!$key) if(!$key)
{ {
return $ret; return $ret;
} }
return ($ret && is_array($ret) && isset($ret[$key]) ? $ret[$key] : ''); return ($ret && is_array($ret) && isset($ret[$key]) ? $ret[$key] : false);
} }
/** /**

View File

@@ -29,7 +29,12 @@ foreach($tmp as $id => $val)
// e107::getDebug()->log($val); // e107::getDebug()->log($val);
} }
$template = e107::getTemplate('news', 'news_menu', 'archive'); $template = e107::getTemplate('news', 'news_menu', 'archive',true, true);
if(ADMIN && empty($template))
{
$text = "Missing Template. Check that your theme's news_menu_template.php file contains an 'archive' template. ";
}
foreach($arr as $year=>$val) foreach($arr as $year=>$val)
{ {
@@ -80,10 +85,10 @@ foreach($arr as $year=>$val)
foreach($items as $row) foreach($items as $row)
{ {
$url = e107::getUrl()->create('news/view/item', $row, array('allow' => 'news_sef,news_title,news_id,category_sef,category_name,category_id')); $url = e107::getUrl()->create('news/view/item', $row, array('allow' => 'news_sef,news_title,news_id,category_sef,category_name,category_id'));
$var = array('ITEM_URL' => $url, $var = array('ITEM_URL' => $url,
'ITEM_TITLE' => $tp->toHtml($row['news_title'],false,'TITLE'), 'ITEM_TITLE' => $tp->toHtml($row['news_title'],false,'TITLE'),
); );
$text .= $tp->simpleParse($template['item'], $var); $text .= $tp->simpleParse($template['item'], $var);
} }
$text .= $template['month_end']; $text .= $template['month_end'];
} }

View File

@@ -137,7 +137,7 @@ $NEWS_MENU_TEMPLATE['archive']['year_start'] = "<li>
$NEWS_MENU_TEMPLATE['archive']['year_end'] = '</ul></li>'; $NEWS_MENU_TEMPLATE['archive']['year_end'] = '</ul></li>';
$NEWS_MENU_TEMPLATE['archive']['month_start'] = "<li> $NEWS_MENU_TEMPLATE['archive']['month_start'] = "<li>
<a class='e-expandit' href='#{MONTH_ID}'>{MONTH_NAME}<span class='badge'>{MONTH_COUNT}</span></a> <a class='e-expandit' href='#{MONTH_ID}'>{MONTH_NAME}</a>
<ul id='{MONTH_ID}' class='news-archive-menu-items' style='display:none'> <ul id='{MONTH_ID}' class='news-archive-menu-items' style='display:none'>
"; ";
$NEWS_MENU_TEMPLATE['archive']['month_end'] = '</ul></li>'; $NEWS_MENU_TEMPLATE['archive']['month_end'] = '</ul></li>';