10 defined(
'JPATH_PLATFORM') or die;
40 parent::__construct($options, $auth);
42 if (isset($this->auth) && !$this->auth->getOption(
'scope'))
44 $this->auth->setOption(
'scope',
'https://picasaweb.google.com/data/');
58 public function delete($match =
'*')
60 if ($this->isAuthenticated())
62 $url = $this->getLink();
66 $match = $this->xml->xpath(
'./@gd:etag');
72 $jdata = $this->query($url, null, array(
'GData-Version' => 2,
'If-Match' => $match),
'delete');
76 if (strpos($e->getMessage(),
'Error code 412 received requesting data: Mismatch: etags') === 0)
78 throw new RuntimeException(
"Etag match failed: `$match`.");
83 if ($jdata->body !=
'')
85 throw new UnexpectedValueException(
"Unexpected data received from Google: `{$jdata->body}`.");
106 public function getLink($type =
'edit')
108 $links = $this->xml->link;
110 foreach ($links as $link)
112 if ($link->attributes()->rel == $type)
114 return (
string) $link->attributes()->href;
127 public function getTitle()
129 return (
string) $this->xml->children()->title;
139 public function getSummary()
141 return (
string) $this->xml->children()->summary;
151 public function getLocation()
153 return (
string) $this->xml->children(
'gphoto',
true)->location;
163 public function getAccess()
165 return (
string) $this->xml->children(
'gphoto',
true)->access;
175 public function getTime()
177 return (
double) $this->xml->children(
'gphoto',
true)->timestamp / 1000;
189 public function setTitle($title)
191 $this->xml->children()->title = $title;
205 public function setSummary($summary)
207 $this->xml->children()->summary = $summary;
221 public function setLocation($location)
223 $this->xml->children(
'gphoto',
true)->location = $location;
237 public function setAccess($access)
239 $this->xml->children(
'gphoto',
true)->access = $access;
253 public function setTime($time)
255 $this->xml->children(
'gphoto',
true)->timestamp = $time * 1000;
269 public function save($match =
'*')
271 if ($this->isAuthenticated())
273 $url = $this->getLink();
277 $match = $this->xml->xpath(
'./@gd:etag');
283 $headers = array(
'GData-Version' => 2,
'Content-type' =>
'application/atom+xml',
'If-Match' => $match);
284 $jdata = $this->query($url, $this->xml->asXML(), $headers,
'put');
288 if (strpos($e->getMessage(),
'Error code 412 received requesting data: Mismatch: etags') === 0)
290 throw new RuntimeException(
"Etag match failed: `$match`.");
295 $this->xml = $this->safeXML($jdata->body);
313 public function refresh()
315 if ($this->isAuthenticated())
317 $url = $this->getLink();
318 $jdata = $this->query($url, null, array(
'GData-Version' => 2));
319 $this->xml = $this->safeXML($jdata->body);
337 public function listPhotos()
339 if ($this->isAuthenticated())
341 $url = $this->getLink(
'http://schemas.google.com/g/2005#feed');
342 $jdata = $this->query($url, null, array(
'GData-Version' => 2));
343 $xml = $this->safeXML($jdata->body);
345 if (isset($xml->children()->entry))
349 foreach ($xml->children()->entry as $item)
357 throw new UnexpectedValueException(
"Unexpected data received from Google: `{$jdata->body}`.");
378 public function upload($file, $title =
'', $summary =
'')
380 if ($this->isAuthenticated())
382 jimport(
'joomla.filesystem.file');
385 if (!($type = $this->getMIME($file)))
387 throw new RuntimeException(
"Inappropriate file type.");
391 throw new RuntimeException(
"Cannot access file: `$file`");
394 $xml =
new SimpleXMLElement(
'<entry></entry>');
395 $xml->addAttribute(
'xmlns',
'http://www.w3.org/2005/Atom');
396 $xml->addChild(
'title', $title);
397 $xml->addChild(
'summary', $summary);
398 $cat = $xml->addChild(
'category',
'');
399 $cat->addAttribute(
'scheme',
'http://schemas.google.com/g/2005#kind');
400 $cat->addAttribute(
'term',
'http://schemas.google.com/photos/2007#photo');
402 $post =
"Media multipart posting\n";
403 $post .=
"--END_OF_PART\n";
404 $post .=
"Content-Type: application/atom+xml\n\n";
405 $post .= $xml->asXML() .
"\n";
406 $post .=
"--END_OF_PART\n";
407 $post .=
"Content-Type: {$type}\n\n";
410 $jdata = $this->query($this->getLink(), $post, array(
'GData-Version' => 2,
'Content-Type: multipart/related'),
'post');
430 protected function getMIME($file)
455 return 'video/quicktime';
475 return 'video/x-ms-asf';
477 return 'video/x-ms-wmv';