Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
picasa.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Google
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * Google Picasa data class for the Joomla Platform.
14  *
15  * @package Joomla.Platform
16  * @subpackage Google
17  * @since 12.3
18  */
20 {
21  /**
22  * Constructor.
23  *
24  * @param JRegistry $options Google options object
25  * @param JGoogleAuth $auth Google data http client object
26  *
27  * @since 12.3
28  */
29  public function __construct(JRegistry $options = null, JGoogleAuth $auth = null)
30  {
31  parent::__construct($options, $auth);
32 
33  if (isset($this->auth) && !$this->auth->getOption('scope'))
34  {
35  $this->auth->setOption('scope', 'https://picasaweb.google.com/data/');
36  }
37  }
38 
39  /**
40  * Method to retrieve a list of Picasa Albums
41  *
42  * @param string $userID ID of user
43  *
44  * @return mixed Data from Google
45  *
46  * @since 12.3
47  * @throws UnexpectedValueException
48  */
49  public function listAlbums($userID = 'default')
50  {
51  if ($this->isAuthenticated())
52  {
53  $url = 'https://picasaweb.google.com/data/feed/api/user/' . urlencode($userID);
54  $jdata = $this->query($url, null, array('GData-Version' => 2));
55  $xml = $this->safeXML($jdata->body);
56 
57  if (isset($xml->children()->entry))
58  {
59  $items = array();
60 
61  foreach ($xml->children()->entry as $item)
62  {
63  $items[] = new JGoogleDataPicasaAlbum($item, $this->options, $this->auth);
64  }
65  return $items;
66  }
67  else
68  {
69  throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
70  }
71  }
72  else
73  {
74  return false;
75  }
76  }
77 
78  /**
79  * Method to create a Picasa Album
80  *
81  * @param string $userID ID of user
82  * @param string $title New album title
83  * @param string $access New album access settings
84  * @param string $summary New album summary
85  * @param string $location New album location
86  * @param int $time New album timestamp
87  * @param array $keywords New album keywords
88  *
89  * @return mixed Data from Google.
90  *
91  * @since 12.3
92  */
93  public function createAlbum($userID = 'default', $title = '', $access = 'private', $summary = '', $location = '', $time = false, $keywords = array())
94  {
95  if ($this->isAuthenticated())
96  {
97  $time = $time ? $time : time();
98  $title = $title != '' ? $title : date('F j, Y');
99  $xml = new SimpleXMLElement('<entry></entry>');
100  $xml->addAttribute('xmlns', 'http://www.w3.org/2005/Atom');
101  $xml->addChild('title', $title);
102  $xml->addChild('summary', $summary);
103  $xml->addChild('gphoto:location', $location, 'http://schemas.google.com/photos/2007');
104  $xml->addChild('gphoto:access', $access);
105  $xml->addChild('gphoto:timestamp', $time);
106  $media = $xml->addChild('media:group', '', 'http://search.yahoo.com/mrss/');
107  $media->addChild('media:keywords', implode($keywords, ', '));
108  $cat = $xml->addChild('category', '');
109  $cat->addAttribute('scheme', 'http://schemas.google.com/g/2005#kind');
110  $cat->addAttribute('term', 'http://schemas.google.com/photos/2007#album');
111 
112  $url = 'https://picasaweb.google.com/data/feed/api/user/' . urlencode($userID);
113  $jdata = $this->query($url, $xml->asXML(), array('GData-Version' => 2, 'Content-type' => 'application/atom+xml'), 'post');
114 
115  $xml = $this->safeXML($jdata->body);
116 
117  return new JGoogleDataPicasaAlbum($xml, $this->options, $this->auth);
118  }
119  else
120  {
121  return false;
122  }
123  }
124 
125  /**
126  * Get Picasa Album
127  *
128  * @param string $url URL of album to get
129  *
130  * @return mixed Data from Google
131  *
132  * @since 12.3
133  * @throws UnexpectedValueException
134  */
135  public function getAlbum($url)
136  {
137  if ($this->isAuthenticated())
138  {
139  $jdata = $this->query($url, null, array('GData-Version' => 2));
140  $xml = $this->safeXML($jdata->body);
141 
142  return new JGoogleDataPicasaAlbum($xml, $this->options, $this->auth);
143  }
144  else
145  {
146  return false;
147  }
148  }
149 }