2016-01-30 20:28:43 +00:00
< ? php
2018-05-18 06:28:27 +00:00
/**
* @ package Joomla . Component . Builder
*
* @ created 30 th April , 2015
* @ author Llewellyn van der Merwe < http :// www . joomlacomponentbuilder . com >
* @ github Joomla Component Builder < https :// github . com / vdm - io / Joomla - Component - Builder >
2019-02-23 13:28:54 +00:00
* @ copyright Copyright ( C ) 2015 - 2019 Vast Development Method . All rights reserved .
2018-05-18 06:28:27 +00:00
* @ license GNU General Public License version 2 or later ; see LICENSE . txt
*/
2016-01-30 20:28:43 +00:00
// No direct access to this file
defined ( '_JEXEC' ) or die ( 'Restricted access' );
/**
2017-02-16 14:02:23 +00:00
* Joomla_components Model
2016-01-30 20:28:43 +00:00
*/
2017-02-16 14:02:23 +00:00
class ComponentbuilderModelJoomla_components extends JModelList
2016-01-30 20:28:43 +00:00
{
public function __construct ( $config = array ())
{
if ( empty ( $config [ 'filter_fields' ]))
{
$config [ 'filter_fields' ] = array (
'a.id' , 'id' ,
'a.published' , 'published' ,
'a.ordering' , 'ordering' ,
'a.created_by' , 'created_by' ,
'a.modified_by' , 'modified_by' ,
'a.system_name' , 'system_name' ,
'a.name_code' , 'name_code' ,
'a.short_description' , 'short_description' ,
'a.companyname' , 'companyname' ,
'a.author' , 'author'
);
}
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 ;
// add to pks
$pks [] = $item -> id ;
}
// has any data been set for this component
if ( ComponentbuilderHelper :: checkArray ( $pks ))
{
// load the linked stuff
$this -> getLinkedToComponents ( $pks );
}
// has any data been set for this component
if ( isset ( $this -> smartBox [ 'joomla_component' ]) && ComponentbuilderHelper :: checkArray ( $this -> smartBox [ 'joomla_component' ]))
{
// 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' );
// check what type of export or backup this is
if ( 'backup' === $this -> activeType || 'manualBackup' === $this -> activeType )
{
// set the paths
if ( ! $this -> backupPath = $this -> params -> get ( 'cronjob_backup_folder_path' , null ))
{
// set the paths
$comConfig = JFactory :: getConfig ();
$this -> backupPath = $comConfig -> get ( 'tmp_path' );
}
// 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
$date = JFactory :: getDate ();
$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
{
// set the paths
$comConfig = JFactory :: getConfig ();
$this -> backupPath = $comConfig -> get ( 'tmp_path' );
// set the package name
if ( count ( $items ) == 1 )
{
$this -> packageName = 'JCB_' . $this -> getPackageName ( $items );
}
else
{
$this -> packageName = 'JCB_smartPackage' ;
}
}
// set the package path
$this -> packagePath = rtrim ( $this -> backupPath , '/' ) . '/' . $this -> packageName ;
$this -> zipPath = $this -> packagePath . '.zip' ;
if ( JFolder :: exists ( $this -> packagePath ))
{
// remove if old folder is found
ComponentbuilderHelper :: removeFolder ( $this -> packagePath );
}
// create the folders
JFolder :: create ( $this -> packagePath );
// Get the basic encryption.
$basickey = ComponentbuilderHelper :: getCryptKey ( 'basic' );
// Get the encription object.
if ( $basickey )
{
$basic = new FOFEncryptAes ( $basickey , 128 );
}
// 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 );
// 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 ;
// set the keys
if ( isset ( $item -> export_key ) && ComponentbuilderHelper :: checkString ( $item -> export_key ))
{
// keep the key locked for exported data set
$export_key = $item -> export_key ;
if ( $basickey && ! is_numeric ( $item -> export_key ) && $item -> export_key === base64_encode ( base64_decode ( $item -> export_key , true )))
{
$export_key = rtrim ( $basic -> decryptString ( $item -> export_key ), " \0 " );
}
// make sure we have a string
if ( strlen ( $export_key ) > 4 )
{
$this -> key [ $item -> id ] = $export_key ;
}
}
// get name of this item key_name
if ( isset ( $item -> system_name ))
{
$keyName = ComponentbuilderHelper :: safeString ( $item -> system_name , 'cAmel' );
}
else
{
$keyName = ComponentbuilderHelper :: safeString ( $item -> name_code );
}
// set the export buy links
if ( isset ( $item -> export_buy_link ) && ComponentbuilderHelper :: checkString ( $item -> export_buy_link ))
{
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
}
// set the export buy links
2018-05-05 14:47:48 +00:00
if ( isset ( $item -> joomla_source_link ) && ComponentbuilderHelper :: checkString ( $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
}
// 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 ;
// add to pks
$pks [] = $item -> id ;
}
// has any data been set for this component
if ( ComponentbuilderHelper :: checkArray ( $pks ))
{
// load the linked stuff
$this -> getLinkedToComponents ( $pks );
}
// has any data been set for this component
if ( isset ( $this -> smartBox [ 'joomla_component' ]) && ComponentbuilderHelper :: checkArray ( $this -> smartBox [ 'joomla_component' ]))
{
// 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' ,
'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
2018-04-17 21:25:03 +00:00
if ( isset ( $this -> smartIDs [ 'admin_view' ]) && ComponentbuilderHelper :: checkArray ( $this -> smartIDs [ 'admin_view' ]))
{
$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-08-12 21:30:31 +00:00
// add joomla plugin
if ( isset ( $this -> smartIDs [ 'joomla_plugin' ]) && ComponentbuilderHelper :: checkArray ( $this -> smartIDs [ 'joomla_plugin' ]))
{
$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
if ( isset ( $this -> smartIDs [ 'validation_rule' ]) && ComponentbuilderHelper :: checkArray ( $this -> smartIDs [ 'validation_rule' ]))
{
$this -> setData ( 'validation_rule' , array_values ( $this -> smartIDs [ 'validation_rule' ]), 'name' );
}
// add field types
if ( isset ( $this -> smartIDs [ 'fieldtype' ]) && ComponentbuilderHelper :: checkArray ( $this -> smartIDs [ 'fieldtype' ]))
{
$this -> setData ( 'fieldtype' , array_values ( $this -> smartIDs [ 'fieldtype' ]), 'id' );
}
// add templates
if ( isset ( $this -> smartIDs [ 'template' ]) && ComponentbuilderHelper :: checkArray ( $this -> smartIDs [ 'template' ]))
{
$this -> setData ( 'template' , array_values ( $this -> smartIDs [ 'template' ]), 'id' );
}
// add layouts
if ( isset ( $this -> smartIDs [ 'layout' ]) && ComponentbuilderHelper :: checkArray ( $this -> smartIDs [ 'layout' ]))
{
$this -> setData ( 'layout' , array_values ( $this -> smartIDs [ 'layout' ]), 'id' );
}
// add dynamic get
if ( isset ( $this -> smartIDs [ 'dynamic_get' ]) && ComponentbuilderHelper :: checkArray ( $this -> smartIDs [ 'dynamic_get' ]))
{
$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
if ( isset ( $this -> smartIDs [ 'class_property' ]) && ComponentbuilderHelper :: checkArray ( $this -> smartIDs [ 'class_property' ]))
{
$this -> setData ( 'class_property' , array_values ( $this -> smartIDs [ 'class_property' ]), 'id' );
}
// add class_method
if ( isset ( $this -> smartIDs [ 'class_method' ]) && ComponentbuilderHelper :: checkArray ( $this -> smartIDs [ 'class_method' ]))
{
$this -> setData ( 'class_method' , array_values ( $this -> smartIDs [ 'class_method' ]), 'id' );
}
// add joomla_plugin_group
if ( isset ( $this -> smartIDs [ 'joomla_plugin_group' ]) && ComponentbuilderHelper :: checkArray ( $this -> smartIDs [ 'joomla_plugin_group' ]))
{
$this -> setData ( 'joomla_plugin_group' , array_values ( $this -> smartIDs [ 'joomla_plugin_group' ]), 'id' );
}
// add class_extends
if ( isset ( $this -> smartIDs [ 'class_extends' ]) && ComponentbuilderHelper :: checkArray ( $this -> smartIDs [ 'class_extends' ]))
{
$this -> setData ( 'class_extends' , array_values ( $this -> smartIDs [ 'class_extends' ]), 'id' );
}
2018-04-17 21:25:03 +00:00
// add snippets
if ( isset ( $this -> smartIDs [ 'snippet' ]) && ComponentbuilderHelper :: checkArray ( $this -> smartIDs [ 'snippet' ]))
{
$this -> setData ( 'snippet' , array_values ( $this -> smartIDs [ 'snippet' ]), 'id' );
}
// add custom code
if ( isset ( $this -> smartIDs [ 'custom_code' ]) && ComponentbuilderHelper :: checkArray ( $this -> smartIDs [ 'custom_code' ]))
{
$this -> setData ( 'custom_code' , array_values ( $this -> smartIDs [ 'custom_code' ]), 'id' );
}
2019-03-04 12:47:28 +00:00
// add placeholder
if ( isset ( $this -> smartIDs [ 'placeholder' ]) && ComponentbuilderHelper :: checkArray ( $this -> smartIDs [ 'placeholder' ]))
{
$this -> setData ( 'placeholder' , array_values ( $this -> smartIDs [ 'placeholder' ]), 'id' );
}
2018-12-29 14:56:06 +00:00
// set limiter
$limit = 0 ;
// and add those custom codes found in custom codes
while ( isset ( $this -> smartIDs [ 'custom_code' ]) && ComponentbuilderHelper :: checkArray ( $this -> smartIDs [ 'custom_code' ]) && $limit < 100 )
{
$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
if ( ComponentbuilderHelper :: checkArray ( $pks ))
{
// Get the user object.
2017-08-20 17:52:35 +00:00
if ( ! ComponentbuilderHelper :: checkObject ( $this -> user ))
{
$this -> user = JFactory :: getUser ();
}
2017-03-18 11:16:07 +00:00
// Create a new query object.
2017-08-20 17:52:35 +00:00
if ( ! ComponentbuilderHelper :: checkObject ( $this -> _db ))
{
$this -> _db = JFactory :: getDBO ();
}
$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
2017-03-18 11:16:07 +00:00
if ( ComponentbuilderHelper :: checkArray ( $items ))
{
2017-03-30 21:19:12 +00:00
// set params
2018-02-20 20:46:29 +00:00
if ( ! ComponentbuilderHelper :: checkObject ( $this -> params ))
{
$this -> params = JComponentHelper :: getParams ( 'com_componentbuilder' );
}
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
if ( ComponentbuilderHelper :: checkJson ( $value ))
{
$value = json_decode ( $value , true );
}
// now update the fields
if ( ComponentbuilderHelper :: checkArray ( $value ))
{
foreach ( $value as $id )
{
2018-03-30 09:32:22 +00:00
if ( $int && ( ComponentbuilderHelper :: checkString ( $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
}
2018-03-30 09:32:22 +00:00
elseif ( ! $int && ComponentbuilderHelper :: checkString ( $id ))
{
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
}
}
2018-03-30 09:32:22 +00:00
elseif ( $int && ( ComponentbuilderHelper :: checkString ( $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
}
2018-03-30 09:32:22 +00:00
elseif ( ! $int && ComponentbuilderHelper :: checkString ( $value ))
{
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
if ( ComponentbuilderHelper :: checkJson ( $values ))
{
$values = json_decode ( $values , true );
}
// check that the array has values
if ( ComponentbuilderHelper :: checkArray ( $values ))
{
// 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 ];
}
elseif ( ComponentbuilderHelper :: checkString ( $value [ $key ]))
{
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
if ( ComponentbuilderHelper :: checkArray ( $bucket ))
{
// 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
}
2017-10-28 03:25:33 +00:00
elseif ( ComponentbuilderHelper :: checkString ( $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 ]) );
}
}
}
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
{
// make sure we have an array of values
if ( ! ComponentbuilderHelper :: checkArray ( $values ) || ! ComponentbuilderHelper :: checkString ( $table ) || ! ComponentbuilderHelper :: checkString ( $key ))
{
return false ;
}
// start the query
$query = $this -> _db -> getQuery ( true );
// Select some fields
$query -> select ( array ( 'a.*' ));
// From the componentbuilder_ANY table
$query -> from ( $this -> _db -> quoteName ( '#__componentbuilder_' . $table , 'a' ));
// set the where query
$query -> where ( 'a.' . $key . ' IN (' . implode ( ',' , $values ) . ')' );
// Implement View Level Access
if ( ! $this -> user -> authorise ( 'core.options' , 'com_componentbuilder' ))
{
$groups = implode ( ',' , $this -> user -> getAuthorisedViewLevels ());
$query -> where ( 'a.access IN (' . $groups . ')' );
}
// Order the results by ordering
$query -> order ( 'a.ordering ASC' );
// Load the items
$this -> _db -> setQuery ( $query );
$this -> _db -> execute ();
if ( $this -> _db -> getNumRows ())
{
$items = $this -> _db -> loadObjectList ();
// check if we have items
if ( ComponentbuilderHelper :: checkArray ( $items ))
{
// set search array
if ( 'site_view' === $table || 'custom_admin_view' === $table )
{
2019-08-12 21:30:31 +00:00
$searchArray = array ( 'php_view' , 'php_jview' , 'php_jview_display' , 'php_document' , 'js_document' , 'css_document' , 'css' );
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
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 );
}
// 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-08-12 21:30:31 +00:00
if (( 'component_files_folders' === $table || 'joomla_plugin_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
}
// 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-08-12 21:30:31 +00:00
// actions to take if table is component_plugins
if ( 'component_plugins' === $table )
{
// 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' );
// 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 ))
{
$fields = ComponentbuilderHelper :: getBetween ( json_decode ( $item -> xml ), 'fields="' , '"' );
$fieldsSets = array ();
if ( strpos ( $fields , ',' ) !== false )
{
// multiple fields
$fieldsSets = ( array ) explode ( ',' , $fields );
}
elseif ( is_numeric ( $fields ))
{
// single field
$fieldsSets [] = ( int ) $fields ;
}
// get fields
if ( ComponentbuilderHelper :: checkArray ( $fieldsSets ))
{
$this -> setData ( 'field' , $fieldsSets , 'id' );
}
}
2018-03-30 09:32:22 +00:00
// check if validation rule is found
$validationRule = ComponentbuilderHelper :: getBetween ( json_decode ( $item -> xml ), 'validate="' , '"' );
if ( ComponentbuilderHelper :: checkString ( $validationRule ))
{
// make sure it is lowercase
$validationRule = ComponentbuilderHelper :: safeString ( $validationRule );
// 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
}
// actions to take if table is site_view and custom_admin_view
if ( 'site_view' === $table || 'custom_admin_view' === $table )
{
// search for templates & layouts
$this -> getTemplateLayout ( base64_decode ( $item -> default ));
// add search array templates and layouts
foreach ( $searchArray as $scripter )
{
if ( isset ( $item -> { 'add_' . $scripter }) && $item -> { 'add_' . $scripter } == 1 )
{
2017-10-20 16:17:46 +00:00
$this -> getTemplateLayout ( $item -> { $scripter });
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
}
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
$this -> getTemplateLayout ( base64_decode ( $item -> $table ), $this -> user );
// 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-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
$this -> setData ( 'field' , $this -> getValues ( $item -> fields , 'subform' , 'field' ), 'id' );
// 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' );
}
// 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' );
}
2017-10-16 17:14:23 +00:00
}
}
}
}
2018-04-17 21:25:03 +00:00
/**
* Method to do the smart cloning
*
* @ return bool
*/
protected function smartCloner ()
{
// check if data is set
if ( isset ( $this -> smartBox ) && ComponentbuilderHelper :: checkArray ( $this -> smartBox ))
{
// 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
$model -> postfix = ' (' . ComponentbuilderHelper :: randomkey ( 2 ) . ')' ;
// get App
$model -> app = JFactory :: getApplication ();
// set user
$model -> user = $this -> user ;
// set today's date
$model -> today = JFactory :: getDate () -> toSql ();
// 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-08-12 21:30:31 +00:00
'joomla_plugin' , 'joomla_plugin_files_folders_urls' , 'joomla_plugin_updates' ,
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-08-12 21:30:31 +00:00
'component_placeholders' , '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
2018-04-17 21:25:03 +00:00
if ( isset ( $this -> smartBox ) && ComponentbuilderHelper :: checkArray ( $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 );
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 );
2018-03-18 04:28:54 +00:00
// lock the data if set
if ( ComponentbuilderHelper :: checkArray ( $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 ));
$locker = new FOFEncryptAes ( $this -> key , 128 );
2018-05-02 14:47:01 +00:00
$data = $locker -> encryptString ( $data );
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
if ( isset ( $this -> info [ 'export_buy_link' ]) && ComponentbuilderHelper :: checkArray ( $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
{
2018-05-05 14:47:48 +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 ;
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 ;
2018-03-18 04:28:54 +00:00
// Set the owner information
$data = base64_encode ( $data );
2017-04-26 08:55:02 +00:00
}
2018-03-18 04:28:54 +00:00
// set the path
$dbPath = $this -> packagePath . '/db.vdm' ;
// write the db data to file in package
if ( ! ComponentbuilderHelper :: writeFile ( $dbPath , wordwrap ( $data , 128 , " \n " , true )))
{
2017-03-30 21:19:12 +00:00
return false ;
2018-03-18 04:28:54 +00:00
}
// set info data
2018-05-05 14:47:48 +00:00
$db = 'COM_COMPONENTBUILDER_SZDEQZDMVSMHBTRWFIFTYTSQFLVVXJTMTHREEJTWOIXM' ;
$locker = new FOFEncryptAes ( base64_decode ( JText :: sprintf ( $db , 'VjR' , 'WV0aE9k' )), 128 );
2018-03-18 04:28:54 +00:00
$info = $locker -> encryptString ( json_encode ( $this -> info ));
// set the path
$infoPath = $this -> packagePath . '/info.vdm' ;
// write the db data to file in package
if ( ! ComponentbuilderHelper :: writeFile ( $infoPath , wordwrap ( $info , 128 , " \n " , true )))
{
return false ;
}
// lock all files
$this -> lockFiles ();
// remove old zip files with the same name
if ( JFile :: exists ( $this -> zipPath ))
{
// remove file if found
JFile :: delete ( $this -> zipPath );
}
// zip the folder
if ( ! ComponentbuilderHelper :: zip ( $this -> packagePath , $this -> zipPath ))
2018-02-20 20:46:29 +00:00
{
return false ;
}
2018-03-18 04:28:54 +00:00
// move to remote server if needed
if ( 2 == $this -> backupType )
{
if ( ! ComponentbuilderHelper :: moveToServer ( $this -> zipPath , $this -> packageName . '.zip' , $this -> backupServer , null , 'joomla_component.export' ))
{
return false ;
}
// remove the local file
JFile :: delete ( $this -> zipPath );
}
// remove the folder
if ( ! ComponentbuilderHelper :: removeFolder ( $this -> packagePath ))
{
return false ;
}
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
if ( ComponentbuilderHelper :: checkString ( $this -> key ) && strlen ( $this -> key ) == 32 )
{
$locker = new FOFEncryptAes ( $this -> key , 128 );
// we must first store the current working directory
$joomla = getcwd ();
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' );
// 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 ;
// go to the package sub folder if found
if ( JFolder :: exists ( $subPath ))
{
$this -> lock ( $subPath , $locker );
}
2017-04-01 13:59:54 +00:00
}
// change back to working dir
chdir ( $joomla );
}
}
/**
* The Locker
*
* @ return void
*/
protected function lock ( & $tmpPath , & $locker )
{
// we are changing the working directory to the tmp path (important)
chdir ( $tmpPath );
// get a list of files in the current directory tree (all)
$files = JFolder :: files ( '.' , '.' , true , true );
// read in the file content
foreach ( $files as $file )
{
// write the encrypted string back to file
if ( ! ComponentbuilderHelper :: writeFile ( $file , wordwrap ( $locker -> encryptString ( file_get_contents ( $file )), 128 , " \n " , true )))
{
// we should add error handler here in case file could not be locked
}
}
}
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
2017-10-28 03:25:33 +00:00
if ( ! ComponentbuilderHelper :: checkArray ( $paths ))
2017-03-20 22:07:14 +00:00
{
return false ;
}
// 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 ;
}
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 );
2017-03-20 22:07:14 +00:00
// create type path if not set
if ( ! JFolder :: exists ( $tmpPath ))
{
// create the folders if not found
JFolder :: create ( $tmpPath );
}
// 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
2017-03-27 12:38:51 +00:00
if ( ComponentbuilderHelper :: checkString ( $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
}
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 );
// check if image folder exist
if ( ! JFolder :: exists ( $imageFolderPath ))
{
// 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
}
}
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 );
}
2017-04-08 20:52:51 +00:00
if ( ! JFolder :: exists ( $tmpFolderPath ) && JFolder :: 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 ]))
{
$properties = ComponentbuilderHelper :: getVar ( 'fieldtype' , $id , 'id' , 'properties' );
if ( ComponentbuilderHelper :: checkJson ( $properties ))
{
$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
{
2017-09-18 02:20:50 +00:00
if ( isset ( $property [ 'example' ]) && ComponentbuilderHelper :: checkString ( $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
if ( ! isset ( $this -> fieldTypes [ $id ]) && $name = ComponentbuilderHelper :: getVar ( 'fieldtype' , $id , 'id' , 'name' ))
{
$this -> fieldTypes [ $id ] = ComponentbuilderHelper :: safeString ( $name );
}
}
// 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
{
// set the Template data
$temp1 = ComponentbuilderHelper :: getAllBetween ( $default , " \$ this->loadTemplate(' " , " ') " );
$temp2 = ComponentbuilderHelper :: getAllBetween ( $default , '$this->loadTemplate("' , '")' );
$templates = array ();
$again = array ();
if ( ComponentbuilderHelper :: checkArray ( $temp1 ) && ComponentbuilderHelper :: checkArray ( $temp2 ))
{
$templates = array_merge ( $temp1 , $temp2 );
}
else
{
if ( ComponentbuilderHelper :: checkArray ( $temp1 ))
{
$templates = $temp1 ;
}
elseif ( ComponentbuilderHelper :: checkArray ( $temp2 ))
{
$templates = $temp2 ;
}
}
if ( ComponentbuilderHelper :: checkArray ( $templates ))
{
foreach ( $templates as $template )
{
2017-08-20 17:52:35 +00:00
$data = $this -> getDataWithAlias ( $template , 'template' );
2017-03-18 20:17:15 +00:00
if ( ComponentbuilderHelper :: checkArray ( $data ))
{
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
$lay1 = ComponentbuilderHelper :: getAllBetween ( $default , " JLayoutHelper::render(' " , " ', " );
2017-03-18 22:55:34 +00:00
$lay2 = ComponentbuilderHelper :: getAllBetween ( $default , 'JLayoutHelper::render("' , '",' );
2017-03-18 20:17:15 +00:00
if ( ComponentbuilderHelper :: checkArray ( $lay1 ) && ComponentbuilderHelper :: checkArray ( $lay2 ))
{
$layouts = array_merge ( $lay1 , $lay2 );
}
else
{
if ( ComponentbuilderHelper :: checkArray ( $lay1 ))
{
$layouts = $lay1 ;
}
elseif ( ComponentbuilderHelper :: checkArray ( $lay2 ))
{
$layouts = $lay2 ;
}
}
if ( isset ( $layouts ) && ComponentbuilderHelper :: checkArray ( $layouts ))
{
foreach ( $layouts as $layout )
{
2017-08-20 17:52:35 +00:00
$data = $this -> getDataWithAlias ( $layout , 'layout' );
2017-03-18 20:17:15 +00:00
if ( ComponentbuilderHelper :: checkArray ( $data ))
{
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
}
}
if ( ComponentbuilderHelper :: checkArray ( $again ))
{
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
2018-04-17 21:25:03 +00:00
if ( isset ( $this -> smartIDs [ 'template' ]) && ComponentbuilderHelper :: checkArray ( $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
2018-04-17 21:25:03 +00:00
if ( isset ( $this -> smartIDs [ 'layout' ]) && ComponentbuilderHelper :: checkArray ( $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 )
{
$k_ey = ComponentbuilderHelper :: safeString ( $row -> alias );
$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
{
2018-09-28 15:46:21 +00:00
$value = ComponentbuilderHelper :: openValidBase64 ( $item -> { $key }, null );
}
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
$codeArray = ComponentbuilderHelper :: getAllBetween ( $value , '[CUSTOMC' . 'ODE=' , ']' );
if ( ComponentbuilderHelper :: checkArray ( $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 );
}
elseif ( ComponentbuilderHelper :: checkString ( $func ))
{
if (( $funcID = ComponentbuilderHelper :: getVar ( $type , $func , 'function_name' , 'id' )) !== false && is_numeric ( $funcID ))
{
$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
if ( ! componentbuilderHelper :: checkArray ( $this -> placeholderM ) && ! componentbuilderHelper :: checkArray ( $this -> placeholderS ))
{
$this -> placeholderS = ComponentbuilderHelper :: getVars ( $type , 1 , 'published' , 'target' );
}
// only continue search if placeholders found
if ( componentbuilderHelper :: checkArray ( $this -> placeholderS ))
{
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
if (( $placeholderID = ComponentbuilderHelper :: getVar ( $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
*
*/
2017-08-20 17:52:35 +00:00
protected function setLanguageTranslation ( & $id )
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
if ( ComponentbuilderHelper :: checkArray ( $items ))
{
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 )
{
2018-04-17 21:25:03 +00:00
if ( ! isset ( $this -> smartBox [ 'language_translation' ][ $item -> id ]) && ComponentbuilderHelper :: checkJson ( $item -> components ))
2017-04-06 21:40:22 +00:00
{
$components = json_decode ( $item -> components , true );
if ( in_array ( $id , $components ))
{
// 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 ))
{
return ComponentbuilderHelper :: safeString ( $item -> system_name , 'cAmel' );
}
else
{
return ComponentbuilderHelper :: safeString ( $item -> name_code );
}
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
$allBetween = ComponentbuilderHelper :: getAllBetween ( $value , $target [ 'start' ], $target [ '_start' ]);
// just again make sure we found some
if ( ComponentbuilderHelper :: checkArray ( $allBetween ))
{
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
if ( ComponentbuilderHelper :: checkArray ( $starts ))
{
foreach ( $starts as $_start )
{
// get the base64 string
$base64 = ComponentbuilderHelper :: getBetween ( $value , $_start , $target [ 'end' ]);
// now open the base64 text
$tmp = ComponentbuilderHelper :: openValidBase64 ( $base64 );
// 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' ,
'php_site_event' , 'javascript' ),
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' ,
'php_import_save' , 'php_import_setdata' , 'php_model' , 'php_model_list' , 'php_postsavehook' , 'php_save' ),
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' ,
'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' ,
'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 (
2018-10-29 16:38:00 +00:00
'search' => array ( 'id' , 'name' , 'xml' , 'javascript_view_footer' , 'javascript_views_footer' ),
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
),
// #__componentbuilder_joomla_plugin (q)
'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-08-12 21:30:31 +00:00
'php_preflight_uninstall' , 'php_postflight_install' , 'php_postflight_update' , 'php_method_uninstall' ),
2019-07-16 23:15:42 +00:00
'views' => 'joomla_plugins' ,
2019-08-12 21:30:31 +00:00
'not_base64' => array ( 'description' => 'string' ),
'name' => 'system_name'
2019-07-16 23:15:42 +00:00
),
// #__componentbuilder_class_extends (r)
'class_extends' => array (
'search' => array ( 'id' , 'name' , 'head' , 'comment' ),
'views' => 'class_extendings' ,
'not_base64' => array (),
'name' => 'name'
),
// #__componentbuilder_class_property (s)
'class_property' => array (
'search' => array ( 'id' , 'name' , 'default' , 'comment' ),
'views' => 'class_properties' ,
'not_base64' => array (),
'name' => 'name'
),
// #__componentbuilder_class_method (t)
'class_method' => array (
'search' => array ( 'id' , 'name' , 'code' , 'comment' ),
'views' => 'class_methods' ,
'not_base64' => array (),
'name' => '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
}
2018-09-28 15:46:21 +00:00
2016-01-30 20:28:43 +00:00
/**
* Method to auto - populate the model state .
*
* @ return void
*/
protected function populateState ( $ordering = null , $direction = null )
{
$app = JFactory :: getApplication ();
// Adjust the context to support modal layouts.
if ( $layout = $app -> input -> get ( 'layout' ))
{
$this -> context .= '.' . $layout ;
}
$system_name = $this -> getUserStateFromRequest ( $this -> context . '.filter.system_name' , 'filter_system_name' );
$this -> setState ( 'filter.system_name' , $system_name );
$name_code = $this -> getUserStateFromRequest ( $this -> context . '.filter.name_code' , 'filter_name_code' );
$this -> setState ( 'filter.name_code' , $name_code );
$short_description = $this -> getUserStateFromRequest ( $this -> context . '.filter.short_description' , 'filter_short_description' );
$this -> setState ( 'filter.short_description' , $short_description );
$companyname = $this -> getUserStateFromRequest ( $this -> context . '.filter.companyname' , 'filter_companyname' );
$this -> setState ( 'filter.companyname' , $companyname );
$author = $this -> getUserStateFromRequest ( $this -> context . '.filter.author' , 'filter_author' );
$this -> setState ( 'filter.author' , $author );
$sorting = $this -> getUserStateFromRequest ( $this -> context . '.filter.sorting' , 'filter_sorting' , 0 , 'int' );
$this -> setState ( 'filter.sorting' , $sorting );
$access = $this -> getUserStateFromRequest ( $this -> context . '.filter.access' , 'filter_access' , 0 , 'int' );
$this -> setState ( 'filter.access' , $access );
$search = $this -> getUserStateFromRequest ( $this -> context . '.filter.search' , 'filter_search' );
$this -> setState ( 'filter.search' , $search );
$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 );
$created = $this -> getUserStateFromRequest ( $this -> context . '.filter.created' , 'filter_created' );
$this -> setState ( 'filter.created' , $created );
// List state information.
parent :: populateState ( $ordering , $direction );
}
/**
* 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
{
2016-01-30 20:28:43 +00:00
// check in items
$this -> checkInNow ();
// 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.
2017-10-14 18:07:23 +00:00
if ( ComponentbuilderHelper :: checkArray ( $items ))
{
2019-09-05 21:12:56 +00:00
// Get the user object if not set.
if ( ! isset ( $user ) || ! ComponentbuilderHelper :: checkObject ( $user ))
{
$user = JFactory :: getUser ();
}
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 ;
}
}
2018-09-11 20:28:17 +00:00
}
2016-01-30 20:28:43 +00:00
// return items
return $items ;
}
/**
* Method to build an SQL query to load the list data .
*
* @ return string An SQL query
*/
protected function getListQuery ()
{
// Get the user object.
$user = JFactory :: getUser ();
// Create a new query object.
$db = JFactory :: getDBO ();
$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.
if ( $access = $this -> getState ( 'filter.access' ))
{
$query -> where ( 'a.access = ' . ( int ) $access );
}
// 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.
if ( $companyname = $this -> getState ( 'filter.companyname' ))
{
2016-10-23 22:48:26 +00:00
$query -> where ( 'a.companyname = ' . $db -> quote ( $db -> escape ( $companyname )));
2016-01-30 20:28:43 +00:00
}
// Filter by Author.
if ( $author = $this -> getState ( 'filter.author' ))
{
2016-10-23 22:48:26 +00:00
$query -> where ( 'a.author = ' . $db -> quote ( $db -> escape ( $author )));
2016-01-30 20:28:43 +00:00
}
// Add the list ordering clause.
$orderCol = $this -> state -> get ( 'list.ordering' , 'a.id' );
$orderDirn = $this -> state -> get ( 'list.direction' , 'asc' );
if ( $orderCol != '' )
{
$query -> order ( $db -> escape ( $orderCol . ' ' . $orderDirn ));
}
return $query ;
}
/**
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
if ( ComponentbuilderHelper :: checkArray ( $pks ))
{
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.
2019-09-05 21:12:56 +00:00
if ( ! isset ( $user ) || ! ComponentbuilderHelper :: checkObject ( $user ))
2019-09-04 11:52:31 +00:00
{
$user = JFactory :: getUser ();
}
2016-01-30 20:28:43 +00:00
// Create a new query object.
$db = JFactory :: getDBO ();
$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' ));
2016-01-30 20:28:43 +00:00
$query -> where ( 'a.id IN (' . implode ( ',' , $pks ) . ')' );
// Implement View Level Access
if ( ! $user -> authorise ( 'core.options' , 'com_componentbuilder' ))
{
$groups = implode ( ',' , $user -> getAuthorisedViewLevels ());
$query -> where ( 'a.access IN (' . $groups . ')' );
}
// Order the results by ordering
$query -> order ( 'a.ordering ASC' );
// 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.
2018-03-06 02:28:44 +00:00
$basic = new FOFEncryptAes ( $basickey );
2016-01-30 20:28:43 +00:00
2019-09-10 16:47:39 +00:00
// Set values to display correctly.
2016-01-30 20:28:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $items ))
{
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 ;
}
2018-07-08 20:18:32 +00:00
// decode php_helper_site
$item -> php_helper_site = base64_decode ( $item -> php_helper_site );
2019-05-15 17:39:27 +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 )))
{
// decrypt crowdin_account_api_key
$item -> crowdin_account_api_key = $basic -> decryptString ( $item -> crowdin_account_api_key );
}
2018-09-24 14:37:51 +00:00
// decode readme
$item -> readme = base64_decode ( $item -> readme );
2019-05-15 17:39:27 +00:00
// decode php_postflight_update
$item -> php_postflight_update = base64_decode ( $item -> php_postflight_update );
// decode javascript
$item -> javascript = base64_decode ( $item -> javascript );
// decode css_site
$item -> css_site = base64_decode ( $item -> css_site );
// decode php_preflight_update
$item -> php_preflight_update = base64_decode ( $item -> php_preflight_update );
// decode sql
$item -> sql = base64_decode ( $item -> sql );
// decode php_helper_admin
$item -> php_helper_admin = base64_decode ( $item -> php_helper_admin );
2018-09-24 14:37:51 +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 );
2019-05-15 17:39:27 +00:00
// decode php_site_event
$item -> php_site_event = base64_decode ( $item -> php_site_event );
// decode css_admin
$item -> css_admin = base64_decode ( $item -> css_admin );
2017-03-18 11:16:07 +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 );
}
2018-09-24 14:37:51 +00:00
// decode php_preflight_install
$item -> php_preflight_install = base64_decode ( $item -> php_preflight_install );
// decode php_postflight_install
$item -> php_postflight_install = base64_decode ( $item -> php_postflight_install );
// decode php_method_uninstall
$item -> php_method_uninstall = base64_decode ( $item -> php_method_uninstall );
// decode sql_uninstall
$item -> sql_uninstall = base64_decode ( $item -> sql_uninstall );
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 );
}
2017-10-26 16:43:51 +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 );
}
2019-05-15 17:39:27 +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 );
}
2017-03-18 11:16:07 +00:00
// decode buildcompsql
$item -> buildcompsql = base64_decode ( $item -> buildcompsql );
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 ();
if ( ComponentbuilderHelper :: checkObject ( $headers ))
{
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.
$db = JFactory :: getDbo ();
// get the columns
$columns = $db -> getTableColumns ( " #__componentbuilder_joomla_component " );
if ( ComponentbuilderHelper :: checkArray ( $columns ))
{
// remove the headers you don't import/export.
unset ( $columns [ 'asset_id' ]);
unset ( $columns [ 'checked_out' ]);
unset ( $columns [ 'checked_out_time' ]);
$headers = new stdClass ();
foreach ( $columns as $column => $type )
{
$headers -> { $column } = $column ;
}
return $headers ;
}
return false ;
2018-09-11 20:28:17 +00:00
}
2016-01-30 20:28:43 +00:00
/**
* Method to get a store id based on model configuration state .
*
* @ return string A store id .
*
*/
protected function getStoreId ( $id = '' )
{
// Compile the store id.
$id .= ':' . $this -> getState ( 'filter.id' );
$id .= ':' . $this -> getState ( 'filter.search' );
$id .= ':' . $this -> getState ( 'filter.published' );
$id .= ':' . $this -> getState ( 'filter.ordering' );
$id .= ':' . $this -> getState ( 'filter.created_by' );
$id .= ':' . $this -> getState ( 'filter.modified_by' );
$id .= ':' . $this -> getState ( 'filter.system_name' );
$id .= ':' . $this -> getState ( 'filter.name_code' );
$id .= ':' . $this -> getState ( 'filter.short_description' );
$id .= ':' . $this -> getState ( 'filter.companyname' );
$id .= ':' . $this -> getState ( 'filter.author' );
return parent :: getStoreId ( $id );
}
/**
2018-05-26 10:03:08 +00:00
* Build an SQL query to checkin all items left checked out longer then a set time .
*
* @ return a bool
*
*/
2016-02-26 12:46:15 +00:00
protected function checkInNow ()
2016-01-30 20:28:43 +00:00
{
// Get set check in time
$time = JComponentHelper :: 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.
$db = JFactory :: getDbo ();
// reset query
$query = $db -> getQuery ( true );
$query -> select ( '*' );
2017-02-16 14:02:23 +00:00
$query -> from ( $db -> quoteName ( '#__componentbuilder_joomla_component' ));
2016-01-30 20:28:43 +00:00
$db -> setQuery ( $query );
$db -> execute ();
if ( $db -> getNumRows ())
{
// Get Yesterdays date
$date = JFactory :: getDate () -> modify ( $time ) -> toSql ();
// reset query
$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 . '\''
);
// 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 );
$db -> execute ();
}
}
return false ;
}
}