Advertisement
terorama

rssloader / funcs3.inc.php

Aug 21st, 2012
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.94 KB | None | 0 0
  1. <?php
  2.    require 'db.inc.php';
  3.    
  4. $cn_status=conn();
  5.  
  6. //---------------------------------------------------
  7. function drawrss($rssname,$count) {
  8.  
  9.    
  10.    $rssquery=getSingle("select http_query from gqueries where name='$rssname'");
  11.    //$rez=$rssquery;
  12.    //return $rez;
  13.    $ver=1;
  14.  
  15.    $rez='';
  16.    //return('test');
  17.    $xml=simplexml_load_file($rssquery);
  18.    $i=1;
  19.    try {
  20.    
  21.    foreach ($xml->children() as $a=>$b) {
  22.       if ($a=='channel') {
  23.          $ver=2;
  24.       }
  25.    }
  26.    
  27.    if ($ver==1) {
  28.        //------------------------------Atom format  
  29.        foreach ($xml->entry as $item) {
  30.          $title=$item->title;
  31.          $content=$item->content;
  32.          $link=$item->link;
  33.          $published=$item->published;
  34.      
  35.          $rez.= <<<RSS
  36.             <div class="rsscontent">
  37.             <h3><a href="$link">$title<a></h3>
  38.             <p>$content</p>
  39.             <p class="rssdate">$published</p>
  40.             </div>
  41.             <div class="rsssplit"></div>
  42.            
  43. RSS;
  44.          $i++;       
  45.          if ($i>$count)
  46.             break;
  47.            
  48.          if (($i%2)!=0)
  49.             $rez.='<div class="rssrowsplit"></div>';
  50.         }
  51.         }
  52.         //----------------------------------RSS 2.0 format
  53.     else
  54.        {//return '<pre>'.print_r($xml->channel->item->title).'</pre>';
  55.        foreach ($xml->channel->item as $item) {
  56.        
  57.           /*foreach ($item->children() as $a=>$b) {
  58.              $rez.=$a.'='.$b.'<br>';
  59.           }}*/
  60.           $title=$item->title;
  61.           $description=$item->description;
  62.           $link=$item->link;
  63.           $pubDate=$item->pubDate;
  64.          
  65.           $rez.= <<<RSS
  66.           <div class="rsscontent">
  67.           <h3><a href="$link">$title</a></h3>
  68.           <p>$description</p>
  69.           <p class="rssdate">$pubDate</p>
  70.           </div>
  71.           <div class="rsssplit"></div>
  72. RSS;
  73.           $i++;
  74.           if ($i>$count)
  75.              break;
  76.              
  77.            if (($i%2)!=0)
  78.               $rez.='<div class="rssrowsplit"></div>';
  79.           }
  80.        }
  81.        }
  82.        catch (Exception $e) {
  83.           return $e->getMessage();
  84.        
  85.        }
  86.        
  87.  
  88.    return $rez;
  89. }
  90.  
  91.  
  92. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement