Ticket #2538: 2538.diff
File 2538.diff, 2.4 KB (added by , 6 years ago) |
---|
-
readme/class-parser.php
161 161 } 162 162 163 163 /** 164 * Parses a readme by URL. 165 * 166 * @param string $url The URL of the readme to validate. 167 * @return bool 168 */ 169 public function parse_from_url( $url ) { 170 $url = esc_url_raw( $url ); 171 172 if ( strtolower( substr( $url, -10 ) ) != 'readme.txt' ) { 173 return false; 174 } 175 176 $readme = wp_safe_remote_get( $url ); 177 if ( ! $readme_text = wp_remote_retrieve_body( $readme ) ) { 178 return false; 179 } 180 181 return $this->parse_readme_contents( $readme_text ); 182 } 183 184 /** 185 * Parse readme contents by file. 186 * 164 187 * @param string $file 165 188 * @return bool 166 189 */ 167 190 protected function parse_readme( $file ) { 168 191 $contents = file_get_contents( $file ); 192 return $this->parse_readme_contents( $contents ); 193 } 194 195 /** 196 * Parse readme contents by string. 197 * 198 * @param string $file 199 * @return bool 200 */ 201 protected function parse_readme_contents( $contents ) { 169 202 if ( preg_match( '!!u', $contents ) ) { 170 203 $contents = preg_split( '!\R!u', $contents ); 171 204 } else { -
shortcodes/class-readme-validator.php
2 2 namespace WordPressdotorg\Plugin_Directory\Shortcodes; 3 3 4 4 use WordPressdotorg\Plugin_Directory\Readme\Validator; 5 use WordPressdotorg\Plugin_Directory\Readme\Parser; 5 6 6 7 class Readme_Validator { 7 8 … … 91 92 } 92 93 93 94 echo $output; 95 96 $parser = new Parser( false ); 97 if ( ! empty( $_POST['readme_url'] ) ) { 98 $parsed = $parser->parse_from_url( wp_unslash( $_POST['readme_url'] ) ); 99 } elseif ( ! empty( $_POST['readme_contents'] ) ) { 100 $parsed = $parser->parse_readme( base64_decode( wp_unslash( $_REQUEST['readme_contents'] ) ) ); 101 } 102 103 if ( $parsed && !empty( $parser-sections ) ) { 104 $output = '<h2>' . __( 'Preview', 'wporg-plugins' ) . '</h2>'; 105 $output .= '<div class="readme-content">'; 106 foreach ( $parser->sections as $title => $section ) { 107 $output .= '<h3 style="text-transform: capitalize;">' . esc_html( $title ) . '</h3>'; 108 $output .= wp_kses_post( $section ); 109 } 110 $output .= '</div>'; 111 echo $output; 112 } 94 113 } 95 114 }