Add rss export in agenda module
This commit is contained in:
parent
1336a3cd41
commit
cbfcd1c7e8
@ -545,13 +545,13 @@ class ActionComm
|
||||
\param filters Array of filters
|
||||
\return int <0 if error, nb of events in new file if ok
|
||||
*/
|
||||
function build_calfile($format,$type,$cachedelay,$filename,$filters)
|
||||
function build_exportfile($format,$type,$cachedelay,$filename,$filters)
|
||||
{
|
||||
global $conf,$langs,$dolibarr_main_url_root;
|
||||
|
||||
require_once (DOL_DOCUMENT_ROOT ."/lib/xcal.lib.php");
|
||||
|
||||
dolibarr_syslog("ActionComm::build_calfile Build cal file format=".$format.", type=".$type.", cachedelay=".$cachedelay.", filename=".$filename.", filters size=".sizeof($filters), LOG_DEBUG);
|
||||
dolibarr_syslog("ActionComm::build_exportfile Build export file format=".$format.", type=".$type.", cachedelay=".$cachedelay.", filename=".$filename.", filters size=".sizeof($filters), LOG_DEBUG);
|
||||
|
||||
// Check parameters
|
||||
if (empty($format)) return -1;
|
||||
@ -602,7 +602,7 @@ class ActionComm
|
||||
}
|
||||
$sql.= " ORDER by datec";
|
||||
|
||||
dolibarr_syslog("ActionComm::build_vcal select events sql=".$sql);
|
||||
dolibarr_syslog("ActionComm::build_exportfile select events sql=".$sql);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
@ -641,14 +641,16 @@ class ActionComm
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dolibarr_syslog("ActionComm::build_calfile ".$this->db->lasterror(), LOG_ERR);
|
||||
dolibarr_syslog("ActionComm::build_exportfile ".$this->db->lasterror(), LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Write file
|
||||
$title='Dolibarr actions';
|
||||
$desc='List of actions - built by Dolibarr';
|
||||
$result=build_calfile($format,$title,$desc,$eventarray,$outputfile);
|
||||
if ($format == 'ical') $result=build_calfile($format,$title,$desc,$eventarray,$outputfile);
|
||||
if ($format == 'vcal') $result=build_calfile($format,$title,$desc,$eventarray,$outputfile);
|
||||
if ($format == 'rss') $result=build_rssfile($format,$title,$desc,$eventarray,$outputfile);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
@ -118,6 +118,9 @@ $message.=$langs->trans("WebCalUrlForVCalExport",'vcal',$urlvcal);
|
||||
$message.='<br>';
|
||||
$urlical='<a href="'.DOL_URL_ROOT.'/comm/action/agendaexport.php?format=ical&type=event&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY):'...').'" target="_blank">'.$urlwithouturlroot.DOL_URL_ROOT.'/comm/action/agendaexport.php?format=ical&type=event&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY):'KEYNOTDEFINED').'</a>';
|
||||
$message.=$langs->trans("WebCalUrlForVCalExport",'ical',$urlical);
|
||||
$message.='<br>';
|
||||
$urlrss='<a href="'.DOL_URL_ROOT.'/comm/action/agendaexport.php?format=rss&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY):'...').'" target="_blank">'.$urlwithouturlroot.DOL_URL_ROOT.'/comm/action/agendaexport.php?format=rss&exportkey='.($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY?urlencode($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY):'KEYNOTDEFINED').'</a>';
|
||||
$message.=$langs->trans("WebCalUrlForVCalExport",'rss',$urlrss);
|
||||
print info_admin($message);
|
||||
|
||||
$db->close();
|
||||
|
||||
@ -29,6 +29,18 @@ require("../../master.inc.php");
|
||||
require_once(DOL_DOCUMENT_ROOT.'/actioncomm.class.php');
|
||||
|
||||
|
||||
$mainmenu=isset($_GET["mainmenu"])?$_GET["mainmenu"]:"";
|
||||
$leftmenu=isset($_GET["leftmenu"])?$_GET["leftmenu"]:"";
|
||||
|
||||
// Define format, type and filter
|
||||
$format='ical';
|
||||
$type='event';
|
||||
if (! empty($_GET["format"])) $format=$_GET["format"];
|
||||
if (! empty($_GET["type"])) $type=$_GET["type"];
|
||||
$filters=array();
|
||||
if (! empty($_GET["year"])) $filters['year']=$_GET["year"];
|
||||
if (! empty($_GET["idaction"])) $filters['idaction']=$_GET["idaction"];
|
||||
|
||||
// C'est un wrapper, donc header vierge
|
||||
function llxHeader() { print '<html><title>Export agenda cal</title><body>'; }
|
||||
function llxFooter() { print '</body></html>'; }
|
||||
@ -37,6 +49,7 @@ function llxFooter() { print '</body></html>'; }
|
||||
if (! $conf->agenda->enabled)
|
||||
accessforbidden();
|
||||
|
||||
|
||||
// Check config
|
||||
if (empty($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY))
|
||||
{
|
||||
@ -48,18 +61,22 @@ if (empty($conf->global->MAIN_AGENDA_XCAL_EXPORTKEY))
|
||||
exit;
|
||||
}
|
||||
|
||||
// Check exportkey
|
||||
if (empty($_GET["exportkey"]) || $conf->global->MAIN_AGENDA_XCAL_EXPORTKEY != $_GET["exportkey"])
|
||||
{
|
||||
$user->getrights();
|
||||
|
||||
$mainmenu=isset($_GET["mainmenu"])?$_GET["mainmenu"]:"";
|
||||
$leftmenu=isset($_GET["leftmenu"])?$_GET["leftmenu"]:"";
|
||||
llxHeader();
|
||||
print '<div class="error">Bad value for key.</div>';
|
||||
llxFooter('$Date$ - $Revision$');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Define format, type, filename and filter
|
||||
$format='ical';
|
||||
$type='event';
|
||||
// Define filename
|
||||
$filename='';
|
||||
if (! empty($_GET["format"])) $format=$_GET["format"];
|
||||
if ($format == 'vcal') $filename='dolibarrcalendar.vcs';
|
||||
if ($format == 'ical') $filename='dolibarrcalendar.ics';
|
||||
if (! empty($_GET["type"])) $type=$_GET["type"];
|
||||
if ($format == 'rss') $filename='dolibarrcalendar.rss';
|
||||
// Check filename
|
||||
if (! $filename)
|
||||
{
|
||||
@ -70,18 +87,16 @@ if (! $filename)
|
||||
llxFooter('$Date$ - $Revision$');
|
||||
exit;
|
||||
}
|
||||
// Check exportkey
|
||||
// \TODO
|
||||
$filters=array();
|
||||
if (! empty($_GET["year"])) $filters['year']=$_GET["year"];
|
||||
if (! empty($_GET["idaction"])) $filters['idaction']=$_GET["idaction"];
|
||||
|
||||
|
||||
$agenda=new ActionComm($db);
|
||||
|
||||
// Build file
|
||||
$result=$agenda->build_calfile($format,$type,0,$filename,$filters);
|
||||
if ($result >= 0)
|
||||
if ($format == 'ical' || $format == 'vcal')
|
||||
{
|
||||
$result=$agenda->build_exportfile($format,$type,0,$filename,$filters);
|
||||
if ($result >= 0)
|
||||
{
|
||||
$encoding='UTF-8';
|
||||
$attachment = true;
|
||||
$type='text/calendar';
|
||||
@ -101,10 +116,41 @@ if ($result >= 0)
|
||||
$result=readfile($outputfile);
|
||||
if (! $result) print 'File '.$outputfile.' was empty.';
|
||||
|
||||
// header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
|
||||
// header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if ($format == 'rss')
|
||||
{
|
||||
$result=$agenda->build_exportfile($format,$type,0,$filename,$filters);
|
||||
if ($result >= 0)
|
||||
{
|
||||
$encoding='iso-8859-1';
|
||||
$attachment = false;
|
||||
$type='application/rss+xml';
|
||||
//$type='text/plain'; // OK
|
||||
//$attachment = false; // OK
|
||||
|
||||
if ($encoding) header('Content-Encoding: '.$encoding);
|
||||
if ($type) header('Content-Type: '.$type);
|
||||
if ($attachment) header('Content-Disposition: attachment; filename="'.$filename.'"');
|
||||
|
||||
// Ajout directives pour resoudre bug IE
|
||||
//header('Cache-Control: Public, must-revalidate');
|
||||
//header('Pragma: public');
|
||||
|
||||
// Clean parameters
|
||||
$outputfile=$conf->agenda->dir_temp.'/'.$filename;
|
||||
$result=readfile($outputfile);
|
||||
if (! $result) print 'File '.$outputfile.' was empty.';
|
||||
|
||||
// header("Location: ".DOL_URL_ROOT.'/document.php?modulepart=agenda&file='.urlencode($filename));
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
llxHeader();
|
||||
print '<div class="error">'.$agenda->error.'</div>';
|
||||
llxFooter('$Date$ - $Revision$');
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
*/
|
||||
function build_calfile($format='vcal',$title,$desc,$events_array,$outputfile,$filter='')
|
||||
{
|
||||
dolibarr_syslog("xcal.lib.php::build_cal_file Build cal file ".$outputfile." to format ".$format);
|
||||
dolibarr_syslog("xcal.lib.php::build_calfile Build cal file ".$outputfile." to format ".$format);
|
||||
|
||||
if (empty($outputfile)) return -1;
|
||||
|
||||
@ -204,6 +204,122 @@ function build_calfile($format='vcal',$title,$desc,$events_array,$outputfile,$fi
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Build a file from an array of events
|
||||
\param format 'rss'
|
||||
\param title Title of export
|
||||
\param desc Description of export
|
||||
\param events_array Array of events ('eid','startdate','duration','enddate','title','summary','category','email','url','desc','author')
|
||||
\param outputfile Output file
|
||||
\param filter Filter
|
||||
\return int <0 if ko, Nb of events in file if ok
|
||||
*/
|
||||
function build_rssfile($format='rss',$title,$desc,$events_array,$outputfile,$filter='')
|
||||
{
|
||||
dolibarr_syslog("xcal.lib.php::build_rssfile Build rss file ".$outputfile." to format ".$format);
|
||||
|
||||
if (empty($outputfile)) return -1;
|
||||
|
||||
$fichier=fopen($outputfile,'w');
|
||||
if ($fichier)
|
||||
{
|
||||
$now=mktime();
|
||||
$date=date("r");
|
||||
|
||||
// Print header
|
||||
$html='<?xml version="1.0" encoding="iso-8859-1"?>';
|
||||
fwrite($fichier, $html);
|
||||
fwrite($fichier, "\n");
|
||||
$html='<rss version="2.0">';
|
||||
fwrite($fichier, $html);
|
||||
fwrite($fichier, "\n");
|
||||
|
||||
$html="<channel>".
|
||||
"\n".
|
||||
"<title>".$title."</title>";
|
||||
fwrite($fichier, $html);
|
||||
fwrite($fichier, "\n");
|
||||
|
||||
$html='<description><![CDATA['.$desc.'.]]></description>'.
|
||||
// '<language>fr</language>'.
|
||||
'<copyright>Dolibarr</copyright>'.
|
||||
'<lastBuildDate>'.$date.'</lastBuildDate>'.
|
||||
'<generator>Dolibarr</generator>'.
|
||||
'<link><![CDATA['.$_SERVER["PHP_SELF"].']]></link>';
|
||||
// '<image>'.
|
||||
// '<url><![CDATA[http://www.lesbonnesannonces.com/images/logo_rss.gif]]></url>'.
|
||||
// '<title><![CDATA[Dolibarr events]]></title>'.
|
||||
// '<link><![CDATA[http://www.lesbonnesannonces.com/]]></link>'.
|
||||
// '<width>144</width>'.
|
||||
// '<height>36</height>'.
|
||||
// '</image>'."\n";
|
||||
|
||||
#print $html;
|
||||
fwrite($fichier, $html);
|
||||
|
||||
|
||||
foreach ($events_array as $date => $event)
|
||||
{
|
||||
$eventqualified=true;
|
||||
if ($filter)
|
||||
{
|
||||
// \TODO Add a filter
|
||||
|
||||
$eventqualified=false;
|
||||
}
|
||||
|
||||
if ($eventqualified)
|
||||
{
|
||||
//$uid = dolibarr_print_date($now,'dayhourxcard').'-'.$event['uid']."-export@".$_SERVER["SERVER_NAME"];
|
||||
$uid = $event['uid'];
|
||||
$type = $event['type'];
|
||||
$startdate = $event['startdate'];
|
||||
$duration = $event['duration'];
|
||||
$enddate = $event['enddate'];
|
||||
$summary = $event['summary'];
|
||||
$category = $event['category'];
|
||||
$location = $event['location'];
|
||||
$email = $event['email'];
|
||||
$url = $event['url'];
|
||||
$transparency = $event['transparency'];
|
||||
$description=eregi_replace('<br[ \/]?>',"\n",$event['desc']);
|
||||
$description=clean_html($description,0); // Remove html tags
|
||||
|
||||
|
||||
fwrite ($fichier, "<item>");
|
||||
fwrite ($fichier, "\n");
|
||||
fwrite ($fichier, "<title><![CDATA[".$summary."]]></title>");
|
||||
fwrite ($fichier, "\n");
|
||||
fwrite ($fichier, "<link><![CDATA[".$url."]]></link>");
|
||||
fwrite ($fichier, "\n");
|
||||
fwrite ($fichier, "<description><![CDATA[");
|
||||
if ($description) fwrite ($fichier, $description);
|
||||
//else fwrite ($fichier, 'NoDesc');
|
||||
fwrite ($fichier, "]]></description>");
|
||||
fwrite ($fichier, "\n");
|
||||
fwrite ($fichier, "<pubDate>".date("r", $startdate)."</pubDate>");
|
||||
fwrite ($fichier, "\n");
|
||||
fwrite ($fichier, '<guid isPermaLink="true"><![CDATA[');
|
||||
// http://www.lesbonnesannonces.com/index_categ.php?origine=&id_categ='.$id_categ.
|
||||
fwrite ($fichier, $url);
|
||||
fwrite ($fichier, ']]></guid>');
|
||||
fwrite ($fichier, "\n");
|
||||
fwrite ($fichier, "</item>");
|
||||
fwrite ($fichier, "\n");
|
||||
|
||||
//chmod($fichierout, 0664);
|
||||
}
|
||||
}
|
||||
|
||||
fwrite($fichier, '</channel>');
|
||||
fwrite ($fichier, "\n");
|
||||
fwrite($fichier, '</rss>');
|
||||
|
||||
fclose($fichier);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function format_cal($format,$string)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user