mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
Adding ICS file on calendar reminder
This commit is contained in:
parent
9a9b8315fe
commit
4327644357
5 changed files with 286 additions and 10 deletions
170
objects/ICS.php
Normal file
170
objects/ICS.php
Normal file
|
@ -0,0 +1,170 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* This is free and unencumbered software released into the public domain.
|
||||
*
|
||||
* Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
* distribute this software, either in source code form or as a compiled
|
||||
* binary, for any purpose, commercial or non-commercial, and by any
|
||||
* means.
|
||||
*
|
||||
* In jurisdictions that recognize copyright laws, the author or authors
|
||||
* of this software dedicate any and all copyright interest in the
|
||||
* software to the public domain. We make this dedication for the benefit
|
||||
* of the public at large and to the detriment of our heirs and
|
||||
* successors. We intend this dedication to be an overt act of
|
||||
* relinquishment in perpetuity of all present and future rights to this
|
||||
* software under copyright law.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* For more information, please refer to <http://unlicense.org>
|
||||
*
|
||||
* ICS.php
|
||||
* =============================================================================
|
||||
* Use this class to create an .ics file.
|
||||
*
|
||||
*
|
||||
* Usage
|
||||
* -----------------------------------------------------------------------------
|
||||
* Basic usage - generate ics file contents (see below for available properties):
|
||||
* $ics = new ICS($props);
|
||||
* $ics_file_contents = $ics->to_string();
|
||||
*
|
||||
* Setting properties after instantiation
|
||||
* $ics = new ICS();
|
||||
* $ics->set('summary', 'My awesome event');
|
||||
*
|
||||
* You can also set multiple properties at the same time by using an array:
|
||||
* $ics->set(array(
|
||||
* 'dtstart' => 'now + 30 minutes',
|
||||
* 'dtend' => 'now + 1 hour'
|
||||
* ));
|
||||
*
|
||||
* Available properties
|
||||
* -----------------------------------------------------------------------------
|
||||
* description
|
||||
* String description of the event.
|
||||
* dtend
|
||||
* A date/time stamp designating the end of the event. You can use either a
|
||||
* DateTime object or a PHP datetime format string (e.g. "now + 1 hour").
|
||||
* dtstart
|
||||
* A date/time stamp designating the start of the event. You can use either a
|
||||
* DateTime object or a PHP datetime format string (e.g. "now + 1 hour").
|
||||
* location
|
||||
* String address or description of the location of the event.
|
||||
* summary
|
||||
* String short summary of the event - usually used as the title.
|
||||
* url
|
||||
* A url to attach to the the event. Make sure to add the protocol (http://
|
||||
* or https://).
|
||||
*/
|
||||
|
||||
class ICS {
|
||||
const DT_FORMAT = 'Ymd\THis\Z';
|
||||
|
||||
protected $properties = array();
|
||||
private $available_properties = array(
|
||||
'description',
|
||||
'dtend',
|
||||
'dtstart',
|
||||
'location',
|
||||
'summary',
|
||||
'url',
|
||||
'valarm'
|
||||
);
|
||||
|
||||
public function __construct($props) {
|
||||
$this->set($props);
|
||||
}
|
||||
|
||||
public function set($key, $val = false) {
|
||||
if (is_array($key)) {
|
||||
foreach ($key as $k => $v) {
|
||||
$this->set($k, $v);
|
||||
}
|
||||
} else {
|
||||
if (in_array($key, $this->available_properties)) {
|
||||
$this->properties[$key] = $this->sanitize_val($val, $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function to_string() {
|
||||
$rows = $this->build_props();
|
||||
return implode("\r\n", $rows);
|
||||
}
|
||||
|
||||
private function build_props() {
|
||||
// Build ICS properties - add header
|
||||
$ics_props = array(
|
||||
'BEGIN:VCALENDAR',
|
||||
'VERSION:2.0',
|
||||
'PRODID:-//hacksw/handcal//NONSGML v1.0//EN',
|
||||
'CALSCALE:GREGORIAN',
|
||||
'BEGIN:VEVENT'
|
||||
);
|
||||
|
||||
// Build ICS properties - add header
|
||||
$props = array();
|
||||
foreach($this->properties as $k => $v) {
|
||||
$props[strtoupper($k . ($k === 'url' ? ';VALUE=URI' : ''))] = $v;
|
||||
}
|
||||
|
||||
// Set some default values
|
||||
$props['DTSTAMP'] = $this->format_timestamp('now');
|
||||
$props['UID'] = uniqid();
|
||||
|
||||
// Append properties
|
||||
foreach ($props as $k => $v) {
|
||||
if($k=='VALARM'){
|
||||
$ics_props[] = "BEGIN:VALARM";
|
||||
$ics_props[] = "$k:$v";
|
||||
if(!empty($props['DESCRIPTION'])){
|
||||
$ics_props[] = "ACTION:DISPLAY";
|
||||
}else{
|
||||
$ics_props[] = "ACTION:AUDIO";
|
||||
}
|
||||
$ics_props[] = "END:VALARM";
|
||||
}else{
|
||||
$ics_props[] = "$k:$v";
|
||||
}
|
||||
}
|
||||
|
||||
// Build ICS properties - add footer
|
||||
$ics_props[] = 'END:VEVENT';
|
||||
$ics_props[] = 'END:VCALENDAR';
|
||||
|
||||
return $ics_props;
|
||||
}
|
||||
|
||||
private function sanitize_val($val, $key = false) {
|
||||
switch($key) {
|
||||
case 'dtend':
|
||||
case 'dtstamp':
|
||||
case 'dtstart':
|
||||
$val = $this->format_timestamp($val);
|
||||
break;
|
||||
default:
|
||||
$val = $this->escape_string($val);
|
||||
}
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
private function format_timestamp($timestamp) {
|
||||
$dt = new DateTime($timestamp);
|
||||
$dt->setTimezone(new DateTimeZone('UTC'));
|
||||
return $dt->format(self::DT_FORMAT);
|
||||
}
|
||||
|
||||
private function escape_string($str) {
|
||||
return preg_replace('/([\,;])/','\\\$1', $str);
|
||||
}
|
||||
}
|
|
@ -3430,7 +3430,20 @@ Click <a href=\"{link}\">here</a> to join our live.";
|
|||
$selectedEarlierOptions[] = intval($parts[3]);
|
||||
}
|
||||
|
||||
return Scheduler::getReminderOptions($destinationURL, $selectedEarlierOptions);
|
||||
$ls = new Live_schedule($_REQUEST['live_schedule_id']);
|
||||
|
||||
$ls = new Live_schedule($live_schedule_id);
|
||||
$users_id = Live_schedule::getUsers_idOrCompany($live_schedule_id);
|
||||
$title = $ls->getTitle();
|
||||
$date_start = $ls->getScheduled_time();
|
||||
$date_end = '';
|
||||
$joinURL = Live::getLinkToLiveFromUsers_id($users_id);
|
||||
$joinURL = addQueryStringParameter($joinURL, 'live_schedule', $live_schedule_id);
|
||||
|
||||
// , $date_start, $selectedEarlierOptions = array(), $date_end = '', $joinURL='', $description=''
|
||||
|
||||
return Scheduler::getReminderOptions($destinationURL, $title, $date_start, $selectedEarlierOptions, $date_end, $joinURL);
|
||||
|
||||
}
|
||||
|
||||
public function getWatchActionButton($videos_id): string {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
global $global;
|
||||
require_once $global['systemRootPath'] . 'objects/ICS.php';
|
||||
require_once $global['systemRootPath'] . 'plugin/Plugin.abstract.php';
|
||||
|
||||
require_once $global['systemRootPath'] . 'plugin/Scheduler/Objects/Scheduler_commands.php';
|
||||
|
@ -79,7 +80,7 @@ class Scheduler extends PluginAbstract {
|
|||
}
|
||||
|
||||
static public function run($scheduler_commands_id) {
|
||||
global $_executeSchelude,$global;
|
||||
global $_executeSchelude, $global;
|
||||
if (!isset($_executeSchelude)) {
|
||||
$_executeSchelude = array();
|
||||
}
|
||||
|
@ -96,7 +97,7 @@ class Scheduler extends PluginAbstract {
|
|||
$_executeSchelude[$callBackURL] = url_get_contents($callBackURL, '', 30);
|
||||
_error_log("Scheduler::run got callback " . json_encode($_executeSchelude[$callBackURL]));
|
||||
$json = _json_decode($_executeSchelude[$callBackURL]);
|
||||
if(is_object($json) && !empty($json->error)){
|
||||
if (is_object($json) && !empty($json->error)) {
|
||||
_error_log("Scheduler::run callback ERROR " . json_encode($json));
|
||||
return false;
|
||||
}
|
||||
|
@ -117,7 +118,7 @@ class Scheduler extends PluginAbstract {
|
|||
$date_to_execute_time = _strtotime($date_to_execute);
|
||||
|
||||
if ($date_to_execute_time <= time()) {
|
||||
_error_log("Scheduler::add ERROR date_to_execute must be greater than now [{$date_to_execute}] ".date('Y/m/d H:i:s', $date_to_execute_time).' '.date('Y/m/d H:i:s'));
|
||||
_error_log("Scheduler::add ERROR date_to_execute must be greater than now [{$date_to_execute}] " . date('Y/m/d H:i:s', $date_to_execute_time) . ' ' . date('Y/m/d H:i:s'));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -157,7 +158,7 @@ class Scheduler extends PluginAbstract {
|
|||
return $scheduler_commands_id;
|
||||
}
|
||||
|
||||
static public function getReminderOptions($destinationURL, $selectedEarlierOptions = array(), $earlierOptions = array(
|
||||
static public function getReminderOptions($destinationURL, $title, $date_start, $selectedEarlierOptions = array(), $date_end = '', $joinURL='', $description='',$earlierOptions = array(
|
||||
'10 minutes earlier' => 10,
|
||||
'30 minutes earlier' => 30,
|
||||
'1 hour earlier' => 60,
|
||||
|
@ -168,9 +169,77 @@ class Scheduler extends PluginAbstract {
|
|||
)
|
||||
) {
|
||||
global $global;
|
||||
$varsArray = array('destinationURL' => $destinationURL, 'earlierOptions' => $earlierOptions, 'selectedEarlierOptions' => $selectedEarlierOptions);
|
||||
$varsArray = array(
|
||||
'destinationURL' => $destinationURL,
|
||||
'title' => $title,
|
||||
'date_start' => $date_start,
|
||||
'selectedEarlierOptions' => $selectedEarlierOptions,
|
||||
'date_end' => $date_end,
|
||||
'joinURL' => $joinURL,
|
||||
'description' => $description,
|
||||
'earlierOptions' => $earlierOptions);
|
||||
$filePath = "{$global['systemRootPath']}plugin/Scheduler/reminderOptions.php";
|
||||
return getIncludeFileContent($filePath, $varsArray);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @global type $global
|
||||
* @param type $title
|
||||
* @param type $description
|
||||
* @param type $date_start
|
||||
* @param type $date_end
|
||||
*
|
||||
* description - string description of the event.
|
||||
dtend - date/time stamp designating the end of the event. You can use either a DateTime object or a PHP datetime format string (e.g. "now + 1 hour").
|
||||
dtstart - date/time stamp designating the start of the event. You can use either a DateTime object or a PHP datetime format string (e.g. "now + 1 hour").
|
||||
location - string address or description of the location of the event.
|
||||
summary - string short summary of the event - usually used as the title.
|
||||
url - string url to attach to the the event. Make sure to add the protocol (http:// or https://).
|
||||
*/
|
||||
static public function downloadICS($title, $date_start, $date_end = '', $reminderInMinutes='', $joinURL='', $description='') {
|
||||
global $global,$config;
|
||||
//var_dump(date_default_timezone_get());exit;
|
||||
header('Content-Type: text/calendar; charset=utf-8');
|
||||
header('Content-Disposition: attachment; filename=invite.ics');
|
||||
|
||||
$location = $config->getWebSiteTitle();
|
||||
if(!isValidURL($joinURL)){
|
||||
$joinURL = $global['webSiteRootURL'];
|
||||
}
|
||||
|
||||
if(empty($description)){
|
||||
$description = $location;
|
||||
}
|
||||
|
||||
$date_start = _strtotime($date_start);
|
||||
$date_end = _strtotime($date_end);
|
||||
|
||||
if(empty($date_end) || $date_end <= $date_start){
|
||||
$date_end = strtotime(date('Y/m/d H:i:s', $date_start).' + 1 hour');
|
||||
}
|
||||
$dtstart = date('Y/m/d H:i:s', $date_start);
|
||||
$dtend = date('Y/m/d H:i:s', $date_end);
|
||||
$reminderInMinutes = intval($reminderInMinutes);
|
||||
if(!empty($reminderInMinutes)){
|
||||
$VALARM = "-P{$reminderInMinutes}M";
|
||||
}else{
|
||||
$VALARM = '';
|
||||
}
|
||||
|
||||
$props = array(
|
||||
'location' => $location,
|
||||
'description' => $description,
|
||||
'dtstart' => $dtstart,
|
||||
'dtend' => $dtend,
|
||||
'summary' => $title,
|
||||
'url' => $joinURL,
|
||||
'valarm' => $VALARM,
|
||||
//'X-WR-TIMEZONE' => date_default_timezone_get()
|
||||
);
|
||||
$ics = new ICS($props);
|
||||
//var_dump($props);
|
||||
echo $ics->to_string();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
17
plugin/Scheduler/downloadICS.php
Normal file
17
plugin/Scheduler/downloadICS.php
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
//streamer config
|
||||
require_once dirname(__FILE__) . '/../../videos/configuration.php';
|
||||
|
||||
if(!AVideoPlugin::isEnabledByName('Scheduler')){
|
||||
forbiddenPage('Scheduler is disabled');
|
||||
}
|
||||
|
||||
if(empty($_REQUEST['title'])){
|
||||
forbiddenPage('Title cannot be empty');
|
||||
}
|
||||
if(empty($_REQUEST['date_start'])){
|
||||
forbiddenPage('date_start cannot be empty');
|
||||
}
|
||||
|
||||
Scheduler::downloadICS($_REQUEST['title'], $_REQUEST['date_start'], @$_REQUEST['date_end'], @$_REQUEST['reminder'], @$_REQUEST['joinURL'], @$_REQUEST['description']);
|
|
@ -4,14 +4,21 @@ $md5DestinationURL = md5($destinationURL);
|
|||
<div class="<?php echo $md5DestinationURL; ?>">
|
||||
<ul class="list-group">
|
||||
<?php
|
||||
$ics = "{$global['webSiteRootURL']}plugin/Scheduler/downloadICS.php";
|
||||
$ics = addQueryStringParameter($ics, 'title', $title);
|
||||
$ics = addQueryStringParameter($ics, 'date_start', $date_start);
|
||||
$ics = addQueryStringParameter($ics, 'date_end', $date_end);
|
||||
$ics = addQueryStringParameter($ics, 'joinURL', $joinURL);
|
||||
$ics = addQueryStringParameter($ics, 'description', $description);
|
||||
foreach ($earlierOptions as $key => $value) {
|
||||
$checked = '';
|
||||
if (in_array($value, $selectedEarlierOptions)) {
|
||||
$checked = 'checked';
|
||||
}
|
||||
$icsURL = addQueryStringParameter($ics, 'reminder', $value);
|
||||
?>
|
||||
<li class="list-group-item">
|
||||
<?php echo __($key); ?>
|
||||
<a href="<?php echo $icsURL; ?>"><i class="fas fa-file-download" data-toggle="tooltip" title="<?php echo __('Download reminder'); ?>"></i></a> <?php echo __($key); ?>
|
||||
<div class="material-switch pull-right">
|
||||
<input name="reminder<?php echo $value; ?>" id="reminder<?php echo $value; ?>" type="checkbox" value="<?php echo $value; ?>" class="reminder" <?php echo $checked; ?>>
|
||||
<label for="reminder<?php echo $value; ?>" class="label-success"></label>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue