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

1,098 lines 51.5 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 /**
7 * Function add BWS Plugins page - for old plugin version
8 * @deprecated 1.7.9
9 */
10 if ( ! function_exists ( 'bws_add_general_menu' ) ) {
11 function bws_add_general_menu() {
12 bws_general_menu();
13 }
14 }
15
16 /**
17 * Function add BWS Plugins page
18 * @return void
19 */
20 if ( ! function_exists ( 'bws_general_menu' ) ) {
21 function bws_general_menu() {
22 global $menu, $bws_general_menu_exist;
23
24 if ( ! $bws_general_menu_exist ) {
25 /* we check also menu exist in global array as in old plugins $bws_general_menu_exist variable not exist */
26 foreach ( $menu as $value_menu ) {
27 if ( 'bws_plugins' == $value_menu[2] ) {
28 $bws_general_menu_exist = true;
29 return;
30 }
31 }
32
33 add_menu_page( 'BWS Plugins', 'BWS Plugins', 'manage_options', 'bws_plugins', 'bws_add_menu_render', plugins_url( 'images/px.png', __FILE__ ), 1001 );
34 $bws_general_menu_exist = true;
35 }
36 }
37 }
38
39 /**
40 * Function check if plugin is compatible with current WP version - for old plugin version
41 * @deprecated 1.7.4
42 */
43 if ( ! function_exists ( 'bws_wp_version_check' ) ) {
44 function bws_wp_version_check( $plugin_basename, $plugin_info, $require_wp ) {
45 bws_wp_min_version_check( $plugin_basename, $plugin_info, '3.8' , $require_wp );
46 }
47 }
48
49 /**
50 * Function check if plugin is compatible with current WP version
51 * @return void
52 */
53 if ( ! function_exists ( 'bws_wp_min_version_check' ) ) {
54 function bws_wp_min_version_check( $plugin_basename, $plugin_info, $require_wp, $min_wp = false ) {
55 global $wp_version, $bws_versions_notice_array;
56 if ( false != $min_wp && version_compare( $wp_version, $min_wp, "<" ) ) {
57 include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
58 if ( is_plugin_active( $plugin_basename ) ) {
59 deactivate_plugins( $plugin_basename );
60 $admin_url = ( function_exists( 'get_admin_url' ) ) ? get_admin_url( null, 'plugins.php' ) : esc_url( '/wp-admin/plugins.php' );
61 wp_die(
62 sprintf(
63 "<strong>%s</strong> %s <strong>WordPress %s</strong> %s <br /><br />%s <a href='%s'>%s</a>.",
64 $plugin_info['Name'],
65 __( 'requires', 'bestwebsoft' ),
66 $require_wp,
67 __( 'or higher, that is why it has been deactivated! Please upgrade WordPress and try again.', 'bestwebsoft' ),
68 __( 'Back to the WordPress', 'bestwebsoft' ),
69 $admin_url,
70 __( 'Plugins page', 'bestwebsoft' )
71 )
72 );
73 }
74 } elseif ( version_compare( $wp_version, $require_wp, "<" ) ) {
75 $bws_versions_notice_array[] = array( 'name' => $plugin_info['Name'], 'version' => $require_wp );
76 }
77 }
78 }
79
80 if ( ! function_exists( 'bws_versions_notice' ) ) {
81 function bws_versions_notice() {
82 global $bws_versions_notice_array;
83 if ( ! empty( $bws_versions_notice_array ) ) {
84 foreach ( $bws_versions_notice_array as $key => $value ) { ?>
85 <div class="update-nag"><?php
86 echo sprintf(
87 "<strong>%s</strong> %s <strong>WordPress %s</strong> %s",
88 $value['name'],
89 __( 'requires', 'bestwebsoft' ),
90 $value['version'],
91 __( 'or higher! We do not guarantee that our plugin will work correctly. Please upgrade to WordPress latest version.', 'bestwebsoft' )
92 );
93 ?></div>
94 <?php }
95 }
96 }
97 }
98
99 if ( ! function_exists( 'bws_plugin_banner' ) ) {
100 function bws_plugin_banner( $plugin_info, $this_banner_prefix, $link_slug, $link_key, $link_pn, $banner_url_or_slug ) {
101 global $wp_version, $bstwbsftwppdtplgns_cookie_add, $bstwbsftwppdtplgns_banner_array;
102
103 if ( empty( $bstwbsftwppdtplgns_banner_array ) ) {
104 if ( ! function_exists( 'bws_get_banner_array' ) )
105 require_once( dirname( __FILE__ ) . '/bws_menu.php' );
106 bws_get_banner_array();
107 }
108
109 if ( false == strrpos( $banner_url_or_slug, '/' ) ) {
110 $banner_url_or_slug = '//ps.w.org/' . $banner_url_or_slug . '/assets/icon-128x128.png';
111 }
112
113 if ( ! function_exists( 'is_plugin_active' ) )
114 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
115
116 $all_plugins = get_plugins();
117
118 $this_banner = $this_banner_prefix . '_hide_banner_on_plugin_page';
119 foreach ( $bstwbsftwppdtplgns_banner_array as $key => $value ) {
120 if ( $this_banner == $value[0] ) {
121 if ( ! isset( $bstwbsftwppdtplgns_cookie_add ) ) {
122 echo '<script type="text/javascript" src="' . plugins_url( 'js/c_o_o_k_i_e.js', __FILE__ ) . '"></script>';
123 $bstwbsftwppdtplgns_cookie_add = true;
124 } ?>
125 <script type="text/javascript">
126 (function($) {
127 $(document).ready( function() {
128 var hide_message = $.cookie( '<?php echo $this_banner_prefix; ?>_hide_banner_on_plugin_page' );
129 if ( hide_message == "true" ) {
130 $( ".<?php echo $this_banner_prefix; ?>_message" ).css( "display", "none" );
131 } else {
132 $( ".<?php echo $this_banner_prefix; ?>_message" ).css( "display", "block" );
133 };
134 $( ".<?php echo $this_banner_prefix; ?>_close_icon" ).click( function() {
135 $( ".<?php echo $this_banner_prefix; ?>_message" ).css( "display", "none" );
136 $.cookie( "<?php echo $this_banner_prefix; ?>_hide_banner_on_plugin_page", "true", { expires: 32 } );
137 });
138 });
139 })(jQuery);
140 </script>
141 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
142 <div class="<?php echo $this_banner_prefix; ?>_message bws_banner_on_plugin_page" style="display: none;">
143 <img class="<?php echo $this_banner_prefix; ?>_close_icon close_icon" title="" src="<?php echo plugins_url( 'images/close_banner.png', __FILE__ ); ?>" alt=""/>
144 <div class="icon">
145 <img title="" src="<?php echo esc_attr( $banner_url_or_slug ); ?>" alt="" />
146 </div>
147 <div class="text"><?php
148 _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 />
149 <span><?php _e( 'Extend standard plugin functionality with new great options.', 'bestwebsoft' ); ?></span>
150 </div>
151 <div class="button_div">
152 <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>
153 </div>
154 </div>
155 </div>
156 <?php break;
157 }
158 if ( isset( $all_plugins[ $value[1] ] ) && $all_plugins[ $value[1] ]["Version"] >= $value[2] && is_plugin_active( $value[1] ) && ! isset( $_COOKIE[ $value[0] ] ) ) {
159 break;
160 }
161 }
162 }
163 }
164
165 if ( ! function_exists( 'bws_plugin_reviews_block' ) ) {
166 function bws_plugin_reviews_block( $plugin_name, $plugin_slug ) { ?>
167 <div class="bws-plugin-reviews">
168 <div class="bws-plugin-reviews-rate">
169 <?php _e( 'If you enjoy our plugin, please give it 5 stars on WordPress', 'bestwebsoft' ); ?>:
170 <a href="http://wordpress.org/support/view/plugin-reviews/<?php echo $plugin_slug; ?>" target="_blank" title="<?php echo $plugin_name; ?> reviews"><?php _e( 'Rate the plugin', 'bestwebsoft' ); ?></a>
171 </div>
172 <div class="bws-plugin-reviews-support">
173 <?php _e( 'If there is something wrong about it, please contact us', 'bestwebsoft' ); ?>:
174 <a href="http://support.bestwebsoft.com">http://support.bestwebsoft.com</a>
175 </div>
176 </div>
177 <?php }
178 }
179
180 if ( ! function_exists( 'bws_go_pro_tab_check' ) ) {
181 function bws_go_pro_tab_check( $plugin_basename, $plugin_options_name = false, $is_network_option = false ) {
182 global $wp_version, $bstwbsftwppdtplgns_options, $current_user;
183 $result = array();
184
185 $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : "";
186
187 if ( ! empty( $plugin_options_name ) && isset( $_POST['bws_hide_premium_options_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) {
188 if ( ! $current_user )
189 get_currentuserinfo();
190
191 $plugin_options = ( $is_network_option ) ? get_site_option( $plugin_options_name ) : get_option( $plugin_options_name );
192
193 if ( !empty( $plugin_options['hide_premium_options'] ) ) {
194
195 $key = array_search( $current_user->ID, $plugin_options['hide_premium_options'] );
196 if ( false !== $key ) {
197 unset( $plugin_options['hide_premium_options'][ $key ] );
198 }
199
200 if ( $is_network_option )
201 update_site_option( $plugin_options_name, $plugin_options );
202 else
203 update_option( $plugin_options_name, $plugin_options );
204
205 $result['message'] = __( 'Check premium options on the plugin settings page!', 'bestwebsoft' );
206 }
207 }
208
209 if ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) {
210 if ( '' != $bws_license_key ) {
211 if ( strlen( $bws_license_key ) != 18 ) {
212 $result['error'] = __( "Wrong license key", 'bestwebsoft' );
213 } else {
214 $bws_license_plugin = stripslashes( esc_html( $_POST['bws_license_plugin'] ) );
215 if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] ) && $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] > ( time() - (24 * 60 * 60) ) ) {
216 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] + 1;
217 } else {
218 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = 1;
219 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] = time();
220 }
221
222 /* download Pro */
223 if ( ! function_exists( 'get_plugins' ) )
224 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
225
226 $all_plugins = get_plugins();
227
228 if ( ! array_key_exists( $bws_license_plugin, $all_plugins ) ) {
229 $current = get_site_transient( 'update_plugins' );
230 if ( is_array( $all_plugins ) && !empty( $all_plugins ) && isset( $current ) && is_array( $current->response ) ) {
231 $to_send = array();
232 $to_send["plugins"][ $bws_license_plugin ] = array();
233 $to_send["plugins"][ $bws_license_plugin ]["bws_license_key"] = $bws_license_key;
234 $to_send["plugins"][ $bws_license_plugin ]["bws_illegal_client"] = true;
235 $options = array(
236 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ),
237 'body' => array( 'plugins' => serialize( $to_send ) ),
238 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
239 $raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options );
240
241 if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
242 $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' );
243 } else {
244 $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );
245 if ( is_array( $response ) && !empty( $response ) ) {
246 foreach ( $response as $key => $value ) {
247 if ( "wrong_license_key" == $value->package ) {
248 $result['error'] = __( "Wrong license key", 'bestwebsoft' );
249 } elseif ( "wrong_domain" == $value->package ) {
250 $result['error'] = __( "This license key is bind to another site", 'bestwebsoft' );
251 } elseif ( "you_are_banned" == $value->package ) {
252 $result['error'] = __( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' );
253 } elseif ( "time_out" == $value->package ) {
254 $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>';
255 } elseif ( "duplicate_domen_for_trial" == $value->package ) {
256 $result['error'] = __( "Unfortunately, the Pro licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' );
257 }
258 }
259 if ( empty( $result['error'] ) ) {
260 $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key;
261
262 $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';
263 $uploadDir = wp_upload_dir();
264 $zip_name = explode( '/', $bws_license_plugin );
265
266 if ( !function_exists( 'curl_init' ) ) {
267 $received_content = file_get_contents( $url );
268 } else {
269 $ch = curl_init();
270 curl_setopt( $ch, CURLOPT_URL, $url );
271 curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
272 $received_content = curl_exec( $ch );
273 curl_close( $ch );
274 }
275
276 if ( ! $received_content ) {
277 $result['error'] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' );
278 } else {
279 if ( is_writable( $uploadDir["path"] ) ) {
280 $file_put_contents = $uploadDir["path"] . "/" . $zip_name[0] . ".zip";
281 if ( file_put_contents( $file_put_contents, $received_content ) ) {
282 @chmod( $file_put_contents, octdec( 755 ) );
283 if ( class_exists( 'ZipArchive' ) ) {
284 $zip = new ZipArchive();
285 if ( $zip->open( $file_put_contents ) === TRUE ) {
286 $zip->extractTo( WP_PLUGIN_DIR );
287 $zip->close();
288 } else {
289 $result['error'] = __( "Failed to open the zip archive. Please, upload the plugin manually", 'bestwebsoft' );
290 }
291 } elseif ( class_exists( 'Phar' ) ) {
292 $phar = new PharData( $file_put_contents );
293 $phar->extractTo( WP_PLUGIN_DIR );
294 } else {
295 $result['error'] = __( "Your server does not support either ZipArchive or Phar. Please, upload the plugin manually", 'bestwebsoft' );
296 }
297 @unlink( $file_put_contents );
298 } else {
299 $result['error'] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' );
300 }
301 } else {
302 $result['error'] = __( "UploadDir is not writable. Please, upload the plugin manually", 'bestwebsoft' );
303 }
304 }
305
306 /* activate Pro */
307 if ( file_exists( WP_PLUGIN_DIR . '/' . $zip_name[0] ) ) {
308 if ( is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
309 /* if multisite and free plugin is network activated */
310 $active_plugins = get_site_option( 'active_sitewide_plugins' );
311 $active_plugins[ $bws_license_plugin ] = time();
312 update_site_option( 'active_sitewide_plugins', $active_plugins );
313 } else {
314 /* activate on a single blog */
315 $active_plugins = get_option( 'active_plugins' );
316 array_push( $active_plugins, $bws_license_plugin );
317 update_option( 'active_plugins', $active_plugins );
318 }
319 $result['pro_plugin_is_activated'] = true;
320 } elseif ( empty( $result['error'] ) ) {
321 $result['error'] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' );
322 }
323 }
324 } else {
325 $result['error'] = __( "Something went wrong. Try again later or upload the plugin manually. We are sorry for inconvenience.", 'bestwebsoft' );
326 }
327 }
328 }
329 } else {
330 $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key;
331 /* activate Pro */
332 if ( ! is_plugin_active( $bws_license_plugin ) ) {
333 if ( is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) {
334 /* if multisite and free plugin is network activated */
335 $network_wide = true;
336 } else {
337 /* activate on a single blog */
338 $network_wide = false;
339 }
340 activate_plugin( $bws_license_plugin, NULL, $network_wide );
341 $result['pro_plugin_is_activated'] = true;
342 }
343 }
344 if ( is_multisite() )
345 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
346 else
347 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
348 }
349 } else {
350 $result['error'] = __( "Please, enter Your license key", 'bestwebsoft' );
351 }
352 }
353 return $result;
354 }
355 }
356
357 /**
358 * Function display GO PRO tab - for old plugin version
359 * @deprecated 1.7.6
360 */
361 if ( ! function_exists( 'bws_go_pro_tab' ) ) {
362 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 ) {
363 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 );
364 }
365 }
366
367 /**
368 * Function display GO PRO tab
369 */
370 if ( ! function_exists( 'bws_go_pro_tab_show' ) ) {
371 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 ) {
372 global $wp_version, $bstwbsftwppdtplgns_options;
373 $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : "";
374 if ( $pro_plugin_is_activated ) { ?>
375 <script type="text/javascript">
376 window.setTimeout( function() {
377 window.location.href = 'admin.php?page=<?php echo $pro_page; ?>';
378 }, 5000 );
379 </script>
380 <p><?php _e( "Congratulations! The Pro version of the plugin is successfully download and activated.", 'bestwebsoft' ); ?></p>
381 <p>
382 <?php _e( "Please, go to", 'bestwebsoft' ); ?> <a href="admin.php?page=<?php echo $pro_page; ?>"><?php _e( 'the setting page', 'bestwebsoft' ); ?></a>
383 (<?php _e( "You will be redirected automatically in 5 seconds.", 'bestwebsoft' ); ?>)
384 </p>
385 <?php } else {
386 if ( $bws_hide_premium_options_check ) { ?>
387 <form method="post" action="admin.php?page=<?php echo $page; ?>&amp;action=go_pro">
388 <p>
389 <input type="hidden" name="bws_hide_premium_options_submit" value="submit" />
390 <input type="submit" class="button" value="<?php _e( 'Show Pro features', 'bestwebsoft' ); ?>" />
391 <?php wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?>
392 </p>
393 </form>
394 <?php } ?>
395 <form method="post" action="admin.php?page=<?php echo $page; ?>&amp;action=go_pro">
396 <p>
397 <?php _e( 'You can download and activate', 'bestwebsoft' ); ?>
398 <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>
399 <?php _e( 'version of this plugin by entering Your license key.', 'bestwebsoft' ); ?><br />
400 <span class="bws_info">
401 <?php _e( 'You can find your license key on your personal page Client area, by clicking on the link', 'bestwebsoft' ); ?>
402 <a href="http://bestwebsoft.com/wp-login.php">http://bestwebsoft.com/wp-login.php</a>
403 <?php _e( '(your username is the email you specify when purchasing the product).', 'bestwebsoft' ); ?>
404 </span>
405 </p>
406 <?php if ( $trial_days_number !== false )
407 $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>';
408 if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] ) &&
409 '5' < $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] &&
410 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] > ( time() - ( 24 * 60 * 60 ) ) ) { ?>
411 <p>
412 <input disabled="disabled" type="text" name="bws_license_key" value="<?php echo $bws_license_key; ?>" />
413 <input disabled="disabled" type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" />
414 <?php if ( $trial_days_number !== false ) echo $trial_days_number; ?>
415 </p>
416 <p><?php _e( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' ); ?></p>
417 <?php } else { ?>
418 <p>
419 <input type="text" maxlength="100" name="bws_license_key" value="<?php echo $bws_license_key; ?>" />
420 <input type="hidden" name="bws_license_plugin" value="<?php echo $bws_license_plugin; ?>" />
421 <input type="hidden" name="bws_license_submit" value="submit" />
422 <input type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" />
423 <?php if ( $trial_days_number !== false ) echo $trial_days_number;
424 wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?>
425 </p>
426 <?php } ?>
427 </form>
428 <?php }
429 }
430 }
431
432 if ( ! function_exists( 'bws_go_pro_from_trial_tab' ) ) {
433 function bws_go_pro_from_trial_tab( $plugin_info, $plugin_basename, $page, $link_slug, $link_key, $link_pn, $trial_license_is_set = true ) {
434 global $wp_version, $bstwbsftwppdtplgns_options;
435 $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : "";
436 if ( $trial_license_is_set ) { ?>
437 <form method="post" action="admin.php?page=<?php echo $page; ?>&amp;action=go_pro">
438 <p>
439 <?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>' ) . ' ';
440 _e( 'After that you can activate it by entering your license key.', 'bestwebsoft' ); ?><br />
441 <span class="bws_info">
442 <?php _e( 'You can find your license key on your personal page Client area, by clicking on the link', 'bestwebsoft' ); ?>
443 <a href="http://bestwebsoft.com/wp-login.php">http://bestwebsoft.com/wp-login.php</a>
444 <?php _e( '(your username is the email you specify when purchasing the product).', 'bestwebsoft' ); ?>
445 </span>
446 </p>
447 <?php if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $plugin_basename ]['count'] ) &&
448 '5' < $bstwbsftwppdtplgns_options['go_pro'][ $plugin_basename ]['count'] &&
449 $bstwbsftwppdtplgns_options['go_pro'][ $plugin_basename ]['time'] > ( time() - ( 24 * 60 * 60 ) ) ) { ?>
450 <p>
451 <input disabled="disabled" type="text" name="bws_license_key" value="" />
452 <input disabled="disabled" type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" />
453 </p>
454 <p><?php _e( "Unfortunately, you have exceeded the number of available tries per day.", 'bestwebsoft' ); ?></p>
455 <?php } else { ?>
456 <p>
457 <input type="text" maxlength="100" name="bws_license_key" value="" />
458 <input type="hidden" name="bws_license_plugin" value="<?php echo $plugin_basename; ?>" />
459 <input type="hidden" name="bws_license_submit" value="submit" />
460 <input type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" />
461 <?php wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?>
462 </p>
463 <?php } ?>
464 </form>
465 <?php } else { ?>
466 <script type="text/javascript">
467 window.setTimeout( function() {
468 window.location.href = 'admin.php?page=<?php echo $page; ?>';
469 }, 5000 );
470 </script>
471 <p><?php _e( "Congratulations! The Pro license of the plugin is successfully activated.", 'bestwebsoft' ); ?></p>
472 <p>
473 <?php _e( "Please, go to", 'bestwebsoft' ); ?> <a href="admin.php?page=<?php echo $page; ?>"><?php _e( 'the setting page', 'bestwebsoft' ); ?></a>
474 (<?php _e( "You will be redirected automatically in 5 seconds.", 'bestwebsoft' ); ?>)
475 </p>
476 <?php }
477 }
478 }
479
480 if ( ! function_exists( 'bws_check_pro_license' ) ) {
481 function bws_check_pro_license( $plugin_basename, $trial_plugin = false ) {
482 global $wp_version, $bstwbsftwppdtplgns_options;
483 $result = array();
484
485 if ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) {
486 $license_key = isset( $_POST['bws_license_key'] ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : '';
487
488 if ( '' != $license_key ) {
489 if ( ! function_exists( 'get_plugins' ) )
490 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
491 $plugins_all = get_plugins();
492 $current = get_site_transient( 'update_plugins' );
493
494 if ( is_array( $plugins_all ) && !empty( $plugins_all ) && isset( $current ) && is_array( $current->response ) ) {
495 $to_send = array();
496 $to_send["plugins"][ $plugin_basename ] = $plugins_all[ $plugin_basename ];
497 $to_send["plugins"][ $plugin_basename ]["bws_license_key"] = $license_key;
498 $to_send["plugins"][ $plugin_basename ]["bws_illegal_client"] = true;
499 $options = array(
500 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3),
501 'body' => array( 'plugins' => serialize( $to_send ) ),
502 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
503 );
504 $raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options );
505 if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) {
506 $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' );
507 } else {
508 $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) );
509 if ( is_array( $response ) && !empty( $response ) ) {
510 foreach ( $response as $key => $value ) {
511 if ( "wrong_license_key" == $value->package ) {
512 $result['error'] = __( 'Wrong license key.', 'bestwebsoft' );
513 } else if ( "wrong_domain" == $value->package ) {
514 $result['error'] = __( 'This license key is bind to another site.', 'bestwebsoft' );
515 } else if ( "time_out" == $value->package ) {
516 $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' );
517 } elseif ( "you_are_banned" == $value->package ) {
518 $result['error'] = __( "Unfortunately, you have exceeded the number of available tries.", 'bestwebsoft' );
519 } elseif ( "duplicate_domen_for_trial" == $value->package ) {
520 $result['error'] = __( "Unfortunately, the Pro Trial licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' );
521 }
522 if ( empty( $result['message'] ) && empty( $result['error'] ) ) {
523 if ( isset( $value->trial ) )
524 $result['message'] = __( 'The Pro Trial license key is valid.', 'bestwebsoft' );
525 else
526 $result['message'] = __( 'The license key is valid.', 'bestwebsoft' );
527
528 if ( isset( $value->time_out ) && $value->time_out != '' )
529 $result['message'] .= ' ' . __( 'Your license will expire on', 'bestwebsoft' ) . ' ' . $value->time_out . '.';
530
531 if ( isset( $value->trial ) && $trial_plugin != false )
532 $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>' );
533
534 if ( isset( $value->trial ) ) {
535 $bstwbsftwppdtplgns_options['trial'][ $plugin_basename ] = 1;
536 } else {
537 unset( $bstwbsftwppdtplgns_options['trial'][ $plugin_basename ] );
538 }
539 }
540 if ( empty( $result['error'] ) ) {
541 if ( $bstwbsftwppdtplgns_options[ $plugin_basename ] != $license_key ) {
542 $bstwbsftwppdtplgns_options[ $plugin_basename ] = $license_key;
543 $bstwbsftwppdtplgns_options['time_out'][ $plugin_basename ] = $value->time_out;
544 if ( is_multisite() )
545 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
546 else
547 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options );
548 $file = @fopen( dirname( dirname( __FILE__ ) ) . "/license_key.txt" , "w+" );
549 if ( $file ) {
550 @fwrite( $file, $license_key );
551 @fclose( $file );
552 }
553 }
554 }
555 }
556 } else {
557 $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' );
558 }
559 }
560 }
561 } else {
562 $result['error'] = __( 'Please, enter your license key', 'bestwebsoft' );
563 }
564 }
565 return $result;
566 }
567 }
568
569 if ( ! function_exists ( 'bws_check_pro_license_form' ) ) {
570 function bws_check_pro_license_form( $plugin_basename, $page ) {
571 global $bstwbsftwppdtplgns_options;
572 $license_key = ( isset( $bstwbsftwppdtplgns_options[ $plugin_basename ] ) ) ? $bstwbsftwppdtplgns_options[ $plugin_basename ] : ''; ?>
573 <div class="clear"></div>
574 <form method="post" action="admin.php?page=<?php echo $page; ?>">
575 <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 you specify when purchasing the product). If necessary, please submit "Lost your password?" request.', 'bestwebsoft' ); ?></p>
576 <p>
577 <input type="text" maxlength="100" name="bws_license_key" value="<?php echo $license_key; ?>" />
578 <input type="hidden" name="bws_license_submit" value="submit" />
579 <input type="submit" class="button-primary" value="<?php _e( 'Check license key', 'bestwebsoft' ) ?>" />
580 <?php wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?>
581 </p>
582 </form>
583 <?php }
584 }
585
586 if ( ! function_exists ( 'bws_plugin_update_row' ) ) {
587 function bws_plugin_update_row( $plugin_key, $link_slug = false, $free_plugin_name = false ) {
588 global $bstwbsftwppdtplgns_options;
589 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' );
590 if ( isset( $bstwbsftwppdtplgns_options['wrong_license_key'][ $plugin_key ] ) ) {
591 echo '<tr class="plugin-update-tr">
592 <td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
593 <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>
594 </td>
595 </tr>';
596 } elseif ( isset( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) && strtotime( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) < strtotime( date("m/d/Y") ) ) {
597 echo '<tr class="plugin-update-tr">
598 <td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
599 <div class="update-message" style="color: #8C0000;">';
600 if ( isset( $bstwbsftwppdtplgns_options['trial'][ $plugin_key ] ) && $link_slug != false ) {
601 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>';
602 } else {
603 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>';
604 }
605 echo '</div>
606 </td>
607 </tr>';
608 } elseif ( isset( $bstwbsftwppdtplgns_options['trial'][ $plugin_key ] ) ) {
609 echo '<tr class="plugin-update-tr">
610 <td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange">
611 <div class="update-message" style="color: #8C0000;">';
612 if ( $free_plugin_name != false ) {
613 echo sprintf( __( 'Notice: You are using the Pro Trial license of %s plugin.', 'bestwebsoft' ), $free_plugin_name );
614 } else {
615 _e( 'Notice: You are using the Pro Trial license of plugin.', 'bestwebsoft' );
616 }
617 if ( isset( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) )
618 echo ' ' . __( "The Pro Trial license will expire on", 'bestwebsoft' ) . ' ' . $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] . '.';
619 echo '</div>
620 </td>
621 </tr>';
622 }
623 }
624 }
625
626 if ( ! function_exists ( 'bws_plugin_banner_timeout' ) ) {
627 function bws_plugin_banner_timeout( $plugin_key, $plugin_prefix, $plugin_name, $banner_url = false ) {
628 global $bstwbsftwppdtplgns_options, $bstwbsftwppdtplgns_cookie_add;
629 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") ) ) ) {
630 if ( ! isset( $bstwbsftwppdtplgns_cookie_add ) ) {
631 echo '<script type="text/javascript" src="' . plugins_url( 'js/c_o_o_k_i_e.js', __FILE__ ) . '"></script>';
632 $bstwbsftwppdtplgns_cookie_add = true;
633 } ?>
634 <script type="text/javascript">
635 (function($) {
636 $(document).ready( function() {
637 var hide_message = $.cookie( "<?php echo $plugin_prefix; ?>_timeout_hide_banner_on_plugin_page" );
638 if ( hide_message == "true" ) {
639 $( ".<?php echo $plugin_prefix; ?>_message" ).css( "display", "none" );
640 } else {
641 $( ".<?php echo $plugin_prefix; ?>_message" ).css( "display", "block" );
642 }
643 $( ".<?php echo $plugin_prefix; ?>_close_icon" ).click( function() {
644 $( ".<?php echo $plugin_prefix; ?>_message" ).css( "display", "none" );
645 $.cookie( "<?php echo $plugin_prefix; ?>_timeout_hide_banner_on_plugin_page", "true", { expires: 30 } );
646 });
647 });
648 })(jQuery);
649 </script>
650 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
651 <div class="<?php echo $plugin_prefix; ?>_message bws_banner_on_plugin_page" style="display:none;">
652 <img class="<?php echo $plugin_prefix; ?>_close_icon close_icon" title="" src="<?php echo plugins_url( 'images/close_banner.png', __FILE__ ); ?>" alt=""/>
653 <div class="icon">
654 <img title="" src="<?php echo $banner_url; ?>" alt="" />
655 </div>
656 <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>
657 </div>
658 </div>
659 <?php }
660 }
661 }
662
663 if ( ! function_exists( 'bws_plugin_banner_to_settings' ) ) {
664 function bws_plugin_banner_to_settings( $plugin_info, $plugin_options_name, $banner_url_or_slug, $settings_url, $post_type_url = false, $post_type_name = false ) {
665 global $wp_version;
666
667 $plugin_options = get_option( $plugin_options_name );
668
669 if ( isset( $plugin_options['display_settings_notice'] ) && 0 == $plugin_options['display_settings_notice'] )
670 return;
671
672 if ( isset( $_POST['bws_hide_settings_notice_' . $plugin_options_name ] ) && check_admin_referer( $plugin_info['Name'], 'bws_settings_nonce_name' ) ) {
673 $plugin_options['display_settings_notice'] = 0;
674 update_option( $plugin_options_name, $plugin_options );
675 return;
676 }
677
678 if ( false == strrpos( $banner_url_or_slug, '/' ) ) {
679 $banner_url_or_slug = '//ps.w.org/' . $banner_url_or_slug . '/assets/icon-128x128.png';
680 } ?>
681 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;">
682 <div class="bws_banner_on_plugin_page">
683 <div class="icon">
684 <img title="" src="<?php echo esc_attr( $banner_url_or_slug ); ?>" alt="" />
685 </div>
686 <div class="text">
687 <strong><?php _e( 'Thank you for installing', 'bestwebsoft' ); ?> <?php echo $plugin_info['Name']; ?> plugin!</strong><br />
688 <?php _e( "Let's get started", 'bestwebsoft' ); ?>:
689 <a target="_blank" href="<?php echo $settings_url; ?>"><?php _e( 'Configure Settings', 'bestwebsoft' ); ?></a>
690 <?php if ( false != $post_type_url && false != $post_type_name ) { ?>
691 <?php _e( 'or', 'bestwebsoft' ); ?>
692 <a target="_blank" href="<?php echo $post_type_url; ?>"><?php _e( 'Add New', 'bestwebsoft' ); ?> <?php echo $post_type_name; ?></a>
693 <?php } ?>
694 </div>
695 <form action="" method="post">
696 <button class="notice-dismiss bws_hide_settings_notice" title="<?php _e( 'Close notice', 'bestwebsoft' ); ?>"></button>
697 <input type="hidden" name="bws_hide_settings_notice_<?php echo $plugin_options_name; ?>" value="hide" />
698 <?php wp_nonce_field( $plugin_info['Name'], 'bws_settings_nonce_name' ); ?>
699 </form>
700 </div>
701 </div>
702 <?php }
703 }
704
705 if ( ! function_exists( 'bws_show_settings_notice' ) ) {
706 function bws_show_settings_notice() { ?>
707 <div id="bws_save_settings_notice" class="updated fade" style="display:none">
708 <p>
709 <strong><?php _e( 'Notice', 'bestwebsoft' ); ?></strong>: <?php _e( "The plugin's settings have been changed.", 'bestwebsoft' ); ?>
710 <a class="bws_save_anchor" href="#bws-submit-button"><?php _e( 'Save Changes', 'bestwebsoft' ); ?></a>
711 </p>
712 </div>
713 <?php }
714 }
715
716 if ( ! function_exists( 'bws_hide_premium_options' ) ) {
717 function bws_hide_premium_options( $options ) {
718 global $current_user;
719 if ( ! $current_user )
720 get_currentuserinfo();
721 if ( ! isset( $options['hide_premium_options'] ) || ! is_array( $options['hide_premium_options'] ) )
722 $options['hide_premium_options'] = array();
723
724 $options['hide_premium_options'][] = $current_user->ID;
725
726 return array(
727 'message' => __( 'You can always look at premium options by clicking on the "Show Pro features" in the "Go PRO" tab', 'bestwebsoft' ),
728 'options' => $options );
729 }
730 }
731
732 if ( ! function_exists( 'bws_hide_premium_options_check' ) ) {
733 function bws_hide_premium_options_check( $options ) {
734 global $current_user;
735 if ( ! $current_user )
736 get_currentuserinfo();
737
738 if ( ! empty( $options['hide_premium_options'] ) && in_array( $current_user->ID, $options['hide_premium_options'] ) )
739 return true;
740 else
741 return false;
742 }
743 }
744
745 if ( ! function_exists ( 'bws_plugins_admin_init' ) ) {
746 function bws_plugins_admin_init() {
747 /* Internationalization, first(!) */
748 load_plugin_textdomain( 'bestwebsoft', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
749
750 bws_add_editor_buttons();
751 }
752 }
753
754 if ( ! function_exists ( 'bws_admin_enqueue_scripts' ) ) {
755 function bws_admin_enqueue_scripts() {
756 global $wp_version;
757 wp_enqueue_style( 'bws-admin-css', plugins_url( 'css/general_style.css', __FILE__ ) );
758 wp_enqueue_script( 'bws-admin-scripts', plugins_url( 'js/general_script.js', __FILE__ ), array( 'jquery' ) );
759
760 if ( isset( $_GET['page'] ) && $_GET['page'] == "bws_plugins" ) {
761 wp_enqueue_style( 'bws_menu_style', plugins_url( 'css/style.css', __FILE__ ) );
762 wp_enqueue_script( 'bws_menu_script', plugins_url( 'js/bws_menu.js' , __FILE__ ) );
763 wp_enqueue_script( 'theme-install' );
764 }
765 }
766 }
767
768 if ( ! function_exists ( 'bws_plugins_admin_head' ) ) {
769 function bws_plugins_admin_head() {
770 global $bws_shortcode_list, $wp_version, $post_type;
771 if ( isset( $_GET['page'] ) && $_GET['page'] == "bws_plugins" ) { ?>
772 <noscript>
773 <style type="text/css">
774 .bws_product_button {
775 display: inline-block;
776 }
777 </style>
778 </noscript>
779 <?php }
780 if ( 4.2 > $wp_version ) {
781 $plugin_dir_array = explode( '/', plugin_basename( __FILE__ ) );
782 $plugin_dir = $plugin_dir_array[0]; ?>
783 <style type="text/css">
784 .bws_hide_settings_notice,
785 .bws_hide_premium_options {
786 width: 11px;
787 height: 11px;
788 border: none;
789 background: url("<?php echo plugins_url( $plugin_dir . '/bws_menu/images/close_banner.png' ); ?>") no-repeat center center;
790 box-shadow: none;
791 float: right;
792 margin: 8px;
793 }
794 .bws_hide_settings_notice:hover,
795 .bws_hide_premium_options:hover {
796 cursor: pointer;
797 }
798 .bws_hide_premium_options {
799 position: relative;
800 }
801 </style>
802 <?php }
803 if ( ! empty( $bws_shortcode_list ) ) { ?>
804 <!-- TinyMCE Shortcode Plugin -->
805 <script type='text/javascript'>
806 var bws_shortcode_button = {
807 'title': '<?php _e( "Add BWS Plugins Shortcode", "bestwebsoft" ); ?>',
808 'function_name': [
809 <?php foreach ( $bws_shortcode_list as $key => $value ) {
810 if ( isset( $value['js_function'] ) )
811 echo "'" . $value['js_function'] . "',";
812 } ?>
813 ],
814 'icon_url': '<?php echo plugins_url( "images/shortcode-icon.png" , __FILE__ ); ?>',
815 'wp_version' : '<?php echo $wp_version; ?>'
816 };
817 </script>
818 <!-- TinyMCE Shortcode Plugin -->
819 <?php if ( isset( $post_type ) && in_array( $post_type, array( 'post', 'page' ) ) ) {
820 $tooltip_args = array(
821 'tooltip_id' => 'bws_shortcode_button_tooltip',
822 'css_selector' => '.mce-bws_shortcode_button',
823 'actions' => array(
824 'click' => false,
825 'onload' => true
826 ),
827 'content' => '<h3>' . __( 'Add shortcode', 'bestwebsoft' ) . '</h3><p>' . __( "Add BestWebSoft plugins' shortcodes using this button.", 'bestwebsoft' ) . '</p>',
828 'position' => array(
829 'edge' => 'right'
830 ),
831 'set_timeout' => 2000
832 );
833 if ( $wp_version < '3.9' )
834 $tooltip_args['css_selector'] = '.mce_add_bws_shortcode';
835 bws_add_tooltip_in_admin( $tooltip_args );
836 }
837 }
838 }
839 }
840
841 /**
842 * Tooltip block
843 */
844 if ( ! function_exists( 'bws_add_tooltip_in_admin' ) ) {
845 function bws_add_tooltip_in_admin( $tooltip_args = array() ) {
846 new BWS_admin_tooltip( $tooltip_args );
847 }
848 }
849
850 if ( ! class_exists( 'BWS_admin_tooltip' ) ) {
851 class BWS_admin_tooltip {
852 private $tooltip_args;
853
854 public function __construct( $tooltip_args ) {
855 global $wp_version;
856 if ( 3.3 > $wp_version )
857 return;
858 /* Default arguments */
859 $tooltip_args_default = array(
860 'tooltip_id' => false,
861 'css_selector' => false,
862 'actions' => array(
863 'click' => true,
864 'onload' => false,
865 ),
866 'buttons' => array(
867 'close' => array(
868 'type' => 'dismiss',
869 'text' => __( 'Close', 'bestwebsoft' ),
870 ),
871 ),
872 'position' => array(
873 'edge' => 'top',
874 'align' => 'center',
875 'pos-left' => 0,
876 'pos-top' => 0,
877 'zindex' => 10000
878 ),
879 'set_timeout' => 0
880 );
881 $tooltip_args = array_merge( $tooltip_args_default, $tooltip_args );
882 /* Check that our merged array has default values */
883 foreach ( $tooltip_args_default as $arg_key => $arg_value ) {
884 if ( is_array( $arg_value ) ) {
885 foreach ( $arg_value as $key => $value) {
886 if ( ! isset( $tooltip_args[ $arg_key ][ $key ] ) ) {
887 $tooltip_args[ $arg_key ][ $key ] = $tooltip_args_default[ $arg_key ][ $key ];
888 }
889 }
890 }
891 }
892 /* Check if tooltip is dismissed */
893 if ( true === $tooltip_args['actions']['onload'] ) {
894 if ( in_array( $tooltip_args['tooltip_id'], array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) ) ) ) {
895 $tooltip_args['actions']['onload'] = false;
896 }
897 }
898 /* Check entered data */
899 if ( false === $tooltip_args['tooltip_id'] || false === $tooltip_args['css_selector'] || ( false === $tooltip_args['actions']['click'] && false === $tooltip_args['actions']['onload'] ) ) {
900 /* if not enough data to output a tooltip or both actions (click, onload) are false */
901 return;
902 } else {
903 /* check position */
904 if ( ! in_array( $tooltip_args['position']['edge'], array( 'left', 'right', 'top', 'bottom' ) ) ) {
905 $tooltip_args['position']['edge'] = 'top';
906 }
907 if ( ! in_array( $tooltip_args['position']['align'], array( 'top', 'bottom', 'left', 'right', 'center', ) ) ) {
908 $tooltip_args['position']['align'] = 'center';
909 }
910 }
911 /* fix position */
912 switch ( $tooltip_args['position']['edge'] ) {
913 case 'left':
914 case 'right':
915 switch ( $tooltip_args['position']['align'] ) {
916 case 'top':
917 case 'bottom':
918 $tooltip_args['position']['align'] = 'center';
919 break;
920 }
921 break;
922 case 'top':
923 case 'bottom':
924 if ( $tooltip_args['position']['align'] == 'left' ) {
925 $tooltip_args['position']['pos-left'] -= 65;
926 }
927 break;
928 }
929 $this->tooltip_args = $tooltip_args;
930 /* add styles and scripts */
931 wp_enqueue_style( 'wp-pointer' );
932 wp_enqueue_script( 'wp-pointer' );
933 /* add script that displays our tooltip */
934 add_action( 'admin_print_footer_scripts', array( $this, 'add_scripts' ) );
935 }
936
937 /**
938 * Display tooltip
939 */
940 public function add_scripts() {
941 global $bstwbsftwppdtplgns_tooltip_script_add;
942 if ( ! isset( $bstwbsftwppdtplgns_tooltip_script_add ) ) {
943 echo '<script type="text/javascript" src="' . plugins_url( 'js/bws_tooltip.js', __FILE__ ) . '"></script>';
944 $bstwbsftwppdtplgns_tooltip_script_add = true;
945 }
946 $tooltip_args = $this->tooltip_args; ?>
947 <script type="text/javascript">
948 (function($) {
949 $(document).ready( function() {
950 $.bwsTooltip( <?php echo json_encode( $tooltip_args ); ?> );
951 })
952 })(jQuery);
953 </script>
954 <?php }
955 }
956 }
957
958 if ( ! function_exists ( 'bws_form_restore_default_settings' ) ) {
959 function bws_form_restore_default_settings( $plugin_basename, $change_permission_attr = '' ) { ?>
960 <form method="post" action="">
961 <p><?php _e( 'Restore all plugin settings to defaults', 'bestwebsoft' ); ?></p>
962 <p>
963 <input <?php echo $change_permission_attr; ?> type="submit" class="button" value="<?php _e( 'Restore settings', 'bestwebsoft' ); ?>" />
964 </p>
965 <input type="hidden" name="bws_restore_default" value="submit" />
966 <?php wp_nonce_field( $plugin_basename, 'bws_settings_nonce_name' ); ?>
967 </form>
968 <?php }
969 }
970
971 if ( ! function_exists ( 'bws_form_restore_default_confirm' ) ) {
972 function bws_form_restore_default_confirm( $plugin_basename ) { ?>
973 <div>
974 <p><?php _e( 'Are you sure you want to restore all settings by default?', 'bestwebsoft' ) ?></p>
975 <form method="post" action="">
976 <p>
977 <button class="button" name="bws_restore_confirm"><?php _e( 'Yes, restore all settings', 'bestwebsoft' ) ?></button>
978 <button class="button" name="bws_restore_deny"><?php _e( 'No, go back to the settings page', 'bestwebsoft' ) ?></button>
979 <?php wp_nonce_field( $plugin_basename, 'bws_settings_nonce_name' ); ?>
980 </p>
981 </form>
982 </div>
983 <?php }
984 }
985
986 /* shortcode */
987 if ( ! function_exists( 'bws_add_editor_buttons' ) ) {
988 function bws_add_editor_buttons() {
989 global $bws_shortcode_list, $wp_version;
990 if ( $wp_version < '3.3' )
991 return;
992 if ( ! empty( $bws_shortcode_list ) && current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {
993 add_filter( 'mce_external_plugins', 'bws_add_buttons' );
994 add_filter( 'mce_buttons', 'bws_register_buttons' );
995 }
996 }
997 }
998
999 if ( ! function_exists( 'bws_add_buttons' ) ){
1000 function bws_add_buttons( $plugin_array ) {
1001 $plugin_array['add_bws_shortcode'] = plugins_url( 'js/shortcode-button.js', __FILE__ );
1002 return $plugin_array;
1003 }
1004 }
1005
1006 if ( ! function_exists( 'bws_register_buttons' ) ) {
1007 function bws_register_buttons( $buttons ) {
1008 array_push( $buttons, 'add_bws_shortcode' ); /* dropcap', 'recentposts */
1009 return $buttons;
1010 }
1011 }
1012
1013 /* Generate inline content for the popup window when the "bws shortcode" button is clicked */
1014 if ( ! function_exists( 'bws_shortcode_media_button_popup' ) ) {
1015 function bws_shortcode_media_button_popup() {
1016 global $bws_shortcode_list, $wp_version;
1017 if ( $wp_version < '3.3' )
1018 return;
1019
1020 if ( ! empty( $bws_shortcode_list ) ) { ?>
1021 <div id="bws_shortcode_popup" style="display:none;">
1022 <div id="bws_shortcode_popup_block">
1023 <div id="bws_shortcode_select_plugin">
1024 <h4><?php _e( 'Plugin', 'bestwebsoft' ); ?></h4>
1025 <select name="bws_shortcode_select" id="bws_shortcode_select">
1026 <?php foreach ( $bws_shortcode_list as $key => $value ) { ?>
1027 <option value="<?php echo $key; ?>"><?php echo $value['name']; ?></option>
1028 <?php } ?>
1029 </select>
1030 </div>
1031 <div class="clear"></div>
1032 <div id="bws_shortcode_content">
1033 <h4><?php _e( 'Shortcode settings', 'bestwebsoft' ); ?></h4>
1034 <?php echo apply_filters( 'bws_shortcode_button_content', '' ); ?>
1035 </div>
1036 <div class="clear"></div>
1037 <div id="bws_shortcode_content_bottom">
1038 <p><?php _e( 'The shortcode will be inserted', 'bestwebsoft' ); ?></p>
1039 <div id="bws_shortcode_block"><div id="bws_shortcode_display"></div></div>
1040 </div>
1041 <?php if ( $wp_version < '3.9' ) { ?>
1042 <p>
1043 <button class="button-primary primary bws_shortcode_insert"><?php _e( 'Insert', 'bestwebsoft' ); ?></button>
1044 </p>
1045 <?php } ?>
1046 </div>
1047 </div>
1048 <?php }
1049 if ( $wp_version < '3.9' ) { ?>
1050 <script type="text/javascript">
1051 (function($){
1052 $( '.bws_shortcode_insert' ).on( 'click',function() {
1053 var shortcode = $( '#TB_ajaxContent #bws_shortcode_display' ).text();
1054 if ( '' != shortcode ) {
1055 /* insert shortcode to tinymce */
1056 if ( !tinyMCE.activeEditor || tinyMCE.activeEditor.isHidden() ) {
1057 $( 'textarea#content' ).val( shortcode );
1058 } else {
1059 tinyMCE.execCommand( 'mceInsertContent', false, shortcode );
1060 }
1061 }
1062 /* close the thickbox after adding shortcode to editor */
1063 self.parent.tb_remove();
1064 });
1065 })(jQuery);
1066 </script>
1067 <?php }
1068 }
1069 }
1070
1071 /* add help tab */
1072 if ( ! function_exists( 'bws_help_tab' ) ) {
1073 function bws_help_tab( $screen, $args ) {
1074 $content = '<p><a href="http://support.bestwebsoft.com/hc/en-us/sections/' . $args['section'] . '" target="_blank">' . __( 'Visit Help Center', 'bestwebsoft' ) . '</a></p>';
1075
1076 $screen->add_help_tab(
1077 array(
1078 'id' => $args['id'] . '_help_tab',
1079 'title' => __( 'FAQ', 'bestwebsoft' ),
1080 'content' => $content
1081 )
1082 );
1083
1084 $screen->set_help_sidebar(
1085 '<p><strong>' . __( 'For more information:', 'bestwebsoft' ) . '</strong></p>' .
1086 '<p><a href="https://drive.google.com/folderview?id=0B5l8lO-CaKt9VGh0a09vUjNFNjA&usp=sharing#list" target="_blank">' . __( 'Documentation', 'bestwebsoft' ) . '</a></p>' .
1087 '<p><a href="http://www.youtube.com/user/bestwebsoft/playlists?flow=grid&sort=da&view=1" target="_blank">' . __( 'Video Instructions', 'bestwebsoft' ) . '</a></p>' .
1088 '<p><a href="http://support.bestwebsoft.com/hc/en-us/requests/new" target="_blank">' . __( 'Submit a Request', 'bestwebsoft' ) . '</a></p>'
1089 );
1090 }
1091 }
1092
1093 add_action( 'admin_init', 'bws_plugins_admin_init' );
1094 add_action( 'admin_enqueue_scripts', 'bws_admin_enqueue_scripts' );
1095 add_action( 'admin_head', 'bws_plugins_admin_head' );
1096 add_action( 'admin_footer','bws_shortcode_media_button_popup' );
1097
1098 add_action( 'admin_notices', 'bws_versions_notice' );