From 188fe9e7d80c213d1684e6ffc20a3edc080aeb5c Mon Sep 17 00:00:00 2001 From: Jonathan Stegall Date: Tue, 5 Jan 2021 14:05:34 -0600 Subject: [PATCH 1/7] Fix PHP 7.4 warnings/notices --- common/lib/markdown.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/common/lib/markdown.php b/common/lib/markdown.php index 1e81fce..90881d8 100644 --- a/common/lib/markdown.php +++ b/common/lib/markdown.php @@ -786,7 +786,7 @@ function _doHeaders_callback_setext( $matches ) { if ( $matches[2] == '-' && preg_match( '{^-(?: |$)}', $matches[1] ) ) return $matches[0]; - $level = $matches[2]{0} == '=' ? 1 : 2; + $level = $matches[2][0] == '=' ? 1 : 2; $block = "".$this->runSpanGamut( $matches[1] ).""; return "\n" . $this->hashBlock( $block ) . "\n\n"; } @@ -1081,7 +1081,7 @@ function doItalicsAndBold( $text ) { } else { // Other closing marker: close one em or strong and // change current token state to match the other - $token_stack[0] = str_repeat( $token{0}, 3-$token_len ); + $token_stack[0] = str_repeat($token[0], 3-$token_len); $tag = $token_len == 2 ? "strong" : "em"; $span = $text_stack[0]; $span = $this->runSpanGamut( $span ); @@ -1106,7 +1106,7 @@ function doItalicsAndBold( $text ) { } else { // Reached opening three-char emphasis marker. Push on token // stack; will be handled by the special condition above. - $em = $token{0}; + $em = $token[0]; $strong = "$em$em"; array_unshift( $token_stack, $token ); array_unshift( $text_stack, '' ); @@ -1435,9 +1435,9 @@ function handleSpanToken( $token, &$str ) { // Handle $token provided by parseSpan by determining its nature and // returning the corresponding value that should replace it. // - switch ( $token{0} ) { + switch ($token[0]) { case "\\": - return $this->hashPart( "&#". ord( $token{1} ). ";" ); + return $this->hashPart("&#". ord($token[1]). ";"); case "`": // Search for end marker in remaining text. if ( preg_match( '/^(.*?[^`])'.preg_quote( $token ).'(?!`)(.*)$/sm', @@ -1503,12 +1503,15 @@ function _initDetab() { // regular expression. // if ( function_exists( $this->utf8_strlen ) ) return; - $this->utf8_strlen = function( $text ) { + $this->utf8_strlen = function ($text) { return preg_match_all( - "/[\\\\x00-\\\\xBF]|[\\\\xC0-\\\\xFF][\\\\x80-\\\\xBF]*/", $text, $m ); + "/[\\x00-\\xBF]|[\\xC0-\\xFF][\\x80-\\xBF]*/", + $text, $m + ); }; } + function unhash( $text ) { // // Swap back in all the tags hashed by _HashHTMLBlocks. From 7fbdc4809da36c608860fcd9166664371e65fe90 Mon Sep 17 00:00:00 2001 From: Jonathan Stegall Date: Tue, 5 Jan 2021 14:37:45 -0600 Subject: [PATCH 2/7] more curly brace syntax to remove --- common/lib/markdown.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/lib/markdown.php b/common/lib/markdown.php index 90881d8..114f76d 100644 --- a/common/lib/markdown.php +++ b/common/lib/markdown.php @@ -1785,7 +1785,7 @@ function _hashHTMLBlocks_inMarkdown( $text, $indent = 0, // // Check for: Code span marker // - if ( $tag{0} == "`" ) { + if ( $tag[0] == "`" ) { // Find corresponding end marker. $tag_re = preg_quote( $tag ); if ( preg_match( '{^(?>.+?|\n(?!\n))*?(?_doHeaders_attr( $id =& $matches[2] ); $block = "".$this->runSpanGamut( $matches[1] ).""; return "\n" . $this->hashBlock( $block ) . "\n\n"; From e249f8ea9aec79b4b78f817dd2757a307a5a20a3 Mon Sep 17 00:00:00 2001 From: Jonathan Stegall Date: Tue, 5 Jan 2021 14:39:35 -0600 Subject: [PATCH 3/7] should be the last of the curly array syntax --- common/lib/markdown.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/lib/markdown.php b/common/lib/markdown.php index 114f76d..f86e709 100644 --- a/common/lib/markdown.php +++ b/common/lib/markdown.php @@ -1846,7 +1846,7 @@ function _hashHTMLBlocks_inMarkdown( $text, $indent = 0, // HTML Comments, processing instructions. // else if ( preg_match( '{^<(?:'.$this->clean_tags_re.')\b}', $tag ) || - $tag{1} == '!' || $tag{1} == '?' ) { + $tag[1] == '!' || $tag[1] == '?' ) { // Need to parse tag and following text using the HTML parser. // (don't check for markdown attribute) list( $block_text, $text ) = @@ -1863,7 +1863,7 @@ function _hashHTMLBlocks_inMarkdown( $text, $indent = 0, // // Increase/decrease nested tag count. // - if ( $tag{1} == '/' ) $depth--; + if ( $tag[1] == '/' ) $depth--; else if ( $tag{strlen( $tag )-2} != '/' ) $depth++; if ( $depth < 0 ) { @@ -1980,7 +1980,7 @@ function _hashHTMLBlocks_inHTML( $text, $hash_method, $md_attr ) { // Comments and Processing Instructions. // if ( preg_match( '{^auto_close_tags_re.')\b}', $tag ) || - $tag{1} == '!' || $tag{1} == '?' ) { + $tag[1] == '!' || $tag[1] == '?' ) { // Just add the tag to the block as if it was text. $block_text .= $tag; } @@ -1990,7 +1990,7 @@ function _hashHTMLBlocks_inHTML( $text, $hash_method, $md_attr ) { // the tag's name match base tag's. // if ( preg_match( '{^ Date: Tue, 5 Jan 2021 14:42:15 -0600 Subject: [PATCH 4/7] curly array syntax --- common/lib/markdown.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/lib/markdown.php b/common/lib/markdown.php index f86e709..87e6f4d 100644 --- a/common/lib/markdown.php +++ b/common/lib/markdown.php @@ -1864,7 +1864,7 @@ function _hashHTMLBlocks_inMarkdown( $text, $indent = 0, // Increase/decrease nested tag count. // if ( $tag[1] == '/' ) $depth--; - else if ( $tag{strlen( $tag )-2} != '/' ) $depth++; + else if ( $tag[strlen( $tag )-2] != '/' ) $depth++; if ( $depth < 0 ) { // @@ -1991,7 +1991,7 @@ function _hashHTMLBlocks_inHTML( $text, $hash_method, $md_attr ) { // if ( preg_match( '{^ Date: Tue, 5 Jan 2021 14:46:38 -0600 Subject: [PATCH 5/7] don't make the spacing worse --- common/lib/markdown.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/lib/markdown.php b/common/lib/markdown.php index 87e6f4d..1442801 100644 --- a/common/lib/markdown.php +++ b/common/lib/markdown.php @@ -1081,7 +1081,7 @@ function doItalicsAndBold( $text ) { } else { // Other closing marker: close one em or strong and // change current token state to match the other - $token_stack[0] = str_repeat($token[0], 3-$token_len); + $token_stack[0] = str_repeat( $token[0], 3-$token_len ); $tag = $token_len == 2 ? "strong" : "em"; $span = $text_stack[0]; $span = $this->runSpanGamut( $span ); @@ -1435,9 +1435,9 @@ function handleSpanToken( $token, &$str ) { // Handle $token provided by parseSpan by determining its nature and // returning the corresponding value that should replace it. // - switch ($token[0]) { + switch ( $token[0] ) { case "\\": - return $this->hashPart("&#". ord($token[1]). ";"); + return $this->hashPart( "&#". ord($token[1]). ";" ); case "`": // Search for end marker in remaining text. if ( preg_match( '/^(.*?[^`])'.preg_quote( $token ).'(?!`)(.*)$/sm', @@ -1503,7 +1503,7 @@ function _initDetab() { // regular expression. // if ( function_exists( $this->utf8_strlen ) ) return; - $this->utf8_strlen = function ($text) { + $this->utf8_strlen = function ( $text ) { return preg_match_all( "/[\\x00-\\xBF]|[\\xC0-\\xFF][\\x80-\\xBF]*/", $text, $m From dd370fc428c4da5d7fd0ffd4088727e2c226c09d Mon Sep 17 00:00:00 2001 From: Jonathan Stegall Date: Tue, 5 Jan 2021 14:48:19 -0600 Subject: [PATCH 6/7] spacing --- common/lib/markdown.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/lib/markdown.php b/common/lib/markdown.php index 1442801..ed1146b 100644 --- a/common/lib/markdown.php +++ b/common/lib/markdown.php @@ -1437,7 +1437,7 @@ function handleSpanToken( $token, &$str ) { // switch ( $token[0] ) { case "\\": - return $this->hashPart( "&#". ord($token[1]). ";" ); + return $this->hashPart( "&#". ord( $token[1] ). ";" ); case "`": // Search for end marker in remaining text. if ( preg_match( '/^(.*?[^`])'.preg_quote( $token ).'(?!`)(.*)$/sm', @@ -1503,7 +1503,7 @@ function _initDetab() { // regular expression. // if ( function_exists( $this->utf8_strlen ) ) return; - $this->utf8_strlen = function ( $text ) { + $this->utf8_strlen = function( $text ) { return preg_match_all( "/[\\x00-\\xBF]|[\\xC0-\\xFF][\\x80-\\xBF]*/", $text, $m From 14fb88df793d83864477fcb7ecc64e3571d259c9 Mon Sep 17 00:00:00 2001 From: Jonathan Stegall Date: Tue, 20 Apr 2021 10:45:13 -0500 Subject: [PATCH 7/7] get_matching_ad_code can return an empty value, which now causes PHP errors later in this method --- ad-code-manager.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ad-code-manager.php b/ad-code-manager.php index 1f5f2e1..a09eda4 100644 --- a/ad-code-manager.php +++ b/ad-code-manager.php @@ -849,6 +849,11 @@ function action_acm_tag( $tag_id, $echo = true ) { return; $code_to_display = $this->get_matching_ad_code( $tag_id ); + + // get_matching_ad_code can return an empty value. + if ( empty( $code_to_display ) ) { + return; + } // Run $url aganist a whitelist to make sure it's a safe URL if ( !$this->validate_script_url( $code_to_display['url'] ) )