Exemplo n.º 1
0
 public function FetchContacts($credential = null)
 {
     if (!$credential) {
         $credential = $this->_credential;
     } else {
         $this->_credential = $credential;
     }
     $user = $credential['username'];
     $pass = $credential['password'];
     try {
         // perform login and set protocol version to 3.0
         $client = \Zend_Gdata_ClientLogin::getHttpClient($user, $pass, 'cp');
         $gdata = new \Zend_Gdata($client);
         $gdata->setMajorProtocolVersion(3);
         // perform query and get result feed
         $query = new \Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/default/full');
         $query->setParam("max-results", 10000);
         $feed = $gdata->getFeed($query);
         // parse feed and extract contact information
         // into simpler objects
         $results = array();
         foreach ($feed as $entry) {
             $xml = simplexml_load_string($entry->getXML());
             $obj = $this->DatatoContact($entry, $xml);
             $results[] = $obj;
         }
     } catch (Exception $e) {
         var_dump($e->getMessage());
         return;
     }
     return $results;
 }
Exemplo n.º 2
0
 public function testSetAndGetStartIndex()
 {
     $query = new Zend_Gdata_Query();
     $query->setStartIndex(12);
     $this->assertEquals(12, $query->getStartIndex());
     $this->assertTrue(strpos($query->getQueryUrl(), 'start-index=12') !== false);
 }
Exemplo n.º 3
0
 /**
  * Retrieve user's uploaded videos.
  *
  * @param $maxResults int
  *       	 Maximum number of YoutubeVideo to return.
  * @return array(YoutubeVideo) Videos retrieved.
  */
 public function getVideos($maxResults)
 {
     try {
         set_include_path(get_include_path() . PATH_SEPARATOR . dirname(WSW_Main::$plugin_dir) . '/lib/Youtube');
         if (!class_exists('Zend_Loader')) {
             require_once 'Zend/Loader.php';
         }
         Zend_Loader::loadClass('Zend_Gdata_Query');
         Zend_Loader::loadClass('Zend_Gdata_YouTube');
         // If the keyword is compoused, divide each word
         $key_phrase = $this->keyword;
         $key_phrase_arr = explode(' ', $key_phrase);
         $query_url = Zend_Gdata_YouTube::VIDEO_URI . "/-/";
         foreach ($key_phrase_arr as $key_phrase_item) {
             if (trim($key_phrase_item) != '') {
                 $query_url .= trim($key_phrase_item) . '/';
             }
         }
         //$query_url .= '?v=2';
         $query = new Zend_Gdata_Query($query_url);
         $query->setMaxResults($maxResults);
         $query->setParam('orderby', 'viewCount');
         $yt = new Zend_Gdata_YouTube();
         $yt->setMajorProtocolVersion(2);
         $videoFeed = $yt->getFeed($query, 'Zend_Gdata_YouTube_VideoFeed');
         // TODO See how this initialization must be done, I mean if is really neccesary
         $keyVideos = array();
         foreach ($videoFeed as $videoEntry) {
             $keyVideos[] = new WSW_YoutubeVideo($videoEntry);
         }
         return $keyVideos;
     } catch (Exception $e) {
         // Store to log
         $msg_to_log = 'Error while getVideos from Youtube, Url: ' . $query_url . ', Exception Msg: ' . $e->getMessage();
         return array();
     }
 }
Exemplo n.º 4
0
 /**
  * get Contacts list to show
  * 
  * @return array
  */
 public function getContacts()
 {
     $list = array();
     $request = $this->getRequest();
     if (!$request->getParam('oauth_token') && !$request->getParam('oauth_verifier')) {
         return $list;
     }
     $google = Mage::getSingleton('affiliateplusreferfriend/refer_gmail');
     $oauthData = array('oauth_token' => $request->getParam('oauth_token'), 'oauth_verifier' => $request->getParam('oauth_verifier'));
     $accessToken = $google->getAccessToken($oauthData, unserialize($google->getGmailRequestToken()));
     $oauthOptions = $google->getOptions();
     $httpClient = $accessToken->getHttpClient($oauthOptions);
     $gdata = new Zend_Gdata($httpClient);
     $query = new Zend_Gdata_Query('https://www.google.com/m8/feeds/contacts/default/full');
     $query->setMaxResults(10000);
     $feed = array();
     try {
         $feed = $gdata->getFeed($query);
     } catch (Exception $e) {
     }
     foreach ($feed as $entry) {
         $_contact = array();
         $xml = simplexml_load_string($entry->getXML());
         $_contact['name'] = $entry->title;
         foreach ($xml->email as $e) {
             $email = '';
             if (isset($e['address'])) {
                 $email = (string) $e['address'];
             }
             if ($email) {
                 $_contact['email'] = $email;
                 $list[] = $_contact;
             }
         }
     }
     return $list;
 }
