Example #1
0
 public function testSetAndGetGenericParam()
 {
     $query = new Zend_Gdata_Query();
     $query->setParam('fw', 'zend');
     $this->assertEquals('zend', $query->getParam('fw'));
     $this->assertContains('fw=zend', $query->getQueryUrl());
 }
 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;
 }
Example #3
0
 public function testSetAndGetGenericParam()
 {
     $query = new Zend_Gdata_Query();
     $query->setParam('fw', 'zend');
     $this->assertEquals('zend', $query->getParam('fw'));
     $this->assertTrue(strpos($query->getQueryUrl(), 'fw=zend') !== false);
 }
 /**
  * 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();
     }
 }
Example #5
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); 
  }
Example #6
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;
 }
Example #7
0
		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
	$response = $dest_gdata->insertEntry( $xml, 'http://www.google.com/m8/feeds/contacts/default/full' );
<?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);