Skip to content

Commit 744c953

Browse files
committed
Merge branch 'develop'
2 parents 63dc7b8 + a00bf96 commit 744c953

20 files changed

+146
-246
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [4.21] - 2022-07-13
8+
### Change
9+
* Updated Twig to v1.42.2, to support PHP 8 or later.
10+
* Optimized feed item date processing when an item is being imported.
11+
* Permalink and GUID checks are now done across all feed sources when an item is being imported.
12+
13+
### Fixed
14+
* Various PHP 8 errors and deprecations compatibility.
15+
* The classic editor button was generating incorrect shortcodes.
16+
717
## [4.20] - 2022-01-18
818
### Added
919
* New option to use feed item GUIDs instead of permalinks to detect duplicate items.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"ext-curl": "*",
1717
"ext-simplexml": "*",
1818
"psr/log": "^1.1",
19-
"twig/twig": "1.41.0 | ^2.10",
19+
"twig/twig": "^1.0 | ^2.10",
2020
"twig/extensions": "^1.5.4",
2121
"dhii/di": "^0.1.1",
2222
"dhii/di-abstract": "^0.1",

composer.lock

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/admin-editor.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,23 @@ function wprss_return_dialog_contents()
8282
'posts_per_page' => -1,
8383
'no_found_rows' => true,
8484
]);
85-
$feed_sources_names = [];
85+
$feed_sources_by_id = [];
86+
$feed_sources_by_slug = [];
8687
foreach ($feed_sources as $source) {
87-
$feed_sources_names[$source->ID] = $source->post_title;
88+
$feed_sources_by_id[$source->ID] = $source->post_title;
89+
$feed_sources_by_slug[$source->post_name] = $source->post_title;
8890
}
8991
$feed_sources_select = wprss_settings_render_select(
9092
'wprss-dialog-feed-source-list',
9193
'',
92-
$feed_sources_names,
94+
$feed_sources_by_slug,
9395
'',
9496
['multiple' => 'multiple', 'class' => 'widefat']
9597
);
9698
$feed_sources_exclude_select = wprss_settings_render_select(
9799
'wprss-dialog-exclude-list',
98100
'',
99-
$feed_sources_names,
101+
$feed_sources_by_id,
100102
'',
101103
['multiple' => 'multiple', 'class' => 'widefat']
102104
);

