WP RSS Aggregator - Version 4.0

Version Description

(2014-02-04) = * Enhanced: Improved some internal queries, for better performance. * Fixed bug: Feed limits were not working properly.

Download this release

Release Info

Developer jeangalea
Plugin Icon 128x128 WP RSS Aggregator
Version 4.0
Comparing to
See all releases

Code changes from version 3.9.9 to 4.0

changelog.txt CHANGED
@@ -1,3 +1,7 @@
 
 
 
 
1
  3.9.9 (2014-02-03)
2
  Enhanced: The custom feed can now be extended by add-ons.
3
 
1
+ 4.0 (2014-02-04)
2
+ Enhanced: Improved some internal queries, for better performance.
3
+ Fixed bug: Feed limits were not working properly.
4
+
5
  3.9.9 (2014-02-03)
6
  Enhanced: The custom feed can now be extended by add-ons.
7
 
includes/admin-welcome.php CHANGED
@@ -74,7 +74,8 @@
74
 
75
  <h3>Changelog for v<?php echo WPRSS_VERSION; ?></h3>
76
  <ul>
77
- <li><b>Enhanced:</b> The custom feed can now be extended by add-ons.</li>
 
78
  </ul>
79
 
80
 
74
 
75
  <h3>Changelog for v<?php echo WPRSS_VERSION; ?></h3>
76
  <ul>
77
+ <li><b>Enhanced:</b> Improved some internal queries, for better performance.</li>
78
+ <li><b>Fixed bug:</b> Feed limits were not working properly.</li>
79
  </ul>
80
 
81
 
