Commit f406a52a authored by Loïc DAYOT's avatar Loïc DAYOT Committed by Ploc
Browse files

feat(): improvement filter and export events

Export list can be filtered on localgroup.
Generalize filter methods : fieldnames in select form and functions.
Add export to a classical html web page.
Generalize exported URL construction with filters.

Fix javascript call when MCE is not present.

Map now filtered on tags and daylimit.

Description field in RSS truncked.

close #25
parent 1bb6a6bb
......@@ -94,9 +94,6 @@ $adl_notenough_message = "Votre évènement a tout à fait sa place dans l'Agend
$adl_double_message = "L'évènement que vous proposez est déjà présent dans ".
"l'Agenda.\n\n";
// rss.php
$adl_url = "http://localhost";
// exportlist.php
$adl_export_intro = "<p>Chaque flux RSS liste les évènements pour les 30 prochains jours en cours dans une région donnée. En vous abonnant à un flux régional, vous recevrez des informations sur les évènements à portée locale, mais également sur les évènements à portée nationale et internationale.</p>";
$adl_rss_more = "<p>Quelques fonctionnalités intéressantes des flux RSS&nbsp;:</p>\n".
......
<?php
/*
* Copyright 2015
* Copyright 2015-2017
* - Loic Dayot <ldayot CHEZ epnadmin POINT net>
*
* This file is part of agenda-libre-php.
......@@ -35,18 +35,10 @@ $tagsE = array();
echo "<fieldset><legend>". _("Sélection"). "</legend>";
$export = new exportEvent($db);
$export->get2fields();
// Get tags from form
$export->getTagList('tags');
// Get tags ===
$aTags = (isset($_GET['tags']) ? $_GET['tags'] : array());
foreach ($aTags as $tags)
if (is_array($tags))
foreach ($tags as $tag)
$export->tags[] = $tag;
else
$export->tags[] = $tags;
$export->region = get_safe_integer('region', 'all');
$export->daylimit = get_safe_integer('daylimit', 30);
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";
......@@ -54,6 +46,7 @@ echo " <li><i class='fa fa-li fa-rss'></i>&nbsp;Flux GeoRSS (sans les détails)
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 "</ul>\n";
echo "</fieldset>\n";
......@@ -61,7 +54,6 @@ echo "</fieldset>\n";
echo "<form action=\"\" method=\"get\" enctype=\"multipart/form-data\">\n";
echo "<fieldset><legend>". _("Critères de sélection"). "</legend>";
// Select place
// Select place
$region = new region($db);
echo "<strong>". _("Région :") ."</strong> ". $region->selectHTML($export->region). " ";
......@@ -73,15 +65,18 @@ echo $export->selectDurationHTML($export->daylimit). " ";
$tagsHtml = new tagsHtml($db);
echo $tagsHtml->selectTagsHTML($export->tags);
// Select localgroup
$localgroups = new localgroups($db);
$localgroups->localgroup_id = $export->localgroup_id;
echo "<p>". $localgroups->selectHTML('localgroup'). "</p>\n";
echo " <input type=\"submit\" name=\"submit\" value=\"". _("Mettre à jour la sélection"). "\" /> <input type=\"reset\" name=\"reset\" value=\"". _("Réinitialiser"). "\" />\n";
echo "</fieldset>";
echo "</form>\n";
echo "<hr>\n";
echo $adl_rss_more;
echo "<hr>\n";
?>
......
<?php
/*
* Copyright 2004-2015
* Copyright 2004-2017
* - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix POINT org>
* - Loic Dayot <ldayot CHEZ epnadmin POINT net>
*
......@@ -27,12 +27,7 @@ include("inc/main.inc.php");
include("inc/class.export.inc.php");
$eventList = new exportEvent($db);
$eventList->event_id = get_safe_integer('id', 0);
$eventList->region = get_safe_integer('region', 'all');;
$eventList->count = get_safe_integer('count', 10);
$eventList->daylimit = get_safe_integer('daylimit', 30);
$tag = get_safe_string('tag', '');
$eventList->tags = ($tag>'' ? explode(' ', $tag) : array());
$eventList->get2fields();
$list = $eventList->getEventsList();
if ($list == FALSE)
......
......@@ -341,11 +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>';
if (file_exists("tiny_mce"))
{
?>
<script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="js/jquery-ui.min.js"></script>
<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>
......@@ -930,10 +931,9 @@ class event {
$ret .= " <dc:date>" . $evt_date . $evt_timezone . "</dc:date>\n";
if ($this->longitude && $this->latitude)
$ret .= " <georss:point>" . $this->latitude . " " . $this->longitude . "</georss:point>\n";
$ret .= " <description>\n";
$ret .= $this->xmlentities(strip_tags($this->formatHTML()));
$ret .= " <description>\n";
$ret .= $this->xmlentities($map ? substr(strip_tags($this->formatHTML()),0,128) : strip_tags($this->formatHTML()));
$ret .= " </description>\n";
if (! $map)
{
......
<?php
/*
* Copyright 2015
* Copyright 2015-2017
* - Loic Dayot <ldayot CHEZ epnadmin POINT net>
*
* This file is part of agenda-libre-php.
......@@ -29,14 +29,15 @@ class exportEvent {
$count, // nombre d'événement
$tags, // tableau des tags
$past, // boolean true si dans le passé
$event_id; // 0 ou un numero ID d'evenement
$event_id, // 0 ou un numero ID d'evenement
$localgroup_id; // 0 ou un numero ID de groupe local
var $event; // objet event
var $error, $message;
var $db;
// -------------------------------------------------------------------
function exportEvent($db)
function __construct($db)
{
$this->region = "all";
$this->delay = 0;
......@@ -57,59 +58,104 @@ class exportEvent {
function getEventsList()
{
if ($this->past)
$sql = "SELECT events.id AS id FROM {$GLOBALS['db_tablename_prefix']}events AS events";
$sqlWhere = " WHERE (moderated=1)";
// event_id
if ($this->event_id != 0)
{
if ($this->daylimit !=0)
$start = time() - ($this->daylimit * 24 * 60 * 60);
$end = time();
$sqlWhere .= " AND (events.id=". $this->db->quote_smart($this->event_id). ")";
$sql .= $sqlWhere;
}
else
{
$start = time();
if ($this->daylimit !=0)
$end = time() + ($this->daylimit * 24 * 60 * 60);
}
$sql = "SELECT events.id as id FROM {$GLOBALS['db_tablename_prefix']}events AS events";
$sqlWhere = " WHERE (moderated=1)";
if (isset($start))
$sqlWhere .= " AND (end_time >= '" . date_timestamp2mysql($start) . "') ";
if (isset($end))
$sqlWhere .= " AND (start_time <= '" . date_timestamp2mysql($end) . "')";
// past/future and daylimit
if ($this->past)
{
if ($this->daylimit !=0)
$start = time() - ($this->daylimit * 24 * 60 * 60);
$end = time();
}
else
{
$start = time();
if ($this->daylimit !=0)
$end = time() + ($this->daylimit * 24 * 60 * 60);
}
if (isset($start))
$sqlWhere .= " AND (end_time >= '" . date_timestamp2mysql($start) . "') ";
if (isset($end))
$sqlWhere .= " AND (start_time <= '" . date_timestamp2mysql($end) . "')";
// tags
if (count($this->tags)>0)
foreach ($this->tags as $categoryId=>$tag)
{
$sqlWhere .= " AND '{$tag}' IN (SELECT name FROM {$GLOBALS['db_tablename_prefix']}tags AS tags".
" LEFT JOIN {$GLOBALS['db_tablename_prefix']}tags_events AS te ON te.tag_id=tags.id WHERE te.event_id=events.id)";
}
// region
if ($this->region != "all")
$sqlWhere .= " AND ((region=" . $this->db->quote_smart($this->region) . ") OR (locality>=1))";
// localgroup_id
if ($this->localgroup_id != 0)
{
$sql .= " LEFT JOIN {$GLOBALS['db_tablename_prefix']}localgroups_events AS le ON events.id=le.event_id";
$sqlWhere .= " AND (localgroup_id=". $this->db->quote_smart($this->localgroup_id). ")";
}
if (count($this->tags)>0)
foreach ($this->tags as $categoryId=>$tag)
{
$sqlWhere .= " AND '{$tag}' IN (SELECT name FROM {$GLOBALS['db_tablename_prefix']}tags AS tags".
" LEFT JOIN {$GLOBALS['db_tablename_prefix']}tags_events AS te ON te.tag_id=tags.id WHERE te.event_id=events.id)";
$sql .= $sqlWhere;
if (count($this->tags)>0 || $this->localgroup_id != 0)
$sql .= " GROUP BY events.id";
// past/future
$sql .= " ORDER BY start_time ". ($this->past ? "DESC" : "ASC");
// count
if ($this->count > 0)
$sql .= " LIMIT ". $this->count;
}
if ($this->region != "all")
$sqlWhere .= " AND ((region=" . $this->db->quote_smart($this->region) . ") OR (locality>=1))";
if ($this->event_id != 0)
$sqlWhere .= " AND (events.id=". $this->db->quote_smart($this->event_id). ")";
$sql .= $sqlWhere;
if (count($this->tags)>0)
$sql .= " GROUP BY events.id";
$sql .= " ORDER BY start_time ". ($this->past ? "DESC" : "ASC");
//var_dump($sql);
return $this->db->query($sql);
}
function get2fields($get)
function get2fields()
{
$this->map = get_safe_integer('map', 0);
$this->region = get_safe_integer('region', 'all');
$this->count = get_safe_integer('count', 10);
$this->daylimit = get_safe_integer('daylimit', 30);
$this->event_id = get_safe_integer('event_id', 0);
$this->localgroup_id = get_safe_integer('localgroup_id', 0);
$this->getTagList('tag');
}
function getTagList($fieldName)
{
// Get tags ===
$aTags = (isset($_GET[$fieldName]) ? $_GET[$fieldName] : array());
if (!is_array($aTags))
{
$aTags = explode(' ', $aTags);
}
foreach ($aTags as $tags)
{
if (is_array($tags))
{
foreach ($tags as $tag)
{
$this->tags[] = $tag;
}
}
else
{
$this->tags[] = $tags;
}
}
return;
}
// -------------------------------------------------------------------
private function partOfUrl()
{
// tags
$urltags = "";
$aTags = $this->tags;
foreach ($aTags as $tags)
......@@ -130,11 +176,19 @@ class exportEvent {
}
if ($urltags>"")
$urltags = "&tag=". $urltags;
$url = "region=". $this->region.
($this->daylimit!=30 && isset($_GET["daylimit"]) ? "&daylimit=". $_GET["daylimit"] : "").
$urltags;
// region
$url = "region=". $this->region;
// delay
if (($this->daylimit!=30))
$url .= "&daylimit=". $this->daylimit;
// localgroup
if ($this->localgroup_id>0)
$url .= "&localgroup_id=". $this->localgroup_id;
// event
if ($this->event_id>0)
$url .= "&event_id=". $this->event_id;
$url .= $urltags;
return $url;
}
......@@ -210,6 +264,13 @@ class exportEvent {
$this->jsUrl(). "\"></script>\n");
}
// -------------------------------------------------------------------
function webUrl()
{
return calendar_absolute_url("listevents.php?". $this->partOfUrl());
}
// iCal ------------------------------------------------------------
function icalStartCalendar()
......@@ -275,12 +336,12 @@ class exportEvent {
$ret .= " <title>". $adl_short_title;
if ($this->region != "all")
{
$regionName = region_find($db, $this->region);
$ret .= " [ " . $regionName . " ]";
$region = new region($this->db, $this->region);
$ret .= " [ " . $region->name . " ]";
}
$ret .= "</title>\n".
" <description>". $adl_title." ".$adl_subtitle. "</description>\n".
" <link>{$adl_url}</link>\n".
" <link>". calendar_absolute_url(). "</link>\n".
" <dc:language>fr</dc:language>\n".
" <dc:creator>AgendaDuLibre.org</dc:creator>\n";
......
......@@ -1197,4 +1197,35 @@ class localgroups {
return json_encode($vals);
}
// -----------------------------------------------------------------
// Present part of form to choose one localgroup
function selectHTML()
{
$html = "";
$html .= "<script type='text/javascript' src='js/jquery-3.2.1.min.js'></script>\n";
$html .= "<script type='text/javascript' src='js/jquery-ui.min.js'></script>\n";
$html .= "<script type='text/javascript' src='js/findLocalgroup.js'></script>\n";
$html .= "<strong>". ucfirst($GLOBALS['adl_localgroup']). " :</strong> ";
if ($this->localgroup_id>0)
{
$this->get();
reset($this->localgroups);
$localgroup = current($this->localgroups);
}
$html .="<span id='lg-container'>
<input type='text' placeholder=\"Saisir une partie du nom du {$GLOBALS['adl_localgroup']}\"
id='lg_name' ";
if (isset($localgroup))
{
$html .= "value='{$localgroup->name} ({$localgroup->department})' ";
}
$html .= "/>
</span>
<span id='loading' class='loading' style='display:none;'>
<i class='fa fa-circle-o-notch fa-spin'></i></span>
<input type='hidden' name='localgroup_id' value='{$this->localgroup_id}'/>
</select>\n";
return $html;
}
}
<?php
/*
* Copyright 2008-2015
* Copyright 2008-2017
* - Loic Dayot <ldayot CHEZ epnadmin POINT net>
*
* This file is part of agenda-libre-php.
......@@ -31,11 +31,7 @@ include("inc/main.inc.php");
include("inc/class.export.inc.php");
$eventList = new exportEvent($db);
$eventList->region = get_safe_integer('region', 'all');;
$eventList->count = get_safe_integer('count', 10);
$eventList->daylimit = get_safe_integer('daylimit', 30);
$tag = get_safe_string('tag', '');
$eventList->tags = ($tag>'' ? explode(' ', $tag) : array());
$eventList->get2fields();
$list = $eventList->getEventsList();
if ($list == FALSE)
......@@ -47,8 +43,8 @@ if ($list == FALSE)
echo $eventList->jsStartCalendar();
while ($eventList->event->id = $db->getOne($list))
{
$eventList->event->get();
echo $eventList->event->toJs();
$eventList->event->get();
echo $eventList->event->toJs();
}
echo $eventList->jsEndCalendar();
......
<?php
/*
* Copyright 2007-2017
* - Mélanie Bats <melanie POINT bats CHEZ utbm POINT fr>
......@@ -52,29 +51,23 @@ function list_events($events)
echo " </ul>\n";
}
put_header("Liste d'évènements");
$hasevent = FALSE;
/* Fetch region name */
$region_num = get_safe_integer('region', 'all');
if ($region_num != "all")
$region = region_find($db, $region_num);
$eventList = new exportEvent($db);
$eventList->get2fields();
$events = $eventList->getEventsList();
if ($eventList->region != "all")
{
$region = new region($db, $eventList->region);
$region = $region->name;
}
else
$region = $adl_all_region;
$daylimit = get_safe_integer('daylimit', 0);
// Get tags ===
$tag = get_safe_string('tag', '');
$aTags = ($tag>'' ? explode(' ', $tag) : array());
echo "<h2>Les évènements <i>" . $tag . "</i></h2>\n";
$hasevent = FALSE;
put_header("Liste d'évènements");
$eventList = new exportEvent($db);
$eventList->region = $region_num;
$eventList->daylimit = $daylimit;
$eventList->tags = $aTags;
$events = $eventList->getEventsList();
echo "<h2>Les évènements $region <i>" . implode(' ', $eventList->tags) . "</i></h2>\n";
if (! $events)
{
......@@ -86,10 +79,10 @@ if (! $events)
// display exports url
echo "<div class='list-group'>Ces événements en flux ";
echo "<a class='list-group-items' href=\"". $eventList->rssUrl(). "\"><i class='fa fa-rss'></i>&nbsp;RSS</a>&nbsp; ";
echo "<a class='list-group-items' href=\"ical.php?tag=" . $tag ."\"><i class='fa fa-calendar'></i>&nbsp;iCal</a>&nbsp; ";
echo "<a class='list-group-items' href=\"javascript.php?tag=" . $tag ."\"><i class='fa fa-connectdevelop'></i>&nbsp;JavaScript</a>&nbsp; ";
echo "<a class='list-group-items' href=\"http://www.google.com/calendar/render?cid=". calendar_absolute_url("ical.php?tag=".
$tag). "\"><i class='fa fa-google'></i>&nbsp;calendrier Google</a>";
echo "<a class='list-group-items' href=\"". $eventList->icalUrl(). "\"><i class='fa fa-calendar'></i>&nbsp;iCal</a>&nbsp; ";
echo "<a class='list-group-items' href=\"". $eventList->jsUrl(). "\"><i class='fa fa-connectdevelop'></i>&nbsp;JavaScript</a>&nbsp; ";
echo "<a class='list-group-items' href=\"http://www.google.com/calendar/render?cid=".
$eventList->calGoogleUrl(). "\"><i class='fa fa-google'></i>&nbsp;calendrier Google</a>";
echo "</p>";
if ($db->numRows($events))
......@@ -133,7 +126,7 @@ if ($db->numRows($events))
}
if (! $hasevent)
echo "<p>Aucun évènement avec ce tag.</p>";
echo "<p>Aucun évènement avec ce filtre.</p>";
put_footer();
?>
......
......@@ -4,7 +4,7 @@
* Copyright 2004-2017
* - Mélanie Bats <melanie POINT bats CHEZ utbm POINT fr>
* - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix POINT org>
* - Loic Dayot <ldayot CHEZ ouvaton POINT org>
* - Loic Dayot <ldayot CHEZ epnadmin POINT net>
*
* This file is part of agenda-libre-php.
*
......@@ -23,6 +23,7 @@
*/
include("inc/main.inc.php");
include("inc/class.export.inc.php");
$jcode = "
<script src=\"https://openlayers.org/api/OpenLayers.js\"></script>
......@@ -51,7 +52,7 @@ $jcode = "
map.setCenter (lonLat, zoom);
var newl = new OpenLayers.Layer.GeoRSS('AdL', '" . calendar_absolute_url("rss.php?region=all&map=1&daylimit=0") . "');
var newl = new OpenLayers.Layer.GeoRSS('AdL', '%s');
map.addLayer(newl);
";
......@@ -71,10 +72,37 @@ $jcode .= "
</script>\n";
$export = new exportEvent($db);
$export->daylimit = get_safe_integer('daylimit', 30);
$export->getTagList('tags');
$url = $export->rssGeoUrl();
$jcode = sprintf($jcode, $url);
put_header("Carte", $jcode, "init();");
//echo $url;
echo "<h2>Carte des événements</h2>\n";
echo "<form action=\"\" method=\"get\" enctype=\"multipart/form-data\">\n";
echo "<fieldset><legend>". _("Critères de sélection"). "</legend>";
// Select duration
echo $export->selectDurationHTML($export->daylimit). " ";
// Select tags
$tagsHtml = new tagsHtml($db);
echo $tagsHtml->selectTagsHTML($export->tags);
echo " <input type=\"submit\" name=\"submit\" value=\"". _("Mettre à jour la sélection").
"\" /> <input type=\"reset\" name=\"reset\" value=\"". _("Réinitialiser"). "\" />\n";
echo "</fieldset>";
echo "</form>\n";
echo "<hr>\n";
echo "<div style=\"margin: auto; width:70%; height:600px; border: 1px solid black;\" id=\"map\"></div>\n";
put_footer();
......
<?php
/*
* Copyright 2004-2015
* Copyright 2004-2017
* - Mélanie Bats <melanie POINT bats CHEZ utbm POINT fr>
* - Thomas Petazzoni <thomas POINT petazzoni CHEZ enix POINT org>
* - Loic Dayot <ldayot CHEZ epnadmin POINT net>
......@@ -28,30 +28,12 @@ include("inc/main.inc.php");
include_once("inc/class.event.inc.php");
include_once("inc/class.export.inc.php");
$event_id = get_safe_integer('id', 0);
$eventList = new exportEvent($db);
$eventList->map = get_safe_integer('map', 0);
$eventList->get2fields();
echo $eventList->rssStartCalendar();
/* Generate item list */
if ($event_id==0)
{
$eventList->region = get_safe_integer('region', 'all');
$eventList->count = get_safe_integer('count', 10);
$eventList->daylimit = get_safe_integer('daylimit', 30);
$tag = get_safe_string('tag', '');
$eventList->tags = ($tag>'' ? explode(' ', $tag) : array());
$list = $eventList->getEventsList();
}
else
{
$sql = "SELECT events.id as id ".
"FROM {$GLOBALS['db_tablename_prefix']}events AS events ".
"WHERE id=". $db->quote_smart($event_id). " AND (moderated=1)";
$list = $db->query($sql);
}
$list = $eventList->getEventsList();
if ($list == FALSE)
{
......@@ -65,25 +47,13 @@ while ($eventList->event->id = $db->getOne($list))
}
echo $eventList->rssEndHeaderCalendar();
/* Generate items */
if ($event_id==0)
$list = $eventList->getEventsList();
else
{
$list = $db->query($sql);
}
if ($list == FALSE)
{
echo "Erreur lors de la récupération des évènements";
exit;
}
$list = $eventList->getEventsList();
while ($eventList->event->id = $db->getOne($list))
{