',$value);
$value = str_replace('<','<',$value);
$value = str_replace('"','"',$value);
$value = str_replace('&','&',$value);
return $value;
}
}
function html_decode_full($string, $quotes = ENT_COMPAT, $charset = 'ISO-8859-1') {
return preg_replace_callback('/&([#a-zA-Z0-9]+);/', 'convert_entity', html_entity_decode($string, $quotes, $charset));
}
function convert_entity($matches, $destroy = false) {
$string = preg_replace('/#(\d+)/me', "chr(\\1)", $matches[1]); #decimal notation
if ($string <> $matches[1]) return $string;
$string = preg_replace('/#x([a-f0-9]+)/mei', "chr(0x\\1)", $matches[1]); #hex notation
if ($string <> $matches[1]) return $string;
if ($matches[1] == 'trade') return '™';
if ($matches[1] == 'bull') return '•';
if ($matches[1] == 'quot') return '"';
if ($matches[1] == 'gt') return '>';
if ($matches[1] == 'lt') return '<';
if ($matches[1] == 'amp') return '&';
if ($matches[1] == 'acirc') return 'â';
if ($matches[1] == 'agrave') return 'à';
if ($matches[1] == 'eacute') return 'é';
if ($matches[1] == 'egrave') return 'è';
if ($matches[1] == 'rsquo') return '’';
if ($matches[1] == 'rsaquo') return '›';
if ($matches[1] == 'nbsp') return ' ';
if ($matches[1] == 'hellip') return '…';
if ($matches[1] == 'euro') return '€';
if ($matches[1] == 'apos') return '\'';
if ($matches[1] == 'ndash') return '–';
echo 'Entity manquant : ' . $matches[1] . ' = ' . '&' . $matches[1] . ';';
return $destroy ? '' : $matches[0];
}
class AdSense {
var $curl = null;
var $cur_url = null;
function AdSense(){
$this->curl = curl_init();
$cookie = ".";
$this->my_curl_setopt(CURLOPT_HEADER, false);
$this->my_curl_setopt(CURLOPT_RETURNTRANSFER, true);
$this->my_curl_setopt(CURLOPT_SSL_VERIFYPEER, false);
$this->my_curl_setopt(CURLOPT_SSL_VERIFYHOST, false);
$this->my_curl_setopt(CURLOPT_FOLLOWLOCATION, true);
$this->my_curl_setopt(CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
$this->my_curl_setopt(CURLOPT_COOKIEFILE, $cookie);
$this->my_curl_setopt(CURLOPT_COOKIEJAR, $cookie);
register_shutdown_function(array(&$this, '__destructor'));
}
function connect($email, $password){
// phase 1
$this->cur_url = 'https://www.google.com/accounts/ServiceLoginBox';
$this->cur_url .= '?service=adsense<mpl=login&ifr=true&rm=hide&fpui=3';
$this->cur_url .= '&nui=15&alwf=true&passive=true';
$this->cur_url .= '&continue=https%3A%2F%2Fwww.google.com%2Fadsense%2Flogin-box-gaiaauth';
$this->cur_url .= '&followup=https%3A%2F%2Fwww.google.com%2Fadsense%2Flogin-box-gaiaauth&hl=fr';
$this->my_curl_setopt(CURLOPT_URL, $this->cur_url);
preg_match_all('',
$this->my_curl_exec(), $out);
$params = array();
foreach($out[1] as $key=>$name) { $params[] = $name . '=' . urlencode($out[2][$key]); }
$params[] = 'Email=' . urlencode($email);
$params[] = 'Passwd=' . urlencode($password);
$params[] = 'null=' . urlencode('Sign in');
// phase 2
$this->cur_url = "https://www.google.com/accounts/ServiceLoginBoxAuth?" . join('&', $params);
$this->my_curl_setopt(CURLOPT_URL, "https://www.google.com/accounts/ServiceLoginBoxAuth");
$this->my_curl_setopt(CURLOPT_POST, true);
$this->my_curl_setopt(CURLOPT_POSTFIELDS, join('&', $params));
$result = $this->my_curl_exec();
if (preg_match("/.*cur_url = $matches[1];
curl_setopt($this->curl, CURLOPT_POST, false);
curl_setopt($this->curl, CURLOPT_URL, $this->cur_url);
} else {
die("Impossible de récupérer l'url de redirection :
" . nl2br(htmlspecialchars($result)));
}
$result = $this->my_curl_exec();
if (preg_match( "//si", $result, $matches )) {
// phase 4
$this->cur_url = htmlspecialchars_decode($matches[1]);
$this->my_curl_setopt(CURLOPT_URL, $this->cur_url);
$result = $this->my_curl_exec();
} else {
die("Impossible de récupérer l'url de redirection :
" . nl2br(htmlspecialchars($result)));
}
// did we login ?
if (eregi("/adsense/gaialogout", $result)) {
return true;
} else {
return false;
}
}
function today(){
$this->my_curl_setopt(CURLOPT_URL, ADSENSE_TODAY);
return $this->parse($this->my_curl_exec());
}
function yesterday(){
$this->my_curl_setopt(CURLOPT_URL, ADSENSE_YESTERDAY);
return $this->parse($this->my_curl_exec());
}
function last7days(){
$this->my_curl_setopt(CURLOPT_URL, ADSENSE_LAST7DAYS);
return $this->parse($this->my_curl_exec());
}
function lastmonth(){
$this->my_curl_setopt(CURLOPT_URL, ADSENSE_LASTMONTH);
return $this->parse($this->my_curl_exec());
}
function thismonth(){
$this->my_curl_setopt(CURLOPT_URL, ADSENSE_THISMONTH);
return $this->parse($this->my_curl_exec());
}
function sincelastpayment(){
$this->my_curl_setopt(CURLOPT_URL, ADSENSE_SINCELASTPAYMENT);
return $this->parse($this->my_curl_exec());
}
function __destructor(){
$this->my_curl_close();
}
function parse($content){
if (!preg_match_all('/
(.*?)<\/td>/',
$content, $matches)) {
$matches1[1][0] = '';
$matches1[1][2] = '';
$matches1[1][3] = '';
$matches1[1][4] = '';
}
if (!preg_match('/\ | ([0-9,]+) \$US\<\/td\>\<\/tr\>\<\/tfoot\>\<\/table\>/',
$content, $matches2)) {
$matches2[1] = '';
}
if (!preg_match('/\([0-9,]+) \$US \<\/span\>\<\/h1\>/',
$content, $matches3)) {
$matches3[1] = '';
}
return array(
"impressions" => preg_replace('/[^0-9]/', '', $matches[1][0]),
"clicks" => preg_replace('/[^0-9]/', '', $matches[1][1]),
"ctr" => $matches[1][2],
"ecpm" => $matches[1][3],
"earnings" => $matches[1][4],
"total" => str_replace(',', '.', $matches2[1]),
"jour" => str_replace(',', '.', $matches3[1])
);
}
function my_curl_init() {
if (($this->curl = curl_init()) === false) {
$num_erreur = curl_errno($this->curl);
$text_erreur = curl_error($this->curl);
die("Erreur d'initialisation de la session cURL : $num_erreur : $text_erreur");
}
}
function my_curl_setopt($param, $value) {
if (!curl_setopt($this->curl, $param, $value)) {
$num_erreur = curl_errno($this->curl);
$text_erreur = curl_error($this->curl);
die("Erreur d'ajout de l'option cURL $param pour " . $this->cur_url .
" : $num_erreur : $text_erreur");
}
}
function my_curl_exec() {
if (($result = curl_exec($this->curl)) === false) {
$num_erreur = curl_errno($this->curl);
$text_erreur = curl_error($this->curl);
die("Erreur d'exécution cURL pour " . $this->cur_url .
" : $num_erreur : $text_erreur");
}
$http_code = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
if (($http_code <> 200) && ($http_code <> 301) && ($http_code <> 302)) {
$url_reelle = convert_url(curl_getinfo($this->curl, CURLINFO_EFFECTIVE_URL));
$description = get_http_code_description($http_code);
die("Code retour $http_code pour $url_reelle : $description");
}
return $result;
}
function my_curl_close() {
curl_close($this->curl);
}
}
?>
Revenus adsense
connect($email, $password)) {
$day = date('j');
if ($day == 1) { //nous sommes le 1er du mois
$yesterday = $adsense->yesterday();
$today = $adsense->today();
$lastmonth = $adsense->lastmonth();
echo '';
echo ' | Impressions | ';
echo 'Clics | ';
echo 'CTR | ';
echo 'eCPM | ';
echo 'Montant total | ';
echo 'Hier | ';
echo '' . $yesterday['impressions'] . ' | ';
echo '' . $yesterday['clicks'] . ' | ';
echo '' . $yesterday['ctr'] . ' | ';
echo '' . $yesterday['ecpm'] . ' | ';
echo '' . $yesterday['total'] . ' $US | ';
echo 'Aujourd\'hui | ';
echo '' . $today['impressions'] . ' | ';
echo '' . $today['clicks'] . ' | ';
echo '' . $today['ctr'] . ' | ';
echo '' . $today['ecpm'] . ' | ';
echo '' . $today['total'] . ' $US | ';
echo 'Mois dernier | ';
echo '' . $lastmonth['impressions'] . ' | ';
echo '' . $lastmonth['clicks'] . ' | ';
echo '' . $lastmonth['ctr'] . ' | ';
echo '' . $lastmonth['ecpm'] . ' | ';
echo '' . $lastmonth['total'] . ' $US | ';
echo ' ';
} else {
$yesterday = $adsense->yesterday();
$today = $adsense->today();
$lastmonth = $adsense->lastmonth();
$thismonth = $adsense->thismonth();
$jours_hier = $day - 1; //nombre de jours du mois jusqu'a hier
$jours_mois = date('t'); //nombre de jours du mois
$moyenne_imp = round(($thismonth['impressions'] - $today['impressions']) / $jours_hier, 0);
$moyenne_clic = round(($thismonth['clicks'] - $today['clicks']) / $jours_hier, 0);
$moyenne_ctr = round(($thismonth['clicks'] - $today['clicks']) /
($thismonth['impressions'] - $today['impressions']) * 100, 2);
$moyenne_ecpm = round(($thismonth['total'] - $today['total']) /
($thismonth['impressions'] - $today['impressions']) * 1000, 2);
$moyenne_mnt = round(($thismonth['total'] - $today['total']) / $jours_hier, 2);
$prev_imp = round(($thismonth['impressions'] - $today['impressions']) / $jours_hier * $jours_mois, 0);
$prev_clic = round(($thismonth['clicks'] - $today['clicks']) / $jours_hier * $jours_mois, 0);
$prev_ctr = $moyenne_ctr;
$prev_ecpm = $moyenne_ecpm;
$prev_mnt = round(($thismonth['total'] - $today['total']) / $jours_hier * $jours_mois, 2);
echo '';
echo ' | Impressions | ';
echo 'Clics | ';
echo 'CTR | ';
echo 'eCPM | ';
echo 'Montant total | ';
echo 'Moyenne / jour | ';
echo '' . $moyenne_imp . ' | ';
echo '' . $moyenne_clic . ' | ';
echo '' . $moyenne_ctr . '% | ';
echo '' . $moyenne_ecpm . ' $US | ';
echo '' . $moyenne_mnt . ' $US | ';
echo 'Hier | ';
echo '' . $yesterday['impressions'] . ' | ';
echo '' . $yesterday['clicks'] . ' | ';
echo '' . $yesterday['ctr'] . ' | ';
echo '' . $yesterday['ecpm'] . ' | ';
echo '' . $yesterday['total'] . ' $US | ';
echo 'Aujourd\'hui | ';
echo '' . $today['impressions'] . ' | ';
echo '' . $today['clicks'] . ' | ';
echo '' . $today['ctr'] . ' | ';
echo '' . $today['ecpm'] . ' | ';
echo '' . $today['total'] . ' $US | ';
echo 'Mois dernier | ';
echo '' . $lastmonth['impressions'] . ' | ';
echo '' . $lastmonth['clicks'] . ' | ';
echo '' . $lastmonth['ctr'] . ' | ';
echo '' . $lastmonth['ecpm'] . ' | ';
echo '' . $lastmonth['total'] . ' $US | ';
echo 'Mois courant | ';
echo '' . $thismonth['impressions'] . ' | ';
echo '' . $thismonth['clicks'] . ' | ';
echo '' . $thismonth['ctr'] . ' | ';
echo '' . $thismonth['ecpm'] . ' | ';
echo '' . $thismonth['total'] . ' $US | ';
echo 'Prévisionnel | ';
echo '' . $prev_imp . ' | ';
echo '' . $prev_clic . ' | ';
echo '' . $prev_ctr . '% | ';
echo '' . $prev_ecpm . ' $US | ';
echo '' . $prev_mnt . ' $US | ';
echo ' ';
}
} else {
die('Could not login to AdSense account.');
}
?>
|