Location: PHPKode > projects > PHP Contact List Grabber > grabbers/grab.class.php
<?php

	/************************************************************************************************
	*	Copyright 2007 Ma'moon Al-Akash hide@address.com					*
	*												*
	*	This program is free software; you can redistribute it and/or modify			*
	*	it under the terms of the GNU General Public License as published by			*
	*	the Free Software Foundation; either version 2 of the License, or			*
	*	(at your option) any later version.							*
	*												*
	*	This program is distributed in the hope that it will be useful,				*
	*	but WITHOUT ANY WARRANTY; without even the implied warranty of				*
	*	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the				*
	*	GNU General Public License for more details.						*
	*												*
	*	You should have received a copy of the GNU General Public License			*
	*	along with this program; if not, write to the Free Software				*
	*	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA		*
	*************************************************************************************************/
	
			//////////////////////////////////////////////////////////////////////////
			// 	initial credet for this class goes to Ma'moon Al-Akash.   	//
			// 	if you have any ideas or suggestions then please contact	//
			//	me at hide@address.com		 				//
			//////////////////////////////////////////////////////////////////////////



	/**
	 * This class should interact with the actuall grabbers, it acts as an interface to use the appropriate grabber
	 */

	class Grabber{
		// private data members section
		var $_username;
		var $_password;
		var $_provider;
		var $_contactList = array(); // This array will contain the grabbed contact list

		/**
		 * Constructor of the class used to initialize the private data members
		 * @param Array that contains the credets.
		 * @return VOID, it returns nothing, it only initialize the private members.
		 */
		function Grabber( $access ){
			// initliaze the private members
			$this->_initializePrivates( $access );
		}

		/**
		 * Initilize the Private members and make some checks
		 * @param $credets, an array that contains the proper values for each private member
		 * @return VOID, it returns nothing, this is the actuall initilizer
		 */
		function _initializePrivates( $credets ){

			// prepare the items that needs to be validated
			$items = array( 'username' => $credets['username'], 'password' => $credets['password'], 'provider' => $credets['provider'] );

			// validate the items please ... :)
			include_once( 'validations/validation.class.php' );
			$validate = new validation;
			$validate->validate_trim( $items );
			$validate->validate_empty( $items );

			// and safely initialize the privates ...
			$this->_username  = $items['username'];
			$this->_password  = $items['password'];
			$this->_provider  = $items['provider'];
		}

		/**
		 * Returns the value of $this->_username
		 * @return String, the value of $this->_username.
		 */
		function _getUsername(){
			return $this->_username;
		}
		
		/**
		 * Returns the value of $this->_password
		 * @return String, the value of $this->_password.
		 */
		function _getPassword(){
			return $this->_password;
		}

		/**
		 * Return the value of $this->_provider
		 * @return String, the value of $this->_provider.
		 */
		function _getProvider(){
			return $this->_provider;
		}

		/**
		 * Return the value of $this->_contactList
		 * @return Array, the array that contains the contact list.
		 */
		function getContactList(){
			return $this->_contactList;
		}

		/**
		 * Sets $this->_contactList to the provided array
		 * @param $contactList, an array that contains a contact list
		 * @return VOID, it returns nothing, just sets $this->_contactList to the proper value
		 */
		function _setContactList( $contactList ){
			$this->_contactList = $contactList;
		}

		/**
		 * From here we start the process of grabbing by calling the proper grabber method.
		 * @return array, an array that contains the contact list for the user's account.
		 */
		function grab(){
			switch( $this->_getProvider() ){
				case 'G':
					$this->_grabGmail();
				break;
				case 'Y':
					$this->_grabYahoo();		
				break;
				case 'M':
					$this->_grabMSNMessenger();
				break;
				case 'A':
					$this->_grabAol();
				break;
				case 'L':
					$this->_grabLycos();
				break;
			}
			return $this->getContactList();
		}

		/**
		 * This method used to deal with Gmail.
		 * @return Array, an array that contains the contact list for the Gmail account.
		 */
		function _grabGmail(){
			include_once( 'grabbers/gmail/libgmailer.php' );
			$contactList = array();
			$gmailer = new GMailer();
			/*
			if ($gmailer->created){
				$gmailer->setLoginInfo( $this->_getUsername(), $this->_getPassword(), $my_timezone, 0 );
				//if you are using a proxy then uncomment the following single line and modify it according to your settings.                                                //$gmailer->setProxy("proxy.company.com");
				if ($gmailer->connect()){
					//GMailer connected to Gmail successfully.
					//Do something with it.
					//Get the contacts
					//For "Inbox"
					$gmailer->fetchBox(GM_CONTACT, "all", "");
					$snapshot = $gmailer->getSnapshot(GM_CONTACT);
					$gmailer->disconnect();
					//Outputs an array of the contacts
					foreach( $snapshot->contacts as $key => $value ){
						$contactList[$value['name']] = $value['email'];
					}
					// now set our private member to the proper value :)
					$this->_setContactList( $contactList );
				}else{
					die("Fail to connect because: ".$gmailer->lastActionStatus());
				}
			} else {
				die('couldn\'t instantiate an object from the libgmailer class!');
			}
			*/
			$contactList = $gmailer->getAddressbook( $this->_getUsername(), $this->_getPassword() );
			$this->_setContactList( $contactList );
		}

		/**
		 * This method used to deal with Yahoo!.
                 * @return Array, an array that contains the contact list for the Yahoo! account.
		 */
		function _grabYahoo(){
			include_once( 'grabbers/yahoo/class.GrabYahoo.php' );
			$yahooContacts = new yahooGrabber( $this->_getUsername(), $this->_getPassword() );
                        $this->_setContactList( $yahooContacts->grabYahoo() );			
		}

                /**
                 * This method used to deal with MSN Messenger Contacts.
                 * @return Array, an array that contains the contact list for the MSN Messenger account.
                 */
		function _grabMSNMessenger(){
			include_once( 'grabbers/msnm/msn_contact_grab.class.php' );
			$contactList = array();
			$msnMessengerContacts = new msn;
			$tmp = $msnMessengerContacts->qGrab( $this->_getUsername(), $this->_getPassword());
			foreach( $tmp as $row ){
				$contactList[$row['1']] = $row['0'];
			}
                        // now set our private member to the proper value :)
                        $this->_setContactList( $contactList );
		}

                /**
                 * This method used to deal with AOL Contacts.
                 * @return Array, an array that contains the contact list for the AOL account.
                 */
		function _grabAol(){
			include_once( 'grabbers/aol/aol.class.php' );
			$aolContacts = new grabAol( $this->_getUsername(), $this->_getPassword() );
			$this->_setContactList( $aolContacts->getContactList() );
		}

		/**
		 * This method used to deal with Lycos Contacts.
		 * @return Array, an array that contains the contact list for the Lycos account.
		 */
		function _grabLycos(){
			include_once( 'grabbers/lycos/lycos.class.php' );
			$lycos = new grabLycos( $this->_getUsername(), $this->_getPassword() );
			$this->_setContactList( $lycos->getContactList() );
		}
	}
?>
Return current item: PHP Contact List Grabber