diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2019-01-01 22:18:11 -0500 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2019-01-01 22:18:11 -0500 |
commit | 018bd442ec1e04ba78a6628763414eb60b359398 (patch) | |
tree | 448cde462397af33e5a964ba5d0803b73c65040e /plugins/jetpack/modules/wordads/wordads.php | |
parent | Update easy-table 1.8 (diff) | |
download | blogs-gentoo-018bd442ec1e04ba78a6628763414eb60b359398.tar.gz blogs-gentoo-018bd442ec1e04ba78a6628763414eb60b359398.tar.bz2 blogs-gentoo-018bd442ec1e04ba78a6628763414eb60b359398.zip |
Update jetpack 6.8.1
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'plugins/jetpack/modules/wordads/wordads.php')
-rw-r--r-- | plugins/jetpack/modules/wordads/wordads.php | 126 |
1 files changed, 77 insertions, 49 deletions
diff --git a/plugins/jetpack/modules/wordads/wordads.php b/plugins/jetpack/modules/wordads/wordads.php index c1370300..e1ce5c37 100644 --- a/plugins/jetpack/modules/wordads/wordads.php +++ b/plugins/jetpack/modules/wordads/wordads.php @@ -7,9 +7,9 @@ define( 'WORDADS_URL', plugins_url( '/', __FILE__ ) ); define( 'WORDADS_API_TEST_ID', '26942' ); define( 'WORDADS_API_TEST_ID2', '114160' ); -require_once( WORDADS_ROOT . '/php/widgets.php' ); -require_once( WORDADS_ROOT . '/php/api.php' ); -require_once( WORDADS_ROOT . '/php/cron.php' ); +require_once WORDADS_ROOT . '/php/widgets.php'; +require_once WORDADS_ROOT . '/php/api.php'; +require_once WORDADS_ROOT . '/php/cron.php'; class WordAds { @@ -23,25 +23,25 @@ class WordAds { * @var array */ public static $ad_tag_ids = array( - 'mrec' => array( - 'tag' => '300x250_mediumrectangle', - 'height' => '250', - 'width' => '300', + 'mrec' => array( + 'tag' => '300x250_mediumrectangle', + 'height' => '250', + 'width' => '300', ), - 'lrec' => array( - 'tag' => '336x280_largerectangle', - 'height' => '280', - 'width' => '336', + 'lrec' => array( + 'tag' => '336x280_largerectangle', + 'height' => '280', + 'width' => '336', ), - 'leaderboard' => array( - 'tag' => '728x90_leaderboard', - 'height' => '90', - 'width' => '728', + 'leaderboard' => array( + 'tag' => '728x90_leaderboard', + 'height' => '90', + 'width' => '728', ), 'wideskyscraper' => array( - 'tag' => '160x600_wideskyscraper', - 'height' => '600', - 'width' => '160', + 'tag' => '160x600_wideskyscraper', + 'height' => '600', + 'width' => '160', ), ); @@ -82,11 +82,11 @@ class WordAds { return; } - require_once( WORDADS_ROOT . '/php/params.php' ); + require_once WORDADS_ROOT . '/php/params.php'; $this->params = new WordAds_Params(); if ( is_admin() ) { - require_once( WORDADS_ROOT . '/php/admin.php' ); + require_once WORDADS_ROOT . '/php/admin.php'; return; } @@ -137,9 +137,10 @@ class WordAds { * @since 4.5.0 */ private function insert_adcode() { - add_action( 'wp_head', array( $this, 'insert_head_meta' ), 20 ); - add_action( 'wp_head', array( $this, 'insert_head_iponweb' ), 30 ); - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); + add_action( 'wp_head', array( $this, 'insert_head_meta' ), 20 ); + add_action( 'wp_head', array( $this, 'insert_head_iponweb' ), 30 ); + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); + add_filter( 'wordads_ads_txt', array( $this, 'insert_custom_adstxt' ) ); /** * Filters enabling ads in `the_content` filter @@ -201,14 +202,15 @@ class WordAds { /** * IPONWEB metadata used by the various scripts + * * @return [type] [description] */ function insert_head_meta() { $themename = esc_js( get_stylesheet() ); - $pagetype = intval( $this->params->get_page_type_ipw() ); + $pagetype = intval( $this->params->get_page_type_ipw() ); $data_tags = ( $this->params->cloudflare ) ? ' data-cfasync="false"' : ''; - $site_id = $this->params->blog_id; - $consent = intval( isset( $_COOKIE['personalized-ads-consent'] ) ); + $site_id = $this->params->blog_id; + $consent = intval( isset( $_COOKIE['personalized-ads-consent'] ) ); echo <<<HTML <script$data_tags type="text/javascript"> var __ATA_PP = { pt: $pagetype, ht: 2, tn: '$themename', amp: false, siteid: $site_id, consent: $consent }; @@ -299,7 +301,7 @@ HTML; return $content; } - $ad_type = $this->option( 'wordads_house' ) ? 'house' : 'iponweb'; + $ad_type = $this->option( 'wordads_house' ) ? 'house' : 'iponweb'; $content .= $this->get_ad( 'inline', $ad_type ); return $content; } @@ -369,7 +371,26 @@ HTML; } /** + * Filter the latest ads.txt to include custom user entries. Strips any tags or whitespace. + * + * @param string $adstxt The ads.txt being filtered + * @return string Filtered ads.txt with custom entries, if applicable + * + * @since 6.5.0 + */ + function insert_custom_adstxt( $adstxt ) { + $custom_adstxt = trim( wp_strip_all_tags( $this->option( 'wordads_custom_adstxt' ) ) ); + if ( $custom_adstxt ) { + $adstxt .= "\n\n#Jetpack - User Custom Entries\n"; + $adstxt .= $custom_adstxt . "\n"; + } + + return $adstxt; + } + + /** * Get the ad for the spot and type. + * * @param string $spot top, side, inline, or belowpost * @param string $type iponweb or adsense */ @@ -377,42 +398,42 @@ HTML; $snippet = ''; if ( 'iponweb' == $type ) { // Default to mrec - $width = 300; + $width = 300; $height = 250; - $section_id = WORDADS_API_TEST_ID; + $section_id = WORDADS_API_TEST_ID; $second_belowpost = ''; - $snippet = ''; + $snippet = ''; if ( 'top' == $spot ) { // mrec for mobile, leaderboard for desktop $section_id = 0 === $this->params->blog_id ? WORDADS_API_TEST_ID : $this->params->blog_id . '2'; - $width = $this->params->mobile_device ? 300 : 728; - $height = $this->params->mobile_device ? 250 : 90; - $snippet = $this->get_ad_snippet( $section_id, $height, $width, $spot ); - } else if ( 'belowpost' == $spot ) { + $width = $this->params->mobile_device ? 300 : 728; + $height = $this->params->mobile_device ? 250 : 90; + $snippet = $this->get_ad_snippet( $section_id, $height, $width, $spot ); + } elseif ( 'belowpost' == $spot ) { $section_id = 0 === $this->params->blog_id ? WORDADS_API_TEST_ID : $this->params->blog_id . '1'; - $width = 300; - $height = 250; + $width = 300; + $height = 250; $snippet = $this->get_ad_snippet( $section_id, $height, $width, $spot, 'float:left;margin-right:5px;margin-top:0px;' ); if ( $this->option( 'wordads_second_belowpost', true ) ) { $section_id2 = 0 === $this->params->blog_id ? WORDADS_API_TEST_ID2 : $this->params->blog_id . '4'; - $snippet .= $this->get_ad_snippet( $section_id2, $height, $width, $spot, 'float:left;margin-top:0px;' ); + $snippet .= $this->get_ad_snippet( $section_id2, $height, $width, $spot, 'float:left;margin-top:0px;' ); } - } else if ( 'inline' === $spot ) { + } elseif ( 'inline' === $spot ) { $section_id = 0 === $this->params->blog_id ? WORDADS_API_TEST_ID : $this->params->blog_id . '5'; - $snippet = $this->get_ad_snippet( $section_id, $height, $width, $spot, 'mrec', 'float:left;margin-right:5px;margin-top:0px;' ); + $snippet = $this->get_ad_snippet( $section_id, $height, $width, $spot, 'mrec', 'float:left;margin-right:5px;margin-top:0px;' ); } - } else if ( 'house' == $type ) { + } elseif ( 'house' == $type ) { $leaderboard = 'top' == $spot && ! $this->params->mobile_device; - $snippet = $this->get_house_ad( $leaderboard ? 'leaderboard' : 'mrec' ); + $snippet = $this->get_house_ad( $leaderboard ? 'leaderboard' : 'mrec' ); if ( 'belowpost' == $spot && $this->option( 'wordads_second_belowpost', true ) ) { $snippet .= $this->get_house_ad( $leaderboard ? 'leaderboard' : 'mrec' ); } } $header = 'top' == $spot ? 'wpcnt-header' : ''; - $about = __( 'Advertisements', 'jetpack' ); + $about = __( 'Advertisements', 'jetpack' ); return <<<HTML <div class="wpcnt $header"> <div class="wpa"> @@ -428,18 +449,23 @@ HTML; /** * Returns the snippet to be inserted into the ad unit - * @param int $section_id - * @param int $height - * @param int $width - * @param int $location + * + * @param int $section_id + * @param int $height + * @param int $width + * @param int $location * @param string $css * @return string * * @since 5.7 */ function get_ad_snippet( $section_id, $height, $width, $location = '', $css = '' ) { - $this->ads[] = array( 'location' => $location, 'width' => $width, 'height' => $height ); - $ad_number = count( $this->ads ); + $this->ads[] = array( + 'location' => $location, + 'width' => $width, + 'height' => $height, + ); + $ad_number = count( $this->ads ); // Max 6 ads per page. if ( $ad_number > 5 && 'top' !== $location ) { return; @@ -467,16 +493,18 @@ HTML; /** * Check the reasons to bail before we attempt to insert ads. + * * @return true if we should bail (don't insert ads) * * @since 4.5.0 */ public function should_bail() { - return ! $this->option( 'wordads_approved' ); + return ! $this->option( 'wordads_approved' ) || (bool) $this->option( 'wordads_unsafe' ); } /** * Returns markup for HTML5 house ad base on unit + * * @param string $unit mrec, widesky, or leaderboard * @return string markup for HTML5 house ad * |