Category Archives: tools

Simple PHP PDO Wrapper : light, static, easy

A few days ago, I was looking for a PDO wrapper to work with a small PHP application. I’ve searched around and found fractalizer’s PDO wrapper nearest to my purpose. Then I just wrote my wrapper on the shadow of his one.

Let’s see what’s inside and how it works.

Features

  1. Easy to use.
  2. Works with MySQL and Sqlite.
  3. All pubic functions works statically.
  4. Connection string created internally.

Get the files

From github, you can clone/fork/ download the files.
Github repository https://github.com/ajaxray/static-pdo

The download archive/repository includes –

  • Db.php – the PDO Wrapper class.
  • DbTest.php – Unit testing class for Db.
  • DbExample.php – Example of some common uses.
  • Some other unit test related files.

Continue reading

Front-end optimization with PHP Speedy – increase Yslow grade in 10 minutes!

Before I move into PHP Speedy, a small background won’t hurt much! Until a few days back, whenever I hear the word optimization, my brain quickly shows a few keywords in my mental screen: “query optimization, page caching, opcode, etc”. All these terms and the associated work relates to the optimization of a web application in the back-end. This has been serving my need pretty good, until I became aware about the excellent 13-point front-end optimization techniques from Yahoo (thanks Emran bhai).

At first I was a bit skeptical, but as soon as I started seeing the points – I knew its importance. Without much delay, I gave it a short in my latest project at work. And the tool that made it a less than 10 minute work is: PHP Speedy. I am literally speechless with it’s performance and way of working. Just in 10 minuets, It upgraded the Yslow grade of our project from 43 to 88.  Just like a magic touch!

php_speedy_logo_medium

Now, let’s see what Yslow Grade is (for those who are not yet using it) and how php-speedy helps to upgrade it. Hope this enlightens someone like me :P

Continue reading

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!

Developing web application with PHP-MySql-Apache in Ubuntu Linux

I have started using Ubuntu 8.04 in few days ago and found it Great. So, now I’ve moved my development environment from windows and working in Ubuntu. Here I am just explaining what steps I had to take for this jump. Also have a listing of some development related softwares/tools which I am using as replacement of windows applications.

Installing Apache, Php5, MySql in Ubuntu:

You can install Apache, Php, Mysql and other applications from Synaptic Package Manager. Go to System > Administration > Synaptic Package Manager and search with your desired application name. When found, double-click on package name. The package will be marked for installation along with it’s dependences. Now click on apply button to install the package. In this post, the red+bold texts are the name of software package which can be installed from Synaptic Package Manager.

To make your system ready for PHP development, you have to install more or less this packages: apache2.2-common, apache2-utils, php5, mysql-server-5.0, mysql-client-5.0, mysql-query-browser etc. You may also require some common php extensions which may not installed automatically with PHP installation. Most of them also will be found in Synaptic Package Manager as php5-gd, php5-curl, php5-mysql, php-pear etc.

Paths of important directories

One of the major differences I find here is the file system. All the directory paths I’ve been using in windows are changed here. I m listing here some PHP-MySql related paths here. But they may differ on your installation.

  • Apache configation files: /etc/apache2/
  • localhost root directory: /var/www/
  • PHP ini file: /etc/php5/apache2/
  • PHP extensions configuration files : /etc/php5/conf.d
  • MySql Data files: /var/lib/mysql/mysql
  • MySql Configuration files: /etc/mysql/

PHP Editors for Ubuntu

Gedit is the default text editor of Ubuntu and it support syntax coloring for many languages including PHP. But If you want an advanced editor for programming, you can try Geany or Screem. But, I am sure, who’ve been using advanced IDEs like PHPEd or PHPDesigner in windows, none of this can satisfy him. Don’t worry, the great open source IDE eclips has PHP-Development-Tool. It’s surely one of the best PHP IDE.

Subversion in Ubuntu

Subversion maintains current and historical versions of source code and documentation. It’s very important for distributed application development. RapidSVN is a graphical client for the subversion revision control system (svn) for linux. If you want to use svn from command line, install subversion.

File Difference and Merging Tools for Ubuntu

I have been using WinMerge in windows as file comparison and merging tool along with TortoiseSVN. Now using TkDiff as it’s alternative in linux. TkDiff has advanced functionalities and graphical interface. It provides file-merge and change-summary facilities, line number toggling (for easier cut & paste) and support for Subversion, RCS, CVS and SCCS. To use from command line, diff is may be the simplest file comparison tool.

Ftp and SSH

Ubuntu installs its default programs for FTP, SSH and many other internet applications. But, I’ve liked gFTP as FTP application because of it’s interface is similar to SmartFTP. And for working with SSH, required nothing. Just open the terminal and use ssh command. Write something like ssh username@example.com and press ENTER.

Testing in IE

One of the important (and painful to me) issue of web development is testing the output in IE. Though IE has no version for Linux, you can install it through wine. Wine is a application that crates a virtual environment for installing windows applications in Linux. After installing wine, you can install any available version of IE from http://www.tatanka.com.br/ies4linux/page/Installation:Ubuntu.

When witting this post, my aim was to help a developer who is thinking to switch to Ubuntu Linux or a newcomer here. You are welcome to add your valuable comment/suggestion for the same purpose.

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 ;)

Windows Live Writer : Blogger’s life made easy

Windows says, "Windows Live Writer Beta is a desktop application that makes it easy to publish rich content to your blog". Really that. I have been using it recently and found it as an exclusive tool for blogging. But remember, a blogger can use windows live writer only when his blog is build on an organized blog system like WordPress, Blogger, LiveJournal, TypePad, Moveable Type, Community Server, and many other weblog services.

image   image

Windows Live focus themselves on five feature of this writer. They are:

  1. Compatible with your blog service
  2. WYSIWYG editing
  3. Rich media publishing
  4. Powerful editing features and
  5. Offline editing

Ok. Now I am going to tell you what features of this software impressed me most. First I should mention that, before using Windows Live Writer, I have been using WordPress and I was satisfied on It’s editing options. But now, I get the powerful yet easiest application for writing blog and I’m going to stay on it. Here goes my share of the praise:

  1. Offline control on everything: It has powerful editor to write/edit blogs, manage my categories etc on offline. So, it’s fast and easy. Only one thing I have to do is, just tell the writer to publish it. Then it will connect to the blog over online and automatically publish it. Moreover, it lets me see the editing post in different views which helps me to visualize how it will look like at online on my installed theme.
  2. Working with images is easiest than ever:  I get rid from the terrible duty of uploading and managing images to use them in a blog post by using writer. It lets me use image in a post and edit them just like MS Word. When an image containing post published, it manages everything.
  3. More control on Html elements: The web’s WYSIWYG editors are simply nice. But not comparable with writer’s editing facilities. It’s more than a web editor and near about a word processor. It offers smooth and flexible visual building.  
  4. Special inserting tools: Writer’s inserting tools are really rich. It can insert and smoothly manage tables, images, videos, maps(from virtual earth), colorize code snippet(need a free plug-in) etc.
  5. Rich and free Plug-ins: Though Windows Live Writer is at beta version yet, it has a large number of free plug-ins. They may solve more than a blogger needs. You can get the plug-ins here:
  6. http://gallery.live.com/results.aspx?c=0&bt=9&pl=8&st=5

Moreover, who are blogging on hosted version of WordPress, Blogger etc blogging site, they have some limitations of using plug-ins there. Writer may be a great solution for them. It also provides the ping functionality which is very important for promoting a blog.

See more details here: http://get.live.com/en-us/betas/writer_betas

You can download it from here: http://windowslivewriter.spaces.live.com/