diff --git a/Puc/v4p11/Autoloader.php b/Puc/v4p11/Autoloader.php index 1f494c1e..5972c160 100644 --- a/Puc/v4p11/Autoloader.php +++ b/Puc/v4p11/Autoloader.php @@ -21,7 +21,7 @@ public function __construct() { $this->libraryDir = $this->libraryDir . '/'; $this->staticMap = array( - 'PucReadmeParser' => 'vendor/PucReadmeParser.php', + 'PucReadmeParser_v4p11' => 'vendor/PucReadmeParser.php', 'Parsedown' => 'vendor/Parsedown.php', 'Puc_v4_Factory' => 'Puc/v4/Factory.php', ); diff --git a/Puc/v4p11/Vcs/Api.php b/Puc/v4p11/Vcs/Api.php index fc31619b..a46342d0 100644 --- a/Puc/v4p11/Vcs/Api.php +++ b/Puc/v4p11/Vcs/Api.php @@ -65,7 +65,7 @@ public function getRemoteReadme($ref = 'master') { return array(); } - $parser = new PucReadmeParser(); + $parser = new PucReadmeParser_v4p11(); return $parser->parse_readme_contents($fileContents); } diff --git a/vendor/PucReadmeParser.php b/vendor/PucReadmeParser.php index 1f5cec9e..32b0615d 100644 --- a/vendor/PucReadmeParser.php +++ b/vendor/PucReadmeParser.php @@ -1,13 +1,13 @@ (.*?)|s', $final_sections['screenshots'], $screenshots, PREG_SET_ORDER); if ( $screenshots ) { - foreach ( (array) $screenshots as $ss ) - $final_screenshots[] = $ss[1]; + /** + * Parse Screenshots from Readme.txt + * + * Refer to @link https://wordpress.org/plugins/readme.txt + * and @link https://developer.wordpress.org/plugins/wordpress-org/how-your-readme-txt-works/ of the standard + */ + $assetDirectory = realpath(dirname( __FILE__ ) . '/../../' ) . DIRECTORY_SEPARATOR . 'assets'; + $assetBaseUrl = trailingslashit(plugins_url('', $assetDirectory . '/imaginary.file')); + $ss_prefix = 'screenshot-'; + $ss_count = 1; + + foreach ( (array) $screenshots as $ss ) { + $ss_text = $ss[1]; + $ss_url = null; + + $filename_path = trailingslashit($assetDirectory) . $ss_prefix . $ss_count; + $filename_url = $assetBaseUrl . $ss_prefix . $ss_count; + /** + * @link https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/ + */ + if ( is_file( $filename_path . '.png') ) { + $ss_url = $filename_url . '.png'; + } elseif ( is_file( $filename_path . '.jpg') ) { + $ss_url = $filename_url . '.jpg'; + } elseif ( is_file( $filename_path . '.jpeg') ) { + $ss_url = $filename_url . '.jpeg'; + } elseif ( is_file( $filename_path . '.gif') ) { + $ss_url = $filename_url . '.gif'; + } + + if ( ! empty($ss_url) ) { + $ss_html = '
  • '; + $ss_html .= ''.$ss_text.''; + $ss_html .= '

    '.$ss_text.'

    '; + $ss_html .= '
  • '; + $final_screenshots[] = $ss_html; + } else { + $final_screenshots[] = '
  • ' . $ss_text . '
  • '; + } + $ss_count++; + } + $final_sections['screenshots'] = '
      '.implode('',$final_screenshots).'
    '; } } @@ -281,7 +321,7 @@ function filter_text( $text, $markdown = false ) { // fancy, Markdown ); $text = balanceTags($text); - + $text = wp_kses( $text, $allowed ); $text = trim($text); return $text;