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 .= ""; } 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 = '
'; return $str; } public static function formField($name, $field, $class = '') { return '
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);
?>
|