Skip to content
Browse files

Finish Picasa Photo class.

  • Loading branch information...
1 parent 4d499ab commit c2d4cd285c921ce37d4e709f4b8cee630337a1e7 @aaronschmitz aaronschmitz committed with LouisLandry Oct 10, 2012
View
4 libraries/joomla/google/data/picasa.php
@@ -116,7 +116,7 @@ public function createAlbum($userID = 'default', $title = '', $access = 'private
$jdata = $this->auth->query($url, $xml->asXML(), array('GData-Version' => 2, 'Content-type' => 'application/atom+xml'), 'post');
$xml = $this->safeXML($jdata->body);
- return new JGoogleDataPicasaAlbum($xml, $this->options, $this->auth);
+ return new JGoogleDataPicasaAlbum($xml, $this->options, $this->auth);
}
else
{
@@ -140,7 +140,7 @@ public function getAlbum($url)
{
$jdata = $this->auth->query($url, null, array('GData-Version' => 2));
$xml = $this->safeXML($jdata->body);
- return new JGoogleDataPicasaAlbum($xml, $this->options, $this->auth);
+ return new JGoogleDataPicasaAlbum($xml, $this->options, $this->auth);
}
else
{
View
71 libraries/joomla/google/data/picasa/album.php
@@ -27,8 +27,9 @@ class JGoogleDataPicasaAlbum extends JGoogleData
/**
* Constructor.
*
- * @param JRegistry $options Google options object
- * @param JGoogleAuth $auth Google data http client object
+ * @param SimpleXMLElement $xml XML from Google
+ * @param JRegistry $options Google options object
+ * @param JGoogleAuth $auth Google data http client object
*
* @since 1234
*/
@@ -67,7 +68,7 @@ public function delete($match = '*')
if ($match === true)
{
$match = $this->xml->xpath('./@gd:etag');
- $match = $match[0];
+ $match = $match[0];
}
try
@@ -83,7 +84,7 @@ public function delete($match = '*')
throw $e;
}
- if ($jdata->body != '')
+ if ($jdata->body != '')
{
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
}
@@ -108,7 +109,7 @@ public function delete($match = '*')
public function getLink($type = 'edit')
{
$links = $this->xml->link;
- foreach($links as $link)
+ foreach ($links as $link)
{
if ($link->attributes()->rel == $type)
{
@@ -151,7 +152,7 @@ public function getSummary()
*/
public function getLocation()
{
- return (string) $this->xml->children('gphoto')->location;
+ return (string) $this->xml->children('gphoto', true)->location;
}
/**
@@ -163,7 +164,7 @@ public function getLocation()
*/
public function getAccess()
{
- return (string) $this->xml->children('gphoto')->access;
+ return (string) $this->xml->children('gphoto', true)->access;
}
/**
@@ -175,12 +176,12 @@ public function getAccess()
*/
public function getTime()
{
- return (int) $this->xml->children('gphoto')->timestamp;
+ return (int) $this->xml->children('gphoto', true)->timestamp;
return $this;
}
/**
- * Method to get the title of the album
+ * Method to set the title of the album
*
* @param string $title New album title
*
@@ -195,7 +196,7 @@ public function setTitle($title)
}
/**
- * Method to get the summary of the album
+ * Method to set the summary of the album
*
* @param string $summary New album summary
*
@@ -210,7 +211,7 @@ public function setSummary($summary)
}
/**
- * Method to get the location of the album
+ * Method to set the location of the album
*
* @param string $location New album location
*
@@ -220,12 +221,12 @@ public function setSummary($summary)
*/
public function setLocation($location)
{
- $this->xml->children('gphoto')->location = $location;
+ $this->xml->children('gphoto', true)->location = $location;
return $this;
}
/**
- * Method to get the access level of the album
+ * Method to set the access level of the album
*
* @param string $access New album access
*
@@ -235,31 +236,29 @@ public function setLocation($location)
*/
public function setAccess($access)
{
- $this->xml->children('gphoto')->access = $access;
+ $this->xml->children('gphoto', true)->access = $access;
return $this;
}
/**
- * Method to get the time of the album
+ * Method to set the time of the album
*
- * @param int $title New album time
+ * @param int $time New album time
*
* @return JGoogleDataPicasaAlbum The object for method chaining
*
* @since 1234
*/
public function setTime($time)
{
- $this->xml->children('gphoto')->timestamp = $time;
+ $this->xml->children('gphoto', true)->timestamp = $time;
return $this;
}
/**
* Method to modify a Picasa Album
*
- * @param string $url URL of album to delete
- * @param array $options Album settings
- * @param string $match Optional eTag matching parameter
+ * @param string $match Optional eTag matching parameter
*
* @return mixed Data from Google.
*
@@ -273,13 +272,13 @@ public function save($match = '*')
if ($match === true)
{
$match = $this->xml->xpath('./@gd:etag');
- $match = $match[0];
+ $match = $match[0];
}
try
{
- sleep(25);
- $jdata = $this->auth->query($url, $this->xml->asXML(), array('GData-Version' => 2, 'Content-type' => 'application/atom+xml', 'If-Match' => $match), 'put');
+ $headers = array('GData-Version' => 2, 'Content-type' => 'application/atom+xml', 'If-Match' => $match);
+ $jdata = $this->auth->query($url, $this->xml->asXML(), $headers, 'put');
}
catch (Exception $e)
{
@@ -300,9 +299,7 @@ public function save($match = '*')
}
/**
- * Get Picasa Album
- *
- * @param string $url URL of album to get
+ * Refresh Picasa Album
*
* @return mixed Data from Google
*
@@ -315,7 +312,7 @@ public function refresh()
{
$url = $this->getLink();
$jdata = $this->auth->query($url, null, array('GData-Version' => 2));
- $this->xml = $this->safeXML($jdata->body);echo $jdata->body;
+ $this->xml = $this->safeXML($jdata->body);
return $this;
}
else
@@ -362,7 +359,9 @@ public function listPhotos()
/**
* Add photo
*
- * @param string $url URL of album to get
+ * @param string $file Path of file to upload
+ * @param string $title Title to give to file (defaults to filename)
+ * @param string $summary Description of the file
*
* @return mixed Data from Google
*
@@ -392,12 +391,12 @@ public function upload($file, $title = '', $summary = '')
$cat->addAttribute('term', 'http://schemas.google.com/photos/2007#photo');
$post = "Media multipart posting\n";
- $post .= "--END_OF_PART\n";
- $post .= "Content-Type: application/atom+xml\n\n";
- $post .= $xml->asXML()."\n";
- $post .= "--END_OF_PART\n";
- $post .= "Content-Type: {$type}\n\n";
- $post .= $data;
+ $post .= "--END_OF_PART\n";
+ $post .= "Content-Type: application/atom+xml\n\n";
+ $post .= $xml->asXML() . "\n";
+ $post .= "--END_OF_PART\n";
+ $post .= "Content-Type: {$type}\n\n";
+ $post .= $data;
$jdata = $this->auth->query($this->getLink(), $data, array('GData-Version' => 2, 'Content-Type: multipart/related'), 'post');
return $this->safeXML($jdata->body);
@@ -411,7 +410,7 @@ public function upload($file, $title = '', $summary = '')
/**
* Add photo
*
- * @param string $url URL of album to get
+ * @param string $file Filename
*
* @return mixed Data from Google
*
@@ -468,6 +467,6 @@ protected function getMIME($file)
return 'video/x-ms-wmv';
default:
return false;
- }
+ }
}
}
View
164 libraries/joomla/google/data/picasa/photo.php
@@ -19,16 +19,17 @@
class JGoogleDataPicasaPhoto extends JGoogleData
{
/**
- * @var SimpleXMLElement The album's XML
+ * @var SimpleXMLElement The photo's XML
* @since 1234
*/
protected $xml;
/**
* Constructor.
*
- * @param JRegistry $options Google options object
- * @param JGoogleAuth $auth Google data http client object
+ * @param SimpleXMLElement $xml XML from Google
+ * @param JRegistry $options Google options object
+ * @param JGoogleAuth $auth Google data http client object
*
* @since 1234
*/
@@ -50,9 +51,9 @@ public function __construct(SimpleXMLElement $xml, JRegistry $options = null, JG
}
/**
- * Method to delete a Picasa album
+ * Method to delete a Picasa photo
*
- * @param mixed $match Check for most up to date album
+ * @param mixed $match Check for most up to date photo
*
* @return bool Success or failure.
*
@@ -67,7 +68,7 @@ public function delete($match = '*')
if ($match === true)
{
$match = $this->xml->xpath('./@gd:etag');
- $match = $match[0];
+ $match = $match[0];
}
try
@@ -83,7 +84,7 @@ public function delete($match = '*')
throw $e;
}
- if ($jdata->body != '')
+ if ($jdata->body != '')
{
throw new UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
}
@@ -97,7 +98,7 @@ public function delete($match = '*')
}
/**
- * Method to get the album link
+ * Method to get the photo link
*
* @param string $type Type of link to return
*
@@ -108,7 +109,7 @@ public function delete($match = '*')
public function getLink($type = 'edit')
{
$links = $this->xml->link;
- foreach($links as $link)
+ foreach ($links as $link)
{
if ($link->attributes()->rel == $type)
{
@@ -119,147 +120,183 @@ public function getLink($type = 'edit')
}
/**
- * Method to get the title of the album
+ * Method to get the photo's URL
*
- * @return string Album title
+ * @return string Link
*
* @since 1234
*/
- public function getTitle()
+ public function getURL()
{
- return (string) $this->xml->children()->title;
+ return (string) $this->xml->children()->content->attributes()->src;
}
/**
- * Method to get the summary of the album
+ * Method to get the photo's thumbnails
*
- * @return string Album summary
+ * @return array An array of thumbnails
*
* @since 1234
*/
- public function getSummary()
+ 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 1234
+ */
+ public function getTitle()
{
- return (string) $this->xml->children()->summary;
+ return (string) $this->xml->children()->title;
}
/**
- * Method to get the location of the album
+ * Method to get the summary of the photo
*
- * @return string Album location
+ * @return string Photo description
*
* @since 1234
*/
- public function getLocation()
+ public function getSummary()
{
- return (string) $this->xml->children('gphoto')->location;
+ return (string) $this->xml->children('gphoto', true)->access;
}
/**
- * Method to get the access level of the album
+ * Method to get the access level of the photo
*
- * @return string Album access level
+ * @return string Photo access level
*
* @since 1234
*/
public function getAccess()
{
- return (string) $this->xml->children('gphoto')->access;
+ return (string) $this->xml->children('gphoto', true)->access;
}
/**
- * Method to get the time of the album
+ * Method to get the time of the photo
*
- * @return int Album time
+ * @return int Photo time
*
* @since 1234
*/
public function getTime()
{
- return (int) $this->xml->children('gphoto')->timestamp;
- return $this;
+ return (int) $this->xml->children('gphoto', true)->timestamp;
}
/**
- * Method to get the title of the album
+ * Method to get the size of the photo
*
- * @param string $title New album title
+ * @return int Photo size
+ *
+ * @since 1234
+ */
+ public function getSize()
+ {
+ return (int) $this->xml->children('gphoto', true)->size;
+ }
+
+ /**
+ * Method to get the height of the photo
*
- * @return JGoogleDataPicasaAlbum The object for method chaining
+ * @return int Photo height
*
* @since 1234
*/
- public function setTitle($title)
+ public function getHeight()
{
- $this->xml->children()->title = $title;
- return $this;
+ return (int) $this->xml->children('gphoto', true)->height;
}
/**
- * Method to get the summary of the album
+ * Method to get the width of the photo
+ *
+ * @return int Photo width
*
- * @param string $summary New album summary
+ * @since 1234
+ */
+ public function getWidth()
+ {
+ return (int) $this->xml->children('gphoto', true)->width;
+ }
+
+ /**
+ * Method to get the time of the photo
*
- * @return JGoogleDataPicasaAlbum The object for method chaining
+ * @return int Photo time
*
* @since 1234
*/
- public function setSummary($summary)
+ public function getTime()
{
- $this->xml->children()->summary = $summary;
+ return (int) $this->xml->children('gphoto', true)->timestamp;
return $this;
}
/**
- * Method to get the location of the album
+ * Method to set the title of the photo
*
- * @param string $location New album location
+ * @param string $title New photo title
*
- * @return JGoogleDataPicasaAlbum The object for method chaining
+ * @return JGoogleDataPicasaPhoto The object for method chaining
*
* @since 1234
*/
- public function setLocation($location)
+ public function setTitle($title)
{
- $this->xml->children('gphoto')->location = $location;
+ $this->xml->children()->title = $title;
return $this;
}
/**
- * Method to get the access level of the album
+ * Method to set the summary of the photo
*
- * @param string $access New album access
+ * @param string $summary New photo description
*
- * @return JGoogleDataPicasaAlbum The object for method chaining
+ * @return JGoogleDataPicasaPhoto The object for method chaining
*
* @since 1234
*/
- public function setAccess($access)
+ public function setSummary($summary)
{
- $this->xml->children('gphoto')->access = $access;
+ $this->xml->children()->summary = $summary;
return $this;
}
/**
- * Method to get the time of the album
+ * Method to set the time of the photo
*
- * @param int $title New album time
+ * @param int $time New photo time
*
- * @return JGoogleDataPicasaAlbum The object for method chaining
+ * @return JGoogleDataPicasaPhoto The object for method chaining
*
* @since 1234
*/
public function setTime($time)
{
- $this->xml->children('gphoto')->timestamp = $time;
+ $this->xml->children('gphoto', true)->timestamp = $time;
return $this;
}
/**
- * Method to modify a Picasa Album
+ * Method to modify a Picasa Photo
*
- * @param string $url URL of album to delete
- * @param array $options Album settings
- * @param string $match Optional eTag matching parameter
+ * @param string $match Optional eTag matching parameter
*
* @return mixed Data from Google.
*
@@ -273,13 +310,13 @@ public function save($match = '*')
if ($match === true)
{
$match = $this->xml->xpath('./@gd:etag');
- $match = $match[0];
+ $match = $match[0];
}
try
{
- sleep(25);
- $jdata = $this->auth->query($url, $this->xml->asXML(), array('GData-Version' => 2, 'Content-type' => 'application/atom+xml', 'If-Match' => $match), 'put');
+ $headers = array('GData-Version' => 2, 'Content-type' => 'application/atom+xml', 'If-Match' => $match);
+ $jdata = $this->auth->query($url, $this->xml->asXML(), $headers, 'put');
}
catch (Exception $e)
{
@@ -300,22 +337,19 @@ public function save($match = '*')
}
/**
- * Get Picasa Album
- *
- * @param string $url URL of album to get
+ * Refresh photo data
*
* @return mixed Data from Google
*
* @since 1234
- * @throws UnexpectedValueException
*/
public function refresh()
{
if ($this->authenticated())
{
$url = $this->getLink();
$jdata = $this->auth->query($url, null, array('GData-Version' => 2));
- $this->xml = $this->safeXML($jdata->body);echo $jdata->body;
+ $this->xml = $this->safeXML($jdata->body);
return $this;
}
else

0 comments on commit c2d4cd2

Please sign in to comment.
Something went wrong with that request. Please try again.