approving) || in_array($post_id, $this->deleting)){ return; } $this->deleting[] = $post_id; $post = get_post($post_id); // Ensure we're not working with a revision if($post->post_parent != 0){ return; } // Get dashboard post id and password $parent_id = get_post_meta($post_id, '_remote_id', true); // Make sure this is a postrunner post if($remote_id == 0){ return; } PostrunnerClient::approve_post($post_id, $parent_id, 'deleted', '', 0, ''); } function settings(){ register_setting('general', 'pr_share_pageviews'); // Add the section to reading settings so we can add our // fields to it add_settings_section('postrunner_settings_section', 'Postrunner Settings', array($this, 'display_settings_page'), 'general'); // Add the field with the names and function to use for our new // settings, put it in our new section add_settings_field('pr_share_pageviews', 'Share Traffic Data', array($this, 'share_pageviews_setting_callback'), 'general', 'postrunner_settings_section'); } function display_settings_page(){ // No intro text yet. } function share_pageviews_setting_callback() { echo '

Only (rough) number of daily visitors will be shared. No identifiable or unique information will be shared. Data is used to display a basic traffic level for your site in Postrunner listings.

'; } function post_page_setup() { global $post; // Remove normal publish box $remote_id = get_post_meta($post->ID, '_remote_id', true); // Ensure this post came from postrunner, and the current user is an admin if(current_user_can('manage_options') && $remote_id != 0){ remove_meta_box( 'submitdiv', 'post', 'side' ); add_meta_box('submitdiv', 'Publish or Decline Post', array($this, 'approval_box'), 'post', 'side', 'high'); } } // Adds the actual option box function approval_box() { global $post; $post_score = intval(get_post_meta($post->ID, '_pr_score', true)); $feedback = get_post_meta($post->ID, '_pr_feedback', true); $post_type = $post->post_type; $post_type_object = get_post_type_object($post_type); $can_publish = current_user_can($post_type_object->cap->publish_posts); ?>

Please score this post

Send feedback to the author:
post_status && 'future' != $post->post_status && 'pending' != $post->post_status ) { ?> post_status ) { ?>style="display:none" type="submit" name="save" id="save-post" value="" tabindex="4" class="button button-highlighted" /> post_status && $can_publish ) { ?>
post_status ) { $preview_link = esc_url( get_permalink( $post->ID ) ); $preview_button = __( 'Preview Changes' ); } else { $preview_link = get_permalink( $post->ID ); if ( is_ssl() ) $preview_link = str_replace( 'http://', 'https://', $preview_link ); $preview_link = esc_url( apply_filters( 'preview_post_link', add_query_arg( 'preview', 'true', $preview_link ) ) ); $preview_button = __( 'Preview' ); } ?>
post_status ) { case 'private': _e('Privately Published'); break; case 'publish': _e('Published'); break; case 'future': _e('Scheduled'); break; case 'pending': _e('Pending Review'); break; case 'draft': case 'auto-draft': _e('Draft'); break; } ?> post_status || 'private' == $post->post_status || $can_publish ) { ?> post_status ) { ?>style="display:none;" class="edit-post-status hide-if-no-js" tabindex='4'>
post_status ) { $post->post_password = ''; $visibility = 'private'; $visibility_trans = __('Private'); } elseif ( !empty( $post->post_password ) ) { $visibility = 'password'; $visibility_trans = __('Password protected'); } elseif ( $post_type == 'post' && is_sticky( $post->ID ) ) { $visibility = 'public'; $visibility_trans = __('Public, Sticky'); } else { $visibility = 'public'; $visibility_trans = __('Public'); } echo esc_html( $visibility_trans ); ?>
ID)); ?> /> />
ID ) ); ?> tabindex="4" />
/>

/>

