コード例 #1
0
/**
 * Prints the checkbox settings for enabling the legacy feed item.
 * 
 * @since 2.9.5
 */
function wprss_ftp_legacy_enable_option() {
	$legacy_enabled = WPRSS_FTP_Settings::get_instance()->get('legacy_enabled');
	echo WPRSS_FTP_Utils::boolean_to_checkbox(
		WPRSS_FTP_Utils::multiboolean( $legacy_enabled ),
		array(
			'id'	=>	'wprss-ftp-legacy-enabled',
			'name'	=>	WPRSS_FTP_Settings::OPTIONS_NAME . '[legacy_enabled]',
			'value'	=>	'true',
		)
	);
	echo WPRSS_Help::get_instance()->do_tooltip( WPRSS_FTP_HELP_PREFIX.'legacy_enabled' );
}
/**
 * Check if the import post is a YouTube, Dailymotion or Vimeo feed item.
 * 
 * @since 2.8
 */
function wprss_ftp_check_yt_feed( $post_id, $source_id ) {
	// Get the post form the ID
	$post = get_post( $post_id );
	// If the post is null, exit function.
	if ( $post === NULL ) return;

	// Get the permalink
	$permalink = get_post_meta( $post_id, 'wprss_item_permalink', TRUE );
	// If the permalink is empty, do not continue. Exit function
	if ( $permalink === '' ) return;

	// Get the source options
	$options = WPRSS_FTP_Settings::get_instance()->get_computed_options( $source_id );
	// If embedded content is not allowed, exit function.
	if ( WPRSS_FTP_Utils::multiboolean( $options['allow_embedded_content'] ) === FALSE ) return;

	// Search for the video host
	$found_video_host = preg_match( '/http[s]?:\/\/(www\.)?(youtube|dailymotion|vimeo)\.com\/(.*)/i', $permalink, $matches );

	// If video host was found and embedded content is allowed
	if ( $found_video_host !== 0 && $found_video_host !== FALSE ) {

		// Determine the embed link
		$embed = NULL;

		// Check which video host was found in the URL and prepare the embed link
		$host = $matches[2];
		switch( $host ) {
			case 'youtube':
				preg_match( '/(&|\?)v=([^&]+)/', $permalink, $yt_matches );
				$embed = 'http://www.youtube.com/embed/' . $yt_matches[2];
				$embed = apply_filters( 'wprss_ftp_yt_auto_embed_url', $embed, $post_id, $source_id );
				break;
			case 'vimeo':
				preg_match( '/(\d*)$/i', $permalink, $vim_matches );
				$embed = 'http://player.vimeo.com/video/' . $vim_matches[0];
				$embed = apply_filters( 'wprss_ftp_vimeo_auto_embed_url', $embed, $post_id, $source_id );
				break;
			case 'dailymotion':
				preg_match( '/(\.com\/)(video\/)(.*)/i', $permalink, $dm_matches );
				$embed = 'http://www.dailymotion.com/embed/video/' . $dm_matches[3];
				$embed = apply_filters( 'wprss_ftp_dm_auto_embed_url', $embed, $post_id, $source_id );
				break;
		}

		// If the embed link was successfully generated, add it to the post
		if ( $embed !== NULL ) {
			$content = $post->post_content;
			$video_link = apply_filters( 'wprss_ftp_enable_auto_embed_videos', FALSE ) === TRUE ? $embed : $permalink;
			$new_content = $video_link . "\n\n" . $content;
			WPRSS_FTP_Utils::update_post_content( $post_id, $new_content );

			// YouTube table fix
			// If the host found is YouTube, and the source is using featured images and removing them from the content
			// then remove the first column in the table that YouTube puts in the feed
			if ( $host === 'youtube' && WPRSS_FTP_Utils::multiboolean( $options['use_featured_image'] ) && WPRSS_FTP_Utils::multiboolean( $options['remove_ft_image'] ) ) {
				// Add a builtin extraction rule
				add_filter('wprss_ftp_built_in_rules', 'wprss_ftp_yt_table_cleanup');
			}
		}

	}
}
コード例 #3
0
	/**
	 * Handles the substitution of the placeholders.
	 * 
	 * @since 1.6
	 */
	public static function handle_appended_data( $post, $append, $wpautop = TRUE ) {
		if ( strlen($append) === 0 ) return "";

		// Get the placeholders
		$placeholders = self::get_placeholders();
		// Get the post's feed source
		$source_id = WPRSS_FTP_Meta::get_instance()->get_meta( $post->ID, 'feed_source' );
		$source = get_post( $source_id );
		// Array of [placeholder] => [text]
		$values = array();

		// Iterate each known placeholder
		foreach ( $placeholders as $placeholder => $description ) {
			$value = null;
			// Generate the text value for this placeholder
			switch ( $placeholder ) {

				case '{{feed_name}}':
					$value = $source->post_title;
					break;

				case '{{feed_url}}':
					$value = get_post_meta( $source_id, 'wprss_site_url', TRUE );
					if ( $value == '' ) {
						$value = get_post_meta( $source_id, 'wprss_url', TRUE );
					}
					break;

				case '{{post_title}}':
					$value = $post->post_title;
					break;

				case '{{post_url}}':
					$value = get_permalink( $post->ID );
					break;

				case '{{original_post_url}}':
					$value = get_post_meta( $post->ID, 'wprss_item_permalink', TRUE );
					break;

				case '{{post_import_date}}':
					$import_date = WPRSS_FTP_Meta::get_instance()->get_meta( $post->ID, 'import_date' );
					// Get the WordPress date and time format settings
					$time_format = get_option('time_format');
					$date_format = get_option('date_format');
					// Format the value and add HTML time tags
					$value = @date( "$date_format $time_format", $import_date );
					$value = '<time>' . $value . '</time>';
					break;
					
				case '{{post_publish_date}}':
					$value = get_the_date( '', $post->ID ) .' '. get_the_time( '', $post->ID );
					$value = '<time>' . $value . '</time>';
					break;

				case '{{post_author_name}}':
					$user = get_user_by( 'id', $post->post_author );
					if ( $user->first_name === '' && $user->last_name === '' ) {
						$value = $user->user_login;
					}
					$value = $user->first_name . ' ' . $user->last_name;
					break;

				case '{{post_author_url}}':
					$user = get_user_by( 'id', $post->post_author );
					$value = $user->user_url;
					break;

				default:
					$value = '/';
					break;

			}
			// Add the placeholder and its value to the values array
			$values[$placeholder] = $value;
		}
		// Replaces new lines with <br/> tags
		$values["\n"] = '<br/>';


		//== ADVANCED PLACEHOLDERS ====
		// {{meta: xyz}} Outputs meta value for the post's meta field 'xyz'
		// {{source_meta: xyz}} The same, but the meta value is taken from the post's feed source.

		// Use regex to find all the advanced placeholders used
		preg_match_all("/{{(source_)?meta\s*:\s*([^}]*)}}/ix", $append, $adv_meta);
		// The first entry in the results array is an array containing the
		// full string match (the placeholder string)
		$adv_meta_placeholders = $adv_meta[0];
		// The second entry in the results array is an array of the matched
		// optional "source_" prefix (the matching group before "meta")
		$adv_meta_source = $adv_meta[1];
		// The third entry in the results array is an array of the matched
		// meta fields (the matching group after the colon)
		$adv_meta_fields = $adv_meta[2];
		// Iterate each found meta field
		for( $i = 0; $i < count($adv_meta_fields); $i++ ) {
			// Determine if retrieveing the meta of the post or the source
			$target = ( $adv_meta_source[$i] === "source_" )? $source_id : $post->ID;
			// Get the meta value from the target post/source
			$meta = get_post_meta( $target, $adv_meta_fields[$i], TRUE );
			// Prepare the placeholder that matches this meta field
			$placeholder = $adv_meta_placeholders[$i];
			// Add the find/replace values
			$values[ $placeholder ] = $meta;
		}

		// Return the append/prepend text with all placeholders replaced with their respective text value
		$return = WPRSS_FTP_Utils::str_mass_replace( $append, $values );
		$return = apply_filters( 'wprss_ftp_handled_append_text', $return, $post->ID );
		return $wpautop === TRUE? wpautop( $return ) : $return;
	}
