1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
<?php
/*****************************************************************************
* @author : Ferdjaoui Sahid
* @email : sahid@funraill.org
* @blog : http://sahid.funraill.org
*
* @license : GNU GPL v3
****************************************************************************/
/**
* Contacts Class
************/
class Contacts
{
public static $arr_type = array ('Gmail', 'MSN', 'Yahoo', 'Lycos', 'AOL');
public static function factory ($user, $pass, $type)
{
if (in_array ($type, self::$arr_type))
{
$class = "{$type}Decorator";
return new $class ($user, $pass);
}
else throw new Exception ('Invalide type, utilisez : '.implode (", ", self::$arr_type));
}
}
class LycosDecorator
{
private $_instance;
private $_user;
private $_pass;
public function __construct ($user, $pass)
{
require ('libs/importLycos.class.php');
$this->_instance = new grabLycos ($user, $pass);
$this->_user = $user;
$this->_pass = $pass;
}
public function getContacts ()
{
$result = array ();
if (!is_object ($this->_instance))
throw new Exception ("Aucune instance");
$contacts = (array) @$this->_instance->getContactList ();
$i = 0;
foreach ($contacts as $name => $email)
{
$result[$i]['name'] = $name;
$result[$i]['email'] = $email;
$i++;
}
return $result;
}
}
class AOLDecorator
{
private $_instance;
private $_user;
private $_pass;
public function __construct ($user, $pass)
{
require ('libs/importAol.class.php');
$this->_instance = new grabAol ($user, $pass);
$this->_user = $user;
$this->_pass = $pass;
}
public function getContacts ()
{
$result = array ();
if (!is_object ($this->_instance))
throw new Exception ("Aucune instance");
$contacts = (array) @$this->_instance->getContactList ();
$i = 0;
foreach ($contacts as $name => $email)
{
$result[$i]['name'] = $name;
$result[$i]['email'] = $email;
$i++;
}
return $result;
}
}
class MSNDecorator
{
private $_instance;
private $_user;
private $_pass;
public function __construct ($user, $pass)
{
require ('libs/importMsn.class.php');
$this->_instance = new msn;
$this->_user = $user;
$this->_pass = $pass;
}
public function getContacts ()
{
$result = array ();
if (!is_object ($this->_instance))
throw new Exception ("Aucune instance");
$contacts = (array) @$this->_instance->qGrab ($this->_user, $this->_pass);
$i = 0;
foreach ($contacts as $contact)
{
$result[$i]['name'] = $contact['1'];
$result[$i]['email'] = $contact['0'];
echo '<b>Email : </b>'.$result[$i]['email'].'<br>';
$i++;
}
}
}
class YahooDecorator
{
private $_instance;
private $_user;
private $_pass;
public function __construct ($user, $pass)
{
require ('libs/importYahoo.class.php');
$this->_instance = new yahooGrabber ($user, $pass);
$this->_user = $user;
$this->_pass = $pass;
}
public function getContacts ()
{
$result = array ();
if (!is_object ($this->_instance))
throw new Exception ("Aucune instance Yahoo Grabber");
$contacts = (array) @$this->_instance->grabYahoo ();
$i = 0;
foreach ($contacts as $name => $email)
{
$result[$i]['name'] = $name;
$result[$i]['email'] = $email;
$i++;
}
return $result;
}
}
class GmailDecorator
{
private $_instance;
private $_user;
private $_pass;
public function __construct ($user, $pass)
{
require ('libs/importGmail.class.php');
$this->_instance = new GMailer;
$this->_user = $user;
$this->_pass = $pass;
}
public function getContacts ()
{
$result = array ();
if (!is_object ($this->_instance))
throw new Exception ("Aucune instance GMailer");
$this->_instance->setLoginInfo ($this->_user, $this->_pass, "+1GMT");
if ($this->_instance->connect ())
{
$this->_instance->fetchBox (GM_CONTACT, 'all', '');
$snapshot = $this->_instance->getSnapshot (GM_CONTACT);
$this->_instance->disconnect ();
$i = 0;
if (isset ($snapshot->contacts))
foreach ($snapshot->contacts as $contact)
{
$result[$i]['name'] = $contact['name'];
$result[$i]['email'] = $contact['email'];
$i++;
}
return $result;
}
else
throw new Exception ('Impossible de se connecter');
}
} |
Partager