Paramètres de l'agenda -> Adresse URL privée, et copiez l'adresse XML. Sinon, laissez vide pour que ce message soit dans l'agenda principal par défaut: $feedxmlprive = "";
/*
Class: MyCurl
Author: Skakunov Alex (i1t2b3@gmail.com)
Date: 26.11.06
Description: provides a simple tool to GET/POST data with help of CURL library
http://a4.users.phpclasses.org/browse/package/3547.html
*/
class MyCurl
{
public $getHeaders = true;//headers will be added to output
public $getContent = true; //contens will be added to output
public $followRedirects = true; //should the class go to another URL, if the current is "HTTP/1.1 302 Moved Temporarily"
private $fCookieFile;
private $fSocket;
function MyCurl()
{
$this->fCookieFile = tempnam("/tmp", "g_");
}
function init()
{
return $this->fSocket = curl_init();
}
function setopt($opt, $value)
{
return curl_setopt($this->fSocket, $opt, $value);
}
function load_defaults()
{
$this->setopt(CURLOPT_RETURNTRANSFER, 1);
$this->setopt(CURLOPT_FOLLOWLOCATION, $this->followRedirects);
$this->setopt(CURLOPT_REFERER, "http://google.com");
$this->setopt(CURLOPT_VERBOSE, false);
$this->setopt(CURLOPT_SSL_VERIFYPEER, false);
$this->setopt(CURLOPT_SSL_VERIFYHOST, false);
$this->setopt(CURLOPT_HEADER, $this->getHeaders);
$this->setopt(CURLOPT_NOBODY, !$this->getContent);
$this->setopt(CURLOPT_COOKIEJAR, $this->fCookieFile);
$this->setopt(CURLOPT_COOKIEFILE, $this->fCookieFile);
$this->setopt(CURLOPT_USERAGENT, "MyCurl");
$this->setopt(CURLOPT_POST, 1);
$this->setopt(CURLOPT_CUSTOMREQUEST,'POST');
$fp = fopen("curl.log", "a");
if($fp)
$this->setopt(CURLOPT_STDERR, $fp);
}
function destroy()
{
return curl_close($this->fSocket);
}
function head($url)
{
$this->init();
if($this->fSocket)
{
$this->getHeaders = true;
$this->getContent = false;
$this->load_defaults();
$this->setopt(CURLOPT_POST, 0);
$this->setopt(CURLOPT_CUSTOMREQUEST,'HEAD');
$this->setopt(CURLOPT_URL, $url);
$result = curl_exec($this->fSocket);
$this->destroy();
return $result;
}
return 0;
}
function get($url)
{
$this->init();
if($this->fSocket)
{
$this->load_defaults();
$this->setopt(CURLOPT_POST, 0);
$this->setopt(CURLOPT_CUSTOMREQUEST,'GET');
$this->setopt(CURLOPT_URL, $url);
$result = curl_exec($this->fSocket);
$this->destroy();
return $result;
}
return 0;
}
function post($url, $post_data, $arr_headers=array(), &$http_code)
{
$this->init();
if($this->fSocket)
{
$post_data = $this->compile_post_data($post_data);
$this->load_defaults();
if(!empty($post_data))
$this->setopt(CURLOPT_POSTFIELDS, $post_data);
if(!empty($arr_headers))
$this->setopt(CURLOPT_HTTPHEADER, $arr_headers);
$this->setopt(CURLOPT_URL, $url);
$result = curl_exec($this->fSocket);
$http_code = curl_getinfo($this->fSocket, CURLINFO_HTTP_CODE);
$this->destroy();
return $result;
}
return 0;
}
function compile_post_data($post_data)
{
$o="";
if(!empty($post_data))
foreach ($post_data as $k=>$v)
$o.= $k."=".urlencode($v)."&";
return substr($o,0,-1);
}
function get_parsed($result, $bef, $aft="")
{
$line=1;
$len = strlen($bef);
$pos_bef = strpos($result, $bef);
if($pos_bef===false)
return "";
$pos_bef+=$len;
if(empty($aft))
{ //try to search up to the end of line
$pos_aft = strpos($result, "\n", $pos_bef);
if($pos_aft===false)
$pos_aft = strpos($result, "\r\n", $pos_bef);
}
else
$pos_aft = strpos($result, $aft, $pos_bef);
if($pos_aft!==false)
$rez = substr($result, $pos_bef, $pos_aft-$pos_bef);
else
$rez = substr($result, $pos_bef);
return $rez;
}
}
/*
Class: GoogleCalendarWrapper
Author: Skakunov Alex (i1t2b3@gmail.com)
Date: 26.11.06
Description: provides a simple tool to work with Google Calendar (add events currenly)
You must define login and password.
Class adds events into your main calendar by default.
If you want to add events in other calendar, write its XML URL into "feed_url" property like this:
$gc = new GoogleCalendarWrapper("email@gmail.com", "password");
$gc->feed_url =
"http://www.google.com/calendar/feeds/pcafiuntiuro1rs%40group.calendar.google.com/private-586fa023b6a7151779f99b/basic";
Feel free to provide "basic" URL, it will be automatically converted to "full" one (prepare_feed_url() method)..
How to get the XML URL: http://code.google.com/apis/gdata/calendar.html#get_feed
*/
class GoogleCalendarWrapper extends MyCurl
{
public $email;
public $password;
public $feed_url = "http://www.google.com/calendar/feeds/default/private/full";
private $fAuth;
private $isLogged = false;
private $feed_url_prepared;
function GoogleCalendarWrapper($email, $password)
{
$this->email = $email;
$this->password = $password;
$this->feed_url_prepared = $this->feed_url;
parent::MyCurl();
}
//login with Google's technology of "ClientLogin"
//check here: http://code.google.com/apis/accounts/AuthForInstalledApps.html
function login()
{
$post_data = array();
$post_data['Email'] = $this->email;
$post_data['Passwd'] = $this->password;
$post_data['source'] = "exampleCo-exampleApp-1";
$post_data['service'] = "cl";
$post_data['accountType'] = "GOOGLE";
$this->getHeaders = true;
$this->getContent = true;
$response = $this->post("https://www.google.com/accounts/ClientLogin", $post_data, null, $http_code);
if(200==$http_code)
{
$this->fAuth = parent::get_parsed($response, "Auth=");
$this->isLogged = true;
return 1;
}
$this->isLogged = false;
return 0;
}
//to make the feed URL writable, it should be ended with "private/full"
//check this: http://code.google.com/apis/gdata/calendar.html#get_feed
function prepare_feed_url()
{
$url = parse_url($this->feed_url);
$path = explode("/", $url["path"]);
$size = sizeof($path);
if($size>4)
{
$path[$size-1] = "full";
$path[$size-2] = "private";
$path = implode("/", $path);
}
$this->feed_url_prepared = $url["scheme"]."://".$url["host"].$path;
}
//adds new event into calendar
//filled $settings array should be provided
function add_event($settings)
{
if(!$this->isLogged)
$this->login();
if($this->isLogged)
{
$_entry = "
";
return false;
}
}
/*
interface web et envoi du message
*/
$gc = new GoogleCalendarWrapper("$emailgoogle", "$passgoogle"); // mettre adresse e-mail et mot de passe Google Calendar Agenda
if ($feedxmlprive){ $gc->feed_url = "$feedxmlprive"; }
?>