chamilo /
chamilo-lms
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | /* For license terms, see /license.txt */ |
||||||
| 4 | |||||||
| 5 | /** |
||||||
| 6 | * This script initiates a video conference session, calling the BigBlueButton API. |
||||||
| 7 | */ |
||||||
| 8 | |||||||
| 9 | use Chamilo\CoreBundle\Framework\Container; |
||||||
| 10 | |||||||
| 11 | require_once __DIR__.'/../../../vendor/autoload.php'; |
||||||
| 12 | |||||||
| 13 | $course_plugin = 'Bbb'; //needed in order to load the plugin lang variables |
||||||
| 14 | |||||||
| 15 | $isGlobal = isset($_GET['global']); |
||||||
| 16 | $isGlobalPerUser = isset($_GET['user_id']) ? (int) $_GET['user_id'] : false; |
||||||
| 17 | |||||||
| 18 | // If global setting is used then we delete the course sessions (cidReq/id_session) |
||||||
| 19 | if ($isGlobalPerUser || $isGlobal) { |
||||||
|
0 ignored issues
–
show
|
|||||||
| 20 | $cidReset = true; |
||||||
| 21 | } |
||||||
| 22 | |||||||
| 23 | require_once __DIR__.'/config.php'; |
||||||
| 24 | |||||||
| 25 | function bbb_flash_redirect(string $htmlMessage, Bbb $bbb): void |
||||||
| 26 | { |
||||||
| 27 | Display::addFlash($htmlMessage); |
||||||
| 28 | try { |
||||||
| 29 | $type = 'info'; |
||||||
| 30 | if (preg_match('/alert-([a-z]+)/', $htmlMessage, $m)) { |
||||||
| 31 | $type = $m[1] === 'danger' ? 'error' : $m[1]; |
||||||
| 32 | } |
||||||
| 33 | $text = $htmlMessage; |
||||||
| 34 | if (preg_match('/<div[^>]*>(.*?)<\/div>/si', $htmlMessage, $m)) { |
||||||
| 35 | $text = trim($m[1]); |
||||||
| 36 | } |
||||||
| 37 | Container::getSession()->set('bbb_preupload_message', ['type' => $type, 'text' => $text]); |
||||||
| 38 | } catch (\Throwable $e) {} |
||||||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
|
|||||||
| 39 | |||||||
| 40 | $url = $bbb->getListingUrl().'#bbb-pre-pop'; |
||||||
| 41 | if (!headers_sent()) { |
||||||
| 42 | header($_SERVER['SERVER_PROTOCOL'].' 303 See Other'); |
||||||
| 43 | header('Location: '.$url); |
||||||
| 44 | } else { |
||||||
| 45 | echo '<script>window.location.href='.json_encode($url).';</script>'; |
||||||
| 46 | } |
||||||
| 47 | exit; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 48 | } |
||||||
| 49 | |||||||
| 50 | $logInfo = [ |
||||||
| 51 | 'tool' => 'Videoconference', |
||||||
| 52 | ]; |
||||||
| 53 | Event::registerLog($logInfo); |
||||||
|
0 ignored issues
–
show
The method
registerLog() does not exist on Event.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 54 | |||||||
| 55 | $tool_name = get_lang('Videoconference'); |
||||||
| 56 | $tpl = new Template($tool_name); |
||||||
| 57 | |||||||
| 58 | $vmIsEnabled = false; |
||||||
| 59 | $host = ''; |
||||||
| 60 | $salt = ''; |
||||||
| 61 | $bbb = new Bbb('', '', $isGlobal, $isGlobalPerUser); |
||||||
| 62 | |||||||
| 63 | $conferenceManager = $bbb->isConferenceManager(); |
||||||
| 64 | if ($bbb->isGlobalConference()) { |
||||||
| 65 | api_block_anonymous_users(); |
||||||
| 66 | } else { |
||||||
| 67 | api_protect_course_script(true); |
||||||
| 68 | } |
||||||
| 69 | |||||||
| 70 | $message = null; |
||||||
| 71 | if ($bbb->pluginEnabled) { |
||||||
| 72 | if ($bbb->isServerConfigured()) { |
||||||
| 73 | if ($bbb->isServerRunning()) { |
||||||
| 74 | if (isset($_GET['launch']) && 1 == $_GET['launch']) { |
||||||
| 75 | if (file_exists(__DIR__.'/config.vm.php')) { |
||||||
| 76 | $config = require __DIR__.'/config.vm.php'; |
||||||
| 77 | $vmIsEnabled = true; |
||||||
| 78 | $host = ''; |
||||||
| 79 | $salt = ''; |
||||||
| 80 | |||||||
| 81 | require __DIR__.'/lib/vm/AbstractVM.php'; |
||||||
| 82 | require __DIR__.'/lib/vm/VMInterface.php'; |
||||||
| 83 | require __DIR__.'/lib/vm/DigitalOceanVM.php'; |
||||||
| 84 | require __DIR__.'/lib/VM.php'; |
||||||
| 85 | |||||||
| 86 | $vm = new VM($config); |
||||||
| 87 | |||||||
| 88 | if ($vm->isEnabled()) { |
||||||
| 89 | try { |
||||||
| 90 | $vm->resizeToMaxLimit(); |
||||||
| 91 | } catch (\Exception $e) { |
||||||
| 92 | echo $e->getMessage(); |
||||||
| 93 | exit; |
||||||
| 94 | } |
||||||
| 95 | } |
||||||
| 96 | } |
||||||
| 97 | |||||||
| 98 | $meetingParams = []; |
||||||
| 99 | $meetingParams['meeting_name'] = $bbb->getCurrentVideoConferenceName(); |
||||||
| 100 | $url = null; |
||||||
| 101 | if ($bbb->meetingExists($meetingParams['meeting_name'])) { |
||||||
| 102 | $joinUrl = $bbb->joinMeeting($meetingParams['meeting_name']); |
||||||
| 103 | if ($joinUrl) { |
||||||
| 104 | $url = $joinUrl; |
||||||
| 105 | } |
||||||
| 106 | } else { |
||||||
| 107 | if ($bbb->isConferenceManager()) { |
||||||
| 108 | if (!empty($_POST['documents']) && is_array($_POST['documents'])) { |
||||||
| 109 | $docs = []; |
||||||
| 110 | foreach ($_POST['documents'] as $raw) { |
||||||
| 111 | $json = html_entity_decode($raw); |
||||||
| 112 | $doc = json_decode($json, true); |
||||||
| 113 | if (is_array($doc) && !empty($doc['url'])) { |
||||||
| 114 | $docs[] = [ |
||||||
| 115 | 'url' => $doc['url'], |
||||||
| 116 | 'filename' => $doc['filename'] ?? basename(parse_url($doc['url'], PHP_URL_PATH)), |
||||||
| 117 | 'downloadable'=> true, |
||||||
| 118 | 'removable' => true |
||||||
| 119 | ]; |
||||||
| 120 | } |
||||||
| 121 | } |
||||||
| 122 | if (!empty($docs)) { |
||||||
| 123 | $meetingParams['documents'] = $docs; |
||||||
| 124 | } |
||||||
| 125 | } |
||||||
| 126 | |||||||
| 127 | $maxTotalMb = (int) api_get_course_plugin_setting('bbb', 'bbb_preupload_max_total_mb', api_get_course_info()); |
||||||
| 128 | if ($maxTotalMb <= 0) { $maxTotalMb = 20; } |
||||||
| 129 | |||||||
| 130 | $totalBytes = 0; |
||||||
| 131 | if (!empty($_POST['documents']) && is_array($_POST['documents'])) { |
||||||
| 132 | $docs = []; |
||||||
| 133 | foreach ($_POST['documents'] as $raw) { |
||||||
| 134 | $json = html_entity_decode($raw); |
||||||
| 135 | $doc = json_decode($json, true); |
||||||
| 136 | if (!is_array($doc) || empty($doc['url'])) { continue; } |
||||||
| 137 | $totalBytes += (int)($doc['size'] ?? 0); |
||||||
| 138 | $docs[] = [ |
||||||
| 139 | 'url' => $doc['url'], |
||||||
| 140 | 'filename' => $doc['filename'] ?? basename(parse_url($doc['url'], PHP_URL_PATH)), |
||||||
| 141 | 'downloadable'=> true, |
||||||
| 142 | 'removable' => true, |
||||||
| 143 | ]; |
||||||
| 144 | } |
||||||
| 145 | |||||||
| 146 | if ($totalBytes > ($maxTotalMb * 1024 * 1024)) { |
||||||
| 147 | bbb_flash_redirect( |
||||||
| 148 | Display::return_message( |
||||||
| 149 | sprintf(get_lang('The total size of selected documents exceeds %d MB.'), $maxTotalMb), |
||||||
| 150 | 'error' |
||||||
| 151 | ), |
||||||
| 152 | $bbb |
||||||
| 153 | ); |
||||||
| 154 | } |
||||||
| 155 | |||||||
| 156 | if (!empty($docs)) { |
||||||
| 157 | $meetingParams['documents'] = $docs; |
||||||
| 158 | } |
||||||
| 159 | } |
||||||
| 160 | |||||||
| 161 | $url = $bbb->createMeeting($meetingParams); |
||||||
| 162 | if (!$url) { |
||||||
| 163 | bbb_flash_redirect( |
||||||
| 164 | Display::return_message( |
||||||
| 165 | get_lang('The selected documents exceed the upload limit of the video-conference server. Try fewer/smaller files or contact your administrator.'), |
||||||
| 166 | 'error' |
||||||
| 167 | ), |
||||||
| 168 | $bbb |
||||||
| 169 | ); |
||||||
| 170 | } |
||||||
| 171 | } |
||||||
| 172 | } |
||||||
| 173 | |||||||
| 174 | $meetingInfo = $bbb->findMeetingByName($meetingParams['meeting_name']); |
||||||
| 175 | if (!empty($meetingInfo) && $url) { |
||||||
| 176 | $remoteId = $meetingInfo['remote_id'] ?? null; |
||||||
| 177 | if (!$remoteId && !empty($meetingInfo['id'])) { |
||||||
| 178 | $full = $bbb->getMeeting((int)$meetingInfo['id']); |
||||||
| 179 | if (is_array($full)) { |
||||||
| 180 | $remoteId = $full['remote_id'] ?? ($full['remoteId'] ?? null); |
||||||
| 181 | } |
||||||
| 182 | } |
||||||
| 183 | |||||||
| 184 | if ($bbb->plugin->webhooksEnabled()) { |
||||||
| 185 | $scope = $bbb->plugin->webhooksScope(); |
||||||
| 186 | if ($scope === 'per_meeting') { |
||||||
| 187 | if ($remoteId) { $bbb->ensureHookForMeeting($remoteId); } |
||||||
| 188 | } else { |
||||||
| 189 | $bbb->ensureGlobalHook(); |
||||||
| 190 | } |
||||||
| 191 | } |
||||||
| 192 | |||||||
| 193 | $bbb->saveParticipant($meetingInfo['id'], api_get_user_id()); |
||||||
| 194 | $bbb->redirectToBBB($url); |
||||||
| 195 | } else { |
||||||
| 196 | Display::addFlash( |
||||||
| 197 | Display::return_message($bbb->plugin->get_lang('ThereIsNoVideoConferenceActive')) |
||||||
| 198 | ); |
||||||
| 199 | $url = $bbb->getListingUrl(); |
||||||
| 200 | header('Location: '.$url); |
||||||
| 201 | exit; |
||||||
| 202 | } |
||||||
| 203 | } else { |
||||||
| 204 | $url = $bbb->getListingUrl(); |
||||||
| 205 | header('Location: '.$url); |
||||||
| 206 | exit; |
||||||
| 207 | } |
||||||
| 208 | } else { |
||||||
| 209 | $message = Display::return_message(get_lang('ServerIsNotRunning'), 'warning'); |
||||||
| 210 | } |
||||||
| 211 | } else { |
||||||
| 212 | $message = Display::return_message(get_lang('ServerIsNotConfigured'), 'warning'); |
||||||
| 213 | } |
||||||
| 214 | } else { |
||||||
| 215 | $message = Display::return_message(get_lang('ServerIsNotConfigured'), 'warning'); |
||||||
| 216 | } |
||||||
| 217 | |||||||
| 218 | $tpl->assign('message', $message); |
||||||
| 219 | $tpl->assign('content', $message); |
||||||
| 220 | $tpl->display_one_col_template(); |
||||||
| 221 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: