From 492993e78e82a8dae4c8d0acae24faf1d567fe7f Mon Sep 17 00:00:00 2001 From: nathan Date: Wed, 7 Jun 2023 13:50:08 -0600 Subject: [PATCH] Avoid some PHP warnings - Undefined array keys - Undefined class variables - Passing null to string functions --- api/src/Etemplate/Widget/Date.php | 2 +- api/src/Etemplate/Widget/Grid.php | 4 ++-- api/src/Etemplate/Widget/Nextmatch.php | 2 +- api/src/Etemplate/Widget/Select.php | 2 +- api/src/Hooks.php | 6 +++++- importexport/inc/class.importexport_definitions_ui.inc.php | 6 +++++- 6 files changed, 15 insertions(+), 7 deletions(-) diff --git a/api/src/Etemplate/Widget/Date.php b/api/src/Etemplate/Widget/Date.php index 5ae21494c4..709507be93 100644 --- a/api/src/Etemplate/Widget/Date.php +++ b/api/src/Etemplate/Widget/Date.php @@ -114,7 +114,7 @@ class Date extends Transformer return $value; } // otherwise we will get current date or 1970-01-01 instead of an empty value - $format = $this->attrs['dataFormat'] ?? $this->attrs['data_format']; + $format = $this->attrs['dataFormat'] ?? $this->attrs['data_format'] ?? ""; // for DateTime objects (regular PHP and Api\DateTime ones), set user timezone if($value instanceof \DateTime) { diff --git a/api/src/Etemplate/Widget/Grid.php b/api/src/Etemplate/Widget/Grid.php index 2b1f85b4b9..5ba49bd7e8 100644 --- a/api/src/Etemplate/Widget/Grid.php +++ b/api/src/Etemplate/Widget/Grid.php @@ -189,9 +189,9 @@ class Grid extends Box foreach(array_merge(array($direct_child), $n ? array() : $direct_child->children) as $child) { $pat = $child->id; - while(($patstr = strstr($pat, '$'))) + while($pat && ($patstr = strstr($pat, '$'))) { - $pat = substr($patstr,$patstr[1] == '{' ? 2 : 1); + $pat = substr($patstr, $patstr[1] == '{' ? 2 : 1); switch ($this->type) { diff --git a/api/src/Etemplate/Widget/Nextmatch.php b/api/src/Etemplate/Widget/Nextmatch.php index e370919795..518e5c52f6 100644 --- a/api/src/Etemplate/Widget/Nextmatch.php +++ b/api/src/Etemplate/Widget/Nextmatch.php @@ -136,7 +136,7 @@ class Nextmatch extends Etemplate\Widget } // Check for sort preference. We only apply this on first load so it can be changed - if($GLOBALS['egw_info']['user']['preferences'][$app][$this->attrs['template'] . "_sort"]) + if(array_key_exists($this->attrs['template'] . "_sort", $GLOBALS['egw_info']['user']['preferences'][$app])) { $send_value['sort'] = $GLOBALS['egw_info']['user']['preferences'][$app][$this->attrs['template'] . "_sort"]; } diff --git a/api/src/Etemplate/Widget/Select.php b/api/src/Etemplate/Widget/Select.php index 84f53d679b..40f946d8e2 100644 --- a/api/src/Etemplate/Widget/Select.php +++ b/api/src/Etemplate/Widget/Select.php @@ -644,7 +644,7 @@ class Select extends Etemplate\Widget } // Legacy / static support // Have to do this explicitly, since legacy options is not defined on class level - $legacy_options = explode(',',$_legacy_options); + $legacy_options = explode(',', $_legacy_options ?? ""); foreach($legacy_options as &$field) { $field = self::expand_name($field, 0, 0,'','',self::$cont); diff --git a/api/src/Hooks.php b/api/src/Hooks.php index 5ac92161cd..cc99a1baf0 100644 --- a/api/src/Hooks.php +++ b/api/src/Hooks.php @@ -261,12 +261,16 @@ class Hooks // some apps have setup_info for more then themselfs (eg. api for groupdav) foreach($setup_info as $appname => $data) { + if(!array_key_exists('hooks', $data)) + { + continue; + } foreach((array)$data['hooks'] as $location => $methods) { if (is_int($location)) { $location = $methods; - $methods = '/'.$appname.'/inc/hook_'.$methods.'.inc.php'; + $methods = '/' . $appname . '/inc/hook_' . $methods . '.inc.php'; } $locations[$location][$appname] = (array)$methods; } diff --git a/importexport/inc/class.importexport_definitions_ui.inc.php b/importexport/inc/class.importexport_definitions_ui.inc.php index aa59985820..6e8e33cc89 100644 --- a/importexport/inc/class.importexport_definitions_ui.inc.php +++ b/importexport/inc/class.importexport_definitions_ui.inc.php @@ -51,6 +51,10 @@ class importexport_definitions_ui * @var object */ var $plugin; + private Etemplate $etpl; + private string $clock; + private array $steps; + private $wizard_content_template; function __construct() { @@ -60,7 +64,7 @@ class importexport_definitions_ui $GLOBALS['egw_info']['flags']['currentapp'] = self::_appname; $this->etpl = new Etemplate(); - $this->clock = Api\Html::image(self::_appname,'clock'); + $this->clock = Api\Html::image(self::_appname, 'clock'); $this->steps = array( 'wizard_step10' => lang('Choose an application'), 'wizard_step20' => lang('Choose a plugin'),