Example #1
0
 public function addSection($name, $section)
 {
     Sobi::Trigger('addSection', 'SPAdmSiteMenu', array($name, $section));
     if ($name == 'AMN.APPS_HEAD' || $name == 'AMN.APPS_SECTION_HEAD') {
         $p = SPFactory::Controller('extensions', true);
         $links = $p->appsMenu();
         if (is_array($links)) {
             $section = array_merge($section, $links);
         }
     } elseif ($name == 'AMN.APPS_SECTION_TPL' && Sobi::Section() && Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE)) {
         $p = SPFactory::Controller('template', true);
         $this->_custom[$name]['after'][] = $p->getTemplateTree(Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE));
     }
     $this->_sections[$name] =& $section;
 }
Example #2
0
 /**
  * @return bool
  */
 private function routeObj()
 {
     if ($this->_model instanceof stdClass && isset($this->_model->id)) {
         if ($this->_sid && $this->_model->id != $this->_sid) {
             $this->_model = SPFactory::object($this->_sid);
         }
     }
     try {
         $ctrl = SPFactory::Controller($this->_model->oType, true);
         if ($ctrl instanceof SPController) {
             $this->setController($ctrl);
             $this->_ctrl->setModel(SPLoader::loadModel($this->_model->oType));
             /** @noinspection PhpParamsInspection */
             $this->_ctrl->extend($this->_model);
             $this->_ctrl->setTask($this->_task);
         }
     } catch (SPException $x) {
         Sobi::Error('CoreCtrl', SPLang::e('Cannot route object: %s.', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     return true;
 }
Example #3
0
 /**
  */
 public function save($update = false, $init = true)
 {
     /* @var SPdb $db */
     $db =& SPFactory::db();
     /* check nid */
     if (!$update) {
         $c = 1;
         while ($c) {
             /* section name id has to be unique */
             try {
                 $db->select('COUNT(nid)', 'spdb_object', array('oType' => 'section', 'nid' => $this->nid));
                 $c = $db->loadResult();
                 if ($c > 0) {
                     $this->nid = $this->nid . '_' . rand(0, 1000);
                 }
             } catch (SPException $x) {
                 Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
             }
         }
     }
     SPFactory::registry()->set('current_section', $this->id);
     $db->transaction();
     parent::save();
     /* case adding new section, define the default title field */
     if (!$update && $init) {
         $field = SPFactory::Model('field', true);
         $fid = $field->saveNew(array('name' => 'Name', 'nid' => 'field_name', 'showIn' => 'both', 'fieldType' => 'inbox', 'enabled' => 1, 'required' => 1, 'editable' => 1, 'section' => $this->id, 'inSearch' => 1, 'searchMethod' => 'general', 'isFree' => 1, 'editLimit' => -1, 'withLabel' => 1));
         $field = SPFactory::Model('field', true);
         $field->saveNew(array('name' => 'Category', 'nid' => 'field_category', 'showIn' => 'hidden', 'fieldType' => 'category', 'enabled' => 1, 'required' => 1, 'editable' => 1, 'section' => $this->id, 'inSearch' => 1, 'searchMethod' => 'select', 'isFree' => 1, 'editLimit' => -1, 'withLabel' => 1, 'method' => 'select', 'isPrimary' => true));
         SPFactory::config()->saveCfg('entry.name_field', $fid)->saveCfg('list.entries_ordering', 'field_name')->saveCfg('template.icon_fonts_arr', array('font-awesome-3-local'));
         SPFactory::Controller('acl', true)->addNewRule($this->get('name'), array($this->id), array('section.access.valid', 'category.access.valid', 'entry.access.valid', 'entry.add.own', 'section.search.*'), array('visitor', 'registered'), 'Default permissions for the section "' . $this->get('name') . '"');
     }
     /* insert relation */
     try {
         $db->insertUpdate('spdb_relations', array('id' => $this->id, 'pid' => 0, 'oType' => 'section', 'position' => 1, 'validSince' => $this->validSince, 'validUntil' => $this->validUntil));
     } catch (SPException $x) {
         $db->rollback();
         Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     /* if there was no errors, commit the database changes */
     $db->commit();
     //		if( !$update ) {
     //			SPFactory::mainframe()->msg( Sobi::Txt( 'SEC.CREATED' ) );
     //		}
     SPFactory::cache()->cleanSection();
     /* trigger plugins */
     Sobi::Trigger('afterSave', $this->name(), array(&$this));
 }
Example #4
0
 private function fetch()
 {
     $msg = SPFactory::Controller('progress');
     if (!SPFactory::mainframe()->checkToken('get')) {
         Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::WARNING, 0, __LINE__, __FILE__);
         $msg->error(SPLang::e('REPO_ERR', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task())));
         exit;
     }
     $msg->progress(0, Sobi::Txt('EX.GETTING_REPOS'));
     $repos = SPLoader::dirPath('etc.repos', 'front');
     $repos = SPFactory::Instance('base.fs.directory', $repos);
     $repos = $repos->searchFile('repository.xml', true, 2);
     $repos = array_keys($repos);
     $cr = count($repos);
     $progress = 5;
     $msg->progress($progress, Sobi::Txt('EX.FOUND_NUM_REPOS', array('count' => $cr)));
     $repository = SPFactory::Instance('services.installers.repository');
     //		sleep( 5 );
     $steps = 2;
     $pstep = 80 / $cr / $steps;
     $list = array();
     $r = array();
     for ($i = 0; $i < $cr; $i++) {
         $repository->loadDefinition($repos[$i]);
         $progress += $pstep / $steps;
         $msg->progress($progress, Sobi::Txt('EX.CON_TO_REPO_D_D', array('num' => $i + 1, 'from' => $cr)));
         try {
             $repository->connect($msg);
             sleep(1);
         } catch (SPException $x) {
             $msg->error(SPLang::e('REPO_ERR', $x->getMessage()));
             exit;
         }
         $progress += $pstep / $steps;
         $msg->progress($progress, Sobi::Txt('EX.FETCHING_FROM_REPO_D_D', array('num' => $i + 1, 'from' => $cr)));
         try {
             $ver = SPFactory::CmsHelper()->cmsVersion();
             $l = $repository->fetchList($repository->get('token'), 'Joomla ' . $ver['major'] . '.' . $ver['minor']);
             //				sleep( 1 );
         } catch (SPException $x) {
             $msg->error(SPLang::e('REPO_ERR', $x->getMessage()));
         }
         if (is_array($l)) {
             if (count($l)) {
                 $pid = $repository->get('id');
                 foreach ($l as $eid => $values) {
                     $eid = str_replace(array('.', '_'), '-', $eid);
                     $values['repository'] = $pid;
                     $l[$eid] = $values;
                 }
                 $r[$pid] = $repository->get('url');
             }
             $list = array_merge($list, $l);
         }
         $progress += $pstep / $steps;
         $msg->progress($progress, Sobi::Txt('EX.FETCHED_LIST_FROM_REPOSITORY', array('count' => count($l), 'num' => $i + 1, 'from' => $cr)));
     }
     $progress += 5;
     if (count($list)) {
         $msg->progress($progress, Sobi::Txt('EX.FETCHED_D_EXTENSIONS', array('count' => count($list))));
         $extensions = array();
         $extensions['created'] = time();
         $extensions['createdBy'] = array('id' => Sobi::My('id'), 'name' => Sobi::My('name'));
         $extensions['repositories'] = $r;
         $extensions['extensions'] = $list;
         $progress += 10;
         $msg->progress($progress);
         /** @var SPFile $file */
         $file = SPFactory::Instance('base.fs.file', SPLoader::path('etc.extensions', 'front', false, 'xml'));
         $def = SPFactory::Instance('types.array');
         $file->content($def->toXML($extensions, 'extensionsList'));
         $msg->progress($progress, $def->toXML($extensions, 'extensionsList'));
         try {
             $file->save();
         } catch (SPException $x) {
             $msg->progress($progress, $x->getMessage());
         }
         //			sleep( 1 );
     }
     $msg->progress(100, Sobi::Txt('EX.EXT_LIST_UPDATED'), SPC::SUCCESS_MSG);
     //		SPFactory::message()->success( Sobi::Txt( 'EX.EXT_LIST_UPDATED' ), false );
     exit;
 }
Example #5
0
 /**
  * @param string $tpl
  * @return void
  */
 private function section($tpl)
 {
     $path = 'install/section/';
     /* get base section data */
     $name = $this->xGetString($path . 'name');
     $description = $this->xGetString($path . 'description');
     /* create new section */
     $section =& SPFactory::Instance('models.section');
     $section->set('description', $description);
     $section->set('name', $name);
     $section->set('nid', SPLang::nid($name));
     $fields =& $this->xGetChilds($path . 'fields/*');
     if ($fields instanceof DOMNodeList && $fields->length) {
         $section->save(false, false);
     } else {
         $section->save();
     }
     $sid = $section->get('id');
     $settings = array();
     $options = $this->xGetChilds($path . 'options/*');
     if ($options instanceof DOMNodeList && $options->length) {
         foreach ($options as $option) {
             $v = $option->nodeValue;
             if (in_array($option->nodeValue, array('true', 'false'))) {
                 $v = $option->nodeValue == 'true' ? true : false;
             }
             $key = explode('.', $option->getAttribute('attribute'));
             $settings[trim($key[0])][trim($key[1])] = $v;
         }
     }
     /* if there are fields to create */
     if ($fields instanceof DOMNodeList && $fields->length) {
         $fids = $this->fields($fields, $sid);
         $settings['entry']['name_field'] = $fids[$this->xGetString($path . 'nameField')];
         $settings['list']['entries_ordering'] = $this->xGetString($path . 'nameField');
     } else {
         $settings['list']['entries_ordering'] = $this->xGetString($path . 'nameField');
     }
     $settings['section']['template'] = $tpl;
     $settings['general']['top_menu'] = $this->xGetString($path . 'showTopMenu') == 'true' ? true : false;
     $settings['list']['categories_in_line'] = (int) $this->xGetString($path . 'catsInLine');
     $settings['list']['cat_desc'] = $this->xGetString($path . 'showCategoryDesc') == 'true' ? true : false;
     $settings['list']['cat_meta'] = $this->xGetString($path . 'showCategoryMeta') == 'true' ? true : false;
     $settings['list']['subcats'] = $this->xGetString($path . 'showCategorySubcats') == 'true' ? true : false;
     $settings['list']['categories_in_line'] = (int) $this->xGetString($path . 'catsInLine');
     $settings['list']['entries_in_line'] = (int) $this->xGetString($path . 'entriesInLine');
     $settings['list']['entries_limit'] = (int) $this->xGetString($path . 'entriesOnPage');
     $settings['list']['entry_meta'] = $this->xGetString($path . 'showEntryMeta') == 'true' ? true : false;
     $settings['list']['entry_cats'] = $this->xGetString($path . 'showEntryCategories') == 'true' ? true : false;
     $values = array();
     foreach ($settings as $section => $setting) {
         foreach ($setting as $k => $v) {
             $values[] = array('sKey' => $k, 'sValue' => $v, 'section' => $sid, 'critical' => 0, 'cSection' => $section);
         }
     }
     try {
         SPFactory::db()->insertArray('spdb_config', $values, true);
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
     /* create default permission */
     SPFactory::Controller('acl', true)->addNewRule($name, array($sid), array('section.access.valid', 'category.access.valid', 'entry.access.valid', 'entry.add.own'), array('visitor', 'registered'), "Default permissions for the section {$name}");
     $categories = $this->xGetChilds($path . 'categories/*');
     if ($categories instanceof DOMNodeList && $categories->length) {
         $this->categories($categories, $sid);
     }
     Sobi::Trigger('After', 'SaveConfig', array(&$values));
 }
Example #6
0
 /**
  * @return bool
  */
 private function routeObj()
 {
     try {
         $ctrl = SPFactory::Controller($this->_model->oType);
         if ($ctrl instanceof SPController) {
             $this->setController($ctrl);
             if ($this->_model->id == SPRequest::sid()) {
                 // just to use the pre-fetched entry
                 if ($this->_model->oType == 'entry') {
                     $e = SPFactory::Entry($this->_model->id);
                     // object has been stored anyway in the SPFactory::object method
                     // and also already initialized
                     // therefore it will be now rewritten and because the init flag is set to true
                     // the name is getting lost
                     // $e->extend( $this->_model );
                     $this->_ctrl->setModel($e);
                 } else {
                     $this->_ctrl->setModel(SPLoader::loadModel($this->_model->oType));
                     $this->_ctrl->extend($this->_model);
                 }
             } else {
                 $this->_ctrl->extend(SPFactory::object(SPRequest::sid()));
             }
             $this->_ctrl->setTask($this->_task);
         }
     } catch (SPException $x) {
         if (defined('SOBI_TESTS')) {
             Sobi::Error('CoreCtrl', SPLang::e('Cannot set controller. %s.', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         } else {
             SPFactory::mainframe()->setRedirect(Sobi::Reg('live_site'), SPLang::e('PAGE_NOT_FOUND'), SPC::ERROR_MSG, true);
         }
     }
     return true;
 }