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/inc/bs_alert.php b/inc/bs_alert.php index 90dd401..6d4cc0f 100644 --- a/inc/bs_alert.php +++ b/inc/bs_alert.php @@ -1,11 +1,12 @@ 'unknown' + 'type' => 'unknown', + 'dismissible' => 'true' ), $params ) ); $content = preg_replace( '/
/', '', $content ); - $result = '
'; - $result .= ''; + $result = '
'; + $result .= $dismissible=='true'? '' : ''; $result .= do_shortcode( $content ); $result .= '
'; return force_balance_tags( $result ); diff --git a/js/plugins/alerts.html b/js/plugins/alerts.html new file mode 100644 index 0000000..77fe78e --- /dev/null +++ b/js/plugins/alerts.html @@ -0,0 +1,95 @@ + + + + + + + + + + + + +
+
+
+

Options

+
+
+ +
+
+
+ +
+
+
+ +
+
+
+
+

Preview

+
+ +
+
+
+
+ + diff --git a/js/plugins/alerts.js b/js/plugins/alerts.js index 7f66df7..9551196 100644 --- a/js/plugins/alerts.js +++ b/js/plugins/alerts.js @@ -1,13 +1,14 @@ -tinymce.PluginManager.add( 'bs_alerts', function( editor, url ) { - editor.addButton( 'bs_alerts', { - type: 'menubutton', +tinymce.PluginManager.add('bs_alerts', function(editor, url) { + editor.addButton('bs_alerts', { tooltip: 'Alerts', - icon: 'bs-alerts', - menu: [ - { text: 'Success notification', onclick: function() { editor.insertContent('[bs_notification type="success"]Well done!You successfully read this important alert message.[/bs_notification]');} }, - { text: 'Info notification', onclick: function() { editor.insertContent('[bs_notification type="info"]Heads up!This alert needs your attention, but it\'s not super important.[/bs_notification]');} }, - { text: 'Warning notification', onclick: function() { editor.insertContent('[bs_notification type="warning"]Warning!Best check yo self, you\'re not looking too good.[/bs_notification]');} }, - { text: 'Error notification', onclick: function() { editor.insertContent('[bs_notification type="danger"]Oh snap! Change a few things up and try submitting again.[/bs_notification]');} } - ] + icon: 'bs-alerts', + onclick: function() { + tinymce.activeEditor.windowManager.open({ + title: 'Add an alert', + url: url + '/alerts.html', + width: 480, + height: 180 + }); + } }); });