public static function get_instance() { if (null == self::$instance) { self::$instance = new self(); } return self::$instance; }
public function print_scripts() { global $pagenow, $post_type; if ('post-new.php' == $pagenow && Advanced_Ads::POST_TYPE_SLUG == $post_type || 'post.php' == $pagenow && Advanced_Ads::POST_TYPE_SLUG == $post_type && isset($_GET['action']) && 'edit' == $_GET['action']) { $db = Gadsense_Data::get_instance(); $pub_id = $db->get_adsense_id(); ?> <script type="text/javascript"> var gadsenseData = { pubId : '<?php echo $pub_id; ?> ', msg : { unknownAd : '<?php esc_attr_e("The ad details couldn't be retrieved from the ad code", ADVADS_SLUG); ?> ', pubIdMismatch : '<?php _e('Warning : The AdSense account from this code does not match the one set with the Advanced Ads Plugin. This ad might cause troubles when used in the front end.', ADVADS_SLUG); ?> ' } }; </script> <?php } }
/** * prepare the ads frontend output * * @param obj $ad ad object * @return str $content ad content prepared for frontend output * @since 1.0.0 */ public function prepare_output($ad) { global $gadsense; $content = json_decode($ad->content); $output = ''; $db = Gadsense_Data::get_instance(); $pub_id = $db->get_adsense_id(); $limit_per_page = $db->get_limit_per_page(); if (!isset($content->unitType) || empty($pub_id)) { return $output; } // deprecated since the adsbygoogle.js file is now always loaded if (!isset($gadsense['google_loaded']) || !$gadsense['google_loaded']) { $gadsense['google_loaded'] = true; } if (isset($gadsense['adsense_count'])) { $gadsense['adsense_count']++; } else { $gadsense['adsense_count'] = 1; } if ($limit_per_page && 3 < $gadsense['adsense_count']) { // The maximum allowed adSense ad per page count is 3 (according to the current Google AdSense TOS). return ''; } if ('responsive' != $content->unitType) { $output .= '<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>' . "\n"; $output .= '<ins class="adsbygoogle" '; $output .= 'style="display:inline-block;width:' . $ad->width . 'px;height:' . $ad->height . 'px;" ' . "\n"; $output .= 'data-ad-client="ca-' . $pub_id . '" ' . "\n"; $output .= 'data-ad-slot="' . $content->slotId . '"></ins> ' . "\n"; $output .= '<script> ' . "\n"; $output .= '(adsbygoogle = window.adsbygoogle || []).push({}); ' . "\n"; $output .= '</script>' . "\n"; } else { if (!isset($content->resize) || 'auto' == $content->resize) { $this->append_defaut_responsive_content($output, $pub_id, $content->slotId); } else { /** * At this point, the ad is responsive ($ad->content->unitType == responsive) * The value of $ad->content->resize should be tested to format the output correctly * The $output variable already contains the first line which includes "adsbygoogle.js", * The rest of the output should be appended to it. */ $unmodified = $output; $output = apply_filters('advanced-ads-gadsense-responsive-output', $output, $ad, $pub_id); if ($unmodified == $output) { /** * If the output has not been modified, perform a default responsive output. * A simple did_action check isn't sufficient, some hooks may be attached and fired but didn't touch the output */ $this->append_defaut_responsive_content($output, $pub_id, $content->slotId); } } } return $output; }
<?php if (!defined('WPINC')) { die; } $is_responsive = 'responsive' == $unit_type ? true : false; $use_manual_css = 'manual' == $unit_resize ? true : false; if ($is_responsive) { echo '<style type="text/css"> #advanced-ads-ad-parameters-size {display: none;} </style>'; } $use_paste_code = true; $use_paste_code = apply_filters('advanced-ads-gadsense-use-pastecode', $use_paste_code); $db = Gadsense_Data::get_instance(); $sizing_array = $db->get_responsive_sizing(); ?> <div id="adsense-new-add-div-default"> <input type="hidden" id="advads-ad-content-adsense" name="advanced_ad[content]" value="<?php echo esc_attr($json_content); ?> " /> <input type="hidden" name="unit_id" id="unit_id" value="<?php echo esc_attr($unit_id); ?> " /> <?php if ($use_paste_code) { echo '<a class="button" href="#" id="show-pastecode-div">' . __('Copy&Paste existing ad code', ADVADS_SLUG) . '</a>'; } ?> <p id="adsense-ad-param-error"></p> <?php