Mauro Pirrone | Blog

Design & Logic Arts

Integrating Flickr with your PHP website

Posted in Web Design, Web Development by Mauro on the May 31st, 2008

Flickr is an image and video hosting website. Luckily enough, they provide a web service to access your photos and use them in any way you want. To get you into perspective, here’s the Flickr photoset which I am using, and here are the customised photo gallaries which I created using PHP:

Although I’m showing you how to integrate Flickr with Lightbox and PostCardViewer, this technique works with any photo gallery including the commercial one SlideShowPro.

Step 1

Downlaod the phpFlicker library from http://phpflickr.com/

Download Lightbox or PostCardViewer (or any other photo gallery).

Step 2

To access Flickr using a web service, you need an API key. You may get one from http://www.flickr.com/services/api/keys

Step 3

Get the photoset ID. In this case I am using photoset id ‘72157605353756648′. Note that the photoset id is part of the URL. For example, http://www.flickr.com/photos/26262208@N07/sets/72157605353756648/

Step 3

Step up your php script.

require_once("phpFlickr/phpFlickr.php");
$f = new phpFlickr("your api key");
$photoset_id = '72157605353756648';
$photos = $f->photosets_getPhotos($photoset_id);

Step 4

Loop through each photo in the photoset and you’re done! The following example uses the Lightbox photo gallery.

<ul>
<?php foreach ($photos['photo'] as $photo): ?>
<li><a rel="lightbox[roadtrip]" href="<?= $f->buildPhotoURL($photo, ‘medium’) ?>" title="<?= $photo['title'] ?>"><img src="<?= $f->buildPhotoURL($photo, ’square’) ?>" alt="<?= $photo['title'] ?>" title="<?= $photo['title'] ?>" /></a></li>
<?php endforeach; ?>
</ul>

Notes

  • You may easily change the file size by specifying either square, thumbnail, small, medium, large or original. For example: $f->buildPhotoURL($photo, ‘large’)
  • You may programmatically get the photoset ids by using the API call photoset.getList (or photoset_getList method)
  • You may also use API calls to get comments, upload photos, and so on
  • For the complete API documentation visit here

Source Code Download

MVC using a PHP Development Framework

Posted in Open Source, Web Development by Mauro on the May 25th, 2008

MVC which stands for Model View Controller is an architectural design pattern used for building modularised web applications. The main idea behind this model is to separate the business logic from the user interface. As a result, the application would be easier to manage and maintain since any changes in the business logic will not affect the user interface.

MVC consists of:

  • Model which consists of the application’s data and the business rules (methods) used to modify the data.
  • View is the application’s presentation layer which consists of text, buttons, and other objects.
  • Controller which uses a model to invoke methods for data processing and views to output the results.

As with regards to the PHP programming language, there are many open-source frameworks which you can use including the following:

Zend Framework
Zend Framework is well designed and specifically targeted for PHP5. The nice thing about ZF is that all modules are self-contained. Practically should can take any module from this framework and plug it into your application. Video Tutorial

CodeIgniter
CodeIgniter works with PHP 4 and 5. CI is very easy to use and it is very well documented. Video Tutorials

CakePHP
CakePHP works with PHP 4 and 5. It is feature-rich and has built-in support for ORM (Object Relational Model) and Ajax. Video Tutorials

Symfony
Symfony is much like Ruby on Rails since you have to use a command line. Video Tutorials

All the above frameworks support MVC but there are some differences when it comes to the framework’s functionality. I would suggest trying them out!