if (version_compare(PHP_VERSION, '5.3', '<')) { //-- @todo php 5.2 spl_autoload_register('easy_creator_loader', true); } else { spl_autoload_register('easy_creator_loader', true, true); } //-- Load the special Language //-- 1) Check if g11n is installed as a PEAR package - see: http://elkuku.github.com/pear/ //@include 'elkuku/g11n/language.php'; //-- @todo: check for installed g11n PEAR package to remove the "shut-up" //-- @require_once 'elkuku/g11n/language.php'; if (!class_exists('g11n')) { //-- 2) Check the libraries folder if (!jimport('g11n.language')) { //-- 3) Load a dummy language handler -> english only ! ecrLoadHelper('g11n_dummy'); ecrScript('g11n_dummy', 'php2js'); } } if (class_exists('g11n')) { //-- TEMP@@debug if (ECR_DEV_MODE && ECR_DEBUG_LANG) { //-- @@DEBUG g11n::cleanStorage(); g11n::setDebug(ECR_DEBUG_LANG); } //-- Get our special language file g11n::loadLanguage(); } /* * Functions
/** * @version SVN: $Id: easycreator.php 1133 2010-03-24 22:30:26Z elkuku $ * @package EasyCreator * @subpackage Frontend * @author EasyJoomla {@link http://www.easy-joomla.org Easy-Joomla.org} * @author Nikolai Plath (elkuku) {@link http://www.nik-it.de NiK-IT.de} * @author Created on 24-Sep-2008 */ //-- No direct access defined('_JEXEC') or die('=;)'); jimport('joomla.filesystem.file'); // --Global functions require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'functions.php'; //-- Load helpers ecrLoadHelper('project'); ecrLoadHelper('projecthelper'); //-- Global constants require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'defines.php'; $document =& JFactory::getDocument(); //-- Add css $document->addStyleSheet('components/com_easycreator/assets/css/default.css'); //-- Add javascript $document->addScript(JURI::root() . 'components/com_easycreator/assets/js/easycreator.js'); //-- Include standard html JLoader::import('helpers.html', JPATH_COMPONENT); //-- Require the base controller require_once JPATH_COMPONENT . DS . 'controller.php'; $controller = new EasyCreatorController(); easyHTML::start(); //-- Perform the Request task $controller->execute(JRequest::getVar('task'));
/** * Create the zip file. * * @throws EcrExceptionZiper * @return EcrProjectZiper */ private function createArchive() { if (false == $this->validBuild) { return $this; } $zipTypes = array('Zip' => 'zip', 'Tgz' => 'tar.gz', 'Bz2' => 'bz2'); $this->logger->log('Start adding files'); if ($this->build_dir != ECRPATH_BUILDS) { $zipDir = $this->build_dir . DS . $this->project->version; } else { $zipDir = $this->build_dir . DS . $this->project->comName . DS . $this->project->version; } //-- Build the file list $files = JFolder::files($this->temp_dir, '.', true, true); $this->logger->log('TOTAL: ' . count($files) . ' files'); if (false == JFolder::exists($zipDir)) { if (false == JFolder::create($zipDir)) { throw new EcrExceptionZiper(__METHOD__ . ' - ERROR creating folder ' . $zipDir); } } if (0 === strpos($this->project->getZipPath(), ECRPATH_BUILDS)) { $hrefBase = JURI::root() . str_replace(JPATH_ROOT, '', ECRPATH_BUILDS) . '/' . $this->project->comName . '/' . $this->project->version; $hrefBase = str_replace('/\\', '/', $hrefBase); $hrefBase = str_replace('\\', '/', $hrefBase); } else { $hrefBase = 'file://' . $this->project->getZipPath() . DIRECTORY_SEPARATOR . $this->project->version; } $customFileName = EcrProjectHelper::formatFileName($this->project, JFactory::getApplication()->input->getString('cst_format')); $fileName = $this->project->getFileName() . $customFileName; foreach ($zipTypes as $zipType => $ext) { if (false == $this->preset->{'archive' . $zipType}) { continue; } $this->logger->log('creating ' . $zipType); switch ($ext) { case 'zip': //-- Translate win path to unix path - for PEAR.. $p = str_replace('\\', '/', $this->temp_dir); if (false == EcrArchive::createZip($zipDir . DS . $fileName . '.zip', $files, $p)) { throw new EcrExceptionZiper(__METHOD__ . ' - ERROR Packing routine for ' . $ext); } break; case 'bz2': ecrLoadHelper('PEAR'); if (false == extension_loaded('bz2')) { PEAR::loadExtension('bz2'); } if (false == extension_loaded('bz2')) { JFactory::getApplication()->enqueueMessage(jgettext('The extension "bz2" couldn\'t be found.'), 'error'); JFactory::getApplication()->enqueueMessage(jgettext('Please make sure your version of PHP was built with bz2 support.'), 'error'); $this->logger->log('PHP extension bz2 not found', 'PHP ERROR'); } else { //-- Translate win path to unix path - for PEAR.. $p = str_replace('\\', '/', $this->temp_dir); $result = $archive = EcrArchive::createTgz($zipDir . DS . $fileName . '.' . $ext, $files, 'bz2', $p); if (!$result->listContent()) { throw new EcrExceptionZiper(__METHOD__ . 'ERROR Packing routine for ' . $ext); } } break; case 'tar.gz': $result = $archive = EcrArchive::createTgz($zipDir . DS . $fileName . '.' . $ext, $files, 'gz', $this->temp_dir); if (!$result->listContent()) { throw new EcrExceptionZiper(__METHOD__ . 'ERROR Packing routine for ' . $ext); } break; default: throw new EcrExceptionZiper(__METHOD__ . 'undefined packing type ' . $ext); break; } $this->logger->log('Packing routine for ' . $ext . ' finished'); $this->downloadLinks[] = $hrefBase . '/' . $fileName . '.' . $ext; /* $f = new EcrProjectZiperCreatedfile($zipDir.DS.$fileName.'.'.$ext); $this->createdFiles[] = $zipDir.DS.$fileName.'.'.$ext; $f = new EcrProjectZiperCreatedfile($zipDir.DS.$fileName.'.'.$ext); */ $this->createdFiles[] = new EcrProjectZiperCreatedfile($zipDir . DS . $fileName . '.' . $ext, $hrefBase . '/' . $fileName . '.' . $ext); } return $this; }
/** * Displays the actual file and a selected version side by side. * * @param integer $revNo Revision number * @param string $lang Language tag e.g. en-GB * * @return void */ public function displayVersion($revNo, $lang) { $fileName = $this->getFileName($lang, $this->_scope, $this->project); $sRev = '.r' . $revNo; $fileNameOrig = $fileName; $fileNameRev = $fileName . '.r' . $revNo; $fileOrig = ''; $fileRev = ''; if (JFile::exists($fileNameOrig)) { $fileOrig = JFile::read($fileNameOrig); if ($fileOrig) { $fileOrig = explode("\n", $fileOrig); } } if (JFile::exists($fileNameRev)) { $fileRev = JFile::read($fileNameRev); if ($fileRev) { $fileRev = explode("\n", $fileRev); } } ecrLoadHelper('DifferenceEngine'); //--we are adding a blank line to the end.. this is somewhat 'required' by PHPdiff if ($fileOrig[count($fileOrig) - 1] != '') { $fileOrig[] = ''; } if ($fileRev[count($fileRev) - 1] != '') { $fileRev[] = ''; } $dwDiff = new Diff($fileRev, $fileOrig); $dwFormatter = new TableDiffFormatter(); ?> <table class="diff"> <tr> <th colspan="2"><?php echo sprintf(jgettext('Version No. %s'), $revNo); ?> </th> <th colspan="2"><?php echo jgettext('Actual file'); ?> </th> </tr> <?php echo $dwFormatter->format($dwDiff); ?> </table> <?php /* PHP */ ?> <!-- <table width="100%"> <tr> <th><?php echo jgettext('Actual file'); ?> </th> <th><?php echo sprintf(jgettext('Version No. %s'), $revNo); ?> </th> </tr> <tr valign="top"> <?php ?> <td><?php if (!$fileOrig) { echo '<strong style="color: red;">' . jgettext('File not found') . '</strong>'; } else { $this->displayFields($lang, $fileOrig); } ?> </td> <td><?php if (!$fileRev) { echo '<strong style="color: red;">' . jgettext('File not found') . '</strong>'; } else { $this->displayFields($lang, $fileRev); } ?> </td> </tr> </table> --> <?php }
/** * Get a diff table. * * @param string $origCode Original code * @param string $newCode New code * @param boolean $showAll Set true to show all lines | false to show only changed lines * * @return return_type */ public function getDiffTable($origCode, $newCode, $showAll = true) { $codeOrig = explode("\n", htmlentities($origCode)); $codeNew = explode("\n", htmlentities($newCode)); ecrLoadHelper('DifferenceEngine'); //--we are adding a blank line to the end.. this is somewhat 'required' by PHPdiff if ($codeOrig[count($codeOrig) - 1] != '') { $codeOrig[] = ''; } if ($codeNew[count($codeNew) - 1] != '') { $codeNew[] = ''; } $dwDiff = new Diff($codeOrig, $codeNew); $dwFormatter = new TableDiffFormatter(); //-- Small hack to display the whole file - :| if ($showAll) { $dwFormatter->leading_context_lines = 99999; $dwFormatter->trailing_context_lines = 99999; } return $dwFormatter->format($dwDiff); }
/** * Dumps a var with PEAR::Var_Dump. * * @param mixed $var The variable to dump * @param string $title An optional title * * @return void */ public static function varDump($var, $title = '') { echo $title ? '<h3><tt>' . $title . '</tt></h3>' : ''; $debug_type = JComponentHelper::getParams('com_easycreator')->get('ecr_debug_type', 'easy'); if ($debug_type == 'krumo') { ecrLoadHelper('krumo_0_2.krumo'); krumo::dump($var); return; } include_once 'Var_Dump.php'; if (class_exists('Var_Dump')) { Var_Dump::displayInit(array('display_mode' => 'HTML4_Table'), array('show_caption' => FALSE, 'bordercolor' => '#ccc', 'bordersize' => '2', 'captioncolor' => 'black', 'cellpadding' => '8', 'cellspacing' => '5', 'color1' => '#000', 'color2' => '#000', 'before_num_key' => '<span style="color: #fff; font-weight: bold;">', 'after_num_key' => '</span>', 'before_str_key' => '<span style="color: #5450cc; font-weight: bold;">', 'after_str_key' => '</span>', 'before_value' => '<span style="color: #5450cc;">', 'after_value' => '</span>')); Var_Dump::display($var); } else { echo '<pre>' . print_r($var, true) . '</pre>'; } }