includes/feed-importing.php ADDED
@@ -0,0 +1,389 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Functions relating to feed importing
4
+ *
5
+ * @package WPRSSAggregator
6
+ */
7
+
8
+
9
+
10
+ add_action( 'wprss_fetch_single_feed_hook', 'wprss_fetch_insert_single_feed_items' );
11
+ /**
12
+ * The main feed fetching function.
13
+ * Fetches the feed items from the source provided and inserts them into the DB.
14
+ *
15
+ * Called on hook 'wprss_fetch_single_feed_hook'.
16
+ *
17
+ * @since 3.2
18
+ */
19
+ function wprss_fetch_insert_single_feed_items( $feed_ID ) {
20
+ // Check if the feed source is active.
21
+ if ( wprss_is_feed_source_active( $feed_ID ) === FALSE && wprss_feed_source_force_next_fetch( $feed_ID ) === FALSE ) {
22
+ // If it is not active ( paused ), return without fetching the feed items.
23
+ return;
24
+ }
25
+ // If the feed source is forced for next fetch, remove the force next fetch data
26
+ if ( wprss_feed_source_force_next_fetch( $feed_ID ) ) {
27
+ delete_post_meta( $feed_ID, 'wprss_force_next_fetch' );
28
+ }
29
+
30
+ // Get the feed source URL from post meta, and filter it
31
+ $feed_url = get_post_meta( $feed_ID, 'wprss_url', true );
32
+ $feed_url = apply_filters( 'wprss_feed_source_url', $feed_url, $feed_ID );
33
+
34
+ // Get the feed limit from post meta
35
+ $feed_limit = get_post_meta( $feed_ID, 'wprss_limit', true );
36
+ // Sanitize the limit. If smaller or equal to zero, or an empty string, set to NULL.
37
+ $feed_limit = ( $feed_limit <= 0 || empty( $feed_limit ) )? NULL : $feed_limit;
38
+
39
+ // Filter the URL for validaty
40
+ if ( filter_var( $feed_url, FILTER_VALIDATE_URL ) ) {
41
+ // Get the feed items from the source
42
+ $items = wprss_get_feed_items( $feed_url );
43
+ // If got NULL, convert to an empty array
44
+ if ( $items === NULL ) $items = array();
45
+
46
+ // If the feed has its own meta limit,
47
+ if ( $feed_limit !== NULL ) {
48
+ // slice the items array using the feed meta limit
49
+ // @todo - Check current number of feed items for source, and delete oldest to make room for new, to keep to the limit.
50
+ // Use wprss_get_feed_items_for_source
51
+
52
+ $items_to_insert = array_slice( $items, 0, $feed_limit );
53
+
54
+ // Gather the permalinks of existing feed item's related to this feed source
55
+ $existing_permalinks = get_existing_permalinks( $feed_ID );
56
+
57
+ // Generate a list of items fetched, that are not already in the DB
58
+ $new_items = array();
59
+ foreach( $items as $item ) {
60
+ $permalink = $item->get_permalink();
61
+ if ( !in_array( $permalink, $existing_permalinks ) ) {
62
+ $new_items = array_push( $new_items, $item );
63
+ }
64
+ }
65
+
66
+ // Get the number of feed items in DB, and their count
67
+ $db_feed_items = wprss_get_feed_items_for_source( $feed_ID );
68
+ $num_db_feed_items = $db_feed_items->post_count;
69
+ // Get the number of feed items we can store until we reach the limit
70
+ $num_can_insert = $feed_limit - $num_db_feed_items;
71
+
72
+ // Calculate how many feed items we must delete before importing, to keep to the limit
73
+ $num_feed_items_to_delete = count( $new_items ) - $num_can_insert;
74
+
75
+ // Get an array with the DB feed items in reverse order (oldest first)
76
+ $db_feed_items_reversed = array_reverse( $db_feed_items->posts );
77
+ // Cut the array to get only the first few that are to be deleted ( equal to $num_feed_items_to_delete )
78
+ $feed_items_to_delete = array_slice( $db_feed_items_reversed, 0, $num_feed_items_to_delete );
79
+ // Iterate the feed items and delete them
80
+ foreach ( $feed_items_to_delete as $key => $post ) {
81
+ wp_delete_post( $post->ID, TRUE );
82
+ }
83
+
84
+ //$items_to_insert = $new_items;
85
+
86
+ }
87
+ else {
88
+ $items_to_insert = $items;
89
+ }
90
+
91
+ // Insert the items into the db
92
+ if ( !empty( $items_to_insert ) ) {
93
+ wprss_items_insert_post( $items_to_insert, $feed_ID );
94
+ }
95
+ }
96
+ }
97
+
98
+
99
+
100
+
101
+
102
+
103
+ /**
104
+ * Fetches the feed items from a feed at the given URL.
105
+ *
106
+ * Called from 'wprss_fetch_insert_single_feed_items'
107
+ *
108
+ * @since 3.0
109
+ */
110
+ function wprss_get_feed_items( $feed_url ) {
111
+ $general_settings = get_option( 'wprss_settings_general' );
112
+ $feed_item_limit = $general_settings['limit_feed_items_imported'];
113
+
114
+ // Don't fetch the feed if feed item limit is 0, there's no need, huge speed improvement
115
+ // if ( $feed_item_limit === '' ) return;
116
+
117
+ add_filter( 'wp_feed_cache_transient_lifetime' , 'wprss_feed_cache_lifetime' );
118
+
119
+ /* Disable caching of feeds */
120
+ add_action( 'wp_feed_options', 'wprss_do_not_cache_feeds' );
121
+ /* Fetch the feed from the soure URL specified */
122
+ $feed = wprss_fetch_feed( $feed_url );
123
+ //$feed = new SimplePie();
124
+ //$feed->set_feed_url( $feed_url );
125
+ //$feed->init();
126
+ /* Remove action here because we only don't want it active feed imports outside of our plugin */
127
+ remove_action( 'wp_feed_options', 'wprss_do_not_cache_feeds' );
128
+
129
+ //$feed = wprss_fetch_feed( $feed_url );
130
+ remove_filter( 'wp_feed_cache_transient_lifetime' , 'wprss_feed_cache_lifetime' );
131
+
132
+ if ( !is_wp_error( $feed ) ) {
133
+
134
+ // Figure out how many total items there are, but limit it to the number of items set in options.
135
+ $maxitems = $feed->get_item_quantity( $feed_item_limit );
136
+
137
+ if ( $maxitems == 0 ) { return; }
138
+
139
+ // Build an array of all the items, starting with element 0 (first element).
140
+ $items = $feed->get_items( 0, $maxitems );
141
+ return $items;
142
+ }
143
+
144
+ else {
145
+ wprss_log( 'Failed to fetch feed "' . $url . '"' );
146
+ return;
147
+ }
148
+ }
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+ /**
157
+ * A clone of the function 'fetch_feed' in wp-includes/feed.php [line #529]
158
+ *
159
+ * Called from 'wprss_get_feed_items'
160
+ *
161
+ * @since 3.5
162
+ */
163
+ function wprss_fetch_feed( $url ) {
164
+ require_once ( ABSPATH . WPINC . '/class-feed.php' );
165
+
166
+ $feed = new SimplePie();
167
+
168
+ // Commented out Sanitization, due to a conflict with google RSS image URLS.
169
+ // With sanitization on, the urls get truncated from the front.
170
+
171
+ // $feed->set_sanitize_class( 'WP_SimplePie_Sanitize_KSES' );
172
+ // We must manually overwrite $feed->sanitize because SimplePie's
173
+ // constructor sets it before we have a chance to set the sanitization class
174
+ // $feed->sanitize = new WP_SimplePie_Sanitize_KSES();
175
+
176
+ $feed->set_cache_class( 'WP_Feed_Cache' );
177
+ $feed->set_file_class( 'WP_SimplePie_File' );
178
+
179
+ $feed->set_feed_url( $url );
180
+
181
+ $feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url ) );
182
+ do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) );
183
+ $feed->init();
184
+ $feed->handle_content_type();
185
+
186
+ if ( $feed->error() ) {
187
+ return new WP_Error( 'simplepie-error', $feed->error() );
188
+ }
189
+
190
+ return $feed;
191
+ }
192
+
193
+
194
+
195
+
196
+ /**
197
+ * Converts YouTube, Vimeo and DailyMotion video urls
198
+ * into embedded video player urls.
199
+ * If the permalink is not a video url, the permalink is returned as is.
200
+ *
201
+ * @param $permalink The string permalink url to convert.
202
+ * @return A string, with the convert permalink, or the same permalink passed as parameter if
203
+ * not a video url.
204
+ * @since 4.0
205
+ */
206
+ function wprss_convert_video_permalink( $permalink ) {
207
+ // CHECK PERMALINK FOR VIDEO HOSTS : YOUTUBE, VIMEO AND DAILYMOTION
208
+ $found_video_host = preg_match( '/http[s]?:\/\/(www\.)?(youtube|dailymotion|vimeo)\.com\/(.*)/i', $permalink, $matches );
209
+
210
+ // If video host was found
211
+ if ( $found_video_host !== 0 && $found_video_host !== FALSE ) {
212
+
213
+ // Get general options
214
+ $options = get_option( 'wprss_settings_general' );
215
+ // Get the video link option entry, or false if it does not exist
216
+ $video_link = ( isset($options['video_link']) )? $options['video_link'] : 'false';
217
+
218
+ // If the video link option is true, change the video URL to its repective host's embedded
219
+ // video player URL. Otherwise, leave the permalink as is.
220
+ if ( strtolower( $video_link ) === 'true' ) {
221
+ $host = $matches[2];
222
+ switch( $host ) {
223
+ case 'youtube':
224
+ preg_match( '/(&|\?)v=([^&]+)/', $permalink, $yt_matches );
225
+ $permalink = 'http://www.youtube.com/embed/' . $yt_matches[2];
226
+ break;
227
+ case 'vimeo':
228
+ preg_match( '/(\d*)$/i', $permalink, $vim_matches );
229
+ $permalink = 'http://player.vimeo.com/video/' . $vim_matches[0];
230
+ break;
231
+ case 'dailymotion':
232
+ preg_match( '/(\.com\/)(video\/)(.*)/i', $permalink, $dm_matches );
233
+ $permalink = 'http://www.dailymotion.com/embed/video/' . $dm_matches[3];
234
+ break;
235
+ }
236
+ }
237
+ }
238
+
239
+ return $permalink;
240
+ }
241
+
242
+
243
+
244
+
245
+
246
+ /**
247
+ * Insert wprss_feed_item posts into the DB
248
+ *
249
+ * @since 3.0
250
+ */
251
+ function wprss_items_insert_post( $items, $feed_ID ) {
252
+
253
+ // Gather the permalinks of existing feed item's related to this feed source
254
+ $existing_permalinks = get_existing_permalinks( $feed_ID );
255
+
256
+ foreach ( $items as $item ) {
257
+
258
+ // Convert the url if it is a video url and the conversion is enabled in the settings.
259
+ $permalink = wprss_convert_video_permalink( $item->get_permalink() );
260
+
261
+
262
+ /* OLD NORMALIZATION CODE - TO NORMALIZE URLS FROM PROXY URLS
263
+ $response = wp_remote_head( $permalink );
264
+ if ( !is_wp_error( $response ) && isset( $response['headers']['location'] ) ) {
265
+ $permalink = current( explode( '?', $response['headers']['location'] ) );
266
+ }*/
267
+
268
+ // Check if newly fetched item already present in existing feed items,
269
+ // if not insert it into wp_posts and insert post meta.
270
+ if ( ! ( in_array( $permalink, $existing_permalinks ) ) ) {
271
+
272
+ // Apply filters that determine if the feed item should be inserted into the DB or not.
273
+ $item = apply_filters( 'wprss_insert_post_item_conditionals', $item, $feed_ID, $permalink );
274
+
275
+ // If the item is not NULL, continue to inserting the feed item post into the DB
276
+ if ( $item !== NULL ) {
277
+
278
+ $feed_item = apply_filters(
279
+ 'wprss_populate_post_data',
280
+ array(
281
+ 'post_title' => $item->get_title(),
282
+ 'post_content' => '',
283
+ 'post_status' => 'publish',
284
+ 'post_type' => 'wprss_feed_item',
285
+ 'post_date' => get_date_from_gmt( $item->get_date( 'Y-m-d H:i:s' ) ),
286
+ 'post_date_gmt' => $item->get_date( 'Y-m-d H:i:s' ),
287
+ ),
288
+ $item
289
+ );
290
+
291
+ if ( defined('ICL_SITEPRESS_VERSION') )
292
+ @include_once( WP_PLUGIN_DIR . '/sitepress-multilingual-cms/inc/wpml-api.php' );
293
+ if ( defined('ICL_LANGUAGE_CODE') )
294
+ $_POST['icl_post_language'] = $language_code = ICL_LANGUAGE_CODE;
295
+
296
+ // Create and insert post object into the DB
297
+ $inserted_ID = wp_insert_post( $feed_item );
298
+
299
+ if ( !is_wp_error( $inserted_ID ) ) {
300
+
301
+ if ( is_object( $inserted_ID ) ) {
302
+ if ( isset( $inserted_ID['ID'] ) ) {
303
+ $inserted_ID = $inserted_ID['ID'];
304
+ }
305
+ elseif ( isset( $inserted_ID->ID ) ) {
306
+ $inserted_ID = $inserted_ID->ID;
307
+ }
308
+ }
309
+
310
+ // Create and insert post meta into the DB
311
+ wprss_items_insert_post_meta( $inserted_ID, $item, $feed_ID, $permalink );
312
+
313
+ // Remember newly added permalink
314
+ $existing_permalinks[] = $permalink;
315
+ }
316
+ else {
317
+ wprss_log_obj( 'Failed to insert post', $feed_item, 'wprss_items_insert_post > wp_insert_post' );
318
+ }
319
+ }
320
+ }
321
+ }
322
+ }
323
+
324
+
325
+
326
+
327
+
328
+ /**
329
+ * Inserts the appropriate post meta for feed items.
330
+ *
331
+ * Called from 'wprss_items_insert_post'
332
+ *
333
+ * @since 2.3
334
+ */
335
+ function wprss_items_insert_post_meta( $inserted_ID, $item, $feed_ID, $feed_url) {
336
+ update_post_meta( $inserted_ID, 'wprss_item_permalink', $feed_url );
337
+ update_post_meta( $inserted_ID, 'wprss_item_description', $item->get_description() );
338
+ update_post_meta( $inserted_ID, 'wprss_item_date', $item->get_date( 'U' ) ); // Save as Unix timestamp format
339
+ update_post_meta( $inserted_ID, 'wprss_feed_id', $feed_ID);
340
+ do_action( 'wprss_items_create_post_meta', $inserted_ID, $item, $feed_ID );
341
+ }
342
+
343
+
344
+
345
+
346
+
347
+
348
+
349
+ /**
350
+ * Fetches all feed items from all feed sources.
351
+ * Iteratively calls 'wprss_fetch_insert_single_feed_items' for all feed sources.
352
+ *
353
+ * This function is used by the cron job or the debugging functions to get all feeds from all feed sources
354
+ *
355
+ * @param $all If set to TRUE, the function will pull from all feed sources, regardless of their individual
356
+ * update interval. If set to FALSE, only feed sources using the global update system will be updated.
357
+ * (Optional) Default: TRUE.
358
+ * @since 3.0
359
+ */
360
+ function wprss_fetch_insert_all_feed_items( $all = TRUE ) {
361
+ // Get all feed sources
362
+ $feed_sources = wprss_get_all_feed_sources();
363
+
364
+ if( $feed_sources->have_posts() ) {
365
+ // Start by getting one feed source, we will cycle through them one by one,
366
+ // fetching feed items and adding them to the database in each pass
367
+ while ( $feed_sources->have_posts() ) {
368
+ $feed_sources->the_post();
369
+
370
+ $interval = get_post_meta( get_the_ID(), 'wprss_update_interval', TRUE );
371
+ $using_global_interval = ( $interval === wprss_get_default_feed_source_update_interval() || $interval === '' );
372
+
373
+ // Check if fetching from all, or if feed source uses the global interval
374
+ if ( $all === TRUE || $using_global_interval ) {
375
+ wp_schedule_single_event( time(), 'wprss_fetch_single_feed_hook', array( get_the_ID() ) );
376
+ }
377
+ }
378
+ wp_reset_postdata(); // Restore the $post global to the current post in the main query
379
+ }
380
+ }
381
+
382
+ /**
383
+ * Runs the above function with parameter FALSE
384
+ *
385
+ * @since 3.9
386
+ */
387
+ function wprss_fetch_insert_all_feed_items_from_cron() {
388
+ wprss_fetch_insert_all_feed_items( FALSE );
389
+ }
includes/feed-processing.php CHANGED
@@ -6,46 +6,6 @@
6
  */
