Commit 98bd184c authored by Francesco Iannuzzelli's avatar Francesco Iannuzzelli

Calendar export

parent 403a1513

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

......@@ -215,6 +215,9 @@ class Cache
$e->phone = $row['phone'];
$e->email = $row['email'];
$e->link = $row['link'];
$e->export = $irl->pub_web . '/' . $ini->Get("events_path") . "/export.php?id={$row['id_event']}";
$e->export_escaped = urlencode($e->export);
$e->export_webcal = preg_replace('#^http(s)?://#','webcal://',$e->export);
$e->gmaps = "https://www.google.com/maps/search/?api=1&hl={$tr->lang_code}&query=" . urlencode("{$row['place']}, {$row['place_details']}");
if($row['latitude']!='' && $row['longitude']!='') {
$e->gmaps .= "&ll={$row['latitude']},{$row['longitude']}";
......
<?php
use ICal\ICal;
use Kigkonsult\Icalcreator\TimezoneHandler;
/********************************************************************
......@@ -294,6 +295,117 @@ class Event
}
}
public function ExportIcs($id_event) {
require(SERVER_ROOT."/../others/vendor/autoload.php");
include_once(SERVER_ROOT."/../classes/ini.php");
$ini = new Ini();
include_once(SERVER_ROOT."/../classes/texthelper.php");
$th = new TextHelper();
$event = $this->EventGet($id_event);
$tz = "Europe/Rome";
$config = [
'UNIQUE_ID' => "peacelink.it"
];
$calendar = new Kigkonsult\Icalcreator\Vcalendar($config);
// required of some calendar software
$calendar->setProperty( 'method', "PUBLISH" );
$calendar->setProperty( "x-wr-calname", "Calendario PeaceLink" );
$calendar->setProperty( "X-WR-CALDESC", "Gli appuntamenti del mondo pacifista italiano" );
$calendar->setProperty( "X-WR-TIMEZONE", $tz );
$url = $ini->Get("pub_web") . '/' . $ini->Get("events_path");
$calendar->setProperty( "X-FROM-URL", $url);
$uuid = "pck-events";
$calendar->setProperty( "X-WR-RELCALID", $uuid );
$vevent = $calendar->newVevent();
// alt. date format, here for an all-day event
if($event['allday']) {
$vevent->setProperty(
'DTSTART',
date("Ymd",$event['start_date_ts']),
[ "VALUE" => "DATE" ]
);
} else {
$vevent->setProperty(
'DTSTART',
new DateTime( date("Y-m-d H:i:s",$event['start_date_ts']))
);
if($event['length']>0) {
$vevent->setProperty(
'DTSTART',
new DateTime( date("Y-m-d H:i:s",$event['start_date_ts'] + ($event['length']*3600)))
);
}
}
$vevent->setProperty('LOCATION', "{$event['address']} {$event['place']}" );
$vevent->setProperty('SUMMARY', $event['title'] );
$vevent->setProperty( "X-ALT-DESC", $event['description'] );
$th->Html2Text($event['description']);
$vevent->setProperty('DESCRIPTION', $event['description'] );
$vevent->setProperty( "URL", "$url/event.php?id={$event['id_event']}");
return $calendar->returnCalendar();;
}
public function ExportIcsProvince($prov) {
include_once(SERVER_ROOT."/../classes/geo.php");
$geo = new Geo();
$prov = $geo->ProvinceGetByProv($prov);
if(isset($prov['id_prov'])) {
require(SERVER_ROOT."/../others/vendor/autoload.php");
include_once(SERVER_ROOT."/../classes/ini.php");
$ini = new Ini();
include_once(SERVER_ROOT."/../classes/texthelper.php");
$th = new TextHelper();
$tz = "Europe/Rome";
$config = [
'UNIQUE_ID' => "peacelink.it"
];
$calendar = new Kigkonsult\Icalcreator\Vcalendar($config);
// required of some calendar software
$calendar->setProperty( 'method', "PUBLISH" );
$calendar->setProperty( "x-wr-calname", "Calendario PeaceLink" );
$calendar->setProperty( "X-WR-CALDESC", "Appuntamenti della provincia di {$prov['prov']}" );
$calendar->setProperty( "X-WR-TIMEZONE", $tz );
$url = $ini->Get("pub_web") . '/' . $ini->Get("events_path");
$calendar->setProperty( "X-FROM-URL", $url);
$uuid = "pck-events";
$calendar->setProperty( "X-WR-RELCALID", $uuid );
include_once(SERVER_ROOT."/../classes/events.php");
$ee = new Events();
$events = $ee->SearchProvince($prov['id_prov']);
foreach($events as $event) {
$vevent = $calendar->newVevent();
// alt. date format, here for an all-day event
if($event['allday']) {
$vevent->setProperty(
'DTSTART',
date("Ymd",$event['start_date_ts']),
[ "VALUE" => "DATE" ]
);
} else {
$vevent->setProperty(
'DTSTART',
new DateTime( date("Y-m-d H:i:s",$event['start_date_ts']))
);
if($event['length']>0) {
$vevent->setProperty(
'DTSTART',
new DateTime( date("Y-m-d H:i:s",$event['start_date_ts'] + ($event['length']*3600)))
);
}
}
$vevent->setProperty('LOCATION', "{$event['address']} {$event['place']}" );
$vevent->setProperty('SUMMARY', $event['title'] );
$vevent->setProperty( "X-ALT-DESC", $event['description'] );
$th->Html2Text($event['description']);
$vevent->setProperty('DESCRIPTION', $event['description'] );
$vevent->setProperty( "URL", "$url/event.php?id={$event['id_event']}");
}
return $calendar->returnCalendar();;
}
}
public function FacebookImport($link) {
include_once(SERVER_ROOT."/../classes/file.php");
$conf = new Configuration();
......
......@@ -429,6 +429,23 @@ class Events
return $db->QueryExe($rows, $sqlstr,true);
}
public function SearchProvince( $id_prov )
{
$rows = array();
$gjoin = $this->geo->GeoJoin("e.id_geo",true);
$db =& Db::globaldb();
$sqlstr = "SELECT UNIX_TIMESTAMP(e.start_date) AS start_date_ts,e.id_event,
e.title,e.place,e.id_topic,e.jump_to_article,e.id_article,e.has_image,e.image_ratio,
'event' AS item_type,evt.type,pr.pr AS geo_name,e.approved
FROM events e
INNER JOIN event_types evt ON e.id_event_type=evt.id_event_type
$gjoin[join]
WHERE e.approved=1 AND e.id_geo=$id_prov AND e.start_date>=CURDATE()
ORDER BY e.start_date DESC ";
$db->QueryExe($rows, $sqlstr);
return $rows;
}
/**
* Events submitted by a specific person
* (only approved ones)
......
......@@ -144,13 +144,13 @@ class Geo
return $name;
}
public function GeoJoin($geo_field)
public function GeoJoin($geo_field,$inner=false)
{
$join = array();
switch ($this->geo_location)
{
case "1";
$join = array('name'=>"pr.pr",'join'=>"LEFT JOIN prov pr ON $geo_field=pr.id_prov");
$join = array('name'=>"pr.pr",'join'=>($inner?"INNER":"LEFT") . " JOIN prov pr ON $geo_field=pr.id_prov");
break;
case "2";
case "6";
......
......@@ -2769,6 +2769,9 @@ class Layout
$ev['facebook_id'] = $event['facebook_id'];
$ev['important'] = $event['important'];
$ev['portal'] = $event['portal'];
$ev['export'] = $this->pub_web . '/' . $this->ini->Get("events_path") . "/export.php?id=$id_event";
$ev['export_escaped'] = urlencode($ev['export']);
$ev['export_webcal'] = preg_replace('#^http(s)?://#','webcal://',$ev['export']);