| @@ -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. |
| @@ -12,10 +16,74 @@ | ||
| 12 | 16 | * |
| 13 | 17 | * Sets parameters for WordAds. |
| 14 | 18 | */ |
| 15 | 19 | class WordAds_Params { |
| 20 | + /** | |
| 21 | + * WordAds options | |
| 22 | + * | |
| 23 | + * @var array | |
| 24 | + */ | |
| 25 | + public $options; | |
| 16 | 26 | |
| 17 | 27 | /** |
| 28 | + * Current URL | |
| 29 | + * | |
| 30 | + * @access public | |
| 31 | + * @var string | |
| 32 | + */ | |
| 33 | + public $url; | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * Is this site served by CloudFlare? | |
| 37 | + * | |
| 38 | + * @access public | |
| 39 | + * @var bool | |
| 40 | + */ | |
| 41 | + public $cloudflare; | |
| 42 | + | |
| 43 | + /** | |
| 44 | + * Jetpack Blog ID | |
| 45 | + * | |
| 46 | + * @var mixed | |
| 47 | + */ | |
| 48 | + public $blog_id; | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * Determine if the current User Agent is a mobile device | |
| 52 | + * | |
| 53 | + * @var bool | |
| 54 | + */ | |
| 55 | + public $mobile_device; | |
| 56 | + | |
| 57 | + /** | |
| 58 | + * WordAds targeting tags | |
| 59 | + * | |
| 60 | + * @var array | |
| 61 | + */ | |
| 62 | + public $targeting_tags; | |
| 63 | + | |
| 64 | + /** | |
| 65 | + * Type of page that is being loaded | |
| 66 | + * | |
| 67 | + * @var string | |
| 68 | + */ | |
| 69 | + public $page_type; | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * Page type code for IPW config | |
| 73 | + * | |
| 74 | + * @var int | |
| 75 | + */ | |
| 76 | + public $page_type_ipw; | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * Is this an AMP request? | |
| 80 | + * | |
| 81 | + * @var bool | |
| 82 | + */ | |
| 83 | + public $is_amp; | |
| 84 | + | |
| 85 | + /** | |
| 18 | 86 | * Setup parameters for serving the ads |
| 19 | 87 | * |
| 20 | 88 | * @since 4.5.0 |
| 21 | 89 | */ |
| @@ -21,22 +89,26 @@ | ||
| 21 | 89 | */ |
| 22 | 90 | public function __construct() { |
| 23 | 91 | // WordAds setting => default. |
| 24 | 92 | $settings = array( |
| 25 | - 'wordads_approved' => false, | |
| 26 | - 'wordads_active' => false, | |
| 27 | - 'wordads_house' => true, | |
| 28 | - 'wordads_unsafe' => false, | |
| 29 | - 'enable_header_ad' => true, | |
| 30 | - 'wordads_second_belowpost' => true, | |
| 31 | - 'wordads_display_front_page' => true, | |
| 32 | - 'wordads_display_post' => true, | |
| 33 | - 'wordads_display_page' => true, | |
| 34 | - 'wordads_display_archive' => true, | |
| 35 | - 'wordads_custom_adstxt' => '', | |
| 36 | - 'wordads_custom_adstxt_enabled' => false, | |
| 37 | - 'wordads_ccpa_enabled' => false, | |
| 38 | - '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, | |
| 39 | 111 | ); |
| 40 | 112 | |
| 41 | 113 | // Grab settings, or set as default if it doesn't exist. |
| 42 | 114 | $this->options = array(); |
| @@ -61,9 +133,9 @@ | ||
| 61 | 133 | $this->options[ $setting ] = is_bool( $default ) ? (bool) $option : $option; |
| 62 | 134 | } |
| 63 | 135 | |
| 64 | 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'] ) : '' ) ); |
| 65 | - 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 | |
| 66 | 138 | $this->url = substr( $this->url, 0, strpos( $this->url, '?' ) ); |
| 67 | 139 | } |
| 68 | 140 | |
| 69 | 141 | $this->cloudflare = self::is_cloudflare(); |
| @@ -73,11 +145,12 @@ | ||
| 73 | 145 | 'WordAds' => 1, |
| 74 | 146 | 'BlogId' => ( new Status() )->is_offline_mode() ? 0 : Jetpack_Options::get_option( 'id' ), |
| 75 | 147 | 'Domain' => esc_js( wp_parse_url( home_url(), PHP_URL_HOST ) ), |
| 76 | 148 | 'PageURL' => esc_js( $this->url ), |
| 77 | - '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? | |
| 78 | 150 | 'AdSafe' => 1, // TODO. |
| 79 | 151 | ); |
| 152 | + $this->is_amp = function_exists( 'amp_is_request' ) && amp_is_request(); | |
| 80 | 153 | } |
| 81 | 154 | |
| 82 | 155 | /** |
| 83 | 156 | * Is this a mobile device? |