Changeset 13235
- Timestamp:
- 02/22/2024 05:46:59 AM (2 years ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme
- Files:
-
- 2 edited
-
class-parser.php (modified) (8 diffs)
-
class-validator.php (modified) (1 diff)
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 ); -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-validator.php
r13133 r13235 181 181 ); 182 182 } elseif( isset( $readme->warnings['trimmed_short_description'] ) ) { 183 $ notes[] = sprintf(183 $warnings[] = sprintf( 184 184 /* translators: %s: section title */ 185 185 __( 'The %s section is too long and was truncated. A maximum of 150 characters is supported.', 'wporg-plugins' ), 186 '<code>Short Description</code>' 186 '<code>Short Description</code>', 187 number_format_i18n( $readme->maximum_field_lengths['short_description'] ) 188 ); 189 } 190 191 $trimmed_sections = array_filter( $readme->warnings, function( $warning ) { 192 return str_contains( $warning, 'trimmed_section_' ); 193 }, ARRAY_FILTER_USE_KEY ); 194 foreach ( $trimmed_sections as $section_name => $dummy ) { 195 $section_name = str_replace( 'trimmed_section_', '', $section_name ); 196 $warnings[] = sprintf( 197 /* translators: %s: section title */ 198 __( 'The %s section is too long and was truncated. A maximum of %s words is supported.', 'wporg-plugins' ), 199 '<code>' . esc_html( ucwords( str_replace( '_', ' ', $section_name ) ) ) . '</code>', 200 number_format_i18n( $readme->maximum_field_lengths[ 'section' ] ) 187 201 ); 188 202 }
Note: See TracChangeset
for help on using the changeset viewer.