public static function init_settings() { if (!self::$settings) { // Add settings CrayonSettingsWP::load_settings(TRUE); self::$settings = array('url' => plugins_url(CRAYON_TE_CONTENT_PHP, __FILE__), 'home_url' => home_url(), 'css' => 'crayon-te', 'used' => CrayonGlobalSettings::val(CrayonSettings::TINYMCE_USED), 'used_setting' => CrayonSettings::TINYMCE_USED, 'ajax_url' => plugins_url(CRAYON_AJAX_PHP, dirname(dirname(__FILE__))), 'css_selected' => 'crayon-selected', 'code_css' => '#crayon-code', 'url_css' => '#crayon-url', 'url_info_css' => '#crayon-te-url-info', 'lang_css' => '#crayon-lang', 'title_css' => '#crayon-title', 'mark_css' => '#crayon-mark', 'inline_css' => 'crayon-inline', 'inline_hide_css' => 'crayon-hide-inline', 'inline_hide_only_css' => 'crayon-hide-inline-only', 'hl_css' => '#crayon-highlight', 'switch_html' => '#content-html', 'switch_tmce' => '#content-tmce', 'tinymce_button' => '#content_crayon_tinymce', 'submit_css' => 'crayon-te-submit', 'submit_wrapper_css' => '#crayon-te-submit-wrapper', 'data_value' => 'data-value', 'attr_sep' => CrayonGlobalSettings::val_str(CrayonSettings::ATTR_SEP), 'css_sep' => '_', 'fallback_lang' => CrayonGlobalSettings::val(CrayonSettings::FALLBACK_LANG), 'dialog_title_add' => crayon__('Add Crayon Code'), 'dialog_title_edit' => crayon__('Edit Crayon Code'), 'submit_add' => crayon__('Add'), 'submit_edit' => crayon__('Save')); } }
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 update() { global $CRAYON_VERSION; CrayonSettingsWP::load_settings(TRUE); $settings = CrayonSettingsWP::get_settings(); if ($settings === NULL || !isset($settings[CrayonSettings::VERSION])) { return; } $version = $settings[CrayonSettings::VERSION]; // Only upgrade if the version differs if ($version != $CRAYON_VERSION) { $defaults = CrayonSettings::get_defaults_array(); $touched = FALSE; // Upgrade database and settings if (CrayonUtil::version_compare($version, '1.7.21') < 0) { $settings[CrayonSettings::SCROLL] = $defaults[CrayonSettings::SCROLL]; $touched = TRUE; } if (CrayonUtil::version_compare($version, '1.7.23') < 0 && $settings[CrayonSettings::FONT] == 'theme-font') { $settings[CrayonSettings::FONT] = $defaults[CrayonSettings::FONT]; $touched = TRUE; } if (CrayonUtil::version_compare($version, '1.14') < 0) { CrayonLog::syslog("Updated to v1.14: Font size enabled"); $settings[CrayonSettings::FONT_SIZE_ENABLE] = TRUE; } if (CrayonUtil::version_compare($version, '1.17') < 0) { $settings[CrayonSettings::HIDE_HELP] = FALSE; } // Save new version $settings[CrayonSettings::VERSION] = $CRAYON_VERSION; CrayonSettingsWP::save_settings($settings); CrayonLog::syslog("Updated from {$version} to {$CRAYON_VERSION}"); // Refresh to show new settings header('Location: ' . CrayonUtil::current_url()); 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
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 '<table class="crayon-table" cellspacing="0" cellpadding="0"><tr class="crayon-table-header">', '<td>', crayon__('ID'), '</td><td>', crayon__('Title'), '</td><td>', crayon__('Posted'), '</td><td>', crayon__('Modifed'), '</td><td>', crayon__('Contains Legacy Tags?'), '</td></tr>'; $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 '<tr class="', $tr, '">', '<td>', $postID, '</td>', '<td><a href="', $post->guid, '" target="_blank">', $title, '</a></td>', '<td>', $post->post_date, '</td>', '<td>', $post->post_modified, '</td>', '<td>', isset($legacy_map[strval($postID)]) ? '<span style="color: red;">' . crayon__('Yes') . '</a>' : crayon__('No'), '</td>', '</tr>'; } echo '</table>'; exit; }
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 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; }
<?php // Used to send requests to db from jQuery require_once dirname(dirname(__FILE__)) . '/crayon_wp.class.php'; require_once CrayonSettingsWP::wp_load_path(); CrayonSettingsWP::load_settings(true); //echo json_encode(CrayonGlobalSettings::get()); $allowed = array(CrayonSettings::HIDE_HELP, CrayonSettings::TINYMCE_USED); //var_dump($_GET); foreach ($allowed as $allow) { if (array_key_exists($allow, $_GET)) { CrayonGlobalSettings::set($allow, $_GET[$allow]); CrayonSettingsWP::save_settings(); } }
public static function save_post($id, $post) { CrayonSettingsWP::load_settings(TRUE); if (wp_is_post_revision($id)) { // Ignore revisions return; } self::init_tags_regex(); if (preg_match(self::$tags_regex, $post->post_content)) { CrayonSettingsWP::add_post($id); } else { CrayonSettingsWP::remove_post($id); } }