Copyright (c) 1999-2009 Christophe DAVID

Permission to use, copy, modify, and distribute this software and its documentation under the terms of the GNU eneral Public License is hereby granted. No representations are made about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.

See the GNU General Public License.
Files / miscellaneous

rssdisplay.php

click here for a demo

<?php
/*

    Last modified by Christophe David on 2005/07/26.

    The latest version of this branch is available on
    https://www.christophedavid.org/w/c/w.php/Files/Rssdisplayphp

    Syntax
    (:RSS http://url.to.rss.feed/feed.rs  [short|long] [Maximum number of items] :)

*/


Markup('rssdisplay', 'fulltext', '/\(:RSS\s*(.*?)\s*:\)/e',"RSS('\$1')");

define('MAGPIE_CACHE_AGE', 60 * 15) ;
define('MAGPIE_CACHE_DIR', "$FarmD/cache");
define('MAGPIE_FETCH_TIME_OUT', 5);
define('MAGPIE_GZIP', true);

function RSS($regex)
   {
   # If you make a call to your own site and you have any kind of WritePage action ( Lock(2) ) for example because you do some kind
   # of logging in a wiki-page. The whole thing will deadlock, so remove any locks. ReadPage will request a lock again when needed
   Lock(-1);

   $output = '';
   if ($regex)
      {
      global $action;
      global $FarmD;

      $OriginalError_reportingLevel = error_reporting();
      error_reporting(0);

      $parameters = preg_split("/\s+/", $regex);

      if (! isset($parameters[1]))
         {
         $parameters[1] = 'long';
         }

      if (! isset($parameters[2]))
         {
         $parameters[2] = -1;
         }

      if (   ($action == 'browse')
          && (isset($parameters[0]))
         )
         {
         include_once("$FarmD/local/magpie/rss_fetch.inc");
         $rss = fetch_rss($parameters[0]);
         if ($rss)
            {
            if ($parameters[2] > 0)
               {
               $items = array_slice($rss->items, 0, $parameters[2]);
               }
           else
               {
               $items = $rss->items;
               }
           foreach ($items as $item)
               {
                $output .=    '* %newwin% [['
                            . $item['link']
                            . "|'''"
                            . $item['title']
                            . "''']]";

                if ($parameters[1] == 'long')
                   {
                   if (isset ($item['description']))
                      {
                      $output .=  "\\\\\n" . $item['description'];
                      }
                   else if (isset ($item['atom_content']))
                      {
                      $output .=  "\\\\\n" . $item['atom_content'];
                      }
                   }
               $output .= "\n";
               }
            }

         $output .= "\n|| %newwin%[[$parameters[0]|RSS]]||\n";
         }
      error_reporting($OriginalError_reportingLevel);
      }
   return $output;
   }
?>
 
Files / miscellaneous

printer friendly view
PDF

   
Google
 
Web www.christophedavid.org