protected function messages() { $messages = SPFactory::message()->getReports(SPRequest::cmd('spsid')); $response = array(); if (count($messages)) { foreach ($messages as $type => $content) { if (count($content)) { foreach ($content as $message) { $response[] = array('type' => $type, 'text' => $message); } } } } $this->response(null, null, false, SPC::INFO_MSG, array('messages' => $response)); }
/** * @param string * @return SPConfigAdmView */ protected function getView($task) { SPLoader::loadClass('html.input'); $sid = Sobi::Reg('current_section'); /* create menu */ $class = SPLoader::loadClass('views.adm.menu'); $menu = new $class($task, $sid); /* load the menu definition */ if ($sid) { $cfg = SPLoader::loadIniFile('etc.adm.section_menu'); } else { $cfg = SPLoader::loadIniFile('etc.adm.config_menu'); } Sobi::Trigger('Create', 'AdmMenu', array(&$cfg)); if (count($cfg)) { foreach ($cfg as $section => $keys) { $menu->addSection($section, $keys); } } Sobi::Trigger('AfterCreate', 'AdmMenu', array(&$menu)); if ($sid) { if (Sobi::Cfg('section.template') == SPC::DEFAULT_TEMPLATE && strstr(SPRequest::task(), 'config')) { SPFactory::message()->warning(Sobi::Txt('TP.DEFAULT_WARN', 'https://www.sigsiu.net/help_screen/template.info'), false)->setSystemMessage(); } /* create new SigsiuTree */ $tree = SPLoader::loadClass('mlo.tree'); $tree = new $tree(Sobi::GetUserState('categories.order', 'corder', 'position.asc')); /* set link */ $tree->setHref(Sobi::Url(array('sid' => '{sid}'))); $tree->setId('menuTree'); /* set the task to expand the tree */ $tree->setTask('category.expand'); $tree->init($sid); /* add the tree into the menu */ $menu->addCustom('AMN.ENT_CAT', $tree->getTree()); $seClass = SPLoader::loadModel('section'); $cSec = new $seClass(); $cSec->init($sid); } else { $cSec = array('name' => Sobi::Txt('GB.CFG.GLOBAL_CONFIGURATION')); $menu->addCustom('GB.CFG.GLOBAL_TEMPLATES', $this->listTemplates()); } $view = SPFactory::View('config', true); $view->assign($task, 'task'); $view->assign($cSec, 'section'); $view->assign($menu, 'menu'); $view->addHidden(SPFactory::registry()->get('current_section'), 'sid'); return $view; }
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(); $optsIds = array(); $defLabelsArr = array(); $duplicates = false; 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); $duplicates = true; } } $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']; } if ($duplicates) { SPFactory::message()->warning('FIELD_WARN_DUPLICATE_OPT_ID'); } $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_STORE_FIELD_OPTIONS_DB_ERR', $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_DELETE_SELECTED_OPTIONS', $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; } } $this->sets['field.options'] = SPFactory::Instance('types.array')->toINIString($data); /** handle upload of new definition file */ $XMLFile = SPRequest::file('select-list-dependency', 'tmp_name'); if ($XMLFile && file_exists($XMLFile)) { $XMLFileName = SPRequest::file('select-list-dependency', 'name'); if (SPFs::getExt($XMLFileName) == 'zip') { $arch = SPFactory::Instance('base.fs.archive'); $name = str_replace('.zip', null, $XMLFileName); $path = SPLoader::dirPath('tmp.install.' . $name, 'front', false); $c = 0; while (SPFs::exists($path)) { $path = SPLoader::dirPath('tmp.install.' . $name . '_' . ++$c, 'front', false); } $arch->upload($XMLFile, $path . '/' . $XMLFileName); $arch->extract($path); $files = scandir($path); if (count($files)) { foreach ($files as $defFile) { switch (SPFs::getExt($defFile)) { case 'xml': $properties['dependencyDefinition'] = $defFile; SPFs::move($path . '/' . $defFile, SOBI_PATH . '/etc/fields/select-list/' . $defFile); break; case 'ini': $defLang = explode('.', $defFile); $defLang = $defLang[0]; if (file_exists(SOBI_ROOT . '/language/' . $defLang)) { SPFs::move($path . '/' . $defFile, SOBI_ROOT . '/language/' . $defLang . '/' . $defFile); } break; } } } } elseif (SPFs::getExt($XMLFileName) == 'xml') { if (SPFs::upload($XMLFile, SOBI_PATH . '/etc/fields/select-list/' . $XMLFileName)) { $properties['dependencyDefinition'] = $XMLFileName; } } } /** if we use it - let's transform the XML file */ if ($properties['dependency'] && $properties['dependencyDefinition']) { $this->parseDependencyDefinition($properties['dependencyDefinition']); } $attr['params'] = $properties; }
protected function parseXml() { $header = $this->_xml->getElementsByTagName('header')->item(0); if ($header->hasChildNodes()) { foreach ($header->childNodes as $node) { if (!strstr($node->nodeName, '#')) { $params = array(); $this->parseParams($node, $params); $this->callHeader($node->nodeName, $params[$node->nodeName]); } } } $data = $this->_xml->getElementsByTagName('cache-data')->item(0); if ($data && $data->hasChildNodes()) { foreach ($data->childNodes as $node) { if (!strstr($node->nodeName, '#')) { $params = array(); $this->parseParams($node, $params); if (isset($params['hidden']) && is_array($params['hidden']) && count($params['hidden'])) { foreach ($params['hidden'] as $k => $v) { $this->addHidden($v, $k); } } if (isset($params['request']) && is_array($params['request']) && count($params['request'])) { foreach ($params['request'] as $k => $v) { SPRequest::set($k, $v, 'get'); } } if (isset($params['pathway']) && is_array($params['pathway']) && count($params['pathway'])) { foreach ($params['pathway'] as $v) { SPFactory::mainframe()->addToPathway($v['name'], $v['url']); } } } } } $visitor = $this->visitorArray(SPFactory::user()->getCurrent()); if (is_array($visitor) && isset($visitor['_data'])) { $this->importData($this->_xml->documentElement, $visitor, 'visitor'); } $messages = SPFactory::message()->getMessages(); $info = array(); if (count($messages)) { foreach ($messages as $type => $content) { $info[$type] = array_values($content); } } if (is_array($info)) { $this->importData($this->_xml->documentElement, $info, 'messages'); } $this->_xml->formatOutput = true; }
/** */ private function editForm() { $sid = SPRequest::int('pid'); $sid = $sid ? $sid : SPRequest::sid(); $view = SPFactory::View('entry', true); $this->checkTranslation(); /* if adding new */ if (!$this->_model) { $this->setModel(SPLoader::loadModel('entry')); } $this->_model->formatDatesToEdit(); $id = $this->_model->get('id'); if (!$id) { $this->_model->set('state', 1); $this->_model->set('approved', 1); } else { $view->assign($view->languages(), 'languages-list'); } $this->_model->loadFields(Sobi::Reg('current_section'), true); $this->_model->formatDatesToEdit(); if ($this->_model->isCheckedOut()) { SPFactory::message()->error(Sobi::Txt('EN.IS_CHECKED_OUT', $this->_model->get('name')), false); } else { /* check out the model */ $this->_model->checkOut(); } /* get fields for this section */ /* @var SPEntry $this ->_model */ $fields = $this->_model->get('fields'); if (!count($fields)) { throw new SPException(SPLang::e('CANNOT_GET_FIELDS_IN_SECTION', Sobi::Reg('current_section'))); } $revisionChange = false; $rev = SPRequest::cmd('revision'); $revisionsDelta = array(); if ($rev) { $revision = SPFactory::message()->getRevision(SPRequest::cmd('revision')); if (isset($revision['changes']) && count($revision['changes'])) { SPFactory::message()->warning(Sobi::Txt('HISTORY_REVISION_WARNING', $revision['changedAt']), false); foreach ($fields as $i => $field) { if ($field->get('enabled') && $field->enabled('form')) { if (isset($revision['changes']['fields'][$field->get('nid')])) { $revisionData = $revision['changes']['fields'][$field->get('nid')]; } else { $revisionData = null; } $currentData = $field->getRaw(); if (is_array($revisionData) && !is_array($currentData)) { try { $currentData = SPConfig::unserialize($currentData); } catch (SPException $x) { } } if ($revisionData || $currentData) { if (md5(serialize($currentData)) != md5(serialize($revisionData))) { $field->revisionChanged()->setRawData($revisionData); } } $fields[$i] = $field; } } unset($revision['changes']['fields']); foreach ($revision['changes'] as $attr => $value) { if ($value != $this->_model->get($attr)) { $revisionsDelta[$attr] = $value; $this->_model->setRevData($attr, $value); } } $revisionChange = true; } else { SPFactory::message()->error(Sobi::Txt('HISTORY_REVISION_NOT_FOUND'), false)->setSystemMessage(); } } $f = array(); foreach ($fields as $field) { if ($field->get('enabled') && $field->enabled('form')) { $f[] = $field; } } /* create the validation script to check if required fields are filled in and the filters, if any, match */ $this->createValidationScript($fields); $view->assign($this->_model, 'entry'); /* get the categories */ $cats = $this->_model->getCategories(true); if (count($cats)) { $tCats = array(); foreach ($cats as $cid) { /* ROTFL ... damn I like arrays ;-) */ $tCats2 = SPFactory::config()->getParentPath($cid, true); if (is_array($tCats2) && count($tCats2)) { $tCats[] = implode(Sobi::Cfg('string.path_separator'), $tCats2); } } if (count($tCats)) { $view->assign(implode("\n", $tCats), 'parent_path'); } $view->assign(implode(", ", $cats), 'parents'); } elseif ($this->_model->get('valid')) { $parent = $sid == Sobi::Reg('current_section') ? 0 : $sid; if ($parent) { $view->assign(implode(Sobi::Cfg('string.path_separator', ' > '), SPFactory::config()->getParentPath($parent, true)), 'parent_path'); } $view->assign($parent, 'parents'); } else { $n = null; $view->assign($n, 'parents'); $view->assign($n, 'parent_path'); } $history = array(); $messages = SPFactory::message()->getHistory($id); if (count($messages)) { foreach ($messages as $message) { $message['change'] = Sobi::Txt('HISTORY_CHANGE_TYPE_' . str_replace('-', '_', strtoupper($message['change']))); $message['site'] = Sobi::Txt('HISTORY_CHANGE_AREA_' . strtoupper($message['site'])); if (strlen($message['reason'])) { $message['status'] = 1; } else { $message['status'] = 0; } $history[] = $message; } } $versioningAdminBehaviour = Sobi::Cfg('entry.versioningAdminBehaviour', 1); if ($versioningAdminBehaviour || !Sobi::Cfg('entry.versioning', true)) { SPFactory::header()->addJsCode(' SobiPro.jQuery( document ).ready( function () { SobiPro.jQuery( "[rel=\'entry.saveWithRevision\']" ).parent().css( "display", "none" ); } ); '); } $view->assign($this->_task, 'task')->assign($f, 'fields')->assign($id, 'id')->assign($history, 'history')->assign($revisionChange, 'revision-change')->assign($revisionsDelta, 'revision')->assign($versioningAdminBehaviour, 'history-behaviour')->assign(SPFactory::CmsHelper()->userSelect('entry.owner', $this->_model->get('owner') ? $this->_model->get('owner') : ($this->_model->get('id') ? 0 : Sobi::My('id')), true), 'owner')->assign(Sobi::Reg('current_section'), 'sid')->determineTemplate('entry', 'edit')->addHidden($rev, 'revision')->addHidden($sid, 'pid'); $view->display(); }
/** * */ public function display($o = null) { if (SPRequest::cmd('format') == 'json' && Sobi::Cfg('output.json_enabled', false)) { return $this->jsonDisplay(); } $type = $this->key('template_type', 'xslt'); $f = null; $task = SPRequest::task(); if ($this->key('functions')) { $f = $this->registerFunctions(); } $out = null; if ($type != 'php' && Sobi::Cfg('global.disable_xslt', false)) { $type = 'php'; } $parserClass = SPLoader::loadClass('mlo.template_' . $type); if ($parserClass) { /** @var $parser SPTemplateXSLT */ $parser = new $parserClass(); } else { throw new SPException(SPLang::e('CANNOT_LOAD_PARSER', $type)); } $this->_attr['template_path'] = Sobi::FixPath(str_replace(SOBI_ROOT, Sobi::Cfg('live_site'), $this->_templatePath)); $messages = SPFactory::message()->getMessages(); if (count($messages)) { foreach ($messages as $type => $content) { $this->_attr['messages'][$type] = array_values($content); } } $parser->setProxy($this); $parser->setData($this->_attr); $parser->setXML($this->_xml); $parser->setCacheData(array('hidden' => $this->_hidden)); $parser->setType($this->_type); $parser->setTemplate($this->_template); Sobi::Trigger('Display', $this->name(), array($type, &$this->_attr)); $o = $o ? $o : strtolower($this->key('output', $this->key('output', 'html'), $this->tTask)); $action = $this->key('form.action'); if ($action) { $opt = SPFactory::mainframe()->form(); if (is_array($opt) && count($opt)) { foreach ($opt as $l => $v) { $this->addHidden($v, $l); } } $form = $this->csection('form'); $form['method'] = isset($form['method']) && $form['method'] ? $form['method'] : 'post'; $out .= "\n<form "; foreach ($form as $p => $v) { $out .= $p . '="' . $v . '" '; } $out .= ">\n"; } $out .= $parser->display($o, $f); $hidden = null; if (count($this->_hidden)) { $this->_hidden[SPFactory::mainframe()->token()] = 1; foreach ($this->_hidden as $name => $value) { $hidden .= "\n<input type=\"hidden\" id=\"SP_{$name}\" name=\"{$name}\" value=\"{$value}\"/>"; } // xhtml strict valid $hidden = "<div>{$hidden}</div>"; $out .= $hidden; } $out .= $action ? "\n</form>\n" : null; /* SobiPro type specific content parser */ Sobi::Trigger('ContentDisplay', $this->name(), array(&$out)); /* common content parser */ $cParse = $this->key('parse', -1); /* if it was specified in the template config file or it was set in the section config and not disabled in the template config */ if (!(strstr($task, '.edit') || strstr($task, '.add') || in_array($task, Sobi::Cfg('plugins.content_disable', array())))) { if ($cParse == 1 || Sobi::Cfg('parse_template_content', false) && $cParse == -1) { Sobi::Trigger('Parse', 'Content', array(&$out)); } } header('SobiPro: ' . Sobi::Section()); if ($o == 'html' && (!strlen(SPRequest::cmd('format')) || SPRequest::cmd('format') == 'html' || SPRequest::int('crawl'))) { $out .= $this->pb(); if ((SPRequest::cmd('dbg') || Sobi::Cfg('debug')) && Sobi::My('id')) { $start = Sobi::Reg('start'); $mem = $start[0]; $time = $start[1]; $queries = SPFactory::db()->getCount(); $mem = number_format(memory_get_usage() - $mem); $time = microtime(true) - $time; SPConfig::debOut("Memory: {$mem}<br/>Time: {$time}<br/> Queries: {$queries}"); } echo "\n<!-- Start of SobiPro component-->\n<div id=\"SobiPro\" class=\"SobiPro\">\n{$out}\n</div>\n<!-- End of SobiPro component Copyright (C) 2011-2014 Sigsiu.NET GmbH -->\n"; } else { $this->customOutput($out); } Sobi::Trigger('AfterDisplay', $this->name()); }
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); }
/** * @param $action * @param null $reason */ protected function logChanges($action, $reason = null) { $changes = $this->_model->getCurrentBaseData(); $fields = $this->_model->getFields(); if (count($fields)) { foreach ($fields as $nid => $field) { try { $changes['fields'][$nid] = $field->saveHistory(); } catch (SPException $x) { $changes['fields'][$nid] = $field->getRaw(); } } } SPFactory::message()->logAction($action, $this->_model->get('id'), $changes, $reason); }
/** * Returns the name/title field * @return SPField */ public function nameField() { if (!isset(self::$fields[Sobi::Section()][Sobi::Cfg('entry.name_field')])) { if (Sobi::Cfg('entry.name_field')) { /* @var SPField $f */ $f = SPFactory::Model('field', true); $f->init(Sobi::Cfg('entry.name_field')); self::$fields[Sobi::Section()][Sobi::Cfg('entry.name_field')] = $f; } else { SPFactory::message()->warning('NO_NAME_FIELD_SELECTED'); } } return isset(self::$fields[Sobi::Section()][Sobi::Cfg('entry.name_field')]) ? self::$fields[Sobi::Section()][Sobi::Cfg('entry.name_field')] : SPFactory::Model('field', true); }
/** */ public function delete($id = 0) { $fields = array(); $m = array(); if ($id) { $fields[] = $id; } else { if (SPRequest::int('fid', 0)) { $fields[] = SPRequest::int('fid', 0); } else { $fields = SPRequest::arr('p_fid', array()); } } if (count($fields)) { foreach ($fields as $id) { $field = SPFactory::Model('field', true); $field->extend($this->loadField($id)); $msg = $field->delete(); SPFactory::message()->setMessage($msg, false, SPC::SUCCESS_MSG); $m[] = $msg; } } else { $msg = SPLang::e('FMN.STATE_CHANGE_NO_ID'); SPFactory::message()->setMessage($msg, false, SPC::ERROR_MSG); return; } return $m; }
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)); }
/** */ private function editForm() { /* if adding new */ if (!$this->_model || $this->_task == 'add') { $this->setModel(SPLoader::loadModel('category')); } $this->checkTranslation(); $this->_model->formatDatesToEdit(); $id = $this->_model->get('id'); if (!$id) { $this->_model->set('state', 1); $this->_model->set('parent', SPRequest::sid()); } if ($this->_model->isCheckedOut()) { SPFactory::message()->error(Sobi::Txt('CAT.IS_CHECKED_OUT'), false); } else { $this->_model->checkOut(); } $view = SPFactory::View('category', true); $view->assign($this->_model, 'category')->assign($this->_task, 'task')->assign(SPFactory::CmsHelper()->userSelect('category.owner', $this->_model->get('owner') ? $this->_model->get('owner') : ($this->_model->get('id') ? 0 : Sobi::My('id')), true), 'owner')->assign($id, 'cid')->addHidden(Sobi::Section(), 'pid'); Sobi::Trigger('Category', 'EditView', array(&$view)); $view->display(); }
/** * Clean cache of a section * @param $section - section id. If not given, current section will be used * @param bool $system * @return SPCache */ public function &cleanSection($section = 0, $system = true) { $sid = $section ? $section : $this->_section; $this->cleanJCache(); if ($section == Sobi::Section() && $this->enabled()) { $this->Exec("BEGIN; DELETE FROM vars; COMMIT;"); $this->Exec("BEGIN; DELETE FROM objects; COMMIT;"); } elseif (SPFs::exists($this->_store . '.htCache_' . $sid . '.db')) { // we need an exception because this files are owned by Apache probably @unlink($this->_store . '.htCache_' . $sid . '.db'); if (SPFs::exists($this->_store . '.htCache_' . $sid . '.db')) { SPFs::delete($this->_store . '.htCache_' . $sid . '.db'); } } if ($sid > 0) { $this->cleanSection(-1); $this->cleanApc(); } if ($system) { SPFactory::message()->resetSystemMessages(); } $this->cleanSectionXML($this->_section); return $this; }
protected function response($url, $message = null, $redirect = true, $type = SPC::INFO_MSG, $data = array(), $request = 'post') { if (is_array($message)) { $type = $message['type']; $message = $message['text']; } if (SPRequest::cmd('method', null, $request) == 'xhr') { if ($redirect && $message) { SPFactory::message()->setMessage($message, false, $type); } $url = str_replace('&', '&', $url); SPFactory::mainframe()->cleanBuffer()->customHeader(); echo json_encode(array('message' => array('text' => $message, 'type' => $type), 'redirect' => array('url' => $url, 'execute' => (bool) $redirect), 'data' => $data)); exit; } else { if ($message) { if (strstr($url, 'com_sobipro')) { SPFactory::message()->setMessage($message, false, $type); $message = null; } } Sobi::Redirect($url, $message, null, $redirect); } }
protected function getState() { $state = SPFactory::cache()->getVar('system_state'); if (!$state) { SPLang::load('com_sobipro.messages'); $state = array(); $state['accelerator'] = array('type' => Sobi::Cfg('cache.l3_enabled', true) ? 'success' : 'error', 'label' => Sobi::Cfg('cache.l3_enabled', true) ? Sobi::Txt('ACCELERATOR_ENABLED') : Sobi::Txt('ACCELERATOR_DISABLED')); $state['xml-optimiser'] = array('type' => Sobi::Cfg('cache.xml_enabled', true) ? 'success' : 'error', 'label' => Sobi::Cfg('cache.xml_enabled', true) ? Sobi::Txt('XML_CACHE_ENABLED') : Sobi::Txt('XML_CACHE_DISABLED')); $state['javascript-cache'] = array('type' => Sobi::Cfg('cache.include_js_files', false) ? 'success' : 'warning', 'label' => Sobi::Cfg('cache.include_js_files', false) ? Sobi::Txt('JS_CACHE_ENABLED') : Sobi::Txt('JS_CACHE_DISABLED')); $state['css-cache'] = array('type' => Sobi::Cfg('cache.include_css_files', false) ? 'success' : 'warning', 'label' => Sobi::Cfg('cache.include_css_files', false) ? Sobi::Txt('CSS_CACHE_ENABLED') : Sobi::Txt('CSS_CACHE_DISABLED')); $state['display-errors'] = array('type' => Sobi::Cfg('debug.display_errors', false) ? 'error' : 'success', 'label' => Sobi::Cfg('debug.display_errors', false) ? Sobi::Txt('DISPLAY_ERRORS_ENABLED') : Sobi::Txt('DISPLAY_ERRORS_DISABLED')); $state['debug-level'] = array('type' => Sobi::Cfg('debug.level', 0) > 2 ? 'warning' : 'success', 'label' => Sobi::Cfg('debug.level', 0) > 2 ? Sobi::Txt('DEBUG_LEVEL_TOO_HIGH') : Sobi::Txt('DEBUG_LEVEL_OK')); $state['debug-xml'] = array('type' => Sobi::Cfg('debug.xml_raw', false) ? 'error' : 'success', 'label' => Sobi::Cfg('debug.xml_raw', false) ? Sobi::Txt('DEBUG_XML_ENABLED') : Sobi::Txt('DEBUG_XML_DISABLED')); // uasort( $state, array( $this, 'sortMessages' ) ); $messages = SPFactory::message()->getSystemMessages(); $content = null; if (count($messages)) { foreach ($messages as $message) { $url = Sobi::Url(array('sid' => $message['section']['id'])); $url = "<a href=\"{$url}\">{$message['section']['name']}</a> "; $message['section']['link'] = $url; $message['type-text'] = ucfirst(Sobi::Txt($message['type'])); $state['messages'][] = $message; } } SPFactory::cache()->addVar($state, 'system_state'); } return $state; }
protected function legacyMessages() { $messages = SPFactory::message()->getMessages(); $out = array(); if (count($messages)) { foreach ($messages as $type => $texts) { if (count($texts)) { $out[] = "<div class=\"alert alert-{$type} spSystemAlert\">"; $out[] = '<button type="button" class="close" data-dismiss="alert">×</button>'; foreach ($texts as $text) { $out[] = "<div>{$text}</div>"; } $out[] = '</div>'; } } } return implode('', $out); }
private function editFile() { if (Sobi::Section() && Sobi::Cfg('section.template') == SPC::DEFAULT_TEMPLATE) { SPFactory::message()->warning(Sobi::Txt('TP.DEFAULT_WARN', 'https://www.sigsiu.net/help_screen/template.info'), false)->setSystemMessage(); } $file = SPRequest::cmd('file'); $file = $this->file($file); $ext = SPFs::getExt($file); $fileContent = SPFs::read($file); $path = str_replace('\\', '/', SOBI_PATH); if (strstr($file, $path)) { $filename = str_replace($path . '/usr/templates/', null, $file); } else { $filename = str_replace(SOBI_ROOT, null, $file); } $menu = $this->createMenu(); if (Sobi::Section()) { $menu->setOpen('AMN.APPS_SECTION_TPL'); } else { $menu->setOpen('GB.CFG.GLOBAL_TEMPLATES'); } /** @var $view SPAdmTemplateView */ $view = SPFactory::View('template', true)->assign($fileContent, 'file_content')->assign($filename, 'file_name')->assign($ext, 'file_ext')->assign($menu, 'menu')->assign($this->_task, 'task')->assign(Sobi::Section(), 'sid')->addHidden(SPRequest::cmd('file'), 'fileName')->addHidden($filename, 'filePath')->determineTemplate('template', 'edit'); Sobi::Trigger('Edit', $this->name(), array(&$file, &$view)); $view->display(); }
protected function ajaxResponse($ajax, $message, $redirect, $type, $callback = 'SPExtensionInstaller') { if ($ajax) { if ($redirect) { SPFactory::message()->setMessage($message, false, $type); } $response = array('type' => $type, 'text' => $message, 'redirect' => $redirect ? Sobi::Url('extensions.installed') : false, 'callback' => $type == SPC::SUCCESS_MSG ? $callback : false); SPFactory::mainframe()->cleanBuffer()->customHeader(); echo json_encode($response); exit; } elseif ($redirect) { SPFactory::message()->setMessage($message, false, $type); Sobi::Redirect(Sobi::Url('extensions.installed')); } else { return array('msg' => $message, 'msgtype' => $type); } }
/** * @param $url * @return bool */ protected function getItemid(&$url) { $sid = isset($url['pid']) && $url['pid'] ? $url['pid'] : $url['sid']; if (!(int) $sid) { return false; } $url['Itemid'] = 0; // Thu, Feb 27, 2014 16:28:22 - iy is probably the right solution // but NTaRS $menu = JFactory::getApplication('site')->getMenu('site'); // Thu, Mar 6, 2014 12:42:01 - let's check // $menu = JApplication::getMenu( 'site' ); if (isset($url['task'])) { $task = $url['task'] == 'search.results' ? 'search' : $url['task']; $link = 'index.php?option=com_sobipro&task=' . $task . '&sid=' . $sid; } else { $link = 'index.php?option=com_sobipro&sid=' . $sid; } $item = $menu->getItems('link', $link, true); if ($item && count($item)) { $url['Itemid'] = $item->id; } else { $path = SPFactory::config()->getParentPath($sid); if (count($path)) { foreach ($path as $sid) { $item = $menu->getItems('link', 'index.php?option=com_sobipro&sid=' . $sid, true); if ($item && count($item)) { $url['Itemid'] = $item->id; } } } } // if we still don't have an Itemid it means that there is no link to SobiPro section if (!$url['Itemid'] && !defined('SOBIPRO_ADM')) { SPFactory::message()->warning(Sobi::Txt('ITEMID_MISSING_WARN', 'https://www.sigsiu.net/help_screen/joomla.menu', $sid), false, false)->setSystemMessage('SEF-URL'); } }
private function langFiles($tag, $def, $dir, &$FilesLog) { $target = $tag == 'administration' ? implode(DS, array(SOBI_ROOT, 'administrator', 'language', $this->id)) : implode(DS, array(SOBI_ROOT, 'language', $this->id)); if (!file_exists($target)) { $this->error = Sobi::Txt('LANG_INSTALL_NO_CORE', $this->id); $this->errorType = SPC::WARN_MSG; SPFs::mkdir($target); } $files = $def->getElementsByTagName($tag)->item(0)->getElementsByTagName('files')->item(0); $folder = $files->getAttribute('folder'); $folder = $dir . $folder . DS; foreach ($files->getElementsByTagName('filename') as $file) { if (file_exists($folder . $file->nodeValue)) { if (!SPFs::copy($folder . $file->nodeValue, $target . DS . $file->nodeValue)) { SPFactory::message()->error(Sobi::Txt('Cannot copy %s to %s', $folder . $file->nodeValue, $target . DS . $file->nodeValue), false); } else { $FilesLog[] = str_replace(array(DS . DS, SOBI_ROOT), array(DS, null), $target . DS . $file->nodeValue); } } else { SPFactory::message()->error(Sobi::Txt('File %s does not exist!', $folder . $file->nodeValue), false); } } }
protected function message($data) { $class = isset($data['attributes']['class']) && $data['attributes']['class'] ? $data['attributes']['class'] : null; if ($this->istSet($data['attributes'], 'label')) { $type = isset($data['attributes']['type']) && $data['attributes']['type'] ? 'alert-' . $data['attributes']['type'] : null; $icon = null; if (isset($data['attributes']['icon']) && $data['attributes']['icon'] == 'true') { if ($type == 'alert-success') { $icon = 'icon-thumbs-up'; } elseif ($type == 'alert-info') { $icon = 'icon-lightbulb'; } else { $icon = 'icon-thumbs-down'; } $icon = "<i class=\"{$icon}\"></i> "; } $this->_out[] = "<div class=\"alert {$type} {$class}\">"; if (isset($data['attributes']['dismiss-button']) && $data['attributes']['dismiss-button'] == 'true') { $this->_out[] = '<button type="button" class="close" data-dismiss="alert">×</button>'; } $this->_out[] = $icon . $data['attributes']['label']; $this->_out[] = '</div>'; } else { $attr = array(); if (isset($data['attributes']['type'])) { unset($data['attributes']['type']); } if (count($data['attributes'])) { foreach ($data['attributes'] as $n => $v) { $attr[] = "{$n}=\"{$v}\""; } } $attr = implode(' ', $attr); $messages = SPFactory::message()->getMessages(); if (count($messages)) { foreach ($messages as $type => $texts) { if (count($texts)) { $this->_out[] = "<div class=\"alert alert-{$type} spSystemAlert\">"; $this->_out[] = '<button type="button" class="close" data-dismiss="alert">×</button>'; foreach ($texts as $text) { $this->_out[] = "<div>{$text}</div>"; } $this->_out[] = '</div>'; } } } $this->_out[] = "<div {$attr}></div>"; } }
/** * @param int $sid * @return void */ public function loadFields($sid = 0, $enabled = false) { $sid = $sid ? $sid : $this->section; /* @var SPdb $db */ $db =& SPFactory::db(); static $fields = array(); static $lang = null; $lang = $lang ? $lang : Sobi::Lang(false); if (!isset($fields[$sid])) { /* get fields */ try { $fields[$sid] = $db->select('*', 'spdb_field', array('section' => $sid, $db->argsOr(array('admList' => 1, 'fid' => $this->nameField()))), 'position')->loadObjectList(); Sobi::Trigger($this->name(), ucfirst(__FUNCTION__), array(&$fields)); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('CANNOT_GET_FIELDS_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } } $nameField = $this->nameField(); if (!$this->_loaded) { if (count($fields[$sid])) { /* if it is an entry - prefetch the basic fields data */ if ($this->id) { $noCopy = $this->checkCopy(); /* in case the entry is approved, or we are aditing an entry, or the user can see unapproved changes */ if ($this->approved || $noCopy) { $ordering = 'copy.desc'; } else { $ordering = 'copy.asc'; } try { $db->select('*', 'spdb_field_data', array('sid' => $this->id), $ordering); $fdata = $db->loadObjectList(); $fieldsdata = array(); if (count($fdata)) { foreach ($fdata as $data) { /* if it has been already set - check if it is not better language choose */ if (isset($fieldsdata[$data->fid])) { /* * I know - the whole thing could be shorter * but it is better to understand and debug this way */ if ($data->lang == $lang) { if ($noCopy) { if (!$data->copy) { $fieldsdata[$data->fid] = $data; } } else { $fieldsdata[$data->fid] = $data; } } else { $fieldsdata['langs'][$data->lang][$data->fid] = $data; } } else { if ($noCopy) { if (!$data->copy) { $fieldsdata[$data->fid] = $data; } } else { $fieldsdata[$data->fid] = $data; } } } } unset($fdata); SPFactory::registry()->set('fields_data_' . $this->id, $fieldsdata); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('DB_REPORTS_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } foreach ($fields[$sid] as $f) { /* @var SPField $field */ $field = SPFactory::Model('field', defined('SOBIPRO_ADM')); $field->extend($f); $field->loadData($this->id); $this->fields[] = $field; $this->fieldsNids[$field->get('nid')] = $this->fields[count($this->fields) - 1]; $this->fieldsIds[$field->get('fid')] = $this->fields[count($this->fields) - 1]; /* case it was the name field */ if ($field->get('fid') == $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'); } } $this->_loaded = true; } } if (!strlen($this->name)) { $this->name = Sobi::Txt('ENTRY_NO_NAME'); // well yeah - screw the pattern :-/ SPFactory::message()->warning('ENTRIES_BASE_DATA_INCOMPLETE')->setSystemMessage(); $this->valid = false; } }