• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ Contributions (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

/news RSS command

Post a bug fix, a new feature, a theme ...

Moderators: OldWolf, re*s.t.a.r.s.*2

Post a reply
2 posts • Page 1 of 1

Postby ninjaw » Sat Oct 06, 2007 5:22 pm

Here is my contribution: Type News {RSS|favorites} and get 3 last news. You can code your favorite feeds (included french nin feeds ..) or use HTTP:// url
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;
   }
  }
}

?>
ninjaw
Member
 
Posts: 49
Joined: Thu Oct 04, 2007 10:40 pm
Top

Postby cedzero » Thu Oct 22, 2009 3:18 pm

it's working like a charm !
Thank you
cedzero
New member
 
Posts: 4
Joined: Fri Oct 09, 2009 10:24 am
Top


Post a reply
2 posts • Page 1 of 1

Return to Contributions (v1.x)

Who is online

Users browsing this forum: No registered users and 21 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub