示例#1
0
 /**
  * count childs of a category / section
  * @param int $sid
  * @param string $childs
  * @return int
  */
 public static function Count($sid, $childs = 'entry')
 {
     static $cache = array();
     if (!isset($cache[$sid])) {
         $cache[$sid] = SPFactory::Model('category');
         $cache[$sid]->init($sid);
     }
     return $cache[$sid]->countChilds($childs, 1);
 }
示例#2
0
文件: field.php 项目: pelloq1/SobiPro
 public function execute()
 {
     $method = explode('.', $this->_task);
     $this->nid = 'field_' . $method[0];
     $method = 'Proxy' . ucfirst($method[1]);
     $this->fid = SPFactory::db()->select('fid', 'spdb_field', array('nid' => $this->nid, 'section' => Sobi::Section()))->loadResult();
     $this->field = SPFactory::Model('field');
     $this->field->init($this->fid);
     $this->field->{$method}();
     return true;
 }
示例#3
0
 protected function alphaMenu(&$data)
 {
     if ($this->key('alphamenu.show', Sobi::Cfg('alphamenu.show'))) {
         $letters = explode(',', $this->key('alphamenu.letters', Sobi::Cfg('alphamenu.letters')));
         $entry = SPFactory::Model('entry');
         $entry->loadFields(Sobi::Section());
         $fs = $entry->getFields('id');
         $defField = true;
         if (count($letters)) {
             foreach ($letters as $i => $letter) {
                 $letters[$i] = trim($letter);
             }
         }
         $field = explode('.', SPRequest::task('get'));
         if (strstr(SPRequest::task('get'), 'field') && isset($field[3])) {
             $field = $field[3];
             $defField = false;
         } else {
             $field = Sobi::Cfg('alphamenu.primary_field', SPFactory::config()->nameField()->get('id'));
             if (isset($fs[$field]) && $fs[$field] instanceof SPObject) {
                 $field = $fs[$field]->get('nid');
             } else {
                 $field = $fs[SPFactory::config()->nameField()->get('id')]->get('nid');
             }
         }
         if ($this->key('alphamenu.verify', Sobi::Cfg('alphamenu.verify'))) {
             $entries = SPFactory::cache()->getVar('alpha_entries_' . $field);
             if (!$entries) {
                 $alphCtrl = SPFactory::Instance('opt.listing.alpha');
                 $entries = array();
                 foreach ($letters as $letter) {
                     $params = array('letter' => $letter);
                     if ($field) {
                         $params['field'] = $field;
                     }
                     $alphCtrl->setParams($params);
                     $entries[$letter] = $alphCtrl->entries($field);
                 }
                 SPFactory::cache()->addVar($entries, 'alpha_entries_' . $field);
             }
             foreach ($letters as $letter) {
                 $le = array('_complex' => 1, '_data' => trim($letter));
                 $urlLetter = SPFactory::Instance('types.string', $letter)->toLower()->trim()->get();
                 if (count($entries[$letter])) {
                     if (!$defField) {
                         $task = 'list.alpha.' . $urlLetter . '.' . $field;
                     } else {
                         $task = 'list.alpha.' . $urlLetter;
                     }
                     $le['_attributes'] = array('url' => Sobi::Url(array('sid' => Sobi::Section(), 'task' => $task)));
                 }
                 $l[] = $le;
             }
         } else {
             foreach ($letters as $i => $letter) {
                 $urlLetter = SPFactory::Instance('types.string', $letter)->toLower()->trim()->get();
                 $l[] = array('_complex' => 1, '_data' => trim($letter), '_attributes' => array('url' => Sobi::Url(array('sid' => Sobi::Section(), 'task' => 'list.alpha.' . $urlLetter))));
             }
         }
         $fields = Sobi::Cfg('alphamenu.extra_fields_array');
         $extraFields = array();
         if (count($fields)) {
             array_unshift($fields, Sobi::Cfg('alphamenu.primary_field'));
             foreach ($fields as $fid) {
                 if (isset($fs[$fid]) && method_exists($fs[$fid], 'get')) {
                     if ($fs[$fid]->get('enabled')) {
                         $extraFields[$fs[$fid]->get('nid')] = $fs[$fid]->get('name');
                     }
                 }
             }
             if (count($extraFields) < 2) {
                 $extraFields = array();
             }
             $extraFields = array('_complex' => 1, '_data' => $extraFields, '_attributes' => array('current' => $field));
         }
         $data['alphaMenu'] = array('_complex' => 1, '_data' => array('letters' => $l, 'fields' => $extraFields));
     }
 }
