public static function fonts() { if (self::$fonts == NULL) { self::$fonts = new CrayonFonts(); } return self::$fonts; }
public static function admin_scripts() { $themes_ = CrayonResources::themes()->get(); $themes = array(); foreach ($themes_ as $theme) { $themes[$theme->id()] = $theme->name(); } $settings = array('themes' => $themes, 'themes_url' => plugins_url(CRAYON_THEME_DIR, dirname(dirname(__FILE__)))); wp_localize_script('crayon_theme_editor', 'CrayonThemeEditorSettings', $settings); }
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 '<span class="crayon-span-5"></span>'; echo '<a href="http://bit.ly/Yr2Xv6" target="_blank">', crayon__('Add More'), '</a>'; echo '<span class="crayon-span-10"></span>'; self::checkbox(array(CrayonSettings::FONT_SIZE_ENABLE, crayon__('Custom Font Size') . ' '), FALSE); self::textbox(array('id' => CrayonSettings::FONT_SIZE, 'size' => 2)); echo '<span class="crayon-span-margin">', crayon__('Pixels'), '</span></br>'; 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 '<span class="crayon-error">', sprintf(crayon__('The selected font with id %s could not be loaded'), '<strong>' . $db_font . '</strong>'), '. </span><br/>'; } if ($editor) { return; } echo '<div style="height:10px;"></div>'; self::checkbox(array(CrayonSettings::ENQUEUE_FONTS, crayon__('Enqueue fonts in the header (more efficient).') . self::help_button('http://bit.ly/zTUAQV'))); }
public static function crayon_font_css() { global $CRAYON_VERSION; CrayonSettingsWP::load_settings(); $css = CrayonResources::fonts()->get_used_css(); foreach ($css as $font_id => $url) { wp_enqueue_style('crayon-font-' . $font_id, $url, array(), $CRAYON_VERSION); } }
<div id="crayon-te-content"> <?php $crayon_root_te = dirname(dirname(dirname(__FILE__))); require_once $crayon_root_te . '/crayon_wp.class.php'; require_once CrayonWP::wp_load_path(); require_once CRAYON_TE_PHP; require_once CRAYON_PARSER_PHP; CrayonSettingsWP::load_settings(); $langs = CrayonParser::parse_all(); $curr_lang = CrayonGlobalSettings::val(CrayonSettings::FALLBACK_LANG); $themes = CrayonResources::themes()->get(); $curr_theme = CrayonGlobalSettings::val(CrayonSettings::THEME); $fonts = CrayonResources::fonts()->get(); $curr_font = CrayonGlobalSettings::val(CrayonSettings::FONT); CrayonTagEditorWP::init_settings(); class CrayonTEContent { public static function select_resource($id, $resources, $current, $set_class = TRUE) { $id = CrayonSettings::PREFIX . $id; if (count($resources) > 0) { $class = $set_class ? 'class="' . CrayonSettings::SETTING . ' ' . CrayonSettings::SETTING_SPECIAL . '"' : ''; echo '<select id="' . $id . '" name="' . $id . '" ' . $class . ' ' . CrayonSettings::SETTING_ORIG_VALUE . '="' . $current . '">'; foreach ($resources as $resource) { $asterisk = $current == $resource->id() ? ' *' : ''; echo '<option value="' . $resource->id() . '" ' . selected($current, $resource->id()) . ' >' . $resource->name() . $asterisk . '</option>'; } echo '</select>'; } else { // None found, default to text box
function language_detect() { // Attempt to detect the language if (!empty($id)) { $this->log("The language '{$id}' could not be loaded."); } $this->language = CrayonResources::langs()->detect($this->url, $this->setting_val(CrayonSettings::FALLBACK_LANG)); }
<?php $crayon_root_theme_editor = dirname(dirname(dirname(__FILE__))); require_once $crayon_root_theme_editor . '/crayon_wp.class.php'; require_once CrayonWP::wp_load_path(); $theme = CrayonResources::themes()->get_default(); $editing = false; if (isset($_GET['curr_theme'])) { $theme = CrayonResources::themes()->get($_GET['curr_theme']); } if (isset($_GET['editing'])) { $editing = CrayonUtil::str_to_bool($_GET['editing'], FALSE); } // var_dump($_GET); // var_dump($theme); // var_dump($editing); ?> <div id="icon-options-general" class="icon32"><br> </div> <h2>Crayon Syntax Highlighter <?php crayon_e('Theme Editor'); ?> </h2> <h3> <?php if ($editing) { echo sprintf(crayon__('Editing "%s" Theme'), $theme->name()); } else { echo sprintf(crayon__('Creating Theme From "%s"'), $theme->name());
public static function delim_to_internal($matches) { // Mark as mixed so we can show (+) self::$curr->is_mixed(TRUE); $capture_group = count($matches) - 2; $capture_groups = array_keys(self::$delimiters); $lang_id = $capture_groups[$capture_group]; if (($lang = CrayonResources::langs()->get($lang_id)) === NULL) { return $matches[0]; } $internal = sprintf('{{crayon-internal:%d}}', count(self::$delim_pieces)); // TODO fix self::$delim_pieces[] = CrayonFormatter::format_code($matches[0], $lang, self::$curr); return $internal; }
public static function content() { CrayonSettingsWP::load_settings(); $langs = CrayonLangs::sort_by_name(CrayonParser::parse_all()); $curr_lang = CrayonGlobalSettings::val(CrayonSettings::FALLBACK_LANG); $themes = CrayonResources::themes()->get(); $curr_theme = CrayonGlobalSettings::val(CrayonSettings::THEME); $fonts = CrayonResources::fonts()->get(); $curr_font = CrayonGlobalSettings::val(CrayonSettings::FONT); CrayonTagEditorWP::init_settings(); ?> <div id="crayon-te-content" class="crayon-te"> <div id="crayon-te-bar"> <div id="crayon-te-bar-content"> <div id="crayon-te-title">Title</div> <div id="crayon-te-controls"> <a id="crayon-te-ok" href="#"><?php crayon_e('OK'); ?> </a> <span class="crayon-te-seperator">|</span> <a id="crayon-te-cancel" href="#"><?php crayon_e('Cancel'); ?> </a> </div> </div> </div> <table id="crayon-te-table" class="describe"> <tr class="crayon-tr-center"> <th><?php crayon_e('Title'); ?> </th> <td class="crayon-nowrap"><?php self::textbox('title', array('placeholder' => crayon__('A short description'))); ?> <span id="crayon-te-sub-section"> <?php self::checkbox('inline'); ?> <span class="crayon-te-section"><?php crayon_e('Inline'); ?> </span> </span> <span id="crayon-te-sub-section"> <?php self::checkbox('highlight'); ?> <span class="crayon-te-section"><?php crayon_e("Don't Highlight"); ?> </span> </span></td> </tr> <tr class="crayon-tr-center"> <th><?php crayon_e('Language'); ?> </th> <td class="crayon-nowrap"><?php self::select_resource('lang', $langs, $curr_lang); ?> <span class="crayon-te-section"><?php crayon_e('Line Range'); ?> </span> <?php self::textbox('range', array('placeholder' => crayon__('(e.g. 3-5 or 3)'))); ?> <span class="crayon-te-section"><?php crayon_e('Marked Lines'); ?> </span> <?php self::textbox('mark', array('placeholder' => crayon__('(e.g. 1,2,3-5)'))); ?> </td> </tr> <tr class="crayon-tr-center" style="text-align: center;"> <th> <div> <?php crayon_e('Code'); ?> </div> <input type="button" id="crayon-te-clear" class="secondary-primary" value="<?php crayon_e('Clear'); ?> " name="clear"/> </th> <td><textarea id="crayon-code" name="code" placeholder="<?php crayon_e('Paste your code here, or type it in manually.'); ?> "></textarea> </td> </tr> <tr class="crayon-tr-center"> <th id="crayon-url-th"><?php crayon_e('URL'); ?> </th> <td><?php self::textbox('url', array('placeholder' => crayon__('Relative local path or absolute URL'))); ?> <div id="crayon-te-url-info" class="crayon-te-info"> <?php crayon_e("If the URL fails to load, the code above will be shown instead. If no code exists, an error is shown."); echo ' '; printf(crayon__('If a relative local path is given it will be appended to %s - which is defined in %sCrayon > Settings > Files%s.'), '<span class="crayon-te-quote">' . get_home_url() . '/' . CrayonGlobalSettings::val(CrayonSettings::LOCAL_PATH) . '</span>', '<a href="options-general.php?page=crayon_settings" target="_blank">', '</a>'); ?> </div> </td> </tr> <tr> <td id="crayon-te-submit-wrapper" colspan="2" style="text-align: center;"><?php self::submit(); ?> </td> </tr> <!-- <tr>--> <!-- <td colspan="2"><div id="crayon-te-warning" class="updated crayon-te-info"></div></td>--> <!-- </tr>--> <tr> <td colspan="2"><?php $admin = isset($_GET['is_admin']) ? intval($_GET['is_admin']) : is_admin(); if (!$admin && !CrayonGlobalSettings::val(CrayonSettings::TAG_EDITOR_SETTINGS)) { exit; } ?> <hr/> <div> <h2 class="crayon-te-heading"> <?php crayon_e('Settings'); ?> </h2> </div> <div id="crayon-te-settings-info" class="crayon-te-info"> <?php crayon_e('Change the following settings to override their global values.'); echo ' <span class="', CrayonSettings::SETTING_CHANGED, '">'; crayon_e('Only changes (shown yellow) are applied.'); echo '</span><br/>'; echo sprintf(crayon__('Future changes to the global settings under %sCrayon > Settings%s won\'t affect overridden settings.'), '<a href="options-general.php?page=crayon_settings" target="_blank">', '</a>'); ?> </div> </td> </tr> <?php $sections = array('Theme', 'Font', 'Metrics', 'Toolbar', 'Lines', 'Code'); foreach ($sections as $section) { echo '<tr><th>', crayon__($section), '</th><td>'; call_user_func('CrayonSettingsWP::' . strtolower($section), TRUE); echo '</td></tr>'; } ?> </table> </div> <?php exit; }
public static function validate_regex($regex, $element) { if (is_string($regex) && @get_class($element) == CRAYON_ELEMENT_CLASS) { // If the (?alt) tag has been used, insert the file into the regex $file = self::regex_match('#\\(\\?alt:(.+?)\\)#', $regex); if (count($file) == 2) { // Element 0 has full match, 1 has captured groups for ($i = 0; $i < count($file[1]); $i++) { $file_lines = CrayonUtil::lines(dirname($element->path()) . crayon_s() . $file[1][$i], 'rcwh'); if ($file_lines !== FALSE) { $file_lines = implode('|', $file_lines); // If any spaces exist, treat them as whitespace $file_lines = preg_replace('#[ \\t]+#msi', '\\s+', $file_lines); $regex = str_replace($file[0][$i], "(?:{$file_lines})", $regex); } else { CrayonLog::syslog("Parsing of '{$element->path()}' failed, an (?alt) tag failed for the element '{$element->name()}'"); return FALSE; } } } // If the (?default:element) function is used, replace the regex with the default, if exists $def = self::regex_match('#\\(\\?default(?:\\:(\\w+))?\\)#', $regex); if (count($def) == 2) { // Load default language $default = CrayonResources::langs()->get(CrayonLangs::DEFAULT_LANG); // If default has not been loaded, we can't use it, skip the element if (!$default) { CrayonLog::syslog("Could not use default regex in the element '{$element->name()}' in '{$element->path()}'"); return FALSE; } for ($i = 0; $i < count($def[1]); $i++) { // If an element has been provided $element_name = !empty($def[1][$i]) ? $def[1][$i] : $element->name(); if (($default_element = $default->element($element_name)) != FALSE) { $regex = str_replace($def[0][$i], '(?:' . $default_element->regex() . ')', $regex); } else { CrayonLog::syslog("The language at '{$element->path()}' referred to the Default Language regex for element '{$element->name()}', which did not exist."); return FALSE; } } } // If the (?html) tag is used, escape characters in html (<, > and &) $html = self::regex_match('#\\(\\?html:(.+?)\\)#', $regex); if (count($html) == 2) { for ($i = 0; $i < count($html[1]); $i++) { $regex = str_replace($html[0][$i], htmlentities($html[1][$i]), $regex); } } // Ensure all parenthesis are atomic to avoid conflicting with element matches $regex = CrayonUtil::esc_atomic($regex); // Escape #, this is our delimiter $regex = CrayonUtil::esc_hash($regex); // Test if regex is valid if (@preg_match("#{$regex}#", '') === FALSE) { CrayonLog::syslog("The regex for the element '{$element->name()}' in '{$element->path()}' is not valid."); return FALSE; } return $regex; } else { return ''; } }
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; }
function language($id = NULL) { if ($id === NULL || !is_string($id)) { return $this->language; } if (($lang = CrayonResources::langs()->get($id)) != FALSE || ($lang = CrayonResources::langs()->alias($id)) != FALSE) { // Set the language if it exists or look for an alias $this->language = $lang; } else { // Attempt to detect the language if (!empty($id)) { $this->log("The language '{$id}' could not be loaded."); } $this->language = CrayonResources::langs()->detect($this->url, $this->setting_val(CrayonSettings::FALLBACK_LANG)); } // Prepare the language for use, even if we have no code, we need the name CrayonParser::parse($this->language->id()); }
$_GET[$key] = CrayonSettings::validate($key, $value); } } $crayon->settings($_GET); 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); } $font_id = $crayon->setting_val(CrayonSettings::FONT); if ($font_id != NULL) { echo CrayonResources::fonts()->get_css($font_id); } // Load custom code based on language $lang = $crayon->setting_val(CrayonSettings::FALLBACK_LANG); $path = crayon_pf(dirname(__FILE__) . '/sample/' . $lang . '.txt', FALSE); if ($lang && @file_exists($path)) { $crayon->url($path); } else { $code = "\r\n// A sample class\r\nclass Human {\r\n\tprivate int age = 0;\r\n\tpublic void birthday() {\r\n\t\tage++;\r\n\t\tprint('Happy Birthday!');\r\n\t}\r\n}\r\n"; $crayon->code($code); } $crayon->title('Sample Code'); $crayon->marked('5-7'); $crayon->output($highlight = true, $nums = true, $print = true); echo '</div>'; crayon_load_plugin_textdomain();