silverstripe-picasaweb 

silverstripe-picasaweb Commit Details

Date:2013-05-06 20:50:58 (7 years 11 months ago)
Author:Nicola Fontana
Branch:master
Commit:4cd750b7b69706c2ab60ae340e98818dafaa7fc8
Parents: 8f86bcd9ac670662cc59376c47f7941f6fb1b375
Message:Refactored url assembling

Changes:
Mcode/Picasaweb.php (2 diffs)

File differences

code/Picasaweb.php
256256
257257
258258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
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
274288
275289
276290
277291
278292
279
280
281
282
283
284
285
286
287
288
289
290293
291294
292295
......
344347
345348
346349
347
350
348351
349352
350
353
351354
352355
353356
return strlen($str) == strspn($str, '0123456789');
}
public static function photoUrl($user, $photo, $album = null) {
// At least user and photo are required to access a photo entry
if (! isset($user, $photo))
return null;
$user = "user/$user";
$photo = self::isId($photo) ? "photoid/$photo" : "photo/$photo";
$url = 'http://picasaweb.google.com/data/entry/api';
// The album is optional
if (isset($album)) {
$album = self::isId($album) ? "albumid/$album" : "album/$album";
$url = "$url/$user/$album/$photo";
} else {
$url = "$url/$user/$photo";
/**
* Build a Picasaweb URL.
*
* Entry point for building the canonical Picasaweb URL from its
* components.
*
* @param String $user The Picasaweb user
* @param String $album The album id (or its canonical title),
* optional for photo URLs.
* @param String $photo The photo id: leave it null for albums.
* @return String The URL or null on errors.
*/
private static function url($user, $album, $photo = null) {
$url = null;
// The user is always required by the Picasaweb API
if (isset($user)) {
$domain = 'http://picasaweb.google.com';
$user = "/user/$user";
isset($album) and $album = self::isId($album) ? "/albumid/$album" : "/album/$album";
isset($photo) and $photo = self::isId($photo) ? "/photoid/$photo" : "/photo/$photo";
if (isset($photo)) {
// Photo URL
$url = "$domain/data/entry/api$user$album$photo";
} elseif (isset($album)) {
// Album URL
$url = "$domain/data/feed/api$user$album";
}
}
return $url;
}
public static function albumUrl($user, $album) {
// Both user and album are required to access an album
if (! isset($user, $album))
return null;
$user = "user/$user";
$album = self::isId($album) ? "albumid/$album" : "album/$album";
return "http://picasaweb.google.com/data/feed/api/$user/$album";
}
public static function photo($url) {
$tree = self::xmlFetch($url);
if (empty($tree))
return null;
} elseif (empty($photo)) {
$viewer = new SSViewer('Picasaweb_album');
$data = self::album(self::albumUrl($user, $album));
$data = self::album(self::url($user, $album));
} else {
$viewer = new SSViewer('Picasaweb_photo');
$data = self::photo(self::photoUrl($user, $photo, $album));
$data = self::photo(self::url($user, $album, $photo));
}
if (is_null($data))

Archive Download the corresponding diff file

Branches