• Moderatore

    Creare un Feed

    Ecco la mia domanda:
    io vorrei creare un feed rss in modo che i navigaotiri del mio sito rimangano sempre aggiornati degli articoli che inseirisco nuovi e tempo qualcuno del forum aveva postato un sito che creava un feed rss della pagina del proprio sito ma non ricordo dov'è finito.
    Qualcuno sa aiutarmi 😎


  • Community Manager

  • Super User

    Per iniziare, ti posso suggerire un programma freeware da eseguire in locale: http://www.phelios.net/rss-writer.html

    Cordialmente,
    Stuart


  • User Attivo

    Mi accodo nel proporre programmi freeware

    http://home.hetnet.nl/~bsoft/rssbuilder/index.htm

    Per farlo direttamente dal sito, invece, le pagine devono avere una struttura tale da essere analizzate correttamente, e qualcosa non va mai per il verso giusto.


  • Super User

    E rilancio con un altro freebie, questa volta è una classe php da far girare sul server:
    http://www.bitfolge.de/rsscreator-en.html

    @m4rc0 said:

    Per farlo direttamente dal sito, invece, le pagine devono avere una struttura tale da essere analizzate correttamente...
    Purtroppo.

    Cordialmente,
    Stuart


  • Moderatore

    Ho dimenticato di dirvi che uso Mambo, non so se cambia qualcosa


  • Super User

    ma mambo non ce l'ha giá un feed?


  • Moderatore

    @must said:

    ma mambo non ce l'ha giá un feed?

    Si però non capisco come fare per crearlo che mi aggiorni solo gli ultimi articoli inseriti...c'è qualcuno che sa farlo?
    Grazie :bho:


  • Super User

    @riga75 said:

    Si però non capisco come fare per crearlo che mi aggiorni solo gli ultimi articoli inseriti...c'è qualcuno che sa farlo?
    Grazie :bho:
    hai le pagine organizzate in un db?


  • Moderatore

    @Rinzi said:

    hai le pagine organizzate in un db?

    Si..... tutti contenuti di mambo sono su un db


  • Super User

    adatta questa pagina rss.php e linkala

    <?php
    include ( "../funzioni.php" );
    include('makerss.php');
    $myDB=ConnectionDB( $option['host'],$option['user_db'],$option['pass_db'],$option['database']);
    $r = new MakeRSS('Feed RSS di sito.it', 'http://www.sito.it', 'descrizione feed rss');
    $result=mysql_query("SCRIVI QUI LA QUERY PER ESTRARRE GLI ARTICOLI");
    echo mysql_error();
    while($row=mysql_fetch_array( $result)){
    $url="http://" .$option['server']. $row["path"]."/". $row["file_name"];
    $r->AddArticle(str_replace('?','Euro',$row["titolo"]), $url, str_replace('?','Euro','descrizione articolo............'), 'Autore');
    }
    $r->Output();
    ?>

    makerss.php

    <?php
    class MakeRSS&#123;
      var $Articles = array&#40;&#41;;
    
      // Channel info
      var $title = '';
      var $link = '';
      var $description = '';
      var $optional = array&#40;&#41;;
      var $image = array&#40;'url' => '', 'title' => '', 'link' => '', 'description' => '', 'w' => 0, 'h' => 0&#41;;
    
      function MakeRSS&#40;$title, $link, $description, $optional = ''&#41;&#123;
        $this->title = $title;
        $this->link = $link;
        $this->description = $description;
    
        if&#40; is_array&#40;$optional&#41; and count&#40;$optional&#41; &#41;&#123;
          $this->optional = $optional;
        &#125;
      &#125;
    
      function AddOptional&#40;$key, $value&#41;&#123;
        $this->optional&#91;$key&#93; = $value;
      &#125;
    
      function AddImage&#40;$title, $url, $link, $description = ''&#41;&#123;
        $this->image&#91;'title'&#93; = $title;
        $this->image&#91;'url'&#93; = $url;
        $this->image&#91;'link'&#93; = $link;
        $this->image&#91;'description'&#93; = $description;
    
        if&#40; $tmp = @getimagesize&#40;$url&#41; &#41;&#123;
          $this->image&#91;'w'&#93; = &#40;$tmp&#91;0&#93; > 144&#41; ? 144 : $tmp&#91;0&#93;;
          $this->image&#91;'h'&#93; = &#40;$tmp&#91;1&#93; > 400&#41; ? 400 &#58; $tmp&#91;1&#93;;
        &#125;
      &#125;
    
      function AddArticle&#40;$title, $link, $description, $author, $optional = ''&#41;&#123;
        $i = array_push&#40;$this->Articles, array&#40;'title' => $title, 'link' => $link, 'description' => $description, 'author' => $author&#41;&#41;;
    
        if&#40; is_array&#40;$optional&#41; and count&#40;$optional&#41; &#41;&#123;
          --$i;
          while&#40; list&#40;$k, $v&#41; = each&#40;$optional&#41; &#41;&#123;
             $this->Articles&#91;$i&#93;&#91;$k&#93; = $v;
          &#125;
        &#125;
      &#125;
    
      function Output&#40;$save = false, $path = ''&#41;&#123;
        $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&#40; is_array&#40;$this->optional&#41; and count&#40;$this->optional&#41; &#41;&#123;
          while&#40; list&#40;$k, $v&#41; = each&#40;$this->optional&#41; &#41;&#123;
            $out .= "<$k>$v</$k>\n";
          &#125;
        &#125;
    
    //Image
      if&#40; $this->image&#91;'title'&#93; and $this->image&#91;'url'&#93; and $this->image&#91;'link'&#93; &#41;&#123;
       $out .= "<image>\n" .
         "<title>" . $this->image&#91;'title'&#93; . "</title>\n" .
         "<url>" . $this->image&#91;'url'&#93; . "</url>\n" .
         "<link>" . $this->image&#91;'link'&#93; . "</link>\n";
    
       if&#40; $this->image&#91;'description'&#93; &#41;&#123;
        $out .= "<description>" . $this->image&#91;'description'&#93; . "</description>\n";
       &#125;
    
       if&#40; $this->image&#91;'w'&#93; and $this->image&#91;'h'&#93; &#41;&#123;
        $out .= "<width>" . $this->image&#91;'w'&#93; . "</width>\n" .
          "<height>" . $this->image&#91;'h'&#93; . "</height>\n";
       &#125;
       $out .= "</image>\n";
      &#125;
    
        //Articles
        for&#40; $i = 0, $c = count&#40;$this->Articles&#41;; $i < $c; $i++ &#41;&#123;
           $out .= "<item>\n" .
               "<title>" . $this->Articles&#91;$i&#93;&#91;'title'&#93; . "</title>\n" .
               "<link>" . $this->Articles&#91;$i&#93;&#91;'link'&#93; . "</link>\n" .
               "<description>" . $this->Articles&#91;$i&#93;&#91;'description'&#93; . "</description>\n" .
               "<author>" . $this->Articles&#91;$i&#93;&#91;'author'&#93; . "</author>\n";
    
           if&#40; count&#40;$this->Articles&#91;$i&#93;&#41; > 4 &#41;&#123;
             while&#40; list&#40;$k, $v&#41; = each&#40;$optional&#41; &#41;&#123;
               if&#40; !in_array&#40;$k, array&#40;'title', 'link', 'description', 'author'&#41;&#41; &#41;&#123;
                 $out .= "<$k>$v</$k>\n";
               &#125;
             &#125;
           &#125;
    
    
           $out .= "</item>\n";
        &#125;
    
        $out .= "</channel>\n</rss>";
    
    
        // True output
        if&#40; !$save or !$path &#41;&#123;
          header&#40;"Content-type&#58; application/xml"&#41;;
          echo $out;
          return true;
        &#125;
        else&#123;
          $fh = fopen&#40;$path, 'w'&#41;;
          if&#40; $fh &#41;&#123;
            fwrite&#40;$fh, $out&#41;;
            fclose&#40;$fh&#41;;
    
            return true;
          &#125;
          return false;
        &#125;
      &#125;
    &#125;
    ?>
    
    

  • Moderatore

    Intanto grazie Rinzi
    Visto che sono un pò ignorantotto, queste sono le mie domande:
    questo dove lo metto, e sto file qua (include ( "../funzioni.php" );) cos'è?
    @"Rinzi" said:

    <?php
    include ( "../funzioni.php" );
    include('makerss.php');
    $myDB=ConnectionDB( $option['host'],$option['user_db'],$option['pass_db'],$option['database']);
    $r = new MakeRSS('Feed RSS di sito.it', 'http://www.sito.it', 'descrizione feed rss');
    $result=mysql_query("SCRIVI QUI LA QUERY PER ESTRARRE GLI ARTICOLI");
    echo mysql_error();
    while($row=mysql_fetch_array( $result)){
    $url="http://" .$option['server']. $row["path"]."/". $row["file_name"];
    $r->AddArticle(str_replace('?','Euro',$row["titolo"]), $url, str_replace('?','Euro','descrizione articolo............'), 'Autore');
    }
    $r->Output();
    ?>
    Qesto se non ho capito male è il file che mi crea il feed?
    Ossia l'icone del feed deve puntare a questo file?
    [quote=Rinzi]
    makerss.php

    <?php
    class MakeRSS&#123;
     var $Articles = array&#40;&#41;;
    
     // Channel info
     var $title = '';
     var $link = '';
     var $description = '';
     var $optional = array&#40;&#41;;
     var $image = array&#40;'url' => '', 'title' => '', 'link' => '', 'description' => '', 'w' => 0, 'h' => 0&#41;;
    
     function MakeRSS&#40;$title, $link, $description, $optional = ''&#41;&#123;
       $this->title = $title;
       $this->link = $link;
       $this->description = $description;
    
       if&#40; is_array&#40;$optional&#41; and count&#40;$optional&#41; &#41;&#123;
         $this->optional = $optional;
       &#125;
     &#125;
    
     function AddOptional&#40;$key, $value&#41;&#123;
       $this->optional&#91;$key&#93; = $value;
     &#125;
    
     function AddImage&#40;$title, $url, $link, $description = ''&#41;&#123;
       $this->image&#91;'title'&#93; = $title;
       $this->image&#91;'url'&#93; = $url;
       $this->image&#91;'link'&#93; = $link;
       $this->image&#91;'description'&#93; = $description;
    
       if&#40; $tmp = @getimagesize&#40;$url&#41; &#41;&#123;
         $this->image&#91;'w'&#93; = &#40;$tmp&#91;0&#93; > 144&#41; ? 144 : $tmp&#91;0&#93;;
         $this->image&#91;'h'&#93; = &#40;$tmp&#91;1&#93; > 400&#41; ? 400 &#58; $tmp&#91;1&#93;;
       &#125;
     &#125;
    
     function AddArticle&#40;$title, $link, $description, $author, $optional = ''&#41;&#123;
       $i = array_push&#40;$this->Articles, array&#40;'title' => $title, 'link' => $link, 'description' => $description, 'author' => $author&#41;&#41;;
    
       if&#40; is_array&#40;$optional&#41; and count&#40;$optional&#41; &#41;&#123;
         --$i;
         while&#40; list&#40;$k, $v&#41; = each&#40;$optional&#41; &#41;&#123;
            $this->Articles&#91;$i&#93;&#91;$k&#93; = $v;
         &#125;
       &#125;
     &#125;
    
     function Output&#40;$save = false, $path = ''&#41;&#123;
       $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&#40; is_array&#40;$this->optional&#41; and count&#40;$this->optional&#41; &#41;&#123;
         while&#40; list&#40;$k, $v&#41; = each&#40;$this->optional&#41; &#41;&#123;
           $out .= "<$k>$v</$k>\n";
         &#125;
       &#125;
    
    //Image
     if&#40; $this->image&#91;'title'&#93; and $this->image&#91;'url'&#93; and $this->image&#91;'link'&#93; &#41;&#123;
      $out .= "<image>\n" .
        "<title>" . $this->image&#91;'title'&#93; . "</title>\n" .
        "<url>" . $this->image&#91;'url'&#93; . "</url>\n" .
        "<link>" . $this->image&#91;'link'&#93; . "</link>\n";
    
      if&#40; $this->image&#91;'description'&#93; &#41;&#123;
       $out .= "<description>" . $this->image&#91;'description'&#93; . "</description>\n";
      &#125;
    
      if&#40; $this->image&#91;'w'&#93; and $this->image&#91;'h'&#93; &#41;&#123;
       $out .= "<width>" . $this->image&#91;'w'&#93; . "</width>\n" .
         "<height>" . $this->image&#91;'h'&#93; . "</height>\n";
      &#125;
      $out .= "</image>\n";
     &#125;
    
       //Articles
       for&#40; $i = 0, $c = count&#40;$this->Articles&#41;; $i < $c; $i++ &#41;&#123;
          $out .= "<item>\n" .
              "<title>" . $this->Articles&#91;$i&#93;&#91;'title'&#93; . "</title>\n" .
              "<link>" . $this->Articles&#91;$i&#93;&#91;'link'&#93; . "</link>\n" .
              "<description>" . $this->Articles&#91;$i&#93;&#91;'description'&#93; . "</description>\n" .
              "<author>" . $this->Articles&#91;$i&#93;&#91;'author'&#93; . "</author>\n";
    
          if&#40; count&#40;$this->Articles&#91;$i&#93;&#41; > 4 &#41;&#123;
            while&#40; list&#40;$k, $v&#41; = each&#40;$optional&#41; &#41;&#123;
              if&#40; !in_array&#40;$k, array&#40;'title', 'link', 'description', 'author'&#41;&#41; &#41;&#123;
                $out .= "<$k>$v</$k>\n";
              &#125;
            &#125;
          &#125;
    
    
          $out .= "</item>\n";
       &#125;
    
       $out .= "</channel>\n</rss>";
    
    
       // True output
       if&#40; !$save or !$path &#41;&#123;
         header&#40;"Content-type&#58; application/xml"&#41;;
         echo $out;
         return true;
       &#125;
       else&#123;
         $fh = fopen&#40;$path, 'w'&#41;;
         if&#40; $fh &#41;&#123;
           fwrite&#40;$fh, $out&#41;;
           fclose&#40;$fh&#41;;
    
           return true;
         &#125;
         return false;
       &#125;
     &#125;
    &#125;
    ?>
    
    

  • Super User

    e sto file qua (include ( "../funzioni.php" )OK cos'è?
    è solo un file in cui imposto alcune variabili da utilizzare in tutto il sito
    come $option['user_db'] per la connessione al DB

    puoi eliminare quest include

    e sostituire

    $myDB=ConnectionDB&#40; $option&#91;'host'&#93;,$option&#91;'user_db'&#93;,$option&#91;'pass_db'&#93;,$option&#91;'database'&#93;&#41;; 
    

    con

    $myDB=ConnectionDB&#40; 'DBhost','user_db','pass_db','database'&#41;; 
    

    il primo blocco di codice lo metti un un file che si chiama** rss.php** (o simile)
    e lo link dal sito

    Qesto se non ho capito male è il file che mi crea il feed?
    Ossia l'icone del feed deve puntare a questo file?

    rss.php è il file che devi linkare e che crea il feed 🙂

    l'altro viene utilizzato dal prima ma nn devi linkarlo direttamente (mettilo nella stessa cartella)

    ci siamo 🙂 ( ero stato impreciso io 😄 )

    se ci siamo nn andiamo OT 😉