7
 
8
 
9
-
10
- add_action( 'init', 'wprss_change_feed_state' );
11
- /**
12
- * Changes the state of a feed source, using POST data
13
- *
14
- * @since 3.7
15
- */
16
- function wprss_change_feed_state() {
17
- // If the id and state are in POST data
18
- if ( isset( $_GET['wprss-feed-id'] ) ) {
19
- // Get the id and state
20
- $feed_ID = $_GET['wprss-feed-id'];
21
- // Change the state
22
- if ( wprss_is_feed_source_active( $feed_ID ) ) {
23
- wprss_pause_feed_source( $feed_ID );
24
- } else {
25
- wprss_activate_feed_source( $feed_ID );
26
- }
27
- // Check for a redirect
28
- if ( isset( $_GET['wprss-redirect'] ) && $_GET['wprss-redirect'] == '1' ) {
29
- wp_redirect( admin_url( 'edit.php?post_type=wprss_feed', 301 ) );
30
- exit();
31
- }
32
- }
33
- }
34
-
35
-
36
- /**
37
- * Returns whether or not a feed source is active.
38
- *
39
- * @param $source_id The ID of the feed soruce
40
- * @return boolean
41
- * @since 3.7
42
- */
43
- function wprss_is_feed_source_active( $source_id ) {
44
- $state = get_post_meta( $source_id, 'wprss_state', TRUE );
45
- return ( $state === '' || $state === 'active' );
46
- }
47
-
48
-
49
  /**
50
  * Returns whether or not the feed source will forcefully fetch the next fetch,
51
  * ignoring whether or not it is paused or not.
@@ -119,6 +79,9 @@
119
  'cache_results' => false, // Disable caching, used for one-off queries
120
  'no_found_rows' => true, // We don't need pagination, so disable it
121
  'posts_per_page'=> -1,
 
 
 
122
  'meta_query' => array(
123
  array(
124
  'key' => 'wprss_feed_id',
@@ -172,213 +135,6 @@
172
  }
173
 
174
 
175
- /**
176
- * A clone of the function 'fetch_feed' in wp-includes/feed.php [line #529]
177
- *
178
- * @since 3.5
179
- */
180
- function wprss_fetch_feed( $url ) {
181
- require_once ( ABSPATH . WPINC . '/class-feed.php' );
182
-
183
- $feed = new SimplePie();
184
-
185
- // Commented out Sanitization, due to a conflict with google RSS image URLS.
186
- // With sanitization on, the urls get truncated from the front.
187
-
188
- // $feed->set_sanitize_class( 'WP_SimplePie_Sanitize_KSES' );
189
- // We must manually overwrite $feed->sanitize because SimplePie's
190
- // constructor sets it before we have a chance to set the sanitization class
191
- // $feed->sanitize = new WP_SimplePie_Sanitize_KSES();
192
-
193
- $feed->set_cache_class( 'WP_Feed_Cache' );
194
- $feed->set_file_class( 'WP_SimplePie_File' );
195
-
196
- $feed->set_feed_url( $url );
197
-
198
- $feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url ) );
199
- do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) );
200
- $feed->init();
201
- $feed->handle_content_type();
202
-
203
- if ( $feed->error() ) {
204
- return new WP_Error( 'simplepie-error', $feed->error() );
205
- }
206
-
207
- return $feed;
208
- }
209
-
210
-
211
- /**
212
- * Fetch the feeds from a feed item url
213
- *
214
- * @since 3.0
215
- */
216
- function wprss_get_feed_items( $feed_url ) {
217
- $general_settings = get_option( 'wprss_settings_general' );
218
- $feed_item_limit = $general_settings['limit_feed_items_imported'];
219
-
220
- // Don't fetch the feed if feed item limit is 0, there's no need, huge speed improvement
221
- // if ( $feed_item_limit === '' ) return;
222
-
223
- add_filter( 'wp_feed_cache_transient_lifetime' , 'wprss_feed_cache_lifetime' );
224
-
225
- /* Disable caching of feeds */
226
- add_action( 'wp_feed_options', 'wprss_do_not_cache_feeds' );
227
- /* Fetch the feed from the soure URL specified */
228
- $feed = wprss_fetch_feed( $feed_url );
229
- //$feed = new SimplePie();
230
- //$feed->set_feed_url( $feed_url );
231
- //$feed->init();
232
- /* Remove action here because we only don't want it active feed imports outside of our plugin */
233
- remove_action( 'wp_feed_options', 'wprss_do_not_cache_feeds' );
234
-
235
- //$feed = wprss_fetch_feed( $feed_url );
236
- remove_filter( 'wp_feed_cache_transient_lifetime' , 'wprss_feed_cache_lifetime' );
237
-
238
- if ( !is_wp_error( $feed ) ) {
239
-
240
- // Figure out how many total items there are, but limit it to the number of items set in options.
241
- $maxitems = $feed->get_item_quantity( $feed_item_limit );
242
-
243
- if ( $maxitems == 0 ) { return; }
244
-
245
- // Build an array of all the items, starting with element 0 (first element).
246
- $items = $feed->get_items( 0, $maxitems );
247
- return $items;
248
- }
249
-
250
- else {
251
- wprss_log( 'Failed to fetch feed "' . $url . '"' );
252
- return;
253
- }
254
- }
255
-
256
-
257
- /**
258
- * Insert a WPRSS feed item post
259
- *
260
- * @since 3.0
261
- */
262
- function wprss_items_insert_post( $items, $feed_ID ) {
263
-
264
- // Gather the permalinks of existing feed item's related to this feed source
265
- $existing_permalinks = get_existing_permalinks( $feed_ID );
266
-
267
- foreach ( $items as $item ) {
268
-
269
- // normalize permalink to pass through feed proxy URL
270
- $permalink = $item->get_permalink();
271
-
272
- // CHECK PERMALINK FOR VIDEO HOSTS : YOUTUBE, VIMEO AND DAILYMOTION
273
- $found_video_host = preg_match( '/http[s]?:\/\/(www\.)?(youtube|dailymotion|vimeo)\.com\/(.*)/i', $permalink, $matches );
274
-
275
- // If video host was found
276
- if ( $found_video_host !== 0 && $found_video_host !== FALSE ) {
277
-
278
- // Get general options
279
- $options = get_option( 'wprss_settings_general' );
280
- // Get the video link option entry, or false if it does not exist
281
- $video_link = ( isset($options['video_link']) )? $options['video_link'] : 'false';
282
-
283
- // If the video link option is true, change the video URL to its repective host's embedded
284
- // video player URL. Otherwise, leave the permalink as is.
285
- if ( strtolower( $video_link ) === 'true' ) {
286
- $host = $matches[2];
287
- switch( $host ) {
288
- case 'youtube':
289
- preg_match( '/(&|\?)v=([^&]+)/', $permalink, $yt_matches );
290
- $permalink = 'http://www.youtube.com/embed/' . $yt_matches[2];
291
- break;
292
- case 'vimeo':
293
- preg_match( '/(\d*)$/i', $permalink, $vim_matches );
294
- $permalink = 'http://player.vimeo.com/video/' . $vim_matches[0];
295
- break;
296
- case 'dailymotion':
297
- preg_match( '/(\.com\/)(video\/)(.*)/i', $permalink, $dm_matches );
298
- $permalink = 'http://www.dailymotion.com/embed/video/' . $dm_matches[3];
299
- break;
300
- }
301
- }
302
- }
303
-
304
-
305
- /*
306
- $response = wp_remote_head( $permalink );
307
- if ( !is_wp_error( $response ) && isset( $response['headers']['location'] ) ) {
308
- $permalink = current( explode( '?', $response['headers']['location'] ) );
309
- }*/
310
-
311
- // Check if newly fetched item already present in existing feed items,
312
- // if not insert it into wp_posts and insert post meta.
313
- if ( ! ( in_array( $permalink, $existing_permalinks ) ) ) {
314
-
315
- // Apply filters that determine if the feed item should be inserted into the DB or not.
316
- $item = apply_filters( 'wprss_insert_post_item_conditionals', $item, $feed_ID, $permalink );
317
-
318
- // If the item is not NULL, continue to inserting the feed item post into the DB
319
- if ( $item !== NULL ) {
320
-
321
- $feed_item = apply_filters(
322
- 'wprss_populate_post_data',
323
- array(
324
- 'post_title' => $item->get_title(),
325
- 'post_content' => '',
326
- 'post_status' => 'publish',
327
- 'post_type' => 'wprss_feed_item',
328
- 'post_date' => get_date_from_gmt( $item->get_date( 'Y-m-d H:i:s' ) ),
329
- 'post_date_gmt' => $item->get_date( 'Y-m-d H:i:s' ),
330
- ),
331
- $item
332
- );
333
-
334
- if ( defined('ICL_SITEPRESS_VERSION') )
335
- @include_once( WP_PLUGIN_DIR . '/sitepress-multilingual-cms/inc/wpml-api.php' );
336
- if ( defined('ICL_LANGUAGE_CODE') )
337
- $_POST['icl_post_language'] = $language_code = ICL_LANGUAGE_CODE;
338
-
339
- // Create and insert post object into the DB
340
- $inserted_ID = wp_insert_post( $feed_item );
341
-
342
- if ( !is_wp_error( $inserted_ID ) ) {
343
-
344
- if ( is_object( $inserted_ID ) ) {
345
- if ( isset( $inserted_ID['ID'] ) ) {
346
- $inserted_ID = $inserted_ID['ID'];
347
- }
348
- elseif ( isset( $inserted_ID->ID ) ) {
349
- $inserted_ID = $inserted_ID->ID;
350
- }
351
- }
352
-
353
- // Create and insert post meta into the DB
354
- wprss_items_insert_post_meta( $inserted_ID, $item, $feed_ID, $permalink );
355
-
356
- // Remember newly added permalink
357
- $existing_permalinks[] = $permalink;
358
- }
359
- else {
360
- wprss_log_obj( 'Failed to insert post', $feed_item, 'wprss_items_insert_post > wp_insert_post' );
361
- }
362
- }
363
- }
364
- }
365
- }
366
-
367
-
368
- /**
369
- * Creates meta entries for feed items while they are being imported
370
- *
371
- * @since 2.3
372
- */
373
- function wprss_items_insert_post_meta( $inserted_ID, $item, $feed_ID, $feed_url) {
374
- update_post_meta( $inserted_ID, 'wprss_item_permalink', $feed_url );
375
- update_post_meta( $inserted_ID, 'wprss_item_description', $item->get_description() );
376
- update_post_meta( $inserted_ID, 'wprss_item_date', $item->get_date( 'U' ) ); // Save as Unix timestamp format
377
- update_post_meta( $inserted_ID, 'wprss_feed_id', $feed_ID);
378
- do_action( 'wprss_items_create_post_meta', $inserted_ID, $item, $feed_ID );
379
- }
380
-
381
-
382
  add_action( 'publish_wprss_feed', 'wprss_fetch_insert_feed_items', 10 );
