_GARD

The Google Adsense for Responsive Design - GARD GARD function.

Description

_GARD( (string) $atts = '' ); 

Parameters (1)

0. $atts — Optional. (string) => ''
The atts.

Usage

  1. if ( !function_exists( '_GARD' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-adsense-for-responsive-design-gard/index.php'; 
  3.  
  4. // The atts. 
  5. $atts = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = _GARD($atts); 
  9.  

Defined (1)

The function is defined in the following location(s).

/index.php  
  1. function _GARD( $atts = '' ) { 
  2. extract( shortcode_atts( array( 
  3. 'align' => '',  
  4. 'async' => 'false' 
  5. ), $atts ) ); 
  6.  
  7.  
  8. if($align == 'center') { 
  9. $align = 'margin: 0 auto;float: none;display: block;text-align:center;'; 
  10. $float = 'none'; 
  11. $margin = '0 auto'; 
  12. $display = 'block'; 
  13. $text = 'center'; 
  14. } elseif($align == 'left') { 
  15. $align = 'margin: 0 10px 10px 0;float: left;display: block;'; 
  16. $float = 'left'; 
  17. $margin = '0 10px 10px 0'; 
  18. $text = 'initial'; 
  19. $display = 'block'; 
  20. } elseif($align == 'right') { 
  21. $align = 'margin: 0 0 10px 10px;float: right;display: block;'; 
  22. $float = 'right'; 
  23. $margin = '0 0 10px 10px'; 
  24. $text = 'initial'; 
  25. $display = 'block'; 
  26. } elseif ($align == '') { 
  27. $float = ''; 
  28. $margin = ''; 
  29. $display = ''; 
  30. $text = '';  
  31.  
  32. $id = "ca-pub-".get_option("GARD_ID"); 
  33. $num = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 4); 
  34.  
  35. $mode = get_option('GARD_ADVANCED_MODE', '1') ; 
  36.  
  37. $async_mode = get_option("GARD_ASYNC"); 
  38.  
  39. if( $mode == 1 && $async_mode !== '1' ) { 
  40.  
  41. # ADVANCED MODE 
  42.  
  43. $link_units = array( 
  44. '728x15' => '728x15',  
  45. '468x15' => '468x15',  
  46. '200x90' => '200x90',  
  47. '180x90' => '180x90',  
  48. '160x90' => '160x90',  
  49. '120x90' => '120x90',  
  50. ); 
  51.  
  52.  
  53. $adsense = '  
  54. <div class="GARD gard_advanced_mode" id="google-ads-'.$num.'"><script> 
  55. adUnit = document.getElementById("google-ads-'.$num.'"); 
  56. google_ad_client = "'.$id.'"; 
  57. adUnit = document.getElementById("google-ads-'.$num.'"); 
  58. adWidth = adUnit.offsetWidth;  
  59. if ( adWidth >= 999999 ) { 
  60. /* GETTING THE FIRST IF OUT OF THE WAY */  
  61. }'; 
  62.  
  63. global $adsizes; 
  64.  
  65. $link_units = array( 
  66. '728x15' => '728x15',  
  67. '468x15' => '468x15',  
  68. '200x90' => '200x90',  
  69. '180x90' => '180x90',  
  70. '160x90' => '160x90',  
  71. '120x90' => '120x90',  
  72. ); 
  73.  
  74. foreach($adsizes as $size => $description) { 
  75. $type = 'ad_unit'; 
  76. if ( in_array($size, $link_units) ) { 
  77. $type = 'link_unit'; 
  78. } elseif ($size == '300x600') { 
  79. $type = 'large_skyscraper'; 
  80.  
  81. $tag = $type."_".$size; 
  82. $code = get_option("GARD_".$size); 
  83. $original_size = $size; 
  84. $size = explode('x', $size); 
  85. $size1 = $size[0]; 
  86. $size2 = $size[1]; 
  87.  
  88. $mobile = get_option('GARD_MOBILE_ADVANCED_'.$original_size); 
  89.  
  90. if( $mobile == 1 && gard_ismobile() === FALSE ) { 
  91. // If ad is set to show to mobile only, and this is not a mobile device, skip the output of this ad 
  92. continue; 
  93. } elseif( $mobile == 2 && gard_ismobile() === TRUE ) { 
  94. // If ad is set to show to non-mobile only, and this is a mobile device, skip the output of this ad 
  95. continue; 
  96.  
  97. if ( strlen($code) == '10' && is_numeric($code)) {  
  98. $adsense .= ' else if ( adWidth >= '.$size1.' ) { 
  99. if (document.querySelectorAll(".'.$type.'").length > 3 ) {  
  100. google_ad_slot = "0"; 
  101. adUnit.style.display = "none"; 
  102. } else { 
  103. google_ad_slot = "'.$code.'"; 
  104. google_ad_width = '.$size1.'; 
  105. google_ad_height = '.$size2.'; 
  106. adUnit.style.cssFloat = "'.$float.'"; 
  107. adUnit.style.styleFloat = "'.$float.'"; 
  108. adUnit.style.margin = "'.$margin.'"; 
  109. adUnit.style.textAlign = "'.$text.'"; 
  110. adcount = document.querySelectorAll(".'.$type.'").length; 
  111. tag = "'.$tag.'_"+adcount; 
  112. adUnit.className = adUnit.className + " '.$type.' " + tag; 
  113. }'; 
  114.  
  115. $adsense .= ' else { 
  116. google_ad_slot = "0"; 
  117. adUnit.style.display = "none"; 
  118. }</script> 
  119. <script src="//pagead2.googlesyndication.com/pagead/show_ads.js"></script></div>'; 
  120.  
  121. } else if ( $mode == 1 && $async_mode == 1 ) { 
  122.  
  123. # ASYNC MODE 
  124.  
  125. $adsense = '<div class="GARD gard_async_mode" id="google-ads-'.$num.'" ><script async="async" src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><div id="GARDasync_'.$num.'"></div><script >(adsbygoogle = window.adsbygoogle || []).push({});</script></div>'; 
  126.  
  127. # determine size and insert correct ad. 
  128. $adsense .= '<script> 
  129. adUnit = document.getElementById("google-ads-'.$num.'"); 
  130. adWidth = adUnit.offsetWidth;  
  131. if ( adWidth >= 999999 ) { 
  132. /* GETTING THE FIRST IF OUT OF THE WAY */  
  133. }'; 
  134.  
  135. global $adsizes; 
  136. foreach($adsizes as $size => $description) { 
  137. $code = get_option("GARD_".$size); 
  138. $original_size = $size; 
  139. $size = explode('x', $size); 
  140. $size1 = $size[0]; 
  141. $size2 = $size[1]; 
  142.  
  143. $mobile = get_option('GARD_MOBILE_ADVANCED_'.$original_size); 
  144.  
  145. if( $mobile == 1 && gard_ismobile() === FALSE ) { 
  146. // If ad is set to show to mobile only, and this is not a mobile device, skip the output of this ad 
  147. continue; 
  148. } elseif( $mobile == 2 && gard_ismobile() === TRUE ) { 
  149. // If ad is set to show to non-mobile only, and this is a mobile device, skip the output of this ad 
  150. continue; 
  151.  
  152. if ( strlen($code) == '10' && is_numeric($code)) {  
  153. $adsense .= ' else if ( adWidth >= '.$size1.' ) { 
  154. document.getElementById("GARDasync_'.$num. 
  155. '").innerHTML = "<ins class=\"adsbygoogle\" style=\"'.$align.'width:'.$size1.'px;height:'.$size2. 
  156. 'px;display:block;\" data-ad-client=\"'.$id.'\" data-ad-slot=\"'.$code.'\"></ins>"; 
  157. }'; 
  158. $adsense .= '</script>'; 
  159.  
  160. } else { 
  161.  
  162. # BASIC MODE 
  163.  
  164. $link_units = array( 
  165. '728x15' => '728x15',  
  166. '468x15' => '468x15',  
  167. '200x90' => '200x90',  
  168. '180x90' => '180x90',  
  169. '160x90' => '160x90',  
  170. '120x90' => '120x90',  
  171. ); 
  172.  
  173. $google_ad_type = get_option('GARD_AD_TYPE', 'text_image' ); 
  174.  
  175. if ($google_ad_type == 'link') { 
  176. $adsizes = $link_units; 
  177. } else { 
  178. global $adsizes; 
  179.  
  180. $google_color_border = str_replace("#", '', get_option( 'GARD_AD_BORDER', '#FFFFFF' ) ); 
  181. $google_color_bg = str_replace("#", '', get_option( 'GARD_AD_BACKGROUND', '#FFFFFF' ) ); 
  182. $google_color_link = str_replace("#", '', get_option( 'GARD_AD_TITLE', '#0000FF' ) ); 
  183. $google_color_url = str_replace("#", '', get_option( 'GARD_AD_URL', '#008000' ) ); 
  184. $google_color_text = str_replace("#", '', get_option( 'GARD_AD_TEXT', '#000000' ) ); 
  185. $google_ui_features = get_option('GARD_AD_RADIUS', '0'); 
  186.  
  187. $format_extension = '_as'; 
  188.  
  189. if ($google_ad_type == 'link') { 
  190. $format_extension = '_0ads_al'; 
  191. $google_ad_type = 'google_ad_type = "";'; 
  192. } else { 
  193. $google_ad_type = 'google_ad_type = "text";'; 
  194. // $google_ad_type = 'google_ad_type = "'.$google_ad_type.'";'; 
  195.  
  196.  
  197. $adsense = '  
  198. <div class="GARD gard_basic_mode" id="google-ads-'.$num.'"><script > 
  199. adUnit = document.getElementById("google-ads-'.$num.'"); 
  200. adWidth = adUnit.offsetWidth;  
  201.  
  202. if ( adWidth >= 999999 ) { 
  203. /* GETTING THE FIRST IF OUT OF THE WAY */  
  204. }'; 
  205.  
  206. foreach($adsizes as $size => $description) { 
  207.  
  208. $code = get_option('GARD_'.$size.'_BASIC'); 
  209. $mobile = get_option('GARD_MOBILE_BASIC'); 
  210.  
  211. $type = 'ad_unit'; 
  212. if ( get_option('GARD_AD_TYPE', 'text_image' ) == 'link' ) { 
  213. $type = 'link_unit'; 
  214. } elseif ($size == '300x600') { 
  215. $type = 'large_skyscraper'; 
  216.  
  217. $tag = $type."_".$size; 
  218. $original_size = $size; 
  219. $size = explode('x', $size); 
  220. $size1 = $size[0]; 
  221. $size2 = $size[1]; 
  222.  
  223. if ($code == '') { 
  224. continue; 
  225.  
  226. $mobile = get_option('GARD_MOBILE_BASIC_'.$original_size); 
  227.  
  228. if( $mobile == 1 && gard_ismobile() === FALSE ) { 
  229. // If ad is set to show to mobile only, and this is not a mobile device, skip the output of this ad 
  230. continue; 
  231. } elseif( $mobile == 2 && gard_ismobile() === TRUE ) { 
  232. // If ad is set to show to non-mobile only, and this is a mobile device, skip the output of this ad 
  233. continue; 
  234.  
  235. $adsense .= ' else if ( adWidth >= '.$size1.' ) { 
  236. if (document.querySelectorAll(".'.$type.'").length > 2 ) { 
  237. google_ad_slot = "0"; 
  238. adUnit.style.display = "none"; 
  239. } else { 
  240. adcount = document.querySelectorAll(".'.$type.'").length; 
  241. tag = "'.$tag.'_"+adcount; 
  242. google_ad_width = "'.$size1.'"; 
  243. google_ad_height = "'.$size2.'"; 
  244. google_ad_format = "'.$size1.'x'.$size2.$format_extension.'"; 
  245. '.$google_ad_type.' 
  246. google_ad_channel = ""; 
  247. }'; 
  248.  
  249.  
  250. $adsense .= ' else { 
  251. google_ad_slot = "0"; 
  252. adUnit.style.display = "none"; 
  253. adUnit.className = adUnit.className + " '.$type.' " + tag; 
  254. google_ad_client = "'.$id.'"; 
  255. adUnit.style.cssFloat = "'.$float.'"; 
  256. adUnit.style.styleFloat = "'.$float.'"; 
  257. adUnit.style.margin = "'.$margin.'"; 
  258. adUnit.style.textAlign = "'.$text.'"; 
  259. google_color_border = "'.$google_color_border.'"; 
  260. google_color_bg = "'.$google_color_bg.'"; 
  261. google_color_link = "'.$google_color_link.'"; 
  262. google_color_url = "'.$google_color_url.'"; 
  263. google_color_text = "'.$google_color_text.'"; 
  264. google_ui_features = "rc:'.$google_ui_features.'"; 
  265. </script> 
  266. <script src="//pagead2.googlesyndication.com/pagead/show_ads.js"></script> 
  267. </div>'; 
  268.  
  269.  
  270. # SET UP STYLE 
  271. if ( file_exists( dirname(__FILE__) .'gard_custom.css') ) {  
  272. wp_register_style( 'gard_ad_style', plugins_url( '/gard_custom.css', __FILE__ ) ); 
  273. wp_enqueue_style( 'gard_ad_style' ); 
  274.  
  275. if (!isset($_GET['GARD_DEBUG']))  
  276. $adsense = str_replace(array("\n", "\t"), "", $adsense); 
  277.  
  278. return $adsense;