cleanup and update of jquery-colorpicker dependency

This commit is contained in:
2021-11-29 01:25:11 +01:00
parent 665970e71a
commit d02db09056
63 changed files with 13398 additions and 4845 deletions

View File

@ -9,7 +9,8 @@ require_once(CRAYON_SETTINGS_PHP);
CrayonHighlighter and any non-WP classes will only use CrayonSettings to separate
the implementation of global settings and ensure any system can use them. */
class CrayonSettingsWP {
class CrayonSettingsWP
{
// Properties and Constants ===============================================
// A copy of the current options in db
@ -45,12 +46,14 @@ class CrayonSettingsWP {
const SAMPLE_CODE = 'sample-code';
const CACHE_CLEAR = 'crayon-cache-clear';
private function __construct() {
private function __construct()
{
}
// Methods ================================================================
public static function admin_load() {
public static function admin_load()
{
self::$admin_page = $admin_page = add_options_page('Crayon Syntax Highlighter ' . crayon__('Settings'), 'Crayon', 'manage_options', 'crayon_settings', 'CrayonSettingsWP::settings');
add_action("admin_print_scripts-$admin_page", 'CrayonSettingsWP::admin_scripts');
add_action("admin_print_styles-$admin_page", 'CrayonSettingsWP::admin_styles');
@ -73,7 +76,8 @@ class CrayonSettingsWP {
}
}
public static function admin_styles() {
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);
@ -84,7 +88,8 @@ class CrayonSettingsWP {
}
}
public static function admin_scripts() {
public static function admin_scripts()
{
global $CRAYON_VERSION;
if (CRAYON_MINIFY) {
@ -102,7 +107,8 @@ class CrayonSettingsWP {
}
}
public static function other_scripts() {
public static function other_scripts()
{
global $CRAYON_VERSION;
self::load_settings(TRUE);
$deps = array('jquery', 'crayon_util_js');
@ -114,7 +120,8 @@ class CrayonSettingsWP {
wp_enqueue_script('crayon_js', plugins_url(CRAYON_JS, __FILE__), $deps, $CRAYON_VERSION);
}
public static function init_js_settings() {
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);
@ -147,7 +154,8 @@ class CrayonSettingsWP {
}
}
public static function init_admin_js_settings() {
public static function init_admin_js_settings()
{
if (!self::$admin_js_settings) {
// We need to load themes at this stage
CrayonSettingsWP::load_settings();
@ -189,7 +197,8 @@ class CrayonSettingsWP {
}
}
public static function settings() {
public static function settings()
{
if (!current_user_can('manage_options')) {
wp_die(crayon__('You do not have sufficient permissions to access this page.'));
}
@ -238,11 +247,12 @@ class CrayonSettingsWP {
<div id="crayon-theme-editor-wrap" class="wrap"></div>
<?php
<?php
}
// Load the global settings and update them from the db
public static function load_settings($just_load_settings = FALSE) {
public static function load_settings($just_load_settings = FALSE)
{
if (self::$options === NULL) {
// Load settings from db
if (!(self::$options = get_option(self::OPTIONS))) {
@ -291,12 +301,14 @@ class CrayonSettingsWP {
}
}
public static function get_settings() {
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) {
public static function save_settings($settings = NULL)
{
if ($settings === NULL) {
$settings = CrayonGlobalSettings::get_array();
}
@ -308,7 +320,8 @@ class CrayonSettingsWP {
/**
* This loads the posts marked as containing Crayons
*/
public static function load_posts() {
public static function load_posts()
{
if (self::$crayon_posts === NULL) {
// Load from db
if (!(self::$crayon_posts = get_option(self::POSTS))) {
@ -330,7 +343,8 @@ class CrayonSettingsWP {
/**
* Saves the marked posts to the db
*/
public static function save_posts($posts = NULL) {
public static function save_posts($posts = NULL)
{
if ($posts === NULL) {
$posts = self::$crayon_posts;
}
@ -341,7 +355,8 @@ class CrayonSettingsWP {
/**
* Adds a post as containing a Crayon
*/
public static function add_post($id, $save = TRUE) {
public static function add_post($id, $save = TRUE)
{
self::load_posts();
if (!in_array($id, self::$crayon_posts)) {
self::$crayon_posts[] = $id;
@ -354,7 +369,8 @@ class CrayonSettingsWP {
/**
* Removes a post as not containing a Crayon
*/
public static function remove_post($id, $save = TRUE) {
public static function remove_post($id, $save = TRUE)
{
self::load_posts();
$key = array_search($id, self::$crayon_posts);
if ($key === false) {
@ -366,7 +382,8 @@ class CrayonSettingsWP {
}
}
public static function remove_posts() {
public static function remove_posts()
{
self::$crayon_posts = array();
self::save_posts();
}
@ -376,7 +393,8 @@ class CrayonSettingsWP {
/**
* This loads the posts marked as containing Crayons
*/
public static function load_legacy_posts($force = FALSE) {
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))) {
@ -398,7 +416,8 @@ class CrayonSettingsWP {
/**
* Saves the marked posts to the db
*/
public static function save_legacy_posts($posts = NULL) {
public static function save_legacy_posts($posts = NULL)
{
if ($posts === NULL) {
$posts = self::$crayon_legacy_posts;
}
@ -409,7 +428,8 @@ class CrayonSettingsWP {
/**
* Adds a post as containing a Crayon
*/
public static function add_legacy_post($id, $save = TRUE) {
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;
@ -422,7 +442,8 @@ class CrayonSettingsWP {
/**
* Removes a post as not containing a Crayon
*/
public static function remove_legacy_post($id, $save = TRUE) {
public static function remove_legacy_post($id, $save = TRUE)
{
self::load_legacy_posts();
$key = array_search($id, self::$crayon_legacy_posts);
if ($key === false) {
@ -434,14 +455,16 @@ class CrayonSettingsWP {
}
}
public static function remove_legacy_posts() {
public static function remove_legacy_posts()
{
self::$crayon_legacy_posts = array();
self::save_legacy_posts();
}
// Cache
public static function add_cache($name) {
public static function add_cache($name)
{
self::load_cache();
if (!in_array($name, self::$cache)) {
self::$cache[] = $name;
@ -449,7 +472,8 @@ class CrayonSettingsWP {
self::save_cache();
}
public static function remove_cache($name) {
public static function remove_cache($name)
{
self::load_cache();
$key = array_search($name, self::$cache);
if ($key === false) {
@ -459,7 +483,8 @@ class CrayonSettingsWP {
self::save_cache();
}
public static function clear_cache() {
public static function clear_cache()
{
self::load_cache();
foreach (self::$cache as $name) {
delete_transient($name);
@ -468,7 +493,8 @@ class CrayonSettingsWP {
self::save_cache();
}
public static function load_cache() {
public static function load_cache()
{
// Load cache from db
if (!(self::$cache = get_option(self::CACHE))) {
self::$cache = array();
@ -476,14 +502,16 @@ class CrayonSettingsWP {
}
}
public static function save_cache() {
public static function save_cache()
{
update_option(self::CACHE, self::$cache);
self::load_cache();
}
// Paths
public static function admin_init() {
public static function admin_init()
{
// Load default settings if they don't exist
self::load_settings();
@ -518,19 +546,22 @@ class CrayonSettingsWP {
// Wrapper functions
private static function add_section($name, $title, $callback = NULL) {
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()) {
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) {
public static function settings_validate($inputs)
{
// Load current settings from db
self::load_settings(TRUE);
@ -630,12 +661,14 @@ class CrayonSettingsWP {
// Section callback functions
public static function blank() {
public static function blank()
{
} // Used for required callbacks with blank content
// Input Drawing ==========================================================
private static function input($args) {
private static function input($args)
{
$id = '';
$size = 40;
$margin = FALSE;
@ -648,7 +681,8 @@ class CrayonSettingsWP {
self::$options[$id], '" style="margin-left: ', ($margin ? '20px' : '0px'), ';" crayon-preview="', ($preview ? 1 : 0), '" />', ($break ? CRAYON_BR : '');
}
private static function checkbox($args, $line_break = TRUE, $preview = TRUE) {
private static function checkbox($args, $line_break = TRUE, $preview = TRUE)
{
if (empty($args) || !is_array($args) || count($args) != 2) {
return;
}
@ -661,7 +695,8 @@ class CrayonSettingsWP {
}
// 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) {
private static function dropdown($id, $line_break = TRUE, $preview = TRUE, $echo = TRUE, $resources = NULL, $selected = NULL)
{
if (!array_key_exists($id, self::$options)) {
return;
}
@ -686,7 +721,8 @@ class CrayonSettingsWP {
}
}
private static function button($args = array()) {
private static function button($args = array())
{
extract($args);
CrayonUtil::set_var($id, '');
CrayonUtil::set_var($class, '');
@ -695,26 +731,27 @@ class CrayonSettingsWP {
return '<a id="' . $id . '" class="button-primary ' . $class . '" onclick="' . $onclick . '">' . $title . '</a>';
}
private static function info_span($name, $text) {
private static function info_span($name, $text)
{
echo '<span id="', $name, '-info">', $text, '</span>';
}
private static function span($text) {
private static function span($text)
{
echo '<span>', $text, '</span>';
}
// General Fields =========================================================
public static function help() {
public static function help()
{
global $CRAYON_WEBSITE, $CRAYON_TWITTER, $CRAYON_GIT, $CRAYON_PLUGIN_WP, $CRAYON_DONATE;
if (CrayonGlobalSettings::val(CrayonSettings::HIDE_HELP)) {
return;
}
echo '<div id="crayon-help" class="updated settings-error crayon-help">
<p><strong>Howdy, coder!</strong> Thanks for using Crayon. <strong>Useful Links:</strong> <a href="' . $CRAYON_WEBSITE . '" target="_blank">Documentation</a>, <a href="' . $CRAYON_GIT . '" target="_blank">GitHub</a>, <a href="' . $CRAYON_PLUGIN_WP . '" target="_blank">Plugin Page</a>, <a href="' . $CRAYON_TWITTER . '" target="_blank">Twitter</a>. Crayon has always been free. If you value my work please consider a <a href="' . $CRAYON_DONATE . '">small donation</a> to show your appreciation. Thanks! <a class="crayon-help-close">X</a></p></div>
';
}
public static function help_screen() {
public static function help_screen()
{
$screen = get_current_screen();
if ($screen->id != self::$admin_page) {
@ -722,7 +759,8 @@ class CrayonSettingsWP {
}
}
public static function metrics() {
public static function metrics()
{
echo '<div id="crayon-section-metrics" class="crayon-hide-inline">';
self::checkbox(array(CrayonSettings::HEIGHT_SET, '<span class="crayon-span-50">' . crayon__('Height') . ' </span>'), FALSE);
self::dropdown(CrayonSettings::HEIGHT_MODE, FALSE);
@ -760,7 +798,8 @@ class CrayonSettingsWP {
echo '</div>';
}
public static function toolbar() {
public static function toolbar()
{
echo '<div id="crayon-section-toolbar" class="crayon-hide-inline">';
self::span(crayon__('Display the Toolbar') . ' ');
self::dropdown(CrayonSettings::TOOLBAR);
@ -775,7 +814,8 @@ class CrayonSettingsWP {
echo '</div>';
}
public static function lines() {
public static function lines()
{
echo '<div id="crayon-section-lines" class="crayon-hide-inline">';
self::checkbox(array(CrayonSettings::STRIPED, crayon__('Display striped code lines')));
self::checkbox(array(CrayonSettings::MARKING, crayon__('Enable line marking for important lines')));
@ -789,7 +829,8 @@ class CrayonSettingsWP {
echo '</div>';
}
public static function langs() {
public static function langs()
{
echo '<a name="langs"></a>';
// Specialised dropdown for languages
if (array_key_exists(CrayonSettings::FALLBACK_LANG, self::$options)) {
@ -818,7 +859,8 @@ class CrayonSettingsWP {
}
}
public static function show_langs() {
public static function show_langs()
{
CrayonSettingsWP::load_settings();
require_once(CRAYON_PARSER_PHP);
if (($langs = CrayonParser::parse_all()) != FALSE) {
@ -846,7 +888,8 @@ class CrayonSettingsWP {
exit();
}
public static function posts() {
public static function posts()
{
echo '<a name="posts"></a>';
echo self::button(array('id' => 'show-posts', 'title' => crayon__('Show Crayon Posts')));
echo ' <input type="submit" name="', self::OPTIONS, '[refresh_tags]" id="refresh_tags" class="button-primary" value="', crayon__('Refresh'), '" />';
@ -854,7 +897,8 @@ class CrayonSettingsWP {
echo '<div id="crayon-subsection-posts-info"></div>';
}
public static function post_cmp($a, $b) {
public static function post_cmp($a, $b)
{
$a = $a->post_modified;
$b = $b->post_modified;
if ($a == $b) {
@ -864,7 +908,8 @@ class CrayonSettingsWP {
}
}
public static function show_posts() {
public static function show_posts()
{
CrayonSettingsWP::load_settings();
$postIDs = self::load_posts();
$legacy_posts = self::load_legacy_posts();
@ -903,7 +948,8 @@ class CrayonSettingsWP {
exit();
}
public static function show_preview() {
public static function show_preview()
{
echo '<div id="content">';
self::load_settings(); // Run first to ensure global settings loaded
@ -970,7 +1016,8 @@ class Human {
exit();
}
public static function theme($editor = FALSE) {
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 = '';
@ -1022,7 +1069,8 @@ class Human {
}
}
public static function font($editor = FALSE) {
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 = '';
@ -1049,7 +1097,8 @@ class Human {
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) {
public static function code($editor = FALSE)
{
echo '<div id="crayon-section-code-interaction" class="crayon-hide-inline-only">';
self::checkbox(array(CrayonSettings::PLAIN, crayon__('Enable plain code view and display') . ' '), FALSE);
self::dropdown(CrayonSettings::SHOW_PLAIN);
@ -1085,7 +1134,8 @@ class Human {
self::input(array('id' => CrayonSettings::WHITESPACE_AFTER, 'size' => 2, 'break' => TRUE));
}
public static function tags() {
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 &lt;code&gt; as')), FALSE);
@ -1101,7 +1151,8 @@ class Human {
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() {
public static function files()
{
echo '<a name="files"></a>';
echo crayon__('When loading local files and a relative path is given for the URL, use the absolute path'), ': ',
'<div style="margin-left: 20px">', home_url(), '/';
@ -1109,7 +1160,8 @@ class Human {
echo '</div>', crayon__('Followed by your relative URL.');
}
public static function tag_editor() {
public static function tag_editor()
{
$can_convert = self::load_legacy_posts();
if ($can_convert) {
$disabled = '';
@ -1135,7 +1187,8 @@ class Human {
self::input(array('id' => CrayonSettings::TAG_EDITOR_QUICKTAG_BUTTON_TEXT, 'break' => TRUE));
}
public static function misc() {
public static function misc()
{
echo crayon__('Clear the cache used to store remote code requests'), ': ';
self::dropdown(CrayonSettings::CACHE, false);
echo '<input type="submit" id="', self::CACHE_CLEAR, '" name="', self::CACHE_CLEAR, '" class="button-secondary" value="', crayon__('Clear Now'), '" /><br/>';
@ -1155,14 +1208,16 @@ class Human {
// Debug Fields ===========================================================
public static function errors() {
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() {
public static function log()
{
$log = CrayonLog::log();
touch(CRAYON_LOG_FILE);
$exists = file_exists(CRAYON_LOG_FILE);
@ -1188,7 +1243,8 @@ class Human {
// About Fields ===========================================================
public static function info() {
public static function info()
{
global $CRAYON_VERSION, $CRAYON_DATE, $CRAYON_AUTHOR, $CRAYON_WEBSITE, $CRAYON_TWITTER, $CRAYON_GIT, $CRAYON_PLUGIN_WP, $CRAYON_AUTHOR_SITE, $CRAYON_EMAIL, $CRAYON_DONATE;
echo '<a name="info"></a>';
$version = '<strong>' . crayon__('Version') . ':</strong> ' . $CRAYON_VERSION;
@ -1224,10 +1280,7 @@ class Human {
<a id="git-icon" class="small-icon" title="GitHub" href="' . $CRAYON_GIT . '" target="_blank"></a>
<a id="wp-icon" class="small-icon" title="Plugin Page" href="' . $CRAYON_PLUGIN_WP . '" target="_blank"></a>
<a id="twitter-icon" class="small-icon" title="Twitter" href="' . $CRAYON_TWITTER . '" target="_blank"></a>
<a id="gmail-icon" class="small-icon" title="Email" href="mailto:' . $CRAYON_EMAIL . '" target="_blank"></a>
<div id="crayon-donate"><a href="' . $CRAYON_DONATE . '" title="Donate" target="_blank">
<img src="' . plugins_url(CRAYON_DONATE_BUTTON, __FILE__) . '"></a>
</div>';
<a id="gmail-icon" class="small-icon" title="Email" href="mailto:' . $CRAYON_EMAIL . '" target="_blank"></a>';
echo '
<table id="crayon-info" border="0">
@ -1244,14 +1297,15 @@ class Human {
<td colspan="2">' . $links . '</td>
</tr>
</table>';
}
public static function help_button($link) {
public static function help_button($link)
{
return ' <a href="' . $link . '" target="_blank" class="crayon-question">' . crayon__('?') . '</a>';
}
public static function plugin_row_meta($meta, $file) {
public static function plugin_row_meta($meta, $file)
{
global $CRAYON_DONATE;
if ($file == CrayonWP::basename()) {
$meta[] = '<a href="options-general.php?page=crayon_settings">' . crayon__('Settings') . '</a>';
@ -1269,5 +1323,3 @@ if (defined('ABSPATH') && is_admin()) {
add_action('admin_menu', 'CrayonSettingsWP::admin_load');
add_filter('plugin_row_meta', 'CrayonSettingsWP::plugin_row_meta', 10, 2);
}
?>