コード例 #4
0
	/**
	 * Retrieve a shortened permalink URL for the feed item identified by $post.
	 * If the post is not a feed item, returns an empty string, unless
	 * overridden by the 'wprss_ftp_shortened_item_url' filter.
	 * The shortened URL will be cached for this item. To invalidate cache,
	 * change the item's or the item source's shortening method.
	 * 
	 * Will write to log on error.
	 * 
	 * @since 2.8.6
	 * @param WP_Post|int $post A post object or ID
	 * @param null|mixed $default The value to return if the post URL cannot be shortened.
	 * @return string The shortened URL of the specified item
	 */
	public static function get_shortened_item_url($post, $default = null) {
		$post = get_post($post);
		$meta = WPRSS_FTP_Meta::get_instance();
		
		// If no permalink, or it's empty, just return it
		if( !($long_url = trim($meta->get_meta( $post->ID, 'wprss_item_permalink', false ))) || empty($long_url) ) {
			return apply_filters('wprss_ftp_shortened_item_url', $long_url, $post, false); // The false at the end means the URL was not shortened
		}
		
		// If item is not attached to feed source, return original permalink too
		if ( !($item_source_id = $meta->get_meta( $post->ID, 'feed_source' )) ) {
			return apply_filters('wprss_ftp_shortened_item_url', $long_url, $post, false); // The false at the end means the URL was not shortened
		}
		
		$short_url = trim($meta->get_meta( $post->ID, self::META_KEY_SHORT_URL)); // The shortened URL that may already exist on the item
		$item_shortening_method = trim((string)$meta->get_meta( $post->ID, self::META_KEY_URL_SHORTENING_METHOD)); // The shortener code of the item
		$source_shortening_method = trim((string)$meta->get_meta($item_source_id, self::META_KEY_URL_SHORTENING_METHOD));  // The shortener code of the source
		
		// If item has been shortened using the source's method, return that
		if( $item_shortening_method === $source_shortening_method ) {
			return apply_filters('wprss_ftp_shortened_item_url', $long_url, $post, false); // The false at the end means the URL was not shortened;
		}
		
		// Initiates the actual shortening
		$short_url = self::shorten_url($long_url, $source_shortening_method);
		
		// If URL could not be shortened using services, log and return the error
		if( is_wp_error($short_url) ) {
			/* @var $short_url WP_Error */
			WPRSS_FTP_Utils::log( sprintf('Could not shorten URL "%3$s" of post #%4$s using method "%1$s": %2$s', $source_shortening_method, $short_url->get_error_message(), $long_url, $post->ID), __FUNCTION__);
			return $default;
		}
		
		// Saving new meta data
		$meta->add_meta($post->ID, self::META_KEY_SHORT_URL, $short_url);
		$meta->add_meta($post->ID, self::META_KEY_URL_SHORTENING_METHOD, $source_shortening_method);
		
		return apply_filters('wprss_ftp_shortened_item_url', $short_url, $post, true);
	}
