/** * 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__); } } }