示例#4
0
 /**
  * @param int $sid
  * @param bool $enabled
  * @return void
  */
 public function loadFields($sid = 0, $enabled = false)
 {
     $sid = $sid ? $sid : $this->section;
     /* @var SPdb $db */
     $db = SPFactory::db();
     static $fields = array();
     static $lang = null;
     $lang = $lang ? $lang : Sobi::Lang(false);
     if (!isset($fields[$sid])) {
         /* get fields */
         try {
             if ($enabled) {
                 $db->select('*', 'spdb_field', array('section' => $sid, 'enabled' => 1), 'position');
             } else {
                 $db->select('*', 'spdb_field', array('section' => $sid), 'position');
             }
             $fields[$sid] = $db->loadObjectList();
             Sobi::Trigger($this->name(), ucfirst(__FUNCTION__), array(&$fields));
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('CANNOT_GET_FIELDS_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
     }
     $nameField = $this->nameField();
     if (!$this->_loaded || !count($fields[$sid])) {
         if (count($fields[$sid])) {
             /* if it is an entry - prefetch the basic fields data */
             if ($this->id) {
                 $noCopy = $this->checkCopy();
                 /* in case the entry is approved, or we are editing an entry, or the user can see unapproved changes */
                 if ($this->approved || $noCopy) {
                     $ordering = 'copy.desc';
                 } else {
                     $ordering = 'copy.asc';
                 }
                 try {
                     $fdata = $db->select('*', 'spdb_field_data', array('sid' => $this->id), $ordering)->loadObjectList();
                     $db->getQuery();
                     $fieldsdata = array();
                     if (count($fdata)) {
                         foreach ($fdata as $data) {
                             /* if it has been already set - check if it is not better language choose */
                             if (isset($fieldsdata[$data->fid])) {
                                 /*
                                  * I know - the whole thing could be shorter
                                  * but it is better to understand and debug this way
                                  */
                                 if ($data->lang == $lang) {
                                     if ($noCopy) {
                                         if (!$data->copy) {
                                             $fieldsdata[$data->fid] = $data;
                                         }
                                     } else {
                                         $fieldsdata[$data->fid] = $data;
                                     }
                                 } else {
                                     $fieldsdata['langs'][$data->lang][$data->fid] = $data;
                                 }
                             } else {
                                 if ($noCopy) {
                                     if (!$data->copy) {
                                         $fieldsdata[$data->fid] = $data;
                                     }
                                 } else {
                                     $fieldsdata[$data->fid] = $data;
                                 }
                             }
                         }
                     }
                     unset($fdata);
                     SPFactory::registry()->set('fields_data_' . $this->id, $fieldsdata);
                 } catch (SPException $x) {
                     Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
                 }
             }
             foreach ($fields[$sid] as $f) {
                 /* @var SPField $field */
                 $field = SPFactory::Model('field', defined('SOBIPRO_ADM'));
                 $field->extend($f);
                 if (isset($fieldsdata[$f->fid])) {
                     $field->loadData($this->id);
                 }
                 $this->fields[] = $field;
                 $this->fieldsNids[$field->get('nid')] = $this->fields[count($this->fields) - 1];
                 $this->fieldsIds[$field->get('fid')] = $this->fields[count($this->fields) - 1];
                 /* case it was the name field */
                 if ($field->get('fid') == $nameField) {
                     /* get the entry name */
                     $this->name = $field->getRaw();
                     /* save the nid (name id) of the field where the entry name is saved */
                     $this->nameField = $field->get('nid');
                 }
             }
             $this->_loaded = true;
         }
     }
 }
示例#5
0
 protected function view()
 {
     /* determine template package */
     $tplPckg = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     Sobi::ReturnPoint();
     $this->_task = 'alpha';
     if (!$this->_model) {
         $this->setModel('section');
         $this->_model->init(Sobi::Section());
     }
     $this->visible();
     /* load template config */
     $this->template();
     $this->tplCfg($tplPckg);
     /* get limits - if defined in template config - otherwise from the section config */
     $eLimit = $this->tKey($this->template, 'entries_limit', Sobi::Cfg('list.entries_limit', 2));
     $eInLine = $this->tKey($this->template, 'entries_in_line', Sobi::Cfg('list.entries_in_line', 2));
     /* get the site to display */
     $site = SPRequest::int('site', 1);
     $eLimStart = ($site - 1) * $eLimit;
     $eCount = count($this->getEntries(0, 0, true));
     $entries = $this->getEntries($eLimit, $site);
     $compare = $this->_field ? $this->_field : $this->_nid;
     if (strlen($compare) && $compare != Sobi::Cfg('alphamenu.primary_field')) {
         $t = 'list.alpha.' . strtolower($this->_letter) . '.' . $this->_nid;
     } else {
         $t = 'list.alpha.' . strtolower($this->_letter);
     }
     $pn = SPFactory::Instance('helpers.pagenav_' . $this->tKey($this->template, 'template_type', 'xslt'), $eLimit, $eCount, $site, array('sid' => SPRequest::sid(), 'task' => $t));
     $cUrl = array('sid' => SPRequest::sid(), 'task' => $t);
     if (SPRequest::int('site', 0)) {
         $cUrl['site'] = SPRequest::int('site', 0);
     }
     SPFactory::header()->addCanonical(Sobi::Url($cUrl, true, true, true));
     /* handle meta data */
     SPFactory::header()->objMeta($this->_model);
     $letter = urldecode(SPRequest::cmd('letter'));
     /* add pathway */
     if (!$this->_fieldType) {
         SPFactory::mainframe()->addToPathway(Sobi::Txt('AL.PATH_TITLE', array('letter' => $letter)), Sobi::Url('current'));
         SPFactory::header()->addTitle(Sobi::Txt('AL.TITLE', array('letter' => $letter, 'section' => $this->_model->get('name'))), array(ceil($eCount / $eLimit), $site));
     } else {
         $field = SPFactory::Model('field');
         $field->init($this->_field);
         SPFactory::mainframe()->addToPathway(Sobi::Txt('AL.PATH_TITLE_FIELD', array('letter' => $letter, 'field' => $field->get('name'))), Sobi::Url('current'));
         SPFactory::header()->addTitle(Sobi::Txt('AL.TITLE_FIELD', array('letter' => $letter, 'section' => $this->_model->get('name'), 'field' => $field->get('name'))), array(ceil($eCount / $eLimit), $site));
     }
     /* get view class */
     $view = SPFactory::View('listing');
     $view->assign($eLimit, '$eLimit');
     $view->assign($eLimStart, '$eLimStart');
     $view->assign($eCount, '$eCount');
     $view->assign($eInLine, '$eInLine');
     $view->assign($this->_task, 'task');
     $view->assign($this->_model, 'section');
     $view->assign(Sobi::Txt('AL.PATH_TITLE', array('letter' => $this->_letter)), 'listing_name');
     $view->setConfig($this->_tCfg, $this->template);
     $view->setTemplate($tplPckg . '.' . $this->templateType . '.' . $this->template);
     $view->assign($pn->get(), 'navigation');
     $view->assign(SPFactory::user()->getCurrent(), 'visitor');
     $view->assign($entries, 'entries');
     Sobi::Trigger('AlphaListing', 'View', array(&$view));
     $view->display();
 }
示例#6
0
 /**
  * Save the config
  */
 protected function save($apply, $clone = false)
 {
     $sid = Sobi::Section();
     $this->authorise($sid);
     if ($sid) {
         $this->validate('config.general', array('task' => 'config.general', 'sid' => $sid));
     } else {
         $this->validate('config.global', array('task' => 'config.global'));
     }
     $fields = array();
     $section = false;
     $data = SPRequest::arr('spcfg', array());
     // strange thing =8-O
     if (!isset($data['alphamenu.extra_fields_array'])) {
         $data['alphamenu.extra_fields_array'] = array();
     }
     if (!isset($data['template.icon_fonts_arr'])) {
         $data['template.icon_fonts_arr'] = array();
     }
     foreach ($data as $k => $v) {
         if (is_string($v)) {
             $v = htmlspecialchars_decode($v);
         }
         //			$k = str_replace( array( 'spcfg_', '.' ), array( null, '_' ), $k );
         $k = str_replace('spcfg_', null, $k);
         $s = explode('.', $k);
         $s = $s[0];
         if (!isset($fields[$s])) {
             $fields[$s] = array();
         }
         $k = str_replace("{$s}.", null, $k);
         $c = explode('_', $k);
         if ($c[count($c) - 1] == 'array' && !is_array($v)) {
             if (!strstr($v, '|')) {
                 $v = explode(',', $v);
             } else {
                 $v = explode('|', $v);
             }
         }
         $fields[$s][$k] = $v;
         if (preg_match('/^section.*/', $k)) {
             $section = true;
         }
     }
     $values = array();
     if (count($fields)) {
         foreach ($fields as $sec => $keys) {
             if (count($keys)) {
                 foreach ($keys as $k => $v) {
                     $values[] = array('sKey' => $k, 'sValue' => $v, 'section' => Sobi::Section(), 'critical' => 0, 'cSection' => $sec);
                 }
             }
         }
     }
     if ($section) {
         /* @var $sec SPSection */
         $sec = SPFactory::Model('section');
         $sec->init(SPRequest::sid());
         $sec->getRequest('section');
         $sec->save(true);
     }
     Sobi::Trigger('SaveConfig', $this->name(), array(&$values));
     try {
         SPFactory::db()->insertArray('spdb_config', $values, true);
     } catch (SPException $x) {
         $this->response(Sobi::Back(), $x->getMessage(), false, SPC::ERROR_MSG);
     }
     if (!($section && !Sobi::Section())) {
         SPFactory::cache()->cleanAll();
     } else {
         SPFactory::cache()->cleanSection();
     }
     Sobi::Trigger('After', 'SaveConfig', array(&$values));
     $this->response(Sobi::Back(), Sobi::Txt('MSG.CONFIG_SAVED'), false, 'success');
 }
示例#7
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));
 }
示例#8
0
 protected function search()
 {
     $term = SPRequest::string('search', null, false, 'post');
     $fid = Sobi::Cfg('entry.name_field');
     /**
      * @var $field SPField
      */
     $field = SPFactory::Model('field');
     $field->init($fid);
     $s = Sobi::Section();
     $data = $field->searchSuggest($term, $s, true, true);
     SPFactory::mainframe()->cleanBuffer();
     echo json_encode($data);
     exit;
 }
示例#9
0
 public function fetchElement($name, &$label)
 {
     $sid = $this->settings()->get('sid');
     $this->oType = 'section';
     switch ($name) {
         case 'sid':
             $params = array('id' => 'sid', 'size' => 5, 'class' => 'text_area', 'style' => 'text-align: center;', 'readonly' => 'readonly');
             return SPHtml_Input::text('jform[params][sid]', $sid, $params);
             break;
         case 'tplFile':
         case 'modalTemplate':
             return $this->tplFile($this->settings()->get('tplFile'), $name == 'modalTemplate');
             break;
         case 'spOrder':
             return $this->ordering($this->settings()->get('spOrder'));
             break;
         case 'spLimit':
             return $this->limits($this->settings()->get('spLimit'));
             break;
         case 'cid':
             if (!in_array($sid, array_keys($this->sections))) {
                 $catName = SPLang::translateObject($sid, array('name'));
                 if (isset($catName[$sid]['value'])) {
                     $this->oName = $catName[$sid]['value'];
                     $this->oType = 'category';
                 }
             }
             return $this->getCat();
             break;
         default:
             $sections = array();
             if (count($this->sections)) {
                 $sections[] = Sobi::Txt('SELECT_SECTION');
                 foreach ($this->sections as $section) {
                     if (Sobi::Can('section', 'access', 'valid', $section->id)) {
                         $s = SPFactory::Model('section');
                         $s->extend($section);
                         $sections[$s->get('id')] = $s->get('name');
                     }
                 }
             }
             $params = array('id' => 'spsection', 'class' => 'text_area required');
             return SPHtml_Input::select('jform[params][section]', $sections, $this->settings()->get('section'), false, $params);
             break;
     }
 }
