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); } }
/** * Loads the first row of a query into an object * * @throws SPException * @return stdObject */ public function loadObject() { try { $r = $this->db->loadObject(); $this->count++; } catch (Exception $e) { } if ($this->db->getErrorNum()) { throw new SPException($this->db->stderr()); } else { if ($r && is_object($r)) { $attr = get_object_vars($r); foreach ($attr as $property => $value) { if (is_string($value) && strstr($value, '"')) { $r->{$property} = class_exists('SPLang') ? SPLang::clean($value) : $value; } } } return $r; } }
/** * Shows the field in the search form * @param bool $return return or display directly * @return string */ public function searchForm($return = false) { if ($this->searchMethod == 'general') { return false; } $hidden = null; $d = $this->getValues(false); $data = array('' => Sobi::Txt('FD.SEARCH_SELECT_LIST', array('name' => $this->name))); foreach ($d as $k => $v) { $data[$k] = $v; } $params = array('id' => $this->nid, 'size' => $this->ssize, 'class' => $this->cssClass . ' ' . Sobi::Cfg('search.form_list_def_css', 'SPSearchSelect')); //still there for compatibility reason if ($this->swidth) { $params['style'] = "width: {$this->swidth}px;"; } if ($this->dependency) { SPFactory::header()->addJsFile('opt.field_select'); $request = json_decode(SPLang::clean(SPRequest::raw($this->nid . '_path', null, 'requestcache')), true); $params['class'] .= ' ctrl-dependency-field'; $hidden = $this->travelDependencyPath($request, $params); $this->_selected = isset($request[1]) ? $request[1] : null; $hiddenValue = str_replace('"', "'", json_encode((object) $request)); $hidden .= SPHtml_Input::hidden($this->nid . '_path', $hiddenValue, null, array('data' => array('selected' => '', 'section' => Sobi::Section()))); $params['data'] = array('order' => '1'); } return SPHtml_Input::select($this->nid, $data, $this->_selected, $this->searchMethod == 'mselect', $params) . $hidden; }
protected function entryData($getFields = true) { /** @var SPEntry $entry */ $entry = $this->get('entry'); $visitor = $this->get('visitor'); $data = array(); $data['section'] = array('_complex' => 1, '_data' => Sobi::Section(true), '_attributes' => array('id' => Sobi::Section(), 'lang' => Sobi::Lang(false))); $en = array(); $en['name'] = array('_complex' => 1, '_data' => $entry->get('name'), '_attributes' => array('lang' => Sobi::Lang(false))); $en['created_time'] = $entry->get('createdTime'); $en['updated_time'] = $entry->get('updatedTime'); $en['valid_since'] = $entry->get('validSince'); $en['valid_until'] = $entry->get('validUntil'); $en['author'] = $entry->get('owner'); $en['counter'] = $entry->get('counter'); $en['approved'] = $entry->get('approved'); $this->fixTimes($en); // $mytime = date( 'Y-m-d H:i:s', time()); if ($entry->get('state') == 0) { $en['state'] = 'unpublished'; } else { if (strtotime($entry->get('validUntil')) != 0 && strtotime($entry->get('validUntil')) < time()) { $en['state'] = 'expired'; } elseif (strtotime($entry->get('validSince')) != 0 && strtotime($entry->get('validSince')) > time()) { $en['state'] = 'pending'; } else { $en['state'] = 'published'; } } $en['url'] = Sobi::Url(array('pid' => $entry->get('parent'), 'sid' => $entry->get('id'), 'title' => Sobi::Cfg('sef.alias', true) ? $entry->get('nid') : $entry->get('name')), true, true, true); if (Sobi::Can('entry', 'edit', '*') || Sobi::My('id') == $entry->get('owner') && Sobi::Can('entry', 'edit', 'own')) { $en['edit_url'] = Sobi::Url(array('task' => 'entry.edit', 'sid' => $entry->get('id'))); } if (Sobi::Can('entry', 'manage', '*')) { $en['approve_url'] = Sobi::Url(array('task' => $entry->get('approved') ? 'entry.unapprove' : 'entry.approve', 'sid' => $entry->get('id'))); } if ($entry->get('owner') == Sobi::My('id') && Sobi::Can('entry', 'delete', 'own') || Sobi::Can('entry', 'delete', '*')) { $en['delete_url'] = Sobi::Url(array('task' => 'entry.delete', 'sid' => $entry->get('id'))); } if (Sobi::Can('entry', 'publish', '*') || Sobi::My('id') == $entry->get('owner') && Sobi::Can('entry', 'publish', 'own')) { $en['publish_url'] = Sobi::Url(array('task' => $entry->get('state') ? 'entry.unpublish' : 'entry.publish', 'sid' => $entry->get('id'))); } $cats = $entry->get('categories'); $categories = array(); if (count($cats)) { $cn = SPLang::translateObject(array_keys($cats), array('name', 'alias'), 'category'); } $primaryCat = $entry->get('parent'); foreach ($cats as $cid => $cat) { $cAttr = array('lang' => Sobi::Lang(false), 'id' => $cat['pid'], 'alias' => $cat['alias'], 'position' => $cat['position'], 'url' => Sobi::Url(array('sid' => $cat['pid'], 'title' => Sobi::Cfg('sef.alias', true) ? $cat['alias'] : $cat['name']))); if ($cat['pid'] == $primaryCat) { $cAttr['primary'] = 'true'; } $categories[] = array('_complex' => 1, '_data' => SPLang::clean($cn[$cid]['value']), '_attributes' => $cAttr); } $en['categories'] = $categories; $en['meta'] = array('description' => $entry->get('metaDesc'), 'keys' => $this->metaKeys($entry), 'author' => $entry->get('metaAuthor'), 'robots' => $entry->get('metaRobots')); if ($getFields) { $fields = $entry->getFields(); if (count($fields)) { $en['fields'] = $this->fieldStruct($fields, 'details'); } } $this->menu($data); $this->alphaMenu($data); $data['entry'] = array('_complex' => 1, '_data' => $en, '_attributes' => array('id' => $entry->get('id'), 'nid' => $entry->get('nid'), 'version' => $entry->get('version'))); $data['visitor'] = $this->visitorArray($visitor); return $data; }
/** * Set Site title * @param string $title * @return SPHeader */ public function &setTitle($title) { if (defined('SOBIPRO_ADM')) { SPFactory::mainframe()->setTitle(SPLang::clean($title)); } if (is_array($title)) { $this->title = $title; } else { $this->title = array(SPLang::clean($title)); } return $this; }
/** * @param string $task * @return \SobiProCtrl */ function __construct($task) { $this->_mem = memory_get_usage(); $this->_time = microtime(true); SPLoader::loadClass('base.exception'); set_error_handler('SPExceptionHandler'); $this->_err = ini_set('display_errors', 'on'); $this->_task = $task; /* load all needed classes */ SPLoader::loadClass('base.const'); SPLoader::loadClass('base.factory'); SPLoader::loadClass('base.object'); SPLoader::loadClass('base.filter'); SPLoader::loadClass('base.request'); SPLoader::loadClass('sobi'); SPLoader::loadClass('base.config'); SPLoader::loadClass('cms.base.lang'); /* get sid if any */ $this->_sid = SPRequest::sid(); /* determine section */ $access = $this->getSection(); /* initialise mainframe interface to CMS */ $this->_mainframe = SPFactory::mainframe(); /* initialise config */ $this->createConfig(); ini_set('display_errors', Sobi::Cfg('debug.display_errors', false)); $this->_deb = error_reporting(Sobi::Cfg('debug.level', 0)); /* trigger plugin */ Sobi::Trigger('Start'); /* initialise translator and load language files */ SPLang::setLang(Sobi::Lang(false)); try { SPLang::registerDomain('site'); } catch (SPException $x) { Sobi::Error('CoreCtrl', SPLang::e('Cannot register language domain: %s.', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } if (!$access) { if (Sobi::Cfg('redirects.section_enabled', false)) { $redirect = Sobi::Cfg('redirects.section_url', null); $msg = Sobi::Cfg('redirects.section_msg', SPLang::e('UNAUTHORIZED_ACCESS', SPRequest::task())); $msgtype = Sobi::Cfg('redirects.section_msgtype', 'message'); Sobi::Redirect(Sobi::Url($redirect), Sobi::Txt($msg), $msgtype, true); } else { SPFactory::mainframe()->runAway('You have no permission to access this site', 403, null, true); } } /* load css and js files */ SPFactory::header()->initBase(); $sectionName = SPLang::translateObject($this->_section, 'name', 'section'); if ($this->_section) { SPFactory::registry()->set('current_section_name', SPLang::clean($sectionName[$this->_section]['value'])); } $start = array($this->_mem, $this->_time); SPFactory::registry()->set('start', $start); /* check if it wasn't plugin custom task */ if (!Sobi::Trigger('custom', 'task', array(&$this, SPRequest::task()))) { /* if not, start to route */ try { $this->route(); } catch (SPException $x) { if (defined('SOBI_TESTS')) { Sobi::Error('CoreCtrl', SPLang::e('Cannot route: %s.', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } else { SPFactory::mainframe()->setRedirect(Sobi::Reg('live_site'), SPLang::e('PAGE_NOT_FOUND'), SPC::ERROR_MSG, true); } } } return true; }
/** * @return array */ public function struct() { $data = SPConfig::unserialize($this->getRaw()); if (isset($data['url']) && strlen($data['url'])) { $show = true; if (!(isset($data['label']) && strlen($data['label']))) { $data['label'] = $data['url']; } /* @TODO: add second step */ if ($this->botProtection) { SPLoader::loadClass('env.browser'); $humanity = SPBrowser::getInstance()->get('humanity'); $display = Sobi::Cfg('mail_protection.show'); $show = $humanity >= $display ? true : false; } if ($show && strlen($data['url'])) { $this->cssClass = strlen($this->cssClass) ? $this->cssClass : 'spFieldsData'; $this->cssClass = $this->cssClass . ' ' . $this->nid; $this->cleanCss(); $attributes = array('href' => "mailto:{$data['url']}", 'class' => $this->cssClass); if ($this->newWindow) { $attributes['target'] = '_blank'; } $data = array('_complex' => 1, '_data' => SPLang::clean($data['label']), '_attributes' => $attributes); return array('_complex' => 1, '_validate' => array('class' => str_replace(str_replace('\\', '/', SOBI_PATH), null, str_replace('\\', '/', __FILE__)), 'method' => 'validateVisibility'), '_data' => array('a' => $data), '_attributes' => array('lang' => Sobi::Lang(false), 'class' => $this->cssClass)); } } }
/** * @param string $title * @param bool $forceAdd */ public function setTitle($title, $forceAdd = false) { $document = JFactory::getDocument(); if (!is_array($title) && (Sobi::Cfg('browser.add_title', true) || $forceAdd)) { $title = array($title); } if (is_array($title)) { //browser.add_title = true: adds the Joomla part (this is normally the menu item) in front of it (works only if full_title is also set to true) $jTitle = $document->getTitle(); //get the title Joomla has set if (Sobi::Cfg('browser.add_title', true) || $forceAdd) { if ($title[0] != $jTitle) { array_unshift($title, $jTitle); } } else { if ($title[0] == $jTitle) { array_shift($title); } } //if ( Sobi::Cfg( 'browser.full_title', true ) || true ) { //browser.full_title = true: if title is array, use only the last. That's e.g. the entry name without categories for SobiPro standard title if (count($title)) { if (is_array($title)) { if (Sobi::Cfg('browser.reverse_title', false)) { $title = array_reverse($title); } $title = implode(Sobi::Cfg('browser.title_separator', ' - '), $title); } else { $title = isset($title[count($title) - 1]) ? $title[count($title) - 1] : $title[0]; } } else { $title = null; } } if (strlen($title)) { if (!defined('SOBIPRO_ADM')) { if (JFactory::getApplication()->getCfg('sitename_pagetitles', 0) == 1) { $title = JText::sprintf('JPAGETITLE', JFactory::getApplication()->getCfg('sitename'), $title); } elseif (JFactory::getApplication()->getCfg('sitename_pagetitles', 0) == 2) { $title = JText::sprintf('JPAGETITLE', $title, JFactory::getApplication()->getCfg('sitename')); } } $document->setTitle(SPLang::clean(html_entity_decode($title))); } }
protected function entry($entry, $manager, $noId = false) { $en = array(); if (is_numeric($entry)) { $en = $this->cachedEntry($entry, $manager, $noId); } if (!is_array($en) || !count($en)) { if (is_numeric($entry)) { $entry = SPFactory::Entry($entry); } $en['id'] = $entry->get('id'); $en['nid'] = $entry->get('nid'); $en['name'] = array('_complex' => 1, '_data' => $entry->get('name'), '_attributes' => array('lang' => Sobi::Lang(false))); $en['url_array'] = array('title' => Sobi::Cfg('sef.alias', true) ? $entry->get('nid') : $entry->get('name'), 'pid' => $entry->get('primary'), 'sid' => $entry->get('id')); if (strstr(SPRequest::task(), 'search') || $noId || Sobi::Cfg('section.force_category_id', false) && SPRequest::sid() == Sobi::Section()) { $en['url'] = Sobi::Url(array('title' => Sobi::Cfg('sef.alias', true) ? $entry->get('nid') : $entry->get('name'), 'pid' => $entry->get('primary'), 'sid' => $entry->get('id'))); } else { $en['url'] = Sobi::Url(array('title' => Sobi::Cfg('sef.alias', true) ? $entry->get('nid') : $entry->get('name'), 'pid' => SPRequest::sid(), 'sid' => $entry->get('id'))); } if (Sobi::Cfg('list.entry_meta', true)) { $en['meta'] = array('description' => $entry->get('metaDesc'), 'keys' => $this->metaKeys($entry), 'author' => $entry->get('metaAuthor'), 'robots' => $entry->get('metaRobots')); } if ($manager || Sobi::My('id') && Sobi::My('id') == $entry->get('owner') && Sobi::Can('entry', 'edit', 'own', Sobi::Section())) { $en['edit_url'] = Sobi::Url(array('task' => 'entry.edit', 'pid' => SPRequest::sid(), 'sid' => $entry->get('id'))); } else { if (isset($en['edit_url'])) { unset($en['edit_url']); } } $en['edit_url_array'] = array('task' => 'entry.edit', 'pid' => SPRequest::sid(), 'sid' => $entry->get('id')); $en['created_time'] = $entry->get('createdTime'); $en['updated_time'] = $entry->get('updatedTime'); $en['valid_since'] = $entry->get('validSince'); $en['valid_until'] = $entry->get('validUntil'); $this->fixTimes($en); if ($entry->get('state') == 0) { $en['state'] = 'unpublished'; } else { if (strtotime($entry->get('validUntil')) != 0 && strtotime($entry->get('validUntil')) < time()) { $en['state'] = 'expired'; } elseif (strtotime($entry->get('validSince')) != 0 && strtotime($entry->get('validSince')) > time()) { $en['state'] = 'pending'; } else { $en['state'] = 'published'; } } $en['author'] = $entry->get('owner'); $en['counter'] = $entry->get('counter'); $en['approved'] = $entry->get('approved'); // $en[ 'confirmed' ] = $entry->get( 'confirmed' ); if (Sobi::Cfg('list.entry_cats', true)) { $cats = $entry->get('categories'); $categories = array(); if (count($cats)) { $cn = SPLang::translateObject(array_keys($cats), array('name', 'alias')); } foreach ($cats as $cid => $cat) { $categories[] = array('_complex' => 1, '_data' => SPLang::clean($cn[$cid]['value']), '_attributes' => array('lang' => Sobi::Lang(false), 'id' => $cat['pid'], 'position' => $cat['position'], 'url' => Sobi::Url(array('sid' => $cat['pid'], 'title' => Sobi::Cfg('sef.alias', true) ? $cat['alias'] : $cat['name'])))); } $en['categories'] = $categories; } $fields = $entry->getFields(); if (count($fields)) { // foreach ( $fields as $field ) { // if ( $field->enabled( 'vcard' ) && $field->get( 'id' ) != Sobi::Cfg( 'entry.name_field' ) ) { // $struct = $field->struct(); // $options = null; // if ( isset( $struct[ '_options' ] ) ) { // $options = $struct[ '_options' ]; // unset( $struct[ '_options' ] ); // } // $f[ $field->get( 'nid' ) ] = array( // '_complex' => 1, // '_data' => array( // 'label' => array( // '_complex' => 1, // '_data' => $field->get( 'name' ), // '_attributes' => array( 'lang' => Sobi::Lang( false ), 'show' => $field->get( 'withLabel' ) ) // ), // 'data' => $struct, // ), // '_attributes' => array( 'id' => $field->get( 'id' ), 'type' => $field->get( 'type' ), 'suffix' => $field->get( 'suffix' ), 'position' => $field->get( 'position' ), 'css_class' => ( strlen( $field->get( 'cssClass' ) ) ? $field->get( 'cssClass' ) : 'spField' ) ) // ); // if ( Sobi::Cfg( 'list.field_description', false ) ) { // $f[ $field->get( 'nid' ) ][ '_data' ][ 'description' ] = array( '_complex' => 1, '_xml' => 1, '_data' => $field->get( 'description' ) ); // } // if ( $options ) { // $f[ $field->get( 'nid' ) ][ '_data' ][ 'options' ] = $options; // } // if ( isset( $struct[ '_xml_out' ] ) && count( $struct[ '_xml_out' ] ) ) { // foreach ( $struct[ '_xml_out' ] as $k => $v ) // $f[ $field->get( 'nid' ) ][ '_data' ][ $k ] = $v; // } // } // } $en['fields'] = $this->fieldStruct($fields, 'vcard'); } SPFactory::cache()->addObj($entry, 'entry', $entry->get('id'))->addObj($en, 'entry_struct', $entry->get('id')); unset($en['url_array']); unset($en['edit_url_array']); unset($entry); } $en['counter'] = $this->getNonStaticData($en['id'], 'counter'); /* * this is te special case: * no matter what task we currently have - if someone called this we need the data for the V-Card * Soe we have to trigger all these plugins we need and therefore also fake the task */ $task = 'list.custom'; SPFactory::registry()->set('task', $task); Sobi::Trigger('List', ucfirst(__FUNCTION__), array(&$en)); return $en; }
/** * @return array */ public function struct() { $data = SPConfig::unserialize($this->getRaw()); if (isset($data['url']) && strlen($data['url'])) { $counter = -1; if ($data['protocol'] == 'relative') { $url = $data['url']; } else { $url = $data['protocol'] . '://' . $data['url']; } if (!(isset($data['label']) && strlen($data['label']))) { $data['label'] = $url; } $this->cssClass = strlen($this->cssClass) ? $this->cssClass : 'spFieldsData'; $this->cssClass = $this->cssClass . ' ' . $this->nid; $attributes = array('href' => $url, 'class' => $this->cssClass); if ($this->countClicks) { SPFactory::header()->addJsFile('opt.field_url'); $this->cssClass = $this->cssClass . ' ctrl-visit-countable'; $counter = $this->getCounter(); $attributes['data-sid'] = $this->sid; if (Sobi::Cfg('cache.xml_enabled')) { $attributes['data-counter'] = $counter; $attributes['data-refresh'] = 'true'; } $attributes['class'] = $this->cssClass; if ($this->counterToLabel) { $data['label'] = Sobi::Txt('FM.URL.COUNTER_WITH_LABEL', array('label' => $data['label'], 'counter' => $counter)); } } $this->cleanCss(); if (strlen($url)) { if ($this->newWindow) { $attributes['target'] = '_blank'; } if ($this->noFollow) { $attributes['rel'] = 'nofollow'; } $data = array('_complex' => 1, '_data' => SPLang::clean($data['label']), '_attributes' => $attributes); return array('_complex' => 1, '_data' => array('a' => $data), '_attributes' => array('lang' => Sobi::Lang(false), 'class' => $this->cssClass, 'counter' => $counter)); } } }
/** * @param int $id * @param bool $parents * @param bool $last * @param int $offset * @return array */ protected function parentPath($id, $parents = false, $last = false, $offset = 2) { static $pathArray = null; $path = null; if (!$pathArray) { $pathArray = SPFactory::config()->getParentPath($id, true, $parents); } if (!$last) { if (is_array($pathArray)) { // if ( strstr( $this->get( 'task' ), 'edit' ) ) { // unset( $path[ count( $path ) - 1 ] ); // } $path = implode(Sobi::Cfg('string.path_separator', ' > '), $pathArray); } } else { if (is_array($pathArray) && isset($pathArray[count($pathArray) - $offset])) { $path = $pathArray[count($pathArray) - $offset]; } } return SPLang::clean($path); }
/** * This function have to add own string into the given array * Basically: $methods[ $this->id ] = "Some String To Output"; * Optionally the value can be also SobiPro Arr2XML array. * Check the documentation for more information * @param array $methods * @param SPEntry $entry * @param array $payment * @return void */ public function PaymentMethodView(&$methods, $entry, &$payment) { $bankdata = SPLang::getValue('bankdata', 'plugin', Sobi::Section()); $bankdata = SPLang::replacePlaceHolders($bankdata, array('entry' => $entry)); $methods[$this->id] = array('content' => SPLang::clean($bankdata), 'title' => Sobi::Txt('APP.PBT.PAY_TITLE')); }
/** * @param string $data * @param int $section * @param bool $startWith * @param bool $ids * @return array */ public function searchSuggest($data, $section, $startWith = true, $ids = false) { $terms = array(); $data = $startWith ? "{$data}%" : "%{$data}%"; $request = array('baseData'); if ($ids) { $request[] = 'sid'; } try { if ($ids) { $conditions = array('fid' => $this->fid, 'baseData' => $data, 'section' => $section); if (!defined('SOBIPRO_ADM')) { $conditions['copy'] = 0; $conditions['enabled'] = 1; } $result = SPFactory::db()->dselect($request, 'spdb_field_data', $conditions)->loadAssocList(); $terms = array(); if (count($result)) { foreach ($result as $row) { $terms[] = array('id' => $row['sid'], 'name' => SPLang::clean($row['baseData'])); } } } else { $terms = SPFactory::db()->select($request, 'spdb_field_data', array('fid' => $this->fid, 'copy' => '0', 'enabled' => 1, 'baseData' => $data, 'section' => $section))->loadResultArray(); } } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('CANNOT_SEARCH_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } return $terms; }
/** * @param array $config * @param array $values * @return string */ private function content($config, $values) { $out = "\n"; $out .= $values['expl']; $out .= "\n"; $out .= '<form action="' . $values['ppurl'] . '" method="post">' . "\n"; foreach ($config['fields'] as $field => $value) { $out .= '<input name="' . $field . '" value="' . SPLang::replacePlaceHolders($value, $values) . '" type="hidden"/>' . "\n"; } $img = SPLang::replacePlaceHolders($config['general']['image']); $out .= '<input src="' . $img . '" name="submit" alt="" type="image"/>' . "\n"; $out .= '</form>' . "\n"; return SPLang::clean($out); }
/** * Std. getter. Returns a property of the object or the default value if the property is not set. * @param string $attr * @param mixed $default * @return mixed */ public function get($attr, $default = null) { if ($attr == 'value') { return $this->getRaw(); } if (isset($this->{$attr})) { return is_string($this->{$attr}) && class_exists('SPLang') ? SPLang::clean($this->{$attr}) : $this->{$attr}; } if (!$this->_type && !$this->_off) { $this->fullInit(); } if ($this->_type && $this->_type->has($attr) && $this->_type->get($attr)) { return $this->_type->get($attr); } else { return $default; } }
/** * @param int $id * @param bool $parents * @return array */ protected function parentPath($id, $parents = false) { $path = SPFactory::config()->getParentPath($id, true, $parents); if (is_array($path)) { $path = implode(Sobi::Cfg('string.path_separator', ' > '), $path); } else { $path = null; } return SPLang::clean($path); }
/** * @param string $task */ function __construct($task) { SPLoader::loadClass('base.exception'); set_error_handler('SPExceptionHandler'); $this->_err = ini_set('display_errors', 'on'); $this->_mem = memory_get_usage(); $this->_time = microtime(); $this->_task = $task; /* load all needed classes */ SPLoader::loadClass('base.factory'); SPLoader::loadClass('base.object'); SPLoader::loadClass('base.const'); SPLoader::loadClass('base.filter'); SPLoader::loadClass('base.request'); SPLoader::loadClass('sobi'); SPLoader::loadClass('base.config'); /* authorise access */ $this->checkAccess(); /* initialise mainframe interface to CMS */ $this->_mainframe =& SPFactory::mainframe(); /* get sid if any */ $this->_sid = SPRequest::sid(); /* determine section */ $this->getSection(); /* initialise config */ $this->createConfig(); ini_set('display_errors', Sobi::Cfg('debug.display_errors', false)); $this->_deb = error_reporting(Sobi::Cfg('debug.level', 0)); /* trigger plugin */ Sobi::Trigger('AdminStart'); /* initialise translator and load language files */ SPLoader::loadClass('cms.base.lang'); SPLang::setLang(Sobi::Lang()); try { SPLang::registerDomain('admin'); } catch (SPException $x) { Sobi::Error('CoreCtrl', SPLang::e('Cannot register language domain: %s.', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } /* load admin html files */ SPFactory::header()->initBase(true); /** @noinspection PhpParamsInspection */ if ($this->_section) { $sectionName = SPLang::translateObject($this->_section, 'name', 'section'); SPFactory::registry()->set('current_section_name', SPLang::clean($sectionName[$this->_section]['value'])); } if ($this->_section && !Sobi::Cfg('section.template')) { SPFactory::config()->set('template', SPC::DEFAULT_TEMPLATE, 'section'); } /* check if it wasn't plugin custom task */ if (!Sobi::Trigger('custom', 'task', array($this, SPRequest::task()))) { /* if not, start to route */ try { $this->route(); } catch (SPException $x) { Sobi::Error('CoreCtrl', SPLang::e('Cannot route: %s.', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } } return true; }
/** * Gets the data for a field and save it in the database * @param SPEntry $entry * @param string $request * @param bool $clone * @throws SPException * @return bool */ public function saveData(&$entry, $request = 'POST', $clone = false) { if (!$this->enabled) { return false; } $del = SPRequest::bool($this->nid . '_delete', false, $request); if ($clone) { $orgSid = SPRequest::sid(); $this->loadData($orgSid); $files = $this->getExistingFiles(); $cloneFiles = array(); if (isset($files['original']) && file_exists(SOBI_ROOT . '/' . $files['original'])) { return $this->cloneFiles($entry, $request, $files, $cloneFiles); } } $fileSize = SPRequest::file($this->nid, 'size'); $cropped = null; static $store = null; $cache = false; if ($store == null) { $store = SPFactory::registry()->get('requestcache_stored'); } if (is_array($store) && isset($store[$this->nid])) { if (!strstr($store[$this->nid], 'file://') && !strstr($store[$this->nid], 'directory://')) { $data = $store[$this->nid]; $cache = true; $orgName = SPRequest::file($this->nid, 'name', $request); } else { SPRequest::set($this->nid, $store[$this->nid]); $orgName = SPRequest::file($this->nid, 'name'); $data = SPRequest::file($this->nid, 'tmp_name'); } } else { $data = SPRequest::file($this->nid, 'tmp_name'); $orgName = SPRequest::file($this->nid, 'name'); } $sPath = $this->parseName($entry, $orgName, $this->savePath); $path = SPLoader::dirPath($sPath, 'root', false); /** Wed, Oct 15, 2014 13:51:03 * Implemented a cropper with Ajax checker. * This is the actual method to get those files * Other methods left for BC * */ if (!$data) { $directory = SPRequest::string($this->nid, $store[$this->nid], false, $request); if (strlen($directory)) { list($data, $dirName, $files, $coordinates) = $this->getAjaxFiles($directory); if (count($files)) { foreach ($files as $file) { if ($file == '.') { continue; } if ($file == '..') { continue; } if (strpos($file, 'icon_') !== false) { continue; } if (strpos($file, 'resized_') !== false) { continue; } if (strpos($file, 'cropped_') !== false) { $cropped = $dirName . $file; SPFs::upload($cropped, $path . basename($cropped)); continue; } if (strpos($file, '.var') !== false) { continue; } $fileSize = filesize($dirName . $file); $orgName = $file; } } if (strlen($coordinates)) { $coordinates = json_decode(SPLang::clean($coordinates), true); /** @var SPImage $croppedImage */ $croppedImage = SPFactory::Instance('base.fs.image', $dirName . $orgName); $croppedImage->crop($coordinates['width'], $coordinates['height'], $coordinates['x'], $coordinates['y']); $cropped = 'cropped_' . $orgName; $croppedImage->saveAs($path . $cropped); } $data = strlen($cropped) ? $cropped : $dirName . $file; } } $files = array(); /* if we have an image */ if ($data && $orgName) { if ($fileSize > $this->maxSize) { throw new SPException(SPLang::e('FIELD_IMG_TOO_LARGE', $this->name, $fileSize, $this->maxSize)); } if ($cropped) { SPFs::upload($dirName . $orgName, $path . $orgName); } /** * @var SPImage $orgImage */ if ($cache) { $orgImage = SPFactory::Instance('base.fs.image', $data); $orgImage->move($path . $orgName); } else { $orgImage = SPFactory::Instance('base.fs.image'); $nameArray = explode('.', $orgName); $ext = strtolower(array_pop($nameArray)); $nameArray[] = $ext; $orgName = implode('.', $nameArray); if ($cropped) { // Fri, Jul 3, 2015 17:15:05 // it has been actually uploaded at ~425 // not sure why we are trying to upload it again if (SPFs::exists($dirName . $data)) { $orgImage->upload($dirName . $data, $path . basename($data)); } else { $orgImage->setFile($path . basename($data)); } } else { $orgImage->upload($dirName . $orgName, $path . $orgName); } } $files['data']['exif'] = $orgImage->exif(); $this->cleanExif($files['data']['exif']); if (Sobi::Cfg('image_field.fix_rotation', true)) { if ($orgImage->fixRotation()) { $orgImage->save(); } } if ($this->resize) { $image = clone $orgImage; try { $image->resample($this->resizeWidth, $this->resizeHeight, false); $files['image'] = $this->parseName($entry, $orgName, $this->imageName, true); $image->saveAs($path . $files['image']); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); $image->delete(); throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage())); } } if ($this->generateThumb) { $thumb = clone $orgImage; try { $thumb->resample($this->thumbWidth, $this->thumbHeight, false); $files['thumb'] = $this->parseName($entry, $orgName, $this->thumbName, true); $thumb->saveAs($path . $files['thumb']); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); $thumb->delete(); throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage())); } } $ico = clone $orgImage; try { $icoSize = explode(':', Sobi::Cfg('image.ico_size', '80:80')); $ico->resample($icoSize[0], $icoSize[1], false); $files['ico'] = $this->parseName($entry, strtolower($orgName), 'ico_{orgname}_' . $this->nid, true); $ico->saveAs($path . $files['ico']); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); $ico->delete(); throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage())); } if (!$this->keepOrg) { $orgImage->delete(); } else { $files['original'] = $this->parseName($entry, $orgName, '{orgname}', true); } foreach ($files as $i => $file) { if ($i == 'data') { continue; } $files[$i] = $sPath . $file; } } elseif ($del) { $this->delImgs(); $files = array(); } else { return true; } $this->storeData($entry, $request, $files); }
/** */ public function loadTable() { parent::loadTable(); /* @var SPdb $db */ $db =& SPFactory::db(); $this->icon = SPLang::clean($this->icon); try { $db->select(array('position', 'pid'), 'spdb_relations', array('id' => $this->id)); $r = $db->loadObject(); Sobi::Trigger($this->name(), ucfirst(__FUNCTION__), array(&$r)); $this->position = $r->position; $this->parent = $r->pid; } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } if (SPRequest::task() != 'category.edit') { if ($this->parseDesc == SPC::GLOBAL_SETTING) { $this->parseDesc = Sobi::Cfg('category.parse_desc', true); } if ($this->parseDesc) { Sobi::Trigger('Parse', 'Content', array(&$this->description)); } } }
/** * @return array */ public function struct() { $baseData = $this->getRaw(); $list = array(); $struct = array(); $order = SPFactory::cache()->getVar('order_' . $this->nid); if (!$order) { $order = SPFactory::db()->select('optValue', 'spdb_field_option', array('fid' => $this->id), 'optPos')->loadResultArray(); SPFactory::cache()->addVar($order, 'order_' . $this->nid); } if (is_array($baseData) && count($baseData)) { $this->cssClass = strlen($this->cssClass) ? $this->cssClass : 'spFieldsData'; $this->cssClass = $this->cssClass . ' ' . $this->nid; $this->cleanCss(); foreach ($order as $opt) { if (isset($baseData[$opt])) { $list[] = array('_tag' => 'li', '_value' => SPLang::clean($baseData[$opt]), '_class' => $opt); } } foreach ($this->options as $opt) { $struct[] = array('_complex' => 1, '_data' => $opt['label'], '_attributes' => array('selected' => isset($baseData[$opt['id']]) ? 'true' : 'false', 'id' => $opt['id'], 'position' => $opt['position'])); } $data = array('ul' => array('_complex' => 1, '_data' => $list, '_attributes' => array('class' => $this->cssClass))); } if (count($list)) { return array('_complex' => 1, '_data' => $data, '_attributes' => array('lang' => $this->lang, 'class' => $this->cssClass), '_options' => $struct); } }
/** * Gets the data for a field and save it in the database * @param SPEntry $entry * @param string $request * @throws SPException * @return bool */ public function saveData(&$entry, $request = 'POST') { if (!$this->enabled) { return false; } $del = SPRequest::bool($this->nid . '_delete', false, $request); $fileSize = SPRequest::file($this->nid, 'size'); $cropped = null; static $store = null; $cache = false; if ($store == null) { $store = SPFactory::registry()->get('requestcache_stored'); } if (is_array($store) && isset($store[$this->nid])) { if (!strstr($store[$this->nid], 'file://') && !strstr($store[$this->nid], 'directory://')) { $data = $store[$this->nid]; $cache = true; $orgName = SPRequest::file($this->nid, 'name', $request); } else { SPRequest::set($this->nid, $store[$this->nid]); $orgName = SPRequest::file($this->nid, 'name'); $data = SPRequest::file($this->nid, 'tmp_name'); } } else { $data = SPRequest::file($this->nid, 'tmp_name'); $orgName = SPRequest::file($this->nid, 'name'); } $sPath = $this->parseName($entry, $orgName, $this->savePath); $path = SPLoader::dirPath($sPath, 'root', false); /** Wed, Oct 15, 2014 13:51:03 * Implemented a cropper with Ajax checker. * This is the actual method to get those files * Other methods left for BC * */ if (!$data) { $directory = SPRequest::string($this->nid, $store[$this->nid], false, $request); if (strlen($directory)) { list($data, $dirName, $files, $coordinates) = $this->getAjaxFiles($directory); if (count($files)) { foreach ($files as $file) { if ($file == '.') { continue; } if ($file == '..') { continue; } if (strpos($file, 'icon_') !== false) { continue; } if (strpos($file, 'resized_') !== false) { continue; } if (strpos($file, 'cropped_') !== false) { $cropped = $dirName . $file; SPFs::upload($cropped, $path . basename($cropped)); continue; } if (strpos($file, '.var') !== false) { continue; } $fileSize = filesize($dirName . $file); $orgName = $file; } } if (strlen($coordinates)) { $coordinates = json_decode(SPLang::clean($coordinates), true); /** @var SPImage $croppedImage */ $croppedImage = SPFactory::Instance('base.fs.image', $dirName . $orgName); $croppedImage->crop($coordinates['width'], $coordinates['height'], $coordinates['x'], $coordinates['y']); $cropped = 'cropped_' . $orgName; $croppedImage->saveAs($path . $cropped); } $data = strlen($cropped) ? $cropped : $dirName . $file; } } $files = array(); /* if we have an image */ if ($data && $orgName) { if ($fileSize > $this->maxSize) { throw new SPException(SPLang::e('FIELD_IMG_TOO_LARGE', $this->name, $fileSize, $this->maxSize)); } if ($cropped) { SPFs::upload($dirName . $orgName, $path . $orgName); } /** * @var SPImage $orgImage */ if ($cache) { $orgImage = SPFactory::Instance('base.fs.image', $data); $orgImage->move($path . $orgName); } else { $orgImage = SPFactory::Instance('base.fs.image'); $nameArray = explode('.', $orgName); $ext = strtolower(array_pop($nameArray)); $nameArray[] = $ext; $orgName = implode('.', $nameArray); if ($cropped) { $orgImage->upload($dirName . $data, $path . basename($data)); } else { $orgImage->upload($dirName . $orgName, $path . $orgName); } } $files['data']['exif'] = $orgImage->exif(); $this->cleanExif($files['data']['exif']); if (Sobi::Cfg('image_field.fix_rotation', true)) { if ($orgImage->fixRotation()) { $orgImage->save(); } } if ($this->resize) { $image = clone $orgImage; try { $image->resample($this->resizeWidth, $this->resizeHeight, false); $files['image'] = $this->parseName($entry, $orgName, $this->imageName, true); $image->saveAs($path . $files['image']); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); $image->delete(); throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage())); } } if ($this->generateThumb) { $thumb = clone $orgImage; try { $thumb->resample($this->thumbWidth, $this->thumbHeight, false); $files['thumb'] = $this->parseName($entry, $orgName, $this->thumbName, true); $thumb->saveAs($path . $files['thumb']); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); $thumb->delete(); throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage())); } } $ico = clone $orgImage; try { $icoSize = explode(':', Sobi::Cfg('image.ico_size', '80:80')); $ico->resample($icoSize[0], $icoSize[1], false); $files['ico'] = $this->parseName($entry, strtolower($orgName), 'ico_{orgname}', true); $ico->saveAs($path . $files['ico']); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); $ico->delete(); throw new SPException(SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage())); } if (!$this->keepOrg) { $orgImage->delete(); } else { $files['original'] = $this->parseName($entry, $orgName, '{orgname}', true); } foreach ($files as $i => $file) { if ($i == 'data') { continue; } $files[$i] = $sPath . $file; } } elseif ($del) { $this->delImgs(); $files = array(); } else { return true; } /* @var SPdb $db */ $db =& SPFactory::db(); $this->verify($entry, $request); $time = SPRequest::now(); $IP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER'); $uid = Sobi::My('id'); /* if we are here, we can save these data */ /* collect the needed params */ $save = count($files) ? SPConfig::serialize($files) : null; $params = array(); $params['publishUp'] = $entry->get('publishUp'); $params['publishDown'] = $entry->get('publishDown'); $params['fid'] = $this->fid; $params['sid'] = $entry->get('id'); $params['section'] = Sobi::Reg('current_section'); $params['lang'] = Sobi::Lang(); $params['enabled'] = $entry->get('state'); $params['baseData'] = $db->escape($save); $params['approved'] = $entry->get('approved'); $params['confirmed'] = $entry->get('confirmed'); /* if it is the first version, it is new entry */ if ($entry->get('version') == 1) { $params['createdTime'] = $time; $params['createdBy'] = $uid; $params['createdIP'] = $IP; } $params['updatedTime'] = $time; $params['updatedBy'] = $uid; $params['updatedIP'] = $IP; $params['copy'] = !$entry->get('approved'); if (Sobi::My('id') == $entry->get('owner')) { --$this->editLimit; } $params['editLimit'] = $this->editLimit; /* save it */ try { $db->insertUpdate('spdb_field_data', $params); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_FIELDS_DATA_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } }