Exemple #1
0
 /**
  * Gets Information about a specific template.
  *
  * @param string $tplType Template type
  * @param string $tplName Template name
  *
  * @return object stdClass Template info.
  */
 public static function getTemplateInfo($tplType, $tplName)
 {
     if (false == JFile::exists(ECRPATH_EXTENSIONTEMPLATES . DS . $tplType . DS . $tplName . DS . 'manifest.xml')) {
         return false;
     }
     $xml = EcrProjectHelper::getXML(ECRPATH_EXTENSIONTEMPLATES . DS . $tplType . DS . $tplName . DS . 'manifest.xml');
     $info = new stdClass();
     $info->folder = $tplName;
     $info->name = (string) $xml->name;
     $info->description = jgettext((string) $xml->description);
     $info->version = (string) $xml->version;
     $info->jVersion = (string) $xml->jVersion;
     $info->phpVersion = (string) $xml->phpVersion;
     $info->dbTables = (string) $xml->dbTables;
     $info->author = (string) $xml->author;
     $info->authorUrl = (string) $xml->authorUrl;
     $info->complements = array();
     if (isset($xml->complements->complement)) {
         foreach ($xml->complements->complement as $complement) {
             $c = new stdClass();
             $c->folder = (string) $complement->folder;
             $c->version = (string) $complement->version;
             $c->targetDir = (string) $complement->targetDir;
             $info->complements[] = $c;
         }
     }
     $info->info = '';
     $info->info .= jgettext(ucfirst($tplType)) . ' ' . $info->name . ' ' . $info->version . '::' . $info->description;
     $info->info .= $info->author ? '<br /><span style=\'color: blue;\'>Author:</span> ' . $info->author : '';
     $info->info .= '<br /><strong>Joomla!:</strong> ' . $info->jVersion;
     $info->info .= '<br /><strong>PHP:</strong> ' . $info->phpVersion;
     $info->info .= $info->dbTables ? '<br /><span style=\'color: orange;\'>dbTables:</span> ' . $info->dbTables : '';
     $info->info .= '<br />ECR Folder: ' . $info->folder;
     return $info;
 }
Exemple #2
0
 /**
  * Constructor.
  *
  * @param string $path
  */
 public function __construct($path = '')
 {
     if ('' != $path) {
         $xml = EcrProjectHelper::getXML($path);
         if ($xml) {
             $this->title = (string) $xml->title;
             $this->link = (string) $xml->link->attributes()->href;
             $this->author = (string) $xml->author->name;
             foreach ($xml->entry as $entry) {
                 $i = new EcrProjectFeedItem();
                 $i->title = (string) $entry->title;
                 $i->link = $entry->link ? (string) $entry->link->attributes()->href : '';
                 $i->id = (string) $entry->id;
                 $i->summary = (string) $entry->summary;
                 $i->updated = (string) $entry->updated;
                 $i->author = (string) $entry->author->name;
                 $this->items[] = $i;
             }
         }
     }
 }
 /**
  * @return string
  */
 private function getDebug()
 {
     if (false == ECR_DEBUG) {
         return '';
     }
     $debug = array();
     $base = ECRPATH_UPDATESERVER . '/' . $this->project->comName;
     $debug[] = '<h3 class="debug">Debug</h3>';
     foreach (JFolder::folders($base) as $state) {
         $path = 'release' == $state ? 'extension' : $state;
         $debug[] = '<div class="path">' . $path . '.xml</div>';
         if (JFile::exists($base . '/' . $path . '.xml')) {
             $xml = EcrProjectHelper::getXML($base . '/' . $path . '.xml');
             $debug[] = '<pre class="code">' . htmlentities($xml->asFormattedXML()) . '</pre>';
         } else {
             $debug[] = 'NOT FOUND<br />';
         }
         $path = $state . '-feed';
         $debug[] = '<div class="path">' . $path . '.xml</div>';
         if (JFile::exists($base . '/' . $path . '.xml')) {
             $xml = EcrProjectHelper::getXML($base . '/' . $path . '.xml');
             $debug[] = '<pre class="code">' . htmlentities($xml->asFormattedXML()) . '</pre>';
         } else {
             $debug[] = 'NOT FOUND<br />';
         }
     }
     return '<div class="debug">' . implode("\n", $debug) . '</div>';
 }
Exemple #4
0
 /**
  * Process plugins in a package.
  *
  * @deprecated removed for J! 1.6
  *
  * @throws Exception
  * @return EcrProjectManifest
  */
 private function processPackagePlugins()
 {
     if (0 == count($this->project->plugins)) {
         return $this;
     }
     $pluginsElement = $this->manifest->addChild('plugins');
     foreach ($this->project->plugins as $item) {
         //-- Get the project
         $project = EcrProjectHelper::getProject('plg_' . $item->scope . '_' . $item->name);
         $f = JPATH_ROOT . DS . EcrProjectHelper::findManifest($project);
         $plgElement = $pluginsElement->addChild('plugin');
         $plgElement->addAttribute('plugin', $item->name);
         $plgElement->addAttribute('group', $item->scope);
         $plgElement->addAttribute('title', $item->title);
         if ($item->ordering) {
             $plgElement->addAttribute('order', $item->ordering);
         }
         $plgFilesElement = $plgElement->addChild('files');
         $plgFilesElement->addAttribute('folder', 'plg_' . $item->scope . '_' . $item->name);
         foreach ($project->copies as $copy) {
             if (JFolder::exists($copy)) {
                 $tName = str_replace('plugins' . DS . $item->scope . DS, '', $copy);
                 $plgFolderElement = $plgFilesElement->addChild('folder', $tName);
             } else {
                 if (JFile::exists($copy)) {
                     $plgFileElement = $plgFilesElement->addChild('file', JFile::getName($copy));
                 } else {
                     //-- @todo error
                     $this->_addLog('Not found<br />SRC: ' . $copy, 'FILE NOT FOUND');
                 }
             }
         }
         if (count($project->langs)) {
             $plgLangsElement = $plgElement->addChild('languages');
             $plgLangsElement->addAttribute('folder', 'plg_' . $item->scope . '_' . $item->name . '/language');
             foreach ($project->langs as $tag => $scopes) {
                 $plgFileElement = $plgLangsElement->addChild('language', $tag . '.' . $project->getLanguageFileName());
                 $plgFileElement->addAttribute('tag', $tag);
             }
         }
         $xml = EcrProjectHelper::getXML($f);
         if (false == $xml) {
             throw new Exception(sprintf(jgettext('Unable to load the xml file %s'), $f));
         }
         $paramsElement = $plgElement->addChild('params');
         if (isset($xml->params->param)) {
             foreach ($xml->params->param as $param) {
                 $paramElement = $paramsElement->addChild('param');
                 foreach ($param->attributes() as $name => $value) {
                     $paramElement->addAttribute($name, (string) $value);
                 }
                 if (isset($param->option)) {
                     foreach ($param->option as $option) {
                         $optionElement = $paramElement->addChild('option', (string) $option);
                         foreach ($option->attributes() as $Name => $Value) {
                             $optionElement->addAttribute($Name, (string) $Value);
                         }
                     }
                 }
             }
         }
     }
     return $this;
 }
