Powerful PHP class for RSS 2.0 feed generation.
By : mgalesic
Simple example:
<?php
include('class.rss.php');
$rss = new rss('utf-8');
$rss->channel('RSStitle', 'http://www.yoursite.com', 'Description of RSS channel');
$rss->language('en-us');
$rss->copyright('Copyright by yourSiteName 2006');
$rss->managingEditor('email@yoursite.com');
$rss->category('CategoryName');
$rss->startRSS();
for($i = 1; $i < 10; $i++){
$rss->itemTitle('News ' . $i);
$rss->itemLink('http://www.yoursite.com/news.php?id=' . $i);
$rss->itemDescription('This is short news description number ' . $i);
$rss->itemAuthor('email@yoursite.com');
$rss->itemGuid('http://www.yoursite.com/news.php?id=' . $i);
$rss->itemSource('YourSiteName', 'http://www.yoursite.com/rss/rss.xml');
$rss->addItem();
}
echo $rss->RSSdone();
?>
Prototypes and description:
---------------------------
Full documentation of RSS 2.0 standard you can find at http://blogs.law.harvard.edu/tech/rss
Legends:
--------
*R - required function
*O - optional function
= '' - optional parameter inside the function
- $rss = new rss($encoding = '');
- function channel($title, $link, $description);
*R
- function language($language);
*O
- function copyright($copyright);
*O
Copyright notice for content in the channel
- function managingEditor($managingEditor);
*O
Email address for person responsible for editorial content
- function webMaster($webMaster);
*O
Email address for person responsible for technical issues relating to channel
- function pubDate($pubDate);
*O
The publication date for the content in the channel
All date-times in RSS conform to the Date and Time Specification of RFC 822
- function lastBuildDate($lastBuildDate);
*O
The last time the content of the channel changed
- function category($category, $domain = '');
*O
Specify one or more categories that the channel belongs to
Follows the same rules as the function itemCategory();
- function cloud($domain, $port, $path, $registerProcedure, $protocol);
*O
Allows processes to register with a cloud to be notified of updates to the channel,
implementing a lightweight publish-subscribe protocol for RSS feeds
- function ttl($ttl);
*O
ttl stands for time to live
It's a number of minutes that indicates how long a channel can be cached before refreshing from the source
- function image($url, $title, $link, $width = '', $height = '', $description = '');
*O
Specifies a GIF, JPEG or PNG image that can be displayed with the channel
- function textInput($title, $description, $name, $link);
*O
Specifies a text input box that can be displayed with the channel
- function skipHours();
*O
function can take any numner of parameters
See the specification for skipHours tag
- function skipDays();
*O
function can take any numner of parameters
See the specification for skipDays tag
- function startRSS($path = '.', $filename = 'rss');
*O
function take path and filename for creating an XML file
It has to be called after all aabove function but before any item function
In default it will create rss.xml file in current directory
Item functions:
---------------
A channel may contain any number of item functions.
An item may represent a "story" much like a story in a newspaper or magazine
If so its description is a synopsis of the story, and the link points to the full story.
An item may also be complete in itself, if so, the description contains the text,
and the link and title may be omitted.
All elements of an item are optional, however at least one of title or description must be present.
- function itemTitle($title)
*R / *O
The title of the item
- function itemLink($link);
*O
The URL of the item
- function itemDescription($description);
*R / *O
The item synopsis
- function itemAuthor($author);
*O
Email address of the author of the item
- function itemCategory($category, $domain = '');
*O
Includes the item in one or more categories.
It has one optional attribute, domain, a string that identifies a categorization taxonomy
The value of the element is a forward-slash-separated string that identifies a hierarchic location in the indicated taxonomy.
Processors may establish conventions for the interpretation of categories.
You may include as many category elements as you need to, for different domains,
and to have an item cross-referenced in different parts of the same domain.
- function itemComments($comments);
*O
URL of a page for comments relating to the item
- function itemEnclosure($enclosure);
*O
Describes a media object that is attached to the item
- function itemGuid($guid, $isPermaLink = '');
*O
A string that uniquely identifies the item
If the guid element has an attribute named "isPermaLink" with a value of true,
the reader may assume that it is a permalink to the item, that is, a url that can be opened in a Web browser,
that points to the full item described by the <item> element
- function itemPubDate($pubDate);
*O
Indicates when the item was published
- function itemSource($source, $url);
*O
The RSS channel that the item came from
- function addItem();
*R
You place this function after all item functions.
You can create unlimited number of items.
- function RSSdone();
*R
This is the last you write in your code
- function clearRSS();
*R / *O
You write this function if You want to create a new RSS channel without reinitializing the class
Click to
Download File| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Miscellaneous Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
David Barnes, Lead Evangelist for IBM Emerging Internet Technologies will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve. FREE! Go There Now!
|
|
|
|
Build secure Web services with transport-level security using IBM Rational Application Developer V7 and IBM WebSphere Application Server V6.1. Follow this three-part series for step-by-step instructions about how to develop Web services and clients, configure HTTP basic authentication, and configure HTTP over SSL (HTTPS). This first part of the series walks you through building a Web service for a simple calculator application. You generate and test two different types of Web services clients: a Java Platform, Enterprise Edition (Java EE) client and a stand-alone Java client. You also handle user-defined exceptions in Web services. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Business Modeler Advanced V6.1.1, IBM’s premier business process modeling and analysis tool for business users that offers process modeling, simulation, and analysis capabilities. IBM WebSphere Business Modeler helps you visualize, understand, and document business processes for continuous improvement. FREE! Go There Now!
|
|
|
|
Listen to this webcast to get an overview of Info 2.0 and a technical demo of how to quickly build an enterprise mashup. IBM's Info 2.0 technology leverages emerging Web 2.0 technologies such as mashups, feeds, AJAX, and JSON in order to simplify assembly of information using feeds and services. Come learn about the technical elements of Info 2.0 including the Feed Generation framework, Mashup Engine, and mashup assembly components. Learn how to pull information from databases, departmental information, and the Web to create mashups critical to your company’s success. We will also discuss best practices to help you get started. FREE! Go There Now!
|
|
|
|
Learn how to do more with your reusable assets with the free Rational Asset Manager eKit. The eKit includes demos on how Rational Asset Manager tracks and audits your assets in order to utilize them for reuse. Plus you’ll find white papers and a Webcast that discuss the challenges of a Service Oriented Architecture and how Rational Asset Manager can provide quick and effective solutions. FREE! Go There Now!
|
|
|
|
Rational Modeling Extension for Microsoft .NET enhances usability for code generation supporting a more intelligent refactoring. The latest enhancements enable organizations with Java and .NET systems and software development maintain architectural integrity across heterogeneous platforms. FREE! Go There Now!
|
|
|
|
As organizations have grown increasingly dependent on online software, the risk of malicious attacks has also become far more serious. Fortunately, well-governed organizations can protect their Web applications by injecting vulnerability assessments and ethical hacks into their software development and delivery processes. This paper describes 12 of the most common hacker attacks and provides basic rules that you can follow to help create more hack-resistant Web applications. FREE! Go There Now!
|
|
|
|
Try the latest version of IBM Rational Manual Tester V7.0.1 by downloading a free trial from IBM developerWorks. This manual test authoring and execution tool promotes test step reuse to reduce the impact of software change on testers and business analysts and addresses the needs of teams performing at least a portion of their testing manually. FREE! Go There Now!
|
|
|
|
Explore how Rational and WebSphere software enable enterprise documentation in SOA environments. Specifically, a new integration between IBM WebSphere® Business Modeler and IBM Rational® Method Composer software can help technical writers more easily keep enterprise operations manuals in sync with changes that are made to business processes, resulting in more accurate and timely documentation that benefits the entire enterprise. FREE! Go There Now!
|
|
|
|
The unprecedented scope of a service-oriented architecture (SOA) initiative brings to the forefront a number of management and governance issues that were sidestepped in the past. The key to a successful SOA implementation is managing and governing activities throughout the entire SOA delivery lifecycle by ensuring that services conform to the needs of all of the business’s stakeholders. Learn how service lifecycle management allows the business to ensure that the process by which services are defined, created, tested, deployed, optimized and retired is manageable, repeatable and auditable. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |