/** * @return string */ public function display() { $this->_view[] = "\n <!-- Sobi Pro - admin side menu start -->"; $this->_view[] = "\n<div id=\"SPaccordionTabs\" class=\"SPmenuTabs\">"; $this->_view[] = '<div id="SPMenuCtrl">'; $this->_view[] = ' <button class="btn btn-mini btn-sobipro" id="SPMenuCtrlBt" type="button">-</button>'; $this->_view[] = '</div>'; $media = Sobi::Cfg('img_folder_live'); $this->_view[] = "\n<div class='well well-small'><a href=\"http://www.Sigsiu.NET\" target=\"_blank\" title=\"Sigsiu.NET Software Development\"><img src=\"{$media}/sp.png\" alt=\"Sigsiu.NET Software Development\" style=\"border-style:none;\" /></a></div>\n"; $fs = null; if (count($this->_sections)) { if ($this->_task == 'section.view') { // $this->_task = 'section.entries'; $this->_open = 'AMN.ENT_CAT'; } $this->_view[] = '<div class="accordion" id="SpMenu">'; foreach ($this->_sections as $section => $list) { $sid = SPLang::nid($section); $in = false; if (!$fs) { $fs = $sid; } if (!$this->_open && array_key_exists($this->_task, $list)) { $this->_open = $sid; $in = ' in'; } if ($this->_open && $section == $this->_open) { $in = ' in'; } if (!$this->_open && array_key_exists($this->_task, $list)) { $in = ' in'; } $this->_view[] = '<div class="accordion-group">'; $this->_view[] = '<div class="accordion-heading">'; $this->_view[] = '<a class="accordion-toggle" data-toggle="collapse" data-parent="#SpMenu" href="#' . $sid . '">'; $this->_view[] = Sobi::Txt($section); $this->_view[] = '</a>'; $this->_view[] = '</div>'; $this->_view[] = '<div id="' . $sid . '" class="accordion-body collapse' . $in . '">'; $this->_view[] = '<div class="accordion-inner">'; $this->_view[] = $this->section($list, $section); $this->_view[] = '</div>'; $this->_view[] = '</div>'; $this->_view[] = '</div>'; } $this->_view[] = '</div>'; } $this->_view[] = "\n</div>\n"; $this->_view[] = '<div class="brand" style="display: inherit;">© <a href="http://www.sigsiu.net">Sigsiu.NET GmbH</a></div>'; $this->_view[] = "\n<!-- Sobi Pro - admin side menu end -->\n"; return implode("\n", $this->_view); }
private function download() { // $file = SPLoader::path( 'tmp.info', 'front', false, 'txt' ); $cont = null; $settings = array(); $settings['SobiPro'] = array('Version' => SPFactory::CmsHelper()->myVersion(true), 'Version_Num' => implode('.', SPFactory::CmsHelper()->myVersion())); $file = SPLoader::path('tmp.info', 'front', false, 'txt'); // if ( SPFs::exists( $file ) ) { // $cont = SPFs::read( $file ); // } // $cont = explode( "\n", $cont ); // if ( count( $cont ) ) { // foreach ( $cont as $line ) { // if ( strstr( $line, '=' ) ) { // $line = explode( "=", $line ); // $line[ 1 ] = explode( ';', $line[ 1 ] ); // $settings[ $line[ 0 ] ] = array( 'key' => $line[ 0 ], 'response' => $line[ 1 ][ 0 ], 'status' => $line[ 1 ][ 1 ] ); // } // } // } $this->prepareStoredData($settings); $settings['env'] = array('PHP_OS' => PHP_OS, 'php_uname' => php_uname(), 'PHP_VERSION_ID' => PHP_VERSION_ID); $settings['ftp'] = $this->ftp(); $settings['curl'] = $this->curlFull(); $settings['exec']['response'] = $this->execResp(); $settings['SOBI_SETTINGS'] = SPFactory::config()->getSettings(); $c = SPFactory::db()->select('*', 'spdb_config')->loadObjectList(); $sections = SPFactory::db()->select(array('nid', 'id'), 'spdb_object', array('oType' => 'section'))->loadAssocList('id'); $as = array(); foreach ($c as $key) { if ($key->section == 0 || !isset($sections[$key->section])) { continue; } $key->section = $sections[$key->section]['nid']; if (!isset($as[$key->section])) { $as[$key->section] = array(); } if (!isset($as[$key->section][$key->cSection])) { $as[$key->section][$key->cSection] = array(); } $_c = explode('_', $key->sKey); if ($_c[count($_c) - 1] == 'array') { $key->sValue = SPConfig::unserialize($key->sValue); } $as[$key->section][$key->cSection][$key->sKey] = $key->sValue; } $settings['SOBI_SETTINGS']['sections'] = $as; $apps = SPFactory::db()->select('*', 'spdb_plugins')->loadObjectList(); foreach ($apps as $app) { $settings['Apps'][$app->pid] = get_object_vars($app); } $settings['SOBI_SETTINGS']['mail']['smtphost'] = $settings['SOBI_SETTINGS']['mail']['smtphost'] ? 'SET' : 0; $settings['SOBI_SETTINGS']['mail']['smtpuser'] = $settings['SOBI_SETTINGS']['mail']['smtpuser'] ? 'SET' : 0; $settings['SOBI_SETTINGS']['mail']['smtppass'] = $settings['SOBI_SETTINGS']['mail']['smtppass'] ? 'SET' : 0; $php = ini_get_all(); unset($php['extension_dir']); unset($php['include_path']); unset($php['mysql.default_user']); unset($php['mysql.default_password']); unset($php['mysqli.default_pw']); unset($php['mysqli.default_user']); unset($php['open_basedir']); unset($php['pdo_mysql.default_socket']); unset($php['sendmail_path']); unset($php['session.name']); unset($php['session.save_path']); unset($php['soap.wsdl_cache_dir']); unset($php['upload_tmp_dir']); unset($php['doc_root']); unset($php['docref_ext']); unset($php['docref_root']); unset($php['mysql.default_socket']); $settings['PHP_SETTINGS'] = $php; $php = get_loaded_extensions(); $settings['PHP_EXT'] = $php; $out = SPFactory::Instance('types.array'); $data = $out->toXML($settings, 'settings'); $data = str_replace(array(SOBI_ROOT, '></'), array('REMOVED', '>0</'), $data); $f = SPLang::nid($settings['SOBI_SETTINGS']['general']['site_name'] . '-' . date(DATE_RFC822)); SPFactory::mainframe()->cleanBuffer(); header('Cache-Control: no-cache, must-revalidate'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); header("Content-type: application/xml"); header("Content-Disposition: attachment; filename=\"sobipro_system_{$f}.xml\""); header('Content-Length: ' . strlen($data)); ob_clean(); flush(); echo $data; exit; }
public static function hidden($name, $value = null, $id = null, $params = array()) { $data = self::createDataTag($params); $id = $id ? $id : SPLang::nid($name); $f = "\n<input type=\"hidden\" name=\"{$name}\" id=\"{$id}\" value=\"{$value}\" {$data}/>"; return "\n<!-- '{$name}' Output -->{$f}<!-- '{$name}' End -->\n\n"; }
protected function nid($txt) { return $this->legacy ? strtolower(SPLang::nid($txt)) : SPLang::nid($txt); }
protected function parseOptsFile($file) { $p = 0; $group = null; $gid = null; $options = array(); if (is_array($file) && count($file)) { foreach ($file as $key => $value) { if (is_array($value)) { if (strstr($key, ',')) { $group = explode(',', $key); $gid = SPLang::nid($group[0]); $group = $group[1]; } else { $gid = SPLang::nid($key, true, true); $group = $key; } $options[] = array('id' => $gid, 'name' => $group, 'parent' => null, 'position' => ++$p); if (count($value)) { foreach ($value as $k => $v) { if (is_numeric($k)) { $k = SPLang::nid($v); } $options[] = array('id' => SPLang::nid($k), 'name' => $v, 'parent' => $gid, 'position' => ++$p); } } } else { $group = null; $gid = null; $options[] = array('id' => SPLang::nid($key), 'name' => $value, 'parent' => null, 'position' => ++$p); } } } return $options; }
/** * Creates alias/nid suitable string * @param string $txt * @return string */ public static function varName($txt) { $pieces = explode(' ', $txt); $txt = null; for ($i = 0; $i < count($pieces); $i++) { $pieces[$i] = SPLang::nid($pieces[$i]); // preg_replace( '/[^a-z0-9_]/', null, strtolower( $pieces[ $i ] ) ); if ($i > 0) { $pieces[$i] = ucfirst($pieces[$i]); } $txt .= $pieces[$i]; } return $txt; }
/** * @param DOMDocument $def * @param string $dir * @return array | string */ protected function installExt($def, $dir) { $this->checkRequirements($def); jimport('joomla.installer.installer'); jimport('joomla.installer.helper'); $installer = JInstaller::getInstance(); $type = JInstallerHelper::detectType($dir); $xp = new DOMXPath($def); try { $installer->install($dir); // it was core update - break now if ($type == 'component') { SPFactory::cache()->cleanAll(); return array('msg' => Sobi::Txt('CMS_SOBIPRO_UPDATE_INSTALLED', $def->getElementsByTagName('version')->item(0)->nodeValue), 'msgtype' => SPC::SUCCESS_MSG); } $msg = Sobi::Txt('CMSEX_INSTALLED', $type, $def->getElementsByTagName('name')->item(0)->nodeValue); $this->id = SPLang::nid($def->getElementsByTagName('name')->item(0)->nodeValue); $id = $xp->query('//filename[@module|@plugin]')->item(0); $this->id = strlen($id->getAttribute('module')) ? $id->getAttribute('module') : $id->getAttribute('plugin'); if (strlen($def->documentElement->getAttribute('group'))) { $this->id = $def->documentElement->getAttribute('group') . '_' . $this->id; } if ($this->id) { $this->definition = new DOMDocument(); $this->definition->formatOutput = true; $this->definition->preserveWhiteSpace = false; $this->definition->appendChild($this->definition->createElement('SobiProApp')); $root = $this->definition->getElementsByTagName('SobiProApp')->item(0); $root->appendChild($this->definition->createElement('id', $this->id)); $root->appendChild($this->definition->createElement('type', $type)); $root->appendChild($this->definition->createElement('name', $def->getElementsByTagName('name')->item(0)->nodeValue)); $root->appendChild($this->definition->createElement('uninstall', 'cms.base.installer:remove')); $this->definition->appendChild($root); $dir = SPLoader::dirPath('etc.installed.' . $type . 's', 'front', false); if (!SPFs::exists($dir)) { SPFs::mkdir($dir); } $path = $dir . '/' . $this->id . '.xml'; $file = SPFactory::Instance('base.fs.file', $path); $this->definition->normalizeDocument(); $file->content($this->definition->saveXML()); $file->save(); $this->storeData($type, $def); } return array('msg' => $msg, 'msgtype' => SPC::SUCCESS_MSG); } catch (Exception $x) { $this->error = Sobi::Txt('CMS_EXT_NOT_INSTALLED') . ' ' . $x->getMessage(); $this->errorType = SPC::ERROR_MSG; return array('msg' => $this->error, 'msgtype' => SPC::ERROR_MSG); } }
private function renderButton($button, $list = false) { $rel = null; $onclick = null; $title = ''; $class = isset($button['class']) ? ' ' . $button['class'] : null; if (isset($button['type']) && $button['type'] == 'url') { $rel = null; $href = $this->getLink($button); } elseif (!isset($button['task']) || !$button['task']) { $href = $this->getLink($button); } else { $rel = $button['task']; $href = '#'; } if (!isset($button['label']) || !$button['label']) { $label = $this->getLabel($button); } else { $label = $button['label']; } if (isset($button['confirm'])) { $title = ' title="' . Sobi::Txt($button['confirm']) . '" '; } if ($button['element'] == 'button-legacy') { $class .= ' legacy'; $onclick = 'onclick="Joomla.submitform(\'' . $rel . '\');"'; // damn SqueezeBox - download field license window $rel = null; } $target = isset($button['target']) && $button['target'] ? " target=\"{$button['target']}\"" : null; if (isset($button['buttons']) && count($button['buttons'])) { $this->output[] = '<div class="btn-group">'; $this->output[] = "<a href=\"{$href}\" class=\"{$this->btClass}{$class}\"{$target} rel=\"{$rel}\">"; if (!(isset($button['icon']) && $button['icon'])) { $icon = $this->getIcon($button, true); } else { $icon = $button['icon']; } $this->output[] = '<i class="icon-' . $icon . '"></i> ' . $label; $this->output[] = '</a>'; $this->output[] = '<button class="' . $this->btClass . ' dropdown-toggle" data-toggle="dropdown"><span class="icon-caret-down"></span> </button>'; $this->output[] = '<div class="dropdown-menu" id="spmenu-' . SPLang::nid($button['task']) . '">'; $this->output[] = '<ul class="nav nav-stacked SpDropDownBt">'; foreach ($button['buttons'] as $bt) { $this->renderButton($bt, true); } $this->output[] = '</ul>'; $this->output[] = '</div>'; $this->output[] = '</div>'; } elseif (!$list) { $this->output[] = "<a href=\"{$href}\" rel=\"{$rel}\" class=\"{$this->btClass}{$class}\"{$target}{$onclick}{$title}>"; if (!(isset($button['icon']) && $button['icon'])) { $icon = $this->getIcon($button); } else { $icon = $button['icon']; } $this->output[] = '<i class="icon-' . $icon . '"></i> ' . $label; $this->output[] = '</a>'; } else { if ($button['element'] == 'nav-header') { $this->output[] = '<li class="nav-header">' . $button['label'] . '</li>'; } else { $this->output[] = '<li><a href="' . $href . '"' . $target . $title . ' rel="' . $rel . '">'; if (!(isset($button['icon']) && $button['icon'])) { $icon = $this->getIcon($button); } else { $icon = $button['icon']; } if (isset($button['selected'])) { if (!$button['selected']) { $icon = $this->icons['not-selected']; } else { $icon = $this->icons['selected']; // $this->output[ ] = '<i class="icon-' . $this->icons[ 'selected' ] . '"></i> '; } } $this->output[] = '<i class="icon-' . $icon . '"></i> ' . $label; $this->output[] = '</a></li>'; } } }
/** * @param DOMNode $node * @param array $element * @param mixed $value * @param bool $skipCondition * @param null $subject * @param $i * @return void */ protected function xmlField($node, &$element, $value = null, $skipCondition = false, $subject = null, $i = -1) { if (!$skipCondition && !$this->xmlCondition($node)) { return; } if (SPRequest::task() == 'entry.edit' && SPRequest::cmd('revision') && isset($element['attributes']['name'])) { $i = str_replace('entry.', null, $element['attributes']['name']); if (isset($this->_attr['revision'][$i])) { $element['revisions-change'] = $element['attributes']['name']; } } /** process all attributes */ $attributes = $node->attributes; $params = array(); $args = array('type' => null, 'name' => null, 'value' => $value); $adds = array('before' => null, 'after' => null); $xml = array(); if ($attributes->length) { /** @var DOMElement $attribute */ foreach ($attributes as $attribute) { $xml[$attribute->nodeName] = $attribute->nodeValue; switch ($attribute->nodeName) { case 'name': $args['id'] = SPLang::nid($attribute->nodeValue); $element['id'] = $args['id']; $params['id'] = $args['id']; case 'name': case 'type': case 'width': case 'height': case 'prefix': $args[$attribute->nodeName] = $attribute->nodeValue; break; case 'editor': case 'multi': $args[$attribute->nodeName] = $attribute->nodeValue == 'true' ? true : false; break; case 'selected': /** if it is being called from a loop, we have to try it that way first */ if (strlen($subject)) { $args[$attribute->nodeName] = $this->get($subject . '.' . $attribute->nodeValue, $i); if ($args[$attribute->nodeName]) { break; } } case 'value': if ($value) { break; } /** no break here */ /** no break here */ case 'values': $args[$attribute->nodeName] = $this->get($attribute->nodeValue); break; case 'value-parsed': $args['value'] = $attribute->nodeValue; break; case 'value-text': $args['value'] = Sobi::Txt($attribute->nodeValue); break; case 'label': case 'header': $element[$attribute->nodeName] = Sobi::Txt($attribute->nodeValue); $args[$attribute->nodeName] = Sobi::Txt($attribute->nodeValue); break; case 'placeholder': $params[$attribute->nodeName] = Sobi::Txt($attribute->nodeValue); break; default: if (strstr($attribute->nodeValue, 'var:[')) { $params[$attribute->nodeName] = $this->parseValue($attribute->nodeValue); } else { $params[$attribute->nodeName] = $attribute->nodeValue; } $args[$attribute->nodeName] = $params[$attribute->nodeName]; break; } } } if ($node->hasChildNodes()) { foreach ($node->childNodes as $child) { if (strstr($child->nodeName, '#')) { continue; } /** @var DOMNode $child */ switch ($child->nodeName) { case 'values': if ($child->childNodes->length) { $values = array(); /** @var DOMNode $value */ foreach ($child->childNodes as $value) { if (strstr($value->nodeName, '#')) { continue; } /** select list with groups e.g. */ if ($value->nodeName == 'values') { $group = array(); if ($value->hasChildNodes()) { foreach ($value->childNodes as $groupNode) { if (strstr($groupNode->nodeName, '#')) { continue; } $group[$groupNode->attributes->getNamedItem('value')->nodeValue] = Sobi::Txt($groupNode->attributes->getNamedItem('label')->nodeValue); } } $values[Sobi::Txt($value->attributes->getNamedItem('label')->nodeValue)] = $group; } else { $vv = $value->attributes->getNamedItem('value')->nodeValue; $vl = $value->attributes->getNamedItem('label') ? $value->attributes->getNamedItem('label')->nodeValue : $vv; $xml['childs'][$child->nodeName][$vv] = $vl; $values[$vv] = Sobi::Txt($vl); } } } $args['values'] = $values; break; case 'value': if ($child->childNodes->length) { /** @var DOMNode $value */ foreach ($child->childNodes as $value) { if (strstr($value->nodeName, '#')) { continue; } switch ($value->nodeName) { case 'url': $params = array(); $content = 'no content given'; foreach ($value->attributes as $a) { switch ($a->nodeName) { case 'type': case 'host': break; case 'content': $v = $this->get(trim($a->nodeValue)); if (!$v) { $v = Sobi::Txt(trim($a->nodeValue)); } $content = $v; break; case 'uri': $params['href'] = $this->get(trim($a->nodeValue)); default: $params[$a->nodeName] = $a->nodeValue; break; } } if (!isset($params['href'])) { $params['href'] = $this->xmlUrl($value); } $link = '<a '; foreach ($params as $k => $v) { $link .= $k . '="' . $v . '" '; } $link .= '>' . $content . '</a>'; $args['value'] = $link; break; } } } break; case 'attribute': $name = $child->attributes->getNamedItem('name')->nodeValue; $value = $this->get($child->attributes->getNamedItem('value')->nodeValue); if (in_array($name, array('disabled', 'readonly')) && !$value) { continue; } if ($name == 'label') { $element[$name] = $value; } else { $params[$name] = $value; $args[$name] = $value; } break; case 'add': if ($child->childNodes->length) { /** @var DOMNode $value */ foreach ($child->childNodes as $value) { if (strstr($value->nodeName, '#')) { continue; } if ($value->nodeName == 'call') { $v = $this->xmlCall($value); } elseif ($value->nodeName == 'text') { $v = $value->nodeValue; } elseif ($value->nodeName == 'button') { $v = $this->xmlButton($value); } $adds[$child->attributes->getNamedItem('where')->nodeValue][] = $v; } } break; } } } $args['params'] = $params; $element['args'] = $args; $element['adds'] = $adds; $element['request'] = $xml; switch ($args['type']) { case 'output': $content = $this->get($args['value']); $element['content'] = strlen($content) ? $content : $args['value']; $element['attributes']['attributes'] = $element['content']; break; case 'custom': $field = $this->get($args['fid']); if ($field && $field instanceof SPField) { $element['label'] = $field->get('name'); if (count($params)) { foreach ($params as $k => $p) { if ($k == 'class') { $k = 'cssClass'; } $field->set($k, $p); } } $element['content'] = $field->field(true); } break; default: if (method_exists('SPHtml_input', $args['type'])) { $method = new ReflectionMethod('SPHtml_input', $args['type']); $methodArgs = array(); $methodParams = $method->getParameters(); foreach ($methodParams as $param) { if (isset($args[$param->name])) { $methodArgs[] = $args[$param->name]; } elseif ($param->name == 'value' && !isset($args['value']) && isset($args['name'])) { $methodArgs[] = $this->get($args['name']); } elseif ($param->isDefaultValueAvailable()) { $methodArgs[] = $param->getDefaultValue(); } else { $methodArgs[] = null; } } $element['content'] = call_user_func_array(array('SPHtml_input', $args['type']), $methodArgs); } else { Sobi::Error($this->name(), SPLang::e('METHOD_DOES_NOT_EXISTS', $args['type']), SPC::WARNING, 0, __LINE__, __FILE__); } break; } }
public function addNewRule($name, $sections, $perms, $groups, $note = null) { SPLoader::loadClass('cms.base.users'); $db =& SPFactory::db(); try { $db->insertUpdate('spdb_permissions_rules', array('rid' => 'NULL', 'name' => $name, 'nid' => SPLang::nid($name), 'validSince' => $db->getNullDate(), 'validUntil' => $db->getNullDate(), 'note' => $note, 'state' => 1)); $rid = $db->insertid(); } catch (SPException $x) { Sobi::Error('ACL', SPLang::e('CANNOT_CREATE_RULE_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } $affectedGroups = array(); $gids = SPUser::availableGroups(); foreach ($gids as $id => $group) { if (in_array($group, $groups) || in_array(strtolower($group), $groups)) { $affectedGroups[] = array('rid' => $rid, 'gid' => $id); } } try { $db->insertArray('spdb_permissions_groups', $affectedGroups); } catch (SPException $x) { Sobi::Error('ACL', SPLang::e('CANNOT_INSERT_GROUPS_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } if (!count($this->_perms)) { $this->loadPermissions(); } $map = array(); foreach ($perms as $perm) { $perm = explode('.', $perm); $pid = $db->select('pid', 'spdb_permissions', array('subject' => $perm[0], 'action' => $perm[1], 'value' => $perm[2]))->loadResult(); if ($pid) { foreach ($sections as $sid) { $map[] = array('rid' => $rid, 'sid' => $sid, 'pid' => $pid); } } } if (count($map)) { try { $db->insertArray('spdb_permissions_map', $map, true); } catch (SPException $x) { Sobi::Error('ACL', SPLang::e('CANNOT_INSERT_GROUPS_DB_ERR', $x->getMessage()), SPC::WARNING, 0, __LINE__, __FILE__); } } return $rid; }
/** * Save existing field */ protected function save($clone = false) { $sets = array(); if (!SPFactory::mainframe()->checkToken()) { Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__); } $fid = SPRequest::int('fid'); $field = SPFactory::Model('field', true); if ($fid) { $f = $this->loadField($fid); $field->extend($f); } else { $field->loadType(SPRequest::cmd('field_fieldType')); } $nid = SPRequest::cmd('field_nid'); if (!$nid || !strstr($nid, 'field_')) { /** give me my spaces back!!! */ $nid = strtolower(str_replace('-', '_', SPLang::nid('field_' . SPRequest::string('field_name')))); SPRequest::set('field_nid', $nid); } $this->getRequest(); $this->validate($field); if ($clone || !$fid) { try { $fid = $field->saveNew($this->attr); $field->save($this->attr); } catch (SPException $x) { $this->response(Sobi::Url(array('task' => 'field.edit', 'fid' => $fid, 'sid' => SPRequest::sid())), $x->getMessage(), false, SPC::ERROR_MSG); } } else { try { $field->save($this->attr); } catch (SPException $x) { $this->response(Sobi::Url(array('task' => 'field.edit', 'fid' => $fid, 'sid' => SPRequest::sid())), $x->getMessage(), false, SPC::ERROR_MSG); } } $alias = $field->get('nid'); $fieldSets = $field->get('sets'); if (is_array($fieldSets) && count($fieldSets)) { $sets = array_merge($fieldSets, $sets); } $sets['fid'] = $field->get('fid'); $sets['field.nid'] = $alias; /* in case we are changing the sort by field */ if (Sobi::Cfg('list.entries_ordering') == $alias && $field->get('nid') != $alias) { SPFactory::config()->saveCfg('list.entries_ordering', $field->get('nid')); } SPFactory::cache()->cleanSection(); if ($this->_task == 'apply' || $clone) { if ($clone) { $msg = Sobi::Txt('FM.FIELD_CLONED'); $this->response(Sobi::Url(array('task' => 'field.edit', 'fid' => $fid, 'sid' => SPRequest::sid())), $msg); } else { $msg = Sobi::Txt('MSG.ALL_CHANGES_SAVED'); $this->response(Sobi::Url(array('task' => 'field.edit', 'fid' => $fid, 'sid' => SPRequest::sid())), $msg, false, 'success', array('sets' => $sets)); } } else { $this->response(Sobi::Back(), Sobi::Txt('MSG.ALL_CHANGES_SAVED')); } }
/** * @param $categories * @param $sid * @return void */ private function categories($categories, $sid) { for ($i = 0; $i < $categories->length; $i++) { $category = $categories->item($i); if ($category->nodeName == 'category') { $name = $this->txt($category, 'name'); $introtext = $this->txt($category, 'introtext'); $description = $this->txt($category, 'description'); $icon = $this->txt($category, 'icon'); $cat = SPFactory::Model('category'); $cat->set('state', 1); /* Additional data */ $options = $category->getElementsByTagName('option'); if ($options instanceof DOMNodeList && $options->length) { foreach ($options as $option) { $v = $option->nodeValue; if (in_array($option->nodeValue, array('true', 'false'))) { $v = $option->nodeValue == 'true' ? true : false; } $cat->set($option->getAttribute('attribute'), $v); } } /* Base category data */ $cat->set('description', $description); $cat->set('name', $name); $cat->set('nid', SPLang::nid($name)); $cat->set('introtext', $introtext); $cat->set('parent', $sid); $cat->set('icon', $icon); /* save the category */ $cat->save(); /* Handle subcats */ $childs = $this->xdef->query("childs/category", $category); if ($childs && $childs->length) { if ($childs instanceof DOMNodeList && $childs->length) { $this->categories($childs, $cat->get('id')); } } } } }
/** * @param string $subject * @param string $col * @param string $def * @return string */ protected function parseOrdering($subject, $col, $def) { return Sobi::GetUserState($subject . '.ordering.' . SPLang::nid(Sobi::Section(true)), $col, $def); }
private function cloneTpl() { $dir = $this->dir(SPRequest::cmd('templateName')); $newName = SPRequest::word('templateNewName', 'Duplicated Template', 'post'); $dirName = SPLang::nid($newName); $dirNameOrg = $dirName; $c = 1; while (SPFs::exists(SPLoader::dirPath('usr.templates.' . $dirName, 'front', false))) { $dirName = $dirNameOrg . '-' . $c++; } $newPath = SPLoader::dirPath('usr.templates.' . $dirName, 'front', false); if (!SPFs::copy($dir, $newPath)) { throw new SPException(SPLang::e('COULD_NOT_COPY_DIRECTORY', $dir, $newPath)); } $defFile = SPLoader::path($newPath . '.template', 'absolute', true, 'xml'); if ($defFile) { $fc = SPLoader::loadClass('base.fs.file'); $def = new DOMDocument(); $def->load($defFile); $xdef = new DOMXPath($def); $oldName = $xdef->query('/template/name')->item(0)->nodeValue; $oldDesc = $xdef->query('/template/description')->item(0)->nodeValue; $date = SPFactory::config()->date(time()); $xdef->query('/template/name')->item(0)->nodeValue = $newName; $xdef->query('/template/creationDate')->item(0)->nodeValue = $date; $xdef->query('/template/id')->item(0)->nodeValue = $dirName; $newDesc = Sobi::Txt('TP.CLONE_NOTE', array('name' => $oldName, 'date' => $date)); $xdef->query('/template/description')->item(0)->nodeValue = "{$newDesc}\n{$oldDesc}"; $file = new $fc($defFile); $file->content($def->saveXML()); $file->save(); } $this->response(Sobi::Url(array('task' => 'template.info', 'template' => str_replace(SOBI_PATH . DS . 'usr' . DS . 'templates' . DS, null, $dirName))), Sobi::Txt('TP.DUPLICATED'), false, 'success'); }
/** * (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(); $clone = SPRequest::task() == 'entry.clone'; if (!$this->nid || $clone) { $this->nid = strtolower(SPLang::nid(SPRequest::string($this->nameField, null, false, $request))); $this->nid = $this->createAlias(); /** Thu, Jul 30, 2015 12:15:25 - what the hell was that? */ // $this->name = $this->nid; } if (!$this->id && 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, $clone); } else { $field->finaliseSave($this, $request, $clone); } 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 parseName($entry, $name, $pattern, $addExt = false) { $nameArray = explode('.', $name); $ext = strtolower(array_pop($nameArray)); $name = implode('.', $nameArray); $user = SPUser::getBaseData((int) $entry->get('owner')); // @todo change to the global method $placeHolders = array('/{id}/', '/{orgname}/', '/{entryname}/', '/{oid}/', '/{ownername}/', '/{uid}/', '/{username}/', '/{nid}/'); $replacements = array($entry->get('id'), $name, $entry->get('nid'), isset($user->id) ? $user->id : null, isset($user->name) ? SPLang::nid($user->name) : 'guest', Sobi::My('id'), SPLang::nid(Sobi::My('name')), $this->nid); $fileName = preg_replace($placeHolders, $replacements, $pattern); return $addExt ? $fileName . '.' . $ext : $fileName; }
protected function saveRejectionTpl() { if (!SPFactory::mainframe()->checkToken()) { Sobi::Error('Token', SPLang::e('UNAUTHORIZED_ACCESS_TASK', SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__); } $templates = $this->getRejectionsTemplates(); $id = SPLang::nid(SPRequest::string('templateName')); $templates[$id] = array('params' => SPConfig::serialize(array('trigger.unpublish' => SPRequest::bool('trigger_unpublish'), 'trigger.unapprove' => SPRequest::bool('trigger_unapprove'), 'unpublish' => SPRequest::bool('unpublish'), 'discard' => SPRequest::bool('discard'))), 'key' => $id, 'value' => SPRequest::string('templateName'), 'options' => array()); foreach ($templates as $tid => $template) { unset($templates[$tid]['description']); } SPFactory::registry()->saveDBSection($templates, 'rejections-templates_' . Sobi::Section()); $data = array('key' => $id, 'value' => SPRequest::string('reason', null, true, 'post'), 'type' => 'rejections-templates', 'id' => Sobi::Section(), 'section' => Sobi::Section(), 'options' => SPRequest::string('templateName')); SPLang::saveValues($data); $this->response(Sobi::Back(), Sobi::Txt('ENTRY_REJECT_SAVED_TPL'), false, SPC::SUCCESS_MSG); }
public function renderButton($button, $list = false) { $rel = null; $class = isset($button['class']) ? ' ' . $button['class'] : null; if (!isset($button['task']) || !$button['task']) { $href = null; $rel = null; } else { $rel = $button['task']; $href = null; } $label = $button['label']; $target = isset($button['target']) && $button['target'] ? " target=\"{$button['target']}\"" : null; if (isset($button['buttons']) && count($button['buttons'])) { $this->_out[] = '<div class="btn-group">'; $this->_out[] = "<a href=\"{$href}\" class=\"btn{$class}\"{$target} rel=\"{$rel}\">"; if (!(isset($button['icon']) && $button['icon'])) { $icon = 'cog'; } else { $icon = $button['icon']; } if ($icon != 'none') { $this->_out[] = '<i class="icon-' . $icon . '"></i> ' . $label; } else { $this->_out[] = ' ' . $label; } $this->_out[] = '</a>'; $this->_out[] = '<button class="btn dropdown-toggle" data-toggle="dropdown"><span class="icon-caret-down"></span> </button>'; $this->_out[] = '<div class="dropdown-menu" id="' . SPLang::nid($button['task']) . '">'; $this->_out[] = '<ul class="nav nav-stacked SpDropDownBt">'; foreach ($button['buttons'] as $bt) { $this->renderButton($bt, true); } $this->_out[] = '</ul>'; $this->_out[] = '</div>'; $this->_out[] = '</div>'; } elseif (!$list) { if ($rel || $href) { $this->_out[] = "<a href=\"{$href}\" rel=\"{$rel}\" class=\"btn{$class}\"{$target}>"; } else { if (isset($button['rel'])) { $r = " rel=\"{$button['rel']}\" "; } $this->_out[] = "<div class=\"btn{$class}\"{$r}{$target}>"; } if (!(isset($button['icon']) && $button['icon'])) { $icon = 'cog'; } else { $icon = $button['icon']; } $this->_out[] = ' <i class="icon-' . $icon . '"></i> ' . $label; if ($rel || $href) { $this->_out[] = '</a>'; } else { $this->_out[] = '</div>'; } } else { if ($button['element'] == 'nav-header') { $this->_out[] = '<li class="nav-header">' . $button['label'] . '</li>'; } else { $this->_out[] = '<li><a href="' . $href . $target . '" rel="' . $rel . '">'; if (!(isset($button['icon']) && $button['icon'])) { $icon = 'cog'; } else { $icon = $button['icon']; } $this->_out[] = '<i class="icon-' . $icon . '"></i> ' . $label; $this->_out[] = '</a></li>'; } } }
/** */ public function save($request = 'post') { $this->version++; /* get current data */ $this->updatedTime = SPRequest::now(); $this->updaterIP = SPRequest::ip('REMOTE_ADDR', 0, 'SERVER'); $this->updater = Sobi::My('id'); $this->nid = SPLang::nid($this->nid, true); if (!$this->nid) { $this->nid = SPLang::nid($this->name, true); } /* get THIS class properties */ $properties = get_class_vars(__CLASS__); /* if new object */ if (!$this->id) { /** @var the notification App is using it to recognise if it is a new entry or an update */ $this->createdTime = $this->updatedTime; $this->owner = $this->owner ? $this->owner : $this->updater; $this->ownerIP = $this->updaterIP; } else { /** Fri, Dec 19, 2014 19:33:52 * When storing it we should actually get already UTC unix time stamp * so there is not need to remove it again */ // $this->createdTime = $this->createdTime && is_numeric( $this->createdTime ) ? gmdate( Sobi::Cfg( 'db.date_format', 'Y-m-d H:i:s' ), $this->createdTime - SPFactory::config()->getTimeOffset() ) : $this->createdTime; $this->createdTime = $this->createdTime && is_numeric($this->createdTime) ? gmdate(Sobi::Cfg('db.date_format', 'Y-m-d H:i:s'), $this->createdTime) : $this->createdTime; $obj = SPFactory::object($this->id); if ($obj->oType != $this->oType) { Sobi::Error('Object Save', sprintf('Serious security violation. Trying to save an object which claims to be an %s but it is a %s. Task was %s', $this->oType, $obj->oType, SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__); exit; } } if (is_numeric($this->validUntil)) { // $this->validUntil = $this->validUntil ? gmdate( Sobi::Cfg( 'db.date_format', 'Y-m-d H:i:s' ), $this->validUntil - SPFactory::config()->getTimeOffset() ) : null; $this->validUntil = $this->validUntil ? gmdate(Sobi::Cfg('db.date_format', 'Y-m-d H:i:s'), $this->validUntil) : null; } if (is_numeric($this->validSince)) { $this->validSince = $this->validSince ? gmdate(Sobi::Cfg('db.date_format', 'Y-m-d H:i:s'), $this->validSince) : null; } /* @var SPdb $db */ $db = SPFactory::db(); $db->transaction(); /* get database columns and their ordering */ $cols = $db->getColumns('spdb_object'); $values = array(); /* * @todo: manage own is not implemented yet */ //$this->approved = Sobi::Can( $this->type(), 'manage', 'own' ); /* if not published, check if user can manage own and if yes, publish it */ if (!$this->state && !defined('SOBIPRO_ADM')) { $this->state = Sobi::Can($this->type(), 'publish', 'own'); } if (!defined('SOBIPRO_ADM')) { $this->approved = Sobi::Can($this->type(), 'publish', 'own'); } // elseif ( defined( 'SOBIPRO_ADM' ) ) { // $this->approved = Sobi::Can( $this->type(), 'publish', 'own' ); // } /* and sort the properties in the same order */ foreach ($cols as $col) { $values[$col] = array_key_exists($col, $properties) ? $this->{$col} : ''; } /* trigger plugins */ Sobi::Trigger('save', $this->name(), array(&$this)); /* try to save */ try { /* if new object */ if (!$this->id) { $db->insert('spdb_object', $values); $this->id = $db->insertid(); } else { $db->update('spdb_object', $values, array('id' => $this->id)); } } catch (SPException $x) { $db->rollback(); Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_OBJECT_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } /* get translatable properties */ $attributes = array_merge($this->translatable(), self::$translatable); $labels = array(); $defLabels = array(); foreach ($attributes as $attr) { if ($this->has($attr)) { $labels[] = array('sKey' => $attr, 'sValue' => $this->{$attr}, 'language' => Sobi::Lang(), 'id' => $this->id, 'oType' => $this->type(), 'fid' => 0); if (Sobi::Lang() != Sobi::DefLang()) { $defLabels[] = array('sKey' => $attr, 'sValue' => $this->{$attr}, 'language' => Sobi::DefLang(), 'id' => $this->id, 'oType' => $this->type(), 'fid' => 0); } } } /* save translatable properties */ if (count($labels)) { try { if (Sobi::Lang() != Sobi::DefLang()) { $db->insertArray('spdb_language', $defLabels, false, true); } $db->insertArray('spdb_language', $labels, true); } catch (SPException $x) { Sobi::Error($this->name(), SPLang::e('CANNOT_SAVE_OBJECT_DB_ERR', $x->getMessage()), SPC::ERROR, 500, __LINE__, __FILE__); } } $db->commit(); $this->checkIn(); }