aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSem <sembrestels@riseup.net>2012-11-23 01:05:31 +0100
committerSem <sembrestels@riseup.net>2012-11-23 01:05:31 +0100
commit39bca929f875ca6e9bd422b112d1e48b717fa126 (patch)
treedb17973fedc2bb72ba25dbfde6513e5194c69be2
parent58eebf19ad92aa1c3247aaec4f61e1440a81523a (diff)
parent75bd3af84a76345928a831eecbc5d0f99f9fead4 (diff)
downloadelgg-39bca929f875ca6e9bd422b112d1e48b717fa126.tar.gz
elgg-39bca929f875ca6e9bd422b112d1e48b717fa126.tar.bz2
Merge branch 'full' of git://github.com/kevinjardine/Elgg-Event-Calendar
-rw-r--r--actions/event_calendar/join_conference.php20
-rw-r--r--languages/en.php2
-rw-r--r--models/model.php127
-rw-r--r--start.php2
-rw-r--r--views/default/event_calendar/conference_button.php9
-rw-r--r--views/default/forms/event_calendar/edit.php2
-rw-r--r--views/rss/event_calendar/show_events.php13
7 files changed, 159 insertions, 16 deletions
diff --git a/actions/event_calendar/join_conference.php b/actions/event_calendar/join_conference.php
new file mode 100644
index 000000000..9eb8f0da9
--- /dev/null
+++ b/actions/event_calendar/join_conference.php
@@ -0,0 +1,20 @@
+<?php
+// extended logic for BBB
+elgg_load_library('elgg:event_calendar');
+
+$event_guid = get_input('event_guid');
+$event = get_entity($event_guid);
+if (elgg_instanceof($event,'object','event_calendar')) {
+ // make sure that the conference still exists, and if not, try recreating it
+ if (event_calendar_conference_exists($event)) {
+ event_calendar_join_conference($event);
+ } else if (event_calendar_create_bbb_conf($event)) {
+ event_calendar_join_conference($event);
+ } else {
+ register_error(elgg_echo('event_calendar:couldnotjoin'));
+ forward($event->getURL());
+ }
+} else {
+ register_error(elgg_echo('event_calendar:error_nosuchevent'));
+ forward('event_calendar/list');
+}
diff --git a/languages/en.php b/languages/en.php
index dfbe0cda4..b8fb918cc 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -329,7 +329,9 @@ You can visit the event page here:
'event_calendar:bbb_server_url' => "Big Blue Button server URL (must end with slash)",
'event_calendar:bbb_security_salt' => "Big Blue Button security salt",
'event_calendar:bbb_create_error' => "Error: unable to create BBB conference, message was: %s",
+ 'event_calendar:conference_create_error' => "Error: unable to create web conference.",
'event_calendar:bbb_settings_error' => "Error: must set conference URL and salt in plugin settings",
+ 'event_calendar:couldnotjoin' => "Error: unable to join conference.",
'event_calendar:join_conf_button' => "Join conference",
'event_calendar:poll_suffix' => "(poll)",
diff --git a/models/model.php b/models/model.php
index a196fcebb..09e8b2092 100644
--- a/models/model.php
+++ b/models/model.php
@@ -184,7 +184,9 @@ function event_calendar_set_event_from_form($event_guid,$group_guid) {
}
if ($event->save()) {
if (!$event_guid && $event->web_conference) {
- event_calendar_create_bbb_conf($event);
+ if (!event_calendar_create_bbb_conf($event)) {
+ register_error(elgg_echo('event_calendar:conference_create_error'));
+ }
}
if ($group_guid && (elgg_get_plugin_setting('autogroup', 'event_calendar') == 'yes')) {
event_calendar_add_personal_events_from_group($event->guid,$group_guid);
@@ -291,8 +293,8 @@ function event_calendar_get_repeating_event_structure($events, $start_date, $end
$dow = array('monday','tuesday','wednesday','thursday','friday','saturday','sunday');
$repeating_events = array();
if ($events) {
- $incs = array();
foreach($events as $e) {
+ $incs = array();
$repeat_data = array();
$day_num = date('N',$e->start_date)-1;
for($d=0;$d<7;$d++) {
@@ -2302,12 +2304,15 @@ function event_calendar_queue_reminder($e) {
}
}
-function event_calendar_create_bbb_conf($event) {
+/*function event_calendar_create_bbb_conf($event) {
$bbb_security_salt = elgg_get_plugin_setting('bbb_security_salt','event_calendar');
$bbb_server_url = rtrim(elgg_get_plugin_setting('bbb_server_url','event_calendar'), '/') . '/';
if ($bbb_security_salt) {
$day_in_minutes = 60*24;
- $duration = (int)(($event->real_end_time-$event->start_date)/60)+$day_in_minutes;
+ $now = time();
+ // fix duration bug
+ # $duration = (int)(($event->real_end_time-$event->start_date)/60)+$day_in_minutes;
+ $duration = (int)(($event->real_end_time-$now)/60)+$day_in_minutes;
$title = urlencode($event->title);
$params = "name=$title&meetingID={$event->guid}&duration=$duration";
$checksum = sha1('create'.$params.$bbb_security_salt);
@@ -2328,11 +2333,11 @@ function event_calendar_create_bbb_conf($event) {
// close curl resource to free up system resources
curl_close($ch);
- /*error_log("BBB create request:");
- error_log($bbb_server_url.'api/create?'.$params);
+ #error_log("BBB create request:");
+ #error_log($bbb_server_url.'api/create?'.$params);
- error_log("BBB create response:");
- error_log($output);*/
+ #error_log("BBB create response:");
+ #error_log($output);
$xml = new SimpleXMLElement($output);
if ($xml->returncode == 'SUCCESS') {
@@ -2344,6 +2349,112 @@ function event_calendar_create_bbb_conf($event) {
} else {
register_error(elgg_echo('event_calendar:bbb_settings_error'));
}
+}*/
+
+// utility function for BBB api calls
+function event_calendar_bbb_api($api_function,$params=NULL) {
+
+ $bbb_security_salt = elgg_get_plugin_setting('bbb_security_salt','event_calendar');
+ $bbb_server_url = rtrim(elgg_get_plugin_setting('bbb_server_url','event_calendar'), '/') . '/';
+ if ($bbb_security_salt) {
+ if (isset($params) && is_array($params) && count($params) > 0) {
+ $query = array();
+ foreach($params as $k => $v) {
+ $query[] = $k.'='.rawurlencode($v);
+ }
+ $qs = implode('&',$query);
+ } else {
+ $qs = '';
+ }
+ $checksum = sha1($api_function.$qs.$bbb_security_salt);
+ if ($qs) {
+ $qs .= "&checksum=$checksum";
+ }
+
+ // create curl resource
+ $ch = curl_init();
+
+ // set url
+ curl_setopt($ch, CURLOPT_URL, $bbb_server_url.'api/'.$api_function.'?'.$qs);
+
+ //return the transfer as a string
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+
+ // $output contains the output string
+ $output = curl_exec($ch);
+
+ // close curl resource to free up system resources
+ curl_close($ch);
+
+ error_log("BBB api call: ".$api_function);
+ error_log(print_r($params,TRUE));
+ error_log("BBB response: \n".$output);
+ return $output;
+ } else {
+ return FALSE;
+ }
+}
+
+function event_calendar_create_bbb_conf($event) {
+ $day_in_minutes = 60*24;
+ $now = time();
+ // fix duration bug
+ # $duration = (int)(($event->real_end_time-$event->start_date)/60)+$day_in_minutes;
+ $duration = (int)(($event->real_end_time-$now)/60)+$day_in_minutes;
+ if ($duration > 0) {
+ $title = urlencode($event->title);
+ $output = event_calendar_bbb_api('create',array('meetingID'=>$event->guid,'name'=>$title,'duration'=>$duration));
+ if ($output) {
+ $xml = new SimpleXMLElement($output);
+ if ($xml->returncode == 'SUCCESS') {
+ $event->bbb_attendee_password = (string) $xml->attendeePW;
+ $event->bbb_moderator_password = (string) $xml->moderatorPW;
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+ } else {
+ return FALSE;
+ }
+ } else {
+ return FALSE;
+ }
+}
+
+// checks to see if a BBB conference is actually running
+function event_calendar_is_conference_running($event) {
+ $output = event_calendar_bbb_api('isMeetingRunning',array('meetingID'=>$event->guid));
+ if (!$output) {
+ return FALSE;
+ } else {
+ $xml = new SimpleXMLElement($output);
+ if ($xml->returncode == 'SUCCESS' && $xml->running == 'true') {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+ }
+}
+
+// checks to see if a BBB conference exists
+function event_calendar_conference_exists($event) {
+ $output = event_calendar_bbb_api('getMeetingInfo',array('meetingID'=>$event->guid,'password'=>$event->bbb_moderator_password));
+ if (!$output) {
+ return FALSE;
+ } else {
+ $xml = new SimpleXMLElement($output);
+ if ($xml->returncode == 'SUCCESS' && $xml->meetingID == $event->guid) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+ }
+}
+
+// forwards to the join link
+// this function assumes that the conference is running
+function event_calendar_join_conference($event) {
+ forward(event_calendar_get_join_bbb_url($event));
}
function event_calendar_get_join_bbb_url($event) {
diff --git a/start.php b/start.php
index 752646a3e..5590544b8 100644
--- a/start.php
+++ b/start.php
@@ -112,7 +112,7 @@ function event_calendar_init() {
elgg_register_action("event_calendar/remove_from_group_members","$action_path/remove_from_group_members.php");
elgg_register_action("event_calendar/manage_subscribers","$action_path/manage_subscribers.php");
elgg_register_action("event_calendar/modify_full_calendar","$action_path/modify_full_calendar.php");
-
+ elgg_register_action("event_calendar/join_conference","$action_path/join_conference.php");
}
/**
diff --git a/views/default/event_calendar/conference_button.php b/views/default/event_calendar/conference_button.php
index f6fedf4f6..79fa9c5a2 100644
--- a/views/default/event_calendar/conference_button.php
+++ b/views/default/event_calendar/conference_button.php
@@ -2,29 +2,30 @@
// A non-admin / non-event-creator only sees the button if they have the event on his/her personal calendar
// and it is at most 15 minutes before the conference starts.
-// The button is removed for everyone (even admins) one day after the conference ends.
+// The button is removed for everyone (even admins) one day after the event end time.
$event = $vars['event'];
if ($event) {
elgg_load_library('elgg:event_calendar');
$user_guid = elgg_get_logged_in_user_guid();
- $termination_time = $event->real_end_time + 60*60*24;
+ $termination_time = strtotime("1 day",$event->real_end_time);
if ($termination_time < time()) {
$in_time_window = FALSE;
} else if ($event->canEdit()) {
$in_time_window = TRUE;
- } else if (event_calendar_has_personal_event($event->guid, $user_guid) && ($event->start_date - 15*60) >= time()) {
+ } else if (event_calendar_has_personal_event($event->guid, $user_guid) && (strtotime('-15 minutes',$event->start_date) <= time())) {
$in_time_window = TRUE;
} else {
$in_time_window = FALSE;
}
if ( $in_time_window ) {
$button = elgg_view('output/url', array(
- 'href' => event_calendar_get_join_bbb_url($event),
+ 'href' => 'action/event_calendar/join_conference?event_guid='.$event->guid,
'text' => elgg_echo('event_calendar:join_conf_button'),
'class' => 'elgg-button elgg-button-action',
'target' => '_blank',
+ 'is_action' => TRUE,
));
echo '<div class="event-calendar-conf-join-button">'.$button.'</div>';
diff --git a/views/default/forms/event_calendar/edit.php b/views/default/forms/event_calendar/edit.php
index d45fb387b..747dae0f0 100644
--- a/views/default/forms/event_calendar/edit.php
+++ b/views/default/forms/event_calendar/edit.php
@@ -7,7 +7,7 @@ $schedule_options = array(
elgg_echo('event_calendar:schedule_type:fixed')=>'fixed',
);
-if (elgg_plugin_exists('event_poll')) {
+if (elgg_is_active_plugin('event_poll')) {
$schedule_options = array_merge(array(elgg_echo('event_calendar:schedule_type:poll')=>'poll'),$schedule_options);
}
diff --git a/views/rss/event_calendar/show_events.php b/views/rss/event_calendar/show_events.php
index add5b75db..40c67ff6a 100644
--- a/views/rss/event_calendar/show_events.php
+++ b/views/rss/event_calendar/show_events.php
@@ -9,7 +9,16 @@
* @link http://radagast.biz/
*
*/
+
+elgg_load_library('elgg:event_calendar');
if ($vars['events']) {
- echo elgg_view_entity_list($vars['events'], $vars['count'], $vars['offset'], $vars['limit'], false, false);
+ $options = array(
+ 'count' => $vars['count'],
+ 'offset' => 0,
+ 'limit' => 15,
+ 'list_type_toggle' => FALSE,
+ 'pagination' => FALSE,
+ );
+ // echo elgg_view_entity_list($vars['events'], $vars['count'], $vars['offset'], $vars['limit'], false, false);
+ echo elgg_view_entity_list(event_calendar_flatten_event_structure($vars['events']), $options);
}
-?> \ No newline at end of file