This commit is contained in:
root
2019-08-30 19:30:19 +02:00
commit 6f2b105ca0
595 changed files with 78405 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@ -0,0 +1,317 @@
#crayon-theme-editor-button {
margin-left: 10px;
}
#crayon-editor-controls {
}
#crayon-editor-preview .crayon-syntax {
margin: 0 !important;
padding: 0 !important;
}
#crayon-editor-control-wrapper {
padding-left: 20px;
}
#crayon-editor-control-wrapper,
#crayon-editor-controls {
width: 422px;
overflow: hidden;
}
#crayon-editor-save {
margin: 0 5px;
}
#crayon-editor-controls label {
margin-right: 10px;
width: 70px;
float: left;
}
#crayon-editor-controls .crayon-theme-editor-form .separator .content {
font-weight: bold;
color: #999;
padding-top: 8px;
border-bottom: 1px solid #ccc;
text-shadow: 0 1px 0px #fff;
text-align: center;
padding-bottom: 2px;
margin-bottom: 5px;
}
#crayon-editor-controls .crayon-theme-editor-form .separator.first .content {
padding-top: 0;
}
#crayon-editor-controls .crayon-theme-editor-form .separator.title .content {
line-height: 24px;
height: 22px;
padding-top: 0;
background: #dedede url(images/title.png) center bottom repeat-x;
border-color: #999;
}
#crayon-editor-controls .crayon-theme-editor-form .separator.title .content {
color: #333;
text-shadow: 0 1px 2px #eee;
}
#crayon-editor-controls .crayon-theme-editor-form .separator.title td {
color: #333;
padding: 0;
}
#crayon-editor-controls .crayon-theme-editor-form .field {
border: 0px;
padding-right: 5px;
vertical-align: middle;
}
#crayon-editor-controls .crayon-theme-editor-form .split-field td {
padding-right: 5px;
}
#crayon-editor-controls .crayon-theme-editor-form .split-field td.last {
padding-right: 0;
}
#crayon-editor-controls .split-field input,
#crayon-editor-controls .split-field select {
width: 100%;
}
#crayon-editor-controls .crayon-theme-editor-form table td.value.split {
padding-left: 0;
}
#crayon-editor-controls .crayon-theme-editor-form table td.field.split {
padding-right: 0;
}
#crayon-editor-controls input {
line-height: 23px;
height: 23px;
border: 1px solid #ccc;
padding: 0 5px;
margin: 2px 0;
}
#crayon-editor-controls input:focus {
border: 1px solid #999;
}
#crayon-editor-controls .ui-tabs-panel {
padding: 5px;
}
.crayon-theme-editor-form table {
width: 100%;
}
#crayon-editor-controls .crayon-theme-editor-form table,
#crayon-editor-controls .crayon-theme-editor-form tr,
#crayon-editor-controls .crayon-theme-editor-form td {
padding: 0;
margin: 0;
border-spacing: 0 !important;
}
#crayon-editor-controls .crayon-theme-editor-form table tr:first-child td,
#crayon-editor-controls .crayon-theme-editor-form table tr:last-child td {
padding: 4px;
}
#crayon-editor-controls .crayon-theme-editor-form table td {
padding: 1px 4px;
}
.crayon-theme-editor-form table .value input {
width: 100%;
}
#crayon-editor-controls .ui-tabs-nav li {
padding: 0;
margin: 0;
border-top: 0;
border-left: 0;
}
#crayon-editor-controls .ui-tabs-nav * {
border-radius: 0px;
}
#crayon-editor-controls .ui-tabs-nav {
padding: 0;
margin: 0;
}
#crayon-editor-controls .ui-tabs-nav,
#crayon-editor-controls .ui-tabs-nav li,
#crayon-editor-controls .ui-tabs-nav li a {
height: 33px;
line-height: 33px;
padding: 0;
}
#crayon-editor-controls .ui-tabs-nav li a,
#crayon-editor-controls .ui-tabs-nav li {
float: left;
width: 70px;
}
#crayon-editor-controls.ui-tabs {
padding: 0;
margin: 0;
}
#crayon-editor-controls .ui-widget-header {
width: 1000px;
overflow: hidden;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
#crayon-editor-controls .ui-widget-header li:last-child {
border-right: none !important;
}
#crayon-editor-control-wrapper .ui-widget-content {
border: 0;
background: none;
}
#crayon-editor-controls .ui-widget-content {
border: 1px solid #bbb;
border-top-style: none;
background: #f5f5f5 50% top repeat-x;
color: #333333;
padding: 0;
}
.ui-colorpicker-preview-container .ui-colorpicker-border,
.ui-colorpicker-preview-initial,
.ui-colorpicker-preview-current {
height: 20px;
}
.ui-colorpicker .ui-colorpicker-mode {
margin-right: 5px;
}
.ui-colorpicker-swatches {
height: auto;
}
.ui-colorpicker {
z-index: 100 !important;
}
.crayon-tab-information {
background: url(images/information.png) no-repeat top center;
}
.crayon-tab-highlighting {
background: url(images/highlighting.png) no-repeat top center;
}
.crayon-tab-frame {
background: url(images/frame.png) no-repeat top center;
}
.crayon-tab-lines {
background: url(images/lines.png) no-repeat top center;
}
.crayon-tab-numbers {
background: url(images/numbers.png) no-repeat top center;
}
.crayon-tab-toolbar {
background: url(images/toolbar.png) no-repeat top center;
}
#crayon-editor-controls .ui-widget-header {
border: 1px solid #b3b3b3;
border-bottom: 1px solid #666;
background: #929292 url(images/button.png) center bottom repeat-x;
color: #474747;
font-weight: bold;
}
#crayon-editor-controls .ui-state-default,
#crayon-editor-controls .ui-widget-content .ui-state-default,
#crayon-editor-controls .ui-widget-header .ui-state-default {
border: none;
background: #929292 url(images/button.png) center bottom repeat-x;
font-weight: bold;
color: #545454;
border-top: 1px solid #ccc !important;
}
#crayon-editor-controls .ui-state-hover,
#crayon-editor-controls .ui-widget-content .ui-state-hover,
#crayon-editor-controls .ui-widget-header .ui-state-hover,
#crayon-editor-controls .ui-state-focus,
#crayon-editor-controls .ui-widget-content .ui-state-focus,
#crayon-editor-controls .ui-widget-header .ui-state-focus {
border: none;
background: #b3b3b3 url(images/button-pressed.png) center bottom repeat-x;
border-top: 1px solid #eee !important;
font-weight: bold;
color: #00467a;
}
#crayon-editor-controls .ui-state-active,
#crayon-editor-controls .ui-widget-content .ui-state-active,
#crayon-editor-controls .ui-widget-header .ui-state-active {
border: none;
background: #b3b3b3 url(images/button-pressed.png) center bottom repeat-x;
font-weight: bold;
color: #4f4f4f;
border-top: 1px solid #eee !important;
}
.wp-dialog {
min-width: 300px;
}
.wp-dialog .ui-dialog-content {
padding: 10px;
min-height: 10px !important;
}
.wp-dialog .ui-dialog-content td {
padding: 5px 0;
}
.wp-dialog .ui-dialog-content .field-table td input,
.wp-dialog .ui-dialog-content .field-table {
width: 100%;
}
.ui-colorpicker-dialog {
width: 575px !important;
height: 350px !important;
/*position: fixed;*/
/*left: auto;*/
/*right: 450px;*/
bottom: 0;
}
.ui-colorpicker-dialog .ui-colorpicker-bar-container {
padding-right: 5px !important;
}
.ui-colorpicker-dialog .ui-dialog-buttonpane {
margin-top: 0;
padding-top: 0;
}
.ui-colorpicker-dialog .ui-dialog-content {
padding-bottom: 0;
}
/* {*/
/*height: auto !important;*/
/*}*/