Exemple #5
0
 /**
  * Read the project XML file.
  *
  * @param string $projectName Projects name
  *
  * @throws Exception
  * @return boolean
  */
 private function readProjectXml($projectName)
 {
     $fileName = ECRPATH_SCRIPTS . DS . $projectName . '.xml';
     if (false == JFile::exists($fileName)) {
         throw new Exception('Project manifest not found');
     }
     $manifest = EcrProjectHelper::getXML($fileName);
     if (!$manifest instanceof SimpleXMLElement || $manifest->getName() != 'easyproject') {
         JFactory::getApplication()->enqueueMessage(jgettext('Invalid project manifest'), 'error');
         return false;
     }
     $this->type = (string) $manifest->attributes()->type;
     $this->scope = (string) $manifest->attributes()->scope;
     $this->name = (string) $manifest->name;
     $this->comName = (string) $manifest->comname;
     //-- @Joomla!-compat 2.5
     $this->JCompat = (string) $manifest->JCompat ? (string) $manifest->JCompat : '2.5';
     $this->langFormat = (string) $manifest->langFormat;
     $this->zipPath = (string) $manifest->zipPath;
     $this->headerType = (string) $manifest->headerType;
     $dbTypes = (string) $manifest->dbTypes;
     if ('' != $dbTypes) {
         $this->dbTypes = explode(',', $dbTypes);
     }
     $this->extensionPrefix = (string) $manifest->extensionPrefix;
     $this->fromTpl = (string) $manifest->attributes()->tpl;
     /*
      * Modules
      */
     if (isset($manifest->modules->module)) {
         foreach ($manifest->modules->module as $e) {
             $c = new stdClass();
             foreach ($e->attributes() as $k => $a) {
                 $c->{$k} = (string) $a;
             }
             $c->scope = (string) $e->attributes()->scope;
             $c->position = (string) $e->attributes()->position;
             $c->ordering = (string) $e->attributes()->ordering;
             $this->modules[] = $c;
         }
     }
     /*
      * Plugins
      */
     if (isset($manifest->plugins->plugin)) {
         /* @var SimpleXMLElement $e */
         foreach ($manifest->plugins->plugin as $e) {
             $c = new stdClass();
             foreach ($e->attributes() as $k => $a) {
                 $c->{$k} = (string) $a;
             }
             $c->scope = (string) $e->attributes()->scope;
             $c->ordering = (string) $e->attributes()->ordering;
             $this->plugins[] = $c;
         }
     }
     /*
      * Tables
      */
     if (isset($manifest->tables->table)) {
         foreach ($manifest->tables->table as $e) {
             $table = new EcrTable($e->name, $e->foreign);
             $t = new stdClass();
             $t->name = (string) $e->name;
             if (isset($e->relations->relation)) {
                 foreach ($e->relations->relation as $r) {
                     $relation = new EcrTableRelation();
                     $relation->type = (string) $r->type;
                     $relation->field = (string) $r->field;
                     $relation->onTable = (string) $r->onTable;
                     $relation->onField = (string) $r->onField;
                     if (isset($r->aliases->alias)) {
                         foreach ($r->aliases->alias as $elAlias) {
                             $alias = new EcrTableRelationalias();
                             $alias->alias = (string) $elAlias->name;
                             $alias->aliasField = (string) $elAlias->field;
                             $relation->addAlias($alias);
                         }
                     }
                     $table->addRelation($relation);
                 }
                 $t->relations = $e->relations;
             } else {
                 $t->relations = array();
             }
             $this->tables[$table->name] = $table;
         }
     }
     /*
      * AutoCodes
      */
     if (isset($manifest->autoCodes->autoCode)) {
         /* @var SimpleXMLElement $code */
         foreach ($manifest->autoCodes->autoCode as $code) {
             $group = (string) $code->attributes()->group;
             $name = (string) $code->attributes()->name;
             $element = (string) $code->attributes()->element;
             $scope = (string) $code->attributes()->scope;
             $key = "{$scope}.{$group}.{$name}.{$element}";
             $EasyAutoCode = EcrProjectHelper::getAutoCode($key);
             if (!$EasyAutoCode) {
                 continue;
             }
             if (isset($code->options->option)) {
                 /* @var SimpleXMLElement $o */
                 foreach ($code->options->option as $o) {
                     $option = (string) $o;
                     $k = (string) $o->attributes()->name;
                     $EasyAutoCode->options[$k] = (string) $option;
                 }
             }
             if (isset($code->fields)) {
                 /* @var SimpleXMLElement $fieldsElement */
                 foreach ($code->fields as $fieldsElement) {
                     $key = (string) $fieldsElement->attributes()->key;
                     $fields = array();
                     if (isset($fieldsElement->field)) {
                         /* @var SimpleXMLElement $field */
                         foreach ($fieldsElement->field as $field) {
                             $f = new EcrTableField($field);
                             $k = '';
                             if ($field->attributes()->name) {
                                 $k = (string) $field->attributes()->name;
                             } else {
                                 if (isset($field->name)) {
                                     $k = (string) $field->name;
                                 }
                             }
                             $fields[$k] = $f;
                         }
                     }
                     $EasyAutoCode->fields[$key] = $fields;
                 }
             }
             $this->addAutoCode($EasyAutoCode);
         }
     }
     /*
      * Package elements - 1.6
      */
     if (isset($manifest->elements->element)) {
         foreach ($manifest->elements->element as $e) {
             $this->elements[(string) $e] = (string) $e;
         }
     }
     /*
      * BuildOptions
      */
     foreach ($manifest->buildoptions as $opt) {
         foreach ($opt as $k => $v) {
             $this->buildOpts[$k] = (string) $v;
         }
     }
     /*
      * Build presets
      */
     //-- Init the defqult preset
     $this->presets['default'] = new EcrProjectModelBuildpreset();
     if (isset($manifest->presets->preset)) {
         /* @var SimpleXMLElement $preset */
         foreach ($manifest->presets->preset as $preset) {
             $p = new EcrProjectModelBuildpreset();
             foreach ($preset as $k => $v) {
                 if ('actions' == $k) {
                     /* @var SimpleXMLElement $action */
                     foreach ($v as $action) {
                         $p->actions[] = EcrProjectAction::getInstance((string) $action->attributes()->type, (string) $action->attributes()->event)->setOptions($action);
                     }
                 } else {
                     if (is_bool($p->{$k})) {
                         $p->{(string) $k} = '1' == (string) $v ? true : false;
                     } else {
                         $p->{(string) $k} = (string) $v;
                     }
                 }
             }
             $this->presets[(string) $preset->attributes()->name] = $p;
         }
     }
     /*
      * Update servers
      */
     if (isset($manifest->updateservers->server)) {
         /* @var SimpleXMLElement $server */
         foreach ($manifest->updateservers->server as $server) {
             $u = new stdClass();
             $u->name = (string) $server->attributes()->name;
             $u->priority = (string) $server->attributes()->priority;
             $u->type = (string) $server->attributes()->type;
             $u->url = (string) $server;
             $this->updateServers[] = $u;
         }
     }
     /*
      * Actions
      */
     /*        if(isset($manifest->actions->action))
             {
                 /* @var SimpleXMLElement $action /
                 foreach($manifest->actions->action as $action)
                 {
                     $a = EcrProjectAction::getInstance(
                         (string)$action->attributes()->type, (string)$action->attributes()->event)
                     ->setOptions($action);
     
                     $this->actions[] = $a;
                 }
             }
     */
     return $this;
 }
