PluginProbe
WP-Appbox / 4.5.4
WP-Appbox v4.5.4
4.5.13 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.15 4.0.16 4.0.17 4.0.18 4.0.19 4.0.2 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.0.25 4.0.26 4.0.27 4.0.28 4.0.29 4.0.3 4.0.30 4.0.31 All 281 releases
wp-appbox / wp-appbox.php

wp-appbox.php in WP-Appbox 4.5.4, at wp-appbox.php

1,006 lines 33.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WP-Appbox
4 Version: 4.5.4
5 Plugin URI: https://tchgdns.de/wp-appbox-app-badge-fuer-google-play-mac-app-store-windows-store-windows-phone-store-co/
6 Description: With WP-Appbox you can add beautiful mobile app badges to your WordPress posts and pages simply by adding a shortcode.
7 Author: Marcel Schmilgeit
8 Author URI: https://tchgdns.de
9 Text Domain: wp-appbox
10 Domain Path: /lang
11 */
12
13
14 /*
15 Copyright (C) 2012-2024 Marcel Schmilgeit
16
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 2 of the License, or
20 (at your option) any later version.
21
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
26
27 You should have received a copy of the GNU General Public License along
28 with this program; if not, write to the Free Software Foundation, Inc.,
29 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 */
31
32 /* PHP-Fehlerausgabe deaktivieren */
33 //error_reporting( E_ALL );
34 //
35
36 defined( 'ABSPATH' ) or exit( 'Nothing to see here' ); // Exit if accessed directly
37
38
39 /**
40 * Ein paar Variablen
41 */
42 $wpAppboxFirstShortcode = true;
43
44
45 /**
46 * Includierung benötigter Scripte und Dateien
47 *
48 * @since 1.0.0
49 * @change 4.4.0
50 */
51 include_once( "inc/definitions.php" );
52 include_once( "inc/appboxdb.php" );
53 include_once( "inc/imagecache.class.php" );
54 include_once( "inc/getstoreurls.class.php" );
55 if ( is_admin() ) {
56 include_once( 'admin/tinymce.php' );
57 include_once( "admin/settings.php" );
58 if ( isset( $_GET['page'] ) && 'wp-appbox' == $_GET['page'] ) {
59 switch ( isset( $_GET['tab'] ) ) {
60 case 'storeurls':
61 case 'advanced':
62 include_once( "inc/getstoreurls.class.php" );
63 break;
64 case 'cache-list':
65 include_once( "inc/getappinfo.class.php" );
66 include_once( "inc/createoutput.class.php" );
67 break;
68 }
69 }
70 }
71 if ( !is_admin() ) {
72 include_once( "inc/getappinfo.class.php" );
73 include_once( "inc/createattributs.class.php" );
74 include_once( "inc/createoutput.class.php" );
75 }
76
77
78 /**
79 * Laden der Sprachpakete
80 *
81 * @since 1.0.0
82 * @change 4.5.4
83 */
84 function wpAppbox_loadTextdomain() {
85 load_plugin_textdomain( 'wp-appbox', false, basename( dirname( __FILE__ ) ) . '/languages' );
86 }
87 add_action( 'plugins_loaded', 'wpAppbox_loadTextdomain' );
88
89
90 /**
91 * Cron Schedules für den Cache-Cronjob festlegen und Cron registrieren
92 *
93 * @since 4.0.0
94 * @change 4.4.0
95 *
96 * @param ka $schedules ka
97 * @return ka $schedules ka
98 */
99
100 function wpAppbox_cronSchedules( $schedules ) {
101 global $wpAppbox_optionsDefault;
102 $cronIntervall = intval( get_option( 'wpAppbox_cronIntervall' ) );
103 if ( !is_int( $cronIntervall ) || 0 == $cronIntervall )
104 $cronIntervall = $wpAppbox_optionsDefault['cronIntervall'];
105 $schedules["wp_appbox_cache"] = array(
106 'interval' => $cronIntervall * 60,
107 'display' => sprintf( __( 'Every %1$s minutes', 'wp-appbox' ), esc_attr( $cronIntervall ) )
108 );
109 return( $schedules );
110 }
111
112 function wpAppbox_setupCronCache() {
113 if ( wp_get_schedule('wpAppbox_cacheCron' ) )
114 wp_clear_scheduled_hook( 'wpAppbox_cacheCron' );
115 if ( 'cronjob' == get_option( 'wpAppbox_cacheMode' ) )
116 wp_schedule_event( time(), 'wp_appbox_cache', 'wpAppbox_cacheCron' );
117 }
118
119 if ( 'cronjob' == get_option( 'wpAppbox_cacheMode' ) ) {
120 add_filter( 'cron_schedules', 'wpAppbox_cronSchedules' );
121 add_action( 'wpAppbox_cacheCron', 'wpAppbox_cacheCron' );
122 }
123
124
125 /**
126 * Prüfen ob der Nutzer Autor (min. User-Level 2) ist
127 *
128 * @since 2.0.0
129 * @change 4.0.9
130 *
131 * @return boolean true/false TRUE when author
132 */
133
134 function wpAppbox_isUserAuthor() {
135 if ( current_user_can( 'editor' ) || current_user_can( 'author' ) || current_user_can( 'administrator' ) )
136 return( true );
137 else
138 return( false );
139 }
140
141
142 /**
143 * Prüfen ob der Nutzer Admin (min. User-Level 9) ist
144 *
145 * @since 2.0.0
146 * @change 4.0.9
147 *
148 * @return boolean true/false TRUE when admin
149 */
150
151 function wpAppbox_isUserAdmin() {
152 if ( current_user_can( 'administrator' ) )
153 return( true );
154 else
155 return( false );
156 }
157
158
159 /**
160 * Ausgabe der Fehlermeldungen
161 *
162 * @since 2.0.0
163 * @change 4.0.9
164 *
165 * @param string $output Fehlermeldung [optional]
166 * @print error message
167 */
168
169 function wpAppbox_errorOutput( $output = "" ) {
170 if ( !wpAppbox_isUserAdmin() ) return;
171 switch( get_option( "wpAppbox_eOutput" ) ):
172 case 'output':
173 print_r( "<pre>$output</pre>" );
174 break;
175 case 'errorlog':
176 error_log( $output );
177 break;
178 case 'output+errorlog':
179 print_r( "<pre>$output</pre>" );
180 error_log( $output );
181 break;
182 endswitch;
183 }
184
185
186 /**
187 * Prüfen ob "?wpappbox_reload_cache" angehangen
188 *
189 * @since 2.0.0
190 * @change 4.0.7
191 *
192 * @return boolean true/false TRUE when $_GET[]
193 */
194
195 function wpAppbox_forceNewCache( $cacheID ) {
196 if ( !wpAppbox_isUserAuthor() ) return( false );
197 if ( ( isset( $_GET["wpappbox_reload_cache"] ) ) || ( isset( $_GET["action"] ) && $_GET["action"] === 'wpappbox_reload_cache' ) ):
198 if ( !isset( $_GET["app_cache_id"] ) ):
199 return( false );
200 elseif ( $_GET["app_cache_id"] === $cacheID ):
201 return( true );
202 endif;
203 endif;
204 }
205
206
207 /**
208 * Einlesen des Templates
209 *
210 * @since 2.0.0
211 * @change 4.0.5
212 *
213 * @param string $styleName Verwendeter Stil
214 * @param boolean $themeTemplate Deprecated [optional]
215 * @return string $tpl Ausgabe des Banners
216 */
217
218 function wpAppbox_loadTemplate( $styleName, $themeTemplate = false ) {
219 ob_start();
220 if ( file_exists( get_template_directory() . "/wpappbox-$styleName.php" ) ):
221 include( get_template_directory()."/wpappbox-$styleName.php" );
222 elseif ( file_exists( get_template_directory() . "/wpappbox/$styleName.php" ) ):
223 include( get_template_directory()."/wpappbox/$styleName.php" );
224 elseif ( file_exists( plugin_dir_path( __FILE__ ) . "tpl/$styleName.php" ) ):
225 include( "tpl/$styleName.php" );
226 else:
227 return( false );
228 endif;
229 $tpl = ob_get_contents();
230 ob_end_clean();
231 return( $tpl );
232 }
233
234
235 /**
236 * Löscht den Seiten-Cache eines Cache-Plugins
237 *
238 * @since 4.0.0
239 * @change 4.2.0
240 *
241 * @param string $postID ID des Posts
242 */
243
244 function wpAppbox_clearCachePlugin( $postID = '') {
245 global $post;
246 if ( !isset( $post ) ) return( false );
247 $postID = $post->ID;
248 if ( false == get_option( 'wpappbox_cachePlugin' ) || !is_single() || !isset( $postID ) || '' == $postID ) return;
249 switch ( get_option( 'wpappbox_cachePlugin' ) ):
250 case 'cachify':
251 if ( has_action( 'cachify_remove_post_cache' ) ):
252 do_action( 'cachify_remove_post_cache', $postID );
253 endif;
254 break;
255 case 'w3-total-cache':
256 if ( function_exists( 'w3tc_pgcache_flush_post' ) ):
257 w3tc_pgcache_flush_post( $postID );
258 endif;
259 case 'wp-super-cache':
260 if ( function_exists( 'wp_cache_post_change' ) ):
261 $GLOBALS["super_cache_enabled"] = 1;
262 wp_cache_post_change( $postID );
263 endif;
264 break;
265 case 'wp-rocket':
266 if ( function_exists( 'rocket_clean_post' ) ):
267 rocket_clean_post( $postID );
268 endif;
269 break;
270 case 'wp-fastest-cache':
271 if ( isset( $GLOBALS['wp_fastest_cache'] ) && method_exists( $GLOBALS['wp_fastest_cache'], 'singleDeleteCache' ) ):
272 $GLOBALS['wp_fastest_cache']->singleDeleteCache( false, $postID );
273 endif;
274 break;
275 case 'zencache':
276 if ( isset( $GLOBALS['zencache'] ) && method_exists( $GLOBALS['zencache'], 'auto_clear_post_cache' ) ):
277 $GLOBALS['zencache']->auto_clear_post_cache( $postID );
278 endif;
279 break;
280 case 'cache-enabler':
281 if ( has_action( 'ce_clear_post_cache' ) ):
282 do_action( 'ce_clear_post_cache', $postID );
283 endif;
284 break;
285 endswitch;
286 }
287
288
289 /**
290 * Prüfen ob Versionsnummer älter oder neuer
291 *
292 * @since 3.1.6
293 * @change 4.1.13
294 *
295 * @param string $this_ver Zu prüfende Versionsnummer
296 * @param string $com_ver Versionsnummer in der Datenbank
297 * @return boolean true/false TRUE when $this_ver neuer
298 */
299
300 function wpAppbox_checkOlderVersion( $this_ver = '', $comp_ver = '' ) {
301 if ( $this_ver == '' ) $this_ver = WPAPPBOX_PLUGIN_VERSION;
302 if ( $comp_ver == '' ) $comp_ver = get_option( 'wpAppbox_pluginVersion' );
303 if ( $comp_ver == '' ) $comp_ver = $this_ver;
304 if ( version_compare( $this_ver, $comp_ver ) == 1 )
305 return( true );
306 }
307
308
309 /**
310 * Appbox-Banner erstellen und ausgeben
311 *
312 * @since 2.0.0
313 * @change 4.1.2
314 *
315 * @param string $appboxAttributs Attribute des Shortcodes
316 * @param string $content Inhalte des Shortcodes [deprecated]
317 * @return string $output Ausgabe des Banners
318 */
319
320 function wpAppbox_createAppbox( $appboxAttributs, $content = null ) {
321 if ( is_admin() ) return( false );
322 global $wpAppboxFirstShortcode;
323 $runtimeStart = microtime( true );
324 wpAppbox_errorOutput( "//=================================================" );
325 $attr = new wpAppbox_CreateAttributs;
326 $attr = $attr->devideAttributs( $appboxAttributs );
327 wpAppbox_errorOutput( "APP-ID: ".$attr['appid'] );
328 $output = new wpAppbox_CreateOutput;
329 $output = $output->theOutput( $attr );
330 if ( $wpAppboxFirstShortcode ):
331 if ( !get_option('wpAppbox_disableDefer') ):
332 wpAppbox_registerStyle();
333 wpAppbox_loadFonts();
334 endif;
335 $wpAppboxFirstShortcode = false;
336 endif;
337 $runtimeEnd = microtime( true );
338 $runetimeResult = $runtimeEnd - $runtimeStart;
339 wpAppbox_errorOutput( "function: wpAppbox_createAppbox() ---> Runtime: $runetimeResult seconds\n" );
340 wpAppbox_errorOutput( "//=================================================\n\n" );
341 return( $output );
342 }
343
344
345 /**
346 * Store-URLs automatisch erkennen und umwandeln
347 *
348 * @since 3.3.0
349 * @change 4.4.6
350 *
351 * @param string $appboxAttributs Attribute des Shortcodes
352 */
353
354 function wpAppbox_autoDetectLinks( $content ) {
355
356 //Links zum App Store
357 $pattern = array( '/^(?:<p>)?http.?:\/\/.*?apps.apple.com\/(?:.*?\/)?app\/(?:.*?\/)?id([0-9]{1,45}).*?(?:<\/p>)?$/m',
358 '/^(?:<p>)?http.?:\/\/.*?apps.apple.com\/WebObjects\/MZStore\.woa\/wa\/viewSoftware\?id=([0-9]{1,45}).*?(?:<\/p>)?$/m',
359 '/^(?:<p>)?http.?:\/\/.*?itunes.apple.com\/(?:.*?\/)?app\/(?:.*?\/)?id([0-9]{1,45}).*?(?:<\/p>)?$/m',
360 '/^(?:<p>)?http.?:\/\/.*?itunes.apple.com\/WebObjects\/MZStore\.woa\/wa\/viewSoftware\?id=([0-9]{1,45}).*?(?:<\/p>)?$/m'
361 );
362 $content = preg_replace_callback( $pattern, function ( $matches ) {
363 $appID = Trim( $matches[1] );
364 return( '[appbox appstore ' . $appID . ']' );
365 }, $content );
366
367
368 //Links zum Play Store
369 $pattern = '/^(?:<p>)?http.?:\/\/play\.google\.com\/store\/apps\/details(?:\/)?\?id=(.*?)(?:\&.*?)?(?:<\/p>)?$/m';
370 $content = preg_replace_callback( $pattern, function ( $matches ) {
371 $appID = Trim( $matches[1] );
372 return( '[appbox googleplay ' . $appID . ']' );
373 }, $content );
374
375 //Links zum Microsoft Store
376 $pattern = array( '/^(?:<p>)?http.?:\/\/(?:www\.)?microsoft\.com\/.*?\/(?:apps|p)\/.*?\/(.*?)(?:\?.*?)?(?:<\/p>)?$/m',
377 '/^(?:<p>)?http.?:\/\/apps\.microsoft\.com\/store\/detail\/.*?\/(.*?)(?:\?.*?)?(?:<\/p>)?$/m'
378 );
379 $content = preg_replace_callback( $pattern, function ( $matches ) {
380 $appID = Trim( $matches[1] );
381 return( '[appbox microsoftstore ' . $appID . ']' );
382 }, $content );
383
384 //Links zu Edge-Add-Ons
385 $pattern = '/^(?:<p>)?http.?:\/\/microsoftedge\.microsoft\.com\/addons\/detail\/.*?\/(.*?)(?:\?.*?)?(?:\&.*?)?(?:<\/p>)?$/m';
386 $content = preg_replace_callback( $pattern, function ( $matches ) {
387 $appID = Trim( $matches[1] );
388 return( '[appbox edgeaddons ' . $appID . ']' );
389 }, $content );
390
391 //Links zur Huawei App Gallery
392 $pattern = '/^(?:<p>)?http.?:\/\/appgallery\.huawei\.com\/app\/(.*?)(?:\/.*?)?(?:<\/p>)?$/m';
393 $content = preg_replace_callback( $pattern, function ( $matches ) {
394 $appID = Trim( $matches[1] );
395 return( '[appbox appgallery ' . $appID . ']' );
396 }, $content );
397
398 //Links zu Amazon-Apps
399 $pattern = array( '/^(?:<p>)?http.?:\/\/www\.amazon\.*(?:.*?)\/gp\/product\/([A-Za-z0-9]*)(?:.*)(?:<\/p>)?$/m',
400 '/^(?:<p>)?http.?:\/\/www\.amazon\.*(?:.*?)\/dp\/([A-Za-z0-9]*)(?:.*)(?:<\/p>)?$/m',
401 '/^(?:<p>)?http.?:\/\/www\.amazon\.*(?:.*?)\/exec\/obidos\/ASIN\/([A-Za-z0-9]*)(?:.*)(?:<\/p>)?$/m'
402 );
403 $content = preg_replace_callback( $pattern, function ( $matches ) {
404 $appID = Trim( $matches[1] );
405 return( '[appbox amazonapps ' . $appID . ']' );
406 }, $content );
407
408 //Links zu F-Droid
409 $pattern = '/^(?:<p>)?http.?:\/\/f\-droid\.org\/(?:.*\/)packages\/(.*?)\/?(?:<\/p>)?$/m';
410 $content = preg_replace_callback( $pattern, function ( $matches ) {
411 $appID = Trim( $matches[1] );
412 return( '[appbox fdroid ' . $appID . ']' );
413 }, $content );
414
415 //Links zu Firefox-Addons
416 $pattern = '/^(?:<p>)?http.?:\/\/addons\.mozilla\.org\/.*?\/firefox\/addon\/(.*?)(?:\/)?(?:<\/p>)?$/m';
417 $content = preg_replace_callback( $pattern, function ( $matches ) {
418 $appID = Trim( $matches[1] );
419 return( '[appbox firefoxaddon ' . $appID . ']' );
420 }, $content );
421
422 //Links zum Chrome Web Store
423 $pattern = '/^(?:<p>)?http.?:\/\/chrome\.google\.com\/webstore\/detail\/.*?\/(.*?)(?:\?.*?)?(?:\&.*?)?(?:<\/p>)?$/m';
424 $content = preg_replace_callback( $pattern, function ( $matches ) {
425 $appID = Trim( $matches[1] );
426 return( '[appbox chromewebstore ' . $appID . ']' );
427 }, $content );
428
429 //Links zu WordPress Plugins
430 $pattern = '/^(?:<p>)?http.?:\/\/(?:www\.)?wordpress\.org\/plugins\/([A-Za-z0-9-]*)(?:.*)?(?:<\/p>)?$/m';
431 $content = preg_replace_callback( $pattern, function ( $matches ) {
432 $appID = Trim( $matches[1] );
433 return( '[appbox wordpress ' . $appID . ']' );
434 }, $content );
435
436 //Links zu Games von GOG.com
437 $pattern = '/^(?:<p>)?http.?:\/\/(?:www\.)?gog\.com\/game\/([A-Za-z0-9-_]*)(?:.*)?(?:<\/p>)?$/m';
438 $content = preg_replace_callback( $pattern, function ( $matches ) {
439 $appID = Trim( $matches[1] );
440 return( '[appbox gog ' . $appID . ']' );
441 }, $content );
442
443 //Links zu Snapcraft
444 $pattern = '/^(?:<p>)?http.?:\/\/snapcraft\.io\/([A-Za-z0-9-_]*)(?:.*)?(?:<\/p>)?$/m';
445 $content = preg_replace_callback( $pattern, function ( $matches ) {
446 $appID = Trim( $matches[1] );
447 return( '[appbox snapcraft ' . $appID . ']' );
448 }, $content );
449
450 //Links zu Games von Steam
451 $pattern = '/^(?:<p>)?http.?:\/\/store\.steampowered\.com\/app\/([A-Za-z0-9-_]*)(?:.*)?(?:<\/p>)?$/m';
452 $content = preg_replace_callback( $pattern, function ( $matches ) {
453 $appID = Trim( $matches[1] );
454 return( '[appbox steam ' . $appID . ']' );
455 }, $content );
456
457 //Links zu Opera Addons
458 $pattern = '/^(?:<p>)?http.?:\/\/addons\.opera\.com\/(?:.*\/)?extensions\/details\/([A-Za-z0-9-_]*)(?:.*)?(?:<\/p>)?$/m';
459 $content = preg_replace_callback( $pattern, function ( $matches ) {
460 $appID = Trim( $matches[1] );
461 return( '[appbox operaaddons ' . $appID . ']' );
462 }, $content );
463
464 //Post-Content zurückgegen
465 return( $content );
466 }
467 if ( get_option('wpAppbox_autoLinks') ) add_filter( 'the_content', 'wpAppbox_autoDetectLinks', 0 );
468
469
470 /**
471 * Benötigte Update-Funktionen durchführen
472 *
473 * @since 3.1.6
474 * @change 4.5.2
475 */
476
477 wpAppbox_UpdateAction();
478
479 function wpAppbox_UpdateAction() {
480 if ( get_option('wpAppbox_pluginVersion') == WPAPPBOX_PLUGIN_VERSION ) return;
481 if ( wpAppbox_checkOlderVersion( '4.5.2' ) ) {
482 delete_option( 'wpAppbox_userAffiliate' );
483 delete_option( 'wpAppbox_affiliateMicrosoftDev' );
484 delete_option( 'wpAppbox_affiliateMicrosoftProgram' );
485 delete_option( 'wpAppbox_affiliateMicrosoftID' );
486 }
487 if ( wpAppbox_checkOlderVersion( '4.5.0' ) ) {
488 delete_option( 'wpAppbox_amaAPIregion' );
489 delete_option( 'wpAppbox_storeURL_amazon' );
490 delete_option( 'wpAppbox_affiliateAmazonID' );
491 delete_option( 'wpAppbox_affiliateAmazonDev' );
492 update_option( 'wpAppbox_affiliateMicrosoftDev', true, 'no' );
493 }
494 if ( wpAppbox_checkOlderVersion( '4.4.0' ) ) {
495 wpAppbox_setOptions();
496 }
497 if ( wpAppbox_checkOlderVersion( '4.3.6' ) ) {
498 global $wpdb;
499 $sql = "DELETE FROM $wpdb->options WHERE option_name LIKE ('%wpAppbox_%xda%')";
500 $wpdb->query( $sql );
501 $sql = "DELETE FROM wp_appbox WHERE store_name_css LIKE ('%xda%')";
502 $wpdb->query( $sql );
503 }
504 if ( wpAppbox_checkOlderVersion( '4.2.0' ) ) {
505 global $wpdb;
506 wpAppbox_setOptions();
507 wpAppbox_changeStoreName( 'windowsstore', 'microsoftstore', 'Microsoft Store' );
508 wpAppbox_changeStoreName( 'goodoldgames', 'gog', 'GOG.com' );
509 }
510 if ( wpAppbox_checkOlderVersion( '4.1.26' ) ) {
511 wpAppbox_setOptions();
512 delete_option( 'wpAppbox_amaAPIuse' );
513 delete_option( 'wpAppbox_amaAPIsecretKey' );
514 delete_option( 'wpAppbox_amaAPIpublicKey' );
515 delete_option( 'wpAppbox_affiliateAmazonID' );
516 delete_option( 'wpAppbox_amaAPIregion' );
517 }
518 if ( wpAppbox_checkOlderVersion( '4.0.63' ) ) {
519 global $wpdb;
520 $sql = "DELETE FROM $wpdb->options WHERE option_name LIKE ('%wpAppbox_%affiliateApple%')";
521 $wpdb->query( $sql );
522 $sql = "DELETE FROM $wpdb->options WHERE option_name LIKE ('%wpAppbox_%firefoxmarketplace%')";
523 $wpdb->query( $sql );
524 }
525 if ( wpAppbox_checkOlderVersion( '4.0.54' ) ) {
526 global $wpdb;
527 $sql = "DELETE FROM $wpdb->options WHERE option_name LIKE ('%wpAppbox_%firefoxmarketplace%')";
528 $wpdb->query( $sql );
529 $sql = "DELETE FROM wp_appbox WHERE store_name_css LIKE ('%firefoxmarketplace%')";
530 $wpdb->query( $sql );
531 }
532 if ( wpAppbox_checkOlderVersion( '4.0.47' ) ) {
533 switch ( get_option('wpAppbox_imgCacheMode') ):
534 case 'appicon':
535 update_option( 'wpAppbox_imgCacheMode', array( 'appicon' ), 'no' );
536 break;
537 case 'screenshots':
538 update_option( 'wpAppbox_imgCacheMode', array( 'screenshots' ), 'no' );
539 break;
540 case 'appicon+screenshots':
541 update_option( 'wpAppbox_imgCacheMode', array( 'appicon', 'screenshots' ), 'no' );
542 break;
543 endswitch;
544 }
545 if ( wpAppbox_checkOlderVersion( '4.0.45' ) ) {
546 delete_option( 'wpAppbox_cacheCronjob' );
547 }
548 if ( wpAppbox_checkOlderVersion( '4.0.42' ) ) {
549 if ( get_option( 'wpAppbox_disableCSS' ) )
550 update_option( 'wpAppbox_includeCSS', 1, 'no' );
551 else
552 update_option( 'wpAppbox_includeCSS', 0, 'no' );
553 delete_option( 'wpAppbox_disableCSS' );
554 }
555 if ( wpAppbox_checkOlderVersion( '4.0.36' ) ) {
556 if ( !get_option( 'wpAppbox_storeURL_steam' ) )
557 update_option( 'wpAppbox_storeURL_steam', '1', 'no' );
558 }
559 if ( wpAppbox_checkOlderVersion( '4.0.30' ) ) {
560 global $wpdb;
561 $wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE ('%wpAppbox_blockQuery_%')" );
562 }
563 if ( wpAppbox_checkOlderVersion( '4.0.18' ) ) {
564 if ( !get_option('wpAppbox_affiliateApple') )
565 update_option( 'wpAppbox_affiliateAppleDev', true, 'no' );
566 if ( !get_option('wpAppbox_affiliateAmazon') )
567 update_option( 'wpAppbox_affiliateAmazonDev', true, 'no' );
568 if ( !get_option('wpAppbox_affiliateMicrosoft') )
569 update_option( 'wpAppbox_affiliateMicrosoftDev', true, 'no' );
570 }
571 if ( wpAppbox_checkOlderVersion( '4.0.15' ) )
572 wpAppbox_setOptions();
573 if ( wpAppbox_checkOlderVersion( '4.0.10' ) )
574 delete_option( 'wpAppbox_iTunesGeo' );
575 if ( wpAppbox_checkOlderVersion( '4.0.9' ) )
576 wpAppbox_autoLanguageStoreURLs();
577 if ( wpAppbox_checkOlderVersion( '4.0.7' ) ) {
578 if ( get_option('wpAppbox_sslAppleImages') )
579 update_option( 'wpAppbox_forceSSL', true, 'no' );
580 else
581 update_option( 'wpAppbox_forceSSL', false, 'no' );
582 delete_option( 'wpAppbox_sslAppleImages' );
583 delete_option( 'wpAppbox_eImageApple' );
584 }
585 if ( wpAppbox_checkOlderVersion( '4.0.0' ) ) {
586 global $wpdb;
587 $whereQuery = "option_name = 'wpAppbox_pluginVersion'";
588 $whereQuery .= " OR option_name = 'wpAppbox_cacheTime'";
589 $whereQuery .= " OR option_name = 'wpAppbox_disableDefer'";
590 $whereQuery .= " OR option_name = 'wpAppbox_dbVersion'";
591 $whereQuery .= " OR option_name = 'wpAppbox_pluginVersion'";
592 $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->options SET autoload = 'yes' WHERE $whereQuery" ) );
593 delete_option( 'wpAppbox_disableAutoCache' );
594 delete_option( 'wpAppbox_disableCache' );
595 delete_option( 'wpAppbox_showReload' );
596 delete_option( 'wpAppbox_imageCache' );
597 delete_option( 'wpAppbox_imageCacheMode' );
598 if ( true == get_option('wpAppbox_eOutput') )
599 update_option( 'wpAppbox_eOutput', 'output', 'no' );
600 wpAppbox_setOptions();
601 wpAppbox_createTable();
602 }
603 /* Grundsätzlich nach Update zu prüfen */
604 if ( get_option('wpAppbox_dbVersion') != WPAPPBOX_DB_VERSION )
605 wpAppbox_createTable();
606 /* Neue Versionsnummer in die Datenbank schreiben */
607 update_option( "wpAppbox_pluginVersion", WPAPPBOX_PLUGIN_VERSION );
608 }
609
610
611 /**
612 * Neue Optionen in wp_options ($wpdb->options) einfügen
613 *
614 * @since 3.1.6
615 * @change 4.0.9
616 */
617
618 function wpAppbox_setOptions() {
619 global $wpAppbox_optionsDefault, $wpAppbox_storeNames;
620 foreach ( $wpAppbox_optionsDefault as $key => $value ):
621 $key = 'wpAppbox_'.$key;
622 if ( false === get_option( $key ) ) update_option( $key, $value, 'no' );
623 endforeach;
624 foreach ( $wpAppbox_storeNames as $storeID => $storeName ):
625 $key_buttonAppbox = "wpAppbox_buttonAppbox_$storeID";
626 $key_buttonWYSIWYG = "wpAppbox_buttonWYSIWYG_$storeID";
627 $key_buttonHTML = "wpAppbox_buttonHTML_$storeID";
628 $key_buttonHidden = "wpAppbox_buttonHidden_$storeID";
629 $key_storeURL = "wpAppbox_storeURL_$storeID";
630 $key_storeURL_URL = "wpAppbox_storeURL_URL_$storeID";
631 if ( false === get_option( $key_buttonWYSIWYG ) ) update_option( $key_buttonWYSIWYG, true, 'no' );
632 if ( false === get_option( $key_buttonHTML ) ) update_option( $key_buttonHTML, true, 'no' );
633 if ( false === get_option( $key_storeURL ) ) update_option( $key_storeURL, intval( "1" ), 'no' );
634 if ( false === get_option( $key_storeURL_URL ) ) update_option( $key_storeURL_URL, "", 'no' );
635 endforeach;
636 update_option( "wpAppbox_pluginVersion", WPAPPBOX_PLUGIN_VERSION );
637 }
638
639
640 /**
641 * Automatische Erkennung der Sprache bei Neuinstallation
642 *
643 * @since 4.0.9
644 */
645
646 function wpAppbox_autoLanguageStoreURLs() {
647 if ( false !== get_option( 'wpAppbox_pluginVersion' ) ) return;
648 global $wpAppbox_storeNames, $wpAppbox_storeURL_languages, $wpAppbox_storeURL_noLanguages, $wpAppbox_storeURL;
649 foreach ( $wpAppbox_storeNames as $storeID => $storeName ):
650 if ( in_array( $storeID, $wpAppbox_storeURL_noLanguages ) ) continue;
651 if ( false !== get_option( $key_storeURL ) ) continue;
652 $key_storeURL = "wpAppbox_storeURL_$storeID";
653 $blogLanguage = get_bloginfo( 'language' );
654 foreach( $wpAppbox_storeURL_languages as $languageID => $languageNameCode ):
655 if ( strtolower( $languageNameCode['code'] ) == strtolower( $blogLanguage ) ) $languageCode = $languageID;
656 endforeach;
657 if ( !empty( $wpAppbox_storeURL[$storeID][$languageCode] ) ) update_option( $key_storeURL, intval( $languageCode ), 'no' );
658 endforeach;
659 }
660
661
662 /**
663 * Registrierung des Gutenberg-Blocks
664 *
665 * @since 4.1.0
666 * @change 4.4.12
667 */
668
669 function wpAppbox_registerGutenbergBlock() {
670 if ( !function_exists( 'register_block_type' ) ) { return; }
671 wp_register_script(
672 'wp-appbox-block',
673 plugins_url( 'editor/gutenberg/block.js?ver=' . WPAPPBOX_PLUGIN_VERSION, __FILE__ ),
674 array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-plugins', 'wp-components', 'wp-edit-post', 'wp-api', 'wp-editor', 'wp-hooks' )
675 );
676 if ( function_exists( 'wp_set_script_translations' ) )
677 wp_set_script_translations( 'wp-appbox-block', 'wp-appbox', plugin_dir_path( __FILE__ ) . 'lang' );
678 if ( get_option('wpAppbox_renderGutenberg') ):
679 wp_register_style(
680 'wp-appbox-block-style',
681 plugins_url( 'css/styles.min.css', __FILE__ ),
682 array( 'wp-edit-blocks' ),
683 WPAPPBOX_PLUGIN_VERSION
684 );
685 endif;
686 register_block_type( 'wp-appbox/appbox', array(
687 'attributes' => array(
688 'appID' => array( 'type' => 'string' ),
689 'storeID' => array( 'type' => 'string' ),
690 'style' => array( 'type' => 'string' )
691 ),
692 'editor_script' => 'wp-appbox-block',
693 'editor_style' => 'wp-appbox-block-style',
694 'render_callback' => 'wpAppbox_renderGutenberg'
695 ) );
696 }
697 add_action( 'init', 'wpAppbox_registerGutenbergBlock' );
698
699
700 /**
701 * Gutenberg-Vorschau direkt im Editor rendern (oder auch nicht)
702 *
703 * @since 4.1.0
704 * @change n/a
705 */
706
707 function wpAppbox_renderGutenberg( $attributes ) {
708 if ( !get_option('wpAppbox_renderGutenberg') && !is_preview() ) {
709 $theShortcode = '';
710 if ( $attributes[ 'style' ] != '' ) $theShortcode .= ' ' . $attributes[ 'style' ];
711 if ( $attributes[ 'storeID' ] != '' ) $theShortcode .= ' ' . $attributes[ 'storeID' ];
712 if ( $attributes[ 'appID' ] != '' ) $theShortcode .= ' ' . $attributes[ 'appID' ];
713 return( '<div class="wp-block-shortcode wp-block-appbox"><label><img src="' . plugins_url( 'editor/tinymce/appbox.btn.png', __FILE__ ) . '" class="dashicon dashicons-shortcode" aria-hidden="true" width="20" height="20" />WP-Appbox</label><textarea class="editor-plain-text input-control" id="blocks-shortcode-input-1" rows="1" style="overflow: hidden; word-wrap: break-word; resize: none; height: 37px;" disabled>[appbox' . $theShortcode . ']</textarea></div>' );
714 }
715 else {
716 return( wpAppbox_createAppbox( $attributes ) );
717 }
718 }
719
720
721 /**
722 * "Einstellungen"-Link zur Plugin-Liste hinzufügen
723 *
724 * @since 2.0.0
725 * @change 4.0.9
726 *
727 * @param array $links Array der eingetragenen Links [WordPress]
728 * @param string $file Aufgerufene Datei [WordPress]
729 * @return array $links Rückgabe der überarbeiteten Links [WordPress]
730 */
731
732 function wpAppbox_addSettings( $links, $file ) {
733 static $this_plugin;
734 if ( !$this_plugin ) $this_plugin = plugin_basename( __FILE__ );
735 if ( $file == $this_plugin ):
736 $settings_link = '<a href="options-general.php?page=wp-appbox">' . esc_html__('Settings', 'wp-appbox') . '</a>';
737 $links = array_merge( array( $settings_link ), $links );
738 endif;
739 return( $links );
740 }
741
742
743 function wpAppbox_addMenuAdminbar() {
744 global $wp_admin_bar;
745 $menu_id = 'wp-appbox';
746 $wp_admin_bar->add_menu( array( 'id' => $menu_id, 'title' => __( 'WP-Appbox' ), 'href' => '/options-general.php?page=wp-appbox' ) );
747 $wp_admin_bar->add_menu( array( 'parent' => $menu_id, 'title' => __( 'Homepage' ), 'id' => 'dwb-home', 'href' => '/options-general.php?page=wp-appbox' ) );
748 }
749
750 //add_action('admin_bar_menu', 'wpAppbox_addMenuAdminbar', 2000);
751
752
753 function wpAppbox_addMenuSidebar() {
754 add_menu_page( 'Über', 'WP-Appbox', 'manage_options', 'wp-appbox', 'sd_display_top_level_menu_page', '', 6 );
755 add_submenu_page( 'wp-appbox', 'Editor Buttons', 'Editor Buttons', 'manage_options', 'wp-appbox&tab=buttons', 'sd_display_sub_menu_page' );
756 }
757
758 //add_action( 'admin_menu', 'wpAppbox_addMenuSidebar' );
759
760
761
762
763
764
765 /**
766 * Weitere Links zur Plugin-Beschreibung in der Liste hinzufügen
767 *
768 * @since 2.0.0
769 * @change 4.4.0
770 *
771 * @param array $links Array der eingetragenen Links [WordPress]
772 * @param string $file Aufgerufene Datei [WordPress]
773 * @return array $links Rückgabe der überarbeiteten Links [WordPress]
774 */
775
776 function wpAppbox_addLinks( $links, $file ) {
777 static $this_plugin;
778 if ( !$this_plugin ) {
779 $this_plugin = plugin_basename( __FILE__ );
780 }
781 if ( $file == $this_plugin ) {
782 $links = array();
783 $links[] = 'Version '.WPAPPBOX_PLUGIN_VERSION;
784 $links[] = '<a target="_blank" href="https://mastodon.social/@marcelismus">' . esc_html__('Follow me on Mastodon', 'wp-appbox') . '</a>';
785 $links[] = '<a target="_blank" href="' . ( ( get_locale() == 'de_DE' ) ? 'https://tchgdns.de/wp-appbox-app-badge-fuer-google-play-mac-app-store-windows-store-windows-phone-store-co/' : 'https://translate.google.de/translate?hl=de&sl=de&tl=en&u=https%3A%2F%2Ftchgdns.de%2Fwp-appbox-app-badge-fuer-google-play-mac-app-store-windows-store-windows-phone-store-co%2F' ) . '">' . esc_html__('Plugin page', 'wp-appbox') . '</a>';
786 $links[] = '<a target="_blank" href="http://wordpress.org/support/view/plugin-reviews/wp-appbox">' . esc_html__('Rate the plugin', 'wp-appbox') . '</a>';
787 $links[] = '<a target="_blank" href="http://www.amazon.de/gp/registry/wishlist/1FC2DA2J8SZW7">' . esc_html__('My Amazon Wishlist', 'wp-appbox') . '</a>';
788 $links[] = '<a target="_blank" href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SH9AAS276RAS6">' . esc_html__('PayPal-Donation', 'wp-appbox') . '</a>';
789 }
790 return( $links );
791 }
792
793
794 /**
795 * Ausgabe von Fehlermeldungen
796 *
797 * @since 2.0.0
798 * @change 3.2.0
799 *
800 * @param string $message Fehlermeldung
801 */
802
803 function br_trigger_error( $message ) {
804 if ( isset( $_GET['action'] ) && $_GET['action'] == 'error_scrape' ) {
805 echo( "<strong>" . esc_html( $message ) . "</strong>" );
806 exit;
807 } else {
808 trigger_error( $message, E_USER_ERROR );
809 }
810 }
811
812
813 /**
814 * Aktivierung des Plugins
815 *
816 * @since 2.0.0
817 * @change 4.0.15
818 */
819
820 function wpAppbox_activatePlugin( $network_wide ) {
821 if ( version_compare( phpversion(), WPAPPBOX_MIN_PHPVERSION ) == -1 ) br_trigger_error( esc_html__( 'To use this plugin requires at least PHP version ' . WPAPPBOX_MIN_PHPVERSION . ' is required.', 'wp-appbox' ) );
822 if ( !function_exists('curl_init') ) br_trigger_error( esc_html__( '"cURL" is disabled on this server, but is required. Please enable this feature (or contact your hoster).', 'wp-appbox' ) );
823 if ( !function_exists('curl_exec') ) br_trigger_error( esc_html__( '"curl_exec" is disabled on this server, but is required. Please enable this feature (or contact your hoster).', 'wp-appbox' ) );
824 if ( !function_exists('json_decode') ) br_trigger_error( esc_html__( '"json_decode" is disabled on this server, but is required. Please enable this feature (or contact your hoster).', 'wp-appbox' ) );
825 if ( function_exists( 'is_multisite' ) && is_multisite() && $network_wide ) {
826 global $wpdb;
827 $current_blog = $wpdb->blogid;
828 $blogs = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
829 foreach ( $blogs as $blog ):
830 switch_to_blog( $blog );
831 wpAppbox_activateActions();
832 endforeach;
833 switch_to_blog( $current_blog );
834 } else wpAppbox_activateActions();
835 }
836
837
838 /**
839 * Aktivierung-Actions des Plugins
840 *
841 * @since 3.2.7
842 * @change 4.0.9
843 */
844
845 function wpAppbox_activateActions() {
846 wpAppbox_autoLanguageStoreURLs(); /* Standard-URLs für die Stores festlegen */
847 wpAppbox_setOptions(); /* Standard-Einstellungen in wp_options schreiben */
848 wpAppbox_createTable(); /* Tabelle für "WP-Appbox" erstellen */
849 wpAppbox_setupCronCache();
850 }
851
852
853 /**
854 * Deinstallation des Plugins
855 *
856 * @since 2.0.0
857 * @change 4.0.9
858 */
859
860 function wpAppbox_uninstallPlugin() {
861 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
862 global $wpdb;
863 $current_blog = $wpdb->blogid;
864 $blogs = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
865 foreach ( $blogs as $blog ):
866 switch_to_blog( $blog );
867 wpAppbox_uninstallActions();
868 endforeach;
869 switch_to_blog( $current_blog );
870 } else wpAppbox_uninstallActions();
871 }
872
873
874 /**
875 * Deinstallation-Actions des Plugins
876 *
877 * @since 3.2.2
878 * @change 4.0.0
879 */
880
881 function wpAppbox_uninstallActions() {
882 global $wpdb;
883 $wpdb->query( "DELETE FROM " . $wpdb->prefix . "options WHERE option_name LIKE 'wpAppbox_%';" );
884 delete_option( "wpAppbox" ); //Für ältere Versionen ==> bis 3.1.6
885 wp_clear_scheduled_hook( 'wpAppbox_cacheCron' );
886 wpAppbox_deleteTable();
887 $delete = wpAppbox_imageCache::deleteImageCache( true );
888 }
889
890
891 /**
892 * Deaktivierung des Plugins
893 *
894 * @since 4.0.0
895 */
896
897 function wpAppbox_deactivatePlugin() {
898 if ( function_exists( 'is_multisite' ) && is_multisite() ) {
899 global $wpdb;
900 $current_blog = $wpdb->blogid;
901 $blogs = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
902 foreach ( $blogs as $blog ) {
903 switch_to_blog( $blog );
904 wpAppbox_deactivateActions();
905 }
906 switch_to_blog( $current_blog );
907 } else wpAppbox_deactivateActions();
908 }
909
910
911 /**
912 * Deaktivierungs-Actions des Plugins
913 *
914 * @since 4.0.0
915 */
916
917 function wpAppbox_deactivateActions() {
918 wp_clear_scheduled_hook( 'wpAppbox_cacheCron' );
919 }
920
921
922 /**
923 * Aktivierung für neue Multisite-Blogs nach Plugin-Aktivierung
924 *
925 * @since 3.2.7
926 */
927
928 function wpAppbox_activateBlogMultisite( $blogID ) {
929 global $wpdb;
930 if ( is_plugin_active_for_network('wp-appbox/wp-appbox.php') ) {
931 switch_to_blog( $blogID );
932 my_plugin_activate();
933 restore_current_blog();
934 }
935 }
936 add_action( 'wpmu_new_blog', 'wpAppbox_activateBlogMultisite' );
937
938
939 /**
940 * Stylesheet des Plugins registrieren
941 *
942 * @since 2.0.0
943 * @change 4.0.42
944 */
945
946 function wpAppbox_registerStyle() {
947 wp_register_style( 'wpappbox', plugins_url( 'css/styles.min.css', __FILE__ ), array(), WPAPPBOX_PLUGIN_VERSION, 'screen' );
948 switch ( get_option('wpAppbox_includeCSS') ):
949 case 1: //Disable CSS
950 break;
951 case 2: //Only on posts and pages
952 if ( is_singular() ) wp_enqueue_style( 'wpappbox' );
953 break;
954 default: //Default
955 wp_enqueue_style( 'wpappbox' );
956 break;
957 endswitch;
958 }
959
960
961 /**
962 * Google Fonts für das Plugin registrieren
963 *
964 * @since 2.0.0
965 * @change 4.0.42
966 */
967
968 function wpAppbox_loadFonts() {
969 if ( get_option('wpAppbox_disableFonts') == false ) {
970 wp_register_style( 'open-sans', '//fonts.googleapis.com/css?family=Open+Sans:400,600' );
971 switch ( get_option('wpAppbox_includeCSS') ):
972 case 1: //Disable CSS
973 break;
974 case 2: //Only on posts and pages
975 if ( is_singular() ) wp_enqueue_style( 'open-sans' );
976 break;
977 default: //Default
978 wp_enqueue_style( 'open-sans' );
979 break;
980 endswitch;
981 }
982 }
983
984
985 /* Diverse Filter, Aktionen und Hooks registrieren */
986 add_filter( 'plugin_action_links', 'wpAppbox_addSettings', 10, 2 );
987 add_filter( 'plugin_row_meta', 'wpAppbox_addLinks', 10, 2 );
988 add_action( 'plugins_loaded', 'wpAppbox_UpdateAction' );
989 add_action( 'admin_menu', 'wpAppbox_pageInit' );
990 register_activation_hook( __FILE__, 'wpAppbox_activatePlugin' );
991 register_deactivation_hook( __FILE__, 'wpAppbox_deactivatePlugin' );
992 register_uninstall_hook( __FILE__, 'wpAppbox_uninstallPlugin' );
993
994
995 /* Stylesheet und Font auf den normalen Weg laden */
996 if ( get_option('wpAppbox_disableDefer') ) {
997 add_action( 'wp_enqueue_scripts', 'wpAppbox_registerStyle' );
998 add_action( 'wp_print_styles', 'wpAppbox_loadFonts' );
999 }
1000
1001
1002 /* DER Shortcode */
1003 add_shortcode( 'appbox', 'wpAppbox_createAppbox' );
1004
1005
1006 ?>