/** * Gets the singleton instance of the Manager class, creating it if it doesn't exist. * * @since 4.7.8 * @return Aventura\Wprss\Core\Licensing\Manager */ function wprss_licensing_get_manager() { static $manager = null; if (is_null($manager)) { $manager = new Aventura\Wprss\Core\Licensing\Manager(); $manager->setExpirationNoticePeriod(wprss_get_general_setting('expiration_notice_period')); $manager->setDefaultAuthorName('Jean Galea'); } return $manager; }
/** * Gets an internationalized and localized datetime string, defaulting * to WP RSS format. * * @see wprss_local_date_i18n; * @param string|null $format Format to use. Default: Wordpress date and time format. * @param int|null $timestamp The timestamp to localize. Default: time(). * @return string The formatted datetime, localized and offset for local timezone. */ function wprss_date_i18n($timestamp = null, $format = null) { $format = is_null($format) ? wprss_get_general_setting('date_format') : $format; return wprss_local_date_i18n($timestamp, $format); }
function wprss_send_tracking_data() { // Check the tracking option - if turned off, exit out of function $tracking_option = wprss_get_general_setting('tracking'); if ($tracking_option == 0 || $tracking_option == FALSE) { return; } // Get the tracking transient. $transient = get_transient('wprss_tracking_transient'); // If the transient did not expire, exit out of function if ($transient !== FALSE && !isset($_GET['wprss_send_report'])) { return; } // If the GET parameter is set, show an admin notice if (isset($_GET['wprss_send_report'])) { add_action('admin_notices', 'wprss_tracking_notice'); } // Check if running on localhost $site_url = site_url(); $running_on_local = preg_match_all("/(localhost|127\\.0\\.0\\.1)/", $site_url, $matches) > 0; if ($running_on_local) { return; } // Get data about the plugin $plugin_data = get_plugin_data(WPRSS_FILE_CONSTANT); // Get the theme name if (function_exists('wp_get_theme')) { $theme_data = wp_get_theme(); $theme_name = $theme_data->Name; } else { $theme_data = get_theme_data(get_stylesheet_directory() . '/style.css'); $theme_name = $theme_data['Name']; } // Get plugins $plugins = get_plugins(); $active_plugins_option = get_option('active_plugins', array()); // Prepare plugin arrays $active_plugins = array(); $inactive_plugins = array(); // Loop through plugins foreach ($plugins as $plugins_path => $plugin_info) { // If plugin found in active plugins list, then add to the active_plugins array if (in_array($plugins_path, $active_plugins_option)) { $add_to =& $active_plugins; } else { $add_to =& $inactive_plugins; } // Add the plugin info to the chosen array $add_to[] = $plugin_info['Name'] . ' v' . $plugin_info['Version']; } // If multisite if (is_multisite()) { // Get network plugins $network_plugins = wp_get_active_network_plugins(); $network_active_plugins_option = get_site_option('active_sitewide_plugins', array()); // Prepare plugin array $network_active_plugins = array(); // Loop through plugins foreach ($network_plugins as $plugin_path) { // Get plugin basename $plugin_base = plugin_basename($plugin_path); // If the plugin basename is found in the active network plugin list if (array_key_exists($plugin_base, $network_active_plugins_option)) { // Get the plugin info and add it to the plugin list $plugin_info = get_plugin_data($plugin_path); $network_active_plugins[] = $plugin_info['Name'] . ' v' . $plugin_info['Version']; } } } else { // Otherwise, indicate that the site is not a multisite installation $network_active_plugins = 'Not multisite'; } // Detect add-ons $addons = array(); if (defined('WPRSS_C_VERSION')) { $addons[] = 'Categories'; } if (defined('WPRSS_ET_VERSION')) { $addons[] = 'Excerpts & Thumbnails'; } if (defined('WPRSS_KF_VERSION')) { $addons[] = 'Keyword Filtering'; } if (defined('WPRSS_FTP_VERSION')) { $addons[] = 'Feed to Post'; } // Compile the data $data = array('Site URL' => base64_encode($site_url), 'Plugin Version' => $plugin_data['Version'], 'Active Add-ons' => $addons, 'Theme Name' => $theme_name, 'Site Name' => str_replace(' ', '', get_bloginfo('name')), 'Plugin Count' => count(get_option('active_plugins')), 'Active Plugins' => $active_plugins, 'Network Active Plugins' => $network_active_plugins, 'Inactive Plugins' => $inactive_plugins, 'WordPress Version' => get_bloginfo('version')); // Send the data wp_remote_post(WPRSS_TRACKING_SERVER_URL, array('method' => 'POST', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => array('wprss_tracking_data' => $data), 'cookies' => array())); // Set a transient that expires in 1 week. When it expires, this function will run again // Expiration: 60secs * 60mins * 24hrs * 7days = 1 week set_transient('wprss_tracking_transient', '-', 60 * 60 * 24 * 7); }
/** * Renders the setting field for the certificate path. * * @since 4.7 * @see wprss_admin_init * @param array $field Data of this field. */ public function render_certificate_path_setting($field) { $feed_limit = wprss_get_general_setting($field['field_id']); ?> <input id="<?php echo $field['field_id']; ?> " name="wprss_settings_general[<?php echo $field['field_id']; ?> ]" type="text" value="<?php echo $feed_limit; ?> " /> <?php echo wprss_settings_inline_help($field['field_id'], $field['tooltip']); }
/** * Renders the Feed Processing metabox * * @since 3.7 */ function wprss_feed_processing_meta_box_callback() { global $post; // Get the post meta $state = get_post_meta($post->ID, 'wprss_state', TRUE); $activate = get_post_meta($post->ID, 'wprss_activate_feed', TRUE); $pause = get_post_meta($post->ID, 'wprss_pause_feed', TRUE); $update_interval = get_post_meta($post->ID, 'wprss_update_interval', TRUE); $age_limit = get_post_meta($post->ID, 'wprss_age_limit', FALSE); $age_unit = get_post_meta($post->ID, 'wprss_age_unit', FALSE); $age_limit = count($age_limit) === 0 ? wprss_get_general_setting('limit_feed_items_age') : $age_limit[0]; $age_unit = count($age_unit) === 0 ? wprss_get_general_setting('limit_feed_items_age_unit') : $age_unit[0]; // Set default strings for activate and pause times $default_activate = 'immediately'; $default_pause = 'never'; // Prepare the states $states = array('active' => __('Active', 'wprss'), 'paused' => __('Paused', 'wprss')); // Prepare the schedules $default_interval = __('Default', 'wprss'); $wprss_schedules = apply_filters('wprss_schedules', wprss_get_schedules()); $default_interval_key = wprss_get_default_feed_source_update_interval(); $schedules = array_merge(array($default_interval_key => array('display' => $default_interval, 'interval' => $default_interval)), $wprss_schedules); ?> <div class="wprss-meta-side-setting"> <label for="wprss_state">Feed state:</label> <select id="wprss_state" name="wprss_state"> <?php foreach ($states as $value => $label) { ?> <option value="<?php echo $value; ?> " <?php selected($state, $value); ?> ><?php echo $label; ?> </option> <?php } ?> </select> </div> <div class="wprss-meta-side-setting"> <p> <label for="">Activate feed: </label> <strong id="wprss-activate-feed-viewer"><?php echo $activate !== '' ? $activate : $default_activate; ?> </strong> <a href="#">Edit</a> </p> <div class="wprss-meta-slider" data-collapse-viewer="wprss-activate-feed-viewer" data-default-value="<?php echo $default_activate; ?> "> <input id="wprss_activate_feed" class="wprss-datetimepicker-from-today" name="wprss_activate_feed" value="<?php echo $activate; ?> " /> <label class="description" for="wprss_activate_feed"> Leave blank to activate the feed immediately. </label> <br/><br/> <span class="description"> <b>Note:</b> WordPress uses UTC time for schedules, not local time. Current UTC time is: <code><?php echo date('d/m/Y H:i:s', current_time('timestamp', 1)); ?> </code> </span> </div> </div> <div class="wprss-meta-side-setting"> <p> <label for="">Pause feed: </label> <strong id="wprss-pause-feed-viewer"><?php echo $pause !== '' ? $pause : $default_pause; ?> </strong> <a href="#">Edit</a> </p> <div class="wprss-meta-slider" data-collapse-viewer="wprss-pause-feed-viewer" data-default-value="<?php echo $default_pause; ?> "> <input id="wprss_pause_feed" class="wprss-datetimepicker-from-today" name="wprss_pause_feed" value="<?php echo $pause; ?> " /> <label class="description" for="wprss_pause_feed"> Leave blank to never pause the feed. </label> <br/><br/> <span class="description"> <b>Note:</b> WordPress uses UTC time for schedules, not local time. Current UTC time is: <code><?php echo date('d/m/Y H:i:s', current_time('timestamp', 1)); ?> </code> </span> </div> </div> <div class="wprss-meta-side-setting"> <p> <label for="">Update interval: </label> <strong id="wprss-feed-update-interval-viewer"> <?php if ($update_interval === '' || $update_interval === wprss_get_default_feed_source_update_interval()) { echo $default_interval; } else { echo wprss_interval($schedules[$update_interval]['interval']); } ?> </strong> <a href="#">Edit</a> </p> <div class="wprss-meta-slider" data-collapse-viewer="wprss-feed-update-interval-viewer" data-default-value="<?php echo $default_interval; ?> "> <select id="feed-update-interval" name="wprss_update_interval"> <?php foreach ($schedules as $value => $schedule) { ?> <?php $text = $value === wprss_get_default_feed_source_update_interval() ? $default_interval : wprss_interval($schedule['interval']); ?> <option value="<?php echo $value; ?> " <?php selected($update_interval, $value); ?> ><?php echo $text; ?> </option> <?php } ?> </select> <br/> <span class='description' for='feed-update-interval'> Enter the interval at which to update this feed. The feed will only be updated if it is <strong>active</strong>. </span> </div> </div> <div class="wprss-meta-side-setting"> <p> <label id="wprss-age-limit-feed-label" for="" data-when-empty="Delete old feed items:">Delete feed items older than: </label> <strong id="wprss-age-limit-feed-viewer"><?php echo $age_limit . ' ' . $age_unit; ?> </strong> <a href="#">Edit</a> </p> <div class="wprss-meta-slider" data-collapse-viewer="wprss-age-limit-feed-viewer" data-label="#wprss-age-limit-feed-label" data-default-value="" data-empty-controller="#limit-feed-items-age" data-hybrid="#limit-feed-items-age, #limit-feed-items-age-unit"> <input id="limit-feed-items-age" name="wprss_age_limit" type="number" min="0" class="wprss-number-roller" placeholder="No limit" value="<?php echo $age_limit; ?> " /> <select id="limit-feed-items-age-unit" name="wprss_age_unit"> <?php foreach (wprss_age_limit_units() as $unit) { ?> <option value="<?php echo $unit; ?> " <?php selected($age_unit, $unit); ?> ><?php echo $unit; ?> </option> <?php } ?> </select> <br/> <span class='description' for='limit-feed-items-age'> Enter the maximum age of feed items to be stored in the database. Feed items older than the specified age will be deleted everyday at midnight. <br/> Leave empty for no limit. </span> </div> </div> <?php }
/** * Generate the feed * * @since 3.3 */ function wprss_addfeed_do_feed($in) { // Prepare the post query /* $wprss_custom_feed_query = apply_filters( 'wprss_custom_feed_query', array( 'post_type' => 'wprss_feed_item', 'post_status' => 'publish', 'cache_results' => false, // disable caching ) );*/ $wprss_custom_feed_query = wprss_get_feed_items_query(apply_filters('wprss_custom_feed_query', array('get-args' => TRUE, 'no-paged' => TRUE, 'feed_limit' => 0))); // Suppress caching $wprss_custom_feed_query['cache_results'] = FALSE; // Get options $options = get_option('wprss_settings_general'); if ($options !== FALSE) { // If options exist, get the limit $limit = $options['custom_feed_limit']; if ($limit !== FALSE) { // if limit exists, set the query limit $wprss_custom_feed_query['posts_per_page'] = $limit; } } // Submit the query to get latest feed items query_posts($wprss_custom_feed_query); $custom_feed_title = wprss_get_general_setting('custom_feed_title'); $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'; header("{$protocol} 200 OK"); // Send content header and start ATOM output header('Content-Type: application/rss+xml'); // Disabling caching header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1. header('Pragma: no-cache'); // HTTP 1.0. header('Expires: 0'); // Proxies. echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '"?>'; ?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" > <channel> <title><?php echo $custom_feed_title; ?> </title> <description></description> <link><?php echo get_site_url(); ?> </link> <atom:link href="<?php echo $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; ?> " rel="self" type="application/rss+xml" /> <?php // Start the Loop while (have_posts()) { the_post(); $source = get_post_meta(get_the_ID(), 'wprss_feed_id', TRUE); $permalink = get_post_meta(get_the_ID(), 'wprss_item_permalink', true); ?> <item> <title><![CDATA[<?php the_title_rss(); ?> ]]></title> <link><?php echo $permalink; ?> </link> <guid isPermaLink="true"><?php echo $permalink; ?> </guid> <pubDate><?php echo get_post_time(DATE_RSS); ?> </pubDate> <description><![CDATA[<?php the_content(); ?> ]]></description> <content:encoded><![CDATA[<?php the_content(); ?> ]]></content:encoded> <source url="<?php echo get_post_meta($source, 'wprss_url', TRUE); ?> "><?php echo get_the_title($source); ?> </source> <?php do_action('wprss_custom_feed_entry', get_the_ID()); ?> </item> <?php } // END OF LOOP ?> </channel> </rss> <?php }
/** * The main feed fetching function. * Fetches the feed items from the source provided and inserts them into the DB. * * Called on hook 'wprss_fetch_single_feed_hook'. * * @since 3.2 */ function wprss_fetch_insert_single_feed_items($feed_ID) { // Check if the feed source is active. if (wprss_is_feed_source_active($feed_ID) === FALSE && wprss_feed_source_force_next_fetch($feed_ID) === FALSE) { // If it is not active ( paused ), return without fetching the feed items. return; } // If the feed source is forced for next fetch, remove the force next fetch data if (wprss_feed_source_force_next_fetch($feed_ID)) { delete_post_meta($feed_ID, 'wprss_force_next_fetch'); } update_post_meta($feed_ID, 'wprss_feed_is_updating', time()); // Get the feed source URL from post meta, and filter it $feed_url = get_post_meta($feed_ID, 'wprss_url', true); $feed_url = apply_filters('wprss_feed_source_url', $feed_url, $feed_ID); // Get the feed limit from post meta $feed_limit = get_post_meta($feed_ID, 'wprss_limit', true); // If the feed has no individual limit if ($feed_limit === '' || intval($feed_limit) <= 0) { // Get the global limit $global_limit = wprss_get_general_setting('limit_feed_items_imported'); // If no global limit is set, mark as NULL if ($global_limit === '' || intval($global_limit) <= 0) { $feed_limit = NULL; } else { $feed_limit = $global_limit; } } // Filter the URL for validaty if (filter_var($feed_url, FILTER_VALIDATE_URL)) { // Get the feed items from the source $items = wprss_get_feed_items($feed_url, $feed_ID); // If got NULL, convert to an empty array if ($items === NULL) { $items = array(); } // If using a limit ... if ($feed_limit === NULL) { $items_to_insert = $items; } else { $items_to_insert = array_slice($items, 0, $feed_limit); } // Gather the permalinks of existing feed item's related to this feed source $existing_permalinks = get_existing_permalinks($feed_ID); // Generate a list of items fetched, that are not already in the DB $new_items = array(); foreach ($items_to_insert as $item) { $permalink = wprss_normalize_permalink($item->get_permalink()); // Check if not blacklisted and not already imported if (wprss_is_blacklisted($permalink) === FALSE && !in_array(trim($permalink), $existing_permalinks)) { $new_items[] = $item; } } $items_to_insert = $new_items; // If using a limit - delete any excess items to make room for the new items if ($feed_limit !== NULL) { // Get the number of feed items in DB, and their count $db_feed_items = wprss_get_feed_items_for_source($feed_ID); $num_db_feed_items = $db_feed_items->post_count; // Get the number of feed items we can store until we reach the limit $num_can_insert = $feed_limit - $num_db_feed_items; // Calculate how many feed items we must delete before importing, to keep to the limit $num_feed_items_to_delete = count($new_items) - $num_can_insert; // Get an array with the DB feed items in reverse order (oldest first) $db_feed_items_reversed = array_reverse($db_feed_items->posts); // Cut the array to get only the first few that are to be deleted ( equal to $num_feed_items_to_delete ) $feed_items_to_delete = array_slice($db_feed_items_reversed, 0, $num_feed_items_to_delete); // Iterate the feed items and delete them foreach ($feed_items_to_delete as $key => $post) { wp_delete_post($post->ID, TRUE); } } update_post_meta($feed_ID, 'wprss_last_update', time()); // Insert the items into the db if (!empty($items_to_insert)) { wprss_items_insert_post($items_to_insert, $feed_ID); } } else { wprss_log("The feed URL is not valid! Please recheck."); } $next_scheduled = get_post_meta($feed_ID, 'wprss_reschedule_event', TRUE); if ($next_scheduled !== '') { wprss_feed_source_update_start_schedule($feed_ID); delete_post_meta($feed_ID, 'wprss_reschedule_event'); } delete_post_meta($feed_ID, 'wprss_feed_is_updating'); }
/** * Renders the Feed Processing metabox * * @since 3.7 */ function wprss_feed_processing_meta_box_callback() { global $post; // Get the post meta $state = get_post_meta($post->ID, 'wprss_state', TRUE); $activate = get_post_meta($post->ID, 'wprss_activate_feed', TRUE); $pause = get_post_meta($post->ID, 'wprss_pause_feed', TRUE); $update_interval = get_post_meta($post->ID, 'wprss_update_interval', TRUE); $age_limit = get_post_meta($post->ID, 'wprss_age_limit', FALSE); $age_unit = get_post_meta($post->ID, 'wprss_age_unit', FALSE); $age_limit = count($age_limit) === 0 ? wprss_get_general_setting('limit_feed_items_age') : $age_limit[0]; $age_unit = count($age_unit) === 0 ? wprss_get_general_setting('limit_feed_items_age_unit') : $age_unit[0]; // Set default strings for activate and pause times $default_activate = 'immediately'; $default_pause = 'never'; // Prepare the states $states = array('active' => __('Active', WPRSS_TEXT_DOMAIN), 'paused' => __('Paused', WPRSS_TEXT_DOMAIN)); // Prepare the schedules $default_interval = __('Default', WPRSS_TEXT_DOMAIN); $wprss_schedules = apply_filters('wprss_schedules', wprss_get_schedules()); $default_interval_key = wprss_get_default_feed_source_update_interval(); $schedules = array_merge(array($default_interval_key => array('display' => $default_interval, 'interval' => $default_interval)), $wprss_schedules); // Inline help $help = WPRSS_Help::get_instance(); $help_options = array('tooltip_handle_class_extra' => $help->get_options('tooltip_handle_class_extra') . ' ' . $help->get_options('tooltip_handle_class') . '-side'); ?> <div class="wprss-meta-side-setting"> <label for="wprss_state">Feed state:</label> <select id="wprss_state" name="wprss_state"> <?php foreach ($states as $value => $label) { ?> <option value="<?php echo $value; ?> " <?php selected($state, $value); ?> ><?php echo $label; ?> </option> <?php } ?> </select> <?php echo $help->tooltip('field_wprss_state', null, $help_options); ?> </div> <div class="wprss-meta-side-setting"> <p> <label for="">Activate feed: </label> <strong id="wprss-activate-feed-viewer"><?php echo $activate !== '' ? $activate : $default_activate; ?> </strong> <a href="#">Edit</a> <?php echo $help->tooltip('field_wprss_activate_feed', null, $help_options); ?> </p> <div class="wprss-meta-slider" data-collapse-viewer="wprss-activate-feed-viewer" data-default-value="<?php echo $default_activate; ?> "> <input id="wprss_activate_feed" class="wprss-datetimepicker-from-today" name="wprss_activate_feed" value="<?php echo $activate; ?> " /> <span class="description"> Current UTC time is:<br/><code><?php echo date('d/m/Y H:i:s', current_time('timestamp', 1)); ?> </code> </span> </div> </div> <div class="wprss-meta-side-setting"> <p> <label for="">Pause feed: </label> <strong id="wprss-pause-feed-viewer"><?php echo $pause !== '' ? $pause : $default_pause; ?> </strong> <a href="#">Edit</a> <?php echo $help->tooltip('field_wprss_pause_feed', null, $help_options); ?> </p> <div class="wprss-meta-slider" data-collapse-viewer="wprss-pause-feed-viewer" data-default-value="<?php echo $default_pause; ?> "> <input id="wprss_pause_feed" class="wprss-datetimepicker-from-today" name="wprss_pause_feed" value="<?php echo $pause; ?> " /> <span class="description"> Current UTC time is:<br/><code><?php echo date('d/m/Y H:i:s', current_time('timestamp', 1)); ?> </code> </span> </div> </div> <div class="wprss-meta-side-setting"> <p> <label for="">Update interval: </label> <strong id="wprss-feed-update-interval-viewer"> <?php if ($update_interval === '' || $update_interval === wprss_get_default_feed_source_update_interval()) { echo $default_interval; } else { echo wprss_interval($schedules[$update_interval]['interval']); } ?> </strong> <a href="#">Edit</a> <?php echo $help->tooltip('field_wprss_update_interval', null, $help_options); ?> </p> <div class="wprss-meta-slider" data-collapse-viewer="wprss-feed-update-interval-viewer" data-default-value="<?php echo $default_interval; ?> "> <select id="feed-update-interval" name="wprss_update_interval"> <?php foreach ($schedules as $value => $schedule) { ?> <?php $text = $value === wprss_get_default_feed_source_update_interval() ? $default_interval : wprss_interval($schedule['interval']); ?> <option value="<?php echo $value; ?> " <?php selected($update_interval, $value); ?> ><?php echo $text; ?> </option> <?php } ?> </select> </div> </div> <div class="wprss-meta-side-setting"> <p> <label id="wprss-age-limit-feed-label" for="" data-when-empty="Delete old feed items:">Delete feed items older than: </label> <strong id="wprss-age-limit-feed-viewer"><?php echo $age_limit . ' ' . $age_unit; ?> </strong> <a href="#">Edit</a> <?php echo $help->tooltip('field_wprss_age_limit', null, $help_options); ?> </p> <div class="wprss-meta-slider" data-collapse-viewer="wprss-age-limit-feed-viewer" data-label="#wprss-age-limit-feed-label" data-default-value="" data-empty-controller="#limit-feed-items-age" data-hybrid="#limit-feed-items-age, #limit-feed-items-age-unit"> <input id="limit-feed-items-age" name="wprss_age_limit" type="number" min="0" class="wprss-number-roller" placeholder="No limit" value="<?php echo $age_limit; ?> " /> <select id="limit-feed-items-age-unit" name="wprss_age_unit"> <?php foreach (wprss_age_limit_units() as $unit) { ?> <option value="<?php echo $unit; ?> " <?php selected($age_unit, $unit); ?> ><?php echo $unit; ?> </option> <?php } ?> </select> </div> </div> <?php }
/** * Returns the maximum age setting for a feed source. * * @since 3.8 */ function wprss_get_max_age_for_feed_source($source_id) { $general_settings = get_option('wprss_settings_general'); // Get the meta data for age for this feed source $age_limit = trim(get_post_meta($source_id, 'wprss_age_limit', TRUE)); $age_unit = get_post_meta($source_id, 'wprss_age_unit', TRUE); // If the meta does not exist, use the global settings if ($age_limit === '') { $age_limit = trim(wprss_get_general_setting('limit_feed_items_age')); $age_unit = wprss_get_general_setting('limit_feed_items_age_unit'); } // If the age limit is an empty string, use no limit if ($age_limit === '') { return FALSE; } // Return the timestamp of the max age date return strtotime("-{$age_limit} {$age_unit}"); }
/** * The main feed fetching function. * Fetches the feed items from the source provided and inserts them into the DB. * * Called on hook 'wprss_fetch_single_feed_hook'. * * @since 3.2 */ function wprss_fetch_insert_single_feed_items($feed_ID) { wprss_log_obj('Starting import of feed', $feed_ID, null, WPRSS_LOG_LEVEL_INFO); global $wprss_importing_feed; $wprss_importing_feed = $feed_ID; register_shutdown_function('wprss_detect_exec_timeout'); // Check if the feed source is active. if (wprss_is_feed_source_active($feed_ID) === FALSE && wprss_feed_source_force_next_fetch($feed_ID) === FALSE) { // If it is not active ( paused ), return without fetching the feed items. wprss_log('Feed is not active and not forced. Import cancelled.', null, WPRSS_LOG_LEVEL_INFO); return; } // If the feed source is forced for next fetch, remove the force next fetch data if (wprss_feed_source_force_next_fetch($feed_ID)) { delete_post_meta($feed_ID, 'wprss_force_next_fetch'); wprss_log('Force feed flag removed', null, WPRSS_LOG_LEVEL_SYSTEM); } $start_of_update = wprss_flag_feed_as_updating($feed_ID); wprss_log_obj('Start of import time updated', date('Y-m-d H:i:s', $start_of_update), null, WPRSS_LOG_LEVEL_SYSTEM); // Get the feed source URL from post meta, and filter it $feed_url = get_post_meta($feed_ID, 'wprss_url', true); wprss_log_obj('Original feed source URL', $feed_url, null, WPRSS_LOG_LEVEL_SYSTEM); $feed_url = apply_filters('wprss_feed_source_url', $feed_url, $feed_ID); wprss_log_obj('Actual feed source URL', $feed_url, null, WPRSS_LOG_LEVEL_INFO); // Get the feed limit from post meta $feed_limit = get_post_meta($feed_ID, 'wprss_limit', true); wprss_log_obj('Feed limit value is', $feed_limit, null, WPRSS_LOG_LEVEL_SYSTEM); // If the feed has no individual limit if ($feed_limit === '' || intval($feed_limit) <= 0) { wprss_log_obj('Using global limit', $feed_limit, null, WPRSS_LOG_LEVEL_NOTICE); // Get the global limit $global_limit = wprss_get_general_setting('limit_feed_items_imported'); // If no global limit is set, mark as NULL if ($global_limit === '' || intval($global_limit) <= 0) { $feed_limit = NULL; } else { $feed_limit = $global_limit; } } wprss_log_obj('Feed import limit', $feed_limit, null, WPRSS_LOG_LEVEL_INFO); // Filter the URL for validaty if (wprss_validate_url($feed_url)) { wprss_log_obj('Feed URL is valid', $feed_url, null, WPRSS_LOG_LEVEL_INFO); // Get the feed items from the source $items = wprss_get_feed_items($feed_url, $feed_ID); // If got NULL, convert to an empty array if ($items === NULL) { $items = array(); wprss_log('Items were NULL. Using empty array', null, WPRSS_LOG_LEVEL_WARNING); } // If using a limit ... if ($feed_limit === NULL) { $items_to_insert = $items; } else { $items_to_insert = array_slice($items, 0, $feed_limit); wprss_log_obj('Sliced a segment of items', count($items_to_insert), null, WPRSS_LOG_LEVEL_SYSTEM); } // Gather the permalinks of existing feed item's related to this feed source $existing_permalinks = wprss_get_existing_permalinks($feed_ID); wprss_log_obj('Retrieved existing permalinks', count($existing_permalinks), null, WPRSS_LOG_LEVEL_SYSTEM); // Check if we should only import uniquely-titled feed items. $existing_titles = array(); $unique_titles = FALSE; if (wprss_get_general_setting('unique_titles')) { $unique_titles = TRUE; $existing_titles = wprss_get_existing_titles(); wprss_log_obj('Retrieved existing titles from global', count($existing_titles), null, WPRSS_LOG_LEVEL_SYSTEM); } else { if (get_post_meta($feed_ID, 'wprss_unique_titles', true) === 'true') { $unique_titles = TRUE; $existing_titles = wprss_get_existing_titles($feed_ID); wprss_log_obj('Retrieved existing titles from feed source', count($existing_titles), null, WPRSS_LOG_LEVEL_SYSTEM); } } // Generate a list of items fetched, that are not already in the DB $new_items = array(); foreach ($items_to_insert as $item) { $permalink = wprss_normalize_permalink($item->get_permalink()); wprss_log_obj('Normalizing permalink', sprintf('%1$s -> %2$s', $item->get_permalink(), $permalink), null, WPRSS_LOG_LEVEL_SYSTEM); // Check if not blacklisted and not already imported $is_blacklisted = wprss_is_blacklisted($permalink); $permalink_exists = array_key_exists($permalink, $existing_permalinks); $title_exists = array_key_exists($item->get_title(), $existing_titles); if ($is_blacklisted === FALSE && $permalink_exists === FALSE && $title_exists === FALSE) { $new_items[] = $item; wprss_log_obj('Permalink OK', $permalink, null, WPRSS_LOG_LEVEL_SYSTEM); if ($unique_titles) { $existing_titles[$item->get_title()] = 1; } } else { if ($is_blacklisted) { wprss_log('Permalink blacklisted', null, WPRSS_LOG_LEVEL_SYSTEM); } if ($permalink_exists) { wprss_log('Permalink already exists', null, WPRSS_LOG_LEVEL_SYSTEM); } if ($title_exists) { wprss_log('Title already exists', null, WPRSS_LOG_LEVEL_SYSTEM); } } } $original_count = count($items_to_insert); $new_count = count($new_items); if ($new_count !== $original_count) { wprss_log_obj('Items filtered out', $original_count - $new_count, null, WPRSS_LOG_LEVEL_SYSTEM); } else { wprss_log('Items to import remained untouched. Not items already exist or are blacklisted.', null, WPRSS_LOG_LEVEL_SYSTEM); } $items_to_insert = $new_items; // If using a limit - delete any excess items to make room for the new items if ($feed_limit !== NULL) { wprss_log_obj('Some items may be deleted due to limit', $feed_limit, null, WPRSS_LOG_LEVEL_SYSTEM); // Get the number of feed items in DB, and their count $db_feed_items = wprss_get_feed_items_for_source($feed_ID); $num_db_feed_items = $db_feed_items->post_count; // Get the number of feed items we can store until we reach the limit $num_can_insert = $feed_limit - $num_db_feed_items; // Calculate how many feed items we must delete before importing, to keep to the limit $num_new_items = count($new_items); $num_feed_items_to_delete = $num_can_insert > $num_new_items ? 0 : $num_new_items - $num_can_insert; // Get an array with the DB feed items in reverse order (oldest first) $db_feed_items_reversed = array_reverse($db_feed_items->posts); // Cut the array to get only the first few that are to be deleted ( equal to $num_feed_items_to_delete ) $feed_items_to_delete = array_slice($db_feed_items_reversed, 0, $num_feed_items_to_delete); wprss_log(sprintf('There already are %1$d items in the database. %2$d items can be inserted. %3$d items will be deleted', $num_db_feed_items, $num_can_insert, $num_feed_items_to_delete), null, WPRSS_LOG_LEVEL_SYSTEM); // Iterate the feed items and delete them foreach ($feed_items_to_delete as $key => $post) { wp_delete_post($post->ID, TRUE); } if ($deleted_items_count = count($feed_items_to_delete)) { wprss_log_obj('Items deleted due to limit', $deleted_items_count, null, WPRSS_LOG_LEVEL_NOTICE); } } update_post_meta($feed_ID, 'wprss_last_update', $last_update_time = time()); update_post_meta($feed_ID, 'wprss_last_update_items', 0); wprss_log_obj('Last import time updated', $last_update_time, null, WPRSS_LOG_LEVEL_SYSTEM); // Insert the items into the db if (!empty($items_to_insert)) { wprss_log_obj('There are items to insert', count($items_to_insert), null, WPRSS_LOG_LEVEL_INFO); wprss_items_insert_post($items_to_insert, $feed_ID); } } else { wprss_log_obj('The feed URL is not valid! Please recheck', $feed_url); } $next_scheduled = get_post_meta($feed_ID, 'wprss_reschedule_event', TRUE); if ($next_scheduled !== '') { wprss_feed_source_update_start_schedule($feed_ID); delete_post_meta($feed_ID, 'wprss_reschedule_event'); wprss_log('Next update rescheduled', null, WPRSS_LOG_LEVEL_SYSTEM); } wprss_flag_feed_as_idle($feed_ID); wprss_log_obj('Import complete', $feed_ID, __FUNCTION__, WPRSS_LOG_LEVEL_INFO); }
/** * Time ago format checkbox * @since 4.2 */ function wprss_setting_time_ago_format_enable_callback($field) { $time_ago_format = wprss_get_general_setting('time_ago_format_enable'); ?> <input type="checkbox" id="<?php echo $field['field_id']; ?> " name="wprss_settings_general[time_ago_format_enable]" value="1" <?php echo checked(1, $time_ago_format, false); ?> /> <?php echo wprss_settings_inline_help($field['field_id'], $field['tooltip']); }
/** * Display pagination links * * @since 3.5 */ function wprss_pagination_links($output) { // Get the general setting $pagination = wprss_get_general_setting('pagination'); // Check the pagination setting, if using page numbers if ($pagination === 'numbered') { global $wp_query; $big = 999999999; // need an unlikely integer $output .= paginate_links(array('base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), 'format' => '?paged=%#%', 'current' => max(1, get_query_var('paged')), 'total' => $wp_query->max_num_pages)); return $output; } else { $output .= '<div class="nav-links">'; $output .= ' <div class="nav-previous alignleft">' . get_next_posts_link(__('Older posts', WPRSS_TEXT_DOMAIN)) . '</div>'; $output .= ' <div class="nav-next alignright">' . get_previous_posts_link(__('Newer posts', WPRSS_TEXT_DOMAIN)) . '</div>'; $output .= '</div>'; return $output; } }
/** * Generate the feed * * @since 3.3 */ function wprss_addfeed_do_feed($in) { // Prepare the post query /* $wprss_custom_feed_query = apply_filters( 'wprss_custom_feed_query', array( 'post_type' => 'wprss_feed_item', 'post_status' => 'publish', 'cache_results' => false, // disable caching ) );*/ $wprss_custom_feed_query = wprss_get_feed_items_query(apply_filters('wprss_custom_feed_query', array('get-args' => TRUE, 'no-paged' => TRUE, 'feed_limit' => 0))); // Suppress caching $wprss_custom_feed_query['cache_results'] = FALSE; // Get options $options = get_option('wprss_settings_general'); if ($options !== FALSE) { // If options exist, get the limit $limit = $options['custom_feed_limit']; if ($limit !== FALSE) { // if limit exists, set the query limit $wprss_custom_feed_query['posts_per_page'] = $limit; } } // Submit the query to get latest feed items query_posts($wprss_custom_feed_query); $custom_feed_title = wprss_get_general_setting('custom_feed_title'); // Send content header and start ATOM output header('Content-Type: text/xml'); // Disabling caching header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1. header('Pragma: no-cache'); // HTTP 1.0. header('Expires: 0'); // Proxies. echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '"?' . '>'; ?> <feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" > <title type="text"><?php echo $custom_feed_title; ?> </title> <?php // Start the Loop while (have_posts()) { the_post(); $permalink = get_post_meta(get_the_ID(), 'wprss_item_permalink', true); ?> <entry> <title><![CDATA[<?php the_title_rss(); ?> ]]></title> <link href="<?php echo $permalink; ?> " /> <?php // Enable below to link to post on our site rather than original source ?> <!--<link href="<?php the_permalink_rss(); ?> " />--> <published><?php echo get_post_time('Y-m-d\\TH:i:s\\Z'); ?> </published> <content type="html"><![CDATA[<?php the_content(); ?> ]]></content> <?php do_action('wprss_custom_feed_entry', get_the_ID()); ?> </entry> <?php // End of the Loop } ?> </feed> <?php }
/** * Time ago format checkbox * @since 4.2 */ function wprss_setting_time_ago_format_enable_callback() { $time_ago_format = wprss_get_general_setting('time_ago_format_enable'); echo "<input type='checkbox' id='time-ago-format' name='wprss_settings_general[time_ago_format_enable]' value='1' " . checked(1, $time_ago_format, false) . " />"; echo "<label class='description' for='time-ago-format'>Check this box to show time since update e.g.: 2 hours ago.</label>"; }
/** * Renders the 'log_level' setting field. * * @param array $field Info about the field */ function wprss_setting_log_level_callback($field) { $log_level = wprss_get_general_setting($field['field_id']); foreach (wprss_log_get_levels(false) as $_level => $_label) { $options[$_level] = $_label; if (is_numeric($_level) && $_level / 2 >= 1) { $options[(int) $_level * -1] = $_label . ' and below'; } } krsort($options, defined('SORT_NATURAL' ? SORT_NATURAL : SORT_STRING)); ?> <select id="<?php echo $field['field_id']; ?> " name="wprss_settings_general[<?php echo $field['field_id']; ?> ]"> <?php foreach ($options as $value => $text) { $selected = (string) $value === (string) $log_level ? 'selected="selected"' : ''; ?> <option value="<?php echo $value; ?> " <?php echo $selected; ?> ><?php echo __($text, WPRSS_TEXT_DOMAIN); ?> </option><?php } ?> </select> <?php echo wprss_settings_inline_help($field['field_id'], $field['tooltip']); }