<?php
/*
Plugin Name: Multiply
Version: 2.3.1
Plugin URI: http://www.rephrase.net/box/word/multiply/
Description: Allows multiple blogs from within the one administration interface. Includes one-click creation of new blogs, with per-blog user permissions, plugins, themes etc.
Author: Sam Angove
Author URI: http://rephrase.net/

And God spake unto Noah, saying . . . be fruitful, and multiply.
*/
global $multiply_tables, $multiply_real_prefix, $table_prefix, $wpdb;

// Remove tables from $multiply_tables for greater integration between blogs,

$multiply_tables = array('categories', 'links', 'linkcategories', 'link2cat', 
                         'posts', 'post2cat', 'comments', 'postmeta', 'options',
                         'terms', 'term_taxonomy', 'term_relationships'); // new in WP 2.3

$multiply_real_prefix = $table_prefix = $wpdb->prefix;

// Our tables. *muser is no longer used.
$wpdb->multiply = $multiply_real_prefix . "multiply";
$wpdb->muser = $multiply_real_prefix . "muser";

load_plugin_textdomain('Multiply');

Multiply::choose_press();

// Load plugins.
if ($blog_id > 1) {
	$current_plugins = get_settings('active_plugins');
	if (is_array($current_plugins))	{
		foreach ($current_plugins as $plugin) {
			if ('' != $plugin && file_exists(ABSPATH . 'wp-content/plugins/' . $plugin))
				include_once(ABSPATH . 'wp-content/plugins/' . $plugin);
		}
	}

}

// Functions are wrapped in a class more for ghetto-namespacing than
// anything else. Methods are always called statically.
class Multiply {
	
function choose_press() {
	global $mb_press_id, $blog_id;
		
	// In wp-admin we use cookies to get the right press		
	if (strstr($_SERVER['PHP_SELF'], 'wp-admin/')) {
						
		// If a new blog is selected, set the cookie.
		if (isset($_GET['set_press_id'])) {
			$press_id = (int) $_GET['set_press_id'];
			Multiply::set_cookie($press_id);
		} else {
			$press_id = Multiply::get_cookie();
		}
				
		// Super dodgy hack to allow on-post edit/delete links to work.
		// If you're referred to post.php & haven't come from a wp-admin
		// page, look for the cookie that was set on the blog page view.
		// 
		// It's pretty fragile, but I figured it was better than nothing.
		// Or you could just edit the core, of course.
		$referrer = $_SERVER['HTTP_REFERER'];
		if (strlen($referrer) > 5 && !strstr($referrer, 'wp-admin')) {
			if ( strstr($_SERVER['PHP_SELF'], 'post.php') || strstr($_SERVER['PHP_SELF'], 'attachments.php') )
				$press_id = Multiply::get_cookie('blogreadid');
		}
			
	} else {
		// Non-admin, i.e. regular blog view pages.	
		
		$press_id = (int) $_REQUEST['press_id'];
		
		if (!$press_id) {
			if ($mb_press_id) // $mb_press_id is legacy from old Multiply
				$press_id = $mb_press_id;
			else 
				$press_id = $blog_id;	
		}
		// Used to make on-post, GET-submitted edit and delete links work *sometimes*.
		// That's the best I can do... See mb_cookiemonster()
		Multiply::set_cookie($press_id, 'blogreadid');
	}
	Multiply::set_press($press_id);
}

function set_prefix($id = 0) {
	global $multiply_real_prefix, $multiply_tables, $table_prefix, $wpdb;
	
	// deprecated/legacy
	global $tableposts, $tableusers, $tablecategories, $tablepost2cat, $tablecomments, $tablelinks, $tablelinkcategories, $tableoptions, $tablepostmeta;
		
	$wpdb->prefix = $multiply_real_prefix;
	
	if ($id > 1) {
	    $wpdb->prefix .= $id . '_';
	    $table_prefix = $wpdb->prefix;
    }
	
	foreach ($multiply_tables as $table) {

		// change tables
		$wpdb->$table = $table_prefix . $table;
	
		// "$tableposts" etc.
		${'table' . $table} = $table_prefix . $table;
	}
}
		
function set_press($press_id = 1) {
	global $wpdb, $blog_id, $cache_settings, $wp_rewrite, $current_user, $wp_object_cache;
	
	if (!$press_id || $press_id == $blog_id) return; 

	$press = $wpdb->get_var("SELECT press_id FROM $wpdb->multiply WHERE press_id = '$press_id'");
		
	if ($press) { 
		Multiply::set_prefix($press_id);
			
		$blog_id = $press_id;
	
		// Reset the settings cache, since it's already been populated
		// with the default blog's options. Re-initialize $wp_rewrite
		// for the same reason.
		wp_cache_init();
			
		if ( is_object($wp_rewrite) )
			$wp_rewrite->init();
	}
}
	
// Builds the array which is used to generate the list of 
// available presses. 
function press_list() {
	global $user_ID, $user_level, $wpdb, $press_cache;
		
	// Returns array : press_id => press_slug 
	
	$results = $wpdb->get_results("
		SELECT 
			press_id, 
			press_name
		FROM 
			$wpdb->multiply 
		ORDER BY press_id
		");
		
	if ($results) {
		foreach ($results as $result) {
			$press_cache[$result->press_id] = $result->press_name;	
		}
	} else { 
		return false;
	}
	
	return $press_cache;
}
	
	
// Cookie monster.
function get_cookie($type = 'blogid') {
	$press_id = (int) $_COOKIE["wordpress_{$type}_".COOKIEHASH];
		
	return $press_id;
}	
function set_cookie($press_id, $type = 'blogid', $expiration = '3000000') {
	if ($press_id) {
		setcookie("wordpress_{$type}_" . COOKIEHASH, $press_id, time() + $expiration, '/');
	} else {
		setcookie("wordpress_{$type}_" . COOKIEHASH, '0', time() + $expiration, '/');
	}
}

// get_settings() from the main blog.
function get_settings($key, $return_id) {
	Multiply::set_prefix();
	$value = get_settings($key);
	Multiply::set_prefix($return_id);
	return $value;
}
	
// Create a new press.
//
function create_press($name = '') {
	global $table_prefix, $wpdb, $multiply_tables, $multiply_real_prefix, $wp_queries, $blog_id;

	if (!$name) $name = __('Blog #', 'Multiply'). $press_id;
	$name = $wpdb->escape($name);
	
	$wpdb->query("INSERT INTO $wpdb->multiply ( `press_name` ) VALUES ( '$name' )");
	$press_id = $wpdb->insert_id;
	
	Multiply::set_prefix($press_id); 
		
	$blog_id = $press_id;
		
	require_once(ABSPATH . '/wp-admin/upgrade-functions.php');
		
	wp_cache_init();
	
	// Probably don't need to do this, but just in case.
	wp_cache_flush();
		
	make_db_current_silent();
		
	populate_options();
	populate_roles();
			
	update_option( 'admin_email', $admin_email );
	update_option( 'blogname', $name );
	update_option( 'active_plugins', array('000-multiply.php') );
			
	$roles = Multiply::get_settings($multiply_real_prefix . 'user_roles', $press_id);
	
	update_option($table_prefix . 'user_roles', $roles);
	
	$user = new WP_User(1);
	$user->set_role('administrator');
	$user->add_cap('manage_blogs');
	
	// Default category
	$wpdb->query("INSERT INTO $wpdb->categories (cat_ID, cat_name, category_nicename, category_count, category_description) VALUES ('0', '".$wpdb->escape(__('Uncategorized'))."', '".sanitize_title(__('Uncategorized'))."', '1', '')");
	
	// First post
	$now = date('Y-m-d H:i:s');
	$now_gmt = gmdate('Y-m-d H:i:s');
	$wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, comment_count, to_ping, pinged, post_content_filtered) VALUES ('1', '$now', '$now_gmt', '".$wpdb->escape(__('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!'))."', '', '".$wpdb->escape(__('Hello world!'))."', '0', '".$wpdb->escape(__('hello-world'))."', '$now', '$now_gmt', '1', '', '', '')");
	$wpdb->query( "INSERT INTO $wpdb->post2cat (`rel_id`, `post_id`, `category_id`) VALUES (1, 1, 1)" );

	// Try and create `xmlrpc-{$press_id}.php` so pingback can function.
	Multiply::create_xmlrpc_php($press_id);
	Multiply::set_press(1);
		
}
	
function delete_press($id) {
	global $multiply_tables, $wpdb;
		
	Multiply::set_press($id);
		
	foreach ($multiply_tables as $table) {
		$wpdb->query("DROP TABLE `{$wpdb->$table}`");
	}
	$wpdb->query("DELETE FROM `$wpdb->multiply` WHERE press_id = $id");	
		
	Multiply::set_press();
}
	
// create xmlrpc-{$press_id}.php files so pingback etc. works
function create_xmlrpc_php($id) {
	
	$contents = "<?php \n" .
		"/* " . __('This file generated by the Multiply multi-blog plugin.', 'Multiply') ."\n" .
		"       http://rephrase.net/box/word/multiply/ \n" .
		"   " . __('If Multiply has been deleted, it is safe to remove this file.', 'Multiply') . "\n" .
		"*/\n" .
		"\n" .
		"\$mb_press_id = $id;\n" .
		"require_once('./xmlrpc.php');\n" .
		"\n" .
		"?>\n";
	
	$filename = ABSPATH . "xmlrpc-{$id}.php";
		
	if ((!file_exists($filename) && is_writable($path)) || is_writable($filename)) {
		$f = fopen($filename, 'w');
		fwrite($f, $contents);
		fclose($f);
		return true;
	} else {
		return false;
	}	
}
	
function xmlrpc_url_filter($url) {
	global $blog_id;
	if (strpos($url, 'xmlrpc.php') && $blog_id > 1) {
		$url = Multiply::xmlrpc_url();
	}
	return $url;
}


function xmlrpc_url() {
	global $blog_id;
	
	if ($blog_id > 1)
		$url = trailingslashit( get_settings('siteurl') ) . "xmlrpc-{$blog_id}.php";	
	else
		$url = trailingslashit( get_settings('siteurl') ) . 'xmlrpc.php';

	return $url;
}
	
// On plugin activation, do most of the necessary installation/upgrading.
function maybe_install() {
	global $wpdb, $table_prefix, $multiply_tables;
	
	//Multiply::set_press(1);
	// If not installed at all, create the table.
	$tables = $wpdb->get_col("SHOW TABLES", 0);
	if (! in_array($wpdb->multiply, $tables) ) {
		
		$wpdb->query("
			CREATE TABLE `$wpdb->multiply` (
			  `press_id` int(11) NOT NULL auto_increment,
			  `press_name` varchar(200)  default '' NOT NULL,
			  `press_type` varchar(20) default 'alt' NOT NULL,
			  PRIMARY KEY  (`press_id`)
			  ); ");
			
		// ... and add a placeholder for the main blog.
		$wpdb->query("
			INSERT INTO $wpdb->multiply ( `press_id`, `press_name`, `press_type` ) 
			VALUES ( '1', '".__('Default/Main', 'Multiply')."', 'main')" 
			);
	}
		
	// Only let user #1 create/delete new blogs.
	$admin = new WP_User(1);
	$admin->add_cap('manage_blogs');
		
	/*
	Multiply only uses the 'manage_blogs' cap (see: Multiply::management_page())
	but it's easy to modify it to include more caps. With a bit of editing you
	can use code like this, which would let anyone with an account create a blog.
		
		$role = get_role('subscriber');
		$role->add_cap('create_blog');
			
	The sky is your oyster!
	*/
}

// Add a hidden value to comment forms; without this, all comments
// show up in the main blog. 
function comment_form($post_id) {
	global $blog_id;
	echo '<input type="hidden" name="press_id" value="'. $blog_id .'" />';
		
	return $post_id;	
}

function login_redirect($link) {
	global $blog_id;
		
	if (! is_user_logged_in() ) {
		$link = '<a href="' . get_settings('siteurl') . '/wp-login.php?redirect_to=' . urlencode("wp-admin/?set_press_id=$blog_id") . '">' . __('Login') . '</a>';
	} 
	return $link;
}

// The Multiply admin page. In the global namespace just because.
function add_management_page() {
	add_management_page(__('Manage Presses', 'Multiply'), __('Presses', 'Multiply'), 10, __FILE__, array('Multiply', 'management_page'));	
}
function management_page() {
	global $wpdb, $user_level, $multiply_tables;
	
	check_admin_referer();
	if (!user_can_access_admin_page())
		die (__("Sorry, you can't access this page.", 'Multiply'));
	
	if (! current_user_can('manage_blogs') )
		$error[] = __('Sorry, you need the "manage_blogs" capability to use functions on this page. You may need to switch to another blog before using it.', 'Multiply');
	
	$press_edit_id = (int) $_REQUEST['press_edit_id'];
	$user_id = (int) $_REQUEST['user_id'];
	
	switch( $_REQUEST['action'] ) {

		case 'create_blog':
			if (! current_user_can('manage_blogs') ) {
				$error[] = __('Blog creation failed. You do not have the "manage_blogs" capability.', 'Multiply');
				break;
			}
			$name = addslashes($_POST['name']);
			$level = (int) $_POST['level'];
			$message = Multiply::create_press($name, $level);
			$status = $message . __("New press '$name' created!", 'Multiply');
		break;
		
		case 'edit_blog':
			if (! current_user_can('manage_blogs') ) {
				$error[] = __('Blog editing failed. You do not have the "manage_blogs" capability.', 'Multiply');
				break;
			}
			$name = addslashes($_POST['name']);
			$wpdb->query("UPDATE $wpdb->multiply SET `press_name` = '$name' WHERE `press_id` = '$press_edit_id'");
		break;
		
		case 'delete_blog':
			if (! current_user_can('manage_blogs') ) {
				$error[] = __('Blog deletion failed. You do not have the "manage_blogs" capability.', 'Multiply');
				break;
			}

			$id = $wpdb->get_var("SELECT press_id FROM $wpdb->multiply WHERE press_id = $press_edit_id");
		
			if ($press_edit_id == 1) {
				$error[] = __( sprintf('You cannot delete the default blog.', $press_edit_id), 'Multiply');
				break;	
			}
			if ($id) {
				Multiply::delete_press($id);	
				$status = __( sprintf('Blog ID #%s deleted.', $id), 'Multiply');
				//header('Location: edit.php?page=000-multiply.php');
			} else {
				$error[] = __( sprintf('Blog ID #%s does not exist.', $press_edit_id), 'Multiply');	
			}
			$press_edit_id = 0;
		break;
		
	}
	
	$presses = Multiply::press_list();
	
	if ($press_edit_id) {
		$header = __('Edit Press', 'Multiply');	
		$press = $presses[$press_edit_id];
		$act = 'edit_blog';
	} else {
		$header = __('Add Press', 'Multiply');	
		$act = 'create_blog';
	}
	?>			
	
	<?php if ($status): ?>
	<div class="updated">
		<p>
		<strong>
			<?php echo htmlentities($status); ?>
		</strong>
		</p>
	</div>
	<?php endif; ?>
	
	<?php if (count($error)): ?>
	<div class="error">
		<ol>
		<?php 
			foreach ($error as $emsg) {
				echo "<li>" . htmlentities($emsg) . "</li>";
			}
		?>
		</ol>
	</div>
	<?php endif; ?>
	
	<div class="wrap">
		<form method="post" action="edit.php?page=000-multiply.php">
			<h2><?php echo $header; ?></h2>
			<fieldset>
				<label for="name">
					<?php _e('Press name', 'Multiply'); ?>
				</label>
				<input type="text" name="name" size="30" maxlength="50" value="<?php echo $press; ?>" />
				<input type="hidden" name="press_edit_id" value="<?php echo $press_edit_id; ?>" /> 
				<input type="hidden" name="action" value="<?php echo $act; ?>" /> 
				<input type="submit" value="<?php echo ($press_edit_id) ? __('Update', 'Multiply') : __('Add', 'Multiply'); ?>" />
			</fieldset>
		</form>
	</div>
		
	<div class="wrap">
		<h2><?php _e('Presses', 'Multiply'); ?></h2>
		<form method="post">
			<table cellpadding="3" cellspacing="3" width="100%">
			<tr>
				<th scope="col">ID</th>
	        	<th scope="col"><?php _e('Name'); ?></th>
	    	    <th colspan="2"><?php _e('Action'); ?></th>
			</tr>
		
	<?php
	if ($presses) {
		foreach ($presses as $id => $press) {
			if ( ++$count % 2 ) 
				$style = ' class="alternate"';
			else 
				$style = '';
			
			echo "<tr$style>";
			echo "<th scope='row'>$id</th>";
			echo "<td>$press</td>";
			echo '<td><a href="edit.php?page=000-multiply.php&amp;press_edit_id='. $id .'" class="edit">Edit</a></td>';
			echo '<td><a href="edit.php?page=000-multiply.php&amp;action=delete_blog&amp;press_edit_id='. $id .'" onclick="return confirm(\''.__('Really delete this press?', 'Multiply') .'\')" class="delete">Delete</a></td>';
			echo '</tr>';
		
		}
	}
	?>
			</table>
		</form>
	</div>
 	<?
}


// Press selection widget on admin pages. 
function select_press() {
	global $press_cache, $blog_id;
	
	$press_cache = Multiply::press_list();
	
	if ($press_cache) {
	
		echo '<div id="mbdiv" style="position: absolute; top: 30px; right: 10px; text-align: right;">';

		echo '<form id="multiply" method="get">';

		echo '<select name="set_press_id">';
		
		//echo '<option value="0">' . __('Default Press', 'Multiply') . '</option>';
			
		foreach ($press_cache as $id => $press) {
			echo '<option value="' . $id . '"';
			if ($id == $blog_id) echo ' selected="selected"';
			echo '>'.$id.'. '.$press.'&nbsp;&nbsp;</option>';
		}
		echo '</select>';
		echo '<input value="' . __('Select', 'Multiply') . '" type="submit">';
		
		echo '</form>';
		echo '</div>';
	}
}


} /* end Multiply class */

add_filter( 'bloginfo', array('Multiply', 'xmlrpc_url_filter') );

// Login links are blog_id sensitive.
add_action( 'loginout', array('Multiply', 'login_redirect') );

// Admin page, Manage->Presses.
add_action( 'admin_menu', array('Multiply', 'add_management_page') );

// Press selection widget.
add_action( 'admin_footer', array('Multiply', 'select_press') );

// Make sure to submit blog_id with comments.
add_action( 'comment_form', array('Multiply', 'comment_form') );

// Do install/upgrade on plugin activation.
register_activation_hook(__FILE__, array('Multiply', 'maybe_install') );




/* Pluggable functions */

if ( ! function_exists('wp_notify_postauthor') ) :
function wp_notify_postauthor($comment_id, $comment_type='') {
	global $wpdb, $blog_id;
    
	$comment = get_comment($comment_id);
	$post    = get_post($comment->comment_post_ID);
	$user    = get_userdata( $post->post_author );

	if ('' == $user->user_email) return false; // If there's no email to send the comment to

	$comment_author_domain = gethostbyaddr($comment->comment_author_IP);

	$blogname = get_settings('blogname');
	
	if ( empty( $comment_type ) ) $comment_type = 'comment';
	
	if ('comment' == $comment_type) {
		$notify_message  = sprintf( __('New comment on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
		$notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
		$notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
		$notify_message .= sprintf( __('URI    : %s'), $comment->comment_author_url ) . "\r\n";
		$notify_message .= sprintf( __('Whois  : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n";
		$notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
		$notify_message .= __('You can see all comments on this post here: ') . "\r\n";
		$subject = sprintf( __('[%1$s] Comment: "%2$s"'), $blogname, $post->post_title );
	} elseif ('trackback' == $comment_type) {
		$notify_message  = sprintf( __('New trackback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
		$notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
		$notify_message .= sprintf( __('URI    : %s'), $comment->comment_author_url ) . "\r\n";
		$notify_message .= __('Excerpt: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
		$notify_message .= __('You can see all trackbacks on this post here: ') . "\r\n";
		$subject = sprintf( __('[%1$s] Trackback: "%2$s"'), $blogname, $post->post_title );
	} elseif ('pingback' == $comment_type) {
		$notify_message  = sprintf( __('New pingback on your post #%1$s "%2$s"'), $comment->comment_post_ID, $post->post_title ) . "\r\n";
		$notify_message .= sprintf( __('Website: %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
		$notify_message .= sprintf( __('URI    : %s'), $comment->comment_author_url ) . "\r\n";
		$notify_message .= __('Excerpt: ') . "\r\n" . sprintf('[...] %s [...]', $comment->comment_content ) . "\r\n\r\n";
		$notify_message .= __('You can see all pingbacks on this post here: ') . "\r\n";
		$subject = sprintf( __('[%1$s] Pingback: "%2$s"'), $blogname, $post->post_title );
	}
	$notify_message .= get_permalink($comment->comment_post_ID) . "#comments\r\n\r\n";
	$notify_message .= sprintf( __('To delete this comment, visit: %s'), get_settings('siteurl').'/wp-admin/post.php?action=confirmdeletecomment&p='.$comment->comment_post_ID."&comment=$comment_id&set_press_id=$blog_id" ) . "\r\n";

	$wp_email = 'wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));

	if ( '' == $comment->comment_author ) {
		$from = "From: \"$blogname\" <$wp_email>";
		if ( '' != $comment->comment_author_email )
			$reply_to = "Reply-To: $comment->comment_author_email";
 	} else {
		$from = "From: \"$comment->comment_author\" <$wp_email>";
		if ( '' != $comment->comment_author_email )
			$reply_to = "Reply-To: \"$comment->comment_author_email\" <$comment->comment_author_email>";
 	}

	$message_headers = "MIME-Version: 1.0\n"
		. "$from\n"
		. "Content-Type: text/plain; charset=\"" . get_settings('blog_charset') . "\"\n";

	if ( isset($reply_to) )
		$message_headers .= $reply_to . "\n";

	$notify_message = apply_filters('comment_notification_text', $notify_message);
	$subject = apply_filters('comment_notification_subject', $subject);
	$message_headers = apply_filters('comment_notification_headers', $message_headers);

	@wp_mail($user->user_email, $subject, $notify_message, $message_headers);
   
	return true;
}
endif;

/* wp_notify_moderator
   notifies the moderator of the blog (usually the admin)
   about a new comment that waits for approval
   always returns true
 */
if ( !function_exists('wp_notify_moderator') ) :
function wp_notify_moderator($comment_id) {
	global $wpdb, $blog_id;

	if( get_settings( "moderation_notify" ) == 0 )
		return true; 
    
	$comment = $wpdb->get_row("SELECT * FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
	$post = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE ID='$comment->comment_post_ID' LIMIT 1");

	$comment_author_domain = gethostbyaddr($comment->comment_author_IP);
	$comments_waiting = $wpdb->get_var("SELECT count(comment_ID) FROM $wpdb->comments WHERE comment_approved = '0'");

	$notify_message  = sprintf( __('A new comment on the post #%1$s "%2$s" is waiting for your approval'), $post->ID, $post->post_title ) . "\r\n";
	$notify_message .= get_permalink($comment->comment_post_ID) . "\r\n\r\n";
	$notify_message .= sprintf( __('Author : %1$s (IP: %2$s , %3$s)'), $comment->comment_author, $comment->comment_author_IP, $comment_author_domain ) . "\r\n";
	$notify_message .= sprintf( __('E-mail : %s'), $comment->comment_author_email ) . "\r\n";
	$notify_message .= sprintf( __('URI    : %s'), $comment->comment_author_url ) . "\r\n";
	$notify_message .= sprintf( __('Whois  : http://ws.arin.net/cgi-bin/whois.pl?queryinput=%s'), $comment->comment_author_IP ) . "\r\n";
	$notify_message .= __('Comment: ') . "\r\n" . $comment->comment_content . "\r\n\r\n";
	$notify_message .= sprintf( __('To approve this comment, visit: %s'),  get_settings('siteurl').'/wp-admin/post.php?action=mailapprovecomment&p='.$comment->comment_post_ID."&comment=$comment_id&set_press_id=$blog_id" ) . "\r\n";
	$notify_message .= sprintf( __('To delete this comment, visit: %s'), get_settings('siteurl').'/wp-admin/post.php?action=confirmdeletecomment&p='.$comment->comment_post_ID."&comment=$comment_id&set_press_id=$blog_id" ) . "\r\n";
	$notify_message .= sprintf( __('Currently %s comments are waiting for approval. Please visit the moderation panel:'), $comments_waiting ) . "\r\n";
	$notify_message .= get_settings('siteurl') . "/wp-admin/moderation.php\r\n";

	$subject = sprintf( __('[%1$s] Please moderate: "%2$s"'), get_settings('blogname'), $post->post_title );
	$admin_email = get_settings('admin_email');

	$notify_message = apply_filters('comment_moderation_text', $notify_message);
	$subject = apply_filters('comment_moderation_subject', $subject);

	@wp_mail($admin_email, $subject, $notify_message);
    
	return true;
}
endif;


?>