public static function format_code($code, $language, $hl = NULL) { // Ensure the language is defined if ($language != NULL && $hl->is_highlighted()) { $code = self::clean_code($code, FALSE, FALSE, FALSE, TRUE); /* Perform the replace on the code using the regex, pass the captured matches for formatting before they are replaced */ try { CrayonParser::parse($language->id()); // Match language regex $elements = $language->elements(); $regex = $language->regex(); if (!empty($regex) && !empty($elements)) { // Get array of CrayonElements self::$elements = array_values($elements); $code = preg_replace_callback($regex, 'CrayonFormatter::format_match', $code); } } catch (Exception $e) { $error = 'An error occured when formatting: ' . $e->message(); $hl ? $hl->log($error) : CrayonLog::syslog($error); } return $code; } else { return self::clean_code($code, TRUE, TRUE, TRUE, TRUE); } }
public static function show_langs() { require_once CRAYON_PARSER_PHP; if (($langs = CrayonParser::parse_all()) != FALSE) { $langs = CrayonLangs::sort_by_name($langs); echo '<table class="crayon-table" cellspacing="0" cellpadding="0"><tr class="crayon-table-header">', '<td>ID</td><td>Name</td><td>Version</td><td>File Extensions</td><td>Aliases</td><td>State</td></tr>'; $keys = array_values($langs); for ($i = 0; $i < count($langs); $i++) { $lang = $keys[$i]; $tr = $i == count($langs) - 1 ? 'crayon-table-last' : ''; echo '<tr class="', $tr, '">', '<td>', $lang->id(), '</td>', '<td>', $lang->name(), '</td>', '<td>', $lang->version(), '</td>', '<td>', implode(', ', $lang->ext()), '</td>', '<td>', implode(', ', $lang->alias()), '</td>', '<td class="', strtolower(CrayonUtil::space_to_hyphen($lang->state_info())), '">', $lang->state_info(), '</td>', '</tr>'; } echo '</table><br/>Languages that have the same extension as their name don\'t need to explicitly map extensions.'; } else { echo 'No languages could be found.'; } exit; }
<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($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 { $this->language_detect(); } // Prepare the language for use, even if we have no code, we need the name CrayonParser::parse($this->language->id()); }
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; }
<?php require_once dirname(dirname(__FILE__)) . '/global.php'; require_once CRAYON_PARSER_PHP; if (($langs = CrayonParser::parse_all()) != FALSE) { echo '<table class="crayon-table" cellspacing="0" cellpadding="0"><tr class="crayon-table-header">', '<td>ID</td><td>Name</td><td>Version</td><td>File Extensions</td><td>Aliases</td><td>State</td></tr>'; $keys = array_values($langs); for ($i = 0; $i < count($langs); $i++) { $lang = $keys[$i]; $tr = $i == count($langs) - 1 ? 'crayon-table-last' : ''; echo '<tr class="', $tr, '">', '<td>', $lang->id(), '</td>', '<td>', $lang->name(), '</td>', '<td>', $lang->version(), '</td>', '<td>', implode(', ', $lang->ext()), '</td>', '<td>', implode(', ', $lang->alias()), '</td>', '<td class="', strtolower(CrayonUtil::space_to_hyphen($lang->state_info())), '">', $lang->state_info(), '</td>', '</tr>'; } echo '</table><br/>Languages that have the same extension as their name don\'t need to explicitly map extensions.'; } else { echo 'No languages could be found.'; }
function css($css = NULL) { if ($css == NULL) { return $this->css; } else { if (is_string($css)) { $this->css = CrayonParser::validate_css($css); } } }
public static function langs() { echo '<a name="langs"></a>'; // Specialised dropdown for languages if (array_key_exists(CrayonSettings::FALLBACK_LANG, self::$options)) { if (($langs = CrayonParser::parse_all()) != FALSE) { 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 '</select>', CRAYON_BR, $parsed ? '' : '<span class="crayon-error">', 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 ? '. ' : '</span>'; // 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 '<br/><span class="crayon-error">', sprintf(crayon__('The selected language with id %s could not be loaded'), '<strong>' . $db_fallback . '</strong>'), '. </span>'; } // Language parsing info echo CRAYON_BR, '<div id="crayon-subsection-lang-info"><div><a id="show-lang" class="button-primary" onclick="CrayonSyntaxAdmin.show_langs(\'', plugins_url(CRAYON_LIST_LANGS_PHP, __FILE__), '\');">', crayon__('Show Languages'), '</a></div></div>'; } else { echo 'No languages could be parsed.'; } } }
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()); }