From 95c3c6f30b2c0a207f108c2aa59aa73ef9728de7 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Mon, 17 May 2021 12:42:24 +0200 Subject: [PATCH] Make sure the Status app hooks methods are there before calling them --- calendar/inc/class.calendar_boupdate.inc.php | 10 +++--- calendar/inc/class.calendar_hooks.inc.php | 35 +++++++++++++++++++- calendar/inc/class.calendar_uiforms.inc.php | 2 +- calendar/inc/class.calendar_uilist.inc.php | 6 ++-- calendar/inc/class.calendar_uiviews.inc.php | 3 +- 5 files changed, 44 insertions(+), 12 deletions(-) diff --git a/calendar/inc/class.calendar_boupdate.inc.php b/calendar/inc/class.calendar_boupdate.inc.php index 4d53301838..1dc9269283 100644 --- a/calendar/inc/class.calendar_boupdate.inc.php +++ b/calendar/inc/class.calendar_boupdate.inc.php @@ -235,8 +235,7 @@ class calendar_boupdate extends calendar_bo } // generate a video-room-url, if we need one and not already have one - if ($event['videoconference'] && empty($event['##videoconference']) && class_exists('EGroupware\\Status\\Videoconference\\Call') - && !EGroupware\Status\Hooks::isVideoconferenceDisabled()) + if ($event['videoconference'] && empty($event['##videoconference']) && !calendar_hooks::isVideoconferenceDisabled()) { $event['##videoconference'] = EGroupware\Status\Videoconference\Call::genUniqueRoomID(); } @@ -245,8 +244,8 @@ class calendar_boupdate extends calendar_bo $event['##videoconference'] = ''; } // update videoconference resource amounts based on number of participants - if ($event['videoconference'] && !empty($event['##videoconference']) && class_exists('EGroupware\\Status\\Videoconference\\Call') - && !EGroupware\Status\Hooks::isVideoconferenceDisabled() && ($videoconferenceResId = \EGroupware\Status\Hooks::getVideoconferenceResourceId())) + if ($event['videoconference'] && !empty($event['##videoconference']) && !calendar_hooks::isVideoconferenceDisabled() + && ($videoconferenceResId = \EGroupware\Status\Hooks::getVideoconferenceResourceId())) { $participant_total = 0; foreach(['u','e','c'] as $p_type) @@ -1107,8 +1106,7 @@ class calendar_boupdate extends calendar_bo $details['olddate'] = $olddate->format($timeformat); } // generate a personal videoconference url, if we need one - if (!empty($event['##videoconference']) && class_exists('EGroupware\\Status\\Videoconference\\Call') - && !EGroupware\Status\Hooks::isVideoconferenceDisabled()) + if (!empty($event['##videoconference']) && !calendar_hooks::isVideoconferenceDisabled()) { $avatar = new Api\Contacts\Photo(is_numeric($userid) ? "account:$userid" : (isset($res_info) && $res_info['type'] === 'c' ? $res_info['res_id'] : $userid), diff --git a/calendar/inc/class.calendar_hooks.inc.php b/calendar/inc/class.calendar_hooks.inc.php index 935672ebc5..612789dccb 100644 --- a/calendar/inc/class.calendar_hooks.inc.php +++ b/calendar/inc/class.calendar_hooks.inc.php @@ -904,7 +904,7 @@ END:VALARM'; if ($params['data']['type'] == 6) { if (!empty($params['data']['videoconference']) - && $GLOBALS['egw_info']['user']['apps']['status'] && !EGroupware\Status\Hooks::isVideoconferenceDisabled()) + && !self::isVideoconferenceDisabled()) { return [ array( @@ -938,6 +938,39 @@ END:VALARM'; ) ); } + + /** + * Wrapper function to check Status app videoconference status + * it makes sure first the Status app is there before calling its method. + * + * @return false|mixed + */ + public static function isVideoconferenceDisabled() + { + if ($GLOBALS['egw_info']['user']['apps']['status'] && class_exists(\EGroupware\Status\Hooks::class) + && method_exists(\EGroupware\Status\Hooks::class, 'isVideoconferenceDisabled')) + { + return EGroupware\Status\Hooks::isVideoconferenceDisabled(); + } + return true; + } + + /** + * Wrapper function to check Status app videoConference recording status + * it makes sure first the Status app is there before calling its method. + * + * @return bool + */ + public static function isVCRecordingSupported() + { + if ($GLOBALS['egw_info']['user']['apps']['status'] && class_exists(\EGroupware\Status\Hooks::class) + && method_exists(\EGroupware\Status\Hooks::class, 'isVCRecordingSupported')) + { + return EGroupware\Status\Hooks::isVCRecordingSupported(); + } + return false; + } + } // Not part of the class, since config hooks are still using the old style diff --git a/calendar/inc/class.calendar_uiforms.inc.php b/calendar/inc/class.calendar_uiforms.inc.php index b6f3aef93e..4e790c7e74 100644 --- a/calendar/inc/class.calendar_uiforms.inc.php +++ b/calendar/inc/class.calendar_uiforms.inc.php @@ -1957,7 +1957,7 @@ class calendar_uiforms extends calendar_ui if (!empty($preserved['lock_token'])) $content['lock_token'] = $preserved['lock_token']; //Disable videoconference if the module is not enabled - $etpl->disableElement('videoconference', $GLOBALS['egw_info']['user']['apps']['status'] && EGroupware\Status\Hooks::isVideoconferenceDisabled()); + $etpl->disableElement('videoconference', calendar_hooks::isVideoconferenceDisabled()); // non_interactive==true from $_GET calls immediate save action without displaying the edit form if(isset($_GET['non_interactive']) && (bool)$_GET['non_interactive'] === true) diff --git a/calendar/inc/class.calendar_uilist.inc.php b/calendar/inc/class.calendar_uilist.inc.php index 007f3848df..6e014f2bfa 100644 --- a/calendar/inc/class.calendar_uilist.inc.php +++ b/calendar/inc/class.calendar_uilist.inc.php @@ -1005,15 +1005,15 @@ class calendar_uilist extends calendar_ui 'caption' => 'Join', 'icon' => 'status/videoconference_join', 'onExecute' => 'javaScript:app.calendar.videoConferenceAction', - 'enabled' => !EGroupware\Status\Hooks::isVideoconferenceDisabled(), + 'enabled' => !calendar_hooks::isVideoconferenceDisabled(), 'allowOnMultiple' => false, ], 'recordings' => [ 'caption' => 'Recordings', 'icon' => 'status/videoconference_recordings', 'onExecute' => 'javaScript:app.calendar.videoConferenceAction', - 'enabled' => !EGroupware\Status\Hooks::isVideoconferenceDisabled() - || EGroupware\Status\Hooks::isVCRecordingSupported(), + 'enabled' => !calendar_hooks::isVideoconferenceDisabled() + || calendar_hooks::isVCRecordingSupported(), 'allowOnMultiple' => false, ] ] diff --git a/calendar/inc/class.calendar_uiviews.inc.php b/calendar/inc/class.calendar_uiviews.inc.php index 3cd9e6a963..b26c34dcae 100644 --- a/calendar/inc/class.calendar_uiviews.inc.php +++ b/calendar/inc/class.calendar_uiviews.inc.php @@ -378,7 +378,8 @@ class calendar_uiviews extends calendar_ui ); // Don't show videoconference action if videoconference is disabled or BBB is not configured - if (\EGroupware\Status\Hooks::isVCRecordingSupported() && !EGroupware\Status\Hooks::isVideoconferenceDisabled()) + if (calendar_hooks::isVCRecordingSupported() + && !calendar_hooks::isVideoconferenceDisabled()) { // Add toggle for video calls $status_config = Api\Config::read("status");