PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.8.3
Advanced Ads – Ad Manager & AdSense v1.8.3
2.0.26 2.0.25 2.0.24 2.0.23 2.0.22 2.0.21 1.38.0 1.39.0 1.39.1 1.39.2 1.39.3 1.39.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.40.0 1.40.1 1.40.2 1.41.0 1.42.0 1.42.1 1.42.2 1.43.0 1.44.0 1.44.1 1.45.0 1.45.1 1.46.0 1.47.0 1.47.1 1.47.2 1.47.3 1.47.4 1.47.5 1.48.0 1.48.1 1.49.0 1.5.0 1.5.0.1 1.5.1 1.5.2 1.5.2.1 1.5.4 1.5.4.1 1.5.5 1.50.0 1.51.0 1.51.1 1.51.2 1.51.3 1.52.0 1.52.1 1.52.2 1.52.3 1.52.4 1.53.0 1.53.1 1.53.2 1.54.0 1.54.1 1.55.0 1.56.0 1.56.1 1.56.2 1.56.3 1.56.4 1.6 1.6.1 1.6.10 1.6.10.1 1.6.10.2 1.6.11 1.6.11.1 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.17.1 1.6.17.2 1.6.2 1.6.2.1 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.6.1 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.6.8.3 1.6.9 1.6.9.1 1.6.9.2 1.6.9.3 1.6.9.4 1.7 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.1.1 1.7.1.2 1.7.1.3 1.7.1.4 1.7.1.5 1.7.10 trunk 1.7.11 1.0.1 1.7.12 1.0.2 1.7.13 1.0.3 1.7.14 1.1.0 1.7.15 1.1.1 1.7.16 1.1.2 1.7.17 1.1.3 1.7.18 1.10 1.7.19 1.10.1 1.7.2 1.10.10 1.7.2.1 1.10.11 1.7.20 1.10.12 1.7.21 1.10.2 1.7.22 1.10.3 1.7.23 1.10.4 1.7.24 1.10.5 1.7.25 1.10.6 1.7.3 1.10.7 1.7.4 1.10.8 1.7.4.1 1.10.9 1.7.4.2 1.11 1.7.4.3 1.11.1 1.7.4.4 1.11.2 1.7.4.5 1.12 1.7.5 1.13 1.7.5.1 1.13.1 1.7.6 1.13.2 1.7.7 1.13.3 1.7.8 1.13.4 1.7.9 1.13.5 1.7.9.1 1.13.6 1.7.9.2 1.13.7 1.7.9.3 1.13.8 1.8 1.14 1.8.1 1.14.1 1.8.10 1.14.10 1.8.11 1.14.11 1.8.12 1.14.2 1.8.13 1.14.3 1.8.14 1.14.4 1.8.15 1.14.5 1.8.16 1.14.6 1.8.17 1.14.7 1.8.18 1.14.8 1.8.19 1.14.9 1.8.2 1.15 1.8.20 1.16 1.8.21 1.16.1 1.8.22 1.17 1.8.23 1.17.1 1.8.24 1.17.10 1.8.25 1.17.10-rc.1 1.8.26 1.17.11 1.8.27 1.17.12 1.8.28 1.17.12-rc.1 1.8.29 1.17.2 1.8.3 1.17.3 1.8.30 1.17.4 1.8.4 1.17.5 1.8.5 1.17.6 1.8.6 1.17.7 1.8.7 1.17.8 1.8.8 1.17.9 1.8.9 1.17.9-beta.1 1.9 1.18.0 2.0.0 1.19.0 2.0.1 1.19.1 2.0.10 1.2 2.0.11 1.2.1 2.0.12 1.2.2 2.0.13 1.2.3 2.0.14 1.2.4 2.0.15 1.2.5 2.0.16 1.2.6 2.0.17 1.2.7 2.0.18 1.20.0 2.0.19 1.20.0-rc.1 2.0.2 1.20.0-rc.2 2.0.20 1.20.1 2.0.3 1.20.2 2.0.4 1.20.3 2.0.5 1.21.0 2.0.6 1.21.1 2.0.7 1.22.0 2.0.8 1.22.1 2.0.9 1.22.2 1.23.0 1.23.1 1.23.2 1.24.0 1.24.1 1.24.2 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.29.0 1.29.1 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.30.0 1.30.1 1.30.2 1.30.2-rc.1 1.30.3 1.30.4 1.30.4-rc.1 1.30.5 1.31.0 1.31.1 1.32.0 1.32.0-rc.1 1.33.0 1.33.1 1.33.2 1.34.0 1.35.0 1.35.1 1.36.0 1.36.1 1.36.2 1.36.3 1.37.0 1.37.1 1.37.2
advanced-ads / admin / includes / class-ad-type.php
advanced-ads / admin / includes Last commit date
class-ad-groups-list.php 9 years ago class-ad-type.php 9 years ago class-licenses.php 9 years ago class-menu.php 9 years ago class-meta-box.php 9 years ago class-notices.php 9 years ago class-options.php 9 years ago class-overview-widgets.php 9 years ago class-settings.php 9 years ago class-shortcode-creator.php 9 years ago notices.php 9 years ago shortcode-creator-l10n.php 10 years ago
class-ad-type.php
602 lines
1 <?php
2 defined( 'ABSPATH' ) || exit;
3
4 class Advanced_Ads_Admin_Ad_Type {
5 /**
6 * Instance of this class.
7 *
8 * @var object
9 */
10 protected static $instance = null;
11
12 /**
13 * post type slug
14 *
15 * @since 1.0.0
16 * @var string
17 */
18 protected $post_type = '';
19
20 private function __construct() {
21 add_filter( 'wp', array($this, 'wp_loaded') );
22 // registering custom columns needs to work with and without DOING_AJAX
23 add_filter( 'manage_advanced_ads_posts_columns', array($this, 'ad_list_columns_head') ); // extra column
24 add_filter( 'manage_advanced_ads_posts_custom_column', array($this, 'ad_list_columns_content'), 10, 2 ); // extra column
25 add_filter( 'manage_advanced_ads_posts_custom_column', array($this, 'ad_list_columns_timing'), 10, 2 ); // extra column
26 add_action( 'restrict_manage_posts', array( $this, 'ad_list_add_filters') );
27
28 // ad updated messages
29 add_filter( 'bulk_post_updated_messages', array($this, 'ad_bulk_update_messages'), 10, 2 );
30
31 // handling (ad) lists
32 add_filter( 'request', array($this, 'ad_list_request') ); // order ads by title, not ID
33 add_action( 'all_admin_notices', array($this, 'no_ads_yet_notice') );
34
35 // save ads post type
36 add_action( 'save_post', array($this, 'save_ad') );
37 // delete ads post type
38 add_action( 'delete_post', array($this, 'delete_ad') );
39
40 // on post/ad edit screen
41 add_action( 'edit_form_top', array($this, 'edit_form_above_title') );
42 add_action( 'edit_form_after_title', array($this, 'edit_form_below_title') );
43 add_action( 'dbx_post_sidebar', array($this, 'edit_form_end') );
44 add_action( 'post_submitbox_misc_actions', array($this, 'add_submit_box_meta') );
45
46 // ad updated messages
47 add_filter( 'post_updated_messages', array($this, 'ad_update_messages') );
48
49 $this->post_type = constant( 'Advanced_Ads::POST_TYPE_SLUG' );
50 }
51
52 /**
53 * Return an instance of this class.
54 *
55 * @return object A single instance of this class.
56 */
57 public static function get_instance() {
58 // If the single instance hasn't been set, set it now.
59 if ( null == self::$instance ) {
60 self::$instance = new self;
61 }
62
63 return self::$instance;
64 }
65
66 /**
67 * general stuff after page is loaded and screen variable is available
68 */
69 public function wp_loaded(){
70 $screen = get_current_screen();
71
72 if( !isset( $screen->id ) ){
73 return;
74 }
75
76 switch( $screen->id ){
77 case 'edit-advanced_ads' : // ad edit page
78 // remove notice about missing first ad
79 Advanced_Ads_Admin_Notices::get_instance()->remove_from_queue( 'nl_intro' );
80 break;
81 }
82 }
83
84 /**
85 * add heading for extra column of ads list
86 * remove the date column
87 *
88 * @since 1.3.3
89 * @param arr $columns
90 */
91 public function ad_list_columns_head( $columns ){
92 $new_columns = array();
93 if( is_array( $columns ) ){
94 foreach( $columns as $key => $value ) {
95 $new_columns[ $key ] = $value;
96 if ( $key == 'title' ){
97 $new_columns[ 'ad_details' ] = __( 'Ad Details', 'advanced-ads' );
98 $new_columns[ 'ad_timing' ] = __( 'Ad Planning', 'advanced-ads' );
99 }
100 }
101 } else {
102 $new_columns[ 'ad_details' ] = __( 'Ad Details', 'advanced-ads' );
103 $new_columns[ 'ad_timing' ] = __( 'Ad Planning', 'advanced-ads' );
104 }
105
106 // white-listed columns
107 $whitelist = apply_filters( 'advanced-ads-ad-list-allowed-columns', array(
108 'cb', // checkbox
109 'title',
110 'ad_details',
111 'ad_timing',
112 'taxonomy-advanced_ads_groups',
113 ) );
114
115 // remove non-white-listed columns
116 foreach( $new_columns as $_key => $_value ){
117 if( ! in_array( $_key, $whitelist ) ){
118 unset( $new_columns[ $_key ] );
119 }
120 }
121
122 return $new_columns;
123 }
124
125 /**
126 * display ad details in ads list
127 *
128 * @since 1.3.3
129 * @param string $column_name name of the column
130 * @param int $ad_id id of the ad
131 */
132 public function ad_list_columns_content($column_name, $ad_id) {
133 if ( $column_name == 'ad_details' ) {
134 $ad = new Advanced_Ads_Ad( $ad_id );
135
136 // load ad type title
137 $types = Advanced_Ads::get_instance()->ad_types;
138 $type = ( ! empty($types[$ad->type]->title)) ? $types[$ad->type]->title : 0;
139
140 // load ad size
141 $size = 0;
142 if ( ! empty($ad->width) || ! empty($ad->height) ) {
143 $size = sprintf( '%d x %d', $ad->width, $ad->height );
144 }
145
146 $size = apply_filters( 'advanced-ads-list-ad-size', $size, $ad );
147
148 include ADVADS_BASE_PATH . 'admin/views/ad-list-details-column.php';
149 }
150 }
151
152 /**
153 * display ad details in ads list
154 *
155 * @since 1.6.11
156 * @param string $column_name name of the column
157 * @param int $ad_id id of the ad
158 */
159 public function ad_list_columns_timing($column_name, $ad_id) {
160 if ( $column_name == 'ad_timing' ) {
161 $ad = new Advanced_Ads_Ad( $ad_id );
162
163 $expiry = false;
164 $post_future = false;
165 $post_start = get_the_date('U', $ad->id );
166 $html_classes = 'advads-filter-timing';
167 $expiry_date_format = get_option( 'date_format' ). ', ' . get_option( 'time_format' );
168
169 if( isset( $ad->expiry_date ) && $ad->expiry_date ){
170 $html_classes .= ' advads-filter-any-exp-date';
171
172 $expiry = $ad->expiry_date;
173 if( $ad->expiry_date < time() ){
174 $html_classes .= ' advads-filter-expired';
175 }
176 }
177 if( $post_start > time() ){
178 $post_future = $post_start;
179 $html_classes .= ' advads-filter-future';
180 }
181
182 ob_start();
183 do_action_ref_array( 'advanced-ads-ad-list-timing-column-after', array( $ad, &$html_classes ) );
184 $content_after = ob_get_clean();
185
186 include ADVADS_BASE_PATH . 'admin/views/ad-list-timing-column.php';
187 }
188 }
189
190 /**
191 * adds filter dropdowns before the 'Filter' button on the ad list table
192 */
193 function ad_list_add_filters() {
194 $screen = get_current_screen();
195 if ( ! isset( $screen->id ) || $screen->id !== 'edit-advanced_ads' ) {
196 return;
197 }
198
199 $timing_filter = apply_filters( 'advanced-ads-ad-list-timing-column-filter', array(
200 'advads-filter-expired' => __( 'expired', 'advanced-ads' ),
201 'advads-filter-any-exp-date' => __( 'any expiry date', 'advanced-ads' ),
202 'advads-filter-future' => __( 'planned', 'advanced-ads' )
203 ) );
204
205 include ADVADS_BASE_PATH . 'admin/views/ad-list-filters.php';
206 }
207
208 /**
209 * edit ad bulk update messages
210 *
211 * @since 1.4.7
212 * @param arr $messages existing bulk update messages
213 * @param arr $counts numbers of updated ads
214 * @return arr $messages
215 *
216 * @see wp-admin/edit.php
217 */
218 public function ad_bulk_update_messages(array $messages, array $counts){
219 $post = get_post();
220
221 $messages[Advanced_Ads::POST_TYPE_SLUG] = array(
222 'updated' => _n( '%s ad updated.', '%s ads updated.', $counts['updated'], 'advanced-ads' ),
223 'locked' => _n( '%s ad not updated, somebody is editing it.', '%s ads not updated, somebody is editing them.', $counts['locked'], 'advanced-ads' ),
224 'deleted' => _n( '%s ad permanently deleted.', '%s ads permanently deleted.', $counts['deleted'], 'advanced-ads' ),
225 'trashed' => _n( '%s ad moved to the Trash.', '%s ads moved to the Trash.', $counts['trashed'], 'advanced-ads' ),
226 'untrashed' => _n( '%s ad restored from the Trash.', '%s ads restored from the Trash.', $counts['untrashed'], 'advanced-ads' ),
227 );
228
229 return $messages;
230 }
231
232 /**
233 * order ads by title on ads list
234 *
235 * @since 1.3.18
236 * @param arr $vars array with request vars
237 */
238 public function ad_list_request($vars){
239
240 // order ads by title on ads list
241 if ( is_admin() && empty( $vars['orderby'] ) && $this->post_type == $vars['post_type'] ) {
242 $vars = array_merge( $vars, array(
243 'orderby' => 'title',
244 'order' => 'ASC'
245 ) );
246 }
247
248 return $vars;
249 }
250
251 /**
252 * show instructions to create first ad above the ad list
253 *
254 * @return type
255 */
256 public function no_ads_yet_notice(){
257 $screen = get_current_screen();
258 if ( ! isset( $screen->id ) || $screen->id !== 'edit-advanced_ads' ) {
259 return;
260 }
261
262 // get number of ads
263 $existing_ads = Advanced_Ads::get_number_of_ads();
264
265 // only display if there are no more than 2 ads
266 if( 3 > $existing_ads ){
267 echo '<div class="advads-ad-metabox postbox" style="clear: both; margin: 10px 20px 0 2px;">';
268 include ADVADS_BASE_PATH . 'admin/views/ad-list-no-ads.php';
269 echo '</div>';
270 }
271 }
272
273
274 /**
275 * prepare the ad post type to be saved
276 *
277 * @since 1.0.0
278 * @param int $post_id id of the post
279 * @todo handling this more dynamic based on ad type
280 */
281 public function save_ad($post_id) {
282
283 // only use for ads, no other post type
284 if ( ! isset($_POST['post_type']) || $this->post_type != $_POST['post_type'] || ! isset($_POST['advanced_ad']['type']) ) {
285 return;
286 }
287
288 // don’t do this on revisions
289 if ( wp_is_post_revision( $post_id ) ) {
290 return;
291 }
292
293 // get ad object
294 $ad = new Advanced_Ads_Ad( $post_id );
295 if ( ! $ad instanceof Advanced_Ads_Ad ) {
296 return;
297 }
298
299 // filter to allow change of submitted ad settings
300 $_POST['advanced_ad'] = apply_filters( 'advanced-ads-ad-settings-pre-save', $_POST['advanced_ad'] );
301
302 $ad->type = $_POST['advanced_ad']['type'];
303 if ( isset($_POST['advanced_ad']['output']) ) {
304 $ad->set_option( 'output', $_POST['advanced_ad']['output'] );
305 } else {
306 $ad->set_option( 'output', array() );
307 }
308 /**
309 * deprecated since introduction of "visitors" in 1.5.4
310 */
311 if ( isset($_POST['advanced_ad']['visitor']) ) {
312 $ad->set_option( 'visitor', $_POST['advanced_ad']['visitor'] );
313 } else {
314 $ad->set_option( 'visitor', array() );
315 }
316 // visitor conditions
317 if ( isset($_POST['advanced_ad']['visitors']) ) {
318 $ad->set_option( 'visitors', $_POST['advanced_ad']['visitors'] );
319 } else {
320 $ad->set_option( 'visitors', array() );
321 }
322 $ad->url = 0;
323 if ( isset($_POST['advanced_ad']['url']) ) {
324 $ad->url = esc_url( $_POST['advanced_ad']['url'] );
325 }
326 // save size
327 $ad->width = 0;
328 if ( isset($_POST['advanced_ad']['width']) ) {
329 $ad->width = absint( $_POST['advanced_ad']['width'] );
330 }
331 $ad->height = 0;
332 if ( isset($_POST['advanced_ad']['height']) ) {
333 $ad->height = absint( $_POST['advanced_ad']['height'] );
334 }
335
336 if ( ! empty($_POST['advanced_ad']['description']) ) {
337 $ad->description = esc_textarea( $_POST['advanced_ad']['description'] ); }
338 else { $ad->description = ''; }
339
340 if ( ! empty($_POST['advanced_ad']['content']) ) {
341 $ad->content = $_POST['advanced_ad']['content']; }
342 else { $ad->content = ''; }
343
344 if ( ! empty($_POST['advanced_ad']['conditions']) ){
345 $ad->conditions = $_POST['advanced_ad']['conditions'];
346 } else {
347 $ad->conditions = array();
348 }
349 // prepare expiry date
350 if ( isset($_POST['advanced_ad']['expiry_date']['enabled']) ) {
351 $year = absint( $_POST['advanced_ad']['expiry_date']['year'] );
352 $month = absint( $_POST['advanced_ad']['expiry_date']['month'] );
353 $day = absint( $_POST['advanced_ad']['expiry_date']['day'] );
354 $hour = absint( $_POST['advanced_ad']['expiry_date']['hour'] );
355 $minute = absint( $_POST['advanced_ad']['expiry_date']['minute'] );
356
357 $expiration_date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $year, $month, $day, $hour, $minute, '00' );
358 $valid_date = wp_checkdate( $month, $day, $year, $expiration_date );
359
360 if ( !$valid_date ) {
361 $ad->expiry_date = 0;
362 } else {
363 $_gmDate = date_create( $expiration_date, Advanced_Ads_Admin::get_wp_timezone() );
364 $_gmDate->setTimezone( new DateTimeZone( 'UTC' ) );
365 $gmDate = $_gmDate->format( 'Y-m-d-H-i' );
366 list( $year, $month, $day, $hour, $minute ) = explode( '-', $gmDate );
367 $ad->expiry_date = gmmktime($hour, $minute, 0, $month, $day, $year);
368 }
369 } else {
370 $ad->expiry_date = 0;
371 }
372
373 $image_id = ( isset( $_POST['advanced_ad']['output']['image_id'] ) ) ? absint( $_POST['advanced_ad']['output']['image_id'] ) : 0;
374 if ( $image_id ) {
375 $all_posts_id = get_post_meta( $image_id, '_advanced-ads_parent_id' );
376
377 if ( ! in_array ( $post_id, $all_posts_id ) ) {
378 add_post_meta( $image_id, '_advanced-ads_parent_id', $post_id, false );
379 }
380 }
381
382 $ad->save();
383 }
384
385 /**
386 * prepare the ad post type to be removed
387 *
388 * @param int $post_id id of the post
389 */
390 public function delete_ad( $post_id ) {
391 global $wpdb;
392
393 if ( ! current_user_can( 'delete_posts' ) ) {
394 return;
395 }
396
397 if ( $post_id > 0 ) {
398 $post_type = get_post_type( $post_id );
399 if ( $post_type == $this->post_type ) {
400 $wpdb->query(
401 $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %d", '_advanced-ads_parent_id', $post_id )
402 );
403 }
404 }
405 }
406
407 /**
408 * add information above the ad title
409 *
410 * @since 1.5.6
411 * @param obj $post
412 */
413 public function edit_form_above_title($post){
414 if ( ! isset($post->post_type) || $post->post_type != $this->post_type ) {
415 return;
416 }
417
418 // highlight Dummy ad if this is the first ad
419 if( ! Advanced_Ads::get_instance()->get_number_of_ads() ){
420 ?><style>.advanced-ads-type-list-dummy { font-weight: bold; }</style><?php
421 }
422
423
424 $ad = new Advanced_Ads_Ad( $post->ID );
425
426 $placement_types = Advanced_Ads_Placements::get_placement_types();
427 $placements = Advanced_Ads::get_ad_placements_array(); // -TODO use model
428
429 include ADVADS_BASE_PATH . 'admin/views/ad-info-top.php';
430 }
431
432 /**
433 * add information about the ad below the ad title
434 *
435 * @since 1.1.0
436 * @param obj $post
437 */
438 public function edit_form_below_title($post){
439 if ( ! isset($post->post_type) || $post->post_type != $this->post_type ) {
440 return;
441 }
442 $ad = new Advanced_Ads_Ad( $post->ID );
443
444 include ADVADS_BASE_PATH . 'admin/views/ad-info.php';
445 }
446
447 /**
448 * add information below the ad edit form
449 *
450 * @since 1.7.3
451 * @param obj $post
452 */
453 public function edit_form_end($post){
454 if ( ! isset($post->post_type) || $post->post_type != $this->post_type ) {
455 return;
456 }
457
458 include ADVADS_BASE_PATH . 'admin/views/ad-info-bottom.php';
459 }
460
461 /**
462 * add meta values below submit box
463 *
464 * @since 1.3.15
465 */
466 public function add_submit_box_meta(){
467 global $post, $wp_locale;
468
469 if ( $post->post_type !== Advanced_Ads::POST_TYPE_SLUG ) { return; }
470
471 $ad = new Advanced_Ads_Ad( $post->ID );
472
473 // get time set for ad or current timestamp (both GMT)
474 $utc_ts = $ad->expiry_date ? $ad->expiry_date : time();
475 $utc_time = date_create( '@' . $utc_ts );
476 $tz_option = get_option( 'timezone_string' );
477 $exp_time = clone $utc_time;
478
479 if ( $tz_option ) {
480 $exp_time->setTimezone( Advanced_Ads_Admin::get_wp_timezone() );
481 } else {
482 $tz_name = Advanced_Ads_Admin::timezone_get_name( Advanced_Ads_Admin::get_wp_timezone() );
483 $tz_offset = substr( $tz_name, 3 );
484 $off_time = date_create( $utc_time->format( 'Y-m-d\TH:i:s' ) . $tz_offset );
485 $offset_in_sec = date_offset_get( $off_time );
486 $exp_time = date_create( '@' . ( $utc_ts + $offset_in_sec ) );
487 }
488
489 list( $curr_year, $curr_month, $curr_day, $curr_hour, $curr_minute ) = explode( '-', $exp_time->format( 'Y-m-d-H-i' ) );
490 $enabled = 1 - empty($ad->expiry_date);
491
492 include ADVADS_BASE_PATH . 'admin/views/ad-submitbox-meta.php';
493 }
494
495 /**
496 * edit ad update messages
497 *
498 * @since 1.4.7
499 * @param arr $messages existing post update messages
500 * @return arr $messages
501 *
502 * @see wp-admin/edit-form-advanced.php
503 */
504 public function ad_update_messages($messages = array()){
505 $post = get_post();
506
507 // added to hide error message caused by third party code that uses post_updated_messages filter wrong
508 if( ! is_array( $messages )){
509 return $messages;
510 }
511
512 $messages[Advanced_Ads::POST_TYPE_SLUG] = array(
513 0 => '', // Unused. Messages start at index 1.
514 1 => __( 'Ad updated.', 'advanced-ads' ),
515 4 => __( 'Ad updated.', 'advanced-ads' ),
516 /* translators: %s: date and time of the revision */
517 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Ad restored to revision from %s', 'advanced-ads' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
518 6 => __( 'Ad published.', 'advanced-ads' ) . ' ' . sprintf(__( 'Ad not showing up? Take a look <a href="%s" target="_blank">here</a>', 'advanced-ads' ), ADVADS_URL . 'manual/ads-not-showing-up/#utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-ad-not-visible'),
519 7 => __( 'Ad saved.', 'advanced-ads' ),
520 8 => __( 'Ad submitted.', 'advanced-ads' ),
521 9 => sprintf(
522 __( 'Ad scheduled for: <strong>%1$s</strong>.', 'advanced-ads' ),
523 // translators: Publish box date format, see http://php.net/date
524 date_i18n( __( 'M j, Y @ G:i', 'advanced-ads' ), strtotime( $post->post_date ) )
525 ),
526 10 => __( 'Ad draft updated.', 'advanced-ads' )
527 );
528 return $messages;
529 }
530
531 /**
532 * whether to show the wizard welcome message or not
533 *
534 * @since 1.7.4
535 * @return bool true, if wizard welcome message should be displayed
536 */
537 public function show_wizard_welcome(){
538 $user_id = get_current_user_id();
539 if( ! $user_id ) {
540 return true;
541 }
542
543 $hide_wizard = get_user_meta( $user_id, 'advanced-ads-hide-wizard', true );
544 global $post;
545
546 return ( ! $hide_wizard && 'edit' !== $post->filter ) ? true : false;
547 }
548
549 /**
550 * whether to start the wizard by default or not
551 *
552 * @since 1.7.4
553 * return bool true, if wizard should start automatically
554 */
555 public function start_wizard_automatically(){
556 $user_id = get_current_user_id();
557 if( ! $user_id ) {
558 return true;
559 }
560
561 $hide_wizard = get_user_meta( $user_id, 'advanced-ads-hide-wizard', true );
562 global $post;
563
564 // true if the wizard was never started or closed
565 return ( ( ! $hide_wizard && 'edit' !== $post->filter ) || 'false'=== $hide_wizard ) ? true : false;
566 }
567
568 /**
569 * Check if an ad is not valid for 'Post Content' placement
570 *
571 * @param obj $ad Advanced_Ads_Ad object
572 * @return string with error if not valid, empty string if valid
573 */
574 public static function check_ad_dom_is_not_valid( Advanced_Ads_Ad $ad ) {
575 $adContent = ( isset( $ad->content ) ) ? $ad->content : '';
576 if ( ! extension_loaded( 'dom' ) || ! $adContent ) {
577 return false;
578 }
579
580 $wpCharset = get_bloginfo('charset');
581 $adDom = new DOMDocument('1.0', $wpCharset);
582
583 $libxml_previous_state = libxml_use_internal_errors( true );
584 // clear existing errors
585 libxml_clear_errors();
586 // source for this regex: http://stackoverflow.com/questions/17852537/preg-replace-only-specific-part-of-string
587 $adContent = preg_replace('#(document.write.+)</(.*)#', '$1<\/$2', $adContent); // escapes all closing html tags
588 $adDom->loadHtml('<!DOCTYPE html><html><meta http-equiv="Content-Type" content="text/html; charset=' . $wpCharset . '" /><body>' . $adContent);
589
590 $errors = '';
591 foreach( libxml_get_errors() as $_error ) {
592 // continue, if there is '&' symbol, but not HTML entity
593 if ( false === stripos( $_error->message, 'htmlParseEntityRef:' ) ) {
594 $errors .= print_r( $_error, true );
595 }
596 }
597
598 libxml_use_internal_errors( $libxml_previous_state );
599 return $errors;
600 }
601
602 }