Category Archives: rss

My Bookmarks – A WordPress plugin to show your valuable bookmarks on sidebar

If you are using delicious or simpy as your bookmarking tool, this plugin is for you. This will help a wordpress user to show his valuable bookmarks on sidebar. Just install this plugin and set your options in plugins settings page – you are done. When you add or update links on your bookmarking site, this section will be automatically updated.

my_bookmarks

The settings page of My Bookmarks in wordpress admin panel

Download

Click here to download the My Bookmarks WordPress plugin (80.3 KB).

Downloaded : [downloadcounter(my_bookmarks)] times

To see a live demo, see the “My Bookmarks” section of sidebar of this blog.

Installation

Installation of this plugin is very easy. First, be sure that you are using latest(2.6) version of wordpress. Then follow this 3 easy steps.

  1. Extract and upload the `MyBookmarks` directory to the `/wp-content/plugins/` directory.
  2. Activate the plugin through the Plugins menu in WordPress.
  3. Go to Settings > My Bookmarks page and make it yours.

Upcoming features

I’ve planned to add some more feature in next version of this plugin. Your comment about any modification or feature request is very mush welcome.

  1. Add caching to store link information in your server. So that, no need to fetch from feeds every time.
  2. Allow more bookmark sites like digg, netvouz, etc.
  3. Adding additional links with parsed feed.
  4. Make independent about enabling blogroll.
  5. ……….. and more.

For any Question/Suggestion please contact me at admin@ajaxray.com

Happy bookmarking, Happy blogging!

PHP Universal Feed Parser – lightweight PHP class for parsing RSS and ATOM feeds.

After the PHP Universal Feed Generator, I’ve written the PHP Universal Feed Parser for Orchid Framework. It’s a RSS and ATOM parser written in PHP5. Though there are many feed parsers over Internet, none of those was serving the basic focuses of Orchid: pure object orientation, being lightweight etc. So, I had to write a new one.

UPDATE(15th May, 2008) : cURL support added. Where url fopen() is disabled, the class will use cURL to load the RSS/ATOM content.

Features:

  • Parses all channels and feed item tags and sub tags.
  • Serve the parsed data as associative array.
  • Enough documented and easy to understand code.
  • Many ways to get parsed information.
  • Parsing includes attributes too.
  • No regular expression used.
  • Parsed by XML Parser extension of PHP.
  • Pure PHP5 objected oriented.
  • Enable to parse all commonly used feed versions.

Supported versions: I tried to include all stable and commonly used feed versions. Currently it’s being used to parse the following versions:

  • RSS 1.0
  • RSS 2.0
  • ATOM 1.0

Download:

  • Click Here to get the class file with example. (downloaded [downloadcounter(feedparser)] times)
  • Download from phpclasses.org.

How to use:

It’s dead simple to use this class. Just follow this 3 steps:

1. Include the file

include(‘FeedParser.php’);

2. Create an object of FeedParser class

$Parser = new FeedParser();

3. Parse the URL you want to featch

