This repository has been archived by the owner on Mar 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
adblock-notify.php
441 lines (412 loc) · 13.3 KB
/
adblock-notify.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<?php
/**
* Main plugin loader
*
* @package adblock-notify
*
* Plugin Name: Ad Blocker Notify Lite
* Plugin URI: https://getadmiral.com?utm_medium=plugin&utm_campaign=abn&utm_source=abnlinks
* Description: An ad blocker detection and nofitication plugin with get around options and a lot of settings. Dashboard widget with adblock counter included!
* Version: 2.2.3
* Author: Admiral
* Author URI: https://getadmiral.com?utm_medium=plugin&utm_campaign=abn&utm_source=abnlinks
* Text Domain: an-translate
* Domain Path: /languages
*/
/**
* ************************************************************
* SECURITY : Exit if accessed directly
***************************************************************/
if ( ! defined( 'ABSPATH' ) ) {
die( 'Direct acces not allowed!' );
}
/**
*************************************************************
* Define constants
*/
if ( ! defined( 'AN_PATH' ) ) {
define( 'AN_PATH', plugin_dir_path( __FILE__ ) );
}
if ( ! defined( 'AN_URL' ) ) {
define( 'AN_URL', plugin_dir_url( __FILE__ ) );
}
if ( ! defined( 'AN_BASE' ) ) {
define( 'AN_BASE', plugin_basename( __FILE__ ) );
}
if ( ! defined( 'AN_NAME' ) ) {
define( 'AN_NAME', 'Ad Blocker Notify' );
}
if ( ! defined( 'AN_ID' ) ) {
define( 'AN_ID', 'adblock-notify' );
}
if ( ! defined( 'AN_COOKIE' ) ) {
define( 'AN_COOKIE', 'anCookie' );
}
if ( ! defined( 'AN_VERSION' ) ) {
define( 'AN_VERSION', '2.2.3' );
}
if ( ! defined( 'AN_TEMP_DEVELOPMENT' ) ) {
define( 'AN_TEMP_DEVELOPMENT', false );
}
if ( ! defined( 'AN_TEMPLATES_DIRECTORY' ) ) {
define( 'AN_TEMPLATES_DIRECTORY', 'an-templates/' );
}
if ( ! defined( 'AN_PRO_URL' ) ) {
define( 'AN_PRO_URL', 'https://getadmiral.com?utm_medium=plugin&utm_campaign=abn&utm_source=abnlinks' );
}
/**
* ************************************************************
* Set priority to properly load plugin translation
***************************************************************/
function an_translate_load_textdomain() {
$path = basename( dirname( __FILE__ ) ) . '/languages/';
load_plugin_textdomain( 'an-translate', false, $path );
do_action( 'an_upgrade_routine' );
}
add_action( 'plugins_loaded', 'an_translate_load_textdomain', 1 );
/**
*************************************************************
* Load plugin files
*/
require_once( AN_PATH . 'vendor/titan-framework/titan-framework-embedder.php' );
$anFiles = array(
'adblock-notify-options',
'adblock-notify-functions',
'adblock-notify-widget',
'adblock-notify-files',
'inc/template-functions',
);
$anFiles = apply_filters( 'an_files_include', $anFiles );
foreach ( $anFiles as $anFile ) {
require_once( AN_PATH . $anFile . '.php' );
}
/**
* ************************************************************
* Front-End Scripts & Styles enqueueing
***************************************************************/
function an_enqueue_an_sripts() {
if ( ! is_admin() ) {
if ( an_check_views() ) {
return;
}
$anVersion = AN_VERSION;
$anScripts = unserialize( an_get_option( 'adblocker_notify_selectors' ) );
$an_option = TitanFramework::getInstance( 'adblocker_notify' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
// Load WP_Filesystem API
WP_Filesystem();
global $wp_filesystem;
$content_style = '';
// Disabled due to too many bug repports
// wp_enqueue_script( 'an_fuckadblock', AN_URL . 'js/an-detect.min.js', array( 'jquery' ), NULL, true );
if ( $an_option->getOption( 'an_option_selectors' ) == false ) {
wp_register_script( 'an_scripts', AN_URL . 'js/an-scripts.js', array( 'jquery' ), $anVersion, true );
wp_register_style( 'an_style', AN_URL . 'css/an-style.css', array(), $anVersion, null );
} elseif ( $anScripts['temp-path'] != false ) {
// check if server is SSL
if ( is_ssl() ) {
$anScripts['temp-url'] = preg_replace( '/^http:/i', 'https:', $anScripts['temp-url'] );
}
wp_register_script( 'an_scripts', $anScripts['temp-url'] . $anScripts['files']['js'], array( 'jquery' ), $anVersion, true );
wp_register_style( 'an_style', $anScripts['temp-url'] . $anScripts['files']['css'], array(), $anVersion, null );
$content_style = $wp_filesystem->get_contents( $anScripts['temp-path'] . $anScripts['files']['css'] );
}
if ( $anScripts['temp-path'] == false && $an_option->getOption( 'an_option_selectors' ) == true ) {
// Print Style and script in the footer with an_prepare (functions.php)
// CSS file does not exist anymore
wp_dequeue_style( 'tf-compiled-options-adblocker_notify' );
}
wp_enqueue_script( 'an_scripts' );
wp_enqueue_style( 'an_style' );
$content_style = str_replace( array( "\r\n", "\r", "\n" ), '', $content_style );
wp_add_inline_style( 'an_style', $content_style );
// AJAX
wp_localize_script(
'an_scripts', 'ajax_object', array(
'nonce' => wp_create_nonce( 'an-nonce' ),
'ajaxurl' => admin_url( 'admin-ajax.php' ),
)
);
// CSS file does not exist anymore
if ( $an_option->getOption( 'an_option_selectors' ) == true ) {
wp_dequeue_style( 'tf-compiled-options-adblocker_notify' );
}
}// End if().
}
add_action( 'wp_enqueue_scripts', 'an_enqueue_an_sripts', 100 );
/**
* ************************************************************
* Back-End Styles enqueueing
***************************************************************/
function an_register_global_styles() {
?>
<style type="text/css">
#toplevel_page_adblock-notify img {
padding: 6px 0px !Important;
}
</style>
<?php
}
/**
* ************************************************************
* Back-End Styles enqueueing
***************************************************************/
function an_register_admin_styles() {
require_once( ABSPATH . 'wp-admin/includes/file.php' );
// Load WP_Filesystem API
WP_Filesystem();
global $wp_filesystem;
$content_style = $wp_filesystem->get_contents( AN_PATH . 'css/an-admin-style.css' );
$ttfcss = $wp_filesystem->get_contents( AN_PATH . 'vendor/titan-framework/css/admin-styles.css' );
?>
<style type="text/css">
<?php
echo $content_style;
?>
<?php
echo $ttfcss ;
?>
</style>
<?php
}
/**
* ************************************************************
* Back-End Scripts enqueueing
***************************************************************/
function an_register_admin_scripts() {
// JS
require_once( ABSPATH . 'wp-admin/includes/file.php' );
// Load WP_Filesystem API
WP_Filesystem();
global $wp_filesystem;
$content_script = $wp_filesystem->get_contents( AN_PATH . 'js/an-admin-scripts.js' );
$ttfjs1 = $wp_filesystem->get_contents( AN_PATH . 'vendor/titan-framework/js/admin-styling.js' );
$ttfjs2 = $wp_filesystem->get_contents( AN_PATH . 'vendor/titan-framework/js/min/serialize-min.jss' );
$ttfjs3 = $wp_filesystem->get_contents( AN_PATH . 'vendor/titan-framework/js/min/wp-color-picker-alpha-min.js' );
$ttfjs4 = $wp_filesystem->get_contents( AN_PATH . 'vendor/titan-framework/js/ace-min-noconflict/ace.js' );
$ttfjs5 = $wp_filesystem->get_contents( AN_PATH . 'vendor/titan-framework/js/ace-min-noconflict/theme-chrome.js' );
$ttfjs6 = $wp_filesystem->get_contents( AN_PATH . 'vendor/titan-framework/js/ace-min-noconflict/mode-css.js' );
?>
<script type="text/javascript" id="content_script">
var an_admin =
<?php
echo json_encode(
array(
'pro_url' => AN_PRO_URL,
'pro' => ( an_is_pro() ) ? 'yes' : 'no',
'nonce' => wp_create_nonce( 'an-nonce' ),
)
);
?>
;
<?php
echo $content_script;
?>
</script>
<script type="text/javascript" id="ttfjs1">
<?php
echo $ttfjs1;
?>
</script>
<script type="text/javascript" id="ttfjs2">
<?php
echo $ttfjs2;
?>
</script>
<script type="text/javascript" id="ttfjs3">
try {
<?php
echo $ttfjs3;
?>
} catch (e) {
}
</script>
<script type="text/javascript" id="ttfjs3">
try {
<?php
echo $ttfjs7;
?>
} catch (e) {
}
</script>
<script type="text/javascript" id="ttfjs4">
<?php
echo $ttfjs4;
?>
</script>
<script type="text/javascript" id="ttfjs5">
<?php
echo $ttfjs5;
?>
</script>
<script type="text/javascript" id="ttfjs6">
<?php
echo $ttfjs6;
?>
</script>
<?php
}
/**
* Enqueue admin scripts
*/
function an_enqueue_admin_scripts() {
$prefix = an_is_bussiness() ? '-network' : '';
$screen = get_current_screen();
if ( $screen->id != 'toplevel_page_' . AN_ID . $prefix ) {
return;
}
an_register_admin_scripts();
}
/**
* Enqueue admin scripts
*/
function an_enqueue_admin_syles() {
an_register_global_styles();
$prefix = an_is_bussiness() ? '-network' : '';
$screen = get_current_screen();
if ( $screen && $screen->id != 'toplevel_page_' . AN_ID . $prefix ) {
return;
}
an_register_admin_styles();
}
add_action( 'admin_head', 'an_enqueue_admin_syles' );
add_action( 'admin_footer', 'an_enqueue_admin_scripts' );
/**
* ************************************************************
* Add settings link on plugin list page
***************************************************************/
function an_settings_link_init() {
if ( an_is_bussiness() ) {
add_filter( 'network_admin_plugin_action_links_' . AN_BASE, 'an_settings_link' );
} else {
add_filter( 'plugin_action_links_' . AN_BASE, 'an_settings_link' );
}
}
/**
* ************************************************************
* Add settings link on plugin list page
***************************************************************/
function an_settings_link( $links ) {
$url = an_is_bussiness() ? network_admin_url( 'admin.php' ) : admin_url( 'options-general.php' );
$links[] = '<a href="' . $url . '?page=' . AN_ID . '">' . __( 'Settings', 'an-translate' ) . '</a>';
return $links;
}
add_action( 'plugins_loaded', 'an_settings_link_init' );
/**
* ************************************************************
* Add custom meta link on plugin list page
***************************************************************/
function an_meta_links( $links, $file ) {
if ( $file === 'adblock-notify-by-bweb/adblock-notify.php' ) {
$links[] = '<a href=" https://getadmiral.com?utm_medium=plugin&utm_campaign=abn&utm_source=abnlinks" target="_blank" title="' . __( 'More features', 'an-translate' ) . '">' . __( 'More features', 'an-translate' ) . '</a>';
}
return $links;
}
add_filter( 'plugin_row_meta', 'an_meta_links', 10, 2 );
/**
* ************************************************************
* Admin Panel Favico
***************************************************************/
function an_add_favicon() {
$prefix = an_is_bussiness() ? '-network' : '';
$screen = get_current_screen();
if ( $screen && $screen->id != 'toplevel_page_' . AN_ID . $prefix ) {
return;
}
$favicon_url = AN_URL . 'img/icon-adblock-notify.png';
echo '<link rel="shortcut icon" href="' . $favicon_url . '" />';
an_register_admin_scripts();
}
add_action( 'admin_head', 'an_add_favicon' );
/**
* ************************************************************
* Create random selectors and files on plugin activation
***************************************************************/
function adblocker_notify_activate() {
an_flag_user();
add_action( 'tf_create_options', 'an_create_options' );
an_save_setting_random_selectors();
}
if ( function_exists( 'adblocker_notify_activate' ) ) {
register_activation_hook( __FILE__, 'adblocker_notify_activate' );
}
/**
*************************************************************
* Remove Plugin settings from DB on uninstallation (= plugin deletion)
*/
// Hooks for install
if ( function_exists( 'register_uninstall_hook' ) ) {
register_uninstall_hook( __FILE__, 'adblocker_notify_uninstall' );
}
/**
* Delete the tempoarary folder
*
* @param string $dirPath the path to temp directory.
*/
function an_delete_temp_folder( $dirPath ) {
try {
if ( file_exists( $dirPath ) ) {
$files = glob( $dirPath . '*', GLOB_MARK );
foreach ( $files as $file ) {
if ( is_dir( $file ) ) {
deleteDir( $file );
} else {
unlink( $file );
}
}
rmdir( $dirPath );
}
} catch ( Exception $e ) {
error_log( $e->getMessage() );
}
}
/**
* Uninstall routine
*/
function adblocker_notify_uninstall() {
// Remove temp files
$anTempDir = unserialize( an_get_option( 'adblocker_notify_selectors' ) );
if ( isset( $anTempDir['temp-path'] ) ) {
an_delete_temp_folder( $anTempDir['temp-path'] );
}
// Remove TitanFramework Generated Style
$uploadDir = wp_upload_dir();
$TfCssFile = trailingslashit( $uploadDir['basedir'] ) . 'titan-framework-adblocker_notify-css.css';
if ( file_exists( $TfCssFile ) ) {
unlink( $TfCssFile );
}
// Remove option from DB
an_delete_option( 'adblocker_notify_options' );
an_delete_option( 'adblocker_notify_counter' );
an_delete_option( 'adblocker_notify_selectors' );
}
/**
* Added Freemius support
*
* @return Freemius
*/
function anbb_fs() {
global $anbb_fs;
$check_phpunit = getenv( 'PHPUNIT_RUNNING' );
if ( ! isset( $anbb_fs ) && $check_phpunit != 'yes' ) {
// Include Freemius SDK.
require_once AN_PATH . 'vendor/freemius/wordpress-sdk/start.php';
$anbb_fs = fs_dynamic_init(
array(
'id' => '503',
'slug' => 'adblock-notify-by-bweb',
'type' => 'plugin',
'public_key' => 'pk_80661c61db7cdcbedd0f6461d6a1b',
'is_premium' => false,
'has_addons' => false,
'has_paid_plans' => false,
'menu' => array(
'slug' => 'adblock-notify',
),
)
);
}
return $anbb_fs;
}
// Init Freemius.
anbb_fs();