示例#1
0
 /**
  * @param $entry
  * @param $request
  * @param $files
  * @return SPdb
  * @throws SPException
  */
 protected function storeData(&$entry, $request, $files)
 {
     /* @var SPdb $db */
     $db =& SPFactory::db();
     $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 */
     /* collect the needed params */
     $save = count($files) ? SPConfig::serialize($files) : null;
     $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['baseData'] = $db->escape($save);
     $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);
         return $db;
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_FIELDS_DATA_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         return $db;
     }
     return $db;
 }
示例#2
0
 /**
  * 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;
     }
     /* @var SPdb $db */
     $db = SPFactory::db();
     $save = $this->verify($entry, $request);
     $time = SPRequest::now();
     $IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
     $uid = Sobi::My('id');
     /* 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['baseData'] = $db->escape(SPConfig::serialize($save));
     $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 {
         /* Notices:
          * If it was new entry - insert
          * If it was an edit and the field wasn't filled before - insert
          * If it was an edit and the field was filled before - update
          *     " ... " and changes are not autopublish it should be insert of the copy .... but
          * " ... " if a copy already exist it is update again
          * */
         $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__);
         }
     }
 }
示例#3
0
 /**
  * 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->fetchData($this->multi ? SPRequest::arr($this->nid, array(), $request) : SPRequest::word($this->nid, null, $request), $request);
     $cdata = $this->verify($entry, $request, $data);
     $time = SPRequest::now();
     $IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
     $uid = Sobi::My('id');
     /* @var SPdb $db */
     $db =& SPFactory::db();
     /* if we are here, we can save these data */
     if ($cdata) {
         if ($this->dependency) {
             return $this->saveDependencyField($entry, $data, $request);
         }
         $options = array();
         $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['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'] = 0;
         $params['baseData'] = null;
         $params['copy'] = (int) (!$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__);
         }
         foreach ($data as $selected) {
             /* collect the needed params */
             $params['baseData'] = strip_tags($db->escape($selected));
             $options[] = array('fid' => $this->fid, 'sid' => $entry->get('id'), 'optValue' => $selected, 'copy' => $params['copy'], 'params' => null);
         }
         /* delete old selected values */
         try {
             $db->delete('spdb_field_option_selected', array('fid' => $this->fid, 'sid' => $entry->get('id'), 'copy' => $params['copy']));
         } catch (SPException $x) {
             Sobi::Error(__CLASS__, SPLang::e('CANNOT_DELETE_PREVIOUS_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
         /* insert new selected value */
         try {
             $db->insertArray('spdb_field_option_selected', $options);
         } catch (SPException $x) {
             Sobi::Error(__CLASS__, SPLang::e('CANNOT_SAVE_SELECTED_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
         }
     } elseif ($entry->get('version') > 1) {
         if (!$entry->get('approved')) {
             try {
                 $db->update('spdb_field_option_selected', array('copy' => 1), array('fid' => $this->fid, 'sid' => $entry->get('id')));
             } catch (SPException $x) {
                 Sobi::Error(__CLASS__, SPLang::e('CANNOT_UPDATE_PREVIOUS_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
             }
         } else {
             /* delete old selected values */
             try {
                 $db->delete('spdb_field_option_selected', array('fid' => $this->fid, 'sid' => $entry->get('id')));
             } catch (SPException $x) {
                 Sobi::Error(__CLASS__, SPLang::e('CANNOT_DELETE_PREVIOUS_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
             }
         }
     }
 }
示例#4
0
 /**
  * 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__);
         }
     }
 }
示例#5
0
 /**
  * Gets the data for a field and save it in the database
  * @param SPEntry $entry
  * @param string $request
  * @throws SPException
  * @return bool
  */
 public function saveData(&$entry, $request = 'POST')
 {
     if (!$this->enabled) {
         return false;
     }
     if ($this->method == 'fixed') {
         $fixed = $this->fixedCid;
         $fixed = explode(',', $fixed);
         $data = array();
         if (count($fixed)) {
             foreach ($fixed as $cid) {
                 $data[] = trim($cid);
             }
         }
         if (!count($data)) {
             throw new SPException(SPLang::e('FIELD_CC_FIXED_CID_NOT_SELECTED', $this->name));
         }
     } else {
         $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();
     /* 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'] = SPConfig::serialize($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 {
         /* Notices:
          * If it was new entry - insert
          * If it was an edit and the field wasn't filled before - insert
          * If it was an edit and the field was filled before - update
          *     " ... " and changes are not autopublish it should be insert of the copy .... but
          * " ... " if a copy already exist it is update again
          * */
         $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__);
         }
     }
     /** Last important thing - join selected categories  */
     $cats = SPFactory::registry()->get('request_categories', array());
     $cats = array_unique(array_merge($cats, $data));
     SPFactory::registry()->set('request_categories', $cats);
     if ($this->method == 'select' && $this->isPrimary) {
         $db->update('spdb_object', array('parent' => $data[0]), array('id' => $params['sid']));
     }
 }
示例#6
0
 /**
  */
 public function save($request = 'post')
 {
     $this->version++;
     /* get current data */
     $this->updatedTime = SPRequest::now();
     $this->updaterIP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
     $this->updater = Sobi::My('id');
     $this->nid = SPLang::nid($this->nid, true);
     if (!$this->nid) {
         $this->nid = SPLang::nid($this->name, true);
     }
     /* get THIS class properties */
     $properties = get_class_vars(__CLASS__);
     /* if new object */
     if (!$this->id) {
         /** @var the notification App is using it to recognise if it is a new entry or an update */
         $this->createdTime = $this->updatedTime;
         $this->owner = $this->owner ? $this->owner : $this->updater;
         $this->ownerIP = $this->updaterIP;
     } else {
         /** Fri, Dec 19, 2014 19:33:52
          * When storing it we should actually get already UTC unix time stamp
          * so there is not need to remove it again
          */
         //			$this->createdTime = $this->createdTime && is_numeric( $this->createdTime ) ? gmdate( Sobi::Cfg( 'db.date_format', 'Y-m-d H:i:s' ), $this->createdTime - SPFactory::config()->getTimeOffset() ) : $this->createdTime;
         $this->createdTime = $this->createdTime && is_numeric($this->createdTime) ? gmdate(Sobi::Cfg('db.date_format', 'Y-m-d H:i:s'), $this->createdTime) : $this->createdTime;
         $obj = SPFactory::object($this->id);
         if ($obj->oType != $this->oType) {
             Sobi::Error('Object Save', sprintf('Serious security violation. Trying to save an object which claims to be an %s but it is a %s. Task was %s', $this->oType, $obj->oType, SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__);
             exit;
         }
     }
     if (is_numeric($this->validUntil)) {
         //			$this->validUntil = $this->validUntil ? gmdate( Sobi::Cfg( 'db.date_format', 'Y-m-d H:i:s' ), $this->validUntil - SPFactory::config()->getTimeOffset() ) : null;
         $this->validUntil = $this->validUntil ? gmdate(Sobi::Cfg('db.date_format', 'Y-m-d H:i:s'), $this->validUntil) : null;
     }
     if (is_numeric($this->validSince)) {
         $this->validSince = $this->validSince ? gmdate(Sobi::Cfg('db.date_format', 'Y-m-d H:i:s'), $this->validSince) : null;
     }
     /* @var SPdb $db */
     $db = SPFactory::db();
     $db->transaction();
     /* get database columns and their ordering */
     $cols = $db->getColumns('spdb_object');
     $values = array();
     /*
      * @todo: manage own is not implemented yet
      */
     //$this->approved = Sobi::Can( $this->type(), 'manage', 'own' );
     /* if not published, check if user can manage own and if yes, publish it */
     if (!$this->state && !defined('SOBIPRO_ADM')) {
         $this->state = Sobi::Can($this->type(), 'publish', 'own');
     }
     if (!defined('SOBIPRO_ADM')) {
         $this->approved = Sobi::Can($this->type(), 'publish', 'own');
     }
     //		elseif ( defined( 'SOBIPRO_ADM' ) ) {
     //			$this->approved = Sobi::Can( $this->type(), 'publish', 'own' );
     //		}
     /* and sort the properties in the same order */
     foreach ($cols as $col) {
         $values[$col] = array_key_exists($col, $properties) ? $this->{$col} : '';
     }
     /* trigger plugins */
     Sobi::Trigger('save', $this->name(), array(&$this));
     /* try to save */
     try {
         /* if new object */
         if (!$this->id) {
             $db->insert('spdb_object', $values);
             $this->id = $db->insertid();
         } else {
             $db->update('spdb_object', $values, array('id' => $this->id));
         }
     } catch (SPException $x) {
         $db->rollback();
         Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_OBJECT_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     /* get translatable properties */
     $attributes = array_merge($this->translatable(), self::$translatable);
     $labels = array();
     $defLabels = array();
     foreach ($attributes as $attr) {
         if ($this->has($attr)) {
             $labels[] = array('sKey' => $attr, 'sValue' => $this->{$attr}, 'language' => Sobi::Lang(), 'id' => $this->id, 'oType' => $this->type(), 'fid' => 0);
             if (Sobi::Lang() != Sobi::DefLang()) {
                 $defLabels[] = array('sKey' => $attr, 'sValue' => $this->{$attr}, 'language' => Sobi::DefLang(), 'id' => $this->id, 'oType' => $this->type(), 'fid' => 0);
             }
         }
     }
     /* save translatable properties */
     if (count($labels)) {
         try {
             if (Sobi::Lang() != Sobi::DefLang()) {
                 $db->insertArray('spdb_language', $defLabels, false, true);
             }
             $db->insertArray('spdb_language', $labels, true);
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_OBJECT_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
     }
     $db->commit();
     $this->checkIn();
 }
示例#7
0
 /**
  * Gets the data for a field and save it in the database
  * @param SPEntry $entry
  * @param string $request
  * @throws SPException
  * @return bool
  */
 public function saveData(&$entry, $request = 'POST')
 {
     if (!$this->enabled) {
         return false;
     }
     $del = SPRequest::bool($this->nid . '_delete', false, $request);
     $fileSize = SPRequest::file($this->nid, 'size');
     $cropped = null;
     static $store = null;
     $cache = false;
     if ($store == null) {
         $store = SPFactory::registry()->get('requestcache_stored');
     }
     if (is_array($store) && isset($store[$this->nid])) {
         if (!strstr($store[$this->nid], 'file://') && !strstr($store[$this->nid], 'directory://')) {
             $data = $store[$this->nid];
             $cache = true;
             $orgName = SPRequest::file($this->nid, 'name', $request);
         } else {
             SPRequest::set($this->nid, $store[$this->nid]);
             $orgName = SPRequest::file($this->nid, 'name');
             $data = SPRequest::file($this->nid, 'tmp_name');
         }
     } else {
         $data = SPRequest::file($this->nid, 'tmp_name');
         $orgName = SPRequest::file($this->nid, 'name');
     }
     $sPath = $this->parseName($entry, $orgName, $this->savePath);
     $path = SPLoader::dirPath($sPath, 'root', false);
     /** Wed, Oct 15, 2014 13:51:03
      * Implemented a cropper with Ajax checker.
      * This is the actual method to get those files
      * Other methods left for BC
      * */
     if (!$data) {
         $directory = SPRequest::string($this->nid, $store[$this->nid], false, $request);
         if (strlen($directory)) {
             list($data, $dirName, $files, $coordinates) = $this->getAjaxFiles($directory);
             if (count($files)) {
                 foreach ($files as $file) {
                     if ($file == '.') {
                         continue;
                     }
                     if ($file == '..') {
                         continue;
                     }
                     if (strpos($file, 'icon_') !== false) {
                         continue;
                     }
                     if (strpos($file, 'resized_') !== false) {
                         continue;
                     }
                     if (strpos($file, 'cropped_') !== false) {
                         $cropped = $dirName . $file;
                         SPFs::upload($cropped, $path . basename($cropped));
                         continue;
                     }
                     if (strpos($file, '.var') !== false) {
                         continue;
                     }
                     $fileSize = filesize($dirName . $file);
                     $orgName = $file;
                 }
             }
             if (strlen($coordinates)) {
                 $coordinates = json_decode(SPLang::clean($coordinates), true);
                 /** @var SPImage $croppedImage */
                 $croppedImage = SPFactory::Instance('base.fs.image', $dirName . $orgName);
                 $croppedImage->crop($coordinates['width'], $coordinates['height'], $coordinates['x'], $coordinates['y']);
                 $cropped = 'cropped_' . $orgName;
                 $croppedImage->saveAs($path . $cropped);
             }
             $data = strlen($cropped) ? $cropped : $dirName . $file;
         }
     }
     $files = array();
     /* if we have an image */
     if ($data && $orgName) {
         if ($fileSize > $this->maxSize) {
             throw new SPException(SPLang::e('FIELD_IMG_TOO_LARGE', $this->name, $fileSize, $this->maxSize));
         }
         if ($cropped) {
             SPFs::upload($dirName . $orgName, $path . $orgName);
         }
         /**
          * @var SPImage $orgImage
          */
         if ($cache) {
             $orgImage = SPFactory::Instance('base.fs.image', $data);
             $orgImage->move($path . $orgName);
         } else {
             $orgImage = SPFactory::Instance('base.fs.image');
             $nameArray = explode('.', $orgName);
             $ext = strtolower(array_pop($nameArray));
             $nameArray[] = $ext;
             $orgName = implode('.', $nameArray);
             if ($cropped) {
                 $orgImage->upload($dirName . $data, $path . basename($data));
             } else {
                 $orgImage->upload($dirName . $orgName, $path . $orgName);
             }
         }
         $files['data']['exif'] = $orgImage->exif();
         $this->cleanExif($files['data']['exif']);
         if (Sobi::Cfg('image_field.fix_rotation', true)) {
             if ($orgImage->fixRotation()) {
                 $orgImage->save();
             }
         }
         if ($this->resize) {
             $image = clone $orgImage;
             try {
                 $image->resample($this->resizeWidth, $this->resizeHeight, false);
                 $files['image'] = $this->parseName($entry, $orgName, $this->imageName, true);
                 $image->saveAs($path . $files['image']);
             } catch (SPException $x) {
                 Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
                 $image->delete();
                 throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()));
             }
         }
         if ($this->generateThumb) {
             $thumb = clone $orgImage;
             try {
                 $thumb->resample($this->thumbWidth, $this->thumbHeight, false);
                 $files['thumb'] = $this->parseName($entry, $orgName, $this->thumbName, true);
                 $thumb->saveAs($path . $files['thumb']);
             } catch (SPException $x) {
                 Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
                 $thumb->delete();
                 throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()));
             }
         }
         $ico = clone $orgImage;
         try {
             $icoSize = explode(':', Sobi::Cfg('image.ico_size', '80:80'));
             $ico->resample($icoSize[0], $icoSize[1], false);
             $files['ico'] = $this->parseName($entry, strtolower($orgName), 'ico_{orgname}', true);
             $ico->saveAs($path . $files['ico']);
         } catch (SPException $x) {
             Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
             $ico->delete();
             throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()));
         }
         if (!$this->keepOrg) {
             $orgImage->delete();
         } else {
             $files['original'] = $this->parseName($entry, $orgName, '{orgname}', true);
         }
         foreach ($files as $i => $file) {
             if ($i == 'data') {
                 continue;
             }
             $files[$i] = $sPath . $file;
         }
     } elseif ($del) {
         $this->delImgs();
         $files = array();
     } else {
         return true;
     }
     /* @var SPdb $db */
     $db =& SPFactory::db();
     $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 */
     /* collect the needed params */
     $save = count($files) ? SPConfig::serialize($files) : null;
     $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['baseData'] = $db->escape($save);
     $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($this->name(), SPLang::e('CANNOT_SAVE_FIELDS_DATA_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__);
     }
 }