$Parser->parse(‘http://www.sitepoint.com/rss.php’);

Done.

Now you can use this functions to get various information of parsed feed:

  • $Parser->getChannels() – To get all channel elements as array
  • $Parser->getItems() – To get all feed elements as array
  • $Parser->getChannel($name) – To get a channel element by name
  • $Parser->getItem($index) – To get a feed element as array by it’s index
  • $Parser->getTotalItems() – To get the number of total feed elements
  • $Parser->getFeedVersion() – To get the detected version of parsed feed
  • $Parser->getParsedUrl() – To get the parsed feed URL

A simple example:

Here is a simple example of using this Feed Parser class. Click here to see is the output of this example.

<span style="color: #0000ff;">&lt;?</span><span style="color: #800000;">php</span>
<span style="color: #ff0000;">include</span>(<span style="color: #0000ff;">'FeedParser.php'</span>);
$<span style="color: #ff0000;">Parser</span>     = <span style="color: #ff0000;">new</span> <span style="color: #ff0000;">FeedParser</span>();
$<span style="color: #ff0000;">Parser-</span><span style="color: #0000ff;">&gt;</span>parse('http://www.sitepoint.com/rss.php');

$channels   = $Parser-<span style="color: #0000ff;">&gt;</span>getChannels();
$items      = $Parser-<span style="color: #0000ff;">&gt;</span>getItems();
?<span style="color: #0000ff;">&gt;</span>
<span style="color: #0000ff;">&lt;</span><span style="color: #800000;">h1</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="title"</span><span style="color: #0000ff;">&gt;&lt;</span><span style="color: #800000;">a</span> <span style="color: #ff0000;">href</span>="&lt;?<span style="color: #ff0000;">php</span> <span style="color: #ff0000;">echo</span> $<span style="color: #ff0000;">channels</span>[<span style="color: #0000ff;">'LINK'</span>]; ?<span style="color: #0000ff;">&gt;</span>"<span style="color: #0000ff;">&gt;&lt;?</span><span style="color: #800000;">php</span> <span style="color: #ff0000;">echo</span> $<span style="color: #ff0000;">channels</span>[<span style="color: #0000ff;">'TITLE'</span>]; ?<span style="color: #0000ff;">&gt;&lt;/</span><span style="color: #800000;">a</span><span style="color: #0000ff;">&gt;&lt;/</span><span style="color: #800000;">h1</span><span style="color: #0000ff;">&gt;</span>
<span style="color: #0000ff;">&lt;</span><span style="color: #800000;">p</span> <span style="color: #ff0000;">id</span><span style="color: #0000ff;">="description"</span><span style="color: #0000ff;">&gt;&lt;?</span><span style="color: #800000;">php</span> <span style="color: #ff0000;">echo</span> $<span style="color: #ff0000;">channels</span>[<span style="color: #0000ff;">'DESCRIPTION'</span>]; ?<span style="color: #0000ff;">&gt;</span> <span style="color: #0000ff;">&lt;/</span><span style="color: #800000;">p</span><span style="color: #0000ff;">&gt;</span>

<?php foreach($items as $item): ?>

    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">a</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="feed-title"</span> <span style="color: #ff0000;">href</span>="&lt;?<span style="color: #ff0000;">php</span> <span style="color: #ff0000;">echo</span> $<span style="color: #ff0000;">item</span>[<span style="color: #0000ff;">'LINK'</span>]; ?<span style="color: #0000ff;">&gt;</span>"<span style="color: #0000ff;">&gt;&lt;?</span><span style="color: #800000;">php</span> <span style="color: #ff0000;">echo</span> $<span style="color: #ff0000;">item</span>[<span style="color: #0000ff;">'TITLE'</span>]; ?<span style="color: #0000ff;">&gt;&lt;/</span><span style="color: #800000;">a</span><span style="color: #0000ff;">&gt;</span>
    <span style="color: #0000ff;">&lt;</span><span style="color: #800000;">p</span> <span style="color: #ff0000;">class</span><span style="color: #0000ff;">="feed-description"</span><span style="color: #0000ff;">&gt;&lt;?</span><span style="color: #800000;">php</span> <span style="color: #ff0000;">echo</span> $<span style="color: #ff0000;">item</span>[<span style="color: #0000ff;">'DESCRIPTION'</span>]; ?<span style="color: #0000ff;">&gt;&lt;/</span><span style="color: #800000;">p</span><span style="color: #0000ff;">&gt;</span>
<span style="color: #0000ff;">&lt;?</span><span style="color: #800000;">php</span> <span style="color: #ff0000;">endforeach</span>;?<span style="color: #0000ff;">&gt;</span>

I hope, this class is so easy that, anyone who have general knowledge about PHP5 can use it. Whatever it is, Feel free to ask me anything, anytime.


Note : Hi all, I’ve reported about some situations from users where this class is not working properly. So, I’ve decided to re-write it ASAP. Hope the next one will be more powerful, smaller in size and easier to use.
— Thanks.

PHP Universal Feed Generator (supports RSS 1.0, RSS 2.0 and ATOM)

It’s been a while since I’ve planned on developing a RSS writer that fulfills most my needs by supporting the various feed formats. Although the necessity was the prime force behind it, a discussion with Hasin and Emran has put the actual fire in. We were discussing about what can be added next in the Orchid – “PHP framework for the rest of us” and suddenly it hit me. At last, it’s finally complete and I’ve named it “PHP Universal Feed Generator“, as it generates both ATOM and RSS feeds.

Supported versions:

  • RSS 1.0 (which officially obsoleted RSS 0.90)
  • RSS 2.0 (which officially obsoleted RSS 0.91, 0.92, 0.93 and 0.94)
  • ATOM 1.0

Download:

Features:

  • Generates RSS 1.0, RSS 2.0 and ATOM 1.0 feeds
  • All feeds are are validated by feed validator.
  • Supports all possible feed elements.
  • Simple and easy to define channel and feed items
  • Implements appropriate namespaces for different versions.
  • Automatically converts date formats.
  • Generates UUID for ATOM feeds.
  • Enables usage of subtags and attributes. (example: image and encloser tags)
  • Completely Object oriented in PHP5 class structure.
  • Handles CDATA encoding for required tags.
  • Nearly same code for generating all kinds of feed

A minimum example

It’s a minimum example of using this class. I am generating a RSS 2.0 feed from retrieved data from a MySQL database. There are more examples in the download package for different versions.

&lt;?php
  <span style="color: #008000;">// This is a minimum example of using the Universal Feed Generator Class</span>
  include(<span style="color: #006080;">"FeedWriter.php"</span>);

  <span style="color: #008000;">//Creating an instance of FeedWriter class. </span>
  $TestFeed = <span style="color: #0000ff;">new</span> FeedWriter(RSS2);

  <span style="color: #008000;">//Setting the channel elements</span>
  <span style="color: #008000;">//Use wrapper functions for common channel elements</span>
  $TestFeed-&gt;setTitle(<span style="color: #006080;">'Testing &amp; Checking the RSS writer class'</span>);
  $TestFeed-&gt;setLink(<span style="color: #006080;">'http://www.ajaxray.com/projects/rss'</span>);
  $TestFeed-&gt;setDescription(<span style="color: #006080;">'This is test of creating a RSS 2.0 feed Universal Feed Writer'</span>);

  <span style="color: #008000;">//Image title and link must match with the 'title' and 'link' channel elements for valid RSS 2.0</span>
  $TestFeed-&gt;setImage(<span style="color: #006080;">'Testing the RSS writer class'</span>,<span style="color: #006080;">'http://www.ajaxray.com/projects/rss'</span>,<span style="color: #006080;">'http://www.rightbrainsolution.com/images/logo.gif'</span>);

    <span style="color: #008000;">//Retriving informations from database</span>
    mysql_connect("server", "mysql_user", "mysql_password");
    mysql_select_db("my_database");

$result = mysql_query(“Your query here”);

 

    <span style="color: #0000ff;">while</span>($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
        <span style="color: #008000;">//Create an empty FeedItem</span>
        $newItem = $TestFeed-&gt;createNewItem();

        <span style="color: #008000;">//Add elements to the feed item    </span>
        $newItem-&gt;setTitle($row[<span style="color: #006080;">'title'</span>]);
        $newItem-&gt;setLink($row[<span style="color: #006080;">'link'</span>]);
        $newItem-&gt;setDate($row[<span style="color: #006080;">'create_date'</span>]);
        $newItem-&gt;setDescription($row[<span style="color: #006080;">'description'</span>]);

        <span style="color: #008000;">//Now add the feed item</span>
        $TestFeed-&gt;addItem($newItem);
    }

  <span style="color: #008000;">//OK. Everything is done. Now genarate the feed.</span>
  $TestFeed-&gt;genarateFeed();
?&gt;

Shhhh….a universal feed reader is on the way ;)