/var/www/wordpress/wp-admin/includes/admin.php
/var/www/wordpress/wp-admin/includes/bookmark.php
/var/www/wordpress/wp-admin/includes/class-ftp-pure.php
/var/www/wordpress/wp-admin/includes/class-ftp-sockets.php
/var/www/wordpress/wp-admin/includes/class-ftp.php
/var/www/wordpress/wp-admin/includes/class-pclzip.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-base.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-direct.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ftpext.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ftpsockets.php
/var/www/wordpress/wp-admin/includes/class-wp-filesystem-ssh2.php
/var/www/wordpress/wp-admin/includes/class-wp-importer.php
/var/www/wordpress/wp-admin/includes/class-wp-upgrader.php
/var/www/wordpress/wp-admin/includes/comment.php
/var/www/wordpress/wp-admin/includes/continents-cities.php
/var/www/wordpress/wp-admin/includes/dashboard.php
/var/www/wordpress/wp-admin/includes/deprecated.php
/var/www/wordpress/wp-admin/includes/export.php
/var/www/wordpress/wp-admin/includes/file.php
/var/www/wordpress/wp-admin/includes/image-edit.php
/var/www/wordpress/wp-admin/includes/image.php
/var/www/wordpress/wp-admin/includes/import.php
/var/www/wordpress/wp-admin/includes/manifest.php
/var/www/wordpress/wp-admin/includes/media.php
/var/www/wordpress/wp-admin/includes/meta-boxes.php
/var/www/wordpress/wp-admin/includes/misc.php
/var/www/wordpress/wp-admin/includes/ms-deprecated.php
/var/www/wordpress/wp-admin/includes/ms.php
/var/www/wordpress/wp-admin/includes/nav-menu.php
/var/www/wordpress/wp-admin/includes/plugin-install.php
/var/www/wordpress/wp-admin/includes/plugin.php
/var/www/wordpress/wp-admin/includes/post.php
/var/www/wordpress/wp-admin/includes/schema.php
/var/www/wordpress/wp-admin/includes/taxonomy.php
/var/www/wordpress/wp-admin/includes/template.php
/var/www/wordpress/wp-admin/includes/theme-install.php
/var/www/wordpress/wp-admin/includes/theme.php
/var/www/wordpress/wp-admin/includes/update-core.php
/var/www/wordpress/wp-admin/includes/update.php
/var/www/wordpress/wp-admin/includes/upgrade.php
/var/www/wordpress/wp-admin/includes/user.php
/var/www/wordpress/wp-admin/includes/widgets.php
/var/www/wordpress/wp-admin/js/revisions-js.php
/var/www/wordpress/wp-admin/maint/repair.php
/var/www/wordpress/wp-admin/admin-ajax.php
/var/www/wordpress/wp-admin/admin-footer.php
/var/www/wordpress/wp-admin/admin-functions.php
/var/www/wordpress/wp-admin/admin-header.php
/var/www/wordpress/wp-admin/admin-post.php
/var/www/wordpress/wp-admin/admin.php
/var/www/wordpress/wp-admin/async-upload.php
/var/www/wordpress/wp-admin/comment.php
/var/www/wordpress/wp-admin/custom-background.php
/var/www/wordpress/wp-admin/custom-header.php
/var/www/wordpress/wp-admin/edit-attachment-rows.php
/var/www/wordpress/wp-admin/edit-comments.php
/var/www/wordpress/wp-admin/edit-form-advanced.php
/var/www/wordpress/wp-admin/edit-form-comment.php
/var/www/wordpress/wp-admin/edit-link-categories.php
/var/www/wordpress/wp-admin/edit-link-category-form.php
/var/www/wordpress/wp-admin/edit-link-form.php
/var/www/wordpress/wp-admin/edit-post-rows.php
/var/www/wordpress/wp-admin/edit-tag-form.php
/var/www/wordpress/wp-admin/edit-tags.php
/var/www/wordpress/wp-admin/edit.php
/var/www/wordpress/wp-admin/export.php
/var/www/wordpress/wp-admin/gears-manifest.php
/var/www/wordpress/wp-admin/import.php
/var/www/wordpress/wp-admin/index-extra.php
/var/www/wordpress/wp-admin/index.php
/var/www/wordpress/wp-admin/install-helper.php
/var/www/wordpress/wp-admin/install.php
/var/www/wordpress/wp-admin/link-add.php
/var/www/wordpress/wp-admin/link-category.php
/var/www/wordpress/wp-admin/link-manager.php
/var/www/wordpress/wp-admin/link-parse-opml.php
/var/www/wordpress/wp-admin/link.php
/var/www/wordpress/wp-admin/load-scripts.php
/var/www/wordpress/wp-admin/load-styles.php
/var/www/wordpress/wp-admin/media-new.php
/var/www/wordpress/wp-admin/media-upload.php
/var/www/wordpress/wp-admin/media.php
/var/www/wordpress/wp-admin/menu-header.php
/var/www/wordpress/wp-admin/menu.php
/var/www/wordpress/wp-admin/moderation.php
/var/www/wordpress/wp-admin/ms-admin.php
/var/www/wordpress/wp-admin/ms-delete-site.php
/var/www/wordpress/wp-admin/ms-edit.php
/var/www/wordpress/wp-admin/ms-options.php
/var/www/wordpress/wp-admin/ms-sites.php
/var/www/wordpress/wp-admin/ms-themes.php
/var/www/wordpress/wp-admin/ms-upgrade-network.php
/var/www/wordpress/wp-admin/ms-users.php
/var/www/wordpress/wp-admin/my-sites.php
/var/www/wordpress/wp-admin/nav-menus.php
/var/www/wordpress/wp-admin/network.php
/var/www/wordpress/wp-admin/options-discussion.php
/var/www/wordpress/wp-admin/options-general.php
/var/www/wordpress/wp-admin/options-head.php
/var/www/wordpress/wp-admin/options-media.php
/var/www/wordpress/wp-admin/options-permalink.php
/var/www/wordpress/wp-admin/options-privacy.php
/var/www/wordpress/wp-admin/options-reading.php
/var/www/wordpress/wp-admin/options-writing.php
/var/www/wordpress/wp-admin/options.php
/var/www/wordpress/wp-admin/plugin-editor.php
/var/www/wordpress/wp-admin/plugin-install.php
/var/www/wordpress/wp-admin/plugins.php
/var/www/wordpress/wp-admin/post-new.php
/var/www/wordpress/wp-admin/post.php
/var/www/wordpress/wp-admin/press-this.php
/var/www/wordpress/wp-admin/profile.php
/var/www/wordpress/wp-admin/revision.php
/var/www/wordpress/wp-admin/setup-config.php
/var/www/wordpress/wp-admin/sidebar.php
/var/www/wordpress/wp-admin/theme-editor.php
/var/www/wordpress/wp-admin/theme-install.php
/var/www/wordpress/wp-admin/themes.php
/var/www/wordpress/wp-admin/tools.php
/var/www/wordpress/wp-admin/update-core.php
/var/www/wordpress/wp-admin/update.php
/var/www/wordpress/wp-admin/upgrade-functions.php
/var/www/wordpress/wp-admin/upgrade.php
/var/www/wordpress/wp-admin/upload.php
/var/www/wordpress/wp-admin/user-edit.php
/var/www/wordpress/wp-admin/user-new.php
/var/www/wordpress/wp-admin/users.php
/var/www/wordpress/wp-admin/widgets.php
/var/www/wordpress/wp-content/languages/ru_RU.php
/var/www/wordpress/wp-content/plugins/akismet/akismet.php
/var/www/wordpress/wp-content/plugins/rh/rh.php
/var/www/wordpress/wp-content/plugins/hello.php
/var/www/wordpress/wp-content/plugins/index.php
/var/www/wordpress/wp-content/themes/twentyten/404.php
/var/www/wordpress/wp-content/themes/twentyten/archive.php
/var/www/wordpress/wp-content/themes/twentyten/attachment.php
/var/www/wordpress/wp-content/themes/twentyten/author.php
/var/www/wordpress/wp-content/themes/twentyten/category.php
/var/www/wordpress/wp-content/themes/twentyten/comments.php
/var/www/wordpress/wp-content/themes/twentyten/footer.php
/var/www/wordpress/wp-content/themes/twentyten/functions.php
/var/www/wordpress/wp-content/themes/twentyten/header.php
/var/www/wordpress/wp-content/themes/twentyten/index.php
/var/www/wordpress/wp-content/themes/twentyten/loop.php
/var/www/wordpress/wp-content/themes/twentyten/onecolumn-page.php
/var/www/wordpress/wp-content/themes/twentyten/page.php
/var/www/wordpress/wp-content/themes/twentyten/search.php
/var/www/wordpress/wp-content/themes/twentyten/sidebar-footer.php
/var/www/wordpress/wp-content/themes/twentyten/sidebar.php
/var/www/wordpress/wp-content/themes/twentyten/single.php
/var/www/wordpress/wp-content/themes/twentyten/tag.php
/var/www/wordpress/wp-content/themes/index.php
/var/www/wordpress/wp-content/index.php
/var/www/wordpress/wp-includes/js/tinymce/langs/wp-langs.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/JSON.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/Logger.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/EnchantSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/GoogleSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/PSpell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/PSpellShell.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/SpellChecker.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/includes/general.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/config.php
/var/www/wordpress/wp-includes/js/tinymce/plugins/spellchecker/rpc.php
/var/www/wordpress/wp-includes/js/tinymce/wp-mce-help.php
/var/www/wordpress/wp-includes/js/tinymce/wp-tinymce.php
/var/www/wordpress/wp-includes/pomo/entry.php
/var/www/wordpress/wp-includes/pomo/mo.php
/var/www/wordpress/wp-includes/pomo/po.php
/var/www/wordpress/wp-includes/pomo/streams.php
/var/www/wordpress/wp-includes/pomo/translations.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/native.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/shell.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/string.php
/var/www/wordpress/wp-includes/Text/Diff/Engine/xdiff.php
/var/www/wordpress/wp-includes/Text/Diff/Renderer/inline.php
/var/www/wordpress/wp-includes/Text/Diff/Renderer.php
/var/www/wordpress/wp-includes/Text/Diff.php
/var/www/wordpress/wp-includes/theme-compat/comments-popup.php
/var/www/wordpress/wp-includes/theme-compat/comments.php
/var/www/wordpress/wp-includes/theme-compat/footer.php
/var/www/wordpress/wp-includes/theme-compat/header.php
/var/www/wordpress/wp-includes/theme-compat/sidebar.php
/var/www/wordpress/wp-includes/atomlib.php
/var/www/wordpress/wp-includes/author-template.php
/var/www/wordpress/wp-includes/bookmark-template.php
/var/www/wordpress/wp-includes/bookmark.php
/var/www/wordpress/wp-includes/cache.php
/var/www/wordpress/wp-includes/canonical.php
/var/www/wordpress/wp-includes/capabilities.php
/var/www/wordpress/wp-includes/category-template.php
/var/www/wordpress/wp-includes/category.php
/var/www/wordpress/wp-includes/class-feed.php
/var/www/wordpress/wp-includes/class-http.php
/var/www/wordpress/wp-includes/class-IXR.php
/var/www/wordpress/wp-includes/class-json.php
/var/www/wordpress/wp-includes/class-oembed.php
/var/www/wordpress/wp-includes/class-phpass.php
/var/www/wordpress/wp-includes/class-phpmailer.php
/var/www/wordpress/wp-includes/class-pop3.php
/var/www/wordpress/wp-includes/class-simplepie.php
/var/www/wordpress/wp-includes/class-smtp.php
/var/www/wordpress/wp-includes/class-snoopy.php
/var/www/wordpress/wp-includes/class.wp-dependencies.php
/var/www/wordpress/wp-includes/class.wp-scripts.php
/var/www/wordpress/wp-includes/class.wp-styles.php
/var/www/wordpress/wp-includes/classes.php
/var/www/wordpress/wp-includes/comment-template.php
/var/www/wordpress/wp-includes/comment.php
/var/www/wordpress/wp-includes/compat.php
/var/www/wordpress/wp-includes/cron.php
/var/www/wordpress/wp-includes/default-constants.php
/var/www/wordpress/wp-includes/default-embeds.php
/var/www/wordpress/wp-includes/default-filters.php
/var/www/wordpress/wp-includes/default-widgets.php
/var/www/wordpress/wp-includes/deprecated.php
/var/www/wordpress/wp-includes/feed-atom-comments.php
/var/www/wordpress/wp-includes/feed-atom.php
/var/www/wordpress/wp-includes/feed-rdf.php
/var/www/wordpress/wp-includes/feed-rss.php
/var/www/wordpress/wp-includes/feed-rss2-comments.php
/var/www/wordpress/wp-includes/feed-rss2.php
/var/www/wordpress/wp-includes/feed.php
/var/www/wordpress/wp-includes/formatting.php
/var/www/wordpress/wp-includes/functions.php
/var/www/wordpress/wp-includes/functions.wp-scripts.php
/var/www/wordpress/wp-includes/functions.wp-styles.php
/var/www/wordpress/wp-includes/general-template.php
/var/www/wordpress/wp-includes/http.php
/var/www/wordpress/wp-includes/kses.php
/var/www/wordpress/wp-includes/l10n.php
/var/www/wordpress/wp-includes/link-template.php
/var/www/wordpress/wp-includes/load.php
/var/www/wordpress/wp-includes/locale.php
/var/www/wordpress/wp-includes/media.php
/var/www/wordpress/wp-includes/meta.php
/var/www/wordpress/wp-includes/ms-blogs.php
#CodeDescriptions
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 3.0.0
9 */
10
11// @todo use update_blog_details
12function wpmu_update_blogs_date() {
13 global $wpdb;
14
15 $wpdb->update( $wpdb->blogs, array('last_updated' => current_time('mysql', true)), array('blog_id' => $wpdb->blogid) );
16 refresh_blog_details( $wpdb->blogid );
17
18 do_action( 'wpmu_blog_updated', $wpdb->blogid );
19}
20
21function get_blogaddress_by_id( $blog_id ) {
22 $bloginfo = get_blog_details( (int) $blog_id, false ); // only get bare details!
23 return esc_url( 'http://' . $bloginfo->domain . $bloginfo->path );
24}
25
26function get_blogaddress_by_name( $blogname ) {
27 global $current_site;
28
29 if ( is_subdomain_install() ) {
30 if ( $blogname == 'main' )
31 $blogname = 'www';
32 $url = rtrim( network_home_url(), '/' );
33 if ( !empty( $blogname ) )
34 $url = preg_replace( '|^([^\.]+://)|', '$1' . $blogname . '.', $url );
35 } else {
36 $url = network_home_url( $blogname );
37 }
38 return esc_url( $url . '/' );
39}
40
41function get_blogaddress_by_domain( $domain, $path ){
42 if ( is_subdomain_install() ) {
43 $url = "http://".$domain.$path;
44 } else {
45 if ( $domain != $_SERVER['HTTP_HOST'] ) {
46 $blogname = substr( $domain, 0, strpos( $domain, '.' ) );
47 $url = 'http://' . substr( $domain, strpos( $domain, '.' ) + 1 ) . $path;
48 // we're not installing the main blog
49 if ( $blogname != 'www.' )
50 $url .= $blogname . '/';
51 } else { // main blog
52 $url = 'http://' . $domain . $path;
53 }
54 }
55 return esc_url( $url );
56}
57
58function get_id_from_blogname( $name ) {
59 global $wpdb, $current_site;
60 $blog_id = wp_cache_get( "get_id_from_blogname_" . $name, 'blog-details' );
61 if ( $blog_id )
62 return $blog_id;
63
64 if ( is_subdomain_install() ) {
65 $domain = $name . '.' . $current_site->domain;
66 $path = $current_site->path;
67 } else {
68 $domain = $current_site->domain;
69 $path = $current_site->path . $name . '/';
70 }
71 $blog_id = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s", $domain, $path) );
72 wp_cache_set( 'get_id_from_blogname_' . $name, $blog_id, 'blog-details' );
73 return $blog_id;
74}
75
76/**
77 * Retrieve the details for a blog from the blogs table and blog options.
78 *
79 * @since 3.0.0
80 * @param int|string|array $fields A blog ID, a blog name, or an array of fields to query against.
81 * @param bool $get_all Whether to retrieve all details or only the details in the blogs table. Default is true.
82 * @return object Blog details.
83 */
84function get_blog_details( $fields, $get_all = true ) {
85 global $wpdb;
86
87 if ( is_array($fields ) ) {
88 if ( isset($fields['blog_id']) ) {
89 $blog_id = $fields['blog_id'];
90 } elseif ( isset($fields['domain']) && isset($fields['path']) ) {
91 $key = md5( $fields['domain'] . $fields['path'] );
92 $blog = wp_cache_get($key, 'blog-lookup');
93 if ( false !== $blog )
94 return $blog;
95 if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {
96 $nowww = substr( $fields['domain'], 4 );
97 $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'] ) );
98 } else {
99 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) );
100 }
101 if ( $blog ) {
102 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');
103 $blog_id = $blog->blog_id;
104 } else {
105 return false;
106 }
107 } elseif ( isset($fields['domain']) && is_subdomain_install() ) {
108 $key = md5( $fields['domain'] );
109 $blog = wp_cache_get($key, 'blog-lookup');
110 if ( false !== $blog )
111 return $blog;
112 if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {
113 $nowww = substr( $fields['domain'], 4 );
114 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) );
115 } else {
116 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) );
117 }
118 if ( $blog ) {
119 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');
120 $blog_id = $blog->blog_id;
121 } else {
122 return false;
123 }
124 } else {
125 return false;
126 }
127 } else {
128 if ( !is_numeric( $fields ) )
129 $blog_id = get_id_from_blogname( $fields );
130 else
131 $blog_id = $fields;
132 }
133
134 $blog_id = (int) $blog_id;
135
136 $all = $get_all == true ? '' : 'short';
137 $details = wp_cache_get( $blog_id . $all, 'blog-details' );
138
139 if ( $details ) {
140 if ( ! is_object( $details ) ) {
141 if ( $details == -1 ) {
142 return false;
143 } else {
144 // Clear old pre-serialized objects. Cache clients do better with that.
145 wp_cache_delete( $blog_id . $all, 'blog-details' );
146 unset($details);
147 }
148 } else {
149 return $details;
150 }
151 }
152
153 // Try the other cache.
154 if ( $get_all ) {
155 $details = wp_cache_get( $blog_id . 'short', 'blog-details' );
156 } else {
157 $details = wp_cache_get( $blog_id, 'blog-details' );
158 // If short was requested and full cache is set, we can return.
159 if ( $details ) {
160 if ( ! is_object( $details ) ) {
161 if ( $details == -1 ) {
162 return false;
163 } else {
164 // Clear old pre-serialized objects. Cache clients do better with that.
165 wp_cache_delete( $blog_id, 'blog-details' );
166 unset($details);
167 }
168 } else {
169 return $details;
170 }
171 }
172 }
173
174 if ( empty($details) ) {
175 $details = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE blog_id = %d /* get_blog_details */", $blog_id ) );
176 if ( ! $details ) {
177 // Set the full cache.
178 wp_cache_set( $blog_id, -1, 'blog-details' );
179 return false;
180 }
181 }
182
183 if ( ! $get_all ) {
184 wp_cache_set( $blog_id . $all, $details, 'blog-details' );
185 return $details;
186 }
187
188 $details->blogname = get_blog_option( $blog_id, 'blogname' );
189 $details->siteurl = get_blog_option( $blog_id, 'siteurl' );
190 $details->post_count = get_blog_option( $blog_id, 'post_count' );
191
192 $details = apply_filters( 'blog_details', $details );
193
194 wp_cache_set( $blog_id . $all, $details, 'blog-details' );
195
196 $key = md5( $details->domain . $details->path );
197 wp_cache_set( $key, $details, 'blog-lookup' );
198
199 return $details;
200}
201
202/**
203 * Clear the blog details cache.
204 *
205 * @since 3.0.0
206 *
207 * @param int $blog_id Blog ID
208 */
209function refresh_blog_details( $blog_id ) {
210 $blog_id = (int) $blog_id;
211 $details = get_blog_details( $blog_id, false );
212
213 wp_cache_delete( $blog_id , 'blog-details' );
214 wp_cache_delete( $blog_id . 'short' , 'blog-details' );
215 wp_cache_delete( md5( $details->domain . $details->path ) , 'blog-lookup' );
216 wp_cache_delete( 'current_blog_' . $details->domain, 'site-options' );
217 wp_cache_delete( 'current_blog_' . $details->domain . $details->path, 'site-options' );
218}
219
220/**
221 * Update the details for a blog. Updates the blogs table for a given blog id.
222 *
223 * @since 3.0.0
224 *
225 * @param int $blog_id Blog ID
226 * @param array $details Array of details keyed by blogs table field names.
227 * @return bool True if update succeeds, false otherwise.
228 */
229function update_blog_details( $blog_id, $details = array() ) {
230 global $wpdb;
231
232 if ( empty($details) )
233 return false;
234
235 if ( is_object($details) )
236 $details = get_object_vars($details);
237
238 $current_details = get_blog_details($blog_id, false);
239 if ( empty($current_details) )
240 return false;
241
242 $current_details = get_object_vars($current_details);
243
244 $details = array_merge($current_details, $details);
245 $details['last_updated'] = current_time('mysql', true);
246
247 $update_details = array();
248 $fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id');
249 foreach ( array_intersect( array_keys( $details ), $fields ) as $field )
250 $update_details[$field] = $details[$field];
251
252 $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) );
253
254 // If spam status changed, issue actions.
255 if ( $details[ 'spam' ] != $current_details[ 'spam' ] ) {
256 if ( $details[ 'spam' ] == 1 )
257 do_action( "make_spam_blog", $blog_id );
258 else
259 do_action( "make_ham_blog", $blog_id );
260 }
261
262 if ( isset($details[ 'public' ]) )
263 update_blog_option( $blog_id, 'blog_public', $details[ 'public' ], false );
264
265 refresh_blog_details($blog_id);
266
267 return true;
268}
269
270/**
271 * Retrieve option value based on setting name and blog_id.
272 *
273 * If the option does not exist or does not have a value, then the return value
274 * will be false. This is useful to check whether you need to install an option
275 * and is commonly used during installation of plugin options and to test
276 * whether upgrading is required.
277 *
278 * There is a filter called 'blog_option_$option' with the $option being
279 * replaced with the option name. The filter takes two parameters. $value and
280 * $blog_id. It returns $value.
281 * The 'option_$option' filter in get_option() is not called.
282 *
283 * @since NA
284 * @package WordPress MU
285 * @subpackage Option
286 * @uses apply_filters() Calls 'blog_option_$optionname' with the option name value.
287 *
288 * @param int $blog_id is the id of the blog.
289 * @param string $setting Name of option to retrieve. Should already be SQL-escaped
290 * @param string $default (optional) Default value returned if option not found.
291 * @return mixed Value set for the option.
292 */
293function get_blog_option( $blog_id, $setting, $default = false ) {
294 global $wpdb;
295
296 $key = $blog_id."-".$setting."-blog_option";
297 $value = wp_cache_get( $key, "site-options" );
298 if ( $value == null ) {
299 if ( $blog_id == $wpdb->blogid ) {
300 $value = get_option( $setting, $default );
301 $notoptions = wp_cache_get( 'notoptions', 'options' );
302 if ( isset( $notoptions[$setting] ) ) {
303 wp_cache_set( $key, 'noop', 'site-options' );
304 $value = $default;
305 } elseif ( $value == false ) {
306 wp_cache_set( $key, 'falsevalue', 'site-options' );
307 } else {
308 wp_cache_set( $key, $value, 'site-options' );
309 }
310 return apply_filters( 'blog_option_' . $setting, $value, $blog_id );
311 } else {
312 $blog_prefix = $wpdb->get_blog_prefix( $blog_id );
313 $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$blog_prefix}options WHERE option_name = %s", $setting ) );
314 if ( is_object( $row ) ) { // Has to be get_row instead of get_var because of funkiness with 0, false, null values
315 $value = $row->option_value;
316 if ( $value == false )
317 wp_cache_set( $key, 'falsevalue', 'site-options' );
318 else
319 wp_cache_set( $key, $value, 'site-options' );
320 } else { // option does not exist, so we must cache its non-existence
321 wp_cache_set( $key, 'noop', 'site-options' );
322 $value = $default;
323 }
324 }
325 } elseif ( $value == 'noop' ) {
326 $value = $default;
327 } elseif ( $value == 'falsevalue' ) {
328 $value = false;
329 }
330 // If home is not set use siteurl.
331 if ( 'home' == $setting && '' == $value )
332 return get_blog_option( $blog_id, 'siteurl' );
333
334 if ( 'siteurl' == $setting || 'home' == $setting || 'category_base' == $setting )
335 $value = untrailingslashit( $value );
336
337 if (! @unserialize( $value ) )
338 $value = stripslashes( $value );
339
340 return apply_filters( 'blog_option_' . $setting, maybe_unserialize( $value ), $blog_id );//Possible Control Flow
341}
342
343function add_blog_option( $id, $key, $value ) {
344 $id = (int) $id;
345
346 switch_to_blog($id);
347 add_option( $key, $value );
348 restore_current_blog();
349 wp_cache_set( $id."-".$key."-blog_option", $value, 'site-options' );
350}
351
352function delete_blog_option( $id, $key ) {
353 $id = (int) $id;
354
355 switch_to_blog($id);
356 delete_option( $key );
357 restore_current_blog();
358 wp_cache_set( $id."-".$key."-blog_option", '', 'site-options' );
359}
360
361function update_blog_option( $id, $key, $value, $refresh = true ) {
362 $id = (int) $id;
363
364 switch_to_blog($id);
365 update_option( $key, $value );
366 restore_current_blog();
367
368 if ( $refresh == true )
369 refresh_blog_details( $id );
370 wp_cache_set( $id."-".$key."-blog_option", $value, 'site-options');
371}
372
373function switch_to_blog( $new_blog, $validate = false ) {
374 global $wpdb, $table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;
375
376 if ( empty($new_blog) )
377 $new_blog = $blog_id;
378
379 if ( $validate && ! get_blog_details( $new_blog ) )
380 return false;
381
382 if ( empty($switched_stack) )
383 $switched_stack = array();
384
385 $switched_stack[] = $blog_id;
386
387 /* If we're switching to the same blog id that we're on,
388 * set the right vars, do the associated actions, but skip
389 * the extra unnecessary work */
390 if ( $blog_id == $new_blog ) {
391 do_action( 'switch_blog', $blog_id, $blog_id );
392 $switched = true;
393 return true;
394 }
395
396 $wpdb->set_blog_id($new_blog);
397 $table_prefix = $wpdb->prefix;
398 $prev_blog_id = $blog_id;
399 $blog_id = $new_blog;
400
401 if ( is_object( $wp_roles ) ) {
402 $wpdb->suppress_errors();
403 if ( method_exists( $wp_roles ,'_init' ) )
404 $wp_roles->_init();
405 elseif ( method_exists( $wp_roles, '__construct' ) )
406 $wp_roles->__construct();
407 $wpdb->suppress_errors( false );
408 }
409
410 if ( did_action('init') ) {
411 $current_user = wp_get_current_user();
412 if ( is_object( $current_user ) )
413 $current_user->for_blog( $blog_id );
414 }
415
416 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
417 $global_groups = $wp_object_cache->global_groups;
418 else
419 $global_groups = false;
420
421 wp_cache_init();
422 if ( function_exists('wp_cache_add_global_groups') ) {
423 if ( is_array( $global_groups ) )
424 wp_cache_add_global_groups( $global_groups );
425 else
426 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'site-transient', 'global-posts' ) );
427 wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
428 }
429
430 do_action('switch_blog', $blog_id, $prev_blog_id);
431 $switched = true;
432 return true;
433}
434
435function restore_current_blog() {
436 global $table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;
437
438 if ( !$switched )
439 return false;
440
441 if ( !is_array( $switched_stack ) )
442 return false;
443
444 $blog = array_pop( $switched_stack );
445 if ( $blog_id == $blog ) {
446 do_action( 'switch_blog', $blog, $blog );
447 /* If we still have items in the switched stack, consider ourselves still 'switched' */
448 $switched = ( is_array( $switched_stack ) && count( $switched_stack ) > 0 );
449 return true;
450 }
451
452 $wpdb->set_blog_id($blog);
453 $prev_blog_id = $blog_id;
454 $blog_id = $blog;
455 $table_prefix = $wpdb->prefix;
456
457 if ( is_object( $wp_roles ) ) {
458 $wpdb->suppress_errors();
459 if ( method_exists( $wp_roles ,'_init' ) )
460 $wp_roles->_init();
461 elseif ( method_exists( $wp_roles, '__construct' ) )
462 $wp_roles->__construct();
463 $wpdb->suppress_errors( false );
464 }
465
466 if ( did_action('init') ) {
467 $current_user = wp_get_current_user();
468 if ( is_object( $current_user ) )
469 $current_user->for_blog( $blog_id );
470 }
471
472 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
473 $global_groups = $wp_object_cache->global_groups;
474 else
475 $global_groups = false;
476
477 wp_cache_init();
478 if ( function_exists('wp_cache_add_global_groups') ) {
479 if ( is_array( $global_groups ) )
480 wp_cache_add_global_groups( $global_groups );
481 else
482 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'site-transient' ) );
483 wp_cache_add_non_persistent_groups(array( 'comment', 'counts', 'plugins' ));
484 }
485
486 do_action('switch_blog', $blog_id, $prev_blog_id);
487
488 /* If we still have items in the switched stack, consider ourselves still 'switched' */
489 $switched = ( is_array( $switched_stack ) && count( $switched_stack ) > 0 );
490 return true;
491}
492
493function is_archived( $id ) {
494 return get_blog_status($id, 'archived');
495}
496
497function update_archived( $id, $archived ) {
498 update_blog_status($id, 'archived', $archived);
499 return $archived;
500}
501
502/**
503 * Update a blog details field.
504 *
505 * @since 3.0.0
506 *
507 * @param int $blog_id BLog ID
508 * @param string $pref A field name
509 * @param string $value Value for $pref
510 * @param bool $refresh Whether to refresh the blog details cache. Default is true.
511 */
512function update_blog_status( $blog_id, $pref, $value, $refresh = true ) {
513 global $wpdb;
514
515 if ( !in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id') ) )
516 return $value;
517
518 $wpdb->update( $wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id) );
519
520 if ( $refresh )
521 refresh_blog_details($blog_id);
522
523 if ( $pref == 'spam' ) {
524 if ( $value == 1 )
525 do_action( "make_spam_blog", $blog_id );
526 else
527 do_action( "make_ham_blog", $blog_id );
528 }
529
530 return $value;
531}
532
533function get_blog_status( $id, $pref ) {
534 global $wpdb;
535
536 $details = get_blog_details( $id, false );
537 if ( $details )
538 return $details->$pref;
539
540 return $wpdb->get_var( $wpdb->prepare("SELECT %s FROM {$wpdb->blogs} WHERE blog_id = %d", $pref, $id) );
541}
542
543function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) {
544 global $wpdb;
545 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 );
546}
547
548?>
549
/var/www/wordpress/wp-includes/ms-default-constants.php
/var/www/wordpress/wp-includes/ms-default-filters.php
/var/www/wordpress/wp-includes/ms-deprecated.php
/var/www/wordpress/wp-includes/ms-files.php
/var/www/wordpress/wp-includes/ms-functions.php
/var/www/wordpress/wp-includes/ms-load.php
/var/www/wordpress/wp-includes/ms-settings.php
/var/www/wordpress/wp-includes/nav-menu-template.php
/var/www/wordpress/wp-includes/nav-menu.php
/var/www/wordpress/wp-includes/pluggable-deprecated.php
/var/www/wordpress/wp-includes/pluggable.php
/var/www/wordpress/wp-includes/plugin.php
/var/www/wordpress/wp-includes/post-template.php
/var/www/wordpress/wp-includes/post-thumbnail-template.php
/var/www/wordpress/wp-includes/post.php
/var/www/wordpress/wp-includes/query.php
/var/www/wordpress/wp-includes/registration-functions.php
/var/www/wordpress/wp-includes/registration.php
/var/www/wordpress/wp-includes/rewrite.php
/var/www/wordpress/wp-includes/rss-functions.php
/var/www/wordpress/wp-includes/rss.php
/var/www/wordpress/wp-includes/script-loader.php
/var/www/wordpress/wp-includes/shortcodes.php
/var/www/wordpress/wp-includes/taxonomy.php
/var/www/wordpress/wp-includes/template-loader.php
/var/www/wordpress/wp-includes/theme.php
/var/www/wordpress/wp-includes/update.php
/var/www/wordpress/wp-includes/user.php
/var/www/wordpress/wp-includes/vars.php
/var/www/wordpress/wp-includes/version.php
/var/www/wordpress/wp-includes/widgets.php
/var/www/wordpress/wp-includes/wp-db.php
/var/www/wordpress/wp-includes/wp-diff.php
/var/www/wordpress/index.php
/var/www/wordpress/wp-activate.php
/var/www/wordpress/wp-app.php
/var/www/wordpress/wp-atom.php
/var/www/wordpress/wp-blog-header.php
/var/www/wordpress/wp-comments-post.php
/var/www/wordpress/wp-commentsrss2.php
/var/www/wordpress/wp-config-sample.php
/var/www/wordpress/wp-cron.php
/var/www/wordpress/wp-feed.php
/var/www/wordpress/wp-links-opml.php
/var/www/wordpress/wp-load.php
/var/www/wordpress/wp-login.php
/var/www/wordpress/wp-mail.php
/var/www/wordpress/wp-pass.php
/var/www/wordpress/wp-rdf.php
/var/www/wordpress/wp-register.php
/var/www/wordpress/wp-rss.php
/var/www/wordpress/wp-rss2.php
/var/www/wordpress/wp-settings.php
/var/www/wordpress/wp-signup.php
/var/www/wordpress/wp-trackback.php
/var/www/wordpress/xmlrpc.php