Commit 3a65410f authored by Loïc DAYOT's avatar Loïc DAYOT
Browse files

feat(): New export formats

exportlist.php class.event.inc.php class.export.inc.php funcs.inc.php
Adding export format for events : KML and geoJSON.
Concentrate all exports into exportevents.php in place of ical.php, javascript.php, rss.php.
Adding export format for localgroups : geoJSON
Rename localgrouptextlist.php into exportlocalgroups.php

close #8
parent 36a2236c
<?php
/*
* Copyright 2018
* - Loic Dayot <ldayot CHEZ epnadmin POINT net>
*
* This file is part of agenda-libre-php.
*
* agenda-libre-php is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* agenda-libre-ph is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with agenda-libre-php. If not, see <http://www.gnu.org/licenses/>.
*/
$privatePage = false;
include("inc/main.inc.php");
include_once("inc/class.event.inc.php");
include_once("inc/class.export.inc.php");
$eventList = new exportEvent($db);
$eventList->get2fields();
$format = get_safe_string('format', 'rss');
if (($list = $eventList->getEventsList()) == FALSE)
{
error ("Erreur lors de la récupération des évènements");
exit;
}
switch ($format) {
case 'js' : {
echo $eventList->jsStartCalendar();
while ($eventList->event->id = $db->getOne($list))
{
$eventList->event->get();
echo $eventList->event->toJs();
}
echo $eventList->jsEndCalendar();
break;
}
case 'ical' : {
echo $eventList->icalStartCalendar();
while ($eventList->event->id = $db->getOne($list))
{
$eventList->event->get();
echo $eventList->event->toIcal();
}
echo $eventList->icalEndCalendar();
break;
}
case 'kml' : {
echo $eventList->kmlStartCalendar();
//$list = $eventList->getEventsList();
while ($eventList->event->id = $db->getOne($list))
{
$eventList->event->get();
echo $eventList->event->toKml();
}
echo $eventList->kmlEndCalendar();
break;
}
case 'geojson' : {
echo $eventList->geojsonStartCalendar();
$isfirst=true;
while ($eventList->event->id = $db->getOne($list))
{
$eventList->event->get();
if ($isfirst) {
$isfirst = false;
} else {
echo ",\n";
}
echo $eventList->event->toGeojson();
}
echo $eventList->geojsonEndCalendar();
break;
}
// TODO : XML from old xmllistevents.php
default :
case 'georss' :
case 'rss' : {
echo $eventList->rssStartCalendar();
while ($eventList->event->id = $db->getOne($list))
{
echo $eventList->rssEventHeaderCalendar();
}
echo $eventList->rssEndHeaderCalendar();
$list = $eventList->getEventsList();
while ($eventList->event->id = $db->getOne($list))
{
$eventList->event->get();
echo $eventList->event->toRss($format == 'georss');
}
echo $eventList->rssEndCalendar();
break;
}
} // end switch
?>
<?php
/*
* Copyright 2015-2017
* Copyright 2015-2018
* - Loic Dayot <ldayot CHEZ epnadmin POINT net>
*
* This file is part of agenda-libre-php.
......@@ -42,11 +42,13 @@ $export->getTagList('tags');
echo "<ul class='fa-ul'>\n";
echo " <li><i class='fa fa-li fa-rss'></i>&nbsp;Flux RSS 1.0 : <a href=\"". $export->rssUrl(). "\">". $export->rssUrl(). "</a>\n";
echo " <li><i class='fa fa-li fa-rss'></i>&nbsp;Flux GeoRSS (sans les détails) : <a href=\"". $export->rssGeoUrl(). "\">". $export->rssGeoUrl(). "</a>\n";
echo " <li><i class='fa fa-li fa-rss'></i>&nbsp;Flux GeoRSS (sans les détails) : <a href=\"". $export->georssUrl(). "\">". $export->georssUrl(). "</a>\n";
echo " <li><i class='fa fa-li fa-external-link'></i>&nbsp;Flux KML : <a href=\"". $export->KmlUrl(). "\">". $export->KmlUrl(). "</a>\n";
echo " <li><i class='fa fa-li fa-external-link'></i>&nbsp;Flux GeoJSON : <a href=\"". $export->geoJsonUrl(). "\">". $export->geoJsonUrl(). "</a>\n";
echo " <li><i class='fa fa-li fa-calendar'></i>&nbsp;Calendrier iCal : <a href=\"". $export->iCalUrl(). "\">". $export->iCalUrl(). "</a>\n";
echo " <li><i class='fa fa-li fa-google'></i>&nbsp;Google calendar : <a href=\"". $export->calGoogleUrl(). "\">". $export->calGoogleUrl(). "</a>\n";
echo " <li><i class='fa fa-li fa-code'></i>&nbsp;widget (JavaScript) : <code><a href=\"". $export->jsUrl(). "\">". $export->jsCode(). "</a></code>\n";
echo " <li><i class='fa fa-li fa-share'></i>&nbsp;web (liste dans le navigateur) : <code><a href=\"". $export->webUrl(). "\">". $export->webUrl(). "</a></code>\n";
echo " <li><i class='fa fa-li fa-share'></i>&nbsp;web (liste dans le navigateur) : <a href=\"". $export->webUrl(). "\">". $export->webUrl(). "</a>\n";
echo "</ul>\n";
echo "</fieldset>\n";
......
<?php
/*
* Copyright 2008-2017
* - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix POINT org>
* - Loic Dayot <ldayot CHEZ epnadmin POINT net>
*
* This file is part of agenda-libre-php.
*
* agenda-libre-php is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* agenda-libre-ph is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with agenda-libre-php. If not, see <http://www.gnu.org/licenses/>.
*/
$privatePage = false;
include("inc/main.inc.php");
include("inc/class.localgroup.inc.php");
include("inc/class.export.inc.php");
$localgroup_id = get_safe_integer('id', 0);
$region_id = get_safe_integer('region', 0);
$depart_id = get_safe_integer('depart', 0);
$localgroups = new localgroups($db);
if ($localgroup_id>0)
{
$localgroups->getOne($localgroup_id);
}
elseif ($depart_id>0)
{
$localgroups->getFromDepartment($depart_id);
}
elseif ($region_id>0)
{
$localgroups->getFromRegion($region_id);
}
if (count($localgroups->localgroups)==0)
{
put_header(ucfirst($adl_localgroups));
echo returnWarning("Pas de $adl_localgroups_acronym avec ce filtre");
put_footer();
exit;
}
$export = new exportEvent($db);
echo $export->geoJsonStartCalendar();
echo $localgroups->formatGeojson();
echo $export->geoJsonEndCalendar();
<?php
/*
* Copyright 2004-2017
* Copyright 2004-2018
* - Melanie Bats <melanie POINT bats CHEZ utbm POINT fr>
* - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix POINT org>
* - Loic Dayot <ldayot CHEZ epnadmin POINT net>
......@@ -341,13 +341,12 @@ class event {
echo "<form method=\"post\" name='event' action=\"{$postUrl}\">\n";
echo '<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>'.
'<script type="text/javascript" src="js/jquery-ui.min.js"></script>';
echo "<script type=\"text/javascript\" src=\"js/jquery-3.2.1.min.js\"></script>\n".
"<script type=\"text/javascript\" src=\"js/jquery-ui.min.js\"></script>";
if (file_exists("tiny_mce"))
{
?>
<script type="text/javascript" src="https://openlayers.org/api/OpenLayers.js"></script>
<!-- tinyMCE -->
<script language="javascript" type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
......@@ -356,7 +355,7 @@ class event {
mode : "textareas",
language : "fr",
theme : "advanced",
plugins : "paste,preview",
plugins : "paste", // preview
theme_advanced_buttons1 : "bold,italic,underline,separator,"+
"bullist,numlist,undo,redo,link,unlink,separator,cut,copy,"+
"paste,pastetext,pasteword,separator,code,preview",
......@@ -589,7 +588,7 @@ class event {
$title = stripslashes($this->title);
//$start = date_timestamp2humanreadable($this->start);
$end = date_timestamp2humanreadable($this->end);
//$end = date_timestamp2humanreadable($this->end);
$address = stripslashes($this->address);
$postalcode = stripslashes($this->postalcode);
$city = stripslashes($this->city);
......@@ -627,7 +626,6 @@ class event {
$result .= "<h3>Informations</h3>\n";
$result .= "<p>Site Web: <a href=\"" . $url . "\">" . $url . "</a></p>\n";
$result .= "<h3>Organisateurs</h3>";
if (count($this->localgroups)>0) {
$result .= "<p>". ucfirst($GLOBALS['adl_localgroups']). " et leur r&ocirc;le&nbsp:<ul>\n";
......@@ -946,6 +944,75 @@ class event {
return $ret;
}
function toKml()
{
// title
$start_day = onlyday_timestamp2humanreadable($this->start);
$end_day = onlyday_timestamp2humanreadable($this->end);
$name = $this->xmlentities($this->city) . " : " . $this->xmlentities($this->title);
if ($start_day == $end_day)
$name .= ", le " . $start_day;
else
$name .= ", du " . $start_day . " au " . $end_day;
// description
$link = calendar_absolute_url("showevent.php?id=". $this->id);
$description = "<a href=\"{$link}\">$link</a><br/>\n".
$this->xmlentities(substr(strip_tags($this->formatHTML()),0,128));
return <<<PARTOFKML
<Placemark>
<name>{$name}</name>
<description><![CDATA[{$description}]]></description>
<styleUrl>#eventIcon</styleUrl>
<Point>
<coordinates>{$this->latitude},{$this->longitude},0</coordinates>
</Point>
</Placemark>\n
PARTOFKML;
}
// -------------------------------------------------------------------
function toGeojson()
{
// title
$start_day = onlyday_timestamp2humanreadable($this->start);
$end_day = onlyday_timestamp2humanreadable($this->end);
$name = $this->xmlentities($this->city) . " : " . $this->xmlentities($this->title);
if ($start_day == $end_day)
$name .= ", le " . $start_day;
else
$name .= ", du " . $start_day . " au " . $end_day;
$properties = new \StdClass();
$properties->id = $this->id;
$properties->name = $name;
$properties->href = calendar_absolute_url("showevent.php?id=". $this->id);
$properties->start_time = $this->start_time;
$properties->end_time = $this->end_time;
$properties->place_name = $this->place;
$properties->address = $this->address;
$properties->city = $this->city;
$properties->postalcode = $this->postalcode;
$properties->tags = explode(" ", $this->tags);
$properties->description = $this->description;
$JSON_properties = json_encode($properties);
return <<<PARTOFGEOJSON
{ "type": "Feature",
"properties": {$JSON_properties},
"geometry": {
"type": "Point",
"coordinates": [ {$this->longitude}, {$this->latitude} ]
}
}
PARTOFGEOJSON;
}
// -------------------------------------------------------------------
function toJs()
{
return "document.write(\"".
......
<?php
/*
* Copyright 2015-2017
* Copyright 2015-2018
* - Loic Dayot <ldayot CHEZ epnadmin POINT net>
*
* This file is part of agenda-libre-php.
......@@ -192,83 +192,62 @@ class exportEvent {
return $url;
}
// RSS -------------------------------------------------------------
// -------------------------------------------------------------------
/* Prepare RSS feeds */
function RssFeed()
function rssUrl()
{
global $adl_short_title, $adl_all_region;
$region = new region($this->db);
$regionList = $region->getList();
if ($region->error)
{
echo returnError($region->message);
put_footer();
exit;
}
$return = $this->rssFeedHeader (calendar_absolute_url("rss.php?region=all"), $adl_short_title. ", ". $adl_all_region);
foreach ($regionList as $region)
{
$return .= $this->rssFeedHeader(calendar_absolute_url("rss.php?region=". $region['id']), $adl_short_title. ", " . $region['name']);
}
return $return;
return calendar_absolute_url("exportevents.php?format=rss&amp;". $this->partOfUrl());
}
// -------------------------------------------------------------------
function rssFeedHeader($href, $title)
function georssUrl()
{
return " <link rel=\"alternate\" href=\"" . $href .
"\" title=\"" . $title . "\" type=\"application/rss+xml\" />\n";
return calendar_absolute_url("exportevents.php?format=georss&amp;". $this->partOfUrl());
//return $this->rssUrl(). "&map=1";
}
// -------------------------------------------------------------------
function rssUrl()
function iCalUrl()
{
return calendar_absolute_url("rss.php?". $this->partOfUrl());
return calendar_absolute_url("exportevents.php?format=ical&amp;". $this->partOfUrl(), 'webcal:');
}
// -------------------------------------------------------------------
function rssGeoUrl()
function calGoogleUrl()
{
return $this->rssUrl(). "&map=1";
return "http://www.google.com/calendar/render?cid=".
calendar_absolute_url("exportevents.php?format=ical&amp;". $this->partOfUrl());
}
// -------------------------------------------------------------------
function iCalUrl()
function jsUrl()
{
return calendar_absolute_url("ical.php?". $this->partOfUrl(), 'webcal:');
return calendar_absolute_url("exportevents.php?format=js&amp;". $this->partOfUrl());
}
// -------------------------------------------------------------------
function calGoogleUrl()
function webUrl()
{
return "http://www.google.com/calendar/render?cid=".
calendar_absolute_url("ical.php?". $this->partOfUrl());
return calendar_absolute_url("listevents.php?". $this->partOfUrl());
}
// -------------------------------------------------------------------
function jsUrl()
function KmlUrl()
{
return calendar_absolute_url("javascript.php?region=". $this->partOfUrl());
}
function jsCode()
{
return htmlentities("<script type=\"text/javascript\" language=\"JavaScript\" src=\"".
$this->jsUrl(). "\"></script>\n");
return calendar_absolute_url("exportevents.php?format=kml&amp;". $this->partOfUrl());
}
// -------------------------------------------------------------------
function webUrl()
function geoJsonUrl()
{
return calendar_absolute_url("listevents.php?". $this->partOfUrl());
return calendar_absolute_url("exportevents.php?format=geojson&amp;". $this->partOfUrl());
}
// iCal ------------------------------------------------------------
......@@ -314,6 +293,36 @@ class exportEvent {
// RSS -------------------------------------------------------------
/* Prepare RSS feeds */
function RssFeed()
{
global $adl_short_title, $adl_all_region;
$region = new region($this->db);
$regionList = $region->getList();
if ($region->error)
{
echo returnError($region->message);
put_footer();
exit;
}
$return = $this->rssFeedHeader (calendar_absolute_url("exportevents.php?format=rss&region=all"),
$adl_short_title. ", ". $adl_all_region);
foreach ($regionList as $region)
{
$return .= $this->rssFeedHeader(calendar_absolute_url("exportevents.php?format=rss&region=".
$region['id']), $adl_short_title. ", " . $region['name']);
}
return $return;
}
// -------------------------------------------------------------------
function rssFeedHeader($href, $title)
{
return " <link rel=\"alternate\" href=\"" . $href .
"\" title=\"" . $title . "\" type=\"application/rss+xml\" />\n";
}
function rssStartCalendar()
{
global $adl_short_title, $adl_title, $adl_subtitle, $adl_url;
......@@ -368,6 +377,8 @@ class exportEvent {
return "</rdf:RDF>\n";
}
// Javascript-------------------------------------------------------
function jsStartCalendar()
{
return "document.write(\"<ul>\");\n";
......@@ -378,6 +389,72 @@ class exportEvent {
return "document.write(\"</ul>\");\n";
}
function jsCode()
{
return htmlentities("<script type=\"text/javascript\" language=\"JavaScript\" src=\"".
$this->jsUrl(). "\"></script>\n");
}
// KML -------------------------------------------------------------
function KmlStartCalendar()
{
$imageUrl = calendar_absolute_url(_themeFile('image/tux-adl.png'));
header("Content-type: text/xml; charset=utf-8");
return <<<KMLSTART
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>KML {$GLOBALS['adl_short_title']} events</name>
<open>1</open>
<description>{$GLOBALS['adl_title']} events</description>
<Style id="eventIcon">
<IconStyle>
<Icon>
<href>{$imageUrl}</href>
</Icon>
</IconStyle>
</Style>\n
KMLSTART;
}
function KmlEndCalendar()
{
return <<<KMLEND
</Document>
</kml>
KMLEND;
}
// geoJSON ---------------------------------------------------------
function geoJsonStartCalendar()
{
header("Content-Type: application/json; charset=utf-8");
return <<<GEOJSONSTART
{ "type": "FeatureCollection",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [
GEOJSONSTART;
}
function geoJsonEndCalendar()
{
return "\n ]\n}\n";
}
// -----------------------------------------------------------------
// Function to choose daylimit (int)
// $daylimit is (int) or 0 for no limit
// output if HTML string select part of form
......
......@@ -205,7 +205,7 @@ function menu_html()
$r .= "<a class='list-group-item' href=\"index.php\"><i class='fa fa-calendar'></i>&nbsp;Consulter l'agenda</a>";
$r .= " - <a class='list-group-item' href=\"map.php\"><i class='fa fa-map-marker'></i>&nbsp;Carte</a>";
$r .= " - <a class='list-group-item' href=\"tags.php\"><i class='fa fa-tags'></i>&nbsp;Mots-clés</a>";
$r .= " - <a class='list-group-item' href=\"exportlist.php\"><i class='fa fa-external-link'></i>&nbsp;Exporter RSS-iCal-widget</a>";
$r .= " - <a class='list-group-item' href=\"exportlist.php\"><i class='fa fa-external-link'></i>&nbsp;Exporter</a>";
$r .= "<br/><a class='list-group-item' href=\"stats.php\"><i class='fa fa-signal'></i>&nbsp;Statistiques</a>";
$r .= " - <a class='list-group-item' href=\"infos.php\"><i class='fa fa-info'></i>&nbsp;À propos</a>";
$r .= " - <a class='list-group-item' href=\"contact.php\"><i class='fa fa-envelope'></i>&nbsp;Contact</a>";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment