Salut,
voilà le nouveau code qui utilise simple xml comme tu le suggérais, plus simple en effet
Problème : ça fonctionne très bien en local, plus du tout en ligne
<?php
$dir = 'tw_cache/';
$fileName = 'latest.php';
$latest = $dir . $fileName;
$update = @filemtime($latest);
$udpateFreq = $update + 600; // en secondes
$target = 'http://twitter.com/statuses/user_timeline/783214.rss'; // source
$res = @simplexml_load_file($target);
if ((file_exists($latest)) && (time() < $udpateFreq)) // si le cache existe et n'est pas périmé
{
$fileContent = fopen($latest, 'r');
$latestTweet = fgets($fileContent);
fclose($fileContent);
echo $latestTweet;
}
elseif ($res) // sinon, si tweeter est up
{
$tweet = str_replace('twitter: ', '', $res->channel->item[0]->title);
$tweet = preg_replace('# ((?:https?|ftp)://\S+?)(?=[[:punct:]]?(?:\s|\Z)|\Z)#', ' <a href="$1">$1</a>', $tweet); // replacing url by link
$link = $res->channel->item[0]->link;
$date = date('d/m/Y à H:i', strtotime($res->channel->item[0]->pubDate));
$latestTweet = '<div id="latesttweet"><p>' . $tweet . '<br/>Posté le <a href="' . $link . '"><span class="date">' . $date . '</span></a></p></div>';
echo $latestTweet;
// si le repertoire de cache n'existe pas, on le cree
if (!is_dir($dir)) { mkdir($dir, 0705); }
// creation du fichier cache
$fileContent = fopen($latest, 'w+');
fputs($fileContent, $latestTweet);
fclose($fileContent);
}
else {
echo '<div id="latesttweet"><p>Tweet ! Tweet !</p></div>';
}
?>
Et les erreurs que j'obtiens :
Warning: simplexml_load_file(http://twitter.com/statuses/user_timeline/783214.rss) [function.simplexml-load-file]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in /homez.42/username/www/includes/latest-tweet.php on line 12
Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "http://twitter.com/statuses/user_timeline/783214.rss" in /homez.42/username/www/includes/latest-tweet.php on line 12