Automattic /
jetpack
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | define( 'WORDADS_ROOT', dirname( __FILE__ ) ); |
||
| 4 | define( 'WORDADS_BASENAME', plugin_basename( __FILE__ ) ); |
||
| 5 | define( 'WORDADS_FILE_PATH', WORDADS_ROOT . '/' . basename( __FILE__ ) ); |
||
| 6 | define( 'WORDADS_URL', plugins_url( '/', __FILE__ ) ); |
||
| 7 | define( 'WORDADS_API_TEST_ID', '26942' ); |
||
| 8 | |||
| 9 | require_once( WORDADS_ROOT . '/php/widgets.php' ); |
||
| 10 | require_once( WORDADS_ROOT . '/php/api.php' ); |
||
| 11 | require_once( WORDADS_ROOT . '/php/cron.php' ); |
||
| 12 | |||
| 13 | class WordAds { |
||
| 14 | |||
| 15 | public $params = null; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * The different supported ad types. |
||
| 19 | * v0.1 - mrec only for now |
||
| 20 | * @var array |
||
| 21 | */ |
||
| 22 | public static $ad_tag_ids = array( |
||
| 23 | 'mrec' => array( |
||
| 24 | 'tag' => '300x250_mediumrectangle', |
||
| 25 | 'height' => '250', |
||
| 26 | 'width' => '300', |
||
| 27 | ), |
||
| 28 | 'lrec' => array( |
||
| 29 | 'tag' => '336x280_largerectangle', |
||
| 30 | 'height' => '280', |
||
| 31 | 'width' => '336', |
||
| 32 | ), |
||
| 33 | 'leaderboard' => array( |
||
| 34 | 'tag' => '728x90_leaderboard', |
||
| 35 | 'height' => '90', |
||
| 36 | 'width' => '728', |
||
| 37 | ), |
||
| 38 | 'wideskyscraper' => array( |
||
| 39 | 'tag' => '160x600_wideskyscraper', |
||
| 40 | 'height' => '600', |
||
| 41 | 'width' => '160', |
||
| 42 | ), |
||
| 43 | ); |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Convenience function for grabbing options from params->options |
||
| 47 | * @param string $option the option to grab |
||
| 48 | * @param mixed $default (optional) |
||
| 49 | * @return option or $default if not set |
||
| 50 | * |
||
| 51 | * @since 4.5.0 |
||
| 52 | */ |
||
| 53 | function option( $option, $default = false ) { |
||
| 54 | if ( ! isset( $this->params->options[ $option ] ) ) { |
||
| 55 | return $default; |
||
| 56 | } |
||
| 57 | |||
| 58 | return $this->params->options[ $option ]; |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Instantiate the plugin |
||
| 63 | * |
||
| 64 | * @since 4.5.0 |
||
| 65 | */ |
||
| 66 | function __construct() { |
||
| 67 | add_action( 'init', array( $this, 'init' ) ); |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Code to run on WordPress 'init' hook |
||
| 72 | * |
||
| 73 | * @since 4.5.0 |
||
| 74 | */ |
||
| 75 | function init() { |
||
| 76 | // bail on infinite scroll |
||
| 77 | if ( self::is_infinite_scroll() ) { |
||
| 78 | return; |
||
| 79 | } |
||
| 80 | |||
| 81 | require_once( WORDADS_ROOT . '/php/params.php' ); |
||
| 82 | $this->params = new WordAds_Params(); |
||
| 83 | |||
| 84 | if ( is_admin() ) { |
||
| 85 | require_once( WORDADS_ROOT . '/php/admin.php' ); |
||
| 86 | return; |
||
| 87 | } |
||
| 88 | |||
| 89 | if ( $this->should_bail() ) { |
||
| 90 | return; |
||
| 91 | } |
||
| 92 | |||
| 93 | $this->insert_adcode(); |
||
| 94 | $this->insert_extras(); |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Check for Jetpack's The_Neverending_Home_Page and use got_infinity |
||
| 99 | * @return boolean true if load came from infinite scroll |
||
| 100 | * |
||
| 101 | * @since 4.5.0 |
||
| 102 | */ |
||
| 103 | public static function is_infinite_scroll() { |
||
| 104 | return current_theme_supports( 'infinite-scroll' ) && |
||
| 105 | class_exists( 'The_Neverending_Home_Page' ) && |
||
| 106 | The_Neverending_Home_Page::got_infinity(); |
||
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Add the actions/filters to insert the ads. Checks for mobile or desktop. |
||
| 111 | * |
||
| 112 | * @since 4.5.0 |
||
| 113 | */ |
||
| 114 | private function insert_adcode() { |
||
| 115 | add_action( 'wp_head', array( $this, 'insert_head_meta' ), 20 ); |
||
| 116 | add_action( 'wp_head', array( $this, 'insert_head_iponweb' ), 30 ); |
||
| 117 | add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); |
||
| 118 | add_filter( 'the_content', array( $this, 'insert_ad' ) ); |
||
| 119 | add_filter( 'the_excerpt', array( $this, 'insert_ad' ) ); |
||
| 120 | |||
| 121 | if ( $this->option( 'enable_header_ad' ) ) { |
||
| 122 | add_action( 'wp_head', array( $this, 'insert_header_ad' ), 100 ); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Add the actions/filters to insert extra-network features. |
||
| 128 | * |
||
| 129 | * @since 4.5.0 |
||
| 130 | */ |
||
| 131 | private function insert_extras() { |
||
| 132 | require_once( WORDADS_ROOT . '/php/networks/amazon.php' ); |
||
| 133 | } |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Register desktop scripts and styles |
||
| 137 | * |
||
| 138 | * @since 4.5.0 |
||
| 139 | */ |
||
| 140 | function enqueue_scripts() { |
||
| 141 | wp_enqueue_style( |
||
| 142 | 'wordads', |
||
| 143 | WORDADS_URL . 'css/style.css', |
||
| 144 | array(), |
||
| 145 | '2015-12-18' |
||
| 146 | ); |
||
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * IPONWEB metadata used by the various scripts |
||
| 151 | * @return [type] [description] |
||
|
0 ignored issues
–
show
|
|||
| 152 | */ |
||
| 153 | function insert_head_meta() { |
||
| 154 | $domain = $this->params->targeting_tags['Domain']; |
||
| 155 | $pageURL = $this->params->targeting_tags['PageURL']; |
||
| 156 | $adsafe = $this->params->targeting_tags['AdSafe']; |
||
| 157 | $data_tags = ( $this->params->cloudflare ) ? ' data-cfasync="false"' : ''; |
||
| 158 | echo <<<HTML |
||
| 159 | <script$data_tags type="text/javascript"> |
||
| 160 | var _ipw_custom = { |
||
| 161 | wordAds: '1', |
||
| 162 | domain: '$domain', |
||
| 163 | pageURL: '$pageURL', |
||
| 164 | adSafe: '$adsafe' |
||
| 165 | }; |
||
| 166 | </script> |
||
| 167 | HTML; |
||
| 168 | } |
||
| 169 | |||
| 170 | /** |
||
| 171 | * IPONWEB scripts in <head> |
||
| 172 | * |
||
| 173 | * @since 4.5.0 |
||
| 174 | */ |
||
| 175 | function insert_head_iponweb() { |
||
| 176 | $data_tags = ( $this->params->cloudflare ) ? ' data-cfasync="false"' : ''; |
||
| 177 | echo "<script$data_tags type='text/javascript' src='//s.pubmine.com/head.js'></script>"; |
||
| 178 | } |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Insert the ad onto the page |
||
| 182 | * |
||
| 183 | * @since 4.5.0 |
||
| 184 | */ |
||
| 185 | function insert_ad( $content ) { |
||
| 186 | /** |
||
| 187 | * Allow third-party tools to disable the display of in post ads. |
||
| 188 | * |
||
| 189 | * @module wordads |
||
| 190 | * |
||
| 191 | * @since 4.5.0 |
||
| 192 | * |
||
| 193 | * @param bool true Should the in post unit be disabled. Default to false. |
||
| 194 | */ |
||
| 195 | $disable = apply_filters( 'wordads_inpost_disable', false ); |
||
| 196 | if ( ! $this->params->should_show() || $disable ) { |
||
| 197 | return $content; |
||
| 198 | } |
||
| 199 | |||
| 200 | $ad_type = $this->option( 'wordads_house' ) ? 'house' : 'iponweb'; |
||
| 201 | return $content . $this->get_ad( 'belowpost', $ad_type ); |
||
| 202 | } |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Inserts ad into header |
||
| 206 | * |
||
| 207 | * @since 4.5.0 |
||
| 208 | */ |
||
| 209 | function insert_header_ad() { |
||
| 210 | /** |
||
| 211 | * Allow third-party tools to disable the display of header ads. |
||
| 212 | * |
||
| 213 | * @module wordads |
||
| 214 | * |
||
| 215 | * @since 4.5.0 |
||
| 216 | * |
||
| 217 | * @param bool true Should the header unit be disabled. Default to false. |
||
| 218 | */ |
||
| 219 | if ( apply_filters( 'wordads_header_disable', false ) ) { |
||
| 220 | return; |
||
| 221 | } |
||
| 222 | |||
| 223 | $ad_type = $this->option( 'wordads_house' ) ? 'house' : 'iponweb'; |
||
| 224 | echo $this->get_ad( 'top', $ad_type ); |
||
| 225 | } |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Get the ad for the spot and type. |
||
| 229 | * @param string $spot top, side, or belowpost |
||
| 230 | * @param string $type iponweb or adsense |
||
| 231 | */ |
||
| 232 | function get_ad( $spot, $type = 'iponweb' ) { |
||
| 233 | $snippet = ''; |
||
| 234 | if ( 'iponweb' == $type ) { |
||
| 235 | $section_id = WORDADS_API_TEST_ID; |
||
| 236 | $width = 300; |
||
| 237 | $height = 250; |
||
| 238 | if ( 'top' == $spot ) { |
||
| 239 | // mrec for mobile, leaderboard for desktop |
||
| 240 | $section_id = 0 === $this->params->blog_id ? WORDADS_API_TEST_ID : $this->params->blog_id . '2'; |
||
| 241 | $width = $this->params->mobile_device ? 300 : 728; |
||
| 242 | $height = $this->params->mobile_device ? 250 : 90; |
||
| 243 | } else if ( 'belowpost' ) { |
||
| 244 | $section_id = 0 === $this->params->blog_id ? WORDADS_API_TEST_ID : $this->params->blog_id . '1'; |
||
| 245 | $width = 300; |
||
| 246 | $height = 250; |
||
| 247 | } |
||
| 248 | $data_tags = ( $this->params->cloudflare ) ? ' data-cfasync="false"' : ''; |
||
| 249 | $snippet = <<<HTML |
||
| 250 | <script$data_tags type='text/javascript'> |
||
| 251 | (function(g){g.__ATA.initAd({sectionId:$section_id, width:$width, height:$height});})(window); |
||
| 252 | </script> |
||
| 253 | HTML; |
||
| 254 | } else if ( 'house' == $type ) { |
||
| 255 | $width = 300; |
||
| 256 | $height = 250; |
||
| 257 | $ad_url = 'https://s0.wp.com/wp-content/blog-plugins/wordads/house/'; |
||
| 258 | if ( 'top' == $spot && ! $this->params->mobile_device ) { |
||
| 259 | $width = 728; |
||
| 260 | $height = 90; |
||
| 261 | $ad_url .= 'leaderboard.png'; |
||
| 262 | } else { |
||
| 263 | $ad_url .= 'mrec.png'; |
||
| 264 | } |
||
| 265 | |||
| 266 | $snippet = <<<HTML |
||
| 267 | <a href="https://wordpress.com/create/" target="_blank"> |
||
| 268 | <img src="$ad_url" alt="WordPress.com: Grow Your Business" width="$width" height="$height" /> |
||
| 269 | </a> |
||
| 270 | HTML; |
||
| 271 | } |
||
| 272 | |||
| 273 | $about = __( 'About these ads', 'jetpack' ); |
||
| 274 | return <<<HTML |
||
| 275 | <div class="wpcnt"> |
||
| 276 | <div class="wpa"> |
||
| 277 | <a class="wpa-about" href="https://en.wordpress.com/about-these-ads/" rel="nofollow">$about</a> |
||
| 278 | <div class="u $spot"> |
||
| 279 | $snippet |
||
| 280 | </div> |
||
| 281 | </div> |
||
| 282 | </div> |
||
| 283 | HTML; |
||
| 284 | } |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Check the reasons to bail before we attempt to insert ads. |
||
| 288 | * @return true if we should bail (don't insert ads) |
||
| 289 | * |
||
| 290 | * @since 4.5.0 |
||
| 291 | */ |
||
| 292 | public function should_bail() { |
||
| 293 | return ! $this->option( 'wordads_approved' ); |
||
| 294 | } |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Activation hook actions |
||
| 298 | * |
||
| 299 | * @since 4.5.0 |
||
| 300 | */ |
||
| 301 | public static function activate() { |
||
| 302 | WordAds_API::update_wordads_status_from_api(); |
||
| 303 | } |
||
| 304 | } |
||
| 305 | |||
| 306 | add_action( 'jetpack_activate_module_wordads', array( 'WordAds', 'activate' ) ); |
||
| 307 | add_action( 'jetpack_activate_module_wordads', array( 'WordAds_Cron', 'activate' ) ); |
||
| 308 | add_action( 'jetpack_deactivate_module_wordads', array( 'WordAds_Cron', 'deactivate' ) ); |
||
| 309 | |||
| 310 | global $wordads; |
||
| 311 | $wordads = new WordAds(); |
||
| 312 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.