示例#1
0
 /**
  * Get an action.
  *
  * @AJAX
  *
  * @return void
  */
 public function getAction()
 {
     $input = JFactory::getApplication()->input;
     try {
         $options = json_decode($input->getHtml('options'));
         $options = $options ?: array();
         $cnt = $input->getInt('cnt');
         $this->response->message = EcrProjectAction::getInstance($input->get('type'))->setOptions($options)->getFields($cnt);
     } catch (Exception $e) {
         $this->response->debug = $e->getMessage();
         $this->response->status = $e->getCode() ?: 1;
     }
     echo $this->response;
     jexit();
 }
示例#2
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;
 }
示例#3
0
 /**
  * @static
  *
  * @param array $attribs
  *
  * @return string
  */
 public static function actions(array $attribs = array())
 {
     //-- aka autoload :P
     JHtml::_('select.option', 'foo');
     $options = array();
     $options[] = JHtmlSelect::option('', jgettext('Select...'));
     /* @var DirectoryIterator $fileInfo */
     foreach (new DirectoryIterator(JPATH_COMPONENT . '/helpers/project/action') as $fileInfo) {
         if ($fileInfo->isDot()) {
             continue;
         }
         $type = JFile::stripExt($fileInfo->getFilename());
         $action = EcrProjectAction::getInstance($type);
         $options[] = JHtmlSelect::option($type, EcrProjectAction::getInstance($type)->name);
     }
     if (JFolder::exists(ECRPATH_DATA . '/actions')) {
         $fileNames = JFolder::files(ECRPATH_DATA . '/actions', 'php');
         if ($fileNames) {
             foreach ($fileNames as $fileName) {
                 require_once ECRPATH_DATA . '/actions/' . $fileName;
                 $type = JFile::stripExt($fileName);
                 $action = EcrProjectAction::getInstance($type);
                 $options[] = JHtmlSelect::option('ecr_custom_' . $type, EcrProjectAction::getInstance($type)->name);
             }
         }
     }
     $attribs = array_merge(array('class' => 'span2'), $attribs);
     return JHtmlSelect::genericlist($options, 'sel_actions', array('list.attr' => $attribs));
 }