|
1 <?php |
|
2 /* |
|
3 * General functions for BestWebSoft plugins |
|
4 * Version: 1.0.9 |
|
5 */ |
|
6 if ( ! function_exists ( 'bws_add_general_menu' ) ) { |
|
7 function bws_add_general_menu( $base ) { |
|
8 global $bstwbsftwppdtplgns_options, $bstwbsftwppdtplgns_added_menu; |
|
9 $bws_menu_info = get_plugin_data( dirname( dirname( plugin_dir_path( __FILE__ ) ) ) . '/' . dirname( $base ) . '/bws_menu/bws_menu.php' ); |
|
10 $bws_menu_version = $bws_menu_info["Version"]; |
|
11 |
|
12 if ( ! isset( $bstwbsftwppdtplgns_options ) ) { |
|
13 if ( is_multisite() ) { |
|
14 if ( ! get_site_option( 'bstwbsftwppdtplgns_options' ) ) |
|
15 add_site_option( 'bstwbsftwppdtplgns_options', array() ); |
|
16 $bstwbsftwppdtplgns_options = get_site_option( 'bstwbsftwppdtplgns_options' ); |
|
17 } else { |
|
18 if ( ! get_option( 'bstwbsftwppdtplgns_options' ) ) |
|
19 add_option( 'bstwbsftwppdtplgns_options', array() ); |
|
20 $bstwbsftwppdtplgns_options = get_option( 'bstwbsftwppdtplgns_options' ); |
|
21 } |
|
22 } |
|
23 |
|
24 if ( isset( $bstwbsftwppdtplgns_options['bws_menu_version'] ) ) { |
|
25 $bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] = $bws_menu_version; |
|
26 unset( $bstwbsftwppdtplgns_options['bws_menu_version'] ); |
|
27 if ( is_multisite() ) |
|
28 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
|
29 else |
|
30 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
|
31 require_once( dirname( __FILE__ ) . '/bws_menu.php' ); |
|
32 } else if ( ! isset( $bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] ) || $bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] < $bws_menu_version ) { |
|
33 $bstwbsftwppdtplgns_options['bws_menu']['version'][ $base ] = $bws_menu_version; |
|
34 if ( is_multisite() ) |
|
35 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
|
36 else |
|
37 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
|
38 require_once( dirname( __FILE__ ) . '/bws_menu.php' ); |
|
39 } else if ( ! isset( $bstwbsftwppdtplgns_added_menu ) ) { |
|
40 $all_plugins = get_plugins(); |
|
41 foreach ( $bstwbsftwppdtplgns_options['bws_menu']['version'] as $key => $value ) { |
|
42 if ( array_key_exists( $key, $all_plugins ) ) { |
|
43 if ( $bws_menu_version < $value && is_plugin_active( $base ) ) { |
|
44 if ( ! isset( $plugin_with_newer_menu ) ) |
|
45 $plugin_with_newer_menu = $key; |
|
46 elseif ( $bstwbsftwppdtplgns_options['bws_menu']['version'][ $plugin_with_newer_menu ] < $bstwbsftwppdtplgns_options['bws_menu']['version'][ $key ] ) |
|
47 $plugin_with_newer_menu = $key; |
|
48 } |
|
49 } else { |
|
50 unset( $bstwbsftwppdtplgns_options['bws_menu']['version'][ $key ] ); |
|
51 if ( is_multisite() ) |
|
52 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
|
53 else |
|
54 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
|
55 } |
|
56 } |
|
57 if ( ! isset( $plugin_with_newer_menu ) ) |
|
58 $plugin_with_newer_menu = $base; |
|
59 $plugin_with_newer_menu = explode( '/', $plugin_with_newer_menu ); |
|
60 $wp_content_dir = defined( 'WP_CONTENT_DIR' ) ? basename( WP_CONTENT_DIR ) : 'wp-content'; |
|
61 |
|
62 if ( file_exists( ABSPATH . $wp_content_dir . '/plugins/' . $plugin_with_newer_menu[0] . '/bws_menu/bws_menu.php' ) ) |
|
63 require_once( ABSPATH . $wp_content_dir . '/plugins/' . $plugin_with_newer_menu[0] . '/bws_menu/bws_menu.php' ); |
|
64 else |
|
65 require_once( dirname( __FILE__ ) . '/bws_menu.php' ); |
|
66 $bstwbsftwppdtplgns_added_menu = true; |
|
67 } |
|
68 add_menu_page( 'BWS Plugins', 'BWS Plugins', 'manage_options', 'bws_plugins', 'bws_add_menu_render', plugins_url( 'images/px.png', __FILE__ ), 1001 ); |
|
69 } |
|
70 } |
|
71 |
|
72 |
|
73 /** |
|
74 * Function check if plugin is compatible with current WP version |
|
75 * @return void |
|
76 */ |
|
77 if ( ! function_exists ( 'bws_wp_version_check' ) ) { |
|
78 function bws_wp_version_check( $plugin_basename, $plugin_info, $require_wp ) { |
|
79 global $wp_version; |
|
80 if ( version_compare( $wp_version, $require_wp, "<" ) ) { |
|
81 include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
82 if ( is_plugin_active( $plugin_basename ) ) { |
|
83 deactivate_plugins( $plugin_basename ); |
|
84 $admin_url = ( function_exists( 'get_admin_url' ) ) ? get_admin_url( null, 'plugins.php' ) : esc_url( '/wp-admin/plugins.php' ); |
|
85 wp_die( |
|
86 sprintf( |
|
87 "<strong>%s</strong> %s <strong>WordPress %s</strong> %s <br /><br />%s <a href='%s'>%s</a>.", |
|
88 $plugin_info['Name'], |
|
89 __( 'requires', 'bestwebsoft' ), |
|
90 $require_wp, |
|
91 __( 'or higher, that is why it has been deactivated! Please upgrade WordPress and try again.', 'bestwebsoft' ), |
|
92 __( 'Back to the WordPress', 'bestwebsoft' ), |
|
93 $admin_url, |
|
94 __( 'Plugins page', 'bestwebsoft' ) |
|
95 ) |
|
96 ); |
|
97 } |
|
98 } |
|
99 } |
|
100 } |
|
101 |
|
102 if ( ! function_exists( 'bws_plugin_banner' ) ) { |
|
103 function bws_plugin_banner( $plugin_info, $this_banner_prefix, $link_slug, $link_key, $link_pn, $banner_url_or_slug ) { |
|
104 global $wp_version, $bstwbsftwppdtplgns_cookie_add, $bstwbsftwppdtplgns_banner_array; |
|
105 |
|
106 if ( empty( $bstwbsftwppdtplgns_banner_array ) ) { |
|
107 if ( ! function_exists( 'bws_get_banner_array' ) ) |
|
108 require_once( dirname( __FILE__ ) . '/bws_menu.php' ); |
|
109 bws_get_banner_array(); |
|
110 } |
|
111 |
|
112 if ( false == strrpos( $banner_url_or_slug, '/' ) ) { |
|
113 $banner_url_or_slug = '//ps.w.org/' . $banner_url_or_slug . '/assets/icon-128x128.png'; |
|
114 } |
|
115 |
|
116 if ( ! function_exists( 'is_plugin_active' ) ) |
|
117 require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
118 |
|
119 $all_plugins = get_plugins(); |
|
120 |
|
121 $this_banner = $this_banner_prefix . '_hide_banner_on_plugin_page'; |
|
122 foreach ( $bstwbsftwppdtplgns_banner_array as $key => $value ) { |
|
123 if ( $this_banner == $value[0] ) { |
|
124 if ( ! isset( $bstwbsftwppdtplgns_cookie_add ) ) { |
|
125 echo '<script type="text/javascript" src="' . plugins_url( 'js/c_o_o_k_i_e.js', __FILE__ ) . '"></script>'; |
|
126 $bstwbsftwppdtplgns_cookie_add = true; |
|
127 } ?> |
|
128 <script type="text/javascript"> |
|
129 (function($) { |
|
130 $(document).ready( function() { |
|
131 var hide_message = $.cookie( '<?php echo $this_banner_prefix; ?>_hide_banner_on_plugin_page' ); |
|
132 if ( hide_message == "true" ) { |
|
133 $( ".<?php echo $this_banner_prefix; ?>_message" ).css( "display", "none" ); |
|
134 } else { |
|
135 $( ".<?php echo $this_banner_prefix; ?>_message" ).css( "display", "block" ); |
|
136 }; |
|
137 $( ".<?php echo $this_banner_prefix; ?>_close_icon" ).click( function() { |
|
138 $( ".<?php echo $this_banner_prefix; ?>_message" ).css( "display", "none" ); |
|
139 $.cookie( "<?php echo $this_banner_prefix; ?>_hide_banner_on_plugin_page", "true", { expires: 32 } ); |
|
140 }); |
|
141 }); |
|
142 })(jQuery); |
|
143 </script> |
|
144 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;"> |
|
145 <div class="<?php echo $this_banner_prefix; ?>_message bws_banner_on_plugin_page" style="display: none;"> |
|
146 <img class="<?php echo $this_banner_prefix; ?>_close_icon close_icon" title="" src="<?php echo plugins_url( 'images/close_banner.png', __FILE__ ); ?>" alt=""/> |
|
147 <div class="icon"> |
|
148 <img title="" src="<?php echo esc_attr( $banner_url_or_slug ); ?>" alt="" /> |
|
149 </div> |
|
150 <div class="text"><?php |
|
151 _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 /> |
|
152 <span><?php _e( 'Extend standard plugin functionality with new great options.', 'bestwebsoft' ); ?></span> |
|
153 </div> |
|
154 <div class="button_div"> |
|
155 <a class="button" target="_blank" href="http://bestwebsoft.com/products/<?php echo $link_slug; ?>/?k=<?php echo $link_key; ?>&pn=<?php echo $link_pn; ?>&v=<?php echo $plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>"><?php _e( 'Learn More', 'bestwebsoft' ); ?></a> |
|
156 </div> |
|
157 </div> |
|
158 </div> |
|
159 <?php break; |
|
160 } |
|
161 if ( isset( $all_plugins[ $value[1] ] ) && $all_plugins[ $value[1] ]["Version"] >= $value[2] && is_plugin_active( $value[1] ) && ! isset( $_COOKIE[ $value[0] ] ) ) { |
|
162 break; |
|
163 } |
|
164 } |
|
165 } |
|
166 } |
|
167 |
|
168 if ( ! function_exists( 'bws_plugin_reviews_block' ) ) { |
|
169 function bws_plugin_reviews_block( $plugin_name, $plugin_slug ) { ?> |
|
170 <div class="bws-plugin-reviews"> |
|
171 <div class="bws-plugin-reviews-rate"> |
|
172 <?php _e( 'If you enjoy our plugin, please give it 5 stars on WordPress', 'bestwebsoft' ); ?>: |
|
173 <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> |
|
174 </div> |
|
175 <div class="bws-plugin-reviews-support"> |
|
176 <?php _e( 'If there is something wrong about it, please contact us', 'bestwebsoft' ); ?>: |
|
177 <a href="http://support.bestwebsoft.com">http://support.bestwebsoft.com</a> |
|
178 </div> |
|
179 </div> |
|
180 <?php } |
|
181 } |
|
182 |
|
183 if ( ! function_exists( 'bws_go_pro_tab_check' ) ) { |
|
184 function bws_go_pro_tab_check( $plugin_basename ) { |
|
185 global $wp_version, $bstwbsftwppdtplgns_options; |
|
186 $result = array(); |
|
187 |
|
188 $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : ""; |
|
189 |
|
190 if ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) { |
|
191 if ( '' != $bws_license_key ) { |
|
192 if ( strlen( $bws_license_key ) != 18 ) { |
|
193 $result['error'] = __( "Wrong license key", 'bestwebsoft' ); |
|
194 } else { |
|
195 $bws_license_plugin = stripslashes( esc_html( $_POST['bws_license_plugin'] ) ); |
|
196 if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] ) && $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] > ( time() - (24 * 60 * 60) ) ) { |
|
197 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] + 1; |
|
198 } else { |
|
199 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = 1; |
|
200 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] = time(); |
|
201 } |
|
202 |
|
203 /* download Pro */ |
|
204 if ( ! function_exists( 'get_plugins' ) ) |
|
205 require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
206 |
|
207 $all_plugins = get_plugins(); |
|
208 |
|
209 if ( ! array_key_exists( $bws_license_plugin, $all_plugins ) ) { |
|
210 $current = get_site_transient( 'update_plugins' ); |
|
211 if ( is_array( $all_plugins ) && !empty( $all_plugins ) && isset( $current ) && is_array( $current->response ) ) { |
|
212 $to_send = array(); |
|
213 $to_send["plugins"][ $bws_license_plugin ] = array(); |
|
214 $to_send["plugins"][ $bws_license_plugin ]["bws_license_key"] = $bws_license_key; |
|
215 $to_send["plugins"][ $bws_license_plugin ]["bws_illegal_client"] = true; |
|
216 $options = array( |
|
217 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ), |
|
218 'body' => array( 'plugins' => serialize( $to_send ) ), |
|
219 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ); |
|
220 $raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options ); |
|
221 |
|
222 if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) { |
|
223 $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' ); |
|
224 } else { |
|
225 $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); |
|
226 if ( is_array( $response ) && !empty( $response ) ) { |
|
227 foreach ( $response as $key => $value ) { |
|
228 if ( "wrong_license_key" == $value->package ) { |
|
229 $result['error'] = __( "Wrong license key", 'bestwebsoft' ); |
|
230 } elseif ( "wrong_domain" == $value->package ) { |
|
231 $result['error'] = __( "This license key is bind to another site", 'bestwebsoft' ); |
|
232 } elseif ( "you_are_banned" == $value->package ) { |
|
233 $result['error'] = __( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' ); |
|
234 } elseif ( "time_out" == $value->package ) { |
|
235 $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>'; |
|
236 } elseif ( "duplicate_domen_for_trial" == $value->package ) { |
|
237 $result['error'] = __( "Unfortunately, the PRO licence was already installed to this domain. The PRO Trial license can be installed only once.", 'bestwebsoft' ); |
|
238 } |
|
239 } |
|
240 if ( empty( $result['error'] ) ) { |
|
241 $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key; |
|
242 |
|
243 $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'; |
|
244 $uploadDir = wp_upload_dir(); |
|
245 $zip_name = explode( '/', $bws_license_plugin ); |
|
246 $received_content = file_get_contents( $url ); |
|
247 if ( ! $received_content ) { |
|
248 $result['error'] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' ); |
|
249 } else { |
|
250 if ( is_writable( $uploadDir["path"] ) ) { |
|
251 $file_put_contents = $uploadDir["path"] . "/" . $zip_name[0] . ".zip"; |
|
252 if ( file_put_contents( $file_put_contents, $received_content ) ) { |
|
253 @chmod( $file_put_contents, octdec( 755 ) ); |
|
254 if ( class_exists( 'ZipArchive' ) ) { |
|
255 $zip = new ZipArchive(); |
|
256 if ( $zip->open( $file_put_contents ) === TRUE ) { |
|
257 $zip->extractTo( WP_PLUGIN_DIR ); |
|
258 $zip->close(); |
|
259 } else { |
|
260 $result['error'] = __( "Failed to open the zip archive. Please, upload the plugin manually", 'bestwebsoft' ); |
|
261 } |
|
262 } elseif ( class_exists( 'Phar' ) ) { |
|
263 $phar = new PharData( $file_put_contents ); |
|
264 $phar->extractTo( WP_PLUGIN_DIR ); |
|
265 } else { |
|
266 $result['error'] = __( "Your server does not support either ZipArchive or Phar. Please, upload the plugin manually", 'bestwebsoft' ); |
|
267 } |
|
268 @unlink( $file_put_contents ); |
|
269 } else { |
|
270 $result['error'] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' ); |
|
271 } |
|
272 } else { |
|
273 $result['error'] = __( "UploadDir is not writable. Please, upload the plugin manually", 'bestwebsoft' ); |
|
274 } |
|
275 } |
|
276 |
|
277 /* activate Pro */ |
|
278 if ( file_exists( WP_PLUGIN_DIR . '/' . $zip_name[0] ) ) { |
|
279 if ( is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) { |
|
280 /* if multisite and free plugin is network activated */ |
|
281 $active_plugins = get_site_option( 'active_sitewide_plugins' ); |
|
282 $active_plugins[ $bws_license_plugin ] = time(); |
|
283 update_site_option( 'active_sitewide_plugins', $active_plugins ); |
|
284 } else { |
|
285 /* activate on a single blog */ |
|
286 $active_plugins = get_option( 'active_plugins' ); |
|
287 array_push( $active_plugins, $bws_license_plugin ); |
|
288 update_option( 'active_plugins', $active_plugins ); |
|
289 } |
|
290 $result['pro_plugin_is_activated'] = true; |
|
291 } elseif ( empty( $result['error'] ) ) { |
|
292 $result['error'] = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' ); |
|
293 } |
|
294 } |
|
295 } else { |
|
296 $result['error'] = __( "Something went wrong. Try again later or upload the plugin manually. We are sorry for inconvenience.", 'bestwebsoft' ); |
|
297 } |
|
298 } |
|
299 } |
|
300 } else { |
|
301 $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key; |
|
302 /* activate Pro */ |
|
303 if ( ! is_plugin_active( $bws_license_plugin ) ) { |
|
304 if ( is_multisite() && is_plugin_active_for_network( plugin_basename( __FILE__ ) ) ) { |
|
305 /* if multisite and free plugin is network activated */ |
|
306 $network_wide = true; |
|
307 } else { |
|
308 /* activate on a single blog */ |
|
309 $network_wide = false; |
|
310 } |
|
311 activate_plugin( $bws_license_plugin, NULL, $network_wide ); |
|
312 $result['pro_plugin_is_activated'] = true; |
|
313 } |
|
314 } |
|
315 if ( is_multisite() ) |
|
316 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
|
317 else |
|
318 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
|
319 } |
|
320 } else { |
|
321 $result['error'] = __( "Please, enter Your license key", 'bestwebsoft' ); |
|
322 } |
|
323 } |
|
324 return $result; |
|
325 } |
|
326 } |
|
327 |
|
328 if ( ! function_exists( 'bws_go_pro_tab' ) ) { |
|
329 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 ) { |
|
330 global $wp_version, $bstwbsftwppdtplgns_options; |
|
331 $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : ""; |
|
332 if ( $pro_plugin_is_activated ) { ?> |
|
333 <script type="text/javascript"> |
|
334 window.setTimeout( function() { |
|
335 window.location.href = 'admin.php?page=<?php echo $pro_page; ?>'; |
|
336 }, 5000 ); |
|
337 </script> |
|
338 <p><?php _e( "Congratulations! The PRO version of the plugin is successfully download and activated.", 'bestwebsoft' ); ?></p> |
|
339 <p> |
|
340 <?php _e( "Please, go to", 'bestwebsoft' ); ?> <a href="admin.php?page=<?php echo $pro_page; ?>"><?php _e( 'the setting page', 'bestwebsoft' ); ?></a> |
|
341 (<?php _e( "You will be redirected automatically in 5 seconds.", 'bestwebsoft' ); ?>) |
|
342 </p> |
|
343 <?php } else { ?> |
|
344 <form method="post" action="admin.php?page=<?php echo $page; ?>&action=go_pro"> |
|
345 <p> |
|
346 <?php _e( 'You can download and activate', 'bestwebsoft' ); ?> |
|
347 <a href="http://bestwebsoft.com/products/<?php echo $link_slug; ?>/?k=<?php echo $link_key; ?>&pn=<?php echo $link_pn; ?>&v=<?php echo $plugin_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="<?php echo $plugin_info["Name"]; ?> Pro">PRO</a> |
|
348 <?php _e( 'version of this plugin by entering Your license key.', 'bestwebsoft' ); ?><br /> |
|
349 <span class="bws_info"> |
|
350 <?php _e( 'You can find your license key on your personal page Client area, by clicking on the link', 'bestwebsoft' ); ?> |
|
351 <a href="http://bestwebsoft.com/wp-login.php">http://bestwebsoft.com/wp-login.php</a> |
|
352 <?php _e( '(your username is the email you specify when purchasing the product).', 'bestwebsoft' ); ?> |
|
353 </span> |
|
354 </p> |
|
355 <?php if ( $trial_days_number !== false ) |
|
356 $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>'; |
|
357 if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] ) && |
|
358 '5' < $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] && |
|
359 $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] > ( time() - ( 24 * 60 * 60 ) ) ) { ?> |
|
360 <p> |
|
361 <input disabled="disabled" type="text" name="bws_license_key" value="<?php echo $bws_license_key; ?>" /> |
|
362 <input disabled="disabled" type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" /> |
|
363 <?php if ( $trial_days_number !== false ) echo $trial_days_number; ?> |
|
364 </p> |
|
365 <p><?php _e( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' ); ?></p> |
|
366 <?php } else { ?> |
|
367 <p> |
|
368 <input type="text" name="bws_license_key" value="<?php echo $bws_license_key; ?>" /> |
|
369 <input type="hidden" name="bws_license_plugin" value="<?php echo $bws_license_plugin; ?>" /> |
|
370 <input type="hidden" name="bws_license_submit" value="submit" /> |
|
371 <input type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" /> |
|
372 <?php if ( $trial_days_number !== false ) echo $trial_days_number; |
|
373 wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?> |
|
374 </p> |
|
375 <?php } ?> |
|
376 </form> |
|
377 <?php } |
|
378 } |
|
379 } |
|
380 |
|
381 if ( ! function_exists( 'bws_go_pro_from_trial_tab' ) ) { |
|
382 function bws_go_pro_from_trial_tab( $plugin_info, $plugin_basename, $page, $link_slug, $link_key, $link_pn, $trial_license_is_set = true ) { |
|
383 global $wp_version, $bstwbsftwppdtplgns_options; |
|
384 $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : ""; |
|
385 if ( $trial_license_is_set ) { ?> |
|
386 <form method="post" action="admin.php?page=<?php echo $page; ?>&action=go_pro"> |
|
387 <p> |
|
388 <?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 . '&pn=' . $link_pn . '&v=' . $plugin_info["Version"] . '&wp_v=' . $wp_version .'" target="_blank" title="' . $plugin_info["Name"] . '">PRO</a>' ) . ' '; |
|
389 _e( 'After that you can activate it by entering your license key.', 'bestwebsoft' ); ?><br /> |
|
390 <span class="bws_info"> |
|
391 <?php _e( 'You can find your license key on your personal page Client area, by clicking on the link', 'bestwebsoft' ); ?> |
|
392 <a href="http://bestwebsoft.com/wp-login.php">http://bestwebsoft.com/wp-login.php</a> |
|
393 <?php _e( '(your username is the email you specify when purchasing the product).', 'bestwebsoft' ); ?> |
|
394 </span> |
|
395 </p> |
|
396 <?php if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $plugin_basename ]['count'] ) && |
|
397 '5' < $bstwbsftwppdtplgns_options['go_pro'][ $plugin_basename ]['count'] && |
|
398 $bstwbsftwppdtplgns_options['go_pro'][ $plugin_basename ]['time'] > ( time() - ( 24 * 60 * 60 ) ) ) { ?> |
|
399 <p> |
|
400 <input disabled="disabled" type="text" name="bws_license_key" value="" /> |
|
401 <input disabled="disabled" type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" /> |
|
402 </p> |
|
403 <p><?php _e( "Unfortunately, you have exceeded the number of available tries per day.", 'bestwebsoft' ); ?></p> |
|
404 <?php } else { ?> |
|
405 <p> |
|
406 <input type="text" name="bws_license_key" value="" /> |
|
407 <input type="hidden" name="bws_license_plugin" value="<?php echo $plugin_basename; ?>" /> |
|
408 <input type="hidden" name="bws_license_submit" value="submit" /> |
|
409 <input type="submit" class="button-primary" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" /> |
|
410 <?php wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?> |
|
411 </p> |
|
412 <?php } ?> |
|
413 </form> |
|
414 <?php } else { ?> |
|
415 <script type="text/javascript"> |
|
416 window.setTimeout( function() { |
|
417 window.location.href = 'admin.php?page=<?php echo $page; ?>'; |
|
418 }, 5000 ); |
|
419 </script> |
|
420 <p><?php _e( "Congratulations! The PRO license of the plugin is successfully activated.", 'bestwebsoft' ); ?></p> |
|
421 <p> |
|
422 <?php _e( "Please, go to", 'bestwebsoft' ); ?> <a href="admin.php?page=<?php echo $page; ?>"><?php _e( 'the setting page', 'bestwebsoft' ); ?></a> |
|
423 (<?php _e( "You will be redirected automatically in 5 seconds.", 'bestwebsoft' ); ?>) |
|
424 </p> |
|
425 <?php } |
|
426 } |
|
427 } |
|
428 |
|
429 if ( ! function_exists( 'bws_check_pro_license' ) ) { |
|
430 function bws_check_pro_license( $plugin_basename, $trial_plugin = false ) { |
|
431 global $wp_version, $bstwbsftwppdtplgns_options; |
|
432 $result = array(); |
|
433 |
|
434 if ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( $plugin_basename, 'bws_license_nonce_name' ) ) { |
|
435 $license_key = isset( $_POST['bws_license_key'] ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : ''; |
|
436 |
|
437 if ( '' != $license_key ) { |
|
438 if ( ! function_exists( 'get_plugins' ) ) |
|
439 require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
440 $plugins_all = get_plugins(); |
|
441 $current = get_site_transient( 'update_plugins' ); |
|
442 |
|
443 if ( is_array( $plugins_all ) && !empty( $plugins_all ) && isset( $current ) && is_array( $current->response ) ) { |
|
444 $to_send = array(); |
|
445 $to_send["plugins"][ $plugin_basename ] = $plugins_all[ $plugin_basename ]; |
|
446 $to_send["plugins"][ $plugin_basename ]["bws_license_key"] = $license_key; |
|
447 $to_send["plugins"][ $plugin_basename ]["bws_illegal_client"] = true; |
|
448 $options = array( |
|
449 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3), |
|
450 'body' => array( 'plugins' => serialize( $to_send ) ), |
|
451 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) |
|
452 ); |
|
453 $raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options ); |
|
454 if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) { |
|
455 $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' ); |
|
456 } else { |
|
457 $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); |
|
458 if ( is_array( $response ) && !empty( $response ) ) { |
|
459 foreach ( $response as $key => $value ) { |
|
460 if ( "wrong_license_key" == $value->package ) { |
|
461 $result['error'] = __( 'Wrong license key.', 'bestwebsoft' ); |
|
462 } else if ( "wrong_domain" == $value->package ) { |
|
463 $result['error'] = __( 'This license key is bind to another site.', 'bestwebsoft' ); |
|
464 } else if ( "time_out" == $value->package ) { |
|
465 $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' ); |
|
466 } elseif ( "you_are_banned" == $value->package ) { |
|
467 $result['error'] = __( "Unfortunately, you have exceeded the number of available tries.", 'bestwebsoft' ); |
|
468 } elseif ( "duplicate_domen_for_trial" == $value->package ) { |
|
469 $result['error'] = __( "Unfortunately, the PRO Trial licence was already installed to this domain. The PRO Trial license can be installed only once.", 'bestwebsoft' ); |
|
470 } |
|
471 if ( empty( $result['message'] ) && empty( $result['error'] ) ) { |
|
472 if ( isset( $value->trial ) ) |
|
473 $result['message'] = __( 'The PRO Trial license key is valid.', 'bestwebsoft' ); |
|
474 else |
|
475 $result['message'] = __( 'The license key is valid.', 'bestwebsoft' ); |
|
476 |
|
477 if ( isset( $value->time_out ) && $value->time_out != '' ) |
|
478 $result['message'] .= ' ' . __( 'Your license will expire on', 'bestwebsoft' ) . ' ' . $value->time_out . '.'; |
|
479 |
|
480 if ( isset( $value->trial ) && $trial_plugin != false ) |
|
481 $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>' ); |
|
482 |
|
483 if ( isset( $value->trial ) ) { |
|
484 $bstwbsftwppdtplgns_options['trial'][ $plugin_basename ] = 1; |
|
485 } else { |
|
486 unset( $bstwbsftwppdtplgns_options['trial'][ $plugin_basename ] ); |
|
487 } |
|
488 } |
|
489 if ( empty( $result['error'] ) ) { |
|
490 if ( $bstwbsftwppdtplgns_options[ $plugin_basename ] != $license_key ) { |
|
491 $bstwbsftwppdtplgns_options[ $plugin_basename ] = $license_key; |
|
492 $bstwbsftwppdtplgns_options['time_out'][ $plugin_basename ] = $value->time_out; |
|
493 if ( is_multisite() ) |
|
494 update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
|
495 else |
|
496 update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); |
|
497 $file = @fopen( dirname( dirname( __FILE__ ) ) . "/license_key.txt" , "w+" ); |
|
498 if ( $file ) { |
|
499 @fwrite( $file, $license_key ); |
|
500 @fclose( $file ); |
|
501 } |
|
502 } |
|
503 } |
|
504 } |
|
505 } else { |
|
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 } |
|
508 } |
|
509 } |
|
510 } else { |
|
511 $result['error'] = __( 'Please, enter your license key', 'bestwebsoft' ); |
|
512 } |
|
513 } |
|
514 return $result; |
|
515 } |
|
516 } |
|
517 |
|
518 if ( ! function_exists ( 'bws_check_pro_license_form' ) ) { |
|
519 function bws_check_pro_license_form( $plugin_basename, $page ) { |
|
520 global $bstwbsftwppdtplgns_options; |
|
521 $license_key = ( isset( $bstwbsftwppdtplgns_options[ $plugin_basename ] ) ) ? $bstwbsftwppdtplgns_options[ $plugin_basename ] : ''; ?> |
|
522 <div class="clear"></div> |
|
523 <form method="post" action="admin.php?page=<?php echo $page; ?>"> |
|
524 <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> |
|
525 <p> |
|
526 <input type="text" name="bws_license_key" value="<?php echo $license_key; ?>" /> |
|
527 <input type="hidden" name="bws_license_submit" value="submit" /> |
|
528 <input type="submit" class="button-primary" value="<?php _e( 'Check license key', 'bestwebsoft' ) ?>" /> |
|
529 <?php wp_nonce_field( $plugin_basename, 'bws_license_nonce_name' ); ?> |
|
530 </p> |
|
531 </form> |
|
532 <?php } |
|
533 } |
|
534 |
|
535 if ( ! function_exists ( 'bws_plugin_update_row' ) ) { |
|
536 function bws_plugin_update_row( $plugin_key, $link_slug = false, $free_plugin_name = false ) { |
|
537 global $bstwbsftwppdtplgns_options; |
|
538 $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); |
|
539 if ( isset( $bstwbsftwppdtplgns_options['wrong_license_key'][ $plugin_key ] ) ) { |
|
540 echo '<tr class="plugin-update-tr"> |
|
541 <td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"> |
|
542 <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> |
|
543 </td> |
|
544 </tr>'; |
|
545 } elseif ( isset( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) && strtotime( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) < strtotime( date("m/d/Y") ) ) { |
|
546 echo '<tr class="plugin-update-tr"> |
|
547 <td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"> |
|
548 <div class="update-message" style="color: #8C0000;">'; |
|
549 if ( isset( $bstwbsftwppdtplgns_options['trial'][ $plugin_key ] ) && $link_slug != false ) { |
|
550 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>'; |
|
551 } else { |
|
552 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>'; |
|
553 } |
|
554 echo '</div> |
|
555 </td> |
|
556 </tr>'; |
|
557 } elseif ( isset( $bstwbsftwppdtplgns_options['trial'][ $plugin_key ] ) ) { |
|
558 echo '<tr class="plugin-update-tr"> |
|
559 <td colspan="' . $wp_list_table->get_column_count() . '" class="plugin-update colspanchange"> |
|
560 <div class="update-message" style="color: #8C0000;">'; |
|
561 if ( $free_plugin_name != false ) { |
|
562 echo sprintf( __( 'Notice: You are using the PRO Trial license of %s plugin.', 'bestwebsoft' ), $free_plugin_name ); |
|
563 } else { |
|
564 _e( 'Notice: You are using the PRO Trial license of plugin.', 'bestwebsoft' ); |
|
565 } |
|
566 if ( isset( $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] ) ) |
|
567 echo ' ' . __( "The PRO Trial license will expire on", 'bestwebsoft' ) . ' ' . $bstwbsftwppdtplgns_options['time_out'][ $plugin_key ] . '.'; |
|
568 echo '</div> |
|
569 </td> |
|
570 </tr>'; |
|
571 } |
|
572 } |
|
573 } |
|
574 |
|
575 if ( ! function_exists ( 'bws_plugin_banner_timeout' ) ) { |
|
576 function bws_plugin_banner_timeout( $plugin_key, $plugin_prefix, $plugin_name, $banner_url = false ) { |
|
577 global $bstwbsftwppdtplgns_options, $bstwbsftwppdtplgns_cookie_add; |
|
578 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") ) ) ) { |
|
579 if ( ! isset( $bstwbsftwppdtplgns_cookie_add ) ) { |
|
580 echo '<script type="text/javascript" src="' . plugins_url( 'js/c_o_o_k_i_e.js', __FILE__ ) . '"></script>'; |
|
581 $bstwbsftwppdtplgns_cookie_add = true; |
|
582 } ?> |
|
583 <script type="text/javascript"> |
|
584 (function($) { |
|
585 $(document).ready( function() { |
|
586 var hide_message = $.cookie( "<?php echo $plugin_prefix; ?>_timeout_hide_banner_on_plugin_page" ); |
|
587 if ( hide_message == "true" ) { |
|
588 $( ".<?php echo $plugin_prefix; ?>_message" ).css( "display", "none" ); |
|
589 } else { |
|
590 $( ".<?php echo $plugin_prefix; ?>_message" ).css( "display", "block" ); |
|
591 } |
|
592 $( ".<?php echo $plugin_prefix; ?>_close_icon" ).click( function() { |
|
593 $( ".<?php echo $plugin_prefix; ?>_message" ).css( "display", "none" ); |
|
594 $.cookie( "<?php echo $plugin_prefix; ?>_timeout_hide_banner_on_plugin_page", "true", { expires: 30 } ); |
|
595 }); |
|
596 }); |
|
597 })(jQuery); |
|
598 </script> |
|
599 <div class="updated" style="padding: 0; margin: 0; border: none; background: none;"> |
|
600 <div class="<?php echo $plugin_prefix; ?>_message bws_banner_on_plugin_page" style="display:none;"> |
|
601 <img class="<?php echo $plugin_prefix; ?>_close_icon close_icon" title="" src="<?php echo plugins_url( 'images/close_banner.png', __FILE__ ); ?>" alt=""/> |
|
602 <div class="icon"> |
|
603 <img title="" src="<?php echo $banner_url; ?>" alt="" /> |
|
604 </div> |
|
605 <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> |
|
606 </div> |
|
607 </div> |
|
608 <?php } |
|
609 } |
|
610 } |
|
611 |
|
612 if ( ! function_exists ( 'bws_plugin_init' ) ) { |
|
613 function bws_plugin_init() { |
|
614 /* Internationalization, first(!) */ |
|
615 load_plugin_textdomain( 'bestwebsoft', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
|
616 } |
|
617 } |
|
618 |
|
619 if ( ! function_exists ( 'bws_admin_add_scripts' ) ) { |
|
620 function bws_admin_add_scripts() { |
|
621 global $wp_version; |
|
622 if ( $wp_version < 3.8 ) |
|
623 wp_enqueue_style( 'bws-admin-style', plugins_url( 'css/general_style_wp_before_3.8.css', __FILE__ ) ); |
|
624 else |
|
625 wp_enqueue_style( 'bws-admin-style', plugins_url( 'css/general_style.css', __FILE__ ) ); |
|
626 |
|
627 if ( isset( $_GET['page'] ) && $_GET['page'] == "bws_plugins" ) { |
|
628 wp_enqueue_style( 'bws_menu_style', plugins_url( 'css/style.css', __FILE__ ) ); |
|
629 wp_enqueue_script( 'bws_menu_script', plugins_url( 'js/bws_menu.js' , __FILE__ ) ); |
|
630 if ( $wp_version >= '3.8' ) |
|
631 wp_enqueue_script( 'theme-install' ); |
|
632 elseif ( $wp_version >= '3.4' ) |
|
633 wp_enqueue_script( 'theme' ); |
|
634 } |
|
635 } |
|
636 } |
|
637 |
|
638 if ( ! function_exists ( 'bws_admin_head' ) ) { |
|
639 function bws_admin_head() { |
|
640 if ( isset( $_GET['page'] ) && $_GET['page'] == "bws_plugins" ) { ?> |
|
641 <noscript> |
|
642 <style type="text/css"> |
|
643 .bws_product_button { |
|
644 display: inline-block; |
|
645 } |
|
646 </style> |
|
647 </noscript> |
|
648 <?php } |
|
649 } |
|
650 } |
|
651 |
|
652 /** |
|
653 * Tooltip block |
|
654 */ |
|
655 if ( ! function_exists( 'bws_add_tooltip_in_admin' ) ) { |
|
656 function bws_add_tooltip_in_admin( $tooltip_args = array() ) { |
|
657 new BWS_admin_tooltip( $tooltip_args ); |
|
658 } |
|
659 } |
|
660 |
|
661 if ( ! class_exists( 'BWS_admin_tooltip' ) ) { |
|
662 class BWS_admin_tooltip { |
|
663 private $tooltip_args; |
|
664 |
|
665 public function __construct( $tooltip_args ) { |
|
666 global $wp_version; |
|
667 if ( 3.3 > $wp_version ) |
|
668 return; |
|
669 /* Default arguments */ |
|
670 $tooltip_args_default = array( |
|
671 'tooltip_id' => false, |
|
672 'css_selector' => false, |
|
673 'actions' => array( |
|
674 'click' => true, |
|
675 'onload' => false, |
|
676 ), |
|
677 'buttons' => array( |
|
678 'close' => array( |
|
679 'type' => 'dismiss', |
|
680 'text' => __( 'Close', 'bestwebsoft' ), |
|
681 ), |
|
682 ), |
|
683 'position' => array( |
|
684 'edge' => 'top', |
|
685 'align' => 'center', |
|
686 'pos-left' => 0, |
|
687 'pos-top' => 0, |
|
688 'zindex' => 10000 |
|
689 ), |
|
690 ); |
|
691 $tooltip_args = array_merge( $tooltip_args_default, $tooltip_args ); |
|
692 /* Check that our merged array has default values */ |
|
693 foreach ( $tooltip_args_default as $arg_key => $arg_value ) { |
|
694 if ( is_array( $arg_value ) ) { |
|
695 foreach ( $arg_value as $key => $value) { |
|
696 if ( ! isset( $tooltip_args[ $arg_key ][ $key ] ) ) { |
|
697 $tooltip_args[ $arg_key ][ $key ] = $tooltip_args_default[ $arg_key ][ $key ]; |
|
698 } |
|
699 } |
|
700 } |
|
701 } |
|
702 /* Check if tooltip is dismissed */ |
|
703 if ( true === $tooltip_args['actions']['onload'] ) { |
|
704 if ( in_array( $tooltip_args['tooltip_id'], array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) ) ) ) { |
|
705 $tooltip_args['actions']['onload'] = false; |
|
706 } |
|
707 } |
|
708 /* Check entered data */ |
|
709 if ( false === $tooltip_args['tooltip_id'] || false === $tooltip_args['css_selector'] || ( false === $tooltip_args['actions']['click'] && false === $tooltip_args['actions']['onload'] ) ) { |
|
710 /* if not enough data to output a tooltip or both actions (click, onload) are false */ |
|
711 return; |
|
712 } else { |
|
713 /* check position */ |
|
714 if ( ! in_array( $tooltip_args['position']['edge'], array( 'left', 'right', 'top', 'bottom' ) ) ) { |
|
715 $tooltip_args['position']['edge'] = 'top'; |
|
716 } |
|
717 if ( ! in_array( $tooltip_args['position']['align'], array( 'top', 'bottom', 'left', 'right', 'center', ) ) ) { |
|
718 $tooltip_args['position']['align'] = 'center'; |
|
719 } |
|
720 } |
|
721 /* fix position */ |
|
722 switch ( $tooltip_args['position']['edge'] ) { |
|
723 case 'left': |
|
724 case 'right': |
|
725 switch ( $tooltip_args['position']['align'] ) { |
|
726 case 'top': |
|
727 case 'bottom': |
|
728 $tooltip_args['position']['align'] = 'center'; |
|
729 break; |
|
730 } |
|
731 break; |
|
732 case 'top': |
|
733 case 'bottom': |
|
734 if ( $tooltip_args['position']['align'] == 'left' ) { |
|
735 $tooltip_args['position']['pos-left'] -= 65; |
|
736 } |
|
737 break; |
|
738 } |
|
739 $this->tooltip_args = $tooltip_args; |
|
740 /* add styles and scripts */ |
|
741 wp_enqueue_style( 'wp-pointer' ); |
|
742 wp_enqueue_script( 'wp-pointer' ); |
|
743 /* add script that displays our tooltip */ |
|
744 add_action( 'admin_print_footer_scripts', array( $this, 'add_scripts' ) ); |
|
745 } |
|
746 |
|
747 /** |
|
748 * Display tooltip |
|
749 */ |
|
750 public function add_scripts() { |
|
751 global $bstwbsftwppdtplgns_tooltip_script_add; |
|
752 if ( ! isset( $bstwbsftwppdtplgns_tooltip_script_add ) ) { |
|
753 echo '<script type="text/javascript" src="' . plugins_url( 'js/bws_tooltip.js', __FILE__ ) . '"></script>'; |
|
754 $bstwbsftwppdtplgns_tooltip_script_add = true; |
|
755 } |
|
756 $tooltip_args = $this->tooltip_args; ?> |
|
757 <script type="text/javascript"> |
|
758 (function($) { |
|
759 $(document).ready( function() { |
|
760 $.bwsTooltip( <?php echo json_encode( $tooltip_args ); ?> ); |
|
761 }) |
|
762 })(jQuery); |
|
763 </script> |
|
764 <?php } |
|
765 } |
|
766 } |
|
767 |
|
768 add_action( 'admin_init', 'bws_plugin_init' ); |
|
769 add_action( 'admin_enqueue_scripts', 'bws_admin_add_scripts' ); |
|
770 add_action( 'admin_head', 'bws_admin_head' ); |