From 2460c7c66f72a2cacff258b3e5223e84d296884c Mon Sep 17 00:00:00 2001 From: Stephen Hartley Date: Thu, 10 Apr 2025 14:57:54 +0100 Subject: [PATCH] Fixed null, dynamic properties deprecation warnings, implicit conversion from float warning, --- categories-page.php | 1 + feedfinder.class.php | 9 ++++++++- feedwordpressparsedpostmeta.class.php | 2 ++ magpiefromsimplepie.class.php | 9 +++++++-- posts-page.php | 3 ++- syndicatedlink.class.php | 2 +- syndicatedpost.class.php | 18 ++++++++++-------- syndicatedpostterm.class.php | 2 +- syndicatedpostxpathquery.class.php | 24 ++++++++++++++---------- template-functions.php | 4 +++- 10 files changed, 49 insertions(+), 25 deletions(-) diff --git a/categories-page.php b/categories-page.php index b65bd98..fa202b6 100644 --- a/categories-page.php +++ b/categories-page.php @@ -1,6 +1,7 @@ data($uri); + if (is_null($data)) { + return false; + } + return ( preg_match ( "\007(".implode('|',$this->_feed_markers).")\007i", @@ -269,7 +273,10 @@ function _link_rel_feeds () { $href = array (); for ($n=0; $n<$link_count; $n++) { if (strtolower($links[$n]['rel']) == 'alternate') { - if (in_array(strtolower($links[$n]['type']), $this->_feed_types)) { + if (isset($links[$n]['type']) + && !is_null($links[$n]['type']) + && in_array(strtolower($links[$n]['type']), $this->_feed_types) + ) { $href[] = $links[$n]['href']; } /* if */ } /* if */ diff --git a/feedwordpressparsedpostmeta.class.php b/feedwordpressparsedpostmeta.class.php index d9cd1f5..6d98f54 100644 --- a/feedwordpressparsedpostmeta.class.php +++ b/feedwordpressparsedpostmeta.class.php @@ -1,4 +1,6 @@ is_rss() ) : - $source["{$cat_id}@term"] = $source[$cat_id]; + $source["{$cat_id}@term"] = isset($source[$cat_id]) + ? $source[$cat_id] + : null; // Avoid PHP notice nastygrams - the source key is probably missing because was a self-closing or empty node endif; if ( isset($source["{$cat_id}@scheme"]) ) : // URI to taxonomy @@ -682,7 +685,9 @@ function normalize_category (&$source, $from, &$dest, $to, $i) { endif; // Now put the identifier into dc:subject - $dest[$dc_id] = $source[$cat_id]; + $dest[$dc_id] = isset($source[$cat_id]) + ? $source[$cat_id] + : null; // Avoid PHP notice nastygrams - the source key is probably missing because was a self-closing or empty node } /* MagpieFromSimplePie::normalize_category */ /** diff --git a/posts-page.php b/posts-page.php index 27f11f9..ed7b026 100644 --- a/posts-page.php +++ b/posts-page.php @@ -2,6 +2,7 @@ require_once(dirname(__FILE__) . '/admin-ui.php'); require_once(dirname(__FILE__) . '/updatedpostscontrol.class.php'); +#[\AllowDynamicProperties] class FeedWordPressPostsPage extends FeedWordPressAdminPage { var $link = NULL; var $updatedPosts = NULL; @@ -224,7 +225,7 @@ function formatting_box( $page, $box = NULL ) { if ($page->for_feed_settings()) : $formatting_filters = null; - $url = preg_replace('|/+$|', '', $page->link->homepage()); + $url = preg_replace('|/+$|', '', $page->link->homepage() ?? ''); else : $formatting_filters = get_option('feedwordpress_formatting_filters', 'no'); $url = 'http://example.com'; diff --git a/syndicatedlink.class.php b/syndicatedlink.class.php index 074ed94..d8f9c01 100644 --- a/syndicatedlink.class.php +++ b/syndicatedlink.class.php @@ -1113,7 +1113,7 @@ public function automatic_ttl() { // We get a fudge of 1/3 of window from elsewhere. We'll do some more // fudging here. - $fudgedInterval = $updateWindow + rand( - ( $updateWindow / 6 ), 5 * ( $updateWindow / 12 ) ); + $fudgedInterval = $updateWindow + rand( (int) - ( $updateWindow / 6 ), (int) (5 * ( $updateWindow / 12 )) ); return apply_filters( 'syndicated_feed_automatic_ttl', $fudgedInterval, $this ); } /* SyndicatedLink::automatic_ttl() */ diff --git a/syndicatedpost.class.php b/syndicatedpost.class.php index 6548aef..cb40d6b 100644 --- a/syndicatedpost.class.php +++ b/syndicatedpost.class.php @@ -413,13 +413,13 @@ public function content ($params = array()) public function excerpt () { # Identify and sanitize excerpt: atom:summary, or rss:description - $excerpt = $this->entry->get_description(); + $excerpt = $this->entry->get_description() ?? ''; # Many RSS feeds use rss:description, inadvisably, to # carry the entire post (typically with escaped HTML). # If that's what happened, we don't want the full # content for the excerpt. - $content = $this->content(); + $content = $this->content() ?? ''; // Ignore whitespace, case, and tag cruft. $theExcerpt = preg_replace('/\s+/', '', strtolower(strip_tags(html_entity_decode($excerpt)))); @@ -909,7 +909,7 @@ public function get_terms_from_feeds () { */ function inline_tags () { $tags = array(); - $content = $this->content(); + $content = $this->content() ?? ''; $pattern = FeedWordPressHTML::tagWithAttributeRegex('a', 'rel', 'tag'); preg_match_all($pattern, $content, $refs, PREG_SET_ORDER); if (is_countable($refs) and count($refs) > 0) : @@ -1168,11 +1168,13 @@ static function resolve_relative_uris ($content, $obj) { // Relying on preg_replace_callback() here can cause a PHP seg fault on my development // server. preg_match_all() causes a similar problem. Apparently this is a PCRE issue // Cf. discussion of similar issue - $content = preg_replace_callback ( - $pattern, - array($obj, 'resolve_single_relative_uri'), - $content - ); + $content = is_null($content) + ? '' + : preg_replace_callback ( + $pattern, + array($obj, 'resolve_single_relative_uri'), + $content + ); endforeach; endif; diff --git a/syndicatedpostterm.class.php b/syndicatedpostterm.class.php index 19b8e01..84489b4 100644 --- a/syndicatedpostterm.class.php +++ b/syndicatedpostterm.class.php @@ -127,7 +127,7 @@ public function is_forbidden_in ($tax = NULL) { $tax = $this->tax[0]; endif; - if ($tax=='category' and strtolower($term)=='uncategorized') : + if ($tax=='category' and !is_null($term) && strtolower($term)=='uncategorized') : $forbid = true; endif; diff --git a/syndicatedpostxpathquery.class.php b/syndicatedpostxpathquery.class.php index 5145b30..7a4f5bd 100644 --- a/syndicatedpostxpathquery.class.php +++ b/syndicatedpostxpathquery.class.php @@ -53,16 +53,20 @@ public function setPath ($path) { $this->urlHash = array(); $this->path = $path; - - // Allow {url} notation for namespaces. URLs will contain : and /, so... - preg_match_all('/{([^}]+)}/', $path, $match, PREG_SET_ORDER); - foreach ($match as $ref) : - $this->urlHash[md5($ref[1])] = $ref[1]; - endforeach; - - foreach ($this->urlHash as $hash => $url) : - $path = str_replace('{'.$url.'}', '{#'.$hash.'}', $path); - endforeach; + + if (is_string($path)) { + // got a non-string path, probably a place marker e.g. `category[1]`, so for now just don't give a warning, but should be fixed by not trying to set the path of an array! + + // Allow {url} notation for namespaces. URLs will contain : and /, so... + preg_match_all('/{([^}]+)}/', $path, $match, PREG_SET_ORDER); + foreach ($match as $ref) : + $this->urlHash[md5($ref[1])] = $ref[1]; + endforeach; + + foreach ($this->urlHash as $hash => $url) : + $path = str_replace('{'.$url.'}', '{#'.$hash.'}', $path); + endforeach; + } $path = $this->parsePath(/*cur=*/ $path, /*orig=*/ $path); diff --git a/template-functions.php b/template-functions.php index 9168ae7..973a939 100644 --- a/template-functions.php +++ b/template-functions.php @@ -29,7 +29,9 @@ function is_syndicated ($id = NULL) { * @return string containing an abbreviated display form of the URL (e.g.: `feedwordpress.radgeek.net/feed`) */ function feedwordpress_display_url ($url, $before = 60, $after = 0) { - $bits = parse_url($url); + $bits = is_null($url) + ? [] + : parse_url($url); // Strip out crufty subdomains if (isset($bits['host'])) :