PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.8.5
Advanced Ads – Ad Manager & AdSense v1.8.5
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 / class-advanced-ads-admin.php
advanced-ads / admin Last commit date
assets 8 years ago includes 8 years ago views 8 years ago class-advanced-ads-admin.php 8 years ago
class-advanced-ads-admin.php
451 lines
1 <?php
2
3 /**
4 * Advanced Ads.
5 *
6 * @package Advanced_Ads_Admin
7 * @author Thomas Maier <thomas.maier@webgilde.com>
8 * @license GPL-2.0+
9 * @link http://webgilde.com
10 * @copyright 2013-2015 Thomas Maier, webgilde GmbH
11 */
12
13 /**
14 * Plugin class. This class should ideally be used to work with the
15 * administrative side of the WordPress site.
16 *
17 * @package Advanced_Ads_Admin
18 * @author Thomas Maier <thomas.maier@webgilde.com>
19 */
20 class Advanced_Ads_Admin {
21
22 /**
23 * Instance of this class.
24 *
25 * @since 1.0.0
26 * @var object
27 */
28 protected static $instance = null;
29
30 /**
31 * Instance of admin notice class.
32 *
33 * @since 1.5.2
34 * @var object
35 */
36 protected $notices = null;
37
38 /**
39 * Slug of the settings page
40 *
41 * @since 1.0.0
42 * @var string
43 */
44 public $plugin_screen_hook_suffix = null;
45
46 /**
47 * general plugin slug
48 *
49 * @since 1.0.0
50 * @var string
51 */
52 protected $plugin_slug = '';
53
54 /**
55 * Initialize the plugin by loading admin scripts & styles and adding a
56 * settings page and menu.
57 *
58 * @since 1.0.0
59 */
60 private function __construct() {
61 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
62 new Advanced_Ads_Ad_Ajax_Callbacks;
63 add_action( 'plugins_loaded', array( $this, 'wp_plugins_loaded_ajax' ) );
64 } else {
65 add_action( 'plugins_loaded', array( $this, 'wp_plugins_loaded' ) );
66 }
67 // add shortcode creator to TinyMCE
68 Advanced_Ads_Shortcode_Creator::get_instance();
69 Advanced_Ads_Admin_Licenses::get_instance();
70 }
71
72 /**
73 * license handling legacy code after moving license handling code to Advanced_Ads_Admin_Licenses
74 *
75 * @since version 1.7.16 (early January 2017)
76 */
77 public function deactivate_license( $addon = '', $plugin_name = '', $options_slug = '' ){ return Advanced_Ads_Admin_Licenses::get_instance()->deactivate_license( $addon = '', $plugin_name = '', $options_slug = '' ); }
78 public function get_license_status( $slug = '' ){ return Advanced_Ads_Admin_Licenses::get_instance()->get_license_status( $slug = '' ); }
79
80 /**
81 * actions and filter available after all plugins are initialized
82 */
83 public function wp_plugins_loaded() {
84 /*
85 * Call $plugin_slug from public plugin class.
86 *
87 */
88 $plugin = Advanced_Ads::get_instance();
89 $this->plugin_slug = $plugin->get_plugin_slug();
90
91 add_action( 'current_screen', array( $this, 'current_screen' ) );
92
93 // Load admin style sheet and JavaScript.
94 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
95 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 9 );
96
97 // update placements
98 add_action( 'admin_init', array('Advanced_Ads_Placements', 'update_placements') );
99
100 // check for update logic
101 add_action( 'admin_notices', array($this, 'admin_notices') );
102
103 // add links to plugin page
104 add_filter( 'plugin_action_links_' . ADVADS_BASE, array( $this, 'add_plugin_links' ) );
105
106 // display information when user is going to disable the plugin
107 add_filter( 'admin_footer', array( $this, 'add_deactivation_logic' ) );
108 // add_filter( 'after_plugin_row_' . ADVADS_BASE, array( $this, 'display_deactivation_message' ) );
109
110 // disable adding rel="noopener noreferrer" to link added through TinyMCE for rich content ads
111 add_filter( 'tiny_mce_before_init', array( $this, 'tinymce_allow_unsafe_link_target' ) );
112
113 Advanced_Ads_Admin_Meta_Boxes::get_instance();
114 Advanced_Ads_Admin_Menu::get_instance();
115 Advanced_Ads_Admin_Ad_Type::get_instance();
116 Advanced_Ads_Admin_Settings::get_instance();
117 }
118
119 /**
120 * actions and filters that should also be available for ajax
121 */
122 public function wp_plugins_loaded_ajax() {
123 // needed here in order to work with Quick Edit option on ad list page
124 Advanced_Ads_Admin_Ad_Type::get_instance();
125
126 add_action( 'wp_ajax_advads_send_feedback', array( $this, 'send_feedback' ) );
127 add_action( 'wp_ajax_advads_load_rss_widget_content', array( 'Advanced_Ads_Admin_Meta_Boxes', 'dashboard_widget_function_output' ) );
128 }
129
130 /**
131 * Return an instance of this class.
132 *
133 * @since 1.0.0
134 *
135 * @return object A single instance of this class.
136 */
137 public static function get_instance() {
138 // If the single instance hasn't been set, set it now.
139 if ( null == self::$instance ) {
140 self::$instance = new self;
141 }
142
143 return self::$instance;
144 }
145
146 /**
147 * general stuff after page is loaded and screen variable is available
148 */
149 public function current_screen(){
150 $screen = get_current_screen();
151
152 if( !isset( $screen->id ) ){
153 return;
154 }
155
156 switch( $screen->id ){
157 case 'edit-advanced_ads' : // ad overview page
158 case 'advanced_ads' : // ad edit page
159 // remove notice about missing first ad
160 Advanced_Ads_Admin_Notices::get_instance()->remove_from_queue( 'nl_intro' );
161 break;
162 }
163 }
164
165 /**
166 * Register and enqueue admin-specific style sheet.
167 *
168 * @since 1.0.0
169 */
170 public function enqueue_admin_styles() {
171 wp_enqueue_style( $this->plugin_slug . '-admin-styles', plugins_url( 'assets/css/admin.css', __FILE__ ), array(), ADVADS_VERSION );
172 if( self::screen_belongs_to_advanced_ads() ){
173 // jQuery ui smoothness style 1.11.4
174 wp_enqueue_style( $this->plugin_slug . '-jquery-ui-styles', plugins_url( 'assets/jquery-ui/jquery-ui.min.css', __FILE__ ), array(), '1.11.4' );
175 }
176 //wp_enqueue_style( 'jquery-style', '//code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css' );
177 }
178
179 /**
180 * Register and enqueue admin-specific JavaScript.
181 *
182 * @since 1.0.0
183 *
184 * @return null Return early if no settings page is registered.
185 */
186 public function enqueue_admin_scripts() {
187
188 // global js script
189 wp_enqueue_script( $this->plugin_slug . '-admin-global-script', plugins_url( 'assets/js/admin-global.js', __FILE__ ), array('jquery'), ADVADS_VERSION );
190 wp_enqueue_script( $this->plugin_slug . '-admin-find-adblocker', plugins_url( 'assets/js/advertisement.js', __FILE__ ), array(), ADVADS_VERSION );
191
192 if( self::screen_belongs_to_advanced_ads() ){
193 wp_register_script( $this->plugin_slug . '-admin-script', plugins_url( 'assets/js/admin.js', __FILE__ ), array( 'jquery', 'jquery-ui-autocomplete' , 'jquery-ui-button' ), ADVADS_VERSION );
194 wp_register_script( $this->plugin_slug . '-wizard-script', plugins_url( 'assets/js/wizard.js', __FILE__ ), array('jquery'), ADVADS_VERSION );
195
196 // jquery ui
197 wp_enqueue_script( 'jquery-ui-accordion' );
198 wp_enqueue_script( 'jquery-ui-button' );
199 wp_enqueue_script( 'jquery-ui-tooltip' );
200
201 // just register this script for later inclusion on ad group list page
202 wp_register_script( 'inline-edit-group-ads', plugins_url( 'assets/js/inline-edit-group-ads.js', __FILE__ ), array('jquery'), ADVADS_VERSION );
203
204 // register admin.js translations
205 $translation_array = array(
206 'condition_or' => __( 'or', 'advanced-ads' ),
207 'condition_and' => __( 'and', 'advanced-ads' ),
208 'after_paragraph_promt' => __( 'After which paragraph?', 'advanced-ads' ),
209 );
210 wp_localize_script( $this->plugin_slug . '-admin-script', 'advadstxt', $translation_array );
211
212 wp_enqueue_script( $this->plugin_slug . '-admin-script' );
213 wp_enqueue_script( $this->plugin_slug . '-wizard-script' );
214 }
215
216 //call media manager for image upload only on ad edit pages
217 $screen = get_current_screen();
218 if( isset( $screen->id ) && Advanced_Ads::POST_TYPE_SLUG === $screen->id ) {
219 // the 'wp_enqueue_media' function can be executed only once and should be called with the 'post' parameter
220 // in this case, the '_wpMediaViewsL10n' js object inside html will contain id of the post, that is necessary to view oEmbed priview inside tinyMCE editor.
221 // since other plugins can call the 'wp_enqueue_media' function without the 'post' parameter, Advanced Ads should call it earlier.
222 global $post;
223 wp_enqueue_media( array( 'post' => $post ) );
224 }
225
226 }
227
228 /**
229 * check if the current screen belongs to Advanced Ads
230 *
231 * @since 1.6.6
232 * @return bool true if screen belongs to Advanced Ads
233 */
234 static function screen_belongs_to_advanced_ads(){
235
236 if( ! function_exists( 'get_current_screen' ) ){
237 return false;
238 }
239
240 $screen = get_current_screen();
241 //echo $screen->id;
242 if( !isset( $screen->id ) ) {
243 return false;
244 }
245
246 $advads_pages = apply_filters( 'advanced-ads-dashboard-screens', array(
247 'advanced-ads_page_advanced-ads-groups', // ad groups
248 'edit-advanced_ads', // ads overview
249 'advanced_ads', // ad edit page
250 'advanced-ads_page_advanced-ads-placements', // placements
251 'advanced-ads_page_advanced-ads-settings', // settings
252 'toplevel_page_advanced-ads', // overview
253 'admin_page_advanced-ads-debug', // debug
254 'advanced-ads_page_advanced-ads-support', // support
255 'admin_page_advanced-ads-import-export', // import & export
256 ));
257
258 if( in_array( $screen->id, $advads_pages )){
259 return true;
260 }
261
262 return false;
263 }
264
265
266 /**
267 * get action from the params
268 *
269 * @since 1.0.0
270 */
271 public function current_action() {
272 if ( isset($_REQUEST['action']) && -1 != $_REQUEST['action'] ) {
273 return $_REQUEST['action'];
274 }
275
276 return false;
277 }
278
279
280 /**
281 * get DateTimeZone object for the WP installation
282 */
283 public static function get_wp_timezone() {
284 $_time_zone = get_option( 'timezone_string' );
285 $time_zone = new DateTimeZone( 'UTC' );
286 if ( $_time_zone ) {
287 $time_zone = new DateTimeZone( $_time_zone );
288 } else {
289 $gmt_offset = floatval( get_option( 'gmt_offset' ) );
290 $sign = ( 0 > $gmt_offset )? '-' : '+';
291 $int = floor( abs( $gmt_offset ) );
292 $frac = abs( $gmt_offset ) - $int;
293
294 $gmt = '';
295 if ( $gmt_offset ) {
296 $gmt .= $sign . zeroise( $int, 2 ) . ':' . zeroise( 60 * $frac, 2 );
297 $time_zone = date_create( '2017-10-01T12:00:00' . $gmt )->getTimezone();
298 }
299
300 }
301 return $time_zone;
302 }
303
304 /**
305 * get literal expression of timezone
306 */
307 public static function timezone_get_name( $DTZ ) {
308 if ( $DTZ instanceof DateTimeZone ) {
309 $TZ = timezone_name_get( $DTZ );
310 if ( 'UTC' == $TZ ) {
311 return 'UTC+0';
312 }
313 if ( false === strpos( $TZ, '/' ) ) {
314 $TZ = 'UTC' . $TZ;
315 } else {
316 $TZ = sprintf( __( 'time of %s', 'advanced-ads' ), $TZ );
317 }
318 return $TZ;
319 }
320 return 'UTC+0';
321 }
322
323 /**
324 * initiate the admin notices class
325 *
326 * @since 1.5.3
327 */
328 public function admin_notices(){
329 // display ad block warning to everyone who can edit ads
330 if( current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
331 if ( $this->screen_belongs_to_advanced_ads() ){
332 include ADVADS_BASE_PATH . 'admin/views/notices/adblock.php';
333 include ADVADS_BASE_PATH . 'admin/views/notices/jqueryui_error.php';
334 }
335 }
336
337 if( current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads') ) ) {
338 $this->notices = Advanced_Ads_Admin_Notices::get_instance()->notices;
339 Advanced_Ads_Admin_Notices::get_instance()->display_notices();
340 }
341 }
342
343 /**
344 * add links to the plugins list
345 *
346 * @since 1.6.14
347 * @param arr $links array of links for the plugins, adapted when the current plugin is found.
348 * @param str $file the filename for the current plugin, which the filter loops through.
349 * @return array $links
350 */
351 public function add_plugin_links( $links ) {
352 // add link to settings
353 //$settings_link = '<a href="' . admin_url( 'admin.php?page=advanced_ads&page=advanced-ads-settings' ) . '">' . __( 'Settings', 'advanced-ads' ) . '</a>';
354 //array_unshift( $links, $settings_link );
355
356 // add link to support page
357 $support_link = '<a href="' . esc_url( admin_url( 'admin.php?page=advanced-ads-support' ) ) . '">' . __( 'Support', 'advanced-ads' ) . '</a>';
358 array_unshift( $links, $support_link );
359
360 // add link to add-ons
361 $extend_link = '<a href="' . ADVADS_URL . 'add-ons/#utm_source=advanced-ads&utm_medium=link&utm_campaign=plugin-page" target="_blank">' . __( 'Add-Ons', 'advanced-ads' ) . '</a>';
362 array_unshift( $links, $extend_link );
363
364 return $links;
365 }
366
367 /**
368 * display deactivation logic on plugins page
369 *
370 * @since 1.7.14
371 */
372 public function add_deactivation_logic(){
373
374 $screen = get_current_screen();
375 if ( ! isset( $screen->id ) || ! in_array( $screen->id, array( 'plugins', 'plugins-network' ), true ) ) {
376 return;
377 }
378
379 $current_user = wp_get_current_user();
380 if ( !($current_user instanceof WP_User) ){
381 $from = '';
382 $email = '';
383 } else {
384 $from = $current_user->user_nicename . ' <' . trim( $current_user->user_email ) . '>';
385 $email = $current_user->user_email;
386 }
387
388 include ADVADS_BASE_PATH . 'admin/views/feedback-disable.php';
389 }
390
391 /**
392 * send feedback via email
393 *
394 * @since 1.7.14
395 */
396 public function send_feedback(){
397
398 if ( isset( $_POST['formdata'] ) ) {
399 parse_str( $_POST['formdata'], $form );
400 }
401
402 $text = '';
403 if( isset( $form[ 'advanced_ads_disable_text' ] ) ){
404 $text = implode( "\n\r", $form[ 'advanced_ads_disable_text' ] );
405 }
406
407 // get first version to see if this is a new problem or might be an older on
408 $options = Advanced_Ads_Plugin::get_instance()->internal_options();
409 $installed = isset( $options['installed'] ) ? date( 'd.m.Y', $options['installed'] ) : '';
410
411 $text .= "\n\n" . home_url() . " ($installed)";
412
413 $headers = array();
414
415 $from = isset( $form['advanced_ads_disable_from'] ) ? $form['advanced_ads_disable_from'] : '';
416 // if an address is given in the form then use that one
417 if( isset( $form['advanced_ads_disable_reason'] ) && in_array( $form['advanced_ads_disable_reason'], array( 'technical issue', 'get help' ) )
418 && isset( $form[ 'advanced_ads_disable_reply' ] ) && !empty( $form[ 'advanced_ads_disable_reply_email' ] ) ){
419 $from = $current_user->user_nicename . ' <' . trim( $form[ 'advanced_ads_disable_reply_email' ] ) . '>';
420 $text .= "\n\n REPLY ALLOWED";
421 }
422 if( $from ){
423 $headers[] = "From: $from";
424 $headers[] = "Reply-To: $from";
425 }
426
427 $subject = isset( $form['advanced_ads_disable_reason'] ) ? $form['advanced_ads_disable_reason'] : '(no reason given)';
428
429 $success = wp_mail( 'improve@wpadvancedads.com', $subject, $text, $headers );
430
431 die();
432
433 }
434
435 public function tinymce_allow_unsafe_link_target( $mceInit ) {
436
437 // check if we are on the ad edit screen
438 if( ! function_exists( 'get_current_screen' ) ){
439 return $mceInit;
440 }
441
442 $screen = get_current_screen();
443 if( isset( $screen->id ) && $screen->id === 'advanced_ads' ) {
444 $mceInit['allow_unsafe_link_target'] = true;
445 }
446
447 return $mceInit;
448 }
449
450 }
451