Example #1
0
 private function limits($selected)
 {
     $f = SPConfig::fields($this->settings()->get('section'), array('chbxgroup', 'select', 'radio'));
     $fields = array('' => null);
     if (count($f)) {
         foreach ($f as $id => $type) {
             $labels = SPFactory::db()->select(array('sValue', 'language', 'sKey'), 'spdb_language', array('fid' => $id, 'oType' => 'field_option'))->loadAssocList();
             /** @var SPField $field */
             $field = SPFactory::Model('field');
             $field->init($id)->loadType();
             $options = $field->get('options');
             if (count($options)) {
                 foreach ($options as $value) {
                     $label = $value['label'];
                     foreach ($labels as $l) {
                         if ($l['sKey'] == $value['label']) {
                             $label = $l['sValue'];
                         }
                     }
                     if (isset($value['options'])) {
                         $fields[$type][$id . '::group::' . $value['id']] = '<b>' . $label . '</b>';
                         foreach ($value['options'] as $subOption) {
                             $fields[$type][$id . '::' . $subOption['id']] = $label . ' &gt; ' . $subOption['label'];
                         }
                     } else {
                         $fields[$type][$id . '::' . $value['id']] = $label;
                     }
                 }
             }
         }
     }
     return SPHtml_Input::select('jform[params][spLimit]', $fields, $selected, false, array('style' => 'width: 300px'));
 }
Example #2
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);
 }
Example #3
0
 /**
  * Simple initialisation method
  *
  */
 public function init()
 {
     if (self::$cs) {
         Sobi::Error('config', SPLang::e('CRITICAL_SECTION_VIOLATED'), SPC::ERROR, 500, __LINE__, __CLASS__);
     }
     /* define critical section to avoid infinite loops */
     self::$cs = true;
     $nameField = self::key('entry.name_field');
     if ($nameField) {
         $fc = SPLoader::loadModel('field');
         $field = new $fc();
         $field->init($nameField);
         $this->set('name_field_nid', $field->get('nid'), 'entry');
         $this->set('name_field_id', $field->get('fid'), 'entry');
     }
     if (defined('SOBIPRO_ADM')) {
         if (self::key('language.adm_domain')) {
             SPLang::registerDomain(self::key('language.adm_domain'));
         }
     } else {
         if (self::key('language.domain')) {
             SPLang::registerDomain(self::key('language.domain'));
         }
     }
     /* set allowed request attributes and tags */
     SPRequest::setTagsAllowed($this->key('html.allowed_tags_array'));
     SPRequest::setAttributesAllowed($this->key('html.allowed_attributes_array'));
     $this->_store['general']['root'] = SOBI_ROOT;
     $this->_store['general']['path'] = SOBI_PATH;
     $this->_store['general']['cms'] = SOBI_CMS;
     $this->_store['general']['live_path'] = SOBI_LIVE_PATH;
     /* leave critical section */
     self::$cs = false;
 }
Example #4
0
 /**
  * initialise config object
  * @return void
  */
 private function createConfig()
 {
     $this->_config =& SPFactory::config();
     /* load basic configuration settings */
     $this->_config->addIniFile('etc.config', true);
     $this->_config->addTable('spdb_config', $this->_section);
     /* initialise interface config setting */
     $this->_mainframe->getBasicCfg();
     /* initialise config */
     $this->_config->init();
 }
Example #5
0
 /**
  * @return SPConfig
  */
 public static function &config()
 {
     SPLoader::loadClass('base.config');
     return SPConfig::getInstance();
 }
Example #6
0
 public static function fields($sid = 0, $types = null)
 {
     if (!$sid) {
         $sid = SPRequest::sid('request', Sobi::Section(), false);
     }
     if (!$types) {
         $types = SPRequest::string('types', null);
         $types = SPFactory::config()->structuralData($types, true);
     }
     $fields = SPConfig::fields($sid, $types);
     if (SPRequest::bool('fields-xhr')) {
         SPFactory::mainframe()->cleanBuffer()->customHeader();
         exit(json_encode($fields));
     } else {
         return $fields;
     }
 }
