@@ -113,8 +113,7 @@ discard block |
||
113 | 113 | if ($this->name !== null) |
114 | 114 | { |
115 | 115 | return $this->name; |
116 | - } |
|
117 | - else |
|
116 | + } else |
|
118 | 117 | { |
119 | 118 | return null; |
120 | 119 | } |
@@ -130,8 +129,7 @@ discard block |
||
130 | 129 | if ($this->link !== null) |
131 | 130 | { |
132 | 131 | return $this->link; |
133 | - } |
|
134 | - else |
|
132 | + } else |
|
135 | 133 | { |
136 | 134 | return null; |
137 | 135 | } |
@@ -147,8 +145,7 @@ discard block |
||
147 | 145 | if ($this->email !== null) |
148 | 146 | { |
149 | 147 | return $this->email; |
150 | - } |
|
151 | - else |
|
148 | + } else |
|
152 | 149 | { |
153 | 150 | return null; |
154 | 151 | } |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function register($type, $class, $legacy = false) |
115 | 115 | { |
116 | - if (!is_subclass_of($class, $this->default[$type])) |
|
116 | + if ( ! is_subclass_of($class, $this->default[$type])) |
|
117 | 117 | { |
118 | 118 | return false; |
119 | 119 | } |
@@ -138,11 +138,11 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function get_class($type) |
140 | 140 | { |
141 | - if (!empty($this->classes[$type])) |
|
141 | + if ( ! empty($this->classes[$type])) |
|
142 | 142 | { |
143 | 143 | return $this->classes[$type]; |
144 | 144 | } |
145 | - if (!empty($this->default[$type])) |
|
145 | + if ( ! empty($this->default[$type])) |
|
146 | 146 | { |
147 | 147 | return $this->default[$type]; |
148 | 148 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | } |
175 | 175 | } |
176 | 176 | |
177 | - if (!method_exists($class, '__construct')) |
|
177 | + if ( ! method_exists($class, '__construct')) |
|
178 | 178 | { |
179 | 179 | $instance = new $class; |
180 | 180 | } |
@@ -177,8 +177,7 @@ |
||
177 | 177 | if (!method_exists($class, '__construct')) |
178 | 178 | { |
179 | 179 | $instance = new $class; |
180 | - } |
|
181 | - else |
|
180 | + } else |
|
182 | 181 | { |
183 | 182 | $reflector = new ReflectionClass($class); |
184 | 183 | $instance = $reflector->newInstanceArgs($parameters); |
@@ -75,8 +75,9 @@ discard block |
||
75 | 75 | public function maybe_run_ajax_cache() { |
76 | 76 | $post = get_post(); |
77 | 77 | |
78 | - if ( ! $post || empty( $_GET['message'] ) ) |
|
79 | - return; |
|
78 | + if ( ! $post || empty( $_GET['message'] ) ) { |
|
79 | + return; |
|
80 | + } |
|
80 | 81 | |
81 | 82 | ?> |
82 | 83 | <script type="text/javascript"> |
@@ -157,8 +158,8 @@ discard block |
||
157 | 158 | foreach ( $this->handlers as $priority => $handlers ) { |
158 | 159 | foreach ( $handlers as $id => $handler ) { |
159 | 160 | if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) { |
160 | - if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) |
|
161 | - /** |
|
161 | + if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) { |
|
162 | + /** |
|
162 | 163 | * Filter the returned embed handler. |
163 | 164 | * |
164 | 165 | * @since 2.9.0 |
@@ -170,13 +171,16 @@ discard block |
||
170 | 171 | * @param array $attr An array of shortcode attributes. |
171 | 172 | */ |
172 | 173 | return apply_filters( 'embed_handler_html', $return, $url, $attr ); |
174 | + } |
|
173 | 175 | } |
174 | 176 | } |
175 | 177 | } |
176 | 178 | |
177 | 179 | $post_ID = ( ! empty( $post->ID ) ) ? $post->ID : null; |
178 | - if ( ! empty( $this->post_ID ) ) // Potentially set by WP_Embed::cache_oembed() |
|
180 | + if ( ! empty( $this->post_ID ) ) { |
|
181 | + // Potentially set by WP_Embed::cache_oembed() |
|
179 | 182 | $post_ID = $this->post_ID; |
183 | + } |
|
180 | 184 | |
181 | 185 | // Unknown URL format. Let oEmbed have a go. |
182 | 186 | if ( $post_ID ) { |
@@ -209,8 +213,9 @@ discard block |
||
209 | 213 | |
210 | 214 | if ( $this->usecache || $cached_recently ) { |
211 | 215 | // Failures are cached. Serve one if we're using the cache. |
212 | - if ( '{{unknown}}' === $cache ) |
|
213 | - return $this->maybe_make_link( $url ); |
|
216 | + if ( '{{unknown}}' === $cache ) { |
|
217 | + return $this->maybe_make_link( $url ); |
|
218 | + } |
|
214 | 219 | |
215 | 220 | if ( ! empty( $cache ) ) { |
216 | 221 | /** |
@@ -269,12 +274,14 @@ discard block |
||
269 | 274 | */ |
270 | 275 | public function delete_oembed_caches( $post_ID ) { |
271 | 276 | $post_metas = get_post_custom_keys( $post_ID ); |
272 | - if ( empty($post_metas) ) |
|
273 | - return; |
|
277 | + if ( empty($post_metas) ) { |
|
278 | + return; |
|
279 | + } |
|
274 | 280 | |
275 | 281 | foreach( $post_metas as $post_meta_key ) { |
276 | - if ( '_oembed_' == substr( $post_meta_key, 0, 8 ) ) |
|
277 | - delete_post_meta( $post_ID, $post_meta_key ); |
|
282 | + if ( '_oembed_' == substr( $post_meta_key, 0, 8 ) ) { |
|
283 | + delete_post_meta( $post_ID, $post_meta_key ); |
|
284 | + } |
|
278 | 285 | } |
279 | 286 | } |
280 | 287 |
@@ -30,17 +30,17 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function __construct() { |
32 | 32 | // Hack to get the [embed] shortcode to run before wpautop() |
33 | - add_filter( 'the_content', array( $this, 'run_shortcode' ), 8 ); |
|
33 | + add_filter('the_content', array($this, 'run_shortcode'), 8); |
|
34 | 34 | |
35 | 35 | // Shortcode placeholder for strip_shortcodes() |
36 | - add_shortcode( 'embed', '__return_false' ); |
|
36 | + add_shortcode('embed', '__return_false'); |
|
37 | 37 | |
38 | 38 | // Attempts to embed all URLs in a post |
39 | - add_filter( 'the_content', array( $this, 'autoembed' ), 8 ); |
|
39 | + add_filter('the_content', array($this, 'autoembed'), 8); |
|
40 | 40 | |
41 | 41 | // After a post is saved, cache oEmbed items via AJAX |
42 | - add_action( 'edit_form_advanced', array( $this, 'maybe_run_ajax_cache' ) ); |
|
43 | - add_action( 'edit_page_form', array( $this, 'maybe_run_ajax_cache' ) ); |
|
42 | + add_action('edit_form_advanced', array($this, 'maybe_run_ajax_cache')); |
|
43 | + add_action('edit_page_form', array($this, 'maybe_run_ajax_cache')); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
@@ -55,17 +55,17 @@ discard block |
||
55 | 55 | * @param string $content Content to parse |
56 | 56 | * @return string Content with shortcode parsed |
57 | 57 | */ |
58 | - public function run_shortcode( $content ) { |
|
58 | + public function run_shortcode($content) { |
|
59 | 59 | global $shortcode_tags; |
60 | 60 | |
61 | 61 | // Back up current registered shortcodes and clear them all out |
62 | 62 | $orig_shortcode_tags = $shortcode_tags; |
63 | 63 | remove_all_shortcodes(); |
64 | 64 | |
65 | - add_shortcode( 'embed', array( $this, 'shortcode' ) ); |
|
65 | + add_shortcode('embed', array($this, 'shortcode')); |
|
66 | 66 | |
67 | 67 | // Do the shortcode (only the [embed] one is registered) |
68 | - $content = do_shortcode( $content, true ); |
|
68 | + $content = do_shortcode($content, true); |
|
69 | 69 | |
70 | 70 | // Put the original shortcodes back |
71 | 71 | $shortcode_tags = $orig_shortcode_tags; |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | public function maybe_run_ajax_cache() { |
81 | 81 | $post = get_post(); |
82 | 82 | |
83 | - if ( ! $post || empty( $_GET['message'] ) ) |
|
83 | + if ( ! $post || empty($_GET['message'])) |
|
84 | 84 | return; |
85 | 85 | |
86 | 86 | ?> |
87 | 87 | <script type="text/javascript"> |
88 | 88 | jQuery(document).ready(function($){ |
89 | - $.get("<?php echo admin_url( 'admin-ajax.php?action=oembed-cache&post=' . $post->ID, 'relative' ); ?>"); |
|
89 | + $.get("<?php echo admin_url('admin-ajax.php?action=oembed-cache&post='.$post->ID, 'relative'); ?>"); |
|
90 | 90 | }); |
91 | 91 | </script> |
92 | 92 | <?php |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @param callable $callback The callback function that will be called if the regex is matched. |
105 | 105 | * @param int $priority Optional. Used to specify the order in which the registered handlers will be tested (default: 10). Lower numbers correspond with earlier testing, and handlers with the same priority are tested in the order in which they were added to the action. |
106 | 106 | */ |
107 | - public function register_handler( $id, $regex, $callback, $priority = 10 ) { |
|
107 | + public function register_handler($id, $regex, $callback, $priority = 10) { |
|
108 | 108 | $this->handlers[$priority][$id] = array( |
109 | 109 | 'regex' => $regex, |
110 | 110 | 'callback' => $callback, |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | * @param string $id The handler ID that should be removed. |
120 | 120 | * @param int $priority Optional. The priority of the handler to be removed (default: 10). |
121 | 121 | */ |
122 | - public function unregister_handler( $id, $priority = 10 ) { |
|
123 | - unset( $this->handlers[ $priority ][ $id ] ); |
|
122 | + public function unregister_handler($id, $priority = 10) { |
|
123 | + unset($this->handlers[$priority][$id]); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -140,35 +140,35 @@ discard block |
||
140 | 140 | * @return string|false The embed HTML on success, otherwise the original URL. |
141 | 141 | * `->maybe_make_link()` can return false on failure. |
142 | 142 | */ |
143 | - public function shortcode( $attr, $url = '' ) { |
|
143 | + public function shortcode($attr, $url = '') { |
|
144 | 144 | $post = get_post(); |
145 | 145 | |
146 | - if ( empty( $url ) && ! empty( $attr['src'] ) ) { |
|
146 | + if (empty($url) && ! empty($attr['src'])) { |
|
147 | 147 | $url = $attr['src']; |
148 | 148 | } |
149 | 149 | |
150 | 150 | $this->last_url = $url; |
151 | 151 | |
152 | - if ( empty( $url ) ) { |
|
152 | + if (empty($url)) { |
|
153 | 153 | $this->last_attr = $attr; |
154 | 154 | return ''; |
155 | 155 | } |
156 | 156 | |
157 | 157 | $rawattr = $attr; |
158 | - $attr = wp_parse_args( $attr, wp_embed_defaults( $url ) ); |
|
158 | + $attr = wp_parse_args($attr, wp_embed_defaults($url)); |
|
159 | 159 | |
160 | 160 | $this->last_attr = $attr; |
161 | 161 | |
162 | 162 | // kses converts & into & and we need to undo this |
163 | 163 | // See https://core.trac.wordpress.org/ticket/11311 |
164 | - $url = str_replace( '&', '&', $url ); |
|
164 | + $url = str_replace('&', '&', $url); |
|
165 | 165 | |
166 | 166 | // Look for known internal handlers |
167 | - ksort( $this->handlers ); |
|
168 | - foreach ( $this->handlers as $priority => $handlers ) { |
|
169 | - foreach ( $handlers as $id => $handler ) { |
|
170 | - if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) { |
|
171 | - if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) |
|
167 | + ksort($this->handlers); |
|
168 | + foreach ($this->handlers as $priority => $handlers) { |
|
169 | + foreach ($handlers as $id => $handler) { |
|
170 | + if (preg_match($handler['regex'], $url, $matches) && is_callable($handler['callback'])) { |
|
171 | + if (false !== $return = call_user_func($handler['callback'], $matches, $attr, $url, $rawattr)) |
|
172 | 172 | /** |
173 | 173 | * Filters the returned embed handler. |
174 | 174 | * |
@@ -180,22 +180,22 @@ discard block |
||
180 | 180 | * @param string $url The attempted embed URL. |
181 | 181 | * @param array $attr An array of shortcode attributes. |
182 | 182 | */ |
183 | - return apply_filters( 'embed_handler_html', $return, $url, $attr ); |
|
183 | + return apply_filters('embed_handler_html', $return, $url, $attr); |
|
184 | 184 | } |
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
188 | - $post_ID = ( ! empty( $post->ID ) ) ? $post->ID : null; |
|
189 | - if ( ! empty( $this->post_ID ) ) // Potentially set by WP_Embed::cache_oembed() |
|
188 | + $post_ID = ( ! empty($post->ID)) ? $post->ID : null; |
|
189 | + if ( ! empty($this->post_ID)) // Potentially set by WP_Embed::cache_oembed() |
|
190 | 190 | $post_ID = $this->post_ID; |
191 | 191 | |
192 | 192 | // Unknown URL format. Let oEmbed have a go. |
193 | - if ( $post_ID ) { |
|
193 | + if ($post_ID) { |
|
194 | 194 | |
195 | 195 | // Check for a cached result (stored in the post meta) |
196 | - $key_suffix = md5( $url . serialize( $attr ) ); |
|
197 | - $cachekey = '_oembed_' . $key_suffix; |
|
198 | - $cachekey_time = '_oembed_time_' . $key_suffix; |
|
196 | + $key_suffix = md5($url.serialize($attr)); |
|
197 | + $cachekey = '_oembed_'.$key_suffix; |
|
198 | + $cachekey_time = '_oembed_time_'.$key_suffix; |
|
199 | 199 | |
200 | 200 | /** |
201 | 201 | * Filters the oEmbed TTL value (time to live). |
@@ -207,23 +207,23 @@ discard block |
||
207 | 207 | * @param array $attr An array of shortcode attributes. |
208 | 208 | * @param int $post_ID Post ID. |
209 | 209 | */ |
210 | - $ttl = apply_filters( 'oembed_ttl', DAY_IN_SECONDS, $url, $attr, $post_ID ); |
|
210 | + $ttl = apply_filters('oembed_ttl', DAY_IN_SECONDS, $url, $attr, $post_ID); |
|
211 | 211 | |
212 | - $cache = get_post_meta( $post_ID, $cachekey, true ); |
|
213 | - $cache_time = get_post_meta( $post_ID, $cachekey_time, true ); |
|
212 | + $cache = get_post_meta($post_ID, $cachekey, true); |
|
213 | + $cache_time = get_post_meta($post_ID, $cachekey_time, true); |
|
214 | 214 | |
215 | - if ( ! $cache_time ) { |
|
215 | + if ( ! $cache_time) { |
|
216 | 216 | $cache_time = 0; |
217 | 217 | } |
218 | 218 | |
219 | - $cached_recently = ( time() - $cache_time ) < $ttl; |
|
219 | + $cached_recently = (time() - $cache_time) < $ttl; |
|
220 | 220 | |
221 | - if ( $this->usecache || $cached_recently ) { |
|
221 | + if ($this->usecache || $cached_recently) { |
|
222 | 222 | // Failures are cached. Serve one if we're using the cache. |
223 | - if ( '{{unknown}}' === $cache ) |
|
224 | - return $this->maybe_make_link( $url ); |
|
223 | + if ('{{unknown}}' === $cache) |
|
224 | + return $this->maybe_make_link($url); |
|
225 | 225 | |
226 | - if ( ! empty( $cache ) ) { |
|
226 | + if ( ! empty($cache)) { |
|
227 | 227 | /** |
228 | 228 | * Filters the cached oEmbed HTML. |
229 | 229 | * |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | * @param array $attr An array of shortcode attributes. |
237 | 237 | * @param int $post_ID Post ID. |
238 | 238 | */ |
239 | - return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $post_ID ); |
|
239 | + return apply_filters('embed_oembed_html', $cache, $url, $attr, $post_ID); |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
@@ -250,28 +250,28 @@ discard block |
||
250 | 250 | * |
251 | 251 | * @param bool $enable Whether to enable `<link>` tag discovery. Default true. |
252 | 252 | */ |
253 | - $attr['discover'] = ( apply_filters( 'embed_oembed_discover', true ) ); |
|
253 | + $attr['discover'] = (apply_filters('embed_oembed_discover', true)); |
|
254 | 254 | |
255 | 255 | // Use oEmbed to get the HTML |
256 | - $html = wp_oembed_get( $url, $attr ); |
|
256 | + $html = wp_oembed_get($url, $attr); |
|
257 | 257 | |
258 | 258 | // Maybe cache the result |
259 | - if ( $html ) { |
|
260 | - update_post_meta( $post_ID, $cachekey, $html ); |
|
261 | - update_post_meta( $post_ID, $cachekey_time, time() ); |
|
262 | - } elseif ( ! $cache ) { |
|
263 | - update_post_meta( $post_ID, $cachekey, '{{unknown}}' ); |
|
259 | + if ($html) { |
|
260 | + update_post_meta($post_ID, $cachekey, $html); |
|
261 | + update_post_meta($post_ID, $cachekey_time, time()); |
|
262 | + } elseif ( ! $cache) { |
|
263 | + update_post_meta($post_ID, $cachekey, '{{unknown}}'); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | // If there was a result, return it |
267 | - if ( $html ) { |
|
267 | + if ($html) { |
|
268 | 268 | /** This filter is documented in wp-includes/class-wp-embed.php */ |
269 | - return apply_filters( 'embed_oembed_html', $html, $url, $attr, $post_ID ); |
|
269 | + return apply_filters('embed_oembed_html', $html, $url, $attr, $post_ID); |
|
270 | 270 | } |
271 | 271 | } |
272 | 272 | |
273 | 273 | // Still unknown |
274 | - return $this->maybe_make_link( $url ); |
|
274 | + return $this->maybe_make_link($url); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -279,14 +279,14 @@ discard block |
||
279 | 279 | * |
280 | 280 | * @param int $post_ID Post ID to delete the caches for. |
281 | 281 | */ |
282 | - public function delete_oembed_caches( $post_ID ) { |
|
283 | - $post_metas = get_post_custom_keys( $post_ID ); |
|
284 | - if ( empty($post_metas) ) |
|
282 | + public function delete_oembed_caches($post_ID) { |
|
283 | + $post_metas = get_post_custom_keys($post_ID); |
|
284 | + if (empty($post_metas)) |
|
285 | 285 | return; |
286 | 286 | |
287 | - foreach ( $post_metas as $post_meta_key ) { |
|
288 | - if ( '_oembed_' == substr( $post_meta_key, 0, 8 ) ) |
|
289 | - delete_post_meta( $post_ID, $post_meta_key ); |
|
287 | + foreach ($post_metas as $post_meta_key) { |
|
288 | + if ('_oembed_' == substr($post_meta_key, 0, 8)) |
|
289 | + delete_post_meta($post_ID, $post_meta_key); |
|
290 | 290 | } |
291 | 291 | } |
292 | 292 | |
@@ -295,10 +295,10 @@ discard block |
||
295 | 295 | * |
296 | 296 | * @param int $post_ID Post ID to do the caching for. |
297 | 297 | */ |
298 | - public function cache_oembed( $post_ID ) { |
|
299 | - $post = get_post( $post_ID ); |
|
298 | + public function cache_oembed($post_ID) { |
|
299 | + $post = get_post($post_ID); |
|
300 | 300 | |
301 | - $post_types = get_post_types( array( 'show_ui' => true ) ); |
|
301 | + $post_types = get_post_types(array('show_ui' => true)); |
|
302 | 302 | /** |
303 | 303 | * Filters the array of post types to cache oEmbed results for. |
304 | 304 | * |
@@ -306,17 +306,17 @@ discard block |
||
306 | 306 | * |
307 | 307 | * @param array $post_types Array of post types to cache oEmbed results for. Defaults to post types with `show_ui` set to true. |
308 | 308 | */ |
309 | - if ( empty( $post->ID ) || ! in_array( $post->post_type, apply_filters( 'embed_cache_oembed_types', $post_types ) ) ){ |
|
309 | + if (empty($post->ID) || ! in_array($post->post_type, apply_filters('embed_cache_oembed_types', $post_types))) { |
|
310 | 310 | return; |
311 | 311 | } |
312 | 312 | |
313 | 313 | // Trigger a caching |
314 | - if ( ! empty( $post->post_content ) ) { |
|
314 | + if ( ! empty($post->post_content)) { |
|
315 | 315 | $this->post_ID = $post->ID; |
316 | 316 | $this->usecache = false; |
317 | 317 | |
318 | - $content = $this->run_shortcode( $post->post_content ); |
|
319 | - $this->autoembed( $content ); |
|
318 | + $content = $this->run_shortcode($post->post_content); |
|
319 | + $this->autoembed($content); |
|
320 | 320 | |
321 | 321 | $this->usecache = true; |
322 | 322 | } |
@@ -330,19 +330,19 @@ discard block |
||
330 | 330 | * @param string $content The content to be searched. |
331 | 331 | * @return string Potentially modified $content. |
332 | 332 | */ |
333 | - public function autoembed( $content ) { |
|
333 | + public function autoembed($content) { |
|
334 | 334 | // Replace line breaks from all HTML elements with placeholders. |
335 | - $content = wp_replace_in_html_tags( $content, array( "\n" => '<!-- wp-line-break -->' ) ); |
|
335 | + $content = wp_replace_in_html_tags($content, array("\n" => '<!-- wp-line-break -->')); |
|
336 | 336 | |
337 | - if ( preg_match( '#(^|\s|>)https?://#i', $content ) ) { |
|
337 | + if (preg_match('#(^|\s|>)https?://#i', $content)) { |
|
338 | 338 | // Find URLs on their own line. |
339 | - $content = preg_replace_callback( '|^(\s*)(https?://[^\s<>"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content ); |
|
339 | + $content = preg_replace_callback('|^(\s*)(https?://[^\s<>"]+)(\s*)$|im', array($this, 'autoembed_callback'), $content); |
|
340 | 340 | // Find URLs in their own paragraph. |
341 | - $content = preg_replace_callback( '|(<p(?: [^>]*)?>\s*)(https?://[^\s<>"]+)(\s*<\/p>)|i', array( $this, 'autoembed_callback' ), $content ); |
|
341 | + $content = preg_replace_callback('|(<p(?: [^>]*)?>\s*)(https?://[^\s<>"]+)(\s*<\/p>)|i', array($this, 'autoembed_callback'), $content); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | // Put the line breaks back. |
345 | - return str_replace( '<!-- wp-line-break -->', "\n", $content ); |
|
345 | + return str_replace('<!-- wp-line-break -->', "\n", $content); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
@@ -351,13 +351,13 @@ discard block |
||
351 | 351 | * @param array $match A regex match array. |
352 | 352 | * @return string The embed HTML on success, otherwise the original URL. |
353 | 353 | */ |
354 | - public function autoembed_callback( $match ) { |
|
354 | + public function autoembed_callback($match) { |
|
355 | 355 | $oldval = $this->linkifunknown; |
356 | 356 | $this->linkifunknown = false; |
357 | - $return = $this->shortcode( array(), $match[2] ); |
|
357 | + $return = $this->shortcode(array(), $match[2]); |
|
358 | 358 | $this->linkifunknown = $oldval; |
359 | 359 | |
360 | - return $match[1] . $return . $match[3]; |
|
360 | + return $match[1].$return.$match[3]; |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | /** |
@@ -366,12 +366,12 @@ discard block |
||
366 | 366 | * @param string $url URL to potentially be linked. |
367 | 367 | * @return false|string Linked URL or the original URL. False if 'return_false_on_fail' is true. |
368 | 368 | */ |
369 | - public function maybe_make_link( $url ) { |
|
370 | - if ( $this->return_false_on_fail ) { |
|
369 | + public function maybe_make_link($url) { |
|
370 | + if ($this->return_false_on_fail) { |
|
371 | 371 | return false; |
372 | 372 | } |
373 | 373 | |
374 | - $output = ( $this->linkifunknown ) ? '<a href="' . esc_url($url) . '">' . esc_html($url) . '</a>' : $url; |
|
374 | + $output = ($this->linkifunknown) ? '<a href="'.esc_url($url).'">'.esc_html($url).'</a>' : $url; |
|
375 | 375 | |
376 | 376 | /** |
377 | 377 | * Filters the returned, maybe-linked embed URL. |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | * @param string $output The linked or original URL. |
382 | 382 | * @param string $url The original URL. |
383 | 383 | */ |
384 | - return apply_filters( 'embed_maybe_make_link', $output, $url ); |
|
384 | + return apply_filters('embed_maybe_make_link', $output, $url); |
|
385 | 385 | } |
386 | 386 | } |
387 | 387 | $GLOBALS['wp_embed'] = new WP_Embed(); |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | * } |
49 | 49 | * @return string Formatted output in HTML |
50 | 50 | */ |
51 | -function _walk_bookmarks( $bookmarks, $args = '' ) { |
|
51 | +function _walk_bookmarks($bookmarks, $args = '') { |
|
52 | 52 | $defaults = array( |
53 | 53 | 'show_updated' => 0, 'show_description' => 0, |
54 | 54 | 'show_images' => 1, 'show_name' => 0, |
@@ -56,63 +56,63 @@ discard block |
||
56 | 56 | 'show_rating' => 0, 'link_before' => '', 'link_after' => '' |
57 | 57 | ); |
58 | 58 | |
59 | - $r = wp_parse_args( $args, $defaults ); |
|
59 | + $r = wp_parse_args($args, $defaults); |
|
60 | 60 | |
61 | 61 | $output = ''; // Blank string to start with. |
62 | 62 | |
63 | - foreach ( (array) $bookmarks as $bookmark ) { |
|
64 | - if ( ! isset( $bookmark->recently_updated ) ) { |
|
63 | + foreach ((array) $bookmarks as $bookmark) { |
|
64 | + if ( ! isset($bookmark->recently_updated)) { |
|
65 | 65 | $bookmark->recently_updated = false; |
66 | 66 | } |
67 | 67 | $output .= $r['before']; |
68 | - if ( $r['show_updated'] && $bookmark->recently_updated ) { |
|
68 | + if ($r['show_updated'] && $bookmark->recently_updated) { |
|
69 | 69 | $output .= '<em>'; |
70 | 70 | } |
71 | 71 | $the_link = '#'; |
72 | - if ( ! empty( $bookmark->link_url ) ) { |
|
73 | - $the_link = esc_url( $bookmark->link_url ); |
|
72 | + if ( ! empty($bookmark->link_url)) { |
|
73 | + $the_link = esc_url($bookmark->link_url); |
|
74 | 74 | } |
75 | - $desc = esc_attr( sanitize_bookmark_field( 'link_description', $bookmark->link_description, $bookmark->link_id, 'display' ) ); |
|
76 | - $name = esc_attr( sanitize_bookmark_field( 'link_name', $bookmark->link_name, $bookmark->link_id, 'display' ) ); |
|
75 | + $desc = esc_attr(sanitize_bookmark_field('link_description', $bookmark->link_description, $bookmark->link_id, 'display')); |
|
76 | + $name = esc_attr(sanitize_bookmark_field('link_name', $bookmark->link_name, $bookmark->link_id, 'display')); |
|
77 | 77 | $title = $desc; |
78 | 78 | |
79 | - if ( $r['show_updated'] ) { |
|
80 | - if ( '00' != substr( $bookmark->link_updated_f, 0, 2 ) ) { |
|
79 | + if ($r['show_updated']) { |
|
80 | + if ('00' != substr($bookmark->link_updated_f, 0, 2)) { |
|
81 | 81 | $title .= ' ('; |
82 | 82 | $title .= sprintf( |
83 | 83 | __('Last updated: %s'), |
84 | 84 | date( |
85 | - get_option( 'links_updated_date_format' ), |
|
86 | - $bookmark->link_updated_f + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) |
|
85 | + get_option('links_updated_date_format'), |
|
86 | + $bookmark->link_updated_f + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
87 | 87 | ) |
88 | 88 | ); |
89 | 89 | $title .= ')'; |
90 | 90 | } |
91 | 91 | } |
92 | - $alt = ' alt="' . $name . ( $r['show_description'] ? ' ' . $title : '' ) . '"'; |
|
92 | + $alt = ' alt="'.$name.($r['show_description'] ? ' '.$title : '').'"'; |
|
93 | 93 | |
94 | - if ( '' != $title ) { |
|
95 | - $title = ' title="' . $title . '"'; |
|
94 | + if ('' != $title) { |
|
95 | + $title = ' title="'.$title.'"'; |
|
96 | 96 | } |
97 | 97 | $rel = $bookmark->link_rel; |
98 | - if ( '' != $rel ) { |
|
99 | - $rel = ' rel="' . esc_attr($rel) . '"'; |
|
98 | + if ('' != $rel) { |
|
99 | + $rel = ' rel="'.esc_attr($rel).'"'; |
|
100 | 100 | } |
101 | 101 | $target = $bookmark->link_target; |
102 | - if ( '' != $target ) { |
|
103 | - $target = ' target="' . $target . '"'; |
|
102 | + if ('' != $target) { |
|
103 | + $target = ' target="'.$target.'"'; |
|
104 | 104 | } |
105 | - $output .= '<a href="' . $the_link . '"' . $rel . $title . $target . '>'; |
|
105 | + $output .= '<a href="'.$the_link.'"'.$rel.$title.$target.'>'; |
|
106 | 106 | |
107 | 107 | $output .= $r['link_before']; |
108 | 108 | |
109 | - if ( $bookmark->link_image != null && $r['show_images'] ) { |
|
110 | - if ( strpos( $bookmark->link_image, 'http' ) === 0 ) { |
|
109 | + if ($bookmark->link_image != null && $r['show_images']) { |
|
110 | + if (strpos($bookmark->link_image, 'http') === 0) { |
|
111 | 111 | $output .= "<img src=\"$bookmark->link_image\" $alt $title />"; |
112 | 112 | } else { // If it's a relative path |
113 | - $output .= "<img src=\"" . get_option('siteurl') . "$bookmark->link_image\" $alt $title />"; |
|
113 | + $output .= "<img src=\"".get_option('siteurl')."$bookmark->link_image\" $alt $title />"; |
|
114 | 114 | } |
115 | - if ( $r['show_name'] ) { |
|
115 | + if ($r['show_name']) { |
|
116 | 116 | $output .= " $name"; |
117 | 117 | } |
118 | 118 | } else { |
@@ -123,23 +123,23 @@ discard block |
||
123 | 123 | |
124 | 124 | $output .= '</a>'; |
125 | 125 | |
126 | - if ( $r['show_updated'] && $bookmark->recently_updated ) { |
|
126 | + if ($r['show_updated'] && $bookmark->recently_updated) { |
|
127 | 127 | $output .= '</em>'; |
128 | 128 | } |
129 | 129 | |
130 | - if ( $r['show_description'] && '' != $desc ) { |
|
131 | - $output .= $r['between'] . $desc; |
|
130 | + if ($r['show_description'] && '' != $desc) { |
|
131 | + $output .= $r['between'].$desc; |
|
132 | 132 | } |
133 | 133 | |
134 | - if ( $r['show_rating'] ) { |
|
135 | - $output .= $r['between'] . sanitize_bookmark_field( |
|
134 | + if ($r['show_rating']) { |
|
135 | + $output .= $r['between'].sanitize_bookmark_field( |
|
136 | 136 | 'link_rating', |
137 | 137 | $bookmark->link_rating, |
138 | 138 | $bookmark->link_id, |
139 | 139 | 'display' |
140 | 140 | ); |
141 | 141 | } |
142 | - $output .= $r['after'] . "\n"; |
|
142 | + $output .= $r['after']."\n"; |
|
143 | 143 | } // end while |
144 | 144 | |
145 | 145 | return $output; |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | * } |
198 | 198 | * @return string|void Will only return if echo option is set to not echo. Default is not return anything. |
199 | 199 | */ |
200 | -function wp_list_bookmarks( $args = '' ) { |
|
200 | +function wp_list_bookmarks($args = '') { |
|
201 | 201 | $defaults = array( |
202 | 202 | 'orderby' => 'name', 'order' => 'ASC', |
203 | 203 | 'limit' => -1, 'category' => '', 'exclude_category' => '', |
@@ -210,41 +210,41 @@ discard block |
||
210 | 210 | 'category_after' => '</li>' |
211 | 211 | ); |
212 | 212 | |
213 | - $r = wp_parse_args( $args, $defaults ); |
|
213 | + $r = wp_parse_args($args, $defaults); |
|
214 | 214 | |
215 | 215 | $output = ''; |
216 | 216 | |
217 | - if ( ! is_array( $r['class'] ) ) { |
|
218 | - $r['class'] = explode( ' ', $r['class'] ); |
|
217 | + if ( ! is_array($r['class'])) { |
|
218 | + $r['class'] = explode(' ', $r['class']); |
|
219 | 219 | } |
220 | - $r['class'] = array_map( 'sanitize_html_class', $r['class'] ); |
|
221 | - $r['class'] = trim( join( ' ', $r['class'] ) ); |
|
220 | + $r['class'] = array_map('sanitize_html_class', $r['class']); |
|
221 | + $r['class'] = trim(join(' ', $r['class'])); |
|
222 | 222 | |
223 | - if ( $r['categorize'] ) { |
|
224 | - $cats = get_terms( 'link_category', array( |
|
223 | + if ($r['categorize']) { |
|
224 | + $cats = get_terms('link_category', array( |
|
225 | 225 | 'name__like' => $r['category_name'], |
226 | 226 | 'include' => $r['category'], |
227 | 227 | 'exclude' => $r['exclude_category'], |
228 | 228 | 'orderby' => $r['category_orderby'], |
229 | 229 | 'order' => $r['category_order'], |
230 | 230 | 'hierarchical' => 0 |
231 | - ) ); |
|
232 | - if ( empty( $cats ) ) { |
|
231 | + )); |
|
232 | + if (empty($cats)) { |
|
233 | 233 | $r['categorize'] = false; |
234 | 234 | } |
235 | 235 | } |
236 | 236 | |
237 | - if ( $r['categorize'] ) { |
|
237 | + if ($r['categorize']) { |
|
238 | 238 | // Split the bookmarks into ul's for each category |
239 | - foreach ( (array) $cats as $cat ) { |
|
240 | - $params = array_merge( $r, array( 'category' => $cat->term_id ) ); |
|
241 | - $bookmarks = get_bookmarks( $params ); |
|
242 | - if ( empty( $bookmarks ) ) { |
|
239 | + foreach ((array) $cats as $cat) { |
|
240 | + $params = array_merge($r, array('category' => $cat->term_id)); |
|
241 | + $bookmarks = get_bookmarks($params); |
|
242 | + if (empty($bookmarks)) { |
|
243 | 243 | continue; |
244 | 244 | } |
245 | 245 | $output .= str_replace( |
246 | - array( '%id', '%class' ), |
|
247 | - array( "linkcat-$cat->term_id", $r['class'] ), |
|
246 | + array('%id', '%class'), |
|
247 | + array("linkcat-$cat->term_id", $r['class']), |
|
248 | 248 | $r['category_before'] |
249 | 249 | ); |
250 | 250 | /** |
@@ -254,36 +254,36 @@ discard block |
||
254 | 254 | * |
255 | 255 | * @param string $cat_name The category name of bookmarks. |
256 | 256 | */ |
257 | - $catname = apply_filters( 'link_category', $cat->name ); |
|
257 | + $catname = apply_filters('link_category', $cat->name); |
|
258 | 258 | |
259 | 259 | $output .= $r['title_before']; |
260 | 260 | $output .= $catname; |
261 | 261 | $output .= $r['title_after']; |
262 | 262 | $output .= "\n\t<ul class='xoxo blogroll'>\n"; |
263 | - $output .= _walk_bookmarks( $bookmarks, $r ); |
|
263 | + $output .= _walk_bookmarks($bookmarks, $r); |
|
264 | 264 | $output .= "\n\t</ul>\n"; |
265 | - $output .= $r['category_after'] . "\n"; |
|
265 | + $output .= $r['category_after']."\n"; |
|
266 | 266 | } |
267 | 267 | } else { |
268 | 268 | //output one single list using title_li for the title |
269 | - $bookmarks = get_bookmarks( $r ); |
|
269 | + $bookmarks = get_bookmarks($r); |
|
270 | 270 | |
271 | - if ( ! empty( $bookmarks ) ) { |
|
272 | - if ( ! empty( $r['title_li'] ) ) { |
|
271 | + if ( ! empty($bookmarks)) { |
|
272 | + if ( ! empty($r['title_li'])) { |
|
273 | 273 | $output .= str_replace( |
274 | - array( '%id', '%class' ), |
|
275 | - array( "linkcat-" . $r['category'], $r['class'] ), |
|
274 | + array('%id', '%class'), |
|
275 | + array("linkcat-".$r['category'], $r['class']), |
|
276 | 276 | $r['category_before'] |
277 | 277 | ); |
278 | 278 | $output .= $r['title_before']; |
279 | 279 | $output .= $r['title_li']; |
280 | 280 | $output .= $r['title_after']; |
281 | 281 | $output .= "\n\t<ul class='xoxo blogroll'>\n"; |
282 | - $output .= _walk_bookmarks( $bookmarks, $r ); |
|
282 | + $output .= _walk_bookmarks($bookmarks, $r); |
|
283 | 283 | $output .= "\n\t</ul>\n"; |
284 | - $output .= $r['category_after'] . "\n"; |
|
284 | + $output .= $r['category_after']."\n"; |
|
285 | 285 | } else { |
286 | - $output .= _walk_bookmarks( $bookmarks, $r ); |
|
286 | + $output .= _walk_bookmarks($bookmarks, $r); |
|
287 | 287 | } |
288 | 288 | } |
289 | 289 | } |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | * |
296 | 296 | * @param string $html The HTML list of bookmarks. |
297 | 297 | */ |
298 | - $html = apply_filters( 'wp_list_bookmarks', $output ); |
|
298 | + $html = apply_filters('wp_list_bookmarks', $output); |
|
299 | 299 | |
300 | - if ( ! $r['echo'] ) { |
|
300 | + if ( ! $r['echo']) { |
|
301 | 301 | return $html; |
302 | 302 | } |
303 | 303 | echo $html; |
@@ -88,9 +88,10 @@ discard block |
||
88 | 88 | _deprecated_function( __FUNCTION__, '2.5', 'wp_set_auth_cookie()' ); |
89 | 89 | $user = get_user_by('login', $username); |
90 | 90 | wp_set_auth_cookie($user->ID, $remember); |
91 | -} |
|
92 | -else : |
|
91 | +} else { |
|
92 | + : |
|
93 | 93 | _deprecated_function( 'wp_setcookie', '2.5', 'wp_set_auth_cookie()' ); |
94 | +} |
|
94 | 95 | endif; |
95 | 96 | |
96 | 97 | if ( !function_exists('wp_clearcookie') ) : |
@@ -104,9 +105,10 @@ discard block |
||
104 | 105 | function wp_clearcookie() { |
105 | 106 | _deprecated_function( __FUNCTION__, '2.5', 'wp_clear_auth_cookie()' ); |
106 | 107 | wp_clear_auth_cookie(); |
107 | -} |
|
108 | -else : |
|
108 | +} else { |
|
109 | + : |
|
109 | 110 | _deprecated_function( 'wp_clearcookie', '2.5', 'wp_clear_auth_cookie()' ); |
111 | +} |
|
110 | 112 | endif; |
111 | 113 | |
112 | 114 | if ( !function_exists('wp_get_cookie_login') ): |
@@ -124,9 +126,10 @@ discard block |
||
124 | 126 | function wp_get_cookie_login() { |
125 | 127 | _deprecated_function( __FUNCTION__, '2.5' ); |
126 | 128 | return false; |
127 | -} |
|
128 | -else : |
|
129 | +} else { |
|
130 | + : |
|
129 | 131 | _deprecated_function( 'wp_get_cookie_login', '2.5' ); |
132 | +} |
|
130 | 133 | endif; |
131 | 134 | |
132 | 135 | if ( !function_exists('wp_login') ) : |
@@ -157,14 +160,16 @@ discard block |
||
157 | 160 | |
158 | 161 | $user = wp_authenticate($username, $password); |
159 | 162 | |
160 | - if ( ! is_wp_error($user) ) |
|
161 | - return true; |
|
163 | + if ( ! is_wp_error($user) ) { |
|
164 | + return true; |
|
165 | + } |
|
162 | 166 | |
163 | 167 | $error = $user->get_error_message(); |
164 | 168 | return false; |
165 | -} |
|
166 | -else : |
|
169 | +} else { |
|
170 | + : |
|
167 | 171 | _deprecated_function( 'wp_login', '2.5', 'wp_signon()' ); |
172 | +} |
|
168 | 173 | endif; |
169 | 174 | |
170 | 175 | /** |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * Deprecated functions come here to die. |
16 | 16 | */ |
17 | 17 | |
18 | -if ( !function_exists('set_current_user') ) : |
|
18 | +if ( ! function_exists('set_current_user')) : |
|
19 | 19 | /** |
20 | 20 | * Changes the current user by ID or name. |
21 | 21 | * |
@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | * @return WP_User returns wp_set_current_user() |
31 | 31 | */ |
32 | 32 | function set_current_user($id, $name = '') { |
33 | - _deprecated_function( __FUNCTION__, '3.0.0', 'wp_set_current_user()' ); |
|
33 | + _deprecated_function(__FUNCTION__, '3.0.0', 'wp_set_current_user()'); |
|
34 | 34 | return wp_set_current_user($id, $name); |
35 | 35 | } |
36 | 36 | endif; |
37 | 37 | |
38 | -if ( !function_exists('get_currentuserinfo') ) : |
|
38 | +if ( ! function_exists('get_currentuserinfo')) : |
|
39 | 39 | /** |
40 | 40 | * Populate global variables with information about the currently logged in user. |
41 | 41 | * |
@@ -46,13 +46,13 @@ discard block |
||
46 | 46 | * @return bool|WP_User False on XMLRPC Request and invalid auth cookie, WP_User instance otherwise. |
47 | 47 | */ |
48 | 48 | function get_currentuserinfo() { |
49 | - _deprecated_function( __FUNCTION__, '4.5.0', 'wp_get_current_user()' ); |
|
49 | + _deprecated_function(__FUNCTION__, '4.5.0', 'wp_get_current_user()'); |
|
50 | 50 | |
51 | 51 | return _wp_get_current_user(); |
52 | 52 | } |
53 | 53 | endif; |
54 | 54 | |
55 | -if ( !function_exists('get_userdatabylogin') ) : |
|
55 | +if ( ! function_exists('get_userdatabylogin')) : |
|
56 | 56 | /** |
57 | 57 | * Retrieve user info by login name. |
58 | 58 | * |
@@ -64,12 +64,12 @@ discard block |
||
64 | 64 | * @return bool|object False on failure, User DB row object |
65 | 65 | */ |
66 | 66 | function get_userdatabylogin($user_login) { |
67 | - _deprecated_function( __FUNCTION__, '3.3.0', "get_user_by('login')" ); |
|
67 | + _deprecated_function(__FUNCTION__, '3.3.0', "get_user_by('login')"); |
|
68 | 68 | return get_user_by('login', $user_login); |
69 | 69 | } |
70 | 70 | endif; |
71 | 71 | |
72 | -if ( !function_exists('get_user_by_email') ) : |
|
72 | +if ( ! function_exists('get_user_by_email')) : |
|
73 | 73 | /** |
74 | 74 | * Retrieve user info by email. |
75 | 75 | * |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | * @return bool|object False on failure, User DB row object |
82 | 82 | */ |
83 | 83 | function get_user_by_email($email) { |
84 | - _deprecated_function( __FUNCTION__, '3.3.0', "get_user_by('email')" ); |
|
84 | + _deprecated_function(__FUNCTION__, '3.3.0', "get_user_by('email')"); |
|
85 | 85 | return get_user_by('email', $email); |
86 | 86 | } |
87 | 87 | endif; |
88 | 88 | |
89 | -if ( !function_exists('wp_setcookie') ) : |
|
89 | +if ( ! function_exists('wp_setcookie')) : |
|
90 | 90 | /** |
91 | 91 | * Sets a cookie for a user who just logged in. This function is deprecated. |
92 | 92 | * |
@@ -102,15 +102,15 @@ discard block |
||
102 | 102 | * @param bool $remember Optional. Remember that the user is logged in |
103 | 103 | */ |
104 | 104 | function wp_setcookie($username, $password = '', $already_md5 = false, $home = '', $siteurl = '', $remember = false) { |
105 | - _deprecated_function( __FUNCTION__, '2.5.0', 'wp_set_auth_cookie()' ); |
|
105 | + _deprecated_function(__FUNCTION__, '2.5.0', 'wp_set_auth_cookie()'); |
|
106 | 106 | $user = get_user_by('login', $username); |
107 | 107 | wp_set_auth_cookie($user->ID, $remember); |
108 | 108 | } |
109 | 109 | else : |
110 | - _deprecated_function( 'wp_setcookie', '2.5.0', 'wp_set_auth_cookie()' ); |
|
110 | + _deprecated_function('wp_setcookie', '2.5.0', 'wp_set_auth_cookie()'); |
|
111 | 111 | endif; |
112 | 112 | |
113 | -if ( !function_exists('wp_clearcookie') ) : |
|
113 | +if ( ! function_exists('wp_clearcookie')) : |
|
114 | 114 | /** |
115 | 115 | * Clears the authentication cookie, logging the user out. This function is deprecated. |
116 | 116 | * |
@@ -119,14 +119,14 @@ discard block |
||
119 | 119 | * @see wp_clear_auth_cookie() |
120 | 120 | */ |
121 | 121 | function wp_clearcookie() { |
122 | - _deprecated_function( __FUNCTION__, '2.5.0', 'wp_clear_auth_cookie()' ); |
|
122 | + _deprecated_function(__FUNCTION__, '2.5.0', 'wp_clear_auth_cookie()'); |
|
123 | 123 | wp_clear_auth_cookie(); |
124 | 124 | } |
125 | 125 | else : |
126 | - _deprecated_function( 'wp_clearcookie', '2.5.0', 'wp_clear_auth_cookie()' ); |
|
126 | + _deprecated_function('wp_clearcookie', '2.5.0', 'wp_clear_auth_cookie()'); |
|
127 | 127 | endif; |
128 | 128 | |
129 | -if ( !function_exists('wp_get_cookie_login') ): |
|
129 | +if ( ! function_exists('wp_get_cookie_login')): |
|
130 | 130 | /** |
131 | 131 | * Gets the user cookie login. This function is deprecated. |
132 | 132 | * |
@@ -139,14 +139,14 @@ discard block |
||
139 | 139 | * @return bool Always returns false |
140 | 140 | */ |
141 | 141 | function wp_get_cookie_login() { |
142 | - _deprecated_function( __FUNCTION__, '2.5.0' ); |
|
142 | + _deprecated_function(__FUNCTION__, '2.5.0'); |
|
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | else : |
146 | - _deprecated_function( 'wp_get_cookie_login', '2.5.0' ); |
|
146 | + _deprecated_function('wp_get_cookie_login', '2.5.0'); |
|
147 | 147 | endif; |
148 | 148 | |
149 | -if ( !function_exists('wp_login') ) : |
|
149 | +if ( ! function_exists('wp_login')) : |
|
150 | 150 | /** |
151 | 151 | * Checks a users login information and logs them in if it checks out. This function is deprecated. |
152 | 152 | * |
@@ -169,19 +169,19 @@ discard block |
||
169 | 169 | * @return bool False on login failure, true on successful check |
170 | 170 | */ |
171 | 171 | function wp_login($username, $password, $deprecated = '') { |
172 | - _deprecated_function( __FUNCTION__, '2.5.0', 'wp_signon()' ); |
|
172 | + _deprecated_function(__FUNCTION__, '2.5.0', 'wp_signon()'); |
|
173 | 173 | global $error; |
174 | 174 | |
175 | 175 | $user = wp_authenticate($username, $password); |
176 | 176 | |
177 | - if ( ! is_wp_error($user) ) |
|
177 | + if ( ! is_wp_error($user)) |
|
178 | 178 | return true; |
179 | 179 | |
180 | 180 | $error = $user->get_error_message(); |
181 | 181 | return false; |
182 | 182 | } |
183 | 183 | else : |
184 | - _deprecated_function( 'wp_login', '2.5.0', 'wp_signon()' ); |
|
184 | + _deprecated_function('wp_login', '2.5.0', 'wp_signon()'); |
|
185 | 185 | endif; |
186 | 186 | |
187 | 187 | /** |
@@ -195,14 +195,14 @@ discard block |
||
195 | 195 | * |
196 | 196 | * @link https://wordpress.org/plugins/atom-publishing-protocol/ |
197 | 197 | */ |
198 | -if ( ! class_exists( 'wp_atom_server', false ) ) { |
|
198 | +if ( ! class_exists('wp_atom_server', false)) { |
|
199 | 199 | class wp_atom_server { |
200 | - public function __call( $name, $arguments ) { |
|
201 | - _deprecated_function( __CLASS__ . '::' . $name, '3.5.0', 'the Atom Publishing Protocol plugin' ); |
|
200 | + public function __call($name, $arguments) { |
|
201 | + _deprecated_function(__CLASS__.'::'.$name, '3.5.0', 'the Atom Publishing Protocol plugin'); |
|
202 | 202 | } |
203 | 203 | |
204 | - public static function __callStatic( $name, $arguments ) { |
|
205 | - _deprecated_function( __CLASS__ . '::' . $name, '3.5.0', 'the Atom Publishing Protocol plugin' ); |
|
204 | + public static function __callStatic($name, $arguments) { |
|
205 | + _deprecated_function(__CLASS__.'::'.$name, '3.5.0', 'the Atom Publishing Protocol plugin'); |
|
206 | 206 | } |
207 | 207 | } |
208 | 208 | } |
@@ -137,7 +137,9 @@ discard block |
||
137 | 137 | |
138 | 138 | $fp = fopen($this->FILE, "r"); |
139 | 139 | while ($data = fread($fp, 4096)) { |
140 | - if($this->debug) $this->content .= $data; |
|
140 | + if($this->debug) { |
|
141 | + $this->content .= $data; |
|
142 | + } |
|
141 | 143 | |
142 | 144 | if(!xml_parse($parser, $data, feof($fp))) { |
143 | 145 | /* translators: 1: error message, 2: line number */ |
@@ -182,8 +184,9 @@ discard block |
||
182 | 184 | |
183 | 185 | $this->content_ns_decls = array(); |
184 | 186 | |
185 | - if($this->is_html || $this->is_text) |
|
186 | - trigger_error("Invalid content in element found. Content must not be of type text or html if it contains markup."); |
|
187 | + if($this->is_html || $this->is_text) { |
|
188 | + trigger_error("Invalid content in element found. Content must not be of type text or html if it contains markup."); |
|
189 | + } |
|
187 | 190 | |
188 | 191 | $attrs_prefix = array(); |
189 | 192 |
@@ -21,20 +21,20 @@ discard block |
||
21 | 21 | * @var array |
22 | 22 | * @access public |
23 | 23 | */ |
24 | - var $links = array(); |
|
25 | - /** |
|
26 | - * Stores Categories |
|
27 | - * @var array |
|
28 | - * @access public |
|
29 | - */ |
|
30 | - var $categories = array(); |
|
24 | + var $links = array(); |
|
25 | + /** |
|
26 | + * Stores Categories |
|
27 | + * @var array |
|
28 | + * @access public |
|
29 | + */ |
|
30 | + var $categories = array(); |
|
31 | 31 | /** |
32 | 32 | * Stores Entries |
33 | 33 | * |
34 | 34 | * @var array |
35 | 35 | * @access public |
36 | 36 | */ |
37 | - var $entries = array(); |
|
37 | + var $entries = array(); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | * @var array |
49 | 49 | * @access public |
50 | 50 | */ |
51 | - var $links = array(); |
|
52 | - /** |
|
53 | - * Stores Categories |
|
54 | - * @var array |
|
51 | + var $links = array(); |
|
52 | + /** |
|
53 | + * Stores Categories |
|
54 | + * @var array |
|
55 | 55 | * @access public |
56 | - */ |
|
57 | - var $categories = array(); |
|
56 | + */ |
|
57 | + var $categories = array(); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
@@ -64,39 +64,39 @@ discard block |
||
64 | 64 | */ |
65 | 65 | class AtomParser { |
66 | 66 | |
67 | - var $NS = 'http://www.w3.org/2005/Atom'; |
|
68 | - var $ATOM_CONTENT_ELEMENTS = array('content','summary','title','subtitle','rights'); |
|
69 | - var $ATOM_SIMPLE_ELEMENTS = array('id','updated','published','draft'); |
|
67 | + var $NS = 'http://www.w3.org/2005/Atom'; |
|
68 | + var $ATOM_CONTENT_ELEMENTS = array('content','summary','title','subtitle','rights'); |
|
69 | + var $ATOM_SIMPLE_ELEMENTS = array('id','updated','published','draft'); |
|
70 | 70 | |
71 | - var $debug = false; |
|
71 | + var $debug = false; |
|
72 | 72 | |
73 | - var $depth = 0; |
|
74 | - var $indent = 2; |
|
75 | - var $in_content; |
|
76 | - var $ns_contexts = array(); |
|
77 | - var $ns_decls = array(); |
|
78 | - var $content_ns_decls = array(); |
|
79 | - var $content_ns_contexts = array(); |
|
80 | - var $is_xhtml = false; |
|
81 | - var $is_html = false; |
|
82 | - var $is_text = true; |
|
83 | - var $skipped_div = false; |
|
73 | + var $depth = 0; |
|
74 | + var $indent = 2; |
|
75 | + var $in_content; |
|
76 | + var $ns_contexts = array(); |
|
77 | + var $ns_decls = array(); |
|
78 | + var $content_ns_decls = array(); |
|
79 | + var $content_ns_contexts = array(); |
|
80 | + var $is_xhtml = false; |
|
81 | + var $is_html = false; |
|
82 | + var $is_text = true; |
|
83 | + var $skipped_div = false; |
|
84 | 84 | |
85 | - var $FILE = "php://input"; |
|
85 | + var $FILE = "php://input"; |
|
86 | 86 | |
87 | - var $feed; |
|
88 | - var $current; |
|
87 | + var $feed; |
|
88 | + var $current; |
|
89 | 89 | |
90 | 90 | /** |
91 | 91 | * PHP5 constructor. |
92 | 92 | */ |
93 | - function __construct() { |
|
93 | + function __construct() { |
|
94 | 94 | |
95 | - $this->feed = new AtomFeed(); |
|
96 | - $this->current = null; |
|
97 | - $this->map_attrs_func = array( __CLASS__, 'map_attrs' ); |
|
98 | - $this->map_xmlns_func = array( __CLASS__, 'map_xmlns' ); |
|
99 | - } |
|
95 | + $this->feed = new AtomFeed(); |
|
96 | + $this->current = null; |
|
97 | + $this->map_attrs_func = array( __CLASS__, 'map_attrs' ); |
|
98 | + $this->map_xmlns_func = array( __CLASS__, 'map_xmlns' ); |
|
99 | + } |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * PHP4 constructor. |
@@ -131,264 +131,264 @@ discard block |
||
131 | 131 | return "{$xd}=\"{$n[1]}\""; |
132 | 132 | } |
133 | 133 | |
134 | - function _p($msg) { |
|
135 | - if($this->debug) { |
|
136 | - print str_repeat(" ", $this->depth * $this->indent) . $msg ."\n"; |
|
137 | - } |
|
138 | - } |
|
134 | + function _p($msg) { |
|
135 | + if($this->debug) { |
|
136 | + print str_repeat(" ", $this->depth * $this->indent) . $msg ."\n"; |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + function error_handler($log_level, $log_text, $error_file, $error_line) { |
|
141 | + $this->error = $log_text; |
|
142 | + } |
|
143 | + |
|
144 | + function parse() { |
|
139 | 145 | |
140 | - function error_handler($log_level, $log_text, $error_file, $error_line) { |
|
141 | - $this->error = $log_text; |
|
142 | - } |
|
146 | + set_error_handler(array(&$this, 'error_handler')); |
|
143 | 147 | |
144 | - function parse() { |
|
148 | + array_unshift($this->ns_contexts, array()); |
|
145 | 149 | |
146 | - set_error_handler(array(&$this, 'error_handler')); |
|
150 | + if ( ! function_exists( 'xml_parser_create_ns' ) ) { |
|
151 | + trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); |
|
152 | + return false; |
|
153 | + } |
|
154 | + |
|
155 | + $parser = xml_parser_create_ns(); |
|
156 | + xml_set_object($parser, $this); |
|
157 | + xml_set_element_handler($parser, "start_element", "end_element"); |
|
158 | + xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0); |
|
159 | + xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,0); |
|
160 | + xml_set_character_data_handler($parser, "cdata"); |
|
161 | + xml_set_default_handler($parser, "_default"); |
|
162 | + xml_set_start_namespace_decl_handler($parser, "start_ns"); |
|
163 | + xml_set_end_namespace_decl_handler($parser, "end_ns"); |
|
164 | + |
|
165 | + $this->content = ''; |
|
166 | + |
|
167 | + $ret = true; |
|
168 | + |
|
169 | + $fp = fopen($this->FILE, "r"); |
|
170 | + while ($data = fread($fp, 4096)) { |
|
171 | + if($this->debug) $this->content .= $data; |
|
172 | + |
|
173 | + if(!xml_parse($parser, $data, feof($fp))) { |
|
174 | + /* translators: 1: error message, 2: line number */ |
|
175 | + trigger_error(sprintf(__('XML Error: %1$s at line %2$s')."\n", |
|
176 | + xml_error_string(xml_get_error_code($parser)), |
|
177 | + xml_get_current_line_number($parser))); |
|
178 | + $ret = false; |
|
179 | + break; |
|
180 | + } |
|
181 | + } |
|
182 | + fclose($fp); |
|
147 | 183 | |
148 | - array_unshift($this->ns_contexts, array()); |
|
184 | + xml_parser_free($parser); |
|
149 | 185 | |
150 | - if ( ! function_exists( 'xml_parser_create_ns' ) ) { |
|
151 | - trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); |
|
152 | - return false; |
|
153 | - } |
|
186 | + restore_error_handler(); |
|
154 | 187 | |
155 | - $parser = xml_parser_create_ns(); |
|
156 | - xml_set_object($parser, $this); |
|
157 | - xml_set_element_handler($parser, "start_element", "end_element"); |
|
158 | - xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0); |
|
159 | - xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,0); |
|
160 | - xml_set_character_data_handler($parser, "cdata"); |
|
161 | - xml_set_default_handler($parser, "_default"); |
|
162 | - xml_set_start_namespace_decl_handler($parser, "start_ns"); |
|
163 | - xml_set_end_namespace_decl_handler($parser, "end_ns"); |
|
164 | - |
|
165 | - $this->content = ''; |
|
188 | + return $ret; |
|
189 | + } |
|
166 | 190 | |
167 | - $ret = true; |
|
168 | - |
|
169 | - $fp = fopen($this->FILE, "r"); |
|
170 | - while ($data = fread($fp, 4096)) { |
|
171 | - if($this->debug) $this->content .= $data; |
|
191 | + function start_element($parser, $name, $attrs) { |
|
172 | 192 | |
173 | - if(!xml_parse($parser, $data, feof($fp))) { |
|
174 | - /* translators: 1: error message, 2: line number */ |
|
175 | - trigger_error(sprintf(__('XML Error: %1$s at line %2$s')."\n", |
|
176 | - xml_error_string(xml_get_error_code($parser)), |
|
177 | - xml_get_current_line_number($parser))); |
|
178 | - $ret = false; |
|
179 | - break; |
|
180 | - } |
|
181 | - } |
|
182 | - fclose($fp); |
|
193 | + $tag = array_pop(explode(":", $name)); |
|
183 | 194 | |
184 | - xml_parser_free($parser); |
|
185 | - |
|
186 | - restore_error_handler(); |
|
187 | - |
|
188 | - return $ret; |
|
189 | - } |
|
190 | - |
|
191 | - function start_element($parser, $name, $attrs) { |
|
192 | - |
|
193 | - $tag = array_pop(explode(":", $name)); |
|
194 | - |
|
195 | - switch($name) { |
|
196 | - case $this->NS . ':feed': |
|
197 | - $this->current = $this->feed; |
|
198 | - break; |
|
199 | - case $this->NS . ':entry': |
|
200 | - $this->current = new AtomEntry(); |
|
201 | - break; |
|
202 | - }; |
|
203 | - |
|
204 | - $this->_p("start_element('$name')"); |
|
205 | - #$this->_p(print_r($this->ns_contexts,true)); |
|
206 | - #$this->_p('current(' . $this->current . ')'); |
|
207 | - |
|
208 | - array_unshift($this->ns_contexts, $this->ns_decls); |
|
209 | - |
|
210 | - $this->depth++; |
|
211 | - |
|
212 | - if(!empty($this->in_content)) { |
|
213 | - |
|
214 | - $this->content_ns_decls = array(); |
|
215 | - |
|
216 | - if($this->is_html || $this->is_text) |
|
217 | - trigger_error("Invalid content in element found. Content must not be of type text or html if it contains markup."); |
|
218 | - |
|
219 | - $attrs_prefix = array(); |
|
220 | - |
|
221 | - // resolve prefixes for attributes |
|
222 | - foreach($attrs as $key => $value) { |
|
223 | - $with_prefix = $this->ns_to_prefix($key, true); |
|
224 | - $attrs_prefix[$with_prefix[1]] = $this->xml_escape($value); |
|
225 | - } |
|
226 | - |
|
227 | - $attrs_str = join(' ', array_map($this->map_attrs_func, array_keys($attrs_prefix), array_values($attrs_prefix))); |
|
228 | - if(strlen($attrs_str) > 0) { |
|
229 | - $attrs_str = " " . $attrs_str; |
|
230 | - } |
|
231 | - |
|
232 | - $with_prefix = $this->ns_to_prefix($name); |
|
233 | - |
|
234 | - if(!$this->is_declared_content_ns($with_prefix[0])) { |
|
235 | - array_push($this->content_ns_decls, $with_prefix[0]); |
|
236 | - } |
|
237 | - |
|
238 | - $xmlns_str = ''; |
|
239 | - if(count($this->content_ns_decls) > 0) { |
|
240 | - array_unshift($this->content_ns_contexts, $this->content_ns_decls); |
|
241 | - $xmlns_str .= join(' ', array_map($this->map_xmlns_func, array_keys($this->content_ns_contexts[0]), array_values($this->content_ns_contexts[0]))); |
|
242 | - if(strlen($xmlns_str) > 0) { |
|
243 | - $xmlns_str = " " . $xmlns_str; |
|
244 | - } |
|
245 | - } |
|
246 | - |
|
247 | - array_push($this->in_content, array($tag, $this->depth, "<". $with_prefix[1] ."{$xmlns_str}{$attrs_str}" . ">")); |
|
248 | - |
|
249 | - } else if(in_array($tag, $this->ATOM_CONTENT_ELEMENTS) || in_array($tag, $this->ATOM_SIMPLE_ELEMENTS)) { |
|
250 | - $this->in_content = array(); |
|
251 | - $this->is_xhtml = $attrs['type'] == 'xhtml'; |
|
252 | - $this->is_html = $attrs['type'] == 'html' || $attrs['type'] == 'text/html'; |
|
253 | - $this->is_text = !in_array('type',array_keys($attrs)) || $attrs['type'] == 'text'; |
|
254 | - $type = $this->is_xhtml ? 'XHTML' : ($this->is_html ? 'HTML' : ($this->is_text ? 'TEXT' : $attrs['type'])); |
|
255 | - |
|
256 | - if(in_array('src',array_keys($attrs))) { |
|
257 | - $this->current->$tag = $attrs; |
|
258 | - } else { |
|
259 | - array_push($this->in_content, array($tag,$this->depth, $type)); |
|
260 | - } |
|
261 | - } else if($tag == 'link') { |
|
262 | - array_push($this->current->links, $attrs); |
|
263 | - } else if($tag == 'category') { |
|
264 | - array_push($this->current->categories, $attrs); |
|
265 | - } |
|
266 | - |
|
267 | - $this->ns_decls = array(); |
|
268 | - } |
|
269 | - |
|
270 | - function end_element($parser, $name) { |
|
271 | - |
|
272 | - $tag = array_pop(explode(":", $name)); |
|
273 | - |
|
274 | - $ccount = count($this->in_content); |
|
275 | - |
|
276 | - # if we are *in* content, then let's proceed to serialize it |
|
277 | - if(!empty($this->in_content)) { |
|
278 | - # if we are ending the original content element |
|
279 | - # then let's finalize the content |
|
280 | - if($this->in_content[0][0] == $tag && |
|
281 | - $this->in_content[0][1] == $this->depth) { |
|
282 | - $origtype = $this->in_content[0][2]; |
|
283 | - array_shift($this->in_content); |
|
284 | - $newcontent = array(); |
|
285 | - foreach($this->in_content as $c) { |
|
286 | - if(count($c) == 3) { |
|
287 | - array_push($newcontent, $c[2]); |
|
288 | - } else { |
|
289 | - if($this->is_xhtml || $this->is_text) { |
|
290 | - array_push($newcontent, $this->xml_escape($c)); |
|
291 | - } else { |
|
292 | - array_push($newcontent, $c); |
|
293 | - } |
|
294 | - } |
|
295 | - } |
|
296 | - if(in_array($tag, $this->ATOM_CONTENT_ELEMENTS)) { |
|
297 | - $this->current->$tag = array($origtype, join('',$newcontent)); |
|
298 | - } else { |
|
299 | - $this->current->$tag = join('',$newcontent); |
|
300 | - } |
|
301 | - $this->in_content = array(); |
|
302 | - } else if($this->in_content[$ccount-1][0] == $tag && |
|
303 | - $this->in_content[$ccount-1][1] == $this->depth) { |
|
304 | - $this->in_content[$ccount-1][2] = substr($this->in_content[$ccount-1][2],0,-1) . "/>"; |
|
305 | - } else { |
|
306 | - # else, just finalize the current element's content |
|
307 | - $endtag = $this->ns_to_prefix($name); |
|
308 | - array_push($this->in_content, array($tag, $this->depth, "</$endtag[1]>")); |
|
309 | - } |
|
310 | - } |
|
311 | - |
|
312 | - array_shift($this->ns_contexts); |
|
313 | - |
|
314 | - $this->depth--; |
|
315 | - |
|
316 | - if($name == ($this->NS . ':entry')) { |
|
317 | - array_push($this->feed->entries, $this->current); |
|
318 | - $this->current = null; |
|
319 | - } |
|
320 | - |
|
321 | - $this->_p("end_element('$name')"); |
|
322 | - } |
|
323 | - |
|
324 | - function start_ns($parser, $prefix, $uri) { |
|
325 | - $this->_p("starting: " . $prefix . ":" . $uri); |
|
326 | - array_push($this->ns_decls, array($prefix,$uri)); |
|
327 | - } |
|
328 | - |
|
329 | - function end_ns($parser, $prefix) { |
|
330 | - $this->_p("ending: #" . $prefix . "#"); |
|
331 | - } |
|
332 | - |
|
333 | - function cdata($parser, $data) { |
|
334 | - $this->_p("data: #" . str_replace(array("\n"), array("\\n"), trim($data)) . "#"); |
|
335 | - if(!empty($this->in_content)) { |
|
336 | - array_push($this->in_content, $data); |
|
337 | - } |
|
338 | - } |
|
339 | - |
|
340 | - function _default($parser, $data) { |
|
341 | - # when does this gets called? |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - function ns_to_prefix($qname, $attr=false) { |
|
346 | - # split 'http://www.w3.org/1999/xhtml:div' into ('http','//www.w3.org/1999/xhtml','div') |
|
347 | - $components = explode(":", $qname); |
|
348 | - |
|
349 | - # grab the last one (e.g 'div') |
|
350 | - $name = array_pop($components); |
|
351 | - |
|
352 | - if(!empty($components)) { |
|
353 | - # re-join back the namespace component |
|
354 | - $ns = join(":",$components); |
|
355 | - foreach($this->ns_contexts as $context) { |
|
356 | - foreach($context as $mapping) { |
|
357 | - if($mapping[1] == $ns && strlen($mapping[0]) > 0) { |
|
358 | - return array($mapping, "$mapping[0]:$name"); |
|
359 | - } |
|
360 | - } |
|
361 | - } |
|
362 | - } |
|
363 | - |
|
364 | - if($attr) { |
|
365 | - return array(null, $name); |
|
366 | - } else { |
|
367 | - foreach($this->ns_contexts as $context) { |
|
368 | - foreach($context as $mapping) { |
|
369 | - if(strlen($mapping[0]) == 0) { |
|
370 | - return array($mapping, $name); |
|
371 | - } |
|
372 | - } |
|
373 | - } |
|
374 | - } |
|
375 | - } |
|
376 | - |
|
377 | - function is_declared_content_ns($new_mapping) { |
|
378 | - foreach($this->content_ns_contexts as $context) { |
|
379 | - foreach($context as $mapping) { |
|
380 | - if($new_mapping == $mapping) { |
|
381 | - return true; |
|
382 | - } |
|
383 | - } |
|
384 | - } |
|
385 | - return false; |
|
386 | - } |
|
387 | - |
|
388 | - function xml_escape($string) |
|
389 | - { |
|
390 | - return str_replace(array('&','"',"'",'<','>'), |
|
391 | - array('&','"',''','<','>'), |
|
392 | - $string ); |
|
393 | - } |
|
195 | + switch($name) { |
|
196 | + case $this->NS . ':feed': |
|
197 | + $this->current = $this->feed; |
|
198 | + break; |
|
199 | + case $this->NS . ':entry': |
|
200 | + $this->current = new AtomEntry(); |
|
201 | + break; |
|
202 | + }; |
|
203 | + |
|
204 | + $this->_p("start_element('$name')"); |
|
205 | + #$this->_p(print_r($this->ns_contexts,true)); |
|
206 | + #$this->_p('current(' . $this->current . ')'); |
|
207 | + |
|
208 | + array_unshift($this->ns_contexts, $this->ns_decls); |
|
209 | + |
|
210 | + $this->depth++; |
|
211 | + |
|
212 | + if(!empty($this->in_content)) { |
|
213 | + |
|
214 | + $this->content_ns_decls = array(); |
|
215 | + |
|
216 | + if($this->is_html || $this->is_text) |
|
217 | + trigger_error("Invalid content in element found. Content must not be of type text or html if it contains markup."); |
|
218 | + |
|
219 | + $attrs_prefix = array(); |
|
220 | + |
|
221 | + // resolve prefixes for attributes |
|
222 | + foreach($attrs as $key => $value) { |
|
223 | + $with_prefix = $this->ns_to_prefix($key, true); |
|
224 | + $attrs_prefix[$with_prefix[1]] = $this->xml_escape($value); |
|
225 | + } |
|
226 | + |
|
227 | + $attrs_str = join(' ', array_map($this->map_attrs_func, array_keys($attrs_prefix), array_values($attrs_prefix))); |
|
228 | + if(strlen($attrs_str) > 0) { |
|
229 | + $attrs_str = " " . $attrs_str; |
|
230 | + } |
|
231 | + |
|
232 | + $with_prefix = $this->ns_to_prefix($name); |
|
233 | + |
|
234 | + if(!$this->is_declared_content_ns($with_prefix[0])) { |
|
235 | + array_push($this->content_ns_decls, $with_prefix[0]); |
|
236 | + } |
|
237 | + |
|
238 | + $xmlns_str = ''; |
|
239 | + if(count($this->content_ns_decls) > 0) { |
|
240 | + array_unshift($this->content_ns_contexts, $this->content_ns_decls); |
|
241 | + $xmlns_str .= join(' ', array_map($this->map_xmlns_func, array_keys($this->content_ns_contexts[0]), array_values($this->content_ns_contexts[0]))); |
|
242 | + if(strlen($xmlns_str) > 0) { |
|
243 | + $xmlns_str = " " . $xmlns_str; |
|
244 | + } |
|
245 | + } |
|
246 | + |
|
247 | + array_push($this->in_content, array($tag, $this->depth, "<". $with_prefix[1] ."{$xmlns_str}{$attrs_str}" . ">")); |
|
248 | + |
|
249 | + } else if(in_array($tag, $this->ATOM_CONTENT_ELEMENTS) || in_array($tag, $this->ATOM_SIMPLE_ELEMENTS)) { |
|
250 | + $this->in_content = array(); |
|
251 | + $this->is_xhtml = $attrs['type'] == 'xhtml'; |
|
252 | + $this->is_html = $attrs['type'] == 'html' || $attrs['type'] == 'text/html'; |
|
253 | + $this->is_text = !in_array('type',array_keys($attrs)) || $attrs['type'] == 'text'; |
|
254 | + $type = $this->is_xhtml ? 'XHTML' : ($this->is_html ? 'HTML' : ($this->is_text ? 'TEXT' : $attrs['type'])); |
|
255 | + |
|
256 | + if(in_array('src',array_keys($attrs))) { |
|
257 | + $this->current->$tag = $attrs; |
|
258 | + } else { |
|
259 | + array_push($this->in_content, array($tag,$this->depth, $type)); |
|
260 | + } |
|
261 | + } else if($tag == 'link') { |
|
262 | + array_push($this->current->links, $attrs); |
|
263 | + } else if($tag == 'category') { |
|
264 | + array_push($this->current->categories, $attrs); |
|
265 | + } |
|
266 | + |
|
267 | + $this->ns_decls = array(); |
|
268 | + } |
|
269 | + |
|
270 | + function end_element($parser, $name) { |
|
271 | + |
|
272 | + $tag = array_pop(explode(":", $name)); |
|
273 | + |
|
274 | + $ccount = count($this->in_content); |
|
275 | + |
|
276 | + # if we are *in* content, then let's proceed to serialize it |
|
277 | + if(!empty($this->in_content)) { |
|
278 | + # if we are ending the original content element |
|
279 | + # then let's finalize the content |
|
280 | + if($this->in_content[0][0] == $tag && |
|
281 | + $this->in_content[0][1] == $this->depth) { |
|
282 | + $origtype = $this->in_content[0][2]; |
|
283 | + array_shift($this->in_content); |
|
284 | + $newcontent = array(); |
|
285 | + foreach($this->in_content as $c) { |
|
286 | + if(count($c) == 3) { |
|
287 | + array_push($newcontent, $c[2]); |
|
288 | + } else { |
|
289 | + if($this->is_xhtml || $this->is_text) { |
|
290 | + array_push($newcontent, $this->xml_escape($c)); |
|
291 | + } else { |
|
292 | + array_push($newcontent, $c); |
|
293 | + } |
|
294 | + } |
|
295 | + } |
|
296 | + if(in_array($tag, $this->ATOM_CONTENT_ELEMENTS)) { |
|
297 | + $this->current->$tag = array($origtype, join('',$newcontent)); |
|
298 | + } else { |
|
299 | + $this->current->$tag = join('',$newcontent); |
|
300 | + } |
|
301 | + $this->in_content = array(); |
|
302 | + } else if($this->in_content[$ccount-1][0] == $tag && |
|
303 | + $this->in_content[$ccount-1][1] == $this->depth) { |
|
304 | + $this->in_content[$ccount-1][2] = substr($this->in_content[$ccount-1][2],0,-1) . "/>"; |
|
305 | + } else { |
|
306 | + # else, just finalize the current element's content |
|
307 | + $endtag = $this->ns_to_prefix($name); |
|
308 | + array_push($this->in_content, array($tag, $this->depth, "</$endtag[1]>")); |
|
309 | + } |
|
310 | + } |
|
311 | + |
|
312 | + array_shift($this->ns_contexts); |
|
313 | + |
|
314 | + $this->depth--; |
|
315 | + |
|
316 | + if($name == ($this->NS . ':entry')) { |
|
317 | + array_push($this->feed->entries, $this->current); |
|
318 | + $this->current = null; |
|
319 | + } |
|
320 | + |
|
321 | + $this->_p("end_element('$name')"); |
|
322 | + } |
|
323 | + |
|
324 | + function start_ns($parser, $prefix, $uri) { |
|
325 | + $this->_p("starting: " . $prefix . ":" . $uri); |
|
326 | + array_push($this->ns_decls, array($prefix,$uri)); |
|
327 | + } |
|
328 | + |
|
329 | + function end_ns($parser, $prefix) { |
|
330 | + $this->_p("ending: #" . $prefix . "#"); |
|
331 | + } |
|
332 | + |
|
333 | + function cdata($parser, $data) { |
|
334 | + $this->_p("data: #" . str_replace(array("\n"), array("\\n"), trim($data)) . "#"); |
|
335 | + if(!empty($this->in_content)) { |
|
336 | + array_push($this->in_content, $data); |
|
337 | + } |
|
338 | + } |
|
339 | + |
|
340 | + function _default($parser, $data) { |
|
341 | + # when does this gets called? |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + function ns_to_prefix($qname, $attr=false) { |
|
346 | + # split 'http://www.w3.org/1999/xhtml:div' into ('http','//www.w3.org/1999/xhtml','div') |
|
347 | + $components = explode(":", $qname); |
|
348 | + |
|
349 | + # grab the last one (e.g 'div') |
|
350 | + $name = array_pop($components); |
|
351 | + |
|
352 | + if(!empty($components)) { |
|
353 | + # re-join back the namespace component |
|
354 | + $ns = join(":",$components); |
|
355 | + foreach($this->ns_contexts as $context) { |
|
356 | + foreach($context as $mapping) { |
|
357 | + if($mapping[1] == $ns && strlen($mapping[0]) > 0) { |
|
358 | + return array($mapping, "$mapping[0]:$name"); |
|
359 | + } |
|
360 | + } |
|
361 | + } |
|
362 | + } |
|
363 | + |
|
364 | + if($attr) { |
|
365 | + return array(null, $name); |
|
366 | + } else { |
|
367 | + foreach($this->ns_contexts as $context) { |
|
368 | + foreach($context as $mapping) { |
|
369 | + if(strlen($mapping[0]) == 0) { |
|
370 | + return array($mapping, $name); |
|
371 | + } |
|
372 | + } |
|
373 | + } |
|
374 | + } |
|
375 | + } |
|
376 | + |
|
377 | + function is_declared_content_ns($new_mapping) { |
|
378 | + foreach($this->content_ns_contexts as $context) { |
|
379 | + foreach($context as $mapping) { |
|
380 | + if($new_mapping == $mapping) { |
|
381 | + return true; |
|
382 | + } |
|
383 | + } |
|
384 | + } |
|
385 | + return false; |
|
386 | + } |
|
387 | + |
|
388 | + function xml_escape($string) |
|
389 | + { |
|
390 | + return str_replace(array('&','"',"'",'<','>'), |
|
391 | + array('&','"',''','<','>'), |
|
392 | + $string ); |
|
393 | + } |
|
394 | 394 | } |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | class AtomParser { |
66 | 66 | |
67 | 67 | var $NS = 'http://www.w3.org/2005/Atom'; |
68 | - var $ATOM_CONTENT_ELEMENTS = array('content','summary','title','subtitle','rights'); |
|
69 | - var $ATOM_SIMPLE_ELEMENTS = array('id','updated','published','draft'); |
|
68 | + var $ATOM_CONTENT_ELEMENTS = array('content', 'summary', 'title', 'subtitle', 'rights'); |
|
69 | + var $ATOM_SIMPLE_ELEMENTS = array('id', 'updated', 'published', 'draft'); |
|
70 | 70 | |
71 | 71 | var $debug = false; |
72 | 72 | |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | |
95 | 95 | $this->feed = new AtomFeed(); |
96 | 96 | $this->current = null; |
97 | - $this->map_attrs_func = array( __CLASS__, 'map_attrs' ); |
|
98 | - $this->map_xmlns_func = array( __CLASS__, 'map_xmlns' ); |
|
97 | + $this->map_attrs_func = array(__CLASS__, 'map_attrs'); |
|
98 | + $this->map_xmlns_func = array(__CLASS__, 'map_xmlns'); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -125,15 +125,15 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public static function map_xmlns($p, $n) { |
127 | 127 | $xd = "xmlns"; |
128 | - if( 0 < strlen($n[0]) ) { |
|
128 | + if (0 < strlen($n[0])) { |
|
129 | 129 | $xd .= ":{$n[0]}"; |
130 | 130 | } |
131 | 131 | return "{$xd}=\"{$n[1]}\""; |
132 | 132 | } |
133 | 133 | |
134 | 134 | function _p($msg) { |
135 | - if($this->debug) { |
|
136 | - print str_repeat(" ", $this->depth * $this->indent) . $msg ."\n"; |
|
135 | + if ($this->debug) { |
|
136 | + print str_repeat(" ", $this->depth * $this->indent).$msg."\n"; |
|
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
@@ -147,16 +147,16 @@ discard block |
||
147 | 147 | |
148 | 148 | array_unshift($this->ns_contexts, array()); |
149 | 149 | |
150 | - if ( ! function_exists( 'xml_parser_create_ns' ) ) { |
|
151 | - trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); |
|
150 | + if ( ! function_exists('xml_parser_create_ns')) { |
|
151 | + trigger_error(__("PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension.")); |
|
152 | 152 | return false; |
153 | 153 | } |
154 | 154 | |
155 | 155 | $parser = xml_parser_create_ns(); |
156 | 156 | xml_set_object($parser, $this); |
157 | 157 | xml_set_element_handler($parser, "start_element", "end_element"); |
158 | - xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0); |
|
159 | - xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,0); |
|
158 | + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); |
|
159 | + xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); |
|
160 | 160 | xml_set_character_data_handler($parser, "cdata"); |
161 | 161 | xml_set_default_handler($parser, "_default"); |
162 | 162 | xml_set_start_namespace_decl_handler($parser, "start_ns"); |
@@ -168,9 +168,9 @@ discard block |
||
168 | 168 | |
169 | 169 | $fp = fopen($this->FILE, "r"); |
170 | 170 | while ($data = fread($fp, 4096)) { |
171 | - if($this->debug) $this->content .= $data; |
|
171 | + if ($this->debug) $this->content .= $data; |
|
172 | 172 | |
173 | - if(!xml_parse($parser, $data, feof($fp))) { |
|
173 | + if ( ! xml_parse($parser, $data, feof($fp))) { |
|
174 | 174 | /* translators: 1: error message, 2: line number */ |
175 | 175 | trigger_error(sprintf(__('XML Error: %1$s at line %2$s')."\n", |
176 | 176 | xml_error_string(xml_get_error_code($parser)), |
@@ -192,11 +192,11 @@ discard block |
||
192 | 192 | |
193 | 193 | $tag = array_pop(explode(":", $name)); |
194 | 194 | |
195 | - switch($name) { |
|
196 | - case $this->NS . ':feed': |
|
195 | + switch ($name) { |
|
196 | + case $this->NS.':feed': |
|
197 | 197 | $this->current = $this->feed; |
198 | 198 | break; |
199 | - case $this->NS . ':entry': |
|
199 | + case $this->NS.':entry': |
|
200 | 200 | $this->current = new AtomEntry(); |
201 | 201 | break; |
202 | 202 | }; |
@@ -209,58 +209,58 @@ discard block |
||
209 | 209 | |
210 | 210 | $this->depth++; |
211 | 211 | |
212 | - if(!empty($this->in_content)) { |
|
212 | + if ( ! empty($this->in_content)) { |
|
213 | 213 | |
214 | 214 | $this->content_ns_decls = array(); |
215 | 215 | |
216 | - if($this->is_html || $this->is_text) |
|
216 | + if ($this->is_html || $this->is_text) |
|
217 | 217 | trigger_error("Invalid content in element found. Content must not be of type text or html if it contains markup."); |
218 | 218 | |
219 | 219 | $attrs_prefix = array(); |
220 | 220 | |
221 | 221 | // resolve prefixes for attributes |
222 | - foreach($attrs as $key => $value) { |
|
222 | + foreach ($attrs as $key => $value) { |
|
223 | 223 | $with_prefix = $this->ns_to_prefix($key, true); |
224 | 224 | $attrs_prefix[$with_prefix[1]] = $this->xml_escape($value); |
225 | 225 | } |
226 | 226 | |
227 | 227 | $attrs_str = join(' ', array_map($this->map_attrs_func, array_keys($attrs_prefix), array_values($attrs_prefix))); |
228 | - if(strlen($attrs_str) > 0) { |
|
229 | - $attrs_str = " " . $attrs_str; |
|
228 | + if (strlen($attrs_str) > 0) { |
|
229 | + $attrs_str = " ".$attrs_str; |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | $with_prefix = $this->ns_to_prefix($name); |
233 | 233 | |
234 | - if(!$this->is_declared_content_ns($with_prefix[0])) { |
|
234 | + if ( ! $this->is_declared_content_ns($with_prefix[0])) { |
|
235 | 235 | array_push($this->content_ns_decls, $with_prefix[0]); |
236 | 236 | } |
237 | 237 | |
238 | 238 | $xmlns_str = ''; |
239 | - if(count($this->content_ns_decls) > 0) { |
|
239 | + if (count($this->content_ns_decls) > 0) { |
|
240 | 240 | array_unshift($this->content_ns_contexts, $this->content_ns_decls); |
241 | 241 | $xmlns_str .= join(' ', array_map($this->map_xmlns_func, array_keys($this->content_ns_contexts[0]), array_values($this->content_ns_contexts[0]))); |
242 | - if(strlen($xmlns_str) > 0) { |
|
243 | - $xmlns_str = " " . $xmlns_str; |
|
242 | + if (strlen($xmlns_str) > 0) { |
|
243 | + $xmlns_str = " ".$xmlns_str; |
|
244 | 244 | } |
245 | 245 | } |
246 | 246 | |
247 | - array_push($this->in_content, array($tag, $this->depth, "<". $with_prefix[1] ."{$xmlns_str}{$attrs_str}" . ">")); |
|
247 | + array_push($this->in_content, array($tag, $this->depth, "<".$with_prefix[1]."{$xmlns_str}{$attrs_str}".">")); |
|
248 | 248 | |
249 | - } else if(in_array($tag, $this->ATOM_CONTENT_ELEMENTS) || in_array($tag, $this->ATOM_SIMPLE_ELEMENTS)) { |
|
249 | + } else if (in_array($tag, $this->ATOM_CONTENT_ELEMENTS) || in_array($tag, $this->ATOM_SIMPLE_ELEMENTS)) { |
|
250 | 250 | $this->in_content = array(); |
251 | 251 | $this->is_xhtml = $attrs['type'] == 'xhtml'; |
252 | 252 | $this->is_html = $attrs['type'] == 'html' || $attrs['type'] == 'text/html'; |
253 | - $this->is_text = !in_array('type',array_keys($attrs)) || $attrs['type'] == 'text'; |
|
253 | + $this->is_text = ! in_array('type', array_keys($attrs)) || $attrs['type'] == 'text'; |
|
254 | 254 | $type = $this->is_xhtml ? 'XHTML' : ($this->is_html ? 'HTML' : ($this->is_text ? 'TEXT' : $attrs['type'])); |
255 | 255 | |
256 | - if(in_array('src',array_keys($attrs))) { |
|
256 | + if (in_array('src', array_keys($attrs))) { |
|
257 | 257 | $this->current->$tag = $attrs; |
258 | 258 | } else { |
259 | - array_push($this->in_content, array($tag,$this->depth, $type)); |
|
259 | + array_push($this->in_content, array($tag, $this->depth, $type)); |
|
260 | 260 | } |
261 | - } else if($tag == 'link') { |
|
261 | + } else if ($tag == 'link') { |
|
262 | 262 | array_push($this->current->links, $attrs); |
263 | - } else if($tag == 'category') { |
|
263 | + } else if ($tag == 'category') { |
|
264 | 264 | array_push($this->current->categories, $attrs); |
265 | 265 | } |
266 | 266 | |
@@ -274,34 +274,34 @@ discard block |
||
274 | 274 | $ccount = count($this->in_content); |
275 | 275 | |
276 | 276 | # if we are *in* content, then let's proceed to serialize it |
277 | - if(!empty($this->in_content)) { |
|
277 | + if ( ! empty($this->in_content)) { |
|
278 | 278 | # if we are ending the original content element |
279 | 279 | # then let's finalize the content |
280 | - if($this->in_content[0][0] == $tag && |
|
280 | + if ($this->in_content[0][0] == $tag && |
|
281 | 281 | $this->in_content[0][1] == $this->depth) { |
282 | 282 | $origtype = $this->in_content[0][2]; |
283 | 283 | array_shift($this->in_content); |
284 | 284 | $newcontent = array(); |
285 | - foreach($this->in_content as $c) { |
|
286 | - if(count($c) == 3) { |
|
285 | + foreach ($this->in_content as $c) { |
|
286 | + if (count($c) == 3) { |
|
287 | 287 | array_push($newcontent, $c[2]); |
288 | 288 | } else { |
289 | - if($this->is_xhtml || $this->is_text) { |
|
289 | + if ($this->is_xhtml || $this->is_text) { |
|
290 | 290 | array_push($newcontent, $this->xml_escape($c)); |
291 | 291 | } else { |
292 | 292 | array_push($newcontent, $c); |
293 | 293 | } |
294 | 294 | } |
295 | 295 | } |
296 | - if(in_array($tag, $this->ATOM_CONTENT_ELEMENTS)) { |
|
297 | - $this->current->$tag = array($origtype, join('',$newcontent)); |
|
296 | + if (in_array($tag, $this->ATOM_CONTENT_ELEMENTS)) { |
|
297 | + $this->current->$tag = array($origtype, join('', $newcontent)); |
|
298 | 298 | } else { |
299 | - $this->current->$tag = join('',$newcontent); |
|
299 | + $this->current->$tag = join('', $newcontent); |
|
300 | 300 | } |
301 | 301 | $this->in_content = array(); |
302 | - } else if($this->in_content[$ccount-1][0] == $tag && |
|
303 | - $this->in_content[$ccount-1][1] == $this->depth) { |
|
304 | - $this->in_content[$ccount-1][2] = substr($this->in_content[$ccount-1][2],0,-1) . "/>"; |
|
302 | + } else if ($this->in_content[$ccount - 1][0] == $tag && |
|
303 | + $this->in_content[$ccount - 1][1] == $this->depth) { |
|
304 | + $this->in_content[$ccount - 1][2] = substr($this->in_content[$ccount - 1][2], 0, -1)."/>"; |
|
305 | 305 | } else { |
306 | 306 | # else, just finalize the current element's content |
307 | 307 | $endtag = $this->ns_to_prefix($name); |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | |
314 | 314 | $this->depth--; |
315 | 315 | |
316 | - if($name == ($this->NS . ':entry')) { |
|
316 | + if ($name == ($this->NS.':entry')) { |
|
317 | 317 | array_push($this->feed->entries, $this->current); |
318 | 318 | $this->current = null; |
319 | 319 | } |
@@ -322,17 +322,17 @@ discard block |
||
322 | 322 | } |
323 | 323 | |
324 | 324 | function start_ns($parser, $prefix, $uri) { |
325 | - $this->_p("starting: " . $prefix . ":" . $uri); |
|
326 | - array_push($this->ns_decls, array($prefix,$uri)); |
|
325 | + $this->_p("starting: ".$prefix.":".$uri); |
|
326 | + array_push($this->ns_decls, array($prefix, $uri)); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | function end_ns($parser, $prefix) { |
330 | - $this->_p("ending: #" . $prefix . "#"); |
|
330 | + $this->_p("ending: #".$prefix."#"); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | function cdata($parser, $data) { |
334 | - $this->_p("data: #" . str_replace(array("\n"), array("\\n"), trim($data)) . "#"); |
|
335 | - if(!empty($this->in_content)) { |
|
334 | + $this->_p("data: #".str_replace(array("\n"), array("\\n"), trim($data))."#"); |
|
335 | + if ( ! empty($this->in_content)) { |
|
336 | 336 | array_push($this->in_content, $data); |
337 | 337 | } |
338 | 338 | } |
@@ -342,31 +342,31 @@ discard block |
||
342 | 342 | } |
343 | 343 | |
344 | 344 | |
345 | - function ns_to_prefix($qname, $attr=false) { |
|
345 | + function ns_to_prefix($qname, $attr = false) { |
|
346 | 346 | # split 'http://www.w3.org/1999/xhtml:div' into ('http','//www.w3.org/1999/xhtml','div') |
347 | 347 | $components = explode(":", $qname); |
348 | 348 | |
349 | 349 | # grab the last one (e.g 'div') |
350 | 350 | $name = array_pop($components); |
351 | 351 | |
352 | - if(!empty($components)) { |
|
352 | + if ( ! empty($components)) { |
|
353 | 353 | # re-join back the namespace component |
354 | - $ns = join(":",$components); |
|
355 | - foreach($this->ns_contexts as $context) { |
|
356 | - foreach($context as $mapping) { |
|
357 | - if($mapping[1] == $ns && strlen($mapping[0]) > 0) { |
|
354 | + $ns = join(":", $components); |
|
355 | + foreach ($this->ns_contexts as $context) { |
|
356 | + foreach ($context as $mapping) { |
|
357 | + if ($mapping[1] == $ns && strlen($mapping[0]) > 0) { |
|
358 | 358 | return array($mapping, "$mapping[0]:$name"); |
359 | 359 | } |
360 | 360 | } |
361 | 361 | } |
362 | 362 | } |
363 | 363 | |
364 | - if($attr) { |
|
364 | + if ($attr) { |
|
365 | 365 | return array(null, $name); |
366 | 366 | } else { |
367 | - foreach($this->ns_contexts as $context) { |
|
368 | - foreach($context as $mapping) { |
|
369 | - if(strlen($mapping[0]) == 0) { |
|
367 | + foreach ($this->ns_contexts as $context) { |
|
368 | + foreach ($context as $mapping) { |
|
369 | + if (strlen($mapping[0]) == 0) { |
|
370 | 370 | return array($mapping, $name); |
371 | 371 | } |
372 | 372 | } |
@@ -375,9 +375,9 @@ discard block |
||
375 | 375 | } |
376 | 376 | |
377 | 377 | function is_declared_content_ns($new_mapping) { |
378 | - foreach($this->content_ns_contexts as $context) { |
|
379 | - foreach($context as $mapping) { |
|
380 | - if($new_mapping == $mapping) { |
|
378 | + foreach ($this->content_ns_contexts as $context) { |
|
379 | + foreach ($context as $mapping) { |
|
380 | + if ($new_mapping == $mapping) { |
|
381 | 381 | return true; |
382 | 382 | } |
383 | 383 | } |
@@ -387,8 +387,8 @@ discard block |
||
387 | 387 | |
388 | 388 | function xml_escape($string) |
389 | 389 | { |
390 | - return str_replace(array('&','"',"'",'<','>'), |
|
391 | - array('&','"',''','<','>'), |
|
392 | - $string ); |
|
390 | + return str_replace(array('&', '"', "'", '<', '>'), |
|
391 | + array('&', '"', ''', '<', '>'), |
|
392 | + $string); |
|
393 | 393 | } |
394 | 394 | } |
@@ -44,17 +44,20 @@ discard block |
||
44 | 44 | * @return bool |
45 | 45 | */ |
46 | 46 | public function do_item( $handle ) { |
47 | - if ( !parent::do_item($handle) ) |
|
48 | - return false; |
|
47 | + if ( !parent::do_item($handle) ) { |
|
48 | + return false; |
|
49 | + } |
|
49 | 50 | |
50 | 51 | $obj = $this->registered[$handle]; |
51 | - if ( null === $obj->ver ) |
|
52 | - $ver = ''; |
|
53 | - else |
|
54 | - $ver = $obj->ver ? $obj->ver : $this->default_version; |
|
52 | + if ( null === $obj->ver ) { |
|
53 | + $ver = ''; |
|
54 | + } else { |
|
55 | + $ver = $obj->ver ? $obj->ver : $this->default_version; |
|
56 | + } |
|
55 | 57 | |
56 | - if ( isset($this->args[$handle]) ) |
|
57 | - $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; |
|
58 | + if ( isset($this->args[$handle]) ) { |
|
59 | + $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; |
|
60 | + } |
|
58 | 61 | |
59 | 62 | if ( $this->do_concat ) { |
60 | 63 | if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt']) ) { |
@@ -67,10 +70,11 @@ discard block |
||
67 | 70 | } |
68 | 71 | } |
69 | 72 | |
70 | - if ( isset($obj->args) ) |
|
71 | - $media = esc_attr( $obj->args ); |
|
72 | - else |
|
73 | - $media = 'all'; |
|
73 | + if ( isset($obj->args) ) { |
|
74 | + $media = esc_attr( $obj->args ); |
|
75 | + } else { |
|
76 | + $media = 'all'; |
|
77 | + } |
|
74 | 78 | |
75 | 79 | $href = $this->_css_href( $obj->src, $ver, $handle ); |
76 | 80 | if ( empty( $href ) ) { |
@@ -206,8 +210,9 @@ discard block |
||
206 | 210 | $src = $this->base_url . $src; |
207 | 211 | } |
208 | 212 | |
209 | - if ( !empty($ver) ) |
|
210 | - $src = add_query_arg('ver', $ver, $src); |
|
213 | + if ( !empty($ver) ) { |
|
214 | + $src = add_query_arg('ver', $ver, $src); |
|
215 | + } |
|
211 | 216 | |
212 | 217 | /** |
213 | 218 | * Filter an enqueued style's fully-qualified URL. |
@@ -226,12 +231,14 @@ discard block |
||
226 | 231 | * @return bool |
227 | 232 | */ |
228 | 233 | public function in_default_dir($src) { |
229 | - if ( ! $this->default_dirs ) |
|
230 | - return true; |
|
234 | + if ( ! $this->default_dirs ) { |
|
235 | + return true; |
|
236 | + } |
|
231 | 237 | |
232 | 238 | foreach ( (array) $this->default_dirs as $test ) { |
233 | - if ( 0 === strpos($src, $test) ) |
|
234 | - return true; |
|
239 | + if ( 0 === strpos($src, $test) ) { |
|
240 | + return true; |
|
241 | + } |
|
235 | 242 | } |
236 | 243 | return false; |
237 | 244 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @param WP_Styles &$this WP_Styles instance, passed by reference. |
126 | 126 | */ |
127 | - do_action_ref_array( 'wp_default_styles', array(&$this) ); |
|
127 | + do_action_ref_array('wp_default_styles', array(&$this)); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -138,40 +138,40 @@ discard block |
||
138 | 138 | * @param string $handle The style's registered handle. |
139 | 139 | * @return bool True on success, false on failure. |
140 | 140 | */ |
141 | - public function do_item( $handle ) { |
|
142 | - if ( !parent::do_item($handle) ) |
|
141 | + public function do_item($handle) { |
|
142 | + if ( ! parent::do_item($handle)) |
|
143 | 143 | return false; |
144 | 144 | |
145 | 145 | $obj = $this->registered[$handle]; |
146 | - if ( null === $obj->ver ) |
|
146 | + if (null === $obj->ver) |
|
147 | 147 | $ver = ''; |
148 | 148 | else |
149 | 149 | $ver = $obj->ver ? $obj->ver : $this->default_version; |
150 | 150 | |
151 | - if ( isset($this->args[$handle]) ) |
|
152 | - $ver = $ver ? $ver . '&' . $this->args[$handle] : $this->args[$handle]; |
|
151 | + if (isset($this->args[$handle])) |
|
152 | + $ver = $ver ? $ver.'&'.$this->args[$handle] : $this->args[$handle]; |
|
153 | 153 | |
154 | - if ( $this->do_concat ) { |
|
155 | - if ( $this->in_default_dir($obj->src) && !isset($obj->extra['conditional']) && !isset($obj->extra['alt']) ) { |
|
154 | + if ($this->do_concat) { |
|
155 | + if ($this->in_default_dir($obj->src) && ! isset($obj->extra['conditional']) && ! isset($obj->extra['alt'])) { |
|
156 | 156 | $this->concat .= "$handle,"; |
157 | 157 | $this->concat_version .= "$handle$ver"; |
158 | 158 | |
159 | - $this->print_code .= $this->print_inline_style( $handle, false ); |
|
159 | + $this->print_code .= $this->print_inline_style($handle, false); |
|
160 | 160 | |
161 | 161 | return true; |
162 | 162 | } |
163 | 163 | } |
164 | 164 | |
165 | - if ( isset($obj->args) ) |
|
166 | - $media = esc_attr( $obj->args ); |
|
165 | + if (isset($obj->args)) |
|
166 | + $media = esc_attr($obj->args); |
|
167 | 167 | else |
168 | 168 | $media = 'all'; |
169 | 169 | |
170 | 170 | // A single item may alias a set of items, by having dependencies, but no source. |
171 | - if ( ! $obj->src ) { |
|
172 | - if ( $inline_style = $this->print_inline_style( $handle, false ) ) { |
|
173 | - $inline_style = sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style ); |
|
174 | - if ( $this->do_concat ) { |
|
171 | + if ( ! $obj->src) { |
|
172 | + if ($inline_style = $this->print_inline_style($handle, false)) { |
|
173 | + $inline_style = sprintf("<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr($handle), $inline_style); |
|
174 | + if ($this->do_concat) { |
|
175 | 175 | $this->print_html .= $inline_style; |
176 | 176 | } else { |
177 | 177 | echo $inline_style; |
@@ -180,13 +180,13 @@ discard block |
||
180 | 180 | return true; |
181 | 181 | } |
182 | 182 | |
183 | - $href = $this->_css_href( $obj->src, $ver, $handle ); |
|
184 | - if ( ! $href ) { |
|
183 | + $href = $this->_css_href($obj->src, $ver, $handle); |
|
184 | + if ( ! $href) { |
|
185 | 185 | return true; |
186 | 186 | } |
187 | 187 | |
188 | 188 | $rel = isset($obj->extra['alt']) && $obj->extra['alt'] ? 'alternate stylesheet' : 'stylesheet'; |
189 | - $title = isset($obj->extra['title']) ? "title='" . esc_attr( $obj->extra['title'] ) . "'" : ''; |
|
189 | + $title = isset($obj->extra['title']) ? "title='".esc_attr($obj->extra['title'])."'" : ''; |
|
190 | 190 | |
191 | 191 | /** |
192 | 192 | * Filter the HTML link tag of an enqueued style. |
@@ -200,19 +200,19 @@ discard block |
||
200 | 200 | * @param string $href The stylesheet's source URL. |
201 | 201 | * @param string $media The stylesheet's media attribute. |
202 | 202 | */ |
203 | - $tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle, $href, $media); |
|
204 | - if ( 'rtl' === $this->text_direction && isset($obj->extra['rtl']) && $obj->extra['rtl'] ) { |
|
205 | - if ( is_bool( $obj->extra['rtl'] ) || 'replace' === $obj->extra['rtl'] ) { |
|
206 | - $suffix = isset( $obj->extra['suffix'] ) ? $obj->extra['suffix'] : ''; |
|
207 | - $rtl_href = str_replace( "{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href( $obj->src , $ver, "$handle-rtl" )); |
|
203 | + $tag = apply_filters('style_loader_tag', "<link rel='$rel' id='$handle-css' $title href='$href' type='text/css' media='$media' />\n", $handle, $href, $media); |
|
204 | + if ('rtl' === $this->text_direction && isset($obj->extra['rtl']) && $obj->extra['rtl']) { |
|
205 | + if (is_bool($obj->extra['rtl']) || 'replace' === $obj->extra['rtl']) { |
|
206 | + $suffix = isset($obj->extra['suffix']) ? $obj->extra['suffix'] : ''; |
|
207 | + $rtl_href = str_replace("{$suffix}.css", "-rtl{$suffix}.css", $this->_css_href($obj->src, $ver, "$handle-rtl")); |
|
208 | 208 | } else { |
209 | - $rtl_href = $this->_css_href( $obj->extra['rtl'], $ver, "$handle-rtl" ); |
|
209 | + $rtl_href = $this->_css_href($obj->extra['rtl'], $ver, "$handle-rtl"); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** This filter is documented in wp-includes/class.wp-styles.php */ |
213 | - $rtl_tag = apply_filters( 'style_loader_tag', "<link rel='$rel' id='$handle-rtl-css' $title href='$rtl_href' type='text/css' media='$media' />\n", $handle, $rtl_href, $media ); |
|
213 | + $rtl_tag = apply_filters('style_loader_tag', "<link rel='$rel' id='$handle-rtl-css' $title href='$rtl_href' type='text/css' media='$media' />\n", $handle, $rtl_href, $media); |
|
214 | 214 | |
215 | - if ( $obj->extra['rtl'] === 'replace' ) { |
|
215 | + if ($obj->extra['rtl'] === 'replace') { |
|
216 | 216 | $tag = $rtl_tag; |
217 | 217 | } else { |
218 | 218 | $tag .= $rtl_tag; |
@@ -220,22 +220,22 @@ discard block |
||
220 | 220 | } |
221 | 221 | |
222 | 222 | $conditional_pre = $conditional_post = ''; |
223 | - if ( isset( $obj->extra['conditional'] ) && $obj->extra['conditional'] ) { |
|
223 | + if (isset($obj->extra['conditional']) && $obj->extra['conditional']) { |
|
224 | 224 | $conditional_pre = "<!--[if {$obj->extra['conditional']}]>\n"; |
225 | 225 | $conditional_post = "<![endif]-->\n"; |
226 | 226 | } |
227 | 227 | |
228 | - if ( $this->do_concat ) { |
|
228 | + if ($this->do_concat) { |
|
229 | 229 | $this->print_html .= $conditional_pre; |
230 | 230 | $this->print_html .= $tag; |
231 | - if ( $inline_style = $this->print_inline_style( $handle, false ) ) { |
|
232 | - $this->print_html .= sprintf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $inline_style ); |
|
231 | + if ($inline_style = $this->print_inline_style($handle, false)) { |
|
232 | + $this->print_html .= sprintf("<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr($handle), $inline_style); |
|
233 | 233 | } |
234 | 234 | $this->print_html .= $conditional_post; |
235 | 235 | } else { |
236 | 236 | echo $conditional_pre; |
237 | 237 | echo $tag; |
238 | - $this->print_inline_style( $handle ); |
|
238 | + $this->print_inline_style($handle); |
|
239 | 239 | echo $conditional_post; |
240 | 240 | } |
241 | 241 | |
@@ -252,19 +252,19 @@ discard block |
||
252 | 252 | * @param string $code String containing the CSS styles to be added. |
253 | 253 | * @return bool True on success, false on failure. |
254 | 254 | */ |
255 | - public function add_inline_style( $handle, $code ) { |
|
256 | - if ( ! $code ) { |
|
255 | + public function add_inline_style($handle, $code) { |
|
256 | + if ( ! $code) { |
|
257 | 257 | return false; |
258 | 258 | } |
259 | 259 | |
260 | - $after = $this->get_data( $handle, 'after' ); |
|
261 | - if ( ! $after ) { |
|
260 | + $after = $this->get_data($handle, 'after'); |
|
261 | + if ( ! $after) { |
|
262 | 262 | $after = array(); |
263 | 263 | } |
264 | 264 | |
265 | 265 | $after[] = $code; |
266 | 266 | |
267 | - return $this->add_data( $handle, 'after', $after ); |
|
267 | + return $this->add_data($handle, 'after', $after); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | /** |
@@ -278,20 +278,20 @@ discard block |
||
278 | 278 | * Default true. |
279 | 279 | * @return string|bool False if no data exists, inline styles if `$echo` is true, true otherwise. |
280 | 280 | */ |
281 | - public function print_inline_style( $handle, $echo = true ) { |
|
282 | - $output = $this->get_data( $handle, 'after' ); |
|
281 | + public function print_inline_style($handle, $echo = true) { |
|
282 | + $output = $this->get_data($handle, 'after'); |
|
283 | 283 | |
284 | - if ( empty( $output ) ) { |
|
284 | + if (empty($output)) { |
|
285 | 285 | return false; |
286 | 286 | } |
287 | 287 | |
288 | - $output = implode( "\n", $output ); |
|
288 | + $output = implode("\n", $output); |
|
289 | 289 | |
290 | - if ( ! $echo ) { |
|
290 | + if ( ! $echo) { |
|
291 | 291 | return $output; |
292 | 292 | } |
293 | 293 | |
294 | - printf( "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr( $handle ), $output ); |
|
294 | + printf("<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n", esc_attr($handle), $output); |
|
295 | 295 | |
296 | 296 | return true; |
297 | 297 | } |
@@ -309,9 +309,9 @@ discard block |
||
309 | 309 | * @param int|false $group Group level: (int) level, (false) no groups. |
310 | 310 | * @return bool True on success, false on failure. |
311 | 311 | */ |
312 | - public function all_deps( $handles, $recursion = false, $group = false ) { |
|
313 | - $r = parent::all_deps( $handles, $recursion, $group ); |
|
314 | - if ( ! $recursion ) { |
|
312 | + public function all_deps($handles, $recursion = false, $group = false) { |
|
313 | + $r = parent::all_deps($handles, $recursion, $group); |
|
314 | + if ( ! $recursion) { |
|
315 | 315 | /** |
316 | 316 | * Filter the array of enqueued styles before processing for output. |
317 | 317 | * |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * |
320 | 320 | * @param array $to_do The list of enqueued styles about to be processed. |
321 | 321 | */ |
322 | - $this->to_do = apply_filters( 'print_styles_array', $this->to_do ); |
|
322 | + $this->to_do = apply_filters('print_styles_array', $this->to_do); |
|
323 | 323 | } |
324 | 324 | return $r; |
325 | 325 | } |
@@ -335,12 +335,12 @@ discard block |
||
335 | 335 | * @param string $handle The style's registered handle. |
336 | 336 | * @return string Style's fully-qualified URL. |
337 | 337 | */ |
338 | - public function _css_href( $src, $ver, $handle ) { |
|
339 | - if ( !is_bool($src) && !preg_match('|^(https?:)?//|', $src) && ! ( $this->content_url && 0 === strpos($src, $this->content_url) ) ) { |
|
340 | - $src = $this->base_url . $src; |
|
338 | + public function _css_href($src, $ver, $handle) { |
|
339 | + if ( ! is_bool($src) && ! preg_match('|^(https?:)?//|', $src) && ! ($this->content_url && 0 === strpos($src, $this->content_url))) { |
|
340 | + $src = $this->base_url.$src; |
|
341 | 341 | } |
342 | 342 | |
343 | - if ( !empty($ver) ) |
|
343 | + if ( ! empty($ver)) |
|
344 | 344 | $src = add_query_arg('ver', $ver, $src); |
345 | 345 | |
346 | 346 | /** |
@@ -351,8 +351,8 @@ discard block |
||
351 | 351 | * @param string $src The source URL of the enqueued style. |
352 | 352 | * @param string $handle The style's registered handle. |
353 | 353 | */ |
354 | - $src = apply_filters( 'style_loader_src', $src, $handle ); |
|
355 | - return esc_url( $src ); |
|
354 | + $src = apply_filters('style_loader_src', $src, $handle); |
|
355 | + return esc_url($src); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | /** |
@@ -364,12 +364,12 @@ discard block |
||
364 | 364 | * @param string $src The source of the enqueued style. |
365 | 365 | * @return bool True if found, false if not. |
366 | 366 | */ |
367 | - public function in_default_dir( $src ) { |
|
368 | - if ( ! $this->default_dirs ) |
|
367 | + public function in_default_dir($src) { |
|
368 | + if ( ! $this->default_dirs) |
|
369 | 369 | return true; |
370 | 370 | |
371 | - foreach ( (array) $this->default_dirs as $test ) { |
|
372 | - if ( 0 === strpos($src, $test) ) |
|
371 | + foreach ((array) $this->default_dirs as $test) { |
|
372 | + if (0 === strpos($src, $test)) |
|
373 | 373 | return true; |
374 | 374 | } |
375 | 375 | return false; |
@@ -42,8 +42,9 @@ discard block |
||
42 | 42 | * @return bool |
43 | 43 | */ |
44 | 44 | public static function test( $args = array() ) { |
45 | - if ( ! extension_loaded('gd') || ! function_exists('gd_info') ) |
|
46 | - return false; |
|
45 | + if ( ! extension_loaded('gd') || ! function_exists('gd_info') ) { |
|
46 | + return false; |
|
47 | + } |
|
47 | 48 | |
48 | 49 | // On some setups GD library does not provide imagerotate() - Ticket #11536 |
49 | 50 | if ( isset( $args['methods'] ) && |
@@ -90,11 +91,13 @@ discard block |
||
90 | 91 | * @return bool|WP_Error True if loaded successfully; WP_Error on failure. |
91 | 92 | */ |
92 | 93 | public function load() { |
93 | - if ( $this->image ) |
|
94 | - return true; |
|
94 | + if ( $this->image ) { |
|
95 | + return true; |
|
96 | + } |
|
95 | 97 | |
96 | - if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) ) |
|
97 | - return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file ); |
|
98 | + if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) ) { |
|
99 | + return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file ); |
|
100 | + } |
|
98 | 101 | |
99 | 102 | /** |
100 | 103 | * Filter the memory limit allocated for image manipulation. |
@@ -109,12 +112,14 @@ discard block |
||
109 | 112 | |
110 | 113 | $this->image = @imagecreatefromstring( file_get_contents( $this->file ) ); |
111 | 114 | |
112 | - if ( ! is_resource( $this->image ) ) |
|
113 | - return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file ); |
|
115 | + if ( ! is_resource( $this->image ) ) { |
|
116 | + return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file ); |
|
117 | + } |
|
114 | 118 | |
115 | 119 | $size = @getimagesize( $this->file ); |
116 | - if ( ! $size ) |
|
117 | - return new WP_Error( 'invalid_image', __('Could not read image size.'), $this->file ); |
|
120 | + if ( ! $size ) { |
|
121 | + return new WP_Error( 'invalid_image', __('Could not read image size.'), $this->file ); |
|
122 | + } |
|
118 | 123 | |
119 | 124 | if ( function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) { |
120 | 125 | imagealphablending( $this->image, false ); |
@@ -138,11 +143,13 @@ discard block |
||
138 | 143 | * @return true |
139 | 144 | */ |
140 | 145 | protected function update_size( $width = false, $height = false ) { |
141 | - if ( ! $width ) |
|
142 | - $width = imagesx( $this->image ); |
|
146 | + if ( ! $width ) { |
|
147 | + $width = imagesx( $this->image ); |
|
148 | + } |
|
143 | 149 | |
144 | - if ( ! $height ) |
|
145 | - $height = imagesy( $this->image ); |
|
150 | + if ( ! $height ) { |
|
151 | + $height = imagesy( $this->image ); |
|
152 | + } |
|
146 | 153 | |
147 | 154 | return parent::update_size( $width, $height ); |
148 | 155 | } |
@@ -164,8 +171,9 @@ discard block |
||
164 | 171 | * @return true|WP_Error |
165 | 172 | */ |
166 | 173 | public function resize( $max_w, $max_h, $crop = false ) { |
167 | - if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) |
|
168 | - return true; |
|
174 | + if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) { |
|
175 | + return true; |
|
176 | + } |
|
169 | 177 | |
170 | 178 | $resized = $this->_resize( $max_w, $max_h, $crop ); |
171 | 179 | |
@@ -174,8 +182,9 @@ discard block |
||
174 | 182 | $this->image = $resized; |
175 | 183 | return true; |
176 | 184 | |
177 | - } elseif ( is_wp_error( $resized ) ) |
|
178 | - return $resized; |
|
185 | + } elseif ( is_wp_error( $resized ) ) { |
|
186 | + return $resized; |
|
187 | + } |
|
179 | 188 | |
180 | 189 | return new WP_Error( 'image_resize_error', __('Image resize failed.'), $this->file ); |
181 | 190 | } |
@@ -284,10 +293,12 @@ discard block |
||
284 | 293 | public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) { |
285 | 294 | // If destination width/height isn't specified, use same as |
286 | 295 | // width/height from source. |
287 | - if ( ! $dst_w ) |
|
288 | - $dst_w = $src_w; |
|
289 | - if ( ! $dst_h ) |
|
290 | - $dst_h = $src_h; |
|
296 | + if ( ! $dst_w ) { |
|
297 | + $dst_w = $src_w; |
|
298 | + } |
|
299 | + if ( ! $dst_h ) { |
|
300 | + $dst_h = $src_h; |
|
301 | + } |
|
291 | 302 | |
292 | 303 | $dst = wp_imagecreatetruecolor( $dst_w, $dst_h ); |
293 | 304 | |
@@ -296,8 +307,9 @@ discard block |
||
296 | 307 | $src_h -= $src_y; |
297 | 308 | } |
298 | 309 | |
299 | - if ( function_exists( 'imageantialias' ) ) |
|
300 | - imageantialias( $dst, true ); |
|
310 | + if ( function_exists( 'imageantialias' ) ) { |
|
311 | + imageantialias( $dst, true ); |
|
312 | + } |
|
301 | 313 | |
302 | 314 | imagecopyresampled( $dst, $this->image, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); |
303 | 315 | |
@@ -398,26 +410,28 @@ discard block |
||
398 | 410 | protected function _save( $image, $filename = null, $mime_type = null ) { |
399 | 411 | list( $filename, $extension, $mime_type ) = $this->get_output_format( $filename, $mime_type ); |
400 | 412 | |
401 | - if ( ! $filename ) |
|
402 | - $filename = $this->generate_filename( null, null, $extension ); |
|
413 | + if ( ! $filename ) { |
|
414 | + $filename = $this->generate_filename( null, null, $extension ); |
|
415 | + } |
|
403 | 416 | |
404 | 417 | if ( 'image/gif' == $mime_type ) { |
405 | - if ( ! $this->make_image( $filename, 'imagegif', array( $image, $filename ) ) ) |
|
406 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
407 | - } |
|
408 | - elseif ( 'image/png' == $mime_type ) { |
|
418 | + if ( ! $this->make_image( $filename, 'imagegif', array( $image, $filename ) ) ) { |
|
419 | + return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
420 | + } |
|
421 | + } elseif ( 'image/png' == $mime_type ) { |
|
409 | 422 | // convert from full colors to index colors, like original PNG. |
410 | - if ( function_exists('imageistruecolor') && ! imageistruecolor( $image ) ) |
|
411 | - imagetruecolortopalette( $image, false, imagecolorstotal( $image ) ); |
|
423 | + if ( function_exists('imageistruecolor') && ! imageistruecolor( $image ) ) { |
|
424 | + imagetruecolortopalette( $image, false, imagecolorstotal( $image ) ); |
|
425 | + } |
|
412 | 426 | |
413 | - if ( ! $this->make_image( $filename, 'imagepng', array( $image, $filename ) ) ) |
|
414 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
415 | - } |
|
416 | - elseif ( 'image/jpeg' == $mime_type ) { |
|
417 | - if ( ! $this->make_image( $filename, 'imagejpeg', array( $image, $filename, $this->get_quality() ) ) ) |
|
418 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
419 | - } |
|
420 | - else { |
|
427 | + if ( ! $this->make_image( $filename, 'imagepng', array( $image, $filename ) ) ) { |
|
428 | + return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
429 | + } |
|
430 | + } elseif ( 'image/jpeg' == $mime_type ) { |
|
431 | + if ( ! $this->make_image( $filename, 'imagejpeg', array( $image, $filename, $this->get_quality() ) ) ) { |
|
432 | + return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
433 | + } |
|
434 | + } else { |
|
421 | 435 | return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
422 | 436 | } |
423 | 437 | |
@@ -479,8 +493,9 @@ discard block |
||
479 | 493 | * @return bool |
480 | 494 | */ |
481 | 495 | protected function make_image( $filename, $function, $arguments ) { |
482 | - if ( wp_is_stream( $filename ) ) |
|
483 | - $arguments[1] = null; |
|
496 | + if ( wp_is_stream( $filename ) ) { |
|
497 | + $arguments[1] = null; |
|
498 | + } |
|
484 | 499 | |
485 | 500 | return parent::make_image( $filename, $function, $arguments ); |
486 | 501 | } |
@@ -68,7 +68,7 @@ |
||
68 | 68 | |
69 | 69 | /** |
70 | 70 | * @param resource $fh |
71 | - * @return true |
|
71 | + * @return boolean |
|
72 | 72 | */ |
73 | 73 | function export_to_file_handle($fh) { |
74 | 74 | $entries = array_filter( $this->entries, array( $this, 'is_entry_good_for_export' ) ); |
@@ -24,9 +24,9 @@ discard block |
||
24 | 24 | protected $image; |
25 | 25 | |
26 | 26 | public function __destruct() { |
27 | - if ( $this->image ) { |
|
27 | + if ($this->image) { |
|
28 | 28 | // we don't need the original in memory anymore |
29 | - imagedestroy( $this->image ); |
|
29 | + imagedestroy($this->image); |
|
30 | 30 | } |
31 | 31 | } |
32 | 32 | |
@@ -41,14 +41,14 @@ discard block |
||
41 | 41 | * @param array $args |
42 | 42 | * @return bool |
43 | 43 | */ |
44 | - public static function test( $args = array() ) { |
|
45 | - if ( ! extension_loaded('gd') || ! function_exists('gd_info') ) |
|
44 | + public static function test($args = array()) { |
|
45 | + if ( ! extension_loaded('gd') || ! function_exists('gd_info')) |
|
46 | 46 | return false; |
47 | 47 | |
48 | 48 | // On some setups GD library does not provide imagerotate() - Ticket #11536 |
49 | - if ( isset( $args['methods'] ) && |
|
50 | - in_array( 'rotate', $args['methods'] ) && |
|
51 | - ! function_exists('imagerotate') ){ |
|
49 | + if (isset($args['methods']) && |
|
50 | + in_array('rotate', $args['methods']) && |
|
51 | + ! function_exists('imagerotate')) { |
|
52 | 52 | |
53 | 53 | return false; |
54 | 54 | } |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | * @param string $mime_type |
68 | 68 | * @return bool |
69 | 69 | */ |
70 | - public static function supports_mime_type( $mime_type ) { |
|
70 | + public static function supports_mime_type($mime_type) { |
|
71 | 71 | $image_types = imagetypes(); |
72 | - switch( $mime_type ) { |
|
72 | + switch ($mime_type) { |
|
73 | 73 | case 'image/jpeg': |
74 | 74 | return ($image_types & IMG_JPG) != 0; |
75 | 75 | case 'image/png': |
@@ -90,30 +90,30 @@ discard block |
||
90 | 90 | * @return bool|WP_Error True if loaded successfully; WP_Error on failure. |
91 | 91 | */ |
92 | 92 | public function load() { |
93 | - if ( $this->image ) |
|
93 | + if ($this->image) |
|
94 | 94 | return true; |
95 | 95 | |
96 | - if ( ! is_file( $this->file ) && ! preg_match( '|^https?://|', $this->file ) ) |
|
97 | - return new WP_Error( 'error_loading_image', __('File doesn’t exist?'), $this->file ); |
|
96 | + if ( ! is_file($this->file) && ! preg_match('|^https?://|', $this->file)) |
|
97 | + return new WP_Error('error_loading_image', __('File doesn’t exist?'), $this->file); |
|
98 | 98 | |
99 | 99 | // Set artificially high because GD uses uncompressed images in memory. |
100 | - wp_raise_memory_limit( 'image' ); |
|
100 | + wp_raise_memory_limit('image'); |
|
101 | 101 | |
102 | - $this->image = @imagecreatefromstring( file_get_contents( $this->file ) ); |
|
102 | + $this->image = @imagecreatefromstring(file_get_contents($this->file)); |
|
103 | 103 | |
104 | - if ( ! is_resource( $this->image ) ) |
|
105 | - return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file ); |
|
104 | + if ( ! is_resource($this->image)) |
|
105 | + return new WP_Error('invalid_image', __('File is not an image.'), $this->file); |
|
106 | 106 | |
107 | - $size = @getimagesize( $this->file ); |
|
108 | - if ( ! $size ) |
|
109 | - return new WP_Error( 'invalid_image', __('Could not read image size.'), $this->file ); |
|
107 | + $size = @getimagesize($this->file); |
|
108 | + if ( ! $size) |
|
109 | + return new WP_Error('invalid_image', __('Could not read image size.'), $this->file); |
|
110 | 110 | |
111 | - if ( function_exists( 'imagealphablending' ) && function_exists( 'imagesavealpha' ) ) { |
|
112 | - imagealphablending( $this->image, false ); |
|
113 | - imagesavealpha( $this->image, true ); |
|
111 | + if (function_exists('imagealphablending') && function_exists('imagesavealpha')) { |
|
112 | + imagealphablending($this->image, false); |
|
113 | + imagesavealpha($this->image, true); |
|
114 | 114 | } |
115 | 115 | |
116 | - $this->update_size( $size[0], $size[1] ); |
|
116 | + $this->update_size($size[0], $size[1]); |
|
117 | 117 | $this->mime_type = $size['mime']; |
118 | 118 | |
119 | 119 | return $this->set_quality(); |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | * @param int $height |
130 | 130 | * @return true |
131 | 131 | */ |
132 | - protected function update_size( $width = false, $height = false ) { |
|
133 | - if ( ! $width ) |
|
134 | - $width = imagesx( $this->image ); |
|
132 | + protected function update_size($width = false, $height = false) { |
|
133 | + if ( ! $width) |
|
134 | + $width = imagesx($this->image); |
|
135 | 135 | |
136 | - if ( ! $height ) |
|
137 | - $height = imagesy( $this->image ); |
|
136 | + if ( ! $height) |
|
137 | + $height = imagesy($this->image); |
|
138 | 138 | |
139 | - return parent::update_size( $width, $height ); |
|
139 | + return parent::update_size($width, $height); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -155,21 +155,21 @@ discard block |
||
155 | 155 | * @param bool $crop |
156 | 156 | * @return true|WP_Error |
157 | 157 | */ |
158 | - public function resize( $max_w, $max_h, $crop = false ) { |
|
159 | - if ( ( $this->size['width'] == $max_w ) && ( $this->size['height'] == $max_h ) ) |
|
158 | + public function resize($max_w, $max_h, $crop = false) { |
|
159 | + if (($this->size['width'] == $max_w) && ($this->size['height'] == $max_h)) |
|
160 | 160 | return true; |
161 | 161 | |
162 | - $resized = $this->_resize( $max_w, $max_h, $crop ); |
|
162 | + $resized = $this->_resize($max_w, $max_h, $crop); |
|
163 | 163 | |
164 | - if ( is_resource( $resized ) ) { |
|
165 | - imagedestroy( $this->image ); |
|
164 | + if (is_resource($resized)) { |
|
165 | + imagedestroy($this->image); |
|
166 | 166 | $this->image = $resized; |
167 | 167 | return true; |
168 | 168 | |
169 | - } elseif ( is_wp_error( $resized ) ) |
|
169 | + } elseif (is_wp_error($resized)) |
|
170 | 170 | return $resized; |
171 | 171 | |
172 | - return new WP_Error( 'image_resize_error', __('Image resize failed.'), $this->file ); |
|
172 | + return new WP_Error('image_resize_error', __('Image resize failed.'), $this->file); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -179,22 +179,22 @@ discard block |
||
179 | 179 | * @param bool|array $crop |
180 | 180 | * @return resource|WP_Error |
181 | 181 | */ |
182 | - protected function _resize( $max_w, $max_h, $crop = false ) { |
|
183 | - $dims = image_resize_dimensions( $this->size['width'], $this->size['height'], $max_w, $max_h, $crop ); |
|
184 | - if ( ! $dims ) { |
|
185 | - return new WP_Error( 'error_getting_dimensions', __('Could not calculate resized image dimensions'), $this->file ); |
|
182 | + protected function _resize($max_w, $max_h, $crop = false) { |
|
183 | + $dims = image_resize_dimensions($this->size['width'], $this->size['height'], $max_w, $max_h, $crop); |
|
184 | + if ( ! $dims) { |
|
185 | + return new WP_Error('error_getting_dimensions', __('Could not calculate resized image dimensions'), $this->file); |
|
186 | 186 | } |
187 | - list( $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ) = $dims; |
|
187 | + list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims; |
|
188 | 188 | |
189 | - $resized = wp_imagecreatetruecolor( $dst_w, $dst_h ); |
|
190 | - imagecopyresampled( $resized, $this->image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); |
|
189 | + $resized = wp_imagecreatetruecolor($dst_w, $dst_h); |
|
190 | + imagecopyresampled($resized, $this->image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
|
191 | 191 | |
192 | - if ( is_resource( $resized ) ) { |
|
193 | - $this->update_size( $dst_w, $dst_h ); |
|
192 | + if (is_resource($resized)) { |
|
193 | + $this->update_size($dst_w, $dst_h); |
|
194 | 194 | return $resized; |
195 | 195 | } |
196 | 196 | |
197 | - return new WP_Error( 'image_resize_error', __('Image resize failed.'), $this->file ); |
|
197 | + return new WP_Error('image_resize_error', __('Image resize failed.'), $this->file); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -220,36 +220,36 @@ discard block |
||
220 | 220 | * } |
221 | 221 | * @return array An array of resized images' metadata by size. |
222 | 222 | */ |
223 | - public function multi_resize( $sizes ) { |
|
223 | + public function multi_resize($sizes) { |
|
224 | 224 | $metadata = array(); |
225 | 225 | $orig_size = $this->size; |
226 | 226 | |
227 | - foreach ( $sizes as $size => $size_data ) { |
|
228 | - if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) { |
|
227 | + foreach ($sizes as $size => $size_data) { |
|
228 | + if ( ! isset($size_data['width']) && ! isset($size_data['height'])) { |
|
229 | 229 | continue; |
230 | 230 | } |
231 | 231 | |
232 | - if ( ! isset( $size_data['width'] ) ) { |
|
232 | + if ( ! isset($size_data['width'])) { |
|
233 | 233 | $size_data['width'] = null; |
234 | 234 | } |
235 | - if ( ! isset( $size_data['height'] ) ) { |
|
235 | + if ( ! isset($size_data['height'])) { |
|
236 | 236 | $size_data['height'] = null; |
237 | 237 | } |
238 | 238 | |
239 | - if ( ! isset( $size_data['crop'] ) ) { |
|
239 | + if ( ! isset($size_data['crop'])) { |
|
240 | 240 | $size_data['crop'] = false; |
241 | 241 | } |
242 | 242 | |
243 | - $image = $this->_resize( $size_data['width'], $size_data['height'], $size_data['crop'] ); |
|
244 | - $duplicate = ( ( $orig_size['width'] == $size_data['width'] ) && ( $orig_size['height'] == $size_data['height'] ) ); |
|
243 | + $image = $this->_resize($size_data['width'], $size_data['height'], $size_data['crop']); |
|
244 | + $duplicate = (($orig_size['width'] == $size_data['width']) && ($orig_size['height'] == $size_data['height'])); |
|
245 | 245 | |
246 | - if ( ! is_wp_error( $image ) && ! $duplicate ) { |
|
247 | - $resized = $this->_save( $image ); |
|
246 | + if ( ! is_wp_error($image) && ! $duplicate) { |
|
247 | + $resized = $this->_save($image); |
|
248 | 248 | |
249 | - imagedestroy( $image ); |
|
249 | + imagedestroy($image); |
|
250 | 250 | |
251 | - if ( ! is_wp_error( $resized ) && $resized ) { |
|
252 | - unset( $resized['path'] ); |
|
251 | + if ( ! is_wp_error($resized) && $resized) { |
|
252 | + unset($resized['path']); |
|
253 | 253 | $metadata[$size] = $resized; |
254 | 254 | } |
255 | 255 | } |
@@ -275,34 +275,34 @@ discard block |
||
275 | 275 | * @param bool $src_abs Optional. If the source crop points are absolute. |
276 | 276 | * @return bool|WP_Error |
277 | 277 | */ |
278 | - public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) { |
|
278 | + public function crop($src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false) { |
|
279 | 279 | // If destination width/height isn't specified, use same as |
280 | 280 | // width/height from source. |
281 | - if ( ! $dst_w ) |
|
281 | + if ( ! $dst_w) |
|
282 | 282 | $dst_w = $src_w; |
283 | - if ( ! $dst_h ) |
|
283 | + if ( ! $dst_h) |
|
284 | 284 | $dst_h = $src_h; |
285 | 285 | |
286 | - $dst = wp_imagecreatetruecolor( $dst_w, $dst_h ); |
|
286 | + $dst = wp_imagecreatetruecolor($dst_w, $dst_h); |
|
287 | 287 | |
288 | - if ( $src_abs ) { |
|
288 | + if ($src_abs) { |
|
289 | 289 | $src_w -= $src_x; |
290 | 290 | $src_h -= $src_y; |
291 | 291 | } |
292 | 292 | |
293 | - if ( function_exists( 'imageantialias' ) ) |
|
294 | - imageantialias( $dst, true ); |
|
293 | + if (function_exists('imageantialias')) |
|
294 | + imageantialias($dst, true); |
|
295 | 295 | |
296 | - imagecopyresampled( $dst, $this->image, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); |
|
296 | + imagecopyresampled($dst, $this->image, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
|
297 | 297 | |
298 | - if ( is_resource( $dst ) ) { |
|
299 | - imagedestroy( $this->image ); |
|
298 | + if (is_resource($dst)) { |
|
299 | + imagedestroy($this->image); |
|
300 | 300 | $this->image = $dst; |
301 | 301 | $this->update_size(); |
302 | 302 | return true; |
303 | 303 | } |
304 | 304 | |
305 | - return new WP_Error( 'image_crop_error', __('Image crop failed.'), $this->file ); |
|
305 | + return new WP_Error('image_crop_error', __('Image crop failed.'), $this->file); |
|
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
@@ -315,21 +315,21 @@ discard block |
||
315 | 315 | * @param float $angle |
316 | 316 | * @return true|WP_Error |
317 | 317 | */ |
318 | - public function rotate( $angle ) { |
|
319 | - if ( function_exists('imagerotate') ) { |
|
320 | - $transparency = imagecolorallocatealpha( $this->image, 255, 255, 255, 127 ); |
|
321 | - $rotated = imagerotate( $this->image, $angle, $transparency ); |
|
322 | - |
|
323 | - if ( is_resource( $rotated ) ) { |
|
324 | - imagealphablending( $rotated, true ); |
|
325 | - imagesavealpha( $rotated, true ); |
|
326 | - imagedestroy( $this->image ); |
|
318 | + public function rotate($angle) { |
|
319 | + if (function_exists('imagerotate')) { |
|
320 | + $transparency = imagecolorallocatealpha($this->image, 255, 255, 255, 127); |
|
321 | + $rotated = imagerotate($this->image, $angle, $transparency); |
|
322 | + |
|
323 | + if (is_resource($rotated)) { |
|
324 | + imagealphablending($rotated, true); |
|
325 | + imagesavealpha($rotated, true); |
|
326 | + imagedestroy($this->image); |
|
327 | 327 | $this->image = $rotated; |
328 | 328 | $this->update_size(); |
329 | 329 | return true; |
330 | 330 | } |
331 | 331 | } |
332 | - return new WP_Error( 'image_rotate_error', __('Image rotate failed.'), $this->file ); |
|
332 | + return new WP_Error('image_rotate_error', __('Image rotate failed.'), $this->file); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
@@ -342,24 +342,24 @@ discard block |
||
342 | 342 | * @param bool $vert Flip along Vertical Axis |
343 | 343 | * @return true|WP_Error |
344 | 344 | */ |
345 | - public function flip( $horz, $vert ) { |
|
345 | + public function flip($horz, $vert) { |
|
346 | 346 | $w = $this->size['width']; |
347 | 347 | $h = $this->size['height']; |
348 | - $dst = wp_imagecreatetruecolor( $w, $h ); |
|
348 | + $dst = wp_imagecreatetruecolor($w, $h); |
|
349 | 349 | |
350 | - if ( is_resource( $dst ) ) { |
|
350 | + if (is_resource($dst)) { |
|
351 | 351 | $sx = $vert ? ($w - 1) : 0; |
352 | 352 | $sy = $horz ? ($h - 1) : 0; |
353 | 353 | $sw = $vert ? -$w : $w; |
354 | 354 | $sh = $horz ? -$h : $h; |
355 | 355 | |
356 | - if ( imagecopyresampled( $dst, $this->image, 0, 0, $sx, $sy, $w, $h, $sw, $sh ) ) { |
|
357 | - imagedestroy( $this->image ); |
|
356 | + if (imagecopyresampled($dst, $this->image, 0, 0, $sx, $sy, $w, $h, $sw, $sh)) { |
|
357 | + imagedestroy($this->image); |
|
358 | 358 | $this->image = $dst; |
359 | 359 | return true; |
360 | 360 | } |
361 | 361 | } |
362 | - return new WP_Error( 'image_flip_error', __('Image flip failed.'), $this->file ); |
|
362 | + return new WP_Error('image_flip_error', __('Image flip failed.'), $this->file); |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | /** |
@@ -372,10 +372,10 @@ discard block |
||
372 | 372 | * @param string|null $mime_type |
373 | 373 | * @return array|WP_Error {'path'=>string, 'file'=>string, 'width'=>int, 'height'=>int, 'mime-type'=>string} |
374 | 374 | */ |
375 | - public function save( $filename = null, $mime_type = null ) { |
|
376 | - $saved = $this->_save( $this->image, $filename, $mime_type ); |
|
375 | + public function save($filename = null, $mime_type = null) { |
|
376 | + $saved = $this->_save($this->image, $filename, $mime_type); |
|
377 | 377 | |
378 | - if ( ! is_wp_error( $saved ) ) { |
|
378 | + if ( ! is_wp_error($saved)) { |
|
379 | 379 | $this->file = $saved['path']; |
380 | 380 | $this->mime_type = $saved['mime-type']; |
381 | 381 | } |
@@ -389,36 +389,36 @@ discard block |
||
389 | 389 | * @param string|null $mime_type |
390 | 390 | * @return WP_Error|array |
391 | 391 | */ |
392 | - protected function _save( $image, $filename = null, $mime_type = null ) { |
|
393 | - list( $filename, $extension, $mime_type ) = $this->get_output_format( $filename, $mime_type ); |
|
392 | + protected function _save($image, $filename = null, $mime_type = null) { |
|
393 | + list($filename, $extension, $mime_type) = $this->get_output_format($filename, $mime_type); |
|
394 | 394 | |
395 | - if ( ! $filename ) |
|
396 | - $filename = $this->generate_filename( null, null, $extension ); |
|
395 | + if ( ! $filename) |
|
396 | + $filename = $this->generate_filename(null, null, $extension); |
|
397 | 397 | |
398 | - if ( 'image/gif' == $mime_type ) { |
|
399 | - if ( ! $this->make_image( $filename, 'imagegif', array( $image, $filename ) ) ) |
|
400 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
398 | + if ('image/gif' == $mime_type) { |
|
399 | + if ( ! $this->make_image($filename, 'imagegif', array($image, $filename))) |
|
400 | + return new WP_Error('image_save_error', __('Image Editor Save Failed')); |
|
401 | 401 | } |
402 | - elseif ( 'image/png' == $mime_type ) { |
|
402 | + elseif ('image/png' == $mime_type) { |
|
403 | 403 | // convert from full colors to index colors, like original PNG. |
404 | - if ( function_exists('imageistruecolor') && ! imageistruecolor( $image ) ) |
|
405 | - imagetruecolortopalette( $image, false, imagecolorstotal( $image ) ); |
|
404 | + if (function_exists('imageistruecolor') && ! imageistruecolor($image)) |
|
405 | + imagetruecolortopalette($image, false, imagecolorstotal($image)); |
|
406 | 406 | |
407 | - if ( ! $this->make_image( $filename, 'imagepng', array( $image, $filename ) ) ) |
|
408 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
407 | + if ( ! $this->make_image($filename, 'imagepng', array($image, $filename))) |
|
408 | + return new WP_Error('image_save_error', __('Image Editor Save Failed')); |
|
409 | 409 | } |
410 | - elseif ( 'image/jpeg' == $mime_type ) { |
|
411 | - if ( ! $this->make_image( $filename, 'imagejpeg', array( $image, $filename, $this->get_quality() ) ) ) |
|
412 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
410 | + elseif ('image/jpeg' == $mime_type) { |
|
411 | + if ( ! $this->make_image($filename, 'imagejpeg', array($image, $filename, $this->get_quality()))) |
|
412 | + return new WP_Error('image_save_error', __('Image Editor Save Failed')); |
|
413 | 413 | } |
414 | 414 | else { |
415 | - return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); |
|
415 | + return new WP_Error('image_save_error', __('Image Editor Save Failed')); |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | // Set correct file permissions |
419 | - $stat = stat( dirname( $filename ) ); |
|
419 | + $stat = stat(dirname($filename)); |
|
420 | 420 | $perms = $stat['mode'] & 0000666; //same permissions as parent folder, strip off the executable bits |
421 | - @ chmod( $filename, $perms ); |
|
421 | + @ chmod($filename, $perms); |
|
422 | 422 | |
423 | 423 | /** |
424 | 424 | * Filters the name of the saved image file. |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | */ |
430 | 430 | return array( |
431 | 431 | 'path' => $filename, |
432 | - 'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ), |
|
432 | + 'file' => wp_basename(apply_filters('image_make_intermediate_size', $filename)), |
|
433 | 433 | 'width' => $this->size['width'], |
434 | 434 | 'height' => $this->size['height'], |
435 | 435 | 'mime-type' => $mime_type, |
@@ -445,19 +445,19 @@ discard block |
||
445 | 445 | * @param string $mime_type |
446 | 446 | * @return bool |
447 | 447 | */ |
448 | - public function stream( $mime_type = null ) { |
|
449 | - list( $filename, $extension, $mime_type ) = $this->get_output_format( null, $mime_type ); |
|
448 | + public function stream($mime_type = null) { |
|
449 | + list($filename, $extension, $mime_type) = $this->get_output_format(null, $mime_type); |
|
450 | 450 | |
451 | - switch ( $mime_type ) { |
|
451 | + switch ($mime_type) { |
|
452 | 452 | case 'image/png': |
453 | - header( 'Content-Type: image/png' ); |
|
454 | - return imagepng( $this->image ); |
|
453 | + header('Content-Type: image/png'); |
|
454 | + return imagepng($this->image); |
|
455 | 455 | case 'image/gif': |
456 | - header( 'Content-Type: image/gif' ); |
|
457 | - return imagegif( $this->image ); |
|
456 | + header('Content-Type: image/gif'); |
|
457 | + return imagegif($this->image); |
|
458 | 458 | default: |
459 | - header( 'Content-Type: image/jpeg' ); |
|
460 | - return imagejpeg( $this->image, null, $this->get_quality() ); |
|
459 | + header('Content-Type: image/jpeg'); |
|
460 | + return imagejpeg($this->image, null, $this->get_quality()); |
|
461 | 461 | } |
462 | 462 | } |
463 | 463 | |
@@ -472,10 +472,10 @@ discard block |
||
472 | 472 | * @param array $arguments |
473 | 473 | * @return bool |
474 | 474 | */ |
475 | - protected function make_image( $filename, $function, $arguments ) { |
|
476 | - if ( wp_is_stream( $filename ) ) |
|
475 | + protected function make_image($filename, $function, $arguments) { |
|
476 | + if (wp_is_stream($filename)) |
|
477 | 477 | $arguments[1] = null; |
478 | 478 | |
479 | - return parent::make_image( $filename, $function, $arguments ); |
|
479 | + return parent::make_image($filename, $function, $arguments); |
|
480 | 480 | } |
481 | 481 | } |
@@ -68,10 +68,13 @@ |
||
68 | 68 | <?php the_category_rss('rdf') ?> |
69 | 69 | <?php if (get_option('rss_use_excerpt')) : ?> |
70 | 70 | <description><![CDATA[<?php the_excerpt_rss() ?>]]></description> |
71 | -<?php else : ?> |
|
71 | +<?php else { |
|
72 | + : ?> |
|
72 | 73 | <description><![CDATA[<?php the_excerpt_rss() ?>]]></description> |
73 | 74 | <content:encoded><![CDATA[<?php the_content_feed('rdf') ?>]]></content:encoded> |
74 | -<?php endif; ?> |
|
75 | +<?php endif; |
|
76 | +} |
|
77 | +?> |
|
75 | 78 | <?php |
76 | 79 | /** |
77 | 80 | * Fires at the end of each RDF feed item. |
@@ -5,13 +5,13 @@ discard block |
||
5 | 5 | * @package WordPress |
6 | 6 | */ |
7 | 7 | |
8 | -header('Content-Type: ' . feed_content_type('rdf') . '; charset=' . get_option('blog_charset'), true); |
|
8 | +header('Content-Type: '.feed_content_type('rdf').'; charset='.get_option('blog_charset'), true); |
|
9 | 9 | $more = 1; |
10 | 10 | |
11 | 11 | echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; |
12 | 12 | |
13 | 13 | /** This action is documented in wp-includes/feed-rss2.php */ |
14 | -do_action( 'rss_tag_pre', 'rdf' ); |
|
14 | +do_action('rss_tag_pre', 'rdf'); |
|
15 | 15 | ?> |
16 | 16 | <rdf:RDF |
17 | 17 | xmlns="http://purl.org/rss/1.0/" |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @since 2.0.0 |
28 | 28 | */ |
29 | - do_action( 'rdf_ns' ); |
|
29 | + do_action('rdf_ns'); |
|
30 | 30 | ?> |
31 | 31 | > |
32 | 32 | <channel rdf:about="<?php bloginfo_rss("url") ?>"> |
@@ -34,16 +34,16 @@ discard block |
||
34 | 34 | <link><?php bloginfo_rss('url') ?></link> |
35 | 35 | <description><?php bloginfo_rss('description') ?></description> |
36 | 36 | <dc:date><?php |
37 | - $date = get_lastpostmodified( 'GMT' ); |
|
38 | - echo $date ? mysql2date( 'Y-m-d\TH:i:s\Z', $date ) : date( 'Y-m-d\TH:i:s\Z' ); |
|
37 | + $date = get_lastpostmodified('GMT'); |
|
38 | + echo $date ? mysql2date('Y-m-d\TH:i:s\Z', $date) : date('Y-m-d\TH:i:s\Z'); |
|
39 | 39 | ?></dc:date> |
40 | 40 | <sy:updatePeriod><?php |
41 | 41 | /** This filter is documented in wp-includes/feed-rss2.php */ |
42 | - echo apply_filters( 'rss_update_period', 'hourly' ); |
|
42 | + echo apply_filters('rss_update_period', 'hourly'); |
|
43 | 43 | ?></sy:updatePeriod> |
44 | 44 | <sy:updateFrequency><?php |
45 | 45 | /** This filter is documented in wp-includes/feed-rss2.php */ |
46 | - echo apply_filters( 'rss_update_frequency', '1' ); |
|
46 | + echo apply_filters('rss_update_frequency', '1'); |
|
47 | 47 | ?></sy:updateFrequency> |
48 | 48 | <sy:updateBase>2000-01-01T12:00+00:00</sy:updateBase> |
49 | 49 | <?php |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @since 2.0.0 |
54 | 54 | */ |
55 | - do_action( 'rdf_header' ); |
|
55 | + do_action('rdf_header'); |
|
56 | 56 | ?> |
57 | 57 | <items> |
58 | 58 | <rdf:Seq> |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @since 2.0.0 |
83 | 83 | */ |
84 | - do_action( 'rdf_item' ); |
|
84 | + do_action('rdf_item'); |
|
85 | 85 | ?> |
86 | 86 | </item> |
87 | -<?php endwhile; ?> |
|
87 | +<?php endwhile; ?> |
|
88 | 88 | </rdf:RDF> |