Completed
Push — develop ( 4e1ddc...b1c313 )
by Seth
02:25
created
common.inc.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@
 block discarded – undo
13 13
 
14 14
 /* prepare the toolbox */
15 15
 if (empty($_SESSION[Toolbox::class])) {
16
-    $_SESSION[Toolbox::class] =& Toolbox::fromConfiguration(CONFIG_FILE);
16
+	$_SESSION[Toolbox::class] =& Toolbox::fromConfiguration(CONFIG_FILE);
17 17
 }
18 18
 $toolbox =& $_SESSION[Toolbox::class];
19 19
 $toolbox->smarty_prependTemplateDir(__DIR__ . '/templates', basename(__DIR__));
20 20
 $toolbox->smarty_assign([
21
-    'category' => DataUtilities::titleCase(preg_replace('/[\-_]+/', ' ', basename(__DIR__)))
21
+	'category' => DataUtilities::titleCase(preg_replace('/[\-_]+/', ' ', basename(__DIR__)))
22 22
 ]);
23 23
 
24 24
 /* set the Tool Consumer's instance URL, if present */
25 25
 if (empty($_SESSION[CANVAS_INSTANCE_URL]) &&
26
-    !empty($_SESSION[ToolProvider::class]['canvas']['api_domain'])
26
+	!empty($_SESSION[ToolProvider::class]['canvas']['api_domain'])
27 27
 ) {
28
-    $_SESSION[CANVAS_INSTANCE_URL] = 'https://' . $_SESSION[ToolProvider::class]['canvas']['api_domain'];
28
+	$_SESSION[CANVAS_INSTANCE_URL] = 'https://' . $_SESSION[ToolProvider::class]['canvas']['api_domain'];
29 29
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once __DIR__ . '/vendor/autoload.php';
3
+require_once __DIR__.'/vendor/autoload.php';
4 4
 
5 5
 use smtech\StMarksReflexiveCanvasLTIExample\Toolbox;
6 6
 use smtech\ReflexiveCanvasLTI\LTI\ToolProvider;
7 7
 use Battis\DataUtilities;
8 8
 
9
-define('CONFIG_FILE', __DIR__ . '/config.xml');
9
+define('CONFIG_FILE', __DIR__.'/config.xml');
10 10
 define('CANVAS_INSTANCE_URL', 'canvas_instance_url');
11 11
 
12 12
 @session_start(); // TODO I don't feel good about suppressing warnings
13 13
 
14 14
 /* prepare the toolbox */
15 15
 if (empty($_SESSION[Toolbox::class])) {
16
-    $_SESSION[Toolbox::class] =& Toolbox::fromConfiguration(CONFIG_FILE);
16
+    $_SESSION[Toolbox::class] = & Toolbox::fromConfiguration(CONFIG_FILE);
17 17
 }
18
-$toolbox =& $_SESSION[Toolbox::class];
19
-$toolbox->smarty_prependTemplateDir(__DIR__ . '/templates', basename(__DIR__));
18
+$toolbox = & $_SESSION[Toolbox::class];
19
+$toolbox->smarty_prependTemplateDir(__DIR__.'/templates', basename(__DIR__));
20 20
 $toolbox->smarty_assign([
21 21
     'category' => DataUtilities::titleCase(preg_replace('/[\-_]+/', ' ', basename(__DIR__)))
22 22
 ]);
@@ -25,5 +25,5 @@  discard block
 block discarded – undo
25 25
 if (empty($_SESSION[CANVAS_INSTANCE_URL]) &&
26 26
     !empty($_SESSION[ToolProvider::class]['canvas']['api_domain'])
27 27
 ) {
28
-    $_SESSION[CANVAS_INSTANCE_URL] = 'https://' . $_SESSION[ToolProvider::class]['canvas']['api_domain'];
28
+    $_SESSION[CANVAS_INSTANCE_URL] = 'https://'.$_SESSION[ToolProvider::class]['canvas']['api_domain'];
29 29
 }
Please login to merge, or discard this patch.
index.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -13,74 +13,74 @@
 block discarded – undo
13 13
 
14 14
 /* store any requested actions for future handling */
15 15
 $action = (empty($_REQUEST['action']) ?
16
-    ACTION_UNSPECIFIED :
17
-    strtolower($_REQUEST['action'])
16
+	ACTION_UNSPECIFIED :
17
+	strtolower($_REQUEST['action'])
18 18
 );
19 19
 
20 20
 /* action requests only come from outside the LTI! */
21 21
 if ($action) {
22
-    unset($_SESSION[ToolProvider::class]);
22
+	unset($_SESSION[ToolProvider::class]);
23 23
 }
24 24
 
25 25
 /* authenticate LTI launch request, if present */
26 26
 if ($toolbox->lti_isLaunching()) {
27
-    $toolbox->resetSession();
28
-    $toolbox->lti_authenticate();
29
-    exit;
27
+	$toolbox->resetSession();
28
+	$toolbox->lti_authenticate();
29
+	exit;
30 30
 }
31 31
 
32 32
 /* if authenticated LTI launch, get the current user profile */
33 33
 if (!empty($_SESSION[ToolProvider::class]['canvas'])) {
34
-    try {
35
-        $profile = $toolbox->api_get('users/' . $_SESSION[ToolProvider::class]['canvas']['user_id'] . '/profile');
36
-    } catch (Exception $e) {
37
-        $toolbox->smarty_addMessage(
38
-            'Error',
39
-            json_decode($e->getMessage(), true),
40
-            NotificationMessage::DANGER
41
-        );
42
-    }
43
-    $toolbox->smarty_assign([
44
-        'profile' => $profile
45
-    ]);
46
-    $toolbox->smarty_display('home.tpl');
47
-    exit;
34
+	try {
35
+		$profile = $toolbox->api_get('users/' . $_SESSION[ToolProvider::class]['canvas']['user_id'] . '/profile');
36
+	} catch (Exception $e) {
37
+		$toolbox->smarty_addMessage(
38
+			'Error',
39
+			json_decode($e->getMessage(), true),
40
+			NotificationMessage::DANGER
41
+		);
42
+	}
43
+	$toolbox->smarty_assign([
44
+		'profile' => $profile
45
+	]);
46
+	$toolbox->smarty_display('home.tpl');
47
+	exit;
48 48
 
49 49
 /* if not authenticated, default to showing credentials */
50 50
 } else {
51
-    $action = (empty($action) ?
52
-        ACTION_CONFIG :
53
-        $action
54
-    );
51
+	$action = (empty($action) ?
52
+		ACTION_CONFIG :
53
+		$action
54
+	);
55 55
 }
56 56
 
57 57
 /* process any actions */
58 58
 switch ($action) {
59
-    /* reset cached install data from config file */
60
-    case ACTION_INSTALL:
61
-        $_SESSION['toolbox'] = Toolbox::fromConfiguration(CONFIG_FILE, true);
62
-        $toolbox =& $_SESSION['toolbox'];
59
+	/* reset cached install data from config file */
60
+	case ACTION_INSTALL:
61
+		$_SESSION['toolbox'] = Toolbox::fromConfiguration(CONFIG_FILE, true);
62
+		$toolbox =& $_SESSION['toolbox'];
63 63
 
64
-        /* test to see if we can connect to the API */
65
-        try {
66
-            $toolbox->getAPI();
67
-        } catch (ConfigurationException $e) {
68
-            /* if there isn't an API token in config.xml, are there OAuth credentials? */
69
-            if ($e->getCode() === ConfigurationException::CANVAS_API_INCORRECT) {
70
-                $toolbox->interactiveGetAccessToken();
71
-                exit;
72
-            } else { /* no (understandable) API credentials available -- doh! */
73
-                throw $e;
74
-            }
75
-        }
64
+		/* test to see if we can connect to the API */
65
+		try {
66
+			$toolbox->getAPI();
67
+		} catch (ConfigurationException $e) {
68
+			/* if there isn't an API token in config.xml, are there OAuth credentials? */
69
+			if ($e->getCode() === ConfigurationException::CANVAS_API_INCORRECT) {
70
+				$toolbox->interactiveGetAccessToken();
71
+				exit;
72
+			} else { /* no (understandable) API credentials available -- doh! */
73
+				throw $e;
74
+			}
75
+		}
76 76
 
77
-        /* finish by opening consumers control panel */
78
-        header('Location: consumers.php');
79
-        exit;
77
+		/* finish by opening consumers control panel */
78
+		header('Location: consumers.php');
79
+		exit;
80 80
 
81
-    /* show LTI configuration XML file */
82
-    case ACTION_CONFIG:
83
-        header('Content-type: application/xml');
84
-        echo $toolbox->saveConfigurationXML();
85
-        exit;
81
+	/* show LTI configuration XML file */
82
+	case ACTION_CONFIG:
83
+		header('Content-type: application/xml');
84
+		echo $toolbox->saveConfigurationXML();
85
+		exit;
86 86
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,8 +13,7 @@  discard block
 block discarded – undo
13 13
 
14 14
 /* store any requested actions for future handling */
15 15
 $action = (empty($_REQUEST['action']) ?
16
-    ACTION_UNSPECIFIED :
17
-    strtolower($_REQUEST['action'])
16
+    ACTION_UNSPECIFIED : strtolower($_REQUEST['action'])
18 17
 );
19 18
 
20 19
 /* action requests only come from outside the LTI! */
@@ -32,7 +31,7 @@  discard block
 block discarded – undo
32 31
 /* if authenticated LTI launch, get the current user profile */
33 32
 if (!empty($_SESSION[ToolProvider::class]['canvas'])) {
34 33
     try {
35
-        $profile = $toolbox->api_get('users/' . $_SESSION[ToolProvider::class]['canvas']['user_id'] . '/profile');
34
+        $profile = $toolbox->api_get('users/'.$_SESSION[ToolProvider::class]['canvas']['user_id'].'/profile');
36 35
     } catch (Exception $e) {
37 36
         $toolbox->smarty_addMessage(
38 37
             'Error',
@@ -49,8 +48,7 @@  discard block
 block discarded – undo
49 48
 /* if not authenticated, default to showing credentials */
50 49
 } else {
51 50
     $action = (empty($action) ?
52
-        ACTION_CONFIG :
53
-        $action
51
+        ACTION_CONFIG : $action
54 52
     );
55 53
 }
56 54
 
@@ -59,7 +57,7 @@  discard block
 block discarded – undo
59 57
     /* reset cached install data from config file */
60 58
     case ACTION_INSTALL:
61 59
         $_SESSION['toolbox'] = Toolbox::fromConfiguration(CONFIG_FILE, true);
62
-        $toolbox =& $_SESSION['toolbox'];
60
+        $toolbox = & $_SESSION['toolbox'];
63 61
 
64 62
         /* test to see if we can connect to the API */
65 63
         try {
Please login to merge, or discard this patch.
export.php 2 patches
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -3,27 +3,27 @@
 block discarded – undo
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([
11
-            'content' => '<h3>Course Calendar ICS Feed</h3>
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([
11
+			'content' => '<h3>Course Calendar ICS Feed</h3>
12 12
                 <p>You can subscribe to the calendar for <a href="https://' .
13
-                $_SESSION[CANVAS_INSTANCE_URL] . '/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
+				$_SESSION[CANVAS_INSTANCE_URL] . '/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" />
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -10,21 +10,21 @@
 block discarded – undo
10 10
         $smarty->assign([
11 11
             'content' => '<h3>Course Calendar ICS Feed</h3>
12 12
                 <p>You can subscribe to the calendar for <a href="https://' .
13
-                $_SESSION[CANVAS_INSTANCE_URL] . '/courses/' . $courseId .
14
-                '">' . $course['name'] . '</a> at <a href="' .
15
-                $webcalFeed . '">' . $webcalFeed .
13
+                $_SESSION[CANVAS_INSTANCE_URL].'/courses/'.$courseId.
14
+                '">'.$course['name'].'</a> at <a href="'.
15
+                $webcalFeed.'">'.$webcalFeed.
16 16
                 '</a> in any calendar application that supports external ICS feeds.</p>'
17 17
             ]);
18 18
     } else {
19 19
         $messages[] = array(
20 20
             'class' => 'error',
21 21
             'title' => 'Canvas API Error',
22
-            'content' => 'The course you requested could not be accessed.<pre>' . print_r($json, false) . '</pre>'
22
+            'content' => 'The course you requested could not be accessed.<pre>'.print_r($json, false).'</pre>'
23 23
         );
24 24
     }
25 25
 } else {
26 26
     $smarty->assign('content', '
27
-    <form method="post" action="' . $_SERVER['PHP_SELF'] . '">
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" />
30 30
         <input type="submit" value="Generate ICS Feed" />
Please login to merge, or discard this patch.
visualize.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@  discard block
 block discarded – undo
10 10
 $smarty->addTemplateDir(__DIR__ . '/templates');
11 11
 
12 12
 if (empty($_REQUEST['url'])) {
13
-    $smarty->display('visualize-form.tpl');
14
-    exit;
13
+	$smarty->display('visualize-form.tpl');
14
+	exit;
15 15
 }
16 16
 
17 17
 $config = new ConfigXML(__DIR__ . '/secrets.xml');
@@ -22,14 +22,14 @@  discard block
 block discarded – undo
22 22
 
23 23
 $ics = $cache->getCache($_REQUEST['url']);
24 24
 if (empty($ics)) {
25
-    $ics = new vcalendar(
26
-        array(
27
-            'unique_id' => basename(__FILE__, '.php'),
28
-            'url' => $_REQUEST['url']
29
-        )
30
-    );
31
-    $ics->parse();
32
-    $cache->setCache($_REQUEST['url'], $ics);
25
+	$ics = new vcalendar(
26
+		array(
27
+			'unique_id' => basename(__FILE__, '.php'),
28
+			'url' => $_REQUEST['url']
29
+		)
30
+	);
31
+	$ics->parse();
32
+	$cache->setCache($_REQUEST['url'], $ics);
33 33
 }
34 34
 
35 35
 $smarty->assign('ics', $ics);
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,20 +1,20 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once __DIR__ . '/vendor/autoload.php';
3
+require_once __DIR__.'/vendor/autoload.php';
4 4
 
5 5
 use smtech\StMarksSmarty\StMarksSmarty;
6 6
 use Battis\ConfigXML;
7 7
 use Battis\HierarchicalSimpleCache;
8 8
 
9 9
 $smarty = StMarksSmarty::getSmarty();
10
-$smarty->addTemplateDir(__DIR__ . '/templates');
10
+$smarty->addTemplateDir(__DIR__.'/templates');
11 11
 
12 12
 if (empty($_REQUEST['url'])) {
13 13
     $smarty->display('visualize-form.tpl');
14 14
     exit;
15 15
 }
16 16
 
17
-$config = new ConfigXML(__DIR__ . '/secrets.xml');
17
+$config = new ConfigXML(__DIR__.'/secrets.xml');
18 18
 
19 19
 $sql = $config->newInstanceOf(mysqli::class, 'mysql');
20 20
 
@@ -33,5 +33,5 @@  discard block
 block discarded – undo
33 33
 }
34 34
 
35 35
 $smarty->assign('ics', $ics);
36
-$smarty->assign('veventProperties', array('unique' => array('CLASS','CREATED','SUMMARY','DESCRIPTION','DTSTART','X-CURRENT-DTSTART','DTEND','X-CURRENT-DTEND','DURATION','GEO','LAST-MOD','LOCATION','ORGANIZER','PRIORITY','DTSTAMP','SEQ','STATUS','TRANSP','UID','URL','RECURID'),'multiple'=>array('ATTACH','ATTENDEE','CATEGORIES','COMMENT','CONTACT','EXDATE','EXRULE','RSTATUS','RELATED','RESOURCES','RDATE','RRULE','X-PROP')));
36
+$smarty->assign('veventProperties', array('unique' => array('CLASS', 'CREATED', 'SUMMARY', 'DESCRIPTION', 'DTSTART', 'X-CURRENT-DTSTART', 'DTEND', 'X-CURRENT-DTEND', 'DURATION', 'GEO', 'LAST-MOD', 'LOCATION', 'ORGANIZER', 'PRIORITY', 'DTSTAMP', 'SEQ', 'STATUS', 'TRANSP', 'UID', 'URL', 'RECURID'), 'multiple'=>array('ATTACH', 'ATTENDEE', 'CATEGORIES', 'COMMENT', 'CONTACT', 'EXDATE', 'EXRULE', 'RSTATUS', 'RELATED', 'RESOURCES', 'RDATE', 'RRULE', 'X-PROP')));
37 37
 $smarty->display('visualize.tpl');
Please login to merge, or discard this patch.
import.php 3 patches
Indentation   +257 added lines, -257 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (php_sapi_name() == 'cli') {
4
-    // TODO there is a more streamlined way of doing this that escapes me just this second
5
-    $_REQUEST['cal'] = $argv[1];
6
-    $_REQUEST['canvas_url'] = $argv[2];
7
-    $_REQUEST['schedule'] = $argv[3];
4
+	// TODO there is a more streamlined way of doing this that escapes me just this second
5
+	$_REQUEST['cal'] = $argv[1];
6
+	$_REQUEST['canvas_url'] = $argv[2];
7
+	$_REQUEST['schedule'] = $argv[3];
8 8
 
9
-    define('IGNORE_LTI', true);
9
+	define('IGNORE_LTI', true);
10 10
 }
11 11
 
12 12
 require_once 'common.inc.php';
@@ -19,8 +19,8 @@  discard block
 block discarded – undo
19 19
  **/
20 20
 function urlExists($url)
21 21
 {
22
-    $handle = fopen($url, 'r');
23
-    return $handle !== false;
22
+	$handle = fopen($url, 'r');
23
+	return $handle !== false;
24 24
 }
25 25
 
26 26
 /**
@@ -28,41 +28,41 @@  discard block
 block discarded – undo
28 28
  **/
29 29
 function getCanvasContext($canvasUrl)
30 30
 {
31
-    global $metadata;
32
-
33
-    // TODO: accept calendar2?contexts links too (they would be an intuitively obvious link to use, after all)
34
-    // FIXME: users aren't working
35
-    // TODO: it would probably be better to look up users by email address than URL
36
-    /* get the context (user, course or group) for the canvas URL */
37
-    $canvasContext = array();
38
-    if (preg_match('%(https?://)?(' . parse_url($metadata['CANVAS_INSTANCE_URL'], PHP_URL_HOST) . '/((about/(\d+))|(courses/(\d+)(/groups/(\d+))?)|(accounts/\d+/groups/(\d+))))%', $_REQUEST['canvas_url'], $matches)) {
39
-        $canvasContext['canonical_url'] = "https://{$matches[2]}"; // https://stmarksschool.instructure.com/courses/953
40
-
41
-        // course or account groups
42
-        if (isset($matches[9]) || isset($matches[11])) {
43
-            $canvasContext['context'] = 'group'; // used to for context_code in events
44
-            $canvasContext['id'] = ($matches[9] > $matches[11] ? $matches[9] : $matches[11]);
45
-            $canvasContext['verification_url'] = "groups/{$canvasContext['id']}"; // used once to look up the object to be sure it really exists
46
-
47
-        // courses
48
-        } elseif (isset($matches[7])) {
49
-            $canvasContext['context'] = 'course';
50
-            $canvasContext['id'] = $matches[7];
51
-            $canvasContext['verification_url'] = "courses/{$canvasContext['id']}";
52
-
53
-        // users
54
-        } elseif (isset($matches[5])) {
55
-            $canvasContext['context'] = 'user';
56
-            $canvasContext['id'] = $matches[5];
57
-            $canvasContext['verification_url'] = "users/{$canvasContext['id']}/profile";
58
-
59
-        // we're somewhere where we don't know where we are
60
-        } else {
61
-            return false;
62
-        }
63
-        return $canvasContext;
64
-    }
65
-    return false;
31
+	global $metadata;
32
+
33
+	// TODO: accept calendar2?contexts links too (they would be an intuitively obvious link to use, after all)
34
+	// FIXME: users aren't working
35
+	// TODO: it would probably be better to look up users by email address than URL
36
+	/* get the context (user, course or group) for the canvas URL */
37
+	$canvasContext = array();
38
+	if (preg_match('%(https?://)?(' . parse_url($metadata['CANVAS_INSTANCE_URL'], PHP_URL_HOST) . '/((about/(\d+))|(courses/(\d+)(/groups/(\d+))?)|(accounts/\d+/groups/(\d+))))%', $_REQUEST['canvas_url'], $matches)) {
39
+		$canvasContext['canonical_url'] = "https://{$matches[2]}"; // https://stmarksschool.instructure.com/courses/953
40
+
41
+		// course or account groups
42
+		if (isset($matches[9]) || isset($matches[11])) {
43
+			$canvasContext['context'] = 'group'; // used to for context_code in events
44
+			$canvasContext['id'] = ($matches[9] > $matches[11] ? $matches[9] : $matches[11]);
45
+			$canvasContext['verification_url'] = "groups/{$canvasContext['id']}"; // used once to look up the object to be sure it really exists
46
+
47
+		// courses
48
+		} elseif (isset($matches[7])) {
49
+			$canvasContext['context'] = 'course';
50
+			$canvasContext['id'] = $matches[7];
51
+			$canvasContext['verification_url'] = "courses/{$canvasContext['id']}";
52
+
53
+		// users
54
+		} elseif (isset($matches[5])) {
55
+			$canvasContext['context'] = 'user';
56
+			$canvasContext['id'] = $matches[5];
57
+			$canvasContext['verification_url'] = "users/{$canvasContext['id']}/profile";
58
+
59
+		// we're somewhere where we don't know where we are
60
+		} else {
61
+			return false;
62
+		}
63
+		return $canvasContext;
64
+	}
65
+	return false;
66 66
 }
67 67
 
68 68
 /**
@@ -73,22 +73,22 @@  discard block
 block discarded – undo
73 73
 function filterEvent($event, $calendarCache)
74 74
 {
75 75
 
76
-     return (
77
-         // include this event if filtering is off...
78
-         $calendarCache['enable_regexp_filter'] == false ||
79
-         (
80
-            (
81
-                ( // if filtering is on, and there's an include pattern test that pattern...
82
-                    !empty($calendarCache['include_regexp']) &&
83
-                    preg_match("%{$calendarCache['include_regexp']}%", $event->getProperty('SUMMARY'))
84
-                )
85
-            ) &&
86
-            !( // if there is an exclude pattern, make sure that this event is NOT excluded
87
-                !empty($calendarCache['exclude_regexp']) &&
88
-                preg_match("%{$calendarCache['exclude_regexp']}%", $event->getProperty('SUMMARY'))
89
-            )
90
-        )
91
-    );
76
+	 return (
77
+		 // include this event if filtering is off...
78
+		 $calendarCache['enable_regexp_filter'] == false ||
79
+		 (
80
+			(
81
+				( // if filtering is on, and there's an include pattern test that pattern...
82
+					!empty($calendarCache['include_regexp']) &&
83
+					preg_match("%{$calendarCache['include_regexp']}%", $event->getProperty('SUMMARY'))
84
+				)
85
+			) &&
86
+			!( // if there is an exclude pattern, make sure that this event is NOT excluded
87
+				!empty($calendarCache['exclude_regexp']) &&
88
+				preg_match("%{$calendarCache['exclude_regexp']}%", $event->getProperty('SUMMARY'))
89
+			)
90
+		)
91
+	);
92 92
 }
93 93
 
94 94
 // TODO: it would be nice to be able to cleanly remove a synched calendar
@@ -99,54 +99,54 @@  discard block
 block discarded – undo
99 99
 /* do we have the vital information (an ICS feed and a URL to a canvas
100 100
    object)? */
101 101
 if (isset($_REQUEST['cal']) && isset($_REQUEST['canvas_url'])) {
102
-    if ($canvasContext = getCanvasContext($_REQUEST['canvas_url'])) {
103
-        /* check ICS feed to be sure it exists */
104
-        if (urlExists($_REQUEST['cal'])) {
105
-            /* look up the canvas object -- mostly to make sure that it exists! */
106
-            if ($canvasObject = $api->get($canvasContext['verification_url'])) {
107
-                /* calculate the unique pairing ID of this ICS feed and canvas object */
108
-                $pairingHash = $toolbox->getPairingHash($_REQUEST['cal'], $canvasContext['canonical_url']);
109
-                $log = Log::singleton('file', __DIR__ . "/logs/$pairingHash.log");
110
-                postMessage('Sync started', getSyncTimestamp(), NotificationMessage::INFO);
111
-
112
-                /* tell users that it's started and to cool their jets */
113
-                if (php_sapi_name() != 'cli') {
114
-                    $smarty->assign([
115
-                        'content' => '<h3>Calendar Import Started</h3>
102
+	if ($canvasContext = getCanvasContext($_REQUEST['canvas_url'])) {
103
+		/* check ICS feed to be sure it exists */
104
+		if (urlExists($_REQUEST['cal'])) {
105
+			/* look up the canvas object -- mostly to make sure that it exists! */
106
+			if ($canvasObject = $api->get($canvasContext['verification_url'])) {
107
+				/* calculate the unique pairing ID of this ICS feed and canvas object */
108
+				$pairingHash = $toolbox->getPairingHash($_REQUEST['cal'], $canvasContext['canonical_url']);
109
+				$log = Log::singleton('file', __DIR__ . "/logs/$pairingHash.log");
110
+				postMessage('Sync started', getSyncTimestamp(), NotificationMessage::INFO);
111
+
112
+				/* tell users that it's started and to cool their jets */
113
+				if (php_sapi_name() != 'cli') {
114
+					$smarty->assign([
115
+						'content' => '<h3>Calendar Import Started</h3>
116 116
                         <p>The calendar import that you requested has begun. You may leave this page at anytime. You can see the progress of the import by visiting <a target="_blank" href="' . $_SESSION[CANVAS_INSTANCE_URL] . "/calendar?include_contexts={$canvasContext['context']}_{$canvasObject['id']}\">this calendar</a> in Canvas.</p>"
117
-                    ]);
118
-                    $smarty->display('page.tpl');
119
-                }
120
-
121
-                /* parse the ICS feed */
122
-                $ics = new vcalendar(
123
-                    array(
124
-                        'unique_id' => $metadata['APP_ID'],
125
-                        'url' => $_REQUEST['cal']
126
-                    )
127
-                );
128
-                $ics->parse();
129
-
130
-                /* log this pairing in the database cache, if it doesn't already exist */
131
-                $calendarCacheResponse = $sql->query("
117
+					]);
118
+					$smarty->display('page.tpl');
119
+				}
120
+
121
+				/* parse the ICS feed */
122
+				$ics = new vcalendar(
123
+					array(
124
+						'unique_id' => $metadata['APP_ID'],
125
+						'url' => $_REQUEST['cal']
126
+					)
127
+				);
128
+				$ics->parse();
129
+
130
+				/* log this pairing in the database cache, if it doesn't already exist */
131
+				$calendarCacheResponse = $sql->query("
132 132
                     SELECT *
133 133
                         FROM `calendars`
134 134
                         WHERE
135 135
                             `id` = '$pairingHash'
136 136
                 ");
137
-                $calendarCache = $calendarCacheResponse->fetch_assoc();
137
+				$calendarCache = $calendarCacheResponse->fetch_assoc();
138 138
 
139
-                /* if the calendar is already cached, just update the sync timestamp */
140
-                if ($calendarCache) {
141
-                    $sql->query("
139
+				/* if the calendar is already cached, just update the sync timestamp */
140
+				if ($calendarCache) {
141
+					$sql->query("
142 142
                         UPDATE `calendars`
143 143
                             SET
144 144
                                 `synced` = '" . getSyncTimestamp() . "'
145 145
                             WHERE
146 146
                                 `id` = '$pairingHash'
147 147
                     ");
148
-                } else {
149
-                    $sql->query("
148
+				} else {
149
+					$sql->query("
150 150
                         INSERT INTO `calendars`
151 151
                             (
152 152
                                 `id`,
@@ -169,44 +169,44 @@  discard block
 block discarded – undo
169 169
                                 " . ($_REQUEST['enable_regexp_filter'] == VALUE_ENABLE_REGEXP_FILTER ? "'" . $sql->real_escape_string($_REQUEST['exclude_regexp']) . "'" : 'NULL') . "
170 170
                             )
171 171
                     ");
172
-                }
172
+				}
173 173
 
174
-                /* refresh calendar information from cache database */
175
-                $calendarCacheResponse = $sql->query("
174
+				/* refresh calendar information from cache database */
175
+				$calendarCacheResponse = $sql->query("
176 176
                     SELECT *
177 177
                         FROM `calendars`
178 178
                         WHERE
179 179
                             `id` = '$pairingHash'
180 180
                 ");
181
-                $calendarCache = $calendarCacheResponse->fetch_assoc();
181
+				$calendarCache = $calendarCacheResponse->fetch_assoc();
182 182
 
183
-                /* walk through $master_array and update the Canvas calendar to match the
183
+				/* walk through $master_array and update the Canvas calendar to match the
184 184
                    ICS feed, caching changes in the database */
185
-                // TODO: would it be worth the performance improvement to just process things from today's date forward? (i.e. ignore old items, even if they've changed...)
186
-                // TODO:0 the best window for syncing would be the term of the course in question, right? issue:12
187
-                // TODO:0 Arbitrarily selecting events in for a year on either side of today's date, probably a better system? issue:12
188
-                foreach ($ics->selectComponents(
189
-                    date('Y')-1, // startYear
190
-                    date('m'), // startMonth
191
-                    date('d'), // startDay
192
-                    date('Y')+1, // endYEar
193
-                    date('m'), // endMonth
194
-                    date('d'), // endDay
195
-                    'vevent', // cType
196
-                    false, // flat
197
-                    true, // any
198
-                    true // split
199
-                ) as $year) {
200
-                    foreach ($year as $month => $days) {
201
-                        foreach ($days as $day => $events) {
202
-                            foreach ($events as $i => $event) {
203
-                                /* does this event already exist in Canvas? */
204
-                                $eventHash = getEventHash($event);
205
-
206
-                                /* if the event should be included... */
207
-                                if (filterEvent($event, $calendarCache)) {
208
-                                    /* have we cached this event already? */
209
-                                    $eventCacheResponse = $sql->query("
185
+				// TODO: would it be worth the performance improvement to just process things from today's date forward? (i.e. ignore old items, even if they've changed...)
186
+				// TODO:0 the best window for syncing would be the term of the course in question, right? issue:12
187
+				// TODO:0 Arbitrarily selecting events in for a year on either side of today's date, probably a better system? issue:12
188
+				foreach ($ics->selectComponents(
189
+					date('Y')-1, // startYear
190
+					date('m'), // startMonth
191
+					date('d'), // startDay
192
+					date('Y')+1, // endYEar
193
+					date('m'), // endMonth
194
+					date('d'), // endDay
195
+					'vevent', // cType
196
+					false, // flat
197
+					true, // any
198
+					true // split
199
+				) as $year) {
200
+					foreach ($year as $month => $days) {
201
+						foreach ($days as $day => $events) {
202
+							foreach ($events as $i => $event) {
203
+								/* does this event already exist in Canvas? */
204
+								$eventHash = getEventHash($event);
205
+
206
+								/* if the event should be included... */
207
+								if (filterEvent($event, $calendarCache)) {
208
+									/* have we cached this event already? */
209
+									$eventCacheResponse = $sql->query("
210 210
                                         SELECT *
211 211
                                             FROM `events`
212 212
                                             WHERE
@@ -215,11 +215,11 @@  discard block
 block discarded – undo
215 215
                                     ");
216 216
 
217 217
 
218
-                                    /* if we already have the event cached in its current form, just update
218
+									/* if we already have the event cached in its current form, just update
219 219
                                        the timestamp */
220
-                                    $eventCache = $eventCacheResponse->fetch_assoc();
221
-                                    if ($eventCache) {
222
-                                        $sql->query("
220
+									$eventCache = $eventCacheResponse->fetch_assoc();
221
+									if ($eventCache) {
222
+										$sql->query("
223 223
                                             UPDATE `events`
224 224
                                                 SET
225 225
                                                     `synced` = '" . getSyncTimestamp() . "'
@@ -227,31 +227,31 @@  discard block
 block discarded – undo
227 227
                                                     `id` = '{$eventCache['id']}'
228 228
                                         ");
229 229
 
230
-                                    /* otherwise, add this new event and cache it */
231
-                                    } else {
232
-                                        /* multi-day event instance start times need to be changed to _this_ date */
233
-                                        $start = new DateTime(iCalUtilityFunctions::_date2strdate($event->getProperty('DTSTART')));
234
-                                        $end = new DateTime(iCalUtilityFunctions::_date2strdate($event->getProperty('DTEND')));
235
-                                        if ($event->getProperty('X-RECURRENCE')) {
236
-                                            $start = new DateTime($event->getProperty('X-CURRENT-DTSTART')[1]);
237
-                                            $end = new DateTime($event->getProperty('X-CURRENT-DTEND')[1]);
238
-                                        }
239
-                                        $start->setTimeZone(new DateTimeZone(LOCAL_TIMEZONE));
240
-                                        $end->setTimeZone(new DateTimeZone(LOCAL_TIMEZONE));
241
-
242
-                                        $calendarEvent = $api->post(
243
-                                            "/calendar_events",
244
-                                            [
245
-                                                'calendar_event[context_code]' => "{$canvasContext['context']}_{$canvasObject['id']}",
246
-                                                'calendar_event[title]' => preg_replace('%^([^\]]+)(\s*\[[^\]]+\]\s*)+$%', '\\1', strip_tags($event->getProperty('SUMMARY'))),
247
-                                                'calendar_event[description]' => \Michelf\Markdown::defaultTransform(str_replace('\n', "\n\n", $event->getProperty('DESCRIPTION', 1))),
248
-                                                'calendar_event[start_at]' => $start->format(CANVAS_TIMESTAMP_FORMAT),
249
-                                                'calendar_event[end_at]' => $end->format(CANVAS_TIMESTAMP_FORMAT),
250
-                                                'calendar_event[location_name]' => $event->getProperty('LOCATION')
251
-                                            ]
252
-                                        );
253
-
254
-                                        $sql->query("
230
+									/* otherwise, add this new event and cache it */
231
+									} else {
232
+										/* multi-day event instance start times need to be changed to _this_ date */
233
+										$start = new DateTime(iCalUtilityFunctions::_date2strdate($event->getProperty('DTSTART')));
234
+										$end = new DateTime(iCalUtilityFunctions::_date2strdate($event->getProperty('DTEND')));
235
+										if ($event->getProperty('X-RECURRENCE')) {
236
+											$start = new DateTime($event->getProperty('X-CURRENT-DTSTART')[1]);
237
+											$end = new DateTime($event->getProperty('X-CURRENT-DTEND')[1]);
238
+										}
239
+										$start->setTimeZone(new DateTimeZone(LOCAL_TIMEZONE));
240
+										$end->setTimeZone(new DateTimeZone(LOCAL_TIMEZONE));
241
+
242
+										$calendarEvent = $api->post(
243
+											"/calendar_events",
244
+											[
245
+												'calendar_event[context_code]' => "{$canvasContext['context']}_{$canvasObject['id']}",
246
+												'calendar_event[title]' => preg_replace('%^([^\]]+)(\s*\[[^\]]+\]\s*)+$%', '\\1', strip_tags($event->getProperty('SUMMARY'))),
247
+												'calendar_event[description]' => \Michelf\Markdown::defaultTransform(str_replace('\n', "\n\n", $event->getProperty('DESCRIPTION', 1))),
248
+												'calendar_event[start_at]' => $start->format(CANVAS_TIMESTAMP_FORMAT),
249
+												'calendar_event[end_at]' => $end->format(CANVAS_TIMESTAMP_FORMAT),
250
+												'calendar_event[location_name]' => $event->getProperty('LOCATION')
251
+											]
252
+										);
253
+
254
+										$sql->query("
255 255
                                             INSERT INTO `events`
256 256
                                                 (
257 257
                                                     `calendar`,
@@ -266,105 +266,105 @@  discard block
 block discarded – undo
266 266
                                                     '" . getSyncTimestamp() . "'
267 267
                                                 )
268 268
                                         ");
269
-                                    }
270
-                                }
271
-                            }
272
-                        }
273
-                    }
274
-                }
275
-
276
-                /* clean out previously synced events that are no longer correct */
277
-                $deletedEventsResponse = $sql->query("
269
+									}
270
+								}
271
+							}
272
+						}
273
+					}
274
+				}
275
+
276
+				/* clean out previously synced events that are no longer correct */
277
+				$deletedEventsResponse = $sql->query("
278 278
                     SELECT * FROM `events`
279 279
                         WHERE
280 280
                             `calendar` = '{$calendarCache['id']}' AND
281 281
                             `synced` != '" . getSyncTimestamp() . "'
282 282
                 ");
283
-                while ($deletedEventCache = $deletedEventsResponse->fetch_assoc()) {
284
-                    try {
285
-                        $deletedEvent = $api->delete(
286
-                            "/calendar_events/{$deletedEventCache['calendar_event[id]']}",
287
-                            [
288
-                                'cancel_reason' => getSyncTimestamp(),
289
-                                'as_user_id' => ($canvasContext['context'] == 'user' ? $canvasObject['id'] : '') // TODO: this feels skeevy -- like the empty string will break
290
-                            ]
291
-                        );
292
-                    } catch (Pest_Unauthorized $e) {
293
-                        /* if the event has been deleted in Canvas, we'll get an error when
283
+				while ($deletedEventCache = $deletedEventsResponse->fetch_assoc()) {
284
+					try {
285
+						$deletedEvent = $api->delete(
286
+							"/calendar_events/{$deletedEventCache['calendar_event[id]']}",
287
+							[
288
+								'cancel_reason' => getSyncTimestamp(),
289
+								'as_user_id' => ($canvasContext['context'] == 'user' ? $canvasObject['id'] : '') // TODO: this feels skeevy -- like the empty string will break
290
+							]
291
+						);
292
+					} catch (Pest_Unauthorized $e) {
293
+						/* if the event has been deleted in Canvas, we'll get an error when
294 294
                            we try to delete it a second time. We still need to delete it from
295 295
                            our cache database, however */
296
-                        postMessage('Cache out-of-sync', "calendar_event[{$deletedEventCache['calendar_event[id]']}] no longer exists and will be purged from cache.", NotificationMessage::INFO);
297
-                    } catch (Pest_ClientError $e) {
298
-                        postMessage(
299
-                            'API Client Error',
300
-                            '<pre>' . print_r(array(
301
-                                'Status' => $PEST->lastStatus(),
302
-                                'Error' => $PEST->lastBody(),
303
-                                'Verb' => $verb,
304
-                                'URL' => $url,
305
-                                'Data' => $data
306
-                            ), false) . '</pre>',
307
-                            NotificationMessage::ERROR
308
-                        );
309
-                        if (php_sapi_name() != 'cli') {
310
-                            $smarty->display('page.tpl')
311
-                        };
312
-                        exit;
313
-                    }
314
-                    $sql->query("
296
+						postMessage('Cache out-of-sync', "calendar_event[{$deletedEventCache['calendar_event[id]']}] no longer exists and will be purged from cache.", NotificationMessage::INFO);
297
+					} catch (Pest_ClientError $e) {
298
+						postMessage(
299
+							'API Client Error',
300
+							'<pre>' . print_r(array(
301
+								'Status' => $PEST->lastStatus(),
302
+								'Error' => $PEST->lastBody(),
303
+								'Verb' => $verb,
304
+								'URL' => $url,
305
+								'Data' => $data
306
+							), false) . '</pre>',
307
+							NotificationMessage::ERROR
308
+						);
309
+						if (php_sapi_name() != 'cli') {
310
+							$smarty->display('page.tpl')
311
+						};
312
+						exit;
313
+					}
314
+					$sql->query("
315 315
                         DELETE FROM `events`
316 316
                             WHERE
317 317
                                 `id` = '{$deletedEventCache['id']}'
318 318
                     ");
319
-                }
319
+				}
320 320
 
321
-                /* if this was a scheduled import (i.e. a sync), update that schedule */
322
-                if (isset($_REQUEST['schedule'])) {
323
-                    $sql->query("
321
+				/* if this was a scheduled import (i.e. a sync), update that schedule */
322
+				if (isset($_REQUEST['schedule'])) {
323
+					$sql->query("
324 324
                         UPDATE `schedules`
325 325
                             SET
326 326
                                 `synced` = '" . getSyncTimestamp() . "'
327 327
                             WHERE
328 328
                                 `id` = '{$_REQUEST['schedule']}'
329 329
                     ");
330
-                }
331
-                /* are we setting up a regular synchronization? */
332
-                if (isset($_REQUEST['sync']) && $_REQUEST['sync'] != SCHEDULE_ONCE) {
330
+				}
331
+				/* are we setting up a regular synchronization? */
332
+				if (isset($_REQUEST['sync']) && $_REQUEST['sync'] != SCHEDULE_ONCE) {
333 333
 
334
-                    // FIXME:0 CRON SYNC SETUP GOES HERE issue:15 issue:13
334
+					// FIXME:0 CRON SYNC SETUP GOES HERE issue:15 issue:13
335 335
 
336
-                    /* add to the cache database schedule, replacing any schedules for this
336
+					/* add to the cache database schedule, replacing any schedules for this
337 337
                        calendar that are already there */
338
-                    $schedulesResponse = $sql->query("
338
+					$schedulesResponse = $sql->query("
339 339
                         SELECT *
340 340
                             FROM `schedules`
341 341
                             WHERE
342 342
                                 `calendar` = '{$calendarCache['id']}'
343 343
                     ");
344 344
 
345
-                    if ($schedule = $schedulesResponse->fetch_assoc()) {
345
+					if ($schedule = $schedulesResponse->fetch_assoc()) {
346 346
 
347
-                        /* only need to worry if the cached schedule is different from the
347
+						/* only need to worry if the cached schedule is different from the
348 348
                            new one we just set */
349
-                        if ($shellArguments[INDEX_SCHEDULE] != $schedule['schedule']) {
350
-                            /* was this the last schedule to require this trigger? */
351
-                            $schedulesResponse = $sql->query("
349
+						if ($shellArguments[INDEX_SCHEDULE] != $schedule['schedule']) {
350
+							/* was this the last schedule to require this trigger? */
351
+							$schedulesResponse = $sql->query("
352 352
                                 SELECT *
353 353
                                     FROM `schedules`
354 354
                                     WHERE
355 355
                                         `calendar` != '{$calendarCache['id']}' AND
356 356
                                         `schedule` == '{$schedule['schedule']}'
357 357
                             ");
358
-                            /* we're the last one, delete it from crontab */
359
-                            if ($schedulesResponse->num_rows == 0) {
360
-                                $crontabs = preg_replace("%^.*{$schedule['schedule']}.*" . PHP_EOL . '%', '', shell_exec('crontab -l'));
361
-                                $filename = md5(getSyncTimestamp()) . '.txt';
362
-                                file_put_contents("/tmp/$filename", $crontabs);
363
-                                shell_exec("crontab /tmp/$filename");
364
-                                postMessage('Unused schedule', "removed schedule '{$schedule['schedule']}' from crontab", NotificationMessage::INFO);
365
-                            }
366
-
367
-                            $sql->query("
358
+							/* we're the last one, delete it from crontab */
359
+							if ($schedulesResponse->num_rows == 0) {
360
+								$crontabs = preg_replace("%^.*{$schedule['schedule']}.*" . PHP_EOL . '%', '', shell_exec('crontab -l'));
361
+								$filename = md5(getSyncTimestamp()) . '.txt';
362
+								file_put_contents("/tmp/$filename", $crontabs);
363
+								shell_exec("crontab /tmp/$filename");
364
+								postMessage('Unused schedule', "removed schedule '{$schedule['schedule']}' from crontab", NotificationMessage::INFO);
365
+							}
366
+
367
+							$sql->query("
368 368
                                 UPDATE `schedules`
369 369
                                     SET
370 370
                                         `schedule` = '" . $shellArguments[INDEX_SCHEDULE] . "',
@@ -372,9 +372,9 @@  discard block
 block discarded – undo
372 372
                                     WHERE
373 373
                                         `calendar` = '{$calendarCache['id']}'
374 374
                             ");
375
-                        }
376
-                    } else {
377
-                        $sql->query("
375
+						}
376
+					} else {
377
+						$sql->query("
378 378
                             INSERT INTO `schedules`
379 379
                                 (
380 380
                                     `calendar`,
@@ -387,46 +387,46 @@  discard block
 block discarded – undo
387 387
                                     '" . getSyncTimestamp() . "'
388 388
                                 )
389 389
                         ");
390
-                    }
391
-                }
390
+					}
391
+				}
392 392
 
393
-                /* if we're ovewriting data (for example, if this is a recurring sync, we
393
+				/* if we're ovewriting data (for example, if this is a recurring sync, we
394 394
                    need to remove the events that were _not_ synced this in this round */
395
-                if (isset($_REQUEST['overwrite']) && $_REQUEST['overwrite'] == VALUE_OVERWRITE_CANVAS_CALENDAR) {
396
-                    // TODO: actually deal with this
397
-                }
398
-
399
-                // TODO: deal with messaging based on context
400
-
401
-                postMessage('Finished sync', getSyncTimestamp(), NotificationMessage::INFO);
402
-                exit;
403
-            } else {
404
-                postMessage(
405
-                    'Canvas Object  Not Found',
406
-                    'The object whose URL you submitted could not be found.<pre>' . print_r(array(
407
-                        'Canvas URL' => $_REQUEST['canvas_url'],
408
-                        'Canvas Context' => $canvasContext,
409
-                        'Canvas Object' => $canvasObject
410
-                    ), false) . '</pre>',
411
-                    NotificationMessage::ERROR
412
-                );
413
-            }
414
-        } else {
415
-            postMessage(
416
-                'ICS feed  Not Found',
417
-                'The calendar whose URL you submitted could not be found.<pre>' . $_REQUEST['cal'] . '</pre>',
418
-                NotificationMessage::ERROR
419
-            );
420
-        }
421
-    } else {
422
-        postMessage(
423
-            'Invalid Canvas URL',
424
-            'The Canvas URL you submitted could not be parsed.<pre>' . $_REQUEST['canvas_url'] . '</pre>',
425
-            NotificationMessage::ERROR
426
-        );
427
-        if (php_sapi_name() != 'cli') $smarty->display('page.tpl');
428
-        exit;
429
-    }
395
+				if (isset($_REQUEST['overwrite']) && $_REQUEST['overwrite'] == VALUE_OVERWRITE_CANVAS_CALENDAR) {
396
+					// TODO: actually deal with this
397
+				}
398
+
399
+				// TODO: deal with messaging based on context
400
+
401
+				postMessage('Finished sync', getSyncTimestamp(), NotificationMessage::INFO);
402
+				exit;
403
+			} else {
404
+				postMessage(
405
+					'Canvas Object  Not Found',
406
+					'The object whose URL you submitted could not be found.<pre>' . print_r(array(
407
+						'Canvas URL' => $_REQUEST['canvas_url'],
408
+						'Canvas Context' => $canvasContext,
409
+						'Canvas Object' => $canvasObject
410
+					), false) . '</pre>',
411
+					NotificationMessage::ERROR
412
+				);
413
+			}
414
+		} else {
415
+			postMessage(
416
+				'ICS feed  Not Found',
417
+				'The calendar whose URL you submitted could not be found.<pre>' . $_REQUEST['cal'] . '</pre>',
418
+				NotificationMessage::ERROR
419
+			);
420
+		}
421
+	} else {
422
+		postMessage(
423
+			'Invalid Canvas URL',
424
+			'The Canvas URL you submitted could not be parsed.<pre>' . $_REQUEST['canvas_url'] . '</pre>',
425
+			NotificationMessage::ERROR
426
+		);
427
+		if (php_sapi_name() != 'cli') $smarty->display('page.tpl');
428
+		exit;
429
+	}
430 430
 }
431 431
 
432 432
 ?>
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
     // TODO: it would probably be better to look up users by email address than URL
36 36
     /* get the context (user, course or group) for the canvas URL */
37 37
     $canvasContext = array();
38
-    if (preg_match('%(https?://)?(' . parse_url($metadata['CANVAS_INSTANCE_URL'], PHP_URL_HOST) . '/((about/(\d+))|(courses/(\d+)(/groups/(\d+))?)|(accounts/\d+/groups/(\d+))))%', $_REQUEST['canvas_url'], $matches)) {
38
+    if (preg_match('%(https?://)?('.parse_url($metadata['CANVAS_INSTANCE_URL'], PHP_URL_HOST).'/((about/(\d+))|(courses/(\d+)(/groups/(\d+))?)|(accounts/\d+/groups/(\d+))))%', $_REQUEST['canvas_url'], $matches)) {
39 39
         $canvasContext['canonical_url'] = "https://{$matches[2]}"; // https://stmarksschool.instructure.com/courses/953
40 40
 
41 41
         // course or account groups
@@ -106,14 +106,14 @@  discard block
 block discarded – undo
106 106
             if ($canvasObject = $api->get($canvasContext['verification_url'])) {
107 107
                 /* calculate the unique pairing ID of this ICS feed and canvas object */
108 108
                 $pairingHash = $toolbox->getPairingHash($_REQUEST['cal'], $canvasContext['canonical_url']);
109
-                $log = Log::singleton('file', __DIR__ . "/logs/$pairingHash.log");
109
+                $log = Log::singleton('file', __DIR__."/logs/$pairingHash.log");
110 110
                 postMessage('Sync started', getSyncTimestamp(), NotificationMessage::INFO);
111 111
 
112 112
                 /* tell users that it's started and to cool their jets */
113 113
                 if (php_sapi_name() != 'cli') {
114 114
                     $smarty->assign([
115 115
                         'content' => '<h3>Calendar Import Started</h3>
116
-                        <p>The calendar import that you requested has begun. You may leave this page at anytime. You can see the progress of the import by visiting <a target="_blank" href="' . $_SESSION[CANVAS_INSTANCE_URL] . "/calendar?include_contexts={$canvasContext['context']}_{$canvasObject['id']}\">this calendar</a> in Canvas.</p>"
116
+                        <p>The calendar import that you requested has begun. You may leave this page at anytime. You can see the progress of the import by visiting <a target="_blank" href="' . $_SESSION[CANVAS_INSTANCE_URL]."/calendar?include_contexts={$canvasContext['context']}_{$canvasObject['id']}\">this calendar</a> in Canvas.</p>"
117 117
                     ]);
118 118
                     $smarty->display('page.tpl');
119 119
                 }
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
                     $sql->query("
142 142
                         UPDATE `calendars`
143 143
                             SET
144
-                                `synced` = '" . getSyncTimestamp() . "'
144
+                                `synced` = '" . getSyncTimestamp()."'
145 145
                             WHERE
146 146
                                 `id` = '$pairingHash'
147 147
                     ");
@@ -160,13 +160,13 @@  discard block
 block discarded – undo
160 160
                             )
161 161
                             VALUES (
162 162
                                 '$pairingHash',
163
-                                '" . $sql->real_escape_string($ics->getProperty('X-WR-CALNAME')) . "',
163
+                                '".$sql->real_escape_string($ics->getProperty('X-WR-CALNAME'))."',
164 164
                                 '{$_REQUEST['cal']}',
165 165
                                 '{$canvasContext['canonical_url']}',
166
-                                '" . getSyncTimestamp() . "',
167
-                                '" . ($_REQUEST['enable_regexp_filter'] == VALUE_ENABLE_REGEXP_FILTER) . "',
168
-                                " . ($_REQUEST['enable_regexp_filter'] == VALUE_ENABLE_REGEXP_FILTER ? "'" . $sql->real_escape_string($_REQUEST['include_regexp']) . "'" : 'NULL') . ",
169
-                                " . ($_REQUEST['enable_regexp_filter'] == VALUE_ENABLE_REGEXP_FILTER ? "'" . $sql->real_escape_string($_REQUEST['exclude_regexp']) . "'" : 'NULL') . "
166
+                                '".getSyncTimestamp()."',
167
+                                '" . ($_REQUEST['enable_regexp_filter'] == VALUE_ENABLE_REGEXP_FILTER)."',
168
+                                " . ($_REQUEST['enable_regexp_filter'] == VALUE_ENABLE_REGEXP_FILTER ? "'".$sql->real_escape_string($_REQUEST['include_regexp'])."'" : 'NULL').",
169
+                                " . ($_REQUEST['enable_regexp_filter'] == VALUE_ENABLE_REGEXP_FILTER ? "'".$sql->real_escape_string($_REQUEST['exclude_regexp'])."'" : 'NULL')."
170 170
                             )
171 171
                     ");
172 172
                 }
@@ -186,10 +186,10 @@  discard block
 block discarded – undo
186 186
                 // TODO:0 the best window for syncing would be the term of the course in question, right? issue:12
187 187
                 // TODO:0 Arbitrarily selecting events in for a year on either side of today's date, probably a better system? issue:12
188 188
                 foreach ($ics->selectComponents(
189
-                    date('Y')-1, // startYear
189
+                    date('Y') - 1, // startYear
190 190
                     date('m'), // startMonth
191 191
                     date('d'), // startDay
192
-                    date('Y')+1, // endYEar
192
+                    date('Y') + 1, // endYEar
193 193
                     date('m'), // endMonth
194 194
                     date('d'), // endDay
195 195
                     'vevent', // cType
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
                                         $sql->query("
223 223
                                             UPDATE `events`
224 224
                                                 SET
225
-                                                    `synced` = '" . getSyncTimestamp() . "'
225
+                                                    `synced` = '" . getSyncTimestamp()."'
226 226
                                                 WHERE
227 227
                                                     `id` = '{$eventCache['id']}'
228 228
                                         ");
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
                                                     '{$calendarCache['id']}',
264 264
                                                     '{$calendarEvent['id']}',
265 265
                                                     '$eventHash',
266
-                                                    '" . getSyncTimestamp() . "'
266
+                                                    '".getSyncTimestamp()."'
267 267
                                                 )
268 268
                                         ");
269 269
                                     }
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
                     SELECT * FROM `events`
279 279
                         WHERE
280 280
                             `calendar` = '{$calendarCache['id']}' AND
281
-                            `synced` != '" . getSyncTimestamp() . "'
281
+                            `synced` != '".getSyncTimestamp()."'
282 282
                 ");
283 283
                 while ($deletedEventCache = $deletedEventsResponse->fetch_assoc()) {
284 284
                     try {
@@ -297,13 +297,13 @@  discard block
 block discarded – undo
297 297
                     } catch (Pest_ClientError $e) {
298 298
                         postMessage(
299 299
                             'API Client Error',
300
-                            '<pre>' . print_r(array(
300
+                            '<pre>'.print_r(array(
301 301
                                 'Status' => $PEST->lastStatus(),
302 302
                                 'Error' => $PEST->lastBody(),
303 303
                                 'Verb' => $verb,
304 304
                                 'URL' => $url,
305 305
                                 'Data' => $data
306
-                            ), false) . '</pre>',
306
+                            ), false).'</pre>',
307 307
                             NotificationMessage::ERROR
308 308
                         );
309 309
                         if (php_sapi_name() != 'cli') {
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
                     $sql->query("
324 324
                         UPDATE `schedules`
325 325
                             SET
326
-                                `synced` = '" . getSyncTimestamp() . "'
326
+                                `synced` = '" . getSyncTimestamp()."'
327 327
                             WHERE
328 328
                                 `id` = '{$_REQUEST['schedule']}'
329 329
                     ");
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
                             ");
358 358
                             /* we're the last one, delete it from crontab */
359 359
                             if ($schedulesResponse->num_rows == 0) {
360
-                                $crontabs = preg_replace("%^.*{$schedule['schedule']}.*" . PHP_EOL . '%', '', shell_exec('crontab -l'));
361
-                                $filename = md5(getSyncTimestamp()) . '.txt';
360
+                                $crontabs = preg_replace("%^.*{$schedule['schedule']}.*".PHP_EOL.'%', '', shell_exec('crontab -l'));
361
+                                $filename = md5(getSyncTimestamp()).'.txt';
362 362
                                 file_put_contents("/tmp/$filename", $crontabs);
363 363
                                 shell_exec("crontab /tmp/$filename");
364 364
                                 postMessage('Unused schedule', "removed schedule '{$schedule['schedule']}' from crontab", NotificationMessage::INFO);
@@ -367,8 +367,8 @@  discard block
 block discarded – undo
367 367
                             $sql->query("
368 368
                                 UPDATE `schedules`
369 369
                                     SET
370
-                                        `schedule` = '" . $shellArguments[INDEX_SCHEDULE] . "',
371
-                                        `synced` = '" . getSyncTimestamp() . "'
370
+                                        `schedule` = '" . $shellArguments[INDEX_SCHEDULE]."',
371
+                                        `synced` = '" . getSyncTimestamp()."'
372 372
                                     WHERE
373 373
                                         `calendar` = '{$calendarCache['id']}'
374 374
                             ");
@@ -383,8 +383,8 @@  discard block
 block discarded – undo
383 383
                                 )
384 384
                                 VALUES (
385 385
                                     '{$calendarCache['id']}',
386
-                                    '" . $shellArguments[INDEX_SCHEDULE] . "',
387
-                                    '" . getSyncTimestamp() . "'
386
+                                    '".$shellArguments[INDEX_SCHEDULE]."',
387
+                                    '" . getSyncTimestamp()."'
388 388
                                 )
389 389
                         ");
390 390
                     }
@@ -403,25 +403,25 @@  discard block
 block discarded – undo
403 403
             } else {
404 404
                 postMessage(
405 405
                     'Canvas Object  Not Found',
406
-                    'The object whose URL you submitted could not be found.<pre>' . print_r(array(
406
+                    'The object whose URL you submitted could not be found.<pre>'.print_r(array(
407 407
                         'Canvas URL' => $_REQUEST['canvas_url'],
408 408
                         'Canvas Context' => $canvasContext,
409 409
                         'Canvas Object' => $canvasObject
410
-                    ), false) . '</pre>',
410
+                    ), false).'</pre>',
411 411
                     NotificationMessage::ERROR
412 412
                 );
413 413
             }
414 414
         } else {
415 415
             postMessage(
416 416
                 'ICS feed  Not Found',
417
-                'The calendar whose URL you submitted could not be found.<pre>' . $_REQUEST['cal'] . '</pre>',
417
+                'The calendar whose URL you submitted could not be found.<pre>'.$_REQUEST['cal'].'</pre>',
418 418
                 NotificationMessage::ERROR
419 419
             );
420 420
         }
421 421
     } else {
422 422
         postMessage(
423 423
             'Invalid Canvas URL',
424
-            'The Canvas URL you submitted could not be parsed.<pre>' . $_REQUEST['canvas_url'] . '</pre>',
424
+            'The Canvas URL you submitted could not be parsed.<pre>'.$_REQUEST['canvas_url'].'</pre>',
425 425
             NotificationMessage::ERROR
426 426
         );
427 427
         if (php_sapi_name() != 'cli') $smarty->display('page.tpl');
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -424,7 +424,9 @@
 block discarded – undo
424 424
             'The Canvas URL you submitted could not be parsed.<pre>' . $_REQUEST['canvas_url'] . '</pre>',
425 425
             NotificationMessage::ERROR
426 426
         );
427
-        if (php_sapi_name() != 'cli') $smarty->display('page.tpl');
427
+        if (php_sapi_name() != 'cli') {
428
+        	$smarty->display('page.tpl');
429
+        }
428 430
         exit;
429 431
     }
430 432
 }
Please login to merge, or discard this patch.
purge.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -3,36 +3,36 @@
 block discarded – undo
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(
11
-        'calendar_events',
12
-        [
13
-            'type' => 'event',
14
-            'all_events' => true,
15
-            'context_codes[]' => preg_replace('|.*/courses/(\d+)/?.*|', "course_$1", $_REQUEST['course_url'])
16
-        ]
17
-    );
18
-    do {
19
-        foreach ($events as $event) {
20
-            $api->delete(
21
-                "calendar_events/{$event['id']}",
22
-                [
23
-                    'cancel_reason' => $metadata['APP_NAME'] . " course_url={$_REQUEST['course_url']}"
24
-                ]
25
-            );
26
-        }
27
-    } while ($events = $eventsApi->nextPage());
10
+	$events = $eventsApi->get(
11
+		'calendar_events',
12
+		[
13
+			'type' => 'event',
14
+			'all_events' => true,
15
+			'context_codes[]' => preg_replace('|.*/courses/(\d+)/?.*|', "course_$1", $_REQUEST['course_url'])
16
+		]
17
+	);
18
+	do {
19
+		foreach ($events as $event) {
20
+			$api->delete(
21
+				"calendar_events/{$event['id']}",
22
+				[
23
+					'cancel_reason' => $metadata['APP_NAME'] . " course_url={$_REQUEST['course_url']}"
24
+				]
25
+			);
26
+		}
27
+	} while ($events = $eventsApi->nextPage());
28 28
 
29
-    $smarty->assign([
30
-        'content' => 'Calendar purged.'
31
-    ]);
29
+	$smarty->assign([
30
+		'content' => 'Calendar purged.'
31
+	]);
32 32
 } else {
33
-    $smarty->assign([
34
-        '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>'
35
-    ]);
33
+	$smarty->assign([
34
+		'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>'
35
+	]);
36 36
 }
37 37
 
38 38
 $smarty->display();
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
             $api->delete(
21 21
                 "calendar_events/{$event['id']}",
22 22
                 [
23
-                    'cancel_reason' => $metadata['APP_NAME'] . " course_url={$_REQUEST['course_url']}"
23
+                    'cancel_reason' => $metadata['APP_NAME']." course_url={$_REQUEST['course_url']}"
24 24
                 ]
25 25
             );
26 26
         }
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
     ]);
32 32
 } else {
33 33
     $smarty->assign([
34
-        '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>'
34
+        '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>'
35 35
     ]);
36 36
 }
37 37
 
Please login to merge, or discard this patch.
sync.php 2 patches
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,13 +15,13 @@
 block discarded – undo
15 15
 ");
16 16
 
17 17
 while ($schedule = $schedulesResponse->fetch_assoc()) {
18
-    $calendarResponse = $sql->query("
18
+	$calendarResponse = $sql->query("
19 19
         SELECT *
20 20
             FROM `calendars`
21 21
             WHERE
22 22
                 `id` = '{$schedule['calendar']}'
23 23
     ");
24
-    if ($calendar = $calendarResponse->fetch_assoc()) {
25
-        echo shell_exec('php ' . __DIR__ . '/import.php ' . $calendar['ics_url'] . ' ' . $calendar['canvas_url'] . ' ' . $schedule['id']);
26
-    }
24
+	if ($calendar = $calendarResponse->fetch_assoc()) {
25
+		echo shell_exec('php ' . __DIR__ . '/import.php ' . $calendar['ics_url'] . ' ' . $calendar['canvas_url'] . ' ' . $schedule['id']);
26
+	}
27 27
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
     SELECT *
10 10
         FROM `schedules`
11 11
         WHERE
12
-            `schedule` = '" . $sql->real_escape_string($argv[1]) . "'
12
+            `schedule` = '" . $sql->real_escape_string($argv[1])."'
13 13
         ORDER BY
14 14
             `synced` ASC
15 15
 ");
@@ -22,6 +22,6 @@  discard block
 block discarded – undo
22 22
                 `id` = '{$schedule['calendar']}'
23 23
     ");
24 24
     if ($calendar = $calendarResponse->fetch_assoc()) {
25
-        echo shell_exec('php ' . __DIR__ . '/import.php ' . $calendar['ics_url'] . ' ' . $calendar['canvas_url'] . ' ' . $schedule['id']);
25
+        echo shell_exec('php '.__DIR__.'/import.php '.$calendar['ics_url'].' '.$calendar['canvas_url'].' '.$schedule['id']);
26 26
     }
27 27
 }
Please login to merge, or discard this patch.
src/SyncIntoCanvas/Filter.php 3 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 
32 32
     public function setEnabled($enabled)
33 33
     {
34
-        $this->enabled = (boolean) $enabled;
34
+        $this->enabled = (boolean)$enabled;
35 35
     }
36 36
 
37 37
     public function isEnabled()
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 
42 42
     public function setIncludeExpression($regex)
43 43
     {
44
-        $this->include = (string) $regex;
44
+        $this->include = (string)$regex;
45 45
     }
46 46
 
47 47
     public function getIncludeExpression()
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 
55 55
     public function setExcludeExpression($regex)
56 56
     {
57
-        $this->exclude = (string) $regex;
57
+        $this->exclude = (string)$regex;
58 58
     }
59 59
 
60 60
     public function getExcludeExpression()
@@ -74,12 +74,12 @@  discard block
 block discarded – undo
74 74
                (
75 75
                    ( // if filtering is on, and there's an include pattern test that pattern...
76 76
                        $this->getIncludeExpression() &&
77
-                       preg_match('%' . $this->getIncludeExpression() . '%', $event->getProperty('SUMMARY'))
77
+                       preg_match('%'.$this->getIncludeExpression().'%', $event->getProperty('SUMMARY'))
78 78
                    )
79 79
                ) &&
80 80
                !( // if there is an exclude pattern, make sure that this event is NOT excluded
81 81
                    $this->getExcludeExpression() &&
82
-                   preg_match('%' . $this->getExcludeExpression() . '%', $event->getProperty('SUMMARY'))
82
+                   preg_match('%'.$this->getExcludeExpression().'%', $event->getProperty('SUMMARY'))
83 83
                )
84 84
            )
85 85
         );
Please login to merge, or discard this patch.
Doc Comments   +9 added lines patch added patch discarded remove patch
@@ -34,6 +34,9 @@  discard block
 block discarded – undo
34 34
         $this->setExcludeExpression($exclude);
35 35
     }
36 36
 
37
+    /**
38
+     * @param boolean $enabled
39
+     */
37 40
     public function setEnabled($enabled)
38 41
     {
39 42
         $this->enabled = (boolean) $enabled;
@@ -44,6 +47,9 @@  discard block
 block discarded – undo
44 47
         return $enabled;
45 48
     }
46 49
 
50
+    /**
51
+     * @param string|null $regex
52
+     */
47 53
     public function setIncludeExpression($regex)
48 54
     {
49 55
         $this->include = (string) $regex;
@@ -57,6 +63,9 @@  discard block
 block discarded – undo
57 63
         return $this->include;
58 64
     }
59 65
 
66
+    /**
67
+     * @param string|null $regex
68
+     */
60 69
     public function setExcludeExpression($regex)
61 70
     {
62 71
         $this->exclude = (string) $regex;
Please login to merge, or discard this patch.
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -4,89 +4,89 @@
 block discarded – undo
4 4
 
5 5
 class Filter
6 6
 {
7
-    /**
8
-     * Whether or not this filter is enabled
9
-     * @var boolean
10
-     */
11
-    protected $enabled = false;
7
+	/**
8
+	 * Whether or not this filter is enabled
9
+	 * @var boolean
10
+	 */
11
+	protected $enabled = false;
12 12
 
13
-    /**
14
-     * Regex to include (applied first)
15
-     * @var string
16
-     */
17
-    protected $include;
13
+	/**
14
+	 * Regex to include (applied first)
15
+	 * @var string
16
+	 */
17
+	protected $include;
18 18
 
19
-    /**
20
-     * Regex to exclude (applied second)
21
-     * @var string
22
-     */
23
-    protected $exclude;
19
+	/**
20
+	 * Regex to exclude (applied second)
21
+	 * @var string
22
+	 */
23
+	protected $exclude;
24 24
 
25
-    /**
26
-     * @param boolean $enabled
27
-     * @param string|null $include
28
-     * @param string|null $exclude
29
-     */
30
-    public function __construct($enabled, $include, $exclude)
31
-    {
32
-        $this->setEnabled($enabled);
33
-        $this->setIncludeExpression($include);
34
-        $this->setExcludeExpression($exclude);
35
-    }
25
+	/**
26
+	 * @param boolean $enabled
27
+	 * @param string|null $include
28
+	 * @param string|null $exclude
29
+	 */
30
+	public function __construct($enabled, $include, $exclude)
31
+	{
32
+		$this->setEnabled($enabled);
33
+		$this->setIncludeExpression($include);
34
+		$this->setExcludeExpression($exclude);
35
+	}
36 36
 
37
-    public function setEnabled($enabled)
38
-    {
39
-        $this->enabled = (boolean) $enabled;
40
-    }
37
+	public function setEnabled($enabled)
38
+	{
39
+		$this->enabled = (boolean) $enabled;
40
+	}
41 41
 
42
-    public function isEnabled()
43
-    {
44
-        return $enabled;
45
-    }
42
+	public function isEnabled()
43
+	{
44
+		return $enabled;
45
+	}
46 46
 
47
-    public function setIncludeExpression($regex)
48
-    {
49
-        $this->include = (string) $regex;
50
-    }
47
+	public function setIncludeExpression($regex)
48
+	{
49
+		$this->include = (string) $regex;
50
+	}
51 51
 
52
-    public function getIncludeExpression()
53
-    {
54
-        if (empty($this->include)) {
55
-            return false;
56
-        }
57
-        return $this->include;
58
-    }
52
+	public function getIncludeExpression()
53
+	{
54
+		if (empty($this->include)) {
55
+			return false;
56
+		}
57
+		return $this->include;
58
+	}
59 59
 
60
-    public function setExcludeExpression($regex)
61
-    {
62
-        $this->exclude = (string) $regex;
63
-    }
60
+	public function setExcludeExpression($regex)
61
+	{
62
+		$this->exclude = (string) $regex;
63
+	}
64 64
 
65
-    public function getExcludeExpression()
66
-    {
67
-        if (empty($this->exclude)) {
68
-            return false;
69
-        }
70
-        return $this->exclude;
71
-    }
65
+	public function getExcludeExpression()
66
+	{
67
+		if (empty($this->exclude)) {
68
+			return false;
69
+		}
70
+		return $this->exclude;
71
+	}
72 72
 
73
-    public function filter(Event $event)
74
-    {
75
-        return (
76
-            // include this event if filtering is off...
77
-            $this->isEnabled() == false ||
78
-            (
79
-               (
80
-                   ( // if filtering is on, and there's an include pattern test that pattern...
81
-                       $this->getIncludeExpression() &&
82
-                       preg_match('%' . $this->getIncludeExpression() . '%', $event->getProperty('SUMMARY'))
83
-                   )
84
-               ) &&
85
-               !( // if there is an exclude pattern, make sure that this event is NOT excluded
86
-                   $this->getExcludeExpression() &&
87
-                   preg_match('%' . $this->getExcludeExpression() . '%', $event->getProperty('SUMMARY'))
88
-               )
89
-           )
90
-        );
91
-    }
73
+	public function filter(Event $event)
74
+	{
75
+		return (
76
+			// include this event if filtering is off...
77
+			$this->isEnabled() == false ||
78
+			(
79
+			   (
80
+				   ( // if filtering is on, and there's an include pattern test that pattern...
81
+					   $this->getIncludeExpression() &&
82
+					   preg_match('%' . $this->getIncludeExpression() . '%', $event->getProperty('SUMMARY'))
83
+				   )
84
+			   ) &&
85
+			   !( // if there is an exclude pattern, make sure that this event is NOT excluded
86
+				   $this->getExcludeExpression() &&
87
+				   preg_match('%' . $this->getExcludeExpression() . '%', $event->getProperty('SUMMARY'))
88
+			   )
89
+		   )
90
+		);
91
+	}
92 92
 }
Please login to merge, or discard this patch.
src/SyncIntoCanvas/CanvasContext.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
 
7 7
 class CanvasContext extends Enum
8 8
 {
9
-    const COURSE = 'course';
10
-    const USER = 'user';
11
-    const GROUP = 'group';
9
+	const COURSE = 'course';
10
+	const USER = 'user';
11
+	const GROUP = 'group';
12 12
 }
Please login to merge, or discard this patch.