52
0
Fork 0

update - v1.0.8

This commit is contained in:
Llewellyn van der Merwe 2021-12-08 22:42:13 +02:00
parent cbbe81168d
commit deda7d5c82
Signed by: Llewellyn
GPG Key ID: EFC0C720A240551C
5 changed files with 258 additions and 212 deletions

View File

@ -22,25 +22,25 @@ JLoader::register('ComponentbuilderHelper', JPATH_ADMINISTRATOR . '/components/c
* Extension - Componentbuilder Headers Compiler plugin.
*
* @package ComponentbuilderHeadersCompiler
* @since 1.0.7
* @since 1.0.8
*/
class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
{
/**
/**
* Global switch to see if a file has custom headers.
*
* @var boolean
* @since 1.0.0
*/
protected $loadHeaders = false;
protected $loadHeaders = false;
/**
* The files active with headers
* The active headers
*
* @var array
* @since 1.0.0
* @since 1.0.8
*/
protected $activeFiles = array();
protected $activeHeaders = array();
/**
* The compiler placeholders values
@ -48,7 +48,7 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
* @var array
* @since 1.0.6
*/
protected $placeholders = array();
protected $placeholders = array();
/**
* The powers to include in project
@ -56,33 +56,33 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
* @var array
* @since 1.0.6
*/
protected $linkedPowers = array();
protected $linkedPowers = array();
/**
* The Targets
*
* @var array
* @since 1.0.5
* @since 1.0.8
*/
protected $targets = array(
'admin_view_headers' =>
'admin_view_headers' =>
array(
'add_admin_view_model' => array(
'field' => 'admin_view_model',
'context' => 'admin.view.model',
'view' => 'name_single'
),
'add_admin_view' => array(
'add_admin_view' => array(
'field' => 'admin_view',
'context' => 'admin.view',
'view' => 'name_single'
),
'add_admin_view_html' => array(
'add_admin_view_html' => array(
'field' => 'admin_view_html',
'context' => 'admin.view.html',
'view' => 'name_single'
),
'add_site_admin_view_html' => array(
'add_site_admin_view_html' => array(
'field' => 'site_admin_view_html',
'context' => 'site.admin.view.html',
'view' => 'name_single'
@ -92,17 +92,22 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
'context' => 'admin.view.controller',
'view' => 'name_single'
),
'add_ajax_model' => array(
'field' => 'ajax_model',
'context' => 'ajax.admin.model',
'view' => 'ajax'
),
'add_admin_views_model' => array(
'field' => 'admin_views_model',
'context' => 'admin.views.model',
'view' => 'name_list'
),
'add_admin_views' => array(
'add_admin_views' => array(
'field' => 'admin_views',
'context' => 'admin.views',
'view' => 'name_list'
),
'add_admin_views_html' => array(
'add_admin_views_html' => array(
'field' => 'admin_views_html',
'context' => 'admin.views.html',
'view' => 'name_list'
@ -113,19 +118,19 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
'view' => 'name_list'
)
),
'site_view_headers' =>
'site_view_headers' =>
array(
'add_site_view_model' => array(
'field' => 'site_view_model',
'context' => 'site.view.model',
'view' => 'code'
),
'add_site_view' => array(
'add_site_view' => array(
'field' => 'site_view',
'context' => 'site.view',
'view' => 'code'
),
'add_site_view_html' => array(
'add_site_view_html' => array(
'field' => 'site_view_html',
'context' => 'site.view.html',
'view' => 'code'
@ -140,12 +145,12 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
'context' => 'site.views.model',
'view' => 'code'
),
'add_site_views' => array(
'add_site_views' => array(
'field' => 'site_views',
'context' => 'site.views',
'view' => 'code'
),
'add_site_views_html' => array(
'add_site_views_html' => array(
'field' => 'site_views_html',
'context' => 'site.views.html',
'view' => 'code'
@ -154,21 +159,26 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
'field' => 'site_views_controller',
'context' => 'site.views.controller',
'view' => 'code'
),
'add_ajax_model' => array(
'field' => 'ajax_model',
'context' => 'ajax.site.model',
'view' => 'ajax'
)
),
'custom_admin_view_headers' =>
'custom_admin_view_headers' =>
array(
'add_custom_admin_view_model' => array(
'field' => 'custom_admin_view_model',
'context' => 'custom.admin.view.model',
'view' => 'code'
),
'add_custom_admin_view' => array(
'add_custom_admin_view' => array(
'field' => 'custom_admin_view',
'context' => 'custom.admin.view',
'view' => 'code'
),
'add_custom_admin_view_html' => array(
'add_custom_admin_view_html' => array(
'field' => 'custom_admin_view_html',
'context' => 'custom.admin.view.html',
'view' => 'code'
@ -183,12 +193,12 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
'context' => 'custom.admin.views.model',
'view' => 'code'
),
'add_custom_admin_views' => array(
'add_custom_admin_views' => array(
'field' => 'custom_admin_views',
'context' => 'custom.admin.views',
'view' => 'code'
),
'add_custom_admin_views_html' => array(
'add_custom_admin_views_html' => array(
'field' => 'custom_admin_views_html',
'context' => 'custom.admin.views.html',
'view' => 'code'
@ -197,11 +207,44 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
'field' => 'custom_admin_views_controller',
'context' => 'custom.admin.views.controller',
'view' => 'code'
),
'add_ajax_model' => array(
'field' => 'ajax_model',
'context' => 'ajax.admin.model',
'view' => 'ajax'
)
),
'joomla_component_headers' =>
'component_dashboard_headers' =>
array(
'add_admin_component' => array(
'add_dashboard_model' => array(
'field' => 'dashboard_model',
'context' => 'dashboard.model',
'view' => 'dashboard'
),
'add_dashboard_view' => array(
'field' => 'dashboard_view',
'context' => 'dashboard.view',
'view' => 'dashboard'
),
'add_dashboard_view_html' => array(
'field' => 'dashboard_view_html',
'context' => 'dashboard.view.html',
'view' => 'dashboard'
),
'add_dashboard_controller' => array(
'field' => 'dashboard_controller',
'context' => 'dashboard.controller',
'view' => 'dashboard'
),
'add_ajax_model' => array(
'field' => 'ajax_model',
'context' => 'ajax.admin.model',
'view' => 'ajax'
)
),
'joomla_component_headers' =>
array(
'add_admin_component' => array(
'field' => 'admin_component',
'context' => 'admin.component',
'view' => 'admin'
@ -211,18 +254,18 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
'context' => 'site.component',
'view' => 'site'
),
'add_admin_helper' => array(
'add_admin_helper' => array(
'field' => 'admin_helper',
'context' => 'admin.helper',
'view' => 'admin'
),
'add_site_helper' => array(
'add_site_helper' => array(
'field' => 'site_helper',
'context' => 'site.helper',
'view' => 'site'
)
)
);
);
/**
* Event Triggered in the compiler [on Before Model View Data]
@ -231,29 +274,13 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
*
* @since 1.0
*/
public function jcb_ce_onBeforeModelViewData(&$context, &$view,
&$placeholders
) {
// add the headers
$view->params = (isset($view->params)
&& ComponentbuilderHelper::checkJson($view->params)) ? json_decode(
$view->params, true
) : $view->params;
if (ComponentbuilderHelper::checkArray($view->params)
&& isset($view->params['admin_view_headers'])
&& ComponentbuilderHelper::checkArray(
$view->params['admin_view_headers']
))
public function jcb_ce_onBeforeModelViewData(&$context, &$view, &$placeholders)
{
// check that the params are set
if (isset($view->params))
{
foreach ($this->targets['admin_view_headers'] as $target => $event)
{
if (isset($view->params['admin_view_headers'][$target])
&& $view->params['admin_view_headers'][$target] == 1)
{
// get the header string if set
$this->getHeaderString($view, $event, 'admin_view_headers');
}
}
// add the headers for the Admin Views
$this->setHeaders($view->params, $view, 'admin_view_headers');
}
}
@ -262,49 +289,17 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
*
* @return void
*
* @since 1.2
* @since 1.0.2
*/
public function jcb_ce_onBeforeModelCustomViewData(&$context, &$view,
&$id, &$table
) {
// add the headers
$view->params = (isset($view->params)
&& ComponentbuilderHelper::checkJson($view->params)) ? json_decode(
$view->params, true
) : $view->params;
// target site views
if (ComponentbuilderHelper::checkArray($view->params)
&& isset($view->params['site_view_headers'])
&& ComponentbuilderHelper::checkArray(
$view->params['site_view_headers']
))
public function jcb_ce_onBeforeModelCustomViewData(&$context, &$view, &$id, &$table)
{
// check that the params are set
if (isset($view->params))
{
foreach ($this->targets['site_view_headers'] as $target => $event)
{
if (isset($view->params['site_view_headers'][$target])
&& $view->params['site_view_headers'][$target] == 1)
{
// get the header string if set
$this->getHeaderString($view, $event, 'site_view_headers');
}
}
}
// target custom admin views
if (ComponentbuilderHelper::checkArray($view->params)
&& isset($view->params['custom_admin_view_headers'])
&& ComponentbuilderHelper::checkArray(
$view->params['custom_admin_view_headers']
))
{
foreach ($this->targets['custom_admin_view_headers'] as $target => $event)
{
if (isset($view->params['custom_admin_view_headers'][$target])
&& $view->params['custom_admin_view_headers'][$target] == 1)
{
// get the header string if set
$this->getHeaderString($view, $event, 'custom_admin_view_headers');
}
}
// add the headers for the Site Views
$this->setHeaders($view->params, $view, 'site_view_headers');
// add the headers for the Custom Admin Views
$this->setHeaders($view->params, $view, 'custom_admin_view_headers');
}
}
@ -313,115 +308,24 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
*
* @return void
*
* @since 1.4
* @since 1.0.4
*/
public function jcb_ce_onBeforeModelComponentData(&$context, &$component)
{
// add the privacy
$component->params = (isset($component->params)
&& ComponentbuilderHelper::checkJson($component->params)) ? json_decode(
$component->params, true
) : $component->params;
if (ComponentbuilderHelper::checkArray($component->params)
&& isset($component->params['joomla_component_headers'])
&& ComponentbuilderHelper::checkArray(
$component->params['joomla_component_headers']
))
// check that the params are set
if (isset($component->params))
{
foreach ($this->targets['joomla_component_headers'] as $target => $event)
{
if (isset($component->params['joomla_component_headers'][$target])
&& $component->params['joomla_component_headers'][$target] == 1)
{
// activate the load of the headers
$this->loadHeaders = true;
// load the headers
$this->activeFiles[$event['view']][$event['context']]
= $component->params['joomla_component_headers'][$event['field']];
}
}
// add the headers for the Joomla Component
$this->setHeaders($component->params, $component, 'joomla_component_headers');
}
}
/**
* get the header string
*
* @return void
*
* @since 1.0
*/
protected function getHeaderString(&$view, &$get, $key, $view_name = null)
{
// we first check if the value is set
if (isset($view->params[$key][$get['field']]) || isset($view->params[$key]['power_' . $get['field']]))
// check that the dashboard params are set
if (isset($component->dashboard_params))
{
// activate the load of the headers
$this->loadHeaders = true;
// setup the view key name
if (!$view_name)
{
$view_name = ComponentbuilderHelper::safeString(
$view->{$get['view']}
);
}
// we start this field if not already
if (!isset($this->activeFiles[$view_name][$get['context']]))
{
$this->activeFiles[$view_name][$get['context']] = '';
}
// start little bucket
$bucket = array();
// load the headers if text
if (isset($view->params[$key][$get['field']]) && ComponentbuilderHelper::checkString($view->params[$key][$get['field']]))
{
$bucket[] = $view->params[$key][$get['field']];
}
// load the headers if power
if (isset($view->params[$key]['power_' . $get['field']]) && ComponentbuilderHelper::checkArray($view->params[$key]['power_' . $get['field']], true)
&& ($use = $this->getPowers($view->params[$key]['power_' . $get['field']])) !== false)
{
$bucket[] = 'use ' . implode(';' . PHP_EOL . 'use ', $use) . ';';
}
// we start this field if not already
if (ComponentbuilderHelper::checkArray($bucket, true))
{
$this->activeFiles[$view_name][$get['context']] .= implode(PHP_EOL, $bucket);
}
// add the headers for the Component Dashboard
$this->setHeaders($component->dashboard_params, $component, 'component_dashboard_headers');
}
}
/**
* get the powers header use strings
*
* @return string
*
* @since 1.0.6
*/
protected function getPowers($ids)
{
// if none are found
$namspaces = false;
// add to active powers
if (($namspaces = ComponentbuilderHelper::getVars('power', $ids, 'id', 'namespace')) !== false)
{
foreach ($ids as $id)
{
$this->linkedPowers[$id] = $id;
}
// convert the dots to namespace
$namspaces = array_map( function($namespace) {
return ComponentbuilderHelper::safeNamespace(
str_replace(
array_keys($this->placeholders),
array_values($this->placeholders),
str_replace('.', '\\', $namespace)
)
);
}, $namspaces );
}
return $namspaces;
}
/**
* Event Triggered in the compiler [on set Class Header]
*
@ -429,20 +333,23 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
*
* @since 1.0
*/
public function jcb_ce_setClassHeader(&$context, &$event_context,
&$view_name,
&$headers
) {
if ($this->loadHeaders && isset($this->activeFiles[$view_name])
&& isset($this->activeFiles[$view_name][$event_context]))
public function jcb_ce_setClassHeader(&$context, &$event_context, &$view_name, &$headers)
{
if ($this->loadHeaders && isset($this->activeHeaders[$view_name])
&& isset($this->activeHeaders[$view_name][$event_context]))
{
// we have default headers we actually need
foreach ($headers as $n => $header)
{
// if an empty line is found just skip it
if (empty($header))
{
continue;
}
// we check if this header is also set from the user
if (empty($header) || (isset($this->activeFiles[$view_name][$event_context]) && strpos(
$this->activeFiles[$view_name][$event_context], $header
) !== false))
if (isset($this->activeHeaders[$view_name][$event_context]) && strpos(
$this->activeHeaders[$view_name][$event_context], $header
) !== false)
{
// since it is set, remove it here
unset($headers[$n]);
@ -450,7 +357,7 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
}
// now add the custom headers
// yes they are below the defaults, unless overridden and removed above
$headers[] = $this->activeFiles[$view_name][$event_context];
$headers[] = $this->activeHeaders[$view_name][$event_context];
}
}
@ -481,5 +388,143 @@ class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
{
$compiler->linkedPowers = $this->linkedPowers;
}
}
}
/**
* set the headers
*
* @return void
*
* @since 1.0.8
*/
protected function setHeaders(&$params, &$obj, $key)
{
// add the headers
$params = (ComponentbuilderHelper::checkJson($params)) ? json_decode($params, true) : $params;
// make sure we have the keys values in the params area
if (ComponentbuilderHelper::checkArray($params) && isset($params[$key])
&& ComponentbuilderHelper::checkArray($params[$key]))
{
foreach ($this->targets[$key] as $target => $event)
{
if (isset($params[$key][$target])
&& $params[$key][$target] == 1)
{
// get the header string if set
$this->getHeaders(
$params[$key],
$event,
$this->getViewName(
$obj,
$event['view']
)
);
}
}
}
}
/**
* get the headers
*
* @return void
*
* @since 1.0
*/
protected function getHeaders(&$params, &$get, $view_name)
{
// we first check if the value is set
if (isset($params[$get['field']]) || isset($params['power_' . $get['field']]))
{
// start little headers bucket
$headers = array();
// load the headers if text
if (isset($params[$get['field']]) && ComponentbuilderHelper::checkString($params[$get['field']]))
{
$headers[] = $params[$get['field']];
}
// load the headers if power
if (isset($params['power_' . $get['field']]) && ComponentbuilderHelper::checkArray($params['power_' . $get['field']], true)
&& ($use = $this->getPowers($params['power_' . $get['field']])) !== false)
{
$headers[] = 'use ' . implode(';' . PHP_EOL . 'use ', $use) . ';';
}
// check if we found some header values
if (ComponentbuilderHelper::checkArray($headers, true))
{
// activate the load of the headers
$this->loadHeaders = true;
// check if this active header is already set
if (!isset($this->activeHeaders[$view_name][$get['context']]))
{
// start the active header
$this->activeHeaders[$view_name][$get['context']] = '';
}
else
{
// each addition we add a new line
$this->activeHeaders[$view_name][$get['context']] = PHP_EOL;
}
// load the found headers
$this->activeHeaders[$view_name][$get['context']] .= implode(PHP_EOL, $headers);
}
}
}
/**
* get the view name
*
* @return string
*
* @since 1.0.8
*/
protected function getViewName(&$view, &$get)
{
if ($get === 'site' || $get === 'admin' || $get === 'ajax' || $get === 'dashboard')
{
// static key name
return $get;
}
elseif (isset($view->{$get}))
{
return ComponentbuilderHelper::safeString(
$view->{$get}
);
}
return '_error';
}
/**
* get the powers header use strings
*
* @return mixed
*
* @since 1.0.6
*/
protected function getPowers($ids)
{
// if none are found
$namspaces = false;
// add to active powers
if (($namspaces = ComponentbuilderHelper::getVars('power', $ids, 'id', 'namespace')) !== false)
{
foreach ($ids as $id)
{
$this->linkedPowers[$id] = $id;
}
// convert the dots to namespace
$namspaces = array_map(function ($namespace) {
return ComponentbuilderHelper::safeNamespace(
str_replace(
array_keys($this->placeholders),
array_values($this->placeholders),
str_replace('.', '\\', $namespace)
)
);
}, $namspaces);
}
return $namspaces;
}
}

View File

@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" version="4" group="extension" method="upgrade">
<name>PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER</name>
<creationDate>3rd December, 2021</creationDate>
<creationDate>8th December, 2021</creationDate>
<author>Llewellyn van der Merwe</author>
<authorEmail>joomla@vdm.io</authorEmail>
<authorUrl>https://dev.vdm.io</authorUrl>
<copyright>Copyright (C) 2015 Vast Development Method. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<version>1.0.7</version>
<version>1.0.8</version>
<description>PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_XML_DESCRIPTION</description>
<!-- Scripts to run on installation -->

View File

@ -2,6 +2,6 @@ PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER="Extension - Componentbuilder Head
PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_DESCRIPTION="This plugin is used to set the custom headers for your classes during compilation. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field.
Also be sure to set your code where you would like to set Custom Headers."
PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_XML_DESCRIPTION="<h1>Extension - Componentbuilder Headers Compiler (v.1.0.7)</h1> <div style='clear: both;'></div><p>This plugin is used to set the custom headers for your classes during compilation. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field.
PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_XML_DESCRIPTION="<h1>Extension - Componentbuilder Headers Compiler (v.1.0.8)</h1> <div style='clear: both;'></div><p>This plugin is used to set the custom headers for your classes during compilation. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field.
Also be sure to set your code where you would like to set Custom Headers.</p><p>Created by <a href='https://dev.vdm.io' target='_blank'>Llewellyn van der Merwe</a><br /><small>Development started 24th May, 2020</small></p>"

View File

@ -2,6 +2,6 @@ PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER="Extension - Componentbuilder Head
PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_DESCRIPTION="This plugin is used to set the custom headers for your classes during compilation. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field.
Also be sure to set your code where you would like to set Custom Headers."
PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_XML_DESCRIPTION="<h1>Extension - Componentbuilder Headers Compiler (v.1.0.7)</h1> <div style='clear: both;'></div><p>This plugin is used to set the custom headers for your classes during compilation. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field.
PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_XML_DESCRIPTION="<h1>Extension - Componentbuilder Headers Compiler (v.1.0.8)</h1> <div style='clear: both;'></div><p>This plugin is used to set the custom headers for your classes during compilation. To activate it you must first enable it here. Then open your JCB component global options, and under the Global tab, select this plugin in the Activate Compiler Plugins field.
Also be sure to set your code where you would like to set Custom Headers.</p><p>Created by <a href='https://dev.vdm.io' target='_blank'>Llewellyn van der Merwe</a><br /><small>Development started 24th May, 2020</small></p>"

View File

@ -43,11 +43,12 @@ class plgExtensionComponentbuilderHeadersCompilerInstallerScript
if ('install' === $route)
{
// check that componentbuilder is installed
$pathToCore = JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/componentbuilder.php';
if (!JFile::exists($pathToCore))
{
$app->enqueueMessage('Joomla Component Builder must first be installed from <a href="https://www.joomlacomponentbuilder.com/ " target="_blank">Joomla Component Builder</a>.', 'error');
$app->enqueueMessage('JCB must first be installed from <a href="https://git.vdm.dev/joomla/Component-Builder-Pro/" target="_blank">Joomla Component Builder</a>.', 'error');
return false;
}
// load the helper class
@ -60,8 +61,8 @@ class plgExtensionComponentbuilderHeadersCompilerInstallerScript
{
// get the version
$jcbVersion = explode('.', $manifest->version);
// check that we have JCB 2.12.14 or higher installed
if (count($jcbVersion) == 3 && (($jcbVersion[0] == 2 && (($jcbVersion[1] == 12 && $jcbVersion[2] >= 14) || ($jcbVersion[1] > 12))) || $jcbVersion[0] >= 3))
// check that we have JCB 3 or higher installed
if (count($jcbVersion) == 3 && $jcbVersion[0] >= 3)
{
$blockInstall = false;
}
@ -69,7 +70,7 @@ class plgExtensionComponentbuilderHeadersCompilerInstallerScript
// allow install if all conditions are met
if ($blockInstall)
{
$app->enqueueMessage('Please upgrade to JCB-PRO 2.12.14 or higher before installing this plugin.', 'error');
$app->enqueueMessage('Please upgrade to JCB-Pro v3.0.0 or higher before installing this plugin.', 'error');
return false;
}
}