2016-01-30 20:28:43 +00:00
< ? php
2018-05-18 06:28:27 +00:00
/**
* @ package Joomla . Component . Builder
*
* @ created 30 th April , 2015
2021-12-21 14:44:50 +00:00
* @ author Llewellyn van der Merwe < https :// dev . vdm . io >
* @ gitea Joomla Component Builder < https :// git . vdm . dev / joomla / Component - Builder >
2018-05-18 06:28:27 +00:00
* @ github Joomla Component Builder < https :// github . com / vdm - io / Joomla - Component - Builder >
2021-01-03 16:49:35 +00:00
* @ copyright Copyright ( C ) 2015 Vast Development Method . All rights reserved .
2018-05-18 06:28:27 +00:00
* @ license GNU General Public License version 2 or later ; see LICENSE . txt
*/
2016-01-30 20:28:43 +00:00
// No direct access to this file
defined ( '_JEXEC' ) or die ( 'Restricted access' );
2021-03-08 22:36:30 +00:00
use Joomla\CMS\Filesystem\File ;
use Joomla\CMS\Filesystem\Folder ;
2022-03-09 23:46:45 +00:00
use VDM\Joomla\Utilities\StringHelper ;
use VDM\Joomla\Utilities\ArrayHelper ;
use VDM\Joomla\Utilities\ObjectHelper ;
2022-04-04 15:35:08 +00:00
use VDM\Joomla\Utilities\FileHelper ;
2023-01-01 02:11:34 +00:00
use VDM\Joomla\Utilities\GetHelper ;
2022-03-09 23:46:45 +00:00
use VDM\Joomla\Utilities\MathHelper ;
2022-08-30 15:28:41 +00:00
use VDM\Joomla\Componentbuilder\Compiler\Factory as CFactory ;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Placefix ;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Indent ;
use VDM\Joomla\Componentbuilder\Compiler\Utilities\Line ;
2022-03-09 23:46:45 +00:00
2016-02-29 11:05:37 +00:00
// Use the component builder autoloader
2016-02-26 00:20:09 +00:00
ComponentbuilderHelper :: autoLoader ();
2016-01-30 20:28:43 +00:00
/**
* Compiler class
2023-01-22 00:38:21 +00:00
* @ deprecated 3.3
2016-01-30 20:28:43 +00:00
*/
2016-02-26 00:20:09 +00:00
class Compiler extends Infusion
2016-01-30 20:28:43 +00:00
{
2022-08-30 15:28:41 +00:00
2019-08-22 01:54:47 +00:00
/**
2016-02-26 00:20:09 +00:00
* The Temp path
2019-08-22 01:54:47 +00:00
*
2016-02-26 00:20:09 +00:00
* @ var string
*/
2020-04-03 18:45:48 +00:00
public $tempPath ;
2017-12-14 23:10:47 +00:00
2019-08-22 01:54:47 +00:00
/**
2017-02-13 23:24:38 +00:00
* The timer
2019-08-22 01:54:47 +00:00
*
2017-02-13 23:24:38 +00:00
* @ var string
*/
private $time_start ;
private $time_end ;
2017-12-14 23:10:47 +00:00
public $secondsCompiled ;
2019-08-12 21:30:31 +00:00
2019-08-22 01:54:47 +00:00
/**
2019-08-12 21:30:31 +00:00
* The file path array
2019-08-22 01:54:47 +00:00
*
2019-08-12 21:30:31 +00:00
* @ var string
*/
2020-03-28 13:34:14 +00:00
public $filepath
= array (
'component' => '' ,
'component-folder' => '' ,
'package' => '' ,
'plugins' => array (),
'plugins-folders' => array (),
'modules' => array ()
2019-08-12 21:30:31 +00:00
);
2016-01-30 20:28:43 +00:00
// fixed pathes
2017-12-14 23:10:47 +00:00
protected $dynamicIntegration = false ;
protected $backupPath = false ;
protected $repoPath = false ;
protected $addCustomCodeAt = array ();
2016-01-30 20:28:43 +00:00
/**
* Constructor
*/
2017-12-14 23:10:47 +00:00
public function __construct ( $config = array ())
2016-01-30 20:28:43 +00:00
{
2017-02-13 23:24:38 +00:00
// to check the compiler speed
$this -> time_start = microtime ( true );
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.Counter' ) -> start ();
2023-01-22 00:38:21 +00:00
// first we run the parent constructors
2022-08-30 15:28:41 +00:00
if ( parent :: __construct ())
2016-01-30 20:28:43 +00:00
{
// set temp directory
2020-03-28 13:34:14 +00:00
$comConfig = JFactory :: getConfig ();
2017-12-14 23:10:47 +00:00
$this -> tempPath = $comConfig -> get ( 'tmp_path' );
2016-01-30 20:28:43 +00:00
// set some folder paths in relation to distribution
2022-08-30 15:28:41 +00:00
if ( CFactory :: _ ( 'Config' ) -> backup )
2016-01-30 20:28:43 +00:00
{
2020-03-28 13:34:14 +00:00
$this -> backupPath = $this -> params -> get (
'backup_folder_path' , $this -> tempPath
);
2017-12-14 23:10:47 +00:00
$this -> dynamicIntegration = true ;
2016-01-30 20:28:43 +00:00
}
2019-08-08 15:35:58 +00:00
// set local repos switch
2022-08-30 15:28:41 +00:00
if ( CFactory :: _ ( 'Config' ) -> repository )
2016-01-30 20:28:43 +00:00
{
2017-12-14 23:10:47 +00:00
$this -> repoPath = $this -> params -> get ( 'git_folder_path' , null );
2016-01-30 20:28:43 +00:00
}
2017-02-01 13:17:04 +00:00
// remove site folder if not needed (TODO add check if custom script was moved to site folder then we must do a more complex cleanup here)
2022-12-11 15:06:13 +00:00
if ( CFactory :: _ ( 'Config' ) -> remove_site_folder && CFactory :: _ ( 'Config' ) -> remove_site_edit_folder )
2017-01-20 00:16:50 +00:00
{
// first remove the files and folders
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.Folder' ) -> remove ( CFactory :: _ ( 'Utilities.Paths' ) -> component_path . '/site' );
2017-01-20 00:16:50 +00:00
// clear form component xml
2023-01-29 20:12:42 +00:00
$xmlPath = CFactory :: _ ( 'Utilities.Paths' ) -> component_path . '/'
2023-10-18 07:26:30 +00:00
. CFactory :: _ ( 'Compiler.Builder.Content.One' ) -> get ( 'component' ) . '.xml' ;
2023-01-01 02:11:34 +00:00
$componentXML = FileHelper :: getContent ( $xmlPath );
$textToSite = GetHelper :: between (
2020-03-28 13:34:14 +00:00
$componentXML , '<files folder="site">' , '</files>'
);
2023-01-01 02:11:34 +00:00
$textToSiteLang = GetHelper :: between (
2020-03-28 13:34:14 +00:00
$componentXML , '<languages folder="site">' , '</languages>'
);
$componentXML = str_replace (
array ( '<files folder="site">' . $textToSite . " </files> " ,
'<languages folder="site">' . $textToSiteLang
2023-01-01 02:11:34 +00:00
. " </languages> " ), array ( '' , '' ), ( string ) $componentXML
2020-03-28 13:34:14 +00:00
);
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.File' ) -> write ( $xmlPath , $componentXML );
2017-01-20 00:16:50 +00:00
}
2023-01-15 08:42:19 +00:00
// for plugin event TODO change event api signatures
$component_context = CFactory :: _ ( 'Config' ) -> component_context ;
2019-09-04 11:52:31 +00:00
// Trigger Event: jcb_ce_onBeforeUpdateFiles
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onBeforeUpdateFiles' ,
2023-01-15 08:42:19 +00:00
array ( & $component_context , & $this )
2020-03-28 13:34:14 +00:00
);
2016-02-26 00:20:09 +00:00
// now update the files
2017-02-01 13:17:04 +00:00
if ( ! $this -> updateFiles ())
2016-01-30 20:28:43 +00:00
{
2017-02-01 13:17:04 +00:00
return false ;
}
2019-09-04 11:52:31 +00:00
// Trigger Event: jcb_ce_onBeforeGetCustomCode
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onBeforeGetCustomCode' ,
2023-01-15 08:42:19 +00:00
array ( & $component_context , & $this )
2020-03-28 13:34:14 +00:00
);
2017-02-01 13:17:04 +00:00
// now insert into the new files
2022-09-03 10:48:53 +00:00
if ( CFactory :: _ ( 'Customcode' ) -> get ())
2017-12-14 23:10:47 +00:00
{
2019-09-04 11:52:31 +00:00
// Trigger Event: jcb_ce_onBeforeAddCustomCode
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onBeforeAddCustomCode' ,
2023-01-15 08:42:19 +00:00
array ( & $component_context , & $this )
2020-03-28 13:34:14 +00:00
);
2019-09-04 11:52:31 +00:00
2017-02-13 23:24:38 +00:00
$this -> addCustomCode ();
2017-02-01 13:17:04 +00:00
}
2019-09-04 11:52:31 +00:00
// Trigger Event: jcb_ce_onBeforeSetLangFileData
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onBeforeSetLangFileData' ,
2023-01-15 08:42:19 +00:00
array ( & $component_context , & $this )
2020-03-28 13:34:14 +00:00
);
2017-02-13 23:24:38 +00:00
// set the lang data now
$this -> setLangFileData ();
2017-10-26 16:43:51 +00:00
// set the language notice if it was set
2022-03-09 23:46:45 +00:00
if ( ArrayHelper :: check ( $this -> langNot )
|| ArrayHelper :: check ( $this -> langSet ))
2017-10-26 16:43:51 +00:00
{
2022-03-09 23:46:45 +00:00
if ( ArrayHelper :: check ( $this -> langNot ))
2017-10-26 16:43:51 +00:00
{
2020-03-28 13:34:14 +00:00
$this -> app -> enqueueMessage (
JText :: _ ( '<hr /><h3>Language Warning</h3>' ), 'Warning'
);
2017-10-26 16:43:51 +00:00
foreach ( $this -> langNot as $tag => $percentage )
{
2020-03-28 13:34:14 +00:00
$this -> app -> enqueueMessage (
JText :: sprintf (
'The <b>%s</b> language has %s% translated, you will need to translate %s% of the language strings before it will be added.' ,
$tag , $percentage , $this -> percentageLanguageAdd
), 'Warning'
);
2017-10-26 16:43:51 +00:00
}
2020-03-28 13:34:14 +00:00
$this -> app -> enqueueMessage (
JText :: _ ( '<hr /><h3>Language Notice</h3>' ), 'Notice'
);
$this -> app -> enqueueMessage (
JText :: sprintf (
'<b>You can change this percentage of translated strings required in the global options of JCB.</b><br />Please watch this <a href=%s>tutorial for more help surrounding the JCB translations manager</a>.' ,
'"https://youtu.be/zzAcVkn_cWU?list=PLQRGFI8XZ_wtGvPQZWBfDzzlERLQgpMRE" target="_blank" title="JCB Tutorial surrounding Translation Manager"'
), 'Notice'
);
2017-10-26 16:43:51 +00:00
}
// set why the strings were added
2020-03-28 13:34:14 +00:00
$whyAddedLang = JText :: sprintf (
'because more then %s% of the strings have been translated.' ,
$this -> percentageLanguageAdd
);
2022-08-30 15:28:41 +00:00
if ( CFactory :: _ ( 'Config' ) -> get ( 'debug_line_nr' , false ))
2017-10-26 16:43:51 +00:00
{
2020-03-28 13:34:14 +00:00
$whyAddedLang = JText :: _ (
'because the debugging mode is on. (debug line numbers)'
);
2017-10-26 16:43:51 +00:00
}
// show languages that were added
2022-03-09 23:46:45 +00:00
if ( ArrayHelper :: check ( $this -> langSet ))
2017-10-26 16:43:51 +00:00
{
2020-03-28 13:34:14 +00:00
$this -> app -> enqueueMessage (
JText :: _ ( '<hr /><h3>Language Notice</h3>' ), 'Notice'
);
2017-10-26 16:43:51 +00:00
foreach ( $this -> langSet as $tag => $percentage )
{
2020-03-28 13:34:14 +00:00
$this -> app -> enqueueMessage (
JText :: sprintf (
2020-12-12 06:24:57 +00:00
'The <b>%s</b> language has %s% translated. Was added %s' ,
2020-03-28 13:34:14 +00:00
$tag , $percentage , $whyAddedLang
), 'Notice'
);
2017-10-26 16:43:51 +00:00
}
}
}
2020-12-12 06:24:57 +00:00
// set assets table column fix type messages
$message_fix [ 'intelligent' ] = JText :: _ (
'The <b>intelligent</b> fix only updates the #__assets table\'s column when it detects that it is too small for the worse case. The intelligent fix also only reverse the #__assets table\'s update on uninstall of the component if it detects that no other component needs the rules column to be larger any longer. This options also shows a notice to the end user of all that it does to the #__assets table on installation and uninstalling of the component.'
);
$message_fix [ 'sql' ] = JText :: _ (
'The <b>SQL</b> fix updates the #__assets table\'s column size on installation of the component and reverses it back to the Joomla default on uninstall of the component.'
);
2023-01-15 08:42:19 +00:00
// get the asset table fix switch
$add_assets_table_fix = CFactory :: _ ( 'Config' ) -> get ( 'add_assets_table_fix' , 0 );
2020-12-12 06:24:57 +00:00
// set assets table rules column notice
2023-01-15 08:42:19 +00:00
if ( $add_assets_table_fix )
2020-12-12 06:24:57 +00:00
{
$this -> app -> enqueueMessage (
JText :: _ ( '<hr /><h3>Assets Table Notice</h3>' ), 'Notice'
);
2023-01-15 08:42:19 +00:00
$asset_table_fix_type = ( $add_assets_table_fix == 2 )
2020-12-12 06:24:57 +00:00
? 'intelligent' : 'sql' ;
$this -> app -> enqueueMessage (
JText :: sprintf (
'The #__assets table <b>%s</b> fix has been added to this component. %s' ,
$asset_table_fix_type ,
$message_fix [ $asset_table_fix_type ]
), 'Notice'
);
}
// set assets table rules column Warning
2023-10-18 07:26:30 +00:00
elseif ( CFactory :: _ ( 'Utilities.Counter' ) -> accessSize >= 30 )
2020-12-12 06:24:57 +00:00
{
$this -> app -> enqueueMessage (
JText :: _ ( '<hr /><h3>Assets Table Warning</h3>' ), 'Warning'
);
$this -> app -> enqueueMessage (
JText :: sprintf (
'The Joomla #__assets table\'s rules column has to be fixed for this component to work coherently. JCB has detected that in worse case the rules column in the #__assets table may require <b>%s</b> characters, and yet the Joomla default is only <b>varchar(5120)</b>. JCB has three option to resolve this issue, first <b>use less permissions</b> in your component, second use the <b>SQL</b> fix, or the <b>intelligent</b> fix. %s %s' ,
2023-01-15 08:42:19 +00:00
CFactory :: _ ( 'Config' ) -> access_worse_case , $message_fix [ 'intelligent' ],
2020-12-12 06:24:57 +00:00
$message_fix [ 'sql' ]
), 'Warning'
);
}
// set assets table name column warning if not set
2023-01-15 08:42:19 +00:00
if ( ! $add_assets_table_fix && CFactory :: _ ( 'Config' ) -> add_assets_table_name_fix )
2020-12-12 06:24:57 +00:00
{
// only add if not already added
2023-10-18 07:26:30 +00:00
if ( CFactory :: _ ( 'Utilities.Counter' ) -> accessSize < 30 )
2020-12-12 06:24:57 +00:00
{
$this -> app -> enqueueMessage (
JText :: _ ( '<hr /><h3>Assets Table Warning</h3>' ),
'Warning'
);
}
$this -> app -> enqueueMessage (
JText :: sprintf (
'The Joomla #__assets table\'s name column has to be fixed for this component to work correctly. JCB has detected that the #__assets table name column will need to be enlarged because this component\'s own naming convention is larger than varchar(50) which is the Joomla default. JCB has three option to resolve this issue, first <b>shorter names</b> for your component and/or its admin views, second use the <b>SQL</b> fix, or the <b>intelligent</b> fix. %s %s' ,
$message_fix [ 'intelligent' ],
$message_fix [ 'sql' ]
), 'Warning'
);
}
2017-02-01 13:17:04 +00:00
// move the update server into place
$this -> setUpdateServer ();
2017-02-13 23:24:38 +00:00
// build read me
$this -> buildReadMe ();
2019-08-08 15:35:58 +00:00
// set local repos
$this -> setLocalRepos ();
2017-02-01 13:17:04 +00:00
// zip the component
if ( ! $this -> zipComponent ())
{
2017-02-13 23:24:38 +00:00
// done with error
2017-02-01 13:17:04 +00:00
return false ;
2016-01-30 20:28:43 +00:00
}
2019-12-06 05:31:32 +00:00
// if there are modules zip them
$this -> zipModules ();
2019-08-08 15:35:58 +00:00
// if there are plugins zip them
$this -> zipPlugins ();
2017-12-14 13:30:21 +00:00
// do lang mismatch check
2022-08-30 15:28:41 +00:00
if ( ArrayHelper :: check ( CFactory :: _ ( 'Language.Extractor' ) -> langMismatch ))
2017-12-14 13:30:21 +00:00
{
2022-08-30 15:28:41 +00:00
if ( ArrayHelper :: check ( CFactory :: _ ( 'Language.Extractor' ) -> langMatch ))
2017-12-14 13:30:21 +00:00
{
2020-03-28 13:34:14 +00:00
$mismatch = array_diff (
2022-08-30 15:28:41 +00:00
array_unique ( CFactory :: _ ( 'Language.Extractor' ) -> langMismatch ),
array_unique ( CFactory :: _ ( 'Language.Extractor' ) -> langMatch )
2020-03-28 13:34:14 +00:00
);
2017-12-14 13:30:21 +00:00
}
else
{
2022-08-30 15:28:41 +00:00
$mismatch = array_unique ( CFactory :: _ ( 'Language.Extractor' ) -> langMismatch );
2017-12-14 13:30:21 +00:00
}
// set a notice if we have a mismatch
2020-03-28 13:34:14 +00:00
if ( isset ( $mismatch )
2022-03-09 23:46:45 +00:00
&& ArrayHelper :: check (
2020-03-28 13:34:14 +00:00
$mismatch
))
2017-12-14 13:30:21 +00:00
{
2020-03-28 13:34:14 +00:00
$this -> app -> enqueueMessage (
JText :: _ ( '<hr /><h3>Language Warning</h3>' ), 'Warning'
);
2019-09-05 21:12:56 +00:00
if ( count (( array ) $mismatch ) > 1 )
2017-12-14 13:30:21 +00:00
{
2020-03-28 13:34:14 +00:00
$this -> app -> enqueueMessage (
JText :: _ (
'<h3>Please check the following mismatching Joomla.JText language constants.</h3>'
), 'Warning'
);
2017-12-14 13:30:21 +00:00
}
else
{
2020-03-28 13:34:14 +00:00
$this -> app -> enqueueMessage (
JText :: _ (
'<h3>Please check the following mismatch Joomla.JText language constant.</h3>'
), 'Warning'
);
2017-12-14 13:30:21 +00:00
}
// add the mismatching issues
foreach ( $mismatch as $string )
{
2022-08-30 15:28:41 +00:00
$constant = CFactory :: _ ( 'Config' ) -> lang_prefix . '_'
2022-03-09 23:46:45 +00:00
. StringHelper :: safe ( $string , 'U' );
2020-03-28 13:34:14 +00:00
$this -> app -> enqueueMessage (
JText :: sprintf (
'The <b>Joomla.JText._('%s')</b> language constant for <b>%s</b> does not have a corresponding <code>JText::script('%s')</code> decalaration, please add it.' ,
$constant , $string , $string
), 'Warning'
);
2017-12-14 13:30:21 +00:00
}
}
}
2018-02-06 10:55:46 +00:00
// check if we should add a EXTERNALCODE notice
2022-03-09 23:46:45 +00:00
if ( ArrayHelper :: check ( $this -> externalCodeString ))
2018-02-06 10:55:46 +00:00
{
// number of external code strings
$externalCount = count ( $this -> externalCodeString );
// the correct string
2020-03-28 13:34:14 +00:00
$externalCodeString = ( $externalCount == 1 ) ? JText :: _ (
'code/string'
) : JText :: _ ( 'code/strings' );
2018-02-06 10:55:46 +00:00
// the notice
2020-03-28 13:34:14 +00:00
$this -> app -> enqueueMessage (
JText :: _ ( '<hr /><h3>External Code Notice</h3>' ), 'Notice'
);
$this -> app -> enqueueMessage (
JText :: sprintf (
'There has been <b>%s - %s</b> added to this component as EXTERNALCODE. To avoid shipping your component with malicious %s always make sure that the correct <b>code/string values</b> were used.' ,
$externalCount , $externalCodeString , $externalCodeString
), 'Notice'
);
2018-02-06 10:55:46 +00:00
}
2017-02-13 23:24:38 +00:00
// end the timer here
2020-03-28 13:34:14 +00:00
$this -> time_end = microtime ( true );
2017-02-13 23:24:38 +00:00
$this -> secondsCompiled = $this -> time_end - $this -> time_start ;
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.Counter' ) -> end ();
2020-03-28 13:34:14 +00:00
2017-02-13 23:24:38 +00:00
// completed the compilation
2017-02-01 13:17:04 +00:00
return true ;
2016-01-30 20:28:43 +00:00
}
2020-03-28 13:34:14 +00:00
2016-01-30 20:28:43 +00:00
return false ;
}
2017-12-14 23:10:47 +00:00
2017-02-01 13:17:04 +00:00
/**
* Set the dynamic data to the created fils
2018-05-22 20:35:39 +00:00
*
2017-02-01 13:17:04 +00:00
* @ return bool true on success
2018-05-22 20:35:39 +00:00
*
2017-02-01 13:17:04 +00:00
*/
2016-02-26 00:20:09 +00:00
protected function updateFiles ()
2016-01-30 20:28:43 +00:00
{
2023-01-29 20:12:42 +00:00
if ( CFactory :: _ ( 'Utilities.Files' ) -> exists ( 'static' )
&& CFactory :: _ ( 'Utilities.Files' ) -> exists ( 'dynamic' ))
2017-04-05 13:21:10 +00:00
{
2016-02-26 00:20:09 +00:00
// get the bom file
2023-01-15 08:42:19 +00:00
$bom = FileHelper :: getContent ( CFactory :: _ ( 'Config' ) -> bom_path );
2016-02-26 00:20:09 +00:00
// first we do the static files
2023-01-29 20:12:42 +00:00
foreach ( CFactory :: _ ( 'Utilities.Files' ) -> get ( 'static' ) as $static )
2016-01-30 20:28:43 +00:00
{
2021-03-08 22:36:30 +00:00
if ( File :: exists ( $static [ 'path' ]))
2016-01-30 20:28:43 +00:00
{
2020-03-28 13:34:14 +00:00
$this -> setFileContent (
$static [ 'name' ], $static [ 'path' ], $bom
);
2016-01-30 20:28:43 +00:00
}
2016-02-26 00:20:09 +00:00
}
// now we do the dynamic files
2023-01-29 20:12:42 +00:00
foreach ( CFactory :: _ ( 'Utilities.Files' ) -> get ( 'dynamic' ) as $view => $files )
2016-02-26 00:20:09 +00:00
{
2023-10-18 07:26:30 +00:00
if ( CFactory :: _ ( 'Compiler.Builder.Content.Multi' ) -> isArray ( $view ))
2016-01-30 20:28:43 +00:00
{
2016-02-26 00:20:09 +00:00
foreach ( $files as $file )
2016-01-30 20:28:43 +00:00
{
2016-02-26 00:20:09 +00:00
if ( $file [ 'view' ] == $view )
2016-01-30 20:28:43 +00:00
{
2021-03-08 22:36:30 +00:00
if ( File :: exists ( $file [ 'path' ]))
2016-01-30 20:28:43 +00:00
{
2020-03-28 13:34:14 +00:00
$this -> setFileContent (
$file [ 'name' ], $file [ 'path' ], $bom ,
$file [ 'view' ]
);
2016-01-30 20:28:43 +00:00
}
}
}
}
2017-02-01 13:17:04 +00:00
// free up some memory
2023-10-18 07:26:30 +00:00
CFactory :: _ ( 'Compiler.Builder.Content.Multi' ) -> remove ( $view );
2016-01-30 20:28:43 +00:00
}
2017-02-01 13:17:04 +00:00
// free up some memory
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.Files' ) -> remove ( 'dynamic' );
2019-12-06 05:31:32 +00:00
// do modules if found
2023-01-22 00:38:21 +00:00
if ( CFactory :: _ ( 'Joomlamodule.Data' ) -> exists ())
2019-12-06 05:31:32 +00:00
{
2023-01-22 00:38:21 +00:00
foreach ( CFactory :: _ ( 'Joomlamodule.Data' ) -> get () as $module )
2019-12-06 05:31:32 +00:00
{
2022-03-09 23:46:45 +00:00
if ( ObjectHelper :: check ( $module )
2023-01-29 20:12:42 +00:00
&& CFactory :: _ ( 'Utilities.Files' ) -> exists ( $module -> key ))
2019-12-06 05:31:32 +00:00
{
// move field or rule if needed
2020-03-28 13:34:14 +00:00
if ( isset ( $module -> fields_rules_paths )
&& $module -> fields_rules_paths == 2 )
2019-12-06 05:31:32 +00:00
{
// check the config fields
2020-03-28 13:34:14 +00:00
if ( isset ( $module -> config_fields )
2022-03-09 23:46:45 +00:00
&& ArrayHelper :: check (
2020-03-28 13:34:14 +00:00
$module -> config_fields
))
2019-12-06 05:31:32 +00:00
{
2020-03-28 13:34:14 +00:00
foreach (
$module -> config_fields as $field_name =>
$fieldsets
)
2019-12-06 05:31:32 +00:00
{
foreach ( $fieldsets as $fieldset => $fields )
{
foreach ( $fields as $field )
{
2020-03-28 13:34:14 +00:00
$this -> moveFieldsRules (
$field , $module -> folder_path
);
2019-12-06 05:31:32 +00:00
}
}
}
}
// check the fieldsets
2020-03-28 13:34:14 +00:00
if ( isset ( $module -> form_files )
2022-03-09 23:46:45 +00:00
&& ArrayHelper :: check (
2020-03-28 13:34:14 +00:00
$module -> form_files
))
2019-12-06 05:31:32 +00:00
{
2020-03-28 13:34:14 +00:00
foreach ( $module -> form_files as $file => $files )
2019-12-06 05:31:32 +00:00
{
2020-03-28 13:34:14 +00:00
foreach (
$files as $field_name => $fieldsets
)
2019-12-06 05:31:32 +00:00
{
2020-03-28 13:34:14 +00:00
foreach (
$fieldsets as $fieldset => $fields
)
2019-12-06 05:31:32 +00:00
{
foreach ( $fields as $field )
{
2020-03-28 13:34:14 +00:00
$this -> moveFieldsRules (
$field , $module -> folder_path
);
2019-12-06 05:31:32 +00:00
}
}
}
}
}
}
// update the module files
2023-01-29 20:12:42 +00:00
foreach ( CFactory :: _ ( 'Utilities.Files' ) -> get ( $module -> key ) as $module_file )
2019-12-06 05:31:32 +00:00
{
2021-03-08 22:36:30 +00:00
if ( File :: exists ( $module_file [ 'path' ]))
2019-12-06 05:31:32 +00:00
{
2020-03-28 13:34:14 +00:00
$this -> setFileContent (
$module_file [ 'name' ], $module_file [ 'path' ],
$bom , $module -> key
);
2019-12-06 05:31:32 +00:00
}
}
// free up some memory
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.Files' ) -> remove ( $module -> key );
2023-10-18 07:26:30 +00:00
CFactory :: _ ( 'Compiler.Builder.Content.Multi' ) -> remove ( $module -> key );
2019-12-06 05:31:32 +00:00
}
}
}
2019-08-04 22:38:53 +00:00
// do plugins if found
2023-01-22 00:38:21 +00:00
if ( CFactory :: _ ( 'Joomlaplugin.Data' ) -> exists ())
2019-08-04 22:38:53 +00:00
{
2023-01-22 00:38:21 +00:00
foreach ( CFactory :: _ ( 'Joomlaplugin.Data' ) -> get () as $plugin )
2019-08-04 22:38:53 +00:00
{
2022-03-09 23:46:45 +00:00
if ( ObjectHelper :: check ( $plugin )
2023-01-29 20:12:42 +00:00
&& CFactory :: _ ( 'Utilities.Files' ) -> exists ( $plugin -> key ))
2019-08-04 22:38:53 +00:00
{
2019-08-22 01:54:47 +00:00
// move field or rule if needed
2020-03-28 13:34:14 +00:00
if ( isset ( $plugin -> fields_rules_paths )
&& $plugin -> fields_rules_paths == 2 )
2019-08-22 01:54:47 +00:00
{
// check the config fields
2020-03-28 13:34:14 +00:00
if ( isset ( $plugin -> config_fields )
2022-03-09 23:46:45 +00:00
&& ArrayHelper :: check (
2020-03-28 13:34:14 +00:00
$plugin -> config_fields
))
2019-08-22 01:54:47 +00:00
{
2020-03-28 13:34:14 +00:00
foreach (
$plugin -> config_fields as $field_name =>
$fieldsets
)
2019-08-22 01:54:47 +00:00
{
foreach ( $fieldsets as $fieldset => $fields )
{
foreach ( $fields as $field )
{
2020-03-28 13:34:14 +00:00
$this -> moveFieldsRules (
$field , $plugin -> folder_path
);
2019-08-22 01:54:47 +00:00
}
}
}
}
// check the fieldsets
2020-03-28 13:34:14 +00:00
if ( isset ( $plugin -> form_files )
2022-03-09 23:46:45 +00:00
&& ArrayHelper :: check (
2020-03-28 13:34:14 +00:00
$plugin -> form_files
))
2019-08-22 01:54:47 +00:00
{
2020-03-28 13:34:14 +00:00
foreach ( $plugin -> form_files as $file => $files )
2019-08-22 01:54:47 +00:00
{
2020-03-28 13:34:14 +00:00
foreach (
$files as $field_name => $fieldsets
)
2019-08-22 01:54:47 +00:00
{
2020-03-28 13:34:14 +00:00
foreach (
$fieldsets as $fieldset => $fields
)
2019-08-22 01:54:47 +00:00
{
foreach ( $fields as $field )
{
2020-03-28 13:34:14 +00:00
$this -> moveFieldsRules (
$field , $plugin -> folder_path
);
2019-08-22 01:54:47 +00:00
}
}
}
}
}
}
2019-12-06 05:31:32 +00:00
// update the plugin files
2023-01-29 20:12:42 +00:00
foreach ( CFactory :: _ ( 'Utilities.Files' ) -> get ( $plugin -> key ) as $plugin_file )
2019-08-04 22:38:53 +00:00
{
2021-03-08 22:36:30 +00:00
if ( File :: exists ( $plugin_file [ 'path' ]))
2019-08-04 22:38:53 +00:00
{
2020-03-28 13:34:14 +00:00
$this -> setFileContent (
$plugin_file [ 'name' ], $plugin_file [ 'path' ],
$bom , $plugin -> key
);
2019-08-04 22:38:53 +00:00
}
}
// free up some memory
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.Files' ) -> remove ( $plugin -> key );
2023-10-18 07:26:30 +00:00
CFactory :: _ ( 'Compiler.Builder.Content.Multi' ) -> remove ( $plugin -> key );
2019-08-04 22:38:53 +00:00
}
}
}
2021-12-21 14:44:50 +00:00
// do powers if found
2022-08-30 15:28:41 +00:00
if ( ArrayHelper :: check ( CFactory :: _ ( 'Power' ) -> active ))
2021-12-21 14:44:50 +00:00
{
2022-08-30 15:28:41 +00:00
foreach ( CFactory :: _ ( 'Power' ) -> active as $power )
2021-12-21 14:44:50 +00:00
{
2022-03-09 23:46:45 +00:00
if ( ObjectHelper :: check ( $power )
2023-01-29 20:12:42 +00:00
&& CFactory :: _ ( 'Utilities.Files' ) -> exists ( $power -> key ))
2021-12-21 14:44:50 +00:00
{
// update the power files
2023-01-29 20:12:42 +00:00
foreach ( CFactory :: _ ( 'Utilities.Files' ) -> get ( $power -> key ) as $power_file )
2021-12-21 14:44:50 +00:00
{
if ( File :: exists ( $power_file [ 'path' ]))
{
$this -> setFileContent (
$power_file [ 'name' ], $power_file [ 'path' ],
$bom , $power -> key
);
}
}
// free up some memory
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.Files' ) -> remove ( $power -> key );
2023-10-18 07:26:30 +00:00
CFactory :: _ ( 'Compiler.Builder.Content.Multi' ) -> remove ( $power -> key );
2021-12-21 14:44:50 +00:00
}
}
}
2023-05-02 00:10:55 +00:00
// do super powers details if found
if ( ArrayHelper :: check ( CFactory :: _ ( 'Power' ) -> superpowers ))
{
foreach ( CFactory :: _ ( 'Power' ) -> superpowers as $path => $powers )
{
$key = StringHelper :: safe ( $path );
if ( CFactory :: _ ( 'Utilities.Files' ) -> exists ( $key ))
{
// update the power files
foreach ( CFactory :: _ ( 'Utilities.Files' ) -> get ( $key ) as $power_file )
{
if ( File :: exists ( $power_file [ 'path' ]))
{
$this -> setFileContent (
$power_file [ 'name' ], $power_file [ 'path' ],
$bom , $key
);
}
}
// free up some memory
CFactory :: _ ( 'Utilities.Files' ) -> remove ( $key );
2023-10-18 07:26:30 +00:00
CFactory :: _ ( 'Compiler.Builder.Content.Multi' ) -> remove ( $key );
2023-05-02 00:10:55 +00:00
}
}
}
2020-03-28 13:34:14 +00:00
2017-02-01 13:17:04 +00:00
return true ;
}
2020-03-28 13:34:14 +00:00
2017-02-01 13:17:04 +00:00
return false ;
}
2017-12-14 23:10:47 +00:00
2018-05-22 20:35:39 +00:00
/**
* set the file content
*
* @ return void
*
*/
protected function setFileContent ( & $name , & $path , & $bom , $view = null )
{
2023-01-15 08:42:19 +00:00
// for plugin event TODO change event api signatures
$component_context = CFactory :: _ ( 'Config' ) -> component_context ;
2023-02-12 19:15:41 +00:00
2019-06-22 10:43:26 +00:00
// Trigger Event: jcb_ce_onBeforeSetFileContent
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onBeforeSetFileContent' ,
2023-01-15 08:42:19 +00:00
array ( & $component_context , & $name , & $path , & $bom , & $view )
2020-03-28 13:34:14 +00:00
);
2023-02-12 19:15:41 +00:00
2018-05-22 20:35:39 +00:00
// set the file name
2023-10-18 07:26:30 +00:00
CFactory :: _ ( 'Compiler.Builder.Content.One' ) -> set ( 'FILENAME' , $name );
2023-02-12 19:15:41 +00:00
2018-05-22 20:35:39 +00:00
// check if the file should get PHP opening
$php = '' ;
if ( ComponentbuilderHelper :: checkFileType ( $name , 'php' ))
{
$php = " <?php \n " ;
}
2023-02-12 19:15:41 +00:00
2018-05-22 20:35:39 +00:00
// get content of the file
2023-01-01 02:11:34 +00:00
$string = FileHelper :: getContent ( $path );
2023-02-12 19:15:41 +00:00
2019-06-22 10:43:26 +00:00
// Trigger Event: jcb_ce_onGetFileContents
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onGetFileContents' ,
2023-01-15 08:42:19 +00:00
array ( & $component_context , & $string , & $name , & $path , & $bom ,
2020-03-28 13:34:14 +00:00
& $view )
);
2023-02-12 19:15:41 +00:00
2018-05-22 20:35:39 +00:00
// see if we should add a BOM
2023-01-01 02:11:34 +00:00
if ( strpos (( string ) $string , ( string ) Placefix :: _h ( 'BOM' )) !== false )
2018-05-22 20:35:39 +00:00
{
2020-03-28 13:34:14 +00:00
list ( $wast , $code ) = explode (
2023-01-01 02:11:34 +00:00
Placefix :: _h ( 'BOM' ), ( string ) $string
2020-03-28 13:34:14 +00:00
);
2018-05-22 20:35:39 +00:00
$string = $php . $bom . $code ;
}
2023-02-12 19:15:41 +00:00
2018-05-22 20:35:39 +00:00
// set the answer
2023-10-18 07:26:30 +00:00
$answer = CFactory :: _ ( 'Placeholder' ) -> update ( $string , CFactory :: _ ( 'Compiler.Builder.Content.One' ) -> allActive (), 3 );
2023-02-12 19:15:41 +00:00
2018-05-22 20:35:39 +00:00
// set the dynamic answer
if ( $view )
{
2023-10-18 07:26:30 +00:00
$placeholders = CFactory :: _ ( 'Compiler.Builder.Content.Multi' ) -> get ( $view , []);
if ( is_array ( $placeholders ))
{
$answer = CFactory :: _ ( 'Placeholder' ) -> update (
$answer , $placeholders , 3
);
}
else
{
echo '<pre>' ;
var_dump ( $view , $placeholders );
exit ;
}
unset ( $placeholders );
2018-05-22 20:35:39 +00:00
}
2023-02-12 19:15:41 +00:00
2018-09-25 20:02:48 +00:00
// check if this file needs extra care :)
2023-02-12 19:15:41 +00:00
if ( CFactory :: _ ( 'Registry' ) -> exists ( 'update.file.content.' . $path ))
2018-09-25 20:02:48 +00:00
{
2022-09-03 10:48:53 +00:00
$answer = CFactory :: _ ( 'Customcode' ) -> update ( $answer );
2018-09-25 20:02:48 +00:00
}
2023-02-12 19:15:41 +00:00
2019-06-22 10:43:26 +00:00
// Trigger Event: jcb_ce_onBeforeSetFileContent
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onBeforeWriteFileContent' ,
2023-01-15 08:42:19 +00:00
array ( & $component_context , & $answer , & $name , & $path , & $bom ,
2020-03-28 13:34:14 +00:00
& $view )
);
2023-02-12 19:15:41 +00:00
2023-05-02 00:10:55 +00:00
// inject any super powers found
$answer = CFactory :: _ ( 'Power.Injector' ) -> power ( $answer );
2018-05-22 20:35:39 +00:00
// add answer back to file
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.File' ) -> write ( $path , $answer );
2023-02-12 19:15:41 +00:00
2018-05-22 20:35:39 +00:00
// count the file lines
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.Counter' ) -> line += substr_count (( string ) $answer , PHP_EOL );
2018-05-22 20:35:39 +00:00
}
2017-02-01 13:17:04 +00:00
/**
* move the local update server xml file to a remote ftp server
2018-05-22 20:35:39 +00:00
*
2017-02-01 13:17:04 +00:00
* @ return void
2018-05-22 20:35:39 +00:00
*
2017-02-01 13:17:04 +00:00
*/
protected function setUpdateServer ()
{
2019-08-08 15:35:58 +00:00
// move the component update server to host
2023-01-22 00:38:21 +00:00
if ( CFactory :: _ ( 'Component' ) -> get ( 'add_update_server' , 0 ) == 1
2020-03-28 13:34:14 +00:00
&& isset ( $this -> updateServerFileName )
&& $this -> dynamicIntegration )
2017-02-01 13:17:04 +00:00
{
2023-01-29 20:12:42 +00:00
$update_server_xml_path = CFactory :: _ ( 'Utilities.Paths' ) -> component_path . '/'
2020-03-28 13:34:14 +00:00
. $this -> updateServerFileName . '.xml' ;
2017-02-01 13:17:04 +00:00
// make sure we have the correct file
2021-03-08 22:36:30 +00:00
if ( File :: exists ( $update_server_xml_path )
2023-01-22 00:38:21 +00:00
&& ( $update_server = CFactory :: _ ( 'Component' ) -> get ( 'update_server' )) !== null )
2017-02-01 13:17:04 +00:00
{
2018-02-20 20:46:29 +00:00
// move to server
2023-02-27 12:27:41 +00:00
if ( ! CFactory :: _ ( 'Server' ) -> legacyMove (
2020-03-28 13:34:14 +00:00
$update_server_xml_path ,
$this -> updateServerFileName . '.xml' ,
2023-01-22 00:38:21 +00:00
( int ) $update_server ,
CFactory :: _ ( 'Component' ) -> get ( 'update_server_protocol' )
2023-02-27 12:27:41 +00:00
))
{
$this -> app -> enqueueMessage (
JText :: sprintf (
'Upload of component (%s) update server XML failed.' ,
CFactory :: _ ( 'Component' ) -> get ( 'system_name' )
), 'Error'
);
}
2018-02-20 20:46:29 +00:00
// remove the local file
2021-03-08 22:36:30 +00:00
File :: delete ( $update_server_xml_path );
2019-08-08 15:35:58 +00:00
}
}
2021-10-18 20:12:19 +00:00
// move the modules update server to host
2023-01-22 00:38:21 +00:00
if ( CFactory :: _ ( 'Joomlamodule.Data' ) -> exists ())
2021-10-18 20:12:19 +00:00
{
2023-01-22 00:38:21 +00:00
foreach ( CFactory :: _ ( 'Joomlamodule.Data' ) -> get () as $module )
2021-10-18 20:12:19 +00:00
{
2022-03-09 23:46:45 +00:00
if ( ObjectHelper :: check ( $module )
2021-10-18 20:12:19 +00:00
&& isset ( $module -> add_update_server )
&& $module -> add_update_server == 1
&& isset ( $module -> update_server_target )
&& $module -> update_server_target == 1
&& isset ( $module -> update_server )
&& is_numeric ( $module -> update_server )
&& $module -> update_server > 0
&& isset ( $module -> update_server_xml_path )
&& File :: exists ( $module -> update_server_xml_path )
&& isset ( $module -> update_server_xml_file_name )
2022-03-09 23:46:45 +00:00
&& StringHelper :: check (
2021-10-18 20:12:19 +00:00
$module -> update_server_xml_file_name
))
{
// move to server
2023-02-27 12:27:41 +00:00
if ( ! CFactory :: _ ( 'Server' ) -> legacyMove (
2021-10-18 20:12:19 +00:00
$module -> update_server_xml_path ,
$module -> update_server_xml_file_name ,
( int ) $module -> update_server ,
$module -> update_server_protocol
2023-02-27 12:27:41 +00:00
))
{
$this -> app -> enqueueMessage (
JText :: sprintf (
'Upload of module (%s) update server XML failed.' ,
$module -> name
), 'Error'
);
}
2021-10-18 20:12:19 +00:00
// remove the local file
File :: delete ( $module -> update_server_xml_path );
}
// var_dump($module->update_server_xml_path);exit;
}
}
2019-08-08 15:35:58 +00:00
// move the plugins update server to host
2023-01-22 00:38:21 +00:00
if ( CFactory :: _ ( 'Joomlaplugin.Data' ) -> exists ())
2019-08-08 15:35:58 +00:00
{
2023-01-22 00:38:21 +00:00
foreach ( CFactory :: _ ( 'Joomlaplugin.Data' ) -> get () as $plugin )
2019-08-08 15:35:58 +00:00
{
2022-03-09 23:46:45 +00:00
if ( ObjectHelper :: check ( $plugin )
2020-03-28 13:34:14 +00:00
&& isset ( $plugin -> add_update_server )
&& $plugin -> add_update_server == 1
&& isset ( $plugin -> update_server_target )
&& $plugin -> update_server_target == 1
&& isset ( $plugin -> update_server )
&& is_numeric ( $plugin -> update_server )
&& $plugin -> update_server > 0
&& isset ( $plugin -> update_server_xml_path )
2021-03-08 22:36:30 +00:00
&& File :: exists ( $plugin -> update_server_xml_path )
2020-03-28 13:34:14 +00:00
&& isset ( $plugin -> update_server_xml_file_name )
2022-03-09 23:46:45 +00:00
&& StringHelper :: check (
2020-03-28 13:34:14 +00:00
$plugin -> update_server_xml_file_name
))
2019-08-08 15:35:58 +00:00
{
// move to server
2023-02-27 12:27:41 +00:00
if ( ! CFactory :: _ ( 'Server' ) -> legacyMove (
2020-03-28 13:34:14 +00:00
$plugin -> update_server_xml_path ,
$plugin -> update_server_xml_file_name ,
( int ) $plugin -> update_server ,
$plugin -> update_server_protocol
2023-02-27 12:27:41 +00:00
))
{
$this -> app -> enqueueMessage (
JText :: sprintf (
'Upload of plugin (%s) update server XML failed.' ,
$plugin -> name
), 'Error'
);
}
2019-08-08 15:35:58 +00:00
// remove the local file
2021-03-08 22:36:30 +00:00
File :: delete ( $plugin -> update_server_xml_path );
2019-08-08 15:35:58 +00:00
}
2017-02-01 13:17:04 +00:00
}
}
}
2021-10-18 20:12:19 +00:00
// link changes made to views into the file license
2017-02-01 13:17:04 +00:00
protected function fixLicenseValues ( $data )
{
2017-02-02 12:17:31 +00:00
// check if these files have its own config data)
2020-03-28 13:34:14 +00:00
if ( isset ( $data [ 'config' ])
2022-03-09 23:46:45 +00:00
&& ArrayHelper :: check (
2020-03-28 13:34:14 +00:00
$data [ 'config' ]
)
2023-01-22 00:38:21 +00:00
&& CFactory :: _ ( 'Component' ) -> get ( 'mvc_versiondate' , 0 ) == 1 )
2017-02-01 13:17:04 +00:00
{
foreach ( $data [ 'config' ] as $key => $value )
2016-02-26 00:20:09 +00:00
{
2022-08-30 15:28:41 +00:00
if ( Placefix :: _h ( 'VERSION' ) === $key )
2016-01-30 20:28:43 +00:00
{
2017-02-01 13:17:04 +00:00
// hmm we sould in some way make it known that this version number
// is not in relation the the project but to the file only... any ideas?
// this is the best for now...
if ( 1 == $value )
2016-01-30 20:28:43 +00:00
{
2017-02-01 13:17:04 +00:00
$value = '@first version of this MVC' ;
}
else
{
2017-12-14 23:10:47 +00:00
$value = '@update number ' . $value . ' of this MVC' ;
2016-01-30 20:28:43 +00:00
}
}
2023-10-18 07:26:30 +00:00
CFactory :: _ ( 'Compiler.Builder.Content.One' ) -> set ( $key , $value );
2016-01-30 20:28:43 +00:00
}
2020-03-28 13:34:14 +00:00
2016-02-26 00:20:09 +00:00
return true ;
2016-01-30 20:28:43 +00:00
}
2017-02-01 13:17:04 +00:00
// else insure to reset to global
2023-10-18 07:26:30 +00:00
CFactory :: _ ( 'Compiler.Builder.Content.One' ) -> set ( 'CREATIONDATE' , CFactory :: _ ( 'Compiler.Builder.Content.One' ) -> get ( 'GLOBALCREATIONDATE' ));
CFactory :: _ ( 'Compiler.Builder.Content.One' ) -> set ( 'BUILDDATE' , CFactory :: _ ( 'Compiler.Builder.Content.One' ) -> get ( 'GLOBALBUILDDATE' ));
CFactory :: _ ( 'Compiler.Builder.Content.One' ) -> set ( 'VERSION' , CFactory :: _ ( 'Compiler.Builder.Content.One' ) -> get ( 'GLOBALVERSION' ));
2016-01-30 20:28:43 +00:00
}
2017-03-08 04:49:54 +00:00
2023-01-22 00:38:21 +00:00
/**
* Set all global numbers
*
* @ return void
* @ deprecated 3.3
*/
2017-03-08 04:49:54 +00:00
protected function setCountingStuff ()
{
2023-01-22 00:38:21 +00:00
// set notice that we could not get a valid string from the target
$this -> app -> enqueueMessage (
JText :: sprintf ( '<hr /><h3>%s Warning</h3>' , __CLASS__ ), 'Error'
);
$this -> app -> enqueueMessage (
JText :: sprintf (
'Use of a deprecated method (%s)!' , __METHOD__
), 'Error'
);
2017-03-08 04:49:54 +00:00
}
2017-12-14 23:10:47 +00:00
2017-02-13 23:24:38 +00:00
private function buildReadMe ()
{
// do a final run to update the readme file
$two = 0 ;
2023-02-27 12:27:41 +00:00
// counter data if not set already
2023-10-18 07:26:30 +00:00
if ( ! CFactory :: _ ( 'Compiler.Builder.Content.One' ) -> exists ( 'LINE_COUNT' )
|| CFactory :: _ ( 'Compiler.Builder.Content.One' ) -> get ( 'LINE_COUNT' ) != CFactory :: _ ( 'Utilities.Counter' ) -> line )
2023-02-27 12:27:41 +00:00
{
CFactory :: _ ( 'Utilities.Counter' ) -> set ();
}
// search for the readme
2023-01-29 20:12:42 +00:00
foreach ( CFactory :: _ ( 'Utilities.Files' ) -> get ( 'static' ) as $static )
2017-02-13 23:24:38 +00:00
{
2020-03-28 13:34:14 +00:00
if (( 'README.md' === $static [ 'name' ]
|| 'README.txt' === $static [ 'name' ])
2023-01-22 00:38:21 +00:00
&& CFactory :: _ ( 'Component' ) -> get ( 'addreadme' )
2021-03-08 22:36:30 +00:00
&& File :: exists ( $static [ 'path' ]))
2017-02-13 23:24:38 +00:00
{
$this -> setReadMe ( $static [ 'path' ]);
$two ++ ;
}
if ( $two == 2 )
{
break ;
}
}
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.Files' ) -> remove ( 'static' );
2017-02-13 23:24:38 +00:00
}
2017-12-14 23:10:47 +00:00
2017-02-13 23:24:38 +00:00
private function setReadMe ( $path )
2016-10-23 22:48:26 +00:00
{
// get the file
2023-01-01 02:11:34 +00:00
$string = FileHelper :: getContent ( $path );
2016-10-23 22:48:26 +00:00
// update the file
2023-10-18 07:26:30 +00:00
$answer = CFactory :: _ ( 'Placeholder' ) -> update ( $string , CFactory :: _ ( 'Compiler.Builder.Content.One' ) -> allActive ());
2016-10-23 22:48:26 +00:00
// add to zip array
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.File' ) -> write ( $path , $answer );
2017-12-14 23:10:47 +00:00
}
2023-01-22 00:38:21 +00:00
/**
* Build README data
*
* @ return void
* @ deprecated 3.3
*/
2016-10-23 22:48:26 +00:00
private function buildReadMeData ()
2016-01-30 20:28:43 +00:00
{
2023-01-22 00:38:21 +00:00
// set notice that we could not get a valid string from the target
$this -> app -> enqueueMessage (
JText :: sprintf ( '<hr /><h3>%s Warning</h3>' , __CLASS__ ), 'Error'
);
$this -> app -> enqueueMessage (
JText :: sprintf (
'Use of a deprecated method (%s)!' , __METHOD__
), 'Error'
);
2016-01-30 20:28:43 +00:00
}
2019-08-08 15:35:58 +00:00
private function setLocalRepos ()
2016-01-30 20:28:43 +00:00
{
2019-08-08 15:35:58 +00:00
// move it to the repo folder if set
2020-03-28 13:34:14 +00:00
if ( isset ( $this -> repoPath )
2022-03-09 23:46:45 +00:00
&& StringHelper :: check (
2020-03-28 13:34:14 +00:00
$this -> repoPath
))
2016-02-26 00:20:09 +00:00
{
2017-09-18 00:18:23 +00:00
// set the repo path
2020-03-28 13:34:14 +00:00
$repoFullPath = $this -> repoPath . '/com_'
2023-01-22 00:38:21 +00:00
. CFactory :: _ ( 'Component' ) -> get ( 'sales_name' ) . '__joomla_'
2022-08-30 15:28:41 +00:00
. CFactory :: _ ( 'Config' ) -> get ( 'version' , 3 );
2023-01-15 08:42:19 +00:00
// for plugin event TODO change event api signatures
$component_context = CFactory :: _ ( 'Config' ) -> component_context ;
2023-01-29 20:12:42 +00:00
$component_path = CFactory :: _ ( 'Utilities.Paths' ) -> component_path ;
2019-07-06 22:29:35 +00:00
// Trigger Event: jcb_ce_onBeforeUpdateRepo
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onBeforeUpdateRepo' ,
2023-01-29 20:12:42 +00:00
array ( & $component_context , & $component_path ,
2020-03-28 13:34:14 +00:00
& $repoFullPath , & $this -> componentData )
);
2016-02-26 00:20:09 +00:00
// remove old data
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.Folder' ) -> remove ( $repoFullPath , CFactory :: _ ( 'Component' ) -> get ( 'toignore' ));
2016-02-26 00:20:09 +00:00
// set the new data
2023-01-29 20:12:42 +00:00
Folder :: copy ( CFactory :: _ ( 'Utilities.Paths' ) -> component_path , $repoFullPath , '' , true );
2019-07-06 22:29:35 +00:00
// Trigger Event: jcb_ce_onAfterUpdateRepo
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onAfterUpdateRepo' ,
2023-01-29 20:12:42 +00:00
array ( & $component_context , & $component_path ,
2020-03-28 13:34:14 +00:00
& $repoFullPath , & $this -> componentData )
);
2019-08-08 15:35:58 +00:00
2019-12-06 05:31:32 +00:00
// move the modules to local folder repos
2023-01-22 00:38:21 +00:00
if ( CFactory :: _ ( 'Joomlamodule.Data' ) -> exists ())
2019-12-06 05:31:32 +00:00
{
2023-01-22 00:38:21 +00:00
foreach ( CFactory :: _ ( 'Joomlamodule.Data' ) -> get () as $module )
2019-12-06 05:31:32 +00:00
{
2022-03-09 23:46:45 +00:00
if ( ObjectHelper :: check ( $module )
2020-03-28 13:34:14 +00:00
&& isset ( $module -> file_name ))
2019-12-06 05:31:32 +00:00
{
2020-03-28 13:34:14 +00:00
$module_context = 'module.' . $module -> file_name . '.'
. $module -> id ;
2019-12-06 05:31:32 +00:00
// set the repo path
2020-03-28 13:34:14 +00:00
$repoFullPath = $this -> repoPath . '/'
. $module -> folder_name . '__joomla_'
2022-08-30 15:28:41 +00:00
. CFactory :: _ ( 'Config' ) -> get ( 'version' , 3 );
2019-12-06 05:31:32 +00:00
// Trigger Event: jcb_ce_onBeforeUpdateRepo
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onBeforeUpdateRepo' ,
array ( & $module_context , & $module -> folder_path ,
& $repoFullPath , & $module )
);
2019-12-06 05:31:32 +00:00
// remove old data
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.Folder' ) -> remove (
2023-01-22 00:38:21 +00:00
$repoFullPath , CFactory :: _ ( 'Component' ) -> get ( 'toignore' )
2020-03-28 13:34:14 +00:00
);
2019-12-06 05:31:32 +00:00
// set the new data
2021-03-08 22:36:30 +00:00
Folder :: copy (
2020-03-28 13:34:14 +00:00
$module -> folder_path , $repoFullPath , '' , true
);
2019-12-06 05:31:32 +00:00
// Trigger Event: jcb_ce_onAfterUpdateRepo
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onAfterUpdateRepo' ,
array ( & $module_context , & $module -> folder_path ,
& $repoFullPath , & $module )
);
2019-12-06 05:31:32 +00:00
}
}
}
2019-08-08 15:35:58 +00:00
// move the plugins to local folder repos
2023-01-22 00:38:21 +00:00
if ( CFactory :: _ ( 'Joomlaplugin.Data' ) -> exists ())
2019-08-08 15:35:58 +00:00
{
2023-01-22 00:38:21 +00:00
foreach ( CFactory :: _ ( 'Joomlaplugin.Data' ) -> get () as $plugin )
2019-08-08 15:35:58 +00:00
{
2022-03-09 23:46:45 +00:00
if ( ObjectHelper :: check ( $plugin )
2020-03-28 13:34:14 +00:00
&& isset ( $plugin -> file_name ))
2019-08-08 15:35:58 +00:00
{
2020-03-28 13:34:14 +00:00
$plugin_context = 'plugin.' . $plugin -> file_name . '.'
. $plugin -> id ;
2019-08-08 15:35:58 +00:00
// set the repo path
2020-03-28 13:34:14 +00:00
$repoFullPath = $this -> repoPath . '/'
. $plugin -> folder_name . '__joomla_'
2022-08-30 15:28:41 +00:00
. CFactory :: _ ( 'Config' ) -> get ( 'version' , 3 );
2019-08-08 15:35:58 +00:00
// Trigger Event: jcb_ce_onBeforeUpdateRepo
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onBeforeUpdateRepo' ,
array ( & $plugin_context , & $plugin -> folder_path ,
& $repoFullPath , & $plugin )
);
2019-08-08 15:35:58 +00:00
// remove old data
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.Folder' ) -> remove (
2023-01-22 00:38:21 +00:00
$repoFullPath , CFactory :: _ ( 'Component' ) -> get ( 'toignore' )
2020-03-28 13:34:14 +00:00
);
2019-08-08 15:35:58 +00:00
// set the new data
2021-03-08 22:36:30 +00:00
Folder :: copy (
2020-03-28 13:34:14 +00:00
$plugin -> folder_path , $repoFullPath , '' , true
);
2019-08-08 15:35:58 +00:00
// Trigger Event: jcb_ce_onAfterUpdateRepo
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onAfterUpdateRepo' ,
array ( & $plugin_context , & $plugin -> folder_path ,
& $repoFullPath , & $plugin )
);
2019-08-08 15:35:58 +00:00
}
}
}
2016-02-26 00:20:09 +00:00
}
2019-08-08 15:35:58 +00:00
}
private function zipComponent ()
{
2019-08-12 21:30:31 +00:00
// Component Folder Name
2023-01-29 20:12:42 +00:00
$this -> filepath [ 'component-folder' ] = CFactory :: _ ( 'Utilities.Paths' ) -> component_folder_name ;
2016-02-26 00:20:09 +00:00
// the name of the zip file to create
2020-03-28 13:34:14 +00:00
$this -> filepath [ 'component' ] = $this -> tempPath . '/'
. $this -> filepath [ 'component-folder' ] . '.zip' ;
2023-01-15 08:42:19 +00:00
// for plugin event TODO change event api signatures
$component_context = CFactory :: _ ( 'Config' ) -> component_context ;
2023-01-29 20:12:42 +00:00
$component_path = CFactory :: _ ( 'Utilities.Paths' ) -> component_path ;
$component_sales_name = CFactory :: _ ( 'Utilities.Paths' ) -> component_sales_name ;
$component_folder_name = CFactory :: _ ( 'Utilities.Paths' ) -> component_folder_name ;
2019-07-06 22:29:35 +00:00
// Trigger Event: jcb_ce_onBeforeZipComponent
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onBeforeZipComponent' ,
2023-01-29 20:12:42 +00:00
array ( & $component_context , & $component_path ,
2020-03-28 13:34:14 +00:00
& $this -> filepath [ 'component' ], & $this -> tempPath ,
2023-01-29 20:12:42 +00:00
& $component_folder_name , & $this -> componentData )
2020-03-28 13:34:14 +00:00
);
2016-02-26 00:20:09 +00:00
//create the zip file
2022-04-04 15:35:08 +00:00
if ( FileHelper :: zip (
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.Paths' ) -> component_path , $this -> filepath [ 'component' ]
2020-03-28 13:34:14 +00:00
))
2016-01-30 20:28:43 +00:00
{
2019-07-06 22:29:35 +00:00
// now move to backup if zip was made and backup is required
2016-11-22 05:48:55 +00:00
if ( $this -> backupPath && $this -> dynamicIntegration )
2016-01-30 20:28:43 +00:00
{
2019-07-06 22:29:35 +00:00
// Trigger Event: jcb_ce_onBeforeBackupZip
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2023-01-15 08:42:19 +00:00
'jcb_ce_onBeforeBackupZip' , array ( & $component_context ,
2020-03-28 13:34:14 +00:00
& $this -> filepath [ 'component' ],
& $this -> tempPath ,
& $this -> backupPath ,
& $this -> componentData )
);
2019-07-06 22:29:35 +00:00
// copy the zip to backup path
2021-03-08 22:36:30 +00:00
File :: copy (
2020-03-28 13:34:14 +00:00
$this -> filepath [ 'component' ],
2023-01-29 20:12:42 +00:00
$this -> backupPath . '/' . CFactory :: _ ( 'Utilities.Paths' ) -> component_backup_name
2020-03-28 13:34:14 +00:00
. '.zip'
);
2016-01-30 20:28:43 +00:00
}
2016-02-26 00:20:09 +00:00
// move to sales server host
2023-01-22 00:38:21 +00:00
if ( CFactory :: _ ( 'Component' ) -> get ( 'add_sales_server' , 0 ) == 1
2020-03-28 13:34:14 +00:00
&& $this -> dynamicIntegration )
2016-01-30 20:28:43 +00:00
{
2016-02-26 00:20:09 +00:00
// make sure we have the correct file
2023-01-22 00:38:21 +00:00
if ( CFactory :: _ ( 'Component' ) -> get ( 'sales_server' ))
2016-01-30 20:28:43 +00:00
{
2019-07-06 22:29:35 +00:00
// Trigger Event: jcb_ce_onBeforeMoveToServer
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onBeforeMoveToServer' ,
2023-01-15 08:42:19 +00:00
array ( & $component_context ,
2020-03-28 13:34:14 +00:00
& $this -> filepath [ 'component' ], & $this -> tempPath ,
2023-01-29 20:12:42 +00:00
& $component_sales_name , & $this -> componentData )
2020-03-28 13:34:14 +00:00
);
2018-02-20 20:46:29 +00:00
// move to server
2023-02-27 12:27:41 +00:00
if ( ! CFactory :: _ ( 'Server' ) -> legacyMove (
2020-03-28 13:34:14 +00:00
$this -> filepath [ 'component' ],
2023-01-29 20:12:42 +00:00
$component_sales_name . '.zip' ,
2023-01-22 00:38:21 +00:00
( int ) CFactory :: _ ( 'Component' ) -> get ( 'sales_server' ),
CFactory :: _ ( 'Component' ) -> get ( 'sales_server_protocol' )
2023-02-27 12:27:41 +00:00
))
{
$this -> app -> enqueueMessage (
JText :: sprintf (
'Upload of component (%s) zip file failed.' ,
CFactory :: _ ( 'Component' ) -> get ( 'system_name' )
), 'Error'
);
}
2016-01-30 20:28:43 +00:00
}
}
2019-07-06 22:29:35 +00:00
// Trigger Event: jcb_ce_onAfterZipComponent
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onAfterZipComponent' ,
2023-01-15 08:42:19 +00:00
array ( & $component_context , & $this -> filepath [ 'component' ],
2023-01-29 20:12:42 +00:00
& $this -> tempPath , & $component_folder_name ,
2020-03-28 13:34:14 +00:00
& $this -> componentData )
);
2016-02-26 00:20:09 +00:00
// remove the component folder since we are done
2023-01-29 20:12:42 +00:00
if ( CFactory :: _ ( 'Utilities.Folder' ) -> remove ( CFactory :: _ ( 'Utilities.Paths' ) -> component_path ))
2016-01-30 20:28:43 +00:00
{
2016-02-26 00:20:09 +00:00
return true ;
2016-01-30 20:28:43 +00:00
}
}
2020-03-28 13:34:14 +00:00
2016-02-26 00:20:09 +00:00
return false ;
}
2017-12-14 23:10:47 +00:00
2019-12-06 05:31:32 +00:00
private function zipModules ()
{
2023-01-22 00:38:21 +00:00
if ( CFactory :: _ ( 'Joomlamodule.Data' ) -> exists ())
2019-12-06 05:31:32 +00:00
{
2023-01-22 00:38:21 +00:00
foreach ( CFactory :: _ ( 'Joomlamodule.Data' ) -> get () as $module )
2019-12-06 05:31:32 +00:00
{
2022-03-09 23:46:45 +00:00
if ( ObjectHelper :: check ( $module )
2020-03-28 13:34:14 +00:00
&& isset ( $module -> zip_name )
2022-03-09 23:46:45 +00:00
&& StringHelper :: check ( $module -> zip_name )
2019-12-06 05:31:32 +00:00
&& isset ( $module -> folder_path )
2022-03-09 23:46:45 +00:00
&& StringHelper :: check (
2020-03-28 13:34:14 +00:00
$module -> folder_path
))
2019-12-06 05:31:32 +00:00
{
// set module context
$module_context = $module -> file_name . '.' . $module -> id ;
// Component Folder Name
2020-03-28 13:34:14 +00:00
$this -> filepath [ 'modules-folder' ][ $module -> id ]
= $module -> zip_name ;
2019-12-06 05:31:32 +00:00
// the name of the zip file to create
2020-03-28 13:34:14 +00:00
$this -> filepath [ 'modules' ][ $module -> id ] = $this -> tempPath
. '/' . $module -> zip_name . '.zip' ;
2019-12-06 05:31:32 +00:00
// Trigger Event: jcb_ce_onBeforeZipModule
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onBeforeZipModule' ,
array ( & $module_context , & $module -> folder_path ,
& $this -> filepath [ 'modules' ][ $module -> id ],
& $this -> tempPath , & $module -> zip_name , & $module )
);
2019-12-06 05:31:32 +00:00
//create the zip file
2022-04-04 15:35:08 +00:00
if ( FileHelper :: zip (
2020-03-28 13:34:14 +00:00
$module -> folder_path ,
$this -> filepath [ 'modules' ][ $module -> id ]
))
2019-12-06 05:31:32 +00:00
{
// now move to backup if zip was made and backup is required
if ( $this -> backupPath )
{
$__module_context = 'module.' . $module_context ;
// Trigger Event: jcb_ce_onBeforeBackupZip
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onBeforeBackupZip' ,
array ( & $__module_context ,
& $this -> filepath [ 'modules' ][ $module -> id ],
& $this -> tempPath , & $this -> backupPath ,
& $module )
);
2019-12-06 05:31:32 +00:00
// copy the zip to backup path
2021-03-08 22:36:30 +00:00
File :: copy (
2020-03-28 13:34:14 +00:00
$this -> filepath [ 'modules' ][ $module -> id ],
$this -> backupPath . '/' . $module -> zip_name
. '.zip'
);
2019-12-06 05:31:32 +00:00
}
// move to sales server host
if ( $module -> add_sales_server == 1 )
{
// make sure we have the correct file
if ( isset ( $module -> sales_server ))
{
// Trigger Event: jcb_ce_onBeforeMoveToServer
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onBeforeMoveToServer' ,
array ( & $__module_context ,
& $this -> filepath [ 'modules' ][ $module -> id ],
& $this -> tempPath , & $module -> zip_name ,
& $module )
);
2019-12-06 05:31:32 +00:00
// move to server
2023-02-27 12:27:41 +00:00
if ( ! CFactory :: _ ( 'Server' ) -> legacyMove (
2020-03-28 13:34:14 +00:00
$this -> filepath [ 'modules' ][ $module -> id ],
$module -> zip_name . '.zip' ,
( int ) $module -> sales_server ,
$module -> sales_server_protocol
2023-02-27 12:27:41 +00:00
))
{
$this -> app -> enqueueMessage (
JText :: sprintf (
'Upload of module (%s) zip file failed.' ,
$module -> name
), 'Error'
);
}
2019-12-06 05:31:32 +00:00
}
}
// Trigger Event: jcb_ce_onAfterZipModule
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onAfterZipModule' , array ( & $module_context ,
& $this -> filepath [ 'modules' ][ $module -> id ],
& $this -> tempPath ,
& $module -> zip_name ,
& $module )
);
2019-12-06 05:31:32 +00:00
// remove the module folder since we are done
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.Folder' ) -> remove ( $module -> folder_path );
2019-12-06 05:31:32 +00:00
}
}
}
}
}
2019-08-08 15:35:58 +00:00
private function zipPlugins ()
{
2023-01-22 00:38:21 +00:00
if ( CFactory :: _ ( 'Joomlaplugin.Data' ) -> exists ())
2019-08-08 15:35:58 +00:00
{
2023-01-22 00:38:21 +00:00
foreach ( CFactory :: _ ( 'Joomlaplugin.Data' ) -> get () as $plugin )
2019-08-08 15:35:58 +00:00
{
2022-03-09 23:46:45 +00:00
if ( ObjectHelper :: check ( $plugin )
2020-03-28 13:34:14 +00:00
&& isset ( $plugin -> zip_name )
2022-03-09 23:46:45 +00:00
&& StringHelper :: check ( $plugin -> zip_name )
2019-08-08 15:35:58 +00:00
&& isset ( $plugin -> folder_path )
2022-03-09 23:46:45 +00:00
&& StringHelper :: check (
2020-03-28 13:34:14 +00:00
$plugin -> folder_path
))
2019-08-08 15:35:58 +00:00
{
// set plugin context
$plugin_context = $plugin -> file_name . '.' . $plugin -> id ;
2019-08-12 21:30:31 +00:00
// Component Folder Name
2020-03-28 13:34:14 +00:00
$this -> filepath [ 'plugins-folder' ][ $plugin -> id ]
= $plugin -> zip_name ;
2019-08-08 15:35:58 +00:00
// the name of the zip file to create
2020-03-28 13:34:14 +00:00
$this -> filepath [ 'plugins' ][ $plugin -> id ] = $this -> tempPath
. '/' . $plugin -> zip_name . '.zip' ;
2019-08-08 15:35:58 +00:00
// Trigger Event: jcb_ce_onBeforeZipPlugin
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onBeforeZipPlugin' ,
array ( & $plugin_context , & $plugin -> folder_path ,
& $this -> filepath [ 'plugins' ][ $plugin -> id ],
& $this -> tempPath , & $plugin -> zip_name , & $plugin )
);
2019-08-08 15:35:58 +00:00
//create the zip file
2022-04-04 15:35:08 +00:00
if ( FileHelper :: zip (
2020-03-28 13:34:14 +00:00
$plugin -> folder_path ,
$this -> filepath [ 'plugins' ][ $plugin -> id ]
))
2019-08-08 15:35:58 +00:00
{
// now move to backup if zip was made and backup is required
if ( $this -> backupPath )
{
$__plugin_context = 'plugin.' . $plugin_context ;
// Trigger Event: jcb_ce_onBeforeBackupZip
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onBeforeBackupZip' ,
array ( & $__plugin_context ,
& $this -> filepath [ 'plugins' ][ $plugin -> id ],
& $this -> tempPath , & $this -> backupPath ,
& $plugin )
);
2019-08-08 15:35:58 +00:00
// copy the zip to backup path
2021-03-08 22:36:30 +00:00
File :: copy (
2020-03-28 13:34:14 +00:00
$this -> filepath [ 'plugins' ][ $plugin -> id ],
$this -> backupPath . '/' . $plugin -> zip_name
. '.zip'
);
2019-08-08 15:35:58 +00:00
}
// move to sales server host
if ( $plugin -> add_sales_server == 1 )
{
// make sure we have the correct file
if ( isset ( $plugin -> sales_server ))
{
// Trigger Event: jcb_ce_onBeforeMoveToServer
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onBeforeMoveToServer' ,
array ( & $__plugin_context ,
& $this -> filepath [ 'plugins' ][ $plugin -> id ],
& $this -> tempPath , & $plugin -> zip_name ,
& $plugin )
);
2019-08-08 15:35:58 +00:00
// move to server
2023-02-27 12:27:41 +00:00
if ( ! CFactory :: _ ( 'Server' ) -> legacyMove (
2020-03-28 13:34:14 +00:00
$this -> filepath [ 'plugins' ][ $plugin -> id ],
$plugin -> zip_name . '.zip' ,
( int ) $plugin -> sales_server ,
$plugin -> sales_server_protocol
2023-02-27 12:27:41 +00:00
))
{
$this -> app -> enqueueMessage (
JText :: sprintf (
'Upload of plugin (%s) zip file failed.' ,
$plugin -> name
), 'Error'
);
}
2019-08-08 15:35:58 +00:00
}
}
// Trigger Event: jcb_ce_onAfterZipPlugin
2022-09-10 08:16:44 +00:00
CFactory :: _ ( 'Event' ) -> trigger (
2020-03-28 13:34:14 +00:00
'jcb_ce_onAfterZipPlugin' , array ( & $plugin_context ,
& $this -> filepath [ 'plugins' ][ $plugin -> id ],
& $this -> tempPath ,
& $plugin -> zip_name ,
& $plugin )
);
2019-08-08 15:35:58 +00:00
// remove the plugin folder since we are done
2023-01-29 20:12:42 +00:00
CFactory :: _ ( 'Utilities.Folder' ) -> remove ( $plugin -> folder_path );
2019-08-08 15:35:58 +00:00
}
}
}
}
}
2017-02-13 23:24:38 +00:00
protected function addCustomCode ()
2017-02-01 13:17:04 +00:00
{
2017-02-11 02:24:26 +00:00
// reset all these
2022-08-30 15:28:41 +00:00
CFactory :: _ ( 'Placeholder' ) -> clearType ( 'view' );
CFactory :: _ ( 'Placeholder' ) -> clearType ( 'arg' );
foreach ( CFactory :: _ ( 'Customcode' ) -> active as $nr => $target )
2017-02-01 13:17:04 +00:00
{
// reset each time per custom code
$fingerPrint = array ();
2020-03-28 13:34:14 +00:00
if ( isset ( $target [ 'hashtarget' ][ 0 ]) && $target [ 'hashtarget' ][ 0 ] > 3
&& isset ( $target [ 'path' ])
2022-03-09 23:46:45 +00:00
&& StringHelper :: check ( $target [ 'path' ])
2020-03-28 13:34:14 +00:00
&& isset ( $target [ 'hashtarget' ][ 1 ])
2022-03-09 23:46:45 +00:00
&& StringHelper :: check (
2020-03-28 13:34:14 +00:00
$target [ 'hashtarget' ][ 1 ]
))
2017-02-01 13:17:04 +00:00
{
2023-01-29 20:12:42 +00:00
$file = CFactory :: _ ( 'Utilities.Paths' ) -> component_path . '/' . $target [ 'path' ];
2020-03-28 13:34:14 +00:00
$size = ( int ) $target [ 'hashtarget' ][ 0 ];
$hash = $target [ 'hashtarget' ][ 1 ];
$cut = $size - 1 ;
$found = false ;
$bites = 0 ;
2017-12-14 23:10:47 +00:00
$lineBites = array ();
2020-03-28 13:34:14 +00:00
$replace = array ();
if ( $target [ 'type' ] == 1 && isset ( $target [ 'hashendtarget' ][ 0 ])
&& $target [ 'hashendtarget' ][ 0 ] > 0 )
2017-02-01 13:17:04 +00:00
{
2017-12-14 23:10:47 +00:00
$foundEnd = false ;
2020-03-28 13:34:14 +00:00
$sizeEnd = ( int ) $target [ 'hashendtarget' ][ 0 ];
$hashEnd = $target [ 'hashendtarget' ][ 1 ];
$cutEnd = $sizeEnd - 1 ;
2017-02-01 13:17:04 +00:00
}
else
{
// replace to the end of the file
2017-12-14 23:10:47 +00:00
$foundEnd = true ;
2017-02-01 13:17:04 +00:00
}
2017-12-14 23:10:47 +00:00
$counter = 0 ;
2017-02-11 02:24:26 +00:00
// check if file exist
2021-03-08 22:36:30 +00:00
if ( File :: exists ( $file ))
2017-02-01 13:17:04 +00:00
{
2020-03-28 13:34:14 +00:00
foreach (
new SplFileObject ( $file ) as $lineNumber => $lineContent
)
2017-02-01 13:17:04 +00:00
{
2017-02-04 00:22:17 +00:00
// if not found we need to load line bites per line
2020-03-28 13:34:14 +00:00
$lineBites [ $lineNumber ] = ( int ) mb_strlen (
$lineContent , '8bit'
);
2017-02-01 13:17:04 +00:00
if ( ! $found )
{
2022-03-09 23:46:45 +00:00
$bites = ( int ) MathHelper :: bc (
2020-03-28 13:34:14 +00:00
'add' , $lineBites [ $lineNumber ], $bites
);
2017-02-01 13:17:04 +00:00
}
if ( $found && ! $foundEnd )
{
2017-02-04 00:22:17 +00:00
$replace [] = ( int ) $lineBites [ $lineNumber ];
2023-05-02 00:10:55 +00:00
// we must keep last three lines to dynamic find target entry
2017-02-01 13:17:04 +00:00
$fingerPrint [ $lineNumber ] = trim ( $lineContent );
// check lines each time if it fits our target
2020-03-28 13:34:14 +00:00
if ( count (( array ) $fingerPrint ) === $sizeEnd
&& ! $foundEnd )
2017-02-01 13:17:04 +00:00
{
2017-12-14 23:10:47 +00:00
$fingerTest = md5 ( implode ( '' , $fingerPrint ));
2017-02-01 13:17:04 +00:00
if ( $fingerTest === $hashEnd )
{
// we are done here
$foundEnd = true ;
2020-03-28 13:34:14 +00:00
$replace = array_slice (
$replace , 0 , count ( $replace ) - $sizeEnd
);
2017-02-01 13:17:04 +00:00
break ;
}
else
{
2020-03-28 13:34:14 +00:00
$fingerPrint = array_slice (
$fingerPrint , - $cutEnd , $cutEnd , true
);
2017-02-01 13:17:04 +00:00
}
}
2017-02-04 00:22:17 +00:00
continue ;
2017-02-01 13:17:04 +00:00
}
if ( $found && $foundEnd )
{
2017-02-04 00:22:17 +00:00
$replace [] = ( int ) $lineBites [ $lineNumber ];
2017-02-01 13:17:04 +00:00
}
2023-05-02 00:10:55 +00:00
// we must keep last three lines to dynamic find target entry
2017-02-01 13:17:04 +00:00
$fingerPrint [ $lineNumber ] = trim ( $lineContent );
// check lines each time if it fits our target
2019-09-05 21:12:56 +00:00
if ( count (( array ) $fingerPrint ) === $size && ! $found )
2017-02-01 13:17:04 +00:00
{
2017-12-14 23:10:47 +00:00
$fingerTest = md5 ( implode ( '' , $fingerPrint ));
2017-02-01 13:17:04 +00:00
if ( $fingerTest === $hash )
{
// we are done here
$found = true ;
// reset in case
$fingerPrint = array ();
// break if it is insertion
if ( $target [ 'type' ] == 2 )
{
break ;
}
}
else
{
2020-03-28 13:34:14 +00:00
$fingerPrint = array_slice (
$fingerPrint , - $cut , $cut , true
);
2017-02-01 13:17:04 +00:00
}
}
}
if ( $found )
{
2022-08-30 15:28:41 +00:00
$placeholder = CFactory :: _ ( 'Placeholder' ) -> keys (
2020-03-28 13:34:14 +00:00
( int ) $target [ 'comment_type' ] . $target [ 'type' ],
$target [ 'id' ]
);
$data = $placeholder [ 'start' ] . PHP_EOL
2022-12-11 15:06:13 +00:00
. CFactory :: _ ( 'Placeholder' ) -> update_ (
$target [ 'code' ]
2020-03-28 13:34:14 +00:00
) . $placeholder [ 'end' ] . PHP_EOL ;
2017-02-01 13:17:04 +00:00
if ( $target [ 'type' ] == 2 )
{
// found it now add code from the next line
$this -> addDataToFile ( $file , $data , $bites );
}
elseif ( $target [ 'type' ] == 1 && $foundEnd )
{
// found it now add code from the next line
2020-03-28 13:34:14 +00:00
$this -> addDataToFile (
$file , $data , $bites , ( int ) array_sum ( $replace )
);
2017-02-01 13:17:04 +00:00
}
else
{
2017-02-04 00:22:17 +00:00
// Load escaped code since the target endhash has changed
$this -> loadEscapedCode ( $file , $target , $lineBites );
2020-03-28 13:34:14 +00:00
$this -> app -> enqueueMessage (
JText :: _ ( '<hr /><h3>Custom Code Warning</h3>' ),
'Warning'
);
$this -> app -> enqueueMessage (
JText :: sprintf (
'Custom code %s could not be added to <b>%s</b> please review the file after install at <b>line %s</b> and reposition the code, remove the comments and recompile to fix the issue. The issue could be due to a change to <b>lines below</b> the custom code.' ,
'<a href="index.php?option=com_componentbuilder&view=custom_codes&task=custom_code.edit&id='
. $target [ 'id' ] . '" target="_blank">#'
. $target [ 'id' ] . '</a>' , $target [ 'path' ],
$target [ 'from_line' ]
), 'Warning'
);
2017-02-01 13:17:04 +00:00
}
}
else
{
2017-02-04 00:22:17 +00:00
// Load escaped code since the target hash has changed
$this -> loadEscapedCode ( $file , $target , $lineBites );
2020-03-28 13:34:14 +00:00
$this -> app -> enqueueMessage (
JText :: _ ( '<hr /><h3>Custom Code Warning</h3>' ),
'Warning'
);
$this -> app -> enqueueMessage (
JText :: sprintf (
'Custom code %s could not be added to <b>%s</b> please review the file after install at <b>line %s</b> and reposition the code, remove the comments and recompile to fix the issue. The issue could be due to a change to <b>lines above</b> the custom code.' ,
'<a href="index.php?option=com_componentbuilder&view=custom_codes&task=custom_code.edit&id='
. $target [ 'id' ] . '" target="_blank">#'
. $target [ 'id' ] . '</a>' , $target [ 'path' ],
$target [ 'from_line' ]
), 'Warning'
);
2017-02-01 13:17:04 +00:00
}
}
else
{
2017-02-04 00:22:17 +00:00
// Give developer a notice that file is not found.
2020-03-28 13:34:14 +00:00
$this -> app -> enqueueMessage (
JText :: _ ( '<hr /><h3>Custom Code Warning</h3>' ),
'Warning'
);
$this -> app -> enqueueMessage (
JText :: sprintf (
'File <b>%s</b> could not be found, so the custom code for this file could not be addded.' ,
$target [ 'path' ]
), 'Warning'
);
2017-02-01 13:17:04 +00:00
}
}
}
}
2017-02-04 00:22:17 +00:00
protected function loadEscapedCode ( $file , $target , $lineBites )
{
2017-10-30 18:50:56 +00:00
// get comment type
if ( $target [ 'comment_type' ] == 1 )
{
2020-03-28 13:34:14 +00:00
$commentType = " // " ;
2017-10-30 18:50:56 +00:00
$_commentType = " " ;
}
else
{
2020-03-28 13:34:14 +00:00
$commentType = " <!-- " ;
2017-10-30 18:50:56 +00:00
$_commentType = " --> " ;
}
2017-02-04 00:22:17 +00:00
// escape the code
2023-01-01 02:11:34 +00:00
$code = explode ( PHP_EOL , ( string ) $target [ 'code' ]);
2020-03-28 13:34:14 +00:00
$code = PHP_EOL . $commentType . implode (
$_commentType . PHP_EOL . $commentType , $code
) . $_commentType . PHP_EOL ;
2023-05-02 00:10:55 +00:00
// get placeholders
2022-08-30 15:28:41 +00:00
$placeholder = CFactory :: _ ( 'Placeholder' ) -> keys (
2020-03-28 13:34:14 +00:00
( int ) $target [ 'comment_type' ] . $target [ 'type' ], $target [ 'id' ]
);
2017-02-04 00:22:17 +00:00
// build the data
2017-12-14 23:10:47 +00:00
$data = $placeholder [ 'start' ] . $code . $placeholder [ 'end' ] . PHP_EOL ;
2017-02-04 00:22:17 +00:00
// get the bites before insertion
2017-12-14 23:10:47 +00:00
$bitBucket = array ();
foreach ( $lineBites as $line => $value )
2017-02-04 00:22:17 +00:00
{
if ( $line < $target [ 'from_line' ])
{
$bitBucket [] = $value ;
}
}
// add to the file
$this -> addDataToFile ( $file , $data , ( int ) array_sum ( $bitBucket ));
}
2023-05-02 00:10:55 +00:00
/**
* Inserts or replaces data in a file at a specific position .
* Thanks to http :// stackoverflow . com / a / 16813550 / 1429677
*
* @ param string $file The path of the file to modify
* @ param string $data The data to insert or replace
* @ param int $position The position in the file where the data should be inserted or replaced
* @ param int | null $replace The number of bytes to replace ; if null , data will be inserted
*
* @ return void
* @ throws RuntimeException if unable to open the file
*/
protected function addDataToFile ( string $file , string $data , int $position , ? int $replace = null )
2017-02-01 13:17:04 +00:00
{
2023-05-02 00:10:55 +00:00
// Open the file and a temporary stream
$actual_file = fopen ( $file , " rw+ " );
if ( $actual_file === false )
2017-02-01 13:17:04 +00:00
{
2023-05-02 00:10:55 +00:00
throw new RuntimeException ( " Unable to open the file: { $file } " );
2017-02-01 13:17:04 +00:00
}
2023-05-02 00:10:55 +00:00
$temp_file = fopen ( 'php://temp' , " rw+ " );
// Make a copy of the file in the temporary stream
stream_copy_to_stream ( $actual_file , $temp_file );
// Move to the position where the data should be added
fseek ( $actual_file , $position );
// Add the data
fwrite ( $actual_file , $data );
// Truncate the file at the end of the added data if replacing
$data_length = mb_strlen ( $data , '8bit' );
$remove = MathHelper :: bc ( 'add' , $position , $data_length );
ftruncate ( $actual_file , $remove );
// check if this was a replacement of data
$position = MathHelper :: bc ( 'add' , $position , $replace ? : 0 );
// Move to the position of the remaining data in the temporary stream
fseek ( $temp_file , $position );
// Copy the remaining data from the temporary stream to the file
stream_copy_to_stream ( $temp_file , $actual_file );
// Close both file handles
fclose ( $actual_file );
fclose ( $temp_file );
2017-12-14 23:10:47 +00:00
2017-02-11 02:24:26 +00:00
// any help to improve this is welcome...
2017-02-01 13:17:04 +00:00
}
2018-05-26 10:03:08 +00:00
2016-01-30 20:28:43 +00:00
}