示例#10
0
 private function section()
 {
     Sobi::ReturnPoint();
     /* create menu */
     $menu = SPFactory::Instance('views.adm.menu', 'extensions.manage', Sobi::Section());
     $cfg = SPLoader::loadIniFile('etc.adm.section_menu');
     Sobi::Trigger('Create', 'AdmMenu', array(&$cfg));
     if (count($cfg)) {
         foreach ($cfg as $section => $keys) {
             $menu->addSection($section, $keys);
         }
     }
     Sobi::Trigger('AfterCreate', 'AdmMenu', array(&$menu));
     /* create new SigsiuTree */
     $tree = SPFactory::Instance('mlo.tree');
     /* set link */
     $tree->setHref(Sobi::Url(array('sid' => '{sid}')));
     $tree->setId('menuTree');
     /* set the task to expand the tree */
     $tree->setTask('category.expand');
     $tree->init(Sobi::Section());
     /* add the tree into the menu */
     $menu->addCustom('AMN.ENT_CAT', $tree->getTree());
     /* section model */
     $cSec = SPFactory::Model('section');
     $cSec->init(Sobi::Section());
     $db = SPFactory::db();
     $all = $db->select('*', 'spdb_plugins', array('!type' => Sobi::Cfg('apps.global_types_array'), 'enabled' => 1))->loadAssocList('pid');
     $list = $db->select('*', 'spdb_plugin_section', array('section' => Sobi::Section()))->loadAssocList('pid');
     if (count($all)) {
         foreach ($all as $id => $app) {
             if (isset($list[$id])) {
                 $all[$id]['enabled'] = $list[$id]['enabled'];
                 $all[$id]['position'] = $list[$id]['position'];
             } else {
                 $all[$id]['enabled'] = false;
                 $all[$id]['position'] = 9999;
             }
             $all[$id]['repository'] = null;
         }
     }
     /** @var $view SPExtensionsView */
     $view = SPFactory::View('extensions', true);
     $view->assign($this->_task, 'task')->assign($menu, 'menu')->assign(Sobi::Section(), 'sid')->assign($all, 'applications');
     Sobi::Trigger($this->_task, $this->name(), array(&$view));
     $view->display();
     Sobi::Trigger('After' . ucfirst($this->_task), $this->name(), array(&$view));
 }
