function filterEvent($content, $action) { $last = 0; while (strpos($content, "PARTSTAT:{$action}", $last + 1) !== false) { $pos = strpos($content, "PARTSTAT:{$action}", $last + 1); $startPos = strrpos($content, "BEGIN:VEVENT", $pos - strlen($content)); $endPos = strpos($content, "END:VEVENT", $pos) + strlen("END:VEVENT") + 2; $content = substr_replace($content, '', $startPos, $endPos - $startPos); $last = $startPos; } return $content; } if (isset($_GET["calendar"])) { $fbCal = urldecode($_GET["calendar"]); if (strpos($fbCal, 'webcal') === 0) { $fbCal = substr_replace($fbCal, "http", 0, strlen('webcal')); } if (strpos($fbCal, 'http://' !== 0)) { http_response_code(400); die("Not a url"); } $content = @file_get_contents($fbCal); if ($content === false) { http_response_code(400); die("Couldn't fetch calendar"); } $content = filterEvent($content, STATUS_UNDECIDED); header('Content-Type: text/calendar; charset=utf-8'); header('Content-Disposition: attachment;filename=calendar.ics'); die($content); }
} } $result = $conn->query($sql); while ($r = $result->fetch_assoc()) { $rows[] = array('data' => $r); } } $conn->close(); return $rows; } if (isset($_GET["action"])) { switch ($_GET["action"]) { case "search": $rows = searchEvent($_GET["criteria"]); break; case "sort": $rows = sortEvent($_GET["criteria"], $_GET["order"]); break; case "filter": $rows = filterEvent($_GET["year"], $_GET["month"], $_GET["target"], $_GET["location"]); break; case "calendar": $rows = getCalendar($_GET["year"], $_GET["month"]); break; } exit(json_encode($rows)); } else { $rows = putCSV($_FILES['csv']['tmp_name']); header("Location: " . $_SERVER['HTTP_REFERER']); exit; }
$calendarCache = $calendarCacheResponse->fetch_assoc(); /* walk through $master_array and update the Canvas calendar to match the ICS feed, caching changes in the database */ // 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...) foreach ($master_array as $date => $times) { if (date_create_from_format('Ymd', $date)) { foreach ($times as $time => $uids) { foreach ($uids as $uid => $event) { /* urldecode all of the fields of the event, for easier processing! */ foreach ($event as $key => $value) { $event[$key] = urldecode($value); } /* does this event already exist in Canvas? */ $eventHash = getEventHash($date, $time, $uid, $event); /* filter event -- clean up formatting and check for regexp filtering */ $event = filterEvent($event, $calendarCache); /* if the event should be included... */ if ($event) { /* have we cached this event already? */ $eventCacheResponse = mysqlQuery("\n\t\t\t\t\t\t\t\t\t\tSELECT *\n\t\t\t\t\t\t\t\t\t\t\tFROM `events`\n\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t`calendar` = '{$calendarCache['id']}' AND\n\t\t\t\t\t\t\t\t\t\t\t\t`event_hash` = '{$eventHash}'\n\t\t\t\t\t\t\t\t\t"); /* if we already have the event cached in its current form, just update the timestamp */ $eventCache = $eventCacheResponse->fetch_assoc(); if (DEBUGGING & DEBUGGING_MYSQL) { displayError($eventCache); } if ($eventCache) { mysqlQuery("\n\t\t\t\t\t\t\t\t\t\t\tUPDATE `events`\n\t\t\t\t\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\t\t\t\t\t`synced` = '" . getSyncTimestamp() . "'\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t\t\t`id` = '{$eventCache['id']}'\n\t\t\t\t\t\t\t\t\t\t"); /* otherwise, add this new event and cache it */ } else { /* multi-day event instance start times need to be changed to _this_ date */