Making WordPress.org


Ignore:
Timestamp:
12/19/2017 04:22:37 PM (7 years ago)
Author:
obenland
Message:

PLugins: Clean up formatting with phpcbf

File:
1 edited

Legend:

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

    r6285 r6287  
    11<?php
    22namespace WordPressdotorg\Plugin_Directory\Readme;
     3
    34use WordPressdotorg\Plugin_Directory\Markdown;
    45
     
    159160    protected function parse_readme( $file ) {
    160161        $contents = file_get_contents( $file );
    161         if ( preg_match( '!!u', $contents ) )
     162        if ( preg_match( '!!u', $contents ) ) {
    162163            $contents = preg_split( '!\R!u', $contents );
    163         else
     164        } else {
    164165            $contents = preg_split( '!\R!', $contents ); // regex failed due to invalid UTF8 in $contents, see #2298
     166        }
    165167        $contents = array_map( array( $this, 'strip_newlines' ), $contents );
    166168
     
    212214            }
    213215
    214             $bits = explode( ':', trim( $line ), 2 );
     216            $bits                = explode( ':', trim( $line ), 2 );
    215217            list( $key, $value ) = $bits;
    216             $key = strtolower( trim( $key, " \t*-\r\n" ) );
     218            $key                 = strtolower( trim( $key, " \t*-\r\n" ) );
    217219            if ( isset( $this->valid_headers[ $key ] ) ) {
    218220                $headers[ $this->valid_headers[ $key ] ] = trim( $value );
     
    252254            if ( empty( $headers['license_uri'] ) && preg_match( '!(https?://\S+)!i', $headers['license'], $url ) ) {
    253255                $headers['license_uri'] = $url[1];
    254                 $headers['license'] = trim( str_replace( $url[1], '', $headers['license'] ), " -*\t\n\r\n" );
     256                $headers['license']     = trim( str_replace( $url[1], '', $headers['license'] ), " -*\t\n\r\n" );
    255257            }
    256258            $this->license = $headers['license'];
     
    268270            }
    269271            if ( ( '=' === $trimmed[0] && isset( $trimmed[1] ) && '=' === $trimmed[1] ) ||
    270                 ( '#' === $trimmed[0] && isset( $trimmed[1] ) && '#' === $trimmed[1] )
     272                ( '#' === $trimmed[0] && isset( $trimmed[1] ) && '#' === $trimmed[1] )
    271273            ) {
    272274
     
    295297            // Stop only after a ## Markdown header, not a ###.
    296298            if ( ( '=' === $trimmed[0] && isset( $trimmed[1] ) && '=' === $trimmed[1] ) ||
    297                 ( '#' === $trimmed[0] && isset( $trimmed[1] ) && '#' === $trimmed[1] && isset( $trimmed[2] ) && '#' !== $trimmed[2] )
     299                ( '#' === $trimmed[0] && isset( $trimmed[1] ) && '#' === $trimmed[1] && isset( $trimmed[2] ) && '#' !== $trimmed[2] )
    298300            ) {
    299301
     
    312314                // If we encounter an unknown section header, include the provided Title, we'll filter it to other_notes later.
    313315                if ( ! in_array( $section_name, $this->expected_sections ) ) {
    314                     $current .= '<h3>' . $section_title . '</h3>';
     316                    $current     .= '<h3>' . $section_title . '</h3>';
    315317                    $section_name = 'other_notes';
    316318                }
     
    334336
    335337        // Suffix the Other Notes section to the description.
    336         if ( !empty( $this->sections['other_notes'] ) ) {
     338        if ( ! empty( $this->sections['other_notes'] ) ) {
    337339            $this->sections['description'] .= "\n" . $this->sections['other_notes'];
    338340            unset( $this->sections['other_notes'] );
     
    348350        // Display FAQs as a definition list.
    349351        if ( isset( $this->sections['faq'] ) ) {
    350             $this->faq = $this->parse_section( $this->sections['faq'] );
     352            $this->faq             = $this->parse_section( $this->sections['faq'] );
    351353            $this->sections['faq'] = '';
    352354        }
     
    356358            $this->faq = array_merge(
    357359                array(
    358                     __( 'Installation Instructions', 'wporg-plugins' ) => $this->sections['installation']
     360                    __( 'Installation Instructions', 'wporg-plugins' ) => $this->sections['installation'],
    359361                ),
    360362                $this->faq
    361363            );
    362             //unset( $this->sections['installation'] );
     364            // unset( $this->sections['installation'] );
    363365            $this->sections['faq'] = ''; // Ensure it's set as per faq section above.
    364366        }
     
    401403                $this->sections['faq'] .= "\n<dl>\n";
    402404                foreach ( $this->faq as $question => $answer ) {
    403                     $question_slug = sanitize_title_with_dashes( $question );
     405                    $question_slug          = sanitize_title_with_dashes( $question );
    404406                    $this->sections['faq'] .= "<dt id='{$question_slug}'>{$question}</dt>\n<dd>{$answer}</dd>\n";
    405407                }
     
    497499        $text = force_balance_tags( $text );
    498500        // TODO: make_clickable() will act inside shortcodes.
    499         //$text = make_clickable( $text );
    500 
     501        // $text = make_clickable( $text );
    501502        $text = wp_kses( $text, $allowed );
    502503
    503504        // wpautop() will eventually replace all \n's with <br>s, and that isn't what we want (The text may be line-wrapped in the readme, we don't want that, we want paragraph-wrapped text)
    504505        // TODO: This incorrectly also applies within `<code>` tags which we don't want either.
    505         //$text = preg_replace( "/(?<![> ])\n/", ' ', $text );
    506 
     506        // $text = preg_replace( "/(?<![> ])\n/", ' ', $text );
    507507        $text = trim( $text );
    508508
     
    516516     * @return string
    517517     */
    518     protected function sanitize_text( $text ) { // not fancy
     518    protected function sanitize_text( $text ) {
     519        // not fancy
    519520        $text = strip_tags( $text );
    520521        $text = esc_html( $text );
     
    583584     */
    584585    protected function parse_section( $lines ) {
    585         $key = $value = '';
     586        $key    = $value = '';
    586587        $return = array();
    587588
     
    606607        $line_count = count( $lines );
    607608        for ( $i = 0; $i < $line_count; $i++ ) {
    608             $line = &$lines[ $i ];
     609            $line    = &$lines[ $i ];
    609610            $trimmed = &$trimmed_lines[ $i ];
    610611            if ( ! $trimmed ) {
     
    627628                $value = '';
    628629                // Trim off the first character of the line, as we know that's the heading style we're expecting to remove.
    629                 $key   = trim( $line, $trimmed[0] . " \t" );
     630                $key = trim( $line, $trimmed[0] . " \t" );
    630631                continue;
    631632            }
Note: See TracChangeset for help on using the changeset viewer.