52
0

first commit - v1.0.0

This commit is contained in:
Llewellyn van der Merwe 2021-10-14 16:31:41 +02:00
commit aad37a1515
Signed by: Llewellyn
GPG Key ID: EFC0C720A240551C
8 changed files with 279 additions and 0 deletions

View File

@ -0,0 +1,155 @@
<?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 - 2020 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');
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Registry\Registry;
JLoader::register('ComponentbuilderHelper', JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/componentbuilder.php');
/**
* Extension - Componentbuilder Headers Compiler plugin.
*
* @package ComponentbuilderHeadersCompiler
* @since 1.0.0
*/
class PlgExtensionComponentbuilderHeadersCompiler extends CMSPlugin
{
/**
* Global switch to see if component have need class headers.
*
* @var boolean
* @since 1.0.0
*/
protected $loadClassHeaders = false;
/**
* The Views active with default ordering options
*
* @var array
* @since 1.0.0
*/
protected $activeViews = array();
/**
* The Target
*
* @var string
* @since 1.0.0
*/
protected $target = 'admin_view_headers';
/**
* The Targets
*
* @var array
* @since 1.0.0
*/
protected $targets
= array(
'add_admin_view_controller' => array(
'field' => 'admin_view_controller',
'context' => 'admin.view.controller',
'view' => 'name_single'
),
'add_admin_views_controller' => array(
'field' => 'admin_views_controller',
'context' => 'admin.views.controller',
'view' => 'name_list'
),
'add_admin_view_model' => array(
'field' => 'admin_view_model',
'context' => 'admin.view.model',
'view' => 'name_single'
),
'add_admin_views_model' => array(
'field' => 'admin_views_model',
'context' => 'admin.views.model',
'view' => 'name_list'
)
);
/**
* Event Triggered in the compiler [on Before Model View Data]
*
* @return void
*
* @since 1.0
*/
public function jcb_ce_onBeforeModelViewData(&$context, &$view,
&$placeholders
) {
// add the privacy
$view->params = (isset($view->params)
&& ComponentbuilderHelper::checkJson($view->params)) ? json_decode(
$view->params, true
) : $view->params;
if (ComponentbuilderHelper::checkArray($view->params)
&& isset($view->params[$this->target])
&& ComponentbuilderHelper::checkArray(
$view->params[$this->target]
))
{
foreach ($this->targets as $target => $event)
{
if (isset($view->params[$this->target][$target])
&& $view->params[$this->target][$target] == 1)
{
// activate the load of the privacy plugin
$this->loadClassHeaders = true;
// setup the view key name
$view_name = ComponentbuilderHelper::safeString(
$view->{$event['view']}
);
// load the admin view details
$this->activeViews[$view_name][$event['context']]
= $view->params[$this->target][$event['field']];
}
}
}
}
/**
* Event Triggered in the compiler [on set ClassHeader]
*
* @return void
*
* @since 1.0
*/
public function jcb_ce_setClassHeader(&$context, &$event_context,
&$view_name,
&$headers
) {
if ($this->loadClassHeaders && isset($this->activeViews[$view_name])
&& isset($this->activeViews[$view_name][$event_context]))
{
// we have default headers we actually need
foreach ($headers as $n => $header)
{
// we check if this header is also set from the user
if (strpos(
$this->activeViews[$view_name][$event_context], $header
) !== false)
{
// since it is set, remove it here
unset($headers[$n]);
}
}
// now add the custom headers
// yes they are below the defaults, unless overridden and remove above
$headers[] = $this->activeViews[$view_name][$event_context];
}
}
}

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" version="3.8" group="extension" method="upgrade">
<name>PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER</name>
<creationDate>8th December, 2020</creationDate>
<author>Llewellyn van der Merwe</author>
<authorEmail>llewellyn@joomlacomponentbuilder.com</authorEmail>
<authorUrl>http://www.joomlacomponentbuilder.com</authorUrl>
<copyright>Copyright (C) 2015 - 2020 Vast Development Method. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<version>1.0.0</version>
<description>PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_XML_DESCRIPTION</description>
<!-- Scripts to run on installation -->
<scriptfile>script.php</scriptfile>
<!-- Language files -->
<languages folder="language">
<language tag="en-GB">en-GB/en-GB.plg_extension_componentbuilderheaderscompiler.ini</language>
<language tag="en-GB">en-GB/en-GB.plg_extension_componentbuilderheaderscompiler.sys.ini</language>
</languages>
<!-- Plugin files -->
<files>
<filename plugin="componentbuilderheaderscompiler">componentbuilderheaderscompiler.php</filename>
<filename>index.html</filename>
<folder>language</folder>
</files>
</extension>

1
index.html Normal file
View File

@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

View File

@ -0,0 +1,7 @@
PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER="Extension - Componentbuilder Headers Compiler"
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 admin views where you would like to set Custom Headers."
PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_XML_DESCRIPTION="<h1>Extension - Componentbuilder Headers Compiler (v.1.0.0)</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 admin views where you would like to set Custom Headers.</p><p>Created by <a href='http://www.joomlacomponentbuilder.com' target='_blank'>Llewellyn van der Merwe</a><br /><small>Development started 24th May, 2020</small></p>"

View File

@ -0,0 +1,7 @@
PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER="Extension - Componentbuilder Headers Compiler"
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 admin views where you would like to set Custom Headers."
PLG_EXTENSION_COMPONENTBUILDERHEADERSCOMPILER_XML_DESCRIPTION="<h1>Extension - Componentbuilder Headers Compiler (v.1.0.0)</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 admin views where you would like to set Custom Headers.</p><p>Created by <a href='http://www.joomlacomponentbuilder.com' target='_blank'>Llewellyn van der Merwe</a><br /><small>Development started 24th May, 2020</small></p>"

View File

@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

1
language/index.html Normal file
View File

@ -0,0 +1 @@
<html><body bgcolor="#FFFFFF"></body></html>

79
script.php Normal file
View File

@ -0,0 +1,79 @@
<?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 - 2020 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');
/**
* Extension - Componentbuilder Headers Compiler script file.
*
* @package PlgExtensionComponentbuilderHeadersCompiler
*/
class plgExtensionComponentbuilderHeadersCompilerInstallerScript
{
/**
* Called before any type of action
*
* @param string $route Which action is happening (install|uninstall|discover_install|update)
* @param JAdapterInstance $adapter The object responsible for running this script
*
* @return boolean True on success
*/
public function preflight($route, JAdapterInstance $adapter)
{
// get application
$app = JFactory::getApplication();
// the default for both install and update
$jversion = new JVersion();
if (!$jversion->isCompatible('3.8.0'))
{
$app->enqueueMessage('Please upgrade to at least Joomla! 3.8.0 before continuing!', 'error');
return false;
}
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');
return false;
}
// load the helper class
JLoader::register('ComponentbuilderHelper', JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/componentbuilder.php');
// block install
$blockInstall = true;
// check the version of JCB
$manifest = ComponentbuilderHelper::manifest();
if (isset($manifest->version) && strpos($manifest->version, '.') !== false)
{
// get the version
$jcbVersion = explode('.', $manifest->version);
// check that we have JCB 2.11.7 or higher installed
if (count($jcbVersion) == 3 && $jcbVersion[0] >= 2 && $jcbVersion[1] >= 11 && (($jcbVersion[1] == 11 && $jcbVersion[2] >= 7) || ($jcbVersion[1] > 11)))
{
$blockInstall = false;
}
}
// allow install if all conditions are met
if ($blockInstall)
{
$app->enqueueMessage('Please upgrade to JCB 2.12.1 or higher before installing this plugin.', 'error');
return false;
}
}
return true;
}
}