diff options
author | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2006-06-22 18:31:50 +0000 |
---|---|---|
committer | donncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36> | 2006-06-22 18:31:50 +0000 |
commit | d48e85e0ac5e675ca33fac173f30c75403d1033f (patch) | |
tree | 1164430fa3b83a4d9283961b09c1576f2885e6b2 /wp-content/mu-plugins | |
parent | 086dcde66603301531efc6d8087bd06d0546f148 (diff) | |
download | wordpress-mu-d48e85e0ac5e675ca33fac173f30c75403d1033f.tar.gz wordpress-mu-d48e85e0ac5e675ca33fac173f30c75403d1033f.tar.xz wordpress-mu-d48e85e0ac5e675ca33fac173f30c75403d1033f.zip |
Moved everything in wp-inst down a directory.
Uses's Ryan Boren's htaccess rules and mods
If you're upgrading, try this on a test server first!
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@591 7be80a69-a1ef-0310-a953-fb0f7c49ff36
Diffstat (limited to 'wp-content/mu-plugins')
-rw-r--r-- | wp-content/mu-plugins/global-categories.php | 31 | ||||
-rw-r--r-- | wp-content/mu-plugins/misc.php | 124 | ||||
-rw-r--r-- | wp-content/mu-plugins/pluggable.php | 160 |
3 files changed, 315 insertions, 0 deletions
diff --git a/wp-content/mu-plugins/global-categories.php b/wp-content/mu-plugins/global-categories.php new file mode 100644 index 0000000..d8c7c8c --- /dev/null +++ b/wp-content/mu-plugins/global-categories.php @@ -0,0 +1,31 @@ +<?php + +function global_categories( $cat_ID ) { + global $wpdb; + + $cat_ID = intval( $cat_ID ); + $c = $wpdb->get_row( "SELECT * FROM $wpdb->categories WHERE cat_ID = '$cat_ID'" ); + + $global_category = $wpdb->get_row( "SELECT * FROM $wpdb->sitecategories WHERE category_nicename = '" . $wpdb->escape( $c->category_nicename ) . "'" ); + + if ( $global_category ) { + $global_id = $global_category->cat_ID; + } else { + $wpdb->query( "INSERT INTO $wpdb->sitecategories ( cat_name, category_nicename ) VALUES ( '" . $wpdb->escape( $c->cat_name ) . "', '" . $wpdb->escape( $c->category_nicename ) . "' )" ); + $global_id = $wpdb->insert_id; + } + $wpdb->query( "UPDATE $wpdb->categories SET cat_ID = '$global_id' WHERE cat_id = '$cat_ID'" ); + $wpdb->query( "UPDATE $wpdb->categories SET category_parent = '$global_id' WHERE category_parent = '$cat_ID'" ); + $wpdb->query( "UPDATE $wpdb->post2cat SET category_id = '$global_id' WHERE category_id = '$cat_ID'" ); + $wpdb->query( "UPDATE $wpdb->link2cat SET category_id = '$global_id' WHERE category_id = '$cat_ID'" ); + wp_cache_delete($cat_ID, 'category'); + wp_cache_delete($global_id, 'category'); + wp_cache_delete('all_category_ids', 'category'); + + do_action('update_cat_id', $global_id, $cat_ID); + + return $global_id; +} + +add_filter( 'cat_id_filter', 'global_categories' ); +?> diff --git a/wp-content/mu-plugins/misc.php b/wp-content/mu-plugins/misc.php new file mode 100644 index 0000000..e02818d --- /dev/null +++ b/wp-content/mu-plugins/misc.php @@ -0,0 +1,124 @@ +<?php + +function graceful_fail( $message ) { + die(' +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"><head profile="http://gmpg.org/xfn/11"> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<title>Error!</title> +<style type="text/css"> +img { + border: 0; +} +body { +line-height: 1.6em; font-family: Georgia, serif; width: 390px; margin: auto; +text-align: center; +} +.message { + font-size: 22px; + width: 350px; + margin: auto; +} +</style> +</head> +<body> +<p class="message">' . $message . '</p> +</body> +</html> + '); +} + +function fix_upload_details( $uploads ) { + + $uploads[ 'url' ] = str_replace( UPLOADS, "files", $uploads[ 'url' ] ); + return $uploads; +} +add_filter( "upload_dir", "fix_upload_details" ); + +function get_dirsize($directory) { + $size = 0; + if(substr($directory,-1) == '/') $directory = substr($directory,0,-1); + if(!file_exists($directory) || !is_dir($directory) || !is_readable($directory)) return false; + if($handle = opendir($directory)) { + while(($file = readdir($handle)) !== false) { + $path = $directory.'/'.$file; + if($file != '.' && $file != '..') { + if(is_file($path)) { + $size += filesize($path); + } elseif(is_dir($path)) { + $handlesize = get_dirsize($path); + if($handlesize >= 0) { + $size += $handlesize; + } else { + return false; + } + } + } + } + closedir($handle); + } + return $size; +} + +function upload_is_user_over_quota( $ret ) { + global $wpdb; + + // Default space allowed is 10 MB + $spaceAllowed = get_site_option("blog_upload_space"); + if(empty($spaceAllowed) || !is_numeric($spaceAllowed)) $spaceAllowed = 10; + + $dirName = ABSPATH."wp-content/blogs.dir/" . $wpdb->blogid . "/files/"; + $size = get_dirsize($dirName) / 1024 / 1024; + + if( ($spaceAllowed-$size) < 0 ) { + return "Sorry, you have used your space allocation. Please delete some files to upload more files."; //No space left + } else { + return false; + } +} +add_filter( "pre_upload_error", "upload_is_user_over_quota" ); + +function upload_is_file_too_big( $ret ) { + if( $_FILES[ 'image' ][ 'size' ] > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) ) + $ret = "This file is too big. Files must be less than " . get_site_option( 'fileupload_maxk', 1500 ) . "Kb in size.<br />"; + + return $ret; +} +add_filter( "check_uploaded_file", "upload_is_file_too_big" ); + +function check_upload_mimes($mimes) { + $site_exts = explode( " ", get_site_option( "upload_filetypes" ) ); + foreach ( $site_exts as $ext ) + foreach ( $mimes as $ext_pattern => $mime ) + if ( preg_match("/$ext_pattern/", $ext) ) + $site_mimes[$ext_pattern] = $mime; + return $site_mimes; +} +add_filter('upload_mimes', 'check_upload_mimes'); + +add_filter('the_title', 'wp_filter_kses'); +function update_posts_count( $post_id ) { + global $wpdb; + $post_id = intval( $post_id ); + $c = $wpdb->get_var( "SELECT count(*) FROM {$wpdb->posts} WHERE post_status = 'publish' and post_type='post'" ); + update_option( "post_count", $c ); +} +add_action( "publish_post", "update_posts_count" ); + +function update_pages_last_updated( $post_id ) { + global $wpdb; + $post_id = intval( $post_id ); + if( $wpdb->get_var( "SELECT post_type FROM {$wpdb->posts} WHERE post_status = 'publish' and ID = '$post_id'" ) == 'page' ) + update_option( "pages_last_updated", time() ); +} +add_action( "save_post", "update_pages_last_updated" ); +add_action( "comment_post", "update_pages_last_updated" ); +add_action( "publish_post", "update_pages_last_updated" ); +add_action('delete_post', 'update_pages_last_updated'); +add_action('delete_comment', 'update_pages_last_updated'); +add_action('private_to_published', 'update_pages_last_updated'); +add_action('trackback_post', 'update_pages_last_updated'); +add_action('wp_set_comment_status', 'update_pages_last_updated'); + + +?> diff --git a/wp-content/mu-plugins/pluggable.php b/wp-content/mu-plugins/pluggable.php new file mode 100644 index 0000000..d6429dc --- /dev/null +++ b/wp-content/mu-plugins/pluggable.php @@ -0,0 +1,160 @@ +<?php + +function wp_login($username, $password, $already_md5 = false) { + global $wpdb, $error, $current_user; + + if ( !$username ) + return false; + + if ( !$password ) { + $error = __('<strong>Error</strong>: The password field is empty.'); + return false; + } + + if ($current_user->data->user_login == $username) + return true; + + $login = get_userdatabylogin($username); + //$login = $wpdb->get_row("SELECT ID, user_login, user_pass FROM $wpdb->users WHERE user_login = '$username'"); + + if (!$login) { + if( is_site_admin( $username ) ) { + unset( $login ); + $userdetails = get_userdatabylogin( $username ); + $login->user_login = $username; + $login->user_pass = $userdetails->user_pass; + } else { + $admins = get_admin_users_for_domain(); + reset( $admins ); + while( list( $key, $val ) = each( $admins ) ) + { + if( $val[ 'user_login' ] == $username ) { + unset( $login ); + $login->user_login = $username; + $login->user_pass = $val[ 'user_pass' ]; + } + } + } + } + if (!$login) { + $error = __('<strong>Error</strong>: Wrong username.'); + return false; + } else { + $primary_blog = get_usermeta( $login->ID, "primary_blog" ); + if( $primary_blog ) { + $details = get_blog_details( $primary_blog ); + if( is_object( $details ) ) { + if( $details->archived == 1 || $details->spam == 1 || $details->deleted == 1 ) { + $error = __('<strong>Error</strong>: Blog suspended.'); + return false; + } + } + } + // If the password is already_md5, it has been double hashed. + // Otherwise, it is plain text. + if ( ($already_md5 && $login->user_login == $username && md5($login->user_pass) == $password) || ($login->user_login == $username && $login->user_pass == md5($password)) ) { + return true; + } else { + $error = __('<strong>Error</strong>: Incorrect password.'); + $pwd = ''; + return false; + } + } +} + +function get_userdata( $user_id ) { + global $wpdb, $cache_userdata, $wpmuBaseTablePrefix; + $user_id = (int) $user_id; + if ( $user_id == 0 ) + return false; + + $user = wp_cache_get($user_id, 'users'); + $user_level = $wpmuBaseTablePrefix . $wpdb->blogid . '_user_level'; + if( $user->$user_level != '' || $user->user_level != '' ) { + if( $user && is_site_admin( $user->user_login ) == true ) { + $user->$user_level = 10; + $user->user_level = 10; + $cap_key = $wpdb->prefix . 'capabilities'; + $user->{$cap_key} = array( 'administrator' => '1' ); + return $user; + } elseif ( $user ) + return $user; + } + + if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE ID = '$user_id'") ) + return false; + + $metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user_id' /* pluggable get_userdata */"); + + if ($metavalues) { + foreach ( $metavalues as $meta ) { + @ $value = unserialize($meta->meta_value); + if ($value === FALSE) + $value = $meta->meta_value; + $user->{$meta->meta_key} = $value; + + // We need to set user_level from meta, not row + if ( $wpdb->prefix . 'user_level' == $meta->meta_key ) + $user->user_level = $meta->meta_value; + } // end foreach + } //end if + + if( is_site_admin( $user->user_login ) == true ) { + $user->user_level = 10; + $cap_key = $wpdb->prefix . 'capabilities'; + $user->{$cap_key} = array( 'administrator' => '1' ); + } + + wp_cache_add($user_id, $user, 'users'); + wp_cache_add($user->user_login, $user, 'userlogins'); + + return $user; +} + +function get_userdatabylogin($user_login) { + global $wpdb; + $user_login = sanitize_user( $user_login ); + + if ( empty( $user_login ) ) + return false; + + $userdata = wp_cache_get($user_login, 'userlogins'); + if( $userdata && is_site_admin( $user_login ) == true ) { + $userdata->user_level = 10; + $cap_key = $wpdb->prefix . 'capabilities'; + $userdata->{$cap_key} = array( 'administrator' => '1' ); + return $userdata; + } elseif( $userdata ) + return $userdata; + + if ( !$user = $wpdb->get_row("SELECT * FROM $wpdb->users WHERE user_login = '$user_login'") ) + return false; + + $metavalues = $wpdb->get_results("SELECT meta_key, meta_value FROM $wpdb->usermeta WHERE user_id = '$user->ID'"); + + if ($metavalues) { + foreach ( $metavalues as $meta ) { + @ $value = unserialize($meta->meta_value); + if ($value === FALSE) + $value = $meta->meta_value; + $user->{$meta->meta_key} = $value; + + // We need to set user_level from meta, not row + if ( $wpdb->prefix . 'user_level' == $meta->meta_key ) + $user->user_level = $meta->meta_value; + } + } + if( is_site_admin( $user_login ) == true ) { + $user->user_level = 10; + $cap_key = $wpdb->prefix . 'capabilities'; + $user->{$cap_key} = array( 'administrator' => '1' ); + } + + wp_cache_add($user->ID, $user, 'users'); + wp_cache_add($user->user_login, $user, 'userlogins'); + + return $user; + +} + +?> |