2023-03-21 22:52:57 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @package Joomla.Component.Builder
|
|
|
|
*
|
|
|
|
* @created 4th September, 2022
|
|
|
|
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
|
|
|
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
|
|
|
|
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
|
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace VDM\Joomla\Componentbuilder\Compiler\Templatelayout;
|
|
|
|
|
|
|
|
|
|
|
|
use VDM\Joomla\Componentbuilder\Compiler\Config;
|
2023-10-04 18:28:29 +00:00
|
|
|
use VDM\Joomla\Componentbuilder\Compiler\Builder\LayoutData;
|
|
|
|
use VDM\Joomla\Componentbuilder\Compiler\Builder\TemplateData;
|
2023-03-21 22:52:57 +00:00
|
|
|
use VDM\Joomla\Componentbuilder\Compiler\Alias\Data as Aliasdata;
|
|
|
|
use VDM\Joomla\Utilities\ArrayHelper;
|
|
|
|
use VDM\Joomla\Utilities\GetHelper;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Template Layout Data Class
|
|
|
|
*
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
class Data
|
|
|
|
{
|
|
|
|
/**
|
2023-10-04 18:28:29 +00:00
|
|
|
* The Config Class.
|
2023-03-21 22:52:57 +00:00
|
|
|
*
|
2023-10-04 18:28:29 +00:00
|
|
|
* @var Config
|
2023-03-21 22:52:57 +00:00
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
protected Config $config;
|
|
|
|
|
|
|
|
/**
|
2023-10-04 18:28:29 +00:00
|
|
|
* The LayoutData Class.
|
2023-03-21 22:52:57 +00:00
|
|
|
*
|
2023-10-04 18:28:29 +00:00
|
|
|
* @var LayoutData
|
2023-03-21 22:52:57 +00:00
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
2023-10-04 18:28:29 +00:00
|
|
|
protected LayoutData $layoutdata;
|
2023-03-21 22:52:57 +00:00
|
|
|
|
|
|
|
/**
|
2023-10-04 18:28:29 +00:00
|
|
|
* The TemplateData Class.
|
2023-03-21 22:52:57 +00:00
|
|
|
*
|
2023-10-04 18:28:29 +00:00
|
|
|
* @var TemplateData
|
2023-03-21 22:52:57 +00:00
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
2023-10-04 18:28:29 +00:00
|
|
|
protected TemplateData $templatedata;
|
2023-03-21 22:52:57 +00:00
|
|
|
|
|
|
|
/**
|
2023-10-04 18:28:29 +00:00
|
|
|
* The Data Class.
|
2023-03-21 22:52:57 +00:00
|
|
|
*
|
2023-10-04 18:28:29 +00:00
|
|
|
* @var Aliasdata
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
protected Aliasdata $aliasdata;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param Config $config The Config Class.
|
|
|
|
* @param LayoutData $layoutdata The LayoutData Class.
|
|
|
|
* @param TemplateData $templatedata The TemplateData Class.
|
|
|
|
* @param Aliasdata $aliasdata The AliasData Class.
|
2023-03-21 22:52:57 +00:00
|
|
|
*
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
2023-10-04 18:28:29 +00:00
|
|
|
public function __construct(Config $config, LayoutData $layoutdata, TemplateData $templatedata, Aliasdata $aliasdata)
|
2023-03-21 22:52:57 +00:00
|
|
|
{
|
2023-10-04 18:28:29 +00:00
|
|
|
$this->config = $config;
|
|
|
|
$this->layoutdata = $layoutdata;
|
|
|
|
$this->templatedata = $templatedata;
|
|
|
|
$this->aliasdata = $aliasdata;
|
2023-03-21 22:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set Template and Layout Data
|
|
|
|
*
|
|
|
|
* @param string $content The content to check
|
|
|
|
* @param string $view The view code name
|
|
|
|
* @param bool $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 bool if something was found true
|
|
|
|
* @since 3.2.0
|
|
|
|
*/
|
|
|
|
public function set(string $content, string $view, bool $found = false,
|
|
|
|
array $templates = [], array $layouts = []): bool
|
|
|
|
{
|
|
|
|
// to check inside the templates
|
|
|
|
$again = [];
|
|
|
|
|
|
|
|
// check if template keys were passed
|
|
|
|
if (!ArrayHelper::check($templates))
|
|
|
|
{
|
|
|
|
// set the Template data
|
|
|
|
$temp1 = GetHelper::allBetween(
|
|
|
|
$content, "\$this->loadTemplate('", "')"
|
|
|
|
);
|
|
|
|
$temp2 = GetHelper::allBetween(
|
|
|
|
$content, '$this->loadTemplate("', '")'
|
|
|
|
);
|
|
|
|
if (ArrayHelper::check($temp1)
|
|
|
|
&& ArrayHelper::check($temp2))
|
|
|
|
{
|
|
|
|
$templates = array_merge($temp1, $temp2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ArrayHelper::check($temp1))
|
|
|
|
{
|
|
|
|
$templates = $temp1;
|
|
|
|
}
|
|
|
|
elseif (ArrayHelper::check($temp2))
|
|
|
|
{
|
|
|
|
$templates = $temp2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if we found templates
|
|
|
|
if (ArrayHelper::check($templates, true))
|
|
|
|
{
|
|
|
|
foreach ($templates as $template)
|
|
|
|
{
|
2023-10-04 18:28:29 +00:00
|
|
|
if (!$this->templatedata->
|
|
|
|
exists($this->config->build_target . '.' . $view . '.' . $template))
|
2023-03-21 22:52:57 +00:00
|
|
|
{
|
2023-10-04 18:28:29 +00:00
|
|
|
$data = $this->aliasdata->get(
|
2023-03-21 22:52:57 +00:00
|
|
|
$template, 'template', $view
|
|
|
|
);
|
|
|
|
if (ArrayHelper::check($data))
|
|
|
|
{
|
|
|
|
// load it to the template data array
|
2023-10-04 18:28:29 +00:00
|
|
|
$this->templatedata->
|
|
|
|
set($this->config->build_target . '.' . $view . '.' . $template, $data);
|
2023-03-21 22:52:57 +00:00
|
|
|
// call self to get child data
|
|
|
|
$again[] = ['content' => $data['html'], 'view' => $view];
|
|
|
|
$again[] = ['content' => $data['php_view'], 'view' => $view];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if we have the template set (and nothing yet found)
|
2023-10-04 18:28:29 +00:00
|
|
|
if (!$found && $this->templatedata->
|
|
|
|
exists($this->config->build_target . '.' . $view . '.' . $template, null))
|
2023-03-21 22:52:57 +00:00
|
|
|
{
|
|
|
|
// something was found
|
|
|
|
$found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if layout keys were passed
|
|
|
|
if (!ArrayHelper::check($layouts))
|
|
|
|
{
|
|
|
|
// set the Layout data
|
|
|
|
$lay1 = GetHelper::allBetween(
|
|
|
|
$content, "JLayoutHelper::render('", "',"
|
|
|
|
);
|
|
|
|
$lay2 = GetHelper::allBetween(
|
|
|
|
$content, 'JLayoutHelper::render("', '",'
|
|
|
|
);
|
|
|
|
if (ArrayHelper::check($lay1)
|
|
|
|
&& ArrayHelper::check($lay2))
|
|
|
|
{
|
|
|
|
$layouts = array_merge($lay1, $lay2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ArrayHelper::check($lay1))
|
|
|
|
{
|
|
|
|
$layouts = $lay1;
|
|
|
|
}
|
|
|
|
elseif (ArrayHelper::check($lay2))
|
|
|
|
{
|
|
|
|
$layouts = $lay2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if we found layouts
|
|
|
|
if (ArrayHelper::check($layouts, true))
|
|
|
|
{
|
|
|
|
// get the other target if both
|
|
|
|
$_target = null;
|
|
|
|
if ($this->config->lang_target === 'both')
|
|
|
|
{
|
|
|
|
$_target = ($this->config->build_target === 'admin') ? 'site' : 'admin';
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($layouts as $layout)
|
|
|
|
{
|
2023-10-04 18:28:29 +00:00
|
|
|
if (!$this->layoutdata->exists($this->config->build_target . '.' . $layout))
|
2023-03-21 22:52:57 +00:00
|
|
|
{
|
2023-10-04 18:28:29 +00:00
|
|
|
$data = $this->aliasdata->get($layout, 'layout', $view);
|
2023-03-21 22:52:57 +00:00
|
|
|
if (ArrayHelper::check($data))
|
|
|
|
{
|
|
|
|
// load it to the layout data array
|
2023-10-04 18:28:29 +00:00
|
|
|
$this->layoutdata->
|
|
|
|
set($this->config->build_target . '.' . $layout, $data);
|
2023-03-21 22:52:57 +00:00
|
|
|
// check if other target is set
|
|
|
|
if ($this->config->lang_target === 'both' && $_target)
|
|
|
|
{
|
2023-10-04 18:28:29 +00:00
|
|
|
$this->layoutdata->set($_target . '.' . $layout, $data);
|
2023-03-21 22:52:57 +00:00
|
|
|
}
|
|
|
|
// call self to get child data
|
|
|
|
$again[] = ['content' => $data['html'], 'view' => $view];
|
|
|
|
$again[] = ['content' => $data['php_view'], 'view' => $view];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if we have the layout set (and nothing yet found)
|
2023-10-04 18:28:29 +00:00
|
|
|
if (!$found && $this->layoutdata->exists($this->config->build_target . '.' . $layout))
|
2023-03-21 22:52:57 +00:00
|
|
|
{
|
|
|
|
// something was found
|
|
|
|
$found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check again
|
|
|
|
if (ArrayHelper::check($again))
|
|
|
|
{
|
|
|
|
foreach ($again as $go)
|
|
|
|
{
|
|
|
|
$found = $this->set(
|
|
|
|
$go['content'], $go['view'], $found
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// return the proof that something was found
|
|
|
|
return $found;
|
2023-10-04 18:28:29 +00:00
|
|
|
}
|
2023-03-21 22:52:57 +00:00
|
|
|
}
|
|
|
|
|