Exemple #1
0
 /**
  * This function have to add own string into the given array
  * Basically: $methods[ $this->id ] = "Some String To Output";
  * Optionally the value can be also SobiPro Arr2XML array.
  * Check the documentation for more information
  * @param array $methods
  * @param SPEntry $entry
  * @param array $payment
  * @param bool $message
  * @return void
  */
 public function PaymentMethodView(&$methods, $entry, &$payment, $message = false)
 {
     $data = SPFactory::registry()->loadDBSection('paypal_' . Sobi::Section())->get('paypal_' . Sobi::Section());
     if (!count($data)) {
         $data = SPFactory::registry()->loadDBSection('paypal')->get('paypal');
     }
     $cfg = SPLoader::loadIniFile('etc.paypal');
     $rp = $cfg['general']['replace'];
     $to = $cfg['general']['replace'] == ',' ? '.' : ',';
     $amount = str_replace($rp, $to, $payment['summary']['sum_brutto']);
     $values = array('entry' => $entry, 'amount' => preg_replace('/[^0-9\\.,]/', null, $amount), 'ppurl' => SPLang::replacePlaceHolders($data['ppurl']['value'], $entry), 'ppemail' => SPLang::replacePlaceHolders($data['ppemail']['value'], $entry), 'pprurl' => SPLang::replacePlaceHolders($data['pprurl']['value'], $entry), 'ppcc' => SPLang::replacePlaceHolders($data['ppcc']['value'], $entry));
     $expl = SPLang::replacePlaceHolders(SPLang::getValue('ppexpl', 'plugin', Sobi::Section()), $values);
     $subject = SPLang::replacePlaceHolders(SPLang::getValue('ppsubject', 'plugin', Sobi::Section()), $values);
     $values['expl'] = $expl;
     $values['subject'] = $subject;
     $values['ip'] = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
     $methods[$this->id] = array('content' => $message ? $this->raw($cfg, $values) : $this->content($cfg, $values), 'title' => Sobi::Txt('APP.PPP.PAY_TITLE'));
 }
Exemple #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__);
         }
     }
 }
Exemple #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;
 }
Exemple #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->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__);
             }
         }
     }
 }
Exemple #5
0
 /**
  * @return bool
  */
 protected function view()
 {
     Sobi::ReturnPoint();
     /** @var $view SPAdmView */
     $view = $this->getView('config.' . $this->_task);
     $view->setCtrl($this);
     $IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER');
     if ($this->_task == 'general') {
         $this->checkTranslation();
         $fields = $this->getNameFields();
         $nameFields = array();
         if (count($fields)) {
             foreach ($fields as $field) {
                 $nameFields[$field->get('fid')] = $field->get('name');
             }
         }
         $alphaFields = array();
         $fields = $this->getNameFields(true, Sobi::Cfg('alphamenu.field_types'));
         if (count($fields)) {
             if (count($fields)) {
                 foreach ($fields as $field) {
                     $alphaFields[$field->get('fid')] = $field->get('name');
                 }
             }
         }
         $templateList = $view->templatesList();
         $entriesOrdering = $view->namesFields(null, true);
         $view->assign($nameFields, 'nameFields');
         $view->assign($templateList, 'templatesList');
         $view->assign($entriesOrdering, 'entriesOrdering');
         $view->assign($alphaFields, 'alphaMenuFields');
         $view->assign($view->languages(), 'languages-list');
     }
     $view->addHidden($IP, 'current-ip');
     Sobi::Trigger($this->_task, $this->name(), array(&$view));
     $view->determineTemplate('config', $this->_task);
     $view->display();
     Sobi::Trigger('After' . ucfirst($this->_task), $this->name(), array(&$view));
     return true;
 }
 /**
  * @param string $out - output type
  * @param array $functions - array with PHP function to register
  * @throws SPException
  * @return mixed|string
  */
 public function display($out = 'html', $functions = array())
 {
     $class = SPLoader::loadClass('helpers.template');
     $methods = get_class_methods($class);
     if (count($methods)) {
         foreach ($methods as $method) {
             $functions[] = $class . '::' . $method;
         }
     }
     /* standard function registered via the core ini file */
     $stdFunctions = SPLoader::loadIniFile('etc.template_functions');
     if (count($stdFunctions)) {
         foreach ($stdFunctions as $class => $fns) {
             if (strstr($class, '.')) {
                 $class = SPLoader::loadClass($class, false, 'sp-root');
             }
             if (count($fns)) {
                 foreach ($fns as $method => $state) {
                     if ($state) {
                         $functions[] = $class == 'functions' ? $method : $class . '::' . $method;
                     }
                 }
             }
         }
     }
     Sobi::Trigger('TemplateEngine', 'RegisterFunctions', array(&$functions));
     $this->createXML();
     if (SPRequest::cmd('xml') && Sobi::Cfg('debug.xml_raw', false) && (!Sobi::Cfg('debug.xml_ip', null) || Sobi::Cfg('debug.xml_ip') == SPRequest::ip('REMOTE_ADDR', 0, 'SERVER'))) {
         SPFactory::mainframe()->cleanBuffer();
         echo $this->_xml->saveXML();
         exit;
     } elseif (SPRequest::cmd('xml')) {
         Sobi::Error('Debug', 'You have no permission to access this site', SPC::ERROR, 403, __LINE__, __FILE__);
     }
     $template = SPLoader::loadTemplate($this->_tpl, 'xsl');
     if (!$template) {
         $template = SPLoader::loadTemplate($this->_tpl, 'xslt');
     }
     if (Sobi::Cfg('cache.xml_enabled')) {
         SPFactory::cache()->addView($this->_xml, $template, $this->_cacheData);
     }
     if ($template) {
         try {
             if (!($style = DOMDocument::load($template))) {
                 Sobi::Error('template', SPLang::e('CANNOT_PARSE_TEMPLATE_FILE', $template), SPC::ERROR, 500, __LINE__, __FILE__);
             }
         } catch (DOMException $x) {
             Sobi::Error('template', SPLang::e('CANNOT_LOAD_TEMPLATE_FILE', $template, $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__);
         }
         Sobi::Trigger('TemplateEngine', 'LoadStyle', array(&$style));
         $processor = new XSLTProcessor();
         $processor->setParameter('block', 'xmlns', 'http://www.w3.org/1999/xhtml');
         $processor->registerPHPFunctions($functions);
         SPException::catchErrors(SPC::WARNING);
         try {
             $processor->importStylesheet($style);
         } catch (SPException $x) {
             Sobi::Error('template', SPLang::e('CANNOT_PARSE_TEMPLATE_FILE', $template) . $x->getMessage(), SPC::ERROR, 500, __LINE__, __FILE__);
         }
         SPException::catchErrors(0);
         if ($out == 'html') {
             $doc = $processor->transformToDoc($this->_xml);
             $doc->formatOutput = true;
             return $this->cleanOut($doc->saveXML());
         } else {
             $doc = $processor->transformToDoc($this->_xml);
             $doc->formatOutput = true;
             return $doc->saveXML();
         }
     } else {
         throw new SPException(SPLang::e('CANNOT_LOAD_TEMPLATE_FILE_AT', SPLoader::loadTemplate($this->_tpl, 'xsl', false)));
     }
 }
Exemple #7
0
 public function ProxyCount()
 {
     SPLoader::loadClass('env.browser');
     SPLoader::loadClass('env.cookie');
     $browser = SPBrowser::getInstance();
     $this->nid = str_replace(array('.count', '.'), array(null, '_'), SPRequest::task());
     $ident = $this->nid . '_' . SPRequest::int('eid');
     $check = SPRequest::cmd('count_' . $ident, null, 'cookie');
     if (!$check) {
         $data = array('date' => 'FUNCTION:NOW()', 'uid' => Sobi::My('id'), 'sid' => SPRequest::int('eid'), 'fid' => $this->nid, 'ip' => SPRequest::ip('REMOTE_ADDR', 0, 'SERVER'), 'section' => Sobi::Section(), 'browserData' => $browser->get('browser'), 'osData' => $browser->get('system'), 'humanity' => $browser->get('humanity'));
         SPCookie::set('count_' . $ident, 1, SPCookie::hours(2));
         SPFactory::db()->insert('spdb_field_url_clicks', $data);
     }
 }
Exemple #8
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__);
         }
     }
 }
