/** * Simple initialisation method * */ public function init() { if (self::$cs) { Sobi::Error('config', SPLang::e('CRITICAL_SECTION_VIOLATED'), SPC::ERROR, 500, __LINE__, __CLASS__); } /* define critical section to avoid infinite loops */ self::$cs = true; $nameField = self::key('entry.name_field'); if ($nameField) { $fc = SPLoader::loadModel('field'); $field = new $fc(); $field->init($nameField); $this->set('name_field_nid', $field->get('nid'), 'entry'); $this->set('name_field_id', $field->get('fid'), 'entry'); } if (defined('SOBIPRO_ADM')) { if (self::key('language.adm_domain')) { SPLang::registerDomain(self::key('language.adm_domain')); } } else { if (self::key('language.domain')) { SPLang::registerDomain(self::key('language.domain')); } } /* set allowed request attributes and tags */ SPRequest::setTagsAllowed($this->key('html.allowed_tags_array')); SPRequest::setAttributesAllowed($this->key('html.allowed_attributes_array')); $this->_store['general']['root'] = SOBI_ROOT; $this->_store['general']['path'] = SOBI_PATH; $this->_store['general']['cms'] = SOBI_CMS; $this->_store['general']['live_path'] = SOBI_LIVE_PATH; /* leave critical section */ self::$cs = false; }
/** * Gets the data for a field and save it in the database * @param SPEntry $entry * @param string $request * @return bool */ public function saveData(&$entry, $request = 'POST') { if (!$this->enabled) { return false; } $data = $this->verify($entry, $request); $time = SPRequest::now(); $IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER'); $uid = Sobi::My('id'); /* if we are here, we can save these data */ /* @var SPdb $db */ $db =& SPFactory::db(); if ($this->allowHtml) { /* filter data */ if (count($this->allowedAttributes)) { SPRequest::setAttributesAllowed($this->allowedAttributes); } if (count($this->allowedTags)) { SPRequest::setTagsAllowed($this->allowedTags); } $data = SPRequest::string($this->nid, null, $this->allowHtml, $request); SPRequest::resetFilter(); if (!$this->editor && $this->maxLength && strlen($data) > $this->maxLength) { $data = substr($data, 0, $this->maxLength); } } else { $data = strip_tags($data); } /* collect the needed params */ $params = array(); $params['publishUp'] = $entry->get('publishUp'); $params['publishDown'] = $entry->get('publishDown'); $params['fid'] = $this->fid; $params['sid'] = $entry->get('id'); $params['section'] = Sobi::Reg('current_section'); $params['lang'] = Sobi::Lang(); $params['enabled'] = $entry->get('state'); $params['params'] = null; $params['options'] = null; $params['baseData'] = $data; $params['approved'] = $entry->get('approved'); $params['confirmed'] = $entry->get('confirmed'); /* if it is the first version, it is new entry */ if ($entry->get('version') == 1) { $params['createdTime'] = $time; $params['createdBy'] = $uid; $params['createdIP'] = $IP; } $params['updatedTime'] = $time; $params['updatedBy'] = $uid; $params['updatedIP'] = $IP; $params['copy'] = !$entry->get('approved'); if (Sobi::My('id') == $entry->get('owner')) { --$this->editLimit; } $params['editLimit'] = $this->editLimit; /* save it */ try { $db->insertUpdate('spdb_field_data', $params); } catch (SPException $x) { Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } /* if it wasn't edited in the default language, we have to try to insert it also for def lang */ if (Sobi::Lang() != Sobi::DefLang()) { $params['lang'] = Sobi::DefLang(); try { $db->insert('spdb_field_data', $params, true, true); } catch (SPException $x) { Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } }