* @copyright Copyright 2007 Edward Dale
* @license http://www.gnu.org/licenses/gpl.txt GPL 2.0
* @version $Id: manage.php 29 2007-07-06 15:12:02Z scompt $
* @link http://www.scompt.com/projects/zensor
* @since 0.5
*/
/**
* Common functions used all over the Zensor package
*/
require_once(dirname(__FILE__).'/common.php');
/**
* A collection of static functions for the management screen
*/
class Zensor_Manage
{
/**
* Prints the management screen for Zensor
*
* Called by the add_management_page call setup in Zensor_Admin::admin_menu.
* Made up of two subpages (awaiting & rejected pages).
*/
function admin_manage_page()
{
global $zensor_table, $wpdb;
// Handle paging and subpage
$limit = 10;
$offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0;
$which = (isset( $_GET['sub'] ) && $_GET['sub'] == ZENSOR_REJECTED ) ? ZENSOR_REJECTED : ZENSOR_AWAITING;
// Do the query. isset($_GET['id'] is used to guarantee that a preloaded
// page is included in the query
$query = "SELECT {$wpdb->posts}.ID, {$wpdb->posts}.post_type, {$wpdb->posts}.post_title, ".
"{$wpdb->users}.display_name, UNIX_TIMESTAMP($zensor_table.last_updated) as last_updated, $zensor_table.message " .
(isset($_GET['id']) ? ", {$wpdb->posts}.ID=".intval($_GET['id'])." AS preload " : "").
"FROM {$wpdb->posts} LEFT JOIN $zensor_table ON {$wpdb->posts}.ID=$zensor_table.post_id ".
"JOIN {$wpdb->users} ON post_author={$wpdb->users}.ID " .
"WHERE ({$wpdb->posts}.post_type='post' OR {$wpdb->posts}.post_type='page') AND $zensor_table.moderation_status='$which' ".
"AND {$wpdb->posts}.post_status='publish' ".
(isset($_GET['id']) ? "ORDER BY preload DESC " : "").
"LIMIT $offset,$limit";
$posts = $wpdb->get_results( $query );
$counts = Zensor_Common::get_counts();
?>
' . __("Pages/Posts Awaiting Moderation", "zensor") . '';
echo '
' . __("The pages/posts below have recently been edited or published by authors on your site. They are now awaiting moderation. To moderate a page, click 'Preview On'. You then have the option to approve or reject the page as it is. The reason you give will be sent to the original author. Approved pages/posts will be immediately available to site visitors. Rejected pages/posts will need to be edited by the original author and then re-moderated.", "zensor") . '
';
} else {
echo '
' . __("Rejected Pages/Posts", "zensor") . '
';
echo '
' . __("The pages/posts below have recently been rejected by a moderator on your site. They are now awaiting editing by the original author, but can also be re-moderated now. To moderate a page, click 'Preview On'. You then have the option to approve or reject the page as it is. The reason you give will be sent to the original author. Approved pages/posts will be immediately available to site visitors. Rejected pages/posts will need to be edited by the original author and then re-moderated.", "zensor") . '
';
}
?>
|
|
|
|
|
|
';
if( $which == ZENSOR_AWAITING ) {
_e('No pages/posts awaiting moderation!', 'zensor');
} else {
_e('No rejected pages/posts!', 'zensor');
}
echo " | \n";
}
if( !isset( $_GET['id'] ) ) Zensor_Manage::preview_row();
?>
$limit ) {
echo '
';
if( $counts[$which] > $offset+$limit ) {
?>
0 ) {
?>
';
}
?>
|
|
|
ID))));
$preload = isset($_GET['id']) && $_GET['id'] == $post->ID;
$preview_text = $preload ? __('Preview Off', 'zensor') : __('Preview On', 'zensor');
?>
| post_type), 'zensor');?> |
post_title;?> |
display_name;?> |
g:i:s a'), $post->last_updated); ?> |
message);?> |
class="edit"
href="ID ); ?>"
onclick="javascript: zensor_showPreview(this, '', ID; ?>); return false;">
|
ID);
}
/**
* Changes the Zensor moderation status for a group of posts
*
* The group of posts is either 'awaiting' or 'rejected' posts and they
* can be either approved or rejected.
*
* @param int $moderator_id The user id of the moderator doing the moderation
* @param string $which_posts The posts to moderate. Either 'awaiting' or 'rejected'
* @param string $what_action The desired status. Either 'approved' or 'rejected'
*/
function bulk_moderate( $moderator_id, $which_posts, $what_action )
{
global $wpdb, $zensor_table;
$posts = $wpdb->get_var( "SELECT GROUP_CONCAT(post_id) FROM $zensor_table WHERE moderation_status='$which_posts'" );
$posts = explode(',', $posts);
$message = __('Bulk', 'zensor') . " $what_action";
// Update records that are already in the table.
$query = "UPDATE $zensor_table SET moderation_status='$what_action', ".
"moderator_id=$moderator_id, message='$message' ".
"WHERE moderation_status='$which_posts'";
$wpdb->query( $query );
// XXX: Send email to owner of post
$notifications = get_option('zensor_author_notifications');
$notifications = array_unique(array_merge( $notifications, $posts ));
update_option( 'zensor_author_notifications', $notifications );
}
/**
* Changes the Zensor moderation status of a single post and emails the owner
*
* @param int $post_id The id of the post being moderated
* @param string $action The action to take. Either 'approve' or 'reject'
* @param string $message The message to attach to the moderation
*/
function moderate( $post_id, $action, $message )
{
global $user_identity, $user_ID, $wpdb, $zensor_table;
$mod_info = new Zensor_Info($post_id);
if( $action == 'approve' ) {
if( !$mod_info->approve($user_ID, $user_identity, $message) ) return false;
$email_subject = Zensor_Common::replace_tags(get_option( "zensor_approval_email_subject" ), $mod_info);
$email_body = Zensor_Common::replace_tags(get_option( "zensor_approval_email_body" ), $mod_info);
} else if( $action == 'reject' ) {
if( !$mod_info->reject($user_ID, $user_identity, $message) ) return false;
$email_subject = Zensor_Common::replace_tags(get_option( "zensor_rejection_email_subject" ), $mod_info);
$email_body = Zensor_Common::replace_tags(get_option( "zensor_rejection_email_body" ), $mod_info);
} else {
return false;
}
// XXX: Send email to owner of post
$notifications = get_option('zensor_author_notifications');
$notifications []= $post_id;
update_option( 'zensor_author_notifications', $notifications );
return true;
}
/**
* Processes POSTs to do the individual and bulk moderation
*/
function handle_posts()
{
global $user_identity, $user_ID, $wpdb, $zensor_table;
if( isset( $_POST['zensor_bulk_action'] ) ) {
check_admin_referer('zensor_bulk-action');
if( isset( $_POST['zensor_bulk-approve'] ) ) {
Zensor_Manage::bulk_moderate( $user_ID,
$_POST['zensor_bulk_action'],
ZENSOR_APPROVED );
} else if( isset( $_POST['zensor_bulk-reject'] ) ) {
Zensor_Manage::bulk_moderate( $user_ID,
$_POST['zensor_bulk_action'],
ZENSOR_REJECTED );
}
} else if( isset( $_POST['zensor_bulk-reject'] ) ) {
check_admin_referer('zensor_bulk-action');
Zensor_Manage::bulk_moderate( $user_ID, ZENSOR_REJECTED );
} else if( isset( $_POST['zensor_moderate'] ) ) {
check_admin_referer('zensor_moderate');
Zensor_Manage::moderate( $_POST['zensor_post_id'],
isset( $_POST['zensor_approve'] ) ? 'approve' : 'reject',
$_POST['zensor_message'] );
}
}
}
/*
* Hook into the init action to process POSTs
*/
if( function_exists('add_action') )
{
add_action('init', array('Zensor_Manage', 'handle_posts') );
}
?>