cvs: pearweb /include/Damblan RSS.php

From: Date: Sun, 05 Sep 2004 08:03:17 +0000
Subject: cvs: pearweb /include/Damblan RSS.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-cvs+get-23647@lists.php.net to get a copy of this message
mj Sun Sep 5 04:03:17 2004 EDT Modified files: /pearweb/include/Damblan RSS.php Log: * Refactored Damblan_RSS to be more generic. * Added support for the PEPr RSS class. http://cvs.php.net/diff.php/pearweb/include/Damblan/RSS.php?r1=1.5&r2=1.6&ty=u Index: pearweb/include/Damblan/RSS.php diff -u pearweb/include/Damblan/RSS.php:1.5 pearweb/include/Damblan/RSS.php:1.6 --- pearweb/include/Damblan/RSS.php:1.5 Tue Jan 6 10:19:04 2004 +++ pearweb/include/Damblan/RSS.php Sun Sep 5 04:03:13 2004 @@ -15,7 +15,7 @@ +----------------------------------------------------------------------+ | Author: Martin Jansen <mj@php.net> | +----------------------------------------------------------------------+ - $Id: RSS.php,v 1.5 2004/01/06 15:19:04 mj Exp $ + $Id: RSS.php,v 1.6 2004/09/05 08:03:13 mj Exp $ */ require_once "PEAR.php"; @@ -26,7 +26,7 @@ * * @author Martin Jansen <mj@php.net> * @package Damblan - * @version $Revision: 1.5 $ + * @version $Revision: 1.6 $ */ class Damblan_RSS { @@ -38,10 +38,22 @@ * @return mixed String or PEAR_Error */ function getFeed($type) { - if (substr($type, 0, 4) == "user") { + // Maps URLs to classnames + $objectMap = array("latest" => "Latest", + "pkg" => "Package", + "cat" => "Category", + "user" => "User", + "pepr" => "PEPr" + ); + + $type = str_replace("/", "_", $type); + + $prefix = substr($type, 0, 4); + + if ($prefix == "user" || $prefix == "pepr") { $cache = $type; $value = substr($type, 5); - $type = substr($type, 0, 4); + $type = $prefix_test; } else if ($type != "latest") { $cache = $type; $value = substr($type, 4); @@ -58,29 +70,22 @@ $site = &Damblan_Site::factory(); PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array(&$site, "error404")); - if ($type == "latest") { - require_once "Damblan/RSS/Latest.php"; - $rss_obj = new Damblan_RSS_Latest(); - } else if ($type == "cat") { - require_once "Damblan/RSS/Category.php"; - $rss_obj = new Damblan_RSS_Category($value); - } else if ($type == "pkg") { - require_once "Damblan/RSS/Package.php"; - $rss_obj = new Damblan_RSS_Package($value); - } else if ($type == "user") { - require_once "Damblan/RSS/User.php"; - $rss_obj = new Damblan_RSS_User($value); + $type = strtolower($type); + if (!isset($objectMap[$type])) { + PEAR::raiseError("The requested URL " . $_SERVER['REQUEST_URI'] . " was not found on this server."); } - if (isset($rss_obj)) { - if (!PEAR::isError($rss_obj)) { - Damblan_RSS_Cache::write($cache, $rss_obj->toString()); - } + $filename = "Damblan/RSS/" . $objectMap[$type] . ".php"; + $classname = "Damblan_RSS_" . $objectMap[$type]; - return $rss_obj->toString(); - } else { - PEAR::raiseError("The requested URL " . $_SERVER['REQUEST_URI'] . " was not found on this server."); + require_once $filename; + $rss_obj = new $classname($value); + + if (!PEAR::isError($rss_obj)) { + Damblan_RSS_Cache::write($cache, $rss_obj->toString()); } + + return $rss_obj->toString(); } /**

« previous php.pear.cvs (#23647) next »