Exemple #6
0
 /**
  * Is the xml file a valid Joomla installation manifest file ?.
  *
  * @param string $file An xmlfile path to check
  *
  * @return mixed A SimpleXMLElement, or null if the file failed to parse
  */
 private function _isManifest($file)
 {
     $xml = EcrProjectHelper::getXML($file);
     //-- If we can not load the xml file return null
     if (false == $xml) {
         return null;
     }
     /*
      * Check for a valid XML root tag.
      */
     if ($xml->getName() != 'install' && $xml->getName() != 'extension') {
         //-- Free up xml parser memory and return null
         unset($xml);
         return null;
     }
     //-- Valid manifest file return the object
     return $xml;
 }
Exemple #7
0
 /**
  * Get JText Keys from a given file.
  *
  * @param string $fileName Full path to file
  *
  * @return array keys as key, file names as value
  */
 public function getKeys($fileName)
 {
     $definitions = array();
     $cmds = array();
     if ($this->project->langFormat == 'ini') {
         $cmds['php1'] = 'JText::_';
         $cmds['php2'] = 'JText::sprintf';
         $cmds['php3'] = 'JText::printf';
         $cmds['js'] = 'Joomla.JText._';
     } else {
         $cmds['php1'] = 'jgettext';
         $cmds['php2'] = 'jgettext';
         $cmds['php3'] = 'jgettext';
         $cmds['js'] = 'jgettext';
     }
     //--RegEx pattern for JText in PHP files
     $patternPHP = "/" . $cmds['php1'] . "\\(\\s*\\'(.*)\\'\\s*\\)|" . $cmds['php1'] . "\\(\\s*\"(.*)\"\\s*\\)" . "|" . $cmds['php1'] . "\\(\\s*\\'(.*)\\'\\s*\\,|" . $cmds['php1'] . "\\(\\s*\"(.*)\"\\s*\\," . "|" . $cmds['php2'] . "\\(\\s*\\'(.*)\\'|" . $cmds['php2'] . "\\(\\s*\"(.*)\"" . "|" . $cmds['php3'] . "\\(\\s*\\'(.*)\\'|" . $cmds['php3'] . "\\(\\s*\"(.*)\"";
     if ($this->project->langFormat == 'ini') {
         // JHtml::_('grid.sort', 'FOO', ...)
         $patternPHP .= "|JHtml::_\\(\\'grid\\.sort\\'\\, \\'(.*)\\'" . "|JToolBarHelper::custom\\(\\'.*\\'\\,\\s*\\'.*\\'\\,\\s*\\'.*'\\,\\s*\\'(.*)\\'/iU";
         //(.*))\'/iU";//, 'publish.png', 'publish_f2.png', 'COM_USERS_TOOLBAR_ACTIVATE', true);/iU";
     } else {
         $patternPHP .= '/iU';
     }
     //--RegEx pattern for Joomla.JText in Javascript files
     $patternJs = "/" . $cmds['js'] . "\\(\\s*\"(.*)\"|" . $cmds['js'] . "\\(\\s*\\'(.*)\\'" . "|" . $cmds['js'] . "\\(\\s*\\'(.*)\\'\\s*\\)|" . $cmds['js'] . "\\(\\s*\"(.*)\"\\s*\\)/iU";
     //--RegEx pattern for JText in PHP files
     //        $pattern = "/JText::_\(\s*\'(.*)\'\s*\)|JText::_\(\s*\"(.*)\"\s*\)".
     //            "|JText::sprintf\(\s*\"(.*)\"|JText::sprintf\(\s*\'(.*)\'".
     //            "|JText::printf\(\s*\'(.*)\'|JText::printf\(\s*\"(.*)\"/iU";
     //
     //        //--RegEx pattern for Joomla.JText in Javascript files
     //        $patternJs =
     //        //--In case there is the second parameter (default) set
     //            "/Joomla.JText._\(\s*\"(.*)\"|Joomla.JText._\(\s*\'(.*)\'".
     //        //--'''normal''' use...
     //               "|Joomla.JText._\(\s*\'(.*)\'\s*\)|JText::_\(\s*\"(.*)\"\s*\)/iU";
     switch (JFile::getExt($fileName)) {
         case 'php':
             //--Search PHP files
             $contents = JFile::read($fileName);
             preg_match_all($patternPHP, $contents, $matches, PREG_SET_ORDER);
             foreach ($matches as $match) {
                 foreach ($match as $key => $m) {
                     $m = ltrim($m);
                     $m = rtrim($m);
                     if ($m == '' || $key == 0) {
                         continue;
                     }
                     $definitions[$m] = $fileName;
                 }
                 //foreach
             }
             //foreach
             break;
         case 'js':
             //--Search Javascript files
             $contents = JFile::read($fileName);
             preg_match_all($patternJs, $contents, $matches, PREG_SET_ORDER);
             foreach ($matches as $match) {
                 foreach ($match as $key => $m) {
                     $m = ltrim($m);
                     $m = rtrim($m);
                     if ($m == '' || $key == 0) {
                         continue;
                     }
                     $definitions[$m] = $fileName;
                 }
                 //foreach
             }
             //foreach
             break;
         case 'xml':
             //--Search XML files
             $xmlDoc = EcrProjectHelper::getXML($fileName);
             if ($xmlDoc) {
                 if ((string) $xmlDoc->description) {
                     $definitions[(string) $xmlDoc->description] = $fileName;
                 }
                 foreach ($xmlDoc->params as $params) {
                     $s = (string) $params->attributes()->group;
                     if ($s) {
                         $definitions[$s] = $fileName;
                     }
                     foreach ($params->param as $param) {
                         $s = (string) $param->attributes()->label;
                         if ($s) {
                             $definitions[$s] = $fileName;
                         }
                         $s = (string) $param->attributes()->default;
                         if ($s != (int) $s) {
                             //-- Don't add numbers
                             if ($s) {
                                 $definitions[$s] = $fileName;
                             }
                         }
                         $s = (string) $param->attributes()->description;
                         if ($s) {
                             $definitions[$s] = $fileName;
                         }
                         foreach ($param->option as $option) {
                             $s = (string) $option;
                             if ($s) {
                                 $definitions[$s] = $fileName;
                             }
                         }
                         //foreach
                     }
                     //foreach
                 }
                 //foreach
             }
             break;
         default:
             EcrHtml::message('Unknown file extension: ' . JFile::getExt($fileName), 'error');
             break;
     }
     //switch
     return $definitions;
 }
