add colored synthax (from user pref for themes)
This commit is contained in:
parent
290597d3cd
commit
008d347893
4 changed files with 55 additions and 19 deletions
30
_admin.php
30
_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,9 +72,10 @@ class tweakStoresBehaviors
|
|||
# generic page tab
|
||||
protected static function modulesToolsTabs(dcCore $core, $modules, $excludes, $page_url)
|
||||
{
|
||||
$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);
|
||||
|
||||
# zip file url pattern
|
||||
$file_pattern = $core->blog->settings->tweakStores->file_pattern;
|
||||
|
||||
# check dcstore repo
|
||||
|
@ -154,10 +162,14 @@ class tweakStoresBehaviors
|
|||
(
|
||||
empty($file_content) ? '' :
|
||||
'<pre>' . 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"'
|
||||
]) . '</pre>'
|
||||
]) . '</pre>' .
|
||||
(
|
||||
!$user_ui_colorsyntax ? '' :
|
||||
dcPage::jsRunCodeMirror('editor', 'file_xml', 'dotclear', $user_ui_colorsyntax_theme)
|
||||
)
|
||||
) .
|
||||
'</div>';
|
||||
}
|
||||
|
@ -197,10 +209,14 @@ class tweakStoresBehaviors
|
|||
}
|
||||
echo
|
||||
'<pre>' . 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"'
|
||||
]) . '</pre>';
|
||||
]) . '</pre>' .
|
||||
(
|
||||
!$user_ui_colorsyntax ? '' :
|
||||
dcPage::jsRunCodeMirror('editor', 'gen_xml', 'dotclear', $user_ui_colorsyntax_theme)
|
||||
);
|
||||
|
||||
if (empty(tweakStores::$failed)
|
||||
&& $modules[$_POST['buildxml_id']]['root_writable']
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
15
js/admin.js
15
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;
|
||||
});
|
||||
});
|
7
js/cms.js
Normal file
7
js/cms.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
/*global CodeMirror, dotclear */
|
||||
'use strict';
|
||||
|
||||
window.CodeMirror.defineMode('dotclear', function (config) {
|
||||
config.readOnly = true;
|
||||
return CodeMirror.getMode(config, 'php');
|
||||
});
|
Loading…
Reference in a new issue