Improved the layout compiler methods.

This commit is contained in:
Llewellyn van der Merwe 2020-12-31 13:18:52 +02:00
parent d29bc8f3a0
commit 75fa49e517
Signed by untrusted user: Llewellyn
GPG Key ID: EFC0C720A240551C
7 changed files with 529 additions and 195 deletions

View File

@ -143,7 +143,7 @@ TODO
+ *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 27th December, 2020 + *Last Build*: 31st December, 2020
+ *Version*: 2.12.4 + *Version*: 2.12.4
+ *Copyright*: Copyright (C) 2015 - 2021 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 - 2021 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt

View File

@ -143,7 +143,7 @@ TODO
+ *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com) + *Author*: [Llewellyn van der Merwe](mailto:llewellyn@joomlacomponentbuilder.com)
+ *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder) + *Name*: [Component Builder](https://github.com/vdm-io/Joomla-Component-Builder)
+ *First Build*: 30th April, 2015 + *First Build*: 30th April, 2015
+ *Last Build*: 27th December, 2020 + *Last Build*: 31st December, 2020
+ *Version*: 2.12.4 + *Version*: 2.12.4
+ *Copyright*: Copyright (C) 2015 - 2021 Vast Development Method. All rights reserved. + *Copyright*: Copyright (C) 2015 - 2021 Vast Development Method. All rights reserved.
+ *License*: GNU General Public License version 2 or later; see LICENSE.txt + *License*: GNU General Public License version 2 or later; see LICENSE.txt

View File

@ -0,0 +1,20 @@
<?php
/**
* @package Joomla.Component.Builder
*
* @created 30th April, 2015
* @author Llewellyn van der Merwe <http://www.joomlacomponentbuilder.com>
* @github Joomla Component Builder <https://github.com/vdm-io/Joomla-Component-Builder>
* @copyright Copyright (C) 2015 - 2018 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
?>
###BOM###
// No direct access to this file
defined('JPATH_BASE') or die('Restricted access');###OVERRIDE_LAYOUT_CODE###
?>###OVERRIDE_LAYOUT_BODY###

View File

@ -386,6 +386,11 @@
"rename": "layout_admin", "rename": "layout_admin",
"type": "layout" "type": "layout"
}, },
"layoutoverride.php": {
"path": "c0mp0n3nt/admin/layouts/VIEW",
"rename": "layoutoverride",
"type": "layoutoverride"
},
"layoutitems.php": { "layoutitems.php": {
"path": "c0mp0n3nt/admin/layouts/VIEW", "path": "c0mp0n3nt/admin/layouts/VIEW",
"rename": "layoutitems", "rename": "layoutitems",
@ -576,6 +581,11 @@
"rename": "layout_site", "rename": "layout_site",
"type": "layout" "type": "layout"
}, },
"layoutoverride.php": {
"path": "c0mp0n3nt/site/layouts/VIEW",
"rename": "layoutoverride",
"type": "layoutoverride"
},
"layoutitems.php": { "layoutitems.php": {
"path": "c0mp0n3nt/site/layouts/VIEW", "path": "c0mp0n3nt/site/layouts/VIEW",
"rename": "layoutitems", "rename": "layoutitems",

View File

@ -787,6 +787,13 @@ class Get
*/ */
public $updateSQL = array(); public $updateSQL = array();
/**
* The data by alias keys
*
* @var array
*/
protected $dataWithAliasKeys = array();
/** /**
* The Library Manager * The Library Manager
* *
@ -5788,41 +5795,49 @@ class Get
/** /**
* Set Template and Layout Data * Set Template and Layout Data
* *
* @param string $default The content to check * @param string $default The content to check
* @param string $view The view code name * @param string $view The view code name
* @param boolean $found The proof that something was found * @param boolean $found The proof that something was found
* @param array $templates The option to pass templates keys (to avoid search)
* @param array $layouts The option to pass layout keys (to avoid search)
* *
* @return boolean if something was found true * @return boolean if something was found true
* *
*/ */
public function setTemplateAndLayoutData($default, $view, $found = false) public function setTemplateAndLayoutData($default, $view, $found = false,
{ $templates = array(), $layouts = array()
// set the Template data ) {
$temp1 = ComponentbuilderHelper::getAllBetween( // to check inside the templates
$default, "\$this->loadTemplate('", "')" $again = array();
); // check if template keys were passed
$temp2 = ComponentbuilderHelper::getAllBetween( if (!ComponentbuilderHelper::checkArray($templates))
$default, '$this->loadTemplate("', '")'
);
$templates = array();
$again = array();
if (ComponentbuilderHelper::checkArray($temp1)
&& ComponentbuilderHelper::checkArray($temp2))
{ {
$templates = array_merge($temp1, $temp2); // set the Template data
} $temp1 = ComponentbuilderHelper::getAllBetween(
else $default, "\$this->loadTemplate('", "')"
{ );
if (ComponentbuilderHelper::checkArray($temp1)) $temp2 = ComponentbuilderHelper::getAllBetween(
$default, '$this->loadTemplate("', '")'
);
if (ComponentbuilderHelper::checkArray($temp1)
&& ComponentbuilderHelper::checkArray($temp2))
{ {
$templates = $temp1; $templates = array_merge($temp1, $temp2);
} }
elseif (ComponentbuilderHelper::checkArray($temp2)) else
{ {
$templates = $temp2; if (ComponentbuilderHelper::checkArray($temp1))
{
$templates = $temp1;
}
elseif (ComponentbuilderHelper::checkArray($temp2))
{
$templates = $temp2;
}
} }
} }
if (ComponentbuilderHelper::checkArray($templates)) // check if we found templates
if (ComponentbuilderHelper::checkArray($templates, true))
{ {
foreach ($templates as $template) foreach ($templates as $template)
{ {
@ -5845,38 +5860,50 @@ class Get
} }
} }
// check if we have the template set (and nothing yet found) // check if we have the template set (and nothing yet found)
if (!$found && isset($this->templateData[$this->target][$view][$template])) if (!$found
&& isset($this->templateData[$this->target][$view][$template]))
{ {
// something was found // something was found
$found = true; $found = true;
} }
} }
} }
// set the Layout data // check if layout keys were passed
$lay1 = ComponentbuilderHelper::getAllBetween( if (!ComponentbuilderHelper::checkArray($layouts))
$default, "JLayoutHelper::render('", "',"
);
$lay2 = ComponentbuilderHelper::getAllBetween(
$default, 'JLayoutHelper::render("', '",'
);;
if (ComponentbuilderHelper::checkArray($lay1)
&& ComponentbuilderHelper::checkArray($lay2))
{ {
$layouts = array_merge($lay1, $lay2); // set the Layout data
} $lay1 = ComponentbuilderHelper::getAllBetween(
else $default, "JLayoutHelper::render('", "',"
{ );
if (ComponentbuilderHelper::checkArray($lay1)) $lay2 = ComponentbuilderHelper::getAllBetween(
$default, 'JLayoutHelper::render("', '",'
);
if (ComponentbuilderHelper::checkArray($lay1)
&& ComponentbuilderHelper::checkArray($lay2))
{ {
$layouts = $lay1; $layouts = array_merge($lay1, $lay2);
} }
elseif (ComponentbuilderHelper::checkArray($lay2)) else
{ {
$layouts = $lay2; if (ComponentbuilderHelper::checkArray($lay1))
{
$layouts = $lay1;
}
elseif (ComponentbuilderHelper::checkArray($lay2))
{
$layouts = $lay2;
}
} }
} }
if (isset($layouts) && ComponentbuilderHelper::checkArray($layouts)) // check if we found layouts
if (ComponentbuilderHelper::checkArray($layouts, true))
{ {
// get the other target if both
$_target = null;
if ($this->lang === 'both')
{
$_target = ($this->target === 'admin') ? 'site' : 'admin';
}
foreach ($layouts as $layout) foreach ($layouts as $layout)
{ {
if (!isset($this->layoutData[$this->target]) if (!isset($this->layoutData[$this->target])
@ -5892,6 +5919,11 @@ class Get
{ {
// load it to the layout data array // load it to the layout data array
$this->layoutData[$this->target][$layout] = $data; $this->layoutData[$this->target][$layout] = $data;
// check if other target is set
if ($this->lang === 'both' && $_target)
{
$this->layoutData[$_target][$layout] = $data;
}
// call self to get child data // call self to get child data
$again[] = array($data['html'], $view); $again[] = array($data['html'], $view);
$again[] = array($data['php_view'], $view); $again[] = array($data['php_view'], $view);
@ -5905,13 +5937,17 @@ class Get
} }
} }
} }
// check again
if (ComponentbuilderHelper::checkArray($again)) if (ComponentbuilderHelper::checkArray($again))
{ {
foreach ($again as $go) foreach ($again as $go)
{ {
$found = $this->setTemplateAndLayoutData($go[0], $go[1], $found); $found = $this->setTemplateAndLayoutData(
$go[0], $go[1], $found
);
} }
} }
// return the proof that something was found // return the proof that something was found
return $found; return $found;
} }
@ -5928,157 +5964,215 @@ class Get
*/ */
protected function getDataWithAlias($n_ame, $table, $view) protected function getDataWithAlias($n_ame, $table, $view)
{ {
// if not set, get all keys in table and set by ID
$this->setDataWithAliasKeys($table);
// now check if key is found
$name = preg_replace("/[^A-Za-z]/", '', $n_ame);
if (isset($this->dataWithAliasKeys[$table][$name]))
{
$ID = $this->dataWithAliasKeys[$table][$name];
}
elseif (isset($this->dataWithAliasKeys[$table][$n_ame]))
{
$ID = $this->dataWithAliasKeys[$table][$n_ame];
}
else
{
return false;
}
// Create a new query object. // Create a new query object.
$query = $this->db->getQuery(true); $query = $this->db->getQuery(true);
$query->select('a.*'); $query->select('a.*');
$query->from('#__componentbuilder_' . $table . ' AS a'); $query->from('#__componentbuilder_' . $table . ' AS a');
$this->db->setQuery($query); $query->where(
$rows = $this->db->loadObjectList(); $this->db->quoteName('a.id') . ' = ' . (int) $ID
foreach ($rows as $row) );
// get the other target if both
$_targets = array($this->target);
if ($this->lang === 'both')
{ {
$k_ey = ComponentbuilderHelper::safeString($row->alias); $_targets = array('site', 'admin');
$key = preg_replace("/[^A-Za-z]/", '', $k_ey); }
$name = preg_replace("/[^A-Za-z]/", '', $n_ame); $this->db->setQuery($query);
if ($k_ey == $n_ame || $key == $name) // get the row
$row = $this->db->loadObject();
// we load this layout
$php_view = '';
if ($row->add_php_view == 1
&& ComponentbuilderHelper::checkString($row->php_view))
{
$php_view = $this->setGuiCodePlaceholder(
$this->setDynamicValues(base64_decode($row->php_view)),
array(
'table' => $table,
'field' => 'php_view',
'id' => (int) $row->id,
'type' => 'php')
);
}
$contnent = $this->setGuiCodePlaceholder(
$this->setDynamicValues(base64_decode($row->{$table})),
array(
'table' => $table,
'field' => $table,
'id' => (int) $row->id,
'type' => 'html')
);
// load all targets
foreach ($_targets as $_target)
{
// load the library
if (!isset($this->libManager[$_target]))
{ {
$php_view = ''; $this->libManager[$_target] = array();
if ($row->add_php_view == 1 }
&& ComponentbuilderHelper::checkString($row->php_view)) if (!isset($this->libManager[$_target][$view]))
{
$this->libManager[$_target][$view] = array();
}
// make sure json become array
if (ComponentbuilderHelper::checkJson($row->libraries))
{
$row->libraries = json_decode($row->libraries, true);
}
// if we have an array add it
if (ComponentbuilderHelper::checkArray($row->libraries))
{
foreach ($row->libraries as $library)
{ {
$php_view = $this->setGuiCodePlaceholder( if (!isset($this->libManager[$_target][$view][$library]))
$this->setDynamicValues(base64_decode($row->php_view)),
array(
'table' => $table,
'field' => 'php_view',
'id' => (int) $row->id,
'type' => 'php')
);
}
$contnent = $this->setGuiCodePlaceholder(
$this->setDynamicValues(base64_decode($row->{$table})),
array(
'table' => $table,
'field' => $table,
'id' => (int) $row->id,
'type' => 'html')
);
// load the library
if (!isset($this->libManager[$this->target]))
{
$this->libManager[$this->target] = array();
}
if (!isset($this->libManager[$this->target][$view]))
{
$this->libManager[$this->target][$view] = array();
}
// make sure json become array
if (ComponentbuilderHelper::checkJson($row->libraries))
{
$row->libraries = json_decode($row->libraries, true);
}
// if we have an array add it
if (ComponentbuilderHelper::checkArray($row->libraries))
{
foreach ($row->libraries as $library)
{ {
if (!isset($this->libManager[$this->target][$view][$library])) if ($this->getMediaLibrary((int) $library))
{ {
if ($this->getMediaLibrary((int) $library)) $this->libManager[$_target][$view][(int) $library]
{ = true;
$this->libManager[$this->target][$view][(int) $library]
= true;
}
} }
} }
} }
elseif (is_numeric($row->libraries) }
&& !isset($this->libManager[$this->target][$view][(int) $row->libraries])) elseif (is_numeric($row->libraries)
&& !isset($this->libManager[$_target][$view][(int) $row->libraries]))
{
if ($this->getMediaLibrary((int) $row->libraries))
{ {
if ($this->getMediaLibrary((int) $row->libraries)) $this->libManager[$_target][$view][(int) $row->libraries]
{ = true;
$this->libManager[$this->target][$view][(int) $row->libraries]
= true;
}
} }
// load UIKIT if needed }
if (2 == $this->uikit || 1 == $this->uikit) // set footable to views and turn it on
if (!isset($this->footableScripts[$_target][$view])
|| !$this->footableScripts[$_target][$view])
{
$foundFoo = $this->getFootableScripts($contnent);
if ($foundFoo)
{ {
if (!isset($this->uikitComp[$view])) $this->footableScripts[$_target][$view] = true;
{
$this->uikitComp[$view] = array();
}
// set uikit to views
$this->uikitComp[$view]
= ComponentbuilderHelper::getUikitComp(
$contnent, $this->uikitComp[$view]
);
} }
// set footable to views and turn it on if ($foundFoo && !$this->footable)
if (!isset($this->footableScripts[$this->target][$view])
|| !$this->footableScripts[$this->target][$view])
{ {
$foundFoo = $this->getFootableScripts($contnent); $this->footable = true;
if ($foundFoo)
{
$this->footableScripts[$this->target][$view] = true;
}
if ($foundFoo && !$this->footable)
{
$this->footable = true;
}
} }
// set google charts to views and turn it on }
if (!isset($this->googleChart[$this->target][$view]) // set google charts to views and turn it on
|| !$this->googleChart[$this->target][$view]) if (!isset($this->googleChart[$_target][$view])
|| !$this->googleChart[$_target][$view])
{
$foundA = $this->getGoogleChart($php_view);
$foundB = $this->getGoogleChart($contnent);
if ($foundA || $foundB)
{ {
$foundA = $this->getGoogleChart($php_view); $this->googleChart[$_target][$view] = true;
$foundB = $this->getGoogleChart($contnent);
if ($foundA || $foundB)
{
$this->googleChart[$this->target][$view] = true;
}
if ($foundA || $foundB && !$this->googlechart)
{
$this->googlechart = true;
}
} }
// check for get module if ($foundA || $foundB && !$this->googlechart)
if (!isset($this->getModule[$this->target][$view])
|| !$this->getModule[$this->target][$view])
{ {
$foundA = $this->getGetModule($php_view); $this->googlechart = true;
$foundB = $this->getGetModule($contnent); }
if ($foundA || $foundB) }
{ // check for get module
$this->getModule[$this->target][$view] = true; if (!isset($this->getModule[$_target][$view])
} || !$this->getModule[$_target][$view])
{
$foundA = $this->getGetModule($php_view);
$foundB = $this->getGetModule($contnent);
if ($foundA || $foundB)
{
$this->getModule[$_target][$view] = true;
} }
return array(
'id' => $row->id,
'html' => $this->setGuiCodePlaceholder(
$contnent,
array(
'table' => $table,
'field' => $table,
'id' => $row->id,
'type' => 'html'
)
),
'php_view' => $this->setGuiCodePlaceholder(
$php_view,
array(
'table' => $table,
'field' => 'php_view',
'id' => $row->id,
'type' => 'php'
)
)
);
} }
} }
// load UIKIT if needed
if (2 == $this->uikit || 1 == $this->uikit)
{
if (!isset($this->uikitComp[$view]))
{
$this->uikitComp[$view] = array();
}
// set uikit to views
$this->uikitComp[$view]
= ComponentbuilderHelper::getUikitComp(
$contnent, $this->uikitComp[$view]
);
}
return false; return array(
'id' => $row->id,
'html' => $this->setGuiCodePlaceholder(
$contnent,
array(
'table' => $table,
'field' => $table,
'id' => $row->id,
'type' => 'html'
)
),
'php_view' => $this->setGuiCodePlaceholder(
$php_view,
array(
'table' => $table,
'field' => 'php_view',
'id' => $row->id,
'type' => 'php'
)
)
);
}
/**
* set Data With Alias Keys
*
* @param string $table The table where to find the alias
*
* @return void
*
*/
protected function setDataWithAliasKeys($table)
{
// now check if key is found
if (!isset($this->dataWithAliasKeys[$table]))
{
// load this table keys
$this->dataWithAliasKeys[$table] = array();
// Create a new query object.
$query = $this->db->getQuery(true);
$query->select(array('a.id', 'a.alias'));
$query->from('#__componentbuilder_' . $table . ' AS a');
$this->db->setQuery($query);
$rows = $this->db->loadObjectList();
// check if we have an array
if (ComponentbuilderHelper::checkArray($rows))
{
foreach ($rows as $row)
{
// build the key
$k_ey = ComponentbuilderHelper::safeString($row->alias);
$key = preg_replace("/[^A-Za-z]/", '', $k_ey);
// set the keys
$this->dataWithAliasKeys[$table][$row->alias] = $row->id;
$this->dataWithAliasKeys[$table][$k_ey] = $row->id;
$this->dataWithAliasKeys[$table][$key] = $row->id;
}
}
}
} }
/** /**
@ -6091,7 +6185,6 @@ class Get
*/ */
protected function getMediaLibrary($id) protected function getMediaLibrary($id)
{ {
// check if the lib has already been set // check if the lib has already been set
if (!isset($this->libraries[$id])) if (!isset($this->libraries[$id]))
{ {

View File

@ -12116,7 +12116,6 @@ class Interpretation extends Fields
$COMPONENT = strtoupper($component); $COMPONENT = strtoupper($component);
// set uppercase view // set uppercase view
$VIEWS = strtoupper($nameListCode); $VIEWS = strtoupper($nameListCode);
// build the body // build the body
$body = array(); $body = array();
// check if the filter type is sidebar (1 = sidebar) // check if the filter type is sidebar (1 = sidebar)
@ -12146,6 +12145,14 @@ class Interpretation extends Fields
$body[] = $this->_t(1) . "}"; $body[] = $this->_t(1) . "}";
$body[] = "</script>"; $body[] = "</script>";
} }
// Trigger Event: jcb_ce_onSetDefaultViewsBodyTop
$this->triggerEvent(
'jcb_ce_onSetDefaultViewsBodyTop',
array(&$this,
&$body,
&$nameSingleCode,
&$nameListCode)
);
$body[] = "<form action=\"<?php echo JRoute::_('index.php?option=com_" $body[] = "<form action=\"<?php echo JRoute::_('index.php?option=com_"
. $component . "&view=" . $nameListCode . $component . "&view=" . $nameListCode
. "'); ?>\" method=\"post\" name=\"adminForm\" id=\"adminForm\">"; . "'); ?>\" method=\"post\" name=\"adminForm\" id=\"adminForm\">";
@ -12159,6 +12166,14 @@ class Interpretation extends Fields
$body[] = "<?php else : ?>"; $body[] = "<?php else : ?>";
$body[] = $this->_t(1) . "<div id=\"j-main-container\">"; $body[] = $this->_t(1) . "<div id=\"j-main-container\">";
$body[] = "<?php endif; ?>"; $body[] = "<?php endif; ?>";
// Trigger Event: jcb_ce_onSetDefaultViewsFormTop
$this->triggerEvent(
'jcb_ce_onSetDefaultViewsFormTop',
array(&$this,
&$body,
&$nameSingleCode,
&$nameListCode)
);
// check if the filter type is sidebar (2 = topbar) // check if the filter type is sidebar (2 = topbar)
if (isset($this->adminFilterType[$nameListCode]) if (isset($this->adminFilterType[$nameListCode])
&& $this->adminFilterType[$nameListCode] == 2) && $this->adminFilterType[$nameListCode] == 2)
@ -12247,7 +12262,23 @@ class Interpretation extends Fields
$body[] = $this->_t(1) $body[] = $this->_t(1)
. "<input type=\"hidden\" name=\"task\" value=\"\" />"; . "<input type=\"hidden\" name=\"task\" value=\"\" />";
$body[] = $this->_t(1) . "<?php echo JHtml::_('form.token'); ?>"; $body[] = $this->_t(1) . "<?php echo JHtml::_('form.token'); ?>";
// Trigger Event: jcb_ce_onSetDefaultViewsFormBottom
$this->triggerEvent(
'jcb_ce_onSetDefaultViewsFormBottom',
array(&$this,
&$body,
&$nameSingleCode,
&$nameListCode)
);
$body[] = "</form>"; $body[] = "</form>";
// Trigger Event: jcb_ce_onSetDefaultViewsBodyBottom
$this->triggerEvent(
'jcb_ce_onSetDefaultViewsBodyBottom',
array(&$this,
&$body,
&$nameSingleCode,
&$nameListCode)
);
return implode(PHP_EOL, $body); return implode(PHP_EOL, $body);
} }
@ -12503,9 +12534,7 @@ class Interpretation extends Fields
public function setEditBody(&$view) public function setEditBody(&$view)
{ {
// set view name // set view name
$nameSingleCode = ComponentbuilderHelper::safeString( $nameSingleCode = $view['settings']->name_single_code;
$view['settings']->name_single
);
// main lang prefix // main lang prefix
$langView = $this->langPrefix . '_' $langView = $this->langPrefix . '_'
. ComponentbuilderHelper::safeString($nameSingleCode, 'U'); . ComponentbuilderHelper::safeString($nameSingleCode, 'U');
@ -12805,7 +12834,7 @@ class Interpretation extends Fields
$tabs = array(); $tabs = array();
// sort the tabs based on key order // sort the tabs based on key order
ksort($this->tabCounter[$nameSingleCode]); ksort($this->tabCounter[$nameSingleCode]);
// start tab builinging loop // start tab building loop
foreach ($this->tabCounter[$nameSingleCode] as $tabNr => $tabName) foreach ($this->tabCounter[$nameSingleCode] as $tabNr => $tabName)
{ {
$tabWidth = 12; $tabWidth = 12;
@ -13516,29 +13545,211 @@ class Interpretation extends Fields
*/ */
public function setLayout($nameSingleCode, $layoutName, $items, $type) public function setLayout($nameSingleCode, $layoutName, $items, $type)
{ {
// first build the layout file // we check if there is a local override
$target = array('admin' => $nameSingleCode); if (!$this->setLayoutOverride($nameSingleCode, $layoutName, $items))
$this->buildDynamique($target, $type, $layoutName);
// add to front if needed
if ($this->lang === 'both')
{ {
$target = array('site' => $nameSingleCode); // first build the layout file
$target = array('admin' => $nameSingleCode);
$this->buildDynamique($target, $type, $layoutName); $this->buildDynamique($target, $type, $layoutName);
// add to front if needed
if ($this->lang === 'both')
{
$target = array('site' => $nameSingleCode);
$this->buildDynamique($target, $type, $layoutName);
}
if (ComponentbuilderHelper::checkString($items))
{
// LAYOUTITEMS <<<DYNAMIC>>>
$this->fileContentDynamic[$nameSingleCode . '_'
. $layoutName][$this->hhh . 'LAYOUTITEMS' . $this->hhh]
= $items;
}
else
{
// LAYOUTITEMS <<<DYNAMIC>>>
$this->fileContentDynamic[$nameSingleCode . '_'
. $layoutName][$this->hhh . 'bogus' . $this->hhh]
= 'boom';
}
} }
if (ComponentbuilderHelper::checkString($items)) }
/**
* @param string $nameSingleCode
* @param string $layoutName
* @param string $items
*
* @return boolean true if override was found
*/
protected function setLayoutOverride($nameSingleCode, $layoutName, $items)
{
if (($data = $this->getLayoutOverride($nameSingleCode, $layoutName))
!== false)
{ {
// LAYOUTITEMS <<<DYNAMIC>>> // first build the layout file
$target = array('admin' => $nameSingleCode);
$this->buildDynamique($target, 'layoutoverride', $layoutName);
// add to front if needed
if ($this->lang === 'both')
{
$target = array('site' => $nameSingleCode);
$this->buildDynamique($target, 'layoutoverride', $layoutName);
}
// make sure items is an empty string (should not be needed.. but)
if (!ComponentbuilderHelper::checkString($items))
{
$items = '';
}
// set placeholder
$placeholder = $this->placeholders;
$placeholder[$this->hhh . 'LAYOUTITEMS' . $this->hhh] = $items;
// OVERRIDE_LAYOUT_CODE <<<DYNAMIC>>>
$php_view = (array) explode(PHP_EOL, $data['php_view']);
if (ComponentbuilderHelper::checkArray($php_view))
{
$php_view = PHP_EOL . PHP_EOL . implode(PHP_EOL, $php_view);
$this->fileContentDynamic[$nameSingleCode . '_'
. $layoutName][$this->hhh
. 'OVERRIDE_LAYOUT_CODE' . $this->hhh]
= $this->setPlaceholders(
$php_view, $placeholder
);
}
else
{
$this->fileContentDynamic[$nameSingleCode . '_'
. $layoutName][$this->hhh
. 'OVERRIDE_LAYOUT_CODE' . $this->hhh]
= '';
}
// OVERRIDE_LAYOUT_BODY <<<DYNAMIC>>>
$this->fileContentDynamic[$nameSingleCode . '_' $this->fileContentDynamic[$nameSingleCode . '_'
. $layoutName][$this->hhh . 'LAYOUTITEMS' . $this->hhh] . $layoutName][$this->hhh
= $items; . 'OVERRIDE_LAYOUT_BODY' . $this->hhh]
= PHP_EOL . $this->setPlaceholders(
$data['html'], $placeholder
);
// since override was found
return true;
} }
else
return false;
}
/**
* @param string $nameSingleCode
* @param string $layoutName
*
* @return array the layout data
*/
protected function getLayoutOverride($nameSingleCode, $layoutName)
{
// check if there is an override by component name, view name, & layout name
if ($this->setTemplateAndLayoutData(
'override', $nameSingleCode, false, array(''),
array($this->componentCodeName . $nameSingleCode . $layoutName)
))
{ {
// LAYOUTITEMS <<<DYNAMIC>>> $data = $this->layoutData[$this->target][$this->componentCodeName
$this->fileContentDynamic[$nameSingleCode . '_' . $nameSingleCode . $layoutName];
. $layoutName][$this->hhh . 'bogus' . $this->hhh] // remove since we will add the layout now
= 'boom'; if ($this->lang === 'both')
{
unset(
$this->layoutData['admin'][$this->componentCodeName
. $nameSingleCode . $layoutName]
);
unset(
$this->layoutData['site'][$this->componentCodeName
. $nameSingleCode . $layoutName]
);
}
else
{
unset(
$this->layoutData[$this->target][$this->componentCodeName
. $nameSingleCode . $layoutName]
);
}
return $data;
} }
// check if there is an override by component name & layout name
elseif ($this->setTemplateAndLayoutData(
'override', $nameSingleCode, false, array(''),
array($this->componentCodeName . $layoutName)
))
{
$data = $this->layoutData[$this->target][$this->componentCodeName
. $layoutName];
// remove since we will add the layout now
if ($this->lang === 'both')
{
unset(
$this->layoutData['admin'][$this->componentCodeName
. $layoutName]
);
unset(
$this->layoutData['site'][$this->componentCodeName
. $layoutName]
);
}
else
{
unset(
$this->layoutData[$this->target][$this->componentCodeName
. $layoutName]
);
}
return $data;
}
// check if there is an override by view & layout name
elseif ($this->setTemplateAndLayoutData(
'override', $nameSingleCode, false, array(''),
array($nameSingleCode . $layoutName)
))
{
$data = $this->layoutData[$this->target][$nameSingleCode
. $layoutName];
// remove since we will add the layout now
if ($this->lang === 'both')
{
unset(
$this->layoutData['admin'][$nameSingleCode . $layoutName]
);
unset($this->layoutData['site'][$nameSingleCode . $layoutName]);
}
else
{
unset($this->layoutData[$this->target][$layoutName]);
}
return $data;
}
// check if there is an override by layout name (global layout)
elseif ($this->setTemplateAndLayoutData(
'override', $nameSingleCode, false, array(''),
array($layoutName)
))
{
$data = $this->layoutData[$this->target][$layoutName];
// remove since we will add the layout now
if ($this->lang === 'both')
{
unset($this->layoutData['admin'][$layoutName]);
unset($this->layoutData['site'][$layoutName]);
}
else
{
unset($this->layoutData[$this->target][$layoutName]);
}
return $data;
}
return false;
} }
/** /**

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<extension type="component" version="3.2" method="upgrade"> <extension type="component" version="3.2" method="upgrade">
<name>COM_COMPONENTBUILDER</name> <name>COM_COMPONENTBUILDER</name>
<creationDate>27th December, 2020</creationDate> <creationDate>31st December, 2020</creationDate>
<author>Llewellyn van der Merwe</author> <author>Llewellyn van der Merwe</author>
<authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail> <authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail>
<authorUrl>http://www.joomlacomponentbuilder.com</authorUrl> <authorUrl>http://www.joomlacomponentbuilder.com</authorUrl>