Example #1
0
 /**
  */
 private function getSections()
 {
     try {
         $sections = SPFactory::db()->select('*', 'spdb_object', array('oType' => 'section'), 'id')->loadObjectList();
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('CANNOT_GET_SECTIONS_LIST', $x->getMessage()), SPC::WARNING, 500, __LINE__, __FILE__);
     }
     if (count($sections)) {
         foreach ($sections as $section) {
             if (Sobi::Can('section', 'access', $section->id, 'valid')) {
                 $s = SPFactory::Section($section->id);
                 $s->extend($section);
                 $this->_sections[] = $s;
             }
         }
         Sobi::Trigger($this->name(), __FUNCTION__, array(&$this->_sections));
     }
 }
Example #2
0
 protected function addEntries($ids)
 {
     static $sections = array();
     $entries = array();
     if (count($ids)) {
         foreach ($ids as $sid) {
             $entry = SPFactory::Entry($sid);
             if (!isset($sections[$entry->get('section')])) {
                 $sections[$entry->get('section')] = SPFactory::Section($entry->get('section'));
             }
             $entry->setProperty('section', $sections[$entry->get('section')]);
             $entries[] = $entry;
         }
     }
     return $entries;
 }
Example #3
0
 /**
  * Returns current section id
  *
  * @param bool $name
  * @return int
  */
 public static function Section($name = false)
 {
     static $section = null;
     if (!$name) {
         return SPFactory::registry()->get('current_section');
     } elseif ((string) $name == 'nid') {
         if (!$section) {
             $section = SPFactory::Section(SPFactory::registry()->get('current_section'));
         }
         return $section->get('nid');
     } else {
         return SPFactory::registry()->get('current_section_name');
     }
 }
Example #4
0
 public function entryFormLabel($sid, $section)
 {
     return Sobi::Txt('MENU_LINK_TO_ADD_ENTRY_FORM_SELECTED', $section == $sid ? SPFactory::Section($sid)->get('name') : SPFactory::Category($sid)->get('name'));
 }
Example #5
0
 protected function form()
 {
     $ssid = 0;
     /* determine template package */
     $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     /* load template config */
     $this->template();
     $this->tplCfg($tplPackage, 'search');
     if ($this->template == 'results') {
         $this->template = 'view';
     }
     if (!$this->_model) {
         $this->setModel('section');
         $this->_model->init(Sobi::Section());
     }
     /* handle meta data */
     SPFactory::header()->objMeta($this->_model);
     $section = SPFactory::Section(Sobi::Section());
     SPFactory::header()->addKeyword($section->get('sfMetaKeys'))->addDescription($section->get('sfMetaDesc'));
     /* add pathway */
     SPFactory::mainframe()->addToPathway(Sobi::Txt('SH.PATH_TITLE'), Sobi::Url('current'));
     SPFactory::mainframe()->setTitle(Sobi::Txt('SH.TITLE', array('section' => $this->_model->get('name'))));
     Sobi::Trigger('OnFormStart', 'Search');
     SPLoader::loadClass('mlo.input');
     $view = SPFactory::View('search');
     /* if we cannot transfer the search id in cookie */
     if (!$this->session($ssid)) {
         $view->addHidden($ssid, 'ssid');
     }
     if ($this->_task == 'results' && $ssid) {
         /* get limits - if defined in template config - otherwise from the section config */
         $eLimit = $this->tKey($this->template, 'entries_limit', Sobi::Cfg('search.entries_limit', Sobi::Cfg('list.entries_limit', 2)));
         $eInLine = $this->tKey($this->template, 'entries_in_line', Sobi::Cfg('search.entries_in_line', Sobi::Cfg('list.entries_in_line', 2)));
         /* get the site to display */
         $site = SPRequest::int('site', 1);
         $eLimStart = ($site - 1) * $eLimit;
         $view->assign($eLimit, '$eLimit');
         $view->assign($eLimStart, '$eLimStart');
         $view->assign($eInLine, '$eInLine');
         $entries = $this->getResults($ssid, $this->template);
         $view->assign(count($this->_results), '$eCount');
         $view->assign($this->_resultsByPriority, 'priorities');
         $view->assign($entries, 'entries');
         /* create page navigation */
         $pnc = SPLoader::loadClass('helpers.pagenav_' . $this->tKey($this->template, 'template_type', 'xslt'));
         $url = array('task' => 'search.results', 'sid' => SPRequest::sid());
         if (!SPRequest::cmd('ssid', null, 'cookie')) {
             $url['ssid'] = $ssid;
         }
         /* @var SPPageNavXSLT $pn */
         $pn = new $pnc($eLimit, $this->_resultsCount, $site, $url);
         $view->assign($pn->get(), 'navigation');
         /**
          * this is te special case:
          * no matter what task we currently have - if someone called this we need the data for the V-Card
          * Soe we have to trigger all these plugins we need and therefore also fake the task
          */
         $task = 'list.custom';
         SPFactory::registry()->set('task', $task);
     } else {
         $eLimit = -1;
         $view->assign($eLimit, '$eCount');
     }
     /* load all fields */
     $fields = $this->loadFields();
     if (isset($this->_request['search_for'])) {
         $view->assign($this->_request['search_for'], 'search_for');
         $view->assign($this->_request['phrase'], 'search_phrase');
     }
     $view->assign($fields, 'fields');
     $view->assign(SPFactory::user()->getCurrent(), 'visitor');
     $view->assign($this->_task, 'task');
     $view->addHidden(Sobi::Section(), 'sid');
     $view->addHidden('search.search', 'task');
     $view->setConfig($this->_tCfg, $this->template);
     $view->setTemplate($tplPackage . '.' . $this->templateType . '.' . $this->template);
     Sobi::Trigger('OnCreateView', 'Search', array(&$view));
     $view->display();
 }
Example #6
0
 protected function determineObjectType($sid)
 {
     if ($this->task) {
         $this->oTypeName = Sobi::Txt('TASK_' . strtoupper($this->task));
         $this->oType = $this->task;
     } elseif ($sid) {
         $this->oType = SPFactory::db()->select('oType', 'spdb_object', array('id' => $sid))->loadResult();
         $this->oTypeName = Sobi::Txt('OTYPE_' . strtoupper($this->oType));
     }
     switch ($this->oType) {
         case 'entry':
             $this->oName = SPFactory::Entry($sid)->get('name');
             break;
         case 'section':
             $this->oName = SPFactory::Section($sid)->get('name');
             break;
         case 'category':
             $this->oName = SPFactory::Category($sid)->get('name');
             break;
         default:
             $this->oName = null;
             break;
     }
 }
Example #7
0
 /**
  * Try to find out what we have to do
  *     - If we have a task - parse task
  *  - If we don't have a task, but sid, we are going via default object task
  *  - Otherwise it could be only the frontpage
  * @throws SPException
  * @return void
  */
 private function route()
 {
     $cache = true;
     if (Sobi::Cfg('cache.xml_enabled')) {
         if ($this->_model instanceof stdClass && !($this->_model instanceof stdClass && $this->_model->owner == Sobi::My('id'))) {
             if (in_array($this->_model->owner, array('entry'))) {
                 $cache = false;
             }
         }
     }
     if ($cache && Sobi::Cfg('cache.xml_enabled')) {
         $this->_cache = SPFactory::cache()->view();
     }
     if (!$this->_cache) {
         /* if we have a task */
         if ($this->_task && $this->_task != 'panel') {
             if (!$this->routeTask()) {
                 throw new SPException(SPLang::e('Cannot interpret task "%s"', $this->_task));
             }
         } elseif ($this->_sid) {
             if (!$this->routeObj()) {
                 throw new SPException(SPLang::e('Cannot route object with id "%d"', $this->_sid));
             }
         } else {
             $this->frontpage();
         }
     } else {
         try {
             $task = $this->_task;
             if (!$task && $this->_sid) {
                 $ctrl = SPFactory::Controller($this->_model->oType);
                 $this->setController($ctrl);
                 $this->_model = SPFactory::object($this->_sid);
                 $model = SPLoader::loadModel($this->_model->oType, false, false);
                 if ($model) {
                     $this->_ctrl->setModel($model);
                     if ($this->_model instanceof stdClass) {
                         $this->_ctrl->extend($this->_model, true);
                     }
                 }
             }
             if (strstr($task, '.')) {
                 $task = explode('.', $task);
                 $obj = trim(array_shift($task));
                 if ($obj == 'list' || $obj == 'ls') {
                     $obj = 'listing';
                 }
                 $task = trim(implode('.', $task));
                 $ctrl = SPFactory::Controller($obj);
                 $this->setController($ctrl);
                 $model = SPLoader::loadModel($obj, false, false);
                 if ($model) {
                     $this->_ctrl->setModel($model);
                     if ($this->_model instanceof stdClass) {
                         $this->_ctrl->extend($this->_model, true);
                     }
                 } else {
                     $this->_ctrl->setModel(SPFactory::Section($this->_section));
                     if ($this->_model instanceof stdClass) {
                         $this->_ctrl->extend($this->_model, true);
                     }
                 }
             } elseif ($task) {
                 /** Special controllers not inherited from object and without model */
                 $ctrl = SPFactory::Controller($task);
                 $this->setController($ctrl);
                 $this->_ctrl->setModel(SPFactory::Section($this->_section));
                 if ($this->_model instanceof stdClass) {
                     $this->_ctrl->extend($this->_model, true);
                 }
             }
             $this->_ctrl->setTask($task);
             $this->_ctrl->visible();
         } catch (SPException $x) {
             Sobi::Error('CachedView', $x->getMessage());
             $this->_cache = null;
             $this->route();
         }
     }
 }
Example #8
0
 /**
  */
 private function editForm()
 {
     if ($this->_task != 'add') {
         $sid = SPRequest::sid();
         $sid = $sid ? $sid : SPRequest::int('pid');
     } else {
         $this->authorise($this->_task, 'own');
         $this->_model = null;
         $sid = SPRequest::int('pid');
         $section = SPFactory::Section(Sobi::Section());
     }
     if ($this->_model && $this->_model->isCheckedOut()) {
         Sobi::Redirect(Sobi::Url(array('sid' => SPRequest::sid())), Sobi::Txt('EN.IS_CHECKED_OUT', $this->_model->get('name')), SPC::ERROR_MSG, true);
     }
     /* determine template package */
     $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     /* load template config */
     $this->template();
     $this->tplCfg($tplPackage);
     /* check if we have stored last edit in cache */
     $this->getCache(SPRequest::string('editentry', null, false, 'cookie'), 'editcache');
     $section = SPFactory::Model('section');
     $section->init(Sobi::Section());
     SPFactory::cache()->setJoomlaCaching(false);
     if ($this->_model) {
         /* handle meta data */
         SPFactory::header()->objMeta($this->_model);
         /* add pathway */
         SPFactory::mainframe()->addObjToPathway($this->_model);
     } else {
         /* handle meta data */
         SPFactory::header()->objMeta($section);
         if ($this->_task == 'add') {
             SPFactory::header()->addKeyword($section->get('efMetaKeys'))->addDescription($section->get('efMetaDesc'));
         }
         SPFactory::mainframe()->addToPathway(Sobi::Txt('EN.ADD_PATH_TITLE'), Sobi::Url('current'));
         SPFactory::mainframe()->setTitle(Sobi::Txt('EN.ADD_TITLE', array('section' => $section->get('name'))));
         /* add pathway */
         SPFactory::mainframe()->addObjToPathway($section);
         $this->setModel(SPLoader::loadModel('entry'));
     }
     $this->_model->formatDatesToEdit();
     $id = $this->_model->get('id');
     if (!$id) {
         $this->_model->set('state', 1);
     }
     if ($this->_task != 'add' && !$this->authorise($this->_task, $this->_model->get('owner') == Sobi::My('id') ? 'own' : '*')) {
         throw new SPException(SPLang::e('YOU_ARE_NOT_AUTH_TO_EDIT_THIS_ENTRY'));
     }
     $this->_model->loadFields(Sobi::Reg('current_section'));
     /* get fields for this section */
     $fields = $this->_model->get('fields');
     if (!count($fields)) {
         throw new SPException(SPLang::e('CANNOT_GET_FIELDS_IN_SECTION', Sobi::Reg('current_section')));
     }
     /* create the validation script to check if required fields are filled in and the filters, if any, match */
     $this->createValidationScript($fields);
     /* check out the model */
     $this->_model->checkOut();
     $class = SPLoader::loadView('entry');
     $view = new $class($this->template);
     $view->assign($this->_model, 'entry');
     $cache = Sobi::Reg('editcache');
     /* get the categories */
     if (isset($cache) && isset($cache['entry_parent'])) {
         $cats = explode(',', $cache['entry_parent']);
     } else {
         $cats = $this->_model->getCategories(true);
     }
     if (count($cats)) {
         $tCats = array();
         foreach ($cats as $cid) {
             $tCats2 = SPFactory::config()->getParentPath((int) $cid, true);
             if (is_array($tCats2) && count($tCats2)) {
                 $tCats[] = implode(Sobi::Cfg('string.path_separator', ' > '), $tCats2);
             }
         }
         if (count($tCats)) {
             $view->assign(implode("\n", $tCats), 'parent_path');
         }
         $view->assign(implode(", ", $cats), 'parents');
     } else {
         $parent = $sid == Sobi::Reg('current_section') ? 0 : $sid;
         if ($parent) {
             $view->assign(implode(Sobi::Cfg('string.path_separator', ' > '), SPFactory::config()->getParentPath($parent, true)), 'parent_path');
         }
         $view->assign($parent, 'parents');
     }
     $view->assign($this->_task, 'task');
     $view->assign($fields, 'fields');
     $view->assign($id, 'id');
     $view->assign($id, 'sid');
     $view->assign(SPFactory::user()->getCurrent(), 'visitor');
     $view->setConfig($this->_tCfg, $this->template);
     $view->setTemplate($tplPackage . '.' . $this->templateType . '.' . ($this->template == 'add' ? 'edit' : $this->template));
     $view->addHidden($sid ? $sid : SPRequest::sid(), 'pid');
     $view->addHidden($id, 'sid');
     $view->addHidden(SPRequest::int('pid') && SPRequest::int('pid') != $id ? SPRequest::int('pid') : Sobi::Section(), 'pid');
     $view->addHidden('entry.submit', SOBI_TASK);
     Sobi::Trigger($this->name(), __FUNCTION__, array(&$view));
     $view->display();
 }