Welcome Guest, Not a member yet? Register   Sign In
I have created code to import gmail contact.(Controller)
#1

[eluser]Unknown[/eluser]
<?php
class Import extends Controller {
function Import()
{
parent::Controller();
$this->load->database();
$this->load->library(array('session','form_validation','validation','pagination','calendar'));
$this->load->helper(array('form','url','adminheader'));
$this->load->model('import_contact');

}
function index()
{$data = array('title' => 'Administrator | Import Contact','heading' => 'Administrator | Import Contact','message' => 'Please enter details to login.');
$config['base_url'] = $this->config->item('base_url').'index.php/import/';
$config['total_rows'] = $this->db->count_all('admins');
$config['per_page'] = 50;
$config['num_tag_open'] = $this->config->item('num_tag_open');
$config['num_tag_close'] = $this->config->item('num_tag_close');
$config['cur_tag_open'] = $this->config->item('cur_tag_open');
$config['cur_tag_close'] = $this->config->item('cur_tag_close');
$config['prev_link'] = $this->config->item('prev_link');
$config['prev_tag_open'] = $this->config->item('prev_tag_open');
$config['prev_tag_close'] = $this->config->item('prev_tag_close');
$config['next_link'] = $this->config->item('next_link');
$config['next_tag_open'] = $this->config->item('next_tag_open');
$config['next_tag_close'] = $this->config->item('next_tag_close');
$this->pagination->initialize($config);
$data['emailLists'] = $this->import_contact->getContact($config['per_page'],$this->uri->segment(2));
$this->load->view('admin_header',$data);
$this->load->view('import_contact',$data);

}
function parse_response($feed) {
$contacts = array();
$doc = new DOMDocument();
$doc->loadXML($feed);
$nodeList = $doc->getElementsByTagName( 'entry' );
foreach($nodeList as $node) {
$entry_nodes = $node->childNodes;
$tempArray = array();
foreach($entry_nodes as $child) {
$domNodesName = $child->nodeName;
switch($domNodesName) {
case "title":
{ $tempArray['fullName'] = $child->nodeValue; }
break;
case "gd:email":
{
if (strpos($child->getAttribute('rel'),'home')!==false)
$tempArray['email_1']=$child->getAttribute('address');
elseif(strpos($child->getAttribute('rel'),'work')!=false)
$tempArray['email_2']=$child->getAttribute('address');
elseif(strpos($child->getAttribute('rel'),'other')!==false)
$tempArray['email_3']=$child->getAttribute('address');
}
break;
}
}
if( !empty($tempArray['email_1'])) $contacts[$tempArray['email_1']] = $tempArray;
if( !empty($tempArray['email_2'])) $contacts[$tempArray['email_2']] = $tempArray;
if( !empty($tempArray['email_3'])) $contacts[$tempArray['email_3']] = $tempArray;
}
return $contacts;
}
function import_contact(){
$data = array('title' => 'Administrator | IMPORT CONTACT ','heading' => 'Administrator | IMPORT CONTACT','message' => 'Please enter details to login.' );
$username = $this->input->post('username');
$password = $this->input->post('password');
//store username and password and some values in array
$clientPost = array(
"accountType" => "HOSTED_OR_GOOGLE",
"Email" => $username,
"Passwd" => $password,
"service" => "cp",
"source" => "leaveurdream" // you can name it anything you want
);
$clientUrl = "https://www.google.com/accounts/ClientLogin";
$curl = curl_init($clientUrl);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $clientPost);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
preg_match("/Auth=([a-z0-9_\-]+)/i", $response, $matches);
$auth = $matches[1];
if( !empty($auth)) {
$headers = array("Authorization: GoogleLogin auth=".$auth);
$curl1 = curl_init("http://www.google.com/m8/feeds/contacts/default/full");
curl_setopt($curl1, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl1, CURLOPT_RETURNTRANSFER, 1);
$feed = curl_exec($curl1);
$emailLists = $this->parse_response($feed);
$res=$this->import_contact->insertEmail($username,$password);
}
else {
$emailLists = array("Invalid Username/Password");
}
$data['emailLists']=$emailLists;

foreach($emailLists as $contactlist){
$this->import_contact->insertContact($res,$contactlist['fullName'],$contactlist['email_3']);
}
$this->loa




Theme © iAndrew 2016 - Forum software by © MyBB