Skip to content

Commit

Permalink
Core: multiple .pre and .post tpls applying fix in AView and Extensio…
Browse files Browse the repository at this point in the history
…ns classes
  • Loading branch information
abolabo committed Nov 12, 2015
1 parent eecb276 commit 0ffc3cf
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 6 deletions.
67 changes: 65 additions & 2 deletions public_html/core/engine/extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,8 @@ public function loadEnabledExtensions($force_enabled_off = false) {
&& has_value($ext)
) {

$priority = (int)$registry->get('config')->get($ext . '_priority');
// run order is sort_order!
$priority = (int)$registry->get('config')->get($ext . '_sort_order');
$enabled_extensions[$priority][] = $ext;

$controllers = $languages = $models = $templates = array(
Expand All @@ -613,6 +614,7 @@ public function loadEnabledExtensions($force_enabled_off = false) {

$this->setExtensionCollection(new ExtensionCollection($extensions));
$this->enabled_extensions = array();
//sort extensions list by sort_order by ascending (sort_order)
ksort($enabled_extensions);
foreach($enabled_extensions as $exts){
$this->enabled_extensions = array_merge($this->enabled_extensions,$exts);
Expand Down Expand Up @@ -714,7 +716,13 @@ public function isExtensionResource($resource_type, $route, $ext_status = '', $m
$extensions_lookup_list = $this->enabled_extensions;
} else if ( $ext_status == 'all' ) {
$extensions_lookup_list = $this->extensions_dir;
}
}

//reverse $extensions_lookup_list when looking for tpl
// need to take last from the list
if ($resource_type == 'T') {
$extensions_lookup_list = array_reverse($extensions_lookup_list);
}

foreach ($extensions_lookup_list as $ext) {
$f = DIR_EXT . $ext . $file;
Expand Down Expand Up @@ -755,6 +763,58 @@ public function isExtensionResource($resource_type, $route, $ext_status = '', $m
return false;
}

/**
* Function returns all tpl with pre or post prefixes for all enabled extensions
* @param string $route - relative path of file.
* @return array|bool
*/
public function getAllPrePostTemplates($route){

$registry = Registry::getInstance();
if (!$registry->has('config')) return false;

$ext_section = (IS_ADMIN ? DIR_EXT_ADMIN : DIR_EXT_STORE);

$tmpl_id = IS_ADMIN ? $registry->get('config')->get('admin_template')
: $registry->get('config')->get('config_storefront_template');
$file = $ext_section . DIR_EXT_TEMPLATE . $tmpl_id . '/template/' . $route;
$source = $this->extension_templates;


$section = trim($ext_section, '/');

//list only enabled extensions
$extensions_lookup_list = $this->enabled_extensions;
$output = array();
foreach ($extensions_lookup_list as $ext) {
//looking for active template tpl
$f = DIR_EXT . $ext . $file;
if ( in_array($route, $source[$ext][$section]) ) {
if (is_file($f)) {
$output[$ext] = array(
'file' => $f,
'extension' => $ext,
'base_path' => $file
);
}
//if active template tpl not found - looking for default
if(!isset($output[$ext])){
//check default template
$f = DIR_EXT . $ext . $ext_section . DIR_EXT_TEMPLATE . 'default/template/' . $route;
if (is_file($f)){
$output[] = array (
'file' => $f,
'extension' => $ext,
'base_path' => $ext_section . DIR_EXT_TEMPLATE . 'default/template/' . $route
);
}
}
}
}

return $output;
}

/**
* check if route is an extension controller (only enabled extensions can be checked)
*
Expand Down Expand Up @@ -1185,6 +1245,9 @@ public function getDefaultSettings() {
$value = (string)$item->resource_type . '/' . $resource_info['resource_path'];
}
$result[(string)$item['id']] = $value;
if((string)$item['id']=='priority'){
$result['sort_order'] = $value;
}
}
}

Expand Down
12 changes: 8 additions & 4 deletions public_html/core/engine/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,19 @@ public function fetch($filename) {
if (is_file($file)) {
$content = '';
$file_pre = str_replace('.tpl', POSTFIX_PRE.'.tpl', $filename );
if ( $result = $this->extensions->isExtensionResource('T', $file_pre) ) {
$content .= $this->_fetch($result['file']);
if ( $result = $this->extensions->getAllPrePostTemplates($file_pre) ) {
foreach($result as $item){
$content .= $this->_fetch($item['file']);
}
}

$content .= $this->_fetch($file);

$file_post = str_replace('.tpl', POSTFIX_POST.'.tpl', $filename );
if ( $result = $this->extensions->isExtensionResource('T', $file_post) ) {
$content .= $this->_fetch($result['file']);
if ( $result = $this->extensions->getAllPrePostTemplates( $file_post) ) {
foreach($result as $item){
$content .= $this->_fetch($item['file']);
}
}
ADebug::checkpoint('fetch '.$filename.' end');
return $content;
Expand Down

0 comments on commit 0ffc3cf

Please sign in to comment.