'.__('WP SyntaxHighlighter has successfully created new DB table.
If you upgraded to this version, some new setting options may be added.
Go to the setting panel and configure WP SyntaxHighlighter now. Once you save your settings, this message will be cleared.', 'wp_sh').'
';
}
// Message for admin when data migration done
function wp_sh_admin_migration_notice() {
echo ''.__('All setting data has migrated successfully.
If you upgraded from ver. 1.3 or older to this version, a part of setting parameters may be reset to the default values.
Go to the setting panel and check your setting parameters. Once you save your settings, this message will be cleared.', 'wp_sh').'
';
}
// Resotre updated settings in DB
function wp_sh_update_setting() {
global $wp_sh_allowed_str, $wp_sh_setting_opt;
$wp_sh_brushes = get_option('wp_sh_brush_files');
// Get updated settings
$wp_sh_code_title = stripslashes($_POST['wp_sh_code_title']);
$wp_sh_class_name = stripslashes($_POST['wp_sh_class_name']);
$wp_sh_addl_style = stripslashes($_POST['wp_sh_addl_style']);
$wp_sh_collapse_lable_text = stripslashes($_POST['wp_sh_collapse_lable_text']);
if (version_compare(get_bloginfo('version'), "3.0", ">=")) {
$wp_sh_comment_hl_description_before = stripslashes($_POST['wp_sh_comment_hl_description_before']);
$wp_sh_comment_hl_stylesheet = stripslashes($_POST['wp_sh_comment_hl_stylesheet']);
} else {
$wp_sh_comment_hl_description_before = wp_sh_default_setting_value('comment_desc');
$wp_sh_comment_hl_stylesheet = wp_sh_default_setting_value('comment_style');
}
$wp_sh_bbpress_hl_description_before = stripslashes($_POST['wp_sh_bbpress_hl_description_before']);
$wp_sh_bbpress_hl_stylesheet = stripslashes($_POST['wp_sh_bbpress_hl_stylesheet']);
// Transforming before validation
$wp_sh_addl_style = strip_tags($wp_sh_addl_style);
$wp_sh_comment_hl_description_before = str_replace(array("\r\n", "\r", "\n"), "
", $wp_sh_comment_hl_description_before);
$wp_sh_comment_hl_stylesheet = strip_tags($wp_sh_comment_hl_stylesheet);
$wp_sh_bbpress_hl_description_before = str_replace(array("\r\n", "\r", "\n"), "
", $wp_sh_bbpress_hl_description_before);
$wp_sh_bbpress_hl_stylesheet = strip_tags($wp_sh_bbpress_hl_stylesheet);
// Validate values
if (!preg_match("/^[0-9]+$/", $wp_sh_setting_opt['first_line'])) {
wp_die(__("Invalid value. Settings could not be saved.
Your \"Line number(Gutter)\" must be entered in numbers.", 'wp_sh'));
}
if (!preg_match("/^[0-9]+$/", $wp_sh_setting_opt['tab_size'])) {
wp_die(__("Invalid value. Settings could not be saved.
Your \"Tab size\" must be entered in numbers.", 'wp_sh'));
}
if (strpos($wp_sh_class_name, "\"") || strpos($wp_sh_class_name, "'")) {
wp_die(__("Invalid value. Settings could not be saved.
Your \"Class attribute\" contains \" or ' that are not allowed to use.", 'wp_sh'));
}
if (wp_sh_valid_css($wp_sh_addl_style) == "invalid") {
wp_die(__('Invalid value. Settings could not be saved.
Your "Stylesheet" contains some character strings that are not allowed to use.', 'wp_sh'));
} else {
$wp_sh_addl_style = wp_sh_valid_css($wp_sh_addl_style);
}
if (wp_sh_valid_text($wp_sh_comment_hl_description_before, $wp_sh_allowed_str) == "invalid") {
wp_die(__('Invalid value. Settings could not be saved.
Your "Description" for "Comment Highlighter Button" contains some character strings that are not allowed to use.', 'wp_sh'));
} else {
$wp_sh_comment_hl_description_before = wp_sh_valid_text($wp_sh_comment_hl_description_before, $wp_sh_allowed_str);
}
if (wp_sh_valid_css($wp_sh_comment_hl_stylesheet) == "invalid") {
wp_die(__('Invalid value. Settings could not be saved.
Your "Stylesheet" for "Comment Highlighter Button" contains some character strings that are not allowed to use.', 'wp_sh'));
} else {
$wp_sh_comment_hl_stylesheet = wp_sh_valid_css($wp_sh_comment_hl_stylesheet);
}
if (wp_sh_valid_text($wp_sh_bbpress_hl_description_before, $wp_sh_allowed_str) == "invalid") {
wp_die(__('Invalid value. Settings could not be saved.
Your "Description" for "bbpress Highlighter Button" contains some character strings that are not allowed to use.', 'wp_sh'));
} else {
$wp_sh_bbpress_hl_description_before = wp_sh_valid_text($wp_sh_bbpress_hl_description_before, $wp_sh_allowed_str);
}
if (wp_sh_valid_css($wp_sh_bbpress_hl_stylesheet) == "invalid") {
wp_die(__('Invalid value. Settings could not be saved.
Your "Stylesheet" for "bbPress Highlighter Button" contains some character strings that are not allowed to use.', 'wp_sh'));
} else {
$wp_sh_bbpress_hl_stylesheet = wp_sh_valid_css($wp_sh_bbpress_hl_stylesheet);
}
// For backward compatibility
$wp_sh_version = $_POST['lib_version'];
if ($_POST['gutter'] == "true") {
$wp_sh_gutter = 1;
} else {
$wp_sh_gutter = 0;
}
$wp_sh_first_line = $_POST['first_line'];
// Update languages
foreach ($wp_sh_brushes as $lang => $val) {
$brush_file = $val[0];
$brush_alias = $val[1];
$brush_ver = $val[2];
$wp_sh_brush_files[$lang] = array($brush_file, $brush_alias, $brush_ver, $_POST[$lang]);
}
// Restore in DB
update_option('wp_sh_version', $wp_sh_version); // For backward compatibility
update_option('wp_sh_gutter', $wp_sh_gutter); // For backward compatibility
update_option('wp_sh_first_line', $wp_sh_first_line); // For backward compatibility
update_option('wp_sh_setting_opt', $wp_sh_setting_opt);
update_option('wp_sh_code_title', $wp_sh_code_title);
update_option('wp_sh_class_name', $wp_sh_class_name);
update_option('wp_sh_addl_style', $wp_sh_addl_style);
update_option('wp_sh_collapse_lable_text', $wp_sh_collapse_lable_text);
update_option('wp_sh_comment_hl_description_before', $wp_sh_comment_hl_description_before);
update_option('wp_sh_comment_hl_stylesheet', $wp_sh_comment_hl_stylesheet);
update_option('wp_sh_bbpress_hl_description_before', $wp_sh_bbpress_hl_description_before);
update_option('wp_sh_bbpress_hl_stylesheet', $wp_sh_bbpress_hl_stylesheet);
update_option('wp_sh_brush_files', $wp_sh_brush_files);
update_option('wp_sh_updated', 'false');
// Rebuild language list
wp_sh_rebuild_lang_list();
// Message for admin
echo "".__("Settings saved.","wp_sh")."
";
}
// Rebuild language list
function wp_sh_rebuild_lang_list() {
$wp_sh_language3 = get_option('wp_sh_language3');
$wp_sh_language2 = get_option('wp_sh_language2');
$wp_sh_brush_files = get_option('wp_sh_brush_files');
foreach ($wp_sh_language3 as $alias3 => $val3) {
$lang_label = $val3[0];
$lang_enable = $val3[1];
$pattern1 = '/^'.$alias3.'$/i';
$pattern2 = '/^'.$alias3.'\s/i';
$pattern3 = '/\s'.$alias3.'\s/i';
$pattern4 = '/\s'.$alias3.'$/i';
if ($lang_enable == 'added') {
$wp_sh_language3[$alias3] = array($lang_label, $lang_enable);
}
foreach ($wp_sh_brush_files as $lang3 => $value3) {
$brush_alias = $value3[1];
$brush_enable = $value3[3];
if (preg_match($pattern1, $brush_alias) || preg_match($pattern2, $brush_alias) || preg_match($pattern3, $brush_alias) || preg_match($pattern4, $brush_alias)) {
$wp_sh_language3[$alias3] = array($lang_label, $brush_enable);
}
}
}
foreach ($wp_sh_language2 as $alias2 => $val2) {
$lang_label = $val2[0];
$lang_enable = $val2[1];
$pattern1 = '/^'.$alias2.'$/i';
$pattern2 = '/^'.$alias2.'\s/i';
$pattern3 = '/\s'.$alias2.'\s/i';
$pattern4 = '/\s'.$alias2.'$/i';
if ($lang_enable == 'added') {
$wp_sh_language2[$alias2] = array($lang_label, $lang_enable);
}
foreach ($wp_sh_brush_files as $lang2 => $value2) {
$brush_alias = $value2[1];
$brush_enable = $value2[3];
if (preg_match($pattern1, $brush_alias) || preg_match($pattern2, $brush_alias) || preg_match($pattern3, $brush_alias) || preg_match($pattern4, $brush_alias)) {
$wp_sh_language2[$alias2] = array($lang_label, $brush_enable);
}
}
}
update_option('wp_sh_language3', $wp_sh_language3);
update_option('wp_sh_language2', $wp_sh_language2);
}
// Reset all settings to default
function wp_sh_reset_setting() {
global $wp_sh_db_ver;
// Remove all settings from DB
include_once('uninstall.php');
// Register default settings
wp_sh_language_array();
wp_sh_setting_array();
add_option('wp_sh_checkver_stamp', $wp_sh_db_ver);
// Message for admin
echo "";
}
// Setting panel
function wp_sh_options_panel() {
global $wp_sh_plugin_url, $wp_sh_allowed_str, $wp_sh_setting_opt;
if(!function_exists('current_user_can') || !current_user_can('manage_options')){
die(__('Cheatin’ uh?'));
}
// Show info on footer
add_action('in_admin_footer', 'wp_sh_add_admin_footer');
// Update settings
if (isset($_POST['WP_SH_Setting_submit']) && $_POST['wp_sh_hidden_value'] == "true" && check_admin_referer("wp-sh-update_options", "_wpnonce_update_options")) {
wp_sh_update_setting();
}
// Reset all settings
if (isset($_POST['WP_SH_Reset']) && $_POST['wp_sh_reset'] == "true" && check_admin_referer("wp-sh-reset_options", "_wpnonce_reset_options")) {
wp_sh_reset_setting();
}
// Load script for admin footer
add_action('admin_footer', 'wp_sh_load_scripts_on_footer');
?>