示例#11
0
 /**
  * Returns the name/title field
  * @return SPField
  */
 public function nameField()
 {
     if (!isset(self::$fields[Sobi::Section()][Sobi::Cfg('entry.name_field')])) {
         if (Sobi::Cfg('entry.name_field')) {
             /* @var SPField $f */
             $f = SPFactory::Model('field', true);
             $f->init(Sobi::Cfg('entry.name_field'));
             self::$fields[Sobi::Section()][Sobi::Cfg('entry.name_field')] = $f;
         } else {
             SPFactory::message()->warning('NO_NAME_FIELD_SELECTED');
         }
     }
     return isset(self::$fields[Sobi::Section()][Sobi::Cfg('entry.name_field')]) ? self::$fields[Sobi::Section()][Sobi::Cfg('entry.name_field')] : SPFactory::Model('field', true);
 }
示例#12
0
文件: entry.php 项目: pelloq1/SobiPro
 /**
  */
 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();
 }
示例#13
0
 /**
  *
  * @param task
  * @return array
  */
 protected function changeState($task)
 {
     $fIds = SPRequest::arr('p_fid');
     $col = 'enabled';
     $state = '0';
     $msg = null;
     if (!$fIds) {
         if (SPRequest::int('fid')) {
             $fIds = array(SPRequest::int('fid'));
         } else {
             $fIds = array();
         }
     }
     if (!count($fIds)) {
         return array('text' => Sobi::Txt('FMN.STATE_CHANGE_NO_ID'), 'type' => SPC::ERROR_MSG);
     }
     switch ($task) {
         case 'hide':
         case 'publish':
             $col = 'enabled';
             $state = $task == 'publish' ? 1 : 0;
             break;
         case 'setRequired':
         case 'setNotRequired':
             $col = 'required';
             $state = $task == 'setRequired' ? 1 : 0;
             break;
         case 'setEditable':
         case 'setNotEditable':
             $col = 'editable';
             $state = $task == 'setEditable' ? 1 : 0;
             break;
         case 'setFee':
         case 'setFree':
             $col = 'isFree';
             $state = $task == 'setFree' ? 1 : 0;
             break;
             /** @since 1.1 - single row only from the field list */
         /** @since 1.1 - single row only from the field list */
         case 'toggle':
             $fIds = array();
             $fid = SPRequest::int('fid');
             $attribute = explode('.', SPRequest::task());
             /** now you know what a naming convention is for! Right? Damn!!! */
             $attribute = in_array($attribute[2], array('editable', 'enabled', 'required')) ? $attribute[2] : 'is' . ucfirst($attribute[2]);
             $this->_model = SPFactory::Model('field', true)->init($fid);
             $current = $this->_model->get($attribute);
             try {
                 SPFactory::db()->update('spdb_field', array($attribute => !$current), array('fid' => $fid), 1);
                 $msg = Sobi::Txt('FM.STATE_CHANGED', array('fid' => $fid));
             } catch (SPException $x) {
                 Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 500, __LINE__, __FILE__);
                 $msg = Sobi::Txt('FM.STATE_NOT_CHANGED', array('fid' => $fid));
             }
             break;
     }
     if (count($fIds)) {
         $msg = array();
         foreach ($fIds as $fid) {
             try {
                 SPFactory::db()->update('spdb_field', array($col => $state), array('fid' => $fid), 1);
                 $msg[] = array('text' => Sobi::Txt('FM.STATE_CHANGED', array('fid' => $fid)), 'type' => 'success');
             } catch (SPException $x) {
                 Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 500, __LINE__, __FILE__);
                 $msg[] = array('text' => Sobi::Txt('FM.STATE_NOT_CHANGED', array('fid' => $fid)), 'type' => 'error');
             }
         }
     }
     SPFactory::cache()->cleanSection(Sobi::Section());
     return $msg;
 }
