magpie templates. SMARTY examplesls
authordhawes <dhawes>
Sun, 23 Jan 2005 15:52:52 +0000 (15:52 +0000)
committerdhawes <dhawes>
Sun, 23 Jan 2005 15:52:52 +0000 (15:52 +0000)
rss/magpie/scripts/README [new file with mode: 0644]
rss/magpie/scripts/magpie_debug.php [new file with mode: 0755]
rss/magpie/scripts/magpie_simple.php [new file with mode: 0755]
rss/magpie/scripts/magpie_slashbox.php [new file with mode: 0755]
rss/magpie/scripts/simple_smarty.php [new file with mode: 0755]

diff --git a/rss/magpie/scripts/README b/rss/magpie/scripts/README
new file mode 100644 (file)
index 0000000..e37afe5
--- /dev/null
@@ -0,0 +1,27 @@
+Some example on how to use Magpie:
+
+* magpie_simple.php *
+  Simple example of fetching and parsing an RSS file. Expects to be
+  called with a query param 'rss_url=http://<some rss file>'
+
+* simple_smarty.php *
+  Similiar to magpie_simple, but using the Smarty template engine to do
+  display.  Also demostrates using rss_utils.inc and a smarty plugin to
+  parse and display when each RSS item was published.
+
+* magpie_debug.php *
+  Displays all the information available from a parsed feed.
+
+* smarty_plugin/modifier.rss_date_parse.php *
+  A Smarty plugin for parsing RSS style dates.  You must include rss_utils.inc
+  for this plugin to work.  It also must be installed in the Smarty plugin
+  directory, see the Smarty docs for details.
+
+* templates/simple.smarty
+  A Smarty template used by simple_smarty.php which demostrates
+  displaying an RSS feed and using the date parse plugin.
+  
+  
+The Smarty template engine and documentation on how to use it are available from
+http://smarty.php.net
diff --git a/rss/magpie/scripts/magpie_debug.php b/rss/magpie/scripts/magpie_debug.php
new file mode 100755 (executable)
index 0000000..43ed1ad
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+
+ini_set('display_errors', 1);
+ini_set('error_reporting', E_ALL);
+
+define('MAGPIE_DIR', '../');
+define('MAGPIE_DEBUG', 2);
+// flush cache quickly for debugging purposes, don't do this on a live site
+define('MAGPIE_CACHE_AGE', 2);
+
+require_once(MAGPIE_DIR.'rss_fetch.inc');
+
+$url = $_GET['url'];
+
+if ( $url ) {
+       $rss = fetch_rss( $url );
+       
+       if ($rss) {
+               echo "Channel: " . $rss->channel['title'] . "<p>";
+               echo "<ul>";
+               foreach ($rss->items as $item) {
+                       $href = $item['link'];
+                       $title = $item['title'];        
+                       echo "<li><a href=$href>$title</a></li>";
+               }
+               echo "</ul>";
+       }
+       else {
+               echo "Error: " . magpie_error();
+       }
+}
+?>
+
+<form>
+       RSS URL: <input type="text" size="30" name="url" value="<?php echo $url ?>"><br />
+       <input type="submit" value="Parse RSS">
+</form>
+
+<pre>
+<?php var_dump($rss); ?>
+</pre>
\ No newline at end of file
diff --git a/rss/magpie/scripts/magpie_simple.php b/rss/magpie/scripts/magpie_simple.php
new file mode 100755 (executable)
index 0000000..8617be3
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+
+define('MAGPIE_DIR', '../');
+require_once(MAGPIE_DIR.'rss_fetch.inc');
+
+$url = $_GET['url'];
+
+if ( $url ) {
+       $rss = fetch_rss( $url );
+       
+       echo "Channel: " . $rss->channel['title'] . "<p>";
+       echo "<ul>";
+       foreach ($rss->items as $item) {
+               $href = $item['link'];
+               $title = $item['title'];        
+               echo "<li><a href=$href>$title</a></li>";
+       }
+       echo "</ul>";
+}
+?>
+
+<form>
+       RSS URL: <input type="text" size="30" name="url" value="<?php echo $url ?>"><br />
+       <input type="submit" value="Parse RSS">
+</form>
diff --git a/rss/magpie/scripts/magpie_slashbox.php b/rss/magpie/scripts/magpie_slashbox.php
new file mode 100755 (executable)
index 0000000..bbef30b
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+
+define('MAGPIE_DIR', '../');
+require_once(MAGPIE_DIR.'rss_fetch.inc');
+       
+$url = $_GET['rss_url'];
+
+?>
+
+<html
+<body LINK="#999999" VLINK="#000000">
+
+<form>
+<input type="text" name="rss_url" size="40" value="<?php echo $url ?>"><input type="Submit">
+</form>
+
+<?php
+
+if ( $url ) {
+       echo "displaying: $url<p>";
+       $rss = fetch_rss( $url );
+       echo slashbox ($rss);
+}
+
+echo "<pre>";
+print_r($rss);
+echo "</pre>";
+?>
+
+</body>
+</html>
+
+<?php
+
+# just some quick and ugly php to generate html
+#
+#
+function slashbox ($rss) {
+       echo "<table cellpadding=2 cellspacing=0><tr>";
+       echo "<td bgcolor=#006666>";
+       
+       # get the channel title and link properties off of the rss object
+       #
+       $title = $rss->channel['title'];
+       $link = $rss->channel['link'];
+       
+       echo "<a href=$link><font color=#FFFFFF><b>$title</b></font></a>";
+       echo "</td></tr>";
+       
+       # foreach over each item in the array.
+       # displaying simple links
+       #
+       # we could be doing all sorts of neat things with the dublin core
+       # info, or the event info, or what not, but keeping it simple for now.
+       #
+       foreach ($rss->items as $item ) {
+               echo "<tr><td bgcolor=#cccccc>";
+               echo "<a href=$item[link]>";
+               echo $item['title'];
+               echo "</a></td></tr>";
+       }               
+       
+       echo "</table>";
+}
+
+?>
diff --git a/rss/magpie/scripts/simple_smarty.php b/rss/magpie/scripts/simple_smarty.php
new file mode 100755 (executable)
index 0000000..a904d88
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+
+// Define path to Smarty files (don't forget trailing slash)
+// and load library.  (you'll want to change this value)
+//
+// NOTE:  you can also simply add Smarty to your include path
+define('SMARTY_DIR', '/home/kellan/projs/magpierss/scripts/Smarty/');
+require_once(SMARTY_DIR.'Smarty.class.php');
+
+// define path to Magpie files and load library
+// (you'll want to change this value)
+//
+// NOTE: you can also simple add MagpieRSS to your include path
+define('MAGPIE_DIR', '/home/kellan/projs/magpierss/');
+require_once(MAGPIE_DIR.'rss_fetch.inc');
+require_once(MAGPIE_DIR.'rss_utils.inc');
+
+
+// optionally show lots of debugging info
+# define('MAGPIE_DEBUG', 2);
+
+// optionally flush cache quickly for debugging purposes, 
+// don't do this on a live site
+# define('MAGPIE_CACHE_AGE', 10);
+
+// use cache?  default is yes.  see rss_fetch for other Magpie options
+# define('MAGPIE_CACHE_ON', 1)
+
+// setup template object
+$smarty = new Smarty;
+$smarty->compile_check = true;
+
+// url of an rss file
+$url = $_GET['rss_url'];
+
+
+if ( $url ) {
+       // assign a variable to smarty for use in the template
+       $smarty->assign('rss_url', $url);
+       
+       // use MagpieRSS to fetch remote RSS file, and parse it
+       $rss = fetch_rss( $url );
+       
+       // if fetch_rss returned false, we encountered an error
+       if ( !$rss ) {
+               $smarty->assign( 'error', magpie_error() );
+       }
+       $smarty->assign('rss', $rss );
+       
+       $item = $rss->items[0];
+       $date = parse_w3cdtf( $item['dc']['date'] );
+       $smarty->assign( 'date', $date );
+}
+
+// parse smarty template, and display using the variables we assigned
+$smarty->display('simple.smarty');
+
+?>