コード例 #1
0
function crayon_resources()
{
    global $CRAYON_VERSION;
    $plugin_url = CrayonGlobalSettings::plugin_path();
    // jQuery only needed once! Don't have two jQuerys, so remove if you've already got one in your header :)
    crayon_print_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', $CRAYON_VERSION);
    crayon_print_style('crayon-style', $plugin_url . CRAYON_STYLE, $CRAYON_VERSION);
    crayon_print_script('crayon_util_js', $plugin_url . CRAYON_JS_UTIL, $CRAYON_VERSION);
    crayon_print_script('crayon-js', $plugin_url . CRAYON_JS, $CRAYON_VERSION);
    crayon_print_script('crayon-jquery-popup', $plugin_url . CRAYON_JQUERY_POPUP, $CRAYON_VERSION);
}
コード例 #2
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;
     }
 }
 public static function show_preview()
 {
     echo '<div id="content">';
     self::load_settings();
     // Run first to ensure global settings loaded
     $crayon = CrayonWP::instance();
     // Settings to prevent from validating
     $preview_settings = array(self::SAMPLE_CODE);
     // Load settings from GET and validate
     foreach ($_POST as $key => $value) {
         //	echo $key, ' ', $value , '<br/>';
         $value = stripslashes($value);
         if (!in_array($key, $preview_settings)) {
             $_POST[$key] = CrayonSettings::validate($key, $value);
         } else {
             $_POST[$key] = $value;
         }
     }
     $crayon->settings($_POST);
     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, date('U'));
     }
     $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 = CrayonGlobalSettings::plugin_path() . CRAYON_UTIL_DIR . '/sample/' . $lang . '.txt';
     if (isset($_POST[self::SAMPLE_CODE])) {
         $crayon->code($_POST[self::SAMPLE_CODE]);
     } else {
         if ($lang && @file_exists($path)) {
             $crayon->url($path);
         } else {
             $code = "\n// A sample class\nclass Human {\n\tprivate int age = 0;\n\tpublic void birthday() {\n\t\tage++;\n\t\tprint('Happy Birthday!');\n\t}\n}\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();
     exit;
 }
コード例 #4
0
 public function dirurl($user = NULL)
 {
     $path = $user ? CrayonGlobalSettings::upload_url() : CrayonGlobalSettings::plugin_path();
     return CrayonUtil::path_slash($path . $this->relative_directory());
 }
コード例 #5
0
 public function get_url($id)
 {
     return CrayonGlobalSettings::plugin_path() . CrayonUtil::pathf(CRAYON_FONT_DIR) . $id . '.css';
 }
コード例 #6
0
 public static function plugin_path($plugin_path = NULL)
 {
     if ($plugin_path === NULL) {
         return self::$plugin_path;
     } else {
         self::$plugin_path = CrayonUtil::path_slash($plugin_path);
     }
 }
コード例 #7
0
 public static function get_crayon_help_file()
 {
     // Load help
     if (($help = @file_get_contents(CRAYON_HELP_FILE)) !== FALSE) {
         $help = str_replace('{PLUGIN}', CrayonGlobalSettings::plugin_path(), $help);
     } else {
         $help = 'Help failed to load... Try <a href="#info">these</a> instead.';
     }
     return $help;
 }