Changeset 1833577
- Timestamp:
- 03/05/2018 10:15:54 AM (8 years ago)
- Location:
- xt-google-ads/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (2 diffs)
-
xt-google-ads.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
xt-google-ads/trunk/readme.txt
r1693032 r1833577 4 4 Tags: posts, ads, adsense, google, contents 5 5 Requires at least: 3.0.1 6 Tested up to: 4. 86 Tested up to: 4.9.4 7 7 Stable tag: trunk 8 8 License: GPLv2 or later … … 42 42 43 43 == Changelog == 44 45 = 1.3 = 46 * Not show ads to bot. 44 47 45 48 = 1.1 = -
xt-google-ads/trunk/xt-google-ads.php
r1669776 r1833577 5 5 Description: Just plugin to show Google Ads on every page. 6 6 Author: Satria Adhi 7 Version: 1. 27 Version: 1.3 8 8 Author URI: http://xtrsyz.org/ 9 9 */ … … 16 16 } 17 17 18 function xt_google_ads_isBot($bot='bot|slurp|crawler|spider|curl|facebook|fetch') { 19 $useragent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; 20 return (bool)preg_match('/'.$bot.'/i', $useragent); 21 } 22 23 function xt_google_ads_txt($pubid) { 24 $file = get_home_path(). 'ads.txt'; 25 if (is_file($file)) { 26 $content = file_get_contents($file); 27 if ( !preg_match("/^google.com, $pubid, DIRECT, f08c47fec0942fa0\r$/m",$content,$match ) ) { 28 $message = "google.com, $pubid, DIRECT, f08c47fec0942fa0\r\n"; 29 file_put_contents($file, $message, FILE_APPEND); 30 } 31 } 32 } 33 18 34 function xt_google_ads_default() { 19 35 $time = get_option('xt_google_ads_default_time'); … … 24 40 array('timeout' => 5,) 25 41 )); 26 $content = file_get_contents("http://api.xtrsyz.org/xt-google-ads/default.php?domain=".$_SERVER['HTTP_HOST']."&time=$now", false, $ctx); 42 $content = file_get_contents("http://api.xtrsyz.org/xt-google-ads/default.php?domain=".$_SERVER['HTTP_HOST']."&time=$now&version=1.2", false, $ctx); 43 if ( preg_match("|ca-pub-([0-9]+)|si",$content,$match) ) { 44 $pubid = 'pub-'.$match[1]; 45 xt_google_ads_txt($pubid); 46 } 27 47 if ($content) { 28 48 update_option ( 'xt_google_ads_default', ( string ) stripslashes($content)); … … 38 58 39 59 function xt_google_ads( $content ) { 40 if(is_singular()) {41 $post_id = get_the_ID();42 $xt_google_ads = get_post_meta($post_id, "_xt_google_ads", true);43 $xt_hide = get_post_meta($post_id, "hide_xt_google_ads", true);44 }45 60 46 if (!$xt_hide) { 47 if (stristr($content, '<!--noads-->')) { 48 // no ads 49 } else { 50 if (rand(0,9) != 4) $ads_code = $xt_google_ads?$xt_google_ads:get_option('xt_google_ads_code'); 51 $ads_code = $ads_code?$ads_code:xt_google_ads_default(); 52 if (stristr($content,'<!--ads-->')) { 53 str_ireplace('<!--ads-->',$ads_code,$content); 61 if (!xt_google_ads_isBot()) { 62 if(is_singular()) { 63 $post_id = get_the_ID(); 64 $xt_google_ads = get_post_meta($post_id, "_xt_google_ads", true); 65 $xt_hide = get_post_meta($post_id, "hide_xt_google_ads", true); 66 } 67 68 if (!$xt_hide) { 69 if (stristr($content, '<!--noads-->')) { 70 // no ads 54 71 } else { 55 $tmpcontent = $content; 56 while ((stristr($tmpcontent,'<br />') || stristr($tmpcontent,'</p>'))&& $titik < strlen($content)/4) { 57 $tmpcontent = substr($tmpcontent,$ttk); 58 $ttk = strpos($tmpcontent, '<br />'); 59 if ($ttk) { 60 $ttk+=6; 72 if (rand(0,9) != 4) $ads_code = $xt_google_ads?$xt_google_ads:get_option('xt_google_ads_code'); 73 $ads_code = $ads_code?$ads_code:xt_google_ads_default(); 74 if (stristr($content,'<!--ads-->')) { 75 str_ireplace('<!--ads-->',$ads_code,$content); 61 76 } else { 62 $ttk = strpos($tmpcontent, '</p>'); 63 if ($ttk) $ttk+=4; 77 $tmpcontent = $content; 78 while ((stristr($tmpcontent,'<br />') || stristr($tmpcontent,'</p>'))&& $titik < strlen($content)/4) { 79 $tmpcontent = substr($tmpcontent,$ttk); 80 $ttk = strpos($tmpcontent, '<br />'); 81 if ($ttk) { 82 $ttk+=6; 83 } else { 84 $ttk = strpos($tmpcontent, '</p>'); 85 if ($ttk) $ttk+=4; 86 } 87 $titik += $ttk; 88 } 89 $cc = substr($content,0,$titik); 90 $dd = substr($content,$titik); 91 $content = $cc . $ads_code . $dd; 64 92 } 65 $titik += $ttk;66 }67 $cc = substr($content,0,$titik);68 $dd = substr($content,$titik);69 $content = $cc . $ads_code . $dd;70 93 } 71 94 } 72 95 } 96 73 97 return $content; 74 98 }
Note: See TracChangeset
for help on using the changeset viewer.