Example #7
0
 /**
  * @param string $name variable name
  * @param string $property
  * @param string $request request method
  * @return string
  */
 public static function file($name, $property = null, $request = 'files')
 {
     if ($request == 'files') {
         /** check for Ajax uploaded files */
         $check = self::string($name);
         if ($check) {
             $secret = md5(Sobi::Cfg('secret'));
             $fileName = str_replace('file://', null, $check);
             $path = SPLoader::dirPath("tmp.files.{$secret}", 'front', false) . '/' . $fileName;
             if (file_exists("{$path}.var")) {
                 $cfg = SPFs::read("{$path}.var");
                 $data = SPConfig::unserialize($cfg);
                 $_FILES[$name] = $data;
             }
         }
     }
     self::init($name, $request);
     self::$val = isset(self::$request[self::$name]) ? self::$request[self::$name] : null;
     return $property && isset(self::$val[$property]) ? self::$val[$property] : self::$val;
 }
Example #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;
     }
     /* @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__);
         }
     }
 }
Example #9
0
 /**
  * Carga el archivo de configuración y lo guarda en caché.
  *
  * @return bool
  */
 public static function readConfig()
 {
     if (self::$_init) {
         return true;
     }
     if (!file_exists(CONFIG_FILE)) {
         return false;
     }
     // Include the file, save the data from $CONFIG
     include_once CONFIG_FILE;
     if (isset($CONFIG) && is_array($CONFIG)) {
         self::$_cache = $CONFIG;
     }
     // We cached everything
     self::$_init = true;
     return true;
 }
Example #10
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;
 }
Example #11
0
 /**
  * @param string $var
  * @param mixed $val
  * @return $this
  */
 public function &set($var, $val)
 {
     if (isset($this->{$var}) || property_exists($this, $var)) {
         if (is_array($this->{$var}) && is_string($val) && strlen($val) > 2) {
             try {
                 $val = SPConfig::unserialize($val, $var);
             } catch (SPException $x) {
                 Sobi::Error($this->name(), SPLang::e('%s.', $x->getMessage()), SPC::NOTICE, 0, __LINE__, __FILE__);
             }
         }
         $this->{$var} = $val;
     }
     return $this;
 }
Example #12
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));
 }
Example #13
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);
 }
Example #14
0
 /**
  *
  * @param int $errNumber
  * @param string $errString
  * @param string $errFile
  * @param int $errLine
  * @param string $errContext
  * @throws ErrorException
  * @throws Exception
  * @throws SPException
  * @return bool
  */
 function SPExceptionHandler($errNumber, $errString, $errFile, $errLine, $errContext)
 {
     if ($errNumber == E_STRICT && (!defined('SOBI_TESTS') || !SOBI_TESTS)) {
         return true;
     }
     $error = null;
     if (!strstr($errFile, 'sobipro')) {
         return false;
     }
     static $cs = 0;
     if ($cs > 100) {
         echo '<h1>Error handler: Violation of critical section. Possible infinite loop. Error reporting temporary disabled. ' . $errString . '</h1>';
         $cs = 0;
         return false;
     }
     if (!class_exists('SPLoader')) {
         /** @noinspection PhpIncludeInspection */
         require_once SOBI_PATH . '/lib/base/fs/loader.php';
     }
     if (strstr($errString, 'json://')) {
         $error = json_decode(str_replace('json://', null, $errString), true);
     }
     if (ini_get('error_reporting') < $errNumber && !(isset($error['code']) && $error['code'])) {
         $cs = 0;
         return false;
     }
     $backTrace = null;
     if (class_exists('SPConfig')) {
         $backTrace = SPConfig::getBacktrace();
     }
     if ($error) {
         $retCode = $error['code'];
         $errString = $error['message'];
         $errFile = $error['file'];
         $errLine = $error['line'];
         $section = $error['section'];
         $errContext = $error['content'];
     } else {
         $retCode = 0;
         if (!strstr($errFile, 'sobi')) {
             $cs = 0;
             return false;
         }
         /* stupid errors we already handle
          * and there is no other possibility to catch it
          * before it happens
          */
         if (strstr($errString, 'gzinflate')) {
             $cs = 0;
             return false;
         }
         if (strstr($errString, 'compress')) {
             $cs = 0;
             return false;
         }
         if (strstr($errString, 'domdocument.loadxml')) {
             $cs = 0;
             return false;
         }
         /** This really sucks - why do I have the possibility to override a method when I cannot change its parameters :(
          * A small design flaw - has to be changed later */
         if (strstr($errString, 'should be compatible with')) {
             $cs = 0;
             return false;
         }
         /* output of errors / call stack causes sometimes it - it's not really important */
         if (strstr($errString, 'Property access is not allowed yet')) {
             $cs = 0;
             return false;
         }
         $section = 'PHP';
     }
     $cs++;
     SPException::storeError($errNumber, $retCode, $errString, $errFile, $errLine, $section, $errContext, $backTrace);
     if ($retCode) {
         SPLoader::loadClass('base.mainframe');
         SPLoader::loadClass('cms.base.mainframe');
         SPFactory::mainframe()->runAway($errString, $retCode, $backTrace);
     } else {
         if ($errNumber == E_USER_ERROR || $errNumber == E_ERROR) {
             throw new ErrorException($errString, $retCode, $errNumber, $errFile, $errLine);
         }
     }
     $cs = 0;
     /** do not display our internal errors because this is an array */
     if ($error) {
         return true;
     }
     return false;
 }
Example #15
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']));
     }
 }
Example #16
0
 /**
  * @param $type
  * @param $id
  * @param int $sid
  * @param bool $force
  * @return bool
  */
 public function getObj($type, $id, $sid = 0, $force = false)
 {
     if ($this->enabled(!$force)) {
         $sid = $sid ? $sid : $this->_section;
         $id = (int) $id;
         $sid = (int) $sid;
         $lang = Sobi::Lang(false);
         $apc = false;
         if ($this->_apc) {
             $var = apc_fetch("com_sobipro_{$sid}_{$id}_{$type}_{$lang}", $apc);
             if (isset($var['classes'])) {
                 SPLoader::wakeUp(unserialize($var['classes']));
             }
         }
         if (!$apc) {
             $result = $this->Query("SELECT * FROM objects WHERE( type = '{$type}' AND id = '{$id}' AND lang = '{$lang}' AND sid = '{$sid}' )");
             if (!is_array($result) || !count($result)) {
                 return false;
             }
             if ($result['classes']) {
                 SPLoader::wakeUp(unserialize($result['classes']));
             }
             if ($result['schecksum'] != md5($result['data'])) {
                 Sobi::Error('cache', SPLang::e('Checksum of the encoded data does not match'), SPC::WARNING, 0, __LINE__, __FILE__);
                 return false;
             }
             $var = SPConfig::unserialize($result['data']);
         } else {
             $var = $var['obj'];
         }
         $this->_check[$type][$id] = false;
         return $var;
     } else {
         return false;
     }
 }
Example #17
0
 /**
  * @return array
  */
 public function struct()
 {
     if (!$this->dependency) {
         return parent::struct(true);
     }
     $selected = $this->getRaw();
     if (isset($this->_fData->options)) {
         $path = SPConfig::unserialize($this->_fData->options);
     } else {
         return null;
     }
     $selectedPath = array();
     $options = json_decode(SPFs::read(SOBI_PATH . '/etc/fields/select-list/definitions/' . str_replace('.xml', '.json', $this->dependencyDefinition)), true);
     if (isset($options['translation'])) {
         SPLang::load($options['translation']);
         $selected = Sobi::Txt(strtoupper($options['prefix']) . '.' . strtoupper($selected));
     }
     if (count($path) && isset($options['translation'])) {
         foreach ($path as $step) {
             $selectedPath[$step] = $selected = Sobi::Txt(strtoupper($options['prefix']) . '.' . strtoupper($step));
         }
     }
     $this->cleanCss();
     return array('_complex' => 1, '_data' => $selected, '_attributes' => array('class' => $this->cssClass), '_options' => array('path' => count($selectedPath) ? $selectedPath : $path));
 }
Example #18
0
 private function download()
 {
     //		$file = SPLoader::path( 'tmp.info', 'front', false, 'txt' );
     $cont = null;
     $settings = array();
     $settings['SobiPro'] = array('Version' => SPFactory::CmsHelper()->myVersion(true), 'Version_Num' => implode('.', SPFactory::CmsHelper()->myVersion()));
     $file = SPLoader::path('tmp.info', 'front', false, 'txt');
     //		if ( SPFs::exists( $file ) ) {
     //			$cont = SPFs::read( $file );
     //		}
     //		$cont = explode( "\n", $cont );
     //		if ( count( $cont ) ) {
     //			foreach ( $cont as $line ) {
     //				if ( strstr( $line, '=' ) ) {
     //					$line = explode( "=", $line );
     //					$line[ 1 ] = explode( ';', $line[ 1 ] );
     //					$settings[ $line[ 0 ] ] = array( 'key' => $line[ 0 ], 'response' => $line[ 1 ][ 0 ], 'status' => $line[ 1 ][ 1 ] );
     //				}
     //			}
     //		}
     $this->prepareStoredData($settings);
     $settings['env'] = array('PHP_OS' => PHP_OS, 'php_uname' => php_uname(), 'PHP_VERSION_ID' => PHP_VERSION_ID);
     $settings['ftp'] = $this->ftp();
     $settings['curl'] = $this->curlFull();
     $settings['exec']['response'] = $this->execResp();
     $settings['SOBI_SETTINGS'] = SPFactory::config()->getSettings();
     $c = SPFactory::db()->select('*', 'spdb_config')->loadObjectList();
     $sections = SPFactory::db()->select(array('nid', 'id'), 'spdb_object', array('oType' => 'section'))->loadAssocList('id');
     $as = array();
     foreach ($c as $key) {
         if ($key->section == 0 || !isset($sections[$key->section])) {
             continue;
         }
         $key->section = $sections[$key->section]['nid'];
         if (!isset($as[$key->section])) {
             $as[$key->section] = array();
         }
         if (!isset($as[$key->section][$key->cSection])) {
             $as[$key->section][$key->cSection] = array();
         }
         $_c = explode('_', $key->sKey);
         if ($_c[count($_c) - 1] == 'array') {
             $key->sValue = SPConfig::unserialize($key->sValue);
         }
         $as[$key->section][$key->cSection][$key->sKey] = $key->sValue;
     }
     $settings['SOBI_SETTINGS']['sections'] = $as;
     $apps = SPFactory::db()->select('*', 'spdb_plugins')->loadObjectList();
     foreach ($apps as $app) {
         $settings['Apps'][$app->pid] = get_object_vars($app);
     }
     $settings['SOBI_SETTINGS']['mail']['smtphost'] = $settings['SOBI_SETTINGS']['mail']['smtphost'] ? 'SET' : 0;
     $settings['SOBI_SETTINGS']['mail']['smtpuser'] = $settings['SOBI_SETTINGS']['mail']['smtpuser'] ? 'SET' : 0;
     $settings['SOBI_SETTINGS']['mail']['smtppass'] = $settings['SOBI_SETTINGS']['mail']['smtppass'] ? 'SET' : 0;
     $php = ini_get_all();
     unset($php['extension_dir']);
     unset($php['include_path']);
     unset($php['mysql.default_user']);
     unset($php['mysql.default_password']);
     unset($php['mysqli.default_pw']);
     unset($php['mysqli.default_user']);
     unset($php['open_basedir']);
     unset($php['pdo_mysql.default_socket']);
     unset($php['sendmail_path']);
     unset($php['session.name']);
     unset($php['session.save_path']);
     unset($php['soap.wsdl_cache_dir']);
     unset($php['upload_tmp_dir']);
     unset($php['doc_root']);
     unset($php['docref_ext']);
     unset($php['docref_root']);
     unset($php['mysql.default_socket']);
     $settings['PHP_SETTINGS'] = $php;
     $php = get_loaded_extensions();
     $settings['PHP_EXT'] = $php;
     $out = SPFactory::Instance('types.array');
     $data = $out->toXML($settings, 'settings');
     $data = str_replace(array(SOBI_ROOT, '></'), array('REMOVED', '>0</'), $data);
     $f = SPLang::nid($settings['SOBI_SETTINGS']['general']['site_name'] . '-' . date(DATE_RFC822));
     SPFactory::mainframe()->cleanBuffer();
     header('Cache-Control: no-cache, must-revalidate');
     header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
     header("Content-type: application/xml");
     header("Content-Disposition: attachment; filename=\"sobipro_system_{$f}.xml\"");
     header('Content-Length: ' . strlen($data));
     ob_clean();
     flush();
     echo $data;
     exit;
 }
Example #19
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;
 }
Example #20
0
 /**
  *
  */
 public function display($o = null)
 {
     if (SPRequest::cmd('format') == 'json' && Sobi::Cfg('output.json_enabled', false)) {
         return $this->jsonDisplay();
     }
     $type = $this->key('template_type', 'xslt');
     $f = null;
     $task = SPRequest::task();
     if ($this->key('functions')) {
         $f = $this->registerFunctions();
     }
     $out = null;
     if ($type != 'php' && Sobi::Cfg('global.disable_xslt', false)) {
         $type = 'php';
     }
     $parserClass = SPLoader::loadClass('mlo.template_' . $type);
     if ($parserClass) {
         /** @var $parser SPTemplateXSLT */
         $parser = new $parserClass();
     } else {
         throw new SPException(SPLang::e('CANNOT_LOAD_PARSER', $type));
     }
     $this->_attr['template_path'] = Sobi::FixPath(str_replace(SOBI_ROOT, Sobi::Cfg('live_site'), $this->_templatePath));
     $messages = SPFactory::message()->getMessages();
     if (count($messages)) {
         foreach ($messages as $type => $content) {
             $this->_attr['messages'][$type] = array_values($content);
         }
     }
     $parser->setProxy($this);
     $parser->setData($this->_attr);
     $parser->setXML($this->_xml);
     $parser->setCacheData(array('hidden' => $this->_hidden));
     $parser->setType($this->_type);
     $parser->setTemplate($this->_template);
     Sobi::Trigger('Display', $this->name(), array($type, &$this->_attr));
     $o = $o ? $o : strtolower($this->key('output', $this->key('output', 'html'), $this->tTask));
     $action = $this->key('form.action');
     if ($action) {
         $opt = SPFactory::mainframe()->form();
         if (is_array($opt) && count($opt)) {
             foreach ($opt as $l => $v) {
                 $this->addHidden($v, $l);
             }
         }
         $form = $this->csection('form');
         $form['method'] = isset($form['method']) && $form['method'] ? $form['method'] : 'post';
         $out .= "\n<form ";
         foreach ($form as $p => $v) {
             $out .= $p . '="' . $v . '" ';
         }
         $out .= ">\n";
     }
     $out .= $parser->display($o, $f);
     $hidden = null;
     if (count($this->_hidden)) {
         $this->_hidden[SPFactory::mainframe()->token()] = 1;
         foreach ($this->_hidden as $name => $value) {
             $hidden .= "\n<input type=\"hidden\" id=\"SP_{$name}\" name=\"{$name}\" value=\"{$value}\"/>";
         }
         // xhtml strict valid
         $hidden = "<div>{$hidden}</div>";
         $out .= $hidden;
     }
     $out .= $action ? "\n</form>\n" : null;
     /* SobiPro type specific content parser */
     Sobi::Trigger('ContentDisplay', $this->name(), array(&$out));
     /* common content parser */
     $cParse = $this->key('parse', -1);
     /* if it was specified in the template config file or it was set in the section config and not disabled in the template config */
     if (!(strstr($task, '.edit') || strstr($task, '.add') || in_array($task, Sobi::Cfg('plugins.content_disable', array())))) {
         if ($cParse == 1 || Sobi::Cfg('parse_template_content', false) && $cParse == -1) {
             Sobi::Trigger('Parse', 'Content', array(&$out));
         }
     }
     header('SobiPro: ' . Sobi::Section());
     if ($o == 'html' && (!strlen(SPRequest::cmd('format')) || SPRequest::cmd('format') == 'html' || SPRequest::int('crawl'))) {
         $out .= $this->pb();
         if ((SPRequest::cmd('dbg') || Sobi::Cfg('debug')) && Sobi::My('id')) {
             $start = Sobi::Reg('start');
             $mem = $start[0];
             $time = $start[1];
             $queries = SPFactory::db()->getCount();
             $mem = number_format(memory_get_usage() - $mem);
             $time = microtime(true) - $time;
             SPConfig::debOut("Memory: {$mem}<br/>Time: {$time}<br/> Queries: {$queries}");
         }
         echo "\n<!-- Start of SobiPro component-->\n<div id=\"SobiPro\" class=\"SobiPro\">\n{$out}\n</div>\n<!-- End of SobiPro component Copyright (C) 2011-2014 Sigsiu.NET GmbH -->\n";
     } else {
         $this->customOutput($out);
     }
     Sobi::Trigger('AfterDisplay', $this->name());
 }
Example #21
0
 private function details()
 {
     $levels = $this->get('levels');
     $error = $this->get('error');
     if ($error->errReq) {
         $error->errReq = "<a href=\"{$error->errReq}\" target\"_blank\">{$error->errReq}</a>";
     }
     if ($error->errRef) {
         $error->errRef = "<a href=\"{$error->errRef}\" target\"_blank\">{$error->errRef}</a>";
     }
     if ($error->errNum) {
         $error->errNum = $levels[$error->errNum];
     }
     if ($error->errBacktrace) {
         $error->errBacktrace = '<pre>' . SPConfig::debOut($error->errBacktrace, false, true) . '</pre>';
     }
     if ($error->errCont) {
         $error->errCont = '<pre>' . SPConfig::debOut($error->errCont, false, true) . '</pre>';
     }
     $error->errMsg = str_replace('href=\'function.', 'target="_blank" href=\'http://php.net/manual/en/function.', $error->errMsg);
     $this->assign($error, 'error');
 }
Example #22
0
 /**
  * @param string $var
  * @param mixed $val
  * @return \SPObject|void
  */
 public function set($var, $val)
 {
     static $types = array();
     if (!count($types)) {
         $types = array_merge($this->types(), self::$types);
     }
     if ($this->has($var) && isset($types[$var])) {
         if (is_array($this->{$var}) && is_string($val) && strlen($val) > 2) {
             try {
                 $val = SPConfig::unserialize($val, $var);
             } catch (SPException $x) {
                 Sobi::Error($this->name(), SPLang::e('%s.', $x->getMessage()), SPC::NOTICE, 0, __LINE__, __FILE__);
             }
         }
         $this->{$var} = $val;
     }
 }
Example #23
0
 /**
  * @param string $var
  * @param mixed $val
  */
 protected function _set($var, $val)
 {
     if ($this->has($var)) {
         if (is_array($this->{$var}) && is_string($val)) {
             try {
                 $val = SPConfig::unserialize($val, $var);
             } catch (SPException $x) {
                 Sobi::Error($this->name(), sprintf('Cannot unserialize: %s.', $x->getMessage()), SPC::NOTICE, 0, __LINE__, __FILE__);
             }
         }
         if (is_string($val)) {
             $val = $this->cgf($val);
         }
         $this->{$var} = $val;
     }
 }
Example #24
0
    /**
     */
    private function editForm()
    {
        $sid = SPRequest::int('pid');
        $sid = $sid ? $sid : SPRequest::sid();
        $view = SPFactory::View('entry', true);
        $this->checkTranslation();
        /* if adding new */
        if (!$this->_model) {
            $this->setModel(SPLoader::loadModel('entry'));
        }
        $this->_model->formatDatesToEdit();
        $id = $this->_model->get('id');
        if (!$id) {
            $this->_model->set('state', 1);
            $this->_model->set('approved', 1);
        } else {
            $view->assign($view->languages(), 'languages-list');
        }
        $this->_model->loadFields(Sobi::Reg('current_section'), true);
        $this->_model->formatDatesToEdit();
        if ($this->_model->isCheckedOut()) {
            SPFactory::message()->error(Sobi::Txt('EN.IS_CHECKED_OUT', $this->_model->get('name')), false);
        } else {
            /* check out the model */
            $this->_model->checkOut();
        }
        /* get fields for this section */
        /* @var SPEntry $this ->_model */
        $fields = $this->_model->get('fields');
        if (!count($fields)) {
            throw new SPException(SPLang::e('CANNOT_GET_FIELDS_IN_SECTION', Sobi::Reg('current_section')));
        }
        $revisionChange = false;
        $rev = SPRequest::cmd('revision');
        $revisionsDelta = array();
        if ($rev) {
            $revision = SPFactory::message()->getRevision(SPRequest::cmd('revision'));
            if (isset($revision['changes']) && count($revision['changes'])) {
                SPFactory::message()->warning(Sobi::Txt('HISTORY_REVISION_WARNING', $revision['changedAt']), false);
                foreach ($fields as $i => $field) {
                    if ($field->get('enabled') && $field->enabled('form')) {
                        if (isset($revision['changes']['fields'][$field->get('nid')])) {
                            $revisionData = $revision['changes']['fields'][$field->get('nid')];
                        } else {
                            $revisionData = null;
                        }
                        $currentData = $field->getRaw();
                        if (is_array($revisionData) && !is_array($currentData)) {
                            try {
                                $currentData = SPConfig::unserialize($currentData);
                            } catch (SPException $x) {
                            }
                        }
                        if ($revisionData || $currentData) {
                            if (md5(serialize($currentData)) != md5(serialize($revisionData))) {
                                $field->revisionChanged()->setRawData($revisionData);
                            }
                        }
                        $fields[$i] = $field;
                    }
                }
                unset($revision['changes']['fields']);
                foreach ($revision['changes'] as $attr => $value) {
                    if ($value != $this->_model->get($attr)) {
                        $revisionsDelta[$attr] = $value;
                        $this->_model->setRevData($attr, $value);
                    }
                }
                $revisionChange = true;
            } else {
                SPFactory::message()->error(Sobi::Txt('HISTORY_REVISION_NOT_FOUND'), false)->setSystemMessage();
            }
        }
        $f = array();
        foreach ($fields as $field) {
            if ($field->get('enabled') && $field->enabled('form')) {
                $f[] = $field;
            }
        }
        /* create the validation script to check if required fields are filled in and the filters, if any, match */
        $this->createValidationScript($fields);
        $view->assign($this->_model, 'entry');
        /* get the categories */
        $cats = $this->_model->getCategories(true);
        if (count($cats)) {
            $tCats = array();
            foreach ($cats as $cid) {
                /* ROTFL ... damn I like arrays ;-) */
                $tCats2 = SPFactory::config()->getParentPath($cid, true);
                if (is_array($tCats2) && count($tCats2)) {
                    $tCats[] = implode(Sobi::Cfg('string.path_separator'), $tCats2);
                }
            }
            if (count($tCats)) {
                $view->assign(implode("\n", $tCats), 'parent_path');
            }
            $view->assign(implode(", ", $cats), 'parents');
        } elseif ($this->_model->get('valid')) {
            $parent = $sid == Sobi::Reg('current_section') ? 0 : $sid;
            if ($parent) {
                $view->assign(implode(Sobi::Cfg('string.path_separator', ' > '), SPFactory::config()->getParentPath($parent, true)), 'parent_path');
            }
            $view->assign($parent, 'parents');
        } else {
            $n = null;
            $view->assign($n, 'parents');
            $view->assign($n, 'parent_path');
        }
        $history = array();
        $messages = SPFactory::message()->getHistory($id);
        if (count($messages)) {
            foreach ($messages as $message) {
                $message['change'] = Sobi::Txt('HISTORY_CHANGE_TYPE_' . str_replace('-', '_', strtoupper($message['change'])));
                $message['site'] = Sobi::Txt('HISTORY_CHANGE_AREA_' . strtoupper($message['site']));
                if (strlen($message['reason'])) {
                    $message['status'] = 1;
                } else {
                    $message['status'] = 0;
                }
                $history[] = $message;
            }
        }
        $versioningAdminBehaviour = Sobi::Cfg('entry.versioningAdminBehaviour', 1);
        if ($versioningAdminBehaviour || !Sobi::Cfg('entry.versioning', true)) {
            SPFactory::header()->addJsCode('
				SobiPro.jQuery( document ).ready( function () { SobiPro.jQuery( "[rel=\'entry.saveWithRevision\']" ).parent().css( "display", "none" ); } );
			');
        }
        $view->assign($this->_task, 'task')->assign($f, 'fields')->assign($id, 'id')->assign($history, 'history')->assign($revisionChange, 'revision-change')->assign($revisionsDelta, 'revision')->assign($versioningAdminBehaviour, 'history-behaviour')->assign(SPFactory::CmsHelper()->userSelect('entry.owner', $this->_model->get('owner') ? $this->_model->get('owner') : ($this->_model->get('id') ? 0 : Sobi::My('id')), true), 'owner')->assign(Sobi::Reg('current_section'), 'sid')->determineTemplate('entry', 'edit')->addHidden($rev, 'revision')->addHidden($sid, 'pid');
        $view->display();
    }
Example #25
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;
 }
Example #26
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();
 }
Example #27
0
 /**
  * @param string $section - error section. I.e. Entry controller
  * @param string $msg - main message
  * @param int $type - error type
  * @param int $code - error code
  * @param int $line - file line
  * @param string $file - file name
  * @param null $sMsg
  * @internal param string $smsg - additional message
  * @return null
  */
 public static function Error($section, $msg, $type = SPC::NOTICE, $code = 0, $line = null, $file = null, $sMsg = null)
 {
     if ($type == 0) {
         $type = SPC::NOTICE;
     }
     /*
      * Mi., Jul 4, 2012
      * So now could someone explain me what was the sense of the code below and why trigger_error was commented out??!!
      *
      * Mi., Jul 4, 2012
      * Ok, it doesn't make much sense.
      * This is what actually should be removed.
      * 		if( Sobi::Cfg( 'debug.level', 0 ) < $type ) { return true; }
      * It was the problem with the ACL when error reporting was disabled.
      * But why the hell I removed the damn trigger_error from it?!!!
      * Being sloppy again?!!!!
      * Frack me - it means that since 20.07.2011 the whole error reporting went in nirvana??
      */
     if ($type == E_USER_ERROR) {
         $rType = E_ERROR;
         $code = $code ? $code : 500;
     } elseif ($type == E_USER_WARNING) {
         $rType = E_WARNING;
     } else {
         $rType = $type;
     }
     if (Sobi::Cfg('debug.level', 0) >= $rType) {
         if ($file) {
             $sMsg .= sprintf('In file %s at line %d', $file, $line);
         }
         if (SPRequest::task()) {
             $sMsg .= ' [ ' . SPRequest::task() . ' ]';
         }
         $error = array('section' => $section, 'message' => $msg, 'code' => $code, 'file' => $file, 'line' => $line, 'content' => $sMsg);
         trigger_error('json://' . json_encode($error), $type);
     }
     if ($code) {
         SPLoader::loadClass('base.mainframe');
         SPLoader::loadClass('cms.base.mainframe');
         SPFactory::mainframe()->runAway($msg, $code, SPConfig::getBacktrace());
     }
     return null;
 }
Example #28
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);
 }