Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 23

Discussione: Rss

  1. #1

    Rss

    class.rss.php
    codice:
    <?php
    class MakeRSS{
      var $Articles = array();
    
      // Channel info
      var $title = '';
      var $link = '';
      var $description = '';
      var $optional = array();
      var $image = array('url' => '', 'title' => '', 'link' => '', 'description' => '', 'w' => 0, 'h' => 0);
    
      function MakeRSS($title, $link, $description, $optional = ''){
        $this->title = $title;
        $this->link = $link;
        $this->description = $description;
    
        if( is_array($optional) and count($optional) ){
          $this->optional = $optional;
        }
      }
      
      function AddOptional($key, $value){
        $this->optional[$key] = $value;
      }
    
      function AddImage($title, $url, $link, $description = ''){
        $this->image['title'] = $title;
        $this->image['url'] = $url;
        $this->image['link'] = $link;
        $this->image['description'] = $description;
    
        if( $tmp = @getimagesize($url) ){
          $this->image['w'] = ($tmp[0] > 144) ? 144 : $tmp[0];
          $this->image['h'] = ($tmp[1] > 400) ? 400 : $tmp[1];
        }
      }
      
      function AddArticle($title, $link, $description, $author, $optional = ''){
        $i = array_push($this->Articles, array('title' => $title, 'link' => $link, 'description' => $description, 'author' => $author));
    
        if( is_array($optional) and count($optional) ){
          --$i;
          while( list($k, $v) = each($optional) ){
             $this->Articles[$i][$k] = $v;
          }
        }
      }
    
      function Output($save = false, $path = ''){
        $out = '<?xml version="1.0"?>' . "\n" . 
           '<rss version="2.0">' . "\n" .
           '<channel>' . "\n";
           
        $out .= "<title>$this->title</title>\n" .
            "<link>$this->link</link>\n" .
            "<description>$this->description</description>\n";
        
        //Channel optionals
        if( is_array($this->optional) and count($this->optional) ){
          while( list($k, $v) = each($this->optional) ){
            $out .= "<$k>$v</$k>\n";
          }
        }
        
    //Image
      if( $this->image['title'] and $this->image['url'] and $this->image['link'] ){
       $out .= "<image>\n" .
         "<title>" . $this->image['title'] . "</title>\n" .
         "<url>" . $this->image['url'] . "</url>\n" .
         "<link>" . $this->image['link'] . "</link>\n";
    
       if( $this->image['description'] ){
        $out .= "<description>" . $this->image['description'] . "</description>\n";
       }
    
       if( $this->image['w'] and $this->image['h'] ){
        $out .= "<width>" . $this->image['w'] . "</width>\n" .
          "<height>" . $this->image['h'] . "</height>\n";
       }
       $out .= "</image>\n";
      }
    
        //Articles
        for( $i = 0, $c = count($this->Articles); $i < $c; $i++ ){
           $out .= "<item>\n" .
               "<title>" . $this->Articles[$i]['title'] . "</title>\n" .
               "<link>" . $this->Articles[$i]['link'] . "</link>\n" .
               "<description>" . $this->Articles[$i]['description'] . "</description>\n" .
               "<author>" . $this->Articles[$i]['author'] . "</author>\n";
    
           if( count($this->Articles[$i]) > 4 ){
             while( list($k, $v) = each($optional) ){
               if( !in_array($k, array('title', 'link', 'description', 'author')) ){
                 $out .= "<$k>$v</$k>\n";
               }
             }
           }
    
    
           $out .= "</item>\n";
        }
    
        $out .= "</channel>\n</rss>";
    
    
        // True output
        if( !$save or !$path ){
          header("Content-type: application/xml");
          echo $out;
          return true;
        }
        else{
          $fh = fopen($path, 'w');
          if( $fh ){
            fwrite($fh, $out);
            fclose($fh);        
            
            return true;
          }
          return false;
        }
      }
    }
    ?>
    rss.php
    codice:
    <?php
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Data passata
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
                                                         // sempre modificato
    header("Cache-Control: no-store, no-cache, must-revalidate");  // HTTP/1.1
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");                          // HTTP/1.0 
    
    include "db.php";
    include('./class.rss.php'); 
    
    function xmlentities($string, $quote_style=ENT_COMPAT)
    {
       $trans = get_html_translation_table(HTML_ENTITIES, $quote_style);
    
       foreach ($trans as $key => $value)
           $trans[$key] = '&#'.ord($key).';';
    
       return strtr($string, $trans);
    } 
    
    $r = new MakeRSS('Sito.it', 'http://www.sito.it', 'Sito');
    
    $query = "SELECT * FROM News ORDER BY ID DESC LIMIT 0,10";
    $result = mysql_query($query, $db);
    while ($rows = mysql_fetch_array($result)) {
    $id = $rows["ID"];
    $titolo = $rows["Titolo"];
    $titolo = str_replace("&quot;","''",$titolo);
    $abs = $rows["Descrizione"];
    $abs = str_replace("&quot;","''",$abs);
    
    $titolo = xmlentities($titolo);
    $abs = xmlentities($abs);
    
    	$r->AddArticle("$titolo - $abs", "http://www.sito.it/news/news.php?News=$id", $abs, "Sito.it");
    }
    
    $r->Output();
    ?>
    Perchè con IE mi da errore?

    Impossibile visualizzare la pagina XML
    Impossibile visualizzare l'input XML tramite il foglio di stile XSL. Correggere l'errore, quindi fare clic su Aggiorna, oppure riprovare in un momento successivo.


    --------------------------------------------------------------------------------

    Carattere non valido nel contenuto di testo. Errore durante l'elaborazione della risorsa "http://www.ruotanti.it/include/rs...

    <title>Titolo news - PrimaLetteraDescrizione

  2. #2
    e se provi a togliere tutti quegli header per mettere solo:

    header("Content-Type: application/xml");

    Non sono sicuro che il problema sia questo, però puoi provare.

    P.s. quella classe non sono mai riuscito a farla funzionare a dovere (AddOptional). Ti consiglio la classe FeedCreator

  3. #3
    Non va, come adatto il tuo? Non so dove modificare rss.php

  4. #4
    A parte il fatto che è facile perchè la classe è ben fatta, molto commentata e fornita di esempi

    Comunque puoi leggere un altro thread dove lo spiegavo:
    http://forum.html.it/forum/showthrea...hreadid=865065

    Se poi ancora non ti riesce, chiedi pure ti darò volentieri una mano! (però qui e non in pvt ok?)


  5. #5
    Mi sa che non ci capisco una mazzafionda
    In pratica la classe non la tocco, giusto? Ma come ricrearmi l'rss con titolo e descrizione (senza data) non c'arrivo.,

  6. #6
    Non toccare la classe. Salvala in un file chiamato feedcrator.class.php e lasciala lì com'è.

    Poi scrivi il tuo rss.php così:

    Codice PHP:
    require_once('feedcreator.class.php');

    function 
    xmlentities($string$quote_style=ENT_COMPAT)
    {
       
    $trans =  get_html_translation_table(HTML_ENTITIES
    $quote_style);

       foreach (
    $trans as $key => $value)
           
    $trans[$key] = '&#'.ord($key).';';

       return 
    strtr($string$trans);


    /* Questa invece è fatta a mano...  maquella di prima mi sembra più efficace (a occchio, non l'ho provata, quella qui sotto sì)

    function xmlentities ( $string ){return str_replace ( array ( '\\' , '"\\' , '&amp;' , '&quot;', '&apos;' , '&lt;' , '&gt;' ), array ( '' , '' , '&', '"', "’", '<', '>' ), $string );}
    */


    // Ok cominciamo a definire le parti fisse del feed
    $rss = new UniversalFeedCreator(); 
    $rss->useCached(); 
    $rss->title "Titolo feed"
    $rss->description "Descrizione feed"
    $rss->cssStyleSheet ""//devi definirlo almeno vuoto
    $rss->link "http://link.to.your.website"
    $rss->feedURL ""//tanto questo non funziona :P

    //ok,  adesso estrai le news dal db (lascio com'era
    $query "SELECT * FROM News ORDER BY ID DESC LIMIT 0,10";
    $result mysql_query($query$db);

    while (
    $rows mysql_fetch_array($result)) {
    $id $rows["ID"];
    $titolo $rows["Titolo"];
    $titolo str_replace(""","''",$titolo);
    $abs = $rows["Descrizione"];
    $abs = str_replace(""","''",$abs);
    $titolo xmlentities($titolo);
    $abs xmlentities($abs);

    //e ora aggiungiamo ogni art. come item del feed
    $item = new FeedItem(); 
    $item->title $titolo
    //$item->link = $link;
    $item->description $abs
    //$item->category = $data[cat];
    //$item->date = ($dato2['pubdate'] + "00000003600"); //pubdate in UNIX TIMESTAMP
    //$item->author = $dato2['author'];
    /*Le cose che ti ho commentato tu non sembri usarle, però per completezza andrebbero specificate (credo che siano necessarie nella specifica RSS, ma non sono sicuro*/

    $item->descriptionHtmlSyndicated true;
    $item->categoryHtmlSyndicated true;
    //item->descriptionTruncSize = 500;
    $rss->addItem($item); 
    }

    //mandiamo l'output a video nel formato specificato
    echo $rss->createFeed("RSS2.0"""); 
    Fammi sapere se funziona...

  7. #7
    Le news non escono.

  8. #8
    Stesso problema, stessa domanda preliminare: ma tu riesci a estrarle dal database? Se fai

    echo $titolo;
    echo $abs;
    (mettili prima di $rss->addItem($item)

    riesci a vedere le news su schermo?

  9. #9
    Sì, escono.

  10. #10
    Quindi ti crea un file rss solo con le intestazioni ma senza item? o che altro?
    Cerca di descrivere il problema nel dettaglio

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.