Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
zoharbabin committed Feb 7, 2021
1 parent dce8518 commit b3e1742
Show file tree
Hide file tree
Showing 37 changed files with 4,563 additions and 0 deletions.
477 changes: 477 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

184 changes: 184 additions & 0 deletions add2calendar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<?php
// ----------------------------------------------------------------
// Rewrite of https://github.com/spatie/calendar-links to a single page script
// ----------------------------------------------------------------
// Meeting calendar event data -
require_once('./utils.php');
$title = filter_var($_GET["title"], FILTER_SANITIZE_STRING);
$title = urldecode($title);
$description = filter_var($_GET["desc"], FILTER_SANITIZE_STRING);
$description = urldecode($description);
$address = filter_var($_GET["address"], FILTER_SANITIZE_STRING);
$address = urldecode($address);
$allDay = filter_var($_GET["allday"], FILTER_SANITIZE_STRING); //yes or no (do not use boolean)
$startDateInput = filter_var($_GET["from"], FILTER_SANITIZE_NUMBER_INT); // see: $inputDateFormat
$endDateInput = false;
// see: $inputDateFormat --> MUST be a time AFTER $startDate
if (isset($_GET["to"])) {
$endDateInput = filter_var($_GET["to"], FILTER_SANITIZE_NUMBER_INT);
}
$duration = false;
// DateInterval format, e.g. PT1H
if (isset($_GET["duration"])) {
$duration = filter_var($_GET["duration"], FILTER_SANITIZE_STRING);
}
if (
$title === false || $description === false || $address === false || $startDateInput === false ||
$allDay === false || ($endDateInput === false && $duration === false)
) {
redirect_to_page('index.html');
}
$inputDateFormat = 'U'; // input should be UNIX timestamp formatted. e.g. 1612612219
$durationInterval = null;
try {
$startDate = DateTime::createFromFormat($inputDateFormat, $startDateInput);
} catch (Exception $e) {
echo 'from input date (' . $startDateInput . ') wrong format, please use a unix-timestamp, e.g. 1612612219' . PHP_EOL;
exit(1);
}
if ($endDateInput) {
try {
$endDate = DateTime::createFromFormat($inputDateFormat, $endDateInput);
} catch (Exception $e) {
echo 'to input date (' . $endDateInput . ') wrong format, please use a unix-timestamp, e.g. 1612612219' . PHP_EOL;
exit(1);
}
} else {
if ($duration) {
try {
$durationInterval = new DateInterval($duration);
} catch (Exception $e) {
echo 'duration input (' . $duration . ') wrong format, please use PHP DateInterval format, e.g. PT1H for +1 hour' . PHP_EOL;
exit(1);
}
$endDate = (clone $startDate)->add($durationInterval);
}
}
if ($endDate <= $startDate) {
echo 'the end date/time must be after start date/time' . PHP_EOL;
exit(1);
}
if ($allDay != 'yes' && $allDay != 'no') {
echo 'allday input (' . $allDay . ') wrong format, please use either "yes" or "no" as value' . PHP_EOL;
exit(1);
}
$allDay = $allDay == 'yes' ? true : false;
// ----------------------------------------------------------------
$dateFormat = 'Ymd';
$dateTimeFormat = 'Ymd\THis\Z';
$outlookDateFormat = 'Y-m-d';
$outlookDateTimeFormat = 'Y-m-d\TH:i:s\Z';
$IcsDateTimeFormat = 'e:Ymd\THis';
$dateTimeFormat = $allDay ? $dateFormat : $dateTimeFormat;
// ----------------------------------------------------------------
// Google Calendar
$googleCalUrl = 'https://calendar.google.com/calendar/render?action=TEMPLATE';
$googleCalUrl .= '&dates=' . $startDate->format($dateTimeFormat) . '/' . $endDate->format($dateTimeFormat);
$googleCalUrl .= '&text=' . rawurlencode($title);
if ($description) $googleCalUrl .= '&details=' . rawurlencode($description);
if ($address) $googleCalUrl .= '&location=' . rawurlencode($address);
// ----------------------------------------------------------------
// Outlook365 Calendar
$outlook365Url = 'https://outlook.live.com/calendar/deeplink/compose?path=/calendar/action/compose'; //&rru=addevent causes + signs
$outlook365Url .= '&startdt=' . $startDate->format($outlookDateTimeFormat);
$outlook365Url .= '&enddt=' . $endDate->format($outlookDateTimeFormat);
if ($allDay) $outlook365Url .= '&allday=true';
$outlook365Url .= '&subject=' . rawurlencode($title);
if ($description) $outlook365Url .= '&body=' . rawurlencode($description);
if ($address) $outlook365Url .= '&location=' . rawurlencode($address);
// ----------------------------------------------------------------
// Yahoo! Calendar
$yahooUrl = 'https://calendar.yahoo.com/?v=60&view=d&type=20';
if ($allDay && $startDate->diff($endDate)->days === 1) {
$yahooUrl .= '&st=' . $startDate->format($dateTimeFormat);
$yahooUrl .= '&dur=allday';
} else {
$yahooUrl .= '&st=' . $startDate->format($dateTimeFormat);
/**
* Yahoo has a bug on parsing end date parameter: it ignores timezone, assuming
* that it's specified in user's tz. In order to bypass it, we can use duration ("dur")
* parameter instead of "et", but this parameter has a limitation cause by it's format HHmm:
* the max duration is 99hours and 59 minutes (dur=9959).
*/
$maxDurationInSecs = (59 * 60 * 60) + (59 * 60);
$canUseDuration = $maxDurationInSecs > ($endDate->getTimestamp() - $startDate->getTimestamp());
if ($canUseDuration) {
$dateDiff = $startDate->diff($endDate);
$yahooUrl .= '&dur=' . $dateDiff->format('%H%I');
} else {
$yahooUrl .= '&et=' . $endDate->format($dateTimeFormat);
}
}
$yahooUrl .= '&title=' . rawurlencode($title);
if ($description) $yahooUrl .= '&desc=' . rawurlencode($description);
if ($address) $yahooUrl .= '&in_loc=' . rawurlencode($address);
// ----------------------------------------------------------------
// ICS Download
// See: https://tools.ietf.org/html/rfc5545#section-3.8.4.7
$eventUuid = md5(sprintf(
'%s%s%s%s',
$startDate->format(\DateTimeInterface::ATOM),
$endDate->format(\DateTimeInterface::ATOM),
$title,
$address
));
// See: https://tools.ietf.org/html/rfc5545.html#section-3.3.11
$ecapedTitle = addcslashes($title, "\r\n,;");
$IcsUrlParts = array(
'BEGIN:VCALENDAR',
'VERSION:2.0',
'BEGIN:VEVENT',
'UID:' . $eventUuid,
'SUMMARY:' . $ecapedTitle,
);
$dateTimeFormat2Use = $allDay ? $dateFormat : $IcsDateTimeFormat;
if ($allDay) {
$IcsUrlParts[] = 'DTSTART:' . $startDate->format($dateTimeFormat2Use);
$IcsUrlParts[] = 'DURATION:P1D';
} else {
$IcsUrlParts[] = 'DTSTART;TZID=' . $startDate->format($dateTimeFormat2Use);
$IcsUrlParts[] = 'DTEND;TZID=' . $endDate->format($dateTimeFormat2Use);
}
if ($description) $IcsUrlParts[] = 'DESCRIPTION:' . addcslashes($description, "\r\n,;");
if ($address) $IcsUrlParts[] = 'LOCATION:' . addcslashes($address, "\r\n,;");
$IcsUrlParts[] = 'END:VEVENT';
$IcsUrlParts[] = 'END:VCALENDAR';
$IcsUrl = 'data:text/calendar;charset=utf8;base64,' . base64_encode(implode("\r\n", $IcsUrlParts));

function echoLink($url, $name, $filename = '')
{
echo '<a href="' . $url . '" target="_blank"' . ($filename != '' ? 'download="' . $filename . '"' : '') . '>' . $name . '</a>' . PHP_EOL;
}

?>
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Kaltura Job Application</title>
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300,400,600,700,900&display=swap" rel="stylesheet" />
<link rel="stylesheet" href="./css/theme.css" type="text/css" media="all" />
<link rel="icon" href="./css/images/fav_icon.png" sizes="32x32" />
<link rel="icon" href="./css/images/fav_icon.png" sizes="192x192" />
<link rel="apple-touch-icon" href="./css/images/fav_icon.png" />
<meta name="msapplication-TileImage" content="./css/images/fav_icon.png" />
</head>

<body>
<div id="maincontainer" class="main">
<h1>Add the meeting to your calendar</h1>
<div class="add2calendar">
<ul>
<li><span class="icon-google"></span>&nbsp;<?php echoLink($googleCalUrl, 'Google'); ?></li>
<li><span class="icon-microsoftoutlook"></span>&nbsp;<?php echoLink($outlook365Url, 'Outlook365'); ?></li>
<li><span class="icon-yahoo"></span>&nbsp;<?php echoLink($yahooUrl, 'Yahoo!'); ?></li>
<li><span class="icon-calendar"></span>&nbsp;<?php echoLink($IcsUrl, 'Download ICS file', 'meetingCal.ics'); ?></li>
</ul>
</div>
</div>
</body>

</html>
120 changes: 120 additions & 0 deletions bookmeeting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php
require_once('./config.php');
require_once('./utils.php');
$startDateInput = filter_var($_GET["from"], FILTER_SANITIZE_NUMBER_INT); // see: $inputDateFormat
$userks = filter_var($_GET['ks'], FILTER_SANITIZE_STRING);
$entryId = filter_var($_GET['id'], FILTER_SANITIZE_STRING);
$userDisplayName = filter_var($_GET['name'], FILTER_SANITIZE_STRING);
$userDisplayName = urldecode($userDisplayName);
$applicantEmail = filter_var($_GET["uid"], FILTER_SANITIZE_EMAIL);
$applicantEmail = urldecode($applicantEmail);
$startDate = null;
$inputDateFormat = 'U';
try {
$startDate = DateTime::createFromFormat($inputDateFormat, $startDateInput);
} catch (Exception $e) {
$startDate = null;
}
$eventDescription = null;
$mediaGetUrl = 'https://cdnapisec.kaltura.com/api_v3/service/media/action/get/format/1/entryId/' . $entryId . '/ks/' . $userks;
try {
$mediaEntry = json_decode(file_get_contents($mediaGetUrl));
$eventDescription = $mediaEntry->description;
} catch (Exception $e) {
$eventDescription = null;
}
if (
$mediaEntry === null || $eventDescription === null ||
$startDate === null || $startDateInput === false || $userks === false ||
$entryId === false || $userDisplayName === false || $applicantEmail === false
) {
redirect_to_page('index.html');
}

// read more: https://github.com/kaltura-vpaas/virtual-meeting-rooms
// We'll create the video meeting experience room by creating:
// 1. scheduled resource (the room the virtual meeting will take place in)
// 2. scheduled event (indicating the date & time the meeting will happen)
// 3. scheduled event resource (an object mapping the two)

$ksType = 2; //admin KS
$sessionStartRESTAPIUrl = 'https://cdnapisec.kaltura.com/api_v3/service/session/action/start/format/1/secret/' . $apiAdminSecret . '/partnerId/' . $partnerId . '/type/' . $ksType . '/expiry/' . $expire . '/userId/' . $applicantEmail . '/privileges/editadmintags:*,appid:' . $appName . '-' . $appDomain . ($privacyContext != null ? ',privacycontext:' . $privacyContext : '');
$adminks = file_get_contents($sessionStartRESTAPIUrl);
$adminks = trim($adminks, '"');

// create the scheduled resource for the meeting:
$scheduledResourceUrl = 'https://www.kaltura.com/api_v3/service/schedule_scheduleresource/action/add/format/1?scheduleResource[objectType]=KalturaLocationScheduleResource';
$scheduledResourceUrl .= '&scheduleResource[name]=' . urlencode('Meeting room for interview with ' . $userDisplayName);
$scheduledResourceUrl .= '&scheduleResource[description]=' . urlencode($eventDescription);
$scheduledResourceUrl .= '&scheduleResource[tags]=vcprovider:newrow,job-application';
$scheduledResourceUrl .= '&scheduleResource[systemName]=job-application-' . $entryId;
$scheduledResourceUrl .= '&ks=' . $adminks;
try {
$scheduledResource = json_decode(file_get_contents($scheduledResourceUrl));
} catch (Exception $e) {
var_dump($e);
exit(1);
}

// create the event for the meeting:
$duration = 'PT1H'; // schedule the event for 1 hour (StartDate was given in the from param, EndDate will be 1 hour from the StartDate)
$durationInterval = new DateInterval($duration);
$endDate = (clone $startDate)->add($durationInterval);

$scheduledEventUrl = 'https://www.kaltura.com/api_v3/service/schedule_scheduleevent/action/add/format/1?scheduleEvent[objectType]=KalturaRecordScheduleEvent&scheduleEvent[recurrenceType]=0';
$scheduledEventUrl .= '&scheduleEvent[tags]=' . 'job-application,custom_rec_auto_start:1,custom_rs_show_participant:0,custom_rs_show_invite:0,custom_rs_show_chat:1,custom_rs_class_mode:virtual_classroom,custom_rs_show_chat_moderators:0,custom_rs_show_chat_questions:0,custom_rs_room_version:nr2';
$scheduledEventUrl .= '&scheduleEvent[summary]=' . urlencode($eventDescription);
$scheduledEventUrl .= '&scheduleEvent[startDate]=' . $startDate->getTimestamp();
$scheduledEventUrl .= '&scheduleEvent[endDate]=' . $endDate->getTimestamp();
$scheduledEventUrl .= '&scheduleEvent[entryIds]=' . $entryId; //associate this event with the job applicant's video
$scheduledEventUrl .= '&ks=' . $adminks;
try {
$scheduledEvent = json_decode(file_get_contents($scheduledEventUrl));
} catch (Exception $e) {
var_dump($e);
exit(1);
}

// associate the resource (room) with the event
$scheduledEventResourceUrl = 'https://www.kaltura.com/api_v3/service/schedule_scheduleeventresource/action/add/format/1?scheduleEventResource[objectType]=KalturaScheduleEventResource';
$scheduledEventResourceUrl .= '&scheduleEventResource[eventId]=' . $scheduledEvent->id;
$scheduledEventResourceUrl .= '&scheduleEventResource[resourceId]=' . $scheduledResource->id;
$scheduledEventResourceUrl .= '&ks=' . $adminks;
try {
$scheduledEventResource = json_decode(file_get_contents($scheduledEventResourceUrl));
} catch (Exception $e) {
var_dump($e);
exit(1);
}

// create the Kaltura Session for authenticated room participant
// to make sure we give the session enough time to live, we'll set it to when the meeting is supposed to end + 2 hours extra
$participantSessionEndDate = (clone $startDate)->add(new DateInterval('PT2H')); // add 2 hours to meeting end time
$sessionExpiry = $participantSessionEndDate->getTimestamp() - $startDate->getTimestamp(); //unixtimestamps are in seconds
$participantSessionPrivileges = "eventId:$scheduledEvent->id,role:viewerRole,userContextualRole:3,firstName:$userDisplayName";
$eventParticipantKsUrl = 'https://cdnapisec.kaltura.com/api_v3/service/session/action/start/format/1/secret/' . $apiAdminSecret . '/partnerId/' . $partnerId . '/type/' . $sessionType . '/expiry/' . $sessionExpiry . '/userId/' . $applicantEmail . '/privileges/' . $participantSessionPrivileges;
$eventParticipantKs = file_get_contents($eventParticipantKsUrl);
$eventParticipantKs = trim($eventParticipantKs, '"');

// since the room link is rather lengthy with the secure session, we will create a shortlink for it
// construct the room link with the KS
$meetingRoomUrl = get_base_url() . '/meetingroom.php?ks=' . $eventParticipantKs;
// create the short link
$shortLinkAddUrl = 'https://www.kaltura.com/api_v3/service/shortlink_shortlink/action/add/format/1/?shortLink[objectType]=KalturaShortLink&shortLink[status]=2';
$shortLinkAddUrl .= '&shortLink[fullUrl]=' . $meetingRoomUrl;
$shortLinkAddUrl .= '&shortLink[systemName]=' . 'roomshortlink' . $scheduledEvent->id;
$shortLinkAddUrl .= '&ks=' . $adminks;
try {
$shortLink = json_decode(file_get_contents($shortLinkAddUrl));
} catch (Exception $e) {
var_dump($e);
exit(1);
}

$participantRoomShortLink = urlencode($kalturaShortLinkBaseUrl . $shortLink->id);

//redirect to the add2calendar page:
$desc = urlencode($eventDescription);
$addToCalendarLink = "add2calendar.php?title=$scheduledResource->name&desc=$desc&address=$participantRoomShortLink&allday=no&from=$scheduledEvent->startDate&to=$scheduledEvent->endDate";
redirect_to_page($addToCalendarLink);
exit(1);
14 changes: 14 additions & 0 deletions config.php.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
$partnerId = 00000; //https://kmc.kaltura.com/index.php/kmcng/settings/integrationSettings
$apiAdminSecret = '1a1d1fg1fjhgda68aysgdahsb7636626'; //https://kmc.kaltura.com/index.php/kmcng/settings/integrationSettings (Admin Secret)
$expire = 60 * 60 * 24; //one day
$recorderPlayerId = 000000; //https://kmc.kaltura.com/index.php/kmcng/studio/v3
$editorPlayerId = 000000; //https://kmc.kaltura.com/index.php/kmcng/studio/v2
$appName = 'kaltura-job-application'; //used to designate your application name, this can be used in the Analytics later to differentiate usage across different apps (such as website vs. mobile iOS vs. mobile Android vs. partner site)
$appDomain = 'vidrecruite.kaltura.me'; // the domain to track this playback session to
//generate the Kaltura Session for secure and tracked playback session
$privacyContext = null; //'YourCategoryName'; //if your entries are inside a category with a defined privacyContext, this must be specified too
$sessionType = 0; // 0 for USER Session, 2 for Admin Session
$kalturaAppsFrameworkBaseUrl = 'https://' . $partnerId . '.kaf.kaltura.com';
$kalturaMeetingRoomLaunchBaseUrl = $kalturaAppsFrameworkBaseUrl . '/virtualEvent/launch?ks=';
$kalturaShortLinkBaseUrl = 'https://kaltura.com/tiny/';
Binary file added css/fonts/CentraNo1-Bold.ttf
Binary file not shown.
Binary file added css/fonts/CentraNo1-Bold.woff
Binary file not shown.
Binary file added css/fonts/CentraNo1-Book.ttf
Binary file not shown.
Binary file added css/fonts/CentraNo1-Book.woff
Binary file not shown.
Binary file added css/fonts/CentraNo1-Hairline.ttf
Binary file not shown.
Binary file added css/fonts/CentraNo1-Hairline.woff
Binary file not shown.
Binary file added css/fonts/CentraNo1-Light.ttf
Binary file not shown.
Binary file added css/fonts/CentraNo1-Light.woff
Binary file not shown.
Binary file added css/fonts/CentraNo1-Medium.ttf
Binary file not shown.
Binary file added css/fonts/CentraNo1-Medium.woff
Binary file not shown.
Binary file added css/fonts/CentraNo1-Thin.ttf
Binary file not shown.
Binary file added css/fonts/CentraNo1-Thin.woff
Binary file not shown.
Binary file added css/fonts/icomoon.eot
Binary file not shown.
Loading

0 comments on commit b3e1742

Please sign in to comment.