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 getURL()
129 return (
string) $this->xml->children()->content->attributes()->src;
139 public function getThumbnails()
143 foreach ($this->xml->children(
'media',
true)->group->thumbnail as $item)
145 $url = (string) $item->attributes()->url;
146 $width = (int) $item->attributes()->width;
147 $height = (int) $item->attributes()->height;
148 $thumbs[$width] = array(
'url' => $url,
'w' => $width,
'h' => $height);
160 public function getTitle()
162 return (
string) $this->xml->children()->title;
172 public function getSummary()
174 return (
string) $this->xml->children()->summary;
184 public function getAccess()
186 return (
string) $this->xml->children(
'gphoto',
true)->access;
196 public function getTime()
198 return (
double) $this->xml->children(
'gphoto',
true)->timestamp / 1000;
208 public function getSize()
210 return (
int) $this->xml->children(
'gphoto',
true)->size;
220 public function getHeight()
222 return (
int) $this->xml->children(
'gphoto',
true)->height;
232 public function getWidth()
234 return (
int) $this->xml->children(
'gphoto',
true)->width;
246 public function setTitle($title)
248 $this->xml->children()->title = $title;
262 public function setSummary($summary)
264 $this->xml->children()->summary = $summary;
278 public function setAccess($access)
280 $this->xml->children(
'gphoto',
true)->access = $access;
294 public function setTime($time)
296 $this->xml->children(
'gphoto',
true)->timestamp = $time * 1000;
310 public function save($match =
'*')
312 if ($this->isAuthenticated())
314 $url = $this->getLink();
318 $match = $this->xml->xpath(
'./@gd:etag');
324 $headers = array(
'GData-Version' => 2,
'Content-type' =>
'application/atom+xml',
'If-Match' => $match);
325 $jdata = $this->query($url, $this->xml->asXML(), $headers,
'put');
329 if (strpos($e->getMessage(),
'Error code 412 received requesting data: Mismatch: etags') === 0)
331 throw new RuntimeException(
"Etag match failed: `$match`.");
336 $this->xml = $this->safeXML($jdata->body);
353 public function refresh()
355 if ($this->isAuthenticated())
357 $url = $this->getLink();
358 $jdata = $this->query($url, null, array(
'GData-Version' => 2));
359 $this->xml = $this->safeXML($jdata->body);