Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Puc/v4p11/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
Expand Down
2 changes: 1 addition & 1 deletion Puc/v4p11/Vcs/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getRemoteReadme($ref = 'master') {
return array();
}

$parser = new PucReadmeParser();
$parser = new PucReadmeParser_v4p11();
return $parser->parse_readme_contents($fileContents);
}

Expand Down
50 changes: 45 additions & 5 deletions vendor/PucReadmeParser.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

if ( !class_exists('PucReadmeParser', false) ):
if ( !class_exists('PucReadmeParser_v4p11', false) ):

/**
* This is a slightly modified version of github.com/markjaquith/WordPress-Plugin-Readme-Parser
* It uses Parsedown instead of the "Markdown Extra" parser.
*/

class PucReadmeParser {
class PucReadmeParser_v4p11 {

function __construct() {
// This space intentionally blank
Expand Down Expand Up @@ -157,8 +157,48 @@ function parse_readme_contents( $file_contents ) {
if ( isset($final_sections['screenshots']) ) {
preg_match_all('|<li>(.*?)</li>|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 = '<li>';
$ss_html .= '<img src="'.$ss_url.'" alt="'.$ss_text.'" />';
$ss_html .= '<p>'.$ss_text.'</p>';
$ss_html .= '</li>';
$final_screenshots[] = $ss_html;
} else {
$final_screenshots[] = '<li>' . $ss_text . '</li>';
}
$ss_count++;
}
$final_sections['screenshots'] = '<ol>'.implode('',$final_screenshots).'</ol>';
}
}

Expand Down Expand Up @@ -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;
Expand Down