PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / 1.8.9
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin v1.8.9
trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 All 71 releases
pdf-print / bws_menu / bws_functions.php

bws_functions.php in PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin 1.8.9, at bws_menu/bws_functions.php

1,543 lines 71.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * General functions for BestWebSoft plugins
4 */
5
6 /* Internationalization, first(!) */
7 load_plugin_textdomain( 'bestwebsoft', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
8
9 /**
10 * Function add BWS Plugins page - for old plugin version
11 * @deprecated 1.7.9
12 */
13 if ( ! function_exists ( 'bws_add_general_menu' ) ) {
14 function bws_add_general_menu() {
15 bws_general_menu();
16 }
17 }
18
19 /**
20 * Function add BWS Plugins page
21 * @return void
22 */
23 if ( ! function_exists ( 'bws_general_menu' ) ) {
24 function bws_general_menu() {
25 global $menu, $bws_general_menu_exist;
26
27 if ( ! $bws_general_menu_exist ) {
28 /* we check also menu exist in global array as in old plugins $bws_general_menu_exist variable not exist */
29 foreach ( $menu as $value_menu ) {
30 if ( 'bws_panel' == $value_menu[2] ) {
31 $bws_general_menu_exist = true;
32 return;
33 }
34 }
35
36 add_menu_page( 'BWS Panel', 'BWS Panel', 'manage_options', 'bws_panel', 'bws_add_menu_render', plugins_url( 'images/bestwebsoft-logo-white.svg', __FILE__ ), '2.1' );
37
38 add_submenu_page( 'bws_panel', __( 'Plugins', 'bestwebsoft' ), __( 'Plugins', 'bestwebsoft' ), 'manage_options', 'bws_panel', 'bws_add_menu_render' );
39 add_submenu_page( 'bws_panel', __( 'Themes', 'bestwebsoft' ), __( 'Themes', 'bestwebsoft' ), 'manage_options', 'bws_themes', 'bws_add_menu_render' );
40 add_submenu_page( 'bws_panel', __( 'System Status', 'bestwebsoft' ), __( 'System Status', 'bestwebsoft' ), 'manage_options', 'bws_system_status', 'bws_add_menu_render' );
41
42 $bws_general_menu_exist = true;
43 }
44 }
45 }
46
47 /**
48 * Function check if plugin is compatible with current WP version - for old plugin version
49 * @deprecated 1.7.4
50 */
51 if ( ! function_exists ( 'bws_wp_version_check' ) ) {
52 function bws_wp_version_check( $plugin_basename, $plugin_info, $require_wp ) {
53 bws_wp_min_version_check( $plugin_basename, $plugin_info, '3.8' , $require_wp );
54 }
55 }
56
57 /**
58 * Function check if plugin is compatible with current WP version
59 * @return void
60 */
61 if ( ! function_exists ( 'bws_wp_min_version_check' ) ) {
62 function bws_wp_min_version_check( $plugin_basename, $plugin_info, $require_wp, $min_wp = false ) {
63 global $wp_version, $bws_versions_notice_array;
64 if ( false == $min_wp )
65 $min_wp = $require_wp;
66 if ( version_compare( $wp_version, $min_wp, "<" ) ) {
67 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
68 if ( is_plugin_active( $plugin_basename ) ) {
69 deactivate_plugins( $plugin_basename );
70 $admin_url = ( function_exists( 'get_admin_url' ) ) ? get_admin_url( null, 'plugins.php' ) : esc_url( '/wp-admin/plugins.php' );
71 wp_die(
72 sprintf(
73 "<strong>%s</strong> %s <strong>WordPress %s</strong> %s <br /><br />%s <a href='%s'>%s</a>.",
74 $plugin_info['Name'],
75 __( 'requires', 'bestwebsoft' ),
76 $require_wp,
77 __( 'or higher, that is why it has been deactivated! Please upgrade WordPress and try again.', 'bestwebsoft' ),
78 __( 'Back to the WordPress', 'bestwebsoft' ),
79 $admin_url,
80 __( 'Plugins page', 'bestwebsoft' )
81 )
82 );
83 }
84 } elseif ( version_compare( $wp_version, $require_wp, "<" ) ) {
85 $bws_versions_notice_array[] = array( 'name' => $plugin_info['Name'], 'version' => $require_wp );
86 }
87 }
88 }
89
90 if ( ! function_exists( 'bws_admin_notices' ) ) {
91 function bws_admin_notices() {
92 global $bws_versions_notice_array, $bws_plugin_banner_to_settings;
93
94 /* versions notice */
95 if ( ! empty( $bws_versions_notice_array ) ) {
96 foreach ( $bws_versions_notice_array as $key => $value ) { ?>
97 <div class="update-nag"><?php
98 echo sprintf(
99 "<strong>%s</strong> %s <strong>WordPress %s</strong> %s",
100 $value['name'],
101 __( 'requires', 'bestwebsoft' ),
102 $value['version'],
103 __( 'or higher! We do not guarantee that our plugin will work correctly. Please upgrade to WordPress latest version.', 'bestwebsoft' )
104 );
105 ?></div>
106 <?php }
107 }
108
109 /* banner_to_settings notice */
110 if ( ! empty( $bws_plugin_banner_to_settings ) ) {
111 if ( 1 == count( $bws_plugin_banner_to_settings ) ) { ?>
112 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
113 <div class="bws_banner_on_plugin_page bws_banner_to_settings">
114 <div class="icon">
115 <img title="" src="<?php echo esc_attr( $bws_plugin_banner_to_settings[0]['banner_url'] ); ?>" alt="" />
116 </div>
117 <div class="text">
118 <strong><?php _e( 'Thank you for installing', 'bestwebsoft' ); ?> <?php echo $bws_plugin_banner_to_settings[0]['plugin_info']['Name']; ?> plugin!</strong><br />
119 <?php _e( "Let's get started", 'bestwebsoft' ); ?>:
120 <a href="<?php echo $bws_plugin_banner_to_settings[0]['settings_url']; ?>"><?php _e( 'Settings', 'bestwebsoft' ); ?></a>
121 <?php if ( false != $bws_plugin_banner_to_settings[0]['post_type_url'] ) { ?>
122 <?php _e( 'or', 'bestwebsoft' ); ?>
123 <a href="<?php echo $bws_plugin_banner_to_settings[0]['post_type_url']; ?>"><?php _e( 'Add New', 'bestwebsoft' ); ?></a>
124 <?php } ?>
125 </div>
126 <form action="" method="post">
127 <button class="notice-dismiss bws_hide_settings_notice" title="<?php _e( 'Close notice', 'bestwebsoft' ); ?>"></button>
128 <input type="hidden" name="bws_hide_settings_notice_<?php echo $bws_plugin_banner_to_settings[0]['plugin_options_name']; ?>" value="hide" />
129 <?php wp_nonce_field( plugin_basename( __FILE__ ), 'bws_settings_nonce_name' ); ?>
130 </form>
131 </div>
132 </div>
133 <?php } else { ?>
134 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
135 <div class="bws_banner_on_plugin_page bws_banner_to_settings_joint">
136 <form action="" method="post">
137 <button class="notice-dismiss bws_hide_settings_notice" title="<?php _e( 'Close notice', 'bestwebsoft' ); ?>"></button>
138 <div class="bws-text">
139 <div class="icon">
140 <span class="dashicons dashicons-admin-plugins"></span>
141 </div>
142 <strong><?php _e( 'Thank you for installing plugins by BestWebSoft!', 'bestwebsoft' ); ?></strong>
143 <div class="hide-if-no-js bws-more-links">
144 <a href="#" class="bws-more"><?php _e( 'More Details', 'bestwebsoft' ); ?></a>
145 <a href="#" class="bws-less hidden"><?php _e( 'Less Details', 'bestwebsoft' ); ?></a>
146 </div>
147 <?php wp_nonce_field( plugin_basename( __FILE__ ), 'bws_settings_nonce_name' ); ?>
148 <div class="clear"></div>
149 </div>
150 <div class="bws-details hide-if-js">
151 <?php foreach ( $bws_plugin_banner_to_settings as $value ) { ?>
152 <div>
153 <strong><?php echo str_replace( ' by BestWebSoft', '', $value['plugin_info']['Name'] ); ?></strong>&ensp;<a href="<?php echo $value['settings_url']; ?>"><?php _e( 'Settings', 'bestwebsoft' ); ?></a>
154 <?php if ( false != $value['post_type_url'] ) { ?>
155 &ensp;|&ensp;<a target="_blank" href="<?php echo $value['post_type_url']; ?>"><?php _e( 'Add New', 'bestwebsoft' ); ?></a>
156 <?php } ?>
157 <input type="hidden" name="bws_hide_settings_notice_<?php echo $value['plugin_options_name']; ?>" value="hide" />
158 </div>
159 <?php } ?>
160 </div>
161 </div>
162 </form>
163 </div>
164 <?php }
165 }
166 }
167 }
168
169 if ( ! function_exists( 'bws_plugin_banner' ) ) {
170 function bws_plugin_banner( $plugin_info, $this_banner_prefix, $link_slug, $link_key, $link_pn, $banner_url_or_slug ) {
171 global $wp_version, $bstwbsftwppdtplgns_cookie_add, $bstwbsftwppdtplgns_banner_array;
172
173 if ( empty( $bstwbsftwppdtplgns_banner_array ) ) {
174 if ( ! function_exists( 'bws_get_banner_array' ) )
175 require_once( dirname( __FILE__ ) . '/bws_menu.php' );
176 bws_get_banner_array();
177 }
178
179 if ( false == strrpos( $banner_url_or_slug, '/' ) ) {
180 $banner_url_or_slug = '//ps.w.org/' . $banner_url_or_slug . '/assets/icon-128x128.png';
181 }
182
183 if ( ! function_exists( 'is_plugin_active' ) )
184 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
185
186 $all_plugins = get_plugins();
187
188 $this_banner = $this_banner_prefix . '_hide_banner_on_plugin_page';
189 foreach ( $bstwbsftwppdtplgns_banner_array as $key => $value ) {
190 if ( $this_banner == $value[0] ) {
191 if ( ! isset( $bstwbsftwppdtplgns_cookie_add ) ) {
192 echo '<script type="text/javascript" src="' . plugins_url( 'js/c_o_o_k_i_e.js', __FILE__ ) . '"></script>';
193 $bstwbsftwppdtplgns_cookie_add = true;
194 } ?>
195 <script type="text/javascript">
196 (function($) {
197 $(document).ready( function() {
198 var hide_message = $.cookie( '<?php echo $this_banner_prefix; ?>_hide_banner_on_plugin_page' );
199 if ( hide_message == "true" ) {
200 $( ".<?php echo $this_banner_prefix; ?>_message" ).css( "display", "none" );
201 } else {
202 $( ".<?php echo $this_banner_prefix; ?>_message" ).css( "display", "block" );
203 };
204 $( ".<?php echo $this_banner_prefix; ?>_close_icon" ).click( function() {
205 $( ".<?php echo $this_banner_prefix; ?>_message" ).css( "display", "none" );
206 $.cookie( "<?php echo $this_banner_prefix; ?>_hide_banner_on_plugin_page", "true", { expires: 32 } );
207 });
208 });
209 })(jQuery);
210 </script>
211 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
212 <div class="<?php echo $this_banner_prefix; ?>_message bws_banner_on_plugin_page bws_go_pro_banner" style="display: none;">
213 <button class="<?php echo $this_banner_prefix; ?>_close_icon close_icon notice-dismiss bws_hide_settings_notice" title="<?php _e( 'Close notice', 'bestwebsoft' ); ?>"></button>
214 <div class="icon">
215 <img title="" src="<?php echo esc_attr( $banner_url_or_slug ); ?>" alt="" />
216 </div>
217 <div class="text"><?php
218 _e( 'It’s time to upgrade your', 'bestwebsoft' ); ?> <strong><?php echo $plugin_info['Name']; ?> plugin</strong> <?php _e( 'to', 'bestwebsoft' ); ?> <strong>Pro</strong> <?php _e( 'version!', 'bestwebsoft' ); ?><br />
219 <span><?php _e( 'Extend standard plugin functionality with new great options.', 'bestwebsoft' ); ?></span>
220 </div>
221 <div class="button_div">
222 <a class="button" target="_blank" href="http://bestwebsoft.com/products/<?php echo $link_slug; ?>/?k=<?php echo $link_key; ?>&amp;pn=<?php echo $link_pn; ?>&amp;v=<?php echo $plugin_info["Version"]; ?>&amp;wp_v=<?php echo $wp_version; ?>"><?php _e( 'Learn More', 'bestwebsoft' ); ?></a>
223 </div>
224 </div>
225 </div>
226 <?php break;
227 }
228 if ( isset( $all_plugins[ $value[1] ] ) && $all_plugins[ $value[1] ]["Version"] >= $value[2] && is_plugin_active( $value[1] ) && ! isset( $_COOKIE[ $value[0] ] ) ) {
229 break;
230 }
231 }
232 }
233 }
234
235 if ( ! function_exists( 'bws_plugin_reviews_block' ) ) {
236 function bws_plugin_reviews_block( $plugin_name, $plugin_slug ) { ?>
237 <div class="bws-plugin-reviews">
238 <div class="bws-plugin-reviews-rate">
239 <?php _e( 'If you enjoy our plugin, please give it 5 stars on WordPress', 'bestwebsoft' ); ?>:
240 <a href="http://wordpress.org/support/view/plugin-reviews/<?php echo $plugin_slug; ?>?filter=5" target="_blank" title="<?php echo $plugin_name; ?> reviews"><?php _e( 'Rate the plugin', 'bestwebsoft' ); ?></a>
241 </div>
242 <div class="bws-plugin-reviews-support">
243 <?php _e( 'If there is something wrong about it, please contact us', 'bestwebsoft' ); ?>:
244 <a href="http://support.bestwebsoft.com">http://support.bestwebsoft.com</a>
245 </div>
246 <div class="bws-plugin-reviews-donate">
247 <?php _e( 'Donations play an important role in supporting great projects', 'bestwebsoft' ); ?>:
248 <a href="https://www.2checkout.com/checkout/purchase?sid=1430388&quantity=10&product_id=13">Donate</a>
249 </div>
250 </div>
251 <?php }
252 }
253
254 if ( ! function_exists( 'bws_go_pro_tab_check' ) ) {
255 function bws_go_pro_tab_check( $plugin_basename, $plugin_options_name = false, $is_network_option = false ) {
256 global $wp_version, $bstwbsftwppdtplgns_options;
257 $result = array();
258
259 $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : "";
260
261 if ( ! empty( $plugin_options_name ) && isset( $_POST['bws_hide_premium_options_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) {
262
263 $plugin_options = ( $is_network_option ) ? get_site_option( $plugin_options_name ) : get_option( $plugin_options_name );
264
265 if ( !empty( $plugin_options['hide_premium_options'] ) ) {
266
267 $key = array_search( get_current_user_id(), $plugin_options['hide_premium_options'] );
268 if ( false !== $key ) {
269 unset( $plugin_options['hide_premium_options'][ $key ] );
270 }
271
272 if ( $is_network_option )
273 update_site_option( $plugin_options_name, $plugin_options );
274 else
275 update_option( $plugin_options_name, $plugin_options );
276
277 $result['message'] = __( 'Check premium options on the plugin settings page!', 'bestwebsoft' );
278 }
279 }
280
281 if ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) {
282 if ( '' != $bws_license_key ) {
283 if ( strlen( $bws_license_key ) != 18 ) {
284 $result['error'] = __( "Wrong license key", 'bestwebsoft' );
285 } else {
286 $bws_license_plugin = stripslashes( esc_html( $_POST['bws_license_plugin'] ) );
287 if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] ) && $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] > ( time() - (24 * 60 * 60) ) ) {
288 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] + 1;
289 } else {
290 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = 1;
291 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] = time();
292 }
293
294 /* download Pro */
295 if ( ! function_exists( 'get_plugins' ) )
296 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
297
298 $all_plugins = get_plugins();
299
300 if ( ! array_key_exists( $bws_license_plugin, $all_plugins ) ) {
301 $current = get_site_transient( 'update_plugins' );
302 if ( is_array( $all_plugins ) && !empty( $all_plugins ) && isset( $current ) && is_array( $current->response ) ) {
303 $to_send = array();
304 $to_send["plugins"][ $bws_license_plugin ] = array();
305 $to_send["plugins"][ $bws_license_plugin ]["bws_license_key"] = $bws_license_key;
306 $to_send["plugins"][ $bws_license_plugin ]["bws_illegal_client"] = true;
307 $options = array(
308 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ),
309 'body' => array( 'plugins' => serialize( $to_send ) ),
310 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
311 $raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options );
312
313 if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
314 $result['error'] = __( "Something went wrong. Please try again later. If the error appears again, please contact us", 'bestwebsoft' ) . ' <a href="http://support.bestwebsoft.com">BestWebSoft</a>. ' . __( "We are sorry for inconvenience.", 'bestwebsoft' );
315 } else {
316 $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );
317 if ( is_array( $response ) && !empty( $response ) ) {
318 foreach ( $response as $key => $value ) {
319 if ( "wrong_license_key" == $value->package ) {
320 $result['error'] = __( "Wrong license key", 'bestwebsoft' );
321 } elseif ( "wrong_domain" == $value->package ) {
322 $result['error'] = __( "This license key is bind to another site", 'bestwebsoft' );
323 } elseif ( "you_are_banned" == $value->package ) {
324 $result['error'] = __( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' );
325 } elseif ( "time_out" == $value->package ) {
326 $result['error'] = __( "Unfortunately, Your license has expired. To continue getting top-priority support and plugin updates you should extend it in your", 'bestwebsoft' ) . ' <a href="http://bestwebsoft.com/wp-admin/admin.php?page=bws_plugins_client_area">Client area</a>';
327 } elseif ( "duplicate_domen_for_trial" == $value->package ) {
328 $result['error'] = __( "Unfortunately, the Pro licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' );
329 }
330 }
331 if ( empty( $result['error'] ) ) {
332 $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key;
333
334 $url = 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/downloads/?bws_first_download=' . $bws_license_plugin . '&bws_license_key=' . $bws_license_key . '&download_from=5';
335 $uploadDir = wp_upload_dir();
336 $zip_name = explode( '/', $bws_license_plugin );
337
338 if ( !function_exists( 'curl_init' ) ) {
339 $received_content = file_get_contents( $url );
340 } else {
341 $ch = curl_init();
342 curl_setopt( $ch, CURLOPT_URL, $url );
343 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
344 $received_content = curl_exec( $ch );
345 curl_close( $ch );
346 }
347
348 if ( ! $received_content ) {
349 $result['error'] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' );
350 } else {
351 if ( is_writable( $uploadDir["path"] ) ) {
352 $file_put_contents = $uploadDir["path"] . "/" . $zip_name[0] . ".zip";
353 if ( file_put_contents( $file_put_contents, $received_content ) ) {
354 @chmod( $file_put_contents, octdec( 755 ) );
355 if ( class_exists( 'ZipArchive' ) ) {
356 $zip = new ZipArchive();
357 if ( $zip->open( $file_put_contents ) === TRUE ) {
358 $zip->extractTo( WP_PLUGIN_DIR );
359 $zip->close();
360 } else {
361 $result['error'] = __( "Failed to open the zip archive. Please, upload the plugin manually", 'bestwebsoft' );
362 }
363 } elseif ( class_exists( 'Phar' ) ) {
364 $phar = new PharData( $file_put_contents );
365 $phar->extractTo( WP_PLUGIN_DIR );
366 } else {
367 $result['error'] = __( "Your server does not support either ZipArchive or Phar. Please, upload the plugin manually", 'bestwebsoft' );
368 }
369 @unlink( $file_put_contents );
370 } else {
371 $result['error'] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' );
372 }
373 } else {
374 $result['error'] = __( "UploadDir is not writable. Please, upload the plugin manually", 'bestwebsoft' );
375 }
376 }
377
378 /* activate Pro */
379 if ( file_exists( WP_PLUGIN_DIR . '/' . $zip_name[0] ) ) {
380 if ( is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
381 /* if multisite and free plugin is network activated */
382 $active_plugins = get_site_option( 'active_sitewide_plugins' );
383 $active_plugins[ $bws_license_plugin ] = time();
384 update_site_option( 'active_sitewide_plugins', $active_plugins );
385 } else {
386 /* activate on a single blog */
387 $active_plugins = get_option( 'active_plugins' );
388 array_push( $active_plugins, $bws_license_plugin );
389 update_option( 'active_plugins', $active_plugins );
390 }
391 $result['pro_plugin_is_activated'] = true;
392 } elseif ( empty( $result['error'] ) ) {
393 $result['error'] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' );
394 }
395 }
396 } else {
397 $result['error'] = __( "Something went wrong. Try again later or upload the plugin manually. We are sorry for inconvenience.", 'bestwebsoft' );
398 }
399 }
400 }
401 } else {
402 $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key;
403 /* activate Pro */
404 if ( ! is_plugin_active( $bws_license_plugin ) ) {
405 if ( is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
406 /* if multisite and free plugin is network activated */
407 $network_wide = true;
408 } else {
409 /* activate on a single blog */
410 $network_wide = false;
411 }
412 activate_plugin( $bws_license_plugin, NULL, $network_wide );
413 $result['pro_plugin_is_activated'] = true;
414 }
415 }
416 if ( is_multisite() )
417 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
418 else
419 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
420 }
421 } else {
422 $result['error'] = __( "Please, enter Your license key", 'bestwebsoft' );
423 }
424 }
425 return $result;
426 }
427 }
428
429 /**
430 * Function display GO PRO tab - for old plugin version
431 * @deprecated 1.7.6
432 */
433 if ( ! function_exists( 'bws_go_pro_tab' ) ) {
434 function bws_go_pro_tab( $plugin_info, $plugin_basename, $page, $pro_page, $bws_license_plugin, $link_slug, $link_key, $link_pn, $pro_plugin_is_activated = false, $trial_days_number = false ) {
435 bws_go_pro_tab_show( false, $plugin_info, $plugin_basename, $page, $pro_page, $bws_license_plugin, $link_slug, $link_key, $link_pn, $pro_plugin_is_activated, $trial_days_number );
436 }
437 }
438
439 /**
440 * Function display GO PRO tab
441 */
442 if ( ! function_exists( 'bws_go_pro_tab_show' ) ) {
443 function bws_go_pro_tab_show( $bws_hide_premium_options_check, $plugin_info, $plugin_basename, $page, $pro_page, $bws_license_plugin, $link_slug, $link_key, $link_pn, $pro_plugin_is_activated = false, $trial_days_number = false ) {
444 global $wp_version, $bstwbsftwppdtplgns_options;
445 $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : "";
446 if ( $pro_plugin_is_activated ) { ?>
447 <script type="text/javascript">
448 window.setTimeout( function() {
449 window.location.href = 'admin.php?page=<?php echo $pro_page; ?>';
450 }, 5000 );
451 </script>
452 <p><?php _e( "Congratulations! Pro version of the plugin is successfully installed and activated.", 'bestwebsoft' ); ?></p>
453 <p>
454 <?php _e( "Please, go to", 'bestwebsoft' ); ?> <a href="admin.php?page=<?php echo $pro_page; ?>"><?php _e( 'the setting page', 'bestwebsoft' ); ?></a>
455 (<?php _e( "You will be redirected automatically in 5 seconds.", 'bestwebsoft' ); ?>)
456 </p>
457 <?php } else {
458 if ( $bws_hide_premium_options_check ) { ?>
459 <form method="post" action="">
460 <p>
461 <input type="hidden" name="bws_hide_premium_options_submit" value="submit" />
462 <input type="submit" class="button" value="<?php _e( 'Show Pro features', 'bestwebsoft' ); ?>" />
463 <?php wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?>
464 </p>
465 </form>
466 <?php } ?>
467 <form method="post" action="">
468 <p>
469 <?php _e( 'Enter your license key to install and activate', 'bestwebsoft' ); ?>
470 <a href="http://bestwebsoft.com/products/<?php echo $link_slug; ?>/?k=<?php echo $link_key; ?>&amp;pn=<?php echo $link_pn; ?>&amp;v=<?php echo $plugin_info["Version"]; ?>&amp;wp_v=<?php echo $wp_version; ?>" target="_blank" title="<?php echo $plugin_info["Name"]; ?> Pro">Pro</a>
471 <?php _e( 'version of the plugin.', 'bestwebsoft' ); ?><br />
472 <span class="bws_info">
473 <?php _e( 'License key can be found in the', 'bestwebsoft' ); ?>
474 <a href="http://bestwebsoft.com/wp-login.php">Client Area</a>
475 <?php _e( '(your username is the email address specified during the purchase).', 'bestwebsoft' ); ?>
476 </span>
477 </p>
478 <?php if ( $trial_days_number !== false )
479 $trial_days_number = __( 'or', 'bestwebsoft' ) . ' <a href="http://bestwebsoft.com/products/' . $link_slug . '/trial/" target="_blank">' . sprintf( __( 'Start Your Free %s-Day Trial Now', 'bestwebsoft' ), $trial_days_number ) . '</a>';
480 if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] ) &&
481 '5' < $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] &&
482 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] > ( time() - ( 24 * 60 * 60 ) ) ) { ?>
483 <p>
484 <input disabled="disabled" type="text" name="bws_license_key" value="<?php echo $bws_license_key; ?>" />
485 <input disabled="disabled" type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" />
486 <?php if ( $trial_days_number !== false ) echo $trial_days_number; ?>
487 </p>
488 <p><?php _e( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' ); ?></p>
489 <?php } else { ?>
490 <p>
491 <input type="text" maxlength="100" name="bws_license_key" value="<?php echo $bws_license_key; ?>" />
492 <input type="hidden" name="bws_license_plugin" value="<?php echo $bws_license_plugin; ?>" />
493 <input type="hidden" name="bws_license_submit" value="submit" />
494 <input type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" />
495 <?php if ( $trial_days_number !== false ) echo $trial_days_number;
496 wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?>
497 </p>
498 <?php } ?>
499 </form>
500 <?php }
501 }
502 }
503
504 if ( ! function_exists( 'bws_go_pro_from_trial_tab' ) ) {
505 function bws_go_pro_from_trial_tab( $plugin_info, $plugin_basename, $page, $link_slug, $link_key, $link_pn, $trial_license_is_set = true ) {
506 global $wp_version, $bstwbsftwppdtplgns_options;
507 $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : "";
508 if ( $trial_license_is_set ) { ?>
509 <form method="post" action="">
510 <p>
511 <?php echo sprintf( __( 'In order to continue using the plugin it is necessary to buy a %s license.', 'bestwebsoft' ), '<a href="http://bestwebsoft.com/products/' . $link_slug . '/?k=' . $link_key . '&amp;pn=' . $link_pn . '&amp;v=' . $plugin_info["Version"] . '&amp;wp_v=' . $wp_version .'" target="_blank" title="' . $plugin_info["Name"] . '">Pro</a>' ) . ' ';
512 _e( 'After that you can activate it by entering your license key.', 'bestwebsoft' ); ?><br />
513 <span class="bws_info">
514 <?php _e( 'License key can be found in the', 'bestwebsoft' ); ?>
515 <a href="http://bestwebsoft.com/wp-login.php">Client Area</a>
516 <?php _e( '(your username is the email address specified during the purchase).', 'bestwebsoft' ); ?>
517 </span>
518 </p>
519 <?php if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $plugin_basename ]['count'] ) &&
520 '5' < $bstwbsftwppdtplgns_options['go_pro'][ $plugin_basename ]['count'] &&
521 $bstwbsftwppdtplgns_options['go_pro'][ $plugin_basename ]['time'] > ( time() - ( 24 * 60 * 60 ) ) ) { ?>
522 <p>
523 <input disabled="disabled" type="text" name="bws_license_key" value="" />
524 <input disabled="disabled" type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" />
525 </p>
526 <p><?php _e( "Unfortunately, you have exceeded the number of available tries per day.", 'bestwebsoft' ); ?></p>
527 <?php } else { ?>
528 <p>
529 <input type="text" maxlength="100" name="bws_license_key" value="" />
530 <input type="hidden" name="bws_license_plugin" value="<?php echo $plugin_basename; ?>" />
531 <input type="hidden" name="bws_license_submit" value="submit" />
532 <input type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" />
533 <?php wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?>
534 </p>
535 <?php } ?>
536 </form>
537 <?php } else { ?>
538 <script type="text/javascript">
539 window.setTimeout( function() {
540 window.location.href = 'admin.php?page=<?php echo $page; ?>';
541 }, 5000 );
542 </script>
543 <p><?php _e( "Congratulations! The Pro license of the plugin is successfully activated.", 'bestwebsoft' ); ?></p>
544 <p>
545 <?php _e( "Please, go to", 'bestwebsoft' ); ?> <a href="admin.php?page=<?php echo $page; ?>"><?php _e( 'the setting page', 'bestwebsoft' ); ?></a>
546 (<?php _e( "You will be redirected automatically in 5 seconds.", 'bestwebsoft' ); ?>)
547 </p>
548 <?php }
549 }
550 }
551
552 if ( ! function_exists( 'bws_check_pro_license' ) ) {
553 function bws_check_pro_license( $plugin_basename, $trial_plugin = false ) {
554 global $wp_version, $bstwbsftwppdtplgns_options;
555 $result = array();
556
557 if ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) {
558 $license_key = isset( $_POST['bws_license_key'] ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : '';
559
560 if ( '' != $license_key ) {
561 if ( ! function_exists( 'get_plugins' ) )
562 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
563 $plugins_all = get_plugins();
564 $current = get_site_transient( 'update_plugins' );
565
566 if ( is_array( $plugins_all ) && !empty( $plugins_all ) && isset( $current ) && is_array( $current->response ) ) {
567 $to_send = array();
568 $to_send["plugins"][ $plugin_basename ] = $plugins_all[ $plugin_basename ];
569 $to_send["plugins"][ $plugin_basename ]["bws_license_key"] = $license_key;
570 $to_send["plugins"][ $plugin_basename ]["bws_illegal_client"] = true;
571 $options = array(
572 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
573 'body' => array( 'plugins' => serialize( $to_send ) ),
574 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
575 );
576 $raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options );
577 if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
578 $result['error'] = __( 'Something went wrong. Please try again later. If the error appears again, please contact us', 'bestwebsoft' ) . ' <a href=http://support.bestwebsoft.com>BestWebSoft</a>. ' . __( 'We are sorry for inconvenience.', 'bestwebsoft' );
579 } else {
580 $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );
581 if ( is_array( $response ) && !empty( $response ) ) {
582 foreach ( $response as $key => $value ) {
583 if ( "wrong_license_key" == $value->package ) {
584 $result['error'] = __( 'Wrong license key.', 'bestwebsoft' );
585 } else if ( "wrong_domain" == $value->package ) {
586 $result['error'] = __( 'This license key is bind to another site.', 'bestwebsoft' );
587 } else if ( "time_out" == $value->package ) {
588 $result['message'] = __( 'This license key is valid, but Your license has expired. If you want to update our plugin in future, you should extend the license.', 'bestwebsoft' );
589 } elseif ( "you_are_banned" == $value->package ) {
590 $result['error'] = __( "Unfortunately, you have exceeded the number of available tries.", 'bestwebsoft' );
591 } elseif ( "duplicate_domen_for_trial" == $value->package ) {
592 $result['error'] = __( "Unfortunately, the Pro Trial licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' );
593 }
594 if ( empty( $result['message'] ) && empty( $result['error'] ) ) {
595 if ( isset( $value->trial ) )
596 $result['message'] = __( 'The Pro Trial license key is valid.', 'bestwebsoft' );
597 else
598 $result['message'] = __( 'The license key is valid.', 'bestwebsoft' );
599
600 if ( isset( $value->time_out ) && $value->time_out != '' )
601 $result['message'] .= ' ' . __( 'Your license will expire on', 'bestwebsoft' ) . ' ' . $value->time_out . '.';
602
603 if ( isset( $value->trial ) && $trial_plugin != false )
604 $result['message'] .= ' ' . sprintf( __( 'In order to continue using the plugin it is necessary to buy a %s license.', 'bestwebsoft' ), '<a href="http://bestwebsoft.com/products/' . $trial_plugin['link_slug'] . '/?k=' . $trial_plugin['link_key'] . '&pn=' . $trial_plugin['link_pn'] . '&v=' . $trial_plugin['plugin_info']['Version'] . '&wp_v=' . $wp_version . '" target="_blank" title="' . $trial_plugin['plugin_info']['Name'] . '">Pro</a>' );
605
606 if ( isset( $value->trial ) ) {
607 $bstwbsftwppdtplgns_options['trial'][ $plugin_basename ] = 1;
608 } else {
609 unset( $bstwbsftwppdtplgns_options['trial'][ $plugin_basename ] );
610 }
611 }
612 if ( empty( $result['error'] ) ) {
613 if ( $bstwbsftwppdtplgns_options[ $plugin_basename ] != $license_key ) {
614 $bstwbsftwppdtplgns_options[ $plugin_basename ] = $license_key;
615 $bstwbsftwppdtplgns_options['time_out'][ $plugin_basename ] = $value->time_out;
616 if ( is_multisite() )
617 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
618 else
619 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
620 $file = @fopen( dirname( dirname( __FILE__ ) ) . "/license_key.txt" , "w+" );
621 if ( $file ) {
622 @fwrite( $file, $license_key );
623 @fclose( $file );
624 }
625 }
626 }
627 }
628 } else {
629 $result['error'] = __( 'Something went wrong. Please try again later. If the error appears again, please contact us', 'bestwebsoft' ) . ' <a href=http://support.bestwebsoft.com>BestWebSoft</a>. ' . __( 'We are sorry for inconvenience.', 'bestwebsoft' );
630 }
631 }
632 }
633 } else {
634 $result['error'] = __( 'Please, enter your license key', 'bestwebsoft' );
635 }
636 }
637 return $result;
638 }
639 }
640
641 if ( ! function_exists ( 'bws_check_pro_license_form' ) ) {
642 function bws_check_pro_license_form( $plugin_basename ) {
643 global $bstwbsftwppdtplgns_options;
644 $license_key = ( isset( $bstwbsftwppdtplgns_options[ $plugin_basename ] ) ) ? $bstwbsftwppdtplgns_options[ $plugin_basename ] : ''; ?>
645 <div class="clear"></div>
646 <form method="post" action="">
647 <p><?php echo _e( 'If needed you can check if the license key is correct or reenter it in the field below. You can find your license key on your personal page - Client area - on our website', 'bestwebsoft' ) . ' <a href="http://bestwebsoft.com/wp-login.php">http://bestwebsoft.com/wp-login.php</a> ' . __( '(your username is the email address specified during the purchase). If necessary, please submit "Lost your password?" request.', 'bestwebsoft' ); ?></p>
648 <p>
649 <input type="text" maxlength="100" name="bws_license_key" value="<?php echo $license_key; ?>" />
650 <input type="hidden" name="bws_license_submit" value="submit" />
651 <input type="submit" class="button" value="<?php _e( 'Check license key', 'bestwebsoft' ) ?>" />
652 <?php wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?>
653 </p>
654 </form>
655 <?php }
656 }
657
658 if ( ! function_exists ( 'bws_plugin_update_row' ) ) {
659 function bws_plugin_update_row( $plugin_key, $link_slug = false, $free_plugin_name = false ) {
660 global $bstwbsftwppdtplgns_options;
661 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
662 if ( isset( $bstwbsftwppdtplgns_options['wrong_license_key'][ $plugin_key ] ) ) {
663 echo '<tr class="plugin-update-tr">
664 <td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
665 <div class="update-message" style="background-color: #FFEBE8; border-color: #CC0000;"><strong>' . __( 'WARNING: Illegal use notification', 'bestwebsoft' ) . '.</strong> ' . __( 'You can use one license of the Pro plugin for one domain only. Please check and edit your license or domain if necessary using you personal Client Area. We strongly recommend you to solve the problem within 24 hours, otherwise the Pro plugin will be deactivated.', 'bestwebsoft' ) . ' <a target="_blank" href="http://support.bestwebsoft.com/hc/en-us/articles/204240089">' . __( 'Learn More', 'bestwebsoft' ) . '</a></div>
666 </td>
667 </tr>';
668 } elseif ( isset( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) && strtotime( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) < strtotime( date("m/d/Y") ) ) {
669 echo '<tr class="plugin-update-tr">
670 <td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
671 <div class="update-message" style="color: #8C0000;">';
672 if ( isset( $bstwbsftwppdtplgns_options['trial'][ $plugin_key ] ) && $link_slug != false ) {
673 echo __( 'Notice: Your Pro Trial license has expired. To continue using the plugin you should buy a Pro license', 'bestwebsoft' ) . ' - <a href="http://bestwebsoft.com/products/' . $link_slug .'/">http://bestwebsoft.com/products/' . $link_slug . '/</a>';
674 } else {
675 echo __( 'Your license has expired. To continue getting top-priority support and plugin updates you should extend it.', 'bestwebsoft' ) . ' <a target="_new" href="http://support.bestwebsoft.com/entries/53487136">' . __( "Learn more", 'bestwebsoft' ) . '</a>';
676 }
677 echo '</div>
678 </td>
679 </tr>';
680 } elseif ( isset( $bstwbsftwppdtplgns_options['trial'][ $plugin_key ] ) ) {
681 echo '<tr class="plugin-update-tr">
682 <td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
683 <div class="update-message" style="color: #8C0000;">';
684 if ( $free_plugin_name != false ) {
685 echo sprintf( __( 'Notice: You are using the Pro Trial license of %s plugin.', 'bestwebsoft' ), $free_plugin_name );
686 } else {
687 _e( 'Notice: You are using the Pro Trial license of plugin.', 'bestwebsoft' );
688 }
689 if ( isset( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) )
690 echo ' ' . __( "The Pro Trial license will expire on", 'bestwebsoft' ) . ' ' . $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] . '.';
691 echo '</div>
692 </td>
693 </tr>';
694 }
695 }
696 }
697
698 if ( ! function_exists ( 'bws_plugin_banner_timeout' ) ) {
699 function bws_plugin_banner_timeout( $plugin_key, $plugin_prefix, $plugin_name, $banner_url = false ) {
700 global $bstwbsftwppdtplgns_options, $bstwbsftwppdtplgns_cookie_add;
701 if ( isset( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) && ( strtotime( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) < strtotime( date("m/d/Y") . '+1 month' ) ) && ( strtotime( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) > strtotime( date("m/d/Y") ) ) ) {
702 if ( ! isset( $bstwbsftwppdtplgns_cookie_add ) ) {
703 echo '<script type="text/javascript" src="' . plugins_url( 'js/c_o_o_k_i_e.js', __FILE__ ) . '"></script>';
704 $bstwbsftwppdtplgns_cookie_add = true;
705 } ?>
706 <script type="text/javascript">
707 (function($) {
708 $(document).ready( function() {
709 var hide_message = $.cookie( "<?php echo $plugin_prefix; ?>_timeout_hide_banner_on_plugin_page" );
710 if ( hide_message == "true" ) {
711 $( ".<?php echo $plugin_prefix; ?>_message" ).css( "display", "none" );
712 } else {
713 $( ".<?php echo $plugin_prefix; ?>_message" ).css( "display", "block" );
714 }
715 $( ".<?php echo $plugin_prefix; ?>_close_icon" ).click( function() {
716 $( ".<?php echo $plugin_prefix; ?>_message" ).css( "display", "none" );
717 $.cookie( "<?php echo $plugin_prefix; ?>_timeout_hide_banner_on_plugin_page", "true", { expires: 30 } );
718 });
719 });
720 })(jQuery);
721 </script>
722 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
723 <div class="<?php echo $plugin_prefix; ?>_message bws_banner_on_plugin_page bws_banner_timeout" style="display:none;">
724 <button class="<?php echo $plugin_prefix; ?>_close_icon close_icon notice-dismiss bws_hide_settings_notice" title="<?php _e( 'Close notice', 'bestwebsoft' ); ?>"></button>
725 <div class="icon">
726 <img title="" src="<?php echo $banner_url; ?>" alt="" />
727 </div>
728 <div class="text"><?php _e( "You license for", 'bestwebsoft' ); ?> <strong><?php echo $plugin_name; ?></strong> <?php echo __( "expires on", 'bestwebsoft' ) . ' ' . $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] . ' ' . __( "and you won't be granted TOP-PRIORITY SUPPORT or UPDATES.", 'bestwebsoft' ); ?> <a target="_new" href="http://support.bestwebsoft.com/entries/53487136"><?php _e( "Learn more", 'bestwebsoft' ); ?></a></div>
729 </div>
730 </div>
731 <?php }
732 }
733 }
734
735 if ( ! function_exists( 'bws_plugin_banner_to_settings' ) ) {
736 function bws_plugin_banner_to_settings( $plugin_info, $plugin_options_name, $banner_url_or_slug, $settings_url, $post_type_url = false ) {
737 global $wp_version, $bws_plugin_banner_to_settings;
738
739 $is_network_admin = is_network_admin();
740
741 $plugin_options = $is_network_admin ? get_site_option( $plugin_options_name ) : get_option( $plugin_options_name );
742
743 if ( isset( $plugin_options['display_settings_notice'] ) && 0 == $plugin_options['display_settings_notice'] )
744 return;
745
746 if ( isset( $_POST['bws_hide_settings_notice_' . $plugin_options_name ] ) && check_admin_referer( plugin_basename( __FILE__ ), 'bws_settings_nonce_name' ) ) {
747 $plugin_options['display_settings_notice'] = 0;
748 if ( $is_network_admin )
749 update_site_option( $plugin_options_name, $plugin_options );
750 else
751 update_option( $plugin_options_name, $plugin_options );
752 return;
753 }
754
755 if ( false == strrpos( $banner_url_or_slug, '/' ) ) {
756 $banner_url_or_slug = '//ps.w.org/' . $banner_url_or_slug . '/assets/icon-128x128.png';
757 }
758
759 $bws_plugin_banner_to_settings[] = array(
760 'plugin_info' => $plugin_info,
761 'plugin_options_name' => $plugin_options_name,
762 'banner_url' => $banner_url_or_slug,
763 'settings_url' => $settings_url,
764 'post_type_url' => $post_type_url
765 );
766 }
767 }
768
769 if ( ! function_exists( 'bws_plugin_suggest_feature_banner' ) ) {
770 function bws_plugin_suggest_feature_banner( $plugin_info, $plugin_options_name, $banner_url_or_slug ) {
771 global $wp_version;
772
773 $is_network_admin = is_network_admin();
774
775 $plugin_options = $is_network_admin ? get_site_option( $plugin_options_name ) : get_option( $plugin_options_name );
776
777 if ( isset( $plugin_options['display_suggest_feature_banner'] ) && 0 == $plugin_options['display_suggest_feature_banner'] )
778 return;
779
780 if ( ! isset( $plugin_options['first_install'] ) ) {
781 $plugin_options['first_install'] = strtotime( "now" );
782 $update_option = $return = true;
783 } elseif ( strtotime( '-2 week' ) < $plugin_options['first_install'] ) {
784 $return = true;
785 }
786
787 if ( ! isset( $plugin_options['go_settings_counter'] ) ) {
788 $plugin_options['go_settings_counter'] = 1;
789 $update_option = $return = true;
790 } elseif ( 20 > $plugin_options['go_settings_counter'] ) {
791 $plugin_options['go_settings_counter'] = $plugin_options['go_settings_counter'] + 1;
792 $update_option = $return = true;
793 }
794
795 if ( isset( $update_option ) ) {
796 if ( $is_network_admin )
797 update_site_option( $plugin_options_name, $plugin_options );
798 else
799 update_option( $plugin_options_name, $plugin_options );
800 }
801
802 if ( isset( $return ) )
803 return;
804
805 if ( isset( $_POST['bws_hide_suggest_feature_banner_' . $plugin_options_name ] ) && check_admin_referer( $plugin_info['Name'], 'bws_settings_nonce_name' ) ) {
806 $plugin_options['display_suggest_feature_banner'] = 0;
807 if ( $is_network_admin )
808 update_site_option( $plugin_options_name, $plugin_options );
809 else
810 update_option( $plugin_options_name, $plugin_options );
811 return;
812 }
813
814 if ( false == strrpos( $banner_url_or_slug, '/' ) ) {
815 $banner_url_or_slug = '//ps.w.org/' . $banner_url_or_slug . '/assets/icon-128x128.png';
816 } ?>
817 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
818 <div class="bws_banner_on_plugin_page bws_suggest_feature_banner">
819 <div class="icon">
820 <img title="" src="<?php echo esc_attr( $banner_url_or_slug ); ?>" alt="" />
821 </div>
822 <div class="text">
823 <strong><?php _e( 'Thank you for choosing', 'bestwebsoft' ); ?> <?php echo $plugin_info['Name']; ?> plugin!</strong><br />
824 <?php _e( "If you have a feature, suggestion or idea you'd like to see in the plugin, we'd love to hear about it!", 'bestwebsoft' ); ?>
825 <a target="_blank" href="http://support.bestwebsoft.com/hc/en-us/requests/new"><?php _e( 'Suggest a Feature', 'bestwebsoft' ); ?></a>
826 </div>
827 <form action="" method="post">
828 <button class="notice-dismiss bws_hide_settings_notice" title="<?php _e( 'Close notice', 'bestwebsoft' ); ?>"></button>
829 <input type="hidden" name="bws_hide_suggest_feature_banner_<?php echo $plugin_options_name; ?>" value="hide" />
830 <?php wp_nonce_field( $plugin_info['Name'], 'bws_settings_nonce_name' ); ?>
831 </form>
832 </div>
833 </div>
834 <?php }
835 }
836
837 if ( ! function_exists( 'bws_show_settings_notice' ) ) {
838 function bws_show_settings_notice() { ?>
839 <div id="bws_save_settings_notice" class="updated fade below-h2" style="display:none;">
840 <p>
841 <strong><?php _e( 'Notice', 'bestwebsoft' ); ?></strong>: <?php _e( "The plugin's settings have been changed.", 'bestwebsoft' ); ?>
842 <a class="bws_save_anchor" href="#bws-submit-button"><?php _e( 'Save Changes', 'bestwebsoft' ); ?></a>
843 </p>
844 </div>
845 <?php }
846 }
847
848 if ( ! function_exists( 'bws_hide_premium_options' ) ) {
849 function bws_hide_premium_options( $options ) {
850 if ( ! isset( $options['hide_premium_options'] ) || ! is_array( $options['hide_premium_options'] ) )
851 $options['hide_premium_options'] = array();
852
853 $options['hide_premium_options'][] = get_current_user_id();
854
855 return array(
856 'message' => __( 'You can always look at premium options by clicking on the "Show Pro features" in the "Go PRO" tab', 'bestwebsoft' ),
857 'options' => $options );
858 }
859 }
860
861 if ( ! function_exists( 'bws_hide_premium_options_check' ) ) {
862 function bws_hide_premium_options_check( $options ) {
863 if ( ! empty( $options['hide_premium_options'] ) && in_array( get_current_user_id(), $options['hide_premium_options'] ) )
864 return true;
865 else
866 return false;
867 }
868 }
869
870 if ( ! function_exists ( 'bws_plugins_admin_init' ) ) {
871 function bws_plugins_admin_init() {
872
873 if ( isset( $_GET['bws_activate_plugin'] ) && check_admin_referer( 'bws_activate_plugin' . $_GET['bws_activate_plugin'] ) ) {
874
875 $plugin = isset( $_GET['bws_activate_plugin'] ) ? $_GET['bws_activate_plugin'] : '';
876 $result = activate_plugin( $plugin, '', is_network_admin() );
877 if ( is_wp_error( $result ) ) {
878 if ( 'unexpected_output' == $result->get_error_code() ) {
879 $redirect = self_admin_url( 'admin.php?page=bws_plugins&error=true&charsout=' . strlen( $result->get_error_data() ) . '&plugin=' . $plugin );
880 wp_redirect( add_query_arg( '_error_nonce', wp_create_nonce( 'plugin-activation-error_' . $plugin ), $redirect ) );
881 exit();
882 } else {
883 wp_die( $result );
884 }
885 }
886
887 if ( ! is_network_admin() ) {
888 $recent = (array) get_option( 'recently_activated' );
889 unset( $recent[ $plugin ] );
890 update_option( 'recently_activated', $recent );
891 } else {
892 $recent = (array) get_site_option( 'recently_activated' );
893 unset( $recent[ $plugin ] );
894 update_site_option( 'recently_activated', $recent );
895 }
896 wp_redirect( self_admin_url( 'admin.php?page=bws_plugins&activate=true' ) );
897 exit();
898 }
899
900 if ( isset( $_GET['page'] ) && $_GET['page'] == 'bws_plugins' ) {
901 if ( ! session_id() )
902 @session_start();
903 }
904
905 bws_add_editor_buttons();
906 }
907 }
908
909 if ( ! function_exists ( 'bws_admin_enqueue_scripts' ) ) {
910 function bws_admin_enqueue_scripts() {
911 global $wp_version;
912 wp_enqueue_style( 'bws-admin-css', plugins_url( 'css/general_style.css', __FILE__ ) );
913 wp_enqueue_script( 'bws-admin-scripts', plugins_url( 'js/general_script.js', __FILE__ ), array( 'jquery' ) );
914
915 if ( isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'bws_panel', 'bws_plugins', 'bws_themes', 'bws_system_status' ) ) ) {
916 wp_enqueue_style( 'bws_menu_style', plugins_url( 'css/style.css', __FILE__ ) );
917 wp_enqueue_script( 'bws_menu_script', plugins_url( 'js/bws_menu.js' , __FILE__ ) );
918 wp_enqueue_script( 'theme-install' );
919 add_thickbox();
920 wp_enqueue_script( 'plugin-install' );
921 }
922 }
923 }
924
925 if ( ! function_exists ( 'bws_plugins_admin_head' ) ) {
926 function bws_plugins_admin_head() {
927 global $bws_shortcode_list, $wp_version, $post_type;
928 if ( isset( $_GET['page'] ) && $_GET['page'] == "bws_plugins" ) { ?>
929 <noscript>
930 <style type="text/css">
931 .bws_product_button {
932 display: inline-block;
933 }
934 </style>
935 </noscript>
936 <?php }
937 if ( 4.2 > $wp_version ) {
938 $plugin_dir_array = explode( '/', plugin_basename( __FILE__ ) );
939 $plugin_dir = $plugin_dir_array[0]; ?>
940 <style type="text/css">
941 .bws_hide_settings_notice,
942 .bws_hide_premium_options {
943 width: 11px;
944 height: 11px;
945 border: none;
946 background: url("<?php echo plugins_url( $plugin_dir . '/bws_menu/images/close_banner.png' ); ?>") no-repeat center center;
947 box-shadow: none;
948 float: right;
949 margin: 8px;
950 }
951 .bws_hide_settings_notice:hover,
952 .bws_hide_premium_options:hover {
953 cursor: pointer;
954 }
955 .bws_hide_premium_options {
956 position: relative;
957 }
958 </style>
959 <?php }
960 if ( ! empty( $bws_shortcode_list ) ) { ?>
961 <!-- TinyMCE Shortcode Plugin -->
962 <script type='text/javascript'>
963 var bws_shortcode_button = {
964 'label': '<?php esc_attr_e( "Add BWS Shortcode", "bestwebsoft" ); ?>',
965 'title': '<?php esc_attr_e( "Add BWS Plugins Shortcode", "bestwebsoft" ); ?>',
966 'icon_url': '<?php echo plugins_url( "images/shortcode-icon.png" , __FILE__ ); ?>',
967 'function_name': [
968 <?php foreach ( $bws_shortcode_list as $key => $value ) {
969 if ( isset( $value['js_function'] ) )
970 echo "'" . $value['js_function'] . "',";
971 } ?>
972 ],
973 'wp_version' : '<?php echo $wp_version; ?>'
974 };
975 </script>
976 <!-- TinyMCE Shortcode Plugin -->
977 <?php if ( isset( $post_type ) && in_array( $post_type, array( 'post', 'page' ) ) ) {
978 $tooltip_args = array(
979 'tooltip_id' => 'bws_shortcode_button_tooltip',
980 'css_selector' => '.mce-bws_shortcode_button',
981 'actions' => array(
982 'click' => false,
983 'onload' => true
984 ),
985 'content' => '<h3>' . __( 'Add shortcode', 'bestwebsoft' ) . '</h3><p>' . __( "Add BestWebSoft plugins' shortcodes using this button.", 'bestwebsoft' ) . '</p>',
986 'position' => array(
987 'edge' => 'right'
988 ),
989 'set_timeout' => 2000
990 );
991 if ( $wp_version < '3.9' )
992 $tooltip_args['css_selector'] = '.mce_add_bws_shortcode';
993 bws_add_tooltip_in_admin( $tooltip_args );
994 }
995 }
996 }
997 }
998
999 if ( ! function_exists ( 'bws_plugins_include_codemirror' ) ) {
1000 function bws_plugins_include_codemirror() {
1001 wp_enqueue_style( 'codemirror.css', plugins_url( 'css/codemirror.css', __FILE__ ) );
1002 wp_enqueue_script( 'codemirror.js', plugins_url( 'js/codemirror.js', __FILE__ ), array( 'jquery' ) );
1003 }
1004 }
1005
1006 /**
1007 * Tooltip block
1008 */
1009 if ( ! function_exists( 'bws_add_tooltip_in_admin' ) ) {
1010 function bws_add_tooltip_in_admin( $tooltip_args = array() ) {
1011 new BWS_admin_tooltip( $tooltip_args );
1012 }
1013 }
1014
1015 if ( ! class_exists( 'BWS_admin_tooltip' ) ) {
1016 class BWS_admin_tooltip {
1017 private $tooltip_args;
1018
1019 public function __construct( $tooltip_args ) {
1020 global $wp_version;
1021 if ( 3.3 > $wp_version )
1022 return;
1023 /* Default arguments */
1024 $tooltip_args_default = array(
1025 'tooltip_id' => false,
1026 'css_selector' => false,
1027 'actions' => array(
1028 'click' => true,
1029 'onload' => false,
1030 ),
1031 'buttons' => array(
1032 'close' => array(
1033 'type' => 'dismiss',
1034 'text' => __( 'Close', 'bestwebsoft' ),
1035 ),
1036 ),
1037 'position' => array(
1038 'edge' => 'top',
1039 'align' => 'center',
1040 'pos-left' => 0,
1041 'pos-top' => 0,
1042 'zindex' => 10000
1043 ),
1044 'set_timeout' => 0
1045 );
1046 $tooltip_args = array_merge( $tooltip_args_default, $tooltip_args );
1047 /* Check that our merged array has default values */
1048 foreach ( $tooltip_args_default as $arg_key => $arg_value ) {
1049 if ( is_array( $arg_value ) ) {
1050 foreach ( $arg_value as $key => $value) {
1051 if ( ! isset( $tooltip_args[ $arg_key ][ $key ] ) ) {
1052 $tooltip_args[ $arg_key ][ $key ] = $tooltip_args_default[ $arg_key ][ $key ];
1053 }
1054 }
1055 }
1056 }
1057 /* Check if tooltip is dismissed */
1058 if ( true === $tooltip_args['actions']['onload'] ) {
1059 if ( in_array( $tooltip_args['tooltip_id'], array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) ) ) ) {
1060 $tooltip_args['actions']['onload'] = false;
1061 }
1062 }
1063 /* Check entered data */
1064 if ( false === $tooltip_args['tooltip_id'] || false === $tooltip_args['css_selector'] || ( false === $tooltip_args['actions']['click'] && false === $tooltip_args['actions']['onload'] ) ) {
1065 /* if not enough data to output a tooltip or both actions (click, onload) are false */
1066 return;
1067 } else {
1068 /* check position */
1069 if ( ! in_array( $tooltip_args['position']['edge'], array( 'left', 'right', 'top', 'bottom' ) ) ) {
1070 $tooltip_args['position']['edge'] = 'top';
1071 }
1072 if ( ! in_array( $tooltip_args['position']['align'], array( 'top', 'bottom', 'left', 'right', 'center', ) ) ) {
1073 $tooltip_args['position']['align'] = 'center';
1074 }
1075 }
1076 /* fix position */
1077 switch ( $tooltip_args['position']['edge'] ) {
1078 case 'left':
1079 case 'right':
1080 switch ( $tooltip_args['position']['align'] ) {
1081 case 'top':
1082 case 'bottom':
1083 $tooltip_args['position']['align'] = 'center';
1084 break;
1085 }
1086 break;
1087 case 'top':
1088 case 'bottom':
1089 if ( $tooltip_args['position']['align'] == 'left' ) {
1090 $tooltip_args['position']['pos-left'] -= 65;
1091 }
1092 break;
1093 }
1094 $this->tooltip_args = $tooltip_args;
1095 /* add styles and scripts */
1096 wp_enqueue_style( 'wp-pointer' );
1097 wp_enqueue_script( 'wp-pointer' );
1098 /* add script that displays our tooltip */
1099 add_action( 'admin_print_footer_scripts', array( $this, 'add_scripts' ) );
1100 }
1101
1102 /**
1103 * Display tooltip
1104 */
1105 public function add_scripts() {
1106 global $bstwbsftwppdtplgns_tooltip_script_add;
1107 if ( ! isset( $bstwbsftwppdtplgns_tooltip_script_add ) ) {
1108 echo '<script type="text/javascript" src="' . plugins_url( 'js/bws_tooltip.js', __FILE__ ) . '"></script>';
1109 $bstwbsftwppdtplgns_tooltip_script_add = true;
1110 }
1111 $tooltip_args = $this->tooltip_args; ?>
1112 <script type="text/javascript">
1113 (function($) {
1114 $(document).ready( function() {
1115 $.bwsTooltip( <?php echo json_encode( $tooltip_args ); ?> );
1116 })
1117 })(jQuery);
1118 </script>
1119 <?php }
1120 }
1121 }
1122
1123 if ( ! function_exists ( 'bws_form_restore_default_settings' ) ) {
1124 function bws_form_restore_default_settings( $plugin_basename, $change_permission_attr = '' ) { ?>
1125 <form method="post" action="">
1126 <p><?php _e( 'Restore all plugin settings to defaults', 'bestwebsoft' ); ?></p>
1127 <p>
1128 <input <?php echo $change_permission_attr; ?> type="submit" class="button" value="<?php _e( 'Restore settings', 'bestwebsoft' ); ?>" />
1129 </p>
1130 <input type="hidden" name="bws_restore_default" value="submit" />
1131 <?php wp_nonce_field( $plugin_basename, 'bws_settings_nonce_name' ); ?>
1132 </form>
1133 <?php }
1134 }
1135
1136 if ( ! function_exists ( 'bws_form_restore_default_confirm' ) ) {
1137 function bws_form_restore_default_confirm( $plugin_basename ) { ?>
1138 <div>
1139 <p><?php _e( 'Are you sure you want to restore all settings by default?', 'bestwebsoft' ) ?></p>
1140 <form method="post" action="">
1141 <p>
1142 <button class="button" name="bws_restore_confirm"><?php _e( 'Yes, restore all settings', 'bestwebsoft' ) ?></button>
1143 <button class="button" name="bws_restore_deny"><?php _e( 'No, go back to the settings page', 'bestwebsoft' ) ?></button>
1144 <?php wp_nonce_field( $plugin_basename, 'bws_settings_nonce_name' ); ?>
1145 </p>
1146 </form>
1147 </div>
1148 <?php }
1149 }
1150
1151 /* shortcode */
1152 if ( ! function_exists( 'bws_add_editor_buttons' ) ) {
1153 function bws_add_editor_buttons() {
1154 global $bws_shortcode_list, $wp_version;
1155 if ( $wp_version < '3.3' )
1156 return;
1157 if ( ! empty( $bws_shortcode_list ) && current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {
1158 add_filter( 'mce_external_plugins', 'bws_add_buttons' );
1159 add_filter( 'mce_buttons', 'bws_register_buttons' );
1160 }
1161 }
1162 }
1163
1164 if ( ! function_exists( 'bws_add_buttons' ) ){
1165 function bws_add_buttons( $plugin_array ) {
1166 $plugin_array['add_bws_shortcode'] = plugins_url( 'js/shortcode-button.js', __FILE__ );
1167 return $plugin_array;
1168 }
1169 }
1170
1171 if ( ! function_exists( 'bws_register_buttons' ) ) {
1172 function bws_register_buttons( $buttons ) {
1173 array_push( $buttons, 'add_bws_shortcode' ); /* dropcap', 'recentposts */
1174 return $buttons;
1175 }
1176 }
1177
1178 /* Generate inline content for the popup window when the "bws shortcode" button is clicked */
1179 if ( ! function_exists( 'bws_shortcode_media_button_popup' ) ) {
1180 function bws_shortcode_media_button_popup() {
1181 global $bws_shortcode_list, $wp_version;
1182 if ( $wp_version < '3.3' )
1183 return;
1184
1185 if ( ! empty( $bws_shortcode_list ) ) { ?>
1186 <div id="bws_shortcode_popup" style="display:none;">
1187 <div id="bws_shortcode_popup_block">
1188 <div id="bws_shortcode_select_plugin">
1189 <h4><?php _e( 'Plugin', 'bestwebsoft' ); ?></h4>
1190 <select name="bws_shortcode_select" id="bws_shortcode_select">
1191 <?php foreach ( $bws_shortcode_list as $key => $value ) { ?>
1192 <option value="<?php echo $key; ?>"><?php echo $value['name']; ?></option>
1193 <?php } ?>
1194 </select>
1195 </div>
1196 <div class="clear"></div>
1197 <div id="bws_shortcode_content">
1198 <h4><?php _e( 'Shortcode settings', 'bestwebsoft' ); ?></h4>
1199 <?php echo apply_filters( 'bws_shortcode_button_content', '' ); ?>
1200 </div>
1201 <div class="clear"></div>
1202 <div id="bws_shortcode_content_bottom">
1203 <p><?php _e( 'The shortcode will be inserted', 'bestwebsoft' ); ?></p>
1204 <div id="bws_shortcode_block"><div id="bws_shortcode_display"></div></div>
1205 </div>
1206 <?php if ( $wp_version < '3.9' ) { ?>
1207 <p>
1208 <button class="button-primary primary bws_shortcode_insert"><?php _e( 'Insert', 'bestwebsoft' ); ?></button>
1209 </p>
1210 <?php } ?>
1211 </div>
1212 </div>
1213 <?php }
1214 if ( $wp_version < '3.9' ) { ?>
1215 <script type="text/javascript">
1216 (function($){
1217 $( '.bws_shortcode_insert' ).on( 'click',function() {
1218 var shortcode = $( '#TB_ajaxContent #bws_shortcode_display' ).text();
1219 if ( '' != shortcode ) {
1220 /* insert shortcode to tinymce */
1221 if ( !tinyMCE.activeEditor || tinyMCE.activeEditor.isHidden() ) {
1222 $( 'textarea#content' ).val( shortcode );
1223 } else {
1224 tinyMCE.execCommand( 'mceInsertContent', false, shortcode );
1225 }
1226 }
1227 /* close the thickbox after adding shortcode to editor */
1228 self.parent.tb_remove();
1229 });
1230 })(jQuery);
1231 </script>
1232 <?php }
1233 }
1234 }
1235
1236 /* add help tab */
1237 if ( ! function_exists( 'bws_help_tab' ) ) {
1238 function bws_help_tab( $screen, $args ) {
1239 $url = ( ! empty( $args['section'] ) ) ? 'http://support.bestwebsoft.com/hc/en-us/sections/' . $args['section'] : 'http://support.bestwebsoft.com/';
1240
1241 $content = '<p><a href="' . $url . '" target="_blank">' . __( 'Visit Help Center', 'bestwebsoft' ) . '</a></p>';
1242
1243 $screen->add_help_tab(
1244 array(
1245 'id' => $args['id'] . '_help_tab',
1246 'title' => __( 'FAQ', 'bestwebsoft' ),
1247 'content' => $content
1248 )
1249 );
1250
1251 $screen->set_help_sidebar(
1252 '<p><strong>' . __( 'For more information:', 'bestwebsoft' ) . '</strong></p>' .
1253 '<p><a href="https://drive.google.com/folderview?id=0B5l8lO-CaKt9VGh0a09vUjNFNjA&usp=sharing#list" target="_blank">' . __( 'Documentation', 'bestwebsoft' ) . '</a></p>' .
1254 '<p><a href="http://www.youtube.com/user/bestwebsoft/playlists?flow=grid&sort=da&view=1" target="_blank">' . __( 'Video Instructions', 'bestwebsoft' ) . '</a></p>' .
1255 '<p><a href="http://support.bestwebsoft.com/hc/en-us/requests/new" target="_blank">' . __( 'Submit a Request', 'bestwebsoft' ) . '</a></p>'
1256 );
1257 }
1258 }
1259
1260 /**
1261 * Function display 'Custom code' tab
1262 */
1263 if ( ! function_exists( 'bws_custom_code_tab' ) ) {
1264 function bws_custom_code_tab() {
1265 if ( ! current_user_can( 'edit_plugins' ) )
1266 wp_die( __( 'You do not have sufficient permissions to edit plugins for this site.', 'bestwebsoft' ) );
1267
1268 global $bstwbsftwppdtplgns_options;
1269
1270 $message = $content = '';
1271 $is_css_active = $is_php_active = false;
1272
1273 $upload_dir = wp_upload_dir();
1274 $folder = $upload_dir['basedir'] . '/bws-custom-code';
1275 if ( ! $upload_dir["error"] ) {
1276 if ( ! is_dir( $folder ) )
1277 wp_mkdir_p( $folder, 0755 );
1278
1279 $index_file = $upload_dir['basedir'] . '/bws-custom-code/index.php';
1280 if ( ! file_exists( $index_file ) ) {
1281 if ( $f = fopen( $index_file, 'w+' ) )
1282 fclose( $f );
1283 }
1284 }
1285
1286 $css_file = 'bws-custom-code.css';
1287 $real_css_file = $folder . '/' . $css_file;
1288
1289 $php_file = 'bws-custom-code.php';
1290 $real_php_file = $folder . '/' . $php_file;
1291
1292 $is_multisite = is_multisite();
1293 if ( $is_multisite )
1294 $blog_id = get_current_blog_id();
1295
1296 if ( isset( $_REQUEST['bws_update_custom_code'] ) && check_admin_referer( 'bws_update_' . $css_file ) ) {
1297
1298 /* CSS */
1299 $newcontent_css = wp_unslash( $_POST['bws_newcontent_css'] );
1300 if ( ! empty( $newcontent_css ) && isset( $_REQUEST['bws_custom_css_active'] ) ) {
1301 if ( $is_multisite )
1302 $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $css_file ] = $upload_dir['baseurl'] . '/bws-custom-code/' . $css_file;
1303 else
1304 $bstwbsftwppdtplgns_options['custom_code'][ $css_file ] = $upload_dir['baseurl'] . '/bws-custom-code/' . $css_file;
1305 } else {
1306 if ( $is_multisite ) {
1307 if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $css_file ] ) )
1308 unset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $css_file ] );
1309 } else {
1310 if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $css_file ] ) )
1311 unset( $bstwbsftwppdtplgns_options['custom_code'][ $css_file ] );
1312 }
1313 }
1314 if ( $f = fopen( $real_css_file, 'w+' ) ) {
1315 fwrite( $f, $newcontent_css );
1316 fclose( $f );
1317 $message .= sprintf( __( 'File %s edited successfully.', 'bestwebsoft' ), '<i>' . $css_file . '</i>' ) . ' ';
1318 } else {
1319 $error .= __( 'Not enough permissions to create or update the file', 'bestwebsoft' ) . ' ' . $real_css_file . '. ';
1320 }
1321
1322 /* PHP */
1323 $newcontent_php = wp_unslash( trim( $_POST['bws_newcontent_php'] ) );
1324 if ( file_exists( $index_file ) ) {
1325 if ( ! empty( $newcontent_php ) && isset( $_REQUEST['bws_custom_php_active'] ) ) {
1326 if ( $is_multisite )
1327 $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $php_file ] = $real_php_file;
1328 else
1329 $bstwbsftwppdtplgns_options['custom_code'][ $php_file ] = $real_php_file;
1330 } else {
1331 if ( $is_multisite ) {
1332 if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $php_file ] ) )
1333 unset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $php_file ] );
1334 } else {
1335 if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $php_file ] ) )
1336 unset( $bstwbsftwppdtplgns_options['custom_code'][ $php_file ] );
1337 }
1338 }
1339
1340 if ( $f = fopen( $real_php_file, 'w+' ) ) {
1341 $newcontent_php = $newcontent_php;
1342 fwrite( $f, $newcontent_php );
1343 fclose( $f );
1344 $message .= sprintf( __( 'File %s edited successfully.', 'bestwebsoft' ), '<i>' . $php_file . '</i>' );
1345 } else {
1346 $error .= __( 'Not enough permissions to create or update the file', 'bestwebsoft' ) . ' ' . $real_php_file . '. ';
1347 }
1348 } else {
1349 $error .= __( 'Not enough permissions to create the file', 'bestwebsoft' ) . ' ' . $index_file . '. ';
1350 }
1351
1352 if ( ! empty( $error ) )
1353 $error .= ' <a href="https://codex.wordpress.org/Changing_File_Permissions" target="_blank">' . __( 'Learn more', 'bestwebsoft' ) . '</a>';
1354
1355 if ( $is_multisite )
1356 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1357 else
1358 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1359 }
1360
1361 if ( file_exists( $real_css_file ) ) {
1362 update_recently_edited( $real_css_file );
1363 $content_css = esc_textarea( file_get_contents( $real_css_file ) );
1364 if ( ( $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $css_file ] ) ) ||
1365 ( ! $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $css_file ] ) ) ) {
1366 $is_css_active = true;
1367 }
1368 }
1369 if ( file_exists( $real_php_file ) ) {
1370 update_recently_edited( $real_php_file );
1371 $content_php = esc_textarea( file_get_contents( $real_php_file ) );
1372 if ( ( $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $php_file ] ) ) ||
1373 ( ! $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $php_file ] ) ) ) {
1374 $is_php_active = true;
1375 }
1376 } else {
1377 $content_php = "<?php" . "\n" . "if ( ! defined( 'ABSPATH' ) ) exit;" . "\n" . "if ( ! defined( 'BWS_GLOBAL' ) ) exit;" . "\n\n" . "/* Start your code here */" . "\n";
1378 }
1379
1380 if ( ! empty( $message ) ) { ?>
1381 <div id="message" class="below-h2 updated notice is-dismissible"><p><?php echo $message; ?></p></div>
1382 <?php } ?>
1383 <form action="" method="post">
1384 <?php foreach ( array( 'css', 'php' ) as $extension ) { ?>
1385 <p>
1386 <?php if ( 'css' == $extension )
1387 _e( 'These styles will be added to the header on all pages of your site.', 'bestwebsoft' );
1388 else
1389 printf( __( 'These PHP code will be hooked to the %s action and will be printed on front end only.', 'bestwebsoft' ), '<a href="http://codex.wordpress.org/Plugin_API/Action_Reference/init" target="_blank"><code>init</code></a>' ); ?>
1390 </p>
1391 <p><big>
1392 <?php if ( ! file_exists( ${"real_{$extension}_file"} ) || ( is_writeable( ${"real_{$extension}_file"} ) ) ) {
1393 echo __( 'Editing', 'bestwebsoft' ) . ' <strong>' . ${"{$extension}_file"} . '</strong>';
1394 } else {
1395 echo __( 'Browsing', 'bestwebsoft' ) . ' <strong>' . ${"{$extension}_file"} . '</strong>';
1396 } ?>
1397 </big></p>
1398 <p><label><input type="checkbox" name="bws_custom_<?php echo $extension; ?>_active" value="1" <?php if ( ${"is_{$extension}_active"} ) echo "checked"; ?> /> <?php _e( 'Activate', 'bestwebsoft' ); ?></label></p>
1399 <textarea cols="70" rows="25" name="bws_newcontent_<?php echo $extension; ?>" id="bws_newcontent_<?php echo $extension; ?>"><?php if ( isset( ${"content_{$extension}"} ) ) echo ${"content_{$extension}"}; ?></textarea>
1400 <p class="description">
1401 <a href="<?php echo ( 'css' == $extension ) ? 'https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started' : 'http://php.net/' ?>" target="_blank">
1402 <?php printf( __( 'Learn more about %s', 'bestwebsoft' ), strtoupper( $extension ) ); ?>
1403 </a>
1404 </p>
1405 <?php }
1406 if ( ( ! file_exists( $real_css_file ) || is_writeable( $real_css_file ) ) && ( ! file_exists( $real_php_file ) || is_writeable( $real_php_file ) ) ) { ?>
1407 <p class="submit">
1408 <input type="hidden" name="bws_update_custom_code" value="submit" />
1409 <?php submit_button( __( 'Save Changes', 'bestwebsoft' ), 'primary', 'submit', false );
1410 wp_nonce_field( 'bws_update_' . $css_file ); ?>
1411 </p>
1412 <?php } else { ?>
1413 <p><em><?php printf( __( 'You need to make this files writable before you can save your changes. See %s the Codex %s for more information.', 'bestwebsoft' ),
1414 '<a href="https://codex.wordpress.org/Changing_File_Permissions" target="_blank">',
1415 '</a>' ); ?></em></p>
1416 <?php } ?>
1417 </form>
1418 <?php }
1419 }
1420
1421 if ( ! function_exists( 'bws_enqueue_custom_code_css' ) ) {
1422 function bws_enqueue_custom_code_css() {
1423 global $bstwbsftwppdtplgns_options;
1424
1425 if ( ! isset( $bstwbsftwppdtplgns_options ) )
1426 $bstwbsftwppdtplgns_options = ( function_exists( 'is_multisite' ) && is_multisite() ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
1427
1428 if ( ! empty( $bstwbsftwppdtplgns_options['custom_code'] ) ) {
1429 $is_multisite = is_multisite();
1430 if ( $is_multisite )
1431 $blog_id = get_current_blog_id();
1432
1433 if ( ! $is_multisite && ! empty( $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.css'] ) )
1434 wp_enqueue_style( 'bws-custom-style', $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.css'] );
1435 elseif ( $is_multisite && ! empty( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.css'] ) )
1436 wp_enqueue_style( 'bws-custom-style', $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.css'] );
1437 }
1438 }
1439 }
1440
1441 if ( ! function_exists( 'bws_enqueue_custom_code_php' ) ) {
1442 function bws_enqueue_custom_code_php() {
1443 if ( is_admin() )
1444 return;
1445
1446 global $bstwbsftwppdtplgns_options;
1447
1448 if ( ! isset( $bstwbsftwppdtplgns_options ) )
1449 $bstwbsftwppdtplgns_options = ( function_exists( 'is_multisite' ) && is_multisite() ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
1450
1451 if ( ! empty( $bstwbsftwppdtplgns_options['custom_code'] ) ) {
1452
1453 $is_multisite = is_multisite();
1454 if ( $is_multisite )
1455 $blog_id = get_current_blog_id();
1456
1457 if ( ! $is_multisite && ! empty( $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.php'] ) ) {
1458
1459 if ( file_exists( $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.php'] ) ) {
1460 define( 'BWS_GLOBAL', true );
1461 require_once( $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.php'] );
1462 } else {
1463 unset( $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.php'] );
1464 if ( $is_multisite )
1465 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1466 else
1467 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1468 }
1469 } elseif ( $is_multisite && ! empty( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.php'] ) ) {
1470 if ( file_exists( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.php'] ) ) {
1471 define( 'BWS_GLOBAL', true );
1472 require_once( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.php'] );
1473 } else {
1474 unset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.php'] );
1475 if ( $is_multisite )
1476 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1477 else
1478 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1479 }
1480 }
1481 }
1482 }
1483 }
1484
1485 if ( ! function_exists( 'bws_delete_plugin' ) ) {
1486 function bws_delete_plugin( $basename ) {
1487 global $bstwbsftwppdtplgns_options;
1488
1489 $is_multisite = is_multisite();
1490 if ( $is_multisite )
1491 $blog_id = get_current_blog_id();
1492
1493 if ( ! isset( $bstwbsftwppdtplgns_options ) )
1494 $bstwbsftwppdtplgns_options = ( $is_multisite ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
1495
1496 /* remove bws_menu versions */
1497 unset( $bstwbsftwppdtplgns_options['bws_menu']['version'][ $basename ] );
1498 /* if empty ['bws_menu']['version'] - there is no other bws plugins - delete all */
1499 if ( empty( $bstwbsftwppdtplgns_options['bws_menu']['version'] ) ) {
1500 /* remove options */
1501 if ( $is_multisite )
1502 delete_site_option( 'bstwbsftwppdtplgns_options' );
1503 else
1504 delete_option( 'bstwbsftwppdtplgns_options' );
1505
1506 /* remove custom_code */
1507 if ( $is_multisite ) {
1508 global $wpdb;
1509 $old_blog = $wpdb->blogid;
1510 /* Get all blog ids */
1511 $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" );
1512 foreach ( $blogids as $blog_id ) {
1513 switch_to_blog( $blog_id );
1514 $upload_dir = wp_upload_dir();
1515 $folder = $upload_dir['basedir'] . '/bws-custom-code';
1516 if ( file_exists( $folder ) && is_dir( $folder ) ) {
1517 array_map( 'unlink', glob( "$folder/*" ) );
1518 rmdir( $folder );
1519 }
1520 }
1521 switch_to_blog( $old_blog );
1522 } else {
1523 $upload_dir = wp_upload_dir();
1524 $folder = $upload_dir['basedir'] . '/bws-custom-code';
1525 if ( file_exists( $folder ) && is_dir( $folder ) ) {
1526 array_map( 'unlink', glob( "$folder/*" ) );
1527 rmdir( $folder );
1528 }
1529 }
1530 }
1531 }
1532 }
1533
1534 add_action( 'admin_init', 'bws_plugins_admin_init' );
1535 add_action( 'admin_enqueue_scripts', 'bws_admin_enqueue_scripts' );
1536 add_action( 'admin_head', 'bws_plugins_admin_head' );
1537 add_action( 'admin_footer','bws_shortcode_media_button_popup' );
1538
1539 add_action( 'admin_notices', 'bws_admin_notices', 30 );
1540
1541 add_action( 'wp_enqueue_scripts', 'bws_enqueue_custom_code_css', 20 );
1542
1543 bws_enqueue_custom_code_php();