Created
December 9, 2016 19:08
-
-
Save campg2j003/18975f7e77119fa99c9d50c79062905b to your computer and use it in GitHub Desktop.
Patch to WordPress plugin Plugin README Parser v1.3.5-- read local
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 16b1372 (HEAD -> master)Author: Gary Campbell <campg2003@gmail.com>Date: Wed Dec 7 15:16:15 2016 -0700 Now tries to use local README. Added code in arp_get_readme to check for a README in a local plugin installation. Added debugging code in readme_parser in generate-output.php to debug the problem. Added debug option, but it doesn't work. Also added dbg key in arp_get_readme, but the messages are small.diff --git a/includes/functions.php b/includes/functions.phpindex 2c1a35f..c333ff2 100644--- a/includes/functions.php+++ b/includes/functions.php@@ -21,10 +21,34 @@ function arp_get_readme( $plugin_url, $version = '' ) { + global $functions_dir; // Work out filename and fetch the contents+ $array['dbg'] = ''; // debug+ $array['dbg'] .= "plugin_url = $plugin_url\n"; // debug if ( strpos( $plugin_url, '://' ) === false ) { $array[ 'name' ] = str_replace( ' ', '-', strtolower( $plugin_url ) );+ // See if the plugin is installed locally. If so, get the local README.+ $our_plugins_dir = dirname(dirname($functions_dir)); // plugins directory+ // *** will this work on Windows???+ $local_readme = $our_plugins_dir."/".$array['name']."/readme.txt";+ $array['dbg'] .= "Checking for local file $local_readme\n"; // debug+ if (file_exists($local_readme)) {+ $array['dbg'] .= "reading local file $local_readme\n";+ $fp = fopen($local_readme, 'r');+ if ($fp === false) {+ $array['dbg'] .= "Unable to open local file\n"; // debug+ } else {+ $array['file'] = fread($fp, filesize($local_readme));+ fclose($fp);+ } // else local file opened+ if (isset($array['file']) && $array['file']) {+ return $array;+ } else {+ // may want to fall through+ return FALSE;+ }+ } // local file $plugin_url = 'http://plugins.svn.wordpress.org/' . $array[ 'name' ] . '/'; if ( is_numeric( $version ) ) { $plugin_url .= 'tags/' . $version;diff --git a/includes/generate-output.php b/includes/generate-output.phpindex 206b499..bc3aee8 100644--- a/includes/generate-output.php+++ b/includes/generate-output.php@@ -31,7 +31,16 @@ function readme_parser( $paras = '', $content = '' ) { // Extract parameters - extract( shortcode_atts( array( 'assets' => '', 'exclude' => '', 'ext' => '', 'hide' => '', 'include' => '', 'scr_url' => '', 'scr_ext' => '' , 'target' => '_blank', 'nofollow' => '', 'ignore' => '', 'cache' => '', 'version' => '', 'mirror' => '', 'links' => 'bottom', 'name' => '' ), $paras ) );+ extract( shortcode_atts( array( 'assets' => '', 'exclude' => '', 'ext' => '', 'hide' => '', 'include' => '', 'scr_url' => '', 'scr_ext' => '' , 'target' => '_blank', 'nofollow' => '', 'ignore' => '', 'cache' => '', 'version' => '', 'mirror' => '', 'links' => 'bottom', 'name' => '', 'debug' => false ), $paras ) );++ if ($debug == 'false') {+ $debug = false;+ }+ if ($debug == 'true') {+ $debug = true;+ }+ // Accumulate debug messages.+ $dbg = ''; // debug // Get cached output @@ -77,6 +86,14 @@ function readme_parser( $paras = '', $content = '' ) { // Work out filename and fetch the contents $file_data = arp_get_readme( $plugin_url, $version );+ if ($file_data['file'] === false) {+ $dbg .= "arp_get_readme returned false\n"; // debug+ } else {+ if (isset($file_data['dbg'])) {+ $dbg .= "from arp_get_readme: " . $file_data['dbg'] . "\n"; // debug+ }+ $dbg .= "Got " . strlen($file_data['file']) . " bytes of README text\n"; // debug+ } // Ensure the file is valid @@ -102,6 +119,8 @@ function readme_parser( $paras = '', $content = '' ) { // Count the number of lines and read through the array $count = count( $file_array );+ $dbg .= "README has $count lines\n"; // debug+ //$dbg .= "content=[" . print_r($file_array, true) . "]\n"; // debug for ( $i = 0; $i < $count; $i++ ) { $add_to_output = true; @@ -192,9 +211,11 @@ function readme_parser( $paras = '', $content = '' ) { } } + //$dbg .= "section = '$section' prev_section = '$prev_section' links = '$links'\n"; // debug if ( ( strtolower( $section ) == $links ) && ( $section != $prev_section ) ) { + $dbg .= "show_links = $show_links\n"; // debug if ( $show_links ) { $file_array[ $i ] = arp_display_links( $download, $target, $nofollow, $version, $mirror, $plugin_name ) . $file_array[ $i ]; } } @@ -418,7 +439,8 @@ function readme_parser( $paras = '', $content = '' ) { $content = $result; } - return $content;+ //return ($debug?nl2br("[$dbg]"):"[debug= '" . print_r($debug, true) . "', dbg=" . nl2br("[$dbg]") . "]") . $content; // debug+ return $content; } add_shortcode( 'readme', 'readme_parser' );diff --git a/readme.txt b/readme.txtindex f5a9afa..9f3e7f3 100644--- a/readme.txt+++ b/readme.txt@@ -1,9 +1,9 @@ === Plugin README Parser ===-Contributors: dartiss+Contributors: dartiss, campg2003 Donate link: http://artiss.co.uk/donate Tags: embed, markdown, parser, plugin, readme, view Requires at least: 2.0-Tested up to: 4.5.1+Tested up to: 4.6.1 Stable tag: 1.3.5 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html@@ -240,6 +240,9 @@ Each of these `div`'s can therefore be styled using your theme stylesheet. == Changelog == += 1.3.5.1 =+* Enhancement: If the plugin is installed locally, uses the local README. WARNING: Changes in arp_get_readme in functions.php may not work on Windows!!!+ = 1.3.5 = * Bug: Fixed a bug in the internationalisation code * Maintenance: Updated branding, inc. adding donation links@@ -352,4 +355,4 @@ Update to improve handling of screenshot files Update to fix a minor bug or to add download version enhancement = 1.0 =-Initial release\ No newline at end of file+Initial releasediff --git a/wp-readme-parser.php b/wp-readme-parser.phpindex 2eddecc..9dc8177 100644--- a/wp-readme-parser.php+++ b/wp-readme-parser.php@@ -3,7 +3,7 @@ Plugin Name: Plugin README Parser Plugin URI: https://wordpress.org/plugins/wp-readme-parser/ Description: Show WordPress Plugin README in your Posts-Version: 1.3.5+Version: 1.3.5.1 Author: David Artiss Author URI: http://www.artiss.co.uk Text Domain: wp-readme-parser |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment