Source for file picasa.php

Documentation is available at picasa.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Google
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * Google Picasa data class for the Joomla Platform.
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Google
  17.  * @since       12.3
  18.  */
  19. {
  20.     /**
  21.      * Constructor.
  22.      *
  23.      * @param   JRegistry    $options  Google options object
  24.      * @param   JGoogleAuth  $auth     Google data http client object
  25.      *
  26.      * @since   12.3
  27.      */
  28.     public function __construct(JRegistry $options nullJGoogleAuth $auth null)
  29.     {
  30.         parent::__construct($options$auth);
  31.  
  32.         if (isset($this->auth&& !$this->auth->getOption('scope'))
  33.         {
  34.             $this->auth->setOption('scope''https://picasaweb.google.com/data/');
  35.         }
  36.     }
  37.  
  38.     /**
  39.      * Method to retrieve a list of Picasa Albums
  40.      *
  41.      * @param   string  $userID  ID of user
  42.      *
  43.      * @return  mixed  Data from Google
  44.      *
  45.      * @since   12.3
  46.      * @throws UnexpectedValueException
  47.      */
  48.     public function listAlbums($userID 'default')
  49.     {
  50.         if ($this->isAuthenticated())
  51.         {
  52.             $url 'https://picasaweb.google.com/data/feed/api/user/' urlencode($userID);
  53.             $jdata $this->query($urlnullarray('GData-Version' => 2));
  54.             $xml $this->safeXML($jdata->body);
  55.  
  56.             if (isset($xml->children()->entry))
  57.             {
  58.                 $items array();
  59.  
  60.                 foreach ($xml->children()->entry as $item)
  61.                 {
  62.                     $items[new JGoogleDataPicasaAlbum($item$this->options$this->auth);
  63.                 }
  64.                 return $items;
  65.             }
  66.             else
  67.             {
  68.                 throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
  69.             }
  70.         }
  71.         else
  72.         {
  73.             return false;
  74.         }
  75.     }
  76.  
  77.     /**
  78.      * Method to create a Picasa Album
  79.      *
  80.      * @param   string  $userID    ID of user
  81.      * @param   string  $title     New album title
  82.      * @param   string  $access    New album access settings
  83.      * @param   string  $summary   New album summary
  84.      * @param   string  $location  New album location
  85.      * @param   int     $time      New album timestamp
  86.      * @param   array   $keywords  New album keywords
  87.      *
  88.      * @return  mixed  Data from Google.
  89.      *
  90.      * @since   12.3
  91.      */
  92.     public function createAlbum($userID 'default'$title ''$access 'private'$summary ''$location ''$time false$keywords array())
  93.     {
  94.         if ($this->isAuthenticated())
  95.         {
  96.             $time $time $time time();
  97.             $title $title != '' $title date('F j, Y');
  98.             $xml new SimpleXMLElement('<entry></entry>');
  99.             $xml->addAttribute('xmlns''http://www.w3.org/2005/Atom');
  100.             $xml->addChild('title'$title);
  101.             $xml->addChild('summary'$summary);
  102.             $xml->addChild('gphoto:location'$location'http://schemas.google.com/photos/2007');
  103.             $xml->addChild('gphoto:access'$access);
  104.             $xml->addChild('gphoto:timestamp'$time);
  105.             $media $xml->addChild('media:group''''http://search.yahoo.com/mrss/');
  106.             $media->addChild('media:keywords'implode($keywords', '));
  107.             $cat $xml->addChild('category''');
  108.             $cat->addAttribute('scheme''http://schemas.google.com/g/2005#kind');
  109.             $cat->addAttribute('term''http://schemas.google.com/photos/2007#album');
  110.  
  111.             $url 'https://picasaweb.google.com/data/feed/api/user/' urlencode($userID);
  112.             $jdata $this->query($url$xml->asXML()array('GData-Version' => 2'Content-type' => 'application/atom+xml')'post');
  113.  
  114.             $xml $this->safeXML($jdata->body);
  115.  
  116.             return new JGoogleDataPicasaAlbum($xml$this->options$this->auth);
  117.         }
  118.         else
  119.         {
  120.             return false;
  121.         }
  122.     }
  123.  
  124.     /**
  125.      * Get Picasa Album
  126.      *
  127.      * @param   string  $url  URL of album to get
  128.      *
  129.      * @return  mixed  Data from Google
  130.      *
  131.      * @since   12.3
  132.      * @throws UnexpectedValueException
  133.      */
  134.     public function getAlbum($url)
  135.     {
  136.         if ($this->isAuthenticated())
  137.         {
  138.             $jdata $this->query($urlnullarray('GData-Version' => 2));
  139.             $xml $this->safeXML($jdata->body);
  140.  
  141.             return new JGoogleDataPicasaAlbum($xml$this->options$this->auth);
  142.         }
  143.         else
  144.         {
  145.             return false;
  146.         }
  147.     }
  148. }

Documentation generated on Tue, 19 Nov 2013 15:10:40 +0100 by phpDocumentor 1.4.3