2016-02-26 00:20:09 +00:00
< ? php
2016-03-04 00:01:43 +00:00
/**--------------------------------------------------------------------------------------------------------| www . vdm . io |------/
2016-02-26 00:20:09 +00:00
__ __ _ _____ _ _ __ __ _ _ _
\ \ / / | | | __ \ | | | | | \ / | | | | | | |
\ \ / / _ _ ___ | | _ | | | | _____ _____ | | ___ _ __ _ __ ___ ___ _ __ | | _ | \ / | ___ | | _ | | __ ___ __ | |
\ \ / / _ ` / __| __| | | | |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __| | |\/| |/ _ \ __| ' _ \ / _ \ / _ ` |
\ / ( _ | \__ \ | _ | | __ | | __ / \ V / __ / | ( _ ) | | _ ) | | | | | | __ / | | | | _ | | | | __ / | _ | | | | ( _ ) | ( _ | |
\ / \__ , _ | ___ / \__ | | _____ / \___ | \_ / \___ | _ | \___ /| . __ /| _ | | _ | | _ | \___ | _ | | _ | \__ | | _ | | _ | \___ | \__ | _ | | _ | \___ / \__ , _ |
| |
| _ |
/-------------------------------------------------------------------------------------------------------------------------------/
2017-02-09 16:11:10 +00:00
@ version 2.3 . 0
2016-02-26 00:20:09 +00:00
@ created 30 th April , 2015
@ package Component Builder
@ subpackage compiler . php
@ author Llewellyn van der Merwe < http :// www . vdm . io >
@ my wife Roline van der Merwe < http :// www . vdm . io />
@ copyright Copyright ( C ) 2015. All Rights Reserved
@ license GNU / GPL Version 2 or later - http :// www . gnu . org / licenses / gpl - 2.0 . html
Builds Complex Joomla Components
/-----------------------------------------------------------------------------------------------------------------------------*/
// No direct access to this file
defined ( '_JEXEC' ) or die ( 'Restricted access' );
/**
* Get class as the main compilers class
*/
class Get
{
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Params
*
* @ var object
*/
public $params ;
2017-02-13 23:24:38 +00:00
/**
* The placeholders
*
* @ var array
*/
public $placeholders = array ();
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Compiler Path
*
* @ var object
*/
public $compilerPath ;
2017-02-14 00:33:24 +00:00
/**
* Switch to add custom code placeholders
*
* @ var bool
*/
public $addPlaceholders = false ;
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Component data
*
* @ var object
*/
public $componentData ;
2017-02-13 23:24:38 +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-02-13 23:24:38 +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-02-13 23:24:38 +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-02-13 23:24:38 +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-02-13 23:24:38 +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 <> $ $ $ $ ] ==>
* New Replace Code = <!== [ REPLACE <> $ $ $ $ ] ==> <!== [ / REPLACE <> $ $ $ $ ] ==>
*
* ///////////////////////////////// when JCB adds it back ///////////////////////////////
* JCB Add Inserted Code = <!== [ INSERTED $ $ $ $ ] ==><!== 23 ==> <!== [ / INSERTED $ $ $ $ ] ==>
* JCB Add Replaced Code = <!== [ REPLACED $ $ $ $ ] ==><!== 25 ==> <!== [ / REPLACED $ $ $ $ ] ==>
*
* //////////////////////////// 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
***********************************************************************************************/
protected $customCodePlaceholders = array (
1 => 'REPLACE<>$$$$]' ,
2017-02-01 13:17:04 +00:00
2 => 'INSERT<>$$$$]' ,
3 => 'REPLACED<>$$$$]' ,
2017-02-13 23:24:38 +00:00
4 => 'INSERTED<>$$$$]'
);
2017-02-01 13:17:04 +00:00
/**
* The custom code to be added
*
* @ var array
*/
public $customCode ;
2017-02-13 23:24:38 +00:00
/**
* The custom code to be added
*
* @ var array
*/
protected $customCodeData = array ();
/**
* The function name memory ids
*
* @ var array
*/
public $functionNameMemory = array ();
/**
* The custom code for local memory
*
* @ var array
*/
public $customCodeMemory = array ();
2017-02-01 13:17:04 +00:00
/**
* The custom code in local files that aready exist in system
*
* @ var array
*/
protected $existingCustomCode = array ();
/**
* The custom code in local files this are new
*
* @ var array
*/
protected $newCustomCode = array ();
2017-02-09 16:11:10 +00:00
/**
* The index of code already loaded
*
* @ var array
*/
2017-02-13 23:24:38 +00:00
protected $codeAreadyDone = array ();
/*
* The line numbers Switch
*
* @ var boolean
*/
2017-04-06 08:47:51 +00:00
public $debugLinenr = false ;
/*
* The percentage when a language should be added
*
* @ var boolean
*/
public $percentageLanguageAdd = 0 ;
2017-02-09 16:11:10 +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 ;
2016-02-26 00:20:09 +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-04-05 13:21:10 +00:00
/**
* The Languages bucket
*
* @ var array
*/
public $languages = array ( 'en-GB' => array ());
/**
* The Multi Languages bucket
*
* @ var array
*/
public $multiLangString = array ();
/**
* The new lang to add
*
* @ var array
*/
protected $newLangStrings = array ();
/**
* The existing lang to update
*
* @ var array
*/
protected $existingLangStrings = array ();
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-02-13 23:24:38 +00:00
/**
* The Component ID
*
* @ var int
*/
public $componentID ;
/**
* The current user
*
* @ var array
*/
public $user ;
/**
* The database object
*
* @ var array
*/
public $db ;
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Component version
*
* @ var string
*/
public $component_version ;
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The UIKIT Switch
*
* @ var boolean
*/
public $uikit = false ;
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 ();
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The FOOTABLE Switch
*
* @ var boolean
*/
public $footable = false ;
2016-04-22 12:03:43 +00:00
/**
* The FOOTABLE Version
*
* @ var int
*/
public $footableVersion ;
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 ();
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 ;
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 ;
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 ;
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 ();
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Language target
*
* @ var string
*/
public $lang = 'admin' ;
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Build target Switch
*
* @ var string
*/
public $target ;
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 ();
2016-03-04 00:01:43 +00:00
/**
2016-02-26 13:57:30 +00:00
* The unique keys
*
* @ var array
*/
public $uniquekeys = array ();
2016-02-26 00:20:09 +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 ;
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 ();
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 ();
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 ;
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 ();
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 ();
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 ();
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 ();
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 ;
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 ;
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 ();
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The template data
*
* @ var array
*/
public $templateData = array ();
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The layout data
*
* @ var array
*/
public $layoutData = array ();
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Advanced Encryption Switch
*
* @ var boolean
*/
public $advancedEncryption = false ;
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 ;
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 ();
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 ();
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 ();
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 ();
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-06-16 12:38:06 +00:00
/**
* The add SQL
*
* @ var array
*/
public $addSQL = array ();
/**
* The update SQL
*
* @ var array
*/
public $updateSQL = array ();
2016-02-26 00:20:09 +00:00
2016-03-04 00:01:43 +00:00
/***
2016-02-26 00:20:09 +00:00
* Constructor
*/
public function __construct ( $config = array ())
{
if ( isset ( $config ) && count ( $config ))
{
// Set the params
$this -> params = JComponentHelper :: getParams ( 'com_componentbuilder' );
// load the compiler path
$this -> compilerPath = $this -> params -> get ( 'compiler_folder_path' , JPATH_COMPONENT_ADMINISTRATOR . '/compiler' );
2017-02-13 23:24:38 +00:00
// set the component ID
$this -> componentID = ( int ) $config [ 'componentId' ];
// 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-04-05 13:21:10 +00:00
$this -> langPrefix = 'COM_' . ComponentbuilderHelper :: safeString ( $name_code , 'U' );
2017-02-13 23:24:38 +00:00
// set component code name
$this -> componentCodeName = ComponentbuilderHelper :: safeString ( $name_code );
// set if placeholders should be added to customcode
2017-02-16 14:02:23 +00:00
$global = (( int ) ComponentbuilderHelper :: getVar ( 'joomla_component' , $this -> componentID , 'id' , 'add_placeholders' ) == 1 ) ? true : false ;
2017-02-13 23:24:38 +00:00
$this -> addPlaceholders = (( int ) $config [ 'addPlaceholders' ] == 0 ) ? false : ((( int ) $config [ 'addPlaceholders' ] == 1 ) ? true : $global );
// set if line numbers should be added to comments
2017-02-16 14:02:23 +00:00
$global = (( int ) ComponentbuilderHelper :: getVar ( 'joomla_component' , $this -> componentID , 'id' , 'debug_linenr' ) == 1 ) ? true : false ;
2017-04-06 08:47:51 +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
$this -> user = JFactory :: getUser ();
// Get a db connection.
$this -> db = JFactory :: getDbo ();
// 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 );
}
// get the component data
$this -> componentData = $this -> getComponentData ();
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
if ( ! isset ( $this -> componentData -> old_component_version )
&& ( ComponentbuilderHelper :: checkArray ( $this -> addSQL ) || ComponentbuilderHelper :: checkArray ( $this -> updateSQL )))
{
// set the new version
$version = ( array ) explode ( '.' , $this -> componentData -> component_version );
// get last key
end ( $version );
$key = key ( $version );
// just increment the last
$version [ $key ] ++ ;
// 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-04-06 08:47:51 +00:00
2017-02-13 23:24:38 +00:00
return true ;
}
2016-02-26 00:20:09 +00:00
}
return false ;
}
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
{
return ' [Get ' . $nr . ']' ;
}
return '' ;
}
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 );
2016-02-26 00:20:09 +00:00
$query -> select ( 'a.*' );
2017-02-16 14:02:23 +00:00
$query -> from ( '#__componentbuilder_joomla_component AS a' );
2017-02-13 23:24:38 +00:00
$query -> where ( $this -> db -> quoteName ( 'a.id' ) . ' = ' . ( int ) $this -> componentID );
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-03-06 12:06:51 +00:00
// set component place holders
$this -> placeholders [ '###component###' ] = ComponentbuilderHelper :: safeString ( $component -> name_code );
$this -> placeholders [ '###Component###' ] = ComponentbuilderHelper :: safeString ( $component -> name_code , 'F' );
$this -> placeholders [ '###COMPONENT###' ] = ComponentbuilderHelper :: safeString ( $component -> name_code , 'U' );
$this -> placeholders [ '[[[component]]]' ] = $this -> placeholders [ '###component###' ];
$this -> placeholders [ '[[[Component]]]' ] = $this -> placeholders [ '###Component###' ];
$this -> placeholders [ '[[[COMPONENT]]]' ] = $this -> placeholders [ '###COMPONENT###' ];
2016-02-26 00:20:09 +00:00
// set component sales name
$component -> sales_name = ComponentbuilderHelper :: safeString ( $component -> system_name );
// ensure version naming is correct
$this -> component_version = preg_replace ( '/[^0-9.]+/' , '' , $component -> component_version );
// ser the addfolders data
$addfolders = json_decode ( $component -> addfolders , true );
if ( ComponentbuilderHelper :: checkArray ( $addfolders ))
{
foreach ( $addfolders as $option => $values )
{
foreach ( $values as $nr => $value )
{
$component -> folders [ $nr ][ $option ] = $value ;
}
}
unset ( $component -> addfolders );
}
2017-06-16 12:38:06 +00:00
2016-02-26 00:20:09 +00:00
// ser the addfiles data
$addfiles = json_decode ( $component -> addfiles , true );
if ( ComponentbuilderHelper :: checkArray ( $addfiles ))
{
foreach ( $addfiles as $option => $values )
{
foreach ( $values as $nr => $value )
{
$component -> files [ $nr ][ $option ] = $value ;
}
}
unset ( $component -> addfiles );
}
// set the uikit switch
if ( $component -> adduikit )
{
$this -> uikit = true ;
}
// 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
}
// ser the addcustommenu data
$addcustommenus = json_decode ( $component -> addcustommenus , true );
if ( ComponentbuilderHelper :: checkArray ( $addcustommenus ))
{
foreach ( $addcustommenus as $option => $values )
{
foreach ( $values as $nr => $value )
{
$component -> custommenus [ $nr ][ $option ] = $value ;
}
}
unset ( $component -> addcustommenus );
}
// tweak the mysql dump settings if needed
$sql_tweak = json_decode ( $component -> sql_tweak , true );
if ( ComponentbuilderHelper :: checkArray ( $sql_tweak ))
{
$component -> sql_tweak = array ();
foreach ( $sql_tweak as $option => $values )
{
foreach ( $values as $nr => $value )
{
if (( string )( int ) $value == $value )
{
$component -> sql_tweak [ $nr ][ $option ] = ( int ) $value ;
}
else
{
$component -> sql_tweak [ $nr ][ $option ] = $value ;
}
}
}
// build the tweak settings
$this -> setSqlTweaking ( $component -> sql_tweak );
unset ( $component -> sql_tweak );
}
// set the admin_view data
$admin_views = json_decode ( $component -> addadmin_views , true );
2017-06-16 12:38:06 +00:00
2016-02-26 00:20:09 +00:00
if ( ComponentbuilderHelper :: checkArray ( $admin_views ))
{
foreach ( $admin_views as $option => $values )
{
foreach ( $values as $nr => $value )
{
if (( string )( int ) $value == $value )
{
$component -> admin_views [ $nr ][ $option ] = ( int ) $value ;
}
else
{
$component -> admin_views [ $nr ][ $option ] = $value ;
}
}
}
unset ( $component -> addadmin_views );
// sort the views acording to order
usort ( $component -> admin_views , function ( $a , $b )
{
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 ;
});
// load the view and field data
foreach ( $component -> admin_views as $key => & $view )
{
if ( $view [ 'port' ] && ! $this -> addEximport )
{
$this -> addEximport = true ;
}
if ( $view [ 'history' ] && ! $this -> setTagHistory )
{
$this -> setTagHistory = true ;
}
if ( $view [ 'edit_create_site_view' ])
{
$this -> siteEditView [ $view [ 'adminview' ]] = true ;
}
// TODO this is a temp fix until front view is added
$view [ 'view' ] = $view [ 'adminview' ];
$view [ 'settings' ] = $this -> getAdminViewData ( $view [ 'view' ]);
}
unset ( $component -> addadmin_view );
}
// set the site_view data
2017-03-06 12:06:51 +00:00
$site_views = json_decode ( $component -> addsite_views , true );
2016-02-26 00:20:09 +00:00
if ( ComponentbuilderHelper :: checkArray ( $site_views ))
{
foreach ( $site_views as $option => $values )
{
foreach ( $values as $nr => $value )
{
if (( string )( int ) $value == $value )
{
$component -> site_views [ $nr ][ $option ] = ( int ) $value ;
}
else
{
$component -> site_views [ $nr ][ $option ] = $value ;
}
}
}
unset ( $component -> addsite_views );
$this -> lang = 'site' ;
$this -> target = 'site' ;
// load the view and field data
2017-03-06 12:06:51 +00:00
if ( isset ( $component -> site_views ) && ComponentbuilderHelper :: checkArray ( $component -> site_views ))
2016-02-26 00:20:09 +00:00
{
2017-03-06 12:06:51 +00:00
foreach ( $component -> site_views as $key => & $view )
{
// has become a lacacy issue, can't remove this
$view [ 'view' ] = $view [ 'siteview' ];
$view [ 'settings' ] = $this -> getCustomViewData ( $view [ 'view' ]);
}
2016-02-26 00:20:09 +00:00
}
}
// set the custom_admin_views data
$custom_admin_views = json_decode ( $component -> addcustom_admin_views , true );
if ( ComponentbuilderHelper :: checkArray ( $custom_admin_views ))
{
foreach ( $custom_admin_views as $option => $values )
{
foreach ( $values as $nr => $value )
{
if (( string )( int ) $value == $value )
{
$component -> custom_admin_views [ $nr ][ $option ] = ( int ) $value ;
}
else
{
$component -> custom_admin_views [ $nr ][ $option ] = $value ;
}
}
}
unset ( $component -> addcustom_admin_views );
$this -> lang = 'admin' ;
$this -> target = 'custom_admin' ;
// load the view and field data
2017-03-06 12:06:51 +00:00
if ( isset ( $component -> custom_admin_views ) && ComponentbuilderHelper :: checkArray ( $component -> custom_admin_views ))
2016-02-26 00:20:09 +00:00
{
2017-03-06 12:06:51 +00:00
foreach ( $component -> custom_admin_views as $key => & $view )
{
// has become a lacacy issue, can't remove this
$view [ 'view' ] = $view [ 'customadminview' ];
$view [ 'settings' ] = $this -> getCustomViewData ( $view [ 'view' ], 'custom_admin_view' );
}
2016-02-26 00:20:09 +00:00
}
}
// ser the config data
$addconfig = json_decode ( $component -> addconfig , true );
if ( ComponentbuilderHelper :: checkArray ( $addconfig ))
{
foreach ( $addconfig as $option => $values )
{
foreach ( $values as $nr => $value )
{
$component -> config [ $nr ][ 'alias' ] = 0 ;
$component -> config [ $nr ][ 'title' ] = 0 ;
2017-02-01 13:17:04 +00:00
if ( $option === 'field' )
2016-02-26 00:20:09 +00:00
{
// load the field data
$component -> config [ $nr ][ 'settings' ] = $this -> getFieldData ( $value );
}
else
{
$component -> config [ $nr ][ $option ] = $value ;
}
}
}
unset ( $component -> addconfig );
}
// check if any contributors is to be added
$contributors = json_decode ( $component -> addcontributors , true );
if ( ComponentbuilderHelper :: checkArray ( $contributors ))
{
$this -> addContributors = true ;
foreach ( $contributors as $option => $values )
{
foreach ( $values as $nr => $value )
{
$component -> contributors [ $nr ][ $option ] = $value ;
}
}
unset ( $component -> addcontributors );
}
// check if version updating is set
$version_update = json_decode ( $component -> version_update , true );
if ( ComponentbuilderHelper :: checkArray ( $version_update ))
{
$component -> version_update = array ();
foreach ( $version_update as $option => $values )
{
foreach ( $values as $nr => $value )
{
$component -> version_update [ $nr ][ $option ] = $value ;
}
}
2017-06-16 12:38:06 +00:00
}
// build update SQL
if ( $old_component = $this -> getHistoryWatch ( 'joomla_component' , $this -> componentID ))
{
// add new views if found
if ( isset ( $old_component -> addadmin_views ) && ComponentbuilderHelper :: checkJson ( $old_component -> addadmin_views ))
{
$this -> setUpdateSQL ( json_decode ( $old_component -> addadmin_views , true ), $admin_views , 'adminview' );
}
// check if a new version was manualy set
$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 );
2016-02-26 00:20:09 +00:00
}
2017-10-06 14:53:22 +00:00
// add_javascript
if ( $component -> add_javascript == 1 )
{
$this -> customScriptBuilder [ 'component_js' ] = base64_decode ( $component -> javascript );
}
else
{
$this -> customScriptBuilder [ 'component_js' ] = '' ;
}
unset ( $component -> javascript );
2016-02-26 00:20:09 +00:00
// add_css
if ( $component -> add_css == 1 )
{
$this -> customScriptBuilder [ 'component_css' ] = base64_decode ( $component -> css );
}
else
{
$this -> customScriptBuilder [ 'component_css' ] = '' ;
}
2016-10-23 22:48:26 +00:00
unset ( $component -> css );
2017-10-06 14:53:22 +00:00
2016-10-23 22:48:26 +00:00
// set the lang target
$this -> lang = 'admin' ;
// add PHP in ADMIN
$addScriptMethods = array ( 'php_preflight' , 'php_postflight' , 'php_method' );
$addScriptTypes = array ( 'install' , 'update' , 'uninstall' );
foreach ( $addScriptMethods as $scriptMethod )
{
foreach ( $addScriptTypes as $scriptType )
{
2017-03-27 12:38:51 +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
{
2017-02-13 23:24:38 +00:00
$this -> customScriptBuilder [ $scriptMethod ][ $scriptType ] = $this -> setDynamicValues ( base64_decode ( $component -> { $scriptMethod . '_' . $scriptType }));
2016-10-23 22:48:26 +00:00
}
else
{
$this -> customScriptBuilder [ $scriptMethod ][ $scriptType ] = '' ;
}
unset ( $component -> { $scriptMethod . '_' . $scriptType });
}
}
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' ;
2017-02-13 23:24:38 +00:00
$this -> customScriptBuilder [ 'component_php_helper_admin' ] = PHP_EOL . PHP_EOL . $this -> setDynamicValues ( base64_decode ( $component -> php_helper_admin ));
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' ;
2017-02-13 23:24:38 +00:00
$this -> customScriptBuilder [ 'component_php_admin_event' ] = $this -> setDynamicValues ( base64_decode ( $component -> php_admin_event ));
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' ;
2017-02-13 23:24:38 +00:00
$this -> customScriptBuilder [ 'component_php_helper_both' ] = PHP_EOL . PHP_EOL . $this -> setDynamicValues ( base64_decode ( $component -> php_helper_both ));
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' ;
2017-02-13 23:24:38 +00:00
$this -> customScriptBuilder [ 'component_php_helper_site' ] = PHP_EOL . PHP_EOL . $this -> setDynamicValues ( base64_decode ( $component -> php_helper_site ));
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' ;
2017-02-13 23:24:38 +00:00
$this -> customScriptBuilder [ 'component_php_site_event' ] = $this -> setDynamicValues ( base64_decode ( $component -> php_site_event ));
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 )
{
$this -> customScriptBuilder [ 'sql' ][ 'component_sql' ] = base64_decode ( $component -> sql );
}
2016-10-23 22:48:26 +00:00
unset ( $component -> sql );
2016-02-26 00:20:09 +00:00
// bom
if ( ComponentbuilderHelper :: checkString ( $component -> bom ))
{
$this -> bomPath = $this -> compilerPath . '/' . $component -> bom ;
}
else
{
$this -> bomPath = $this -> compilerPath . '/default.txt' ;
}
2016-10-23 22:48:26 +00:00
unset ( $component -> bom );
2016-02-26 00:20:09 +00:00
// README
if ( $component -> addreadme )
{
$component -> readme = base64_decode ( $component -> readme );
}
else
{
$component -> readme = '' ;
}
// dashboard methods
2017-03-27 12:38:51 +00:00
if ( $component -> add_php_dashboard_methods && ComponentbuilderHelper :: checkString ( $component -> php_dashboard_methods ))
2016-02-26 00:20:09 +00:00
{
2016-10-23 22:48:26 +00:00
$nowLang = $this -> lang ;
$this -> lang = 'admin' ;
2016-02-26 00:20:09 +00:00
// load the php for the dashboard model
2017-02-13 23:24:38 +00:00
$component -> php_dashboard_methods = $this -> setDynamicValues ( base64_decode ( $component -> php_dashboard_methods ));
2016-02-26 00:20:09 +00:00
// check if dashboard_tab is set
$dashboard_tab = json_decode ( $component -> dashboard_tab , true );
if ( ComponentbuilderHelper :: checkArray ( $dashboard_tab ))
{
$component -> dashboard_tab = array ();
foreach ( $dashboard_tab as $option => $values )
{
foreach ( $values as $nr => $value )
{
2017-02-02 11:54:07 +00:00
if ( 'html' === $option )
2016-02-26 00:20:09 +00:00
{
2017-02-13 23:24:38 +00:00
$value = $this -> setDynamicValues ( $value );
2016-02-26 00:20:09 +00:00
}
$component -> dashboard_tab [ $nr ][ $option ] = $value ;
}
}
}
else
{
$component -> dashboard_tab = '' ;
}
2016-10-23 22:48:26 +00:00
$this -> lang = $nowLang ;
2016-02-26 00:20:09 +00:00
}
else
{
$component -> php_dashboard_methods = '' ;
$component -> dashboard_tab = '' ;
}
2017-08-25 01:46:12 +00:00
// add the update FTP server sig
if ( $component -> add_update_server == 1 && is_numeric ( $component -> update_server_ftp ) && $component -> update_server_ftp > 0 )
{
$component -> update_server_ftp = ComponentbuilderHelper :: getVar ( 'ftp' , ( int ) $component -> update_server_ftp , 'id' , 'signature' );
}
else
{
$component -> update_server_ftp = 0 ;
}
// add the sales FTP server sig
if ( $component -> add_sales_server == 1 && is_numeric ( $component -> sales_server_ftp ) && $component -> sales_server_ftp > 0 )
{
$component -> sales_server_ftp = ComponentbuilderHelper :: getVar ( 'ftp' , ( int ) $component -> sales_server_ftp , 'id' , 'signature' );
}
else
{
$component -> sales_server_ftp = 0 ;
$component -> add_sales_server = 0 ;
}
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' );
}
2017-08-25 01:46:12 +00:00
2016-02-26 00:20:09 +00:00
// return the found component data
return $component ;
}
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* To limit the SQL Demo date build in the views
*
2017-09-13 10:15:14 +00:00
* @ param array $settings Tweaking array .
2016-02-26 00:20:09 +00:00
*
* @ return void
*
*/
public function setSqlTweaking ( $settings )
{
if ( ComponentbuilderHelper :: checkArray ( $settings ))
{
foreach ( $settings as $setting )
{
// 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 )
{
$id_array = ( array ) array_map ( 'trim' , explode ( ',' , $ids ));
}
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
if ( count ( $id_range ) == 2 )
{
$range = range ( $id_range [ 0 ], $id_range [ 1 ]);
$id_array_new = array_merge ( $id_array_new , $range );
}
}
}
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
$this -> sqlTweak [ ( int ) $setting [ 'adminview' ]][ 'where' ] = implode ( ',' , $id_array );
}
}
}
else
{
// remove all sql dump options
$this -> sqlTweak [ ( int ) $setting [ 'adminview' ]][ 'remove' ] = true ;
}
}
}
}
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.*' );
$query -> from ( '#__componentbuilder_admin_view AS a' );
2017-02-13 23:24:38 +00:00
$query -> where ( $this -> db -> quoteName ( 'a.id' ) . ' = ' . ( int ) $id );
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 ();
2016-02-26 00:20:09 +00:00
// reset fields
$view -> fields = array ();
// setup view name to use in storing the data
$name_single = ComponentbuilderHelper :: safeString ( $view -> name_single );
$name_list = ComponentbuilderHelper :: safeString ( $view -> name_list );
// 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
$this -> placeholders [ '###view###' ] = ComponentbuilderHelper :: safeString ( $name_single );
$this -> placeholders [ '###views###' ] = ComponentbuilderHelper :: safeString ( $name_list );
$this -> placeholders [ '###View###' ] = ComponentbuilderHelper :: safeString ( $name_single , 'F' );
$this -> placeholders [ '###Views###' ] = ComponentbuilderHelper :: safeString ( $name_list , 'F' );
$this -> placeholders [ '###VIEW###' ] = ComponentbuilderHelper :: safeString ( $name_single , 'U' );
$this -> placeholders [ '###VIEWS###' ] = ComponentbuilderHelper :: safeString ( $name_list , 'U' );
$this -> placeholders [ '[[[view]]]' ] = $this -> placeholders [ '###view###' ];
$this -> placeholders [ '[[[views]]]' ] = $this -> placeholders [ '###views###' ];
$this -> placeholders [ '[[[View]]]' ] = $this -> placeholders [ '###View###' ];
$this -> placeholders [ '[[[Views]]]' ] = $this -> placeholders [ '###Views###' ];
$this -> placeholders [ '[[[VIEW]]]' ] = $this -> placeholders [ '###VIEW###' ];
$this -> placeholders [ '[[[VIEWS]]]' ] = $this -> placeholders [ '###VIEWS###' ];
2016-02-26 00:20:09 +00:00
// load the values form params
2017-02-01 13:17:04 +00:00
$permissions = json_decode ( $view -> addpermissions , true );
2016-02-26 00:20:09 +00:00
unset ( $view -> addpermissions );
$tabs = json_decode ( $view -> addtabs , true );
unset ( $view -> addtabs );
$fields = json_decode ( $view -> addfields , true );
unset ( $view -> addfields );
$conditions = json_decode ( $view -> addconditions , true );
unset ( $view -> addconditions );
2017-02-01 13:17:04 +00:00
$linked_views = json_decode ( $view -> addlinked_views , true );
2016-02-26 00:20:09 +00:00
unset ( $view -> addlinked_views );
2017-02-01 13:17:04 +00:00
$tables = json_decode ( $view -> addtables , true );
2016-02-26 00:20:09 +00:00
unset ( $view -> addtables );
2017-06-16 12:38:06 +00:00
// build update SQL
if ( $old_view = $this -> getHistoryWatch ( 'admin_view' , $id ))
{
// add new fields were added
if ( isset ( $old_view -> addfields ) && ComponentbuilderHelper :: checkJson ( $old_view -> addfields ))
{
$this -> setUpdateSQL ( json_decode ( $old_view -> addfields , true ), $fields , 'field' , $name_single );
}
// 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 );
}
// clear this data
unset ( $old_view );
}
2016-02-26 00:20:09 +00:00
// sort the values
if ( ComponentbuilderHelper :: checkArray ( $tables ))
{
foreach ( $tables as $option => $values )
{
foreach ( $values as $nr => $value )
{
$view -> tables [ $nr ][ $option ] = $value ;
}
}
}
if ( ComponentbuilderHelper :: checkArray ( $tabs ))
{
foreach ( $tabs as $option => $values )
{
foreach ( $values as $nr => $value )
{
$fix = $nr + 1 ;
$view -> tabs [ $fix ] = $value ;
}
}
}
if ( ComponentbuilderHelper :: checkArray ( $permissions ))
{
foreach ( $permissions as $option => $values )
{
foreach ( $values as $nr => $value )
{
$view -> permissions [ $nr ][ $option ] = $value ;
}
}
}
if ( ComponentbuilderHelper :: checkArray ( $fields ))
{
foreach ( $fields as $option => $values )
{
foreach ( $values as $nr => $value )
{
$view -> fields [ $nr ][ $option ] = ( int ) $value ;
}
}
// sort the fields acording to order
usort ( $view -> fields , function ( $a , $b )
{
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 )
{
return 1 ;
}
elseif ( $a [ 'order_list' ] != 0 && $b [ 'order_list' ] == 0 )
{
return 0 ;
}
return 1 ;
});
// load the field data
foreach ( $view -> fields as $key => & $field )
{
$field [ 'settings' ] = $this -> getFieldData ( $field [ 'field' ], $name_single , $name_list );
}
}
if ( ComponentbuilderHelper :: checkArray ( $conditions ))
{
foreach ( $conditions as $condition => $conditionValues )
{
foreach ( $conditionValues as $nr => $conditionValue )
{
2017-02-01 13:17:04 +00:00
if ( $condition === 'target_field' )
2016-02-26 00:20:09 +00:00
{
if ( ComponentbuilderHelper :: checkArray ( $conditionValue ) && ComponentbuilderHelper :: checkArray ( $view -> fields ))
{
foreach ( $conditionValue as $fieldKey => $fieldId )
{
foreach ( $view -> fields as $fieldValues )
{
if (( int ) $fieldValues [ 'field' ] == ( int ) $fieldId )
{
// load the field details
$required = ComponentbuilderHelper :: getBetween ( $fieldValues [ 'settings' ] -> xml , 'required="' , '"' );
$required = ( $required == true ) ? 'yes' : 'no' ;
$filter = ComponentbuilderHelper :: getBetween ( $fieldValues [ 'settings' ] -> xml , 'filter="' , '"' );
$filter = ComponentbuilderHelper :: checkString ( $filter ) ? $filter : 'none' ;
// get name
$name = ComponentbuilderHelper :: getBetween ( $fieldValues [ 'settings' ] -> xml , 'name="' , '"' );
$name = ComponentbuilderHelper :: checkString ( $name ) ? $name : $fieldValues [ 'settings' ] -> name ;
// get type
$type = ComponentbuilderHelper :: getBetween ( $fieldValues [ 'settings' ] -> xml , 'type="' , '"' );
$type = ComponentbuilderHelper :: checkString ( $type ) ? $type : $fieldValues [ 'settings' ] -> type_name ;
// set the field name
$conditionValue [ $fieldKey ] = array (
'name' => ComponentbuilderHelper :: safeString ( $name ),
'type' => ComponentbuilderHelper :: safeString ( $type ),
'required' => $required ,
'filter' => $filter
);
break ;
}
}
}
}
}
2017-02-01 13:17:04 +00:00
if ( $condition === 'match_field' )
2016-02-26 00:20:09 +00:00
{
foreach ( $view -> fields as $fieldValue )
{
if (( int ) $fieldValue [ 'field' ] == ( int ) $conditionValue )
{
// get name
$name = ComponentbuilderHelper :: getBetween ( $fieldValue [ 'settings' ] -> xml , 'name="' , '"' );
$name = ComponentbuilderHelper :: checkString ( $name ) ? $name : $fieldValue [ 'settings' ] -> name ;
// get type
$type = ComponentbuilderHelper :: getBetween ( $fieldValue [ 'settings' ] -> xml , 'type="' , '"' );
$type = ComponentbuilderHelper :: checkString ( $type ) ? $type : $fieldValue [ 'settings' ] -> type_name ;
// set the field details
$view -> conditions [ $nr ][ 'match_name' ] = ComponentbuilderHelper :: safeString ( $name );
$view -> conditions [ $nr ][ 'match_type' ] = ComponentbuilderHelper :: safeString ( $type );
$view -> conditions [ $nr ][ 'match_xml' ] = $fieldValue [ 'settings' ] -> xml ;
2016-05-31 05:11:07 +00:00
// if custom field load field being extended
if ( ! ComponentbuilderHelper :: typeField ( $type ))
{
$view -> conditions [ $nr ][ 'match_extends' ] = ComponentbuilderHelper :: getBetween ( $fieldValue [ 'settings' ] -> xml , 'extends="' , '"' );
}
else
{
$view -> conditions [ $nr ][ 'match_extends' ] = '' ;
}
2016-02-26 00:20:09 +00:00
break ;
}
}
}
// set condition values
$view -> conditions [ $nr ][ $condition ] = $conditionValue ;
}
}
}
// set linked views
$linked_views_sorted = null ;
if ( ComponentbuilderHelper :: checkArray ( $linked_views ))
{
$linked_views_sorted = array ();
foreach ( $linked_views as $option => $values )
{
foreach ( $values as $nr => $value )
{
$linked_views_sorted [ $nr ][ $option ] = $value ;
}
}
}
unset ( $linked_views );
// setup linked views to global data sets
$this -> linkedAdminViews [ $name_single ] = $linked_views_sorted ;
unset ( $linked_views_sorted );
2016-06-23 15:05:37 +00:00
// set the lang target
$this -> lang = 'admin' ;
// add_javascript
$addArrayJ = array ( 'javascript_view_file' , 'javascript_view_footer' , 'javascript_views_file' , 'javascript_views_footer' );
foreach ( $addArrayJ as $scripter )
2016-02-26 00:20:09 +00:00
{
2017-03-27 12:38:51 +00:00
if ( isset ( $view -> { 'add_' . $scripter }) && $view -> { 'add_' . $scripter } == 1 && ComponentbuilderHelper :: checkString ( $view -> $scripter ))
2016-02-26 00:20:09 +00:00
{
2017-02-13 23:24:38 +00:00
$view -> $scripter = $this -> setDynamicValues ( base64_decode ( $view -> $scripter ));
2016-06-23 15:05:37 +00:00
$scripter_target = str_replace ( 'javascript_' , '' , $scripter );
if ( ! isset ( $this -> customScriptBuilder [ $scripter_target ][ $name_single ]))
2016-02-26 00:20:09 +00:00
{
2016-06-23 15:05:37 +00:00
if ( ! isset ( $this -> customScriptBuilder [ $scripter_target ]))
{
$this -> customScriptBuilder [ $scripter_target ] = array ();
}
$this -> customScriptBuilder [ $scripter_target ][ $name_single ] = '' ;
2016-02-26 00:20:09 +00:00
}
2016-06-23 15:05:37 +00:00
$this -> customScriptBuilder [ $scripter_target ][ $name_single ] .= $view -> $scripter ;
2017-02-16 14:02:23 +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
}
2016-06-23 15:05:37 +00:00
unset ( $view -> $scripter );
2016-02-26 00:20:09 +00:00
}
}
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
{
2016-06-23 15:05:37 +00:00
if ( isset ( $view -> { 'add_' . $scripter }) && $view -> { 'add_' . $scripter } == 1 )
2016-02-26 00:20:09 +00:00
{
2016-06-23 15:05:37 +00:00
if ( ! isset ( $this -> customScriptBuilder [ $scripter ][ $name_single ]))
2016-02-26 00:20:09 +00:00
{
2016-06-23 15:05:37 +00:00
$this -> customScriptBuilder [ $scripter ][ $name_single ] = '' ;
2016-02-26 00:20:09 +00:00
}
2016-06-23 15:05:37 +00:00
$this -> customScriptBuilder [ $scripter ][ $name_single ] .= base64_decode ( $view -> $scripter );
unset ( $view -> $scripter );
2016-02-26 00:20:09 +00:00
}
}
2016-06-23 15:05:37 +00:00
// add_php
2017-09-13 00:37:43 +00:00
$addArrayP = array ( 'php_getitem' , 'php_before_save' , 'php_save' , 'php_postsavehook' , 'php_getitems' , 'php_getitems_after_all' , 'php_getlistquery' , 'php_allowedit' , '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
{
if ( isset ( $view -> { 'add_' . $scripter }) && $view -> { 'add_' . $scripter } == 1 )
{
2017-02-13 23:24:38 +00:00
$this -> customScriptBuilder [ $scripter ][ $name_single ] = $this -> setDynamicValues ( base64_decode ( $view -> $scripter ));
2016-02-26 00:20:09 +00:00
unset ( $view -> $scripter );
}
}
2016-09-11 15:27:04 +00:00
// add the custom buttons
if ( isset ( $view -> add_custom_button ) && $view -> add_custom_button == 1 )
{
2017-03-02 00:55:04 +00:00
// set for the edit views
if ( ComponentbuilderHelper :: checkString ( $view -> php_model ))
2016-09-11 15:27:04 +00:00
{
2017-02-13 23:24:38 +00:00
$view -> php_model = $this -> setDynamicValues ( base64_decode ( $view -> php_model ));
2016-09-11 15:27:04 +00:00
}
2017-03-02 00:55:04 +00:00
if ( ComponentbuilderHelper :: checkString ( $view -> php_controller ))
2017-02-13 23:24:38 +00:00
{
$view -> php_controller = $this -> setDynamicValues ( base64_decode ( $view -> php_controller ));
}
2017-03-02 00:55:04 +00:00
// set for the list views
if ( isset ( $view -> php_model_list ) && ComponentbuilderHelper :: checkString ( $view -> php_model_list ))
{
$view -> php_model_list = $this -> setDynamicValues ( base64_decode ( $view -> php_model_list ));
}
if ( isset ( $view -> php_controller_list ) && ComponentbuilderHelper :: checkString ( $view -> php_controller_list ))
{
$view -> php_controller_list = $this -> setDynamicValues ( base64_decode ( $view -> php_controller_list ));
}
2016-09-11 15:27:04 +00:00
// set the button array
$buttons = json_decode ( $view -> custom_button , true );
unset ( $view -> custom_button );
// sort the values
if ( ComponentbuilderHelper :: checkArray ( $buttons ))
{
foreach ( $buttons as $option => $values )
{
foreach ( $values as $nr => $value )
{
$view -> custom_buttons [ $nr ][ $option ] = $value ;
}
}
}
}
2016-05-04 04:53:33 +00:00
// set custom import scripts
if ( isset ( $view -> add_custom_import ) && $view -> add_custom_import == 1 )
{
2017-03-27 12:38:51 +00:00
$addImportArray = array ( 'php_import_ext' , 'php_import_display' , 'php_import' , 'php_import_setdata' , 'php_import_save' , 'html_import_view' );
2016-05-04 04:53:33 +00:00
foreach ( $addImportArray as $importScripter )
{
if ( isset ( $view -> $importScripter ) && strlen ( $view -> $importScripter ) > 0 )
{
2017-02-13 23:24:38 +00:00
$this -> customScriptBuilder [ $importScripter ][ 'import_' . $name_list ] = $this -> setDynamicValues ( base64_decode ( $view -> $importScripter ));
2016-05-04 04:53:33 +00:00
unset ( $view -> $importScripter );
}
2017-03-27 12:38:51 +00:00
else
{
// load the default
$this -> customScriptBuilder [ $importScripter ][ 'import_' . $name_list ] = ComponentbuilderHelper :: getImportScripts ( $importScripter , true );
}
2016-05-04 04:53:33 +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
$ajax_input = json_decode ( $view -> ajax_input , true );
if ( ComponentbuilderHelper :: checkArray ( $ajax_input ))
{
foreach ( $ajax_input as $option => $values )
{
foreach ( $values as $nr => $value )
{
if ( $addAjaxSite )
{
$this -> customScriptBuilder [ 'site' ][ 'ajax_controller' ][ $name_single ][ $nr ][ $option ] = $value ;
}
$this -> customScriptBuilder [ 'admin' ][ 'ajax_controller' ][ $name_single ][ $nr ][ $option ] = $value ;
}
}
2016-05-10 05:47:47 +00:00
$this -> addAjax = true ;
unset ( $view -> ajax_input );
}
if ( ComponentbuilderHelper :: checkString ( $view -> php_ajaxmethod ))
{
2017-02-13 23:24:38 +00:00
$this -> customScriptBuilder [ 'admin' ][ 'ajax_model' ][ $name_single ] = $this -> setDynamicValues ( base64_decode ( $view -> php_ajaxmethod ));
2016-02-26 00:20:09 +00:00
if ( $addAjaxSite )
{
2017-02-13 23:24:38 +00:00
$this -> customScriptBuilder [ 'site' ][ 'ajax_model' ][ $name_single ] = $this -> customScriptBuilder [ 'admin' ][ 'ajax_model' ][ $name_single ];
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 ;
}
}
// 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
$this -> customScriptBuilder [ 'sql' ][ $name_single ] = $this -> buildSqlDump ( $view -> tables , $name_single , $id );
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
$this -> customScriptBuilder [ 'sql' ][ $name_single ] = base64_decode ( $view -> sql );
unset ( $view -> sql );
}
}
2017-10-06 14:53:22 +00:00
// clear placeholders
unset ( $this -> placeholders [ '###view###' ]);
unset ( $this -> placeholders [ '###views###' ]);
unset ( $this -> placeholders [ '###View###' ]);
unset ( $this -> placeholders [ '###Views###' ]);
unset ( $this -> placeholders [ '###VIEW###' ]);
unset ( $this -> placeholders [ '###VIEWS###' ]);
unset ( $this -> placeholders [ '[[[view]]]' ]);
unset ( $this -> placeholders [ '[[[views]]]' ]);
unset ( $this -> placeholders [ '[[[View]]]' ]);
unset ( $this -> placeholders [ '[[[Views]]]' ]);
unset ( $this -> placeholders [ '[[[VIEW]]]' ]);
unset ( $this -> placeholders [ '[[[VIEWS]]]' ]);
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 ];
}
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
*
* @ 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.*' );
$query -> from ( '#__componentbuilder_' . $table . ' AS a' );
2017-02-13 23:24:38 +00:00
$query -> where ( $this -> db -> quoteName ( 'a.id' ) . ' = ' . ( int ) $id );
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 ();
2017-02-01 13:17:04 +00:00
if ( $table === 'site_view' )
2016-02-26 00:20:09 +00:00
{
$this -> lang = 'site' ;
}
else
{
$this -> lang = 'admin' ;
}
// set the default data
2017-02-13 23:24:38 +00:00
$view -> default = $this -> setDynamicValues ( base64_decode ( $view -> default ));
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' );
$view -> CODE = ComponentbuilderHelper :: safeString ( $view -> code , 'U' );
// insure the uikit components are loaded
if ( ! isset ( $this -> uikitComp [ $view -> code ]))
{
$this -> uikitComp [ $view -> code ] = array ();
}
$this -> uikitComp [ $view -> code ] = ComponentbuilderHelper :: getUikitComp ( $view -> default , $this -> uikitComp [ $view -> code ]);
// 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 ;
}
}
// setup template array
$this -> templateData [ $this -> target ][ $view -> code ] = array ();
// setup template and layout data
$this -> setTemplateAndLayoutData ( $view -> default , $view -> code );
// set the main get data
$main_get = $this -> setGetData ( array ( $view -> main_get ), $view -> code );
$view -> main_get = $main_get [ 0 ];
// set the custom_get data
2017-10-06 14:53:22 +00:00
$view -> custom_get = $this -> setGetData ( json_decode ( $view -> custom_get , true ), $view -> code );
2016-02-26 00:20:09 +00:00
// set array adding array of scripts
$addArray = array ( 'php_view' , 'php_jview' , 'php_jview_display' , 'php_document' , 'js_document' , 'css_document' , 'css' );
foreach ( $addArray as $scripter )
{
2017-03-27 12:38:51 +00:00
if ( isset ( $view -> { 'add_' . $scripter }) && $view -> { 'add_' . $scripter } == 1 && ComponentbuilderHelper :: checkString ( $view -> $scripter ))
2016-02-26 00:20:09 +00:00
{
2017-02-13 23:24:38 +00:00
$view -> $scripter = $this -> setDynamicValues ( base64_decode ( $view -> $scripter ));
2016-02-26 00:20:09 +00:00
// set uikit to views
$this -> uikitComp [ $view -> code ] = ComponentbuilderHelper :: getUikitComp ( $view -> $scripter , $this -> uikitComp [ $view -> code ]);
$this -> setTemplateAndLayoutData ( $view -> $scripter , $view -> code );
// 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 ;
}
}
2017-02-17 18:35:18 +00:00
// (TODO) we may want to automate this .... lets see if someone asks
// if (strpos($view->$scripter,"token") !== false || strpos($view->$scripter,"task=ajax") !== false)
// {
// if(!isset($this->customScriptBuilder['token']))
// {
// $this->customScriptBuilder['token'] = array();
// }
// if (!isset($this->customScriptBuilder['token'][$this->target.$view->code]) || !$this->customScriptBuilder['token'][$this->target.$view->code])
// {
// $this->customScriptBuilder['token'][$this->target.$view->code] = true;
// }
// }
2016-02-26 00:20:09 +00:00
}
}
// add_Ajax for this view
if ( isset ( $view -> add_php_ajax ) && $view -> add_php_ajax == 1 )
{
// check if controller input as been set
$ajax_input = json_decode ( $view -> ajax_input , true );
if ( ComponentbuilderHelper :: checkArray ( $ajax_input ))
{
foreach ( $ajax_input as $option => $values )
{
foreach ( $values as $nr => $value )
{
$this -> customScriptBuilder [ $this -> target ][ 'ajax_controller' ][ $view -> code ][ $nr ][ $option ] = $value ;
}
}
$this -> addSiteAjax = true ;
unset ( $view -> ajax_input );
}
2016-05-10 05:47:47 +00:00
if ( ComponentbuilderHelper :: checkString ( $view -> php_ajaxmethod ))
{
2017-02-13 23:24:38 +00:00
$this -> customScriptBuilder [ $this -> target ][ 'ajax_model' ][ $view -> code ] = $this -> setDynamicValues ( base64_decode ( $view -> php_ajaxmethod ));
2016-05-10 05:47:47 +00:00
$this -> addSiteAjax = true ;
}
2016-02-26 00:20:09 +00:00
// unset anyway
unset ( $view -> php_ajaxmethod );
}
// add the custom buttons
if ( isset ( $view -> add_custom_button ) && $view -> add_custom_button == 1 )
{
if ( ComponentbuilderHelper :: checkString ( $view -> php_model ))
{
$view -> php_model = base64_decode ( $view -> php_model );
2017-02-13 23:24:38 +00:00
$view -> php_model = $this -> setDynamicValues ( $view -> php_model );
2016-02-26 00:20:09 +00:00
}
$view -> php_controller = base64_decode ( $view -> php_controller );
2017-02-13 23:24:38 +00:00
$view -> php_controller = $this -> setDynamicValues ( $view -> php_controller );
2016-02-26 00:20:09 +00:00
// set the button array
$buttons = json_decode ( $view -> custom_button , true );
unset ( $view -> custom_button );
// sort the values
if ( ComponentbuilderHelper :: checkArray ( $buttons ))
{
foreach ( $buttons as $option => $values )
{
foreach ( $values as $nr => $value )
{
$view -> custom_buttons [ $nr ][ $option ] = $value ;
}
}
}
}
// return the found view data
return $view ;
}
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
*
*/
public function getFieldData ( $id , $name_single = null , $name_list = null )
{
2017-02-01 13:17:04 +00:00
if ( ! isset ( $this -> _fieldData [ $id ]) && $id > 0 )
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
// Order it by the ordering field.
$query -> select ( 'a.*' );
2017-09-18 02:20:50 +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' ) . ')' );
$query -> where ( $this -> db -> quoteName ( 'a.id' ) . ' = ' . $this -> db -> quote ( $id ));
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
2016-06-23 15:05:37 +00:00
// adding a fix for the changed name of type to fieldtype
$field -> type = $field -> fieldtype ;
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 ));
2016-02-26 00:20:09 +00:00
2016-06-23 15:05:37 +00:00
// load the type values form type params
2017-09-18 02:20:50 +00:00
$field -> properties = json_decode ( $field -> properties , true );
2016-02-26 00:20:09 +00:00
2016-06-23 15:05:37 +00:00
// check if we have advanced encryption
if ( 4 == $field -> store && ( ! isset ( $this -> advancedEncryption ) || ! $this -> advancedEncryption ))
{
$this -> advancedEncryption = true ;
}
// check if we have basic encryption
elseif ( 3 == $field -> store && ( ! isset ( $this -> basicEncryption ) || ! $this -> basicEncryption ))
{
$this -> basicEncryption = true ;
}
2017-02-01 13:17:04 +00:00
2017-06-16 12:38:06 +00:00
// get the last used version
$field -> history = $this -> getHistoryWatch ( 'field' , $id );
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
if ( isset ( $this -> _fieldData [ $id ]) && $id > 0 )
{
// 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
{
2017-02-01 13:17:04 +00:00
if ( ! isset ( $this -> customScriptBuilder [ 'view_footer' ]))
2016-02-26 00:20:09 +00:00
{
2017-02-01 13:17:04 +00:00
$this -> customScriptBuilder [ 'view_footer' ] = array ();
}
if ( ! isset ( $this -> customScriptBuilder [ 'view_footer' ][ $name_single ]))
{
$this -> customScriptBuilder [ 'view_footer' ][ $name_single ] = '' ;
}
if ( ! isset ( $this -> _fieldData [ $id ] -> javascript_view_footer_decoded ))
{
2017-02-13 23:24:38 +00:00
$this -> _fieldData [ $id ] -> javascript_view_footer = $this -> setDynamicValues ( base64_decode ( $this -> _fieldData [ $id ] -> javascript_view_footer ));
2017-02-01 13:17:04 +00:00
$this -> _fieldData [ $id ] -> javascript_view_footer_decoded = true ;
}
2017-02-09 16:11:10 +00:00
$this -> customScriptBuilder [ 'view_footer' ][ $name_single ] .= PHP_EOL . $this -> _fieldData [ $id ] -> javascript_view_footer ;
2017-02-13 23:24:38 +00:00
if ( strpos ( $this -> _fieldData [ $id ] -> javascript_view_footer , " token " ) !== false ||
2017-02-16 14:02:23 +00:00
strpos ( $this -> _fieldData [ $id ] -> javascript_view_footer , " task=ajax " ) !== false )
2017-02-01 13:17:04 +00:00
{
2017-02-13 23:24:38 +00:00
if ( ! isset ( $this -> customScriptBuilder [ 'token' ]))
{
$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 )
{
if ( ! isset ( $this -> customScriptBuilder [ 'css_view' ]))
2016-02-26 00:20:09 +00:00
{
2017-02-01 13:17:04 +00:00
$this -> customScriptBuilder [ 'css_view' ] = array ();
2016-02-26 00:20:09 +00:00
}
2017-02-01 13:17:04 +00:00
if ( ! isset ( $this -> customScriptBuilder [ 'css_view' ][ $name_single ]))
{
$this -> customScriptBuilder [ 'css_view' ][ $name_single ] = '' ;
}
if ( ! isset ( $this -> _fieldData [ $id ] -> css_view_decoded ))
{
2017-02-13 23:24:38 +00:00
$this -> _fieldData [ $id ] -> css_view = base64_decode ( $this -> _fieldData [ $id ] -> css_view );
// check for custom code
$this -> setCustomCodeData ( $this -> _fieldData [ $id ] -> css_view );
2017-02-01 13:17:04 +00:00
$this -> _fieldData [ $id ] -> css_view_decoded = true ;
}
2017-02-09 16:11:10 +00:00
$this -> customScriptBuilder [ 'css_view' ][ $name_single ] .= PHP_EOL . $this -> _fieldData [ $id ] -> css_view ;
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
{
2017-02-01 13:17:04 +00:00
if ( ! isset ( $this -> customScriptBuilder [ 'views_footer' ]))
2016-06-23 15:05:37 +00:00
{
2017-02-01 13:17:04 +00:00
$this -> customScriptBuilder [ 'views_footer' ] = array ();
}
if ( ! isset ( $this -> customScriptBuilder [ 'views_footer' ][ $name_list ]))
{
$this -> customScriptBuilder [ 'views_footer' ][ $name_list ] = '' ;
}
if ( ! isset ( $this -> _fieldData [ $id ] -> javascript_views_footer_decoded ))
{
2017-02-13 23:24:38 +00:00
$this -> _fieldData [ $id ] -> javascript_views_footer = $this -> setDynamicValues ( base64_decode ( $this -> _fieldData [ $id ] -> javascript_views_footer ));
2017-02-01 13:17:04 +00:00
$this -> _fieldData [ $id ] -> javascript_views_footer_decoded = true ;
2016-06-23 15:05:37 +00:00
}
2017-02-01 13:17:04 +00:00
$this -> customScriptBuilder [ 'views_footer' ][ $name_list ] .= $this -> _fieldData [ $id ] -> javascript_views_footer ;
2017-02-13 23:24:38 +00:00
if ( strpos ( $this -> _fieldData [ $id ] -> javascript_views_footer , " token " ) !== false ||
2017-02-16 14:02:23 +00:00
strpos ( $this -> _fieldData [ $id ] -> javascript_views_footer , " task=ajax " ) !== false )
2016-02-26 00:20:09 +00:00
{
2017-02-13 23:24:38 +00:00
if ( ! isset ( $this -> customScriptBuilder [ 'token' ]))
{
$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
{
2017-02-01 13:17:04 +00:00
if ( ! isset ( $this -> customScriptBuilder [ 'css_views' ]))
{
$this -> customScriptBuilder [ 'css_views' ] = array ();
}
if ( ! isset ( $this -> customScriptBuilder [ 'css_views' ][ $name_list ]))
{
$this -> customScriptBuilder [ 'css_views' ][ $name_list ] = '' ;
}
if ( ! isset ( $this -> _fieldData [ $id ] -> css_views_decoded ))
{
2017-02-13 23:24:38 +00:00
$this -> _fieldData [ $id ] -> css_views = base64_decode ( $this -> _fieldData [ $id ] -> css_views );
// check for custom code
$this -> setCustomCodeData ( $this -> _fieldData [ $id ] -> css_views );
2017-02-01 13:17:04 +00:00
$this -> _fieldData [ $id ] -> css_views_decoded = true ;
}
$this -> customScriptBuilder [ 'css_views' ][ $name_list ] .= $this -> _fieldData [ $id ] -> css_views ;
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-02-01 13:17:04 +00:00
if ( isset ( $this -> _fieldData [ $id ]) && $id > 0 )
{
// return the found field data
return $this -> _fieldData [ $id ];
}
return false ;
2016-02-26 00:20:09 +00:00
}
2016-03-04 00:01:43 +00:00
/**
2016-02-26 00:20:09 +00:00
* Set get Data
*
2016-03-01 18:44:13 +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
*
* @ return oject the get dynamicGet data
*
*/
2017-10-06 14:53:22 +00:00
public function setGetData ( $ids , $view_code )
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' );
foreach ( $results as $nr => & $result )
{
// add calculations if set
2017-03-27 12:38:51 +00:00
if ( $result -> addcalculation == 1 && ComponentbuilderHelper :: checkString ( $result -> php_calculation ))
2016-02-26 00:20:09 +00:00
{
2017-03-27 12:38:51 +00:00
$result -> php_calculation = $this -> setDynamicValues ( base64_decode ( $result -> php_calculation ));
2016-02-26 00:20:09 +00:00
}
// add php custom scripting (php_before_getitem)
2017-03-27 12:38:51 +00:00
if ( $result -> add_php_before_getitem == 1 && ComponentbuilderHelper :: checkString ( $result -> php_before_getitem ))
2016-02-26 00:20:09 +00:00
{
if ( ! isset ( $this -> customScriptBuilder [ $this -> target . '_php_before_getitem' ][ $view_code ]))
{
$this -> customScriptBuilder [ $this -> target . '_php_before_getitem' ][ $view_code ] = '' ;
}
2017-02-13 23:24:38 +00:00
$this -> customScriptBuilder [ $this -> target . '_php_before_getitem' ][ $view_code ] .=
$this -> setDynamicValues ( PHP_EOL . PHP_EOL . base64_decode ( $result -> php_before_getitem ));
2016-02-26 00:20:09 +00:00
unset ( $result -> php_before_getitem );
}
// add php custom scripting (php_after_getitem)
2017-03-27 12:38:51 +00:00
if ( $result -> add_php_after_getitem == 1 && ComponentbuilderHelper :: checkString ( $result -> php_after_getitem ))
2016-02-26 00:20:09 +00:00
{
if ( ! isset ( $this -> customScriptBuilder [ $this -> target . '_php_after_getitem' ][ $view_code ]))
{
$this -> customScriptBuilder [ $this -> target . '_php_after_getitem' ][ $view_code ] = '' ;
}
2017-02-13 23:24:38 +00:00
$this -> customScriptBuilder [ $this -> target . '_php_after_getitem' ][ $view_code ] .=
$this -> setDynamicValues ( PHP_EOL . PHP_EOL . base64_decode ( $result -> php_after_getitem ));
2016-02-26 00:20:09 +00:00
unset ( $result -> php_after_getitem );
}
// add php custom scripting (php_before_getitems)
2017-03-27 12:38:51 +00:00
if ( $result -> add_php_before_getitems == 1 && ComponentbuilderHelper :: checkString ( $result -> php_before_getitems ))
2016-02-26 00:20:09 +00:00
{
if ( ! isset ( $this -> customScriptBuilder [ $this -> target . '_php_before_getitems' ][ $view_code ]))
{
$this -> customScriptBuilder [ $this -> target . '_php_before_getitems' ][ $view_code ] = '' ;
}
2017-02-13 23:24:38 +00:00
$this -> customScriptBuilder [ $this -> target . '_php_before_getitems' ][ $view_code ] .=
$this -> setDynamicValues ( PHP_EOL . PHP_EOL . base64_decode ( $result -> php_before_getitems ));
2016-02-26 00:20:09 +00:00
unset ( $result -> php_before_getitems );
}
// add php custom scripting (php_after_getitems)
2017-03-27 12:38:51 +00:00
if ( $result -> add_php_after_getitems == 1 && ComponentbuilderHelper :: checkString ( $result -> php_after_getitems ))
2016-02-26 00:20:09 +00:00
{
if ( ! isset ( $this -> customScriptBuilder [ $this -> target . '_php_after_getitems' ][ $view_code ]))
{
$this -> customScriptBuilder [ $this -> target . '_php_after_getitems' ][ $view_code ] = '' ;
}
2017-02-13 23:24:38 +00:00
$this -> customScriptBuilder [ $this -> target . '_php_after_getitems' ][ $view_code ] .=
$this -> setDynamicValues ( PHP_EOL . PHP_EOL . base64_decode ( $result -> php_after_getitems ));
2016-02-26 00:20:09 +00:00
unset ( $result -> php_after_getitems );
}
// add php custom scripting (php_getlistquery)
2017-03-27 12:38:51 +00:00
if ( $result -> add_php_getlistquery == 1 && ComponentbuilderHelper :: checkString ( $result -> php_getlistquery ))
2016-02-26 00:20:09 +00:00
{
if ( ! isset ( $this -> customScriptBuilder [ $this -> target . '_php_getlistquery' ][ $view_code ]))
{
$this -> customScriptBuilder [ $this -> target . '_php_getlistquery' ][ $view_code ] = '' ;
}
2017-02-13 23:24:38 +00:00
$this -> customScriptBuilder [ $this -> target . '_php_getlistquery' ][ $view_code ] .=
$this -> setDynamicValues ( PHP_EOL . base64_decode ( $result -> php_getlistquery ));
2016-02-26 00:20:09 +00:00
unset ( $result -> php_getlistquery );
}
// set the getmethod code name
$result -> key = ComponentbuilderHelper :: safeString ( $view_code . ' ' . $result -> name . ' ' . $result -> id );
// reset buckets
$result -> main_get = array ();
$result -> custom_get = array ();
// set source data
switch ( $result -> main_source )
{
case 1 :
// set the view data
2017-10-06 14:53:22 +00:00
$result -> main_get [ 0 ][ 'selection' ] = $this -> setDataSelection ( $result -> key , $view_code , $result -> view_selection , $result -> view_table_main , 'a' , '' , 'view' );
2016-02-26 00:20:09 +00:00
$result -> main_get [ 0 ][ 'as' ] = 'a' ;
$result -> main_get [ 0 ][ 'key' ] = $result -> key ;
unset ( $result -> view_selection );
break ;
case 2 :
// set the database data
2017-10-06 14:53:22 +00:00
$result -> main_get [ 0 ][ 'selection' ] = $this -> setDataSelection ( $result -> key , $view_code , $result -> db_selection , $result -> db_table_main , 'a' , '' , 'db' );
2016-02-26 00:20:09 +00:00
$result -> main_get [ 0 ][ 'as' ] = 'a' ;
$result -> main_get [ 0 ][ 'key' ] = $result -> key ;
unset ( $result -> db_selection );
break ;
case 3 :
// set custom script
$result -> main_get [ 0 ][ 'selection' ] = array (
'select' => base64_decode ( $result -> php_custom_get ),
'from' => '' , 'table' => '' , 'type' => '' );
break ;
}
// set join_view_table details
2017-10-06 14:53:22 +00:00
$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
{
2017-10-06 14:53:22 +00:00
foreach ( $result -> join_view_table as $nr => & $option )
2016-02-26 00:20:09 +00:00
{
2017-10-06 14:53:22 +00:00
if ( ComponentbuilderHelper :: checkString ( $option [ 'selection' ]))
2016-02-26 00:20:09 +00:00
{
2017-10-06 14:53:22 +00:00
// convert the type
$option [ 'type' ] = $typeArray [ $option [ 'type' ]];
// convert the operator
$option [ 'operator' ] = $operatorArray [ $option [ 'operator' ]];
// get the on field values
$on_field = array (); // array(on_field_as, on_field)
$on_field = array_map ( 'trim' , explode ( '.' , $option [ 'on_field' ]));
// get the join field values
$join_field = array (); // array(join_field_as, join_field)
$join_field = array_map ( 'trim' , explode ( '.' , $option [ 'join_field' ]));
$option [ 'selection' ] =
$this -> setDataSelection ( $result -> key , $view_code , $option [ 'selection' ], $option [ 'view_table' ], $option [ 'as' ], $option [ 'row_type' ], 'view' );
$option [ 'key' ] = $result -> key ;
// load to the getters
if ( $option [ 'row_type' ] == 1 )
2016-02-26 00:20:09 +00:00
{
2017-10-06 14:53:22 +00:00
$result -> main_get [] = $option ;
if ( $on_field [ 0 ] === 'a' )
2016-02-26 00:20:09 +00:00
{
2017-10-06 14:53:22 +00:00
$this -> siteMainGet [ $this -> target ][ $view_code ][ $option [ 'as' ]] = $option [ 'as' ];
2016-02-26 00:20:09 +00:00
}
else
{
2017-10-06 14:53:22 +00:00
$this -> siteDynamicGet [ $this -> target ][ $view_code ][ $option [ 'as' ]][ $join_field [ 1 ]] = $on_field [ 0 ];
}
}
elseif ( $option [ 'row_type' ] == 2 )
{
$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
}
}
}
2017-10-06 14:53:22 +00:00
unset ( $result -> join_view_table [ $nr ]);
2016-02-26 00:20:09 +00:00
}
}
unset ( $result -> join_view_table );
// set join_db_table details
2017-10-06 14:53:22 +00:00
$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
{
2017-10-06 14:53:22 +00:00
foreach ( $result -> join_db_table as $nr => & $option1 )
2016-02-26 00:20:09 +00:00
{
2017-10-06 14:53:22 +00:00
if ( ComponentbuilderHelper :: checkString ( $option1 [ 'selection' ]))
2016-02-26 00:20:09 +00:00
{
2017-10-06 14:53:22 +00:00
// convert the type
$option1 [ 'type' ] = $typeArray [ $option1 [ 'type' ]];
// convert the operator
$option1 [ 'operator' ] = $operatorArray [ $option1 [ 'operator' ]];
// get the on field values
$on_field = array (); // array(on_field_as, on_field)
$on_field = array_map ( 'trim' , explode ( '.' , $option1 [ 'on_field' ]));
// get the join field values
$join_field = array (); // array(join_field_as, join_field)
$join_field = array_map ( 'trim' , explode ( '.' , $option1 [ 'join_field' ]));
$option1 [ 'selection' ] =
$this -> setDataSelection ( $result -> key , $view_code , $value , $option1 [ 'db_table' ], $option1 [ 'as' ], $option1 [ 'row_type' ], 'db' );
$option1 [ 'key' ] = $result -> key ;
// load to the getters
if ( $option1 [ 'row_type' ] == 1 )
2016-02-26 00:20:09 +00:00
{
2017-10-06 14:53:22 +00:00
$result -> main_get [] = $option1 ;
if ( $on_field [ 0 ] === 'a' )
2016-02-26 00:20:09 +00:00
{
2017-10-06 14:53:22 +00:00
$this -> siteMainGet [ $this -> target ][ $view_code ][ $option1 [ 'as' ]] = $option1 [ 'as' ];
2016-02-26 00:20:09 +00:00
}
else
{
2017-10-06 14:53:22 +00:00
$this -> siteDynamicGet [ $this -> target ][ $view_code ][ $option1 [ 'as' ]][ $join_field [ 1 ]] = $on_field [ 0 ];
2016-02-26 00:20:09 +00:00
}
}
2017-10-06 14:53:22 +00:00
elseif ( $option1 [ 'row_type' ] == 2 )
2016-02-26 00:20:09 +00:00
{
2017-10-06 14:53:22 +00:00
$result -> custom_get [] = $option1 ;
if ( $on_field [ 0 ] != 'a' )
2016-02-26 00:20:09 +00:00
{
2017-10-06 14:53:22 +00:00
$this -> siteDynamicGet [ $this -> target ][ $view_code ][ $option1 [ 'as' ]][ $join_field [ 1 ]] = $on_field [ 0 ];
2016-02-26 00:20:09 +00:00
}
}
}
2017-10-06 14:53:22 +00:00
unset ( $result -> join_db_table [ $nr ]);
2016-02-26 00:20:09 +00:00
}
}
2017-10-06 14:53:22 +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
{
2017-10-06 14:53:22 +00:00
foreach ( $result -> filter as $nr => & $option2 )
2016-02-26 00:20:09 +00:00
{
2017-10-06 14:53:22 +00:00
if ( isset ( $option2 [ 'operator' ]))
2016-02-26 00:20:09 +00:00
{
2017-10-06 14:53:22 +00:00
$option2 [ 'operator' ] = $operatorArray [ $option2 [ 'operator' ]];
$option2 [ 'key' ] = $result -> key ;
2016-02-26 00:20:09 +00:00
}
2017-10-06 14:53:22 +00:00
else
2016-02-26 00:20:09 +00:00
{
2017-10-06 14:53:22 +00:00
unset ( $result -> filter [ $nr ]);
2016-02-26 00:20:09 +00:00
}
}
}
// set where details
2017-10-06 14:53:22 +00:00
$result -> where = json_decode ( $result -> where , true );
if ( ComponentbuilderHelper :: checkArray ( $result -> where ))
2016-02-26 00:20:09 +00:00
{
2017-10-06 14:53:22 +00:00
foreach ( $result -> where as $nr => & $option3 )
2016-02-26 00:20:09 +00:00
{
2017-10-06 14:53:22 +00:00
if ( isset ( $option3 [ 'operator' ]))
2016-02-26 00:20:09 +00:00
{
2017-10-06 14:53:22 +00:00
$option3 [ 'operator' ] = $operatorArray [ $option3 [ 'operator' ]];
}
else
{
unset ( $result -> where [ $nr ]);
2016-02-26 00:20:09 +00:00
}
}
}
2017-10-06 14:53:22 +00:00
else
{
unset ( $result -> where );
}
// set order details
$result -> order = json_decode ( $result -> order , true );
if ( ! ComponentbuilderHelper :: checkArray ( $result -> order ))
{
unset ( $result -> order );
}
// 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
}
return $results ;
}
}
}
return false ;
}
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
*
* @ return void
*
*/
protected function setUpdateSQL ( $old , $new , $type , $key = null )
{
// check if there were new items added
if ( isset ( $new [ $type ]) && ComponentbuilderHelper :: checkArray ( $new [ $type ])
&& isset ( $old [ $type ]) && ComponentbuilderHelper :: checkArray ( $old [ $type ]))
{
foreach ( $new [ $type ] as $item )
{
if ( ! in_array ( $item , $old [ $type ]))
{
// 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 ;
}
}
}
}
}
elseif ( $key && ComponentbuilderHelper :: checkString ( $new )
&& ComponentbuilderHelper :: checkString ( $old )
&& $new !== $old )
{
// 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
$this -> updateSQL [ $type ][ $key ] = array ( 'old' => $old , 'new' => $new );
}
}
/**
* 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' );
$query -> where ( $this -> db -> quoteName ( 'h.ucm_item_id' ) . ' = ' . ( int ) $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' );
$query -> where ( 'ct.type_alias = ' . $this -> db -> quote ( 'com_componentbuilder.' . $type ));
$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' );
$query -> where ( 'ct.type_alias = ' . $this -> db -> quote ( 'com_componentbuilder.' . $type ));
$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 ;
}
/**
* Set Item History Watch
*
* @ param Object $object The history object
* @ param int $action The action to take
* 0 = remove watch
* 1 = add watch
* @ 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
if ( isset ( $version_note [ 'component' ]) && ( $key = array_search ( $this -> componentID , $version_note [ 'component' ])) !== false )
{
// 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 ;
}
break ;
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 ;
}
break ;
}
// 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' );
}
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
*
*/
public function setTemplateAndLayoutData ( $default , $view )
{
// set the Tempale date
$temp1 = ComponentbuilderHelper :: getAllBetween ( $default , " \$ this->loadTemplate(' " , " ') " );
$temp2 = ComponentbuilderHelper :: getAllBetween ( $default , '$this->loadTemplate("' , '")' );
$templates = array ();
$again = array ();
if ( ComponentbuilderHelper :: checkArray ( $temp1 ) && ComponentbuilderHelper :: checkArray ( $temp2 ))
{
$templates = array_merge ( $temp1 , $temp2 );
}
else
{
if ( ComponentbuilderHelper :: checkArray ( $temp1 ))
{
$templates = $temp1 ;
}
elseif ( ComponentbuilderHelper :: checkArray ( $temp2 ))
{
$templates = $temp2 ;
}
}
if ( ComponentbuilderHelper :: checkArray ( $templates ))
{
foreach ( $templates as $template )
{
if ( ! isset ( $this -> templateData [ $this -> target ][ $view ]) || ! array_key_exists ( $template , $this -> templateData [ $this -> target ][ $view ]))
{
$data = $this -> getDataWithAlias ( $template , 'template' , $view );
if ( ComponentbuilderHelper :: checkArray ( $data ))
{
$this -> templateData [ $this -> target ][ $view ][ $template ] = $data ;
// call self to get child data
$again [] = array ( $data [ 'html' ], $view );
$again [] = array ( $data [ 'php_view' ], $view );
}
}
}
}
// set the layout data
$lay1 = ComponentbuilderHelper :: getAllBetween ( $default , " JLayoutHelper::render(' " , " ', " );
$lay2 = ComponentbuilderHelper :: getAllBetween ( $default , 'JLayoutHelper::render("' , '",' );;
if ( ComponentbuilderHelper :: checkArray ( $lay1 ) && ComponentbuilderHelper :: checkArray ( $lay2 ))
{
$layouts = array_merge ( $lay1 , $lay2 );
}
else
{
if ( ComponentbuilderHelper :: checkArray ( $lay1 ))
{
$layouts = $lay1 ;
}
elseif ( ComponentbuilderHelper :: checkArray ( $lay2 ))
{
$layouts = $lay2 ;
}
}
if ( isset ( $layouts ) && ComponentbuilderHelper :: checkArray ( $layouts ))
{
foreach ( $layouts as $layout )
{
if ( ! isset ( $this -> layoutData [ $this -> target ]) || ! ComponentbuilderHelper :: checkArray ( $this -> layoutData [ $this -> target ]) || ! array_key_exists ( $layout , $this -> layoutData [ $this -> target ]))
{
$data = $this -> getDataWithAlias ( $layout , 'layout' , $view );
if ( ComponentbuilderHelper :: checkArray ( $data ))
{
$this -> layoutData [ $this -> target ][ $layout ] = $data ;
// call self to get child data
$again [] = array ( $data [ 'html' ], $view );
$again [] = array ( $data [ 'php_view' ], $view );
}
}
}
}
if ( ComponentbuilderHelper :: checkArray ( $again ))
{
foreach ( $again as $go )
{
$this -> setTemplateAndLayoutData ( $go [ 0 ], $go [ 1 ]);
}
}
}
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
*
*/
public function getDataWithAlias ( $n_ame , $table , $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.*' );
$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
{
2017-02-13 23:24:38 +00:00
$php_view = $this -> setDynamicValues ( base64_decode ( $row -> php_view ));
2016-02-26 00:20:09 +00:00
}
2017-02-13 23:24:38 +00:00
$contnent = $this -> setDynamicValues ( base64_decode ( $row -> { $table }));
2016-02-26 00:20:09 +00:00
// set uikit to views
$this -> uikitComp [ $view ] = ComponentbuilderHelper :: getUikitComp ( $contnent , $this -> uikitComp [ $view ]);
// 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 ;
}
}
return array ( 'id' => $row -> id , 'html' => $contnent , 'php_view' => $php_view );
}
}
return false ;
}
2016-03-04 00:01:43 +00:00
/**
2017-02-13 23:24:38 +00:00
* Set Language Place Holders
2016-02-26 00:20:09 +00:00
*
* @ param string $content The content
*
* @ return string The content with the updated Language place holder
*
*/
2017-02-13 23:24:38 +00:00
public function setLangStrings ( $content )
2016-02-26 00:20:09 +00:00
{
2017-02-13 23:24:38 +00:00
// first check if we should continue
if ( strpos ( $content , 'JText::_(' ) !== false || strpos ( $content , 'JText::sprintf(' ) !== false )
{
// insure string is not broken
$content = str_replace ( 'COM_###COMPONENT###' , $this -> langPrefix , $content );
// set language data
$langCheck [] = ComponentbuilderHelper :: getAllBetween ( $content , " JText::_(' " , " ' " );
$langCheck [] = ComponentbuilderHelper :: getAllBetween ( $content , 'JText::_("' , '"' );
$langCheck [] = ComponentbuilderHelper :: getAllBetween ( $content , " JText::sprintf(' " , " ' " );
$langCheck [] = ComponentbuilderHelper :: getAllBetween ( $content , 'JText::sprintf("' , '"' );
$langArray = ComponentbuilderHelper :: mergeArrays ( $langCheck );
if ( ComponentbuilderHelper :: checkArray ( $langArray ))
2016-02-26 00:20:09 +00:00
{
2017-02-13 23:24:38 +00:00
foreach ( $langArray as $string )
2016-02-26 00:20:09 +00:00
{
2017-02-13 23:24:38 +00:00
// this is there to insure we dont break already added Language strings
if ( ComponentbuilderHelper :: safeString ( $string , 'U' ) === $string )
{
continue ;
}
// only load if string is not already set
$keyLang = $this -> langPrefix . '_' . ComponentbuilderHelper :: safeString ( $string , 'U' );
if ( ! isset ( $this -> langContent [ $this -> lang ][ $keyLang ]))
{
$this -> langContent [ $this -> lang ][ $keyLang ] = trim ( $string );
}
$langHolders [ " JText::_(' " . $string . " ') " ] = " JText::_(' " . $keyLang . " ') " ;
$langHolders [ 'JText::_("' . $string . '")' ] = 'JText::_("' . $keyLang . '")' ;
$langHolders [ " JText::sprintf(' " . $string . " ', " ] = " JText::sprintf(' " . $keyLang . " ', " ;
$langHolders [ 'JText::sprintf("' . $string . '",' ] = 'JText::sprintf("' . $keyLang . '",' ;
2016-02-26 00:20:09 +00:00
}
2017-03-08 04:49:54 +00:00
// only continue if we have value to replace
if ( isset ( $langHolders ) && ComponentbuilderHelper :: checkArray ( $langHolders ))
{
$content = $this -> setPlaceholders ( $content , $langHolders );
}
2016-02-26 00:20:09 +00:00
}
}
return $content ;
}
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
* @ param string || INT $asset The asset in question
* @ 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 ))
{
$lines = explode ( PHP_EOL , $string );
if ( ComponentbuilderHelper :: checkArray ( $lines ))
{
2017-02-02 11:54:07 +00:00
if ( 'db' === $type )
2016-02-26 00:20:09 +00:00
{
$table = '#__' . $asset ;
$queryName = $asset ;
$view = '' ;
}
2017-02-02 11:54:07 +00:00
elseif ( 'view' === $type )
2016-02-26 00:20:09 +00:00
{
$view = $this -> getViewTableName ( $asset );
$table = '#__' . $this -> componentCodeName . '_' . $view ;
$queryName = $view ;
}
$gets = array ();
$keys = array ();
foreach ( $lines as $line )
{
if ( strpos ( $line , 'AS' ) !== false )
{
list ( $get , $key ) = explode ( " AS " , $line );
}
elseif ( strpos ( $line , 'as' ) !== false )
{
list ( $get , $key ) = explode ( " as " , $line );
}
else
{
$get = $line ;
$key = null ;
}
$get = trim ( $get );
$key = trim ( $key );
// only add the view
2017-02-02 11:54:07 +00:00
if ( 'a' != $as && 1 == $row_type && 'view' === $type && strpos ( '#' . $key , '#' . $view . '_' ) === false )
2016-02-26 00:20:09 +00:00
{
$key = $view . '_' . trim ( $key );
}
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
{
$key = str_replace ( $as . '.' , '' , $get );
$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
}
if ( ComponentbuilderHelper :: checkString ( $view ))
{
$field = str_replace ( $as . '.' , '' , $get );
$this -> siteFields [ $view ][ $field ][ $method_key ] = array ( 'site' => $view_code , 'get' => $get , 'as' => $as , 'key' => $key );
}
}
}
if ( ComponentbuilderHelper :: checkArray ( $gets ) && ComponentbuilderHelper :: checkArray ( $keys ))
{
2017-02-09 16:11:10 +00:00
$querySelect = '$query->select($db->quoteName(' . PHP_EOL . " \t \t \t " . 'array(' . implode ( ',' , $gets ) . '),' . PHP_EOL . " \t \t \t " . 'array(' . implode ( ',' , $keys ) . ')));' ;
2017-02-13 23:24:38 +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 ;
}
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' )));
$query -> from ( $this -> db -> quoteName ( '#__componentbuilder_admin_view' , 'a' ));
$query -> where ( $this -> db -> quoteName ( 'a.id' ) . ' = ' . ( int ) $id );
$this -> db -> setQuery ( $query );
return ComponentbuilderHelper :: safeString ( $this -> db -> loadResult ());
2016-02-26 00:20:09 +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
*
*/
public function buildSqlDump ( $tables , $view , $view_id )
{
// 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 );
2016-02-26 00:20:09 +00:00
foreach ( $tables as $table )
{
2017-02-01 13:17:04 +00:00
if ( $counter === 'a' )
2016-02-26 00:20:09 +00:00
{
// the main table fields
if ( strpos ( $table [ 'sourcemap' ], PHP_EOL ) !== false )
{
$fields = explode ( PHP_EOL , $table [ 'sourcemap' ]);
if ( ComponentbuilderHelper :: checkArray ( $fields ))
{
// reset array buckets
$sourceArray = array ();
$targetArray = array ();
foreach ( $fields as $field )
{
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
2017-02-13 23:24:38 +00:00
$query -> select ( $this -> db -> quoteName ( $sourceArray , $targetArray ));
2016-02-26 00:20:09 +00:00
$query -> from ( '#__' . $table [ 'table' ] . ' AS a' );
}
// 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' ] . ')' );
}
}
}
}
else
{
// the other tables
if ( strpos ( $table [ 'sourcemap' ], PHP_EOL ) !== false )
{
$fields = explode ( PHP_EOL , $table [ 'sourcemap' ]);
if ( ComponentbuilderHelper :: checkArray ( $fields ))
{
// reset array buckets
$sourceArray = array ();
$targetArray = array ();
foreach ( $fields as $field )
{
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
2017-02-13 23:24:38 +00:00
$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
}
}
if ( ComponentbuilderHelper :: checkArray ( $sourceArray ) && ComponentbuilderHelper :: checkArray ( $targetArray ))
{
// add to query
2017-02-13 23:24:38 +00:00
$query -> select ( $this -> db -> quoteName ( $sourceArray , $targetArray ));
2016-02-26 00:20:09 +00:00
}
}
}
}
$counter ++ ;
}
// now get the data
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
{
// get the data
2017-02-13 23:24:38 +00:00
$data = $this -> db -> loadObjectList ();
2016-02-26 00:20:09 +00:00
// start building the MySql dump
$dump = " -- " ;
2017-02-09 16:11:10 +00:00
$dump .= PHP_EOL . " -- Dumping data for table `#__[[[component]]]_ " . $view . " ` " ;
$dump .= PHP_EOL . " -- " ;
$dump .= PHP_EOL . PHP_EOL . " INSERT INTO `#__[[[component]]]_ " . $view . " ` ( " ;
2016-02-26 00:20:09 +00:00
foreach ( $data as $line )
{
$comaSet = 0 ;
foreach ( $line as $fieldName => $fieldValue )
{
if ( $comaSet == 0 )
{
2017-02-13 23:24:38 +00:00
$dump .= $this -> db -> quoteName ( $fieldName );
2016-02-26 00:20:09 +00:00
}
else
{
2017-02-13 23:24:38 +00:00
$dump .= " , " . $this -> db -> quoteName ( $fieldName );
2016-02-26 00:20:09 +00:00
}
$comaSet ++ ;
}
break ;
}
$dump .= " ) VALUES " ;
$coma = 0 ;
foreach ( $data as $line )
{
if ( $coma == 0 )
{
2017-02-09 16:11:10 +00:00
$dump .= PHP_EOL . " ( " ;
2016-02-26 00:20:09 +00:00
}
else
{
2017-02-09 16:11:10 +00:00
$dump .= " , " . PHP_EOL . " ( " ;
2016-02-26 00:20:09 +00:00
}
$comaSet = 0 ;
foreach ( $line as $fieldName => $fieldValue )
{
if ( $comaSet == 0 )
{
$dump .= $this -> mysql_escape ( $fieldValue );
}
else
{
$dump .= " , " . $this -> mysql_escape ( $fieldValue );
}
$comaSet ++ ;
}
$dump .= " ) " ;
$coma ++ ;
}
$dump .= " ; " ;
// return build dump query
return $dump ;
}
}
return false ;
}
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
if ( ComponentbuilderHelper :: checkArray ( $value ))
{
return array_map ( __METHOD__ , $value );
}
// if string make sure it is correctly escaped
if ( ComponentbuilderHelper :: checkString ( $value ) && ! is_numeric ( $value ))
{
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
if ( empty ( $value ))
{
return " '' " ;
}
// if not array or string then return number
return $value ;
}
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 )
{
2016-02-26 13:57:30 +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
2016-02-26 13:57:30 +00:00
return $this -> uniqueCode ( $code . $this -> uniquekey ( 1 ));
}
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
}
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 )
{
if ( strpos ( $content , 'footable' ) !== false )
{
return true ;
}
return false ;
}
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 )
{
if ( strpos ( $content , 'this->getModules(' ) !== false )
{
return true ;
}
return false ;
}
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 getGoogleChart ( $content )
{
if ( strpos ( $content , 'Chartbuilder(' ) !== false )
{
return true ;
}
return false ;
}
2017-02-01 13:17:04 +00:00
2017-02-13 23:24:38 +00:00
/**
* Set the dynamic values in strings here
*
* @ param string $string The content to check
*
* @ return string
*
*/
public function setDynamicValues ( $string )
{
2017-03-08 04:49:54 +00:00
if ( ComponentbuilderHelper :: checkString ( $string ))
{
return $this -> setLangStrings ( $this -> setCustomCodeData ( $string ));
}
return $string ;
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
* @ param bool $insert Should we insert the code into the content
* @ param bool $bool Should we return bool on success
*
* @ return string | bool based on sig
*
*/
public function setCustomCodeData ( $string )
{
// insure the code is loaded
$loaded = false ;
// check if content has custom code place holder
if ( strpos ( $string , '[CUSTO' . 'MCODE=' ) !== false )
{
// the ids found in this content
$bucket = array ();
$found = ComponentbuilderHelper :: getAllBetween ( $string , '[CUSTO' . 'MCODE=' , ']' );
if ( ComponentbuilderHelper :: checkArray ( $found ))
{
foreach ( $found as $key )
{
// 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 ]))
{
if ( ! $found = ComponentbuilderHelper :: getVar ( 'custom_code' , $getFuncName , 'function_name' , 'id' ))
{
continue ;
}
$this -> functionNameMemory [ $getFuncName ] = $found ;
}
$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 ]))
{
if ( ! $found = ComponentbuilderHelper :: getVar ( 'custom_code' , $getFuncName , 'function_name' , 'id' ))
{
continue ;
}
$this -> functionNameMemory [ $getFuncName ] = $found ;
}
$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 )
{
$this -> customCodeData [ $id ][ 'args' ][ $key ] = explode ( ',' , $array [ 1 ]);
}
elseif ( ComponentbuilderHelper :: checkString ( $array [ 1 ]))
{
$this -> customCodeData [ $id ][ 'args' ][ $key ] = array ();
$this -> customCodeData [ $id ][ 'args' ][ $key ][] = $array [ 1 ];
}
}
}
}
else
{
continue ;
}
$bucket [ $id ] = $id ;
}
}
// 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
$loaded = $this -> getCustomCode ( $bucket , false );
// revert lang to current setting
$this -> lang = $_tmpLang ;
}
// when the custom code is loaded
if ( $loaded === true )
{
$string = $this -> insertCustomCode ( $string );
}
}
return $string ;
}
/**
* Insert the custom code into the string
*
* @ param string $string The content to check
*
* @ return string on success
*
*/
protected function insertCustomCode ( $string )
{
$code = array ();
foreach ( $this -> customCode as $item )
{
$this -> buildCustomCodePlaceholders ( $item , $code );
}
// now update the string
return $this -> setPlaceholders ( $string , $code );
}
/**
* Insert the custom code into the string
*
* @ param string $string The content to check
*
* @ return string on success
*
*/
protected function buildCustomCodePlaceholders ( $item , & $code )
{
// 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 );
// we have args and so need to load each
foreach ( $this -> customCodeData [ $item [ 'id' ]][ 'args' ] as $key => $args )
{
$this -> setThesePlaceHolders ( 'arg' , $args );
$code [ '[CUSTOM' . 'CODE=' . $key . ']' ] = $placeholder [ 'start' ] . PHP_EOL . $this -> setPlaceholders ( $item [ 'code' ], $this -> placeholders ) . $placeholder [ 'end' ];
}
// 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
$placeholderType = ( int ) $item [ 'comment_type' ] . '2' ;
2017-10-06 14:53:22 +00:00
if ( stripos ( $item [ 'code' ], '[[[view' ) !== false || stripos ( $item [ 'code' ], '[[[sview' ) !== false || stripos ( $item [ 'code' ], '[[[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
$placeholder = $this -> getPlaceHolder ( $placeholderType , $item [ 'id' ]);
$code [ '[CUSTOM' . 'CODE=' . $keyPlaceholder . ']' ] = $placeholder [ 'start' ] . PHP_EOL . $this -> setPlaceholders ( $item [ 'code' ], $this -> placeholders ) . $placeholder [ 'end' ];
}
}
/**
* Set a type of placeholder with set of values
*
* @ param string $key The main string for placeholder key
* @ param array $values The values to add
*
* @ return void
*/
public function setThesePlaceHolders ( $key , $values )
{
// aways fist reset these
$this -> clearFromPlaceHolders ( $key );
if ( ComponentbuilderHelper :: checkArray ( $values ))
{
$number = 0 ;
foreach ( $values as $value )
{
$this -> placeholders [ '[[[' . $key . $number . ']]]' ] = $value ;
$number ++ ;
}
}
}
/**
* 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-02-01 13:17:04 +00:00
/**
* to unset stuff that are private or protected
*
*/
public function unsetNow ( $remove )
{
unset ( $this -> $remove );
}
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 );
$query -> from ( $this -> db -> quoteName ( '#__componentbuilder_language_translation' , 'a' ));
if ( ComponentbuilderHelper :: checkArray ( $values ))
{
2017-04-07 20:33:35 +00:00
$query -> select ( $this -> db -> quoteName ( array ( 'a.id' , 'a.translation' , 'a.entranslation' , 'a.components' , 'a.published' )));
2017-04-05 13:21:10 +00:00
$query -> where ( $this -> db -> quoteName ( 'a.entranslation' ) . ' IN (' . implode ( ',' , array_map ( function ( $a ){ return $this -> db -> quote ( $a ); }, $values )) . ')' );
$this -> db -> setQuery ( $query );
$this -> db -> execute ();
if ( $this -> db -> getNumRows ())
{
return $this -> db -> loadAssocList ( 'entranslation' );
}
}
return false ;
}
/**
* 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 ();
foreach ( $this -> languages [ 'en-GB' ] as $area => $placeholders )
{
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
if ( isset ( $this -> multiLangString [ $string ][ 'translation' ])
2017-09-18 00:18:23 +00:00
&& 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-04-05 16:26:17 +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
$this -> newLangStrings [ $counterInsert ] = array ();
$this -> newLangStrings [ $counterInsert ][] = $this -> db -> quote ( json_encode ( array ( $this -> componentID ))); // 'components'
$this -> newLangStrings [ $counterInsert ][] = $this -> db -> quote ( $string ); // 'entranslation'
$this -> newLangStrings [ $counterInsert ][] = $this -> db -> quote ( 1 ); // 'published'
$this -> newLangStrings [ $counterInsert ][] = $this -> db -> quote ( $today ); // 'created'
$this -> newLangStrings [ $counterInsert ][] = $this -> db -> quote (( int ) $this -> user -> id ); // 'created_by'
$this -> newLangStrings [ $counterInsert ][] = $this -> db -> quote ( 1 ); // 'version'
$this -> newLangStrings [ $counterInsert ][] = $this -> db -> quote ( 1 ); // 'access'
$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 ();
}
/**
* store the language placeholders
*
* @ param int $when To set when to update
*
* @ return void
*
*/
protected function setNewLangStrings ( $when = 1 )
{
if ( count ( $this -> newLangStrings ) >= $when )
{
// Create a new query object.
$query = $this -> db -> getQuery ( true );
$continue = false ;
// Insert columns.
$columns = array ( 'components' , 'entranslation' , 'published' , 'created' , 'created_by' , 'version' , 'access' );
// Prepare the insert query.
$query -> insert ( $this -> db -> quoteName ( '#__componentbuilder_language_translation' ));
$query -> columns ( $this -> db -> quoteName ( $columns ));
foreach ( $this -> newLangStrings as $values )
{
if ( count ( $values ) == 7 )
{
$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 ();
}
}
/**
* update the language placeholders
*
* @ param int $when To set when to update
*
* @ return void
*
*/
protected function setExistingLangStrings ( $when = 1 )
{
if ( count ( $this -> existingLangStrings ) >= $when )
{
foreach ( $this -> existingLangStrings as $values )
{
// 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
$this -> existingLangStrings = array ();
}
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 );
// delete all custom keys for user 1001.
$conditions = array (
$this -> db -> quoteName ( 'id' ) . ' = ' . ( int ) $id
);
$query -> delete ( $this -> db -> quoteName ( '#__componentbuilder_language_translation' ));
$query -> where ( $conditions );
$this -> db -> setQuery ( $query );
$this -> db -> execute ();
}
/**
* 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 );
$query -> from ( $this -> db -> quoteName ( '#__componentbuilder_language_translation' , 'a' ));
$query -> select ( $this -> db -> quoteName ( array ( 'a.id' , 'a.translation' , 'a.components' )));
// get all string that are not linked to this component
$query -> where ( $this -> db -> quoteName ( 'a.entranslation' ) . ' NOT IN (' . implode ( ',' , array_map ( function ( $a ){ return $this -> db -> quote ( $a ); }, $values )) . ')' );
$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 ();
}
}
/**
* 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
$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-02-01 13:17:04 +00:00
/**
* get the custom code from the system
*
* @ return void
*
*/
2017-02-13 23:24:38 +00:00
public function getCustomCode ( $ids = null , $setLang = true )
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 );
$query -> from ( $this -> db -> quoteName ( '#__componentbuilder_custom_code' , 'a' ));
if ( ComponentbuilderHelper :: checkArray ( $ids ))
2017-02-09 16:11:10 +00:00
{
2017-02-13 23:24:38 +00:00
if ( $idArray = $this -> customCodeMemory ( $ids ))
{
$query -> select ( $this -> db -> quoteName ( array ( 'a.id' , 'a.code' , 'a.comment_type' )));
$query -> where ( $this -> db -> quoteName ( 'a.id' ) . ' IN (' . implode ( ',' , $idArray ) . ')' );
$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-02-13 23:24:38 +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 );
$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-02-13 23:24:38 +00:00
foreach ( $bucket as $nr => & $customCode )
2017-02-01 13:17:04 +00:00
{
$customCode [ 'code' ] = base64_decode ( $customCode [ 'code' ]);
2017-02-13 23:24:38 +00:00
if ( $setLang )
{
$customCode [ 'code' ] = $this -> setLangStrings ( $customCode [ 'code' ]);
}
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' ]);
if ( $customCode [ 'type' ] == 1 && strpos ( $customCode [ 'hashendtarget' ], '__' ) !== false )
{
$customCode [ 'hashendtarget' ] = explode ( " __ " , $customCode [ 'hashendtarget' ]);
}
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-02-13 23:24:38 +00:00
/**
* check if we already have these ids in local memory
*
* @ return void
*
*/
protected function customCodeMemory ( $ids )
{
// 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-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
{
if ( count ( $this -> newCustomCode ) >= $when )
{
// 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-02-13 23:24:38 +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-02-09 16:11:10 +00:00
foreach ( $this -> newCustomCode as $values )
{
2017-02-13 23:24:38 +00:00
if ( count ( $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
}
}
/**
* 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
{
if ( count ( $this -> existingCustomCode ) >= $when )
{
foreach ( $this -> existingCustomCode as $code )
{
// 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
$this -> existingCustomCode = array ();
}
}
/**
* 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
$fileTypes = array ( '\.php' , '\.js' );
2017-02-11 02:24:26 +00:00
// set some local placeholders
$placeholders = array ();
2017-02-13 23:24:38 +00:00
$placeholders [ ComponentbuilderHelper :: safeString ( $this -> componentCodeName , 'F' ) . 'Helper::' ] = '[[[Component]]]Helper::' ;
$placeholders [ 'COM_' . ComponentbuilderHelper :: safeString ( $this -> componentCodeName , 'U' )] = 'COM_[[[COMPONENT]]]' ;
$placeholders [ 'com_' . $this -> componentCodeName ] = 'com_[[[component]]]' ;
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
{
2017-02-16 14:02:23 +00:00
// get a list of files in the current directory tree (only PHP and JS for now)
2017-02-14 00:33:24 +00:00
$files = JFolder :: files ( '.' , $type , true , true );
foreach ( $files as $file )
2017-02-01 13:17:04 +00:00
{
2017-02-14 00:33:24 +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-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
}
}
/**
* 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
{
// reset each time per file
$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
$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
$file = str_replace ( './' , '' , $file );
if ( $file !== 'script.php' )
{
$path = $target . '/' . $file ;
}
else
{
$path = $file ;
2017-02-11 02:24:26 +00:00
}
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-02-09 16:11:10 +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 )
{
$targetKey = $type ;
2017-02-11 02:24:26 +00:00
$start = '/***[' . $search . '***/' ;
$end = '/***[/' . $search . '***/' ;
2017-02-13 23:24:38 +00:00
$startHTML = '<!--[' . $search . '-->' ;
$endHTML = '<!--[/' . $search . '-->' ;
2017-02-01 13:17:04 +00:00
// check if the ending place holder was found
2017-02-13 23:24:38 +00:00
if ( isset ( $reading [ $targetKey ]) && $reading [ $targetKey ] &&
(( trim ( $lineContent ) === $end || strpos ( $lineContent , $end ) !== false ) ||
( 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
if ( $_line = $this -> addLineChecker ( $endReplace , 2 , $lineContent ))
{
$codeBucket [ $pointer [ $targetKey ]][] = $_line ;
}
2017-02-01 13:17:04 +00:00
// deactivate the reader
$reading [ $targetKey ] = false ;
if ( $_type == 2 )
{
// deactivate search
$reader = 0 ;
}
else
{
// activate fingerPrint for replacement end target
$loadEndFingerPrint = true ;
$backupTargetKey = $targetKey ;
2017-02-09 16:11:10 +00:00
$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-02-13 23:24:38 +00:00
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote (( int ) $lineNumber ); // 'toline'
// first reverse engineer this code block
$c0de = $this -> reversePlaceholders ( implode ( '' , $codeBucket [ $pointer [ $targetKey ]]), $placeholders );
$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
2017-02-13 23:24:38 +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
$c0de = $this -> reversePlaceholders ( implode ( '' , $codeBucket [ $pointer [ $targetKey ]]), $placeholders , $this -> existingCustomCode [ $pointer [ $targetKey ]][ 'id' ]);
$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
if ( count ( $endFingerPrint ) === 3 )
{
$hashendtarget = '3__' . md5 ( implode ( '' , $endFingerPrint ));
// all new records we can do a bulk insert
if ( $i === 1 )
{
// load the last value
2017-02-13 23:24:38 +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
$endFingerPrint = array ();
$loadEndFingerPrint = false ;
// deactivate reader (to allow other search)
$reader = 0 ;
}
// 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 ))
{
$commentType = 1 ; // PHP/JS type
$startReplace = $start ;
$endReplace = $end ;
}
// 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-02-13 23:24:38 +00:00
$commentType = 2 ; // HTML type
$startReplace = $startHTML ;
$endReplace = $endHTML ;
}
// check if the starting place holder was found
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 ;
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-02-13 23:24:38 +00:00
$reader = $i ;
2017-02-01 13:17:04 +00:00
// set pointer
$pointer [ $targetKey ] = $counter [ $i ];
// activate the reader
$reading [ $targetKey ] = true ;
// start code bucket
2017-02-13 23:24:38 +00:00
$codeBucket [ $pointer [ $targetKey ]] = array ();
// 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
$inFinger = count ( $fingerPrint );
$getFinger = $inFinger - 1 ;
$hasharray = array_slice ( $fingerPrint , - $inFinger , $getFinger , true );
$hasleng = count ( $hasharray );
$hashtarget = $hasleng . '__' . md5 ( implode ( '' , $hasharray ));
// all new records we can do a buldk insert
if ( $i === 1 || ! $id )
{
// start the bucket for this code
$this -> newCustomCode [ $pointer [ $targetKey ]] = array ();
2017-02-13 23:24:38 +00:00
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( $path ); // 'path'
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote (( int ) $_type ); // 'type'
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( 1 ); // 'target'
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( $commentType ); // 'comment_type'
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote (( int ) $this -> componentID ); // 'component'
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( 1 ); // 'published'
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( $today ); // 'created'
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote (( int ) $this -> user -> id ); // 'created_by'
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( 1 ); // 'version'
$this -> newCustomCode [ $pointer [ $targetKey ]][] = $this -> db -> quote ( 1 ); // 'access'
$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
$this -> existingCustomCode [ $pointer [ $targetKey ]] = array ();
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'id' ] = ( int ) $id ;
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'conditions' ] = array ();
2017-02-13 23:24:38 +00:00
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'conditions' ][] = $this -> db -> quoteName ( 'id' ) . ' = ' . $this -> db -> quote ( $id );
2017-02-01 13:17:04 +00:00
$this -> existingCustomCode [ $pointer [ $targetKey ]][ 'fields' ] = array ();
2017-02-13 23:24:38 +00:00
$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
$reading [ $targetKey ] = false ;
$reader = 0 ;
}
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
$counter [ $i ] ++ ;
}
}
}
// make sure only a few lines is kept at a time
if ( count ( $fingerPrint ) > 10 )
{
$fingerPrint = array_slice ( $fingerPrint , - 6 , 6 , true );
}
}
// if the code is at the end of the page and there were not three more lines
if ( count ( $endFingerPrint ) > 0 || $loadEndFingerPrint )
{
if ( count ( $endFingerPrint ) > 0 )
{
$leng = count ( $endFingerPrint );
$hashendtarget = $leng . '__' . md5 ( implode ( '' , $endFingerPrint ));
}
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-02-13 23:24:38 +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-02-13 23:24:38 +00:00
/**
* Check if this line should be added
*
* @ param strin $replaceKey The key to remove from line
* @ param int $type The line type
* @ param string $lineContent The line to check
*
* @ return bool true on success
*
*/
protected function addLineChecker ( $replaceKey , $type , $lineContent )
{
$check = explode ( $replaceKey , $lineContent );
switch ( $type )
{
case 1 :
// beginning of code
$i = trim ( $check [ 1 ]);
if ( ComponentbuilderHelper :: checkString ( $i ))
{
return $check [ 1 ];
}
break ;
case 2 :
// end of code
$i = trim ( $check [ 0 ]);
if ( ComponentbuilderHelper :: checkString ( $i ))
{
return $check [ 0 ];
}
break ;
}
return false ;
}
/**
* search for the system id in the line given
*
* @ 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 )
{
switch ( $commentType )
{
case 1 :
$startReplace .= '/*' . $id . '*/' ;
break ;
case 2 :
$startReplace .= '<!--' . $id . '-->' ;
break ;
}
}
return $startReplace ;
}
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
*
* @ 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-02-13 23:24:38 +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-02-11 02:24:26 +00:00
/**
2017-02-13 23:24:38 +00:00
* Reverse Engineer the dynamic placeholders ( hmmmm )
2017-02-11 02:24:26 +00:00
*
2017-02-13 23:24:38 +00:00
* @ param string $string The string to revers
* @ param int $id The custom code id
* @ param array $placeholders The values to search for
2017-02-11 02:24:26 +00:00
*
* @ return string
*
*/
2017-02-13 23:24:38 +00:00
protected function reversePlaceholders ( $string , & $placeholders , $id = null )
2017-02-11 02:24:26 +00:00
{
2017-02-13 23:24:38 +00:00
// get local code if set
if ( $id > 0 && $code = base64_decode ( ComponentbuilderHelper :: getVar ( 'custom_code' , $id , 'id' , 'code' )))
2017-02-11 02:24:26 +00:00
{
2017-02-13 23:24:38 +00:00
$string = $this -> setReverseLangPlaceholders ( $string , $code );
}
return $this -> setPlaceholders ( $string , $placeholders , 2 );
}
/**
* Set the langs strings for the reveres prossess
*
* @ param string $updateString The string to update
* @ param string $string The string to use lang update
*
* @ return array
*
*/
protected function setReverseLangPlaceholders ( $updateString , $string )
{
if ( strpos ( $string , 'JText::_(' ) !== false || strpos ( $string , 'JText::sprintf(' ) !== false )
{
$langHolders = array ();
// set the lang for both since we don't know what area is being targeted
$_tmp = $this -> lang ;
$this -> lang = 'both' ;
// set language data
$langCheck [] = ComponentbuilderHelper :: getAllBetween ( $string , " JText::_(' " , " ' " );
$langCheck [] = ComponentbuilderHelper :: getAllBetween ( $string , 'JText::_("' , '"' );
$langCheck [] = ComponentbuilderHelper :: getAllBetween ( $string , " JText::sprintf(' " , " ' " );
$langCheck [] = ComponentbuilderHelper :: getAllBetween ( $string , 'JText::sprintf("' , '"' );
// merge arrays
$langArray = ComponentbuilderHelper :: mergeArrays ( $langCheck );
// continue only if strings were found
2017-02-11 02:24:26 +00:00
if ( ComponentbuilderHelper :: checkArray ( $langArray ))
{
foreach ( $langArray as $lang )
{
2017-02-13 23:24:38 +00:00
$_keyLang = ComponentbuilderHelper :: safeString ( $lang , 'U' );
// 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
}
2017-02-13 23:24:38 +00:00
// only load if string is not already set
$keyLang = $this -> langPrefix . '_' . $_keyLang ;
if ( ! isset ( $this -> langContent [ $this -> lang ][ $keyLang ]))
{
$this -> langContent [ $this -> lang ][ $keyLang ] = trim ( $lang );
}
// reverse the placeholders
$langHolders [ " JText::_(' " . $keyLang . " ') " ] = " JText::_(' " . $lang . " ') " ;
$langHolders [ 'JText::_("' . $keyLang . '")' ] = 'JText::_("' . $lang . '")' ;
$langHolders [ " JText::sprintf(' " . $keyLang . " ', " ] = " JText::sprintf(' " . $lang . " ', " ;
$langHolders [ 'JText::sprintf("' . $keyLang . '",' ] = 'JText::sprintf("' . $lang . '",' ;
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 ;
2017-02-11 02:24:26 +00:00
}
2017-02-13 23:24:38 +00:00
return $updateString ;
}
/**
* Update the data with the placeholders
*
* @ param string $data The actual data
* @ param array $placeholder The placeholders
* @ param int $action The action to use
*===================================================
* THE ACTION OPTIONS ARE
*===================================================
* 1 -> Just replace ( default )
* 2 -> Check if data string has placeholders
* 3 -> Remove placeholders not in data string
*===================================================
* @ param int $langSwitch The lang switch
*
* @ return string
*
*/
public function setPlaceholders ( & $data , & $placeholder , $action = 1 )
{
2017-02-11 02:24:26 +00:00
if ( 1 == $action ) // <-- just replace (default)
{
return str_replace ( array_keys ( $placeholder ), array_values ( $placeholder ), $data );
}
elseif ( 2 == $action ) // <-- check if data string has placeholders
{
$replace = false ;
foreach ( $placeholder as $key => $val )
{
if ( strpos ( $data , $key ) !== FALSE )
{
$replace = true ;
break ;
}
}
// only replace if the data has these placeholder values
if ( $replace === true )
{
return str_replace ( array_keys ( $placeholder ), array_values ( $placeholder ), $data );
}
}
elseif ( 3 == $action ) // <-- remove placeholders not in data string
{
$replace = $placeholder ;
foreach ( $replace as $key => $val )
{
if ( strpos ( $data , $key ) === FALSE )
{
unset ( $replace [ $key ]);
}
}
// only replace if the data has these placeholder values
if ( ComponentbuilderHelper :: checkArray ( $replace ))
{
return str_replace ( array_keys ( $replace ), array_values ( $replace ), $data );
}
}
return $data ;
}
2017-02-01 13:17:04 +00:00
/**
* return the placeholders for insered and replaced code
*
* @ 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-02-13 23:24:38 +00:00
'start' => '/***[REPLACED$$$$]***//*' . $id . '*/' ,
2017-02-02 12:17:31 +00:00
'end' => '/***[/REPLACED$$$$]***/' );
}
else
{
return array (
2017-02-11 02:24:26 +00:00
'start' => " \t \t \t " ,
'end' => " \t \t \t " );
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-02-13 23:24:38 +00:00
'start' => '/***[INSERTED$$$$]***//*' . $id . '*/' ,
2017-02-01 13:17:04 +00:00
'end' => '/***[/INSERTED$$$$]***/' );
2017-02-02 12:17:31 +00:00
}
else
{
return array (
2017-02-11 02:24:26 +00:00
'start' => " \t \t \t " ,
'end' => " \t \t \t " );
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 (
'start' => '<!--[REPLACED$$$$]--><!--' . $id . '-->' ,
'end' => '<!--[/REPLACED$$$$]-->' );
}
else
{
return array (
'start' => " \t \t \t " ,
'end' => " \t \t \t " );
}
break ;
case 22 :
//<!--[INSERTED$$$$]--><!--1-->
if ( $this -> addPlaceholders === true )
{
return array (
'start' => '<!--[INSERTED$$$$]--><!--' . $id . '-->' ,
'end' => '<!--[/INSERTED$$$$]-->' );
}
else
{
return array (
'start' => " \t \t \t " ,
'end' => " \t \t \t " );
}
break ;
2017-02-11 02:24:26 +00:00
case 3 :
return array (
'start' => " \t \t \t " ,
'end' => " \t \t \t " );
break ;
2017-02-01 13:17:04 +00:00
}
return false ;
}
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
$localPaths [ 'admin' ] = JPATH_ADMINISTRATOR . '/components/com_' . $this -> componentCodeName ;
// site path
$localPaths [ 'site' ] = JPATH_ROOT . '/components/com_' . $this -> componentCodeName ;
// TODO later to include the JS and CSS
$localPaths [ 'media' ] = JPATH_ROOT . '/media/com_' . $this -> componentCodeName ;
// 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 ;
}
2016-02-26 00:20:09 +00:00
}