PageRenderTime 53ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/_plugins_/openinviter/OpenInviter/plugins/bordermail.plg.php

https://bitbucket.org/pombredanne/spip-zone-treemap
PHP | 194 lines | 143 code | 14 blank | 37 comment | 15 complexity | 30190fa3da58d63ddd7e30e6ab0190dc MD5 | raw file
  1. <?php
  2. $_pluginInfo=array(
  3. 'name'=>'Bordermail',
  4. 'version'=>'1.0.3',
  5. 'description'=>"Get the contacts from a Bordermail account",
  6. 'base_version'=>'1.6.5',
  7. 'type'=>'email',
  8. 'check_url'=>'http://www.boardermail.com/',
  9. 'requirement'=>'user',
  10. 'allowed_domains'=>false,
  11. 'imported_details'=>array('first_name','email_1'),
  12. );
  13. /**
  14. * Bordermail Plugin
  15. *
  16. * Imports user's contacts from Bordermail AddressBook
  17. *
  18. * @author OpenInviter
  19. * @version 1.0.0
  20. */
  21. class bordermail extends openinviter_base
  22. {
  23. private $login_ok=false;
  24. public $showContacts=true;
  25. public $internalError=false;
  26. protected $timeout=30;
  27. public $debug_array=array(
  28. 'initial_get'=>'name="mailcom"',
  29. 'login_post'=>'mailcomframe',
  30. 'inbox'=>'outblaze',
  31. 'export_page'=>'addrURL',
  32. 'post_contacts'=>'csv',
  33. 'file_contacts'=>'Title'
  34. );
  35. /**
  36. * Login function
  37. *
  38. * Makes all the necessary requests to authenticate
  39. * the current user to the server.
  40. *
  41. * @param string $user The current user.
  42. * @param string $pass The password for the current user.
  43. * @return bool TRUE if the current user was authenticated successfully, FALSE otherwise.
  44. */
  45. public function login($user,$pass)
  46. {
  47. $this->resetDebugger();
  48. $this->service='bordermail';
  49. $this->service_user=$user;
  50. $this->service_password=$pass;
  51. if (!$this->init()) return false;
  52. $res=$this->get("http://www.mail.com/login.aspx?domain=boardermail.com&lang=en",true);
  53. if ($this->checkResponse('initial_get',$res))
  54. $this->updateDebugBuffer('initial_get',"http://www.mail.com/login.aspx?domain=boardermail.com&lang=en",'GET');
  55. else
  56. {
  57. $this->updateDebugBuffer('initial_get',"http://www.mail.com/login.aspx?domain=boardermail.com&lang=en",'GET',false);
  58. $this->debugRequest();
  59. $this->stopPlugin();
  60. return false;
  61. }
  62. $form_action=$this->getElementString($res,'name="mailcom" action="','"');
  63. $post_elements=array("login"=>"{$user}","password"=>"{$pass}","redirlogin"=>1,"siteselected"=>"normal");
  64. $res=$this->post($form_action,$post_elements,true);
  65. if ($this->checkResponse('login_post',$res))
  66. $this->updateDebugBuffer('login_post',"{$form_action}",'POST',true,$post_elements);
  67. else
  68. {
  69. $this->updateDebugBuffer('login_post',"{$form_action}",'POST',false,$post_elements);
  70. $this->debugRequest();
  71. $this->stopPlugin();
  72. return false;
  73. }
  74. $url_redirect=$this->getElementDOM($res,"//frame[@name='mailcomframe']",'src');
  75. $res=$this->get($url_redirect[0],true);
  76. $this->login_ok=$url_redirect[0];
  77. return true;
  78. }
  79. /**
  80. * Get the current user's contacts
  81. *
  82. * Makes all the necesarry requests to import
  83. * the current user's contacts
  84. *
  85. * @return mixed The array if contacts if importing was successful, FALSE otherwise.
  86. */
  87. public function getMyContacts()
  88. {
  89. if (!$this->login_ok)
  90. {
  91. $this->debugRequest();
  92. $this->stopPlugin();
  93. return false;
  94. }
  95. else $url=$this->login_ok;
  96. $res=$this->get($url,true);
  97. if ($this->checkResponse('inbox',$res))
  98. $this->updateDebugBuffer('login_post',"{$url}",'GET');
  99. else
  100. {
  101. $this->updateDebugBuffer('login_post',"{$url}",'GET',false);
  102. $this->debugRequest();
  103. $this->stopPlugin();
  104. return false;
  105. }
  106. $url_contacts=$this->getElementDOM($res,"//a[@id='addrURL']",'href');
  107. $res=$this->get($url_contacts[0],true);
  108. if ($this->checkResponse("export_page",$res))
  109. {
  110. $url_export="";
  111. $doc=new DOMDocument();libxml_use_internal_errors(true);if (!empty($res)) $doc->loadHTML($res);libxml_use_internal_errors(false);
  112. $xpath=new DOMXPath($doc);$query="//a[@href]";$data=$xpath->query($query);
  113. foreach($data as $val)
  114. if (strstr($val->nodeValue,"Import/Export")) $url_export=$val->getAttribute('href')."&gab=1";
  115. $this->updateDebugBuffer('post_contacts',"{$url_contacts[0]}",'GET');
  116. }
  117. else
  118. {
  119. $this->updateDebugBuffer('post_contacts',"{$url_contacts[0]}",'GET',false);
  120. $this->debugRequest();
  121. $this->stopPlugin();
  122. return false;
  123. }
  124. $post_elements=array("showexport"=>"showexport","action"=>"export","format"=>"csv");
  125. $res=$this->post($url_export,$post_elements);
  126. if ($this->checkResponse('file_contacts',$res))
  127. {
  128. $temp=$this->parseCSV($res);
  129. $contacts=array();
  130. foreach ($temp as $values)
  131. {
  132. $name=$values['0'].(empty($values['1'])?'':(empty($values['0'])?'':'-')."{$values['1']}").(empty($values['3'])?'':" \"{$values['3']}\"").(empty($values['2'])?'':' '.$values['2']);
  133. if (!empty($values['4']))
  134. $contacts[$values['4']]=(empty($name)?$values['4']:$name);
  135. if (!empty($values['12']))
  136. $contacts[$values['12']]=(empty($name)?$values['12']:$name);
  137. if (!empty($values['13']))
  138. $contacts[$values['13']]=(empty($name)?$values['13']:$name);
  139. }
  140. //full description
  141. $teM=explode(PHP_EOL,$res);$arrayDescriptionFlag=explode(',',$teM[0]);
  142. foreach($temp as $tempA)
  143. {
  144. $name=$tempA['0'].(empty($tempA['1'])?'':(empty($tempA['0'])?'':'-')."{$tempA['1']}").(empty($tempA['3'])?'':" \"{$tempA['3']}\"").(empty($tempA['2'])?'':' '.$tempA['2']);
  145. foreach ($arrayDescriptionFlag as $key=>$value)
  146. $descriptionArray[(!empty($name)?$name:(!empty($tempA[4])?$tempA[4]:false))][$value]=isset($tempA[$key])?$tempA[$key]:false;
  147. }
  148. //print_R($descriptionArray);
  149. $this->updateDebugBuffer('login_post',"{$url_export}",'POST',true,$post_elements);
  150. }
  151. else
  152. {
  153. $this->updateDebugBuffer('login_post',"{$url_export}",'POST',false,$post_elements);
  154. $this->debugRequest();
  155. $this->stopPlugin();
  156. return false;
  157. }
  158. foreach ($contacts as $email=>$name) if (!$this->isEmail($email)) unset($contacts[$email]);
  159. return $descriptionArray;
  160. }
  161. /**
  162. * Terminate session
  163. *
  164. * Terminates the current user's session,
  165. * debugs the request and reset's the internal
  166. * debudder.
  167. *
  168. * @return bool TRUE if the session was terminated successfully, FALSE otherwise.
  169. */
  170. public function logout()
  171. {
  172. if (!$this->checkSession()) return false;
  173. $res=$this->get("http://www.mail.com/logout.aspx");
  174. $this->debugRequest();
  175. $this->resetDebugger();
  176. $this->stopPlugin();
  177. return true;
  178. }
  179. }
  180. ?>