Fix warnings in PHP 8

This commit is contained in:
Anna Dabrowska
2022-12-07 13:54:29 +01:00
parent bf1a58f309
commit c6996533a5
5 changed files with 113 additions and 43 deletions

View File

@ -14,6 +14,6 @@ require_once(DOKU_INC . 'inc/init.php');
$graph = plugin_load('helper', 'statdisplay_graph'); $graph = plugin_load('helper', 'statdisplay_graph');
$graph->sendgraph( $graph->sendgraph(
$_REQUEST['graph'], $_REQUEST['graph'],
$_REQUEST['f'], $_REQUEST['f'] ?? '',
$_REQUEST['to'] $_REQUEST['t'] ?? ''
); );

View File

@ -70,15 +70,15 @@ class helper_plugin_statdisplay_graph extends DokuWiki_Plugin
$visitors = array(); $visitors = array();
foreach ($this->log->logdata as $month => $data) { foreach ($this->log->logdata as $month => $data) {
if ($month{0} == '_') continue; if ($month[0] == '_') continue;
if ($from && $month < $from) continue; if ($from && $month < $from) continue;
if ($to && $month > $to) break; if ($to && $month > $to) break;
$times[] = $month; $times[] = $month;
$pages[] = $data['page']['all']['count']; $pages[] = $data['page']['all']['count'] ?? 0;
$media[] = $data['media']['all']['count']; $media[] = $data['media']['all']['count'] ?? 0;
$hits[] = $data['hits']['all']['count']; $hits[] = $data['hits']['all']['count'] ?? 0;
$visitors[] = $data['hits']['all']['visitor']; $visitors[] = $data['hits']['all']['visitor'] ?? 0;
} }
$title = $this->getLang('t_summary'); $title = $this->getLang('t_summary');

View File

@ -51,11 +51,11 @@ class helper_plugin_statdisplay_log extends DokuWiki_Plugin
*/ */
public function progress() public function progress()
{ {
$pos = (int)$this->logdata['_logpos']; $pos = $this->logdata['_logpos'] ?? 0;
$max = @filesize($this->logfile); $max = @filesize($this->logfile);
if (!$max) return 100.0; if (!$max) return 100.0;
return $pos * 100 / $max; return (int)$pos * 100 / $max;
} }
/** /**
@ -125,7 +125,11 @@ class helper_plugin_statdisplay_log extends DokuWiki_Plugin
// remember IPs // remember IPs
$newvisitor = !isset($this->logdata[$month]['ip'][$parts[0]]); $newvisitor = !isset($this->logdata[$month]['ip'][$parts[0]]);
$this->logdata[$month]['ip'][$parts[0]]++; if ($newvisitor) {
$this->logdata[$month]['ip'][$parts[0]] = 1;
} else {
$this->logdata[$month]['ip'][$parts[0]]++;
}
// log type dependent and summarized // log type dependent and summarized
foreach (array($thistype, 'hits') as $type) { foreach (array($thistype, 'hits') as $type) {
@ -134,66 +138,129 @@ class helper_plugin_statdisplay_log extends DokuWiki_Plugin
$this->logdata[$month][$type]['hour'] = array_fill(0, 23, array()); $this->logdata[$month][$type]['hour'] = array_fill(0, 23, array());
} }
$this->logdata[$month][$type]['all']['count']++; $this->logdata[$month][$type]['all']['count'] =
$this->logdata[$month][$type]['day'][$day]['count']++; isset($this->logdata[$month][$type]['all']['count']) ?
$this->logdata[$month][$type]['hour'][$hour]['count']++; $this->logdata[$month][$type]['all']['count'] + 1 :
1;
$this->logdata[$month][$type]['day'][$day]['count'] =
isset($this->logdata[$month][$type]['day'][$day]['count']) ?
$this->logdata[$month][$type]['day'][$day]['count'] + 1 :
1;
$this->logdata[$month][$type]['hour'][$hour]['count'] =
isset($this->logdata[$month][$type]['hour'][$hour]['count']) ?
$this->logdata[$month][$type]['hour'][$hour]['count'] + 1 :
1;
$this->logdata[$month][$type]['all']['bytes'] += $size; $this->logdata[$month][$type]['all']['bytes'] =
$this->logdata[$month][$type]['day'][$day]['bytes'] += $size; isset($this->logdata[$month][$type]['all']['bytes']) ?
$this->logdata[$month][$type]['hour'][$hour]['bytes'] += $size; $this->logdata[$month][$type]['all']['bytes'] + $size :
$size;
$this->logdata[$month][$type]['day'][$day]['bytes'] =
isset($this->logdata[$month][$type]['day'][$day]['bytes']) ?
$this->logdata[$month][$type]['day'][$day]['bytes'] + $size
: $size;
$this->logdata[$month][$type]['hour'][$hour]['bytes'] =
isset($this->logdata[$month][$type]['hour'][$hour]['bytes']) ?
$this->logdata[$month][$type]['hour'][$hour]['bytes'] + $size :
$size;
if ($user) { if ($user) {
$this->logdata[$month]['usertraffic'][$day][$user] += $size; $this->logdata[$month]['usertraffic'][$day][$user] =
isset($this->logdata[$month]['usertraffic'][$day][$user]) ?
$this->logdata[$month]['usertraffic'][$day][$user] + $size :
$size;
} }
if ($newvisitor) { if ($newvisitor) {
$this->logdata[$month][$type]['all']['visitor']++; $this->logdata[$month][$type]['all']['visitor'] =
$this->logdata[$month][$type]['day'][$day]['visitor']++; isset($this->logdata[$month][$type]['all']['visitor']) ?
$this->logdata[$month][$type]['hour'][$hour]['visitor']++; $this->logdata[$month][$type]['all']['visitor'] + 1 :
1;
$this->logdata[$month][$type]['day'][$day]['visitor'] =
isset($this->logdata[$month][$type]['day'][$day]['visitor']) ?
$this->logdata[$month][$type]['day'][$day]['visitor'] + 1 :
1;
$this->logdata[$month][$type]['hour'][$hour]['visitor'] =
isset($this->logdata[$month][$type]['hour'][$hour]['visitor']) ?
$this->logdata[$month][$type]['hour'][$hour]['visitor'] + 1 :
1;
} }
} }
// log additional detailed data // log additional detailed data
if ($thistype == 'page') { if ($thistype == 'page') {
// url // url
$this->logdata[$month]['page_url'][$url]++; $this->logdata[$month]['page_url'][$url] =
isset($this->logdata[$month]['page_url'][$url]) ?
$this->logdata[$month]['page_url'][$url] + 1 :
1;
// referer // referer
$referer = trim($parts[10], '"'); $referer = trim($parts[10], '"');
// skip non valid and local referers // skip non valid and local referers
if (substr($referer, 0, 4) == 'http' && (strpos($referer, DOKU_URL) !== 0)) { if (substr($referer, 0, 4) == 'http' && (strpos($referer, DOKU_URL) !== 0)) {
list($referer) = explode('?', $referer); list($referer) = explode('?', $referer);
$this->logdata[$month]['referer']['count']++; $this->logdata[$month]['referer']['count'] =
$this->logdata[$month]['referer_url'][$referer]++; isset($this->logdata[$month]['referer']['count']) ?
$this->logdata[$month]['referer']['count'] + 1 :
1;
$this->logdata[$month]['referer_url'][$referer] =
isset($this->logdata[$month]['referer_url'][$referer]) ?
$this->logdata[$month]['referer_url'][$referer] + 1 :
1;
} }
// entry page // entry page
if ($newvisitor) { if ($newvisitor) {
$this->logdata[$month]['entry'][$url]++; $this->logdata[$month]['entry'][$url] =
isset($this->logdata[$month]['entry'][$url]) ?
$this->logdata[$month]['entry'][$url] + 1 :
1;
} }
// user agent // user agent
$ua = trim(join(' ', array_slice($parts, 11)), '" '); $ua = trim(join(' ', array_slice($parts, 11)), '" ');
if ($ua) { if ($ua) {
$ua = $this->ua($ua); $ua = $this->ua($ua);
$this->logdata[$month]['useragent'][$ua]++; $this->logdata[$month]['useragent'][$ua] =
isset($this->logdata[$month]['useragent'][$ua]) ?
$this->logdata[$month]['useragent'][$ua] + 1 :
1;
} }
} }
} else { } else {
// count non-200 as a hit too // count non-200 as a hit too
$this->logdata[$month]['hits']['all']['count']++; $this->logdata[$month]['hits']['all']['count'] =
$this->logdata[$month]['hits']['day'][$day]['count']++; isset($this->logdata[$month]['hits']['all']['count']) ?
$this->logdata[$month]['hits']['hour'][$hour]['count']++; $this->logdata[$month]['hits']['all']['count'] + 1 :
1;
$this->logdata[$month]['hits']['day'][$day]['count'] =
isset($this->logdata[$month]['hits']['day'][$day]['count']) ?
$this->logdata[$month]['hits']['day'][$day]['count'] + 1 :
1;
$this->logdata[$month]['hits']['hour'][$hour]['count'] =
isset($this->logdata[$month]['hits']['hour'][$hour]['count']) ?
$this->logdata[$month]['hits']['hour'][$hour]['count'] + 1 :
1;
} }
$this->logdata[$month]['status']['all'][$status]++; $this->logdata[$month]['status']['all'][$status] =
$this->logdata[$month]['status']['day'][$day][$status]++; isset($this->logdata[$month]['status']['all'][$status]) ?
$this->logdata[$month]['status']['hour'][$hour][$status]++; $this->logdata[$month]['status']['all'][$status] + 1 :
1;
$this->logdata[$month]['status']['day'][$day][$status] =
isset($this->logdata[$month]['status']['day'][$day][$status]) ?
$this->logdata[$month]['status']['day'][$day][$status] + 1 :
1;
$this->logdata[$month]['status']['hour'][$hour][$status] =
isset($this->logdata[$month]['status']['hour'][$hour][$status]) ?
$this->logdata[$month]['status']['hour'][$hour][$status] + 1 :
1;
} }
$this->logdata['_logpos'] = $pos; $this->logdata['_logpos'] = $pos;
// clean up the last month, freeing memory // clean up the last month, freeing memory
if (isset($month) && $this->logdata['_lastmonth'] != $month) { if (isset($month) && isset($this->logdata['_lastmonth']) && $this->logdata['_lastmonth'] != $month) {
$this->clean_month($this->logdata['_lastmonth']); $this->clean_month($this->logdata['_lastmonth']);
$this->logdata['_lastmonth'] = $month; $this->logdata['_lastmonth'] = $month;
} }
@ -345,7 +412,7 @@ class helper_plugin_statdisplay_log extends DokuWiki_Plugin
foreach ((array)$input as $item) { foreach ((array)$input as $item) {
if (is_null($key)) { if (is_null($key)) {
$all += $item; $all += $item;
} else { } elseif (isset($item[$key])) {
$all += $item[$key]; $all += $item[$key];
} }
$cnt++; $cnt++;

View File

@ -313,18 +313,21 @@ class helper_plugin_statdisplay_table extends DokuWiki_Plugin
$this->R->tablerow_close(); $this->R->tablerow_close();
foreach ((array)$this->log->logdata as $month => $data) { foreach ((array)$this->log->logdata as $month => $data) {
if ($month{0} == '_') continue; if ($month[0] == '_') continue;
if ($from && $month < $from) continue; if (!empty($from) && $month < $from) continue;
if ($to && $month > $to) break; if (!empty($to) && $month > $to) break;
$this->R->tablerow_open(); $this->R->tablerow_open();
$this->cell($month, 1, false); // Month $this->cell($month, 1, false); // Month
// ---- averages ---- // ---- averages ----
$this->cell(round($this->log->avg($data['hits']['day'], 'count'))); // Hits $this->cell(round($this->log->avg($data['hits']['day'] ?? [], 'count'))); // Hits
$this->cell(round($this->log->avg($data['media']['day'], 'count'))); // Files $this->cell(round($this->log->avg($data['media']['day'] ?? [], 'count'))); // Files
$this->cell(round($this->log->avg($data['page']['day'], 'count'))); // Pages $this->cell(round($this->log->avg($data['page']['day'] ?? [], 'count'))); // Pages
$this->cell(round($this->log->avg($data['hits']['day'], 'visitor'))); // Visits $this->cell(round($this->log->avg($data['hits']['day'] ?? [], 'visitor'))); // Visits
// ---- totals ---- // ---- totals ----
$this->cell($data['hits']['all']['count']); // Hits $this->cell($data['hits']['all']['count']); // Hits
$this->cell($data['media']['all']['count']); // Files $this->cell($data['media']['all']['count']); // Files

View File

@ -36,7 +36,7 @@ class syntax_plugin_statdisplay extends DokuWiki_Syntax_Plugin
function handle($match, $state, $pos, Doku_Handler $handler) function handle($match, $state, $pos, Doku_Handler $handler)
{ {
$command = trim(substr($match, 14, -2)); $command = trim(substr($match, 14, -2));
list($command, $params) = explode('?', $command); list($command, $params) = array_pad(explode('?', $command), 2, '');
$params = explode(' ', $params); $params = explode(' ', $params);
$params = array_map('trim', $params); $params = array_map('trim', $params);
@ -51,7 +51,7 @@ class syntax_plugin_statdisplay extends DokuWiki_Syntax_Plugin
} }
// remaining params are dates // remaining params are dates
list($from, $to) = array_values($params); list($from, $to) = array_pad(array_values($params), 2, '');
return [ return [
'command' => $command, 'command' => $command,
@ -93,7 +93,7 @@ class syntax_plugin_statdisplay extends DokuWiki_Syntax_Plugin
private function cleanDate($date) private function cleanDate($date)
{ {
$months = array('', 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'); $months = array('', 'jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec');
list($month, $year) = explode('_', strtolower($date)); list($month, $year) = array_pad(explode('_', strtolower($date)), 2, '');
$year = (int)$year; $year = (int)$year;
if ($year < 2000 || $year > 2050) return ''; if ($year < 2000 || $year > 2050) return '';
$month = array_search($month, $months); $month = array_search($month, $months);