PHP Classes
Icontem

File: Gmailimporter.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of inayat  >  GDataGmailer  >  Gmailimporter.php  
File: Gmailimporter.php
Role: Class source
Content type: text/plain
Description: Gmail importer using Gdata
Class: GDataGmailer
Import contacts from Gmail
 

Contents

Class file image Download
<?

class GDataGmailer 
{

/*

$googleUri = Zend_Gdata_AuthSub::getAuthSubTokenUri('http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'],urlencode($scope),
0, 1);

echo "Click <a href='$googleUri'>here</a> to authorize this application.";

*/
var $email;
var 
$pwd;

 function 
__construct($email,$pwd)
 {
     
$this->email $email;
     
$this->pwd $pwd
 }
 
function 
GoogleContactsAuth(){

       
       
/*
       Download from http://framework.zend.com/download/gdata .
       TODO ---> Please change the myfolder to ur working directory of file 
       */
        
ini_set('include_path','/myfolder/ZendGdata/library/');
        include_once(
'Zend/Loader.php');

        
Zend_Loader::registerAutoload();

        
$GoogleContactsService  'cp';

        
try {
            
$GoogleContactsClient   Zend_Gdata_ClientLogin::getHttpClient($this->email,$this->pwd$GoogleContactsService);
        }  
catch (Zend_Gdata_App_AuthException $ae) {
           return 
'0';
        }

        
$GoogleContactsClient   Zend_Gdata_ClientLogin::getHttpClient($this->email,$this->pwd$GoogleContactsService);

        return 
$GoogleContactsClient;

}

function 
GoogleContactsAll($GoogleContactsClient ){

        
$scope          "http://www.google.com/m8/feeds/contacts/".$this->email."/";

        
$gdata          = new Zend_Gdata($GoogleContactsClient);

        
$query          = new Zend_Gdata_Query($scope.'full');

        
$query->setMaxResults(10000);

        
$feed           $gdata->retrieveAllEntriesForFeed($gdata->getFeed($query));

        foreach (
$feed as $entry){

                
$contactName $entry->title->text;

                
$ext $entry->getExtensionElements();

                foreach(
$ext as $extension){

                        if(
$extension->rootElement == "email"){

                                
$attr=$extension->getExtensionAttributes();

                                
$contactMail $attr['address']['value'];

                        }else if(
$extension->rootElement == "phoneNumber"){

                                
$contactPhone $extension->text;

                        }else if(
$extension->rootElement == "postalAddress"){

                                
$contactAddr $extension->text;

                        }else if(
$extension->rootElement == "groupMembershipInfo"){

                                
$UrlGroup       $extension->extensionAttributes['href']['value'];

                                
$arrGroupEx     explode("/",$UrlGroup);

                                
$contactGrp     $arrGroupEx[(count($arrGroupEx)-1)];

                        }else if(
$extension->rootElement == "organization"){

                                
$attr=$extension->getExtensionElements();

                                if(
$attr[0]->rootElement == "orgName"){

                                        
$contactJob $attr[0]->text;

                                }

                                if(
$attr[1]->rootElement == "orgTitle"){

                                        
$contactPos $attr[1]->text;

                                }

                        }

                        if(
$contactName==""){

                                
$contactName $contactMail;

                        }

                }

                
$arrContactsData['contactMail']         = $contactMail;

                
$arrContactsData['contactName']         = $contactName;

                
$arrContactsData['contactPhone']        = $contactPhone;

                
$arrContactsData['contactAddr']         = $contactAddr;

                
$arrContactsData['contactJob']          = $contactJob;

                
$arrContactsData['contactPos']          = $contactPos;

                
$arrContactsData['contactGrp']          = $contactGrp;

                
$arrContacts[] = $arrContactsData;

        }

        return 
$arrContacts;

}

function 
GoogleGroupsAll($GoogleContactsClient ){

        
$scope          "http://www.google.com/m8/feeds/groups/".$this->email."/";

        
$gdata          = new Zend_Gdata($GoogleContactsClient);

        
$query          = new Zend_Gdata_Query($scope.'full');

        
$query->setMaxResults(10000);

        
$feed           $gdata->retrieveAllEntriesForFeed($gdata->getFeed($query));

        foreach (
$feed as $entry){

                
$arrGroupsData['groupName']     = $entry->title->text;

                
$arrIdExplode                   explode("/",$entry->id->text);

                
$arrGroupsData['groupId']       = $arrIdExplode[(count($arrIdExplode)-1)];

                
$GroupHref                      $entry->link[1];

                if(
$GroupHref->rootElement == "link"){

                        
$arrHrefExplode                 explode("/",$GroupHref->href);

                        
$arrGroupsData['groupHref']     = $arrHrefExplode[(count($arrHrefExplode)-1)];

                }

                
$arrGroups[] = $arrGroupsData;

        }

        return 
$arrGroups;

}
}
//end of class

 /*
       Download GDATA  from http://framework.zend.com/download/gdata . 
       Copy the Zend folder in library path of downloaded zip package
     
       TODO ---> in GoogleContactsAuth() function of this class, CHANGE  myfolder to Zend folder path
       
       If ur using  Zend Framework then no need to download GDATA . 
       */
 
$Gobject =& new  GDataGmailer('email@gmail.com','pasword');

$GClient  $Gobject->GoogleContactsAuth() ;
if( 
$GClient  != ) {
    echo 
'<pre>';
    
print_r$Gobject->GoogleContactsAll($GClient) ); 
    echo 
'</pre>';
}
?> 

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products