@@ -2,9 +2,9 @@ discard block |
||
2 | 2 | |
3 | 3 | //Check everything exists before using it |
4 | 4 | if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) |
5 | - $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; |
|
5 | + $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; |
|
6 | 6 | if(!isset($_SERVER['HTTP_USER_AGENT'])) |
7 | - $_SERVER['HTTP_USER_AGENT'] = ''; |
|
7 | + $_SERVER['HTTP_USER_AGENT'] = ''; |
|
8 | 8 | |
9 | 9 | // Determine supported compression method |
10 | 10 | $gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'); |
@@ -15,30 +15,30 @@ discard block |
||
15 | 15 | |
16 | 16 | // Check for buggy versions of Internet Explorer |
17 | 17 | if (!strstr($_SERVER['HTTP_USER_AGENT'], 'Opera') && |
18 | - preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) |
|
18 | + preg_match('/^Mozilla\/4\.0 \(compatible; MSIE ([0-9]\.[0-9])/i', $_SERVER['HTTP_USER_AGENT'], $matches)) |
|
19 | 19 | { |
20 | - $version = floatval($matches[1]); |
|
20 | + $version = floatval($matches[1]); |
|
21 | 21 | |
22 | - if ($version < 6) |
|
23 | - $encoding = 'none'; |
|
22 | + if ($version < 6) |
|
23 | + $encoding = 'none'; |
|
24 | 24 | |
25 | - if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) |
|
26 | - $encoding = 'none'; |
|
25 | + if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) |
|
26 | + $encoding = 'none'; |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | //Some servers compress the output of PHP - Don't break in those cases |
30 | 30 | if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) |
31 | - $encoding = 'none'; |
|
31 | + $encoding = 'none'; |
|
32 | 32 | |
33 | 33 | $iscompressed = file_exists(__FILE__.'.'.$encoding); |
34 | 34 | if($encoding != 'none' && $iscompressed == false) |
35 | 35 | { |
36 | - $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); |
|
37 | - $code = file_get_contents(__FILE__.'.none'); |
|
38 | - $contents = gzencode($code,9,$flag); |
|
36 | + $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); |
|
37 | + $code = file_get_contents(__FILE__.'.none'); |
|
38 | + $contents = gzencode($code,9,$flag); |
|
39 | 39 | }else{ |
40 | - //Get data |
|
41 | - $contents = file_get_contents(__FILE__.'.'.$encoding); |
|
40 | + //Get data |
|
41 | + $contents = file_get_contents(__FILE__.'.'.$encoding); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | // first check if we have to send 304 |
@@ -52,36 +52,36 @@ discard block |
||
52 | 52 | $modTimeMatch = (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) === $modTime); |
53 | 53 | |
54 | 54 | if (($modTimeMatch)||($eTagMatch)) { |
55 | - header('HTTP/1.1 304 Not Modified'); |
|
56 | - header('Connection: close'); |
|
55 | + header('HTTP/1.1 304 Not Modified'); |
|
56 | + header('Connection: close'); |
|
57 | 57 | } else { |
58 | - // send all sorts of headers |
|
59 | - $expireTime=60*60*24*355; // 1y max according to RFC |
|
60 | - if ($encoding != 'none') { |
|
61 | - header('Content-Encoding: '.$encoding); |
|
62 | - } |
|
63 | - header('Vary: Accept-Encoding'); |
|
64 | - header('Content-Length: '.strlen($contents)); |
|
65 | - header('Content-type: %%CONTENT%%; charset=utf-8'); |
|
66 | - header('Cache-Control: max-age='.$expireTime.', public, must-revalidate'); |
|
67 | - header('Cache-Control: max-age='.$expireTime.', public, immutable'); |
|
68 | - header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); |
|
69 | - header('ETag: ' . $eTag); |
|
70 | - header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); |
|
58 | + // send all sorts of headers |
|
59 | + $expireTime=60*60*24*355; // 1y max according to RFC |
|
60 | + if ($encoding != 'none') { |
|
61 | + header('Content-Encoding: '.$encoding); |
|
62 | + } |
|
63 | + header('Vary: Accept-Encoding'); |
|
64 | + header('Content-Length: '.strlen($contents)); |
|
65 | + header('Content-type: %%CONTENT%%; charset=utf-8'); |
|
66 | + header('Cache-Control: max-age='.$expireTime.', public, must-revalidate'); |
|
67 | + header('Cache-Control: max-age='.$expireTime.', public, immutable'); |
|
68 | + header('Expires: '.gmdate('D, d M Y H:i:s', time() + $expireTime).' GMT'); |
|
69 | + header('ETag: ' . $eTag); |
|
70 | + header('Last-Modified: '.gmdate('D, d M Y H:i:s', $modTime).' GMT'); |
|
71 | 71 | |
72 | - // send output |
|
73 | - echo $contents; |
|
72 | + // send output |
|
73 | + echo $contents; |
|
74 | 74 | |
75 | - //And write to filesystem cache if not done yet |
|
76 | - if($encoding != 'none' && $iscompressed == false) |
|
77 | - { |
|
78 | - //Write the content we sent |
|
79 | - file_put_contents(__FILE__.'.'.$encoding,$contents); |
|
75 | + //And write to filesystem cache if not done yet |
|
76 | + if($encoding != 'none' && $iscompressed == false) |
|
77 | + { |
|
78 | + //Write the content we sent |
|
79 | + file_put_contents(__FILE__.'.'.$encoding,$contents); |
|
80 | 80 | |
81 | - //And write the new content |
|
82 | - $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP); |
|
83 | - $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip'); |
|
84 | - $contents = gzencode($code,9,$flag); |
|
85 | - file_put_contents(__FILE__.'.'.$ext,$contents); |
|
86 | - } |
|
81 | + //And write the new content |
|
82 | + $flag = ($encoding == 'gzip' ? FORCE_DEFLATE : FORCE_GZIP); |
|
83 | + $ext = ($encoding == 'gzip' ? 'deflate' : 'gzip'); |
|
84 | + $contents = gzencode($code,9,$flag); |
|
85 | + file_put_contents(__FILE__.'.'.$ext,$contents); |
|
86 | + } |
|
87 | 87 | } |
@@ -1,10 +1,12 @@ discard block |
||
1 | 1 | <?php exit; |
2 | 2 | |
3 | 3 | //Check everything exists before using it |
4 | -if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) |
|
4 | +if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) { |
|
5 | 5 | $_SERVER['HTTP_ACCEPT_ENCODING'] = ''; |
6 | -if(!isset($_SERVER['HTTP_USER_AGENT'])) |
|
6 | +} |
|
7 | +if(!isset($_SERVER['HTTP_USER_AGENT'])) { |
|
7 | 8 | $_SERVER['HTTP_USER_AGENT'] = ''; |
9 | +} |
|
8 | 10 | |
9 | 11 | // Determine supported compression method |
10 | 12 | $gzip = strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'); |
@@ -19,16 +21,19 @@ discard block |
||
19 | 21 | { |
20 | 22 | $version = floatval($matches[1]); |
21 | 23 | |
22 | - if ($version < 6) |
|
23 | - $encoding = 'none'; |
|
24 | + if ($version < 6) { |
|
25 | + $encoding = 'none'; |
|
26 | + } |
|
24 | 27 | |
25 | - if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) |
|
26 | - $encoding = 'none'; |
|
27 | -} |
|
28 | + if ($version == 6 && !strstr($_SERVER['HTTP_USER_AGENT'], 'EV1')) { |
|
29 | + $encoding = 'none'; |
|
30 | + } |
|
31 | + } |
|
28 | 32 | |
29 | 33 | //Some servers compress the output of PHP - Don't break in those cases |
30 | -if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) |
|
34 | +if(ini_get('output_handler') == 'ob_gzhandler' || ini_get('zlib.output_compression') == 1) { |
|
31 | 35 | $encoding = 'none'; |
36 | +} |
|
32 | 37 | |
33 | 38 | $iscompressed = file_exists(__FILE__.'.'.$encoding); |
34 | 39 | if($encoding != 'none' && $iscompressed == false) |
@@ -36,7 +41,7 @@ discard block |
||
36 | 41 | $flag = ($encoding == 'gzip' ? FORCE_GZIP : FORCE_DEFLATE); |
37 | 42 | $code = file_get_contents(__FILE__.'.none'); |
38 | 43 | $contents = gzencode($code,9,$flag); |
39 | -}else{ |
|
44 | +} else{ |
|
40 | 45 | //Get data |
41 | 46 | $contents = file_get_contents(__FILE__.'.'.$encoding); |
42 | 47 | } |
@@ -412,7 +412,7 @@ |
||
412 | 412 | * First element is the filepath, second is the md5 hash of contents |
413 | 413 | * the filepath had when it was being processed. |
414 | 414 | * If we don't have those, we'll bail out early. |
415 | - */ |
|
415 | + */ |
|
416 | 416 | $filepath = null; |
417 | 417 | $filehash = null; |
418 | 418 |
@@ -1,5 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly. |
|
2 | +if ( ! defined( 'ABSPATH' ) ) { |
|
3 | + exit; |
|
4 | +} |
|
5 | +// Exit if accessed directly. |
|
3 | 6 | |
4 | 7 | class autoptimizeConfig |
5 | 8 | { |
@@ -791,10 +794,13 @@ discard block |
||
791 | 794 | <ul> |
792 | 795 | <?php if ( $maxitems == 0 ) : ?> |
793 | 796 | <li><?php _e( 'No items', 'autoptimize' ); ?></li> |
794 | - <?php else : ?> |
|
797 | + <?php else { |
|
798 | + : ?> |
|
795 | 799 | <?php foreach ( $rss_items as $item ) : ?> |
796 | 800 | <li> |
797 | - <a href="<?php echo esc_url( $item->get_permalink() ); ?>" |
|
801 | + <a href="<?php echo esc_url( $item->get_permalink() ); |
|
802 | +} |
|
803 | +?>" |
|
798 | 804 | title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date('j F Y | g:i a') ); ?>"> |
799 | 805 | <?php echo esc_html( $item->get_title() ); ?> |
800 | 806 | </a> |
@@ -29,131 +29,131 @@ |
||
29 | 29 | * Exit if called directly. |
30 | 30 | */ |
31 | 31 | if ( ! defined( 'ABSPATH' ) ) { |
32 | - die; |
|
32 | + die; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | if ( ! class_exists( 'PAnD' ) ) { |
36 | 36 | |
37 | - /** |
|
38 | - * Class PAnD |
|
39 | - */ |
|
40 | - class PAnD { |
|
41 | - |
|
42 | - /** |
|
43 | - * Init hooks. |
|
44 | - */ |
|
45 | - public static function init() { |
|
46 | - add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_script' ) ); |
|
47 | - add_action( 'wp_ajax_dismiss_admin_notice', array( __CLASS__, 'dismiss_admin_notice' ) ); |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Enqueue javascript and variables. |
|
52 | - */ |
|
53 | - public static function load_script() { |
|
54 | - |
|
55 | - if ( is_customize_preview() ) { |
|
56 | - return; |
|
57 | - } |
|
58 | - |
|
59 | - wp_enqueue_script( |
|
60 | - 'dismissible-notices', |
|
61 | - plugins_url( 'dismiss-notice.js', __FILE__ ), |
|
62 | - array( 'jquery', 'common' ), |
|
63 | - false, |
|
64 | - true |
|
65 | - ); |
|
66 | - |
|
67 | - wp_localize_script( |
|
68 | - 'dismissible-notices', |
|
69 | - 'dismissible_notice', |
|
70 | - array( |
|
71 | - 'nonce' => wp_create_nonce( 'dismissible-notice' ), |
|
72 | - ) |
|
73 | - ); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Handles Ajax request to persist notices dismissal. |
|
78 | - * Uses check_ajax_referer to verify nonce. |
|
79 | - */ |
|
80 | - public static function dismiss_admin_notice() { |
|
81 | - $option_name = sanitize_text_field( $_POST['option_name'] ); |
|
82 | - $dismissible_length = sanitize_text_field( $_POST['dismissible_length'] ); |
|
83 | - |
|
84 | - if ( 'forever' != $dismissible_length ) { |
|
85 | - // If $dismissible_length is not an integer default to 1 |
|
86 | - $dismissible_length = ( 0 == absint( $dismissible_length ) ) ? 1 : $dismissible_length; |
|
87 | - $dismissible_length = strtotime( absint( $dismissible_length ) . ' days' ); |
|
88 | - } |
|
89 | - |
|
90 | - check_ajax_referer( 'dismissible-notice', 'nonce' ); |
|
91 | - self::set_admin_notice_cache( $option_name, $dismissible_length ); |
|
92 | - wp_die(); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Is admin notice active? |
|
97 | - * |
|
98 | - * @param string $arg data-dismissible content of notice. |
|
99 | - * |
|
100 | - * @return bool |
|
101 | - */ |
|
102 | - public static function is_admin_notice_active( $arg ) { |
|
103 | - $array = explode( '-', $arg ); |
|
104 | - $length = array_pop( $array ); |
|
105 | - $option_name = implode( '-', $array ); |
|
106 | - $db_record = self::get_admin_notice_cache( $option_name ); |
|
107 | - if ( 'forever' == $db_record ) { |
|
108 | - return false; |
|
109 | - } elseif ( absint( $db_record ) >= time() ) { |
|
110 | - return false; |
|
111 | - } else { |
|
112 | - return true; |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Returns admin notice cached timeout. |
|
118 | - * |
|
119 | - * @access public |
|
120 | - * |
|
121 | - * @param string|bool $id admin notice name or false. |
|
122 | - * |
|
123 | - * @return array|bool The timeout. False if expired. |
|
124 | - */ |
|
125 | - public static function get_admin_notice_cache( $id = false ) { |
|
126 | - if ( ! $id ) { |
|
127 | - return false; |
|
128 | - } |
|
129 | - $cache_key = 'pand-' . md5( $id ); |
|
130 | - $timeout = get_site_option( $cache_key ); |
|
131 | - $timeout = 'forever' === $timeout ? time() + 60 : $timeout; |
|
132 | - |
|
133 | - if ( empty( $timeout ) || time() > $timeout ) { |
|
134 | - return false; |
|
135 | - } |
|
136 | - |
|
137 | - return $timeout; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Sets admin notice timeout in site option. |
|
142 | - * |
|
143 | - * @access public |
|
144 | - * |
|
145 | - * @param string $id Data Identifier. |
|
146 | - * @param string|bool $timeout Timeout for admin notice. |
|
147 | - * |
|
148 | - * @return bool |
|
149 | - */ |
|
150 | - public static function set_admin_notice_cache( $id, $timeout ) { |
|
151 | - $cache_key = 'pand-' . md5( $id ); |
|
152 | - update_site_option( $cache_key, $timeout ); |
|
153 | - |
|
154 | - return true; |
|
155 | - } |
|
156 | - |
|
157 | - } |
|
37 | + /** |
|
38 | + * Class PAnD |
|
39 | + */ |
|
40 | + class PAnD { |
|
41 | + |
|
42 | + /** |
|
43 | + * Init hooks. |
|
44 | + */ |
|
45 | + public static function init() { |
|
46 | + add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_script' ) ); |
|
47 | + add_action( 'wp_ajax_dismiss_admin_notice', array( __CLASS__, 'dismiss_admin_notice' ) ); |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Enqueue javascript and variables. |
|
52 | + */ |
|
53 | + public static function load_script() { |
|
54 | + |
|
55 | + if ( is_customize_preview() ) { |
|
56 | + return; |
|
57 | + } |
|
58 | + |
|
59 | + wp_enqueue_script( |
|
60 | + 'dismissible-notices', |
|
61 | + plugins_url( 'dismiss-notice.js', __FILE__ ), |
|
62 | + array( 'jquery', 'common' ), |
|
63 | + false, |
|
64 | + true |
|
65 | + ); |
|
66 | + |
|
67 | + wp_localize_script( |
|
68 | + 'dismissible-notices', |
|
69 | + 'dismissible_notice', |
|
70 | + array( |
|
71 | + 'nonce' => wp_create_nonce( 'dismissible-notice' ), |
|
72 | + ) |
|
73 | + ); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Handles Ajax request to persist notices dismissal. |
|
78 | + * Uses check_ajax_referer to verify nonce. |
|
79 | + */ |
|
80 | + public static function dismiss_admin_notice() { |
|
81 | + $option_name = sanitize_text_field( $_POST['option_name'] ); |
|
82 | + $dismissible_length = sanitize_text_field( $_POST['dismissible_length'] ); |
|
83 | + |
|
84 | + if ( 'forever' != $dismissible_length ) { |
|
85 | + // If $dismissible_length is not an integer default to 1 |
|
86 | + $dismissible_length = ( 0 == absint( $dismissible_length ) ) ? 1 : $dismissible_length; |
|
87 | + $dismissible_length = strtotime( absint( $dismissible_length ) . ' days' ); |
|
88 | + } |
|
89 | + |
|
90 | + check_ajax_referer( 'dismissible-notice', 'nonce' ); |
|
91 | + self::set_admin_notice_cache( $option_name, $dismissible_length ); |
|
92 | + wp_die(); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Is admin notice active? |
|
97 | + * |
|
98 | + * @param string $arg data-dismissible content of notice. |
|
99 | + * |
|
100 | + * @return bool |
|
101 | + */ |
|
102 | + public static function is_admin_notice_active( $arg ) { |
|
103 | + $array = explode( '-', $arg ); |
|
104 | + $length = array_pop( $array ); |
|
105 | + $option_name = implode( '-', $array ); |
|
106 | + $db_record = self::get_admin_notice_cache( $option_name ); |
|
107 | + if ( 'forever' == $db_record ) { |
|
108 | + return false; |
|
109 | + } elseif ( absint( $db_record ) >= time() ) { |
|
110 | + return false; |
|
111 | + } else { |
|
112 | + return true; |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Returns admin notice cached timeout. |
|
118 | + * |
|
119 | + * @access public |
|
120 | + * |
|
121 | + * @param string|bool $id admin notice name or false. |
|
122 | + * |
|
123 | + * @return array|bool The timeout. False if expired. |
|
124 | + */ |
|
125 | + public static function get_admin_notice_cache( $id = false ) { |
|
126 | + if ( ! $id ) { |
|
127 | + return false; |
|
128 | + } |
|
129 | + $cache_key = 'pand-' . md5( $id ); |
|
130 | + $timeout = get_site_option( $cache_key ); |
|
131 | + $timeout = 'forever' === $timeout ? time() + 60 : $timeout; |
|
132 | + |
|
133 | + if ( empty( $timeout ) || time() > $timeout ) { |
|
134 | + return false; |
|
135 | + } |
|
136 | + |
|
137 | + return $timeout; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Sets admin notice timeout in site option. |
|
142 | + * |
|
143 | + * @access public |
|
144 | + * |
|
145 | + * @param string $id Data Identifier. |
|
146 | + * @param string|bool $timeout Timeout for admin notice. |
|
147 | + * |
|
148 | + * @return bool |
|
149 | + */ |
|
150 | + public static function set_admin_notice_cache( $id, $timeout ) { |
|
151 | + $cache_key = 'pand-' . md5( $id ); |
|
152 | + update_site_option( $cache_key, $timeout ); |
|
153 | + |
|
154 | + return true; |
|
155 | + } |
|
156 | + |
|
157 | + } |
|
158 | 158 | |
159 | 159 | } |
@@ -1528,8 +1528,8 @@ |
||
1528 | 1528 | 'q', 'rt', 'ins', 'font', 'strong', |
1529 | 1529 | 's', 'tt', 'sub', 'mark', |
1530 | 1530 | 'u', 'xm', 'sup', 'nobr', |
1531 | - 'var', 'ruby', |
|
1532 | - 'wbr', 'span', |
|
1533 | - 'time', |
|
1531 | + 'var', 'ruby', |
|
1532 | + 'wbr', 'span', |
|
1533 | + 'time', |
|
1534 | 1534 | ); |
1535 | 1535 | } |
@@ -178,8 +178,7 @@ discard block |
||
178 | 178 | $CurrentBlock = $Block; |
179 | 179 | |
180 | 180 | continue; |
181 | - } |
|
182 | - else |
|
181 | + } else |
|
183 | 182 | { |
184 | 183 | if (method_exists($this, 'block'.$CurrentBlock['type'].'Complete')) |
185 | 184 | { |
@@ -240,8 +239,7 @@ discard block |
||
240 | 239 | if (isset($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted'])) |
241 | 240 | { |
242 | 241 | $CurrentBlock['element']['text'] .= "\n".$text; |
243 | - } |
|
244 | - else |
|
242 | + } else |
|
245 | 243 | { |
246 | 244 | $Blocks []= $CurrentBlock; |
247 | 245 | |
@@ -696,8 +694,7 @@ discard block |
||
696 | 694 | |
697 | 695 | $Block['void'] = true; |
698 | 696 | } |
699 | - } |
|
700 | - else |
|
697 | + } else |
|
701 | 698 | { |
702 | 699 | if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) |
703 | 700 | { |
@@ -721,18 +718,21 @@ discard block |
||
721 | 718 | return; |
722 | 719 | } |
723 | 720 | |
724 | - if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open |
|
721 | + if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) { |
|
722 | + # open |
|
725 | 723 | { |
726 | 724 | $Block['depth'] ++; |
727 | 725 | } |
726 | + } |
|
728 | 727 | |
729 | - if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close |
|
728 | + if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) { |
|
729 | + # close |
|
730 | 730 | { |
731 | 731 | if ($Block['depth'] > 0) |
732 | 732 | { |
733 | 733 | $Block['depth'] --; |
734 | - } |
|
735 | - else |
|
734 | + } |
|
735 | + } else |
|
736 | 736 | { |
737 | 737 | $Block['closed'] = true; |
738 | 738 | } |
@@ -1010,10 +1010,12 @@ discard block |
||
1010 | 1010 | continue; |
1011 | 1011 | } |
1012 | 1012 | |
1013 | - if (isset($Inline['position']) and $Inline['position'] > $markerPosition) # position is ahead of marker |
|
1013 | + if (isset($Inline['position']) and $Inline['position'] > $markerPosition) { |
|
1014 | + # position is ahead of marker |
|
1014 | 1015 | { |
1015 | 1016 | continue; |
1016 | 1017 | } |
1018 | + } |
|
1017 | 1019 | |
1018 | 1020 | if ( ! isset($Inline['position'])) |
1019 | 1021 | { |
@@ -1105,12 +1107,10 @@ discard block |
||
1105 | 1107 | if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches)) |
1106 | 1108 | { |
1107 | 1109 | $emphasis = 'strong'; |
1108 | - } |
|
1109 | - elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches)) |
|
1110 | + } elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches)) |
|
1110 | 1111 | { |
1111 | 1112 | $emphasis = 'em'; |
1112 | - } |
|
1113 | - else |
|
1113 | + } else |
|
1114 | 1114 | { |
1115 | 1115 | return; |
1116 | 1116 | } |
@@ -1193,8 +1193,7 @@ discard block |
||
1193 | 1193 | $extent += strlen($matches[0]); |
1194 | 1194 | |
1195 | 1195 | $remainder = substr($remainder, $extent); |
1196 | - } |
|
1197 | - else |
|
1196 | + } else |
|
1198 | 1197 | { |
1199 | 1198 | return; |
1200 | 1199 | } |
@@ -1209,8 +1208,7 @@ discard block |
||
1209 | 1208 | } |
1210 | 1209 | |
1211 | 1210 | $extent += strlen($matches[0]); |
1212 | - } |
|
1213 | - else |
|
1211 | + } else |
|
1214 | 1212 | { |
1215 | 1213 | if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches)) |
1216 | 1214 | { |
@@ -1218,8 +1216,7 @@ discard block |
||
1218 | 1216 | $definition = strtolower($definition); |
1219 | 1217 | |
1220 | 1218 | $extent += strlen($matches[0]); |
1221 | - } |
|
1222 | - else |
|
1219 | + } else |
|
1223 | 1220 | { |
1224 | 1221 | $definition = strtolower($Element['text']); |
1225 | 1222 | } |
@@ -1372,8 +1369,7 @@ discard block |
||
1372 | 1369 | if ($this->breaksEnabled) |
1373 | 1370 | { |
1374 | 1371 | $text = preg_replace('/[ ]*\n/', "<br />\n", $text); |
1375 | - } |
|
1376 | - else |
|
1372 | + } else |
|
1377 | 1373 | { |
1378 | 1374 | $text = preg_replace('/(?:[ ][ ]+|[ ]*\\\\)\n/', "<br />\n", $text); |
1379 | 1375 | $text = str_replace(" \n", "\n", $text); |
@@ -1410,15 +1406,13 @@ discard block |
||
1410 | 1406 | if (isset($Element['handler'])) |
1411 | 1407 | { |
1412 | 1408 | $markup .= $this->{$Element['handler']}($Element['text']); |
1413 | - } |
|
1414 | - else |
|
1409 | + } else |
|
1415 | 1410 | { |
1416 | 1411 | $markup .= $Element['text']; |
1417 | 1412 | } |
1418 | 1413 | |
1419 | 1414 | $markup .= '</'.$Element['name'].'>'; |
1420 | - } |
|
1421 | - else |
|
1415 | + } else |
|
1422 | 1416 | { |
1423 | 1417 | $markup .= ' />'; |
1424 | 1418 | } |
@@ -1531,8 +1531,8 @@ |
||
1531 | 1531 | 'q', 'rt', 'ins', 'font', 'strong', |
1532 | 1532 | 's', 'tt', 'sub', 'mark', |
1533 | 1533 | 'u', 'xm', 'sup', 'nobr', |
1534 | - 'var', 'ruby', |
|
1535 | - 'wbr', 'span', |
|
1536 | - 'time', |
|
1534 | + 'var', 'ruby', |
|
1535 | + 'wbr', 'span', |
|
1536 | + 'time', |
|
1537 | 1537 | ); |
1538 | 1538 | } |
1539 | 1539 | \ No newline at end of file |
@@ -172,8 +172,7 @@ discard block |
||
172 | 172 | $CurrentBlock = $Block; |
173 | 173 | |
174 | 174 | continue; |
175 | - } |
|
176 | - else |
|
175 | + } else |
|
177 | 176 | { |
178 | 177 | if ($this->isBlockCompletable($CurrentBlock['type'])) |
179 | 178 | { |
@@ -232,8 +231,7 @@ discard block |
||
232 | 231 | if (isset($CurrentBlock) and ! isset($CurrentBlock['type']) and ! isset($CurrentBlock['interrupted'])) |
233 | 232 | { |
234 | 233 | $CurrentBlock['element']['text'] .= "\n".$text; |
235 | - } |
|
236 | - else |
|
234 | + } else |
|
237 | 235 | { |
238 | 236 | $Blocks []= $CurrentBlock; |
239 | 237 | |
@@ -700,8 +698,7 @@ discard block |
||
700 | 698 | |
701 | 699 | $Block['void'] = true; |
702 | 700 | } |
703 | - } |
|
704 | - else |
|
701 | + } else |
|
705 | 702 | { |
706 | 703 | if (isset($matches[2]) or in_array($matches[1], $this->voidElements)) |
707 | 704 | { |
@@ -725,18 +722,21 @@ discard block |
||
725 | 722 | return; |
726 | 723 | } |
727 | 724 | |
728 | - if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) # open |
|
725 | + if (preg_match('/^<'.$Block['name'].'(?:[ ]*'.$this->regexHtmlAttribute.')*[ ]*>/i', $Line['text'])) { |
|
726 | + # open |
|
729 | 727 | { |
730 | 728 | $Block['depth'] ++; |
731 | 729 | } |
730 | + } |
|
732 | 731 | |
733 | - if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) # close |
|
732 | + if (preg_match('/(.*?)<\/'.$Block['name'].'>[ ]*$/i', $Line['text'], $matches)) { |
|
733 | + # close |
|
734 | 734 | { |
735 | 735 | if ($Block['depth'] > 0) |
736 | 736 | { |
737 | 737 | $Block['depth'] --; |
738 | - } |
|
739 | - else |
|
738 | + } |
|
739 | + } else |
|
740 | 740 | { |
741 | 741 | $Block['closed'] = true; |
742 | 742 | } |
@@ -1113,12 +1113,10 @@ discard block |
||
1113 | 1113 | if ($Excerpt['text'][1] === $marker and preg_match($this->StrongRegex[$marker], $Excerpt['text'], $matches)) |
1114 | 1114 | { |
1115 | 1115 | $emphasis = 'strong'; |
1116 | - } |
|
1117 | - elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches)) |
|
1116 | + } elseif (preg_match($this->EmRegex[$marker], $Excerpt['text'], $matches)) |
|
1118 | 1117 | { |
1119 | 1118 | $emphasis = 'em'; |
1120 | - } |
|
1121 | - else |
|
1119 | + } else |
|
1122 | 1120 | { |
1123 | 1121 | return; |
1124 | 1122 | } |
@@ -1201,8 +1199,7 @@ discard block |
||
1201 | 1199 | $extent += strlen($matches[0]); |
1202 | 1200 | |
1203 | 1201 | $remainder = substr($remainder, $extent); |
1204 | - } |
|
1205 | - else |
|
1202 | + } else |
|
1206 | 1203 | { |
1207 | 1204 | return; |
1208 | 1205 | } |
@@ -1217,8 +1214,7 @@ discard block |
||
1217 | 1214 | } |
1218 | 1215 | |
1219 | 1216 | $extent += strlen($matches[0]); |
1220 | - } |
|
1221 | - else |
|
1217 | + } else |
|
1222 | 1218 | { |
1223 | 1219 | if (preg_match('/^\s*\[(.*?)\]/', $remainder, $matches)) |
1224 | 1220 | { |
@@ -1226,8 +1222,7 @@ discard block |
||
1226 | 1222 | $definition = strtolower($definition); |
1227 | 1223 | |
1228 | 1224 | $extent += strlen($matches[0]); |
1229 | - } |
|
1230 | - else |
|
1225 | + } else |
|
1231 | 1226 | { |
1232 | 1227 | $definition = strtolower($Element['text']); |
1233 | 1228 | } |
@@ -1375,8 +1370,7 @@ discard block |
||
1375 | 1370 | if ($this->breaksEnabled) |
1376 | 1371 | { |
1377 | 1372 | $text = preg_replace('/[ ]*\n/', "<br />\n", $text); |
1378 | - } |
|
1379 | - else |
|
1373 | + } else |
|
1380 | 1374 | { |
1381 | 1375 | $text = preg_replace('/(?:[ ][ ]+|[ ]*\\\\)\n/', "<br />\n", $text); |
1382 | 1376 | $text = str_replace(" \n", "\n", $text); |
@@ -1413,15 +1407,13 @@ discard block |
||
1413 | 1407 | if (isset($Element['handler'])) |
1414 | 1408 | { |
1415 | 1409 | $markup .= $this->{$Element['handler']}($Element['text']); |
1416 | - } |
|
1417 | - else |
|
1410 | + } else |
|
1418 | 1411 | { |
1419 | 1412 | $markup .= $Element['text']; |
1420 | 1413 | } |
1421 | 1414 | |
1422 | 1415 | $markup .= '</'.$Element['name'].'>'; |
1423 | - } |
|
1424 | - else |
|
1416 | + } else |
|
1425 | 1417 | { |
1426 | 1418 | $markup .= ' />'; |
1427 | 1419 | } |
@@ -9,325 +9,325 @@ |
||
9 | 9 | |
10 | 10 | class PucReadmeParser { |
11 | 11 | |
12 | - function __construct() { |
|
13 | - // This space intentionally blank |
|
14 | - } |
|
15 | - |
|
16 | - function parse_readme( $file ) { |
|
17 | - $file_contents = @implode('', @file($file)); |
|
18 | - return $this->parse_readme_contents( $file_contents ); |
|
19 | - } |
|
20 | - |
|
21 | - function parse_readme_contents( $file_contents ) { |
|
22 | - $file_contents = str_replace(array("\r\n", "\r"), "\n", $file_contents); |
|
23 | - $file_contents = trim($file_contents); |
|
24 | - if ( 0 === strpos( $file_contents, "\xEF\xBB\xBF" ) ) |
|
25 | - $file_contents = substr( $file_contents, 3 ); |
|
26 | - |
|
27 | - // Markdown transformations |
|
28 | - $file_contents = preg_replace( "|^###([^#]+)#*?\s*?\n|im", '=$1='."\n", $file_contents ); |
|
29 | - $file_contents = preg_replace( "|^##([^#]+)#*?\s*?\n|im", '==$1=='."\n", $file_contents ); |
|
30 | - $file_contents = preg_replace( "|^#([^#]+)#*?\s*?\n|im", '===$1==='."\n", $file_contents ); |
|
31 | - |
|
32 | - // === Plugin Name === |
|
33 | - // Must be the very first thing. |
|
34 | - if ( !preg_match('|^===(.*)===|', $file_contents, $_name) ) |
|
35 | - return array(); // require a name |
|
36 | - $name = trim($_name[1], '='); |
|
37 | - $name = $this->sanitize_text( $name ); |
|
38 | - |
|
39 | - $file_contents = $this->chop_string( $file_contents, $_name[0] ); |
|
40 | - |
|
41 | - |
|
42 | - // Requires at least: 1.5 |
|
43 | - if ( preg_match('|Requires at least:(.*)|i', $file_contents, $_requires_at_least) ) |
|
44 | - $requires_at_least = $this->sanitize_text($_requires_at_least[1]); |
|
45 | - else |
|
46 | - $requires_at_least = NULL; |
|
47 | - |
|
48 | - |
|
49 | - // Tested up to: 2.1 |
|
50 | - if ( preg_match('|Tested up to:(.*)|i', $file_contents, $_tested_up_to) ) |
|
51 | - $tested_up_to = $this->sanitize_text( $_tested_up_to[1] ); |
|
52 | - else |
|
53 | - $tested_up_to = NULL; |
|
54 | - |
|
55 | - |
|
56 | - // Stable tag: 10.4-ride-the-fire-eagle-danger-day |
|
57 | - if ( preg_match('|Stable tag:(.*)|i', $file_contents, $_stable_tag) ) |
|
58 | - $stable_tag = $this->sanitize_text( $_stable_tag[1] ); |
|
59 | - else |
|
60 | - $stable_tag = NULL; // we assume trunk, but don't set it here to tell the difference between specified trunk and default trunk |
|
61 | - |
|
62 | - |
|
63 | - // Tags: some tag, another tag, we like tags |
|
64 | - if ( preg_match('|Tags:(.*)|i', $file_contents, $_tags) ) { |
|
65 | - $tags = preg_split('|,[\s]*?|', trim($_tags[1])); |
|
66 | - foreach ( array_keys($tags) as $t ) |
|
67 | - $tags[$t] = $this->sanitize_text( $tags[$t] ); |
|
68 | - } else { |
|
69 | - $tags = array(); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - // Contributors: markjaquith, mdawaffe, zefrank |
|
74 | - $contributors = array(); |
|
75 | - if ( preg_match('|Contributors:(.*)|i', $file_contents, $_contributors) ) { |
|
76 | - $temp_contributors = preg_split('|,[\s]*|', trim($_contributors[1])); |
|
77 | - foreach ( array_keys($temp_contributors) as $c ) { |
|
78 | - $tmp_sanitized = $this->user_sanitize( $temp_contributors[$c] ); |
|
79 | - if ( strlen(trim($tmp_sanitized)) > 0 ) |
|
80 | - $contributors[$c] = $tmp_sanitized; |
|
81 | - unset($tmp_sanitized); |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - // Donate Link: URL |
|
87 | - if ( preg_match('|Donate link:(.*)|i', $file_contents, $_donate_link) ) |
|
88 | - $donate_link = esc_url( $_donate_link[1] ); |
|
89 | - else |
|
90 | - $donate_link = NULL; |
|
91 | - |
|
92 | - |
|
93 | - // togs, conts, etc are optional and order shouldn't matter. So we chop them only after we've grabbed their values. |
|
94 | - foreach ( array('tags', 'contributors', 'requires_at_least', 'tested_up_to', 'stable_tag', 'donate_link') as $chop ) { |
|
95 | - if ( $$chop ) { |
|
96 | - $_chop = '_' . $chop; |
|
97 | - $file_contents = $this->chop_string( $file_contents, ${$_chop}[0] ); |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - $file_contents = trim($file_contents); |
|
102 | - |
|
103 | - |
|
104 | - // short-description fu |
|
105 | - if ( !preg_match('/(^(.*?))^[\s]*=+?[\s]*.+?[\s]*=+?/ms', $file_contents, $_short_description) ) |
|
106 | - $_short_description = array( 1 => &$file_contents, 2 => &$file_contents ); |
|
107 | - $short_desc_filtered = $this->sanitize_text( $_short_description[2] ); |
|
108 | - $short_desc_length = strlen($short_desc_filtered); |
|
109 | - $short_description = substr($short_desc_filtered, 0, 150); |
|
110 | - if ( $short_desc_length > strlen($short_description) ) |
|
111 | - $truncated = true; |
|
112 | - else |
|
113 | - $truncated = false; |
|
114 | - if ( $_short_description[1] ) |
|
115 | - $file_contents = $this->chop_string( $file_contents, $_short_description[1] ); // yes, the [1] is intentional |
|
116 | - |
|
117 | - // == Section == |
|
118 | - // Break into sections |
|
119 | - // $_sections[0] will be the title of the first section, $_sections[1] will be the content of the first section |
|
120 | - // the array alternates from there: title2, content2, title3, content3... and so forth |
|
121 | - $_sections = preg_split('/^[\s]*==[\s]*(.+?)[\s]*==/m', $file_contents, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); |
|
122 | - |
|
123 | - $sections = array(); |
|
124 | - for ( $i=1; $i <= count($_sections); $i +=2 ) { |
|
125 | - $_sections[$i] = preg_replace('/(^[\s]*)=[\s]+(.+?)[\s]+=/m', '$1<h4>$2</h4>', $_sections[$i]); |
|
126 | - $_sections[$i] = $this->filter_text( $_sections[$i], true ); |
|
127 | - $title = $this->sanitize_text( $_sections[$i-1] ); |
|
128 | - $sections[str_replace(' ', '_', strtolower($title))] = array('title' => $title, 'content' => $_sections[$i]); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - // Special sections |
|
133 | - // This is where we nab our special sections, so we can enforce their order and treat them differently, if needed |
|
134 | - // upgrade_notice is not a section, but parse it like it is for now |
|
135 | - $final_sections = array(); |
|
136 | - foreach ( array('description', 'installation', 'frequently_asked_questions', 'screenshots', 'changelog', 'change_log', 'upgrade_notice') as $special_section ) { |
|
137 | - if ( isset($sections[$special_section]) ) { |
|
138 | - $final_sections[$special_section] = $sections[$special_section]['content']; |
|
139 | - unset($sections[$special_section]); |
|
140 | - } |
|
141 | - } |
|
142 | - if ( isset($final_sections['change_log']) && empty($final_sections['changelog']) ) |
|
143 | - $final_sections['changelog'] = $final_sections['change_log']; |
|
144 | - |
|
145 | - |
|
146 | - $final_screenshots = array(); |
|
147 | - if ( isset($final_sections['screenshots']) ) { |
|
148 | - preg_match_all('|<li>(.*?)</li>|s', $final_sections['screenshots'], $screenshots, PREG_SET_ORDER); |
|
149 | - if ( $screenshots ) { |
|
150 | - foreach ( (array) $screenshots as $ss ) |
|
151 | - $final_screenshots[] = $ss[1]; |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - // Parse the upgrade_notice section specially: |
|
156 | - // 1.0 => blah, 1.1 => fnord |
|
157 | - $upgrade_notice = array(); |
|
158 | - if ( isset($final_sections['upgrade_notice']) ) { |
|
159 | - $split = preg_split( '#<h4>(.*?)</h4>#', $final_sections['upgrade_notice'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ); |
|
160 | - for ( $i = 0; $i < count( $split ); $i += 2 ) |
|
161 | - $upgrade_notice[$this->sanitize_text( $split[$i] )] = substr( $this->sanitize_text( $split[$i + 1] ), 0, 300 ); |
|
162 | - unset( $final_sections['upgrade_notice'] ); |
|
163 | - } |
|
164 | - |
|
165 | - // No description? |
|
166 | - // No problem... we'll just fall back to the old style of description |
|
167 | - // We'll even let you use markup this time! |
|
168 | - $excerpt = false; |
|
169 | - if ( !isset($final_sections['description']) ) { |
|
170 | - $final_sections = array_merge(array('description' => $this->filter_text( $_short_description[2], true )), $final_sections); |
|
171 | - $excerpt = true; |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - // dump the non-special sections into $remaining_content |
|
176 | - // their order will be determined by their original order in the readme.txt |
|
177 | - $remaining_content = ''; |
|
178 | - foreach ( $sections as $s_name => $s_data ) { |
|
179 | - $remaining_content .= "\n<h3>{$s_data['title']}</h3>\n{$s_data['content']}"; |
|
180 | - } |
|
181 | - $remaining_content = trim($remaining_content); |
|
182 | - |
|
183 | - |
|
184 | - // All done! |
|
185 | - // $r['tags'] and $r['contributors'] are simple arrays |
|
186 | - // $r['sections'] is an array with named elements |
|
187 | - $r = array( |
|
188 | - 'name' => $name, |
|
189 | - 'tags' => $tags, |
|
190 | - 'requires_at_least' => $requires_at_least, |
|
191 | - 'tested_up_to' => $tested_up_to, |
|
192 | - 'stable_tag' => $stable_tag, |
|
193 | - 'contributors' => $contributors, |
|
194 | - 'donate_link' => $donate_link, |
|
195 | - 'short_description' => $short_description, |
|
196 | - 'screenshots' => $final_screenshots, |
|
197 | - 'is_excerpt' => $excerpt, |
|
198 | - 'is_truncated' => $truncated, |
|
199 | - 'sections' => $final_sections, |
|
200 | - 'remaining_content' => $remaining_content, |
|
201 | - 'upgrade_notice' => $upgrade_notice |
|
202 | - ); |
|
203 | - |
|
204 | - return $r; |
|
205 | - } |
|
206 | - |
|
207 | - function chop_string( $string, $chop ) { // chop a "prefix" from a string: Agressive! uses strstr not 0 === strpos |
|
208 | - if ( $_string = strstr($string, $chop) ) { |
|
209 | - $_string = substr($_string, strlen($chop)); |
|
210 | - return trim($_string); |
|
211 | - } else { |
|
212 | - return trim($string); |
|
213 | - } |
|
214 | - } |
|
215 | - |
|
216 | - function user_sanitize( $text, $strict = false ) { // whitelisted chars |
|
217 | - if ( function_exists('user_sanitize') ) // bbPress native |
|
218 | - return user_sanitize( $text, $strict ); |
|
219 | - |
|
220 | - if ( $strict ) { |
|
221 | - $text = preg_replace('/[^a-z0-9-]/i', '', $text); |
|
222 | - $text = preg_replace('|-+|', '-', $text); |
|
223 | - } else { |
|
224 | - $text = preg_replace('/[^a-z0-9_-]/i', '', $text); |
|
225 | - } |
|
226 | - return $text; |
|
227 | - } |
|
228 | - |
|
229 | - function sanitize_text( $text ) { // not fancy |
|
230 | - $text = strip_tags($text); |
|
231 | - $text = esc_html($text); |
|
232 | - $text = trim($text); |
|
233 | - return $text; |
|
234 | - } |
|
235 | - |
|
236 | - function filter_text( $text, $markdown = false ) { // fancy, Markdown |
|
237 | - $text = trim($text); |
|
238 | - |
|
239 | - $text = call_user_func( array( __CLASS__, 'code_trick' ), $text, $markdown ); // A better parser than Markdown's for: backticks -> CODE |
|
240 | - |
|
241 | - if ( $markdown ) { // Parse markdown. |
|
242 | - if ( !class_exists('Parsedown', false) ) { |
|
243 | - /** @noinspection PhpIncludeInspection */ |
|
244 | - require_once(dirname(__FILE__) . '/Parsedown' . (version_compare(PHP_VERSION, '5.3.0', '>=') ? '' : 'Legacy') . '.php'); |
|
245 | - } |
|
246 | - $instance = Parsedown::instance(); |
|
247 | - $text = $instance->text($text); |
|
248 | - } |
|
249 | - |
|
250 | - $allowed = array( |
|
251 | - 'a' => array( |
|
252 | - 'href' => array(), |
|
253 | - 'title' => array(), |
|
254 | - 'rel' => array()), |
|
255 | - 'blockquote' => array('cite' => array()), |
|
256 | - 'br' => array(), |
|
257 | - 'p' => array(), |
|
258 | - 'code' => array(), |
|
259 | - 'pre' => array(), |
|
260 | - 'em' => array(), |
|
261 | - 'strong' => array(), |
|
262 | - 'ul' => array(), |
|
263 | - 'ol' => array(), |
|
264 | - 'li' => array(), |
|
265 | - 'h3' => array(), |
|
266 | - 'h4' => array() |
|
267 | - ); |
|
268 | - |
|
269 | - $text = balanceTags($text); |
|
12 | + function __construct() { |
|
13 | + // This space intentionally blank |
|
14 | + } |
|
15 | + |
|
16 | + function parse_readme( $file ) { |
|
17 | + $file_contents = @implode('', @file($file)); |
|
18 | + return $this->parse_readme_contents( $file_contents ); |
|
19 | + } |
|
20 | + |
|
21 | + function parse_readme_contents( $file_contents ) { |
|
22 | + $file_contents = str_replace(array("\r\n", "\r"), "\n", $file_contents); |
|
23 | + $file_contents = trim($file_contents); |
|
24 | + if ( 0 === strpos( $file_contents, "\xEF\xBB\xBF" ) ) |
|
25 | + $file_contents = substr( $file_contents, 3 ); |
|
26 | + |
|
27 | + // Markdown transformations |
|
28 | + $file_contents = preg_replace( "|^###([^#]+)#*?\s*?\n|im", '=$1='."\n", $file_contents ); |
|
29 | + $file_contents = preg_replace( "|^##([^#]+)#*?\s*?\n|im", '==$1=='."\n", $file_contents ); |
|
30 | + $file_contents = preg_replace( "|^#([^#]+)#*?\s*?\n|im", '===$1==='."\n", $file_contents ); |
|
31 | + |
|
32 | + // === Plugin Name === |
|
33 | + // Must be the very first thing. |
|
34 | + if ( !preg_match('|^===(.*)===|', $file_contents, $_name) ) |
|
35 | + return array(); // require a name |
|
36 | + $name = trim($_name[1], '='); |
|
37 | + $name = $this->sanitize_text( $name ); |
|
38 | + |
|
39 | + $file_contents = $this->chop_string( $file_contents, $_name[0] ); |
|
40 | + |
|
41 | + |
|
42 | + // Requires at least: 1.5 |
|
43 | + if ( preg_match('|Requires at least:(.*)|i', $file_contents, $_requires_at_least) ) |
|
44 | + $requires_at_least = $this->sanitize_text($_requires_at_least[1]); |
|
45 | + else |
|
46 | + $requires_at_least = NULL; |
|
47 | + |
|
48 | + |
|
49 | + // Tested up to: 2.1 |
|
50 | + if ( preg_match('|Tested up to:(.*)|i', $file_contents, $_tested_up_to) ) |
|
51 | + $tested_up_to = $this->sanitize_text( $_tested_up_to[1] ); |
|
52 | + else |
|
53 | + $tested_up_to = NULL; |
|
54 | + |
|
55 | + |
|
56 | + // Stable tag: 10.4-ride-the-fire-eagle-danger-day |
|
57 | + if ( preg_match('|Stable tag:(.*)|i', $file_contents, $_stable_tag) ) |
|
58 | + $stable_tag = $this->sanitize_text( $_stable_tag[1] ); |
|
59 | + else |
|
60 | + $stable_tag = NULL; // we assume trunk, but don't set it here to tell the difference between specified trunk and default trunk |
|
61 | + |
|
62 | + |
|
63 | + // Tags: some tag, another tag, we like tags |
|
64 | + if ( preg_match('|Tags:(.*)|i', $file_contents, $_tags) ) { |
|
65 | + $tags = preg_split('|,[\s]*?|', trim($_tags[1])); |
|
66 | + foreach ( array_keys($tags) as $t ) |
|
67 | + $tags[$t] = $this->sanitize_text( $tags[$t] ); |
|
68 | + } else { |
|
69 | + $tags = array(); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + // Contributors: markjaquith, mdawaffe, zefrank |
|
74 | + $contributors = array(); |
|
75 | + if ( preg_match('|Contributors:(.*)|i', $file_contents, $_contributors) ) { |
|
76 | + $temp_contributors = preg_split('|,[\s]*|', trim($_contributors[1])); |
|
77 | + foreach ( array_keys($temp_contributors) as $c ) { |
|
78 | + $tmp_sanitized = $this->user_sanitize( $temp_contributors[$c] ); |
|
79 | + if ( strlen(trim($tmp_sanitized)) > 0 ) |
|
80 | + $contributors[$c] = $tmp_sanitized; |
|
81 | + unset($tmp_sanitized); |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + // Donate Link: URL |
|
87 | + if ( preg_match('|Donate link:(.*)|i', $file_contents, $_donate_link) ) |
|
88 | + $donate_link = esc_url( $_donate_link[1] ); |
|
89 | + else |
|
90 | + $donate_link = NULL; |
|
91 | + |
|
92 | + |
|
93 | + // togs, conts, etc are optional and order shouldn't matter. So we chop them only after we've grabbed their values. |
|
94 | + foreach ( array('tags', 'contributors', 'requires_at_least', 'tested_up_to', 'stable_tag', 'donate_link') as $chop ) { |
|
95 | + if ( $$chop ) { |
|
96 | + $_chop = '_' . $chop; |
|
97 | + $file_contents = $this->chop_string( $file_contents, ${$_chop}[0] ); |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + $file_contents = trim($file_contents); |
|
102 | + |
|
103 | + |
|
104 | + // short-description fu |
|
105 | + if ( !preg_match('/(^(.*?))^[\s]*=+?[\s]*.+?[\s]*=+?/ms', $file_contents, $_short_description) ) |
|
106 | + $_short_description = array( 1 => &$file_contents, 2 => &$file_contents ); |
|
107 | + $short_desc_filtered = $this->sanitize_text( $_short_description[2] ); |
|
108 | + $short_desc_length = strlen($short_desc_filtered); |
|
109 | + $short_description = substr($short_desc_filtered, 0, 150); |
|
110 | + if ( $short_desc_length > strlen($short_description) ) |
|
111 | + $truncated = true; |
|
112 | + else |
|
113 | + $truncated = false; |
|
114 | + if ( $_short_description[1] ) |
|
115 | + $file_contents = $this->chop_string( $file_contents, $_short_description[1] ); // yes, the [1] is intentional |
|
116 | + |
|
117 | + // == Section == |
|
118 | + // Break into sections |
|
119 | + // $_sections[0] will be the title of the first section, $_sections[1] will be the content of the first section |
|
120 | + // the array alternates from there: title2, content2, title3, content3... and so forth |
|
121 | + $_sections = preg_split('/^[\s]*==[\s]*(.+?)[\s]*==/m', $file_contents, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY); |
|
122 | + |
|
123 | + $sections = array(); |
|
124 | + for ( $i=1; $i <= count($_sections); $i +=2 ) { |
|
125 | + $_sections[$i] = preg_replace('/(^[\s]*)=[\s]+(.+?)[\s]+=/m', '$1<h4>$2</h4>', $_sections[$i]); |
|
126 | + $_sections[$i] = $this->filter_text( $_sections[$i], true ); |
|
127 | + $title = $this->sanitize_text( $_sections[$i-1] ); |
|
128 | + $sections[str_replace(' ', '_', strtolower($title))] = array('title' => $title, 'content' => $_sections[$i]); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + // Special sections |
|
133 | + // This is where we nab our special sections, so we can enforce their order and treat them differently, if needed |
|
134 | + // upgrade_notice is not a section, but parse it like it is for now |
|
135 | + $final_sections = array(); |
|
136 | + foreach ( array('description', 'installation', 'frequently_asked_questions', 'screenshots', 'changelog', 'change_log', 'upgrade_notice') as $special_section ) { |
|
137 | + if ( isset($sections[$special_section]) ) { |
|
138 | + $final_sections[$special_section] = $sections[$special_section]['content']; |
|
139 | + unset($sections[$special_section]); |
|
140 | + } |
|
141 | + } |
|
142 | + if ( isset($final_sections['change_log']) && empty($final_sections['changelog']) ) |
|
143 | + $final_sections['changelog'] = $final_sections['change_log']; |
|
144 | + |
|
145 | + |
|
146 | + $final_screenshots = array(); |
|
147 | + if ( isset($final_sections['screenshots']) ) { |
|
148 | + preg_match_all('|<li>(.*?)</li>|s', $final_sections['screenshots'], $screenshots, PREG_SET_ORDER); |
|
149 | + if ( $screenshots ) { |
|
150 | + foreach ( (array) $screenshots as $ss ) |
|
151 | + $final_screenshots[] = $ss[1]; |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + // Parse the upgrade_notice section specially: |
|
156 | + // 1.0 => blah, 1.1 => fnord |
|
157 | + $upgrade_notice = array(); |
|
158 | + if ( isset($final_sections['upgrade_notice']) ) { |
|
159 | + $split = preg_split( '#<h4>(.*?)</h4>#', $final_sections['upgrade_notice'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ); |
|
160 | + for ( $i = 0; $i < count( $split ); $i += 2 ) |
|
161 | + $upgrade_notice[$this->sanitize_text( $split[$i] )] = substr( $this->sanitize_text( $split[$i + 1] ), 0, 300 ); |
|
162 | + unset( $final_sections['upgrade_notice'] ); |
|
163 | + } |
|
164 | + |
|
165 | + // No description? |
|
166 | + // No problem... we'll just fall back to the old style of description |
|
167 | + // We'll even let you use markup this time! |
|
168 | + $excerpt = false; |
|
169 | + if ( !isset($final_sections['description']) ) { |
|
170 | + $final_sections = array_merge(array('description' => $this->filter_text( $_short_description[2], true )), $final_sections); |
|
171 | + $excerpt = true; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + // dump the non-special sections into $remaining_content |
|
176 | + // their order will be determined by their original order in the readme.txt |
|
177 | + $remaining_content = ''; |
|
178 | + foreach ( $sections as $s_name => $s_data ) { |
|
179 | + $remaining_content .= "\n<h3>{$s_data['title']}</h3>\n{$s_data['content']}"; |
|
180 | + } |
|
181 | + $remaining_content = trim($remaining_content); |
|
182 | + |
|
183 | + |
|
184 | + // All done! |
|
185 | + // $r['tags'] and $r['contributors'] are simple arrays |
|
186 | + // $r['sections'] is an array with named elements |
|
187 | + $r = array( |
|
188 | + 'name' => $name, |
|
189 | + 'tags' => $tags, |
|
190 | + 'requires_at_least' => $requires_at_least, |
|
191 | + 'tested_up_to' => $tested_up_to, |
|
192 | + 'stable_tag' => $stable_tag, |
|
193 | + 'contributors' => $contributors, |
|
194 | + 'donate_link' => $donate_link, |
|
195 | + 'short_description' => $short_description, |
|
196 | + 'screenshots' => $final_screenshots, |
|
197 | + 'is_excerpt' => $excerpt, |
|
198 | + 'is_truncated' => $truncated, |
|
199 | + 'sections' => $final_sections, |
|
200 | + 'remaining_content' => $remaining_content, |
|
201 | + 'upgrade_notice' => $upgrade_notice |
|
202 | + ); |
|
203 | + |
|
204 | + return $r; |
|
205 | + } |
|
206 | + |
|
207 | + function chop_string( $string, $chop ) { // chop a "prefix" from a string: Agressive! uses strstr not 0 === strpos |
|
208 | + if ( $_string = strstr($string, $chop) ) { |
|
209 | + $_string = substr($_string, strlen($chop)); |
|
210 | + return trim($_string); |
|
211 | + } else { |
|
212 | + return trim($string); |
|
213 | + } |
|
214 | + } |
|
215 | + |
|
216 | + function user_sanitize( $text, $strict = false ) { // whitelisted chars |
|
217 | + if ( function_exists('user_sanitize') ) // bbPress native |
|
218 | + return user_sanitize( $text, $strict ); |
|
219 | + |
|
220 | + if ( $strict ) { |
|
221 | + $text = preg_replace('/[^a-z0-9-]/i', '', $text); |
|
222 | + $text = preg_replace('|-+|', '-', $text); |
|
223 | + } else { |
|
224 | + $text = preg_replace('/[^a-z0-9_-]/i', '', $text); |
|
225 | + } |
|
226 | + return $text; |
|
227 | + } |
|
228 | + |
|
229 | + function sanitize_text( $text ) { // not fancy |
|
230 | + $text = strip_tags($text); |
|
231 | + $text = esc_html($text); |
|
232 | + $text = trim($text); |
|
233 | + return $text; |
|
234 | + } |
|
235 | + |
|
236 | + function filter_text( $text, $markdown = false ) { // fancy, Markdown |
|
237 | + $text = trim($text); |
|
238 | + |
|
239 | + $text = call_user_func( array( __CLASS__, 'code_trick' ), $text, $markdown ); // A better parser than Markdown's for: backticks -> CODE |
|
240 | + |
|
241 | + if ( $markdown ) { // Parse markdown. |
|
242 | + if ( !class_exists('Parsedown', false) ) { |
|
243 | + /** @noinspection PhpIncludeInspection */ |
|
244 | + require_once(dirname(__FILE__) . '/Parsedown' . (version_compare(PHP_VERSION, '5.3.0', '>=') ? '' : 'Legacy') . '.php'); |
|
245 | + } |
|
246 | + $instance = Parsedown::instance(); |
|
247 | + $text = $instance->text($text); |
|
248 | + } |
|
249 | + |
|
250 | + $allowed = array( |
|
251 | + 'a' => array( |
|
252 | + 'href' => array(), |
|
253 | + 'title' => array(), |
|
254 | + 'rel' => array()), |
|
255 | + 'blockquote' => array('cite' => array()), |
|
256 | + 'br' => array(), |
|
257 | + 'p' => array(), |
|
258 | + 'code' => array(), |
|
259 | + 'pre' => array(), |
|
260 | + 'em' => array(), |
|
261 | + 'strong' => array(), |
|
262 | + 'ul' => array(), |
|
263 | + 'ol' => array(), |
|
264 | + 'li' => array(), |
|
265 | + 'h3' => array(), |
|
266 | + 'h4' => array() |
|
267 | + ); |
|
268 | + |
|
269 | + $text = balanceTags($text); |
|
270 | 270 | |
271 | - $text = wp_kses( $text, $allowed ); |
|
272 | - $text = trim($text); |
|
273 | - return $text; |
|
274 | - } |
|
275 | - |
|
276 | - function code_trick( $text, $markdown ) { // Don't use bbPress native function - it's incompatible with Markdown |
|
277 | - // If doing markdown, first take any user formatted code blocks and turn them into backticks so that |
|
278 | - // markdown will preserve things like underscores in code blocks |
|
279 | - if ( $markdown ) |
|
280 | - $text = preg_replace_callback("!(<pre><code>|<code>)(.*?)(</code></pre>|</code>)!s", array( __CLASS__,'decodeit'), $text); |
|
281 | - |
|
282 | - $text = str_replace(array("\r\n", "\r"), "\n", $text); |
|
283 | - if ( !$markdown ) { |
|
284 | - // This gets the "inline" code blocks, but can't be used with Markdown. |
|
285 | - $text = preg_replace_callback("|(`)(.*?)`|", array( __CLASS__, 'encodeit'), $text); |
|
286 | - // This gets the "block level" code blocks and converts them to PRE CODE |
|
287 | - $text = preg_replace_callback("!(^|\n)`(.*?)`!s", array( __CLASS__, 'encodeit'), $text); |
|
288 | - } else { |
|
289 | - // Markdown can do inline code, we convert bbPress style block level code to Markdown style |
|
290 | - $text = preg_replace_callback("!(^|\n)([ \t]*?)`(.*?)`!s", array( __CLASS__, 'indent'), $text); |
|
291 | - } |
|
292 | - return $text; |
|
293 | - } |
|
294 | - |
|
295 | - function indent( $matches ) { |
|
296 | - $text = $matches[3]; |
|
297 | - $text = preg_replace('|^|m', $matches[2] . ' ', $text); |
|
298 | - return $matches[1] . $text; |
|
299 | - } |
|
300 | - |
|
301 | - function encodeit( $matches ) { |
|
302 | - if ( function_exists('encodeit') ) // bbPress native |
|
303 | - return encodeit( $matches ); |
|
304 | - |
|
305 | - $text = trim($matches[2]); |
|
306 | - $text = htmlspecialchars($text, ENT_QUOTES); |
|
307 | - $text = str_replace(array("\r\n", "\r"), "\n", $text); |
|
308 | - $text = preg_replace("|\n\n\n+|", "\n\n", $text); |
|
309 | - $text = str_replace('&lt;', '<', $text); |
|
310 | - $text = str_replace('&gt;', '>', $text); |
|
311 | - $text = "<code>$text</code>"; |
|
312 | - if ( "`" != $matches[1] ) |
|
313 | - $text = "<pre>$text</pre>"; |
|
314 | - return $text; |
|
315 | - } |
|
316 | - |
|
317 | - function decodeit( $matches ) { |
|
318 | - if ( function_exists('decodeit') ) // bbPress native |
|
319 | - return decodeit( $matches ); |
|
320 | - |
|
321 | - $text = $matches[2]; |
|
322 | - $trans_table = array_flip(get_html_translation_table(HTML_ENTITIES)); |
|
323 | - $text = strtr($text, $trans_table); |
|
324 | - $text = str_replace('<br />', '', $text); |
|
325 | - $text = str_replace('&', '&', $text); |
|
326 | - $text = str_replace(''', "'", $text); |
|
327 | - if ( '<pre><code>' == $matches[1] ) |
|
328 | - $text = "\n$text\n"; |
|
329 | - return "`$text`"; |
|
330 | - } |
|
271 | + $text = wp_kses( $text, $allowed ); |
|
272 | + $text = trim($text); |
|
273 | + return $text; |
|
274 | + } |
|
275 | + |
|
276 | + function code_trick( $text, $markdown ) { // Don't use bbPress native function - it's incompatible with Markdown |
|
277 | + // If doing markdown, first take any user formatted code blocks and turn them into backticks so that |
|
278 | + // markdown will preserve things like underscores in code blocks |
|
279 | + if ( $markdown ) |
|
280 | + $text = preg_replace_callback("!(<pre><code>|<code>)(.*?)(</code></pre>|</code>)!s", array( __CLASS__,'decodeit'), $text); |
|
281 | + |
|
282 | + $text = str_replace(array("\r\n", "\r"), "\n", $text); |
|
283 | + if ( !$markdown ) { |
|
284 | + // This gets the "inline" code blocks, but can't be used with Markdown. |
|
285 | + $text = preg_replace_callback("|(`)(.*?)`|", array( __CLASS__, 'encodeit'), $text); |
|
286 | + // This gets the "block level" code blocks and converts them to PRE CODE |
|
287 | + $text = preg_replace_callback("!(^|\n)`(.*?)`!s", array( __CLASS__, 'encodeit'), $text); |
|
288 | + } else { |
|
289 | + // Markdown can do inline code, we convert bbPress style block level code to Markdown style |
|
290 | + $text = preg_replace_callback("!(^|\n)([ \t]*?)`(.*?)`!s", array( __CLASS__, 'indent'), $text); |
|
291 | + } |
|
292 | + return $text; |
|
293 | + } |
|
294 | + |
|
295 | + function indent( $matches ) { |
|
296 | + $text = $matches[3]; |
|
297 | + $text = preg_replace('|^|m', $matches[2] . ' ', $text); |
|
298 | + return $matches[1] . $text; |
|
299 | + } |
|
300 | + |
|
301 | + function encodeit( $matches ) { |
|
302 | + if ( function_exists('encodeit') ) // bbPress native |
|
303 | + return encodeit( $matches ); |
|
304 | + |
|
305 | + $text = trim($matches[2]); |
|
306 | + $text = htmlspecialchars($text, ENT_QUOTES); |
|
307 | + $text = str_replace(array("\r\n", "\r"), "\n", $text); |
|
308 | + $text = preg_replace("|\n\n\n+|", "\n\n", $text); |
|
309 | + $text = str_replace('&lt;', '<', $text); |
|
310 | + $text = str_replace('&gt;', '>', $text); |
|
311 | + $text = "<code>$text</code>"; |
|
312 | + if ( "`" != $matches[1] ) |
|
313 | + $text = "<pre>$text</pre>"; |
|
314 | + return $text; |
|
315 | + } |
|
316 | + |
|
317 | + function decodeit( $matches ) { |
|
318 | + if ( function_exists('decodeit') ) // bbPress native |
|
319 | + return decodeit( $matches ); |
|
320 | + |
|
321 | + $text = $matches[2]; |
|
322 | + $trans_table = array_flip(get_html_translation_table(HTML_ENTITIES)); |
|
323 | + $text = strtr($text, $trans_table); |
|
324 | + $text = str_replace('<br />', '', $text); |
|
325 | + $text = str_replace('&', '&', $text); |
|
326 | + $text = str_replace(''', "'", $text); |
|
327 | + if ( '<pre><code>' == $matches[1] ) |
|
328 | + $text = "\n$text\n"; |
|
329 | + return "`$text`"; |
|
330 | + } |
|
331 | 331 | |
332 | 332 | } // end class |
333 | 333 |
@@ -21,8 +21,9 @@ discard block |
||
21 | 21 | function parse_readme_contents( $file_contents ) { |
22 | 22 | $file_contents = str_replace(array("\r\n", "\r"), "\n", $file_contents); |
23 | 23 | $file_contents = trim($file_contents); |
24 | - if ( 0 === strpos( $file_contents, "\xEF\xBB\xBF" ) ) |
|
25 | - $file_contents = substr( $file_contents, 3 ); |
|
24 | + if ( 0 === strpos( $file_contents, "\xEF\xBB\xBF" ) ) { |
|
25 | + $file_contents = substr( $file_contents, 3 ); |
|
26 | + } |
|
26 | 27 | |
27 | 28 | // Markdown transformations |
28 | 29 | $file_contents = preg_replace( "|^###([^#]+)#*?\s*?\n|im", '=$1='."\n", $file_contents ); |
@@ -31,8 +32,10 @@ discard block |
||
31 | 32 | |
32 | 33 | // === Plugin Name === |
33 | 34 | // Must be the very first thing. |
34 | - if ( !preg_match('|^===(.*)===|', $file_contents, $_name) ) |
|
35 | - return array(); // require a name |
|
35 | + if ( !preg_match('|^===(.*)===|', $file_contents, $_name) ) { |
|
36 | + return array(); |
|
37 | + } |
|
38 | + // require a name |
|
36 | 39 | $name = trim($_name[1], '='); |
37 | 40 | $name = $this->sanitize_text( $name ); |
38 | 41 | |
@@ -40,31 +43,36 @@ discard block |
||
40 | 43 | |
41 | 44 | |
42 | 45 | // Requires at least: 1.5 |
43 | - if ( preg_match('|Requires at least:(.*)|i', $file_contents, $_requires_at_least) ) |
|
44 | - $requires_at_least = $this->sanitize_text($_requires_at_least[1]); |
|
45 | - else |
|
46 | - $requires_at_least = NULL; |
|
46 | + if ( preg_match('|Requires at least:(.*)|i', $file_contents, $_requires_at_least) ) { |
|
47 | + $requires_at_least = $this->sanitize_text($_requires_at_least[1]); |
|
48 | + } else { |
|
49 | + $requires_at_least = NULL; |
|
50 | + } |
|
47 | 51 | |
48 | 52 | |
49 | 53 | // Tested up to: 2.1 |
50 | - if ( preg_match('|Tested up to:(.*)|i', $file_contents, $_tested_up_to) ) |
|
51 | - $tested_up_to = $this->sanitize_text( $_tested_up_to[1] ); |
|
52 | - else |
|
53 | - $tested_up_to = NULL; |
|
54 | + if ( preg_match('|Tested up to:(.*)|i', $file_contents, $_tested_up_to) ) { |
|
55 | + $tested_up_to = $this->sanitize_text( $_tested_up_to[1] ); |
|
56 | + } else { |
|
57 | + $tested_up_to = NULL; |
|
58 | + } |
|
54 | 59 | |
55 | 60 | |
56 | 61 | // Stable tag: 10.4-ride-the-fire-eagle-danger-day |
57 | - if ( preg_match('|Stable tag:(.*)|i', $file_contents, $_stable_tag) ) |
|
58 | - $stable_tag = $this->sanitize_text( $_stable_tag[1] ); |
|
59 | - else |
|
60 | - $stable_tag = NULL; // we assume trunk, but don't set it here to tell the difference between specified trunk and default trunk |
|
62 | + if ( preg_match('|Stable tag:(.*)|i', $file_contents, $_stable_tag) ) { |
|
63 | + $stable_tag = $this->sanitize_text( $_stable_tag[1] ); |
|
64 | + } else { |
|
65 | + $stable_tag = NULL; |
|
66 | + } |
|
67 | + // we assume trunk, but don't set it here to tell the difference between specified trunk and default trunk |
|
61 | 68 | |
62 | 69 | |
63 | 70 | // Tags: some tag, another tag, we like tags |
64 | 71 | if ( preg_match('|Tags:(.*)|i', $file_contents, $_tags) ) { |
65 | 72 | $tags = preg_split('|,[\s]*?|', trim($_tags[1])); |
66 | - foreach ( array_keys($tags) as $t ) |
|
67 | - $tags[$t] = $this->sanitize_text( $tags[$t] ); |
|
73 | + foreach ( array_keys($tags) as $t ) { |
|
74 | + $tags[$t] = $this->sanitize_text( $tags[$t] ); |
|
75 | + } |
|
68 | 76 | } else { |
69 | 77 | $tags = array(); |
70 | 78 | } |
@@ -76,18 +84,20 @@ discard block |
||
76 | 84 | $temp_contributors = preg_split('|,[\s]*|', trim($_contributors[1])); |
77 | 85 | foreach ( array_keys($temp_contributors) as $c ) { |
78 | 86 | $tmp_sanitized = $this->user_sanitize( $temp_contributors[$c] ); |
79 | - if ( strlen(trim($tmp_sanitized)) > 0 ) |
|
80 | - $contributors[$c] = $tmp_sanitized; |
|
87 | + if ( strlen(trim($tmp_sanitized)) > 0 ) { |
|
88 | + $contributors[$c] = $tmp_sanitized; |
|
89 | + } |
|
81 | 90 | unset($tmp_sanitized); |
82 | 91 | } |
83 | 92 | } |
84 | 93 | |
85 | 94 | |
86 | 95 | // Donate Link: URL |
87 | - if ( preg_match('|Donate link:(.*)|i', $file_contents, $_donate_link) ) |
|
88 | - $donate_link = esc_url( $_donate_link[1] ); |
|
89 | - else |
|
90 | - $donate_link = NULL; |
|
96 | + if ( preg_match('|Donate link:(.*)|i', $file_contents, $_donate_link) ) { |
|
97 | + $donate_link = esc_url( $_donate_link[1] ); |
|
98 | + } else { |
|
99 | + $donate_link = NULL; |
|
100 | + } |
|
91 | 101 | |
92 | 102 | |
93 | 103 | // togs, conts, etc are optional and order shouldn't matter. So we chop them only after we've grabbed their values. |
@@ -102,17 +112,21 @@ discard block |
||
102 | 112 | |
103 | 113 | |
104 | 114 | // short-description fu |
105 | - if ( !preg_match('/(^(.*?))^[\s]*=+?[\s]*.+?[\s]*=+?/ms', $file_contents, $_short_description) ) |
|
106 | - $_short_description = array( 1 => &$file_contents, 2 => &$file_contents ); |
|
115 | + if ( !preg_match('/(^(.*?))^[\s]*=+?[\s]*.+?[\s]*=+?/ms', $file_contents, $_short_description) ) { |
|
116 | + $_short_description = array( 1 => &$file_contents, 2 => &$file_contents ); |
|
117 | + } |
|
107 | 118 | $short_desc_filtered = $this->sanitize_text( $_short_description[2] ); |
108 | 119 | $short_desc_length = strlen($short_desc_filtered); |
109 | 120 | $short_description = substr($short_desc_filtered, 0, 150); |
110 | - if ( $short_desc_length > strlen($short_description) ) |
|
111 | - $truncated = true; |
|
112 | - else |
|
113 | - $truncated = false; |
|
114 | - if ( $_short_description[1] ) |
|
115 | - $file_contents = $this->chop_string( $file_contents, $_short_description[1] ); // yes, the [1] is intentional |
|
121 | + if ( $short_desc_length > strlen($short_description) ) { |
|
122 | + $truncated = true; |
|
123 | + } else { |
|
124 | + $truncated = false; |
|
125 | + } |
|
126 | + if ( $_short_description[1] ) { |
|
127 | + $file_contents = $this->chop_string( $file_contents, $_short_description[1] ); |
|
128 | + } |
|
129 | + // yes, the [1] is intentional |
|
116 | 130 | |
117 | 131 | // == Section == |
118 | 132 | // Break into sections |
@@ -139,16 +153,18 @@ discard block |
||
139 | 153 | unset($sections[$special_section]); |
140 | 154 | } |
141 | 155 | } |
142 | - if ( isset($final_sections['change_log']) && empty($final_sections['changelog']) ) |
|
143 | - $final_sections['changelog'] = $final_sections['change_log']; |
|
156 | + if ( isset($final_sections['change_log']) && empty($final_sections['changelog']) ) { |
|
157 | + $final_sections['changelog'] = $final_sections['change_log']; |
|
158 | + } |
|
144 | 159 | |
145 | 160 | |
146 | 161 | $final_screenshots = array(); |
147 | 162 | if ( isset($final_sections['screenshots']) ) { |
148 | 163 | preg_match_all('|<li>(.*?)</li>|s', $final_sections['screenshots'], $screenshots, PREG_SET_ORDER); |
149 | 164 | if ( $screenshots ) { |
150 | - foreach ( (array) $screenshots as $ss ) |
|
151 | - $final_screenshots[] = $ss[1]; |
|
165 | + foreach ( (array) $screenshots as $ss ) { |
|
166 | + $final_screenshots[] = $ss[1]; |
|
167 | + } |
|
152 | 168 | } |
153 | 169 | } |
154 | 170 | |
@@ -157,8 +173,9 @@ discard block |
||
157 | 173 | $upgrade_notice = array(); |
158 | 174 | if ( isset($final_sections['upgrade_notice']) ) { |
159 | 175 | $split = preg_split( '#<h4>(.*?)</h4>#', $final_sections['upgrade_notice'], -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ); |
160 | - for ( $i = 0; $i < count( $split ); $i += 2 ) |
|
161 | - $upgrade_notice[$this->sanitize_text( $split[$i] )] = substr( $this->sanitize_text( $split[$i + 1] ), 0, 300 ); |
|
176 | + for ( $i = 0; $i < count( $split ); $i += 2 ) { |
|
177 | + $upgrade_notice[$this->sanitize_text( $split[$i] )] = substr( $this->sanitize_text( $split[$i + 1] ), 0, 300 ); |
|
178 | + } |
|
162 | 179 | unset( $final_sections['upgrade_notice'] ); |
163 | 180 | } |
164 | 181 | |
@@ -214,8 +231,10 @@ discard block |
||
214 | 231 | } |
215 | 232 | |
216 | 233 | function user_sanitize( $text, $strict = false ) { // whitelisted chars |
217 | - if ( function_exists('user_sanitize') ) // bbPress native |
|
234 | + if ( function_exists('user_sanitize') ) { |
|
235 | + // bbPress native |
|
218 | 236 | return user_sanitize( $text, $strict ); |
237 | + } |
|
219 | 238 | |
220 | 239 | if ( $strict ) { |
221 | 240 | $text = preg_replace('/[^a-z0-9-]/i', '', $text); |
@@ -276,8 +295,9 @@ discard block |
||
276 | 295 | function code_trick( $text, $markdown ) { // Don't use bbPress native function - it's incompatible with Markdown |
277 | 296 | // If doing markdown, first take any user formatted code blocks and turn them into backticks so that |
278 | 297 | // markdown will preserve things like underscores in code blocks |
279 | - if ( $markdown ) |
|
280 | - $text = preg_replace_callback("!(<pre><code>|<code>)(.*?)(</code></pre>|</code>)!s", array( __CLASS__,'decodeit'), $text); |
|
298 | + if ( $markdown ) { |
|
299 | + $text = preg_replace_callback("!(<pre><code>|<code>)(.*?)(</code></pre>|</code>)!s", array( __CLASS__,'decodeit'), $text); |
|
300 | + } |
|
281 | 301 | |
282 | 302 | $text = str_replace(array("\r\n", "\r"), "\n", $text); |
283 | 303 | if ( !$markdown ) { |
@@ -299,8 +319,10 @@ discard block |
||
299 | 319 | } |
300 | 320 | |
301 | 321 | function encodeit( $matches ) { |
302 | - if ( function_exists('encodeit') ) // bbPress native |
|
322 | + if ( function_exists('encodeit') ) { |
|
323 | + // bbPress native |
|
303 | 324 | return encodeit( $matches ); |
325 | + } |
|
304 | 326 | |
305 | 327 | $text = trim($matches[2]); |
306 | 328 | $text = htmlspecialchars($text, ENT_QUOTES); |
@@ -309,14 +331,17 @@ discard block |
||
309 | 331 | $text = str_replace('&lt;', '<', $text); |
310 | 332 | $text = str_replace('&gt;', '>', $text); |
311 | 333 | $text = "<code>$text</code>"; |
312 | - if ( "`" != $matches[1] ) |
|
313 | - $text = "<pre>$text</pre>"; |
|
334 | + if ( "`" != $matches[1] ) { |
|
335 | + $text = "<pre>$text</pre>"; |
|
336 | + } |
|
314 | 337 | return $text; |
315 | 338 | } |
316 | 339 | |
317 | 340 | function decodeit( $matches ) { |
318 | - if ( function_exists('decodeit') ) // bbPress native |
|
341 | + if ( function_exists('decodeit') ) { |
|
342 | + // bbPress native |
|
319 | 343 | return decodeit( $matches ); |
344 | + } |
|
320 | 345 | |
321 | 346 | $text = $matches[2]; |
322 | 347 | $trans_table = array_flip(get_html_translation_table(HTML_ENTITIES)); |
@@ -324,8 +349,9 @@ discard block |
||
324 | 349 | $text = str_replace('<br />', '', $text); |
325 | 350 | $text = str_replace('&', '&', $text); |
326 | 351 | $text = str_replace(''', "'", $text); |
327 | - if ( '<pre><code>' == $matches[1] ) |
|
328 | - $text = "\n$text\n"; |
|
352 | + if ( '<pre><code>' == $matches[1] ) { |
|
353 | + $text = "\n$text\n"; |
|
354 | + } |
|
329 | 355 | return "`$text`"; |
330 | 356 | } |
331 | 357 |
@@ -2,68 +2,68 @@ |
||
2 | 2 | |
3 | 3 | if ( !class_exists('Puc_v4p4_Utils', false) ): |
4 | 4 | |
5 | - class Puc_v4p4_Utils { |
|
6 | - /** |
|
7 | - * Get a value from a nested array or object based on a path. |
|
8 | - * |
|
9 | - * @param array|object|null $collection Get an entry from this array. |
|
10 | - * @param array|string $path A list of array keys in hierarchy order, or a string path like "foo.bar.baz". |
|
11 | - * @param mixed $default The value to return if the specified path is not found. |
|
12 | - * @param string $separator Path element separator. Only applies to string paths. |
|
13 | - * @return mixed |
|
14 | - */ |
|
15 | - public static function get($collection, $path, $default = null, $separator = '.') { |
|
16 | - if ( is_string($path) ) { |
|
17 | - $path = explode($separator, $path); |
|
18 | - } |
|
5 | + class Puc_v4p4_Utils { |
|
6 | + /** |
|
7 | + * Get a value from a nested array or object based on a path. |
|
8 | + * |
|
9 | + * @param array|object|null $collection Get an entry from this array. |
|
10 | + * @param array|string $path A list of array keys in hierarchy order, or a string path like "foo.bar.baz". |
|
11 | + * @param mixed $default The value to return if the specified path is not found. |
|
12 | + * @param string $separator Path element separator. Only applies to string paths. |
|
13 | + * @return mixed |
|
14 | + */ |
|
15 | + public static function get($collection, $path, $default = null, $separator = '.') { |
|
16 | + if ( is_string($path) ) { |
|
17 | + $path = explode($separator, $path); |
|
18 | + } |
|
19 | 19 | |
20 | - //Follow the $path into $input as far as possible. |
|
21 | - $currentValue = $collection; |
|
22 | - foreach ($path as $node) { |
|
23 | - if ( is_array($currentValue) && isset($currentValue[$node]) ) { |
|
24 | - $currentValue = $currentValue[$node]; |
|
25 | - } else if ( is_object($currentValue) && isset($currentValue->$node) ) { |
|
26 | - $currentValue = $currentValue->$node; |
|
27 | - } else { |
|
28 | - return $default; |
|
29 | - } |
|
30 | - } |
|
20 | + //Follow the $path into $input as far as possible. |
|
21 | + $currentValue = $collection; |
|
22 | + foreach ($path as $node) { |
|
23 | + if ( is_array($currentValue) && isset($currentValue[$node]) ) { |
|
24 | + $currentValue = $currentValue[$node]; |
|
25 | + } else if ( is_object($currentValue) && isset($currentValue->$node) ) { |
|
26 | + $currentValue = $currentValue->$node; |
|
27 | + } else { |
|
28 | + return $default; |
|
29 | + } |
|
30 | + } |
|
31 | 31 | |
32 | - return $currentValue; |
|
33 | - } |
|
32 | + return $currentValue; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Get the first array element that is not empty. |
|
37 | - * |
|
38 | - * @param array $values |
|
39 | - * @param mixed|null $default Returns this value if there are no non-empty elements. |
|
40 | - * @return mixed|null |
|
41 | - */ |
|
42 | - public static function findNotEmpty($values, $default = null) { |
|
43 | - if ( empty($values) ) { |
|
44 | - return $default; |
|
45 | - } |
|
35 | + /** |
|
36 | + * Get the first array element that is not empty. |
|
37 | + * |
|
38 | + * @param array $values |
|
39 | + * @param mixed|null $default Returns this value if there are no non-empty elements. |
|
40 | + * @return mixed|null |
|
41 | + */ |
|
42 | + public static function findNotEmpty($values, $default = null) { |
|
43 | + if ( empty($values) ) { |
|
44 | + return $default; |
|
45 | + } |
|
46 | 46 | |
47 | - foreach ($values as $value) { |
|
48 | - if ( !empty($value) ) { |
|
49 | - return $value; |
|
50 | - } |
|
51 | - } |
|
47 | + foreach ($values as $value) { |
|
48 | + if ( !empty($value) ) { |
|
49 | + return $value; |
|
50 | + } |
|
51 | + } |
|
52 | 52 | |
53 | - return $default; |
|
54 | - } |
|
53 | + return $default; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Check if the input string starts with the specified prefix. |
|
58 | - * |
|
59 | - * @param string $input |
|
60 | - * @param string $prefix |
|
61 | - * @return bool |
|
62 | - */ |
|
63 | - public static function startsWith($input, $prefix) { |
|
64 | - $length = strlen($prefix); |
|
65 | - return (substr($input, 0, $length) === $prefix); |
|
66 | - } |
|
67 | - } |
|
56 | + /** |
|
57 | + * Check if the input string starts with the specified prefix. |
|
58 | + * |
|
59 | + * @param string $input |
|
60 | + * @param string $prefix |
|
61 | + * @return bool |
|
62 | + */ |
|
63 | + public static function startsWith($input, $prefix) { |
|
64 | + $length = strlen($prefix); |
|
65 | + return (substr($input, 0, $length) === $prefix); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | 69 | endif; |
70 | 70 | \ No newline at end of file |
@@ -1,27 +1,27 @@ |
||
1 | 1 | <?php |
2 | 2 | if ( !interface_exists('Puc_v4p4_Vcs_BaseChecker', false) ): |
3 | 3 | |
4 | - interface Puc_v4p4_Vcs_BaseChecker { |
|
5 | - /** |
|
6 | - * Set the repository branch to use for updates. Defaults to 'master'. |
|
7 | - * |
|
8 | - * @param string $branch |
|
9 | - * @return $this |
|
10 | - */ |
|
11 | - public function setBranch($branch); |
|
4 | + interface Puc_v4p4_Vcs_BaseChecker { |
|
5 | + /** |
|
6 | + * Set the repository branch to use for updates. Defaults to 'master'. |
|
7 | + * |
|
8 | + * @param string $branch |
|
9 | + * @return $this |
|
10 | + */ |
|
11 | + public function setBranch($branch); |
|
12 | 12 | |
13 | - /** |
|
14 | - * Set authentication credentials. |
|
15 | - * |
|
16 | - * @param array|string $credentials |
|
17 | - * @return $this |
|
18 | - */ |
|
19 | - public function setAuthentication($credentials); |
|
13 | + /** |
|
14 | + * Set authentication credentials. |
|
15 | + * |
|
16 | + * @param array|string $credentials |
|
17 | + * @return $this |
|
18 | + */ |
|
19 | + public function setAuthentication($credentials); |
|
20 | 20 | |
21 | - /** |
|
22 | - * @return Puc_v4p4_Vcs_Api |
|
23 | - */ |
|
24 | - public function getVcsApi(); |
|
25 | - } |
|
21 | + /** |
|
22 | + * @return Puc_v4p4_Vcs_Api |
|
23 | + */ |
|
24 | + public function getVcsApi(); |
|
25 | + } |
|
26 | 26 | |
27 | 27 | endif; |
28 | 28 | \ No newline at end of file |