Exemple #8
0
 /**
  * Get a list of registered projects.
  *
  * @param string $type Project type
  *
  * @return array
  */
 public static function getProjectList($type = '')
 {
     static $projectList;
     if (!$projectList) {
         $projectList = array();
         if (!JFolder::exists(ECRPATH_SCRIPTS)) {
             return $projectList;
         }
         $xmlfiles = JFolder::files(ECRPATH_SCRIPTS, '.xml$', true, true);
         if (!$xmlfiles) {
             return $projectList;
         }
         foreach ($xmlfiles as $fileName) {
             $xml = EcrProjectHelper::getXML($fileName);
             if (!$xml) {
                 continue;
             }
             if ($xml->getName() != 'easyproject') {
                 continue;
             }
             $p = new stdClass();
             $p->type = (string) $xml->attributes()->type;
             $p->name = (string) $xml->name;
             $p->comName = (string) $xml->comname;
             $p->scope = (string) $xml->attributes()->scope;
             $p->position = (string) $xml->position;
             $p->ordering = (string) $xml->ordering;
             $p->fileName = JFile::stripExt(JFile::getName($fileName));
             $projectList[$p->type][] = $p;
         }
         //foreach
     }
     if ($type) {
         return isset($projectList[$type]) ? $projectList[$type] : array();
     }
     return $projectList;
 }
