diff --git a/api/src/Accounts.php b/api/src/Accounts.php index 58d08ad136..89c604fb45 100644 --- a/api/src/Accounts.php +++ b/api/src/Accounts.php @@ -272,14 +272,14 @@ class Accounts } // no backend understands $param['app'], only sql understands type owngroups or groupmemember[+memberships] // --> do an full search first and then filter and limit that search - elseif($param['app'] || $this->config['account_repository'] != 'sql' && + elseif(!empty($param['app']) || $this->config['account_repository'] != 'sql' && in_array($param['type'], array('owngroups','groupmembers','groupmembers+memberships'))) { $app = $param['app']; unset($param['app']); $start = $param['start']; unset($param['start']); - $offset = $param['offset'] ? $param['offset'] : $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; + $offset = $param['offset'] ?: $GLOBALS['egw_info']['user']['preferences']['common']['maxmatchs']; unset($param['offset']); $stop = $start + $offset; diff --git a/api/src/Accounts/Sql.php b/api/src/Accounts/Sql.php index f9c93c8ee4..a9a1783f4c 100644 --- a/api/src/Accounts/Sql.php +++ b/api/src/Accounts/Sql.php @@ -428,7 +428,7 @@ class Sql if (!isset($GLOBALS['egw_setup']) || in_array(Api\Mail\Smtp\Sql::TABLE, $this->db->table_names(true))) { $email_cols = array('coalesce('.$this->contacts_table.'.contact_email,'.Api\Mail\Smtp\Sql::TABLE.'.mail_value) as email'); - if ($this->db->Type == 'mysql' && !preg_match('/[\x80-\xFF]/', $param['query'])) + if ($this->db->Type == 'mysql' && !preg_match('/[\x80-\xFF]/', $param['query'] ?? '')) { $search_cols[] = Api\Mail\Smtp\Sql::TABLE.'.mail_value'; } @@ -489,8 +489,8 @@ class Sql $filter[] = str_replace('UNIX_TIMESTAMP(NOW())',time(),Api\Contacts\Sql::ACOUNT_ACTIVE_FILTER); } $criteria = array(); - $wildcard = $param['query_type'] == 'start' || $param['query_type'] == 'exact' ? '' : '%'; - if (($query = $param['query'])) + $wildcard = in_array($param['query_type'] ?? '', ['start', 'exact']) ? '' : '%'; + if (($query = $param['query'] ?? null)) { switch($param['query_type']) { @@ -536,7 +536,7 @@ class Sql $order, "account_lid,account_type,account_status,account_expires,account_primary_group,account_description". ",account_lastlogin,account_lastloginfrom,account_lastpwd_change", $wildcard,false,$query[0] == '!' ? 'AND' : 'OR', - $param['offset'] ? array($param['start'], $param['offset']) : (is_null($param['start']) ? false : $param['start']), + !empty($param['offset']) ? array($param['start'], $param['offset']) : $param['start'] ?? false, $filter,$join) as $contact) { if ($contact) @@ -607,7 +607,7 @@ class Sql $cols .= ',account_type'; $where[$which] = $name; // check if we need to treat username case-insensitive - if ($which == 'account_lid' && !$GLOBALS['egw_info']['server']['case_sensitive_username']) // = is case sensitiv eg. on postgres, but not on mysql! + if ($which === 'account_lid' && empty($GLOBALS['egw_info']['server']['case_sensitive_username'])) // = is case sensitiv eg. on postgres, but not on mysql! { $where[] = 'account_lid '.$this->db->capabilities[Api\Db::CAPABILITY_CASE_INSENSITIV_LIKE].' '.$this->db->quote($where['account_lid']); unset($where['account_lid']); @@ -665,4 +665,4 @@ class Sql return $previous_login; } -} +} \ No newline at end of file diff --git a/api/src/Contacts/Sql.php b/api/src/Contacts/Sql.php index 7ac0647636..56499455b9 100644 --- a/api/src/Contacts/Sql.php +++ b/api/src/Contacts/Sql.php @@ -581,7 +581,7 @@ class Sql extends Api\Storage " OR $shared_sql". ($this->grants ? " OR contact_private=0 AND $this->table_name.contact_owner IN (". implode(',',array_keys($this->grants)).")" : ''). - $groupmember_sql." OR $this->table_name.contact_owner IS NULL)"; + ($groupmember_sql??'')." OR $this->table_name.contact_owner IS NULL)"; } } if (isset($filter['list'])) @@ -1298,4 +1298,4 @@ class Sql extends Api\Storage { $this->db->delete($this->extra_table,$data,__LINE__,__FILE__); } -} +} \ No newline at end of file diff --git a/api/src/Contacts/Storage.php b/api/src/Contacts/Storage.php index 8d6366de18..fc8ee28954 100755 --- a/api/src/Contacts/Storage.php +++ b/api/src/Contacts/Storage.php @@ -685,8 +685,8 @@ class Storage { unset($filter['tid']); // return all entries incl. deleted } - $backend = $this->get_backend(null, isset($filter['list']) && $filter['list'] < 0 ? 0 : $filter['owner']); - // single string to search for --> create so_sql conformant search criterial for the standard search columns + $backend = $this->get_backend(null, isset($filter['list']) && $filter['list'] < 0 ? 0 : $filter['owner'] ?? null); + // single string to search for --> create so_sql conformant search criteria for the standard search columns if ($criteria && !is_array($criteria)) { $op = 'OR'; @@ -1316,4 +1316,4 @@ class Storage return $this->somain->lists_ctag($owner); } -} +} \ No newline at end of file diff --git a/api/src/Etemplate/Widget.php b/api/src/Etemplate/Widget.php index 96dfc4c12a..0cdff5a233 100644 --- a/api/src/Etemplate/Widget.php +++ b/api/src/Etemplate/Widget.php @@ -966,7 +966,7 @@ class Widget $readonly = $readonlys === true || // exception to __ALL__ or readonly="true" attribute by setting $readonlys[$from_name] === false - ($this->attrs['readonly'] || isset(self::$request->readonlys['__ALL__'])) && $readonlys !== false; + (!empty($this->attrs['readonly']) || isset(self::$request->readonlys['__ALL__'])) && $readonlys !== false; //error_log(__METHOD__."('$cname') this->id='$this->id' --> form_name='$form_name': attrs[readonly]=".array2string($this->attrs['readonly']).", readonlys['$form_name']=".array2string(self::$request->readonlys[$form_name]).", readonlys[$form_name]=".array2string(self::get_array(self::$request->readonlys,$form_name)).", readonlys['__ALL__']=".array2string(self::$request->readonlys['__ALL__'])." returning ".array2string($readonly)); return $readonly; diff --git a/api/src/Etemplate/Widget/File.php b/api/src/Etemplate/Widget/File.php index 1fb1b654aa..087400856b 100644 --- a/api/src/Etemplate/Widget/File.php +++ b/api/src/Etemplate/Widget/File.php @@ -370,7 +370,7 @@ class File extends Etemplate\Widget * Set default chunk_size attribute to (max_upload_size-1M)/2 * * Last chunk can be 2*chunk_size, therefore we can only set max_upload_size/2 - * minus "some" for other transfered fields. + * minus "some" for other transferred fields. * * @param string $cname * @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont' @@ -381,7 +381,8 @@ class File extends Etemplate\Widget $upload_max_filesize = ini_get('upload_max_filesize'); $unit = strtolower(substr($upload_max_filesize, -1)); - if (!is_numeric($unit)) $upload_max_filesize *= $unit == 'm' ? 1024*1024 : 1024; + $upload_max_filesize = (float)$upload_max_filesize; + if (!is_numeric($unit)) $upload_max_filesize *= $unit === 'm' ? 1024*1024 : 1024; if ($upload_max_filesize > 1024*1024) { self::setElementAttribute($form_name, 'chunk_size', ($upload_max_filesize-1024*1024)/2); diff --git a/api/src/Etemplate/Widget/Nextmatch.php b/api/src/Etemplate/Widget/Nextmatch.php index 897f79ab78..97febabcec 100644 --- a/api/src/Etemplate/Widget/Nextmatch.php +++ b/api/src/Etemplate/Widget/Nextmatch.php @@ -174,7 +174,7 @@ class Nextmatch extends Etemplate\Widget unset($send_value['favorite']); // Parse sort into something that get_rows functions are expecting: db_field in order, ASC/DESC in sort - if(is_array($send_value['sort'])) + if(!empty($send_value['sort']) && is_array($send_value['sort'])) { $send_value['order'] = $send_value['sort']['id']; $send_value['sort'] = $send_value['sort']['asc'] ? 'ASC' : 'DESC'; @@ -584,7 +584,7 @@ class Nextmatch extends Etemplate\Widget { list($app,$class,$method) = explode('.',$value['get_rows']); } - if ($class) + if (!empty($class)) { if (!$app && !is_object($GLOBALS[$class])) { @@ -979,7 +979,7 @@ class Nextmatch extends Etemplate\Widget if (!empty($action['url'])) { $action['url'] = Api\Framework::link('/index.php',str_replace('$action',$id,$action['url'])); - if ($action['popup']) + if (!empty($action['popup'])) { list($action['data']['width'],$action['data']['height']) = explode('x',$action['popup']); unset($action['popup']); @@ -988,7 +988,7 @@ class Nextmatch extends Etemplate\Widget else { $action['data']['nm_action'] = 'location'; - if(!$action['target'] && strpos($action['url'],'menuaction') > 0) + if(empty($action['target']) && strpos($action['url'],'menuaction') > 0) { // It would be better if app set target, but we'll auto-detect if not list(,$menuaction) = explode('=',$action['url']); @@ -1265,4 +1265,4 @@ class Nextmatch extends Etemplate\Widget } // Registration needs to go here, otherwise customfields won't be loaded until some other cf shows up -Etemplate\Widget::registerWidget(__NAMESPACE__.'\\Customfields', array('nextmatch-customfields')); +Etemplate\Widget::registerWidget(__NAMESPACE__.'\\Customfields', array('nextmatch-customfields')); \ No newline at end of file diff --git a/api/src/Etemplate/Widget/Select.php b/api/src/Etemplate/Widget/Select.php index 44b8364e6f..4a15da5c26 100644 --- a/api/src/Etemplate/Widget/Select.php +++ b/api/src/Etemplate/Widget/Select.php @@ -317,7 +317,8 @@ class Select extends Etemplate\Widget { // Check selection preference, we may be able to skip reading some data $select_pref = $GLOBALS['egw_info']['user']['preferences']['common']['account_selection']; - if($this->attrs['type'] == 'select-account' && empty($GLOBALS['egw_info']['user']['apps']['admin']) && $select_pref == 'none') + if(!empty($this->attrs['type']) && $this->attrs['type'] === 'select-account' && + empty($GLOBALS['egw_info']['user']['apps']['admin']) && $select_pref === 'none') { // Preserve but do not send the value if preference is 'none' self::$request->preserv[$this->id] = self::$request->content[$this->id] ?? null; diff --git a/api/src/Etemplate/Widget/Tree.php b/api/src/Etemplate/Widget/Tree.php index b05deaac1c..042d4f8ef9 100644 --- a/api/src/Etemplate/Widget/Tree.php +++ b/api/src/Etemplate/Widget/Tree.php @@ -324,7 +324,7 @@ class Tree extends Etemplate\Widget { $label = html_entity_decode($label, ENT_NOQUOTES,'utf-8'); } - elseif($label['label']) + elseif(!empty($label['label'])) { $label['label'] = html_entity_decode($label['label'], ENT_NOQUOTES,'utf-8'); } @@ -524,4 +524,4 @@ class Tree extends Etemplate\Widget //error_log(__METHOD__."('$widget_type', '$legacy_options', no_lang=".array2string($no_lang).', readonly='.array2string($readonly).", value=$value) returning ".array2string($options)); return $options; } -} +} \ No newline at end of file diff --git a/api/src/Framework.php b/api/src/Framework.php index b84d43602b..bee3b11d82 100644 --- a/api/src/Framework.php +++ b/api/src/Framework.php @@ -901,11 +901,11 @@ abstract class Framework extends Framework\Extra } //Sort the applications accordingly to their user sort setting - if ($GLOBALS['egw_info']['user']['preferences']['common']['user_apporder']) + if (!empty($GLOBALS['egw_info']['user']['preferences']['common']['user_apporder'])) { //Sort the application array using the user_apporder array as sort index self::$user_apporder = - unserialize($GLOBALS['egw_info']['user']['preferences']['common']['user_apporder']); + unserialize($GLOBALS['egw_info']['user']['preferences']['common']['user_apporder'], ['allowed_classes' => false]); uasort($apps, __CLASS__.'::_sort_apparray'); } diff --git a/api/src/Html.php b/api/src/Html.php index 1dd9414d01..315b67bc93 100644 --- a/api/src/Html.php +++ b/api/src/Html.php @@ -86,7 +86,7 @@ class Html $additionalQuote = """; } //error_log(__METHOD__.__LINE__.array2string($match)); - return "".$match[3].$match[4]."$additionalQuote"; + return "".$match[3].($match[4]??'')."$additionalQuote"; }, $result2); // Now match things beginning with www. @@ -1391,4 +1391,4 @@ tinymce.init({ { return Html\HtmLawed::purify($html, $config, $spec, $_force); } -} +} \ No newline at end of file diff --git a/api/src/Html/HtmLawed.php b/api/src/Html/HtmLawed.php index 31ec440987..2e80f30a7f 100644 --- a/api/src/Html/HtmLawed.php +++ b/api/src/Html/HtmLawed.php @@ -148,7 +148,7 @@ class HtmLawed // no need to do the extra routine $html = str_ireplace($newStyle[0],'',$html); } - if ($style2buffer) + if (!empty($style2buffer)) { //error_log(__METHOD__.__LINE__.array2string($style2buffer)); $test = json_encode($style2buffer); @@ -161,7 +161,7 @@ class HtmLawed $style2buffer = utf8_encode($style2buffer); } } - $style = $style2buffer; + $style = $style2buffer ?? ''; // clean out comments and stuff $search = array( '@url\(http:\/\/[^\)].*?\)@si', // url calls e.g. in style definitions @@ -456,5 +456,4 @@ function hl_email_tag_transform($element, $attribute_array=0) // Return the opening tag with attributes static $empty_elements = array('area'=>1, 'br'=>1, 'col'=>1, 'embed'=>1, 'hr'=>1, 'img'=>1, 'input'=>1, 'isindex'=>1, 'param'=>1); return "<{$element}{$attributes}". (isset($empty_elements[$element]) ? ' /' : ''). '>'; -} - +} \ No newline at end of file diff --git a/api/src/Sharing.php b/api/src/Sharing.php index 13640b379b..9ab267c2a7 100644 --- a/api/src/Sharing.php +++ b/api/src/Sharing.php @@ -109,7 +109,7 @@ class Sharing $path_info = $matches[1]; } $path_info = substr($path_info, strlen($_SERVER['SCRIPT_NAME'])); - list(, $token/*, $path*/) = preg_split('|[/?]|', $path_info, 3); + list(, $token/*, $path*/) = preg_split('|[/?]|', $path_info, 3)+[null,null,null]; list($token) = explode(':', $token); return $token; diff --git a/api/src/Storage.php b/api/src/Storage.php index 42b31fb1a4..ae2c94e8e3 100644 --- a/api/src/Storage.php +++ b/api/src/Storage.php @@ -537,7 +537,7 @@ class Storage extends Storage\Base $extra_join_added = true; } $extra_columns = $this->db->get_table_definitions($this->app, $this->extra_table); - if(is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)]) + if(is_string($name) && $extra_columns['fd'][array_search($name, $this->db_cols)] ?? null) { $criteria[] = $this->db->expression($this->table_name,$this->table_name.'.',array( array_search($name, $this->db_cols) => $val, @@ -568,7 +568,7 @@ class Storage extends Storage\Base } } } - if ($cfcriteria && $op =='OR') $criteria[] = implode(' OR ',$cfcriteria); + if (!empty($cfcriteria) && $op === 'OR') $criteria[] = implode(' OR ', $cfcriteria); } if($only_keys === true) { @@ -817,4 +817,4 @@ class Storage extends Storage\Base return $this->allow_multiple_values && in_array($this->customfields[$name]['type'],array('select','select-account')) && $this->customfields[$name]['rows'] > 1; } -} +} \ No newline at end of file diff --git a/api/src/Storage/Base.php b/api/src/Storage/Base.php index 91e683cc6d..60da4cf54e 100644 --- a/api/src/Storage/Base.php +++ b/api/src/Storage/Base.php @@ -23,7 +23,7 @@ use EGroupware\Api; * 2) by setting the following documented class-vars in a class derived from this one * Of cause you can derive from the class and call the constructor with params. * - * @todo modify search() to return an interator instead of an array + * @todo modify search() to return an iterator instead of an array */ class Base { @@ -495,7 +495,7 @@ class Base $query = []; foreach ($this->db_key_cols as $db_col => $col) { - if ($this->data[$col] != '') + if ((string)($this->data[$col] ?? '') !== '') { $query[$db_col] = $this->data[$col]; } @@ -504,7 +504,7 @@ class Base { foreach($this->db_uni_cols as $db_col => $col) { - if (!is_array($col) && $this->data[$col] != '') + if (!is_array($col) && (string)($this->data[$col] ?? '') !== '') { $query[$db_col] = $this->data[$col]; } @@ -939,18 +939,17 @@ class Base if (($key = array_search('*', $colums)) !== false) { unset($colums[$key]); - // don't add colums already existing incl. aliased colums (AS $name) + // don't add columns already existing incl. aliased colums (AS $name) $as_columns = array_map(function($col) { - $as = null; - list(, $as) = preg_split('/ +AS +/i', $col); + list(, $as) = preg_split('/ +AS +/i', $col)+[null,null]; return empty($as) ? $col : $as; }, $colums); foreach(array_keys($this->db_cols) as $col) { if (!in_array($col, $colums) && !in_array($col, $as_columns)) { - // make sure column-name is not ambigous + // make sure column-name is not ambiguous if ($join && strpos($join, $this->table_name.'.'.$col)) { $col = $this->table_name.'.'.$col.' AS '.$col; @@ -1029,7 +1028,7 @@ class Base { $this->total = $this->db->select($this->table_name,'COUNT(*)',$query,__LINE__,__FILE__,false,'',$this->app,0,$join)->fetchColumn(); } - else // cant do a count, have to run the query without limit + else // can't do a count, have to run the query without limit { $this->total = $this->db->select($this->table_name,$colums,$query,__LINE__,__FILE__,false,$order_by,false,0,$join)->NumRows(); } @@ -1048,7 +1047,8 @@ class Base // ToDo: Implement that as an iterator, as $rs is also an interator and we could return one instead of an array if ($this->search_return_iterator) { - return new Db2DataIterator($this,$rs); + $ret = new Db2DataIterator($this,$rs); + return $ret; } $arr = array(); $n = 0; @@ -1057,7 +1057,7 @@ class Base $data = array(); foreach($cols as $db_col => $col) { - $data[$col] = (isset($row[$db_col]) ? $row[$db_col] : $row[$col]); + $data[$col] = $row[$db_col] ?? $row[$col] ?? null; } $arr[] = $this->db2data($data); $n++; @@ -1721,4 +1721,4 @@ class Base } return is_null($column) ? $comments : $comments[$column]; } -} +} \ No newline at end of file diff --git a/api/src/Storage/Customfields.php b/api/src/Storage/Customfields.php index 29f2e2437c..49e32bb0b8 100644 --- a/api/src/Storage/Customfields.php +++ b/api/src/Storage/Customfields.php @@ -140,7 +140,7 @@ class Customfields implements \IteratorAggregate public static function get($app, $account=false, $only_type2=null, Api\Db $db=null) { $account_key = $account === true ? 'all' : - ($account === false ? $GLOBALS['egw_info']['user']['account_id'] : + ($account === false ? ($GLOBALS['egw_info']['user']['account_id']??null) : (int)$account); $cache_key = $app.':'.$account_key.':'.$only_type2; @@ -598,4 +598,4 @@ class Customfields implements \IteratorAggregate } } -Customfields::init_static(); +Customfields::init_static(); \ No newline at end of file diff --git a/api/src/Storage/Merge.php b/api/src/Storage/Merge.php index 7350c34e17..01055ebcd2 100644 --- a/api/src/Storage/Merge.php +++ b/api/src/Storage/Merge.php @@ -702,7 +702,7 @@ abstract class Merge if(!array_key_exists($app, $exportLimitStore)) { //error_log(__METHOD__.__LINE__.' -> '.$app_limit.' '.function_backtrace()); - $exportLimitStore[$app] = $GLOBALS['egw_info']['server']['export_limit']; + $exportLimitStore[$app] = $GLOBALS['egw_info']['server']['export_limit'] ?? null; if($app != 'common') { $app_limit = Api\Hooks::single('export_limit', $app); @@ -1272,7 +1272,7 @@ abstract class Merge } } } - if($is_xml) // zip'ed xml document (eg. OO) + if (!empty($is_xml)) // zip'ed xml document (eg. OO) { // Numeric fields $names = array(); @@ -1598,7 +1598,7 @@ abstract class Merge { $key = '$$' . $field . '$$'; $field = preg_quote($field, '/'); - if($values[$key]) + if (!empty($values[$key])) { $date = Api\DateTime::createFromUserFormat($values[$key]); if($mimetype == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || @@ -1901,21 +1901,21 @@ abstract class Merge */ private function replace_callback($param) { - if(array_key_exists('$$' . $param[4] . '$$', $this->replacements)) + if(!empty($param[4]) && array_key_exists('$$' . $param[4] . '$$', $this->replacements)) { $param[4] = $this->replacements['$$' . $param[4] . '$$']; } - if(array_key_exists('$$' . $param[3] . '$$', $this->replacements)) + if(!empty($param[3]) && array_key_exists('$$' . $param[3] . '$$', $this->replacements)) { $param[3] = $this->replacements['$$' . $param[3] . '$$']; } - $pattern = '/' . preg_quote($param[2], '/') . '/'; + $pattern = '/' . preg_quote($param[2]??'', '/') . '/'; if(strpos($param[0], '$$IF') === 0 && (trim($param[2]) == "EMPTY" || $param[2] === '')) { $pattern = '/^$/'; } - $replace = preg_match($pattern, $this->replacements['$$' . $param[1] . '$$']) ? $param[3] : $param[4]; + $replace = preg_match($pattern, $this->replacements['$$' . $param[1] . '$$'] ?? '') ? ($param[3]??null) : ($param[4]??null); switch($this->mimetype) { case 'application/vnd.oasis.opendocument.text': // open office @@ -1977,7 +1977,7 @@ abstract class Merge } if(strpos($param[0], '$$NELF') === 0) { //sets a Pagebreak and value, only if the field has a value - if($this->replacements['$$' . $param[1] . '$$'] != '') + if(!empty($this->replacements['$$' . $param[1] . '$$'])) { $replace = $LF . $this->replacements['$$' . $param[1] . '$$']; } @@ -1995,7 +1995,7 @@ abstract class Merge $replaceprefix = explode(' ', substr($param[0], 21, -2)); foreach($replaceprefix as $nameprefix) { - if($this->replacements['$$' . $nameprefix . '$$'] != '') + if(!empty($this->replacements['$$' . $nameprefix . '$$'])) { $replaceprefixsort[] = $this->replacements['$$' . $nameprefix . '$$']; } @@ -3295,4 +3295,4 @@ abstract class Merge protected function show_replacements_hook(&$template_name, &$content, &$sel_options, &$readonlys) { } -} +} \ No newline at end of file diff --git a/api/src/Vfs/Sqlfs/StreamWrapper.php b/api/src/Vfs/Sqlfs/StreamWrapper.php index e99213a711..dae0b351bf 100644 --- a/api/src/Vfs/Sqlfs/StreamWrapper.php +++ b/api/src/Vfs/Sqlfs/StreamWrapper.php @@ -335,7 +335,7 @@ class StreamWrapper extends Api\Db\Pdo implements Vfs\StreamWrapperIface // remember initial size and directory for adjustDirSize call in close if (is_resource($this->opened_stream)) { - $this->opened_size = empty($stat) ? $stat['size'] : 0; + $this->opened_size = !empty($stat) ? $stat['size'] : 0; if (empty($dir_stat)) { $dir_stat = $this->url_stat($dir,STREAM_URL_STAT_QUIET); @@ -2058,4 +2058,4 @@ GROUP BY A.fs_id'; } } -StreamWrapper::register(); +StreamWrapper::register(); \ No newline at end of file