SEO Correction in PEAR::Pager

Pagination is a common practice to show big volume of data. It is quite important if you are showing dynamically populated data.

For myself I mostly use PEAR::Pager to display paginated data. If you are familiar with this package then you know that you can use 2 types of pagination display, as – sliding and jumping. In case of sliding display with a common practice is to use it with constructor option append:true and urlVar:<variablename>.

Let me show an example of this kind of usage -

  1. $Params = array(
  2.           ‘itemData’ => $dataDetails,
  3.           ‘perPage’ => $ViewPerPage,
  4.           ‘append’ => true,
  5.           ‘separator’ => ‘|’,
  6.           ‘spacesBeforeSeparator’ => 1,
  7.           ‘spacesAfterSeparator’ => 1,
  8.           ‘clearIfVoid’ => false,
  9.           ‘urlVar’ => ‘page’,
  10.           ‘useSessions’ => true,
  11.           ‘closeSession’ => true,
  12.           ‘mode’  => ‘Sliding’,
  13.           ‘importQuery’ => true,
  14.           ‘linkClass’ => ‘LinkStyle’,
  15.           );
  16. $Pager = Pager::factory($Params);
  17. $DataDetailsInArray = $Pager->getPageData();
  18. $PaginationLinks = $Pager->getLinks();

Now if you print/echo the $PaginationLinks, then you will get pagination like 1 2 3 4 etc.

Now let me describe you the problem:
Say your page url is mydata.php. So mydata.php page will show the first page of paginated data. while using the pagination links you will get a page with url mydata.php?page=1. This page shows the first page of paginated data. Now you are having a page with 2 different url like mydata.php and mydata.php?page=1. In SEO this is known as duplicate content. This is not good if you are seriously deal with SEO.

Here is the correction for this. This is simple but effective.

  1. if(isset($_GET[‘page’]) && $_GET[‘page’] > 1)
  2. {
  3.    $PaginationLinks[‘all’] = str_replace(array(‘?page=1"’, ‘&amp;page=1"’), ‘"’, $PaginationLinks[‘all’]);
  4. }

Use this code section just after generating $PaginationLinks. Hope this will help you. As always comments/suggestions are welcome. But spammers please don’t waste your time. :)

PaginationSlider – a jQuery plugin

I have started using jQuery – JavaScript framework almost end of the last year. I have also used it for my last couple of projects. I find it very useful to design/develop complex type of functionality in the client-end. One of the interesting feature of jQuery is that it provides a large number of plugins designed by different developers. They are very useful too.

In my current project I need to display multiple content pages within a web page. I require to slide the page numbers so that user can view the number of pages by sliding/scrolling. I was looking for some good plugin which could satisfy my need. I have tested some of them but couldn’t find out the ideal one. So wrote the basic code for the functionality and the effect. However I wasn’t satisfied with my work as I was looking for some plugin for it. I thought it is the best time to try authoring plugin in jQuery.

It took almost 9 days to convert the code into a plugin. I gave the plugin namespace as paginationslider.

Code example:
Script section -

  1. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  2.    <script type="text/javascript" src="jquery.paginationslider.js"></script>
  3. <script type="text/javascript">
  4. $(document).ready(function(){
  5.    $(‘#sliderMain’).paginationslider({
  6.                                     SliderLeft:‘LeftSlide’,
  7.                                     SliderRight:‘RightSlide’
  8.                                     });
  9. });
  10. </script>

Style section –

  1. .pgSlider {
  2.   width: 80px; overflow: auto; background:#fff; margin:0 auto; position:relative; border:1px solid orange; float:left; display:inline;
  3. }
  4. .pgSlider ul {
  5.   display: block; padding: 0; margin: 0; list-style: none; position:relative;
  6. }
  7. .pgSlider ul li {
  8.   display: block; float: left; background:#E3ECF4;
  9. }
  10. .pgSlider a {
  11.   display: block; text-decoration: none; text-align:center; padding: 5px 8px; color:#1079B1; font-weight:bold; border-right:1px solid #fff;
  12. }

HTML Section –

  1. <pre class="html" name="code">
  2. <div id="paginationContainer">
  3.    <div id="LeftSlide" class="sliderArrow">&lt;&lt;</div>
  4.    <div id="sliderMain" class="pgSlider">
  5.       <ul>
  6.          <li><a href="#1">1</a></li>
  7.          <li><a href="#2">2</a></li>
  8.          <li><a href="#3">3</a></li>
  9.          <li><a href="#4">4</a></li>
  10.          <li><a href="#5">5</a></li>
  11.          <li><a href="#6">6</a></li>
  12.          <li><a href="#7">7</a></li>
  13.          <li><a href="#8">8</a></li>
  14.          <li><a href="#9">9</a></li>
  15.       </ul>
  16.    </div>
  17.    <div id="RightSlide" class="sliderArrow">&gt;&gt;</div>
  18. </div>
  19. </pre>

I will eagerly wait for your reviews on this plugin. Here you can view the demo.

Freetag PEAR DB Version

While working with tagging application my favourite is freetag by Gordon Luk. It is a comprehensive open source tagging and folksonomy code in php. The source code is also hosted in Google Code. The best feature of it is you can use this code with little modification to fit your requirement. First time I used it in advaitaashrama.org for their book store application. Currently I am using it in another website which is under development.

I am having an issue of compatibility with this code and I am writting this post for it. If you look at the code you will find that it uses the ADODB Library for database operations. In my case I am happy with PEAR::DB. Now for me to use this code I need to use 2 different database component as PEAR::DB and ADODB Library. It seems useless to me. So I decided to make the code compatiable with PEAR::DB. While working upon the compatibility modification I also made 3 changes as

  1. I have written a function as show_debug_text() which is a replacement of debug_text().
  2. I have removed the silly_list() function from my code as it was declared as deprecated.
  3. I have renamed the main class file from freetag.class.php to freetag.db.class.php

Here is the sample code for use this

  1. <php?
  2. require_once("/path-to/freetag.db.class.php");
  3. $DbObj = DB::connect($dsn, $options); //this is the database connection object using PEAR::DB
  4. $OptionArray = array(
  5.                ‘table_prefix’ => ‘mytags’,
  6.                );
  7. $TagObj = new freetag($DbObj, $OptionArray);
  8. // Use this object to call tag related functions .
  9. ?>

Here is the code modified by me.
If you use this code please let me know if you have any problem.

PHP serialization or Json

Information storage and retrieval is an important job while designing or developing an application. We all know how to store data with normal data types in database or file systems. Here I am going to discuss about storage and retrieval of data having complex type. Complex type means they are not like normal string or number or boolean values. Complex type means data structure or objects.

Think of a situation where you are working with some array. Now there may be some situations where you need to store the array and retrieve it back. If you are familiar with OOPS concept then objects are another type which you may need to store and retrieve.

Serialization is the process by which you can convert an object or data structure into a sequence of bits which can stored and retrieve back. Serialization is also known as deflating or marshalling. The opposite process (converting the serialized sequence of bits to object or data structure) is known as Deserialization or inflating or unmarshalling. Most of the important languages have their own implementation of these processes. In Java provides automatic serialization by implementing the java.io.Serializable interface. In perl there are modules like Storable or FreezeThaw. Python implements serialization through the standard library module pickle. In PHP there are two built-in functions as serialize() and unserialize() for this purpose. However as I will continue the discussion with PHP then you should be aware of the fact that – there is a difference in the implementation of serialization in PHP 4.x and PHP 5.x.

In last couple of months I need to work with JSON (JavaScript Object Notation). JSON is an ideal data interchange format which is language independent. I had used the JSON to design some Ajax driven functionality in one of my projects. Over there I had encoded into JSON some normal and associative PHP array and passed them to access by JavaScript.

After successful completion of the project I started working upon the possibilities of storing data structure or object in PHP using JSON. IN case of PHP there are two function as json_encode() and json_decode(). Interesting thing with json_decode() is that it takes a boolean argument as second parameter[$assoc] which is by default false. But when TRUE json_decode() returns objects converted in associative array. After doing a lot R&D I find out certain facts which favors JSON rather than using serialize() /unserialize(). In general if you consider the size of the stream produced by serialize() with json_encode(), later produces small sized stream. While working with data structure like arrays JSON produces the same structure after encode and decode. So in my opinion usage of JSON is better than PHP serialize()/unserialize().

