Changeset 13513
- Timestamp:
- 04/12/2024 06:18:06 AM (10 months ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-validator.php
r13465 r13513 11 11 */ 12 12 class Validator { 13 14 /** 15 * Last content validated. 16 * 17 * @var string 18 */ 19 public $last_content = ''; 13 20 14 21 /** … … 86 93 public function validate( $readme ) { 87 94 $errors = $warnings = $notes = array(); 95 96 // Store the last validated content for later use. 97 $this->last_content = $readme; 88 98 89 99 // Security note: Keep the data: protocol here, Parser accepts a string HOWEVER -
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/shortcodes/class-readme-validator.php
r13275 r13513 2 2 namespace WordPressdotorg\Plugin_Directory\Shortcodes; 3 3 4 use WordPressdotorg\Plugin_Directory\Plugin_Directory; 4 5 use WordPressdotorg\Plugin_Directory\Readme\Validator; 5 6 … … 10 11 */ 11 12 public static function display() { 13 $readme_url = ''; 14 $readme_contents = ''; 15 if ( ! empty( $_REQUEST['readme'] ) && is_string( $_REQUEST['readme'] ) ) { 16 $readme_url = wp_unslash( $_REQUEST['readme'] ); 17 } 18 19 if ( ! empty( $_POST['readme_contents'] ) && is_string( $_POST['readme_contents'] ) ) { 20 $readme_contents = base64_decode( wp_unslash( $_POST['readme_contents'] ), true ); 21 } 22 23 // If the user has specified a plugin URL, validate the stable tags readme (Well, try to, we don't know it's exact filename). 24 if ( $readme_url && preg_match( '!^https?://([^./]+\.)?wordpress.org/plugins/(?P<slug>[^/]+)!i', $readme_url, $m ) ) { 25 $plugin = Plugin_Directory::get_plugin_post( $m['slug'] ); 26 27 if ( $plugin ) { 28 $readme_url = 'https://plugins.svn.wordpress.org/' . $plugin->post_name . '/' . ( ( $plugin->stable_tag && 'trunk' != $plugin->stable_tag ) ? 'tags/' . $plugin->stable_tag : 'trunk' ) . '/readme.txt'; 29 $_REQUEST['readme'] = $readme_url; 30 } 31 } 32 12 33 ob_start(); 13 34 ?> 14 35 <div class="wrap"> 15 36 <?php 16 if ( $_REQUEST ) { 17 self::validate_readme(); 18 } 37 if ( $readme_contents || $readme_url ) { 38 self::validate_readme( $readme_contents ?: $readme_url ); 19 39 20 $readme_url = ''; 21 $readme_contents = ''; 22 if ( ! empty( $_REQUEST['readme'] ) && is_string( $_REQUEST['readme'] ) ) { 23 $readme_url = wp_unslash( $_REQUEST['readme'] ); 24 } 25 if ( ! empty( $_POST['readme_contents'] ) && is_string( $_POST['readme_contents'] ) ) { 26 $readme_contents = base64_decode( wp_unslash( $_POST['readme_contents'] ), true ); 40 $readme_contents = Validator::instance()->last_content ?: $readme_contents; 27 41 } 28 42 ?> … … 62 76 /** 63 77 * Validates readme.txt contents and adds feedback. 78 * 79 * @param string $readme_url_or_contents URL or contents of the readme.txt file. 80 * @return void 64 81 */ 65 protected static function validate_readme() { 66 if ( ! empty( $_REQUEST['readme'] ) && is_string( $_REQUEST['readme'] ) ) { 67 $errors = Validator::instance()->validate_url( wp_unslash( $_REQUEST['readme'] ) ); 82 protected static function validate_readme( $readme_url_or_contents = '' ) { 68 83 69 } elseif ( ! empty( $_POST['readme_contents'] ) && is_string( $_POST['readme_contents'] ) ) { 70 $contents = base64_decode( wp_unslash( $_REQUEST['readme_contents'] ), true ); 71 if ( ! $contents ) { 72 return; 73 } 84 if ( str_starts_with( $readme_url_or_contents, 'http://' ) || str_starts_with( $readme_url_or_contents, 'https://' ) ) { 85 $errors = Validator::instance()->validate_url( $readme_url_or_contents ); 74 86 75 $errors = Validator::instance()->validate_content( $contents ); 87 } elseif ( $readme_url_or_contents ) { 88 $errors = Validator::instance()->validate_content( $readme_url_or_contents ); 76 89 77 90 } else {
Note: See TracChangeset
for help on using the changeset viewer.