Exemplo n.º 5
0
 /**
  * Retrieves a specific volume entry.
  *
  * @param string|null $volumeId The volumeId of interest.
  * @param Zend_Gdata_Query|string|null $location (optional) The URL to
  *        query or a Zend_Gdata_Query object from which a URL can be
  *        determined.
  * @return Zend_Gdata_Books_VolumeEntry The feed of volumes found at the
  *         specified URL.
  */
 public function getVolumeEntry($volumeId = null, $location = null)
 {
     if ($volumeId !== null) {
         $uri = self::VOLUME_FEED_URI . "/" . $volumeId;
     } else {
         if ($location instanceof Zend_Gdata_Query) {
             $uri = $location->getQueryUrl();
         } else {
             $uri = $location;
         }
     }
     return parent::getEntry($uri, 'Zend_Gdata_Books_VolumeEntry');
 }
Exemplo n.º 6
0
 /**
  * Gets the attribute query string for this query.
  *
  * @return string query string
  */
 public function getQueryString()
 {
     return parent::getQueryString();
 }
Exemplo n.º 7
0
 /**
  * Constructs a new instance of a Zend_Gdata_Docs_Query object.
  */
 public function __construct()
 {
     parent::__construct();
 }
Exemplo n.º 8
0
 /**
  * Create Gdata_YouTube_VideoQuery object
  */
 public function __construct($url = null)
 {
     parent::__construct($url);
 }
Exemplo n.º 9
0
 public function testSetAndGetStartIndex()
 {
     $query = new Zend_Gdata_Query();
     $query->setStartIndex(12);
     $this->assertEquals(12, $query->getStartIndex());
     $this->assertContains('start-index=12', $query->getQueryUrl());
 }
Exemplo n.º 10
0
 /**
  * Create a new instance.
  *
  * @param string $domain (optional) The Google Apps-hosted domain to use
  *          when constructing query URIs.
  */
 public function __construct($domain = null)
 {
     parent::__construct();
     $this->_domain = $domain;
 }
Exemplo n.º 11
0
 /**
  *
  * @param  string $object
  * @param  int    $offset_start
  * @param  int    $quantity
  * @return string
  */
 protected function get_user_object_list_feed($object, $offset_start, $quantity)
 {
     $feed = null;
     switch ($object) {
         case self::ELEMENT_TYPE_VIDEO:
             $uri = Zend_Gdata_YouTube::USER_URI . '/default/' . Zend_Gdata_YouTube::UPLOADS_URI_SUFFIX;
             $query = new Zend_Gdata_Query($uri);
             if ($quantity !== 0) {
                 $query->setMaxResults($quantity);
             }
             $query->setStartIndex($offset_start);
             $feed = $this->_api->getUserUploads(null, $query);
             break;
         case self::CONTAINER_TYPE_PLAYLIST:
             $uri = Zend_Gdata_YouTube::USER_URI . '/default/playlists';
             $query = new Zend_Gdata_Query($uri);
             if ($quantity !== 0) {
                 $query->setMaxResults($quantity);
             }
             $query->setStartIndex($offset_start);
             $feed = $this->_api->getPlaylistListFeed(null, $query);
             break;
         default:
             throw new Bridge_Exception_ObjectUnknown('Unknown object ' . $object);
             break;
     }
     return $feed;
 }
Exemplo n.º 12
0
  /**
   * This function uses query parameters to retrieve and print all posts 
   * within a specified date range.
   *
   * @param string $startDate Beginning date, inclusive. Preferred format is 
   *                          a RFC-3339 date, though other formats are
   *                          accepted. 
   * @param string $endDate End date, exclusive.  
   */
  public function printPostsInDateRange($startDate, $endDate)
  {
      $query = new Zend_Gdata_Query('http://www.blogger.com/feeds/' . $this->blogID . '/posts/default'); 
      $query->setParam('published-min', $startDate);
      $query->setParam('published-max', $endDate); 
 
      $feed = $this->gdClient->getFeed($query); 
      $this->printFeed($feed); 
  }
Exemplo n.º 13
0
 /**
  * retrieves email ids for all the contacts from Gmail and stores in Ofuz DB temprorily.
  *
  * @return void
  * @see Gdata
  */
 function storeGmailEmailsTemprorily()
 {
     global $_SESSION, $_GET;
     $client = $this->client;
     $useremailid = urlencode($_SESSION["uEmail"]);
     // Create a Gdata object using the authenticated Http Client
     $gdata = new Zend_Gdata($client);
     //$query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/'.$_SESSION["uEmail"].'%40gmail.com/full');
     $query = new Zend_Gdata_Query('http://www.google.com/m8/feeds/contacts/' . $useremailid . '/full');
     $query->setMaxResults(1000);
     try {
         $feed = $gdata->getFeed($query);
         if ($feed) {
             $q_email = new sqlQuery($this->getDbCon());
             foreach ($feed as $entry) {
                 // retrieving emails
                 $extensionElements = $entry->getExtensionElements();
                 foreach ($extensionElements as $extensionElement) {
                     //emails
                     if ($extensionElement->rootNamespaceURI == "http://schemas.google.com/g/2005" && $extensionElement->rootElement == "email") {
                         $attributes = $extensionElement->getExtensionAttributes();
                         if (array_key_exists('address', $attributes)) {
                             if ($attributes['rel']['value'] == "http://schemas.google.com/g/2005#home") {
                                 //$data['em_home'] = $attributes['address']['value'];
                                 $sql_email_ins = "INSERT INTO \n                                                              temp_gmail_emails(email_address)\n                                                              VALUES('" . $attributes['address']['value'] . "')\n                                                            ";
                                 $q_email->query($sql_email_ins);
                             }
                             if ($attributes['rel']['value'] == "http://schemas.google.com/g/2005#work") {
                                 $sql_email_ins = "INSERT INTO \n                                                              temp_gmail_emails(email_address)\n                                                              VALUES('" . $attributes['address']['value'] . "')\n                                                            ";
                                 $q_email->query($sql_email_ins);
                             }
                             if ($attributes['rel']['value'] == "http://schemas.google.com/g/2005#other") {
                                 $sql_email_ins = "INSERT INTO \n                                                              temp_gmail_emails(email_address)\n                                                              VALUES('" . $attributes['address']['value'] . "')\n                                                            ";
                                 $q_email->query($sql_email_ins);
                             }
                         }
                     }
                 }
             }
             $q_email->free();
         }
     } catch (Exception $e) {
         $status_code = $gdata->getHttpClient()->getLastResponse()->getStatus();
         $this->status_code_desc = $this->getStatusDescription($status_code);
     }
 }
Exemplo n.º 14
0
 function GetMessageList($folderid, $cutoffdate)
 {
     debugLog('GContacts::GetMessageList(' . $folderid . ')');
     $messages = array();
     try {
         // perform query and get feed of all results
         $query = new Zend_Gdata_Query(GCONTACTS_URL);
         $query->maxResults = 999999;
         //$query->group = "My Contacts";
         $query->setParam('orderby', 'lastmodified');
         $query->setParam('sortorder', 'descending');
         $feed = $this->service->getFeed($query);
     } catch (Exception $e) {
         debugLog('Gcontacts::GetMessageList - Error while opening feed (' . $e->exception() . ')');
         return false;
     }
     debugLog('GContacts::GetMessageList(' . $folderid . ')' . ' -' . $feed->title . ' ' . $feed->totalResults);
     // parse feed and extract contact information
     // into simpler objects
     $results = array();
     try {
         foreach ($feed as $entry) {
             $obj = new stdClass();
             $obj->edit = $entry->getEditLink()->href;
             $xmldata = $entry->getXML();
             //filter out real contact id without other garbage
             preg_match("/[_a-z0-9]+\$/", $entry->id, $matches);
             $contactid = $matches[0];
             $xml = simplexml_load_string($xmldata);
             $e["id"] = (string) $contactid;
             $e["flags"] = "1";
             $e["mod"] = strtotime((string) $entry->getUpdated());
             $results[] = $e;
             //debugLog((string)$entry->getUpdated());
         }
     } catch (Exception $e) {
         debugLog('Gcontacts::GetMessageList - Problem retrieving data (' . $e->exception() . ')');
         return false;
     }
     return $results;
 }
Exemplo n.º 15
0
 function GoogleContactPhoto($GoogleContactsClient)
 {
     $data = array();
     $lnkPhotoGet = 'http://google.com/m8/feeds/contacts/jayanth.bagare%40gmail.com/full';
     $gdata = new Zend_Gdata($GoogleContactsClient);
     $query = new Zend_Gdata_Query($lnkPhotoGet);
     $query->setMaxResults(10000);
     $feed = $gdata->getFeed($query);
     foreach ($feed as $entry) {
         array_push($data, $entry);
     }
     $contacts[] = $data;
     foreach ($contacts as $entry) {
         if ($entry['link_photo']) {
             Zend_Loader::loadClass('Zend_Http_Response');
             $http_response = $gdata->get($entry['link_photo']);
             $rawImage = $http_response->getBody();
             $headers = $http_response->getHeaders();
             $contentType = $headers["Content-type"];
             header("Content-type: " . $contentType);
             var_dump($rawImage);
         }
     }
 }
Exemplo n.º 16
0
	foreach ( $dest_feed as $entry ) {

		if ( !$editlink = $entry->getEditLink() )
			continue;

		$entry = $dest_gdata->getEntry( $editlink->getHref() );
		$dest_gdata->delete( $entry );

		message( '  Deleted ' . $entry->title );
	}
	message( 'Existing "My Contacts" cleared from destination account.' );
}