Now while working with objects, JSON produces the same result as PHP serialization functions. However if the object is complex or if you like to take the benefit of magic methods object oriented PHP5 then its better to use serialize()/unserialize(). As serialize() will attempt to call _sleep() [if exists] which can be used to do some last minute clean up of the object prior to serialization. Same way unserialize() will call _wakeup()[if exists] which can be used to do some reconstruction in the object just after unserialization. So if your objects are simple then use JSON otherwise go for serialize()/unserialize().

In the conclusion I will prefer to use JSON rather than PHP serialization methods. I won’t be surprised if I get good nos of comments for/against my preference.

QuickForm and AutoSuggest

The best example of auttosuggest filed I can instantly think of is Google. While designing dynamic forms I felt the requirement of such field. As I mostly use PEAR class and HTML Quickform to design dynamic forms in php. However in HTML Quickform there is autocomplete type but still there is no support for autosuggest. I googled a lot to get such support, but found it out in RFC of HTML Quickform. So I started working upon it. My first job was to found out a autosuggest Javascript code suitable for integration. I searched out an autocomplete javascript code by Beau D. Scott

The reasons why I selected Beau’s code is :
The code is simple to use but robust and has good documentation.
It uses standard JS library like prototype and scriptaculous.

Now having previous knowledge of integration of QuickForm and Jscalender I created the code for autosuggest class. This autosuggest class file contains constructor function, toHtml function which generates the HTML code for the field, getFrozenHtml function to return the autosuggest content in HTML and finally the registering process of the autosuggest type with HTML QuickForm. I put this autosuggest class name as autosuggestwce. View this wceautosuggest.php file.

To use this autosuggest field in HTML Quickform you need to have 3 javascript files as prototype.js, scriptaculous.js and autocomplete.js. Prototype Javascript is used for javascript framework, Scriptaculous for show and hide effect and AutoComplete is the main javascript functionality file. Among them scriptaculous.js can be removed if you don’t like to show effects, but you need to modify certain section in the wceautosuggest.php file. You also need to declare $GLOBALS['_HTML_QUICKFORM_AUTOSUGGEST_BASEPATH'] the global path defining variable for the javascript files path in the page where you will generate the form.

This autosuggest uses php script to populate values. The name of the php script has to be mentioned in the $attribute array for the key ‘fileref’.

If you are using DB_Table here is snippet of code

  1. ‘user_name’ => array(
  2.                ‘type’ => ‘varchar’,
  3.                ‘size’ => 255,
  4.                ‘qf_type’ => ‘autosuggestwce’,
  5.                ‘qf_label’=> ‘UserName:’,
  6.                ‘require’ => false,
  7.                ‘qf_attrs’ => array(
  8.                            ‘id’ => ‘user_name_autosuggest’,
  9.                            ‘autocomplete’ => ‘off’,
  10.                            ‘fileref’ => ‘getusersname.php’,
  11.                                  ),
  12.                   ),

If you are using QuickForm directly then here is the code snippet

  1. $form = new HTML_QuickForm(‘someTest’, ‘get’);
  2. $form->addElement(‘autosuggestwce’, ‘username’, ‘UserName:’, "array(‘id’ => ‘user_name_autosuggest’, ‘autocomplete’ => ‘off’, ‘fileref’ => ‘getusersname.php’)");
  3. $form->display();

Here is the code segment of php script

  1. <?php
  2. $UsrObj = new CLUsrChk($DBObj, ‘hllqz_tblusers’);
  3. $SqlStatement = "SLECT user_name FROM ".$UsrObj->table." WHERE user_name LIKE (‘".$_GET[‘s’]."%’)";
  4. $UsrNameArray = $UsrObj->bd->query($SqlStatement);
  5. echo json_encode($UsrNameArray);
  6. ?>

Here is the screenshot

autosuggest_field
autosuggest_filed_populated

However if you require the files for your reference please let me about that.

I was planning to do this post almost a month ago but I was busy with learning another Javascript framework jQuery. I am started loving it. Hope I will be able to post something about jQuery in near future.

Web site hacked via HTACCESS

