@@ -4,53 +4,53 @@ |
||
4 | 4 | |
5 | 5 | /* save the URL we were given for the OAuth endpoint */ |
6 | 6 | if (isset($_REQUEST['url']) && !empty($_REQUEST['url'])) { |
7 | - $metadata['CANVAS_INSTANCE_URL'] = $_REQUEST['url']; |
|
8 | - $metadata['CANVAS_API_URL'] = '@CANVAS_INSTANCE_URL/api/v1'; |
|
7 | + $metadata['CANVAS_INSTANCE_URL'] = $_REQUEST['url']; |
|
8 | + $metadata['CANVAS_API_URL'] = '@CANVAS_INSTANCE_URL/api/v1'; |
|
9 | 9 | |
10 | - /* if a token is provided use it, otherwise we will begin the interactive token |
|
10 | + /* if a token is provided use it, otherwise we will begin the interactive token |
|
11 | 11 | authorization process */ |
12 | - if (isset($_REQUEST['token']) && !empty($_REQUEST['token'])) { |
|
13 | - $metadata['CANVAS_API_TOKEN'] = $_REQUEST['token']; |
|
14 | - header("Location: {$metadata['APP_URL']}/admin/install.php?step=" . CanvasAPIviaLTI_Installer::API_TOKEN_PROVIDED_STEP); |
|
15 | - exit; |
|
16 | - } |
|
12 | + if (isset($_REQUEST['token']) && !empty($_REQUEST['token'])) { |
|
13 | + $metadata['CANVAS_API_TOKEN'] = $_REQUEST['token']; |
|
14 | + header("Location: {$metadata['APP_URL']}/admin/install.php?step=" . CanvasAPIviaLTI_Installer::API_TOKEN_PROVIDED_STEP); |
|
15 | + exit; |
|
16 | + } |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | try { |
20 | - /* are we at the beginning of the process, so we need to give the OAuthNegotiator as much information as possible? */ |
|
21 | - if (isset($_REQUEST['step'])) { |
|
20 | + /* are we at the beginning of the process, so we need to give the OAuthNegotiator as much information as possible? */ |
|
21 | + if (isset($_REQUEST['step'])) { |
|
22 | 22 | |
23 | - /* clear any existing session data */ |
|
24 | - if (session_status() === PHP_SESSION_NONE) { |
|
25 | - session_start(); |
|
26 | - } |
|
27 | - $_SESSION = array(); |
|
28 | - session_destroy(); |
|
29 | - session_start(); |
|
23 | + /* clear any existing session data */ |
|
24 | + if (session_status() === PHP_SESSION_NONE) { |
|
25 | + session_start(); |
|
26 | + } |
|
27 | + $_SESSION = array(); |
|
28 | + session_destroy(); |
|
29 | + session_start(); |
|
30 | 30 | |
31 | - $oauth = new OAuthNegotiator( |
|
32 | - "{$metadata['CANVAS_INSTANCE_URL']}/login/oauth2", |
|
33 | - (string) $secrets->oauth->id, |
|
34 | - (string) $secrets->oauth->key, |
|
35 | - "{$metadata['APP_URL']}/admin/install.php?step={$_REQUEST['step']}", |
|
36 | - (string) $secrets->app->name |
|
37 | - ); |
|
38 | - } |
|
31 | + $oauth = new OAuthNegotiator( |
|
32 | + "{$metadata['CANVAS_INSTANCE_URL']}/login/oauth2", |
|
33 | + (string) $secrets->oauth->id, |
|
34 | + (string) $secrets->oauth->key, |
|
35 | + "{$metadata['APP_URL']}/admin/install.php?step={$_REQUEST['step']}", |
|
36 | + (string) $secrets->app->name |
|
37 | + ); |
|
38 | + } |
|
39 | 39 | |
40 | - /* OAuthNegotiator will return here periodically and we will just keep re-instantiating it until it finishes */ |
|
41 | - $oauth = new OAuthNegotiator(); |
|
40 | + /* OAuthNegotiator will return here periodically and we will just keep re-instantiating it until it finishes */ |
|
41 | + $oauth = new OAuthNegotiator(); |
|
42 | 42 | } catch (OAuthNegotiator_Exception $e) { |
43 | - $smarty->addMessage( |
|
44 | - 'OAuthNegotiator error', |
|
45 | - $e->getMessage() . ' [Error ' . $e->getCode() . ']', |
|
46 | - NotificationMessage::ERROR |
|
47 | - ); |
|
48 | - $smarty->assign( |
|
49 | - 'content', |
|
50 | - '<h1>Install Interrupted</h1> |
|
43 | + $smarty->addMessage( |
|
44 | + 'OAuthNegotiator error', |
|
45 | + $e->getMessage() . ' [Error ' . $e->getCode() . ']', |
|
46 | + NotificationMessage::ERROR |
|
47 | + ); |
|
48 | + $smarty->assign( |
|
49 | + 'content', |
|
50 | + '<h1>Install Interrupted</h1> |
|
51 | 51 | <p>An error interrupted the installation process. To restart, <a href="install.php">click here</a>.</p>'); |
52 | - $smarty->display(); |
|
53 | - exit; |
|
52 | + $smarty->display(); |
|
53 | + exit; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | ?> |
57 | 57 | \ No newline at end of file |
@@ -3,9 +3,9 @@ |
||
3 | 3 | require_once('common.inc.php'); |
4 | 4 | |
5 | 5 | if ($ready) { |
6 | - header('Location: consumers.php'); |
|
6 | + header('Location: consumers.php'); |
|
7 | 7 | } else { |
8 | - header('Location: install.php'); |
|
8 | + header('Location: install.php'); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | ?> |
12 | 12 | \ No newline at end of file |
@@ -10,72 +10,72 @@ |
||
10 | 10 | |
11 | 11 | /* validate new consumer information and save it */ |
12 | 12 | if (isset($_REQUEST['name']) && isset($_REQUEST['key']) && isset($_REQUEST['secret'])) { |
13 | - $valid = true; |
|
14 | - $message = 'Invalid consumer information. '; |
|
15 | - if (empty($_name = trim($_REQUEST['name']))) { |
|
16 | - $valid = false; |
|
17 | - $message .= 'Consumer name must not be empty. '; |
|
18 | - } |
|
19 | - if (empty($_key = trim($_REQUEST['key']))) { |
|
20 | - $valid = false; |
|
21 | - $message .= 'Consumer key must not be empty. '; |
|
22 | - } |
|
23 | - if (empty(trim($_REQUEST['secret']))) { // secret may contain intentional whitespace -- leave untrimmed |
|
24 | - $valid = false; |
|
25 | - $message .= 'Shared secret must not be empty. '; |
|
26 | - } |
|
13 | + $valid = true; |
|
14 | + $message = 'Invalid consumer information. '; |
|
15 | + if (empty($_name = trim($_REQUEST['name']))) { |
|
16 | + $valid = false; |
|
17 | + $message .= 'Consumer name must not be empty. '; |
|
18 | + } |
|
19 | + if (empty($_key = trim($_REQUEST['key']))) { |
|
20 | + $valid = false; |
|
21 | + $message .= 'Consumer key must not be empty. '; |
|
22 | + } |
|
23 | + if (empty(trim($_REQUEST['secret']))) { // secret may contain intentional whitespace -- leave untrimmed |
|
24 | + $valid = false; |
|
25 | + $message .= 'Shared secret must not be empty. '; |
|
26 | + } |
|
27 | 27 | |
28 | - if ($valid) { |
|
29 | - $consumer = new LTI_Tool_Consumer($_key, LTI_Data_Connector::getDataConnector($sql)); |
|
30 | - $consumer->name = $_name; |
|
31 | - $consumer->secret = $_REQUEST['secret']; |
|
32 | - $consumer->enabled = isset($_REQUEST['enabled']); |
|
33 | - if (!$consumer->save()) { |
|
34 | - $valid = false; |
|
35 | - $message = "<strong>Consumer could not be saved.</strong> {$sql->error}"; |
|
36 | - } |
|
37 | - } |
|
28 | + if ($valid) { |
|
29 | + $consumer = new LTI_Tool_Consumer($_key, LTI_Data_Connector::getDataConnector($sql)); |
|
30 | + $consumer->name = $_name; |
|
31 | + $consumer->secret = $_REQUEST['secret']; |
|
32 | + $consumer->enabled = isset($_REQUEST['enabled']); |
|
33 | + if (!$consumer->save()) { |
|
34 | + $valid = false; |
|
35 | + $message = "<strong>Consumer could not be saved.</strong> {$sql->error}"; |
|
36 | + } |
|
37 | + } |
|
38 | 38 | |
39 | - if (!$valid) { |
|
40 | - $smarty->addMessage( |
|
41 | - 'Required information missing', |
|
42 | - $message, |
|
43 | - NotificationMessage::ERROR |
|
44 | - ); |
|
45 | - } |
|
39 | + if (!$valid) { |
|
40 | + $smarty->addMessage( |
|
41 | + 'Required information missing', |
|
42 | + $message, |
|
43 | + NotificationMessage::ERROR |
|
44 | + ); |
|
45 | + } |
|
46 | 46 | |
47 | 47 | /* look up consumer to edit, if requested */ |
48 | 48 | } elseif (isset($_REQUEST['consumer_key'])) { |
49 | - $consumer = new LTI_Tool_Consumer($_REQUEST['consumer_key'], LTI_Data_Connector::getDataConnector($sql)); |
|
50 | - if (isset($_REQUEST['action'])) |
|
51 | - switch ($_REQUEST['action']) { |
|
52 | - case 'delete': { |
|
53 | - $consumer->delete(); |
|
54 | - break; |
|
55 | - } |
|
56 | - case 'select': { |
|
57 | - $name = $consumer->name; |
|
58 | - $key = $consumer->getKey(); |
|
59 | - $secret = $consumer->secret; |
|
60 | - $enabled = $consumer->enabled; |
|
61 | - break; |
|
62 | - } |
|
63 | - case 'update': |
|
64 | - case 'insert': |
|
65 | - default: { |
|
66 | - // leave default form values set |
|
67 | - } |
|
68 | - } |
|
49 | + $consumer = new LTI_Tool_Consumer($_REQUEST['consumer_key'], LTI_Data_Connector::getDataConnector($sql)); |
|
50 | + if (isset($_REQUEST['action'])) |
|
51 | + switch ($_REQUEST['action']) { |
|
52 | + case 'delete': { |
|
53 | + $consumer->delete(); |
|
54 | + break; |
|
55 | + } |
|
56 | + case 'select': { |
|
57 | + $name = $consumer->name; |
|
58 | + $key = $consumer->getKey(); |
|
59 | + $secret = $consumer->secret; |
|
60 | + $enabled = $consumer->enabled; |
|
61 | + break; |
|
62 | + } |
|
63 | + case 'update': |
|
64 | + case 'insert': |
|
65 | + default: { |
|
66 | + // leave default form values set |
|
67 | + } |
|
68 | + } |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /* display a list of consumers */ |
72 | 72 | $response = $sql->query("SELECT * FROM `" . LTI_Data_Connector::CONSUMER_TABLE_NAME . "` ORDER BY `name` ASC, `consumer_key` ASC"); |
73 | 73 | $consumers = array(); |
74 | 74 | while ($consumer = $response->fetch_assoc()) { |
75 | - $consumers[] = $consumer; |
|
75 | + $consumers[] = $consumer; |
|
76 | 76 | } |
77 | 77 | if (!empty($consumers)) { |
78 | - $smarty->assign('fields', array_keys($consumers[0])); |
|
78 | + $smarty->assign('fields', array_keys($consumers[0])); |
|
79 | 79 | } |
80 | 80 | $smarty->assign('consumers', $consumers); |
81 | 81 |
@@ -47,10 +47,11 @@ |
||
47 | 47 | /* look up consumer to edit, if requested */ |
48 | 48 | } elseif (isset($_REQUEST['consumer_key'])) { |
49 | 49 | $consumer = new LTI_Tool_Consumer($_REQUEST['consumer_key'], LTI_Data_Connector::getDataConnector($sql)); |
50 | - if (isset($_REQUEST['action'])) |
|
51 | - switch ($_REQUEST['action']) { |
|
50 | + if (isset($_REQUEST['action'])) { |
|
51 | + switch ($_REQUEST['action']) { |
|
52 | 52 | case 'delete': { |
53 | 53 | $consumer->delete(); |
54 | + } |
|
54 | 55 | break; |
55 | 56 | } |
56 | 57 | case 'select': { |
@@ -3,30 +3,30 @@ |
||
3 | 3 | require_once('common.inc.php'); |
4 | 4 | |
5 | 5 | if (isset($_REQUEST['course_url'])) { |
6 | - $eventsApi = new CanvasPest($_SESSION['apiUrl'], $_SESSION['apiToken']); |
|
6 | + $eventsApi = new CanvasPest($_SESSION['apiUrl'], $_SESSION['apiToken']); |
|
7 | 7 | |
8 | - // TODO work nicely with the cache (purge uncached events, or only cached events, etc.) |
|
8 | + // TODO work nicely with the cache (purge uncached events, or only cached events, etc.) |
|
9 | 9 | |
10 | - $events = $eventsApi->get('calendar_events', |
|
11 | - array( |
|
12 | - 'type' => 'event', |
|
13 | - 'all_events' => true, |
|
14 | - 'context_codes[]' => preg_replace('|.*/courses/(\d+)/?.*|', "course_$1", $_REQUEST['course_url']) |
|
15 | - ) |
|
16 | - ); |
|
17 | - do { |
|
18 | - foreach($events as $event) { |
|
19 | - $api->delete("calendar_events/{$event['id']}", |
|
20 | - array( |
|
21 | - 'cancel_reason' => $metadata['APP_NAME'] . " course_url={$_REQUEST['course_url']}" |
|
22 | - ) |
|
23 | - ); |
|
24 | - } |
|
25 | - } while($events = $eventsApi->nextPage()); |
|
10 | + $events = $eventsApi->get('calendar_events', |
|
11 | + array( |
|
12 | + 'type' => 'event', |
|
13 | + 'all_events' => true, |
|
14 | + 'context_codes[]' => preg_replace('|.*/courses/(\d+)/?.*|', "course_$1", $_REQUEST['course_url']) |
|
15 | + ) |
|
16 | + ); |
|
17 | + do { |
|
18 | + foreach($events as $event) { |
|
19 | + $api->delete("calendar_events/{$event['id']}", |
|
20 | + array( |
|
21 | + 'cancel_reason' => $metadata['APP_NAME'] . " course_url={$_REQUEST['course_url']}" |
|
22 | + ) |
|
23 | + ); |
|
24 | + } |
|
25 | + } while($events = $eventsApi->nextPage()); |
|
26 | 26 | |
27 | - $smarty->assign('content', 'Calendar purged.'); |
|
27 | + $smarty->assign('content', 'Calendar purged.'); |
|
28 | 28 | } else { |
29 | - $smarty->assign('content', '<form action="' . $_SERVER['PHP_SELF'] . '" method="post"><label for="course_url">Course URL <input id="course_url" name="course_url" type="text" /><input type="submit" value="Purge All Calendar Events" /></form>'); |
|
29 | + $smarty->assign('content', '<form action="' . $_SERVER['PHP_SELF'] . '" method="post"><label for="course_url">Course URL <input id="course_url" name="course_url" type="text" /><input type="submit" value="Purge All Calendar Events" /></form>'); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | $smarty->display(); |
@@ -15,14 +15,14 @@ |
||
15 | 15 | ) |
16 | 16 | ); |
17 | 17 | do { |
18 | - foreach($events as $event) { |
|
18 | + foreach ($events as $event) { |
|
19 | 19 | $api->delete("calendar_events/{$event['id']}", |
20 | 20 | array( |
21 | 21 | 'cancel_reason' => $metadata['APP_NAME'] . " course_url={$_REQUEST['course_url']}" |
22 | 22 | ) |
23 | 23 | ); |
24 | 24 | } |
25 | - } while($events = $eventsApi->nextPage()); |
|
25 | + } while ($events = $eventsApi->nextPage()); |
|
26 | 26 | |
27 | 27 | $smarty->assign('content', 'Calendar purged.'); |
28 | 28 | } else { |
@@ -3,27 +3,27 @@ |
||
3 | 3 | require_once('common.inc.php'); |
4 | 4 | |
5 | 5 | if (isset($_REQUEST['course_url'])) { |
6 | - $courseId = preg_replace('|.*/courses/(\d+)/?.*|', '$1', parse_url($_REQUEST['course_url'], PHP_URL_PATH)); |
|
7 | - $course = $api->get("/courses/$courseId"); |
|
8 | - if ($course) { |
|
9 | - $webcalFeed = str_replace('https://', 'webcal://', $course['calendar']['ics']); |
|
10 | - $smarty->assign('content', ' |
|
6 | + $courseId = preg_replace('|.*/courses/(\d+)/?.*|', '$1', parse_url($_REQUEST['course_url'], PHP_URL_PATH)); |
|
7 | + $course = $api->get("/courses/$courseId"); |
|
8 | + if ($course) { |
|
9 | + $webcalFeed = str_replace('https://', 'webcal://', $course['calendar']['ics']); |
|
10 | + $smarty->assign('content', ' |
|
11 | 11 | <h3>Course Calendar ICS Feed</h3> |
12 | 12 | <p>You can subscribe to the calendar for <a href="https://' . |
13 | - parse_url(CANVAS_API_URL, PHP_URL_HOST) . '/courses/' . $courseId . |
|
14 | - '">' . $course['name'] . '</a> at <a href="' . |
|
15 | - $webcalFeed . '">' . $webcalFeed . |
|
16 | - '</a> in any calendar application that supports external ICS feeds.</p>' |
|
17 | - ); |
|
18 | - } else { |
|
19 | - $messages[] = array( |
|
20 | - 'class' => 'error', |
|
21 | - 'title' => 'Canvas API Error', |
|
22 | - 'content' => 'The course you requested could not be accessed.<pre>' . print_r($json, false) . '</pre>' |
|
23 | - ); |
|
24 | - } |
|
13 | + parse_url(CANVAS_API_URL, PHP_URL_HOST) . '/courses/' . $courseId . |
|
14 | + '">' . $course['name'] . '</a> at <a href="' . |
|
15 | + $webcalFeed . '">' . $webcalFeed . |
|
16 | + '</a> in any calendar application that supports external ICS feeds.</p>' |
|
17 | + ); |
|
18 | + } else { |
|
19 | + $messages[] = array( |
|
20 | + 'class' => 'error', |
|
21 | + 'title' => 'Canvas API Error', |
|
22 | + 'content' => 'The course you requested could not be accessed.<pre>' . print_r($json, false) . '</pre>' |
|
23 | + ); |
|
24 | + } |
|
25 | 25 | } else { |
26 | - $smarty->assign('content', ' |
|
26 | + $smarty->assign('content', ' |
|
27 | 27 | <form method="post" action="' . $_SERVER['PHP_SELF'] . '"> |
28 | 28 | <label for="course_url">Course URL <span class="comment">The URL to the course whose calendar you would like to export as an ICS feed</span></label> |
29 | 29 | <input id="course_url" name="course_url" type="text" /> |
@@ -7,41 +7,41 @@ |
||
7 | 7 | user is about to be asked to log into Canvas in the middle of Canvas */ |
8 | 8 | |
9 | 9 | try { |
10 | - $oauth = new OAuthNegotiator(); |
|
10 | + $oauth = new OAuthNegotiator(); |
|
11 | 11 | } catch (OAuthNegotiator_Exception $e) {} |
12 | 12 | |
13 | 13 | if (isset($_REQUEST['oauth'])) { |
14 | - switch ($_REQUEST['oauth']) { |
|
15 | - case 'request': { |
|
16 | - $smarty->assign('content', '<h1>Token Request</h1> |
|
14 | + switch ($_REQUEST['oauth']) { |
|
15 | + case 'request': { |
|
16 | + $smarty->assign('content', '<h1>Token Request</h1> |
|
17 | 17 | <p>This application requires access to the Canvas APIs. Canvas is about to ask you to give permission for this.</p> |
18 | 18 | <p><a href="' . $_SERVER['PHP_SELF'] . '?oauth=process">Click to continue</a></p>'); |
19 | - $smarty->display(); |
|
20 | - exit; |
|
21 | - } |
|
22 | - case 'process': { |
|
23 | - $oauth = new OAuthNegotiator( |
|
24 | - 'https://' . $toolProvider->user->getResourceLink()->settings['custom_canvas_api_domain'] . '/login/oauth2', |
|
25 | - (string) $secrets->oauth->id, |
|
26 | - (string) $secrets->oauth->key, |
|
27 | - "{$_SERVER['PHP_SELF']}?oauth=complete", |
|
28 | - (string) $secrets->app->name |
|
29 | - ); |
|
30 | - break; |
|
31 | - } |
|
32 | - case 'complete': { |
|
33 | - $user = new UserAPIToken($_SESSION['user_consumer_key'], $_SESSION['user_id'], $sql); |
|
34 | - $user->setToken($oauth->getToken()); |
|
35 | - $user->setAPIUrl("{$metadata['CANVAS_INSTANCE_URL']}/api/v1"); |
|
19 | + $smarty->display(); |
|
20 | + exit; |
|
21 | + } |
|
22 | + case 'process': { |
|
23 | + $oauth = new OAuthNegotiator( |
|
24 | + 'https://' . $toolProvider->user->getResourceLink()->settings['custom_canvas_api_domain'] . '/login/oauth2', |
|
25 | + (string) $secrets->oauth->id, |
|
26 | + (string) $secrets->oauth->key, |
|
27 | + "{$_SERVER['PHP_SELF']}?oauth=complete", |
|
28 | + (string) $secrets->app->name |
|
29 | + ); |
|
30 | + break; |
|
31 | + } |
|
32 | + case 'complete': { |
|
33 | + $user = new UserAPIToken($_SESSION['user_consumer_key'], $_SESSION['user_id'], $sql); |
|
34 | + $user->setToken($oauth->getToken()); |
|
35 | + $user->setAPIUrl("{$metadata['CANVAS_INSTANCE_URL']}/api/v1"); |
|
36 | 36 | |
37 | - $_SESSION['apiToken'] = $user->getToken(); |
|
38 | - $_SESSION['apiUrl'] = $user->getAPIUrl(); |
|
39 | - $_SESSION['isUserToken'] = true; |
|
37 | + $_SESSION['apiToken'] = $user->getToken(); |
|
38 | + $_SESSION['apiUrl'] = $user->getAPIUrl(); |
|
39 | + $_SESSION['isUserToken'] = true; |
|
40 | 40 | |
41 | - header("Location: {$metadata['APP_URL']}/app.php"); |
|
42 | - exit; |
|
43 | - } |
|
44 | - } |
|
41 | + header("Location: {$metadata['APP_URL']}/app.php"); |
|
42 | + exit; |
|
43 | + } |
|
44 | + } |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | ?> |
48 | 48 | \ No newline at end of file |
@@ -4,15 +4,15 @@ discard block |
||
4 | 4 | use Battis\BootstrapSmarty\NotificationMessage; |
5 | 5 | |
6 | 6 | if (isset($_SESSION['toolProvider']->user)) { |
7 | - $_SESSION['canvasInstanceUrl'] = 'https://' . $_SESSION['toolProvider']->user->getResourceLink()->settings['custom_canvas_api_domain']; |
|
7 | + $_SESSION['canvasInstanceUrl'] = 'https://' . $_SESSION['toolProvider']->user->getResourceLink()->settings['custom_canvas_api_domain']; |
|
8 | 8 | } else { |
9 | - $_SESSION['canvasInstanceUrl'] = $metadata['CANVAS_INSTANCE_URL']; |
|
9 | + $_SESSION['canvasInstanceUrl'] = $metadata['CANVAS_INSTANCE_URL']; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | if (isset($_SESSION['apiUrl']) && isset($_SESSION['apiToken'])) { |
13 | - $api = new CanvasPest($_SESSION['apiUrl'], $_SESSION['apiToken']); |
|
13 | + $api = new CanvasPest($_SESSION['apiUrl'], $_SESSION['apiToken']); |
|
14 | 14 | } else { |
15 | - $api = new CanvasPest($metadata['CANVAS_API_URL'], $metadata['CANVAS_API_TOKEN']); |
|
15 | + $api = new CanvasPest($metadata['CANVAS_API_URL'], $metadata['CANVAS_API_TOKEN']); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | /* argument values for sync */ |
@@ -59,18 +59,18 @@ discard block |
||
59 | 59 | |
60 | 60 | $log = null; |
61 | 61 | function postMessage($subject, $body, $flag = NotificationMessage::INFO) { |
62 | - global $log; |
|
63 | - global $smarty; |
|
64 | - if (php_sapi_name() != 'cli') { |
|
65 | - $smarty->addMessage($subject, $body, $flag); |
|
66 | - } else { |
|
67 | - $logEntry = "[$flag] $subject: $body"; |
|
68 | - if (is_a($log, Log::class)) { |
|
69 | - $log->log($logEntry); |
|
70 | - } else { |
|
71 | - echo "$logEntry\n"; |
|
72 | - } |
|
73 | - } |
|
62 | + global $log; |
|
63 | + global $smarty; |
|
64 | + if (php_sapi_name() != 'cli') { |
|
65 | + $smarty->addMessage($subject, $body, $flag); |
|
66 | + } else { |
|
67 | + $logEntry = "[$flag] $subject: $body"; |
|
68 | + if (is_a($log, Log::class)) { |
|
69 | + $log->log($logEntry); |
|
70 | + } else { |
|
71 | + echo "$logEntry\n"; |
|
72 | + } |
|
73 | + } |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -78,45 +78,45 @@ discard block |
||
78 | 78 | * Canvas calendar |
79 | 79 | **/ |
80 | 80 | function getPairingHash($icsUrl, $canvasContext) { |
81 | - global $metadata; |
|
82 | - return md5($icsUrl . $canvasContext . $metadata['CANVAS_INSTANCE_URL']); |
|
81 | + global $metadata; |
|
82 | + return md5($icsUrl . $canvasContext . $metadata['CANVAS_INSTANCE_URL']); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | $FIELD_MAP = array( |
86 | - 'calendar_event[title]' => 'SUMMARY', |
|
87 | - 'calendar_event[description]' => 'DESCRIPTION', |
|
88 | - 'calendar_event[start_at]' => array ( |
|
89 | - 0 => 'X-CURRENT-DTSTART', |
|
90 | - 1 => 'DTSTART' |
|
91 | - ), |
|
92 | - 'calendar_event[end_at]' => array( |
|
93 | - 0 => 'X-CURRENT-DTEND', |
|
94 | - 1 => 'DTEND' |
|
95 | - ), |
|
96 | - 'calendar_event[location_name]' => 'LOCATION' |
|
86 | + 'calendar_event[title]' => 'SUMMARY', |
|
87 | + 'calendar_event[description]' => 'DESCRIPTION', |
|
88 | + 'calendar_event[start_at]' => array ( |
|
89 | + 0 => 'X-CURRENT-DTSTART', |
|
90 | + 1 => 'DTSTART' |
|
91 | + ), |
|
92 | + 'calendar_event[end_at]' => array( |
|
93 | + 0 => 'X-CURRENT-DTEND', |
|
94 | + 1 => 'DTEND' |
|
95 | + ), |
|
96 | + 'calendar_event[location_name]' => 'LOCATION' |
|
97 | 97 | ); |
98 | 98 | |
99 | 99 | /** |
100 | 100 | * Generate a hash of this version of an event to cache in the database |
101 | 101 | **/ |
102 | 102 | function getEventHash($event) { |
103 | - global $FIELD_MAP; |
|
104 | - $blob = ''; |
|
105 | - foreach ($FIELD_MAP as $field) { |
|
106 | - if (is_array($field)) { |
|
107 | - foreach ($field as $option) { |
|
108 | - if (!empty($property = $event->getProperty($option))) { |
|
109 | - $blob .= serialize($property); |
|
110 | - break; |
|
111 | - } |
|
112 | - } |
|
113 | - } else { |
|
114 | - if (!empty($property = $event->getProperty($field))) { |
|
115 | - $blob .= serialize($property); |
|
116 | - } |
|
117 | - } |
|
118 | - } |
|
119 | - return md5($blob); |
|
103 | + global $FIELD_MAP; |
|
104 | + $blob = ''; |
|
105 | + foreach ($FIELD_MAP as $field) { |
|
106 | + if (is_array($field)) { |
|
107 | + foreach ($field as $option) { |
|
108 | + if (!empty($property = $event->getProperty($option))) { |
|
109 | + $blob .= serialize($property); |
|
110 | + break; |
|
111 | + } |
|
112 | + } |
|
113 | + } else { |
|
114 | + if (!empty($property = $event->getProperty($field))) { |
|
115 | + $blob .= serialize($property); |
|
116 | + } |
|
117 | + } |
|
118 | + } |
|
119 | + return md5($blob); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -124,14 +124,14 @@ discard block |
||
124 | 124 | **/ |
125 | 125 | $SYNC_TIMESTAMP = null; |
126 | 126 | function getSyncTimestamp() { |
127 | - global $SYNC_TIMESTAMP; |
|
128 | - if ($SYNC_TIMESTAMP) { |
|
129 | - return $SYNC_TIMESTAMP; |
|
130 | - } else { |
|
131 | - $timestamp = new DateTime(); |
|
132 | - $SYNC_TIMESTAMP = $timestamp->format(SYNC_TIMESTAMP_FORMAT) . SEPARATOR . md5((php_sapi_name() == 'cli' ? 'cli' : $_SERVER['REMOTE_ADDR']) . time()); |
|
133 | - return $SYNC_TIMESTAMP; |
|
134 | - } |
|
127 | + global $SYNC_TIMESTAMP; |
|
128 | + if ($SYNC_TIMESTAMP) { |
|
129 | + return $SYNC_TIMESTAMP; |
|
130 | + } else { |
|
131 | + $timestamp = new DateTime(); |
|
132 | + $SYNC_TIMESTAMP = $timestamp->format(SYNC_TIMESTAMP_FORMAT) . SEPARATOR . md5((php_sapi_name() == 'cli' ? 'cli' : $_SERVER['REMOTE_ADDR']) . time()); |
|
133 | + return $SYNC_TIMESTAMP; |
|
134 | + } |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | ?> |
@@ -85,7 +85,7 @@ |
||
85 | 85 | $FIELD_MAP = array( |
86 | 86 | 'calendar_event[title]' => 'SUMMARY', |
87 | 87 | 'calendar_event[description]' => 'DESCRIPTION', |
88 | - 'calendar_event[start_at]' => array ( |
|
88 | + 'calendar_event[start_at]' => array( |
|
89 | 89 | 0 => 'X-CURRENT-DTSTART', |
90 | 90 | 1 => 'DTSTART' |
91 | 91 | ), |