From f0443c32c1756f5bf3df7099171e79c4aab7c1d9 Mon Sep 17 00:00:00 2001 From: Michiel Dethmers Date: Sat, 30 Mar 2024 15:41:05 +0000 Subject: [PATCH] Php8fixes 202401 (#1026) * remove deprecated ini_set call * stop possible warning * avoid warning * avoid warning * cast to int * avoid warning on existing being null * force template to be an integer * suppress warnings * check on valid var and cast to int * give buttons an ID, so they can be targetted with testing * avoid warning on empty array index --- public_html/lists/admin/CsvReader.php | 1 - public_html/lists/admin/actions/import1.php | 11 +++++----- .../lists/admin/actions/listmembercount.php | 6 +++--- public_html/lists/admin/import1.php | 4 ++-- public_html/lists/admin/import2.php | 21 ++++++++++++------- public_html/lists/admin/inc/userlib.php | 4 ++-- public_html/lists/admin/lib.php | 4 ++-- public_html/lists/admin/members.php | 1 + public_html/lists/admin/mysqli.inc | 3 +++ .../admin/phpListAdminAuthentication.php | 2 +- public_html/lists/admin/pluginlib.php | 2 ++ public_html/lists/admin/plugins.php | 4 ++-- public_html/lists/admin/send_core.php | 2 +- public_html/lists/admin/user.php | 2 +- 14 files changed, 39 insertions(+), 28 deletions(-) diff --git a/public_html/lists/admin/CsvReader.php b/public_html/lists/admin/CsvReader.php index d5d3cb68b..fe5e15fca 100644 --- a/public_html/lists/admin/CsvReader.php +++ b/public_html/lists/admin/CsvReader.php @@ -16,7 +16,6 @@ class CsvReader */ public function __construct($filename, $delimiter) { - ini_set('auto_detect_line_endings', true); $this->fh = fopen($filename, 'r'); $this->delimiter = $delimiter; $this->totalRows = 0; diff --git a/public_html/lists/admin/actions/import1.php b/public_html/lists/admin/actions/import1.php index 9e0a69fd9..e73631edc 100644 --- a/public_html/lists/admin/actions/import1.php +++ b/public_html/lists/admin/actions/import1.php @@ -53,12 +53,13 @@ if (!is_email($email) && $omit_invalid) { unset($email, $info); $count_invalid_emails++; + } else { + //# actually looks like the "info" bit will get lost, but + //# in a way, that doesn't matter + $user_list[$email] = array( + 'info' => $info, + ); } - //# actually looks like the "info" bit will get lost, but - //# in a way, that doesn't matter - $user_list[$email] = array( - 'info' => $info, - ); } $count_email_add = 0; diff --git a/public_html/lists/admin/actions/listmembercount.php b/public_html/lists/admin/actions/listmembercount.php index edf7cb6de..e0b2b0127 100644 --- a/public_html/lists/admin/actions/listmembercount.php +++ b/public_html/lists/admin/actions/listmembercount.php @@ -49,11 +49,11 @@ function listMemberCounts($listId) .'%s, '.' ' .'%s'.')', s('Confirmed and not blacklisted members'), - number_format($counts['confirmed']), + number_format(!empty($counts['confirmed']) ? $counts['confirmed'] : 0), s('Unconfirmed and not blacklisted members'), - number_format($counts['notconfirmed']), + number_format(!empty($counts['notconfirmed']) ? $counts['notconfirmed'] : 0), s('Blacklisted members'), - number_format($counts['blacklisted']) + number_format(!empty($counts['blacklisted']) ? $counts['blacklisted'] : 0) ); return $membersDisplay; diff --git a/public_html/lists/admin/import1.php b/public_html/lists/admin/import1.php index 827353ea4..fd45f0cbd 100644 --- a/public_html/lists/admin/import1.php +++ b/public_html/lists/admin/import1.php @@ -134,8 +134,8 @@ if (count($email_list) > 300 && !$test_import) { // this is a possibly a time consuming process, so lets show a progress bar flush(); - // increase the memory to make sure we are not running out - ini_set('memory_limit', '16M'); + // try to increase the memory to make sure we are not running out + @ini_set('memory_limit', '16M'); } // View test output of emails diff --git a/public_html/lists/admin/import2.php b/public_html/lists/admin/import2.php index df72bbf6f..f5d5ccd21 100644 --- a/public_html/lists/admin/import2.php +++ b/public_html/lists/admin/import2.php @@ -309,16 +309,21 @@ //@@ Why is $attributes not used $query = sprintf('select id from %s where name = "%s"', $tables['attribute'], sql_escape($column)); $existing = Sql_Fetch_Row_Query($query); - $_SESSION['import_attribute'][$column] = array( - 'index' => $i, - 'record' => $existing[0], - 'column' => $column, - ); - array_push($used_attributes, $existing[0]); - if ($existing[0]) { + if (!empty($existing[0])) { // $dbg .= " =known attribute id=" . $existing[0]; - } else { + $_SESSION['import_attribute'][$column] = array( + 'index' => $i, + 'record' => $existing[0], + 'column' => $column, + ); + array_push($used_attributes, $existing[0]); + } else { // $dbg .= " =request mapping"; + $_SESSION['import_attribute'][$column] = array( + 'index' => $i, + 'record' => "", + 'column' => $column, + ); } } } diff --git a/public_html/lists/admin/inc/userlib.php b/public_html/lists/admin/inc/userlib.php index f417ca9fb..00b9ea5aa 100644 --- a/public_html/lists/admin/inc/userlib.php +++ b/public_html/lists/admin/inc/userlib.php @@ -196,7 +196,7 @@ function addNewUser($email, $password = '') // insert into user db $exists = Sql_Fetch_Row_Query(sprintf('select id from %s where email = "%s"', $GLOBALS['tables']['user'], $email)); - if ($exists[0]) { + if (!empty($exists[0])) { return $exists[0]; } @@ -840,7 +840,7 @@ function addUserHistory($email, $msg, $detail) } $userid = Sql_Fetch_Row_Query("select id from $user_table where email = \"$email\""); - if ($userid[0]) { + if (!empty($userid[0])) { Sql_Query(sprintf('insert into %s (ip,userid,date,summary,detail,systeminfo) values("%s",%d,now(),"%s","%s","%s")', $user_his_table, getClientIP(), $userid[0], sql_escape($msg), sql_escape(htmlspecialchars($detail)), sql_escape($sysinfo))); diff --git a/public_html/lists/admin/lib.php b/public_html/lists/admin/lib.php index 587739ff3..18e83eae9 100644 --- a/public_html/lists/admin/lib.php +++ b/public_html/lists/admin/lib.php @@ -943,7 +943,7 @@ function getPageLock($force = 0) // while ($running_res['age'] && $count >= $max) { # a process is already running while ($count >= $max) { // don't check age, as it may be 0 // cl_output('running process: '.$running_res['age'].' '.$max); - if ($running_res['age'] > 600) { + if (!empty($running_res['age']) && (int)$running_res['age'] > 600) { // some sql queries can take quite a while //cl_output($running_res['id'].' is old '.$running_res['age']); // process has been inactive for too long, kill it @@ -1879,7 +1879,7 @@ function refreshTlds($force = 0) $lastDone = getConfig('tld_last_sync'); $tlds = ''; //# let's not do this too often - if ($lastDone + TLD_REFETCH_TIMEOUT < time() || $force) { + if (((int)$lastDone + TLD_REFETCH_TIMEOUT < time()) || $force) { //# even if it fails we mark it as done, so that we won't getting stuck in eternal updating. SaveConfig('tld_last_sync', time(), 0); if (defined('TLD_AUTH_LIST')) { diff --git a/public_html/lists/admin/members.php b/public_html/lists/admin/members.php index f5abae282..bbfa07b98 100644 --- a/public_html/lists/admin/members.php +++ b/public_html/lists/admin/members.php @@ -22,6 +22,7 @@ $confirmedSelection = ' u.confirmed and !u.blacklisted'; } $listAll = false; +$subselect = ''; switch ($access) { case 'owner': diff --git a/public_html/lists/admin/mysqli.inc b/public_html/lists/admin/mysqli.inc index fbb6d258b..3423d78ca 100644 --- a/public_html/lists/admin/mysqli.inc +++ b/public_html/lists/admin/mysqli.inc @@ -410,6 +410,9 @@ function Sql_create_Table($table, $structure) function sql_escape($text) { + if (empty($text)) { + return ''; + } if (empty($GLOBALS['database_connection'])) { $GLOBALS['database_connection'] = Sql_Connect( $GLOBALS['database_host'], diff --git a/public_html/lists/admin/phpListAdminAuthentication.php b/public_html/lists/admin/phpListAdminAuthentication.php index d2b26e765..a0adbe2f5 100644 --- a/public_html/lists/admin/phpListAdminAuthentication.php +++ b/public_html/lists/admin/phpListAdminAuthentication.php @@ -138,7 +138,7 @@ public function adminName($id) { $req = Sql_Fetch_Row_Query(sprintf('select loginname from %s where id = %d', $GLOBALS['tables']['admin'], $id)); - return $req[0] ? $req[0] : s('Nobody'); + return !empty($req[0]) ? $req[0] : s('Nobody'); } /** diff --git a/public_html/lists/admin/pluginlib.php b/public_html/lists/admin/pluginlib.php index cc2d6d9c7..6f365b5a4 100644 --- a/public_html/lists/admin/pluginlib.php +++ b/public_html/lists/admin/pluginlib.php @@ -69,6 +69,8 @@ $GLOBALS['plugins_disabled'][] = $pl; } } +} else { + $disabled_plugins = array(); } //var_dump($GLOBALS['plugins_disabled']);exit; diff --git a/public_html/lists/admin/plugins.php b/public_html/lists/admin/plugins.php index 558c16da9..10a83cf71 100644 --- a/public_html/lists/admin/plugins.php +++ b/public_html/lists/admin/plugins.php @@ -310,8 +310,8 @@ if ($canEnable) { $ls->addColumn($pluginname, s('enabled'), $plugin->enabled ? $GLOBALS['img_tick'] : $GLOBALS['img_cross']); $ls->addColumn($pluginname, s('action'), $plugin->enabled ? - PageLinkAjax('plugins&disable='.$pluginname, '') : - PageLinkAjax('plugins&enable='.$pluginname, '')); + PageLinkAjax('plugins&disable='.$pluginname, '') : + PageLinkAjax('plugins&enable='.$pluginname, '')); } else { $ls->addColumn($pluginname, s('enabled'), $GLOBALS['img_cross']); } diff --git a/public_html/lists/admin/send_core.php b/public_html/lists/admin/send_core.php index 738326df6..012fa2cd7 100644 --- a/public_html/lists/admin/send_core.php +++ b/public_html/lists/admin/send_core.php @@ -211,7 +211,7 @@ subject = "%s", fromfield = "%s", tofield = "%s", replyto ="%s", embargo = "%s", repeatinterval = "%s", repeatuntil = "%s", message = "%s", textmessage = "%s", footer = "%s", status = "%s", - htmlformatted = "%s", sendformat = "%s", template = "%s" where id = %d', + htmlformatted = "%s", sendformat = "%s", template = "%d" where id = %d', $tables['message'], sql_escape(strip_tags($messagedata['campaigntitle'])), /* we store the title in the subject field. Better would be to rename the DB column, but this will do for now */ diff --git a/public_html/lists/admin/user.php b/public_html/lists/admin/user.php index d5f800f94..421cc64fb 100644 --- a/public_html/lists/admin/user.php +++ b/public_html/lists/admin/user.php @@ -465,7 +465,7 @@ class="confirm btn btn-default" while ($row = Sql_fetch_array($res)) { if (!empty($id)) { $val_req = Sql_Fetch_Row_Query("select value from $tables[user_attribute] where userid = $id and attributeid = $row[id]"); - $row['value'] = $val_req[0]; + $row['value'] = !empty($val_req[0]) ? $val_req[0] : ""; } elseif (!empty($_POST['attribute'][$row['id']])) { $row['value'] = $_POST['attribute'][$row['id']]; } else {