]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/ms-blogs.php
Wordpress 3.3.1-scripts
[autoinstalls/wordpress.git] / wp-includes / ms-blogs.php
1 <?php
2
3 /**
4  * Site/blog functions that work with the blogs table and related data.
5  *
6  * @package WordPress
7  * @subpackage Multisite
8  * @since MU
9  */
10
11 /**
12  * Update the last_updated field for the current blog.
13  *
14  * @since MU
15  */
16 function wpmu_update_blogs_date() {
17         global $wpdb;
18
19         update_blog_details( $wpdb->blogid, array('last_updated' => current_time('mysql', true)) );
20
21         do_action( 'wpmu_blog_updated', $wpdb->blogid );
22 }
23
24 /**
25  * Get a full blog URL, given a blog id.
26  *
27  * @since MU
28  *
29  * @param int $blog_id Blog ID
30  * @return string
31  */
32 function get_blogaddress_by_id( $blog_id ) {
33         $bloginfo = get_blog_details( (int) $blog_id, false ); // only get bare details!
34         return esc_url( 'http://' . $bloginfo->domain . $bloginfo->path );
35 }
36
37 /**
38  * Get a full blog URL, given a blog name.
39  *
40  * @since MU
41  *
42  * @param string $blogname The (subdomain or directory) name
43  * @return string
44  */
45 function get_blogaddress_by_name( $blogname ) {
46         global $current_site;
47
48         if ( is_subdomain_install() ) {
49                 if ( $blogname == 'main' )
50                         $blogname = 'www';
51                 $url = rtrim( network_home_url(), '/' );
52                 if ( !empty( $blogname ) )
53                         $url = preg_replace( '|^([^\.]+://)|', '$1' . $blogname . '.', $url );
54         } else {
55                 $url = network_home_url( $blogname );
56         }
57         return esc_url( $url . '/' );
58 }
59
60 /**
61  * Get a full blog URL, given a domain and a path.
62  *
63  * @since MU
64  *
65  * @param string $domain
66  * @param string $path
67  * @return string
68  */
69 function get_blogaddress_by_domain( $domain, $path ) {
70         if ( is_subdomain_install() ) {
71                 $url = "http://" . $domain.$path;
72         } else {
73                 if ( $domain != $_SERVER['HTTP_HOST'] ) {
74                         $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
75                         $url = 'http://' . substr( $domain, strpos( $domain, '.' ) + 1 ) . $path;
76                         // we're not installing the main blog
77                         if ( $blogname != 'www.' )
78                                 $url .= $blogname . '/';
79                 } else { // main blog
80                         $url = 'http://' . $domain . $path;
81                 }
82         }
83         return esc_url( $url );
84 }
85
86 /**
87  * Given a blog's (subdomain or directory) name, retrieve it's id.
88  *
89  * @since MU
90  *
91  * @param string $name
92  * @return int A blog id
93  */
94 function get_id_from_blogname( $name ) {
95         global $wpdb, $current_site;
96         $blog_id = wp_cache_get( 'get_id_from_blogname_' . $name, 'blog-details' );
97         if ( $blog_id )
98                 return $blog_id;
99
100         if ( is_subdomain_install() ) {
101                 $domain = $name . '.' . $current_site->domain;
102                 $path = $current_site->path;
103         } else {
104                 $domain = $current_site->domain;
105                 $path = $current_site->path . $name . '/';
106         }
107         $blog_id = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s", $domain, $path) );
108         wp_cache_set( 'get_id_from_blogname_' . $name, $blog_id, 'blog-details' );
109         return $blog_id;
110 }
111
112 /**
113  * Retrieve the details for a blog from the blogs table and blog options.
114  *
115  * @since MU
116  *
117  * @param int|string|array $fields A blog ID, a blog name, or an array of fields to query against.
118  * @param bool $get_all Whether to retrieve all details or only the details in the blogs table. Default is true.
119  * @return object Blog details.
120  */
121 function get_blog_details( $fields, $get_all = true ) {
122         global $wpdb;
123
124         if ( is_array($fields ) ) {
125                 if ( isset($fields['blog_id']) ) {
126                         $blog_id = $fields['blog_id'];
127                 } elseif ( isset($fields['domain']) && isset($fields['path']) ) {
128                         $key = md5( $fields['domain'] . $fields['path'] );
129                         $blog = wp_cache_get($key, 'blog-lookup');
130                         if ( false !== $blog )
131                                 return $blog;
132                         if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {
133                                 $nowww = substr( $fields['domain'], 4 );
134                                 $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'] ) );
135                         } else {
136                                 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) );
137                         }
138                         if ( $blog ) {
139                                 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');
140                                 $blog_id = $blog->blog_id;
141                         } else {
142                                 return false;
143                         }
144                 } elseif ( isset($fields['domain']) && is_subdomain_install() ) {
145                         $key = md5( $fields['domain'] );
146                         $blog = wp_cache_get($key, 'blog-lookup');
147                         if ( false !== $blog )
148                                 return $blog;
149                         if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {
150                                 $nowww = substr( $fields['domain'], 4 );
151                                 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) );
152                         } else {
153                                 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) );
154                         }
155                         if ( $blog ) {
156                                 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');
157                                 $blog_id = $blog->blog_id;
158                         } else {
159                                 return false;
160                         }
161                 } else {
162                         return false;
163                 }
164         } else {
165                 if ( !is_numeric( $fields ) )
166                         $blog_id = get_id_from_blogname( $fields );
167                 else
168                         $blog_id = $fields;
169         }
170
171         $blog_id = (int) $blog_id;
172
173         $all = $get_all == true ? '' : 'short';
174         $details = wp_cache_get( $blog_id . $all, 'blog-details' );
175
176         if ( $details ) {
177                 if ( ! is_object( $details ) ) {
178                         if ( $details == -1 ) {
179                                 return false;
180                         } else {
181                                 // Clear old pre-serialized objects. Cache clients do better with that.
182                                 wp_cache_delete( $blog_id . $all, 'blog-details' );
183                                 unset($details);
184                         }
185                 } else {
186                         return $details;
187                 }
188         }
189
190         // Try the other cache.
191         if ( $get_all ) {
192                 $details = wp_cache_get( $blog_id . 'short', 'blog-details' );
193         } else {
194                 $details = wp_cache_get( $blog_id, 'blog-details' );
195                 // If short was requested and full cache is set, we can return.
196                 if ( $details ) {
197                         if ( ! is_object( $details ) ) {
198                                 if ( $details == -1 ) {
199                                         return false;
200                                 } else {
201                                         // Clear old pre-serialized objects. Cache clients do better with that.
202                                         wp_cache_delete( $blog_id, 'blog-details' );
203                                         unset($details);
204                                 }
205                         } else {
206                                 return $details;
207                         }
208                 }
209         }
210
211         if ( empty($details) ) {
212                 $details = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE blog_id = %d /* get_blog_details */", $blog_id ) );
213                 if ( ! $details ) {
214                         // Set the full cache.
215                         wp_cache_set( $blog_id, -1, 'blog-details' );
216                         return false;
217                 }
218         }
219
220         if ( ! $get_all ) {
221                 wp_cache_set( $blog_id . $all, $details, 'blog-details' );
222                 return $details;
223         }
224
225         $details->blogname              = get_blog_option( $blog_id, 'blogname' );
226         $details->siteurl               = get_blog_option( $blog_id, 'siteurl' );
227         $details->post_count    = get_blog_option( $blog_id, 'post_count' );
228
229         $details = apply_filters( 'blog_details', $details );
230
231         wp_cache_set( $blog_id . $all, $details, 'blog-details' );
232
233         $key = md5( $details->domain . $details->path );
234         wp_cache_set( $key, $details, 'blog-lookup' );
235
236         return $details;
237 }
238
239 /**
240  * Clear the blog details cache.
241  *
242  * @since MU
243  *
244  * @param int $blog_id Blog ID
245  */
246 function refresh_blog_details( $blog_id ) {
247         $blog_id = (int) $blog_id;
248         $details = get_blog_details( $blog_id, false );
249
250         wp_cache_delete( $blog_id , 'blog-details' );
251         wp_cache_delete( $blog_id . 'short' , 'blog-details' );
252         wp_cache_delete( md5( $details->domain . $details->path )  , 'blog-lookup' );
253         wp_cache_delete( 'current_blog_' . $details->domain, 'site-options' );
254         wp_cache_delete( 'current_blog_' . $details->domain . $details->path, 'site-options' );
255 }
256
257 /**
258  * Update the details for a blog. Updates the blogs table for a given blog id.
259  *
260  * @since MU
261  *
262  * @param int $blog_id Blog ID
263  * @param array $details Array of details keyed by blogs table field names.
264  * @return bool True if update succeeds, false otherwise.
265  */
266 function update_blog_details( $blog_id, $details = array() ) {
267         global $wpdb;
268
269         if ( empty($details) )
270                 return false;
271
272         if ( is_object($details) )
273                 $details = get_object_vars($details);
274
275         $current_details = get_blog_details($blog_id, false);
276         if ( empty($current_details) )
277                 return false;
278
279         $current_details = get_object_vars($current_details);
280
281         $details = array_merge($current_details, $details);
282         $details['last_updated'] = current_time('mysql', true);
283
284         $update_details = array();
285         $fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id');
286         foreach ( array_intersect( array_keys( $details ), $fields ) as $field )
287                 $update_details[$field] = $details[$field];
288
289         $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) );
290
291         // If spam status changed, issue actions.
292         if ( $details[ 'spam' ] != $current_details[ 'spam' ] ) {
293                 if ( $details[ 'spam' ] == 1 )
294                         do_action( "make_spam_blog", $blog_id );
295                 else
296                         do_action( "make_ham_blog", $blog_id );
297         }
298
299         if ( isset($details[ 'public' ]) )
300                 update_blog_option( $blog_id, 'blog_public', $details[ 'public' ] );
301
302         refresh_blog_details($blog_id);
303
304         return true;
305 }
306
307 /**
308  * Retrieve option value based on setting name and blog_id.
309  *
310  * If the option does not exist or does not have a value, then the return value
311  * will be false. This is useful to check whether you need to install an option
312  * and is commonly used during installation of plugin options and to test
313  * whether upgrading is required.
314  *
315  * There is a filter called 'blog_option_$option' with the $option being
316  * replaced with the option name. The filter takes two parameters. $value and
317  * $blog_id. It returns $value.
318  * The 'option_$option' filter in get_option() is not called.
319  *
320  * @since MU
321  * @uses apply_filters() Calls 'blog_option_$optionname' with the option name value.
322  *
323  * @param int $blog_id Optional. Blog ID, can be null to refer to the current blog.
324  * @param string $setting Name of option to retrieve. Should already be SQL-escaped.
325  * @param string $default (optional) Default value returned if option not found.
326  * @return mixed Value set for the option.
327  */
328 function get_blog_option( $blog_id, $setting, $default = false ) {
329         global $wpdb;
330
331         if ( null === $blog_id )
332                 $blog_id = $wpdb->blogid;
333
334         $key = $blog_id . '-' . $setting . '-blog_option';
335         $value = wp_cache_get( $key, 'site-options' );
336         if ( $value == null ) {
337                 if ( $blog_id == $wpdb->blogid ) {
338                         $value = get_option( $setting, $default );
339                         $notoptions = wp_cache_get( 'notoptions', 'options' );
340                         if ( isset( $notoptions[$setting] ) ) {
341                                 wp_cache_set( $key, 'noop', 'site-options' );
342                                 $value = $default;
343                         } elseif ( $value == false ) {
344                                 wp_cache_set( $key, 'falsevalue', 'site-options' );
345                         } else {
346                                 wp_cache_set( $key, $value, 'site-options' );
347                         }
348                         return apply_filters( 'blog_option_' . $setting, $value, $blog_id );
349                 } else {
350                         $blog_prefix = $wpdb->get_blog_prefix( $blog_id );
351                         $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$blog_prefix}options WHERE option_name = %s", $setting ) );
352                         if ( is_object( $row ) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
353                                 $value = $row->option_value;
354                                 if ( $value == false )
355                                         wp_cache_set( $key, 'falsevalue', 'site-options' );
356                                 else
357                                         wp_cache_set( $key, $value, 'site-options' );
358                         } else { // option does not exist, so we must cache its non-existence
359                                 wp_cache_set( $key, 'noop', 'site-options' );
360                                 $value = $default;
361                         }
362                 }
363         } elseif ( $value == 'noop' ) {
364                 $value = $default;
365         } elseif ( $value == 'falsevalue' ) {
366                 $value = false;
367         }
368         // If home is not set use siteurl.
369         if ( 'home' == $setting && '' == $value )
370                 return get_blog_option( $blog_id, 'siteurl' );
371
372         if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting )
373                 $value = untrailingslashit( $value );
374
375         return apply_filters( 'blog_option_' . $setting, maybe_unserialize( $value ), $blog_id );
376 }
377
378 /**
379  * Add an option for a particular blog.
380  *
381  * @since MU
382  *
383  * @param int $id The blog id
384  * @param string $key The option key
385  * @param mixed $value The option value
386  * @return bool True on success, false on failure.
387  */
388 function add_blog_option( $id, $key, $value ) {
389         $id = (int) $id;
390
391         switch_to_blog($id);
392         $return = add_option( $key, $value );
393         restore_current_blog();
394         if ( $return )
395                 wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options' );
396         return $return;
397 }
398
399 /**
400  * Delete an option for a particular blog.
401  *
402  * @since MU
403  *
404  * @param int $id The blog id
405  * @param string $key The option key
406  * @return bool True on success, false on failure.
407  */
408 function delete_blog_option( $id, $key ) {
409         $id = (int) $id;
410
411         switch_to_blog($id);
412         $return = delete_option( $key );
413         restore_current_blog();
414         if ( $return )
415                 wp_cache_set( $id . '-' . $key . '-blog_option', '', 'site-options' );
416         return $return;
417 }
418
419 /**
420  * Update an option for a particular blog.
421  *
422  * @since MU
423  *
424  * @param int $id The blog id
425  * @param string $key The option key
426  * @param mixed $value The option value
427  * @return bool True on success, false on failrue.
428  */
429 function update_blog_option( $id, $key, $value, $deprecated = null ) {
430         $id = (int) $id;
431
432         if ( null !== $deprecated  )
433                 _deprecated_argument( __FUNCTION__, '3.1' );
434
435         switch_to_blog($id);
436         $return = update_option( $key, $value );
437         restore_current_blog();
438
439         refresh_blog_details( $id );
440
441         if ( $return )
442                 wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options');
443         return $return;
444 }
445
446 /**
447  * Switch the current blog.
448  *
449  * This function is useful if you need to pull posts, or other information,
450  * from other blogs. You can switch back afterwards using restore_current_blog().
451  *
452  * Things that aren't switched:
453  *  - autoloaded options. See #14992
454  *  - plugins. See #14941
455  *
456  * @see restore_current_blog()
457  * @since MU
458  *
459  * @param int $new_blog The id of the blog you want to switch to. Default: current blog
460  * @param bool $validate Whether to check if $new_blog exists before proceeding
461  * @return bool True on success, False if the validation failed
462  */
463 function switch_to_blog( $new_blog, $validate = false ) {
464         global $wpdb, $table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;
465
466         if ( empty($new_blog) )
467                 $new_blog = $blog_id;
468
469         if ( $validate && ! get_blog_details( $new_blog ) )
470                 return false;
471
472         if ( empty($switched_stack) )
473                 $switched_stack = array();
474
475         $switched_stack[] = $blog_id;
476
477         /* If we're switching to the same blog id that we're on,
478         * set the right vars, do the associated actions, but skip
479         * the extra unnecessary work */
480         if ( $blog_id == $new_blog ) {
481                 do_action( 'switch_blog', $blog_id, $blog_id );
482                 $switched = true;
483                 return true;
484         }
485
486         $wpdb->set_blog_id($new_blog);
487         $table_prefix = $wpdb->prefix;
488         $prev_blog_id = $blog_id;
489         $blog_id = $new_blog;
490
491         if ( is_object( $wp_roles ) ) {
492                 $wpdb->suppress_errors();
493                 if ( method_exists( $wp_roles ,'_init' ) )
494                         $wp_roles->_init();
495                 elseif ( method_exists( $wp_roles, '__construct' ) )
496                         $wp_roles->__construct();
497                 $wpdb->suppress_errors( false );
498         }
499
500         if ( did_action('init') ) {
501                 $current_user = wp_get_current_user();
502                 if ( is_object( $current_user ) )
503                         $current_user->for_blog( $blog_id );
504         }
505
506         if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
507                 $global_groups = $wp_object_cache->global_groups;
508         else
509                 $global_groups = false;
510
511         wp_cache_init();
512         if ( function_exists('wp_cache_add_global_groups') ) {
513                 if ( is_array( $global_groups ) )
514                         wp_cache_add_global_groups( $global_groups );
515                 else
516                         wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
517                 wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
518         }
519
520         do_action('switch_blog', $blog_id, $prev_blog_id);
521         $switched = true;
522         return true;
523 }
524
525 /**
526  * Restore the current blog, after calling switch_to_blog()
527  *
528  * @see switch_to_blog()
529  * @since MU
530  *
531  * @return bool True on success, False if we're already on the current blog
532  */
533 function restore_current_blog() {
534         global $table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;
535
536         if ( !$switched )
537                 return false;
538
539         if ( !is_array( $switched_stack ) )
540                 return false;
541
542         $blog = array_pop( $switched_stack );
543         if ( $blog_id == $blog ) {
544                 do_action( 'switch_blog', $blog, $blog );
545                 /* If we still have items in the switched stack, consider ourselves still 'switched' */
546                 $switched = ( is_array( $switched_stack ) && count( $switched_stack ) > 0 );
547                 return true;
548         }
549
550         $wpdb->set_blog_id($blog);
551         $prev_blog_id = $blog_id;
552         $blog_id = $blog;
553         $table_prefix = $wpdb->prefix;
554
555         if ( is_object( $wp_roles ) ) {
556                 $wpdb->suppress_errors();
557                 if ( method_exists( $wp_roles ,'_init' ) )
558                         $wp_roles->_init();
559                 elseif ( method_exists( $wp_roles, '__construct' ) )
560                         $wp_roles->__construct();
561                 $wpdb->suppress_errors( false );
562         }
563
564         if ( did_action('init') ) {
565                 $current_user = wp_get_current_user();
566                 if ( is_object( $current_user ) )
567                         $current_user->for_blog( $blog_id );
568         }
569
570         if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
571                 $global_groups = $wp_object_cache->global_groups;
572         else
573                 $global_groups = false;
574
575         wp_cache_init();
576         if ( function_exists('wp_cache_add_global_groups') ) {
577                 if ( is_array( $global_groups ) )
578                         wp_cache_add_global_groups( $global_groups );
579                 else
580                         wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) );
581                 wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
582         }
583
584         do_action('switch_blog', $blog_id, $prev_blog_id);
585
586         /* If we still have items in the switched stack, consider ourselves still 'switched' */
587         $switched = ( is_array( $switched_stack ) && count( $switched_stack ) > 0 );
588         return true;
589 }
590
591 /**
592  * Check if a particular blog is archived.
593  *
594  * @since MU
595  *
596  * @param int $id The blog id
597  * @return string Whether the blog is archived or not
598  */
599 function is_archived( $id ) {
600         return get_blog_status($id, 'archived');
601 }
602
603 /**
604  * Update the 'archived' status of a particular blog.
605  *
606  * @since MU
607  *
608  * @param int $id The blog id
609  * @param string $archived The new status
610  * @return string $archived
611  */
612 function update_archived( $id, $archived ) {
613         update_blog_status($id, 'archived', $archived);
614         return $archived;
615 }
616
617 /**
618  * Update a blog details field.
619  *
620  * @since MU
621  *
622  * @param int $blog_id BLog ID
623  * @param string $pref A field name
624  * @param string $value Value for $pref
625  * @return string $value
626  */
627 function update_blog_status( $blog_id, $pref, $value, $deprecated = null ) {
628         global $wpdb;
629
630         if ( null !== $deprecated  )
631                 _deprecated_argument( __FUNCTION__, '3.1' );
632
633         if ( !in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id') ) )
634                 return $value;
635
636         $wpdb->update( $wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id) );
637
638         refresh_blog_details($blog_id);
639
640         if ( 'spam' == $pref )
641                 ( $value == 1 ) ? do_action( 'make_spam_blog', $blog_id ) :     do_action( 'make_ham_blog', $blog_id );
642         elseif ( 'mature' == $pref )
643                 ( $value == 1 ) ? do_action( 'mature_blog', $blog_id ) : do_action( 'unmature_blog', $blog_id );
644         elseif ( 'archived' == $pref )
645                 ( $value == 1 ) ? do_action( 'archive_blog', $blog_id ) : do_action( 'unarchive_blog', $blog_id );
646         elseif ( 'archived' == $pref )
647                 ( $value == 1 ) ? do_action( 'archive_blog', $blog_id ) : do_action( 'unarchive_blog', $blog_id );
648
649         return $value;
650 }
651
652 /**
653  * Get a blog details field.
654  *
655  * @since MU
656  *
657  * @param int $id The blog id
658  * @param string $pref A field name
659  * @return bool $value
660  */
661 function get_blog_status( $id, $pref ) {
662         global $wpdb;
663
664         $details = get_blog_details( $id, false );
665         if ( $details )
666                 return $details->$pref;
667
668         return $wpdb->get_var( $wpdb->prepare("SELECT %s FROM {$wpdb->blogs} WHERE blog_id = %d", $pref, $id) );
669 }
670
671 /**
672  * Get a list of most recently updated blogs.
673  *
674  * @since MU
675  *
676  * @param mixed $deprecated Not used
677  * @param int $start The offset
678  * @param int $quantity The maximum number of blogs to retrieve. Default is 40.
679  * @return array The list of blogs
680  */
681 function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) {
682         global $wpdb;
683
684         if ( ! empty( $deprecated ) )
685                 _deprecated_argument( __FUNCTION__, 'MU' ); // never used
686
687         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 );
688 }
689
690 /**
691  * Handler for updating the blog date when a post is published or an already published post is changed.
692  *
693  * @since 3.3.0
694  *
695  * @param string $new_status The new post status
696  * @param string $old_status The old post status
697  * @param object $post Post object
698  */
699 function _update_blog_date_on_post_publish( $new_status, $old_status, $post ) {
700         $post_type_obj = get_post_type_object( $post->post_type );
701         if ( ! $post_type_obj->public )
702                 return;
703
704         if ( 'publish' != $new_status && 'publish' != $old_status )
705                 return;
706
707         // Post was freshly published, published post was saved, or published post was unpublished.
708
709         wpmu_update_blogs_date();
710 }
711
712 ?>