1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8function wikiplugin_bigbluebutton_info()
9{
10	return [
11		'name' => tra('BigBlueButton'),
12		'documentation' => 'PluginBigBlueButton',
13		'description' => tra('Hold a video/audio/chat/presentation session using the BigBlueButton web conferencing system.'),
14		'format' => 'html',
15		'prefs' => [ 'wikiplugin_bigbluebutton', 'bigbluebutton_feature' ],
16		'iconname' => 'video',
17		'introduced' => 5,
18		'tags' => [ 'basic' ],
19		'params' => [
20			'name' => [
21				'required' => true,
22				'name' => tra('Meeting'),
23				'description' => tr('MeetingID for BigBlueButton. This is a 5 digit number, starting with a 7.
24					Ex.: %0 or %1.', '<code>77777</code>', '<code>71111</code>'),
25				'since' => '5.0',
26				'filter' => 'text',
27				'default' => '',
28			],
29			'prefix' => [
30				'required' => false,
31				'name' => tra('Anonymous Prefix'),
32				'description' => tra('Unregistered users will get this token prepended to their name.'),
33				'since' => '5.0',
34				'filter' => 'text',
35				'default' => '',
36			],
37			'welcome' => [
38				'required' => false,
39				'name' => tra('Welcome Message'),
40				'description' => tra('A message to be provided when someone enters the room.'),
41				'since' => '5.0',
42				'filter' => 'text',
43				'default' => '',
44			],
45			'number' => [
46				'required' => false,
47				'name' => tra('Dial Number'),
48				'description' => tra('The phone-in support number to join from traditional phones.'),
49				'since' => '5.0',
50				'filter' => 'text',
51				'default' => '',
52			],
53			'voicebridge' => [
54				'required' => false,
55				'name' => tra('Voice Bridge'),
56				'description' => tra('Code to enter for phone attendees to join the room. Typically, the same 5 digits
57					of the MeetingID.'),
58				'since' => '5.0',
59				'filter' => 'digits',
60				'default' => '',
61			],
62			'logout' => [
63				'required' => false,
64				'name' => tra('Log-out URL'),
65				'description' => tra('URL to which the user will be redirected after logging out of BigBlueButton.'),
66				'since' => '5.0',
67				'filter' => 'url',
68				'default' => '',
69			],
70			'recording' => [
71				'required' => false,
72				'name' => tra('Record'),
73				'description' => tra('The recording starts when the first person enters the room, and ends when the last
74					person leaves. After a period of processing (which depends on the length of the meeting), the
75					recording will be added to the list of all recordings for this room. Requires BBB >= 0.8.'),
76				'since' => '5.0',
77				'filter' => 'digits',
78				'default' => 0,
79				'options' => [
80					['value' => 0, 'text' => tr('Off')],
81					['value' => 1, 'text' => tr('On')],
82				],
83			],
84			'showrecording' => [
85				'required' => false,
86				'name' => tra('Display Recordings'),
87				'description' => tra('Enable or Disable the display of video recordings.'),
88				'filter' => 'alpha',
89				'default' => 'y',
90			],
91			'showattendees' => [
92				'required' => false,
93				'name' => tra('Display Attendees'),
94				'description' => tra('Enable or Disable the display of attendees list.'),
95				'filter' => 'alpha',
96				'default' => 'y',
97			],
98		],
99	];
100}
101
102function wikiplugin_bigbluebutton($data, $params)
103{
104	try {
105		global $prefs, $user;
106		$bigbluebuttonlib = TikiLib::lib('bigbluebutton');
107		$meeting = $params['name']; // Meeting is more descriptive than name, but parameter name was already decided.
108		$smarty = TikiLib::lib('smarty');
109		$smarty->assign('bbb_meeting', $meeting);
110
111		$perms = Perms::get('bigbluebutton', $meeting);
112
113		$params = array_merge(['prefix' => '', 'recording' => 0], $params);
114		// This is incomplete, will only apply if the dynamic feature is enabled. To be completed.
115		$params['configuration'] = [
116			'presentation' => [
117				'active' => false,
118			],
119		];
120		$smarty->assign('bbb_params', Tiki_Security::get()->encode($params));
121
122		if (! $bigbluebuttonlib->roomExists($meeting)) {
123			if (! isset($_POST['bbb']) || $_POST['bbb'] != $meeting || ! $perms->bigbluebutton_create) {
124				if ($perms->bigbluebutton_view_rec && $params['showrecording'] != 'n') {
125					$smarty->assign('bbb_recordings', $bigbluebuttonlib->getRecordings($meeting));
126				} else {
127					$smarty->assign('bbb_recordings', null);
128				}
129				return $smarty->fetch('wiki-plugins/wikiplugin_bigbluebutton_create.tpl');
130			}
131		}
132
133		if ($perms->bigbluebutton_view_rec) {
134			$smarty->assign('bbb_recordings', $bigbluebuttonlib->getRecordings($meeting));
135		} else {
136			$smarty->assign('bbb_recordings', null);
137		}
138
139		if ($perms->bigbluebutton_join) {
140			if ($params['showattendees'] != 'n') {
141				$smarty->assign('bbb_attendees', $bigbluebuttonlib->getAttendees($meeting));
142				$smarty->assign('bbb_show_attendees', true);
143			} else {
144				$smarty->assign('bbb_show_attendees', false);
145			}
146
147			return $smarty->fetch('wiki-plugins/wikiplugin_bigbluebutton.tpl');
148		}
149
150		// Won't display anything if recordings were not loaded
151		return $smarty->fetch('wiki-plugins/wikiplugin_bigbluebutton_view_recordings.tpl');
152	} catch (Exception $e) {
153		return WikiParser_PluginOutput::internalError(tr('BigBlueButton is misconfigured or inaccessible.'));
154	}
155}
156