コード例 #1
0
 /**
  * Handles readme parsing.
  *
  * @package s2Member\Readmes
  * @since 3.5
  *
  * @param string $specific_path Optional. Path to a specific readme file to parse. Defaults to that of the software itself.
  * 	When/if a readme-dev.txt file is available, that will be used instead of the default readme.txt.
  * @param string $specific_section Optional. The title of a specific section to parse, instead of the entire file.
  * @param bool $_blank_targets Optional. Defaults to true. If false, no target attribute is used.
  * @param bool $process_wp_syntax Optional. Defaults to false.
  * 	If true, and WP Syntax is installed; it will be used to parse code samples.
  * @return string Parsed readme file, or a parsed readme file section; based on parameter configuration.
  */
 public static function parse_readme($specific_path = FALSE, $specific_section = FALSE, $_blank_targets = TRUE, $process_wp_syntax = FALSE)
 {
     if (!($path = $specific_path)) {
         $path = dirname(dirname(dirname(__FILE__))) . "/readme.txt";
         $dev_path = dirname(dirname(dirname(__FILE__))) . "/readme-dev.txt";
         $path = file_exists($dev_path) ? $dev_path : $path;
     }
     foreach (array_keys(get_defined_vars()) as $__v) {
         $__refs[$__v] =& ${$__v};
     }
     do_action("ws_plugin__s2member_before_parse_readme", get_defined_vars());
     unset($__refs, $__v);
     if (file_exists($path)) {
         $o_pcre = @ini_get("pcre.backtrack_limit");
         @ini_set("pcre.backtrack_limit", 10000000);
         if (!function_exists("NC_Markdown")) {
             include_once dirname(dirname(__FILE__)) . "/externals/markdown/nc-markdown.inc.php";
         }
         $rm = file_get_contents($path);
         // Get readme.txt file contents.
         $mb = function_exists("mb_convert_encoding") ? @mb_convert_encoding($rm, "UTF-8", $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["mb_detection_order"]) : $rm;
         $rm = $mb ? $mb : $rm;
         // Double check this, just in case conversion fails on an unpredicted charset.
         if ($specific_section) {
             preg_match("/(\\=\\= )(" . preg_quote($specific_section, "/") . ")( \\=\\=)(.+?)([\r\n]+\\=\\= |\$)/si", $rm, $m);
             if ($rm = trim($m[4])) {
                 $rm = preg_replace("/(\\=\\=\\=)( )(.+?)( )(\\=\\=\\=)/", "<h4 id=\"rm-specs\">Specifications</h4>", $rm);
                 $rm = preg_replace("/(\\=\\=)( )(Installation)( )(\\=\\=)/", "<h4 id=\"rm-installation\">\$3</h4>", $rm);
                 $rm = preg_replace("/(\\=\\=)( )(Description)( )(\\=\\=)/", "<h4 id=\"rm-description\">\$3</h4>", $rm);
                 $rm = preg_replace("/(\\=\\=)( )(Screenshots)( )(\\=\\=)/", "<h4 id=\"rm-screenshots\">\$3</h4>", $rm);
                 $rm = preg_replace("/(\\=\\=)( )(Frequently Asked Questions)( )(\\=\\=)/", "<h4 id=\"rm-faqs\">\$3</h4>", $rm);
                 $rm = preg_replace("/(\\=\\=)( )(Changelog)( )(\\=\\=)/", "<h4 id=\"rm-changelog\">\$3</h4>", $rm);
                 $rm = preg_replace("/(\\=\\=)( )(.+?)( )(\\=\\=)/", "<h4>\$3</h4>", $rm);
                 $rm = preg_replace("/(\\=)( )(.+?)( )(\\=)/", "<h6>\$3</h6>", $rm);
                 $y1 = "/\\[youtube http\\:\\/\\/www\\.youtube\\.com\\/view_play_list\\?p\\=(.+?)[\\s\\/]*?\\]/i";
                 $y2 = "/\\[youtube http\\:\\/\\/www\\.youtube\\.com\\/watch\\?v\\=(.+?)[\\s\\/]*?\\]/i";
                 $rm = preg_replace($y1, '<embed type="application/x-shockwave-flash" src="//www.youtube.com/p/$1?version=3&hd=1&fs=1&rel=0" style="width:320px; height:210px; float:right; margin:0 0 15px 15px;" allowscriptaccess="always" allowfullscreen="true"></embed>', $rm);
                 $rm = preg_replace($y2, '<embed type="application/x-shockwave-flash" src="//www.youtube.com/v/$1?version=3&hd=1&fs=1&rel=0" style="width:320px; height:210px; float:right; margin:0 0 15px 15px;" allowscriptaccess="always" allowfullscreen="true"></embed>', $rm);
                 $rm = NC_Markdown($rm);
                 // Parse out the Markdown syntax.
                 $r1 = "/(\\<a)( href)/i";
                 // Modify all links. Assume nofollow.
                 if ($_blank_targets) {
                     // Modify all links. Always nofollow. ( with _blank targets ? ).
                     $rm = preg_replace($r1, "\$1" . ' target="_blank" rel="nofollow external"' . "\$2", $rm);
                 } else {
                     // Otherwise, we don't need to set _blank targets. So external is removed also.
                     $rm = preg_replace($r1, "\$1" . ' rel="nofollow"' . "\$2", $rm);
                 }
                 if ($process_wp_syntax) {
                     // If we're processing <pre><code> tags for WP-Syntax.
                     if (function_exists("wp_syntax_before_filter") && function_exists("wp_syntax_before_filter")) {
                         $rm = preg_replace("/\\<pre\\>\\<code\\>/i", '<pre lang="php" escaped="true">', $rm);
                         $rm = preg_replace("/\\<\\/code\\>\\<\\/pre\\>/i", '</pre>', $rm);
                         $rm = wp_syntax_after_filter(wp_syntax_before_filter($rm));
                     }
                 }
             }
             @ini_set("pcre.backtrack_limit", $o_pcre);
             $readme = '<div class="readme">' . "\n";
             $readme .= $rm . "\n";
             // Content.
             $readme .= '</div>' . "\n";
             return apply_filters("ws_plugin__s2member_parse_readme", $readme, get_defined_vars());
         } else {
             $rm = preg_replace("/(\\=\\=\\=)( )(.+?)( )(\\=\\=\\=)/", "<h2 id=\"rm-specs\">Specifications</h2>", $rm);
             $rm = preg_replace("/(\\=\\=)( )(Installation)( )(\\=\\=)/", "<h2 id=\"rm-installation\">\$3</h2>", $rm);
             $rm = preg_replace("/(\\=\\=)( )(Description)( )(\\=\\=)/", "<h2 id=\"rm-description\">\$3</h2>", $rm);
             $rm = preg_replace("/(\\=\\=)( )(Screenshots)( )(\\=\\=)/", "<h2 id=\"rm-screenshots\">\$3</h2>", $rm);
             $rm = preg_replace("/(\\=\\=)( )(Frequently Asked Questions)( )(\\=\\=)/", "<h2 id=\"rm-faqs\">\$3</h2>", $rm);
             $rm = preg_replace("/(\\=\\=)( )(Changelog)( )(\\=\\=)/", "<h2 id=\"rm-changelog\">\$3</h2>", $rm);
             $rm = preg_replace("/(\\=\\=)( )(.+?)( )(\\=\\=)/", "<h2>\$3</h2>", $rm);
             $rm = preg_replace("/(\\=)( )(.+?)( )(\\=)/", "<h3>\$3</h3>", $rm);
             $y1 = "/\\[youtube http\\:\\/\\/www\\.youtube\\.com\\/view_play_list\\?p\\=(.+?)[\\s\\/]*?\\]/i";
             $y2 = "/\\[youtube http\\:\\/\\/www\\.youtube\\.com\\/watch\\?v\\=(.+?)[\\s\\/]*?\\]/i";
             $rm = preg_replace($y1, '<embed type="application/x-shockwave-flash" src="//www.youtube.com/p/$1?version=3&hd=1&fs=1&rel=0" style="width:320px; height:210px; float:right; margin:0 0 15px 15px;" allowscriptaccess="always" allowfullscreen="true"></embed>', $rm);
             $rm = preg_replace($y2, '<embed type="application/x-shockwave-flash" src="//www.youtube.com/v/$1?version=3&hd=1&fs=1&rel=0" style="width:320px; height:210px; float:right; margin:0 0 15px 15px;" allowscriptaccess="always" allowfullscreen="true"></embed>', $rm);
             $rm = NC_Markdown($rm);
             // Parse out the Markdown syntax.
             $r1 = "/(\\<h2(.*?)\\>)(.+?)(\\<\\/h2\\>)(.+?)(\\<h2(.*?)\\>|\$)/si";
             $r2 = "/(\\<\\/div\\>)(\\<h2(.*?)\\>)(.+?)(\\<\\/h2\\>)(.+?)(\\<div class\\=\"section\"\\>\\<h2(.*?)\\>|\$)/si";
             $r3 = "/(\\<div class\\=\"section\"\\>)(\\<h2 id\\=\"rm-specs\"\\>)(Specifications)(\\<\\/h2\\>)(\\<div class\\=\"content\"\\>)(.+?)(\\<\\/div\\>\\<\\/div\\>)/sei";
             $r4 = "/(\\<div class\\=\"section\"\\>)(\\<h2 id\\=\"rm-screenshots\"\\>)(Screenshots)(\\<\\/h2\\>)(\\<div class\\=\"content\"\\>)(.+?)(\\<\\/div\\>\\<\\/div\\>)/sei";
             $r5 = "/(\\<a)( href)/i";
             // Modify all links. Assume a nofollow relationship since destinations are unknown.
             $rm = preg_replace($r1, '<div class="section">' . "\$1\$3\$4" . '<div class="content">' . "\$5" . '</div></div>' . "\$6", $rm);
             $rm = preg_replace($r2, "\$1" . '<div class="section">' . "\$2\$4\$5" . '<div class="content">' . "\$6" . '</div></div>' . "\$7", $rm);
             $rm = stripslashes(preg_replace($r3, "'\$1\$2\$3\$4\$5'.c_ws_plugin__s2member_readmes::_parse_readme_specs('\$6').'\$7'", $rm, 1));
             $rm = preg_replace($r4, "", $rm, 1);
             // Here we just remove the screenshots completely.
             if ($_blank_targets) {
                 // Modify all links. Always nofollow. ( with _blank targets ? ).
                 $rm = preg_replace($r5, "\$1" . ' target="_blank" rel="nofollow external"' . "\$2", $rm);
             } else {
                 // Otherwise, we don't need to set _blank targets. So external is removed also.
                 $rm = preg_replace($r5, "\$1" . ' rel="nofollow"' . "\$2", $rm);
             }
             if ($process_wp_syntax) {
                 // If we're processing <pre><code> tags for WP-Syntax.
                 if (function_exists("wp_syntax_before_filter") && function_exists("wp_syntax_before_filter")) {
                     $rm = preg_replace("/\\<pre\\>\\<code\\>/i", '<pre lang="php" escaped="true">', $rm);
                     $rm = preg_replace("/\\<\\/code\\>\\<\\/pre\\>/i", '</pre>', $rm);
                     $rm = wp_syntax_after_filter(wp_syntax_before_filter($rm));
                 }
             }
             @ini_set("pcre.backtrack_limit", $o_pcre);
             $readme = '<div class="readme">' . "\n";
             $readme .= $rm . "\n";
             // Content.
             $readme .= '</div>' . "\n";
             return apply_filters("ws_plugin__s2member_parse_readme", $readme, get_defined_vars());
         }
     } else {
         return "Unable to parse /readme.txt.";
     }
 }
コード例 #2
0
 public static function parse_readme($specific_path = FALSE, $specific_section = FALSE, $_blank_targets = TRUE, $process_wp_syntax = FALSE)
 {
     if (!($path = $specific_path)) {
         $path = dirname(dirname(dirname(__FILE__))) . "/readme.txt";
         $dev_path = dirname(dirname(dirname(__FILE__))) . "/readme-dev.txt";
         $path = file_exists($dev_path) ? $dev_path : $path;
     }
     /**/
     eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;');
     do_action("ws_plugin__qcache_before_parse_readme", get_defined_vars());
     unset($__refs, $__v);
     /* Unset defined __refs, __v. */
     /**/
     if (file_exists($path)) {
         $o_pcre = @ini_get("pcre.backtrack_limit");
         @ini_set("pcre.backtrack_limit", 10000000);
         /**/
         if (!function_exists("NC_Markdown")) {
             include_once dirname(dirname(__FILE__)) . "/markdown/nc-markdown.inc.php";
         }
         /**/
         $rm = file_get_contents($path);
         /* Get readme.txt file contents. */
         $mb = function_exists("mb_convert_encoding") ? @mb_convert_encoding($rm, "UTF-8", @mb_detect_encoding($rm, "WINDOWS-1252, UTF-8")) : $rm;
         $rm = $mb ? $mb : $rm;
         /* Double check this, just in case conversion fails on an unpredicted charset. */
         /**/
         if ($specific_section) {
             preg_match("/(\\=\\= )(" . preg_quote($specific_section, "/") . ")( \\=\\=)(.+?)([\r\n]+\\=\\= |\$)/si", $rm, $m);
             /**/
             if ($rm = trim($m[4])) {
                 $rm = preg_replace("/(\\=\\=\\=)( )(.+?)( )(\\=\\=\\=)/", "<h4 id=\"rm-specs\">Specifications</h4>", $rm);
                 $rm = preg_replace("/(\\=\\=)( )(Installation)( )(\\=\\=)/", "<h4 id=\"rm-installation\">\$3</h4>", $rm);
                 $rm = preg_replace("/(\\=\\=)( )(Description)( )(\\=\\=)/", "<h4 id=\"rm-description\">\$3</h4>", $rm);
                 $rm = preg_replace("/(\\=\\=)( )(Screenshots)( )(\\=\\=)/", "<h4 id=\"rm-screenshots\">\$3</h4>", $rm);
                 $rm = preg_replace("/(\\=\\=)( )(Frequently Asked Questions)( )(\\=\\=)/", "<h4 id=\"rm-faqs\">\$3</h4>", $rm);
                 $rm = preg_replace("/(\\=\\=)( )(Changelog)( )(\\=\\=)/", "<h4 id=\"rm-changelog\">\$3</h4>", $rm);
                 $rm = preg_replace("/(\\=\\=)( )(.+?)( )(\\=\\=)/", "<h4>\$3</h4>", $rm);
                 $rm = preg_replace("/(\\=)( )(.+?)( )(\\=)/", "<h6>\$3</h6>", $rm);
                 /**/
                 $rm = NC_Markdown($rm);
                 /* Parse out the Markdown syntax. */
                 /**/
                 $r1 = "/(\\<a)( href)/i";
                 /* Modify all links. Assume a nofollow relationship. */
                 /**/
                 if ($_blank_targets) {
                     /* Modify all links. Always nofollow. ( with _blank targets ? ). */
                     $rm = preg_replace($r1, "\$1" . ' target="_blank" rel="nofollow external"' . "\$2", $rm);
                 } else {
                     /* Otherwise, we don't need to set _blank targets. So external is removed also. */
                     $rm = preg_replace($r1, "\$1" . ' rel="nofollow"' . "\$2", $rm);
                 }
                 /**/
                 if ($process_wp_syntax) {
                     /* If we're processing <pre><code> tags for WP-Syntax. */
                     if (function_exists("wp_syntax_before_filter") && function_exists("wp_syntax_before_filter")) {
                         $rm = preg_replace("/\\<pre\\>\\<code\\>/i", '<pre lang="php" escaped="true">', $rm);
                         $rm = preg_replace("/\\<\\/code\\>\\<\\/pre\\>/i", '</pre>', $rm);
                         $rm = wp_syntax_after_filter(wp_syntax_before_filter($rm));
                     }
                 }
             }
             /**/
             @ini_set("pcre.backtrack_limit", $o_pcre);
             /**/
             $readme = '<div class="readme">' . "\n";
             $readme .= $rm . "\n";
             /* Content. */
             $readme .= '</div>' . "\n";
             /**/
             return apply_filters("ws_plugin__qcache_parse_readme", $readme, get_defined_vars());
         } else {
             $rm = preg_replace("/(\\=\\=\\=)( )(.+?)( )(\\=\\=\\=)/", "<h2 id=\"rm-specs\">Specifications</h2>", $rm);
             $rm = preg_replace("/(\\=\\=)( )(Installation)( )(\\=\\=)/", "<h2 id=\"rm-installation\">\$3</h2>", $rm);
             $rm = preg_replace("/(\\=\\=)( )(Description)( )(\\=\\=)/", "<h2 id=\"rm-description\">\$3</h2>", $rm);
             $rm = preg_replace("/(\\=\\=)( )(Screenshots)( )(\\=\\=)/", "<h2 id=\"rm-screenshots\">\$3</h2>", $rm);
             $rm = preg_replace("/(\\=\\=)( )(Frequently Asked Questions)( )(\\=\\=)/", "<h2 id=\"rm-faqs\">\$3</h2>", $rm);
             $rm = preg_replace("/(\\=\\=)( )(Changelog)( )(\\=\\=)/", "<h2 id=\"rm-changelog\">\$3</h2>", $rm);
             $rm = preg_replace("/(\\=\\=)( )(.+?)( )(\\=\\=)/", "<h2>\$3</h2>", $rm);
             $rm = preg_replace("/(\\=)( )(.+?)( )(\\=)/", "<h3>\$3</h3>", $rm);
             /**/
             $rm = NC_Markdown($rm);
             /* Parse out the Markdown syntax. */
             /**/
             $r1 = "/(\\<h2(.*?)\\>)(.+?)(\\<\\/h2\\>)(.+?)(\\<h2(.*?)\\>|\$)/si";
             $r2 = "/(\\<\\/div\\>)(\\<h2(.*?)\\>)(.+?)(\\<\\/h2\\>)(.+?)(\\<div class\\=\"section\"\\>\\<h2(.*?)\\>|\$)/si";
             $r3 = "/(\\<div class\\=\"section\"\\>)(\\<h2 id\\=\"rm-specs\"\\>)(Specifications)(\\<\\/h2\\>)(\\<div class\\=\"content\"\\>)(.+?)(\\<\\/div\\>\\<\\/div\\>)/sei";
             $r4 = "/(\\<div class\\=\"section\"\\>)(\\<h2 id\\=\"rm-screenshots\"\\>)(Screenshots)(\\<\\/h2\\>)(\\<div class\\=\"content\"\\>)(.+?)(\\<\\/div\\>\\<\\/div\\>)/sei";
             $r5 = "/(\\<a)( href)/i";
             /* Modify all links. Assume a nofollow relationship since destinations are unknown. */
             /**/
             $rm = preg_replace($r1, '<div class="section">' . "\$1\$3\$4" . '<div class="content">' . "\$5" . '</div></div>' . "\$6", $rm);
             $rm = preg_replace($r2, "\$1" . '<div class="section">' . "\$2\$4\$5" . '<div class="content">' . "\$6" . '</div></div>' . "\$7", $rm);
             $rm = stripslashes(preg_replace($r3, "'\$1\$2\$3\$4\$5'.c_ws_plugin__qcache_readmes::_parse_readme_specs('\$6').'\$7'", $rm, 1));
             $rm = preg_replace($r4, "", $rm, 1);
             /* Here we just remove the screenshots completely. */
             /**/
             if ($_blank_targets) {
                 /* Modify all links. Always nofollow. ( with _blank targets ? ). */
                 $rm = preg_replace($r5, "\$1" . ' target="_blank" rel="nofollow external"' . "\$2", $rm);
             } else {
                 /* Otherwise, we don't need to set _blank targets. So external is removed also. */
                 $rm = preg_replace($r5, "\$1" . ' rel="nofollow"' . "\$2", $rm);
             }
             /**/
             if ($process_wp_syntax) {
                 /* If we're processing <pre><code> tags for WP-Syntax. */
                 if (function_exists("wp_syntax_before_filter") && function_exists("wp_syntax_before_filter")) {
                     $rm = preg_replace("/\\<pre\\>\\<code\\>/i", '<pre lang="php" escaped="true">', $rm);
                     $rm = preg_replace("/\\<\\/code\\>\\<\\/pre\\>/i", '</pre>', $rm);
                     $rm = wp_syntax_after_filter(wp_syntax_before_filter($rm));
                 }
             }
             /**/
             @ini_set("pcre.backtrack_limit", $o_pcre);
             /**/
             $readme = '<div class="readme">' . "\n";
             $readme .= $rm . "\n";
             /* Content. */
             $readme .= '</div>' . "\n";
             /**/
             return apply_filters("ws_plugin__qcache_parse_readme", $readme, get_defined_vars());
         }
     } else {
         return "Unable to parse /readme.txt.";
     }
 }