2016-01-30 20:28:43 +00:00
< ? php
2021-03-05 03:08:47 +00:00
/**
* @ package Joomla . Component . Builder
*
* @ created 30 th April , 2015
2022-07-09 15:45:08 +00:00
* @ author Llewellyn van der Merwe < https :// dev . vdm . io >
* @ git Joomla Component Builder < https :// git . vdm . dev / joomla / Component - Builder >
2021-03-05 03:08:47 +00:00
* @ copyright Copyright ( C ) 2015 Vast Development Method . All rights reserved .
* @ license GNU General Public License version 2 or later ; see LICENSE . txt
*/
// No direct access to this file
defined ( '_JEXEC' ) or die ( 'Restricted access' );
2024-03-02 20:10:30 +00:00
use Joomla\CMS\Factory ;
use Joomla\CMS\Language\Text ;
2022-05-25 08:30:55 +00:00
use Joomla\CMS\MVC\Controller\AdminController ;
2021-03-05 03:08:47 +00:00
use Joomla\Utilities\ArrayHelper ;
2024-03-02 20:10:30 +00:00
use Joomla\CMS\Router\Route ;
use Joomla\CMS\Session\Session ;
2022-08-30 15:28:41 +00:00
use VDM\Joomla\Componentbuilder\Compiler\Factory as CFactory ;
2024-03-02 20:10:30 +00:00
use Joomla\CMS\Version ;
2023-10-18 07:26:30 +00:00
use VDM\Joomla\Utilities\ArrayHelper as UtilitiesArrayHelper ;
use VDM\Joomla\Utilities\StringHelper ;
2021-03-05 03:08:47 +00:00
/**
2022-05-25 08:30:55 +00:00
* Compiler Admin Controller
2021-03-05 03:08:47 +00:00
*/
2022-05-25 08:30:55 +00:00
class ComponentbuilderControllerCompiler extends AdminController
2021-03-05 03:08:47 +00:00
{
2022-05-25 08:30:55 +00:00
/**
* The prefix to use with controller messages .
*
* @ var string
* @ since 1.6
*/
2021-03-05 03:08:47 +00:00
protected $text_prefix = 'COM_COMPONENTBUILDER_COMPILER' ;
2022-05-25 08:30:55 +00:00
2021-03-05 03:08:47 +00:00
/**
* Proxy for getModel .
2024-03-02 20:10:30 +00:00
* @ since 2.5
2021-03-05 03:08:47 +00:00
*/
2024-03-02 20:10:30 +00:00
public function getModel ( $name = 'Compiler' , $prefix = 'ComponentbuilderModel' , $config = [])
2021-03-05 03:08:47 +00:00
{
$model = parent :: getModel ( $name , $prefix , array ( 'ignore_request' => true ));
return $model ;
}
2022-05-25 08:30:55 +00:00
public function dashboard ()
2021-03-05 03:08:47 +00:00
{
2024-03-02 20:10:30 +00:00
$this -> setRedirect ( Route :: _ ( 'index.php?option=com_componentbuilder' , false ));
2021-03-05 03:08:47 +00:00
return ;
2017-02-02 11:54:07 +00:00
}
2021-02-19 23:53:14 +00:00
/**
* get all the animations used in the compiler
*
* @ return true on success
*/
2022-10-20 14:40:18 +00:00
public function getDynamicContent ()
2021-02-19 23:53:14 +00:00
{
// Check for request forgeries
2024-03-02 20:10:30 +00:00
Session :: checkToken () or jexit ( Text :: _ ( 'JINVALID_TOKEN' ));
2021-02-19 23:53:14 +00:00
// check if user has the right
2024-03-02 20:10:30 +00:00
$user = Factory :: getUser ();
2021-02-19 23:53:14 +00:00
// set page redirect
2024-03-02 20:10:30 +00:00
$redirect_url = Route :: _ ( 'index.php?option=com_componentbuilder&view=compiler' , false );
$message = Text :: _ ( 'COM_COMPONENTBUILDER_YOU_DO_NOT_HAVE_PERMISSION_TO_DOWNLOAD_THE_COMPILER_ANIMATIONS' );
2021-04-26 13:54:43 +00:00
// currently only those with permissions can get these images
2021-02-19 23:53:14 +00:00
if ( $user -> authorise ( 'compiler.compiler_animations' , 'com_componentbuilder' ))
{
// get the model
$model = $this -> getModel ( 'compiler' );
2022-10-20 14:40:18 +00:00
if ( $model -> getDynamicContent ( $message ))
2021-02-19 23:53:14 +00:00
{
2024-03-02 20:10:30 +00:00
$message = Text :: _ ( 'COM_COMPONENTBUILDER_BALL_THE_COMPILER_ANIMATIONS_WERE_SUCCESSFULLY_DOWNLOADED_TO_THIS_JOOMLA_INSTALLB' );
2021-02-19 23:53:14 +00:00
$this -> setRedirect ( $redirect_url , $message , 'message' );
return true ;
}
}
$this -> setRedirect ( $redirect_url , $message , 'error' );
return false ;
}
2018-09-20 19:17:07 +00:00
/**
* Run the Compiler
*
* @ return true on success
*/
2016-01-30 20:28:43 +00:00
public function compiler ()
{
// Check for request forgeries
2024-03-02 20:10:30 +00:00
Session :: checkToken () or jexit ( Text :: _ ( 'JINVALID_TOKEN' ));
2016-01-30 20:28:43 +00:00
// check if user has the right
2024-03-02 20:10:30 +00:00
$user = Factory :: getUser ();
2021-04-26 13:54:43 +00:00
// currently only those with admin access can compile a component
if ( $user -> authorise ( 'core.manage' , 'com_componentbuilder' ))
2016-01-30 20:28:43 +00:00
{
2017-02-02 11:54:07 +00:00
// include component compiler
require_once JPATH_ADMINISTRATOR . '/components/com_componentbuilder/helpers/compiler.php' ;
2018-04-18 19:11:14 +00:00
$model = $this -> getModel ( 'compiler' );
2022-08-30 15:28:41 +00:00
if ( $model -> builder ())
2016-01-30 20:28:43 +00:00
{
2024-03-02 20:10:30 +00:00
$cache = Factory :: getCache ( 'mod_menu' );
2016-01-30 20:28:43 +00:00
$cache -> clean ();
// TODO: Reset the users acl here as well to kill off any missing bits
}
else
{
return false ;
}
2020-12-25 21:16:34 +00:00
// switch to set multi install button
$add_multi_install = false ;
$add_plugin_install = false ;
$add_module_install = false ;
// get application
2024-03-02 20:10:30 +00:00
$app = Factory :: getApplication ();
2020-12-25 21:16:34 +00:00
// set redirection URL
2018-04-18 19:11:14 +00:00
$redirect_url = $app -> getUserState ( 'com_componentbuilder.redirect_url' );
2020-12-25 21:16:34 +00:00
// get system messages
2018-04-18 19:11:14 +00:00
$message = $app -> getUserState ( 'com_componentbuilder.message' );
2022-08-30 15:28:41 +00:00
if ( empty ( $redirect_url ) && CFactory :: _ ( 'Config' ) -> component_id > 0 )
2016-01-30 20:28:43 +00:00
{
2020-12-25 21:16:34 +00:00
// start new message
$message = array ();
// update the redirection URL
2024-03-02 20:10:30 +00:00
$redirect_url = Route :: _ ( 'index.php?option=com_componentbuilder&view=compiler' , false );
2019-08-08 15:35:58 +00:00
if (( $pos = strpos ( $model -> compiler -> filepath [ 'component' ], " /tmp/ " )) !== FALSE )
2016-01-30 20:28:43 +00:00
{
2024-03-04 06:54:03 +00:00
$url = \JUri :: root () . substr ( $model -> compiler -> filepath [ 'component' ], $pos + 1 );
2016-01-30 20:28:43 +00:00
}
2019-08-12 21:30:31 +00:00
// check if we have plugins
2023-10-18 07:26:30 +00:00
$add_plugin_install = UtilitiesArrayHelper :: check ( $model -> compiler -> filepath [ 'plugins' ], true );
2020-12-25 21:16:34 +00:00
// check if we have modules
2023-10-18 07:26:30 +00:00
$add_module_install = UtilitiesArrayHelper :: check ( $model -> compiler -> filepath [ 'modules' ], true );
2020-12-25 21:16:34 +00:00
// if a multi install we set another kind of header
if ( $add_plugin_install || $add_module_install )
2019-08-12 21:30:31 +00:00
{
2020-12-25 21:16:34 +00:00
// Message of successful builds
$message [] = '<h1>The Extensions were Successfully Compiled!</h1>' ;
$message [] = '<h4>You can install any one of the following extensions!</h4>' ;
// set multi install
$add_multi_install = true ;
2019-08-12 21:30:31 +00:00
}
else
{
// Message of successful build
2020-12-25 21:16:34 +00:00
$message [] = '<h1>The (' . $model -> compiler -> filepath [ 'component-folder' ] . ') was Successfully Compiled!</h1>' ;
2019-08-12 21:30:31 +00:00
}
2024-03-02 20:10:30 +00:00
if ( CFactory :: _ ( 'Config' ) -> joomla_version == Version :: MAJOR_VERSION )
2019-12-06 05:31:32 +00:00
{
2024-03-02 20:10:30 +00:00
$message [] = '<p><button class="btn btn-small btn-success" onclick="Joomla.submitbutton(\'compiler.installCompiledComponent\')">' ;
$message [] = 'Install ' . $model -> compiler -> filepath [ 'component-folder' ] . ' on this <span class="icon-joomla icon-white"></span>Joomla website. (component)</button></p>' ;
// check if we have modules
if ( $add_module_install )
2019-12-06 05:31:32 +00:00
{
2024-03-02 20:10:30 +00:00
foreach ( $model -> compiler -> filepath [ 'modules-folder' ] as $module_id => $module_folder )
{
$message [] = '<p><button class="btn btn-small btn-success" onclick="Joomla.submitbutton(\'compiler.installCompiledModule\', ' . ( int ) $module_id . ')">' ;
$message [] = 'Install ' . $module_folder . ' on this <span class="icon-joomla icon-white"></span>Joomla website. (module)</button></p>' ;
}
2019-12-06 05:31:32 +00:00
}
2024-03-02 20:10:30 +00:00
// check if we have plugins
if ( $add_plugin_install )
2019-08-12 21:30:31 +00:00
{
2024-03-02 20:10:30 +00:00
foreach ( $model -> compiler -> filepath [ 'plugins-folder' ] as $plugin_id => $plugin_folder )
{
$message [] = '<p><button class="btn btn-small btn-success" onclick="Joomla.submitbutton(\'compiler.installCompiledPlugin\', ' . ( int ) $plugin_id . ')">' ;
$message [] = 'Install ' . $plugin_folder . ' on this <span class="icon-joomla icon-white"></span>Joomla website. (plugin)</button></p>' ;
}
}
// set multi install button
if ( $add_multi_install )
{
$message [] = '<h4>You can install all compiled extensions!</h4>' ;
$message [] = '<p><button class="btn btn-small btn-success" onclick="Joomla.submitbutton(\'compiler.installCompiledExtensions\')">' ;
$message [] = 'Install all above extensions on this <span class="icon-joomla icon-white"></span>Joomla! website.</button></p>' ;
2019-08-12 21:30:31 +00:00
}
}
2020-12-25 21:16:34 +00:00
$message [] = '<h2>Total time saved</h2>' ;
$message [] = '<ul>' ;
2023-01-22 00:38:21 +00:00
$message [] = '<li>Total folders created: <b>#' . '##FOLDER_COUNT##' . '#</b></li>' ;
$message [] = '<li>Total files created: <b>#' . '##FILE_COUNT##' . '#</b></li>' ;
$message [] = '<li>Total fields created: <b>#' . '##FIELD_COUNT##' . '#</b></li>' ;
$message [] = '<li>Total lines written: <b>#' . '##LINE_COUNT##' . '#</b></li>' ;
$message [] = '<li>A4 Book of: <b>#' . '##PAGE_COUNT##' . '# pages</b></li>' ;
2020-12-25 21:16:34 +00:00
$message [] = '</ul>' ;
2023-01-22 00:38:21 +00:00
$message [] = '<p><b>#' . '##totalHours##' . '# Hours</b> or <b>#' . '##totalDays##' . '# Eight Hour Days</b> <em>(actual time you saved)</em><br />' ;
2020-12-25 21:16:34 +00:00
$message [] = '<small>(if creating a folder and file took <b>5 seconds</b> and writing one line of code took <b>10 seconds</b>, never making one mistake or taking any coffee break.)</small><br />' ;
2023-01-22 00:38:21 +00:00
$message [] = '<b>#' . '##actualHoursSpent##' . '# Hours</b> or <b>#' . '##actualDaysSpent##' . '# Eight Hour Days</b> <em>(the actual time you spent)</em><br />' ;
$message [] = '<small>(with the following break down: <b>debugging @#' . '##debuggingHours##' . '#hours</b> = codingtime / 4; <b>planning @#' . '##planningHours##' . '#hours</b> = codingtime / 7; <b>mapping @#' . '##mappingHours##' . '#hours</b> = codingtime / 10; <b>office @#' . '##officeHours##' . '#hours</b> = codingtime / 6;)</small></p>' ;
$message [] = '<p><b>#' . '##actualTotalHours##' . '# Hours</b> or <b>#' . '##actualTotalDays##' . '# Eight Hour Days</b> <em>(a total of the realistic time frame for this project)</em><br />' ;
2020-12-25 21:16:34 +00:00
$message [] = '<small>(if creating a folder and file took <b>5 seconds</b> and writing one line of code took <b>10 seconds</b>, with the normal everyday realities at the office, that includes the component planning, mapping & debugging.)</small></p>' ;
2023-01-22 00:38:21 +00:00
$message [] = '<p>Project duration: <b>' . $model -> compiler -> projectWeekTime . ' weeks</b> or <b>#' . '##projectMonthTime##' . '# months</b></p>' ;
2019-12-06 05:31:32 +00:00
// check if we have modules or plugins
2020-12-25 21:16:34 +00:00
if ( $add_multi_install )
2019-08-12 21:30:31 +00:00
{
2020-12-25 21:16:34 +00:00
$message [] = '<h2>Path to Zip Files</h2>' ;
$message [] = '<p><b>Component Path:</b> <code>' . $model -> compiler -> filepath [ 'component' ] . '</code><br />' ;
$message [] = '<b>Component URL:</b> <code>' . $url . '</code><br /><br />' ;
2019-12-06 05:31:32 +00:00
// load modules if found
2020-12-25 21:16:34 +00:00
if ( $add_module_install )
2019-08-12 21:30:31 +00:00
{
2019-12-06 05:31:32 +00:00
$module_urls = array ();
// load the modules path/url
foreach ( $model -> compiler -> filepath [ 'modules' ] as $module_id => $module_path )
2019-08-12 21:30:31 +00:00
{
2019-12-06 05:31:32 +00:00
// set module path
2020-12-25 21:16:34 +00:00
$message [] = '<b>Module Path:</b> <code>' . $module_path . '</code><br />' ;
2019-12-06 05:31:32 +00:00
if (( $pos = strpos ( $module_path , " /tmp/ " )) !== FALSE )
{
2024-03-04 06:54:03 +00:00
$module_urls [ $module_id ] = \JUri :: root () . substr ( $module_path , $pos + 1 );
2020-12-25 21:16:34 +00:00
$message [] = '<b>Module URL:</b> <code>' . $module_urls [ $module_id ] . '</code><br />' ;
}
}
}
// load plugins if found
if ( $add_plugin_install )
{
$plugin_urls = array ();
// load the plugins path/url
foreach ( $model -> compiler -> filepath [ 'plugins' ] as $plugin_id => $plugin_path )
{
// set plugin path
$message [] = '<b>Plugin Path:</b> <code>' . $plugin_path . '</code><br />' ;
if (( $pos = strpos ( $plugin_path , " /tmp/ " )) !== FALSE )
{
2024-03-04 06:54:03 +00:00
$plugin_urls [ $plugin_id ] = \JUri :: root () . substr ( $plugin_path , $pos + 1 );
2020-12-25 21:16:34 +00:00
$message [] = '<b>Plugin URL:</b> <code>' . $plugin_urls [ $plugin_id ] . '</code><br />' ;
2019-12-06 05:31:32 +00:00
}
2019-08-12 21:30:31 +00:00
}
}
2020-12-25 21:16:34 +00:00
$message [] = '<br /><small>Hey! you can also download these zip files right now!</small><br />' ;
$message [] = '<a class="btn btn-success" href="' . $url . '" ><span class="icon-download icon-white"></span>Download Component</a> ' ;
2019-12-06 05:31:32 +00:00
// load the module download URL's
2023-10-18 07:26:30 +00:00
if ( isset ( $module_urls ) && UtilitiesArrayHelper :: check ( $module_urls ))
2019-12-06 05:31:32 +00:00
{
foreach ( $module_urls as $module_id => $module_url )
{
2020-12-25 21:16:34 +00:00
$message [] = ' <a class="btn btn-success" href="' . $module_url . '" >' ;
$message [] = '<span class="icon-download icon-white"></span>Download ' . $model -> compiler -> filepath [ 'modules-folder' ][ $module_id ] . '</a> ' ;
2019-12-06 05:31:32 +00:00
}
}
2019-08-12 21:30:31 +00:00
// load the plugin download URL's
2023-10-18 07:26:30 +00:00
if ( isset ( $plugin_urls ) && UtilitiesArrayHelper :: check ( $plugin_urls ))
2019-08-12 21:30:31 +00:00
{
2019-12-06 05:31:32 +00:00
foreach ( $plugin_urls as $plugin_id => $plugin_url )
{
2020-12-25 21:16:34 +00:00
$message [] = ' <a class="btn btn-success" href="' . $plugin_url . '" >' ;
$message [] = '<span class="icon-download icon-white"></span>Download ' . $model -> compiler -> filepath [ 'plugins-folder' ][ $plugin_id ] . '</a> ' ;
2019-12-06 05:31:32 +00:00
}
2019-08-12 21:30:31 +00:00
}
2020-12-25 21:16:34 +00:00
$message [] = '</p>' ;
$message [] = '<p><small><b>Remember!</b> These zip files are in your tmp folder and therefore publicly accessible until you click [Clear tmp]!</small></p>' ;
2019-08-12 21:30:31 +00:00
}
else
{
2020-12-25 21:16:34 +00:00
$message [] = '<h2>Path to Zip File</h2>' ;
$message [] = '<p><b>Path:</b> <code>' . $model -> compiler -> filepath [ 'component' ] . '</code><br />' ;
$message [] = '<b>URL:</b> <code>' . $url . '</code><br /><br />' ;
$message [] = '<small>Hey! you can also download the zip file right now!</small><br />' ;
$message [] = '<a class="btn btn-success" href="' . $url . '" ><span class="icon-download icon-white"></span>Download</a></p>' ;
$message [] = '<p><small><b>Remember!</b> This zip file is in your tmp folder and therefore publicly accessible until you click [Clear tmp]!</small> </p>' ;
2019-08-12 21:30:31 +00:00
}
2023-01-22 00:38:21 +00:00
$message [] = '<p><small>Compilation took <b>#' . '##COMPILER_TIMER##' . '#</b> seconds to complete.</small> </p>' ;
2021-03-04 06:13:05 +00:00
// pass the message via the user state... wow this is painful
2023-01-22 00:38:21 +00:00
$app -> setUserState ( 'com_componentbuilder.success_message' ,
CFactory :: _ ( 'Placeholder' ) -> update (
implode ( PHP_EOL , $message ),
2023-10-18 07:26:30 +00:00
CFactory :: _ ( 'Compiler.Builder.Content.One' ) -> allActive ()
2023-01-22 00:38:21 +00:00
)
);
2016-01-30 20:28:43 +00:00
// set redirect
2021-03-04 06:13:05 +00:00
$this -> setRedirect ( $redirect_url , '<h2>Successful Build!</h2>' , 'message' );
2019-08-12 21:30:31 +00:00
$app -> setUserState ( 'com_componentbuilder.component_folder_name' , $model -> compiler -> filepath [ 'component-folder' ]);
2019-12-06 05:31:32 +00:00
// check if we have modules
2020-12-25 21:16:34 +00:00
if ( $add_module_install )
2019-12-06 05:31:32 +00:00
{
$app -> setUserState ( 'com_componentbuilder.modules_folder_name' , $model -> compiler -> filepath [ 'modules-folder' ]);
}
2019-08-12 21:30:31 +00:00
// check if we have plugins
2020-12-25 21:16:34 +00:00
if ( $add_plugin_install )
2019-08-12 21:30:31 +00:00
{
$app -> setUserState ( 'com_componentbuilder.plugins_folder_name' , $model -> compiler -> filepath [ 'plugins-folder' ]);
}
2016-01-30 20:28:43 +00:00
}
else
{
// wipe out the user state when we're going to redirect
$app -> setUserState ( 'com_componentbuilder.redirect_url' , '' );
$app -> setUserState ( 'com_componentbuilder.message' , '' );
$app -> setUserState ( 'com_componentbuilder.extension_message' , '' );
2019-08-12 21:30:31 +00:00
$app -> setUserState ( 'com_componentbuilder.component_folder_name' , '' );
2019-12-06 05:31:32 +00:00
$app -> setUserState ( 'com_componentbuilder.modules_folder_name' , '' );
2019-08-12 21:30:31 +00:00
$app -> setUserState ( 'com_componentbuilder.plugins_folder_name' , '' );
2021-03-04 06:13:05 +00:00
$app -> setUserState ( 'com_componentbuilder.success_message' , '' );
2016-01-30 20:28:43 +00:00
// set redirect
2019-08-12 21:30:31 +00:00
$this -> setRedirect ( $redirect_url , $message );
2016-01-30 20:28:43 +00:00
}
return true ;
}
return false ;
}
2018-09-20 19:17:07 +00:00
/**
2019-08-12 21:30:31 +00:00
* Install All Compiled Extensions
2018-09-20 19:17:07 +00:00
*
* @ return true on success
*/
2019-08-12 21:30:31 +00:00
public function installCompiledExtensions ()
2016-01-30 20:28:43 +00:00
{
// Check for request forgeries
2024-03-02 20:10:30 +00:00
Session :: checkToken () or jexit ( Text :: _ ( 'JINVALID_TOKEN' ));
2016-01-30 20:28:43 +00:00
// check if user has the right
2024-03-02 20:10:30 +00:00
$user = Factory :: getUser ();
2016-01-30 20:28:43 +00:00
// set page redirect
2024-03-02 20:10:30 +00:00
$redirect_url = Route :: _ ( 'index.php?option=com_componentbuilder&view=compiler' , false );
$message = Text :: _ ( 'COM_COMPONENTBUILDER_YOU_DO_NOT_HAVE_PERMISSION_TO_INSTALL_THESE_EXTENSIONS' );
2021-04-26 13:54:43 +00:00
// currently only those with admin access can install a component via JCB
if ( $user -> authorise ( 'core.manage' ))
2016-01-30 20:28:43 +00:00
{
2024-03-02 20:10:30 +00:00
$message = Text :: _ ( 'COM_COMPONENTBUILDER_COULD_NOT_INSTALL_EXTENSIONS' );
2019-08-12 21:30:31 +00:00
$_message = array ( 'success' => array (), 'error' => array ());
2024-03-02 20:10:30 +00:00
$app = Factory :: getApplication ();
2019-12-06 05:31:32 +00:00
// start file name array
$fileNames = array ();
2019-08-12 21:30:31 +00:00
$fileNames [] = $app -> getUserState ( 'com_componentbuilder.component_folder_name' , null );
2019-12-06 05:31:32 +00:00
// check if we have modules
2023-10-18 07:26:30 +00:00
$fileNames = UtilitiesArrayHelper :: merge ( array ( $fileNames , $app -> getUserState ( 'com_componentbuilder.modules_folder_name' , array ()) ));
2019-12-06 05:31:32 +00:00
// check if we have plugins
2023-10-18 07:26:30 +00:00
$fileNames = UtilitiesArrayHelper :: merge ( array ( $fileNames , $app -> getUserState ( 'com_componentbuilder.plugins_folder_name' , array ()) ));
2019-12-13 03:58:41 +00:00
// wipe out the user c-m-p since we are done with them all
$app -> setUserState ( 'com_componentbuilder.component_folder_name' , '' );
$app -> setUserState ( 'com_componentbuilder.modules_folder_name' , '' );
$app -> setUserState ( 'com_componentbuilder.plugins_folder_name' , '' );
2021-03-04 06:13:05 +00:00
$app -> setUserState ( 'com_componentbuilder.success_message' , '' );
2019-12-13 03:58:41 +00:00
2019-12-06 05:31:32 +00:00
// loop and install all extensions found
2019-08-12 21:30:31 +00:00
foreach ( $fileNames as $fileName )
{
if ( $this -> installExtension ( $fileName ))
{
2024-03-02 20:10:30 +00:00
$_message [ 'success' ][] = Text :: sprintf ( 'COM_COMPONENTBUILDER_SZIP_WAS_REMOVED_THE_FROM_TMP_FOLDER_DURING_INSTALLATION' , $fileName );
2019-08-12 21:30:31 +00:00
}
else
{
2024-03-02 20:10:30 +00:00
$_message [ 'error' ][] = Text :: sprintf ( 'COM_COMPONENTBUILDER_SZIP_COULD_NOT_BE_INSTALLED' , $fileName );
2019-08-12 21:30:31 +00:00
}
}
// catch errors
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $_message [ 'error' ]))
2019-08-12 21:30:31 +00:00
{
$app -> enqueueMessage ( implode ( '<br />' , $_message [ 'error' ]), 'Error' );
}
// build success message
2023-10-18 07:26:30 +00:00
if ( UtilitiesArrayHelper :: check ( $_message [ 'success' ]))
2019-08-12 21:30:31 +00:00
{
$this -> setRedirect ( $redirect_url , implode ( '<br />' , $_message [ 'success' ]), 'message' );
return true ;
}
}
$this -> setRedirect ( $redirect_url , $message , 'error' );
return false ;
}
/**
* Install Compiled Component
*
* @ return true on success
*/
public function installCompiledComponent ()
{
// Check for request forgeries
2024-03-02 20:10:30 +00:00
Session :: checkToken () or jexit ( Text :: _ ( 'JINVALID_TOKEN' ));
2019-08-12 21:30:31 +00:00
// check if user has the right
2024-03-02 20:10:30 +00:00
$user = Factory :: getUser ();
2019-08-12 21:30:31 +00:00
// set page redirect
2024-03-02 20:10:30 +00:00
$redirect_url = Route :: _ ( 'index.php?option=com_componentbuilder&view=compiler' , false );
$message = Text :: _ ( 'COM_COMPONENTBUILDER_YOU_DO_NOT_HAVE_PERMISSION_TO_INSTALL_THE_COMPONENT' );
2021-04-26 13:54:43 +00:00
// currently only those with admin access can install a component via JCB
if ( $user -> authorise ( 'core.manage' ))
2019-08-12 21:30:31 +00:00
{
2024-03-02 20:10:30 +00:00
$message = Text :: _ ( 'COM_COMPONENTBUILDER_COULD_NOT_INSTALL_COMPONENT' );
$app = Factory :: getApplication ();
2019-12-13 03:58:41 +00:00
$fileName = $app -> getUserState ( 'com_componentbuilder.component_folder_name' );
// wipe out the user c-m-p since we are done with them all
$app -> setUserState ( 'com_componentbuilder.component_folder_name' , '' );
$app -> setUserState ( 'com_componentbuilder.modules_folder_name' , '' );
$app -> setUserState ( 'com_componentbuilder.plugins_folder_name' , '' );
2021-03-04 06:13:05 +00:00
$app -> setUserState ( 'com_componentbuilder.success_message' , '' );
2019-12-13 03:58:41 +00:00
2019-08-12 21:30:31 +00:00
if ( $this -> installExtension ( $fileName ))
{
2024-03-02 20:10:30 +00:00
$message = Text :: sprintf ( 'COM_COMPONENTBUILDER_ONLY_SZIP_FILE_WAS_REMOVED_THE_FROM_TMP_FOLDER_DURING_INSTALLATION' , $fileName );
2019-08-12 21:30:31 +00:00
$this -> setRedirect ( $redirect_url , $message , 'message' );
return true ;
}
}
$this -> setRedirect ( $redirect_url , $message , 'error' );
2019-12-06 05:31:32 +00:00
return false ;
}
/**
* Install Compiled Module
*
* @ return true on success
*/
public function installCompiledModule ()
{
// Check for request forgeries
2024-03-02 20:10:30 +00:00
Session :: checkToken () or jexit ( Text :: _ ( 'JINVALID_TOKEN' ));
2019-12-06 05:31:32 +00:00
// check if user has the right
2024-03-02 20:10:30 +00:00
$user = Factory :: getUser ();
2019-12-06 05:31:32 +00:00
// set page redirect
2024-03-02 20:10:30 +00:00
$redirect_url = Route :: _ ( 'index.php?option=com_componentbuilder&view=compiler' , false );
$message = Text :: _ ( 'COM_COMPONENTBUILDER_YOU_DO_NOT_HAVE_PERMISSION_TO_INSTALL_THE_MODULE' );
2021-04-26 13:54:43 +00:00
// currently only those with admin access can install a molule via JCB
if ( $user -> authorise ( 'core.manage' ))
2019-12-06 05:31:32 +00:00
{
2024-03-02 20:10:30 +00:00
$message = Text :: _ ( 'COM_COMPONENTBUILDER_COULD_NOT_INSTALL_MODULE' );
$app = Factory :: getApplication ();
2019-12-06 05:31:32 +00:00
$fileNames = $app -> getUserState ( 'com_componentbuilder.modules_folder_name' );
2019-12-13 03:58:41 +00:00
// wipe out the user c-m-p since we are done with them all
$app -> setUserState ( 'com_componentbuilder.component_folder_name' , '' );
$app -> setUserState ( 'com_componentbuilder.modules_folder_name' , '' );
$app -> setUserState ( 'com_componentbuilder.plugins_folder_name' , '' );
2021-03-04 06:13:05 +00:00
$app -> setUserState ( 'com_componentbuilder.success_message' , '' );
2019-12-13 03:58:41 +00:00
2024-03-02 20:10:30 +00:00
if ( UtilitiesArrayHelper :: check ( $fileNames ))
2019-12-06 05:31:32 +00:00
{
2024-03-02 20:10:30 +00:00
$jinput = Factory :: getApplication () -> input ;
2019-12-06 05:31:32 +00:00
$moduleId = $jinput -> post -> get ( 'install_item_id' , 0 , 'INT' );
if ( $moduleId > 0 && isset ( $fileNames [ $moduleId ]) && $this -> installExtension ( $fileNames [ $moduleId ]))
{
2024-03-02 20:10:30 +00:00
$message = Text :: sprintf ( 'COM_COMPONENTBUILDER_ONLY_SZIP_FILE_WAS_REMOVED_THE_FROM_TMP_FOLDER_DURING_INSTALLATION' , $fileNames [ $moduleId ]);
2019-12-06 05:31:32 +00:00
$this -> setRedirect ( $redirect_url , $message , 'message' );
return true ;
}
}
}
$this -> setRedirect ( $redirect_url , $message , 'error' );
2019-08-12 21:30:31 +00:00
return false ;
}
/**
* Install Compiled Plugin
*
* @ return true on success
*/
public function installCompiledPlugin ()
{
// Check for request forgeries
2024-03-02 20:10:30 +00:00
Session :: checkToken () or jexit ( Text :: _ ( 'JINVALID_TOKEN' ));
2019-08-12 21:30:31 +00:00
// check if user has the right
2024-03-02 20:10:30 +00:00
$user = Factory :: getUser ();
2019-08-12 21:30:31 +00:00
// set page redirect
2024-03-02 20:10:30 +00:00
$redirect_url = Route :: _ ( 'index.php?option=com_componentbuilder&view=compiler' , false );
$message = Text :: _ ( 'COM_COMPONENTBUILDER_YOU_DO_NOT_HAVE_PERMISSION_TO_INSTALL_THE_PLUGIN' );
2021-04-26 13:54:43 +00:00
// currently only those with admin access can install a plugin via JCB
if ( $user -> authorise ( 'core.manage' ))
2019-08-12 21:30:31 +00:00
{
2024-03-02 20:10:30 +00:00
$message = Text :: _ ( 'COM_COMPONENTBUILDER_COULD_NOT_INSTALL_PLUGIN' );
$app = Factory :: getApplication ();
2019-08-12 21:30:31 +00:00
$fileNames = $app -> getUserState ( 'com_componentbuilder.plugins_folder_name' );
2019-12-13 03:58:41 +00:00
// wipe out the user c-m-p since we are done with them all
$app -> setUserState ( 'com_componentbuilder.component_folder_name' , '' );
$app -> setUserState ( 'com_componentbuilder.modules_folder_name' , '' );
$app -> setUserState ( 'com_componentbuilder.plugins_folder_name' , '' );
2021-03-04 06:13:05 +00:00
$app -> setUserState ( 'com_componentbuilder.success_message' , '' );
2019-12-13 03:58:41 +00:00
2024-03-02 20:10:30 +00:00
if ( UtilitiesArrayHelper :: check ( $fileNames ))
2016-01-30 20:28:43 +00:00
{
2024-03-02 20:10:30 +00:00
$jinput = Factory :: getApplication () -> input ;
2019-08-12 21:30:31 +00:00
$pluginId = $jinput -> post -> get ( 'install_item_id' , 0 , 'INT' );
if ( $pluginId > 0 && isset ( $fileNames [ $pluginId ]) && $this -> installExtension ( $fileNames [ $pluginId ]))
{
2024-03-02 20:10:30 +00:00
$message = Text :: sprintf ( 'COM_COMPONENTBUILDER_ONLY_SZIP_FILE_WAS_REMOVED_THE_FROM_TMP_FOLDER_DURING_INSTALLATION' , $fileNames [ $pluginId ]);
2019-08-12 21:30:31 +00:00
$this -> setRedirect ( $redirect_url , $message , 'message' );
return true ;
}
2016-01-30 20:28:43 +00:00
}
}
2019-08-12 21:30:31 +00:00
$this -> setRedirect ( $redirect_url , $message , 'error' );
return false ;
}
/**
* Install Extension
*
* @ return true on success
*/
protected function installExtension ( $fileName )
{
// check that the model is set
if ( ! isset ( $this -> _compiler_model ))
{
// get the compiler model
$this -> _compiler_model = $this -> getModel ( 'compiler' );
}
// set the language if not set
if ( ! isset ( $this -> _installer_lang ))
{
2024-03-02 20:10:30 +00:00
$this -> _installer_lang = Factory :: getLanguage ();
2019-08-12 21:30:31 +00:00
$extension = 'com_installer' ;
$base_dir = JPATH_ADMINISTRATOR ;
$language_tag = 'en-GB' ;
$reload = true ;
$this -> _installer_lang -> load ( $extension , $base_dir , $language_tag , $reload );
}
// make sure we have a string
2024-03-02 20:10:30 +00:00
if ( StringHelper :: check ( $fileName ))
2019-08-12 21:30:31 +00:00
{
return $this -> _compiler_model -> install ( $fileName . '.zip' );
}
2016-01-30 20:28:43 +00:00
return false ;
}
2019-05-15 17:39:27 +00:00
/**
* Run the Expansion
*
* @ return void
*/
public function runExpansion ()
{
// Check for request forgeries
2024-03-02 20:10:30 +00:00
Session :: checkToken () or jexit ( Text :: _ ( 'JINVALID_TOKEN' ));
2019-05-15 17:39:27 +00:00
// check if user has the right
2024-03-02 20:10:30 +00:00
$user = Factory :: getUser ();
2019-05-15 17:39:27 +00:00
// set page redirect
$redirect_url = JRoute :: _ ( 'index.php?option=com_componentbuilder&view=compiler' , false );
// set massage
2024-03-02 20:10:30 +00:00
$message = Text :: _ ( 'COM_COMPONENTBUILDER_YOU_DO_NOT_HAVE_PERMISSION_TO_RUN_THE_EXPANSION_MODULE' );
2019-05-15 17:39:27 +00:00
// check if this user has the right to run expansion
if ( $user -> authorise ( 'compiler.run_expansion' , 'com_componentbuilder' ))
{
// set massage
2024-03-02 20:10:30 +00:00
$message = Text :: _ ( 'COM_COMPONENTBUILDER_EXPANSION_FAILED_PLEASE_CHECK_YOUR_SETTINGS_IN_THE_GLOBAL_OPTIONS_OF_JCB_UNDER_THE_DEVELOPMENT_METHOD_TAB' );
2019-05-15 17:39:27 +00:00
// run expansion via API
2024-03-04 06:54:03 +00:00
$result = ComponentbuilderHelper :: getFileContents ( \JUri :: root () . 'index.php?option=com_componentbuilder&task=api.expand' );
2019-05-15 17:39:27 +00:00
// is there a message returned
2023-10-18 07:26:30 +00:00
if ( ! is_numeric ( $result ) && StringHelper :: check ( $result ))
2019-05-15 17:39:27 +00:00
{
$this -> setRedirect ( $redirect_url , $result );
return true ;
}
elseif ( is_numeric ( $result ) && 1 == $result )
{
2024-03-02 20:10:30 +00:00
$message = Text :: _ ( 'COM_COMPONENTBUILDER_BTHE_EXPANSION_WAS_SUCCESSFULLYB_TO_SEE_MORE_INFORMATION_CHANGE_THE_BRETURN_OPTIONS_FOR_BUILDB_TO_BDISPLAY_MESSAGEB_IN_THE_GLOBAL_OPTIONS_OF_JCB_UNDER_THE_DEVELOPMENT_METHOD_TABB' );
2019-05-15 17:39:27 +00:00
$this -> setRedirect ( $redirect_url , $message , 'message' );
return true ;
}
}
$this -> setRedirect ( $redirect_url , $message , 'error' );
return false ;
}
/**
* Clear tmp folder
*
* @ return true on success
*/
public function clearTmp ()
{
// Check for request forgeries
2024-03-02 20:10:30 +00:00
Session :: checkToken () or jexit ( Text :: _ ( 'JINVALID_TOKEN' ));
2019-05-15 17:39:27 +00:00
// check if user has the right
2024-03-02 20:10:30 +00:00
$user = Factory :: getUser ();
2019-05-15 17:39:27 +00:00
// set page redirect
2024-03-02 20:10:30 +00:00
$redirect_url = Route :: _ ( 'index.php?option=com_componentbuilder&view=compiler' , false );
$message = Text :: _ ( 'COM_COMPONENTBUILDER_COULD_NOT_CLEAR_THE_TMP_FOLDER' );
2021-04-26 13:54:43 +00:00
if ( $user -> authorise ( 'compiler.clear_tmp' , 'com_componentbuilder' ) && $user -> authorise ( 'core.manage' , 'com_componentbuilder' ))
2019-05-15 17:39:27 +00:00
{
// get the model
$model = $this -> getModel ( 'compiler' );
// get tmp folder
2024-03-02 20:10:30 +00:00
$comConfig = Factory :: getConfig ();
2019-05-15 17:39:27 +00:00
$tmp = $comConfig -> get ( 'tmp_path' );
if ( $model -> emptyFolder ( $tmp ))
{
2024-03-02 20:10:30 +00:00
$message = Text :: _ ( 'COM_COMPONENTBUILDER_BTHE_TMP_FOLDER_HAS_BEEN_CLEAR_SUCCESSFULLYB' );
2019-05-15 17:39:27 +00:00
$this -> setRedirect ( $redirect_url , $message , 'message' );
2021-03-04 06:13:05 +00:00
// get application
2024-03-02 20:10:30 +00:00
$app = Factory :: getApplication ();
2021-03-04 06:13:05 +00:00
// wipe out the user c-m-p since we are done with them all
$app -> setUserState ( 'com_componentbuilder.component_folder_name' , '' );
$app -> setUserState ( 'com_componentbuilder.modules_folder_name' , '' );
$app -> setUserState ( 'com_componentbuilder.plugins_folder_name' , '' );
$app -> setUserState ( 'com_componentbuilder.success_message' , '' );
2019-05-15 17:39:27 +00:00
return true ;
}
}
$this -> setRedirect ( $redirect_url , $message , 'error' );
return false ;
}
/**
* Run the Translator
*
* @ return void
*/
public function runTranslator ()
{
// Check for request forgeries
2024-03-02 20:10:30 +00:00
Session :: checkToken () or jexit ( Text :: _ ( 'JINVALID_TOKEN' ));
2019-05-15 17:39:27 +00:00
// check if user has the right
2024-03-02 20:10:30 +00:00
$user = Factory :: getUser ();
2019-05-15 17:39:27 +00:00
// set page redirect
2024-03-02 20:10:30 +00:00
$redirect_url = Route :: _ ( 'index.php?option=com_componentbuilder&view=compiler' , false );
2019-05-15 17:39:27 +00:00
// set massage
2024-03-02 20:10:30 +00:00
$message = Text :: _ ( 'COM_COMPONENTBUILDER_YOU_DO_NOT_HAVE_PERMISSION_TO_RUN_THE_TRANSLATOR_MODULE' );
2019-05-15 17:39:27 +00:00
// check if this user has the right to run expansion
if ( $user -> authorise ( 'compiler.run_translator' , 'com_componentbuilder' ))
{
// set massage
2024-03-02 20:10:30 +00:00
$message = Text :: _ ( 'COM_COMPONENTBUILDER_TRANSLATION_FAILED_SINCE_THERE_ARE_NO_COMPONENTS_LINKED_WITH_TRANSLATION_TOOLS' );
2019-05-15 17:39:27 +00:00
// run translator via API
2024-03-02 20:10:30 +00:00
$result = ComponentbuilderHelper :: getFileContents ( Uri :: root () . 'index.php?option=com_componentbuilder&task=api.translator' );
2019-05-15 17:39:27 +00:00
// is there a message returned
2023-10-18 07:26:30 +00:00
if ( ! is_numeric ( $result ) && StringHelper :: check ( $result ))
2019-05-15 17:39:27 +00:00
{
$this -> setRedirect ( $redirect_url , $result );
return true ;
}
}
$this -> setRedirect ( $redirect_url , $message , 'error' );
return false ;
}
2021-03-05 03:08:47 +00:00
}