2016-02-26 00:20:09 +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-03-04 12:47:28 +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-02-26 00:20:09 +00:00
// No direct access to this file
defined ( '_JEXEC' ) or die ( 'Restricted access' );
/**
* Get class as the main compilers class
*/
class Get
{
2019-05-15 22:50:45 +00:00
2019-08-08 15:35:58 +00:00
/**
* The Joomla Version
*
* @ var string
*/
public $joomlaVersion ;
2018-05-22 19:01:36 +00:00
/**
* The hash placeholder
*
* @ var string
*/
public $hhh = '#' . '#' . '#' ;
/**
* The open bracket placeholder
*
* @ var string
*/
public $bbb = '[' . '[' . '[' ;
/**
* The close bracket placeholder
*
* @ var string
*/
public $ddd = ']' . ']' . ']' ;
2017-10-26 16:43:51 +00:00
/**
* The app
*
* @ var object
*/
public $app ;
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Params
*
* @ var object
*/
public $params ;
2017-12-14 23:10:47 +00:00
2019-09-10 16:47:39 +00:00
/**
* Add strict field export permissions
*
* @ var boolean
*/
public $strictFieldExportPermissions = false ;
/**
* Add text only export options
*
* @ var boolean
*/
public $exportTextOnly = false ;
2019-02-15 22:03:21 +00:00
/**
* The global placeholders
*
* @ var array
*/
public $globalPlaceholders = array ();
2017-02-13 23:24:38 +00:00
/**
* The placeholders
*
* @ var array
*/
public $placeholders = array ();
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Compiler Path
*
* @ var object
*/
public $compilerPath ;
2017-12-14 23:10:47 +00:00
2017-02-14 00:33:24 +00:00
/**
* Switch to add custom code placeholders
*
* @ var bool
*/
public $addPlaceholders = false ;
2017-12-14 23:10:47 +00:00
2018-08-02 05:36:47 +00:00
/**
* The placeholders for custom code keys
*
* @ var array
*/
protected $customCodeKeyPlacholders = array (
'[' => '[' ,
']' => ']' ,
',' => ',' ,
2018-11-08 04:05:08 +00:00
'+' => '+' ,
'=' => '='
2018-08-02 05:36:47 +00:00
);
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Component data
*
* @ var object
*/
public $componentData ;
2017-12-14 23:10:47 +00:00
2019-08-22 01:54:47 +00:00
/**
* The Plugins data
*
* @ var array
*/
public $joomlaPlugins = array ();
2019-12-06 05:31:32 +00:00
/**
* The Modules data
*
* @ var array
*/
public $joomlaModules = array ();
2019-08-15 14:26:46 +00:00
/**
2017-12-14 23:10:47 +00:00
* The custom script placeholders - we use the ( xxx ) to avoid detection it should be ( *** )
* ##################################---> PHP/JS <---####################################
2017-02-01 13:17:04 +00:00
*
2017-12-14 23:10:47 +00:00
* New Insert Code = / xxx [ INSERT <> $ $ $ $ ] xxx / / xxx [ / INSERT <> $ $ $ $ ] xxx /
* New Replace Code = / xxx [ REPLACE <> $ $ $ $ ] xxx / / xxx [ / REPLACE <> $ $ $ $ ] xxx /
2017-02-01 13:17:04 +00:00
*
2017-12-14 23:10:47 +00:00
* //////////////////////////////// when JCB adds it back //////////////////////////////////
* JCB Add Inserted Code = / xxx [ INSERTED $ $ $ $ ] xxx //x23x/ /xxx[/INSERTED$$$$]xxx/
* JCB Add Replaced Code = / xxx [ REPLACED $ $ $ $ ] xxx //x25x/ /xxx[/REPLACED$$$$]xxx/
2017-02-01 13:17:04 +00:00
*
2017-12-14 23:10:47 +00:00
* /////////////////////////////// changeing existing custom code /////////////////////////
* Update Inserted Code = / xxx [ INSERTED <> $ $ $ $ ] xxx //x23x/ /xxx[/INSERTED<>$$$$]xxx/
* Update Replaced Code = / xxx [ REPLACED <> $ $ $ $ ] xxx //x25x/ /xxx[/REPLACED<>$$$$]xxx/
2017-02-01 13:17:04 +00:00
*
2017-12-14 23:10:47 +00:00
* The custom script placeholders - we use the ( == ) to avoid detection it should be ( -- )
* ###################################---> HTML <---#####################################
2017-02-01 13:17:04 +00:00
*
2017-02-13 23:24:38 +00:00
* New Insert Code = <!== [ INSERT <> $ $ $ $ ] ==> <!== [ / INSERT <> $ $ $ $ ] ==>
2017-12-14 23:10:47 +00:00
* New Replace Code = <!== [ REPLACE <> $ $ $ $ ] ==> <!== [ / REPLACE <> $ $ $ $ ] ==>
2017-02-13 23:24:38 +00:00
*
2017-12-14 23:10:47 +00:00
* ///////////////////////////////// when JCB adds it back ///////////////////////////////
* JCB Add Inserted Code = <!== [ INSERTED $ $ $ $ ] ==><!== 23 ==> <!== [ / INSERTED $ $ $ $ ] ==>
* JCB Add Replaced Code = <!== [ REPLACED $ $ $ $ ] ==><!== 25 ==> <!== [ / REPLACED $ $ $ $ ] ==>
2017-02-13 23:24:38 +00:00
*
2017-12-14 23:10:47 +00:00
* //////////////////////////// changeing existing custom code ///////////////////////////
* Update Inserted Code = <!== [ INSERTED <> $ $ $ $ ] ==><!== 23 ==> <!== [ / INSERTED <> $ $ $ $ ] ==>
* Update Replaced Code = <!== [ REPLACED <> $ $ $ $ ] ==><!== 25 ==> <!== [ / REPLACED <> $ $ $ $ ] ==>
*
* ////////23 is the ID of the code in the system don't change it!!!!!!!!!!!!!!!!!!!!!!!!!!
*
* @ var array
2019-08-15 14:26:46 +00:00
*/
2017-12-14 23:10:47 +00:00
protected $customCodePlaceholders = array (
1 => 'REPLACE<>$$$$]' ,
2 => 'INSERT<>$$$$]' ,
3 => 'REPLACED<>$$$$]' ,
4 => 'INSERTED<>$$$$]'
);
2017-02-01 13:17:04 +00:00
/**
* The custom code to be added
*
* @ var array
*/
public $customCode ;
2017-12-14 23:10:47 +00:00
2017-02-13 23:24:38 +00:00
/**
* The custom code to be added
*
* @ var array
*/
protected $customCodeData = array ();
2017-12-14 23:10:47 +00:00
2017-02-13 23:24:38 +00:00
/**
* The function name memory ids
*
* @ var array
*/
public $functionNameMemory = array ();
2017-12-14 23:10:47 +00:00
2017-02-13 23:24:38 +00:00
/**
* The custom code for local memory
*
* @ var array
*/
public $customCodeMemory = array ();
2017-12-14 23:10:47 +00:00
2017-02-01 13:17:04 +00:00
/**
2018-01-31 13:35:54 +00:00
* The custom code in local files that already exist in system
2017-02-01 13:17:04 +00:00
*
* @ var array
*/
protected $existingCustomCode = array ();
2017-12-14 23:10:47 +00:00
2017-02-01 13:17:04 +00:00
/**
* The custom code in local files this are new
*
* @ var array
*/
protected $newCustomCode = array ();
2017-12-14 23:10:47 +00:00
2017-02-09 16:11:10 +00:00
/**
* The index of code already loaded
*
* @ var array
*/
2017-12-14 23:10:47 +00:00
protected $codeAreadyDone = array ();
2018-01-31 13:35:54 +00:00
/**
2018-02-03 00:13:48 +00:00
* The external code / string to be added
2018-01-31 13:35:54 +00:00
*
* @ var array
*/
2018-02-03 00:13:48 +00:00
protected $externalCodeString = array ();
2018-01-31 13:35:54 +00:00
2017-02-13 23:24:38 +00:00
/*
* The line numbers Switch
*
* @ var boolean
*/
2017-12-14 23:10:47 +00:00
public $debugLinenr = false ;
2017-04-06 08:47:51 +00:00
/*
* The percentage when a language should be added
*
* @ var boolean
*/
public $percentageLanguageAdd = 0 ;
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2017-04-05 13:21:10 +00:00
* The Placholder Language prefix
2016-02-26 00:20:09 +00:00
*
* @ var string
*/
2017-04-05 13:21:10 +00:00
public $langPrefix ;
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Language content
*
* @ var array
*/
public $langContent = array ();
2017-12-14 23:10:47 +00:00
2017-04-05 13:21:10 +00:00
/**
* The Languages bucket
*
* @ var array
*/
2018-04-19 23:36:21 +00:00
public $languages = array ();
/**
* The Main Languages
*
* @ var string
*/
public $langTag = 'en-GB' ;
2017-12-14 23:10:47 +00:00
2017-04-05 13:21:10 +00:00
/**
* The Multi Languages bucket
*
* @ var array
*/
public $multiLangString = array ();
2017-12-14 23:10:47 +00:00
2017-04-05 13:21:10 +00:00
/**
* The new lang to add
*
* @ var array
*/
protected $newLangStrings = array ();
2017-12-14 23:10:47 +00:00
2017-04-05 13:21:10 +00:00
/**
* The existing lang to update
*
* @ var array
*/
protected $existingLangStrings = array ();
2017-12-14 23:10:47 +00:00
2017-12-14 13:30:21 +00:00
/**
* The Language JS matching check
*
* @ var array
*/
public $langMismatch = array ();
2017-12-14 23:10:47 +00:00
2017-12-14 13:30:21 +00:00
/**
* The Language SC matching check
*
* @ var array
*/
public $langMatch = array ();
2017-12-14 23:10:47 +00:00
2017-12-14 13:30:21 +00:00
/**
* The Language string targets
*
* @ var array
*/
public $langStringTargets = array (
2018-03-18 04:52:07 +00:00
'Joomla' . '.JText._(' ,
'JText:' . ':script(' ,
'JText:' . ':_(' ,
2018-04-08 06:12:18 +00:00
'JText:' . ':sprintf(' ,
'JustTEXT:' . ':_('
2017-12-14 23:10:47 +00:00
);
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Component Code Name
*
* @ var string
*/
public $componentCodeName ;
2017-12-14 23:10:47 +00:00
2017-02-13 23:24:38 +00:00
/**
* The Component ID
*
* @ var int
*/
public $componentID ;
2017-12-14 23:10:47 +00:00
2017-02-13 23:24:38 +00:00
/**
* The current user
*
* @ var array
*/
public $user ;
2017-12-14 23:10:47 +00:00
2017-02-13 23:24:38 +00:00
/**
* The database object
*
* @ var array
*/
public $db ;
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Component version
*
* @ var string
*/
public $component_version ;
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The UIKIT Switch
*
* @ var boolean
*/
2017-11-11 04:33:51 +00:00
public $uikit = 0 ;
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The UIKIT component checker
*
* @ var array
*/
public $uikitComp = array ();
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The FOOTABLE Switch
*
* @ var boolean
*/
public $footable = false ;
2017-12-14 23:10:47 +00:00
2016-04-22 12:03:43 +00:00
/**
* The FOOTABLE Version
*
* @ var int
*/
public $footableVersion ;
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Google Chart Switch per view
*
* @ var array
*/
public $googleChart = array ();
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Google Chart Switch
*
* @ var boolean
*/
public $googlechart = false ;
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Import & Export Switch
*
* @ var boolean
*/
public $addEximport = false ;
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Tag & History Switch
*
* @ var boolean
*/
public $setTagHistory = false ;
2017-12-14 23:10:47 +00:00
2018-08-23 01:37:42 +00:00
/**
* The Joomla Fields Switch
*
* @ var boolean
*/
public $setJoomlaFields = false ;
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The site edit views
*
* @ var array
*/
public $siteEditView = array ();
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Language target
*
* @ var string
*/
public $lang = 'admin' ;
2017-12-14 23:10:47 +00:00
2019-09-11 14:50:42 +00:00
/**
* The lang keys for extentions
*
* @ var array
*/
public $langKeys = array ();
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Build target Switch
*
* @ var string
*/
public $target ;
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The unique codes
*
* @ var array
*/
2016-02-26 13:57:30 +00:00
public $uniquecodes = array ();
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 13:57:30 +00:00
* The unique keys
*
* @ var array
*/
public $uniquekeys = array ();
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Ad contributors Switch
*
* @ var boolean
*/
public $addContributors = false ;
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Custom Script Builder
*
* @ var array
*/
public $customScriptBuilder = array ();
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Footable Script Builder
*
* @ var array
*/
public $footableScripts = array ();
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The pathe to the bom file to be used
*
* @ var string
*/
public $bomPath ;
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The SQL Tweak of admin views
*
* @ var array
*/
public $sqlTweak = array ();
2017-12-14 23:10:47 +00:00
2018-03-27 09:57:16 +00:00
/**
* The validation rules that should be added
*
* @ var array
*/
public $validationRules = array ();
2019-08-22 01:54:47 +00:00
/**
* The validation linked to fields
*
* @ var array
*/
public $validationLinkedFields = array ();
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The admin views data array
*
* @ var array
*/
private $_adminViewData = array ();
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The field data array
*
* @ var array
*/
private $_fieldData = array ();
2017-12-14 23:10:47 +00:00
2018-03-28 09:46:14 +00:00
/**
* The custom alias builder
*
* @ var array
*/
public $customAliasBuilder = array ();
2018-03-18 04:28:54 +00:00
/**
* The field builder type
*
* 1 = StringManipulation
* 2 = SimpleXMLElement
*
* @ var int
*/
public $fieldBuilderType ;
2018-03-11 02:44:43 +00:00
/**
* Set unique Names
*
* @ var array
*/
public $uniqueNames = array ();
/**
* Set unique Names
*
* @ var array
*/
protected $uniqueFieldNames = array ();
/**
* Category other name bucket
*
* @ var array
*/
public $catOtherName = array ();
2018-05-24 13:56:56 +00:00
/**
* The field relations values
*
* @ var array
*/
public $fieldRelations = array ();
2018-07-12 16:35:38 +00:00
/**
* Default Fields
*
* @ var array
*/
public $defaultFields = array ( 'created' , 'created_by' , 'modified' , 'modified_by' , 'published' , 'ordering' , 'access' , 'version' , 'hits' , 'id' );
2018-05-24 13:56:56 +00:00
/**
* The list join fields
*
* @ var array
*/
public $listJoinBuilder = array ();
2018-05-29 03:45:16 +00:00
/**
* The list head over ride
*
* @ var array
*/
public $listHeadOverRide = array ();
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The linked admin view tabs
*
* @ var array
*/
public $linkedAdminViews = array ();
2017-12-14 23:10:47 +00:00
2018-08-24 21:46:41 +00:00
/**
* The custom admin view tabs
*
* @ var array
*/
public $customTabs = array ();
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Add Ajax Switch
*
* @ var boolean
*/
public $addAjax = false ;
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Add Site Ajax Switch
*
* @ var boolean
*/
public $addSiteAjax = false ;
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The get Module Script Switch
*
* @ var array
*/
public $getModule = array ();
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The template data
*
* @ var array
*/
public $templateData = array ();
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The layout data
*
* @ var array
*/
public $layoutData = array ();
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2018-03-06 02:28:44 +00:00
* The Encryption Types
*
* @ var array
*/
2019-10-16 20:34:36 +00:00
public $cryptionTypes = array ( 'basic' , 'medium' , 'whmcs' , 'expert' );
2018-03-06 02:28:44 +00:00
/**
* The WHMCS Encryption Switch
2016-02-26 00:20:09 +00:00
*
* @ var boolean
*/
2018-03-06 02:28:44 +00:00
public $whmcsEncryption = false ;
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Basic Encryption Switch
*
* @ var boolean
*/
public $basicEncryption = false ;
2017-12-14 23:10:47 +00:00
2018-03-06 02:28:44 +00:00
/**
* The Medium Encryption Switch
*
* @ var boolean
*/
public $mediumEncryption = false ;
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Custom field Switch per view
*
* @ var array
*/
public $customFieldScript = array ();
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The site main get
*
* @ var array
*/
public $siteMainGet = array ();
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The site dynamic get
*
* @ var array
*/
public $siteDynamicGet = array ();
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The get AS lookup
*
* @ var array
*/
public $getAsLookup = array ();
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The site fields
*
* @ var array
*/
public $siteFields = array ();
2017-12-14 23:10:47 +00:00
2017-06-16 12:38:06 +00:00
/**
* The add SQL
*
* @ var array
*/
public $addSQL = array ();
2017-12-14 23:10:47 +00:00
2017-06-16 12:38:06 +00:00
/**
* The update SQL
*
* @ var array
*/
public $updateSQL = array ();
2017-12-14 23:10:47 +00:00
2017-12-03 18:09:04 +00:00
/**
* The Library Manager
*
* @ var array
*/
public $libManager = array ();
2017-12-14 23:10:47 +00:00
2017-12-03 18:09:04 +00:00
/**
* The Libraries
*
* @ var array
*/
public $libraries = array ();
2017-12-14 23:10:47 +00:00
2018-04-18 19:11:14 +00:00
/**
* Is minify Enabled
*
* @ var int
*/
public $minify = 0 ;
2017-12-12 22:17:02 +00:00
/**
* Is Tidy Enabled
*
* @ var bool
*/
public $tidy = false ;
2017-12-14 23:10:47 +00:00
2017-12-12 22:17:02 +00:00
/**
* Set Tidy warning once switch
*
* @ var bool
*/
public $setTidyWarning = false ;
2016-02-26 00:20:09 +00:00
2018-09-25 20:02:48 +00:00
/**
* mysql table setting keys
*
* @ var array
*/
public $mysqlTableKeys = array (
'engine' => array ( 'default' => 'MyISAM' ),
'charset' => array ( 'default' => 'utf8' ),
2019-01-26 03:51:48 +00:00
'collate' => array ( 'default' => 'utf8_general_ci' ),
'row_format' => array ( 'default' => '' )
2018-09-25 20:02:48 +00:00
);
/**
* mysql table settings
*
* @ var array
*/
public $mysqlTableSetting = array ();
2019-06-22 10:43:26 +00:00
/**
* event plugin trigger switch
*
* @ var boolean
*/
protected $active_plugins = false ;
2018-05-26 10:03:08 +00:00
/**
2016-02-26 00:20:09 +00:00
* Constructor
*/
2017-12-14 23:10:47 +00:00
public function __construct ( $config = array ())
2016-02-26 00:20:09 +00:00
{
if ( isset ( $config ) && count ( $config ))
{
2017-10-26 16:43:51 +00:00
// load application
2017-12-14 23:10:47 +00:00
$this -> app = JFactory :: getApplication ();
2016-02-26 00:20:09 +00:00
// Set the params
2017-12-14 23:10:47 +00:00
$this -> params = JComponentHelper :: getParams ( 'com_componentbuilder' );
2019-06-22 10:43:26 +00:00
// get active plugins
if (( $plugins = $this -> params -> get ( 'compiler_plugin' , false )) !== false )
{
foreach ( $plugins as $plugin )
{
// get posible plugins
if ( \JPluginHelper :: isEnabled ( 'extension' , $plugin ))
{
// Import the appropriate plugin group.
\JPluginHelper :: importPlugin ( 'extension' , $plugin );
// activate events
$this -> active_plugins = true ;
}
}
}
2019-08-22 01:54:47 +00:00
// Trigger Event: jcb_ce_onBeforeGet
$this -> triggerEvent ( 'jcb_ce_onBeforeGet' , array ( & $config , $this ));
2019-08-08 15:35:58 +00:00
// set the Joomla version
$this -> joomlaVersion = $config [ 'version' ];
2018-04-18 19:11:14 +00:00
// set the minfy switch of the JavaScript
$this -> minify = ( isset ( $config [ 'minify' ]) && $config [ 'minify' ] != 2 ) ? $config [ 'minify' ] : $this -> params -> get ( 'minify' , 0 );
2018-04-19 23:36:21 +00:00
// set the global language
$this -> langTag = $this -> params -> get ( 'language' , $this -> langTag );
2019-10-11 14:51:43 +00:00
// also set the helper class langTag (for safeStrings)
ComponentbuilderHelper :: $langTag = $this -> langTag ;
2018-04-19 23:36:21 +00:00
// setup the main language array
$this -> languages [ $this -> langTag ] = array ();
2018-04-18 19:11:14 +00:00
// check if we have Tidy enabled
$this -> tidy = extension_loaded ( 'Tidy' );
2018-03-18 04:28:54 +00:00
// set the field type builder
$this -> fieldBuilderType = $this -> params -> get ( 'compiler_field_builder_type' , 2 );
// check the field builder type logic
if ( ! $this -> tidy && $this -> fieldBuilderType == 2 )
{
// we do not have the tidy extention set fall back to StringManipulation
$this -> fieldBuilderType = 1 ;
// load the sugestion to use string manipulation
2018-09-25 20:02:48 +00:00
$this -> app -> enqueueMessage ( JText :: _ ( '<hr /><h3>Field Notice</h3>' ), 'Notice' );
$this -> app -> enqueueMessage ( JText :: _ ( 'Since you do not have <b>Tidy</b> extentsion setup on your system, we could not use the SimpleXMLElement class. We instead used <b>string manipulation</b> to build all your fields, this is a faster method, you must inspect the xml files in your component package to see if you are satisfied with the result.<br />You can make this method your default by opening the global options of JCB and under the <b>Global</b> tab set the <b>Field Builder Type</b> to string manipulation.' ), 'Notice' );
2018-03-18 04:28:54 +00:00
}
2016-02-26 00:20:09 +00:00
// load the compiler path
2017-12-14 23:10:47 +00:00
$this -> compilerPath = $this -> params -> get ( 'compiler_folder_path' , JPATH_COMPONENT_ADMINISTRATOR . '/compiler' );
2017-02-13 23:24:38 +00:00
// set the component ID
2018-04-24 22:36:05 +00:00
$this -> componentID = ( int ) $config [ 'component' ];
2017-02-13 23:24:38 +00:00
// set this components code name
2017-02-16 14:02:23 +00:00
if ( $name_code = ComponentbuilderHelper :: getVar ( 'joomla_component' , $this -> componentID , 'id' , 'name_code' ))
2017-02-13 23:24:38 +00:00
{
// set lang prefix
2017-12-14 23:10:47 +00:00
$this -> langPrefix = 'COM_' . ComponentbuilderHelper :: safeString ( $name_code , 'U' );
2017-02-13 23:24:38 +00:00
// set component code name
2017-12-14 23:10:47 +00:00
$this -> componentCodeName = ComponentbuilderHelper :: safeString ( $name_code );
2019-07-01 16:10:28 +00:00
// set component context
$this -> componentContext = $this -> componentCodeName . '.' . $this -> componentID ;
2017-02-13 23:24:38 +00:00
// set if placeholders should be added to customcode
2017-12-14 23:10:47 +00:00
$global = (( int ) ComponentbuilderHelper :: getVar ( 'joomla_component' , $this -> componentID , 'id' , 'add_placeholders' ) == 1 ) ? true : false ;
2018-04-24 22:36:05 +00:00
$this -> addPlaceholders = (( int ) $config [ 'placeholders' ] == 0 ) ? false : ((( int ) $config [ 'placeholders' ] == 1 ) ? true : $global );
2017-02-13 23:24:38 +00:00
// set if line numbers should be added to comments
2017-12-14 23:10:47 +00:00
$global = (( int ) ComponentbuilderHelper :: getVar ( 'joomla_component' , $this -> componentID , 'id' , 'debug_linenr' ) == 1 ) ? true : false ;
2018-04-24 22:36:05 +00:00
$this -> debugLinenr = (( int ) $config [ 'debuglinenr' ] == 0 ) ? false : ((( int ) $config [ 'debuglinenr' ] == 1 ) ? true : $global );
2017-02-13 23:24:38 +00:00
// set the current user
2017-12-14 23:10:47 +00:00
$this -> user = JFactory :: getUser ();
2017-02-13 23:24:38 +00:00
// Get a db connection.
2017-12-14 23:10:47 +00:00
$this -> db = JFactory :: getDbo ();
2019-02-15 22:03:21 +00:00
// get global placeholders
$this -> globalPlaceholders = $this -> getGlobalPlaceholders ();
2017-02-13 23:24:38 +00:00
// check if this component is install on the current website
if ( $paths = $this -> getLocalInstallPaths ())
{
// start Automatic import of custom code
$today = JFactory :: getDate () -> toSql ();
// get the custom code from installed files
$this -> customCodeFactory ( $paths , $today );
}
2019-08-28 13:07:18 +00:00
// Trigger Event: jcb_ce_onBeforeGetComponentData
$this -> triggerEvent ( 'jcb_ce_onBeforeGetComponentData' , array ( & $this -> componentContext , $this ));
2017-02-13 23:24:38 +00:00
// get the component data
$this -> componentData = $this -> getComponentData ();
2019-08-28 13:07:18 +00:00
// Trigger Event: jcb_ce_onAfterGetComponentData
$this -> triggerEvent ( 'jcb_ce_onAfterGetComponentData' , array ( & $this -> componentContext , $this ));
2017-06-16 12:38:06 +00:00
// make sure we have a version
if ( strpos ( $this -> componentData -> component_version , '.' ) === FALSE )
{
$this -> componentData -> component_version = '1.0.0' ;
}
// update the version
2017-12-14 23:10:47 +00:00
if ( ! isset ( $this -> componentData -> old_component_version ) && ( ComponentbuilderHelper :: checkArray ( $this -> addSQL ) || ComponentbuilderHelper :: checkArray ( $this -> updateSQL )))
2017-06-16 12:38:06 +00:00
{
// set the new version
$version = ( array ) explode ( '.' , $this -> componentData -> component_version );
// get last key
end ( $version );
$key = key ( $version );
// just increment the last
2019-08-26 06:54:16 +00:00
$version [ $key ] ++ ;
2017-06-16 12:38:06 +00:00
// set the old version
$this -> componentData -> old_component_version = $this -> componentData -> component_version ;
// set the new version, and set update switch
$this -> componentData -> component_version = implode ( '.' , $version );
}
2017-04-06 08:47:51 +00:00
// set the percentage when a language can be added
2017-04-06 08:51:46 +00:00
$this -> percentageLanguageAdd = ( int ) $this -> params -> get ( 'percentagelanguageadd' , 50 );
2017-12-14 23:10:47 +00:00
2019-08-22 01:54:47 +00:00
// Trigger Event: jcb_ce_onBeforeGet
$this -> triggerEvent ( 'jcb_ce_onAfterGet' , array ( & $this -> componentContext , $this ));
2017-02-13 23:24:38 +00:00
return true ;
}
2016-02-26 00:20:09 +00:00
}
return false ;
}
2017-12-14 23:10:47 +00:00
2018-05-26 10:03:08 +00:00
/**
* Set the tab / space
*
* @ param int $nr The number of tag / space
*
* @ return string
*
*/
public function _t ( $nr )
{
2019-09-04 11:52:31 +00:00
// use global method for conformity
return ComponentbuilderHelper :: _t ( $nr );
2018-05-26 10:03:08 +00:00
}
2016-09-03 21:44:47 +00:00
/**
* Set the line number in comments
*
* @ param int $nr The line number
*
* @ return void
*
*/
private function setLine ( $nr )
{
2017-04-06 08:47:51 +00:00
if ( $this -> debugLinenr )
2016-09-03 21:44:47 +00:00
{
2017-12-14 23:10:47 +00:00
return ' [Get ' . $nr . ']' ;
2016-09-03 21:44:47 +00:00
}
return '' ;
}
2017-12-14 23:10:47 +00:00
2019-06-22 10:43:26 +00:00
/**
* Trigger events
*
* @ param string $event The event to trigger
* @ param mix $data The values to pass to the event / plugin
*
* @ return string
*
*/
public function triggerEvent ( $event , $data )
{
// only exicute if plugins were loaded (active)
if ( $this -> active_plugins )
{
// Get the dispatcher.
$dispatcher = \JEventDispatcher :: getInstance ();
2019-06-29 21:11:37 +00:00
// Trigger this compiler event.
2019-06-22 10:43:26 +00:00
$results = $dispatcher -> trigger ( $event , $data );
// Check for errors encountered while trigger the event
2019-09-05 21:12:56 +00:00
if ( count (( array ) $results ) && in_array ( false , $results , true ))
2019-06-22 10:43:26 +00:00
{
// Get the last error.
$error = $dispatcher -> getError ();
if ( ! ( $error instanceof \Exception ))
{
throw new \Exception ( $error );
}
}
}
}
2019-02-15 22:03:21 +00:00
/**
* get all System Placeholders
*
* @ return array The global placeholders
*
*/
public function getGlobalPlaceholders ()
{
// reset bucket
$bucket = array ();
// Create a new query object.
$query = $this -> db -> getQuery ( true );
$query -> select ( $this -> db -> quoteName ( array ( 'a.target' , 'a.value' )));
// from these tables
$query -> from ( '#__componentbuilder_placeholder AS a' );
// Reset the query using our newly populated query object.
$this -> db -> setQuery ( $query );
// Load the items
$this -> db -> execute ();
if ( $this -> db -> getNumRows ())
{
$bucket = $this -> db -> loadAssocList ( 'target' , 'value' );
2019-07-28 21:48:42 +00:00
// open all the code
2019-02-15 22:03:21 +00:00
foreach ( $bucket as $key => & $code )
{
$code = base64_decode ( $code );
}
2019-08-08 15:35:58 +00:00
}
// set component place holders
$bucket [ $this -> hhh . 'component' . $this -> hhh ] = $this -> componentCodeName ;
$bucket [ $this -> hhh . 'Component' . $this -> hhh ] = ComponentbuilderHelper :: safeString ( $this -> componentCodeName , 'F' );
$bucket [ $this -> hhh . 'COMPONENT' . $this -> hhh ] = ComponentbuilderHelper :: safeString ( $this -> componentCodeName , 'U' );
$bucket [ $this -> bbb . 'component' . $this -> ddd ] = $bucket [ $this -> hhh . 'component' . $this -> hhh ];
$bucket [ $this -> bbb . 'Component' . $this -> ddd ] = $bucket [ $this -> hhh . 'Component' . $this -> hhh ];
$bucket [ $this -> bbb . 'COMPONENT' . $this -> ddd ] = $bucket [ $this -> hhh . 'COMPONENT' . $this -> hhh ];
2019-08-28 13:07:18 +00:00
$bucket [ $this -> hhh . 'LANG_PREFIX' . $this -> hhh ] = $this -> langPrefix ;
$bucket [ $this -> bbb . 'LANG_PREFIX' . $this -> ddd ] = $bucket [ $this -> hhh . 'LANG_PREFIX' . $this -> hhh ];
2019-08-08 15:35:58 +00:00
// get the current components overides
if (( $_placeholders = ComponentbuilderHelper :: getVar ( 'component_placeholders' , $this -> componentID , 'joomla_component' , 'addplaceholders' )) !== false
&& ComponentbuilderHelper :: checkJson ( $_placeholders ))
{
$_placeholders = json_decode ( $_placeholders , true );
if ( ComponentbuilderHelper :: checkArray ( $_placeholders ))
{
foreach ( $_placeholders as $row )
{
$bucket [ $row [ 'target' ]] = $row [ 'value' ];
2019-07-28 21:48:42 +00:00
}
}
2019-02-15 22:03:21 +00:00
}
return $bucket ;
}
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* get all Component Data
*
* @ param int $id The component ID
*
* @ return oject The component data
*
*/
2017-02-13 23:24:38 +00:00
public function getComponentData ()
2016-02-26 00:20:09 +00:00
{
// Create a new query object.
2017-02-13 23:24:38 +00:00
$query = $this -> db -> getQuery ( true );
2019-07-28 21:48:42 +00:00
// selection
$selection = array (
'b.addadmin_views' => 'addadmin_views' ,
'b.id' => 'addadmin_views_id' ,
'h.addconfig' => 'addconfig' ,
'd.addcustom_admin_views' => 'addcustom_admin_views' ,
'g.addcustommenus' => 'addcustommenus' ,
'j.addfiles' => 'addfiles' ,
'j.addfolders' => 'addfolders' ,
'j.addfilesfullpath' => 'addfilesfullpath' ,
'j.addfoldersfullpath' => 'addfoldersfullpath' ,
'c.addsite_views' => 'addsite_views' ,
'l.addjoomla_plugins' => 'addjoomla_plugins' ,
2019-12-06 05:31:32 +00:00
'k.addjoomla_modules' => 'addjoomla_modules' ,
2019-07-28 21:48:42 +00:00
'i.dashboard_tab' => 'dashboard_tab' ,
'i.php_dashboard_methods' => 'php_dashboard_methods' ,
'i.id' => 'component_dashboard_id' ,
'f.sql_tweak' => 'sql_tweak' ,
'e.version_update' => 'version_update' ,
'e.id' => 'version_update_id'
);
2016-02-26 00:20:09 +00:00
$query -> select ( 'a.*' );
2017-10-29 11:03:06 +00:00
$query -> select (
$this -> db -> quoteName (
2019-07-28 21:48:42 +00:00
array_keys ( $selection ), array_values ( $selection )
2017-12-14 23:10:47 +00:00
)
);
2019-07-28 21:48:42 +00:00
// from this table
2017-02-16 14:02:23 +00:00
$query -> from ( '#__componentbuilder_joomla_component AS a' );
2019-07-28 21:48:42 +00:00
// jointer-map
$joiners = array (
'b' => 'component_admin_views' ,
'c' => 'component_site_views' ,
'd' => 'component_custom_admin_views' ,
'e' => 'component_updates' ,
'f' => 'component_mysql_tweaks' ,
'g' => 'component_custom_admin_menus' ,
'h' => 'component_config' ,
'i' => 'component_dashboard' ,
'j' => 'component_files_folders' ,
2019-12-06 05:31:32 +00:00
'l' => 'component_plugins' ,
'k' => 'component_modules'
2019-07-28 21:48:42 +00:00
);
// load the joins
foreach ( $joiners as $as => $join )
{
$query -> join ( 'LEFT' , $this -> db -> quoteName ( '#__componentbuilder_' . $join , $as ) . ' ON (' . $this -> db -> quoteName ( 'a.id' ) . ' = ' . $this -> db -> quoteName ( $as . '.joomla_component' ) . ')' );
}
2017-12-14 23:10:47 +00:00
$query -> where ( $this -> db -> quoteName ( 'a.id' ) . ' = ' . ( int ) $this -> componentID );
2016-02-26 00:20:09 +00:00
2019-06-22 10:43:26 +00:00
// Trigger Event: jcb_ce_onBeforeQueryComponentData
2019-07-01 16:10:28 +00:00
$this -> triggerEvent ( 'jcb_ce_onBeforeQueryComponentData' , array ( & $this -> componentContext , & $this -> componentID , & $query , & $this -> db ));
2019-06-22 10:43:26 +00:00
2016-02-26 00:20:09 +00:00
// Reset the query using our newly populated query object.
2017-02-13 23:24:38 +00:00
$this -> db -> setQuery ( $query );
2016-02-26 00:20:09 +00:00
// Load the results as a list of stdClass objects
2017-02-13 23:24:38 +00:00
$component = $this -> db -> loadObject ();
2017-12-14 23:10:47 +00:00
2019-06-22 10:43:26 +00:00
// Trigger Event: jcb_ce_onBeforeModelComponentData
2019-07-01 16:10:28 +00:00
$this -> triggerEvent ( 'jcb_ce_onBeforeModelComponentData' , array ( & $this -> componentContext , & $component ));
2019-06-22 10:43:26 +00:00
2017-10-29 11:03:06 +00:00
// set upater
$updater = array (
'unique' => array (
'addadmin_views' => array ( 'table' => 'component_admin_views' , 'val' => ( int ) $component -> addadmin_views_id , 'key' => 'id' ),
'addconfig' => array ( 'table' => 'component_config' , 'val' => ( int ) $this -> componentID , 'key' => 'joomla_component' ),
'addcustom_admin_views' => array ( 'table' => 'component_custom_admin_views' , 'val' => ( int ) $this -> componentID , 'key' => 'joomla_component' ),
'addcustommenus' => array ( 'table' => 'component_custom_admin_menus' , 'val' => ( int ) $this -> componentID , 'key' => 'joomla_component' ),
'addfiles' => array ( 'table' => 'component_files_folders' , 'val' => ( int ) $this -> componentID , 'key' => 'joomla_component' ),
'addfolders' => array ( 'table' => 'component_files_folders' , 'val' => ( int ) $this -> componentID , 'key' => 'joomla_component' ),
'addsite_views' => array ( 'table' => 'component_site_views' , 'val' => ( int ) $this -> componentID , 'key' => 'joomla_component' ),
'dashboard_tab' => array ( 'table' => 'component_dashboard' , 'val' => ( int ) $this -> componentID , 'key' => 'joomla_component' ),
'sql_tweak' => array ( 'table' => 'component_mysql_tweaks' , 'val' => ( int ) $this -> componentID , 'key' => 'joomla_component' ),
'version_update' => array ( 'table' => 'component_updates' , 'val' => ( int ) $this -> componentID , 'key' => 'joomla_component' )
),
'table' => 'joomla_component' ,
'key' => 'id' ,
'val' => ( int ) $this -> componentID
);
// repeatable fields to update
$searchRepeatables = array (
// repeatablefield => checker
'addadmin_views' => 'adminview' ,
'addconfig' => 'field' ,
'addcontributors' => 'name' ,
'addcustom_admin_views' => 'customadminview' ,
'addcustommenus' => 'name' ,
'addfiles' => 'file' ,
'addfolders' => 'folder' ,
'addsite_views' => 'siteview' ,
'dashboard_tab' => 'name' ,
'sql_tweak' => 'adminview' ,
'version_update' => 'version'
);
// update the repeatable fields
$component = ComponentbuilderHelper :: convertRepeatableFields ( $component , $searchRepeatables , $updater );
2017-12-14 23:10:47 +00:00
2019-02-15 22:03:21 +00:00
// load the global placeholders
if ( ComponentbuilderHelper :: checkArray ( $this -> globalPlaceholders ))
{
2019-07-28 21:48:42 +00:00
$this -> placeholders = $this -> globalPlaceholders ;
2019-02-15 22:03:21 +00:00
}
2016-02-26 00:20:09 +00:00
// set component sales name
$component -> sales_name = ComponentbuilderHelper :: safeString ( $component -> system_name );
2017-12-14 23:10:47 +00:00
2016-02-26 00:20:09 +00:00
// ensure version naming is correct
$this -> component_version = preg_replace ( '/[^0-9.]+/' , '' , $component -> component_version );
2017-12-14 23:10:47 +00:00
2018-02-16 21:53:43 +00:00
// set the add targets
$addArrayF = array ( 'files' => 'files' , 'folders' => 'folders' , 'filesfullpath' => 'files' , 'foldersfullpath' => 'folders' );
foreach ( $addArrayF as $addTarget => $targetHere )
2016-02-26 00:20:09 +00:00
{
2018-02-16 21:53:43 +00:00
// set the add target data
2018-03-18 04:52:07 +00:00
$component -> { 'add' . $addTarget } = ( isset ( $component -> { 'add' . $addTarget }) && ComponentbuilderHelper :: checkJson ( $component -> { 'add' . $addTarget })) ? json_decode ( $component -> { 'add' . $addTarget }, true ) : null ;
if ( ComponentbuilderHelper :: checkArray ( $component -> { 'add' . $addTarget }))
2018-02-16 21:53:43 +00:00
{
if ( isset ( $component -> { $targetHere }) && ComponentbuilderHelper :: checkArray ( $component -> { $targetHere }))
{
2018-03-18 04:52:07 +00:00
foreach ( $component -> { 'add' . $addTarget } as $taget )
2018-02-16 21:53:43 +00:00
{
$component -> { $targetHere }[] = $taget ;
}
}
else
{
2018-03-18 04:52:07 +00:00
$component -> { $targetHere } = array_values ( $component -> { 'add' . $addTarget });
2018-02-16 21:53:43 +00:00
}
}
2018-03-18 04:52:07 +00:00
unset ( $component -> { 'add' . $addTarget });
2016-02-26 00:20:09 +00:00
}
2017-12-14 23:10:47 +00:00
2016-02-26 00:20:09 +00:00
// set the uikit switch
2017-11-11 04:33:51 +00:00
$this -> uikit = $component -> adduikit ;
2017-12-14 23:10:47 +00:00
2018-07-08 20:18:32 +00:00
// set whmcs links if needed
if ( 1 == $component -> add_license && ( ! isset ( $component -> whmcs_buy_link ) || ! ComponentbuilderHelper :: checkString ( $component -> whmcs_buy_link )))
{
// update with the whmcs url
if ( isset ( $component -> whmcs_url ) && ComponentbuilderHelper :: checkString ( $component -> whmcs_url ))
{
$component -> whmcs_buy_link = $component -> whmcs_url ;
}
// use the company website
elseif ( isset ( $component -> website ) && ComponentbuilderHelper :: checkString ( $component -> website ))
{
$component -> whmcs_buy_link = $component -> website ;
$component -> whmcs_url = rtrim ( $component -> website , '/' ) . '/whmcs' ;
}
// none set
else
{
$component -> whmcs_buy_link = '#' ;
$component -> whmcs_url = '#' ;
}
}
2018-07-08 23:17:04 +00:00
// since the license details are not set clear
2018-07-10 15:09:21 +00:00
elseif ( 0 == $component -> add_license )
2018-07-08 23:17:04 +00:00
{
$component -> whmcs_key = '' ;
$component -> whmcs_buy_link = '' ;
$component -> whmcs_url = '' ;
}
2018-07-08 20:18:32 +00:00
2016-02-26 00:20:09 +00:00
// set the footable switch
if ( $component -> addfootable )
{
$this -> footable = true ;
2016-04-22 12:03:43 +00:00
// add the version
$this -> footableVersion = ( 1 == $component -> addfootable || 2 == $component -> addfootable ) ? 2 : $component -> addfootable ;
2016-02-26 00:20:09 +00:00
}
2017-12-14 23:10:47 +00:00
2017-10-29 11:03:06 +00:00
// set the addcustommenus data
2017-12-14 23:10:47 +00:00
$component -> addcustommenus = ( isset ( $component -> addcustommenus ) && ComponentbuilderHelper :: checkJson ( $component -> addcustommenus )) ? json_decode ( $component -> addcustommenus , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $component -> addcustommenus ))
2016-02-26 00:20:09 +00:00
{
2017-10-29 11:03:06 +00:00
$component -> custommenus = array_values ( $component -> addcustommenus );
2016-02-26 00:20:09 +00:00
}
2017-10-29 11:03:06 +00:00
unset ( $component -> addcustommenus );
2017-12-14 23:10:47 +00:00
2017-10-29 11:03:06 +00:00
// set the sql_tweak data
2017-12-14 23:10:47 +00:00
$component -> sql_tweak = ( isset ( $component -> sql_tweak ) && ComponentbuilderHelper :: checkJson ( $component -> sql_tweak )) ? json_decode ( $component -> sql_tweak , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $component -> sql_tweak ))
2016-02-26 00:20:09 +00:00
{
2017-10-29 11:03:06 +00:00
// build the tweak settings
2017-12-14 23:10:47 +00:00
$this -> setSqlTweaking ( array_map ( function ( $array )
{
return array_map ( function ( $value )
2016-02-26 00:20:09 +00:00
{
2017-12-14 23:10:47 +00:00
if ( ! ComponentbuilderHelper :: checkArray ( $value ) && ! ComponentbuilderHelper :: checkObject ( $value ) && strval ( $value ) === strval ( intval ( $value )))
{
return ( int ) $value ;
}
return $value ;
}, $array );
}, array_values ( $component -> sql_tweak )));
2016-02-26 00:20:09 +00:00
}
2017-10-29 11:03:06 +00:00
unset ( $component -> sql_tweak );
2017-12-14 23:10:47 +00:00
2016-02-26 00:20:09 +00:00
// set the admin_view data
2017-12-14 23:10:47 +00:00
$component -> addadmin_views = ( isset ( $component -> addadmin_views ) && ComponentbuilderHelper :: checkJson ( $component -> addadmin_views )) ? json_decode ( $component -> addadmin_views , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $component -> addadmin_views ))
2016-02-26 00:20:09 +00:00
{
// sort the views acording to order
2017-10-29 11:03:06 +00:00
usort ( $component -> addadmin_views , function ( $a , $b )
2016-02-26 00:20:09 +00:00
{
if ( $a [ 'order' ] != 0 && $b [ 'order' ] != 0 )
{
return $a [ 'order' ] - $b [ 'order' ];
}
elseif ( $b [ 'order' ] != 0 && $a [ 'order' ] == 0 )
{
return 1 ;
}
elseif ( $a [ 'order' ] != 0 && $b [ 'order' ] == 0 )
{
return 0 ;
}
return 1 ;
});
2017-10-29 11:03:06 +00:00
// build the admin_views settings
2017-12-14 23:10:47 +00:00
$component -> admin_views = array_map ( function ( $array )
{
2018-05-11 04:08:14 +00:00
$array = array_map ( function ( $value )
{
2017-12-14 23:10:47 +00:00
if ( ! ComponentbuilderHelper :: checkArray ( $value ) && ! ComponentbuilderHelper :: checkObject ( $value ) && strval ( $value ) === strval ( intval ( $value )))
2017-10-29 11:03:06 +00:00
{
return ( int ) $value ;
}
return $value ;
}, $array );
2018-03-30 01:29:24 +00:00
// check if we must add to site
2019-04-09 21:54:54 +00:00
if ( isset ( $array [ 'edit_create_site_view' ]) && is_numeric ( $array [ 'edit_create_site_view' ]) && $array [ 'edit_create_site_view' ] > 0 )
2018-03-30 01:29:24 +00:00
{
$this -> siteEditView [ $array [ 'adminview' ]] = true ;
$this -> lang = 'both' ;
}
2017-10-30 13:08:02 +00:00
if ( isset ( $array [ 'port' ]) && $array [ 'port' ] && ! $this -> addEximport )
2016-02-26 00:20:09 +00:00
{
$this -> addEximport = true ;
}
2017-10-30 13:08:02 +00:00
if ( isset ( $array [ 'history' ]) && $array [ 'history' ] && ! $this -> setTagHistory )
2016-02-26 00:20:09 +00:00
{
$this -> setTagHistory = true ;
}
2018-08-23 01:37:42 +00:00
if ( isset ( $array [ 'joomla_fields' ]) && $array [ 'joomla_fields' ] && ! $this -> setJoomlaFields )
{
$this -> setJoomlaFields = true ;
}
2018-03-30 01:29:24 +00:00
// has become a lacacy issue, can't remove this
$array [ 'view' ] = $array [ 'adminview' ];
// get the admin settings/data
$array [ 'settings' ] = $this -> getAdminViewData ( $array [ 'view' ]);
2018-04-23 00:42:41 +00:00
2017-10-29 11:03:06 +00:00
return $array ;
}, array_values ( $component -> addadmin_views ));
2016-02-26 00:20:09 +00:00
}
// set the site_view data
2017-12-14 23:10:47 +00:00
$component -> addsite_views = ( isset ( $component -> addsite_views ) && ComponentbuilderHelper :: checkJson ( $component -> addsite_views )) ? json_decode ( $component -> addsite_views , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $component -> addsite_views ))
2016-02-26 00:20:09 +00:00
{
2017-10-29 11:03:06 +00:00
$this -> lang = 'site' ;
$this -> target = 'site' ;
// build the site_views settings
2017-12-14 23:10:47 +00:00
$component -> site_views = array_map ( function ( $array )
{
2017-10-29 11:03:06 +00:00
// has become a lacacy issue, can't remove this
$array [ 'view' ] = $array [ 'siteview' ];
$array [ 'settings' ] = $this -> getCustomViewData ( $array [ 'view' ]);
2017-12-14 23:10:47 +00:00
return array_map ( function ( $value )
{
if ( ! ComponentbuilderHelper :: checkArray ( $value ) && ! ComponentbuilderHelper :: checkObject ( $value ) && strval ( $value ) === strval ( intval ( $value )))
2016-02-26 00:20:09 +00:00
{
2017-10-29 11:03:06 +00:00
return ( int ) $value ;
2016-02-26 00:20:09 +00:00
}
2017-10-29 11:03:06 +00:00
return $value ;
}, $array );
}, array_values ( $component -> addsite_views ));
// unset original value
2016-02-26 00:20:09 +00:00
unset ( $component -> addsite_views );
}
// set the custom_admin_views data
2017-12-14 23:10:47 +00:00
$component -> addcustom_admin_views = ( isset ( $component -> addcustom_admin_views ) && ComponentbuilderHelper :: checkJson ( $component -> addcustom_admin_views )) ? json_decode ( $component -> addcustom_admin_views , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $component -> addcustom_admin_views ))
2016-02-26 00:20:09 +00:00
{
2017-10-29 11:03:06 +00:00
$this -> lang = 'admin' ;
$this -> target = 'custom_admin' ;
// build the custom_admin_views settings
2017-12-14 23:10:47 +00:00
$component -> custom_admin_views = array_map ( function ( $array )
{
2017-10-29 11:03:06 +00:00
// has become a lacacy issue, can't remove this
$array [ 'view' ] = $array [ 'customadminview' ];
$array [ 'settings' ] = $this -> getCustomViewData ( $array [ 'view' ], 'custom_admin_view' );
2017-12-14 23:10:47 +00:00
return array_map ( function ( $value )
{
if ( ! ComponentbuilderHelper :: checkArray ( $value ) && ! ComponentbuilderHelper :: checkObject ( $value ) && strval ( $value ) === strval ( intval ( $value )))
2016-02-26 00:20:09 +00:00
{
2017-10-29 11:03:06 +00:00
return ( int ) $value ;
2016-02-26 00:20:09 +00:00
}
2017-10-29 11:03:06 +00:00
return $value ;
}, $array );
}, array_values ( $component -> addcustom_admin_views ));
// unset original value
2016-02-26 00:20:09 +00:00
unset ( $component -> addcustom_admin_views );
}
2017-12-03 18:09:04 +00:00
// set the config data
2017-12-14 23:10:47 +00:00
$component -> addconfig = ( isset ( $component -> addconfig ) && ComponentbuilderHelper :: checkJson ( $component -> addconfig )) ? json_decode ( $component -> addconfig , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $component -> addconfig ))
2016-02-26 00:20:09 +00:00
{
2018-10-01 02:16:24 +00:00
$component -> config = array_map ( function ( $field ) {
// make sure the alias and title is 0
2018-03-11 02:44:43 +00:00
$field [ 'alias' ] = 0 ;
$field [ 'title' ] = 0 ;
2018-10-01 02:16:24 +00:00
// set the field details
$this -> setFieldDetails ( $field );
// set unique name counter
$this -> setUniqueNameCounter ( $field [ 'base_name' ], 'configs' );
2018-03-11 02:44:43 +00:00
// return field
return $field ;
2017-10-29 11:03:06 +00:00
}, array_values ( $component -> addconfig ));
2018-03-11 02:44:43 +00:00
// do some house cleaning (for fields)
foreach ( $component -> config as $field )
{
// so first we lock the field name in
$this -> getFieldName ( $field , 'configs' );
}
2017-10-29 11:03:06 +00:00
// unset original value
2016-02-26 00:20:09 +00:00
unset ( $component -> addconfig );
}
2017-12-14 23:10:47 +00:00
2017-10-29 11:03:06 +00:00
// set the addcustommenus data
2017-12-14 23:10:47 +00:00
$component -> addcontributors = ( isset ( $component -> addcontributors ) && ComponentbuilderHelper :: checkJson ( $component -> addcontributors )) ? json_decode ( $component -> addcontributors , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $component -> addcontributors ))
2016-02-26 00:20:09 +00:00
{
$this -> addContributors = true ;
2017-10-29 11:03:06 +00:00
$component -> contributors = array_values ( $component -> addcontributors );
2016-02-26 00:20:09 +00:00
}
2017-10-29 11:03:06 +00:00
unset ( $component -> addcontributors );
2017-12-14 23:10:47 +00:00
2017-10-29 11:03:06 +00:00
// set the addcustommenus data
2017-12-14 23:10:47 +00:00
$component -> version_update = ( isset ( $component -> version_update ) && ComponentbuilderHelper :: checkJson ( $component -> version_update )) ? json_decode ( $component -> version_update , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $component -> version_update ))
2016-02-26 00:20:09 +00:00
{
2017-10-29 11:03:06 +00:00
$component -> version_update = array_values ( $component -> version_update );
}
2017-12-14 23:10:47 +00:00
2017-06-16 12:38:06 +00:00
// build update SQL
2017-10-30 18:50:56 +00:00
$old_admin_views = $this -> getHistoryWatch ( 'component_admin_views' , $component -> addadmin_views_id );
$old_component = $this -> getHistoryWatch ( 'joomla_component' , $this -> componentID );
if ( $old_component || $old_admin_views )
2017-06-16 12:38:06 +00:00
{
2017-10-30 13:08:02 +00:00
if ( ComponentbuilderHelper :: checkObject ( $old_admin_views ))
2017-06-16 12:38:06 +00:00
{
2017-10-30 13:08:02 +00:00
// add new views if found
if ( isset ( $old_admin_views -> addadmin_views ) && ComponentbuilderHelper :: checkJson ( $old_admin_views -> addadmin_views ))
{
$this -> setUpdateSQL ( json_decode ( $old_admin_views -> addadmin_views , true ), $component -> addadmin_views , 'adminview' );
}
// check if a new version was manualy set
if ( ComponentbuilderHelper :: checkObject ( $old_component ))
{
$old_component_version = preg_replace ( '/[^0-9.]+/' , '' , $old_component -> component_version );
if ( $old_component_version != $this -> component_version )
{
// yes, this is a new version, this mean there may be manual sql and must be checked and updated
$component -> old_component_version = $old_component_version ;
}
// clear this data
unset ( $old_component );
}
// clear this data
unset ( $old_admin_views );
2017-06-16 12:38:06 +00:00
}
2016-02-26 00:20:09 +00:00
}
2017-10-29 11:03:06 +00:00
// unset original value
unset ( $component -> addadmin_views );
2016-02-26 00:20:09 +00:00
2019-07-28 21:48:42 +00:00
// set GUI mapper
$guiMapper = array ( 'table' => 'joomla_component' , 'id' => ( int ) $this -> componentID , 'field' => 'javascript' , 'type' => 'js' );
2017-10-06 14:53:22 +00:00
// add_javascript
if ( $component -> add_javascript == 1 )
{
2019-07-28 21:48:42 +00:00
$this -> setCustomScriptBuilder (
$component -> javascript ,
'component_js' ,
false ,
false ,
$guiMapper
);
2017-10-06 14:53:22 +00:00
}
else
{
$this -> customScriptBuilder [ 'component_js' ] = '' ;
}
unset ( $component -> javascript );
2018-01-15 15:54:05 +00:00
// add global CSS
$addGlobalCss = array ( 'admin' , 'site' );
foreach ( $addGlobalCss as $area )
2016-02-26 00:20:09 +00:00
{
2018-01-15 15:54:05 +00:00
// add_css if found
2018-03-18 04:52:07 +00:00
if ( isset ( $component -> { 'add_css_' . $area }) && $component -> { 'add_css_' . $area } == 1 && isset ( $component -> { 'css_' . $area }) && ComponentbuilderHelper :: checkString ( $component -> { 'css_' . $area }))
2018-01-15 15:54:05 +00:00
{
2019-07-28 21:48:42 +00:00
$this -> setCustomScriptBuilder (
$component -> { 'css_' . $area },
'component_css_' . $area
);
2018-01-15 15:54:05 +00:00
}
else
{
2018-03-18 04:52:07 +00:00
$this -> customScriptBuilder [ 'component_css_' . $area ] = '' ;
2018-01-15 15:54:05 +00:00
}
2018-03-18 04:52:07 +00:00
unset ( $component -> { 'css_' . $area });
2016-02-26 00:20:09 +00:00
}
2016-10-23 22:48:26 +00:00
// set the lang target
$this -> lang = 'admin' ;
// add PHP in ADMIN
2017-12-14 23:10:47 +00:00
$addScriptMethods = array ( 'php_preflight' , 'php_postflight' , 'php_method' );
$addScriptTypes = array ( 'install' , 'update' , 'uninstall' );
2019-07-28 21:48:42 +00:00
// update GUI mapper
$guiMapper [ 'type' ] = 'php' ;
2016-10-23 22:48:26 +00:00
foreach ( $addScriptMethods as $scriptMethod )
2017-12-14 23:10:47 +00:00
{
2016-10-23 22:48:26 +00:00
foreach ( $addScriptTypes as $scriptType )
{
2017-12-14 23:10:47 +00:00
if ( isset ( $component -> { 'add_' . $scriptMethod . '_' . $scriptType }) && $component -> { 'add_' . $scriptMethod . '_' . $scriptType } == 1 && ComponentbuilderHelper :: checkString ( $component -> { $scriptMethod . '_' . $scriptType }))
2016-10-23 22:48:26 +00:00
{
2019-07-28 21:48:42 +00:00
// set GUI mapper field
$guiMapper [ 'field' ] = $scriptMethod . '_' . $scriptType ;
$this -> setCustomScriptBuilder (
$component -> { $scriptMethod . '_' . $scriptType },
$scriptMethod ,
$scriptType ,
false ,
$guiMapper
);
2016-10-23 22:48:26 +00:00
}
else
{
$this -> customScriptBuilder [ $scriptMethod ][ $scriptType ] = '' ;
}
2017-12-14 23:10:47 +00:00
unset ( $component -> { $scriptMethod . '_' . $scriptType });
2016-10-23 22:48:26 +00:00
}
}
2016-02-26 00:20:09 +00:00
// add_php_helper
2017-03-27 12:38:51 +00:00
if ( $component -> add_php_helper_admin == 1 && ComponentbuilderHelper :: checkString ( $component -> php_helper_admin ))
2016-02-26 00:20:09 +00:00
{
$this -> lang = 'admin' ;
2019-07-28 21:48:42 +00:00
// update GUI mapper
$guiMapper [ 'field' ] = 'php_helper_admin' ;
$guiMapper [ 'prefix' ] = PHP_EOL . PHP_EOL ;
$this -> setCustomScriptBuilder (
$component -> php_helper_admin ,
'component_php_helper_admin' ,
false ,
false ,
$guiMapper
);
unset ( $guiMapper [ 'prefix' ]);
2016-02-26 00:20:09 +00:00
}
else
{
$this -> customScriptBuilder [ 'component_php_helper_admin' ] = '' ;
}
2016-10-23 22:48:26 +00:00
unset ( $component -> php_helper );
2016-02-26 00:20:09 +00:00
// add_admin_event
2017-03-27 12:38:51 +00:00
if ( $component -> add_admin_event == 1 && ComponentbuilderHelper :: checkString ( $component -> php_admin_event ))
2016-02-26 00:20:09 +00:00
{
$this -> lang = 'admin' ;
2019-07-28 21:48:42 +00:00
// update GUI mapper field
$guiMapper [ 'field' ] = 'php_admin_event' ;
$this -> setCustomScriptBuilder (
$component -> php_admin_event ,
'component_php_admin_event' ,
false ,
false ,
$guiMapper
);
2016-02-26 00:20:09 +00:00
}
else
{
$this -> customScriptBuilder [ 'component_php_admin_event' ] = '' ;
}
2016-10-23 22:48:26 +00:00
unset ( $component -> php_admin_event );
2016-11-25 02:56:16 +00:00
// add_php_helper_both
2017-03-27 12:38:51 +00:00
if ( $component -> add_php_helper_both == 1 && ComponentbuilderHelper :: checkString ( $component -> php_helper_both ))
2016-11-25 02:56:16 +00:00
{
$this -> lang = 'both' ;
2019-07-28 21:48:42 +00:00
// update GUI mapper field
$guiMapper [ 'field' ] = 'php_helper_both' ;
$guiMapper [ 'prefix' ] = PHP_EOL . PHP_EOL ;
$this -> setCustomScriptBuilder (
$component -> php_helper_both ,
'component_php_helper_both' ,
false ,
false ,
$guiMapper
);
unset ( $guiMapper [ 'prefix' ]);
2016-11-25 02:56:16 +00:00
}
else
{
$this -> customScriptBuilder [ 'component_php_helper_both' ] = '' ;
}
2016-02-26 00:20:09 +00:00
// add_php_helper_site
2017-03-27 12:38:51 +00:00
if ( $component -> add_php_helper_site == 1 && ComponentbuilderHelper :: checkString ( $component -> php_helper_site ))
2016-02-26 00:20:09 +00:00
{
$this -> lang = 'site' ;
2019-07-28 21:48:42 +00:00
// update GUI mapper field
$guiMapper [ 'field' ] = 'php_helper_site' ;
$guiMapper [ 'prefix' ] = PHP_EOL . PHP_EOL ;
$this -> setCustomScriptBuilder (
$component -> php_helper_site ,
'component_php_helper_site' ,
false ,
false ,
$guiMapper
);
unset ( $guiMapper [ 'prefix' ]);
2016-02-26 00:20:09 +00:00
}
else
{
$this -> customScriptBuilder [ 'component_php_helper_site' ] = '' ;
}
2016-10-23 22:48:26 +00:00
unset ( $component -> php_helper );
2016-02-26 00:20:09 +00:00
// add_site_event
2017-03-27 12:38:51 +00:00
if ( $component -> add_site_event == 1 && ComponentbuilderHelper :: checkString ( $component -> php_site_event ))
2016-02-26 00:20:09 +00:00
{
$this -> lang = 'site' ;
2019-07-28 21:48:42 +00:00
// update GUI mapper field
$guiMapper [ 'field' ] = 'php_site_event' ;
$this -> setCustomScriptBuilder (
$component -> php_site_event ,
'component_php_site_event' ,
false ,
false ,
$guiMapper
);
2016-02-26 00:20:09 +00:00
}
else
{
$this -> customScriptBuilder [ 'component_php_site_event' ] = '' ;
}
2016-10-23 22:48:26 +00:00
unset ( $component -> php_site_event );
2016-02-26 00:20:09 +00:00
// add_sql
if ( $component -> add_sql == 1 )
{
2019-07-28 21:48:42 +00:00
$this -> setCustomScriptBuilder (
$component -> sql ,
'sql' ,
'component_sql'
);
2016-02-26 00:20:09 +00:00
}
2016-10-23 22:48:26 +00:00
unset ( $component -> sql );
2018-05-11 04:08:14 +00:00
// add_sql_uninstall
if ( $component -> add_sql_uninstall == 1 )
{
2019-07-28 21:48:42 +00:00
$this -> setCustomScriptBuilder (
$component -> sql_uninstall ,
'sql_uninstall'
);
2018-05-11 04:08:14 +00:00
}
unset ( $component -> sql_uninstall );
2016-02-26 00:20:09 +00:00
// bom
if ( ComponentbuilderHelper :: checkString ( $component -> bom ))
{
2017-12-14 23:10:47 +00:00
$this -> bomPath = $this -> compilerPath . '/' . $component -> bom ;
2016-02-26 00:20:09 +00:00
}
else
{
2017-12-14 23:10:47 +00:00
$this -> bomPath = $this -> compilerPath . '/default.txt' ;
2016-02-26 00:20:09 +00:00
}
2016-10-23 22:48:26 +00:00
unset ( $component -> bom );
2016-02-26 00:20:09 +00:00
// README
if ( $component -> addreadme )
{
2019-12-03 02:17:35 +00:00
$component -> readme = $this -> setDynamicValues ( base64_decode ( $component -> readme ));
2016-02-26 00:20:09 +00:00
}
else
{
$component -> readme = '' ;
}
2018-03-18 04:52:07 +00:00
2017-12-10 19:17:26 +00:00
// set lang now
$nowLang = $this -> lang ;
$this -> lang = 'admin' ;
2016-02-26 00:20:09 +00:00
// dashboard methods
2017-12-14 23:10:47 +00:00
$component -> dashboard_tab = ( isset ( $component -> dashboard_tab ) && ComponentbuilderHelper :: checkJson ( $component -> dashboard_tab )) ? json_decode ( $component -> dashboard_tab , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $component -> dashboard_tab ))
2017-12-10 19:17:26 +00:00
{
2017-12-14 23:10:47 +00:00
$component -> dashboard_tab = array_map ( function ( $array )
{
2017-10-29 11:03:06 +00:00
$array [ 'html' ] = $this -> setDynamicValues ( $array [ 'html' ]);
return $array ;
}, array_values ( $component -> dashboard_tab ));
}
else
{
$component -> dashboard_tab = '' ;
}
// add the php of the dashboard if set
2017-10-29 13:51:43 +00:00
if ( isset ( $component -> php_dashboard_methods ) && ComponentbuilderHelper :: checkString ( $component -> php_dashboard_methods ))
2017-10-29 11:03:06 +00:00
{
2016-02-26 00:20:09 +00:00
// load the php for the dashboard model
2019-07-28 21:48:42 +00:00
$component -> php_dashboard_methods = $this -> setGuiCodePlaceholder (
$this -> setDynamicValues ( base64_decode ( $component -> php_dashboard_methods )),
array (
'table' => 'component_dashboard' ,
'field' => 'php_dashboard_methods' ,
2019-08-04 22:38:53 +00:00
'id' => ( int ) $component -> component_dashboard_id ,
2019-07-28 21:48:42 +00:00
'type' => 'php' )
);
2016-02-26 00:20:09 +00:00
}
else
{
$component -> php_dashboard_methods = '' ;
}
2017-12-10 19:17:26 +00:00
// reset back to nowlang
$this -> lang = $nowLang ;
2017-12-14 23:10:47 +00:00
2018-02-17 22:47:01 +00:00
// add the update/sales server FTP details if that is the expected protocol
2018-03-18 04:52:07 +00:00
$serverArray = array ( 'update_server' , 'sales_server' );
foreach ( $serverArray as $server )
2017-08-25 01:46:12 +00:00
{
2018-03-18 04:52:07 +00:00
if ( $component -> { 'add_' . $server } == 1 && is_numeric ( $component -> { $server }) && $component -> { $server } > 0 )
2018-02-17 22:47:01 +00:00
{
// get the server protocol
2018-03-18 04:52:07 +00:00
$component -> { $server . '_protocol' } = ComponentbuilderHelper :: getVar ( 'server' , ( int ) $component -> { $server }, 'id' , 'protocol' );
2018-02-17 22:47:01 +00:00
}
else
{
$component -> { $server } = 0 ;
2018-02-17 23:11:05 +00:00
// only change this for sales server (update server can be added loacaly to the zip file)
if ( 'sales_server' === $server )
{
2018-03-18 04:52:07 +00:00
$component -> { 'add_' . $server } = 0 ;
2018-02-17 23:11:05 +00:00
}
2018-03-18 04:52:07 +00:00
$component -> { $server . '_protocol' } = 0 ;
2018-02-17 22:47:01 +00:00
}
2017-08-25 01:46:12 +00:00
}
2017-09-18 00:18:23 +00:00
// set the ignore folders for repo if found
2017-09-13 00:37:43 +00:00
if ( isset ( $component -> toignore ) && ComponentbuilderHelper :: checkString ( $component -> toignore ))
{
if ( strpos ( $component -> toignore , ',' ) !== false )
{
$component -> toignore = array_map ( 'trim' , ( array ) explode ( ',' , $component -> toignore ));
}
else
{
$component -> toignore = array ( trim ( $component -> toignore ));
}
}
else
{
2017-09-18 00:18:23 +00:00
// the default is to ignore the repo folder
2017-09-13 00:37:43 +00:00
$component -> toignore = array ( '.git' );
}
2019-12-06 05:31:32 +00:00
// get all modules
$component -> addjoomla_modules = ( isset ( $component -> addjoomla_modules ) && ComponentbuilderHelper :: checkJson ( $component -> addjoomla_modules )) ? json_decode ( $component -> addjoomla_modules , true ) : null ;
if ( ComponentbuilderHelper :: checkArray ( $component -> addjoomla_modules ))
{
$joomla_modules = array_map ( function ( $array ) use ( & $component ) {
// only load the modules whose target association calls for it
if ( ! isset ( $array [ 'target' ]) || $array [ 'target' ] != 2 )
{
return $this -> setJoomlaModule ( $array [ 'module' ], $component );
}
return null ;
}, array_values ( $component -> addjoomla_modules ));
}
unset ( $component -> addjoomla_modules );
2019-07-28 21:48:42 +00:00
// get all plugins
$component -> addjoomla_plugins = ( isset ( $component -> addjoomla_plugins ) && ComponentbuilderHelper :: checkJson ( $component -> addjoomla_plugins )) ? json_decode ( $component -> addjoomla_plugins , true ) : null ;
if ( ComponentbuilderHelper :: checkArray ( $component -> addjoomla_plugins ))
{
2019-08-22 01:54:47 +00:00
$joomla_plugins = array_map ( function ( $array ) use ( & $component ) {
2019-12-06 05:31:32 +00:00
// only load the plugins whose target association calls for it
2019-09-10 16:47:39 +00:00
if ( ! isset ( $array [ 'target' ]) || $array [ 'target' ] != 2 )
{
return $this -> setJoomlaPlugin ( $array [ 'plugin' ], $component );
}
return null ;
2019-07-28 21:48:42 +00:00
}, array_values ( $component -> addjoomla_plugins ));
}
unset ( $component -> addjoomla_plugins );
2017-12-14 23:10:47 +00:00
2019-06-22 10:43:26 +00:00
// Trigger Event: jcb_ce_onAfterModelComponentData
2019-07-01 16:10:28 +00:00
$this -> triggerEvent ( 'jcb_ce_onAfterModelComponentData' , array ( & $this -> componentContext , & $component ));
2019-06-22 10:43:26 +00:00
2016-02-26 00:20:09 +00:00
// return the found component data
return $component ;
}
2017-12-14 23:10:47 +00:00
2019-07-04 23:53:54 +00:00
/**
* set the language content values to language content array
*
* @ param string $target The target area for the language string
* @ param string $language The language key string
* @ param string $string The language string
* @ param boolean $addPrefix The switch to add langPrefix
*
* @ return void
*
*/
public function setLangContent ( $target , $language , $string , $addPrefix = false )
{
if ( $addPrefix && ! isset ( $this -> langContent [ $target ][ $this -> langPrefix . '_' . $language ]))
{
$this -> langContent [ $target ][ $this -> langPrefix . '_' . $language ] = trim ( $string );
}
elseif ( ! isset ( $this -> langContent [ $target ][ $language ]))
{
$this -> langContent [ $target ][ $language ] = trim ( $string );
}
}
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* Get all Admin View Data
*
* @ param int $id The view ID
*
* @ return oject The view data
*
*/
public function getAdminViewData ( $id )
{
if ( ! isset ( $this -> _adminViewData [ $id ]))
{
// Create a new query object.
2017-02-13 23:24:38 +00:00
$query = $this -> db -> getQuery ( true );
2016-02-26 00:20:09 +00:00
$query -> select ( 'a.*' );
2017-10-29 11:03:06 +00:00
$query -> select (
$this -> db -> quoteName (
array (
2017-12-14 23:10:47 +00:00
'b.addfields' ,
'b.id' ,
'c.addconditions' ,
2018-05-24 13:56:56 +00:00
'c.id' ,
2018-08-24 21:46:41 +00:00
'r.addrelations' ,
't.tabs'
2017-12-14 23:10:47 +00:00
), array (
'addfields' ,
'addfields_id' ,
'addconditions' ,
2018-05-24 13:56:56 +00:00
'addconditions_id' ,
2018-08-24 21:46:41 +00:00
'addrelations' ,
'customtabs'
2017-10-29 11:03:06 +00:00
)
2017-12-14 23:10:47 +00:00
)
);
2016-02-26 00:20:09 +00:00
$query -> from ( '#__componentbuilder_admin_view AS a' );
2017-10-29 11:03:06 +00:00
$query -> join ( 'LEFT' , $this -> db -> quoteName ( '#__componentbuilder_admin_fields' , 'b' ) . ' ON (' . $this -> db -> quoteName ( 'a.id' ) . ' = ' . $this -> db -> quoteName ( 'b.admin_view' ) . ')' );
$query -> join ( 'LEFT' , $this -> db -> quoteName ( '#__componentbuilder_admin_fields_conditions' , 'c' ) . ' ON (' . $this -> db -> quoteName ( 'a.id' ) . ' = ' . $this -> db -> quoteName ( 'c.admin_view' ) . ')' );
2018-05-24 13:56:56 +00:00
$query -> join ( 'LEFT' , $this -> db -> quoteName ( '#__componentbuilder_admin_fields_relations' , 'r' ) . ' ON (' . $this -> db -> quoteName ( 'a.id' ) . ' = ' . $this -> db -> quoteName ( 'r.admin_view' ) . ')' );
2018-08-24 21:46:41 +00:00
$query -> join ( 'LEFT' , $this -> db -> quoteName ( '#__componentbuilder_admin_custom_tabs' , 't' ) . ' ON (' . $this -> db -> quoteName ( 'a.id' ) . ' = ' . $this -> db -> quoteName ( 't.admin_view' ) . ')' );
2017-12-14 23:10:47 +00:00
$query -> where ( $this -> db -> quoteName ( 'a.id' ) . ' = ' . ( int ) $id );
2016-02-26 00:20:09 +00:00
2019-06-22 10:43:26 +00:00
// Trigger Event: jcb_ce_onBeforeQueryViewData
2019-07-01 16:10:28 +00:00
$this -> triggerEvent ( 'jcb_ce_onBeforeQueryViewData' , array ( & $this -> componentContext , & $id , & $query , & $this -> db ));
2019-06-22 10:43:26 +00:00
2016-02-26 00:20:09 +00:00
// Reset the query using our newly populated query object.
2017-02-13 23:24:38 +00:00
$this -> db -> setQuery ( $query );
2016-02-26 00:20:09 +00:00
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
2017-02-13 23:24:38 +00:00
$view = $this -> db -> loadObject ();
2018-01-15 15:54:05 +00:00
2016-02-26 00:20:09 +00:00
// setup view name to use in storing the data
$name_single = ComponentbuilderHelper :: safeString ( $view -> name_single );
$name_list = ComponentbuilderHelper :: safeString ( $view -> name_list );
2017-12-14 23:10:47 +00:00
2017-10-29 11:03:06 +00:00
// set upater
$updater = array (
'unique' => array (
'addfields' => array ( 'table' => 'admin_fields' , 'val' => ( int ) $view -> addfields_id , 'key' => 'id' ),
'addconditions' => array ( 'table' => 'admin_fields_conditions' , 'val' => ( int ) $view -> addconditions_id , 'key' => 'id' )
),
'table' => 'admin_view' ,
'key' => 'id' ,
'val' => ( int ) $id
);
// repeatable fields to update
$searchRepeatables = array (
// repeatablefield => checker
'addfields' => 'field' ,
'addconditions' => 'target_field' ,
'ajax_input' => 'value_name' ,
'custom_button' => 'name' ,
2017-12-14 23:10:47 +00:00
'addlinked_views' => 'adminview' ,
2017-10-29 11:03:06 +00:00
'addtables' => 'table' ,
2017-12-14 23:10:47 +00:00
'addtabs' => 'name' ,
2017-10-29 11:03:06 +00:00
'addpermissions' => 'action'
);
// update the repeatable fields
$view = ComponentbuilderHelper :: convertRepeatableFields ( $view , $searchRepeatables , $updater );
2017-12-14 23:10:47 +00:00
2016-02-26 00:20:09 +00:00
// setup token check
2017-02-13 23:24:38 +00:00
if ( ! isset ( $this -> customScriptBuilder [ 'token' ]))
{
$this -> customScriptBuilder [ 'token' ] = array ();
}
2016-02-26 00:20:09 +00:00
$this -> customScriptBuilder [ 'token' ][ $name_single ] = false ;
$this -> customScriptBuilder [ 'token' ][ $name_list ] = false ;
2017-10-06 14:53:22 +00:00
// set some placeholders
2018-05-22 19:01:36 +00:00
$this -> placeholders [ $this -> hhh . 'view' . $this -> hhh ] = ComponentbuilderHelper :: safeString ( $name_single );
$this -> placeholders [ $this -> hhh . 'views' . $this -> hhh ] = ComponentbuilderHelper :: safeString ( $name_list );
$this -> placeholders [ $this -> hhh . 'View' . $this -> hhh ] = ComponentbuilderHelper :: safeString ( $name_single , 'F' );
$this -> placeholders [ $this -> hhh . 'Views' . $this -> hhh ] = ComponentbuilderHelper :: safeString ( $name_list , 'F' );
$this -> placeholders [ $this -> hhh . 'VIEW' . $this -> hhh ] = ComponentbuilderHelper :: safeString ( $name_single , 'U' );
$this -> placeholders [ $this -> hhh . 'VIEWS' . $this -> hhh ] = ComponentbuilderHelper :: safeString ( $name_list , 'U' );
$this -> placeholders [ $this -> bbb . 'view' . $this -> ddd ] = $this -> placeholders [ $this -> hhh . 'view' . $this -> hhh ];
$this -> placeholders [ $this -> bbb . 'views' . $this -> ddd ] = $this -> placeholders [ $this -> hhh . 'views' . $this -> hhh ];
$this -> placeholders [ $this -> bbb . 'View' . $this -> ddd ] = $this -> placeholders [ $this -> hhh . 'View' . $this -> hhh ];
$this -> placeholders [ $this -> bbb . 'Views' . $this -> ddd ] = $this -> placeholders [ $this -> hhh . 'Views' . $this -> hhh ];
$this -> placeholders [ $this -> bbb . 'VIEW' . $this -> ddd ] = $this -> placeholders [ $this -> hhh . 'VIEW' . $this -> hhh ];
$this -> placeholders [ $this -> bbb . 'VIEWS' . $this -> ddd ] = $this -> placeholders [ $this -> hhh . 'VIEWS' . $this -> hhh ];
2019-06-22 10:43:26 +00:00
// Trigger Event: jcb_ce_onBeforeModelViewData
2019-07-01 16:10:28 +00:00
$this -> triggerEvent ( 'jcb_ce_onBeforeModelViewData' , array ( & $this -> componentContext , & $view , & $this -> placeholders ));
2019-06-22 10:43:26 +00:00
2017-10-12 00:50:14 +00:00
// add the tables
2017-12-14 23:10:47 +00:00
$view -> addtables = ( isset ( $view -> addtables ) && ComponentbuilderHelper :: checkJson ( $view -> addtables )) ? json_decode ( $view -> addtables , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $view -> addtables ))
2017-10-12 00:50:14 +00:00
{
$view -> tables = array_values ( $view -> addtables );
}
unset ( $view -> addtables );
2018-08-24 21:46:41 +00:00
// set custom tabs
$this -> customTabs [ $name_single ] = null ;
$view -> customtabs = ( isset ( $view -> customtabs ) && ComponentbuilderHelper :: checkJson ( $view -> customtabs )) ? json_decode ( $view -> customtabs , true ) : null ;
if ( ComponentbuilderHelper :: checkArray ( $view -> customtabs ))
{
// setup custom tabs to global data sets
$this -> customTabs [ $name_single ] = array_map ( function ( $tab ) use ( $name_single ) {
// set the view name
$tab [ 'view' ] = $name_single ;
// load the dynamic data
2018-08-30 16:33:30 +00:00
$tab [ 'html' ] = $this -> setPlaceholders ( $this -> setDynamicValues ( $tab [ 'html' ]), $this -> placeholders );
2018-08-24 21:46:41 +00:00
// set the tab name
$tab [ 'name' ] = ( isset ( $tab [ 'name' ]) && ComponentbuilderHelper :: checkString ( $tab [ 'name' ])) ? $tab [ 'name' ] : 'Tab' ;
// set lang
$tab [ 'lang' ] = $this -> langPrefix . '_' . ComponentbuilderHelper :: safeString ( $tab [ 'view' ], 'U' ) . '_' . ComponentbuilderHelper :: safeString ( $tab [ 'name' ], 'U' );
2019-07-04 23:53:54 +00:00
$this -> setLangContent ( 'both' , $tab [ 'lang' ], $tab [ 'name' ]);
2018-08-24 21:46:41 +00:00
// set code name
$tab [ 'code' ] = ComponentbuilderHelper :: safeString ( $tab [ 'name' ]);
// check if the permissions for the tab should be added
$_tab = '' ;
if ( isset ( $tab [ 'permission' ]) && $tab [ 'permission' ] == 1 )
{
$_tab = $this -> _t ( 1 );
}
// check if the php of the tab is set, if not load it now
if ( strpos ( $tab [ 'html' ], 'bootstrap.addTab' ) === false && strpos ( $tab [ 'html' ], 'bootstrap.endTab' ) === false )
{
// add the tab
$tmp = PHP_EOL . $_tab . $this -> _t ( 1 ) . " <?php echo JHtml::_('bootstrap.addTab', ' " . $tab [ 'view' ] . " Tab', ' " . $tab [ 'code' ] . " ', JText::_(' " . $tab [ 'lang' ] . " ', true)); ?> " ;
$tmp .= PHP_EOL . $_tab . $this -> _t ( 2 ) . '<div class="row-fluid form-horizontal-desktop">' ;
$tmp .= PHP_EOL . $_tab . $this -> _t ( 3 ) . '<div class="span12">' ;
$tmp .= PHP_EOL . $_tab . $this -> _t ( 4 ) . implode ( PHP_EOL . $_tab . $this -> _t ( 4 ), ( array ) explode ( PHP_EOL , trim ( $tab [ 'html' ])));
$tmp .= PHP_EOL . $_tab . $this -> _t ( 3 ) . '</div>' ;
$tmp .= PHP_EOL . $_tab . $this -> _t ( 2 ) . '</div>' ;
$tmp .= PHP_EOL . $_tab . $this -> _t ( 1 ) . " <?php echo JHtml::_('bootstrap.endTab'); ?> " ;
// update html
$tab [ 'html' ] = $tmp ;
}
else
{
$tab [ 'html' ] = PHP_EOL . $_tab . $this -> _t ( 1 ) . implode ( PHP_EOL . $_tab . $this -> _t ( 1 ), ( array ) explode ( PHP_EOL , trim ( $tab [ 'html' ])));
}
// add the permissions if needed
if ( isset ( $tab [ 'permission' ]) && $tab [ 'permission' ] == 1 )
{
$tmp = PHP_EOL . $this -> _t ( 1 ) . " <?php if ( \$ this->canDo->get(' " . $tab [ 'view' ] . " . " . $tab [ 'code' ] . " .viewtab')) : ?> " ;
$tmp .= $tab [ 'html' ];
$tmp .= PHP_EOL . $this -> _t ( 1 ) . " <?php endif; ?> " ;
// update html
$tab [ 'html' ] = $tmp ;
// set lang for permissions
$tab [ 'lang_permission' ] = $tab [ 'lang' ] . '_TAB_PERMISSION' ;
$tab [ 'lang_permission_desc' ] = $tab [ 'lang' ] . '_TAB_PERMISSION_DESC' ;
$tab [ 'lang_permission_title' ] = $this -> placeholders [ $this -> hhh . 'Views' . $this -> hhh ] . ' View ' . $tab [ 'name' ] . ' Tab' ;
2019-07-04 23:53:54 +00:00
$this -> setLangContent ( 'both' , $tab [ 'lang_permission' ], $tab [ 'lang_permission_title' ]);
$this -> setLangContent ( 'both' , $tab [ 'lang_permission_desc' ], 'Allow the users in this group to view ' . $tab [ 'name' ] . ' Tab of ' . $this -> placeholders [ $this -> hhh . 'views' . $this -> hhh ]);
2018-08-24 21:46:41 +00:00
// set the sort key
$tab [ 'sortKey' ] = ComponentbuilderHelper :: safeString ( $tab [ 'lang_permission_title' ]);
}
// return tab
return $tab ;
}, array_values ( $view -> customtabs ));
}
unset ( $view -> customtabs );
// add the local tabs
2017-12-14 23:10:47 +00:00
$view -> addtabs = ( isset ( $view -> addtabs ) && ComponentbuilderHelper :: checkJson ( $view -> addtabs )) ? json_decode ( $view -> addtabs , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $view -> addtabs ))
2016-02-26 00:20:09 +00:00
{
2017-10-12 00:50:14 +00:00
$nr = 1 ;
foreach ( $view -> addtabs as $tab )
2016-02-26 00:20:09 +00:00
{
2017-10-26 16:43:51 +00:00
$view -> tabs [ $nr ] = trim ( $tab [ 'name' ]);
2017-10-12 00:50:14 +00:00
$nr ++ ;
2016-02-26 00:20:09 +00:00
}
}
2017-10-26 16:43:51 +00:00
// if Details tab is not set, then set it here
if ( ! isset ( $view -> tabs [ 1 ]))
{
2017-10-26 21:11:52 +00:00
$view -> tabs [ 1 ] = 'Details' ;
2017-10-26 16:43:51 +00:00
}
// always make sure that publishing is lowercase
if (( $removeKey = array_search ( 'publishing' , array_map ( 'strtolower' , $view -> tabs ))) !== false )
{
$view -> tabs [ $removeKey ] = 'publishing' ;
}
// make sure to set the publishing tab (just incase we need it)
$view -> tabs [ 15 ] = 'publishing' ;
2017-10-12 00:50:14 +00:00
unset ( $view -> addtabs );
// add permissions
2017-12-14 23:10:47 +00:00
$view -> addpermissions = ( isset ( $view -> addpermissions ) && ComponentbuilderHelper :: checkJson ( $view -> addpermissions )) ? json_decode ( $view -> addpermissions , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $view -> addpermissions ))
2017-10-12 00:50:14 +00:00
{
$view -> permissions = array_values ( $view -> addpermissions );
2016-02-26 00:20:09 +00:00
}
2017-10-12 00:50:14 +00:00
unset ( $view -> addpermissions );
// reset fields
$view -> fields = array ();
// set fields
2017-12-14 23:10:47 +00:00
$view -> addfields = ( isset ( $view -> addfields ) && ComponentbuilderHelper :: checkJson ( $view -> addfields )) ? json_decode ( $view -> addfields , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $view -> addfields ))
2016-02-26 00:20:09 +00:00
{
2018-07-12 16:35:38 +00:00
$ignoreFields = array ();
// load the field data
$view -> fields = array_map ( function ( $field ) use ( $name_single , $name_list , & $ignoreFields )
{
2018-10-01 02:16:24 +00:00
// set the field details
$this -> setFieldDetails ( $field , $name_single , $name_list );
2018-07-21 07:10:37 +00:00
// check if this field is a default field OR
2018-07-12 16:35:38 +00:00
// check if this is none database related field
2018-07-21 07:10:37 +00:00
if ( in_array ( $field [ 'base_name' ], $this -> defaultFields ) ||
2018-07-12 16:35:38 +00:00
ComponentbuilderHelper :: fieldCheck ( $field [ 'type_name' ], 'spacer' ) ||
2018-07-21 07:10:37 +00:00
( isset ( $field [ 'list' ]) && $field [ 'list' ] == 2 )) // 2 = none database
2018-07-12 16:35:38 +00:00
{
$ignoreFields [ $field [ 'field' ]] = $field [ 'field' ];
}
// return field
return $field ;
}, array_values ( $view -> addfields ));
2017-10-12 23:14:17 +00:00
// build update SQL
2017-10-29 11:03:06 +00:00
if ( $old_view = $this -> getHistoryWatch ( 'admin_fields' , $view -> addfields_id ))
2017-10-12 23:14:17 +00:00
{
// add new fields were added
if ( isset ( $old_view -> addfields ) && ComponentbuilderHelper :: checkJson ( $old_view -> addfields ))
{
2018-07-12 16:35:38 +00:00
$this -> setUpdateSQL ( json_decode ( $old_view -> addfields , true ), $view -> addfields , 'field' , $name_single , $ignoreFields );
2017-12-14 23:10:47 +00:00
}
2017-10-12 23:14:17 +00:00
// clear this data
unset ( $old_view );
2016-02-26 00:20:09 +00:00
}
2018-07-12 16:35:38 +00:00
// sort the fields acording to order
usort ( $view -> fields , function ( $a , $b )
2017-10-12 23:14:17 +00:00
{
2018-07-12 16:35:38 +00:00
if ( isset ( $a [ 'order_list' ]) && isset ( $b [ 'order_list' ]))
2017-10-12 23:14:17 +00:00
{
2018-07-12 16:35:38 +00:00
if ( $a [ 'order_list' ] != 0 && $b [ 'order_list' ] != 0 )
{
return $a [ 'order_list' ] - $b [ 'order_list' ];
}
elseif ( $b [ 'order_list' ] != 0 && $a [ 'order_list' ] == 0 )
2017-10-12 23:14:17 +00:00
{
return 1 ;
}
2018-07-12 16:35:38 +00:00
elseif ( $a [ 'order_list' ] != 0 && $b [ 'order_list' ] == 0 )
{
return 0 ;
}
return 1 ;
}
return 0 ;
});
// do some house cleaning (for fields)
foreach ( $view -> fields as $field )
{
// so first we lock the field name in
$field_name = $this -> getFieldName ( $field , $name_list );
// check if the field changed since the last compilation (default fields never change and are always added)
if ( ! isset ( $ignoreFields [ $field [ 'field' ]]) && ComponentbuilderHelper :: checkObject ( $field [ 'settings' ] -> history ))
2018-03-11 02:44:43 +00:00
{
2018-07-12 16:35:38 +00:00
// check if the datatype changed
if ( isset ( $field [ 'settings' ] -> history -> datatype ))
2018-03-11 02:44:43 +00:00
{
2018-07-12 16:35:38 +00:00
$this -> setUpdateSQL ( $field [ 'settings' ] -> history -> datatype , $field [ 'settings' ] -> datatype , 'field.datatype' , $name_single . '.' . $field_name );
}
// check if the datatype lenght changed
if ( isset ( $field [ 'settings' ] -> history -> datalenght ) && isset ( $field [ 'settings' ] -> history -> datalenght_other ))
{
$this -> setUpdateSQL ( $field [ 'settings' ] -> history -> datalenght . $field [ 'settings' ] -> history -> datalenght_other , $field [ 'settings' ] -> datalenght . $field [ 'settings' ] -> datalenght_other , 'field.lenght' , $name_single . '.' . $field_name );
}
// check if the name changed
if ( isset ( $field [ 'settings' ] -> history -> xml ) && ComponentbuilderHelper :: checkJson ( $field [ 'settings' ] -> history -> xml ))
{
// only run if this is not an alias or a tag
if (( ! isset ( $field [ 'alias' ]) || ! $field [ 'alias' ]) && 'tag' !== $field [ 'settings' ] -> type_name )
2018-03-11 02:44:43 +00:00
{
2018-07-12 16:35:38 +00:00
// build temp field bucket
$tmpfield = array ();
$tmpfield [ 'settings' ] = new stdClass ();
// convert the xml json string to normal string
$tmpfield [ 'settings' ] -> xml = $this -> setDynamicValues ( json_decode ( $field [ 'settings' ] -> history -> xml ));
// add properties from current field as it is generic
$tmpfield [ 'settings' ] -> properties = $field [ 'settings' ] -> properties ;
// add the old name
$tmpfield [ 'settings' ] -> name = $field [ 'settings' ] -> history -> name ;
// add the field type from current field since it is generic
$tmpfield [ 'settings' ] -> type_name = $field [ 'settings' ] -> type_name ;
// get the old name
$old_field_name = $this -> getFieldName ( $tmpfield );
// only run this if not a multi field
if ( ! isset ( $this -> uniqueNames [ $name_list ][ 'names' ][ $field_name ]))
2018-03-11 02:44:43 +00:00
{
2018-07-12 16:35:38 +00:00
// this only works when the field is not multiple of the same field
$this -> setUpdateSQL ( $old_field_name , $field_name , 'field.name' , $name_single . '.' . $field_name );
}
elseif ( $old_field_name !== $field_name )
{
// give a notice atleast that the multi fields could have changed and no DB update was done
2018-09-25 20:02:48 +00:00
$this -> app -> enqueueMessage ( JText :: _ ( '<hr /><h3>Field Notice</h3>' ), 'Notice' );
2018-07-12 16:35:38 +00:00
$this -> app -> enqueueMessage ( JText :: sprintf ( 'You have a field called <b>%s</b> that has been added multiple times to the <b>%s</b> view, the name of that field has changed to <b>%s</b>. Normaly we would automaticly add the update SQL to your component, but with multiple fields this does not work automaticly since it could be that noting changed and it just seems like it did. Therefore you will have to do this manualy if it actualy did change!' , $field_name , $name_single , $old_field_name ), 'Notice' );
2018-03-11 02:44:43 +00:00
}
2018-07-12 16:35:38 +00:00
// remove tmp
unset ( $tmpfield );
2018-03-11 02:44:43 +00:00
}
}
}
2017-10-12 23:14:17 +00:00
}
2017-10-29 11:03:06 +00:00
}
2017-12-14 23:10:47 +00:00
unset ( $view -> addfields );
2017-10-12 00:50:14 +00:00
// build update SQL
if ( $old_view = $this -> getHistoryWatch ( 'admin_view' , $id ))
{
// check if the view name changed
if ( ComponentbuilderHelper :: checkString ( $old_view -> name_single ))
{
$this -> setUpdateSQL ( ComponentbuilderHelper :: safeString ( $old_view -> name_single ), $name_single , 'table_name' , $name_single );
2017-12-14 23:10:47 +00:00
}
2018-09-25 20:02:48 +00:00
// loop the mysql table settings
foreach ( $this -> mysqlTableKeys as $_mysqlTableKey => $_mysqlTableVal )
{
// check if the table engine changed
if ( isset ( $old_view -> { 'mysql_table_' . $_mysqlTableKey }) && isset ( $view -> { 'mysql_table_' . $_mysqlTableKey }))
{
$this -> setUpdateSQL ( $old_view -> { 'mysql_table_' . $_mysqlTableKey }, $view -> { 'mysql_table_' . $_mysqlTableKey }, 'table_' . $_mysqlTableKey , $name_single );
}
// check if there is no history on table engine, and it changed from the default/global
elseif ( isset ( $view -> { 'mysql_table_' . $_mysqlTableKey }) && ComponentbuilderHelper :: checkString ( $view -> { 'mysql_table_' . $_mysqlTableKey }) && ! is_numeric ( $view -> { 'mysql_table_' . $_mysqlTableKey }))
{
$this -> setUpdateSQL ( $_mysqlTableVal [ 'default' ], $view -> { 'mysql_table_' . $_mysqlTableKey }, 'table_' . $_mysqlTableKey , $name_single );
}
}
2017-10-12 00:50:14 +00:00
// clear this data
unset ( $old_view );
2017-12-14 23:10:47 +00:00
}
2017-10-12 23:14:17 +00:00
// set the conditions
2017-12-14 23:10:47 +00:00
$view -> addconditions = ( isset ( $view -> addconditions ) && ComponentbuilderHelper :: checkJson ( $view -> addconditions )) ? json_decode ( $view -> addconditions , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $view -> addconditions ))
2017-10-12 00:50:14 +00:00
{
2017-10-29 11:03:06 +00:00
$view -> conditions = array ();
$ne = 0 ;
foreach ( $view -> addconditions as $nr => $conditionValue )
2017-10-12 23:14:17 +00:00
{
2017-10-29 11:03:06 +00:00
if ( ComponentbuilderHelper :: checkArray ( $conditionValue [ 'target_field' ]) && ComponentbuilderHelper :: checkArray ( $view -> fields ))
2016-02-26 00:20:09 +00:00
{
2017-10-29 11:03:06 +00:00
foreach ( $conditionValue [ 'target_field' ] as $fieldKey => $fieldId )
2016-02-26 00:20:09 +00:00
{
2017-10-29 11:03:06 +00:00
foreach ( $view -> fields as $fieldValues )
2016-02-26 00:20:09 +00:00
{
2017-10-29 11:03:06 +00:00
if (( int ) $fieldValues [ 'field' ] == ( int ) $fieldId )
2016-02-26 00:20:09 +00:00
{
2017-10-29 11:03:06 +00:00
// load the field details
2017-12-14 23:10:47 +00:00
$required = ComponentbuilderHelper :: getBetween ( $fieldValues [ 'settings' ] -> xml , 'required="' , '"' );
2020-02-04 23:18:34 +00:00
$required = ( $required === 'true' || $required === '1' ) ? 'yes' : 'no' ;
2017-12-14 23:10:47 +00:00
$filter = ComponentbuilderHelper :: getBetween ( $fieldValues [ 'settings' ] -> xml , 'filter="' , '"' );
$filter = ComponentbuilderHelper :: checkString ( $filter ) ? $filter : 'none' ;
2017-10-29 11:03:06 +00:00
// set the field name
$conditionValue [ 'target_field' ][ $fieldKey ] = array (
2018-03-11 02:44:43 +00:00
'name' => $this -> getFieldName ( $fieldValues , $name_list ),
'type' => $this -> getFieldType ( $fieldValues ),
2017-10-29 11:03:06 +00:00
'required' => $required ,
'filter' => $filter
2017-12-14 23:10:47 +00:00
);
2017-10-29 11:03:06 +00:00
break ;
2016-02-26 00:20:09 +00:00
}
}
}
2017-10-29 11:03:06 +00:00
}
2017-10-12 23:14:17 +00:00
2017-10-29 11:03:06 +00:00
// load match field
if ( ComponentbuilderHelper :: checkArray ( $view -> fields ) && isset ( $conditionValue [ 'match_field' ]))
{
foreach ( $view -> fields as $fieldValue )
2016-02-26 00:20:09 +00:00
{
2017-10-29 11:03:06 +00:00
if (( int ) $fieldValue [ 'field' ] == ( int ) $conditionValue [ 'match_field' ])
2016-02-26 00:20:09 +00:00
{
2018-03-11 02:44:43 +00:00
// set the type
$type = $this -> getFieldType ( $fieldValue );
2017-10-29 11:03:06 +00:00
// set the field details
2018-03-11 02:44:43 +00:00
$conditionValue [ 'match_name' ] = $this -> getFieldName ( $fieldValue , $name_list );
$conditionValue [ 'match_type' ] = $type ;
2017-12-14 23:10:47 +00:00
$conditionValue [ 'match_xml' ] = $fieldValue [ 'settings' ] -> xml ;
2017-10-29 11:03:06 +00:00
// if custom field load field being extended
2018-05-24 13:56:56 +00:00
if ( ! ComponentbuilderHelper :: fieldCheck ( $type ))
2017-10-12 00:50:14 +00:00
{
2017-12-14 23:10:47 +00:00
$conditionValue [ 'match_extends' ] = ComponentbuilderHelper :: getBetween ( $fieldValue [ 'settings' ] -> xml , 'extends="' , '"' );
2017-10-12 00:50:14 +00:00
}
2017-10-29 11:03:06 +00:00
else
{
$conditionValue [ 'match_extends' ] = '' ;
}
break ;
2016-02-26 00:20:09 +00:00
}
}
}
2017-10-29 11:03:06 +00:00
// set condition values
$view -> conditions [ $ne ] = $conditionValue ;
$ne ++ ;
2016-02-26 00:20:09 +00:00
}
}
2017-10-29 11:03:06 +00:00
unset ( $view -> addconditions );
2018-05-24 13:56:56 +00:00
// prep the buckets
$this -> fieldRelations [ $name_list ] = array ();
$this -> listJoinBuilder [ $name_list ] = array ();
2018-05-29 03:45:16 +00:00
$this -> listHeadOverRide [ $name_list ] = array ();
2018-05-24 13:56:56 +00:00
// set the relations
$view -> addrelations = ( isset ( $view -> addrelations ) && ComponentbuilderHelper :: checkJson ( $view -> addrelations )) ? json_decode ( $view -> addrelations , true ) : null ;
if ( ComponentbuilderHelper :: checkArray ( $view -> addrelations ))
{
foreach ( $view -> addrelations as $nr => $relationsValue )
{
// only add if list view field is selected and joind fields are set
2018-07-21 07:10:37 +00:00
if ( isset ( $relationsValue [ 'listfield' ]) && is_numeric ( $relationsValue [ 'listfield' ]) && $relationsValue [ 'listfield' ] > 0 &&
isset ( $relationsValue [ 'area' ]) && is_numeric ( $relationsValue [ 'area' ]) && $relationsValue [ 'area' ] > 0 )
2018-05-24 13:56:56 +00:00
{
2018-05-26 10:03:08 +00:00
// do a dynamic update on the set values
if ( isset ( $relationsValue [ 'set' ]) && ComponentbuilderHelper :: checkString ( $relationsValue [ 'set' ]))
{
$relationsValue [ 'set' ] = $this -> setDynamicValues ( $relationsValue [ 'set' ]);
}
2018-07-21 07:10:37 +00:00
// check that the arrays are set
if ( ! isset ( $this -> fieldRelations [ $name_list ][( int ) $relationsValue [ 'listfield' ]]) || ! ComponentbuilderHelper :: checkArray ( $this -> fieldRelations [ $name_list ][( int ) $relationsValue [ 'listfield' ]]))
{
$this -> fieldRelations [ $name_list ][( int ) $relationsValue [ 'listfield' ]] = array ();
}
2018-05-24 13:56:56 +00:00
// load the field relations
2018-07-21 07:10:37 +00:00
$this -> fieldRelations [ $name_list ][ ( int ) $relationsValue [ 'listfield' ]][ ( int ) $relationsValue [ 'area' ]] = $relationsValue ;
2018-05-24 13:56:56 +00:00
// load the list joints
2018-07-21 07:10:37 +00:00
if ( isset ( $relationsValue [ 'joinfields' ]) && ComponentbuilderHelper :: checkArray ( $relationsValue [ 'joinfields' ]))
2018-05-24 13:56:56 +00:00
{
2018-07-21 07:10:37 +00:00
foreach ( $relationsValue [ 'joinfields' ] as $join )
{
$this -> listJoinBuilder [ $name_list ][( int ) $join ] = ( int ) $join ;
}
2018-05-24 13:56:56 +00:00
}
2018-05-29 03:45:16 +00:00
// set header over-ride
if ( isset ( $relationsValue [ 'column_name' ]) && ComponentbuilderHelper :: checkString ( $relationsValue [ 'column_name' ]))
{
$check_column_name = trim ( strtolower ( $relationsValue [ 'column_name' ]));
// confirm it should really make the over ride
if ( 'default' !== $check_column_name )
{
2018-08-19 20:26:26 +00:00
$column_name_lang = $this -> langPrefix . '_' . ComponentbuilderHelper :: safeString ( $name_list , 'U' ) . '_' . ComponentbuilderHelper :: safeString ( $relationsValue [ 'column_name' ], 'U' );
2019-07-04 23:53:54 +00:00
$this -> setLangContent ( 'admin' , $column_name_lang , $relationsValue [ 'column_name' ]);
2018-05-29 03:45:16 +00:00
$this -> listHeadOverRide [ $name_list ][( int ) $relationsValue [ 'listfield' ]] = $column_name_lang ;
}
}
2018-05-24 13:56:56 +00:00
}
}
}
unset ( $view -> addrelations );
2016-02-26 00:20:09 +00:00
// set linked views
2017-10-12 00:50:14 +00:00
$this -> linkedAdminViews [ $name_single ] = null ;
2017-12-14 23:10:47 +00:00
$view -> addlinked_views = ( isset ( $view -> addlinked_views ) && ComponentbuilderHelper :: checkJson ( $view -> addlinked_views )) ? json_decode ( $view -> addlinked_views , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $view -> addlinked_views ))
2017-10-12 00:50:14 +00:00
{
// setup linked views to global data sets
$this -> linkedAdminViews [ $name_single ] = array_values ( $view -> addlinked_views );
2016-02-26 00:20:09 +00:00
}
2017-10-12 00:50:14 +00:00
unset ( $view -> addlinked_views );
2016-06-23 15:05:37 +00:00
// set the lang target
$this -> lang = 'admin' ;
2018-03-30 01:29:24 +00:00
if ( isset ( $this -> siteEditView [ $id ]))
{
$this -> lang = 'both' ;
}
2019-07-28 21:48:42 +00:00
// set GUI mapper
$guiMapper = array ( 'table' => 'admin_view' , 'id' => ( int ) $id , 'type' => 'js' );
2016-06-23 15:05:37 +00:00
// add_javascript
2017-12-14 23:10:47 +00:00
$addArrayJ = array ( 'javascript_view_file' , 'javascript_view_footer' , 'javascript_views_file' , 'javascript_views_footer' );
2019-07-28 21:48:42 +00:00
// update GUI mapper
$guiMapper [ 'prefix' ] = PHP_EOL ;
2016-06-23 15:05:37 +00:00
foreach ( $addArrayJ as $scripter )
2016-02-26 00:20:09 +00:00
{
2017-12-14 23:10:47 +00:00
if ( isset ( $view -> { 'add_' . $scripter }) && $view -> { 'add_' . $scripter } == 1 && ComponentbuilderHelper :: checkString ( $view -> $scripter ))
2016-02-26 00:20:09 +00:00
{
2016-06-23 15:05:37 +00:00
$scripter_target = str_replace ( 'javascript_' , '' , $scripter );
2019-07-28 21:48:42 +00:00
// update GUI mapper field
$guiMapper [ 'field' ] = $scripter ;
$this -> setCustomScriptBuilder (
$view -> { $scripter },
$scripter_target ,
$name_single ,
false ,
$guiMapper ,
true ,
true ,
true
);
2019-03-05 07:51:52 +00:00
// check if a token must be set
2017-12-14 23:10:47 +00:00
if ( strpos ( $view -> $scripter , " token " ) !== false || strpos ( $view -> $scripter , " task=ajax " ) !== false )
2016-02-26 00:20:09 +00:00
{
2016-06-23 15:05:37 +00:00
if ( ! $this -> customScriptBuilder [ 'token' ][ $name_single ])
{
$this -> customScriptBuilder [ 'token' ][ $name_single ] = true ;
}
2016-02-26 00:20:09 +00:00
}
2019-03-05 07:51:52 +00:00
unset ( $view -> { $scripter });
2016-02-26 00:20:09 +00:00
}
}
2019-07-28 21:48:42 +00:00
unset ( $guiMapper [ 'prefix' ]);
2016-06-23 15:05:37 +00:00
// add_css
$addArrayC = array ( 'css_view' , 'css_views' );
foreach ( $addArrayC as $scripter )
2016-02-26 00:20:09 +00:00
{
2019-03-05 07:51:52 +00:00
if ( isset ( $view -> { 'add_' . $scripter }) && $view -> { 'add_' . $scripter } == 1 && ComponentbuilderHelper :: checkString ( $view -> { $scripter }))
2016-02-26 00:20:09 +00:00
{
2019-07-28 21:48:42 +00:00
$this -> setCustomScriptBuilder (
$view -> { $scripter },
$scripter ,
$name_single ,
false ,
array ( 'prefix' => PHP_EOL ),
true ,
true ,
true
);
2019-03-05 07:51:52 +00:00
unset ( $view -> { $scripter });
2016-02-26 00:20:09 +00:00
}
}
2019-07-28 21:48:42 +00:00
// update GUI mapper
$guiMapper [ 'type' ] = 'php' ;
2016-06-23 15:05:37 +00:00
// add_php
2019-06-12 20:36:05 +00:00
$addArrayP = array ( 'php_getitem' , 'php_before_save' , 'php_save' , 'php_getform' , 'php_postsavehook' , 'php_getitems' , 'php_getitems_after_all' , 'php_getlistquery' , 'php_allowadd' , 'php_allowedit' , 'php_before_cancel' , 'php_after_cancel' , 'php_before_delete' , 'php_after_delete' , 'php_before_publish' , 'php_after_publish' , 'php_batchcopy' , 'php_batchmove' , 'php_document' );
2016-06-23 15:05:37 +00:00
foreach ( $addArrayP as $scripter )
2016-02-26 00:20:09 +00:00
{
2017-12-14 23:10:47 +00:00
if ( isset ( $view -> { 'add_' . $scripter }) && $view -> { 'add_' . $scripter } == 1 )
2016-02-26 00:20:09 +00:00
{
2019-07-28 21:48:42 +00:00
// update GUI mapper field
$guiMapper [ 'field' ] = $scripter ;
$this -> setCustomScriptBuilder (
$view -> { $scripter },
$scripter ,
$name_single ,
false ,
$guiMapper
);
unset ( $view -> { $scripter });
2016-02-26 00:20:09 +00:00
}
}
2017-12-14 23:10:47 +00:00
// add the custom buttons
if ( isset ( $view -> add_custom_button ) && $view -> add_custom_button == 1 )
{
2019-07-28 21:48:42 +00:00
$button_code_array = array (
'php_model' ,
'php_controller' ,
'php_model_list' ,
'php_controller_list'
);
// set for the code
foreach ( $button_code_array as $button_code_field )
2017-12-14 23:10:47 +00:00
{
2019-07-28 21:48:42 +00:00
if ( isset ( $view -> { $button_code_field }) && ComponentbuilderHelper :: checkString ( $view -> { $button_code_field }))
{
// set field
$guiMapper [ 'field' ] = $button_code_field ;
$view -> { $button_code_field } = $this -> setGuiCodePlaceholder (
$this -> setDynamicValues ( base64_decode ( $view -> { $button_code_field })),
$guiMapper
);
}
2017-03-02 00:55:04 +00:00
}
2017-12-14 23:10:47 +00:00
// set the button array
$view -> custom_button = ( isset ( $view -> custom_button ) && ComponentbuilderHelper :: checkJson ( $view -> custom_button )) ? json_decode ( $view -> custom_button , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $view -> custom_button ))
2017-12-14 23:10:47 +00:00
{
$view -> custom_buttons = array_values ( $view -> custom_button );
}
unset ( $view -> custom_button );
}
2016-05-04 04:53:33 +00:00
// set custom import scripts
if ( isset ( $view -> add_custom_import ) && $view -> add_custom_import == 1 )
{
2018-01-17 23:14:43 +00:00
$addImportArray = array ( 'php_import_ext' , 'php_import_display' , 'php_import' , 'php_import_setdata' , 'php_import_save' , 'php_import_headers' , 'html_import_view' );
2016-05-04 04:53:33 +00:00
foreach ( $addImportArray as $importScripter )
{
if ( isset ( $view -> $importScripter ) && strlen ( $view -> $importScripter ) > 0 )
{
2019-07-28 21:48:42 +00:00
// update GUI mapper field
$guiMapper [ 'field' ] = $importScripter ;
$this -> setCustomScriptBuilder (
$view -> $importScripter ,
$importScripter ,
'import_' . $name_list ,
false ,
$guiMapper
);
2016-05-04 04:53:33 +00:00
unset ( $view -> $importScripter );
}
2017-03-27 12:38:51 +00:00
else
{
// load the default
2018-01-23 22:05:57 +00:00
$this -> customScriptBuilder [ $importScripter ][ 'import_' . $name_list ] = ComponentbuilderHelper :: getDynamicScripts ( $importScripter , true );
2017-03-27 12:38:51 +00:00
}
2016-05-04 04:53:33 +00:00
}
}
2017-12-14 23:10:47 +00:00
2016-02-26 00:20:09 +00:00
// add_Ajax for this view
2016-05-10 05:47:47 +00:00
if ( isset ( $view -> add_php_ajax ) && $view -> add_php_ajax == 1 )
2016-02-26 00:20:09 +00:00
{
2017-02-13 23:24:38 +00:00
// insure the token is added to edit view atleast
$this -> customScriptBuilder [ 'token' ][ $name_single ] = true ;
2016-02-26 00:20:09 +00:00
$addAjaxSite = false ;
if ( isset ( $this -> siteEditView [ $id ]) && $this -> siteEditView [ $id ])
{
2017-02-13 23:24:38 +00:00
// we should add this site ajax to front ajax
2016-02-26 00:20:09 +00:00
$addAjaxSite = true ;
if ( ! isset ( $this -> addSiteAjax ) || ! $this -> addSiteAjax )
{
$this -> addSiteAjax = true ;
}
}
// check if controller input as been set
2017-12-14 23:10:47 +00:00
$view -> ajax_input = ( isset ( $view -> ajax_input ) && ComponentbuilderHelper :: checkJson ( $view -> ajax_input )) ? json_decode ( $view -> ajax_input , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $view -> ajax_input ))
2017-10-12 00:50:14 +00:00
{
if ( $addAjaxSite )
{
$this -> customScriptBuilder [ 'site' ][ 'ajax_controller' ][ $name_single ] = array_values ( $view -> ajax_input );
}
$this -> customScriptBuilder [ 'admin' ][ 'ajax_controller' ][ $name_single ] = array_values ( $view -> ajax_input );
2016-05-10 05:47:47 +00:00
$this -> addAjax = true ;
unset ( $view -> ajax_input );
}
if ( ComponentbuilderHelper :: checkString ( $view -> php_ajaxmethod ))
{
2019-07-28 21:48:42 +00:00
// update GUI mapper field
$guiMapper [ 'field' ] = 'php_ajaxmethod' ;
$this -> setCustomScriptBuilder (
$view -> php_ajaxmethod ,
'admin' ,
'ajax_model' ,
$name_single ,
$guiMapper
);
2016-02-26 00:20:09 +00:00
if ( $addAjaxSite )
{
2019-07-28 21:48:42 +00:00
$this -> setCustomScriptBuilder (
$view -> php_ajaxmethod ,
'site' ,
'ajax_model' ,
$name_single ,
$guiMapper ,
false ,
false
);
2016-02-26 00:20:09 +00:00
}
2016-05-10 05:47:47 +00:00
// unset anyway
unset ( $view -> php_ajaxmethod );
2016-02-26 00:20:09 +00:00
$this -> addAjax = true ;
}
}
2018-03-28 09:46:14 +00:00
// activate alias builder
2018-05-11 04:08:14 +00:00
if ( ! isset ( $this -> customAliasBuilder [ $name_single ]) && isset ( $view -> alias_builder_type ) && 2 == $view -> alias_builder_type && isset ( $view -> alias_builder ) && ComponentbuilderHelper :: checkJson ( $view -> alias_builder ))
2018-03-28 09:46:14 +00:00
{
// get the aliasFields
$alias_fields = ( array ) json_decode ( $view -> alias_builder , true );
// get the active fields
2018-05-11 04:08:14 +00:00
$alias_fields = ( array ) array_filter ( $view -> fields , function ( $field ) use ( $alias_fields )
2018-03-28 09:46:14 +00:00
{
2018-05-11 04:08:14 +00:00
// check if field is in view fields
if ( in_array ( $field [ 'field' ], $alias_fields ))
{
return true ;
}
return false ;
});
2018-03-28 09:46:14 +00:00
// check if all is well
if ( ComponentbuilderHelper :: checkArray ( $alias_fields ))
{
// load the field names
2018-05-11 04:08:14 +00:00
$this -> customAliasBuilder [ $name_single ] = ( array ) array_map ( function ( $field ) use ( $name_list )
{
2018-03-28 09:46:14 +00:00
return $this -> getFieldName ( $field , $name_list );
2018-05-11 04:08:14 +00:00
}, $alias_fields
2018-03-28 09:46:14 +00:00
);
}
}
// unset
unset ( $view -> alias_builder );
2016-02-26 00:20:09 +00:00
// add_sql
if ( $view -> add_sql == 1 )
{
2017-08-22 22:17:19 +00:00
if ( $view -> source == 1 && isset ( $view -> tables ))
2016-02-26 00:20:09 +00:00
{
// build and add the SQL dump
2017-10-12 00:50:14 +00:00
$this -> customScriptBuilder [ 'sql' ][ $name_single ] = $this -> buildSqlDump ( $view -> tables , $name_single , $id );
2016-02-26 00:20:09 +00:00
unset ( $view -> tables );
}
2017-08-22 22:17:19 +00:00
elseif ( $view -> source == 2 && isset ( $view -> sql ))
2016-02-26 00:20:09 +00:00
{
// add the SQL dump string
2019-07-28 21:48:42 +00:00
$this -> setCustomScriptBuilder (
$view -> sql ,
'sql' ,
$name_single
);
2016-02-26 00:20:09 +00:00
unset ( $view -> sql );
}
}
2018-09-25 20:02:48 +00:00
// load table settings
if ( ! isset ( $this -> mysqlTableSetting [ $name_single ]))
{
$this -> mysqlTableSetting [ $name_single ] = array ();
}
// set mySql Table Settings
foreach ( $this -> mysqlTableKeys as $_mysqlTableKey => $_mysqlTableVal )
{
if ( isset ( $view -> { 'mysql_table_' . $_mysqlTableKey }) && ComponentbuilderHelper :: checkString ( $view -> { 'mysql_table_' . $_mysqlTableKey }) && ! is_numeric ( $view -> { 'mysql_table_' . $_mysqlTableKey }))
{
$this -> mysqlTableSetting [ $name_single ][ $_mysqlTableKey ] = $view -> { 'mysql_table_' . $_mysqlTableKey };
}
else
{
$this -> mysqlTableSetting [ $name_single ][ $_mysqlTableKey ] = $_mysqlTableVal [ 'default' ];
}
// remove the table values since we moved to another object
unset ( $view -> { 'mysql_table_' . $_mysqlTableKey });
}
2019-06-22 10:43:26 +00:00
// Trigger Event: jcb_ce_onAfterModelViewData
2019-07-01 16:10:28 +00:00
$this -> triggerEvent ( 'jcb_ce_onAfterModelViewData' , array ( & $this -> componentContext , & $view , & $this -> placeholders ));
2019-06-22 10:43:26 +00:00
2017-10-06 14:53:22 +00:00
// clear placeholders
2018-05-22 19:01:36 +00:00
unset ( $this -> placeholders [ $this -> hhh . 'view' . $this -> hhh ]);
unset ( $this -> placeholders [ $this -> hhh . 'views' . $this -> hhh ]);
unset ( $this -> placeholders [ $this -> hhh . 'View' . $this -> hhh ]);
unset ( $this -> placeholders [ $this -> hhh . 'Views' . $this -> hhh ]);
unset ( $this -> placeholders [ $this -> hhh . 'VIEW' . $this -> hhh ]);
unset ( $this -> placeholders [ $this -> hhh . 'VIEWS' . $this -> hhh ]);
unset ( $this -> placeholders [ $this -> bbb . 'view' . $this -> ddd ]);
unset ( $this -> placeholders [ $this -> bbb . 'views' . $this -> ddd ]);
unset ( $this -> placeholders [ $this -> bbb . 'View' . $this -> ddd ]);
unset ( $this -> placeholders [ $this -> bbb . 'Views' . $this -> ddd ]);
unset ( $this -> placeholders [ $this -> bbb . 'VIEW' . $this -> ddd ]);
unset ( $this -> placeholders [ $this -> bbb . 'VIEWS' . $this -> ddd ]);
2018-01-15 15:54:05 +00:00
2017-06-16 12:38:06 +00:00
// store this view to class object
2016-02-26 00:20:09 +00:00
$this -> _adminViewData [ $id ] = $view ;
}
// return the found view data
return $this -> _adminViewData [ $id ];
}
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* Get all Custom View Data
*
2016-03-01 18:44:13 +00:00
* @ param int $id The view ID
2016-02-26 00:20:09 +00:00
* @ param string $table The view table
2017-10-20 16:17:46 +00:00
*
2016-02-26 00:20:09 +00:00
* @ return oject The view data
*
*/
public function getCustomViewData ( $id , $table = 'site_view' )
{
// Create a new query object.
2017-02-13 23:24:38 +00:00
$query = $this -> db -> getQuery ( true );
2016-02-26 00:20:09 +00:00
$query -> select ( 'a.*' );
2017-12-14 23:10:47 +00:00
$query -> from ( '#__componentbuilder_' . $table . ' AS a' );
$query -> where ( $this -> db -> quoteName ( 'a.id' ) . ' = ' . ( int ) $id );
2016-02-26 00:20:09 +00:00
2019-06-22 10:43:26 +00:00
// Trigger Event: jcb_ce_onBeforeQueryCustomViewData
2019-07-01 16:10:28 +00:00
$this -> triggerEvent ( 'jcb_ce_onBeforeQueryCustomViewData' , array ( & $this -> componentContext , & $id , & $table , & $query , & $this -> db ));
2019-06-22 10:43:26 +00:00
2016-02-26 00:20:09 +00:00
// Reset the query using our newly populated query object.
2017-02-13 23:24:38 +00:00
$this -> db -> setQuery ( $query );
2016-02-26 00:20:09 +00:00
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
2017-02-13 23:24:38 +00:00
$view = $this -> db -> loadObject ();
2019-06-22 10:43:26 +00:00
// Trigger Event: jcb_ce_onBeforeModelCustomViewData
2019-07-01 16:10:28 +00:00
$this -> triggerEvent ( 'jcb_ce_onBeforeModelCustomViewData' , array ( & $this -> componentContext , & $view , & $id , & $table ));
2019-06-22 10:43:26 +00:00
2017-02-01 13:17:04 +00:00
if ( $table === 'site_view' )
2016-02-26 00:20:09 +00:00
{
$this -> lang = 'site' ;
2017-10-29 11:03:06 +00:00
// repeatable fields to update
$searchRepeatables = array (
// repeatablefield => checker
'ajax_input' => 'value_name' ,
'custom_button' => 'name'
);
2016-02-26 00:20:09 +00:00
}
else
{
$this -> lang = 'admin' ;
2017-10-29 11:03:06 +00:00
// repeatable fields to update
$searchRepeatables = array (
// repeatablefield => checker
'custom_button' => 'name'
);
2016-02-26 00:20:09 +00:00
}
2017-10-29 11:03:06 +00:00
// set upater
$updater = array (
'table' => $table ,
'key' => 'id' ,
'val' => ( int ) $id
2017-12-14 23:10:47 +00:00
);
2017-10-29 11:03:06 +00:00
// update the repeatable fields
$view = ComponentbuilderHelper :: convertRepeatableFields ( $view , $searchRepeatables , $updater );
2017-12-14 23:10:47 +00:00
2019-07-28 21:48:42 +00:00
// set GUI mapper
$guiMapper = array ( 'table' => $table , 'id' => ( int ) $id , 'field' => 'default' , 'type' => 'html' );
2016-02-26 00:20:09 +00:00
// set the default data
2019-07-28 21:48:42 +00:00
$view -> default = $this -> setGuiCodePlaceholder (
$this -> setDynamicValues ( base64_decode ( $view -> default )),
$guiMapper
);
2016-02-26 00:20:09 +00:00
// fix alias to use in code
2017-02-04 00:22:17 +00:00
$view -> code = $this -> uniqueCode ( ComponentbuilderHelper :: safeString ( $view -> codename ));
2016-02-26 00:20:09 +00:00
$view -> Code = ComponentbuilderHelper :: safeString ( $view -> code , 'F' );
2017-12-14 23:10:47 +00:00
$view -> CODE = ComponentbuilderHelper :: safeString ( $view -> code , 'U' );
2018-08-23 21:51:09 +00:00
// load context if not set
if ( ! isset ( $view -> context ) || ! ComponentbuilderHelper :: checkString ( $view -> context ))
{
$view -> context = $view -> code ;
}
else
{
// always make sure context is a safe string
$view -> context = ComponentbuilderHelper :: safeString ( $view -> context );
}
2017-12-10 19:17:26 +00:00
// load the library
if ( ! isset ( $this -> libManager [ $this -> target ]))
{
$this -> libManager [ $this -> target ] = array ();
}
if ( ! isset ( $this -> libManager [ $this -> target ][ $view -> code ]))
{
$this -> libManager [ $this -> target ][ $view -> code ] = array ();
}
// make sure json become array
if ( ComponentbuilderHelper :: checkJson ( $view -> libraries ))
{
$view -> libraries = json_decode ( $view -> libraries , true );
}
// if we have an array add it
if ( ComponentbuilderHelper :: checkArray ( $view -> libraries ))
{
foreach ( $view -> libraries as $library )
{
if ( ! isset ( $this -> libManager [ $this -> target ][ $view -> code ][ $library ]))
{
2019-10-16 20:34:36 +00:00
if ( $this -> getMediaLibrary (( int ) $library ))
2017-12-10 19:17:26 +00:00
{
$this -> libManager [ $this -> target ][ $view -> code ][( int ) $library ] = true ;
}
}
}
}
elseif ( is_numeric ( $view -> libraries ) && ! isset ( $this -> libManager [ $this -> target ][ $view -> code ][( int ) $view -> libraries ]))
{
2019-10-16 20:34:36 +00:00
if ( $this -> getMediaLibrary (( int ) $view -> libraries ))
2017-12-10 19:17:26 +00:00
{
$this -> libManager [ $this -> target ][ $view -> code ][( int ) $view -> libraries ] = true ;
}
}
// setup template array
$this -> templateData [ $this -> target ][ $view -> code ] = array ();
// setup template and layout data
2017-12-14 23:10:47 +00:00
$this -> setTemplateAndLayoutData ( $view -> default , $view -> code );
2016-02-26 00:20:09 +00:00
// insure the uikit components are loaded
2017-11-11 04:33:51 +00:00
if ( 2 == $this -> uikit || 1 == $this -> uikit )
2016-02-26 00:20:09 +00:00
{
2017-11-11 04:33:51 +00:00
if ( ! isset ( $this -> uikitComp [ $view -> code ]))
{
$this -> uikitComp [ $view -> code ] = array ();
}
2017-12-14 23:10:47 +00:00
$this -> uikitComp [ $view -> code ] = ComponentbuilderHelper :: getUikitComp ( $view -> default , $this -> uikitComp [ $view -> code ]);
2016-02-26 00:20:09 +00:00
}
// check for footable
if ( ! isset ( $this -> footableScripts [ $this -> target ][ $view -> code ]) || ! $this -> footableScripts [ $this -> target ][ $view -> code ])
{
$foundFoo = $this -> getFootableScripts ( $view -> default );
if ( $foundFoo )
{
$this -> footableScripts [ $this -> target ][ $view -> code ] = true ;
}
if ( $foundFoo && ! $this -> footableScripts )
{
$this -> footable = true ;
}
}
// check for get module
if ( ! isset ( $this -> getModule [ $this -> target ][ $view -> code ]) || ! $this -> getModule [ $this -> target ][ $view -> code ])
{
$found = $this -> getGetModule ( $view -> default );
if ( $found )
{
$this -> getModule [ $this -> target ][ $view -> code ] = true ;
}
}
// set the main get data
2018-08-23 21:51:09 +00:00
$main_get = $this -> setGetData ( array ( $view -> main_get ), $view -> code , $view -> context );
2016-02-26 00:20:09 +00:00
$view -> main_get = $main_get [ 0 ];
// set the custom_get data
2018-08-23 21:51:09 +00:00
$view -> custom_get = $this -> setGetData ( json_decode ( $view -> custom_get , true ), $view -> code , $view -> context );
2016-02-26 00:20:09 +00:00
// set array adding array of scripts
2017-12-14 23:10:47 +00:00
$addArray = array ( 'php_view' , 'php_jview' , 'php_jview_display' , 'php_document' , 'javascript_file' , 'js_document' , 'css_document' , 'css' );
2019-07-28 21:48:42 +00:00
// set GUI mapper
$guiMapper [ 'type' ] = 'php' ;
2016-02-26 00:20:09 +00:00
foreach ( $addArray as $scripter )
{
2017-12-14 23:10:47 +00:00
if ( isset ( $view -> { 'add_' . $scripter }) && $view -> { 'add_' . $scripter } == 1 && ComponentbuilderHelper :: checkString ( $view -> $scripter ))
2016-02-26 00:20:09 +00:00
{
2019-07-28 21:48:42 +00:00
// css does not get placholders yet
if ( strpos ( $scripter , 'css' ) === false )
{
// set field
$guiMapper [ 'field' ] = $scripter ;
$view -> $scripter = $this -> setGuiCodePlaceholder (
$this -> setDynamicValues ( base64_decode ( $view -> $scripter )),
$guiMapper
);
}
else
{
$view -> $scripter = $this -> setDynamicValues ( base64_decode ( $view -> $scripter ));
}
2017-11-11 04:33:51 +00:00
if ( 2 == $this -> uikit || 1 == $this -> uikit )
{
2017-12-12 22:17:02 +00:00
if ( ! isset ( $this -> uikitComp [ $view -> code ]))
{
$this -> uikitComp [ $view -> code ] = array ();
}
2017-11-11 04:33:51 +00:00
// set uikit to views
2017-12-14 23:10:47 +00:00
$this -> uikitComp [ $view -> code ] = ComponentbuilderHelper :: getUikitComp ( $view -> $scripter , $this -> uikitComp [ $view -> code ]);
2017-11-11 04:33:51 +00:00
}
2017-12-14 23:10:47 +00:00
$this -> setTemplateAndLayoutData ( $view -> $scripter , $view -> code );
2016-02-26 00:20:09 +00:00
// check for footable
if ( ! isset ( $this -> footableScripts [ $this -> target ][ $view -> code ]) || ! $this -> footableScripts [ $this -> target ][ $view -> code ])
{
$foundFoo = $this -> getFootableScripts ( $view -> $scripter );
if ( $foundFoo )
{
$this -> footableScripts [ $this -> target ][ $view -> code ] = true ;
}
if ( $foundFoo && ! $this -> footable )
{
$this -> footable = true ;
}
}
// check for google chart
if ( ! isset ( $this -> googleChart [ $this -> target ][ $view -> code ]) || ! $this -> googleChart [ $this -> target ][ $view -> code ])
{
$found = $this -> getGoogleChart ( $view -> $scripter );
if ( $found )
{
$this -> googleChart [ $this -> target ][ $view -> code ] = true ;
}
if ( $found && ! $this -> googlechart )
{
$this -> googlechart = true ;
}
}
// check for get module
if ( ! isset ( $this -> getModule [ $this -> target ][ $view -> code ]) || ! $this -> getModule [ $this -> target ][ $view -> code ])
{
$found = $this -> getGetModule ( $view -> $scripter );
if ( $found )
{
$this -> getModule [ $this -> target ][ $view -> code ] = true ;
}
}
}
}
// add_Ajax for this view
if ( isset ( $view -> add_php_ajax ) && $view -> add_php_ajax == 1 )
{
2018-01-15 15:54:05 +00:00
// ajax target (since we only have two options really)
if ( 'site' === $this -> target )
{
$target = 'site' ;
}
else
{
$target = 'admin' ;
}
$setAjax = false ;
2016-02-26 00:20:09 +00:00
// check if controller input as been set
2017-12-14 23:10:47 +00:00
$view -> ajax_input = ( isset ( $view -> ajax_input ) && ComponentbuilderHelper :: checkJson ( $view -> ajax_input )) ? json_decode ( $view -> ajax_input , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $view -> ajax_input ))
2017-10-12 00:50:14 +00:00
{
2018-01-15 15:54:05 +00:00
$this -> customScriptBuilder [ $target ][ 'ajax_controller' ][ $view -> code ] = array_values ( $view -> ajax_input );
$setAjax = true ;
2016-02-26 00:20:09 +00:00
}
2017-10-29 11:03:06 +00:00
unset ( $view -> ajax_input );
// load the ajax class mathods (if set)
2016-05-10 05:47:47 +00:00
if ( ComponentbuilderHelper :: checkString ( $view -> php_ajaxmethod ))
{
2019-07-28 21:48:42 +00:00
// set field
$guiMapper [ 'field' ] = 'php_ajaxmethod' ;
$this -> setCustomScriptBuilder (
$view -> php_ajaxmethod ,
$target ,
'ajax_model' ,
$view -> code ,
$guiMapper
);
2018-01-15 15:54:05 +00:00
$setAjax = true ;
2016-05-10 05:47:47 +00:00
}
2016-02-26 00:20:09 +00:00
// unset anyway
unset ( $view -> php_ajaxmethod );
2018-01-15 15:54:05 +00:00
// should ajax be set
if ( $setAjax )
{
// turn on ajax area
if ( 'site' === $this -> target )
{
$this -> addSiteAjax = true ;
}
else
{
$this -> addAjax = true ;
}
}
2016-02-26 00:20:09 +00:00
}
// add the custom buttons
if ( isset ( $view -> add_custom_button ) && $view -> add_custom_button == 1 )
{
2019-07-28 21:48:42 +00:00
$button_code_array = array (
'php_model' ,
'php_controller'
);
// set for the code
foreach ( $button_code_array as $button_code_field )
2016-02-26 00:20:09 +00:00
{
2019-07-28 21:48:42 +00:00
if ( isset ( $view -> { $button_code_field }) && ComponentbuilderHelper :: checkString ( $view -> { $button_code_field }))
{
// set field
$guiMapper [ 'field' ] = $button_code_field ;
$view -> { $button_code_field } = $this -> setGuiCodePlaceholder (
$this -> setDynamicValues ( base64_decode ( $view -> { $button_code_field })),
$guiMapper
);
}
2016-02-26 00:20:09 +00:00
}
// set the button array
2017-12-14 23:10:47 +00:00
$view -> custom_button = ( isset ( $view -> custom_button ) && ComponentbuilderHelper :: checkJson ( $view -> custom_button )) ? json_decode ( $view -> custom_button , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $view -> custom_button ))
2017-10-12 00:50:14 +00:00
{
$view -> custom_buttons = array_values ( $view -> custom_button );
2016-02-26 00:20:09 +00:00
}
2017-10-12 00:50:14 +00:00
unset ( $view -> custom_button );
}
2019-06-22 10:43:26 +00:00
// Trigger Event: jcb_ce_onAfterModelCustomViewData
2019-07-01 16:10:28 +00:00
$this -> triggerEvent ( 'jcb_ce_onAfterModelCustomViewData' , array ( & $this -> componentContext , & $view ));
2019-06-22 10:43:26 +00:00
2016-02-26 00:20:09 +00:00
// return the found view data
return $view ;
}
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* Get all Field Data
*
2016-03-01 18:44:13 +00:00
* @ param int $id The field ID
2016-02-26 00:20:09 +00:00
* @ param string $name_single The view edit or single name
* @ param string $name_list The view list name
*
* @ return oject The field data
*
*/
2017-10-12 00:50:14 +00:00
public function getFieldData ( $id , $name_single = null , $name_list = null )
2016-02-26 00:20:09 +00:00
{
2017-10-29 11:03:06 +00:00
if ( $id > 0 && ! isset ( $this -> _fieldData [ $id ]))
2016-02-26 00:20:09 +00:00
{
// Create a new query object.
2017-02-13 23:24:38 +00:00
$query = $this -> db -> getQuery ( true );
2016-02-26 00:20:09 +00:00
2018-04-27 13:45:50 +00:00
// Select all the values in the field
2016-02-26 00:20:09 +00:00
$query -> select ( 'a.*' );
2017-10-12 00:50:14 +00:00
$query -> select ( $this -> db -> quoteName ( array ( 'c.name' , 'c.properties' ), array ( 'type_name' , 'properties' )));
2016-02-26 00:20:09 +00:00
$query -> from ( '#__componentbuilder_field AS a' );
2017-02-13 23:24:38 +00:00
$query -> join ( 'LEFT' , $this -> db -> quoteName ( '#__componentbuilder_fieldtype' , 'c' ) . ' ON (' . $this -> db -> quoteName ( 'a.fieldtype' ) . ' = ' . $this -> db -> quoteName ( 'c.id' ) . ')' );
2017-12-14 23:10:47 +00:00
$query -> where ( $this -> db -> quoteName ( 'a.id' ) . ' = ' . $this -> db -> quote ( $id ));
2016-02-26 00:20:09 +00:00
2019-06-22 10:43:26 +00:00
// Trigger Event: jcb_ce_onBeforeQueryFieldData
2019-07-01 16:10:28 +00:00
$this -> triggerEvent ( 'jcb_ce_onBeforeQueryFieldData' , array ( & $this -> componentContext , & $id , & $query , & $this -> db ));
2019-06-22 10:43:26 +00:00
2016-02-26 00:20:09 +00:00
// Reset the query using our newly populated query object.
2017-02-13 23:24:38 +00:00
$this -> db -> setQuery ( $query );
$this -> db -> execute ();
if ( $this -> db -> getNumRows ())
2016-06-23 15:05:37 +00:00
{
// Load the results as a list of stdClass objects (see later for more options on retrieving data).
2017-02-13 23:24:38 +00:00
$field = $this -> db -> loadObject ();
2016-02-26 00:20:09 +00:00
2019-06-22 10:43:26 +00:00
// Trigger Event: jcb_ce_onBeforeModelFieldData
2019-07-01 16:10:28 +00:00
$this -> triggerEvent ( 'jcb_ce_onBeforeModelFieldData' , array ( & $this -> componentContext , & $field ));
2019-06-22 10:43:26 +00:00
2016-06-23 15:05:37 +00:00
// adding a fix for the changed name of type to fieldtype
$field -> type = $field -> fieldtype ;
2017-12-14 23:10:47 +00:00
2017-10-29 11:03:06 +00:00
// repeatable fields to update
$searchRepeatables = array (
// repeatablefield => checker
'properties' => 'name'
);
// set upater
$updater = array (
'table' => 'fieldtype' ,
'key' => 'id' ,
'val' => ( int ) $id
);
// update the repeatable fields
$field = ComponentbuilderHelper :: convertRepeatableFields ( $field , $searchRepeatables , $updater );
2016-02-26 00:20:09 +00:00
2016-06-23 15:05:37 +00:00
// load the values form params
2017-02-17 18:35:18 +00:00
$field -> xml = $this -> setDynamicValues ( json_decode ( $field -> xml ));
2018-03-28 09:46:14 +00:00
2018-03-27 09:57:16 +00:00
// check if we have validate (validation rule set)
$validationRule = ComponentbuilderHelper :: getBetween ( $field -> xml , 'validate="' , '"' );
if ( ComponentbuilderHelper :: checkString ( $validationRule ))
{
// make sure it is lowercase
$validationRule = ComponentbuilderHelper :: safeString ( $validationRule );
2019-08-22 01:54:47 +00:00
// link this field to this validation
$this -> validationLinkedFields [ $id ] = $validationRule ;
2018-03-27 09:57:16 +00:00
// make sure it is not already set
if ( ! isset ( $this -> validationRules [ $validationRule ]))
{
// get joomla core validation names
if ( $coreValidationRules = ComponentbuilderHelper :: getExistingValidationRuleNames ( true ))
{
// make sure this rule is not a core validation rule
2018-03-28 09:46:14 +00:00
if ( ! in_array ( $validationRule , ( array ) $coreValidationRules ))
2018-03-27 09:57:16 +00:00
{
// get the class methods for this rule if it exists
2018-05-11 04:08:14 +00:00
if ( $this -> validationRules [ $validationRule ] = ComponentbuilderHelper :: getVar ( 'validation_rule' , $validationRule , 'name' , 'php' ))
2018-03-27 09:57:16 +00:00
{
// open and set the validation rule
2019-07-28 21:48:42 +00:00
$this -> validationRules [ $validationRule ] = $this -> setGuiCodePlaceholder (
$this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $this -> validationRules [ $validationRule ])), $this -> placeholders ),
array (
'table' => 'validation_rule' ,
'field' => 'php' ,
'id' => ComponentbuilderHelper :: getVar ( 'validation_rule' , $validationRule , 'name' , 'id' ),
'type' => 'php' )
);
2018-03-27 09:57:16 +00:00
}
else
{
2018-03-28 09:46:14 +00:00
// set the notice that this validation rule is custom and was not found (TODO)
2019-08-22 01:54:47 +00:00
unset ( $this -> validationLinkedFields [ $id ], $this -> validationRules [ $validationRule ]);
2018-03-27 09:57:16 +00:00
}
}
2019-08-22 01:54:47 +00:00
else
{
// remove link (we only want custom validations linked)
unset ( $this -> validationLinkedFields [ $id ]);
}
2018-03-27 09:57:16 +00:00
}
}
}
2016-02-26 00:20:09 +00:00
2016-06-23 15:05:37 +00:00
// load the type values form type params
2017-12-14 23:10:47 +00:00
$field -> properties = ( isset ( $field -> properties ) && ComponentbuilderHelper :: checkJson ( $field -> properties )) ? json_decode ( $field -> properties , true ) : null ;
2017-10-29 13:51:43 +00:00
if ( ComponentbuilderHelper :: checkArray ( $field -> properties ))
2017-10-12 00:50:14 +00:00
{
2017-10-29 11:03:06 +00:00
$field -> properties = array_values ( $field -> properties );
2017-10-12 00:50:14 +00:00
}
2018-03-06 02:28:44 +00:00
// check if we have WHMCS encryption
if ( 4 == $field -> store && ( ! isset ( $this -> whmcsEncryption ) || ! $this -> whmcsEncryption ))
2016-06-23 15:05:37 +00:00
{
2018-03-06 02:28:44 +00:00
$this -> whmcsEncryption = true ;
2016-06-23 15:05:37 +00:00
}
// check if we have basic encryption
2017-12-14 23:10:47 +00:00
elseif ( 3 == $field -> store && ( ! isset ( $this -> basicEncryption ) || ! $this -> basicEncryption ))
2016-06-23 15:05:37 +00:00
{
2017-12-14 23:10:47 +00:00
$this -> basicEncryption = true ;
2016-06-23 15:05:37 +00:00
}
2018-03-06 02:28:44 +00:00
// check if we have better encryption
elseif ( 5 == $field -> store && ( ! isset ( $this -> mediumEncryption ) || ! $this -> mediumEncryption ))
{
$this -> mediumEncryption = true ;
}
2019-10-16 20:34:36 +00:00
// check if we have better encryption
elseif ( 6 == $field -> store
&& ComponentbuilderHelper :: checkString ( $field -> on_get_model_field )
&& ComponentbuilderHelper :: checkString ( $field -> on_save_model_field ))
{
// add only if string lenght found
if ( ComponentbuilderHelper :: checkString ( $field -> initiator_on_save_model ))
{
$field -> initiator_save_key = md5 ( $field -> initiator_on_save_model );
$field -> initiator_save = explode ( PHP_EOL , $this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $field -> initiator_on_save_model )), $this -> placeholders ));
}
if ( ComponentbuilderHelper :: checkString ( $field -> initiator_on_save_model ))
{
$field -> initiator_get_key = md5 ( $field -> initiator_on_get_model );
$field -> initiator_get = explode ( PHP_EOL , $this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $field -> initiator_on_get_model )), $this -> placeholders ));
}
// set the field modeling
$field -> model_field [ 'save' ] = explode ( PHP_EOL , $this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $field -> on_save_model_field )), $this -> placeholders ));
$field -> model_field [ 'get' ] = explode ( PHP_EOL , $this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $field -> on_get_model_field )), $this -> placeholders ));
// remove the original values
unset ( $field -> on_save_model_field , $field -> on_get_model_field , $field -> initiator_on_save_model , $field -> initiator_on_get_model );
}
2017-12-14 23:10:47 +00:00
2017-06-16 12:38:06 +00:00
// get the last used version
$field -> history = $this -> getHistoryWatch ( 'field' , $id );
2017-12-14 23:10:47 +00:00
2019-06-22 10:43:26 +00:00
// Trigger Event: jcb_ce_onAfterModelFieldData
2019-07-01 16:10:28 +00:00
$this -> triggerEvent ( 'jcb_ce_onAfterModelFieldData' , array ( & $this -> componentContext , & $field ));
2019-06-22 10:43:26 +00:00
2017-02-01 13:17:04 +00:00
$this -> _fieldData [ $id ] = $field ;
}
else
{
return false ;
}
}
// check if the script should be added to the view each time this field is called
2017-10-29 11:03:06 +00:00
if ( $id > 0 && isset ( $this -> _fieldData [ $id ]))
2017-02-01 13:17:04 +00:00
{
// check if we should load scripts for single view
if ( ComponentbuilderHelper :: checkString ( $name_single ) && ! isset ( $this -> customFieldScript [ $name_single ][ $id ]))
{
// add_javascript_view_footer
2017-03-27 12:38:51 +00:00
if ( $this -> _fieldData [ $id ] -> add_javascript_view_footer == 1 && ComponentbuilderHelper :: checkString ( $this -> _fieldData [ $id ] -> javascript_view_footer ))
2016-02-26 00:20:09 +00:00
{
2019-07-28 21:48:42 +00:00
$convert__ = true ;
if ( isset ( $this -> _fieldData [ $id ] -> javascript_view_footer_decoded )
&& $this -> _fieldData [ $id ] -> javascript_view_footer_decoded )
2016-02-26 00:20:09 +00:00
{
2019-07-28 21:48:42 +00:00
$convert__ = false ;
2017-02-01 13:17:04 +00:00
}
2019-07-28 21:48:42 +00:00
$this -> setCustomScriptBuilder (
$this -> _fieldData [ $id ] -> javascript_view_footer ,
'view_footer' ,
$name_single ,
false ,
array (
'table' => 'field' ,
'id' => ( int ) $id ,
'field' => 'javascript_view_footer' ,
'type' => 'js' ,
'prefix' => PHP_EOL ),
$convert__ ,
$convert__ ,
true
);
2017-02-01 13:17:04 +00:00
if ( ! isset ( $this -> _fieldData [ $id ] -> javascript_view_footer_decoded ))
{
$this -> _fieldData [ $id ] -> javascript_view_footer_decoded = true ;
}
2017-12-14 23:10:47 +00:00
if ( strpos ( $this -> _fieldData [ $id ] -> javascript_view_footer , " token " ) !== false ||
strpos ( $this -> _fieldData [ $id ] -> javascript_view_footer , " task=ajax " ) !== false )
2017-02-01 13:17:04 +00:00
{
2017-12-14 23:10:47 +00:00
if ( ! isset ( $this -> customScriptBuilder [ 'token' ]))
2017-02-13 23:24:38 +00:00
{
$this -> customScriptBuilder [ 'token' ] = array ();
}
2017-02-01 13:17:04 +00:00
if ( ! isset ( $this -> customScriptBuilder [ 'token' ][ $name_single ]) || ! $this -> customScriptBuilder [ 'token' ][ $name_single ])
2016-06-23 15:05:37 +00:00
{
2017-02-01 13:17:04 +00:00
$this -> customScriptBuilder [ 'token' ][ $name_single ] = true ;
2016-06-23 15:05:37 +00:00
}
2016-02-26 00:20:09 +00:00
}
2017-02-01 13:17:04 +00:00
}
2016-02-26 00:20:09 +00:00
2017-02-01 13:17:04 +00:00
// add_css_view
if ( $this -> _fieldData [ $id ] -> add_css_view == 1 )
{
2019-07-28 21:48:42 +00:00
$convert__ = true ;
if ( isset ( $this -> _fieldData [ $id ] -> css_view_decoded )
&& $this -> _fieldData [ $id ] -> css_view_decoded )
2016-02-26 00:20:09 +00:00
{
2019-07-28 21:48:42 +00:00
$convert__ = false ;
2017-02-01 13:17:04 +00:00
}
2019-07-28 21:48:42 +00:00
$this -> setCustomScriptBuilder (
$this -> _fieldData [ $id ] -> css_view ,
'css_view' ,
$name_single ,
false ,
array ( 'prefix' => PHP_EOL ),
$convert__ ,
$convert__ ,
true
);
2017-02-01 13:17:04 +00:00
if ( ! isset ( $this -> _fieldData [ $id ] -> css_view_decoded ))
{
$this -> _fieldData [ $id ] -> css_view_decoded = true ;
}
2016-02-26 00:20:09 +00:00
}
2017-02-01 13:17:04 +00:00
// add this only once to view.
$this -> customFieldScript [ $name_single ][ $id ] = true ;
}
// check if we should load scripts for list views
if ( ComponentbuilderHelper :: checkString ( $name_list ) && ! isset ( $this -> customFieldScript [ $name_list ][ $id ]))
{
// add_javascript_views_footer
2017-03-27 12:38:51 +00:00
if ( $this -> _fieldData [ $id ] -> add_javascript_views_footer == 1 && ComponentbuilderHelper :: checkString ( $this -> _fieldData [ $id ] -> javascript_views_footer ))
2016-02-26 00:20:09 +00:00
{
2019-07-28 21:48:42 +00:00
$convert__ = true ;
if ( isset ( $this -> _fieldData [ $id ] -> javascript_views_footer_decoded )
&& $this -> _fieldData [ $id ] -> javascript_views_footer_decoded )
2016-06-23 15:05:37 +00:00
{
2019-07-28 21:48:42 +00:00
$convert__ = false ;
2017-02-01 13:17:04 +00:00
}
2019-07-28 21:48:42 +00:00
$this -> setCustomScriptBuilder (
$this -> _fieldData [ $id ] -> javascript_views_footer ,
'views_footer' ,
$name_single ,
false ,
array (
'table' => 'field' ,
'id' => ( int ) $id ,
'field' => 'javascript_views_footer' ,
'type' => 'js' ,
'prefix' => PHP_EOL ),
$convert__ ,
$convert__ ,
true
);
2017-02-01 13:17:04 +00:00
if ( ! isset ( $this -> _fieldData [ $id ] -> javascript_views_footer_decoded ))
{
$this -> _fieldData [ $id ] -> javascript_views_footer_decoded = true ;
2016-06-23 15:05:37 +00:00
}
2017-12-14 23:10:47 +00:00
if ( strpos ( $this -> _fieldData [ $id ] -> javascript_views_footer , " token " ) !== false ||
strpos ( $this -> _fieldData [ $id ] -> javascript_views_footer , " task=ajax " ) !== false )
2016-02-26 00:20:09 +00:00
{
2017-12-14 23:10:47 +00:00
if ( ! isset ( $this -> customScriptBuilder [ 'token' ]))
2017-02-13 23:24:38 +00:00
{
$this -> customScriptBuilder [ 'token' ] = array ();
}
if ( ! isset ( $this -> customScriptBuilder [ 'token' ][ $name_list ]) || ! $this -> customScriptBuilder [ 'token' ][ $name_list ])
2016-02-26 00:20:09 +00:00
{
2017-02-01 13:17:04 +00:00
$this -> customScriptBuilder [ 'token' ][ $name_list ] = true ;
2016-02-26 00:20:09 +00:00
}
}
}
2017-02-01 13:17:04 +00:00
// add_css_views
if ( $this -> _fieldData [ $id ] -> add_css_views == 1 )
2016-02-26 00:20:09 +00:00
{
2019-07-28 21:48:42 +00:00
$convert__ = true ;
if ( isset ( $this -> _fieldData [ $id ] -> css_views_decoded )
&& $this -> _fieldData [ $id ] -> css_views_decoded )
2017-02-01 13:17:04 +00:00
{
2019-07-28 21:48:42 +00:00
$convert__ = false ;
2017-02-01 13:17:04 +00:00
}
2019-07-28 21:48:42 +00:00
$this -> setCustomScriptBuilder (
$this -> _fieldData [ $id ] -> css_views ,
'css_views' ,
$name_list ,
false ,
array ( 'prefix' => PHP_EOL ),
$convert__ ,
$convert__ ,
true
);
2017-02-01 13:17:04 +00:00
if ( ! isset ( $this -> _fieldData [ $id ] -> css_views_decoded ))
{
$this -> _fieldData [ $id ] -> css_views_decoded = true ;
}
2016-02-26 00:20:09 +00:00
}
2017-02-01 13:17:04 +00:00
// add this only once to view.
$this -> customFieldScript [ $name_list ][ $id ] = true ;
2016-02-26 00:20:09 +00:00
}
}
2017-10-29 11:03:06 +00:00
if ( $id > 0 && isset ( $this -> _fieldData [ $id ]))
2017-02-01 13:17:04 +00:00
{
// return the found field data
return $this -> _fieldData [ $id ];
}
return false ;
2016-02-26 00:20:09 +00:00
}
2017-12-14 23:10:47 +00:00
2018-10-01 02:16:24 +00:00
/**
* set Field details
*
* @ param object $field The field object
* @ param string $singleViewName The single view name
* @ param string $listViewName The list view name
* @ param string $amicably The peaceful resolve
*
* @ return void
*
*/
public function setFieldDetails ( & $field , $singleViewName = null , $listViewName = null , $amicably = '' )
{
// set hash
static $hash = 123467890 ;
// load hash if not found
if ( ! isset ( $field [ 'hash' ]))
{
$field [ 'hash' ] = md5 ( $field [ 'field' ] . $hash );
// increment hash
$hash ++ ;
}
// set the settings
if ( ! isset ( $field [ 'settings' ]))
{
$field [ 'settings' ] = $this -> getFieldData ( $field [ 'field' ], $singleViewName , $listViewName );
}
// set real field name
if ( ! isset ( $field [ 'base_name' ]))
{
$field [ 'base_name' ] = $this -> getFieldName ( $field );
}
// set code name for field type
if ( ! isset ( $field [ 'type_name' ]))
{
$field [ 'type_name' ] = $this -> getFieldType ( $field );
}
// check if value is array
if ( isset ( $field [ 'permission' ]) && ! ComponentbuilderHelper :: checkArray ( $field [ 'permission' ]) && is_numeric ( $field [ 'permission' ]) && $field [ 'permission' ] > 0 )
{
$field [ 'permission' ] = array ( $field [ 'permission' ]);
}
// set unigue name keeper
if ( $listViewName )
{
$this -> setUniqueNameCounter ( $field [ 'base_name' ], $listViewName . $amicably );
}
}
2018-03-11 02:44:43 +00:00
/**
* Get the field ' s actual type
*
* @ param object $field The field object
*
* @ return string Success returns field type
*
*/
public function getFieldType ( & $field )
{
2018-07-12 16:35:38 +00:00
// check if we have done this already
if ( isset ( $field [ 'type_name' ]))
{
return $field [ 'type_name' ];
}
2018-03-11 02:44:43 +00:00
// check that we have the poperties
2018-10-29 16:38:00 +00:00
if ( isset ( $field [ 'settings' ]) && ComponentbuilderHelper :: checkObject ( $field [ 'settings' ]) && isset ( $field [ 'settings' ] -> properties ) && ComponentbuilderHelper :: checkArray ( $field [ 'settings' ] -> properties ))
2018-03-11 02:44:43 +00:00
{
2018-09-24 14:37:51 +00:00
// search for own custom fields
if ( strpos ( $field [ 'settings' ] -> type_name , '@' ) !== false )
2018-03-11 02:44:43 +00:00
{
2018-09-24 14:37:51 +00:00
// set own custom field
2018-10-01 02:16:24 +00:00
$field [ 'settings' ] -> own_custom = $field [ 'settings' ] -> type_name ;
2018-09-24 14:37:51 +00:00
$field [ 'settings' ] -> type_name = 'Custom' ;
}
// set the type name
2019-07-19 02:17:15 +00:00
$type_name = ComponentbuilderHelper :: safeTypeName ( $field [ 'settings' ] -> type_name );
2018-09-24 14:37:51 +00:00
// if custom (we must use the xml value)
2019-07-19 02:17:15 +00:00
if ( strtolower ( $type_name ) === 'custom' || strtolower ( $type_name ) === 'customuser' )
2018-09-24 14:37:51 +00:00
{
2019-07-19 02:17:15 +00:00
$type = ComponentbuilderHelper :: safeTypeName ( ComponentbuilderHelper :: getBetween ( $field [ 'settings' ] -> xml , 'type="' , '"' ));
2018-09-24 14:37:51 +00:00
}
else
{
// loop over properties looking for the type value
foreach ( $field [ 'settings' ] -> properties as $property )
2018-03-11 02:44:43 +00:00
{
2018-09-24 14:37:51 +00:00
if ( $property [ 'name' ] === 'type' ) // type field is never ajustable (unless custom)
2018-03-11 02:44:43 +00:00
{
2018-09-24 14:37:51 +00:00
// force the default value
if ( isset ( $property [ 'example' ]) && ComponentbuilderHelper :: checkString ( $property [ 'example' ]))
{
2019-07-19 02:17:15 +00:00
$type = ComponentbuilderHelper :: safeTypeName ( $property [ 'example' ]);
2018-09-24 14:37:51 +00:00
}
// fall back on the xml settings (not ideal)
else
{
2019-07-19 02:17:15 +00:00
$type = ComponentbuilderHelper :: safeTypeName ( ComponentbuilderHelper :: getBetween ( $field [ 'settings' ] -> xml , 'type="' , '"' ));
2018-09-24 14:37:51 +00:00
}
// exit foreach loop
break ;
2018-03-11 02:44:43 +00:00
}
}
}
2018-09-24 14:37:51 +00:00
// check if the value is set
2019-07-19 02:17:15 +00:00
if ( isset ( $type ) && ComponentbuilderHelper :: checkString ( $type ))
2018-09-24 14:37:51 +00:00
{
return $type ;
}
2019-07-19 02:17:15 +00:00
// fallback on type name set in name field (not ideal)
else
{
return $type_name ;
}
2018-03-11 02:44:43 +00:00
}
// fall back to text
2018-03-18 04:52:07 +00:00
return 'text' ;
2018-03-11 02:44:43 +00:00
}
/**
* Get the field ' s actual name
*
* @ param object $field The field object
* @ param string $listViewName The list view name
2019-06-18 14:12:49 +00:00
* @ param string $amicably The peaceful resolve ( for fields in subforms in same view : )
2018-03-11 02:44:43 +00:00
*
* @ return string Success returns field name
*
*/
2018-10-01 02:16:24 +00:00
public function getFieldName ( & $field , $listViewName = null , $amicably = '' )
2018-03-11 02:44:43 +00:00
{
// return the unique name if already set
2018-10-01 02:16:24 +00:00
if ( ComponentbuilderHelper :: checkString ( $listViewName ) && isset ( $field [ 'hash' ]) && isset ( $this -> uniqueFieldNames [ $listViewName . $amicably . $field [ 'hash' ]]))
2018-03-11 02:44:43 +00:00
{
2018-10-01 02:16:24 +00:00
return $this -> uniqueFieldNames [ $listViewName . $amicably . $field [ 'hash' ]];
2018-03-11 02:44:43 +00:00
}
2018-09-10 11:04:52 +00:00
// always make sure we have a field name and type
if ( ! isset ( $field [ 'settings' ]) || ! isset ( $field [ 'settings' ] -> type_name ) || ! isset ( $field [ 'settings' ] -> name ))
{
return 'error' ;
}
2018-03-11 02:44:43 +00:00
// set the type name
2019-07-28 21:48:42 +00:00
$type_name = ComponentbuilderHelper :: safeTypeName ( $field [ 'settings' ] -> type_name );
2018-03-11 02:44:43 +00:00
// set the name of the field
2019-06-18 14:12:49 +00:00
$name = ComponentbuilderHelper :: safeFieldName ( $field [ 'settings' ] -> name );
2018-03-11 02:44:43 +00:00
// check that we have the poperties
if ( ComponentbuilderHelper :: checkArray ( $field [ 'settings' ] -> properties ))
{
foreach ( $field [ 'settings' ] -> properties as $property )
{
if ( $property [ 'name' ] === 'name' )
{
// if category then name must be catid (only one per view)
if ( $type_name === 'category' )
{
// quick check if this is a category linked to view page
$requeSt_id = ComponentbuilderHelper :: getBetween ( $field [ 'settings' ] -> xml , 'name="' , '"' );
if ( strpos ( $requeSt_id , '_request_id' ) !== false || strpos ( $requeSt_id , '_request_catid' ) !== false )
{
// keep it then, don't change
2019-02-15 22:03:21 +00:00
$name = $this -> setPlaceholders ( $requeSt_id , $this -> placeholders );
2018-03-11 02:44:43 +00:00
}
else
{
$name = 'catid' ;
}
// if list view name is set
if ( ComponentbuilderHelper :: checkString ( $listViewName ))
{
// check if we should use another Text Name as this views name
2019-06-07 14:59:27 +00:00
$otherName = $this -> setPlaceholders ( ComponentbuilderHelper :: getBetween ( $field [ 'settings' ] -> xml , 'othername="' , '"' ), $this -> placeholders );
$otherViews = $this -> setPlaceholders ( ComponentbuilderHelper :: getBetween ( $field [ 'settings' ] -> xml , 'views="' , '"' ), $this -> placeholders );
$otherView = $this -> setPlaceholders ( ComponentbuilderHelper :: getBetween ( $field [ 'settings' ] -> xml , 'view="' , '"' ), $this -> placeholders );
// This is to link other view category
2018-03-11 02:44:43 +00:00
if ( ComponentbuilderHelper :: checkString ( $otherName ) && ComponentbuilderHelper :: checkString ( $otherViews ) && ComponentbuilderHelper :: checkString ( $otherView ))
{
2019-06-07 14:59:27 +00:00
// set other category details
2018-03-11 02:44:43 +00:00
$this -> catOtherName [ $listViewName ] = array (
2019-06-18 14:12:49 +00:00
'name' => ComponentbuilderHelper :: safeFieldName ( $otherName ),
2018-03-11 02:44:43 +00:00
'views' => ComponentbuilderHelper :: safeString ( $otherViews ),
'view' => ComponentbuilderHelper :: safeString ( $otherView )
);
}
}
}
// if tag is set then enable all tag options for this view (only one per view)
elseif ( $type_name === 'tag' )
{
$name = 'tags' ;
}
// if the field is set as alias it must be called alias
elseif ( isset ( $field [ 'alias' ]) && $field [ 'alias' ])
{
$name = 'alias' ;
}
else
{
2018-03-11 02:59:46 +00:00
// get value from xml
2019-06-18 14:12:49 +00:00
$xml = ComponentbuilderHelper :: safeFieldName ( $this -> setPlaceholders ( ComponentbuilderHelper :: getBetween ( $field [ 'settings' ] -> xml , 'name="' , '"' ), $this -> placeholders ));
2018-03-11 02:59:46 +00:00
// check if a value was found
if ( ComponentbuilderHelper :: checkString ( $xml ))
{
$name = $xml ;
}
2018-03-11 02:44:43 +00:00
}
// exit foreach loop
break ;
}
}
}
// return the value unique
2018-03-18 04:52:07 +00:00
if ( ComponentbuilderHelper :: checkString ( $listViewName ) && isset ( $field [ 'hash' ]))
2018-03-11 02:44:43 +00:00
{
2018-10-01 02:16:24 +00:00
$this -> uniqueFieldNames [ $listViewName . $amicably . $field [ 'hash' ]] = $this -> uniqueName ( $name , $listViewName . $amicably );
2018-03-11 02:44:43 +00:00
// now return the unique name
2018-10-01 02:16:24 +00:00
return $this -> uniqueFieldNames [ $listViewName . $amicably . $field [ 'hash' ]];
2018-03-11 02:44:43 +00:00
}
// fall back to global
2018-03-18 04:52:07 +00:00
return $name ;
2018-03-11 02:44:43 +00:00
}
/**
* Count how many times the same field is used per view
*
* @ param string $name The name of the field
* @ param string $view The name of the view
*
* @ return void
*
*/
protected function setUniqueNameCounter ( $name , $view )
{
if ( ! isset ( $this -> uniqueNames [ $view ]))
{
$this -> uniqueNames [ $view ] = array ();
$this -> uniqueNames [ $view ][ 'counter' ] = array ();
$this -> uniqueNames [ $view ][ 'names' ] = array ();
}
if ( ! isset ( $this -> uniqueNames [ $view ][ 'counter' ][ $name ]))
{
$this -> uniqueNames [ $view ][ 'counter' ][ $name ] = 1 ;
return ;
}
// count how many times the field is used
$this -> uniqueNames [ $view ][ 'counter' ][ $name ] ++ ;
return ;
}
/**
* Naming each field with an unique name
*
* @ param string $name The name of the field
* @ param string $view The name of the view
*
* @ return string the name
*
*/
protected function uniqueName ( $name , $view )
{
// only increment if the field name is used multiple times
if ( isset ( $this -> uniqueNames [ $view ][ 'counter' ][ $name ]) && $this -> uniqueNames [ $view ][ 'counter' ][ $name ] > 1 )
{
$counter = 1 ;
// set the unique name
2019-06-18 14:12:49 +00:00
$uniqueName = ComponentbuilderHelper :: safeFieldName ( $name . '_' . $counter );
2018-03-11 02:44:43 +00:00
while ( isset ( $this -> uniqueNames [ $view ][ 'names' ][ $uniqueName ]))
{
// increment the number
$counter ++ ;
// try again
2019-06-18 14:12:49 +00:00
$uniqueName = ComponentbuilderHelper :: safeFieldName ( $name . '_' . $counter );
2018-03-11 02:44:43 +00:00
}
// set the new name number
$this -> uniqueNames [ $view ][ 'names' ][ $uniqueName ] = $counter ;
// return the unique name
return $uniqueName ;
}
return $name ;
}
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* Set get Data
*
2018-08-23 21:51:09 +00:00
* @ param array $ids The ids of the dynamic get
2016-02-26 00:20:09 +00:00
* @ param string $view_code The view code name
2018-08-23 21:51:09 +00:00
* @ param string $context The context for events
2016-02-26 00:20:09 +00:00
*
* @ return oject the get dynamicGet data
*
*/
2018-08-23 21:51:09 +00:00
public function setGetData ( $ids , $view_code , $context )
2016-02-26 00:20:09 +00:00
{
if ( ComponentbuilderHelper :: checkArray ( $ids ))
{
$ids = implode ( ',' , $ids );
if ( ComponentbuilderHelper :: checkString ( $ids ))
{
// Create a new query object.
2017-02-13 23:24:38 +00:00
$query = $this -> db -> getQuery ( true );
2016-02-26 00:20:09 +00:00
$query -> select ( 'a.*' );
$query -> from ( '#__componentbuilder_dynamic_get AS a' );
$query -> where ( 'a.id IN (' . $ids . ')' );
2017-02-13 23:24:38 +00:00
$this -> db -> setQuery ( $query );
$this -> db -> execute ();
if ( $this -> db -> getNumRows ())
2016-02-26 00:20:09 +00:00
{
2017-02-13 23:24:38 +00:00
$results = $this -> db -> loadObjectList ();
2016-02-26 00:20:09 +00:00
$typeArray = array ( 1 => 'LEFT' , 2 => 'LEFT OUTER' , 3 => 'INNER' , 4 => 'RIGHT' , 5 => 'RIGHT OUTER' );
$operatorArray = array ( 1 => '=' , 2 => '!=' , 3 => '<>' , 4 => '>' , 5 => '<' , 6 => '>=' , 7 => '<=' , 8 => '!<' , 9 => '!>' , 10 => 'IN' , 11 => 'NOT IN' );
2019-08-04 22:38:53 +00:00
$guiMapper = array ( 'table' => 'dynamic_get' , 'type' => 'php' );
2017-10-26 16:43:51 +00:00
foreach ( $results as $_nr => & $result )
2016-02-26 00:20:09 +00:00
{
2019-08-04 22:38:53 +00:00
// set GUI mapper id
$guiMapper [ 'id' ] = ( int ) $result -> id ;
2016-02-26 00:20:09 +00:00
// add calculations if set
2017-12-14 23:10:47 +00:00
if ( $result -> addcalculation == 1 && ComponentbuilderHelper :: checkString ( $result -> php_calculation ))
2019-08-04 22:38:53 +00:00
{
2019-07-28 21:48:42 +00:00
// set GUI mapper field
$guiMapper [ 'field' ] = 'php_calculation' ;
$result -> php_calculation = $this -> setGuiCodePlaceholder (
$this -> setDynamicValues ( base64_decode ( $result -> php_calculation )),
$guiMapper
);
}
// setup the router parse
if ( isset ( $result -> add_php_router_parse )
&& $result -> add_php_router_parse == 1
&& isset ( $result -> php_router_parse )
&& ComponentbuilderHelper :: checkString ( $result -> php_router_parse ))
2016-02-26 00:20:09 +00:00
{
2019-07-28 21:48:42 +00:00
// set GUI mapper field
$guiMapper [ 'field' ] = 'php_router_parse' ;
$result -> php_router_parse = $this -> setGuiCodePlaceholder (
$this -> setDynamicValues ( base64_decode ( $result -> php_router_parse )),
$guiMapper
);
}
else
{
$result -> add_php_router_parse = 0 ;
2016-02-26 00:20:09 +00:00
}
2018-03-11 17:03:31 +00:00
// The array of the php scripts that should be added to the script builder
$phpSripts = array ( 'php_before_getitem' , 'php_after_getitem' , 'php_before_getitems' , 'php_after_getitems' , 'php_getlistquery' );
// load the php scripts
foreach ( $phpSripts as $script )
2016-02-26 00:20:09 +00:00
{
2018-03-11 17:03:31 +00:00
// add php script to the script builder
2018-03-18 04:52:07 +00:00
if ( isset ( $result -> { 'add_' . $script }) && $result -> { 'add_' . $script } == 1 && isset ( $result -> { $script }) && ComponentbuilderHelper :: checkString ( $result -> { $script }))
2016-02-26 00:20:09 +00:00
{
2018-03-11 17:03:31 +00:00
// move all main gets out to the customscript builder
if ( $result -> gettype <= 2 )
{
2019-07-28 21:48:42 +00:00
// set GUI mapper field
$guiMapper [ 'field' ] = $script ;
$guiMapper [ 'prefix' ] = PHP_EOL . PHP_EOL ;
$this -> setCustomScriptBuilder (
$result -> { $script },
$this -> target . '_' . $script ,
$view_code ,
false ,
$guiMapper ,
true ,
true ,
true
);
unset ( $guiMapper [ 'prefix' ]);
2018-03-11 17:03:31 +00:00
// remove from local item
unset ( $result -> { $script });
2018-03-18 04:52:07 +00:00
unset ( $result -> { 'add_' . $script });
2018-03-11 17:03:31 +00:00
}
else
{
2019-07-28 21:48:42 +00:00
// set GUI mapper field
$guiMapper [ 'field' ] = $script ;
$guiMapper [ 'prefix' ] = PHP_EOL ;
2018-03-11 17:03:31 +00:00
// only for custom gets
2019-07-28 21:48:42 +00:00
$result -> { $script } = $this -> setGuiCodePlaceholder (
$this -> setDynamicValues ( base64_decode ( $result -> { $script })),
$guiMapper
);
unset ( $guiMapper [ 'prefix' ]);
2018-03-11 17:03:31 +00:00
}
2016-02-26 00:20:09 +00:00
}
2018-03-11 17:03:31 +00:00
else
2016-02-26 00:20:09 +00:00
{
2018-03-11 17:03:31 +00:00
// remove from local item
unset ( $result -> { $script });
2018-03-18 04:52:07 +00:00
unset ( $result -> { 'add_' . $script });
2016-02-26 00:20:09 +00:00
}
}
// set the getmethod code name
2017-12-14 23:10:47 +00:00
$result -> key = ComponentbuilderHelper :: safeString ( $view_code . ' ' . $result -> name . ' ' . $result -> id );
2016-02-26 00:20:09 +00:00
// reset buckets
$result -> main_get = array ();
$result -> custom_get = array ();
2018-10-04 10:07:37 +00:00
// should joineds and other weaks be added
$addDynamicTweaksJoints = true ;
2016-02-26 00:20:09 +00:00
// set source data
switch ( $result -> main_source )
{
case 1 :
2019-01-29 14:43:27 +00:00
// check if auto sync is set
if ( $result -> select_all == 1 )
{
$result -> view_selection = '*' ;
}
2017-12-14 23:10:47 +00:00
// set the view data
2019-01-29 14:43:27 +00:00
$result -> main_get [ 0 ][ 'selection' ] = $this -> setDataSelection ( $result -> key , $view_code , $result -> view_selection , $result -> view_table_main , 'a' , null , 'view' );
2017-12-14 23:10:47 +00:00
$result -> main_get [ 0 ][ 'as' ] = 'a' ;
$result -> main_get [ 0 ][ 'key' ] = $result -> key ;
2018-08-23 21:51:09 +00:00
$result -> main_get [ 0 ][ 'context' ] = $context ;
2017-12-14 23:10:47 +00:00
unset ( $result -> view_selection );
break ;
2016-02-26 00:20:09 +00:00
case 2 :
2019-01-29 14:43:27 +00:00
// check if auto sync is set
if ( $result -> select_all == 1 )
{
$result -> db_selection = '*' ;
}
2017-12-14 23:10:47 +00:00
// set the database data
2019-01-29 14:43:27 +00:00
$result -> main_get [ 0 ][ 'selection' ] = $this -> setDataSelection ( $result -> key , $view_code , $result -> db_selection , $result -> db_table_main , 'a' , null , 'db' );
2017-12-14 23:10:47 +00:00
$result -> main_get [ 0 ][ 'as' ] = 'a' ;
$result -> main_get [ 0 ][ 'key' ] = $result -> key ;
2018-08-23 21:51:09 +00:00
$result -> main_get [ 0 ][ 'context' ] = $context ;
2017-12-14 23:10:47 +00:00
unset ( $result -> db_selection );
break ;
2016-02-26 00:20:09 +00:00
case 3 :
2019-07-28 21:48:42 +00:00
// set GUI mapper field
$guiMapper [ 'field' ] = 'php_custom_get' ;
2018-08-30 16:33:30 +00:00
// get the custom query
2019-07-28 21:48:42 +00:00
$customQueryString = $this -> setGuiCodePlaceholder (
$this -> setDynamicValues ( base64_decode ( $result -> php_custom_get )),
$guiMapper
);
2018-08-30 16:33:30 +00:00
// get the table name
$_searchQuery = ComponentbuilderHelper :: getBetween ( $customQueryString , '$query->from(' , ')' );
if ( ComponentbuilderHelper :: checkString ( $_searchQuery ) && strpos ( $_searchQuery , '#__' ) !== false )
{
$_queryName = ComponentbuilderHelper :: getBetween ( $_searchQuery , '#__' , " ' " );
if ( ! ComponentbuilderHelper :: checkString ( $_queryName ))
{
$_queryName = ComponentbuilderHelper :: getBetween ( $_searchQuery , '#__' , '"' );
}
}
// set to blank if not found
if ( ! isset ( $_queryName ) || ! ComponentbuilderHelper :: checkString ( $_queryName ))
{
$_queryName = '' ;
}
2017-12-14 23:10:47 +00:00
// set custom script
$result -> main_get [ 0 ][ 'selection' ] = array (
2018-08-30 16:33:30 +00:00
'select' => $customQueryString ,
'from' => '' , 'table' => '' , 'type' => '' , 'name' => $_queryName );
$result -> main_get [ 0 ][ 'as' ] = 'a' ;
$result -> main_get [ 0 ][ 'key' ] = $result -> key ;
$result -> main_get [ 0 ][ 'context' ] = $context ;
2018-10-04 10:07:37 +00:00
// do not add
$addDynamicTweaksJoints = false ;
2017-12-14 23:10:47 +00:00
break ;
2016-02-26 00:20:09 +00:00
}
2018-10-04 10:07:37 +00:00
// only add if main source is not custom
if ( $addDynamicTweaksJoints )
2016-02-26 00:20:09 +00:00
{
2018-10-04 10:07:37 +00:00
// set join_view_table details
$result -> join_view_table = json_decode ( $result -> join_view_table , true );
if ( ComponentbuilderHelper :: checkArray ( $result -> join_view_table ))
2016-02-26 00:20:09 +00:00
{
2019-12-16 03:02:16 +00:00
// start the part of a table bucket
$_part_of_a = array ();
// build relationship
$_relationship = array_map ( function ( $op ) use ( & $_part_of_a ){
$bucket = array ();
// array(on_field_as, on_field)
$bucket [ 'on_field' ] = array_map ( 'trim' , explode ( '.' , $op [ 'on_field' ]));
// array(join_field_as, join_field)
$bucket [ 'join_field' ] = array_map ( 'trim' , explode ( '.' , $op [ 'join_field' ]));
// triget filed that has table a relationship
if ( $bucket [ 'on_field' ][ 0 ] === 'a' ||
isset ( $_part_of_a [ $bucket [ 'on_field' ][ 0 ]]) ||
isset ( $_part_of_a [ $bucket [ 'join_field' ][ 0 ]]))
{
$_part_of_a [ $op [ 'as' ]] = $op [ 'as' ];
}
return $bucket ;
}, $result -> join_view_table );
// loop joints
2018-10-04 10:07:37 +00:00
foreach ( $result -> join_view_table as $nr => & $option )
2016-02-26 00:20:09 +00:00
{
2018-10-04 10:07:37 +00:00
if ( ComponentbuilderHelper :: checkString ( $option [ 'selection' ]))
2016-02-26 00:20:09 +00:00
{
2018-10-04 10:07:37 +00:00
// convert the type
$option [ 'type' ] = $typeArray [ $option [ 'type' ]];
// convert the operator
$option [ 'operator' ] = $operatorArray [ $option [ 'operator' ]];
// get the on field values
2019-12-16 03:02:16 +00:00
$on_field = $_relationship [ $nr ][ 'on_field' ];
2018-10-04 10:07:37 +00:00
// get the join field values
2019-12-16 03:02:16 +00:00
$join_field = $_relationship [ $nr ][ 'join_field' ];
// set selection
2018-10-04 10:07:37 +00:00
$option [ 'selection' ] = $this -> setDataSelection ( $result -> key , $view_code , $option [ 'selection' ], $option [ 'view_table' ], $option [ 'as' ], $option [ 'row_type' ], 'view' );
$option [ 'key' ] = $result -> key ;
$option [ 'context' ] = $context ;
// load to the getters
if ( $option [ 'row_type' ] == 1 )
2016-02-26 00:20:09 +00:00
{
2018-10-04 10:07:37 +00:00
$result -> main_get [] = $option ;
2019-12-16 03:02:16 +00:00
if ( $on_field [ 0 ] === 'a' || isset ( $_part_of_a [ $join_field [ 0 ]]) || isset ( $_part_of_a [ $on_field [ 0 ]]))
2018-10-04 10:07:37 +00:00
{
$this -> siteMainGet [ $this -> target ][ $view_code ][ $option [ 'as' ]] = $option [ 'as' ];
}
else
{
$this -> siteDynamicGet [ $this -> target ][ $view_code ][ $option [ 'as' ]][ $join_field [ 1 ]] = $on_field [ 0 ];
}
2016-02-26 00:20:09 +00:00
}
2018-10-04 10:07:37 +00:00
elseif ( $option [ 'row_type' ] == 2 )
2016-02-26 00:20:09 +00:00
{
2018-10-04 10:07:37 +00:00
$result -> custom_get [] = $option ;
if ( $on_field [ 0 ] != 'a' )
{
$this -> siteDynamicGet [ $this -> target ][ $view_code ][ $option [ 'as' ]][ $join_field [ 1 ]] = $on_field [ 0 ];
}
2016-02-26 00:20:09 +00:00
}
}
2018-10-04 10:07:37 +00:00
unset ( $result -> join_view_table [ $nr ]);
2016-02-26 00:20:09 +00:00
}
}
2018-10-04 10:07:37 +00:00
unset ( $result -> join_view_table );
// set join_db_table details
$result -> join_db_table = json_decode ( $result -> join_db_table , true );
if ( ComponentbuilderHelper :: checkArray ( $result -> join_db_table ))
2016-02-26 00:20:09 +00:00
{
2019-12-16 03:02:16 +00:00
// start the part of a table bucket
$_part_of_a = array ();
// build relationship
$_relationship = array_map ( function ( $op ) use ( & $_part_of_a ){
$bucket = array ();
// array(on_field_as, on_field)
$bucket [ 'on_field' ] = array_map ( 'trim' , explode ( '.' , $op [ 'on_field' ]));
// array(join_field_as, join_field)
$bucket [ 'join_field' ] = array_map ( 'trim' , explode ( '.' , $op [ 'join_field' ]));
// triget filed that has table a relationship
if ( $bucket [ 'on_field' ][ 0 ] === 'a' ||
isset ( $_part_of_a [ $bucket [ 'on_field' ][ 0 ]]) ||
isset ( $_part_of_a [ $bucket [ 'join_field' ][ 0 ]]))
{
$_part_of_a [ $op [ 'as' ]] = $op [ 'as' ];
}
return $bucket ;
}, $result -> join_db_table );
// loop joints
2018-10-04 10:07:37 +00:00
foreach ( $result -> join_db_table as $nr => & $option1 )
2016-02-26 00:20:09 +00:00
{
2018-10-04 10:07:37 +00:00
if ( ComponentbuilderHelper :: checkString ( $option1 [ 'selection' ]))
2016-02-26 00:20:09 +00:00
{
2018-10-04 10:07:37 +00:00
// convert the type
$option1 [ 'type' ] = $typeArray [ $option1 [ 'type' ]];
// convert the operator
$option1 [ 'operator' ] = $operatorArray [ $option1 [ 'operator' ]];
// get the on field values
2019-12-16 03:02:16 +00:00
$on_field = $_relationship [ $nr ][ 'on_field' ];
2018-10-04 10:07:37 +00:00
// get the join field values
2019-12-16 03:02:16 +00:00
$join_field = $_relationship [ $nr ][ 'join_field' ];
// set selection
2018-10-04 10:07:37 +00:00
$option1 [ 'selection' ] = $this -> setDataSelection ( $result -> key , $view_code , $option1 [ 'selection' ], $option1 [ 'db_table' ], $option1 [ 'as' ], $option1 [ 'row_type' ], 'db' );
$option1 [ 'key' ] = $result -> key ;
$option1 [ 'context' ] = $context ;
// load to the getters
if ( $option1 [ 'row_type' ] == 1 )
2016-02-26 00:20:09 +00:00
{
2018-10-04 10:07:37 +00:00
$result -> main_get [] = $option1 ;
2019-12-16 03:02:16 +00:00
if ( $on_field [ 0 ] === 'a' || isset ( $_part_of_a [ $join_field [ 0 ]]) || isset ( $_part_of_a [ $on_field [ 0 ]]))
2018-10-04 10:07:37 +00:00
{
$this -> siteMainGet [ $this -> target ][ $view_code ][ $option1 [ 'as' ]] = $option1 [ 'as' ];
}
else
{
$this -> siteDynamicGet [ $this -> target ][ $view_code ][ $option1 [ 'as' ]][ $join_field [ 1 ]] = $on_field [ 0 ];
}
2016-02-26 00:20:09 +00:00
}
2018-10-04 10:07:37 +00:00
elseif ( $option1 [ 'row_type' ] == 2 )
2016-02-26 00:20:09 +00:00
{
2018-10-04 10:07:37 +00:00
$result -> custom_get [] = $option1 ;
if ( $on_field [ 0 ] != 'a' )
{
$this -> siteDynamicGet [ $this -> target ][ $view_code ][ $option1 [ 'as' ]][ $join_field [ 1 ]] = $on_field [ 0 ];
}
2016-02-26 00:20:09 +00:00
}
}
2018-10-04 10:07:37 +00:00
unset ( $result -> join_db_table [ $nr ]);
2016-02-26 00:20:09 +00:00
}
}
2018-10-04 10:07:37 +00:00
unset ( $result -> join_db_table );
// set filter details
$result -> filter = json_decode ( $result -> filter , true );
if ( ComponentbuilderHelper :: checkArray ( $result -> filter ))
2016-02-26 00:20:09 +00:00
{
2018-10-04 10:07:37 +00:00
foreach ( $result -> filter as $nr => & $option2 )
2016-02-26 00:20:09 +00:00
{
2018-10-04 10:07:37 +00:00
if ( isset ( $option2 [ 'operator' ]))
{
$option2 [ 'operator' ] = $operatorArray [ $option2 [ 'operator' ]];
2018-12-19 04:06:36 +00:00
$option2 [ 'state_key' ] = $this -> setPlaceholders ( $this -> setDynamicValues ( $option2 [ 'state_key' ]), $this -> placeholders );
2018-10-04 10:07:37 +00:00
$option2 [ 'key' ] = $result -> key ;
}
else
{
unset ( $result -> filter [ $nr ]);
}
2016-02-26 00:20:09 +00:00
}
}
2018-10-04 10:07:37 +00:00
// set where details
$result -> where = json_decode ( $result -> where , true );
if ( ComponentbuilderHelper :: checkArray ( $result -> where ))
2016-02-26 00:20:09 +00:00
{
2018-10-04 10:07:37 +00:00
foreach ( $result -> where as $nr => & $option3 )
2016-02-26 00:20:09 +00:00
{
2018-10-04 10:07:37 +00:00
if ( isset ( $option3 [ 'operator' ]))
{
$option3 [ 'operator' ] = $operatorArray [ $option3 [ 'operator' ]];
}
else
{
unset ( $result -> where [ $nr ]);
}
2016-02-26 00:20:09 +00:00
}
}
2018-10-04 10:07:37 +00:00
else
{
unset ( $result -> where );
}
// set order details
$result -> order = json_decode ( $result -> order , true );
if ( ! ComponentbuilderHelper :: checkArray ( $result -> order ))
{
unset ( $result -> order );
}
2019-04-09 20:42:19 +00:00
// set grouping
$result -> group = json_decode ( $result -> group , true );
if ( ! ComponentbuilderHelper :: checkArray ( $result -> group ))
{
unset ( $result -> group );
}
2018-10-04 10:07:37 +00:00
// set global details
$result -> global = json_decode ( $result -> global , true );
if ( ! ComponentbuilderHelper :: checkArray ( $result -> global ))
{
unset ( $result -> global );
}
2016-02-26 00:20:09 +00:00
}
2017-10-06 14:53:22 +00:00
else
{
2018-10-04 10:07:37 +00:00
// when we have a custom query script we do not add the dynamic options
unset ( $result -> join_view_table );
unset ( $result -> join_db_table );
unset ( $result -> filter );
2017-10-06 14:53:22 +00:00
unset ( $result -> where );
unset ( $result -> order );
2019-04-09 20:42:19 +00:00
unset ( $result -> group );
2017-10-06 14:53:22 +00:00
unset ( $result -> global );
}
2018-08-23 01:37:42 +00:00
// load the events if any is set
if ( $result -> gettype == 1 && ComponentbuilderHelper :: checkJson ( $result -> plugin_events ))
{
$result -> plugin_events = json_decode ( $result -> plugin_events , true );
}
else
{
$result -> plugin_events = '' ;
}
2016-02-26 00:20:09 +00:00
}
return $results ;
}
}
}
return false ;
}
2017-12-14 23:10:47 +00:00
2019-07-28 21:48:42 +00:00
/**
* set the script for the custom script builder
*
* @ param string $script The script
* @ param string $first The first key
* @ param string $second The second key ( if not set we use only first key )
* @ param string $third The third key ( if not set we use only first and second key )
* @ param array $config The config options
* @ param bool $base64 The switch to decode base64 the script
* default : true
* @ param bool $dynamic The switch to dynamic update the script
* default : true
* @ param bool $add The switch to add to exiting instead of replace
* default : false
*
* @ return boolean true on success
*
*/
public function setCustomScriptBuilder ( & $script , $first , $second = false , $third = false , $config = array (), $base64 = true , $dynamic = true , $add = false )
{
// only load if we have a string
if ( ! ComponentbuilderHelper :: checkString ( $script ))
{
return false ;
}
// this needs refactoring (TODO)
if ( ! isset ( $this -> customScriptBuilder [ $first ]) || ( $second && ! isset ( $this -> customScriptBuilder [ $first ][ $second ])))
{
// check if the script first key is set
if ( $second && ! isset ( $this -> customScriptBuilder [ $first ]))
{
$this -> customScriptBuilder [ $first ] = array ();
}
elseif ( $add && ! $second && ! isset ( $this -> customScriptBuilder [ $first ]))
{
$this -> customScriptBuilder [ $first ] = '' ;
}
// check if the script second key is set
if ( $second && $third && ! isset ( $this -> customScriptBuilder [ $first ][ $second ]))
{
$this -> customScriptBuilder [ $first ][ $second ] = array ();
}
elseif ( $add && $second && ! $third && ! isset ( $this -> customScriptBuilder [ $first ][ $second ]))
{
$this -> customScriptBuilder [ $first ][ $second ] = '' ;
}
// check if the script third key is set
if ( $add && $second && $third && ! isset ( $this -> customScriptBuilder [ $first ][ $second ][ $third ]))
{
$this -> customScriptBuilder [ $first ][ $second ][ $third ] = '' ;
}
}
// prep the script string
if ( $base64 && $dynamic )
{
$script = $this -> setDynamicValues ( base64_decode ( $script ));
}
elseif ( $base64 )
{
$script = base64_decode ( $script );
}
elseif ( $dynamic ) // this does not happen (just incase)
{
$script = $this -> setDynamicValues ( $script );
}
// check if we still hava a string
if ( ComponentbuilderHelper :: checkString ( $script ))
{
// now load the placeholder snippet if needed
if ( $base64 || $dynamic )
{
$script = $this -> setGuiCodePlaceholder ( $script , $config );
}
// load the script
if ( $first && $second && $third )
{
// now act on loading option
if ( $add )
{
$this -> customScriptBuilder [ $first ][ $second ][ $third ] .= $script ;
}
else
{
$this -> customScriptBuilder [ $first ][ $second ][ $third ] = $script ;
}
}
elseif ( $first && $second )
{
// now act on loading option
if ( $add )
{
$this -> customScriptBuilder [ $first ][ $second ] .= $script ;
}
else
{
$this -> customScriptBuilder [ $first ][ $second ] = $script ;
}
}
else
{
// now act on loading option
if ( $add )
{
$this -> customScriptBuilder [ $first ] .= $script ;
}
else
{
$this -> customScriptBuilder [ $first ] = $script ;
}
}
return true ;
}
return false ;
}
2017-10-29 11:03:06 +00:00
/**
* To limit the SQL Demo date build in the views
*
* @ param array $settings Tweaking array .
*
* @ return void
*
2017-12-14 23:10:47 +00:00
*/
2017-10-29 11:03:06 +00:00
public function setSqlTweaking ( $settings )
{
if ( ComponentbuilderHelper :: checkArray ( $settings ))
{
2017-12-14 23:10:47 +00:00
foreach ( $settings as $setting )
2017-10-29 11:03:06 +00:00
{
// should sql dump be added
if ( 1 == $setting [ 'add_sql' ])
{
// add sql (by option)
if ( 2 == $setting [ 'add_sql_options' ])
{
// rest always
$id_array = array ();
// by id (first remove backups)
$ids = $setting [ 'ids' ];
// now get the ids
if ( strpos ( $ids , ',' ) !== false )
{
2017-12-14 23:10:47 +00:00
$id_array = ( array ) array_map ( 'trim' , explode ( ',' , $ids ));
2017-10-29 11:03:06 +00:00
}
else
{
$id_array [] = trim ( $ids );
}
$id_array_new = array ();
// check for ranges
foreach ( $id_array as $key => $id )
{
if ( strpos ( $id , '=>' ) !== false )
{
$id_range = ( array ) array_map ( 'trim' , explode ( '=>' , $id ));
unset ( $id_array [ $key ]);
// build range
2019-09-05 21:12:56 +00:00
if ( count (( array ) $id_range ) == 2 )
2017-10-29 11:03:06 +00:00
{
2017-12-14 23:10:47 +00:00
$range = range ( $id_range [ 0 ], $id_range [ 1 ]);
$id_array_new = array_merge ( $id_array_new , $range );
2017-10-29 11:03:06 +00:00
}
}
}
if ( ComponentbuilderHelper :: checkArray ( $id_array_new ))
{
$id_array = array_merge ( $id_array_new , $id_array );
}
// final fixing to array
if ( ComponentbuilderHelper :: checkArray ( $id_array ))
{
// uniqe
$id_array = array_unique ( $id_array , SORT_NUMERIC );
// sort
sort ( $id_array , SORT_NUMERIC );
// now set it to global
2017-12-14 23:10:47 +00:00
$this -> sqlTweak [( int ) $setting [ 'adminview' ]][ 'where' ] = implode ( ',' , $id_array );
2017-10-29 11:03:06 +00:00
}
}
}
else
{
// remove all sql dump options
2017-12-14 23:10:47 +00:00
$this -> sqlTweak [( int ) $setting [ 'adminview' ]][ 'remove' ] = true ;
2017-10-29 11:03:06 +00:00
}
}
}
}
2017-12-14 23:10:47 +00:00
2017-06-16 12:38:06 +00:00
/**
* check if an update SQL is needed
*
* @ param mix $old The old values
* @ param mix $new The new values
* @ param string $type The type of values
* @ param int $key The id / key where values changed
2018-07-12 16:35:38 +00:00
* @ param array $ignore The ids to ignore
2017-06-16 12:38:06 +00:00
*
* @ return void
*
*/
2018-07-12 16:35:38 +00:00
protected function setUpdateSQL ( $old , $new , $type , $key = null , $ignore = null )
2017-06-16 12:38:06 +00:00
{
// check if there were new items added
2017-12-14 23:10:47 +00:00
if ( ComponentbuilderHelper :: checkArray ( $new ) && ComponentbuilderHelper :: checkArray ( $old ))
2017-06-16 12:38:06 +00:00
{
2017-10-12 23:14:17 +00:00
// check if this is old repeatable field
if ( isset ( $new [ $type ]))
2017-06-16 12:38:06 +00:00
{
2017-10-12 23:14:17 +00:00
foreach ( $new [ $type ] as $item )
2017-10-12 00:50:14 +00:00
{
2017-10-12 23:14:17 +00:00
$newItem = true ;
2018-07-12 16:35:38 +00:00
// check if this is an id to ignore
if ( ComponentbuilderHelper :: checkArray ( $ignore ) && in_array ( $item , $ignore ))
{
// don't add ignored ids
$newItem = false ;
}
2017-10-12 00:50:14 +00:00
// check if this is old repeatable field
2018-07-12 16:35:38 +00:00
elseif ( isset ( $old [ $type ]) && ComponentbuilderHelper :: checkArray ( $old [ $type ]))
2017-10-12 00:50:14 +00:00
{
2017-10-12 23:14:17 +00:00
if ( ! in_array ( $item , $old [ $type ]))
2017-10-12 00:50:14 +00:00
{
2017-10-12 23:14:17 +00:00
// we have a new item, lets add to SQL
$this -> setAddSQL ( $type , $item , $key );
2017-10-12 00:50:14 +00:00
}
2017-10-12 23:14:17 +00:00
// add only once
$newItem = false ;
2017-10-12 00:50:14 +00:00
}
elseif ( ! isset ( $old [ $type ]))
{
// we have new values
2017-12-14 23:10:47 +00:00
foreach ( $old as $oldItem )
2017-10-12 00:50:14 +00:00
{
if ( isset ( $oldItem [ $type ]))
{
if ( $oldItem [ $type ] == $item [ $type ])
{
$newItem = false ;
break ;
}
}
else
{
$newItem = false ;
break ;
}
}
}
else
{
$newItem = false ;
}
2017-10-12 23:14:17 +00:00
// add if new
if ( $newItem )
2017-06-16 12:38:06 +00:00
{
2017-10-12 23:14:17 +00:00
// we have a new item, lets add to SQL
$this -> setAddSQL ( $type , $item [ $type ], $key );
2017-06-16 12:38:06 +00:00
}
2017-10-12 23:14:17 +00:00
}
}
else
{
foreach ( $new as $item )
{
if ( isset ( $item [ $type ]))
2017-06-16 12:38:06 +00:00
{
2018-07-12 16:35:38 +00:00
// search to see if this is a new value
$newItem = true ;
// check if this is an id to ignore
if ( ComponentbuilderHelper :: checkArray ( $ignore ) && in_array ( $item [ $type ], $ignore ))
{
// don't add ignored ids
$newItem = false ;
}
2017-10-12 23:14:17 +00:00
// check if this is old repeatable field
2018-07-12 16:35:38 +00:00
elseif ( isset ( $old [ $type ]) && ComponentbuilderHelper :: checkArray ( $old [ $type ]))
2017-06-16 12:38:06 +00:00
{
2017-10-12 23:14:17 +00:00
if ( in_array ( $item [ $type ], $old [ $type ]))
{
$newItem = false ;
}
2017-06-16 12:38:06 +00:00
}
2017-10-12 23:14:17 +00:00
elseif ( ! isset ( $old [ $type ]))
2017-06-16 12:38:06 +00:00
{
2017-10-12 23:14:17 +00:00
// we have new values
2017-12-14 23:10:47 +00:00
foreach ( $old as $oldItem )
2017-10-12 23:14:17 +00:00
{
if ( isset ( $oldItem [ $type ]))
{
if ( $oldItem [ $type ] == $item [ $type ])
{
$newItem = false ;
break ;
}
}
else
{
$newItem = false ;
break ;
}
}
2017-06-16 12:38:06 +00:00
}
else
{
2017-10-12 23:14:17 +00:00
$newItem = false ;
2017-06-16 12:38:06 +00:00
}
2018-07-12 16:35:38 +00:00
// add if new
if ( $newItem )
{
// we have a new item, lets add to SQL
$this -> setAddSQL ( $type , $item [ $type ], $key );
}
2017-10-12 23:14:17 +00:00
}
2017-06-16 12:38:06 +00:00
}
}
}
2018-09-25 20:02:48 +00:00
elseif ( $key && (( ComponentbuilderHelper :: checkString ( $new ) && ComponentbuilderHelper :: checkString ( $old )) || ( is_numeric ( $new ) && is_numeric ( $old ))) && $new !== $old )
2017-06-16 12:38:06 +00:00
{
// the string changed, lets add to SQL update
if ( ! isset ( $this -> updateSQL [ $type ]) || ! ComponentbuilderHelper :: checkArray ( $this -> updateSQL [ $type ]))
{
$this -> updateSQL [ $type ] = array ();
}
// set at key
2017-12-14 23:10:47 +00:00
$this -> updateSQL [ $type ][ $key ] = array ( 'old' => $old , 'new' => $new );
2017-06-16 12:38:06 +00:00
}
}
2017-12-14 23:10:47 +00:00
2017-10-12 23:14:17 +00:00
/**
* Set the add sql
*
* @ param string $type The type of values
* @ param int $item The item id to add
* @ param int $key The id / key where values changed
*
* @ return void
*/
protected function setAddSQL ( $type , $item , $key )
{
// we have a new item, lets add to SQL
if ( ! isset ( $this -> addSQL [ $type ]) || ! ComponentbuilderHelper :: checkArray ( $this -> addSQL [ $type ]))
{
$this -> addSQL [ $type ] = array ();
}
// add key if found
if ( $key )
{
if ( ! isset ( $this -> addSQL [ $type ][ $key ]) || ! ComponentbuilderHelper :: checkArray ( $this -> addSQL [ $type ][ $key ]))
{
$this -> addSQL [ $type ][ $key ] = array ();
}
$this -> addSQL [ $type ][ $key ][] = ( int ) $item ;
}
else
{
// convert adminview id to name
if ( 'adminview' === $type )
{
$this -> addSQL [ $type ][] = ComponentbuilderHelper :: safeString ( $this -> getAdminViewData ( $item ) -> name_single );
}
else
{
$this -> addSQL [ $type ][] = ( int ) $item ;
}
}
}
2017-12-14 23:10:47 +00:00
2017-06-16 12:38:06 +00:00
/**
* Get Item History values
*
* @ param string $type The type of item
* @ param int $id The item ID
*
* @ return oject The history
*
*/
protected function getHistoryWatch ( $type , $id )
{
// quick class object to store old history object
$this -> tmpHistory = null ;
// Create a new query object.
$query = $this -> db -> getQuery ( true );
$query -> select ( 'h.*' );
$query -> from ( '#__ucm_history AS h' );
2017-12-14 23:10:47 +00:00
$query -> where ( $this -> db -> quoteName ( 'h.ucm_item_id' ) . ' = ' . ( int ) $id );
2017-06-16 12:38:06 +00:00
// Join over the content type for the type id
$query -> join ( 'LEFT' , '#__content_types AS ct ON ct.type_id = h.ucm_type_id' );
2017-12-14 23:10:47 +00:00
$query -> where ( 'ct.type_alias = ' . $this -> db -> quote ( 'com_componentbuilder.' . $type ));
2017-06-16 12:38:06 +00:00
$query -> order ( 'h.save_date DESC' );
$this -> db -> setQuery ( $query , 0 , 1 );
$this -> db -> execute ();
if ( $this -> db -> getNumRows ())
{
// new version of this item found
// so we need to mark it as the last compiled version
$newActive = $this -> db -> loadObject ();
// set the new version watch
$this -> setHistoryWatch ( $newActive , 1 );
}
// Get last compiled verion
$query = $this -> db -> getQuery ( true );
$query -> select ( 'h.*' );
$query -> from ( '#__ucm_history AS h' );
$query -> where ( $this -> db -> quoteName ( 'h.ucm_item_id' ) . ' = ' . ( int ) $id );
$query -> where ( 'h.keep_forever = 1' );
$query -> where ( 'h.version_note LIKE ' . $this -> db -> quote ( '%component%' ));
// make sure it does not return the active version
if ( isset ( $newActive ) && isset ( $newActive -> version_id ))
{
$query -> where ( 'h.version_id != ' . ( int ) $newActive -> version_id );
}
// Join over the content type for the type id
$query -> join ( 'LEFT' , '#__content_types AS ct ON ct.type_id = h.ucm_type_id' );
2017-12-14 23:10:47 +00:00
$query -> where ( 'ct.type_alias = ' . $this -> db -> quote ( 'com_componentbuilder.' . $type ));
2017-06-16 12:38:06 +00:00
$query -> order ( 'h.save_date DESC' );
$this -> db -> setQuery ( $query );
$this -> db -> execute ();
if ( $this -> db -> getNumRows ())
{
// the old active version was found
// so we may need to do an SQL update
// and unmark the old compiled version
$oldActives = $this -> db -> loadObjectList ();
foreach ( $oldActives as $oldActive )
{
// remove old version watch
$this -> setHistoryWatch ( $oldActive , 0 );
}
}
// return the last used history record or null.
return $this -> tmpHistory ;
}
2017-12-14 23:10:47 +00:00
2017-06-16 12:38:06 +00:00
/**
* Set Item History Watch
*
* @ param Object $object The history object
* @ param int $action The action to take
2017-12-14 23:10:47 +00:00
* 0 = remove watch
* 1 = add watch
2017-06-16 12:38:06 +00:00
* @ param string $type The type of item
*
* @ return bool
*
*/
protected function setHistoryWatch ( $object , $action )
{
// check the note
if ( ComponentbuilderHelper :: checkJson ( $object -> version_note ))
{
$version_note = json_decode ( $object -> version_note , true );
}
else
{
$version_note = array ( 'component' => array ());
}
// set watch
switch ( $action )
{
case 0 :
// remove watch
2017-12-14 23:10:47 +00:00
if ( isset ( $version_note [ 'component' ]) && ( $key = array_search ( $this -> componentID , $version_note [ 'component' ])) !== false )
2017-06-16 12:38:06 +00:00
{
// last version that was used to build/compile
$this -> tmpHistory = json_decode ( $object -> version_data );
// remove it from this component
unset ( $version_note [ 'component' ][ $key ]);
}
else
{
// since it was not found, no need to update anything
return true ;
}
2017-12-14 23:10:47 +00:00
break ;
2017-06-16 12:38:06 +00:00
case 1 :
// add watch
if ( ! in_array ( $this -> componentID , $version_note [ 'component' ]))
{
$version_note [ 'component' ][] = $this -> componentID ;
}
else
{
// since it is there already, no need to update anything
return true ;
}
2017-12-14 23:10:47 +00:00
break ;
2017-06-16 12:38:06 +00:00
}
// check if we need to still keep this locked
if ( isset ( $version_note [ 'component' ]) && ComponentbuilderHelper :: checkArray ( $version_note [ 'component' ]))
{
// insure component ids are only added once per item
$version_note [ 'component' ] = array_unique ( $version_note [ 'component' ]);
// we may change this, little risky (but since JCB does not have history notes it should be okay for now)
$object -> version_note = json_encode ( $version_note );
$object -> keep_forever = '1' ;
}
else
{
$object -> version_note = '' ;
$object -> keep_forever = '0' ;
}
// run the update
return $this -> db -> updateObject ( '#__ucm_history' , $object , 'version_id' );
}
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* Set Template and Layout Data
*
* @ param string $default The content to check
* @ param string $view The view code name
*
* @ return void
*
*/
2017-12-14 23:10:47 +00:00
public function setTemplateAndLayoutData ( $default , $view )
2016-02-26 00:20:09 +00:00
{
// set the Tempale date
2017-12-14 23:10:47 +00:00
$temp1 = ComponentbuilderHelper :: getAllBetween ( $default , " \$ this->loadTemplate(' " , " ') " );
$temp2 = ComponentbuilderHelper :: getAllBetween ( $default , '$this->loadTemplate("' , '")' );
2016-02-26 00:20:09 +00:00
$templates = array ();
$again = array ();
if ( ComponentbuilderHelper :: checkArray ( $temp1 ) && ComponentbuilderHelper :: checkArray ( $temp2 ))
{
2017-12-14 23:10:47 +00:00
$templates = array_merge ( $temp1 , $temp2 );
2016-02-26 00:20:09 +00:00
}
else
{
if ( ComponentbuilderHelper :: checkArray ( $temp1 ))
{
$templates = $temp1 ;
}
elseif ( ComponentbuilderHelper :: checkArray ( $temp2 ))
{
$templates = $temp2 ;
}
}
if ( ComponentbuilderHelper :: checkArray ( $templates ))
{
foreach ( $templates as $template )
{
2017-12-14 23:10:47 +00:00
if ( ! isset ( $this -> templateData [ $this -> target ][ $view ]) || ! array_key_exists ( $template , $this -> templateData [ $this -> target ][ $view ]))
2016-02-26 00:20:09 +00:00
{
2017-12-14 23:10:47 +00:00
$data = $this -> getDataWithAlias ( $template , 'template' , $view );
2016-02-26 00:20:09 +00:00
if ( ComponentbuilderHelper :: checkArray ( $data ))
{
$this -> templateData [ $this -> target ][ $view ][ $template ] = $data ;
// call self to get child data
2017-12-14 23:10:47 +00:00
$again [] = array ( $data [ 'html' ], $view );
$again [] = array ( $data [ 'php_view' ], $view );
2016-02-26 00:20:09 +00:00
}
}
}
}
// set the layout data
2017-12-14 23:10:47 +00:00
$lay1 = ComponentbuilderHelper :: getAllBetween ( $default , " JLayoutHelper::render(' " , " ', " );
$lay2 = ComponentbuilderHelper :: getAllBetween ( $default , 'JLayoutHelper::render("' , '",' );
;
2016-02-26 00:20:09 +00:00
if ( ComponentbuilderHelper :: checkArray ( $lay1 ) && ComponentbuilderHelper :: checkArray ( $lay2 ))
{
2017-12-14 23:10:47 +00:00
$layouts = array_merge ( $lay1 , $lay2 );
2016-02-26 00:20:09 +00:00
}
else
{
if ( ComponentbuilderHelper :: checkArray ( $lay1 ))
{
$layouts = $lay1 ;
}
elseif ( ComponentbuilderHelper :: checkArray ( $lay2 ))
{
$layouts = $lay2 ;
}
}
if ( isset ( $layouts ) && ComponentbuilderHelper :: checkArray ( $layouts ))
{
foreach ( $layouts as $layout )
{
2017-12-14 23:10:47 +00:00
if ( ! isset ( $this -> layoutData [ $this -> target ]) || ! ComponentbuilderHelper :: checkArray ( $this -> layoutData [ $this -> target ]) || ! array_key_exists ( $layout , $this -> layoutData [ $this -> target ]))
2016-02-26 00:20:09 +00:00
{
2017-12-14 23:10:47 +00:00
$data = $this -> getDataWithAlias ( $layout , 'layout' , $view );
2016-02-26 00:20:09 +00:00
if ( ComponentbuilderHelper :: checkArray ( $data ))
{
$this -> layoutData [ $this -> target ][ $layout ] = $data ;
// call self to get child data
2017-12-14 23:10:47 +00:00
$again [] = array ( $data [ 'html' ], $view );
$again [] = array ( $data [ 'php_view' ], $view );
2016-02-26 00:20:09 +00:00
}
}
}
}
if ( ComponentbuilderHelper :: checkArray ( $again ))
{
foreach ( $again as $go )
{
2017-12-14 23:10:47 +00:00
$this -> setTemplateAndLayoutData ( $go [ 0 ], $go [ 1 ]);
2016-02-26 00:20:09 +00:00
}
}
}
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +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-12-03 18:09:04 +00:00
public function getDataWithAlias ( $n_ame , $table , $view )
2016-02-26 00:20:09 +00:00
{
// Create a new query object.
2017-02-13 23:24:38 +00:00
$query = $this -> db -> getQuery ( true );
2016-02-26 00:20:09 +00:00
$query -> select ( 'a.*' );
2017-12-14 23:10:47 +00:00
$query -> from ( '#__componentbuilder_' . $table . ' AS a' );
2017-02-13 23:24:38 +00:00
$this -> db -> setQuery ( $query );
$rows = $this -> db -> loadObjectList ();
2016-02-26 00:20:09 +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 = '' ;
2017-03-27 12:38:51 +00:00
if ( $row -> add_php_view == 1 && ComponentbuilderHelper :: checkString ( $row -> php_view ))
2016-02-26 00:20:09 +00:00
{
2019-07-28 21:48:42 +00:00
$php_view = $this -> setGuiCodePlaceholder (
$this -> setDynamicValues ( base64_decode ( $row -> php_view )),
array (
'table' => $table ,
'field' => 'php_view' ,
'id' => ( int ) $row -> id ,
'type' => 'php' )
);
2016-02-26 00:20:09 +00:00
}
2019-07-28 21:48:42 +00:00
$contnent = $this -> setGuiCodePlaceholder (
$this -> setDynamicValues ( base64_decode ( $row -> { $table })),
array (
'table' => $table ,
'field' => $table ,
'id' => ( int ) $row -> id ,
'type' => 'html' )
);
2017-12-10 19:17:26 +00:00
// load the library
if ( ! isset ( $this -> libManager [ $this -> target ]))
{
$this -> libManager [ $this -> target ] = array ();
}
if ( ! isset ( $this -> libManager [ $this -> target ][ $view ]))
{
$this -> libManager [ $this -> target ][ $view ] = array ();
}
// make sure json become array
if ( ComponentbuilderHelper :: checkJson ( $row -> libraries ))
{
$row -> libraries = json_decode ( $row -> libraries , true );
}
// if we have an array add it
if ( ComponentbuilderHelper :: checkArray ( $row -> libraries ))
{
foreach ( $row -> libraries as $library )
{
if ( ! isset ( $this -> libManager [ $this -> target ][ $view ][ $library ]))
{
2019-10-16 20:34:36 +00:00
if ( $this -> getMediaLibrary (( int ) $library ))
2017-12-10 19:17:26 +00:00
{
$this -> libManager [ $this -> target ][ $view ][( int ) $library ] = true ;
}
}
}
}
elseif ( is_numeric ( $row -> libraries ) && ! isset ( $this -> libManager [ $this -> target ][ $view ][( int ) $row -> libraries ]))
{
2019-10-16 20:34:36 +00:00
if ( $this -> getMediaLibrary (( int ) $row -> libraries ))
2017-12-10 19:17:26 +00:00
{
$this -> libManager [ $this -> target ][ $view ][( int ) $row -> libraries ] = true ;
}
}
// load UIKIT if needed
2017-11-11 04:33:51 +00:00
if ( 2 == $this -> uikit || 1 == $this -> uikit )
{
2017-12-12 22:17:02 +00:00
if ( ! isset ( $this -> uikitComp [ $view ]))
{
$this -> uikitComp [ $view ] = array ();
}
2017-11-11 04:33:51 +00:00
// set uikit to views
2017-12-14 23:10:47 +00:00
$this -> uikitComp [ $view ] = ComponentbuilderHelper :: getUikitComp ( $contnent , $this -> uikitComp [ $view ]);
2017-11-11 04:33:51 +00:00
}
2016-02-26 00:20:09 +00:00
// set footable to views and turn it on
if ( ! isset ( $this -> footableScripts [ $this -> target ][ $view ]) || ! $this -> footableScripts [ $this -> target ][ $view ])
{
$foundFoo = $this -> getFootableScripts ( $contnent );
if ( $foundFoo )
{
$this -> footableScripts [ $this -> target ][ $view ] = true ;
}
if ( $foundFoo && ! $this -> footable )
{
$this -> footable = true ;
}
}
// set google charts to views and turn it on
if ( ! isset ( $this -> googleChart [ $this -> target ][ $view ]) || ! $this -> googleChart [ $this -> target ][ $view ])
{
$foundA = $this -> getGoogleChart ( $php_view );
$foundB = $this -> getGoogleChart ( $contnent );
if ( $foundA || $foundB )
{
$this -> googleChart [ $this -> target ][ $view ] = true ;
}
if ( $foundA || $foundB && ! $this -> googlechart )
{
$this -> googlechart = true ;
}
}
// check for get module
if ( ! isset ( $this -> getModule [ $this -> target ][ $view ]) || ! $this -> getModule [ $this -> target ][ $view ])
{
$foundA = $this -> getGetModule ( $php_view );
$foundB = $this -> getGetModule ( $contnent );
if ( $foundA || $foundB )
{
$this -> getModule [ $this -> target ][ $view ] = true ;
}
}
2019-07-28 21:48:42 +00:00
return array (
'id' => $row -> id ,
'html' => $this -> setGuiCodePlaceholder (
$contnent ,
array (
'table' => $table ,
'field' => $table ,
'id' => $row -> id ,
'type' => 'html'
)
),
'php_view' => $this -> setGuiCodePlaceholder (
$php_view ,
array (
'table' => $table ,
'field' => 'php_view' ,
'id' => $row -> id ,
'type' => 'php'
)
)
);
2016-02-26 00:20:09 +00:00
}
}
return false ;
}
2017-12-14 23:10:47 +00:00
2017-12-03 18:09:04 +00:00
/**
2019-10-16 20:34:36 +00:00
* Get Media Library Data and store globally
2017-12-03 18:09:04 +00:00
*
* @ param string $id the library id
*
* @ return bool true on success
*
*/
2019-10-16 20:34:36 +00:00
protected function getMediaLibrary ( $id )
2017-12-03 18:09:04 +00:00
{
2017-12-14 23:10:47 +00:00
2017-12-10 19:17:26 +00:00
// check if the lib has already been set
if ( ! isset ( $this -> libraries [ $id ]))
{
2019-12-06 05:31:32 +00:00
// make sure we should continue and that the lib is not already being loaded
2017-12-10 19:17:26 +00:00
switch ( $id )
{
case 1 : // No Library
return false ;
2017-12-14 23:10:47 +00:00
break ;
2017-12-10 19:17:26 +00:00
case 3 : // Uikit v3
if ( 2 == $this -> uikit || 3 == $this -> uikit )
{
// already being loaded
$this -> libraries [ $id ] = false ;
}
2017-12-14 23:10:47 +00:00
break ;
2017-12-10 19:17:26 +00:00
case 4 : // Uikit v2
if ( 2 == $this -> uikit || 1 == $this -> uikit )
{
// already being loaded
$this -> libraries [ $id ] = false ;
}
2017-12-14 23:10:47 +00:00
break ;
2017-12-10 19:17:26 +00:00
case 5 : // FooTable v2
if ( ! isset ( $this -> footableVersion ) || 2 == $this -> footableVersion )
{
// already being loaded
$this -> libraries [ $id ] = false ;
}
2017-12-14 23:10:47 +00:00
break ;
2017-12-10 19:17:26 +00:00
case 6 : // FooTable v3
if ( 3 == $this -> footableVersion )
{
// already being loaded
$this -> libraries [ $id ] = false ;
}
2017-12-14 23:10:47 +00:00
break ;
2017-12-10 19:17:26 +00:00
}
}
2017-12-03 18:09:04 +00:00
// check if the lib has already been set
if ( ! isset ( $this -> libraries [ $id ]))
{
$query = $this -> db -> getQuery ( true );
$query -> select ( 'a.*' );
$query -> select (
$this -> db -> quoteName (
array (
2017-12-14 23:10:47 +00:00
'a.id' ,
'a.name' ,
'a.how' ,
'a.type' ,
'a.addconditions' ,
'b.addconfig' ,
'c.addfiles' ,
'c.addfolders' ,
2018-02-16 21:53:43 +00:00
'c.addfilesfullpath' ,
'c.addfoldersfullpath' ,
2017-12-14 23:10:47 +00:00
'c.addurls' ,
'a.php_setdocument'
), array (
'id' ,
'name' ,
'how' ,
'type' ,
'addconditions' ,
'addconfig' ,
'addfiles' ,
'addfolders' ,
2018-02-16 21:53:43 +00:00
'addfilesfullpath' ,
'addfoldersfullpath' ,
2017-12-14 23:10:47 +00:00
'addurls' ,
'php_setdocument'
2017-12-03 18:09:04 +00:00
)
2017-12-14 23:10:47 +00:00
)
);
2017-12-03 18:09:04 +00:00
// from these tables
$query -> from ( '#__componentbuilder_library AS a' );
$query -> join ( 'LEFT' , $this -> db -> quoteName ( '#__componentbuilder_library_config' , 'b' ) . ' ON (' . $this -> db -> quoteName ( 'a.id' ) . ' = ' . $this -> db -> quoteName ( 'b.library' ) . ')' );
$query -> join ( 'LEFT' , $this -> db -> quoteName ( '#__componentbuilder_library_files_folders_urls' , 'c' ) . ' ON (' . $this -> db -> quoteName ( 'a.id' ) . ' = ' . $this -> db -> quoteName ( 'c.library' ) . ')' );
2017-12-14 23:10:47 +00:00
$query -> where ( $this -> db -> quoteName ( 'a.id' ) . ' = ' . ( int ) $id );
2019-10-16 20:34:36 +00:00
$query -> where ( $this -> db -> quoteName ( 'a.target' ) . ' = 1' );
2017-12-03 18:09:04 +00:00
// Reset the query using our newly populated query object.
$this -> db -> setQuery ( $query );
// Load the results as a list of stdClass objects
$library = $this -> db -> loadObject ();
2017-12-14 23:10:47 +00:00
2017-12-10 19:17:26 +00:00
// check if this lib uses build-in behaviour
if ( $library -> how == 4 )
{
// fall back on build-in features
$buildin = array ( 3 => array ( 'uikit' => 3 ), 4 => array ( 'uikit' => 1 ), 5 => array ( 'footableVersion' => 2 , 'footable' => true ), 6 => array ( 'footableVersion' => 3 , 'footable' => true ));
if ( isset ( $buildin [ $library -> id ]) && ComponentbuilderHelper :: checkArray ( $buildin [ $library -> id ]))
{
// set the lib switch
foreach ( $buildin [ $library -> id ] as $lib => $val )
{
$this -> { $lib } = $val ;
}
// since we are falling back on build-in feature
$library -> how = 0 ;
}
else
{
// since we did not find build in behaviour we must load always.
$library -> how = 1 ;
}
}
2017-12-03 18:09:04 +00:00
// check if this lib has dynamic behaviour
if ( $library -> how > 0 )
{
2018-02-16 21:53:43 +00:00
// set the add targets
$addArray = array ( 'files' => 'files' , 'folders' => 'folders' , 'urls' => 'urls' , 'filesfullpath' => 'files' , 'foldersfullpath' => 'folders' );
foreach ( $addArray as $addTarget => $targetHere )
2017-12-03 18:09:04 +00:00
{
2018-02-16 21:53:43 +00:00
// set the add target data
2018-03-18 04:52:07 +00:00
$library -> { 'add' . $addTarget } = ( isset ( $library -> { 'add' . $addTarget }) && ComponentbuilderHelper :: checkJson ( $library -> { 'add' . $addTarget })) ? json_decode ( $library -> { 'add' . $addTarget }, true ) : null ;
if ( ComponentbuilderHelper :: checkArray ( $library -> { 'add' . $addTarget }))
2018-02-16 21:53:43 +00:00
{
if ( isset ( $library -> { $targetHere }) && ComponentbuilderHelper :: checkArray ( $library -> { $targetHere }))
{
2018-03-18 04:52:07 +00:00
foreach ( $library -> { 'add' . $addTarget } as $taget )
2018-02-16 21:53:43 +00:00
{
$library -> { $targetHere }[] = $taget ;
}
}
else
{
2018-03-18 04:52:07 +00:00
$library -> { $targetHere } = array_values ( $library -> { 'add' . $addTarget });
2018-02-16 21:53:43 +00:00
}
}
2018-03-18 04:52:07 +00:00
unset ( $library -> { 'add' . $addTarget });
2017-12-14 23:10:47 +00:00
}
2017-12-03 18:09:04 +00:00
// add config fields only if needed
if ( $library -> how > 1 )
{
// set the config data
2017-12-14 23:10:47 +00:00
$library -> addconfig = ( isset ( $library -> addconfig ) && ComponentbuilderHelper :: checkJson ( $library -> addconfig )) ? json_decode ( $library -> addconfig , true ) : null ;
2017-12-03 18:09:04 +00:00
if ( ComponentbuilderHelper :: checkArray ( $library -> addconfig ))
{
2017-12-14 23:10:47 +00:00
$library -> config = array_map ( function ( $array )
{
2017-12-03 18:09:04 +00:00
$array [ 'alias' ] = 0 ;
$array [ 'title' ] = 0 ;
$array [ 'settings' ] = $this -> getFieldData ( $array [ 'field' ]);
return $array ;
}, array_values ( $library -> addconfig ));
}
}
// if this lib is controlled by custom script
if ( 3 == $library -> how )
{
// set Needed PHP
2017-12-10 19:17:26 +00:00
if ( isset ( $library -> php_setdocument ) && ComponentbuilderHelper :: checkString ( $library -> php_setdocument ))
2017-12-03 18:09:04 +00:00
{
2019-07-28 21:48:42 +00:00
$library -> document = $this -> setGuiCodePlaceholder (
$this -> setDynamicValues ( base64_decode ( $library -> php_setdocument )),
array (
'table' => 'library' ,
'field' => 'php_setdocument' ,
'id' => ( int ) $id ,
'type' => 'php' )
);
2017-12-03 18:09:04 +00:00
}
}
// if this lib is controlled by conditions
elseif ( 2 == $library -> how )
{
// set the addconditions data
2017-12-14 23:10:47 +00:00
$library -> addconditions = ( isset ( $library -> addconditions ) && ComponentbuilderHelper :: checkJson ( $library -> addconditions )) ? json_decode ( $library -> addconditions , true ) : null ;
2017-12-03 18:09:04 +00:00
if ( ComponentbuilderHelper :: checkArray ( $library -> addconditions ))
{
$library -> conditions = array_values ( $library -> addconditions );
}
}
unset ( $library -> php_setdocument );
unset ( $library -> addconditions );
2017-12-10 19:17:26 +00:00
unset ( $library -> addconfig );
// load to global lib
$this -> libraries [ $id ] = $library ;
2017-12-03 18:09:04 +00:00
}
else
{
$this -> libraries [ $id ] = false ;
}
}
// if set return
if ( isset ( $this -> libraries [ $id ]))
{
return $this -> libraries [ $id ];
}
return false ;
}
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2017-02-13 23:24:38 +00:00
* Set Language Place Holders
2018-04-08 06:12:18 +00:00
*
2016-02-26 00:20:09 +00:00
* @ param string $content The content
*
* @ return string The content with the updated Language place holder
2018-04-08 06:12:18 +00:00
*
2016-02-26 00:20:09 +00:00
*/
2017-02-13 23:24:38 +00:00
public function setLangStrings ( $content )
2016-02-26 00:20:09 +00:00
{
2017-12-14 13:30:21 +00:00
// get targets to search for
$langStringTargets = array_filter (
2017-12-14 23:10:47 +00:00
$this -> langStringTargets , function ( $get ) use ( $content )
{
if ( strpos ( $content , $get ) !== false )
{
return true ;
}
return false ;
});
2017-12-14 13:30:21 +00:00
// check if we should continue
if ( ComponentbuilderHelper :: checkArray ( $langStringTargets ))
2017-02-13 23:24:38 +00:00
{
2019-08-28 13:07:18 +00:00
// insure string is not broken
2019-08-28 11:48:07 +00:00
$content = $this -> setPlaceholders ( $content , $this -> placeholders );
2018-04-08 06:12:18 +00:00
// reset some buckets
$langHolders = array ();
$langCheck = array ();
$langOnly = array ();
$jsTEXT = array ();
$scTEXT = array ();
// first get the Joomla .JText._()
2018-03-18 04:52:07 +00:00
if ( in_array ( 'Joomla' . '.JText._(' , $langStringTargets ))
2017-12-14 13:30:21 +00:00
{
2018-03-18 04:52:07 +00:00
$jsTEXT [] = ComponentbuilderHelper :: getAllBetween ( $content , " Joomla " . " .JText._(' " , " ' " );
2018-04-08 06:12:18 +00:00
$jsTEXT [] = ComponentbuilderHelper :: getAllBetween ( $content , 'Joomla' . '.JText._("' , '"' );
2017-12-14 13:30:21 +00:00
// combine into one array
$jsTEXT = ComponentbuilderHelper :: mergeArrays ( $jsTEXT );
// we need to add a check to insure these JavaScript lang matchup
if ( ComponentbuilderHelper :: checkArray ( $jsTEXT )) //<-- not really needed hmmm
{
// load the JS text to mismatch array
$langCheck [] = $jsTEXT ;
$this -> langMismatch = ComponentbuilderHelper :: mergeArrays ( array ( $jsTEXT , $this -> langMismatch ));
}
}
2018-02-06 10:55:46 +00:00
// now get the JText: :script()
2018-03-18 04:52:07 +00:00
if ( in_array ( 'JText:' . ':script(' , $langStringTargets ))
2017-12-14 13:30:21 +00:00
{
2018-03-18 04:52:07 +00:00
$scTEXT [] = ComponentbuilderHelper :: getAllBetween ( $content , " JText: " . " :script(' " , " ' " );
$scTEXT [] = ComponentbuilderHelper :: getAllBetween ( $content , 'JText:' . ':script("' , '"' );
2017-12-14 13:30:21 +00:00
// combine into one array
$scTEXT = ComponentbuilderHelper :: mergeArrays ( $scTEXT );
// we need to add a check to insure these JavaScript lang matchup
2019-08-28 13:07:18 +00:00
if ( ComponentbuilderHelper :: checkArray ( $scTEXT ))
2017-12-14 13:30:21 +00:00
{
// load the Script text to match array
$langCheck [] = $scTEXT ;
$this -> langMatch = ComponentbuilderHelper :: mergeArrays ( array ( $scTEXT , $this -> langMatch ));
}
}
2018-04-08 06:12:18 +00:00
// now do the little trick for JustTEXT: :_('Just uppercase text');
if ( in_array ( 'JustTEXT:' . ':_(' , $langStringTargets ))
{
$langOnly [] = ComponentbuilderHelper :: getAllBetween ( $content , " JustTEXT: " . " :_(' " , " ') " );
$langOnly [] = ComponentbuilderHelper :: getAllBetween ( $content , 'JustTEXT:' . ':_("' , '")' );
2018-08-02 05:36:47 +00:00
// merge lang only
$langOnly = ComponentbuilderHelper :: mergeArrays ( $langOnly );
2018-04-08 06:12:18 +00:00
}
2017-02-13 23:24:38 +00:00
// set language data
2017-12-14 23:10:47 +00:00
foreach ( $langStringTargets as $langStringTarget )
2017-12-14 13:30:21 +00:00
{
// need some special treatment here
2018-04-08 06:12:18 +00:00
if ( $langStringTarget === 'Joomla' . '.JText._(' ||
$langStringTarget === 'JText:' . ':script(' ||
$langStringTarget === 'JustTEXT:' . ':_(' )
2017-12-14 13:30:21 +00:00
{
continue ;
}
2017-12-14 23:10:47 +00:00
$langCheck [] = ComponentbuilderHelper :: getAllBetween ( $content , $langStringTarget . " ' " , " ' " );
$langCheck [] = ComponentbuilderHelper :: getAllBetween ( $content , $langStringTarget . '"' , '"' );
2017-12-14 13:30:21 +00:00
}
2018-04-08 06:12:18 +00:00
// the normal loading of the language strings
$langCheck = ComponentbuilderHelper :: mergeArrays ( $langCheck );
if ( ComponentbuilderHelper :: checkArray ( $langCheck )) //<-- not really needed hmmm
2016-02-26 00:20:09 +00:00
{
2018-04-08 06:12:18 +00:00
foreach ( $langCheck as $string )
2016-02-26 00:20:09 +00:00
{
2018-04-08 06:12:18 +00:00
if ( $keyLang = $this -> setLang ( $string ))
2017-02-13 23:24:38 +00:00
{
2018-04-08 06:12:18 +00:00
// load the language targets
foreach ( $langStringTargets as $langStringTarget )
{
2018-08-02 05:36:47 +00:00
// need some special treatment here
if ( $langStringTarget === 'JustTEXT:' . ':_(' )
{
continue ;
}
2018-04-08 06:12:18 +00:00
$langHolders [ $langStringTarget . " ' " . $string . " ' " ] = $langStringTarget . " ' " . $keyLang . " ' " ;
$langHolders [ $langStringTarget . '"' . $string . '"' ] = $langStringTarget . '"' . $keyLang . '"' ;
}
2017-12-14 13:30:21 +00:00
}
2016-02-26 00:20:09 +00:00
}
2018-04-08 06:12:18 +00:00
}
// the uppercase loading only (for arrays and other tricks)
if ( ComponentbuilderHelper :: checkArray ( $langOnly ))
{
foreach ( $langOnly as $string )
2017-03-08 04:49:54 +00:00
{
2018-04-08 06:12:18 +00:00
if ( $keyLang = $this -> setLang ( $string ))
{
// load the language targets
$langHolders [ " JustTEXT: " . " :_(' " . $string . " ') " ] = " ' " . $keyLang . " ' " ;
$langHolders [ 'JustTEXT:' . ':_("' . $string . '")' ] = '"' . $keyLang . '"' ;
}
2017-03-08 04:49:54 +00:00
}
2016-02-26 00:20:09 +00:00
}
2018-04-08 06:12:18 +00:00
// only continue if we have value to replace
if ( ComponentbuilderHelper :: checkArray ( $langHolders ))
{
$content = $this -> setPlaceholders ( $content , $langHolders );
}
2016-02-26 00:20:09 +00:00
}
return $content ;
}
2017-12-14 23:10:47 +00:00
2018-04-08 06:12:18 +00:00
/**
* Set the language String
*
* @ param string $string The plan text string ( English )
*
* @ return string The key language string ( all uppercase )
*
*/
public function setLang ( $string )
{
// this is there to insure we dont break already added Language strings
if ( ComponentbuilderHelper :: safeString ( $string , 'U' ) === $string )
{
return false ;
}
2019-07-04 23:53:54 +00:00
// build lang key
2018-04-08 06:12:18 +00:00
$keyLang = $this -> langPrefix . '_' . ComponentbuilderHelper :: safeString ( $string , 'U' );
2019-07-04 23:53:54 +00:00
// set the language string
$this -> setLangContent ( $this -> lang , $keyLang , $string );
2018-04-08 06:12:18 +00:00
return $keyLang ;
}
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* Set Data Selection of the dynamic get
*
2016-03-01 18:44:13 +00:00
* @ param string $method_key The method unique key
* @ param string $view_code The code name of the view
* @ param string $string The data string
2018-07-21 07:10:37 +00:00
* @ param string $asset The asset in question
2016-03-01 18:44:13 +00:00
* @ param string $as The as string
* @ param int $row_type The row type
* @ param string $type The target type ( db || view )
2016-02-26 00:20:09 +00:00
*
* @ return array the select query
*
*/
2017-10-06 14:53:22 +00:00
public function setDataSelection ( $method_key , $view_code , $string , $asset , $as , $row_type , $type )
2016-02-26 00:20:09 +00:00
{
if ( ComponentbuilderHelper :: checkString ( $string ))
{
2019-01-29 14:43:27 +00:00
if ( 'db' === $type )
2016-02-26 00:20:09 +00:00
{
2019-01-29 14:43:27 +00:00
$table = '#__' . $asset ;
$queryName = $asset ;
$view = '' ;
}
elseif ( 'view' === $type )
{
$view = $this -> getViewTableName ( $asset );
$table = '#__' . $this -> componentCodeName . '_' . $view ;
$queryName = $view ;
}
// just get all values from table if * is found
if ( $string === '*' || strpos ( $string , '*' ) !== false )
{
if ( $type == 'view' )
2016-02-26 00:20:09 +00:00
{
2019-01-29 14:43:27 +00:00
$_string = ComponentbuilderHelper :: getViewTableColumns ( $asset , $as , $row_type );
2016-02-26 00:20:09 +00:00
}
2019-01-29 14:43:27 +00:00
else
2016-02-26 00:20:09 +00:00
{
2019-01-29 14:43:27 +00:00
$_string = ComponentbuilderHelper :: getDbTableColumns ( $asset , $as , $row_type );
2016-02-26 00:20:09 +00:00
}
2019-01-29 14:43:27 +00:00
// get only selected values
$lines = explode ( PHP_EOL , $_string );
// make sure to set the string to *
$string = '*' ;
}
else
{
// get only selected values
$lines = explode ( PHP_EOL , $string );
}
// only continue if lines are available
if ( ComponentbuilderHelper :: checkArray ( $lines ))
{
2016-02-26 00:20:09 +00:00
$gets = array ();
$keys = array ();
2017-11-16 04:37:32 +00:00
// first load all options
2016-02-26 00:20:09 +00:00
foreach ( $lines as $line )
{
2017-12-14 23:10:47 +00:00
if ( strpos ( $line , 'AS' ) !== false )
2016-02-26 00:20:09 +00:00
{
2018-07-21 07:10:37 +00:00
$lineArray = explode ( " AS " , $line );
2016-02-26 00:20:09 +00:00
}
2017-12-14 23:10:47 +00:00
elseif ( strpos ( $line , 'as' ) !== false )
2016-02-26 00:20:09 +00:00
{
2018-07-21 07:10:37 +00:00
$lineArray = explode ( " as " , $line );
2016-02-26 00:20:09 +00:00
}
else
{
2018-07-21 07:10:37 +00:00
$lineArray = array ( $line , null );
2016-02-26 00:20:09 +00:00
}
2017-11-16 04:37:32 +00:00
// set the get and key
2018-07-21 07:10:37 +00:00
$get = trim ( $lineArray [ 0 ]);
$key = trim ( $lineArray [ 1 ]);
2017-11-16 04:37:32 +00:00
// only add the view (we must adapt this)
2017-12-14 23:10:47 +00:00
if ( isset ( $this -> getAsLookup [ $method_key ][ $get ]) && 'a' != $as && 1 == $row_type && 'view' === $type && strpos ( '#' . $key , '#' . $view . '_' ) === false )
2016-02-26 00:20:09 +00:00
{
2017-11-16 04:37:32 +00:00
// this is a problem (TODO) since we may want to not add the view name.
2017-12-14 23:10:47 +00:00
$key = $view . '_' . trim ( $key );
2016-02-26 00:20:09 +00:00
}
2017-11-16 04:37:32 +00:00
// continue only if we have get
2016-02-26 00:20:09 +00:00
if ( ComponentbuilderHelper :: checkString ( $get ))
{
2017-02-13 23:24:38 +00:00
$gets [] = $this -> db -> quote ( $get );
2016-02-26 00:20:09 +00:00
if ( ComponentbuilderHelper :: checkString ( $key ))
{
$this -> getAsLookup [ $method_key ][ $get ] = $key ;
2017-02-13 23:24:38 +00:00
$keys [] = $this -> db -> quote ( $key );
2016-02-26 00:20:09 +00:00
}
else
{
2017-12-14 23:10:47 +00:00
$key = str_replace ( $as . '.' , '' , $get );
2016-02-26 00:20:09 +00:00
$this -> getAsLookup [ $method_key ][ $get ] = $key ;
2017-02-13 23:24:38 +00:00
$keys [] = $this -> db -> quote ( $key );
2016-02-26 00:20:09 +00:00
}
2018-07-21 07:10:37 +00:00
// make sure we have the view name
2016-02-26 00:20:09 +00:00
if ( ComponentbuilderHelper :: checkString ( $view ))
{
2018-07-21 07:10:37 +00:00
// prep the field name
2017-12-14 23:10:47 +00:00
$field = str_replace ( $as . '.' , '' , $get );
2018-07-21 07:10:37 +00:00
// make sure the array is set
if ( ! isset ( $this -> siteFields [ $view ][ $field ]))
{
$this -> siteFields [ $view ][ $field ] = array ();
}
// load to the site fields memory bucket
$this -> siteFields [ $view ][ $field ][ $method_key . '___' . $as ] = array ( 'site' => $view_code , 'get' => $get , 'as' => $as , 'key' => $key );
2016-02-26 00:20:09 +00:00
}
}
}
if ( ComponentbuilderHelper :: checkArray ( $gets ) && ComponentbuilderHelper :: checkArray ( $keys ))
{
2019-01-29 14:43:27 +00:00
// single joined selection needs the prefix to the values to avoid conflict in the names
2019-12-16 03:02:16 +00:00
// so we must still add then AS
2019-01-29 14:43:27 +00:00
if ( $string == '*' && 1 != $row_type )
{
$querySelect = " \$ query->select(' " . $as . " .*'); " ;
}
else
{
$querySelect = '$query->select($db->quoteName(' . PHP_EOL . $this -> _t ( 3 ) . 'array(' . implode ( ',' , $gets ) . '),' . PHP_EOL . $this -> _t ( 3 ) . 'array(' . implode ( ',' , $keys ) . ')));' ;
}
2017-12-14 23:10:47 +00:00
$queryFrom = '$db->quoteName(' . $this -> db -> quote ( $table ) . ', ' . $this -> db -> quote ( $as ) . ')' ;
2016-02-26 00:20:09 +00:00
// return the select query
return array ( 'select' => $querySelect , 'from' => $queryFrom , 'name' => $queryName , 'table' => $table , 'type' => $type , 'select_gets' => $gets , 'select_keys' => $keys );
}
}
}
return false ;
}
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* Get the View Table Name
*
* @ param int $id The admin view in
*
* @ return string view code name
*
*/
public function getViewTableName ( $id )
{
// Create a new query object.
2017-02-13 23:24:38 +00:00
$query = $this -> db -> getQuery ( true );
$query -> select ( $this -> db -> quoteName ( array ( 'a.name_single' )));
2017-12-14 23:10:47 +00:00
$query -> from ( $this -> db -> quoteName ( '#__componentbuilder_admin_view' , 'a' ));
$query -> where ( $this -> db -> quoteName ( 'a.id' ) . ' = ' . ( int ) $id );
2017-02-13 23:24:38 +00:00
$this -> db -> setQuery ( $query );
return ComponentbuilderHelper :: safeString ( $this -> db -> loadResult ());
2016-02-26 00:20:09 +00:00
}
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* Build the SQL dump String for a view
*
* @ param string $tables The tables to use in build
* @ param string $view The target view / table to dump in
2016-03-01 18:44:13 +00:00
* @ param int $view_id The id of the target view
2016-02-26 00:20:09 +00:00
*
* @ return string on success with the Dump SQL
*
*/
2017-10-12 00:50:14 +00:00
public function buildSqlDump ( $tables , $view , $view_id )
2016-02-26 00:20:09 +00:00
{
// first build a query statment to get all the data (insure it must be added - check the tweaking)
if ( ComponentbuilderHelper :: checkArray ( $tables ) && ( ! isset ( $this -> sqlTweak [ $view_id ][ 'remove' ]) || ! $this -> sqlTweak [ $view_id ][ 'remove' ]))
{
$counter = 'a' ;
// Create a new query object.
2017-02-13 23:24:38 +00:00
$query = $this -> db -> getQuery ( true );
2018-10-29 16:38:00 +00:00
// switch to onlu trigger the run of the query if we have tables to query
$runQuery = false ;
2016-02-26 00:20:09 +00:00
foreach ( $tables as $table )
{
2018-10-29 16:38:00 +00:00
if ( isset ( $table [ 'table' ]))
2016-02-26 00:20:09 +00:00
{
2018-10-29 16:38:00 +00:00
if ( $counter === 'a' )
2016-02-26 00:20:09 +00:00
{
2018-10-29 16:38:00 +00:00
// the main table fields
if ( strpos ( $table [ 'sourcemap' ], PHP_EOL ) !== false )
2016-02-26 00:20:09 +00:00
{
2018-10-29 16:38:00 +00:00
$fields = explode ( PHP_EOL , $table [ 'sourcemap' ]);
if ( ComponentbuilderHelper :: checkArray ( $fields ))
2016-02-26 00:20:09 +00:00
{
2018-10-29 16:38:00 +00:00
// reset array buckets
$sourceArray = array ();
$targetArray = array ();
foreach ( $fields as $field )
2016-02-26 00:20:09 +00:00
{
2018-10-29 16:38:00 +00:00
if ( strpos ( $field , " => " ) !== false )
{
list ( $source , $target ) = explode ( " => " , $field );
$sourceArray [] = $counter . '.' . trim ( $source );
$targetArray [] = trim ( $target );
}
}
if ( ComponentbuilderHelper :: checkArray ( $sourceArray ) && ComponentbuilderHelper :: checkArray ( $targetArray ))
{
// add to query
$query -> select ( $this -> db -> quoteName ( $sourceArray , $targetArray ));
$query -> from ( '#__' . $table [ 'table' ] . ' AS a' );
$runQuery = true ;
}
// we may need to filter the selection
if ( isset ( $this -> sqlTweak [ $view_id ][ 'where' ]))
{
// add to query the where filter
$query -> where ( 'a.id IN (' . $this -> sqlTweak [ $view_id ][ 'where' ] . ')' );
2016-02-26 00:20:09 +00:00
}
}
}
}
2018-10-29 16:38:00 +00:00
else
2016-02-26 00:20:09 +00:00
{
2018-10-29 16:38:00 +00:00
// the other tables
if ( strpos ( $table [ 'sourcemap' ], PHP_EOL ) !== false )
2016-02-26 00:20:09 +00:00
{
2018-10-29 16:38:00 +00:00
$fields = explode ( PHP_EOL , $table [ 'sourcemap' ]);
if ( ComponentbuilderHelper :: checkArray ( $fields ))
2016-02-26 00:20:09 +00:00
{
2018-10-29 16:38:00 +00:00
// reset array buckets
$sourceArray = array ();
$targetArray = array ();
foreach ( $fields as $field )
2016-02-26 00:20:09 +00:00
{
2018-10-29 16:38:00 +00:00
if ( strpos ( $field , " => " ) !== false )
{
list ( $source , $target ) = explode ( " => " , $field );
$sourceArray [] = $counter . '.' . trim ( $source );
$targetArray [] = trim ( $target );
}
if ( strpos ( $field , " == " ) !== false )
{
list ( $aKey , $bKey ) = explode ( " == " , $field );
// add to query
$query -> join ( 'LEFT' , $this -> db -> quoteName ( '#__' . $table [ 'table' ], $counter ) . ' ON (' . $this -> db -> quoteName ( 'a.' . trim ( $aKey )) . ' = ' . $this -> db -> quoteName ( $counter . '.' . trim ( $bKey )) . ')' );
}
2016-02-26 00:20:09 +00:00
}
2018-10-29 16:38:00 +00:00
if ( ComponentbuilderHelper :: checkArray ( $sourceArray ) && ComponentbuilderHelper :: checkArray ( $targetArray ))
2016-02-26 00:20:09 +00:00
{
// add to query
2018-10-29 16:38:00 +00:00
$query -> select ( $this -> db -> quoteName ( $sourceArray , $targetArray ));
2016-02-26 00:20:09 +00:00
}
}
}
}
2018-10-29 16:38:00 +00:00
$counter ++ ;
}
else
{
// see where
// var_dump($view);
// jexit();
2016-02-26 00:20:09 +00:00
}
}
2018-10-29 16:38:00 +00:00
// check if we should run query
if ( $runQuery )
2016-02-26 00:20:09 +00:00
{
2018-10-29 16:38:00 +00:00
// now get the data
$this -> db -> setQuery ( $query );
$this -> db -> execute ();
if ( $this -> db -> getNumRows ())
2016-02-26 00:20:09 +00:00
{
2018-10-29 16:38:00 +00:00
// get the data
$data = $this -> db -> loadObjectList ();
// start building the MySql dump
$dump = " -- " ;
$dump .= PHP_EOL . " -- Dumping data for table `#__ " . $this -> bbb . " component " . $this -> ddd . " _ " . $view . " ` " ;
$dump .= PHP_EOL . " -- " ;
$dump .= PHP_EOL . PHP_EOL . " INSERT INTO `#__ " . $this -> bbb . " component " . $this -> ddd . " _ " . $view . " ` ( " ;
foreach ( $data as $line )
2016-02-26 00:20:09 +00:00
{
2018-10-29 16:38:00 +00:00
$comaSet = 0 ;
foreach ( $line as $fieldName => $fieldValue )
2016-02-26 00:20:09 +00:00
{
2018-10-29 16:38:00 +00:00
if ( $comaSet == 0 )
{
$dump .= $this -> db -> quoteName ( $fieldName );
}
else
{
$dump .= " , " . $this -> db -> quoteName ( $fieldName );
}
$comaSet ++ ;
2016-02-26 00:20:09 +00:00
}
2018-10-29 16:38:00 +00:00
break ;
2016-02-26 00:20:09 +00:00
}
2018-10-29 16:38:00 +00:00
$dump .= " ) VALUES " ;
$coma = 0 ;
foreach ( $data as $line )
2016-02-26 00:20:09 +00:00
{
2018-10-29 16:38:00 +00:00
if ( $coma == 0 )
2016-02-26 00:20:09 +00:00
{
2018-10-29 16:38:00 +00:00
$dump .= PHP_EOL . " ( " ;
2016-02-26 00:20:09 +00:00
}
else
{
2018-10-29 16:38:00 +00:00
$dump .= " , " . PHP_EOL . " ( " ;
}
$comaSet = 0 ;
foreach ( $line as $fieldName => $fieldValue )
{
if ( $comaSet == 0 )
{
$dump .= $this -> mysql_escape ( $fieldValue );
}
else
{
$dump .= " , " . $this -> mysql_escape ( $fieldValue );
}
$comaSet ++ ;
2016-02-26 00:20:09 +00:00
}
2018-10-29 16:38:00 +00:00
$dump .= " ) " ;
$coma ++ ;
2016-02-26 00:20:09 +00:00
}
2018-10-29 16:38:00 +00:00
$dump .= " ; " ;
// return build dump query
return $dump ;
2016-02-26 00:20:09 +00:00
}
}
}
return false ;
}
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* Escape the values for a SQL dump
*
* @ param string $value the value to escape
*
* @ return string on success with escaped string
*
*/
public function mysql_escape ( $value )
{
// if array then return maped
2017-12-14 23:10:47 +00:00
if ( ComponentbuilderHelper :: checkArray ( $value ))
2016-02-26 00:20:09 +00:00
{
return array_map ( __METHOD__ , $value );
}
// if string make sure it is correctly escaped
2017-12-14 23:10:47 +00:00
if ( ComponentbuilderHelper :: checkString ( $value ) && ! is_numeric ( $value ))
2016-02-26 00:20:09 +00:00
{
2017-02-13 23:24:38 +00:00
return $this -> db -> quote ( $value );
2016-02-26 00:20:09 +00:00
}
// if empty value return place holder
2017-12-14 23:10:47 +00:00
if ( empty ( $value ))
2016-02-26 00:20:09 +00:00
{
return " '' " ;
}
// if not array or string then return number
return $value ;
}
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* Creating an uniqueCode
*
* @ param string $code The planed code
*
* @ return string The unique code
*
*/
public function uniqueCode ( $code )
{
2017-12-14 23:10:47 +00:00
if ( ! isset ( $this -> uniquecodes [ $this -> target ]) || ! in_array ( $code , $this -> uniquecodes [ $this -> target ]))
2016-02-26 00:20:09 +00:00
{
2016-02-26 13:57:30 +00:00
$this -> uniquecodes [ $this -> target ][] = $code ;
2016-02-26 00:20:09 +00:00
return $code ;
}
// make sure it is unique
2017-12-14 23:10:47 +00:00
return $this -> uniqueCode ( $code . $this -> uniquekey ( 1 ));
2016-02-26 13:57:30 +00:00
}
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 13:57:30 +00:00
* Creating an unique local key
*
* @ param int $size The key size
*
* @ return string The unique localkey
*
*/
2016-11-22 17:08:17 +00:00
public function uniquekey ( $size , $random = false , $newBag = " vvvvvvvvvvvvvvvvvvv " )
2016-02-26 13:57:30 +00:00
{
if ( $random )
{
$bag = " abcefghijknopqrstuwxyzABCDDEFGHIJKLLMMNOPQRSTUVVWXYZabcddefghijkllmmnopqrstuvvwxyzABCEFGHIJKNOPQRSTUWXYZ " ;
}
else
{
2016-11-22 17:08:17 +00:00
$bag = $newBag ;
2016-02-26 13:57:30 +00:00
}
$key = array ();
$bagsize = strlen ( $bag ) - 1 ;
for ( $i = 0 ; $i < $size ; $i ++ )
{
$get = rand ( 0 , $bagsize );
$key [] = $bag [ $get ];
}
$key = implode ( $key );
while ( in_array ( $key , $this -> uniquekeys ))
{
$key ++ ;
}
$this -> uniquekeys [] = $key ;
return $key ;
2016-02-26 00:20:09 +00:00
}
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* Check for footable scripts
*
* @ param string $content The content to check
*
* @ return boolean True if found
*
*/
public function getFootableScripts ( $content )
{
2017-12-14 23:10:47 +00:00
if ( strpos ( $content , 'footable' ) !== false )
2016-02-26 00:20:09 +00:00
{
return true ;
}
return false ;
}
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* Check for getModules script
*
* @ param string $content The content to check
*
* @ return boolean True if found
*
*/
public function getGetModule ( $content )
{
2017-12-14 23:10:47 +00:00
if ( strpos ( $content , 'this->getModules(' ) !== false )
2016-02-26 00:20:09 +00:00
{
return true ;
}
return false ;
}
2017-12-14 23:10:47 +00:00
2016-03-04 00:01:43 +00:00
/**
2017-12-03 18:09:04 +00:00
* Check for get Google Chart script
2016-02-26 00:20:09 +00:00
*
* @ param string $content The content to check
*
* @ return boolean True if found
*
*/
public function getGoogleChart ( $content )
{
2017-12-14 23:10:47 +00:00
if ( strpos ( $content , 'Chartbuilder(' ) !== false )
2016-02-26 00:20:09 +00:00
{
return true ;
}
return false ;
}
2017-12-14 23:10:47 +00:00
2017-02-13 23:24:38 +00:00
/**
* Set the dynamic values in strings here
*
* @ param string $string The content to check
2018-08-02 05:36:47 +00:00
* @ param int $debug The switch to debug the update
* We can now at any time debug the
* dynamic build values if it gets broken
2017-02-13 23:24:38 +00:00
*
* @ return string
*
*/
2018-08-02 05:36:47 +00:00
public function setDynamicValues ( $string , $debug = 0 )
2017-02-13 23:24:38 +00:00
{
2017-03-08 04:49:54 +00:00
if ( ComponentbuilderHelper :: checkString ( $string ))
{
2018-08-02 05:36:47 +00:00
$string = $this -> setLangStrings ( $this -> setCustomCodeData ( $this -> setExternalCodeString ( $string , $debug ), $debug ));
}
// if debug
if ( $debug )
{
jexit ();
2017-03-08 04:49:54 +00:00
}
return $string ;
2017-02-13 23:24:38 +00:00
}
2018-03-18 04:52:07 +00:00
2018-01-31 13:35:54 +00:00
/**
2018-02-03 00:13:48 +00:00
* Set the external code string & load it in to string
2018-01-31 13:35:54 +00:00
*
* @ param string $string The content to check
2018-08-02 05:36:47 +00:00
* @ param int $debug The switch to debug the update
2018-01-31 13:35:54 +00:00
*
* @ return string
*
*/
2018-08-02 05:36:47 +00:00
public function setExternalCodeString ( $string , $debug = 0 )
2018-01-31 13:35:54 +00:00
{
// check if content has custom code place holder
2018-03-18 04:52:07 +00:00
if ( strpos ( $string , '[EXTERNA' . 'LCODE=' ) !== false )
2018-01-31 13:35:54 +00:00
{
2018-08-02 05:36:47 +00:00
// if debug
if ( $debug )
{
echo 'External Code String:' ;
var_dump ( $string );
}
2018-02-03 00:13:48 +00:00
// target content
2018-01-31 13:35:54 +00:00
$bucket = array ();
2018-03-18 04:52:07 +00:00
$found = ComponentbuilderHelper :: getAllBetween ( $string , '[EXTERNA' . 'LCODE=' , ']' );
2018-01-31 13:35:54 +00:00
if ( ComponentbuilderHelper :: checkArray ( $found ))
{
// build local bucket
2018-02-03 00:13:48 +00:00
foreach ( $found as $target )
2018-01-31 13:35:54 +00:00
{
2018-03-06 02:28:44 +00:00
// check if user has permission to use EXTERNAL code (we may add a custom access switch - use ADMIN for now)
if ( $this -> user -> authorise ( 'core.admin' , 'com_componentbuilder' ))
2018-01-31 13:35:54 +00:00
{
2018-03-06 02:28:44 +00:00
// check if the target is valid URL or path
2018-03-18 04:52:07 +00:00
if (( ! filter_var ( $target , FILTER_VALIDATE_URL ) === false && ComponentbuilderHelper :: urlExists ( $target )) || ( JPath :: clean ( $target ) === $target && JFile :: exists ( $target )))
2018-03-06 02:28:44 +00:00
{
$this -> getExternalCodeString ( $target , $bucket );
}
// give notice that target is not a valid url/path
else
{
// set key
2018-03-18 04:52:07 +00:00
$key = '[EXTERNA' . 'LCODE=' . $target . ']' ;
2018-03-06 02:28:44 +00:00
// set the notice
$this -> app -> enqueueMessage ( JText :: _ ( '<hr /><h3>External Code Warning</h3>' ), 'Warning' );
$this -> app -> enqueueMessage ( JText :: sprintf ( 'The <b>%s</b> is not a valid url/path!' , $key ), 'Warning' );
// remove the placeholder
$bucket [ $key ] = '' ;
}
2018-01-31 13:35:54 +00:00
}
2018-02-02 17:36:22 +00:00
else
2018-01-31 13:35:54 +00:00
{
2018-02-03 00:13:48 +00:00
// set key
2018-03-18 04:52:07 +00:00
$key = '[EXTERNA' . 'LCODE=' . $target . ']' ;
2018-02-03 00:13:48 +00:00
// set the notice
2018-09-25 20:02:48 +00:00
$this -> app -> enqueueMessage ( JText :: _ ( '<hr /><h3>External Code Error</h3>' ), 'Error' );
$this -> app -> enqueueMessage ( JText :: sprintf ( '%s, you do not have permission to use <b>EXTERNALCODE</b> feature (so <b>%s</b> was removed from the compilation), please contact you system administrator for more info!<br /><small>(admin access required)</small>' , $this -> user -> get ( 'name' ), $key ), 'Error' );
2018-02-02 17:36:22 +00:00
// remove the placeholder
2018-02-03 00:13:48 +00:00
$bucket [ $key ] = '' ;
2018-01-31 13:35:54 +00:00
}
}
// now update local string if bucket has values
if ( ComponentbuilderHelper :: checkArray ( $bucket ))
{
$string = $this -> setPlaceholders ( $string , $bucket );
}
}
2018-08-02 05:36:47 +00:00
// if debug
if ( $debug )
{
echo 'External Code String After Update:' ;
var_dump ( $string );
}
2018-01-31 13:35:54 +00:00
}
return $string ;
}
2018-03-18 04:52:07 +00:00
2018-02-02 17:36:22 +00:00
/**
2018-02-03 00:13:48 +00:00
* Get the External Code / String
2018-02-02 17:36:22 +00:00
*
* @ param string $string The content to check
* @ param array $bucket The Placeholders bucket
*
* @ return void
*
*/
2018-02-03 00:13:48 +00:00
protected function getExternalCodeString ( $target , & $bucket )
2018-02-02 17:36:22 +00:00
{
// set key
2018-03-18 04:52:07 +00:00
$key = '[EXTERNA' . 'LCODE=' . $target . ']' ;
2018-02-02 17:36:22 +00:00
// set URL key
2018-02-03 00:13:48 +00:00
$targetKey = trim ( $target );
// check if we already fetched this
if ( ! isset ( $this -> externalCodeString [ $targetKey ]))
2018-02-02 17:36:22 +00:00
{
// get the data string (code)
2018-02-03 00:13:48 +00:00
$this -> externalCodeString [ $targetKey ] = ComponentbuilderHelper :: getFileContents ( $targetKey );
2018-02-02 17:36:22 +00:00
// did we get any value
2018-02-03 00:13:48 +00:00
if ( ComponentbuilderHelper :: checkString ( $this -> externalCodeString [ $targetKey ]))
2018-02-02 17:36:22 +00:00
{
// check for changes
2018-02-03 00:13:48 +00:00
$liveHash = md5 ( $this -> externalCodeString [ $targetKey ]);
2018-02-02 17:36:22 +00:00
// check if it exist local
2018-02-03 00:13:48 +00:00
if ( $hash = ComponentbuilderHelper :: getVar ( 'external_code' , $targetKey , 'target' , 'hash' ))
2018-02-02 17:36:22 +00:00
{
if ( $hash !== $liveHash )
{
2018-02-06 10:55:46 +00:00
// update the hash since it changed
2018-02-02 17:36:22 +00:00
$object = new stdClass ();
2018-02-03 00:13:48 +00:00
$object -> target = $targetKey ;
2018-02-02 17:36:22 +00:00
$object -> hash = $liveHash ;
// update local hash
2018-02-03 00:13:48 +00:00
$this -> db -> updateObject ( '#__componentbuilder_external_code' , $object , 'target' );
2018-02-02 17:36:22 +00:00
// give notice of the change
2018-03-05 00:13:42 +00:00
$this -> app -> enqueueMessage ( JText :: _ ( '<hr /><h3>External Code Warning</h3>' ), 'Warning' );
2018-02-06 10:55:46 +00:00
$this -> app -> enqueueMessage ( JText :: sprintf ( 'The code/string from <b>%s</b> has been <b>changed</b> since the last compilation, please investigate to insure the changes are safe!' , $key ), 'Warning' );
2018-02-02 17:36:22 +00:00
}
}
else
{
// add the hash to track changes
$object = new stdClass ();
2018-02-03 00:13:48 +00:00
$object -> target = $targetKey ;
2018-02-02 17:36:22 +00:00
$object -> hash = $liveHash ;
// insert local hash
2018-02-03 00:13:48 +00:00
$this -> db -> insertObject ( '#__componentbuilder_external_code' , $object );
2018-02-06 10:55:46 +00:00
// give notice the first time this is added
2018-03-05 00:13:42 +00:00
$this -> app -> enqueueMessage ( JText :: _ ( '<hr /><h3>External Code Notice</h3>' ), 'Notice' );
2018-02-06 10:55:46 +00:00
$this -> app -> enqueueMessage ( JText :: sprintf ( 'The code/string from <b>%s</b> has been added for the <b>first time</b>, please investigate to insure the correct code/string was used!' , $key ), 'Notice' );
2018-02-02 17:36:22 +00:00
}
}
else
{
2018-02-03 00:13:48 +00:00
// set notice that we could not get a valid string from the target
2018-03-05 00:13:42 +00:00
$this -> app -> enqueueMessage ( JText :: _ ( '<hr /><h3>External Code Warning</h3>' ), 'Warning' );
2018-02-06 10:55:46 +00:00
$this -> app -> enqueueMessage ( JText :: sprintf ( 'The <b>%s</b> returned an invalid string!' , $key ), 'Warning' );
2018-02-02 17:36:22 +00:00
}
}
// add to local bucket
2018-02-03 00:13:48 +00:00
if ( isset ( $this -> externalCodeString [ $targetKey ]))
2018-02-02 17:36:22 +00:00
{
2018-02-03 00:13:48 +00:00
$bucket [ $key ] = $this -> externalCodeString [ $targetKey ];
2018-02-02 17:36:22 +00:00
}
}
2018-03-18 04:52:07 +00:00
2017-02-13 23:24:38 +00:00
/**
* We start set the custom code data & can load it in to string
*
* @ param string $string The content to check
2018-08-02 05:36:47 +00:00
* @ param int $debug The switch to debug the update
2017-02-13 23:24:38 +00:00
*
2018-01-31 13:35:54 +00:00
* @ return string
2017-02-13 23:24:38 +00:00
*
*/
2018-11-27 13:05:47 +00:00
public function setCustomCodeData ( $string , $debug = 0 , $not = null )
2017-02-13 23:24:38 +00:00
{
// insure the code is loaded
$loaded = false ;
// check if content has custom code place holder
2017-12-14 23:10:47 +00:00
if ( strpos ( $string , '[CUSTO' . 'MCODE=' ) !== false )
2017-02-13 23:24:38 +00:00
{
2018-08-02 05:36:47 +00:00
// if debug
if ( $debug )
{
echo 'Custom Code String:' ;
var_dump ( $string );
}
2017-02-13 23:24:38 +00:00
// the ids found in this content
$bucket = array ();
2017-12-14 23:10:47 +00:00
$found = ComponentbuilderHelper :: getAllBetween ( $string , '[CUSTO' . 'MCODE=' , ']' );
2017-02-13 23:24:38 +00:00
if ( ComponentbuilderHelper :: checkArray ( $found ))
{
foreach ( $found as $key )
{
2018-08-02 05:36:47 +00:00
// if debug
if ( $debug )
{
echo '$key before update:' ;
var_dump ( $key );
}
2017-02-13 23:24:38 +00:00
// check if we have args
if ( is_numeric ( $key ))
{
$id = ( int ) $key ;
}
elseif ( ComponentbuilderHelper :: checkString ( $key ) && strpos ( $key , '+' ) === false )
{
$getFuncName = trim ( $key );
if ( ! isset ( $this -> functionNameMemory [ $getFuncName ]))
{
2018-01-31 13:35:54 +00:00
if ( ! $found_local = ComponentbuilderHelper :: getVar ( 'custom_code' , $getFuncName , 'function_name' , 'id' ))
2017-02-13 23:24:38 +00:00
{
continue ;
}
2018-01-31 13:35:54 +00:00
$this -> functionNameMemory [ $getFuncName ] = $found_local ;
2017-02-13 23:24:38 +00:00
}
$id = ( int ) $this -> functionNameMemory [ $getFuncName ];
}
elseif ( ComponentbuilderHelper :: checkString ( $key ) && strpos ( $key , '+' ) !== false )
{
$array = explode ( '+' , $key );
// set ID
if ( is_numeric ( $array [ 0 ]))
{
$id = ( int ) $array [ 0 ];
}
elseif ( ComponentbuilderHelper :: checkString ( $array [ 0 ]))
{
$getFuncName = trim ( $array [ 0 ]);
if ( ! isset ( $this -> functionNameMemory [ $getFuncName ]))
{
2018-01-31 13:35:54 +00:00
if ( ! $found_local = ComponentbuilderHelper :: getVar ( 'custom_code' , $getFuncName , 'function_name' , 'id' ))
2017-02-13 23:24:38 +00:00
{
continue ;
}
2018-01-31 13:35:54 +00:00
$this -> functionNameMemory [ $getFuncName ] = $found_local ;
2017-02-13 23:24:38 +00:00
}
$id = ( int ) $this -> functionNameMemory [ $getFuncName ];
}
else
{
continue ;
}
// load args for this ID
if ( isset ( $array [ 1 ]))
{
if ( ! isset ( $this -> customCodeData [ $id ][ 'args' ]))
{
$this -> customCodeData [ $id ][ 'args' ] = array ();
}
// only load if not already loaded
if ( ! isset ( $this -> customCodeData [ $id ][ 'args' ][ $key ]))
{
if ( strpos ( $array [ 1 ], ',' ) !== false )
{
2018-08-02 05:36:47 +00:00
// update the function values with the custom code key placholdres (this allow the use of [] + and , in the values)
$this -> customCodeData [ $id ][ 'args' ][ $key ] = array_map ( function ( $_key ) {
return $this -> setPlaceholders ( $_key , $this -> customCodeKeyPlacholders );
}, ( array ) explode ( ',' , $array [ 1 ]));
2017-02-13 23:24:38 +00:00
}
elseif ( ComponentbuilderHelper :: checkString ( $array [ 1 ]))
{
$this -> customCodeData [ $id ][ 'args' ][ $key ] = array ();
2018-08-02 05:36:47 +00:00
// update the function values with the custom code key placholdres (this allow the use of [] + and , in the values)
$this -> customCodeData [ $id ][ 'args' ][ $key ][] = $this -> setPlaceholders ( $array [ 1 ], $this -> customCodeKeyPlacholders );
2017-02-13 23:24:38 +00:00
}
}
2017-12-14 23:10:47 +00:00
}
2017-02-13 23:24:38 +00:00
}
else
{
continue ;
}
2018-11-27 13:05:47 +00:00
// make sure to remove the not if set
if ( $not && is_numeric ( $not ) && $not > 0 && $not == $id )
{
continue ;
}
2017-02-13 23:24:38 +00:00
$bucket [ $id ] = $id ;
}
}
2018-08-02 05:36:47 +00:00
// if debug
if ( $debug )
{
echo 'Bucket:' ;
var_dump ( $bucket );
}
2017-02-13 23:24:38 +00:00
// check if any custom code placeholders where found
if ( ComponentbuilderHelper :: checkArray ( $bucket ))
{
$_tmpLang = $this -> lang ;
// insure we add the langs to both site and admin
$this -> lang = 'both' ;
// now load the code to memory
2018-11-27 13:05:47 +00:00
$loaded = $this -> getCustomCode ( $bucket , false , $debug );
2017-02-13 23:24:38 +00:00
// revert lang to current setting
$this -> lang = $_tmpLang ;
}
2018-08-02 05:36:47 +00:00
// if debug
if ( $debug )
{
echo 'Loaded:' ;
var_dump ( $loaded );
}
2017-02-13 23:24:38 +00:00
// when the custom code is loaded
if ( $loaded === true )
{
2019-01-21 22:58:22 +00:00
$string = $this -> insertCustomCode ( $bucket , $string , $debug );
2018-08-02 05:36:47 +00:00
}
// if debug
if ( $debug )
{
echo 'Custom Code String After Update:' ;
var_dump ( $string );
2017-02-13 23:24:38 +00:00
}
}
return $string ;
}
2017-12-14 23:10:47 +00:00
2017-02-13 23:24:38 +00:00
/**
* Insert the custom code into the string
*
* @ param string $string The content to check
2018-08-02 05:36:47 +00:00
* @ param int $debug The switch to debug the update
2017-02-13 23:24:38 +00:00
*
* @ return string on success
*
*/
2019-01-21 22:58:22 +00:00
protected function insertCustomCode ( $ids , $string , $debug = 0 )
2017-02-13 23:24:38 +00:00
{
$code = array ();
2018-11-27 13:05:47 +00:00
// load the code
2019-01-21 22:58:22 +00:00
foreach ( $ids as $id )
2017-02-13 23:24:38 +00:00
{
2019-01-21 22:58:22 +00:00
$this -> buildCustomCodePlaceholders ( $this -> customCodeMemory [ $id ], $code , $debug );
2018-08-02 05:36:47 +00:00
}
// if debug
if ( $debug )
{
echo 'Place holders to Update String:' ;
var_dump ( $code );
echo 'Custom Code String Before Update:' ;
var_dump ( $string );
2017-02-13 23:24:38 +00:00
}
// now update the string
return $this -> setPlaceholders ( $string , $code );
}
2017-12-14 23:10:47 +00:00
2017-02-13 23:24:38 +00:00
/**
* Insert the custom code into the string
*
* @ param string $string The content to check
2018-08-02 05:36:47 +00:00
* @ param int $debug The switch to debug the update
2017-02-13 23:24:38 +00:00
*
* @ return string on success
*
2017-12-14 23:10:47 +00:00
*/
2018-08-02 05:36:47 +00:00
protected function buildCustomCodePlaceholders ( $item , & $code , $debug = 0 )
2017-02-13 23:24:38 +00:00
{
// check if there is args for this code
if ( isset ( $this -> customCodeData [ $item [ 'id' ]][ 'args' ]) && ComponentbuilderHelper :: checkArray ( $this -> customCodeData [ $item [ 'id' ]][ 'args' ]))
{
// since we have args we cant update this code via IDE (TODO)
$placeholder = $this -> getPlaceHolder ( 3 , null );
2018-08-02 05:36:47 +00:00
// if debug
if ( $debug )
{
echo 'Custom Code Placeholders:' ;
var_dump ( $placeholder );
}
2017-02-13 23:24:38 +00:00
// we have args and so need to load each
foreach ( $this -> customCodeData [ $item [ 'id' ]][ 'args' ] as $key => $args )
{
$this -> setThesePlaceHolders ( 'arg' , $args );
2018-08-02 05:36:47 +00:00
// if debug
if ( $debug )
{
echo 'Custom Code Global Placholders:' ;
var_dump ( $this -> placeholders );
}
2017-12-14 23:10:47 +00:00
$code [ '[CUSTOM' . 'CODE=' . $key . ']' ] = $placeholder [ 'start' ] . PHP_EOL . $this -> setPlaceholders ( $item [ 'code' ], $this -> placeholders ) . $placeholder [ 'end' ];
2017-02-13 23:24:38 +00:00
}
// always clear the args
$this -> clearFromPlaceHolders ( 'arg' );
}
else
{
2017-04-07 20:33:35 +00:00
if (( $keyPlaceholder = array_search ( $item [ 'id' ], $this -> functionNameMemory )) === false )
2017-02-13 23:24:38 +00:00
{
$keyPlaceholder = $item [ 'id' ];
}
// check what type of place holders we should load here
2017-12-14 23:10:47 +00:00
$placeholderType = ( int ) $item [ 'comment_type' ] . '2' ;
2018-05-22 19:01:36 +00:00
if ( stripos ( $item [ 'code' ], $this -> bbb . 'view' ) !== false || stripos ( $item [ 'code' ], $this -> bbb . 'sview' ) !== false || stripos ( $item [ 'code' ], $this -> bbb . 'arg' ) !== false )
2017-02-13 23:24:38 +00:00
{
// if view is being set dynamicly then we can't update this code via IDE (TODO)
$placeholderType = 3 ;
}
// if now ars were found, clear it
$this -> clearFromPlaceHolders ( 'arg' );
// load args for this code
2017-12-14 23:10:47 +00:00
$placeholder = $this -> getPlaceHolder ( $placeholderType , $item [ 'id' ]);
$code [ '[CUSTOM' . 'CODE=' . $keyPlaceholder . ']' ] = $placeholder [ 'start' ] . PHP_EOL . $this -> setPlaceholders ( $item [ 'code' ], $this -> placeholders ) . $placeholder [ 'end' ];
2017-02-13 23:24:38 +00:00
}
}
2017-12-14 23:10:47 +00:00
2017-02-13 23:24:38 +00:00
/**
* Set a type of placeholder with set of values
*
2019-08-26 06:54:16 +00:00
* @ param string $key The main string for placeholder key
* @ param array $values The values to add
2017-02-13 23:24:38 +00:00
*
* @ return void
*/
public function setThesePlaceHolders ( $key , $values )
{
// aways fist reset these
$this -> clearFromPlaceHolders ( $key );
if ( ComponentbuilderHelper :: checkArray ( $values ))
{
$number = 0 ;
foreach ( $values as $value )
{
2018-05-22 19:01:36 +00:00
$this -> placeholders [ $this -> bbb . $key . $number . $this -> ddd ] = $value ;
2017-02-13 23:24:38 +00:00
$number ++ ;
}
}
}
2017-12-14 23:10:47 +00:00
2017-02-13 23:24:38 +00:00
/**
* Remove a type of placeholder by main string
*
* @ param string $like The main string for placeholder key
*
* @ return void
*/
public function clearFromPlaceHolders ( $like )
{
foreach ( $this -> placeholders as $something => $value )
{
if ( stripos ( $something , $like ) !== false )
{
unset ( $this -> placeholders [ $something ]);
}
}
}
2017-12-14 23:10:47 +00:00
2017-02-01 13:17:04 +00:00
/**
* to unset stuff that are private or protected
*
*/
public function unsetNow ( $remove )
{
unset ( $this -> $remove );
}
2017-12-14 23:10:47 +00:00
2017-04-05 13:21:10 +00:00
/**
* Get the other languages
*
* @ param array $values The lang strings to get
*
*
* @ return void
*
*/
public function getMultiLangStrings ( $values )
{
// Create a new query object.
$query = $this -> db -> getQuery ( true );
2017-12-14 23:10:47 +00:00
$query -> from ( $this -> db -> quoteName ( '#__componentbuilder_language_translation' , 'a' ));
2017-04-05 13:21:10 +00:00
if ( ComponentbuilderHelper :: checkArray ( $values ))
{
2018-04-19 23:36:21 +00:00
$query -> select ( $this -> db -> quoteName ( array ( 'a.id' , 'a.translation' , 'a.source' , 'a.components' , 'a.published' )));
$query -> where ( $this -> db -> quoteName ( 'a.source' ) . ' IN (' . implode ( ',' , array_map ( function ( $a )
2017-12-14 23:10:47 +00:00
{
return $this -> db -> quote ( $a );
}, $values )) . ')' );
2017-04-05 13:21:10 +00:00
$this -> db -> setQuery ( $query );
$this -> db -> execute ();
if ( $this -> db -> getNumRows ())
{
2018-04-19 23:36:21 +00:00
return $this -> db -> loadAssocList ( 'source' );
2017-04-05 13:21:10 +00:00
}
}
return false ;
}
2017-12-14 23:10:47 +00:00
2017-04-05 13:21:10 +00:00
/**
* Set the Current language values to DB
*
*
* @ return void
*
*/
2017-04-07 20:33:35 +00:00
public function setLangPlaceholders ( $strings )
2017-04-05 13:21:10 +00:00
{
$counterInsert = 0 ;
$counterUpdate = 0 ;
$today = JFactory :: getDate () -> toSql ();
2018-04-19 23:36:21 +00:00
foreach ( $this -> languages [ $this -> langTag ] as $area => $placeholders )
2017-04-05 13:21:10 +00:00
{
foreach ( $placeholders as $placeholder => $string )
{
// to keep or remove
$remove = false ;
// build the tranlations
2017-04-05 16:26:17 +00:00
if ( ComponentbuilderHelper :: checkString ( $string ) && isset ( $this -> multiLangString [ $string ]))
2017-04-05 13:21:10 +00:00
{
// make sure we have converted the string to array
if ( isset ( $this -> multiLangString [ $string ][ 'translation' ]) && ComponentbuilderHelper :: checkJson ( $this -> multiLangString [ $string ][ 'translation' ]))
{
$this -> multiLangString [ $string ][ 'translation' ] = json_decode ( $this -> multiLangString [ $string ][ 'translation' ], true );
}
// if we have an array continue
2017-12-14 23:10:47 +00:00
if ( isset ( $this -> multiLangString [ $string ][ 'translation' ]) && ComponentbuilderHelper :: checkArray ( $this -> multiLangString [ $string ][ 'translation' ]))
2017-04-05 13:21:10 +00:00
{
// great lets build the multi languages strings
2017-09-18 00:18:23 +00:00
foreach ( $this -> multiLangString [ $string ][ 'translation' ] as $translations )
2017-04-05 13:21:10 +00:00
{
2017-09-18 00:18:23 +00:00
if ( isset ( $translations [ 'language' ]) && isset ( $translations [ 'translation' ]))
2017-04-05 13:21:10 +00:00
{
2017-09-18 00:18:23 +00:00
// build arrays
if ( ! isset ( $this -> languages [ $translations [ 'language' ]]))
{
$this -> languages [ $translations [ 'language' ]] = array ();
}
if ( ! isset ( $this -> languages [ $translations [ 'language' ]][ $area ]))
{
$this -> languages [ $translations [ 'language' ]][ $area ] = array ();
}
$this -> languages [ $translations [ 'language' ]][ $area ][ $placeholder ] = $translations [ 'translation' ];
2017-04-05 13:21:10 +00:00
}
}
}
else
{
// remove this string not to be checked again
$remove = true ;
}
}
// do the database managment
2017-12-14 23:10:47 +00:00
if ( ComponentbuilderHelper :: checkString ( $string ) && ( $key = array_search ( $string , $strings )) !== false )
2017-04-05 13:21:10 +00:00
{
if ( isset ( $this -> multiLangString [ $string ]))
{
// update the existing placeholder in db
$id = $this -> multiLangString [ $string ][ 'id' ];
if ( ComponentbuilderHelper :: checkJson ( $this -> multiLangString [ $string ][ 'components' ]))
{
$components = ( array ) json_decode ( $this -> multiLangString [ $string ][ 'components' ], true );
2017-04-07 20:33:35 +00:00
// check if we should add the component ID
2017-04-05 13:21:10 +00:00
if ( in_array ( $this -> componentID , $components ))
{
2017-04-07 20:33:35 +00:00
// only skip the update if the string is published and has the component ID
if ( $this -> multiLangString [ $string ][ 'published' ] == 1 )
{
continue ;
}
2017-04-05 13:21:10 +00:00
}
else
{
$components [] = $this -> componentID ;
}
}
else
{
$components = array ( $this -> componentID );
}
// start the bucket for this lang
2017-04-07 20:33:35 +00:00
$this -> setUpdateExistingLangStrings ( $id , $components , 1 , $today , $counterUpdate );
2017-04-05 13:21:10 +00:00
$counterUpdate ++ ;
// load to db
$this -> setExistingLangStrings ( 50 );
// remove string if needed
if ( $remove )
{
unset ( $this -> multiLangString [ $string ]);
}
}
else
{
// add the new lang placeholder to the db
2017-12-14 23:10:47 +00:00
$this -> newLangStrings [ $counterInsert ] = array ();
$this -> newLangStrings [ $counterInsert ][] = $this -> db -> quote ( json_encode ( array ( $this -> componentID ))); // 'components'
2018-04-19 23:36:21 +00:00
$this -> newLangStrings [ $counterInsert ][] = $this -> db -> quote ( $string ); // 'source'
2018-03-18 04:52:07 +00:00
$this -> newLangStrings [ $counterInsert ][] = $this -> db -> quote ( 1 ); // 'published'
$this -> newLangStrings [ $counterInsert ][] = $this -> db -> quote ( $today ); // 'created'
2017-12-14 23:10:47 +00:00
$this -> newLangStrings [ $counterInsert ][] = $this -> db -> quote (( int ) $this -> user -> id ); // 'created_by'
2018-03-18 04:52:07 +00:00
$this -> newLangStrings [ $counterInsert ][] = $this -> db -> quote ( 1 ); // 'version'
$this -> newLangStrings [ $counterInsert ][] = $this -> db -> quote ( 1 ); // 'access'
2017-04-05 13:21:10 +00:00
$counterInsert ++ ;
// load to db
$this -> setNewLangStrings ( 100 );
}
// only set the string once
unset ( $strings [ $key ]);
}
}
}
// just to make sure all is done
$this -> setExistingLangStrings ();
$this -> setNewLangStrings ();
}
2017-12-14 23:10:47 +00:00
2017-04-05 13:21:10 +00:00
/**
* store the language placeholders
*
* @ param int $when To set when to update
*
* @ return void
*
*/
protected function setNewLangStrings ( $when = 1 )
{
2019-09-05 21:12:56 +00:00
if ( count (( array ) $this -> newLangStrings ) >= $when )
2017-04-05 13:21:10 +00:00
{
// Create a new query object.
$query = $this -> db -> getQuery ( true );
$continue = false ;
// Insert columns.
2018-04-19 23:36:21 +00:00
$columns = array ( 'components' , 'source' , 'published' , 'created' , 'created_by' , 'version' , 'access' );
2017-04-05 13:21:10 +00:00
// Prepare the insert query.
$query -> insert ( $this -> db -> quoteName ( '#__componentbuilder_language_translation' ));
$query -> columns ( $this -> db -> quoteName ( $columns ));
2017-12-14 23:10:47 +00:00
foreach ( $this -> newLangStrings as $values )
2017-04-05 13:21:10 +00:00
{
2019-09-05 21:12:56 +00:00
if ( count (( array ) $values ) == 7 )
2017-04-05 13:21:10 +00:00
{
$query -> values ( implode ( ',' , $values ));
$continue = true ;
}
else
{
// TODO line mismatch... should not happen
}
}
// clear the values array
$this -> newLangStrings = array ();
if ( ! $continue )
{
return false ; // insure we dont continue if no values were loaded
}
// Set the query using our newly populated query object and execute it.
$this -> db -> setQuery ( $query );
$this -> db -> execute ();
}
2017-12-14 23:10:47 +00:00
}
2017-04-05 13:21:10 +00:00
/**
* update the language placeholders
*
* @ param int $when To set when to update
*
* @ return void
*
*/
protected function setExistingLangStrings ( $when = 1 )
{
2019-09-05 21:12:56 +00:00
if ( count (( array ) $this -> existingLangStrings ) >= $when )
2017-04-05 13:21:10 +00:00
{
2017-12-14 23:10:47 +00:00
foreach ( $this -> existingLangStrings as $values )
2017-04-05 13:21:10 +00:00
{
// Create a new query object.
$query = $this -> db -> getQuery ( true );
// Prepare the update query.
$query -> update ( $this -> db -> quoteName ( '#__componentbuilder_language_translation' )) -> set ( $values [ 'fields' ]) -> where ( $values [ 'conditions' ]);
// Set the query using our newly populated query object and execute it.
$this -> db -> setQuery ( $query );
$this -> db -> execute ();
}
// clear the values array
2017-12-14 23:10:47 +00:00
$this -> existingLangStrings = array ();
2017-04-05 13:21:10 +00:00
}
2017-12-14 23:10:47 +00:00
}
2017-04-07 20:33:35 +00:00
/**
* Remove exiting language translation stings
*
* @ param int $id To string ID to remove
*
* @ return void
*
*/
protected function removeExitingLangString ( $id )
{
// Create a new query object.
$query = $this -> db -> getQuery ( true );
2017-12-14 23:10:47 +00:00
2017-04-07 20:33:35 +00:00
// delete all custom keys for user 1001.
$conditions = array (
2017-12-14 23:10:47 +00:00
$this -> db -> quoteName ( 'id' ) . ' = ' . ( int ) $id
2017-04-07 20:33:35 +00:00
);
$query -> delete ( $this -> db -> quoteName ( '#__componentbuilder_language_translation' ));
$query -> where ( $conditions );
$this -> db -> setQuery ( $query );
$this -> db -> execute ();
}
2017-12-14 23:10:47 +00:00
2017-04-07 20:33:35 +00:00
/**
* Function to purge the unused languge strings
*
* @ param string $values the active strings
*
* @ return void
*
*/
public function purgeLanuageStrings ( $values )
{
// Create a new query object.
$query = $this -> db -> getQuery ( true );
2017-12-14 23:10:47 +00:00
$query -> from ( $this -> db -> quoteName ( '#__componentbuilder_language_translation' , 'a' ));
$query -> select ( $this -> db -> quoteName ( array ( 'a.id' , 'a.translation' , 'a.components' )));
2017-04-07 20:33:35 +00:00
// get all string that are not linked to this component
2018-04-19 23:36:21 +00:00
$query -> where ( $this -> db -> quoteName ( 'a.source' ) . ' NOT IN (' . implode ( ',' , array_map ( function ( $a )
2017-12-14 23:10:47 +00:00
{
return $this -> db -> quote ( $a );
}, $values )) . ')' );
2017-04-07 20:33:35 +00:00
$query -> where ( $this -> db -> quoteName ( 'a.published' ) . ' = 1' );
$this -> db -> setQuery ( $query );
$this -> db -> execute ();
if ( $this -> db -> getNumRows ())
{
$counterUpdate = 0 ;
$otherStrings = $this -> db -> loadAssocList ();
$today = JFactory :: getDate () -> toSql ();
foreach ( $otherStrings as $item )
{
if ( ComponentbuilderHelper :: checkJson ( $item [ 'components' ]))
{
$components = ( array ) json_decode ( $item [ 'components' ], true );
// if component is not found ignore this string, and do nothing
if (( $key = array_search ( $this -> componentID , $components )) !== false )
{
// first remove the component from the string
unset ( $components [ $key ]);
// check if there are more components
if ( ComponentbuilderHelper :: checkArray ( $components ))
{
// just update the string to unlink the current component
$this -> setUpdateExistingLangStrings ( $item [ 'id' ], $components , 1 , $today , $counterUpdate );
$counterUpdate ++ ;
// load to db
$this -> setExistingLangStrings ( 50 );
}
// check if this string has been worked on
elseif ( ComponentbuilderHelper :: checkJson ( $item [ 'translation' ]))
{
$translation = json_decode ( $item [ 'translation' ], true );
2017-09-18 00:18:23 +00:00
if ( ComponentbuilderHelper :: checkArray ( $translation ))
2017-04-07 20:33:35 +00:00
{
// only archive the item and update the string to unlink the current component
$this -> setUpdateExistingLangStrings ( $item [ 'id' ], $components , 2 , $today , $counterUpdate );
$counterUpdate ++ ;
// load to db
$this -> setExistingLangStrings ( 50 );
}
else
{
// remove the string since no translation found and not linked to any other component
$this -> removeExitingLangString ( $item [ 'id' ]);
}
}
else
{
// remove the string since no translation found and not linked to any other component
$this -> removeExitingLangString ( $item [ 'id' ]);
}
}
}
}
// load to db
$this -> setExistingLangStrings ();
}
}
2017-12-14 23:10:47 +00:00
2017-04-07 20:33:35 +00:00
/**
* just to add lang string to the existing Lang Strings array
*
* @ return void
*
*/
protected function setUpdateExistingLangStrings ( $id , $components , $published , $today , $counterUpdate )
{
// start the bucket for this lang
2017-12-14 23:10:47 +00:00
$this -> existingLangStrings [ $counterUpdate ] = array ();
$this -> existingLangStrings [ $counterUpdate ][ 'id' ] = ( int ) $id ;
$this -> existingLangStrings [ $counterUpdate ][ 'conditions' ] = array ();
$this -> existingLangStrings [ $counterUpdate ][ 'conditions' ][] = $this -> db -> quoteName ( 'id' ) . ' = ' . $this -> db -> quote ( $id );
$this -> existingLangStrings [ $counterUpdate ][ 'fields' ] = array ();
$this -> existingLangStrings [ $counterUpdate ][ 'fields' ][] = $this -> db -> quoteName ( 'components' ) . ' = ' . $this -> db -> quote ( json_encode ( $components ));
$this -> existingLangStrings [ $counterUpdate ][ 'fields' ][] = $this -> db -> quoteName ( 'published' ) . ' = ' . $this -> db -> quote ( $published );
$this -> existingLangStrings [ $counterUpdate ][ 'fields' ][] = $this -> db -> quoteName ( 'modified' ) . ' = ' . $this -> db -> quote ( $today );
$this -> existingLangStrings [ $counterUpdate ][ 'fields' ][] = $this -> db -> quoteName ( 'modified_by' ) . ' = ' . $this -> db -> quote (( int ) $this -> user -> id );
2017-04-05 13:21:10 +00:00
}
2017-12-14 23:10:47 +00:00
2017-02-01 13:17:04 +00:00
/**
* get the custom code from the system
*
* @ return void
*
*/
2018-11-27 13:05:47 +00:00
public function getCustomCode ( $ids = null , $setLang = true , $debug = 0 )
2017-02-01 13:17:04 +00:00
{
2017-02-13 23:24:38 +00:00
// should the result be stored in memory
$loadInMemory = false ;
2017-02-01 13:17:04 +00:00
// Create a new query object.
2017-02-13 23:24:38 +00:00
$query = $this -> db -> getQuery ( true );
2017-12-14 23:10:47 +00:00
$query -> from ( $this -> db -> quoteName ( '#__componentbuilder_custom_code' , 'a' ));
2017-02-13 23:24:38 +00:00
if ( ComponentbuilderHelper :: checkArray ( $ids ))
2017-02-09 16:11:10 +00:00
{
2018-11-27 13:05:47 +00:00
if ( $idArray = $this -> checkCustomCodeMemory ( $ids ))
2017-02-13 23:24:38 +00:00
{
2017-12-14 23:10:47 +00:00
$query -> select ( $this -> db -> quoteName ( array ( 'a.id' , 'a.code' , 'a.comment_type' )));
$query -> where ( $this -> db -> quoteName ( 'a.id' ) . ' IN (' . implode ( ',' , $idArray ) . ')' );
2017-02-13 23:24:38 +00:00
$query -> where ( $this -> db -> quoteName ( 'a.target' ) . ' = 2' ); // <--- to load the correct target
$loadInMemory = true ;
}
else
{
// all values are already in memory continue
return true ;
}
2017-02-09 16:11:10 +00:00
}
else
{
2017-12-14 23:10:47 +00:00
$query -> select ( $this -> db -> quoteName ( array ( 'a.id' , 'a.code' , 'a.comment_type' , 'a.component' , 'a.from_line' , 'a.hashtarget' , 'a.hashendtarget' , 'a.path' , 'a.to_line' , 'a.type' )));
$query -> where ( $this -> db -> quoteName ( 'a.component' ) . ' = ' . ( int ) $this -> componentData -> id );
2017-02-13 23:24:38 +00:00
$query -> where ( $this -> db -> quoteName ( 'a.target' ) . ' = 1' ); // <--- to load the correct target
$query -> order ( $this -> db -> quoteName ( 'a.from_line' ) . ' ASC' ); // <--- insrue we always add code from top of file
// reset custom code
$this -> customCode = array ();
2017-02-09 16:11:10 +00:00
}
2017-02-13 23:24:38 +00:00
$query -> where ( $this -> db -> quoteName ( 'a.published' ) . ' >= 1' );
$this -> db -> setQuery ( $query );
$this -> db -> execute ();
if ( $this -> db -> getNumRows ())
2017-02-01 13:17:04 +00:00
{
2017-02-13 23:24:38 +00:00
$bucket = $this -> db -> loadAssocList ( 'id' );
2017-02-01 13:17:04 +00:00
// open the code
2017-12-14 23:10:47 +00:00
foreach ( $bucket as $nr => & $customCode )
2017-02-01 13:17:04 +00:00
{
$customCode [ 'code' ] = base64_decode ( $customCode [ 'code' ]);
2018-02-03 00:13:48 +00:00
// always insure that the external code is loaded
$customCode [ 'code' ] = $this -> setExternalCodeString ( $customCode [ 'code' ]);
2018-01-31 14:27:17 +00:00
// set the lang only if needed
2017-02-13 23:24:38 +00:00
if ( $setLang )
{
$customCode [ 'code' ] = $this -> setLangStrings ( $customCode [ 'code' ]);
}
2018-11-27 13:05:47 +00:00
// check for more custom code (since this is a custom code placeholder)
else
{
$customCode [ 'code' ] = $this -> setCustomCodeData ( $customCode [ 'code' ], $debug , $nr );
}
2019-02-12 16:42:16 +00:00
// build the hash array
2017-02-09 16:11:10 +00:00
if ( isset ( $customCode [ 'hashtarget' ]))
2017-02-01 13:17:04 +00:00
{
2017-02-09 16:11:10 +00:00
$customCode [ 'hashtarget' ] = explode ( " __ " , $customCode [ 'hashtarget' ]);
2019-02-12 16:42:16 +00:00
// is this a replace code, set end has array
2017-02-09 16:11:10 +00:00
if ( $customCode [ 'type' ] == 1 && strpos ( $customCode [ 'hashendtarget' ], '__' ) !== false )
{
$customCode [ 'hashendtarget' ] = explode ( " __ " , $customCode [ 'hashendtarget' ]);
2019-02-12 16:42:16 +00:00
// NOW see if this is an end of page target (TODO not sure if the string is always d41d8cd98f00b204e9800998ecf8427e)
// I know this fix is not air-tight, but it should work as the value of an empty line when md5'ed is ^^^^
// Then if the line number is only >>>one<<< it is almost always end of the page.
// So I am using those two values to detect end of page replace ending, to avoid mismatching the ending target hash.
if ( $customCode [ 'hashendtarget' ][ 0 ] == 1 && 'd41d8cd98f00b204e9800998ecf8427e' === $customCode [ 'hashendtarget' ][ 1 ])
{
// unset since this will force the replacement unto end of page.
unset ( $customCode [ 'hashendtarget' ]);
}
2017-02-09 16:11:10 +00:00
}
2017-02-01 13:17:04 +00:00
}
}
2017-02-13 23:24:38 +00:00
// load this code into memory if needed
if ( $loadInMemory === true )
{
$this -> customCodeMemory = $this -> customCodeMemory + $bucket ;
}
$this -> customCode = array_merge ( $this -> customCode , $bucket );
2017-02-09 16:11:10 +00:00
return true ;
2017-02-01 13:17:04 +00:00
}
return false ;
}
2017-12-14 23:10:47 +00:00
2019-12-06 05:31:32 +00:00
/**
* get the Joomla Modules IDs
*
* @ return array of IDs on success
*
*/
protected function getModuleIDs ()
{
if (( $addjoomla_modules = ComponentbuilderHelper :: getVar ( 'component_modules' , $this -> componentID , 'joomla_component' , 'addjoomla_modules' )) !== false )
{
$addjoomla_modules = ( ComponentbuilderHelper :: checkJson ( $addjoomla_modules )) ? json_decode ( $addjoomla_modules , true ) : null ;
if ( ComponentbuilderHelper :: checkArray ( $addjoomla_modules ))
{
$joomla_modules = array_filter (
array_values ( $addjoomla_modules ),
function ( $array ){
// only load the modules whose target association call for it
if ( ! isset ( $array [ 'target' ]) || $array [ 'target' ] != 2 )
{
return true ;
}
return false ;
});
// if we have values we return IDs
if ( ComponentbuilderHelper :: checkArray ( $joomla_modules ))
{
return array_map ( function ( $array ){
return ( int ) $array [ 'module' ];
}, $joomla_modules );
}
}
}
return false ;
}
/**
* set the Joomla modules
*
* @ return true
*
*/
public function setJoomlaModule ( $id , & $component )
{
if ( isset ( $this -> joomlaModules [ $id ]))
{
return true ;
}
else
{
// Create a new query object.
$query = $this -> db -> getQuery ( true );
$query -> select ( 'a.*' );
$query -> select (
$this -> db -> quoteName (
array (
'f.addfiles' ,
'f.addfolders' ,
'f.addfilesfullpath' ,
'f.addfoldersfullpath' ,
'f.addurls' ,
'u.version_update' ,
'u.id'
), array (
'addfiles' ,
'addfolders' ,
'addfilesfullpath' ,
'addfoldersfullpath' ,
'addurls' ,
'version_update' ,
'version_update_id'
)
)
);
// from these tables
$query -> from ( '#__componentbuilder_joomla_module AS a' );
$query -> join ( 'LEFT' , $this -> db -> quoteName ( '#__componentbuilder_joomla_module_updates' , 'u' ) . ' ON (' . $this -> db -> quoteName ( 'a.id' ) . ' = ' . $this -> db -> quoteName ( 'u.joomla_module' ) . ')' );
$query -> join ( 'LEFT' , $this -> db -> quoteName ( '#__componentbuilder_joomla_module_files_folders_urls' , 'f' ) . ' ON (' . $this -> db -> quoteName ( 'a.id' ) . ' = ' . $this -> db -> quoteName ( 'f.joomla_module' ) . ')' );
$query -> where ( $this -> db -> quoteName ( 'a.id' ) . ' = ' . ( int ) $id );
$query -> where ( $this -> db -> quoteName ( 'a.published' ) . ' >= 1' );
$this -> db -> setQuery ( $query );
$this -> db -> execute ();
if ( $this -> db -> getNumRows ())
{
// get the module data
$module = $this -> db -> loadObject ();
// tweak system to set stuff to the module domain
$_backup_target = $this -> target ;
$_backup_lang = $this -> lang ;
$_backup_langPrefix = $this -> langPrefix ;
// set some keys
$module -> target_type = 'M0dU|3' ;
$module -> key = $module -> id . '_' . $module -> target_type ;
// update to point to module
$this -> target = $module -> key ;
$this -> lang = $module -> key ;
// set version if not set
if ( empty ( $module -> module_version ))
{
$module -> module_version = '1.0.0' ;
}
// set GUI mapper
$guiMapper = array ( 'table' => 'joomla_module' , 'id' => ( int ) $id , 'type' => 'php' );
// update the name if it has dynamic values
$module -> name = $this -> setPlaceholders ( $this -> setDynamicValues ( $module -> name ), $this -> placeholders );
// update the name if it has dynamic values
$module -> code_name = ComponentbuilderHelper :: safeClassFunctionName ( $module -> name );
// set official name
2019-12-23 03:47:19 +00:00
$module -> official_name = ComponentbuilderHelper :: safeString ( $module -> name , 'W' );
2019-12-06 05:31:32 +00:00
// set langPrefix
$this -> langPrefix = 'MOD_' . strtoupper ( $module -> code_name );
// set lang prefix
$module -> lang_prefix = $this -> langPrefix ;
// set module class name
$module -> class_helper_name = 'Mod' . ucfirst ( $module -> code_name ) . 'Helper' ;
$module -> class_data_name = 'Mod' . ucfirst ( $module -> code_name ) . 'Data' ;
// set module install class name
$module -> installer_class_name = 'mod_' . ucfirst ( $module -> code_name ) . 'InstallerScript' ;
// set module folder name
$module -> folder_name = 'mod_' . strtolower ( $module -> code_name );
// set the zip name
$module -> zip_name = $module -> folder_name . '_v' . str_replace ( '.' , '_' , $module -> module_version ) . '__J' . $this -> joomlaVersion ;
// set module file name
$module -> file_name = $module -> folder_name ;
// set official_name lang strings
$this -> setLangContent ( $module -> key , $this -> langPrefix , $module -> official_name );
// set some placeholder for this module
$this -> placeholders [ $this -> bbb . 'Module_name' . $this -> ddd ] = $module -> official_name ;
$this -> placeholders [ $this -> bbb . 'Module' . $this -> ddd ] = ucfirst ( $module -> code_name );
$this -> placeholders [ $this -> bbb . 'module' . $this -> ddd ] = strtolower ( $module -> code_name );
$this -> placeholders [ $this -> bbb . 'module.version' . $this -> ddd ] = $module -> module_version ;
$this -> placeholders [ $this -> bbb . 'module_version' . $this -> ddd ] = str_replace ( '.' , '_' , $module -> module_version );
// set description (TODO) add description field to module
if ( ! isset ( $module -> description ) || ! ComponentbuilderHelper :: checkString ( $module -> description ))
{
$module -> description = '' ;
}
else
{
$module -> description = $this -> setPlaceholders ( $this -> setDynamicValues ( $module -> description ), $this -> placeholders );
$this -> setLangContent ( $module -> key , $module -> lang_prefix . '_DESCRIPTION' , $module -> description );
$module -> description = '<p>' . $module -> description . '</p>' ;
}
$module -> xml_description = " <h1> " . $module -> official_name . " (v. " . $module -> module_version . " )</h1> <div style='clear: both;'></div> " . $module -> description . " <p>Created by <a href=' " . trim ( $component -> website ) . " ' target='_blank'> " . trim ( JFilterOutput :: cleanText ( $component -> author )) . " </a><br /><small>Development started " . JFactory :: getDate ( $module -> created ) -> format ( " jS F, Y " ) . " </small></p> " ;
// set xml description
$this -> setLangContent ( $module -> key , $module -> lang_prefix . '_XML_DESCRIPTION' , $module -> xml_description );
// update the readme if set
if ( $module -> addreadme == 1 && ! empty ( $module -> readme ))
{
$module -> readme = $this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $module -> readme )), $this -> placeholders );
}
else
{
$module -> addreadme = 0 ;
unset ( $module -> readme );
}
// get the custom_get
$module -> custom_get = ( isset ( $module -> custom_get ) && ComponentbuilderHelper :: checkJson ( $module -> custom_get )) ? json_decode ( $module -> custom_get , true ) : null ;
if ( ComponentbuilderHelper :: checkArray ( $module -> custom_get ))
{
$module -> custom_get = $this -> setGetData ( $module -> custom_get , $module -> key , $module -> key );
}
else
{
$module -> custom_get = false ;
}
// set helper class details
if ( $module -> add_class_helper >= 1 && ComponentbuilderHelper :: checkString ( $module -> class_helper_code ))
{
if ( $module -> add_class_helper_header == 1 && ComponentbuilderHelper :: checkString ( $module -> class_helper_header ))
{
// set GUI mapper field
$guiMapper [ 'field' ] = 'class_helper_header' ;
// base64 Decode code
$module -> class_helper_header = PHP_EOL . $this -> setGuiCodePlaceholder (
$this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $module -> class_helper_header )), $this -> placeholders ),
$guiMapper
) . PHP_EOL ;
}
else
{
$module -> add_class_helper_header = 0 ;
$module -> class_helper_header = '' ;
}
// set GUI mapper field
$guiMapper [ 'field' ] = 'class_helper_code' ;
// base64 Decode code
$module -> class_helper_code = $this -> setGuiCodePlaceholder (
$this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $module -> class_helper_code )), $this -> placeholders ),
$guiMapper
);
// set class type
if ( $module -> add_class_helper == 2 )
{
$module -> class_helper_type = 'abstract class ' ;
}
else
{
$module -> class_helper_type = 'class ' ;
}
}
else
{
$module -> add_class_helper = 0 ;
$module -> class_helper_code = '' ;
$module -> class_helper_header = '' ;
}
// base64 Decode mod_code
if ( isset ( $module -> mod_code ) && ComponentbuilderHelper :: checkString ( $module -> mod_code ))
{
// set GUI mapper field
$guiMapper [ 'field' ] = 'mod_code' ;
$module -> mod_code = $this -> setGuiCodePlaceholder (
$this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $module -> mod_code )), $this -> placeholders ),
$guiMapper
);
}
else
{
$module -> mod_code = " // get the module class sfx " ;
$module -> mod_code .= PHP_EOL . " \$ moduleclass_sfx = htmlspecialchars( \$ params->get('moduleclass_sfx'), ENT_COMPAT, 'UTF-8'); " ;
$module -> mod_code .= PHP_EOL . " // load the default Tmpl " ;
$module -> mod_code .= PHP_EOL . " require JModuleHelper::getLayoutPath('mod_ " . strtolower ( $module -> code_name ) . " ', \$ params->get('layout', 'default')); " ;
}
// base64 Decode default header
if ( isset ( $module -> default_header ) && ComponentbuilderHelper :: checkString ( $module -> default_header ))
{
// set GUI mapper field
$guiMapper [ 'field' ] = 'default_header' ;
$module -> default_header = $this -> setGuiCodePlaceholder (
$this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $module -> default_header )), $this -> placeholders ),
$guiMapper
);
}
else
{
$module -> default_header = '' ;
}
// base64 Decode default
if ( isset ( $module -> default ) && ComponentbuilderHelper :: checkString ( $module -> default ))
{
// set GUI mapper field
$guiMapper [ 'field' ] = 'default' ;
$module -> default = $this -> setGuiCodePlaceholder (
$this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $module -> default )), $this -> placeholders ),
$guiMapper
);
}
else
{
$module -> default = '<h1>No Tmpl set</h1>' ;
}
// start the config array
$module -> config_fields = array ();
// create the form arrays
$module -> form_files = array ();
$module -> fieldsets_label = array ();
$module -> fieldsets_paths = array ();
// set global fields rule to default component path
$module -> fields_rules_paths = 1 ;
// set the fields data
$module -> fields = ( isset ( $module -> fields ) && ComponentbuilderHelper :: checkJson ( $module -> fields )) ? json_decode ( $module -> fields , true ) : null ;
if ( ComponentbuilderHelper :: checkArray ( $module -> fields ))
{
// ket global key
$key = $module -> key ;
$dynamic_fields = array ( 'fieldset' => 'basic' , 'fields_name' => 'params' , 'file' => 'config' );
foreach ( $module -> fields as $n => & $form )
{
if ( isset ( $form [ 'fields' ]) && ComponentbuilderHelper :: checkArray ( $form [ 'fields' ]))
{
// make sure the dynamic_field is set to dynamic_value by default
foreach ( $dynamic_fields as $dynamic_field => $dynamic_value )
{
if ( ! isset ( $form [ $dynamic_field ]) || ! ComponentbuilderHelper :: checkString ( $form [ $dynamic_field ]))
{
$form [ $dynamic_field ] = $dynamic_value ;
}
else
{
if ( 'fields_name' === $dynamic_field && strpos ( $form [ $dynamic_field ], '.' ) !== false )
{
$form [ $dynamic_field ] = $form [ $dynamic_field ];
}
else
{
$form [ $dynamic_field ] = ComponentbuilderHelper :: safeString ( $form [ $dynamic_field ]);
}
}
}
// check if field is external form file
if ( ! isset ( $form [ 'module' ]) || $form [ 'module' ] != 1 )
{
// now build the form key
$unique = $form [ 'file' ] . $form [ 'fields_name' ] . $form [ 'fieldset' ];
}
else
{
// now build the form key
$unique = $form [ 'fields_name' ] . $form [ 'fieldset' ];
}
// set global fields rule path switchs
if ( $module -> fields_rules_paths == 1 && isset ( $form [ 'fields_rules_paths' ]) && $form [ 'fields_rules_paths' ] == 2 )
{
$module -> fields_rules_paths = 2 ;
}
// set where to path is pointing
$module -> fieldsets_paths [ $unique ] = $form [ 'fields_rules_paths' ];
// add the label if set to lang
if ( isset ( $form [ 'label' ]) && ComponentbuilderHelper :: checkString ( $form [ 'label' ]))
{
$module -> fieldsets_label [ $unique ] = $this -> setLang ( $form [ 'label' ]);
}
// build the fields
$form [ 'fields' ] = array_map ( function ( $field ) use ( $key , $unique ){
// make sure the alias and title is 0
$field [ 'alias' ] = 0 ;
$field [ 'title' ] = 0 ;
// set the field details
$this -> setFieldDetails ( $field , $key , $key , $unique );
// update the default if set
if ( ComponentbuilderHelper :: checkString ( $field [ 'custom_value' ]) && isset ( $field [ 'settings' ]))
{
if (( $old_default = ComponentbuilderHelper :: getBetween ( $field [ 'settings' ] -> xml , 'default="' , '"' , false )) !== false )
{
// replace old default
$field [ 'settings' ] -> xml = str_replace ( 'default="' . $old_default . '"' , 'default="' . $field [ 'custom_value' ] . '"' , $field [ 'settings' ] -> xml );
}
else
{
// add the default (hmmm not ideal but okay it should work)
$field [ 'settings' ] -> xml = 'default="' . $field [ 'custom_value' ] . '" ' . $field [ 'settings' ] -> xml ;
}
}
unset ( $field [ 'custom_value' ]);
// return field
return $field ;
}, array_values ( $form [ 'fields' ]));
// check if field is external form file
if ( ! isset ( $form [ 'module' ]) || $form [ 'module' ] != 1 )
{
// load the form file
if ( ! isset ( $module -> form_files [ $form [ 'file' ]]))
{
$module -> form_files [ $form [ 'file' ]] = array ();
}
if ( ! isset ( $module -> form_files [ $form [ 'file' ]][ $form [ 'fields_name' ]]))
{
$module -> form_files [ $form [ 'file' ]][ $form [ 'fields_name' ]] = array ();
}
if ( ! isset ( $module -> form_files [ $form [ 'file' ]][ $form [ 'fields_name' ]][ $form [ 'fieldset' ]]))
{
$module -> form_files [ $form [ 'file' ]][ $form [ 'fields_name' ]][ $form [ 'fieldset' ]] = array ();
}
// do some house cleaning (for fields)
foreach ( $form [ 'fields' ] as $field )
{
// so first we lock the field name in
$this -> getFieldName ( $field , $module -> key , $unique );
// add the fields to the global form file builder
$module -> form_files [ $form [ 'file' ]][ $form [ 'fields_name' ]][ $form [ 'fieldset' ]][] = $field ;
}
// remove form
unset ( $module -> fields [ $n ]);
}
else
{
// load the config form
if ( ! isset ( $module -> config_fields [ $form [ 'fields_name' ]]))
{
$module -> config_fields [ $form [ 'fields_name' ]] = array ();
}
if ( ! isset ( $module -> config_fields [ $form [ 'fields_name' ]][ $form [ 'fieldset' ]]))
{
$module -> config_fields [ $form [ 'fields_name' ]][ $form [ 'fieldset' ]] = array ();
}
// do some house cleaning (for fields)
foreach ( $form [ 'fields' ] as $field )
{
// so first we lock the field name in
$this -> getFieldName ( $field , $module -> key , $unique );
// add the fields to the config builder
$module -> config_fields [ $form [ 'fields_name' ]][ $form [ 'fieldset' ]][] = $field ;
}
// remove form
unset ( $module -> fields [ $n ]);
}
}
else
{
unset ( $module -> fields [ $n ]);
}
}
}
unset ( $module -> fields );
// set the add targets
$addArray = array ( 'files' => 'files' , 'folders' => 'folders' , 'urls' => 'urls' , 'filesfullpath' => 'files' , 'foldersfullpath' => 'folders' );
foreach ( $addArray as $addTarget => $targetHere )
{
// set the add target data
$module -> { 'add' . $addTarget } = ( isset ( $module -> { 'add' . $addTarget }) && ComponentbuilderHelper :: checkJson ( $module -> { 'add' . $addTarget })) ? json_decode ( $module -> { 'add' . $addTarget }, true ) : null ;
if ( ComponentbuilderHelper :: checkArray ( $module -> { 'add' . $addTarget }))
{
if ( isset ( $module -> { $targetHere }) && ComponentbuilderHelper :: checkArray ( $module -> { $targetHere }))
{
foreach ( $module -> { 'add' . $addTarget } as $taget )
{
$module -> { $targetHere }[] = $taget ;
}
}
else
{
$module -> { $targetHere } = array_values ( $module -> { 'add' . $addTarget });
}
}
unset ( $module -> { 'add' . $addTarget });
}
// load the library
if ( ! isset ( $this -> libManager [ $this -> target ]))
{
$this -> libManager [ $this -> target ] = array ();
}
if ( ! isset ( $this -> libManager [ $this -> target ][ $module -> code_name ]))
{
$this -> libManager [ $this -> target ][ $module -> code_name ] = array ();
}
// make sure json become array
if ( ComponentbuilderHelper :: checkJson ( $module -> libraries ))
{
$module -> libraries = json_decode ( $module -> libraries , true );
}
// if we have an array add it
if ( ComponentbuilderHelper :: checkArray ( $module -> libraries ))
{
foreach ( $module -> libraries as $library )
{
if ( ! isset ( $this -> libManager [ $this -> target ][ $module -> code_name ][ $library ]))
{
if ( $this -> getMediaLibrary (( int ) $library ))
{
$this -> libManager [ $this -> target ][ $module -> code_name ][( int ) $library ] = true ;
}
}
}
}
elseif ( is_numeric ( $module -> libraries ) && ! isset ( $this -> libManager [ $this -> target ][ $module -> code_name ][( int ) $module -> libraries ]))
{
if ( $this -> getMediaLibrary (( int ) $module -> libraries ))
{
$this -> libManager [ $this -> target ][ $module -> code_name ][( int ) $module -> libraries ] = true ;
}
}
// add PHP in module install
$module -> add_install_script = false ;
$addScriptMethods = array ( 'php_preflight' , 'php_postflight' , 'php_method' );
$addScriptTypes = array ( 'install' , 'update' , 'uninstall' );
foreach ( $addScriptMethods as $scriptMethod )
{
foreach ( $addScriptTypes as $scriptType )
{
if ( isset ( $module -> { 'add_' . $scriptMethod . '_' . $scriptType }) && $module -> { 'add_' . $scriptMethod . '_' . $scriptType } == 1 && ComponentbuilderHelper :: checkString ( $module -> { $scriptMethod . '_' . $scriptType }))
{
// set GUI mapper field
$guiMapper [ 'field' ] = $scriptMethod . '_' . $scriptType ;
$module -> { $scriptMethod . '_' . $scriptType } = $this -> setGuiCodePlaceholder (
$this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $module -> { $scriptMethod . '_' . $scriptType })), $this -> placeholders ),
$guiMapper
);
$module -> add_install_script = true ;
}
else
{
unset ( $module -> { $scriptMethod . '_' . $scriptType });
$module -> { 'add_' . $scriptMethod . '_' . $scriptType } = 0 ;
}
}
}
// add_sql
if ( $module -> add_sql == 1 && ComponentbuilderHelper :: checkString ( $module -> sql ))
{
$module -> sql = $this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $module -> sql )), $this -> placeholders );
}
else
{
unset ( $module -> sql );
$module -> add_sql = 0 ;
}
// add_sql_uninstall
if ( $module -> add_sql_uninstall == 1 && ComponentbuilderHelper :: checkString ( $module -> sql_uninstall ))
{
$module -> sql_uninstall = $this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $module -> sql_uninstall )), $this -> placeholders );
}
else
{
unset ( $module -> sql_uninstall );
$module -> add_sql_uninstall = 0 ;
}
// update the URL of the update_server if set
if ( $module -> add_update_server == 1 && ComponentbuilderHelper :: checkString ( $module -> update_server_url ))
{
$module -> update_server_url = $this -> setPlaceholders ( $this -> setDynamicValues ( $module -> update_server_url ), $this -> placeholders );
}
// add the update/sales server FTP details if that is the expected protocol
$serverArray = array ( 'update_server' , 'sales_server' );
foreach ( $serverArray as $server )
{
if ( $module -> { 'add_' . $server } == 1 && is_numeric ( $module -> { $server }) && $module -> { $server } > 0 )
{
// get the server protocol
$module -> { $server . '_protocol' } = ComponentbuilderHelper :: getVar ( 'server' , ( int ) $module -> { $server }, 'id' , 'protocol' );
}
else
{
$module -> { $server } = 0 ;
// only change this for sales server (update server can be added loacaly to the zip file)
if ( 'sales_server' === $server )
{
$module -> { 'add_' . $server } = 0 ;
}
$module -> { $server . '_protocol' } = 0 ;
}
}
// set the update server stuff (TODO)
// update_server_xml_path
// update_server_xml_file_name
// rest globals
$this -> target = $_backup_target ;
$this -> lang = $_backup_lang ;
$this -> langPrefix = $_backup_langPrefix ;
unset ( $this -> placeholders [ $this -> bbb . 'Module_name' . $this -> ddd ]);
unset ( $this -> placeholders [ $this -> bbb . 'Module' . $this -> ddd ]);
unset ( $this -> placeholders [ $this -> bbb . 'module' . $this -> ddd ]);
unset ( $this -> placeholders [ $this -> bbb . 'module.version' . $this -> ddd ]);
unset ( $this -> placeholders [ $this -> bbb . 'module_version' . $this -> ddd ]);
$this -> joomlaModules [ $id ] = $module ;
return true ;
}
}
return false ;
}
/**
* get the module xml template
*
* @ return string
*
*/
public function getModuleXMLTemplate ( & $module )
{
$xml = '<?xml version="1.0" encoding="utf-8"?>' ;
$xml .= PHP_EOL . '<extension type="module" version="3.8" client="site" method="upgrade">' ;
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<name>' . $module -> lang_prefix . '</name>' ;
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<creationDate>' . $this -> hhh . 'BUILDDATE' . $this -> hhh . '</creationDate>' ;
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<author>' . $this -> hhh . 'AUTHOR' . $this -> hhh . '</author>' ;
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<authorEmail>' . $this -> hhh . 'AUTHOREMAIL' . $this -> hhh . '</authorEmail>' ;
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<authorUrl>' . $this -> hhh . 'AUTHORWEBSITE' . $this -> hhh . '</authorUrl>' ;
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<copyright>' . $this -> hhh . 'COPYRIGHT' . $this -> hhh . '</copyright>' ;
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<license>' . $this -> hhh . 'LICENSE' . $this -> hhh . '</license>' ;
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<version>' . $module -> module_version . '</version>' ;
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<description>' . $module -> lang_prefix . '_XML_DESCRIPTION</description>' ;
$xml .= $this -> hhh . 'MAINXML' . $this -> hhh ;
$xml .= PHP_EOL . '</extension>' ;
return $xml ;
}
2019-09-11 14:50:42 +00:00
/**
* get the Joomla plugins IDs
*
* @ return array of IDs on success
*
*/
protected function getPluginIDs ()
{
if (( $addjoomla_plugins = ComponentbuilderHelper :: getVar ( 'component_plugins' , $this -> componentID , 'joomla_component' , 'addjoomla_plugins' )) !== false )
{
$addjoomla_plugins = ( ComponentbuilderHelper :: checkJson ( $addjoomla_plugins )) ? json_decode ( $addjoomla_plugins , true ) : null ;
if ( ComponentbuilderHelper :: checkArray ( $addjoomla_plugins ))
{
$joomla_plugins = array_filter (
array_values ( $addjoomla_plugins ),
function ( $array ){
2019-11-13 03:36:42 +00:00
// only load the plugins whose target association call for it
2019-09-11 14:50:42 +00:00
if ( ! isset ( $array [ 'target' ]) || $array [ 'target' ] != 2 )
{
return true ;
}
return false ;
});
// if we have values we return IDs
if ( ComponentbuilderHelper :: checkArray ( $joomla_plugins ))
{
return array_map ( function ( $array ){
return ( int ) $array [ 'plugin' ];
}, $joomla_plugins );
}
}
}
return false ;
}
/**
* get the Joomla plugin path
*
* @ return string of plugin path on success
*
*/
protected function getPluginPath ( $id )
{
if ( is_numeric ( $id ) && $id > 0 )
{
// Create a new query object.
$query = $this -> db -> getQuery ( true );
$query -> select ( 'a.*' );
$query -> select (
$this -> db -> quoteName (
array (
'a.name' ,
'g.name'
), array (
'name' ,
'group'
)
)
);
// from these tables
$query -> from ( '#__componentbuilder_joomla_plugin AS a' );
$query -> join ( 'LEFT' , $this -> db -> quoteName ( '#__componentbuilder_joomla_plugin_group' , 'g' ) . ' ON (' . $this -> db -> quoteName ( 'a.joomla_plugin_group' ) . ' = ' . $this -> db -> quoteName ( 'g.id' ) . ')' );
$query -> where ( $this -> db -> quoteName ( 'a.id' ) . ' = ' . ( int ) $id );
$query -> where ( $this -> db -> quoteName ( 'a.published' ) . ' >= 1' );
$this -> db -> setQuery ( $query );
$this -> db -> execute ();
if ( $this -> db -> getNumRows ())
{
// get the plugin data
$plugin = $this -> db -> loadObject ();
// update the name if it has dynamic values
$plugin -> name = $this -> setPlaceholders ( $this -> setDynamicValues ( $plugin -> name ), $this -> globalPlaceholders );
// update the name if it has dynamic values
$plugin -> code_name = ComponentbuilderHelper :: safeClassFunctionName ( $plugin -> name );
// set plugin folder name
$plugin -> group = strtolower ( $plugin -> group );
// set plugin file name
$plugin -> file_name = strtolower ( $plugin -> code_name );
// set the lang key
$this -> langKeys [ 'PLG_' . strtoupper ( $plugin -> group . '_' . $plugin -> file_name )] = $plugin -> id . '_P|uG!n' ;
// return the path
return $plugin -> group . '/' . $plugin -> file_name ;
}
}
return false ;
}
2019-07-28 21:48:42 +00:00
/**
2019-08-22 01:54:47 +00:00
* set the Joomla plugins
2019-07-28 21:48:42 +00:00
*
2019-08-22 01:54:47 +00:00
* @ return true
2019-07-28 21:48:42 +00:00
*
*/
2019-08-22 01:54:47 +00:00
public function setJoomlaPlugin ( $id , & $component )
2019-07-28 21:48:42 +00:00
{
2019-08-22 01:54:47 +00:00
if ( isset ( $this -> joomlaPlugins [ $id ]))
2019-07-28 21:48:42 +00:00
{
2019-08-22 01:54:47 +00:00
return true ;
}
else
{
// Create a new query object.
$query = $this -> db -> getQuery ( true );
$query -> select ( 'a.*' );
$query -> select (
$this -> db -> quoteName (
2019-07-28 21:48:42 +00:00
array (
2019-08-22 01:54:47 +00:00
'g.name' ,
'e.name' ,
'e.head' ,
'e.comment' ,
'e.id' ,
'f.addfiles' ,
'f.addfolders' ,
'f.addfilesfullpath' ,
'f.addfoldersfullpath' ,
'f.addurls' ,
'u.version_update' ,
'u.id'
), array (
'group' ,
'extends' ,
'class_head' ,
'comment' ,
'class_id' ,
'addfiles' ,
'addfolders' ,
'addfilesfullpath' ,
'addfoldersfullpath' ,
'addurls' ,
'version_update' ,
'version_update_id'
)
)
);
// from these tables
$query -> from ( '#__componentbuilder_joomla_plugin AS a' );
$query -> join ( 'LEFT' , $this -> db -> quoteName ( '#__componentbuilder_joomla_plugin_group' , 'g' ) . ' ON (' . $this -> db -> quoteName ( 'a.joomla_plugin_group' ) . ' = ' . $this -> db -> quoteName ( 'g.id' ) . ')' );
$query -> join ( 'LEFT' , $this -> db -> quoteName ( '#__componentbuilder_class_extends' , 'e' ) . ' ON (' . $this -> db -> quoteName ( 'a.class_extends' ) . ' = ' . $this -> db -> quoteName ( 'e.id' ) . ')' );
$query -> join ( 'LEFT' , $this -> db -> quoteName ( '#__componentbuilder_joomla_plugin_updates' , 'u' ) . ' ON (' . $this -> db -> quoteName ( 'a.id' ) . ' = ' . $this -> db -> quoteName ( 'u.joomla_plugin' ) . ')' );
$query -> join ( 'LEFT' , $this -> db -> quoteName ( '#__componentbuilder_joomla_plugin_files_folders_urls' , 'f' ) . ' ON (' . $this -> db -> quoteName ( 'a.id' ) . ' = ' . $this -> db -> quoteName ( 'f.joomla_plugin' ) . ')' );
$query -> where ( $this -> db -> quoteName ( 'a.id' ) . ' = ' . ( int ) $id );
$query -> where ( $this -> db -> quoteName ( 'a.published' ) . ' >= 1' );
$this -> db -> setQuery ( $query );
$this -> db -> execute ();
if ( $this -> db -> getNumRows ())
2019-07-28 21:48:42 +00:00
{
2019-08-22 01:54:47 +00:00
// get the plugin data
$plugin = $this -> db -> loadObject ();
// tweak system to set stuff to the plugin domain
$_backup_target = $this -> target ;
$_backup_lang = $this -> lang ;
$_backup_langPrefix = $this -> langPrefix ;
// set some keys
$plugin -> target_type = 'P|uG!n' ;
$plugin -> key = $plugin -> id . '_' . $plugin -> target_type ;
// update to point to plugin
$this -> target = $plugin -> key ;
$this -> lang = $plugin -> key ;
// set version if not set
if ( empty ( $plugin -> plugin_version ))
{
$plugin -> plugin_version = '1.0.0' ;
}
// set GUI mapper
$guiMapper = array ( 'table' => 'joomla_plugin' , 'id' => ( int ) $id , 'type' => 'php' );
// update the name if it has dynamic values
$plugin -> name = $this -> setPlaceholders ( $this -> setDynamicValues ( $plugin -> name ), $this -> placeholders );
// update the name if it has dynamic values
$plugin -> code_name = ComponentbuilderHelper :: safeClassFunctionName ( $plugin -> name );
// set official name
$plugin -> official_name = ucwords ( $plugin -> group . ' - ' . $plugin -> name );
// set langPrefix
$this -> langPrefix = 'PLG_' . strtoupper ( $plugin -> group ) . '_' . strtoupper ( $plugin -> code_name );
// set lang prefix
$plugin -> lang_prefix = $this -> langPrefix ;
// set plugin class name
$plugin -> class_name = 'Plg' . ucfirst ( $plugin -> group ) . ucfirst ( $plugin -> code_name );
// set plugin install class name
$plugin -> installer_class_name = 'plg' . ucfirst ( $plugin -> group ) . ucfirst ( $plugin -> code_name ) . 'InstallerScript' ;
// set plugin folder name
$plugin -> folder_name = 'plg_' . strtolower ( $plugin -> group ) . '_' . strtolower ( $plugin -> code_name );
// set the zip name
$plugin -> zip_name = $plugin -> folder_name . '_v' . str_replace ( '.' , '_' , $plugin -> plugin_version ) . '__J' . $this -> joomlaVersion ;
// set plugin file name
$plugin -> file_name = strtolower ( $plugin -> code_name );
// set official_name lang strings
$this -> setLangContent ( $plugin -> key , $this -> langPrefix , $plugin -> official_name );
2019-08-26 06:54:16 +00:00
// set some placeholder for this plugin
$this -> placeholders [ $this -> bbb . 'Plugin_name' . $this -> ddd ] = $plugin -> official_name ;
$this -> placeholders [ $this -> bbb . 'Plugin' . $this -> ddd ] = ucfirst ( $plugin -> code_name );
$this -> placeholders [ $this -> bbb . 'plugin' . $this -> ddd ] = strtolower ( $plugin -> code_name );
$this -> placeholders [ $this -> bbb . 'Plugin_group' . $this -> ddd ] = ucfirst ( $plugin -> group );
$this -> placeholders [ $this -> bbb . 'plugin_group' . $this -> ddd ] = strtolower ( $plugin -> group );
$this -> placeholders [ $this -> bbb . 'plugin.version' . $this -> ddd ] = $plugin -> plugin_version ;
$this -> placeholders [ $this -> bbb . 'plugin_version' . $this -> ddd ] = str_replace ( '.' , '_' , $plugin -> plugin_version );
2019-08-22 01:54:47 +00:00
// set description (TODO) add description field to plugin
if ( ! isset ( $plugin -> description ) || ! ComponentbuilderHelper :: checkString ( $plugin -> description ))
{
$plugin -> description = '' ;
}
else
2019-07-28 21:48:42 +00:00
{
2019-08-22 01:54:47 +00:00
$plugin -> description = $this -> setPlaceholders ( $this -> setDynamicValues ( $plugin -> description ), $this -> placeholders );
$this -> setLangContent ( $plugin -> key , $plugin -> lang_prefix . '_DESCRIPTION' , $plugin -> description );
$plugin -> description = '<p>' . $plugin -> description . '</p>' ;
2019-07-28 21:48:42 +00:00
}
2019-08-22 01:54:47 +00:00
$plugin -> xml_description = " <h1> " . $plugin -> official_name . " (v. " . $plugin -> plugin_version . " )</h1> <div style='clear: both;'></div> " . $plugin -> description . " <p>Created by <a href=' " . trim ( $component -> website ) . " ' target='_blank'> " . trim ( JFilterOutput :: cleanText ( $component -> author )) . " </a><br /><small>Development started " . JFactory :: getDate ( $plugin -> created ) -> format ( " jS F, Y " ) . " </small></p> " ;
// set xml discription
$this -> setLangContent ( $plugin -> key , $plugin -> lang_prefix . '_XML_DESCRIPTION' , $plugin -> xml_description );
// update the readme if set
if ( $plugin -> addreadme == 1 && ! empty ( $plugin -> readme ))
{
$plugin -> readme = $this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $plugin -> readme )), $this -> placeholders );
}
else
2019-07-28 21:48:42 +00:00
{
2019-08-22 01:54:47 +00:00
$plugin -> addreadme = 0 ;
unset ( $plugin -> readme );
}
// open some base64 strings
if ( ! empty ( $plugin -> main_class_code ))
{
// set GUI mapper field
$guiMapper [ 'field' ] = 'main_class_code' ;
// base64 Decode main_class_code.
$plugin -> main_class_code = $this -> setGuiCodePlaceholder (
$this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $plugin -> main_class_code )), $this -> placeholders ),
$guiMapper
);
}
// set the head :)
if ( $plugin -> add_head == 1 && ! empty ( $plugin -> head ))
{
// set GUI mapper field
$guiMapper [ 'field' ] = 'head' ;
// base64 Decode head.
$plugin -> head = $this -> setGuiCodePlaceholder (
$this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $plugin -> head )), $this -> placeholders ),
$guiMapper
);
}
elseif ( ! empty ( $plugin -> class_head ))
{
// base64 Decode head.
$plugin -> head = $this -> setGuiCodePlaceholder (
$this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $plugin -> class_head )), $this -> placeholders ),
array (
'table' => 'class_extends' ,
'field' => 'head' ,
'id' => ( int ) $plugin -> class_id ,
'type' => 'php' )
);
}
unset ( $plugin -> class_head );
// set the comment
if ( ! empty ( $plugin -> comment ))
{
// base64 Decode comment.
$plugin -> comment = $this -> setGuiCodePlaceholder (
$this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $plugin -> comment )), $this -> placeholders ),
array (
'table' => 'class_extends' ,
'field' => 'comment' ,
'id' => ( int ) $plugin -> class_id ,
'type' => 'php' )
);
}
// start the config array
$plugin -> config_fields = array ();
// create the form arrays
$plugin -> form_files = array ();
$plugin -> fieldsets_label = array ();
$plugin -> fieldsets_paths = array ();
// set global fields rule to default component path
$plugin -> fields_rules_paths = 1 ;
// set the fields data
$plugin -> fields = ( isset ( $plugin -> fields ) && ComponentbuilderHelper :: checkJson ( $plugin -> fields )) ? json_decode ( $plugin -> fields , true ) : null ;
if ( ComponentbuilderHelper :: checkArray ( $plugin -> fields ))
{
// ket global key
$key = $plugin -> key ;
$dynamic_fields = array ( 'fieldset' => 'basic' , 'fields_name' => 'params' , 'file' => 'config' );
foreach ( $plugin -> fields as $n => & $form )
2019-07-28 21:48:42 +00:00
{
2019-08-22 01:54:47 +00:00
if ( isset ( $form [ 'fields' ]) && ComponentbuilderHelper :: checkArray ( $form [ 'fields' ]))
2019-07-28 21:48:42 +00:00
{
2019-08-22 01:54:47 +00:00
// make sure the dynamic_field is set to dynamic_value by default
foreach ( $dynamic_fields as $dynamic_field => $dynamic_value )
{
if ( ! isset ( $form [ $dynamic_field ]) || ! ComponentbuilderHelper :: checkString ( $form [ $dynamic_field ]))
{
$form [ $dynamic_field ] = $dynamic_value ;
}
else
{
2019-10-11 13:41:00 +00:00
if ( 'fields_name' === $dynamic_field && strpos ( $form [ $dynamic_field ], '.' ) !== false )
{
$form [ $dynamic_field ] = $form [ $dynamic_field ];
}
else
{
$form [ $dynamic_field ] = ComponentbuilderHelper :: safeString ( $form [ $dynamic_field ]);
}
2019-08-22 01:54:47 +00:00
}
}
// check if field is external form file
if ( ! isset ( $form [ 'plugin' ]) || $form [ 'plugin' ] != 1 )
{
// now build the form key
2019-12-03 02:17:35 +00:00
$unique = $form [ 'file' ] . $form [ 'fields_name' ] . $form [ 'fieldset' ];
2019-08-22 01:54:47 +00:00
}
else
{
// now build the form key
$unique = $form [ 'fields_name' ] . $form [ 'fieldset' ];
}
// set global fields rule path switchs
if ( $plugin -> fields_rules_paths == 1 && isset ( $form [ 'fields_rules_paths' ]) && $form [ 'fields_rules_paths' ] == 2 )
{
$plugin -> fields_rules_paths = 2 ;
}
// set where to path is pointing
$plugin -> fieldsets_paths [ $unique ] = $form [ 'fields_rules_paths' ];
// add the label if set to lang
if ( isset ( $form [ 'label' ]) && ComponentbuilderHelper :: checkString ( $form [ 'label' ]))
{
$plugin -> fieldsets_label [ $unique ] = $this -> setLang ( $form [ 'label' ]);
}
// build the fields
$form [ 'fields' ] = array_map ( function ( $field ) use ( $key , $unique ){
// make sure the alias and title is 0
$field [ 'alias' ] = 0 ;
$field [ 'title' ] = 0 ;
// set the field details
$this -> setFieldDetails ( $field , $key , $key , $unique );
// update the default if set
if ( ComponentbuilderHelper :: checkString ( $field [ 'custom_value' ]) && isset ( $field [ 'settings' ]))
{
if (( $old_default = ComponentbuilderHelper :: getBetween ( $field [ 'settings' ] -> xml , 'default="' , '"' , false )) !== false )
{
// replace old default
$field [ 'settings' ] -> xml = str_replace ( 'default="' . $old_default . '"' , 'default="' . $field [ 'custom_value' ] . '"' , $field [ 'settings' ] -> xml );
}
else
{
// add the default (hmmm not ideal but okay it should work)
$field [ 'settings' ] -> xml = 'default="' . $field [ 'custom_value' ] . '" ' . $field [ 'settings' ] -> xml ;
}
}
unset ( $field [ 'custom_value' ]);
// return field
return $field ;
}, array_values ( $form [ 'fields' ]));
// check if field is external form file
if ( ! isset ( $form [ 'plugin' ]) || $form [ 'plugin' ] != 1 )
{
// load the form file
if ( ! isset ( $plugin -> form_files [ $form [ 'file' ]]))
{
$plugin -> form_files [ $form [ 'file' ]] = array ();
}
if ( ! isset ( $plugin -> form_files [ $form [ 'file' ]][ $form [ 'fields_name' ]]))
{
$plugin -> form_files [ $form [ 'file' ]][ $form [ 'fields_name' ]] = array ();
}
if ( ! isset ( $plugin -> form_files [ $form [ 'file' ]][ $form [ 'fields_name' ]][ $form [ 'fieldset' ]]))
{
$plugin -> form_files [ $form [ 'file' ]][ $form [ 'fields_name' ]][ $form [ 'fieldset' ]] = array ();
}
// do some house cleaning (for fields)
foreach ( $form [ 'fields' ] as $field )
{
// so first we lock the field name in
$this -> getFieldName ( $field , $plugin -> key , $unique );
// add the fields to the global form file builder
$plugin -> form_files [ $form [ 'file' ]][ $form [ 'fields_name' ]][ $form [ 'fieldset' ]][] = $field ;
}
// remove form
unset ( $plugin -> fields [ $n ]);
}
else
{
2019-12-03 02:17:35 +00:00
// load the config form
2019-08-22 01:54:47 +00:00
if ( ! isset ( $plugin -> config_fields [ $form [ 'fields_name' ]]))
{
$plugin -> config_fields [ $form [ 'fields_name' ]] = array ();
}
if ( ! isset ( $plugin -> config_fields [ $form [ 'fields_name' ]][ $form [ 'fieldset' ]]))
{
$plugin -> config_fields [ $form [ 'fields_name' ]][ $form [ 'fieldset' ]] = array ();
}
// do some house cleaning (for fields)
foreach ( $form [ 'fields' ] as $field )
{
// so first we lock the field name in
$this -> getFieldName ( $field , $plugin -> key , $unique );
// add the fields to the config builder
$plugin -> config_fields [ $form [ 'fields_name' ]][ $form [ 'fieldset' ]][] = $field ;
}
// remove form
unset ( $plugin -> fields [ $n ]);
}
}
else
{
unset ( $plugin -> fields [ $n ]);
2019-07-28 21:48:42 +00:00
}
}
}
2019-08-22 01:54:47 +00:00
unset ( $plugin -> fields );
// set the add targets
$addArray = array ( 'files' => 'files' , 'folders' => 'folders' , 'urls' => 'urls' , 'filesfullpath' => 'files' , 'foldersfullpath' => 'folders' );
foreach ( $addArray as $addTarget => $targetHere )
2019-08-04 22:38:53 +00:00
{
2019-08-22 01:54:47 +00:00
// set the add target data
$plugin -> { 'add' . $addTarget } = ( isset ( $plugin -> { 'add' . $addTarget }) && ComponentbuilderHelper :: checkJson ( $plugin -> { 'add' . $addTarget })) ? json_decode ( $plugin -> { 'add' . $addTarget }, true ) : null ;
if ( ComponentbuilderHelper :: checkArray ( $plugin -> { 'add' . $addTarget }))
2019-08-04 22:38:53 +00:00
{
2019-08-22 01:54:47 +00:00
if ( isset ( $plugin -> { $targetHere }) && ComponentbuilderHelper :: checkArray ( $plugin -> { $targetHere }))
{
foreach ( $plugin -> { 'add' . $addTarget } as $taget )
{
$plugin -> { $targetHere }[] = $taget ;
}
}
else
{
$plugin -> { $targetHere } = array_values ( $plugin -> { 'add' . $addTarget });
}
2019-08-04 22:38:53 +00:00
}
2019-08-22 01:54:47 +00:00
unset ( $plugin -> { 'add' . $addTarget });
}
// add PHP in plugin install
$plugin -> add_install_script = false ;
$addScriptMethods = array ( 'php_preflight' , 'php_postflight' , 'php_method' );
$addScriptTypes = array ( 'install' , 'update' , 'uninstall' );
foreach ( $addScriptMethods as $scriptMethod )
{
foreach ( $addScriptTypes as $scriptType )
2019-08-04 22:38:53 +00:00
{
2019-08-22 01:54:47 +00:00
if ( isset ( $plugin -> { 'add_' . $scriptMethod . '_' . $scriptType }) && $plugin -> { 'add_' . $scriptMethod . '_' . $scriptType } == 1 && ComponentbuilderHelper :: checkString ( $plugin -> { $scriptMethod . '_' . $scriptType }))
{
// set GUI mapper field
$guiMapper [ 'field' ] = $scriptMethod . '_' . $scriptType ;
$plugin -> { $scriptMethod . '_' . $scriptType } = $this -> setGuiCodePlaceholder (
$this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $plugin -> { $scriptMethod . '_' . $scriptType })), $this -> placeholders ),
$guiMapper
);
$plugin -> add_install_script = true ;
}
else
{
unset ( $plugin -> { $scriptMethod . '_' . $scriptType });
$plugin -> { 'add_' . $scriptMethod . '_' . $scriptType } = 0 ;
}
2019-08-04 22:38:53 +00:00
}
}
2019-08-22 01:54:47 +00:00
// add_sql
if ( $plugin -> add_sql == 1 && ComponentbuilderHelper :: checkString ( $plugin -> sql ))
{
$plugin -> sql = $this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $plugin -> sql )), $this -> placeholders );
}
else
2019-08-04 22:38:53 +00:00
{
2019-08-22 01:54:47 +00:00
unset ( $plugin -> sql );
$plugin -> add_sql = 0 ;
}
// add_sql_uninstall
if ( $plugin -> add_sql_uninstall == 1 && ComponentbuilderHelper :: checkString ( $plugin -> sql_uninstall ))
{
$plugin -> sql_uninstall = $this -> setPlaceholders ( $this -> setDynamicValues ( base64_decode ( $plugin -> sql_uninstall )), $this -> placeholders );
2019-08-04 22:38:53 +00:00
}
else
{
2019-08-22 01:54:47 +00:00
unset ( $plugin -> sql_uninstall );
$plugin -> add_sql_uninstall = 0 ;
}
// update the URL of the update_server if set
if ( $plugin -> add_update_server == 1 && ComponentbuilderHelper :: checkString ( $plugin -> update_server_url ))
{
$plugin -> update_server_url = $this -> setPlaceholders ( $this -> setDynamicValues ( $plugin -> update_server_url ), $this -> placeholders );
}
// add the update/sales server FTP details if that is the expected protocol
$serverArray = array ( 'update_server' , 'sales_server' );
foreach ( $serverArray as $server )
{
if ( $plugin -> { 'add_' . $server } == 1 && is_numeric ( $plugin -> { $server }) && $plugin -> { $server } > 0 )
{
// get the server protocol
$plugin -> { $server . '_protocol' } = ComponentbuilderHelper :: getVar ( 'server' , ( int ) $plugin -> { $server }, 'id' , 'protocol' );
}
else
2019-08-04 22:38:53 +00:00
{
2019-08-22 01:54:47 +00:00
$plugin -> { $server } = 0 ;
// only change this for sales server (update server can be added loacaly to the zip file)
if ( 'sales_server' === $server )
{
$plugin -> { 'add_' . $server } = 0 ;
}
$plugin -> { $server . '_protocol' } = 0 ;
2019-08-04 22:38:53 +00:00
}
}
2019-08-22 01:54:47 +00:00
// set the update server stuff (TODO)
// update_server_xml_path
// update_server_xml_file_name
2019-08-08 15:35:58 +00:00
2019-08-22 01:54:47 +00:00
// rest globals
$this -> target = $_backup_target ;
$this -> lang = $_backup_lang ;
$this -> langPrefix = $_backup_langPrefix ;
2019-08-04 22:38:53 +00:00
2019-08-26 06:54:16 +00:00
unset ( $this -> placeholders [ $this -> bbb . 'Plugin_name' . $this -> ddd ]);
unset ( $this -> placeholders [ $this -> bbb . 'Plugin' . $this -> ddd ]);
unset ( $this -> placeholders [ $this -> bbb . 'plugin' . $this -> ddd ]);
unset ( $this -> placeholders [ $this -> bbb . 'Plugin_group' . $this -> ddd ]);
unset ( $this -> placeholders [ $this -> bbb . 'plugin_group' . $this -> ddd ]);
unset ( $this -> placeholders [ $this -> bbb . 'plugin.version' . $this -> ddd ]);
unset ( $this -> placeholders [ $this -> bbb . 'plugin_version' . $this -> ddd ]);
2019-08-22 01:54:47 +00:00
$this -> joomlaPlugins [ $id ] = $plugin ;
return true ;
}
2019-07-28 21:48:42 +00:00
}
return false ;
}
2019-08-04 22:38:53 +00:00
/**
* get the plugin xml template
*
* @ return string
*
*/
public function getPluginXMLTemplate ( & $plugin )
{
$xml = '<?xml version="1.0" encoding="utf-8"?>' ;
$xml .= PHP_EOL . '<extension type="plugin" version="3.8" group="' . strtolower ( $plugin -> group ) . '" method="upgrade">' ;
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<name>' . $plugin -> lang_prefix . '</name>' ;
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<creationDate>' . $this -> hhh . 'BUILDDATE' . $this -> hhh . '</creationDate>' ;
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<author>' . $this -> hhh . 'AUTHOR' . $this -> hhh . '</author>' ;
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<authorEmail>' . $this -> hhh . 'AUTHOREMAIL' . $this -> hhh . '</authorEmail>' ;
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<authorUrl>' . $this -> hhh . 'AUTHORWEBSITE' . $this -> hhh . '</authorUrl>' ;
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<copyright>' . $this -> hhh . 'COPYRIGHT' . $this -> hhh . '</copyright>' ;
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<license>' . $this -> hhh . 'LICENSE' . $this -> hhh . '</license>' ;
2019-08-08 15:35:58 +00:00
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<version>' . $plugin -> plugin_version . '</version>' ;
2019-08-04 22:38:53 +00:00
$xml .= PHP_EOL . $this -> _t ( 1 ) . '<description>' . $plugin -> lang_prefix . '_XML_DESCRIPTION</description>' ;
$xml .= $this -> hhh . 'MAINXML' . $this -> hhh ;
$xml .= PHP_EOL . '</extension>' ;
return $xml ;
}
2017-02-13 23:24:38 +00:00
/**
* check if we already have these ids in local memory
*
* @ return void
*
*/
2018-11-27 13:05:47 +00:00
protected function checkCustomCodeMemory ( $ids )
2017-02-13 23:24:38 +00:00
{
// reset custom code
$this -> customCode = array ();
foreach ( $ids as $pointer => $id )
{
if ( isset ( $this -> customCodeMemory [ $id ]))
{
$this -> customCode [] = $this -> customCodeMemory [ $id ];
unset ( $ids [ $pointer ]);
}
}
// check if any ids left to fetch
if ( ComponentbuilderHelper :: checkArray ( $ids ))
{
return $ids ;
}
return false ;
}
2017-12-14 23:10:47 +00:00
2017-02-01 13:17:04 +00:00
/**
* store the code
*
* @ param int $when To set when to update
*
* @ return void
*
*/
2017-02-13 23:24:38 +00:00
protected function setNewCustomCode ( $when = 1 )
2017-02-01 13:17:04 +00:00
{
2019-09-05 21:12:56 +00:00
if ( count (( array ) $this -> newCustomCode ) >= $when )
2017-02-01 13:17:04 +00:00
{
// Create a new query object.
2017-02-13 23:24:38 +00:00
$query = $this -> db -> getQuery ( true );
2017-02-11 02:24:26 +00:00
$continue = false ;
2017-02-01 13:17:04 +00:00
// Insert columns.
2017-12-14 23:10:47 +00:00
$columns = array ( 'path' , 'type' , 'target' , 'comment_type' , 'component' , 'published' , 'created' , 'created_by' , 'version' , 'access' , 'hashtarget' , 'from_line' , 'to_line' , 'code' , 'hashendtarget' );
2017-02-01 13:17:04 +00:00
// Prepare the insert query.
2017-02-13 23:24:38 +00:00
$query -> insert ( $this -> db -> quoteName ( '#__componentbuilder_custom_code' ));
$query -> columns ( $this -> db -> quoteName ( $columns ));
2017-12-14 23:10:47 +00:00
foreach ( $this -> newCustomCode as $values )
2017-02-09 16:11:10 +00:00
{
2019-09-05 21:12:56 +00:00
if ( count (( array ) $values ) == 15 )
2017-02-09 16:11:10 +00:00
{
$query -> values ( implode ( ',' , $values ));
2017-02-11 02:24:26 +00:00
$continue = true ;
2017-02-09 16:11:10 +00:00
}
else
{
// TODO line mismatch... should not happen
}
2017-02-01 13:17:04 +00:00
}
// clear the values array
$this -> newCustomCode = array ();
2017-02-11 02:24:26 +00:00
if ( ! $continue )
{
return false ; // insure we dont continue if no values were loaded
}
2017-02-01 13:17:04 +00:00
// Set the query using our newly populated query object and execute it.
2017-02-13 23:24:38 +00:00
$this -> db -> setQuery ( $query );
$this -> db -> execute ();
2017-02-01 13:17:04 +00:00
}
}
2017-12-14 23:10:47 +00:00
2017-02-01 13:17:04 +00:00
/**
* store the code
*
* @ param int $when To set when to update
*
* @ return void
*
*/
2017-02-13 23:24:38 +00:00
protected function setExistingCustomCode ( $when = 1 )
2017-02-01 13:17:04 +00:00
{
2019-09-05 21:12:56 +00:00
if ( count (( array ) $this -> existingCustomCode ) >= $when )
2017-02-01 13:17:04 +00:00
{
2017-12-14 23:10:47 +00:00
foreach ( $this -> existingCustomCode as $code )
2017-02-01 13:17:04 +00:00
{
// Create a new query object.
2017-02-13 23:24:38 +00:00
$query = $this -> db -> getQuery ( true );
2017-02-01 13:17:04 +00:00
// Prepare the update query.
2017-02-13 23:24:38 +00:00
$query -> update ( $this -> db -> quoteName ( '#__componentbuilder_custom_code' )) -> set ( $code [ 'fields' ]) -> where ( $code [ 'conditions' ]);
2017-02-01 13:17:04 +00:00
// Set the query using our newly populated query object and execute it.
2017-02-13 23:24:38 +00:00
$this -> db -> setQuery ( $query );
$this -> db -> execute ();
2017-02-01 13:17:04 +00:00
}
// clear the values array
2017-12-14 23:10:47 +00:00
$this -> existingCustomCode = array ();
2017-02-01 13:17:04 +00:00
}
}
2017-12-14 23:10:47 +00:00
2017-02-01 13:17:04 +00:00
/**
* get the custom code from the local files
*
* @ param array $paths The local paths to parse
* @ param string $today The date for today
*
* @ return void
*
*/
2017-02-13 23:24:38 +00:00
protected function customCodeFactory ( & $paths , & $today )
2017-02-01 13:17:04 +00:00
{
// we must first store the current woking directory
$joomla = getcwd ();
2017-02-14 00:33:24 +00:00
$counter = array ( 1 => 0 , 2 => 0 );
// file types to get
2019-05-20 12:14:43 +00:00
$fileTypes = array ( '\.php' , '\.js' , '\.xml' );
2019-07-28 21:48:42 +00:00
2017-02-11 02:24:26 +00:00
// set some local placeholders
2019-07-28 21:48:42 +00:00
$placeholders = array_flip ( $this -> globalPlaceholders );
2018-05-22 19:01:36 +00:00
$placeholders [ ComponentbuilderHelper :: safeString ( $this -> componentCodeName , 'F' ) . 'Helper::' ] = $this -> bbb . 'Component' . $this -> ddd . 'Helper::' ;
$placeholders [ 'COM_' . ComponentbuilderHelper :: safeString ( $this -> componentCodeName , 'U' )] = 'COM_' . $this -> bbb . 'COMPONENT' . $this -> ddd ;
$placeholders [ 'com_' . $this -> componentCodeName ] = 'com_' . $this -> bbb . 'component' . $this -> ddd ;
2019-07-28 21:48:42 +00:00
// putt the last first
$placeholders = array_reverse ( $placeholders , true );
2019-02-15 22:03:21 +00:00
2017-02-01 13:17:04 +00:00
foreach ( $paths as $target => $path )
{
// we are changing the working directory to the componet path
chdir ( $path );
2017-02-14 00:33:24 +00:00
foreach ( $fileTypes as $type )
2017-02-01 13:17:04 +00:00
{
2019-05-20 12:14:43 +00:00
// get a list of files in the current directory tree (only PHP, JS and XML for now)
2017-02-14 00:33:24 +00:00
$files = JFolder :: files ( '.' , $type , true , true );
2019-05-20 12:14:43 +00:00
// check if files found
if ( ComponentbuilderHelper :: checkArray ( $files ))
2017-02-01 13:17:04 +00:00
{
2019-05-20 12:14:43 +00:00
foreach ( $files as $file )
2017-02-14 00:33:24 +00:00
{
2019-05-20 12:14:43 +00:00
$this -> searchFileContent ( $counter , $file , $target , $this -> customCodePlaceholders , $placeholders , $today );
// insert new code
if ( ComponentbuilderHelper :: checkArray ( $this -> newCustomCode ))
{
$this -> setNewCustomCode ( 100 );
}
// update existing custom code
if ( ComponentbuilderHelper :: checkArray ( $this -> existingCustomCode ))
{
$this -> setExistingCustomCode ( 30 );
}
2017-02-14 00:33:24 +00:00
}
2017-02-01 13:17:04 +00:00
}
}
}
// change back to Joomla working directory
chdir ( $joomla );
// make sure all code is stored
if ( ComponentbuilderHelper :: checkArray ( $this -> newCustomCode ))
{
2017-02-13 23:24:38 +00:00
$this -> setNewCustomCode ();
2017-02-01 13:17:04 +00:00
}
// update existing custom code
if ( ComponentbuilderHelper :: checkArray ( $this -> existingCustomCode ))
{
2017-02-13 23:24:38 +00:00
$this -> setExistingCustomCode ();
2017-02-01 13:17:04 +00:00
}
}
2017-12-14 23:10:47 +00:00
2017-02-01 13:17:04 +00:00
/**
* search a file for placeholders and store result
*
* @ param array $counter The counter for the arrays
* @ param string $file The file path to search
2017-02-11 02:24:26 +00:00
* @ param array $searchArray The values to search for
* @ param array $placeholders The values to replace in the code being stored
2017-02-01 13:17:04 +00:00
* @ param string $today The date for today
*
* @ return array on success
*
*/
2017-02-13 23:24:38 +00:00
protected function searchFileContent ( & $counter , & $file , & $target , & $searchArray , & $placeholders , & $today )
2017-02-01 13:17:04 +00:00
{
2019-07-28 21:48:42 +00:00
// we add a new search for the GUI CODE Blocks
2019-09-11 14:50:42 +00:00
$this -> guiCodeSearch ( $file , $placeholders , $today , $target );
2017-02-01 13:17:04 +00:00
// reset each time per file
2017-12-14 23:10:47 +00:00
$loadEndFingerPrint = false ;
$endFingerPrint = array ();
$fingerPrint = array ();
$codeBucket = array ();
$pointer = array ();
$reading = array ();
$reader = 0 ;
2017-02-13 23:24:38 +00:00
// reset found Start type
2017-12-14 23:10:47 +00:00
$commentType = 0 ;
2017-02-09 16:11:10 +00:00
// make sure we have the path correct (the script file is not in admin path for example)
// there may be more... will nead to keep our eye on this... since files could be moved during install
2019-03-13 12:20:51 +00:00
$file = str_replace ( './' , '' , $file ); # TODO (windows path issues)
2017-02-09 16:11:10 +00:00
if ( $file !== 'script.php' )
{
2017-12-14 23:10:47 +00:00
$path = $target . '/' . $file ;
2017-02-09 16:11:10 +00:00
}
else
{
2017-12-14 23:10:47 +00:00
$path = $file ;
}
2018-03-24 01:36:07 +00:00
// now we go line by line
2017-02-01 13:17:04 +00:00
foreach ( new SplFileObject ( $file ) as $lineNumber => $lineContent )
{
// we musk keep last few lines to dynamic find target entry later
$fingerPrint [ $lineNumber ] = trim ( $lineContent );
// load the end fingerprint
if ( $loadEndFingerPrint )
{
$endFingerPrint [ $lineNumber ] = trim ( $lineContent );
}
2017-02-11 02:24:26 +00:00
foreach ( $searchArray as $type => $search )
2017-02-01 13:17:04 +00:00
{
2017-12-14 23:10:47 +00:00
$i = ( int ) ( $type == 3 || $type == 4 ) ? 2 : 1 ;
$_type = ( int ) ( $type == 1 || $type == 3 ) ? 1 : 2 ;
2017-02-01 13:17:04 +00:00
if ( $reader === 0 || $reader === $i )
{
2017-12-14 23:10:47 +00:00
$targetKey = $type ;
$start = '/***[' . $search . '***/' ;
$end = '/***[/' . $search . '***/' ;
$startHTML = '<!--[' . $search . '-->' ;
$endHTML = '<!--[/' . $search . '-->' ;
2017-02-01 13:17:04 +00:00
// check if the ending place holder was found
2017-12-14 23:10:47 +00:00
if ( isset ( $reading [ $targetKey ]) && $reading [ $targetKey ] &&
(( trim ( $lineContent ) === $end || strpos ( $lineContent , $end ) !== false ) ||
2017-02-13 23:24:38 +00:00
( trim ( $lineContent ) === $endHTML || strpos ( $lineContent , $endHTML ) !== false )))
2017-02-01 13:17:04 +00:00
{
2017-02-13 23:24:38 +00:00
// trim the placeholder and if there is still data then load it
2019-11-08 16:07:08 +00:00
if ( isset ( $endReplace ) && ( $_line = $this -> addLineChecker ( $endReplace , 2 , $lineContent )) !== false )
2017-02-13 23:24:38 +00:00
{
$codeBucket [ $pointer [ $targetKey ]][] = $_line ;
}
2017-02-01 13:17:04 +00:00
// deactivate the reader
2017-12-14 23:10:47 +00:00
$reading [ $targetKey ] = false ;
2017-02-01 13:17:04 +00:00
if ( $_type == 2 )
{
// deactivate search
2017-12-14 23:10:47 +00:00
$reader = 0 ;
2017-02-01 13:17:04 +00:00
}
else
{
// activate fingerPrint for replacement end target
2017-12-14 23:10:47 +00:00
$loadEndFingerPrint = true ;
$backupTargetKey = $targetKey ;
$backupI = $i ;
2017-02-01 13:17:04 +00:00
}
// all new records we can do a bulk insert
if ( $i === 1 )
{
// end the bucket info for this code block
2017-12-14 23:10:47 +00:00
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote (( int ) $lineNumber ); // 'toline'
2017-02-13 23:24:38 +00:00
// first reverse engineer this code block
2019-09-11 14:50:42 +00:00
$c0de = $this -> reversePlaceholders ( implode ( '' , $codeBucket [ $pointer [ $targetKey ]]), $placeholders , $target );
2017-12-14 23:10:47 +00:00
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( base64_encode ( $c0de )); // 'code'
2017-02-01 13:17:04 +00:00
if ( $_type == 2 )
{
// load the last value
2018-03-18 04:52:07 +00:00
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( 0 ); // 'hashendtarget'
2017-02-01 13:17:04 +00:00
}
}
2017-02-16 14:02:23 +00:00
// the record already exist so we must update instead
2017-02-01 13:17:04 +00:00
elseif ( $i === 2 )
{
2017-02-13 23:24:38 +00:00
// end the bucket info for this code block
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'fields' ][] = $this -> db -> quoteName ( 'to_line' ) . ' = ' . $this -> db -> quote ( $lineNumber );
// first reverse engineer this code block
2019-09-11 14:50:42 +00:00
$c0de = $this -> reversePlaceholders ( implode ( '' , $codeBucket [ $pointer [ $targetKey ]]), $placeholders , $target , $this -> existingCustomCode [ $pointer [ $targetKey ]][ 'id' ]);
2017-02-13 23:24:38 +00:00
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'fields' ][] = $this -> db -> quoteName ( 'code' ) . ' = ' . $this -> db -> quote ( base64_encode ( $c0de ));
2017-02-01 13:17:04 +00:00
if ( $_type == 2 )
{
// load the last value
2017-02-13 23:24:38 +00:00
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'fields' ][] = $this -> db -> quoteName ( 'hashendtarget' ) . ' = ' . $this -> db -> quote ( 0 );
2017-02-01 13:17:04 +00:00
}
}
}
// check if the endfingerprint is ready to save
2019-09-05 21:12:56 +00:00
if ( count (( array ) $endFingerPrint ) === 3 )
2017-02-01 13:17:04 +00:00
{
2017-12-14 23:10:47 +00:00
$hashendtarget = '3__' . md5 ( implode ( '' , $endFingerPrint ));
2017-02-01 13:17:04 +00:00
// all new records we can do a bulk insert
if ( $i === 1 )
{
// load the last value
2017-12-14 23:10:47 +00:00
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( $hashendtarget ); // 'hashendtarget'
2017-02-01 13:17:04 +00:00
}
// the record already exist so we must use module to update
elseif ( $i === 2 )
{
2017-02-13 23:24:38 +00:00
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'fields' ][] = $this -> db -> quoteName ( 'hashendtarget' ) . ' = ' . $this -> db -> quote ( $hashendtarget );
2017-02-01 13:17:04 +00:00
}
// reset the needed values
2017-12-14 23:10:47 +00:00
$endFingerPrint = array ();
$loadEndFingerPrint = false ;
2017-02-01 13:17:04 +00:00
// deactivate reader (to allow other search)
2017-12-14 23:10:47 +00:00
$reader = 0 ;
2017-02-01 13:17:04 +00:00
}
// then read in the code
if ( isset ( $reading [ $targetKey ]) && $reading [ $targetKey ])
{
2017-02-13 23:24:38 +00:00
$codeBucket [ $pointer [ $targetKey ]][] = $lineContent ;
2017-02-01 13:17:04 +00:00
}
2017-02-13 23:24:38 +00:00
// see if the custom code line starts now with PHP/JS comment type
if (( ! isset ( $reading [ $targetKey ]) || ! $reading [ $targetKey ]) && (( $i === 1 && trim ( $lineContent ) === $start ) || strpos ( $lineContent , $start ) !== false ))
{
2017-12-14 23:10:47 +00:00
$commentType = 1 ; // PHP/JS type
$startReplace = $start ;
$endReplace = $end ;
2017-02-13 23:24:38 +00:00
}
// see if the custom code line starts now with HTML comment type
elseif (( ! isset ( $reading [ $targetKey ]) || ! $reading [ $targetKey ]) && (( $i === 1 && trim ( $lineContent ) === $startHTML ) || strpos ( $lineContent , $startHTML ) !== false ))
2017-02-01 13:17:04 +00:00
{
2017-12-14 23:10:47 +00:00
$commentType = 2 ; // HTML type
$startReplace = $startHTML ;
$endReplace = $endHTML ;
2017-02-13 23:24:38 +00:00
}
// check if the starting place holder was found
2017-12-14 23:10:47 +00:00
if ( $commentType > 0 )
{
2017-02-16 14:02:23 +00:00
// if we have all on one line we have a problem (don't load it TODO)
2017-02-13 23:24:38 +00:00
if ( strpos ( $lineContent , $endReplace ) !== false )
{
2017-02-16 14:02:23 +00:00
// reset found comment type
$commentType = 0 ;
2018-09-25 20:02:48 +00:00
$this -> app -> enqueueMessage ( JText :: _ ( '<hr /><h3>Custom Codes Warning</h3>' ), 'Warning' );
2018-02-06 10:55:46 +00:00
$this -> app -> enqueueMessage ( JText :: sprintf ( 'We found dynamic code <b>all in one line</b>, and ignored it! Please review (%s) for more details!' , $path ), 'Warning' );
2017-02-13 23:24:38 +00:00
continue ;
}
2017-02-11 02:24:26 +00:00
// do a quick check to insure we have an id
$id = false ;
2017-02-09 16:11:10 +00:00
if ( $i === 2 )
{
2017-02-13 23:24:38 +00:00
$id = $this -> getSystemID ( $lineContent , array ( 1 => $start , 2 => $startHTML ), $commentType );
2017-02-09 16:11:10 +00:00
}
if ( $i === 2 && $id > 0 )
{
// make sure we update it only once even if found again.
if ( isset ( $this -> codeAreadyDone [ $id ]))
{
2017-02-16 14:02:23 +00:00
// reset found comment type
$commentType = 0 ;
2017-02-09 16:11:10 +00:00
continue ;
}
// store the id to avoid duplication
$this -> codeAreadyDone [ $id ] = ( int ) $id ;
}
2017-02-13 23:24:38 +00:00
// start replace
$startReplace = $this -> setStartReplace ( $id , $commentType , $startReplace );
2017-02-01 13:17:04 +00:00
// set active reader (to lock out other search)
2017-12-14 23:10:47 +00:00
$reader = $i ;
2017-02-01 13:17:04 +00:00
// set pointer
2017-12-14 23:10:47 +00:00
$pointer [ $targetKey ] = $counter [ $i ];
2017-02-01 13:17:04 +00:00
// activate the reader
2017-12-14 23:10:47 +00:00
$reading [ $targetKey ] = true ;
2017-02-01 13:17:04 +00:00
// start code bucket
2017-12-14 23:10:47 +00:00
$codeBucket [ $pointer [ $targetKey ]] = array ();
2017-02-13 23:24:38 +00:00
// trim the placeholder and if there is still data then load it
if ( $_line = $this -> addLineChecker ( $startReplace , 1 , $lineContent ))
{
$codeBucket [ $pointer [ $targetKey ]][] = $_line ;
}
2017-02-01 13:17:04 +00:00
// get the finger print around the custom code
2017-12-14 23:10:47 +00:00
$inFinger = count ( $fingerPrint );
$getFinger = $inFinger - 1 ;
$hasharray = array_slice ( $fingerPrint , - $inFinger , $getFinger , true );
$hasleng = count ( $hasharray );
$hashtarget = $hasleng . '__' . md5 ( implode ( '' , $hasharray ));
2019-03-13 12:20:51 +00:00
// for good practice
ComponentbuilderHelper :: fixPath ( $path );
2019-09-11 14:50:42 +00:00
// all new records we can do a bulk insert
2017-02-01 13:17:04 +00:00
if ( $i === 1 || ! $id )
{
// start the bucket for this code
2017-12-14 23:10:47 +00:00
$this -> newCustomCode [ $pointer [ $targetKey ]] = array ();
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( $path ); // 'path'
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote (( int ) $_type ); // 'type'
2018-03-18 04:52:07 +00:00
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( 1 ); // 'target'
2017-12-14 23:10:47 +00:00
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( $commentType ); // 'comment_type'
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote (( int ) $this -> componentID ); // 'component'
2018-03-18 04:52:07 +00:00
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( 1 ); // 'published'
2017-12-14 23:10:47 +00:00
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( $today ); // 'created'
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote (( int ) $this -> user -> id ); // 'created_by'
2018-03-18 04:52:07 +00:00
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( 1 ); // 'version'
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( 1 ); // 'access'
2017-12-14 23:10:47 +00:00
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( $hashtarget ); // 'hashtarget'
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote (( int ) $lineNumber ); // 'fromline'
2017-02-01 13:17:04 +00:00
}
// the record already exist so we must update instead
elseif ( $i === 2 && $id > 0 )
{
// start the bucket for this code
2017-12-14 23:10:47 +00:00
$this -> existingCustomCode [ $pointer [ $targetKey ]] = array ();
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'id' ] = ( int ) $id ;
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'conditions' ] = array ();
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'conditions' ][] = $this -> db -> quoteName ( 'id' ) . ' = ' . $this -> db -> quote ( $id );
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'fields' ] = array ();
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'fields' ][] = $this -> db -> quoteName ( 'path' ) . ' = ' . $this -> db -> quote ( $path );
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'fields' ][] = $this -> db -> quoteName ( 'type' ) . ' = ' . $this -> db -> quote ( $_type );
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'fields' ][] = $this -> db -> quoteName ( 'comment_type' ) . ' = ' . $this -> db -> quote ( $commentType );
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'fields' ][] = $this -> db -> quoteName ( 'component' ) . ' = ' . $this -> db -> quote ( $this -> componentID );
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'fields' ][] = $this -> db -> quoteName ( 'from_line' ) . ' = ' . $this -> db -> quote ( $lineNumber );
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'fields' ][] = $this -> db -> quoteName ( 'modified' ) . ' = ' . $this -> db -> quote ( $today );
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'fields' ][] = $this -> db -> quoteName ( 'modified_by' ) . ' = ' . $this -> db -> quote ( $this -> user -> id );
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'fields' ][] = $this -> db -> quoteName ( 'hashtarget' ) . ' = ' . $this -> db -> quote ( $hashtarget );
2017-02-01 13:17:04 +00:00
}
2017-02-09 16:11:10 +00:00
else // this should actualy never happen
{
// de activate the reader
2017-12-14 23:10:47 +00:00
$reading [ $targetKey ] = false ;
$reader = 0 ;
2017-02-09 16:11:10 +00:00
}
2017-02-13 23:24:38 +00:00
// reset found comment type
$commentType = 0 ;
2017-02-01 13:17:04 +00:00
// update the counter
2017-12-14 23:10:47 +00:00
$counter [ $i ] ++ ;
2017-02-01 13:17:04 +00:00
}
}
}
// make sure only a few lines is kept at a time
2019-09-05 21:12:56 +00:00
if ( count (( array ) $fingerPrint ) > 10 )
2017-02-01 13:17:04 +00:00
{
$fingerPrint = array_slice ( $fingerPrint , - 6 , 6 , true );
}
}
// if the code is at the end of the page and there were not three more lines
2019-09-05 21:12:56 +00:00
if ( count (( array ) $endFingerPrint ) > 0 || $loadEndFingerPrint )
2017-02-01 13:17:04 +00:00
{
2019-09-05 21:12:56 +00:00
if ( count (( array ) $endFingerPrint ) > 0 )
2017-02-01 13:17:04 +00:00
{
$leng = count ( $endFingerPrint );
2017-12-14 23:10:47 +00:00
$hashendtarget = $leng . '__' . md5 ( implode ( '' , $endFingerPrint ));
2017-02-01 13:17:04 +00:00
}
else
{
$hashendtarget = 0 ;
}
// all new records we can do a buldk insert
2017-02-09 16:11:10 +00:00
if ( $backupI === 1 )
2017-02-01 13:17:04 +00:00
{
// load the last value
2017-12-14 23:10:47 +00:00
$this -> newCustomCode [ $pointer [ $backupTargetKey ]][] = $this -> db -> quote ( $hashendtarget ); // 'hashendtarget'
2017-02-01 13:17:04 +00:00
}
// the record already exist so we must use module to update
2017-02-09 16:11:10 +00:00
elseif ( $backupI === 2 )
2017-02-01 13:17:04 +00:00
{
2017-02-13 23:24:38 +00:00
$this -> existingCustomCode [ $pointer [ $backupTargetKey ]][ 'fields' ][] = $this -> db -> quoteName ( 'hashendtarget' ) . ' = ' . $this -> db -> quote ( $hashendtarget );
2017-02-01 13:17:04 +00:00
}
}
}
2017-12-14 23:10:47 +00:00
2019-07-28 21:48:42 +00:00
/**
* Set the JCB GUI code placeholder
*
* @ param string $string The code string
* @ param array $config The placeholder config values
*
2019-12-03 02:17:35 +00:00
* @ return string
2019-07-28 21:48:42 +00:00
*
*/
public function setGuiCodePlaceholder ( $string , $config )
{
if ( ComponentbuilderHelper :: checkString ( $string ))
{
if ( $this -> addPlaceholders && $this -> canAddGuiCodePlaceholder ( $string )
&& ComponentbuilderHelper :: checkArray ( $config )
&& isset ( $config [ 'table' ]) && ComponentbuilderHelper :: checkString ( $config [ 'table' ])
&& isset ( $config [ 'field' ]) && ComponentbuilderHelper :: checkString ( $config [ 'field' ])
&& isset ( $config [ 'type' ]) && ComponentbuilderHelper :: checkString ( $config [ 'type' ])
&& isset ( $config [ 'id' ]) && is_numeric ( $config [ 'id' ]))
{
// if we have a key we must get the ID
if ( isset ( $config [ 'key' ]) && ComponentbuilderHelper :: checkString ( $config [ 'key' ]) && $config [ 'key' ] !== 'id' )
{
if (( $id = ComponentbuilderHelper :: getVar ( $config [ 'table' ], $config [ 'id' ], $config [ 'key' ], 'id' )) !== false && is_numeric ( $id ))
{
$config [ 'id' ] = $id ;
}
else
{
// we must give a error message to inform the user of this issue. (should never happen)
$this -> app -> enqueueMessage ( JText :: sprintf ( 'ID mismatch was detected with the %s.%s.%s.%s GUI code field. So the placeholder was not set.' , $config [ 'table' ], $config [ 'field' ], $config [ 'key' ], $config [ 'id' ]), 'Error' );
// check some config
if ( ! isset ( $config [ 'prefix' ]))
{
$config [ 'prefix' ] = '' ;
}
return $config [ 'prefix' ] . $string ;
}
}
// check some config
if ( ! isset ( $config [ 'prefix' ]))
{
$config [ 'prefix' ] = PHP_EOL ;
}
// add placheolder based on type of code
switch ( strtolower ( $config [ 'type' ]))
{
// adding with html commenting
case 'html' :
$front = $config [ 'prefix' ] . '<!--' . '[JCBGUI.' ;
$sufix = '$$$$]-->' . PHP_EOL ;
$back = '<!--[/JCBGUI' . $sufix ;
break ;
// adding with php commenting
default :
$front = $config [ 'prefix' ] . '/***' . '[JCBGUI.' ;
$sufix = '$$$$]***/' . PHP_EOL ;
$back = '/***[/JCBGUI' . $sufix ;
break ;
}
return $front . $config [ 'table' ] . '.' . $config [ 'field' ] . '.' . $config [ 'id' ] . '.' . $sufix . $string . $back ;
}
// check some config
if ( ! isset ( $config [ 'prefix' ]))
{
$config [ 'prefix' ] = '' ;
}
return $config [ 'prefix' ] . $string ;
}
return $string ;
}
/**
* search a code to see if there is already any custom
* code or other reasons not to add the GUI code placeholders
*
* @ param string $code The code to check
*
* @ return boolean true if GUI code placeholders can be added
*
*/
protected function canAddGuiCodePlaceholder ( & $code )
{
// check for customcode placeholders
if ( strpos ( $code , '$$$$' ) !== false )
{
// we do not add GUI wrapper placeholder to code
// that already has any customcode placeholders
return false ;
}
return true ;
}
/**
* search a file for gui code blocks that were updated in the IDE
*
* @ param string $file The file path to search
* @ param array $placeholders The values to replace in the code being stored
* @ param string $today The date for today
2019-09-11 14:50:42 +00:00
* @ param string $target The target path type
2019-07-28 21:48:42 +00:00
*
* @ return void
*
*/
2019-09-11 14:50:42 +00:00
protected function guiCodeSearch ( & $file , & $placeholders , & $today , & $target )
2019-07-28 21:48:42 +00:00
{
// get file content
$file_conent = ComponentbuilderHelper :: getFileContents ( $file );
$guiCode = array ();
// we add a new search for the GUI CODE Blocks
$guiCode [] = ComponentbuilderHelper :: getAllBetween ( $file_conent , '/***[JCB' . 'GUI<>' , '/***[/JCBGUI' . '$$$$]***/' );
$guiCode [] = ComponentbuilderHelper :: getAllBetween ( $file_conent , '<!--[JCB' . 'GUI<>' , '<!--[/JCBGUI' . '$$$$]-->' );
if (( $guiCode = ComponentbuilderHelper :: mergeArrays ( $guiCode )) !== false && ComponentbuilderHelper :: checkArray ( $guiCode , true ))
{
foreach ( $guiCode as $code )
{
$first_line = strtok ( $code , PHP_EOL );
// get the GUI target details
2019-09-11 14:50:42 +00:00
$query = explode ( '.' , trim ( $first_line , '.' ));
2019-12-03 02:17:35 +00:00
// only continue if we have 3 values in the query
2019-12-23 03:47:19 +00:00
if ( is_array ( $query ) && count ( $query ) >= 3 )
2019-12-03 02:17:35 +00:00
{
// cleanup the newlines around the code
$code = trim ( str_replace ( $first_line , '' , $code ), PHP_EOL ) . PHP_EOL ;
// set the ID
$id = ( int ) $query [ 2 ];
// make the field name save
$field = ComponentbuilderHelper :: safeFieldName ( $query [ 1 ]);
// make the table name save
$table = ComponentbuilderHelper :: safeString ( $query [ 0 ]);
// reverse placeholder as much as we can
$code = $this -> reversePlaceholders ( $code , $placeholders , $target , $id , $field , $table );
// update the GUI/Tables/Database
$object = new stdClass ();
$object -> id = $id ;
$object -> { $field } = base64_encode ( $code ); // (TODO) this may not always work...
// update the value in GUI
$this -> db -> updateObject ( '#__componentbuilder_' . ( string ) $table , $object , 'id' );
}
2019-07-28 21:48:42 +00:00
}
}
}
2017-02-13 23:24:38 +00:00
/**
* Check if this line should be added
*
2019-11-08 16:07:08 +00:00
* @ param string $replaceKey The key to remove from line
* @ param int $type The line type
* @ param string $lineContent The line to check
2017-02-13 23:24:38 +00:00
*
* @ return bool true on success
*
*/
protected function addLineChecker ( $replaceKey , $type , $lineContent )
{
$check = explode ( $replaceKey , $lineContent );
2017-12-14 23:10:47 +00:00
switch ( $type )
2017-02-13 23:24:38 +00:00
{
case 1 :
// beginning of code
$i = trim ( $check [ 1 ]);
if ( ComponentbuilderHelper :: checkString ( $i ))
{
return $check [ 1 ];
}
2017-12-14 23:10:47 +00:00
break ;
2017-02-13 23:24:38 +00:00
case 2 :
// end of code
$i = trim ( $check [ 0 ]);
if ( ComponentbuilderHelper :: checkString ( $i ))
{
return $check [ 0 ];
}
2017-12-14 23:10:47 +00:00
break ;
2017-02-13 23:24:38 +00:00
}
return false ;
}
2017-12-14 23:10:47 +00:00
2017-02-13 23:24:38 +00:00
/**
2018-04-19 15:52:47 +00:00
* set the start replace placeholder
2017-02-13 23:24:38 +00:00
*
* @ param int $id The comment id
* @ param int $commentType The comment type
* @ param string $startReplace The main replace string
*
* @ return array on success
*
*/
protected function setStartReplace ( $id , $commentType , $startReplace )
{
if ( $id > 0 )
{
2017-12-14 23:10:47 +00:00
switch ( $commentType )
2017-02-13 23:24:38 +00:00
{
2017-10-30 18:50:56 +00:00
case 1 : // the PHP & JS type
2017-12-14 23:10:47 +00:00
$startReplace .= '/*' . $id . '*/' ;
break ;
2017-10-30 18:50:56 +00:00
case 2 : // the HTML type
2017-12-14 23:10:47 +00:00
$startReplace .= '<!--' . $id . '-->' ;
break ;
2017-02-13 23:24:38 +00:00
}
}
return $startReplace ;
}
2017-12-14 23:10:47 +00:00
2017-02-01 13:17:04 +00:00
/**
* search for the system id in the line given
*
* @ param string $lineContent The file path to search
* @ param string $placeholders The values to search for
2018-04-19 15:52:47 +00:00
* @ param int $commentType The comment type
2017-02-01 13:17:04 +00:00
*
* @ return array on success
*
*/
2017-02-13 23:24:38 +00:00
protected function getSystemID ( & $lineContent , $placeholders , $commentType )
2017-02-01 13:17:04 +00:00
{
2017-02-13 23:24:38 +00:00
$trim = '/' ;
if ( $commentType == 2 )
{
$trim = '<!--' ;
}
2017-02-01 13:17:04 +00:00
// remove place holder from content
2017-12-14 23:10:47 +00:00
$string = trim ( str_replace ( $placeholders [ $commentType ] . $trim , '' , $lineContent ));
2017-02-01 13:17:04 +00:00
// now get all numbers
$numbers = array ();
preg_match_all ( '!\d+!' , $string , $numbers );
// return the first number
if ( isset ( $numbers [ 0 ]) && ComponentbuilderHelper :: checkArray ( $numbers [ 0 ]))
{
return reset ( $numbers [ 0 ]);
}
return false ;
}
2017-12-14 23:10:47 +00:00
2017-02-11 02:24:26 +00:00
/**
2018-04-19 15:52:47 +00:00
* Reverse Engineer the dynamic placeholders ( TODO hmmmm this is not ideal )
2017-02-11 02:24:26 +00:00
*
2017-02-13 23:24:38 +00:00
* @ param string $string The string to revers
* @ param array $placeholders The values to search for
2019-09-11 14:50:42 +00:00
* @ param string $target The target path type
2019-07-28 21:48:42 +00:00
* @ param int $id The custom code id
* @ param string $field The field name
* @ param string $table The table name
2017-02-11 02:24:26 +00:00
*
* @ return string
*
*/
2019-09-11 14:50:42 +00:00
protected function reversePlaceholders ( $string , & $placeholders , & $target , $id = null , $field = 'code' , $table = 'custom_code' )
2017-02-11 02:24:26 +00:00
{
2017-02-13 23:24:38 +00:00
// get local code if set
2019-07-28 21:48:42 +00:00
if ( $id > 0 && $code = base64_decode ( ComponentbuilderHelper :: getVar ( $table , $id , 'id' , $field )))
2017-02-11 02:24:26 +00:00
{
2019-09-11 14:50:42 +00:00
$string = $this -> setReverseLangPlaceholders ( $string , $code , $target );
2017-02-13 23:24:38 +00:00
}
return $this -> setPlaceholders ( $string , $placeholders , 2 );
}
2017-12-14 23:10:47 +00:00
2017-02-13 23:24:38 +00:00
/**
2019-09-11 14:50:42 +00:00
* Set the langs strings for the reveres process
2017-02-13 23:24:38 +00:00
*
* @ param string $updateString The string to update
* @ param string $string The string to use lang update
2019-09-11 14:50:42 +00:00
* @ param string $target The target path type
2017-02-13 23:24:38 +00:00
*
2019-05-20 12:14:43 +00:00
* @ return string
2017-02-13 23:24:38 +00:00
*
*/
2019-09-11 14:50:42 +00:00
protected function setReverseLangPlaceholders ( $updateString , $string , & $target )
2017-02-13 23:24:38 +00:00
{
2017-12-14 13:30:21 +00:00
// get targets to search for
$langStringTargets = array_filter (
2017-12-14 23:10:47 +00:00
$this -> langStringTargets , function ( $get ) use ( $string )
2018-05-11 04:08:14 +00:00
{
if ( strpos ( $string , $get ) !== false )
2017-12-14 23:10:47 +00:00
{
2018-05-11 04:08:14 +00:00
return true ;
}
return false ;
});
2017-12-14 13:30:21 +00:00
// check if we should continue
if ( ComponentbuilderHelper :: checkArray ( $langStringTargets ))
2017-02-13 23:24:38 +00:00
{
2019-08-28 11:48:07 +00:00
// start lang holder
2017-02-13 23:24:38 +00:00
$langHolders = array ();
// set the lang for both since we don't know what area is being targeted
$_tmp = $this -> lang ;
2019-09-11 14:50:42 +00:00
// set the lang based on target
2019-12-06 05:31:32 +00:00
if ( strpos ( $target , 'module' ) !== false )
{
// backup lang prefix
$_tmp_lang_prefix = $this -> langPrefix ;
// set the new lang prefix
$this -> langPrefix = strtoupper ( str_replace ( 'module' , 'mod' , $target ));
// now set the lang
if ( isset ( $this -> langKeys [ $this -> langPrefix ]))
{
$this -> lang = $this -> langKeys [ $this -> langPrefix ];
}
else
{
$this -> lang = 'module' ;
}
}
elseif ( strpos ( $target , 'plugin' ) !== false )
2019-09-11 14:50:42 +00:00
{
// backup lang prefix
$_tmp_lang_prefix = $this -> langPrefix ;
// set the new lang prefix
$this -> langPrefix = strtoupper ( str_replace ( 'plugin' , 'plg' , $target ));
// now set the lang
if ( isset ( $this -> langKeys [ $this -> langPrefix ]))
{
$this -> lang = $this -> langKeys [ $this -> langPrefix ];
}
else
{
$this -> lang = 'plugin' ;
}
}
else
{
$this -> lang = 'both' ;
}
2017-02-13 23:24:38 +00:00
// set language data
2017-12-14 23:10:47 +00:00
foreach ( $langStringTargets as $langStringTarget )
2017-12-14 13:30:21 +00:00
{
2017-12-14 23:10:47 +00:00
$langCheck [] = ComponentbuilderHelper :: getAllBetween ( $string , $langStringTarget . " ' " , " ' " );
$langCheck [] = ComponentbuilderHelper :: getAllBetween ( $string , $langStringTarget . " ' " , " ' " );
2017-12-14 13:30:21 +00:00
}
2017-02-13 23:24:38 +00:00
// merge arrays
$langArray = ComponentbuilderHelper :: mergeArrays ( $langCheck );
// continue only if strings were found
2017-12-14 13:30:21 +00:00
if ( ComponentbuilderHelper :: checkArray ( $langArray )) //<-- not really needed hmmm
2017-02-11 02:24:26 +00:00
{
foreach ( $langArray as $lang )
{
2017-12-14 23:10:47 +00:00
$_keyLang = ComponentbuilderHelper :: safeString ( $lang , 'U' );
2017-02-13 23:24:38 +00:00
// this is there to insure we dont break already added Language strings
if ( $_keyLang === $lang )
2017-02-11 02:24:26 +00:00
{
2017-02-13 23:24:38 +00:00
continue ;
2017-02-11 02:24:26 +00:00
}
2019-07-04 23:53:54 +00:00
// build lang key
2017-12-14 23:10:47 +00:00
$keyLang = $this -> langPrefix . '_' . $_keyLang ;
2019-07-04 23:53:54 +00:00
// set lang content string
$this -> setLangContent ( $this -> lang , $keyLang , $lang );
2017-02-13 23:24:38 +00:00
// reverse the placeholders
2017-12-14 23:10:47 +00:00
foreach ( $langStringTargets as $langStringTarget )
2017-12-14 13:30:21 +00:00
{
2017-12-14 23:10:47 +00:00
$langHolders [ $langStringTarget . " ' " . $keyLang . " ' " ] = $langStringTarget . " ' " . $lang . " ' " ;
$langHolders [ $langStringTarget . '"' . $keyLang . '"' ] = $langStringTarget . '"' . $lang . '"' ;
2017-12-14 13:30:21 +00:00
}
2017-02-11 02:24:26 +00:00
}
2017-02-13 23:24:38 +00:00
// return the found placeholders
$updateString = $this -> setPlaceholders ( $updateString , $langHolders );
2017-02-11 02:24:26 +00:00
}
2017-02-13 23:24:38 +00:00
// reset the lang
$this -> lang = $_tmp ;
2019-09-11 14:50:42 +00:00
// also rest the lang prefix if set
if ( isset ( $_tmp_lang_prefix ))
{
$this -> langPrefix = $_tmp_lang_prefix ;
}
2017-02-11 02:24:26 +00:00
}
2017-02-13 23:24:38 +00:00
return $updateString ;
}
2017-12-14 23:10:47 +00:00
2017-02-13 23:24:38 +00:00
/**
* Update the data with the placeholders
*
* @ param string $data The actual data
* @ param array $placeholder The placeholders
* @ param int $action The action to use
2018-03-30 04:41:33 +00:00
*
2017-02-13 23:24:38 +00:00
* THE ACTION OPTIONS ARE
* 1 -> Just replace ( default )
* 2 -> Check if data string has placeholders
* 3 -> Remove placeholders not in data string
*
* @ return string
*
*/
2018-03-20 02:35:48 +00:00
public function setPlaceholders ( $data , & $placeholder , $action = 1 )
2017-02-13 23:24:38 +00:00
{
2018-03-18 21:07:18 +00:00
// make sure the placeholders is an array
if ( ! ComponentbuilderHelper :: checkArray ( $placeholder ))
{
// This is an error, (TODO) actualy we need to add a kind of log here to know that this happened
return $data ;
}
// continue with the work of replacement
2017-02-11 02:24:26 +00:00
if ( 1 == $action ) // <-- just replace (default)
{
2017-12-14 23:10:47 +00:00
return str_replace ( array_keys ( $placeholder ), array_values ( $placeholder ), $data );
2017-02-11 02:24:26 +00:00
}
elseif ( 2 == $action ) // <-- check if data string has placeholders
{
$replace = false ;
foreach ( $placeholder as $key => $val )
{
if ( strpos ( $data , $key ) !== FALSE )
{
2017-12-14 23:10:47 +00:00
$replace = true ;
break ;
2017-02-11 02:24:26 +00:00
}
}
// only replace if the data has these placeholder values
if ( $replace === true )
{
2017-12-14 23:10:47 +00:00
return str_replace ( array_keys ( $placeholder ), array_values ( $placeholder ), $data );
2017-02-11 02:24:26 +00:00
}
}
elseif ( 3 == $action ) // <-- remove placeholders not in data string
{
$replace = $placeholder ;
foreach ( $replace as $key => $val )
{
if ( strpos ( $data , $key ) === FALSE )
{
2017-12-14 23:10:47 +00:00
unset ( $replace [ $key ]);
2017-02-11 02:24:26 +00:00
}
}
// only replace if the data has these placeholder values
if ( ComponentbuilderHelper :: checkArray ( $replace ))
{
2017-12-14 23:10:47 +00:00
return str_replace ( array_keys ( $replace ), array_values ( $replace ), $data );
2017-02-11 02:24:26 +00:00
}
}
return $data ;
}
2017-12-14 23:10:47 +00:00
2017-02-01 13:17:04 +00:00
/**
2018-04-19 15:52:47 +00:00
* return the placeholders for inserted and replaced code
2017-02-01 13:17:04 +00:00
*
* @ param int $type The type of placement
* @ param int $id The code id in the system
*
* @ return array on success
*
*/
2017-02-11 02:24:26 +00:00
public function getPlaceHolder ( $type , $id )
2017-02-01 13:17:04 +00:00
{
switch ( $type )
{
2017-02-13 23:24:38 +00:00
case 11 :
//***[REPLACED$$$$]***//*1*/
if ( $this -> addPlaceholders === true )
2017-02-02 12:17:31 +00:00
{
return array (
2017-12-14 23:10:47 +00:00
'start' => '/***[REPLACED$$$$]***//*' . $id . '*/' ,
2017-02-02 12:17:31 +00:00
'end' => '/***[/REPLACED$$$$]***/' );
}
else
{
return array (
2018-02-27 12:17:38 +00:00
'start' => " " ,
'end' => " " );
2017-02-02 12:17:31 +00:00
}
2017-02-01 13:17:04 +00:00
break ;
2017-02-13 23:24:38 +00:00
case 12 :
//***[INSERTED$$$$]***//*1*/
if ( $this -> addPlaceholders === true )
2017-02-02 12:17:31 +00:00
{
return array (
2017-12-14 23:10:47 +00:00
'start' => '/***[INSERTED$$$$]***//*' . $id . '*/' ,
'end' => '/***[/INSERTED$$$$]***/' );
2017-02-02 12:17:31 +00:00
}
else
{
return array (
2018-02-27 12:17:38 +00:00
'start' => " " ,
'end' => " " );
2017-02-02 12:17:31 +00:00
}
2017-02-01 13:17:04 +00:00
break ;
2017-02-13 23:24:38 +00:00
case 21 :
//<!--[REPLACED$$$$]--><!--1-->
if ( $this -> addPlaceholders === true )
{
return array (
2017-12-14 23:10:47 +00:00
'start' => '<!--[REPLACED$$$$]--><!--' . $id . '-->' ,
'end' => '<!--[/REPLACED$$$$]-->' );
2017-02-13 23:24:38 +00:00
}
else
{
return array (
2018-02-27 12:17:38 +00:00
'start' => " " ,
'end' => " " );
2017-02-13 23:24:38 +00:00
}
break ;
case 22 :
//<!--[INSERTED$$$$]--><!--1-->
if ( $this -> addPlaceholders === true )
{
return array (
2017-12-14 23:10:47 +00:00
'start' => '<!--[INSERTED$$$$]--><!--' . $id . '-->' ,
'end' => '<!--[/INSERTED$$$$]-->' );
2017-02-13 23:24:38 +00:00
}
else
{
return array (
2018-02-27 12:17:38 +00:00
'start' => " " ,
'end' => " " );
2017-02-13 23:24:38 +00:00
}
break ;
2017-02-11 02:24:26 +00:00
case 3 :
return array (
2018-02-27 12:17:38 +00:00
'start' => " " ,
'end' => " " );
2017-02-11 02:24:26 +00:00
break ;
2017-02-01 13:17:04 +00:00
}
return false ;
}
2017-12-14 23:10:47 +00:00
2017-02-13 23:24:38 +00:00
/**
* get the local installed path of this component
*
* @ return array of paths on success
*
*/
protected function getLocalInstallPaths ()
{
// set the local paths to search
$localPaths = array ();
// admin path
2017-12-14 23:10:47 +00:00
$localPaths [ 'admin' ] = JPATH_ADMINISTRATOR . '/components/com_' . $this -> componentCodeName ;
2017-02-13 23:24:38 +00:00
// site path
2017-12-14 23:10:47 +00:00
$localPaths [ 'site' ] = JPATH_ROOT . '/components/com_' . $this -> componentCodeName ;
2017-02-13 23:24:38 +00:00
// TODO later to include the JS and CSS
2017-12-14 23:10:47 +00:00
$localPaths [ 'media' ] = JPATH_ROOT . '/media/com_' . $this -> componentCodeName ;
2019-12-06 05:31:32 +00:00
// Painfull but we need to folder paths for the linked modules
if (( $module_ids = $this -> getModuleIDs ()) !== false )
{
foreach ( $module_ids as $module_id )
{
// get the module group and folder name
// if (($path = $this->getModulePath($module_id)) !== false)
// {
// // set the path
// $localPaths['module_' . str_replace('/', '_', $path)] = JPATH_ROOT . '/modules/' . $path;
// }
}
}
2019-09-11 14:50:42 +00:00
// Painfull but we need to folder paths for the linked plugins
if (( $plugin_ids = $this -> getPluginIDs ()) !== false )
{
foreach ( $plugin_ids as $plugin_id )
{
// get the plugin group and folder name
if (( $path = $this -> getPluginPath ( $plugin_id )) !== false )
{
// set the path
$localPaths [ 'plugin_' . str_replace ( '/' , '_' , $path )] = JPATH_ROOT . '/plugins/' . $path ;
}
}
}
2017-02-13 23:24:38 +00:00
// check if the local install is found
foreach ( $localPaths as $key => $localPath )
{
if ( ! JFolder :: exists ( $localPath ))
{
unset ( $localPaths [ $key ]);
}
}
if ( ComponentbuilderHelper :: checkArray ( $localPaths ))
{
return $localPaths ;
}
return false ;
}
2017-12-14 23:10:47 +00:00
2016-02-26 00:20:09 +00:00
}