1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
<?php

class module_adsense {
    var 
$user 'adsense@user';
    var 
$pass 'adsensepass';
    
// today, yesterday, last7days, thismonth, lastmonth, sincelastpayment, 
    
var $time 'yesterday';
    var 
$text 'AdSense-%s:$%s';

    function 
get() {
        if( !empty( 
$this->user ) && !empty( $this->pass ) && !empty( $this->time ) ) {
            
$destination '/adsense/report/overview?timePeriod='.$this->time;
            
$postdata 'destination='.urlencode$destination ).
                    
'&username='.urlencode$this->user ).
                    
'&password='.urlencode$this->pass ).
                    
'&null=Login';
            
$s curl_init();
            
curl_setopt$sCURLOPT_URL'https://www.google.com/adsense/login.do' );
            
curl_setopt$sCURLOPT_SSL_VERIFYPEERFALSE );
            
curl_setopt$sCURLOPT_USERAGENT'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)' );
            
curl_setopt$sCURLOPT_TIMEOUT20 );
            
curl_setopt$sCURLOPT_FOLLOWLOCATION);
            
curl_setopt$sCURLOPT_RETURNTRANSFER);
            
curl_setopt$sCURLOPT_COOKIEJAR'/tmp/cookiefile' );
            
curl_setopt$sCURLOPT_COOKIEFILE'/tmp/cookiefile' );
            
curl_setopt$sCURLOPT_POSTFIELDS$postdata );
            
curl_setopt$sCURLOPT_POST);
            
$result curl_exec$s );
            
curl_close$s );
            
$result str_replace( array( "\n""\r""\t" ), ''$result );
            
preg_match'/> Total Earnings <\/td> <td colspan="4"> <\/td> <td style="font-weight:bold;" nowrap> \$([0-9\.]+?) <\/td>/i'$result$match );
            if( isset( 
$match[1] ) && is_numeric$match[1] ) ) {
                return 
sprintf$this->text$this->time$match[1] );
            }
            return 
false;
        }
    }
}

?>