Replaced most each() calls with foreach() in preparation to support php 8

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2022-01-19 15:40:42 +01:00
parent 7aec4647a5
commit 7a66346036
22 changed files with 47 additions and 45 deletions

View File

@ -103,7 +103,7 @@ function saveMessages($storage, $folder = '', $num = 0) {
$messages = $storage->piler_batch_fetch(1, $num); $messages = $storage->piler_batch_fetch(1, $num);
while(list($k, $v) = each($messages)) { foreach($messages as $k => $v) {
$uuid = $storage->getUniqueId($k); $uuid = $storage->getUniqueId($k);
$tmpname = "piler-" . $username . "-" . $folder . "-" . $k . "-" . $uuid . ".eml"; $tmpname = "piler-" . $username . "-" . $folder . "-" . $k . "-" . $uuid . ".eml";

View File

@ -410,7 +410,7 @@ class Zend_Mail_Protocol_Imap
$a = $this->requestAndResponse("LIST", array('""', '"*"')); $a = $this->requestAndResponse("LIST", array('""', '"*"'));
while(list($k, $v) = each($a)) { foreach ($a as $k => $v) {
if($v[1][0] == '\HasNoChildren') { if($v[1][0] == '\HasNoChildren') {
array_push($folders, $v[3]); array_push($folders, $v[3]);
} }

View File

@ -99,7 +99,7 @@ class ControllerAuditHelper extends Controller {
$s = preg_replace("/\s{1,}/", " ", $s); $s = preg_replace("/\s{1,}/", " ", $s);
$b = explode(" ", $s); $b = explode(" ", $s);
while(list($k, $v) = each($b)) { foreach ($b as $k => $v) {
if($v == '') { continue; } if($v == '') { continue; }
if(preg_match("/(login|loginfailed|logout|view|download|search|restore|journal)$/", $v) && isset($actions[$v])) { $this->a['action'] .= "\t" . $actions[$v]; } if(preg_match("/(login|loginfailed|logout|view|download|search|restore|journal)$/", $v) && isset($actions[$v])) { $this->a['action'] .= "\t" . $actions[$v]; }

View File

@ -140,7 +140,7 @@ class ControllerSearchHelper extends Controller {
$s = preg_replace("/OR/", "|", $data['search']); $s = preg_replace("/OR/", "|", $data['search']);
$b = preg_split("/\s/", $s); $b = preg_split("/\s/", $s);
while(list($k, $v) = each($b)) { foreach ($b as $k => $v) {
if($v == '') { continue; } if($v == '') { continue; }
if(preg_match("/\d{4}\-\d{1,2}\-\d{1,2}/", $v) || preg_match("/\d{1,2}\/\d{1,2}\/\d{4}/", $v)) { if(preg_match("/\d{4}\-\d{1,2}\-\d{1,2}/", $v) || preg_match("/\d{1,2}\/\d{1,2}\/\d{4}/", $v)) {

View File

@ -43,7 +43,7 @@ class ModelAuditAudit extends Model {
if(Registry::get('admin_user') == 0 && RESTRICTED_AUDITOR == 1) { if(Registry::get('admin_user') == 0 && RESTRICTED_AUDITOR == 1) {
$auditdomains = $session->get("auditdomains"); $auditdomains = $session->get("auditdomains");
while(list($k, $v) = each($auditdomains)) { foreach($auditdomains as $k => $v) {
if($q) { $q .= ","; } if($q) { $q .= ","; }
$q .= "?"; $q .= "?";
array_push($arr, $v); array_push($arr, $v);

View File

@ -76,7 +76,7 @@ class ModelGoogleGoogle extends Model {
$messages = $storage->piler_batch_fetch($from, $to); $messages = $storage->piler_batch_fetch($from, $to);
while(list($k, $v) = each($messages)) { foreach($messages as $k => $v) {
$uuid = $storage->getUniqueId($k); $uuid = $storage->getUniqueId($k);
$tmpname = "piler-" . $email . "-" . $k . "-" . $uuid . ".eml"; $tmpname = "piler-" . $email . "-" . $k . "-" . $uuid . ".eml";
@ -98,7 +98,7 @@ class ModelGoogleGoogle extends Model {
} }
syslog(LOG_INFO, "downloaded $count messages for $email"); syslog(LOG_INFO, "downloaded $count messages for $email");
return $count; return $count;
} }
@ -174,5 +174,3 @@ class ModelGoogleGoogle extends Model {
} }
?>

View File

@ -199,7 +199,7 @@ class ModelHealthHealth extends Model {
public function meminfo() { public function meminfo() {
$m = explode("\n", file_get_contents("/proc/meminfo")); $m = explode("\n", file_get_contents("/proc/meminfo"));
while(list($k, $v) = each($m)) { foreach($m as $k => $v) {
$a = preg_split("/\ {1,}/", $v); $a = preg_split("/\ {1,}/", $v);
if(isset($a[0]) && $a[0]) { $_m[$a[0]] = $a[1]; } if(isset($a[0]) && $a[0]) { $_m[$a[0]] = $a[1]; }
} }
@ -219,7 +219,7 @@ class ModelHealthHealth extends Model {
$partitions = Registry::get('partitions_to_monitor'); $partitions = Registry::get('partitions_to_monitor');
while(list($k, $v) = each($output)) { foreach($output as $k => $v) {
if($k > 0) { if($k > 0) {
$p = preg_split("/\ {1,}/", $v); $p = preg_split("/\ {1,}/", $v);
if(isset($p[5]) && in_array($p[5], $partitions) && !isset($a[$p[5]])) { if(isset($p[5]) && in_array($p[5], $partitions) && !isset($a[$p[5]])) {

View File

@ -26,7 +26,7 @@ class ModelMailMail extends Model {
fputs($r, "MAIL FROM: <$from>\r\n"); fputs($r, "MAIL FROM: <$from>\r\n");
$l = fgets($r, 4096); $l = fgets($r, 4096);
while(list($k, $v) = each($to)) { foreach($to as $k => $v) {
fputs($r, "RCPT TO: <$v>\r\n"); fputs($r, "RCPT TO: <$v>\r\n");
$l = fgets($r, 4096); $l = fgets($r, 4096);
} }

View File

@ -213,7 +213,7 @@ class ModelSearchMessage extends Model {
$a = explode(" ", $terms); $a = explode(" ", $terms);
$terms = array(); $terms = array();
while(list($k, $v) = each($a)) { foreach($a as $k => $v) {
if(strlen($v) >= 3 && !in_array($v, $fields)) { if(strlen($v) >= 3 && !in_array($v, $fields)) {
$v = preg_replace("/\*/", "", $v); $v = preg_replace("/\*/", "", $v);
if($v) { array_push($terms, $v); } if($v) { array_push($terms, $v); }
@ -223,7 +223,7 @@ class ModelSearchMessage extends Model {
if(count($terms) <= 0) { return $s; } if(count($terms) <= 0) { return $s; }
if($html == 0) { if($html == 0) {
while(list($k, $v) = each($terms)) { foreach($terms as $k => $v) {
$s = preg_replace("/$v/i", "<span class=\"mssghglght\">$v</span>", $s); $s = preg_replace("/$v/i", "<span class=\"mssghglght\">$v</span>", $s);
} }
@ -233,7 +233,7 @@ class ModelSearchMessage extends Model {
$tokens = preg_split("/\</", $s); $tokens = preg_split("/\</", $s);
$s = ''; $s = '';
while(list($k, $token) = each($tokens)) { foreach($tokens as $k => $token) {
$pos = strpos($token, ">"); $pos = strpos($token, ">");
if($pos > 0) { if($pos > 0) {
@ -245,7 +245,7 @@ class ModelSearchMessage extends Model {
$str = substr($token, $pos+1, $len); $str = substr($token, $pos+1, $len);
reset($terms); reset($terms);
while(list($k, $v) = each($terms)) { foreach($terms as $k => $v) {
$str = preg_replace("/$v/i", "<span class=\"mssghglght\">$v</span>", $str); $str = preg_replace("/$v/i", "<span class=\"mssghglght\">$v</span>", $str);
} }

View File

@ -16,7 +16,7 @@ class ModelSearchSearch extends Model {
$session = Registry::get('session'); $session = Registry::get('session');
while(list($k,$v) = each($data)) { foreach($data as $k => $v) {
if($v) { if(is_array($v)) { $v = implode(" ", $v); } $s .= '&' . $k . '=' . $v; } if($v) { if(is_array($v)) { $v = implode(" ", $v); } $s .= '&' . $k . '=' . $v; }
} }
@ -113,7 +113,7 @@ class ModelSearchSearch extends Model {
$session = Registry::get('session'); $session = Registry::get('session');
$i = 0; $i = 0;
while(list($k, $v) = each($data['match'])) { foreach($data['match'] as $k => $v) {
if($v == "@attachment_types") { if($v == "@attachment_types") {
list($k, $v) = each($data['match']); list($k, $v) = each($data['match']);
$i++; $i++;
@ -199,7 +199,7 @@ class ModelSearchSearch extends Model {
if(ENABLE_FOLDER_RESTRICTIONS == 1) { if(ENABLE_FOLDER_RESTRICTIONS == 1) {
$s = explode(" ", $data['folders']); $s = explode(" ", $data['folders']);
while(list($k,$v) = each($s)) { foreach($s as $k => $v) {
if(in_array($v, $session->get("folders"))) { if(in_array($v, $session->get("folders"))) {
array_push($__folders, $v); array_push($__folders, $v);
} }
@ -347,7 +347,7 @@ class ModelSearchSearch extends Model {
$s = preg_replace("/httpX/", "http:", $s); $s = preg_replace("/httpX/", "http:", $s);
$b = explode(" ", $s); $b = explode(" ", $s);
while(list($k, $v) = each($b)) { foreach($b as $k => $v) {
if($v == '') { continue; } if($v == '') { continue; }
if($v == 'from:') { $token = 'match'; $a['match'][] = FROM_TOKEN; continue; } if($v == 'from:') { $token = 'match'; $a['match'][] = FROM_TOKEN; continue; }
@ -441,7 +441,7 @@ class ModelSearchSearch extends Model {
$offset = $page * $pagelen; $offset = $page * $pagelen;
$s = explode(" ", $extra_folders); $s = explode(" ", $extra_folders);
while(list($k,$v) = each($s)) { foreach($s as $k => $v) {
if(in_array($v, $session->get("extra_folders")) && is_numeric($v)) { if(in_array($v, $session->get("extra_folders")) && is_numeric($v)) {
array_push($__folders, $v); array_push($__folders, $v);
if($q) { $q .= ",?"; } if($q) { $q .= ",?"; }
@ -649,7 +649,7 @@ class ModelSearchSearch extends Model {
if(!$emails) { return $s; } if(!$emails) { return $s; }
while(list($k, $v) = each($emails)) { foreach($emails as $k => $v) {
if($s) { $s .= '| ' . $this->fix_email_address_for_sphinx($v); } if($s) { $s .= '| ' . $this->fix_email_address_for_sphinx($v); }
else { $s = $this->fix_email_address_for_sphinx($v); } else { $s = $this->fix_email_address_for_sphinx($v); }
} }
@ -704,7 +704,7 @@ class ModelSearchSearch extends Model {
$auditdomains = $session->get("auditdomains"); $auditdomains = $session->get("auditdomains");
while(list($k, $v) = each($auditdomains)) { foreach($auditdomains as $k => $v) {
if(validdomain($v) == 1 && !in_array($v, $a)) { if(validdomain($v) == 1 && !in_array($v, $a)) {
$q .= ",?"; $q .= ",?";
array_push($a, $v); array_push($a, $v);
@ -720,7 +720,7 @@ class ModelSearchSearch extends Model {
$emails = $session->get("emails"); $emails = $session->get("emails");
while(list($k, $v) = each($emails)) { foreach($emails as $k => $v) {
if(validemail($v) == 1) { if(validemail($v) == 1) {
$q .= ",?"; $q .= ",?";
array_push($a, $v); array_push($a, $v);
@ -776,7 +776,7 @@ class ModelSearchSearch extends Model {
$auditdomains = $session->get("auditdomains"); $auditdomains = $session->get("auditdomains");
while(list($k, $v) = each($auditdomains)) { foreach($auditdomains as $k => $v) {
if(validdomain($v) == 1 && !in_array($v, $a)) { if(validdomain($v) == 1 && !in_array($v, $a)) {
$q .= ",?"; $q .= ",?";
array_push($a, $v); array_push($a, $v);
@ -787,7 +787,7 @@ class ModelSearchSearch extends Model {
if(Registry::get('auditor_user') == 0) { if(Registry::get('auditor_user') == 0) {
$emails = $session->get("emails"); $emails = $session->get("emails");
while(list($k, $v) = each($emails)) { foreach($emails as $k => $v) {
if(validemail($v) == 1) { if(validemail($v) == 1) {
$q .= ",?"; $q .= ",?";
array_push($a, $v); array_push($a, $v);
@ -915,7 +915,7 @@ class ModelSearchSearch extends Model {
$a = explode(" ", $s); $a = explode(" ", $s);
$s = ''; $s = '';
while(list($k, $v) = each($a)) { foreach($a as $k => $v) {
if(substr($v, 0, 4) == 'http') { if(substr($v, 0, 4) == 'http') {
$v = preg_replace("/http(s){0,1}\:\/\//", "__URL__", $v); $v = preg_replace("/http(s){0,1}\:\/\//", "__URL__", $v);

View File

@ -69,7 +69,7 @@ class ModelStatChart extends Model {
if($query->num_rows >= 15) { if($query->num_rows >= 15) {
$i = 0; $i = 0;
while(list($k, $v) = each($dates)) { foreach($dates as $k => $v) {
$i++; $i++;
if($i % 3) { $dates[$k] = ""; } if($i % 3) { $dates[$k] = ""; }
} }

View File

@ -155,7 +155,7 @@ class ModelUserImport extends Model {
/* build a list of DNs to exclude from the import */ /* build a list of DNs to exclude from the import */
while (list($k, $v) = each($globals)) { foreach($globals as $k => $v) {
if(preg_match("/^reject_/", $k)) { if(preg_match("/^reject_/", $k)) {
$exclude[$v] = $v; $exclude[$v] = $v;
} }

View File

@ -27,7 +27,9 @@ class Controller {
public function args($args = array()){ public function args($args = array()){
while(list($key, $value) = each($args)) $this->data[$key] = $value; foreach($args as $key => $value) {
$this->data[$key] = $value;
}
} }

View File

@ -53,7 +53,7 @@ class MySQL {
$R = $s->fetchAll(PDO::FETCH_ASSOC); $R = $s->fetchAll(PDO::FETCH_ASSOC);
while(list ($k, $v) = each($R)){ foreach($R as $k => $v) {
$data[$i] = $v; $data[$i] = $v;
$i++; $i++;
} }

View File

@ -47,7 +47,7 @@ class Sphinx {
$R = $s->fetchAll(); $R = $s->fetchAll();
while(list ($k, $v) = each($R)){ foreach($R as $k => $v) {
$data[$i] = $v; $data[$i] = $v;
$i++; $i++;
} }
@ -72,7 +72,7 @@ class Sphinx {
$meta->execute(); $meta->execute();
$R = $meta->fetchAll(); $R = $meta->fetchAll();
while(list ($k, $v) = each($R)){ foreach($R as $k => $v) {
if($v[0] == "total_found") { $query->total_found = $v[1]; } if($v[0] == "total_found") { $query->total_found = $v[1]; }
} }

View File

@ -47,7 +47,7 @@ class SQLite {
$R = $s->fetchAll(); $R = $s->fetchAll();
while(list ($k, $v) = each($R)){ foreach($R as $k => $v) {
$data[$i] = $v; $data[$i] = $v;
$i++; $i++;
} }

View File

@ -255,7 +255,8 @@ class Piler_Mime_Decode {
} }
while(list($k, $v) = each($result)) { foreach($result as $k => $v) {
if(strchr($v, "\n")) { if(strchr($v, "\n")) {
$result[$k] = explode("\n", $v); $result[$k] = explode("\n", $v);
} }

View File

@ -17,7 +17,7 @@ class Language {
else { else {
$pref_langs = $this->get_preferred_languages(); $pref_langs = $this->get_preferred_languages();
while(list($k, $v) = each($pref_langs)) { foreach($pref_langs as $k => $v) {
if(in_array($v, $langs)) { if(in_array($v, $langs)) {
$lang = $v; $lang = $v;
define('LANG', $lang); define('LANG', $lang);
@ -53,7 +53,8 @@ class Language {
$l = explode(";", $_SERVER['HTTP_ACCEPT_LANGUAGE']); $l = explode(";", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
while(list($k, $v) = each($l)) { foreach($l as $k => $v) {
$a = explode(",", $v); $a = explode(",", $v);
if(isset($a[0]) && substr($a[0], 0, 2) != 'q=') { if(isset($a[0]) && substr($a[0], 0, 2) != 'q=') {

View File

@ -196,7 +196,7 @@ function first_n_characters($what, $n){
$len = 0; $len = 0;
$a = explode(" ", $what); $a = explode(" ", $what);
while(list($k, $v) = each($a)){ foreach($a as $k => $v) {
$x .= "$v "; $len += strlen($v) + 1; $x .= "$v "; $len += strlen($v) + 1;
if($len >= $n){ return $x . "..."; } if($len >= $n){ return $x . "..."; }
} }
@ -279,7 +279,7 @@ function my_qp_encode($s){
$res = ""; $res = "";
$a = explode("\n", $s); $a = explode("\n", $s);
while(list($k, $v) = each($a)){ foreach($a as $k => $v) {
$part = ""; $part = "";
for($i=0; $i<strlen($v); $i++){ for($i=0; $i<strlen($v); $i++){
@ -417,7 +417,7 @@ function parse_string_to_array($s = '', $arr = array()) {
parse_str($s, $a); parse_str($s, $a);
while(list($k, $v) = each($a)) { foreach($a as $k => $v) {
if(!isset($arr[$k]) || $arr[$k] == '') $arr[$k] = $v; if(!isset($arr[$k]) || $arr[$k] == '') $arr[$k] = $v;
} }
@ -453,7 +453,7 @@ function convert_date_string_to_ymd_by_template($date_string, $date_template) {
return [$Y, $m, $d]; return [$Y, $m, $d];
} }
while(list($k, $v) = each($template_array)) { foreach($template_array as $k => $v) {
$$v = $date_array[$k]; $$v = $date_array[$k];
} }
@ -613,7 +613,7 @@ function get_ldap_attribute_names($ldap_type = '') {
function htmlentities_on_array($arr = []) { function htmlentities_on_array($arr = []) {
while(list($k, $v) = each($arr)) { foreach($arr as $k => $v) {
if(is_array($v)) { if(is_array($v)) {
$arr[$k] = htmlentities_on_array($v); $arr[$k] = htmlentities_on_array($v);
} else { } else {

View File

@ -123,7 +123,7 @@
<tr> <tr>
<th colspan="2"><?php print $text_message_disposition; ?></th> <th colspan="2"><?php print $text_message_disposition; ?></th>
</tr> </tr>
<?php while(list($k, $v) = each($health['counters'])) { <?php foreach($health['counters'] as $k => $v) {
if(!is_numeric($k)) { ?> if(!is_numeric($k)) { ?>
<tr> <tr>
<td><?php $a = preg_replace("/^_piler\:/", "", $k); if(isset($$a)) { print $$a; } else { print $k; } ?></td> <td><?php $a = preg_replace("/^_piler\:/", "", $k); if(isset($$a)) { print $$a; } else { print $k; } ?></td>

View File

@ -36,7 +36,7 @@
<label class="control-label" for="ldap_type"><?php print $text_ldap_type; ?>:</label> <label class="control-label" for="ldap_type"><?php print $text_ldap_type; ?>:</label>
<div class="controls"> <div class="controls">
<select name="ldap_type" id="ldap_type" onchange="Piler.fix_ldap_display();" class="span4"> <select name="ldap_type" id="ldap_type" onchange="Piler.fix_ldap_display();" class="span4">
<?php while(list($k, $v) = each($ldap_types)) { ?> <?php foreach($ldap_types as $k => $v) { ?>
<option value="<?php print $v; ?>"<?php if(isset($a['ldap_type']) && $a['ldap_type'] == $v) { ?> selected="selected"<?php } ?>><?php print $v; ?></option> <option value="<?php print $v; ?>"<?php if(isset($a['ldap_type']) && $a['ldap_type'] == $v) { ?> selected="selected"<?php } ?>><?php print $v; ?></option>
<?php } ?> <?php } ?>
</select> </select>

View File

@ -91,7 +91,7 @@
<div class="controls"> <div class="controls">
<select class="ruleselect" name="folder_id"> <select class="ruleselect" name="folder_id">
<option value="0">-</option> <option value="0">-</option>
<?php while(list($k,$v) = each($folders)) { ?> <?php foreach($folders as $k => $v) { ?>
<option value="<?php print $k; ?>"><?php print $v; ?></option> <option value="<?php print $k; ?>"><?php print $v; ?></option>
<?php } ?> <?php } ?>
</select> </select>