コード例 #1
0
 public static function load_settings($just_load_settings = FALSE)
 {
     if (self::$options === NULL) {
         // Load settings from db
         if (!(self::$options = get_option(self::OPTIONS))) {
             self::$options = CrayonSettings::get_defaults_array();
             update_option(self::OPTIONS, self::$options);
         }
         // Initialise default global settings and update them from db
         CrayonGlobalSettings::set(self::$options);
     }
     if (!self::$is_fully_loaded && !$just_load_settings) {
         // Load everything else as well
         // For local file loading
         // This is used to decouple WP functions from internal Crayon classes
         CrayonGlobalSettings::site_url(home_url());
         CrayonGlobalSettings::site_path(ABSPATH);
         CrayonGlobalSettings::plugin_path(plugins_url('', __FILE__));
         $upload = wp_upload_dir();
         CrayonLog::debug($upload, "WP UPLOAD FUNCTION");
         CrayonGlobalSettings::upload_path(CrayonUtil::path_slash($upload['basedir']) . CRAYON_DIR);
         CrayonGlobalSettings::upload_url($upload['baseurl'] . '/' . CRAYON_DIR);
         CrayonLog::debug(CrayonGlobalSettings::upload_path(), "UPLOAD PATH");
         CrayonGlobalSettings::set_mkdir('wp_mkdir_p');
         // Load all available languages and themes
         CrayonResources::langs()->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;
     }
 }
コード例 #2
0
 public static function ajax()
 {
     $allowed = array(CrayonSettings::HIDE_HELP);
     foreach ($allowed as $allow) {
         if (array_key_exists($allow, $_GET)) {
             CrayonGlobalSettings::set($allow, $_GET[$allow]);
             CrayonSettingsWP::save_settings();
         }
     }
 }
 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(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;
 }
コード例 #4
0
 public static function delete()
 {
     CrayonSettingsWP::load_settings();
     $id = $_POST['id'];
     $dir = CrayonResources::themes()->dirpath_for_id($id);
     if (is_dir($dir) && CrayonResources::themes()->exists($id)) {
         try {
             CrayonUtil::deleteDir($dir);
             CrayonGlobalSettings::set(CrayonSettings::THEME, CrayonThemes::DEFAULT_THEME);
             CrayonSettingsWP::save_settings();
             echo 1;
         } catch (Exception $e) {
             CrayonLog::syslog($e->getMessage(), "THEME SAVE");
             echo -2;
         }
     } else {
         echo -1;
     }
     exit;
 }
コード例 #5
0
<?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();
    }
}
コード例 #6
0
 public static function the_posts($posts)
 {
     CrayonLog::debug('the_posts');
     // Whether to enqueue syles/scripts
     $enqueue = FALSE;
     CrayonSettingsWP::load_settings(TRUE);
     // Load just the settings from db, for now
     self::init_tags_regex();
     $crayon_posts = CrayonSettingsWP::load_posts();
     // Loads posts containing crayons
     // Search for shortcode in posts
     foreach ($posts as $post) {
         $wp_id = $post->ID;
         if (!in_array($wp_id, $crayon_posts)) {
             // If we get query for a page, then that page might have a template and load more posts containing Crayons
             // By this state, we would be unable to enqueue anything (header already written).
             if (CrayonGlobalSettings::val(CrayonSettings::SAFE_ENQUEUE) && is_page($wp_id)) {
                 CrayonGlobalSettings::set(CrayonSettings::ENQUEUE_THEMES, false);
                 CrayonGlobalSettings::set(CrayonSettings::ENQUEUE_FONTS, false);
             } else {
                 // Only include crayon posts
                 continue;
             }
         }
         $id_str = strval($wp_id);
         if (isset(self::$post_captures[$id_str])) {
             // Don't capture twice
             // XXX post->post_content is reset each loop, replace content
             // Doing this might cause content changed by other plugins between the last loop
             // to fail, so be cautious
             $post->post_content = self::$post_captures[$id_str];
             continue;
         }
         // Capture post Crayons
         $captures = self::capture_crayons($post->ID, $post->post_content);
         // XXX Careful not to undo changes by other plugins
         // XXX Must replace to remove $ for ignored Crayons
         $post->post_content = $captures['content'];
         self::$post_captures[$id_str] = $captures['content'];
         if ($captures['has_captured'] === TRUE) {
             $enqueue = TRUE;
             self::$post_queue[$id_str] = array();
             foreach ($captures['capture'] as $capture_id => $capture_content) {
                 self::$post_queue[$id_str][$capture_id] = $capture_content;
             }
         }
         // Search for shortcode in comments
         if (CrayonGlobalSettings::val(CrayonSettings::COMMENTS)) {
             $comments = get_comments(array('post_id' => $post->ID));
             foreach ($comments as $comment) {
                 $id_str = strval($comment->comment_ID);
                 if (isset(self::$comment_queue[$id_str])) {
                     // Don't capture twice
                     continue;
                 }
                 // Capture comment Crayons, decode their contents if decode not specified
                 $captures = self::capture_crayons($comment->comment_ID, $comment->comment_content, array(CrayonSettings::DECODE => TRUE));
                 self::$comment_captures[$id_str] = $captures['content'];
                 if ($captures['has_captured'] === TRUE) {
                     $enqueue = TRUE;
                     self::$comment_queue[$id_str] = array();
                     foreach ($captures['capture'] as $capture_id => $capture_content) {
                         self::$comment_queue[$id_str][$capture_id] = $capture_content;
                     }
                 }
             }
         }
     }
     if (!is_admin() && $enqueue && !self::$enqueued) {
         // Crayons have been found and we enqueue efficiently
         self::enqueue_resources();
     }
     return $posts;
 }