web/wp-content/plugins/wptouch/include/adsense.php
branchwordpress
changeset 123 561aa6d282f6
equal deleted inserted replaced
112:fb7cd02b9848 123:561aa6d282f6
       
     1 <?php
       
     2 
       
     3 /*
       
     4 	Code taken from Google's website
       
     5 	Modified to use Snoopy class for HTTP request
       
     6 */
       
     7 
       
     8 if (!function_exists('google_append_url')) {
       
     9 
       
    10 	function read_global($var) {
       
    11 	  return isset($_SERVER[$var]) ? $_SERVER[$var]: '';
       
    12 	}
       
    13 	
       
    14 	function google_set_screen_res() {
       
    15 	  $screen_res = read_global('HTTP_UA_PIXELS');
       
    16 	  if ($screen_res == '') {
       
    17 	    $screen_res = read_global('HTTP_X_UP_DEVCAP_SCREENPIXELS');
       
    18 	  }
       
    19 	  if ($screen_res == '') {
       
    20 	    $screen_res = read_global('HTTP_X_JPHONE_DISPLAY');
       
    21 	  }
       
    22 	  $res_array = split('[x,*]', $screen_res);
       
    23 	  if (sizeof($res_array) == 2) {
       
    24 	    $GLOBALS['google']['u_w'] = $res_array[0];
       
    25 	    $GLOBALS['google']['u_h'] = $res_array[1];
       
    26 	  }
       
    27 	}
       
    28 
       
    29 	function google_set_muid() {
       
    30 	  $muid = read_global('HTTP_X_DCMGUID');
       
    31 	  if ($muid != '') {
       
    32 	    $GLOBALS['google']['muid'] = $muid;
       
    33 	  }
       
    34 	  $muid = read_global('HTTP_X_UP_SUBNO');
       
    35 	  if ($muid != '') {
       
    36 	    $GLOBALS['google']['muid'] = $muid;
       
    37 	  }
       
    38 	  $muid = read_global('HTTP_X_EM_UID');
       
    39 	  if ($muid != '') {
       
    40 	    $GLOBALS['google']['muid'] = $muid;
       
    41 	  }
       
    42 	}	
       
    43 
       
    44 
       
    45 	require_once( WP_CONTENT_DIR . '/../wp-includes/class-snoopy.php');
       
    46 
       
    47 	$GLOBALS['google']['ad_type']='text';
       
    48 	$GLOBALS['google']['channel']='';
       
    49 	$GLOBALS['google']['format']='mobile_single';
       
    50 	$GLOBALS['google']['https']=read_global('HTTPS');
       
    51 	$GLOBALS['google']['ip']=read_global('REMOTE_ADDR');
       
    52 	$GLOBALS['google']['markup']='xhtml';
       
    53 	$GLOBALS['google']['oe']='utf8';
       
    54 	$GLOBALS['google']['output']='xhtml';
       
    55 	$GLOBALS['google']['ref']=read_global('HTTP_REFERER');
       
    56 	$GLOBALS['google']['url']=read_global('HTTP_HOST') . read_global('REQUEST_URI');
       
    57 	$GLOBALS['google']['useragent']=read_global('HTTP_USER_AGENT');
       
    58 	$google_dt = time();
       
    59 
       
    60 // $GLOBALS['google']['color_border']='FFFFFF';
       
    61 //	$GLOBALS['google']['color_bg']='FFFFFF';
       
    62 //	$GLOBALS['google']['color_link']='0000CC';
       
    63 //	$GLOBALS['google']['color_text']='333333';
       
    64 //	$GLOBALS['google']['color_url']='008000';
       
    65 	
       
    66 	function google_append_url(&$url, $param, $value) {
       
    67 	  $url .= '&' . $param . '=' . urlencode($value);
       
    68 	}
       
    69 	
       
    70 	function google_append_globals(&$url, $param) {
       
    71 	  google_append_url($url, $param, $GLOBALS['google'][$param]);
       
    72 	}
       
    73 	
       
    74 	function google_append_color(&$url, $param) {
       
    75 	  global $google_dt;
       
    76 	  $color_array = split(',', $GLOBALS['google'][$param]);
       
    77 	  google_append_url($url, $param,
       
    78 	                    $color_array[$google_dt % sizeof($color_array)]);
       
    79 	}
       
    80 	
       
    81 
       
    82 	
       
    83 	
       
    84 	function google_get_ad_url() {
       
    85 	  $google_ad_url = 'http://pagead2.googlesyndication.com/pagead/ads?';
       
    86 	  $google_scheme = ($GLOBALS['google']['https'] == 'on')
       
    87 	      ? 'https://' : 'http://';
       
    88 		foreach ($GLOBALS['google'] as $param => $value) {
       
    89 		  if ($param == 'client') {
       
    90 		    google_append_url($google_ad_url, $param,
       
    91 		                      'ca-mb-' . $GLOBALS['google'][$param]);
       
    92 		  } else if (strpos($param, 'color_') === 0) {
       
    93 		    google_append_color($google_ad_url, $param);
       
    94 		  } else if (strpos($param, 'url') === 0) {
       
    95 		    $google_scheme = ($GLOBALS['google']['https'] == 'on')
       
    96 		        ? 'https://' : 'http://';
       
    97 		    google_append_url($google_ad_url, $param,
       
    98 		                      $google_scheme . $GLOBALS['google'][$param]);
       
    99 		  } else {
       
   100 		    google_append_globals($google_ad_url, $param);
       
   101 		  }
       
   102 		}
       
   103 		
       
   104 	  google_append_url($google_ad_url, 'dt',
       
   105 	   		    round(1000 * array_sum(explode(' ', microtime()))));
       
   106 	   		    
       
   107 	  return $google_ad_url;
       
   108 	}
       
   109 	
       
   110 	function google_show_ad( $id, $channel = '' ) {
       
   111 		global $bnc_wptouch_version;
       
   112 		
       
   113 		$ad = '';
       
   114 		$GLOBALS['google']['client']= $id;
       
   115 		$GLOBALS['google']['channel']= $channel;
       
   116 		
       
   117 		$google_dt = time();
       
   118 		google_set_screen_res();
       
   119 		google_set_muid();
       
   120 		
       
   121    	$snoopy = new Snoopy;
       
   122    	$snoopy->agent = 'WPtouch ' . $bnc_wptouch_version;
       
   123 
       
   124 		$ad = '';
       
   125       $result = $snoopy->fetch( google_get_ad_url() );
       
   126       if ( $result ) {
       
   127          $ad = $snoopy->results;
       
   128       }
       
   129 		
       
   130 		return $ad;
       
   131 	}
       
   132 }
       
   133 ?>