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 = crayon_pf(CRAYON_UTIL_PATH . '/sample/' . $lang . '.txt', FALSE); 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; }
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(); } // 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('crayon-cache-clear', $_POST)) { self::clear_cache(); } // Validate inputs foreach ($inputs as $input => $value) { // Convert all array setting values to ints $inputs[$input] = CrayonSettings::validate($input, $value); // Clear cache when changed if ($input == CrayonSettings::CACHE && $value != CrayonGlobalSettings::val(CrayonSettings::CACHE)) { self::clear_cache(); } } // If settings don't exist in input, set them to default $global_settings = CrayonSettings::get_defaults(); $ignored = array(CrayonSettings::HIDE_HELP, CrayonSettings::TINYMCE_USED); 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(); } } } } return $inputs; }
function set($name, $value = NULL, $replace = FALSE) { // Set associative array of settings if (is_array($name)) { $keys = array_keys($name); foreach ($keys as $key) { if (is_string($key)) { // Associative value $this->set($key, $name[$key], $replace); } else { if (is_int($key)) { $setting = $name[$key]; $this->set($setting, NULL, $replace); } } } } else { if (is_string($name) && !empty($name) && $value !== NULL) { $value = CrayonSettings::validate($name, $value); if ($replace || !$this->is_setting($name)) { // Replace/Create $this->settings[$name] = new CrayonSetting($name, $value); } else { // Update $this->settings[$name]->value($value); } } else { if (is_object($name) && get_class($name) == CRAYON_SETTING_CLASS) { $setting = $name; // Semantics if ($replace || !$this->is_setting($setting->name())) { // Replace/Create $this->settings[$setting->name()] = $setting->copy(); } else { // Update if ($setting->is_array()) { $this->settings[$setting->name()]->index($setting->index()); } else { $this->settings[$setting->name()]->value($setting->value()); } } } } } }
<?php require_once dirname(dirname(__FILE__)) . '/crayon_wp.class.php'; require_once CrayonWP::wp_load_path(); echo '<link rel="stylesheet" href="', plugins_url(CRAYON_STYLE, dirname(__FILE__)), '?ver=', $CRAYON_VERSION, '" type="text/css" media="all" />'; echo '<div id="content">'; CrayonSettingsWP::load_settings(); // Run first to ensure global settings loaded $crayon = CrayonWP::instance(); // Settings to prevent from validating $preview_settings = array(); // Load settings from GET and validate foreach ($_GET as $key => $value) { // echo $key, ' ', $value , '<br/>'; if (!in_array($key, $preview_settings)) { $_GET[$key] = CrayonSettings::validate($key, $value); } } $crayon->settings($_GET); 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); } $font_id = $crayon->setting_val(CrayonSettings::FONT); if ($font_id != NULL) { echo CrayonResources::fonts()->get_css($font_id);