Exemple #9
0
 /**
  * Show the formatted log of a unit test.
  *
  * @param string $fileName Full path to XML log file
  *
  * @todo move ?
  *
  * @return string
  */
 public function showFormattedLog($fileName)
 {
     $ret = '';
     if (!JFile::exists($fileName)) {
         return 'file not found..';
     }
     if (!filesize($fileName)) {
         return 'file size is 0..';
     }
     $xmlObject = EcrProjectHelper::getXML($fileName);
     if (!$xmlObject instanceof SimpleXMLElement) {
         return 'unable to load xml parser..';
     }
     foreach ($xmlObject->testsuite as $testSuite) {
         $ret .= $this->outputSingleTest($testSuite);
         $ts = $testSuite->testsuite;
         if ($ts instanceof SimpleXMLElement && isset($ts->testcase)) {
             foreach ($ts as $t) {
                 $ret .= $this->outputSingleTest($t);
             }
             //foreach
         }
     }
     //foreach
     return $ret;
 }
Exemple #10
0
 /**
  * Setup the builder.
  *
  * @throws EcrExceptionBuilder
  * @return EcrProjectBuilder
  */
 private function setUp()
 {
     if (false == JFile::exists($this->buildBase . DS . 'manifest.xml')) {
         throw new EcrExceptionBuilder('Failed to open: ' . $this->buildBase . DS . 'manifest.xml');
     }
     if (false == JFolder::exists($this->buildBase . DS . 'tmpl')) {
         throw new EcrExceptionBuilder('Template must be in folder named tmpl - ' . $this->buildBase . DS . 'tmpl');
     }
     $folders = JFolder::folders($this->buildBase . DS . 'tmpl');
     if (false == in_array('site', $folders) && !in_array('admin', $folders)) {
         throw new EcrExceptionBuilder('Template must contain folders named admin or site');
     }
     $this->buildManifest = EcrProjectHelper::getXML($this->buildBase . DS . 'manifest.xml');
     $this->logger->log('Build manifest loaded');
     return $this;
 }