PluginProbe
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin / 1.9.1
PDF & Print by BestWebSoft – WordPress Posts and Pages PDF Generator Plugin v1.9.1
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.9.1, at bws_menu/bws_functions.php

1,586 lines 73.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/logo-white-min.png', __FILE__ ), '1001' );
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=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 if ( ! empty( $result['pro_plugin_is_activated'] ) )
422 delete_transient( 'bws_plugins_update' );
423 }
424 } else {
425 $result['error'] = __( "Please, enter Your license key", 'bestwebsoft' );
426 }
427 }
428 return $result;
429 }
430 }
431
432 /**
433 * Function display GO PRO tab - for old plugin version
434 * @deprecated 1.7.6
435 */
436 if ( ! function_exists( 'bws_go_pro_tab' ) ) {
437 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 ) {
438 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 );
439 }
440 }
441
442 /**
443 * Function display GO PRO tab
444 */
445 if ( ! function_exists( 'bws_go_pro_tab_show' ) ) {
446 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 ) {
447 global $wp_version, $bstwbsftwppdtplgns_options;
448 $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : "";
449 if ( $pro_plugin_is_activated ) { ?>
450 <script type="text/javascript">
451 window.setTimeout( function() {
452 window.location.href = 'admin.php?page=<?php echo $pro_page; ?>';
453 }, 5000 );
454 </script>
455 <p><?php _e( "Congratulations! Pro version of the plugin is successfully installed and activated.", 'bestwebsoft' ); ?></p>
456 <p>
457 <?php _e( "Please, go to", 'bestwebsoft' ); ?> <a href="admin.php?page=<?php echo $pro_page; ?>"><?php _e( 'the setting page', 'bestwebsoft' ); ?></a>
458 (<?php _e( "You will be redirected automatically in 5 seconds.", 'bestwebsoft' ); ?>)
459 </p>
460 <?php } else {
461 if ( $bws_hide_premium_options_check ) { ?>
462 <form method="post" action="">
463 <p>
464 <input type="hidden" name="bws_hide_premium_options_submit" value="submit" />
465 <input type="submit" class="button" value="<?php _e( 'Show Pro features', 'bestwebsoft' ); ?>" />
466 <?php wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?>
467 </p>
468 </form>
469 <?php } ?>
470 <form method="post" action="">
471 <p>
472 <?php _e( 'Enter your license key to install and activate', 'bestwebsoft' ); ?>
473 <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>
474 <?php _e( 'version of the plugin.', 'bestwebsoft' ); ?><br />
475 <span class="bws_info">
476 <?php _e( 'License key can be found in the', 'bestwebsoft' ); ?>
477 <a href="http://bestwebsoft.com/wp-login.php">Client Area</a>
478 <?php _e( '(your username is the email address specified during the purchase).', 'bestwebsoft' ); ?>
479 </span>
480 </p>
481 <?php if ( $trial_days_number !== false )
482 $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>';
483 if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] ) &&
484 '5' < $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] &&
485 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] > ( time() - ( 24 * 60 * 60 ) ) ) { ?>
486 <p>
487 <input disabled="disabled" type="text" name="bws_license_key" value="<?php echo $bws_license_key; ?>" />
488 <input disabled="disabled" type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" />
489 <?php if ( $trial_days_number !== false ) echo $trial_days_number; ?>
490 </p>
491 <p><?php _e( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' ); ?></p>
492 <?php } else { ?>
493 <p>
494 <input type="text" maxlength="100" name="bws_license_key" value="<?php echo $bws_license_key; ?>" />
495 <input type="hidden" name="bws_license_plugin" value="<?php echo $bws_license_plugin; ?>" />
496 <input type="hidden" name="bws_license_submit" value="submit" />
497 <input type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" />
498 <?php if ( $trial_days_number !== false ) echo $trial_days_number;
499 wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?>
500 </p>
501 <?php } ?>
502 </form>
503 <?php }
504 }
505 }
506
507 if ( ! function_exists( 'bws_go_pro_from_trial_tab' ) ) {
508 function bws_go_pro_from_trial_tab( $plugin_info, $plugin_basename, $page, $link_slug, $link_key, $link_pn, $trial_license_is_set = true ) {
509 global $wp_version, $bstwbsftwppdtplgns_options;
510 $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : "";
511 if ( $trial_license_is_set ) { ?>
512 <form method="post" action="">
513 <p>
514 <?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>' ) . ' ';
515 _e( 'After that you can activate it by entering your license key.', 'bestwebsoft' ); ?><br />
516 <span class="bws_info">
517 <?php _e( 'License key can be found in the', 'bestwebsoft' ); ?>
518 <a href="http://bestwebsoft.com/wp-login.php">Client Area</a>
519 <?php _e( '(your username is the email address specified during the purchase).', 'bestwebsoft' ); ?>
520 </span>
521 </p>
522 <?php if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $plugin_basename ]['count'] ) &&
523 '5' < $bstwbsftwppdtplgns_options['go_pro'][ $plugin_basename ]['count'] &&
524 $bstwbsftwppdtplgns_options['go_pro'][ $plugin_basename ]['time'] > ( time() - ( 24 * 60 * 60 ) ) ) { ?>
525 <p>
526 <input disabled="disabled" type="text" name="bws_license_key" value="" />
527 <input disabled="disabled" type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" />
528 </p>
529 <p><?php _e( "Unfortunately, you have exceeded the number of available tries per day.", 'bestwebsoft' ); ?></p>
530 <?php } else { ?>
531 <p>
532 <input type="text" maxlength="100" name="bws_license_key" value="" />
533 <input type="hidden" name="bws_license_plugin" value="<?php echo $plugin_basename; ?>" />
534 <input type="hidden" name="bws_license_submit" value="submit" />
535 <input type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" />
536 <?php wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?>
537 </p>
538 <?php } ?>
539 </form>
540 <?php } else { ?>
541 <script type="text/javascript">
542 window.setTimeout( function() {
543 window.location.href = 'admin.php?page=<?php echo $page; ?>';
544 }, 5000 );
545 </script>
546 <p><?php _e( "Congratulations! The Pro license of the plugin is successfully activated.", 'bestwebsoft' ); ?></p>
547 <p>
548 <?php _e( "Please, go to", 'bestwebsoft' ); ?> <a href="admin.php?page=<?php echo $page; ?>"><?php _e( 'the setting page', 'bestwebsoft' ); ?></a>
549 (<?php _e( "You will be redirected automatically in 5 seconds.", 'bestwebsoft' ); ?>)
550 </p>
551 <?php }
552 }
553 }
554
555 if ( ! function_exists( 'bws_check_pro_license' ) ) {
556 function bws_check_pro_license( $plugin_basename, $trial_plugin = false ) {
557 global $wp_version, $bstwbsftwppdtplgns_options;
558 $result = array();
559
560 if ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) {
561 $license_key = isset( $_POST['bws_license_key'] ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : '';
562
563 if ( '' != $license_key ) {
564
565 delete_transient( 'bws_plugins_update' );
566
567 if ( ! function_exists( 'get_plugins' ) )
568 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
569 $plugins_all = get_plugins();
570 $current = get_site_transient( 'update_plugins' );
571
572 if ( is_array( $plugins_all ) && !empty( $plugins_all ) && isset( $current ) && is_array( $current->response ) ) {
573 $to_send = array();
574 $to_send["plugins"][ $plugin_basename ] = $plugins_all[ $plugin_basename ];
575 $to_send["plugins"][ $plugin_basename ]["bws_license_key"] = $license_key;
576 $to_send["plugins"][ $plugin_basename ]["bws_illegal_client"] = true;
577 $options = array(
578 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
579 'body' => array( 'plugins' => serialize( $to_send ) ),
580 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
581 );
582 $raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options );
583 if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
584 $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' );
585 } else {
586 $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );
587 if ( is_array( $response ) && !empty( $response ) ) {
588 foreach ( $response as $key => $value ) {
589 if ( "wrong_license_key" == $value->package ) {
590 $result['error'] = __( 'Wrong license key.', 'bestwebsoft' );
591 } else if ( "wrong_domain" == $value->package ) {
592 $result['error'] = __( 'This license key is bind to another site.', 'bestwebsoft' );
593 } else if ( "time_out" == $value->package ) {
594 $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' );
595 } elseif ( "you_are_banned" == $value->package ) {
596 $result['error'] = __( "Unfortunately, you have exceeded the number of available tries.", 'bestwebsoft' );
597 } elseif ( "duplicate_domen_for_trial" == $value->package ) {
598 $result['error'] = __( "Unfortunately, the Pro Trial licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' );
599 }
600 if ( empty( $result['message'] ) && empty( $result['error'] ) ) {
601 if ( isset( $value->trial ) )
602 $result['message'] = __( 'The Pro Trial license key is valid.', 'bestwebsoft' );
603 else
604 $result['message'] = __( 'The license key is valid.', 'bestwebsoft' );
605
606 if ( ! empty( $value->time_out ) )
607 $result['message'] .= ' ' . __( 'Your license will expire on', 'bestwebsoft' ) . ' ' . $value->time_out . '.';
608
609 if ( isset( $value->trial ) && $trial_plugin != false )
610 $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>' );
611
612 if ( isset( $value->trial ) ) {
613 $bstwbsftwppdtplgns_options['trial'][ $plugin_basename ] = 1;
614 } else {
615 unset( $bstwbsftwppdtplgns_options['trial'][ $plugin_basename ] );
616 }
617 }
618 if ( empty( $result['error'] ) ) {
619 if ( $bstwbsftwppdtplgns_options[ $plugin_basename ] != $license_key ) {
620 $bstwbsftwppdtplgns_options[ $plugin_basename ] = $license_key;
621
622 $file = @fopen( dirname( dirname( __FILE__ ) ) . "/license_key.txt" , "w+" );
623 if ( $file ) {
624 @fwrite( $file, $license_key );
625 @fclose( $file );
626 }
627 $update_option = true;
628 }
629
630 if ( $bstwbsftwppdtplgns_options['time_out'][ $plugin_basename ] != $value->time_out ) {
631 $bstwbsftwppdtplgns_options['time_out'][ $plugin_basename ] = $value->time_out;
632 $update_option = true;
633 }
634
635 if ( isset( $update_option ) ) {
636 if ( is_multisite() )
637 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
638 else
639 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
640 }
641 }
642 }
643 } else {
644 $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' );
645 }
646 }
647 }
648 } else {
649 $result['error'] = __( 'Please, enter your license key', 'bestwebsoft' );
650 }
651 }
652 return $result;
653 }
654 }
655
656 if ( ! function_exists ( 'bws_check_pro_license_form' ) ) {
657 function bws_check_pro_license_form( $plugin_basename ) {
658 global $bstwbsftwppdtplgns_options;
659 $license_key = ( isset( $bstwbsftwppdtplgns_options[ $plugin_basename ] ) ) ? $bstwbsftwppdtplgns_options[ $plugin_basename ] : ''; ?>
660 <div class="clear"></div>
661 <form method="post" action="">
662 <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>
663 <p>
664 <input type="text" maxlength="100" name="bws_license_key" value="<?php echo $license_key; ?>" />
665 <input type="hidden" name="bws_license_submit" value="submit" />
666 <input type="submit" class="button" value="<?php _e( 'Check license key', 'bestwebsoft' ) ?>" />
667 <?php wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?>
668 </p>
669 </form>
670 <?php }
671 }
672
673 if ( ! function_exists ( 'bws_plugin_update_row' ) ) {
674 function bws_plugin_update_row( $plugin_key, $link_slug = false, $free_plugin_name = false ) {
675 global $bstwbsftwppdtplgns_options, $wp_version;
676 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
677 if ( isset( $bstwbsftwppdtplgns_options['wrong_license_key'][ $plugin_key ] ) ) {
678 $explode_plugin_key = explode( '/', $plugin_key );
679 $class = ( $wp_version >= 4.6 ) ? 'active' : '';
680 $style = ( $wp_version < 4.6 ) ? ' style="background-color: #FFEBE8;border-color: #CC0000;"' : '';
681 $div_class = ( $wp_version >= 4.6 ) ? ' notice inline notice-warning notice-alt' : '';
682 echo '<tr class="bws-plugin-update-tr plugin-update-tr ' . $class . '" id="' . $explode_plugin_key[0] . '-update" data-slug="' . $explode_plugin_key[0] . '" data-plugin="' . $plugin_key . '">
683 <td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
684 <div class="update-message' . $div_class . '"' . $style . '>';
685 if ( $wp_version >= 4.6 )
686 echo '<p>';
687 echo '<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>';
688 if ( $wp_version >= 4.6 )
689 echo '</p>';
690 echo '</div>
691 </td>
692 </tr>';
693 } elseif ( isset( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) && strtotime( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) < strtotime( date("m/d/Y") ) ) {
694 $explode_plugin_key = explode( '/', $plugin_key );
695 $class = ( $wp_version >= 4.6 ) ? 'active' : '';
696 $style = ( $wp_version < 4.6 ) ? ' style="color: #8C0000;"' : '';
697 $div_class = ( $wp_version >= 4.6 ) ? ' notice inline notice-warning notice-alt' : '';
698 echo '<tr class="bws-plugin-update-tr plugin-update-tr ' . $class . '" id="' . $explode_plugin_key[0] . '-update" data-slug="' . $explode_plugin_key[0] . '" data-plugin="' . $plugin_key . '">
699 <td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
700 <div class="update-message' . $div_class . '"' . $style . '>';
701 if ( $wp_version >= 4.6 )
702 echo '<p>';
703 if ( isset( $bstwbsftwppdtplgns_options['trial'][ $plugin_key ] ) && $link_slug != false ) {
704 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>';
705 } else {
706 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>';
707 }
708 if ( $wp_version >= 4.6 )
709 echo '</p>';
710 echo '</div>
711 </td>
712 </tr>';
713 } elseif ( isset( $bstwbsftwppdtplgns_options['trial'][ $plugin_key ] ) ) {
714 $explode_plugin_key = explode( '/', $plugin_key );
715 $class = ( $wp_version >= 4.6 ) ? 'active' : '';
716 $style = ( $wp_version < 4.6 ) ? ' style="color: #8C0000;"' : '';
717 $div_class = ( $wp_version >= 4.6 ) ? ' notice inline notice-warning notice-alt' : '';
718 echo '<tr class="bws-plugin-update-tr plugin-update-tr ' . $class . '" id="' . $explode_plugin_key[0] . '-update" data-slug="' . $explode_plugin_key[0] . '" data-plugin="' . $plugin_key . '">
719 <td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
720 <div class="update-message' . $div_class . '"' . $style . '>';
721 if ( $wp_version >= 4.6 )
722 echo '<p>';
723 if ( $free_plugin_name != false ) {
724 echo sprintf( __( 'Notice: You are using the Pro Trial license of %s plugin.', 'bestwebsoft' ), $free_plugin_name );
725 } else {
726 _e( 'Notice: You are using the Pro Trial license of plugin.', 'bestwebsoft' );
727 }
728 if ( isset( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) )
729 echo ' ' . __( "The Pro Trial license will expire on", 'bestwebsoft' ) . ' ' . $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] . '.';
730 if ( $wp_version >= 4.6 )
731 echo '</p>';
732 echo '</div>
733 </td>
734 </tr>';
735 }
736 }
737 }
738
739 if ( ! function_exists ( 'bws_plugin_banner_timeout' ) ) {
740 function bws_plugin_banner_timeout( $plugin_key, $plugin_prefix, $plugin_name, $banner_url = false ) {
741 global $bstwbsftwppdtplgns_options, $bstwbsftwppdtplgns_cookie_add;
742 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") ) ) ) {
743 if ( ! isset( $bstwbsftwppdtplgns_cookie_add ) ) {
744 echo '<script type="text/javascript" src="' . plugins_url( 'js/c_o_o_k_i_e.js', __FILE__ ) . '"></script>';
745 $bstwbsftwppdtplgns_cookie_add = true;
746 } ?>
747 <script type="text/javascript">
748 (function($) {
749 $(document).ready( function() {
750 var hide_message = $.cookie( "<?php echo $plugin_prefix; ?>_timeout_hide_banner_on_plugin_page" );
751 if ( hide_message == "true" ) {
752 $( ".<?php echo $plugin_prefix; ?>_message" ).css( "display", "none" );
753 } else {
754 $( ".<?php echo $plugin_prefix; ?>_message" ).css( "display", "block" );
755 }
756 $( ".<?php echo $plugin_prefix; ?>_close_icon" ).click( function() {
757 $( ".<?php echo $plugin_prefix; ?>_message" ).css( "display", "none" );
758 $.cookie( "<?php echo $plugin_prefix; ?>_timeout_hide_banner_on_plugin_page", "true", { expires: 30 } );
759 });
760 });
761 })(jQuery);
762 </script>
763 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
764 <div class="<?php echo $plugin_prefix; ?>_message bws_banner_on_plugin_page bws_banner_timeout" style="display:none;">
765 <button class="<?php echo $plugin_prefix; ?>_close_icon close_icon notice-dismiss bws_hide_settings_notice" title="<?php _e( 'Close notice', 'bestwebsoft' ); ?>"></button>
766 <div class="icon">
767 <img title="" src="<?php echo $banner_url; ?>" alt="" />
768 </div>
769 <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>
770 </div>
771 </div>
772 <?php }
773 }
774 }
775
776 if ( ! function_exists( 'bws_plugin_banner_to_settings' ) ) {
777 function bws_plugin_banner_to_settings( $plugin_info, $plugin_options_name, $banner_url_or_slug, $settings_url, $post_type_url = false ) {
778 global $wp_version, $bws_plugin_banner_to_settings;
779
780 $is_network_admin = is_network_admin();
781
782 $plugin_options = $is_network_admin ? get_site_option( $plugin_options_name ) : get_option( $plugin_options_name );
783
784 if ( isset( $plugin_options['display_settings_notice'] ) && 0 == $plugin_options['display_settings_notice'] )
785 return;
786
787 if ( isset( $_POST['bws_hide_settings_notice_' . $plugin_options_name ] ) && check_admin_referer( plugin_basename( __FILE__ ), 'bws_settings_nonce_name' ) ) {
788 $plugin_options['display_settings_notice'] = 0;
789 if ( $is_network_admin )
790 update_site_option( $plugin_options_name, $plugin_options );
791 else
792 update_option( $plugin_options_name, $plugin_options );
793 return;
794 }
795
796 if ( false == strrpos( $banner_url_or_slug, '/' ) ) {
797 $banner_url_or_slug = '//ps.w.org/' . $banner_url_or_slug . '/assets/icon-128x128.png';
798 }
799
800 $bws_plugin_banner_to_settings[] = array(
801 'plugin_info' => $plugin_info,
802 'plugin_options_name' => $plugin_options_name,
803 'banner_url' => $banner_url_or_slug,
804 'settings_url' => $settings_url,
805 'post_type_url' => $post_type_url
806 );
807 }
808 }
809
810 if ( ! function_exists( 'bws_plugin_suggest_feature_banner' ) ) {
811 function bws_plugin_suggest_feature_banner( $plugin_info, $plugin_options_name, $banner_url_or_slug ) {
812 global $wp_version;
813
814 $is_network_admin = is_network_admin();
815
816 $plugin_options = $is_network_admin ? get_site_option( $plugin_options_name ) : get_option( $plugin_options_name );
817
818 if ( isset( $plugin_options['display_suggest_feature_banner'] ) && 0 == $plugin_options['display_suggest_feature_banner'] )
819 return;
820
821 if ( ! isset( $plugin_options['first_install'] ) ) {
822 $plugin_options['first_install'] = strtotime( "now" );
823 $update_option = $return = true;
824 } elseif ( strtotime( '-2 week' ) < $plugin_options['first_install'] ) {
825 $return = true;
826 }
827
828 if ( ! isset( $plugin_options['go_settings_counter'] ) ) {
829 $plugin_options['go_settings_counter'] = 1;
830 $update_option = $return = true;
831 } elseif ( 20 > $plugin_options['go_settings_counter'] ) {
832 $plugin_options['go_settings_counter'] = $plugin_options['go_settings_counter'] + 1;
833 $update_option = $return = true;
834 }
835
836 if ( isset( $update_option ) ) {
837 if ( $is_network_admin )
838 update_site_option( $plugin_options_name, $plugin_options );
839 else
840 update_option( $plugin_options_name, $plugin_options );
841 }
842
843 if ( isset( $return ) )
844 return;
845
846 if ( isset( $_POST['bws_hide_suggest_feature_banner_' . $plugin_options_name ] ) && check_admin_referer( $plugin_info['Name'], 'bws_settings_nonce_name' ) ) {
847 $plugin_options['display_suggest_feature_banner'] = 0;
848 if ( $is_network_admin )
849 update_site_option( $plugin_options_name, $plugin_options );
850 else
851 update_option( $plugin_options_name, $plugin_options );
852 return;
853 }
854
855 if ( false == strrpos( $banner_url_or_slug, '/' ) ) {
856 $banner_url_or_slug = '//ps.w.org/' . $banner_url_or_slug . '/assets/icon-128x128.png';
857 } ?>
858 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
859 <div class="bws_banner_on_plugin_page bws_suggest_feature_banner">
860 <div class="icon">
861 <img title="" src="<?php echo esc_attr( $banner_url_or_slug ); ?>" alt="" />
862 </div>
863 <div class="text">
864 <strong><?php _e( 'Thank you for choosing', 'bestwebsoft' ); ?> <?php echo $plugin_info['Name']; ?> plugin!</strong><br />
865 <?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' ); ?>
866 <a target="_blank" href="http://support.bestwebsoft.com/hc/en-us/requests/new"><?php _e( 'Suggest a Feature', 'bestwebsoft' ); ?></a>
867 </div>
868 <form action="" method="post">
869 <button class="notice-dismiss bws_hide_settings_notice" title="<?php _e( 'Close notice', 'bestwebsoft' ); ?>"></button>
870 <input type="hidden" name="bws_hide_suggest_feature_banner_<?php echo $plugin_options_name; ?>" value="hide" />
871 <?php wp_nonce_field( $plugin_info['Name'], 'bws_settings_nonce_name' ); ?>
872 </form>
873 </div>
874 </div>
875 <?php }
876 }
877
878 if ( ! function_exists( 'bws_show_settings_notice' ) ) {
879 function bws_show_settings_notice() { ?>
880 <div id="bws_save_settings_notice" class="updated fade below-h2" style="display:none;">
881 <p>
882 <strong><?php _e( 'Notice', 'bestwebsoft' ); ?></strong>: <?php _e( "The plugin's settings have been changed.", 'bestwebsoft' ); ?>
883 <a class="bws_save_anchor" href="#bws-submit-button"><?php _e( 'Save Changes', 'bestwebsoft' ); ?></a>
884 </p>
885 </div>
886 <?php }
887 }
888
889 if ( ! function_exists( 'bws_hide_premium_options' ) ) {
890 function bws_hide_premium_options( $options ) {
891 if ( ! isset( $options['hide_premium_options'] ) || ! is_array( $options['hide_premium_options'] ) )
892 $options['hide_premium_options'] = array();
893
894 $options['hide_premium_options'][] = get_current_user_id();
895
896 return array(
897 'message' => __( 'You can always look at premium options by clicking on the "Show Pro features" in the "Go PRO" tab', 'bestwebsoft' ),
898 'options' => $options );
899 }
900 }
901
902 if ( ! function_exists( 'bws_hide_premium_options_check' ) ) {
903 function bws_hide_premium_options_check( $options ) {
904 if ( ! empty( $options['hide_premium_options'] ) && in_array( get_current_user_id(), $options['hide_premium_options'] ) )
905 return true;
906 else
907 return false;
908 }
909 }
910
911 if ( ! function_exists ( 'bws_plugins_admin_init' ) ) {
912 function bws_plugins_admin_init() {
913
914 if ( isset( $_GET['bws_activate_plugin'] ) && check_admin_referer( 'bws_activate_plugin' . $_GET['bws_activate_plugin'] ) ) {
915
916 $plugin = isset( $_GET['bws_activate_plugin'] ) ? $_GET['bws_activate_plugin'] : '';
917 $result = activate_plugin( $plugin, '', is_network_admin() );
918 if ( is_wp_error( $result ) ) {
919 if ( 'unexpected_output' == $result->get_error_code() ) {
920 $redirect = self_admin_url( 'admin.php?page=bws_panel&error=true&charsout=' . strlen( $result->get_error_data() ) . '&plugin=' . $plugin );
921 wp_redirect( add_query_arg( '_error_nonce', wp_create_nonce( 'plugin-activation-error_' . $plugin ), $redirect ) );
922 exit();
923 } else {
924 wp_die( $result );
925 }
926 }
927
928 if ( ! is_network_admin() ) {
929 $recent = (array) get_option( 'recently_activated' );
930 unset( $recent[ $plugin ] );
931 update_option( 'recently_activated', $recent );
932 } else {
933 $recent = (array) get_site_option( 'recently_activated' );
934 unset( $recent[ $plugin ] );
935 update_site_option( 'recently_activated', $recent );
936 }
937 wp_redirect( self_admin_url( 'admin.php?page=bws_panel&activate=true' ) );
938 exit();
939 }
940
941 if ( isset( $_GET['page'] ) && $_GET['page'] == 'bws_panel' ) {
942 if ( ! session_id() )
943 @session_start();
944 }
945
946 bws_add_editor_buttons();
947 }
948 }
949
950 if ( ! function_exists ( 'bws_admin_enqueue_scripts' ) ) {
951 function bws_admin_enqueue_scripts() {
952 global $wp_version;
953 wp_enqueue_style( 'bws-admin-css', plugins_url( 'css/general_style.css', __FILE__ ) );
954 wp_enqueue_script( 'bws-admin-scripts', plugins_url( 'js/general_script.js', __FILE__ ), array( 'jquery' ) );
955
956 if ( isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'bws_panel', 'bws_themes', 'bws_system_status' ) ) ) {
957 wp_enqueue_style( 'bws_menu_style', plugins_url( 'css/style.css', __FILE__ ) );
958 wp_enqueue_script( 'bws_menu_script', plugins_url( 'js/bws_menu.js' , __FILE__ ) );
959 wp_enqueue_script( 'theme-install' );
960 add_thickbox();
961 wp_enqueue_script( 'plugin-install' );
962 }
963 }
964 }
965
966 if ( ! function_exists ( 'bws_plugins_admin_head' ) ) {
967 function bws_plugins_admin_head() {
968 global $bws_shortcode_list, $wp_version, $post_type;
969 if ( isset( $_GET['page'] ) && $_GET['page'] == "bws_panel" ) { ?>
970 <noscript>
971 <style type="text/css">
972 .bws_product_button {
973 display: inline-block;
974 }
975 </style>
976 </noscript>
977 <?php }
978 if ( 4.2 > $wp_version ) {
979 $plugin_dir_array = explode( '/', plugin_basename( __FILE__ ) );
980 $plugin_dir = $plugin_dir_array[0]; ?>
981 <style type="text/css">
982 .bws_hide_settings_notice,
983 .bws_hide_premium_options {
984 width: 11px;
985 height: 11px;
986 border: none;
987 background: url("<?php echo plugins_url( $plugin_dir . '/bws_menu/images/close_banner.png' ); ?>") no-repeat center center;
988 box-shadow: none;
989 float: right;
990 margin: 8px;
991 }
992 .bws_hide_settings_notice:hover,
993 .bws_hide_premium_options:hover {
994 cursor: pointer;
995 }
996 .bws_hide_premium_options {
997 position: relative;
998 }
999 </style>
1000 <?php }
1001 if ( ! empty( $bws_shortcode_list ) ) { ?>
1002 <!-- TinyMCE Shortcode Plugin -->
1003 <script type='text/javascript'>
1004 var bws_shortcode_button = {
1005 'label': '<?php esc_attr_e( "Add BWS Shortcode", "bestwebsoft" ); ?>',
1006 'title': '<?php esc_attr_e( "Add BWS Plugins Shortcode", "bestwebsoft" ); ?>',
1007 'icon_url': '<?php echo plugins_url( "images/shortcode-icon.png" , __FILE__ ); ?>',
1008 'function_name': [
1009 <?php foreach ( $bws_shortcode_list as $key => $value ) {
1010 if ( isset( $value['js_function'] ) )
1011 echo "'" . $value['js_function'] . "',";
1012 } ?>
1013 ],
1014 'wp_version' : '<?php echo $wp_version; ?>'
1015 };
1016 </script>
1017 <!-- TinyMCE Shortcode Plugin -->
1018 <?php if ( isset( $post_type ) && in_array( $post_type, array( 'post', 'page' ) ) ) {
1019 $tooltip_args = array(
1020 'tooltip_id' => 'bws_shortcode_button_tooltip',
1021 'css_selector' => '.mce-bws_shortcode_button',
1022 'actions' => array(
1023 'click' => false,
1024 'onload' => true
1025 ),
1026 'content' => '<h3>' . __( 'Add shortcode', 'bestwebsoft' ) . '</h3><p>' . __( "Add BestWebSoft plugins' shortcodes using this button.", 'bestwebsoft' ) . '</p>',
1027 'position' => array(
1028 'edge' => 'right'
1029 ),
1030 'set_timeout' => 2000
1031 );
1032 if ( $wp_version < '3.9' )
1033 $tooltip_args['css_selector'] = '.mce_add_bws_shortcode';
1034 bws_add_tooltip_in_admin( $tooltip_args );
1035 }
1036 }
1037 }
1038 }
1039
1040 if ( ! function_exists ( 'bws_plugins_include_codemirror' ) ) {
1041 function bws_plugins_include_codemirror() {
1042 wp_enqueue_style( 'codemirror.css', plugins_url( 'css/codemirror.css', __FILE__ ) );
1043 wp_enqueue_script( 'codemirror.js', plugins_url( 'js/codemirror.js', __FILE__ ), array( 'jquery' ) );
1044 }
1045 }
1046
1047 /**
1048 * Tooltip block
1049 */
1050 if ( ! function_exists( 'bws_add_tooltip_in_admin' ) ) {
1051 function bws_add_tooltip_in_admin( $tooltip_args = array() ) {
1052 new BWS_admin_tooltip( $tooltip_args );
1053 }
1054 }
1055
1056 if ( ! class_exists( 'BWS_admin_tooltip' ) ) {
1057 class BWS_admin_tooltip {
1058 private $tooltip_args;
1059
1060 public function __construct( $tooltip_args ) {
1061 global $wp_version;
1062 if ( 3.3 > $wp_version )
1063 return;
1064 /* Default arguments */
1065 $tooltip_args_default = array(
1066 'tooltip_id' => false,
1067 'css_selector' => false,
1068 'actions' => array(
1069 'click' => true,
1070 'onload' => false,
1071 ),
1072 'buttons' => array(
1073 'close' => array(
1074 'type' => 'dismiss',
1075 'text' => __( 'Close', 'bestwebsoft' ),
1076 ),
1077 ),
1078 'position' => array(
1079 'edge' => 'top',
1080 'align' => 'center',
1081 'pos-left' => 0,
1082 'pos-top' => 0,
1083 'zindex' => 10000
1084 ),
1085 'set_timeout' => 0
1086 );
1087 $tooltip_args = array_merge( $tooltip_args_default, $tooltip_args );
1088 /* Check that our merged array has default values */
1089 foreach ( $tooltip_args_default as $arg_key => $arg_value ) {
1090 if ( is_array( $arg_value ) ) {
1091 foreach ( $arg_value as $key => $value) {
1092 if ( ! isset( $tooltip_args[ $arg_key ][ $key ] ) ) {
1093 $tooltip_args[ $arg_key ][ $key ] = $tooltip_args_default[ $arg_key ][ $key ];
1094 }
1095 }
1096 }
1097 }
1098 /* Check if tooltip is dismissed */
1099 if ( true === $tooltip_args['actions']['onload'] ) {
1100 if ( in_array( $tooltip_args['tooltip_id'], array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) ) ) ) {
1101 $tooltip_args['actions']['onload'] = false;
1102 }
1103 }
1104 /* Check entered data */
1105 if ( false === $tooltip_args['tooltip_id'] || false === $tooltip_args['css_selector'] || ( false === $tooltip_args['actions']['click'] && false === $tooltip_args['actions']['onload'] ) ) {
1106 /* if not enough data to output a tooltip or both actions (click, onload) are false */
1107 return;
1108 } else {
1109 /* check position */
1110 if ( ! in_array( $tooltip_args['position']['edge'], array( 'left', 'right', 'top', 'bottom' ) ) ) {
1111 $tooltip_args['position']['edge'] = 'top';
1112 }
1113 if ( ! in_array( $tooltip_args['position']['align'], array( 'top', 'bottom', 'left', 'right', 'center', ) ) ) {
1114 $tooltip_args['position']['align'] = 'center';
1115 }
1116 }
1117 /* fix position */
1118 switch ( $tooltip_args['position']['edge'] ) {
1119 case 'left':
1120 case 'right':
1121 switch ( $tooltip_args['position']['align'] ) {
1122 case 'top':
1123 case 'bottom':
1124 $tooltip_args['position']['align'] = 'center';
1125 break;
1126 }
1127 break;
1128 case 'top':
1129 case 'bottom':
1130 if ( $tooltip_args['position']['align'] == 'left' ) {
1131 $tooltip_args['position']['pos-left'] -= 65;
1132 }
1133 break;
1134 }
1135 $this->tooltip_args = $tooltip_args;
1136 /* add styles and scripts */
1137 wp_enqueue_style( 'wp-pointer' );
1138 wp_enqueue_script( 'wp-pointer' );
1139 /* add script that displays our tooltip */
1140 add_action( 'admin_print_footer_scripts', array( $this, 'add_scripts' ) );
1141 }
1142
1143 /**
1144 * Display tooltip
1145 */
1146 public function add_scripts() {
1147 global $bstwbsftwppdtplgns_tooltip_script_add;
1148 if ( ! isset( $bstwbsftwppdtplgns_tooltip_script_add ) ) {
1149 echo '<script type="text/javascript" src="' . plugins_url( 'js/bws_tooltip.js', __FILE__ ) . '"></script>';
1150 $bstwbsftwppdtplgns_tooltip_script_add = true;
1151 }
1152 $tooltip_args = $this->tooltip_args; ?>
1153 <script type="text/javascript">
1154 (function($) {
1155 $(document).ready( function() {
1156 $.bwsTooltip( <?php echo json_encode( $tooltip_args ); ?> );
1157 })
1158 })(jQuery);
1159 </script>
1160 <?php }
1161 }
1162 }
1163
1164 if ( ! function_exists ( 'bws_form_restore_default_settings' ) ) {
1165 function bws_form_restore_default_settings( $plugin_basename, $change_permission_attr = '' ) { ?>
1166 <form method="post" action="">
1167 <p><?php _e( 'Restore all plugin settings to defaults', 'bestwebsoft' ); ?></p>
1168 <p>
1169 <input <?php echo $change_permission_attr; ?> type="submit" class="button" value="<?php _e( 'Restore settings', 'bestwebsoft' ); ?>" />
1170 </p>
1171 <input type="hidden" name="bws_restore_default" value="submit" />
1172 <?php wp_nonce_field( $plugin_basename, 'bws_settings_nonce_name' ); ?>
1173 </form>
1174 <?php }
1175 }
1176
1177 if ( ! function_exists ( 'bws_form_restore_default_confirm' ) ) {
1178 function bws_form_restore_default_confirm( $plugin_basename ) { ?>
1179 <div>
1180 <p><?php _e( 'Are you sure you want to restore all settings by default?', 'bestwebsoft' ) ?></p>
1181 <form method="post" action="">
1182 <p>
1183 <button class="button" name="bws_restore_confirm"><?php _e( 'Yes, restore all settings', 'bestwebsoft' ) ?></button>
1184 <button class="button" name="bws_restore_deny"><?php _e( 'No, go back to the settings page', 'bestwebsoft' ) ?></button>
1185 <?php wp_nonce_field( $plugin_basename, 'bws_settings_nonce_name' ); ?>
1186 </p>
1187 </form>
1188 </div>
1189 <?php }
1190 }
1191
1192 /* shortcode */
1193 if ( ! function_exists( 'bws_add_editor_buttons' ) ) {
1194 function bws_add_editor_buttons() {
1195 global $bws_shortcode_list, $wp_version;
1196 if ( $wp_version < '3.3' )
1197 return;
1198 if ( ! empty( $bws_shortcode_list ) && current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {
1199 add_filter( 'mce_external_plugins', 'bws_add_buttons' );
1200 add_filter( 'mce_buttons', 'bws_register_buttons' );
1201 }
1202 }
1203 }
1204
1205 if ( ! function_exists( 'bws_add_buttons' ) ){
1206 function bws_add_buttons( $plugin_array ) {
1207 $plugin_array['add_bws_shortcode'] = plugins_url( 'js/shortcode-button.js', __FILE__ );
1208 return $plugin_array;
1209 }
1210 }
1211
1212 if ( ! function_exists( 'bws_register_buttons' ) ) {
1213 function bws_register_buttons( $buttons ) {
1214 array_push( $buttons, 'add_bws_shortcode' ); /* dropcap', 'recentposts */
1215 return $buttons;
1216 }
1217 }
1218
1219 /* Generate inline content for the popup window when the "bws shortcode" button is clicked */
1220 if ( ! function_exists( 'bws_shortcode_media_button_popup' ) ) {
1221 function bws_shortcode_media_button_popup() {
1222 global $bws_shortcode_list, $wp_version;
1223 if ( $wp_version < '3.3' )
1224 return;
1225
1226 if ( ! empty( $bws_shortcode_list ) ) { ?>
1227 <div id="bws_shortcode_popup" style="display:none;">
1228 <div id="bws_shortcode_popup_block">
1229 <div id="bws_shortcode_select_plugin">
1230 <h4><?php _e( 'Plugin', 'bestwebsoft' ); ?></h4>
1231 <select name="bws_shortcode_select" id="bws_shortcode_select">
1232 <?php foreach ( $bws_shortcode_list as $key => $value ) { ?>
1233 <option value="<?php echo $key; ?>"><?php echo $value['name']; ?></option>
1234 <?php } ?>
1235 </select>
1236 </div>
1237 <div class="clear"></div>
1238 <div id="bws_shortcode_content">
1239 <h4><?php _e( 'Shortcode settings', 'bestwebsoft' ); ?></h4>
1240 <?php echo apply_filters( 'bws_shortcode_button_content', '' ); ?>
1241 </div>
1242 <div class="clear"></div>
1243 <div id="bws_shortcode_content_bottom">
1244 <p><?php _e( 'The shortcode will be inserted', 'bestwebsoft' ); ?></p>
1245 <div id="bws_shortcode_block"><div id="bws_shortcode_display"></div></div>
1246 </div>
1247 <?php if ( $wp_version < '3.9' ) { ?>
1248 <p>
1249 <button class="button-primary primary bws_shortcode_insert"><?php _e( 'Insert', 'bestwebsoft' ); ?></button>
1250 </p>
1251 <?php } ?>
1252 </div>
1253 </div>
1254 <?php }
1255 if ( $wp_version < '3.9' ) { ?>
1256 <script type="text/javascript">
1257 (function($){
1258 $( '.bws_shortcode_insert' ).on( 'click',function() {
1259 var shortcode = $( '#TB_ajaxContent #bws_shortcode_display' ).text();
1260 if ( '' != shortcode ) {
1261 /* insert shortcode to tinymce */
1262 if ( !tinyMCE.activeEditor || tinyMCE.activeEditor.isHidden() ) {
1263 $( 'textarea#content' ).val( shortcode );
1264 } else {
1265 tinyMCE.execCommand( 'mceInsertContent', false, shortcode );
1266 }
1267 }
1268 /* close the thickbox after adding shortcode to editor */
1269 self.parent.tb_remove();
1270 });
1271 })(jQuery);
1272 </script>
1273 <?php }
1274 }
1275 }
1276
1277 /* add help tab */
1278 if ( ! function_exists( 'bws_help_tab' ) ) {
1279 function bws_help_tab( $screen, $args ) {
1280 $url = ( ! empty( $args['section'] ) ) ? 'http://support.bestwebsoft.com/hc/en-us/sections/' . $args['section'] : 'http://support.bestwebsoft.com/';
1281
1282 $content = '<p><a href="' . $url . '" target="_blank">' . __( 'Visit Help Center', 'bestwebsoft' ) . '</a></p>';
1283
1284 $screen->add_help_tab(
1285 array(
1286 'id' => $args['id'] . '_help_tab',
1287 'title' => __( 'FAQ', 'bestwebsoft' ),
1288 'content' => $content
1289 )
1290 );
1291
1292 $screen->set_help_sidebar(
1293 '<p><strong>' . __( 'For more information:', 'bestwebsoft' ) . '</strong></p>' .
1294 '<p><a href="https://drive.google.com/folderview?id=0B5l8lO-CaKt9VGh0a09vUjNFNjA&usp=sharing#list" target="_blank">' . __( 'Documentation', 'bestwebsoft' ) . '</a></p>' .
1295 '<p><a href="http://www.youtube.com/user/bestwebsoft/playlists?flow=grid&sort=da&view=1" target="_blank">' . __( 'Video Instructions', 'bestwebsoft' ) . '</a></p>' .
1296 '<p><a href="http://support.bestwebsoft.com/hc/en-us/requests/new" target="_blank">' . __( 'Submit a Request', 'bestwebsoft' ) . '</a></p>'
1297 );
1298 }
1299 }
1300
1301 /**
1302 * Function display 'Custom code' tab
1303 */
1304 if ( ! function_exists( 'bws_custom_code_tab' ) ) {
1305 function bws_custom_code_tab() {
1306 if ( ! current_user_can( 'edit_plugins' ) )
1307 wp_die( __( 'You do not have sufficient permissions to edit plugins for this site.', 'bestwebsoft' ) );
1308
1309 global $bstwbsftwppdtplgns_options;
1310
1311 $message = $content = '';
1312 $is_css_active = $is_php_active = false;
1313
1314 $upload_dir = wp_upload_dir();
1315 $folder = $upload_dir['basedir'] . '/bws-custom-code';
1316 if ( ! $upload_dir["error"] ) {
1317 if ( ! is_dir( $folder ) )
1318 wp_mkdir_p( $folder, 0755 );
1319
1320 $index_file = $upload_dir['basedir'] . '/bws-custom-code/index.php';
1321 if ( ! file_exists( $index_file ) ) {
1322 if ( $f = fopen( $index_file, 'w+' ) )
1323 fclose( $f );
1324 }
1325 }
1326
1327 $css_file = 'bws-custom-code.css';
1328 $real_css_file = $folder . '/' . $css_file;
1329
1330 $php_file = 'bws-custom-code.php';
1331 $real_php_file = $folder . '/' . $php_file;
1332
1333 $is_multisite = is_multisite();
1334 if ( $is_multisite )
1335 $blog_id = get_current_blog_id();
1336
1337 if ( isset( $_REQUEST['bws_update_custom_code'] ) && check_admin_referer( 'bws_update_' . $css_file ) ) {
1338
1339 /* CSS */
1340 $newcontent_css = wp_unslash( $_POST['bws_newcontent_css'] );
1341 if ( ! empty( $newcontent_css ) && isset( $_REQUEST['bws_custom_css_active'] ) ) {
1342 if ( $is_multisite )
1343 $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $css_file ] = $upload_dir['baseurl'] . '/bws-custom-code/' . $css_file;
1344 else
1345 $bstwbsftwppdtplgns_options['custom_code'][ $css_file ] = $upload_dir['baseurl'] . '/bws-custom-code/' . $css_file;
1346 } else {
1347 if ( $is_multisite ) {
1348 if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $css_file ] ) )
1349 unset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $css_file ] );
1350 } else {
1351 if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $css_file ] ) )
1352 unset( $bstwbsftwppdtplgns_options['custom_code'][ $css_file ] );
1353 }
1354 }
1355 if ( $f = fopen( $real_css_file, 'w+' ) ) {
1356 fwrite( $f, $newcontent_css );
1357 fclose( $f );
1358 $message .= sprintf( __( 'File %s edited successfully.', 'bestwebsoft' ), '<i>' . $css_file . '</i>' ) . ' ';
1359 } else {
1360 $error .= __( 'Not enough permissions to create or update the file', 'bestwebsoft' ) . ' ' . $real_css_file . '. ';
1361 }
1362
1363 /* PHP */
1364 $newcontent_php = wp_unslash( trim( $_POST['bws_newcontent_php'] ) );
1365 if ( file_exists( $index_file ) ) {
1366 if ( ! empty( $newcontent_php ) && isset( $_REQUEST['bws_custom_php_active'] ) ) {
1367 if ( $is_multisite )
1368 $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $php_file ] = $real_php_file;
1369 else
1370 $bstwbsftwppdtplgns_options['custom_code'][ $php_file ] = $real_php_file;
1371 } else {
1372 if ( $is_multisite ) {
1373 if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $php_file ] ) )
1374 unset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $php_file ] );
1375 } else {
1376 if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $php_file ] ) )
1377 unset( $bstwbsftwppdtplgns_options['custom_code'][ $php_file ] );
1378 }
1379 }
1380
1381 if ( $f = fopen( $real_php_file, 'w+' ) ) {
1382 $newcontent_php = $newcontent_php;
1383 fwrite( $f, $newcontent_php );
1384 fclose( $f );
1385 $message .= sprintf( __( 'File %s edited successfully.', 'bestwebsoft' ), '<i>' . $php_file . '</i>' );
1386 } else {
1387 $error .= __( 'Not enough permissions to create or update the file', 'bestwebsoft' ) . ' ' . $real_php_file . '. ';
1388 }
1389 } else {
1390 $error .= __( 'Not enough permissions to create the file', 'bestwebsoft' ) . ' ' . $index_file . '. ';
1391 }
1392
1393 if ( ! empty( $error ) )
1394 $error .= ' <a href="https://codex.wordpress.org/Changing_File_Permissions" target="_blank">' . __( 'Learn more', 'bestwebsoft' ) . '</a>';
1395
1396 if ( $is_multisite )
1397 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1398 else
1399 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1400 }
1401
1402 if ( file_exists( $real_css_file ) ) {
1403 update_recently_edited( $real_css_file );
1404 $content_css = esc_textarea( file_get_contents( $real_css_file ) );
1405 if ( ( $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $css_file ] ) ) ||
1406 ( ! $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $css_file ] ) ) ) {
1407 $is_css_active = true;
1408 }
1409 }
1410 if ( file_exists( $real_php_file ) ) {
1411 update_recently_edited( $real_php_file );
1412 $content_php = esc_textarea( file_get_contents( $real_php_file ) );
1413 if ( ( $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ][ $php_file ] ) ) ||
1414 ( ! $is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $php_file ] ) ) ) {
1415 $is_php_active = true;
1416 }
1417 } else {
1418 $content_php = "<?php" . "\n" . "if ( ! defined( 'ABSPATH' ) ) exit;" . "\n" . "if ( ! defined( 'BWS_GLOBAL' ) ) exit;" . "\n\n" . "/* Start your code here */" . "\n";
1419 }
1420
1421 if ( ! empty( $message ) ) { ?>
1422 <div id="message" class="below-h2 updated notice is-dismissible"><p><?php echo $message; ?></p></div>
1423 <?php } ?>
1424 <form action="" method="post">
1425 <?php foreach ( array( 'css', 'php' ) as $extension ) { ?>
1426 <p>
1427 <?php if ( 'css' == $extension )
1428 _e( 'These styles will be added to the header on all pages of your site.', 'bestwebsoft' );
1429 else
1430 printf( __( 'This 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>' ); ?>
1431 </p>
1432 <p><big>
1433 <?php if ( ! file_exists( ${"real_{$extension}_file"} ) || ( is_writeable( ${"real_{$extension}_file"} ) ) ) {
1434 echo __( 'Editing', 'bestwebsoft' ) . ' <strong>' . ${"{$extension}_file"} . '</strong>';
1435 } else {
1436 echo __( 'Browsing', 'bestwebsoft' ) . ' <strong>' . ${"{$extension}_file"} . '</strong>';
1437 } ?>
1438 </big></p>
1439 <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>
1440 <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>
1441 <p class="description">
1442 <a href="<?php echo ( 'css' == $extension ) ? 'https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started' : 'http://php.net/' ?>" target="_blank">
1443 <?php printf( __( 'Learn more about %s', 'bestwebsoft' ), strtoupper( $extension ) ); ?>
1444 </a>
1445 </p>
1446 <?php }
1447 if ( ( ! file_exists( $real_css_file ) || is_writeable( $real_css_file ) ) && ( ! file_exists( $real_php_file ) || is_writeable( $real_php_file ) ) ) { ?>
1448 <p class="submit">
1449 <input type="hidden" name="bws_update_custom_code" value="submit" />
1450 <?php submit_button( __( 'Save Changes', 'bestwebsoft' ), 'primary', 'submit', false );
1451 wp_nonce_field( 'bws_update_' . $css_file ); ?>
1452 </p>
1453 <?php } else { ?>
1454 <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' ),
1455 '<a href="https://codex.wordpress.org/Changing_File_Permissions" target="_blank">',
1456 '</a>' ); ?></em></p>
1457 <?php } ?>
1458 </form>
1459 <?php }
1460 }
1461
1462 if ( ! function_exists( 'bws_enqueue_custom_code_css' ) ) {
1463 function bws_enqueue_custom_code_css() {
1464 global $bstwbsftwppdtplgns_options;
1465
1466 if ( ! isset( $bstwbsftwppdtplgns_options ) )
1467 $bstwbsftwppdtplgns_options = ( function_exists( 'is_multisite' ) && is_multisite() ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
1468
1469 if ( ! empty( $bstwbsftwppdtplgns_options['custom_code'] ) ) {
1470 $is_multisite = is_multisite();
1471 if ( $is_multisite )
1472 $blog_id = get_current_blog_id();
1473
1474 if ( ! $is_multisite && ! empty( $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.css'] ) )
1475 wp_enqueue_style( 'bws-custom-style', $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.css'] );
1476 elseif ( $is_multisite && ! empty( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.css'] ) )
1477 wp_enqueue_style( 'bws-custom-style', $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.css'] );
1478 }
1479 }
1480 }
1481
1482 if ( ! function_exists( 'bws_enqueue_custom_code_php' ) ) {
1483 function bws_enqueue_custom_code_php() {
1484 if ( is_admin() )
1485 return;
1486
1487 global $bstwbsftwppdtplgns_options;
1488
1489 if ( ! isset( $bstwbsftwppdtplgns_options ) )
1490 $bstwbsftwppdtplgns_options = ( function_exists( 'is_multisite' ) && is_multisite() ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
1491
1492 if ( ! empty( $bstwbsftwppdtplgns_options['custom_code'] ) ) {
1493
1494 $is_multisite = is_multisite();
1495 if ( $is_multisite )
1496 $blog_id = get_current_blog_id();
1497
1498 if ( ! $is_multisite && ! empty( $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.php'] ) ) {
1499
1500 if ( file_exists( $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.php'] ) ) {
1501 if ( ! defined( 'BWS_GLOBAL' ) )
1502 define( 'BWS_GLOBAL', true );
1503 require_once( $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.php'] );
1504 } else {
1505 unset( $bstwbsftwppdtplgns_options['custom_code']['bws-custom-code.php'] );
1506 if ( $is_multisite )
1507 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1508 else
1509 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1510 }
1511 } elseif ( $is_multisite && ! empty( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.php'] ) ) {
1512 if ( file_exists( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.php'] ) ) {
1513 if ( ! defined( 'BWS_GLOBAL' ) )
1514 define( 'BWS_GLOBAL', true );
1515 require_once( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.php'] );
1516 } else {
1517 unset( $bstwbsftwppdtplgns_options['custom_code'][ $blog_id ]['bws-custom-code.php'] );
1518 if ( $is_multisite )
1519 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1520 else
1521 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
1522 }
1523 }
1524 }
1525 }
1526 }
1527
1528 if ( ! function_exists( 'bws_delete_plugin' ) ) {
1529 function bws_delete_plugin( $basename ) {
1530 global $bstwbsftwppdtplgns_options;
1531
1532 $is_multisite = is_multisite();
1533 if ( $is_multisite )
1534 $blog_id = get_current_blog_id();
1535
1536 if ( ! isset( $bstwbsftwppdtplgns_options ) )
1537 $bstwbsftwppdtplgns_options = ( $is_multisite ) ? get_site_option( 'bstwbsftwppdtplgns_options' ) : get_option( 'bstwbsftwppdtplgns_options' );
1538
1539 /* remove bws_menu versions */
1540 unset( $bstwbsftwppdtplgns_options['bws_menu']['version'][ $basename ] );
1541 /* if empty ['bws_menu']['version'] - there is no other bws plugins - delete all */
1542 if ( empty( $bstwbsftwppdtplgns_options['bws_menu']['version'] ) ) {
1543 /* remove options */
1544 if ( $is_multisite )
1545 delete_site_option( 'bstwbsftwppdtplgns_options' );
1546 else
1547 delete_option( 'bstwbsftwppdtplgns_options' );
1548
1549 /* remove custom_code */
1550 if ( $is_multisite ) {
1551 global $wpdb;
1552 $old_blog = $wpdb->blogid;
1553 /* Get all blog ids */
1554 $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" );
1555 foreach ( $blogids as $blog_id ) {
1556 switch_to_blog( $blog_id );
1557 $upload_dir = wp_upload_dir();
1558 $folder = $upload_dir['basedir'] . '/bws-custom-code';
1559 if ( file_exists( $folder ) && is_dir( $folder ) ) {
1560 array_map( 'unlink', glob( "$folder/*" ) );
1561 rmdir( $folder );
1562 }
1563 }
1564 switch_to_blog( $old_blog );
1565 } else {
1566 $upload_dir = wp_upload_dir();
1567 $folder = $upload_dir['basedir'] . '/bws-custom-code';
1568 if ( file_exists( $folder ) && is_dir( $folder ) ) {
1569 array_map( 'unlink', glob( "$folder/*" ) );
1570 rmdir( $folder );
1571 }
1572 }
1573 }
1574 }
1575 }
1576
1577 add_action( 'admin_init', 'bws_plugins_admin_init' );
1578 add_action( 'admin_enqueue_scripts', 'bws_admin_enqueue_scripts' );
1579 add_action( 'admin_head', 'bws_plugins_admin_head' );
1580 add_action( 'admin_footer','bws_shortcode_media_button_popup' );
1581
1582 add_action( 'admin_notices', 'bws_admin_notices', 30 );
1583
1584 add_action( 'wp_enqueue_scripts', 'bws_enqueue_custom_code_css', 20 );
1585
1586 bws_enqueue_custom_code_php();