Here is another example how your site got hacked. I found this instance very recently in Godaddy server. This type of site hacking is not very common. You may not be able to detect any specific web page infected if you search your site using Google Diagonestic tool for safe browsing mentioned in my earlier post – Iframe code injection. In this kind of attack none of your web pages get infected but your .htaccess file gets modified and becomes the main source of redirection to malware containing site. Let me show you an infected .htaccess file for example.

hacked_htaccess

Modified HTACCESS file used for hacking

Experienced developer can understand why this is so dangerous. Let me explain a little for the newbies. In case of apache web server configuration directives are described in httpd.conf file. Many cases this file can’t be accessed or modified due to security reasons. So to change some configuration directives for a specific website or its sub directory best solution is to use .htaccess file. To know further about .htaccess file and its functionality you can read .htaccess files. However URL rewriting, URL redirection, authentication are the important functionality .htaccess file are used for.

In the example htaccess file there are 3 sections. First line is for instructing the apache web server to put the rewrite engine on. This is first section. Second section goes from line no. 2 to line no. 8. This section is basically for condition checking on URL. Its checking if the visitors are coming from a website or page with URL containing the following words like google, aol, msn, yahoo, yandex, rambler or ya. NC means pattern checking will be case insensitive. OR means combines with other rule. Third section is in line no. 9. It says if any of the above pattern checking become true then it will redirect to the specified URL. Here R means redirection. Normally this generates HTTP response code 302 means moved temporarily. L means this is the last rule.

So the result is that if some visitor coming to the site from above specified search engine, they will be simply redirected to the malware site without understanding whats happening. So be careful if you come to know your site gotta hacked and youre unable to find out why then take a look at your .htaccess file.

The KBM-09

Hey, if you are thinking that I am going to talk about a application or software, then stop thinking. Its not a sofware/code/appliaction or somthing like that. Its all about a successful event happened last Saturday on 8th August 2009. Its Kolkata Bloggers Meet 2009 organised by Webreps in Cafe Coffee Day, RDB Adlabs Sector V, Saltlake City.

A cozy moment

A cozy moment

It was a wonderful evening with great atmosphere, good mass of perticipents, also good food and drink. I really enjoyed the evening and actually learnt a lot about blogging. Speeches from Aji Issac Mathew, Arun Agarwal, Vikas Kedia, Abhishek Rungta and Saptarshi Roy Chaudhury were really valuable inputs. Most interesting part was the interaction between bloggers. So many people exchanging ideas, thoughts upon such a topic called blogging. It is really unbelievable. I am damm sure that who ever wasn’t present over there missed a lot. More over I got chances to meet my old friends and colleagues specially Anand and Debasish. One thing I must say, I was almost spellbound when I saw Soham’s presentation.

Our anchor

Our anchor


Friends from Webreps

Friends from Webreps

I don’t have any dought upon the anchoring capabilities of Kamanashish aka Mr. Doubt. Also I am very much sure that Anirudh, Saikat, Simul will be able to take the next meet in more bigger level. You guyes simply rocked. I like to thanks all the guyes and gals who were there and made the event successfull. Also thanks to Cafe Coffee Day for creating such a cozy atmosphere.

The pictures taken by my Nokia E51 are not so good, you should visit Yogesh’s post for wonderfull pictures of Kolkata Bloggers Meet.

The meet gave a tremendous effect on me as a blogger (back banchers is approtiate for me). Surprisingly I am able to make this within few hours :o . I will surely going to spend more time for my blog and … wait and watch.

Iframe code injection

After a long days I am back for blog post. Last one month I was very much irritated with the problem occurred in some of my client website. In a Sunday morning while I was sleeping one of my client ranged me and asked me to check her website as she got a mail from google that her website is spreading malware. I got confused as I had never faced this kind of problem. I started checking the website. But the antivirus in my Laptop didn’t allowed me to open the site at all. Then I decided to go to my office to check the situation.

In my office I checked the site thoroughly(OMG, I was able to open the site in my office). I found iframe code with hidden visibility was inserted in some pages. To be more specific index pages. I checked all the index pages in office PC, deleted the infected pages in the server and uploaded the pages from PC. Checked, cleaned all the html, php, temporary files. Almost near about afternoon I was back to my home while thinking how this happened.