View File

@ -0,0 +1,655 @@
// Crayon Syntax Highlighter Theme Editor JavaScript
(function ($) {
CrayonSyntaxThemeEditor = new function () {
var base = this;
var crayonSettings = CrayonSyntaxSettings;
var adminSettings = CrayonAdminSettings;
var settings = CrayonThemeEditorSettings;
var strings = CrayonThemeEditorStrings;
var adminStrings = CrayonAdminStrings;
var admin = CrayonSyntaxAdmin;
var preview, previewCrayon, previewCSS, status, title, info;
var colorPickerPos;
var changed, loaded;
var themeID, themeJSON, themeCSS, themeStr, themeInfo;
var reImportant = /\s+!important$/gmi;
var reSize = /^[0-9-]+px$/;
var reCopy = /-copy(-\d+)?$/;
var changedAttr = 'data-value';
var borderCSS = {'border': true, 'border-left': true, 'border-right': true, 'border-top': true, 'border-bottom': true};
base.init = function (callback) {
// Called only once
CrayonUtil.log('editor init');
base.initUI();
if (callback) {
callback();
}
};
base.show = function (callback, crayon) {
// Called each time editor is shown
previewCrayon = crayon.find('.crayon-syntax');
preview.append(crayon)
base.load();
if (callback) {
callback();
}
};
base.load = function () {
loaded = false;
themeStr = adminSettings.currThemeCSS;
themeID = adminSettings.currTheme;
changed = false;
themeJSON = CSSJSON.toJSON(themeStr, {
stripComments: true,
split: true
});
themeJSON = base.filterCSS(themeJSON);
CrayonUtil.log(themeJSON);
themeInfo = base.readCSSInfo(themeStr);
base.removeExistingCSS();
base.initInfoUI();
base.updateTitle();
base.updateInfo();
base.setFieldValues(themeInfo);
base.populateAttributes();
base.updateLiveCSS();
base.updateUI();
loaded = true;
};
base.save = function () {
// Update info from form fields
themeInfo = base.getFieldValues($.keys(themeInfo));
// Get the names of the fields and map them to their values
var names = base.getFieldNames(themeInfo);
var info = {};
for (var id in themeInfo) {
info[names[id]] = themeInfo[id];
}
// Update attributes
base.persistAttributes();
// Save
themeCSS = CSSJSON.toCSS(themeJSON);
var newThemeStr = base.writeCSSInfo(info) + themeCSS;
CrayonUtil.postAJAX({
action: 'crayon-theme-editor-save',
id: themeID,
name: base.getName(),
css: newThemeStr
}, function (result) {
status.show();
result = parseInt(result);
if (result > 0) {
status.html(strings.success);
if (result === 2) {
window.GET['theme-editor'] = 1;
CrayonUtil.reload();
}
} else {
status.html(strings.fail);
}
changed = false;
setTimeout(function () {
status.fadeOut();
}, 1000);
});
};
base.del = function (id, name) {
admin.createDialog({
title: strings.del,
html: strings.deleteThemeConfirm.replace('%s', name),
yes: function () {
CrayonUtil.postAJAX({
action: 'crayon-theme-editor-delete',
id: id
}, function (result) {
if (result > 0) {
CrayonUtil.reload();
} else {
admin.createAlert({
html: strings.deleteFail + ' ' + strings.checkLog
});
}
});
},
options: {
selectedButtonIndex: 2
}
});
};
base.duplicate = function (id, name) {
base.createPrompt({
//html: "Are you sure you want to duplicate the '" + name + "' theme?",
title: strings.duplicate,
text: strings.newName,
value: base.getNextAvailableName(id),
ok: function (val) {
CrayonUtil.postAJAX({
action: 'crayon-theme-editor-duplicate',
id: id,
name: val
}, function (result) {
if (result > 0) {
CrayonUtil.reload();
} else {
admin.createAlert({
html: strings.duplicateFail + ' ' + strings.checkLog
});
}
});
}
});
};
base.submit = function (id, name) {
base.createPrompt({
title: strings.submit,
desc: strings.submitText,
text: strings.message,
value: strings.submitMessage,
ok: function (val) {
CrayonUtil.postAJAX({
action: 'crayon-theme-editor-submit',
id: id,
message: val
}, function (result) {
var msg = result > 0 ? strings.submitSucceed : strings.submitFail + ' ' + strings.checkLog;
admin.createAlert({
html: msg
});
});
}
});
};
base.getNextAvailableName = function (id) {
var next = base.getNextAvailableID(id);
return base.idToName(next[1]);
};
base.getNextAvailableID = function (id) {
var themes = adminSettings.themes;
var count = 0;
if (reCopy.test(id)) {
// Remove the "copy" if it already exists
var newID = id.replace(reCopy, '');
if (newID.length > 0) {
id = newID;
}
}
var nextID = id;
while (nextID in themes) {
count++;
if (count == 1) {
nextID = id + '-copy';
} else {
nextID = id + '-copy-' + count.toString();
}
}
return [count, nextID];
};
base.readCSSInfo = function (cssStr) {
var infoStr = /^\s*\/\*[\s\S]*?\*\//gmi.exec(cssStr);
var themeInfo = {};
var match = null;
var infoRegex = /([^\r\n:]*[^\r\n\s:])\s*:\s*([^\r\n]+)/gmi;
while ((match = infoRegex.exec(infoStr)) != null) {
themeInfo[base.nameToID(match[1])] = CrayonUtil.encode_html(match[2]);
}
// Force title case on the name
if (themeInfo.name) {
themeInfo.name = base.idToName(themeInfo.name);
}
return themeInfo;
};
base.getFieldName = function (id) {
var name = '';
if (id in settings.fields) {
name = settings.fields[id];
} else {
name = base.idToName(id);
}
return name;
};
base.getFieldNames = function (fields) {
var names = {};
for (var id in fields) {
names[id] = base.getFieldName(id);
}
return names;
};
base.removeExistingCSS = function () {
// Remove the old <style> tag to prevent clashes
preview.find('link[rel="stylesheet"][href*="' + adminSettings.currThemeURL + '"]').remove()
};
base.initInfoUI = function () {
CrayonUtil.log(themeInfo);
// TODO abstract
var names = base.getFieldNames(themeInfo);
var fields = {};
for (var id in names) {
var name = names[id];
var value = themeInfo[id];
fields[name] = base.createInput(id, value);
}
$('#tabs-1-contents').html(base.createForm(fields));
base.getField('name').bind('change keydown keyup', function () {
themeInfo.name = base.getFieldValue('name');
base.updateTitle();
});
};
base.nameToID = function (name) {
return name.toLowerCase().replace(/\s+/gmi, '-');
};
base.idToName = function (id) {
id = id.replace(/-/gmi, ' ');
return id.toTitleCase();
};
base.getName = function () {
var name = themeInfo.name;
if (!name) {
name = base.idToName(themeID);
}
return name;
};
base.getField = function (id) {
return $('#' + settings.cssInputPrefix + id);
};
base.getFieldValue = function (id) {
return base.getElemValue(base.getField(id));
};
base.getElemValue = function (elem) {
if (elem) {
// TODO add support for checkboxes etc.
return elem.val();
} else {
return null;
}
};
base.getFieldValues = function (fields) {
var info = {};
$(fields).each(function (i, id) {
info[id] = base.getFieldValue(id);
});
return info;
};
base.setFieldValue = function (id, value) {
base.setElemValue(base.getField(id), value);
};
base.setFieldValues = function (obj) {
for (var i in obj) {
base.setFieldValue(i, obj[i]);
}
};
base.setElemValue = function (elem, val) {
if (elem) {
// TODO add support for checkboxes etc.
return elem.val(val);
} else {
return false;
}
};
base.getAttribute = function (element, attribute) {
return base.getField(element + '_' + attribute);
};
base.getAttributes = function () {
return $('.' + settings.cssInputPrefix + settings.attribute);
};
base.visitAttribute = function (attr, callback) {
var elems = themeJSON.children;
var root = settings.cssThemePrefix + base.nameToID(themeInfo.name);
var dataElem = attr.attr('data-element');
var dataAttr = attr.attr('data-attribute');
var elem = elems[root + dataElem];
callback(attr, elem, dataElem, dataAttr, root, elems);
};
base.persistAttributes = function (remove_default) {
remove_default = CrayonUtil.setDefault(remove_default, true);
base.getAttributes().each(function () {
base.persistAttribute($(this), remove_default);
});
};
base.persistAttribute = function (attr, remove_default) {
remove_default = CrayonUtil.setDefault(remove_default, true);
base.visitAttribute(attr, function (attr, elem, dataElem, dataAttr, root, elems) {
if (remove_default && attr.prop('tagName') == 'SELECT' && attr.val() == attr.attr('data-default')) {
if (elem) {
// If default is selected in a dropdown, then remove
delete elem.attributes[dataAttr];
}
return;
}
var val = base.getElemValue(attr);
if ((val == null || val == '')) {
// No value given
if (remove_default && elem) {
delete elem.attributes[dataAttr];
return;
}
} else {
val = base.addImportant(val);
if (!elem) {
elem = elems[root + dataElem] = {
attributes: {},
children: {}
};
}
elem.attributes[dataAttr] = val;
}
CrayonUtil.log(dataElem + ' ' + dataAttr);
});
};
base.populateAttributes = function ($change) {
var elems = themeJSON.children;
var root = settings.cssThemePrefix + base.nameToID(themeInfo.name);
CrayonUtil.log(elems, root);
base.getAttributes().each(function () {
base.visitAttribute($(this), function (attr, elem, dataElem, dataAttr, root, elems) {
if (elem) {
if (dataAttr in elem.attributes) {
var val = base.removeImportant(elem.attributes[dataAttr]);
base.setElemValue(attr, val);
attr.trigger('change');
}
}
});
});
};
base.addImportant = function (attr) {
if (!reImportant.test(attr)) {
attr = attr + ' !important';
}
return attr;
};
base.removeImportant = function (attr) {
return attr.replace(reImportant, '');
};
base.isImportant = function (attr) {
return reImportant.exec(attr) != null;
};
base.appendStyle = function (css) {
previewCSS.html('<style>' + css + '</style>');
};
base.removeStyle = function () {
previewCSS.html('');
};
base.writeCSSInfo = function (info) {
var infoStr = '/*\n';
for (var field in info) {
infoStr += field + ': ' + info[field] + '\n';
}
return infoStr + '*/\n';
};
base.filterCSS = function (css) {
// Split all border CSS attributes into individual attributes
for (var child in css.children) {
var atts = css.children[child].attributes;
for (var att in atts) {
if (att in borderCSS) {
var rules = base.getBorderCSS(atts[att]);
for (var rule in rules) {
atts[att + '-' + rule] = rules[rule];
}
delete atts[att];
}
}
}
return css;
},
base.getBorderCSS = function (css) {
var result = {};
var important = base.isImportant(css);
$.each(strings.borderStyles, function (i, style) {
if (css.indexOf(style) >= 0) {
result.style = style;
}
});
var width = /\d+\s*(px|%|em|rem)/gi.exec(css);
if (width) {
result.width = width[0];
}
var color = /#\w+/gi.exec(css);
if (color) {
result.color = color[0];
}
if (important) {
for (var rule in result) {
result[rule] = base.addImportant(result[rule]);
}
}
return result;
},
base.createPrompt = function (args) {
args = $.extend({
title: adminStrings.prompt,
text: adminStrings.value,
desc: null,
value: '',
options: {
buttons: {
"OK": function () {
if (args.ok) {
args.ok(base.getFieldValue('prompt-text'));
}
$(this).crayonDialog('close');
},
"Cancel": function () {
$(this).crayonDialog('close');
}
},
open: function () {
base.getField('prompt-text').val(args.value).focus();
}
}
}, args);
args.html = '<table class="field-table crayon-prompt-' + base.nameToID(args.title) + '">';
if (args.desc) {
args.html += '<tr><td colspan="2">' + args.desc + '</td></tr>';
}
args.html += '<tr><td>' + args.text + ':</td><td>' + base.createInput('prompt-text') + '</td></tr>';
args.html += '</table>';
var options = {width: '400px'};
admin.createDialog(args, options);
};
base.initUI = function () {
// Bind events
preview = $('#crayon-editor-preview');
previewCSS = $('#crayon-editor-preview-css');
status = $('#crayon-editor-status');
title = $('#crayon-theme-editor-name');
info = $('#crayon-theme-editor-info');
$('#crayon-editor-controls').tabs();
$('#crayon-editor-back').click(function () {
if (changed) {
admin.createDialog({
html: strings.discardConfirm,
title: adminStrings.confirm,
yes: function () {
showMain();
}
});
} else {
showMain();
}
});
$('#crayon-editor-save').click(base.save);
// Set up jQuery UI
base.getAttributes().each(function () {
var attr = $(this);
var type = attr.attr('data-group');
if (type == 'color') {
var args = {
parts: 'full',
showNoneButton: true,
colorFormat: '#HEX'
};
args.open = function (e, color) {
$('.ui-colorpicker-dialog .ui-button').addClass('button-primary');
if (colorPickerPos) {
var picker = $('.ui-colorpicker-dialog:visible');
picker.css('left', colorPickerPos.left);
// picker.css('top', colorPickerPos.top);
}
};
args.select = function (e, color) {
attr.trigger('change');
};
args.close = function (e, color) {
attr.trigger('change');
};
attr.colorpicker(args);
attr.bind('change', function () {
var hex = attr.val();
attr.css('background-color', hex);
attr.css('color', CrayonUtil.getReadableColor(hex));
});
} else if (type == 'size') {
attr.bind('change', function () {
var val = attr.val();
if (!reSize.test(val)) {
val = CrayonUtil.removeChars('^0-9-', val);
if (val != '') {
attr.val(val + 'px');
}
}
});
}
if (type != 'color') {
// For regular text boxes, capture changes on keys
attr.bind('keydown keyup', function () {
if (attr.attr(changedAttr) != attr.val()) {
CrayonUtil.log('triggering', attr.attr(changedAttr), attr.val());
attr.trigger('change');
}
});
}
// Update CSS changes to the live instance
attr.bind('change', function () {
if (attr.attr(changedAttr) == attr.val()) {
return;
} else {
attr.attr(changedAttr, attr.val());
}
if (loaded) {
base.persistAttribute(attr);
base.updateLiveCSS();
}
});
});
$('.ui-colorpicker-dialog').addClass('wp-dialog');
$('.ui-colorpicker-dialog').mouseup(function () {
base.colorPickerMove($(this));
});
};
base.colorPickerMove = function (picker) {
if (picker) {
colorPickerPos = {left: picker.css('left'), top: picker.css('top')};
}
};
base.updateLiveCSS = function (clone) {
clone = CrayonUtil.setDefault(clone, false);
if (previewCrayon) {
var json;
if (clone) {
var id = previewCrayon.attr('id');
json = $.extend(true, {}, themeJSON);
$.each(json.children, function (child) {
json.children['#' + id + child] = json.children[child];
delete json.children[child];
});
} else {
json = themeJSON;
}
base.appendStyle(CSSJSON.toCSS(json));
}
};
base.updateUI = function () {
$('#crayon-editor-controls input, #crayon-editor-controls select').bind('change', function () {
changed = true;
});
};
base.createInput = function (id, value, type) {
value = CrayonUtil.setDefault(value, '');
type = CrayonUtil.setDefault(type, 'text');
return '<input id="' + settings.cssInputPrefix + id + '" class="' + settings.cssInputPrefix + type + '" type="' + type + '" value="' + value + '" />';
};
base.createForm = function (inputs) {
var str = '<form class="' + settings.prefix + '-form"><table>';
$.each(inputs, function (input) {
str += '<tr><td class="field">' + input + '</td><td class="value">' + inputs[input] + '</td></tr>';
});
str += '</table></form>';
return str;
};
var showMain = function () {
admin.resetPreview();
admin.preview_update();
admin.show_theme_info();
admin.show_main();
//preview.html('');
};
base.updateTitle = function () {
var name = base.getName();
if (adminSettings.editing_theme) {
title.html(strings.editingTheme.replace('%s', name));
} else {
title.html(strings.creatingTheme.replace('%s', name));
}
};
base.updateInfo = function () {
info.html('<a target="_blank" href="' + adminSettings.currThemeURL + '">' + adminSettings.currThemeURL + '</a>');
};
};
})(jQueryCrayon);