383
  /**
384
  * Fetches feed items from source provided and inserts into db
@@ -471,92 +227,6 @@
471
 
472
 
473
 
474
- add_action( 'wprss_fetch_single_feed_hook', 'wprss_fetch_insert_single_feed_items' );
475
- /**
476
- * Fetches feed items from source provided and inserts into db
477
- *
478
- * @since 3.2
479
- */
480
- function wprss_fetch_insert_single_feed_items( $feed_ID ) {
481
- // Check if the feed source is active.
482
- if ( wprss_is_feed_source_active( $feed_ID ) === FALSE && wprss_feed_source_force_next_fetch( $feed_ID ) === FALSE ) {
483
- // If it is not active ( paused ), return without fetching the feed items.
484
- return;
485
- }
486
- if ( wprss_feed_source_force_next_fetch( $feed_ID ) ) {
487
- delete_post_meta( $feed_ID, 'wprss_force_next_fetch' );
488
- }
489
-
490
- // Get the URL and Feed Limit post meta data
491
- $feed_url = get_post_meta( $feed_ID, 'wprss_url', true );
492
- $feed_limit = get_post_meta( $feed_ID, 'wprss_limit', true );
493
-
494
- $feed_url = apply_filters( 'wprss_feed_source_url', $feed_url, $feed_ID );
495
-
496
- // Use the URL custom field to fetch the feed items for this source
497
- if ( filter_var( $feed_url, FILTER_VALIDATE_URL ) ) {
498
- $items = wprss_get_feed_items( $feed_url );
499
- if ( $items === NULL ) $items = array();
500
-
501
- // If the feed has its own meta limit, which is not zero,
502
- // slice the items array using the feed meta limit
503
- if ( !empty( $feed_limit ) && $feed_limit !== 0 ) {
504
- $items_to_insert = array_slice($items, 0, $feed_limit);
505
- }
506
- else {
507
- $items_to_insert = $items;
508
- }
509
-
510
- // Insert the items into the db
511
- if ( !empty( $items_to_insert ) ) {
512
- wprss_items_insert_post( $items_to_insert, $feed_ID );
513
- }
514
- }
515
- }
516
-
517
-
518
- /**
519
- * Fetches all feed items from sources provided and inserts into db
520
- *
521
- * This function is used by the cron job or the debugging functions to get all feeds from all feed sources
522
- *
523
- * @param $all If set to TRUE, the function will pull from all feed sources, regardless of their individual
524
- * update interval. If set to FALSE, only feed sources using the global update system will be updated.
525
- * (Optional) Default: TRUE.
526
- * @since 3.0
527
- */
528
- function wprss_fetch_insert_all_feed_items( $all = TRUE ) {
529
- // Get all feed sources
530
- $feed_sources = wprss_get_all_feed_sources();
531
-
532
- if( $feed_sources->have_posts() ) {
533
- // Start by getting one feed source, we will cycle through them one by one,
534
- // fetching feed items and adding them to the database in each pass
535
- while ( $feed_sources->have_posts() ) {
536
- $feed_sources->the_post();
537
-
538
- $interval = get_post_meta( get_the_ID(), 'wprss_update_interval', TRUE );
539
- $using_global_interval = ( $interval === wprss_get_default_feed_source_update_interval() || $interval === '' );
540
-
541
- // Check if fetching from all, or if feed source uses the global interval
542
- if ( $all === TRUE || $using_global_interval ) {
543
- wp_schedule_single_event( time(), 'wprss_fetch_single_feed_hook', array( get_the_ID() ) );
544
- }
545
- }
546
- wp_reset_postdata(); // Restore the $post global to the current post in the main query
547
- }
548
- }
549
- /**
550
- * Runs the above function with parameter FALSE
551
- *
552
- * @since 3.9
553
- */
554
- function wprss_fetch_insert_all_feed_items_from_cron() {
555
- wprss_fetch_insert_all_feed_items( FALSE );
556
- }
557
-
558
-
559
-
560
  add_action( 'updated_post_meta', 'wprss_update_feed_meta', 10, 4 );
