@@ -112,8 +112,8 @@ function wprss_fetch_insert_single_feed_items( $feed_ID ) {
112
112
$ useGuids = get_post_meta ($ feed_ID , 'wprss_use_guids ' , true );
113
113
$ useGuids = filter_var ($ useGuids , FILTER_VALIDATE_BOOLEAN );
114
114
$ existingIds = $ useGuids
115
- ? wprss_get_existing_guids ($ feed_ID )
116
- : wprss_get_existing_permalinks ($ feed_ID );
115
+ ? wprss_get_existing_guids ()
116
+ : wprss_get_existing_permalinks ();
117
117
118
118
// Generate a list of items fetched, that are not already in the DB
119
119
$ new_items = array ();
@@ -527,8 +527,8 @@ function wprss_tracking_url_fix( $permalink, $patterns, $argName = 'url' ) {
527
527
* into embedded video player urls.
528
528
* If the permalink is not a video url, the permalink is returned as is.
529
529
*
530
- * @param $permalink The string permalink url to convert.
531
- * @return A string, with the convert permalink, or the same permalink passed as parameter if
530
+ * @param string $permalink The string permalink url to convert.
531
+ * @return string A string, with the convert permalink, or the same permalink passed as parameter if
532
532
* not a video url.
533
533
* @since 4.0
534
534
*/
@@ -550,8 +550,8 @@ function wprss_convert_video_permalink( $permalink ) {
550
550
$ host = $ matches [2 ];
551
551
switch ( $ host ) {
552
552
case 'youtube ' :
553
- preg_match ( '/(&|\? )v=([^&]+)/ ' , $ permalink , $ yt_matches );
554
- $ permalink = 'https://www.youtube.com/embed/ ' . $ yt_matches [2 ];
553
+ preg_match ( '/([&?] )v=([^&]+)/ ' , $ permalink , $ yt_matches );
554
+ $ permalink = 'https://www.youtube.com/embed/ ' . $ yt_matches [1 ];
555
555
break ;
556
556
case 'vimeo ' :
557
557
preg_match ( '/(\d*)$/i ' , $ permalink , $ vim_matches );
@@ -584,6 +584,16 @@ function wprss_items_insert_post( $items, $feed_ID ) {
584
584
// Count of items inserted
585
585
$ items_inserted = 0 ;
586
586
587
+ // The date format expected by WordPress when inserting posts
588
+ $ date_format = 'Y-m-d H:i:s ' ;
589
+ // Check if we can schedule future items
590
+ $ schedule_items_filter = apply_filters ('wpra/importer/allow_scheduled_items ' , false );
591
+ $ schedule_items_option = wprss_get_general_setting ('schedule_future_items ' );
592
+ $ schedule_future_items = $ schedule_items_filter || $ schedule_items_option ;
593
+
594
+ // Get whether the imported items count should still be updated, even if the item is imported by a filter or add-on
595
+ $ still_update_count = apply_filters ( 'wprss_still_update_import_count ' , FALSE );
596
+
587
597
foreach ( $ items as $ i => $ item ) {
588
598
$ permalink = $ item ->get_permalink ();
589
599
$ permalink = wprss_normalize_permalink ($ permalink , $ item , $ feed_ID );
@@ -624,51 +634,43 @@ function wprss_items_insert_post( $items, $feed_ID ) {
624
634
$ item = apply_filters ( 'wprss_insert_post_item_conditionals ' , $ item , $ feed_ID , $ permalink );
625
635
/* @var $item SimplePie_Item */
626
636
627
- // Check if the imported count should still be updated, even if the item is NULL
628
- $ still_update_count = apply_filters ( 'wprss_still_update_import_count ' , FALSE );
629
-
630
637
// If the item is not NULL, continue to inserting the feed item post into the DB
631
638
if ( $ item !== NULL && !is_bool ($ item ) ) {
632
639
$ logger ->debug ('Resuming insertion into DB ' );
633
640
634
641
$ post_status = 'publish ' ;
635
642
636
- // Get the date and GMT date and normalize if not valid or not given by the feed
637
- $ format = 'Y-m-d H:i:s ' ;
643
+ // Get the date and normalize if not valid or not given by the feed
638
644
$ timestamp = $ item ->get_date ( 'U ' );
639
- $ has_date = $ timestamp ? true : false ;
645
+ $ has_date = ! empty ( $ timestamp) ;
640
646
641
647
if ($ has_date ) {
642
- $ logger ->debug ('Feed item "{0}" date: {1} ' , [$ item ->get_title (), $ item ->get_date ($ format )]);
648
+ $ logger ->debug ('Feed item "{0}" date: {1} ' , [$ item ->get_title (), $ item ->get_date ($ date_format )]);
643
649
644
650
if ($ timestamp > time ()) {
645
651
// Item has a future timestamp ...
646
652
$ logger ->debug ('Item "{0}" has a future date ' , [$ item ->get_title ()]);
647
653
648
- $ schedule_items_filter = apply_filters ('wpra/importer/allow_scheduled_items ' , false );
649
- $ schedule_items_option = wprss_get_general_setting ('schedule_future_items ' );
650
-
651
- if ($ schedule_items_filter || $ schedule_items_option ) {
652
- // If can schedule future items, set the post status to "future" (aka scheduled)
653
- $ post_status = 'future ' ;
654
-
654
+ // If we can schedule future items, set the post status to "future" (aka scheduled).
655
+ // Otherwise, clamp the timestamp to the current time minus 1 second for each item iteration.
656
+ // This results in the items having a 1-second time difference between them, and preserves their
657
+ // order when sorting by their timestamp.
658
+ if ($ schedule_future_items ) {
655
659
$ logger ->debug ('Setting future status ' );
660
+ $ post_status = 'future ' ;
656
661
} else {
657
- // If cannot schedule future items, clamp the timestamp to the current time minus
658
- // 1 second for each iteration done so far
659
- $ timestamp = min (time () - $ i , $ timestamp );
660
-
661
662
$ logger ->debug ('Date was clamped to present time ' );
663
+ $ timestamp = min (time () - $ i , $ timestamp );
662
664
}
663
665
}
664
666
} else {
665
- // Item has no date ...
667
+ // Item has no date, use the current time
666
668
$ logger ->debug ('Item "{0}" has no date. Using current time ' , [$ item ->get_title ()]);
667
669
$ timestamp = time ();
668
670
}
669
671
670
- $ date = date ( $ format , $ timestamp );
671
- $ date_gmt = gmdate ( $ format , $ item -> get_gmdate ( ' U ' ) );
672
+ $ date = date ( $ date_format , $ timestamp );
673
+ $ date_gmt = gmdate ( $ date_format , $ timestamp );
672
674
673
675
$ logger ->debug ('Date for "{0}" will be {1} ' , [$ item ->get_title (), $ date ]);
674
676
@@ -879,7 +881,7 @@ function wprss_get_feed_fetch_time_limit() {
879
881
*
880
882
* This function is used by the cron job or the debugging functions to get all feeds from all feed sources
881
883
*
882
- * @param $all If set to TRUE, the function will pull from all feed sources, regardless of their individual
884
+ * @param boolean $all If set to TRUE, the function will pull from all feed sources, regardless of their individual
883
885
* update interval. If set to FALSE, only feed sources using the global update system will be updated.
884
886
* (Optional) Default: TRUE.
885
887
* @since 3.0
@@ -966,13 +968,13 @@ function wprss_detect_exec_timeout() {
966
968
*
967
969
* @since 4.11.2
968
970
*
969
- * @param \ SimplePie_Item|mixed $item The item to validate.
971
+ * @param SimplePie_Item|mixed $item The item to validate.
970
972
*
971
- * @return \ SimplePie_Item|null The item, if it passes; otherwise, null.
973
+ * @return SimplePie_Item|null The item, if it passes; otherwise, null.
972
974
*/
973
975
function wprss_item_filter_valid ($ item )
974
976
{
975
- return $ item instanceof \ SimplePie_Item
977
+ return $ item instanceof SimplePie_Item
976
978
? $ item
977
979
: null ;
978
980
}
@@ -985,8 +987,8 @@ function wprss_item_filter_valid($item)
985
987
*
986
988
* @since 4.11.2
987
989
*
988
- * @param \ SimplePie_Item[] $items The items list.
989
- * @param \ WP_Post $feedSource The feed source, for which to sort, if any.
990
+ * @param SimplePie_Item[] $items The items list.
991
+ * @param WP_Post $feedSource The feed source, for which to sort, if any.
990
992
*/
991
993
function wprss_sort_items (&$ items , $ feedSource = null )
992
994
{
@@ -1017,8 +1019,8 @@ function wprss_sort_items(&$items, $feedSource = null)
1017
1019
*
1018
1020
* @since 4.11.2
1019
1021
*
1020
- * @param \ SimplePie_Item|mixed $itemA The item being compared;
1021
- * @param \ SimplePie_Item|mixed $itemB The item being compared to;
1022
+ * @param SimplePie_Item|mixed $itemA The item being compared;
1023
+ * @param SimplePie_Item|mixed $itemB The item being compared to;
1022
1024
* @param callable[] $comparators A list of functions for item comparison.
1023
1025
*
1024
1026
* @return int A result usable as a return value for {@see usort()}.
@@ -1050,13 +1052,13 @@ function wprss_items_sort_compare_items($itemA, $itemB, $comparators, $feedSourc
1050
1052
* @since 4.11.2
1051
1053
*
1052
1054
* @param string $key The key of the field or setting.
1053
- * @param \ WP_Post|null $feedSource The feed source, if any.
1054
- * @return type
1055
+ * @param WP_Post|null $feedSource The feed source, if any.
1056
+ * @return mixed
1055
1057
*/
1056
1058
function wprss_get_source_meta_or_setting ($ key , $ feedSource = null )
1057
1059
{
1058
1060
$ value = null ;
1059
- if ($ feedSource instanceof \ WP_Post) {
1061
+ if ($ feedSource instanceof WP_Post) {
1060
1062
$ value = $ feedSource ->{$ key };
1061
1063
}
1062
1064
@@ -1072,9 +1074,9 @@ function wprss_get_source_meta_or_setting($key, $feedSource = null)
1072
1074
*
1073
1075
* @since 4.11.2
1074
1076
*
1075
- * @param \ SimplePie_Item|mixed $itemA The first item.
1076
- * @param \ SimplePie_Item|mixed $itemB The second item.
1077
- * @param \ WP_Post|null $feedSource The feed source for which the items are being compared, if any.
1077
+ * @param SimplePie_Item|mixed $itemA The first item.
1078
+ * @param SimplePie_Item|mixed $itemB The second item.
1079
+ * @param WP_Post|null $feedSource The feed source for which the items are being compared, if any.
1078
1080
* @return int A comparison result for {@see usort()}.
1079
1081
*/
1080
1082
function wprss_item_comparator_date ($ itemA , $ itemB , $ feedSource = null )
@@ -1097,16 +1099,13 @@ function wprss_item_comparator_date($itemA, $itemB, $feedSource = null)
1097
1099
return null ;
1098
1100
}
1099
1101
return $ aDate > $ bDate ? -1 : 1 ;
1100
- break ;
1101
1102
1102
1103
case 'oldest ' :
1103
1104
return $ aDate < $ bDate ? -1 : 1 ;
1104
- break ;
1105
1105
1106
1106
case '' :
1107
1107
default :
1108
1108
return 0 ;
1109
- break ;
1110
1109
}
1111
1110
}
1112
1111
@@ -1115,7 +1114,7 @@ function wprss_item_comparator_date($itemA, $itemB, $feedSource = null)
1115
1114
*
1116
1115
* @since 4.11.2
1117
1116
*
1118
- * @param \ WP_Post|null $feedSource The feed source, for which to get comparators, if any.
1117
+ * @param WP_Post|null $feedSource The feed source, for which to get comparators, if any.
1119
1118
*
1120
1119
* @return callable[] The list of comparators.
1121
1120
*/
0 commit comments