includes/admin-options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ function wprss_settings_render_select($id, $name, $items, $selected = null, $att
785785
$_item = (string) $_item;
786786

787787
$html .= sprintf(
788-
'<option name="%s" %s>%s</option>',
788+
'<option value="%s" %s>%s</option>',
789789
esc_attr($_key),
790790
selected($selected, $_key, false),
791791
esc_html($_item)

includes/feed-importing.php

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ function wprss_fetch_insert_single_feed_items( $feed_ID ) {
112112
$useGuids = get_post_meta($feed_ID, 'wprss_use_guids', true);
113113
$useGuids = filter_var($useGuids, FILTER_VALIDATE_BOOLEAN);
114114
$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();
117117

118118
// Generate a list of items fetched, that are not already in the DB
119119
$new_items = array();
@@ -527,8 +527,8 @@ function wprss_tracking_url_fix( $permalink, $patterns, $argName = 'url' ) {
527527
* into embedded video player urls.
528528
* If the permalink is not a video url, the permalink is returned as is.
529529
*
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
532532
* not a video url.
533533
* @since 4.0
534534
*/
@@ -550,8 +550,8 @@ function wprss_convert_video_permalink( $permalink ) {
550550
$host = $matches[2];
551551
switch( $host ) {
552552
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];
555555
break;
556556
case 'vimeo':
557557
preg_match( '/(\d*)$/i', $permalink, $vim_matches );
@@ -584,6 +584,16 @@ function wprss_items_insert_post( $items, $feed_ID ) {
584584
// Count of items inserted
585585
$items_inserted = 0;
586586

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+
587597
foreach ( $items as $i => $item ) {
588598
$permalink = $item->get_permalink();
589599
$permalink = wprss_normalize_permalink($permalink, $item, $feed_ID);
@@ -624,51 +634,43 @@ function wprss_items_insert_post( $items, $feed_ID ) {
624634
$item = apply_filters( 'wprss_insert_post_item_conditionals', $item, $feed_ID, $permalink );
625635
/* @var $item SimplePie_Item */
626636

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-
630637
// If the item is not NULL, continue to inserting the feed item post into the DB
631638
if ( $item !== NULL && !is_bool($item) ) {
632639
$logger->debug('Resuming insertion into DB');
633640

634641
$post_status = 'publish';
635642

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
638644
$timestamp = $item->get_date( 'U' );
639-
$has_date = $timestamp ? true : false;
645+
$has_date = !empty($timestamp);
640646

641647
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)]);
643649

644650
if ($timestamp > time()) {
645651
// Item has a future timestamp ...
646652
$logger->debug('Item "{0}" has a future date', [$item->get_title()]);
647653

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) {
655659
$logger->debug('Setting future status');
660+
$post_status = 'future';
656661
} 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-
661662
$logger->debug('Date was clamped to present time');
663+
$timestamp = min(time() - $i, $timestamp);
662664
}
663665
}
664666
} else {
665-
// Item has no date ...
667+
// Item has no date, use the current time
666668
$logger->debug('Item "{0}" has no date. Using current time', [$item->get_title()]);
667669
$timestamp = time();
668670
}
669671

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 );
672674

673675
$logger->debug('Date for "{0}" will be {1}', [$item->get_title(), $date]);
674676

@@ -879,7 +881,7 @@ function wprss_get_feed_fetch_time_limit() {
879881
*
880882
* This function is used by the cron job or the debugging functions to get all feeds from all feed sources
881883
*
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
883885
* update interval. If set to FALSE, only feed sources using the global update system will be updated.
884886
* (Optional) Default: TRUE.
885887
* @since 3.0
@@ -966,13 +968,13 @@ function wprss_detect_exec_timeout() {
966968
*
967969
* @since 4.11.2
968970
*
969-
* @param \SimplePie_Item|mixed $item The item to validate.
971+
* @param SimplePie_Item|mixed $item The item to validate.
970972
*
971-
* @return \SimplePie_Item|null The item, if it passes; otherwise, null.
973+
* @return SimplePie_Item|null The item, if it passes; otherwise, null.
972974
*/
973975
function wprss_item_filter_valid($item)
974976
{
975-
return $item instanceof \SimplePie_Item
977+
return $item instanceof SimplePie_Item
976978
? $item
977979
: null;
978980
}
@@ -985,8 +987,8 @@ function wprss_item_filter_valid($item)
985987
*
986988
* @since 4.11.2
987989
*
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.
990992
*/
991993
function wprss_sort_items(&$items, $feedSource = null)
992994
{
@@ -1017,8 +1019,8 @@ function wprss_sort_items(&$items, $feedSource = null)
10171019
*
10181020
* @since 4.11.2
10191021
*
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;
10221024
* @param callable[] $comparators A list of functions for item comparison.
10231025
*
10241026
* @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
10501052
* @since 4.11.2
10511053
*
10521054
* @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
10551057
*/
10561058
function wprss_get_source_meta_or_setting($key, $feedSource = null)
10571059
{
10581060
$value = null;
1059-
if ($feedSource instanceof \WP_Post) {
1061+
if ($feedSource instanceof WP_Post) {
10601062
$value = $feedSource->{$key};
10611063
}
10621064

@@ -1072,9 +1074,9 @@ function wprss_get_source_meta_or_setting($key, $feedSource = null)
10721074
*
10731075
* @since 4.11.2
10741076
*
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.
10781080
* @return int A comparison result for {@see usort()}.
10791081
*/
10801082
function wprss_item_comparator_date($itemA, $itemB, $feedSource = null)
@@ -1097,16 +1099,13 @@ function wprss_item_comparator_date($itemA, $itemB, $feedSource = null)
10971099
return null;
10981100
}
10991101
return $aDate > $bDate ? -1 : 1;
1100-
break;
11011102

11021103
case 'oldest':
11031104
return $aDate < $bDate ? -1 : 1;
1104-
break;
11051105

11061106
case '':
11071107
default:
11081108
return 0;
1109-
break;
11101109
}
11111110
}
11121111

@@ -1115,7 +1114,7 @@ function wprss_item_comparator_date($itemA, $itemB, $feedSource = null)
11151114
*
11161115
* @since 4.11.2
11171116
*
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.
11191118
*
11201119
* @return callable[] The list of comparators.
11211120
*/

0 commit comments

Comments
 (0)