// Fetch all source contacts
message( 'Fetching all "My Contacts" from source account...' );
$source_query = new Zend_Gdata_Query( 'http://www.google.com/m8/feeds/contacts/default/full' );
$source_query->maxResults = 99999;
$source_query->setParam( 'group', 'http://www.google.com/m8/feeds/groups/' . urlencode($source_user) . '/base/6' ); // "My Contacts" only
$source_feed = $source_gdata->getFeed( $source_query );
message( $source_feed->totalResults . ' contacts found.' );

// Add contacts from source account to the destination account
message( 'Creating contacts in destination account...' );
foreach ( $source_feed as $entry ) {
	//if ( 'Test Contact' != $entry->title ) continue;

	// Tweak the entry slightly
	$xml = $entry->getXML();
	$xml = str_replace( urlencode( $source_user ), urlencode( $dest_user ), $xml );

	// Insert the entry into the destination acccount
Exemplo n.º 17
0
 /**
  *
  * @param $maxResults int
  *       	 Maximum number of YoutubeVideo to return.
  * @return array(YoutubeVideo) Videos retrieved.
  */
 public function getRelatedVideos($maxResults)
 {
     try {
         if (!class_exists('Zend_Loader')) {
             require_once WPPostsRateKeys::$plugin_dir . 'classes/YoutubeWordpress/Zend/Loader.php';
         }
         Zend_Loader::loadClass('Zend_Gdata_Query');
         Zend_Loader::loadClass('Zend_Gdata_YouTube');
         $query = new Zend_Gdata_Query(Zend_Gdata_YouTube::VIDEO_URI . "/{$this->videoEntry->getVideoId()}/" . Zend_Gdata_YouTube::RELATED_URI_SUFFIX);
         $query->setMaxResults($maxResults);
         $yt = new Zend_Gdata_YouTube();
         $yt->setMajorProtocolVersion(2);
         $relatedVideosFeed = $yt->getFeed($query, 'Zend_Gdata_YouTube_VideoFeed');
         // TODO See how this initialization must be done, I mean if is really neccesary.
         $relatedVideos = array();
         foreach ($relatedVideosFeed as $relatedVideoEntry) {
             $relatedVideos[] = new YoutubeVideo($relatedVideoEntry);
         }
         return $relatedVideos;
     } catch (Exception $e) {
         // Store to log
         $msg_to_log = 'Error while getRelatedVideos from Youtube' . ', Exception Msg: ' . $e->getMessage();
         // Add log
         WPPostsRateKeys_Logs::add_error('362', $msg_to_log);
         return array();
     }
 }
Exemplo n.º 18
0
<?php

/**
 *
 * File is under copyright of Bouke Haarsma and can
 * only be used with written permission of the author.
 *
 * @author Bouke Haarsma <*****@*****.**>
 * @copyright 2010, Bouke Haarsma
 */
require "config.php";
$client = Zend_Gdata_ClientLogin::getHttpClient($email, $password, "cp");
$gdata = new Zend_Gdata($client);
$query = new Zend_Gdata_Query("http://www.google.com/m8/feeds/contacts/{$email}/full");
$query->setParam("group", $group);
$feed = $gdata->getFeed($query);
$xml = new SimpleXMLElement($feed->getXML(), null, null, "http://www.w3.org/2005/Atom");
$xml->registerXPathNamespace("default", "http://schemas.google.com/g/2005");
$entries = $xml->xpath("//atom:entry/default:phoneNumber[@rel != 'http://schemas.google.com/g/2005#work_fax']");
$phonebook = array();
foreach ($entries as $phone) {
    $name = $phone->xpath("../atom:title");
    $phone = preg_replace("/([^\\+^0-9])/", "", $phone[0]);
    $phone = preg_replace("/^(\\+31|0031)/", "0", $phone);
    $phonebook[] = sprintf("n=%s;p=%s", $name[0], $phone);
}
// field names vary between spa models
// get all field names from directory
// (thanks to Lennart van der Hoorn)
$spaDir = file_get_contents('http://{$ip}/pdir.htm');
preg_match_all('/name="([0-9]{5})"/', $spaDir, $fields);
Exemplo n.º 19
0
 function GoogleContactPhoto($GoogleContactsClient, $ContactEmail)
 {
     $lnkPhotoGet = 'http://google.com/m8/feeds/photos/media/';
     $gdata = new Zend_Gdata($GoogleContactsClient);
     $query = new Zend_Gdata_Query($lnkPhotoGet . $ContactEmail . '/c9012de');
     $query->setMaxResults(10000);
     $feed = $gdata->retrieveAllEntriesForFeed($gdata->getFeed($query));
 }