diff --git a/wp-includes/admin-bar.php b/wp-includes/admin-bar.php new file mode 100644 index 0000000000..6af0fe3175 --- /dev/null +++ b/wp-includes/admin-bar.php @@ -0,0 +1,346 @@ +menu member var. + * This is called very late on the footer actions so that it will render after anything else being + * added to the footer. + * + * It includes the action "wp_before_admin_bar_render" which should be used to hook in and + * add new menus to the admin bar. That way you can be sure that you are adding at most optimal point, + * right before the admin bar is rendered. This also gives you access to the $post global, among others. + */ +function wp_admin_bar_render() { + global $wp_admin_bar; + + if ( !is_object( $wp_admin_bar ) ) + return false; + + $wp_admin_bar->load_user_locale_translations(); + + do_action( 'wp_before_admin_bar_render' ); + + $wp_admin_bar->render(); + + do_action( 'wp_after_admin_bar_render' ); + + $wp_admin_bar->unload_user_locale_translations(); +} +add_action( 'wp_footer', 'wp_admin_bar_render', 1000 ); +add_action( 'admin_footer', 'wp_admin_bar_render', 1000 ); + +/** + * Show the logged in user's gravatar as a separator. + */ +function wp_admin_bar_me_separator() { + global $wp_admin_bar, $current_user; + + if ( !is_object( $wp_admin_bar ) ) + return false; + + $wp_admin_bar->add_menu( array( 'id' => 'me', 'title' => get_avatar( $current_user->ID, 16 ), 'href' => $wp_admin_bar->user->account_domain . 'wp-admin/profile.php' ) ); +} +add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_me_separator', 10 ); + +/** + * Use the $wp_admin_bar global to add the "My Account" menu and all submenus. + */ +function wp_admin_bar_my_account_menu() { + global $wp_admin_bar, $current_user; + + if ( !is_object( $wp_admin_bar ) ) + return false; + + /* Add the 'My Account' menu */ + $wp_admin_bar->add_menu( array( 'id' => 'my-account', 'title' => __( 'My Account' ), 'href' => admin_url('profile.php') ) ); + + /* Add the "My Account" sub menus */ + $wp_admin_bar->add_menu( array( 'parent' => 'my-account', 'title' => __( 'Edit My Profile' ), 'href' => admin_url('profile.php') ) ); + $wp_admin_bar->add_menu( array( 'parent' => 'my-account', 'title' => __( 'Global Dashboard' ), 'href' => admin_url() ) ); + $wp_admin_bar->add_menu( array( 'parent' => 'my-account', 'title' => __( 'Log Out' ), 'href' => wp_logout_url() ) ); +} +add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_my_account_menu', 20 ); + +/** + * Use the $wp_admin_bar global to add the "My Blogs/[Blog Name]" menu and all submenus. + */ +function wp_admin_bar_my_blogs_menu() { + global $wpdb, $wp_admin_bar; + + if ( !is_object( $wp_admin_bar ) ) + return false; + + /* Remove the global dashboard */ + if ( is_multisite() ) { + foreach ( (array) $wp_admin_bar->user->blogs as $key => $blog ) { + if ( get_dashboard_blog() == $blog->domain ) + unset( $wp_admin_bar->user->blogs[$key] ); + } + } + + /* Add the 'My Dashboards' menu if the user has more than one blog. */ + if ( count( $wp_admin_bar->user->blogs ) > 1 ) { + $wp_admin_bar->add_menu( array( 'id' => 'my-blogs', 'title' => __( 'My Blogs' ), 'href' => $wp_admin_bar->user->account_domain ) ); + + $default = includes_url('images/wpmini-blue.png'); + + $counter = 2; + foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { + $blogdomain = preg_replace( '!^https?://!', '', $blog->siteurl ); + // @todo Replace with some favicon lookup. + //$blavatar = 'Blavatar'; + $blavatar = 'Blavatar';; + + $marker = ''; + if ( strlen($blog->blogname) > 35 ) + $marker = '...'; + + if ( empty( $blog->blogname ) ) + $blogname = $blog->domain; + else + $blogname = substr( $blog->blogname, 0, 35 ) . $marker; + + if ( !isset( $blog->visible ) || $blog->visible === true ) { + $wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'blog-' . $blog->userblog_id, 'title' => $blavatar . $blogname, 'href' => constant( 'PROTO' ) . $blogdomain . '/wp-admin/' ) ); + $wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-d', 'title' => __( 'Dashboard' ), 'href' => constant( 'PROTO' ) . $blogdomain . '/wp-admin/' ) ); + $wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-n', 'title' => __( 'New Post' ), 'href' => constant( 'PROTO' ) . $blogdomain . '/wp-admin/post-new.php' ) ); + // @todo, stats plugins should add this: + //$wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-s', 'title' => __( 'Blog Stats' ), 'href' => constant( 'PROTO' ) . $blogdomain . '/wp-admin/index.php?page=stats' ) ); + $wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-c', 'title' => __( 'Manage Comments' ), 'href' => constant( 'PROTO' ) . $blogdomain . '/wp-admin/edit-comments.php' ) ); + $wp_admin_bar->add_menu( array( 'parent' => 'blog-' . $blog->userblog_id, 'id' => 'blog-' . $blog->userblog_id . '-v', 'title' => __( 'Read Blog' ), 'href' => constant( 'PROTO' ) . $blogdomain ) ); + } + $counter++; + } + + /* Add the "Manage Blogs" menu item */ + // @todo, use dashboard blog. + $wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'manage-blogs', 'title' => __( 'Manage Blogs' ), admin_url('my-sites.php') ) ); + + /* Add the 'My Dashboard' menu if the user only has one blog. */ + } else { + $wp_admin_bar->add_menu( array( 'id' => 'my-blogs', 'title' => __( 'My Blog' ), 'href' => $wp_admin_bar->user->account_domain ) ); + + $wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'blog-1-d', 'title' => __( 'Dashboard' ), 'href' => admin_url() ) ); + $wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'blog-1-n', 'title' => __( 'New Post' ), 'href' => admin_url('post-new.php') ) ); + // @todo Stats plugins should add this. + //$wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'blog-1-s', 'title' => __( 'Blog Stats' ), 'href' => admin_ur;('index.php?page=stats') ) ); + $wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'blog-1-c', 'title' => __( 'Manage Comments' ), 'href' => admin_url('edit-comments.php') ) ); + $wp_admin_bar->add_menu( array( 'parent' => 'my-blogs', 'id' => 'blog-1-v', 'title' => __( 'Read Blog' ), 'href' => home_url() ) ); + } +} +add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_my_blogs_menu', 30 ); + +/** + * Show the blavatar of the current blog as a separator. + */ +function wp_admin_bar_blog_separator() { + global $wp_admin_bar, $current_user, $current_blog; + + if ( !is_object( $wp_admin_bar ) ) + return false; + + $default = includes_url('images/wpmini-blue.png'); + + $wp_admin_bar->add_menu( array( 'id' => 'blog', 'title' => '' . __( 'Current blog avatar' ) . '', 'href' => home_url() ) ); +} +add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_blog_separator', 40 ); + +/** + * Use the $wp_admin_bar global to add a menu for blog info, accessable to all users. + */ +function wp_admin_bar_bloginfo_menu() { + global $wp_admin_bar; + + if ( !is_object( $wp_admin_bar ) ) + return false; + + /* Add the Blog Info menu */ + $wp_admin_bar->add_menu( array( 'id' => 'bloginfo', 'title' => __( 'Blog Info' ), 'href' => '' ) ); + + $wp_admin_bar->add_menu( array( 'parent' => 'bloginfo', 'title' => __( 'Get Shortlink' ), 'href' => '', 'meta' => array( 'onclick' => 'javascript:function wpcomshort() { var url=document.location;var links=document.getElementsByTagName('link');var found=0;for(var i = 0, l; l = links[i]; i++){if(l.getAttribute('rel')=='shortlink') {found=l.getAttribute('href');break;}}if (!found) {for (var i = 0; l = document.links[i]; i++) {if (l.getAttribute('rel') == 'shortlink') {found = l.getAttribute('href');break;}}}if (found) {prompt('URL:', found);} else {alert('No shortlink available for this page'); } return false; } wpcomshort();' ) ) ); +} +add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_bloginfo_menu', 50 ); + +/** + * Use the $wp_admin_bar global to add the "Edit Post" menu when viewing a single post. + */ +function wp_admin_bar_edit_menu() { + global $post, $wp_admin_bar; + + if ( !is_object( $wp_admin_bar ) ) + return false; + + if ( !is_single() && !is_page() ) + return false; + + if ( !$post_type_object = get_post_type_object( $post->post_type ) ) + return false; + + if ( !current_user_can( $post_type_object->cap->edit_post, $post->ID ) ) + return false; + + $wp_admin_bar->add_menu( array( 'id' => 'edit', 'title' => __( 'Edit' ), 'href' => get_edit_post_link( $post->ID ) ) ); +} +add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_edit_menu', 100 ); + +/** + * Load up the CSS needed to render the admin bar nice and pretty. + */ +function wp_admin_bar_css() { + global $pagenow, $wp_locale; + + if ( !is_user_logged_in() ) + return false; + + if ( 'press-this.php' == $pagenow ) + return; + + $nobump = false; + + /* Wish we could use wp_enqueue_style() here, but it will not let us pass GET params to the stylesheet correctly. */ + ?> + + + + diff --git a/wp-includes/admin-bar/admin-bar-class.php b/wp-includes/admin-bar/admin-bar-class.php new file mode 100644 index 0000000000..91e30dd5fd --- /dev/null +++ b/wp-includes/admin-bar/admin-bar-class.php @@ -0,0 +1,168 @@ +user = new stdClass; + $this->menu = new stdClass; + + /* Populate settings we need for the menu based on the current user. */ + $this->user->blogs = get_ordered_blogs_of_user( $current_user->id ); + if ( is_multisite() ) { + $this->user->active_blog = get_active_blog_for_user( $current_user->id ); + $this->user->domain = ( $this->user->active_blog == 'username only' ) ? get_dashboard_blog() : trailingslashit( get_home_url( $this->user->active_blog->blog_id ) ); + $this->user->account_domain = $this->user->domain; + } else { + $this->user->active_blog = $this->user->blogs[$blog_id]; + $this->user->domain = home_url(); + $this->user->account_domain = home_url(); + } + $this->user->locale = get_locale(); + } + + function add_menu( $args = array() ) { + $defaults = array( + 'title' => false, + 'href' => false, + 'parent' => false, // false for a root menu, pass the ID value for a submenu of that menu. + 'id' => false, // defaults to a sanitized title value. + 'meta' => false // array of any of the following options: array( 'html' => '', 'class' => '', 'onclick' => '', target => '' ); + ); + + $r = wp_parse_args( $args, $defaults ); + extract( $r, EXTR_SKIP ); + + if ( empty( $title ) ) + return false; + + /* Make sure we have a valid ID */ + if ( empty( $id ) ) + $id = esc_attr( sanitize_title( trim( $title ) ) ); + + if ( !empty( $parent ) ) { + /* Add the menu to the parent item */ + $child = array( + 'id' => $id, + 'title' => $title, + 'href' => $href + ); + + if ( !empty( $meta ) ) + $child['meta'] = $meta; + + $this->add_node( $parent, $this->menu, $child ); + } else { + /* Add the menu item */ + $this->menu->{$id} = array( + 'title' => $title, + 'href' => $href + ); + + if ( !empty( $meta ) ) + $this->menu->{$id}['meta'] = $meta; + } + } + + function remove_menu( $id ) { + return $this->remove_node( $id, $this->menu ); + } + + function render() { + ?> +
+ + +
+
+ +
+
+
+ + menu = null; + } + + /* Helpers */ + function recursive_render( $id, &$menu_item ) { ?> + + +
  • "> + onclick=""target=""> + + + + + + + + +
  • &$menu_item ) { + if ( $parent_id == $id ) { + $menu->{$parent_id}['children']->{$child['id']} = $child; + $child = null; + return true; + } + + if ( !empty( $menu->{$id}['children'] ) ) + $this->add_node( $parent_id, $menu->{$id}['children'], $child ); + } + $child = null; + + return false; + } + + function remove_node( $id, &$menu ) { + foreach( $menu as $menu_item_id => &$menu_item ) { + if ( $menu_item_id == $id ) { + $menu_item = null; + return true; + } + + if ( !empty( $menu->{$menu_item_id}['children'] ) ) + $this->remove_node( $id, $menu->{$menu_item_id}['children'] ); + } + + return false; + } + + function load_user_locale_translations() { + $this->need_to_change_locale = ( get_locale() != $this->user->locale ); + if ( !$this->need_to_change_locale ) return; + $this->previous_translations = get_translations_for_domain( 'default' ); + $this->adminbar_locale_filter = lambda( '$_', '$GLOBALS["wp_admin_bar"]->user->locale;' ); + unload_textdomain( 'default' ); + add_filter( 'locale', $this->adminbar_locale_filter ); + load_default_textdomain(); + $this->changed_locale = true; + } + + function unload_user_locale_translations() { + global $l10n; + if ( !$this->changed_locale ) return; + remove_filter( 'locale', $this->adminbar_locale_filter ); + $l10n['default'] = &$this->previous_translations; + + } +} +?> diff --git a/wp-includes/admin-bar/admin-bar-css.php b/wp-includes/admin-bar/admin-bar-css.php new file mode 100644 index 0000000000..64513fecf8 --- /dev/null +++ b/wp-includes/admin-bar/admin-bar-css.php @@ -0,0 +1,453 @@ + + +#wpadminbar { direction:ltr; background:#666 url() 0 -222px repeat-x; color:#ddd; font:12px Arial, Helvetica, sans-serif; height:28px; left:0; margin:0; position:fixed; top:0; width:100%; z-index:99999; min-width: 960px; } +#wpadminbar ul, #wpadminbar ul li { position: relative; z-index: 99999; } +#wpadminbar ul li img { vertical-align: middle !important; margin-right: 8px !important; border: none !important; padding: 0 !important; } +#wpadminbar .quicklinks > ul > li > a { border-right: 1px solid #686868; border-left: 1px solid #808080; } +#wpadminbar .quicklinks > ul > li.ab-subscriptions > a, #wpadminbar .quicklinks > ul > li:last-child > a { border-right: none; } +#wpadminbar .quicklinks > ul > li.hover > a { border-left-color: #707070; } +#wpadminbar a { outline: none; } +#wpadminbar .avatar {border:1px solid #999 !important;padding:0 !important;margin:-3px 5px 0 0 !important;vertical-align:middle;float:none;display:inline !important; } +#wpadminbar .menupop ul li a {color:#555 !important;text-shadow:none;font-weight:normal;white-space:nowrap;} +#wpadminbar .menupop a > span {background:url() 100% 100.4% no-repeat;padding-right:.8em;line-height: 28px;} +#wpadminbar .menupop ul li a > span { display: block; background:url() 100% 97.2% no-repeat;padding-right:1.5em;line-height: 28px;} +#wpadminbar .menupop ul li a span#awaiting-mod { display: inline; background: #aaa; color: #fff; padding: 1px 5px; font-size: 10px; font-family: verdana; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; } +#wpadminbar .menupop ul li a:hover span#awaiting-mod { background: #fff; color: #888; } +#wpadminbar .menupop ul {-moz-box-shadow:0 4px 8px rgba(0,0,0,0.1);-webkit-box-shadow:0 4px 8px rgba(0,0,0,0.1);background:#fff;display:none;position:absolute;border:1px solid #dfdfdf;border-top:none !important;float:none} +html>body #wpadminbar .menupop ul {background:rgba(255,255,255,0.97);border-color:rgba(0,0,0,0.1);} +#wpadminbar .menupop.ab-my-account ul, #wpadminbar .menupop.ab-my-dash ul, #wpadminbar .menupop.ab-new-post ul {min-width:140px} +#wpadminbar .menupop li {float:none;margin:0;padding:0;background-image:none;} +#wpadminbar .quicklinks a {border:none;color:#ddd !important;text-shadow:#555 0px -1px 0px;display:block;font:13px Arial, Helvetica, sans-serif;font-weight:normal;letter-spacing:normal;padding:0 0.85em;line-height:28px;text-decoration:none !important;} +#wpadminbar .quicklinks a:hover {text-shadow:#333 0px -1px 0px;} +#wpadminbar li.ab-privacy { float: right; background: #333; } +#wpadminbar li.ab-privacy > a > span { background: none; padding: 0; } +#wpadminbar li.ab-privacy span#priv-icon { display: block; text-indent: -999em; background:url() 40% 59.7% no-repeat; padding: 0; width: 13px; margin-right: -3px; } + +#wpadminbar li.ab-sadmin { float: right; background: #555 } +#wpadminbar li.ab-sadmin ul, #wpadminbar li.ab-privacy ul { right: 0; float: right; } +#wpadminbar li.ab-sadmin > a { font-size: 11px !important; padding: 0 7px !important; border: none !important; border-left: 1px solid #666 !important; } + +#wpadminbar li.ab-sadmin ul a, #wpadminbar li.ab-privacy a { border-right: none !important; border-left: none !important; } +#wpadminbar li.ab-sadmin ul li { right: 0; float: right; text-align: left; width: 100%; } +#wpadminbar li.ab-sadmin ul li a { padding-left: 1.75em; } +#wpadminbar li.ab-sadmin ul li a > span { background:url() 0% 101.8% no-repeat;padding-left: 1.25em; margin-left: -1.25em; line-height: 28px; padding-right: 0 !important; } +#wpadminbar li a.loading { background: url() 32% 59.8% no-repeat !important; text-indent: -999em; overflow: hidden; padding: 0 16px 0 0; height: 28px; display: block; float: left; margin-right: 2px; } + +#wpadminbar li:hover {background: #555 url() 0 -282px repeat-x;} +#wpadminbar li li:hover { color:#fff !important; background: #888 url() 0 -222px repeat-x !important;text-shadow: #666 0px -1px 0px;} +#wpadminbar li li:hover > a { color:#fff !important; } +.quicklinks ul {list-style:none;margin:0;padding:0;text-align:left} +.quicklinks ul li {float:left;margin:0} + +#adminbarlogin {float:left;display:inline;} + +#adminbarsearch {float:right; } +#adminbarsearch {height: 18px;padding: 3px;} +#adminbarsearch * {color: #555;font-size:12px;} +#adminbarsearch label, #adminbarsearch a { height: 28px; color: #ccc; display:block;float:left;padding:3px 4px;text-shadow:0px -1px 0px #444;} +#adminbarsearch a {text-decoration:underline;} +#adminbarsearch a:hover {color:#fff;} + +#wpadminbar li.ab-me:hover, #wpadminbar li.ab-blog:hover { background:none;} +#wpadminbar li.ab-me > a, #wpadminbar li.ab-blog > a { line-height: 18px !important; border: none !important; background:url() 100% 59.8% no-repeat; height: 28px; padding: 0 1.15em 0 0.7em; } +#wpadminbar li.ab-me > a.hover, #wpadminbar li.ab-blog > a.hover { background-position: 67% 59.8%; } +#wpadminbar li.ab-me img.avatar, #wpadminbar li.ab-blog img.avatar { margin: 4px 0 0 0 !important; vertical-align: middle; background: #eee; width: 16px !important; height: 16px !important; } +#wpadminbar li.ab-my-account a, #wpadminbar li.ab-bloginfo a { border-left: none !important; padding-left: 0.7em !important; margin-top: 0 !important; } +#wpadminbar li.ab-my-account > ul, #wpadminbar li.ab-bloginfo > ul { left: -7px; } +#wpadminbar ul li img { width: 16px !important; height: 16px !important; } + +#wpadminbar ul li a strong.count { text-shadow: none; background: #ddd; color: #555; margin-left: 5px; padding: 1px 6px; top: -1px; position: relative; font-size: 9px; -moz-border-radius: 7px; -webkit-border-radius: 7px; border-radius: 7px; font-weight: normal } + +#wpadminbar #q { + line-height:normal !important; + width:140px !important; + margin-top:0px !important; +} +.adminbar-input { + display:block !important; + float:left !important; + font:12px Arial,Helvetica,sans-serif !important; + border:1px solid #626262 !important; + padding:2px 3px !important; + margin-right:3px !important; + background:#ddd url() top left no-repeat !important; + -webkit-border-radius:0 !important; + -khtml-border-radius:0 !important; + -moz-border-radius:0 !important; + border-radius:0 !important; + outline:none; + text-shadow:0 1px 0 #fff; +} +button.adminbar-button { + position:relative; + border:0; + cursor:pointer; + overflow:visible; + margin:0 !important; + float:left; + background:url() right -107px no-repeat; + padding:0 14px 0 0; + text-align:center; +} +button.adminbar-button span { + position:relative; + display:block; + white-space:nowrap; + height:19px; + background:url() left -69px no-repeat; + padding:3px 0 0 14px; + font:12px Arial,Helvetica,sans-serif !important; + font-weight:bold !important; + color:#444 !important; + text-shadow:0px 1px 0px #eee !important; +} +button.adminbar-button:active { + background-position:right -184px !important; + text-shadow:0px 1px 0px #eee !important; +} +button.adminbar-button:hover span { + color:#000 !important; +} +button.adminbar-button:active span { + background-position:left -146px !important; +} +button.adminbar-button::-moz-focus-inner { + border:none; +} +@media screen and (-webkit-min-device-pixel-ratio:0) { + button.adminbar-button span { + margin-top: -1px; + } +} + + + #wpadminbar { + direction:rtl; + font-family: Tahoma, Arial ,sans-serif; + right:0; + left:auto; + } + #wpadminbar div, #wpadminbar ul, #wpadminbar ul li { + min-height: 0; + } + #wpadminbar ul li img { margin-left: 8px !important; margin-right: 0 !important; } + #wpadminbar .quicklinks > ul > li > a { border-left: 1px solid #686868; border-right: 1px solid #808080;} + #wpadminbar .quicklinks > ul > li.ab-subscriptions > a, #wpadminbar .quicklinks > ul > li:last-child > a { border-left: none; border-right: 1px solid #808080;} + #wpadminbar .quicklinks > ul > li.hover > a { border-right-color: #707070; border-left-color: #686868; } + #wpadminbar .avatar {margin: -3px 0 0 5px !important; float:none; } + #wpadminbar .menupop a > span {background-position: 0 100.4%; padding-left:.8em;} + #wpadminbar .menupop ul li a > span { background-position: 0% 97.2%; padding-right:0;padding-left:1.5em } + #wpadminbar .menupop ul {right: 0; width:100%; min-width:150px;} + #wpadminbar .ab-my-account ul { width:200px;} + #wpadminbar .ab-my-blogs ul { width:300px;} + #wpadminbar .ab-my-blogs ul ul { width:200px;} + #wpadminbar .ab-subscribe ul { width:150px;} + #wpadminbar .ab-bloginfo ul { width:200px;} + #wpadminbar .ab-subscribe ul { width:150px;} + #wpadminbar .ab-subscriptions ul { width:200px;} + #wpadminbar .menupop ul li {width:auto} + #wpadminbar .quicklinks a {font-family: Tahoma, Arial, Helvetica, sans-serif;} + #wpadminbar li.ab-privacy { float: left; } + #wpadminbar li.ab-privacy span#priv-icon { text-indent: 999em; background-position: 60% 59.7%; padding: 0; margin-right: 0; margin-left: -3px;} + + #wpadminbar li.ab-sadmin { float: left; } + #wpadminbar li.ab-sadmin ul, #wpadminbar li.ab-privacy ul { right: auto; left: 0; float: left; } + #wpadminbar li.ab-sadmin > a { border-right: 1px solid #666 !important; border-left:none !important;} + + #wpadminbar li.ab-sadmin ul a, #wpadminbar li.ab-privacy a { border-right: none !important; border-left: none !important; } + #wpadminbar li.ab-sadmin ul li { left: 0; right:auto; float: left; text-align: right; } + + + #wpadminbar li.ab-sadmin ul li a { padding-right: 1.75em; padding-left: 0 } + #wpadminbar li.ab-sadmin ul li a > span { background-position: 100% 101.8%; padding-right: 1.25em !important; padding-left: 0 !important; margin-right: -1.25em; margin-left: 0; } + #wpadminbar li a.loading { background-position: right 50% !important; padding-right: 29px; padding-left: 0;} + #wpadminbar li.subscribed a strong { background-position: 68% 59.8% !important; padding: 0 0 0 16px; float: right; margin-left: 2px; } + + + .quicklinks ul {text-align:right} + .quicklinks ul li {float:right;} + + #adminbarlogin {float:right;} + + #adminbarsearch {display:none;} + #adminbarsearch label, #adminbarsearch a { float:right;} + + #wpadminbar li.ab-me > a, #wpadminbar li.ab-blog > a { background-position:0% 59.8%; padding: 0 0.7em 0 1.15em; } + #wpadminbar li.ab-me > a.hover, #wpadminbar li.ab-blog > a.hover { background-position: 33% 59.8%; } + #wpadminbar li.ab-my-account a, #wpadminbar li.ab-bloginfo a { border-right: none !important; padding-right: 0.7em !important; } + #wpadminbar li.ab-my-account > ul, #wpadminbar li.ab-bloginfo > ul { right: -7px; left:auto;} + + #wpadminbar ul li a strong.count { margin-right: 5px; margin-left: 0; position:static} + + + .adminbar-input { + float:right !important; + font-family: Tahoma, Arial,Helvetica,sans-serif !important; + margin-right:3px !important; + margin-left:0 !important; + background-position: right top !important; + } + button.adminbar-button { + float:right; + background-position: left -107px; + padding:0 0 0 14px; + } + button.adminbar-button span { + background-position: right -69px; + padding:3px 14px 0 0; + font-family: Tahoma, Arial,Helvetica,sans-serif !important; + } + button.adminbar-button:active { + background-position:left -184px !important; + } + button.adminbar-button:active span { + background-position:right -146px !important; + } + + body { padding-top: 28px !important; } + + + + body { padding-top: 28px; background-position: 0px 28px; } + + + + #querylist { + font-family: Arial, Tahoma, sans-serif; + display: none; + position: absolute; + top: 50px; + left: 50px; + right: 50px; + background: #fff; + padding: 20px; + -moz-box-shadow: 0 0 15px #888; + -webkit-box-shadow: 0 0 15px #888; + box-shadow: 0 0 15px #888; + z-index: 99999; + border: 10px solid #f0f0f0; + color: #000; + line-height: 150% !important; + } + #querylist pre { + font-size: 12px; + padding: 10px; + } + + #querylist h1 { + font-family: georgia, times, serif; + text-align: center; + font-size: 24px; + padding: 20px 5px; + background: #eee; + color: #555; + margin: 0; + } + #querylist div#debug-status { + background: #ccc; + color: #fff; + overflow: hidden; + height: 21px; + font-size: 14px; + font-family: georgia, times, serif; + padding: 7px 15px; + } + #querylist .left { float: left; } + #querylist .right { float: right; } + + #querylist h1, #querylist h2, #querylist h3 { + font-weight: normal; + } + + #querylist ul.debug-menu-links { + clear: left; + background: #ccc; + padding: 10px 15px 0; + overflow: hidden; + list-style: none; + margin: 0; + padding: 0 0 0 15px; + } + #querylist ul.debug-menu-links li { + float: left; + margin-right: 10px; + margin-bottom: 0 !important; + } + + #querylist ul.debug-menu-links li a { + outline: none; + display: block; + padding: 5px 9px; + margin-right: 0; + background: #bbb; + color: #fff !important; + text-decoration: none !important; + font-weight: normal; + font-size: 12px; + color: #555; + -webkit-border-top-right-radius: 4px; + -webkit-border-top-left-radius: 4px; + -moz-border-radius-topright: 4px; + -moz-border-radius-topleft: 4px; + } + #querylist ul.debug-menu-links li.current a { + background: #fff; + color: #555 !important; + } + + #querylist h2 { + float: left; + min-width: 150px; + border: 1px solid #eee; + padding: 5px 10px 15px; + clear: none; important; + text-align: center; + font-family: georgia, times, serif; + font-size: 28px; + margin: 15px 10px 15px 0 !important; + } + #querylist h2 span { + font-size: 12px; + color: #888; + text-transform: uppercase; + white-space: nowrap; + display: block; + margin-bottom: 5px; + } + + #object-cache-stats h2 { + border: none; + float: none; + text-align: left; + font-size: 22px; + margin-bottom: 0; + } + + #object-cache-stats ul.debug-menu-links { + padding: 0; + margin: 0; + background: none; + } + #object-cache-stats ul.debug-menu-links li { + float: left; + margin-bottom: 10px !important; + background: none !important; + border: 1px solid #eee !important; + color: #555 !important; + } + #object-cache-stats ul.debug-menu-links li.current a { + background: #ccc !important; + color: #fff !important; + -webkit-border-top-right-radius: 0; + -webkit-border-top-left-radius: 0; + -moz-border-radius-topright: 0; + -moz-border-radius-topleft: 0; + } + + #object-cache-stats ul.debug-menu-links li a { + background: none; + color: #555 !important; + overflow: hidden; + } + + #querylist h3 { + margin-bottom: 15px; + } + + #querylist ol#wpd-queries { + padding: 0 !important; + margin: 0 !important; + list-style: none; + clear: left; + } + #querylist ol#wpd-queries li { + padding: 10px; + background: #f0f0f0; + margin: 0 0 10px 0; + } + #querylist ol#wpd-queries li div.qdebug { + background: #e8e8e8; + margin: 10px -10px -10px -10px; + padding: 5px 150px 5px 5px; + font-size: 11px; + position: relative; + min-height: 20px; + } + + #querylist ol#wpd-queries li div.qdebug span { + position: absolute; + right: 10px; + top: 5px; + white-space: nowrap; + } + + #querylist a { + text-decoration: underline !important; + color: blue !important; + } + #querylist a:hover { + text-decoration: none !important; + } + #querylist .debug-menu-target { + display: none; + } + + #querylist ol { + font: 12px Monaco, "Courier New", Courier, Fixed !important; + line-height: 180% !important; + } + + #wpadminbar #admin-bar-micro ul li { + list-style-type: none; + position: relative; + margin: 0; + padding: 0; + } + #wpadminbar #admin-bar-micro ul ul, #wpadminbar #admin-bar-micro #awaiting-mod, #wpadminbar .ab-sadmin .count-0 { + display: none !important; + } + #wpadminbar #admin-bar-micro ul li:hover > ul { + display: block; + position: absolute; + top: -1px; + left: 100%; + } + #wpadminbar #admin-bar-micro li a { + display: block; + text-decoration: none; + } + #wpadminbar #admin-bar-micro li li a { + background: #ddd; + } + #wpadminbar #admin-bar-micro li li li a { + background: #fff; + } + + + + #querylist { + direction: ltr; + } + + #wpadminbar #admin-bar-micro ul li:hover > ul { + left: auto; + right: 100%; + } + + \ No newline at end of file diff --git a/wp-includes/admin-bar/admin-bar-debug.php b/wp-includes/admin-bar/admin-bar-debug.php new file mode 100644 index 0000000000..5d1c0df207 --- /dev/null +++ b/wp-includes/admin-bar/admin-bar-debug.php @@ -0,0 +1,161 @@ +num_queries; + $seconds = timer_stop(); + + /* Add the main siteadmin menu item */ + $wp_admin_bar->add_menu( array( 'id' => 'queries', 'title' => "{$queries}q/{$seconds}", 'href' => 'javascript:toggle_query_list()', 'meta' => array( 'class' => 'ab-sadmin' ) ) ); +} +add_action( 'wp_before_admin_bar_render', 'wp_admin_bar_debug_menu', 1000 ); + +function wp_admin_bar_query_debug_list() { + global $wpdb, $wp_object_cache; + + if ( !is_super_admin() ) + return false; + + $debugs = array(); + + if ( defined('SAVEQUERIES') && SAVEQUERIES ) + $debugs['wpdb'] = array( __('Queries'), 'wp_admin_bar_debug_queries' ); + + if ( is_object($wp_object_cache) && method_exists($wp_object_cache, 'stats') ) + $debugs['object-cache'] = array( __('Object Cache'), 'wp_admin_bar_debug_object_cache' ); + + $debugs = apply_filters( 'wp_admin_bar_debugs_list', $debugs ); + + if ( empty($debugs) ) + return; + +?> + +
    + +

    Debugging blog # on

    +
    +

    +

    PHP Version:

    +
    + + +
    + + $debug_output ) : ?> + +
    > + +
    + + + +
    + + + +
    + +queries) ) { + $show_many = isset($_GET['debug_queries']); + + if ( $wpdb->num_queries > 500 && !$show_many ) + $out .= "

    There are too many queries to show easily! Show them anyway.

    "; + + $out .= '
      '; + $first_query = 0; + $counter = 0; + + foreach ( $wpdb->queries as $q ) { + list($query, $elapsed, $debug) = $q; + + $total_time += $elapsed; + + if ( !$show_many && ++$counter > 500 ) + continue; + + $query = nl2br(esc_html($query)); + + // $dbhname, $host, $port, $name, $tcp, $elapsed + $out .= "
    1. $query
      $debug #{$counter} (" . number_format(sprintf('%0.1f', $elapsed * 1000), 1, '.', ',') . "ms)
    2. \n"; + } + $out .= '
    '; + } else { + $out .= "

    There are no queries on this page, you won the prize!!! :)

    "; + } + + $query_count = '

    Total Queries:' . number_format( $wpdb->num_queries ) . "

    \n"; + $query_time = '

    Total query time:' . number_format(sprintf('%0.1f', $total_time * 1000), 1) . "ms

    \n"; + $memory_usage = '

    Peak Memory Used:' . number_format( memory_get_peak_usage( ) ) . " bytes

    \n"; + + $out = $query_count . $query_time . $memory_usage . $out; + + return $out; +} + +function wp_admin_bar_debug_object_cache() { + global $wp_object_cache; + ob_start(); + echo "
    "; + $wp_object_cache->stats(); + echo "
    "; + $out = ob_get_contents(); + ob_end_clean(); + + return $out; +} + +?> \ No newline at end of file diff --git a/wp-includes/admin-bar/admin-bar-superadmin.php b/wp-includes/admin-bar/admin-bar-superadmin.php new file mode 100644 index 0000000000..c93e6a3449 --- /dev/null +++ b/wp-includes/admin-bar/admin-bar-superadmin.php @@ -0,0 +1,156 @@ +add_menu( array( 'id' => 'superadmin', 'title' => 'μ', 'href' => '', 'meta' => array( 'class' => 'ab-sadmin' ) ) ); + + wp_admin_bar_build_snackmenu(); + + /* Get the settings we need for the current blog */ + $matureaction = $current_blog->mature ? 'unmatureblog' : 'matureblog'; + $maturetext = $current_blog->mature ? esc_attr__('Unmark as mature') : esc_attr__('Mark as mature'); + $suspendtext = $current_blog->spam ? esc_attr('Unsuspend blog') : esc_attr('Suspend blog'); + $suspendaction = $current_blog->spam ? 'unspamblog' : 'spamblog'; + $mature_url = admin_url( "ms-edit.php?action=confirm&action2={$matureaction}&id={$current_blog->blog_id}&msg=" . urlencode( 'Are you sure you want to ' . strtolower( $maturetext ) . " {$current_blog->domain} as mature?" ) ); + $suspend_url = admin_url( "ms-edit.php?action=confirm&action2={$suspendaction}&id={$current_blog->blog_id}&msg=" . urlencode( 'Are you sure you want to ' . strtolower( $suspendtext ) . " {$current_blog->domain} ?" ) ); + + /* Add the submenu items to the Super Admin menu */ + $wp_admin_bar->add_menu( array( 'parent' => 'superadmin', 'title' => __( 'Blog Dashboard' ), 'href' => admin_url(), 'position' => 10 ) ); + $wp_admin_bar->add_menu( array( 'parent' => 'superadmin', 'title' => __( 'Blog Options' ), 'href' => admin_url( "ms-sites.php?action=blogs&searchaction=id&s={$current_blog->blog_id}" ), 'position' => 30 ) ); + $wp_admin_bar->add_menu( array( 'parent' => 'superadmin', 'title' => "$maturetext", 'href' => $mature_url, 'position' => 50 ) ); + $wp_admin_bar->add_menu( array( 'parent' => 'superadmin', 'title' => "$suspendtext", 'href' => $suspend_url, 'position' => 80 ) ); +} + +function wp_admin_bar_build_snackmenu() { + global $wp_admin_bar, $menu, $submenu, $pagenow; + + if ( !is_object( $wp_admin_bar ) || !is_super_admin() ) + return false; + + // Hide moderation count, filter removed at the bottom of this function + add_filter( 'wp_count_comments', 'wp_admin_bar_removemodcount' ); + + require_once( ABSPATH . 'wp-admin/includes/admin.php' ); + + // menu.php assumes it is in the global scope and relies on the $wp_taxonomies global array + $wp_taxonomies = array(); + require_once( ABSPATH . 'wp-admin/menu.php' ); + + /* Add the snack menu submenu to the superadmin menu */ + $wp_admin_bar->add_menu( array( 'parent' => 'superadmin', 'title' => 'Snack Menu', 'href' => '/wp-admin/' ) ); + + /* Loop through the submenus and add them */ + foreach ( (array) $menu as $key => $item ) { + $admin_is_parent = false; + $submenu_as_parent = false; + + if ( $submenu_as_parent && !empty($submenu[$item[2]]) ) { + $submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index. + $menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]); + $menu_file = $submenu[$item[2]][0][2]; + + if ( false !== $pos = strpos($menu_file, '?') ) + $menu_file = substr($menu_file, 0, $pos); + if ( ( ('index.php' != $submenu[$item[2]][0][2]) && file_exists(WP_PLUGIN_DIR . "/$menu_file") ) || !empty($menu_hook)) { + $admin_is_parent = true; + $wp_admin_bar->add_menu( array( 'parent' => 'snack-menu', 'title' => $item[0], 'href' => admin_url("admin.php?page={$submenu[$item[2]][0][2]}") ) ); + } else { + $wp_admin_bar->add_menu( array( 'parent' => 'snack-menu', 'title' => $item[0], 'href' => admin_url("{$submenu[$item[2]][0][2]}") ) ); + } + } else if ( current_user_can($item[1]) ) { + $menu_hook = get_plugin_page_hook($item[2], 'admin.php'); + $menu_file = $item[2]; + + if ( false !== $pos = strpos($menu_file, '?') ) + $menu_file = substr($menu_file, 0, $pos); + if ( ('index.php' != $item[2]) && file_exists(WP_PLUGIN_DIR . "/$menu_file") || !empty($menu_hook) ) { + $admin_is_parent = true; + $wp_admin_bar->add_menu( array( 'parent' => 'snack-menu', 'title' => $item[0], 'href' => admin_url("admin.php?page={$item[2]}") ) ); + } else { + $wp_admin_bar->add_menu( array( 'parent' => 'snack-menu', 'title' => $item[0], 'href' => admin_url("{$item[2]}") ) ); + } + } + + if ( !empty($submenu[$item[2]]) ) { + $first = true; + $unique_submenu = array(); + + foreach ( $submenu[$item[2]] as $sub_key => $sub_item ) { + if ( !current_user_can($sub_item[1]) || in_array( $sub_item[0], $unique_submenu ) ) + continue; + + $unique_submenu[] = $sub_item[0]; + + if ( $first ) + $first = false; + + $menu_file = $item[2]; + if ( false !== $pos = strpos($menu_file, '?') ) + $menu_file = substr($menu_file, 0, $pos); + + $menu_hook = get_plugin_page_hook($sub_item[2], $item[2]); + $sub_file = $sub_item[2]; + if ( false !== $pos = strpos($sub_file, '?') ) + $sub_file = substr($sub_file, 0, $pos); + + if ( ( ('index.php' != $sub_item[2]) && file_exists(WP_PLUGIN_DIR . "/$sub_file") ) || ! empty($menu_hook) ) { + // If admin.php is the current page or if the parent exists as a file in the plugins or admin dir + + $parent_exists = (!$admin_is_parent && file_exists(WP_PLUGIN_DIR . "/$menu_file") && !is_dir(WP_PLUGIN_DIR . "/{$item[2]}") ) || file_exists($menu_file); + if ( $parent_exists ) + $wp_admin_bar->add_menu( array( 'parent' => sanitize_title( $item[0] ), 'title' => $sub_item[0], 'href' => admin_url("{$item[2]}?page={$sub_item[2]}") ) ); + elseif ( 'admin.php' == $pagenow || !$parent_exists ) + $wp_admin_bar->add_menu( array( 'parent' => sanitize_title( $item[0] ), 'title' => $sub_item[0], 'href' => admin_url("admin.php?page={$sub_item[2]}") ) ); + else + $wp_admin_bar->add_menu( array( 'parent' => sanitize_title( $item[0] ), 'title' => $sub_item[0], 'href' => admin_url("{$item[2]}?page={$sub_item[2]}") ) ); + } else { + $wp_admin_bar->add_menu( array( 'parent' => sanitize_title( $item[0] ), 'title' => $sub_item[0], 'href' => admin_url("{$sub_item[2]}") ) ); + } + } + } + } + + remove_filter( 'wp_count_comments', 'wp_admin_bar_removemodcount' ); +} + +// Short circuits wp_count_comments() for the front end +function wp_admin_bar_removemodcount( $stats ) { + if ( is_admin() ) + return $stats; + + $stats = array( + 'moderated' => 0, + 'approved' => 0, + 'spam' => 0, + 'trash' => 0, + 'post-trashed' => 0, + 'total_comments' => 0, + ); + + return (object) $stats; +} + +?> diff --git a/wp-includes/images/admin-bar-sprite-rtl.png b/wp-includes/images/admin-bar-sprite-rtl.png new file mode 100644 index 0000000000..8f5362210f Binary files /dev/null and b/wp-includes/images/admin-bar-sprite-rtl.png differ diff --git a/wp-includes/images/admin-bar-sprite.png b/wp-includes/images/admin-bar-sprite.png new file mode 100644 index 0000000000..cd5aa77c18 Binary files /dev/null and b/wp-includes/images/admin-bar-sprite.png differ diff --git a/wp-includes/images/wpmini-blue.png b/wp-includes/images/wpmini-blue.png new file mode 100644 index 0000000000..13f3fa64dd Binary files /dev/null and b/wp-includes/images/wpmini-blue.png differ diff --git a/wp-includes/ms-functions.php b/wp-includes/ms-functions.php index cbd765be99..8cb2b0a87b 100644 --- a/wp-includes/ms-functions.php +++ b/wp-includes/ms-functions.php @@ -30,46 +30,6 @@ function get_admin_users_for_domain( $sitedomain = '', $path = '' ) { return false; } -function get_blogs_of_user( $id, $all = false ) { - global $wpdb; - - $cache_suffix = $all ? '_all' : '_short'; - $return = wp_cache_get( 'blogs_of_user_' . $id . $cache_suffix, 'users' ); - if ( $return ) - return apply_filters( 'get_blogs_of_user', $return, $id, $all ); - - $user = get_userdata( (int) $id ); - if ( !$user ) - return false; - - $blogs = $match = array(); - $prefix_length = strlen($wpdb->base_prefix); - foreach ( (array) $user as $key => $value ) { - if ( $prefix_length && substr($key, 0, $prefix_length) != $wpdb->base_prefix ) - continue; - if ( substr($key, -12, 12) != 'capabilities' ) - continue; - if ( preg_match( '/^' . $wpdb->base_prefix . '((\d+)_)?capabilities$/', $key, $match ) ) { - if ( count( $match ) > 2 ) - $blog_id = $match[ 2 ]; - else - $blog_id = 1; - $blog = get_blog_details( $blog_id ); - if ( $blog && isset( $blog->domain ) && ( $all == true || $all == false && ( $blog->archived == 0 && $blog->spam == 0 && $blog->deleted == 0 ) ) ) { - $blogs[ $blog_id ]->userblog_id = $blog_id; - $blogs[ $blog_id ]->blogname = $blog->blogname; - $blogs[ $blog_id ]->domain = $blog->domain; - $blogs[ $blog_id ]->path = $blog->path; - $blogs[ $blog_id ]->site_id = $blog->site_id; - $blogs[ $blog_id ]->siteurl = $blog->siteurl; - } - } - } - - wp_cache_add( 'blogs_of_user_' . $id . $cache_suffix, $blogs, 'users', 5 ); - return apply_filters( 'get_blogs_of_user', $blogs, $id, $all ); -} - function get_active_blog_for_user( $user_id ) { // get an active blog for user - either primary blog or from blogs list global $wpdb; $blogs = get_blogs_of_user( $user_id ); @@ -366,21 +326,6 @@ function wpmu_admin_redirect_add_updated_param( $url = '' ) { return $url; } -function is_blog_user( $blog_id = 0 ) { - global $wpdb; - - $current_user = wp_get_current_user(); - if ( !$blog_id ) - $blog_id = $wpdb->blogid; - - $cap_key = $wpdb->base_prefix . $blog_id . '_capabilities'; - - if ( is_array($current_user->$cap_key) && in_array(1, $current_user->$cap_key) ) - return true; - - return false; -} - function is_email_address_unsafe( $user_email ) { $banned_names = get_site_option( 'banned_email_domains' ); if ($banned_names && !is_array( $banned_names )) diff --git a/wp-includes/user.php b/wp-includes/user.php index 621fb978a1..ef5b1e010d 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -574,6 +574,167 @@ function get_users_of_blog( $id = '' ) { return get_users( array( 'blog_id' => $id ) ); } +/** + * Get the blogs a user belong to. + * + * $since 3.0.0 + * + * @param int $id User Id + * @param bool $all Whether to retrieve all blog details or an abbreviated set of details. Default is abbreviated. + * @return array A list of the user's blogs. + */ +function get_blogs_of_user( $id, $all = false ) { + global $wpdb; + + if ( !is_multisite() ) { + global $blog_id; + $blogs = array(); + $blogs[ $blog_id ]->userblog_id = $blog_id; + $blogs[ $blog_id ]->blogname = get_option('blogname'); + $blogs[ $blog_id ]->domain = ''; + $blogs[ $blog_id ]->path = ''; + $blogs[ $blog_id ]->site_id = 1; + $blogs[ $blog_id ]->siteurl = get_option('siteurl'); + return $blogs; + } + + $cache_suffix = $all ? '_all' : '_short'; + $return = wp_cache_get( 'blogs_of_user_' . $id . $cache_suffix, 'users' ); + if ( $return ) + return apply_filters( 'get_blogs_of_user', $return, $id, $all ); + + $user = get_userdata( (int) $id ); + if ( !$user ) + return false; + + $blogs = $match = array(); + $prefix_length = strlen($wpdb->base_prefix); + foreach ( (array) $user as $key => $value ) { + if ( $prefix_length && substr($key, 0, $prefix_length) != $wpdb->base_prefix ) + continue; + if ( substr($key, -12, 12) != 'capabilities' ) + continue; + if ( preg_match( '/^' . $wpdb->base_prefix . '((\d+)_)?capabilities$/', $key, $match ) ) { + if ( count( $match ) > 2 ) + $blog_id = $match[ 2 ]; + else + $blog_id = 1; + $blog = get_blog_details( $blog_id ); + if ( $blog && isset( $blog->domain ) && ( $all == true || $all == false && ( $blog->archived == 0 && $blog->spam == 0 && $blog->deleted == 0 ) ) ) { + $blogs[ $blog_id ]->userblog_id = $blog_id; + $blogs[ $blog_id ]->blogname = $blog->blogname; + $blogs[ $blog_id ]->domain = $blog->domain; + $blogs[ $blog_id ]->path = $blog->path; + $blogs[ $blog_id ]->site_id = $blog->site_id; + $blogs[ $blog_id ]->siteurl = $blog->siteurl; + } + } + } + + wp_cache_add( 'blogs_of_user_' . $id . $cache_suffix, $blogs, 'users', 5 ); + return apply_filters( 'get_blogs_of_user', $blogs, $id, $all ); +} + +function get_ordered_blogs_of_user( $user_id, $visibility = true ) { + $newblogs = $ordered = array(); + $blogs = get_blogs_of_user( $user_id ); + $order_meta = get_user_meta( $user_id, 'blog_order' ); + $visible_meta = get_user_meta( $user_id, 'blog_visibility' ); + + $order = $order_meta; + if ( !is_array( $order ) ) + $order = array(); + + $visible = $visible_meta; + if ( !is_array( $visible ) ) + $visible = array(); + + // Index the blogs by userblog_id and set the visibility flag + // Visibility is on by default, unless a linked site then off + foreach ( $blogs AS $blog ) { + $blog->visible = true; + + if ( isset( $visible[$blog->userblog_id] ) ) + $blog->visible = $visible[$blog->userblog_id]; + + $newblogs[$blog->userblog_id] = $blog; + } + + // Add the blogs to our list by order + foreach ( (array)$order AS $id ) { + // A previous change was saving the entire blog details into ordered, not just the blog ID - this detects it + if ( is_object( $id ) && isset( $id->userblog_id ) ) + $id = $id->userblog_id; + + if ( is_numeric( $id ) && isset( $newblogs[intval( $id )] ) ) { + $ordered[$id] = $newblogs[$id]; + unset( $newblogs[$id] ); + } + } + + // Add any blog not yet ordered to the end + foreach ( $newblogs AS $blog ) { + $ordered[$blog->userblog_id] = $blog; + } + + // If we're only interested in visible blogs then remove the rest + if ( $visibility ) { + foreach ( (array)$ordered AS $pos => $blog ) { + if ( $blog->visible == false ) + unset( $ordered[$pos] ); + } + } + +/* + // Set the order and visible options if the user doesn't have any, + // but rate limit it so that the global DB doesn't get hammered + if ( !is_array( $order_meta ) && ( 1 == mt_rand( 1, 10 ) ) ) + update_usermeta( $user_id, 'blog_order', array() ); + + if ( !is_array( $visible_meta ) && ( 1 == mt_rand( 1, 10 ) ) ) + update_usermeta( $user_id, 'blog_visibility', array() ); +*/ + + return apply_filters( 'ordered_blogs', $ordered ); +} + +function set_blog_visibility( $blog_id, $visible ) { + global $current_user; + + if ( is_blog_user( $blog_id ) ) { + $visibility = get_user_meta( $current_user->ID, 'blog_visibility' ); + if ( !is_array( $visibility ) ) + $visibility = array(); + + $visibility[$blog_id] = $visible; + + update_user_meta( $current_user->ID, 'blog_visibility', $visibility ); + } +} + +/** + * Checks if the current user belong to a given blog. + * + * @since 3.0.0 + * + * @param int $blog_id Blog ID + * @return bool True if the current users belong to $blog_id, false if not. + */ +function is_blog_user( $blog_id = 0 ) { + global $wpdb; + + $current_user = wp_get_current_user(); + if ( !$blog_id ) + $blog_id = $wpdb->blogid; + + $cap_key = $wpdb->base_prefix . $blog_id . '_capabilities'; + + if ( is_array($current_user->$cap_key) && in_array(1, $current_user->$cap_key) ) + return true; + + return false; +} + /** * Add meta data field to a user. * diff --git a/wp-settings.php b/wp-settings.php index bdfc58a5cb..6e35a8e6e7 100644 --- a/wp-settings.php +++ b/wp-settings.php @@ -133,6 +133,7 @@ require( ABSPATH . WPINC . '/class-http.php' ); require( ABSPATH . WPINC . '/widgets.php' ); require( ABSPATH . WPINC . '/nav-menu.php' ); require( ABSPATH . WPINC . '/nav-menu-template.php' ); +require( ABSPATH . WPINC . '/admin-bar.php' ); // Load multisite-specific files. if ( is_multisite() ) {