diff --git a/_admin.php b/_admin.php index 0bd3406..bd6a0bc 100644 --- a/_admin.php +++ b/_admin.php @@ -45,9 +45,16 @@ class tweakStoresBehaviors # addd some js public static function modulesToolsHeaders(dcCore $core, $plugin) { + $core->auth->user_prefs->addWorkspace('interface'); + return dcPage::jsVars(['dotclear.ts_copied' => __('Copied to clipboard')]) . - dcPage::jsLoad(dcPage::getPF('tweakStores/js/admin.js')); + dcPage::jsLoad(dcPage::getPF('tweakStores/js/admin.js')) . + ( + !$core->auth->user_prefs->interface->colorsyntax ? '' : + dcPage::jsLoadCodeMirror($core->auth->user_prefs->interface->colorsyntax_theme) . + dcPage::jsLoad(dcPage::getPF('tweakStores/js/cms.js')) + ); } # admin plugins page tab @@ -65,10 +72,11 @@ class tweakStoresBehaviors # generic page tab protected static function modulesToolsTabs(dcCore $core, $modules, $excludes, $page_url) { - $combo = self::comboModules($modules, $excludes); - - # zip file url pattern - $file_pattern = $core->blog->settings->tweakStores->file_pattern; + $core->auth->user_prefs->addWorkspace('interface'); + $user_ui_colorsyntax = $core->auth->user_prefs->interface->colorsyntax; + $user_ui_colorsyntax_theme = $core->auth->user_prefs->interface->colorsyntax_theme; + $combo = self::comboModules($modules, $excludes); + $file_pattern = $core->blog->settings->tweakStores->file_pattern; # check dcstore repo $url = ''; @@ -154,10 +162,14 @@ class tweakStoresBehaviors ( empty($file_content) ? '' : '
' . form::textArea('file_xml', 165, 14, [ - 'default' => html::escapeHTML(str_replace('><', ">\n<", $file_content)), + 'default' => html::escapeHTML(tweakStores::prettyXML($file_content)), 'class' => 'maximal', 'extra_html' => 'readonly="true"' - ]) . '' + ]) . '' . + ( + !$user_ui_colorsyntax ? '' : + dcPage::jsRunCodeMirror('editor', 'file_xml', 'dotclear', $user_ui_colorsyntax_theme) + ) ) . ''; } @@ -197,10 +209,14 @@ class tweakStoresBehaviors } echo '
' . form::textArea('gen_xml', 165, 14, [ - 'default' => html::escapeHTML(str_replace('><', ">\n<", $xml_content)), + 'default' => html::escapeHTML(tweakStores::prettyXML($xml_content)), 'class' => 'maximal', 'extra_html' => 'readonly="true"' - ]) . ''; + ]) . '' . + ( + !$user_ui_colorsyntax ? '' : + dcPage::jsRunCodeMirror('editor', 'gen_xml', 'dotclear', $user_ui_colorsyntax_theme) + ); if (empty(tweakStores::$failed) && $modules[$_POST['buildxml_id']]['root_writable'] diff --git a/inc/class.tweakstores.php b/inc/class.tweakstores.php index 8b8f39a..f5e3ff4 100644 --- a/inc/class.tweakstores.php +++ b/inc/class.tweakstores.php @@ -182,7 +182,7 @@ class tweakStores $res = new xmlTag('modules', $rsp); $res->insertAttr('xmlns:da', 'http://dotaddict.org/da/'); - return $res->toXML(); + return self::prettyXML($res->toXML()); } public static function writeXML($id, $module, $file_pattern) @@ -197,7 +197,7 @@ class tweakStores } try { - files::putContent($module['root'] . '/dcstore.xml', str_replace('><', ">\n<", $content)); + files::putContent($module['root'] . '/dcstore.xml', $content); } catch (Exception $e) { self::$failed[] = $e->getMessage(); @@ -206,4 +206,18 @@ class tweakStores return true; } + + public static function prettyXML(string $str): string + { + if (class_exists('DOMDocument')) { + $dom = new DOMDocument('1.0'); + $dom->preserveWhiteSpace = false; + $dom->formatOutput = true; + $dom->loadXML($str); + + return $dom->saveXML(); + } + + return str_replace('><', ">\n<", $str); + } } diff --git a/js/admin.js b/js/admin.js index dff1a0b..6205522 100644 --- a/js/admin.js +++ b/js/admin.js @@ -3,19 +3,18 @@ $(function(){ $("#ts_copy_button").click(function() { - tsCopy("#gen_xml"); - return false; - }); - - function tsCopy(element_id) { - $(element_id).attr("contenteditable", true) + var style = $("#gen_xml").attr('style'); + $("#gen_xml").attr('style', '').attr("contenteditable", true) .select() .on("focus", function() { document.execCommand('selectAll', false, null) }) .focus() document.execCommand("Copy"); - $(element_id).removeAttr("contenteditable"); + $("#gen_xml").removeAttr("contenteditable").attr('style', style); + $("#ts_copy_button").focus(); + alert(dotclear.ts_copied); - } + return false; + }); }); \ No newline at end of file diff --git a/js/cms.js b/js/cms.js new file mode 100644 index 0000000..0ac9f92 --- /dev/null +++ b/js/cms.js @@ -0,0 +1,7 @@ +/*global CodeMirror, dotclear */ +'use strict'; + +window.CodeMirror.defineMode('dotclear', function (config) { + config.readOnly = true; + return CodeMirror.getMode(config, 'php'); +}); \ No newline at end of file