From 813ff48cc3d1757d5406e416929b8e9ac42c600a Mon Sep 17 00:00:00 2001 From: Filippo Buratti Date: Thu, 20 Aug 2015 17:58:30 +0200 Subject: [PATCH 1/7] added option to hide dismiss button in alert shortcode --- inc/bs_alert.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/inc/bs_alert.php b/inc/bs_alert.php index 90dd401..1bb3f35 100644 --- a/inc/bs_alert.php +++ b/inc/bs_alert.php @@ -1,13 +1,14 @@ 'unknown' + 'type' => 'unknown', + 'dismissible' => 1 ), $params ) ); $content = preg_replace( '/
/', '', $content ); - $result = '
'; - $result .= ''; + $result = '
'; + $result .= $dismissible==1 ? '' : ''; $result .= do_shortcode( $content ); $result .= '
'; return force_balance_tags( $result ); } -add_shortcode( 'bs_notification', 'bs_notice' ); +add_shortcode( 'bs_notification', 'bs_notice' ); \ No newline at end of file From a894dad6fe39105ad474ef6f34f44663bc6ebd79 Mon Sep 17 00:00:00 2001 From: Sinetheta Date: Sat, 22 Aug 2015 20:29:53 -0700 Subject: [PATCH 2/7] Prefer true/false flag to 1/not-1 --- inc/bs_alert.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inc/bs_alert.php b/inc/bs_alert.php index 1bb3f35..6d4cc0f 100644 --- a/inc/bs_alert.php +++ b/inc/bs_alert.php @@ -2,13 +2,13 @@ function bs_notice( $params, $content=null ) { extract( shortcode_atts( array( 'type' => 'unknown', - 'dismissible' => 1 + 'dismissible' => 'true' ), $params ) ); $content = preg_replace( '/
/', '', $content ); - $result = '
'; - $result .= $dismissible==1 ? '' : ''; + $result = '
'; + $result .= $dismissible=='true'? '' : ''; $result .= do_shortcode( $content ); $result .= '
'; return force_balance_tags( $result ); } -add_shortcode( 'bs_notification', 'bs_notice' ); \ No newline at end of file +add_shortcode( 'bs_notification', 'bs_notice' ); From c86f10657dc7f483186beb6dea6ed72822e521a7 Mon Sep 17 00:00:00 2001 From: Sinetheta Date: Sat, 22 Aug 2015 21:14:31 -0700 Subject: [PATCH 3/7] Add control panel popup for inserting alerts With the new "dismissible" option, we need a more complex UI so let's add a small form for inserting alerts. This one includes a "preview" pane to see the alert type which will be added. --- js/plugins/alerts.html | 91 ++++++++++++++++++++++++++++++++++++++++++ js/plugins/alerts.js | 21 +++++----- 2 files changed, 102 insertions(+), 10 deletions(-) create mode 100644 js/plugins/alerts.html diff --git a/js/plugins/alerts.html b/js/plugins/alerts.html new file mode 100644 index 0000000..3959088 --- /dev/null +++ b/js/plugins/alerts.html @@ -0,0 +1,91 @@ + + + + + + + + + + + + +
+
+
+

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 + }); + } }); }); From 91879d25af65fb0af32252c202d3cb68debc7796 Mon Sep 17 00:00:00 2001 From: No3x Date: Mon, 24 Aug 2015 17:03:28 +0200 Subject: [PATCH 4/7] Do shortcode via ajax to get a real preview. This avoids building the shortcode parsing logic for preview once again in the js. --- bootstrap-shortcodes.php | 21 +++++++++++++++++++++ js/plugins/alerts.html | 8 +++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/bootstrap-shortcodes.php b/bootstrap-shortcodes.php index 913d2ba..0695ca6 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,22 @@ 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_sortcode' ); + return $settings; + } + + function bss_do_shortcode() { + if( false == check_ajax_referer('bss_ajax_do_sortcode', 'nonce', false) ) { + _e( 'Security Issue - No Preview', 'bsshortcodes'); + } else { + $shortcode = $_POST['shortcode']; + echo stripslashes( do_shortcode( $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') ); } @@ -163,3 +181,6 @@ function dw_render_form() { } $bscodes = new BootstrapShortcodes(); + + + diff --git a/js/plugins/alerts.html b/js/plugins/alerts.html index 3959088..ec8e174 100644 --- a/js/plugins/alerts.html +++ b/js/plugins/alerts.html @@ -23,7 +23,13 @@ function renderAlertPreview() { var closebutton = ''; var template = '' - $('#alert-demo').html(template); + jQuery.post(top.tinymce.settings.ajaxurl, { + 'action': 'bss_do_shortcode', + 'nonce': top.tinymce.settings.bss_nonce, + 'shortcode': template + }, function(response) { + $('#alert-demo').html( response ); + }); } function insertShortcode(event) { From 8aeeabfc123aa22000a2db2c04470baf0973bebd Mon Sep 17 00:00:00 2001 From: No3x Date: Mon, 24 Aug 2015 17:32:30 +0200 Subject: [PATCH 5/7] Removed blank lines. --- bootstrap-shortcodes.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bootstrap-shortcodes.php b/bootstrap-shortcodes.php index 0695ca6..5166fbb 100644 --- a/bootstrap-shortcodes.php +++ b/bootstrap-shortcodes.php @@ -180,7 +180,4 @@ function dw_render_form() { } } -$bscodes = new BootstrapShortcodes(); - - - +$bscodes = new BootstrapShortcodes(); \ No newline at end of file From 094087c49483810037369b9d64d915cd75f84c3a Mon Sep 17 00:00:00 2001 From: No3x Date: Mon, 24 Aug 2015 17:52:24 +0200 Subject: [PATCH 6/7] Fixed typo --- bootstrap-shortcodes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bootstrap-shortcodes.php b/bootstrap-shortcodes.php index 5166fbb..e5d34b9 100644 --- a/bootstrap-shortcodes.php +++ b/bootstrap-shortcodes.php @@ -87,12 +87,12 @@ function regplugins( $plgs) { function register_tinymce_settings( $settings ) { $settings['ajaxurl'] = admin_url( 'admin-ajax.php' ); - $settings['bss_nonce'] = wp_create_nonce( 'bss_ajax_do_sortcode' ); + $settings['bss_nonce'] = wp_create_nonce( 'bss_ajax_do_shortcode' ); return $settings; } function bss_do_shortcode() { - if( false == check_ajax_referer('bss_ajax_do_sortcode', 'nonce', false) ) { + if( false == check_ajax_referer('bss_ajax_do_shortcode', 'nonce', false) ) { _e( 'Security Issue - No Preview', 'bsshortcodes'); } else { $shortcode = $_POST['shortcode']; From 59387f62a4de20f5b3e589fad41663e1cbc39991 Mon Sep 17 00:00:00 2001 From: No3x Date: Mon, 31 Aug 2015 16:38:16 +0200 Subject: [PATCH 7/7] Fixed nonsense preview. --- bootstrap-shortcodes.php | 5 ++--- js/plugins/alerts.html | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/bootstrap-shortcodes.php b/bootstrap-shortcodes.php index e5d34b9..ce8435b 100644 --- a/bootstrap-shortcodes.php +++ b/bootstrap-shortcodes.php @@ -92,11 +92,10 @@ function register_tinymce_settings( $settings ) { } function bss_do_shortcode() { - if( false == check_ajax_referer('bss_ajax_do_shortcode', 'nonce', false) ) { + if( false === check_ajax_referer('bss_ajax_do_shortcode', 'nonce', false) ) { _e( 'Security Issue - No Preview', 'bsshortcodes'); } else { - $shortcode = $_POST['shortcode']; - echo stripslashes( do_shortcode( $shortcode ) ); + echo do_shortcode( wp_unslash( $_POST['shortcode'] ) ) ; } wp_die(); // this is required to terminate immediately and return a proper response } diff --git a/js/plugins/alerts.html b/js/plugins/alerts.html index ec8e174..77fe78e 100644 --- a/js/plugins/alerts.html +++ b/js/plugins/alerts.html @@ -21,12 +21,10 @@ } function renderAlertPreview() { - var closebutton = ''; - var template = '' jQuery.post(top.tinymce.settings.ajaxurl, { 'action': 'bss_do_shortcode', 'nonce': top.tinymce.settings.bss_nonce, - 'shortcode': template + 'shortcode': alertShortcode() }, function(response) { $('#alert-demo').html( response ); });