merci
<?php
include 'config/parametre.ini.php';
$path=dirname(__file__);
define('SMARTY_DIR_LIB',$path.'/lib/Smarty/libs');
define('DIR_ACTIONS',$path.'/Action/');
function __autoload($nom)
{
require dirname(__file__).'/lib/class/'.$nom.'.php';
}
$rss=new rss2_ab();
$rss->send();
$rss->encoding='utf-8';
$rss->lang='fr';
$mv=$rss->createrss2();
require_once(SMARTY_DIR_LIB.'/Smarty.class.php');
include 'configSmarty.php';
$Smarty = new Smarty_page();
$Smarty->assign($mv->getModel());
$Smarty->display($mv->getView());
//echo '<pre>'.print_r($mv).'</pre>';
///$rss->writreXml('actu/xml');
?>
le fichier creer apparais dans cette page sous forme xml(grace a un header)
$this-fd = fopen ($this->file, "r");
while (!feof ($this->)) {
$buffer .=$buffer.fgets($this->fd);
}
$rss=new document();
$rss->loadXML($buffer);
$rss->saveXML('actu.rss');
fclose ($this->fd);
c'est pas encore tester, je vais voir ce ca donne public function WriteXml($file)
{
$this->file=$file;
try
{
//ouverture de essai1.php
if(!($this->fp= fopen ('essai1.php', "r")))
throw new MyException('impossible d\'ouvrir le fichier');
$buffer='';//initialisation
while (!feof ($this->fp))
{
//recuperation du contenu
$buffer.=$buffer.fgets($this->fp);
}
echo $buffer;
$rss=new document();
//ecriture de la chaine xml
$rss->loadXML($buffer);
//sauve-garde du fichier
$rss->saveXML($this->file);
//fermeture de essai1.php
fclose ($this->fp);
}
catch (MyException $e){
$e->exceptionlog();
}
}
et pourtant c'est faisable d'autre l'on fait public function getXML()
{
ob_start();
$this->content=ob_get_contents();
ob_clean();
return $this->content;
}
public function Writexml()
{
$xml=new DOMDocument();
$xml->loadXML($this->content);
$xml->saveXML($this->file);
}
mais je n'arrive pas à recuperer le contenu(j'utilise smarty comme tpl, c'est peut etre la qu'il faut chercher?)<?php
abstract class abstractrss
{
public function Create()
{
try{
if(!($this->fp=fopen($this->file,"w")))
throw new MyException('impossible d\'ouvrir :'.$this->file);
}
catch (MyException $e)
{
$e->exceptionlog();
}
}
/**
* ajoute des items
*
* @param string $titre
* @param string $description
* @param url $lien
*/
public function add_item($titre,$description,$lien)
{
try
{
if(isset($titre) && isset($description) && isset($lien))
{
$this->item[]=array('title'=>$titre,'description'=>$description,'link'=>$lien);
}
else
throw new MyException("les arguments 'titre','description','lien' sont obligatoires");
}
catch (MyException $e)
{$e->exceptionlog();}
return $this->item;
}
/**
* information sur le channel
*
* @param string $titre
* @param string $description
* @param url $lien
* @param date $date
*/
public function infoChannel($titre,$description,$lien,$date)
{
try
{
if(isset($titre) && isset($description) && isset($lien))
$this->channel=array('title'=>$titre,'description'=>$description,'link'=>$lien);
else
throw new MyException("les arguments 'titre','description','lien' sont obligatoires");
$this->channel['date']=$date;
}
catch (MyException $e)
{$e->exceptionlog();}
return $this->channel;
}
public function OptionItemImage($lien,$urlimage,$titre,$description,$width,$height)
{
try {
if(isset($titre) && isset($description) && isset($urlimage))
$this->image_item[]=array('urlimage'=>$urlimage,'titleimage'=>$titre,'descriptionimage'=>$description,'link'=>$lien,'width'=>$width,'height'=>$height);
else
throw new MyException("les arguments 'titre','description','lien' sont obligatoires");
}
catch (MyException $e)
{$e->exceptionlog();}
return $this->image_item;
}
public function __set($name,$value)
{
try
{
if(is_string($value))
$this->$name=htmlspecialchars($value);
elseif(is_numeric($value))
$this->$name=$value;
elseif(is_array($value))
{
foreach ($value as $cle=>&$val)
{
$val=htmlspecialchars($val);
}
$this->$name=$value;
}
elseif(is_bool($value))
$this->$name=$value;
else
throw new MyException('type non attendu');
}
catch (MyException $e)
{
$e->exceptionlog();
}
}
public function __get($name)
{
return $this->$name;
}
public function send()
{
if (!headers_sent($file,$line))
{
header("Content-Type: application/xml");
header("Content-Transfer-Encoding: binary");
header("Expires: 0");
}
}
public function createrss2()
{
foreach ($this as $cle=>$val)
{
$arr[$cle]=$val;
}
require_once(SMARTY_DIR_LIB.'/Smarty.class.php');
include 'configSmarty.php';
$Smarty = new Smarty_page();
$Smarty->assign($arr);
$this->content=$Smarty->fetch($this->tpl);
$xml=new DOMDocument();
$xml->loadXML($this->content);
$xml->saveXML($this->file);
/*$mv=new ModelView();
$mv->setView($this->tpl);
$mv->setModel($arr);
return $mv;*/
}
public function Writexml()
{
//echo 'methode'.__METHOD__.$this->content;
$xml=new DOMDocument();
$xml->loadXML($this->content);
$xml->saveXML($this->file);
}
}
?>
classe pour genere un flux rss 2
<?php
class rss2_ab extends abstractrss
{
protected $file;
public $lang;
protected $item;
protected $fp;
public $encoding;
protected $channel;
public $xslt;
protected $image_item;
public $copyright;
public $lastBuildDate;
protected $tpl;
protected $version;
protected $creator;
public $content;
/**
* constructeur de classe
*
*/
public function __construct(/*$file*/)
{ $mysql=new Mysqldb(SERVEUR,LOGIN,PASS,BASE);
$dao=new DAO($mysql);
$this->file='RSS/actu.xml';
$this->channel=array();
$this->encoding='UTF-8';
$this->lang='en';
$this->creator='Class rss2 creator';
$this->item=array();
$this->lastBuildDate='';
$this->version="2.0";
$this->tpl='rss/actu_rss2.tpl';
$this->copyright='by jeff';
$this->infoChannel('essai','premier test','http://localhost/projet_ing/',date("d/m/Y-H:i:s"));
$champs=array('date','description','titre','id_a');
$table=array('actu');
$dao->SetVar($table,$champs);
foreach($dao->Select('','Limit 0,4') as $cle=>$tab)
{
$this->add_item($tab[2],$tab[1],'http://localhost/projet_ing/index.php?module=actu&action=display&id='.$tab[3]);
}
}
}
?>
le template(il peut etre enrichi)<?xml version="1.0" encoding="{$encoding}" ?>
{if !empty($xslt)}
<?xml-stylesheet href="{$xslt}" type="text/xsl"?>
{/if}
<rss version="{$version}">
<channel>
<title>{$channel.title}</title>
<link>{$channel.link}</link>
<description>{$channel.description}</description>
<language>{$lang}</language>
{if !empty($copyright)}
<copyright>{$copyright}</copyright>
{/if}
{if !empty($lastBuildDate)}
<lastBuildDate>{$lastBuildDate}</lastBuildDate>
{/if}
{if !empty($creator)}
<generator>{$creator}</generator>
{/if}
{foreach from=$item item=item key=key name=item1}
<item>
<title>{$item.title}</title>
<link>{$item.link}</link>
<description>{$item.description}</description>
{if !empty($image_item)}
<image>
<url>$item.image_item.url</url>
<title>$item.image_item.title</title>
<link>$item.image_item.link</link>
<width>$item.image_item.width</width>
<height>$item.image_item.height</height>
</image>
{/if}
</item>
{/foreach}
</channel>
</rss>
et l'appel $rss=new rss2_ab();
$rss->send();
$rss->encoding='utf-8';
$rss->lang='fr';
$rss->lastBuildDate=date('d M Y à H:i');
$rss->createrss2();
echo $rss->content;
mais j'ai des erreur d'encodage quand j'utilise loadXMLCode : Tout sélectionner
<b>Warning</b>: DOMDocument::loadXML() [<a href='function.loadXML'>function.loadXML</a>]: Input is not proper UTF-8, indicate encoding ! in Entity, line: 9 in <b>e:\wamp\www\projet_ing\lib\class\abstractrss.php</b> on line <b>133</b><br />
<br />
<b>Warning</b>: DOMDocument::loadXML() [<a href='function.loadXML'>function.loadXML</a>]: Bytes: 0xE0 0x20 0x31 0x30 in Entity, line: 9 in <b>e:\wamp\www\projet_ing\lib\class\abstractrss.php</b> on line <b>133</b><br />Code : Tout sélectionner
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
<channel>
<title>essai</title>
<link>http://localhost/projet_ing/</link>
<description>premier test</description>
<language>fr</language>
<copyright>by jeff</copyright>
<lastBuildDate>30 Oct 2005 � 10:00</lastBuildDate>
<generator>Class rss2 creator</generator>
<item>
<title>test1</title>
<link>http://localhost/projet_ing/index.php?module=actu&action=display&id=1</link>
<description>premier test1</description>
</item>
<item>
<title>test2</title>
<link>http://localhost/projet_ing/index.php?module=actu&action=display&id=2</link>
<description>2ieme test</description>
</item>
</channel>
</rss>//...
public function send()
{
if (!headers_sent($file,$line))
{
header("Content-Type: application/xml");
header("Content-Transfer-Encoding: binary");
header("Expires: 0");
}
}
Tu utilises deux variables non définies $file et $line dans ta méthode, et en plus tu ne les utilises jamais dans cette même méthode...