protected function upload() { $ident = SPRequest::cmd('ident', null, 'post'); $data = SPRequest::file($ident, 'tmp_name'); $secret = md5(Sobi::Cfg('secret')); if ($data) { $properties = SPRequest::file($ident); $fileName = md5(SPRequest::file($ident, 'name') . time() . $secret); $path = SPLoader::dirPath("tmp.files.{$secret}", 'front', false) . '/' . $fileName; /** @var $file SPFile */ $file = SPFactory::Instance('base.fs.file'); if (!$file->upload($data, $path)) { $this->message(array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE'), 'id' => '')); } $path = $file->getPathname(); $type = $this->check($path); $properties['tmp_name'] = $path; SPFs::write($path . '.var', SPConfig::serialize($properties)); $response = array('type' => 'success', 'text' => Sobi::Txt('FILE_UPLOADED', $properties['name'], $type), 'id' => 'file://' . $fileName, 'data' => array('name' => $properties['name'], 'type' => $properties['type'], 'size' => $properties['size'])); } else { $response = array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE_NO_DATA'), 'id' => ''); } // $field = SPRequest::cmd( 'field', null ); $this->message($response); }
/** * @param DOMDocument $def * @param string $dir * @return array | string */ protected function installExt($def, $dir) { if ($def->firstChild->nodeName == 'install') { $content = $def->saveXML(); // I know, I know .... $content = str_replace(array('<install', '</install>'), array('<extension', '</extension>'), $content); SPFs::write($dir . '/temp.xml', $content); $def = new DOMDocument(); $def->load($dir . '/temp.xml'); } return parent::installExt($def, $dir); }
private function status($message, $progress = 0, $interval = 0, $type = SPC::INFO_MSG) { if (!strlen($message)) { $message = Sobi::Txt('PROGRESS_WORKING'); } $progress = $progress ? $progress : $this->progress; $interval = $interval ? $interval : $this->interval; $type = $type ? $type : $this->type; $this->progress = $progress; $this->message = $message; $this->interval = $interval; $this->type = $type; $typeText = Sobi::Txt('STATUS_' . $type); SPFs::write($this->file, json_encode(array('progress' => $progress, 'message' => $message, 'interval' => $interval, 'type' => $type, 'typeText' => $typeText))); }
/** * */ public function ProxyUpload() { $ident = SPRequest::cmd('ident', null, 'post'); $data = SPRequest::file($ident, 'tmp_name'); $secret = md5(Sobi::Cfg('secret')); if ($data) { $properties = SPRequest::file($ident); $orgFileName = $properties['name']; $extension = SPFs::getExt($orgFileName); $orgFileName = str_replace('.' . $extension, '.' . strtolower($extension), $orgFileName); if ($properties['size'] > $this->maxSize) { $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_TOO_LARGE', $this->name, $properties['size'], $this->maxSize), 'id' => '')); } $dirNameHash = md5($orgFileName . time() . $secret); $dirName = SPLoader::dirPath("tmp.files.{$secret}.{$dirNameHash}", 'front', false); SPFs::mkdir($dirName); $path = $dirName . $orgFileName; /** @var $file SPImage */ $orgImage = SPFactory::Instance('base.fs.image'); if (!$orgImage->upload($data, $path)) { $this->message(array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE'), 'id' => '')); } if (Sobi::Cfg('image_field.fix_rotation', true)) { if ($orgImage->fixRotation()) { $orgImage->save(); } } if ($this->crop) { $croppedImage = clone $orgImage; list($originalWidth, $originalHeight) = getimagesize($path); $aspectRatio = $this->resizeWidth / $this->resizeHeight; $width = $aspectRatio * $originalHeight > $originalWidth ? $originalWidth : $aspectRatio * $originalHeight; $height = $originalWidth / $aspectRatio > $originalHeight ? $originalHeight : $originalWidth / $aspectRatio; try { $croppedImage->crop($width, $height); $croppedImage->saveAs($dirName . 'cropped_' . $orgFileName); $ico = SPFactory::Instance('base.fs.image', $dirName . 'cropped_' . $orgFileName); } catch (SPException $x) { $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_CANNOT_CROP', $x->getMessage()), 'id' => '')); } } else { $ico = clone $orgImage; } $image = clone $orgImage; try { $previewSize = explode(':', Sobi::Cfg('image.preview_size', '500:500')); $image->resample($previewSize[0], $previewSize[1], false); $image->saveAs($dirName . 'resized_' . $orgFileName); } catch (SPException $x) { $image->delete(); $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), 'id' => '')); } try { $icoSize = explode(':', Sobi::Cfg('image.ico_size', '80:80')); $ico->resample($icoSize[0], $icoSize[1], false); $ico->saveAs($dirName . 'icon_' . $orgFileName); } catch (SPException $x) { $ico->delete(); $this->message(array('type' => 'error', 'text' => SPLang::e('FIELD_IMG_CANNOT_RESAMPLE', $x->getMessage()), 'id' => '')); } $path = $orgImage->getPathname(); $type = $this->check($path); $properties['tmp_name'] = $path; SPFs::write(SPLoader::dirPath("tmp.files.{$secret}", 'front', false) . '/' . $orgFileName . '.var', SPConfig::serialize($properties)); $response = array('type' => 'success', 'text' => $this->crop ? Sobi::Txt('IMAGE_UPLOADED_CROP', $properties['name'], $type) : Sobi::Txt('FILE_UPLOADED', $properties['name']), 'id' => 'directory://' . $dirNameHash, 'data' => array('name' => $properties['name'], 'type' => $properties['type'], 'size' => $properties['size'], 'original' => $dirNameHash . '/' . $properties['name'], 'icon' => $dirNameHash . '/' . 'icon_' . $orgFileName, 'crop' => $this->crop, 'height' => $this->resizeHeight, 'width' => $this->resizeWidth)); } else { $response = array('type' => 'error', 'text' => SPLang::e('CANNOT_UPLOAD_FILE_NO_DATA'), 'id' => ''); } $this->message($response); }
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 ); }
private static function createLangFile() { static $loaded = false; if (!$loaded) { $lang = array('months' => Sobi::Txt('JS_CALENDAR_MONTHS'), 'monthsShort' => Sobi::Txt('JS_CALENDAR_MONTHS_SHORT'), 'days' => Sobi::Txt('JS_CALENDAR_DAYS'), 'daysShort' => Sobi::Txt('JS_CALENDAR_DAYS_SHORT'), 'daysMin' => Sobi::Txt('JS_CALENDAR_DAYS_MINI'), 'today' => Sobi::Txt('JS_CALENDAR_TODAY')); $check = md5(serialize($lang)); if (!SPLoader::JsFile('locale.' . Sobi::Lang(false) . '_date_picker', false, true, false) || !stripos(SPFs::read(SPLoader::JsFile('locale.' . Sobi::Lang(false) . '_date_picker', false, false, false)), $check)) { foreach ($lang as $k => $v) { $lang[$k] = explode(',', $v); } $lang = json_encode($lang); $c = "\nvar spDatePickerLang={$lang}"; $c .= "\n//{$check}"; SPFs::write(SPLoader::JsFile('locale.' . Sobi::Lang(false) . '_date_picker', false, false, false), $c); } } $loaded = true; }
protected function parseDependencyDefinition($file) { $dom = new DOMDocument(); $dom->load(SOBI_PATH . '/etc/fields/select-list/' . $file); $xpath = new DOMXPath($dom); $definition = array(); $root = $xpath->query('/definition'); $definition['prefix'] = $root->item(0)->attributes->getNamedItem('prefix')->nodeValue; $definition['translation'] = $root->item(0)->attributes->getNamedItem('translation')->nodeValue; $definition['options'] = array(); $this->_parseXML($xpath->query('/definition/option'), $definition['options']); SPFs::write(SOBI_PATH . '/etc/fields/select-list/definitions/' . str_replace('.xml', '.json', $file), json_encode($definition)); }
private function _jsFiles() { if (Sobi::Cfg('cache.include_js_files', false) && !defined('SOBIPRO_ADM')) { if (count($this->_cache['js'])) { $compression = Sobi::Cfg('cache.compress_js', false); $comprLevel = Sobi::Cfg('cache.compress_level', 0); $check = array('section' => Sobi::Section(), 'compress_level' => $comprLevel, 'compress_js' => $compression); foreach ($this->_cache['js'] as $file) { $check[$file] = filemtime($file); } $check = md5(serialize($check)); if (!SPFs::exists(SOBI_PATH . "/var/js/{$check}.js")) { $noCompress = explode(',', Sobi::Cfg('cache.js_compress_exceptions')); $jsContent = "\n/* Created at: " . date(SPFactory::config()->key('date.log_format', 'D M j G:i:s T Y')) . " */\n"; foreach ($this->_cache['js'] as $file) { $fName = str_replace(SOBI_ROOT, null, $file); $jsContent .= "\n// ========\n// File: {$fName}\n// ========\n\n"; if ($compression && !in_array(basename($file), $noCompress)) { $compressor = SPFactory::Instance('env.jspacker', SPFs::read($file), $comprLevel, false, true); $jsContent .= $compressor->pack(); } else { $jsContent .= SPFs::read($file); } $jsContent .= ";\n"; } SPFs::write(SOBI_PATH . "/var/js/{$check}.js", $jsContent); } $cfile = SPLoader::JsFile('front.var.js.' . $check, false, true, true); $this->jsFiles[++$this->count] = "\n<script type=\"text/javascript\" src=\"{$cfile}\"></script>"; } } return $this->jsFiles; }
private function packageToFile($stream, $checksum, $name, $msg) { $path = SPLoader::dirPath('tmp.install', 'front', false); $stream = base64_decode($stream); $msg->progress(65, Sobi::Txt('EX.EXAMINING_CHECKSUM'), 1000); try { SPFs::write($path . DS . $name, $stream); } catch (SPException $x) { $msg->error(SPLang::e('REPO_ERR', $x->getMessage())); exit; } if (md5_file($path . DS . $name) != $checksum) { $msg->error(SPLang::e('EX.CHECKSUM_NOK')); exit; } // sleep( 1 ); $msg->progress(75, Sobi::Txt('EX.CHECKSUM_OK')); return $path . DS . $name; }
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; }
/** * 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); }
/** * Saves file as a copy * @param string $path * @return bool */ public function saveAs($path) { return SPFs::write($path, $this->_content); }
/** * @param $file * @param $output * @param $u */ protected function compileLessFile($file, $output, $u, $compress = false) { include_once 'phar://' . SOBI_PATH . '/lib/services/third-party/less/less.phar.tar.gz/Autoloader.php'; try { Less_Autoloader::register(); if ($compress) { $options = array('compress' => true, 'strictMath' => true); } else { $options = array(); } $parser = new Less_Parser($options); $parser->parseFile($file); $css = $parser->getCss(); if (SPFs::exists($output)) { SPFs::delete($output); } SPFs::write($output, $css); } catch (Exception $x) { $this->response(Sobi::Url($u), SPLang::e('TP.LESS_FILE_NOT_COMPILED', $x->getMessage()), false, SPC::ERROR_MSG); } }
/** * This method is adding new tasks to the XML files used for Joomla! menu definition * @param $tasks - list of tasks to add * @param $controlString - a single string to check for if it has not been already added * @param $languageFile - language file where the translation for tasks can be found * @param array $additionalStrings - optional list of additional strings to add to the sys ini files * @param bool $force - force even if it has been already done - forcing only language files redefinition * @return void */ public function updateXMLDefinition($tasks, $controlString, $languageFile, $additionalStrings = array(), $force = false) { $file = SPLoader::translatePath('metadata', 'front', true, 'xml'); $run = false; $strings = array(); foreach ($tasks as $label) { $strings[] = $label; $strings[] = $label . '_EXPL'; } if (count($additionalStrings)) { foreach ($additionalStrings as $additionalString) { $strings[] = $additionalString; } } /** check if it hasn't been already added */ if (!strstr(SPFs::read($file), $controlString)) { $run = true; $doc = new DOMDocument(); $doc->load($file); $options = $doc->getElementsByTagName('options')->item(0); foreach ($tasks as $task => $label) { $node = $doc->createElement('option'); $attribute = $doc->createAttribute('value'); $attribute->value = $task; $node->appendChild($attribute); $attribute = $doc->createAttribute('name'); $attribute->value = 'SP.' . $label; $node->appendChild($attribute); $attribute = $doc->createAttribute('msg'); $attribute->value = 'SP.' . $label . '_EXPL'; $node->appendChild($attribute); $options->appendChild($node); } $doc->save($file); } if ($run || $force) { $dirPath = SPLoader::dirPath('administrator.language', 'root'); /** @var SPDirectory $dir */ $dir = SPFactory::Instance('base.fs.directory', $dirPath); $files = $dir->searchFile('com_sobipro.sys.ini', false, 2); $default = array(); $defaultLangDir = SPLoader::dirPath("language.en-GB", 'root', true); $defaultLang = parse_ini_file($defaultLangDir . 'en-GB.' . $languageFile . '.ini'); foreach ($strings as $string) { $default['SP.' . $string] = $defaultLang['SP.' . $string]; } /** @var SPFile $file */ $file = null; foreach ($files as $file) { $fileName = $file->getFileName(); list($language) = explode('.', $fileName); $nativeLangDir = SPLoader::dirPath("language.{$language}", 'root', true); $nativeStrings = array(); if ($nativeLangDir) { $nativeLangFile = $nativeLangDir . $language . '.' . $languageFile . '.ini'; if (file_exists($nativeLangFile)) { $nativeLang = @parse_ini_file($nativeLangFile); foreach ($strings as $string) { if (isset($nativeLang['SP.' . $string])) { $nativeStrings['SP.' . $string] = $nativeLang['SP.' . $string]; } } } } $add = null; foreach ($strings as $string) { if (isset($nativeStrings['SP.' . $string])) { $add .= "\nSP.{$string}=\"{$nativeStrings['SP.' . $string]}\""; } else { $add .= "\nSP.{$string}=\"{$default['SP.' . $string]}\""; } } $add .= "\n"; $content = SPFs::read($file->getPathname()); $add = $content . $add; SPFs::write($file->getPathname(), $add); } } }
/** */ 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()); } } }