Description
PHP RDF Parser is yet another PHP class that parses and outputs netscape's rdf/rss (whichever you would like to call them) files. PHP RDF Parser can easily be integrated into existing web content with an easy output function, or you can use the variables within the class to arrange the data however you want.
Licensed under the GNU/GPL
Downloading
The current version is: 0.1.5
You may download a tarball right here.
Retriving RDFs To Parse Them
PHP RDF Parser allows you to retrive rdf feeds from the internet on the fly. Simply name the url to download the rdf from and PHP RDF Parser will take care of the rest. Of course, if the site you are reading from is down, you are left without your feed. You may want to run something like my little perl program I call rdfgetter.pl. You may download it from here. Right now, I have rdfgetter.pl setup as a cron job that fires every 15 minutes. The perl program looks at a database and downloads all of the feeds it finds references to in a certain table. All of those variables can be set in the first part of rdfgetter.pl.
Please note that I am not currently supporting rdfgetter.pl and the comments within the code are terrible, so good luck if you choose to use it. If you feel like it, you can email me and I will try to answer your questions.
Usage/Instructions
The basic steps for using PHP RDF Parser are, declare the use of the class, declare a new class, parse the file, and output the results. Here's some sample code to get you started:
require ("/home/httpd/html/rdf_class.php"); //notice the full file system path
$channel = new rdfFile("/home/httpd/html/news.rdf"); //again, full system path
$channel->parse(True);
$channel->ReturnTable(True, "#00FF00", "#FFFFFF", 200);
The sample code above outputs a table that is 200 pixels wide with the title
cell (at the top) with a background color of green and a main body text
background color of white. The comments for each item will be listed along
with the links/titles for each item.
Also, the True parameter value for the parse function tells the parser to
check for encoding mistakes. This is handy in case the author of the rdf
file forgot to strickly use Latin-1 encoding. In essence, making this value
True will get rid of all rogue ampersands in the rdf/rss file.
The parsing functions listed below should be used in the order they are listed. If you try to reverse the order, things will not work. (obviously)
- $item = new rdfFile(string filename)
- The filename passed to the class should be the full system path (see the example above) or a URL (i.e. http://www.mysite.com/mynews.rdf).
- $item->parse(boolean CheckEncoding)
- CheckEncoding should be either True of False.
If CheckEncoding is True, the rdf/rss file will be searched for ampersands (&) without pound signs (#) following them. If the &# sequence is found, it is assumed that the encoding is correct and leaves the characters alone. If an ampersand is found without a following pound sign, the ampersand is removed.
If CheckEncoding is False, no check is done and you should assure that there are no rogue ampersands in the rdf/rss file because the php xml parser does not like them.
- $item->ReturnTable(boolean comments, string titlebgcolor, bodybgcolor[, string tablewidth, int borderwidth, string bordercolor])
- The argument comments should be True or False. If comments is True, the comments (if any) for each item in the rss/rdf will be displayed after the title/link of the item. If comments is False, the comments will not be displayed and the function will only output the title/link for each item.
Both the titlebgcolor and the bodybgcolor strings should be html hexidecimal color values (ex: #00FF00).
The string tablewidth is an optional argument and should be the width (in pixles or percentage followed by the % sign) that you wish the table to be.
The integer borderwidth is an optional argument and is the width of the border you want around the rdf content.
The string bordercolor is an optional argument and is the color of the border you want around the rdf content.
The variables from within the class that you may find helpful are listed and described below. These variables cannot be called until you call the parse function. In the descriptions below, it is assumed that $item is an object of the rdfFile class.
- $item->ChannelTitle
- $item->ChannelDescription
- $item->ChannelTitleLink
- ChannelTitleLink is the url of the home page for the channel (<a></a>).
- $item->ChannelLanguage
- $item->ChannelRating
- $item->ChannelCopyright
- $item->ChannelPubDate
- $item->ChannelLastBuildDate
- $item->ChannelDocs
- $item->ChannelManagingEditor
- $item->ChannelWebmaster
- $item->ChannelImageTitle
- $item->ChannelImageUrl
- ChannelImageUrl is the url of the image to be displayed (<img>).
- $item->ChannelImageLink
- ChannelImageLink is the url that the image should link to (<a></a>).
- $item->ChannelImageWidth
- $item->ChannelImageHeight
- $item->ChannelImageDescription
- $item->ChannelSkipHours
- ChannelSkipHours is an array that contains the hours in the Channel-skipHours-hour tags.
- $item->ChannelSkipDays
- ChannelSkipDays is an array that contains the days in the Channel-skipDays-day tags.
- $item->Items
- Items is a two-dimensional array containing the collective contents of title, link, and description for each item.
e.g.:
$item->Items[0]["Link"] holds the url/link for the first item.
$item->Items[0]["Title"] holds the title of the first item.
$item->Items[0]["Description"] holds the description for the first item.
- $item->TextInputTitle
- TextInputTitle is the title of the form field text box.
- $item->TextInputDescription
- $item->TextInputName
- TextInputName is the name of the form field to be submited (<input type="text" name="HERE">).
- $item->TextInputLink
- TextInputLink contains the url that the form should be submited to (<form action="HERE">).
Copyright(c) Jason Williams (jason at sign goes here jasonandann.com)