/** * Building resulte XML Document */ public function build() { //Если у нас не режим json $this->doc = new \DOMDocument('1.0', 'UTF-8'); $dom_root = $this->doc->createElement('document'); $dom_root->setAttribute('debug', $this->getConfigValue('site.debug')); $dom_root->setAttribute('editable', $this->isEditable()); $this->setProperty('url', (string) $this->request->getURI()); $this->doc->appendChild($dom_root); if (!isset($this->properties['title'])) { $this->setProperty('title', strip_tags($this->documentInfo['Name'])); } $dom_documentProperties = $this->doc->createElement('properties'); foreach ($this->properties as $propName => $propValue) { $dom_property = $this->doc->createElement('property', str_replace('&', '&', $propValue)); $dom_property->setAttribute('name', $propName); if ($propName == 'title') { $dom_property->setAttribute('alt', $this->documentInfo['HtmlTitle']); } $dom_documentProperties->appendChild($dom_property); } $dom_root->appendChild($dom_documentProperties); //Дополнительные свойства, имеющие параметры $prop = $this->doc->createElement('property', $baseURL = E()->getSiteManager()->getCurrentSite()->base); $prop->setAttribute('name', 'base'); $prop->setAttribute('static', $staticURL = $this->getConfigValue('site.static') ? $staticURL : $baseURL); $prop->setAttribute('media', ($mediaURL = $this->getConfigValue('site.media')) ? $mediaURL : $baseURL); $prop->setAttribute('resizer', ($resizerURL = $this->getConfigValue('site.resizer')) ? $resizerURL : E()->getSiteManager()->getDefaultSite()->base . 'resizer/'); $prop->setAttribute('folder', E()->getSiteManager()->getCurrentSite()->folder); $prop->setAttribute('default', E()->getSiteManager()->getDefaultSite()->base); $prop->setAttribute('favicon', ($favicon = E()->getSiteManager()->getCurrentSite()->faviconFile) ? $favicon : E()->getSiteManager()->getDefaultSite()->faviconFile); $dom_documentProperties->appendChild($prop); $prop = $this->doc->createElement('property', $this->getLang()); $prop->setAttribute('name', 'lang'); $prop->setAttribute('abbr', $this->request->getLangSegment()); $prop->setAttribute('default', E()->getLanguage()->getDefault()); $prop->setAttribute('real_abbr', E()->getLanguage()->getAbbrByID($this->getLang())); $dom_documentProperties->appendChild($prop); if (($docVars = $this->getConfigValue('site.vars')) && is_array($docVars)) { $dom_documentVars = $this->doc->createElement('variables'); foreach ($docVars as $varName => $varValue) { $var = $this->doc->createElement('var', $varValue); $var->setAttribute('name', strtoupper($varName)); $dom_documentVars->appendChild($var); } $dom_root->appendChild($dom_documentVars); } if ($og = E()->getOGObject()->build()) { $dom_root->appendChild($this->doc->importNode($og, true)); } unset($prop, $og); foreach ($this->componentManager as $component) { $componentResult = false; $dom_errors = false; try { if ($component->enabled() && $this->getRights() >= $component->getCurrentStateRights()) { $componentResult = $component->build(); } } catch (DummyException $dummyException) { } if (!empty($componentResult)) { try { $componentResult = $this->doc->importNode($componentResult->documentElement, true); } catch (\Exception $e) { //stop($e->getTraceAsString()); } if ($dom_errors) { $componentResult->insertBefore($dom_errors, $componentResult->firstChild); } $dom_root->appendChild($componentResult); } elseif ($dom_errors) { $dom_root->appendChild($dom_errors); } } if (!empty($this->translations)) { $dom_translations = $this->doc->createElement('translations'); $dom_root->appendChild($dom_translations); foreach ($this->translations as $const => $componentName) { $dom_translation = $this->doc->createElement('translation', translate($const)); $dom_translation->setAttribute('const', $const); if (!is_null($componentName)) { $dom_translation->setAttribute('component', $componentName); } $dom_translations->appendChild($dom_translation); } } $jsLibs = Primitive::getConfigValue('site.js-lib'); if (!isset($jsLibs['mootools'])) { $jsLibs['mootools'] = $staticURL . 'scripts/mootools.min.js'; } if (!isset($jsLibs['jquery'])) { $jsLibs['jquery'] = 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'; } $dom_javascript = $this->doc->createElement('javascript'); foreach ($jsLibs as $name => $path) { $dom_javascript->setAttribute($name, $path); } $dom_root->appendChild($dom_javascript); foreach ($this->js as $behavior) { $dom_javascript->appendChild($this->doc->importNode($behavior, true)); } // построение списка подключаемых js библиотек в порядке зависимостей $jsMapFile = HTDOCS_DIR . '/system.jsmap.php'; if (!file_exists($jsMapFile)) { throw new \RuntimeException('JS dependencies file ' . $jsMapFile . ' does\'nt exists'); } $jsIncludes = []; $jsmap = (include $jsMapFile); $xpath = new \DOMXPath($this->doc); $nl = $xpath->query('//javascript/behavior'); if ($nl->length) { foreach ($nl as $node) { $classPath = $node->getAttribute('path'); if ($classPath && substr($classPath, -1) != '/') { $classPath .= '/'; } $cls = ($classPath ? $classPath : '') . $node->getAttribute('name'); $this->createJavascriptDependencies([$cls], $jsmap, $jsIncludes); } } foreach ($jsIncludes as $js) { $dom_js_library = $this->doc->createElement('library'); $dom_js_library->setAttribute('path', $js); $onlyName = explode('/', $js); $dom_js_library->setAttribute('name', array_pop($onlyName)); $dom_javascript->appendChild($dom_js_library); } }