Ejemplo n.º 1
0
 protected function upload()
 {
     $ident = SPRequest::cmd('ident', null, 'post');
     $data = SPRequest::file($ident, 'tmp_name');
     $secret = md5(Sobi::Cfg('secret'));
     if ($data) {
         $properties = SPRequest::file($ident);
         $fileName = md5(SPRequest::file($ident, 'name') . time() . $secret);
         $path = SPLoader::dirPath("tmp.files.{$secret}", 'front', false) . '/' . $fileName;
         /** @var $file SPFile */
         $file = SPFactory::Instance('base.fs.file');
         if (!$file->upload($data, $path)) {
             $this->message(array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE'), 'id' => ''));
         }
         $path = $file->getPathname();
         $type = $this->check($path);
         $properties['tmp_name'] = $path;
         SPFs::write($path . '.var', SPConfig::serialize($properties));
         $response = array('type' => 'success', 'text' => Sobi::Txt('FILE_UPLOADED', $properties['name'], $type), 'id' => 'file://' . $fileName, 'data' => array('name' => $properties['name'], 'type' => $properties['type'], 'size' => $properties['size']));
     } else {
         $response = array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE_NO_DATA'), 'id' => '');
     }
     //		$field = SPRequest::cmd( 'field', null );
     $this->message($response);
 }
Ejemplo n.º 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__);
         }
     }
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 /**
  * Creates a "insert" SQL query with update if cannot insert it because of duplicate primary key
  *
  * @param string $table - table name
  * @param array $values - two-dimensional array with table row name => value
  * @throws SPException
  * @return \SPJoomlaDb
  */
 public function insertUpdate($table, $values)
 {
     $v = array();
     $c = array();
     $k = array();
     foreach ($values as $var => $val) {
         if (is_array($val) || is_object($val)) {
             $val = SPConfig::serialize($val);
         }
         $val = $this->escape($val);
         if (strstr($val, 'FUNCTION:')) {
             $f = str_replace('FUNCTION:', null, $val);
             $v[] = $f;
             $c[] = "{$var} = {$f}";
         } else {
             $v[] = "'{$val}'";
             $c[] = "{$var} = '{$val}'";
         }
         $k[] = "`{$var}`";
     }
     $v = implode(',', $v);
     $c = implode(',', $c);
     $k = implode(',', $k);
     try {
         $this->exec("INSERT INTO {$table} ({$k}) VALUES ({$v}) ON DUPLICATE KEY UPDATE {$c}");
     } catch (Exception $e) {
     }
     if ($this->db->getErrorNum()) {
         throw new SPException($this->db->stderr());
     }
     return $this;
 }
Ejemplo n.º 5
0
 /**
  * @param $message
  * @param $spsid string
  * @param string $type
  * @return SPMessage
  */
 public function &setReport($message, $spsid, $type = SPC::INFO_MSG)
 {
     $this->reports[$spsid][$type][] = $message;
     if (count($this->reports)) {
         $messages = SPConfig::serialize($this->reports);
         $store = array('params' => $messages, 'key' => 'queue', 'value' => date(DATE_RFC822), 'description' => null, 'options' => null);
         SPFactory::registry()->saveDBSection(array('reports' => $store), 'reports');
     }
     return $this;
 }
