@@ -595,7 +595,7 @@ |
||
595 | 595 | * |
596 | 596 | * @param int $new_blog The id of the blog you want to switch to. Default: current blog |
597 | 597 | * @param bool $deprecated Deprecated argument |
598 | - * @return true Always returns True. |
|
598 | + * @return boolean Always returns True. |
|
599 | 599 | */ |
600 | 600 | function switch_to_blog( $new_blog, $deprecated = null ) { |
601 | 601 | global $wpdb; |
@@ -845,7 +845,7 @@ |
||
845 | 845 | * |
846 | 846 | * @param int $blog_id Blog ID. |
847 | 847 | * @param string $value The value of blog status. |
848 | - */ |
|
848 | + */ |
|
849 | 849 | do_action( 'update_blog_public', $blog_id, $value ); // Moved here from update_blog_public(). |
850 | 850 | } |
851 | 851 |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | function wpmu_update_blogs_date() { |
19 | 19 | global $wpdb; |
20 | 20 | |
21 | - update_blog_details( $wpdb->blogid, array('last_updated' => current_time('mysql', true)) ); |
|
21 | + update_blog_details($wpdb->blogid, array('last_updated' => current_time('mysql', true))); |
|
22 | 22 | /** |
23 | 23 | * Fires after the blog details are updated. |
24 | 24 | * |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * |
27 | 27 | * @param int $blog_id Site ID. |
28 | 28 | */ |
29 | - do_action( 'wpmu_blog_updated', $wpdb->blogid ); |
|
29 | + do_action('wpmu_blog_updated', $wpdb->blogid); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
@@ -37,17 +37,17 @@ discard block |
||
37 | 37 | * @param int $blog_id Blog ID |
38 | 38 | * @return string Full URL of the blog if found. Empty string if not. |
39 | 39 | */ |
40 | -function get_blogaddress_by_id( $blog_id ) { |
|
41 | - $bloginfo = get_blog_details( (int) $blog_id ); |
|
40 | +function get_blogaddress_by_id($blog_id) { |
|
41 | + $bloginfo = get_blog_details((int) $blog_id); |
|
42 | 42 | |
43 | - if ( empty( $bloginfo ) ) { |
|
43 | + if (empty($bloginfo)) { |
|
44 | 44 | return ''; |
45 | 45 | } |
46 | 46 | |
47 | - $scheme = parse_url( $bloginfo->home, PHP_URL_SCHEME ); |
|
48 | - $scheme = empty( $scheme ) ? 'http' : $scheme; |
|
47 | + $scheme = parse_url($bloginfo->home, PHP_URL_SCHEME); |
|
48 | + $scheme = empty($scheme) ? 'http' : $scheme; |
|
49 | 49 | |
50 | - return esc_url( $scheme . '://' . $bloginfo->domain . $bloginfo->path ); |
|
50 | + return esc_url($scheme.'://'.$bloginfo->domain.$bloginfo->path); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -58,17 +58,17 @@ discard block |
||
58 | 58 | * @param string $blogname The (subdomain or directory) name |
59 | 59 | * @return string |
60 | 60 | */ |
61 | -function get_blogaddress_by_name( $blogname ) { |
|
62 | - if ( is_subdomain_install() ) { |
|
63 | - if ( $blogname == 'main' ) |
|
61 | +function get_blogaddress_by_name($blogname) { |
|
62 | + if (is_subdomain_install()) { |
|
63 | + if ($blogname == 'main') |
|
64 | 64 | $blogname = 'www'; |
65 | - $url = rtrim( network_home_url(), '/' ); |
|
66 | - if ( !empty( $blogname ) ) |
|
67 | - $url = preg_replace( '|^([^\.]+://)|', "\${1}" . $blogname . '.', $url ); |
|
65 | + $url = rtrim(network_home_url(), '/'); |
|
66 | + if ( ! empty($blogname)) |
|
67 | + $url = preg_replace('|^([^\.]+://)|', "\${1}".$blogname.'.', $url); |
|
68 | 68 | } else { |
69 | - $url = network_home_url( $blogname ); |
|
69 | + $url = network_home_url($blogname); |
|
70 | 70 | } |
71 | - return esc_url( $url . '/' ); |
|
71 | + return esc_url($url.'/'); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -81,26 +81,26 @@ discard block |
||
81 | 81 | * @param string $slug |
82 | 82 | * @return int A blog id |
83 | 83 | */ |
84 | -function get_id_from_blogname( $slug ) { |
|
84 | +function get_id_from_blogname($slug) { |
|
85 | 85 | global $wpdb; |
86 | 86 | |
87 | 87 | $current_site = get_current_site(); |
88 | - $slug = trim( $slug, '/' ); |
|
88 | + $slug = trim($slug, '/'); |
|
89 | 89 | |
90 | - $blog_id = wp_cache_get( 'get_id_from_blogname_' . $slug, 'blog-details' ); |
|
91 | - if ( $blog_id ) |
|
90 | + $blog_id = wp_cache_get('get_id_from_blogname_'.$slug, 'blog-details'); |
|
91 | + if ($blog_id) |
|
92 | 92 | return $blog_id; |
93 | 93 | |
94 | - if ( is_subdomain_install() ) { |
|
95 | - $domain = $slug . '.' . $current_site->domain; |
|
94 | + if (is_subdomain_install()) { |
|
95 | + $domain = $slug.'.'.$current_site->domain; |
|
96 | 96 | $path = $current_site->path; |
97 | 97 | } else { |
98 | 98 | $domain = $current_site->domain; |
99 | - $path = $current_site->path . $slug . '/'; |
|
99 | + $path = $current_site->path.$slug.'/'; |
|
100 | 100 | } |
101 | 101 | |
102 | - $blog_id = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s", $domain, $path) ); |
|
103 | - wp_cache_set( 'get_id_from_blogname_' . $slug, $blog_id, 'blog-details' ); |
|
102 | + $blog_id = $wpdb->get_var($wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s", $domain, $path)); |
|
103 | + wp_cache_set('get_id_from_blogname_'.$slug, $blog_id, 'blog-details'); |
|
104 | 104 | return $blog_id; |
105 | 105 | } |
106 | 106 | |
@@ -117,42 +117,42 @@ discard block |
||
117 | 117 | * Default is true. |
118 | 118 | * @return WP_Site|false Blog details on success. False on failure. |
119 | 119 | */ |
120 | -function get_blog_details( $fields = null, $get_all = true ) { |
|
120 | +function get_blog_details($fields = null, $get_all = true) { |
|
121 | 121 | global $wpdb; |
122 | 122 | |
123 | - if ( is_array($fields ) ) { |
|
124 | - if ( isset($fields['blog_id']) ) { |
|
123 | + if (is_array($fields)) { |
|
124 | + if (isset($fields['blog_id'])) { |
|
125 | 125 | $blog_id = $fields['blog_id']; |
126 | - } elseif ( isset($fields['domain']) && isset($fields['path']) ) { |
|
127 | - $key = md5( $fields['domain'] . $fields['path'] ); |
|
126 | + } elseif (isset($fields['domain']) && isset($fields['path'])) { |
|
127 | + $key = md5($fields['domain'].$fields['path']); |
|
128 | 128 | $blog = wp_cache_get($key, 'blog-lookup'); |
129 | - if ( false !== $blog ) |
|
129 | + if (false !== $blog) |
|
130 | 130 | return $blog; |
131 | - if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) { |
|
132 | - $nowww = substr( $fields['domain'], 4 ); |
|
133 | - $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) ); |
|
131 | + if (substr($fields['domain'], 0, 4) == 'www.') { |
|
132 | + $nowww = substr($fields['domain'], 4); |
|
133 | + $blog = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'])); |
|
134 | 134 | } else { |
135 | - $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) ); |
|
135 | + $blog = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'])); |
|
136 | 136 | } |
137 | - if ( $blog ) { |
|
138 | - wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details'); |
|
137 | + if ($blog) { |
|
138 | + wp_cache_set($blog->blog_id.'short', $blog, 'blog-details'); |
|
139 | 139 | $blog_id = $blog->blog_id; |
140 | 140 | } else { |
141 | 141 | return false; |
142 | 142 | } |
143 | - } elseif ( isset($fields['domain']) && is_subdomain_install() ) { |
|
144 | - $key = md5( $fields['domain'] ); |
|
143 | + } elseif (isset($fields['domain']) && is_subdomain_install()) { |
|
144 | + $key = md5($fields['domain']); |
|
145 | 145 | $blog = wp_cache_get($key, 'blog-lookup'); |
146 | - if ( false !== $blog ) |
|
146 | + if (false !== $blog) |
|
147 | 147 | return $blog; |
148 | - if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) { |
|
149 | - $nowww = substr( $fields['domain'], 4 ); |
|
150 | - $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) ); |
|
148 | + if (substr($fields['domain'], 0, 4) == 'www.') { |
|
149 | + $nowww = substr($fields['domain'], 4); |
|
150 | + $blog = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'])); |
|
151 | 151 | } else { |
152 | - $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) ); |
|
152 | + $blog = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'])); |
|
153 | 153 | } |
154 | - if ( $blog ) { |
|
155 | - wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details'); |
|
154 | + if ($blog) { |
|
155 | + wp_cache_set($blog->blog_id.'short', $blog, 'blog-details'); |
|
156 | 156 | $blog_id = $blog->blog_id; |
157 | 157 | } else { |
158 | 158 | return false; |
@@ -161,10 +161,10 @@ discard block |
||
161 | 161 | return false; |
162 | 162 | } |
163 | 163 | } else { |
164 | - if ( ! $fields ) |
|
164 | + if ( ! $fields) |
|
165 | 165 | $blog_id = get_current_blog_id(); |
166 | - elseif ( ! is_numeric( $fields ) ) |
|
167 | - $blog_id = get_id_from_blogname( $fields ); |
|
166 | + elseif ( ! is_numeric($fields)) |
|
167 | + $blog_id = get_id_from_blogname($fields); |
|
168 | 168 | else |
169 | 169 | $blog_id = $fields; |
170 | 170 | } |
@@ -172,15 +172,15 @@ discard block |
||
172 | 172 | $blog_id = (int) $blog_id; |
173 | 173 | |
174 | 174 | $all = $get_all == true ? '' : 'short'; |
175 | - $details = wp_cache_get( $blog_id . $all, 'blog-details' ); |
|
175 | + $details = wp_cache_get($blog_id.$all, 'blog-details'); |
|
176 | 176 | |
177 | - if ( $details ) { |
|
178 | - if ( ! is_object( $details ) ) { |
|
179 | - if ( $details == -1 ) { |
|
177 | + if ($details) { |
|
178 | + if ( ! is_object($details)) { |
|
179 | + if ($details == -1) { |
|
180 | 180 | return false; |
181 | 181 | } else { |
182 | 182 | // Clear old pre-serialized objects. Cache clients do better with that. |
183 | - wp_cache_delete( $blog_id . $all, 'blog-details' ); |
|
183 | + wp_cache_delete($blog_id.$all, 'blog-details'); |
|
184 | 184 | unset($details); |
185 | 185 | } |
186 | 186 | } else { |
@@ -189,18 +189,18 @@ discard block |
||
189 | 189 | } |
190 | 190 | |
191 | 191 | // Try the other cache. |
192 | - if ( $get_all ) { |
|
193 | - $details = wp_cache_get( $blog_id . 'short', 'blog-details' ); |
|
192 | + if ($get_all) { |
|
193 | + $details = wp_cache_get($blog_id.'short', 'blog-details'); |
|
194 | 194 | } else { |
195 | - $details = wp_cache_get( $blog_id, 'blog-details' ); |
|
195 | + $details = wp_cache_get($blog_id, 'blog-details'); |
|
196 | 196 | // If short was requested and full cache is set, we can return. |
197 | - if ( $details ) { |
|
198 | - if ( ! is_object( $details ) ) { |
|
199 | - if ( $details == -1 ) { |
|
197 | + if ($details) { |
|
198 | + if ( ! is_object($details)) { |
|
199 | + if ($details == -1) { |
|
200 | 200 | return false; |
201 | 201 | } else { |
202 | 202 | // Clear old pre-serialized objects. Cache clients do better with that. |
203 | - wp_cache_delete( $blog_id, 'blog-details' ); |
|
203 | + wp_cache_delete($blog_id, 'blog-details'); |
|
204 | 204 | unset($details); |
205 | 205 | } |
206 | 206 | } else { |
@@ -209,29 +209,29 @@ discard block |
||
209 | 209 | } |
210 | 210 | } |
211 | 211 | |
212 | - if ( empty($details) ) { |
|
213 | - $details = WP_Site::get_instance( $blog_id ); |
|
214 | - if ( ! $details ) { |
|
212 | + if (empty($details)) { |
|
213 | + $details = WP_Site::get_instance($blog_id); |
|
214 | + if ( ! $details) { |
|
215 | 215 | // Set the full cache. |
216 | - wp_cache_set( $blog_id, -1, 'blog-details' ); |
|
216 | + wp_cache_set($blog_id, -1, 'blog-details'); |
|
217 | 217 | return false; |
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
221 | - if ( ! $details instanceof WP_Site ) { |
|
222 | - $details = new WP_Site( $details ); |
|
221 | + if ( ! $details instanceof WP_Site) { |
|
222 | + $details = new WP_Site($details); |
|
223 | 223 | } |
224 | 224 | |
225 | - if ( ! $get_all ) { |
|
226 | - wp_cache_set( $blog_id . $all, $details, 'blog-details' ); |
|
225 | + if ( ! $get_all) { |
|
226 | + wp_cache_set($blog_id.$all, $details, 'blog-details'); |
|
227 | 227 | return $details; |
228 | 228 | } |
229 | 229 | |
230 | - switch_to_blog( $blog_id ); |
|
231 | - $details->blogname = get_option( 'blogname' ); |
|
232 | - $details->siteurl = get_option( 'siteurl' ); |
|
233 | - $details->post_count = get_option( 'post_count' ); |
|
234 | - $details->home = get_option( 'home' ); |
|
230 | + switch_to_blog($blog_id); |
|
231 | + $details->blogname = get_option('blogname'); |
|
232 | + $details->siteurl = get_option('siteurl'); |
|
233 | + $details->post_count = get_option('post_count'); |
|
234 | + $details->home = get_option('home'); |
|
235 | 235 | restore_current_blog(); |
236 | 236 | |
237 | 237 | /** |
@@ -241,12 +241,12 @@ discard block |
||
241 | 241 | * |
242 | 242 | * @param object $details The blog details. |
243 | 243 | */ |
244 | - $details = apply_filters( 'blog_details', $details ); |
|
244 | + $details = apply_filters('blog_details', $details); |
|
245 | 245 | |
246 | - wp_cache_set( $blog_id . $all, $details, 'blog-details' ); |
|
246 | + wp_cache_set($blog_id.$all, $details, 'blog-details'); |
|
247 | 247 | |
248 | - $key = md5( $details->domain . $details->path ); |
|
249 | - wp_cache_set( $key, $details, 'blog-lookup' ); |
|
248 | + $key = md5($details->domain.$details->path); |
|
249 | + wp_cache_set($key, $details, 'blog-lookup'); |
|
250 | 250 | |
251 | 251 | return $details; |
252 | 252 | } |
@@ -258,14 +258,14 @@ discard block |
||
258 | 258 | * |
259 | 259 | * @param int $blog_id Optional. Blog ID. Defaults to current blog. |
260 | 260 | */ |
261 | -function refresh_blog_details( $blog_id = 0 ) { |
|
261 | +function refresh_blog_details($blog_id = 0) { |
|
262 | 262 | $blog_id = (int) $blog_id; |
263 | - if ( ! $blog_id ) { |
|
263 | + if ( ! $blog_id) { |
|
264 | 264 | $blog_id = get_current_blog_id(); |
265 | 265 | } |
266 | 266 | |
267 | - $details = get_blog_details( $blog_id, false ); |
|
268 | - if ( ! $details ) { |
|
267 | + $details = get_blog_details($blog_id, false); |
|
268 | + if ( ! $details) { |
|
269 | 269 | // Make sure clean_blog_cache() gets the blog ID |
270 | 270 | // when the blog has been previously cached as |
271 | 271 | // non-existent. |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | ); |
277 | 277 | } |
278 | 278 | |
279 | - clean_blog_cache( $details ); |
|
279 | + clean_blog_cache($details); |
|
280 | 280 | |
281 | 281 | /** |
282 | 282 | * Fires after the blog details cache is cleared. |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * |
286 | 286 | * @param int $blog_id Blog ID. |
287 | 287 | */ |
288 | - do_action( 'refresh_blog_details', $blog_id ); |
|
288 | + do_action('refresh_blog_details', $blog_id); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -299,17 +299,17 @@ discard block |
||
299 | 299 | * @param array $details Array of details keyed by blogs table field names. |
300 | 300 | * @return bool True if update succeeds, false otherwise. |
301 | 301 | */ |
302 | -function update_blog_details( $blog_id, $details = array() ) { |
|
302 | +function update_blog_details($blog_id, $details = array()) { |
|
303 | 303 | global $wpdb; |
304 | 304 | |
305 | - if ( empty($details) ) |
|
305 | + if (empty($details)) |
|
306 | 306 | return false; |
307 | 307 | |
308 | - if ( is_object($details) ) |
|
308 | + if (is_object($details)) |
|
309 | 309 | $details = get_object_vars($details); |
310 | 310 | |
311 | 311 | $current_details = get_blog_details($blog_id, false); |
312 | - if ( empty($current_details) ) |
|
312 | + if (empty($current_details)) |
|
313 | 313 | return false; |
314 | 314 | |
315 | 315 | $current_details = get_object_vars($current_details); |
@@ -318,23 +318,23 @@ discard block |
||
318 | 318 | $details['last_updated'] = current_time('mysql', true); |
319 | 319 | |
320 | 320 | $update_details = array(); |
321 | - $fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id'); |
|
322 | - foreach ( array_intersect( array_keys( $details ), $fields ) as $field ) { |
|
323 | - if ( 'path' === $field ) { |
|
324 | - $details[ $field ] = trailingslashit( '/' . trim( $details[ $field ], '/' ) ); |
|
321 | + $fields = array('site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id'); |
|
322 | + foreach (array_intersect(array_keys($details), $fields) as $field) { |
|
323 | + if ('path' === $field) { |
|
324 | + $details[$field] = trailingslashit('/'.trim($details[$field], '/')); |
|
325 | 325 | } |
326 | 326 | |
327 | - $update_details[ $field ] = $details[ $field ]; |
|
327 | + $update_details[$field] = $details[$field]; |
|
328 | 328 | } |
329 | 329 | |
330 | - $result = $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) ); |
|
330 | + $result = $wpdb->update($wpdb->blogs, $update_details, array('blog_id' => $blog_id)); |
|
331 | 331 | |
332 | - if ( false === $result ) |
|
332 | + if (false === $result) |
|
333 | 333 | return false; |
334 | 334 | |
335 | 335 | // If spam status changed, issue actions. |
336 | - if ( $details['spam'] != $current_details['spam'] ) { |
|
337 | - if ( $details['spam'] == 1 ) { |
|
336 | + if ($details['spam'] != $current_details['spam']) { |
|
337 | + if ($details['spam'] == 1) { |
|
338 | 338 | /** |
339 | 339 | * Fires when the blog status is changed to 'spam'. |
340 | 340 | * |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | * |
343 | 343 | * @param int $blog_id Blog ID. |
344 | 344 | */ |
345 | - do_action( 'make_spam_blog', $blog_id ); |
|
345 | + do_action('make_spam_blog', $blog_id); |
|
346 | 346 | } else { |
347 | 347 | /** |
348 | 348 | * Fires when the blog status is changed to 'ham'. |
@@ -351,13 +351,13 @@ discard block |
||
351 | 351 | * |
352 | 352 | * @param int $blog_id Blog ID. |
353 | 353 | */ |
354 | - do_action( 'make_ham_blog', $blog_id ); |
|
354 | + do_action('make_ham_blog', $blog_id); |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | |
358 | 358 | // If mature status changed, issue actions. |
359 | - if ( $details['mature'] != $current_details['mature'] ) { |
|
360 | - if ( $details['mature'] == 1 ) { |
|
359 | + if ($details['mature'] != $current_details['mature']) { |
|
360 | + if ($details['mature'] == 1) { |
|
361 | 361 | /** |
362 | 362 | * Fires when the blog status is changed to 'mature'. |
363 | 363 | * |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | * |
366 | 366 | * @param int $blog_id Blog ID. |
367 | 367 | */ |
368 | - do_action( 'mature_blog', $blog_id ); |
|
368 | + do_action('mature_blog', $blog_id); |
|
369 | 369 | } else { |
370 | 370 | /** |
371 | 371 | * Fires when the blog status is changed to 'unmature'. |
@@ -374,13 +374,13 @@ discard block |
||
374 | 374 | * |
375 | 375 | * @param int $blog_id Blog ID. |
376 | 376 | */ |
377 | - do_action( 'unmature_blog', $blog_id ); |
|
377 | + do_action('unmature_blog', $blog_id); |
|
378 | 378 | } |
379 | 379 | } |
380 | 380 | |
381 | 381 | // If archived status changed, issue actions. |
382 | - if ( $details['archived'] != $current_details['archived'] ) { |
|
383 | - if ( $details['archived'] == 1 ) { |
|
382 | + if ($details['archived'] != $current_details['archived']) { |
|
383 | + if ($details['archived'] == 1) { |
|
384 | 384 | /** |
385 | 385 | * Fires when the blog status is changed to 'archived'. |
386 | 386 | * |
@@ -388,7 +388,7 @@ discard block |
||
388 | 388 | * |
389 | 389 | * @param int $blog_id Blog ID. |
390 | 390 | */ |
391 | - do_action( 'archive_blog', $blog_id ); |
|
391 | + do_action('archive_blog', $blog_id); |
|
392 | 392 | } else { |
393 | 393 | /** |
394 | 394 | * Fires when the blog status is changed to 'unarchived'. |
@@ -397,13 +397,13 @@ discard block |
||
397 | 397 | * |
398 | 398 | * @param int $blog_id Blog ID. |
399 | 399 | */ |
400 | - do_action( 'unarchive_blog', $blog_id ); |
|
400 | + do_action('unarchive_blog', $blog_id); |
|
401 | 401 | } |
402 | 402 | } |
403 | 403 | |
404 | 404 | // If deleted status changed, issue actions. |
405 | - if ( $details['deleted'] != $current_details['deleted'] ) { |
|
406 | - if ( $details['deleted'] == 1 ) { |
|
405 | + if ($details['deleted'] != $current_details['deleted']) { |
|
406 | + if ($details['deleted'] == 1) { |
|
407 | 407 | /** |
408 | 408 | * Fires when the blog status is changed to 'deleted'. |
409 | 409 | * |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | * |
412 | 412 | * @param int $blog_id Blog ID. |
413 | 413 | */ |
414 | - do_action( 'make_delete_blog', $blog_id ); |
|
414 | + do_action('make_delete_blog', $blog_id); |
|
415 | 415 | } else { |
416 | 416 | /** |
417 | 417 | * Fires when the blog status is changed to 'undeleted'. |
@@ -420,13 +420,13 @@ discard block |
||
420 | 420 | * |
421 | 421 | * @param int $blog_id Blog ID. |
422 | 422 | */ |
423 | - do_action( 'make_undelete_blog', $blog_id ); |
|
423 | + do_action('make_undelete_blog', $blog_id); |
|
424 | 424 | } |
425 | 425 | } |
426 | 426 | |
427 | - if ( isset( $details['public'] ) ) { |
|
428 | - switch_to_blog( $blog_id ); |
|
429 | - update_option( 'blog_public', $details['public'] ); |
|
427 | + if (isset($details['public'])) { |
|
428 | + switch_to_blog($blog_id); |
|
429 | + update_option('blog_public', $details['public']); |
|
430 | 430 | restore_current_blog(); |
431 | 431 | } |
432 | 432 | |
@@ -442,19 +442,19 @@ discard block |
||
442 | 442 | * |
443 | 443 | * @param WP_Site $blog The blog details as returned from get_blog_details() |
444 | 444 | */ |
445 | -function clean_blog_cache( $blog ) { |
|
445 | +function clean_blog_cache($blog) { |
|
446 | 446 | $blog_id = $blog->blog_id; |
447 | - $domain_path_key = md5( $blog->domain . $blog->path ); |
|
448 | - |
|
449 | - wp_cache_delete( $blog_id, 'sites' ); |
|
450 | - wp_cache_delete( $blog_id, 'site-details' ); |
|
451 | - wp_cache_delete( $blog_id , 'blog-details' ); |
|
452 | - wp_cache_delete( $blog_id . 'short' , 'blog-details' ); |
|
453 | - wp_cache_delete( $domain_path_key, 'blog-lookup' ); |
|
454 | - wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' ); |
|
455 | - wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' ); |
|
456 | - wp_cache_delete( 'get_id_from_blogname_' . trim( $blog->path, '/' ), 'blog-details' ); |
|
457 | - wp_cache_delete( $domain_path_key, 'blog-id-cache' ); |
|
447 | + $domain_path_key = md5($blog->domain.$blog->path); |
|
448 | + |
|
449 | + wp_cache_delete($blog_id, 'sites'); |
|
450 | + wp_cache_delete($blog_id, 'site-details'); |
|
451 | + wp_cache_delete($blog_id, 'blog-details'); |
|
452 | + wp_cache_delete($blog_id.'short', 'blog-details'); |
|
453 | + wp_cache_delete($domain_path_key, 'blog-lookup'); |
|
454 | + wp_cache_delete('current_blog_'.$blog->domain, 'site-options'); |
|
455 | + wp_cache_delete('current_blog_'.$blog->domain.$blog->path, 'site-options'); |
|
456 | + wp_cache_delete('get_id_from_blogname_'.trim($blog->path, '/'), 'blog-details'); |
|
457 | + wp_cache_delete($domain_path_key, 'blog-id-cache'); |
|
458 | 458 | |
459 | 459 | /** |
460 | 460 | * Fires immediately after a site has been removed from the object cache. |
@@ -465,9 +465,9 @@ discard block |
||
465 | 465 | * @param WP_Site $blog Site object. |
466 | 466 | * @param string $domain_path_key md5 hash of domain and path. |
467 | 467 | */ |
468 | - do_action( 'clean_site_cache', $blog_id, $blog, $domain_path_key ); |
|
468 | + do_action('clean_site_cache', $blog_id, $blog, $domain_path_key); |
|
469 | 469 | |
470 | - wp_cache_set( 'last_changed', microtime(), 'sites' ); |
|
470 | + wp_cache_set('last_changed', microtime(), 'sites'); |
|
471 | 471 | } |
472 | 472 | |
473 | 473 | /** |
@@ -481,20 +481,20 @@ discard block |
||
481 | 481 | * @param WP_Site|int|null $site Optional. Site to retrieve. Default is the current site. |
482 | 482 | * @return WP_Site|null The site object or null if not found. |
483 | 483 | */ |
484 | -function get_site( $site = null ) { |
|
485 | - if ( empty( $site ) ) { |
|
484 | +function get_site($site = null) { |
|
485 | + if (empty($site)) { |
|
486 | 486 | $site = get_current_blog_id(); |
487 | 487 | } |
488 | 488 | |
489 | - if ( $site instanceof WP_Site ) { |
|
489 | + if ($site instanceof WP_Site) { |
|
490 | 490 | $_site = $site; |
491 | - } elseif ( is_object( $site ) ) { |
|
492 | - $_site = new WP_Site( $site ); |
|
491 | + } elseif (is_object($site)) { |
|
492 | + $_site = new WP_Site($site); |
|
493 | 493 | } else { |
494 | - $_site = WP_Site::get_instance( $site ); |
|
494 | + $_site = WP_Site::get_instance($site); |
|
495 | 495 | } |
496 | 496 | |
497 | - if ( ! $_site ) { |
|
497 | + if ( ! $_site) { |
|
498 | 498 | return null; |
499 | 499 | } |
500 | 500 | |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | * |
506 | 506 | * @param WP_Site $_site Site data. |
507 | 507 | */ |
508 | - $_site = apply_filters( 'get_site', $_site ); |
|
508 | + $_site = apply_filters('get_site', $_site); |
|
509 | 509 | |
510 | 510 | return $_site; |
511 | 511 | } |
@@ -521,14 +521,14 @@ discard block |
||
521 | 521 | * |
522 | 522 | * @param array $ids ID list. |
523 | 523 | */ |
524 | -function _prime_site_caches( $ids ) { |
|
524 | +function _prime_site_caches($ids) { |
|
525 | 525 | global $wpdb; |
526 | 526 | |
527 | - $non_cached_ids = _get_non_cached_ids( $ids, 'sites' ); |
|
528 | - if ( ! empty( $non_cached_ids ) ) { |
|
529 | - $fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) ); |
|
527 | + $non_cached_ids = _get_non_cached_ids($ids, 'sites'); |
|
528 | + if ( ! empty($non_cached_ids)) { |
|
529 | + $fresh_sites = $wpdb->get_results(sprintf("SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join(",", array_map('intval', $non_cached_ids)))); |
|
530 | 530 | |
531 | - update_site_cache( $fresh_sites ); |
|
531 | + update_site_cache($fresh_sites); |
|
532 | 532 | } |
533 | 533 | } |
534 | 534 | |
@@ -539,14 +539,14 @@ discard block |
||
539 | 539 | * |
540 | 540 | * @param array $sites Array of site objects. |
541 | 541 | */ |
542 | -function update_site_cache( $sites ) { |
|
543 | - if ( ! $sites ) { |
|
542 | +function update_site_cache($sites) { |
|
543 | + if ( ! $sites) { |
|
544 | 544 | return; |
545 | 545 | } |
546 | 546 | |
547 | - foreach ( $sites as $site ) { |
|
548 | - wp_cache_add( $site->blog_id, $site, 'sites' ); |
|
549 | - wp_cache_add( $site->blog_id . 'short', $site, 'blog-details' ); |
|
547 | + foreach ($sites as $site) { |
|
548 | + wp_cache_add($site->blog_id, $site, 'sites'); |
|
549 | + wp_cache_add($site->blog_id.'short', $site, 'blog-details'); |
|
550 | 550 | } |
551 | 551 | } |
552 | 552 | |
@@ -601,10 +601,10 @@ discard block |
||
601 | 601 | * } |
602 | 602 | * @return array List of sites. |
603 | 603 | */ |
604 | -function get_sites( $args = array() ) { |
|
604 | +function get_sites($args = array()) { |
|
605 | 605 | $query = new WP_Site_Query(); |
606 | 606 | |
607 | - return $query->query( $args ); |
|
607 | + return $query->query($args); |
|
608 | 608 | } |
609 | 609 | |
610 | 610 | /** |
@@ -624,17 +624,17 @@ discard block |
||
624 | 624 | * @param mixed $default Optional. Default value to return if the option does not exist. |
625 | 625 | * @return mixed Value set for the option. |
626 | 626 | */ |
627 | -function get_blog_option( $id, $option, $default = false ) { |
|
627 | +function get_blog_option($id, $option, $default = false) { |
|
628 | 628 | $id = (int) $id; |
629 | 629 | |
630 | - if ( empty( $id ) ) |
|
630 | + if (empty($id)) |
|
631 | 631 | $id = get_current_blog_id(); |
632 | 632 | |
633 | - if ( get_current_blog_id() == $id ) |
|
634 | - return get_option( $option, $default ); |
|
633 | + if (get_current_blog_id() == $id) |
|
634 | + return get_option($option, $default); |
|
635 | 635 | |
636 | - switch_to_blog( $id ); |
|
637 | - $value = get_option( $option, $default ); |
|
636 | + switch_to_blog($id); |
|
637 | + $value = get_option($option, $default); |
|
638 | 638 | restore_current_blog(); |
639 | 639 | |
640 | 640 | /** |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | * @param string $value The option value. |
648 | 648 | * @param int $id Blog ID. |
649 | 649 | */ |
650 | - return apply_filters( "blog_option_{$option}", $value, $id ); |
|
650 | + return apply_filters("blog_option_{$option}", $value, $id); |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | /** |
@@ -669,17 +669,17 @@ discard block |
||
669 | 669 | * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped. |
670 | 670 | * @return bool False if option was not added and true if option was added. |
671 | 671 | */ |
672 | -function add_blog_option( $id, $option, $value ) { |
|
672 | +function add_blog_option($id, $option, $value) { |
|
673 | 673 | $id = (int) $id; |
674 | 674 | |
675 | - if ( empty( $id ) ) |
|
675 | + if (empty($id)) |
|
676 | 676 | $id = get_current_blog_id(); |
677 | 677 | |
678 | - if ( get_current_blog_id() == $id ) |
|
679 | - return add_option( $option, $value ); |
|
678 | + if (get_current_blog_id() == $id) |
|
679 | + return add_option($option, $value); |
|
680 | 680 | |
681 | - switch_to_blog( $id ); |
|
682 | - $return = add_option( $option, $value ); |
|
681 | + switch_to_blog($id); |
|
682 | + $return = add_option($option, $value); |
|
683 | 683 | restore_current_blog(); |
684 | 684 | |
685 | 685 | return $return; |
@@ -694,17 +694,17 @@ discard block |
||
694 | 694 | * @param string $option Name of option to remove. Expected to not be SQL-escaped. |
695 | 695 | * @return bool True, if option is successfully deleted. False on failure. |
696 | 696 | */ |
697 | -function delete_blog_option( $id, $option ) { |
|
697 | +function delete_blog_option($id, $option) { |
|
698 | 698 | $id = (int) $id; |
699 | 699 | |
700 | - if ( empty( $id ) ) |
|
700 | + if (empty($id)) |
|
701 | 701 | $id = get_current_blog_id(); |
702 | 702 | |
703 | - if ( get_current_blog_id() == $id ) |
|
704 | - return delete_option( $option ); |
|
703 | + if (get_current_blog_id() == $id) |
|
704 | + return delete_option($option); |
|
705 | 705 | |
706 | - switch_to_blog( $id ); |
|
707 | - $return = delete_option( $option ); |
|
706 | + switch_to_blog($id); |
|
707 | + $return = delete_option($option); |
|
708 | 708 | restore_current_blog(); |
709 | 709 | |
710 | 710 | return $return; |
@@ -721,20 +721,20 @@ discard block |
||
721 | 721 | * @param mixed $deprecated Not used. |
722 | 722 | * @return bool True on success, false on failure. |
723 | 723 | */ |
724 | -function update_blog_option( $id, $option, $value, $deprecated = null ) { |
|
724 | +function update_blog_option($id, $option, $value, $deprecated = null) { |
|
725 | 725 | $id = (int) $id; |
726 | 726 | |
727 | - if ( null !== $deprecated ) |
|
728 | - _deprecated_argument( __FUNCTION__, '3.1.0' ); |
|
727 | + if (null !== $deprecated) |
|
728 | + _deprecated_argument(__FUNCTION__, '3.1.0'); |
|
729 | 729 | |
730 | - if ( get_current_blog_id() == $id ) |
|
731 | - return update_option( $option, $value ); |
|
730 | + if (get_current_blog_id() == $id) |
|
731 | + return update_option($option, $value); |
|
732 | 732 | |
733 | - switch_to_blog( $id ); |
|
734 | - $return = update_option( $option, $value ); |
|
733 | + switch_to_blog($id); |
|
734 | + $return = update_option($option, $value); |
|
735 | 735 | restore_current_blog(); |
736 | 736 | |
737 | - refresh_blog_details( $id ); |
|
737 | + refresh_blog_details($id); |
|
738 | 738 | |
739 | 739 | return $return; |
740 | 740 | } |
@@ -763,10 +763,10 @@ discard block |
||
763 | 763 | * @param bool $deprecated Deprecated argument |
764 | 764 | * @return true Always returns True. |
765 | 765 | */ |
766 | -function switch_to_blog( $new_blog, $deprecated = null ) { |
|
766 | +function switch_to_blog($new_blog, $deprecated = null) { |
|
767 | 767 | global $wpdb; |
768 | 768 | |
769 | - if ( empty( $new_blog ) ) |
|
769 | + if (empty($new_blog)) |
|
770 | 770 | $new_blog = $GLOBALS['blog_id']; |
771 | 771 | |
772 | 772 | $GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id']; |
@@ -776,7 +776,7 @@ discard block |
||
776 | 776 | * set the right vars, do the associated actions, but skip |
777 | 777 | * the extra unnecessary work |
778 | 778 | */ |
779 | - if ( $new_blog == $GLOBALS['blog_id'] ) { |
|
779 | + if ($new_blog == $GLOBALS['blog_id']) { |
|
780 | 780 | /** |
781 | 781 | * Fires when the blog is switched. |
782 | 782 | * |
@@ -785,46 +785,46 @@ discard block |
||
785 | 785 | * @param int $new_blog New blog ID. |
786 | 786 | * @param int $new_blog Blog ID. |
787 | 787 | */ |
788 | - do_action( 'switch_blog', $new_blog, $new_blog ); |
|
788 | + do_action('switch_blog', $new_blog, $new_blog); |
|
789 | 789 | $GLOBALS['switched'] = true; |
790 | 790 | return true; |
791 | 791 | } |
792 | 792 | |
793 | - $wpdb->set_blog_id( $new_blog ); |
|
793 | + $wpdb->set_blog_id($new_blog); |
|
794 | 794 | $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); |
795 | 795 | $prev_blog_id = $GLOBALS['blog_id']; |
796 | 796 | $GLOBALS['blog_id'] = $new_blog; |
797 | 797 | |
798 | - if ( function_exists( 'wp_cache_switch_to_blog' ) ) { |
|
799 | - wp_cache_switch_to_blog( $new_blog ); |
|
798 | + if (function_exists('wp_cache_switch_to_blog')) { |
|
799 | + wp_cache_switch_to_blog($new_blog); |
|
800 | 800 | } else { |
801 | 801 | global $wp_object_cache; |
802 | 802 | |
803 | - if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) |
|
803 | + if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) |
|
804 | 804 | $global_groups = $wp_object_cache->global_groups; |
805 | 805 | else |
806 | 806 | $global_groups = false; |
807 | 807 | |
808 | 808 | wp_cache_init(); |
809 | 809 | |
810 | - if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
|
811 | - if ( is_array( $global_groups ) ) { |
|
812 | - wp_cache_add_global_groups( $global_groups ); |
|
810 | + if (function_exists('wp_cache_add_global_groups')) { |
|
811 | + if (is_array($global_groups)) { |
|
812 | + wp_cache_add_global_groups($global_groups); |
|
813 | 813 | } else { |
814 | - wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) ); |
|
814 | + wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details')); |
|
815 | 815 | } |
816 | - wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); |
|
816 | + wp_cache_add_non_persistent_groups(array('counts', 'plugins')); |
|
817 | 817 | } |
818 | 818 | } |
819 | 819 | |
820 | - if ( did_action( 'init' ) ) { |
|
820 | + if (did_action('init')) { |
|
821 | 821 | wp_roles()->reinit(); |
822 | 822 | $current_user = wp_get_current_user(); |
823 | - $current_user->for_blog( $new_blog ); |
|
823 | + $current_user->for_blog($new_blog); |
|
824 | 824 | } |
825 | 825 | |
826 | 826 | /** This filter is documented in wp-includes/ms-blogs.php */ |
827 | - do_action( 'switch_blog', $new_blog, $prev_blog_id ); |
|
827 | + do_action('switch_blog', $new_blog, $prev_blog_id); |
|
828 | 828 | $GLOBALS['switched'] = true; |
829 | 829 | |
830 | 830 | return true; |
@@ -848,57 +848,57 @@ discard block |
||
848 | 848 | function restore_current_blog() { |
849 | 849 | global $wpdb; |
850 | 850 | |
851 | - if ( empty( $GLOBALS['_wp_switched_stack'] ) ) |
|
851 | + if (empty($GLOBALS['_wp_switched_stack'])) |
|
852 | 852 | return false; |
853 | 853 | |
854 | - $blog = array_pop( $GLOBALS['_wp_switched_stack'] ); |
|
854 | + $blog = array_pop($GLOBALS['_wp_switched_stack']); |
|
855 | 855 | |
856 | - if ( $GLOBALS['blog_id'] == $blog ) { |
|
856 | + if ($GLOBALS['blog_id'] == $blog) { |
|
857 | 857 | /** This filter is documented in wp-includes/ms-blogs.php */ |
858 | - do_action( 'switch_blog', $blog, $blog ); |
|
858 | + do_action('switch_blog', $blog, $blog); |
|
859 | 859 | // If we still have items in the switched stack, consider ourselves still 'switched' |
860 | - $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); |
|
860 | + $GLOBALS['switched'] = ! empty($GLOBALS['_wp_switched_stack']); |
|
861 | 861 | return true; |
862 | 862 | } |
863 | 863 | |
864 | - $wpdb->set_blog_id( $blog ); |
|
864 | + $wpdb->set_blog_id($blog); |
|
865 | 865 | $prev_blog_id = $GLOBALS['blog_id']; |
866 | 866 | $GLOBALS['blog_id'] = $blog; |
867 | 867 | $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix(); |
868 | 868 | |
869 | - if ( function_exists( 'wp_cache_switch_to_blog' ) ) { |
|
870 | - wp_cache_switch_to_blog( $blog ); |
|
869 | + if (function_exists('wp_cache_switch_to_blog')) { |
|
870 | + wp_cache_switch_to_blog($blog); |
|
871 | 871 | } else { |
872 | 872 | global $wp_object_cache; |
873 | 873 | |
874 | - if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) |
|
874 | + if (is_object($wp_object_cache) && isset($wp_object_cache->global_groups)) |
|
875 | 875 | $global_groups = $wp_object_cache->global_groups; |
876 | 876 | else |
877 | 877 | $global_groups = false; |
878 | 878 | |
879 | 879 | wp_cache_init(); |
880 | 880 | |
881 | - if ( function_exists( 'wp_cache_add_global_groups' ) ) { |
|
882 | - if ( is_array( $global_groups ) ) { |
|
883 | - wp_cache_add_global_groups( $global_groups ); |
|
881 | + if (function_exists('wp_cache_add_global_groups')) { |
|
882 | + if (is_array($global_groups)) { |
|
883 | + wp_cache_add_global_groups($global_groups); |
|
884 | 884 | } else { |
885 | - wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details' ) ); |
|
885 | + wp_cache_add_global_groups(array('users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites', 'site-details')); |
|
886 | 886 | } |
887 | - wp_cache_add_non_persistent_groups( array( 'counts', 'plugins' ) ); |
|
887 | + wp_cache_add_non_persistent_groups(array('counts', 'plugins')); |
|
888 | 888 | } |
889 | 889 | } |
890 | 890 | |
891 | - if ( did_action( 'init' ) ) { |
|
891 | + if (did_action('init')) { |
|
892 | 892 | wp_roles()->reinit(); |
893 | 893 | $current_user = wp_get_current_user(); |
894 | - $current_user->for_blog( $blog ); |
|
894 | + $current_user->for_blog($blog); |
|
895 | 895 | } |
896 | 896 | |
897 | 897 | /** This filter is documented in wp-includes/ms-blogs.php */ |
898 | - do_action( 'switch_blog', $blog, $prev_blog_id ); |
|
898 | + do_action('switch_blog', $blog, $prev_blog_id); |
|
899 | 899 | |
900 | 900 | // If we still have items in the switched stack, consider ourselves still 'switched' |
901 | - $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); |
|
901 | + $GLOBALS['switched'] = ! empty($GLOBALS['_wp_switched_stack']); |
|
902 | 902 | |
903 | 903 | return true; |
904 | 904 | } |
@@ -913,7 +913,7 @@ discard block |
||
913 | 913 | * @return bool True if switched, false otherwise. |
914 | 914 | */ |
915 | 915 | function ms_is_switched() { |
916 | - return ! empty( $GLOBALS['_wp_switched_stack'] ); |
|
916 | + return ! empty($GLOBALS['_wp_switched_stack']); |
|
917 | 917 | } |
918 | 918 | |
919 | 919 | /** |
@@ -924,7 +924,7 @@ discard block |
||
924 | 924 | * @param int $id The blog id |
925 | 925 | * @return string Whether the blog is archived or not |
926 | 926 | */ |
927 | -function is_archived( $id ) { |
|
927 | +function is_archived($id) { |
|
928 | 928 | return get_blog_status($id, 'archived'); |
929 | 929 | } |
930 | 930 | |
@@ -937,7 +937,7 @@ discard block |
||
937 | 937 | * @param string $archived The new status |
938 | 938 | * @return string $archived |
939 | 939 | */ |
940 | -function update_archived( $id, $archived ) { |
|
940 | +function update_archived($id, $archived) { |
|
941 | 941 | update_blog_status($id, 'archived', $archived); |
942 | 942 | return $archived; |
943 | 943 | } |
@@ -955,55 +955,55 @@ discard block |
||
955 | 955 | * @param null $deprecated |
956 | 956 | * @return string|false $value |
957 | 957 | */ |
958 | -function update_blog_status( $blog_id, $pref, $value, $deprecated = null ) { |
|
958 | +function update_blog_status($blog_id, $pref, $value, $deprecated = null) { |
|
959 | 959 | global $wpdb; |
960 | 960 | |
961 | - if ( null !== $deprecated ) |
|
962 | - _deprecated_argument( __FUNCTION__, '3.1.0' ); |
|
961 | + if (null !== $deprecated) |
|
962 | + _deprecated_argument(__FUNCTION__, '3.1.0'); |
|
963 | 963 | |
964 | - if ( ! in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id') ) ) |
|
964 | + if ( ! in_array($pref, array('site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id'))) |
|
965 | 965 | return $value; |
966 | 966 | |
967 | - $result = $wpdb->update( $wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id) ); |
|
967 | + $result = $wpdb->update($wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id)); |
|
968 | 968 | |
969 | - if ( false === $result ) |
|
969 | + if (false === $result) |
|
970 | 970 | return false; |
971 | 971 | |
972 | - refresh_blog_details( $blog_id ); |
|
972 | + refresh_blog_details($blog_id); |
|
973 | 973 | |
974 | - if ( 'spam' == $pref ) { |
|
975 | - if ( $value == 1 ) { |
|
974 | + if ('spam' == $pref) { |
|
975 | + if ($value == 1) { |
|
976 | 976 | /** This filter is documented in wp-includes/ms-blogs.php */ |
977 | - do_action( 'make_spam_blog', $blog_id ); |
|
977 | + do_action('make_spam_blog', $blog_id); |
|
978 | 978 | } else { |
979 | 979 | /** This filter is documented in wp-includes/ms-blogs.php */ |
980 | - do_action( 'make_ham_blog', $blog_id ); |
|
980 | + do_action('make_ham_blog', $blog_id); |
|
981 | 981 | } |
982 | - } elseif ( 'mature' == $pref ) { |
|
983 | - if ( $value == 1 ) { |
|
982 | + } elseif ('mature' == $pref) { |
|
983 | + if ($value == 1) { |
|
984 | 984 | /** This filter is documented in wp-includes/ms-blogs.php */ |
985 | - do_action( 'mature_blog', $blog_id ); |
|
985 | + do_action('mature_blog', $blog_id); |
|
986 | 986 | } else { |
987 | 987 | /** This filter is documented in wp-includes/ms-blogs.php */ |
988 | - do_action( 'unmature_blog', $blog_id ); |
|
988 | + do_action('unmature_blog', $blog_id); |
|
989 | 989 | } |
990 | - } elseif ( 'archived' == $pref ) { |
|
991 | - if ( $value == 1 ) { |
|
990 | + } elseif ('archived' == $pref) { |
|
991 | + if ($value == 1) { |
|
992 | 992 | /** This filter is documented in wp-includes/ms-blogs.php */ |
993 | - do_action( 'archive_blog', $blog_id ); |
|
993 | + do_action('archive_blog', $blog_id); |
|
994 | 994 | } else { |
995 | 995 | /** This filter is documented in wp-includes/ms-blogs.php */ |
996 | - do_action( 'unarchive_blog', $blog_id ); |
|
996 | + do_action('unarchive_blog', $blog_id); |
|
997 | 997 | } |
998 | - } elseif ( 'deleted' == $pref ) { |
|
999 | - if ( $value == 1 ) { |
|
998 | + } elseif ('deleted' == $pref) { |
|
999 | + if ($value == 1) { |
|
1000 | 1000 | /** This filter is documented in wp-includes/ms-blogs.php */ |
1001 | - do_action( 'make_delete_blog', $blog_id ); |
|
1001 | + do_action('make_delete_blog', $blog_id); |
|
1002 | 1002 | } else { |
1003 | 1003 | /** This filter is documented in wp-includes/ms-blogs.php */ |
1004 | - do_action( 'make_undelete_blog', $blog_id ); |
|
1004 | + do_action('make_undelete_blog', $blog_id); |
|
1005 | 1005 | } |
1006 | - } elseif ( 'public' == $pref ) { |
|
1006 | + } elseif ('public' == $pref) { |
|
1007 | 1007 | /** |
1008 | 1008 | * Fires after the current blog's 'public' setting is updated. |
1009 | 1009 | * |
@@ -1012,7 +1012,7 @@ discard block |
||
1012 | 1012 | * @param int $blog_id Blog ID. |
1013 | 1013 | * @param string $value The value of blog status. |
1014 | 1014 | */ |
1015 | - do_action( 'update_blog_public', $blog_id, $value ); // Moved here from update_blog_public(). |
|
1015 | + do_action('update_blog_public', $blog_id, $value); // Moved here from update_blog_public(). |
|
1016 | 1016 | } |
1017 | 1017 | |
1018 | 1018 | return $value; |
@@ -1029,14 +1029,14 @@ discard block |
||
1029 | 1029 | * @param string $pref A field name |
1030 | 1030 | * @return bool|string|null $value |
1031 | 1031 | */ |
1032 | -function get_blog_status( $id, $pref ) { |
|
1032 | +function get_blog_status($id, $pref) { |
|
1033 | 1033 | global $wpdb; |
1034 | 1034 | |
1035 | - $details = get_blog_details( $id, false ); |
|
1036 | - if ( $details ) |
|
1035 | + $details = get_blog_details($id, false); |
|
1036 | + if ($details) |
|
1037 | 1037 | return $details->$pref; |
1038 | 1038 | |
1039 | - return $wpdb->get_var( $wpdb->prepare("SELECT %s FROM {$wpdb->blogs} WHERE blog_id = %d", $pref, $id) ); |
|
1039 | + return $wpdb->get_var($wpdb->prepare("SELECT %s FROM {$wpdb->blogs} WHERE blog_id = %d", $pref, $id)); |
|
1040 | 1040 | } |
1041 | 1041 | |
1042 | 1042 | /** |
@@ -1051,13 +1051,13 @@ discard block |
||
1051 | 1051 | * @param int $quantity The maximum number of blogs to retrieve. Default is 40. |
1052 | 1052 | * @return array The list of blogs |
1053 | 1053 | */ |
1054 | -function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) { |
|
1054 | +function get_last_updated($deprecated = '', $start = 0, $quantity = 40) { |
|
1055 | 1055 | global $wpdb; |
1056 | 1056 | |
1057 | - if ( ! empty( $deprecated ) ) |
|
1058 | - _deprecated_argument( __FUNCTION__, 'MU' ); // never used |
|
1057 | + if ( ! empty($deprecated)) |
|
1058 | + _deprecated_argument(__FUNCTION__, 'MU'); // never used |
|
1059 | 1059 | |
1060 | - return $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC limit %d, %d", $wpdb->siteid, $start, $quantity ) , ARRAY_A ); |
|
1060 | + return $wpdb->get_results($wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC limit %d, %d", $wpdb->siteid, $start, $quantity), ARRAY_A); |
|
1061 | 1061 | } |
1062 | 1062 | |
1063 | 1063 | /** |
@@ -1069,10 +1069,10 @@ discard block |
||
1069 | 1069 | * for information on accepted arguments. Default empty array. |
1070 | 1070 | * @return int|array List of networks or number of found networks if `$count` argument is true. |
1071 | 1071 | */ |
1072 | -function get_networks( $args = array() ) { |
|
1072 | +function get_networks($args = array()) { |
|
1073 | 1073 | $query = new WP_Network_Query(); |
1074 | 1074 | |
1075 | - return $query->query( $args ); |
|
1075 | + return $query->query($args); |
|
1076 | 1076 | } |
1077 | 1077 | |
1078 | 1078 | /** |
@@ -1088,21 +1088,21 @@ discard block |
||
1088 | 1088 | * @param WP_Network|int|null $network Optional. Network to retrieve. Default is the current network. |
1089 | 1089 | * @return WP_Network|null The network object or null if not found. |
1090 | 1090 | */ |
1091 | -function get_network( $network = null ) { |
|
1091 | +function get_network($network = null) { |
|
1092 | 1092 | global $current_site; |
1093 | - if ( empty( $network ) && isset( $current_site ) ) { |
|
1093 | + if (empty($network) && isset($current_site)) { |
|
1094 | 1094 | $network = $current_site; |
1095 | 1095 | } |
1096 | 1096 | |
1097 | - if ( $network instanceof WP_Network ) { |
|
1097 | + if ($network instanceof WP_Network) { |
|
1098 | 1098 | $_network = $network; |
1099 | - } elseif ( is_object( $network ) ) { |
|
1100 | - $_network = new WP_Network( $network ); |
|
1099 | + } elseif (is_object($network)) { |
|
1100 | + $_network = new WP_Network($network); |
|
1101 | 1101 | } else { |
1102 | - $_network = WP_Network::get_instance( $network ); |
|
1102 | + $_network = WP_Network::get_instance($network); |
|
1103 | 1103 | } |
1104 | 1104 | |
1105 | - if ( ! $_network ) { |
|
1105 | + if ( ! $_network) { |
|
1106 | 1106 | return null; |
1107 | 1107 | } |
1108 | 1108 | |
@@ -1113,7 +1113,7 @@ discard block |
||
1113 | 1113 | * |
1114 | 1114 | * @param WP_Network $_network Network data. |
1115 | 1115 | */ |
1116 | - $_network = apply_filters( 'get_network', $_network ); |
|
1116 | + $_network = apply_filters('get_network', $_network); |
|
1117 | 1117 | |
1118 | 1118 | return $_network; |
1119 | 1119 | } |
@@ -1125,9 +1125,9 @@ discard block |
||
1125 | 1125 | * |
1126 | 1126 | * @param int|array $ids Network ID or an array of network IDs to remove from cache. |
1127 | 1127 | */ |
1128 | -function clean_network_cache( $ids ) { |
|
1129 | - foreach ( (array) $ids as $id ) { |
|
1130 | - wp_cache_delete( $id, 'networks' ); |
|
1128 | +function clean_network_cache($ids) { |
|
1129 | + foreach ((array) $ids as $id) { |
|
1130 | + wp_cache_delete($id, 'networks'); |
|
1131 | 1131 | |
1132 | 1132 | /** |
1133 | 1133 | * Fires immediately after a network has been removed from the object cache. |
@@ -1136,10 +1136,10 @@ discard block |
||
1136 | 1136 | * |
1137 | 1137 | * @param int $id Network ID. |
1138 | 1138 | */ |
1139 | - do_action( 'clean_network_cache', $id ); |
|
1139 | + do_action('clean_network_cache', $id); |
|
1140 | 1140 | } |
1141 | 1141 | |
1142 | - wp_cache_set( 'last_changed', microtime(), 'networks' ); |
|
1142 | + wp_cache_set('last_changed', microtime(), 'networks'); |
|
1143 | 1143 | } |
1144 | 1144 | |
1145 | 1145 | /** |
@@ -1153,9 +1153,9 @@ discard block |
||
1153 | 1153 | * |
1154 | 1154 | * @param array $networks Array of network row objects. |
1155 | 1155 | */ |
1156 | -function update_network_cache( $networks ) { |
|
1157 | - foreach ( (array) $networks as $network ) { |
|
1158 | - wp_cache_add( $network->id, $network, 'networks' ); |
|
1156 | +function update_network_cache($networks) { |
|
1157 | + foreach ((array) $networks as $network) { |
|
1158 | + wp_cache_add($network->id, $network, 'networks'); |
|
1159 | 1159 | } |
1160 | 1160 | } |
1161 | 1161 | |
@@ -1170,14 +1170,14 @@ discard block |
||
1170 | 1170 | * |
1171 | 1171 | * @param array $network_ids Array of network IDs. |
1172 | 1172 | */ |
1173 | -function _prime_network_caches( $network_ids ) { |
|
1173 | +function _prime_network_caches($network_ids) { |
|
1174 | 1174 | global $wpdb; |
1175 | 1175 | |
1176 | - $non_cached_ids = _get_non_cached_ids( $network_ids, 'networks' ); |
|
1177 | - if ( !empty( $non_cached_ids ) ) { |
|
1178 | - $fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", join( ",", array_map( 'intval', $non_cached_ids ) ) ) ); |
|
1176 | + $non_cached_ids = _get_non_cached_ids($network_ids, 'networks'); |
|
1177 | + if ( ! empty($non_cached_ids)) { |
|
1178 | + $fresh_networks = $wpdb->get_results(sprintf("SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", join(",", array_map('intval', $non_cached_ids)))); |
|
1179 | 1179 | |
1180 | - update_network_cache( $fresh_networks ); |
|
1180 | + update_network_cache($fresh_networks); |
|
1181 | 1181 | } |
1182 | 1182 | } |
1183 | 1183 | |
@@ -1190,13 +1190,13 @@ discard block |
||
1190 | 1190 | * @param string $old_status The old post status |
1191 | 1191 | * @param object $post Post object |
1192 | 1192 | */ |
1193 | -function _update_blog_date_on_post_publish( $new_status, $old_status, $post ) { |
|
1194 | - $post_type_obj = get_post_type_object( $post->post_type ); |
|
1195 | - if ( ! $post_type_obj || ! $post_type_obj->public ) { |
|
1193 | +function _update_blog_date_on_post_publish($new_status, $old_status, $post) { |
|
1194 | + $post_type_obj = get_post_type_object($post->post_type); |
|
1195 | + if ( ! $post_type_obj || ! $post_type_obj->public) { |
|
1196 | 1196 | return; |
1197 | 1197 | } |
1198 | 1198 | |
1199 | - if ( 'publish' != $new_status && 'publish' != $old_status ) { |
|
1199 | + if ('publish' != $new_status && 'publish' != $old_status) { |
|
1200 | 1200 | return; |
1201 | 1201 | } |
1202 | 1202 | |
@@ -1212,15 +1212,15 @@ discard block |
||
1212 | 1212 | * |
1213 | 1213 | * @param int $post_id Post ID |
1214 | 1214 | */ |
1215 | -function _update_blog_date_on_post_delete( $post_id ) { |
|
1216 | - $post = get_post( $post_id ); |
|
1215 | +function _update_blog_date_on_post_delete($post_id) { |
|
1216 | + $post = get_post($post_id); |
|
1217 | 1217 | |
1218 | - $post_type_obj = get_post_type_object( $post->post_type ); |
|
1219 | - if ( ! $post_type_obj || ! $post_type_obj->public ) { |
|
1218 | + $post_type_obj = get_post_type_object($post->post_type); |
|
1219 | + if ( ! $post_type_obj || ! $post_type_obj->public) { |
|
1220 | 1220 | return; |
1221 | 1221 | } |
1222 | 1222 | |
1223 | - if ( 'publish' != $post->post_status ) { |
|
1223 | + if ('publish' != $post->post_status) { |
|
1224 | 1224 | return; |
1225 | 1225 | } |
1226 | 1226 | |
@@ -1234,10 +1234,10 @@ discard block |
||
1234 | 1234 | * |
1235 | 1235 | * @param int $post_id Post ID. |
1236 | 1236 | */ |
1237 | -function _update_posts_count_on_delete( $post_id ) { |
|
1238 | - $post = get_post( $post_id ); |
|
1237 | +function _update_posts_count_on_delete($post_id) { |
|
1238 | + $post = get_post($post_id); |
|
1239 | 1239 | |
1240 | - if ( ! $post || 'publish' !== $post->post_status ) { |
|
1240 | + if ( ! $post || 'publish' !== $post->post_status) { |
|
1241 | 1241 | return; |
1242 | 1242 | } |
1243 | 1243 | |
@@ -1252,12 +1252,12 @@ discard block |
||
1252 | 1252 | * @param string $new_status The status the post is changing to. |
1253 | 1253 | * @param string $old_status The status the post is changing from. |
1254 | 1254 | */ |
1255 | -function _update_posts_count_on_transition_post_status( $new_status, $old_status ) { |
|
1256 | - if ( $new_status === $old_status ) { |
|
1255 | +function _update_posts_count_on_transition_post_status($new_status, $old_status) { |
|
1256 | + if ($new_status === $old_status) { |
|
1257 | 1257 | return; |
1258 | 1258 | } |
1259 | 1259 | |
1260 | - if ( 'publish' !== $new_status && 'publish' !== $old_status ) { |
|
1260 | + if ('publish' !== $new_status && 'publish' !== $old_status) { |
|
1261 | 1261 | return; |
1262 | 1262 | } |
1263 | 1263 |
@@ -60,11 +60,13 @@ discard block |
||
60 | 60 | */ |
61 | 61 | function get_blogaddress_by_name( $blogname ) { |
62 | 62 | if ( is_subdomain_install() ) { |
63 | - if ( $blogname == 'main' ) |
|
64 | - $blogname = 'www'; |
|
63 | + if ( $blogname == 'main' ) { |
|
64 | + $blogname = 'www'; |
|
65 | + } |
|
65 | 66 | $url = rtrim( network_home_url(), '/' ); |
66 | - if ( !empty( $blogname ) ) |
|
67 | - $url = preg_replace( '|^([^\.]+://)|', "\${1}" . $blogname . '.', $url ); |
|
67 | + if ( !empty( $blogname ) ) { |
|
68 | + $url = preg_replace( '|^([^\.]+://)|', "\${1}" . $blogname . '.', $url ); |
|
69 | + } |
|
68 | 70 | } else { |
69 | 71 | $url = network_home_url( $blogname ); |
70 | 72 | } |
@@ -88,8 +90,9 @@ discard block |
||
88 | 90 | $slug = trim( $slug, '/' ); |
89 | 91 | |
90 | 92 | $blog_id = wp_cache_get( 'get_id_from_blogname_' . $slug, 'blog-details' ); |
91 | - if ( $blog_id ) |
|
92 | - return $blog_id; |
|
93 | + if ( $blog_id ) { |
|
94 | + return $blog_id; |
|
95 | + } |
|
93 | 96 | |
94 | 97 | if ( is_subdomain_install() ) { |
95 | 98 | $domain = $slug . '.' . $current_site->domain; |
@@ -126,8 +129,9 @@ discard block |
||
126 | 129 | } elseif ( isset($fields['domain']) && isset($fields['path']) ) { |
127 | 130 | $key = md5( $fields['domain'] . $fields['path'] ); |
128 | 131 | $blog = wp_cache_get($key, 'blog-lookup'); |
129 | - if ( false !== $blog ) |
|
130 | - return $blog; |
|
132 | + if ( false !== $blog ) { |
|
133 | + return $blog; |
|
134 | + } |
|
131 | 135 | if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) { |
132 | 136 | $nowww = substr( $fields['domain'], 4 ); |
133 | 137 | $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) ); |
@@ -143,8 +147,9 @@ discard block |
||
143 | 147 | } elseif ( isset($fields['domain']) && is_subdomain_install() ) { |
144 | 148 | $key = md5( $fields['domain'] ); |
145 | 149 | $blog = wp_cache_get($key, 'blog-lookup'); |
146 | - if ( false !== $blog ) |
|
147 | - return $blog; |
|
150 | + if ( false !== $blog ) { |
|
151 | + return $blog; |
|
152 | + } |
|
148 | 153 | if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) { |
149 | 154 | $nowww = substr( $fields['domain'], 4 ); |
150 | 155 | $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) ); |
@@ -161,12 +166,13 @@ discard block |
||
161 | 166 | return false; |
162 | 167 | } |
163 | 168 | } else { |
164 | - if ( ! $fields ) |
|
165 | - $blog_id = get_current_blog_id(); |
|
166 | - elseif ( ! is_numeric( $fields ) ) |
|
167 | - $blog_id = get_id_from_blogname( $fields ); |
|
168 | - else |
|
169 | - $blog_id = $fields; |
|
169 | + if ( ! $fields ) { |
|
170 | + $blog_id = get_current_blog_id(); |
|
171 | + } elseif ( ! is_numeric( $fields ) ) { |
|
172 | + $blog_id = get_id_from_blogname( $fields ); |
|
173 | + } else { |
|
174 | + $blog_id = $fields; |
|
175 | + } |
|
170 | 176 | } |
171 | 177 | |
172 | 178 | $blog_id = (int) $blog_id; |
@@ -302,15 +308,18 @@ discard block |
||
302 | 308 | function update_blog_details( $blog_id, $details = array() ) { |
303 | 309 | global $wpdb; |
304 | 310 | |
305 | - if ( empty($details) ) |
|
306 | - return false; |
|
311 | + if ( empty($details) ) { |
|
312 | + return false; |
|
313 | + } |
|
307 | 314 | |
308 | - if ( is_object($details) ) |
|
309 | - $details = get_object_vars($details); |
|
315 | + if ( is_object($details) ) { |
|
316 | + $details = get_object_vars($details); |
|
317 | + } |
|
310 | 318 | |
311 | 319 | $current_details = get_blog_details($blog_id, false); |
312 | - if ( empty($current_details) ) |
|
313 | - return false; |
|
320 | + if ( empty($current_details) ) { |
|
321 | + return false; |
|
322 | + } |
|
314 | 323 | |
315 | 324 | $current_details = get_object_vars($current_details); |
316 | 325 | |
@@ -329,8 +338,9 @@ discard block |
||
329 | 338 | |
330 | 339 | $result = $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) ); |
331 | 340 | |
332 | - if ( false === $result ) |
|
333 | - return false; |
|
341 | + if ( false === $result ) { |
|
342 | + return false; |
|
343 | + } |
|
334 | 344 | |
335 | 345 | // If spam status changed, issue actions. |
336 | 346 | if ( $details['spam'] != $current_details['spam'] ) { |
@@ -627,11 +637,13 @@ discard block |
||
627 | 637 | function get_blog_option( $id, $option, $default = false ) { |
628 | 638 | $id = (int) $id; |
629 | 639 | |
630 | - if ( empty( $id ) ) |
|
631 | - $id = get_current_blog_id(); |
|
640 | + if ( empty( $id ) ) { |
|
641 | + $id = get_current_blog_id(); |
|
642 | + } |
|
632 | 643 | |
633 | - if ( get_current_blog_id() == $id ) |
|
634 | - return get_option( $option, $default ); |
|
644 | + if ( get_current_blog_id() == $id ) { |
|
645 | + return get_option( $option, $default ); |
|
646 | + } |
|
635 | 647 | |
636 | 648 | switch_to_blog( $id ); |
637 | 649 | $value = get_option( $option, $default ); |
@@ -672,11 +684,13 @@ discard block |
||
672 | 684 | function add_blog_option( $id, $option, $value ) { |
673 | 685 | $id = (int) $id; |
674 | 686 | |
675 | - if ( empty( $id ) ) |
|
676 | - $id = get_current_blog_id(); |
|
687 | + if ( empty( $id ) ) { |
|
688 | + $id = get_current_blog_id(); |
|
689 | + } |
|
677 | 690 | |
678 | - if ( get_current_blog_id() == $id ) |
|
679 | - return add_option( $option, $value ); |
|
691 | + if ( get_current_blog_id() == $id ) { |
|
692 | + return add_option( $option, $value ); |
|
693 | + } |
|
680 | 694 | |
681 | 695 | switch_to_blog( $id ); |
682 | 696 | $return = add_option( $option, $value ); |
@@ -697,11 +711,13 @@ discard block |
||
697 | 711 | function delete_blog_option( $id, $option ) { |
698 | 712 | $id = (int) $id; |
699 | 713 | |
700 | - if ( empty( $id ) ) |
|
701 | - $id = get_current_blog_id(); |
|
714 | + if ( empty( $id ) ) { |
|
715 | + $id = get_current_blog_id(); |
|
716 | + } |
|
702 | 717 | |
703 | - if ( get_current_blog_id() == $id ) |
|
704 | - return delete_option( $option ); |
|
718 | + if ( get_current_blog_id() == $id ) { |
|
719 | + return delete_option( $option ); |
|
720 | + } |
|
705 | 721 | |
706 | 722 | switch_to_blog( $id ); |
707 | 723 | $return = delete_option( $option ); |
@@ -724,11 +740,13 @@ discard block |
||
724 | 740 | function update_blog_option( $id, $option, $value, $deprecated = null ) { |
725 | 741 | $id = (int) $id; |
726 | 742 | |
727 | - if ( null !== $deprecated ) |
|
728 | - _deprecated_argument( __FUNCTION__, '3.1.0' ); |
|
743 | + if ( null !== $deprecated ) { |
|
744 | + _deprecated_argument( __FUNCTION__, '3.1.0' ); |
|
745 | + } |
|
729 | 746 | |
730 | - if ( get_current_blog_id() == $id ) |
|
731 | - return update_option( $option, $value ); |
|
747 | + if ( get_current_blog_id() == $id ) { |
|
748 | + return update_option( $option, $value ); |
|
749 | + } |
|
732 | 750 | |
733 | 751 | switch_to_blog( $id ); |
734 | 752 | $return = update_option( $option, $value ); |
@@ -766,8 +784,9 @@ discard block |
||
766 | 784 | function switch_to_blog( $new_blog, $deprecated = null ) { |
767 | 785 | global $wpdb; |
768 | 786 | |
769 | - if ( empty( $new_blog ) ) |
|
770 | - $new_blog = $GLOBALS['blog_id']; |
|
787 | + if ( empty( $new_blog ) ) { |
|
788 | + $new_blog = $GLOBALS['blog_id']; |
|
789 | + } |
|
771 | 790 | |
772 | 791 | $GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id']; |
773 | 792 | |
@@ -800,10 +819,11 @@ discard block |
||
800 | 819 | } else { |
801 | 820 | global $wp_object_cache; |
802 | 821 | |
803 | - if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) |
|
804 | - $global_groups = $wp_object_cache->global_groups; |
|
805 | - else |
|
806 | - $global_groups = false; |
|
822 | + if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) { |
|
823 | + $global_groups = $wp_object_cache->global_groups; |
|
824 | + } else { |
|
825 | + $global_groups = false; |
|
826 | + } |
|
807 | 827 | |
808 | 828 | wp_cache_init(); |
809 | 829 | |
@@ -848,8 +868,9 @@ discard block |
||
848 | 868 | function restore_current_blog() { |
849 | 869 | global $wpdb; |
850 | 870 | |
851 | - if ( empty( $GLOBALS['_wp_switched_stack'] ) ) |
|
852 | - return false; |
|
871 | + if ( empty( $GLOBALS['_wp_switched_stack'] ) ) { |
|
872 | + return false; |
|
873 | + } |
|
853 | 874 | |
854 | 875 | $blog = array_pop( $GLOBALS['_wp_switched_stack'] ); |
855 | 876 | |
@@ -871,10 +892,11 @@ discard block |
||
871 | 892 | } else { |
872 | 893 | global $wp_object_cache; |
873 | 894 | |
874 | - if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) |
|
875 | - $global_groups = $wp_object_cache->global_groups; |
|
876 | - else |
|
877 | - $global_groups = false; |
|
895 | + if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) { |
|
896 | + $global_groups = $wp_object_cache->global_groups; |
|
897 | + } else { |
|
898 | + $global_groups = false; |
|
899 | + } |
|
878 | 900 | |
879 | 901 | wp_cache_init(); |
880 | 902 | |
@@ -958,16 +980,19 @@ discard block |
||
958 | 980 | function update_blog_status( $blog_id, $pref, $value, $deprecated = null ) { |
959 | 981 | global $wpdb; |
960 | 982 | |
961 | - if ( null !== $deprecated ) |
|
962 | - _deprecated_argument( __FUNCTION__, '3.1.0' ); |
|
983 | + if ( null !== $deprecated ) { |
|
984 | + _deprecated_argument( __FUNCTION__, '3.1.0' ); |
|
985 | + } |
|
963 | 986 | |
964 | - if ( ! in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id') ) ) |
|
965 | - return $value; |
|
987 | + if ( ! in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id') ) ) { |
|
988 | + return $value; |
|
989 | + } |
|
966 | 990 | |
967 | 991 | $result = $wpdb->update( $wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id) ); |
968 | 992 | |
969 | - if ( false === $result ) |
|
970 | - return false; |
|
993 | + if ( false === $result ) { |
|
994 | + return false; |
|
995 | + } |
|
971 | 996 | |
972 | 997 | refresh_blog_details( $blog_id ); |
973 | 998 | |
@@ -1033,8 +1058,9 @@ discard block |
||
1033 | 1058 | global $wpdb; |
1034 | 1059 | |
1035 | 1060 | $details = get_blog_details( $id, false ); |
1036 | - if ( $details ) |
|
1037 | - return $details->$pref; |
|
1061 | + if ( $details ) { |
|
1062 | + return $details->$pref; |
|
1063 | + } |
|
1038 | 1064 | |
1039 | 1065 | return $wpdb->get_var( $wpdb->prepare("SELECT %s FROM {$wpdb->blogs} WHERE blog_id = %d", $pref, $id) ); |
1040 | 1066 | } |
@@ -1054,8 +1080,10 @@ discard block |
||
1054 | 1080 | function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) { |
1055 | 1081 | global $wpdb; |
1056 | 1082 | |
1057 | - if ( ! empty( $deprecated ) ) |
|
1058 | - _deprecated_argument( __FUNCTION__, 'MU' ); // never used |
|
1083 | + if ( ! empty( $deprecated ) ) { |
|
1084 | + _deprecated_argument( __FUNCTION__, 'MU' ); |
|
1085 | + } |
|
1086 | + // never used |
|
1059 | 1087 | |
1060 | 1088 | return $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC limit %d, %d", $wpdb->siteid, $start, $quantity ) , ARRAY_A ); |
1061 | 1089 | } |
@@ -65,7 +65,7 @@ |
||
65 | 65 | * |
66 | 66 | * @since 3.0.0 |
67 | 67 | * |
68 | - * @return true|string Returns true on success, or drop-in file to include. |
|
68 | + * @return boolean|string Returns true on success, or drop-in file to include. |
|
69 | 69 | */ |
70 | 70 | function ms_site_check() { |
71 | 71 | $blog = get_blog_details(); |
@@ -16,8 +16,9 @@ discard block |
||
16 | 16 | * @return bool True if subdomain configuration is enabled, false otherwise. |
17 | 17 | */ |
18 | 18 | function is_subdomain_install() { |
19 | - if ( defined('SUBDOMAIN_INSTALL') ) |
|
20 | - return SUBDOMAIN_INSTALL; |
|
19 | + if ( defined('SUBDOMAIN_INSTALL') ) { |
|
20 | + return SUBDOMAIN_INSTALL; |
|
21 | + } |
|
21 | 22 | |
22 | 23 | return ( defined( 'VHOST' ) && VHOST == 'yes' ); |
23 | 24 | } |
@@ -35,8 +36,9 @@ discard block |
||
35 | 36 | */ |
36 | 37 | function wp_get_active_network_plugins() { |
37 | 38 | $active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() ); |
38 | - if ( empty( $active_plugins ) ) |
|
39 | - return array(); |
|
39 | + if ( empty( $active_plugins ) ) { |
|
40 | + return array(); |
|
41 | + } |
|
40 | 42 | |
41 | 43 | $plugins = array(); |
42 | 44 | $active_plugins = array_keys( $active_plugins ); |
@@ -46,8 +48,9 @@ discard block |
||
46 | 48 | if ( ! validate_file( $plugin ) // $plugin must validate as file |
47 | 49 | && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php' |
48 | 50 | && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist |
49 | - ) |
|
50 | - $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; |
|
51 | + ) { |
|
52 | + $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; |
|
53 | + } |
|
51 | 54 | } |
52 | 55 | return $plugins; |
53 | 56 | } |
@@ -78,18 +81,21 @@ discard block |
||
78 | 81 | * @param bool null Whether to skip the blog status check. Default null. |
79 | 82 | */ |
80 | 83 | $check = apply_filters( 'ms_site_check', null ); |
81 | - if ( null !== $check ) |
|
82 | - return true; |
|
84 | + if ( null !== $check ) { |
|
85 | + return true; |
|
86 | + } |
|
83 | 87 | |
84 | 88 | // Allow super admins to see blocked sites |
85 | - if ( is_super_admin() ) |
|
86 | - return true; |
|
89 | + if ( is_super_admin() ) { |
|
90 | + return true; |
|
91 | + } |
|
87 | 92 | |
88 | 93 | if ( '1' == $blog->deleted ) { |
89 | - if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) ) |
|
90 | - return WP_CONTENT_DIR . '/blog-deleted.php'; |
|
91 | - else |
|
92 | - wp_die( __( 'This site is no longer available.' ), '', array( 'response' => 410 ) ); |
|
94 | + if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) ) { |
|
95 | + return WP_CONTENT_DIR . '/blog-deleted.php'; |
|
96 | + } else { |
|
97 | + wp_die( __( 'This site is no longer available.' ), '', array( 'response' => 410 ) ); |
|
98 | + } |
|
93 | 99 | } |
94 | 100 | |
95 | 101 | if ( '2' == $blog->deleted ) { |
@@ -107,10 +113,11 @@ discard block |
||
107 | 113 | } |
108 | 114 | |
109 | 115 | if ( $blog->archived == '1' || $blog->spam == '1' ) { |
110 | - if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) ) |
|
111 | - return WP_CONTENT_DIR . '/blog-suspended.php'; |
|
112 | - else |
|
113 | - wp_die( __( 'This site has been archived or suspended.' ), '', array( 'response' => 410 ) ); |
|
116 | + if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) ) { |
|
117 | + return WP_CONTENT_DIR . '/blog-suspended.php'; |
|
118 | + } else { |
|
119 | + wp_die( __( 'This site has been archived or suspended.' ), '', array( 'response' => 410 ) ); |
|
120 | + } |
|
114 | 121 | } |
115 | 122 | |
116 | 123 | return true; |
@@ -311,8 +318,9 @@ discard block |
||
311 | 318 | ); |
312 | 319 | $msg .= ' ' . __( 'If you’re still stuck with this message, then check that your database contains the following tables:' ) . '</p><ul>'; |
313 | 320 | foreach ( $wpdb->tables('global') as $t => $table ) { |
314 | - if ( 'sitecategories' == $t ) |
|
315 | - continue; |
|
321 | + if ( 'sitecategories' == $t ) { |
|
322 | + continue; |
|
323 | + } |
|
316 | 324 | $msg .= '<li>' . $table . '</li>'; |
317 | 325 | } |
318 | 326 | $msg .= '</ul>'; |
@@ -75,7 +75,7 @@ |
||
75 | 75 | * @since 3.0.0 |
76 | 76 | * |
77 | 77 | * @param bool null Whether to skip the blog status check. Default null. |
78 | - */ |
|
78 | + */ |
|
79 | 79 | $check = apply_filters( 'ms_site_check', null ); |
80 | 80 | if ( null !== $check ) |
81 | 81 | return true; |
@@ -16,10 +16,10 @@ discard block |
||
16 | 16 | * @return bool True if subdomain configuration is enabled, false otherwise. |
17 | 17 | */ |
18 | 18 | function is_subdomain_install() { |
19 | - if ( defined('SUBDOMAIN_INSTALL') ) |
|
19 | + if (defined('SUBDOMAIN_INSTALL')) |
|
20 | 20 | return SUBDOMAIN_INSTALL; |
21 | 21 | |
22 | - return ( defined( 'VHOST' ) && VHOST == 'yes' ); |
|
22 | + return (defined('VHOST') && VHOST == 'yes'); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -34,20 +34,20 @@ discard block |
||
34 | 34 | * @return array Files to include. |
35 | 35 | */ |
36 | 36 | function wp_get_active_network_plugins() { |
37 | - $active_plugins = (array) get_site_option( 'active_sitewide_plugins', array() ); |
|
38 | - if ( empty( $active_plugins ) ) |
|
37 | + $active_plugins = (array) get_site_option('active_sitewide_plugins', array()); |
|
38 | + if (empty($active_plugins)) |
|
39 | 39 | return array(); |
40 | 40 | |
41 | 41 | $plugins = array(); |
42 | - $active_plugins = array_keys( $active_plugins ); |
|
43 | - sort( $active_plugins ); |
|
42 | + $active_plugins = array_keys($active_plugins); |
|
43 | + sort($active_plugins); |
|
44 | 44 | |
45 | - foreach ( $active_plugins as $plugin ) { |
|
46 | - if ( ! validate_file( $plugin ) // $plugin must validate as file |
|
47 | - && '.php' == substr( $plugin, -4 ) // $plugin must end with '.php' |
|
48 | - && file_exists( WP_PLUGIN_DIR . '/' . $plugin ) // $plugin must exist |
|
45 | + foreach ($active_plugins as $plugin) { |
|
46 | + if ( ! validate_file($plugin) // $plugin must validate as file |
|
47 | + && '.php' == substr($plugin, -4) // $plugin must end with '.php' |
|
48 | + && file_exists(WP_PLUGIN_DIR.'/'.$plugin) // $plugin must exist |
|
49 | 49 | ) |
50 | - $plugins[] = WP_PLUGIN_DIR . '/' . $plugin; |
|
50 | + $plugins[] = WP_PLUGIN_DIR.'/'.$plugin; |
|
51 | 51 | } |
52 | 52 | return $plugins; |
53 | 53 | } |
@@ -76,42 +76,42 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @param bool null Whether to skip the blog status check. Default null. |
78 | 78 | */ |
79 | - $check = apply_filters( 'ms_site_check', null ); |
|
80 | - if ( null !== $check ) |
|
79 | + $check = apply_filters('ms_site_check', null); |
|
80 | + if (null !== $check) |
|
81 | 81 | return true; |
82 | 82 | |
83 | 83 | // Allow super admins to see blocked sites |
84 | - if ( is_super_admin() ) |
|
84 | + if (is_super_admin()) |
|
85 | 85 | return true; |
86 | 86 | |
87 | 87 | $blog = get_blog_details(); |
88 | 88 | |
89 | - if ( '1' == $blog->deleted ) { |
|
90 | - if ( file_exists( WP_CONTENT_DIR . '/blog-deleted.php' ) ) |
|
91 | - return WP_CONTENT_DIR . '/blog-deleted.php'; |
|
89 | + if ('1' == $blog->deleted) { |
|
90 | + if (file_exists(WP_CONTENT_DIR.'/blog-deleted.php')) |
|
91 | + return WP_CONTENT_DIR.'/blog-deleted.php'; |
|
92 | 92 | else |
93 | - wp_die( __( 'This site is no longer available.' ), '', array( 'response' => 410 ) ); |
|
93 | + wp_die(__('This site is no longer available.'), '', array('response' => 410)); |
|
94 | 94 | } |
95 | 95 | |
96 | - if ( '2' == $blog->deleted ) { |
|
97 | - if ( file_exists( WP_CONTENT_DIR . '/blog-inactive.php' ) ) { |
|
98 | - return WP_CONTENT_DIR . '/blog-inactive.php'; |
|
96 | + if ('2' == $blog->deleted) { |
|
97 | + if (file_exists(WP_CONTENT_DIR.'/blog-inactive.php')) { |
|
98 | + return WP_CONTENT_DIR.'/blog-inactive.php'; |
|
99 | 99 | } else { |
100 | - $admin_email = str_replace( '@', ' AT ', get_site_option( 'admin_email', 'support@' . get_current_site()->domain ) ); |
|
100 | + $admin_email = str_replace('@', ' AT ', get_site_option('admin_email', 'support@'.get_current_site()->domain)); |
|
101 | 101 | wp_die( |
102 | 102 | /* translators: %s: admin email link */ |
103 | - sprintf( __( 'This site has not been activated yet. If you are having problems activating your site, please contact %s.' ), |
|
104 | - sprintf( '<a href="mailto:%s">%s</a>', $admin_email ) |
|
103 | + sprintf(__('This site has not been activated yet. If you are having problems activating your site, please contact %s.'), |
|
104 | + sprintf('<a href="mailto:%s">%s</a>', $admin_email) |
|
105 | 105 | ) |
106 | 106 | ); |
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
110 | - if ( $blog->archived == '1' || $blog->spam == '1' ) { |
|
111 | - if ( file_exists( WP_CONTENT_DIR . '/blog-suspended.php' ) ) |
|
112 | - return WP_CONTENT_DIR . '/blog-suspended.php'; |
|
110 | + if ($blog->archived == '1' || $blog->spam == '1') { |
|
111 | + if (file_exists(WP_CONTENT_DIR.'/blog-suspended.php')) |
|
112 | + return WP_CONTENT_DIR.'/blog-suspended.php'; |
|
113 | 113 | else |
114 | - wp_die( __( 'This site has been archived or suspended.' ), '', array( 'response' => 410 ) ); |
|
114 | + wp_die(__('This site has been archived or suspended.'), '', array('response' => 410)); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | return true; |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | * @param int|null $segments Path segments to use. Defaults to null, or the full path. |
130 | 130 | * @return WP_Network|false Network object if successful. False when no network is found. |
131 | 131 | */ |
132 | -function get_network_by_path( $domain, $path, $segments = null ) { |
|
133 | - return WP_Network::get_by_path( $domain, $path, $segments ); |
|
132 | +function get_network_by_path($domain, $path, $segments = null) { |
|
133 | + return WP_Network::get_by_path($domain, $path, $segments); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -143,9 +143,9 @@ discard block |
||
143 | 143 | * @param object|int $network The network's database row or ID. |
144 | 144 | * @return WP_Network|false Object containing network information if found, false if not. |
145 | 145 | */ |
146 | -function wp_get_network( $network ) { |
|
147 | - $network = get_network( $network ); |
|
148 | - if ( null === $network ) { |
|
146 | +function wp_get_network($network) { |
|
147 | + $network = get_network($network); |
|
148 | + if (null === $network) { |
|
149 | 149 | return false; |
150 | 150 | } |
151 | 151 | |
@@ -164,8 +164,8 @@ discard block |
||
164 | 164 | * @param int|null $segments Path segments to use. Defaults to null, or the full path. |
165 | 165 | * @return object|false Site object if successful. False when no site is found. |
166 | 166 | */ |
167 | -function get_site_by_path( $domain, $path, $segments = null ) { |
|
168 | - $path_segments = array_filter( explode( '/', trim( $path, '/' ) ) ); |
|
167 | +function get_site_by_path($domain, $path, $segments = null) { |
|
168 | + $path_segments = array_filter(explode('/', trim($path, '/'))); |
|
169 | 169 | |
170 | 170 | /** |
171 | 171 | * Filters the number of path segments to consider when searching for a site. |
@@ -178,17 +178,17 @@ discard block |
||
178 | 178 | * @param string $domain The requested domain. |
179 | 179 | * @param string $path The requested path, in full. |
180 | 180 | */ |
181 | - $segments = apply_filters( 'site_by_path_segments_count', $segments, $domain, $path ); |
|
181 | + $segments = apply_filters('site_by_path_segments_count', $segments, $domain, $path); |
|
182 | 182 | |
183 | - if ( null !== $segments && count( $path_segments ) > $segments ) { |
|
184 | - $path_segments = array_slice( $path_segments, 0, $segments ); |
|
183 | + if (null !== $segments && count($path_segments) > $segments) { |
|
184 | + $path_segments = array_slice($path_segments, 0, $segments); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | $paths = array(); |
188 | 188 | |
189 | - while ( count( $path_segments ) ) { |
|
190 | - $paths[] = '/' . implode( '/', $path_segments ) . '/'; |
|
191 | - array_pop( $path_segments ); |
|
189 | + while (count($path_segments)) { |
|
190 | + $paths[] = '/'.implode('/', $path_segments).'/'; |
|
191 | + array_pop($path_segments); |
|
192 | 192 | } |
193 | 193 | |
194 | 194 | $paths[] = '/'; |
@@ -212,8 +212,8 @@ discard block |
||
212 | 212 | * Default null, meaning the entire path was to be consulted. |
213 | 213 | * @param array $paths The paths to search for, based on $path and $segments. |
214 | 214 | */ |
215 | - $pre = apply_filters( 'pre_get_site_by_path', null, $domain, $path, $segments, $paths ); |
|
216 | - if ( null !== $pre ) { |
|
215 | + $pre = apply_filters('pre_get_site_by_path', null, $domain, $path, $segments, $paths); |
|
216 | + if (null !== $pre) { |
|
217 | 217 | return $pre; |
218 | 218 | } |
219 | 219 | |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | |
229 | 229 | // Either www or non-www is supported, not both. If a www domain is requested, |
230 | 230 | // query for both to provide the proper redirect. |
231 | - $domains = array( $domain ); |
|
232 | - if ( 'www.' === substr( $domain, 0, 4 ) ) { |
|
233 | - $domains[] = substr( $domain, 4 ); |
|
231 | + $domains = array($domain); |
|
232 | + if ('www.' === substr($domain, 0, 4)) { |
|
233 | + $domains[] = substr($domain, 4); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | $args = array( |
@@ -239,18 +239,18 @@ discard block |
||
239 | 239 | 'number' => 1, |
240 | 240 | ); |
241 | 241 | |
242 | - if ( count( $domains ) > 1 ) { |
|
242 | + if (count($domains) > 1) { |
|
243 | 243 | $args['orderby']['domain_length'] = 'DESC'; |
244 | 244 | } |
245 | 245 | |
246 | - if ( count( $paths ) > 1 ) { |
|
246 | + if (count($paths) > 1) { |
|
247 | 247 | $args['orderby']['path_length'] = 'DESC'; |
248 | 248 | } |
249 | 249 | |
250 | - $result = get_sites( $args ); |
|
251 | - $site = array_shift( $result ); |
|
250 | + $result = get_sites($args); |
|
251 | + $site = array_shift($result); |
|
252 | 252 | |
253 | - if ( $site ) { |
|
253 | + if ($site) { |
|
254 | 254 | // @todo get_blog_details() |
255 | 255 | return $site; |
256 | 256 | } |
@@ -289,55 +289,55 @@ discard block |
||
289 | 289 | * False if bootstrap could not be properly completed. |
290 | 290 | * Redirect URL if parts exist, but the request as a whole can not be fulfilled. |
291 | 291 | */ |
292 | -function ms_load_current_site_and_network( $domain, $path, $subdomain = false ) { |
|
292 | +function ms_load_current_site_and_network($domain, $path, $subdomain = false) { |
|
293 | 293 | global $wpdb, $current_site, $current_blog; |
294 | 294 | |
295 | 295 | // If the network is defined in wp-config.php, we can simply use that. |
296 | - if ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' ) ) { |
|
296 | + if (defined('DOMAIN_CURRENT_SITE') && defined('PATH_CURRENT_SITE')) { |
|
297 | 297 | $current_site = new stdClass; |
298 | - $current_site->id = defined( 'SITE_ID_CURRENT_SITE' ) ? SITE_ID_CURRENT_SITE : 1; |
|
298 | + $current_site->id = defined('SITE_ID_CURRENT_SITE') ? SITE_ID_CURRENT_SITE : 1; |
|
299 | 299 | $current_site->domain = DOMAIN_CURRENT_SITE; |
300 | 300 | $current_site->path = PATH_CURRENT_SITE; |
301 | - if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) { |
|
301 | + if (defined('BLOG_ID_CURRENT_SITE')) { |
|
302 | 302 | $current_site->blog_id = BLOG_ID_CURRENT_SITE; |
303 | - } elseif ( defined( 'BLOGID_CURRENT_SITE' ) ) { // deprecated. |
|
303 | + } elseif (defined('BLOGID_CURRENT_SITE')) { // deprecated. |
|
304 | 304 | $current_site->blog_id = BLOGID_CURRENT_SITE; |
305 | 305 | } |
306 | 306 | |
307 | - if ( 0 === strcasecmp( $current_site->domain, $domain ) && 0 === strcasecmp( $current_site->path, $path ) ) { |
|
308 | - $current_blog = get_site_by_path( $domain, $path ); |
|
309 | - } elseif ( '/' !== $current_site->path && 0 === strcasecmp( $current_site->domain, $domain ) && 0 === stripos( $path, $current_site->path ) ) { |
|
307 | + if (0 === strcasecmp($current_site->domain, $domain) && 0 === strcasecmp($current_site->path, $path)) { |
|
308 | + $current_blog = get_site_by_path($domain, $path); |
|
309 | + } elseif ('/' !== $current_site->path && 0 === strcasecmp($current_site->domain, $domain) && 0 === stripos($path, $current_site->path)) { |
|
310 | 310 | // If the current network has a path and also matches the domain and path of the request, |
311 | 311 | // we need to look for a site using the first path segment following the network's path. |
312 | - $current_blog = get_site_by_path( $domain, $path, 1 + count( explode( '/', trim( $current_site->path, '/' ) ) ) ); |
|
312 | + $current_blog = get_site_by_path($domain, $path, 1 + count(explode('/', trim($current_site->path, '/')))); |
|
313 | 313 | } else { |
314 | 314 | // Otherwise, use the first path segment (as usual). |
315 | - $current_blog = get_site_by_path( $domain, $path, 1 ); |
|
315 | + $current_blog = get_site_by_path($domain, $path, 1); |
|
316 | 316 | } |
317 | 317 | |
318 | - } elseif ( ! $subdomain ) { |
|
318 | + } elseif ( ! $subdomain) { |
|
319 | 319 | /* |
320 | 320 | * A "subdomain" install can be re-interpreted to mean "can support any domain". |
321 | 321 | * If we're not dealing with one of these installs, then the important part is determining |
322 | 322 | * the network first, because we need the network's path to identify any sites. |
323 | 323 | */ |
324 | - if ( ! $current_site = wp_cache_get( 'current_network', 'site-options' ) ) { |
|
324 | + if ( ! $current_site = wp_cache_get('current_network', 'site-options')) { |
|
325 | 325 | // Are there even two networks installed? |
326 | - $one_network = $wpdb->get_row( "SELECT * FROM $wpdb->site LIMIT 2" ); // [sic] |
|
327 | - if ( 1 === $wpdb->num_rows ) { |
|
328 | - $current_site = new WP_Network( $one_network ); |
|
329 | - wp_cache_add( 'current_network', $current_site, 'site-options' ); |
|
330 | - } elseif ( 0 === $wpdb->num_rows ) { |
|
326 | + $one_network = $wpdb->get_row("SELECT * FROM $wpdb->site LIMIT 2"); // [sic] |
|
327 | + if (1 === $wpdb->num_rows) { |
|
328 | + $current_site = new WP_Network($one_network); |
|
329 | + wp_cache_add('current_network', $current_site, 'site-options'); |
|
330 | + } elseif (0 === $wpdb->num_rows) { |
|
331 | 331 | // A network not found hook should fire here. |
332 | 332 | return false; |
333 | 333 | } |
334 | 334 | } |
335 | 335 | |
336 | - if ( empty( $current_site ) ) { |
|
337 | - $current_site = WP_Network::get_by_path( $domain, $path, 1 ); |
|
336 | + if (empty($current_site)) { |
|
337 | + $current_site = WP_Network::get_by_path($domain, $path, 1); |
|
338 | 338 | } |
339 | 339 | |
340 | - if ( empty( $current_site ) ) { |
|
340 | + if (empty($current_site)) { |
|
341 | 341 | /** |
342 | 342 | * Fires when a network cannot be found based on the requested domain and path. |
343 | 343 | * |
@@ -349,48 +349,48 @@ discard block |
||
349 | 349 | * @param string $domain The domain used to search for a network. |
350 | 350 | * @param string $path The path used to search for a path. |
351 | 351 | */ |
352 | - do_action( 'ms_network_not_found', $domain, $path ); |
|
352 | + do_action('ms_network_not_found', $domain, $path); |
|
353 | 353 | |
354 | 354 | return false; |
355 | - } elseif ( $path === $current_site->path ) { |
|
356 | - $current_blog = get_site_by_path( $domain, $path ); |
|
355 | + } elseif ($path === $current_site->path) { |
|
356 | + $current_blog = get_site_by_path($domain, $path); |
|
357 | 357 | } else { |
358 | 358 | // Search the network path + one more path segment (on top of the network path). |
359 | - $current_blog = get_site_by_path( $domain, $path, substr_count( $current_site->path, '/' ) ); |
|
359 | + $current_blog = get_site_by_path($domain, $path, substr_count($current_site->path, '/')); |
|
360 | 360 | } |
361 | 361 | } else { |
362 | 362 | // Find the site by the domain and at most the first path segment. |
363 | - $current_blog = get_site_by_path( $domain, $path, 1 ); |
|
364 | - if ( $current_blog ) { |
|
365 | - $current_site = WP_Network::get_instance( $current_blog->site_id ? $current_blog->site_id : 1 ); |
|
363 | + $current_blog = get_site_by_path($domain, $path, 1); |
|
364 | + if ($current_blog) { |
|
365 | + $current_site = WP_Network::get_instance($current_blog->site_id ? $current_blog->site_id : 1); |
|
366 | 366 | } else { |
367 | 367 | // If you don't have a site with the same domain/path as a network, you're pretty screwed, but: |
368 | - $current_site = WP_Network::get_by_path( $domain, $path, 1 ); |
|
368 | + $current_site = WP_Network::get_by_path($domain, $path, 1); |
|
369 | 369 | } |
370 | 370 | } |
371 | 371 | |
372 | 372 | // The network declared by the site trumps any constants. |
373 | - if ( $current_blog && $current_blog->site_id != $current_site->id ) { |
|
374 | - $current_site = WP_Network::get_instance( $current_blog->site_id ); |
|
373 | + if ($current_blog && $current_blog->site_id != $current_site->id) { |
|
374 | + $current_site = WP_Network::get_instance($current_blog->site_id); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | // No network has been found, bail. |
378 | - if ( empty( $current_site ) ) { |
|
378 | + if (empty($current_site)) { |
|
379 | 379 | /** This action is documented in wp-includes/ms-settings.php */ |
380 | - do_action( 'ms_network_not_found', $domain, $path ); |
|
380 | + do_action('ms_network_not_found', $domain, $path); |
|
381 | 381 | |
382 | 382 | return false; |
383 | 383 | } |
384 | 384 | |
385 | 385 | // During activation of a new subdomain, the requested site does not yet exist. |
386 | - if ( empty( $current_blog ) && wp_installing() ) { |
|
386 | + if (empty($current_blog) && wp_installing()) { |
|
387 | 387 | $current_blog = new stdClass; |
388 | 388 | $current_blog->blog_id = $blog_id = 1; |
389 | 389 | $current_blog->public = 1; |
390 | 390 | } |
391 | 391 | |
392 | 392 | // No site has been found, bail. |
393 | - if ( empty( $current_blog ) ) { |
|
393 | + if (empty($current_blog)) { |
|
394 | 394 | // We're going to redirect to the network URL, with some possible modifications. |
395 | 395 | $scheme = is_ssl() ? 'https' : 'http'; |
396 | 396 | $destination = "$scheme://{$current_site->domain}{$current_site->path}"; |
@@ -407,19 +407,19 @@ discard block |
||
407 | 407 | * @param string $domain The domain used to search for a site. |
408 | 408 | * @param string $path The path used to search for a site. |
409 | 409 | */ |
410 | - do_action( 'ms_site_not_found', $current_site, $domain, $path ); |
|
410 | + do_action('ms_site_not_found', $current_site, $domain, $path); |
|
411 | 411 | |
412 | - if ( $subdomain && ! defined( 'NOBLOGREDIRECT' ) ) { |
|
412 | + if ($subdomain && ! defined('NOBLOGREDIRECT')) { |
|
413 | 413 | // For a "subdomain" install, redirect to the signup form specifically. |
414 | - $destination .= 'wp-signup.php?new=' . str_replace( '.' . $current_site->domain, '', $domain ); |
|
415 | - } elseif ( $subdomain ) { |
|
414 | + $destination .= 'wp-signup.php?new='.str_replace('.'.$current_site->domain, '', $domain); |
|
415 | + } elseif ($subdomain) { |
|
416 | 416 | // For a "subdomain" install, the NOBLOGREDIRECT constant |
417 | 417 | // can be used to avoid a redirect to the signup form. |
418 | 418 | // Using the ms_site_not_found action is preferred to the constant. |
419 | - if ( '%siteurl%' !== NOBLOGREDIRECT ) { |
|
419 | + if ('%siteurl%' !== NOBLOGREDIRECT) { |
|
420 | 420 | $destination = NOBLOGREDIRECT; |
421 | 421 | } |
422 | - } elseif ( 0 === strcasecmp( $current_site->domain, $domain ) ) { |
|
422 | + } elseif (0 === strcasecmp($current_site->domain, $domain)) { |
|
423 | 423 | /* |
424 | 424 | * If the domain we were searching for matches the network's domain, |
425 | 425 | * it's no use redirecting back to ourselves -- it'll cause a loop. |
@@ -432,13 +432,13 @@ discard block |
||
432 | 432 | } |
433 | 433 | |
434 | 434 | // Figure out the current network's main site. |
435 | - if ( empty( $current_site->blog_id ) ) { |
|
436 | - if ( $current_blog->domain === $current_site->domain && $current_blog->path === $current_site->path ) { |
|
435 | + if (empty($current_site->blog_id)) { |
|
436 | + if ($current_blog->domain === $current_site->domain && $current_blog->path === $current_site->path) { |
|
437 | 437 | $current_site->blog_id = $current_blog->blog_id; |
438 | - } elseif ( ! $current_site->blog_id = wp_cache_get( 'network:' . $current_site->id . ':main_site', 'site-options' ) ) { |
|
439 | - $current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", |
|
440 | - $current_site->domain, $current_site->path ) ); |
|
441 | - wp_cache_add( 'network:' . $current_site->id . ':main_site', $current_site->blog_id, 'site-options' ); |
|
438 | + } elseif ( ! $current_site->blog_id = wp_cache_get('network:'.$current_site->id.':main_site', 'site-options')) { |
|
439 | + $current_site->blog_id = $wpdb->get_var($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs WHERE domain = %s AND path = %s", |
|
440 | + $current_site->domain, $current_site->path)); |
|
441 | + wp_cache_add('network:'.$current_site->id.':main_site', $current_site->blog_id, 'site-options'); |
|
442 | 442 | } |
443 | 443 | } |
444 | 444 | |
@@ -459,50 +459,50 @@ discard block |
||
459 | 459 | * @param string $domain The requested domain for the error to reference. |
460 | 460 | * @param string $path The requested path for the error to reference. |
461 | 461 | */ |
462 | -function ms_not_installed( $domain, $path ) { |
|
462 | +function ms_not_installed($domain, $path) { |
|
463 | 463 | global $wpdb; |
464 | 464 | |
465 | - if ( ! is_admin() ) { |
|
465 | + if ( ! is_admin()) { |
|
466 | 466 | dead_db(); |
467 | 467 | } |
468 | 468 | |
469 | 469 | wp_load_translations_early(); |
470 | 470 | |
471 | - $title = __( 'Error establishing a database connection' ); |
|
471 | + $title = __('Error establishing a database connection'); |
|
472 | 472 | |
473 | - $msg = '<h1>' . $title . '</h1>'; |
|
474 | - $msg .= '<p>' . __( 'If your site does not display, please contact the owner of this network.' ) . ''; |
|
475 | - $msg .= ' ' . __( 'If you are the owner of this network please check that MySQL is running properly and all tables are error free.' ) . '</p>'; |
|
476 | - $query = $wpdb->prepare( "SHOW TABLES LIKE %s", $wpdb->esc_like( $wpdb->site ) ); |
|
477 | - if ( ! $wpdb->get_var( $query ) ) { |
|
478 | - $msg .= '<p>' . sprintf( |
|
473 | + $msg = '<h1>'.$title.'</h1>'; |
|
474 | + $msg .= '<p>'.__('If your site does not display, please contact the owner of this network.').''; |
|
475 | + $msg .= ' '.__('If you are the owner of this network please check that MySQL is running properly and all tables are error free.').'</p>'; |
|
476 | + $query = $wpdb->prepare("SHOW TABLES LIKE %s", $wpdb->esc_like($wpdb->site)); |
|
477 | + if ( ! $wpdb->get_var($query)) { |
|
478 | + $msg .= '<p>'.sprintf( |
|
479 | 479 | /* translators: %s: table name */ |
480 | - __( '<strong>Database tables are missing.</strong> This means that MySQL is not running, WordPress was not installed properly, or someone deleted %s. You really should look at your database now.' ), |
|
481 | - '<code>' . $wpdb->site . '</code>' |
|
482 | - ) . '</p>'; |
|
480 | + __('<strong>Database tables are missing.</strong> This means that MySQL is not running, WordPress was not installed properly, or someone deleted %s. You really should look at your database now.'), |
|
481 | + '<code>'.$wpdb->site.'</code>' |
|
482 | + ).'</p>'; |
|
483 | 483 | } else { |
484 | - $msg .= '<p>' . sprintf( |
|
484 | + $msg .= '<p>'.sprintf( |
|
485 | 485 | /* translators: 1: site url, 2: table name, 3: database name */ |
486 | - __( '<strong>Could not find site %1$s.</strong> Searched for table %2$s in database %3$s. Is that right?' ), |
|
487 | - '<code>' . rtrim( $domain . $path, '/' ) . '</code>', |
|
488 | - '<code>' . $wpdb->blogs . '</code>', |
|
489 | - '<code>' . DB_NAME . '</code>' |
|
490 | - ) . '</p>'; |
|
486 | + __('<strong>Could not find site %1$s.</strong> Searched for table %2$s in database %3$s. Is that right?'), |
|
487 | + '<code>'.rtrim($domain.$path, '/').'</code>', |
|
488 | + '<code>'.$wpdb->blogs.'</code>', |
|
489 | + '<code>'.DB_NAME.'</code>' |
|
490 | + ).'</p>'; |
|
491 | 491 | } |
492 | - $msg .= '<p><strong>' . __( 'What do I do now?' ) . '</strong> '; |
|
492 | + $msg .= '<p><strong>'.__('What do I do now?').'</strong> '; |
|
493 | 493 | /* translators: %s: Codex URL */ |
494 | - $msg .= sprintf( __( 'Read the <a href="%s" target="_blank">bug report</a> page. Some of the guidelines there may help you figure out what went wrong.' ), |
|
495 | - __( 'https://codex.wordpress.org/Debugging_a_WordPress_Network' ) |
|
494 | + $msg .= sprintf(__('Read the <a href="%s" target="_blank">bug report</a> page. Some of the guidelines there may help you figure out what went wrong.'), |
|
495 | + __('https://codex.wordpress.org/Debugging_a_WordPress_Network') |
|
496 | 496 | ); |
497 | - $msg .= ' ' . __( 'If you’re still stuck with this message, then check that your database contains the following tables:' ) . '</p><ul>'; |
|
498 | - foreach ( $wpdb->tables('global') as $t => $table ) { |
|
499 | - if ( 'sitecategories' == $t ) |
|
497 | + $msg .= ' '.__('If you’re still stuck with this message, then check that your database contains the following tables:').'</p><ul>'; |
|
498 | + foreach ($wpdb->tables('global') as $t => $table) { |
|
499 | + if ('sitecategories' == $t) |
|
500 | 500 | continue; |
501 | - $msg .= '<li>' . $table . '</li>'; |
|
501 | + $msg .= '<li>'.$table.'</li>'; |
|
502 | 502 | } |
503 | 503 | $msg .= '</ul>'; |
504 | 504 | |
505 | - wp_die( $msg, $title, array( 'response' => 500 ) ); |
|
505 | + wp_die($msg, $title, array('response' => 500)); |
|
506 | 506 | } |
507 | 507 | |
508 | 508 | /** |
@@ -518,8 +518,8 @@ discard block |
||
518 | 518 | * @param object $current_site |
519 | 519 | * @return object |
520 | 520 | */ |
521 | -function get_current_site_name( $current_site ) { |
|
522 | - _deprecated_function( __FUNCTION__, '3.9.0', 'get_current_site()' ); |
|
521 | +function get_current_site_name($current_site) { |
|
522 | + _deprecated_function(__FUNCTION__, '3.9.0', 'get_current_site()'); |
|
523 | 523 | return $current_site; |
524 | 524 | } |
525 | 525 | |
@@ -539,6 +539,6 @@ discard block |
||
539 | 539 | */ |
540 | 540 | function wpmu_current_site() { |
541 | 541 | global $current_site; |
542 | - _deprecated_function( __FUNCTION__, '3.9.0' ); |
|
542 | + _deprecated_function(__FUNCTION__, '3.9.0'); |
|
543 | 543 | return $current_site; |
544 | 544 | } |
@@ -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' ) ); |
@@ -7,10 +7,10 @@ discard block |
||
7 | 7 | * @subpackage mo |
8 | 8 | */ |
9 | 9 | |
10 | -require_once dirname(__FILE__) . '/translations.php'; |
|
11 | -require_once dirname(__FILE__) . '/streams.php'; |
|
10 | +require_once dirname(__FILE__).'/translations.php'; |
|
11 | +require_once dirname(__FILE__).'/streams.php'; |
|
12 | 12 | |
13 | -if ( ! class_exists( 'MO', false ) ): |
|
13 | +if ( ! class_exists('MO', false)): |
|
14 | 14 | class MO extends Gettext_Translations { |
15 | 15 | |
16 | 16 | var $_nplurals = 2; |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | function import_from_file($filename) { |
24 | 24 | $reader = new POMO_FileReader($filename); |
25 | - if (!$reader->is_resource()) |
|
25 | + if ( ! $reader->is_resource()) |
|
26 | 26 | return false; |
27 | 27 | return $this->import_from_reader($reader); |
28 | 28 | } |
@@ -33,8 +33,8 @@ discard block |
||
33 | 33 | */ |
34 | 34 | function export_to_file($filename) { |
35 | 35 | $fh = fopen($filename, 'wb'); |
36 | - if ( !$fh ) return false; |
|
37 | - $res = $this->export_to_file_handle( $fh ); |
|
36 | + if ( ! $fh) return false; |
|
37 | + $res = $this->export_to_file_handle($fh); |
|
38 | 38 | fclose($fh); |
39 | 39 | return $res; |
40 | 40 | } |
@@ -44,22 +44,22 @@ discard block |
||
44 | 44 | */ |
45 | 45 | function export() { |
46 | 46 | $tmp_fh = fopen("php://temp", 'r+'); |
47 | - if ( !$tmp_fh ) return false; |
|
48 | - $this->export_to_file_handle( $tmp_fh ); |
|
49 | - rewind( $tmp_fh ); |
|
50 | - return stream_get_contents( $tmp_fh ); |
|
47 | + if ( ! $tmp_fh) return false; |
|
48 | + $this->export_to_file_handle($tmp_fh); |
|
49 | + rewind($tmp_fh); |
|
50 | + return stream_get_contents($tmp_fh); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | 54 | * @param Translation_Entry $entry |
55 | 55 | * @return bool |
56 | 56 | */ |
57 | - function is_entry_good_for_export( $entry ) { |
|
58 | - if ( empty( $entry->translations ) ) { |
|
57 | + function is_entry_good_for_export($entry) { |
|
58 | + if (empty($entry->translations)) { |
|
59 | 59 | return false; |
60 | 60 | } |
61 | 61 | |
62 | - if ( !array_filter( $entry->translations ) ) { |
|
62 | + if ( ! array_filter($entry->translations)) { |
|
63 | 63 | return false; |
64 | 64 | } |
65 | 65 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @return true |
72 | 72 | */ |
73 | 73 | function export_to_file_handle($fh) { |
74 | - $entries = array_filter( $this->entries, array( $this, 'is_entry_good_for_export' ) ); |
|
74 | + $entries = array_filter($this->entries, array($this, 'is_entry_good_for_export')); |
|
75 | 75 | ksort($entries); |
76 | 76 | $magic = 0x950412de; |
77 | 77 | $revision = 0; |
@@ -92,8 +92,8 @@ discard block |
||
92 | 92 | |
93 | 93 | $reader = new POMO_Reader(); |
94 | 94 | |
95 | - foreach($entries as $entry) { |
|
96 | - $originals_table .= $this->export_original($entry) . chr(0); |
|
95 | + foreach ($entries as $entry) { |
|
96 | + $originals_table .= $this->export_original($entry).chr(0); |
|
97 | 97 | $length = $reader->strlen($this->export_original($entry)); |
98 | 98 | fwrite($fh, pack('VV', $length, $current_addr)); |
99 | 99 | $current_addr += $length + 1; // account for the NULL byte after |
@@ -102,10 +102,10 @@ discard block |
||
102 | 102 | $exported_headers = $this->export_headers(); |
103 | 103 | fwrite($fh, pack('VV', $reader->strlen($exported_headers), $current_addr)); |
104 | 104 | $current_addr += strlen($exported_headers) + 1; |
105 | - $translations_table = $exported_headers . chr(0); |
|
105 | + $translations_table = $exported_headers.chr(0); |
|
106 | 106 | |
107 | - foreach($entries as $entry) { |
|
108 | - $translations_table .= $this->export_translations($entry) . chr(0); |
|
107 | + foreach ($entries as $entry) { |
|
108 | + $translations_table .= $this->export_translations($entry).chr(0); |
|
109 | 109 | $length = $reader->strlen($this->export_translations($entry)); |
110 | 110 | fwrite($fh, pack('VV', $length, $current_addr)); |
111 | 111 | $current_addr += $length + 1; |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | //TODO: warnings for control characters |
125 | 125 | $exported = $entry->singular; |
126 | 126 | if ($entry->is_plural) $exported .= chr(0).$entry->plural; |
127 | - if ($entry->context) $exported = $entry->context . chr(4) . $exported; |
|
127 | + if ($entry->context) $exported = $entry->context.chr(4).$exported; |
|
128 | 128 | return $exported; |
129 | 129 | } |
130 | 130 | |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | */ |
143 | 143 | function export_headers() { |
144 | 144 | $exported = ''; |
145 | - foreach($this->headers as $header => $value) { |
|
146 | - $exported.= "$header: $value\n"; |
|
145 | + foreach ($this->headers as $header => $value) { |
|
146 | + $exported .= "$header: $value\n"; |
|
147 | 147 | } |
148 | 148 | return $exported; |
149 | 149 | } |
@@ -156,10 +156,10 @@ discard block |
||
156 | 156 | // The magic is 0x950412de |
157 | 157 | |
158 | 158 | // bug in PHP 5.0.2, see https://savannah.nongnu.org/bugs/?func=detailitem&item_id=10565 |
159 | - $magic_little = (int) - 1794895138; |
|
159 | + $magic_little = (int) -1794895138; |
|
160 | 160 | $magic_little_64 = (int) 2500072158; |
161 | 161 | // 0xde120495 |
162 | - $magic_big = ((int) - 569244523) & 0xFFFFFFFF; |
|
162 | + $magic_big = ((int) -569244523) & 0xFFFFFFFF; |
|
163 | 163 | if ($magic_little == $magic || $magic_little_64 == $magic) { |
164 | 164 | return 'little'; |
165 | 165 | } else if ($magic_big == $magic) { |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | } |
180 | 180 | $reader->setEndian($endian_string); |
181 | 181 | |
182 | - $endian = ('big' == $endian_string)? 'N' : 'V'; |
|
182 | + $endian = ('big' == $endian_string) ? 'N' : 'V'; |
|
183 | 183 | |
184 | 184 | $header = $reader->read(24); |
185 | 185 | if ($reader->strlen($header) != 24) |
@@ -187,42 +187,42 @@ discard block |
||
187 | 187 | |
188 | 188 | // parse header |
189 | 189 | $header = unpack("{$endian}revision/{$endian}total/{$endian}originals_lenghts_addr/{$endian}translations_lenghts_addr/{$endian}hash_length/{$endian}hash_addr", $header); |
190 | - if (!is_array($header)) |
|
190 | + if ( ! is_array($header)) |
|
191 | 191 | return false; |
192 | 192 | |
193 | 193 | // support revision 0 of MO format specs, only |
194 | - if ( $header['revision'] != 0 ) { |
|
194 | + if ($header['revision'] != 0) { |
|
195 | 195 | return false; |
196 | 196 | } |
197 | 197 | |
198 | 198 | // seek to data blocks |
199 | - $reader->seekto( $header['originals_lenghts_addr'] ); |
|
199 | + $reader->seekto($header['originals_lenghts_addr']); |
|
200 | 200 | |
201 | 201 | // read originals' indices |
202 | 202 | $originals_lengths_length = $header['translations_lenghts_addr'] - $header['originals_lenghts_addr']; |
203 | - if ( $originals_lengths_length != $header['total'] * 8 ) { |
|
203 | + if ($originals_lengths_length != $header['total'] * 8) { |
|
204 | 204 | return false; |
205 | 205 | } |
206 | 206 | |
207 | 207 | $originals = $reader->read($originals_lengths_length); |
208 | - if ( $reader->strlen( $originals ) != $originals_lengths_length ) { |
|
208 | + if ($reader->strlen($originals) != $originals_lengths_length) { |
|
209 | 209 | return false; |
210 | 210 | } |
211 | 211 | |
212 | 212 | // read translations' indices |
213 | 213 | $translations_lenghts_length = $header['hash_addr'] - $header['translations_lenghts_addr']; |
214 | - if ( $translations_lenghts_length != $header['total'] * 8 ) { |
|
214 | + if ($translations_lenghts_length != $header['total'] * 8) { |
|
215 | 215 | return false; |
216 | 216 | } |
217 | 217 | |
218 | 218 | $translations = $reader->read($translations_lenghts_length); |
219 | - if ( $reader->strlen( $translations ) != $translations_lenghts_length ) { |
|
219 | + if ($reader->strlen($translations) != $translations_lenghts_length) { |
|
220 | 220 | return false; |
221 | 221 | } |
222 | 222 | |
223 | 223 | // transform raw data into set of indices |
224 | - $originals = $reader->str_split( $originals, 8 ); |
|
225 | - $translations = $reader->str_split( $translations, 8 ); |
|
224 | + $originals = $reader->str_split($originals, 8); |
|
225 | + $translations = $reader->str_split($translations, 8); |
|
226 | 226 | |
227 | 227 | // skip hash table |
228 | 228 | $strings_addr = $header['hash_addr'] + $header['hash_length'] * 4; |
@@ -232,17 +232,17 @@ discard block |
||
232 | 232 | $strings = $reader->read_all(); |
233 | 233 | $reader->close(); |
234 | 234 | |
235 | - for ( $i = 0; $i < $header['total']; $i++ ) { |
|
236 | - $o = unpack( "{$endian}length/{$endian}pos", $originals[$i] ); |
|
237 | - $t = unpack( "{$endian}length/{$endian}pos", $translations[$i] ); |
|
238 | - if ( !$o || !$t ) return false; |
|
235 | + for ($i = 0; $i < $header['total']; $i++) { |
|
236 | + $o = unpack("{$endian}length/{$endian}pos", $originals[$i]); |
|
237 | + $t = unpack("{$endian}length/{$endian}pos", $translations[$i]); |
|
238 | + if ( ! $o || ! $t) return false; |
|
239 | 239 | |
240 | 240 | // adjust offset due to reading strings to separate space before |
241 | 241 | $o['pos'] -= $strings_addr; |
242 | 242 | $t['pos'] -= $strings_addr; |
243 | 243 | |
244 | - $original = $reader->substr( $strings, $o['pos'], $o['length'] ); |
|
245 | - $translation = $reader->substr( $strings, $t['pos'], $t['length'] ); |
|
244 | + $original = $reader->substr($strings, $o['pos'], $o['length']); |
|
245 | + $translation = $reader->substr($strings, $t['pos'], $t['length']); |
|
246 | 246 | |
247 | 247 | if ('' === $original) { |
248 | 248 | $this->set_headers($this->make_headers($translation)); |
@@ -22,8 +22,9 @@ discard block |
||
22 | 22 | */ |
23 | 23 | function import_from_file($filename) { |
24 | 24 | $reader = new POMO_FileReader($filename); |
25 | - if (!$reader->is_resource()) |
|
26 | - return false; |
|
25 | + if (!$reader->is_resource()) { |
|
26 | + return false; |
|
27 | + } |
|
27 | 28 | return $this->import_from_reader($reader); |
28 | 29 | } |
29 | 30 | |
@@ -33,7 +34,9 @@ discard block |
||
33 | 34 | */ |
34 | 35 | function export_to_file($filename) { |
35 | 36 | $fh = fopen($filename, 'wb'); |
36 | - if ( !$fh ) return false; |
|
37 | + if ( !$fh ) { |
|
38 | + return false; |
|
39 | + } |
|
37 | 40 | $res = $this->export_to_file_handle( $fh ); |
38 | 41 | fclose($fh); |
39 | 42 | return $res; |
@@ -44,7 +47,9 @@ discard block |
||
44 | 47 | */ |
45 | 48 | function export() { |
46 | 49 | $tmp_fh = fopen("php://temp", 'r+'); |
47 | - if ( !$tmp_fh ) return false; |
|
50 | + if ( !$tmp_fh ) { |
|
51 | + return false; |
|
52 | + } |
|
48 | 53 | $this->export_to_file_handle( $tmp_fh ); |
49 | 54 | rewind( $tmp_fh ); |
50 | 55 | return stream_get_contents( $tmp_fh ); |
@@ -123,8 +128,12 @@ discard block |
||
123 | 128 | function export_original($entry) { |
124 | 129 | //TODO: warnings for control characters |
125 | 130 | $exported = $entry->singular; |
126 | - if ($entry->is_plural) $exported .= chr(0).$entry->plural; |
|
127 | - if ($entry->context) $exported = $entry->context . chr(4) . $exported; |
|
131 | + if ($entry->is_plural) { |
|
132 | + $exported .= chr(0).$entry->plural; |
|
133 | + } |
|
134 | + if ($entry->context) { |
|
135 | + $exported = $entry->context . chr(4) . $exported; |
|
136 | + } |
|
128 | 137 | return $exported; |
129 | 138 | } |
130 | 139 | |
@@ -182,13 +191,15 @@ discard block |
||
182 | 191 | $endian = ('big' == $endian_string)? 'N' : 'V'; |
183 | 192 | |
184 | 193 | $header = $reader->read(24); |
185 | - if ($reader->strlen($header) != 24) |
|
186 | - return false; |
|
194 | + if ($reader->strlen($header) != 24) { |
|
195 | + return false; |
|
196 | + } |
|
187 | 197 | |
188 | 198 | // parse header |
189 | 199 | $header = unpack("{$endian}revision/{$endian}total/{$endian}originals_lenghts_addr/{$endian}translations_lenghts_addr/{$endian}hash_length/{$endian}hash_addr", $header); |
190 | - if (!is_array($header)) |
|
191 | - return false; |
|
200 | + if (!is_array($header)) { |
|
201 | + return false; |
|
202 | + } |
|
192 | 203 | |
193 | 204 | // support revision 0 of MO format specs, only |
194 | 205 | if ( $header['revision'] != 0 ) { |
@@ -235,7 +246,9 @@ discard block |
||
235 | 246 | for ( $i = 0; $i < $header['total']; $i++ ) { |
236 | 247 | $o = unpack( "{$endian}length/{$endian}pos", $originals[$i] ); |
237 | 248 | $t = unpack( "{$endian}length/{$endian}pos", $translations[$i] ); |
238 | - if ( !$o || !$t ) return false; |
|
249 | + if ( !$o || !$t ) { |
|
250 | + return false; |
|
251 | + } |
|
239 | 252 | |
240 | 253 | // adjust offset due to reading strings to separate space before |
241 | 254 | $o['pos'] -= $strings_addr; |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * Sets the endianness of the file. |
34 | 34 | * |
35 | - * @param $endian string 'big' or 'little' |
|
35 | + * @param string $endian string 'big' or 'little' |
|
36 | 36 | */ |
37 | 37 | function setEndian($endian) { |
38 | 38 | $this->endian = $endian; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | /** |
42 | 42 | * Reads a 32bit Integer from the Stream |
43 | 43 | * |
44 | - * @return mixed The integer, corresponding to the next 32 bits from |
|
44 | + * @return integer The integer, corresponding to the next 32 bits from |
|
45 | 45 | * the stream of false if there are not enough bytes or on error |
46 | 46 | */ |
47 | 47 | function readint32() { |
@@ -119,14 +119,14 @@ discard block |
||
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
122 | - * @return true |
|
122 | + * @return boolean |
|
123 | 123 | */ |
124 | 124 | function is_resource() { |
125 | 125 | return true; |
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
129 | - * @return true |
|
129 | + * @return boolean |
|
130 | 130 | */ |
131 | 131 | function close() { |
132 | 132 | return true; |
@@ -46,8 +46,9 @@ discard block |
||
46 | 46 | */ |
47 | 47 | function readint32() { |
48 | 48 | $bytes = $this->read(4); |
49 | - if (4 != $this->strlen($bytes)) |
|
50 | - return false; |
|
49 | + if (4 != $this->strlen($bytes)) { |
|
50 | + return false; |
|
51 | + } |
|
51 | 52 | $endian_letter = ('big' == $this->endian)? 'N' : 'V'; |
52 | 53 | $int = unpack($endian_letter, $bytes); |
53 | 54 | return reset( $int ); |
@@ -62,8 +63,9 @@ discard block |
||
62 | 63 | */ |
63 | 64 | function readint32array($count) { |
64 | 65 | $bytes = $this->read(4 * $count); |
65 | - if (4*$count != $this->strlen($bytes)) |
|
66 | - return false; |
|
66 | + if (4*$count != $this->strlen($bytes)) { |
|
67 | + return false; |
|
68 | + } |
|
67 | 69 | $endian_letter = ('big' == $this->endian)? 'N' : 'V'; |
68 | 70 | return unpack($endian_letter.$count, $bytes); |
69 | 71 | } |
@@ -103,8 +105,9 @@ discard block |
||
103 | 105 | if (!function_exists('str_split')) { |
104 | 106 | $length = $this->strlen($string); |
105 | 107 | $out = array(); |
106 | - for ($i = 0; $i < $length; $i += $chunk_size) |
|
107 | - $out[] = $this->substr($string, $i, $chunk_size); |
|
108 | + for ($i = 0; $i < $length; $i += $chunk_size) { |
|
109 | + $out[] = $this->substr($string, $i, $chunk_size); |
|
110 | + } |
|
108 | 111 | return $out; |
109 | 112 | } else { |
110 | 113 | return str_split( $string, $chunk_size ); |
@@ -197,8 +200,9 @@ discard block |
||
197 | 200 | */ |
198 | 201 | function read_all() { |
199 | 202 | $all = ''; |
200 | - while ( !$this->feof() ) |
|
201 | - $all .= $this->read(4096); |
|
203 | + while ( !$this->feof() ) { |
|
204 | + $all .= $this->read(4096); |
|
205 | + } |
|
202 | 206 | return $all; |
203 | 207 | } |
204 | 208 | } |
@@ -236,7 +240,9 @@ discard block |
||
236 | 240 | function read($bytes) { |
237 | 241 | $data = $this->substr($this->_str, $this->_pos, $bytes); |
238 | 242 | $this->_pos += $bytes; |
239 | - if ($this->strlen($this->_str) < $this->_pos) $this->_pos = $this->strlen($this->_str); |
|
243 | + if ($this->strlen($this->_str) < $this->_pos) { |
|
244 | + $this->_pos = $this->strlen($this->_str); |
|
245 | + } |
|
240 | 246 | return $data; |
241 | 247 | } |
242 | 248 | |
@@ -246,7 +252,9 @@ discard block |
||
246 | 252 | */ |
247 | 253 | function seekto($pos) { |
248 | 254 | $this->_pos = $pos; |
249 | - if ($this->strlen($this->_str) < $this->_pos) $this->_pos = $this->strlen($this->_str); |
|
255 | + if ($this->strlen($this->_str) < $this->_pos) { |
|
256 | + $this->_pos = $this->strlen($this->_str); |
|
257 | + } |
|
250 | 258 | return $this->_pos; |
251 | 259 | } |
252 | 260 | |
@@ -278,8 +286,9 @@ discard block |
||
278 | 286 | function __construct( $filename ) { |
279 | 287 | parent::POMO_StringReader(); |
280 | 288 | $this->_str = file_get_contents($filename); |
281 | - if (false === $this->_str) |
|
282 | - return false; |
|
289 | + if (false === $this->_str) { |
|
290 | + return false; |
|
291 | + } |
|
283 | 292 | $this->_pos = 0; |
284 | 293 | } |
285 | 294 |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @subpackage streams |
9 | 9 | */ |
10 | 10 | |
11 | -if ( ! class_exists( 'POMO_Reader', false ) ): |
|
11 | +if ( ! class_exists('POMO_Reader', false)): |
|
12 | 12 | class POMO_Reader { |
13 | 13 | |
14 | 14 | var $endian = 'little'; |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | $bytes = $this->read(4); |
49 | 49 | if (4 != $this->strlen($bytes)) |
50 | 50 | return false; |
51 | - $endian_letter = ('big' == $this->endian)? 'N' : 'V'; |
|
51 | + $endian_letter = ('big' == $this->endian) ? 'N' : 'V'; |
|
52 | 52 | $int = unpack($endian_letter, $bytes); |
53 | - return reset( $int ); |
|
53 | + return reset($int); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | /** |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | */ |
63 | 63 | function readint32array($count) { |
64 | 64 | $bytes = $this->read(4 * $count); |
65 | - if (4*$count != $this->strlen($bytes)) |
|
65 | + if (4 * $count != $this->strlen($bytes)) |
|
66 | 66 | return false; |
67 | - $endian_letter = ('big' == $this->endian)? 'N' : 'V'; |
|
67 | + $endian_letter = ('big' == $this->endian) ? 'N' : 'V'; |
|
68 | 68 | return unpack($endian_letter.$count, $bytes); |
69 | 69 | } |
70 | 70 | |
@@ -100,14 +100,14 @@ discard block |
||
100 | 100 | * @return array |
101 | 101 | */ |
102 | 102 | function str_split($string, $chunk_size) { |
103 | - if (!function_exists('str_split')) { |
|
103 | + if ( ! function_exists('str_split')) { |
|
104 | 104 | $length = $this->strlen($string); |
105 | 105 | $out = array(); |
106 | 106 | for ($i = 0; $i < $length; $i += $chunk_size) |
107 | 107 | $out[] = $this->substr($string, $i, $chunk_size); |
108 | 108 | return $out; |
109 | 109 | } else { |
110 | - return str_split( $string, $chunk_size ); |
|
110 | + return str_split($string, $chunk_size); |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
@@ -134,13 +134,13 @@ discard block |
||
134 | 134 | } |
135 | 135 | endif; |
136 | 136 | |
137 | -if ( ! class_exists( 'POMO_FileReader', false ) ): |
|
137 | +if ( ! class_exists('POMO_FileReader', false)): |
|
138 | 138 | class POMO_FileReader extends POMO_Reader { |
139 | 139 | |
140 | 140 | /** |
141 | 141 | * @param string $filename |
142 | 142 | */ |
143 | - function __construct( $filename ) { |
|
143 | + function __construct($filename) { |
|
144 | 144 | parent::POMO_Reader(); |
145 | 145 | $this->_f = fopen($filename, 'rb'); |
146 | 146 | } |
@@ -148,8 +148,8 @@ discard block |
||
148 | 148 | /** |
149 | 149 | * PHP4 constructor. |
150 | 150 | */ |
151 | - public function POMO_FileReader( $filename ) { |
|
152 | - self::__construct( $filename ); |
|
151 | + public function POMO_FileReader($filename) { |
|
152 | + self::__construct($filename); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -197,14 +197,14 @@ discard block |
||
197 | 197 | */ |
198 | 198 | function read_all() { |
199 | 199 | $all = ''; |
200 | - while ( !$this->feof() ) |
|
200 | + while ( ! $this->feof()) |
|
201 | 201 | $all .= $this->read(4096); |
202 | 202 | return $all; |
203 | 203 | } |
204 | 204 | } |
205 | 205 | endif; |
206 | 206 | |
207 | -if ( ! class_exists( 'POMO_StringReader', false ) ): |
|
207 | +if ( ! class_exists('POMO_StringReader', false)): |
|
208 | 208 | /** |
209 | 209 | * Provides file-like methods for manipulating a string instead |
210 | 210 | * of a physical file. |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | /** |
217 | 217 | * PHP5 constructor. |
218 | 218 | */ |
219 | - function __construct( $str = '' ) { |
|
219 | + function __construct($str = '') { |
|
220 | 220 | parent::POMO_Reader(); |
221 | 221 | $this->_str = $str; |
222 | 222 | $this->_pos = 0; |
@@ -225,8 +225,8 @@ discard block |
||
225 | 225 | /** |
226 | 226 | * PHP4 constructor. |
227 | 227 | */ |
228 | - public function POMO_StringReader( $str = '' ) { |
|
229 | - self::__construct( $str ); |
|
228 | + public function POMO_StringReader($str = '') { |
|
229 | + self::__construct($str); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | /** |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | } |
268 | 268 | endif; |
269 | 269 | |
270 | -if ( ! class_exists( 'POMO_CachedFileReader', false ) ): |
|
270 | +if ( ! class_exists('POMO_CachedFileReader', false)): |
|
271 | 271 | /** |
272 | 272 | * Reads the contents of the file in the beginning. |
273 | 273 | */ |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | /** |
276 | 276 | * PHP5 constructor. |
277 | 277 | */ |
278 | - function __construct( $filename ) { |
|
278 | + function __construct($filename) { |
|
279 | 279 | parent::POMO_StringReader(); |
280 | 280 | $this->_str = file_get_contents($filename); |
281 | 281 | if (false === $this->_str) |
@@ -286,13 +286,13 @@ discard block |
||
286 | 286 | /** |
287 | 287 | * PHP4 constructor. |
288 | 288 | */ |
289 | - public function POMO_CachedFileReader( $filename ) { |
|
290 | - self::__construct( $filename ); |
|
289 | + public function POMO_CachedFileReader($filename) { |
|
290 | + self::__construct($filename); |
|
291 | 291 | } |
292 | 292 | } |
293 | 293 | endif; |
294 | 294 | |
295 | -if ( ! class_exists( 'POMO_CachedIntFileReader', false ) ): |
|
295 | +if ( ! class_exists('POMO_CachedIntFileReader', false)): |
|
296 | 296 | /** |
297 | 297 | * Reads the contents of the file in the beginning. |
298 | 298 | */ |
@@ -300,15 +300,15 @@ discard block |
||
300 | 300 | /** |
301 | 301 | * PHP5 constructor. |
302 | 302 | */ |
303 | - public function __construct( $filename ) { |
|
303 | + public function __construct($filename) { |
|
304 | 304 | parent::POMO_CachedFileReader($filename); |
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
308 | 308 | * PHP4 constructor. |
309 | 309 | */ |
310 | - function POMO_CachedIntFileReader( $filename ) { |
|
311 | - self::__construct( $filename ); |
|
310 | + function POMO_CachedIntFileReader($filename) { |
|
311 | + self::__construct($filename); |
|
312 | 312 | } |
313 | 313 | } |
314 | 314 | endif; |
@@ -18,6 +18,7 @@ discard block |
||
18 | 18 | * Add entry to the PO structure |
19 | 19 | * |
20 | 20 | * @param array|Translation_Entry &$entry |
21 | + * @param Translation_Entry $entry |
|
21 | 22 | * @return bool true on success, false if the entry doesn't have a key |
22 | 23 | */ |
23 | 24 | function add_entry($entry) { |
@@ -72,6 +73,7 @@ discard block |
||
72 | 73 | |
73 | 74 | /** |
74 | 75 | * @param string $header |
76 | + * @return string |
|
75 | 77 | */ |
76 | 78 | function get_header($header) { |
77 | 79 | return isset($this->headers[$header])? $this->headers[$header] : false; |
@@ -150,7 +152,7 @@ discard block |
||
150 | 152 | } |
151 | 153 | |
152 | 154 | /** |
153 | - * @param object $other |
|
155 | + * @param Translations $other |
|
154 | 156 | */ |
155 | 157 | function merge_originals_with(&$other) { |
156 | 158 | foreach( $other->entries as $entry ) { |
@@ -326,7 +328,7 @@ discard block |
||
326 | 328 | /** |
327 | 329 | * |
328 | 330 | * @param int $count |
329 | - * @return bool |
|
331 | + * @return integer |
|
330 | 332 | */ |
331 | 333 | function select_plural_form($count) { |
332 | 334 | return 1 == $count? 0 : 1; |
@@ -25,7 +25,9 @@ discard block |
||
25 | 25 | $entry = new Translation_Entry($entry); |
26 | 26 | } |
27 | 27 | $key = $entry->key(); |
28 | - if (false === $key) return false; |
|
28 | + if (false === $key) { |
|
29 | + return false; |
|
30 | + } |
|
29 | 31 | $this->entries[$key] = &$entry; |
30 | 32 | return true; |
31 | 33 | } |
@@ -39,11 +41,14 @@ discard block |
||
39 | 41 | $entry = new Translation_Entry($entry); |
40 | 42 | } |
41 | 43 | $key = $entry->key(); |
42 | - if (false === $key) return false; |
|
43 | - if (isset($this->entries[$key])) |
|
44 | - $this->entries[$key]->merge_with($entry); |
|
45 | - else |
|
46 | - $this->entries[$key] = &$entry; |
|
44 | + if (false === $key) { |
|
45 | + return false; |
|
46 | + } |
|
47 | + if (isset($this->entries[$key])) { |
|
48 | + $this->entries[$key]->merge_with($entry); |
|
49 | + } else { |
|
50 | + $this->entries[$key] = &$entry; |
|
51 | + } |
|
47 | 52 | return true; |
48 | 53 | } |
49 | 54 | |
@@ -131,10 +136,11 @@ discard block |
||
131 | 136 | $total_plural_forms = $this->get_plural_forms_count(); |
132 | 137 | if ($translated && 0 <= $index && $index < $total_plural_forms && |
133 | 138 | is_array($translated->translations) && |
134 | - isset($translated->translations[$index])) |
|
135 | - return $translated->translations[$index]; |
|
136 | - else |
|
137 | - return 1 == $count? $singular : $plural; |
|
139 | + isset($translated->translations[$index])) { |
|
140 | + return $translated->translations[$index]; |
|
141 | + } else { |
|
142 | + return 1 == $count? $singular : $plural; |
|
143 | + } |
|
138 | 144 | } |
139 | 145 | |
140 | 146 | /** |
@@ -154,10 +160,11 @@ discard block |
||
154 | 160 | */ |
155 | 161 | function merge_originals_with(&$other) { |
156 | 162 | foreach( $other->entries as $entry ) { |
157 | - if ( !isset( $this->entries[$entry->key()] ) ) |
|
158 | - $this->entries[$entry->key()] = $entry; |
|
159 | - else |
|
160 | - $this->entries[$entry->key()]->merge_with($entry); |
|
163 | + if ( !isset( $this->entries[$entry->key()] ) ) { |
|
164 | + $this->entries[$entry->key()] = $entry; |
|
165 | + } else { |
|
166 | + $this->entries[$entry->key()]->merge_with($entry); |
|
167 | + } |
|
161 | 168 | } |
162 | 169 | } |
163 | 170 | } |
@@ -251,7 +258,9 @@ discard block |
||
251 | 258 | $lines = explode("\n", $translation); |
252 | 259 | foreach($lines as $line) { |
253 | 260 | $parts = explode(':', $line, 2); |
254 | - if (!isset($parts[1])) continue; |
|
261 | + if (!isset($parts[1])) { |
|
262 | + continue; |
|
263 | + } |
|
255 | 264 | $headers[trim($parts[0])] = trim($parts[1]); |
256 | 265 | } |
257 | 266 | return $headers; |
@@ -7,9 +7,9 @@ discard block |
||
7 | 7 | * @subpackage translations |
8 | 8 | */ |
9 | 9 | |
10 | -require_once dirname(__FILE__) . '/entry.php'; |
|
10 | +require_once dirname(__FILE__).'/entry.php'; |
|
11 | 11 | |
12 | -if ( ! class_exists( 'Translations', false ) ): |
|
12 | +if ( ! class_exists('Translations', false)): |
|
13 | 13 | class Translations { |
14 | 14 | var $entries = array(); |
15 | 15 | var $headers = array(); |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @param array $headers |
66 | 66 | */ |
67 | 67 | function set_headers($headers) { |
68 | - foreach($headers as $header => $value) { |
|
68 | + foreach ($headers as $header => $value) { |
|
69 | 69 | $this->set_header($header, $value); |
70 | 70 | } |
71 | 71 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * @param string $header |
75 | 75 | */ |
76 | 76 | function get_header($header) { |
77 | - return isset($this->headers[$header])? $this->headers[$header] : false; |
|
77 | + return isset($this->headers[$header]) ? $this->headers[$header] : false; |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | function translate_entry(&$entry) { |
84 | 84 | $key = $entry->key(); |
85 | - return isset($this->entries[$key])? $this->entries[$key] : false; |
|
85 | + return isset($this->entries[$key]) ? $this->entries[$key] : false; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | * @param string $context |
91 | 91 | * @return string |
92 | 92 | */ |
93 | - function translate($singular, $context=null) { |
|
93 | + function translate($singular, $context = null) { |
|
94 | 94 | $entry = new Translation_Entry(array('singular' => $singular, 'context' => $context)); |
95 | 95 | $translated = $this->translate_entry($entry); |
96 | - return ($translated && !empty($translated->translations))? $translated->translations[0] : $singular; |
|
96 | + return ($translated && ! empty($translated->translations)) ? $translated->translations[0] : $singular; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @param integer $count number of items |
109 | 109 | */ |
110 | 110 | function select_plural_form($count) { |
111 | - return 1 == $count? 0 : 1; |
|
111 | + return 1 == $count ? 0 : 1; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | isset($translated->translations[$index])) |
135 | 135 | return $translated->translations[$index]; |
136 | 136 | else |
137 | - return 1 == $count? $singular : $plural; |
|
137 | + return 1 == $count ? $singular : $plural; |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @return void |
145 | 145 | **/ |
146 | 146 | function merge_with(&$other) { |
147 | - foreach( $other->entries as $entry ) { |
|
147 | + foreach ($other->entries as $entry) { |
|
148 | 148 | $this->entries[$entry->key()] = $entry; |
149 | 149 | } |
150 | 150 | } |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | * @param object $other |
154 | 154 | */ |
155 | 155 | function merge_originals_with(&$other) { |
156 | - foreach( $other->entries as $entry ) { |
|
157 | - if ( !isset( $this->entries[$entry->key()] ) ) |
|
156 | + foreach ($other->entries as $entry) { |
|
157 | + if ( ! isset($this->entries[$entry->key()])) |
|
158 | 158 | $this->entries[$entry->key()] = $entry; |
159 | 159 | else |
160 | 160 | $this->entries[$entry->key()]->merge_with($entry); |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | * @param int $count |
173 | 173 | */ |
174 | 174 | function gettext_select_plural_form($count) { |
175 | - if (!isset($this->_gettext_select_plural_form) || is_null($this->_gettext_select_plural_form)) { |
|
176 | - list( $nplurals, $expression ) = $this->nplurals_and_expression_from_header($this->get_header('Plural-Forms')); |
|
175 | + if ( ! isset($this->_gettext_select_plural_form) || is_null($this->_gettext_select_plural_form)) { |
|
176 | + list($nplurals, $expression) = $this->nplurals_and_expression_from_header($this->get_header('Plural-Forms')); |
|
177 | 177 | $this->_nplurals = $nplurals; |
178 | 178 | $this->_gettext_select_plural_form = $this->make_plural_form_function($nplurals, $expression); |
179 | 179 | } |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | function nplurals_and_expression_from_header($header) { |
188 | 188 | if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches)) { |
189 | - $nplurals = (int)$matches[1]; |
|
189 | + $nplurals = (int) $matches[1]; |
|
190 | 190 | $expression = trim($this->parenthesize_plural_exression($matches[2])); |
191 | 191 | return array($nplurals, $expression); |
192 | 192 | } else { |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | $res .= ') : ('; |
231 | 231 | break; |
232 | 232 | case ';': |
233 | - $res .= str_repeat(')', $depth) . ';'; |
|
234 | - $depth= 0; |
|
233 | + $res .= str_repeat(')', $depth).';'; |
|
234 | + $depth = 0; |
|
235 | 235 | break; |
236 | 236 | default: |
237 | 237 | $res .= $char; |
@@ -249,9 +249,9 @@ discard block |
||
249 | 249 | // sometimes \ns are used instead of real new lines |
250 | 250 | $translation = str_replace('\n', "\n", $translation); |
251 | 251 | $lines = explode("\n", $translation); |
252 | - foreach($lines as $line) { |
|
252 | + foreach ($lines as $line) { |
|
253 | 253 | $parts = explode(':', $line, 2); |
254 | - if (!isset($parts[1])) continue; |
|
254 | + if ( ! isset($parts[1])) continue; |
|
255 | 255 | $headers[trim($parts[0])] = trim($parts[1]); |
256 | 256 | } |
257 | 257 | return $headers; |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | function set_header($header, $value) { |
265 | 265 | parent::set_header($header, $value); |
266 | 266 | if ('Plural-Forms' == $header) { |
267 | - list( $nplurals, $expression ) = $this->nplurals_and_expression_from_header($this->get_header('Plural-Forms')); |
|
267 | + list($nplurals, $expression) = $this->nplurals_and_expression_from_header($this->get_header('Plural-Forms')); |
|
268 | 268 | $this->_nplurals = $nplurals; |
269 | 269 | $this->_gettext_select_plural_form = $this->make_plural_form_function($nplurals, $expression); |
270 | 270 | } |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | } |
273 | 273 | endif; |
274 | 274 | |
275 | -if ( ! class_exists( 'NOOP_Translations', false ) ): |
|
275 | +if ( ! class_exists('NOOP_Translations', false)): |
|
276 | 276 | /** |
277 | 277 | * Provides the same interface as Translations, but doesn't do anything |
278 | 278 | */ |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * @param string $singular |
320 | 320 | * @param string $context |
321 | 321 | */ |
322 | - function translate($singular, $context=null) { |
|
322 | + function translate($singular, $context = null) { |
|
323 | 323 | return $singular; |
324 | 324 | } |
325 | 325 | |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | * @return bool |
330 | 330 | */ |
331 | 331 | function select_plural_form($count) { |
332 | - return 1 == $count? 0 : 1; |
|
332 | + return 1 == $count ? 0 : 1; |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | * @param string $context |
347 | 347 | */ |
348 | 348 | function translate_plural($singular, $plural, $count, $context = null) { |
349 | - return 1 == $count? $singular : $plural; |
|
349 | + return 1 == $count ? $singular : $plural; |
|
350 | 350 | } |
351 | 351 | |
352 | 352 | /** |
@@ -135,7 +135,7 @@ |
||
135 | 135 | * @since 3.1.0 |
136 | 136 | * |
137 | 137 | * @param string $format The post format slug. |
138 | - * @return string|WP_Error|false The post format term link. |
|
138 | + * @return string The post format term link. |
|
139 | 139 | */ |
140 | 140 | function get_post_format_link( $format ) { |
141 | 141 | $term = get_term_by('slug', 'post-format-' . $format, 'post_format' ); |
@@ -15,16 +15,19 @@ discard block |
||
15 | 15 | * @return string|false The format if successful. False otherwise. |
16 | 16 | */ |
17 | 17 | function get_post_format( $post = null ) { |
18 | - if ( ! $post = get_post( $post ) ) |
|
19 | - return false; |
|
18 | + if ( ! $post = get_post( $post ) ) { |
|
19 | + return false; |
|
20 | + } |
|
20 | 21 | |
21 | - if ( ! post_type_supports( $post->post_type, 'post-formats' ) ) |
|
22 | - return false; |
|
22 | + if ( ! post_type_supports( $post->post_type, 'post-formats' ) ) { |
|
23 | + return false; |
|
24 | + } |
|
23 | 25 | |
24 | 26 | $_format = get_the_terms( $post->ID, 'post_format' ); |
25 | 27 | |
26 | - if ( empty( $_format ) ) |
|
27 | - return false; |
|
28 | + if ( empty( $_format ) ) { |
|
29 | + return false; |
|
30 | + } |
|
28 | 31 | |
29 | 32 | $format = reset( $_format ); |
30 | 33 | |
@@ -64,15 +67,17 @@ discard block |
||
64 | 67 | function set_post_format( $post, $format ) { |
65 | 68 | $post = get_post( $post ); |
66 | 69 | |
67 | - if ( empty( $post ) ) |
|
68 | - return new WP_Error( 'invalid_post', __( 'Invalid post.' ) ); |
|
70 | + if ( empty( $post ) ) { |
|
71 | + return new WP_Error( 'invalid_post', __( 'Invalid post.' ) ); |
|
72 | + } |
|
69 | 73 | |
70 | 74 | if ( ! empty( $format ) ) { |
71 | 75 | $format = sanitize_key( $format ); |
72 | - if ( 'standard' === $format || ! in_array( $format, get_post_format_slugs() ) ) |
|
73 | - $format = ''; |
|
74 | - else |
|
75 | - $format = 'post-format-' . $format; |
|
76 | + if ( 'standard' === $format || ! in_array( $format, get_post_format_slugs() ) ) { |
|
77 | + $format = ''; |
|
78 | + } else { |
|
79 | + $format = 'post-format-' . $format; |
|
80 | + } |
|
76 | 81 | } |
77 | 82 | |
78 | 83 | return wp_set_post_terms( $post->ID, $format, 'post_format' ); |
@@ -123,11 +128,12 @@ discard block |
||
123 | 128 | */ |
124 | 129 | function get_post_format_string( $slug ) { |
125 | 130 | $strings = get_post_format_strings(); |
126 | - if ( !$slug ) |
|
127 | - return $strings['standard']; |
|
128 | - else |
|
129 | - return ( isset( $strings[$slug] ) ) ? $strings[$slug] : ''; |
|
130 | -} |
|
131 | + if ( !$slug ) { |
|
132 | + return $strings['standard']; |
|
133 | + } else { |
|
134 | + return ( isset( $strings[$slug] ) ) ? $strings[$slug] : ''; |
|
135 | + } |
|
136 | + } |
|
131 | 137 | |
132 | 138 | /** |
133 | 139 | * Returns a link to a post format index. |
@@ -139,8 +145,9 @@ discard block |
||
139 | 145 | */ |
140 | 146 | function get_post_format_link( $format ) { |
141 | 147 | $term = get_term_by('slug', 'post-format-' . $format, 'post_format' ); |
142 | - if ( ! $term || is_wp_error( $term ) ) |
|
143 | - return false; |
|
148 | + if ( ! $term || is_wp_error( $term ) ) { |
|
149 | + return false; |
|
150 | + } |
|
144 | 151 | return get_term_link( $term ); |
145 | 152 | } |
146 | 153 | |
@@ -154,14 +161,17 @@ discard block |
||
154 | 161 | * @return array |
155 | 162 | */ |
156 | 163 | function _post_format_request( $qvs ) { |
157 | - if ( ! isset( $qvs['post_format'] ) ) |
|
158 | - return $qvs; |
|
164 | + if ( ! isset( $qvs['post_format'] ) ) { |
|
165 | + return $qvs; |
|
166 | + } |
|
159 | 167 | $slugs = get_post_format_slugs(); |
160 | - if ( isset( $slugs[ $qvs['post_format'] ] ) ) |
|
161 | - $qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ]; |
|
168 | + if ( isset( $slugs[ $qvs['post_format'] ] ) ) { |
|
169 | + $qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ]; |
|
170 | + } |
|
162 | 171 | $tax = get_taxonomy( 'post_format' ); |
163 | - if ( ! is_admin() ) |
|
164 | - $qvs['post_type'] = $tax->object_type; |
|
172 | + if ( ! is_admin() ) { |
|
173 | + $qvs['post_type'] = $tax->object_type; |
|
174 | + } |
|
165 | 175 | return $qvs; |
166 | 176 | } |
167 | 177 |
@@ -14,21 +14,21 @@ discard block |
||
14 | 14 | * @param int|object|null $post Post ID or post object. Optional, default is the current post from the loop. |
15 | 15 | * @return string|false The format if successful. False otherwise. |
16 | 16 | */ |
17 | -function get_post_format( $post = null ) { |
|
18 | - if ( ! $post = get_post( $post ) ) |
|
17 | +function get_post_format($post = null) { |
|
18 | + if ( ! $post = get_post($post)) |
|
19 | 19 | return false; |
20 | 20 | |
21 | - if ( ! post_type_supports( $post->post_type, 'post-formats' ) ) |
|
21 | + if ( ! post_type_supports($post->post_type, 'post-formats')) |
|
22 | 22 | return false; |
23 | 23 | |
24 | - $_format = get_the_terms( $post->ID, 'post_format' ); |
|
24 | + $_format = get_the_terms($post->ID, 'post_format'); |
|
25 | 25 | |
26 | - if ( empty( $_format ) ) |
|
26 | + if (empty($_format)) |
|
27 | 27 | return false; |
28 | 28 | |
29 | - $format = reset( $_format ); |
|
29 | + $format = reset($_format); |
|
30 | 30 | |
31 | - return str_replace('post-format-', '', $format->slug ); |
|
31 | + return str_replace('post-format-', '', $format->slug); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -40,16 +40,16 @@ discard block |
||
40 | 40 | * @param object|int|null $post Optional. The post to check. If not supplied, defaults to the current post if used in the loop. |
41 | 41 | * @return bool True if the post has any of the given formats (or any format, if no format specified), false otherwise. |
42 | 42 | */ |
43 | -function has_post_format( $format = array(), $post = null ) { |
|
43 | +function has_post_format($format = array(), $post = null) { |
|
44 | 44 | $prefixed = array(); |
45 | 45 | |
46 | - if ( $format ) { |
|
47 | - foreach ( (array) $format as $single ) { |
|
48 | - $prefixed[] = 'post-format-' . sanitize_key( $single ); |
|
46 | + if ($format) { |
|
47 | + foreach ((array) $format as $single) { |
|
48 | + $prefixed[] = 'post-format-'.sanitize_key($single); |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | - return has_term( $prefixed, 'post_format', $post ); |
|
52 | + return has_term($prefixed, 'post_format', $post); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
@@ -61,21 +61,21 @@ discard block |
||
61 | 61 | * @param string $format A format to assign. Use an empty string or array to remove all formats from the post. |
62 | 62 | * @return array|WP_Error|false WP_Error on error. Array of affected term IDs on success. |
63 | 63 | */ |
64 | -function set_post_format( $post, $format ) { |
|
65 | - $post = get_post( $post ); |
|
64 | +function set_post_format($post, $format) { |
|
65 | + $post = get_post($post); |
|
66 | 66 | |
67 | - if ( empty( $post ) ) |
|
68 | - return new WP_Error( 'invalid_post', __( 'Invalid post.' ) ); |
|
67 | + if (empty($post)) |
|
68 | + return new WP_Error('invalid_post', __('Invalid post.')); |
|
69 | 69 | |
70 | - if ( ! empty( $format ) ) { |
|
71 | - $format = sanitize_key( $format ); |
|
72 | - if ( 'standard' === $format || ! in_array( $format, get_post_format_slugs() ) ) |
|
70 | + if ( ! empty($format)) { |
|
71 | + $format = sanitize_key($format); |
|
72 | + if ('standard' === $format || ! in_array($format, get_post_format_slugs())) |
|
73 | 73 | $format = ''; |
74 | 74 | else |
75 | - $format = 'post-format-' . $format; |
|
75 | + $format = 'post-format-'.$format; |
|
76 | 76 | } |
77 | 77 | |
78 | - return wp_set_post_terms( $post->ID, $format, 'post_format' ); |
|
78 | + return wp_set_post_terms($post->ID, $format, 'post_format'); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -87,16 +87,16 @@ discard block |
||
87 | 87 | */ |
88 | 88 | function get_post_format_strings() { |
89 | 89 | $strings = array( |
90 | - 'standard' => _x( 'Standard', 'Post format' ), // Special case. any value that evals to false will be considered standard |
|
91 | - 'aside' => _x( 'Aside', 'Post format' ), |
|
92 | - 'chat' => _x( 'Chat', 'Post format' ), |
|
93 | - 'gallery' => _x( 'Gallery', 'Post format' ), |
|
94 | - 'link' => _x( 'Link', 'Post format' ), |
|
95 | - 'image' => _x( 'Image', 'Post format' ), |
|
96 | - 'quote' => _x( 'Quote', 'Post format' ), |
|
97 | - 'status' => _x( 'Status', 'Post format' ), |
|
98 | - 'video' => _x( 'Video', 'Post format' ), |
|
99 | - 'audio' => _x( 'Audio', 'Post format' ), |
|
90 | + 'standard' => _x('Standard', 'Post format'), // Special case. any value that evals to false will be considered standard |
|
91 | + 'aside' => _x('Aside', 'Post format'), |
|
92 | + 'chat' => _x('Chat', 'Post format'), |
|
93 | + 'gallery' => _x('Gallery', 'Post format'), |
|
94 | + 'link' => _x('Link', 'Post format'), |
|
95 | + 'image' => _x('Image', 'Post format'), |
|
96 | + 'quote' => _x('Quote', 'Post format'), |
|
97 | + 'status' => _x('Status', 'Post format'), |
|
98 | + 'video' => _x('Video', 'Post format'), |
|
99 | + 'audio' => _x('Audio', 'Post format'), |
|
100 | 100 | ); |
101 | 101 | return $strings; |
102 | 102 | } |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | * @return array The array of post format slugs. |
110 | 110 | */ |
111 | 111 | function get_post_format_slugs() { |
112 | - $slugs = array_keys( get_post_format_strings() ); |
|
113 | - return array_combine( $slugs, $slugs ); |
|
112 | + $slugs = array_keys(get_post_format_strings()); |
|
113 | + return array_combine($slugs, $slugs); |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -121,12 +121,12 @@ discard block |
||
121 | 121 | * @param string $slug A post format slug. |
122 | 122 | * @return string The translated post format name. |
123 | 123 | */ |
124 | -function get_post_format_string( $slug ) { |
|
124 | +function get_post_format_string($slug) { |
|
125 | 125 | $strings = get_post_format_strings(); |
126 | - if ( !$slug ) |
|
126 | + if ( ! $slug) |
|
127 | 127 | return $strings['standard']; |
128 | 128 | else |
129 | - return ( isset( $strings[$slug] ) ) ? $strings[$slug] : ''; |
|
129 | + return (isset($strings[$slug])) ? $strings[$slug] : ''; |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -137,11 +137,11 @@ discard block |
||
137 | 137 | * @param string $format The post format slug. |
138 | 138 | * @return string|WP_Error|false The post format term link. |
139 | 139 | */ |
140 | -function get_post_format_link( $format ) { |
|
141 | - $term = get_term_by('slug', 'post-format-' . $format, 'post_format' ); |
|
142 | - if ( ! $term || is_wp_error( $term ) ) |
|
140 | +function get_post_format_link($format) { |
|
141 | + $term = get_term_by('slug', 'post-format-'.$format, 'post_format'); |
|
142 | + if ( ! $term || is_wp_error($term)) |
|
143 | 143 | return false; |
144 | - return get_term_link( $term ); |
|
144 | + return get_term_link($term); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -153,14 +153,14 @@ discard block |
||
153 | 153 | * @param array $qvs |
154 | 154 | * @return array |
155 | 155 | */ |
156 | -function _post_format_request( $qvs ) { |
|
157 | - if ( ! isset( $qvs['post_format'] ) ) |
|
156 | +function _post_format_request($qvs) { |
|
157 | + if ( ! isset($qvs['post_format'])) |
|
158 | 158 | return $qvs; |
159 | 159 | $slugs = get_post_format_slugs(); |
160 | - if ( isset( $slugs[ $qvs['post_format'] ] ) ) |
|
161 | - $qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ]; |
|
162 | - $tax = get_taxonomy( 'post_format' ); |
|
163 | - if ( ! is_admin() ) |
|
160 | + if (isset($slugs[$qvs['post_format']])) |
|
161 | + $qvs['post_format'] = 'post-format-'.$slugs[$qvs['post_format']]; |
|
162 | + $tax = get_taxonomy('post_format'); |
|
163 | + if ( ! is_admin()) |
|
164 | 164 | $qvs['post_type'] = $tax->object_type; |
165 | 165 | return $qvs; |
166 | 166 | } |
@@ -178,16 +178,16 @@ discard block |
||
178 | 178 | * @param string $taxonomy |
179 | 179 | * @return string |
180 | 180 | */ |
181 | -function _post_format_link( $link, $term, $taxonomy ) { |
|
181 | +function _post_format_link($link, $term, $taxonomy) { |
|
182 | 182 | global $wp_rewrite; |
183 | - if ( 'post_format' != $taxonomy ) { |
|
183 | + if ('post_format' != $taxonomy) { |
|
184 | 184 | return $link; |
185 | 185 | } |
186 | - if ( $wp_rewrite->get_extra_permastruct( $taxonomy ) ) { |
|
187 | - return str_replace( "/{$term->slug}", '/' . str_replace( 'post-format-', '', $term->slug ), $link ); |
|
186 | + if ($wp_rewrite->get_extra_permastruct($taxonomy)) { |
|
187 | + return str_replace("/{$term->slug}", '/'.str_replace('post-format-', '', $term->slug), $link); |
|
188 | 188 | } else { |
189 | - $link = remove_query_arg( 'post_format', $link ); |
|
190 | - return add_query_arg( 'post_format', str_replace( 'post-format-', '', $term->slug ), $link ); |
|
189 | + $link = remove_query_arg('post_format', $link); |
|
190 | + return add_query_arg('post_format', str_replace('post-format-', '', $term->slug), $link); |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
@@ -200,9 +200,9 @@ discard block |
||
200 | 200 | * @param object $term |
201 | 201 | * @return object |
202 | 202 | */ |
203 | -function _post_format_get_term( $term ) { |
|
204 | - if ( isset( $term->slug ) ) { |
|
205 | - $term->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); |
|
203 | +function _post_format_get_term($term) { |
|
204 | + if (isset($term->slug)) { |
|
205 | + $term->name = get_post_format_string(str_replace('post-format-', '', $term->slug)); |
|
206 | 206 | } |
207 | 207 | return $term; |
208 | 208 | } |
@@ -218,16 +218,16 @@ discard block |
||
218 | 218 | * @param array $args |
219 | 219 | * @return array |
220 | 220 | */ |
221 | -function _post_format_get_terms( $terms, $taxonomies, $args ) { |
|
222 | - if ( in_array( 'post_format', (array) $taxonomies ) ) { |
|
223 | - if ( isset( $args['fields'] ) && 'names' == $args['fields'] ) { |
|
224 | - foreach ( $terms as $order => $name ) { |
|
225 | - $terms[$order] = get_post_format_string( str_replace( 'post-format-', '', $name ) ); |
|
221 | +function _post_format_get_terms($terms, $taxonomies, $args) { |
|
222 | + if (in_array('post_format', (array) $taxonomies)) { |
|
223 | + if (isset($args['fields']) && 'names' == $args['fields']) { |
|
224 | + foreach ($terms as $order => $name) { |
|
225 | + $terms[$order] = get_post_format_string(str_replace('post-format-', '', $name)); |
|
226 | 226 | } |
227 | 227 | } else { |
228 | - foreach ( (array) $terms as $order => $term ) { |
|
229 | - if ( isset( $term->taxonomy ) && 'post_format' == $term->taxonomy ) { |
|
230 | - $terms[$order]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); |
|
228 | + foreach ((array) $terms as $order => $term) { |
|
229 | + if (isset($term->taxonomy) && 'post_format' == $term->taxonomy) { |
|
230 | + $terms[$order]->name = get_post_format_string(str_replace('post-format-', '', $term->slug)); |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 | } |
@@ -244,10 +244,10 @@ discard block |
||
244 | 244 | * @param array $terms |
245 | 245 | * @return array |
246 | 246 | */ |
247 | -function _post_format_wp_get_object_terms( $terms ) { |
|
248 | - foreach ( (array) $terms as $order => $term ) { |
|
249 | - if ( isset( $term->taxonomy ) && 'post_format' == $term->taxonomy ) { |
|
250 | - $terms[$order]->name = get_post_format_string( str_replace( 'post-format-', '', $term->slug ) ); |
|
247 | +function _post_format_wp_get_object_terms($terms) { |
|
248 | + foreach ((array) $terms as $order => $term) { |
|
249 | + if (isset($term->taxonomy) && 'post_format' == $term->taxonomy) { |
|
250 | + $terms[$order]->name = get_post_format_string(str_replace('post-format-', '', $term->slug)); |
|
251 | 251 | } |
252 | 252 | } |
253 | 253 | return $terms; |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | * @subpackage MagpieRSS |
410 | 410 | * |
411 | 411 | * @param string $url URL to retrieve feed |
412 | - * @return bool|MagpieRSS false on failure or MagpieRSS object on success. |
|
412 | + * @return integer|null false on failure or MagpieRSS object on success. |
|
413 | 413 | */ |
414 | 414 | function fetch_rss ($url) { |
415 | 415 | // initialize constants |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | * |
548 | 548 | * @param string $url URL to retrieve |
549 | 549 | * @param array $headers Optional. Headers to send to the URL. |
550 | - * @return Snoopy style response |
|
550 | + * @return stdClass style response |
|
551 | 551 | */ |
552 | 552 | function _fetch_remote_file($url, $headers = "" ) { |
553 | 553 | $resp = wp_safe_remote_request( $url, array( 'headers' => $headers, 'timeout' => MAGPIE_FETCH_TIME_OUT ) ); |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | * @package External |
590 | 590 | * @subpackage MagpieRSS |
591 | 591 | * |
592 | - * @param array $resp |
|
592 | + * @param stdClass $resp |
|
593 | 593 | * @return MagpieRSS|bool |
594 | 594 | */ |
595 | 595 | function _response_to_rss ($resp) { |
@@ -746,6 +746,9 @@ discard block |
||
746 | 746 | Input: url from wich the rss file was fetched |
747 | 747 | Output: true on success |
748 | 748 | \*=======================================================================*/ |
749 | + /** |
|
750 | + * @param string $url |
|
751 | + */ |
|
749 | 752 | function set ($url, $rss) { |
750 | 753 | $cache_option = 'rss_' . $this->file_name( $url ); |
751 | 754 | |
@@ -760,6 +763,9 @@ discard block |
||
760 | 763 | Input: url from wich the rss file was fetched |
761 | 764 | Output: cached object on HIT, false on MISS |
762 | 765 | \*=======================================================================*/ |
766 | + /** |
|
767 | + * @param string $url |
|
768 | + */ |
|
763 | 769 | function get ($url) { |
764 | 770 | $this->ERROR = ""; |
765 | 771 | $cache_option = 'rss_' . $this->file_name( $url ); |
@@ -781,6 +787,9 @@ discard block |
||
781 | 787 | Input: url from wich the rss file was fetched |
782 | 788 | Output: cached object on HIT, false on MISS |
783 | 789 | \*=======================================================================*/ |
790 | + /** |
|
791 | + * @param string $url |
|
792 | + */ |
|
784 | 793 | function check_cache ( $url ) { |
785 | 794 | $this->ERROR = ""; |
786 | 795 | $cache_option = 'rss_' . $this->file_name( $url ); |
@@ -936,7 +945,7 @@ discard block |
||
936 | 945 | * |
937 | 946 | * @param string $url URL of feed to display. Will not auto sense feed URL. |
938 | 947 | * @param int $num_items Optional. Number of items to display, default is all. |
939 | - * @return bool False on failure. |
|
948 | + * @return null|false False on failure. |
|
940 | 949 | */ |
941 | 950 | function get_rss ($url, $num_items = 5) { // Like get posts, but for RSS |
942 | 951 | $rss = fetch_rss($url); |
@@ -62,13 +62,15 @@ discard block |
||
62 | 62 | |
63 | 63 | # if PHP xml isn't compiled in, die |
64 | 64 | # |
65 | - if ( !function_exists('xml_parser_create') ) |
|
66 | - trigger_error( "Failed to load PHP's XML Extension. https://secure.php.net/manual/en/ref.xml.php" ); |
|
65 | + if ( !function_exists('xml_parser_create') ) { |
|
66 | + trigger_error( "Failed to load PHP's XML Extension. https://secure.php.net/manual/en/ref.xml.php" ); |
|
67 | + } |
|
67 | 68 | |
68 | 69 | $parser = @xml_parser_create(); |
69 | 70 | |
70 | - if ( !is_resource($parser) ) |
|
71 | - trigger_error( "Failed to create an instance of PHP's XML parser. https://secure.php.net/manual/en/ref.xml.php"); |
|
71 | + if ( !is_resource($parser) ) { |
|
72 | + trigger_error( "Failed to create an instance of PHP's XML parser. https://secure.php.net/manual/en/ref.xml.php"); |
|
73 | + } |
|
72 | 74 | |
73 | 75 | $this->parser = $parser; |
74 | 76 | |
@@ -127,12 +129,10 @@ discard block |
||
127 | 129 | if ( $el == 'rdf' ) { |
128 | 130 | $this->feed_type = RSS; |
129 | 131 | $this->feed_version = '1.0'; |
130 | - } |
|
131 | - elseif ( $el == 'rss' ) { |
|
132 | + } elseif ( $el == 'rss' ) { |
|
132 | 133 | $this->feed_type = RSS; |
133 | 134 | $this->feed_version = $attrs['version']; |
134 | - } |
|
135 | - elseif ( $el == 'feed' ) { |
|
135 | + } elseif ( $el == 'feed' ) { |
|
136 | 136 | $this->feed_type = ATOM; |
137 | 137 | $this->feed_version = $attrs['version']; |
138 | 138 | $this->inchannel = true; |
@@ -143,8 +143,7 @@ discard block |
||
143 | 143 | if ( $el == 'channel' ) |
144 | 144 | { |
145 | 145 | $this->inchannel = true; |
146 | - } |
|
147 | - elseif ($el == 'item' or $el == 'entry' ) |
|
146 | + } elseif ($el == 'item' or $el == 'entry' ) |
|
148 | 147 | { |
149 | 148 | $this->initem = true; |
150 | 149 | if ( isset($attrs['rdf:about']) ) { |
@@ -160,9 +159,7 @@ discard block |
||
160 | 159 | $el == 'textinput' ) |
161 | 160 | { |
162 | 161 | $this->intextinput = true; |
163 | - } |
|
164 | - |
|
165 | - elseif ( |
|
162 | + } elseif ( |
|
166 | 163 | $this->feed_type == RSS and |
167 | 164 | $this->current_namespace == '' and |
168 | 165 | $el == 'image' ) |
@@ -205,8 +202,7 @@ discard block |
||
205 | 202 | if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) |
206 | 203 | { |
207 | 204 | $link_el = 'link'; |
208 | - } |
|
209 | - else { |
|
205 | + } else { |
|
210 | 206 | $link_el = 'link_' . $attrs['rel']; |
211 | 207 | } |
212 | 208 | |
@@ -223,8 +219,7 @@ discard block |
||
223 | 219 | if ($this->feed_type == ATOM and $this->incontent) |
224 | 220 | { |
225 | 221 | $this->append_content( $text ); |
226 | - } |
|
227 | - else { |
|
222 | + } else { |
|
228 | 223 | $current_el = join('_', array_reverse($this->stack)); |
229 | 224 | $this->append($current_el, $text); |
230 | 225 | } |
@@ -238,37 +233,30 @@ discard block |
||
238 | 233 | $this->items[] = $this->current_item; |
239 | 234 | $this->current_item = array(); |
240 | 235 | $this->initem = false; |
241 | - } |
|
242 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) |
|
236 | + } elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) |
|
243 | 237 | { |
244 | 238 | $this->intextinput = false; |
245 | - } |
|
246 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) |
|
239 | + } elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) |
|
247 | 240 | { |
248 | 241 | $this->inimage = false; |
249 | - } |
|
250 | - elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
242 | + } elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
251 | 243 | { |
252 | 244 | $this->incontent = false; |
253 | - } |
|
254 | - elseif ($el == 'channel' or $el == 'feed' ) |
|
245 | + } elseif ($el == 'channel' or $el == 'feed' ) |
|
255 | 246 | { |
256 | 247 | $this->inchannel = false; |
257 | - } |
|
258 | - elseif ($this->feed_type == ATOM and $this->incontent ) { |
|
248 | + } elseif ($this->feed_type == ATOM and $this->incontent ) { |
|
259 | 249 | // balance tags properly |
260 | 250 | // note: This may not actually be necessary |
261 | 251 | if ( $this->stack[0] == $el ) |
262 | 252 | { |
263 | 253 | $this->append_content("</$el>"); |
264 | - } |
|
265 | - else { |
|
254 | + } else { |
|
266 | 255 | $this->append_content("<$el />"); |
267 | 256 | } |
268 | 257 | |
269 | 258 | array_shift( $this->stack ); |
270 | - } |
|
271 | - else { |
|
259 | + } else { |
|
272 | 260 | array_shift( $this->stack ); |
273 | 261 | } |
274 | 262 | |
@@ -285,8 +273,7 @@ discard block |
||
285 | 273 | function append_content($text) { |
286 | 274 | if ( $this->initem ) { |
287 | 275 | $this->concat( $this->current_item[ $this->incontent ], $text ); |
288 | - } |
|
289 | - elseif ( $this->inchannel ) { |
|
276 | + } elseif ( $this->inchannel ) { |
|
290 | 277 | $this->concat( $this->channel[ $this->incontent ], $text ); |
291 | 278 | } |
292 | 279 | } |
@@ -301,34 +288,27 @@ discard block |
||
301 | 288 | if ( $this->initem ) { |
302 | 289 | $this->concat( |
303 | 290 | $this->current_item[ $this->current_namespace ][ $el ], $text); |
304 | - } |
|
305 | - elseif ($this->inchannel) { |
|
291 | + } elseif ($this->inchannel) { |
|
306 | 292 | $this->concat( |
307 | 293 | $this->channel[ $this->current_namespace][ $el ], $text ); |
308 | - } |
|
309 | - elseif ($this->intextinput) { |
|
294 | + } elseif ($this->intextinput) { |
|
310 | 295 | $this->concat( |
311 | 296 | $this->textinput[ $this->current_namespace][ $el ], $text ); |
312 | - } |
|
313 | - elseif ($this->inimage) { |
|
297 | + } elseif ($this->inimage) { |
|
314 | 298 | $this->concat( |
315 | 299 | $this->image[ $this->current_namespace ][ $el ], $text ); |
316 | 300 | } |
317 | - } |
|
318 | - else { |
|
301 | + } else { |
|
319 | 302 | if ( $this->initem ) { |
320 | 303 | $this->concat( |
321 | 304 | $this->current_item[ $el ], $text); |
322 | - } |
|
323 | - elseif ($this->intextinput) { |
|
305 | + } elseif ($this->intextinput) { |
|
324 | 306 | $this->concat( |
325 | 307 | $this->textinput[ $el ], $text ); |
326 | - } |
|
327 | - elseif ($this->inimage) { |
|
308 | + } elseif ($this->inimage) { |
|
328 | 309 | $this->concat( |
329 | 310 | $this->image[ $el ], $text ); |
330 | - } |
|
331 | - elseif ($this->inchannel) { |
|
311 | + } elseif ($this->inchannel) { |
|
332 | 312 | $this->concat( |
333 | 313 | $this->channel[ $el ], $text ); |
334 | 314 | } |
@@ -342,22 +322,25 @@ discard block |
||
342 | 322 | $this->channel['descripton'] = $this->channel['tagline']; |
343 | 323 | for ( $i = 0; $i < count($this->items); $i++) { |
344 | 324 | $item = $this->items[$i]; |
345 | - if ( isset($item['summary']) ) |
|
346 | - $item['description'] = $item['summary']; |
|
347 | - if ( isset($item['atom_content'])) |
|
348 | - $item['content']['encoded'] = $item['atom_content']; |
|
325 | + if ( isset($item['summary']) ) { |
|
326 | + $item['description'] = $item['summary']; |
|
327 | + } |
|
328 | + if ( isset($item['atom_content'])) { |
|
329 | + $item['content']['encoded'] = $item['atom_content']; |
|
330 | + } |
|
349 | 331 | |
350 | 332 | $this->items[$i] = $item; |
351 | 333 | } |
352 | - } |
|
353 | - elseif ( $this->is_rss() ) { |
|
334 | + } elseif ( $this->is_rss() ) { |
|
354 | 335 | $this->channel['tagline'] = $this->channel['description']; |
355 | 336 | for ( $i = 0; $i < count($this->items); $i++) { |
356 | 337 | $item = $this->items[$i]; |
357 | - if ( isset($item['description'])) |
|
358 | - $item['summary'] = $item['description']; |
|
359 | - if ( isset($item['content']['encoded'] ) ) |
|
360 | - $item['atom_content'] = $item['content']['encoded']; |
|
338 | + if ( isset($item['description'])) { |
|
339 | + $item['summary'] = $item['description']; |
|
340 | + } |
|
341 | + if ( isset($item['content']['encoded'] ) ) { |
|
342 | + $item['atom_content'] = $item['content']['encoded']; |
|
343 | + } |
|
361 | 344 | |
362 | 345 | $this->items[$i] = $item; |
363 | 346 | } |
@@ -367,8 +350,7 @@ discard block |
||
367 | 350 | function is_rss () { |
368 | 351 | if ( $this->feed_type == RSS ) { |
369 | 352 | return $this->feed_version; |
370 | - } |
|
371 | - else { |
|
353 | + } else { |
|
372 | 354 | return false; |
373 | 355 | } |
374 | 356 | } |
@@ -376,8 +358,7 @@ discard block |
||
376 | 358 | function is_atom() { |
377 | 359 | if ( $this->feed_type == ATOM ) { |
378 | 360 | return $this->feed_version; |
379 | - } |
|
380 | - else { |
|
361 | + } else { |
|
381 | 362 | return false; |
382 | 363 | } |
383 | 364 | } |
@@ -426,8 +407,7 @@ discard block |
||
426 | 407 | $resp = _fetch_remote_file( $url ); |
427 | 408 | if ( is_success( $resp->status ) ) { |
428 | 409 | return _response_to_rss( $resp ); |
429 | - } |
|
430 | - else { |
|
410 | + } else { |
|
431 | 411 | // error("Failed to fetch $url and cache is off"); |
432 | 412 | return false; |
433 | 413 | } |
@@ -490,8 +470,7 @@ discard block |
||
490 | 470 | // reset cache on 304 (at minutillo insistent prodding) |
491 | 471 | $cache->set($url, $rss); |
492 | 472 | return $rss; |
493 | - } |
|
494 | - elseif ( is_success( $resp->status ) ) { |
|
473 | + } elseif ( is_success( $resp->status ) ) { |
|
495 | 474 | $rss = _response_to_rss( $resp ); |
496 | 475 | if ( $rss ) { |
497 | 476 | if (MAGPIE_DEBUG > 1) { |
@@ -501,21 +480,18 @@ discard block |
||
501 | 480 | $cache->set( $url, $rss ); |
502 | 481 | return $rss; |
503 | 482 | } |
504 | - } |
|
505 | - else { |
|
483 | + } else { |
|
506 | 484 | $errormsg = "Failed to fetch $url. "; |
507 | 485 | if ( $resp->error ) { |
508 | 486 | # compensate for Snoopy's annoying habbit to tacking |
509 | 487 | # on '\n' |
510 | 488 | $http_error = substr($resp->error, 0, -2); |
511 | 489 | $errormsg .= "(HTTP Error: $http_error)"; |
512 | - } |
|
513 | - else { |
|
490 | + } else { |
|
514 | 491 | $errormsg .= "(HTTP Response: " . $resp->response_code .')'; |
515 | 492 | } |
516 | 493 | } |
517 | - } |
|
518 | - else { |
|
494 | + } else { |
|
519 | 495 | $errormsg = "Unable to retrieve RSS file for unknown reasons."; |
520 | 496 | } |
521 | 497 | |
@@ -568,8 +544,9 @@ discard block |
||
568 | 544 | if ( !is_array($value) ) { |
569 | 545 | $return_headers[] = "$key: $value"; |
570 | 546 | } else { |
571 | - foreach ( $value as $v ) |
|
572 | - $return_headers[] = "$key: $v"; |
|
547 | + foreach ( $value as $v ) { |
|
548 | + $return_headers[] = "$key: $v"; |
|
549 | + } |
|
573 | 550 | } |
574 | 551 | } |
575 | 552 | |
@@ -603,8 +580,7 @@ discard block |
||
603 | 580 | // 2003-03-02 - Nicola Asuni (www.tecnick.com) - fixed bug "Undefined offset: 1" |
604 | 581 | if (strpos($h, ": ")) { |
605 | 582 | list($field, $val) = explode(": ", $h, 2); |
606 | - } |
|
607 | - else { |
|
583 | + } else { |
|
608 | 584 | $field = $h; |
609 | 585 | $val = ""; |
610 | 586 | } |
@@ -642,8 +618,7 @@ discard block |
||
642 | 618 | function init () { |
643 | 619 | if ( defined('MAGPIE_INITALIZED') ) { |
644 | 620 | return; |
645 | - } |
|
646 | - else { |
|
621 | + } else { |
|
647 | 622 | define('MAGPIE_INITALIZED', 1); |
648 | 623 | } |
649 | 624 | |
@@ -672,8 +647,7 @@ discard block |
||
672 | 647 | |
673 | 648 | if ( MAGPIE_CACHE_ON ) { |
674 | 649 | $ua = $ua . ')'; |
675 | - } |
|
676 | - else { |
|
650 | + } else { |
|
677 | 651 | $ua = $ua . '; No cache)'; |
678 | 652 | } |
679 | 653 | |
@@ -830,8 +804,7 @@ discard block |
||
830 | 804 | $this->ERROR = $errormsg; |
831 | 805 | if ( MAGPIE_DEBUG ) { |
832 | 806 | trigger_error( $errormsg, $lvl); |
833 | - } |
|
834 | - else { |
|
807 | + } else { |
|
835 | 808 | error_log( $errormsg, 0); |
836 | 809 | } |
837 | 810 | } |
@@ -858,8 +831,7 @@ discard block |
||
858 | 831 | $offset = 0; |
859 | 832 | if ( $match[11] == 'Z' ) { |
860 | 833 | # zulu time, aka GMT |
861 | - } |
|
862 | - else { |
|
834 | + } else { |
|
863 | 835 | list( $tz_mod, $tz_hour, $tz_min ) = |
864 | 836 | array( $match[8], $match[9], $match[10]); |
865 | 837 | |
@@ -879,8 +851,7 @@ discard block |
||
879 | 851 | } |
880 | 852 | $epoch = $epoch + $offset; |
881 | 853 | return $epoch; |
882 | - } |
|
883 | - else { |
|
854 | + } else { |
|
884 | 855 | return -1; |
885 | 856 | } |
886 | 857 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * Deprecated. Use SimplePie (class-simplepie.php) instead. |
18 | 18 | */ |
19 | -_deprecated_file( basename( __FILE__ ), '3.0.0', WPINC . '/class-simplepie.php' ); |
|
19 | +_deprecated_file(basename(__FILE__), '3.0.0', WPINC.'/class-simplepie.php'); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Fires before MagpieRSS is loaded, to optionally replace it. |
@@ -24,32 +24,32 @@ discard block |
||
24 | 24 | * @since 2.3.0 |
25 | 25 | * @deprecated 3.0.0 |
26 | 26 | */ |
27 | -do_action( 'load_feed_engine' ); |
|
27 | +do_action('load_feed_engine'); |
|
28 | 28 | |
29 | 29 | /** RSS feed constant. */ |
30 | 30 | define('RSS', 'RSS'); |
31 | 31 | define('ATOM', 'Atom'); |
32 | -define('MAGPIE_USER_AGENT', 'WordPress/' . $GLOBALS['wp_version']); |
|
32 | +define('MAGPIE_USER_AGENT', 'WordPress/'.$GLOBALS['wp_version']); |
|
33 | 33 | |
34 | 34 | class MagpieRSS { |
35 | 35 | var $parser; |
36 | - var $current_item = array(); // item currently being parsed |
|
37 | - var $items = array(); // collection of parsed items |
|
38 | - var $channel = array(); // hash of channel fields |
|
39 | - var $textinput = array(); |
|
36 | + var $current_item = array(); // item currently being parsed |
|
37 | + var $items = array(); // collection of parsed items |
|
38 | + var $channel = array(); // hash of channel fields |
|
39 | + var $textinput = array(); |
|
40 | 40 | var $image = array(); |
41 | 41 | var $feed_type; |
42 | 42 | var $feed_version; |
43 | 43 | |
44 | 44 | // parser variables |
45 | - var $stack = array(); // parser stack |
|
45 | + var $stack = array(); // parser stack |
|
46 | 46 | var $inchannel = false; |
47 | - var $initem = false; |
|
47 | + var $initem = false; |
|
48 | 48 | var $incontent = false; // if in Atom <content mode="xml"> field |
49 | - var $intextinput = false; |
|
50 | - var $inimage = false; |
|
51 | - var $current_field = ''; |
|
52 | - var $current_namespace = false; |
|
49 | + var $intextinput = false; |
|
50 | + var $inimage = false; |
|
51 | + var $current_field = ''; |
|
52 | + var $current_namespace = false; |
|
53 | 53 | |
54 | 54 | //var $ERROR = ""; |
55 | 55 | |
@@ -58,44 +58,44 @@ discard block |
||
58 | 58 | /** |
59 | 59 | * PHP5 constructor. |
60 | 60 | */ |
61 | - function __construct( $source ) { |
|
61 | + function __construct($source) { |
|
62 | 62 | |
63 | 63 | # if PHP xml isn't compiled in, die |
64 | 64 | # |
65 | - if ( !function_exists('xml_parser_create') ) |
|
66 | - trigger_error( "Failed to load PHP's XML Extension. https://secure.php.net/manual/en/ref.xml.php" ); |
|
65 | + if ( ! function_exists('xml_parser_create')) |
|
66 | + trigger_error("Failed to load PHP's XML Extension. https://secure.php.net/manual/en/ref.xml.php"); |
|
67 | 67 | |
68 | 68 | $parser = @xml_parser_create(); |
69 | 69 | |
70 | - if ( !is_resource($parser) ) |
|
71 | - trigger_error( "Failed to create an instance of PHP's XML parser. https://secure.php.net/manual/en/ref.xml.php"); |
|
70 | + if ( ! is_resource($parser)) |
|
71 | + trigger_error("Failed to create an instance of PHP's XML parser. https://secure.php.net/manual/en/ref.xml.php"); |
|
72 | 72 | |
73 | 73 | $this->parser = $parser; |
74 | 74 | |
75 | 75 | # pass in parser, and a reference to this object |
76 | 76 | # set up handlers |
77 | 77 | # |
78 | - xml_set_object( $this->parser, $this ); |
|
78 | + xml_set_object($this->parser, $this); |
|
79 | 79 | xml_set_element_handler($this->parser, |
80 | - 'feed_start_element', 'feed_end_element' ); |
|
80 | + 'feed_start_element', 'feed_end_element'); |
|
81 | 81 | |
82 | - xml_set_character_data_handler( $this->parser, 'feed_cdata' ); |
|
82 | + xml_set_character_data_handler($this->parser, 'feed_cdata'); |
|
83 | 83 | |
84 | - $status = xml_parse( $this->parser, $source ); |
|
84 | + $status = xml_parse($this->parser, $source); |
|
85 | 85 | |
86 | - if (! $status ) { |
|
87 | - $errorcode = xml_get_error_code( $this->parser ); |
|
88 | - if ( $errorcode != XML_ERROR_NONE ) { |
|
89 | - $xml_error = xml_error_string( $errorcode ); |
|
86 | + if ( ! $status) { |
|
87 | + $errorcode = xml_get_error_code($this->parser); |
|
88 | + if ($errorcode != XML_ERROR_NONE) { |
|
89 | + $xml_error = xml_error_string($errorcode); |
|
90 | 90 | $error_line = xml_get_current_line_number($this->parser); |
91 | 91 | $error_col = xml_get_current_column_number($this->parser); |
92 | 92 | $errormsg = "$xml_error at line $error_line, column $error_col"; |
93 | 93 | |
94 | - $this->error( $errormsg ); |
|
94 | + $this->error($errormsg); |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
98 | - xml_parser_free( $this->parser ); |
|
98 | + xml_parser_free($this->parser); |
|
99 | 99 | |
100 | 100 | $this->normalize(); |
101 | 101 | } |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | /** |
104 | 104 | * PHP4 constructor. |
105 | 105 | */ |
106 | - public function MagpieRSS( $source ) { |
|
107 | - self::__construct( $source ); |
|
106 | + public function MagpieRSS($source) { |
|
107 | + self::__construct($source); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | function feed_start_element($p, $element, &$attrs) { |
@@ -112,27 +112,27 @@ discard block |
||
112 | 112 | $attrs = array_change_key_case($attrs, CASE_LOWER); |
113 | 113 | |
114 | 114 | // check for a namespace, and split if found |
115 | - $ns = false; |
|
116 | - if ( strpos( $element, ':' ) ) { |
|
117 | - list($ns, $el) = explode( ':', $element, 2); |
|
115 | + $ns = false; |
|
116 | + if (strpos($element, ':')) { |
|
117 | + list($ns, $el) = explode(':', $element, 2); |
|
118 | 118 | } |
119 | - if ( $ns and $ns != 'rdf' ) { |
|
119 | + if ($ns and $ns != 'rdf') { |
|
120 | 120 | $this->current_namespace = $ns; |
121 | 121 | } |
122 | 122 | |
123 | 123 | # if feed type isn't set, then this is first element of feed |
124 | 124 | # identify feed from root element |
125 | 125 | # |
126 | - if (!isset($this->feed_type) ) { |
|
127 | - if ( $el == 'rdf' ) { |
|
126 | + if ( ! isset($this->feed_type)) { |
|
127 | + if ($el == 'rdf') { |
|
128 | 128 | $this->feed_type = RSS; |
129 | 129 | $this->feed_version = '1.0'; |
130 | 130 | } |
131 | - elseif ( $el == 'rss' ) { |
|
131 | + elseif ($el == 'rss') { |
|
132 | 132 | $this->feed_type = RSS; |
133 | 133 | $this->feed_version = $attrs['version']; |
134 | 134 | } |
135 | - elseif ( $el == 'feed' ) { |
|
135 | + elseif ($el == 'feed') { |
|
136 | 136 | $this->feed_type = ATOM; |
137 | 137 | $this->feed_version = $attrs['version']; |
138 | 138 | $this->inchannel = true; |
@@ -140,14 +140,14 @@ discard block |
||
140 | 140 | return; |
141 | 141 | } |
142 | 142 | |
143 | - if ( $el == 'channel' ) |
|
143 | + if ($el == 'channel') |
|
144 | 144 | { |
145 | 145 | $this->inchannel = true; |
146 | 146 | } |
147 | - elseif ($el == 'item' or $el == 'entry' ) |
|
147 | + elseif ($el == 'item' or $el == 'entry') |
|
148 | 148 | { |
149 | 149 | $this->initem = true; |
150 | - if ( isset($attrs['rdf:about']) ) { |
|
150 | + if (isset($attrs['rdf:about'])) { |
|
151 | 151 | $this->current_item['about'] = $attrs['rdf:about']; |
152 | 152 | } |
153 | 153 | } |
@@ -171,10 +171,10 @@ discard block |
||
171 | 171 | } |
172 | 172 | |
173 | 173 | # handle atom content constructs |
174 | - elseif ( $this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
174 | + elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS)) |
|
175 | 175 | { |
176 | 176 | // avoid clashing w/ RSS mod_content |
177 | - if ($el == 'content' ) { |
|
177 | + if ($el == 'content') { |
|
178 | 178 | $el = 'atom_content'; |
179 | 179 | } |
180 | 180 | |
@@ -183,31 +183,31 @@ discard block |
||
183 | 183 | } |
184 | 184 | |
185 | 185 | // if inside an Atom content construct (e.g. content or summary) field treat tags as text |
186 | - elseif ($this->feed_type == ATOM and $this->incontent ) |
|
186 | + elseif ($this->feed_type == ATOM and $this->incontent) |
|
187 | 187 | { |
188 | 188 | // if tags are inlined, then flatten |
189 | 189 | $attrs_str = join(' ', |
190 | 190 | array_map(array('MagpieRSS', 'map_attrs'), |
191 | 191 | array_keys($attrs), |
192 | - array_values($attrs) ) ); |
|
192 | + array_values($attrs))); |
|
193 | 193 | |
194 | - $this->append_content( "<$element $attrs_str>" ); |
|
194 | + $this->append_content("<$element $attrs_str>"); |
|
195 | 195 | |
196 | - array_unshift( $this->stack, $el ); |
|
196 | + array_unshift($this->stack, $el); |
|
197 | 197 | } |
198 | 198 | |
199 | 199 | // Atom support many links per containging element. |
200 | 200 | // Magpie treats link elements of type rel='alternate' |
201 | 201 | // as being equivalent to RSS's simple link element. |
202 | 202 | // |
203 | - elseif ($this->feed_type == ATOM and $el == 'link' ) |
|
203 | + elseif ($this->feed_type == ATOM and $el == 'link') |
|
204 | 204 | { |
205 | - if ( isset($attrs['rel']) and $attrs['rel'] == 'alternate' ) |
|
205 | + if (isset($attrs['rel']) and $attrs['rel'] == 'alternate') |
|
206 | 206 | { |
207 | 207 | $link_el = 'link'; |
208 | 208 | } |
209 | 209 | else { |
210 | - $link_el = 'link_' . $attrs['rel']; |
|
210 | + $link_el = 'link_'.$attrs['rel']; |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | $this->append($link_el, $attrs['href']); |
@@ -218,11 +218,11 @@ discard block |
||
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
221 | - function feed_cdata ($p, $text) { |
|
221 | + function feed_cdata($p, $text) { |
|
222 | 222 | |
223 | 223 | if ($this->feed_type == ATOM and $this->incontent) |
224 | 224 | { |
225 | - $this->append_content( $text ); |
|
225 | + $this->append_content($text); |
|
226 | 226 | } |
227 | 227 | else { |
228 | 228 | $current_el = join('_', array_reverse($this->stack)); |
@@ -230,35 +230,35 @@ discard block |
||
230 | 230 | } |
231 | 231 | } |
232 | 232 | |
233 | - function feed_end_element ($p, $el) { |
|
233 | + function feed_end_element($p, $el) { |
|
234 | 234 | $el = strtolower($el); |
235 | 235 | |
236 | - if ( $el == 'item' or $el == 'entry' ) |
|
236 | + if ($el == 'item' or $el == 'entry') |
|
237 | 237 | { |
238 | 238 | $this->items[] = $this->current_item; |
239 | 239 | $this->current_item = array(); |
240 | 240 | $this->initem = false; |
241 | 241 | } |
242 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput' ) |
|
242 | + elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'textinput') |
|
243 | 243 | { |
244 | 244 | $this->intextinput = false; |
245 | 245 | } |
246 | - elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image' ) |
|
246 | + elseif ($this->feed_type == RSS and $this->current_namespace == '' and $el == 'image') |
|
247 | 247 | { |
248 | 248 | $this->inimage = false; |
249 | 249 | } |
250 | - elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
250 | + elseif ($this->feed_type == ATOM and in_array($el, $this->_CONTENT_CONSTRUCTS)) |
|
251 | 251 | { |
252 | 252 | $this->incontent = false; |
253 | 253 | } |
254 | - elseif ($el == 'channel' or $el == 'feed' ) |
|
254 | + elseif ($el == 'channel' or $el == 'feed') |
|
255 | 255 | { |
256 | 256 | $this->inchannel = false; |
257 | 257 | } |
258 | - elseif ($this->feed_type == ATOM and $this->incontent ) { |
|
258 | + elseif ($this->feed_type == ATOM and $this->incontent) { |
|
259 | 259 | // balance tags properly |
260 | 260 | // note: This may not actually be necessary |
261 | - if ( $this->stack[0] == $el ) |
|
261 | + if ($this->stack[0] == $el) |
|
262 | 262 | { |
263 | 263 | $this->append_content("</$el>"); |
264 | 264 | } |
@@ -266,97 +266,97 @@ discard block |
||
266 | 266 | $this->append_content("<$el />"); |
267 | 267 | } |
268 | 268 | |
269 | - array_shift( $this->stack ); |
|
269 | + array_shift($this->stack); |
|
270 | 270 | } |
271 | 271 | else { |
272 | - array_shift( $this->stack ); |
|
272 | + array_shift($this->stack); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | $this->current_namespace = false; |
276 | 276 | } |
277 | 277 | |
278 | - function concat (&$str1, $str2="") { |
|
279 | - if (!isset($str1) ) { |
|
280 | - $str1=""; |
|
278 | + function concat(&$str1, $str2 = "") { |
|
279 | + if ( ! isset($str1)) { |
|
280 | + $str1 = ""; |
|
281 | 281 | } |
282 | 282 | $str1 .= $str2; |
283 | 283 | } |
284 | 284 | |
285 | 285 | function append_content($text) { |
286 | - if ( $this->initem ) { |
|
287 | - $this->concat( $this->current_item[ $this->incontent ], $text ); |
|
286 | + if ($this->initem) { |
|
287 | + $this->concat($this->current_item[$this->incontent], $text); |
|
288 | 288 | } |
289 | - elseif ( $this->inchannel ) { |
|
290 | - $this->concat( $this->channel[ $this->incontent ], $text ); |
|
289 | + elseif ($this->inchannel) { |
|
290 | + $this->concat($this->channel[$this->incontent], $text); |
|
291 | 291 | } |
292 | 292 | } |
293 | 293 | |
294 | 294 | // smart append - field and namespace aware |
295 | 295 | function append($el, $text) { |
296 | - if (!$el) { |
|
296 | + if ( ! $el) { |
|
297 | 297 | return; |
298 | 298 | } |
299 | - if ( $this->current_namespace ) |
|
299 | + if ($this->current_namespace) |
|
300 | 300 | { |
301 | - if ( $this->initem ) { |
|
301 | + if ($this->initem) { |
|
302 | 302 | $this->concat( |
303 | - $this->current_item[ $this->current_namespace ][ $el ], $text); |
|
303 | + $this->current_item[$this->current_namespace][$el], $text); |
|
304 | 304 | } |
305 | 305 | elseif ($this->inchannel) { |
306 | 306 | $this->concat( |
307 | - $this->channel[ $this->current_namespace][ $el ], $text ); |
|
307 | + $this->channel[$this->current_namespace][$el], $text ); |
|
308 | 308 | } |
309 | 309 | elseif ($this->intextinput) { |
310 | 310 | $this->concat( |
311 | - $this->textinput[ $this->current_namespace][ $el ], $text ); |
|
311 | + $this->textinput[$this->current_namespace][$el], $text ); |
|
312 | 312 | } |
313 | 313 | elseif ($this->inimage) { |
314 | 314 | $this->concat( |
315 | - $this->image[ $this->current_namespace ][ $el ], $text ); |
|
315 | + $this->image[$this->current_namespace][$el], $text ); |
|
316 | 316 | } |
317 | 317 | } |
318 | 318 | else { |
319 | - if ( $this->initem ) { |
|
319 | + if ($this->initem) { |
|
320 | 320 | $this->concat( |
321 | - $this->current_item[ $el ], $text); |
|
321 | + $this->current_item[$el], $text); |
|
322 | 322 | } |
323 | 323 | elseif ($this->intextinput) { |
324 | 324 | $this->concat( |
325 | - $this->textinput[ $el ], $text ); |
|
325 | + $this->textinput[$el], $text ); |
|
326 | 326 | } |
327 | 327 | elseif ($this->inimage) { |
328 | 328 | $this->concat( |
329 | - $this->image[ $el ], $text ); |
|
329 | + $this->image[$el], $text ); |
|
330 | 330 | } |
331 | 331 | elseif ($this->inchannel) { |
332 | 332 | $this->concat( |
333 | - $this->channel[ $el ], $text ); |
|
333 | + $this->channel[$el], $text ); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | } |
337 | 337 | } |
338 | 338 | |
339 | - function normalize () { |
|
339 | + function normalize() { |
|
340 | 340 | // if atom populate rss fields |
341 | - if ( $this->is_atom() ) { |
|
341 | + if ($this->is_atom()) { |
|
342 | 342 | $this->channel['descripton'] = $this->channel['tagline']; |
343 | - for ( $i = 0; $i < count($this->items); $i++) { |
|
343 | + for ($i = 0; $i < count($this->items); $i++) { |
|
344 | 344 | $item = $this->items[$i]; |
345 | - if ( isset($item['summary']) ) |
|
345 | + if (isset($item['summary'])) |
|
346 | 346 | $item['description'] = $item['summary']; |
347 | - if ( isset($item['atom_content'])) |
|
347 | + if (isset($item['atom_content'])) |
|
348 | 348 | $item['content']['encoded'] = $item['atom_content']; |
349 | 349 | |
350 | 350 | $this->items[$i] = $item; |
351 | 351 | } |
352 | 352 | } |
353 | - elseif ( $this->is_rss() ) { |
|
353 | + elseif ($this->is_rss()) { |
|
354 | 354 | $this->channel['tagline'] = $this->channel['description']; |
355 | - for ( $i = 0; $i < count($this->items); $i++) { |
|
355 | + for ($i = 0; $i < count($this->items); $i++) { |
|
356 | 356 | $item = $this->items[$i]; |
357 | - if ( isset($item['description'])) |
|
357 | + if (isset($item['description'])) |
|
358 | 358 | $item['summary'] = $item['description']; |
359 | - if ( isset($item['content']['encoded'] ) ) |
|
359 | + if (isset($item['content']['encoded'])) |
|
360 | 360 | $item['atom_content'] = $item['content']['encoded']; |
361 | 361 | |
362 | 362 | $this->items[$i] = $item; |
@@ -364,8 +364,8 @@ discard block |
||
364 | 364 | } |
365 | 365 | } |
366 | 366 | |
367 | - function is_rss () { |
|
368 | - if ( $this->feed_type == RSS ) { |
|
367 | + function is_rss() { |
|
368 | + if ($this->feed_type == RSS) { |
|
369 | 369 | return $this->feed_version; |
370 | 370 | } |
371 | 371 | else { |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | } |
375 | 375 | |
376 | 376 | function is_atom() { |
377 | - if ( $this->feed_type == ATOM ) { |
|
377 | + if ($this->feed_type == ATOM) { |
|
378 | 378 | return $this->feed_version; |
379 | 379 | } |
380 | 380 | else { |
@@ -386,21 +386,21 @@ discard block |
||
386 | 386 | return "$k=\"$v\""; |
387 | 387 | } |
388 | 388 | |
389 | - function error( $errormsg, $lvl = E_USER_WARNING ) { |
|
389 | + function error($errormsg, $lvl = E_USER_WARNING) { |
|
390 | 390 | // append PHP's error message if track_errors enabled |
391 | - if ( isset($php_errormsg) ) { |
|
391 | + if (isset($php_errormsg)) { |
|
392 | 392 | $errormsg .= " ($php_errormsg)"; |
393 | 393 | } |
394 | - if ( MAGPIE_DEBUG ) { |
|
395 | - trigger_error( $errormsg, $lvl); |
|
394 | + if (MAGPIE_DEBUG) { |
|
395 | + trigger_error($errormsg, $lvl); |
|
396 | 396 | } else { |
397 | - error_log( $errormsg, 0); |
|
397 | + error_log($errormsg, 0); |
|
398 | 398 | } |
399 | 399 | } |
400 | 400 | |
401 | 401 | } |
402 | 402 | |
403 | -if ( !function_exists('fetch_rss') ) : |
|
403 | +if ( ! function_exists('fetch_rss')) : |
|
404 | 404 | /** |
405 | 405 | * Build Magpie object based on RSS from URL. |
406 | 406 | * |
@@ -411,21 +411,21 @@ discard block |
||
411 | 411 | * @param string $url URL to retrieve feed |
412 | 412 | * @return bool|MagpieRSS false on failure or MagpieRSS object on success. |
413 | 413 | */ |
414 | -function fetch_rss ($url) { |
|
414 | +function fetch_rss($url) { |
|
415 | 415 | // initialize constants |
416 | 416 | init(); |
417 | 417 | |
418 | - if ( !isset($url) ) { |
|
418 | + if ( ! isset($url)) { |
|
419 | 419 | // error("fetch_rss called without a url"); |
420 | 420 | return false; |
421 | 421 | } |
422 | 422 | |
423 | 423 | // if cache is disabled |
424 | - if ( !MAGPIE_CACHE_ON ) { |
|
424 | + if ( ! MAGPIE_CACHE_ON) { |
|
425 | 425 | // fetch file, and parse it |
426 | - $resp = _fetch_remote_file( $url ); |
|
427 | - if ( is_success( $resp->status ) ) { |
|
428 | - return _response_to_rss( $resp ); |
|
426 | + $resp = _fetch_remote_file($url); |
|
427 | + if (is_success($resp->status)) { |
|
428 | + return _response_to_rss($resp); |
|
429 | 429 | } |
430 | 430 | else { |
431 | 431 | // error("Failed to fetch $url and cache is off"); |
@@ -440,28 +440,28 @@ discard block |
||
440 | 440 | // 3. if cached obj fails freshness check, fetch remote |
441 | 441 | // 4. if remote fails, return stale object, or error |
442 | 442 | |
443 | - $cache = new RSSCache( MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE ); |
|
443 | + $cache = new RSSCache(MAGPIE_CACHE_DIR, MAGPIE_CACHE_AGE); |
|
444 | 444 | |
445 | 445 | if (MAGPIE_DEBUG and $cache->ERROR) { |
446 | 446 | debug($cache->ERROR, E_USER_WARNING); |
447 | 447 | } |
448 | 448 | |
449 | - $cache_status = 0; // response of check_cache |
|
449 | + $cache_status = 0; // response of check_cache |
|
450 | 450 | $request_headers = array(); // HTTP headers to send with fetch |
451 | - $rss = 0; // parsed RSS object |
|
452 | - $errormsg = 0; // errors, if any |
|
451 | + $rss = 0; // parsed RSS object |
|
452 | + $errormsg = 0; // errors, if any |
|
453 | 453 | |
454 | - if (!$cache->ERROR) { |
|
454 | + if ( ! $cache->ERROR) { |
|
455 | 455 | // return cache HIT, MISS, or STALE |
456 | - $cache_status = $cache->check_cache( $url ); |
|
456 | + $cache_status = $cache->check_cache($url); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | // if object cached, and cache is fresh, return cached obj |
460 | - if ( $cache_status == 'HIT' ) { |
|
461 | - $rss = $cache->get( $url ); |
|
462 | - if ( isset($rss) and $rss ) { |
|
460 | + if ($cache_status == 'HIT') { |
|
461 | + $rss = $cache->get($url); |
|
462 | + if (isset($rss) and $rss) { |
|
463 | 463 | $rss->from_cache = 1; |
464 | - if ( MAGPIE_DEBUG > 1) { |
|
464 | + if (MAGPIE_DEBUG > 1) { |
|
465 | 465 | debug("MagpieRSS: Cache HIT", E_USER_NOTICE); |
466 | 466 | } |
467 | 467 | return $rss; |
@@ -471,47 +471,47 @@ discard block |
||
471 | 471 | // else attempt a conditional get |
472 | 472 | |
473 | 473 | // set up headers |
474 | - if ( $cache_status == 'STALE' ) { |
|
475 | - $rss = $cache->get( $url ); |
|
476 | - if ( isset($rss->etag) and $rss->last_modified ) { |
|
474 | + if ($cache_status == 'STALE') { |
|
475 | + $rss = $cache->get($url); |
|
476 | + if (isset($rss->etag) and $rss->last_modified) { |
|
477 | 477 | $request_headers['If-None-Match'] = $rss->etag; |
478 | 478 | $request_headers['If-Last-Modified'] = $rss->last_modified; |
479 | 479 | } |
480 | 480 | } |
481 | 481 | |
482 | - $resp = _fetch_remote_file( $url, $request_headers ); |
|
482 | + $resp = _fetch_remote_file($url, $request_headers); |
|
483 | 483 | |
484 | 484 | if (isset($resp) and $resp) { |
485 | - if ($resp->status == '304' ) { |
|
485 | + if ($resp->status == '304') { |
|
486 | 486 | // we have the most current copy |
487 | - if ( MAGPIE_DEBUG > 1) { |
|
487 | + if (MAGPIE_DEBUG > 1) { |
|
488 | 488 | debug("Got 304 for $url"); |
489 | 489 | } |
490 | 490 | // reset cache on 304 (at minutillo insistent prodding) |
491 | 491 | $cache->set($url, $rss); |
492 | 492 | return $rss; |
493 | 493 | } |
494 | - elseif ( is_success( $resp->status ) ) { |
|
495 | - $rss = _response_to_rss( $resp ); |
|
496 | - if ( $rss ) { |
|
494 | + elseif (is_success($resp->status)) { |
|
495 | + $rss = _response_to_rss($resp); |
|
496 | + if ($rss) { |
|
497 | 497 | if (MAGPIE_DEBUG > 1) { |
498 | 498 | debug("Fetch successful"); |
499 | 499 | } |
500 | 500 | // add object to cache |
501 | - $cache->set( $url, $rss ); |
|
501 | + $cache->set($url, $rss); |
|
502 | 502 | return $rss; |
503 | 503 | } |
504 | 504 | } |
505 | 505 | else { |
506 | 506 | $errormsg = "Failed to fetch $url. "; |
507 | - if ( $resp->error ) { |
|
507 | + if ($resp->error) { |
|
508 | 508 | # compensate for Snoopy's annoying habbit to tacking |
509 | 509 | # on '\n' |
510 | 510 | $http_error = substr($resp->error, 0, -2); |
511 | 511 | $errormsg .= "(HTTP Error: $http_error)"; |
512 | 512 | } |
513 | 513 | else { |
514 | - $errormsg .= "(HTTP Response: " . $resp->response_code .')'; |
|
514 | + $errormsg .= "(HTTP Response: ".$resp->response_code.')'; |
|
515 | 515 | } |
516 | 516 | } |
517 | 517 | } |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | |
524 | 524 | // attempt to return cached object |
525 | 525 | if ($rss) { |
526 | - if ( MAGPIE_DEBUG ) { |
|
526 | + if (MAGPIE_DEBUG) { |
|
527 | 527 | debug("Returning STALE object for $url"); |
528 | 528 | } |
529 | 529 | return $rss; |
@@ -549,35 +549,35 @@ discard block |
||
549 | 549 | * @param array $headers Optional. Headers to send to the URL. |
550 | 550 | * @return Snoopy style response |
551 | 551 | */ |
552 | -function _fetch_remote_file($url, $headers = "" ) { |
|
553 | - $resp = wp_safe_remote_request( $url, array( 'headers' => $headers, 'timeout' => MAGPIE_FETCH_TIME_OUT ) ); |
|
554 | - if ( is_wp_error($resp) ) { |
|
552 | +function _fetch_remote_file($url, $headers = "") { |
|
553 | + $resp = wp_safe_remote_request($url, array('headers' => $headers, 'timeout' => MAGPIE_FETCH_TIME_OUT)); |
|
554 | + if (is_wp_error($resp)) { |
|
555 | 555 | $error = array_shift($resp->errors); |
556 | 556 | |
557 | 557 | $resp = new stdClass; |
558 | 558 | $resp->status = 500; |
559 | 559 | $resp->response_code = 500; |
560 | - $resp->error = $error[0] . "\n"; //\n = Snoopy compatibility |
|
560 | + $resp->error = $error[0]."\n"; //\n = Snoopy compatibility |
|
561 | 561 | return $resp; |
562 | 562 | } |
563 | 563 | |
564 | 564 | // Snoopy returns headers unprocessed. |
565 | 565 | // Also note, WP_HTTP lowercases all keys, Snoopy did not. |
566 | 566 | $return_headers = array(); |
567 | - foreach ( wp_remote_retrieve_headers( $resp ) as $key => $value ) { |
|
568 | - if ( !is_array($value) ) { |
|
567 | + foreach (wp_remote_retrieve_headers($resp) as $key => $value) { |
|
568 | + if ( ! is_array($value)) { |
|
569 | 569 | $return_headers[] = "$key: $value"; |
570 | 570 | } else { |
571 | - foreach ( $value as $v ) |
|
571 | + foreach ($value as $v) |
|
572 | 572 | $return_headers[] = "$key: $v"; |
573 | 573 | } |
574 | 574 | } |
575 | 575 | |
576 | 576 | $response = new stdClass; |
577 | - $response->status = wp_remote_retrieve_response_code( $resp ); |
|
578 | - $response->response_code = wp_remote_retrieve_response_code( $resp ); |
|
577 | + $response->status = wp_remote_retrieve_response_code($resp); |
|
578 | + $response->response_code = wp_remote_retrieve_response_code($resp); |
|
579 | 579 | $response->headers = $return_headers; |
580 | - $response->results = wp_remote_retrieve_body( $resp ); |
|
580 | + $response->results = wp_remote_retrieve_body($resp); |
|
581 | 581 | |
582 | 582 | return $response; |
583 | 583 | } |
@@ -592,14 +592,14 @@ discard block |
||
592 | 592 | * @param array $resp |
593 | 593 | * @return MagpieRSS|bool |
594 | 594 | */ |
595 | -function _response_to_rss ($resp) { |
|
596 | - $rss = new MagpieRSS( $resp->results ); |
|
595 | +function _response_to_rss($resp) { |
|
596 | + $rss = new MagpieRSS($resp->results); |
|
597 | 597 | |
598 | 598 | // if RSS parsed successfully |
599 | - if ( $rss && (!isset($rss->ERROR) || !$rss->ERROR) ) { |
|
599 | + if ($rss && ( ! isset($rss->ERROR) || ! $rss->ERROR)) { |
|
600 | 600 | |
601 | 601 | // find Etag, and Last-Modified |
602 | - foreach ( (array) $resp->headers as $h) { |
|
602 | + foreach ((array) $resp->headers as $h) { |
|
603 | 603 | // 2003-03-02 - Nicola Asuni (www.tecnick.com) - fixed bug "Undefined offset: 1" |
604 | 604 | if (strpos($h, ": ")) { |
605 | 605 | list($field, $val) = explode(": ", $h, 2); |
@@ -609,11 +609,11 @@ discard block |
||
609 | 609 | $val = ""; |
610 | 610 | } |
611 | 611 | |
612 | - if ( $field == 'etag' ) { |
|
612 | + if ($field == 'etag') { |
|
613 | 613 | $rss->etag = $val; |
614 | 614 | } |
615 | 615 | |
616 | - if ( $field == 'last-modified' ) { |
|
616 | + if ($field == 'last-modified') { |
|
617 | 617 | $rss->last_modified = $val; |
618 | 618 | } |
619 | 619 | } |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | $errormsg = "Failed to parse RSS file."; |
625 | 625 | |
626 | 626 | if ($rss) { |
627 | - $errormsg .= " (" . $rss->ERROR . ")"; |
|
627 | + $errormsg .= " (".$rss->ERROR.")"; |
|
628 | 628 | } |
629 | 629 | // error($errormsg); |
630 | 630 | |
@@ -639,95 +639,95 @@ discard block |
||
639 | 639 | * @package External |
640 | 640 | * @subpackage MagpieRSS |
641 | 641 | */ |
642 | -function init () { |
|
643 | - if ( defined('MAGPIE_INITALIZED') ) { |
|
642 | +function init() { |
|
643 | + if (defined('MAGPIE_INITALIZED')) { |
|
644 | 644 | return; |
645 | 645 | } |
646 | 646 | else { |
647 | 647 | define('MAGPIE_INITALIZED', 1); |
648 | 648 | } |
649 | 649 | |
650 | - if ( !defined('MAGPIE_CACHE_ON') ) { |
|
650 | + if ( ! defined('MAGPIE_CACHE_ON')) { |
|
651 | 651 | define('MAGPIE_CACHE_ON', 1); |
652 | 652 | } |
653 | 653 | |
654 | - if ( !defined('MAGPIE_CACHE_DIR') ) { |
|
654 | + if ( ! defined('MAGPIE_CACHE_DIR')) { |
|
655 | 655 | define('MAGPIE_CACHE_DIR', './cache'); |
656 | 656 | } |
657 | 657 | |
658 | - if ( !defined('MAGPIE_CACHE_AGE') ) { |
|
659 | - define('MAGPIE_CACHE_AGE', 60*60); // one hour |
|
658 | + if ( ! defined('MAGPIE_CACHE_AGE')) { |
|
659 | + define('MAGPIE_CACHE_AGE', 60 * 60); // one hour |
|
660 | 660 | } |
661 | 661 | |
662 | - if ( !defined('MAGPIE_CACHE_FRESH_ONLY') ) { |
|
662 | + if ( ! defined('MAGPIE_CACHE_FRESH_ONLY')) { |
|
663 | 663 | define('MAGPIE_CACHE_FRESH_ONLY', 0); |
664 | 664 | } |
665 | 665 | |
666 | - if ( !defined('MAGPIE_DEBUG') ) { |
|
666 | + if ( ! defined('MAGPIE_DEBUG')) { |
|
667 | 667 | define('MAGPIE_DEBUG', 0); |
668 | 668 | } |
669 | 669 | |
670 | - if ( !defined('MAGPIE_USER_AGENT') ) { |
|
671 | - $ua = 'WordPress/' . $GLOBALS['wp_version']; |
|
670 | + if ( ! defined('MAGPIE_USER_AGENT')) { |
|
671 | + $ua = 'WordPress/'.$GLOBALS['wp_version']; |
|
672 | 672 | |
673 | - if ( MAGPIE_CACHE_ON ) { |
|
674 | - $ua = $ua . ')'; |
|
673 | + if (MAGPIE_CACHE_ON) { |
|
674 | + $ua = $ua.')'; |
|
675 | 675 | } |
676 | 676 | else { |
677 | - $ua = $ua . '; No cache)'; |
|
677 | + $ua = $ua.'; No cache)'; |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | define('MAGPIE_USER_AGENT', $ua); |
681 | 681 | } |
682 | 682 | |
683 | - if ( !defined('MAGPIE_FETCH_TIME_OUT') ) { |
|
684 | - define('MAGPIE_FETCH_TIME_OUT', 2); // 2 second timeout |
|
683 | + if ( ! defined('MAGPIE_FETCH_TIME_OUT')) { |
|
684 | + define('MAGPIE_FETCH_TIME_OUT', 2); // 2 second timeout |
|
685 | 685 | } |
686 | 686 | |
687 | 687 | // use gzip encoding to fetch rss files if supported? |
688 | - if ( !defined('MAGPIE_USE_GZIP') ) { |
|
688 | + if ( ! defined('MAGPIE_USE_GZIP')) { |
|
689 | 689 | define('MAGPIE_USE_GZIP', true); |
690 | 690 | } |
691 | 691 | } |
692 | 692 | |
693 | -function is_info ($sc) { |
|
693 | +function is_info($sc) { |
|
694 | 694 | return $sc >= 100 && $sc < 200; |
695 | 695 | } |
696 | 696 | |
697 | -function is_success ($sc) { |
|
697 | +function is_success($sc) { |
|
698 | 698 | return $sc >= 200 && $sc < 300; |
699 | 699 | } |
700 | 700 | |
701 | -function is_redirect ($sc) { |
|
701 | +function is_redirect($sc) { |
|
702 | 702 | return $sc >= 300 && $sc < 400; |
703 | 703 | } |
704 | 704 | |
705 | -function is_error ($sc) { |
|
705 | +function is_error($sc) { |
|
706 | 706 | return $sc >= 400 && $sc < 600; |
707 | 707 | } |
708 | 708 | |
709 | -function is_client_error ($sc) { |
|
709 | +function is_client_error($sc) { |
|
710 | 710 | return $sc >= 400 && $sc < 500; |
711 | 711 | } |
712 | 712 | |
713 | -function is_server_error ($sc) { |
|
713 | +function is_server_error($sc) { |
|
714 | 714 | return $sc >= 500 && $sc < 600; |
715 | 715 | } |
716 | 716 | |
717 | 717 | class RSSCache { |
718 | - var $BASE_CACHE; // where the cache files are stored |
|
719 | - var $MAX_AGE = 43200; // when are files stale, default twelve hours |
|
720 | - var $ERROR = ''; // accumulate error messages |
|
718 | + var $BASE_CACHE; // where the cache files are stored |
|
719 | + var $MAX_AGE = 43200; // when are files stale, default twelve hours |
|
720 | + var $ERROR = ''; // accumulate error messages |
|
721 | 721 | |
722 | 722 | /** |
723 | 723 | * PHP5 constructor. |
724 | 724 | */ |
725 | - function __construct( $base = '', $age = '' ) { |
|
726 | - $this->BASE_CACHE = WP_CONTENT_DIR . '/cache'; |
|
727 | - if ( $base ) { |
|
725 | + function __construct($base = '', $age = '') { |
|
726 | + $this->BASE_CACHE = WP_CONTENT_DIR.'/cache'; |
|
727 | + if ($base) { |
|
728 | 728 | $this->BASE_CACHE = $base; |
729 | 729 | } |
730 | - if ( $age ) { |
|
730 | + if ($age) { |
|
731 | 731 | $this->MAX_AGE = $age; |
732 | 732 | } |
733 | 733 | |
@@ -736,8 +736,8 @@ discard block |
||
736 | 736 | /** |
737 | 737 | * PHP4 constructor. |
738 | 738 | */ |
739 | - public function RSSCache( $base = '', $age = '' ) { |
|
740 | - self::__construct( $base, $age ); |
|
739 | + public function RSSCache($base = '', $age = '') { |
|
740 | + self::__construct($base, $age); |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | /*=======================================================================*\ |
@@ -746,8 +746,8 @@ discard block |
||
746 | 746 | Input: url from wich the rss file was fetched |
747 | 747 | Output: true on success |
748 | 748 | \*=======================================================================*/ |
749 | - function set ($url, $rss) { |
|
750 | - $cache_option = 'rss_' . $this->file_name( $url ); |
|
749 | + function set($url, $rss) { |
|
750 | + $cache_option = 'rss_'.$this->file_name($url); |
|
751 | 751 | |
752 | 752 | set_transient($cache_option, $rss, $this->MAX_AGE); |
753 | 753 | |
@@ -760,11 +760,11 @@ discard block |
||
760 | 760 | Input: url from wich the rss file was fetched |
761 | 761 | Output: cached object on HIT, false on MISS |
762 | 762 | \*=======================================================================*/ |
763 | - function get ($url) { |
|
763 | + function get($url) { |
|
764 | 764 | $this->ERROR = ""; |
765 | - $cache_option = 'rss_' . $this->file_name( $url ); |
|
765 | + $cache_option = 'rss_'.$this->file_name($url); |
|
766 | 766 | |
767 | - if ( ! $rss = get_transient( $cache_option ) ) { |
|
767 | + if ( ! $rss = get_transient($cache_option)) { |
|
768 | 768 | $this->debug( |
769 | 769 | "Cache doesn't contain: $url (cache option: $cache_option)" |
770 | 770 | ); |
@@ -781,11 +781,11 @@ discard block |
||
781 | 781 | Input: url from wich the rss file was fetched |
782 | 782 | Output: cached object on HIT, false on MISS |
783 | 783 | \*=======================================================================*/ |
784 | - function check_cache ( $url ) { |
|
784 | + function check_cache($url) { |
|
785 | 785 | $this->ERROR = ""; |
786 | - $cache_option = 'rss_' . $this->file_name( $url ); |
|
786 | + $cache_option = 'rss_'.$this->file_name($url); |
|
787 | 787 | |
788 | - if ( get_transient($cache_option) ) { |
|
788 | + if (get_transient($cache_option)) { |
|
789 | 789 | // object exists and is current |
790 | 790 | return 'HIT'; |
791 | 791 | } else { |
@@ -797,15 +797,15 @@ discard block |
||
797 | 797 | /*=======================================================================*\ |
798 | 798 | Function: serialize |
799 | 799 | \*=======================================================================*/ |
800 | - function serialize ( $rss ) { |
|
801 | - return serialize( $rss ); |
|
800 | + function serialize($rss) { |
|
801 | + return serialize($rss); |
|
802 | 802 | } |
803 | 803 | |
804 | 804 | /*=======================================================================*\ |
805 | 805 | Function: unserialize |
806 | 806 | \*=======================================================================*/ |
807 | - function unserialize ( $data ) { |
|
808 | - return unserialize( $data ); |
|
807 | + function unserialize($data) { |
|
808 | + return unserialize($data); |
|
809 | 809 | } |
810 | 810 | |
811 | 811 | /*=======================================================================*\ |
@@ -814,64 +814,64 @@ discard block |
||
814 | 814 | Input: url from wich the rss file was fetched |
815 | 815 | Output: a file name |
816 | 816 | \*=======================================================================*/ |
817 | - function file_name ($url) { |
|
818 | - return md5( $url ); |
|
817 | + function file_name($url) { |
|
818 | + return md5($url); |
|
819 | 819 | } |
820 | 820 | |
821 | 821 | /*=======================================================================*\ |
822 | 822 | Function: error |
823 | 823 | Purpose: register error |
824 | 824 | \*=======================================================================*/ |
825 | - function error ($errormsg, $lvl=E_USER_WARNING) { |
|
825 | + function error($errormsg, $lvl = E_USER_WARNING) { |
|
826 | 826 | // append PHP's error message if track_errors enabled |
827 | - if ( isset($php_errormsg) ) { |
|
827 | + if (isset($php_errormsg)) { |
|
828 | 828 | $errormsg .= " ($php_errormsg)"; |
829 | 829 | } |
830 | 830 | $this->ERROR = $errormsg; |
831 | - if ( MAGPIE_DEBUG ) { |
|
832 | - trigger_error( $errormsg, $lvl); |
|
831 | + if (MAGPIE_DEBUG) { |
|
832 | + trigger_error($errormsg, $lvl); |
|
833 | 833 | } |
834 | 834 | else { |
835 | - error_log( $errormsg, 0); |
|
835 | + error_log($errormsg, 0); |
|
836 | 836 | } |
837 | 837 | } |
838 | - function debug ($debugmsg, $lvl=E_USER_NOTICE) { |
|
839 | - if ( MAGPIE_DEBUG ) { |
|
838 | + function debug($debugmsg, $lvl = E_USER_NOTICE) { |
|
839 | + if (MAGPIE_DEBUG) { |
|
840 | 840 | $this->error("MagpieRSS [debug] $debugmsg", $lvl); |
841 | 841 | } |
842 | 842 | } |
843 | 843 | } |
844 | 844 | |
845 | -if ( !function_exists('parse_w3cdtf') ) : |
|
846 | -function parse_w3cdtf ( $date_str ) { |
|
845 | +if ( ! function_exists('parse_w3cdtf')) : |
|
846 | +function parse_w3cdtf($date_str) { |
|
847 | 847 | |
848 | 848 | # regex to match wc3dtf |
849 | 849 | $pat = "/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; |
850 | 850 | |
851 | - if ( preg_match( $pat, $date_str, $match ) ) { |
|
852 | - list( $year, $month, $day, $hours, $minutes, $seconds) = |
|
853 | - array( $match[1], $match[2], $match[3], $match[4], $match[5], $match[7]); |
|
851 | + if (preg_match($pat, $date_str, $match)) { |
|
852 | + list($year, $month, $day, $hours, $minutes, $seconds) = |
|
853 | + array($match[1], $match[2], $match[3], $match[4], $match[5], $match[7]); |
|
854 | 854 | |
855 | 855 | # calc epoch for current date assuming GMT |
856 | - $epoch = gmmktime( $hours, $minutes, $seconds, $month, $day, $year); |
|
856 | + $epoch = gmmktime($hours, $minutes, $seconds, $month, $day, $year); |
|
857 | 857 | |
858 | 858 | $offset = 0; |
859 | - if ( $match[11] == 'Z' ) { |
|
859 | + if ($match[11] == 'Z') { |
|
860 | 860 | # zulu time, aka GMT |
861 | 861 | } |
862 | 862 | else { |
863 | - list( $tz_mod, $tz_hour, $tz_min ) = |
|
864 | - array( $match[8], $match[9], $match[10]); |
|
863 | + list($tz_mod, $tz_hour, $tz_min) = |
|
864 | + array($match[8], $match[9], $match[10]); |
|
865 | 865 | |
866 | 866 | # zero out the variables |
867 | - if ( ! $tz_hour ) { $tz_hour = 0; } |
|
868 | - if ( ! $tz_min ) { $tz_min = 0; } |
|
867 | + if ( ! $tz_hour) { $tz_hour = 0; } |
|
868 | + if ( ! $tz_min) { $tz_min = 0; } |
|
869 | 869 | |
870 | - $offset_secs = (($tz_hour*60)+$tz_min)*60; |
|
870 | + $offset_secs = (($tz_hour * 60) + $tz_min) * 60; |
|
871 | 871 | |
872 | 872 | # is timezone ahead of GMT? then subtract offset |
873 | 873 | # |
874 | - if ( $tz_mod == '+' ) { |
|
874 | + if ($tz_mod == '+') { |
|
875 | 875 | $offset_secs = $offset_secs * -1; |
876 | 876 | } |
877 | 877 | |
@@ -886,7 +886,7 @@ discard block |
||
886 | 886 | } |
887 | 887 | endif; |
888 | 888 | |
889 | -if ( !function_exists('wp_rss') ) : |
|
889 | +if ( ! function_exists('wp_rss')) : |
|
890 | 890 | /** |
891 | 891 | * Display all RSS items in a HTML ordered list. |
892 | 892 | * |
@@ -897,31 +897,31 @@ discard block |
||
897 | 897 | * @param string $url URL of feed to display. Will not auto sense feed URL. |
898 | 898 | * @param int $num_items Optional. Number of items to display, default is all. |
899 | 899 | */ |
900 | -function wp_rss( $url, $num_items = -1 ) { |
|
901 | - if ( $rss = fetch_rss( $url ) ) { |
|
900 | +function wp_rss($url, $num_items = -1) { |
|
901 | + if ($rss = fetch_rss($url)) { |
|
902 | 902 | echo '<ul>'; |
903 | 903 | |
904 | - if ( $num_items !== -1 ) { |
|
905 | - $rss->items = array_slice( $rss->items, 0, $num_items ); |
|
904 | + if ($num_items !== -1) { |
|
905 | + $rss->items = array_slice($rss->items, 0, $num_items); |
|
906 | 906 | } |
907 | 907 | |
908 | - foreach ( (array) $rss->items as $item ) { |
|
908 | + foreach ((array) $rss->items as $item) { |
|
909 | 909 | printf( |
910 | 910 | '<li><a href="%1$s" title="%2$s">%3$s</a></li>', |
911 | - esc_url( $item['link'] ), |
|
912 | - esc_attr( strip_tags( $item['description'] ) ), |
|
913 | - esc_html( $item['title'] ) |
|
911 | + esc_url($item['link']), |
|
912 | + esc_attr(strip_tags($item['description'])), |
|
913 | + esc_html($item['title']) |
|
914 | 914 | ); |
915 | 915 | } |
916 | 916 | |
917 | 917 | echo '</ul>'; |
918 | 918 | } else { |
919 | - _e( 'An error has occurred, which probably means the feed is down. Try again later.' ); |
|
919 | + _e('An error has occurred, which probably means the feed is down. Try again later.'); |
|
920 | 920 | } |
921 | 921 | } |
922 | 922 | endif; |
923 | 923 | |
924 | -if ( !function_exists('get_rss') ) : |
|
924 | +if ( ! function_exists('get_rss')) : |
|
925 | 925 | /** |
926 | 926 | * Display RSS items in HTML list items. |
927 | 927 | * |
@@ -938,11 +938,11 @@ discard block |
||
938 | 938 | * @param int $num_items Optional. Number of items to display, default is all. |
939 | 939 | * @return bool False on failure. |
940 | 940 | */ |
941 | -function get_rss ($url, $num_items = 5) { // Like get posts, but for RSS |
|
941 | +function get_rss($url, $num_items = 5) { // Like get posts, but for RSS |
|
942 | 942 | $rss = fetch_rss($url); |
943 | - if ( $rss ) { |
|
943 | + if ($rss) { |
|
944 | 944 | $rss->items = array_slice($rss->items, 0, $num_items); |
945 | - foreach ( (array) $rss->items as $item ) { |
|
945 | + foreach ((array) $rss->items as $item) { |
|
946 | 946 | echo "<li>\n"; |
947 | 947 | echo "<a href='$item[link]' title='$item[description]'>"; |
948 | 948 | echo esc_html($item['title']); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * Consume the next byte |
110 | 110 | * |
111 | 111 | * @access private |
112 | - * @return mixed The next byte, or false, if there is no more data |
|
112 | + * @return string|false The next byte, or false, if there is no more data |
|
113 | 113 | */ |
114 | 114 | public function consume() |
115 | 115 | { |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @access private |
131 | 131 | * @param string $chars Characters to consume |
132 | - * @return mixed A series of characters that match the range, or false |
|
132 | + * @return string|false A series of characters that match the range, or false |
|
133 | 133 | */ |
134 | 134 | public function consume_range($chars) |
135 | 135 | { |
@@ -215,7 +215,7 @@ |
||
215 | 215 | $replacement = SimplePie_Misc::codepoint_to_utf8($codepoint); |
216 | 216 | } |
217 | 217 | |
218 | - if (!in_array($this->consume(), array(';', false), true)) |
|
218 | + if ( ! in_array($this->consume(), array(';', false), true)) |
|
219 | 219 | { |
220 | 220 | $this->unconsume(); |
221 | 221 | } |
@@ -117,8 +117,7 @@ discard block |
||
117 | 117 | { |
118 | 118 | $this->consumed .= $this->data[$this->position]; |
119 | 119 | return $this->data[$this->position++]; |
120 | - } |
|
121 | - else |
|
120 | + } else |
|
122 | 121 | { |
123 | 122 | return false; |
124 | 123 | } |
@@ -139,8 +138,7 @@ discard block |
||
139 | 138 | $this->consumed .= $data; |
140 | 139 | $this->position += $len; |
141 | 140 | return $data; |
142 | - } |
|
143 | - else |
|
141 | + } else |
|
144 | 142 | { |
145 | 143 | return false; |
146 | 144 | } |
@@ -200,8 +198,7 @@ discard block |
||
200 | 198 | if ($hex) |
201 | 199 | { |
202 | 200 | $codepoint = hexdec($codepoint); |
203 | - } |
|
204 | - else |
|
201 | + } else |
|
205 | 202 | { |
206 | 203 | $codepoint = intval($codepoint); |
207 | 204 | } |
@@ -209,8 +206,7 @@ discard block |
||
209 | 206 | if (isset($windows_1252_specials[$codepoint])) |
210 | 207 | { |
211 | 208 | $replacement = $windows_1252_specials[$codepoint]; |
212 | - } |
|
213 | - else |
|
209 | + } else |
|
214 | 210 | { |
215 | 211 | $replacement = SimplePie_Misc::codepoint_to_utf8($codepoint); |
216 | 212 | } |
@@ -647,7 +647,7 @@ |
||
647 | 647 | /** |
648 | 648 | * Get length |
649 | 649 | * |
650 | - * @return float Length in bytes |
|
650 | + * @return string|null Length in bytes |
|
651 | 651 | */ |
652 | 652 | public function get_length() |
653 | 653 | { |
@@ -813,7 +813,7 @@ discard block |
||
813 | 813 | $length = $this->get_length(); |
814 | 814 | if ($length !== null) |
815 | 815 | { |
816 | - return round($length/1048576, 2); |
|
816 | + return round($length / 1048576, 2); |
|
817 | 817 | } |
818 | 818 | else |
819 | 819 | { |
@@ -917,7 +917,7 @@ discard block |
||
917 | 917 | * @param array|string $options See first paramter to {@see embed} |
918 | 918 | * @return string HTML string to output |
919 | 919 | */ |
920 | - public function native_embed($options='') |
|
920 | + public function native_embed($options = '') |
|
921 | 921 | { |
922 | 922 | return $this->embed($options, true); |
923 | 923 | } |
@@ -991,7 +991,7 @@ discard block |
||
991 | 991 | else |
992 | 992 | { |
993 | 993 | $options = explode(',', $options); |
994 | - foreach($options as $option) |
|
994 | + foreach ($options as $option) |
|
995 | 995 | { |
996 | 996 | $opt = explode(':', $option, 2); |
997 | 997 | if (isset($opt[0], $opt[1])) |
@@ -1058,11 +1058,11 @@ discard block |
||
1058 | 1058 | } |
1059 | 1059 | elseif ($widescreen) |
1060 | 1060 | { |
1061 | - $width = round((intval($height)/9)*16); |
|
1061 | + $width = round((intval($height) / 9) * 16); |
|
1062 | 1062 | } |
1063 | 1063 | else |
1064 | 1064 | { |
1065 | - $width = round((intval($height)/3)*4); |
|
1065 | + $width = round((intval($height) / 3) * 4); |
|
1066 | 1066 | } |
1067 | 1067 | } |
1068 | 1068 | else |
@@ -1092,11 +1092,11 @@ discard block |
||
1092 | 1092 | } |
1093 | 1093 | elseif ($widescreen) |
1094 | 1094 | { |
1095 | - $height = round((intval($width)/16)*9); |
|
1095 | + $height = round((intval($width) / 16) * 9); |
|
1096 | 1096 | } |
1097 | 1097 | else |
1098 | 1098 | { |
1099 | - $height = round((intval($width)/4)*3); |
|
1099 | + $height = round((intval($width) / 4) * 3); |
|
1100 | 1100 | } |
1101 | 1101 | } |
1102 | 1102 | else |
@@ -1126,11 +1126,11 @@ discard block |
||
1126 | 1126 | { |
1127 | 1127 | if ($native) |
1128 | 1128 | { |
1129 | - $embed .= "<embed src=\"" . $this->get_link() . "\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"$type\" quality=\"high\" width=\"$width\" height=\"$height\" bgcolor=\"$bgcolor\" loop=\"$loop\"></embed>"; |
|
1129 | + $embed .= "<embed src=\"".$this->get_link()."\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"$type\" quality=\"high\" width=\"$width\" height=\"$height\" bgcolor=\"$bgcolor\" loop=\"$loop\"></embed>"; |
|
1130 | 1130 | } |
1131 | 1131 | else |
1132 | 1132 | { |
1133 | - $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>"; |
|
1133 | + $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '".$this->get_link()."', '$loop', '$type');</script>"; |
|
1134 | 1134 | } |
1135 | 1135 | } |
1136 | 1136 | |
@@ -1141,11 +1141,11 @@ discard block |
||
1141 | 1141 | $height += 20; |
1142 | 1142 | if ($native) |
1143 | 1143 | { |
1144 | - $embed .= "<embed src=\"$mediaplayer\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" quality=\"high\" width=\"$width\" height=\"$height\" wmode=\"transparent\" flashvars=\"file=" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "&autostart=false&repeat=$loop&showdigits=true&showfsbutton=false\"></embed>"; |
|
1144 | + $embed .= "<embed src=\"$mediaplayer\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" quality=\"high\" width=\"$width\" height=\"$height\" wmode=\"transparent\" flashvars=\"file=".rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension())."&autostart=false&repeat=$loop&showdigits=true&showfsbutton=false\"></embed>"; |
|
1145 | 1145 | } |
1146 | 1146 | else |
1147 | 1147 | { |
1148 | - $embed .= "<script type='text/javascript'>embed_flv('$width', '$height', '" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "', '$placeholder', '$loop', '$mediaplayer');</script>"; |
|
1148 | + $embed .= "<script type='text/javascript'>embed_flv('$width', '$height', '".rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension())."', '$placeholder', '$loop', '$mediaplayer');</script>"; |
|
1149 | 1149 | } |
1150 | 1150 | } |
1151 | 1151 | |
@@ -1158,16 +1158,16 @@ discard block |
||
1158 | 1158 | { |
1159 | 1159 | if ($placeholder !== '') |
1160 | 1160 | { |
1161 | - $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" href=\"" . $this->get_link() . "\" src=\"$placeholder\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"false\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>"; |
|
1161 | + $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" href=\"".$this->get_link()."\" src=\"$placeholder\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"false\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>"; |
|
1162 | 1162 | } |
1163 | 1163 | else |
1164 | 1164 | { |
1165 | - $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" src=\"" . $this->get_link() . "\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"true\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>"; |
|
1165 | + $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" src=\"".$this->get_link()."\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"true\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>"; |
|
1166 | 1166 | } |
1167 | 1167 | } |
1168 | 1168 | else |
1169 | 1169 | { |
1170 | - $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>"; |
|
1170 | + $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '".$this->get_link()."', '$placeholder', '$loop');</script>"; |
|
1171 | 1171 | } |
1172 | 1172 | } |
1173 | 1173 | |
@@ -1177,16 +1177,16 @@ discard block |
||
1177 | 1177 | $height += 45; |
1178 | 1178 | if ($native) |
1179 | 1179 | { |
1180 | - $embed .= "<embed type=\"application/x-mplayer2\" src=\"" . $this->get_link() . "\" autosize=\"1\" width=\"$width\" height=\"$height\" showcontrols=\"1\" showstatusbar=\"0\" showdisplay=\"0\" autostart=\"0\"></embed>"; |
|
1180 | + $embed .= "<embed type=\"application/x-mplayer2\" src=\"".$this->get_link()."\" autosize=\"1\" width=\"$width\" height=\"$height\" showcontrols=\"1\" showstatusbar=\"0\" showdisplay=\"0\" autostart=\"0\"></embed>"; |
|
1181 | 1181 | } |
1182 | 1182 | else |
1183 | 1183 | { |
1184 | - $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>"; |
|
1184 | + $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '".$this->get_link()."');</script>"; |
|
1185 | 1185 | } |
1186 | 1186 | } |
1187 | 1187 | |
1188 | 1188 | // Everything else |
1189 | - else $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>'; |
|
1189 | + else $embed .= '<a href="'.$this->get_link().'" class="'.$altclass.'">'.$alt.'</a>'; |
|
1190 | 1190 | |
1191 | 1191 | return $embed; |
1192 | 1192 | } |
@@ -1206,7 +1206,7 @@ discard block |
||
1206 | 1206 | { |
1207 | 1207 | // Mime-types by handler. |
1208 | 1208 | $types_flash = array('application/x-shockwave-flash', 'application/futuresplash'); // Flash |
1209 | - $types_fmedia = array('video/flv', 'video/x-flv','flv-application/octet-stream'); // Flash Media Player |
|
1209 | + $types_fmedia = array('video/flv', 'video/x-flv', 'flv-application/octet-stream'); // Flash Media Player |
|
1210 | 1210 | $types_quicktime = array('audio/3gpp', 'audio/3gpp2', 'audio/aac', 'audio/x-aac', 'audio/aiff', 'audio/x-aiff', 'audio/mid', 'audio/midi', 'audio/x-midi', 'audio/mp4', 'audio/m4a', 'audio/x-m4a', 'audio/wav', 'audio/x-wav', 'video/3gpp', 'video/3gpp2', 'video/m4v', 'video/x-m4v', 'video/mp4', 'video/mpeg', 'video/x-mpeg', 'video/quicktime', 'video/sd-video'); // QuickTime |
1211 | 1211 | $types_wmedia = array('application/asx', 'application/x-mplayer2', 'audio/x-ms-wma', 'audio/x-ms-wax', 'video/x-ms-asf-plugin', 'video/x-ms-asf', 'video/x-ms-wm', 'video/x-ms-wmv', 'video/x-ms-wvx'); // Windows Media |
1212 | 1212 | $types_mp3 = array('audio/mp3', 'audio/x-mp3', 'audio/mpeg', 'audio/x-mpeg'); // MP3 |
@@ -1221,7 +1221,7 @@ discard block |
||
1221 | 1221 | } |
1222 | 1222 | |
1223 | 1223 | // If we encounter an unsupported mime-type, check the file extension and guess intelligently. |
1224 | - if (!in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3))) |
|
1224 | + if ( ! in_array($type, array_merge($types_flash, $types_fmedia, $types_quicktime, $types_wmedia, $types_mp3))) |
|
1225 | 1225 | { |
1226 | 1226 | switch (strtolower($this->get_extension())) |
1227 | 1227 | { |
@@ -282,8 +282,7 @@ discard block |
||
282 | 282 | if ($this->bitrate !== null) |
283 | 283 | { |
284 | 284 | return $this->bitrate; |
285 | - } |
|
286 | - else |
|
285 | + } else |
|
287 | 286 | { |
288 | 287 | return null; |
289 | 288 | } |
@@ -301,8 +300,7 @@ discard block |
||
301 | 300 | if (isset($captions[$key])) |
302 | 301 | { |
303 | 302 | return $captions[$key]; |
304 | - } |
|
305 | - else |
|
303 | + } else |
|
306 | 304 | { |
307 | 305 | return null; |
308 | 306 | } |
@@ -318,8 +316,7 @@ discard block |
||
318 | 316 | if ($this->captions !== null) |
319 | 317 | { |
320 | 318 | return $this->captions; |
321 | - } |
|
322 | - else |
|
319 | + } else |
|
323 | 320 | { |
324 | 321 | return null; |
325 | 322 | } |
@@ -337,8 +334,7 @@ discard block |
||
337 | 334 | if (isset($categories[$key])) |
338 | 335 | { |
339 | 336 | return $categories[$key]; |
340 | - } |
|
341 | - else |
|
337 | + } else |
|
342 | 338 | { |
343 | 339 | return null; |
344 | 340 | } |
@@ -354,8 +350,7 @@ discard block |
||
354 | 350 | if ($this->categories !== null) |
355 | 351 | { |
356 | 352 | return $this->categories; |
357 | - } |
|
358 | - else |
|
353 | + } else |
|
359 | 354 | { |
360 | 355 | return null; |
361 | 356 | } |
@@ -371,8 +366,7 @@ discard block |
||
371 | 366 | if ($this->channels !== null) |
372 | 367 | { |
373 | 368 | return $this->channels; |
374 | - } |
|
375 | - else |
|
369 | + } else |
|
376 | 370 | { |
377 | 371 | return null; |
378 | 372 | } |
@@ -388,8 +382,7 @@ discard block |
||
388 | 382 | if ($this->copyright !== null) |
389 | 383 | { |
390 | 384 | return $this->copyright; |
391 | - } |
|
392 | - else |
|
385 | + } else |
|
393 | 386 | { |
394 | 387 | return null; |
395 | 388 | } |
@@ -407,8 +400,7 @@ discard block |
||
407 | 400 | if (isset($credits[$key])) |
408 | 401 | { |
409 | 402 | return $credits[$key]; |
410 | - } |
|
411 | - else |
|
403 | + } else |
|
412 | 404 | { |
413 | 405 | return null; |
414 | 406 | } |
@@ -424,8 +416,7 @@ discard block |
||
424 | 416 | if ($this->credits !== null) |
425 | 417 | { |
426 | 418 | return $this->credits; |
427 | - } |
|
428 | - else |
|
419 | + } else |
|
429 | 420 | { |
430 | 421 | return null; |
431 | 422 | } |
@@ -441,8 +432,7 @@ discard block |
||
441 | 432 | if ($this->description !== null) |
442 | 433 | { |
443 | 434 | return $this->description; |
444 | - } |
|
445 | - else |
|
435 | + } else |
|
446 | 436 | { |
447 | 437 | return null; |
448 | 438 | } |
@@ -462,13 +452,11 @@ discard block |
||
462 | 452 | { |
463 | 453 | $time = SimplePie_Misc::time_hms($this->duration); |
464 | 454 | return $time; |
465 | - } |
|
466 | - else |
|
455 | + } else |
|
467 | 456 | { |
468 | 457 | return $this->duration; |
469 | 458 | } |
470 | - } |
|
471 | - else |
|
459 | + } else |
|
472 | 460 | { |
473 | 461 | return null; |
474 | 462 | } |
@@ -484,8 +472,7 @@ discard block |
||
484 | 472 | if ($this->expression !== null) |
485 | 473 | { |
486 | 474 | return $this->expression; |
487 | - } |
|
488 | - else |
|
475 | + } else |
|
489 | 476 | { |
490 | 477 | return 'full'; |
491 | 478 | } |
@@ -519,8 +506,7 @@ discard block |
||
519 | 506 | if ($this->framerate !== null) |
520 | 507 | { |
521 | 508 | return $this->framerate; |
522 | - } |
|
523 | - else |
|
509 | + } else |
|
524 | 510 | { |
525 | 511 | return null; |
526 | 512 | } |
@@ -549,8 +535,7 @@ discard block |
||
549 | 535 | if (isset($hashes[$key])) |
550 | 536 | { |
551 | 537 | return $hashes[$key]; |
552 | - } |
|
553 | - else |
|
538 | + } else |
|
554 | 539 | { |
555 | 540 | return null; |
556 | 541 | } |
@@ -566,8 +551,7 @@ discard block |
||
566 | 551 | if ($this->hashes !== null) |
567 | 552 | { |
568 | 553 | return $this->hashes; |
569 | - } |
|
570 | - else |
|
554 | + } else |
|
571 | 555 | { |
572 | 556 | return null; |
573 | 557 | } |
@@ -583,8 +567,7 @@ discard block |
||
583 | 567 | if ($this->height !== null) |
584 | 568 | { |
585 | 569 | return $this->height; |
586 | - } |
|
587 | - else |
|
570 | + } else |
|
588 | 571 | { |
589 | 572 | return null; |
590 | 573 | } |
@@ -601,8 +584,7 @@ discard block |
||
601 | 584 | if ($this->lang !== null) |
602 | 585 | { |
603 | 586 | return $this->lang; |
604 | - } |
|
605 | - else |
|
587 | + } else |
|
606 | 588 | { |
607 | 589 | return null; |
608 | 590 | } |
@@ -620,8 +602,7 @@ discard block |
||
620 | 602 | if (isset($keywords[$key])) |
621 | 603 | { |
622 | 604 | return $keywords[$key]; |
623 | - } |
|
624 | - else |
|
605 | + } else |
|
625 | 606 | { |
626 | 607 | return null; |
627 | 608 | } |
@@ -637,8 +618,7 @@ discard block |
||
637 | 618 | if ($this->keywords !== null) |
638 | 619 | { |
639 | 620 | return $this->keywords; |
640 | - } |
|
641 | - else |
|
621 | + } else |
|
642 | 622 | { |
643 | 623 | return null; |
644 | 624 | } |
@@ -654,8 +634,7 @@ discard block |
||
654 | 634 | if ($this->length !== null) |
655 | 635 | { |
656 | 636 | return $this->length; |
657 | - } |
|
658 | - else |
|
637 | + } else |
|
659 | 638 | { |
660 | 639 | return null; |
661 | 640 | } |
@@ -671,8 +650,7 @@ discard block |
||
671 | 650 | if ($this->link !== null) |
672 | 651 | { |
673 | 652 | return urldecode($this->link); |
674 | - } |
|
675 | - else |
|
653 | + } else |
|
676 | 654 | { |
677 | 655 | return null; |
678 | 656 | } |
@@ -689,8 +667,7 @@ discard block |
||
689 | 667 | if ($this->medium !== null) |
690 | 668 | { |
691 | 669 | return $this->medium; |
692 | - } |
|
693 | - else |
|
670 | + } else |
|
694 | 671 | { |
695 | 672 | return null; |
696 | 673 | } |
@@ -707,8 +684,7 @@ discard block |
||
707 | 684 | if ($this->player !== null) |
708 | 685 | { |
709 | 686 | return $this->player; |
710 | - } |
|
711 | - else |
|
687 | + } else |
|
712 | 688 | { |
713 | 689 | return null; |
714 | 690 | } |
@@ -726,8 +702,7 @@ discard block |
||
726 | 702 | if (isset($ratings[$key])) |
727 | 703 | { |
728 | 704 | return $ratings[$key]; |
729 | - } |
|
730 | - else |
|
705 | + } else |
|
731 | 706 | { |
732 | 707 | return null; |
733 | 708 | } |
@@ -743,8 +718,7 @@ discard block |
||
743 | 718 | if ($this->ratings !== null) |
744 | 719 | { |
745 | 720 | return $this->ratings; |
746 | - } |
|
747 | - else |
|
721 | + } else |
|
748 | 722 | { |
749 | 723 | return null; |
750 | 724 | } |
@@ -762,8 +736,7 @@ discard block |
||
762 | 736 | if (isset($restrictions[$key])) |
763 | 737 | { |
764 | 738 | return $restrictions[$key]; |
765 | - } |
|
766 | - else |
|
739 | + } else |
|
767 | 740 | { |
768 | 741 | return null; |
769 | 742 | } |
@@ -779,8 +752,7 @@ discard block |
||
779 | 752 | if ($this->restrictions !== null) |
780 | 753 | { |
781 | 754 | return $this->restrictions; |
782 | - } |
|
783 | - else |
|
755 | + } else |
|
784 | 756 | { |
785 | 757 | return null; |
786 | 758 | } |
@@ -796,8 +768,7 @@ discard block |
||
796 | 768 | if ($this->samplingrate !== null) |
797 | 769 | { |
798 | 770 | return $this->samplingrate; |
799 | - } |
|
800 | - else |
|
771 | + } else |
|
801 | 772 | { |
802 | 773 | return null; |
803 | 774 | } |
@@ -814,8 +785,7 @@ discard block |
||
814 | 785 | if ($length !== null) |
815 | 786 | { |
816 | 787 | return round($length/1048576, 2); |
817 | - } |
|
818 | - else |
|
788 | + } else |
|
819 | 789 | { |
820 | 790 | return null; |
821 | 791 | } |
@@ -833,8 +803,7 @@ discard block |
||
833 | 803 | if (isset($thumbnails[$key])) |
834 | 804 | { |
835 | 805 | return $thumbnails[$key]; |
836 | - } |
|
837 | - else |
|
806 | + } else |
|
838 | 807 | { |
839 | 808 | return null; |
840 | 809 | } |
@@ -850,8 +819,7 @@ discard block |
||
850 | 819 | if ($this->thumbnails !== null) |
851 | 820 | { |
852 | 821 | return $this->thumbnails; |
853 | - } |
|
854 | - else |
|
822 | + } else |
|
855 | 823 | { |
856 | 824 | return null; |
857 | 825 | } |
@@ -867,8 +835,7 @@ discard block |
||
867 | 835 | if ($this->title !== null) |
868 | 836 | { |
869 | 837 | return $this->title; |
870 | - } |
|
871 | - else |
|
838 | + } else |
|
872 | 839 | { |
873 | 840 | return null; |
874 | 841 | } |
@@ -885,8 +852,7 @@ discard block |
||
885 | 852 | if ($this->type !== null) |
886 | 853 | { |
887 | 854 | return $this->type; |
888 | - } |
|
889 | - else |
|
855 | + } else |
|
890 | 856 | { |
891 | 857 | return null; |
892 | 858 | } |
@@ -902,8 +868,7 @@ discard block |
||
902 | 868 | if ($this->width !== null) |
903 | 869 | { |
904 | 870 | return $this->width; |
905 | - } |
|
906 | - else |
|
871 | + } else |
|
907 | 872 | { |
908 | 873 | return null; |
909 | 874 | } |
@@ -987,8 +952,7 @@ discard block |
||
987 | 952 | if (is_array($options)) |
988 | 953 | { |
989 | 954 | extract($options); |
990 | - } |
|
991 | - else |
|
955 | + } else |
|
992 | 956 | { |
993 | 957 | $options = explode(',', $options); |
994 | 958 | foreach($options as $option) |
@@ -1055,17 +1019,14 @@ discard block |
||
1055 | 1019 | if ($height === 'auto') |
1056 | 1020 | { |
1057 | 1021 | $width = 480; |
1058 | - } |
|
1059 | - elseif ($widescreen) |
|
1022 | + } elseif ($widescreen) |
|
1060 | 1023 | { |
1061 | 1024 | $width = round((intval($height)/9)*16); |
1062 | - } |
|
1063 | - else |
|
1025 | + } else |
|
1064 | 1026 | { |
1065 | 1027 | $width = round((intval($height)/3)*4); |
1066 | 1028 | } |
1067 | - } |
|
1068 | - else |
|
1029 | + } else |
|
1069 | 1030 | { |
1070 | 1031 | $width = '100%'; |
1071 | 1032 | } |
@@ -1076,35 +1037,29 @@ discard block |
||
1076 | 1037 | if ($mime === 'audio') |
1077 | 1038 | { |
1078 | 1039 | $height = 0; |
1079 | - } |
|
1080 | - elseif ($mime === 'video') |
|
1040 | + } elseif ($mime === 'video') |
|
1081 | 1041 | { |
1082 | 1042 | if ($width === 'auto') |
1083 | 1043 | { |
1084 | 1044 | if ($widescreen) |
1085 | 1045 | { |
1086 | 1046 | $height = 270; |
1087 | - } |
|
1088 | - else |
|
1047 | + } else |
|
1089 | 1048 | { |
1090 | 1049 | $height = 360; |
1091 | 1050 | } |
1092 | - } |
|
1093 | - elseif ($widescreen) |
|
1051 | + } elseif ($widescreen) |
|
1094 | 1052 | { |
1095 | 1053 | $height = round((intval($width)/16)*9); |
1096 | - } |
|
1097 | - else |
|
1054 | + } else |
|
1098 | 1055 | { |
1099 | 1056 | $height = round((intval($width)/4)*3); |
1100 | 1057 | } |
1101 | - } |
|
1102 | - else |
|
1058 | + } else |
|
1103 | 1059 | { |
1104 | 1060 | $height = 376; |
1105 | 1061 | } |
1106 | - } |
|
1107 | - elseif ($mime === 'audio') |
|
1062 | + } elseif ($mime === 'audio') |
|
1108 | 1063 | { |
1109 | 1064 | $height = 0; |
1110 | 1065 | } |
@@ -1113,8 +1068,7 @@ discard block |
||
1113 | 1068 | if ($mime === 'audio') |
1114 | 1069 | { |
1115 | 1070 | $placeholder = $audio; |
1116 | - } |
|
1117 | - elseif ($mime === 'video') |
|
1071 | + } elseif ($mime === 'video') |
|
1118 | 1072 | { |
1119 | 1073 | $placeholder = $video; |
1120 | 1074 | } |
@@ -1127,8 +1081,7 @@ discard block |
||
1127 | 1081 | if ($native) |
1128 | 1082 | { |
1129 | 1083 | $embed .= "<embed src=\"" . $this->get_link() . "\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"$type\" quality=\"high\" width=\"$width\" height=\"$height\" bgcolor=\"$bgcolor\" loop=\"$loop\"></embed>"; |
1130 | - } |
|
1131 | - else |
|
1084 | + } else |
|
1132 | 1085 | { |
1133 | 1086 | $embed .= "<script type='text/javascript'>embed_flash('$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$loop', '$type');</script>"; |
1134 | 1087 | } |
@@ -1142,8 +1095,7 @@ discard block |
||
1142 | 1095 | if ($native) |
1143 | 1096 | { |
1144 | 1097 | $embed .= "<embed src=\"$mediaplayer\" pluginspage=\"http://adobe.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" quality=\"high\" width=\"$width\" height=\"$height\" wmode=\"transparent\" flashvars=\"file=" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "&autostart=false&repeat=$loop&showdigits=true&showfsbutton=false\"></embed>"; |
1145 | - } |
|
1146 | - else |
|
1098 | + } else |
|
1147 | 1099 | { |
1148 | 1100 | $embed .= "<script type='text/javascript'>embed_flv('$width', '$height', '" . rawurlencode($this->get_link().'?file_extension=.'.$this->get_extension()) . "', '$placeholder', '$loop', '$mediaplayer');</script>"; |
1149 | 1101 | } |
@@ -1159,13 +1111,11 @@ discard block |
||
1159 | 1111 | if ($placeholder !== '') |
1160 | 1112 | { |
1161 | 1113 | $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" href=\"" . $this->get_link() . "\" src=\"$placeholder\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"false\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>"; |
1162 | - } |
|
1163 | - else |
|
1114 | + } else |
|
1164 | 1115 | { |
1165 | 1116 | $embed .= "<embed type=\"$type\" style=\"cursor:hand; cursor:pointer;\" src=\"" . $this->get_link() . "\" width=\"$width\" height=\"$height\" autoplay=\"false\" target=\"myself\" controller=\"true\" loop=\"$loop\" scale=\"aspect\" bgcolor=\"$bgcolor\" pluginspage=\"http://apple.com/quicktime/download/\"></embed>"; |
1166 | 1117 | } |
1167 | - } |
|
1168 | - else |
|
1118 | + } else |
|
1169 | 1119 | { |
1170 | 1120 | $embed .= "<script type='text/javascript'>embed_quicktime('$type', '$bgcolor', '$width', '$height', '" . $this->get_link() . "', '$placeholder', '$loop');</script>"; |
1171 | 1121 | } |
@@ -1178,15 +1128,16 @@ discard block |
||
1178 | 1128 | if ($native) |
1179 | 1129 | { |
1180 | 1130 | $embed .= "<embed type=\"application/x-mplayer2\" src=\"" . $this->get_link() . "\" autosize=\"1\" width=\"$width\" height=\"$height\" showcontrols=\"1\" showstatusbar=\"0\" showdisplay=\"0\" autostart=\"0\"></embed>"; |
1181 | - } |
|
1182 | - else |
|
1131 | + } else |
|
1183 | 1132 | { |
1184 | 1133 | $embed .= "<script type='text/javascript'>embed_wmedia('$width', '$height', '" . $this->get_link() . "');</script>"; |
1185 | 1134 | } |
1186 | 1135 | } |
1187 | 1136 | |
1188 | 1137 | // Everything else |
1189 | - else $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>'; |
|
1138 | + else { |
|
1139 | + $embed .= '<a href="' . $this->get_link() . '" class="' . $altclass . '">' . $alt . '</a>'; |
|
1140 | + } |
|
1190 | 1141 | |
1191 | 1142 | return $embed; |
1192 | 1143 | } |
@@ -1214,8 +1165,7 @@ discard block |
||
1214 | 1165 | if ($this->get_type() !== null) |
1215 | 1166 | { |
1216 | 1167 | $type = strtolower($this->type); |
1217 | - } |
|
1218 | - else |
|
1168 | + } else |
|
1219 | 1169 | { |
1220 | 1170 | $type = null; |
1221 | 1171 | } |
@@ -1349,29 +1299,23 @@ discard block |
||
1349 | 1299 | if (in_array($type, $types_flash)) |
1350 | 1300 | { |
1351 | 1301 | return 'flash'; |
1352 | - } |
|
1353 | - elseif (in_array($type, $types_fmedia)) |
|
1302 | + } elseif (in_array($type, $types_fmedia)) |
|
1354 | 1303 | { |
1355 | 1304 | return 'fmedia'; |
1356 | - } |
|
1357 | - elseif (in_array($type, $types_quicktime)) |
|
1305 | + } elseif (in_array($type, $types_quicktime)) |
|
1358 | 1306 | { |
1359 | 1307 | return 'quicktime'; |
1360 | - } |
|
1361 | - elseif (in_array($type, $types_wmedia)) |
|
1308 | + } elseif (in_array($type, $types_wmedia)) |
|
1362 | 1309 | { |
1363 | 1310 | return 'wmedia'; |
1364 | - } |
|
1365 | - elseif (in_array($type, $types_mp3)) |
|
1311 | + } elseif (in_array($type, $types_mp3)) |
|
1366 | 1312 | { |
1367 | 1313 | return 'mp3'; |
1368 | - } |
|
1369 | - else |
|
1314 | + } else |
|
1370 | 1315 | { |
1371 | 1316 | return null; |
1372 | 1317 | } |
1373 | - } |
|
1374 | - else |
|
1318 | + } else |
|
1375 | 1319 | { |
1376 | 1320 | return $type; |
1377 | 1321 | } |