function getAddressbook($gmail_acc, $gmail_pwd) { $my_timezone = 0; $gmailer = new GMailer(); if ($gmailer->created) { $gmailer->setLoginInfo($gmail_acc, $gmail_pwd, $my_timezone); echo "Created gmailer obj...<br />"; if ($gmailer->connect()) { echo 'connected with gmailer obj...<br />'; // GMailer connected to Gmail successfully. // Do something with it. //Get the contacts // For "Inbox" $gmailer->fetchBox(GM_CONTACT, "all", ""); $snapshot = $gmailer->getSnapshot(GM_CONTACT); //Outputs an array of the contacts return $snapshot; return $snapshot->contacts; //Outputs the number of contacts //var_dump($snapshot->contacts_total); } else { return $gmailer->lastActionStatus(); } } }
<?php require_once 'libgmailer.php'; require_once '../Templates.php'; error_reporting(0); $gm = new GMailer(); if (!$gm->created) { die("GMailer not created"); } $gm->getCookieFromBrowser(); $mode = $_GET['mode']; if (strlen($mode) != 0 and $mode != 'enter' and !$gm->isConnected()) { header("Location: ?"); } switch ($mode) { case 'new': $tpl = new Templates('tpls'); $tpl->set('contact_form', array('name' => "", 'email' => "", 'id' => -1)); $tpl->set('main', 'content', $tpl->parse('contact_form')); print $tpl->parse('main'); break; case 'edit': $id = $_GET['id']; if (!$gm->fetchBox(GM_CONTACT, 'detail', $id)) { die($gm->lastActionStatus()); } $sps = $gm->getSnapshot(GM_CONTACT); $tpl = new Templates('tpls'); foreach ($sps->contacts as $c) { $tpl->set('contact_form', array('name' => $c['name'], 'email' => $c['email'], 'id' => $id)); $tpl->set('main', 'content', $tpl->parse('contact_form'));
/** * Parse Gmail responses. * * @access private * @static * @return bool * @param string $raw_html * @since 7 Jun 2005 */ function parse_gmail_response($raw_html, $non_standard = false) { $raw_html = str_replace("\n", "", $raw_html); $raw_html = str_replace("D([", "\nD([", $raw_html); $raw_html = str_replace("]);", "]);\n", $raw_html); // Fix Gmail's conversion of = and /; by Neerav; 18 Dec 2005 // Added < and >; by Neerav; 4 Mar 2007 $raw_html = str_replace(array('u003d', 'u002f', 'u003c', 'u003e'), array('=', '/', '<', '>'), $raw_html); $regexp = !$non_standard ? "|D\\(\\[(.*)\\]\\);|U" : "/\\[(.*)\\]/"; $matches = ""; preg_match_all($regexp, $raw_html, $matches, PREG_SET_ORDER); $packets = array(); for ($i = 0; $i < count($matches); $i++) { $off = 0; $tmp = GMailer::parse_data_packet("[" . $matches[$i][1] . "]", $off); if (array_key_exists($tmp[0], $packets) || ($tmp[0] == "mi" || $tmp[0] == "mb" || $tmp[0] == "di")) { // Added cl as alternate contact datapack; by Neerav; 15 June 2005 if ($tmp[0] == "t" || $tmp[0] == "ts" || $tmp[0] == "a" || $tmp[0] == "cl") { $packets[$tmp[0]] = array_merge($packets[$tmp[0]], array_slice($tmp, 1)); } if ($tmp[0] == "mi" || $tmp[0] == "mb" || $tmp[0] == "di") { if (array_key_exists("mg", $packets)) { array_push($packets["mg"], $tmp); } else { $packets["mg"] = array($tmp); } } } else { $packets[$tmp[0]] = $tmp; } } $this->raw = $packets; return 1; }
/** * Parse Gmail responses. * * @access private * @static * @return bool * @param string $raw_html * @since 7 Jun 2005 */ function parse_gmail_response($raw_html) { $raw_html = str_replace("\n", "", $raw_html); $raw_html = str_replace("D([", "\nD([", $raw_html); $raw_html = str_replace("]);", "]);\n", $raw_html); // Fix Gmail's conversion of = and /; by Neerav; 18 Dec 2005 $raw_html = str_replace(array('u003d', 'u002f'), array('=', '/'), $raw_html); /* $raw_html = preg_replace(array('/(<[^>]*?u003d[^>]*?'.'>)/e'),array('str_replace("u003d","=",\1)'),$raw_html); */ /* $raw_html = str_replace(array('\\\\u003d\\\\','\\\\u002f\\\\'),array('=','/'),$raw_html); */ /* $raw_html = preg_replace(array('/(<[^>]*?u003d[^>]*?'.'>)/e'),array('str_replace("u003d","=",\1)'),$raw_html); */ /* $raw_html = preg_replace('/(\w)u003d\"/','\\1=\\2',&$raw_html); */ /* $raw_html = str_replace(array('u003d\"','u002f'),array('=\"','/'),$raw_html); */ /* $raw_html = preg_replace(array('/(<[^>]*?)u003d/'),array('\\1='),$raw_html); */ $regexp = "|D\\(\\[(.*)\\]\\);|U"; $matches = ""; preg_match_all($regexp, $raw_html, $matches, PREG_SET_ORDER); $packets = array(); for ($i = 0; $i < count($matches); $i++) { $off = 0; $tmp = GMailer::parse_data_packet("[" . $matches[$i][1] . "]", $off); if (array_key_exists($tmp[0], $packets) || ($tmp[0] == "mi" || $tmp[0] == "mb" || $tmp[0] == "di")) { // Added cl as alternate contact datapack; by Neerav; 15 June 2005 if ($tmp[0] == "t" || $tmp[0] == "ts" || $tmp[0] == "a" || $tmp[0] == "cl") { $packets[$tmp[0]] = array_merge($packets[$tmp[0]], array_slice($tmp, 1)); } if ($tmp[0] == "mi" || $tmp[0] == "mb" || $tmp[0] == "di") { if (array_key_exists("mg", $packets)) { array_push($packets["mg"], $tmp); } else { $packets["mg"] = array($tmp); } } } else { $packets[$tmp[0]] = $tmp; } } $this->raw = $packets; return 1; }
/** * Parse status replies. * * @access private * @static * @return bool * @param string $raw_html * @author Neerav * @since 7 Jun 2005 */ function status_message($raw_html) { Debugger::say("Begin parsing status..."); $raw_html = str_replace("\n", "", $raw_html); $raw_html = str_replace("D([", "\nD([", $raw_html); $raw_html = str_replace("]);", "]);\n", $raw_html); $regexp = "|D\\(\\[(.*)\\]\\);|U"; $matches = ""; preg_match_all($regexp, $raw_html, $matches, PREG_SET_ORDER); $packets = array(); for ($i = 0; $i < count($matches); $i++) { $off = 0; $tmp = GMailer::parse_data_packet("[" . $matches[$i][1] . "]", $off); if (array_key_exists($tmp[0], $packets) || ($tmp[0] == "mi" || $tmp[0] == "mb" || $tmp[0] == "di")) { if ($tmp[0] == "t" || $tmp[0] == "ts" || $tmp[0] == "a" || $tmp[0] == "cl") { $packets[$tmp[0]] = array_merge($packets[$tmp[0]], array_slice($tmp, 1)); } if ($tmp[0] == "mi" || $tmp[0] == "mb" || $tmp[0] == "di") { if (array_key_exists("mg", $packets)) { array_push($packets["mg"], $tmp); } else { $packets["mg"] = array($tmp); } } } else { $packets[$tmp[0]] = $tmp; } } $this->raw = $packets; Debugger::say("Status parsing completed."); return 1; }
/** * Parse Gmail responses. * * @access private * @static * @return bool * @param string $raw_html * @since 7 Jun 2005 */ function parse_gmail_response($raw_html, $non_standard = false) { //Debugger::say(basename(__FILE__).": ".__LINE__.": "."parse_gmail_response(): start:\n".print_r($raw_html,true)); $raw_html = str_replace("\n", "", $raw_html); /* $raw_html = str_replace("D([", "\nD([", $raw_html); */ /* $raw_html = str_replace("]);", "]);\n", $raw_html); */ // combined multiple str_replace into one; Neerav; 12 Sept 2007 $raw_html = str_replace(array("D([", "]);"), array("\nD([", "]);\n"), $raw_html); // Fix Gmail's conversion of = and /; by Neerav; 18 Dec 2005 // Added < and >; by Neerav; 4 Mar 2007 // Added \> (Gmail is doing something wierd); Neerav; 12 Sept 2007 // Added &; Neerav; 10 Dec 2007 $raw_html = str_replace(array('\\u003d', '\\u002f', '\\u003c', '\\u003e', '\\>', '\\u0026'), array('=', '/', '<', '>', '>', '&'), $raw_html); //Debugger::say(basename(__FILE__).": ".__LINE__.": "."parse_gmail_response(): cleaned:\n".print_r($raw_html,true)); /* // combined multiple str_replace into one; Neerav; 12 Sept 2007 */ /* $raw_html = str_replace(array("D([","]);",'u003d','u002f','u003c','u003e'), array("\nD([","]);\n",'=','/','<','>'), $raw_html); */ $regexp = !$non_standard ? "|D\\(\\[(.*)\\]\\);|U" : "/\\[(.*)\\]/"; $matches = ""; preg_match_all($regexp, $raw_html, $matches, PREG_SET_ORDER); $packets = array(); $matches_count = count($matches); for ($i = 0; $i < $matches_count; $i++) { $off = 0; //Debugger::say(basename(__FILE__).": ".__LINE__.": "."parse_gmail_response(): match(pre parse_data_packet):\n".print_r($matches[$i][1],true)); $tmp = GMailer::parse_data_packet("[" . $matches[$i][1] . "]", $off); //Debugger::say(basename(__FILE__).": ".__LINE__.": "."parse_gmail_response(): parsed(post parse_data_packet):\n".print_r($tmp,true)); if (array_key_exists($tmp[0], $packets) || ($tmp[0] == "mi" || $tmp[0] == "mb" || $tmp[0] == "di")) { // Added cl as alternate contact datapack; by Neerav; 15 June 2005 if ($tmp[0] == "t" || $tmp[0] == "ts" || $tmp[0] == "a" || $tmp[0] == "cl") { $packets[$tmp[0]] = array_merge($packets[$tmp[0]], array_slice($tmp, 1)); } if ($tmp[0] == "mi" || $tmp[0] == "mb" || $tmp[0] == "di") { if (array_key_exists("mg", $packets)) { array_push($packets["mg"], $tmp); } else { $packets["mg"] = array($tmp); } } } else { $packets[$tmp[0]] = $tmp; } } $this->raw = $packets; //Debugger::say(basename(__FILE__).": ".__LINE__.": "."parse_gmail_response(): raw packets:\n".print_r($this->raw,true)); return 1; }