コード例 #1
0
 /**
  * SyndicatedPost::fix_revision_meta() - Ensures that we get the meta
  * data (authorship, guid, etc.) that we want when storing revisions of
  * a syndicated post.
  *
  * In their infinite wisdom, the WordPress coders seem to have made it
  * completely impossible for a plugin that uses wp_insert_post() to set
  * certain meta-data (such as the author) when you store an old revision
  * of an updated post. Instead, it uses the WordPress defaults (= cur.
  * active user ID if the process is running with a user logged in, or
  * = #0 if there is no user logged in). This results in bogus authorship
  * data for revisions that are syndicated from off the feed, unless we
  * use a ridiculous kludge like this to end-run the munging of meta-data
  * by _wp_put_post_revision.
  *
  * @param int $revision_id The revision ID to fix up meta-data
  */
 function fix_revision_meta($revision_id)
 {
     global $wpdb;
     $post_author = (int) $this->post['post_author'];
     $revision_id = (int) $revision_id;
     // Let's fix the author.
     set_post_field('post_author', $this->post['post_author'], $revision_id);
     // Let's fix the GUID to a dummy URL with the update hash.
     set_post_field('guid', 'http://feedwordpress.radgeek.com/?rev=' . $this->update_hash(), $revision_id);
     // Let's fire an event for add-ons and filters
     do_action('syndicated_post_fix_revision_meta', $revision_id, $this);
 }
コード例 #2
0
	function process_retirements ($delta) {
		global $post;

		$q = new WP_Query(array(
		'fields' => '_synfrom',
		'post_status__not' => 'fwpretired',
		'ignore_sticky_posts' => true,
		'meta_key' => '_feedwordpress_retire_me_'.$this->id,
		'meta_value' => '1',
		));
		if ($q->have_posts()) :
			foreach ($q->posts as $p) :
				$old_status = $p->post_status;
				FeedWordPress::diagnostic('syndicated_posts', 'Retiring existing post # '.$p->ID.' "'.$p->post_title.'" due to absence from a non-incremental feed.');
				set_post_field('post_status', 'fwpretired', $p->ID);
				wp_transition_post_status('fwpretired', $old_status, $p);
				delete_post_meta($p->ID, '_feedwordpress_retire_me_'.$this->id);
			endforeach;
		endif;
		return $delta;
	}
コード例 #3
0
 public function feedwordpress_cleanup()
 {
     if (get_option('feedwordpress_process_zaps', null)) {
         $q = new WP_Query(array('fields' => '_synfrom', 'post_status' => 'fwpzapped', 'ignore_sticky_posts' => true, 'meta_key' => '_feedwordpress_zapped_blank_me', 'meta_value' => 1));
         if ($q->have_posts()) {
             foreach ($q->posts as $p) {
                 $post_id = $p->ID;
                 $revisions = wp_get_post_revisions($post_id, array("check_enabled" => false));
                 # Now nuke the content of the post & its revisions
                 set_post_field('post_content', '', $post_id);
                 set_post_field('post_excerpt', '', $post_id);
                 foreach ($revisions as $rev) {
                     set_post_field('post_content', '', $rev->ID);
                     set_post_field('post_excerpt', '', $rev->ID);
                 }
                 # Un-tag it for blanking.
                 delete_post_meta($p->ID, '_feedwordpress_zapped_blank_me');
                 # Don't remove old_status indicator. A later
                 # update from the feed may cause us to once
                 # again have some content so we can un-zap.
             }
         }
         $q = new WP_Query(array('fields' => '_synfrom', 'post_status' => 'fwpzapped', 'ignore_sticky_posts' => true, 'meta_key' => '_feedwordpress_zapped_blank_me', 'meta_value' => 2));
         if ($q->have_posts()) {
             foreach ($q->posts as $p) {
                 update_post_meta($p->ID, '_feedwordpress_zapped_blank_me', 1);
             }
         }
         update_option('feedwordpress_process_zaps', 0);
     }
 }
