/**
 * Plugin deactivation procedure
 *
 * @since 1.0
 */
function wprss_deactivate()
{
    // On deactivation remove the cron job
    wp_clear_scheduled_hook('wprss_fetch_all_feeds_hook');
    wp_clear_scheduled_hook('wprss_truncate_posts_hook');
    // Uschedule cron jobs for all feed sources
    $feed_sources = wprss_get_all_feed_sources();
    if ($feed_sources->have_posts()) {
        // For each feed source
        while ($feed_sources->have_posts()) {
            // Stop its cron job
            $feed_sources->the_post();
            wprss_feed_source_update_stop_schedule(get_the_ID());
        }
        wp_reset_postdata();
    }
    // Flush the rewrite rules
    flush_rewrite_rules();
}
Exemple #2
0
/**
 * Fetches all feed items from all feed sources.
 * Iteratively calls 'wprss_fetch_insert_single_feed_items' for all feed sources.
 *
 * This function is used by the cron job or the debugging functions to get all feeds from all feed sources
 *
 * @param $all  If set to TRUE, the function will pull from all feed sources, regardless of their individual
 *              update interval. If set to FALSE, only feed sources using the global update system will be updated.
 *              (Optional) Default: TRUE.
 * @since 3.0
 */
function wprss_fetch_insert_all_feed_items($all = TRUE)
{
    // Get all feed sources
    $feed_sources = wprss_get_all_feed_sources();
    if ($feed_sources->have_posts()) {
        // Start by getting one feed source, we will cycle through them one by one,
        // fetching feed items and adding them to the database in each pass
        while ($feed_sources->have_posts()) {
            $feed_sources->the_post();
            $interval = get_post_meta(get_the_ID(), 'wprss_update_interval', TRUE);
            $using_global_interval = $interval === wprss_get_default_feed_source_update_interval() || $interval === '';
            // Check if fetching from all, or if feed source uses the global interval
            if ($all === TRUE || $using_global_interval) {
                wp_schedule_single_event(time(), 'wprss_fetch_single_feed_hook', array(get_the_ID()));
            }
        }
        wp_reset_postdata();
        // Restore the $post global to the current post in the main query
    }
}
/**
 * Delete old feed items from the database to avoid bloat.
 * As of 3.8, it uses the new feed age system.
 *
 * @since 3.8
 */
function wprss_truncate_posts()
{
    // Get general settings
    $general_settings = get_option('wprss_settings_general');
    // Get all feed sources
    $feed_sources = wprss_get_all_feed_sources();
    // Check if there are feed sources
    if ($feed_sources->have_posts()) {
        // FOR EACH FEED SOURCE
        while ($feed_sources->have_posts()) {
            $feed_sources->the_post();
            // Get the max age setting for this feed source
            $max_age = wprss_get_max_age_for_feed_source(get_the_ID());
            // If the data is empty, do not delete
            if ($max_age === FALSE) {
                continue;
            }
            // Get all feed items for this source
            $feed_items = wprss_get_feed_items_for_source(get_the_ID());
            // If there are feed items
            if ($feed_items->have_posts()) {
                // Extend the timeout time limit for the deletion of the feed items
                $time_limit = wprss_get_item_import_time_limit();
                wprss_log("Extended execution time limit by {$time_limit}s for imported items truncation.", null, WPRSS_LOG_LEVEL_INFO);
                set_time_limit($time_limit);
                // For each feed item
                while ($feed_items->have_posts()) {
                    $feed_items->the_post();
                    // If the post is older than the maximum age
                    if (wprss_is_feed_item_older_than(get_the_ID(), $max_age) === TRUE) {
                        // Delete the post
                        wp_delete_post(get_the_ID(), true);
                    }
                }
                // Reset feed items query data
                wp_reset_postdata();
            }
        }
        // Reset feed sources query data
        wp_reset_postdata();
    }
    // If the filter to use the fixed limit is enabled, call the old truncation function
    if (apply_filters('wprss_use_fixed_feed_limit', FALSE) === TRUE && isset($general_settings['limit_feed_items_db'])) {
        wprss_old_truncate_posts();
    }
}
Exemple #4
0
/**
 * Delete old feed items from the database to avoid bloat.
 * As of 3.8, it uses the new feed age system.
 *
 * @since 3.8
 */
function wprss_truncate_posts()
{
    $general_settings = get_option('wprss_settings_general');
    // Get all feed sources
    $feed_sources = wprss_get_all_feed_sources();
    if ($feed_sources->have_posts()) {
        // FOR EACH FEED SOURCE
        while ($feed_sources->have_posts()) {
            $feed_sources->the_post();
            // Get the max age setting for this feed source
            $max_age = wprss_get_max_age_for_feed_source(get_the_ID());
            // If the data is empty, do not delete
            if ($max_age !== FALSE) {
                // Get all feed items for this source
                $feed_items = wprss_get_feed_items_for_source(get_the_ID());
                // FOR EACH FEED ITEM
                if ($feed_items->have_posts()) {
                    while ($feed_items->have_posts()) {
                        $feed_items->the_post();
                        // If the post is older than the maximum age
                        if (wprss_is_feed_item_older_than(get_the_ID(), $max_age) === TRUE) {
                            // Delete the post
                            wp_delete_post(get_the_ID(), true);
                        }
                    }
                    // Reset feed items query data
                    wp_reset_postdata();
                }
            }
        }
        // Reset feed sources query data
        wp_reset_postdata();
    }
    // If the filter to use the fixed limit is enabled, call the old truncation function
    if (apply_filters('wprss_use_fixed_feed_limit', FALSE) === TRUE && isset($general_settings['limit_feed_items_db'])) {
        wprss_old_truncate_posts();
    }
}
	/**
	 * 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() 
	/**
	 * 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
	}