// The templates definitions. templates :'; //append XML templates $filename = PATH_CSS_FS . '/editortemplates.xml'; if (file_exists($filename)) { $source = file_get_contents($filename); $file = new DOMDocument('1.0', APPLICATION_DEFAULT_ENCODING); $file->loadXml($source, $options); $tplsTags = $file->getElementsByTagName('Template'); $tpls = array(); foreach ($tplsTags as $tplTag) { $tpl = new stdClass(); $tpl->title = $tplTag->getAttribute("title"); $descTags = $tplTag->getElementsByTagName('Description'); if ($descTags->length) { foreach ($descTags as $descTag) { $tpl->description = $descTag->nodeValue; } } $htmlTags = $tplTag->getElementsByTagName('Html'); if ($htmlTags->length) { foreach ($htmlTags as $htmlTag) { $tpl->html = $htmlTag->nodeValue; } } $tpls[] = $tpl; } $content .= io::jsonEncode($tpls); } $content .= '});'; echo $content;
/** * Get the HTML form given the block HTML example data. * * @param CMS_language &$language The language of the administration frontend * @param CMS_page &$page The page which contains the client space * @param CMS_clientSpace &$clientSpace The client space which contains the row * @param CMS_row &$row The row which contains the block * @param integer $blockID The tag ID of the block * @param string $data The data to show as example * @return string The HTML form which can send to the page that will modify the block * @access private */ protected function _getHTMLForm($language, &$page, &$clientSpace, &$row, $blockID, $data) { global $cms_user; //append atm-block class and block-id to all first level tags found in block datas $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML('<block>' . $data . '</block>'); } catch (DOMException $e) { $this->raiseError('Parse error for ' . get_class($this) . ' : Page ' . $page->getID() . ' - Row "' . $row->getTagID() . '" - Block "' . $blockID . '" : ' . $e->getMessage()); $data = '<div class="atm-error-block atm-block-helper">' . $language->getMessage(self::MESSAGE_BLOCK_CONTENT_ERROR) . '</div>'; $domdocument = new CMS_DOMDocument(); $domdocument->loadXML('<block>' . $data . '</block>'); } $blockNodes = $domdocument->getElementsByTagName('block'); if ($blockNodes->length == 1) { $blockXML = $blockNodes->item(0); } //check for valid tags nodes inside current block tag $hasNode = false; foreach ($blockXML->childNodes as $blockChildNode) { //scripts tags and p tags are not correctly handled by javascript if (is_a($blockChildNode, 'DOMElement') && $blockChildNode->tagName != 'script') { $hasNode = true; } } foreach ($blockXML->childNodes as $blockChildNode) { //scripts tags and p tags are not correctly handled by javascript if (is_a($blockChildNode, 'DOMElement') && ($blockChildNode->tagName != 'p' || io::substr($blockChildNode->tagName, 0, 4) != 'atm-')) { $hasNode = false; } } if (!$hasNode) { //append div with atm-empty-block class around datas $domdocument = new CMS_DOMDocument(); try { $domdocument->loadXML('<block><div class="atm-empty-block atm-block-helper">' . $data . '</div></block>'); } catch (DOMException $e) { $this->raiseError('Parse error for block : ' . $e->getMessage() . " :\n" . $data, true); return ''; } $blockNodes = $domdocument->getElementsByTagName('block'); if ($blockNodes->length == 1) { $blockXML = $blockNodes->item(0); } } $elements = array(); $uniqueId = 'block-' . md5(mt_rand() . microtime()); foreach ($blockXML->childNodes as $blockChildNode) { if (is_a($blockChildNode, 'DOMElement') && $blockChildNode->tagName != 'script' && $blockChildNode->tagName != 'p' && io::substr($blockChildNode->tagName, 0, 4) != 'atm-') { if ($blockChildNode->hasAttribute('class')) { $blockChildNode->setAttribute('class', $blockChildNode->getAttribute('class') . ' atm-block ' . $uniqueId); } else { $blockChildNode->setAttribute('class', 'atm-block ' . $uniqueId); } $elementId = 'el-' . md5(mt_rand() . microtime()); $blockChildNode->setAttribute('id', $elementId); $elements[] = $elementId; } } $data = CMS_DOMDocument::DOMElementToString($blockXML, true); //add block JS specification $data = ' <script type="text/javascript"> atmBlocksDatas[\'' . $uniqueId . '\'] = { page: \'' . $page->getID() . '\', document: document, clientSpaceTagID: \'' . $clientSpace->getTagID() . '\', row: \'' . $row->getTagID() . '\', id: \'' . $blockID . '\', jsBlockClass: \'' . $this->_jsBlockClass . '\', hasContent: \'' . $this->_hasContent . '\', editable: \'' . $this->_editable . '\', administrable: \'' . $this->_administrable . '\', options: ' . io::jsonEncode($this->_options) . ', value: ' . (is_array($this->_value) ? sensitiveIO::jsonEncode($this->_value) : '\'' . sensitiveIO::sanitizeJSString($this->_value) . '\'') . ', elements: [' . ($elements ? '\'' . implode('\',\'', $elements) . '\'' : '') . '] }; </script> ' . $data; return $data; }
} //append XML styles $filename = PATH_CSS_FS . '/editorstyles.xml'; if (file_exists($filename)) { $source = file_get_contents($filename); $file = new DOMDocument('1.0', APPLICATION_DEFAULT_ENCODING); $file->loadXml($source, $options); $stylesTags = $file->getElementsByTagName('Style'); $styles = array(); foreach ($stylesTags as $styleTag) { $style = new stdClass(); $style->name = $styleTag->getAttribute("name"); $style->element = $styleTag->getAttribute("element"); $attrTags = $styleTag->getElementsByTagName('Attribute'); if ($attrTags->length) { $style->attributes = new stdClass(); foreach ($attrTags as $attrTag) { $name = $attrTag->getAttribute("name"); $style->attributes->{$name} = $attrTag->getAttribute("value"); } } $styles[] = $style; } $content .= 'config.stylesSet = ' . io::jsonEncode($styles) . ';' . "\n"; } $content .= ' config.templates_files = [\'' . PATH_MAIN_WR . '/ckeditor/templates.php\']; config.menu_groups = \'clipboard,tablecell,tablecellproperties,tablerow,tablecolumn,table,anchor,link,automneLinks,editPlugin\'; }; '; echo $content;