- Timestamp:
- 12/17/2018 05:06:03 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-block-parser.php
r44264 r44266 64 64 65 65 function __construct( $name, $attrs, $innerBlocks, $innerHTML, $innerContent ) { 66 $this->blockName = $name;67 $this->attrs = $attrs;68 $this->innerBlocks = $innerBlocks;69 $this->innerHTML = $innerHTML;66 $this->blockName = $name; 67 $this->attrs = $attrs; 68 $this->innerBlocks = $innerBlocks; 69 $this->innerHTML = $innerHTML; 70 70 $this->innerContent = $innerContent; 71 71 } … … 270 270 if ( 0 === $stack_depth ) { 271 271 if ( isset( $leading_html_start ) ) { 272 $this->output[] = (array) self::freeform( substr( 273 $this->document, 274 $leading_html_start, 275 $start_offset - $leading_html_start 276 ) ); 272 $this->output[] = (array) self::freeform( 273 substr( 274 $this->document, 275 $leading_html_start, 276 $start_offset - $leading_html_start 277 ) 278 ); 277 279 } 278 280 279 281 $this->output[] = (array) new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() ); 280 $this->offset = $start_offset + $token_length;282 $this->offset = $start_offset + $token_length; 281 283 return true; 282 284 } … … 293 295 case 'block-opener': 294 296 // track all newly-opened blocks on the stack 295 array_push( $this->stack, new WP_Block_Parser_Frame( 296 new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() ), 297 $start_offset, 298 $token_length, 299 $start_offset + $token_length, 300 $leading_html_start 301 ) ); 297 array_push( 298 $this->stack, 299 new WP_Block_Parser_Frame( 300 new WP_Block_Parser_Block( $block_name, $attrs, array(), '', array() ), 301 $start_offset, 302 $token_length, 303 $start_offset + $token_length, 304 $leading_html_start 305 ) 306 ); 302 307 $this->offset = $start_offset + $token_length; 303 308 return true; … … 330 335 * block and add it as a new innerBlock to the parent 331 336 */ 332 $stack_top = array_pop( $this->stack );333 $html = substr( $this->document, $stack_top->prev_offset, $start_offset - $stack_top->prev_offset );334 $stack_top->block->innerHTML .= $html;337 $stack_top = array_pop( $this->stack ); 338 $html = substr( $this->document, $stack_top->prev_offset, $start_offset - $stack_top->prev_offset ); 339 $stack_top->block->innerHTML .= $html; 335 340 $stack_top->block->innerContent[] = $html; 336 $stack_top->prev_offset = $start_offset + $token_length;341 $stack_top->prev_offset = $start_offset + $token_length; 337 342 338 343 $this->add_inner_block( … … 386 391 } 387 392 388 list( $match, $started_at ) = $matches[ 0];393 list( $match, $started_at ) = $matches[0]; 389 394 390 395 $length = strlen( $match ); 391 $is_closer = isset( $matches[ 'closer' ] ) && -1 !== $matches[ 'closer' ][ 1];392 $is_void = isset( $matches[ 'void' ] ) && -1 !== $matches[ 'void' ][ 1];393 $namespace = $matches[ 'namespace'];394 $namespace = ( isset( $namespace ) && -1 !== $namespace[ 1 ] ) ? $namespace[ 0] : 'core/';395 $name = $namespace . $matches[ 'name' ][ 0];396 $has_attrs = isset( $matches[ 'attrs' ] ) && -1 !== $matches[ 'attrs' ][ 1];396 $is_closer = isset( $matches['closer'] ) && -1 !== $matches['closer'][1]; 397 $is_void = isset( $matches['void'] ) && -1 !== $matches['void'][1]; 398 $namespace = $matches['namespace']; 399 $namespace = ( isset( $namespace ) && -1 !== $namespace[1] ) ? $namespace[0] : 'core/'; 400 $name = $namespace . $matches['name'][0]; 401 $has_attrs = isset( $matches['attrs'] ) && -1 !== $matches['attrs'][1]; 397 402 398 403 /* … … 401 406 */ 402 407 $attrs = $has_attrs 403 ? json_decode( $matches[ 'attrs' ][ 0], /* as-associative */ true )408 ? json_decode( $matches['attrs'][0], /* as-associative */ true ) 404 409 : $this->empty_attrs; 405 410 … … 466 471 */ 467 472 function add_inner_block( WP_Block_Parser_Block $block, $token_start, $token_length, $last_offset = null ) { 468 $parent = $this->stack[ count( $this->stack ) - 1 ];473 $parent = $this->stack[ count( $this->stack ) - 1 ]; 469 474 $parent->block->innerBlocks[] = (array) $block; 470 $html = substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset );475 $html = substr( $this->document, $parent->prev_offset, $token_start - $parent->prev_offset ); 471 476 472 477 if ( ! empty( $html ) ) { 473 $parent->block->innerHTML .= $html;478 $parent->block->innerHTML .= $html; 474 479 $parent->block->innerContent[] = $html; 475 480 } 476 481 477 482 $parent->block->innerContent[] = null; 478 $parent->prev_offset = $last_offset ? $last_offset : $token_start + $token_length;483 $parent->prev_offset = $last_offset ? $last_offset : $token_start + $token_length; 479 484 } 480 485 … … 495 500 496 501 if ( ! empty( $html ) ) { 497 $stack_top->block->innerHTML .= $html;502 $stack_top->block->innerHTML .= $html; 498 503 $stack_top->block->innerContent[] = $html; 499 504 } 500 505 501 506 if ( isset( $stack_top->leading_html_start ) ) { 502 $this->output[] = (array) self::freeform( substr( 503 $this->document, 504 $stack_top->leading_html_start, 505 $stack_top->token_start - $stack_top->leading_html_start 506 ) ); 507 $this->output[] = (array) self::freeform( 508 substr( 509 $this->document, 510 $stack_top->leading_html_start, 511 $stack_top->token_start - $stack_top->leading_html_start 512 ) 513 ); 507 514 } 508 515
Note: See TracChangeset
for help on using the changeset viewer.