コード例 #4
0
 function store()
 {
     global $wpdb;
     if ($this->filtered()) {
         // This should never happen.
         FeedWordPress::critical_bug('SyndicatedPost', $this, __LINE__, __FILE__);
     }
     $freshness = $this->freshness();
     if ($freshness > 0) {
         # -- Look up, or create, numeric ID for author
         $this->post['post_author'] = $this->author_id($this->link->setting('unfamiliar author', 'unfamiliar_author', 'create'));
         if (is_null($this->post['post_author'])) {
             FeedWordPress::diagnostic('feed_items:rejected', 'Filtered out item [' . $this->guid() . '] without syndication: no author available');
             $this->post = NULL;
         }
     }
     if (!$this->filtered() and $freshness > 0) {
         $consider = array('category' => array('abbr' => 'cats', 'domain' => array('category', 'post_tag')), 'post_tag' => array('abbr' => 'tags', 'domain' => array('post_tag')));
         $termSet = array();
         $valid = null;
         foreach ($consider as $what => $taxes) {
             if (!is_null($this->post)) {
                 // Not filtered out yet
                 # -- Look up, or create, numeric ID for categories
                 $taxonomies = $this->link->setting("match/" . $taxes['abbr'], 'match_' . $taxes['abbr'], $taxes['domain']);
                 // Eliminate dummy variables
                 $taxonomies = array_filter($taxonomies, 'remove_dummy_zero');
                 $terms = $this->category_ids($this->feed_terms[$what], $this->link->setting("unfamiliar {$what}", "unfamiliar_{$what}", 'create:' . $what), $taxonomies, array('singleton' => false, 'filters' => true));
                 if (is_null($terms) or is_null($termSet)) {
                     // filtered out -- no matches
                 } else {
                     $valid = true;
                     // filter mode off, or at least one match
                     foreach ($terms as $tax => $term_ids) {
                         if (!isset($termSet[$tax])) {
                             $termSet[$tax] = array();
                         }
                         $termSet[$tax] = array_merge($termSet[$tax], $term_ids);
                     }
                 }
             }
         }
         if (is_null($valid)) {
             // Plonked
             $this->post = NULL;
         } else {
             // We can proceed
             $this->post['tax_input'] = array();
             foreach ($termSet as $tax => $term_ids) {
                 if (!isset($this->post['tax_input'][$tax])) {
                     $this->post['tax_input'][$tax] = array();
                 }
                 $this->post['tax_input'][$tax] = array_merge($this->post['tax_input'][$tax], $term_ids);
             }
             // Now let's add on the feed and global presets
             foreach ($this->preset_terms as $tax => $term_ids) {
                 if (!isset($this->post['tax_input'][$tax])) {
                     $this->post['tax_input'][$tax] = array();
                 }
                 $this->post['tax_input'][$tax] = array_merge($this->post['tax_input'][$tax], $this->category_ids($term_ids, 'create:' . $tax, array($tax), array('singleton' => true)));
             }
         }
     }
     if (!$this->filtered() and $freshness > 0) {
         // Filter some individual fields
         // If there already is a post slug (from syndication or by manual
         // editing) don't cause WP to overwrite it by sending in a NULL
         // post_name. Props Chris Fritz 2012-11-28.
         $post_name = is_null($this->_wp_post) ? NULL : $this->_wp_post->post_name;
         // Allow filters to set post slug. Props niska.
         $post_name = apply_filters('syndicated_post_slug', $post_name, $this);
         if (!empty($post_name)) {
             $this->post['post_name'] = $post_name;
         }
         $this->post = apply_filters('syndicated_post', $this->post, $this);
         // Allow for feed-specific syndicated_post filters.
         $this->post = apply_filters("syndicated_post_" . $this->link->uri(), $this->post, $this);
     }
     // Hook in early to make sure these get inserted if at all possible
     add_action('transition_post_status', array($this, 'add_rss_meta'), -10000, 3);
     $retval = array(1 => 'updated', 2 => 'new');
     $ret = false;
     if (!$this->filtered() and isset($retval[$freshness])) {
         $diag = array(1 => 'Updating existing post # ' . $this->wp_id() . ', "' . $this->post['post_title'] . '"', 2 => 'Inserting new post "' . $this->post['post_title'] . '"');
         FeedWordPress::diagnostic('syndicated_posts', $diag[$freshness]);
         $this->insert_post($freshness == 1);
         $hook = array(1 => 'update_syndicated_item', 2 => 'post_syndicated_item');
         do_action($hook[$freshness], $this->wp_id(), $this);
         $ret = $retval[$freshness];
     }
     // If this is a legit, non-filtered post, tag it as found on the feed
     // regardless of fresh or stale status
     if (!$this->filtered()) {
         $key = '_feedwordpress_retire_me_' . $this->link->id;
         delete_post_meta($this->wp_id(), $key);
         $status = get_post_field('post_status', $this->wp_id());
         if ('fwpretired' == $status and $this->link->is_incremental()) {
             FeedWordPress::diagnostic('syndicated_posts', "Un-retiring previously retired post # " . $this->wp_id() . " due to re-appearance on non-incremental feed.");
             set_post_field('post_status', $this->post['post_status'], $this->wp_id());
             wp_transition_post_status($this->post['post_status'], $status, $old_status, $this->post);
         }
     }
     // Remove add_rss_meta hook
     remove_action('transition_post_status', array($this, 'add_rss_meta'), -10000, 3);
     return $ret;
 }
コード例 #5
0
 function process_expirations($delta)
 {
     global $post;
     global $wpdb;
     $q = new WP_Query(array('post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => get_option('fwplpbd_expiration_chunk', 25), 'meta_key' => '_syndication_expiration_date', 'meta_value' => time(), 'meta_compare' => '<='));
     while ($q->have_posts()) {
         $q->the_post();
         $expiration = get_post_meta($post->ID, '_syndication_expiration_date', true);
         if ((int) $expiration and (int) $expiration <= time()) {
             $action = get_post_meta($post->ID, '_syndication_expiration_action', true);
             FeedWordPress::diagnostic('expiration', 'Post [' . $post->ID . '] "' . esc_html($post->post_title) . '" expired as of ' . date('r', (int) $expiration) . ' and will now be ' . ('trash' == $action ? 'trashed' : ('nuke' == $action ? 'deleted permanently' : 'hidden')));
             switch ($action) {
                 case 'trash':
                 case 'nuke':
                     $feed = get_syndication_feed_object($post->ID);
                     $thumbId = get_post_thumbnail_id($post->ID);
                     wp_delete_post($post->ID, 'nuke' == $action);
                     // Check to see whether any other posts
                     // use this as a Featured Image. If not
                     // then zap it.
                     if ("nuke" == $feed->setting('post expiration thumbnail', 'post_expiration_thumbnail', "keep")) {
                         if (strlen($thumbId) > 0) {
                             $qrows = $wpdb->get_results($wpdb->prepare("\n\t\t\t\t\t\t\tSELECT meta_value FROM {$wpdb->postmeta}\n\t\t\t\t\t\t\tWHERE meta_key = '_thumbnail_id'\n\t\t\t\t\t\t\tAND meta_value = '%d'\n\t\t\t\t\t\t\tAND post_id <> '%d'\n\t\t\t\t\t\t\t", $thumbId, $post->ID));
                             if (count($qrows) < 1) {
                                 FeedWordPress::diagnostic('expiration', 'The expired post [' . $post->ID . ']  had an attached Featured Image, which is not used as the Featured Image for any other post. We will now clean up and the image will be ' . ('trash' == $action ? 'trashed' : ('nuke' == $action ? 'deleted permanently' : 'hidden')));
                                 wp_delete_attachment($thumbId, 'nuke' == $action);
                             } else {
                                 FeedWordPress::diagnostic('expiration', 'The expired post [' . $post->ID . ']  had an attached Featured Image, but it CANNOT be deleted right now because at least one other post uses the same image as its Featured Image.');
                             }
                         }
                     }
                     break;
                 case 'hide':
                 case 'redirect':
                 default:
                     $old_status = $post->post_status;
                     set_post_field('post_status', 'expired', $post->ID);
                     wp_transition_post_status('expired', $old_status, $post);
                     break;
             }
         }
     }
 }