Changeset 2501 for sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme-parser/compat.php
- Timestamp:
- 02/15/2016 06:28:02 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme-parser/compat.php
r2499 r2501 1 1 <?php 2 /** 3 * WordPress.org Plugin Readme Parser. 4 * 5 * @package WPorg_Plugin_Directory 6 */ 2 7 3 if ( ! defined('WORDPRESS_README_MARKDOWN') ) {4 define( 'WORDPRESS_README_MARKDOWN', dirname(__FILE__) . '/markdown.php');8 if ( ! defined( 'WORDPRESS_README_MARKDOWN' ) ) { 9 define( 'WORDPRESS_README_MARKDOWN', dirname( __FILE__ ) . '/markdown.php' ); 5 10 } 6 11 7 require_once( dirname(__FILE__) . '/ReadmeParser.php');12 require_once( dirname( __FILE__ ) . '/ReadmeParser.php' ); 8 13 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 */ 17 class 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 ); 13 29 } 14 30 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 ) ) { 17 39 return array(); 18 40 } 19 41 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 ); 33 47 } 34 48 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 ); 38 51 } 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 { 40 57 $result->remaining_content = ''; 41 58 } 42 59 43 $result->name = self::sanitize_text( $result->name);60 $result->name = self::sanitize_text( $result->name ); 44 61 //$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 ); 46 63 47 64 $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; 52 70 } 53 71 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; 57 83 } 58 84 85 /** 86 * @access protected 87 * 88 * @param string $text 89 * @return string 90 */ 59 91 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 63 96 return $text; 64 97 } 65 98 99 /** 100 * @access protected 101 * 102 * @param string $text 103 * @return string 104 */ 66 105 protected static function filter_text( $text ) { 67 $text = trim( $text);106 $text = trim( $text ); 68 107 //$text = self::code_trick($text); // A better parser than Markdown's for: backticks -> CODE 69 108 70 109 $allowed = array( 71 'a' => array(72 'href' => array(),110 'a' => array( 111 'href' => array(), 73 112 '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(), 87 127 ); 88 128 89 $text = balanceTags( $text);129 $text = balanceTags( $text ); 90 130 91 131 $text = wp_kses( $text, $allowed ); 92 $text = trim($text); 132 $text = trim( $text ); 133 93 134 return $text; 94 135 }
Note: See TracChangeset
for help on using the changeset viewer.