52
0

first commit - v1.0.0

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

View File

@ -0,0 +1,324 @@
<?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;
JLoader::register('ComponentbuilderHelper', JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/componentbuilder.php');
/**
* Extension - Componentbuilder Export Compiler plugin.
*
* @package ComponentbuilderExportCompiler
* @since 1.0.0
*/
class PlgExtensionComponentbuilderExportCompiler extends CMSPlugin
{
/**
* Application object
*
* @var CMSApplication
* @since 1.0.0
*/
protected $app;
/**
* Affects constructor behavior. If true, language files will be loaded automatically.
*
* @var boolean
* @since 1.0.0
*/
protected $autoloadLanguage = true;
/**
* The language string builder
*
* @var array
*/
protected $languageArray = array();
/**
* The hash placeholder
*
* @var string
*/
protected $hhh = '#' . '#' . '#';
/**
* The open bracket placeholder
*
* @var string
*/
protected $bbb = '[' . '[' . '[';
/**
* The close bracket placeholder
*
* @var string
*/
protected $ddd = ']' . ']' . ']';
/**
* The line numbers Switch
*
* @var boolean
*/
protected $debugLinenr = false;
/*
* The lang prefix
*
* @var boolean
*/
protected $langPrefix;
/*
* The Export Text Only switch
*
* @var int
*/
protected $exportTextOnly = 0;
/*
* The Strict Field Export Permissions switch
*
* @var int
*/
protected $strictFieldExportPermissions = 0;
/**
* Event Triggered in the compiler [on Before Get Component Data]
*
* @return void
*
* @since 1.0
*/
public function jcb_ce_onAfterGetComponentData(&$context, $compiler)
{
if ($this->exportTextOnly && $this->componentActive($context))
{
// sync needed compiler properties with this plugin class
$this->debugLinenr = $compiler->debugLinenr;
$this->hhh = $compiler->hhh;
$this->bbb = $compiler->bbb;
$this->ddd = $compiler->ddd;
$this->langPrefix = $compiler->langPrefix;
// activate export text only
$compiler->exportTextOnly = $this->exportTextOnly;
// activate strict_permission_per_field if set in plugin (default true)
$compiler->strictFieldExportPermissions = $this->strictFieldExportPermissions;
}
}
/**
* Event Triggered in the compiler [on After Model Component Data]
*
* @return void
*
* @since 1.0
*/
public function jcb_ce_onAfterModelComponentData(&$context, &$component)
{
// check if we have export for any view
if ($this->componentActive($context))
{
// set the export/import option
if (isset($component->admin_views) && ComponentbuilderHelper::checkArray($component->admin_views))
{
foreach ($component->admin_views as $view)
{
if (!$this->exportTextOnly && (isset($view['port']) && $view['port'] || 1 == $view['settings']->add_custom_import))
{
$this->exportTextOnly = 1;
$this->strictFieldExportPermissions = $this->params->get('strict_permission_per_field', 1);
}
}
}
}
}
/**
* Event Triggered in the compiler [on Before Set Lang File Data]
*
* @return void
*
* @since 1.0
*/
public function jcb_ce_onBeforeSetLangFileData(&$context, $compiler)
{
if ($this->exportTextOnly && $this->componentActive($context) && ComponentbuilderHelper::checkArray($this->languageArray))
{
foreach($this->languageArray as $key => $string)
{
$compiler->setLangContent('adminsys', $key, $string);
}
}
}
/**
* Event Triggered in the compiler [on Before Set Config Field sets]
*
* @return void
*
* @since 1.0
*/
public function jcb_ce_onBeforeSetConfigFieldsets(&$context, &$timer, &$configFieldSets, &$configFieldSetsCustomField, &$componentDataConfig, &$extensionsParams, &$placeholders)
{
// only add fields after second time
if ($this->exportTextOnly && $this->componentActive($context) && $timer == 2)
{
// main lang prefix
$lang = $this->langPrefix . '_CONFIG';
// start building field set for config
$configFieldSets[] = $this->_t(1) . "<fieldset";
$configFieldSets[] = $this->_t(2) . 'name="export_text_only_config"';
$configFieldSets[] = $this->_t(2) . 'label="' . $lang . '_EXPORT_TEXT_ONLY_TAB_LABEL"';
$configFieldSets[] = $this->_t(2) . 'description="' . $lang . '_EXPORT_TEXT_ONLY_TAB_DESCRIPTION">';
// setup lang
$this->languageArray[$lang . '_EXPORT_TEXT_ONLY_TAB_LABEL'] = "Export Options";
$this->languageArray[$lang . '_EXPORT_TEXT_ONLY_TAB_DESCRIPTION'] = "Here are some extra option to adjust the export behavior of admin views.";
// add custom Export Options
if (isset($configFieldSetsCustomField['Export Options']) && ComponentbuilderHelper::checkArray($configFieldSetsCustomField['Export Options']))
{
$configFieldSets[] = implode("", $configFieldSetsCustomField['Export Options']);
unset($configFieldSetsCustomField['Export Options']);
}
else
{
$this->languageArray[$lang . '_EXPORT_TEXT_ONLY_LABEL'] = "Export Text Only";
$this->languageArray[$lang . '_EXPORT_TEXT_ONLY_DESCRIPTION'] = "This option enables the export of string/text instead of linked IDs in all admin views that have an export option.";
$this->languageArray[$lang . '_ACTIVATE'] = "Activate";
$this->languageArray[$lang . '_DEACTIVATE'] = "Deactivate";
$configFieldSets[] = PHP_EOL . $this->_t(2) . "<!--" . $this->setLine(__LINE__) . " Export Text Only Field. Type: Radio. (joomla) -->";
$configFieldSets[] = $this->_t(2) . "<field";
$configFieldSets[] = $this->_t(3) . "type=\"radio\"";
$configFieldSets[] = $this->_t(3) . "name=\"export_text_only\"";
$configFieldSets[] = $this->_t(3) . "label=\"" . $lang . "_EXPORT_TEXT_ONLY_LABEL\"";
$configFieldSets[] = $this->_t(3) . "description=\"" . $lang . "_EXPORT_TEXT_ONLY_DESCRIPTION\"";
$configFieldSets[] = $this->_t(3) . "class=\"btn-group btn-group-yesno\"";
$configFieldSets[] = $this->_t(3) . "default=\"0\">";
$configFieldSets[] = $this->_t(3) . "<!--" . $this->setLine(__LINE__) . " Option Set. -->";
$configFieldSets[] = $this->_t(3) . "<option value=\"1\">";
$configFieldSets[] = $this->_t(4) . $lang . "_ACTIVATE</option>";
$configFieldSets[] = $this->_t(3) . "<option value=\"0\">";
$configFieldSets[] = $this->_t(4) . $lang . "_DEACTIVATE</option>";
$configFieldSets[] = $this->_t(2) . "</field>";
// add strict Field Export Permissions field
if ($this->strictFieldExportPermissions)
{
$this->languageArray[$lang . '_STRICT_PERMISSION_PER_FIELD_LABEL'] = "Use Strict Permission per/field";
$this->languageArray[$lang . '_STRICT_PERMISSION_PER_FIELD_DESCRIPTION'] = "Use strict permissions per/field in the export methods where there are fields permissions in a view.";
$configFieldSets[] = PHP_EOL . $this->_t(2) . "<!--" . $this->setLine(__LINE__) . " Strict_permission_per_field Field. Type: Radio. (joomla) -->";
$configFieldSets[] = $this->_t(2) . "<field";
$configFieldSets[] = $this->_t(3) . "type=\"radio\"";
$configFieldSets[] = $this->_t(3) . "name=\"strict_permission_per_field\"";
$configFieldSets[] = $this->_t(3) . "label=\"" . $lang . "_STRICT_PERMISSION_PER_FIELD_LABEL\"";
$configFieldSets[] = $this->_t(3) . "description=\"" . $lang . "_STRICT_PERMISSION_PER_FIELD_DESCRIPTION\"";
$configFieldSets[] = $this->_t(3) . "class=\"btn-group btn-group-yesno\"";
$configFieldSets[] = $this->_t(3) . "default=\"1\">";
$configFieldSets[] = $this->_t(3) . "<!--" . $this->setLine(__LINE__) . " Option Set. -->";
$configFieldSets[] = $this->_t(3) . "<option value=\"1\">";
$configFieldSets[] = $this->_t(4) . $lang . "_ACTIVATE</option>";
$configFieldSets[] = $this->_t(3) . "<option value=\"0\">";
$configFieldSets[] = $this->_t(4) . $lang . "_DEACTIVATE</option>";
$configFieldSets[] = $this->_t(2) . "</field>";
}
}
// close that fieldset
$configFieldSets[] = $this->_t(1) . "</fieldset>";
}
}
/**
* Set the line number in comments
*
* @param int $nr The line number
*
* @return void
*
*/
protected function setLine($nr)
{
if ($this->debugLinenr)
{
return ' [Plugin-Privacy-Compiler ' . $nr . ']';
}
return '';
}
/**
* Set the tab/space
*
* @param int $nr The number of tag/space
*
* @return string
*
*/
protected function _t($nr)
{
// use global method for conformity
return ComponentbuilderHelper::_t($nr);
}
/**
* The array of active components
*
* @var array
*/
protected $componentsActive;
/**
* The activate option
*
* @var int
*/
protected $activateOption = 0;
/**
* Set the line number in comments
*
* @param string $context The context of the current executing component
*
* @return bool
*
*/
protected function componentActive(&$context)
{
// check the active option
if (!$this->activateOption)
{
$this->activateOption = $this->params->get('activate_option', 1);
}
elseif ($this->activateOption == 1)
{
return true;
}
// first check is we have the active components set
if ($this->activateOption == 2 && !ComponentbuilderHelper::checkArray($this->componentsActive))
{
$this->componentsActive = $this->params->get('components');
}
// only check if there are active
if (ComponentbuilderHelper::checkArray($this->componentsActive))
{
return in_array((int) filter_var($context, FILTER_SANITIZE_NUMBER_INT), $this->componentsActive);
}
return false;
}
}

View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" version="3.8" group="extension" method="upgrade">
<name>PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER</name>
<creationDate>3rd April, 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_COMPONENTBUILDEREXPORTCOMPILER_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_componentbuilderexportcompiler.ini</language>
<language tag="en-GB">en-GB/en-GB.plg_extension_componentbuilderexportcompiler.sys.ini</language>
</languages>
<!-- Plugin files -->
<files>
<filename plugin="componentbuilderexportcompiler">componentbuilderexportcompiler.php</filename>
<filename>index.html</filename>
<folder>language</folder>
</files>
<!-- Config parameter -->
<config
addrulepath="/administrator/components/com_componentbuilder/models/rules"
addfieldpath="/administrator/components/com_componentbuilder/models/fields"
>
<fields name="params">
<fieldset name="basic" label="PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_SETTINGS">
<!-- Activate_option Field. Type: Radio. (joomla) -->
<field
type="radio"
name="activate_option"
label="PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_ACTIVATE_OPTION_LABEL"
description="PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_ACTIVATE_OPTION_DESCRIPTION"
class="btn-group btn-group-yesno"
default="1"
required="true">
<!-- Option Set. -->
<option value="1">
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_ALL</option>
<option value="2">
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_SELECTED</option>
</field>
<!-- Components Field. Type: Components. (custom) -->
<field
type="components"
name="components"
label="PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_COMPONENTS_LABEL"
description="PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_COMPONENTS_DESCRIPTION"
class="list_class"
multiple="true"
default="0"
showon="activate_option:2"
button="false"
/>
<!-- Strict_permission_per_field Field. Type: Radio. (joomla) -->
<field
type="radio"
name="strict_permission_per_field"
label="PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_STRICT_PERMISSION_PER_FIELD_LABEL"
description="PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_STRICT_PERMISSION_PER_FIELD_DESCRIPTION"
class="btn-group btn-group-yesno"
default="1">
<!-- Option Set. -->
<option value="0">
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_NO</option>
<option value="1">
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_YES</option>
</field>
</fieldset>
</fields>
</config>
</extension>

1
index.html Normal file
View File

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

View File

@ -0,0 +1,16 @@
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER="Extension - Componentbuilder Export Compiler"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_DESCRIPTION="This plugin is used to tweak the export options for your components 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 activate the component/s that should be targeted with this added export feature under the Component Activation tab."
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_XML_DESCRIPTION="<h1>Extension - Componentbuilder Export Compiler (v.1.0.0)</h1> <div style='clear: both;'></div><p>This plugin is used to tweak the export options for your components 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 activate the component/s that should be targeted with this added export feature under the Component Activation tab.</p><p>Created by <a href='http://www.joomlacomponentbuilder.com' target='_blank'>Llewellyn van der Merwe</a><br /><small>Development started 21st August, 2019</small></p>"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_SETTINGS="Settings"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_ACTIVATE_OPTION_LABEL="Activate Options"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_ACTIVATE_OPTION_DESCRIPTION="You can select the kind of activation control you would like to use. <b>All</b> will target all components, and <b>Selected</b> will let you select only those you want to be active."
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_ALL="All"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_SELECTED="Selected"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_COMPONENTS_LABEL="Components"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_COMPONENTS_DESCRIPTION="Select the components you would like to be targeted."
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_STRICT_PERMISSION_PER_FIELD_LABEL="Add Strict Permission per/field"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_STRICT_PERMISSION_PER_FIELD_DESCRIPTION="You can add strict permissions per/field in the export method where there is field permissions in a view."
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_NO="No"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_YES="Yes"

View File

@ -0,0 +1,16 @@
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER="Extension - Componentbuilder Export Compiler"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_DESCRIPTION="This plugin is used to tweak the export options for your components 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 activate the component/s that should be targeted with this added export feature under the Component Activation tab."
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_XML_DESCRIPTION="<h1>Extension - Componentbuilder Export Compiler (v.1.0.0)</h1> <div style='clear: both;'></div><p>This plugin is used to tweak the export options for your components 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 activate the component/s that should be targeted with this added export feature under the Component Activation tab.</p><p>Created by <a href='http://www.joomlacomponentbuilder.com' target='_blank'>Llewellyn van der Merwe</a><br /><small>Development started 21st August, 2019</small></p>"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_SETTINGS="Settings"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_ACTIVATE_OPTION_LABEL="Activate Options"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_ACTIVATE_OPTION_DESCRIPTION="You can select the kind of activation control you would like to use. <b>All</b> will target all components, and <b>Selected</b> will let you select only those you want to be active."
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_ALL="All"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_SELECTED="Selected"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_COMPONENTS_LABEL="Components"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_COMPONENTS_DESCRIPTION="Select the components you would like to be targeted."
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_STRICT_PERMISSION_PER_FIELD_LABEL="Add Strict Permission per/field"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_STRICT_PERMISSION_PER_FIELD_DESCRIPTION="You can add strict permissions per/field in the export method where there is field permissions in a view."
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_NO="No"
PLG_EXTENSION_COMPONENTBUILDEREXPORTCOMPILER_YES="Yes"

57
script.php Normal file
View File

@ -0,0 +1,57 @@
<?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 Export Compiler script file.
*
* @package PlgExtensionComponentbuilderExportCompiler
*/
class plgExtensionComponentbuilderExportCompilerInstallerScript
{
/**
* 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;
}
}
return true;
}
}