/** * Constructor. * * @param EcrProjectBase $project * * @throws DomainException */ public function __construct(EcrProjectBase $project) { $this->project = $project; $comParams = JComponentHelper::getComponent('com_easycreator')->params; $this->localPath = $comParams->get('local_updateserver_dir'); $this->serverUrl = $comParams->get('updateserver_url'); $this->serverTitle = $comParams->get('updateserver_title'); $this->releaseUrl = $comParams->get('updateserver_release_url') ?: $this->serverUrl; $this->developmentUrl = $comParams->get('updateserver_development_url') ?: $this->serverUrl; //-- Check the base directory if (false == JFolder::exists(ECRPATH_UPDATESERVER)) { if (false == JFolder::copy(JPATH_COMPONENT_ADMINISTRATOR . '/data/updateserver', ECRPATH_UPDATESERVER)) { throw new DomainException(sprintf('%s - Can not create the update server directory: %s', __METHOD__, ECRPATH_UPDATESERVER)); } EcrHtml::message(sprintf(jgettext('The update server directory has been created in: %s'), ECRPATH_UPDATESERVER)); } //-- Check the extension directory $base = ECRPATH_UPDATESERVER . '/' . $this->project->comName; if (false == JFolder::exists($base)) { if (false == JFolder::create($base)) { throw new DomainException(sprintf('%s - Can not create the extension update server directory: %s', __METHOD__, $base)); } EcrHtml::message(sprintf(jgettext('The update server extension directory has been created in: %s'), $base)); JFolder::create($base . '/release'); JFolder::create($base . '/development'); JFile::copy(ECRPATH_UPDATESERVER . '/index.html', $base . '/index.html'); JFile::copy(ECRPATH_UPDATESERVER . '/template_extension.html', $base . '/template.html'); JFile::copy(ECRPATH_UPDATESERVER . '/updateserver.css', $base . '/updateserver.css'); JFile::copy(ECRPATH_UPDATESERVER . '/favicon.ico', $base . '/favicon.ico'); /* @var SimpleXMLElement $xml */ $xml = EcrProjectHelper::getXML('<updates/>', false); $xml->addChild('name', $this->project->name); $buffer = $xml->asFormattedXML(); //-- @todo: The file name "extension.xml" is the J! default - customize. JFile::write($base . '/extension.xml', $buffer); JFile::write($base . '/development.xml', $buffer); $feed = new EcrProjectFeed(); $feed->title = $this->serverTitle . ' - ' . $this->project->name . ' - Release Feed'; $feed->link = $this->releaseUrl . '/release-feed.xml'; $feed->id = $feed->link; $feed->author = 'XX-Author'; $feed->updated = date(DATE_ATOM); $buffer = $feed->printPretty(); JFile::write($base . '/release-feed.xml', $buffer); $feed->title = $this->serverTitle . ' - ' . $this->project->name . ' - Development Feed'; $feed->link = $this->developmentUrl . '/development-feed.xml'; $feed->id = $feed->link; $buffer = $feed->printPretty(); JFile::write($base . '/development-feed.xml', $buffer); //-- Copy the Joomla! manifest JFile::copy($this->project->getJoomlaManifestPath() . '/' . $this->project->getJoomlaManifestName(), $base . '/manifest.xml'); $this->update(); } }
/** * Draws a h1 tag with title and project name. * * @param string $title * @param EcrProjectBase $project * @param string $class */ public static function header($title, EcrProjectBase $project = null, $class = '') { $pName = $project ? $project->name : ''; $pType = $project ? $project->translateType() : ''; $pVersion = $project ? $project->version : ''; $icon = $class ? '<span class="img32c icon32-' . $class . '"></span>' : ''; $html = ''; $html .= $icon; $html .= $title; $html .= $pType ? ' <span style="color: black">' . $pType . '</span>' : ''; $html .= $pName ? ' <span style="color: green">' . $pName . '</span>' : ''; $html .= $pVersion ? ' <small><small>' . $pVersion . '</small></small>' : ''; echo '<h1>' . $html . '</h1>'; }
private function prepareUpdate() { jimport('joomla.filesystem.archive'); $buildsPath = $this->project->getZipPath(); if (!JFolder::exists($buildsPath)) { return false; } $folders = JFolder::folders($buildsPath); if (!$folders) { return false; } $tmpPath = ''; $tmpPath .= JFactory::getConfig()->get('tmp_path'); $tmpPath .= '/' . $this->project->comName . '_update_' . time(); $this->log('Temp path is set to ' . $tmpPath); if (!JFolder::create($tmpPath)) { EcrHtml::message('Unable to create temp folder for update', 'error'); $this->log('Can not create the temp folder ' . $tmpPath); return false; } foreach ($folders as $folder) { JFolder::create($tmpPath . '/' . $folder); $this->log('Processing version ' . $folder); $files = JFolder::files($buildsPath . '/' . $folder); if (!$files) { continue; } $this->log(sprintf('Found %d package(s) ', count($files))); if (1 == count($files)) { //-- Only one file found in folder - take it $source = $buildsPath . '/' . $folder . '/' . $files[0]; } else { //-- @todo tmp solution for multiple file :-? //-- ===echo 'more files found....picking '.$files[0]; //-- Temp $source = $buildsPath . '/' . $folder . '/' . $files[0]; } $this->log('Processing package: ' . $source); $destination = $tmpPath . '/' . $folder; if (!JArchive::extract($source, $destination)) { EcrHtml::message(sprintf('Unable to extract the package %s to %s', $source, $destination), 'error'); return false; } } //foreach $this->tmpPath = $tmpPath; return true; }
/** * CLI Application View. * * @return void */ protected function runwap() { $webPath = str_replace(JPATH_ROOT . DIRECTORY_SEPARATOR, '', $this->project->getExtensionPath()); $this->href = JURI::root() . $webPath; //.'/'.$this->project->comName.'.php'; $this->setLayout('runwap'); }
/** * Discover the languages for a project. * * @param EcrProjectBase $project The project * * @return array */ public static function discoverLanguages(EcrProjectBase $project) { static $languages = array(); $pKey = $project->type . $project->scope . $project->comName; if (isset($languages[$pKey])) { return $languages[$pKey]; } $langs = JFactory::getLanguage()->getKnownLanguages(); if (count($langs > 1)) { //-- We have more than one language.. order en-GB at first position $enGB = array('en-GB' => $langs['en-GB']); unset($langs['en-GB']); $langs = $enGB + $langs; } $languages[$pKey] = array(); $langPaths = $project->getLanguagePaths(); if (!$langPaths) { return array(); } foreach ($langs as $tag => $lang) { foreach ($langPaths as $scope => $paths) { if (!is_array($paths)) { $paths = array($paths); } foreach ($paths as $path) { if ($project->langFormat != 'ini') { //-- Special g11n Language $addPath = $tag . '/' . $tag . '.' . $project->getLanguageFileName($scope); } else { $addPath = 'language/' . $tag . '/' . $tag . '.' . $project->getLanguageFileName($scope); } $fileName = JPath::clean($path . '/' . $addPath); if (JFile::exists($fileName)) { $languages[$pKey][$tag][] = $scope; } } //foreach } //foreach } //foreach return $languages[$pKey]; }
/** * Installs an extension with the standard Joomla! installer. * * @throws EcrExceptionBuilder * @return EcrProjectBuilder */ private function install() { if ($this->testMode) { //-- Exiting in test mode $this->logger->log('TEST MODE - not installing'); return $this; } if ('cliapp' == $this->project->type || 'webapp' == $this->project->type) { $src = $this->buildDir . '/site'; $dest = $this->project->getExtensionPath(); if (false == JFolder::copy($src, $dest)) { throw new EcrExceptionBuilder(sprintf('Failed to copy the JApplication from %s to %s', $src, $dest)); } $this->logger->log(sprintf('JApplication files copied from %s to %s', $src, $dest)); $src = $this->buildDir . DS . $this->project->getJoomlaManifestName(); $dest = $this->project->getJoomlaManifestPath() . DS . $this->project->getJoomlaManifestName(); if (false == JFile::copy($src, $dest)) { throw new EcrExceptionBuilder(sprintf('Failed to copy package manifest xml from %s to %s', $src, $dest)); } return $this; } if ('package' == $this->project->type) { //-- J! 1.6 package - only copy the manifest xml $src = $this->buildDir . DS . $this->project->getJoomlaManifestName(); $dest = $this->project->getJoomlaManifestPath() . DS . $this->project->getJoomlaManifestName(); if (false == JFile::copy($src, $dest)) { throw new EcrExceptionBuilder(sprintf('Failed to copy package manifest xml from %s to %s', $src, $dest)); } $this->logger->log(sprintf('Package manifest xml has been copied from %s to %s', $src, $dest)); return $this; } jimport('joomla.installer.installer'); jimport('joomla.installer.helper'); $this->logger->log('Starting Install'); //-- Did you give us a valid package ? $type = JInstallerHelper::detectType($this->buildDir); if (false == $type) { throw new EcrExceptionBuilder(jgettext('Path does not have a valid package')); } //-- Get an installer instance $installer = JInstaller::getInstance(); //-- Install the package $result = $installer->install($this->buildDir); $this->logger->log('Installer Message: ' . $installer->message); $this->logger->log('Extension Message: ' . $installer->get('extension.message')); //-- Clean up the install directory. If we are not debugging. ECR_DEBUG ? null : JInstallerHelper::cleanupInstall('', $this->buildDir); //-- There was an error installing the package if (false == $result) { throw new EcrExceptionBuilder(sprintf(jgettext('An error happened while installing your %s'), jgettext($type))); } return $this; }
/** * Constructor. * * @param EcrProjectBase $project * @param string $adapter */ public function __construct(EcrProjectBase $project, $adapter = 'mysql') { if (class_exists('easyLogger')) { $this->logger = EcrLogger::getInstance('ecr'); } if (!$this->setAdapter($adapter)) { return false; } $buildsPath = $project->getZipPath(); $this->log('Looking for versions in ' . $buildsPath); if (false == JFolder::exists($buildsPath)) { return; } $folders = JFolder::folders($buildsPath); $this->log(sprintf('Found %d version(s) ', count($folders))); if (!$folders) { return; } $this->versions = $folders; $this->project = $project; }
/** * Scans the project. * * @return void */ private function scan() { foreach ($this->project->copies as $copy) { if (is_dir($copy)) { //-- Process known extensions foreach ($this->fileExtensions as $ext) { $data = $this->getCodeLines($copy, $ext); $this->addData($data, $ext); } //foreach //-- Process images $files = JFolder::files($copy, $this->imgExtensions, true, true); $this->projectData['images']['files'] += count($files); foreach ($files as $file) { $this->projectData['images']['size'] += filesize($file); } //foreach $this->totalFiles += $this->projectData['images']['files']; $this->totalSize += $this->projectData['images']['size']; } else { //-- It's a file //... @todo ? //-- Process known extensions foreach ($this->fileExtensions as $ext) { $data = $this->getCodeLines($copy, $ext); $this->addData($data, $ext); } //foreach } } //foreach /* * Language files */ $langPaths = $this->project->getLanguagePaths(); $languages = EcrLanguageHelper::discoverLanguages($this->project); foreach ($languages as $tag => $scopes) { foreach ($scopes as $scope) { $fileName = $langPaths[$scope] . DS . 'language' . DS . $tag . DS . $tag . '.' . $this->project->getLanguageFileName($scope); $data = $this->getCodeLines($fileName, 'ini'); $this->addData($data, 'languages'); } //foreach } //foreach return $this; }
/** * Formats SimpleXML. * * @return string XML */ public function formatXML() { $errRep = ini_get('error_reporting'); //-- DOMImplementation throws strict errors :( ini_set('error_reporting', 0); $dtd = $this->project->getDTD(JVERSION); if ($dtd) { $doctype = DOMImplementation::createDocumentType($dtd['type'], $dtd['public'], $dtd['uri']); $document = DOMImplementation::createDocument('', '', $doctype); } else { $this->setError('no DTD found for ' . JVERSION . ' - ' . $this->project->type); $document = DOMImplementation::createDocument(); } $domnode = dom_import_simplexml($this->manifest); $domnode = $document->importNode($domnode, true); $domnode = $document->appendChild($domnode); $document->encoding = 'utf-8'; $document->formatOutput = true; ini_set('error_reporting', $errRep); return $document->saveXML(); }
/** * Inserts the AutoCode into the project. * * @param EcrProjectBase $project The project. * @param array $options Insert options. * @param EcrLogger $logger The EcrLogger. * * @return boolean */ public function insert(EcrProjectBase $project, $options, EcrLogger $logger) { JFactory::getApplication()->enqueueMessage(__METHOD__ . ' not finished', 'error'); $input = JFactory::getApplication()->input; $table_name = $input->get('element'); $element_scope = $input->get('element_scope'); if (!$table_name) { JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error'); return false; } $fields = EcrTableHelper::getTableColumns($table_name); $reqFields = $input->get('field', array(), 'array'); $headers = ''; $cells = ''; $tags = array('<!--', '-->'); $indent = ' '; if (!count($fields)) { JFactory::getApplication()->enqueueMessage('No table fields found', 'error'); return false; } foreach ($fields as $name => $field) { $reqFieldHeader = $reqFields['header'][$name]; $reqFieldCell = $reqFields['cell'][$name]; if (isset($project->autoCodes[$this->key]->fields[$this->key . '.header'][$name])) { $fieldHeader = $project->autoCodes[$this->key]->fields[$this->key . '.header'][$name]; $fieldHeader->label = $reqFieldHeader['label']; } else { $fieldHeader = new EcrTableField(); $fieldHeader->name = $name; $fieldHeader->label = $name; } if (isset($project->autoCodes[$this->key]->fields[$this->key . '.cell'][$name])) { $fieldCell = $project->autoCodes[$this->key]->fields[$this->key . '.cell'][$name]; } else { $fieldCell = new EcrTableField(); $fieldCell->name = $name; } $fieldHeader->display = $reqFieldHeader['display']; $fieldHeader->width = $reqFieldHeader['width']; //-- Display value for cells is the same as for headers $fieldCell->display = $reqFieldHeader['display']; $autoCodeFieldsHeader[] = $fieldHeader; $autoCodeFieldsCell[] = $fieldCell; $headers .= $this->getCode('header', $fieldHeader, $indent); $cells .= $this->getCode('cell', $fieldCell, $indent); } //foreach $this->fields[$this->key . '.header'] = $autoCodeFieldsHeader; $this->codes[$this->key . '.header'] = $this->enclose($headers, $this->key . '.header', true); $this->fields[$this->key . '.cell'] = $autoCodeFieldsCell; $this->codes[$this->key . '.cell'] = $this->enclose($cells, $this->key . '.cell', true); $project->addAutoCode($this); /* * Add substitutes * * Define keys that will be substitutes in the code */ $project->addSubstitute('ECR_SUBPACKAGE', 'Views'); $project->addSubstitute('_ECR_TABLE_NAME_', $table_name); foreach ($this->codes as $key => $code) { $project->addSubstitute($tags[0] . $key . $tags[1], $code); } //foreach /* Insert the part to your project and return the results */ return $project->insertPart($options, $logger); }
/** * Inserts the part into the project. * * @param EcrProjectBase $project The project. * @param array $options Insert options. * @param EcrLogger $logger The EcrLogger. * * @return boolean */ public function insert(EcrProjectBase $project, $options, EcrLogger $logger) { $project->addSubstitute('ECR_SUBPACKAGE', 'Installer'); JFactory::getApplication()->input->set('element_scope', 'admin'); return $project->insertPart($options, $logger); }
/** * Inserts the part into the project. * * @param EcrProjectBase $project The project. * @param array $options Insert options. * @param EcrLogger $logger The EcrLogger. * * @return boolean */ public function insert(EcrProjectBase $project, $options, EcrLogger $logger) { JFactory::getApplication()->input->set('element_scope', 'admin'); return $project->insertPart($options, $logger); }
/** * Inserts the AutoCode into the project. * * @param EcrProjectBase $project The project. * @param array $options Insert options. * @param EcrLogger $logger EcrLogger. * * @return boolean */ public function insert(EcrProjectBase $project, $options, EcrLogger $logger) { $input = JFactory::getApplication()->input; $table_name = $input->get('element'); $var_scope = $input->get('var_scope'); $element_scope = $input->get('element_scope'); if (!$table_name) { JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error'); return false; } $db = JFactory::getDBO(); $prefix = $db->getPrefix(); $fields = $db->getTableFields($prefix . $table_name); $table_vars = ''; $autoCodeFields = array(); $reqFields = $input->get('field', array(), 'array'); if (count($fields)) { foreach ($fields[$prefix . $table_name] as $name => $type) { $reqField = $reqFields[$name]; if (isset($project->autoCodes[$this->key]->fields[$this->key . '.var'][$name])) { $field = $project->autoCodes[$this->key]->fields[$this->key . '.var'][$name]; $field->label = $reqField['label']; } else { $field = new EcrTableField(); $field->name = $name; $field->label = $name; $field->type = $type; } $autoCodeFields[] = $field; $adds = array($field->label); $table_vars .= EcrTableHelper::formatTableVar($name, $type, $adds, $var_scope); } //foreach } $AutoCode = new EcrProjectAutocode($this->group, $this->name, $table_name, $element_scope); $AutoCode->options = array(); $AutoCode->options['varscope'] = $var_scope; $AutoCode->fields[$AutoCode->getKey() . '.var'] = $autoCodeFields; $AutoCode->codes[$AutoCode->getKey() . '.var'] = $AutoCode->enclose($table_vars, $AutoCode->getKey() . '.var'); $project->addAutoCode($AutoCode); /* * Add substitutes * * Define keys that will be substitutes in the code */ $project->addSubstitute('ECR_SUBPACKAGE', 'Tables'); $project->addSubstitute('_ECR_TABLE_NAME_', $table_name); foreach ($AutoCode->codes as $key => $code) { $project->addSubstitute($key, $code); } //foreach /* Insert the part to your project and return the results */ return $project->insertPart($options, $logger); }
/** * Inserts the part into the project. * * @param EcrProjectBase $EasyProject The project. * @param array $options Insert options. * @param EcrLogger $logger The EcrLogger. * * @return boolean */ public function insert(EcrProjectBase $EasyProject, $options, EcrLogger $logger) { $input = JFactory::getApplication()->input; $this->_options = $options; $EasyProject->addSubstitute('ECR_SUBPACKAGE', 'Views'); $element_name = $input->get('element_name'); $table_name = $input->get('table_name'); $req_table_fields = $input->get('table_fields', array(), 'array'); $req_table_fields_types = $input->get('table_fields_types', array(), 'array'); if (!$table_name) { $table_name = $element_name; } if (!$table_name) { $table_name = $element_name; JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error'); return false; } $table_name = strtolower($table_name); $db = JFactory::getDBO(); $prefix = $db->getPrefix(); $fields = $db->getTableFields($prefix . $table_name); $tableFields = array(); $table_vars = ''; if (count($fields)) { $tableFields = $fields[$prefix . $table_name]; } /* * Add substitutes */ $EasyProject->addSubstitute('ECR_ELEMENT_NAME', $element_name); $EasyProject->addSubstitute('_ECR_LOWER_ELEMENT_NAME_', strtolower($element_name)); $EasyProject->addSubstitute('_ECR_TABLE_NAME_', $table_name); /* * Add manual substitutes */ // $substitutes = array(); // foreach($this->patterns as $pKey => $pReplacement) // { // $substitutes[$pKey] = ''; // }//foreach $code = ''; $acFields = array(); foreach ($req_table_fields as $field) { $f = new stdClass(); $f->name = $field; $f->type = $req_table_fields_types[$field]; $code .= str_replace('_ECR_KEY_', $f->name, $this->fieldsOptions[$f->type]); $acFields[] = $f; // $acOptions[$field] = array(); // $acOptions[$field]['type'] = $req_table_fields_types[$field]; } //foreach // foreach($tableFields as $key => $value) // { // if( ! in_array($key, $req_table_fields)) { continue; } // // foreach($this->patterns as $pKey => $pReplacement) // { // $substitutes[$pKey] .= str_replace('##ECR_KEY##', $key, $pReplacement); // }//foreach // $i ++; // }//foreach /* $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= ' <?php $coloumnCount += '.$i.'; ?>'.NL; */ $AutoCode = new EcrProjectAutocode($this->group, $this->name, $table_name, $this->_scope); // $AutoCode->group = $this->group; // $AutoCode->name = $this->name; // // $AutoCode->element = $table_name; // $AutoCode->scope = $this->_scope; $AutoCode->options = array(); //$acOptions; // foreach($substitutes as $key => $value) // { $key = '##ECR_OPTIONS##'; $AutoCode->fields[$key] = $acFields; //array(); $AutoCode->codes[$key] = $AutoCode->enclose($code, $key, true); $EasyProject->addSubstitute($key, $AutoCode->enclose($code, $key, true)); // } // foreach($substitutes as $key => $value) // { // $EcrProject->addSubstitute($key, $AutoCode->enclose($code, $key, true)); // } $EasyProject->addAutoCode($AutoCode, $this->key); return $EasyProject->insertPart($options, $logger); }
/** * Inserts the part into the project. * * @param EcrProjectBase $project The project. * @param array $options Insert options. * @param EcrLogger $logger The EcrLogger. * * @return boolean */ public function insert(EcrProjectBase $project, $options, EcrLogger $logger) { $input = JFactory::getApplication()->input; $table_name = $input->get('element'); $var_scope = $input->get('var_scope'); $element_scope = $input->get('element_scope'); if (!$table_name) { JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error'); return false; } $db = JFactory::getDBO(); $prefix = $db->getPrefix(); $fields = $db->getTableFields($prefix . $table_name); $table_vars = ''; $autoCodeFields = array(); if (count($fields)) { foreach ($fields[$prefix . $table_name] as $key => $value) { $table_vars .= $this->formatTableVar($key, $value, array(), $var_scope); $autoCodeFields[] = $key; } //foreach } $AutoCode = new EcrProjectAutocode($this->group, $this->name, $table_name, $element_scope); $AutoCode->options = array(); $AutoCode->options['varScope'] = $var_scope; $AutoCode->fields['##ECR_TABLE_VARS##'] = array(); //$autoCodeFields; $AutoCode->codes['##ECR_TABLE_VARS##'] = $AutoCode->enclose($table_vars, '##ECR_TABLE_VARS##'); $AutoCode->fields['##ECR_FIELD_1##'] = array(); $AutoCode->codes['##ECR_FIELD_1##'] = $AutoCode->enclose($this->formatTableVar('db', 'Database object', array(), $var_scope), '##ECR_FIELD_1##'); $project->addAutoCode($AutoCode, $this->key); /* * Add substitutes * * Define keys that will be substitutes in the code */ $project->addSubstitute('ECR_SUBPACKAGE', 'Tables'); $project->addSubstitute('_ECR_TABLE_NAME_', $table_name); foreach ($AutoCode->codes as $key => $code) { $project->addSubstitute($key, $code); } //foreach /* Insert the part to your project and return the results */ return $project->insertPart($options, $logger); }
/** * 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; }
/** * Inserts the part into the project. * * @param EcrProjectBase $easyProject The project. * @param array $options Insert options. * @param EcrLogger $logger The EcrLogger. * * @return boolean */ public function insert(EcrProjectBase $easyProject, $options, EcrLogger $logger) { $easyProject->addSubstitute('ECR_SUBPACKAGE', 'Models'); return $easyProject->insertPart($options, $logger); }
/** * Inserts the AutoCode into the project. * * @param EcrProjectBase $project The project. * @param array $options Insert options. * @param EcrLogger $logger EcrLogger. * * @return boolean */ public function insert(EcrProjectBase $project, $options, EcrLogger $logger) { $input = JFactory::getApplication()->input; $table_name = $input->get('element'); $element_scope = $input->get('element_scope'); $element = 'row'; if (!$table_name) { JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error'); return false; } $table = new EcrTable($table_name); $fields = EcrTableHelper::getTableColumns($table_name); $reqFields = $input->get('field', array(), 'array'); $rows = ''; $tags = array('<!--', '-->'); $indent = ' '; if (!count($fields)) { JFactory::getApplication()->enqueueMessage('No table fields found', 'error'); return false; } foreach ($fields as $name => $field) { $reqFieldHeader = $reqFields[$name]; if (isset($project->autoCodes[$this->key]->fields[$this->key . '.' . $element][$name])) { $fieldHeader = $project->autoCodes[$this->key]->fields[$this->key . '.' . $element][$name]; } else { $fieldHeader = new EcrTableField(); $fieldHeader->name = $name; } $fieldHeader->label = $reqFieldHeader['label']; $fieldHeader->inputType = $reqFieldHeader['input_type']; $autoCodeFieldsHeader[] = $fieldHeader; $table->addField($fieldHeader); } //foreach $rows .= $this->getCode($element, $table, $indent); $this->fields[$this->key . '.' . $element] = $autoCodeFieldsHeader; $this->codes[$this->key . '.' . $element] = $this->enclose($rows, $this->key . '.' . $element); $project->addAutoCode($this); /* * Add substitutes * * Define keys that will be substitutes in the code */ $project->addSubstitute('ECR_SUBPACKAGE', 'Views'); $project->addSubstitute('_ECR_TABLE_NAME_', $table_name); foreach ($this->codes as $key => $code) { $project->addSubstitute($tags[0] . $key . $tags[1], $code); } //foreach /* Insert the part to your project and return the results */ return $project->insertPart($options, $logger); }
/** * Findes the Joomla! install xml file for a given extension. * * @param EcrProjectBase $project The project * * @return mixed [boolean false on error | string path on success] */ public static function findManifest(EcrProjectBase $project) { $path = $project->getJoomlaManifestPath(); if (!JFolder::exists($path)) { return false; } //-- @Joomla!-version-check switch (ECR_JVERSION) { case '2.5': case '3.0': case '3.1': case '3.2': case '3.3': case '3.4': if ('library' == $project->type || 'package' == $project->type) { $xmlFiles = array($path . DS . $project->getJoomlaManifestName()); } break; default: EcrHtml::message(__METHOD__ . ' - Unknown JVersion', 'error'); return false; break; } if (empty($xmlFiles)) { $xmlFiles = JFolder::files($path, '.xml$', false, true); } if (empty($xmlFiles)) { return false; } //-- If at least one xml file exists foreach ($xmlFiles as $fileName) { if (!JFile::exists($fileName)) { /* JXXError::raiseWarning(100, 'File not found '.$fileName); EcrHtml::displayMessage('Unable to load XML file '.$fileName, 'error'); */ return false; } $xml = self::getXML($fileName); //-- Invalid XML file if (!$xml) { return false; } if ($xml->getName() == 'extension') { //-- Valid xml manifest found return str_replace(JPATH_ROOT . DS, '', JPath::clean($fileName)); } } //foreach //-- None of the xml files found were valid install files EcrHtml::message(sprintf(jgettext('Manifest not found for type: %s - name: %s'), $project->type, $fileName), 'error'); return false; }
/** * Inserts the part into the project. * * @param EcrProjectBase $project The project. * @param array $options Insert options. * @param EcrLogger $logger The EcrLogger. * * @return boolean */ public function insert(EcrProjectBase $project, $options, EcrLogger $logger) { $input = JFactory::getApplication()->input; $element_name = $input->get('element_name'); $table_name = $input->get('table_name'); $req_table_fields = $input->get('table_fields', array(), 'array'); $req_table_fields_edits = $input->get('table_fields_edits', array(), 'array'); $req_table_fields_types = $input->get('table_fields_types', array(), 'array'); if (!$table_name) { JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error'); return false; } $db = JFactory::getDBO(); $prefix = $db->getPrefix(); $fields = $db->getTableFields($prefix . $table_name); $tableFields = array(); $table_vars = ''; if (count($fields)) { $tableFields = $fields[$prefix . $table_name]; foreach ($tableFields as $key => $value) { if (!in_array($key, $req_table_fields)) { continue; } $table_vars .= EcrTableHelper::formatTableVar($key, $value); } //foreach } /* * Add substitutes */ $project->addSubstitute('ECR_ELEMENT_NAME', $element_name); $project->addSubstitute('_ECR_LOWER_ELEMENT_NAME_', strtolower($element_name)); $project->addSubstitute('_ECR_TABLE_NAME_', $table_name); $project->addSubstitute('##ECR_TABLE_VARS##', $table_vars); /* * Read part options files */ $files = JFolder::files($options->pathSource . DS . 'options', '.', true, true); foreach ($files as $file) { $fileContents = JFile::read($file); if (strpos($fileContents, '<?php') === 0) { $fileContents = substr($fileContents, 6); } $project->substitute($fileContents); $project->addSubstitute('##' . strtoupper(JFile::stripExt(JFile::getName($file))) . '##', $fileContents); } //foreach /* * Add manual substitutes */ $substitutes['##ECR_VIEW1_TMPL1_THS##'] = '?>'; $substitutes['##ECR_VIEW1_TMPL1_TDS##'] = '?>'; $substitutes['##ECR_VIEW2_TMPL1_OPTION2##'] = '?>'; $i = 0; foreach ($tableFields as $key => $value) { if (!in_array($key, $req_table_fields)) { continue; } $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= ' <th>' . NL; $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= " <?php echo JHTML::_('grid.sort', '" . $key . "', '" . $key . "', \$this->lists['order_Dir'], \$this->lists['order']);?>" . NL; $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= ' </th>' . NL; $substitutes['##ECR_VIEW1_TMPL1_TDS##'] .= ' <td>' . NL; $substitutes['##ECR_VIEW1_TMPL1_TDS##'] .= ' <?php echo $row->' . $key . '; ?>' . NL; $substitutes['##ECR_VIEW1_TMPL1_TDS##'] .= ' </td>' . NL; if (in_array($key, $req_table_fields_edits)) { $s = $project->getSubstitute('##ECR_VIEW2_TMPL1_OPTION2VAL##'); $s = str_replace('_ECR_FIELDVALUE_1_', $key, $s); $s = str_replace('_ECR_FIELDVALUE_2_', $req_table_fields_types[$key], $s); $substitutes['##ECR_VIEW2_TMPL1_OPTION2##'] .= $s; } $i++; } //foreach $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= ' <?php $coloumnCount += ' . $i . '; ?>' . NL; $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= ' <?php ' . NL; $substitutes['##ECR_VIEW1_TMPL1_TDS##'] .= ' <?php ' . NL; $substitutes['##ECR_VIEW2_TMPL1_OPTION2##'] .= ' <?php ' . NL; foreach ($substitutes as $key => $value) { $project->addSubstitute($key, $value); } //foreach /* * Remove options */ if (!in_array('ordering', $req_table_fields)) { $project->addSubstitute('##ECR_CONTROLLER1_OPTION1##', ''); } if (!in_array('published', $req_table_fields)) { } $project->addSubstitute('ECR_SUBPACKAGE', 'Tables'); $input->set('element_scope', 'admin'); if (!$project->insertPart($options, $logger)) { return false; } /* * Create menu link */ if ($input->get('create_menu_link', false)) { $link = 'option=' . $options->ecr_project . '&view=' . strtolower($element_name) . $project->listPostfix . '&controller=' . strtolower($element_name) . $project->listPostfix; if (!$project->addSubmenuEntry($element_name, $link)) { JFactory::getApplication()->enqueueMessage(jgettext('Unable to create menu link'), 'error'); return false; } } return true; }
/** * Inserts the part into the project. * * @param EcrProjectBase $EcrProject The project. * @param array $options Insert options. * @param EcrLogger $logger The EcrLogger. * * @return boolean */ public function insert(EcrProjectBase $EcrProject, $options, EcrLogger $logger) { $input = JFactory::getApplication()->input; $EcrProject->addSubstitute('ECR_SUBPACKAGE', 'Models'); $element_name = $input->get('element'); $element_scope = $input->get('element_scope'); $table_name = $input->get('table_name'); if (!$table_name) { $table_name = $element_name; } $req_table_fields = $input->get('table_fields', array(), 'array'); if (!$table_name) { JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error'); return false; } $db = JFactory::getDBO(); $prefix = $db->getPrefix(); $fields = $db->getTableFields($prefix . $table_name); $tableFields = array(); $table_vars = ''; if (count($fields)) { $tableFields = $fields[$prefix . $table_name]; } /* * Add substitutes */ $EcrProject->addSubstitute('ECR_ELEMENT_NAME', $element_name); $EcrProject->addSubstitute('_ECR_LOWER_ELEMENT_NAME_', strtolower($element_name)); $EcrProject->addSubstitute('_ECR_TABLE_NAME_', $table_name); /* * Add manual substitutes */ $substitutes = array(); foreach ($this->patterns as $pKey => $pReplacement) { $substitutes[$pKey] = ''; } //foreach $i = 0; foreach ($tableFields as $key => $value) { if (!in_array($key, $req_table_fields)) { continue; } foreach ($this->patterns as $pKey => $pReplacement) { $substitutes[$pKey] .= str_replace('##ECR_KEY##', $key, $pReplacement); } //foreach $i++; } //foreach $substitutes['##ECR_VIEW1_TMPL1_THS##'] .= ' <?php $coloumnCount += ' . $i . '; ?>' . NL; $AutoCode = new EcrProjectAutocode($this->group, $this->name, $table_name, $element_scope); $AutoCode->options = array(); foreach ($substitutes as $key => $value) { $AutoCode->fields[$key] = $req_table_fields; //array();//$autoCodeFields; $AutoCode->codes[$key] = $AutoCode->enclose($value, $key, true); $EcrProject->addSubstitute($key, $AutoCode->enclose($value, $key, true)); } //foreach $EcrProject->addAutoCode($AutoCode, $this->key); return $EcrProject->insertPart($options, $logger); }
/** * Display the bar View. * * @param string $task The actual task * * @todo move * * @return string */ private function displayBar($task) { $sel_language = JFactory::getApplication()->input->get('sel_language'); $this->sel_language = $sel_language; $subTasks = array(array('title' => jgettext('Setup'), 'description' => jgettext('Setup your language files'), 'icon' => 'apply', 'task' => 'languages'), array('title' => jgettext('Files and menus'), 'description' => jgettext('Searches inside the source files and menus for translatable strings'), 'icon' => 'ecr_language', 'task' => 'searchfiles'), array('title' => jgettext('Translations'), 'description' => jgettext('Manage translations in ini files and inspect your php / xml files for JText strings to translate.'), 'icon' => 'ecr_language', 'task' => 'translations'), array('title' => jgettext('Default file order'), 'description' => jgettext('Change the order of your default language file and add comments to create a structure.'), 'icon' => 'text', 'task' => 'langcorrectdeforder'), array('title' => jgettext('Translation order'), 'description' => jgettext('Change the order of your translated language files according to your default file.'), 'icon' => 'text', 'task' => 'langcorrectorder'), array('title' => jgettext('Versions'), 'description' => jgettext('Compare saved versions of your language files.'), 'icon' => 'sig', 'task' => 'show_versions'), array('title' => jgettext('Convert'), 'description' => jgettext('Convert your language files and your code simultaneously.'), 'icon' => 'rename', 'task' => 'convert')); //@todo - unify.. $html = ''; $html .= EcrHtmlMenu::sub($subTasks); $html .= '<div style="clear: both; height: 1em;"></div>'; //-- Scope selector if ($task != 'languages') { $html .= '<div class="ecr_menu_box" style="margin-left: 0.3em;">'; $html .= jgettext('Scope') . ' '; $html .= '<select name="scope" class="span1" onchange="submitbutton(\'' . $task . '\');">'; foreach ($this->project->getLanguagePaths() as $scope => $p) { $html .= '<option value="' . $scope . '" '; $html .= $this->scope == $scope ? ' selected="selected"' : ''; $html .= '>'; $html .= $scope . '</option>'; } $html .= '</select>'; $html .= '</div>'; } switch ($task) { case 'translations': case 'searchfiles': if (count($this->project->langs) > 2) { $html .= '<div class="ecr_menu_box">'; $html .= jgettext('Do NOT show') . ': '; foreach ($this->project->langs as $lang => $scopes) { if ($lang == 'en-GB') { //-- Always show default language continue; } $checked = in_array($lang, $this->hideLangs) ? 'checked="checked"' : ''; $color = in_array($lang, $this->hideLangs) ? 'red' : 'green'; $html .= '<input type="checkbox" name="hide_langs[]"' . ' id="hide_langs_' . $lang . '"' . ' value="' . $lang . '" ' . $checked . ' onclick="submitbutton(\'' . $task . '\');">'; $html .= '<label class="inline" for="hide_langs_' . $lang . '" style="color: ' . $color . ';">' . $lang . '</label>'; } $html .= '</div>'; } break; case 'langcorrectorder': case 'save_lang_corrected': $html .= '<div class="ecr_menu_box">'; $html .= $this->drawLangSelector($sel_language, 'langcorrectorder'); $html .= ' </div>'; if ($sel_language) { $html .= '<div class="ecr_menu_box">'; $html .= jgettext('Cut'); $cut_after = JFactory::getApplication()->input->getInt('cut_after', 30); $html .= '<select name="cut_after" onchange="submitbutton(\'langcorrectorder\');">'; for ($i = 10; $i < 62; $i = $i + 2) { $selected = $cut_after == $i ? ' selected="selected"' : ''; $html .= '<option value="' . $i . '" ' . $selected . '>' . $i . '</option>'; } //for $html .= '</select>'; $html .= '</div>'; $html .= EcrHtmlCheck::versioned(); $html .= ' <span class="ecr_button img icon16-ecr_save"' . ' onclick="submitbutton(\'save_lang_corrected\');" style="display: inline !important;">'; $html .= jgettext('Save'); $html .= ' </span>'; } break; case 'langcorrectdeforder': case 'save_deflang_corrected': $html .= EcrHtmlCheck::versioned(); $html .= '<span class="btn img icon16-ecr_save"'; $html .= 'onclick="submitbutton(\'save_deflang_corrected\');">' . jgettext('Save') . '</span>'; $html .= '<br /><br /><div class="explanation">' . jgettext('Drag and drop elements to rearrange. Add new comments.') . '</div>'; break; case 'show_versions': case 'show_version': $html .= '<div class="ecr_menu_box">'; $html .= $this->drawLangSelector($sel_language, 'show_versions', true); $html .= '</div>'; break; case 'translate': case 'language_check': case 'languages': case 'convert': case 'jalhoo': //-- Do nothing break; default: echo 'UNDEFINED: ' . $task; break; } //switch return $html; }
/** * Generates a language file name. * * @param string $lang Language code eg. en-GB * @param string $scope Eg. admin * @param EcrProjectBase $project The EcrProject * * @return string full path to file */ public static function getFileName($lang, $scope, EcrProjectBase $project) { $paths = $project->getLanguagePaths($scope); if (!is_array($paths)) { $paths = array($paths); } if ($project->langFormat != 'ini') { //-- Special g11n Language $addPath = $lang . '/' . $lang . '.' . $project->getLanguageFileName($scope); } else { $addPath = 'language/' . $lang . '/' . $lang . '.' . $project->getLanguageFileName($scope); } foreach ($paths as $path) { if (file_exists($path . DS . $addPath)) { return $path . DS . $addPath; } } //foreach //-- No existing file found. //-- Return a valid new file name based on the scope if (isset($paths[$scope])) { return $paths[$scope] . DS . $addPath; } if (isset($paths[0])) { return $paths[0] . DS . $addPath; } //-- Found nothing :( return ''; }