ID ) { if ( 'future' == $post->post_status ) { // scheduled for publishing at a future date $stamp = __('Scheduled for: %1$s'); } else if ( 'publish' == $post->post_status || 'private' == $post->post_status ) { // already published $stamp = __('Published on: %1$s'); } else if ( '0000-00-00 00:00:00' == $post->post_date_gmt ) { // draft, 1 or more saves, no date specified $stamp = __('Publish immediately'); } else if ( time() < strtotime( $post->post_date_gmt . ' +0000' ) ) { // draft, 1 or more saves, future date specified $stamp = __('Schedule for: %1$s'); } else { // draft, 1 or more saves, date specified $stamp = __('Publish on: %1$s'); } $date = date_i18n( $datef, strtotime( $post->post_date ) ); } else { // draft (no saves, and thus no date specified) $stamp = __('Publish immediately'); $date = date_i18n( $datef, strtotime( current_time('mysql') ) ); } if ( $can_publish ) : // Contributors don't get to choose the date of publish ?>
post_status == 'publish'): ?>
post_status, array('publish', 'future', 'private') ) || 0 == $post->ID ) { if ( $can_publish ) : if ( !empty($post->post_date_gmt) && time() < strtotime( $post->post_date_gmt . ' +0000' ) ) : ?> '5', 'accesskey' => 'p' ) ); ?> '5', 'accesskey' => 'p' ) ); ?> '5', 'accesskey' => 'p' ) ); ?>
get_var("SELECT count(ID) FROM $wpdb->posts WHERE post_parent = 0 and post_status = 'publish' and post_type = 'post'"); } function get_pr_post_count(){ global $wpdb; return $wpdb->get_var("select count(ID) from $wpdb->posts p join $wpdb->postmeta pm on p.ID = pm.post_id where meta_key = '_remote_id' AND post_parent = 0 and post_status = 'publish' and post_type = 'post'"); } function handle_post_save($data, $postarr){ global $wpdb; // $data holds content that is about to be inserted. // $postarr holds array from argument to wp_insert_post $post_id = $postarr['ID']; $this->approving[] = $post_id; // Prevent this code from running on revisions - we only want to run it when the modified post is being // inserted over the original parent post. if(DOING_AUTOSAVE === true || $data['post_parent'] != 0 ){ return $data; } // Only work on Postrunner posts $parent_id = get_post_meta($post_id, '_remote_id', true); if(!$parent_id) return $data; $status = get_post_meta($post_id, '_pr_status', true); if(isset($_POST['pr_score'])){ $score = intval($_POST['pr_score']); }else{ $score = get_post_meta($post_id, '_pr_score', true); } if(isset($_POST['pr_feedback'])){ $feedback = $_POST['pr_feedback']; }else{ $feedback = get_post_meta($post_id, '_pr_feedback', true); } if($_POST['pr_blacklist'] == 'blacklist'){ $blacklist = true; }else{ $blacklist = false; } // Check if we're declining if($_POST['save'] == 'Decline Post' || $_POST['save'] == 'Delete Post'){ if($score < 1){ $this->notices[] = "In order to decline or approve this post, you must choose a post score."; $location = add_query_arg( 'pr_message', 1, get_edit_post_link( $post_id, 'url' ) ); header('LOCATION: '.$location); die(); } $approve = $_POST['save'] == 'Delete Post' ? 'deleted' : 'declined'; $permalink = ''; PostrunnerClient::approve_post($post_id, $parent_id, $approve, $permalink, $score, $feedback, $blacklist); wp_delete_post($post_id, true); return $data; } switch($data['post_status']){ case 'publish': // Check if this post has already been approved if($status != 'live'){ if($score < 1){ $this->notices[] = "In order to decline or approve this post, you must choose a post score."; $location = add_query_arg( 'pr_message', 1, get_edit_post_link( $post_id, 'url' ) ); header('LOCATION: '.$location); die(); } $permalink = get_permalink($post_id); update_post_meta($post_id, '_pr_status', 'live'); update_post_meta($post_id, '_pr_feedback', $feedback); update_post_meta($post_id, '_pr_score', $score); $approve = 'approved'; PostrunnerClient::approve_post($post_id, $parent_id, $approve, $permalink, $score, $feedback, $blacklist); } break; case 'pending': case 'draft': case 'private': default: update_post_meta($post_id, '_pr_feedback', $feedback); update_post_meta($post_id, '_pr_score', $score); break; } return $data; } function display_notices(){ if(isset($_GET['pr_message'])){ switch($_GET['pr_message']){ case '1': $notice['type'] = 'error'; $notice['message'] = 'You must give this post a score before you can approve or decline it.'; $this->notices[] = $notice; break; } } if( is_array($this->notices) && !empty($this->notices) ){ foreach($this->notices as $notice){ if(!is_array($notice)){ $notice['type'] = 'updated'; $notice['message'] = $notice; } echo "
"; echo "

".$notice['message']."

\n"; echo "
"; } } } function post_date_column_time($time, $post, $column_name, $mode){ if($this->is_from_postrunner($post->ID)){ if($post->post_status != 'publish'){ $time = "Rec'd ".human_time_diff($this->get_post_receipt_time($post->ID))." ago"; $sendback_date = strtotime('+'.PR_REVIEW_PERIOD, $this->get_post_receipt_time($post->ID)); // Total review time in seconds $total_review_time = strtotime('+'.PR_REVIEW_PERIOD, 0); // Color the "returned" text // Greater then 2/3 review time left if($sendback_date - time() > ($total_review_time/3)*2){ $color = '#108f25'; // Greater than 1/3 review time left }elseif($sendback_date - time() > ($total_review_time/3)){ $color = '#d2c106'; }else{ $color = '#ff0000'; } if($sendback_date < time()){ $sendback_date = time(); } $time .= '
'.human_time_diff($sendback_date).' until rejection'; }else{ } } return $time; } // Fetches list of pr posts. Caches on a per pageload basis function is_from_postrunner($post_id = 0){ global $wpdb; if(empty($this->pr_posts)){ $pr_post_results = $wpdb->get_results("select post_id, meta_value from $wpdb->postmeta where meta_key = '_pr_sent'", ARRAY_A); if(is_array($pr_post_results) && !empty($pr_post_results)){ foreach($pr_post_results as $pr_post){ $this->pr_posts[$pr_post['post_id']] = $pr_post['meta_value']; } } } if(in_array($post_id, array_keys($this->pr_posts))){ return true; }else{ return false; } } function display_post_states($states){ global $post; if($this->is_from_postrunner($post->ID)){ if($post->post_status == 'pending'){ $states = array(); $states[] = '
PostRunner - Waiting to be Reviewed'; } } return $states; } function posts_join($join){ global $wpdb; if( !empty($_GET['postrunner_status'])) { $join .= " join $wpdb->postmeta pm ON $wpdb->posts.ID = pm.post_id"; } return $join; } function posts_where($where){ global $wpdb; if(!empty($_GET['postrunner_status'])){ $pr_post_status = $wpdb->escape($_GET['postrunner_status']); switch($pr_post_status){ case 'approved': $where .= " AND pm.meta_key = '_pr_sent' AND post_status = 'publish'"; break; case 'waiting': $where .= " AND pm.meta_key = '_pr_sent' AND post_status != 'publish'"; break; case 'any': default: $where .= " AND pm.meta_key = '_pr_sent'"; break; } } return $where; } function post_page_dropdowns($args) { global $pagenow; if($pagenow = 'edit.php'){ ?> is_from_postrunner(); } return $this->pr_posts[$post_id]; } function dashboard_setup(){ wp_add_dashboard_widget('pr_dashboard_widget', 'PostRunner', array($this, 'dashboard_widget')); } function dashboard_widget(){ global $wpdb; $total_posts = $wpdb->get_var("select count(ID) from $wpdb->posts p join $wpdb->postmeta pm on p.ID = pm.post_id where meta_key = '_pr_sent' AND post_parent = 0"); $approved_posts = $wpdb->get_var("select count(ID) from $wpdb->posts p join $wpdb->postmeta pm on p.ID = pm.post_id where meta_key = '_pr_sent' AND post_parent = 0 AND post_status = 'publish'"); $waiting_approval = $total_posts-$approved_posts; ?>
Posts received from Postrunner
Posts approved
Posts waiting for approval
get_results("select p.ID, (select meta_value from $wpdb->postmeta where post_id = p.id and meta_key = '_remote_id') as parent_id, (select meta_value from $wpdb->postmeta where post_id = p.id and meta_key = '_pr_sent') as pr_sent from $wpdb->posts p join $wpdb->postmeta m on p.id = m.post_id where post_status != 'publish' AND meta_key = '_remote_id' HAVING pr_sent <= $time", ARRAY_A); if(is_array($old_posts)){ foreach($old_posts as $old_post){ $post_id = $old_post['ID']; $parent_id = $old_post['parent_id']; $approve = 'ignored'; $permalink = ''; $score = 0; $feedback = ''; PostrunnerClient::approve_post($post_id, $parent_id, $approve, $permalink, $score, $feedback); wp_delete_post($post_id, true); } } } public function track_pageviews(){ // If it's a new day, truncate the pageviews table if(date('m d y') != get_option('pr_pageview_day')){ global $wpdb; update_option('pr_pageview_day', date('m d y')); $yesterdays_count = $this->get_visitor_count(); update_option('pr_pageview_yesterday', $yesterdays_count); $wpdb->query('TRUNCATE TABLE '.$wpdb->prefix.'postrunner_pageviews'); } if(!is_admin() && !is_user_logged_in()){ global $wpdb; $wpdb->query('INSERT IGNORE INTO '.$wpdb->prefix.'postrunner_pageviews (ip_address) VALUES (INET_ATON(\''.$_SERVER['REMOTE_ADDR'].'\'))' ); } } public static function get_visitor_count(){ global $wpdb; $count = $wpdb->get_var('SELECT count(*) FROM '.$wpdb->prefix.'postrunner_pageviews'); return $count; } public function activate_plugin(){ $share = get_option('pr_share_pageviews', true); update_option($share); global $wpdb; $wpdb->query('CREATE TABLE IF NOT EXISTS `'.$wpdb->prefix.'postrunner_pageviews` ( `ip_address` int(11) unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`ip_address`) ) ENGINE=myisam DEFAULT CHARSET=latin1;'); } }