561
  /**
562
  * This function is run whenever a post is saved or updated.
6
  */
7
 
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  /**
10
  * Returns whether or not the feed source will forcefully fetch the next fetch,
11
  * ignoring whether or not it is paused or not.
79
  'cache_results' => false, // Disable caching, used for one-off queries
80
  'no_found_rows' => true, // We don't need pagination, so disable it
81
  'posts_per_page'=> -1,
82
+ 'orderby' => 'meta_value',
83
+ 'meta_key' => 'wprss_item_date',
84
+ 'order' => 'DESC',
85
  'meta_query' => array(
86
  array(
87
  'key' => 'wprss_feed_id',
135
  }
136
 
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  add_action( 'publish_wprss_feed', 'wprss_fetch_insert_feed_items', 10 );
139
  /**
140
  * Fetches feed items from source provided and inserts into db
227
 
228
 
229
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
230
  add_action( 'updated_post_meta', 'wprss_update_feed_meta', 10, 4 );
231
  /**
232
  * This function is run whenever a post is saved or updated.
includes/feed-states.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Functions relating to feed source states
4
+ *
5
+ * @package WPRSSAggregator
6
+ */
7
+
8
+
9
+ add_action( 'init', 'wprss_change_feed_state' );
10
+ /**
11
+ * Changes the state of a feed source, using POST data
12
+ *
13
+ * @since 3.7
14
+ */
15
+ function wprss_change_feed_state() {
16
+ // If the id and state are in POST data
17
+ if ( isset( $_GET['wprss-feed-id'] ) ) {
18
+ // Get the id and state
19
+ $feed_ID = $_GET['wprss-feed-id'];
20
+ // Change the state
21
+ if ( wprss_is_feed_source_active( $feed_ID ) ) {
22
+ wprss_pause_feed_source( $feed_ID );
23
+ } else {
24
+ wprss_activate_feed_source( $feed_ID );
25
+ }
26
+ // Check for a redirect
27
+ if ( isset( $_GET['wprss-redirect'] ) && $_GET['wprss-redirect'] == '1' ) {
28
+ wp_redirect( admin_url( 'edit.php?post_type=wprss_feed', 301 ) );
29
+ exit();
30
+ }
31
+ }
32
+ }
33
+
34
+
35
+ /**
36
+ * Returns whether or not a feed source is active.
37
+ *
38
+ * @param $source_id The ID of the feed soruce
39
+ * @return boolean
40
+ * @since 3.7
41
+ */
42
+ function wprss_is_feed_source_active( $source_id ) {
43
+ $state = get_post_meta( $source_id, 'wprss_state', TRUE );
44
+ return ( $state === '' || $state === 'active' );
45
+ }
readme.txt CHANGED
@@ -5,7 +5,7 @@ Plugin URI: http://www.wprssaggregator.com
5
  Tags: rss, feeds, aggregation, autoblog aggregator, rss import, feed aggregator, rss aggregator, multiple rss feeds, multi rss feeds, rss multi importer, feed import, feed import, multiple feed import, feed aggregation, rss feader, feed reader, feed to post, multiple feeds, multi feed importer, multi feed import, multi import, autoblogging, autoblogger
