photo.php
7.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<?php
/**
* @package Joomla.Platform
* @subpackage Google
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
use Joomla\Registry\Registry;
/**
* Google Picasa data class for the Joomla Platform.
*
* @since 3.1.4
* @deprecated 4.0 Use the `joomla/google` package via Composer instead
*/
class JGoogleDataPicasaPhoto extends JGoogleData
{
/**
* @var SimpleXMLElement The photo's XML
* @since 3.1.4
*/
protected $xml;
/**
* Constructor.
*
* @param SimpleXMLElement $xml XML from Google
* @param Registry $options Google options object
* @param JGoogleAuth $auth Google data http client object
*
* @since 3.1.4
*/
public function __construct(SimpleXMLElement $xml, Registry $options = null, JGoogleAuth $auth = null)
{
$this->xml = $xml;
parent::__construct($options, $auth);
if (isset($this->auth) && !$this->auth->getOption('scope'))
{
$this->auth->setOption('scope', 'https://picasaweb.google.com/data/');
}
}
/**
* Method to delete a Picasa photo
*
* @param mixed $match Check for most up to date photo
*
* @return boolean Success or failure.
*
* @since 3.1.4
* @throws Exception
* @throws RuntimeException
* @throws UnexpectedValueException
*/
public function delete($match = '*')
{
if ($this->isAuthenticated())
{
$url = $this->getLink();
if ($match === true)
{
$match = $this->xml->xpath('./@gd:etag');
$match = $match[0];
}
try
{
$jdata = $this->query($url, null, array('GData-Version' => 2, 'If-Match' => $match), 'delete');
}
catch (Exception $e)
{
if (strpos($e->getMessage(), 'Error code 412 received requesting data: Mismatch: etags') === 0)
{
throw new RuntimeException("Etag match failed: `$match`.", $e->getCode(), $e);
}
throw $e;
}
if ($jdata->body != '')
{
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
}
$this->xml = null;
return true;
}
else
{
return false;
}
}
/**
* Method to get the photo link
*
* @param string $type Type of link to return
*
* @return string Link or false on failure
*
* @since 3.1.4
*/
public function getLink($type = 'edit')
{
$links = $this->xml->link;
foreach ($links as $link)
{
if ($link->attributes()->rel == $type)
{
return (string) $link->attributes()->href;
}
}
return false;
}
/**
* Method to get the photo's URL
*
* @return string Link
*
* @since 3.1.4
*/
public function getUrl()
{
return (string) $this->xml->children()->content->attributes()->src;
}
/**
* Method to get the photo's thumbnails
*
* @return array An array of thumbnails
*
* @since 3.1.4
*/
public function getThumbnails()
{
$thumbs = array();
foreach ($this->xml->children('media', true)->group->thumbnail as $item)
{
$url = (string) $item->attributes()->url;
$width = (int) $item->attributes()->width;
$height = (int) $item->attributes()->height;
$thumbs[$width] = array('url' => $url, 'w' => $width, 'h' => $height);
}
return $thumbs;
}
/**
* Method to get the title of the photo
*
* @return string Photo title
*
* @since 3.1.4
*/
public function getTitle()
{
return (string) $this->xml->children()->title;
}
/**
* Method to get the summary of the photo
*
* @return string Photo description
*
* @since 3.1.4
*/
public function getSummary()
{
return (string) $this->xml->children()->summary;
}
/**
* Method to get the access level of the photo
*
* @return string Photo access level
*
* @since 3.1.4
*/
public function getAccess()
{
return (string) $this->xml->children('gphoto', true)->access;
}
/**
* Method to get the time of the photo
*
* @return double Photo time
*
* @since 3.1.4
*/
public function getTime()
{
return (double) $this->xml->children('gphoto', true)->timestamp / 1000;
}
/**
* Method to get the size of the photo
*
* @return int Photo size
*
* @since 3.1.4
*/
public function getSize()
{
return (int) $this->xml->children('gphoto', true)->size;
}
/**
* Method to get the height of the photo
*
* @return int Photo height
*
* @since 3.1.4
*/
public function getHeight()
{
return (int) $this->xml->children('gphoto', true)->height;
}
/**
* Method to get the width of the photo
*
* @return int Photo width
*
* @since 3.1.4
*/
public function getWidth()
{
return (int) $this->xml->children('gphoto', true)->width;
}
/**
* Method to set the title of the photo
*
* @param string $title New photo title
*
* @return JGoogleDataPicasaPhoto The object for method chaining
*
* @since 3.1.4
*/
public function setTitle($title)
{
$this->xml->children()->title = $title;
return $this;
}
/**
* Method to set the summary of the photo
*
* @param string $summary New photo description
*
* @return JGoogleDataPicasaPhoto The object for method chaining
*
* @since 3.1.4
*/
public function setSummary($summary)
{
$this->xml->children()->summary = $summary;
return $this;
}
/**
* Method to set the access level of the photo
*
* @param string $access New photo access level
*
* @return JGoogleDataPicasaPhoto The object for method chaining
*
* @since 3.1.4
*/
public function setAccess($access)
{
$this->xml->children('gphoto', true)->access = $access;
return $this;
}
/**
* Method to set the time of the photo
*
* @param int $time New photo time
*
* @return JGoogleDataPicasaPhoto The object for method chaining
*
* @since 3.1.4
*/
public function setTime($time)
{
$this->xml->children('gphoto', true)->timestamp = $time * 1000;
return $this;
}
/**
* Method to modify a Picasa Photo
*
* @param string $match Optional eTag matching parameter
*
* @return mixed Data from Google.
*
* @since 3.1.4
*/
public function save($match = '*')
{
if ($this->isAuthenticated())
{
$url = $this->getLink();
if ($match === true)
{
$match = $this->xml->xpath('./@gd:etag');
$match = $match[0];
}
try
{
$headers = array('GData-Version' => 2, 'Content-type' => 'application/atom+xml', 'If-Match' => $match);
$jdata = $this->query($url, $this->xml->asXml(), $headers, 'put');
}
catch (Exception $e)
{
if (strpos($e->getMessage(), 'Error code 412 received requesting data: Mismatch: etags') === 0)
{
throw new RuntimeException("Etag match failed: `$match`.", $e->getCode(), $e);
}
throw $e;
}
$this->xml = $this->safeXml($jdata->body);
return $this;
}
else
{
return false;
}
}
/**
* Refresh photo data
*
* @return mixed Data from Google
*
* @since 3.1.4
*/
public function refresh()
{
if ($this->isAuthenticated())
{
$url = $this->getLink();
$jdata = $this->query($url, null, array('GData-Version' => 2));
$this->xml = $this->safeXml($jdata->body);
return $this;
}
else
{
return false;
}
}
}