Skip to content

Commit c382be2

Browse files
committed
PHP 8.1 compat changes in interface part
1 parent 0a7aee0 commit c382be2

File tree

11 files changed

+110
-58
lines changed

11 files changed

+110
-58
lines changed

install/lib/classes/tpl.inc.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -931,17 +931,12 @@ private function _parseLoop ($varname)
931931
{
932932
array_push($this->_namespace, $varname);
933933
$tempvar = count($this->_namespace) - 1;
934-
$retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < (isset(\$this->_arrvars";
934+
$retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < \$this->_tpl_count(\$this->_arrvars";
935935
for ($i=0; $i < count($this->_namespace); $i++) {
936936
$retstr .= "['".$this->_namespace[$i]."']";
937937
if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]";
938938
}
939-
$retstr .= ") ? count(\$this->_arrvars";
940-
for ($i=0; $i < count($this->_namespace); $i++) {
941-
$retstr .= "['".$this->_namespace[$i]."']";
942-
if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]";
943-
}
944-
return $retstr.") : 0); \$_".$tempvar."++) {";
939+
return $retstr."); \$_".$tempvar."++) {";
945940
}
946941

947942
/**
@@ -1040,7 +1035,7 @@ private function _parseTag ($args)
10401035
$wholetag = $args[0];
10411036
$openclose = $args[1];
10421037
$tag = strtolower($args[2]);
1043-
1038+
10441039
if ($tag == 'else') return '<?php } else { ?>';
10451040
if ($tag == 'tmpl_include') return $wholetag; // ignore tmpl_include tags
10461041

@@ -1281,6 +1276,27 @@ private function _escape_hex($str = '', $entity = false) {
12811276
return $return;
12821277
}
12831278

1279+
/**
1280+
* Used during in evaled code to replace PHP count function for PHP 8 compatibility
1281+
* @var variable to be counted
1282+
*/
1283+
private function _tpl_count($var)
1284+
{
1285+
$retvar = 0;
1286+
if(isset($var)) {
1287+
if(is_array($var)) {
1288+
$retvar = count($var);
1289+
} elseif(is_null($var)) {
1290+
$retvar = 0;
1291+
} else {
1292+
$retvar = 1;
1293+
}
1294+
} else {
1295+
$retvar = 0;
1296+
}
1297+
return $retvar;
1298+
}
1299+
12841300
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
12851301
The following functions have no use and are included just so that if the user
12861302
is making use of vlibTemplateCache functions, this doesn't crash when changed to

interface/lib/classes/db_mysql.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ public function escape($sString) {
526526
$sString = '';
527527
}
528528

529-
$cur_encoding = mb_detect_encoding($sString);
529+
$cur_encoding = mb_detect_encoding($sString, "auto");
530530
if($cur_encoding != "UTF-8") {
531531
if($cur_encoding != 'ASCII') {
532532
if(is_object($app) && method_exists($app, 'log')) $app->log('String ' . substr($sString, 0, 25) . '... is ' . $cur_encoding . '.', LOGLEVEL_DEBUG);

interface/lib/classes/listform.inc.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function loadListDef($file, $module = '')
8080

8181
private function getDatasourceData($field)
8282
{
83-
global $app;
83+
global $app, $api;
8484
$values = array();
8585

8686
if($field['datasource']['type'] == 'SQL') {
@@ -97,7 +97,8 @@ private function getDatasourceData($field)
9797
$querystring = str_replace("{AUTHSQL}", $app->tform->getAuthSQL('r'), $querystring);
9898
$querystring = str_replace("{AUTHSQL-A}", $app->tform->getAuthSQL('r', 'a'), $querystring);
9999
$querystring = str_replace("{AUTHSQL-B}", $app->tform->getAuthSQL('r', 'b'), $querystring);
100-
$querystring = preg_replace_callback('@{AUTHSQL::(.+?)}@', create_function('$matches','global $app; $tmp = $app->tform->getAuthSQL("r", $matches[1]); return $tmp;'), $querystring);
100+
//$querystring = preg_replace_callback('@{AUTHSQL::(.+?)}@', create_function('$matches','global $app; $tmp = $app->tform->getAuthSQL("r", $matches[1]); return $tmp;'), $querystring);
101+
$querystring = preg_replace_callback('@{AUTHSQL::(.+?)}@', function($matches) {global $app; $tmp = $app->tform->getAuthSQL("r", $matches[1]); return $tmp;}, $querystring);
101102

102103
//* Getting the records
103104
$tmp_records = $app->db->queryAllRecords($querystring);
@@ -195,9 +196,9 @@ public function getSearchSQL($sql_where = '')
195196
if(@is_array($this->listDef['item'])) {
196197
foreach($this->listDef['item'] as $i) {
197198
$field = $i['field'];
198-
$table = $i['table'];
199+
$table = (isset($i['table']))?$i['table']:'';
199200

200-
$searchval = $_SESSION['search'][$list_name][$search_prefix.$field];
201+
$searchval = (isset($_SESSION['search'][$list_name][$search_prefix.$field]))?$_SESSION['search'][$list_name][$search_prefix.$field]:'';
201202
// IDN
202203
if($searchval != ''){
203204
if(is_array($i['filters'])) {
@@ -325,7 +326,7 @@ public function getPagingSQL($sql_where = '1')
325326
if($this->searchChanged == 1) $_SESSION['search'][$list_name]['page'] = 0;
326327

327328
$sql_von = $app->functions->intval($_SESSION['search'][$list_name]['page'] * $records_per_page);
328-
$record_count = $app->db->queryOneRecord("SELECT count(*) AS anzahl FROM ??".($app->listform->listDef['additional_tables'] != ''? ','.$app->listform->listDef['additional_tables'] : '')." WHERE $sql_where", $table);
329+
$record_count = $app->db->queryOneRecord("SELECT count(*) AS anzahl FROM ??".(isset($app->listform->listDef['additional_tables']) && $app->listform->listDef['additional_tables'] != ''? ','.$app->listform->listDef['additional_tables'] : '')." WHERE $sql_where", $table);
329330
$pages = $app->functions->intval(($record_count['anzahl'] - 1) / $records_per_page);
330331

331332

interface/lib/classes/listform_actions.inc.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function onLoad()
135135
}
136136
}
137137

138-
if($_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order_in_php']) $php_sort = true;
138+
if(@$_SESSION['search'][$_SESSION['s']['module']['name'].$app->listform->listDef["name"].$app->listform->listDef['table']]['order_in_php']) $php_sort = true;
139139

140140
// Getting Datasets from DB
141141
$records = $app->db->queryAllRecords($this->getQueryString($php_sort));
@@ -226,7 +226,7 @@ public function getQueryString($no_limit = false) {
226226
}
227227

228228
$sql_where = $app->listform->getSearchSQL($sql_where);
229-
if($app->listform->listDef['join_sql']) $sql_where .= ' AND '.$app->listform->listDef['join_sql'];
229+
if(isset($app->listform->listDef['join_sql'])) $sql_where .= ' AND '.$app->listform->listDef['join_sql'];
230230
$app->tpl->setVar($app->listform->searchValues);
231231

232232
$order_by_sql = $this->SQLOrderBy;
@@ -245,16 +245,17 @@ public function getQueryString($no_limit = false) {
245245

246246
$table_selects = array();
247247
$table_selects[] = trim($app->listform->listDef['table']).'.*';
248-
$app->listform->listDef['additional_tables'] = trim($app->listform->listDef['additional_tables']);
249-
if($app->listform->listDef['additional_tables'] != ''){
248+
249+
if(isset($app->listform->listDef['additional_tables']) && trim($app->listform->listDef['additional_tables']) != ''){
250+
$app->listform->listDef['additional_tables'] = trim($app->listform->listDef['additional_tables']);
250251
$additional_tables = explode(',', $app->listform->listDef['additional_tables']);
251252
foreach($additional_tables as $additional_table){
252253
$table_selects[] = trim($additional_table).'.*';
253254
}
254255
}
255256
$select = implode(', ', $table_selects);
256257

257-
$sql = 'SELECT '.$select.$extselect.' FROM '.$app->listform->listDef['table'].($app->listform->listDef['additional_tables'] != ''? ','.$app->listform->listDef['additional_tables'] : '')."$join WHERE $sql_where $order_by_sql";
258+
$sql = 'SELECT '.$select.$extselect.' FROM '.$app->listform->listDef['table'].(isset($app->listform->listDef['additional_tables']) && $app->listform->listDef['additional_tables'] != ''? ','.$app->listform->listDef['additional_tables'] : '')."$join WHERE $sql_where $order_by_sql";
258259
if($no_limit == false) $sql .= " $limit_sql";
259260
//echo $sql;
260261
return $sql;

interface/lib/classes/simplepie.inc.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13186,8 +13186,8 @@ class SimplePie_Parse_Date
1318613186
*/
1318713187
function __construct()
1318813188
{
13189-
$this->day_pcre = '(' . implode(array_keys($this->day), '|') . ')';
13190-
$this->month_pcre = '(' . implode(array_keys($this->month), '|') . ')';
13189+
$this->day_pcre = '(' . implode('|', array_keys($this->day)) . ')';
13190+
$this->month_pcre = '(' . implode('|', array_keys($this->month)) . ')';
1319113191

1319213192
static $cache;
1319313193
if (!isset($cache[get_class($this)]))
@@ -13338,9 +13338,9 @@ function date_w3cdtf($date)
1333813338
}
1333913339

1334013340
// Convert the number of seconds to an integer, taking decimals into account
13341-
$second = @round($match[6] + $match[7] / @pow(10, strlen($match[7])));
13341+
$second = @round((int)$match[6] + (int)$match[7] / @pow(10, strlen($match[7])));
1334213342

13343-
return gmmktime($match[4], $match[5], $second, $match[2], $match[3], $match[1]) - $timezone;
13343+
return gmmktime((int)$match[4], (int)$match[5], (int)$second, (int)$match[2], (int)$match[3], (int)$match[1]) - $timezone;
1334413344
}
1334513345
else
1334613346
{

interface/lib/classes/system.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class system {
3333
var $client_service = null;
3434
private $_last_exec_out = null;
3535
private $_last_exec_retcode = null;
36+
private $server_count = null;
3637

3738
public function has_service($userid, $service) {
3839
global $app;

interface/lib/classes/tform_base.inc.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ protected function _getDatasourceData($field, $record, $api = false) {
276276
unset($tmp_recordid);
277277

278278
$querystring = str_replace("{AUTHSQL}", $this->getAuthSQL('r'), $querystring);
279-
$querystring = preg_replace_callback('@{AUTHSQL::(.+?)}@', create_function('$matches','global $app; $tmp = $app->tform->getAuthSQL("r", $matches[1]); return $tmp;'), $querystring);
279+
//$querystring = preg_replace_callback('@{AUTHSQL::(.+?)}@', create_function('$matches','global $app; $tmp = $app->tform->getAuthSQL("r", $matches[1]); return $tmp;'), $querystring);
280+
$querystring = preg_replace_callback('@{AUTHSQL::(.+?)}@', function($matches) {global $app; $tmp = $app->tform->getAuthSQL("r", $matches[1]); return $tmp;}, $querystring);
280281

281282
// Getting the records
282283
$tmp_records = $app->db->queryAllRecords($querystring);

interface/lib/classes/tpl.inc.php

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function newTemplate($tmplfile)
233233
public function setVar($k, $v = null, $encode = false)
234234
{
235235
global $app;
236-
236+
237237
if (is_array($k)) {
238238
foreach($k as $key => $value){
239239
$key = ($this->OPTIONS['CASELESS']) ? strtolower(trim($key)) : trim($key);
@@ -1079,12 +1079,12 @@ private function _parseIf($varname, $value = null, $op = null, $namespace = null
10791079
private function _parseHook ($name)
10801080
{
10811081
global $app;
1082-
1082+
10831083
if(!$name) return false;
1084-
1084+
10851085
$module = isset($_SESSION['s']['module']['name']) ? $_SESSION['s']['module']['name'] : '';
10861086
$form = isset($app->tform->formDef['name']) ? $app->tform->formDef['name'] : '';
1087-
1087+
10881088
$events = array();
10891089
if($module) {
10901090
$events[] = $module . ':' . ($form ? $form : '') . ':' . $name;
@@ -1093,9 +1093,9 @@ private function _parseHook ($name)
10931093
$events[] = $name;
10941094
$events[] = 'on_template_content';
10951095
}
1096-
1096+
10971097
$events = array_unique($events);
1098-
1098+
10991099
for($e = 0; $e < count($events); $e++) {
11001100
$tmpresult = $app->plugin->raiseEvent($events[$e], array(
11011101
'name' => $name,
@@ -1104,10 +1104,10 @@ private function _parseHook ($name)
11041104
), true);
11051105
if(!$tmpresult) $tmpresult = '';
11061106
else $tmpresult = $this->_getData($tmpresult, false, true);
1107-
1107+
11081108
$result .= $tmpresult;
11091109
}
1110-
1110+
11111111
return $result;
11121112
}
11131113

@@ -1121,17 +1121,12 @@ private function _parseLoop ($varname)
11211121
{
11221122
array_push($this->_namespace, $varname);
11231123
$tempvar = count($this->_namespace) - 1;
1124-
$retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < (isset(\$this->_arrvars";
1125-
for ($i=0; $i < count($this->_namespace); $i++) {
1126-
$retstr .= "['".$this->_namespace[$i]."']";
1127-
if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]";
1128-
}
1129-
$retstr .= ") ? count(\$this->_arrvars";
1124+
$retstr = "for (\$_".$tempvar."=0 ; \$_".$tempvar." < \$this->_tpl_count(\$this->_arrvars";
11301125
for ($i=0; $i < count($this->_namespace); $i++) {
11311126
$retstr .= "['".$this->_namespace[$i]."']";
11321127
if ($this->_namespace[$i] != $varname) $retstr .= "[\$_".$i."]";
11331128
}
1134-
return $retstr.") : 0); \$_".$tempvar."++) {";
1129+
return $retstr."); \$_".$tempvar."++) {";
11351130
}
11361131

11371132
/**
@@ -1230,7 +1225,7 @@ private function _parseTag ($args)
12301225
$wholetag = $args[0];
12311226
$openclose = $args[1];
12321227
$tag = strtolower($args[2]);
1233-
1228+
12341229
if ($tag == 'else') return '<?php } else { ?>';
12351230
if ($tag == 'tmpl_include') return $wholetag; // ignore tmpl_include tags
12361231

@@ -1308,10 +1303,10 @@ private function _parseTag ($args)
13081303
if ($this->OPTIONS['ENABLE_PHPINCLUDE']) {
13091304
return '<?php include(\''.$file.'\'); ?>';
13101305
}
1311-
1306+
13121307
case 'hook':
13131308
return $this->_parseHook(@$var);
1314-
1309+
13151310
case 'include':
13161311
return '<?php $this->_getData($this->_fileSearch(\''.$file.'\'), 1); ?>';
13171312

@@ -1466,6 +1461,27 @@ private function _escape_hex($str = '', $entity = false) {
14661461
return $return;
14671462
}
14681463

1464+
/**
1465+
* Used during in evaled code to replace PHP count function for PHP 8 compatibility
1466+
* @var variable to be counted
1467+
*/
1468+
private function _tpl_count($var)
1469+
{
1470+
$retvar = 0;
1471+
if(isset($var)) {
1472+
if(is_array($var)) {
1473+
$retvar = count($var);
1474+
} elseif(is_null($var)) {
1475+
$retvar = 0;
1476+
} else {
1477+
$retvar = 1;
1478+
}
1479+
} else {
1480+
$retvar = 0;
1481+
}
1482+
return $retvar;
1483+
}
1484+
14691485
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14701486
The following functions have no use and are included just so that if the user
14711487
is making use of vlibTemplateCache functions, this doesn't crash when changed to

interface/web/dashboard/dashlets/limits.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,13 @@ public function show()
169169
}
170170
if ($value != 0 || $value == $wb['unlimited_txt']) {
171171
$value_formatted = ($value == '-1')?$wb['unlimited_txt']:$value;
172-
if ($limit['q_type']!='') {
172+
if (isset($limit['q_type']) && $limit['q_type'] != '') {
173173
$usage = $this->_get_assigned_quota($limit) . " MB";
174174
$value_formatted = ($value == '-1')?$wb['unlimited_txt']:$value . " MB";
175175
} else {
176176
$usage = $this->_get_limit_usage($limit);
177177
}
178-
$percentage = ($value == '-1' || $value == 0 ? -1 : round(100 * $usage / $value));
178+
$percentage = ($value == '-1' || intval($value) == 0 || trim($value) == '' ? -1 : round(100 * (int)$usage / (int)$value));
179179
$progressbar = $percentage > 100 ? 100 : $percentage;
180180
$rows[] = array('field' => $field,
181181
'field_txt' => $wb[$field.'_txt'],

server/lib/classes/cron.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public function getNextRun($vDate) {
246246
$ts = mktime($iHour, $iMinute, 0, $iMonth, $iDay, $iYear);
247247
//print strftime('%d.%m.%Y (%A) %H:%M', $ts) . "\n";
248248
//var_dump($iCurMinute, $iCurHour, $iCurDay, $iCurMonth, $iCurWDay, '--', $iNextMinute, $iNextHour, $iNextDay, $iNextMonth, $iNextWDay);
249-
if(ISPConfigDateTime::last_day($iMonth, $iYear) >= $iDay && in_array($app->functions->intval(strftime('%w', $ts)), $this->_aValidValues['weekday'], true) === true) {
249+
if(ISPConfigDateTime::last_day($iMonth, $iYear) >= $iDay && in_array($app->functions->intval(date('w', $ts)), $this->_aValidValues['weekday'], true) === true) {
250250
$bValid = true;
251251
} else {
252252
if($iYear - $iStartYear > 5) {

0 commit comments

Comments
 (0)