示例#14
0
 private function travelCats($sid, &$cats, $init = false)
 {
     $category = SPFactory::Model($init == true ? 'section' : 'category');
     $category->init($sid);
     $cats[$sid] = array('sid' => $sid, 'state' => $category->get('state'), 'name' => $category->get('name'), 'type' => $category->get('oType'), 'childs' => array());
     $childs = $category->getChilds('category');
     if (count($childs)) {
         foreach ($childs as $id => $name) {
             $this->travelCats($id, $cats[$sid]['childs']);
         }
     }
 }
示例#15
0
 /**
  * @param $categories
  * @param $sid
  * @return void
  */
 private function categories($categories, $sid)
 {
     for ($i = 0; $i < $categories->length; $i++) {
         $category = $categories->item($i);
         if ($category->nodeName == 'category') {
             $name = $this->txt($category, 'name');
             $introtext = $this->txt($category, 'introtext');
             $description = $this->txt($category, 'description');
             $icon = $this->txt($category, 'icon');
             $cat = SPFactory::Model('category');
             $cat->set('state', 1);
             /* Additional data */
             $options = $category->getElementsByTagName('option');
             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;
                     }
                     $cat->set($option->getAttribute('attribute'), $v);
                 }
             }
             /* Base category data */
             $cat->set('description', $description);
             $cat->set('name', $name);
             $cat->set('nid', SPLang::nid($name));
             $cat->set('introtext', $introtext);
             $cat->set('parent', $sid);
             $cat->set('icon', $icon);
             /* save the category */
             $cat->save();
             /* Handle subcats */
             $childs = $this->xdef->query("childs/category", $category);
             if ($childs && $childs->length) {
                 if ($childs instanceof DOMNodeList && $childs->length) {
                     $this->categories($childs, $cat->get('id'));
                 }
             }
         }
     }
 }