diff --git a/bootstrap-shortcodes.php b/bootstrap-shortcodes.php index 913d2ba..ce8435b 100644 --- a/bootstrap-shortcodes.php +++ b/bootstrap-shortcodes.php @@ -41,6 +41,7 @@ public function __construct() { register_activation_hook( __FILE__, array( &$this, 'add_options_defaults' ) ); add_action( 'admin_init', array( &$this, 'register_settings' ) ); add_action( 'admin_menu', array( &$this, 'register_settings_page' ) ); + add_action( 'wp_ajax_bss_do_shortcode', array( &$this, 'bss_do_shortcode') ); } function init() { @@ -63,6 +64,7 @@ function init() { if ( get_user_option( 'rich_editing' ) == 'true' ) { add_filter( 'mce_external_plugins', array( &$this, 'regplugins' ) ); add_filter( 'mce_buttons_3', array( &$this, 'regbtns' ) ); + add_filter( 'tiny_mce_before_init', array( &$this ,'register_tinymce_settings') ); } } @@ -83,6 +85,21 @@ function regplugins( $plgs) { return $plgs; } + function register_tinymce_settings( $settings ) { + $settings['ajaxurl'] = admin_url( 'admin-ajax.php' ); + $settings['bss_nonce'] = wp_create_nonce( 'bss_ajax_do_shortcode' ); + return $settings; + } + + function bss_do_shortcode() { + if( false === check_ajax_referer('bss_ajax_do_shortcode', 'nonce', false) ) { + _e( 'Security Issue - No Preview', 'bsshortcodes'); + } else { + echo do_shortcode( wp_unslash( $_POST['shortcode'] ) ) ; + } + wp_die(); // this is required to terminate immediately and return a proper response + } + function register_settings_page() { add_options_page( __( 'BS Shortcodes', 'bsshortcodes' ), __( 'BS Shortcodes', 'bsshortcodes' ), 'manage_options', __FILE__, array( &$this, 'dw_render_form') ); } @@ -162,4 +179,4 @@ function dw_render_form() { } } -$bscodes = new BootstrapShortcodes(); +$bscodes = new BootstrapShortcodes(); \ No newline at end of file diff --git a/js/plugins/alerts.html b/js/plugins/alerts.html index 3959088..77fe78e 100644 --- a/js/plugins/alerts.html +++ b/js/plugins/alerts.html @@ -21,9 +21,13 @@ } function renderAlertPreview() { - var closebutton = ''; - var template = '