Changeset 6287 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-parser.php
- Timestamp:
- 12/19/2017 04:22:37 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-parser.php
r6285 r6287 1 1 <?php 2 2 namespace WordPressdotorg\Plugin_Directory\Readme; 3 3 4 use WordPressdotorg\Plugin_Directory\Markdown; 4 5 … … 159 160 protected function parse_readme( $file ) { 160 161 $contents = file_get_contents( $file ); 161 if ( preg_match( '!!u', $contents ) ) 162 if ( preg_match( '!!u', $contents ) ) { 162 163 $contents = preg_split( '!\R!u', $contents ); 163 else164 } else { 164 165 $contents = preg_split( '!\R!', $contents ); // regex failed due to invalid UTF8 in $contents, see #2298 166 } 165 167 $contents = array_map( array( $this, 'strip_newlines' ), $contents ); 166 168 … … 212 214 } 213 215 214 $bits = explode( ':', trim( $line ), 2 );216 $bits = explode( ':', trim( $line ), 2 ); 215 217 list( $key, $value ) = $bits; 216 $key = strtolower( trim( $key, " \t*-\r\n" ) );218 $key = strtolower( trim( $key, " \t*-\r\n" ) ); 217 219 if ( isset( $this->valid_headers[ $key ] ) ) { 218 220 $headers[ $this->valid_headers[ $key ] ] = trim( $value ); … … 252 254 if ( empty( $headers['license_uri'] ) && preg_match( '!(https?://\S+)!i', $headers['license'], $url ) ) { 253 255 $headers['license_uri'] = $url[1]; 254 $headers['license'] = trim( str_replace( $url[1], '', $headers['license'] ), " -*\t\n\r\n" );256 $headers['license'] = trim( str_replace( $url[1], '', $headers['license'] ), " -*\t\n\r\n" ); 255 257 } 256 258 $this->license = $headers['license']; … … 268 270 } 269 271 if ( ( '=' === $trimmed[0] && isset( $trimmed[1] ) && '=' === $trimmed[1] ) || 270 272 ( '#' === $trimmed[0] && isset( $trimmed[1] ) && '#' === $trimmed[1] ) 271 273 ) { 272 274 … … 295 297 // Stop only after a ## Markdown header, not a ###. 296 298 if ( ( '=' === $trimmed[0] && isset( $trimmed[1] ) && '=' === $trimmed[1] ) || 297 299 ( '#' === $trimmed[0] && isset( $trimmed[1] ) && '#' === $trimmed[1] && isset( $trimmed[2] ) && '#' !== $trimmed[2] ) 298 300 ) { 299 301 … … 312 314 // If we encounter an unknown section header, include the provided Title, we'll filter it to other_notes later. 313 315 if ( ! in_array( $section_name, $this->expected_sections ) ) { 314 $current .= '<h3>' . $section_title . '</h3>';316 $current .= '<h3>' . $section_title . '</h3>'; 315 317 $section_name = 'other_notes'; 316 318 } … … 334 336 335 337 // Suffix the Other Notes section to the description. 336 if ( ! empty( $this->sections['other_notes'] ) ) {338 if ( ! empty( $this->sections['other_notes'] ) ) { 337 339 $this->sections['description'] .= "\n" . $this->sections['other_notes']; 338 340 unset( $this->sections['other_notes'] ); … … 348 350 // Display FAQs as a definition list. 349 351 if ( isset( $this->sections['faq'] ) ) { 350 $this->faq = $this->parse_section( $this->sections['faq'] );352 $this->faq = $this->parse_section( $this->sections['faq'] ); 351 353 $this->sections['faq'] = ''; 352 354 } … … 356 358 $this->faq = array_merge( 357 359 array( 358 __( 'Installation Instructions', 'wporg-plugins' ) => $this->sections['installation'] 360 __( 'Installation Instructions', 'wporg-plugins' ) => $this->sections['installation'], 359 361 ), 360 362 $this->faq 361 363 ); 362 // unset( $this->sections['installation'] );364 // unset( $this->sections['installation'] ); 363 365 $this->sections['faq'] = ''; // Ensure it's set as per faq section above. 364 366 } … … 401 403 $this->sections['faq'] .= "\n<dl>\n"; 402 404 foreach ( $this->faq as $question => $answer ) { 403 $question_slug = sanitize_title_with_dashes( $question );405 $question_slug = sanitize_title_with_dashes( $question ); 404 406 $this->sections['faq'] .= "<dt id='{$question_slug}'>{$question}</dt>\n<dd>{$answer}</dd>\n"; 405 407 } … … 497 499 $text = force_balance_tags( $text ); 498 500 // TODO: make_clickable() will act inside shortcodes. 499 //$text = make_clickable( $text ); 500 501 // $text = make_clickable( $text ); 501 502 $text = wp_kses( $text, $allowed ); 502 503 503 504 // wpautop() will eventually replace all \n's with <br>s, and that isn't what we want (The text may be line-wrapped in the readme, we don't want that, we want paragraph-wrapped text) 504 505 // TODO: This incorrectly also applies within `<code>` tags which we don't want either. 505 //$text = preg_replace( "/(?<![> ])\n/", ' ', $text ); 506 506 // $text = preg_replace( "/(?<![> ])\n/", ' ', $text ); 507 507 $text = trim( $text ); 508 508 … … 516 516 * @return string 517 517 */ 518 protected function sanitize_text( $text ) { // not fancy 518 protected function sanitize_text( $text ) { 519 // not fancy 519 520 $text = strip_tags( $text ); 520 521 $text = esc_html( $text ); … … 583 584 */ 584 585 protected function parse_section( $lines ) { 585 $key = $value = '';586 $key = $value = ''; 586 587 $return = array(); 587 588 … … 606 607 $line_count = count( $lines ); 607 608 for ( $i = 0; $i < $line_count; $i++ ) { 608 $line = &$lines[ $i ];609 $line = &$lines[ $i ]; 609 610 $trimmed = &$trimmed_lines[ $i ]; 610 611 if ( ! $trimmed ) { … … 627 628 $value = ''; 628 629 // Trim off the first character of the line, as we know that's the heading style we're expecting to remove. 629 $key 630 $key = trim( $line, $trimmed[0] . " \t" ); 630 631 continue; 631 632 }
Note: See TracChangeset
for help on using the changeset viewer.