Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

magpie templates. SMARTY examplesls

  • Loading branch information...
commit b6442a5e3a988c19912529ec63bf0d61e39f855b 1 parent ae4b445
authored January 23, 2005
27  rss/magpie/scripts/README
... ...
@@ -0,0 +1,27 @@
  1
+Some example on how to use Magpie:
  2
+
  3
+* magpie_simple.php *
  4
+  Simple example of fetching and parsing an RSS file. Expects to be
  5
+  called with a query param 'rss_url=http://<some rss file>'
  6
+
  7
+* simple_smarty.php *
  8
+  Similiar to magpie_simple, but using the Smarty template engine to do
  9
+  display.  Also demostrates using rss_utils.inc and a smarty plugin to
  10
+  parse and display when each RSS item was published.
  11
+
  12
+* magpie_debug.php *
  13
+  Displays all the information available from a parsed feed.
  14
+
  15
+* smarty_plugin/modifier.rss_date_parse.php *
  16
+ 
  17
+  A Smarty plugin for parsing RSS style dates.  You must include rss_utils.inc
  18
+  for this plugin to work.  It also must be installed in the Smarty plugin
  19
+  directory, see the Smarty docs for details.
  20
+
  21
+* templates/simple.smarty
  22
+  A Smarty template used by simple_smarty.php which demostrates
  23
+  displaying an RSS feed and using the date parse plugin.
  24
+  
  25
+  
  26
+The Smarty template engine and documentation on how to use it are available from
  27
+http://smarty.php.net
41  rss/magpie/scripts/magpie_debug.php
... ...
@@ -0,0 +1,41 @@
  1
+<?php
  2
+
  3
+ini_set('display_errors', 1);
  4
+ini_set('error_reporting', E_ALL);
  5
+
  6
+define('MAGPIE_DIR', '../');
  7
+define('MAGPIE_DEBUG', 2);
  8
+// flush cache quickly for debugging purposes, don't do this on a live site
  9
+define('MAGPIE_CACHE_AGE', 2);
  10
+
  11
+require_once(MAGPIE_DIR.'rss_fetch.inc');
  12
+
  13
+$url = $_GET['url'];
  14
+
  15
+if ( $url ) {
  16
+	$rss = fetch_rss( $url );
  17
+	
  18
+	if ($rss) {
  19
+		echo "Channel: " . $rss->channel['title'] . "<p>";
  20
+		echo "<ul>";
  21
+		foreach ($rss->items as $item) {
  22
+			$href = $item['link'];
  23
+			$title = $item['title'];	
  24
+			echo "<li><a href=$href>$title</a></li>";
  25
+		}
  26
+		echo "</ul>";
  27
+	}
  28
+	else {
  29
+		echo "Error: " . magpie_error();
  30
+	}
  31
+}
  32
+?>
  33
+
  34
+<form>
  35
+	RSS URL: <input type="text" size="30" name="url" value="<?php echo $url ?>"><br />
  36
+	<input type="submit" value="Parse RSS">
  37
+</form>
  38
+
  39
+<pre>
  40
+<?php var_dump($rss); ?>
  41
+</pre>
25  rss/magpie/scripts/magpie_simple.php
... ...
@@ -0,0 +1,25 @@
  1
+<?php
  2
+
  3
+define('MAGPIE_DIR', '../');
  4
+require_once(MAGPIE_DIR.'rss_fetch.inc');
  5
+
  6
+$url = $_GET['url'];
  7
+
  8
+if ( $url ) {
  9
+	$rss = fetch_rss( $url );
  10
+	
  11
+	echo "Channel: " . $rss->channel['title'] . "<p>";
  12
+	echo "<ul>";
  13
+	foreach ($rss->items as $item) {
  14
+		$href = $item['link'];
  15
+		$title = $item['title'];	
  16
+		echo "<li><a href=$href>$title</a></li>";
  17
+	}
  18
+	echo "</ul>";
  19
+}
  20
+?>
  21
+
  22
+<form>
  23
+	RSS URL: <input type="text" size="30" name="url" value="<?php echo $url ?>"><br />
  24
+	<input type="submit" value="Parse RSS">
  25
+</form>
66  rss/magpie/scripts/magpie_slashbox.php
... ...
@@ -0,0 +1,66 @@
  1
+<?php
  2
+
  3
+define('MAGPIE_DIR', '../');
  4
+require_once(MAGPIE_DIR.'rss_fetch.inc');
  5
+	
  6
+$url = $_GET['rss_url'];
  7
+
  8
+?>
  9
