= '3.3') { add_action("load-$admin_page", 'CrayonSettingsWP::help_screen'); } else { add_filter('contextual_help', 'CrayonSettingsWP::cont_help', 10, 3); } } public static function admin_styles() { global $CRAYON_VERSION; if (CRAYON_MINIFY) { wp_enqueue_style('crayon', plugins_url(CRAYON_STYLE_MIN, __FILE__), array('editor-buttons'), $CRAYON_VERSION); } else { wp_enqueue_style('crayon', plugins_url(CRAYON_STYLE, __FILE__), array(), $CRAYON_VERSION); wp_enqueue_style('crayon_global', plugins_url(CRAYON_STYLE_GLOBAL, __FILE__), array(), $CRAYON_VERSION); wp_enqueue_style('crayon_admin', plugins_url(CRAYON_STYLE_ADMIN, __FILE__), array('editor-buttons'), $CRAYON_VERSION); } } public static function admin_scripts() { global $CRAYON_VERSION; if (CRAYON_MINIFY) { CrayonWP::enqueue_resources(); } else { wp_enqueue_script('crayon_util_js', plugins_url(CRAYON_JS_UTIL, __FILE__), array('jquery'), $CRAYON_VERSION); self::other_scripts(); } self::init_js_settings(); if (is_admin()) { wp_enqueue_script('crayon_admin_js', plugins_url(CRAYON_JS_ADMIN, __FILE__), array('jquery', 'crayon_js', 'wpdialogs'), $CRAYON_VERSION); self::init_admin_js_settings(); } } public static function other_scripts() { global $CRAYON_VERSION; self::load_settings(TRUE); $deps = array('jquery', 'crayon_util_js'); if (CrayonGlobalSettings::val(CrayonSettings::POPUP) || is_admin()) { // TODO include anyway and minify wp_enqueue_script('crayon_jquery_popup', plugins_url(CRAYON_JQUERY_POPUP, __FILE__), array('jquery'), $CRAYON_VERSION); $deps[] = 'crayon_jquery_popup'; } wp_enqueue_script('crayon_js', plugins_url(CRAYON_JS, __FILE__), $deps, $CRAYON_VERSION); } public static function init_js_settings() { // This stores JS variables used in AJAX calls and in the JS files global $CRAYON_VERSION; self::load_settings(TRUE); if (!self::$js_settings) { self::$js_settings = array( 'version' => $CRAYON_VERSION, 'is_admin' => intval(is_admin()), 'ajaxurl' => admin_url('admin-ajax.php'), 'prefix' => CrayonSettings::PREFIX, 'setting' => CrayonSettings::SETTING, 'selected' => CrayonSettings::SETTING_SELECTED, 'changed' => CrayonSettings::SETTING_CHANGED, 'special' => CrayonSettings::SETTING_SPECIAL, 'orig_value' => CrayonSettings::SETTING_ORIG_VALUE, 'debug' => CRAYON_DEBUG ); } if (!self::$js_strings) { self::$js_strings = array( 'copy' => crayon__('Press %s to Copy, %s to Paste'), 'minimize' => crayon__('Click To Expand Code') ); } if (CRAYON_MINIFY) { wp_localize_script('crayon_js', 'CrayonSyntaxSettings', self::$js_settings); wp_localize_script('crayon_js', 'CrayonSyntaxStrings', self::$js_strings); } else { wp_localize_script('crayon_util_js', 'CrayonSyntaxSettings', self::$js_settings); wp_localize_script('crayon_util_js', 'CrayonSyntaxStrings', self::$js_strings); } } public static function init_admin_js_settings() { if (!self::$admin_js_settings) { // We need to load themes at this stage CrayonSettingsWP::load_settings(); $themes_ = CrayonResources::themes()->get(); $stockThemes = array(); $userThemes = array(); foreach ($themes_ as $theme) { $id = $theme->id(); $name = $theme->name(); if ($theme->user()) { $userThemes[$id] = $name; } else { $stockThemes[$id] = $name; } } self::$admin_js_settings = array( 'themes' => array_merge($stockThemes, $userThemes), 'stockThemes' => $stockThemes, 'userThemes' => $userThemes, 'defaultTheme' => CrayonThemes::DEFAULT_THEME, 'themesURL' => CrayonResources::themes()->dirurl(false), 'userThemesURL' => CrayonResources::themes()->dirurl(true), 'sampleCode' => self::SAMPLE_CODE, 'dialogFunction' => 'wpdialog' ); wp_localize_script('crayon_admin_js', 'CrayonAdminSettings', self::$admin_js_settings); } if (!self::$admin_js_strings) { self::$admin_js_strings = array( 'prompt' => crayon__("Prompt"), 'value' => crayon__("Value"), 'alert' => crayon__("Alert"), 'no' => crayon__("No"), 'yes' => crayon__("Yes"), 'confirm' => crayon__("Confirm"), 'changeCode' => crayon__("Change Code") ); wp_localize_script('crayon_admin_js', 'CrayonAdminStrings', self::$admin_js_strings); } } public static function settings() { if (!current_user_can('manage_options')) { wp_die(crayon__('You do not have sufficient permissions to access this page.')); } ?>

Crayon Syntax Highlighter

load(); CrayonResources::themes()->load(); // Ensure all missing settings in db are replaced by default values $changed = FALSE; foreach (CrayonSettings::get_defaults_array() as $name => $value) { // Add missing settings if (!array_key_exists($name, self::$options)) { self::$options[$name] = $value; $changed = TRUE; } } // A setting was missing, update options if ($changed) { update_option(self::OPTIONS, self::$options); } self::$is_fully_loaded = TRUE; } } public static function get_settings() { return get_option(self::OPTIONS); } // Saves settings from CrayonGlobalSettings, or provided array, to the db public static function save_settings($settings = NULL) { if ($settings === NULL) { $settings = CrayonGlobalSettings::get_array(); } update_option(self::OPTIONS, $settings); } // Crayon posts /** * This loads the posts marked as containing Crayons */ public static function load_posts() { if (self::$crayon_posts === NULL) { // Load from db if (!(self::$crayon_posts = get_option(self::POSTS))) { // Posts don't exist! Scan for them. This will fill self::$crayon_posts self::$crayon_posts = CrayonWP::scan_posts(); update_option(self::POSTS, self::$crayon_posts); } } return self::$crayon_posts; } /** * This looks through all posts and marks those which contain Crayons */ // public static function scan_and_save_posts() { // self::save_posts(CrayonWP::scan_posts(TRUE, TRUE)); // } /** * Saves the marked posts to the db */ public static function save_posts($posts = NULL) { if ($posts === NULL) { $posts = self::$crayon_posts; } update_option(self::POSTS, $posts); self::load_posts(); } /** * Adds a post as containing a Crayon */ public static function add_post($id, $save = TRUE) { self::load_posts(); if (!in_array($id, self::$crayon_posts)) { self::$crayon_posts[] = $id; } if ($save) { self::save_posts(); } } /** * Removes a post as not containing a Crayon */ public static function remove_post($id, $save = TRUE) { self::load_posts(); $key = array_search($id, self::$crayon_posts); if ($key === false) { return; } unset(self::$crayon_posts[$key]); if ($save) { self::save_posts(); } } public static function remove_posts() { self::$crayon_posts = array(); self::save_posts(); } // Crayon legacy posts /** * This loads the posts marked as containing Crayons */ public static function load_legacy_posts($force = FALSE) { if (self::$crayon_legacy_posts === NULL || $force) { // Load from db if (!(self::$crayon_legacy_posts = get_option(self::LEGACY_POSTS))) { // Posts don't exist! Scan for them. This will fill self::$crayon_legacy_posts self::$crayon_legacy_posts = CrayonWP::scan_legacy_posts(); update_option(self::LEGACY_POSTS, self::$crayon_legacy_posts); } } return self::$crayon_legacy_posts; } /** * This looks through all posts and marks those which contain Crayons */ // public static function scan_and_save_posts() { // self::save_posts(CrayonWP::scan_posts(TRUE, TRUE)); // } /** * Saves the marked posts to the db */ public static function save_legacy_posts($posts = NULL) { if ($posts === NULL) { $posts = self::$crayon_legacy_posts; } update_option(self::LEGACY_POSTS, $posts); self::load_legacy_posts(); } /** * Adds a post as containing a Crayon */ public static function add_legacy_post($id, $save = TRUE) { self::load_legacy_posts(); if (!in_array($id, self::$crayon_legacy_posts)) { self::$crayon_legacy_posts[] = $id; } if ($save) { self::save_legacy_posts(); } } /** * Removes a post as not containing a Crayon */ public static function remove_legacy_post($id, $save = TRUE) { self::load_legacy_posts(); $key = array_search($id, self::$crayon_legacy_posts); if ($key === false) { return; } unset(self::$crayon_legacy_posts[$key]); if ($save) { self::save_legacy_posts(); } } public static function remove_legacy_posts() { self::$crayon_legacy_posts = array(); self::save_legacy_posts(); } // Cache public static function add_cache($name) { self::load_cache(); if (!in_array($name, self::$cache)) { self::$cache[] = $name; } self::save_cache(); } public static function remove_cache($name) { self::load_cache(); $key = array_search($name, self::$cache); if ($key === false) { return; } unset(self::$cache[$key]); self::save_cache(); } public static function clear_cache() { self::load_cache(); foreach (self::$cache as $name) { delete_transient($name); } self::$cache = array(); self::save_cache(); } public static function load_cache() { // Load cache from db if (!(self::$cache = get_option(self::CACHE))) { self::$cache = array(); update_option(self::CACHE, self::$cache); } } public static function save_cache() { update_option(self::CACHE, self::$cache); self::load_cache(); } // Paths public static function admin_init() { // Load default settings if they don't exist self::load_settings(); // General // Some of these will the $editor arguments, if TRUE it will alter for use in the Tag Editor self::add_section(self::GENERAL, crayon__('General')); self::add_field(self::GENERAL, crayon__('Theme'), 'theme'); self::add_field(self::GENERAL, crayon__('Font'), 'font'); self::add_field(self::GENERAL, crayon__('Metrics'), 'metrics'); self::add_field(self::GENERAL, crayon__('Toolbar'), 'toolbar'); self::add_field(self::GENERAL, crayon__('Lines'), 'lines'); self::add_field(self::GENERAL, crayon__('Code'), 'code'); self::add_field(self::GENERAL, crayon__('Tags'), 'tags'); self::add_field(self::GENERAL, crayon__('Languages'), 'langs'); self::add_field(self::GENERAL, crayon__('Files'), 'files'); self::add_field(self::GENERAL, crayon__('Posts'), 'posts'); self::add_field(self::GENERAL, crayon__('Tag Editor'), 'tag_editor'); self::add_field(self::GENERAL, crayon__('Misc'), 'misc'); // Debug self::add_section(self::DEBUG, crayon__('Debug')); self::add_field(self::DEBUG, crayon__('Errors'), 'errors'); self::add_field(self::DEBUG, crayon__('Log'), 'log'); // ABOUT self::add_section(self::ABOUT, crayon__('About')); $image = ''; self::add_field(self::ABOUT, $image, 'info'); } // Wrapper functions private static function add_section($name, $title, $callback = NULL) { $callback = (empty($callback) ? 'blank' : $callback); add_settings_section($name, $title, 'CrayonSettingsWP::' . $callback, self::SETTINGS); } private static function add_field($section, $title, $callback, $args = array()) { $unique = preg_replace('#\\s#', '_', strtolower($title)); add_settings_field($unique, $title, 'CrayonSettingsWP::' . $callback, self::SETTINGS, $section, $args); } // Validates all the settings passed from the form in $inputs public static function settings_validate($inputs) { // Load current settings from db self::load_settings(TRUE); global $CRAYON_EMAIL; // When reset button is pressed, remove settings so default loads next time if (array_key_exists('reset', $inputs)) { self::clear_cache(); return array(); } // Convert old tags if (array_key_exists('convert', $inputs)) { $encode = array_key_exists('convert_encode', $inputs); CrayonWP::convert_tags($encode); } // Refresh internal tag management if (array_key_exists('refresh_tags', $inputs)) { CrayonWP::refresh_posts(); } // Clear the log if needed if (array_key_exists(self::LOG_CLEAR, $_POST)) { CrayonLog::clear(); } // Send to admin if (array_key_exists(self::LOG_EMAIL_ADMIN, $_POST)) { CrayonLog::email(get_bloginfo('admin_email')); } // Send to developer if (array_key_exists(self::LOG_EMAIL_DEV, $_POST)) { CrayonLog::email($CRAYON_EMAIL, get_bloginfo('admin_email')); } // Clear the cache if (array_key_exists(self::CACHE_CLEAR, $_POST)) { self::clear_cache(); } // If settings don't exist in input, set them to default $global_settings = CrayonSettings::get_defaults(); $ignored = array(CrayonSettings::HIDE_HELP); foreach ($global_settings as $setting) { // XXX Ignore some settings if (in_array($setting->name(), $ignored)) { $inputs[$setting->name()] = CrayonGlobalSettings::val($setting->name()); continue; } // If boolean setting is not in input, then it is set to FALSE in the form if (!array_key_exists($setting->name(), $inputs)) { // For booleans, set to FALSE (unchecked boxes are not sent as POST) if (is_bool($setting->def())) { $inputs[$setting->name()] = FALSE; } else { /* For array settings, set the input as the value, which by default is the default index */ if (is_array($setting->def())) { $inputs[$setting->name()] = $setting->value(); } else { $inputs[$setting->name()] = $setting->def(); } } } } $refresh = array( // These should trigger a refresh of which posts contain crayons, since they affect capturing CrayonSettings::INLINE_TAG => TRUE, CrayonSettings::INLINE_TAG_CAPTURE => TRUE, CrayonSettings::CODE_TAG_CAPTURE => TRUE, CrayonSettings::BACKQUOTE => TRUE, CrayonSettings::CAPTURE_PRE => TRUE, CrayonSettings::CAPTURE_MINI_TAG => TRUE, CrayonSettings::PLAIN_TAG => TRUE ); // Validate inputs foreach ($inputs as $input => $value) { // Convert all array setting values to ints $inputs[$input] = $value = CrayonSettings::validate($input, $value); // Clear cache when changed if (CrayonGlobalSettings::has_changed($input, CrayonSettings::CACHE, $value)) { self::clear_cache(); } if (isset($refresh[$input])) { if (CrayonGlobalSettings::has_changed($input, $input, $value)) { // Needs to take place, in case it refresh depends on changed value CrayonGlobalSettings::set($input, $value); CrayonWP::refresh_posts(); } } } return $inputs; } // Section callback functions public static function blank() { } // Used for required callbacks with blank content // Input Drawing ========================================================== private static function input($args) { $id = ''; $size = 40; $margin = FALSE; $preview = 1; $break = FALSE; $type = 'text'; extract($args); echo '', ($break ? CRAYON_BR : ''); } private static function checkbox($args, $line_break = TRUE, $preview = TRUE) { if (empty($args) || !is_array($args) || count($args) != 2) { return; } $id = $args[0]; $text = $args[1]; $checked = (!array_key_exists($id, self::$options)) ? FALSE : self::$options[$id] == TRUE; $checked_str = $checked ? ' checked="checked"' : ''; echo ' ', '', ($line_break ? CRAYON_BR : ''); } // Draws a dropdown by loading the default value (an array) from a setting private static function dropdown($id, $line_break = TRUE, $preview = TRUE, $echo = TRUE, $resources = NULL, $selected = NULL) { if (!array_key_exists($id, self::$options)) { return; } $resources = $resources != NULL ? $resources : CrayonGlobalSettings::get($id)->def(); $return = '' . ($line_break ? CRAYON_BR : ''); if ($echo) { echo $return; } else { return $return; } } private static function button($args = array()) { extract($args); CrayonUtil::set_var($id, ''); CrayonUtil::set_var($class, ''); CrayonUtil::set_var($onclick, ''); CrayonUtil::set_var($title, ''); return '' . $title . ''; } private static function info_span($name, $text) { echo '', $text, ''; } private static function span($text) { echo '', $text, ''; } // General Fields ========================================================= public static function help() { global $CRAYON_WEBSITE, $CRAYON_TWITTER, $CRAYON_GIT; if (CrayonGlobalSettings::val(CrayonSettings::HIDE_HELP)) { return; } } public static function help_screen() { $screen = get_current_screen(); if ($screen->id != self::$admin_page) { return; } } public static function metrics() { echo '
'; self::checkbox(array(CrayonSettings::HEIGHT_SET, '' . crayon__('Height') . ' '), FALSE); self::dropdown(CrayonSettings::HEIGHT_MODE, FALSE); echo ' '; self::input(array('id' => CrayonSettings::HEIGHT, 'size' => 8)); echo ' '; self::dropdown(CrayonSettings::HEIGHT_UNIT); self::checkbox(array(CrayonSettings::WIDTH_SET, '' . crayon__('Width') . ' '), FALSE); self::dropdown(CrayonSettings::WIDTH_MODE, FALSE); echo ' '; self::input(array('id' => CrayonSettings::WIDTH, 'size' => 8)); echo ' '; self::dropdown(CrayonSettings::WIDTH_UNIT); $text = array(crayon__('Top Margin') => array(CrayonSettings::TOP_SET, CrayonSettings::TOP_MARGIN), crayon__('Bottom Margin') => array(CrayonSettings::BOTTOM_SET, CrayonSettings::BOTTOM_MARGIN), crayon__('Left Margin') => array(CrayonSettings::LEFT_SET, CrayonSettings::LEFT_MARGIN), crayon__('Right Margin') => array(CrayonSettings::RIGHT_SET, CrayonSettings::RIGHT_MARGIN)); foreach ($text as $p => $s) { $set = $s[0]; $margin = $s[1]; $preview = ($p == crayon__('Left Margin') || $p == crayon__('Right Margin')); self::checkbox(array($set, '' . $p . ''), FALSE, $preview); echo ' '; self::input(array('id' => $margin, 'size' => 8, 'preview' => FALSE)); echo '', crayon__('Pixels'), '', CRAYON_BR; } echo '' . crayon__('Horizontal Alignment') . ' '; self::dropdown(CrayonSettings::H_ALIGN); echo '
'; self::checkbox(array(CrayonSettings::FLOAT_ENABLE, crayon__('Allow floating elements to surround Crayon')), FALSE, FALSE); echo '
'; echo '' . crayon__('Inline Margin') . ' '; self::input(array('id' => CrayonSettings::INLINE_MARGIN, 'size' => 2)); echo '', crayon__('Pixels'), ''; echo '
'; } public static function toolbar() { echo '
'; self::span(crayon__('Display the Toolbar') . ' '); self::dropdown(CrayonSettings::TOOLBAR); echo '
'; self::checkbox(array(CrayonSettings::TOOLBAR_OVERLAY, crayon__('Overlay the toolbar on code rather than push it down when possible'))); self::checkbox(array(CrayonSettings::TOOLBAR_HIDE, crayon__('Toggle the toolbar on single click when it is overlayed'))); self::checkbox(array(CrayonSettings::TOOLBAR_DELAY, crayon__('Delay hiding the toolbar on MouseOut'))); echo '
'; self::checkbox(array(CrayonSettings::SHOW_TITLE, crayon__('Display the title when provided'))); self::span(crayon__('Display the language') . ' '); self::dropdown(CrayonSettings::SHOW_LANG); echo '
'; } public static function lines() { echo '
'; self::checkbox(array(CrayonSettings::STRIPED, crayon__('Display striped code lines'))); self::checkbox(array(CrayonSettings::MARKING, crayon__('Enable line marking for important lines'))); self::checkbox(array(CrayonSettings::RANGES, crayon__('Enable line ranges for showing only parts of code'))); self::checkbox(array(CrayonSettings::NUMS, crayon__('Display line numbers by default'))); self::checkbox(array(CrayonSettings::NUMS_TOGGLE, crayon__('Enable line number toggling'))); self::checkbox(array(CrayonSettings::WRAP, crayon__('Wrap lines by default'))); self::checkbox(array(CrayonSettings::WRAP_TOGGLE, crayon__('Enable line wrap toggling'))); self::span(crayon__('Start line numbers from') . ' '); self::input(array('id' => CrayonSettings::START_LINE, 'size' => 2, 'break' => TRUE)); echo '
'; } public static function langs() { echo ''; // Specialised dropdown for languages if (array_key_exists(CrayonSettings::FALLBACK_LANG, self::$options)) { if (($langs = CrayonParser::parse_all()) != FALSE) { $langs = CrayonLangs::sort_by_name($langs); self::span(crayon__('When no language is provided, use the fallback') . ': '); self::dropdown(CrayonSettings::FALLBACK_LANG, FALSE, TRUE, TRUE, $langs); // Information about parsing $parsed = CrayonResources::langs()->is_parsed(); $count = count($langs); echo '', CRAYON_BR, ($parsed ? '' : ''), sprintf(crayon_n('%d language has been detected.', '%d languages have been detected.', $count), $count), ' ', $parsed ? crayon__('Parsing was successful') : crayon__('Parsing was unsuccessful'), ($parsed ? '. ' : ''); // Check if fallback from db is loaded $db_fallback = self::$options[CrayonSettings::FALLBACK_LANG]; // Fallback name from db if (!CrayonResources::langs()->is_loaded($db_fallback) || !CrayonResources::langs()->exists($db_fallback)) { echo '
', sprintf(crayon__('The selected language with id %s could not be loaded'), '' . $db_fallback . ''), '. '; } // Language parsing info echo CRAYON_BR, '
' . self::button(array('id' => 'show-langs', 'title' => crayon__('Show Languages'))) . '
'; } else { echo crayon__('No languages could be parsed.'); } } } public static function show_langs() { CrayonSettingsWP::load_settings(); require_once(CRAYON_PARSER_PHP); if (($langs = CrayonParser::parse_all()) != FALSE) { $langs = CrayonLangs::sort_by_name($langs); echo '', ''; $keys = array_values($langs); for ($i = 0; $i < count($langs); $i++) { $lang = $keys[$i]; $tr = ($i == count($langs) - 1) ? 'crayon-table-last' : ''; echo '', '', '', '', '', '', '', ''; } echo '
', crayon__('ID'), '', crayon__('Name'), '', crayon__('Version'), '', crayon__('File Extensions'), '', crayon__('Aliases'), '', crayon__('State'), '
', $lang->id(), '', $lang->name(), '', $lang->version(), '', implode(', ', $lang->ext()), '', implode(', ', $lang->alias()), '', $lang->state_info(), '

' . crayon__("Languages that have the same extension as their name don't need to explicitly map extensions."); } else { echo crayon__('No languages could be found.'); } exit(); } public static function posts() { echo ''; echo self::button(array('id' => 'show-posts', 'title' => crayon__('Show Crayon Posts'))); echo ' '; echo self::help_button('http://aramk.com/blog/2012/09/26/internal-post-management-crayon/'); echo '
'; } public static function post_cmp($a, $b) { $a = $a->post_modified; $b = $b->post_modified; if ($a == $b) { return 0; } else { return $a < $b ? 1 : -1; } } public static function show_posts() { CrayonSettingsWP::load_settings(); $postIDs = self::load_posts(); $legacy_posts = self::load_legacy_posts(); // Avoids O(n^2) by using a hash map, tradeoff in using strval $legacy_map = array(); foreach ($legacy_posts as $legacyID) { $legacy_map[strval($legacyID)] = TRUE; } echo '', ''; $posts = array(); for ($i = 0; $i < count($postIDs); $i++) { $posts[$i] = get_post($postIDs[$i]); } usort($posts, 'CrayonSettingsWP::post_cmp'); for ($i = 0; $i < count($posts); $i++) { $post = $posts[$i]; $postID = $post->ID; $title = $post->post_title; $title = !empty($title) ? $title : 'N/A'; $tr = ($i == count($posts) - 1) ? 'crayon-table-last' : ''; echo '', '', '', '', '', '', ''; } echo '
', crayon__('ID'), '', crayon__('Title'), '', crayon__('Posted'), '', crayon__('Modifed'), '', crayon__('Contains Legacy Tags?'), '
', $postID, '', $title, '', $post->post_date, '', $post->post_modified, '', isset($legacy_map[strval($postID)]) ? '' . crayon__('Yes') . '' : crayon__('No'), '
'; exit(); } public static function show_preview() { echo '
'; self::load_settings(); // Run first to ensure global settings loaded $crayon = CrayonWP::instance(); // Settings to prevent from validating $preview_settings = array(self::SAMPLE_CODE); // Load settings from GET and validate foreach ($_POST as $key => $value) { // echo $key, ' ', $value , '
'; $value = stripslashes($value); if (!in_array($key, $preview_settings)) { $_POST[$key] = CrayonSettings::validate($key, $value); } else { $_POST[$key] = $value; } } $crayon->settings($_POST); if (!isset($crayon_preview_dont_override_get) || !$crayon_preview_dont_override_get) { $settings = array(CrayonSettings::TOP_SET => TRUE, CrayonSettings::TOP_MARGIN => 10, CrayonSettings::BOTTOM_SET => FALSE, CrayonSettings::BOTTOM_MARGIN => 0); $crayon->settings($settings); } // Print the theme CSS $theme_id = $crayon->setting_val(CrayonSettings::THEME); if ($theme_id != NULL) { echo CrayonResources::themes()->get_css($theme_id, date('U')); } $font_id = $crayon->setting_val(CrayonSettings::FONT); if ($font_id != NULL /*&& $font_id != CrayonFonts::DEFAULT_FONT*/) { echo CrayonResources::fonts()->get_css($font_id); } // Load custom code based on language $lang = $crayon->setting_val(CrayonSettings::FALLBACK_LANG); $path = CrayonGlobalSettings::plugin_path() . CRAYON_UTIL_DIR . '/sample/' . $lang . '.txt'; if (isset($_POST[self::SAMPLE_CODE])) { $crayon->code($_POST[self::SAMPLE_CODE]); } else if ($lang && @file_exists($path)) { $crayon->url($path); } else { $code = " // A sample class class Human { private int age = 0; public void birthday() { age++; print('Happy Birthday!'); } } "; $crayon->code($code); } $crayon->title('Sample Code'); $crayon->marked('5-7'); $crayon->output($highlight = true, $nums = true, $print = true); echo '
'; crayon_load_plugin_textdomain(); exit(); } public static function theme($editor = FALSE) { $db_theme = self::$options[CrayonSettings::THEME]; // Theme name from db if (!array_key_exists(CrayonSettings::THEME, self::$options)) { $db_theme = ''; } $themes_array = CrayonResources::themes()->get_array(); // Mark user themes foreach ($themes_array as $id => $name) { $mark = CrayonResources::themes()->get($id)->user() ? ' *' : ''; $themes_array[$id] = array($name, $name . $mark); } $missing_theme = !CrayonResources::themes()->is_loaded($db_theme) || !CrayonResources::themes()->exists($db_theme); self::dropdown(CrayonSettings::THEME, FALSE, FALSE, TRUE, $themes_array, $missing_theme ? CrayonThemes::DEFAULT_THEME : NULL); if ($editor) { return; } // Theme editor if (CRAYON_THEME_EDITOR) { // echo ''. crayon__('Theme Editor') .'
'; echo '
'; $buttons = array('edit' => crayon__('Edit'), 'duplicate' => crayon__('Duplicate'), 'submit' => crayon__('Submit'), 'delete' => crayon__('Delete')); foreach ($buttons as $k => $v) { echo '', $v, ''; } echo '', self::help_button('http://aramk.com/blog/2012/12/27/crayon-theme-editor/'), '', crayon__("Duplicate a Stock Theme into a User Theme to allow editing."); echo '
'; } // Preview Box ?>
', '', '', ''); ?>
'; self::checkbox(array(CrayonSettings::ENQUEUE_THEMES, crayon__('Enqueue themes in the header (more efficient).') . self::help_button('http://aramk.com/blog/2012/01/07/enqueuing-themes-and-fonts-in-crayon/'))); // Check if theme from db is loaded if ($missing_theme) { echo '', sprintf(crayon__('The selected theme with id %s could not be loaded'), '' . $db_theme . ''), '. '; } } public static function font($editor = FALSE) { $db_font = self::$options[CrayonSettings::FONT]; // Theme name from db if (!array_key_exists(CrayonSettings::FONT, self::$options)) { $db_font = ''; } $fonts_array = CrayonResources::fonts()->get_array(); self::dropdown(CrayonSettings::FONT, FALSE, TRUE, TRUE, $fonts_array); echo ''; // TODO(aramk) Add this blog article back. // echo '', crayon__('Add More'), ''; echo ''; self::checkbox(array(CrayonSettings::FONT_SIZE_ENABLE, crayon__('Custom Font Size') . ' '), FALSE); self::input(array('id' => CrayonSettings::FONT_SIZE, 'size' => 2)); echo '', crayon__('Pixels'), ',  ', crayon__('Line Height'), ' '; self::input(array('id' => CrayonSettings::LINE_HEIGHT, 'size' => 2)); echo '', crayon__('Pixels'), '
'; if ((!CrayonResources::fonts()->is_loaded($db_font) || !CrayonResources::fonts()->exists($db_font))) { // Default font doesn't actually exist as a file, it means do not override default theme font echo '', sprintf(crayon__('The selected font with id %s could not be loaded'), '' . $db_font . ''), '.
'; } if ($editor) { return; } echo '
'; self::checkbox(array(CrayonSettings::ENQUEUE_FONTS, crayon__('Enqueue fonts in the header (more efficient).') . self::help_button('http://aramk.com/blog/2012/01/07/enqueuing-themes-and-fonts-in-crayon/'))); } public static function code($editor = FALSE) { echo '
'; self::checkbox(array(CrayonSettings::PLAIN, crayon__('Enable plain code view and display') . ' '), FALSE); self::dropdown(CrayonSettings::SHOW_PLAIN); echo ''; self::checkbox(array(CrayonSettings::PLAIN_TOGGLE, crayon__('Enable plain code toggling'))); self::checkbox(array(CrayonSettings::SHOW_PLAIN_DEFAULT, crayon__('Show the plain code by default'))); self::checkbox(array(CrayonSettings::COPY, crayon__('Enable code copy/paste'))); echo ''; self::checkbox(array(CrayonSettings::POPUP, crayon__('Enable opening code in a window'))); self::checkbox(array(CrayonSettings::SCROLL, crayon__('Always display scrollbars'))); self::checkbox(array(CrayonSettings::MINIMIZE, crayon__('Minimize code') . self::help_button('http://aramk.com/blog/2013/01/15/minimizing-code-in-crayon/'))); self::checkbox(array(CrayonSettings::EXPAND, crayon__('Expand code beyond page borders on mouseover'))); self::checkbox(array(CrayonSettings::EXPAND_TOGGLE, crayon__('Enable code expanding toggling when possible'))); echo '
'; if (!$editor) { self::checkbox(array(CrayonSettings::DECODE, crayon__('Decode HTML entities in code'))); } self::checkbox(array(CrayonSettings::DECODE_ATTRIBUTES, crayon__('Decode HTML entities in attributes'))); echo '
'; self::checkbox(array(CrayonSettings::TRIM_WHITESPACE, crayon__('Remove whitespace surrounding the shortcode content'))); echo '
'; self::checkbox(array(CrayonSettings::TRIM_CODE_TAG, crayon__('Remove <code> tags surrounding the shortcode content'))); self::checkbox(array(CrayonSettings::MIXED, crayon__('Allow Mixed Language Highlighting with delimiters and tags.') . self::help_button('http://aramk.com/blog/2011/12/25/mixed-language-highlighting-in-crayon/'))); echo '
'; self::checkbox(array(CrayonSettings::SHOW_MIXED, crayon__('Show Mixed Language Icon (+)'))); echo '
'; self::checkbox(array(CrayonSettings::TAB_CONVERT, crayon__('Convert tabs to spaces'))); self::span(crayon__('Tab size in spaces') . ': '); self::input(array('id' => CrayonSettings::TAB_SIZE, 'size' => 2, 'break' => TRUE)); self::span(crayon__('Blank lines before code:') . ' '); self::input(array('id' => CrayonSettings::WHITESPACE_BEFORE, 'size' => 2, 'break' => TRUE)); self::span(crayon__('Blank lines after code:') . ' '); self::input(array('id' => CrayonSettings::WHITESPACE_AFTER, 'size' => 2, 'break' => TRUE)); } public static function tags() { self::checkbox(array(CrayonSettings::INLINE_TAG, crayon__('Capture Inline Tags') . self::help_button('http://aramk.com/blog/2012/03/07/inline-crayons/'))); self::checkbox(array(CrayonSettings::INLINE_WRAP, crayon__('Wrap Inline Tags') . self::help_button('http://aramk.com/blog/2012/03/07/inline-crayons/'))); self::checkbox(array(CrayonSettings::CODE_TAG_CAPTURE, crayon__('Capture <code> as')), FALSE); echo ' '; self::dropdown(CrayonSettings::CODE_TAG_CAPTURE_TYPE, FALSE); echo self::help_button('http://aramk.com/blog/2012/03/07/inline-crayons/') . '
'; self::checkbox(array(CrayonSettings::BACKQUOTE, crayon__('Capture `backquotes` as <code>') . self::help_button('http://aramk.com/blog/2012/03/07/inline-crayons/'))); self::checkbox(array(CrayonSettings::CAPTURE_PRE, crayon__('Capture <pre> tags as Crayons') . self::help_button('http://aramk.com/blog/2011/12/27/mini-tags-in-crayon/'))); echo '
', sprintf(crayon__("Using this markup for Mini Tags and Inline tags is now %sdeprecated%s! Use the %sTag Editor%s instead and convert legacy tags."), '', '', '', ''), '
'; self::checkbox(array(CrayonSettings::CAPTURE_MINI_TAG, crayon__('Capture Mini Tags like [php][/php] as Crayons.') . self::help_button('http://aramk.com/blog/2011/12/27/mini-tags-in-crayon/'))); self::checkbox(array(CrayonSettings::INLINE_TAG_CAPTURE, crayon__('Capture Inline Tags like {php}{/php} inside sentences.') . self::help_button('http://aramk.com/blog/2012/03/07/inline-crayons/'))); self::checkbox(array(CrayonSettings::PLAIN_TAG, crayon__('Enable [plain][/plain] tag.') . self::help_button('http://aramk.com/blog/2011/12/27/mini-tags-in-crayon/'))); } public static function files() { echo ''; echo crayon__('When loading local files and a relative path is given for the URL, use the absolute path'), ': ', '
', home_url(), '/'; self::input(array('id' => CrayonSettings::LOCAL_PATH)); echo '
', crayon__('Followed by your relative URL.'); } public static function tag_editor() { $can_convert = self::load_legacy_posts(); if ($can_convert) { $disabled = ''; $convert_text = crayon__('Convert Legacy Tags'); } else { $disabled = 'disabled="disabled"'; $convert_text = crayon__('No Legacy Tags Found'); } echo '  '; self::checkbox(array('convert_encode', crayon__("Encode")), FALSE); echo self::help_button('http://aramk.com/blog/2012/09/26/converting-legacy-tags-to-pre/'), CRAYON_BR, CRAYON_BR; $sep = sprintf(crayon__('Use %s to separate setting names from values in the <pre> class attribute'), self::dropdown(CrayonSettings::ATTR_SEP, FALSE, FALSE, FALSE)); echo '', $sep, self::help_button('http://aramk.com/blog/2012/03/25/crayon-tag-editor/'), '
'; self::checkbox(array(CrayonSettings::TAG_EDITOR_FRONT, crayon__("Display the Tag Editor in any TinyMCE instances on the frontend (e.g. bbPress)") . self::help_button('http://aramk.com/blog/2012/09/08/crayon-with-bbpress/'))); self::checkbox(array(CrayonSettings::TAG_EDITOR_SETTINGS, crayon__("Display Tag Editor settings on the frontend"))); self::span(crayon__('Add Code button text') . ' '); self::input(array('id' => CrayonSettings::TAG_EDITOR_ADD_BUTTON_TEXT, 'break' => TRUE)); self::span(crayon__('Edit Code button text') . ' '); self::input(array('id' => CrayonSettings::TAG_EDITOR_EDIT_BUTTON_TEXT, 'break' => TRUE)); self::span(crayon__('Quicktag button text') . ' '); self::input(array('id' => CrayonSettings::TAG_EDITOR_QUICKTAG_BUTTON_TEXT, 'break' => TRUE)); } public static function misc() { echo crayon__('Clear the cache used to store remote code requests'), ': '; self::dropdown(CrayonSettings::CACHE, false); echo '
'; self::checkbox(array(CrayonSettings::EFFICIENT_ENQUEUE, crayon__('Attempt to load Crayon\'s CSS and JavaScript only when needed') . self::help_button('http://aramk.com/blog/2012/01/23/failing-to-load-crayons-on-pages/'))); self::checkbox(array(CrayonSettings::SAFE_ENQUEUE, crayon__('Disable enqueuing for page templates that may contain The Loop.') . self::help_button('http://aramk.com/blog/2012/01/23/failing-to-load-crayons-on-pages/'))); self::checkbox(array(CrayonSettings::COMMENTS, crayon__('Allow Crayons inside comments'))); self::checkbox(array(CrayonSettings::EXCERPT_STRIP, crayon__('Remove Crayons from excerpts'))); self::checkbox(array(CrayonSettings::MAIN_QUERY, crayon__('Load Crayons only from the main Wordpress query'))); self::checkbox(array(CrayonSettings::TOUCHSCREEN, crayon__('Disable mouse gestures for touchscreen devices (eg. MouseOver)'))); self::checkbox(array(CrayonSettings::DISABLE_ANIM, crayon__('Disable animations'))); self::checkbox(array(CrayonSettings::DISABLE_RUNTIME, crayon__('Disable runtime stats'))); echo '' . crayon__('Disable for posts before') . ': '; self::input(array('id' => CrayonSettings::DISABLE_DATE, 'type' => 'date', 'size' => 8, 'break' => FALSE)); echo '
'; self::checkbox(array(CrayonSettings::DELAY_LOAD_JS, crayon__('Load scripts in the page footer using wp_footer() to improve loading performance.'))); } // Debug Fields =========================================================== public static function errors() { self::checkbox(array(CrayonSettings::ERROR_LOG, crayon__('Log errors for individual Crayons'))); self::checkbox(array(CrayonSettings::ERROR_LOG_SYS, crayon__('Log system-wide errors'))); self::checkbox(array(CrayonSettings::ERROR_MSG_SHOW, crayon__('Display custom message for errors'))); self::input(array('id' => CrayonSettings::ERROR_MSG, 'size' => 60, 'margin' => TRUE)); } public static function log() { $log = CrayonLog::log(); touch(CRAYON_LOG_FILE); $exists = file_exists(CRAYON_LOG_FILE); $writable = is_writable(CRAYON_LOG_FILE); if (!empty($log)) { echo '
', '
', $log, '
', '
', ' ', ' ', ' ', ' ', '
', '
'; } echo '', (empty($log)) ? crayon__('The log is currently empty.') . ' ' : ''; if ($exists) { $writable ? crayon_e('The log file exists and is writable.') : crayon_e('The log file exists and is not writable.'); } else { crayon_e('The log file does not exist and is not writable.'); } echo ''; } // About Fields =========================================================== public static function info() { global $CRAYON_VERSION, $CRAYON_DATE, $CRAYON_AUTHOR, $CRAYON_WEBSITE, $CRAYON_TWITTER, $CRAYON_GIT, $CRAYON_AUTHOR_SITE, $CRAYON_EMAIL; echo ''; $version = '' . crayon__('Version') . ': ' . $CRAYON_VERSION; $date = $CRAYON_DATE; $developer = '' . crayon__('Developer') . ': ' . '' . $CRAYON_AUTHOR . ''; $translators = '' . crayon__('Translators') . ': ' . ' Arabic (Djennad Hamza), Chinese Simplified (Dezhi Liu, Jash Yin), Chinese Traditional (Arefly), Dutch (Robin Roelofsen, Chilion Snoek), French (Victor Felder), Finnish (vahalan), German (Stephan Knauß), Italian (Federico Bellucci), Japanese (@west_323), Korean (dokenzy), Lithuanian (Vincent G), Norwegian (Jackalworks), Persian (MahdiY), Polish (Bartosz Romanowski, Robert Korulczyk), Portuguese (Adonai S. Canez), Russian (Minimus, Di_Skyer), Slovak (webhostgeeks), Slovenian (Jan Sušnik), Spanish (Hermann Bravo), Tamil (KKS21199), Turkish (Hakan), Ukrainian (Michael Yunat)'; echo '
' . $version . ' - ' . $date . '
' . $developer . '
' . $translators . '
'; } public static function help_button($link) { return ' ' . crayon__('?') . ''; } public static function plugin_row_meta($meta, $file) { if ($file == CrayonWP::basename()) { $meta[] = '' . crayon__('Settings') . ''; $meta[] = '' . crayon__('Theme Editor') . ''; } return $meta; } } // Add the settings menus if (defined('ABSPATH') && is_admin()) { // For the admin section add_action('admin_menu', 'CrayonSettingsWP::admin_load'); add_filter('plugin_row_meta', 'CrayonSettingsWP::plugin_row_meta', 10, 2); }