//
// This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike License. //
// To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/1.0/ //
// or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. //
// Francais (brouillon): http://creativecommons.org/projects/international/fr/translated-license //
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Gestion des feeds RSS
// v0.2.1
class RSS
{
var $chemin = "datas/";
var $err = array(
"stop" => "oui",
"log" => "oui",
"debug" => "oui");
// Gestion des erreurs
function _err($err,$debug="") {
// Si le debug est activé
if($this->err['debug'] == "oui" && !empty($debug)) $err.= "\n// DEBUG //\n".$debug;
// Si on log les erreurs
if($this->err['log'] == "oui") $this->erreurs[] = $err;
// Si on s'arrête sur les erreurs
if($this->err['stop'] == "oui") {
echo "
".htmlentities(stripslashes($err))."
";
exit;
}
$this->erreur = $err;
return FALSE;
}
function _date($date)
{
return gmdate('Y-m-d\TH:i\Z', $date);
#return date('r',$date);
}
// Début du fil RSS 1.0 (+modules Dublin Core + Content)
function _header($titre,$url,$texte,$date,$items,$lang="fr")
{
$description = strip_tags($texte);
$description = strtr($description,array("\n"=>" ","\r"=>""));
$description = eregi_replace("[ ]{2,}"," ",$description);
$description = html_entity_decode($description);
$head = "\n";
$head.= "\n\n";
$head.= "\n";
$head.= " ".htmlspecialchars(stripslashes($titre))."\n";
$head.= " ".$url."\n";
$head.= " ".htmlspecialchars(stripslashes($description))."\n";
$head.= " ".$lang."\n";
$head.= " ".$this->_date($date)."\n";
$head.= " \n";
$head.= " \n".$items."\n \n \n";
$head.= "\n\n";
return $head;
}
function _items($url)
{
$out = " \n";
return $out;
}
function _item($url,$titre,$texte="",$dublinCore=array())
{
$description = strip_tags($texte);
$description = strtr($description,array("\n"=>" ","\r"=>""));
$description = eregi_replace("[ ]{2,}"," ",$description);
$description = html_entity_decode($description);
if(strlen($description) > 600)
{
$description = substr($description,0,600);
$pos = strrpos($description,".");
$description = substr($description,0,$pos+1);
}
$out = "\n";
$out.= " ".$url."\n";
$out.= " ".htmlspecialchars(stripslashes($titre))."\n";
$out.= " ".htmlspecialchars($description)."\n";
if(strstr($texte,"<"))
{
$baseUrl = ereg_replace("^(http://[a-z0-9.-]+/).*$","\\1",$url);
$texte = str_replace('\n";
$out.= " \n";
$out.= " \n";
}
if(count($dublinCore) > 0)
{
foreach($dublinCore as $tag=>$value)
{
if($tag == "date") $value = $this->_date($value);
$out.= " ".htmlspecialchars(stripslashes($value))."\n";
}
}
$out.= "\n\n";
return $out;
}
function _footer()
{
$foot = "\n\n\n";
return $foot;
}
function _get_ecrit_url($journal,$ecrit,$date,$name="")
{
if(!empty($name)) $last = $name;
else $last = $ecrit;
$url = str_replace("[ID]",$journal,$GLOBALS['cfg']['url_tpl']).date("Y/m/d/",$date).$last;
return $url;
}
function _get_forum_url($journal,$id,$date,$name="")
{
if(!empty($name)) $last = $name;
else $last = $id;
$url = str_replace("[ID]",$journal,$GLOBALS['cfg']['url_tpl'])."forum/".date("Y/m/d/",$date).$last;
return $url;
}
function derniers_ecrits($limit="")
{
if(empty($limit)) $limit = 20;
$req = 'SELECT e.id,e.uri,e.date,e.titre,e.journal,j.titre AS jtitre, h.texte AS texte_html FROM ecrits AS e,
journaux AS j, ecrits_html AS h WHERE e.journal=j.id AND e.id=h.id
AND e.statut != "prive" AND e.valide="oui" AND j.statut IN ("collectif","public") ORDER BY e.date DESC LIMIT 0,'.$limit;
$res = mysql_query($req);
if(!$res)
return $this->_err("Problème technique.",$req."\n--> ".mysql_error());
while($rec = mysql_fetch_assoc($res))
{
if(!$pubdate) $pubdate = $rec['date'];
$url = id2url($rec['journal']).$rec['uri'];
$items.= $this->_items($url);
$out.= $this->_item($url,$rec['titre'],$rec['texte_html'],
array("date"=>$rec['date'], "author"=>$rec['jtitre'], "source"=>id2url($rec['journal'])));
}
$out2 = $this->_header($GLOBALS['cfg']['titre'],$GLOBALS['cfg']['url'],"Derniers écrits sur les journaux publics.",$pubdate,$items)
.$out.$this->_footer();
return $out2;
}
function journal_ecrits($journal)
{
$limit = 20;
$req = 'SELECT e.id,e.uri,e.date,e.titre,e.journal,j.titre AS jtitre, j.texte AS jtexte, h.texte AS texte_html
FROM ecrits AS e, journaux AS j, ecrits_html AS h WHERE e.journal=j.id AND e.id=h.id
AND (e.statut = "normal" OR e.statut="haut") AND j.id="'.$journal.'" ORDER BY e.date DESC LIMIT 0,'.$limit;
$res = mysql_query($req);
if(!$res)
return $this->_err("Problème technique.",$req."\n--> ".mysql_error());
while($rec = mysql_fetch_assoc($res))
{
if(!$pubdate) $pubdate = $rec['date'];
if(!$jtexte) $jtexte = $rec['jtexte'];
if(!$jtitre) $jtitre = $rec['jtitre'];
$url = id2url($rec['journal']).$rec['uri'];
$items.= $this->_items($url);
$out.= $this->_item($url,$rec['titre'],$rec['texte_html'],
array("date"=>$rec['date'], "author"=>$rec['jtitre'], "source"=>id2url($rec['journal'])));
}
$out2 = $this->_header($jtitre,id2url($journal),$this->$jtexte,$pubdate,$items).$out.$this->_footer();
return $out2;
}
function derniers_forums($limit="")
{
if(empty($limit)) $limit = 20;
$req = 'SELECT f.id,f.uri,f.date,f.titre,f.journal,j.titre AS jtitre,f.tempo,f.reponses,t.texte FROM forums AS f, journaux AS j, '.
"forums_textes AS t WHERE f.journal=j.id AND f.id=t.id AND f.status='online' AND f.parent='0' AND j.statut IN
('collectif','public') ORDER BY f.tempo DESC LIMIT 0,".$limit;
$res = mysql_query($req);
if(!$res)
return $this->_err("Problème technique.",$req."\n--> ".mysql_error());
while($rec = mysql_fetch_assoc($res))
{
if(!$pubdate) $pubdate = $rec['date'];
$url = id2url($rec['journal'])."forum/".$rec['uri'];
$texte = $rec['texte'];
$items.= $this->_items($url);
$out.= $this->_item($url,$rec['titre'],$texte,
array("date"=>$rec['date'],"author"=>$rec['jtitre'],"source"=>id2url($rec['journal'])."forum/"));
}
$out2 = $this->_header($GLOBALS['cfg']['titre'],$GLOBALS['cfg']['url'],"Derniers messages sur les forums des journaux publics.",
$pubdate,$items).$out.$this->_footer();
return $out2;
}
function stats()
{
$champs = array("membres","journaux","ecrits","forums","messages");
foreach($champs as $el)
{
$req = 'SELECT COUNT(id) FROM '.$el;
$res = mysql_query($req);
if(!$res)
return $this->_err("Problème technique.",$req."\n--> ".mysql_error());
$rec = mysql_fetch_row($res);
$out2.= $this->_item(id2url("public")."stats.php/view/".$el,ucfirst($el),$rec[0]);
mysql_free_result($res);
}
$out = $this->_header($GLOBALS['cfg']['titre'],$GLOBALS['cfg']['url'],"Statistiques globales",time()).$out2.$this->_footer();
return $out;
}
function liste_journaux()
{
$res = mysql_query("SELECT id,titre,texte,dernier FROM journaux WHERE statut IN ('public','collectif') ORDER BY titre");
while($rec = mysql_fetch_assoc($res))
{
$texte = strip_tags($rec['texte']);
$out2.= $this->_item(id2url($rec['id']),$rec['titre'],$texte,array("date"=>$rec['dernier']));
}
$out = $this->_header($GLOBALS['cfg']['titre'],$GLOBALS['cfg']['url'],"Liste des journaux publics",time()).$out2.$this->_footer();
return $out;
}
}
?>