+
  10
+<html
  11
+<body LINK="#999999" VLINK="#000000">
  12
+
  13
+<form>
  14
+<input type="text" name="rss_url" size="40" value="<?php echo $url ?>"><input type="Submit">
  15
+</form>
  16
+
  17
+<?php
  18
+
  19
+if ( $url ) {
  20
+	echo "displaying: $url<p>";
  21
+	$rss = fetch_rss( $url );
  22
+	echo slashbox ($rss);
  23
+}
  24
+
  25
+echo "<pre>";
  26
+print_r($rss);
  27
+echo "</pre>";
  28
+?>
  29
+
  30
+</body>
  31
+</html>
  32
+
  33
+<?php
  34
+
  35
+# just some quick and ugly php to generate html
  36
+#
  37
+#
  38
+function slashbox ($rss) {
  39
+	echo "<table cellpadding=2 cellspacing=0><tr>";
  40
+	echo "<td bgcolor=#006666>";
  41
+	
  42
+	# get the channel title and link properties off of the rss object
  43
+	#
  44
+	$title = $rss->channel['title'];
  45
+	$link = $rss->channel['link'];
  46
+	
  47
+	echo "<a href=$link><font color=#FFFFFF><b>$title</b></font></a>";
  48
+	echo "</td></tr>";
  49
+	
  50
+	# foreach over each item in the array.
  51
+	# displaying simple links
  52
+	#
  53
+	# we could be doing all sorts of neat things with the dublin core
  54
+	# info, or the event info, or what not, but keeping it simple for now.
  55
+	#
  56
+	foreach ($rss->items as $item ) {
  57
+		echo "<tr><td bgcolor=#cccccc>";
  58
+		echo "<a href=$item[link]>";
  59
+		echo $item['title'];
  60
+		echo "</a></td></tr>";
  61
+	}		
  62
+	
  63
+	echo "</table>";
  64
+}
  65
+
  66
+?>
58  rss/magpie/scripts/simple_smarty.php
... ...
@@ -0,0 +1,58 @@
  1
+<?php
  2
+
  3
+// Define path to Smarty files (don't forget trailing slash)
  4
+// and load library.  (you'll want to change this value)
  5
+//
  6
+// NOTE:  you can also simply add Smarty to your include path
  7
+define('SMARTY_DIR', '/home/kellan/projs/magpierss/scripts/Smarty/');
  8
+require_once(SMARTY_DIR.'Smarty.class.php');
  9
+
  10
+// define path to Magpie files and load library
  11
+// (you'll want to change this value)
  12
+//
  13
+// NOTE: you can also simple add MagpieRSS to your include path
  14
+define('MAGPIE_DIR', '/home/kellan/projs/magpierss/');
  15
+require_once(MAGPIE_DIR.'rss_fetch.inc');
  16
+require_once(MAGPIE_DIR.'rss_utils.inc');
  17
+
  18
+
  19
+// optionally show lots of debugging info
  20
+# define('MAGPIE_DEBUG', 2);
  21
+
  22
+// optionally flush cache quickly for debugging purposes, 
  23
+// don't do this on a live site
  24
+# define('MAGPIE_CACHE_AGE', 10);
  25
+
  26
+// use cache?  default is yes.  see rss_fetch for other Magpie options
  27
+# define('MAGPIE_CACHE_ON', 1)
  28
+
  29
+// setup template object
  30
+$smarty = new Smarty;
  31
+$smarty->compile_check = true;
  32
+
  33
+// url of an rss file
  34
+$url = $_GET['rss_url'];
  35
+
  36
+
  37
+if ( $url ) {
  38
+	// assign a variable to smarty for use in the template
  39
+	$smarty->assign('rss_url', $url);
  40
+	
  41
+	// use MagpieRSS to fetch remote RSS file, and parse it
  42
+	$rss = fetch_rss( $url );
  43
+	
  44
+	// if fetch_rss returned false, we encountered an error
  45
+	if ( !$rss ) {
  46
+		$smarty->assign( 'error', magpie_error() );
  47
+	}
  48
+	$smarty->assign('rss', $rss );
  49
+	
  50
+	$item = $rss->items[0];
  51
+	$date = parse_w3cdtf( $item['dc']['date'] );
  52
+	$smarty->assign( 'date', $date );
  53
+}
  54
+
  55
+// parse smarty template, and display using the variables we assigned
  56
+$smarty->display('simple.smarty');
  57
+
  58
+?>

0 notes on commit b6442a5

Please sign in to comment.
Something went wrong with that request. Please try again.