Changeset 13235 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-parser.php
- Timestamp:
- 02/22/2024 05:46:59 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-parser.php
r13162 r13235 100 100 * @var array 101 101 */ 102 p rivate$expected_sections = array(102 public $expected_sections = array( 103 103 'description', 104 104 'installation', … … 115 115 * @var array 116 116 */ 117 p rivate$alias_sections = array(117 public $alias_sections = array( 118 118 'frequently_asked_questions' => 'faq', 119 119 'change_log' => 'changelog', … … 126 126 * @var array 127 127 */ 128 p rivate$valid_headers = array(128 public $valid_headers = array( 129 129 'tested' => 'tested', 130 130 'tested up to' => 'tested', … … 149 149 'wordpress', 150 150 ); 151 152 /** 153 * The maximum field lengths for the readme. 154 * 155 * @var array 156 */ 157 public $maximum_field_lengths = array( 158 'short_description' => 150, 159 'section' => 1500, 160 ); 161 162 /** 163 * The raw contents of the readme file. 164 * 165 * @var string 166 */ 167 public $raw_contents = ''; 151 168 152 169 /** … … 197 214 */ 198 215 protected function parse_readme_contents( $contents ) { 216 $this->raw_contents = $contents; 217 199 218 if ( preg_match( '!!u', $contents ) ) { 200 219 $contents = preg_split( '!\R!u', $contents ); … … 411 430 } 412 431 432 foreach ( $this->sections as $section => $content ) { 433 $this->sections[ $section ] = $this->trim_length( $content, 'section', 'words' ); 434 435 if ( $content !== $this->sections[ $section ] ) { 436 $this->warnings["trimmed_section_{$section}"] = true; 437 } 438 } 439 413 440 // Display FAQs as a definition list. 414 441 if ( isset( $this->sections['faq'] ) ) { … … 432 459 $this->short_description = $this->parse_markdown( $this->short_description ); 433 460 $this->short_description = wp_strip_all_tags( $this->short_description ); 434 $short_description = $this->trim_length( $this->short_description, 150);461 $short_description = $this->trim_length( $this->short_description, 'short_description' ); 435 462 if ( $short_description !== $this->short_description ) { 436 463 if ( empty( $this->warnings['no_short_description_present'] ) ) { … … 506 533 * @param string $desc 507 534 * @param int $length 535 * @param string $type The type of the length, 'char' or 'words'. 508 536 * @return string 509 537 */ 510 protected function trim_length( $desc, $length = 150 ) { 538 protected function trim_length( $desc, $length = 150, $type = 'char' ) { 539 if ( is_string( $length ) ) { 540 $length = $this->maximum_field_lengths[ $length ] ?? $length; 541 } 542 543 if ( 'words' === $type ) { 544 return wp_trim_words( $desc, $length, ' …' ); 545 } 546 511 547 // Apply the length restriction without counting html entities. 512 548 $str_length = mb_strlen( html_entity_decode( $desc ) ?: $desc );
Note: See TracChangeset
for help on using the changeset viewer.