|
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] |
|
|
|
|
|
|
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
|
|
|
* @since 4.5.0 |
|
190
|
|
|
* |
|
191
|
|
|
* @param bool true Should the in post unit be disabled. Default to false. |
|
192
|
|
|
*/ |
|
193
|
|
|
$disable = apply_filters( 'wordads_inpost_disable', false ); |
|
194
|
|
|
if ( ! $this->params->should_show() || $disable ) { |
|
195
|
|
|
return $content; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
$ad_type = $this->option( 'wordads_house' ) ? 'house' : 'iponweb'; |
|
199
|
|
|
return $content . $this->get_ad( 'belowpost', $ad_type ); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Inserts ad into header |
|
204
|
|
|
* |
|
205
|
|
|
* @since 4.5.0 |
|
206
|
|
|
*/ |
|
207
|
|
|
function insert_header_ad() { |
|
208
|
|
|
/** |
|
209
|
|
|
* Allow third-party tools to disable the display of header ads. |
|
210
|
|
|
* |
|
211
|
|
|
* @since 4.5.0 |
|
212
|
|
|
* |
|
213
|
|
|
* @param bool true Should the header unit be disabled. Default to false. |
|
214
|
|
|
*/ |
|
215
|
|
|
if ( apply_filters( 'wordads_header_disable', false ) ) { |
|
216
|
|
|
return; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
$ad_type = $this->option( 'wordads_house' ) ? 'house' : 'iponweb'; |
|
220
|
|
|
echo $this->get_ad( 'top', $ad_type ); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* Get the ad for the spot and type. |
|
225
|
|
|
* @param string $spot top, side, or belowpost |
|
226
|
|
|
* @param string $type iponweb or adsense |
|
227
|
|
|
*/ |
|
228
|
|
|
function get_ad( $spot, $type = 'iponweb' ) { |
|
229
|
|
|
$snippet = ''; |
|
230
|
|
|
if ( 'iponweb' == $type ) { |
|
231
|
|
|
$section_id = WORDADS_API_TEST_ID; |
|
232
|
|
|
$width = 300; |
|
233
|
|
|
$height = 250; |
|
234
|
|
|
if ( 'top' == $spot ) { |
|
235
|
|
|
// mrec for mobile, leaderboard for desktop |
|
236
|
|
|
$section_id = 0 === $this->params->blog_id ? WORDADS_API_TEST_ID : $this->params->blog_id . '2'; |
|
237
|
|
|
$width = $this->params->mobile_device ? 300 : 728; |
|
238
|
|
|
$height = $this->params->mobile_device ? 250 : 90; |
|
239
|
|
|
} else if ( 'belowpost' ) { |
|
240
|
|
|
$section_id = 0 === $this->params->blog_id ? WORDADS_API_TEST_ID : $this->params->blog_id . '1'; |
|
241
|
|
|
$width = 300; |
|
242
|
|
|
$height = 250; |
|
243
|
|
|
} |
|
244
|
|
|
$data_tags = ( $this->params->cloudflare ) ? ' data-cfasync="false"' : ''; |
|
245
|
|
|
$snippet = <<<HTML |
|
246
|
|
|
<script$data_tags type='text/javascript'> |
|
247
|
|
|
(function(g){g.__ATA.initAd({sectionId:$section_id, width:$width, height:$height});})(window); |
|
248
|
|
|
</script> |
|
249
|
|
|
HTML; |
|
250
|
|
|
} else if ( 'house' == $type ) { |
|
251
|
|
|
$width = 300; |
|
252
|
|
|
$height = 250; |
|
253
|
|
|
$ad_url = 'https://s0.wp.com/wp-content/blog-plugins/wordads/house/'; |
|
254
|
|
|
if ( 'top' == $spot && ! $this->params->mobile_device ) { |
|
255
|
|
|
$width = 728; |
|
256
|
|
|
$height = 90; |
|
257
|
|
|
$ad_url .= 'leaderboard.png'; |
|
258
|
|
|
} else { |
|
259
|
|
|
$ad_url .= 'mrec.png'; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
$snippet = <<<HTML |
|
263
|
|
|
<a href="https://wordpress.com/create/" target="_blank"> |
|
264
|
|
|
<img src="$ad_url" alt="WordPress.com: Grow Your Business" width="$width" height="$height" /> |
|
265
|
|
|
</a> |
|
266
|
|
|
HTML; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
$about = __( 'About these ads', 'jetpack' ); |
|
270
|
|
|
return <<<HTML |
|
271
|
|
|
<div class="wpcnt"> |
|
272
|
|
|
<div class="wpa"> |
|
273
|
|
|
<a class="wpa-about" href="https://en.wordpress.com/about-these-ads/" rel="nofollow">$about</a> |
|
274
|
|
|
<div class="u $spot"> |
|
275
|
|
|
$snippet |
|
276
|
|
|
</div> |
|
277
|
|
|
</div> |
|
278
|
|
|
</div> |
|
279
|
|
|
HTML; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* Check the reasons to bail before we attempt to insert ads. |
|
284
|
|
|
* @return true if we should bail (don't insert ads) |
|
285
|
|
|
* |
|
286
|
|
|
* @since 4.5.0 |
|
287
|
|
|
*/ |
|
288
|
|
|
public function should_bail() { |
|
289
|
|
|
return ! $this->option( 'wordads_approved' ); |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* Activation hook actions |
|
294
|
|
|
* |
|
295
|
|
|
* @since 4.5.0 |
|
296
|
|
|
*/ |
|
297
|
|
|
public static function activate() { |
|
298
|
|
|
WordAds_API::update_wordads_status_from_api(); |
|
299
|
|
|
} |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
add_action( 'jetpack_activate_module_wordads', array( 'WordAds', 'activate' ) ); |
|
303
|
|
|
add_action( 'jetpack_activate_module_wordads', array( 'WordAds_Cron', 'activate' ) ); |
|
304
|
|
|
add_action( 'jetpack_deactivate_module_wordads', array( 'WordAds_Cron', 'deactivate' ) ); |
|
305
|
|
|
|
|
306
|
|
|
global $wordads; |
|
307
|
|
|
$wordads = new WordAds(); |
|
308
|
|
|
|
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.