コード例 #5
0
 /**
  * Checks whether a value is considered to be 'true' by this class.
  *
  * @since 4.8.1
  * @param mixed $value The value to check.
  * @return bool True if the value is considered by this class to represent 'true'; false otherwise.
  */
 public static function isTrue($value)
 {
     return \WPRSS_FTP_Utils::multiboolean($value) || trim($value) === static::getTrueValue();
 }
コード例 #6
0
	/**
	 * Changes the tags to be stripped from the feed item.
	 * 
	 * @since 2.2
	 */
	public static function feed_tags_to_strip( $tags, $source ) {
		if ( is_null( $source ) ) return $tags;
		
		$allow_embedded_content = WPRSS_FTP_Meta::get_instance()->get_meta( $source, 'allow_embedded_content' );
		if ( WPRSS_FTP_Utils::multiboolean( $allow_embedded_content ) !== true )
			return $tags;
		
		// Remove the allowed tags from the list of tags to remove
		$tags = array_diff( $tags, self::get_allowed_embed_tags() );
		$tags = array_values( array_filter( $tags ) );
		
		return $tags;
	}
コード例 #7
0
	/**
	 * Returns whether or not a URL is allowed.
	 *
	 * @since 2.8.6
	 * @deprecated 3.0
	 * @param bool $is_allowed Whether or not the request is originally allowed
	 * @param string $host This server's host name
	 * @param string $url URL of the request
	 */
	public static function is_allow_local_requests( $is_allowed, $host, $url ) {
		$allow_local_requests = WPRSS_FTP_Settings::get_instance()->get( 'allow_local_requests' );
		if ( true === $allow_local_requests || WPRSS_FTP_Utils::multiboolean( $allow_local_requests ) ) {
			return true;
		}

		return $isAllowed;
	}