Exemple #9
0
 /**
  * pre-save an entry
  */
 protected function submit()
 {
     if (!SPFactory::mainframe()->checkToken()) {
         Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__);
     }
     if (!$this->_model) {
         $this->setModel(SPLoader::loadModel($this->_type));
     } else {
         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;
         }
     }
     $ajax = SPRequest::cmd('method', 'html') == 'xhr';
     /** let's create a simple plug-in method from the template to allow to modify the 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, 'BeforeSubmitEntry')) {
             $customClass::BeforeSubmitEntry($this->_model);
         }
     }
     $sid = $this->_model->get('id');
     $this->_model->init(SPRequest::sid());
     $this->_model->getRequest($this->_type);
     Sobi::Trigger($this->name(), __FUNCTION__, array(&$this->_model));
     if ($sid) {
         if (Sobi::My('id') && Sobi::My('id') == $this->_model->get('owner')) {
             $this->authorise('edit', 'own');
         } else {
             $this->authorise('edit', '*');
         }
     } else {
         $this->authorise('add', 'own');
     }
     if (Sobi::Cfg('legacy.sigsiutree', false) && !SPRequest::int('entry_parent', 0)) {
         $this->response(Sobi::Back(), Sobi::Txt('CAT.SELECT_ONE'), true, SPC::ERROR_MSG);
     }
     $this->_model->loadFields(Sobi::Reg('current_section'));
     $fields = $this->_model->get('fields');
     $tsId = SPRequest::string('editentry', null, false, 'cookie');
     $tsIdToRequest = false;
     if (!strlen($tsId)) {
         //			$tsId = date( 'Y-m-d_H-m-s_' ) . str_replace( array( '.', ':' ), array( '-', null ), SPRequest::ip( 'REMOTE_ADDR', 0, 'SERVER' ) );
         $tsId = microtime(true) * 100 . '.' . rand(0, 99) . '.' . str_replace(array(':', '.'), null, SPRequest::ip('REMOTE_ADDR', 0, 'SERVER'));
         SPLoader::loadClass('env.cookie');
         // in case we wre not able for some reason to set the cookie - we are going to pass this id into the URL
         if (!SPCookie::set('editentry', $tsId, SPCookie::hours(48))) {
             $tsIdToRequest = true;
         }
     }
     $store = array();
     if (count($fields)) {
         foreach ($fields as $field) {
             $field->enabled('form');
             try {
                 $request = $field->submit($this->_model, $tsId);
                 if (is_array($request) && count($request)) {
                     $store = array_merge($store, $request);
                 }
             } catch (SPException $x) {
                 $this->response(Sobi::Back(), $x->getMessage(), !$ajax, SPC::ERROR_MSG, array('error' => $field->get('nid')));
             }
         }
     }
     /* try in Sobi Cache first */
     if (Sobi::Cfg('cache.l3_enabled', true)) {
         SPFactory::cache()->addVar(array('post' => $_POST, 'files' => $_FILES, 'store' => $store), 'request_cache_' . $tsId);
     } else {
         $file = str_replace('.', '-', $tsId);
         SPFs::write(SPLoader::path('tmp.edit.' . $file . '.post', 'front', false, 'var'), SPConfig::serialize($_POST));
         SPFs::write(SPLoader::path('tmp.edit.' . $file . '.files', 'front', false, 'var'), SPConfig::serialize($_FILES));
         SPFs::write(SPLoader::path('tmp.edit.' . $file . '.store', 'front', false, 'var'), SPConfig::serialize($store));
     }
     if (!Sobi::Can('entry.payment.free') && SPFactory::payment()->count($this->_model->get('id'))) {
         $this->paymentView($tsId);
     } else {
         if ($customClass && method_exists($customClass, 'AfterSubmitEntry')) {
             $customClass::AfterSubmitEntry($this->_model);
         }
         $url = array('task' => 'entry.save', 'pid' => Sobi::Reg('current_section'), 'sid' => $sid);
         if ($tsIdToRequest) {
             $url['ssid'] = $tsId;
         }
         $this->response(Sobi::Url($url, false, false));
     }
 }
Exemple #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']));
     }
 }
Exemple #11
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();
 }
Exemple #12
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__);
     }
 }