2021-10-14 14:31:26 +00:00
< ? php
2021-12-16 13:15:27 +00:00
/**
* @ package Joomla . Component . Builder
*
* @ created 30 th April , 2015
* @ author Llewellyn van der Merwe < https :// dev . vdm . io >
2022-08-20 16:38:51 +00:00
* @ git Joomla Component Builder < https :// git . vdm . dev / joomla / Component - Builder >
2021-12-16 13:15:27 +00:00
* @ copyright Copyright ( C ) 2015 Vast Development Method . All rights reserved .
* @ license GNU General Public License version 2 or later ; see LICENSE . txt
2021-10-14 14:31:26 +00:00
*/
// No direct access to this file
defined ( '_JEXEC' ) or die ( 'Restricted access' );
use Joomla\CMS\Application\CMSApplication ;
2023-10-18 07:28:04 +00:00
use Joomla\CMS\Plugin\CMSPlugin ;
2024-03-11 14:14:23 +00:00
use VDM\Joomla\Componentbuilder\Compiler\Factory ;
use VDM\Joomla\Utilities\ArrayHelper ;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent ;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line ;
2021-10-14 14:31:26 +00:00
/**
* Extension - Componentbuilder Export Compiler plugin .
*
* @ package ComponentbuilderExportCompiler
2024-03-11 14:14:23 +00:00
* @ since 2.0 . 0
2021-10-14 14:31:26 +00:00
*/
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
*/
2024-03-02 20:06:24 +00:00
protected $languageArray = [];
2021-10-14 14:31:26 +00:00
/*
* The Export Text Only switch
*
* @ var int
*/
protected $exportTextOnly = 0 ;
/*
* The Strict Field Export Permissions switch
*
2024-03-02 20:06:24 +00:00
* @ var bool
2021-10-14 14:31:26 +00:00
*/
2024-03-02 20:06:24 +00:00
protected $strictFieldExportPermissions = false ;
2021-10-14 14:31:26 +00:00
/**
* Event Triggered in the compiler [ on Before Get Component Data ]
*
* @ return void
*
* @ since 1.0
*/
2024-03-02 20:06:24 +00:00
public function jcb_ce_onAfterGetComponentData ()
2021-10-14 14:31:26 +00:00
{
2024-03-02 20:06:24 +00:00
if ( $this -> exportTextOnly && $this -> componentActive ())
2021-10-14 14:31:26 +00:00
{
// activate export text only
2024-03-11 14:14:23 +00:00
Factory :: _ ( 'Config' ) -> set ( 'export_text_only' , ( int ) $this -> exportTextOnly );
2023-02-05 21:57:58 +00:00
2021-10-14 14:31:26 +00:00
// activate strict_permission_per_field if set in plugin (default true)
2024-03-11 14:14:23 +00:00
Factory :: _ ( 'Config' ) -> set ( 'permission_strict_per_field' , ( bool ) $this -> strictFieldExportPermissions );
2021-10-14 14:31:26 +00:00
}
}
/**
* Event Triggered in the compiler [ on After Model Component Data ]
*
* @ return void
*
* @ since 1.0
*/
2024-03-02 20:06:24 +00:00
public function jcb_ce_onAfterModelComponentData ( & $component )
2021-10-14 14:31:26 +00:00
{
// check if we have export for any view
2024-03-02 20:06:24 +00:00
if ( $this -> componentActive ())
2021-10-14 14:31:26 +00:00
{
// set the export/import option
2023-10-18 07:28:04 +00:00
if ( isset ( $component -> admin_views ) && ArrayHelper :: check ( $component -> admin_views ))
2021-10-14 14:31:26 +00:00
{
foreach ( $component -> admin_views as $view )
{
if ( ! $this -> exportTextOnly && ( isset ( $view [ 'port' ]) && $view [ 'port' ] || 1 == $view [ 'settings' ] -> add_custom_import ))
{
$this -> exportTextOnly = 1 ;
2024-03-02 20:06:24 +00:00
$this -> strictFieldExportPermissions = ( bool ) $this -> params -> get ( 'strict_permission_per_field' , 1 );
2021-10-14 14:31:26 +00:00
}
}
}
}
}
/**
* Event Triggered in the compiler [ on Before Set Lang File Data ]
*
* @ return void
*
* @ since 1.0
*/
2024-03-02 20:06:24 +00:00
public function jcb_ce_onBeforeSetLangFileData ()
2021-10-14 14:31:26 +00:00
{
2024-03-02 20:06:24 +00:00
if ( $this -> exportTextOnly && $this -> componentActive () && ArrayHelper :: check ( $this -> languageArray ))
2021-10-14 14:31:26 +00:00
{
foreach ( $this -> languageArray as $key => $string )
{
2024-03-11 14:14:23 +00:00
Factory :: _ ( 'Language' ) -> set ( 'adminsys' , $key , $string );
2021-10-14 14:31:26 +00:00
}
}
}
/**
* Event Triggered in the compiler [ on Before Set Config Field sets ]
*
* @ return void
*
* @ since 1.0
*/
2024-03-02 20:06:24 +00:00
public function jcb_ce_onBeforeSetConfigFieldsets ( & $timer )
2021-10-14 14:31:26 +00:00
{
// only add fields after second time
2024-03-02 20:06:24 +00:00
if ( $this -> exportTextOnly && $this -> componentActive () && $timer == 2 )
2021-10-14 14:31:26 +00:00
{
// main lang prefix
2024-03-11 14:14:23 +00:00
$lang = Factory :: _ ( 'Config' ) -> lang_prefix . '_CONFIG' ;
2021-10-14 14:31:26 +00:00
// start building field set for config
2024-03-11 14:14:23 +00:00
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 1 ) . " <fieldset " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 2 ) . 'name="export_text_only_config"' );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 2 ) . 'label="' . $lang . '_EXPORT_TEXT_ONLY_TAB_LABEL"' );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 2 ) . 'description="' . $lang . '_EXPORT_TEXT_ONLY_TAB_DESCRIPTION">' );
2021-10-14 14:31:26 +00:00
// setup lang
$this -> languageArray [ $lang . '_EXPORT_TEXT_ONLY_TAB_LABEL' ] = " Export Options " ;
2024-03-11 16:22:04 +00:00
$this -> languageArray [ $lang . '_EXPORT_TEXT_ONLY_TAB_DESCRIPTION' ] = " Here are some extra option to adjust the export behaviour of admin views. " ;
2021-10-14 14:31:26 +00:00
// add custom Export Options
2024-03-02 20:06:24 +00:00
if ( isset ( $configFieldSetsCustomField [ 'Export Options' ]) && ArrayHelper :: check ( $configFieldSetsCustomField [ 'Export Options' ]))
2021-10-14 14:31:26 +00:00
{
2024-03-11 16:22:04 +00:00
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , implode ( " " , $configFieldSetsCustomField [ 'Export Options' ]));
unset ( $configFieldSetsCustomField [ 'Export Options' ]);
2021-10-14 14:31:26 +00:00
}
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 " ;
2024-03-11 14:14:23 +00:00
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , PHP_EOL . Indent :: _ ( 2 ) . " <!-- " . Line :: _ ( __Line__ , __Class__ ) . " Export Text Only Field. Type: Radio. (joomla) --> " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 2 ) . " <field " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " type= \" radio \" " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " name= \" export_text_only \" " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " label= \" " . $lang . " _EXPORT_TEXT_ONLY_LABEL \" " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " description= \" " . $lang . " _EXPORT_TEXT_ONLY_DESCRIPTION \" " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " class= \" btn-group btn-group-yesno \" " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " default= \" 0 \" > " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " <!-- " . Line :: _ ( __Line__ , __Class__ ) . " Option Set. --> " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " <option value= \" 1 \" > " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 4 ) . $lang . " _ACTIVATE</option> " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " <option value= \" 0 \" > " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 4 ) . $lang . " _DEACTIVATE</option> " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 2 ) . " </field> " );
2021-10-14 14:31:26 +00:00
// 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. " ;
2024-03-11 14:14:23 +00:00
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , PHP_EOL . Indent :: _ ( 2 ) . " <!-- " . Line :: _ ( __Line__ , __Class__ ) . " Strict_permission_per_field Field. Type: Radio. (joomla) --> " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 2 ) . " <field " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " type= \" radio \" " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " name= \" strict_permission_per_field \" " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " label= \" " . $lang . " _STRICT_PERMISSION_PER_FIELD_LABEL \" " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " description= \" " . $lang . " _STRICT_PERMISSION_PER_FIELD_DESCRIPTION \" " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " class= \" btn-group btn-group-yesno \" " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " default= \" 1 \" > " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " <!-- " . Line :: _ ( __Line__ , __Class__ ) . " Option Set. --> " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " <option value= \" 1 \" > " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 4 ) . $lang . " _ACTIVATE</option> " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 3 ) . " <option value= \" 0 \" > " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 4 ) . $lang . " _DEACTIVATE</option> " );
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 2 ) . " </field> " );
2021-10-14 14:31:26 +00:00
}
}
// close that fieldset
2024-03-11 14:14:23 +00:00
Factory :: _ ( 'Compiler.Builder.Config.Fieldsets' ) -> add ( 'component' , Indent :: _ ( 1 ) . " </fieldset> " );
2021-10-14 14:31:26 +00:00
}
}
/**
* The array of active components
*
* @ var array
*/
protected $componentsActive ;
/**
* The activate option
*
* @ var int
*/
protected $activateOption = 0 ;
/**
* Set the line number in comments
*
* @ return bool
*
*/
2024-03-02 20:06:24 +00:00
protected function componentActive ()
2021-10-14 14:31:26 +00:00
{
// check the active option
if ( ! $this -> activateOption )
{
$this -> activateOption = $this -> params -> get ( 'activate_option' , 1 );
}
2021-10-14 14:31:33 +00:00
// active for all components
if ( $this -> activateOption == 1 )
2021-10-14 14:31:26 +00:00
{
return true ;
}
// first check is we have the active components set
2023-10-18 07:28:04 +00:00
if ( $this -> activateOption == 2 && ! ArrayHelper :: check ( $this -> componentsActive ))
2021-10-14 14:31:26 +00:00
{
$this -> componentsActive = $this -> params -> get ( 'components' );
}
// only check if there are active
2023-10-18 07:28:04 +00:00
if ( ArrayHelper :: check ( $this -> componentsActive ))
2021-10-14 14:31:26 +00:00
{
2024-03-11 14:14:23 +00:00
return in_array (( int ) Factory :: _ ( 'Config' ) -> component_id , $this -> componentsActive );
2021-10-14 14:31:26 +00:00
}
return false ;
}
}