public function saveToken($token) { $arrdef = SPFactory::Instance('types.array'); $def = $arrdef->fromXML($this->definition, 'repository'); $ndef = array(); $u = false; $rid = null; foreach ($def['repository'] as $k => $v) { if ($u) { $ndef['token'] = $token; } if ($k == 'id') { $rid = $v; } if ($k == 'url') { $u = true; } $ndef[$k] = $v; } $path = SPLoader::path("etc.repos.{$rid}.repository", 'front', true, 'xml'); $file = SPFactory::Instance('base.fs.file', $path); $xdef = SPFactory::Instance('types.array'); $file->content($xdef->toXML($ndef, 'repository')); $file->save(); }
public function __construct() { $ident = SPRequest::cmd('session') ? SPRequest::cmd('ProgressMsg' . SPRequest::cmd('session'), null, 'cookie') : SPRequest::cmd('ProgressMsg', null, 'cookie'); $this->file = SPLoader::path('tmp.' . $ident, 'front', false, 'tmp'); if (SPFs::exists($this->file)) { $content = json_decode(SPFs::read($this->file), true); $this->message = $content['message']; $this->type = $content['type']; $this->progress = $content['progress']; $this->interval = $content['interval']; } }
public function validate() { $type = $this->type == 'SobiProApp' ? 'application' : $this->type; $schemaDef = SPLoader::path('lib.services.installers.schemas.' . $type, 'front', false, 'xsd'); if (!SPFs::exists($schemaDef) || time() - filemtime($schemaDef) > 60 * 60 * 24 * 7) { $connection = SPFactory::Instance('services.remote'); $def = "https://xml.sigsiu.net/SobiPro/{$type}.xsd"; $connection->setOptions(array('url' => $def, 'connecttimeout' => 10, 'header' => false, 'returntransfer' => true, 'ssl_verifypeer' => false, 'ssl_verifyhost' => 2)); $schema =& SPFactory::Instance('base.fs.file', SPLoader::path('lib.services.installers.schemas.' . $type, 'front', false, 'xsd')); $file = $connection->exec(); if (!strlen($file)) { throw new SPException(SPLang::e('CANNOT_ACCESS_SCHEMA_DEF', $def)); } $schema->content($file); $schema->save(); $schemaDef = $schema->filename(); } if (!$this->definition->schemaValidate($schemaDef)) { throw new SPException(SPLang::e('CANNOT_VALIDATE_SCHEMA_DEF_AT', str_replace(SOBI_ROOT . DS, null, $this->xmlFile), $def)); } }
private function screen() { $view =& SPFactory::View('view', true); $view->setTemplate('config.help'); if (SPLoader::path('etc.repos.sobipro_core.repository', 'front', true, 'xml')) { $repository = SPFactory::Instance('services.installers.repository'); $repository->loadDefinition(SPLoader::path("etc.repos.sobipro_core.repository", 'front', true, 'xml')); try { $repository->connect(); } catch (SPException $x) { $view->assign(SPLang::e('REPO_ERR', $x->getMessage()), 'message'); } try { $response = $repository->help($repository->get('token'), SPRequest::cmd('mid')); $view->assign($response, 'message'); } catch (SPException $x) { $view->assign(SPLang::e('REPO_ERR', $x->getMessage()), 'message'); } } else { $view->assign(Sobi::Txt('MSG.HELP_ADD_CORE_REPO'), 'message'); } $view->display(); }
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; }
protected function listTemplates($tpl = null, $cmsOv = true) { SPFactory::header()->addJsFile('dtree')->addCssFile('dtree', true); SPLoader::loadClass('base.fs.directory_iterator'); $ls = Sobi::Cfg('live_site') . 'media/sobipro/tree'; $nodes = null; $count = 0; $tpl = Sobi::FixPath($tpl ? $tpl : SPLoader::dirPath('usr.templates')); if (Sobi::Section()) { $realName = Sobi::Txt('TP.INFO'); $iTask = Sobi::Url(array('task' => 'template.info', 'template' => basename($tpl), 'sid' => Sobi::Section())); $nodes .= "spTpl.add( -123, 0,'{$realName}','{$iTask}', '', '', '{$ls}/info.png' );\n"; if (file_exists("{$tpl}/config.xml")) { $realName = Sobi::Txt('TP.SETTINGS'); $iTask = Sobi::Url(array('task' => 'template.settings', 'template' => basename($tpl), 'sid' => Sobi::Section())); $nodes .= "spTpl.add( -120, 0,'{$realName}','{$iTask}', '', '', '{$ls}/settings.png' );\n"; } } $this->travelTpl(new SPDirectoryIterator($tpl), $nodes, 0, $count); if ($cmsOv) { $cms = SPFactory::CmsHelper()->templatesPath(); if (is_array($cms) && isset($cms['name']) && isset($cms['data']) && is_array($cms['data']) && count($cms['data'])) { $count++; if (isset($cms['icon'])) { $nodes .= "spTpl.add( {$count}, 0, '{$cms['name']}', '', '', '', '{$cms['icon']}', '{$cms['icon']}' );\n"; } else { $nodes .= "spTpl.add( {$count}, 0, '{$cms['name']}' );\n"; } $current = $count; foreach ($cms['data'] as $name => $path) { $count++; $nodes .= "spTpl.add( {$count}, {$current},'{$name}' );\n"; $this->travelTpl(new SPDirectoryIterator($path), $nodes, $count, $count, true); } } } if (Sobi::Section()) { $file = SPLoader::path('usr.templates.' . Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE) . '.template', 'front', true, 'xml'); $def = new DOMDocument(); $def->load($file); $xdef = new DOMXPath($def); $t = $xdef->query('/template/name')->item(0)->nodeValue; } else { $t = Sobi::Txt('GB.TEMPLATES'); } SPFactory::header()->addJsCode("\n\t\t\ticons = {\n\t\t\t\t\t\troot : '{$ls}/base.gif',\n\t\t\t\t\t\tfolder : '{$ls}/folder.gif',\n\t\t\t\t\t\tfolderOpen : '{$ls}/folderopen.gif',\n\t\t\t\t\t\tnode : '{$ls}/page.gif',\n\t\t\t\t\t\tempty : '{$ls}/empty.gif',\n\t\t\t\t\t\tline : '{$ls}/line.gif',\n\t\t\t\t\t\tjoin : '{$ls}/join.gif',\n\t\t\t\t\t\tjoinBottom : '{$ls}/joinbottom.gif',\n\t\t\t\t\t\tplus : '{$ls}/plus.gif',\n\t\t\t\t\t\tplusBottom : '{$ls}/plusbottom.gif',\n\t\t\t\t\t\tminus : '{$ls}/minus.gif',\n\t\t\t\t\t\tminusBottom\t: '{$ls}/minusbottom.gif',\n\t\t\t\t\t\tnlPlus : '{$ls}/nolines_plus.gif',\n\t\t\t\t\t\tnlMinus : '{$ls}/nolines_minus.gif'\n\t\t\t};\n\t\t\tvar spTpl = new dTree( 'spTpl', icons );\t\n\n\t\t\tSobiPro.jQuery( document ).ready( function ()\n\t\t\t{\n\t\t\t\tspTpl.add(0, -1, '{$t}' );\n\n\t\t\t\t{$nodes} \n\n\t\t\t\ttry { document.getElementById( 'spTpl' ).innerHTML = spTpl } catch( e ) {}\n\t\t\t} );\n\t\t"); /** for some reason jQuery is not able to add the tree */ return "<div id=\"spTpl\"></div>"; }
protected function templatePath($tpl) { $file = explode('.', $tpl); if (strstr($file[0], 'cms:')) { $file[0] = str_replace('cms:', null, $file[0]); $file = SPFactory::mainframe()->path(implode('.', $file)); $template = SPLoader::path($file, 'root', false, null); } else { $template = SOBI_PATH . '/usr/templates/' . str_replace('.', '/', $tpl); } return $template; }
/** */ public function storeView($head) { if (!Sobi::Cfg('cache.xml_enabled') || $this->_cachedView || Sobi::My('id') && Sobi::Cfg('cache.xml_no_reg')) { return false; } if ($this->view['xml']) { $xml = $this->view['xml']; $template = Sobi::Reg('cache_view_template'); if (!$template) { $template = $this->view['template']; $template = str_replace(SPLoader::translateDirPath(Sobi::Cfg('section.template'), 'templates'), null, $template); } $root = $xml->documentElement; $root->removeChild($root->getElementsByTagName('visitor')->item(0)); if ($root->getElementsByTagName('messages')->length) { $root->removeChild($root->getElementsByTagName('messages')->item(0)); } /** @var $header DOMDocument */ $header = SPFactory::Instance('types.array')->toXML($head, 'header', true); $root->appendChild($xml->importNode($header->documentElement, true)); if ($this->view['data'] && count($this->view['data'])) { $data = SPFactory::Instance('types.array')->toXML($this->view['data'], 'cache-data', true); $root->appendChild($xml->importNode($data->documentElement, true)); } $request = $this->viewRequest(); $request['template'] = $template; $configFiles = SPFactory::registry()->get('template_config'); $request['configFile'] = str_replace('"', "'", json_encode($configFiles)); $request['cid'] = 'NULL'; $request['created'] = 'FUNCTION:NOW()'; $fileName = md5(serialize($request)); $request['fileName'] = $fileName; $filePath = SPLoader::path('var.xml.' . $fileName, 'front', false, 'xml'); $content = $xml->saveXML(); $content = str_replace(' ', ' ', $content); $content = preg_replace('/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u', null, $content); $matches = array(); preg_match_all('/<(category|entry|subcategory)[^>]*id="(\\d{1,})"/', $content, $matches); try { $cid = SPFactory::db()->insert('spdb_view_cache', $request, false, true)->insertid(); $relations = array(SPRequest::sid() => array('cid' => $cid, 'sid' => SPRequest::sid())); if (isset($matches[2])) { $ids = array_unique($matches[2]); foreach ($ids as $sid) { $relations[$sid] = array('cid' => $cid, 'sid' => $sid); } } SPFactory::db()->insertArray('spdb_view_cache_relation', $relations); SPFs::write($filePath, $content); } catch (SPException $x) { Sobi::Error('XML-Cache', $x->getMessage()); } } }
/** * */ 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()); }
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; }
private function store($key, $value, $msg = null) { // let's try to create kinda mutex here $file = SPLoader::path('tmp.info', 'front', false, 'txt'); while (SPFs::exists($file)) { usleep(100000); } $c = date(DATE_RFC822); SPFs::write($file, $c); $store = Sobi::GetUserData('requirements', array()); $store[$key] = array('value' => $value, 'message' => $msg); Sobi::SetUserData('requirements', $store); SPFs::delete($file); // $msg = $msg ? $msg[ 'org' ][ 'label' ] : null; // $file = SPLoader::path( 'tmp.info', 'front', false, 'txt' ); // $cont = null; // if ( SPFs::exists( $file ) ) { // $cont = SPFs::read( $file ); // } // $txt = "{$cont}\n{$key}={$msg};{$value}"; // SPFs::write( $file, $txt ); }
/** * */ public function display() { $tpl = SPLoader::path($this->_template . '_override', 'adm.template'); if (!$tpl) { $tpl = SPLoader::path($this->_template, 'adm.template'); } if (!$tpl) { $tpl = SPLoader::translatePath($this->_template, 'adm.template', false); Sobi::Error($this->name(), SPLang::e('TEMPLATE_DOES_NOT_EXISTS', $tpl), SPC::ERROR, 500, __LINE__, __FILE__); exit; } Sobi::Trigger('Display', $this->name(), array(&$this)); $action = $this->key('action'); echo "\n<!-- SobiPro output -->\n"; echo '<div class="SobiPro" id="SobiPro">' . "\n"; if ($this->_legacy) { echo SPFactory::AdmToolbar()->render(); echo $this->legacyMessages(); echo '<div class="row-fluid">' . "\n"; } echo $action ? "\n<form action=\"{$action}\" method=\"post\" name=\"adminForm\" id=\"SPAdminForm\" enctype=\"multipart/form-data\" accept-charset=\"utf-8\" >\n" : null; $prefix = null; if (!$this->_legacy) { $prefix = 'SP_'; } include $tpl; if (count($this->_hidden)) { $this->_hidden[SPFactory::mainframe()->token()] = 1; $this->_hidden['spsid'] = microtime(true) + Sobi::My('id') * mt_rand(5, 15) / mt_rand(5, 15); foreach ($this->_hidden as $name => $value) { echo "\n<input type=\"hidden\" name=\"{$name}\" id=\"{$prefix}{$name}\" value=\"{$value}\"/>"; } } echo $action ? "\n</form>\n" : null; if ($this->_legacy) { echo '</div>' . "\n"; } echo '</div>' . "\n"; echo "\n<!-- SobiPro output end -->\n"; Sobi::Trigger('AfterDisplay', $this->name()); }
/** * Creates debug output * @param mixed $str - string/object/array to parse * @param bool $hide - embed within a HTML comment * @param bool $return - return or output directly * @param bool $store - store within a file * @return mixed */ public static function debOut($str = null, $hide = false, $return = false, $store = false) { $return = $store ? 1 : $return; if (!$str) { $str = 'Empty'; } if ($hide) { echo "\n\n<!-- Sobi Pro Debug: "; } elseif (!$return) { echo "<h4>"; } if (is_object($str)) { try { $str = @var_export($str); $str = trim(highlight_string($str, true)); } catch (Exception $x) { $str = $x->getMessage(); } } elseif (is_array($str)) { $str = @print_r($str, true); $str = highlight_string($str, true); } if (!$return) { echo $str; } if ($hide) { echo " -->\n\n"; } elseif (!$return) { echo "</h4>"; } if ($store) { file_put_contents(SPLoader::path('var.log.debug', 'front', false, 'html'), '<br/>[' . date(DATE_RFC822) . "]<br/>{$str}<br/>", SPC::FS_APP); } elseif ($return) { return $str; } }
/** * Save an entry * * @param bool $apply */ protected function save($apply) { $new = true; if (!$this->_model) { $this->setModel(SPLoader::loadModel($this->_type)); } if ($this->_model->get('oType') != 'entry') { Sobi::Error('Entry', sprintf('Serious security violation. Trying to save an object which claims to be an entry but it is a %s. Task was %s', $this->_model->get('oType'), SPRequest::task()), SPC::ERROR, 403, __LINE__, __FILE__); exit; } /* check if we have stored last edit in cache */ $tsId = SPRequest::string('editentry', null, false, 'cookie'); if (!$tsId) { $tsId = SPRequest::cmd('ssid'); } $request = $this->getCache($tsId); $this->_model->init(SPRequest::sid($request)); $tplPackage = Sobi::Cfg('section.template', SPC::DEFAULT_TEMPLATE); $this->tplCfg($tplPackage); $customClass = null; if (isset($this->_tCfg['general']['functions']) && $this->_tCfg['general']['functions']) { $customClass = SPLoader::loadClass('/' . str_replace('.php', null, $this->_tCfg['general']['functions']), false, 'templates'); if (method_exists($customClass, 'BeforeStoreEntry')) { $customClass::BeforeStoreEntry($this->_model, $this->store['post']); SPFactory::registry()->set('requestcache_stored', $this->store); SPFactory::registry()->set('requestcache', $this->store['post']); } } $preState = array('approved' => $this->_model->get('approved'), 'state' => $this->_model->get('state'), 'new' => !$this->_model->get('id')); SPFactory::registry()->set('object_previous_state', $preState); $this->_model->getRequest($this->_type, $request); Sobi::Trigger($this->name(), __FUNCTION__, array(&$this->_model)); if ($this->_model->get('id') && $this->_model->get('id') == SPRequest::sid()) { $new = false; if (Sobi::My('id') && Sobi::My('id') == $this->_model->get('owner')) { $this->authorise('edit', 'own'); } else { $this->authorise('edit', '*'); } } else { $this->authorise('add', 'own'); } $this->_model->save($request); /* if there is something pay */ $pCount = SPFactory::payment()->count($this->_model->get('id')); if ($pCount && !Sobi::Can('entry.payment.free')) { // $this->paymentView( $tsid ); if ($customClass && method_exists($customClass, 'BeforeStoreEntryPayment')) { $customClass::BeforeStoreEntryPayment($this->_model->get('id')); } SPFactory::payment()->store($this->_model->get('id')); } /* delete cache files on after */ $file = str_replace('.', '-', $tsId); if (SPLoader::dirPath('tmp.edit.' . $file)) { SPFs::delete(SPLoader::dirPath('tmp.edit.' . $file)); } else { SPFactory::cache()->deleteVar('request_cache_' . $tsId); } SPLoader::loadClass('env.cookie'); SPCookie::delete('editentry'); $sid = $this->_model->get('id'); $pid = SPRequest::int('pid') ? SPRequest::int('pid') : Sobi::Section(); if ($new) { if ($this->_model->get('state') || Sobi::Can('entry.see_unpublished.own')) { $msg = $this->_model->get('state') ? Sobi::Txt('EN.ENTRY_SAVED') : Sobi::Txt('EN.ENTRY_SAVED_NP'); $url = Sobi::Url(array('sid' => $sid, 'pid' => $pid)); } else { // determine if there is a custom redirect if (Sobi::Cfg('redirects.entry_save_enabled') && !($pCount && !Sobi::Can('entry.payment.free'))) { $redirect = Sobi::Cfg('redirects.entry_save_url', null); if (!preg_match('/http[s]?:\\/\\/.*/', $redirect) && $redirect != 'index.php') { $redirect = Sobi::Url($redirect); } $this->response($redirect, Sobi::Txt(Sobi::Cfg('redirects.entry_save_msg', 'EN.ENTRY_SAVED_NP')), true, Sobi::Cfg('redirects.entry_save_msgtype', SPC::SUCCESS_MSG)); } else { $msg = Sobi::Txt('EN.ENTRY_SAVED_NP'); $url = Sobi::Url(array('sid' => $pid)); } } } elseif ($this->_model->get('approved') || Sobi::Can('entry.see_unapproved.own')) { $url = Sobi::Url(array('sid' => $sid, 'pid' => $pid)); $msg = $this->_model->get('approved') ? Sobi::Txt('EN.ENTRY_SAVED') : Sobi::Txt('EN.ENTRY_SAVED_NA'); } else { if ($this->_model->get('approved')) { $msg = Sobi::Txt('EN.ENTRY_SAVED'); } else { $msg = Sobi::Txt('EN.ENTRY_SAVED_NA'); } $url = Sobi::Url(array('sid' => $sid, 'pid' => $pid)); } if ($pCount && !Sobi::Can('entry.payment.free')) { $ident = md5(microtime() . $tsId . $sid . time()); $data = array('data' => SPFactory::payment()->summary($sid), 'ident' => $ident); $url = Sobi::Url(array('sid' => $sid, 'task' => 'entry.payment'), false, false); if (Sobi::Cfg('cache.l3_enabled', true)) { SPFactory::cache()->addObj($data, 'payment', $sid, Sobi::Section(), true); } else { SPFs::write(SPLoader::path('tmp.edit.' . $ident . '.payment', 'front', false, 'var'), SPConfig::serialize($data)); $url = Sobi::Url(array('sid' => $sid, 'task' => 'entry.payment', 'tsid' => $ident), false, false); } SPLoader::loadClass('env.cookie'); SPCookie::set('payment_' . $sid, $ident, SPCookie::days(1)); } if ($customClass && method_exists($customClass, 'AfterStoreEntry')) { $customClass::AfterStoreEntry($this->_model); } $this->logChanges('save', SPRequest::string('history-note')); $this->response($url, $msg, true, SPC::SUCCESS_MSG); }
protected function validate($field) { $type = SPRequest::cmd('field_fieldType'); $definition = SPLoader::path('field.' . $type, 'adm', true, 'xml'); if ($definition) { $xdef = new DOMXPath(DOMdocument::load($definition)); $required = $xdef->query('//field[@required="true"]'); if ($required->length) { for ($i = 0; $i < $required->length; $i++) { $node = $required->item($i); $name = $node->attributes->getNamedItem('name')->nodeValue; if (!SPRequest::raw(str_replace('.', '_', $name))) { $this->response(Sobi::Url(array('task' => 'field.edit', 'fid' => $field->get('fid'), 'sid' => SPRequest::sid())), Sobi::Txt('PLEASE_FILL_IN_ALL_REQUIRED_FIELDS'), false, 'error', array('required' => $name)); } } } } }
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; }
private function download() { $Error = new DOMDocument('1.0', 'utf-8'); $Error->formatOutput = true; $Root = $Error->createElement('errorLog'); $Date = $Error->createAttribute('createdAt'); $Date->appendChild($Error->createTextNode(date(DATE_RFC822))); $Root->appendChild($Date); $Site = $Error->createAttribute('site'); $Site->appendChild($Error->createTextNode(Sobi::Cfg('live_site'))); $Root->appendChild($Site); $Error->appendChild($Root); $levels = $this->levels(); try { $errors = SPFactory::db()->select('*', 'spdb_errors', null, 'eid.desc')->loadAssocList(); } catch (SPException $x) { } $c = 0; if (count($errors)) { foreach ($errors as $i => $err) { $c++; if ($c > Sobi::Cfg('err_log.limit', 50)) { break; } $err['errNum'] = $levels[$err['errNum']]; $Err = $Error->createElement('error'); $Date = $Error->createAttribute('date'); $Date->appendChild($Error->createTextNode($err['date'])); $Err->appendChild($Date); $Level = $Error->createAttribute('level'); $Level->appendChild($Error->createTextNode($err['errNum'])); $Err->appendChild($Level); $Code = $Error->createAttribute('returnCode'); $Code->appendChild($Error->createTextNode($err['errCode'])); $Err->appendChild($Code); $Section = $Error->createAttribute('section'); $Section->appendChild($Error->createTextNode($err['errSect'])); $Err->appendChild($Section); $err['errBacktrace'] = unserialize(gzuncompress(base64_decode($err['errBacktrace']))); $err['errBacktrace'] = str_replace(SOBI_ROOT, null, $err['errBacktrace']); $err['errMsg'] = str_replace(SOBI_ROOT, null, $err['errMsg']); $err['errCont'] = unserialize(gzuncompress(base64_decode($err['errCont']))); $err['errCont'] = str_replace(SOBI_ROOT, null, $err['errCont']); $ErrMsg = $Error->createElement('message', $err['errMsg']); $Err->appendChild($ErrMsg); $ErrMsg = $Error->createElement('file', $err['errFile'] . ':' . $err['errLine']); $Err->appendChild($ErrMsg); $ErrUser = $Error->createElement('user'); $Uid = $Error->createAttribute('uid'); $Uid->appendChild($Error->createTextNode($err['errUid'])); $ErrUser->appendChild($Uid); $UsrIp = $Error->createElement('ip', $err['errIp']); $ErrUser->appendChild($UsrIp); $UsrA = $Error->createElement('userAgent', $err['errUa']); $ErrUser->appendChild($UsrA); $UsrReq = $Error->createElement('requestedUri', htmlentities($err['errReq'])); $ErrUser->appendChild($UsrReq); $UsrRef = $Error->createElement('referrerUri', str_replace(Sobi::Cfg('live_site'), null, htmlentities($err['errRef']))); $ErrUser->appendChild($UsrRef); $Err->appendChild($ErrUser); $ErrStack = $Error->createElement('callStack'); $ErrStack->appendChild($Error->createCDATASection("\n" . stripslashes(var_export($err['errCont'], true)) . "\n")); $Err->appendChild($ErrStack); $ErrTrace = $Error->createElement('callTrace'); $ErrTrace->appendChild($Error->createCDATASection("\n" . stripslashes(var_export($err['errBacktrace'], true)) . "\n")); $Err->appendChild($ErrTrace); $Root->appendChild($Err); } } $file = SPLoader::path('var.log.errors', 'front', false, 'xml'); SPFs::write($file, $Error->saveXML()); $fp = SPFs::read($file); SPFactory::mainframe()->cleanBuffer(); header("Content-type: application/xml"); header('Content-Disposition: attachment; filename=error.xml'); echo $fp; flush(); exit; }
/** * @param string $template * @return $this */ public function &setTemplate($template) { $file = explode('.', $template); if (strstr($file[0], 'cms:')) { $file[0] = str_replace('cms:', null, $file[0]); $file = SPFactory::mainframe()->path(implode('.', $file)); $this->_template = SPLoader::path($file, 'root', false, null); } else { $this->_template = SOBI_PATH . '/usr/templates/' . str_replace('.', '/', $template); } Sobi::Trigger('setTemplate', $this->name(), array(&$this->_template)); return $this; }
/** * Small work-around * The imageTYPE function is not very suitable for OO code * @return void */ private function storeImage() { $st = preg_replace('/[^0-9]/', null, microtime(true) * 10000); $this->temp = SPLoader::path('tmp.img.' . $st, 'front', false, 'var', false); if (!SPLoader::dirPath('tmp.img', 'front', true)) { SPFs::mkdir(SPLoader::dirPath('tmp.img', 'front', false)); } switch ($this->type) { case IMAGETYPE_GIF: imagegif($this->image, $this->temp); break; case IMAGETYPE_JPEG: case IMAGETYPE_JPEG2000: imagejpeg($this->image, $this->temp, Sobi::Cfg('image.jpeg_quality', 75)); break; case IMAGETYPE_PNG: imagepng($this->image, $this->temp, Sobi::Cfg('image.png_compression', 0)); break; } $this->_content = file_get_contents($this->temp); if ($this->image) { imagedestroy($this->image); } }
private function installed() { $list = array(); try { SPFactory::db()->select('*', 'spdb_plugins'); $list = SPFactory::db()->loadAssocList(); } catch (SPException $x) { } $cl = count($list); for ($i = 0; $i < $cl; $i++) { $list[$i]['locked'] = SPLoader::path("etc.installed.{$list[$i]['type']}s.{$list[$i]['pid']}", 'front', true, 'xml') ? false : true; $list[$i]['eid'] = $list[$i]['type'] . '.' . $list[$i]['pid']; if ($list[$i]['pid'] == 'router' || in_array($list[$i]['type'], array('field', 'language', 'module', 'plugin'))) { $list[$i]['enabled'] = -1; } } /** @var $view SPExtensionsView */ $view = SPFactory::View('extensions', true); $view->assign($this->_task, 'task')->assign($this->menu(), 'menu')->assign($list, 'applications')->determineTemplate('extensions', $this->_task); Sobi::Trigger($this->_task, $this->name(), array(&$view)); $view->display(); Sobi::Trigger('After' . ucfirst($this->_task), $this->name(), array(&$view)); }
/** * @param $xml - path to xml file inside the administrator directory (e.g. field.definitions.filter) * @param $type - object type or array with error url * */ protected function validate($xml, $type) { $definition = SPLoader::path($xml, 'adm', true, 'xml'); if ($definition) { if (is_array($type)) { $errorUrl = Sobi::Url($type); } else { $errorUrl = Sobi::Url(array('task' => $type . '.edit', 'sid' => SPRequest::sid())); } $xdef = new DOMXPath(DOMdocument::load($definition)); $required = $xdef->query('//field[@required="true"]'); if ($required->length) { for ($i = 0; $i < $required->length; $i++) { $node = $required->item($i); $name = $node->attributes->getNamedItem('name')->nodeValue; if (!SPRequest::raw(str_replace('.', '_', $name))) { $this->response($errorUrl, Sobi::Txt('PLEASE_FILL_IN_ALL_REQUIRED_FIELDS'), false, SPC::ERROR_MSG, array('required' => $name)); } } } } }