Permalink
Browse files

added google contact photos

  • Loading branch information...
kriswallsmith committed Jun 27, 2012
1 parent 4d19e31 commit b5965c2eee5bababffa809da9f4fb1b4a3338e9a
@@ -49,15 +49,22 @@ private function loadContacts(Url $url, array $contacts = array())
$feed->registerXPathNamespace('gdata', 'http://schemas.google.com/g/2005');
foreach ($feed->xpath('./atom:entry[atom:title and gdata:email[@address]]') as $entry) {
+ $entry->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
$entry->registerXPathNamespace('gdata', 'http://schemas.google.com/g/2005');
+
$email = $entry->xpath('./gdata:email');
- $contacts[] = new Contact((string) $entry->title, (string) $email[0]['address']);
- }
+ $contacts[] = $contact = new Contact(
+ (string) $entry->title,
+ (string) $email[0]['address']
+ );
- $next = $feed->xpath('./atom:link[@rel="next"]');
+ if ($this->accessToken && $photo = $entry->xpath('./atom:link[@rel="http://schemas.google.com/contacts/2008/rel#photo" and @href]')) {
+ $contact->setPhoto((string) $photo[0]['href'].'?access_token='.rawurlencode($this->accessToken));
+ }
+ }
- if (!isset($next[0]['href'])) {
+ if (!$next = $feed->xpath('./atom:link[@rel="next" and @href]')) {
// all done
return $contacts;
}
@@ -6,11 +6,13 @@ class Contact
{
private $name;
private $email;
+ private $photo;
- public function __construct($name = null, $email = null)
+ public function __construct($name = null, $email = null, $photo = null)
{
$this->name = $name;
$this->email = $email;
+ $this->photo = $photo;
}
public function getName()
@@ -32,4 +34,14 @@ public function setEmail($email)
{
$this->email = $email;
}
+
+ public function getPhoto()
+ {
+ return $this->photo;
+ }
+
+ public function setPhoto($photo)
+ {
+ $this->photo = $photo;
+ }
}

0 comments on commit b5965c2

Please sign in to comment.