6
  Requires at least: 3.3
7
  Tested up to: 3.8
8
- Stable tag: 3.9.9
9
  License: GPLv2 or later
10
  Imports and aggregates multiple RSS Feeds using SimplePie. Outputs feeds sorted by date (latest first).
11
 
@@ -145,6 +145,10 @@ Yes, within the [Feed to Post](http://www.wprssaggregator.com/extensions/feed-to
145
 
146
  == Changelog ==
147
 
 
 
 
 
148
  = 3.9.9 (2014-02-03) =
149
  * Enhanced: The custom feed can now be extended by add-ons.
150
 
5
  Tags: rss, feeds, aggregation, autoblog aggregator, rss import, feed aggregator, rss aggregator, multiple rss feeds, multi rss feeds, rss multi importer, feed import, feed import, multiple feed import, feed aggregation, rss feader, feed reader, feed to post, multiple feeds, multi feed importer, multi feed import, multi import, autoblogging, autoblogger
6
  Requires at least: 3.3
7
  Tested up to: 3.8
8
+ Stable tag: 4.0
9
  License: GPLv2 or later
10
  Imports and aggregates multiple RSS Feeds using SimplePie. Outputs feeds sorted by date (latest first).
11
 
145
 
146
  == Changelog ==
147
 
148
+ = 4.0 (2014-02-04) =
149
+ * Enhanced: Improved some internal queries, for better performance.
150
+ * Fixed bug: Feed limits were not working properly.
151
+
152
  = 3.9.9 (2014-02-03) =
153
  * Enhanced: The custom feed can now be extended by add-ons.
154
 
wp-rss-aggregator.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP RSS Aggregator
4
  Plugin URI: http://www.wprssaggregator.com
5
  Description: Imports and aggregates multiple RSS Feeds using SimplePie
6
- Version: 3.9.9
7
  Author: Jean Galea
8
  Author URI: http://www.wprssaggregator.com
9
  License: GPLv2
@@ -29,7 +29,7 @@
29
 
30
  /**
31
  * @package WPRSSAggregator
32
- * @version 3.9.9
33
  * @since 1.0
34
  * @author Jean Galea <info@jeangalea.com>
35
  * @copyright Copyright (c) 2012-2013, Jean Galea
@@ -43,7 +43,7 @@
43
 
44
  // Set the version number of the plugin.
45
  if( !defined( 'WPRSS_VERSION' ) )
46
- define( 'WPRSS_VERSION', '3.9.9', true );
47
 
48
  // Set the database version number of the plugin.
49
  if( !defined( 'WPRSS_DB_VERSION' ) )
@@ -103,7 +103,13 @@
103
  require_once ( WPRSS_INC . 'roles-capabilities.php' );
104
 
105
  /* Load the feed processing functions file */
106
- require_once ( WPRSS_INC . 'feed-processing.php' );
 
 
 
 
 
 
107
 
108
  /* Load the feed display functions file */
109
  require_once ( WPRSS_INC . 'feed-display.php' );
3
  Plugin Name: WP RSS Aggregator
4
  Plugin URI: http://www.wprssaggregator.com
5
  Description: Imports and aggregates multiple RSS Feeds using SimplePie
6
+ Version: 4.0
7
  Author: Jean Galea
8
  Author URI: http://www.wprssaggregator.com
9
  License: GPLv2
29
 
30
  /**
31
  * @package WPRSSAggregator
32
+ * @version 4.0
33
  * @since 1.0
34
  * @author Jean Galea <info@jeangalea.com>
35
  * @copyright Copyright (c) 2012-2013, Jean Galea
43
 
44
  // Set the version number of the plugin.
45
  if( !defined( 'WPRSS_VERSION' ) )
46
+ define( 'WPRSS_VERSION', '4.0', true );
47
 
48
  // Set the database version number of the plugin.
49
  if( !defined( 'WPRSS_DB_VERSION' ) )
103
  require_once ( WPRSS_INC . 'roles-capabilities.php' );
104
 
105
  /* Load the feed processing functions file */
106
+ require_once ( WPRSS_INC . 'feed-processing.php' );
107
+
108
+ /* Load the feed importing functions file */
109
+ require_once ( WPRSS_INC . 'feed-importing.php' );
110
+
111
+ /* Load the feed states functions file */
112
+ require_once ( WPRSS_INC . 'feed-states.php' );
113
 
114
  /* Load the feed display functions file */
115
  require_once ( WPRSS_INC . 'feed-display.php' );