Ejemplo n.º 6
0
 public function save($attr)
 {
     /* @var SPdb $db */
     $db = SPFactory::db();
     $base = $attr;
     $this->loadType();
     /* clean input */
     if (isset($attr['name'])) {
         $base['name'] = $db->escape($attr['name']);
     } else {
         $base['name'] = 'missing name - something went wrong';
     }
     if (isset($attr['nid'])) {
         $base['nid'] = $this->nid($db->escape(preg_replace('/[^[:alnum:]\\-\\_]/', null, $attr['nid'])), false);
     }
     if (isset($attr['cssClass'])) {
         $base['cssClass'] = $db->escape(preg_replace('/[^[:alnum:]\\-\\_ ]/', null, $attr['cssClass']));
     }
     if (isset($attr['notice'])) {
         $base['notice'] = $attr['notice'];
     }
     if (isset($attr['showIn'])) {
         $base['showIn'] = $db->escape(preg_replace('/[^[:alnum:]\\.\\-\\_]/', null, $attr['showIn']));
     }
     if (isset($attr['filter'])) {
         $base['filter'] = preg_replace('/[^[:alnum:]\\.\\-\\_]/', null, $attr['filter']);
     }
     if (isset($attr['fieldType'])) {
         $base['fieldType'] = preg_replace('/[^[:alnum:]\\.\\-\\_]/', null, $attr['fieldType']);
     }
     if (isset($attr['type'])) {
         $base['fieldType'] = preg_replace('/[^[:alnum:]\\.\\-\\_]/', null, $attr['type']);
     }
     if (isset($attr['enabled'])) {
         $base['enabled'] = (int) $attr['enabled'];
     }
     if (isset($attr['required'])) {
         $base['required'] = (int) $attr['required'];
     }
     if (isset($attr['adminField'])) {
         $base['adminField'] = (int) $attr['adminField'];
     }
     if ($attr['adminField']) {
         $attr['required'] = false;
     }
     if (isset($attr['editable'])) {
         $base['editable'] = (int) $attr['editable'];
     }
     if (isset($attr['inSearch'])) {
         $base['inSearch'] = (int) $attr['inSearch'];
     }
     if (isset($attr['editLimit'])) {
         $base['editLimit'] = (int) $attr['editLimit'];
     }
     $base['editLimit'] = isset($base['editLimit']) && $base['editLimit'] > 0 ? $base['editLimit'] : -1;
     if (isset($attr['isFree'])) {
         $base['isFree'] = (int) $attr['isFree'];
     }
     if (isset($attr['withLabel'])) {
         $base['withLabel'] = (int) $attr['withLabel'];
     }
     if (isset($attr['fee'])) {
         $base['fee'] = (double) str_replace(',', '.', $attr['fee']);
     }
     if (isset($attr['addToMetaDesc'])) {
         $base['addToMetaDesc'] = (int) $attr['addToMetaDesc'];
     }
     if (isset($attr['addToMetaKeys'])) {
         $base['addToMetaKeys'] = (int) $attr['addToMetaKeys'];
     }
     if (isset($attr['uniqueData'])) {
         $base['uniqueData'] = (int) $attr['uniqueData'];
     }
     /* both strpos are removed because it does not allow to have one parameter only */
     //      if( isset( $attr[ 'allowedAttributes' ] ) && strpos( $attr[ 'allowedAttributes' ], '|' ) )
     if (isset($attr['allowedAttributes'])) {
         $att = SPFactory::config()->structuralData($attr['allowedAttributes'], true);
         if (count($att)) {
             foreach ($att as $i => $k) {
                 $att[$i] = trim($k);
             }
         }
         $base['allowedAttributes'] = SPConfig::serialize($att);
     }
     if (isset($attr['allowedTags'])) {
         $tags = SPFactory::config()->structuralData($attr['allowedTags'], true);
         if (count($tags)) {
             foreach ($tags as $i => $k) {
                 $tags[$i] = trim($k);
             }
         }
         $base['allowedTags'] = SPConfig::serialize($tags);
     }
     if (isset($attr['admList'])) {
         $base['admList'] = (int) $attr['admList'];
     }
     if (isset($attr['description'])) {
         $base['description'] = $attr['description'];
     } else {
         $base['description'] = null;
     }
     if (isset($attr['suffix'])) {
         $base['suffix'] = $db->escape($attr['suffix']);
     } else {
         $base['suffix'] = null;
     }
     $this->version++;
     $base['version'] = $this->version;
     /* section id is needed only if it was new field */
     if (!(isset($attr['section']) && $attr['section'])) {
         if (!SPRequest::int('fid')) {
             $base['section'] = SPRequest::sid();
         }
     }
     /* bind attributes to this object */
     foreach ($attr as $a => $v) {
         $a = trim($a);
         if ($this->has($a)) {
             $this->{$a} = $v;
         }
     }
     if ($this->_type && method_exists($this->_type, 'save')) {
         $this->_type->save($base);
     }
     /* get database columns and their ordering */
     $cols = $db->getColumns('spdb_field');
     $values = array();
     /* and sort the properties in the same order */
     foreach ($cols as $col) {
         if (array_key_exists($col, $base)) {
             $values[$col] = $base[$col];
         }
     }
     /* save field */
     try {
         $db->update('spdb_field', $values, array('fid' => $this->fid));
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     /* save language dependent properties */
     $labels = array();
     $defLabels = array();
     $labels[] = array('sKey' => 'name', 'sValue' => $base['name'], 'language' => Sobi::Lang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
     $labels[] = array('sKey' => 'description', 'sValue' => $base['description'], 'language' => Sobi::Lang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
     $labels[] = array('sKey' => 'suffix', 'sValue' => $base['suffix'], 'language' => Sobi::Lang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
     if (Sobi::Lang() != Sobi::DefLang()) {
         $defLabels[] = array('sKey' => 'name', 'sValue' => $base['name'], 'language' => Sobi::DefLang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
         $defLabels[] = array('sKey' => 'suffix', 'sValue' => $base['suffix'], 'language' => Sobi::DefLang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
         $defLabels[] = array('sKey' => 'description', 'sValue' => $base['description'], 'language' => Sobi::DefLang(), 'id' => 0, 'oType' => 'field', 'fid' => $this->fid);
     }
     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_FIELD_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
     }
     SPFactory::cache()->cleanSection();
 }
Ejemplo n.º 7
0
 protected function saveRejectionTpl()
 {
     if (!SPFactory::mainframe()->checkToken()) {
         Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__);
     }
     $templates = $this->getRejectionsTemplates();
     $id = SPLang::nid(SPRequest::string('templateName'));
     $templates[$id] = array('params' => SPConfig::serialize(array('trigger.unpublish' => SPRequest::bool('trigger_unpublish'), 'trigger.unapprove' => SPRequest::bool('trigger_unapprove'), 'unpublish' => SPRequest::bool('unpublish'), 'discard' => SPRequest::bool('discard'))), 'key' => $id, 'value' => SPRequest::string('templateName'), 'options' => array());
     foreach ($templates as $tid => $template) {
         unset($templates[$tid]['description']);
     }
     SPFactory::registry()->saveDBSection($templates, 'rejections-templates_' . Sobi::Section());
     $data = array('key' => $id, 'value' => SPRequest::string('reason', null, true, 'post'), 'type' => 'rejections-templates', 'id' => Sobi::Section(), 'section' => Sobi::Section(), 'options' => SPRequest::string('templateName'));
     SPLang::saveValues($data);
     $this->response(Sobi::Back(), Sobi::Txt('ENTRY_REJECT_SAVED_TPL'), false, SPC::SUCCESS_MSG);
 }
Ejemplo n.º 8
0
 /**
  * Save an entry
  *
  * @param bool $apply
  */
 protected function save($apply)
 {
     $new = true;
     if (!$this->_model) {
         $this->setModel(SPLoader::loadModel($this->_type));
     }
     if ($this->_model->get('oType') != 'entry') {
         Sobi::Error('Entry', sprintf('Serious security violation. Trying to save an object which claims to be an entry but it is a %s. Task was %s', $this->_model->get('oType'), SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__);
         exit;
     }
     /* check if we have stored last edit in cache */
     $tsId = SPRequest::string('editentry', null, false, 'cookie');
     if (!$tsId) {
         $tsId = SPRequest::cmd('ssid');
     }
     $request = $this->getCache($tsId);
     $this->_model->init(SPRequest::sid($request));
     $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE);
     $this->tplCfg($tplPackage);
     $customClass = null;
     if (isset($this->_tCfg['general']['functions']) && $this->_tCfg['general']['functions']) {
         $customClass = SPLoader::loadClass('/' . str_replace('.php', null, $this->_tCfg['general']['functions']), false, 'templates');
         if (method_exists($customClass, 'BeforeStoreEntry')) {
             $customClass::BeforeStoreEntry($this->_model, $this->store['post']);
             SPFactory::registry()->set('requestcache_stored', $this->store);
             SPFactory::registry()->set('requestcache', $this->store['post']);
         }
     }
     $preState = array('approved' => $this->_model->get('approved'), 'state' => $this->_model->get('state'), 'new' => !$this->_model->get('id'));
     SPFactory::registry()->set('object_previous_state', $preState);
     $this->_model->getRequest($this->_type, $request);
     Sobi::Trigger($this->name(), __FUNCTION__, array(&$this->_model));
     if ($this->_model->get('id') && $this->_model->get('id') == SPRequest::sid()) {
         $new = false;
         if (Sobi::My('id') && Sobi::My('id') == $this->_model->get('owner')) {
             $this->authorise('edit', 'own');
         } else {
             $this->authorise('edit', '*');
         }
     } else {
         $this->authorise('add', 'own');
     }
     $this->_model->save($request);
     /* if there is something pay */
     $pCount = SPFactory::payment()->count($this->_model->get('id'));
     if ($pCount && !Sobi::Can('entry.payment.free')) {
         //			$this->paymentView( $tsid );
         if ($customClass && method_exists($customClass, 'BeforeStoreEntryPayment')) {
             $customClass::BeforeStoreEntryPayment($this->_model->get('id'));
         }
         SPFactory::payment()->store($this->_model->get('id'));
     }
     /* delete cache files on after */
     $file = str_replace('.', '-', $tsId);
     if (SPLoader::dirPath('tmp.edit.' . $file)) {
         SPFs::delete(SPLoader::dirPath('tmp.edit.' . $file));
     } else {
         SPFactory::cache()->deleteVar('request_cache_' . $tsId);
     }
     SPLoader::loadClass('env.cookie');
     SPCookie::delete('editentry');
     $sid = $this->_model->get('id');
     $pid = SPRequest::int('pid') ? SPRequest::int('pid') : Sobi::Section();
     if ($new) {
         if ($this->_model->get('state') || Sobi::Can('entry.see_unpublished.own')) {
             $msg = $this->_model->get('state') ? Sobi::Txt('EN.ENTRY_SAVED') : Sobi::Txt('EN.ENTRY_SAVED_NP');
             $url = Sobi::Url(array('sid' => $sid, 'pid' => $pid));
         } else {
             // determine if there is a custom redirect
             if (Sobi::Cfg('redirects.entry_save_enabled') && !($pCount && !Sobi::Can('entry.payment.free'))) {
                 $redirect = Sobi::Cfg('redirects.entry_save_url', null);
                 if (!preg_match('/http[s]?:\\/\\/.*/', $redirect) && $redirect != 'index.php') {
                     $redirect = Sobi::Url($redirect);
                 }
                 $this->response($redirect, Sobi::Txt(Sobi::Cfg('redirects.entry_save_msg', 'EN.ENTRY_SAVED_NP')), true, Sobi::Cfg('redirects.entry_save_msgtype', SPC::SUCCESS_MSG));
             } else {
                 $msg = Sobi::Txt('EN.ENTRY_SAVED_NP');
                 $url = Sobi::Url(array('sid' => $pid));
             }
         }
     } elseif ($this->_model->get('approved') || Sobi::Can('entry.see_unapproved.own')) {
         $url = Sobi::Url(array('sid' => $sid, 'pid' => $pid));
         $msg = $this->_model->get('approved') ? Sobi::Txt('EN.ENTRY_SAVED') : Sobi::Txt('EN.ENTRY_SAVED_NA');
     } else {
         if ($this->_model->get('approved')) {
             $msg = Sobi::Txt('EN.ENTRY_SAVED');
         } else {
             $msg = Sobi::Txt('EN.ENTRY_SAVED_NA');
         }
         $url = Sobi::Url(array('sid' => $sid, 'pid' => $pid));
     }
     if ($pCount && !Sobi::Can('entry.payment.free')) {
         $ident = md5(microtime() . $tsId . $sid . time());
         $data = array('data' => SPFactory::payment()->summary($sid), 'ident' => $ident);
         $url = Sobi::Url(array('sid' => $sid, 'task' => 'entry.payment'), false, false);
         if (Sobi::Cfg('cache.l3_enabled', true)) {
             SPFactory::cache()->addObj($data, 'payment', $sid, Sobi::Section(), true);
         } else {
             SPFs::write(SPLoader::path('tmp.edit.' . $ident . '.payment', 'front', false, 'var'), SPConfig::serialize($data));
             $url = Sobi::Url(array('sid' => $sid, 'task' => 'entry.payment', 'tsid' => $ident), false, false);
         }
         SPLoader::loadClass('env.cookie');
         SPCookie::set('payment_' . $sid, $ident, SPCookie::days(1));
     }
     if ($customClass && method_exists($customClass, 'AfterStoreEntry')) {
         $customClass::AfterStoreEntry($this->_model);
     }
     $this->logChanges('save', SPRequest::string('history-note'));
     $this->response($url, $msg, true, SPC::SUCCESS_MSG);
 }
Ejemplo n.º 9
0
 protected function session(&$ssid)
 {
     /* if it wasn't new search */
     $ssid = SPRequest::cmd('ssid', SPRequest::cmd('ssid', null, 'cookie'));
     $new = false;
     /* otherwise create new ssid */
     if (!$ssid) {
         $ssid = microtime(true) * 100 . '.' . rand(0, 99);
         $new = true;
     }
     $attr = array('ssid' => $ssid, 'uid' => Sobi::My('id'), 'browserData' => SPConfig::serialize(SPBrowser::getInstance()));
     /* get search request */
     if (!count($this->_request)) {
         $r = SPRequest::search('field_');
         if (is_array($r) && count($r)) {
             $attr['requestData'] = SPConfig::serialize($r);
         }
     }
     /* determine the search parameters */
     if ($new) {
         $attr['searchCreated'] = 'FUNCTION:NOW()';
     }
     /* finally save */
     try {
         $this->_db->insertUpdate('spdb_search', $attr);
     } catch (SPException $x) {
         Sobi::Error($this->name(), SPLang::e('CANNOT_CREATE_SESSION_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
     }
     return SPCookie::set('ssid', $ssid, SPCookie::days(7));
 }
Ejemplo n.º 10
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']));
     }
 }
Ejemplo n.º 11
0
 /**
  * Store object in to the cache
  * @param mixed $obj - object to store
  * @param string $type - type of object entry/category/section
  * @param int $id - id of the object
  * @param int $sid
  * @param bool $force
  * @return SPCache
  */
 public function &addObj($obj, $type, $id, $sid = 0, $force = false)
 {
     if ($this->enabled(!$force)) {
         static $startTime = 0;
         if (!$startTime && class_exists('Sobi')) {
             $start = Sobi::Reg('start');
             $startTime = $start[1];
         }
         // storing need time - if we are over five seconds - skip
         if (!defined('SOBIPRO_ADM') && !$force && microtime(true) - $startTime > 5) {
             return $this;
         }
         // it was the idea that if entry has been taken from cache, and do not reports any changes - it doesn't have to be stored again
         // but I'm not so sure if this is a good idea any longer
         // so let's skip it and see what's going to happen
         // poor guys from the testing team :P
         // Tue, Feb 19, 2013 14:09:52
         // it makes sense - otherwise the cache is being invalidated again and again
         // anyway stupid solution -  i have to reconsider it therefore @todo
         if ($type == 'entry') {
             // entry has to report if it should be re-validate
             if (!isset($this->_check[$type][$id]) || !$this->_check[$type][$id]) {
                 return $this;
             }
         }
         $id = (int) $id;
         $sid = (int) $sid;
         $sid = $sid ? $sid : $this->_section;
         $loaded = serialize(SPLoader::getLoaded());
         $lang = Sobi::Lang(false);
         $checksum = null;
         //md5( serialize( $obj ) );
         if ($this->_apc) {
             $var = array('obj' => $obj, 'classes' => $loaded);
             apc_store("com_sobipro_{$sid}_{$id}_{$type}_{$lang}", $var);
         }
         $obj = SPConfig::serialize($obj);
         $schecksum = md5($obj);
         // the command is a "REPLACE" so there is actually no reason for deleting it anyway
         // the "deleteObj" causing however a chain reaction which would delete lot of other things so it doesn't make any sense here
         //			$this->deleteObj( $type, $id, $sid );
         $this->Exec("BEGIN; REPLACE INTO objects ( type, validtime, id, sid, lang, params, checksum, schecksum, data, classes ) VALUES( '{$type}', '0', '{$id}', '{$sid}', '{$lang}', NULL, '{$checksum}', '{$schecksum}', '{$obj}', '{$loaded}' ); COMMIT;");
         $this->cleanJCache();
     }
     return $this;
 }
Ejemplo n.º 12
0
 /**
  * */
 public function ProxyUpload()
 {
     $ident = SPRequest::cmd('ident', null, 'post');
     $data = SPRequest::file($ident, 'tmp_name');
     $secret = md5(Sobi::Cfg('secret'));
     if ($data) {
         $properties = SPRequest::file($ident);
         $orgFileName = $properties['name'];
         $extension = SPFs::getExt($orgFileName);
         $orgFileName = str_replace('.' . $extension, '.' . strtolower($extension), $orgFileName);
         if ($properties['size'] > $this->maxSize) {
             $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_TOO_LARGE', $this->name, $properties['size'], $this->maxSize), 'id' => ''));
         }
         $dirNameHash = md5($orgFileName . time() . $secret);
         $dirName = SPLoader::dirPath("tmp.files.{$secret}.{$dirNameHash}", 'front', false);
         SPFs::mkdir($dirName);
         $path = $dirName . $orgFileName;
         /** @var $file SPImage */
         $orgImage = SPFactory::Instance('base.fs.image');
         if (!$orgImage->upload($data, $path)) {
             $this->message(array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE'), 'id' => ''));
         }
         if (Sobi::Cfg('image_field.fix_rotation', true)) {
             if ($orgImage->fixRotation()) {
                 $orgImage->save();
             }
         }
         if ($this->crop) {
             $croppedImage = clone $orgImage;
             list($originalWidth, $originalHeight) = getimagesize($path);
             $aspectRatio = $this->resizeWidth / $this->resizeHeight;
             $width = $aspectRatio * $originalHeight > $originalWidth ? $originalWidth : $aspectRatio * $originalHeight;
             $height = $originalWidth / $aspectRatio > $originalHeight ? $originalHeight : $originalWidth / $aspectRatio;
             try {
                 $croppedImage->crop($width, $height);
                 $croppedImage->saveAs($dirName . 'cropped_' . $orgFileName);
                 $ico = SPFactory::Instance('base.fs.image', $dirName . 'cropped_' . $orgFileName);
             } catch (SPException $x) {
                 $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_CANNOT_CROP', $x->getMessage()), 'id' => ''));
             }
         } else {
             $ico = clone $orgImage;
         }
         $image = clone $orgImage;
         try {
             $previewSize = explode(':', Sobi::Cfg('image.preview_size', '500:500'));
             $image->resample($previewSize[0], $previewSize[1], false);
             $image->saveAs($dirName . 'resized_' . $orgFileName);
         } catch (SPException $x) {
             $image->delete();
             $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), 'id' => ''));
         }
         try {
             $icoSize = explode(':', Sobi::Cfg('image.ico_size', '80:80'));
             $ico->resample($icoSize[0], $icoSize[1], false);
             $ico->saveAs($dirName . 'icon_' . $orgFileName);
         } catch (SPException $x) {
             $ico->delete();
             $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), 'id' => ''));
         }
         $path = $orgImage->getPathname();
         $type = $this->check($path);
         $properties['tmp_name'] = $path;
         SPFs::write(SPLoader::dirPath("tmp.files.{$secret}", 'front', false) . '/' . $orgFileName . '.var', SPConfig::serialize($properties));
         $response = array('type' => 'success', 'text' => Sobi::Txt('IMAGE_UPLOADED_CROP', $properties['name'], $type), 'id' => 'directory://' . $dirNameHash, 'data' => array('name' => $properties['name'], 'type' => $properties['type'], 'size' => $properties['size'], 'original' => $dirNameHash . '/' . $properties['name'], 'icon' => $dirNameHash . '/' . 'icon_' . $orgFileName, 'crop' => $this->crop, 'height' => $this->resizeHeight, 'width' => $this->resizeWidth));
     } else {
         $response = array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE_NO_DATA'), 'id' => '');
     }
     $this->message($response);
 }