/bws_menu/bws_functions.php

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