blogs." SET last_updated = NOW() WHERE blog_id = '".$wpdb->blogid."'"; $wpdb->query( $query ); } add_action('comment_post', 'wpmu_update_blogs_date'); add_action('delete_post', 'wpmu_update_blogs_date'); add_action('delete_comment', 'wpmu_update_blogs_date'); add_action('private_to_published', 'wpmu_update_blogs_date'); add_action('publish_phone', 'wpmu_update_blogs_date'); add_action('publish_post', 'wpmu_update_blogs_date'); add_action('trackback_post', 'wpmu_update_blogs_date'); add_action('wp_set_comment_status', 'wpmu_update_blogs_date'); /** * Cleans the passed path. * Removes the wpmu & the blog name from the path * This should only be used for display filters * * @param unknown $path * @return unknown */ function wpmu_tidypath($path) { global $wpblog; $path = str_replace('/wpmu/','/',$path); $path = str_replace("/{$wpblog}/",'/',$path); return $path; } add_filter('wpmu_display_get_page_string','wpmu_tidypath',10); add_filter('wpmu_display_get_permalink','wpmu_tidypath',10); /** * Wrapper for querying the databse * * @param string $query * @return object */ function wpmu_adminDatabaseQuery($query) { /* @var $wpdb wpdb */ global $wpdb; $result = $wpdb->get_row($query); return $result; } /** * Set an option in the Master Blog 'main' options table * * @param string $optionName * @param mixed $optionValue */ function wpmu_adminOptionSet($optionName, $optionValue) { wpmu_blogOption_set('main',$optionName, $optionValue); } /** * Retrieve a setting from the Master Blog Tables * * @param string $optionName * @param mixed $default * @return mixed */ function wpmu_adminOption_get($optionName, $default=null) { return wpmu_blogOption_get('main',$optionName, $default); } /** * Retrives a setting from a specific client blog * * @param string $blogName * @param string $optionName * @param mixed $default * @return mixed */ function wpmu_blogOption_get($blogName, $optionName, $default=null) { global $wpdb; // check if options table exists if( defined('WP_INSTALLING') ) return null; $query = wpmu_adminDatabaseQuery("SELECT * FROM ".$wpdb->options." WHERE option_name = '{$optionName}'"); if (!isset($query) || is_null($query)) { $result = $default; } else { $result = $query->option_value; if (!(unserialize($result)===false)) { $result = unserialize($result); } } return $result; } /** * Sets an option for a specific client blog * * @param string $blogName * @param string $optionName * @param mixed $optionValue */ function wpmu_blogOption_set($blogName, $optionName, $optionValue) { global $wpdb; $isExisting = wpmu_blogOption_get($blogName,$optionName,null); if (is_array($optionValue) || is_object($optionValue)) { $optionValue = serialize($optionValue); } if (is_null($isExisting)) { wpmu_adminDatabaseQuery("INSERT INTO ".$wpdb->options." (option_name, option_value) values ('{$optionName}', '{$optionValue}')"); } else { wpmu_adminDatabaseQuery("UPDATE ".$wpdb->options." set option_value = '{$optionValue}' where option_name = '{$optionName}'"); } } /* Determines if the available space defined by the admin has been exceeded by the user */ /** * Returns how much space is available (also shows a picture) for the current client blog, retrieving the value from the master blog 'main' option table * * @param string $action * @return string */ function wpmu_checkAvailableSpace($action) { // Using the action. // Set the action to 'not-writable' to block the upload global $wpblog, $blog_id; // Default space allowed is 10 MB $spaceAllowed = wpmu_adminOption_get("wpmu_space_allocated", 10485760 ); $dirName = ABSPATH."wp-content/blogs.dir/".$blog_id."/files/"; $dir = dir($dirName); $size = 0; while($file = $dir->read()) { if ($file != '.' && $file != '..') { if (is_dir($file)) { $size += dirsize($dirName . '/' . $file); } else { $size += filesize($dirName . '/' . $file); } } } $dir->close(); ?>
Space Available (bytes) | |
"> |
','',$pluginAutoInstall);
$pluginAutoInstall = str_replace('
','',$pluginAutoInstall);
return $pluginAutoInstall;
}
return false;
}
/**
* Evaluates an expression
*
* @param unknown $string
* @return unknown
*/
function wpmu_eval($string) {
$result = eval($string);
if ($result===false || is_null($result)) {
return false;
}
return true;
}
/**
* Auto installs plugins
*
*/
function wpmu_autoInstallPlugins($pendingPlugins) {
global $wpblog;
foreach ($pendingPlugins as $key => $filename) {
$installOptions = wpmu_checkPluginForInstallStages($filename);
if ($installOptions) {
// Include the file
require_once(ABSPATH.'wp-content/plugins/'.$filename);
$result = wpmu_eval($installOptions);
} else {
$result = true;
}
if ($result==true) {
// Everything worked ok
unset($pendingPlugins[$key]);
} else {
// There was a problem - should be logged
}
}
wpmu_blogOption_set($wpblog,'wpmu_plugins_pending',serialize($pendingPlugins));
}
/*
Determine if there are any plugins that need installing or configuring
This will enable not just the auto install/configure of plugins - but updates (to plugins or plugin data) as well
*/
$pendingPlugins = wpmu_blogOption_get($wpblog,'wpmu_plugins_pending', null);
if (is_null($pendingPlugins)) {
// If null is returned - then this is a brand new blog
$adminPlugins = wpmu_adminOption_get('wpmu_global_blog_plugins',null);
if (!is_null($adminPlugins)) {
// We've something to do
wpmu_autoInstallPlugins($adminPlugins);
}
} else {
if (count($pendingPlugins)>0) {
wpmu_autoInstallPlugins($pendingPlugins);
}
}
function createBlog( $hostname, $domain, $path, $blogname, $weblog_title, $admin_email, $username='' ) {
global $wpdb, $table_prefix, $wp_queries, $wpmuBaseTablePrefix;
$blogname = addslashes( $blogname );
$weblog_title = addslashes( $weblog_title );
$admin_email = addslashes( $admin_email );
$username = addslashes( $username );
// Check if the username has been used already. We should return an error message.
if( $username == '' ) {
$query = "SELECT ID
FROM ".$wpdb->users."
WHERE user_login = '".$blogname."'";
$ID = $wpdb->get_var( $query );
if( $ID != false ) {
return "error: blogname used by user";
}
} else {
$query = "SELECT ID
FROM ".$wpdb->users."
WHERE user_login = '".$username."'";
$ID = $wpdb->get_var( $query );
if( $ID != false ) {
return "error: username used";
}
}
// Need to backup wpdb table names, and create a new wp_blogs entry for new blog.
// Need to get blog_id from wp_blogs, and create new table names.
// Must restore table names at the end of function.
$wpdb->hide_errors();
$query = "SELECT id
FROM ".$wpdb->site."
WHERE domain = '".$domain."'
AND path = '".$path."'";
$site_id = $wpdb->get_var( $query );
if( $site_id == false ) {
$query = "INSERT INTO `wp_site` ( `id` , `domain` , `path` )
VALUES ( NULL, '".$domain."', '".$path."')";
$wpdb->query( $query );
$site_id = $wpdb->insert_id;
}
$query = "SELECT blog_id
FROM ".$wpdb->blogs."
WHERE site_id = '".$site_id."'
AND blogname = '".$blogname."'";
$blog_id = $wpdb->get_var( $query );
if( $blog_id != false ) {
return "error: blogname used";
}
$query = "INSERT INTO ".$wpdb->blogs." ( blog_id, site_id, blogname, registered )
VALUES ( NULL, '".$site_id."', '".$blogname."', NOW( ))";
if( $wpdb->query( $query ) == false ) {
return "error: problem creating blog entry";
}
$blog_id = $wpdb->insert_id;
// backup
$tmp[ 'siteid' ] = $wpdb->siteid;
$tmp[ 'blogid' ] = $wpdb->blogid;
$tmp[ 'posts' ] = $wpdb->posts;
$tmp[ 'categories' ] = $wpdb->categories;
$tmp[ 'post2cat' ] = $wpdb->post2cat;
$tmp[ 'comments' ] = $wpdb->comments;
$tmp[ 'links' ] = $wpdb->links;
$tmp[ 'linkcategories' ] = $wpdb->linkcategories;
$tmp[ 'option' ] = $wpdb->option;
$tmp[ 'postmeta' ] = $wpdb->postmeta;
$tmptable_prefix = $table_prefix;
// fix the new prefix.
$table_prefix = $wpmuBaseTablePrefix . $blog_id . "_";
$wpdb->siteid = $site_id;
$wpdb->blogid = $blog_id;
$wpdb->posts = $table_prefix . 'posts';
$wpdb->categories = $table_prefix . 'categories';
$wpdb->post2cat = $table_prefix . 'post2cat';
$wpdb->comments = $table_prefix . 'comments';
$wpdb->links = $table_prefix . 'links';
$wpdb->linkcategories = $table_prefix . 'linkcategories';
$wpdb->options = $table_prefix . 'options';
$wpdb->postmeta = $table_prefix . 'postmeta';
@mkdir( ABSPATH . "wp-content/blogs.dir/".$blog_id, 0777 );
@mkdir( ABSPATH . "wp-content/blogs.dir/".$blog_id."/files", 0777 );
require_once( ABSPATH . 'wp-admin/upgrade-functions.php');
$wpdb->hide_errors();
$installed = $wpdb->get_results("SELECT * FROM $wpdb->posts");
if ($installed) die(__('You appear to have already installed WordPress. To reinstall please clear your old database tables first.
') . '