/**
	 * Deletes all posts generated by the source identified by the given source id.
	 *
	 * @param $source_id The ID of the feed source, to which the posts to be deleted belong to.
	 * @since 1.3
	 */
	public function delete_posts_from_source_query( $query, $source_id ) {
		if ( wprss_ftp_using_feed_items( $source_id ) ) return $query;
		return new WP_Query(
			array(
					'meta_key'		 => 'wprss_ftp_feed_source',
					'meta_value' 	 => $source_id,
					'post_type'		 => 'any',
					'post_status'	 => 'any',
					'posts_per_page' => -1
				)
		);
	}
	/**
	 * Checks if the feed source uses the force full content option or meta option, and
	 * returns the fulltextrss url if so.
	 * 
	 * @since 1.0
	 */
	public static function check_force_full_content( $feed_url, $feed_ID ) {
		if ( wprss_ftp_using_feed_items( $feed_ID ) ) {
			return $feed_url;
		}
		// Get the computed settings / meta options for the feed source
		$options = WPRSS_FTP_Settings::get_instance()->get_computed_options( $feed_ID );

		// If using force full content option / meta
		if ( WPRSS_FTP_Utils::multiboolean( $options['force_full_content'] ) === TRUE ) {
			
			$service = WPRSS_FTP_Settings::get_instance()->get('full_text_rss_service');
			$service = apply_filters( 'wprss_ftp_service_before_full_text_feed_url', $service );
			switch( $service ) {
				case 'free':
					$key = WPRSS_FTP_FULL_TEXT_RSS_KEY;
					$API_HASH = sha1( $key . $feed_url );
					$encoded_url = urlencode( $feed_url );
					// Prepare the fulltext sources
					$full_text_sources = apply_filters(
						'wprss_ftp_full_text_sources',
						array(
							"http://fulltext.wprssaggregator.com/makefulltextfeed.php?key=1&hash=$API_HASH&links=preserve&exc=1&url=",
							"http://ftr-premium.fivefilters.org/makefulltextfeed.php?key=1920&hash=$API_HASH&max=10&links=preserve&exc=1&url=",						
						)
					);
					// Start with no feed to use
					$feed_url_to_use = NULL;

					// Load SimplePie
					require_once ( ABSPATH . WPINC . '/class-feed.php' );

					// For each source ...
					foreach ( $full_text_sources as $full_text_source ) {
						// Prepare the feed
						$full_text_feed_url = $full_text_source . $encoded_url;
						$feed = wprss_fetch_feed( $full_text_feed_url, $feed_ID );

						// If the feed has no errors, the we will use this feed
						if ( !is_wp_error( $feed ) && !$feed->error() ) {
							$feed_url_to_use = $full_text_source . $encoded_url;
							break;
						}
					}
					
					// If after trying all the sources, the feed to use is still NULL, then no source was valid.
					// Return the same url passed as parameter, Otherwise, return the full text rss feed url
					if ( $feed_url_to_use === NULL ) {
						WPRSS_FTP_Utils::log( __( 'Failed to find a working full text rss service.', WPRSS_TEXT_DOMAIN ), 'check_force_full_content' );
					}
					return ( $feed_url_to_use === NULL )? $feed_url : $feed_url_to_use;

				case 'feeds_api':
					$api_key = WPRSS_FTP_Settings::get_instance()->get( 'feeds_api_key' );
					$encoded_url = urlencode( $feed_url );

					$feeds_api_feed_url = WPRSS_FTP_Utils::template(
						WPRSS_FTP_FEEDS_API_REQUEST_FORMAT,
						array(
							'url'	=>	$encoded_url,
							'key'	=>	$api_key,
						)
					);
					// Attempt to fetch the feed
					$feed = wprss_fetch_feed( $feeds_api_feed_url, $feed_ID );

					// If an error was encountered
					if (  is_wp_error( $feed ) || $feed->error() ) {
						// Request the error message and log it
						$response = wp_remote_get( $feeds_api_feed_url );
						WPRSS_FTP_Utils::log( "FeedsAPI failed to return a feed, and responded with: \"{$response['body']}\"" );
						// Return the original parameter url
						return $feed_url;
					}

					// Return the feeds api if no error was encountered.
					return $feeds_api_feed_url;

				// For other services
				default:
					return apply_filters( 'wprss_ftp_misc_full_text_url', $feed_url, $feed_ID, $service );
			}
		}
		// Otherwise, return back the given url
		else return $feed_url;
	}
	/**
	 * Returns the registered post types.
	 *
	 * @since 2.9.5
	 */
	public static function get_post_types() {
		// Get all post types, as objects
		$post_types = get_post_types( array(), 'objects' );
		// Remove the blacklist CPT
		unset( $post_types['wprss_blacklist'] );
		// If not using the legacy feed items, remove them
		if ( !wprss_ftp_using_feed_items() ) {
			unset( $post_types['wprss_feed_item'] );
		}
		// Return the list, mapping the post type objects to their singular name
		return array_map( array( __CLASS__, 'post_type_singular_name' ), $post_types );
	}