コード例 #8
0
	/**
	 * Disables the link to source option for each feed source
	 * 
	 * @since 2.4
	 */
	public static function source_link_update() {
		// Get the meta class instance
		$meta = WPRSS_FTP_Meta::get_instance();

		if ( ! function_exists( "wprss_get_all_feed_sources" ) ) return;

		// Get all feed sources
		$feed_sources = wprss_get_all_feed_sources();

		// Keep a count of feed sources that got updated
		$count = 0;

		// Iterate all feed sources
		while ( $feed_sources->have_posts() ) {
			// Prepare loop variables
			$feed_sources->the_post();
			$ID = get_the_ID();

			// Get the source link enable and text meta for the feed sources
			$source_link = $meta->get_meta( $ID, 'source_link' );
			$source_link_text = $meta->get_meta( $ID, 'source_link_text' );
			// Get the post append text
			$post_append = $meta->get_meta( $ID, 'post_append' );
			
			// If the post's feed source has source_link enabled ...
			if ( WPRSS_FTP_Utils::multiboolean( $source_link ) === TRUE ) {

				// Disable the source link option
				update_post_meta( $ID, WPRSS_FTP_Meta::META_PREFIX . 'source_link', 'false' );

				// Increment the count
				$count++;
				
				// If an asterisk is found in the source link text, use regex to generate the linked phrase
				if ( stripos( $source_link_text, '*') !== FALSE ) {
					// Prepare the replacement <a> tag with the placeholder for feed_url
					$feed_url_link = "<a target=\"_blank\" href=\"{{feed_url}}\">$1</a>";
					// Replace the string in double asteriks into the <a> tag
					$linked_text = preg_replace(
						'/\*\*(.*?)\*\*/',									// The regex pattern to search for
						$feed_url_link,										// The replacement text
						$source_link_text									// The text to which to search in
					);
					// Prepare the replacement <a> tag with the placeholder for post_url
					$post_url_link = "<a target=\"_blank\" href=\"{{original_post_url}}\">$1</a>";
					// Replace the string in single asteriks into the <a> tag
					$linked_text = preg_replace(
						'/\*(.*?)\*/',										// The regex pattern to search for
						$post_url_link,										// The replacement text
						$linked_text										// The text to which to search in
					);

					
					// Update the post append text
					if ( strlen( $post_append ) > 0 ) {
						$post_append .= '<br/>';
					}
					$post_append .= $linked_text;
					update_post_meta( $ID, WPRSS_FTP_Meta::META_PREFIX . 'post_append', $post_append );

				}


			} // END OF SOURCLE LINK ENABLED CHECK

		} // END OF WHILE LOOP

		if ( $count > 0 ) {
			set_transient( 'wprss_ftp_admin_notices', array( 'WPRSS_FTP_Utils', 'source_link_update_notice' ), 0 );
		}

		// Restore the $post global to the current post in the main query
		wp_reset_postdata();

	} // END OF source_link_update() 
コード例 #9
0
/**
 * Inserts the terms into a given post, based on their saved meta/
 *
 * This function replaces the old taxonomy code in the converter class, utilizing the new meta data
 * format used for the taxonomies. The terms for each taxonomy, along with any auto created feed terms
 * are inserted into the post.
 *
 * @since 3.1
 * @param int $post_id The ID of the post.
 * @param int $feed_id The ID of the feed source that imported the post.
 * @param object $sp_item The SimplePie_Item from which the post was converted.
 * @return bool TRUE if the terms where inserted successfully, FALSE if the post was not found.
 */
function wprss_ftp_add_taxonomies_to_post( $post_id, $feed_id, $sp_item ) {
	// If the post does not exist, stop immediately
	if ( get_post( $post_id ) === null ) return NULL;

	// Get the taxonomies meta
	$meta = WPRSS_FTP_Meta::get_instance()->get( $feed_id, 'taxonomies' );
	// If the source has the old meta saved, convert it into the new meta
	if ( $meta === '' ) {
		$meta = WPRSS_FTP_Meta::convert_post_taxonomy_meta( $feed_id );
	}

	// Get the settings instance
	$settings = WPRSS_FTP_Settings::get_instance();
	// Get the post type saved in the settings
	$settings_post_type = $settings->get( 'post_type' );
	// If it matches, add the settings taxonomies to the meta taxonomies
	if ( $settings_post_type === get_post_type( $post_id ) ) {
		// Get the taxonomies settings, and convert from old format if needed
		$settings_taxonomies = $settings->get( 'taxonomies' );
		if ( $settings_taxonomies === '' ) {
			$settings_taxonomies = WPRSS_FTP_Settings::convert_post_taxonomy_settings();
		}
		// Add to meta taxonomies
		$meta = array_merge( (array) $settings_taxonomies, (array) $meta );
	}

	$tax_iterated = array();

	// For each entry
	foreach( $meta as $entry ) {
		// Check if this taxonomy term should be applied.
		if ( wprss_ftp_should_apply_taxonomy( $entry, $sp_item ) === FALSE ) {
			continue;
		}

		// Get the data
		$taxonomy = $entry['taxonomy'];
		$terms = $entry['terms'];
		$terms = is_array( $terms ) ? $terms : array();
		$auto = WPRSS_FTP_Utils::multiboolean( $entry['auto'] );
		$feed_terms = array();

		// Repeat the taxonomy slug in an array with the same length as the terms array
		$taxonomies_array = count( $terms ) > 0 ? array_fill( 0, count($terms), $taxonomy ) : array();
		// Run the term slugs through the 'wprss_ftp_create_or_get_term'
		$terms_to_set = array_map( 'wprss_ftp_create_or_get_term', $terms, $taxonomies_array);
		// Filter the terms to remove NULL entries (NULL can be returned by 'wprss_ftp_create_or_get_term')
		$terms_to_set = array_filter( $terms_to_set );

		// If auto creation is enabled
		if ( $auto === TRUE ) {
			// If auto create is enabled, get the terms from the feed
			$feed_terms = $sp_item->get_categories();
			$feed_terms = is_array( $feed_terms )? $feed_terms : array();
			// Map the terms through our preparation function, and filter them for custom user manipulation
			$feed_terms = array_map( 'wprss_ftp_prepare_auto_created_term', $feed_terms );
			$feed_terms = apply_filters( 'wprss_auto_create_terms', $feed_terms, $taxonomy, $feed_id );
			// Repeat the taxonomy slug in an array with the same length as the terms array
			$num_terms = count( $feed_terms );
			$taxonomies_array = $num_terms > 0? array_fill( 0, $num_terms, $taxonomy ) : array();
			// Run them through the `wprss_ftp_process_auto_created_terms` function for processing
			$feed_terms = array_map( 'wprss_ftp_process_auto_created_terms', $feed_terms, $taxonomies_array );
			// Filter the terms to remove NULL entries (NULL can be returned by 'wprss_ftp_create_or_get_term')
			$feed_terms = array_filter( $feed_terms );
			// Add them to the terms to set
			$terms_to_set = array_merge( (array) $terms_to_set, (array) $feed_terms );
		}

		// Add the taxonomy to the tax_iterated array if it's not already in the array
		if ( ! in_array( $taxonomy, $tax_iterated ) ) {
			$tax_iterated[] = $taxonomy;
			// Set no terms, and override existing - to remove any default terms, like 'Uncategorized'
			wp_set_object_terms( $post_id, array(), $taxonomy, FALSE );
		}
		// Insert the terms
		wp_set_object_terms( $post_id, $terms_to_set, $taxonomy, TRUE );
		// clear the cache
		delete_option($taxonomy."_children");
	}

	return TRUE;
}
コード例 #10
0
	/**
	 * Fixed incorrect meta value for multisite option for all existing feed sources
	 *
	 * @since 1.8.3
	 */
	public static function multisite_fix() {
		if ( is_multisite() ) {
			global $switched;
			$current_site_id = get_current_blog_id();
			$site_ids = array_keys( WPRSS_FTP_Utils::get_sites() );

			for( $i = 0; $i < count( $site_ids ); $i++ ) {
				$site_id = $site_ids[$i];
   				$switch_success = switch_to_blog( $site_id );
   				if ( $switch_success === FALSE ) continue;

				$feed_sources = wprss_get_all_feed_sources();

				if( $feed_sources->have_posts() ) {
					while ( $feed_sources->have_posts() ) {
						$feed_sources->the_post();

						$post_site = get_post_meta( get_the_ID(), WPRSS_FTP_Meta::META_PREFIX . 'post_site', TRUE );

						if ( $post_site === '' || $post_site === FALSE || strtolower( strval( $post_site ) ) == 'false' ) {
							update_post_meta( get_the_ID(), WPRSS_FTP_Meta::META_PREFIX . 'post_site', get_current_blog_id() );
						}

					}

					// Restore the $post global to the current post in the main query
					wp_reset_postdata();

				} // end of have_posts()

			} // End of site loop
			switch_to_blog( $current_site_id );
		} // End of multisite check
	}
コード例 #11
0
	/**
	 * Prints the enclosure link in the post content.
	 *
	 * @since 2.8
	 */
	public static function enclosure_link( $content ) {
		global $post;

		// Start with the original content
		$new_content = $content;

		// check if enclosure is enabled, check filter for before and after (default: before), check filter to modify print

		// Check if not in the feed and if showing the post, not processing the content
		if ( is_feed() || !( is_singular() || is_home() || is_front_page() || is_search() || is_preview() ) ) {
			return $content;
		}

		// Get the source meta, if it exists, for this post
		$source = WPRSS_FTP_Meta::get_instance()->get_meta( $post->ID, 'feed_source' );
		// If the meta exists ( i.e. is an imported post )
		if ( $source === '' ) {
			return $content;
		}

		// Check if enclosure is enabled
		$enclosure_enabled = get_post_meta( $source, 'wprss_enclosure', TRUE );
		if ( $enclosure_enabled === '' || !WPRSS_FTP_Utils::multiboolean( $enclosure_enabled ) ) {
			return $content;
		}

		// Get the post enclosure link
		$enclosure_link = WPRSS_FTP_Meta::get_instance()->get_meta( $post->ID, 'enclosure_link' );
		// Prepare the default output
		$enclosure_output = "<a href='$enclosure_link'>$enclosure_link</a>";

		// Get the position of the enclosure link. Default: 'before' post content
		$pos = apply_filters( 'wprss_ftp_enclosure_link_position', 'before' );

		// Filter the enclosure output
		$enclosure_output = apply_filters( 'wprss_ftp_enclosure_output', $enclosure_output, $enclosure_link, $source );

		// Show the enclosure link at the appropriate position
		switch( $pos ) {
			default:
			case 'before':
				$new_content = $enclosure_output . $content;
				break;
			case 'after':
				$new_content = $content . $enclosure_output;
				break;
		}
		
		// Return the new content
		return $new_content;
	}
コード例 #12
0
	/**
	 * Checks if the post is to be rejected since no featured image was determined.
	 *
	 * If the 'must_have_ft_image' is enabled for the feed source that imported the post, the
	 * post is deleted. Otherwise no action is taken.
	 *
	 * This function triggers the action 'wprss_ftp_after_post_rejected_no_ft_image' upon
	 * completion.
	 *
	 * @since 3.3
	 * @param $post_id   int The ID of the post.
	 * @param $source_id int The ID of the feed source.
	 */
	public function maybe_reject_post( $post_id, $source_id ) {
		wprss_log( 'Checking if post should be rejected due to lack of a featured image ...', NULL, WPRSS_LOG_LEVEL_SYSTEM );
		// Get the meta option value that determines if posts are allowed if they have no featured image
		$must_have_ft_image = WPRSS_FTP_Meta::get_instance()->get( $source_id, 'must_have_ft_image' );
		// Check if the option is enabled
		$enabled = WPRSS_FTP_Utils::multiboolean( $must_have_ft_image ) === TRUE;
		if ( $enabled ) {
			// Filter force deletion. False for sending post to trash
			$force_delete = apply_filters( 'wprss_ftp_post_rejected_no_ft_image_force_delete', TRUE );
			// Delete the post
			wp_delete_post( $post_id, $force_delete );
			// Return null from the convertor
			add_filter( 'wprss_ftp_converter_return_post_'.$post_id, '__return_false' );
			// Logging
			wprss_log( 'Post rejected.', NULL, WPRSS_LOG_LEVEL_SYSTEM );
		} else {
			// Logging
			wprss_log( 'Post accepted.', NULL, WPRSS_LOG_LEVEL_SYSTEM );
		}
		// Trigger action. First param: TRUE reject, FALSE accepted.
		do_action( 'wprss_ftp_after_post_rejected_no_ft_image', $enabled, $source_id );
	}
コード例 #13
0
	/**
	 * Handles extraction for the given post.
	 * 
	 * @since 2.5
	 */
	public static function extract( $post_id, $source ) {

		// If a source is set ( hence an imported post ), ...
		if ( $source !== '' ) {

			// Get the extraction rules of the source
			$rules = self::get_extraction_rules_and_types( $source );
			wprss_log_obj( 'Got extraction rules', $rules, NULL, WPRSS_LOG_LEVEL_SYSTEM );

			// If the rules are not an array or there are no rules, return
			if ( !is_array( $rules ) && count( $rules ) == 0 ) return;

			// Load the ganon library
			if ( version_compare(phpversion(), '5.3.1', '<') ) {
				// PHP4 Ganon
				require_once( WPRSS_FTP_LIB . 'ganon.php4' );
			}
			else {
				// PHP5+ Ganon
				require_once( WPRSS_FTP_LIB . 'ganon.php' );
			}

			// Get the post
			$post = get_post( $post_id );
			// If the post is a WP error, return
			if ( is_wp_error( $post ) || !is_object( $post ) ) return;
			// Otherwise, get the content
			$content = $post->post_content;

			// Parse the post content
			$html = str_get_dom( $content );

			// For each rule and its type
			foreach ( $rules as $rule => $type ) {

				// Trim the rule string
				$rule = trim( $rule );
				// If the rule is empty, skip it
				if ( strlen( $rule ) === 0 ) {
					continue;
				}

				// Used to replace the current html DOM
				$new_html = '';

				// Each found element ...
				foreach ( $html->select($rule) as $element ) {
					// Check the rule type
					switch( $type ) {
						// If keeping the matched element
						case 'keep' :
							// Add the element as a string to the new_html variable
							$new_html .= $element->toString(TRUE, TRUE, FALSE);
							break;
						// Remove the element
						case 'remove' :
							$element->detach();
							break;
						// Remove the element, and keep its children
						case 'remove_keep_children' :
							$element->detach( TRUE );
							break;
					}
				}

				// If the new_html variable has changed, use it as the new HMTL DOM
				if ( strlen( $new_html ) > 0 ) {
					$html = str_get_dom( $new_html );
				}

			} // End of rules foreach

			// Update the post with its new content
			$new_content = (string)$html;
			WPRSS_FTP_Utils::update_post_content( $post_id, $new_content );
		}

	}
コード例 #14
0
	/**
     * Adds a button in the debugging page, that deletes all posts imported by Feed to Post
     * 
     * @deprecated
     * @since 1.3
     */
	public function show_error_log() {
		?>
		<h3>
			<?php _e( 'Feed To Post Error Log', WPRSS_TEXT_DOMAIN ); ?>
		</h3>

		<textarea readonly="readonly" id="wprss-ftp-error-log-textarea">
			<?php echo WPRSS_FTP_Utils::get_log(); ?>
		</textarea>

		<form action="edit.php?post_type=wprss_feed&page=wprss-debugging" method="POST"> 
			<?php wp_nonce_field( 'wprss-ftp-clear-error-log' );
			submit_button( __( 'Clear log', WPRSS_TEXT_DOMAIN ), 'button-primary', 'ftp-error-log', true  ); ?>
		</form>

		<?php
	}
コード例 #15
0
	/**
	 * Get the specified feed item's date
	 * @since 3.3.2
	 */
	private function preview_date($item) {
		
		$date = $item->get_date( 'U' );
		
		if ( WPRSS_FTP_Utils::multiboolean( $this->params['apply_filters'] ) === TRUE ) {
			$date = apply_filters( 'wprss_ftp_converter_post_date', $date, 0 );
		}

		if (empty($date)) {
			$date = $this->format_error_string( __('The item has no date!', WPRSS_TEXT_DOMAIN) );
		} else {
                        $date_difference = human_time_diff( $date, current_time('timestamp'));
			$date = ( $date > current_time('timestamp') ) ? __( 'In', WPRSS_TEXT_DOMAIN ) . ' ' .$date_difference : $date_difference .' '. __( 'ago', WPRSS_TEXT_DOMAIN );
		}


		return $date;

	}
コード例 #16
0
	/**
	 * Renders the author settings
	 * 
	 * @since 1.9.3
	 */
	public function render_author_options( $post_id = NULL, $meta_row_title = '', $meta_label_for = '' ) {
		// Get the options
		$options = WPRSS_FTP_Settings::get_instance()->get_computed_options( $post_id );
		$def_author = ( $post_id !== NULL ) ? $options['def_author'] : $this->get( 'def_author' );
		$author_fallback_method = ( $post_id !== NULL ) ? $options['author_fallback_method'] : $this->get( 'author_fallback_method' );
		$author_fallback_method = ( strtolower( $author_fallback_method ) === 'use_existing' )? 'existing' : $author_fallback_method;
		$fallback_author = ( $post_id !== NULL ) ? $options['fallback_author'] : $this->get( 'fallback_author' );
		$no_author_found = ( $post_id !== NULL ) ? $options['no_author_found'] : $this->get( 'no_author_found' );
		
		// Set the HTML tag ids
		$ids = array(
			'def_author'				=>	'ftp-def-author',
			'author_fallback_method'	=>	'ftp-author-fallback-method',
			'fallback_author'			=>	'ftp-fallback-author',
			'no_author_found'			=>	'ftp-no-author-skip'
		);
		// If in meta, copy the keys into the values
		if ( $post_id !== NULL ) {
			foreach ( $ids as $field => $id ) {
				$ids[$field] = $field;
			}
		}
		// Set the HTML tag names
		$names = array(
			'def_author'				=>	'def_author',
			'author_fallback_method'	=>	'author_fallback_method',
			'fallback_author'			=>	'fallback_author',
			'no_author_found'			=>	'no_author_found',
		);
		// Set the names appropriately according to the page, meta or settings
		foreach( $names as $field => $name) {
			$names[$field] = ( $post_id !== NULL )? WPRSS_FTP_Meta::META_PREFIX . $name : self::OPTIONS_NAME . "[$name]";
		}

		// If in meta, print the table row
		if ( $post_id !== NULL ) : ?>
			<tr>
				<th>
					<label for="<?php echo $meta_label_for; ?>">
						<?php echo $meta_row_title; ?>
					</label>
				</th>
				<td>
		<?php endif; ?>

		<!-- Author to use -->
		<span id="wprss-ftp-authors-options">
			<label for="<?php echo $ids['def_author']; ?>">Use </label>
			<?php $users = WPRSS_FTP_Meta::get_users_array( WPRSS_FTP_Admin_User_Ajax::get_instance()->is_over_threshold() ? (array)$def_author : false ) ?>
			<?php echo WPRSS_FTP_Utils::array_to_select( $users, array(
					'id'		=>	$ids['def_author'],
					'name'		=>	$names['def_author'],
					'selected'	=>	$def_author,
			));
			?>
			<script type="text/javascript">
				top.wprss.f2p.userAjax.addElement('#<?php echo $ids['def_author'] ?>');
			</script>
			<?php
			echo WPRSS_Help::get_instance()->do_tooltip( WPRSS_FTP_HELP_PREFIX.'post_author' ); ?>
		</span>
		
		<!-- Separator -->
		<?php if ( $post_id !== NULL ) : ?>
			</td></tr>
			<tr class="wprss-tr-hr wprss-ftp-authors-hide-if-using-existing">
				<th>
				</th>
				<td>
		<?php endif; ?>
		
		<!-- Section that hides when using an existing user -->
		<span class="wprss-ftp-authors-hide-if-using-existing">
			
			<!-- Radio group if author has no user -->
			<span class="ftp-author-using-in-feed">
				<label for="<?php echo $ids['author_fallback_method']; ?>">
					<?php _e( 'If the author in the feed is not an existing user', WPRSS_TEXT_DOMAIN ); ?>:
				</label>
				<br/>
				<?php
					echo implode( '', WPRSS_FTP_Utils::array_to_radio_buttons(
						array(
							'existing'	=> __( 'Use the fallback user', WPRSS_TEXT_DOMAIN ),
							'create'	=> __( 'Create a user for the author', WPRSS_TEXT_DOMAIN )
						),
						array(
							'id'		=>	$ids['author_fallback_method'],
							'name'		=>	$names['author_fallback_method'],
							'checked'	=>	$author_fallback_method,
						)
					));
				?>
			</span>
			
			<!-- Radio group if author not found in feed -->
			<span class="ftp-author-using-in-feed">
				<label for="<?php echo $ids['no_author_found']; ?>">
					<?php _e( 'If the author is missing from the feed', WPRSS_TEXT_DOMAIN ); ?>
				</label>
				<br/>
				<?php
					echo implode( WPRSS_FTP_Utils::array_to_radio_buttons(
						array(
							'fallback'	=>	__( 'Use the fallback user', WPRSS_TEXT_DOMAIN ),
							'skip'		=>	__( 'Do not import the post', WPRSS_TEXT_DOMAIN )
						),
						array(
							'id'		=>	$ids['no_author_found'],
							'name'		=>	$names['no_author_found'],
							'checked'	=>	$no_author_found,
						)
					));
				?>
			</span>
		</span>
		
		
		<?php if ( $post_id !== NULL ) : ?>
			</td></tr>
			<tr class="wprss-tr-hr wprss-ftp-authors-hide-if-using-existing">
				<th>
					<label for="<?php echo $ids['fallback_author']; ?>">
						<?php _e( 'Fallback User', WPRSS_TEXT_DOMAIN ); ?>
					</label>
				</th>
				<td>
		<?php endif; ?>
		
		<!-- Section that hides when using an existing user -->
		<span class="wprss-ftp-authors-hide-if-using-existing">
			<?php if ( $post_id === NULL ) : ?>
			<label for="<?php echo $ids['fallback_author']; ?>">
				<?php _e( 'Fallback user:'******'id'		=>	$ids['fallback_author'],
					'name'		=>	$names['fallback_author'],
					'selected'	=>	$fallback_author,
				));
			?>
			<script type="text/javascript">
				top.wprss.f2p.userAjax.addElement('#<?php echo $ids['fallback_author'] ?>', {<?php echo WPRSS_FTP_Admin_User_Ajax::REQUEST_VAR_EXISTING_USERS_ONLY ?>: true, <?php echo WPRSS_FTP_Admin_User_Ajax::REQUEST_VAR_LOGIN_NAMES ?>: true});
			</script>
			<?php echo WPRSS_Help::get_instance()->do_tooltip( WPRSS_FTP_HELP_PREFIX.'fallback_author' ); ?>
		</span>
					
		<?php // Add scripts ?>

		<script type="text/javascript">
			(function($){
				$(document).ready( function(){

					// Set a pointer to the dropdowns
					var dropdown1 = $('#<?php echo $ids['def_author']; ?>');

					// Create the function that shows/hides the second section
					var authorsSection2UI = function(){
						// Show second section only if the option to use the author in the feed is chosen
						$('.wprss-ftp-authors-hide-if-using-existing').toggle( dropdown1.val() === '.' );
					}

					// Set the on change handlers
					dropdown1.change( authorsSection2UI );

					// Run the function at least once
					authorsSection2UI();

				});
			})(jQuery);
		</script>
		<?php // End of scripts

		// If in meta, close the table row
		if ( $post_id !== NULL ) {
			?></td></tr><?php
		}
	}