Paradise ReTRyMaS
Vous souhaitez réagir à ce message ? Créez un compte en quelques clics ou connectez-vous pour continuer.
Paradise ReTRyMaS

By ReTRyMaS - FreeWeb

Le Deal du moment :
Bon plan achat en duo : 2ème robot cuiseur ...
Voir le deal
600 €

Vous n'êtes pas connecté. Connectez-vous ou enregistrez-vous

-SMS avec google agenda- [code a tester]

Aller en bas  Message [Page 1 sur 1]

Admin


Admin

<?php
/*
** Envoi un SMS gratuitement via Google Agenda (Calendar). Créez un Agenda Google, et choisissez la notification par SMS à 5 min.
** Envoie un sms en ajoutant l'évenement 5minutes et 30 secondes plus tard.
** Le texto est envoyé dans les 5 secondes qui suivent l'envoi
** http://macsim.labolinux.net/index.php/post/2008/02/15/137-smsalert-envoyer-des-sms-gratuitement-depuis-ses-serveurs
*/

$emailgoogle = "xxxxx@gmail.com"; // e-mail du compte google agenda calendar
$passgoogle = "xxxxx"; // mot de passe

$feedxmlprive = ""; // Enregistrez vos SMS dans un agenda google différent de celui par défaut. Utile pour ne pas mélanger les SMS avec les autres événements. Voir dans Google Agenda -> 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 = "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'>
<category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/2005#event'></category>
<title type='text'>".$settings["title"]."</title>
<content type='text'>".$settings["content"]."</content>
<author>
<name>".$this->email."</name>
<email>".$this->email."</email>
</author>
<gd:transparency
value='http://schemas.google.com/g/2005#event.opaque'>
</gd:transparency>
<gd:eventStatus
value='http://schemas.google.com/g/2005#event.confirmed'>
</gd:eventStatus>
<gd:where valueString='".$settings["where"]."'></gd:where>
<gd:when startTime='".$settings["startDay"]."T".$settings["startTime"].".000Z'
endTime='".$settings["endDay"]."T".$settings["endTime"].".000Z'>
<gd:reminder minutes='5' /></gd:when>
</entry>";
$this->prepare_feed_url();

$header = array();
$header[] = "Host: www.google.com";
$header[] = "MIME-Version: 1.0";
$header[] = "Accept: text/xml";
$header[] = "Authorization: GoogleLogin auth=".$this->fAuth;
$header[] = "Content-length: ".strlen($_entry);
$header[] = "Content-type: application/atom+xml";
$header[] = "Cache-Control: no-cache";
$header[] = "Connection: close \r\n";
$header[] = $_entry;

$this->post($this->feed_url_prepared, null, $header, $http_code);
if(201==$http_code)
return true;

}
else
echo "cannot login with '".$this->email."' email and '<font color=\"lightgray\">".$this->password."</font>' password<br/>";
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"; }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Envoi d'un SMS</title>
</head>
<body>
<script type="text/javascript"> <!-- compteur de caracteres -->
function cmptrNmbrCrctrs () {
var caras = 113 - document.getElementById('cmptr-crctrs-nm').value.length - document.getElementById('cmptr-crctrs-mssg').value.length ;
if(caras < 0) {
if(document.getElementById('cmptr-crctrs-nm').value.length > 113) {
document.getElementById('cmptr-crctrs-nm').value = document.getElementById('cmptr-crctrs-nm').value.substr(0, 113) ;
} else {
var smsMsgLen = 113 - document.getElementById('cmptr-crctrs-nm').value.length ;
document.getElementById('cmptr-crctrs-mssg').value = document.getElementById('cmptr-crctrs-mssg').value.substr(0, smsMsgLen) ;
}
}
if(caras < 0) caras = 0 ;
document.getElementById('mdfnmbrcrctrs').innerHTML = caras ;
}
</script>
<form enctype="multipart/form-data" action="sms.php" method="post">
Votre nom :<br />
<input name="gijhuyw" id="cmptr-crctrs-nm" style="width: 180px;" onchange="cmptrNmbrCrctrs() ;" onkeydown="cmptrNmbrCrctrs() ;" onkeyup="cmptrNmbrCrctrs() ;" type="text"><br />
Votre message :<br />
<textarea name="trkxxw" id="cmptr-crctrs-mssg" style="width: 180px; height: 70px;" onchange="cmptrNmbrCrctrs() ;" onkeydown="cmptrNmbrCrctrs() ;" onkeyup="cmptrNmbrCrctrs() ;"></textarea><br />
Il vous reste <span id="mdfnmbrcrctrs">113</span> caractères<br />
<input type="submit" value=" Envoyer SMS ">
</form>
<br />
<?php

/* on filtre tout */
foreach ($_REQUEST as $key => $val) {
$val = trim(stripslashes(htmlentities($val)));
$_REQUEST[$key] = $val;
}
$titre = 0;
$titre = preg_replace("/[^a-zA-Z0-9éÉèÈçÇàÀùÙâÂêÊîÎôÔûÛäÄëËïÏöÖüÜÿŸœŒæÆ@€\,\.\!\? \'\’\(\)\/\-\:\+]/i",'', $_POST["gijhuyw"]);
$titre = preg_replace("/[\']/i",'’', $titre);
$message = 0;
$message = preg_replace("/[^a-zA-Z0-9éÉèÈçÇàÀùÙâÂêÊîÎôÔûÛäÄëËïÏöÖüÜÿŸœŒæÆ@€\,\.\!\? \'\’\(\)\/\-\:\+]/i",'', $_POST["trkxxw"]);
$message = preg_replace("/[\']/i",'’', $message);

/* Dans la partie Description de l'événement inscrit dans l'agenda, on enregistre les date et heure ainsi que l'adresse IP. Ces données ne sont pas visibles dans le SMS. */
/* fonction recuperation IP */
function get_ip() {
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; }
elseif(isset($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; }
else { $ip = $_SERVER['REMOTE_ADDR']; }
return $ip;
}
/* enregistrement ip et de son host */
$ip = get_ip();
$nomhote = gethostbyaddr($ip);
/* date et heure réelles */
@setlocale(LC_TIME, 'fr_FR.utf-8');
$jour = strftime("%A %d %B %Y");
$heure = date("H:i");

$contenu = 0;
$contenu = "Demande faite le $jour, $heure. \n";
$contenu .= "Adresse internet: $nomhote - $ip \n";


/* on fixe la date et l'heure à include dans l'agenda Google */
$localtime_assoc = localtime(time(), true);
if ($localtime_assoc[tm_isdst] = 1) { // si heure d'été; Je retire une heure. Si on a 10h, google mets 11h
// On capture le temps actuel
$heure = time() - 6870; // -2 heures + 5 minutes + 30 secondes
$now = date('H:i:s', $heure);
// On lui ajoute 15 sec
$heure15sec = time() - 6435; // -2 heures + 15 minutes + 15 secondes
$now15sec = date('H:i:s', $heure15sec); }
else { // On capture le temps actuel
$heure = time() - 3270; // -1 heures + 5 minutes + 30 secondes
$now = date('H:i:s', $heure);
// On lui ajoute 15 sec
$heure15sec = time() - 2835; // -1 heures + 15 minutes + 15 secondes
$now15sec = date('H:i:s', $heure15sec); }

$s = array();
$s["title"] = $titre;
$s["content"] = $contenu;
$s["where"] = $message;
$s["startDay"] = date('Y-m-d', $heure);
$s["startTime"] = $now;
$s["endDay"] = date('Y-m-d', $heure15sec);
$s["endTime"] = $now15sec;

if ($message){
if($gc->add_event($s)) {
echo "<strong>Envoi SMS [ OK ]</strong><br /> <strong>Heure:</strong> ".$now." (".$s['startDay'].")<br /> <strong>Nom:</strong> ".$titre." <br /> <strong>Message:</strong> ".$message."<br />".$contenu."\n"; }
else{
echo "<strong>Erreur Envoi Message</strong> ".$s['startTime']." ".$s['startDay']." \n"; }
}
?>
</body>
</html>

<?php
?>

https://paradise-retrymas.kanak.fr

Revenir en haut  Message [Page 1 sur 1]

Permission de ce forum:
Vous ne pouvez pas répondre aux sujets dans ce forum