Changeset 2221536
- Timestamp:
- 01/03/2020 10:04:04 AM (6 years ago)
- Location:
- shortcode-tester/trunk
- Files:
-
- 4 edited
-
js/mf2tk_macros_admin.js (modified) (3 diffs)
-
readme.txt (modified) (3 diffs)
-
shortcode-tester-loader.php (modified) (1 diff)
-
shortcode-tester.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
shortcode-tester/trunk/js/mf2tk_macros_admin.js
r2197070 r2221536 14 14 }); 15 15 // "Shortcode Tester" evaluate button 16 divShortcode.find("button#mf2tk-shortcode-tester-evaluate,button#mf2tk-shortcode-tester-evaluate-and-prettify, button#mf2tk-shortcode-tester-show-rendered")17 .click(function(){16 divShortcode.find("button#mf2tk-shortcode-tester-evaluate,button#mf2tk-shortcode-tester-evaluate-and-prettify," 17 +"button#mf2tk-shortcode-tester-show-rendered,button#mf2tk-shortcode-tester-alt-show-rendered").click(function(){ 18 18 var permalink=jQuery("#sample-permalink a"); 19 19 if(!permalink.length){ … … 42 42 var punc=url.indexOf("?")===-1?"?":"&"; 43 43 var source=jQuery("div#mf2tk-shortcode-tester div#mf2tk-shortcode-tester-area-source textarea").val(); 44 if(this.id==="mf2tk-shortcode-tester-show-rendered" ){44 if(this.id==="mf2tk-shortcode-tester-show-rendered"||this.id==="mf2tk-shortcode-tester-alt-show-rendered"){ 45 45 var width=640; 46 46 var height=480; … … 49 49 var features="left="+left+",top="+top+",width="+width+",height="+height+",location=0,resizable,scrollbars,menubar=0"; 50 50 url+=punc+"mc-sct=tpcti_html_eval_post_content&post_content="+encodeURI(source); 51 if(this.id==="mf2tk-shortcode-tester-alt-show-rendered"){ 52 url+="&theme_scripts=nullify"; 53 } 51 54 window.open(url,"mc-sct-rendered",features); 52 55 return; -
shortcode-tester/trunk/readme.txt
r2197070 r2221536 5 5 Requires at least: 3.6 6 6 Tested up to: 5.3 7 Stable tag: 1.2. 17 Stable tag: 1.2.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 25 25 In addition to the HTML elements emitted by the PHP code for the shortcode, the shortcode may have JavaScript code to dynamically emit additional HTML elements. The shortcode tester hides non shortcode HTML elements by setting the CSS display property to none and changing the element id. These changes may affect the execution of the shortcode's JavaScript code. 26 26 27 = "Show Rendered" vs "Alt Show Rendered" = 28 29 "Show Rendered" allows all JavaScript code to execute. Unfortunately, the shortcode tester hides non shortcode HTML elements and this may cause some JavaScript code to abort which prevents the execution of the shortcode's JavaScript code. "Alt Show Rendered" suppresses the execution of the theme's JavaScript code and this may allow the shortcode's JavaScript code to execute. 30 31 = Does "Show Rendered" require that the shortcode have support for Gutenberg blocks? = 32 33 No. "Show Rendered" does not use Gutenberg blocks. It uses the WordPress server to render the shortcode as it would when the page is requested from the browser and tries to skip rendering everything but the shortcode. In particular, it will work with old plugins that do not have support for Gutenberg blocks. 34 27 35 == Screenshots == 28 36 1. The Shortcode Tester 29 37 30 38 == Changelog == 39 40 = 1.2.2 = 41 * added "Alt Show Rendered" button which prevent the theme's scripts from running 31 42 32 43 = 1.2.1 = … … 59 70 == Upgrade Notice == 60 71 72 = 1.2.2 = 73 * added "Alt Show Rendered" button which prevent the theme's scripts from running 74 61 75 = 1.2.1 = 62 76 * fix problem with non permalink URL's -
shortcode-tester/trunk/shortcode-tester-loader.php
r2197070 r2221536 5 5 Plugin URI: https://github.com/magenta-cuda/shortcode-tester 6 6 Description: a simple shortcode tester 7 Version: 1.2. 17 Version: 1.2.2 8 8 Author: Magenta Cuda 9 9 Author URI: https://github.com/magenta-cuda -
shortcode-tester/trunk/shortcode-tester.php
r2197070 r2221536 137 137 <button id="mf2tk-shortcode-tester-show-both" class="mf2tk-shortcode-tester-button">Show Both</button> 138 138 <button id="mf2tk-shortcode-tester-show-rendered" class="mf2tk-shortcode-tester-button">Show Rendered</button> 139 <button id="mf2tk-shortcode-tester-alt-show-rendered" class="mf2tk-shortcode-tester-button" title="Please try this if 'Show Rendered' does not work."> 140 Alt Show Rendered 141 </button> 139 142 </div> 140 143 <div class="sct_ix-shortcode_tester_input_output"> … … 265 268 $offset = $gt_offset; 266 269 } 267 if ( $marked === FALSE && ! in_array( $name, [ 'script' ] ) ) { 268 # Add element to list of elements to hide. 269 # error_log( 'hide_html_elements():Element to hide = "' . substr( $buffer, $left_offset, ( $gt_offset + 1 ) - $left_offset ) . '"' ); 270 $elements[ ] = (object) [ 'name' => $name, 'left' => $left_offset, 'right' => $gt_offset ]; 270 if ( $marked === FALSE ) { 271 $op = FALSE; 272 if ( $name === 'script' ) { 273 # error_log( 'hide_html_elements():<script> = "' . substr( $buffer, $left_offset, ( $gt_offset + 1 ) - $left_offset ) . '"' ); 274 if ( array_key_exists( 'theme_scripts', $_REQUEST ) && $_REQUEST['theme_scripts'] === 'nullify' ) { 275 $tag = substr( $buffer, $left_offset, ( $gt_offset + 1 ) - $left_offset ); 276 if ( preg_match( '#src=("|\')([^\1]+?)\1#', $tag, $matches ) === 1 ) { 277 # error_log( 'hide_html_elements():src = "' . $matches[2] ); 278 if ( strpos( $matches[2], '/wp-content/themes/' ) !== FALSE ) { 279 # error_log( 'hide_html_elements():theme <script> = "' . substr( $buffer, $left_offset, ( $gt_offset + 1 ) - $left_offset ) . '"' ); 280 $op = 'nullify-script'; 281 } 282 } 283 } 284 } else { 285 $op = 'hide'; 286 } 287 if ( $op !== FALSE ) { 288 # Add element to list of elements to hide or nullify. 289 # error_log( 'hide_html_elements():Element to hide = "' . substr( $buffer, $left_offset, ( $gt_offset + 1 ) - $left_offset ) . '"' ); 290 $elements[ ] = (object) [ 'op' => $op, 'name' => $name, 'left' => $left_offset, 'right' => $gt_offset ]; 291 } 271 292 } 272 293 $start = $offset + 1; … … 281 302 # error_log( 'hide_html_elements():$name=' . $element->name ); 282 303 # error_log( 'hide_html_elements():tag=' . substr( $buffer, $element->left, $element->right - ( $element->left - 1 ) ) ); 283 if ( ( $style_offset = strpos( substr( $buffer, $element->left, $element->right - ( $element->left - 1 ) ), 'style=' ) ) === FALSE ) { 284 $buffer = substr_replace( $buffer, ' style="display:none;"', $element->right, 0 ); 285 } else { 286 # Element already has an inline style attribute. 287 // TODO: 288 $buffer = substr_replace( $buffer, ' style="display:none;"', $element->right, 0 ); 289 } 290 # JavaScript can make visible elements that we have hidden. Changing an element's id may defeat this. 291 if ( ( $id_offset = strpos( substr( $buffer, $element->left, $element->right - ( $element->left - 1 ) ), 'id=' ) ) !== FALSE ) { 292 $buffer = substr_replace( $buffer, 'xxx-', $element->left + $id_offset + 4, 0 ); 304 if ( $element->op === 'hide' ) { 305 if ( ( $style_offset = strpos( substr( $buffer, $element->left, $element->right - ( $element->left - 1 ) ), 'style=' ) ) === FALSE ) { 306 $buffer = substr_replace( $buffer, ' style="display:none;"', $element->right, 0 ); 307 } else { 308 # Element already has an inline style attribute. 309 // TODO: 310 $buffer = substr_replace( $buffer, ' style="display:none;"', $element->right, 0 ); 311 } 312 # JavaScript can make visible elements that we have hidden. Changing an element's id may defeat this. 313 if ( ( $id_offset = strpos( substr( $buffer, $element->left, $element->right - ( $element->left - 1 ) ), 'id=' ) ) !== FALSE ) { 314 $buffer = substr_replace( $buffer, 'xxx-', $element->left + $id_offset + 4, 0 ); 315 } 316 } else if ( $element->op === 'nullify-script' ) { 317 # Prevent script from loading. 318 $buffer = substr_replace( $buffer, '<script>/* Nullified by shortcode-tester. */', $element->left, ( $element->right + 1 ) - $element->left ); 293 319 } 294 320 }
Note: See TracChangeset
for help on using the changeset viewer.