From 6b4fe3c784e8e6fd8b77ca770e4d8b05ba371db9 Mon Sep 17 00:00:00 2001 From: Norbert Micheel Date: Wed, 17 Aug 2022 11:50:36 +0200 Subject: [PATCH] more Fixes (most in plot and simple dom) for PHP 8.1 --- CHANGELOG.md | 3 ++ lib/search_it.php | 16 +++++--- package.yml | 4 +- plugins/autocomplete/package.yml | 2 +- plugins/documentation/package.yml | 2 +- plugins/plaintext/lib/simple_html_dom.php | 36 ++++++++++------- plugins/plaintext/package.yml | 2 +- plugins/stats/images/phplot/phplot.php | 48 +++++++++++++++++------ plugins/stats/package.yml | 2 +- 9 files changed, 75 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f90b6f0..d60eb60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # Changelog +## Version 6.9.4 (2022-08-17) +- Fixes for PHP 8.1 thx @skerbis + ## Version 6.9.3 (2022-08-16) - Fix autoreindex on yform change for PHP 8.1 (#337) thx @gharlan diff --git a/lib/search_it.php b/lib/search_it.php index 451576b..3e71ccd 100644 --- a/lib/search_it.php +++ b/lib/search_it.php @@ -249,10 +249,12 @@ public function indexArticle($_id, $_clang = false) try { - if (substr(rex_addon::get('search_it')->getConfig('index_host'),0,1) == ':') { - $scanparts['port'] = trim(rex_addon::get('search_it')->getConfig('index_host'),':'); + $index_host = rex_addon::get('search_it')->getConfig('index_host'); + if (!isset($index_host)) { $index_host = ''; } + if (substr($index_host,0,1) == ':') { + $scanparts['port'] = trim($index_host,':'); } else { - $scanparts = parse_url(rex_addon::get('search_it')->getConfig('index_host')); + $scanparts = parse_url($index_host); } if(rex_addon::get("yrewrite") && rex_addon::get("yrewrite")->isAvailable() && !isset($scanparts['host'])) { @@ -421,10 +423,12 @@ public function indexURL($url_hash, $article_id, $clang_id, $profile_id, $data_i } else if (is_object($article) AND ($article->isOnline() OR rex_addon::get('search_it')->getConfig('indexoffline'))) { try { - if (substr(rex_addon::get('search_it')->getConfig('index_host'),0,1) == ':') { - $scanparts['port'] = trim(rex_addon::get('search_it')->getConfig('index_host'),':'); + $index_host = rex_addon::get('search_it')->getConfig('index_host'); + if (!isset($index_host)) { $index_host = ''; } + if (substr($index_host,0,1) == ':') { + $scanparts['port'] = trim($index_host,':'); } else { - $scanparts = parse_url(rex_addon::get('search_it')->getConfig('index_host')); + $scanparts = parse_url($index_host); } if(rex_addon::get("yrewrite") && rex_addon::get('yrewrite')->isAvailable() && !isset($scanparts['host'])) { diff --git a/package.yml b/package.yml index 543be79..f051eeb 100644 --- a/package.yml +++ b/package.yml @@ -1,5 +1,5 @@ package: search_it -version: '6.9.3' +version: '6.9.4' author: Friends Of REDAXO supportpage: https://github.com/FriendsOfREDAXO/search_it @@ -26,7 +26,7 @@ console_commands: search_it:reindex: rex_search_it_command_reindex requires: - redaxo: '^5.5.0' + redaxo: '^5.6.0' php: '>=7' system_plugins: diff --git a/plugins/autocomplete/package.yml b/plugins/autocomplete/package.yml index fed88de..571e054 100644 --- a/plugins/autocomplete/package.yml +++ b/plugins/autocomplete/package.yml @@ -1,5 +1,5 @@ package: search_it/autocomplete -version: '6.9.3' +version: '6.9.4' author: Manétage title: 'translate:search_it_autocomplete_plugin_title' diff --git a/plugins/documentation/package.yml b/plugins/documentation/package.yml index 0d088dd..288a929 100644 --- a/plugins/documentation/package.yml +++ b/plugins/documentation/package.yml @@ -1,5 +1,5 @@ package: search_it/documentation -version: '6.9.3' +version: '6.9.4' author: Friends Of REDAXO title: 'translate:search_it_documentation_title' diff --git a/plugins/plaintext/lib/simple_html_dom.php b/plugins/plaintext/lib/simple_html_dom.php index 9513d20..ebf5e55 100644 --- a/plugins/plaintext/lib/simple_html_dom.php +++ b/plugins/plaintext/lib/simple_html_dom.php @@ -11,7 +11,7 @@ Licensed under The MIT License Redistributions of files must retain the above copyright notice. -Edited by Robert Rupf: Added the remove-method, which allows to remove nodes in +Edited by Robert Rupf: Added the remove-method, which allows to remove nodes in the same way you can find them. Edited by Norbert Micheel: adapted the regex pattern for pcre2 PHP 7.3 in function parse_selector @@ -116,7 +116,7 @@ function clear() { $this->parent = null; $this->children = null; } - + // dump node's tree function dump($show_attr=true) { dump_html_tree($this, $show_attr); @@ -146,7 +146,7 @@ function last_child() { return null; } - // returns the next sibling of node + // returns the next sibling of node function next_sibling() { if ($this->parent===null) return null; $idx = 0; @@ -223,7 +223,7 @@ function text() { $ret .= $n->text().' '; return $ret; } - + function xmltext() { $ret = $this->innertext(); $ret = str_ireplace('dom->lowercase) {$tag=strtolower($tag); $key=strtolower($key);} + if ($this->dom->lowercase) { + $tag = is_null($tag) ? '' : strtolower($tag); + $key = is_null($key) ? '' : strtolower($key); + } //elements that do NOT have the specified attribute if (isset($key[0]) && $key[0]==='!') {$key=substr($key, 1); $no_key=true;} @@ -445,7 +448,7 @@ function __set($name, $value) { return $this->_[HDOM_INFO_INNER] = $value; } if (!isset($this->attr[$name])) { - $this->_[HDOM_INFO_SPACE][] = array(' ', '', ''); + $this->_[HDOM_INFO_SPACE][] = array(' ', '', ''); $this->_[HDOM_INFO_QUOTE][] = HDOM_QUOTE_DOUBLE; } $this->attr[$name] = $value; @@ -482,8 +485,8 @@ function firstChild() {return $this->first_child();} function lastChild() {return $this->last_child();} function nextSibling() {return $this->next_sibling();} function previousSibling() {return $this->prev_sibling();} - - + + // Added by Robert Rupf // remove elements by css selector function remove($selector) { @@ -555,11 +558,11 @@ class simple_html_dom { 'p'=>array('p'=>1), 'nobr'=>array('nobr'=>1), ); - + function __construct($str=null) { if ($str) { - if (preg_match("/^http:\/\//i",$str) || is_file($str)) - $this->load_file($str); + if (preg_match("/^http:\/\//i",$str) || is_file($str)) + $this->load_file($str); else $this->load($str); } @@ -632,7 +635,7 @@ function clear() { unset($this->doc); unset($this->noise); } - + function dump($show_attr=true) { $this->root->dump($show_attr); } @@ -907,11 +910,13 @@ function dump($show_attr=true) { } /*protected*/ function skip($chars) { + if (!isset($chars)) { $chars = ''; } $this->pos += strspn($this->doc, $chars, $this->pos); $this->char = ($this->pos<$this->size) ? $this->doc[$this->pos] : null; // next } /*protected*/ function copy_skip($chars) { + if (!isset($chars)) { $chars = ''; } $pos = $this->pos; $len = strspn($this->doc, $chars, $pos); $this->pos += $len; @@ -921,6 +926,7 @@ function dump($show_attr=true) { } /*protected*/ function copy_until($chars) { + if (!isset($chars)) { $chars = ''; } $pos = $this->pos; $len = strcspn($this->doc, $chars, $pos); $this->pos += $len; @@ -1018,8 +1024,8 @@ function getElementsById($id, $idx=null) {return $this->find("#$id", $idx);} function getElementByTagName($name) {return $this->find($name, 0);} function getElementsByTagName($name, $idx=-1) {return $this->find($name, $idx);} function loadFile() {$args = func_get_args();$this->load(call_user_func_array('file_get_contents', $args), true);} - - + + // Added by Robert Rupf // remove dom node by css selector function remove($selector) { diff --git a/plugins/plaintext/package.yml b/plugins/plaintext/package.yml index 9023cdc..adf0d7b 100644 --- a/plugins/plaintext/package.yml +++ b/plugins/plaintext/package.yml @@ -1,5 +1,5 @@ package: search_it/plaintext -version: '6.9.3' +version: '6.9.4' author: Friends Of REDAXO title: 'translate:search_it_plaintext_title' diff --git a/plugins/stats/images/phplot/phplot.php b/plugins/stats/images/phplot/phplot.php index ddfc00e..1996073 100644 --- a/plugins/stats/images/phplot/phplot.php +++ b/plugins/stats/images/phplot/phplot.php @@ -6826,8 +6826,8 @@ protected function DrawLegend() $this->DrawText('legend', 0, $x_pos, $yc, $this->ndx_legend_text_color, $leg, $this->legend_text_align, 'center'); if ($colorbox_mode) { - $y1 = $y_pos - $dot_height + 1; - $y2 = $y_pos - 1; + $y1 = floor($y_pos - $dot_height) + 1; + $y2 = floor($y_pos) - 1; // If plot area background is on, draw a background for any non-box shapes: if ($this->draw_plot_area_background && $colorbox_mode != 'box') { @@ -7004,6 +7004,26 @@ protected function GetGridSetting($xy) return isset($this->draw_y_grid) ? $this->draw_y_grid : !$this->datatype_swapped_xy; } + /** + * @param GdImage|resource $image + * @param array $points + * @param int $numPoints + * @param int $color + * @return void + */ + protected function imageFilledPolygonWrapper( + $image, + array $points, + $numPoints, + $color + ) { + if (version_compare(PHP_VERSION, '8.1.0') === -1) { + imagefilledpolygon($image, $points, $numPoints, $color); + } else { + imagefilledpolygon($image, $points, $color); + } + } + /** * Draws a single marker shape (a dot or shape) * @@ -7054,23 +7074,23 @@ protected function DrawShape($x, $y, $record, $color, $allow_none = TRUE) break; case 'diamond': $arrpoints = array($x1, $y, $x, $y1, $x2, $y, $x, $y2); - ImageFilledPolygon($this->img, $arrpoints, 4, $color); + $this->imageFilledPolygonWrapper($this->img, $arrpoints, 4, $color); break; case 'triangle': $arrpoints = array($x1, $y, $x2, $y, $x, $y2); - ImageFilledPolygon($this->img, $arrpoints, 3, $color); + $this->imageFilledPolygonWrapper($this->img, $arrpoints, 3, $color); break; case 'trianglemid': $arrpoints = array($x1, $y1, $x2, $y1, $x, $y); - ImageFilledPolygon($this->img, $arrpoints, 3, $color); + $this->imageFilledPolygonWrapper($this->img, $arrpoints, 3, $color); break; case 'yield': $arrpoints = array($x1, $y1, $x2, $y1, $x, $y2); - ImageFilledPolygon($this->img, $arrpoints, 3, $color); + $this->imageFilledPolygonWrapper($this->img, $arrpoints, 3, $color); break; case 'delta': $arrpoints = array($x1, $y2, $x2, $y2, $x, $y1); - ImageFilledPolygon($this->img, $arrpoints, 3, $color); + $this->imageFilledPolygonWrapper($this->img, $arrpoints, 3, $color); break; case 'star': ImageLine($this->img, $x1, $y, $x2, $y, $color); @@ -7080,11 +7100,11 @@ protected function DrawShape($x, $y, $record, $color, $allow_none = TRUE) break; case 'hourglass': $arrpoints = array($x1, $y1, $x2, $y1, $x1, $y2, $x2, $y2); - ImageFilledPolygon($this->img, $arrpoints, 4, $color); + $this->imageFilledPolygonWrapper($this->img, $arrpoints, 4, $color); break; case 'bowtie': $arrpoints = array($x1, $y1, $x1, $y2, $x2, $y1, $x2, $y2); - ImageFilledPolygon($this->img, $arrpoints, 4, $color); + $this->imageFilledPolygonWrapper($this->img, $arrpoints, 4, $color); break; case 'target': ImageFilledRectangle($this->img, $x1, $y1, $x, $y, $color); @@ -7096,7 +7116,7 @@ protected function DrawShape($x, $y, $record, $color, $allow_none = TRUE) break; case 'home': /* As in: "home plate" (baseball), also looks sort of like a house. */ $arrpoints = array($x1, $y2, $x2, $y2, $x2, $y, $x, $y1, $x1, $y); - ImageFilledPolygon($this->img, $arrpoints, 5, $color); + $this->imageFilledPolygonWrapper($this->img, $arrpoints, 5, $color); break; case 'up': ImagePolygon($this->img, array($x, $y1, $x2, $y2, $x1, $y2), 3, $color); @@ -7155,6 +7175,8 @@ protected function DrawDot($row, $column, $x_world, $y_world, $color) protected function DrawBar($row, $column, $x1, $y1, $x2, $y2, $data_color, $shade_color, $border_color, $shade_top = TRUE, $shade_side = TRUE) { + $x1 = floor($x1); $x2 = floor($x2); + $y1 = floor($y1); $y2 = floor($y2); // Sort the points so x1,y1 is upper left and x2,y2 is lower right. This // is needed in order to get the shading right, and imagerectangle may require it. if ($x1 > $x2) { @@ -7178,7 +7200,7 @@ protected function DrawBar($row, $column, $x1, $y1, $x2, $y2, $data_color, $shad } else { // Suppress top shading (Note shade_top==FALSE && shade_side==FALSE is not allowed) $pts = array($x2, $y2, $x2, $y1, $x2 + $shade, $y1 - $shade, $x2 + $shade, $y2 - $shade); } - ImageFilledPolygon($this->img, $pts, count($pts) / 2, $shade_color); + $this->imageFilledPolygonWrapper($this->img, $pts, count($pts) / 2, $shade_color); } // Draw a border around the bar, if enabled. @@ -7853,7 +7875,7 @@ protected function DrawArea($do_stacked = FALSE) array_push($pts, $xd[$row], $yd[$row][$col]); } // Draw it: - ImageFilledPolygon($this->img, $pts, $n_rows * 2, $this->ndx_data_colors[$prev_col]); + $this->imageFilledPolygonWrapper($this->img, $pts, $n_rows * 2, $this->ndx_data_colors[$prev_col]); $prev_col = $col; } @@ -8148,7 +8170,7 @@ protected function DrawSquaredArea($do_stacked = FALSE) } // Draw the resulting polygon, which has (2 * (1 + 2*(n_rows-1))) points: - ImageFilledPolygon($this->img, $pts, 4 * $n_rows - 2, $this->ndx_data_colors[$prev_col]); + $this->imageFilledPolygonWrapper($this->img, $pts, 4 * $n_rows - 2, $this->ndx_data_colors[$prev_col]); $prev_col = $col; } diff --git a/plugins/stats/package.yml b/plugins/stats/package.yml index bda3dd6..09d9a23 100644 --- a/plugins/stats/package.yml +++ b/plugins/stats/package.yml @@ -1,5 +1,5 @@ package: search_it/stats -version: '6.9.3' +version: '6.9.4' author: Friends Of REDAXO title: 'translate:search_it_stats_plugin_title'