| @@ -46,11 +46,17 @@ | ||
| 46 | 46 | |
| 47 | 47 | // Get shortcodes. |
| 48 | 48 | $shortcodes = convertkit_get_shortcodes(); |
| 49 | 49 | |
| 50 | + // Bail if no shortcode or editor type is specified. | |
| 51 | + if ( ! isset( $_REQUEST['shortcode'] ) || ! isset( $_REQUEST['editor_type'] ) ) { | |
| 52 | + require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-missing.php'; | |
| 53 | + die(); | |
| 54 | + } | |
| 55 | + | |
| 50 | 56 | // Get requested shortcode name. |
| 51 | - $shortcode_name = sanitize_text_field( $_REQUEST['shortcode'] ); | |
| 52 | - $editor_type = sanitize_text_field( $_REQUEST['editor_type'] ); | |
| 57 | + $shortcode_name = sanitize_text_field( wp_unslash( $_REQUEST['shortcode'] ) ); | |
| 58 | + $editor_type = sanitize_text_field( wp_unslash( $_REQUEST['editor_type'] ) ); | |
| 53 | 59 | |
| 54 | 60 | // If the shortcode is not registered, return a view in the modal to tell the user. |
| 55 | 61 | if ( ! isset( $shortcodes[ $shortcode_name ] ) ) { |
| 56 | 62 | require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-missing.php'; |
| @@ -59,10 +65,30 @@ | ||
| 59 | 65 | |
| 60 | 66 | // Define shortcode. |
| 61 | 67 | $shortcode = $shortcodes[ $shortcode_name ]; |
| 62 | 68 | |
| 63 | - // Output the modal. | |
| 64 | - require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal.php'; | |
| 69 | + // Show a message in the modal if no Access Token is specified. | |
| 70 | + if ( array_key_exists( 'has_access_token', $shortcode ) && ! $shortcode['has_access_token'] ) { | |
| 71 | + $notice = $shortcode['no_access_token']; | |
| 72 | + require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-notice.php'; | |
| 73 | + die(); | |
| 74 | + } | |
| 75 | + | |
| 76 | + // Show a message in the modal if no resources exist. | |
| 77 | + if ( array_key_exists( 'has_resources', $shortcode ) && ! $shortcode['has_resources'] ) { | |
| 78 | + $notice = $shortcode['no_resources']; | |
| 79 | + require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-notice.php'; | |
| 80 | + die(); | |
| 81 | + } | |
| 82 | + | |
| 83 | + // If we have less than two panels defined in the shortcode properties, output a basic modal. | |
| 84 | + if ( count( $shortcode['panels'] ) < 2 ) { | |
| 85 | + require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal.php'; | |
| 86 | + die(); | |
| 87 | + } | |
| 88 | + | |
| 89 | + // Output tabbed view. | |
| 90 | + require_once CONVERTKIT_PLUGIN_PATH . '/views/backend/tinymce/modal-tabbed.php'; | |
| 65 | 91 | die(); |
| 66 | 92 | |
| 67 | 93 | } |
| 68 | 94 | |
| @@ -76,14 +102,14 @@ | ||
| 76 | 102 | // Get shortcodes. |
| 77 | 103 | $shortcodes = convertkit_get_shortcodes(); |
| 78 | 104 | |
| 79 | 105 | // Bail if no shortcode are available. |
| 80 | - if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) { | |
| 106 | + if ( ! count( $shortcodes ) ) { | |
| 81 | 107 | return; |
| 82 | 108 | } |
| 83 | 109 | |
| 84 | 110 | // Enqueue Quicktag JS. |
| 85 | - wp_enqueue_script( 'convertkit-admin-quicktags', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/quicktags.js', array( 'jquery', 'quicktags' ), CONVERTKIT_PLUGIN_VERSION, true ); | |
| 111 | + wp_enqueue_script( 'convertkit-admin-quicktags', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/quicktags.js', array( 'quicktags' ), CONVERTKIT_PLUGIN_VERSION, true ); | |
| 86 | 112 | |
| 87 | 113 | // Make shortcodes available as convertkit_quicktags JS variable. |
| 88 | 114 | wp_localize_script( 'convertkit-admin-quicktags', 'convertkit_quicktags', $shortcodes ); |
| 89 | 115 | |
| @@ -98,12 +124,8 @@ | ||
| 98 | 124 | |
| 99 | 125 | // Enqueue Quicktag CSS. |
| 100 | 126 | wp_enqueue_style( 'convertkit-admin-quicktags', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/quicktags.css', array(), CONVERTKIT_PLUGIN_VERSION ); |
| 101 | 127 | |
| 102 | - // Enqueue WordPress JS and CSS. | |
| 103 | - wp_enqueue_script( 'wp-color-picker' ); | |
| 104 | - wp_enqueue_style( 'wp-color-picker' ); | |
| 105 | - | |
| 106 | 128 | // Output Backbone View Template. |
| 107 | 129 | add_action( 'wp_print_footer_scripts', array( $this, 'output_quicktags_modal' ) ); |
| 108 | 130 | add_action( 'admin_print_footer_scripts', array( $this, 'output_quicktags_modal' ) ); |
| 109 | 131 | |
| @@ -122,20 +144,21 @@ | ||
| 122 | 144 | // Get shortcodes. |
| 123 | 145 | $shortcodes = convertkit_get_shortcodes(); |
| 124 | 146 | |
| 125 | 147 | // Bail if no shortcodes are available. |
| 126 | - if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) { | |
| 148 | + if ( ! count( $shortcodes ) ) { | |
| 127 | 149 | return $plugins; |
| 128 | 150 | } |
| 129 | 151 | |
| 130 | 152 | // Enqueue TinyMCE CSS and JS. |
| 131 | - wp_enqueue_script( 'convertkit-admin-tinymce', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/tinymce.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true ); | |
| 132 | - wp_enqueue_script( 'convertkit-admin-modal', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/modal.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true ); | |
| 153 | + wp_enqueue_script( 'convertkit-admin-tabs', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/tabs.js', array( 'jquery' ), CONVERTKIT_PLUGIN_VERSION, true ); | |
| 154 | + wp_enqueue_script( 'convertkit-admin-editor', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/editor.js', array(), CONVERTKIT_PLUGIN_VERSION, true ); | |
| 155 | + wp_enqueue_script( 'convertkit-admin-modal', CONVERTKIT_PLUGIN_URL . 'resources/backend/js/modal.js', array(), CONVERTKIT_PLUGIN_VERSION, true ); | |
| 133 | 156 | wp_enqueue_style( 'convertkit-admin-tinymce', CONVERTKIT_PLUGIN_URL . 'resources/backend/css/tinymce.css', array(), CONVERTKIT_PLUGIN_VERSION ); |
| 134 | 157 | |
| 135 | 158 | // Register JS variable convertkit_admin_tinymce.nonce for AJAX calls. |
| 136 | 159 | wp_localize_script( |
| 137 | - 'convertkit-admin-tinymce', | |
| 160 | + 'convertkit-admin-editor', | |
| 138 | 161 | 'convertkit_admin_tinymce', |
| 139 | 162 | array( |
| 140 | 163 | 'nonce' => wp_create_nonce( 'convertkit_admin_tinymce' ), |
| 141 | 164 | ) |
| @@ -141,9 +164,9 @@ | ||
| 141 | 164 | ) |
| 142 | 165 | ); |
| 143 | 166 | |
| 144 | 167 | // Make shortcodes available as convertkit_shortcodes JS variable. |
| 145 | - wp_localize_script( 'convertkit-admin-tinymce', 'convertkit_shortcodes', $shortcodes ); | |
| 168 | + wp_localize_script( 'convertkit-admin-editor', 'convertkit_shortcodes', $shortcodes ); | |
| 146 | 169 | |
| 147 | 170 | // Register TinyMCE Javascript Plugin. |
| 148 | 171 | foreach ( $shortcodes as $shortcode => $properties ) { |
| 149 | 172 | $plugins[ 'convertkit_' . $shortcode ] = CONVERTKIT_PLUGIN_URL . 'resources/backend/js/tinymce-' . $shortcode . '.js'; |
| @@ -166,9 +189,9 @@ | ||
| 166 | 189 | // Get shortcodes. |
| 167 | 190 | $shortcodes = convertkit_get_shortcodes(); |
| 168 | 191 | |
| 169 | 192 | // Bail if no shortcodes are available. |
| 170 | - if ( ! is_array( $shortcodes ) || ! count( $shortcodes ) ) { | |
| 193 | + if ( ! count( $shortcodes ) ) { | |
| 171 | 194 | return $buttons; |
| 172 | 195 | } |
| 173 | 196 | |
| 174 | 197 | // Register each Shortcode as a TinyMCE Button. |
| @@ -190,10 +213,20 @@ | ||
| 190 | 213 | |
| 191 | 214 | ?> |
| 192 | 215 | <script type="text/template" id="tmpl-convertkit-quicktags-modal"> |
| 193 | 216 | <div id="convertkit-quicktags-modal"> |
| 194 | - <div class="media-frame-title"><h1>Title</h1></div> | |
| 195 | - <div class="media-frame-content">Content</div> | |
| 217 | + <div class="media-frame-title"><h1></h1></div> | |
| 218 | + <div class="media-frame-content"></div> | |
| 219 | + <div class="media-frame-toolbar"> | |
| 220 | + <div class="media-toolbar"> | |
| 221 | + <div class="media-toolbar-secondary"> | |
| 222 | + <button type="button" class="button button-large cancel"><?php esc_html_e( 'Cancel', 'convertkit' ); ?></button> | |
| 223 | + </div> | |
| 224 | + <div class="media-toolbar-primary"> | |
| 225 | + <button type="button" class="button button-primary button-large"><?php esc_html_e( 'Insert', 'convertkit' ); ?></button> | |
| 226 | + </div> | |
| 227 | + </div> | |
| 228 | + </div> | |
| 196 | 229 | </div> |
| 197 | 230 | </script> |
| 198 | 231 | <?php |
| 199 | 232 | |