Making WordPress.org


Ignore:
Timestamp:
02/15/2016 06:28:02 AM (10 years ago)
Author:
obenland
Message:

W.org Plugins: Code reformatting.

  • Splitting out classes in their own files.
  • Let the automated code formatter run over the plugin.

It should break too many things.

See #1584.

File:
1 edited

Legend:

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

    r2499 r2501  
    11<?php
     2/**
     3 * WordPress.org Plugin Readme Parser.
     4 *
     5 * @package WPorg_Plugin_Directory
     6 */
    27
    3 if ( !defined('WORDPRESS_README_MARKDOWN') ) {
    4     define('WORDPRESS_README_MARKDOWN', dirname(__FILE__) . '/markdown.php');
     8if ( ! defined( 'WORDPRESS_README_MARKDOWN' ) ) {
     9    define( 'WORDPRESS_README_MARKDOWN', dirname( __FILE__ ) . '/markdown.php' );
    510}
    611
    7 require_once(dirname(__FILE__) . '/ReadmeParser.php');
     12require_once( dirname( __FILE__ ) . '/ReadmeParser.php' );
    813
    9 class _WordPress_org_Readme extends Baikonur_ReadmeParser {
    10     public static function parse_readme($file) {
    11         $contents = file($file);
    12         return self::parse_readme_contents($contents);
     14/**
     15 * Class WPorg_Readme
     16 */
     17class WPorg_Readme extends Baikonur_ReadmeParser {
     18
     19    /**
     20     * @access public
     21     *
     22     * @param string $file File name.
     23     * @return array
     24     */
     25    public static function parse_readme( $file ) {
     26        $contents = file( $file );
     27
     28        return self::parse_readme_contents( $contents );
    1329    }
    1430
    15     public static function parse_readme_contents($contents) {
    16         if (empty($contents)) {
     31    /**
     32     * @access public
     33     *
     34     * @param array $contents
     35     * @return array
     36     */
     37    public static function parse_readme_contents( $contents ) {
     38        if ( empty( $contents ) ) {
    1739            return array();
    1840        }
    1941
    20         $result = parent::parse_readme_contents($contents);
    21         foreach ($result->sections as &$section) {
    22             $section = self::filter_text($section);
    23         }
    24         if (!empty($result->upgrade_notice)) {
    25             foreach ($result->upgrade_notice as &$notice) {
    26                 $notice = self::sanitize_text($notice);
    27             }
    28         }
    29         if (!empty($result->screenshots)) {
    30             foreach ($result->screenshots as &$shot) {
    31                 $shot = self::filter_text($shot);
    32             }
     42        $result = parent::parse_readme_contents( $contents );
     43        $result->sections = array_map( array( 'WPorg_Readme', 'filter_text' ), $result->sections );
     44
     45        if ( ! empty( $result->upgrade_notice ) ) {
     46            $result->upgrade_notice = array_map( array( 'WPorg_Readme', 'sanitize_text' ), $result->upgrade_notice );
    3347        }
    3448
    35         if (!empty($result->remaining_content)) {
    36             $result->remaining_content = implode("\n", $result->remaining_content);
    37             $result->remaining_content = self::filter_text(str_replace("</h3>\n\n", "</h3>\n", $result->remaining_content));
     49        if ( ! empty( $result->screenshots ) ) {
     50            $result->screenshots = array_map( array( 'WPorg_Readme', 'filter_text' ), $result->screenshots );
    3851        }
    39         else {
     52
     53        if ( ! empty( $result->remaining_content ) ) {
     54            $result->remaining_content = implode( "\n", $result->remaining_content );
     55            $result->remaining_content = self::filter_text( str_replace( "</h3>\n\n", "</h3>\n", $result->remaining_content ) );
     56        } else {
    4057            $result->remaining_content = '';
    4158        }
    4259
    43         $result->name = self::sanitize_text($result->name);
     60        $result->name = self::sanitize_text( $result->name );
    4461        //$result->short_description = self::sanitize_text($result->short_description);
    45         $result->donate_link = esc_url($result->donate_link);
     62        $result->donate_link = esc_url( $result->donate_link );
    4663
    4764        $result->requires_at_least = $result->requires;
    48         $result->tested_up_to = $result->tested;
    49         unset($result->requires, $result->tested);
    50         $result = ((array) $result);
    51         return $result;
     65        $result->tested_up_to      = $result->tested;
     66
     67        unset( $result->requires, $result->tested );
     68
     69        return (array) $result;
    5270    }
    5371
    54     protected static function trim_short_desc(&$desc) {
    55         $desc = self::sanitize_text($desc);
    56         return parent::trim_short_desc($desc);
     72    /**
     73     * @access protected
     74     *
     75     * @param string $desc
     76     * @return string
     77     */
     78    protected static function trim_short_desc( &$desc ) {
     79        $desc = self::sanitize_text( $desc );
     80        parent::trim_short_desc( $desc );
     81
     82        return $desc;
    5783    }
    5884
     85    /**
     86     * @access protected
     87     *
     88     * @param string $text
     89     * @return string
     90     */
    5991    protected static function sanitize_text( $text ) { // not fancy
    60         $text = strip_tags($text);
    61         $text = esc_html($text);
    62         $text = trim($text);
     92        $text = strip_tags( $text );
     93        $text = esc_html( $text );
     94        $text = trim( $text );
     95
    6396        return $text;
    6497    }
    6598
     99    /**
     100     * @access protected
     101     *
     102     * @param string $text
     103     * @return string
     104     */
    66105    protected static function filter_text( $text ) {
    67         $text = trim($text);
     106        $text = trim( $text );
    68107        //$text = self::code_trick($text); // A better parser than Markdown's for: backticks -> CODE
    69108
    70109        $allowed = array(
    71             'a' => array(
    72                 'href' => array(),
     110            'a'          => array(
     111                'href'  => array(),
    73112                'title' => array(),
    74                 'rel' => array()),
    75             'blockquote' => array('cite' => array()),
    76             'br' => array(),
    77             'p' => array(),
    78             'code' => array(),
    79             'pre' => array(),
    80             'em' => array(),
    81             'strong' => array(),
    82             'ul' => array(),
    83             'ol' => array(),
    84             'li' => array(),
    85             'h3' => array(),
    86             'h4' => array()
     113                'rel'   => array()
     114            ),
     115            'blockquote' => array( 'cite' => array() ),
     116            'br'         => array(),
     117            'p'          => array(),
     118            'code'       => array(),
     119            'pre'        => array(),
     120            'em'         => array(),
     121            'strong'     => array(),
     122            'ul'         => array(),
     123            'ol'         => array(),
     124            'li'         => array(),
     125            'h3'         => array(),
     126            'h4'         => array(),
    87127        );
    88128
    89         $text = balanceTags($text);
     129        $text = balanceTags( $text );
    90130
    91131        $text = wp_kses( $text, $allowed );
    92         $text = trim($text);
     132        $text = trim( $text );
     133
    93134        return $text;
    94135    }
Note: See TracChangeset for help on using the changeset viewer.