2016-01-30 20:28:43 +00:00
< ? php
2021-03-05 03:08:47 +00:00
/**
* @ package Joomla . Component . Builder
*
* @ created 30 th April , 2015
2022-07-09 15:45:08 +00:00
* @ author Llewellyn van der Merwe < https :// dev . vdm . io >
* @ git Joomla Component Builder < https :// git . vdm . dev / joomla / Component - Builder >
2021-03-05 03:08:47 +00:00
* @ copyright Copyright ( C ) 2015 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' );
2024-03-02 20:10:30 +00:00
use Joomla\CMS\Factory ;
use Joomla\CMS\Language\Text ;
use Joomla\CMS\Component\ComponentHelper ;
2022-05-25 08:30:55 +00:00
use Joomla\CMS\MVC\Model\ListModel ;
2024-03-02 20:10:30 +00:00
use Joomla\CMS\Plugin\PluginHelper ;
2021-03-05 03:08:47 +00:00
use Joomla\Utilities\ArrayHelper ;
2024-03-02 20:10:30 +00:00
use Joomla\CMS\Helper\TagsHelper ;
2022-12-04 09:23:43 +00:00
use VDM\Joomla\Componentbuilder\Package\Factory as PackageFactory ;
2023-02-27 12:27:41 +00:00
use VDM\Joomla\Utilities\FileHelper ;
use VDM\Joomla\Utilities\ObjectHelper ;
use VDM\Joomla\Utilities\GetHelper ;
use VDM\Joomla\Utilities\JsonHelper ;
2023-10-18 07:26:30 +00:00
use VDM\Joomla\Utilities\Base64Helper ;
2024-03-02 20:10:30 +00:00
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper ;
use VDM\Joomla\Utilities\StringHelper ;
2023-10-18 07:26:30 +00:00
use VDM\Joomla\FOF\Encrypt\AES ;
2021-03-05 03:08:47 +00:00
/**
2022-05-25 08:30:55 +00:00
* Joomla_components List Model
2021-03-05 03:08:47 +00:00
*/
2022-05-25 08:30:55 +00:00
class ComponentbuilderModelJoomla_components extends ListModel
2021-03-05 03:08:47 +00:00
{
2024-03-02 20:10:30 +00:00
public function __construct ( $config = [])
2021-03-05 03:08:47 +00:00
{
if ( empty ( $config [ 'filter_fields' ]))
2024-03-02 20:10:30 +00:00
{
2021-03-05 03:08:47 +00:00
$config [ 'filter_fields' ] = array (
2016-01-30 20:28:43 +00:00
'a.id' , 'id' ,
'a.published' , 'published' ,
2020-12-03 00:13:49 +00:00
'a.access' , 'access' ,
2016-01-30 20:28:43 +00:00
'a.ordering' , 'ordering' ,
'a.created_by' , 'created_by' ,
'a.modified_by' , 'modified_by' ,
2020-11-21 06:01:26 +00:00
'a.companyname' , 'companyname' ,
'a.author' , 'author' ,
2016-01-30 20:28:43 +00:00
'a.system_name' , 'system_name' ,
'a.name_code' , 'name_code' ,
2021-01-30 13:36:03 +00:00
'a.short_description' , 'short_description' ,
'a.created' , 'created' ,
2021-03-05 03:08:47 +00:00
'a.modified' , 'modified'
);
}
parent :: __construct ( $config );
2017-03-18 11:16:07 +00:00
}
2017-08-20 17:52:35 +00:00
public $user ;
2017-12-25 12:46:35 +00:00
public $packagePath = false ;
public $packageName = false ;
public $zipPath = false ;
public $key = array ();
public $exportBuyLinks = array ();
2018-05-05 14:47:48 +00:00
public $joomlaSourceLinks = array ();
2017-12-25 12:46:35 +00:00
public $info = array (
'name' => array (),
'short_description' => array (),
'component_version' => array (),
'companyname' => array (),
'author' => array (),
'email' => array (),
'website' => array (),
'license' => array (),
'copyright' => array (),
'getKeyFrom' => null
);
public $activeType = 'export' ;
2018-05-29 04:59:08 +00:00
public $backupType = 1 ;
2017-03-18 22:55:34 +00:00
2017-03-20 22:07:14 +00:00
protected $params ;
protected $tempPath ;
protected $customPath ;
2018-04-17 21:25:03 +00:00
protected $smartBox = array ();
protected $smartIDs = array ();
2017-12-25 12:46:35 +00:00
protected $customCodeM = array ();
2019-03-04 12:47:28 +00:00
protected $placeholderM = array ();
protected $placeholderS = array ();
2017-12-25 12:46:35 +00:00
protected $fieldTypes = array ();
protected $isMultiple = array ();
2017-03-18 20:17:15 +00:00
2018-04-17 21:25:03 +00:00
/**
* Method to clone the component
*
* @ return bool on success .
*/
public function cloner ( $pks )
{
// get the components
if ( $items = $this -> getComponents ( $pks ))
{
// update $pks with returned IDs
$pks = array ();
// start loading the components
$this -> smartBox [ 'joomla_component' ] = array ();
foreach ( $items as $nr => & $item )
{
// check if user has access
$access = ( $this -> user -> authorise ( 'joomla_component.access' , 'com_componentbuilder.joomla_component.' . ( int ) $item -> id ) && $this -> user -> authorise ( 'joomla_component.access' , 'com_componentbuilder' ));
if ( ! $access )
{
unset ( $items [ $nr ]);
continue ;
}
// make sure old fields are not exported any more
$this -> removeOldComponentValues ( $item );
// load to global object
$this -> smartBox [ 'joomla_component' ][ $item -> id ] = $item ;
2022-05-16 04:25:03 +00:00
// set the powers linked to this joomla component
$this -> setSmartIDs ( $this -> getValues ( $item -> params , 'power' , 'joomla_component_headers' , null ), 'power' , false );
2018-04-17 21:25:03 +00:00
// add to pks
$pks [] = $item -> id ;
}
// has any data been set for this component
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $pks ))
2018-04-17 21:25:03 +00:00
{
// load the linked stuff
$this -> getLinkedToComponents ( $pks );
}
// has any data been set for this component
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartBox [ 'joomla_component' ]) && JCBArrayHelper :: check ( $this -> smartBox [ 'joomla_component' ]))
2018-04-17 21:25:03 +00:00
{
// set the folder and move the files of each component to the folder
return $this -> smartCloner ();
}
}
return false ;
}
2017-03-18 11:16:07 +00:00
/**
2017-03-20 22:07:14 +00:00
* Method to build the export package
2017-03-18 11:16:07 +00:00
*
2017-03-20 22:07:14 +00:00
* @ return bool on success .
2017-03-18 11:16:07 +00:00
*/
public function getSmartExport ( $pks )
2018-04-17 21:25:03 +00:00
{
// get the components
if ( $items = $this -> getComponents ( $pks ))
{
// set custom folder path
$this -> customPath = $this -> params -> get ( 'custom_folder_path' , JPATH_COMPONENT_ADMINISTRATOR . '/custom' );
2020-03-13 02:45:08 +00:00
// set the backup paths
2024-03-02 20:10:30 +00:00
$comConfig = Factory :: getConfig ();
2020-03-13 02:45:08 +00:00
$this -> backupPath = $comConfig -> get ( 'tmp_path' );
2018-04-17 21:25:03 +00:00
// check what type of export or backup this is
if ( 'backup' === $this -> activeType || 'manualBackup' === $this -> activeType )
{
2020-03-13 02:45:08 +00:00
// set the zip path
$this -> zipPath = $this -> params -> get ( 'cronjob_backup_folder_path' , $this -> backupPath );
2018-04-17 21:25:03 +00:00
// check what backup type we are working with here
$this -> backupType = $this -> params -> get ( 'cronjob_backup_type' , 1 ); // 1 = local folder; 2 = remote server (default is local)
// if remote server get the ID
if ( 2 == $this -> backupType )
{
$this -> backupServer = $this -> params -> get ( 'cronjob_backup_server' , null );
}
// set the date array
2024-03-02 20:10:30 +00:00
$date = Factory :: getDate ();
2018-04-17 21:25:03 +00:00
$placeholderDate = array ();
$placeholderDate [ '[YEAR]' ] = $date -> format ( 'Y' );
$placeholderDate [ '[MONTH]' ] = $date -> format ( 'm' );
$placeholderDate [ '[DAY]' ] = $date -> format ( 'd' );
$placeholderDate [ '[HOUR]' ] = $date -> format ( 'H' );
$placeholderDate [ '[MINUTE]' ] = $date -> format ( 'i' );
// get the package name
$packageName = $this -> params -> get ( 'backup_package_name' , 'JCB_Backup_[YEAR]_[MONTH]_[DAY]' );
$this -> packageName = str_replace ( array_keys ( $placeholderDate ), array_values ( $placeholderDate ), $packageName );
}
else
{
2020-03-13 02:45:08 +00:00
// set the zip path
$this -> zipPath = $this -> backupPath ;
2018-04-17 21:25:03 +00:00
// set the package name
if ( count ( $items ) == 1 )
{
$this -> packageName = 'JCB_' . $this -> getPackageName ( $items );
}
else
{
$this -> packageName = 'JCB_smartPackage' ;
}
}
2023-02-27 12:27:41 +00:00
2018-04-17 21:25:03 +00:00
// set the package path
$this -> packagePath = rtrim ( $this -> backupPath , '/' ) . '/' . $this -> packageName ;
2020-03-13 02:45:08 +00:00
$this -> zipPath = rtrim ( $this -> zipPath , '/' ) . '/' . $this -> packageName . '.zip' ;
2023-02-27 12:27:41 +00:00
if ( FileHelper :: exists ( $this -> packagePath ))
2018-04-17 21:25:03 +00:00
{
// remove if old folder is found
ComponentbuilderHelper :: removeFolder ( $this -> packagePath );
}
2023-02-27 12:27:41 +00:00
2018-04-17 21:25:03 +00:00
// create the folders
JFolder :: create ( $this -> packagePath );
2023-02-27 12:27:41 +00:00
2018-04-17 21:25:03 +00:00
// update $pks with returned IDs
$pks = array ();
2023-02-27 12:27:41 +00:00
2018-04-17 21:25:03 +00:00
// start loading the components
$this -> smartBox [ 'joomla_component' ] = array ();
foreach ( $items as $nr => & $item )
{
// check if user has access
$access = ( $this -> user -> authorise ( 'joomla_component.access' , 'com_componentbuilder.joomla_component.' . ( int ) $item -> id ) && $this -> user -> authorise ( 'joomla_component.access' , 'com_componentbuilder' ));
if ( ! $access )
{
unset ( $items [ $nr ]);
continue ;
}
2023-02-27 12:27:41 +00:00
2018-04-17 21:25:03 +00:00
// make sure old fields are not exported any more
$this -> removeOldComponentValues ( $item );
2023-02-27 12:27:41 +00:00
2018-04-17 21:25:03 +00:00
// build information data set
$this -> info [ 'name' ][ $item -> id ] = $item -> name ;
$this -> info [ 'short_description' ][ $item -> id ] = $item -> short_description ;
$this -> info [ 'component_version' ][ $item -> id ] = $item -> component_version ;
$this -> info [ 'companyname' ][ $item -> id ] = $item -> companyname ;
$this -> info [ 'author' ][ $item -> id ] = $item -> author ;
$this -> info [ 'email' ][ $item -> id ] = $item -> email ;
$this -> info [ 'website' ][ $item -> id ] = $item -> website ;
$this -> info [ 'license' ][ $item -> id ] = $item -> license ;
$this -> info [ 'copyright' ][ $item -> id ] = $item -> copyright ;
2023-02-27 12:27:41 +00:00
2018-04-17 21:25:03 +00:00
// set the keys
2023-02-27 12:27:41 +00:00
if ( isset ( $item -> export_key ) && StringHelper :: check ( $item -> export_key ))
2018-04-17 21:25:03 +00:00
{
// keep the key locked for exported data set
$export_key = $item -> export_key ;
2023-02-27 12:27:41 +00:00
if ( ! is_numeric ( $item -> export_key ) && $item -> export_key === base64_encode ( base64_decode ( $item -> export_key , true )))
2018-04-17 21:25:03 +00:00
{
2023-02-27 12:27:41 +00:00
$export_key = PackageFactory :: _ ( 'Crypt' ) -> decrypt ( $item -> export_key , 'basic' );
2018-04-17 21:25:03 +00:00
}
// make sure we have a string
if ( strlen ( $export_key ) > 4 )
{
$this -> key [ $item -> id ] = $export_key ;
}
}
2023-02-27 12:27:41 +00:00
2018-04-17 21:25:03 +00:00
// get name of this item key_name
if ( isset ( $item -> system_name ))
{
2023-02-27 12:27:41 +00:00
$keyName = StringHelper :: safe ( $item -> system_name , 'cAmel' );
2018-04-17 21:25:03 +00:00
}
else
{
2023-02-27 12:27:41 +00:00
$keyName = StringHelper :: safe ( $item -> name_code );
2018-04-17 21:25:03 +00:00
}
2023-02-27 12:27:41 +00:00
2018-04-17 21:25:03 +00:00
// set the export buy links
2023-02-27 12:27:41 +00:00
if ( isset ( $item -> export_buy_link ) && StringHelper :: check ( $item -> export_buy_link ))
2018-04-17 21:25:03 +00:00
{
2018-05-05 14:47:48 +00:00
// set the export buy link
$this -> info [ 'export_buy_link' ][ $item -> id ] = $item -> export_buy_link ;
2018-04-17 21:25:03 +00:00
}
2023-02-27 12:27:41 +00:00
2018-04-17 21:25:03 +00:00
// set the export buy links
2023-02-27 12:27:41 +00:00
if ( isset ( $item -> joomla_source_link ) && StringHelper :: check ( $item -> joomla_source_link ))
2018-04-17 21:25:03 +00:00
{
2018-05-05 14:47:48 +00:00
// set the source link
$this -> info [ 'joomla_source_link' ][ $item -> id ] = $item -> joomla_source_link ;
2018-04-17 21:25:03 +00:00
}
2023-02-27 12:27:41 +00:00
2018-04-17 21:25:03 +00:00
// component image
$this -> moveIt ( array ( $item -> image ), 'image' );
// set the custom code ID's
2019-03-04 12:47:28 +00:00
$this -> setCodePlaceholdersIds ( $item , 'joomla_component' );
// set the placeholder ID's
$this -> setCodePlaceholdersIds ( $item , 'joomla_component' , 'placeholder' );
2018-04-17 21:25:03 +00:00
// set the language strings for this component
$this -> setLanguageTranslation ( $item -> id );
// load to global object
$this -> smartBox [ 'joomla_component' ][ $item -> id ] = $item ;
2022-05-16 04:25:03 +00:00
// set the powers linked to this joomla component
$this -> setSmartIDs ( $this -> getValues ( $item -> params , 'power' , 'joomla_component_headers' , null ), 'power' , false );
2018-04-17 21:25:03 +00:00
// add to pks
$pks [] = $item -> id ;
}
// has any data been set for this component
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $pks ))
2018-04-17 21:25:03 +00:00
{
// load the linked stuff
$this -> getLinkedToComponents ( $pks );
}
// has any data been set for this component
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartBox [ 'joomla_component' ]) && JCBArrayHelper :: check ( $this -> smartBox [ 'joomla_component' ]))
2018-04-17 21:25:03 +00:00
{
// set the folder and move the files of each component to the folder
return $this -> smartExportBuilder ();
}
}
return false ;
}
/**
* Get Everything Linked to Components
*
* @ return void
*/
protected function getLinkedToComponents ( $pks )
{
// array of tables linked to joomla_component
$linkedTables = array (
'custom_code' => 'component' ,
'component_files_folders' => 'joomla_component' ,
'component_admin_views' => 'joomla_component' ,
'component_config' => 'joomla_component' ,
'component_site_views' => 'joomla_component' ,
'component_custom_admin_views' => 'joomla_component' ,
'component_updates' => 'joomla_component' ,
'component_mysql_tweaks' => 'joomla_component' ,
'component_custom_admin_menus' => 'joomla_component' ,
2019-02-15 22:03:21 +00:00
'component_dashboard' => 'joomla_component' ,
2019-08-12 21:30:31 +00:00
'component_placeholders' => 'joomla_component' ,
2019-12-07 01:39:16 +00:00
'component_modules' => 'joomla_component' ,
2019-08-12 21:30:31 +00:00
'component_plugins' => 'joomla_component' );
2018-04-17 21:25:03 +00:00
// load all tables linked to joomla_component
foreach ( $linkedTables as $table => $field )
{
$this -> setData ( $table , $pks , $field );
}
2018-05-26 10:03:08 +00:00
// add fields conditions and relations
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'admin_view' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'admin_view' ]))
2018-04-17 21:25:03 +00:00
{
$this -> setData ( 'admin_fields' , array_values ( $this -> smartIDs [ 'admin_view' ]), 'admin_view' );
$this -> setData ( 'admin_fields_conditions' , array_values ( $this -> smartIDs [ 'admin_view' ]), 'admin_view' );
2018-05-26 10:03:08 +00:00
$this -> setData ( 'admin_fields_relations' , array_values ( $this -> smartIDs [ 'admin_view' ]), 'admin_view' );
2018-08-24 21:46:41 +00:00
$this -> setData ( 'admin_custom_tabs' , array_values ( $this -> smartIDs [ 'admin_view' ]), 'admin_view' );
2018-04-17 21:25:03 +00:00
}
2019-12-07 01:39:16 +00:00
// add joomla module
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'joomla_module' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'joomla_module' ]))
2019-12-07 01:39:16 +00:00
{
$this -> setData ( 'joomla_module' , array_values ( $this -> smartIDs [ 'joomla_module' ]), 'id' );
$this -> setData ( 'joomla_module_updates' , array_values ( $this -> smartIDs [ 'joomla_module' ]), 'joomla_module' );
$this -> setData ( 'joomla_module_files_folders_urls' , array_values ( $this -> smartIDs [ 'joomla_module' ]), 'joomla_module' );
}
2019-08-12 21:30:31 +00:00
// add joomla plugin
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'joomla_plugin' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'joomla_plugin' ]))
2019-08-12 21:30:31 +00:00
{
$this -> setData ( 'joomla_plugin' , array_values ( $this -> smartIDs [ 'joomla_plugin' ]), 'id' );
$this -> setData ( 'joomla_plugin_updates' , array_values ( $this -> smartIDs [ 'joomla_plugin' ]), 'joomla_plugin' );
$this -> setData ( 'joomla_plugin_files_folders_urls' , array_values ( $this -> smartIDs [ 'joomla_plugin' ]), 'joomla_plugin' );
}
2018-04-17 21:25:03 +00:00
// add validation rules
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'validation_rule' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'validation_rule' ]))
2018-04-17 21:25:03 +00:00
{
$this -> setData ( 'validation_rule' , array_values ( $this -> smartIDs [ 'validation_rule' ]), 'name' );
}
// add field types
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'fieldtype' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'fieldtype' ]))
2018-04-17 21:25:03 +00:00
{
$this -> setData ( 'fieldtype' , array_values ( $this -> smartIDs [ 'fieldtype' ]), 'id' );
}
// add templates
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'template' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'template' ]))
2018-04-17 21:25:03 +00:00
{
$this -> setData ( 'template' , array_values ( $this -> smartIDs [ 'template' ]), 'id' );
}
// add layouts
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'layout' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'layout' ]))
2018-04-17 21:25:03 +00:00
{
$this -> setData ( 'layout' , array_values ( $this -> smartIDs [ 'layout' ]), 'id' );
}
// add dynamic get
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'dynamic_get' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'dynamic_get' ]))
2018-04-17 21:25:03 +00:00
{
$this -> setData ( 'dynamic_get' , array_values ( $this -> smartIDs [ 'dynamic_get' ]), 'id' );
}
// only if exporting
if ( 'clone' !== $this -> activeType )
{
2019-08-12 21:30:31 +00:00
// add class_property
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'class_property' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'class_property' ]))
2019-08-12 21:30:31 +00:00
{
$this -> setData ( 'class_property' , array_values ( $this -> smartIDs [ 'class_property' ]), 'id' );
}
// add class_method
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'class_method' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'class_method' ]))
2019-08-12 21:30:31 +00:00
{
$this -> setData ( 'class_method' , array_values ( $this -> smartIDs [ 'class_method' ]), 'id' );
}
// add joomla_plugin_group
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'joomla_plugin_group' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'joomla_plugin_group' ]))
2019-08-12 21:30:31 +00:00
{
$this -> setData ( 'joomla_plugin_group' , array_values ( $this -> smartIDs [ 'joomla_plugin_group' ]), 'id' );
}
// add class_extends
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'class_extends' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'class_extends' ]))
2019-08-12 21:30:31 +00:00
{
$this -> setData ( 'class_extends' , array_values ( $this -> smartIDs [ 'class_extends' ]), 'id' );
}
2018-04-17 21:25:03 +00:00
// add snippets
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'snippet' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'snippet' ]))
2018-04-17 21:25:03 +00:00
{
$this -> setData ( 'snippet' , array_values ( $this -> smartIDs [ 'snippet' ]), 'id' );
}
// add custom code
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'custom_code' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'custom_code' ]))
2018-04-17 21:25:03 +00:00
{
$this -> setData ( 'custom_code' , array_values ( $this -> smartIDs [ 'custom_code' ]), 'id' );
}
2019-03-04 12:47:28 +00:00
// add placeholder
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'placeholder' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'placeholder' ]))
2019-03-04 12:47:28 +00:00
{
$this -> setData ( 'placeholder' , array_values ( $this -> smartIDs [ 'placeholder' ]), 'id' );
}
2021-12-21 14:44:50 +00:00
// add powers
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'power' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'power' ]))
2021-12-21 14:44:50 +00:00
{
2022-05-16 04:25:03 +00:00
$this -> setData ( 'power' , array_values ( $this -> smartIDs [ 'power' ]), 'guid' );
2021-12-21 14:44:50 +00:00
}
2018-12-29 14:56:06 +00:00
// set limiter
$limit = 0 ;
// and add those custom codes found in custom codes
2023-02-27 12:27:41 +00:00
while ( isset ( $this -> smartIDs [ 'custom_code' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'custom_code' ]) && $limit < 100 )
2018-12-29 14:56:06 +00:00
{
$this -> setData ( 'custom_code' , array_values ( $this -> smartIDs [ 'custom_code' ]), 'id' );
// make sure we break
$limit ++ ; // just in case (should not be needed)
}
2018-04-17 21:25:03 +00:00
}
}
/**
* Get Components
*
* @ return array of objects .
*/
protected function getComponents ( $pks )
2017-03-18 11:16:07 +00:00
{
// setup the query
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $pks ))
2017-03-18 11:16:07 +00:00
{
// Get the user object.
2023-02-27 12:27:41 +00:00
if ( ! ObjectHelper :: check ( $this -> user ))
2017-08-20 17:52:35 +00:00
{
2024-03-02 20:10:30 +00:00
$this -> user = Factory :: getUser ();
2017-08-20 17:52:35 +00:00
}
2017-03-18 11:16:07 +00:00
// Create a new query object.
2023-02-27 12:27:41 +00:00
if ( ! ObjectHelper :: check ( $this -> _db ))
2017-08-20 17:52:35 +00:00
{
2024-03-02 20:10:30 +00:00
$this -> _db = Factory :: getDBO ();
2017-08-20 17:52:35 +00:00
}
$query = $this -> _db -> getQuery ( true );
2017-03-18 11:16:07 +00:00
// Select some fields
2017-04-05 13:21:10 +00:00
$query -> select ( array ( 'a.*' ));
2017-03-18 11:16:07 +00:00
2017-03-18 22:55:34 +00:00
// From the componentbuilder_joomla_component table
2017-08-20 17:52:35 +00:00
$query -> from ( $this -> _db -> quoteName ( '#__componentbuilder_joomla_component' , 'a' ));
2017-03-18 11:16:07 +00:00
$query -> where ( 'a.id IN (' . implode ( ',' , $pks ) . ')' );
// Implement View Level Access
2017-08-20 17:52:35 +00:00
if ( ! $this -> user -> authorise ( 'core.options' , 'com_componentbuilder' ))
2017-03-18 11:16:07 +00:00
{
2017-08-20 17:52:35 +00:00
$groups = implode ( ',' , $this -> user -> getAuthorisedViewLevels ());
2017-03-18 11:16:07 +00:00
$query -> where ( 'a.access IN (' . $groups . ')' );
}
// Order the results by ordering
$query -> order ( 'a.ordering ASC' );
// Load the items
2017-08-20 17:52:35 +00:00
$this -> _db -> setQuery ( $query );
$this -> _db -> execute ();
if ( $this -> _db -> getNumRows ())
2017-03-18 11:16:07 +00:00
{
2017-03-20 22:07:14 +00:00
// load the items from db
2017-08-20 17:52:35 +00:00
$items = $this -> _db -> loadObjectList ();
2017-03-18 20:17:15 +00:00
// check if we have items
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $items ))
2017-03-18 11:16:07 +00:00
{
2017-03-30 21:19:12 +00:00
// set params
2023-02-27 12:27:41 +00:00
if ( ! ObjectHelper :: check ( $this -> params ))
2018-02-20 20:46:29 +00:00
{
2024-03-02 20:10:30 +00:00
$this -> params = ComponentHelper :: getParams ( 'com_componentbuilder' );
2018-02-20 20:46:29 +00:00
}
2018-04-17 21:25:03 +00:00
return $items ;
2017-03-18 20:17:15 +00:00
}
}
}
return false ;
}
2018-04-17 21:25:03 +00:00
/**
* Remove all values that are no longer relevant .
*
* @ return void .
*/
protected function removeOldComponentValues ( & $item )
{
// make sure old fields are not used any more
unset ( $item -> addconfig );
unset ( $item -> addadmin_views );
unset ( $item -> addcustom_admin_views );
unset ( $item -> addsite_views );
unset ( $item -> version_update );
unset ( $item -> sql_tweak );
unset ( $item -> addcustommenus );
unset ( $item -> dashboard_tab );
unset ( $item -> php_dashboard_methods );
unset ( $item -> addfiles );
unset ( $item -> addfolders );
}
2017-10-20 16:17:46 +00:00
/**
* Set export IDs .
*
* @ return void .
*/
2018-04-17 21:25:03 +00:00
protected function setSmartIDs ( $value , $table , $int = true )
2017-10-20 16:17:46 +00:00
{
// check if table has been set
2018-04-17 21:25:03 +00:00
if ( ! isset ( $this -> smartIDs [ $table ]))
2017-10-20 16:17:46 +00:00
{
2018-04-17 21:25:03 +00:00
$this -> smartIDs [ $table ] = array ();
2017-10-20 16:17:46 +00:00
}
// convert if value is in json
2023-02-27 12:27:41 +00:00
if ( JsonHelper :: check ( $value ))
2017-10-20 16:17:46 +00:00
{
$value = json_decode ( $value , true );
}
// now update the fields
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $value ))
2017-10-20 16:17:46 +00:00
{
foreach ( $value as $id )
{
2023-02-27 12:27:41 +00:00
if ( $int && ( StringHelper :: check ( $id ) || is_numeric ( $id )) && 0 !== ( int ) $id )
2017-10-20 16:17:46 +00:00
{
2018-04-17 21:25:03 +00:00
$this -> smartIDs [ $table ][( int ) $id ] = ( int ) $id ;
2017-10-20 16:17:46 +00:00
}
2023-02-27 12:27:41 +00:00
elseif ( ! $int && StringHelper :: check ( $id ))
2018-03-30 09:32:22 +00:00
{
2018-04-17 21:25:03 +00:00
$this -> smartIDs [ $table ][ $id ] = $this -> _db -> quote ( $id );
2018-03-30 09:32:22 +00:00
}
2017-10-20 16:17:46 +00:00
}
}
2023-02-27 12:27:41 +00:00
elseif ( $int && ( StringHelper :: check ( $value ) || is_numeric ( $value )) && 0 !== ( int ) $value )
2017-10-20 16:17:46 +00:00
{
2018-04-17 21:25:03 +00:00
$this -> smartIDs [ $table ][( int ) $value ] = ( int ) $value ;
2017-10-20 16:17:46 +00:00
}
2023-02-27 12:27:41 +00:00
elseif ( ! $int && StringHelper :: check ( $value ))
2018-03-30 09:32:22 +00:00
{
2018-04-17 21:25:03 +00:00
$this -> smartIDs [ $table ][ $value ] = $this -> _db -> quote ( $value );
2018-03-30 09:32:22 +00:00
}
2017-10-20 16:17:46 +00:00
}
2017-10-16 17:14:23 +00:00
/**
2017-10-28 03:25:33 +00:00
* Method to get values from repeatable or subform .
2017-10-16 17:14:23 +00:00
*
2017-10-28 03:25:33 +00:00
* @ return mixed An array of values on success , false on failure .
2017-10-16 17:14:23 +00:00
*/
2017-10-28 03:25:33 +00:00
protected function getValues ( $values , $type , $key = null , $prep = 'table' )
2017-10-16 17:14:23 +00:00
{
// the ids bucket
$bucket = array ();
// if json convert to array
2023-02-27 12:27:41 +00:00
if ( JsonHelper :: check ( $values ))
2017-10-16 17:14:23 +00:00
{
$values = json_decode ( $values , true );
}
// check that the array has values
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $values ))
2017-10-16 17:14:23 +00:00
{
// check if the key is an array (targeting subform)
if ( 'subform' === $type && $key )
{
foreach ( $values as $value )
{
if ( isset ( $value [ $key ]))
{
if ( is_numeric ( $value [ $key ]))
{
$bucket [] = $value [ $key ];
}
2023-02-27 12:27:41 +00:00
elseif ( StringHelper :: check ( $value [ $key ]))
2017-10-16 17:14:23 +00:00
{
2017-10-28 03:25:33 +00:00
if ( 'table' === $prep )
{
$bucket [] = $this -> _db -> quote ( $value [ $key ]);
}
else
{
$bucket [] = $value [ $key ];
}
2017-10-16 17:14:23 +00:00
}
}
}
// only return if we set the ids
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $bucket ))
2017-10-16 17:14:23 +00:00
{
// now set the values back
return array_unique ( $bucket );
}
}
2019-12-07 01:39:16 +00:00
// check if the key is an array (targeting subform subform)
if ( 'subform++' === $type && strpos ( $key , '.' ) !== false )
{
$_key = explode ( '.' , $key );
foreach ( $values as $value )
{
2023-02-27 12:27:41 +00:00
if ( isset ( $value [ $_key [ 0 ]]) && JCBArrayHelper :: check ( $value [ $_key [ 0 ]]))
2019-12-07 01:39:16 +00:00
{
foreach ( $value [ $_key [ 0 ]] as $_value )
{
if ( is_numeric ( $_value [ $_key [ 1 ]]))
{
$bucket [] = $_value [ $_key [ 1 ]];
}
2023-02-27 12:27:41 +00:00
elseif ( StringHelper :: check ( $_value [ $_key [ 1 ]]))
2019-12-07 01:39:16 +00:00
{
if ( 'table' === $prep )
{
$bucket [] = $this -> _db -> quote ( $_value [ $_key [ 1 ]]);
}
else
{
$bucket [] = $_value [ $_key [ 1 ]];
}
}
}
}
}
// only return if we set the ids
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $bucket ))
2019-12-07 01:39:16 +00:00
{
// now set the values back
return array_unique ( $bucket );
}
}
2017-10-28 03:25:33 +00:00
// check if the key is an array (targeting repeatable)
2017-10-16 17:14:23 +00:00
if ( 'repeatable' === $type && $key )
{
if ( isset ( $values [ $key ]))
{
2017-10-28 03:25:33 +00:00
return array_map ( function ( $value ) use ( $prep ){
if ( is_numeric ( $value ))
2017-10-16 17:14:23 +00:00
{
2017-10-28 03:25:33 +00:00
return $value ;
2017-10-16 17:14:23 +00:00
}
2023-02-27 12:27:41 +00:00
elseif ( StringHelper :: check ( $value ))
2017-10-16 17:14:23 +00:00
{
2017-10-28 03:25:33 +00:00
if ( 'table' === $prep )
{
return $this -> _db -> quote ( $value );
}
else
{
return $value ;
}
2017-10-16 17:14:23 +00:00
}
}, array_unique ( $values [ $key ]) );
}
}
2021-12-21 14:44:50 +00:00
// get the powers
if ( 'power' === $type )
{
if ( isset ( $values [ $key ]))
{
foreach ( $values [ $key ] as $k => $val )
{
2023-02-27 12:27:41 +00:00
if ( strpos ( $k , 'power_' ) !== false && JCBArrayHelper :: check ( $val ))
2021-12-21 14:44:50 +00:00
{
foreach ( $val as $v )
{
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $v ) && isset ( $v [ 'power' ]))
2022-05-25 08:30:55 +00:00
{
$bucket [ $v [ 'power' ]] = $v [ 'power' ];
}
2021-12-21 14:44:50 +00:00
}
}
}
// only return if we set the ids
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $bucket ))
2021-12-21 14:44:50 +00:00
{
// now return the values back
return array_values ( $bucket );
}
}
}
2017-10-16 17:14:23 +00:00
}
return false ;
}
/**
* Method to get data of a given table .
*
* @ return mixed An array of data items on success , false on failure .
*/
2018-03-30 09:32:22 +00:00
protected function setData ( $table , $values , $key , $string = false )
2017-10-16 17:14:23 +00:00
{
2021-12-21 14:44:50 +00:00
// lets check for json strings
2023-02-27 12:27:41 +00:00
if ( JsonHelper :: check ( $values ))
2021-12-21 14:44:50 +00:00
{
$values = json_decode ( $values , true );
}
2022-10-23 21:18:02 +00:00
// let's check for just a string or int
elseif ( is_string ( $values ) || ( is_numeric ( $values ) && $values > 0 ))
{
$values = [ $values ];
}
2017-10-16 17:14:23 +00:00
// make sure we have an array of values
2023-02-27 12:27:41 +00:00
if ( ! JCBArrayHelper :: check ( $values , true ) || ! StringHelper :: check ( $table ) || ! StringHelper :: check ( $key ))
2017-10-16 17:14:23 +00:00
{
return false ;
}
2022-10-23 21:18:02 +00:00
2017-10-16 17:14:23 +00:00
// start the query
$query = $this -> _db -> getQuery ( true );
// Select some fields
$query -> select ( array ( 'a.*' ));
2022-10-23 21:18:02 +00:00
2017-10-16 17:14:23 +00:00
// From the componentbuilder_ANY table
$query -> from ( $this -> _db -> quoteName ( '#__componentbuilder_' . $table , 'a' ));
2022-10-23 21:18:02 +00:00
2022-05-16 04:25:03 +00:00
// check if this is an array of integers
if ( $this -> is_numeric ( $values ))
{
// set the where query
$query -> where ( 'a.' . $key . ' IN (' . implode ( ',' , $values ) . ')' );
}
else
{
// set the where query
$query -> where ( 'a.' . $key . ' IN (' . implode ( ',' , array_map ( function ( $var ) {
// check if already quoted
if ( preg_match ( '/^(["\']).*\1$/m' , $var ))
{
return $var ;
}
return $this -> _db -> quote ( $var );
}, $values )) . ')' );
}
2022-10-23 21:18:02 +00:00
2017-10-16 17:14:23 +00:00
// Implement View Level Access
if ( ! $this -> user -> authorise ( 'core.options' , 'com_componentbuilder' ))
{
$groups = implode ( ',' , $this -> user -> getAuthorisedViewLevels ());
$query -> where ( 'a.access IN (' . $groups . ')' );
}
2022-10-23 21:18:02 +00:00
2017-10-16 17:14:23 +00:00
// Order the results by ordering
$query -> order ( 'a.ordering ASC' );
// Load the items
$this -> _db -> setQuery ( $query );
$this -> _db -> execute ();
if ( $this -> _db -> getNumRows ())
{
2021-05-17 03:57:02 +00:00
// get the items
2017-10-16 17:14:23 +00:00
$items = $this -> _db -> loadObjectList ();
2021-05-17 03:57:02 +00:00
// reset the search array (only search for template/layouts)
$searchTLArray = array ();
2017-10-16 17:14:23 +00:00
// check if we have items
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $items ))
2017-10-16 17:14:23 +00:00
{
2021-05-17 03:57:02 +00:00
// set search array if site/custom admin view
2017-10-16 17:14:23 +00:00
if ( 'site_view' === $table || 'custom_admin_view' === $table )
{
2021-05-17 03:57:02 +00:00
$searchTLArray = array (
'default' => 'force_it' ,
'php_view' => 'add_php_view' ,
'php_jview' => 'add_php_jview' ,
'php_jview_display' => 'add_php_jview_display' ,
'php_document' => 'add_php_document' ,
'javascript_file' => 'add_javascript_file' ,
'js_document' => 'add_js_document' ,
'css_document' => 'add_css_document' ,
'css' => 'add_css'
);
}
// set search array if admin view
if ( 'admin_view' === $table )
{
$searchTLArray = array (
'php_getitem' => 'add_php_getitem' ,
'php_before_save' => 'add_php_before_save' ,
'php_save' => 'add_php_save' ,
'php_getform' => 'add_php_getform' ,
'php_postsavehook' => 'add_php_postsavehook' ,
'php_getitems' => 'add_php_getitems' ,
'php_getitems_after_all' => 'add_php_getitems_after_all' ,
'php_getlistquery' => 'add_php_getlistquery' ,
'php_allowadd' => 'add_php_allowadd' ,
'php_allowedit' => 'add_php_allowedit' ,
'php_before_cancel' => 'add_php_before_cancel' ,
'php_after_cancel' => 'add_php_after_cancel' ,
'php_before_delete' => 'add_php_before_delete' ,
'php_after_delete' => 'add_php_after_delete' ,
'php_before_publish' => 'add_php_before_publish' ,
'php_after_publish' => 'add_php_after_publish' ,
'php_batchcopy' => 'add_php_batchcopy' ,
'php_batchmove' => 'add_php_batchmove' ,
'php_document' => 'add_php_document' ,
'php_model' => 'add_custom_button' ,
'php_controller' => 'add_custom_button' ,
'php_model_list' => 'add_custom_button' ,
'php_controller_list' => 'add_custom_button'
);
2017-10-16 17:14:23 +00:00
}
// reset the global array
if ( 'template' === $table )
{
2018-04-17 21:25:03 +00:00
$this -> smartIDs [ 'template' ] = array ();
2017-10-16 17:14:23 +00:00
}
elseif ( 'layout' === $table )
{
2018-04-17 21:25:03 +00:00
$this -> smartIDs [ 'layout' ] = array ();
2017-10-16 17:14:23 +00:00
}
2019-03-04 12:47:28 +00:00
elseif ( 'custom_code' === $table && 'id' === $key && ! isset ( $this -> smartIDs [ 'custom_code' ]))
2018-12-29 14:56:06 +00:00
{
$this -> smartIDs [ 'custom_code' ] = array ();
}
2019-03-04 12:47:28 +00:00
elseif ( 'placeholder' === $table && 'id' === $key && ! isset ( $this -> smartIDs [ 'placeholder' ]))
{
$this -> smartIDs [ 'placeholder' ] = array ();
}
2017-10-16 17:14:23 +00:00
// start loading the data
2018-04-17 21:25:03 +00:00
if ( ! isset ( $this -> smartBox [ $table ]))
2017-10-16 17:14:23 +00:00
{
2018-04-17 21:25:03 +00:00
$this -> smartBox [ $table ] = array ();
2017-10-16 17:14:23 +00:00
}
// start loading the found items
foreach ( $items as $nr => & $item )
{
// set the data per id only once
2018-04-17 21:25:03 +00:00
if ( ! isset ( $item -> id ) || 0 === ( int ) $item -> id || isset ( $this -> smartBox [ $table ][ $item -> id ]))
2017-10-16 17:14:23 +00:00
{
continue ;
}
2017-12-25 12:46:35 +00:00
// actions to take before storing the item if table is template, layout, site_view, or custom_admin_view
if ( 'layout' === $table || 'template' === $table || 'site_view' === $table || 'custom_admin_view' === $table )
{
// unset snippets (we no longer export snippets)
if ( isset ( $item -> snippet ))
{
unset ( $item -> snippet );
}
}
// actions to take before storing the item if table is joomla_component
if ( 'joomla_component' === $table )
{
// make sure old fields are not exported any more
2022-05-16 04:25:03 +00:00
$this -> removeOldComponentValues ( $item );
// set the powers linked to this joomla component
$this -> setSmartIDs ( $this -> getValues ( $item -> params , 'power' , 'joomla_component_headers' , null ), 'power' , false );
2017-12-25 12:46:35 +00:00
}
// actions to take before storing the item if table is admin_view
if ( 'admin_view' === $table )
{
// make sure old fields are not exported any more
unset ( $item -> addfields );
unset ( $item -> addconditions );
}
2017-10-16 17:14:23 +00:00
// load to global object
2018-04-17 21:25:03 +00:00
$this -> smartBox [ $table ][ $item -> id ] = $item ;
2017-10-16 17:14:23 +00:00
// set the custom code ID's
2019-03-04 12:47:28 +00:00
$this -> setCodePlaceholdersIds ( $item , $table );
// set the placeholder ID's
$this -> setCodePlaceholdersIds ( $item , $table , 'placeholder' );
2017-10-28 03:25:33 +00:00
// actions to take if table is component_files_folders
2019-12-07 01:39:16 +00:00
if (( 'component_files_folders' === $table || 'joomla_plugin_files_folders_urls' === $table || 'joomla_module_files_folders_urls' === $table ) && 'clone' !== $this -> activeType )
2017-10-28 03:25:33 +00:00
{
// build files
$this -> moveIt ( $this -> getValues ( $item -> addfiles , 'subform' , 'file' , null ), 'file' );
// build folders
$this -> moveIt ( $this -> getValues ( $item -> addfolders , 'subform' , 'folder' , null ), 'folder' );
2018-03-02 01:37:04 +00:00
// build full path files
$this -> moveIt ( $this -> getValues ( $item -> addfilesfullpath , 'subform' , 'filepath' , null ), 'file' , true );
// build full path folders
$this -> moveIt ( $this -> getValues ( $item -> addfoldersfullpath , 'subform' , 'folderpath' , null ), 'folder' , true );
2017-10-28 03:25:33 +00:00
}
2022-05-16 04:25:03 +00:00
// actions to take if table is component_dashboard
if ( 'component_dashboard' === $table )
{
// set the powers linked to this dashboard
$this -> setSmartIDs ( $this -> getValues ( $item -> params , 'power' , 'component_dashboard_headers' , null ), 'power' , false );
}
2017-10-28 03:25:33 +00:00
// actions to take if table is component_config
if ( 'component_config' === $table )
{
// add config fields
$this -> setData ( 'field' , $this -> getValues ( $item -> addconfig , 'subform' , 'field' ), 'id' );
}
// actions to take if table is component_admin_views
if ( 'component_admin_views' === $table )
{
// add admin views
$this -> setData ( 'admin_view' , $this -> getValues ( $item -> addadmin_views , 'subform' , 'adminview' ), 'id' );
}
// actions to take if table is component_site_views
if ( 'component_site_views' === $table )
{
// add site views
$this -> setData ( 'site_view' , $this -> getValues ( $item -> addsite_views , 'subform' , 'siteview' ), 'id' );
}
// actions to take if table is component_custom_admin_views
if ( 'component_custom_admin_views' === $table )
{
// add custom admin views
$this -> setData ( 'custom_admin_view' , $this -> getValues ( $item -> addcustom_admin_views , 'subform' , 'customadminview' ), 'id' );
}
2019-12-07 01:39:16 +00:00
// actions to take if table is component_modules
if ( 'component_modules' === $table )
{
// we remove those modules not part of the export
2023-02-27 12:27:41 +00:00
if ( isset ( $item -> addjoomla_modules ) && JsonHelper :: check ( $item -> addjoomla_modules ))
2019-12-07 01:39:16 +00:00
{
$item -> addjoomla_modules = array_filter (
json_decode ( $item -> addjoomla_modules , true ),
function ( $module ) {
// target 2 is only export and target 0 is both (1 is only compile)
if ( isset ( $module [ 'target' ]) && ( $module [ 'target' ] == 2 || $module [ 'target' ] == 0 ))
{
return true ;
}
return false ;
}
);
}
// add custom admin views
$this -> setData ( 'joomla_module' , $this -> getValues ( $item -> addjoomla_modules , 'subform' , 'module' ), 'id' );
}
2019-08-12 21:30:31 +00:00
// actions to take if table is component_plugins
if ( 'component_plugins' === $table )
{
2019-11-13 03:36:42 +00:00
// we remove those plugins not part of the export
2023-02-27 12:27:41 +00:00
if ( isset ( $item -> addjoomla_plugins ) && JsonHelper :: check ( $item -> addjoomla_plugins ))
2019-11-13 03:36:42 +00:00
{
$item -> addjoomla_plugins = array_filter (
json_decode ( $item -> addjoomla_plugins , true ),
function ( $plugin ) {
// target 2 is only export and target 0 is both (1 is only compile)
if ( isset ( $plugin [ 'target' ]) && ( $plugin [ 'target' ] == 2 || $plugin [ 'target' ] == 0 ))
{
return true ;
}
return false ;
}
);
}
2019-08-12 21:30:31 +00:00
// add custom admin views
$this -> setData ( 'joomla_plugin' , $this -> getValues ( $item -> addjoomla_plugins , 'subform' , 'plugin' ), 'id' );
}
2017-10-16 17:14:23 +00:00
// actions to take if table is admin_view
if ( 'admin_view' === $table )
{
// add fields & conditions
2018-04-17 21:25:03 +00:00
$this -> setSmartIDs ( $item -> id , 'admin_view' );
2021-12-21 14:44:50 +00:00
// set the powers linked to this admin view
2022-05-16 04:25:03 +00:00
$this -> setSmartIDs ( $this -> getValues ( $item -> params , 'power' , 'admin_view_headers' , null ), 'power' , false );
2018-04-17 21:25:03 +00:00
// do not move anything if clone
if ( 'clone' !== $this -> activeType )
{
// admin icon
$this -> moveIt ( array ( $item -> icon ), 'image' );
// admin icon_add
$this -> moveIt ( array ( $item -> icon_add ), 'image' );
// admin icon_category
$this -> moveIt ( array ( $item -> icon_category ), 'image' );
}
2017-10-16 17:14:23 +00:00
}
// actions to take if table is admin_fields
if ( 'admin_fields' === $table )
{
// add fields
2017-10-28 03:25:33 +00:00
$this -> setData ( 'field' , $this -> getValues ( $item -> addfields , 'subform' , 'field' ), 'id' );
2017-10-16 17:14:23 +00:00
}
2018-03-03 03:19:04 +00:00
// actions to take if table is admin_fields_conditions
if ( 'admin_fields_conditions' === $table )
{
2018-05-26 10:03:08 +00:00
// add fields (all should already be added)
2018-03-03 03:19:04 +00:00
$this -> setData ( 'field' , $this -> getValues ( $item -> addconditions , 'subform' , 'target_field' ), 'id' );
$this -> setData ( 'field' , $this -> getValues ( $item -> addconditions , 'subform' , 'match_field' ), 'id' );
}
2018-05-26 10:03:08 +00:00
// actions to take if table is admin_fields_relations
if ( 'admin_fields_relations' === $table )
{
// add fields (all should already be added)
$this -> setData ( 'field' , $this -> getValues ( $item -> addrelations , 'subform' , 'listfield' ), 'id' );
$this -> setData ( 'field' , $this -> getValues ( $item -> addrelations , 'subform' , 'joinfields' ), 'id' );
}
2017-10-16 17:14:23 +00:00
// actions to take if table is field
if ( 'field' === $table )
{
// add field types
2018-04-17 21:25:03 +00:00
$this -> setSmartIDs ( $item -> fieldtype , 'fieldtype' );
2017-10-16 17:14:23 +00:00
// check if this field has multiple fields
if ( $this -> checkMultiFields ( $item -> fieldtype ))
{
2023-10-18 07:26:30 +00:00
$fields = GetHelper :: between ( json_decode ( $item -> xml ), 'fields="' , '"' );
2017-10-16 17:14:23 +00:00
$fieldsSets = array ();
if ( strpos ( $fields , ',' ) !== false )
{
// multiple fields
$fieldsSets = ( array ) explode ( ',' , $fields );
}
elseif ( is_numeric ( $fields ))
{
// single field
$fieldsSets [] = ( int ) $fields ;
}
// get fields
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $fieldsSets ))
2017-10-16 17:14:23 +00:00
{
$this -> setData ( 'field' , $fieldsSets , 'id' );
}
}
2018-03-30 09:32:22 +00:00
// check if validation rule is found
2023-10-18 07:26:30 +00:00
$validationRule = GetHelper :: between ( json_decode ( $item -> xml ), 'validate="' , '"' );
2023-02-27 12:27:41 +00:00
if ( StringHelper :: check ( $validationRule ))
2018-03-30 09:32:22 +00:00
{
// make sure it is lowercase
2023-02-27 12:27:41 +00:00
$validationRule = StringHelper :: safe ( $validationRule );
2018-03-30 09:32:22 +00:00
// get core validation rules
if ( $coreValidationRules = ComponentbuilderHelper :: getExistingValidationRuleNames ( true ))
{
// make sure this rule is not a core validation rule
if ( ! in_array ( $validationRule , ( array ) $coreValidationRules ))
{
// okay load the rule
2018-04-17 21:25:03 +00:00
$this -> setSmartIDs ( $validationRule , 'validation_rule' , false );
2018-03-30 09:32:22 +00:00
}
}
}
2017-10-16 17:14:23 +00:00
}
2021-05-17 03:57:02 +00:00
// check if a search is required
2023-02-27 12:27:41 +00:00
if ( isset ( $searchTLArray ) && JCBArrayHelper :: check ( $searchTLArray )){
2021-05-17 03:57:02 +00:00
2017-10-16 17:14:23 +00:00
// add search array templates and layouts
2021-05-17 03:57:02 +00:00
foreach ( $searchTLArray as $scripter => $add )
2017-10-16 17:14:23 +00:00
{
2021-05-17 03:57:02 +00:00
if ( $add === 'force_it' || ( isset ( $item -> { $add }) && $item -> { $add } == 1 ))
2017-10-16 17:14:23 +00:00
{
2017-10-20 16:17:46 +00:00
$this -> getTemplateLayout ( $item -> { $scripter });
2017-10-16 17:14:23 +00:00
}
}
2021-05-17 03:57:02 +00:00
}
// actions to take if table is site_view and custom_admin_view
if ( 'site_view' === $table || 'custom_admin_view' === $table )
{
2017-10-16 17:14:23 +00:00
// add dynamic gets
2018-04-17 21:25:03 +00:00
$this -> setSmartIDs ( $item -> main_get , 'dynamic_get' );
$this -> setSmartIDs ( $item -> custom_get , 'dynamic_get' );
$this -> setSmartIDs ( $item -> dynamic_get , 'dynamic_get' );
2017-10-20 16:17:46 +00:00
// move the icon
2018-04-17 21:25:03 +00:00
if ( 'custom_admin_view' === $table && isset ( $item -> icon ) && 'clone' !== $this -> activeType )
2017-10-16 17:14:23 +00:00
{
// view icon
2017-10-28 03:25:33 +00:00
$this -> moveIt ( array ( $item -> icon ), 'image' );
2017-10-16 17:14:23 +00:00
}
2018-02-20 20:46:29 +00:00
// add snippets (was removed please use snippet importer)
if ( isset ( $item -> snippet ) && is_numeric ( $item -> snippet ))
{
2018-04-17 21:25:03 +00:00
$this -> setSmartIDs (( int ) $item -> snippet , 'snippet' );
2018-02-20 20:46:29 +00:00
}
2021-12-21 14:44:50 +00:00
// actions to take if table is site_view
if ( 'site_view' === $table )
{
// set the powers linked to this admin view
2022-05-16 04:25:03 +00:00
$this -> setSmartIDs ( $this -> getValues ( $item -> params , 'power' , 'site_view_headers' , null ), 'power' , false );
2021-12-21 14:44:50 +00:00
}
// actions to take if table is custom_admin_view
elseif ( 'custom_admin_view' === $table )
{
// set the powers linked to this admin view
2022-05-16 04:25:03 +00:00
$this -> setSmartIDs ( $this -> getValues ( $item -> params , 'power' , 'custom_admin_view_headers' , null ), 'power' , false );
2021-12-21 14:44:50 +00:00
}
2017-10-16 17:14:23 +00:00
}
// actions to take if table is template and layout
if ( 'layout' === $table || 'template' === $table )
{
2018-02-20 20:46:29 +00:00
// add snippets (was removed please use snippet importer)
if ( isset ( $item -> snippet ) && is_numeric ( $item -> snippet ))
{
2018-04-17 21:25:03 +00:00
$this -> setSmartIDs (( int ) $item -> snippet , 'snippet' );
2018-02-20 20:46:29 +00:00
}
2017-10-16 17:14:23 +00:00
// search for templates & layouts
2021-05-17 03:57:02 +00:00
$this -> getTemplateLayout ( $item -> $table , $this -> user );
2017-10-16 17:14:23 +00:00
// add search array templates and layouts
if ( isset ( $item -> add_php_view ) && $item -> add_php_view == 1 )
{
$this -> getTemplateLayout ( $item -> php_view , $this -> user );
}
// add dynamic gets
2018-04-17 21:25:03 +00:00
$this -> setSmartIDs (( int ) $item -> dynamic_get , 'dynamic_get' );
2017-10-16 17:14:23 +00:00
}
2019-12-07 01:39:16 +00:00
// actions to take if table is joomla_module
if ( 'joomla_module' === $table )
{
// add the updates and folder stuff
$this -> setSmartIDs ( $item -> id , 'joomla_module' );
// add class_extends
$this -> setSmartIDs (( int ) $item -> class_extends , 'class_extends' );
// add fields
$this -> setData ( 'field' , $this -> getValues ( $item -> fields , 'subform++' , 'fields.field' ), 'id' );
// add dynamic gets
$this -> setSmartIDs ( $item -> custom_get , 'dynamic_get' );
2020-04-03 18:45:48 +00:00
// set module language strings
$this -> setLanguageTranslation ( $item -> id , 'modules' );
2019-12-07 01:39:16 +00:00
}
2019-08-12 21:30:31 +00:00
// actions to take if table is joomla_plugin
if ( 'joomla_plugin' === $table )
{
// add the updates and folder stuff
$this -> setSmartIDs ( $item -> id , 'joomla_plugin' );
// add class_extends
$this -> setSmartIDs (( int ) $item -> class_extends , 'class_extends' );
// add joomla_plugin_group
$this -> setSmartIDs (( int ) $item -> joomla_plugin_group , 'joomla_plugin_group' );
// add fields
2019-12-07 01:39:16 +00:00
$this -> setData ( 'field' , $this -> getValues ( $item -> fields , 'subform++' , 'fields.field' ), 'id' );
2019-08-12 21:30:31 +00:00
// add property_selection
$this -> setData ( 'class_property' , $this -> getValues ( $item -> property_selection , 'subform' , 'property' ), 'id' );
// add class_method
$this -> setData ( 'class_method' , $this -> getValues ( $item -> method_selection , 'subform' , 'method' ), 'id' );
2020-04-03 18:45:48 +00:00
// set plugin language strings
$this -> setLanguageTranslation ( $item -> id , 'plugins' );
2019-08-12 21:30:31 +00:00
}
// actions to take if table is joomla_plugin_group
if ( 'joomla_plugin_group' === $table )
{
// add class_extends
$this -> setSmartIDs (( int ) $item -> class_extends , 'class_extends' );
}
// actions to take if table is class_method or
if ( 'class_method' === $table || 'class_property' === $table )
{
// add joomla_plugin_group
$this -> setSmartIDs (( int ) $item -> joomla_plugin_group , 'joomla_plugin_group' );
}
2022-05-16 04:25:03 +00:00
// actions to take if table is dynamic_get
if ( 'dynamic_get' === $table )
{
// add dynamic_get_headers
$this -> setSmartIDs ( $this -> getValues ( $item -> params , 'power' , 'dynamic_get_headers' , null ), 'power' , false );
}
2021-12-21 14:44:50 +00:00
// actions to take if table is power
if ( 'power' === $table )
{
// add the extended class (powers)
2022-05-16 04:25:03 +00:00
$this -> setData ( 'power' , $item -> extends , 'guid' );
2021-12-21 14:44:50 +00:00
// add implements interfaces (powers)
2022-05-16 04:25:03 +00:00
$this -> setData ( 'power' , $item -> implements , 'guid' );
2021-12-21 14:44:50 +00:00
// add use classes (powers)
2022-05-16 04:25:03 +00:00
$this -> setData ( 'power' , $this -> getValues ( $item -> use_selection , 'subform' , 'use' ), 'guid' );
2021-12-21 14:44:50 +00:00
// add load classes (powers)
2022-05-16 04:25:03 +00:00
$this -> setData ( 'power' , $this -> getValues ( $item -> load_selection , 'subform' , 'load' ), 'guid' );
2021-12-21 14:44:50 +00:00
// add property_selection
$this -> setData ( 'class_property' , $this -> getValues ( $item -> property_selection , 'subform' , 'property' ), 'id' );
// add class_method
$this -> setData ( 'class_method' , $this -> getValues ( $item -> method_selection , 'subform' , 'method' ), 'id' );
}
2017-10-16 17:14:23 +00:00
}
}
}
}
2022-05-16 04:25:03 +00:00
/**
* Method to check if array has only numiric values
*
* @ return bool
**/
protected function is_numeric ( $array )
{
foreach ( $array as $value )
{
if ( ! is_numeric ( $value ))
{
return false ;
}
}
return true ;
}
2018-04-17 21:25:03 +00:00
/**
* Method to do the smart cloning
*
* @ return bool
*/
protected function smartCloner ()
{
// check if data is set
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartBox ) && JCBArrayHelper :: check ( $this -> smartBox ))
2018-04-17 21:25:03 +00:00
{
// get the import_joomla_components
$model = ComponentbuilderHelper :: getModel ( 'import_joomla_components' );
// do not show more information
$model -> moreInfo = 0 ;
// trigger the create new (clone) feature
$model -> canmerge = 0 ;
// set some postfix
2023-02-27 12:27:41 +00:00
$model -> postfix = ' (' . StringHelper :: random ( 2 ) . ')' ;
2018-04-17 21:25:03 +00:00
// get App
2024-03-02 20:10:30 +00:00
$model -> app = Factory :: getApplication ();
2018-04-17 21:25:03 +00:00
// set user
$model -> user = $this -> user ;
// set today's date
2024-03-02 20:10:30 +00:00
$model -> today = Factory :: getDate () -> toSql ();
2018-04-17 21:25:03 +00:00
// load the data
$model -> data = $this -> smartBox ;
// remove smart box to safe on memory
unset ( $this -> smartBox );
// the array of tables to store
$tables = array (
'fieldtype' , 'field' , 'admin_view' , 'snippet' , 'dynamic_get' , 'custom_admin_view' , 'site_view' ,
2019-03-04 12:47:28 +00:00
'template' , 'layout' , 'joomla_component' , 'language' , 'language_translation' , 'custom_code' , 'placeholder' ,
2019-12-07 01:39:16 +00:00
'joomla_module' , 'joomla_module_files_folders_urls' , 'joomla_module_updates' ,
2021-12-21 14:44:50 +00:00
'joomla_plugin' , 'joomla_plugin_files_folders_urls' , 'joomla_plugin_updates' , 'power' ,
2018-08-24 21:46:41 +00:00
'admin_fields' , 'admin_fields_conditions' , 'admin_fields_relations' , 'admin_custom_tabs' , 'component_admin_views' ,
'component_site_views' , 'component_custom_admin_views' , 'component_updates' , 'component_mysql_tweaks' ,
2019-02-15 22:03:21 +00:00
'component_custom_admin_menus' , 'component_config' , 'component_dashboard' , 'component_files_folders' ,
2019-12-07 01:39:16 +00:00
'component_placeholders' , 'component_modules' , 'component_plugins'
2018-04-17 21:25:03 +00:00
);
// smart table loop
foreach ( $tables as $table )
{
// save the table to database
if ( ! $model -> saveSmartItems ( $table ))
{
return false ;
}
}
// do an after all run on all items that need it
2018-05-04 20:27:49 +00:00
$model -> updateAfterAll ();
2018-04-17 21:25:03 +00:00
// finally move the old datasets
$model -> moveDivergedData ();
// we had success
return true ;
}
return false ;
}
2017-03-20 22:07:14 +00:00
/**
* Method to build the package to export
*
2018-04-17 21:25:03 +00:00
* @ return bool
2017-03-20 22:07:14 +00:00
*/
protected function smartExportBuilder ()
{
2018-03-18 04:28:54 +00:00
// check if data is set
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartBox ) && JCBArrayHelper :: check ( $this -> smartBox ))
2017-03-28 14:57:59 +00:00
{
2018-03-18 04:28:54 +00:00
// set db data
2018-04-17 21:25:03 +00:00
$data = serialize ( $this -> smartBox );
2023-02-27 12:27:41 +00:00
2018-05-02 14:47:01 +00:00
// Set the key owner information
$this -> info [ 'source' ] = array ();
$this -> info [ 'source' ][ 'company' ] = $this -> params -> get ( 'export_company' , null );
$this -> info [ 'source' ][ 'owner' ] = $this -> params -> get ( 'export_owner' , null );
$this -> info [ 'source' ][ 'email' ] = $this -> params -> get ( 'export_email' , null );
$this -> info [ 'source' ][ 'website' ] = $this -> params -> get ( 'export_website' , null );
$this -> info [ 'source' ][ 'license' ] = $this -> params -> get ( 'export_license' , null );
$this -> info [ 'source' ][ 'copyright' ] = $this -> params -> get ( 'export_copyright' , null );
2023-02-27 12:27:41 +00:00
2018-03-18 04:28:54 +00:00
// lock the data if set
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $this -> key ))
2017-04-26 08:55:02 +00:00
{
2018-03-18 04:28:54 +00:00
// lock the data
$this -> key = md5 ( implode ( '' , $this -> key ));
2023-02-27 12:27:41 +00:00
// lock the data
$data = PackageFactory :: _ ( 'Crypt' ) -> encrypt ( $data , 'aes' , $this -> key );
2018-03-18 04:28:54 +00:00
// Set the key owner information
$this -> info [ 'getKeyFrom' ] = array ();
2018-05-02 14:47:01 +00:00
$this -> info [ 'getKeyFrom' ][ 'company' ] = $this -> info [ 'source' ][ 'company' ];
$this -> info [ 'getKeyFrom' ][ 'owner' ] = $this -> info [ 'source' ][ 'owner' ];
$this -> info [ 'getKeyFrom' ][ 'email' ] = $this -> info [ 'source' ][ 'email' ];
$this -> info [ 'getKeyFrom' ][ 'website' ] = $this -> info [ 'source' ][ 'website' ];
$this -> info [ 'getKeyFrom' ][ 'license' ] = $this -> info [ 'source' ][ 'license' ];
$this -> info [ 'getKeyFrom' ][ 'copyright' ] = $this -> info [ 'source' ][ 'copyright' ];
2018-05-05 14:47:48 +00:00
// add buy link if only one link is set
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> info [ 'export_buy_link' ])
&& JCBArrayHelper :: check ( $this -> info [ 'export_buy_link' ])
&& count (( array ) $this -> info [ 'export_buy_link' ]) == 1 )
2018-03-18 04:28:54 +00:00
{
2018-05-05 14:47:48 +00:00
$this -> info [ 'getKeyFrom' ][ 'buy_link' ] = array_values ( $this -> info [ 'export_buy_link' ])[ 0 ];
2018-03-18 04:28:54 +00:00
}
else
{
2023-02-27 12:27:41 +00:00
// use global if more then one component is exported
// (since they now have one key), or if none has a buy link
2018-03-18 04:28:54 +00:00
$this -> info [ 'getKeyFrom' ][ 'buy_link' ] = $this -> params -> get ( 'export_buy_link' , null );
}
2018-05-05 14:47:48 +00:00
// no remove the buy links
unset ( $this -> info [ 'export_buy_link' ]);
// if we have multi links add them also
2018-05-02 14:47:01 +00:00
// we started adding this at v2.7.7
2018-05-03 14:04:47 +00:00
$this -> info [ 'key' ] = true ;
2023-02-27 12:27:41 +00:00
// Changed: 25th Feb. 2023 at v3.1.18
// $this->info['phpseclib'] = false;
// we started adding this at v3.1.18
$this -> info [ 'phpseclib3' ] = true ;
2017-04-26 08:55:02 +00:00
}
else
{
2018-05-03 14:04:47 +00:00
// we started adding this at v2.7.7
2018-05-04 00:15:57 +00:00
$this -> info [ 'key' ] = false ;
2022-05-16 04:25:03 +00:00
// we started adding this at v3.0.11 and v2.12.17
2023-02-27 12:27:41 +00:00
// $this->info['phpseclib'] = false;
// we started adding this at v3.1.18
$this -> info [ 'phpseclib3' ] = false ;
2022-05-16 04:25:03 +00:00
// base 64 encode the data
2018-03-18 04:28:54 +00:00
$data = base64_encode ( $data );
2017-04-26 08:55:02 +00:00
}
2023-02-27 12:27:41 +00:00
2018-03-18 04:28:54 +00:00
// set the path
$dbPath = $this -> packagePath . '/db.vdm' ;
2023-02-27 12:27:41 +00:00
2018-03-18 04:28:54 +00:00
// write the db data to file in package
2023-02-27 12:27:41 +00:00
if ( ! FileHelper :: write ( $dbPath , wordwrap ( $data , 128 , " \n " , true )))
2018-03-18 04:28:54 +00:00
{
2017-03-30 21:19:12 +00:00
return false ;
2018-03-18 04:28:54 +00:00
}
2023-02-27 12:27:41 +00:00
// lock the info data
$info = PackageFactory :: _ ( 'Crypt' ) -> encrypt ( json_encode ( $this -> info ), 'local' );
// set the path
$infoPath = $this -> packagePath . '/info.vdm' ;
// write the info data to file in package
if ( ! FileHelper :: write ( $infoPath , wordwrap ( $info , 128 , " \n " , true )))
2022-05-16 04:25:03 +00:00
{
2023-02-27 12:27:41 +00:00
return false ;
2018-03-18 04:28:54 +00:00
}
2023-02-27 12:27:41 +00:00
2018-03-18 04:28:54 +00:00
// lock all files
$this -> lockFiles ();
2023-02-27 12:27:41 +00:00
2018-03-18 04:28:54 +00:00
// remove old zip files with the same name
if ( JFile :: exists ( $this -> zipPath ))
{
// remove file if found
JFile :: delete ( $this -> zipPath );
}
2023-02-27 12:27:41 +00:00
2018-03-18 04:28:54 +00:00
// zip the folder
2023-02-27 12:27:41 +00:00
if ( ! FileHelper :: zip ( $this -> packagePath , $this -> zipPath ))
2018-02-20 20:46:29 +00:00
{
return false ;
}
2023-02-27 12:27:41 +00:00
2018-03-18 04:28:54 +00:00
// move to remote server if needed
if ( 2 == $this -> backupType )
{
2023-02-27 12:27:41 +00:00
if ( ! PackageFactory :: _ ( 'Server' ) -> legacyMove (
$this -> zipPath , $this -> packageName . '.zip' ,
$this -> backupServer , null , 'joomla_component.export'
)
)
2018-03-18 04:28:54 +00:00
{
return false ;
}
2023-02-27 12:27:41 +00:00
2018-03-18 04:28:54 +00:00
// remove the local file
JFile :: delete ( $this -> zipPath );
}
2023-02-27 12:27:41 +00:00
2018-03-18 04:28:54 +00:00
// remove the folder
if ( ! ComponentbuilderHelper :: removeFolder ( $this -> packagePath ))
{
return false ;
}
2023-02-27 12:27:41 +00:00
2018-03-18 04:28:54 +00:00
return true ;
2017-03-20 22:07:14 +00:00
}
2018-03-18 04:28:54 +00:00
return false ;
2017-03-20 22:07:14 +00:00
}
2017-04-01 13:59:54 +00:00
/**
* Method to lock all files
*
* @ return void
*/
protected function lockFiles ()
{
// lock the data if set
2023-02-27 12:27:41 +00:00
if ( StringHelper :: check ( $this -> key ) && strlen ( $this -> key ) == 32 )
2017-04-01 13:59:54 +00:00
{
// we must first store the current working directory
$joomla = getcwd ();
2023-02-27 12:27:41 +00:00
2018-03-02 01:37:04 +00:00
// to avoid that it encrypt the db and info file again we must move per/folder
$folders = array ( 'images' , 'custom' , 'dynamic' );
2023-02-27 12:27:41 +00:00
2018-03-02 01:37:04 +00:00
// loop the folders
foreach ( $folders as $folder )
2017-04-01 13:59:54 +00:00
{
2018-03-02 01:37:04 +00:00
// the sub path
$subPath = $this -> packagePath . '/' . $folder ;
2023-02-27 12:27:41 +00:00
2018-03-02 01:37:04 +00:00
// go to the package sub folder if found
2023-02-27 12:27:41 +00:00
if ( FileHelper :: exists ( $subPath ))
2018-03-02 01:37:04 +00:00
{
2022-05-16 04:25:03 +00:00
$this -> lock ( $subPath );
2018-03-02 01:37:04 +00:00
}
2017-04-01 13:59:54 +00:00
}
2023-02-27 12:27:41 +00:00
2017-04-01 13:59:54 +00:00
// change back to working dir
chdir ( $joomla );
}
}
/**
* The Locker
*
* @ return void
*/
2022-05-16 04:25:03 +00:00
protected function lock ( & $tmpPath )
2017-04-01 13:59:54 +00:00
{
// we are changing the working directory to the tmp path (important)
chdir ( $tmpPath );
2023-02-27 12:27:41 +00:00
2017-04-01 13:59:54 +00:00
// get a list of files in the current directory tree (all)
$files = JFolder :: files ( '.' , '.' , true , true );
2023-02-27 12:27:41 +00:00
2017-04-01 13:59:54 +00:00
// read in the file content
foreach ( $files as $file )
{
2023-02-27 12:27:41 +00:00
// get file content
$content = FileHelper :: getContent ( $file );
2017-04-01 13:59:54 +00:00
// write the encrypted string back to file
2023-02-27 12:27:41 +00:00
$content = PackageFactory :: _ ( 'Crypt' ) -> encrypt ( $content , 'eac' , $this -> key );
// store the encrypted file content in the same file
FileHelper :: write ( $file , wordwrap ( $content , 128 , " \n " , true ));
2017-04-01 13:59:54 +00:00
}
}
2017-03-20 22:07:14 +00:00
/**
* Method to move the files and folder to the package folder
*
* @ return bool
*/
2018-03-02 01:37:04 +00:00
protected function moveIt ( $paths , $type , $dynamic = false )
2017-03-20 22:07:14 +00:00
{
// make sure we have an array
2023-02-27 12:27:41 +00:00
if ( ! JCBArrayHelper :: check ( $paths ))
2017-03-20 22:07:14 +00:00
{
return false ;
}
2023-02-27 12:27:41 +00:00
2017-03-20 22:07:14 +00:00
// set the name of the folder
if ( 'file' === $type || 'folder' === $type )
{
2017-10-28 03:25:33 +00:00
$folderName = 'custom' ;
2018-03-02 01:37:04 +00:00
// if these are full paths use dynamic folder
if ( $dynamic )
{
$folderName = 'dynamic' ;
}
2017-03-20 22:07:14 +00:00
}
2018-03-02 01:37:04 +00:00
elseif ( 'image' === $type )
2017-03-20 22:07:14 +00:00
{
2017-10-28 03:25:33 +00:00
$folderName = 'images' ;
2017-03-20 22:07:14 +00:00
}
2018-03-02 01:37:04 +00:00
else
{
return false ;
}
2023-02-27 12:27:41 +00:00
2017-03-20 22:07:14 +00:00
// setup the type path
2017-10-28 03:25:33 +00:00
$tmpPath = str_replace ( '//' , '/' , $this -> packagePath . '/' . $folderName );
2023-02-27 12:27:41 +00:00
2017-03-20 22:07:14 +00:00
// create type path if not set
2023-02-27 12:27:41 +00:00
if ( ! FileHelper :: exists ( $tmpPath ))
2017-03-20 22:07:14 +00:00
{
// create the folders if not found
JFolder :: create ( $tmpPath );
}
2023-02-27 12:27:41 +00:00
2017-03-20 22:07:14 +00:00
// now move it
2017-10-28 03:25:33 +00:00
foreach ( $paths as $item )
2017-03-20 22:07:14 +00:00
{
2018-03-02 01:37:04 +00:00
// make sure we have a string
2023-02-27 12:27:41 +00:00
if ( StringHelper :: check ( $item ))
2017-03-20 22:07:14 +00:00
{
2018-03-02 01:37:04 +00:00
// if the file type
2017-03-27 12:38:51 +00:00
if ( 'file' === $type )
2017-03-20 22:07:14 +00:00
{
2018-03-02 01:37:04 +00:00
// if dynamic paths
if ( $dynamic )
{
$tmpFilePath = $tmpPath . '/' . $this -> setDynamicPathName ( $item );
$customFilePath = str_replace ( '//' , '/' , $this -> setFullPath ( $item ));
}
else
{
$tmpFilePath = str_replace ( '//' , '/' , $tmpPath . '/' . $item );
$customFilePath = str_replace ( '//' , '/' , $this -> customPath . '/' . $item );
}
// now check if file exist
2017-04-08 20:52:51 +00:00
if ( ! JFile :: exists ( $tmpFilePath ) && JFile :: exists ( $customFilePath ))
2017-03-27 12:38:51 +00:00
{
// move the file to its place
2017-08-20 17:52:35 +00:00
JFile :: copy ( $customFilePath , $tmpFilePath );
2017-03-27 12:38:51 +00:00
}
2017-03-20 22:07:14 +00:00
}
2023-02-27 12:27:41 +00:00
2018-03-02 01:37:04 +00:00
// if the image type
2017-03-27 12:38:51 +00:00
if ( 'image' === $type )
2017-03-20 22:07:14 +00:00
{
2017-08-20 17:52:35 +00:00
$imageName = basename ( $item );
$imagePath = str_replace ( $imageName , '' , $item );
$imageFolderPath = str_replace ( '//' , '/' , $this -> packagePath . '/' . $imagePath );
2023-02-27 12:27:41 +00:00
2017-08-20 17:52:35 +00:00
// check if image folder exist
2023-02-27 12:27:41 +00:00
if ( ! FileHelper :: exists ( $imageFolderPath ))
2017-08-20 17:52:35 +00:00
{
// create the folders if not found
JFolder :: create ( $imageFolderPath );
}
2017-04-08 20:52:51 +00:00
$tmpImagePath = str_replace ( '//' , '/' , $this -> packagePath . '/' . $item );
$customImagePath = str_replace ( '//' , '/' , JPATH_ROOT . '/' . $item );
if ( ! JFile :: exists ( $tmpImagePath ) && JFile :: exists ( $customImagePath ))
2017-03-27 12:38:51 +00:00
{
// move the file to its place
2017-08-20 17:52:35 +00:00
JFile :: copy ( $customImagePath , $tmpImagePath );
2017-03-27 12:38:51 +00:00
}
}
2023-02-27 12:27:41 +00:00
2018-03-02 01:37:04 +00:00
// if the folder type
2017-03-27 12:38:51 +00:00
if ( 'folder' === $type )
{
2018-03-02 01:37:04 +00:00
// if dynamic paths
if ( $dynamic )
{
$tmpFolderPath = $tmpPath . '/' . $this -> setDynamicPathName ( $item );
$customFolderPath = str_replace ( '//' , '/' , $this -> setFullPath ( $item ));
}
else
{
$tmpFolderPath = str_replace ( '//' , '/' , $tmpPath . '/' . $item );
$customFolderPath = str_replace ( '//' , '/' , $this -> customPath . '/' . $item );
}
2023-02-27 12:27:41 +00:00
if ( ! FileHelper :: exists ( $tmpFolderPath ) && FileHelper :: exists ( $customFolderPath ))
2017-03-27 12:38:51 +00:00
{
// move the folder to its place
2017-04-08 20:52:51 +00:00
JFolder :: copy ( $customFolderPath , $tmpFolderPath , '' , true );
2017-03-27 12:38:51 +00:00
}
2017-03-20 22:07:14 +00:00
}
}
}
return true ;
}
2017-03-31 21:28:16 +00:00
/**
2017-09-18 02:20:50 +00:00
* Check if a field has multiple fields
2017-03-31 21:28:16 +00:00
*
* @ param string $typeID The type ID
*
* @ return bool true on success
*
*/
2017-09-18 02:20:50 +00:00
protected function checkMultiFields ( $typeID )
2017-03-31 21:28:16 +00:00
{
2017-09-18 02:20:50 +00:00
if ( isset ( $this -> isMultiple [ $typeID ]))
2017-03-31 21:28:16 +00:00
{
2017-09-18 02:20:50 +00:00
return $this -> isMultiple [ $typeID ];
2017-03-31 21:28:16 +00:00
}
elseif ( $type = $this -> getFieldType ( $typeID ))
{
2017-09-18 02:20:50 +00:00
if ( 'repeatable' === $type || 'subform' === $type )
{
$this -> isMultiple [ $typeID ] = true ;
}
else
2017-03-31 21:28:16 +00:00
{
2017-09-18 02:20:50 +00:00
$this -> isMultiple [ $typeID ] = false ;
2017-03-31 21:28:16 +00:00
}
2017-09-18 02:20:50 +00:00
return $this -> isMultiple [ $typeID ];
2017-03-31 21:28:16 +00:00
}
return false ;
}
/**
* Get the field type
*
* @ param string $id The field type id
*
* @ return string field type
*
*/
protected function getFieldType ( $id )
{
if ( ! isset ( $this -> fieldTypes [ $id ]))
{
2024-03-02 20:10:30 +00:00
$properties = GetHelper :: var ( 'fieldtype' , $id , 'id' , 'properties' );
2023-02-27 12:27:41 +00:00
if ( JsonHelper :: check ( $properties ))
2017-03-31 21:28:16 +00:00
{
$properties = json_decode ( $properties , true );
2017-09-18 02:20:50 +00:00
foreach ( $properties as $property )
2017-03-31 21:28:16 +00:00
{
2017-09-18 02:20:50 +00:00
if ( 'type' === $property [ 'name' ])
2017-03-31 21:28:16 +00:00
{
2023-02-27 12:27:41 +00:00
if ( isset ( $property [ 'example' ]) && StringHelper :: check ( $property [ 'example' ]))
2017-03-31 21:28:16 +00:00
{
2017-09-18 02:20:50 +00:00
$this -> fieldTypes [ $id ] = $property [ 'example' ];
break ;
2017-03-31 21:28:16 +00:00
}
}
}
}
// if not found
2024-03-02 20:10:30 +00:00
if ( ! isset ( $this -> fieldTypes [ $id ]) && $name = GetHelper :: var ( 'fieldtype' , $id , 'id' , 'name' ))
2017-03-31 21:28:16 +00:00
{
2023-02-27 12:27:41 +00:00
$this -> fieldTypes [ $id ] = StringHelper :: safe ( $name );
2017-03-31 21:28:16 +00:00
}
}
// return the type
if ( isset ( $this -> fieldTypes [ $id ]))
{
return $this -> fieldTypes [ $id ];
}
return false ;
}
2017-03-18 20:17:15 +00:00
/**
* Set Template and Layout Data
*
* @ param string $default The content to check
*
* @ return void
*
*/
2017-08-20 17:52:35 +00:00
protected function getTemplateLayout ( $default , $user = false )
2017-03-18 20:17:15 +00:00
{
2021-05-17 03:57:02 +00:00
// check if we have base64 encoding
if ( base64_encode ( base64_decode ( $default , true )) === $default )
{
$default = base64_decode ( $default );
}
2017-03-18 20:17:15 +00:00
// set the Template data
2023-02-27 12:27:41 +00:00
$temp1 = GetHelper :: allBetween ( $default , " \$ this->loadTemplate(' " , " ') " );
$temp2 = GetHelper :: allBetween ( $default , '$this->loadTemplate("' , '")' );
2017-03-18 20:17:15 +00:00
$templates = array ();
$again = array ();
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $temp1 ) && JCBArrayHelper :: check ( $temp2 ))
2017-03-18 20:17:15 +00:00
{
$templates = array_merge ( $temp1 , $temp2 );
}
else
{
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $temp1 ))
2017-03-18 20:17:15 +00:00
{
$templates = $temp1 ;
}
2023-02-27 12:27:41 +00:00
elseif ( JCBArrayHelper :: check ( $temp2 ))
2017-03-18 20:17:15 +00:00
{
$templates = $temp2 ;
}
}
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $templates ))
2017-03-18 20:17:15 +00:00
{
foreach ( $templates as $template )
{
2017-08-20 17:52:35 +00:00
$data = $this -> getDataWithAlias ( $template , 'template' );
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $data ))
2017-03-18 20:17:15 +00:00
{
2018-04-17 21:25:03 +00:00
if ( ! isset ( $this -> smartIDs [ 'template' ]) || ! isset ( $this -> smartIDs [ 'template' ][ $data [ 'id' ]]))
2017-03-18 20:17:15 +00:00
{
2018-04-17 21:25:03 +00:00
$this -> setSmartIDs ( $data [ 'id' ], 'template' );
2017-03-18 20:17:15 +00:00
// call self to get child data
$again [] = $data [ 'html' ];
$again [] = $data [ 'php_view' ];
}
}
}
}
// set the layout data
2024-03-02 20:10:30 +00:00
$lay1 = GetHelper :: allBetween ( $default , " LayoutHelper::render(' " , " ', " );
$lay2 = GetHelper :: allBetween ( $default , 'LayoutHelper::render("' , '",' );
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $lay1 ) && JCBArrayHelper :: check ( $lay2 ))
2017-03-18 20:17:15 +00:00
{
$layouts = array_merge ( $lay1 , $lay2 );
}
else
{
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $lay1 ))
2017-03-18 20:17:15 +00:00
{
$layouts = $lay1 ;
}
2023-02-27 12:27:41 +00:00
elseif ( JCBArrayHelper :: check ( $lay2 ))
2017-03-18 20:17:15 +00:00
{
$layouts = $lay2 ;
}
}
2023-02-27 12:27:41 +00:00
if ( isset ( $layouts ) && JCBArrayHelper :: check ( $layouts ))
2017-03-18 20:17:15 +00:00
{
foreach ( $layouts as $layout )
{
2017-08-20 17:52:35 +00:00
$data = $this -> getDataWithAlias ( $layout , 'layout' );
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $data ))
2017-03-18 20:17:15 +00:00
{
2018-04-17 21:25:03 +00:00
if ( ! isset ( $this -> smartIDs [ 'layout' ]) || ! isset ( $this -> smartIDs [ 'layout' ][ $data [ 'id' ]]))
2017-03-18 20:17:15 +00:00
{
2018-04-17 21:25:03 +00:00
$this -> setSmartIDs ( $data [ 'id' ], 'layout' );
2017-03-18 20:17:15 +00:00
// call self to get child data
$again [] = $data [ 'html' ];
$again [] = $data [ 'php_view' ];
2017-03-18 11:16:07 +00:00
}
}
2017-03-18 20:17:15 +00:00
}
}
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $again ))
2017-03-18 20:17:15 +00:00
{
foreach ( $again as $get )
{
2017-08-20 17:52:35 +00:00
$this -> getTemplateLayout ( $get );
2017-03-18 20:17:15 +00:00
}
}
2017-03-31 21:28:16 +00:00
// Set the Data
if ( $user )
{
// add templates
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'template' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'template' ]))
2017-03-31 21:28:16 +00:00
{
2018-04-17 21:25:03 +00:00
$this -> setData ( 'template' , array_values ( $this -> smartIDs [ 'template' ]), 'id' );
2017-03-31 21:28:16 +00:00
}
// add layouts
2023-02-27 12:27:41 +00:00
if ( isset ( $this -> smartIDs [ 'layout' ]) && JCBArrayHelper :: check ( $this -> smartIDs [ 'layout' ]))
2017-03-31 21:28:16 +00:00
{
2018-04-17 21:25:03 +00:00
$this -> setData ( 'layout' , array_values ( $this -> smartIDs [ 'layout' ]), 'id' );
2017-03-31 21:28:16 +00:00
}
}
2017-03-18 20:17:15 +00:00
}
/**
* Get Data With Alias
*
* @ param string $n_ame The alias name
* @ param string $table The table where to find the alias
* @ param string $view The view code name
*
* @ return array The data found with the alias
*
*/
2017-08-20 17:52:35 +00:00
protected function getDataWithAlias ( $n_ame , $table )
2017-03-18 20:17:15 +00:00
{
// Create a new query object.
2017-08-20 17:52:35 +00:00
$query = $this -> _db -> getQuery ( true );
$query -> select ( $this -> _db -> quoteName ( array ( 'a.id' , 'a.alias' , 'a.' . $table , 'a.php_view' , 'a.add_php_view' )));
2017-03-18 20:17:15 +00:00
$query -> from ( '#__componentbuilder_' . $table . ' AS a' );
2017-08-20 17:52:35 +00:00
$this -> _db -> setQuery ( $query );
$rows = $this -> _db -> loadObjectList ();
2017-03-18 20:17:15 +00:00
foreach ( $rows as $row )
{
2023-02-27 12:27:41 +00:00
$k_ey = StringHelper :: safe ( $row -> alias );
2017-03-18 20:17:15 +00:00
$key = preg_replace ( " /[^A-Za-z]/ " , '' , $k_ey );
$name = preg_replace ( " /[^A-Za-z]/ " , '' , $n_ame );
if ( $k_ey == $n_ame || $key == $name )
{
$php_view = '' ;
if ( $row -> add_php_view == 1 )
{
$php_view = base64_decode ( $row -> php_view );
}
$contnent = base64_decode ( $row -> { $table });
// return to continue the search
return array ( 'id' => $row -> id , 'html' => $contnent , 'php_view' => $php_view );
2017-03-18 11:16:07 +00:00
}
}
return false ;
2016-01-30 20:28:43 +00:00
}
2017-03-18 22:55:34 +00:00
/**
2019-03-04 12:47:28 +00:00
* Set the ids of the found code placeholders
2017-03-18 22:55:34 +00:00
*
* @ param object $item The item being searched
* @ param string $target The target table
2019-03-04 12:47:28 +00:00
* @ param string $type The type of placeholder to search and set
2017-03-18 22:55:34 +00:00
*
* @ return void
*
*/
2019-03-04 12:47:28 +00:00
protected function setCodePlaceholdersIds ( $item , $target , $type = 'custom_code' )
2017-03-18 22:55:34 +00:00
{
if ( $keys = $this -> getCodeSearchKeys ( $target ))
{
foreach ( $keys [ 'search' ] as $key )
{
2018-02-20 20:46:29 +00:00
if ( 'id' === $key || 'name' === $key || 'system_name' === $key )
{
continue ;
}
elseif ( ! isset ( $keys [ 'not_base64' ][ $key ]))
2017-03-18 22:55:34 +00:00
{
2023-10-18 07:26:30 +00:00
$value = Base64Helper :: open ( $item -> { $key }, null );
2018-09-28 15:46:21 +00:00
}
2018-10-29 16:38:00 +00:00
elseif ( isset ( $keys [ 'not_base64' ][ $key ]) && 'json' === $keys [ 'not_base64' ][ $key ] && 'xml' === $key ) // just for field search
2018-09-28 15:46:21 +00:00
{
$value = json_decode ( $item -> { $key });
2017-03-18 22:55:34 +00:00
}
else
{
$value = $item -> { $key };
}
2018-09-28 15:46:21 +00:00
// check if we should search for base64 string inside the text
2018-10-29 16:38:00 +00:00
if ( isset ( $keys [ 'base64_search' ]) && isset ( $keys [ 'base64_search' ][ $key ])
&& isset ( $keys [ 'base64_search' ][ $key ][ 'start' ]) && strpos ( $value , $keys [ 'base64_search' ][ $key ][ 'start' ]) !== false )
2018-09-28 15:46:21 +00:00
{
2018-09-29 21:52:22 +00:00
// search and open the base64 strings
2018-10-29 16:38:00 +00:00
$this -> searchOpenBase64 ( $value , $keys [ 'base64_search' ][ $key ]);
2018-09-28 15:46:21 +00:00
}
2019-03-04 12:47:28 +00:00
// based on the type of search
if ( 'custom_code' === $type )
2017-03-18 22:55:34 +00:00
{
2019-03-04 12:47:28 +00:00
// search the value to see if it has custom code
2023-02-27 12:27:41 +00:00
$codeArray = GetHelper :: allBetween ( $value , '[CUSTOMC' . 'ODE=' , ']' );
if ( JCBArrayHelper :: check ( $codeArray ))
2017-03-18 22:55:34 +00:00
{
2019-03-04 12:47:28 +00:00
foreach ( $codeArray as $func )
2017-03-18 22:55:34 +00:00
{
2019-03-04 12:47:28 +00:00
// first make sure we have only the function key
if ( strpos ( $func , '+' ) !== false )
{
$funcArray = explode ( '+' , $func );
$func = $funcArray [ 0 ];
}
if ( ! isset ( $this -> customCodeM [ $func ]))
2017-03-18 22:55:34 +00:00
{
2019-03-04 12:47:28 +00:00
$this -> customCodeM [ $func ] = $func ;
// if numeric add to ids
if ( is_numeric ( $func ))
{
$this -> setSmartIDs ( $func , $type );
}
2023-02-27 12:27:41 +00:00
elseif ( StringHelper :: check ( $func ))
2019-03-04 12:47:28 +00:00
{
2024-03-02 20:10:30 +00:00
if (( $funcID = GetHelper :: var ( $type , $func , 'function_name' , 'id' )) !== false && is_numeric ( $funcID ))
2019-03-04 12:47:28 +00:00
{
$this -> setSmartIDs ( $funcID , $type );
}
else
{
// set a notice that custom code was not found (weird)
}
}
2017-03-18 22:55:34 +00:00
}
2019-03-04 12:47:28 +00:00
}
}
}
elseif ( 'placeholder' === $type )
{
// check if we already have the placeholder search array
2023-02-27 12:27:41 +00:00
if ( ! JCBArrayHelper :: check ( $this -> placeholderM ) && ! JCBArrayHelper :: check ( $this -> placeholderS ))
2019-03-04 12:47:28 +00:00
{
$this -> placeholderS = ComponentbuilderHelper :: getVars ( $type , 1 , 'published' , 'target' );
}
// only continue search if placeholders found
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $this -> placeholderS ))
2019-03-04 12:47:28 +00:00
{
foreach ( $this -> placeholderS as $remove => $placeholder )
{
// search the value to see if it has this placeholder and is not already set
if ( ! isset ( $this -> placeholderM [ $placeholder ]) && strpos ( $value , $placeholder ) !== false )
2017-03-18 22:55:34 +00:00
{
2019-03-04 12:47:28 +00:00
// add only once
$this -> placeholderM [ $placeholder ] = $placeholder ;
unset ( $this -> placeholderS [ $remove ]);
// get the ID
2024-03-02 20:10:30 +00:00
if (( $placeholderID = GetHelper :: var ( $type , $placeholder , 'target' , 'id' )) !== false && is_numeric ( $placeholderID ))
2017-03-18 22:55:34 +00:00
{
2019-03-04 12:47:28 +00:00
$this -> setSmartIDs ( $placeholderID , $type );
2017-03-18 22:55:34 +00:00
}
2018-10-29 16:38:00 +00:00
else
{
2019-03-04 12:47:28 +00:00
// set a notice that placeholder was not found (weird)
2018-10-29 16:38:00 +00:00
}
2017-03-18 22:55:34 +00:00
}
}
}
}
}
}
}
2017-04-06 21:40:22 +00:00
/**
* Set the language strings for this component
*
* @ param int $id The component id
*
* @ return void
*
*/
2020-04-03 18:45:48 +00:00
protected function setLanguageTranslation ( & $id , $target = 'components' )
2017-04-06 21:40:22 +00:00
{
2020-07-28 04:14:49 +00:00
// check if the export of language strings is allowed
if ( $this -> params -> get ( 'export_language_strings' , 1 ) != 1 )
{
return ;
}
2017-04-06 21:40:22 +00:00
// Create a new query object.
2017-08-20 17:52:35 +00:00
$query = $this -> _db -> getQuery ( true );
2017-04-06 21:40:22 +00:00
$query -> select ( array ( 'a.*' ));
$query -> from ( '#__componentbuilder_language_translation AS a' );
// Implement View Level Access
2017-08-20 17:52:35 +00:00
if ( ! $this -> user -> authorise ( 'core.options' , 'com_componentbuilder' ))
2017-04-06 21:40:22 +00:00
{
2017-08-20 17:52:35 +00:00
$groups = implode ( ',' , $this -> user -> getAuthorisedViewLevels ());
2017-04-06 21:40:22 +00:00
$query -> where ( 'a.access IN (' . $groups . ')' );
}
// Order the results by ordering
$query -> order ( 'a.ordering ASC' );
// Load the items
2017-08-20 17:52:35 +00:00
$this -> _db -> setQuery ( $query );
$this -> _db -> execute ();
if ( $this -> _db -> getNumRows ())
2017-04-06 21:40:22 +00:00
{
2017-08-20 17:52:35 +00:00
$items = $this -> _db -> loadObjectList ();
2017-04-06 21:40:22 +00:00
// check if we have items
2023-02-27 12:27:41 +00:00
if ( JCBArrayHelper :: check ( $items ))
2017-04-06 21:40:22 +00:00
{
2018-04-17 21:25:03 +00:00
if ( ! isset ( $this -> smartBox [ 'language_translation' ]))
2017-04-06 21:40:22 +00:00
{
2018-04-17 21:25:03 +00:00
$this -> smartBox [ 'language_translation' ] = array ();
2017-04-06 21:40:22 +00:00
}
foreach ( $items as $item )
{
2023-02-27 12:27:41 +00:00
if ( ! isset ( $this -> smartBox [ 'language_translation' ][ $item -> id ]) && JsonHelper :: check ( $item -> { $target }))
2017-04-06 21:40:22 +00:00
{
2020-04-03 18:45:48 +00:00
$targets = json_decode ( $item -> { $target }, true );
if ( in_array ( $id , $targets ))
2017-04-06 21:40:22 +00:00
{
// load to global object
2018-04-17 21:25:03 +00:00
$this -> smartBox [ 'language_translation' ][ $item -> id ] = $item ;
2017-04-06 21:40:22 +00:00
// add languages
if ( isset ( $item -> translation ))
2017-09-18 00:18:23 +00:00
{
2017-10-28 03:25:33 +00:00
$this -> setData ( 'language' , $this -> getValues ( $item -> translation , 'subform' , 'language' ), 'langtag' );
2017-04-06 21:40:22 +00:00
}
}
}
}
}
}
}
2017-03-30 21:19:12 +00:00
/**
* Get the package name
*
* @ param array $items of all components
*
* @ return string The package name
*
*/
protected function getPackageName ( & $items )
{
foreach ( $items as $item )
{
2017-04-01 13:59:54 +00:00
if ( isset ( $item -> system_name ))
{
2023-02-27 12:27:41 +00:00
return StringHelper :: safe ( $item -> system_name , 'cAmel' );
2017-04-01 13:59:54 +00:00
}
else
{
2023-02-27 12:27:41 +00:00
return StringHelper :: safe ( $item -> name_code );
2017-04-01 13:59:54 +00:00
}
2017-03-30 21:19:12 +00:00
}
}
2018-03-02 01:37:04 +00:00
/**
* Convert the path to a name
*
* @ param string $path The full path
*
* @ return string The path name
*
*/
protected function setDynamicPathName ( $path )
{
// remove the full path if possible
$path = str_replace ( '//' , '/' , $this -> setConstantPath ( $path ));
// now convert to string
return str_replace ( '/' , '__v_d_m__' , $path );
}
/**
* Update real full path value with constant path string
*
* @ param string $path The full path
*
* @ return string The updated path
*
*/
protected function setConstantPath ( $path )
{
return str_replace ( array_values ( ComponentbuilderHelper :: $constantPaths ), array_keys ( ComponentbuilderHelper :: $constantPaths ), $path );
}
/**
* Update constant path with real full path value
*
* @ param string $path The full path
*
* @ return string The updated path
*
*/
protected function setFullPath ( $path )
{
return str_replace ( array_keys ( ComponentbuilderHelper :: $constantPaths ), array_values ( ComponentbuilderHelper :: $constantPaths ), $path );
}
2018-02-27 12:17:38 +00:00
2018-09-29 21:52:22 +00:00
/**
* Search for base64 strings and decode them
*
* @ param string $value The string to search
* @ param array $target The target search values
*
* @ return void
*
*/
protected function searchOpenBase64 ( & $value , & $target )
{
// first get the start property (if dynamic)
$starts = array ();
if ( isset ( $target [ '_start' ]))
{
// get all values
2023-10-18 07:26:30 +00:00
$allBetween = GetHelper :: allBetween ( $value , $target [ 'start' ], $target [ '_start' ]);
2018-09-29 21:52:22 +00:00
// just again make sure we found some
2024-03-02 20:10:30 +00:00
if ( UtilitiesArrayHelper :: check ( $allBetween ))
2018-09-29 21:52:22 +00:00
{
if ( count (( array ) $allBetween ) > 1 )
{
// search for many
foreach ( $allBetween as $between )
{
// load the starting property
$start = $target [ 'start' ];
$start .= $between ;
$start .= $target [ '_start' ];
$starts [] = $start ;
}
}
else
{
// load the starting property
$start = $target [ 'start' ];
$start .= array_values ( $allBetween )[ 0 ];
$start .= $target [ '_start' ];
$starts [] = $start ;
}
}
}
else
{
$starts [] = $target [ 'start' ];
}
// has any been found
2024-03-02 20:10:30 +00:00
if ( UtilitiesArrayHelper :: check ( $starts ))
2018-09-29 21:52:22 +00:00
{
foreach ( $starts as $_start )
{
// get the base64 string
2023-10-18 07:26:30 +00:00
$base64 = GetHelper :: between ( $value , $_start , $target [ 'end' ]);
2018-09-29 21:52:22 +00:00
// now open the base64 text
2023-10-18 07:26:30 +00:00
$tmp = Base64Helper :: open ( $base64 );
2018-09-29 21:52:22 +00:00
// insert it back into the value (so we still search the whole string)
$value = str_replace ( $base64 , $tmp , $value );
}
}
}
2018-09-28 15:46:21 +00:00
/**
* The code search keys / targets
*
* @ var array
*/
protected $codeSearchKeys = array (
2018-10-29 16:38:00 +00:00
// #__componentbuilder_joomla_component (a)
2018-09-28 15:46:21 +00:00
'joomla_component' => array (
2018-10-29 16:38:00 +00:00
'search' => array ( 'id' , 'system_name' , 'php_preflight_install' , 'php_postflight_install' ,
'php_preflight_update' , 'php_postflight_update' , 'php_method_uninstall' ,
'php_helper_admin' , 'php_admin_event' , 'php_helper_both' , 'php_helper_site' ,
2019-12-03 02:17:35 +00:00
'php_site_event' , 'javascript' , 'readme' , 'sql' , 'sql_uninstall' ),
2018-09-28 15:46:21 +00:00
'views' => 'joomla_components' ,
'not_base64' => array (),
'name' => 'system_name'
),
2018-10-29 16:38:00 +00:00
// #__componentbuilder_component_dashboard (b)
2018-09-28 15:46:21 +00:00
'component_dashboard' => array (
2018-10-29 16:38:00 +00:00
'search' => array ( 'id' , 'joomla_component' , 'php_dashboard_methods' , 'dashboard_tab' ),
2018-09-28 15:46:21 +00:00
'views' => 'components_dashboard' ,
'not_base64' => array ( 'dashboard_tab' => 'json' ),
'name' => 'joomla_component->id:joomla_component.system_name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_component_placeholders (c)
'component_placeholders' => array (
'search' => array ( 'id' , 'joomla_component' , 'addplaceholders' ),
'views' => 'components_placeholders' ,
'not_base64' => array ( 'addplaceholders' => 'json' ),
'name' => 'joomla_component->id:joomla_component.system_name'
),
// #__componentbuilder_admin_view (d)
2018-09-28 15:46:21 +00:00
'admin_view' => array (
2018-10-29 16:38:00 +00:00
'search' => array ( 'id' , 'system_name' , 'javascript_view_file' , 'javascript_view_footer' ,
'javascript_views_file' , 'javascript_views_footer' , 'html_import_view' ,
'php_after_delete' , 'php_after_publish' , 'php_ajaxmethod' , 'php_allowedit' , 'php_batchcopy' ,
'php_batchmove' , 'php_before_delete' , 'php_before_publish' , 'php_before_save' , 'php_controller' ,
'php_controller_list' , 'php_document' , 'php_getitem' , 'php_getitems' , 'php_getitems_after_all' ,
'php_getlistquery' , 'php_import' , 'php_import_display' , 'php_import_ext' , 'php_import_headers' , 'php_getform' ,
2020-10-11 02:02:00 +00:00
'php_import_save' , 'php_import_setdata' , 'php_model' , 'php_model_list' , 'php_postsavehook' , 'php_save' , 'sql' ),
2018-09-28 15:46:21 +00:00
'views' => 'admin_views' ,
'not_base64' => array (),
'name' => 'system_name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_admin_fields_relations (e)
2018-09-28 15:46:21 +00:00
'admin_fields_relations' => array (
'search' => array ( 'id' , 'admin_view' , 'addrelations' ),
'views' => 'admins_fields_relations' ,
'not_base64' => array ( 'addrelations' => 'json' ),
'name' => 'admin_view->id:admin_view.system_name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_admin_custom_tabs (f)
'admin_custom_tabs' => array (
'search' => array ( 'id' , 'admin_view' , 'tabs' ),
'views' => 'admins_custom_tabs' ,
'not_base64' => array ( 'tabs' => 'json' ),
'name' => 'admin_view->id:admin_view.system_name'
),
// #__componentbuilder_custom_admin_view (g)
2018-09-28 15:46:21 +00:00
'custom_admin_view' => array (
2018-10-29 16:38:00 +00:00
'search' => array ( 'id' , 'system_name' , 'default' , 'php_view' , 'php_jview' , 'php_jview_display' , 'php_document' ,
2020-01-03 01:41:55 +00:00
'javascript_file' , 'js_document' , 'css_document' , 'css' , 'php_ajaxmethod' , 'php_model' , 'php_controller' ),
2018-09-28 15:46:21 +00:00
'views' => 'custom_admin_views' ,
'not_base64' => array (),
'name' => 'system_name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_site_view (h)
2018-09-28 15:46:21 +00:00
'site_view' => array (
2018-10-29 16:38:00 +00:00
'search' => array ( 'id' , 'system_name' , 'default' , 'php_view' , 'php_jview' , 'php_jview_display' , 'php_document' ,
2020-01-03 01:41:55 +00:00
'javascript_file' , 'js_document' , 'css_document' , 'css' , 'php_ajaxmethod' , 'php_model' , 'php_controller' ),
2018-09-28 15:46:21 +00:00
'views' => 'site_views' ,
'not_base64' => array (),
'name' => 'system_name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_field (i)
2018-09-28 15:46:21 +00:00
'field' => array (
2019-10-16 20:34:36 +00:00
'search' => array ( 'id' , 'name' , 'xml' , 'javascript_view_footer' , 'javascript_views_footer' , 'on_save_model_field' , 'on_get_model_field' , 'initiator_on_save_model' , 'initiator_on_get_model' ),
2018-09-28 15:46:21 +00:00
'views' => 'fields' ,
'not_base64' => array ( 'xml' => 'json' ),
'base64_search' => array ( 'xml' => array ( 'start' => 'type_php' , '_start' => '="' , 'end' => '"' )),
'name' => 'name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_fieldtype (j)
2018-09-28 15:46:21 +00:00
'fieldtype' => array (
'search' => array ( 'id' , 'name' , 'properties' ),
'views' => 'fieldtypes' ,
'not_base64' => array ( 'properties' => 'json' ),
'name' => 'name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_dynamic_get (k)
2018-09-28 15:46:21 +00:00
'dynamic_get' => array (
2018-10-29 16:38:00 +00:00
'search' => array ( 'id' , 'name' , 'php_before_getitem' , 'php_after_getitem' , 'php_before_getitems' , 'php_after_getitems' ,
2019-10-11 13:41:00 +00:00
'php_getlistquery' , 'php_calculation' ),
2018-09-28 15:46:21 +00:00
'views' => 'dynamic_gets' ,
'not_base64' => array (),
'name' => 'name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_template (l)
2018-09-28 15:46:21 +00:00
'template' => array (
2018-10-29 16:38:00 +00:00
'search' => array ( 'id' , 'name' , 'php_view' , 'template' ),
2018-09-28 15:46:21 +00:00
'views' => 'templates' ,
'not_base64' => array (),
'name' => 'name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_layout (m)
2018-09-28 15:46:21 +00:00
'layout' => array (
2018-10-29 16:38:00 +00:00
'search' => array ( 'id' , 'name' , 'php_view' , 'layout' ),
2018-09-28 15:46:21 +00:00
'views' => 'layouts' ,
'not_base64' => array (),
'name' => 'name'
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_library (n)
2018-09-28 15:46:21 +00:00
'library' => array (
'search' => array ( 'id' , 'name' , 'php_setdocument' ),
'views' => 'libraries' ,
'not_base64' => array (),
'name' => 'name'
2018-11-27 13:05:47 +00:00
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_custom_code (o)
2018-11-27 13:05:47 +00:00
'custom_code' => array (
'search' => array ( 'id' , 'system_name' , 'code' ),
'views' => 'custom_codes' ,
'not_base64' => array (),
'name' => 'system_name'
2019-01-31 21:44:21 +00:00
),
2019-05-20 20:54:40 +00:00
// #__componentbuilder_validation_rule (p)
2019-01-31 21:44:21 +00:00
'validation_rule' => array (
'search' => array ( 'id' , 'name' , 'php' ),
'views' => 'validation_rules' ,
'not_base64' => array (),
'name' => 'name'
2019-07-16 23:15:42 +00:00
),
2019-12-06 05:31:32 +00:00
// #__componentbuilder_joomla_module (q)
'joomla_module' => array (
'search' => array ( 'id' , 'system_name' , 'name' , 'default' , 'description' , 'mod_code' , 'class_helper_header' , 'class_helper_code' , 'php_script_construct' , 'php_preflight_install' , 'php_preflight_update' ,
'php_preflight_uninstall' , 'php_postflight_install' , 'php_postflight_update' , 'php_method_uninstall' , 'sql' , 'sql_uninstall' , 'readme' ),
'views' => 'joomla_modules' ,
'not_base64' => array ( 'description' => 'string' , 'readme' => 'string' ),
'name' => 'system_name'
),
// #__componentbuilder_joomla_plugin (r)
2019-07-16 23:15:42 +00:00
'joomla_plugin' => array (
2019-08-15 14:26:46 +00:00
'search' => array ( 'id' , 'system_name' , 'name' , 'main_class_code' , 'head' , 'description' , 'php_script_construct' , 'php_preflight_install' , 'php_preflight_update' ,
2019-12-06 05:31:32 +00:00
'php_preflight_uninstall' , 'php_postflight_install' , 'php_postflight_update' , 'php_method_uninstall' , 'sql' , 'sql_uninstall' , 'readme' ),
2019-07-16 23:15:42 +00:00
'views' => 'joomla_plugins' ,
2019-12-06 05:31:32 +00:00
'not_base64' => array ( 'description' => 'string' , 'readme' => 'string' ),
2019-08-12 21:30:31 +00:00
'name' => 'system_name'
2019-07-16 23:15:42 +00:00
),
2019-12-06 05:31:32 +00:00
// #__componentbuilder_class_extends (s)
2019-07-16 23:15:42 +00:00
'class_extends' => array (
'search' => array ( 'id' , 'name' , 'head' , 'comment' ),
'views' => 'class_extendings' ,
'not_base64' => array (),
'name' => 'name'
),
2019-12-06 05:31:32 +00:00
// #__componentbuilder_class_property (t)
2019-07-16 23:15:42 +00:00
'class_property' => array (
'search' => array ( 'id' , 'name' , 'default' , 'comment' ),
'views' => 'class_properties' ,
'not_base64' => array (),
'name' => 'name'
),
2019-12-06 05:31:32 +00:00
// #__componentbuilder_class_method (u)
2019-07-16 23:15:42 +00:00
'class_method' => array (
'search' => array ( 'id' , 'name' , 'code' , 'comment' ),
'views' => 'class_methods' ,
'not_base64' => array (),
'name' => 'name'
2021-10-18 20:12:19 +00:00
),
// #__componentbuilder_power (v)
2022-05-16 04:25:03 +00:00
'power' => array (
2021-12-21 14:44:50 +00:00
'search' => array ( 'id' , 'system_name' , 'name' , 'description' , 'head' , 'namespace' , 'main_class_code' ),
2021-10-18 20:12:19 +00:00
'views' => 'powers' ,
'not_base64' => array ( 'description' ),
2021-12-21 14:44:50 +00:00
'name' => 'system_name'
2018-09-28 15:46:21 +00:00
)
);
2017-03-18 22:55:34 +00:00
/**
* Get the keys of the values to search custom code in
*
2018-09-29 00:57:11 +00:00
* @ param string $target The table targeted
2018-02-20 20:46:29 +00:00
* @ param string $type The type of get
2017-03-18 22:55:34 +00:00
*
* @ return array The query options
*
*/
2018-02-20 20:46:29 +00:00
protected function getCodeSearchKeys ( $target , $type = null )
2017-03-18 22:55:34 +00:00
{
2018-02-20 20:46:29 +00:00
// set the template if type is query
if ( 'query' === $type )
{
2018-09-28 15:46:21 +00:00
// setup the tables
$tables = array ();
$key = 'a' ;
foreach ( array_keys ( $this -> codeSearchKeys ) as $table )
{
$tables [ $key ] = $table ;
$key ++ ;
}
2018-02-20 20:46:29 +00:00
// check if we have a match
if ( isset ( $tables [ $target ]))
{
$target = $tables [ $target ];
}
}
// return result ready for a.query
2019-01-31 21:44:21 +00:00
if (( 'query' === $type || 'query_' === $type ) && isset ( $this -> codeSearchKeys [ $target ]))
2018-02-20 20:46:29 +00:00
{
2018-09-28 15:46:21 +00:00
// set the targets
$codeSearchTarget = $this -> codeSearchKeys [ $target ];
2018-02-20 20:46:29 +00:00
// add the .a to the selection array
2018-09-28 15:46:21 +00:00
$codeSearchTarget [ 'select' ] = array_map ( function ( $select ) { return 'a.' . $select ; }, $codeSearchTarget [ 'search' ]);
2018-02-20 20:46:29 +00:00
// also set the table
2018-09-28 15:46:21 +00:00
$codeSearchTarget [ 'table' ] = $target ;
2018-02-20 20:46:29 +00:00
// remove search
2018-09-28 15:46:21 +00:00
unset ( $codeSearchTarget [ 'search' ]);
// return targeted array to use in query
return $codeSearchTarget ;
2018-02-20 20:46:29 +00:00
}
2018-09-28 15:46:21 +00:00
// does the target exist
elseif ( isset ( $this -> codeSearchKeys [ $target ]))
2017-03-18 22:55:34 +00:00
{
2018-09-28 15:46:21 +00:00
// return target array values to use in search
return $this -> codeSearchKeys [ $target ];
2017-03-18 22:55:34 +00:00
}
return false ;
2018-02-27 12:17:38 +00:00
}
2021-03-05 03:08:47 +00:00
/**
* Method to auto - populate the model state .
*
* Note . Calling getState in this method will result in recursion .
*
* @ param string $ordering An optional ordering field .
* @ param string $direction An optional direction ( asc | desc ) .
*
* @ return void
*
*/
protected function populateState ( $ordering = null , $direction = null )
{
2024-03-02 20:10:30 +00:00
$app = Factory :: getApplication ();
2021-03-05 03:08:47 +00:00
// Adjust the context to support modal layouts.
if ( $layout = $app -> input -> get ( 'layout' ))
{
$this -> context .= '.' . $layout ;
2020-11-19 03:07:18 +00:00
}
2016-01-30 20:28:43 +00:00
2020-12-03 05:24:20 +00:00
// Check if the form was submitted
$formSubmited = $app -> input -> post -> get ( 'form_submited' );
2020-11-19 03:07:18 +00:00
$access = $this -> getUserStateFromRequest ( $this -> context . '.filter.access' , 'filter_access' , 0 , 'int' );
2020-12-03 05:24:20 +00:00
if ( $formSubmited )
{
$access = $app -> input -> post -> get ( 'access' );
$this -> setState ( 'filter.access' , $access );
}
2016-01-30 20:28:43 +00:00
2020-11-19 03:07:18 +00:00
$published = $this -> getUserStateFromRequest ( $this -> context . '.filter.published' , 'filter_published' , '' );
$this -> setState ( 'filter.published' , $published );
$created_by = $this -> getUserStateFromRequest ( $this -> context . '.filter.created_by' , 'filter_created_by' , '' );
$this -> setState ( 'filter.created_by' , $created_by );
$sorting = $this -> getUserStateFromRequest ( $this -> context . '.filter.sorting' , 'filter_sorting' , 0 , 'int' );
$this -> setState ( 'filter.sorting' , $sorting );
$search = $this -> getUserStateFromRequest ( $this -> context . '.filter.search' , 'filter_search' );
$this -> setState ( 'filter.search' , $search );
2016-01-30 20:28:43 +00:00
$companyname = $this -> getUserStateFromRequest ( $this -> context . '.filter.companyname' , 'filter_companyname' );
2020-12-03 05:24:20 +00:00
if ( $formSubmited )
{
$companyname = $app -> input -> post -> get ( 'companyname' );
$this -> setState ( 'filter.companyname' , $companyname );
}
2016-01-30 20:28:43 +00:00
$author = $this -> getUserStateFromRequest ( $this -> context . '.filter.author' , 'filter_author' );
2020-12-03 05:24:20 +00:00
if ( $formSubmited )
{
$author = $app -> input -> post -> get ( 'author' );
$this -> setState ( 'filter.author' , $author );
}
2020-11-19 03:07:18 +00:00
$system_name = $this -> getUserStateFromRequest ( $this -> context . '.filter.system_name' , 'filter_system_name' );
2020-12-03 05:24:20 +00:00
if ( $formSubmited )
{
$system_name = $app -> input -> post -> get ( 'system_name' );
$this -> setState ( 'filter.system_name' , $system_name );
}
2020-11-19 03:07:18 +00:00
$name_code = $this -> getUserStateFromRequest ( $this -> context . '.filter.name_code' , 'filter_name_code' );
2020-12-03 05:24:20 +00:00
if ( $formSubmited )
{
$name_code = $app -> input -> post -> get ( 'name_code' );
$this -> setState ( 'filter.name_code' , $name_code );
}
2020-11-19 03:07:18 +00:00
$short_description = $this -> getUserStateFromRequest ( $this -> context . '.filter.short_description' , 'filter_short_description' );
2020-12-03 05:24:20 +00:00
if ( $formSubmited )
{
$short_description = $app -> input -> post -> get ( 'short_description' );
$this -> setState ( 'filter.short_description' , $short_description );
2021-01-30 13:36:03 +00:00
}
$created = $this -> getUserStateFromRequest ( $this -> context . '.filter.created' , 'filter_created' );
if ( $formSubmited )
{
$created = $app -> input -> post -> get ( 'created' );
$this -> setState ( 'filter.created' , $created );
}
$modified = $this -> getUserStateFromRequest ( $this -> context . '.filter.modified' , 'filter_modified' );
if ( $formSubmited )
{
$modified = $app -> input -> post -> get ( 'modified' );
$this -> setState ( 'filter.modified' , $modified );
2021-03-05 03:08:47 +00:00
}
// List state information.
parent :: populateState ( $ordering , $direction );
}
2024-03-02 20:10:30 +00:00
2021-03-05 03:08:47 +00:00
/**
* Method to get an array of data items .
*
* @ return mixed An array of data items on success , false on failure .
*/
public function getItems ()
2018-09-11 20:28:17 +00:00
{
2022-02-02 11:45:15 +00:00
// Check in items
2016-01-30 20:28:43 +00:00
$this -> checkInNow ();
2021-03-05 03:08:47 +00:00
// load parent items
2017-10-14 18:07:23 +00:00
$items = parent :: getItems ();
2019-09-10 16:47:39 +00:00
// Set values to display correctly.
2024-03-02 20:10:30 +00:00
if ( UtilitiesArrayHelper :: check ( $items ))
2017-10-14 18:07:23 +00:00
{
2019-09-05 21:12:56 +00:00
// Get the user object if not set.
2024-03-02 20:10:30 +00:00
if ( ! isset ( $user ) || ! ObjectHelper :: check ( $user ))
2019-09-05 21:12:56 +00:00
{
2024-03-02 20:10:30 +00:00
$user = Factory :: getUser ();
2019-09-05 21:12:56 +00:00
}
2017-10-14 18:07:23 +00:00
foreach ( $items as $nr => & $item )
{
2019-09-05 21:12:56 +00:00
// Remove items the user can't access.
$access = ( $user -> authorise ( 'joomla_component.access' , 'com_componentbuilder.joomla_component.' . ( int ) $item -> id ) && $user -> authorise ( 'joomla_component.access' , 'com_componentbuilder' ));
2017-10-14 18:07:23 +00:00
if ( ! $access )
{
unset ( $items [ $nr ]);
continue ;
}
}
2021-03-05 03:08:47 +00:00
}
2024-03-02 20:10:30 +00:00
2021-03-05 03:08:47 +00:00
// return items
return $items ;
}
2024-03-02 20:10:30 +00:00
2021-03-05 03:08:47 +00:00
/**
* Method to build an SQL query to load the list data .
*
2024-03-02 20:10:30 +00:00
* @ return string An SQL query
2021-03-05 03:08:47 +00:00
*/
protected function getListQuery ()
{
2016-01-30 20:28:43 +00:00
// Get the user object.
2024-03-02 20:10:30 +00:00
$user = Factory :: getUser ();
2016-01-30 20:28:43 +00:00
// Create a new query object.
2024-03-02 20:10:30 +00:00
$db = Factory :: getDBO ();
2016-01-30 20:28:43 +00:00
$query = $db -> getQuery ( true );
// Select some fields
$query -> select ( 'a.*' );
// From the componentbuilder_item table
2017-02-16 14:02:23 +00:00
$query -> from ( $db -> quoteName ( '#__componentbuilder_joomla_component' , 'a' ));
2016-01-30 20:28:43 +00:00
// Filter by published state
$published = $this -> getState ( 'filter.published' );
if ( is_numeric ( $published ))
{
$query -> where ( 'a.published = ' . ( int ) $published );
}
elseif ( $published === '' )
{
$query -> where ( '(a.published = 0 OR a.published = 1)' );
}
// Join over the asset groups.
$query -> select ( 'ag.title AS access_level' );
$query -> join ( 'LEFT' , '#__viewlevels AS ag ON ag.id = a.access' );
// Filter by access level.
2020-12-03 00:13:49 +00:00
$_access = $this -> getState ( 'filter.access' );
if ( $_access && is_numeric ( $_access ))
2016-01-30 20:28:43 +00:00
{
2020-12-03 00:13:49 +00:00
$query -> where ( 'a.access = ' . ( int ) $_access );
}
2024-03-02 20:10:30 +00:00
elseif ( UtilitiesArrayHelper :: check ( $_access ))
2020-12-03 00:13:49 +00:00
{
// Secure the array for the query
$_access = ArrayHelper :: toInteger ( $_access );
// Filter by the Access Array.
$query -> where ( 'a.access IN (' . implode ( ',' , $_access ) . ')' );
2016-01-30 20:28:43 +00:00
}
// Implement View Level Access
if ( ! $user -> authorise ( 'core.options' , 'com_componentbuilder' ))
{
$groups = implode ( ',' , $user -> getAuthorisedViewLevels ());
$query -> where ( 'a.access IN (' . $groups . ')' );
}
// Filter by search.
$search = $this -> getState ( 'filter.search' );
if ( ! empty ( $search ))
{
if ( stripos ( $search , 'id:' ) === 0 )
{
$query -> where ( 'a.id = ' . ( int ) substr ( $search , 3 ));
}
else
{
2016-10-23 22:48:26 +00:00
$search = $db -> quote ( '%' . $db -> escape ( $search ) . '%' );
2018-08-19 20:15:43 +00:00
$query -> where ( '(a.system_name LIKE ' . $search . ' OR a.name_code LIKE ' . $search . ' OR a.short_description LIKE ' . $search . ' OR a.companyname LIKE ' . $search . ' OR a.author LIKE ' . $search . ' OR a.email LIKE ' . $search . ' OR a.website LIKE ' . $search . ' OR a.name LIKE ' . $search . ')' );
2016-01-30 20:28:43 +00:00
}
}
// Filter by Companyname.
2020-11-30 03:59:45 +00:00
$_companyname = $this -> getState ( 'filter.companyname' );
if ( is_numeric ( $_companyname ))
2016-01-30 20:28:43 +00:00
{
2020-11-30 03:59:45 +00:00
if ( is_float ( $_companyname ))
{
$query -> where ( 'a.companyname = ' . ( float ) $_companyname );
}
else
{
$query -> where ( 'a.companyname = ' . ( int ) $_companyname );
}
}
2024-03-02 20:10:30 +00:00
elseif ( StringHelper :: check ( $_companyname ))
2020-11-30 03:59:45 +00:00
{
$query -> where ( 'a.companyname = ' . $db -> quote ( $db -> escape ( $_companyname )));
2016-01-30 20:28:43 +00:00
}
2024-03-02 20:10:30 +00:00
elseif ( UtilitiesArrayHelper :: check ( $_companyname ))
2021-01-15 07:13:06 +00:00
{
// Secure the array for the query
$_companyname = array_map ( function ( $val ) use ( & $db ) {
if ( is_numeric ( $val ))
{
if ( is_float ( $val ))
{
return ( float ) $val ;
}
else
{
return ( int ) $val ;
}
}
2024-03-02 20:10:30 +00:00
elseif ( StringHelper :: check ( $val ))
2021-01-15 07:13:06 +00:00
{
return $db -> quote ( $db -> escape ( $val ));
}
}, $_companyname );
// Filter by the Companyname Array.
$query -> where ( 'a.companyname IN (' . implode ( ',' , $_companyname ) . ')' );
}
2016-01-30 20:28:43 +00:00
// Filter by Author.
2020-11-30 03:59:45 +00:00
$_author = $this -> getState ( 'filter.author' );
if ( is_numeric ( $_author ))
{
if ( is_float ( $_author ))
{
$query -> where ( 'a.author = ' . ( float ) $_author );
}
else
{
$query -> where ( 'a.author = ' . ( int ) $_author );
}
}
2024-03-02 20:10:30 +00:00
elseif ( StringHelper :: check ( $_author ))
2016-01-30 20:28:43 +00:00
{
2020-11-30 03:59:45 +00:00
$query -> where ( 'a.author = ' . $db -> quote ( $db -> escape ( $_author )));
2016-01-30 20:28:43 +00:00
}
2024-03-02 20:10:30 +00:00
elseif ( UtilitiesArrayHelper :: check ( $_author ))
2021-01-15 07:13:06 +00:00
{
// Secure the array for the query
$_author = array_map ( function ( $val ) use ( & $db ) {
if ( is_numeric ( $val ))
{
if ( is_float ( $val ))
{
return ( float ) $val ;
}
else
{
return ( int ) $val ;
}
}
2024-03-02 20:10:30 +00:00
elseif ( StringHelper :: check ( $val ))
2021-01-15 07:13:06 +00:00
{
return $db -> quote ( $db -> escape ( $val ));
}
}, $_author );
// Filter by the Author Array.
$query -> where ( 'a.author IN (' . implode ( ',' , $_author ) . ')' );
}
2016-01-30 20:28:43 +00:00
2021-02-02 21:13:59 +00:00
// Add the list ordering clause.
2024-03-02 20:10:30 +00:00
$orderCol = $this -> getState ( 'list.ordering' , 'a.id' );
$orderDirn = $this -> getState ( 'list.direction' , 'desc' );
2021-02-02 21:13:59 +00:00
if ( $orderCol != '' )
{
2024-03-02 20:10:30 +00:00
// Check that the order direction is valid encase we have a field called direction as part of filers.
$orderDirn = ( is_string ( $orderDirn ) && in_array ( strtolower ( $orderDirn ), [ 'asc' , 'desc' ])) ? $orderDirn : 'desc' ;
2021-02-02 21:13:59 +00:00
$query -> order ( $db -> escape ( $orderCol . ' ' . $orderDirn ));
}
2021-03-05 03:08:47 +00:00
return $query ;
2016-01-30 20:28:43 +00:00
}
/**
2018-05-26 10:03:08 +00:00
* Method to get list export data .
*
2019-09-05 21:12:56 +00:00
* @ param array $pks The ids of the items to get
* @ param JUser $user The user making the request
*
2018-05-26 10:03:08 +00:00
* @ return mixed An array of data items on success , false on failure .
*/
2019-09-04 11:52:31 +00:00
public function getExportData ( $pks , $user = null )
2016-01-30 20:28:43 +00:00
{
// setup the query
2024-03-02 20:10:30 +00:00
if (( $pks_size = UtilitiesArrayHelper :: check ( $pks )) !== false || 'bulk' === $pks )
2016-01-30 20:28:43 +00:00
{
2019-09-05 21:12:56 +00:00
// Set a value to know this is export method. (USE IN CUSTOM CODE TO ALTER OUTCOME)
2016-06-03 06:28:32 +00:00
$_export = true ;
2019-09-04 11:52:31 +00:00
// Get the user object if not set.
2024-03-02 20:10:30 +00:00
if ( ! isset ( $user ) || ! ObjectHelper :: check ( $user ))
2019-09-04 11:52:31 +00:00
{
2024-03-02 20:10:30 +00:00
$user = Factory :: getUser ();
2019-09-04 11:52:31 +00:00
}
2016-01-30 20:28:43 +00:00
// Create a new query object.
2024-03-02 20:10:30 +00:00
$db = Factory :: getDBO ();
2016-01-30 20:28:43 +00:00
$query = $db -> getQuery ( true );
// Select some fields
$query -> select ( 'a.*' );
2017-02-16 14:02:23 +00:00
// From the componentbuilder_joomla_component table
$query -> from ( $db -> quoteName ( '#__componentbuilder_joomla_component' , 'a' ));
2020-07-24 04:11:38 +00:00
// The bulk export path
if ( 'bulk' === $pks )
{
$query -> where ( 'a.id > 0' );
}
// A large array of ID's will not work out well
elseif ( $pks_size > 500 )
{
// Use lowest ID
$query -> where ( 'a.id >= ' . ( int ) min ( $pks ));
// Use highest ID
$query -> where ( 'a.id <= ' . ( int ) max ( $pks ));
}
// The normal default path
else
{
$query -> where ( 'a.id IN (' . implode ( ',' , $pks ) . ')' );
}
2016-01-30 20:28:43 +00:00
// Implement View Level Access
if ( ! $user -> authorise ( 'core.options' , 'com_componentbuilder' ))
{
$groups = implode ( ',' , $user -> getAuthorisedViewLevels ());
$query -> where ( 'a.access IN (' . $groups . ')' );
}
2021-02-02 21:13:59 +00:00
// Order the results by ordering
$query -> order ( 'a.id desc' );
2016-01-30 20:28:43 +00:00
// Load the items
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> getNumRows ())
{
$items = $db -> loadObjectList ();
2017-09-13 00:37:43 +00:00
// Get the basic encryption key.
2016-01-30 20:28:43 +00:00
$basickey = ComponentbuilderHelper :: getCryptKey ( 'basic' );
2017-09-13 00:37:43 +00:00
// Get the encryption object.
2023-10-18 07:26:30 +00:00
$basic = new AES ( $basickey );
2016-01-30 20:28:43 +00:00
2019-09-10 16:47:39 +00:00
// Set values to display correctly.
2024-03-02 20:10:30 +00:00
if ( UtilitiesArrayHelper :: check ( $items ))
2016-01-30 20:28:43 +00:00
{
foreach ( $items as $nr => & $item )
{
2019-09-05 21:12:56 +00:00
// Remove items the user can't access.
$access = ( $user -> authorise ( 'joomla_component.access' , 'com_componentbuilder.joomla_component.' . ( int ) $item -> id ) && $user -> authorise ( 'joomla_component.access' , 'com_componentbuilder' ));
2017-10-14 18:07:23 +00:00
if ( ! $access )
{
unset ( $items [ $nr ]);
continue ;
}
2024-03-02 20:10:30 +00:00
// decode sql_uninstall
$item -> sql_uninstall = base64_decode ( $item -> sql_uninstall );
2024-04-06 17:48:58 +00:00
// decode php_postflight_install
$item -> php_postflight_install = base64_decode ( $item -> php_postflight_install );
// decode php_site_event
$item -> php_site_event = base64_decode ( $item -> php_site_event );
2024-03-02 20:10:30 +00:00
// decode php_helper_both
$item -> php_helper_both = base64_decode ( $item -> php_helper_both );
// decode php_admin_event
$item -> php_admin_event = base64_decode ( $item -> php_admin_event );
2024-04-06 17:48:58 +00:00
// decode css_admin
$item -> css_admin = base64_decode ( $item -> css_admin );
// decode php_preflight_install
$item -> php_preflight_install = base64_decode ( $item -> php_preflight_install );
// decode php_method_uninstall
$item -> php_method_uninstall = base64_decode ( $item -> php_method_uninstall );
2020-12-10 01:24:29 +00:00
if ( $basickey && ! is_numeric ( $item -> whmcs_key ) && $item -> whmcs_key === base64_encode ( base64_decode ( $item -> whmcs_key , true )))
{
// decrypt whmcs_key
$item -> whmcs_key = $basic -> decryptString ( $item -> whmcs_key );
}
2024-04-06 17:48:58 +00:00
// decode php_helper_admin
$item -> php_helper_admin = base64_decode ( $item -> php_helper_admin );
// decode php_helper_site
$item -> php_helper_site = base64_decode ( $item -> php_helper_site );
2024-03-07 19:23:32 +00:00
// decode javascript
$item -> javascript = base64_decode ( $item -> javascript );
2021-01-30 13:36:03 +00:00
// decode css_site
$item -> css_site = base64_decode ( $item -> css_site );
2020-01-03 01:41:55 +00:00
// decode php_preflight_update
$item -> php_preflight_update = base64_decode ( $item -> php_preflight_update );
2020-12-10 01:24:29 +00:00
// decode php_postflight_update
$item -> php_postflight_update = base64_decode ( $item -> php_postflight_update );
// decode sql
$item -> sql = base64_decode ( $item -> sql );
2024-04-06 17:48:58 +00:00
if ( $basickey && ! is_numeric ( $item -> crowdin_username ) && $item -> crowdin_username === base64_encode ( base64_decode ( $item -> crowdin_username , true )))
{
// decrypt crowdin_username
$item -> crowdin_username = $basic -> decryptString ( $item -> crowdin_username );
}
// decode buildcompsql
$item -> buildcompsql = base64_decode ( $item -> buildcompsql );
2020-01-03 01:41:55 +00:00
if ( $basickey && ! is_numeric ( $item -> export_key ) && $item -> export_key === base64_encode ( base64_decode ( $item -> export_key , true )))
{
// decrypt export_key
$item -> export_key = $basic -> decryptString ( $item -> export_key );
}
// decode readme
$item -> readme = base64_decode ( $item -> readme );
2019-05-15 17:39:27 +00:00
if ( $basickey && ! is_numeric ( $item -> crowdin_project_api_key ) && $item -> crowdin_project_api_key === base64_encode ( base64_decode ( $item -> crowdin_project_api_key , true )))
{
// decrypt crowdin_project_api_key
$item -> crowdin_project_api_key = $basic -> decryptString ( $item -> crowdin_project_api_key );
}
2020-01-03 01:41:55 +00:00
if ( $basickey && ! is_numeric ( $item -> crowdin_account_api_key ) && $item -> crowdin_account_api_key === base64_encode ( base64_decode ( $item -> crowdin_account_api_key , true )))
2019-05-15 17:39:27 +00:00
{
2020-01-03 01:41:55 +00:00
// decrypt crowdin_account_api_key
$item -> crowdin_account_api_key = $basic -> decryptString ( $item -> crowdin_account_api_key );
2019-05-15 17:39:27 +00:00
}
2016-01-30 20:28:43 +00:00
// unset the values we don't want exported.
unset ( $item -> asset_id );
unset ( $item -> checked_out );
unset ( $item -> checked_out_time );
}
}
// Add headers to items array.
$headers = $this -> getExImPortHeaders ();
2024-03-02 20:10:30 +00:00
if ( ObjectHelper :: check ( $headers ))
2016-01-30 20:28:43 +00:00
{
array_unshift ( $items , $headers );
}
return $items ;
}
}
return false ;
}
2018-01-24 12:47:57 +00:00
/**
* Method to get header .
*
* @ return mixed An array of data items on success , false on failure .
*/
public function getExImPortHeaders ()
{
// Get a db connection.
2024-03-02 20:10:30 +00:00
$db = Factory :: getDbo ();
2018-01-24 12:47:57 +00:00
// get the columns
$columns = $db -> getTableColumns ( " #__componentbuilder_joomla_component " );
2024-03-02 20:10:30 +00:00
if ( UtilitiesArrayHelper :: check ( $columns ))
2018-01-24 12:47:57 +00:00
{
// remove the headers you don't import/export.
unset ( $columns [ 'asset_id' ]);
unset ( $columns [ 'checked_out' ]);
unset ( $columns [ 'checked_out_time' ]);
2024-03-02 20:10:30 +00:00
$headers = new \stdClass ();
2018-01-24 12:47:57 +00:00
foreach ( $columns as $column => $type )
{
$headers -> { $column } = $column ;
}
return $headers ;
}
return false ;
2021-03-05 03:08:47 +00:00
}
2024-03-02 20:10:30 +00:00
2021-03-05 03:08:47 +00:00
/**
* Method to get a store id based on model configuration state .
*
* @ return string A store id .
*
*/
protected function getStoreId ( $id = '' )
{
2016-01-30 20:28:43 +00:00
// Compile the store id.
$id .= ':' . $this -> getState ( 'filter.id' );
$id .= ':' . $this -> getState ( 'filter.search' );
$id .= ':' . $this -> getState ( 'filter.published' );
2020-12-10 04:16:01 +00:00
// Check if the value is an array
2020-12-10 15:56:47 +00:00
$_access = $this -> getState ( 'filter.access' );
2024-03-02 20:10:30 +00:00
if ( UtilitiesArrayHelper :: check ( $_access ))
2020-12-10 04:16:01 +00:00
{
2020-12-10 15:56:47 +00:00
$id .= ':' . implode ( ':' , $_access );
2020-12-10 04:16:01 +00:00
}
2020-12-11 02:05:48 +00:00
// Check if this is only an number or string
2020-12-10 15:56:47 +00:00
elseif ( is_numeric ( $_access )
2024-03-02 20:10:30 +00:00
|| StringHelper :: check ( $_access ))
2020-12-10 04:16:01 +00:00
{
2020-12-10 15:56:47 +00:00
$id .= ':' . $_access ;
2020-12-10 04:16:01 +00:00
}
2016-01-30 20:28:43 +00:00
$id .= ':' . $this -> getState ( 'filter.ordering' );
$id .= ':' . $this -> getState ( 'filter.created_by' );
$id .= ':' . $this -> getState ( 'filter.modified_by' );
2021-01-15 07:13:06 +00:00
// Check if the value is an array
$_companyname = $this -> getState ( 'filter.companyname' );
2024-03-02 20:10:30 +00:00
if ( UtilitiesArrayHelper :: check ( $_companyname ))
2021-01-15 07:13:06 +00:00
{
$id .= ':' . implode ( ':' , $_companyname );
}
// Check if this is only an number or string
elseif ( is_numeric ( $_companyname )
2024-03-02 20:10:30 +00:00
|| StringHelper :: check ( $_companyname ))
2021-01-15 07:13:06 +00:00
{
$id .= ':' . $_companyname ;
}
// Check if the value is an array
$_author = $this -> getState ( 'filter.author' );
2024-03-02 20:10:30 +00:00
if ( UtilitiesArrayHelper :: check ( $_author ))
2021-01-15 07:13:06 +00:00
{
$id .= ':' . implode ( ':' , $_author );
}
// Check if this is only an number or string
elseif ( is_numeric ( $_author )
2024-03-02 20:10:30 +00:00
|| StringHelper :: check ( $_author ))
2021-01-15 07:13:06 +00:00
{
$id .= ':' . $_author ;
}
2016-01-30 20:28:43 +00:00
$id .= ':' . $this -> getState ( 'filter.system_name' );
$id .= ':' . $this -> getState ( 'filter.name_code' );
2021-01-30 13:36:03 +00:00
$id .= ':' . $this -> getState ( 'filter.short_description' );
$id .= ':' . $this -> getState ( 'filter.created' );
2021-03-05 03:08:47 +00:00
$id .= ':' . $this -> getState ( 'filter.modified' );
return parent :: getStoreId ( $id );
2016-01-30 20:28:43 +00:00
}
/**
2018-05-26 10:03:08 +00:00
* Build an SQL query to checkin all items left checked out longer then a set time .
*
2024-03-02 20:10:30 +00:00
* @ return bool
* @ since 3.2 . 0
2018-05-26 10:03:08 +00:00
*/
2024-03-02 20:10:30 +00:00
protected function checkInNow () : bool
2016-01-30 20:28:43 +00:00
{
// Get set check in time
2024-03-02 20:10:30 +00:00
$time = ComponentHelper :: getParams ( 'com_componentbuilder' ) -> get ( 'check_in' );
2018-05-26 10:03:08 +00:00
2016-01-30 20:28:43 +00:00
if ( $time )
{
// Get a db connection.
2024-03-02 20:10:30 +00:00
$db = Factory :: getDbo ();
2022-02-02 11:45:15 +00:00
// Reset query.
2016-01-30 20:28:43 +00:00
$query = $db -> getQuery ( true );
$query -> select ( '*' );
2017-02-16 14:02:23 +00:00
$query -> from ( $db -> quoteName ( '#__componentbuilder_joomla_component' ));
2022-02-02 11:45:15 +00:00
// Only select items that are checked out.
$query -> where ( $db -> quoteName ( 'checked_out' ) . '!=0' );
$db -> setQuery ( $query , 0 , 1 );
2016-01-30 20:28:43 +00:00
$db -> execute ();
if ( $db -> getNumRows ())
{
2022-02-02 11:45:15 +00:00
// Get Yesterdays date.
2024-03-02 20:10:30 +00:00
$date = Factory :: getDate () -> modify ( $time ) -> toSql ();
2022-02-02 11:45:15 +00:00
// Reset query.
2016-01-30 20:28:43 +00:00
$query = $db -> getQuery ( true );
// Fields to update.
$fields = array (
$db -> quoteName ( 'checked_out_time' ) . '=\'0000-00-00 00:00:00\'' ,
$db -> quoteName ( 'checked_out' ) . '=0'
);
// Conditions for which records should be updated.
$conditions = array (
$db -> quoteName ( 'checked_out' ) . '!=0' ,
$db -> quoteName ( 'checked_out_time' ) . '<\'' . $date . '\''
);
2022-02-02 11:45:15 +00:00
// Check table.
2017-02-16 14:02:23 +00:00
$query -> update ( $db -> quoteName ( '#__componentbuilder_joomla_component' )) -> set ( $fields ) -> where ( $conditions );
2016-01-30 20:28:43 +00:00
$db -> setQuery ( $query );
2024-03-02 20:10:30 +00:00
return $db -> execute ();
2016-01-30 20:28:43 +00:00
}
}
return false ;
2021-03-05 03:08:47 +00:00
}
}