Wednesday, March 11, 2009

Upgrading sfFlickrGalleryPlugin

Well, I figure it's probably time for another post, and perhaps a real one this time!

Recently I got into Symfony and wanted to install a photo gallery type plugin in one of my projects. I took a look at sfFlickrGalleryPlugin which is compatible with Symfony 0.1.1 but my project is in crispy new 1.2.4. I upgraded the plugin manually for now, and I decided it would be a good idea to make a post on how this is done. (It was not exactly trivial.)

Here's what it'll take for you to get the plugin to work in 1.2.4:

  1. Install the plugin in your project and follow the rest of the directions in the plugin README.
  2. Modify Request.php in the included Phlickr library by changing the submitHttpPost function to look as follows:


    static function submitHttpPost($url, $postParams = null, $timeout = self::TIMEOUT_TOTAL)
    {
    $ch = curl_init();

    // set up the request
    curl_setopt($ch, CURLOPT_URL, $url);
    // make sure we submit this as a post
    curl_setopt($ch, CURLOPT_POST, true);
    if (isset($postParams)) {
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postParams);
    }
    else curl_setopt($ch, CURLOPT_POSTFIELDS, '');



    (solution found at http://www.milk-hub.net/blog/2008/08/26/curl_error_26#comments-77)


  3. Modify Photo.php also in the Phlickr library to include:

    public function getFarm(){
    if (!isset($this->_cachedXml['farm'])) {
    $this->load();
    }
    return (integer) $this->_cachedXml['farm'];
    }


  4. Modify line 547 in Photo.php's buildImgUrl so that it looks as follows:

    $url = sprintf("http://farm%d.static.flickr.com/%d/%s_%s%s.%s",
    $this->getFarm(), $this->getServer(), $this->getId(), $this->getSecret(), $sizeStr, $type);


    (Discovered here: http://forum.symfony-project.org/index.php/m/53102/)
    You need to use %s instead of %d because Flickr has exceeded integer bounds or photo ids. (http://andrewsblog.org/2007/12/30/use-bigint-for-flickr-photo-ids/)



  5. Change all references to $this->setFlash in the plugin's modules to be $this->getUser()->setFlash

That's it! You should be good to go!

No comments:

2008 joshnankin.com | Based on template from Free CSS Templates