PHP 8: Handle more errors explicitly

The error control operator "@" has changed behavior in PHP8 and generally seems
like a quite bad hack. So let's handle array/ dict access errors explicitly.
This commit is contained in:
Jannik Beyerstedt 2023-07-18 22:28:38 +02:00
parent 1cd3e2b60b
commit dc57652519
12 changed files with 62 additions and 33 deletions

View file

@ -24,11 +24,11 @@ $GLOBALS['CONFIG']['PREVIEW_DOMAIN'] = 'xlocalhost';
* Protokollfreie URLs (welche, die mit // beginnen), werden automatisch mit dem korrekten Protokoll ergänzt.
* In diesem Fall wird auch ein SSL-Umschalt-Button im Header angezeigt
*/
if(@$_SERVER['SERVER_NAME'] == 'localhost' || @$_SERVER['SERVER_NAME'] == '0.0.0.0')
if(isset($_SERVER['SERVER_NAME']) && ($_SERVER['SERVER_NAME'] == 'localhost' || $_SERVER['SERVER_NAME'] == '0.0.0.0'))
{
// keine Konfiguration -> BASEURL wird automatisch erraten
}
else if(@$_SERVER['SERVER_NAME'] == 'streaming.test.c3voc.de')
else if(isset($_SERVER['SERVER_NAME']) && ($_SERVER['SERVER_NAME'] == 'streaming.test.c3voc.de'))
{
$GLOBALS['CONFIG']['BASEURL'] = '//streaming.test.c3voc.de/';
}

View file

@ -52,11 +52,11 @@ if(isset($argv) && isset($argv[1]))
try {
if(isset($_GET['htaccess']))
{
$route = @$_GET['route'];
$route = isset($_GET['route']) ? $_GET['route'] : "";
}
elseif(isset($_SERVER["REQUEST_URI"]))
{
$route = ltrim(@$_SERVER["REQUEST_URI"], '/');
$route = ltrim($_SERVER["REQUEST_URI"], '/');
// serve static
if($route != '' && file_exists($_SERVER["DOCUMENT_ROOT"].'/'.$route))
@ -87,11 +87,12 @@ try {
'conference' => new GenericConference(),
));
if(isset($GLOBALS['CONFIG']['BASEURL']) && startswith('//', @$GLOBALS['CONFIG']['BASEURL']))
if(isset($GLOBALS['CONFIG']['BASEURL']) && startswith('//', $GLOBALS['CONFIG']['BASEURL']))
{
$mandator = isset($GLOBALS['MANDATOR']) ? $GLOBALS['MANDATOR'] : "";
$tpl->set(array(
'httpsurl' => forceslash(forceslash('https:'.$GLOBALS['CONFIG']['BASEURL']).@$GLOBALS['MANDATOR']).forceslash($route).url_params(),
'httpurl' => forceslash(forceslash('http:'. $GLOBALS['CONFIG']['BASEURL']).@$GLOBALS['MANDATOR']).forceslash($route).url_params(),
'httpsurl' => forceslash(forceslash('https:'.$GLOBALS['CONFIG']['BASEURL']).$mandator).forceslash($route).url_params(),
'httpurl' => forceslash(forceslash('http:'. $GLOBALS['CONFIG']['BASEURL']).$mandator).forceslash($route).url_params(),
));
}

View file

@ -247,5 +247,17 @@ function query_data($operation, $query, $variables = [], $assoc = false, $cache
// TODO: add error handling?
// TODO: should we return the cached value, when we did not get an answer?
return $assoc ? @$r['data'] : @$r->data;
if ($assoc) {
if (isset($r['data'])) {
return $r['data'];
} else {
throw new NotFoundException();
}
} else {
if (isset($r->data)) {
return $r->data;
} else {
throw new NotFoundException();
}
}
}

View file

@ -20,7 +20,7 @@ class Conference extends ModelBase
}
public function isPreviewEnabled() {
if(@$GLOBALS['forceopen'])
if(isset($GLOBALS['forceopen']) && $GLOBALS['forceopen'])
return true;
if($this->has('PREVIEW_DOMAIN') && ($this->get('PREVIEW_DOMAIN') == $_SERVER['SERVER_NAME']))

View file

@ -12,10 +12,16 @@ class ConferenceJson extends Conference
$c = $json->conference;
$this->start = DateTime::createFromFormat(DateTimeInterface::ISO8601, $c->start);
$this->end = DateTime::createFromFormat(DateTimeInterface::ISO8601, $c->end);
$this->html = @$c->streamingConfig->html ?: [];
$this->html = isset($c->streamingConfig->html) ? $c->streamingConfig->html : [];
$this->rooms = [];
$rooms = (is_array(@$c->rooms) ? $c->rooms : @$c->rooms->nodes) ?: [];
if (isset($c->rooms)) {
if (is_array($c->rooms)) {
$rooms = $c->rooms;
} else {
$rooms = isset($c->rooms->nodes) ? $c->rooms->nodes : [];
}
}
foreach($rooms as $r) {
if (!$r) {
continue;
@ -23,15 +29,15 @@ class ConferenceJson extends Conference
$this->rooms[$r->slug] = array_merge(
['stream' => $r->streamId],
get_object_vars($r),
@get_object_vars($r->streamingConfig) ?: [],
@get_object_vars($r->streamingConfig->chat) ?: []
(isset($r->streamingConfig) ? get_object_vars($r->streamingConfig) : []),
(isset($r->streamingConfig->chat) ? get_object_vars($r->streamingConfig->chat) : [])
);
}
$groups = [];
if ( isset($c->streamingConfig->overviewPage->sections) ) {
foreach(@$c->streamingConfig->overviewPage->sections as $s) {
$groups[@$s->title] = array_map(
foreach($c->streamingConfig->overviewPage->sections as $s) {
$groups[$s->title] = array_map(
function($r) { return $r->slug; },
@$s->items ?: @$s->rooms ?: []
);
@ -44,15 +50,15 @@ class ConferenceJson extends Conference
$acronym = $mandator ?: $c->acronym;
parent::__construct(array_merge(
@get_object_vars($c->streamingConfig) ?: [],
@get_object_vars($c->streamingConfig->features) ?: [],
@get_object_vars($c->streamingConfig->features->chat) ?: [],
isset($c->streamingConfig) ? get_object_vars($c->streamingConfig) : [],
isset($c->streamingConfig->features) ? get_object_vars($c->streamingConfig->features) : [],
isset($c->streamingConfig->features->chat) ? get_object_vars($c->streamingConfig->features->chat) : [],
[
'conference' => [
'title' => $c->title,
'author' => $c->organizer,
'description' => $c->description,
'keywords' => @implode(', ', $c->keywords),
'keywords' => is_array($c->keywords) ? implode(', ', $c->keywords) : "",
// future TODO: change structure
"relive_json" => @$c->streamingConfig->features->relive !== false ? "https://cdn.c3voc.de/relive/".$acronym."/index.json" : null,
"releases" => @$c->streamingConfig->features->releases !== false ? "https://media.ccc.de/c/".$acronym : null
@ -140,21 +146,21 @@ class ConferenceJson extends Conference
return !empty($this->html->banner);
}
public function getBannerHtml() {
return @$this->html->banner;
return isset($this->html->banner) ? $this->html->banner : "";
}
public function hasFooterHtml() {
return !empty($this->html->footer);
}
public function getFooterHtml() {
return @$this->html->footer;
return isset($this->html->footer) ? $this->html->footer : "";
}
public function hasNotStartedHtml() {
return !empty($this->html->not_started);
}
public function getNotStartedHtml() {
return @$this->html->not_started;
return isset($this->html->not_started) ? $this->html->not_started : "";
}
}

View file

@ -65,7 +65,8 @@ class Conferences
}
public static function getLastConference() {
return @Conferences::getFinishedConferencesSorted()[0];
$conferences = Conferences::getFinishedConferencesSorted();
return isset($conferences[0]) ? $conferences[0] : null;
}
public static function exists($mandator) {
@ -133,7 +134,7 @@ class Conferences
}
// config option for dynamic lookup feature defined below
if (!@$GLOBALS['CONFIG']['DYNAMIC_LOOKUP']) {
if (isset($GLOBALS['CONFIG']['DYNAMIC_LOOKUP']) && !$GLOBALS['CONFIG']['DYNAMIC_LOOKUP']) {
throw new NotFoundException();;
}

View file

@ -10,9 +10,10 @@ class Feedback
}
private function get($key) {
$global_feedback_elem = isset($GLOBALS['CONFIG']['FEEDBACK'][$key]) ? $GLOBALS['CONFIG']['FEEDBACK'][$key] : "";
return $this->conference->has(['FEEDBACK', $key])
? $this->conference->get(['FEEDBACK', $key])
: @$GLOBALS['CONFIG']['FEEDBACK'][$key];
: $global_feedback_elem;
}
public function getConference() {

View file

@ -364,7 +364,15 @@ class Schedule
$this->mapping = array();
foreach($this->getConference()->get('ROOMS') as $slug => $room)
{
$key = @$room['name'] ?: @$room['SCHEDULE_NAME'] ?: @$room['DISPLAY'] ?: $slug;
// json has 'name', config.php has 'SCHEDULE_NAME' and 'DISPLAY'
$key = $slug;
if (isset($room['name'])) {
$key = $room['name'];
} elseif ($room['SCHEDULE_NAME']) {
$key = $room['SCHEDULE_NAME'];
} elseif ($room['DISPLAY']) {
$key = $room['DISPLAY'];
}
$this->mapping[$key] = $slug;
}
}

View file

@ -6,7 +6,7 @@ echo $tpl->render(array(
'page' => 'allclosed',
'title' => 'See you soon … somewhere else!',
'next' => @$events[0],
'next' => isset($events[0]) ? $events[0] : null,
'events' => $events,
'last' => Conferences::getLastConference(),
));

View file

@ -6,6 +6,6 @@ echo $tpl->render(array(
'page' => 'closed',
'title' => 'See you soon … somewhere else!',
'next' => @$events[0],
'next' => isset($events[0]) ? $events[0] : null,
'events' => $events,
));

View file

@ -28,5 +28,5 @@ echo $tpl->render(array(
'room' => $room,
'stream' => $stream,
'autoplay' => @$_GET['autoplay'],
'autoplay' => isset($_GET['autoplay']) ? $_GET['autoplay'] : false,
));

View file

@ -5,5 +5,5 @@ echo $tpl->render(array(
'title' => 'Stream-Übersicht',
'rooms' => $conference->getRooms(),
'selection' => @$_GET['selection'],
'selection' => isset($_GET['selection']) ? $_GET['selection'] : "",
));