Making WordPress.org


Ignore:
Timestamp:
11/05/2020 03:37:13 AM (6 years ago)
Author:
dd32
Message:

Plugin Directory: Readme Parser: Allow a File, URL, or now the raw readme contents to be passed to the Readme Parser.

This eases integration and re-use of the parser for other purposes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-parser.php

    r10042 r10429  
    153153     * Parser constructor.
    154154     *
    155      * @param string $file_or_url
    156      */
    157     public function __construct( $file_or_url ) {
    158         if ( $file_or_url ) {
    159             $this->parse_readme( $file_or_url );
     155     * @param string $string A Filepath, URL, or contents of a readme to parse.
     156     */
     157    public function __construct( $string ) {
     158        if ( file_exists( $string ) || preg_match( '!^https?://!i', $string ) ) {
     159            $this->parse_readme( $string );
     160        } elseif ( $string ) {
     161            $this->parse_readme_contents( $string );
    160162        }
    161163    }
     
    174176        $contents = file_get_contents( $file_or_url, false, $context );
    175177
     178        return $this->parse_readme_contents( $contents );
     179    }
     180
     181    /**
     182     * @param string $contents The contents of the readme to parse.
     183     * @return bool
     184     */
     185    protected function parse_readme_contents( $contents ) {
    176186        if ( preg_match( '!!u', $contents ) ) {
    177187            $contents = preg_split( '!\R!u', $contents );
Note: See TracChangeset for help on using the changeset viewer.