Programalama > PHP

Etiketler: gmail, adres, defteri

Ort. 1
Puan ver:
1. <-- GrabGmail.class.php sayfası kodları --> 
   2. <?php 
   3. /** 
   4. * Grab Gmail : Gmail Addressbook Grabber Class 
   5. * 
   6. * @author  :  MA Razzaque Rupom <rupom_315@yahoo.com>, <rupom.bd@gmail.com> 
   7. *             Moderator, phpResource (http://groups.yahoo.com/group/phpresource/) 
   8. *             URL: http://www.rupom.info   
   9. * @version :  1.0 
  10. * @date       06/09/2006 
  11. * Purpose  :  Grabbing Your Gmail Addressbook 
  12. */ 
  13.  
  14.   class GrabGmail 
  15.   { 
  16.      //To use it in PHP4, please replace each "private" by "var" 
  17.      private $contactListArray = array(); 
  18.      private $contactListTable; 
  19.      private $requireCaBundle = false; 
  20.      private $caBundleFile; 
  21.      private $cookiePath; 
  22.      private $proxyUrl=''; 
  23.      private $userId     =''; 
  24.      private $password   =''; 
  25.      private $url        = "https://www.google.com/accounts/ServiceLoginAuth";      
  26.      private $refererUrl = "https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http://mail.google.com/mail/?ui=html&zy=f&ltmpl=yj_blanco&ltmplcache=2&hl=en";  
  27.       
  28.      /** 
  29.      * Sets login information of Gmail account 
  30.      * @param user id and password 
  31.      * @return none 
  32.      */  
  33.      function setLoginInfo($userId, $password) 
  34.      { 
  35.       
  36.         $this->userId   = $userId; 
  37.         $this->password = $password;      
  38.       
  39.      }//EO Method 
  40.       
  41.      /** 
  42.      * Sets cookie save path(where cookie will be saved) 
  43.      * @param cookie path 
  44.      * @return none 
  45.      */       
  46.      function setCookiePath($cookiePath) 
  47.      { 
  48.         $this->cookiePath = $cookiePath;      
  49.      } 
  50.       
  51.      /** 
  52.      * Sets proxy information if any 
  53.      * @param proxy URL 
  54.      * @return none 
  55.      */  
  56.      function setProxy($proxyUrl) 
  57.      { 
  58.         $this->proxyUrl = $proxyUrl;        
  59.      } 
  60.       
  61.      /** 
  62.      * Sets Certificate Bundle File (this is necessary in accessing Gmail from localhost) 
  63.      * @param user id and password 
  64.      * @return none 
  65.      */  
  66.      function setCaBundleFile($fileName) 
  67.      { 
  68.         $this->requireCaBundle = true; 
  69.         $this->caBundleFile    = $fileName; //provide absolute path 
  70.      } 
  71.   
  72.      /** 
  73.      * Checks whether proxy info is set 
  74.      * @param none 
  75.      * @return none 
  76.      */      
  77.      function isProxy() 
  78.      { 
  79.         if($this->proxyUrl == '') 
  80.         { 
  81.            return false;         
  82.         } 
  83.          
  84.         return true;         
  85.       
  86.      }//EO Method 
  87.       
  88.      /** 
  89.      * Prepares contact list 
  90.      * @param none 
  91.      * @return none 
  92.      */  
  93.      function prepareContactList() 
  94.      { 
  95.       
  96.        if($this->userId == "" || $this->password=="") 
  97.        { 
  98.          die("Set Login Info");          
  99.        } 
 100.        else 
 101.        { 
 102.          $this->postRequestToGmail();          
 103.        }       
 104.       
 105.      }//EO Method 
 106.       
 107.      /** 
 108.      * Gets contact list in a table 
 109.      * @param none 
 110.      * @return Contact List Table 
 111.      */  
 112.      function getResultTable() 
 113.      { 
 114.         if(!empty($this->contactListTable)) 
 115.         { 
 116.            return $this->contactListTable;            
 117.         } 
 118.         else 
 119.         { 
 120.            return "List is Empty. Check your user id and password.";      
 121.         }      
 122.      }//EO Method 
 123.            
 124.      /** 
 125.      * Gets contact list in an array 
 126.      * @param none 
 127.      * @return Contact List Array 
 128.      */       
 129.      function getResultArray() 
 130.      { 
 131.         if(strlen($this->contactListTable)>33) 
 132.         { 
 133.            $strValue = $this->contactListTable;                       
 134.            $this->convertToArray($strValue);            
 135.             
 136.            return $this->contactListArray; 
 137.             
 138.         } 
 139.         else 
 140.         { 
 141.            return "List is Empty. Check your user id and password.";      
 142.         }      
 143.      }//EO Method 
 144.       
 145.      /** 
 146.      * Post request to Gmail, gets and parses contact list from Gmail 
 147.      * @param none 
 148.      * @return none 
 149.      */ 
 150.      function postRequestToGmail() 
 151.      { 
 152.          
 153.         $requestString  = "service=mail&Email=".urlencode($this->userId)."&Passwd=".urlencode(str_replace(' ','+',$this->password))."&null=Sign%20in&continue=http%3A%2F%2Fmail.google.com%2Fmail%3F&rm=false&hl=en"; 
 154.         $user_agent     = $_SERVER['HTTP_USER_AGENT'];   
 155.         $cookie         = 1;         
 156.         $cookieFileName = md5($this->userId);   
 157.          
 158.         //setting cookie file. make sure the file has write permission 
 159.         $cookieFileJar  = (isset($this->cookiePath))?($this->cookiePath. "/" . $cookieFileName) : ($_SERVER['DOCUMENT_ROOT'] . "/" . $cookieFileName);                         
 160.         $cookieFile     = $cookieFileJar; 
 161.         $refererUrl     = $this->refererUrl; 
 162.          
 163.         $c = curl_init(); 
 164.            curl_setopt($c, CURLOPT_URL, $this->url); 
 165.            curl_setopt($c, CURLOPT_HEADER, 1); 
 166.            curl_setopt($c, CURLOPT_POST,   1); 
 167.            //this referer tells Gmail that request is coming from Gmail 
 168.            curl_setopt($c, CURLOPT_REFERER, $this->refererUrl);                               
 169.            curl_setopt($c, CURLOPT_POSTFIELDS, $requestString);                     
 170.             
 171.            curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); 
 172.             
 173.            //Certificate information 
 174.         if($this->requireCaBundle) 
 175.         { 
 176.           if(isset($this->caBundleFile)) 
 177.           {              
 178.              curl_setopt($c, CURLOPT_CAINFO, $this->caBundleFile); 
 179.           } 
 180.           else 
 181.           { 
 182.              die("Provide CA Bundle File");      
 183.           }         
 184.         } 
 185.          
 186.         if($this->isProxy()) 
 187.         { 
 188.            curl_setopt($c, CURLOPT_PROXY, $this->proxyUrl); 
 189.            } 
 190.             
 191.            curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1); 
 192.            curl_setopt($c, CURLOPT_USERAGENT, $user_agent);           
 193.             
 194.            //writting cookie 
 195.            curl_setopt($c, CURLOPT_COOKIEJAR, $cookieFileJar);      
 196.            curl_setopt($c, CURLOPT_COOKIE, $cookie); 
 197.             
 198.            $res = curl_exec($c); 
 199.             
 200.            curl_close($c); 
 201.                                                  
 202.         $requestString ='http://mail.google.com/mail/?view=cl&pnl=a&ui=html&zy=f'; 
 203.          
 204.         //New curl session         
 205.         $ch = curl_init(); 
 206.                       
 207.            curl_setopt($ch, CURLOPT_URL, $requestString); 
 208.            curl_setopt($ch, CURLOPT_HEADER, 0); 
 209.          
 210.            curl_setopt($ch, CURLOPT_REFERER, $refererUrl);                               
 211.            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
 212.             
 213.            //Certificate information                  
 214.         if($this->requireCaBundle) 
 215.         { 
 216.           if(isset($this->caBundleFile)) 
 217.           {              
 218.              curl_setopt($ch, CURLOPT_CAINFO, $this->caBundleFile);              
 219.           } 
 220.           else 
 221.           { 
 222.              die("Provide CA Bundle File");      
 223.           }         
 224.         } 
 225.          
 226.         if($this->isProxy()) 
 227.         {               
 228.            curl_setopt($ch, CURLOPT_PROXY, $this->proxyUrl); 
 229.            } 
 230.             
 231.            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
 232.             curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); 
 233.              
 234.             //reading cookie 
 235.             curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);      
 236.              
 237.             curl_setopt($ch, CURLOPT_COOKIE, $cookie); 
 238.                          
 239.            $gmailResponse = curl_exec($ch);      
 240.             
 241.            curl_close($ch);      
 242.             
 243.            $parsedResponse  = $this->parseResponse($gmailResponse); 
 244.             
 245.            $this->contactListTable = $parsedResponse; 
 246.             
 247.      }//EO Method 
 248.       
 249.      /** 
 250.      * Converts table data to array data 
 251.      * @param Table of Contact List 
 252.      * @return Contact List Array 
 253.      */  
 254.      function convertToArray($strValue) 
 255.      { 
 256.         $strVal = str_replace("&nbsp;","",$strValue); 
 257.         $output = array();         
 258.         $strVal = nl2br($strVal); 
 259.         $strVal = str_replace("<br />",'',$strVal);             
 260.         $matches1 = preg_match_all("/<b>([^<]+)<\/b>/si",$strVal,$output, PREG_PATTERN_ORDER);            
 261.         $offset = array();         
 262.         $matches2 = preg_match_all("/<td[^>]*>([a-zA-Z0-9_\.]+@[a-zA-Z0-9_\.]+)?([^<]*)<\/td>/si",$strVal,$offset, PREG_PATTERN_ORDER);         
 263.          
 264.         //putting values into associative array                 
 265.         for($i=0;$i<sizeof($offset[2]); $i++) 
 266.         { 
 267.               $email = trim($offset[2][$i]); 
 268.               $name  = $output[1][$i];               
 269.            $this->contactListArray["'$email'"] =$name;                 
 270.         }                        
 271.       
 272.      }//EO Method   
 273.       
 274.      /** 
 275.      * Parses Gmail Response String 
 276.      * @param Gmail Response 
 277.      * @return Parsed Response 
 278.      */  
 279.      function parseResponse($str) 
 280.      { 
 281.         $str = nl2br($str); 
 282.         $str = str_replace("<br />","",$str); 
 283.         $str = preg_replace("/<script[^>]*?>.*?<\/script>/si","", $str); 
 284.         $off = array(); 
 285.         $matches = preg_match_all("/<table[^>]*?>.*?<\/table>/si", $str, $off,PREG_PATTERN_ORDER); 
 286.         $strVal = $off[0][6]; 
 287.          
 288.         return $strVal; 
 289.               
 290.      }//EO Method 
 291.       
 292.      /** 
 293.      * Debugs dump/data 
 294.      * @param $dump 
 295.      * @return none 
 296.      */ 
 297.      function dBug($dump) 
 298.      { 
 299.       
 300.         echo "<PRE>"; 
 301.         print_r($dump); 
 302.         echo "</PRE>";   
 303.       
 304.      }//EO Method 
 305.         
 306.   }//EO Class 
 307.   
 308. ?> 
 309.  
 310.  
 311. <!-- Kullanım --> 
 312. <?php 
 313. /** 
 314. * Grab Gmail : Gmail Addressbook Grabber Class 
 315. * 
 316. * @author  :  MA Razzaque Rupom <rupom_315@yahoo.com>, <rupom.bd@gmail.com> 
 317. *             Moderator, phpResource (http://groups.yahoo.com/group/phpresource/) 
 318. *             URL: http://www.rupom.info   
 319. * @version :  1.0 
 320. * @date       06/09/2006 
 321. * Purpose  :  Grabbing Your Gmail Addressbook 
 322. */ 
 323.  
 324.   require_once("GrabGmail.class.php"); 
 325.    
 326.   $login = 'gmail_kullanici_adi';          // @gmail.com yazmayınız" 
 327.   $password = 'gmail_sifreniz'; 
 328.    
 329.   $obj = new GrabGmail(); 
 330.   $obj->setLoginInfo($login, $password); 
 331.   $obj->setCaBundleFile("D:/Rupom/xampp/htdocs/xampp/Test/ca-bundle.crt"); 
 332.   $obj->setProxy("proxy.citech.net:8000"); 
 333.   $obj->prepareContactList(); 
 334.   $obj->dBug("===== <b>$login@gmail.com</b> Kullanıcısına Ait Adres Defteri ====="); 
 335.   $obj->dBug('---- Contacts in Table ------'); 
 336.   $resultTable = $obj->getResultTable(); 
 337.   $obj->dBug($resultTable); 
 338.   $obj->dBug('---- Contacts in Array ------'); 
 339.   $resultArray = $obj->getResultArray(); 
 340.   $obj->dBug($resultArray);     
 341. ?>

ßurack
burakcemuruk@hotmail.com


Yorumlar                 Yorum Yaz
Bu hazır kod'a ilk yorumu siz yapın!
KATEGORİLER
ASP - 240
ASP.NET - 24
C# - 75
C++ - 174
CGI - 8
DELPHI - 247
FLASH - 49
HTML - 536
PASCAL - 246
PERL - 11
PHP - 160
WML - 9
XML - 2
Copyright © 2002 - 2018 Hazır Kod - Tüm Hakları Saklıdır.
Siteden yararlanırken gizlilik ilkelerini okumanızı tavsiye ederiz.
hazirkod.com bir İSOBİL projesidir.