Iframe Injected

Iframe Injected

Next Morning after arriving in the office I started checking the website and I found it was again infected by the hidden iframe. Site url was different as earler it was .cn and next day it was .ru I was upset about how to fix the things. Believe me or not in the last one month this site got infected 27 times. Our team had experienced the same attack for 5 more site. It was a horrible experience for us.

We had done lot of googleing to find out the preventive measurement. We found out lots of information regarding this. Some of them are good and some of them are misleading too. So here I like to point out some effective ones only.

  1. You should have good antivirus installed in your system from where you access web. I am using avast free edition and it works fine for me.
  2. Please check your websites on a regular basis. If you see if any web page with a blank section in the top them be almost sure that it is infected. Your antivirus should give you warning.
  3. If you find any of your website get infected then start following the next steps.
  4. First of all scan your machine with the antivirus. A boot time scan is more preferable.
  5. Replace all the pages in the website using a local copy from your system. If the web site is too big to repalce then try to repalce all the pages with name index. Then check the site again.
  6. Once the site is cleaned change the ftp details for the site and if possible do the same for the other sites whose details are kept in your ftp application.
  7. Keep checking the site in a short span of interval.

You should also check your site in google too. If google find out some problem with your site they may have shown a warning message like “This site may harm your computer”. Another way to check your site is

http://www.google.com/safebrowsing/diagnostic?site=http://www.yourdomain.tld

If you find that google is showing the warning message for your site you can request Google for a recheck via Google Webmaster Tool. But you should check the site twice after cleaning and then request for review.

However I have designed a code in php for checking mainly the index pages in the website. Here is the code.

  1. <?php
  2. // page-checker.php
  3. $path = ".";
  4. $baseDir = basename(dirname($_SERVER[‘PHP_SELF’]));
  5. $WebPath = ‘http://’.$_SERVER[‘HTTP_HOST’].‘/’.$baseDir;
  6. $content_pattern = "iframe";
  7. echo "Checking files for IFRAME Infection<br/>";
  8. $dir_handle = @opendir($path) or die("Unable to open $path");
  9. echo "Directory Structure of $WebPath<br/>";
  10. navigate($dir_handle, $path, );
  11. function navigate($dir_handle,$path, $WebPth)
  12. {
  13.    global $WebPath, $content_pattern;
  14.    echo "<ul>";
  15.    while (false !== ($file = readdir($dir_handle)))
  16.    {
  17.       $dir = $path.‘/’.$file;
  18.       if(is_dir($dir) &amp;&amp; $file != ‘.’ && $file !=‘..’ )
  19.       {
  20.          $handle = @opendir($dir) or die("undable to open file $file");
  21.          $WebRef = $file.‘/’;
  22.          navigate($handle, $dir, $WebRef);
  23.       }
  24.       elseif($file != ‘.’ &amp;&amp; $file !=‘..’)
  25.       {
  26.          if(preg_match(‘/^index+/’,$file))
  27.          {
  28.             $ChcekFlag = FALSE;
  29.             echo "<li>";
  30.             echo "<a href=’".$WebPath.$WebPth.$file."’>".$WebPth.$file."</a><br />";
  31.             $handle = @fopen($dir, "r");
  32.             if ($handle)
  33.             {
  34.                while (!feof($handle))
  35.                {
  36.                   $content = fgets($handle);
  37.                   if(stristr($content, $content_pattern))
  38.                   {
  39.                      $test = stristr($content, $content_pattern);
  40.                      echo $test."<br />";
  41.                      $ChcekFlag = TRUE;
  42.                   }
  43.                }
  44.             }
  45.             fclose($handle);
  46.             if($ChcekFlag)
  47.             {
  48.                echo "<font color=’red’>Infected</font><br />";
  49.             }
  50.             else
  51.             {
  52.                echo "<font color=’green’>Clean</font><br />";
  53.             }
  54.             echo "</li>";
  55.          }
  56.       }
  57.    }
  58.    echo "</ul>";
  59. }
  60. ?>

you can put this code in the root level of your website (in www or public_html or httpdocs). Browsing this page will show all the index pages with status of it.

Current I am working upon extending the code so that it can clean the infected pages automatically. Hopefully I will post it within few days.

Tricky Sql Statements

Here are some tricky Sql statements that can be used in some specific cases. I figured them out in certain cases where I needed to do data manipulation directly on the database instead of writing script to accomplish them. I will describe them in case study style.

Case 1:

In one of my project there is a user table containing fields like userId, UserName, UserLoginID, Password etc. The UserLoginID field is basically the email address. Almost 95% of the email addresses belongs to a specific domain that is the domain of the project. Let’s say testproject.com. The table contains approx 12,000 records. In that project client decided to shift their main tld from .com to .org like testproject.com to testproject.org. Now they asked me to change the all the users’ email from .com to .org. That means user1@testproject.com to user1@testproject.org I needed to do this job within a shortest span of time. So I decided to run a sql command directly in the database to do the modification. A simple UPDATE sql won’t work in that situation as I needed to change some part of a field and also update statement shouldn’t affect those rows which do not contain testproject.com. So I tried with different types of update sql to do the job but finally derived the following one :-

  1. UPDATE tblUser SET UserLoginID = REPLACE(UserLoginID, ‘ testproject.org’, ‘ testproject.com’);

The beauty of this statement lies in the usage of replace function. This replace function will synchronously select records having ‘testproject.com’ implementing functionality of the Where clause and generate the value to be set for the field UserLoginID as @testproject.org

Case 2:

This case was relatively easy. I need to find out unique entries from a table. It was not a hard job for me but still I googled a bit for this purpose. Now after some study I come to a position where I could do that using two different sql statements. They are :-

  1. SELECT product_code FROM tblproductdetails GROUP BY product_code;

and

  1. SELECT DISTINCT product_code FROM tblproductdetails;

While looking at the results I found both of them produces same result but the only differnce is Select DISTINCT does not sort the result set like GROUP BY does. So I wasn’t sure which one should used. SELECT DISTINCT vs GROUP BY – udbug | Google Groups helped me to chose the correct statement as Select DISTINCT. So I used the following :-

  1. SELECT DISTINCT product_code FROM tblproductdetails ORDER BY product_code

Case 3:

This is also related with the earlier case of unique entries. This time I need to find out the ids which have duplicate entries. Almost the opposite job than the previous one. Well this statement also uses distinct but along with Group by clause gives the entries which have duplicates in the table. Here is the statement.

  1. SELECT DISTINCT regn_id FROM tblstudentdetails GROUP BY regn_id HAVING count(regn_id) > 1;

This statement is very useful to find out entries which have duplicates in the tables.

Somebody asked me earlier how do I learn php and database? My answer was – learn the basic, find some real-life project to work for, take the challenge to complete it. You would face lots and lots problem while doing that. Don’t try to get rid of them but try to solve them. When you would finish the job you will understand the difference in you in terms of practical knowledge. I hope you all agree with me. :)

Picasa web album slideshow – Development guide

I was looking for a application to embed slideshow using pictures from picase web album. I found some plugins which can be used in blog or myspace. Some of them uses the picasa slide show url opened in a iframe or div. Then you will have less control on the slideshow as it is controlled by the slideshow application of picasa. But I required more control on the images from picasa.

I was looking for some application which will fetch/store all the images for an album in picasa and create a slideshow with more control on the images. I found nothing thats suites my requirement. So I started to design an application of such kind. On the basis of functionality I sub devided it into two major part. First is fetch the image related information for an album and store it if required. Second is display the slideshow using those image information.

In picasa you can view the pictures as set or individual but you won’t get actual picture name or its location. So I found now simple way to get the pictures name and their location. While searching more for such option I found there is a RSS feed for each album. The RSS feed provides image names and its location details. It makes my job easier. Now objective became to process the RSS feed to get the image related information. For this purpose I used XML-RSS package from PEAR. Here is snapshot of the code I wrote to process the feed:

  1. <?php
  2. require_once "XML/RSS.php";
  3. //$FeedURL is the URL of the rss feed of an album in picasa
  4. $FeedURL = "http://picasaweb.google.com/data/feed/base/user/wce/albumid/5331321673727336541?alt=rss&kind=photo&hl=en_GB";
  5. $rss =& new XML_RSS($FeedURL);
  6. $rss->parse();
  7. $rssArray = $rss->getStructure();
  8. $PicasaDataArray = array();
  9. $InfoArray = array();
  10. for($C=0; $C<count($rssArray); $C++)
  11. {
  12.    if($rssArray[$C][‘type’] == ‘item’)
  13.    {
  14.       $PicasaDataArray[] = array(
  15.                               ‘title’ => $rssArray[$C][‘title’],
  16.                               ‘image’ => $rssArray[$C][‘enclosures’][0][‘url’],
  17.                               ‘link’ => $rssArray[$C][‘link’],
  18.                               ‘description’ => $rssArray[$C][‘description’],
  19.                               );
  20.    }
  21.    elseif($rssArray[$C][‘type’] == ‘image’)
  22.    {
  23.       $AlbumTitle =  $rssArray[$C][‘title’];
  24.       $AlbumPicture =  $rssArray[$C][‘url’];
  25.       $CreateDate =  $MetaInfo[‘lastbuilddate’];
  26.    }
  27. }
  28. // this $PicasaDataArray contains all the picture related information of an album from picasa web.
  29. ?>

Now this $PicasaDataArray can be stored in files/database or can be directly used for the slideshow. While processing the feed by this I found the feed contain other information like title, description, link of the album, its last build date etc. So I modified the code a little more to store these information too. So the first part of my application is complete.

Now the second part – slideshow using $PicasaDataArray. For this section I didn’t tried to put my head to develop slide show application as I had already seen some very nice attractive slideshow application. They are also easy to use and configure. One of my favourite is Lightbox JS. Another good slideshow script is Highslide. Both of them are very nice and easy to configure. So I used one of them for my purpose. Here is another snapshot of code

  1. <?php
  2. require_once "XML/RSS.php";
  3. //$FeedURL is the URL of the rss feed of an album in picasa
  4. $FeedURL = "http://picasaweb.google.com/data/feed/base/user/wce/albumid/5331321673727336541?alt=rss&kind=photo&hl=en_GB";
  5. $rss =& new XML_RSS($FeedURL);
  6. $rss->parse();
  7. $rssArray = $rss->getStructure();
  8. $PicasaDataArray = array();
  9. $InfoArray = array();
  10. for($C=0; $C<count($rssArray); $C++)
  11. {
  12.    if($rssArray[$C][‘type’] == ‘item’)
  13.    {
  14.       $PicasaDataArray[] = array(
  15.                               ‘title’ => $rssArray[$C][‘title’],
  16.                               ‘image’ => $rssArray[$C][‘enclosures’][0][‘url’],
  17.                               ‘link’ => $rssArray[$C][‘link’],
  18.                               ‘description’ => $rssArray[$C][‘description’],
  19.                               );
  20.    }
  21.    elseif($rssArray[$C][‘type’] == ‘image’)
  22.    {
  23.       $AlbumTitle =  $rssArray[$C][‘title’];
  24.       $AlbumPicture =  $rssArray[$C][‘url’];
  25.       $CreateDate =  $MetaInfo[‘lastbuilddate’];
  26.    }
  27. }
  28. ?>
  29. <html>
  30. <head>
  31. <title>Slide Show :: <?php echo  $AlbumTitle;?></title>
  32. <script type="text/javascript" src="js/prototype.js"></script>
  33. <script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
  34. <script type="text/javascript" src="js/lightbox.js"></script>
  35. <link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
  36. </head>
  37. <body>
  38. <a href="<?php echo  $AlbumPicture;?>" rel="lightbox[picasa]"><img src="<?php echo  $AlbumPicture;?>" /></a>
  39. <div style="display:box;">
  40. <?php
  41. foreach($PicasaDataArray as $ImageInfo)
  42. {
  43.    echo ‘<a href="’.$ImageInfo[‘image’].‘"’ rel="lightbox[picasa]">‘.$ImageInfo['title'].’</a><br> ‘;
  44. }
  45. ?>
  46. </div>
  47. </body>
  48. </html>

I made this code simple and easy to use. Though I have used xml-rss class from pear but it can be repalced by and standard xml-rss parser class. Experienced developer can modify this code or enhance its feature much more as per their requirement. If like to use this code or if you have any suggestion let me know about it via your comment.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes