* @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. */ function admin_manage_page() { global $wpdb, $post; // Handle paging and subpage $limit = 10; $offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0; ?>
posts}.ID, {$wpdb->posts}.post_type, {$wpdb->posts}.post_title, ". "{$wpdb->users}.display_name, {$wpdb->posts}.post_modified, {$wpdb->postmeta}.meta_value AS message " . (isset($_GET['id']) ? ", {$wpdb->posts}.ID=".intval($_GET['id'])." AS preload " : ""). "FROM {$wpdb->posts} " . "JOIN {$wpdb->users} ON post_author={$wpdb->users}.ID " . "LEFT JOIN {$wpdb->postmeta} ON {$wpdb->posts}.ID={$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key='_zensor_message' " . "WHERE ({$wpdb->posts}.post_type='post' OR {$wpdb->posts}.post_type='page') AND {$wpdb->posts}.post_status='pending' ". (isset($_GET['id']) ? "ORDER BY preload DESC " : ""). "LIMIT $offset,$limit"; $posts = $wpdb->get_results( $query ); echo '

' . __("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") . '

'; ?> \n"; } if( !isset( $_GET['id'] ) ) Zensor_Manage::preview_row(); ?>
 
'; _e('No pages/posts awaiting moderation!', 'zensor'); echo "
$limit ) { echo '

" /> " />
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;?> 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, $what_action ) { global $wpdb, $user_identity; // Allow the post status to go to 'publish' remove_filter('pre_post_status', array('Zensor_Edit', 'prevent_publish_status')); $new_stati = array(ZENSOR_APPROVED=>'publish', ZENSOR_REJECTED=>'draft'); if( !array_key_exists($what_action, $new_stati ) ) return; $message = sprintf( __('Bulk %1$s by %2$s', 'zensor'), $what_action, $user_identity); $new_status = $new_stati[$what_action]; $posts = $wpdb->get_var( "SELECT GROUP_CONCAT(ID) FROM {$wpdb->posts} WHERE post_status='pending'" ); $ids = explode(',', $posts); foreach( $ids as $id ) { Zensor_Common::moderate_post($id, $message, $new_status); } $notifications = get_option('zensor_author_notifications'); $notifications = array_unique(array_merge( $notifications, $ids )); update_option( 'zensor_author_notifications', $notifications ); wp_redirect(Zensor_Common::uri()); } /** * 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; // Allow the post_status to go to 'publish' remove_filter('pre_post_status', array('Zensor_Edit', 'prevent_publish_status')); if( $action == 'approve' ) { Zensor_Common::approve_post($post_id, $message); } else if( $action == 'reject' ) { Zensor_Common::reject_post($post_id, $message); } else { return false; } $notifications = get_option('zensor_author_notifications'); $notifications []= $post_id; update_option( 'zensor_author_notifications', $notifications ); wp_redirect(Zensor_Common::uri()); return true; } /** * Processes POSTs to do the individual and bulk moderation */ function handle_posts() { global $user_identity, $user_ID; if( isset( $_POST['zensor_bulk-approve'] ) ) { check_admin_referer('zensor_bulk-action'); if( !current_user_can('zensor_moderate') ) wp_die(__('You are not allowed to moderate.')); Zensor_Manage::bulk_moderate( $user_ID, ZENSOR_APPROVED ); } else if( isset( $_POST['zensor_bulk-reject'] ) ) { check_admin_referer('zensor_bulk-action'); if( !current_user_can('zensor_moderate') ) wp_die(__('You are not allowed to moderate.')); Zensor_Manage::bulk_moderate( $user_ID, ZENSOR_REJECTED ); } else if( isset( $_POST['zensor_moderate'] ) ) { check_admin_referer('zensor_moderate'); if( !current_user_can('zensor_moderate') ) wp_die(__('You are not allowed to moderate.')); Zensor_Manage::moderate( $_POST['zensor_post_id'], isset( $_POST['zensor_approve'] ) ? 'approve' : 'reject', stripslashes($_POST['zensor_message']) ); } } } /* * Hook into the init action to process POSTs */ if( function_exists('add_action') ) { add_action('init', array('Zensor_Manage', 'handle_posts') ); } ?>