Completed
Branch master (c3ca5f)
by Seth
04:51
created
include/mysql.inc.php 1 patch
Spacing   +4 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-require_once(__DIR__ . '/../config.inc.php');
4
-require_once(APP_PATH . '/include/debug.inc.php');
5
-require_once(APP_PATH . '/include/page-generator.inc.php');
3
+require_once(__DIR__.'/../config.inc.php');
4
+require_once(APP_PATH.'/include/debug.inc.php');
5
+require_once(APP_PATH.'/include/page-generator.inc.php');
6 6
 
7 7
 $MYSQL = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE);
8 8
 function mysqlQuery($query) {
@@ -25,8 +25,7 @@  discard block
 block discarded – undo
25 25
 			'Query' => $query,
26 26
 			'Response' => (
27 27
 				$response ?
28
-					'True' :
29
-					mysqlError()
28
+					'True' : mysqlError()
30 29
 			)
31 30
 		),
32 31
 		true,
Please login to merge, or discard this patch.
import.php 2 patches
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -9,12 +9,12 @@  discard block
 block discarded – undo
9 9
 /* REQUIRES crontab
10 10
    http://en.wikipedia.org/wiki/Cron */
11 11
 
12
-require_once(__DIR__ . '/.ignore.calendar-ics-authentication.inc.php');
13
-require_once(__DIR__ . '/config.inc.php');
12
+require_once(__DIR__.'/.ignore.calendar-ics-authentication.inc.php');
13
+require_once(__DIR__.'/config.inc.php');
14 14
 
15
-require_once(APP_PATH . '/include/page-generator.inc.php');
16
-require_once(APP_PATH . '/include/canvas-api.inc.php');
17
-require_once(APP_PATH . '/include/mysql.inc.php');
15
+require_once(APP_PATH.'/include/page-generator.inc.php');
16
+require_once(APP_PATH.'/include/canvas-api.inc.php');
17
+require_once(APP_PATH.'/include/mysql.inc.php');
18 18
 
19 19
 define('TOOL_NAME_ABBREVIATION', 'ICS Import');
20 20
 
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 define('WARNING_REGEXP_FILTER', '<em>Note:</em> The regular expression match is applied to the <em>title</em> of an event <em>only</em>, and the event must both match the include regular expression <em>and</em> not match the exclude regular expression to be included. Note also that the regular expressions are <em>case-sensitive</em>.');
29 29
 
30
-require_once(__DIR__ . '/common.inc.php');
30
+require_once(__DIR__.'/common.inc.php');
31 31
 
32 32
 if (isset($argc)) {
33 33
 	$_REQUEST['cal'] = urldecode($argv[1]);
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	// TODO: it would probably be better to look up users by email address than URL
53 53
 	/* get the context (user, course or group) for the canvas URL */
54 54
 	$canvasContext = array();
55
-	if (preg_match('%(https?://)?(' . parse_url(CANVAS_API_URL, PHP_URL_HOST) . '/((about/(\d+))|(courses/(\d+)(/groups/(\d+))?)|(accounts/\d+/groups/(\d+))))%', $_REQUEST['canvas_url'], $matches)) {
55
+	if (preg_match('%(https?://)?('.parse_url(CANVAS_API_URL, PHP_URL_HOST).'/((about/(\d+))|(courses/(\d+)(/groups/(\d+))?)|(accounts/\d+/groups/(\d+))))%', $_REQUEST['canvas_url'], $matches)) {
56 56
 		$canvasContext['canonical_url'] = "https://{$matches[2]}"; // https://stmarksschool.instructure.com/courses/953
57 57
 		
58 58
 		// course or account groups
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 		$event['event_text'] = preg_replace('%^([^\]]+)(\s*\[[^\]]+\]\s*)+$%', '\\1', $event['event_text']);	
113 113
 	
114 114
 		/* replace newlines with <br /> to maintain formatting */
115
-		$event['description'] = str_replace( PHP_EOL , '<br />' . PHP_EOL, $event['description']);
115
+		$event['description'] = str_replace(PHP_EOL, '<br />'.PHP_EOL, $event['description']);
116 116
 	
117 117
 		return $event;
118 118
 	}
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 	
134 134
 	if ($canvasContext = getCanvasContext($_REQUEST['canvas_url'])) {
135 135
 		/* check ICS feed to be sure it exists */
136
-		if(urlExists($_REQUEST['cal'])) {
136
+		if (urlExists($_REQUEST['cal'])) {
137 137
 			/* look up the canvas object -- mostly to make sure that it exists! */
138 138
 			if ($canvasObject = callCanvasApi(CANVAS_API_GET, $canvasContext['verification_url'])) {
139 139
 			
@@ -145,14 +145,14 @@  discard block
 block discarded – undo
145 145
 				/* tell users that it's started and to cool their jets */
146 146
 				displayPage('
147 147
 					<h3>Calendar Import Started</h3>
148
-					<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="https://' . parse_url(CANVAS_API_URL, PHP_URL_HOST) . "/calendar?include_contexts={$canvasContext['context']}_{$canvasObject['id']}\">this calendar</a> in Canvas.</p>"
148
+					<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="https://' . parse_url(CANVAS_API_URL, PHP_URL_HOST)."/calendar?include_contexts={$canvasContext['context']}_{$canvasObject['id']}\">this calendar</a> in Canvas.</p>"
149 149
 				);
150 150
 				
151 151
 				/* use phpicalendar to parse the ICS feed into $master_array */
152 152
 				define('BASE', './phpicalendar/');
153
-				require_once(BASE . 'functions/date_functions.php');
154
-				require_once(BASE . 'functions/init.inc.php');
155
-				require_once(BASE . 'functions/ical_parser.php');
153
+				require_once(BASE.'functions/date_functions.php');
154
+				require_once(BASE.'functions/init.inc.php');
155
+				require_once(BASE.'functions/ical_parser.php');
156 156
 				displayError(
157 157
 					$master_array,
158 158
 					false, null, null,
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 					mysqlQuery("
174 174
 						UPDATE `calendars`
175 175
 							SET
176
-								`synced` = '" . getSyncTimestamp() . "'
176
+								`synced` = '" . getSyncTimestamp()."'
177 177
 							WHERE
178 178
 								`id` = '$pairingHash'
179 179
 					");
@@ -192,13 +192,13 @@  discard block
 block discarded – undo
192 192
 							)
193 193
 							VALUES (
194 194
 								'$pairingHash',
195
-								'" . addslashes($master_array['calendar_name']) . "',
195
+								'".addslashes($master_array['calendar_name'])."',
196 196
 								'{$_REQUEST['cal']}',
197 197
 								'{$canvasContext['canonical_url']}',
198
-								'" . getSyncTimestamp() . "',
199
-								'" . ($_REQUEST['enable_regexp_filter'] == VALUE_ENABLE_REGEXP_FILTER) . "',
200
-								" . ($_REQUEST['enable_regexp_filter'] == VALUE_ENABLE_REGEXP_FILTER ? "'" . addslashes($_REQUEST['include_regexp']) . "'" : 'NULL') . ",
201
-								" . ($_REQUEST['enable_regexp_filter'] == VALUE_ENABLE_REGEXP_FILTER ? "'" . addslashes($_REQUEST['exclude_regexp']) . "'" : 'NULL') . "
198
+								'".getSyncTimestamp()."',
199
+								'" . ($_REQUEST['enable_regexp_filter'] == VALUE_ENABLE_REGEXP_FILTER)."',
200
+								" . ($_REQUEST['enable_regexp_filter'] == VALUE_ENABLE_REGEXP_FILTER ? "'".addslashes($_REQUEST['include_regexp'])."'" : 'NULL').",
201
+								" . ($_REQUEST['enable_regexp_filter'] == VALUE_ENABLE_REGEXP_FILTER ? "'".addslashes($_REQUEST['exclude_regexp'])."'" : 'NULL')."
202 202
 							)
203 203
 					");
204 204
 				}
@@ -215,10 +215,10 @@  discard block
 block discarded – undo
215 215
 				/* walk through $master_array and update the Canvas calendar to match the
216 216
 				   ICS feed, caching changes in the database */
217 217
 				// 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...)
218
-				foreach($master_array as $date => $times) {
218
+				foreach ($master_array as $date => $times) {
219 219
 					if (date_create_from_format('Ymd', $date)) {
220
-						foreach($times as $time => $uids) {
221
-							foreach($uids as $uid => $event) {
220
+						foreach ($times as $time => $uids) {
221
+							foreach ($uids as $uid => $event) {
222 222
 								/* urldecode all of the fields of the event, for easier processing! */
223 223
 								foreach ($event as $key => $value) {
224 224
 									$event[$key] = urldecode($value);
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 										mysqlQuery("
252 252
 											UPDATE `events`
253 253
 												SET
254
-													`synced` = '" . getSyncTimestamp() . "'
254
+													`synced` = '" . getSyncTimestamp()."'
255 255
 												WHERE
256 256
 													`id` = '{$eventCache['id']}'
257 257
 										");
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 													'{$calendarCache['id']}',
295 295
 													'{$calendarEvent['id']}',
296 296
 													'$eventHash',
297
-													'" . getSyncTimestamp() . "'
297
+													'".getSyncTimestamp()."'
298 298
 												)
299 299
 										");
300 300
 									}
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 					SELECT * FROM `events`
310 310
 						WHERE
311 311
 							`calendar` = '{$calendarCache['id']}' AND
312
-							`synced` != '" . getSyncTimestamp() . "'
312
+							`synced` != '".getSyncTimestamp()."'
313 313
 				");
314 314
 				while ($deletedEventCache = $deletedEventsResponse->fetch_assoc()) {
315 315
 					try {
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 					mysqlQuery("
354 354
 						UPDATE `schedules`
355 355
 							SET
356
-								`synced` = '" . getSyncTimestamp() . "'
356
+								`synced` = '" . getSyncTimestamp()."'
357 357
 							WHERE
358 358
 								`id` = '{$_REQUEST['schedule']}'
359 359
 					");
@@ -361,9 +361,9 @@  discard block
 block discarded – undo
361 361
 				
362 362
 				/* are we setting up a regular synchronization? */
363 363
 				if (isset($_REQUEST['sync']) && $_REQUEST['sync'] != SCHEDULE_ONCE) {
364
-					$shellArguments[INDEX_COMMAND] = dirname(__FILE__) . '/sync.sh';
364
+					$shellArguments[INDEX_COMMAND] = dirname(__FILE__).'/sync.sh';
365 365
 					$shellArguments[INDEX_SCHEDULE] = $_REQUEST['sync'];
366
-					$shellArguments[INDEX_WEB_PATH] = 'http://localhost' . dirname($_SERVER['PHP_SELF']);
366
+					$shellArguments[INDEX_WEB_PATH] = 'http://localhost'.dirname($_SERVER['PHP_SELF']);
367 367
 					$crontab = null;
368 368
 					switch ($_REQUEST['sync']) {
369 369
 						case SCHEDULE_WEEKLY: {
@@ -379,22 +379,22 @@  discard block
 block discarded – undo
379 379
 							break;
380 380
 						}
381 381
 						case SCHEDULE_CUSTOM: {
382
-							$shellArguments[INDEX_SCHEDULE] = md5($_REQUEST['crontab'] . getSyncTimestamp());
382
+							$shellArguments[INDEX_SCHEDULE] = md5($_REQUEST['crontab'].getSyncTimestamp());
383 383
 							$crontab = trim($_REQUEST['crontab']);
384 384
 						}
385 385
 					}
386 386
 					
387 387
 					/* schedule crontab trigger, if it doesn't already exist */
388
-					$crontab .= ' ' . implode(' ', $shellArguments);
388
+					$crontab .= ' '.implode(' ', $shellArguments);
389 389
 					
390 390
 					/* thank you http://stackoverflow.com/a/4421284 ! */
391 391
 					$crontabs = shell_exec('crontab -l');
392 392
 					/* check to see if this sync is already scheduled */
393 393
 					if (strpos($crontabs, $crontab) === false) {
394
-						$filename = md5(getSyncTimestamp()) . '.txt';
395
-						file_put_contents("/tmp/$filename", $crontabs . $crontab . PHP_EOL);
394
+						$filename = md5(getSyncTimestamp()).'.txt';
395
+						file_put_contents("/tmp/$filename", $crontabs.$crontab.PHP_EOL);
396 396
 						shell_exec("crontab /tmp/$filename");
397
-						debugFlag("added new schedule '" . $shellArguments[INDEX_SCHEDULE] . "' to crontab");
397
+						debugFlag("added new schedule '".$shellArguments[INDEX_SCHEDULE]."' to crontab");
398 398
 					}
399 399
 					
400 400
 					/* try to make sure that we have execute access to sync.sh */
@@ -424,8 +424,8 @@  discard block
 block discarded – undo
424 424
 							");
425 425
 							/* we're the last one, delete it from crontab */
426 426
 							if ($schedulesResponse->num_rows == 0) {
427
-								$crontabs = preg_replace("%^.*{$schedule['schedule']}.*" . PHP_EOL . '%', '', shell_exec('crontab -l'));
428
-								$filename = md5(getSyncTimestamp()) . '.txt';
427
+								$crontabs = preg_replace("%^.*{$schedule['schedule']}.*".PHP_EOL.'%', '', shell_exec('crontab -l'));
428
+								$filename = md5(getSyncTimestamp()).'.txt';
429 429
 								file_put_contents("/tmp/$filename", $crontabs);
430 430
 								shell_exec("crontab /tmp/$filename");
431 431
 								debugFlag("removed unused schedule '{$schedule['schedule']}' from crontab");
@@ -434,8 +434,8 @@  discard block
 block discarded – undo
434 434
 							mysqlQuery("
435 435
 								UPDATE `schedules`
436 436
 									SET
437
-										`schedule` = '" . $shellArguments[INDEX_SCHEDULE] . "',
438
-										`synced` = '" . getSyncTimestamp() . "'
437
+										`schedule` = '" . $shellArguments[INDEX_SCHEDULE]."',
438
+										`synced` = '" . getSyncTimestamp()."'
439 439
 									WHERE
440 440
 										`calendar` = '{$calendarCache['id']}'
441 441
 							");
@@ -450,8 +450,8 @@  discard block
 block discarded – undo
450 450
 								)
451 451
 								VALUES (
452 452
 									'{$calendarCache['id']}',
453
-									'" . $shellArguments[INDEX_SCHEDULE] . "',
454
-									'" . getSyncTimestamp() . "'
453
+									'".$shellArguments[INDEX_SCHEDULE]."',
454
+									'" . getSyncTimestamp()."'
455 455
 								)
456 456
 						");
457 457
 					}
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
 
537 537
 var crontabSection = '<label for=\"crontab\">Custom Sync Schedule <span class=\"comment\"><em>Warning:</em> Not for the faint of heart! Enter a valid crontab time specification. For more information, <a target=\"_blank\" href=\"http://www.linuxweblog.com/crotab-tutorial\">refer to this tutorial.</a></span></label><input id=\"crontab\" name=\"crontab\" type=\"text\" class=\"code\" value=\"0 0 * * *\" />';
538 538
 
539
-var tagFilterSection = '<label for=\"include_regexp\">Regular expression to include <span class=\"comment\">A regular expression to include in the import (e.g. <code>.*</code>). " . WARNING_REGEXP_FILTER . "</span></label><input id=\"include_regexp\" name=\"include_regexp\" class=\"code\" type=\"text\" value=\".*\" /><label for=\"exclude_regexp\">Regular expression to exclude <span class=\"comment\">A regular expression to exclude from the import (e.g. <code>((\\[PAR\\])|(\\[FAC\\]))</code>). " . WARNING_REGEXP_FILTER . "</span></label><input id=\"exclude_regexp\" name=\"exclude_regexp\" class=\"code\" type=\"text\" />';
539
+var tagFilterSection = '<label for=\"include_regexp\">Regular expression to include <span class=\"comment\">A regular expression to include in the import (e.g. <code>.*</code>). " . WARNING_REGEXP_FILTER."</span></label><input id=\"include_regexp\" name=\"include_regexp\" class=\"code\" type=\"text\" value=\".*\" /><label for=\"exclude_regexp\">Regular expression to exclude <span class=\"comment\">A regular expression to exclude from the import (e.g. <code>((\\[PAR\\])|(\\[FAC\\]))</code>). ".WARNING_REGEXP_FILTER."</span></label><input id=\"exclude_regexp\" name=\"exclude_regexp\" class=\"code\" type=\"text\" />';
540 540
 
541 541
 function toggleVisibility(target, visibleTrigger, innerHTML) {
542 542
 	var targetElement = document.getElementById(target);
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 	}
550 550
 }
551 551
 " . '//--></script>
552
-<form enctype="multipart/form-data" action="' . $_SERVER['PHP_SELF'] . '" method="get">
552
+<form enctype="multipart/form-data" action="' . $_SERVER['PHP_SELF'].'" method="get">
553 553
 	<table>
554 554
 		<tr valign="middle">
555 555
 			<td class="calendarUrl">
@@ -568,29 +568,29 @@  discard block
 block discarded – undo
568 568
 			<td colspan="3">
569 569
 				<dl>
570 570
 					<dt>
571
-						<label for="overwrite"><input id="overwrite" name="overwrite" type="checkbox" value="' . VALUE_OVERWRITE_CANVAS_CALENDAR . '" unchecked disabled /> Replace existing calendar information <span class="comment">Checking this box will <em>delete</em> all of your current Canvas calendar information for this user/group/course.</span></label>
571
+						<label for="overwrite"><input id="overwrite" name="overwrite" type="checkbox" value="' . VALUE_OVERWRITE_CANVAS_CALENDAR.'" unchecked disabled /> Replace existing calendar information <span class="comment">Checking this box will <em>delete</em> all of your current Canvas calendar information for this user/group/course.</span></label>
572 572
 					</dt>
573 573
 					<dt>
574
-						<label for="enable_regexp_filter"><input id="enable_regexp_filter" name="enable_regexp_filter" type="checkbox" value="' . VALUE_ENABLE_REGEXP_FILTER . '" onChange="toggleVisibility(\'tag-filter-section\', this.checked, tagFilterSection);" />Filter event by regular expression <span class="comment">Filter calendar events with a regular expression on their title (e.g. <code>.* Classes</code>).</span></label>
574
+						<label for="enable_regexp_filter"><input id="enable_regexp_filter" name="enable_regexp_filter" type="checkbox" value="' . VALUE_ENABLE_REGEXP_FILTER.'" onChange="toggleVisibility(\'tag-filter-section\', this.checked, tagFilterSection);" />Filter event by regular expression <span class="comment">Filter calendar events with a regular expression on their title (e.g. <code>.* Classes</code>).</span></label>
575 575
 					</dt>
576 576
 					<dd>
577 577
 						<div id="tag-filter-section" onLoad="toggleVisibility(this.id, document.getElementById(\'enable_regexp_filter\').checked, tagFilterSection);"></div>
578 578
 					</dd>
579 579
 				<dl>
580 580
 					<dt>
581
-						<label for="schedule">Schedule automatic updates from this feed to this course <span class="comment">' . WARNING_SYNC . '</span></label>
582
-						<select id="schedule" name="sync" onChange="toggleVisibility(\'crontab-section\', this.value == \'' . SCHEDULE_CUSTOM . '\', crontabSection);">
583
-							<option value="' . SCHEDULE_ONCE . '">One-time import only</option>
581
+						<label for="schedule">Schedule automatic updates from this feed to this course <span class="comment">' . WARNING_SYNC.'</span></label>
582
+						<select id="schedule" name="sync" onChange="toggleVisibility(\'crontab-section\', this.value == \'' . SCHEDULE_CUSTOM.'\', crontabSection);">
583
+							<option value="' . SCHEDULE_ONCE.'">One-time import only</option>
584 584
 							<optgroup label="Recurring">
585
-								<option value="' . SCHEDULE_WEEKLY . '">Weekly (Saturday at midnight)</option>
586
-								<option value="' . SCHEDULE_DAILY . '">Daily (at midnight)</option>
587
-								<option value="' . SCHEDULE_HOURLY . '">Hourly (at the top of the hour)</option>
588
-								<option value="' . SCHEDULE_CUSTOM . '">Custom (define your own schedule)</option>
585
+								<option value="' . SCHEDULE_WEEKLY.'">Weekly (Saturday at midnight)</option>
586
+								<option value="' . SCHEDULE_DAILY.'">Daily (at midnight)</option>
587
+								<option value="' . SCHEDULE_HOURLY.'">Hourly (at the top of the hour)</option>
588
+								<option value="' . SCHEDULE_CUSTOM.'">Custom (define your own schedule)</option>
589 589
 							</optgroup>
590 590
 						</select>
591 591
 					</dt>
592 592
 					<dd>
593
-						<div id="crontab-section" onLoad="toggleVisibility(this.id, document.getElementById(\'schedule\').value == \'' . SCHEDULE_CUSTOM . '\', crontabSection);"></div>
593
+						<div id="crontab-section" onLoad="toggleVisibility(this.id, document.getElementById(\'schedule\').value == \'' . SCHEDULE_CUSTOM.'\', crontabSection);"></div>
594 594
 					</dd>
595 595
 				</dl>
596 596
 			</td>
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -246,7 +246,9 @@
 block discarded – undo
246 246
 									/* if we already have the event cached in its current form, just update
247 247
 									   the timestamp */
248 248
 									$eventCache = $eventCacheResponse->fetch_assoc();
249
-									if (DEBUGGING & DEBUGGING_MYSQL) displayError($eventCache);
249
+									if (DEBUGGING & DEBUGGING_MYSQL) {
250
+										displayError($eventCache);
251
+									}
250 252
 									if ($eventCache) {
251 253
 										mysqlQuery("
252 254
 											UPDATE `events`
Please login to merge, or discard this patch.
common.inc.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -44,14 +44,14 @@  discard block
 block discarded – undo
44 44
  * Canvas calendar
45 45
  **/
46 46
 function getPairingHash($icsUrl, $canvasContext) {
47
-	return md5($icsUrl . $canvasContext . CANVAS_API_URL);
47
+	return md5($icsUrl.$canvasContext.CANVAS_API_URL);
48 48
 }
49 49
 
50 50
 /**
51 51
  * Generate a hash of this version of an event to cache in the database
52 52
  **/
53 53
 function getEventHash($date, $time, $uid, $event) {
54
-	return md5($date . $time . $uid . serialize($event));
54
+	return md5($date.$time.$uid.serialize($event));
55 55
 }
56 56
 
57 57
 /**
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		return $SYNC_TIMESTAMP;
65 65
 	} else {
66 66
 		$timestamp = new DateTime();
67
-		$SYNC_TIMESTAMP = $timestamp->format(SYNC_TIMESTAMP_FORMAT) . SEPARATOR . md5($_SERVER['REMOTE_ADDR'] . time());
67
+		$SYNC_TIMESTAMP = $timestamp->format(SYNC_TIMESTAMP_FORMAT).SEPARATOR.md5($_SERVER['REMOTE_ADDR'].time());
68 68
 		return $SYNC_TIMESTAMP;
69 69
 	}
70 70
 }
Please login to merge, or discard this patch.