| @@ -6,8 +6,12 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | use Automattic\Jetpack\Status; |
| 9 | 9 | |
| 10 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 11 | + exit( 0 ); | |
| 12 | +} | |
| 13 | + | |
| 10 | 14 | /** |
| 11 | 15 | * Class WordAds_Params |
| 12 | 16 | * |
| 13 | 17 | * Sets parameters for WordAds. |
| @@ -71,8 +75,15 @@ | ||
| 71 | 75 | */ |
| 72 | 76 | public $page_type_ipw; |
| 73 | 77 | |
| 74 | 78 | /** |
| 79 | + * Is this an AMP request? | |
| 80 | + * | |
| 81 | + * @var bool | |
| 82 | + */ | |
| 83 | + public $is_amp; | |
| 84 | + | |
| 85 | + /** | |
| 75 | 86 | * Setup parameters for serving the ads |
| 76 | 87 | * |
| 77 | 88 | * @since 4.5.0 |
| 78 | 89 | */ |
| @@ -78,22 +89,26 @@ | ||
| 78 | 89 | */ |
| 79 | 90 | public function __construct() { |
| 80 | 91 | // WordAds setting => default. |
| 81 | 92 | $settings = array( |
| 82 | - 'wordads_approved' => false, | |
| 83 | - 'wordads_active' => false, | |
| 84 | - 'wordads_house' => true, | |
| 85 | - 'wordads_unsafe' => false, | |
| 86 | - 'enable_header_ad' => true, | |
| 87 | - 'wordads_second_belowpost' => true, | |
| 88 | - 'wordads_display_front_page' => true, | |
| 89 | - 'wordads_display_post' => true, | |
| 90 | - 'wordads_display_page' => true, | |
| 91 | - 'wordads_display_archive' => true, | |
| 92 | - 'wordads_custom_adstxt' => '', | |
| 93 | - 'wordads_custom_adstxt_enabled' => false, | |
| 94 | - 'wordads_ccpa_enabled' => false, | |
| 95 | - 'wordads_ccpa_privacy_policy_url' => get_option( 'wp_page_for_privacy_policy' ) ? get_permalink( (int) get_option( 'wp_page_for_privacy_policy' ) ) : '', | |
| 93 | + 'wordads_approved' => false, | |
| 94 | + 'wordads_active' => false, | |
| 95 | + 'wordads_house' => true, | |
| 96 | + 'wordads_unsafe' => false, | |
| 97 | + 'enable_header_ad' => true, | |
| 98 | + 'wordads_second_belowpost' => true, | |
| 99 | + 'wordads_inline_enabled' => true, | |
| 100 | + 'wordads_bottom_sticky_enabled' => false, | |
| 101 | + 'wordads_sidebar_sticky_right_enabled' => false, | |
| 102 | + 'wordads_display_front_page' => true, | |
| 103 | + 'wordads_display_post' => true, | |
| 104 | + 'wordads_display_page' => true, | |
| 105 | + 'wordads_display_archive' => true, | |
| 106 | + 'wordads_custom_adstxt' => '', | |
| 107 | + 'wordads_custom_adstxt_enabled' => false, | |
| 108 | + 'wordads_ccpa_enabled' => false, | |
| 109 | + 'wordads_ccpa_privacy_policy_url' => get_option( 'wp_page_for_privacy_policy' ) ? get_permalink( (int) get_option( 'wp_page_for_privacy_policy' ) ) : '', | |
| 110 | + 'wordads_cmp_enabled' => false, | |
| 96 | 111 | ); |
| 97 | 112 | |
| 98 | 113 | // Grab settings, or set as default if it doesn't exist. |
| 99 | 114 | $this->options = array(); |
| @@ -118,9 +133,9 @@ | ||
| 118 | 133 | $this->options[ $setting ] = is_bool( $default ) ? (bool) $option : $option; |
| 119 | 134 | } |
| 120 | 135 | |
| 121 | 136 | $this->url = esc_url_raw( ( is_ssl() ? 'https' : 'http' ) . '://' . ( isset( $_SERVER['HTTP_HOST'] ) ? wp_unslash( $_SERVER['HTTP_HOST'] ) : 'localhost' ) . ( isset( $_SERVER['REQUEST_URI'] ) ? wp_unslash( $_SERVER['REQUEST_URI'] ) : '' ) ); |
| 122 | - if ( ! ( false === strpos( $this->url, '?' ) ) && ! isset( $_GET['p'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 137 | + if ( str_contains( $this->url, '?' ) && ! isset( $_GET['p'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 123 | 138 | $this->url = substr( $this->url, 0, strpos( $this->url, '?' ) ); |
| 124 | 139 | } |
| 125 | 140 | |
| 126 | 141 | $this->cloudflare = self::is_cloudflare(); |
| @@ -130,11 +145,12 @@ | ||
| 130 | 145 | 'WordAds' => 1, |
| 131 | 146 | 'BlogId' => ( new Status() )->is_offline_mode() ? 0 : Jetpack_Options::get_option( 'id' ), |
| 132 | 147 | 'Domain' => esc_js( wp_parse_url( home_url(), PHP_URL_HOST ) ), |
| 133 | 148 | 'PageURL' => esc_js( $this->url ), |
| 134 | - 'LangId' => false !== strpos( get_bloginfo( 'language' ), 'en' ) ? 1 : 0, // TODO something else? | |
| 149 | + 'LangId' => str_contains( get_bloginfo( 'language' ), 'en' ) ? 1 : 0, // TODO something else? | |
| 135 | 150 | 'AdSafe' => 1, // TODO. |
| 136 | 151 | ); |
| 152 | + $this->is_amp = function_exists( 'amp_is_request' ) && amp_is_request(); | |
| 137 | 153 | } |
| 138 | 154 | |
| 139 | 155 | /** |
| 140 | 156 | * Is this a mobile device? |