RSS to Cisco XML converter in PHP

RSS to Cisco XML converter in PHP

This is a little script to display an RSS/RDF channel on a Cisco IP phone.


<?php
  # rss2ciscoxml.php
  # (C) 2005 Stefan Gofferje
  # http://www.gofferje.net/
  # License: GNU General Public License
  # http://www.gnu.org/licenses/gpl.html
  ######################################
  
  header ("Content-type: text/xml");
  $rdf = parse_url($url);
  $fp = fsockopen($rdf['host'], 80, $errno, $errstr, 15);
  if (!$fp) {
    $content = "";
    echo $content;
    return;
  }
  if ($fp) {
    if ($rdf['query'] <> "") fputs($fp, "GET " . $rdf['path'] . "?" . $rdf['query'] . " HTTP/1.0rn");
    else fputs($fp, "GET " . $rdf['path'] . " HTTP/1.0rn");
    fputs($fp, "HOST: " . $rdf['host'] . "rnrn");
    $string = "";
    while(!feof($fp)) {
      $pagetext = fgets($fp,300);
      $string .= chop($pagetext);
    }
    fputs($fp,"Connection: closernrn");
    fclose($fp);
  
    print "<CiscoIPPhoneText>n";
    $items = explode("</title>",$string);
    $title = ereg_replace(".*<title>","",$items[0]);
    print "<Title>$title</Title>n";
    print "<Text>";
  
    $items = explode("</item>",$string);
    for ($i=0;$i<10;$i++) {
      $link = ereg_replace(".*<link>","",$items[$i]);
      $link = ereg_replace("</link>.*","",$link);
      $title2 = ereg_replace(".*<title>","",$items[$i]);
      $title2 = ereg_replace("</title>.*","",$title2);
      if ((stristr($items[$i],"</rss>")) || (stristr($items[$i],"</rdf:RDF>"))) {
        print "</Text>n";
        print "<Prompt></Prompt>n";
        print "<SoftKeyItem>n";
        print "  <Name>Return</Name>n";
        print "  <URL>Softkey:Exit</URL>n";
        print "  <Position>1</Position>n";
        print "</SoftKeyItem>n";
        print "</CiscoIPPhoneText>n";
        return;
      } else {
        if (strcmp($link,$title)) {
          print "- ".$title2."n";
        }
      }
    }
    print "</Text>n";
    print "<Prompt></Prompt>n";
    print "<SoftKeyItem>n";
    print "  <Name>Return</Name>n";
    print "  <URL>Softkey:Exit</URL>n";
    print "  <Position>1</Position>n";
    print "</SoftKeyItem>n";
    print "</CiscoIPPhoneText>n";
  }
?>