* @github Joomla Component Builder * @copyright Copyright (C) 2015 - 2019 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'); /** * Compiler Controller */ class ComponentbuilderControllerCompiler extends JControllerAdmin { protected $text_prefix = 'COM_COMPONENTBUILDER_COMPILER'; /** * Proxy for getModel. * @since 2.5 */ public function getModel($name = 'Compiler', $prefix = 'ComponentbuilderModel', $config = array()) { $model = parent::getModel($name, $prefix, array('ignore_request' => true)); return $model; } public function dashboard() { $this->setRedirect(JRoute::_('index.php?option=com_componentbuilder', false)); return; } /** * Run the Compiler * * @return true on success */ public function compiler() { // Check for request forgeries JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // check if user has the right $user = JFactory::getUser(); if($user->authorise('core.admin', 'com_componentbuilder')) { // get the post values $jinput = JFactory::getApplication()->input; $componentId = $jinput->post->get('component', 0, 'INT'); $version = $jinput->post->get('version', 0, 'INT'); $addBackup = $jinput->post->get('backup', 0, 'INT'); $addRepo = $jinput->post->get('repository', 0, 'INT'); $addPlaceholders = $jinput->post->get('placeholders', 2, 'INT'); $debugLinenr = $jinput->post->get('debuglinenr', 2, 'INT'); $minify = $jinput->post->get('minify', 2, 'INT'); // include component compiler require_once JPATH_ADMINISTRATOR.'/components/com_componentbuilder/helpers/compiler.php'; $model = $this->getModel('compiler'); if ($model->builder($version,$componentId,$addBackup,$addRepo,$addPlaceholders,$debugLinenr, $minify)) { $cache = JFactory::getCache('mod_menu'); $cache->clean(); // TODO: Reset the users acl here as well to kill off any missing bits } else { return false; } $app = JFactory::getApplication(); $redirect_url = $app->getUserState('com_componentbuilder.redirect_url'); $message = $app->getUserState('com_componentbuilder.message'); if (empty($redirect_url) && $componentId > 0) { $redirect_url = JRoute::_('index.php?option=com_componentbuilder&view=compiler', false); if (($pos = strpos($model->compiler->filepath, "/tmp/")) !== FALSE) { $url = JURI::root() . substr($model->compiler->filepath, $pos + 1); } // Message of successful build $message = '

The ('.$model->compiler->componentFolderName.') Was Successfully Compiled!

'; $message .= '

'; $message .= '

Total time saved

'; $message .= ''; $message .= '

'.$model->compiler->totalHours.' Hours or '.$model->compiler->totalDays.' Eight Hour Days (actual time you saved)
'; $message .= '(if creating a folder and file took 5 seconds and writing one line of code took 10 seconds, never making one mistake or taking any coffee break.)
'; $message .= ''.$model->compiler->actualHoursSpent.' Hours or '.$model->compiler->actualDaysSpent.' Eight Hour Days (the actual time you spent)
'; $message .= '(with the following break down: debugging @'.$model->compiler->debuggingHours.'hours = codingtime / 4; planning @'.$model->compiler->planningHours.'hours = codingtime / 7; mapping @'.$model->compiler->mappingHours.'hours = codingtime / 10; office @'.$model->compiler->officeHours.'hours = codingtime / 6;)

'; $message .= '

'.$model->compiler->actualTotalHours.' Hours or '.$model->compiler->actualTotalDays.' Eight Hour Days (a total of the realistic time frame for this project)
'; $message .= '(if creating a folder and file took 5 seconds and writing one line of code took 10 seconds, with the normal everyday realities at the office, that includes the component planning, mapping & debugging.)

'; $message .= '

Project duration: '.$model->compiler->projectWeekTime. ' weeks or '.$model->compiler->projectMonthTime.' months

'; $message .= '

Path to Zip File

'; $message .= '

Path: '.$model->compiler->filepath.'
'; $message .= 'URL: '.$url.'

'; $message .= 'Hey! you can also download the file right now!
Download

'; $message .= '

Remember! This file is in your tmp folder and therefore publicly accessible untill you click [Clear tmp]!

'; $message .= '

Compilation took '.$model->compiler->secondsCompiled.' seconds to complete.

'; // set redirect $this->setRedirect($redirect_url,$message,'message'); $app->setUserState('com_componentbuilder.extension_name', $model->compiler->componentFolderName); } 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', ''); $app->setUserState('com_componentbuilder.extension_name', ''); // set redirect $this->setRedirect($redirect_url,$message); } return true; } return false; } /** * Install Compiled Extension * * @return true on success */ public function installExtention() { // Check for request forgeries JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // check if user has the right $user = JFactory::getUser(); // set page redirect $redirect_url = JRoute::_('index.php?option=com_componentbuilder&view=compiler', false); $message = 'Could not install component!'; if($user->authorise('core.admin')) { // get the model $model = $this->getModel('compiler'); $app = JFactory::getApplication(); $fileName = $app->getUserState('com_componentbuilder.extension_name'); if (ComponentbuilderHelper::checkString($fileName)) { $lang = JFactory::getLanguage(); $extension = 'com_installer'; $base_dir = JPATH_ADMINISTRATOR; $language_tag = 'en-GB'; $reload = true; $lang->load($extension, $base_dir, $language_tag, $reload); $message = '('.$fileName.'.zip) file was also removed from tmp!'; $this->setRedirect($redirect_url,$message,'message'); return $model->install($fileName.'.zip'); } } $this->setRedirect($redirect_url,$message,'error'); return false; } /** * Run the Expansion * * @return void */ public function runExpansion() { // Check for request forgeries JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // check if user has the right $user = JFactory::getUser(); // set page redirect $redirect_url = JRoute::_('index.php?option=com_componentbuilder&view=compiler', false); // set massage $message = JText::_('COM_COMPONENTBUILDER_YOU_DO_NOT_HAVE_PERMISSION_TO_RUN_THE_EXPANSION_MODULE'); // check if this user has the right to run expansion if($user->authorise('compiler.run_expansion', 'com_componentbuilder')) { // set massage $message = JText::_('COM_COMPONENTBUILDER_EXPANSION_FAILED_PLEASE_CHECK_YOUR_SETTINGS_IN_THE_GLOBAL_OPTIONS_OF_JCB_UNDER_THE_DEVELOPMENT_METHOD_TAB'); // run expansion via API $result = ComponentbuilderHelper::getFileContents(JURI::root() . 'index.php?option=com_componentbuilder&task=api.expand'); // is there a message returned if (!is_numeric($result) && ComponentbuilderHelper::checkString($result)) { $this->setRedirect($redirect_url, $result); return true; } elseif (is_numeric($result) && 1 == $result) { $message = JText::_('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'); $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 JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // check if user has the right $user = JFactory::getUser(); // set page redirect $redirect_url = JRoute::_('index.php?option=com_componentbuilder&view=compiler', false); $message = JText::_('COM_COMPONENTBUILDER_COULD_NOT_CLEAR_THE_TMP_FOLDER'); if($user->authorise('compiler.clear_tmp', 'com_componentbuilder') && $user->authorise('core.options', 'com_componentbuilder')) { // get the model $model = $this->getModel('compiler'); // get tmp folder $comConfig = JFactory::getConfig(); $tmp = $comConfig->get('tmp_path'); if ($model->emptyFolder($tmp)) { $message = JText::_('COM_COMPONENTBUILDER_BTHE_TMP_FOLDER_HAS_BEEN_CLEAR_SUCCESSFULLYB'); $this->setRedirect($redirect_url, $message, 'message'); return true; } } $this->setRedirect($redirect_url, $message, 'error'); return false; } /** * Run the Translator * * @return void */ public function runTranslator() { // Check for request forgeries JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // check if user has the right $user = JFactory::getUser(); // set page redirect $redirect_url = JRoute::_('index.php?option=com_componentbuilder&view=compiler', false); // set massage $message = JText::_('COM_COMPONENTBUILDER_YOU_DO_NOT_HAVE_PERMISSION_TO_RUN_THE_TRANSLATOR_MODULE'); // check if this user has the right to run expansion if($user->authorise('compiler.run_translator', 'com_componentbuilder')) { // set massage $message = JText::_('COM_COMPONENTBUILDER_TRANSLATION_FAILED_SINCE_THERE_ARE_NO_COMPONENTS_LINKED_WITH_TRANSLATION_TOOLS'); // run translator via API $result = ComponentbuilderHelper::getFileContents(JURI::root() . 'index.php?option=com_componentbuilder&task=api.translator'); // is there a message returned if (!is_numeric($result) && ComponentbuilderHelper::checkString($result)) { $this->setRedirect($redirect_url, $result); return true; } } $this->setRedirect($redirect_url, $message, 'error'); return false; } }