1 <?php
  2   3   4   5   6   7   8 
  9 
 10 defined('JPATH_PLATFORM') or die;
 11 
 12 use Joomla\Registry\Registry;
 13 
 14  15  16  17  18  19 
 20 class JGoogleDataPicasa extends JGoogleData
 21 {
 22      23  24  25  26  27  28  29 
 30     public function __construct(Registry $options = null, JGoogleAuth $auth = null)
 31     {
 32         parent::__construct($options, $auth);
 33 
 34         if (isset($this->auth) && !$this->auth->getOption('scope'))
 35         {
 36             $this->auth->setOption('scope', 'https://picasaweb.google.com/data/');
 37         }
 38     }
 39 
 40      41  42  43  44  45  46  47  48  49 
 50     public function listAlbums($userID = 'default')
 51     {
 52         if ($this->isAuthenticated())
 53         {
 54             $url = 'https://picasaweb.google.com/data/feed/api/user/' . urlencode($userID);
 55             $jdata = $this->query($url, null, array('GData-Version' => 2));
 56             $xml = $this->safeXml($jdata->body);
 57 
 58             if (isset($xml->children()->entry))
 59             {
 60                 $items = array();
 61 
 62                 foreach ($xml->children()->entry as $item)
 63                 {
 64                     $items[] = new JGoogleDataPicasaAlbum($item, $this->options, $this->auth);
 65                 }
 66 
 67                 return $items;
 68             }
 69             else
 70             {
 71                 throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
 72             }
 73         }
 74         else
 75         {
 76             return false;
 77         }
 78     }
 79 
 80      81  82  83  84  85  86  87  88  89  90  91  92  93  94 
 95     public function createAlbum($userID = 'default', $title = '', $access = 'private', $summary = '', $location = '', $time = false, $keywords = array())
 96     {
 97         if ($this->isAuthenticated())
 98         {
 99             $time = $time ? $time : time();
100             $title = $title != '' ? $title : date('F j, Y');
101             $xml = new SimpleXMLElement('<entry></entry>');
102             $xml->addAttribute('xmlns', 'http://www.w3.org/2005/Atom');
103             $xml->addChild('title', $title);
104             $xml->addChild('summary', $summary);
105             $xml->addChild('gphoto:location', $location, 'http://schemas.google.com/photos/2007');
106             $xml->addChild('gphoto:access', $access);
107             $xml->addChild('gphoto:timestamp', $time);
108             $media = $xml->addChild('media:group', '', 'http://search.yahoo.com/mrss/');
109             $media->addChild('media:keywords', implode($keywords, ', '));
110             $cat = $xml->addChild('category', '');
111             $cat->addAttribute('scheme', 'http://schemas.google.com/g/2005#kind');
112             $cat->addAttribute('term', 'http://schemas.google.com/photos/2007#album');
113 
114             $url = 'https://picasaweb.google.com/data/feed/api/user/' . urlencode($userID);
115             $jdata = $this->query($url, $xml->asXml(), array('GData-Version' => 2, 'Content-type' => 'application/atom+xml'), 'post');
116 
117             $xml = $this->safeXml($jdata->body);
118 
119             return new JGoogleDataPicasaAlbum($xml, $this->options, $this->auth);
120         }
121         else
122         {
123             return false;
124         }
125     }
126 
127     128 129 130 131 132 133 134 135 136 
137     public function getAlbum($url)
138     {
139         if ($this->isAuthenticated())
140         {
141             $jdata = $this->query($url, null, array('GData-Version' => 2));
142             $xml = $this->safeXml($jdata->body);
143 
144             return new JGoogleDataPicasaAlbum($xml, $this->options, $this->auth);
145         }
146         else
147         {
148             return false;
149         }
150     }
151 }
152