protected function save() { if (!SPFactory::mainframe()->checkToken()) { Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__); } $id = SPRequest::cmd('filter_id'); if ($id) { $this->validate('field.filter', 'filter'); $filters = $this->getFilters(); $name = SPRequest::string('filter_name', 'Filter Name'); $msg = str_replace(array("\n", "\t", "\r"), null, SPLang::clean(SPRequest::string('filter_message', 'The data entered in the $field field contains not allowed characters'))); $regex = SPLang::clean(SPRequest::raw('filter_regex', '/^[\\.*]+$/')); $regex = str_replace('[:apostrophes:]', '\\"' . "\\'", $regex); $regex = base64_encode(str_replace(array("\n", "\t", "\r"), null, $regex)); $custom = 'custom'; if (isset($filters[$id]) && !strlen($filters[$id]['options'])) { $regex = $filters[$id]['params']; $custom = null; } $filters[$id] = array('params' => $regex, 'key' => $id, 'value' => $name, 'description' => $msg, 'options' => $custom); SPFactory::registry()->saveDBSection($filters, 'fields_filter'); $this->response(Sobi::Url('filter'), Sobi::Txt('FLR.MSG_FILTER_SAVED'), false, 'success'); } else { $this->response(Sobi::Url('filter'), SPLang::e('FILTER_NOT_FOUND'), true, SPC::ERROR_MSG); } }
protected function search() { if (!SPFactory::mainframe()->checkToken()) { Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__); } // $selected = SPRequest::int( 'selected', 0 ); $ssid = SPRequest::base64('ssid'); $query = SPRequest::string('q', null); $session = SPFactory::user()->getUserState('userSelector', null, array()); $setting = $session[$ssid]; /* get the site to display */ $site = SPRequest::int('site', 1); $eLim = Sobi::Cfg('user_selector.entries_limit', 18); $eLimStart = ($site - 1) * $eLim; $params = array(); if ($query) { $q = '%' . $query . '%'; $params = SPFactory::db()->where(array('name' => $q, 'username' => $q, 'email' => $q), 'OR'); } try { $count = SPFactory::db()->select('COUNT(*)', '#__users', $params, $setting['ordering'])->loadResult(); $data = SPFactory::db()->select(array('id', 'name', 'username', 'email', 'registerDate', 'lastvisitDate'), '#__users', $params, $setting['ordering'], $eLim, $eLimStart)->loadAssocList(); } catch (SPException $x) { echo $x->getMessage(); exit; } $response = array('sites' => ceil($count / $eLim), 'site' => $site); if (count($data)) { $replacements = array(); preg_match_all('/\\%[a-z]*/', $setting['format'], $replacements); $placeholders = array(); if (isset($replacements[0]) && count($replacements[0])) { foreach ($replacements[0] as $placeholder) { $placeholders[] = str_replace('%', null, $placeholder); } } if (count($replacements)) { foreach ($data as $index => $user) { $txt = $setting['format']; foreach ($placeholders as $attribute) { if (isset($user[$attribute])) { $txt = str_replace('%' . $attribute, $user[$attribute], $txt); } } $data[$index]['text'] = $txt; } } $response['users'] = $data; } SPFactory::mainframe()->cleanBuffer(); echo json_encode($response); exit; }
protected function save() { if (!SPFactory::mainframe()->checkToken()) { Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__); } $data = SPRequest::string('bankdata', null, true); $data = array('key' => 'bankdata', 'value' => $data, 'type' => 'application', 'id' => Sobi::Section(), 'section' => Sobi::Section()); try { SPLang::saveValues($data); } catch (SPException $x) { $message = SPLang::e('DB_REPORTS_ERR', $x->getMessage()); Sobi::Error('SPPaymentBt', $message, SPC::WARNING, 0, __LINE__, __FILE__); $this->response(Sobi::Back(), $message, false, 'error'); } $this->response(Sobi::Back(), Sobi::Txt('MSG.ALL_CHANGES_SAVED'), false, 'success'); }
protected function save() { if (!SPFactory::mainframe()->checkToken()) { Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__); } $this->validate('extensions.paypal', array('task' => 'paypal', 'pid' => Sobi::Section())); SPFactory::registry()->saveDBSection(array(array('key' => 'ppurl', 'value' => SPRequest::string('ppurl')), array('key' => 'ppemail', 'value' => SPRequest::string('ppemail')), array('key' => 'ppcc', 'value' => SPRequest::string('ppcc')), array('key' => 'pprurl', 'value' => SPRequest::string('pprurl'))), 'paypal_' . Sobi::Section()); $data = array('key' => 'ppexpl', 'value' => SPRequest::string('ppexpl', null, true), 'type' => 'application', 'id' => Sobi::Section(), 'section' => Sobi::Section()); try { SPLang::saveValues($data); $data['key'] = 'ppsubject'; $data['value'] = SPRequest::string('ppsubject', true); SPLang::saveValues($data); } catch (SPException $x) { $message = SPLang::e('DB_REPORTS_ERR', $x->getMessage()); Sobi::Error('SPPaymentBt', $message, SPC::WARNING, 0, __LINE__, __FILE__); $this->response(Sobi::Back(), $message, false, 'error'); } $this->response(Sobi::Back(), Sobi::Txt('MSG.ALL_CHANGES_SAVED'), false, 'success'); }
/** * */ public function ProxyDependency() { $path = json_decode(Sobi::Clean(SPRequest::string('path')), true); $values = $this->loadDependencyDefinition($path); SPFactory::mainframe()->cleanBuffer()->customHeader(); exit(json_encode(array('options' => $values, 'path' => json_encode($path)))); }
private function webServer() { $server = SPRequest::string('SERVER_SOFTWARE', getenv('SERVER_SOFTWARE'), null, 'server'); // $server = 'Apache'; $server = preg_split('/[\\/ ]/', $server); $soft = isset($server[0]) ? $server[0] : 'Unknown'; $ver = isset($server[1]) ? preg_replace('/[^0-9\\.]/i', null, $server[1]) : '0.0.0'; $ver = explode('.', $ver); $sapi = function_exists('php_sapi_name') ? php_sapi_name() : 'Unknown'; if (strtolower($soft) != 'apache') { echo $this->warning($this->txt('REQ.WS_WRONG_SOFTWARE', array('webserver' => SPRequest::string('SERVER_SOFTWARE', getenv('SERVER_SOFTWARE'), null, 'server'))), __FUNCTION__); } else { $minVer = array('major' => 2, 'minor' => 0, 'build' => 0); $rVer = array('major' => 2, 'minor' => 2, 'build' => 0); if (!(isset($ver[0]) && isset($ver[1]) && isset($ver[2])) || !($ver[0] && $ver[1])) { echo $this->warning($this->txt('REQ.WS_NO_APACHE_VER', array('required' => implode('.', $minVer), 'sapi' => $sapi)), __FUNCTION__); exit; } $ver = array('major' => $ver[0], 'minor' => $ver[1], 'build' => isset($ver[2]) ? $ver[2] : 0); if (!$this->compareVersion($minVer, $ver)) { echo $this->error($this->txt('REQ.WS_WRONG_VER', array('required' => implode('.', $minVer), 'installed' => implode('.', $ver), 'sapi' => $sapi)), __FUNCTION__); } else { echo $this->ok($this->txt('REQ.WS_VERSION_OK', array('installed' => implode('.', $ver), 'sapi' => $sapi)), __FUNCTION__); } } }
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; } }
/** * (non-PHPdoc) * @see Site/lib/models/SPDBObject#save() */ public function save($request = 'post') { $this->loadFields(Sobi::Section(), true); // Thu, Feb 19, 2015 12:12:47 - it should be actually "beforeSave" Sobi::Trigger($this->name(), 'Before' . ucfirst(__FUNCTION__), array($this->id)); /* save the base object data */ /* @var SPdb $db */ $db = SPFactory::db(); $db->transaction(); if (!$this->nid || SPRequest::task() == 'entry.clone') { $this->nid = SPRequest::string($this->nameField, null, false, $request); $this->nid = $this->createAlias(); $this->name = $this->nid; } if (Sobi::Cfg('entry.publish_limit', 0) && !defined('SOBI_ADM_PATH')) { SPRequest::set('entry_createdTime', 0, $request); SPRequest::set('entry_validSince', 0, $request); SPRequest::set('entry_validUntil', 0, $request); $this->validUntil = gmdate('Y-m-d H:i:s', time() + Sobi::Cfg('entry.publish_limit', 0) * 24 * 3600); } $preState = Sobi::Reg('object_previous_state'); parent::save($request); $nameField = $this->nameField(); /* get the fields for this section */ foreach ($this->fields as $field) { /* @var $field SPField */ try { if ($field->enabled('form', $preState['new'])) { $field->saveData($this, $request); } else { $field->finaliseSave($this, $request); } if ($field->get('id') == $nameField) { /* get the entry name */ $this->name = $field->getRaw(); /* save the nid (name id) of the field where the entry name is saved */ $this->nameField = $field->get('nid'); } } catch (SPException $x) { if (SPRequest::task() != 'entry.clone') { $db->rollback(); throw new SPException(SPLang::e('CANNOT_SAVE_FIELS_DATA', $x->getMessage())); } else { Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_FIELS_DATA', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } } $values = array(); /* get categories */ $cats = Sobi::Reg('request_categories'); if (!count($cats)) { $cats = SPRequest::arr('entry_parent', SPFactory::registry()->get('request_categories', array()), $request); } /* by default it should be comma separated string */ if (!count($cats)) { $cats = SPRequest::string('entry_parent', null, $request); if (strlen($cats) && strpos($cats, ',')) { $cats = explode(',', $cats); foreach ($cats as $i => $cat) { $c = (int) trim($cat); if ($c) { $cats[$i] = $c; } else { unset($cats[$i]); } } } elseif (strlen($cats)) { $cats = array((int) $cats); } } if (is_array($cats) && count($cats)) { foreach ($cats as $i => $v) { if (!$v) { unset($cats[$i]); } } } if (is_array($cats) && count($cats)) { /* get the ordering in these categories */ try { $db->select('pid, MAX(position)', 'spdb_relations', array('pid' => $cats, 'oType' => 'entry'), null, 0, 0, false, 'pid'); $cPos = $db->loadAssocList('pid'); $currPos = $db->select(array('pid', 'position'), 'spdb_relations', array('id' => $this->id, 'oType' => 'entry'))->loadAssocList('pid'); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } /* set the right position */ foreach ($cats as $i => $cat) { $copy = 0; if (!$this->approved) { $copy = isset($this->categories[$cats[$i]]) ? 0 : 1; } else { $db->delete('spdb_relations', array('id' => $this->id, 'oType' => 'entry')); } if (isset($currPos[$cat])) { $pos = $currPos[$cat]['position']; } else { $pos = isset($cPos[$cat]) ? $cPos[$cat]['MAX(position)'] : 0; $pos++; } $values[] = array('id' => $this->id, 'pid' => $cats[$i], 'oType' => 'entry', 'position' => $pos, 'validSince' => $this->validSince, 'validUntil' => $this->validUntil, 'copy' => $copy); } try { $db->insertArray('spdb_relations', $values, true); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } } elseif (!count($this->categories)) { throw new SPException(SPLang::e('MISSING_CAT')); } /* trigger possible state changes */ if ($preState['approved'] != $this->approved) { if ($this->approved) { $this->approveFields(true); // it's being done by the method above - removing //Sobi::Trigger( $this->name(), 'AfterApprove', array( $this->id, $this->approved ) ); } } if ($preState['state'] != $this->state) { Sobi::Trigger($this->name(), 'AfterChangeState', array($this->id, $this->state)); } SPFactory::cache()->purgeSectionVars(); SPFactory::cache()->deleteObj('entry', $this->id); if (count($cats)) { foreach ($cats as $cat) { SPFactory::cache()->deleteObj('category', $cat); } } Sobi::Trigger($this->name(), 'After' . ucfirst($preState['new'] ? __FUNCTION__ : 'Update'), array(&$this)); }
protected function save($apply, $clone = false) { if (!SPFactory::mainframe()->checkToken()) { Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__); } $sets = array(); if (!$clone) { $sid = SPRequest::sid() ? SPRequest::sid() : SPRequest::int('entry_id'); } else { $sid = 0; } $apply = (int) $apply; if (!$this->_model) { $this->setModel(SPLoader::loadModel($this->_type)); } $this->_model->init($sid); $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, $_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); $this->authorise($this->_model->get('id') ? 'edit' : 'add'); try { $this->_model->validate('post'); } catch (SPException $x) { $back = Sobi::GetUserState('back_url', Sobi::Url(array('task' => 'entry.add', 'sid' => Sobi::Section()))); $data = $x->getData(); $this->response($back, $x->getMessage(), false, 'error', array('required' => $data['field'])); } try { $this->_model->save(); } catch (SPException $x) { $back = Sobi::GetUserState('back_url', Sobi::Url(array('task' => 'entry.add', 'sid' => Sobi::Section()))); $this->response($back, $x->getMessage(), false, 'error'); } $sid = $this->_model->get('id'); $sets['sid'] = $sid; $sets['entry.nid'] = $this->_model->get('nid'); $sets['entry.id'] = $sid; if ($customClass && method_exists($customClass, 'AfterStoreEntry')) { $customClass::AfterStoreEntry($this->_model); } if (SPRequest::string('history-note') || $this->_task == 'saveWithRevision' || Sobi::Cfg('entry.versioningAdminBehaviour', 1)) { $this->logChanges('save', SPRequest::string('history-note')); } if ($apply || $clone) { if ($clone) { $msg = Sobi::Txt('MSG.OBJ_CLONED', array('type' => Sobi::Txt($this->_model->get('oType')))); $this->response(Sobi::Url(array('task' => $this->_type . '.edit', 'sid' => $sid)), $msg); } else { $msg = Sobi::Txt('MSG.OBJ_SAVED', array('type' => Sobi::Txt($this->_model->get('oType')))); $this->response(Sobi::Url(array('task' => $this->_type . '.edit', 'sid' => $sid)), $msg, false, 'success', array('sets' => $sets)); } } elseif ($this->_task == 'saveAndNew') { $msg = Sobi::Txt('MSG.ALL_CHANGES_SAVED'); $sid = $this->_model->get('parent'); if (!$sid) { $sid = Sobi::Section(); } $this->response(Sobi::Url(array('task' => $this->_type . '.add', 'sid' => $sid)), $msg, true, 'success', array('sets' => $sets)); } else { $this->response(Sobi::Back(), Sobi::Txt('MSG.OBJ_SAVED', array('type' => Sobi::Txt($this->_model->get('oType'))))); } }
/** * @param string $name - The name of the cookie. * @param string $value - The value of the cookie * @param int $expire - The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch * @param bool $httponly - When true the cookie will be made accessible only through the HTTP protocol. * @param bool $secure - Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client * @param string $path - The path on the server in which the cookie will be available on * @param string $domain - The domain that the cookie is available * @return bool */ public static function set($name, $value, $expire = 0, $httponly = false, $secure = false, $path = '/', $domain = null) { $name = self::prefix . $name; $expire = $expire == 0 ? $expire : time() + $expire; return SPFactory::mainframe()->setCookie($name, $value, $expire, $httponly, $secure, $path, $domain) && SPRequest::string($name, null, false, 'cookie'); }
/** * @param $xml DOMDocument * @param $template string * @param array $data * @return bool */ public function addView($xml, $template, $data = array()) { if (!Sobi::Cfg('cache.xml_enabled') || $this->_cachedView || Sobi::Reg('break_cache_view') || Sobi::My('id') && Sobi::Cfg('cache.xml_no_reg')) { return false; } if (!in_array(SPRequest::task('get'), $this->_disableViewCache)) { foreach ($this->_disableObjectCache as $task) { if (strstr(SPRequest::task(), $task)) { return false; } } if (count($_REQUEST)) { foreach ($_REQUEST as $k => $v) { if (!isset($this->requestStore[$k])) { $data['request'][$k] = SPRequest::string($k); } } } $data['pathway'] = SPFactory::mainframe()->getPathway(); $this->view['xml'] = $xml; $this->view['template'] = $template; $this->view['data'] = $data; } }
/** * Save a rule * * @param bool $apply */ protected function save($apply) { Sobi::Trigger('Save', 'Acl', array(&$this)); if (!SPFactory::mainframe()->checkToken()) { Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__); } $rid = SPRequest::int('rid', 'null'); $this->validate('acl.edit', array('task' => 'acl.edit', 'rid' => $rid)); if ($rid) { $this->remove($rid); } $vs = SPRequest::timestamp('set_validSince'); $vu = SPRequest::timestamp('set_validUntil'); $vs = $vs ? date(Sobi::Cfg('db.date_format', 'Y-m-d H:i:s'), $vs) : null; $vu = $vu ? date(Sobi::Cfg('db.date_format', 'Y-m-d H:i:s'), $vu) : null; $name = SPRequest::string('set_name'); $nid = SPRequest::cmd('set_nid'); $note = SPRequest::string('set_note'); $state = SPRequest::int('set_state', 1); $gids = SPRequest::arr('set_groups'); $sids = SPRequest::arr('set_sections'); $pf = SPRequest::arr('set_permissions', array()); $pa = SPRequest::arr('set_adm_permissions', array()); // if can publish any, then can see any unpublished if (in_array(20, $pf)) { $pf[] = 14; } // if can publish own, then can see own unpublished if (in_array(21, $pf)) { $pf[] = 12; } if (in_array(19, $pf)) { $pf[] = 15; } $perms = array_merge($pf, $pa); /* @var SPdb $db */ $db = SPFactory::db(); /* update or insert the rule definition */ try { $db->insertUpdate('spdb_permissions_rules', array('rid' => $rid, 'name' => $name, 'nid' => $nid, 'validSince' => $vs, 'validUntil' => $vu, 'note' => $note, 'state' => $state)); } catch (SPException $x) { Sobi::Error('ACL', SPLang::e('CANNOT_CREATE_RULE_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } $rid = (int) $rid ? (int) $rid : $db->insertid(); /* insert the groups ids */ if (count($gids)) { foreach ($gids as $i => $gid) { $gids[$i] = array('rid' => $rid, 'gid' => $gid); } try { $db->insertArray('spdb_permissions_groups', $gids); } catch (SPException $x) { Sobi::Error('ACL', SPLang::e('CANNOT_INSERT_GROUPS_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } try { $db->select('*', 'spdb_permissions', array('site' => 'adm', 'value' => 'global')); $admPermissions = $db->loadResultArray(); } catch (SPException $x) { Sobi::Error('ACL', SPLang::e('CANNOT_GET_PERMISSIONS_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } /* create permission and section map */ if (count($sids) && count($perms)) { $map = array(); /* travel the sections */ foreach ($sids as $sid) { foreach ($perms as $pid) { if (in_array($pid, $admPermissions)) { $map[] = array('rid' => $rid, 'sid' => 0, 'pid' => $pid); } else { $map[] = array('rid' => $rid, 'sid' => $sid, 'pid' => $pid); } } } try { $db->insertArray('spdb_permissions_map', $map, true); } catch (SPException $x) { Sobi::Error('ACL', SPLang::e('CANNOT_INSERT_GROUPS_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } SPFactory::cache()->cleanAll(); /* trigger plugins */ Sobi::Trigger('AfterSave', 'Acl', array(&$this)); /* set redirect */ $this->response(Sobi::Url($apply ? array('task' => 'acl.edit', 'rid' => $rid) : 'acl'), Sobi::Txt('ACL_RULE_SAVED'), !$apply, SPC::SUCCESS_MSG, array('sets' => array('rid' => $rid))); }
/** * @param SPEntry $entry * @param string $request * @throws SPException * @return string * @throw SPException */ private function verify($entry, $request) { $data = SPRequest::arr($this->nid, array(), $request); if (!$data) { $dataString = SPRequest::string($this->nid, null, false, $request); if (strstr($dataString, '://')) { $data = SPFactory::config()->structuralData($dataString); } else { $dataString = SPRequest::int($this->nid, 0, $request); if ($dataString) { $data = array($dataString); } } } else { if (count($data) > $this->catsMaxLimit && count($data) > 1) { $data = array_slice($data, 0, $this->catsMaxLimit); } } $dexs = count($data); /* check if it was required */ if ($this->required && !$dexs && $this->method != 'fixed') { throw new SPException(SPLang::e('FIELD_REQUIRED_ERR', $this->name)); } /* check if there was an adminField */ if ($this->adminField && $dexs && $this->method != 'fixed') { if (!Sobi::Can('entry.adm_fields.edit')) { throw new SPException(SPLang::e('FIELD_NOT_AUTH', $this->name)); } } /* check if it was free */ if (!$this->isFree && $this->fee && $dexs) { SPFactory::payment()->add($this->fee, $this->name, $entry->get('id'), $this->fid); } /* check if it was editLimit */ if ($this->editLimit == 0 && !Sobi::Can('entry.adm_fields.edit') && $dexs) { throw new SPException(SPLang::e('FIELD_NOT_AUTH_EXP', $this->name)); } /* check if it was editable */ if (!$this->editable && !Sobi::Can('entry.adm_fields.edit') && $dexs && $entry->get('version') > 1) { throw new SPException(SPLang::e('FIELD_NOT_AUTH_NOT_ED', $this->name)); } if (!$dexs) { $data = array(); } $this->setData($data); return $data; }
/** * @return string */ public function getBack() { $r = Sobi::GetUserState('back_url', Sobi::Url()); if (!$r) { $r = SPRequest::string('HTTP_REFERER', self::url(), false, 'SERVER'); } return $r; }
/** * 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__); } } }
/** * Save existing field */ protected function save($clone = false) { $sets = array(); if (!SPFactory::mainframe()->checkToken()) { Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__); } $fid = SPRequest::int('fid'); $field = SPFactory::Model('field', true); if ($fid) { $f = $this->loadField($fid); $field->extend($f); } else { $field->loadType(SPRequest::cmd('field_fieldType')); } $nid = SPRequest::cmd('field_nid'); if (!$nid || !strstr($nid, 'field_')) { /** give me my spaces back!!! */ $nid = strtolower(str_replace('-', '_', SPLang::nid('field_' . SPRequest::string('field_name')))); SPRequest::set('field_nid', $nid); } $this->getRequest(); $this->validate($field); if ($clone || !$fid) { try { $fid = $field->saveNew($this->attr); $field->save($this->attr); } catch (SPException $x) { $this->response(Sobi::Url(array('task' => 'field.edit', 'fid' => $fid, 'sid' => SPRequest::sid())), $x->getMessage(), false, SPC::ERROR_MSG); } } else { try { $field->save($this->attr); } catch (SPException $x) { $this->response(Sobi::Url(array('task' => 'field.edit', 'fid' => $fid, 'sid' => SPRequest::sid())), $x->getMessage(), false, SPC::ERROR_MSG); } } $alias = $field->get('nid'); $fieldSets = $field->get('sets'); if (is_array($fieldSets) && count($fieldSets)) { $sets = array_merge($fieldSets, $sets); } $sets['fid'] = $field->get('fid'); $sets['field.nid'] = $alias; /* in case we are changing the sort by field */ if (Sobi::Cfg('list.entries_ordering') == $alias && $field->get('nid') != $alias) { SPFactory::config()->saveCfg('list.entries_ordering', $field->get('nid')); } SPFactory::cache()->cleanSection(); if ($this->_task == 'apply' || $clone) { if ($clone) { $msg = Sobi::Txt('FM.FIELD_CLONED'); $this->response(Sobi::Url(array('task' => 'field.edit', 'fid' => $fid, 'sid' => SPRequest::sid())), $msg); } else { $msg = Sobi::Txt('MSG.ALL_CHANGES_SAVED'); $this->response(Sobi::Url(array('task' => 'field.edit', 'fid' => $fid, 'sid' => SPRequest::sid())), $msg, false, 'success', array('sets' => $sets)); } } else { $this->response(Sobi::Back(), Sobi::Txt('MSG.ALL_CHANGES_SAVED')); } }
/** * @param string $path * @deprecated since 1.1 */ public function loadConfig($path) { SPFactory::header()->addCssFile('adm.legacy')->addJsFile(array('adm.legacy', 'menu')); $this->_legacy = true; if (strlen($path)) { $this->_config = SPLoader::loadIniFile($path, true, true, true); } Sobi::Trigger('beforeLoadConfig', $this->name(), array(&$this->_config)); if (isset($this->_config['css_files'])) { foreach ($this->_config['css_files'] as $file) { $this->loadCSSFile($file); } unset($this->_config['css_files']); } if (isset($this->_config['js_files'])) { foreach ($this->_config['js_files'] as $file) { $this->loadJsFile($file); } unset($this->_config['js_files']); } if ($this->key('site_title')) { $this->setTitle($this->key('site_title')); } if (isset($this->_config['toolbar'])) { /* in case we are adding new entry/category/field we have to remove the 'duplicate' button and the separators after and before*/ if ($this->get('task') == 'add' || $this->get('task') == 'new') { $previous = null; $next = false; foreach ($this->_config['toolbar'] as $key => $value) { $previous = $key; if ($key == 'duplicate') { if ($next && isset($this->_config['toolbar'][$key])) { unset($this->_config['toolbar'][$key]); break; } unset($this->_config['toolbar']['duplicate']); if ($previous && isset($this->_config['toolbar'][$previous])) { unset($this->_config['toolbar'][$previous]); } $next = true; } } } $menu = array(); foreach ($this->_config['toolbar'] as $type => $settings) { $type = preg_replace('/\\_{1}[a-zA-Z0-9]$/', null, $type); $cfg = $this->parseMenu(explode('|', $settings)); $menu[] = array('type' => $type, 'settings' => $cfg); } $this->legacyToolbar($menu); unset($this->_config['toolbar']); } if (!isset($this->_config['submenu'])) { $this->_config['submenu'] = SPLoader::loadIniFile('etc.adm.submenu', false); } if (isset($this->_config['submenu'])) { //// SPLoader::loadClass( 'cms.html.admin_menu' ); // foreach ( $this->_config[ 'submenu' ] as $type => $settings ) { //// $type = preg_replace( '/\_{1}[a-zA-Z0-9]$/', null, $type ); // $cfg = $this->parseMenu( explode( '|', $settings ) ); // call_user_func_array( array( 'SPAdmMenu', 'addSubMenuEntry' ), $cfg ); // } unset($this->_config['submenu']); } if (isset($this->_config['hidden'])) { foreach ($this->_config['hidden'] as $name => $defValue) { $this->addHidden(SPRequest::string($name, $defValue), $name); } } Sobi::Trigger('afterLoadConfig', $this->name(), array(&$this->_config)); }
/** */ private function editForm() { if ($this->_task != 'add') { $sid = SPRequest::sid(); $sid = $sid ? $sid : SPRequest::int('pid'); } else { $this->authorise($this->_task, 'own'); $this->_model = null; $sid = SPRequest::int('pid'); // $section = SPFactory::Section( Sobi::Section() ); } if ($this->_model && $this->_model->isCheckedOut()) { Sobi::Redirect(Sobi::Url(array('sid' => SPRequest::sid())), Sobi::Txt('EN.IS_CHECKED_OUT', $this->_model->get('name')), SPC::ERROR_MSG, true); } /* determine template package */ $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE); /* load template config */ $this->template(); $this->tplCfg($tplPackage); /* check if we have stored last edit in cache */ $this->getCache(SPRequest::string('editentry', null, false, 'cookie'), 'editcache'); $section = SPFactory::Model('section'); $section->init(Sobi::Section()); SPFactory::cache()->setJoomlaCaching(false); if ($this->_model) { /* handle meta data */ SPFactory::header()->objMeta($this->_model); /* add pathway */ SPFactory::mainframe()->addObjToPathway($this->_model); } else { /* handle meta data */ SPFactory::header()->objMeta($section); if ($this->_task == 'add') { SPFactory::header()->addKeyword($section->get('efMetaKeys'))->addDescription($section->get('efMetaDesc')); } SPFactory::mainframe()->addToPathway(Sobi::Txt('EN.ADD_PATH_TITLE'), Sobi::Url('current')); SPFactory::mainframe()->setTitle(Sobi::Txt('EN.ADD_TITLE', array('section' => $section->get('name')))); /* add pathway */ SPFactory::mainframe()->addObjToPathway($section); $this->setModel(SPLoader::loadModel('entry')); } $this->_model->formatDatesToEdit(); $id = $this->_model->get('id'); if (!$id) { $this->_model->set('state', 1); } if ($this->_task != 'add' && !$this->authorise($this->_task, $this->_model->get('owner') == Sobi::My('id') ? 'own' : '*')) { throw new SPException(SPLang::e('YOU_ARE_NOT_AUTH_TO_EDIT_THIS_ENTRY')); } $this->_model->loadFields(Sobi::Reg('current_section')); /* get fields for this section */ $fields = $this->_model->get('fields'); if (!count($fields)) { throw new SPException(SPLang::e('CANNOT_GET_FIELDS_IN_SECTION', Sobi::Reg('current_section'))); } /* create the validation script to check if required fields are filled in and the filters, if any, match */ $this->createValidationScript($fields); /* check out the model */ $this->_model->checkOut(); $class = SPLoader::loadView('entry'); $view = new $class($this->template); $view->assign($this->_model, 'entry'); $cache = Sobi::Reg('editcache'); /* get the categories */ if (isset($cache) && isset($cache['entry_parent'])) { $cats = explode(',', $cache['entry_parent']); } else { $cats = $this->_model->getCategories(true); } if (count($cats)) { $tCats = array(); foreach ($cats as $cid) { $tCats2 = SPFactory::config()->getParentPath((int) $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'); } else { $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'); } $view->assign($this->_task, 'task'); $view->assign($fields, 'fields'); $view->assign($id, 'id'); $view->assign($id, 'sid'); $view->assign(SPFactory::user()->getCurrent(), 'visitor'); $view->setConfig($this->_tCfg, $this->template); $view->setTemplate($tplPackage . '.' . $this->templateType . '.' . ($this->template == 'add' ? 'edit' : $this->template)); $view->addHidden($sid ? $sid : SPRequest::sid(), 'pid'); $view->addHidden($id, 'sid'); $view->addHidden(SPRequest::int('pid') && SPRequest::int('pid') != $id ? SPRequest::int('pid') : Sobi::Section(), 'pid'); $view->addHidden('entry.submit', SOBI_TASK); Sobi::Trigger($this->name(), __FUNCTION__, array(&$view)); $view->display(); }
protected function search() { $this->_request = SPRequest::search('field_'); $this->_request['search_for'] = str_replace('*', '%', SPRequest::string('sp_search_for', null)); $this->_request['phrase'] = SPRequest::string('spsearchphrase', Sobi::Cfg('search.form_searchphrase_def', 'all')); $this->_request['phrase'] = strlen($this->_request['phrase']) ? $this->_request['phrase'] : Sobi::Cfg('search.form_searchphrase_def', 'all'); $ssid = SPRequest::cmd('ssid', SPRequest::cmd('ssid', null, 'cookie')); $this->_fields = $this->loadFields(); $searchForString = false; Sobi::Trigger('OnRequest', 'Search', array(&$this->_request)); $searchLimit = Sobi::Cfg('search.result_limit', 1000); for ($i = 1; $i < 11; $i++) { $this->_resultsByPriority[$i] = array(); } // if the visitor wasn't on the search page first if (!$ssid || SPRequest::int('reset', 0)) { $this->session($ssid); } /* clean request */ if (count($this->_request)) { foreach ($this->_request as $i => $v) { if (is_array($v)) { foreach ($v as $index => $value) { $v[$index] = htmlspecialchars_decode($value, ENT_QUOTES); } $this->_request[$i] = SPRequest::cleanArray($v, true); } else { $this->_request[$i] = $this->_db->escape($v); } } } /* sort fields by priority */ usort($this->_fields, array('self', 'sortByPrio')); /* First the basic search ..... */ /* if we have a string to search */ if (strlen($this->_request['search_for']) && $this->_request['search_for'] != Sobi::Txt('SH.SEARCH_FOR_BOX')) { $searchForString = true; $this->_narrowing = true; switch ($this->_request['phrase']) { case 'exact': $this->searchPhrase(); break; default: case 'all': case 'any': $this->searchWords($this->_request['phrase'] == 'all'); break; } $this->_results = array_unique($this->_results); } Sobi::Trigger('AfterBasic', 'Search', array(&$this->_results, &$this->_resultsByPriority)); /* ... now the extended search. Check which data we've received */ if (count($this->_fields)) { $results = null; foreach ($this->_fields as $field) { if (isset($this->_request[$field->get('nid')]) && $this->_request[$field->get('nid')] != null) { $this->_narrowing = true; $fr = $field->searchData($this->_request[$field->get('nid')], Sobi::Section()); $priority = $field->get('priority'); if (is_array($fr)) { $this->_resultsByPriority[$priority] = array_merge($this->_resultsByPriority[$priority], $fr); } /* if we didn't got any results before this array contains the results */ if (!is_array($results)) { $results = $fr; } else { if (is_array($fr)) { $results = array_intersect($results, $fr); } } } } /** Tue, Oct 21, 2014 10:18:37 * No result is also a result so no "count" * */ // if ( is_array( $results ) && count( $results ) ) { if (is_array($results)) { /* if we had also a string to search we have to get the intersection */ if ($searchForString) { $this->_results = array_intersect($this->_results, $results); } else { $this->_results = $results; } } } $this->verify(); /** @since 1.1 - a method to narrow the search results down */ if (count($this->_fields)) { // If we have any results already - the we are limiting results down // if we don't have results but we were already searching then skip - because there is nothing to narrow down // if we don't have results but we weren't searching for anything else - then we are narrowing down everything if (count($this->_results) || !$this->_narrowing) { foreach ($this->_fields as &$field) { $request = isset($this->_request[$field->get('nid')]) ? $this->_request[$field->get('nid')] : null; if ($request) { $field->searchNarrowResults($request, $this->_results, $this->_resultsByPriority); } } } } $this->_request['search_for'] = str_replace('%', '*', $this->_request['search_for']); if (count($this->_results) > $searchLimit) { SPFactory::message()->error(Sobi::Txt('SH.SEARCH_TOO_MANY_RESULTS', count($this->_results), $searchLimit), false); $this->_resultsByPriority = array(); $this->_results = array_slice($this->_results, 0, $searchLimit); } else { $this->sortPriority(); } Sobi::Trigger('AfterExtended', 'Search', array(&$this->_results, &$this->_resultsByPriority)); $req = is_array($this->_request) && count($this->_request) ? SPConfig::serialize($this->_request) : null; $res = is_array($this->_results) && count($this->_results) ? implode(', ', $this->_results) : null; $cre = is_array($this->_categoriesResults) && count($this->_categoriesResults) ? implode(', ', $this->_categoriesResults) : null; /* determine the search parameters */ $attr = array('entriesResults' => array('results' => $res, 'resultsByPriority' => $this->_resultsByPriority), 'catsResults' => $cre, 'uid' => Sobi::My('id'), 'browserData' => SPConfig::serialize(SPBrowser::getInstance())); if (strlen($req)) { $attr['requestData'] = $req; } /* finally save */ try { Sobi::Trigger('OnSave', 'Search', array(&$attr, &$ssid)); $this->_db->update('spdb_search', $attr, array('ssid' => $ssid)); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('CANNOT_CREATE_SESSION_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } $url = array('task' => 'search.results', 'sid' => Sobi::Section()); // For Peter's Components Anywhere extension and other $params = Sobi::Cfg('search.params_to_pass'); if (count($params)) { foreach ($params as $param) { $val = SPRequest::raw($param); if ($val) { $url[$param] = SPRequest::raw($param); } } } /* if we cannot transfer the search id in cookie */ if (!SPRequest::cmd('ssid', null, 'cookie')) { $url['ssid'] = $ssid; } if (Sobi::Cfg('cache.unique_search_url')) { $url['t'] = microtime(true); } Sobi::Redirect(Sobi::Url($url)); }
/** * @param array $cfg * @param string $template * @return $this */ public function &setConfig($cfg, $template) { $this->_config = $cfg; if (isset($cfg[$template]) && count($cfg[$template])) { foreach ($cfg[$template] as $k => $v) { $this->_config[$k] = $v; } } if (isset($this->_config['general']['css_files'])) { $this->_config['general']['css_files'] = explode(',', $this->_config['general']['css_files']); foreach ($this->_config['general']['css_files'] as $file) { $this->loadCSSFile(trim($file)); } } if (isset($this->_config['general']['js_files'])) { $this->_config['general']['js_files'] = explode(',', $this->_config['general']['js_files']); foreach ($this->_config['general']['js_files'] as $file) { if (trim($file)) { $this->loadJsFile(trim($file)); } } } if ($this->key('site_title')) { $this->setTitle($this->key('site_title')); } if (isset($this->_config['hidden'])) { foreach ($this->_config['hidden'] as $name => $defValue) { $this->addHidden(SPRequest::string($name, $defValue), $name); } } Sobi::Trigger('afterLoadConfig', $this->name(), array(&$this->_config)); return $this; }
private function install($file = null) { $arch = SPFactory::Instance('base.fs.archive'); $ajax = strlen(SPRequest::cmd('ident', null, 'post')); if (!$file && SPRequest::string('root')) { $file = str_replace('.xml', null, SPRequest::string('root')); $file = SPLoader::path('tmp.install.' . $file, 'front', true, 'xml'); } if (!$file) { $ident = SPRequest::cmd('ident', null, 'post'); $data = SPRequest::file($ident); $name = str_replace(array('.' . SPFs::getExt($data['name']), '.'), null, $data['name']); $path = SPLoader::dirPath('tmp.install.' . $name, 'front', false); $c = 0; while (SPFs::exists($path)) { $path = SPLoader::dirPath('tmp.install.' . $name . '_' . ++$c, 'front', false); } /* * temp directory - will be removed later but it needs to be writable for apache and Joomla! fs (FTP mode) */ try { if (Sobi::Cfg('ftp_mode')) { SPFs::mkdir($path, 0777); } else { SPFs::mkdir($path); } } catch (SPException $x) { return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG); } $file = $path . '/' . $data['name']; try { $arch->upload($data['tmp_name'], $file); } catch (SPException $x) { return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG); } } elseif (SPRequest::string('root') && $file) { $path = dirname($file); } else { $arch->setFile($file); $name = str_replace(array('.' . SPFs::getExt($file), '.'), null, basename($file)); $path = SPLoader::dirPath('tmp.install.' . $name, 'front', false); $c = 0; while (SPFs::exists($path)) { $path = SPLoader::dirPath('tmp.install.' . $name . '_' . ++$c, 'front', false); } /* * temp directory - will be removed later but it needs to writable for apache and Joomla! fs (FTP mode) */ try { if (Sobi::Cfg('ftp_mode')) { SPFs::mkdir($path, 0777); } else { SPFs::mkdir($path); } } catch (SPException $x) { return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG); } } if ($path) { if (!SPRequest::string('root')) { if (!$arch->extract($path)) { return $this->ajaxResponse($ajax, SPLang::e('CANNOT_EXTRACT_ARCHIVE', basename($file), $path), false, SPC::ERROR_MSG); } } $dir =& SPFactory::Instance('base.fs.directory', $path); $xml = array_keys($dir->searchFile('.xml', false, 2)); if (!count($xml)) { return $this->ajaxResponse($ajax, SPLang::e('NO_INSTALL_FILE_IN_PACKAGE'), false, SPC::ERROR_MSG); } $definition = $this->searchInstallFile($xml); if (!$definition) { if (SPFactory::CmsHelper()->installerFile($xml)) { try { $message = SPFactory::CmsHelper()->install($xml, $path); return $this->ajaxResponse($ajax, $message['msg'], $ajax, $message['msgtype']); } catch (SPException $x) { return $this->ajaxResponse($ajax, $x->getMessage(), $ajax, SPC::ERROR_MSG); } } else { return $this->ajaxResponse($ajax, SPLang::e('NO_INSTALL_FILE_IN_PACKAGE'), false, SPC::ERROR_MSG); } } /** @var $installer SPInstaller */ $installer =& SPFactory::Instance('services.installers.' . trim(strtolower($definition->documentElement->tagName)), $xml[0], trim($definition->documentElement->tagName)); try { $installer->validate(); $msg = $installer->install(); return $this->ajaxResponse($ajax, $msg, true, SPC::SUCCESS_MSG); } catch (SPException $x) { return $this->ajaxResponse($ajax, $x->getMessage(), false, SPC::ERROR_MSG); } } else { return $this->ajaxResponse($ajax, SPLang::e('NO_FILE_HAS_BEEN_UPLOADED'), false, SPC::ERROR_MSG); } }
/** * */ public function ProxyIcon() { $secret = md5(Sobi::Cfg('secret')); $file = SPRequest::string('file'); $file = explode('/', $file); $dirName = SPLoader::dirPath("tmp.files.{$secret}.{$file[0]}", 'front', true); $fileName = $dirName . $file[1]; header('Content-Type:' . image_type_to_mime_type(exif_imagetype($fileName))); header('Content-Length: ' . filesize($fileName)); readfile($fileName); exit; }
/** * Returns copy of stored registry value key * * @param string $key - stored key * @param mixed $def - default value * @return mixed */ public static function Request($key, $def = null) { return SPRequest::string($key, $def); }