setTimeZone(new DateTimeZone("Europe/Paris"));
$dt ->modify('+ 5 minutes + 30 seconds');
$now = $dt->format(DateTime::RFC3339);
$dt ->modify('+ 15 seconds');
$now5sec = $dt->format(DateTime::RFC3339);
/*CONFIGURATION PART :*/
//DONNEES D'AUTHENTIFICATION
$post_data = array();
$post_data['Email'] = "mon mail@gmail.com";
$post_data['Passwd'] = "mon pass";
$post_data['source'] = "exampleCo-exampleApp-1";
$post_data['service'] = "cl";
$post_data['accountType'] = "GOOGLE";
//DONNEES PROPRE AU CONTENU ET A L'HEURE DE RECEPTION DU SMS
$s = array();
$s["title"] = "Simple test";
$s["content"] = "";
$s["where"] = "Lieu de test";
$s["startTime"] = $now; $s["endTime"] = $now5sec;
/*
CLASS HTTP VIA SOCKET AVEC SUPPORT SSL
PAR GRIGIS GAETAN
cipher16@gmail.com
http://www.gaetan-grigis.eu
http://blog.gaetan-grigis.eu
*/
class SockHttp
{
//CONNECTION INFORMATION
private $connection;
private $port;
private $host;
private $timeout;
private $scheme;
//ERRORS
private $errors;
//MISC
private $cookie;
private $referer;
private $userAgent;
//FUNCTIONS
function SockHttp($ho,$po=80,$sc="tcp://", $to = 30)
{
$this->port = $po;
$this->host = $ho;
$this->timeout = $to;
$this->scheme = $sc;
$this->errors = array();
$this->cookie = array();
$this->referer = array();
$this->cookie = array();
}
function connect()
{
$this->connection = fsockopen($this->scheme.$this->host,$this->port,$err1,$err2,$this->timeout);
$this->errors[]=$err1;
$this->errors[]=$err2;
}
function close()
{
//we don't clean error ...
fclose($this->connection);
$this->connection="";
}
function get($path,$headers=array())
{
if(!$this->connection)
$this->connect();
$request = "GET ".trim($path)." HTTP/1.1\r\n";
$request .= "Host: ".$this->host."\r\n";
foreach($headers as $header)
$request .= $header."\r\n";
$request .= "Connection: Close\r\n\r\n";
fwrite($this->connection,$request);
$ret = array();
$ind = false;
$redirection = "";
while(!feof($this->connection))
{
$tmp = fgets($this->connection);
if( preg_match("#^[-A-Za-z]+:.*$#i",$tmp) || !$ind )
{
if( preg_match("#^Location: (.*)$#i",$tmp,$url) )
$redirection = $url[1];
$ret["HEAD"][] = $tmp;
}
else
$ret["BODY"][] = $tmp;
$ind = true;
}
//better to close connection here
$this->close();
if($redirection)//recursivity powaaaa!
return $this->get($redirection);
else
return $ret;
}
function post($path,$var,$content_body="",$headers=array(),$ct="application/x-www-form-urlencoded")
{
if(!$this->connection)
$this->connect();
//cleanup path to avoid bad request (between https and http in case of an opened connection known as ssl)
//first check if it's on the same domain
if(preg_match("#^https?://".$this->host."/.*$#i",$path))
$path=preg_replace("#^https?://".$this->host."#i","",$path);
$content="";
foreach($var as $key=>$contenu)
$content .= $key."=".urlencode($contenu)."&";
$request = "POST ".trim($path)." HTTP/1.1\r\n";
$request .= "Host: ".$this->host."\r\n";
$request .= "Content-type: ".$ct."\r\n";
foreach($headers as $header)
$request .= $header."\r\n";
$request .= "Content-Length: ".(strlen($content)+strlen($content_body))."\r\n";
$request .= "Connection: Close\r\n\n";
//need an empty line to begin post
//in case both are empty no \r\n that will return 400
if($content)
$request .= substr($content,0,-1)."\r\n";
if($content_body)
$request .= $content_body."\r\n";
//echo "
".$request."
";
fwrite($this->connection,$request."\r\n");
$ret = array();
$ind = false;
$redirection = "";
while(!feof($this->connection))
{
$tmp = fgets($this->connection);
if( preg_match("#^[-A-Za-z]+:.*$#i",$tmp) || !$ind )
{
if( preg_match("#^Location: (.*)$#i",$tmp,$url) )
$redirection = $url[1];
$ret["HEAD"][] = $tmp;
}
else
$ret["BODY"][] = $tmp;
$ind = true;
}
//better to close connection here if we want to reopen another one in case of redirection
$this->close();
if($redirection)//recursivity powaaaa!
{
//echo "
REDIRECTION : ".$redirection."
";
return $this->post($redirection,$var,$content_body,$headers,$ct);
}
else
return $ret;
}
}
$cle_auth = "";
$SID = "";
$LSID = "";
$sock = new SockHttp("www.google.com",443,"ssl://");
//RECUPERATION DE LA CLE
$contenu = $sock->post("/accounts/ClientLogin",$post_data);
foreach($contenu['BODY'] as $content)
{
if(preg_match("#^Auth=(.*)$#i",$content,$auth_key))
$cle_auth = $auth_key[1];
if(preg_match("#^SID=(.*)$#i",$content,$auth_key))
$SID = $auth_key[1];
if(preg_match("#^LSID=(.*)$#i",$content,$auth_key))
$LSID = $auth_key[1];
}
$cle_auth or die("Probleme lors de l'authentification, le login et le mot de passe ne semble pas etre bon");
//CREATION DE L'EVENT
$_entry = "
".$s["title"]."
".$s["content"]."
".$post_data['Email']."
".$post_data['Email']."
";
$header[] = "MIME-Version: 1.0";
$header[] = "Accept: text/xml";
$header[] = "Authorization: GoogleLogin auth=".$cle_auth;
$header[] = "Cache-Control: no-cache";
$header[] = "Cookie: SID=".$SID;//."; LSID=".$LSID;
//EXECUTION DE L'EVENT
$retour = $sock->post("/calendar/feeds/default/private/full",array(),$_entry,$header,"application/atom+xml");
/*POUR DEBUG
foreach($retour['HEAD'] as $content)
echo $content."
";
echo "
------
";
foreach($retour['BODY'] as $content)
echo $content."
";*/
echo "Envoi ok (normalement ... si vous avez renseigne le champs du telephone portable dans google calendar)";
?>