Location: PHPKode > projects > Slashster > slashster/cron/rss.php
#!/usr/local/bin/php
<?

# Slashster: Open Source Friend of a Friend Software
# Copyright 2004 Mark El-Wakil
# Contact: hide@address.com
# http://seventhcycle.net
#
# This file is part of Slashster.
#
# Slashster is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Slashster is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Slashster; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

   require("cronpth.php");       
   $mpage = new PageClass("sqlonly");

   $sql = "select * from RSS order by Id desc";
   $r = $mpage->DoQuery($sql,1);

   foreach($r as $s)
   {
      UserRSS($s[Id], $s[URL]);
   }

function UserRSS($id, $uFile)
{
   global $mpage;

   $read = 1;
   $write = 1;
   $translate = 1;
   $writeback = 1;

   if ($read)
   {
      ob_start();
      readfile($uFile);
      $str = ob_get_contents();
      ob_end_clean();
   }

   if ($write)
   {
      $sql = "update RSS set XML = \"".mysql_escape_string($str)."\" where Id = $id";
      $mpage->DoQuery($sql);
   }


   if ($translate)
   {
      $sql = "select XML from RSS where Id = $id";
      $str = $mpage->DoQuery($sql);
      $str = $str[0][0];

      $p = xml_parser_create();
      xml_parse_into_struct($p,$str,$vals,$index);
      xml_parser_free($p);

      $title = array();
      $link  = array();

      if (!sizeof($index[ITEM] )) return;
      if (!sizeof($index[TITLE])) return;
      if (!sizeof($index[LINK]))  return;


      $itemarr = $index[ITEM];
      $titlearr = $index[TITLE]; 
      $linkarr  = $index[LINK];



      for ($x = 0; $x < 10 && $x < sizeof($titlearr); $x++)
      {
           $chkvar = $titlearr[$x];
           $chkplu = $chkvar + 1;

           $psh = 1;

           if ($vals[$chkplu][tag] != "ITEM" || $vals[$chkplu][type] != "cdata")
               $psh = 0;

           if ($psh) array_push($title, $vals[$chkvar][value]);
      }


      for ($x = 0; $x < 10 && $x < sizeof($linkarr); $x++)
      {
           $chkvar = $linkarr[$x];
           $chkplu = $chkvar + 1;
    
           $psh = 1;
      
           if ($vals[$chkplu][tag] != "ITEM" || $vals[$chkplu][type] != "cdata")
               $psh = 0;
             
           if ($psh) array_push($link, $vals[$chkvar][value]);
      }

   }

   if ($writeback)
   {
      $sze = min(sizeof($title), sizeof($link));

      $str  = "<font size=-1>";
      $str .= "<ul style=\"margin-left: 15px; padding-left:3px;\">";
      for ($x = 0; ($x < $sze) && ($x < 10); $x++)
      {
          $str .= "<li><a target=\"_blank\" href = \"$link[$x]\">$title[$x]</a></li>\n";
      }
      $str .= "</ul>";
        $str .= "</font>";

      $sql = "update RSS set Txt = \"".mysql_escape_string($str)."\" where Id = $id";
      $mpage->DoQuery($sql);
   }

   return;

}
Return current item: Slashster