Exemple :
18:12:25 ‹Ninjaw› /news hotline
06/10/2007 18:12:33 Ninjaw ask for news: The Nine Inch Nails Hotline
06/10/2007 18:12:33 [06/10/2007 00:00] TheDailyWTF mentions NIN poll
06/10/2007 18:12:33 [06/10/2007 00:00] Grey slimfit hoodie added to Hotline store
06/10/2007 18:12:33 [06/10/2007 00:00] Been a long time Becoming
feel free to add options for details or pick news numbers
optimize the code (especially my bad feed title detection)
src/commands/news.class.php :
- Code: Select all
<?php
require_once(dirname(__FILE__)."/../pfccommand.class.php");
// News command 0.9 by Ninjaw : get 3 last RSS news with prefered feeds
class pfcCommand_news extends pfcCommand
{
var $usage = "/news {rss | nin | hotline | ninnewsfr | ninfr | ninfrance | ninforum}";
function run(&$xml_reponse, $p)
{
$clientid = $p["clientid"];
$param = $p["param"];
$sender = $p["sender"];
$recipient = $p["recipient"];
$recipientid = $p["recipientid"];
$c =& pfcGlobalConfig::Instance();
$u =& pfcUserConfig::Instance();
$ct =& pfcContainer::Instance();
if (trim($param) == "")
{
// error
$cmdp = $p;
$cmdp["param"] = _pfc("Missing parameter");
$cmdp["param"] .= " (".$this->usage.")";
$cmd =& pfcCommand::Factory("error");
$cmd->run($xml_reponse, $cmdp);
return;
}
$msg = phpFreeChat::PreFilterMsg($param);
// knowns feeds
if($msg=="nin") $msg="http://www.nin.com/rss/nin.xml";
if($msg=="ninnewsfr") $msg="http://ninnewsfr.mihalis.org/rss";
if($msg=="hotline") $msg="http://feeds.feedburner.com/theninhotline/TWxQ";
if($msg=="ninfrance") $msg="http://ninfrance.free.fr/rss.xml";
if($msg=="ninfr") $msg="http://rss.groups.yahoo.com/group/ninfr/rss ";
if($msg=="ninforum") $msg="http://ninforum.org/rss.php";
// Read file
if($chaine = @implode("",@file($msg)))
{
// feed title
$feedtitle = preg_split("/</?title>/",$chaine);
// explode on <item>
$tmp = preg_split("/</?item>/",$chaine);
// for each <item>
for($i=1;$i<sizeof($tmp)-1;$i+=2)
{
// read asked champs <champ>
$champs=array("title","link","pubDate","description");
foreach($champs as $champ)
{
$tmp2 = preg_split("/</?".$champ.">/",$tmp[$i]);
// add into tab
$xml[$i-1][] = @$tmp2[1];
}
}
}
else
{
//file unavailable
$ct->write($recipient, "*me*", $this->name, $u->getNickname()." ask for news: error with ".$msg);
exit();
}
$ct->write($recipient, "*me*", $this->name, $u->getNickname()." ask for news: <a href='".$msg."'>".$feedtitle[1]."</a>");
//show news
foreach($xml as $row)
{
$buffer= "<font size=2 color=gray>[".date("d/m/Y H:i",strtotime($row[2]))."]</font> "
."<A target=_blank href='".$row[1]."'>".$row[0]."</A>";
$ct->write($recipient, "*me*", $this->name, " ".$buffer);
if(++$counter>2) break;
}
}
}
?>