public static function __callStatic($name, $args) { if (defined('SOBIPRO_ADM')) { return call_user_func_array(array('self', '_' . $name), $args); } else { static $className = false; if (!$className) { $package = Sobi::Reg('current_template'); if (SPFs::exists(Sobi::FixPath($package . '/input.php'))) { $path = Sobi::FixPath($package . '/input.php'); ob_start(); $content = file_get_contents($path); $class = array(); preg_match('/\\s*(class)\\s+(\\w+)/', $content, $class); if (isset($class[2])) { $className = $class[2]; } else { Sobi::Error('Custom Input Class', SPLang::e('Cannot determine class name in file %s.', str_replace(SOBI_ROOT, null, $path)), SPC::WARNING, 0); return false; } require_once $path; } else { $className = true; } } if (is_string($className) && method_exists($className, $name)) { return call_user_func_array(array($className, $name), $args); } else { return call_user_func_array(array('self', '_' . $name), $args); } } }
public function execute() { SPLang::load('com_sobipro.check'); $task = $this->_task = strlen($this->_task) ? $this->_task : $this->_defTask; // this is need to delete all old cache after installation if (SPRequest::int('init')) { SPFactory::cache()->cleanAll(); } switch ($this->_task) { case 'view': $this->view(); break; case 'download': $this->download(); break; default: if (method_exists($this, $this->_task)) { SPFactory::mainframe()->cleanBuffer()->customHeader(); $this->{$task}(); exit; } else { Sobi::Error('requirements', 'Task not found', SPC::WARNING, 404, __LINE__, __FILE__); exit; } break; } }
public function execute() { $this->_task = strlen($this->_task) ? $this->_task : $this->_defTask; switch ($this->_task) { case 'list': $this->screen(); Sobi::ReturnPoint(); break; case 'purge': $this->purge(); break; case 'download': $this->download(); break; case 'details': $this->details(); break; default: /* case plugin didn't registered this task, it was an error */ if (!parent::execute()) { Sobi::Error('error_ctrl', 'Task not found', SPC::WARNING, 404, __LINE__, __FILE__); } break; } }
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); } }
/** * */ public function __construct() { if (self::$cs) { Sobi::Error('mainframe', SPLang::e('CRITICAL_SECTION'), SPC::ERROR, 500, __LINE__, __CLASS__); } else { self::$cs = true; self::$cs = false; } }
public function __call($method, $params) { if (function_exists($method)) { $this->string = $method($this->string); } else { Sobi::Error('String', "Function {$method} does not exist!", SPC::WARNING); } return $this; }
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'); }
protected function iconChooser() { if (!Sobi::Can('category.edit')) { Sobi::Error('category', 'You have no permission to access this site', SPC::ERROR, 403, __LINE__, __FILE__); } if (strlen(SPRequest::cmd('font'))) { return $this->iconFont(); } $folder = SPRequest::cmd('iconFolder', null); $callback = SPRequest::cmd('callback', 'SPSelectIcon'); $dir = $folder ? Sobi::Cfg('images.category_icons') . str_replace('.', '/', $folder) . '/' : Sobi::Cfg('images.category_icons'); $files = array(); $dirs = array(); if ($folder) { $up = explode('.', $folder); unset($up[count($up) - 1]); $dirs[] = array('name' => Sobi::Txt('FOLEDR_UP'), 'count' => count(scandir($dir . '..')) - 2, 'url' => Sobi::Url(array('task' => 'category.icon', 'out' => 'html', 'iconFolder' => count($up) ? implode('.', $up) : null))); } $ext = array('png', 'jpg', 'jpeg', 'gif'); if (is_dir($dir) && ($dh = opendir($dir))) { while (($file = readdir($dh)) !== false) { if (filetype($dir . $file) == 'file' && in_array(strtolower(SPFs::getExt($file)), $ext)) { $files[] = array('name' => $folder ? str_replace('.', '/', $folder) . '/' . $file : $file, 'path' => str_replace('\\', '/', str_replace(SOBI_ROOT, Sobi::Cfg('live_site'), str_replace('//', '/', $dir . $file)))); } elseif (filetype($dir . $file) == 'dir' && !($file == '.' || $file == '..')) { $dirs[] = array('name' => $file, 'count' => count(scandir($dir . $file)) - 2, 'path' => str_replace('\\', '/', str_replace(SOBI_ROOT, Sobi::Cfg('live_site'), str_replace('//', '/', $dir . $file))), 'url' => Sobi::Url(array('task' => 'category.icon', 'out' => 'html', 'iconFolder' => $folder ? $folder . '.' . $file : $file))); } } closedir($dh); } sort($files); sort($dirs); $view = SPFactory::View('category'); $view->setTemplate('category.icon'); $view->assign($this->_task, 'task'); $view->assign($callback, 'callback'); $view->assign($files, 'files'); $view->assign(Sobi::Cfg('images.folder_ico'), 'folder'); $view->assign($dirs, 'directories'); $view->icon(); }
/** */ public function execute() { /* parent class executes the plugins */ SPRequest::set('task', $this->_type . '.' . $this->_task); switch ($this->_task) { case 'front': $this->getSections(); /** @var $view SPAdmPanelView */ $view = SPFactory::View('front'); /* load template config */ // $this->tplCfg( 'front' ); // $view->setConfig( $this->_tCfg, 'general' ); $view->determineTemplate('front', SPC::DEFAULT_TEMPLATE); $view->assign($this->_sections, 'sections'); $view->display(); break; default: /* case parents or plugin didn't registered this task, it was an error */ if (!parent::execute()) { Sobi::Error($this->name(), SPLang::e('SUCH_TASK_NOT_FOUND', SPRequest::task()), SPC::NOTICE, 404, __LINE__, __FILE__); } break; } }
public function execute() { SPRequest::set('task', $this->_type . '.' . $this->_task); if (strstr($this->_task, '.')) { $task = explode('.', $this->_task); $class = SPLoader::loadClass('opt.listing.' . $task[0], false, null, true); } else { $class = SPLoader::loadClass('opt.listing.' . $this->_task, false, null, true); } if ($class) { $imp = class_implements($class); if (is_array($imp) && in_array('SPListing', $imp)) { /** @noinspection PhpIncludeInspection $compatibility */ $listing = new $class(); if (!isset($class::$compatibility)) { define('SOBI_LEGACY_LISTING', true); if (strstr($this->_task, '.')) { $t = explode('.', $this->_task); $listing->setTask($t[0]); } else { $listing->setTask($this->_task); } } else { $listing->setTask($this->_task); } return $listing->execute(); } else { Sobi::Error($this->name(), SPLang::e('SUCH_TASK_NOT_FOUND Wrong class definition', SPRequest::task()), SPC::NOTICE, 404, __LINE__, __FILE__); } } else { /* case parent didn't registered this task, it was an error */ if (!parent::execute() && $this->name() == __CLASS__) { Sobi::Error($this->name(), SPLang::e('SUCH_TASK_NOT_FOUND', SPRequest::task()), SPC::NOTICE, 404, __LINE__, __FILE__); } } }
/** * */ public function displayForm() { Sobi::Trigger('Display', $this->name(), array(&$this)); $action = $this->key('action'); echo '<div class="SobiPro" id="SobiPro">' . "\n"; if ($this->get('_compatibility')) { echo SPFactory::AdmToolbar()->render(); echo $this->legacyMessages(); } echo $action ? "\n<form action=\"{$action}\" method=\"post\" name=\"adminForm\" id=\"SPAdminForm\" enctype=\"multipart/form-data\" accept-charset=\"utf-8\" >\n" : null; foreach ($this->_templates as $tpl) { $template = SPLoader::path($tpl, 'adm.template'); if (!$template) { $tpl = SPLoader::translatePath($tpl, 'adm.template', false); Sobi::Error($this->name(), SPLang::e('CANNOT_LOAD_TEMPLATE_AT', $tpl), SPC::ERROR, 500, __LINE__, __FILE__); } else { include $template; } } if (count($this->_hidden)) { $this->_hidden[SPFactory::mainframe()->token()] = 1; $prefix = null; if (!$this->get('_compatibility')) { $prefix = 'SP_'; } foreach ($this->_hidden as $name => $value) { echo "\n<input type=\"hidden\" name=\"{$name}\" id=\"{$prefix}{$name}\" value=\"{$value}\"/>"; } } echo $action ? "\n</form>\n" : null; echo '</div>'; Sobi::Trigger('AfterDisplay', $this->name()); }
/** * @deprecated since 1.1 replaced by {@link #Initialise()} * @param int $sid - section id * @param null $root - root of Joomla! * @param null $lang - language * @return null */ public static function Init($root = null, $lang = null, $sid = 0) { static $loaded = false; if (!$loaded) { if (!defined('SOBI_CMS')) { define('SOBI_CMS', version_compare(JVERSION, '3.0.0', 'ge') ? 'joomla3' : (version_compare(JVERSION, '1.6.0', 'ge') ? 'joomla16' : 'joomla15')); } defined('SOBIPRO') || define('SOBIPRO', true); defined('SOBI_TASK') || define('SOBI_TASK', 'task'); defined('SOBI_DEFLANG') || define('SOBI_DEFLANG', $lang); defined('SOBI_ACL') || define('SOBI_ACL', 'front'); defined('SOBI_ROOT') || define('SOBI_ROOT', $root); defined('SOBI_MEDIA') || define('SOBI_MEDIA', implode('/', array($root, 'media', 'sobipro'))); defined('SOBI_PATH') || define('SOBI_PATH', SOBI_ROOT . '/components/com_sobipro'); defined('SOBI_LIVE_PATH') || define('SOBI_LIVE_PATH', 'components/com_sobipro'); require_once SOBI_PATH . '/lib/base/fs/loader.php'; SPLoader::loadController('sobipro'); SPLoader::loadController('interface'); SPLoader::loadClass('base.exception'); SPLoader::loadClass('base.const'); SPLoader::loadClass('base.object'); SPLoader::loadClass('base.filter'); SPLoader::loadClass('base.request'); SPLoader::loadClass('cms.base.lang'); SPLoader::loadClass('models.dbobject'); SPLoader::loadClass('base.factory'); SPLoader::loadClass('base.config'); SPLoader::loadClass('cms.base.fs'); // in case it is a CLI call if (isset($_SERVER['REQUEST_URI'])) { SPFactory::config()->set('live_site', JURI::root()); } $loaded = true; } if ($sid) { $section = null; if ($sid) { $path = array(); $id = $sid; $path[] = (int) $id; while ($id > 0) { try { $id = SPFactory::db()->select('pid', 'spdb_relations', array('id' => $id))->loadResult(); if ($id) { $path[] = (int) $id; } } catch (SPException $x) { Sobi::Error('ExtCoreCtrl', SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } } $path = array_reverse($path); $section = SPFactory::object($path[0]); } /* set current section in the registry */ SPFactory::registry()->set('current_section', $section->id); $_config =& SPFactory::config(); /* load basic configuration settings */ $_config->addIniFile('etc.config', true); $_config->addTable('spdb_config', $sid); /* initialise interface config setting */ SPFactory::mainframe()->getBasicCfg(); /* initialise config */ $_config->init(); } }
/** * 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__); } } }
/** * */ private function mimeFromExt() { $ext = SPFs::getExt($this->_path); if (!count(self::$_exts)) { self::$_exts = SPLoader::loadIniFile('etc.mime', false); } if (!isset(self::$_exts[$ext])) { Sobi::Error('FileInfo', SPLang::e('Cannot determine the right file type from extension'), SPC::WARNING, 0); } else { $this->_mime = self::$_exts[$ext]; } }
/** * @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; }
private function getNews() { $out = array(); $path = SPLoader::path('etc.news', 'front', false, 'xml'); if (SPFs::exists($path) && time() - filemtime($path) < 60 * 60 * 12) { $content = SPFs::read(SPLoader::path('etc.news', 'front', false, 'xml')); } else { try { $connection = SPFactory::Instance('services.remote'); $news = 'http://rss.sigsiu.net'; $connection->setOptions(array('url' => $news, 'connecttimeout' => 10, 'header' => false, 'returntransfer' => true)); $file = SPFactory::Instance('base.fs.file', $path); $content = $connection->exec(); $cinf = $connection->info(); if (isset($cinf['http_code']) && $cinf['http_code'] != 200) { return Sobi::Error('about', sprintf('CANNOT_GET_NEWS', $news, $cinf['http_code']), SPC::WARNING, 0, __LINE__, __FILE__); } $file->content($content); $file->save(); } catch (SPException $x) { return Sobi::Error('about', SPLang::e('CANNOT_LOAD_NEWS', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } try { if (strlen($content)) { $news = new DOMXPath(DOMDocument::loadXML($content)); $atom = false; if ($atom) { //Atom $news->registerNamespace('atom', 'http://www.w3.org/2005/Atom'); $out['title'] = $news->query('/atom:feed/atom:title')->item(0)->nodeValue; $items = $news->query('/atom:feed/atom:entry[*]'); $c = 5; $open = false; foreach ($items as $item) { $date = $item->getElementsByTagName('updated')->item(0)->nodeValue; if (!$open && time() - strtotime($date) < 60 * 60 * 24) { $open = true; } $feed = array('url' => $item->getElementsByTagName('link')->item(0)->nodeValue, 'title' => $item->getElementsByTagName('title')->item(0)->nodeValue, 'content' => $item->getElementsByTagName('content')->item(0)->nodeValue); if (!$c--) { break; } $out['feeds'][] = $feed; } } else { //RSS $out['title'] = $news->query('/rss/channel/title')->item(0)->nodeValue; $items = $news->query('/rss/channel/item[*]'); $c = 5; $open = false; foreach ($items as $item) { $date = $item->getElementsByTagName('pubDate')->item(0)->nodeValue; if (!$open && time() - strtotime($date) < 60 * 60 * 24) { $open = true; } $feed = array('url' => $item->getElementsByTagName('link')->item(0)->nodeValue, 'title' => $item->getElementsByTagName('title')->item(0)->nodeValue, 'content' => $item->getElementsByTagName('description')->item(0)->nodeValue, 'image' => $item->getElementsByTagName('enclosure')->item(0)->attributes->getNamedItem('url')->nodeValue); if (!$c--) { break; } $out['feeds'][] = $feed; } } } if ($open) { SPFactory::header()->addJsCode('SobiPro.jQuery( document ).ready( function () { SobiPro.jQuery( \'#SobiProNews\' ).trigger(\'click\'); } );'); } } catch (DOMException $x) { return Sobi::Error('about', SPLang::e('CANNOT_LOAD_NEWS', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } return $out; }
/** * * @param mixed $attr * @param int $index * @return mixed */ public function &get($attr, $index = -1) { $r = null; if (strstr($attr, '.')) { $properties = explode('.', $attr); } else { $properties[0] = $attr; } if (isset($this->_attr[$properties[0]])) { $var = null; /* if array field */ if ($index > -1) { if (is_array($this->_attr[$properties[0]]) && isset($this->_attr[$properties[0]][trim($index)])) { $var = $this->_attr[$properties[0]][trim($index)]; } else { Sobi::Error($this->name(), SPLang::e('ATTR_DOES_NOT_EXISTS', $attr), SPC::NOTICE, 0, __LINE__, __FILE__); } } else { $var = $this->_attr[$properties[0]]; } /* remove first field of properties */ array_shift($properties); /* if there are still fields in array, accessing object attribute or array field */ if (is_array($properties) && count($properties)) { foreach ($properties as $property) { $property = trim($property); /* it has to be SPObject subclass to access the attribute */ if (method_exists($var, 'has') && $var->has($property)) { if (method_exists($var, 'get')) { $var = $var->get($property); } else { /*@TODO need to create error object */ $r = ''; return $r; } } elseif (is_array($var)) { $var = $var[$property]; } else { /* nothing to show */ Sobi::Error($this->name(), SPLang::e('NO_PROPERTY_TO_SHOW', $attr), SPC::NOTICE, 0, __LINE__, __FILE__); /*@TODO need to create error object */ $r = ''; return $r; } } } $r = $var; } else { $r = null; } $r = is_string($r) ? Sobi::Clean($r) : $r; return $r; }
public function delete() { /* @var SPdb $db */ $db = SPFactory::db(); try { $db->delete('spdb_field_option', array('fid' => $this->id)); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } }
private function dir($file) { $file = explode('.', $file); if (strstr($file[0], 'cms:')) { $file[0] = str_replace('cms:', null, $file[0]); $file = SPFactory::mainframe()->path(implode('.', $file)); $file = SPLoader::dirPath($file, 'root', true); } else { $file = SPLoader::dirPath('usr.templates.' . implode('.', $file), 'front', true); } if (!$file) { $file = SPLoader::path('usr.templates.' . implode('.', $file), 'front', false); Sobi::Error($this->name(), SPLang::e('FILE_NOT_FOUND', $file), SPC::WARNING, 404, __LINE__, __FILE__); } return $file; }
/** * saving copy of current registry state * */ public function save() { array_unshift($this->store, array()); if (!count($this->store)) { Sobi::Error('registry', SPLang::e('Registry lost'), SPC::NOTICE, 0, __LINE__, __CLASS__); } }
public function getEntries($eLimit, $site, $ids = false) { $conditions = array(); $entries = array(); /* get the site to display */ $eLimStart = ($site - 1) * $eLimit; if (isset($this->_letter[1]) && $this->_letter[1] == '-') { $this->_letter = "[{$this->_letter[0]}-{$this->_letter[2]}]"; } $db = SPFactory::db(); /* * Don't know exactly why but on Windows servers there seems to be some problem with unicode chars * - strtolower/strtoupper is destroying these chars completely * - MySQL seems to be suddenly case sensitive with non-latin chars so we need to ask both * * Wed, Apr 4, 2012: Apparently it's not only Windows related */ if (!preg_match('/^[\\x20-\\x7f]*$/D', $this->_letter) && function_exists('mb_strtolower')) { // if we have multibyte string support - ask both cases ... $baseCondition = "REGEXP:^{$this->_letter}|^" . mb_strtoupper($this->_letter); } else { // if no unicode - great, it'll work. // if we don't have MB - shit happens $baseCondition = "REGEXP:^{$this->_letter}"; } switch ($this->_fieldType) { case 'chbxgroup': case 'select': case 'multiselect': $eOrder = 'sValue'; $table = $db->join(array(array('table' => 'spdb_field_option_selected', 'as' => 'opts'), array('table' => 'spdb_language', 'as' => 'lang', 'key' => array('opts.optValue', 'lang.sKey')), array('table' => 'spdb_object', 'as' => 'spo', 'key' => array('opts.sid', 'spo.id')), array('table' => 'spdb_relations', 'as' => 'sprl', 'key' => array('opts.sid', 'sprl.id')))); $oPrefix = 'spo.'; $conditions['spo.oType'] = 'entry'; $conditions['opts.fid'] = $this->_field; $conditions['lang.sValue'] = $baseCondition; break; default: $eOrder = 'baseData'; $table = $db->join(array(array('table' => 'spdb_field', 'as' => 'fdef', 'key' => 'fid'), array('table' => 'spdb_field_data', 'as' => 'fdata', 'key' => 'fid'), array('table' => 'spdb_object', 'as' => 'spo', 'key' => array('fdata.sid', 'spo.id')), array('table' => 'spdb_relations', 'as' => 'sprl', 'key' => array('fdata.sid', 'sprl.id')))); $oPrefix = 'spo.'; $conditions['spo.oType'] = 'entry'; $conditions['fdef.fid'] = $this->_field; $conditions['fdata.baseData'] = $baseCondition; break; } $this->_field = $this->_field ? $this->_field : Sobi::Cfg('alphamenu.primary_field', SPFactory::config()->nameField()->get('id')); /* check user permissions for the visibility */ if (Sobi::My('id')) { $this->userPermissionsQuery($conditions, $oPrefix); } else { $conditions = array_merge($conditions, array($oPrefix . 'state' => '1', '@VALID' => $db->valid($oPrefix . 'validUntil', $oPrefix . 'validSince'))); } $conditions['sprl.copy'] = '0'; try { $db->select($oPrefix . 'id', $table, $conditions, $eOrder, $eLimit, $eLimStart, true); $results = $db->loadResultArray(); } catch (SPException $x) { Sobi::Error('AlphaListing', SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } if ($ids) { Sobi::SetUserData('currently-displayed-entries', $results); return $results; } if (count($results)) { foreach ($results as $i => $sid) { // it needs too much memory moving the object creation to the view //$entries[ $i ] = SPFactory::Entry( $sid ); $entries[$i] = $sid; } } Sobi::Trigger($this->name(), 'AfterGetEntries', array(&$entries, false)); return $entries; }
public function searchData($request, $section) { if ($this->dependency) { $path = json_decode(Sobi::Clean(SPRequest::string($this->nid . '_path')), true); if (count($path)) { $request = array_pop($path); } } $sids = array(); /* check if there was something to search for */ if (is_array($request) && count($request) || is_string($request) && strlen($request)) { /** @var SPDb $db */ $db = SPFactory::db(); try { /* if we are searching for multiple options * and the field contains 'predefined_multi_data_multi_choice' * - we have to find entries matches all these options */ if (is_array($request) && $this->multi) { foreach ($request as $opt) { $db->select('sid', 'spdb_field_option_selected', array('copy' => '0', 'fid' => $this->fid, 'optValue' => $opt)); if (!isset($results)) { $results = $db->loadResultArray(); } else { $cids = $db->loadResultArray(); $results = array_intersect($results, $cids); } } $sids = $results; } else { $db->select('sid', 'spdb_field_option_selected', array('copy' => '0', 'fid' => $this->fid, 'optValue' => $request)); $sids = $db->loadResultArray(); } } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('CANNOT_SEARCH_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } return $sids; }
/** * @author Radek Suski * @version 1.0 * @param string $name * @param bool $sections * @param bool $adm * @param bool $try * @param bool $absolute * @param bool $fixedPath * @param bool $custom * @return array */ public static function loadIniFile($name, $sections = true, $adm = false, $try = false, $absolute = false, $fixedPath = false, $custom = false) { $path = $absolute ? null : ($adm ? SOBI_ADM_PATH . '/' : SOBI_PATH . '/'); /* if there is a customized ini file * it should be named like filename_override.ini * i.e config_my.ini will be loaded instead fo config.ini */ if (!$custom) { $customIni = self::loadIniFile($name . '_override', $sections, $adm, true, $absolute, $fixedPath, true); if ($customIni && is_array($customIni)) { return $customIni; } } if (!$fixedPath) { $path = self::fixPath($path . $name, !false); $path .= '.ini'; } else { $path .= $name . '.ini'; } if (!file_exists($path) || !is_readable($path)) { if (!$try) { /* We had to change it to notice because all these script kiddies are trying to call some not existent file which causes this error here * As a result we have the error log file full of USER_ERRORs and it looks badly but it's not really an error. * So we result wit the 500 response code but we log a notice for the logfile * */ Sobi::Error('ini_load', sprintf('Cannot load file at %s', str_replace(SOBI_ROOT . '/', null, $path)), SPC::NOTICE, 500, __LINE__, __FILE__); } return false; } else { ob_start(); self::$count++; $ini = parse_ini_file($path, $sections); ob_end_clean(); self::iniStorage($path); return $ini; } }
/** * Translating language depend attributes of objects * * @param array $sids - array with ids of objects to translate * @param array $fields - (optional) array (or string) with properties names to translate. If not given, translates all * @param string $type - (optional) type of object (section, category, entry). If not given, translates all * @param string $lang - (optional) specific language. If not given, use currently set language * @param string $ident * @return array */ public static function translateObject($sids, $fields = array(), $type = null, $lang = null, $ident = 'id') { /** @todo multiple attr does not work because the id is the object id */ $fields = is_array($fields) ? $fields : (strlen($fields) ? array($fields) : null); $lang = $lang ? $lang : Sobi::Lang(false); // we don't need to specify the language as we want to have all of them and then order it right // when an object name has been entered in a particular language but this language isn't used later // we won't have any label for this certain object // Wed, Dec 18, 2013 09:57:04 //$params = array( 'id' => $sids, 'language' => array( $lang, Sobi::DefLang(), 'en-GB' ) ); $params = array($ident => $sids); $result = array(); if ($type) { $params['oType'] = $type; } if (in_array('alias', $fields)) { $fields[] = 'nid'; } if ($fields && count($fields)) { $params['sKey'] = $fields; } try { $labels = SPFactory::db()->select($ident . ' AS id, sKey AS label, sValue AS value, language', 'spdb_language', $params, "FIELD( language, '{$lang}', '" . Sobi::DefLang() . "' )")->loadAssocList(); if (count($labels)) { $aliases = array(); if (in_array('alias', $fields)) { $aliases = SPFactory::db()->select(array('nid', 'id'), 'spdb_object', array('id' => $sids))->loadAssocList('id'); } foreach ($labels as $label) { if ($label['label'] == 'nid') { $result[$label['id']]['alias'] = $label['value']; } else { if (!isset($result[$label['id']]) || $label['language'] == Sobi::Lang()) { $result[$label['id']] = $label; } } if (in_array('nid', $fields)) { if (!isset($result[$label['id']]['alias'])) { $result[$label['id']]['alias'] = isset($aliases[$label['id']]) ? $aliases[$label['id']]['nid'] : null; } } } } } catch (SPError $x) { Sobi::Error('language', SPLang::e('CANNOT_TRANSLATE_OBJECT', $x->getMessage()), SPC::WARNING, 500, __LINE__, __CLASS__); } return $result; }
/** * Get field specific values if these are in an other table * @param $sid - id of the entry * @param $fullData - the database row form the spdb_field_data table * @param $rawData - raw data of the field content * @param $fData - full formatted data of the field content * @return void */ public function loadData($sid, &$fullData, &$rawData, &$fData) { /* @var SPdb $db */ $db =& SPFactory::db(); static $lang = null; if (!$lang) { $lang = Sobi::Lang(false); } $table = $db->join(array(array('table' => 'spdb_field_option_selected', 'as' => 'sdata', 'key' => 'fid'), array('table' => 'spdb_field_data', 'as' => 'fdata', 'key' => 'fid'), array('table' => 'spdb_language', 'as' => 'ldata', 'key' => array('sdata.optValue', 'ldata.sKey')))); try { $db->select('*, sdata.copy as scopy', $table, array('sdata.fid' => $this->id, 'sdata.sid' => $sid, 'fdata.sid' => $sid, 'ldata.oType' => 'field_option', 'ldata.fid' => $this->id), 'scopy', 0, 0, true); $data = $db->loadObjectList(); if ($data && count($data)) { $order = SPFactory::cache()->getVar('order_' . $this->nid); if (!$order) { $db->select('optValue', 'spdb_field_option', array('fid' => $this->id), 'optPos'); $order = $db->loadResultArray(); SPFactory::cache()->addVar($order, 'order_' . $this->nid); } $rawData = array(); $sRawData = array(); $copied = false; // check which version the user may see $copy = $this->checkCopy(); foreach ($data as $selected) { // if there was at least once copy if ($selected->scopy) { $copied = true; } } // check what we should show $remove = (int) $copied && $copy; foreach ($data as $selected) { if ($selected->scopy == $remove) { if (!isset($rawData[$selected->optValue]) || $selected->language == $lang) { $rawData[$selected->optValue] = $selected->sValue; } } } foreach ($order as $opt) { if (isset($rawData[$opt])) { $sRawData[] = $rawData[$opt]; } } $fData = implode("</li>\n\t<li>", $sRawData); $fData = "<ul id=\"{$this->nid}\" class=\"{$this->cssClass}\">\n\t<li>{$fData}</li>\n</ul>\n"; $fullData->baseData = $fData; } } catch (SPException $x) { Sobi::Error(__CLASS__, SPLang::e('CANNOT_GET_SELECTED_OPTION', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } }
public function save(&$attr) { static $lang = null; static $defLang = null; if (!$lang) { $lang = Sobi::Lang(); $defLang = Sobi::DefLang(); } $file = SPRequest::file('spfieldsopts', 'tmp_name'); if ($file) { $data = parse_ini_file($file, true); } elseif (is_string($attr['options'])) { $data = parse_ini_string($attr['options'], true); } else { $data = null; } $options = $this->parseOptsFile($data); if (!count($options) && count($attr['options'])) { $p = 0; $hold = array(); foreach ($attr['options'] as $o) { if (is_numeric($o['id'])) { $o['id'] = $this->nid . '_' . $o['id']; } if (isset($o['id'])) { $i = 0; $oid = $o['id']; while (isset($hold[$oid])) { $oid = $o['id'] . '_' . ++$i; } $options[] = array('id' => $oid, 'name' => $o['name'], 'parent' => null, 'position' => ++$p); $hold[$oid] = $oid; } } } if (count($options)) { unset($attr['options']); $optionsArr = array(); $labelsArr = array(); $defLabelsArr = array(); $optsIds = array(); foreach ($options as $i => $option) { /* check for doubles */ foreach ($options as $pos => $opt) { if ($i == $pos) { continue; } if ($option['id'] == $opt['id']) { $option['id'] = $option['id'] . '_' . substr((string) microtime(), 2, 8) . rand(1, 100); SPFactory::message()->warning('FIELD_WARN_DUPLICATE_OPT_ID'); } } $optionsArr[] = array('fid' => $this->id, 'optValue' => $option['id'], 'optPos' => $option['position'], 'optParent' => $option['parent']); $defLabelsArr[] = array('sKey' => $option['id'], 'sValue' => $option['name'], 'language' => $defLang, 'oType' => 'field_option', 'fid' => $this->id); $labelsArr[] = array('sKey' => $option['id'], 'sValue' => $option['name'], 'language' => $lang, 'oType' => 'field_option', 'fid' => $this->id); $optsIds[] = $option['id']; } /* @var SPdb $db */ $db =& SPFactory::db(); /* try to delete the existing labels */ try { $db->delete('spdb_field_option', array('fid' => $this->id)); $db->delete('spdb_language', array('oType' => 'field_option', 'fid' => $this->id, '!sKey' => $optsIds)); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('CANNOT_DELETE_SELECTED_OPTIONS', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } /* insert new values */ try { $db->insertArray('spdb_field_option', $optionsArr); $db->insertArray('spdb_language', $labelsArr, true); if ($defLang != $lang) { $db->insertArray('spdb_language', $defLabelsArr, false, true); } } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('CANNOT_STORE_FIELD_OPTIONS_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } } if (!isset($attr['params'])) { $attr['params'] = array(); } $myAttr = $this->getAttr(); $properties = array(); if (count($myAttr)) { foreach ($myAttr as $property) { $properties[$property] = isset($attr[$property]) ? $attr[$property] : null; } } $attr['params'] = $properties; $this->sets['field.options'] = SPFactory::Instance('types.array')->toINIString($data); }
/** * (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 loadSection() { $sections = array(); $sectionsOutput = array(); try { $sections = SPFactory::db()->select('*', 'spdb_object', array('oType' => 'section'), 'id')->loadObjectList(); } catch (SPException $x) { Sobi::Error($this->name(), $x->getMessage(), SPC::ERROR, 500, __LINE__, __FILE__); } if (count($sections)) { $sectionsOutput[] = Sobi::Txt('SOBI_SELECT_SECTION'); foreach ($sections as $section) { if (Sobi::Can('section', 'access', 'valid', $section->id)) { $s = new SPSection(); $s->extend($section); $sectionsOutput[$s->get('id')] = $s->get('name'); } } } $params = array('id' => 'SobiSection', 'class' => 'required'); return SPHtml_Input::select('section', $sectionsOutput, self::$section, false, $params); }