View File

@ -0,0 +1,879 @@
<?php
class CrayonHTMLElement {
public $id;
public $class = '';
public $tag = 'div';
public $closed = FALSE;
public $contents = '';
public $attributes = array();
const CSS_INPUT_PREFIX = "crayon-theme-input-";
public static $borderStyles = array(
'none',
'hidden',
'dotted',
'dashed',
'solid',
'double',
'groove',
'ridge',
'inset',
'outset',
'inherit'
);
public function __construct($id) {
$this->id = $id;
}
public function addClass($class) {
$this->class .= ' ' . self::CSS_INPUT_PREFIX . $class;
}
public function addAttributes($atts) {
$this->attributes = array_merge($this->attributes, $atts);
}
public function attributeString() {
$str = '';
foreach ($this->attributes as $k => $v) {
$str .= "$k=\"$v\" ";
}
return $str;
}
public function __toString() {
return '<' . $this->tag . ' id="' . self::CSS_INPUT_PREFIX . $this->id . '" class="' . self::CSS_INPUT_PREFIX . $this->class . '" ' . $this->attributeString() . ($this->closed ? ' />' : ' >' . $this->contents . "</$this->tag>");
}
}
class CrayonHTMLInput extends CrayonHTMLElement {
public $name;
public $type;
public function __construct($id, $name = NULL, $value = '', $type = 'text') {
parent::__construct($id);
$this->tag = 'input';
$this->closed = TRUE;
if ($name === NULL) {
$name = CrayonUserResource::clean_name($id);
}
$this->name = $name;
$this->class .= $type;
$this->addAttributes(array(
'type' => $type,
'value' => $value
));
}
}
class CrayonHTMLSelect extends CrayonHTMLInput {
public $options;
public $selected = NULL;
public function __construct($id, $name = NULL, $value = '', $options = array()) {
parent::__construct($id, $name, 'select');
$this->tag = 'select';
$this->closed = FALSE;
$this->addOptions($options);
}
public function addOptions($options, $default = NULL) {
for ($i = 0; $i < count($options); $i++) {
$key = $options[$i];
$value = isset($options[$key]) ? $options[$key] : $key;
$this->options[$key] = $value;
}
if ($default === NULL && count($options) > 1) {
$this->attributes['data-default'] = $options[0];
} else {
$this->attributes['data-default'] = $default;
}
}
public function getOptionsString() {
$str = '';
foreach ($this->options as $k => $v) {
$selected = $this->selected == $k ? 'selected="selected"' : '';
$str .= "<option value=\"$k\" $selected>$v</option>";
}
return $str;
}
public function __toString() {
$this->contents = $this->getOptionsString();
return parent::__toString();
}
}
class CrayonHTMLSeparator extends CrayonHTMLElement {
public $name = '';
public function __construct($name) {
parent::__construct($name);
$this->name = $name;
}
}
class CrayonHTMLTitle extends CrayonHTMLSeparator {
}
class CrayonThemeEditorWP {
public static $attributes = NULL;
public static $attributeGroups = NULL;
public static $attributeGroupsInverse = NULL;
public static $attributeTypes = NULL;
public static $attributeTypesInverse = NULL;
public static $infoFields = NULL;
public static $infoFieldsInverse = NULL;
public static $settings = NULL;
public static $strings = NULL;
const ATTRIBUTE = 'attribute';
const RE_COMMENT = '#^\s*\/\*[\s\S]*?\*\/#msi';
public static function initFields() {
if (self::$infoFields === NULL) {
self::$infoFields = array(
// These are canonical and can't be translated, since they appear in the comments of the CSS
'name' => 'Name',
'description' => 'Description',
'version' => 'Version',
'author' => 'Author',
'url' => 'URL',
'original-author' => 'Original Author',
'notes' => 'Notes',
'maintainer' => 'Maintainer',
'maintainer-url' => 'Maintainer URL'
);
self::$infoFieldsInverse = CrayonUtil::array_flip(self::$infoFields);
// A map of CSS element name and property to name
self::$attributes = array();
// A map of CSS attribute to input type
self::$attributeGroups = array(
'color' => array('background', 'background-color', 'border-color', 'color', 'border-top-color', 'border-bottom-color', 'border-left-color', 'border-right-color'),
'size' => array('border-width'),
'border-style' => array('border-style', 'border-bottom-style', 'border-top-style', 'border-left-style', 'border-right-style')
);
self::$attributeGroupsInverse = CrayonUtil::array_flip(self::$attributeGroups);
// Mapping of input type to attribute group
self::$attributeTypes = array(
'select' => array('border-style', 'font-style', 'font-weight', 'text-decoration')
);
self::$attributeTypesInverse = CrayonUtil::array_flip(self::$attributeTypes);
}
}
public static function initSettings() {
CrayonSettingsWP::load_settings();
self::initFields();
self::initStrings();
if (self::$settings === NULL) {
self::$settings = array(
// Only things the theme editor needs
'cssThemePrefix' => CrayonThemes::CSS_PREFIX,
'cssInputPrefix' => CrayonHTMLElement::CSS_INPUT_PREFIX,
'attribute' => self::ATTRIBUTE,
'fields' => self::$infoFields,
'fieldsInverse' => self::$infoFieldsInverse,
'prefix' => 'crayon-theme-editor'
);
}
}
public static function initStrings() {
if (self::$strings === NULL) {
self::$strings = array(
// These appear only in the UI and can be translated
'userTheme' => crayon__("User-Defined Theme"),
'stockTheme' => crayon__("Stock Theme"),
'success' => crayon__("Success!"),
'fail' => crayon__("Failed!"),
'delete' => crayon__("Delete"),
'deleteThemeConfirm' => crayon__("Are you sure you want to delete the \"%s\" theme?"),
'deleteFail' => crayon__("Delete failed!"),
'duplicate' => crayon__("Duplicate"),
'newName' => crayon__("New Name"),
'duplicateFail' => crayon__("Duplicate failed!"),
'checkLog' => crayon__("Please check the log for details."),
'discardConfirm' => crayon__("Are you sure you want to discard all changes?"),
'editingTheme' => crayon__("Editing Theme: %s"),
'creatingTheme' => crayon__("Creating Theme: %s"),
'submit' => crayon__("Submit Your Theme"),
'submitText' => crayon__("Submit your User Theme for inclusion as a Stock Theme in Crayon! This will email me your theme - make sure it's considerably different from the stock themes :)"),
'message' => crayon__("Message"),
'submitMessage' => crayon__("Please include this theme in Crayon!"),
'submitSucceed' => crayon__("Submit was successful."),
'submitFail' => crayon__("Submit failed!"),
'borderStyles' => CrayonHTMLElement::$borderStyles
);
}
}
public static function admin_resources() {
global $CRAYON_VERSION;
self::initSettings();
$path = dirname(dirname(__FILE__));
wp_enqueue_script('cssjson_js', plugins_url(CRAYON_CSSJSON_JS, $path), $CRAYON_VERSION);
wp_enqueue_script('jquery_colorpicker_js', plugins_url(CRAYON_JS_JQUERY_COLORPICKER, $path), array('jquery', 'jquery-ui-core', 'jquery-ui-widget', 'jquery-ui-tabs', 'jquery-ui-draggable', 'jquery-ui-dialog', 'jquery-ui-position', 'jquery-ui-mouse', 'jquery-ui-slider', 'jquery-ui-droppable', 'jquery-ui-selectable', 'jquery-ui-resizable'), $CRAYON_VERSION);
wp_enqueue_script('jquery_tinycolor_js', plugins_url(CRAYON_JS_TINYCOLOR, $path), array(), $CRAYON_VERSION);
if (CRAYON_MINIFY) {
wp_enqueue_script('crayon_theme_editor', plugins_url(CRAYON_THEME_EDITOR_JS, $path), array('jquery', 'crayon_js', 'crayon_admin_js', 'cssjson_js', 'jquery_colorpicker_js', 'jquery_tinycolor_js'), $CRAYON_VERSION);
} else {
wp_enqueue_script('crayon_theme_editor', plugins_url(CRAYON_THEME_EDITOR_JS, $path), array('jquery', 'crayon_util_js', 'crayon_admin_js', 'cssjson_js', 'jquery_colorpicker_js', 'jquery_tinycolor_js'), $CRAYON_VERSION);
}
wp_localize_script('crayon_theme_editor', 'CrayonThemeEditorSettings', self::$settings);
wp_localize_script('crayon_theme_editor', 'CrayonThemeEditorStrings', self::$strings);
wp_enqueue_style('crayon_theme_editor', plugins_url(CRAYON_THEME_EDITOR_STYLE, $path), array('wp-jquery-ui-dialog'), $CRAYON_VERSION);
wp_enqueue_style('jquery_colorpicker', plugins_url(CRAYON_CSS_JQUERY_COLORPICKER, $path), array(), $CRAYON_VERSION);
}
public static function form($inputs) {
$str = '<form class="' . self::$settings['prefix'] . '-form"><table>';
$sepCount = 0;
foreach ($inputs as $input) {
if ($input instanceof CrayonHTMLInput) {
$str .= self::formField($input->name, $input);
} else if ($input instanceof CrayonHTMLSeparator) {
$sepClass = '';
if ($input instanceof CrayonHTMLTitle) {
$sepClass .= ' title';
}
if ($sepCount == 0) {
$sepClass .= ' first';
}
$str .= '<tr class="separator' . $sepClass . '"><td colspan="2"><div class="content">' . $input->name . '</div></td></tr>';
$sepCount++;
} else if (is_array($input) && count($input) > 1) {
$name = $input[0];
$fields = '<table class="split-field"><tr>';
$percent = 100 / count($input);
for ($i = 1; $i < count($input); $i++) {
$class = $i == count($input) - 1 ? 'class="last"' : '';
$fields .= '<td ' . $class . ' style="width: ' . $percent . '%">' . $input[$i] . '</td>';
}
$fields .= '</tr></table>';
$str .= self::formField($name, $fields, 'split');
}
}
$str .= '</table></form>';
return $str;
}
public static function formField($name, $field, $class = '') {
return '<tr><td class="field ' . $class . '">' . $name . '</td><td class="value ' . $class . '">' . $field . '</td></tr>';
}
public static function content() {
self::initSettings();
$theme = CrayonResources::themes()->get_default();
$editing = false;
if (isset($_GET['curr_theme'])) {
$currTheme = CrayonResources::themes()->get($_GET['curr_theme']);
if ($currTheme) {
$theme = $currTheme;
}
}
if (isset($_GET['editing'])) {
$editing = CrayonUtil::str_to_bool($_GET['editing'], FALSE);
}
$tInformation = crayon__("Information");
$tHighlighting = crayon__("Highlighting");
$tFrame = crayon__("Frame");
$tLines = crayon__("Lines");
$tNumbers = crayon__("Line Numbers");
$tToolbar = crayon__("Toolbar");
$tBackground = crayon__("Background");
$tText = crayon__("Text");
$tBorder = crayon__("Border");
$tTopBorder = crayon__("Top Border");
$tBottomBorder = crayon__("Bottom Border");
$tBorderRight = crayon__("Right Border");
$tHover = crayon__("Hover");
$tActive = crayon__("Active");
$tPressed = crayon__("Pressed");
$tHoverPressed = crayon__("Pressed & Hover");
$tActivePressed = crayon__("Pressed & Active");
$tTitle = crayon__("Title");
$tButtons = crayon__("Buttons");
$tNormal = crayon__("Normal");
$tInline = crayon__("Inline");
$tStriped = crayon__("Striped");
$tMarked = crayon__("Marked");
$tStripedMarked = crayon__("Striped & Marked");
$tLanguage = crayon__("Language");
$top = '.crayon-top';
$bottom = '.crayon-bottom';
$hover = ':hover';
$active = ':active';
$pressed = '.crayon-pressed';
?>
<div
id="icon-options-general" class="icon32"></div>
<h2>
Crayon Syntax Highlighter
<?php crayon_e('Theme Editor'); ?>
</h2>
<h3 id="<?php echo self::$settings['prefix'] ?>-name">
<?php
// if ($editing) {
// echo sprintf(crayon__('Editing "%s" Theme'), $theme->name());
// } else {
// echo sprintf(crayon__('Creating Theme From "%s"'), $theme->name());
// }
?>
</h3>
<div id="<?php echo self::$settings['prefix'] ?>-info"></div>
<p>
<a id="crayon-editor-back" class="button-primary"><?php crayon_e("Back To Settings"); ?></a>
<a id="crayon-editor-save" class="button-primary"><?php crayon_e("Save"); ?></a>
<span id="crayon-editor-status"></span>
</p>
<?php //crayon_e('Use the Sidebar on the right to change the Theme of the Preview window.') ?>
<div id="crayon-editor-top-controls"></div>
<table id="crayon-editor-table" style="width: 100%;" cellspacing="5"
cellpadding="0">
<tr>
<td id="crayon-editor-preview-wrapper">
<div id="crayon-editor-preview"></div>
</td>
<div id="crayon-editor-preview-css"></div>
<td id="crayon-editor-control-wrapper">
<div id="crayon-editor-controls">
<ul>
<li title="<?php echo $tInformation ?>"><a class="crayon-tab-information" href="#tabs-1"></a></li>
<li title="<?php echo $tHighlighting ?>"><a class="crayon-tab-highlighting" href="#tabs-2"></a></li>
<li title="<?php echo $tFrame ?>"><a class="crayon-tab-frame" href="#tabs-3"></a></li>
<li title="<?php echo $tLines ?>"><a class="crayon-tab-lines" href="#tabs-4"></a></li>
<li title="<?php echo $tNumbers ?>"><a class="crayon-tab-numbers" href="#tabs-5"></a></li>
<li title="<?php echo $tToolbar ?>"><a class="crayon-tab-toolbar" href="#tabs-6"></a></li>
</ul>
<div id="tabs-1">
<?php
self::createAttributesForm(array(
new CrayonHTMLTitle($tInformation)
));
?>
<div id="tabs-1-contents"></div>
<!-- Auto-filled by theme_editor.js -->
</div>
<div id="tabs-2">
<?php
$highlight = ' .crayon-pre';
$elems = array(
'c' => crayon__("Comment"),
's' => crayon__("String"),
'p' => crayon__("Preprocessor"),
'ta' => crayon__("Tag"),
'k' => crayon__("Keyword"),
'st' => crayon__("Statement"),
'r' => crayon__("Reserved"),
't' => crayon__("Type"),
'm' => crayon__("Modifier"),
'i' => crayon__("Identifier"),
'e' => crayon__("Entity"),
'v' => crayon__("Variable"),
'cn' => crayon__("Constant"),
'o' => crayon__("Operator"),
'sy' => crayon__("Symbol"),
'n' => crayon__("Notation"),
'f' => crayon__("Faded"),
'h' => crayon__("HTML"),
'' => crayon__("Unhighlighted")
);
$atts = array(new CrayonHTMLTitle($tHighlighting));
foreach ($elems as $class => $name) {
$fullClass = $class != '' ? $highlight . ' .crayon-' . $class : $highlight;
$atts[] = array(
$name,
self::createAttribute($fullClass, 'color'),
self::createAttribute($fullClass, 'font-weight'),
self::createAttribute($fullClass, 'font-style'),
self::createAttribute($fullClass, 'text-decoration')
);
}
self::createAttributesForm($atts);
?>
</div>
<div id="tabs-3">
<?php
$inline = '-inline';
self::createAttributesForm(array(
new CrayonHTMLTitle($tFrame),
new CrayonHTMLSeparator($tNormal),
// self::createAttribute('', 'background', $tBackground),
array(
$tBorder,
self::createAttribute('', 'border-width'),
self::createAttribute('', 'border-color'),
self::createAttribute('', 'border-style')
),
new CrayonHTMLSeparator($tInline),
self::createAttribute($inline, 'background', $tBackground),
array(
$tBorder,
self::createAttribute($inline, 'border-width'),
self::createAttribute($inline, 'border-color'),
self::createAttribute($inline, 'border-style')
),
));
?>
</div>
<div id="tabs-4">
<?php
$stripedLine = ' .crayon-striped-line';
$markedLine = ' .crayon-marked-line';
$stripedMarkedLine = ' .crayon-marked-line.crayon-striped-line';
self::createAttributesForm(array(
new CrayonHTMLTitle($tLines),
new CrayonHTMLSeparator($tNormal),
self::createAttribute('', 'background', $tBackground),
new CrayonHTMLSeparator($tStriped),
self::createAttribute($stripedLine, 'background', $tBackground),
new CrayonHTMLSeparator($tMarked),
self::createAttribute($markedLine, 'background', $tBackground),
array(
$tBorder,
self::createAttribute($markedLine, 'border-width'),
self::createAttribute($markedLine, 'border-color'),
self::createAttribute($markedLine, 'border-style'),
),
self::createAttribute($markedLine . $top, 'border-top-style', $tTopBorder),
self::createAttribute($markedLine . $bottom, 'border-bottom-style', $tBottomBorder),
new CrayonHTMLSeparator($tStripedMarked),
self::createAttribute($stripedMarkedLine, 'background', $tBackground),
));
?>
</div>
<div id="tabs-5">
<?php
$nums = ' .crayon-table .crayon-nums';
$stripedNum = ' .crayon-striped-num';
$markedNum = ' .crayon-marked-num';
$stripedMarkedNum = ' .crayon-marked-num.crayon-striped-num';
self::createAttributesForm(array(
new CrayonHTMLTitle($tNumbers),
array(
$tBorderRight,
self::createAttribute($nums, 'border-right-width'),
self::createAttribute($nums, 'border-right-color'),
self::createAttribute($nums, 'border-right-style'),
),
new CrayonHTMLSeparator($tNormal),
self::createAttribute($nums, 'background', $tBackground),
self::createAttribute($nums, 'color', $tText),
new CrayonHTMLSeparator($tStriped),
self::createAttribute($stripedNum, 'background', $tBackground),
self::createAttribute($stripedNum, 'color', $tText),
new CrayonHTMLSeparator($tMarked),
self::createAttribute($markedNum, 'background', $tBackground),
self::createAttribute($markedNum, 'color', $tText),
array(
$tBorder,
self::createAttribute($markedNum, 'border-width'),
self::createAttribute($markedNum, 'border-color'),
self::createAttribute($markedNum, 'border-style'),
),
self::createAttribute($markedNum.$top, 'border-top-style', $tTopBorder),
self::createAttribute($markedNum.$bottom, 'border-bottom-style', $tBottomBorder),
new CrayonHTMLSeparator($tStripedMarked),
self::createAttribute($stripedMarkedNum, 'background', $tBackground),
self::createAttribute($stripedMarkedNum, 'color', $tText),
));
?>
</div>
<div id="tabs-6">
<?php
$toolbar = ' .crayon-toolbar';
$title = ' .crayon-title';
$button = ' .crayon-button';
$info = ' .crayon-info';
$language = ' .crayon-language';
self::createAttributesForm(array(
new CrayonHTMLTitle($tToolbar),
new CrayonHTMLSeparator($tFrame),
self::createAttribute($toolbar, 'background', $tBackground),
array(
$tBottomBorder,
self::createAttribute($toolbar, 'border-bottom-width'),
self::createAttribute($toolbar, 'border-bottom-color'),
self::createAttribute($toolbar, 'border-bottom-style'),
),
array(
$tTitle,
self::createAttribute($title, 'color'),
self::createAttribute($title, 'font-weight'),
self::createAttribute($title, 'font-style'),
self::createAttribute($title, 'text-decoration')
),
new CrayonHTMLSeparator($tButtons),
self::createAttribute($button, 'background-color', $tBackground),
self::createAttribute($button.$hover, 'background-color', $tHover),
self::createAttribute($button.$active, 'background-color', $tActive),
self::createAttribute($button.$pressed, 'background-color', $tPressed),
self::createAttribute($button.$pressed.$hover, 'background-color', $tHoverPressed),
self::createAttribute($button.$pressed.$active, 'background-color', $tActivePressed),
new CrayonHTMLSeparator($tInformation . ' ' . crayon__("(Used for Copy/Paste)")),
self::createAttribute($info, 'background', $tBackground),
array(
$tText,
self::createAttribute($info, 'color'),
self::createAttribute($info, 'font-weight'),
self::createAttribute($info, 'font-style'),
self::createAttribute($info, 'text-decoration')
),
array(
$tBottomBorder,
self::createAttribute($info, 'border-bottom-width'),
self::createAttribute($info, 'border-bottom-color'),
self::createAttribute($info, 'border-bottom-style'),
),
new CrayonHTMLSeparator($tLanguage),
array(
$tText,
self::createAttribute($language, 'color'),
self::createAttribute($language, 'font-weight'),
self::createAttribute($language, 'font-style'),
self::createAttribute($language, 'text-decoration')
),
self::createAttribute($language, 'background-color', $tBackground)
));
?>
</div>
</div>
</td>
</tr>
</table>
<?php
exit();
}
public static function createAttribute($element, $attribute, $name = NULL) {
$group = self::getAttributeGroup($attribute);
$type = self::getAttributeType($group);
if ($type == 'select') {
$input = new CrayonHTMLSelect($element . '_' . $attribute, $name);
if ($group == 'border-style') {
$input->addOptions(CrayonHTMLElement::$borderStyles);
} else if ($group == 'float') {
$input->addOptions(array(
'left',
'right',
'both',
'none',
'inherit'
));
} else if ($group == 'font-style') {
$input->addOptions(array(
'normal',
'italic',
'oblique',
'inherit'
));
} else if ($group == 'font-weight') {
$input->addOptions(array(
'normal',
'bold',
'bolder',
'lighter',
'100',
'200',
'300',
'400',
'500',
'600',
'700',
'800',
'900',
'inherit'
));
} else if ($group == 'text-decoration') {
$input->addOptions(array(
'none',
'underline',
'overline',
'line-through',
'blink',
'inherit'
));
}
} else {
$input = new CrayonHTMLInput($element . '_' . $attribute, $name);
}
$input->addClass(self::ATTRIBUTE);
$input->addAttributes(array(
'data-element' => $element,
'data-attribute' => $attribute,
'data-group' => $group
));
return $input;
}
public static function createAttributesForm($atts) {
echo self::form($atts);
}
/**
* Saves the given theme id and css, making any necessary path and id changes to ensure the new theme is valid.
* Echos 0 on failure, 1 on success and 2 on success and if paths have changed.
*/
public static function save() {
CrayonSettingsWP::load_settings();
$oldID = stripslashes($_POST['id']);
$name = stripslashes($_POST['name']);
$css = stripslashes($_POST['css']);
$change_settings = CrayonUtil::set_default($_POST['change_settings'], TRUE);
$allow_edit = CrayonUtil::set_default($_POST['allow_edit'], TRUE);
$allow_edit_stock_theme = CrayonUtil::set_default($_POST['allow_edit_stock_theme'], CRAYON_DEBUG);
$delete = CrayonUtil::set_default($_POST['delete'], TRUE);
$oldTheme = CrayonResources::themes()->get($oldID);
if (!empty($oldID) && !empty($css) && !empty($name)) {
// By default, expect a user theme to be saved - prevents editing stock themes
// If in DEBUG mode, then allow editing stock themes.
$user = $oldTheme !== NULL && $allow_edit_stock_theme ? $oldTheme->user() : TRUE;
$oldPath = CrayonResources::themes()->path($oldID);
$oldDir = CrayonResources::themes()->dirpath_for_id($oldID);
// Create an instance to use functions, since late static binding is only available in 5.3 (PHP kinda sucks)
$theme = CrayonResources::themes()->resource_instance('');
$newID = $theme->clean_id($name);
$name = CrayonResource::clean_name($newID);
$newPath = CrayonResources::themes()->path($newID, $user);
$newDir = CrayonResources::themes()->dirpath_for_id($newID, $user);
$exists = CrayonResources::themes()->is_loaded($newID) || (is_file($newPath) && is_file($oldPath));
if ($exists && $oldPath != $newPath) {
// Never allow overwriting a theme with a different id!
echo -3;
exit();
}
if ($oldPath == $newPath && $allow_edit === FALSE) {
// Don't allow editing
echo -4;
exit();
}
// Create the new path if needed
if (!is_dir($newDir)) {
wp_mkdir_p($newDir);
$imageSrc = $oldDir . 'images';
if (is_dir($imageSrc)) {
try {
// Copy image folder
CrayonUtil::copyDir($imageSrc, $newDir . 'images', 'wp_mkdir_p');
} catch (Exception $e) {
CrayonLog::syslog($e->getMessage(), "THEME SAVE");
}
}
}
$refresh = FALSE;
$replaceID = $oldID;
// Replace ids in the CSS
if (!is_file($oldPath) || strpos($css, CrayonThemes::CSS_PREFIX . $oldID) === FALSE) {
// The old path/id is no longer valid - something has gone wrong - we should refresh afterwards
$refresh = TRUE;
}
// XXX This is case sensitive to avoid modifying text, but it means that CSS must be in lowercase
$css = preg_replace('#(?<=' . CrayonThemes::CSS_PREFIX . ')' . $replaceID . '\b#ms', $newID, $css);
// Replace the name with the new one
$info = self::getCSSInfo($css);
$info['name'] = $name;
$css = self::setCSSInfo($css, $info);
$result = @file_put_contents($newPath, $css);
$success = $result !== FALSE;
if ($success && $oldPath !== $newPath) {
if ($oldID !== CrayonThemes::DEFAULT_THEME && $delete) {
// Only delete the old path if it isn't the default theme
try {
// Delete the old path
CrayonUtil::deleteDir($oldDir);
} catch (Exception $e) {
CrayonLog::syslog($e->getMessage(), "THEME SAVE");
}
}
// Refresh
echo 2;
} else {
if ($refresh) {
echo 2;
} else {
if ($success) {
echo 1;
} else {
echo -2;
}
}
}
// Set the new theme in settings
if ($change_settings) {
CrayonGlobalSettings::set(CrayonSettings::THEME, $newID);
CrayonSettingsWP::save_settings();
}
} else {
CrayonLog::syslog("$oldID=$oldID\n\n$name=$name", "THEME SAVE");
echo -1;
}
exit();
}
public static function duplicate() {
CrayonSettingsWP::load_settings();
$oldID = $_POST['id'];
$oldPath = CrayonResources::themes()->path($oldID);
$_POST['css'] = file_get_contents($oldPath);
$_POST['delete'] = FALSE;
$_POST['allow_edit'] = FALSE;
$_POST['allow_edit_stock_theme'] = FALSE;
self::save();
}
public static function delete() {
CrayonSettingsWP::load_settings();
$id = $_POST['id'];
$dir = CrayonResources::themes()->dirpath_for_id($id);
if (is_dir($dir) && CrayonResources::themes()->exists($id)) {
try {
CrayonUtil::deleteDir($dir);
CrayonGlobalSettings::set(CrayonSettings::THEME, CrayonThemes::DEFAULT_THEME);
CrayonSettingsWP::save_settings();
echo 1;
} catch (Exception $e) {
CrayonLog::syslog($e->getMessage(), "THEME SAVE");
echo -2;
}
} else {
echo -1;
}
exit();
}
public static function submit() {
global $CRAYON_EMAIL;
CrayonSettingsWP::load_settings();
$id = $_POST['id'];
$message = $_POST['message'];
$dir = CrayonResources::themes()->dirpath_for_id($id);
$dest = $dir . 'tmp';
wp_mkdir_p($dest);
if (is_dir($dir) && CrayonResources::themes()->exists($id)) {
try {
$zipFile = CrayonUtil::createZip($dir, $dest, TRUE);
$result = CrayonUtil::emailFile(array(
'to' => $CRAYON_EMAIL,
'from' => get_bloginfo('admin_email'),
'subject' => 'Theme Editor Submission',
'message' => $message,
'file' => $zipFile
));
CrayonUtil::deleteDir($dest);
if ($result) {
echo 1;
} else {
echo -3;
}
} catch (Exception $e) {
CrayonLog::syslog($e->getMessage(), "THEME SUBMIT");
echo -2;
}
} else {
echo -1;
}
exit();
}
public static function getCSSInfo($css) {
$info = array();
preg_match(self::RE_COMMENT, $css, $matches);
if (count($matches)) {
$comment = $matches[0];
preg_match_all('#([^\r\n:]*[^\r\n\s:])\s*:\s*([^\r\n]+)#msi', $comment, $matches);
if (count($matches)) {
for ($i = 0; $i < count($matches[1]); $i++) {
$name = $matches[1][$i];
$value = $matches[2][$i];
$info[self::getFieldID($name)] = $value;
}
}
}
return $info;
}
public static function cssInfoToString($info) {
$str = "/*\n";
foreach ($info as $id => $value) {
$str .= self::getFieldName($id) . ': ' . $value . "\n";
}
$str .= "*/";
return $str;
}
public static function setCSSInfo($css, $info) {
return preg_replace(self::RE_COMMENT, self::cssInfoToString($info), $css);
}
public static function getFieldID($name) {
if (isset(self::$infoFieldsInverse[$name])) {
return self::$infoFieldsInverse[$name];
} else {
return CrayonUserResource::clean_id($name);
}
}
public static function getFieldName($id) {
self::initFields();
if (isset(self::$infoFields[$id])) {
return self::$infoFields[$id];
} else {
return CrayonUserResource::clean_name($id);
}
}
public static function getAttributeGroup($attribute) {
if (isset(self::$attributeGroupsInverse[$attribute])) {
return self::$attributeGroupsInverse[$attribute];
} else {
return $attribute;
}
}
public static function getAttributeType($group) {
if (isset(self::$attributeTypesInverse[$group])) {
return self::$attributeTypesInverse[$group];
} else {
return 'text';
}
}
}
?>