Bws_Settings_Tabs

The Google Captcha (reCAPTCHA) by BestWebSoft Bws Settings Tabs class.

Defined (1)

The class is defined in the following location(s).

/bws_menu/class-bws-settings.php  
  1. class Bws_Settings_Tabs { 
  2. private $tabs;  
  3. private $plugin_basename; 
  4. private $prefix; 
  5. private $pro_plugin_is_activated = false; 
  6. private $custom_code_args = array(); 
  7. private $wp_slug; 
  8.  
  9. public $options; 
  10. public $default_options; 
  11. public $is_network_options;  
  12. public $plugins_info = array(); 
  13. public $hide_pro_tabs = false; 
  14. public $demo_data; 
  15.  
  16. public $is_pro = false; 
  17. public $pro_page; 
  18. public $bws_license_plugin; 
  19. public $link_key; 
  20. public $link_pn; 
  21. public $is_trial = false; 
  22. public $trial_days; 
  23. public $bws_hide_pro_option_exist = true;  
  24.  
  25. public $forbid_view = false; 
  26. public $change_permission_attr = ''; 
  27.  
  28. public $version; 
  29. public $upload_dir; 
  30. public $all_plugins; 
  31. public $is_multisite; 
  32.  
  33. public $doc_link; 
  34. public $doc_video_link; 
  35.  
  36. /** 
  37. * Constructor. 
  38. * The child class should call this constructor from its own constructor to override 
  39. * the default $args. 
  40. * @access public 
  41. *  
  42. * @param array|string $args 
  43. */ 
  44. public function __construct( $args = array() ) { 
  45. $args = wp_parse_args( $args, array( 
  46. 'plugin_basename' => '',  
  47. 'prefix' => '',  
  48. 'plugins_info' => array(),  
  49. 'default_options' => array(),  
  50. 'options' => array(),  
  51. 'is_network_options' => false,  
  52. 'tabs' => array(),  
  53. 'doc_link' => '',  
  54. 'doc_video_link' => '',  
  55. 'wp_slug' => '',  
  56. 'demo_data' => false,  
  57. /** if this is free version and pro exist */ 
  58. 'pro_page' => '',  
  59. 'bws_license_plugin'=> '',  
  60. 'link_key' => '',  
  61. 'link_pn' => '',  
  62. 'trial_days' => false 
  63. ) ); 
  64.  
  65. $args['plugins_info']['Name'] = str_replace( ' by BestWebSoft', '', $args['plugins_info']['Name'] ); 
  66.  
  67. $this->plugin_basename = $args['plugin_basename']; 
  68. $this->prefix = $args['prefix']; 
  69. $this->plugins_info = $args['plugins_info'];  
  70. $this->options = $args['options']; 
  71. $this->default_options = $args['default_options']; 
  72. $this->wp_slug = $args['wp_slug']; 
  73. $this->demo_data = $args['demo_data']; 
  74.  
  75. $this->tabs = $args['tabs']; 
  76. $this->is_network_options = $args['is_network_options']; 
  77.  
  78. $this->doc_link = $args['doc_link']; 
  79. $this->doc_video_link = $args['doc_video_link']; 
  80.  
  81. $this->pro_page = $args['pro_page']; 
  82. $this->bws_license_plugin = $args['bws_license_plugin']; 
  83. $this->link_key = $args['link_key']; 
  84. $this->link_pn = $args['link_pn']; 
  85. $this->trial_days = $args['trial_days']; 
  86.  
  87. $this->hide_pro_tabs = bws_hide_premium_options_check( $this->options ); 
  88. $this->version = '1.0.0'; 
  89. $this->is_multisite = is_multisite(); 
  90.  
  91. if ( empty( $this->pro_page ) && array_key_exists( 'license', $this->tabs ) ) 
  92. $this->is_pro = true; 
  93.  
  94. /** 
  95. * Displays the content of the "Settings" on the plugin settings page 
  96. * @access public 
  97. * @param void 
  98. * @return void 
  99. */ 
  100. public function display_content() { 
  101. global $bstwbsftwppdtplgns_options; 
  102. if ( array_key_exists( 'custom_code', $this->tabs ) ) { 
  103. /** get args for `custom code` tab */ 
  104. $this->get_custom_code(); 
  105.  
  106. $save_results = $this->save_all_tabs_options(); 
  107.  
  108. $this->display_messages( $save_results ); 
  109. if ( isset( $_REQUEST['bws_restore_default'] ) && check_admin_referer( $this->plugin_basename, 'bws_nonce_name' ) ) { 
  110. bws_form_restore_default_confirm( $this->plugin_basename ); 
  111. } elseif ( isset( $_POST['bws_handle_demo'] ) && check_admin_referer( $this->plugin_basename, 'bws_nonce_name' ) ) { 
  112. $this->demo_data->bws_demo_confirm(); 
  113. } else { 
  114. bws_show_settings_notice(); ?> 
  115. <form class="bws_form" method="post" action="" enctype="multipart/form-data"> 
  116. <div id="poststuff"> 
  117. <div id="post-body" class="metabox-holder columns-2"> 
  118. <div id="post-body-content" style="position: relative;"> 
  119. <?php $this->display_tabs(); ?>  
  120. </div><!-- /post-body-content --> 
  121. <div id="postbox-container-1" class="postbox-container"> 
  122. <div class="meta-box-sortables ui-sortable"> 
  123. <div id="submitdiv" class="postbox"> 
  124. <h3 class="hndle"><?php _e( 'Information', 'bestwebsoft' ); ?></h3> 
  125. <div class="inside"> 
  126. <div class="submitbox" id="submitpost"> 
  127. <div id="minor-publishing"> 
  128. <div id="misc-publishing-actions"> 
  129. <?php if ( $this->is_pro ) { 
  130. if ( ! isset( $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] ) || isset( $bstwbsftwppdtplgns_options['wrong_license_key'][ $this->plugin_basename ] ) ) { 
  131. $license_type = 'Pro'; 
  132. $license_status = __( 'Inactive', 'bestwebsoft' ) . ' <a href="#' . $this->prefix . '_license_tab" class="bws_trigger_tab_click">' . __( 'Learn More', 'bestwebsoft' ) . '</a>'; 
  133. } else { 
  134. $finish = strtotime( $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] ); 
  135. $today = strtotime( date( "m/d/Y" ) ); 
  136. if ( isset( $bstwbsftwppdtplgns_options['trial'][ $this->plugin_basename ] ) ) {  
  137. $license_type = 'Trial Pro'; 
  138.  
  139. if ( $finish < $today ) { 
  140. $license_status = __( 'Expired', 'bestwebsoft' ); 
  141. } else { 
  142. $daysleft = floor( ( $finish - $today ) / ( 60*60*24 ) ); 
  143. $license_status = sprintf( __( '%s day(-s) left', 'bestwebsoft' ), $daysleft ); 
  144. $license_status .= '. <a target="_blank" href="' . $this->plugins_info['PluginURI'] . '">' . __( 'Upgrade to Pro', 'bestwebsoft' ) . '</a>';  
  145. } else { 
  146. $license_type = isset( $bstwbsftwppdtplgns_options['nonprofit'][ $this->plugin_basename ] ) ? 'Nonprofit Pro' : 'Pro'; 
  147. if ( $finish < $today ) { 
  148. $license_status = sprintf( __( 'Expired on %s', 'bestwebsoft' ), $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] ) . '. <a target="_blank" href="https://support.bestwebsoft.com/entries/53487136">' . __( 'Renew Now', 'bestwebsoft' ) . '</a>'; 
  149. } else { 
  150. $license_status = __( 'Active', 'bestwebsoft' ); 
  151. } ?> 
  152. <div class="misc-pub-section"> 
  153. <strong><?php _e( 'License', 'bestwebsoft' ); ?>:</strong> <?php echo $license_type; ?> 
  154. </div> 
  155. <div class="misc-pub-section"> 
  156. <strong><?php _e( 'Status', 'bestwebsoft' ); ?>:</strong> <?php echo $license_status; ?> 
  157. </div><!-- .misc-pub-section --> 
  158. <?php } ?> 
  159. <div class="misc-pub-section"> 
  160. <strong><?php _e( 'Version', 'bestwebsoft' ); ?>:</strong> <?php echo $this->plugins_info['Version']; ?> 
  161. </div><!-- .misc-pub-section --> 
  162. </div> 
  163. <div class="clear"></div> 
  164. </div> 
  165. <div id="major-publishing-actions"> 
  166. <div id="publishing-action"> 
  167. <input type="hidden" name="<?php echo $this->prefix; ?>_form_submit" value="submit" /> 
  168. <input id="bws-submit-button" type="submit" class="button button-primary button-large" value="<?php _e( 'Save Changes', 'bestwebsoft' ); ?>" /> 
  169. <?php wp_nonce_field( $this->plugin_basename, 'bws_nonce_name' ); ?>  
  170. </div> 
  171. <div class="clear"></div> 
  172. </div> 
  173. </div> 
  174. </div>  
  175. </div> 
  176. <?php /** 
  177. * action - Display custom metabox 
  178. */ 
  179. do_action( __CLASS__ . '_display_metabox' ); ?> 
  180. </div> 
  181. </div> 
  182. <div id="postbox-container-2" class="postbox-container"> 
  183. <?php /** 
  184. * action - Display additional content for #postbox-container-2 
  185. */ 
  186. do_action( __CLASS__ . '_display_second_postbox' ); ?> 
  187. <div class="submit"> 
  188. <input type="submit" class="button button-primary button-large" value="<?php _e( 'Save Changes', 'bestwebsoft' ); ?>" /> 
  189. </div>  
  190. <?php if ( ! empty( $this->wp_slug ) ) 
  191. bws_plugin_reviews_block( $this->plugins_info['Name'], $this->wp_slug ); ?> 
  192. </div> 
  193. </div> 
  194. </form> 
  195. </div> 
  196. <?php } 
  197.  
  198. /** 
  199. * Displays the Tabs 
  200. * @access public 
  201. * @param void 
  202. * @return void 
  203. */ 
  204. public function display_tabs() {  
  205. global $wp_version; ?> 
  206. <div id="bws_settings_tabs_wrapper"<?php if ( version_compare( $wp_version, '4.0', '<' ) ) echo ' class="edit-form-section"'; ?>> 
  207. <ul id="bws_settings_tabs"> 
  208. <?php $this->display_tabs_list(); ?> 
  209. </ul> 
  210. <?php $this->display_tabs_content(); ?> 
  211. <div class="clear"></div> 
  212. <input type="hidden" name="bws_active_tab" value="<?php if ( isset( $_REQUEST['bws_active_tab'] ) ) echo esc_attr( $_REQUEST['bws_active_tab'] ); ?>" /> 
  213. </div> 
  214. <?php } 
  215.  
  216. /** 
  217. * Displays the list of tabs 
  218. * @access private 
  219. * @return void 
  220. */ 
  221. private function display_tabs_list() { 
  222. foreach ( $this->tabs as $tab_slug => $data ) { 
  223. if ( ! empty( $data['is_pro'] ) && $this->hide_pro_tabs ) 
  224. continue; 
  225. $tab_class = 'bws-tab-' . $tab_slug; 
  226. if ( ! empty( $data['is_pro'] ) ) 
  227. $tab_class .= ' bws_pro_tab'; 
  228. if ( ! empty( $data['class'] ) ) 
  229. $tab_class .= ' ' . $data['class']; ?> 
  230. <li class="<?php echo $tab_class; ?>" data-slug="<?php echo $tab_slug; ?>"> 
  231. <a href="#<?php echo $this->prefix; ?>_<?php echo $tab_slug; ?>_tab"> 
  232. <span><?php echo esc_html( $data['label'] ); ?></span> 
  233. </a> 
  234. </li> 
  235. <?php } 
  236.  
  237. /** 
  238. * Displays the content of tabs 
  239. * @access private 
  240. * @param string $tab_slug 
  241. * @return void 
  242. */ 
  243. public function display_tabs_content() { 
  244. foreach ( $this->tabs as $tab_slug => $data ) {  
  245. if ( ! empty( $data['is_pro'] ) && $this->hide_pro_tabs ) 
  246. continue; ?> 
  247. <div class="bws_tab ui-tabs-panel ui-widget-content ui-corner-bottom" id="<?php echo $this->prefix . '_' . $tab_slug; ?>_tab" aria-labelledby="ui-id-2" role="tabpanel" aria-hidden="false" style="display: block;">  
  248. <?php if ( method_exists( $this, 'tab_' . str_replace( '-', '_', $tab_slug ) ) ) { 
  249. call_user_func( array( $this, 'tab_' . str_replace( '-', '_', $tab_slug ) ) ); 
  250. } ?> 
  251. </div> 
  252. <?php } 
  253.  
  254. /** 
  255. * Save all options from all tabs and display errors\messages 
  256. * @access public 
  257. * @param void 
  258. * @return void 
  259. */ 
  260. public function save_all_tabs_options() { 
  261. $message = $notice = $error = ''; 
  262. /** Restore default settings */ 
  263. if ( isset( $_POST['bws_restore_confirm'] ) && check_admin_referer( $this->plugin_basename, 'bws_settings_nonce_name' ) ) { 
  264. $this->restore_options(); 
  265. $message = __( 'All plugin settings were restored.', 'bestwebsoft' ); 
  266. /** Go Pro - check license key */ 
  267. } elseif ( isset( $_POST['bws_license_submit'] ) && check_admin_referer( $this->plugin_basename, 'bws_nonce_name' ) ) { 
  268. $result = $this->save_options_license_key(); 
  269. if ( ! empty( $result['error'] ) ) 
  270. $error = $result['error']; 
  271. if ( ! empty( $result['message'] ) ) 
  272. $message = $result['message']; 
  273. if ( ! empty( $result['notice'] ) ) 
  274. $notice = $result['notice']; 
  275. /** check demo data */ 
  276. } else { 
  277. $demo_result = ! empty( $this->demo_data ) ? $this->demo_data->bws_handle_demo_data() : false; 
  278. if ( false !== $demo_result ) { 
  279. if ( ! empty( $demo_result ) && is_array( $demo_result ) ) { 
  280. $error = $demo_result['error']; 
  281. $message = $demo_result['done']; 
  282. if ( ! empty( $demo_result['done'] ) && ! empty( $demo_result['options'] ) ) 
  283. $this->options = $demo_result['options']; 
  284. /** Save options */ 
  285. } elseif ( ! isset( $_REQUEST['bws_restore_default'] ) && ! isset( $_POST['bws_handle_demo'] ) && isset( $_REQUEST[ $this->prefix . '_form_submit'] ) && check_admin_referer( $this->plugin_basename, 'bws_nonce_name' ) ) { 
  286. /** save tabs */  
  287. $result = $this->save_options(); 
  288. if ( ! empty( $result['error'] ) ) 
  289. $error = $result['error']; 
  290. if ( ! empty( $result['message'] ) ) 
  291. $message = $result['message']; 
  292. if ( ! empty( $result['notice'] ) ) 
  293. $notice = $result['notice']; 
  294.  
  295. if ( '' == $this->change_permission_attr ) { 
  296. /** save `misc` tab */ 
  297. $result = $this->save_options_misc(); 
  298. if ( ! empty( $result['notice'] ) ) 
  299. $notice .= $result['notice']; 
  300.  
  301. if ( array_key_exists( 'custom_code', $this->tabs ) ) { 
  302. /** save `custom code` tab */ 
  303. $this->save_options_custom_code(); 
  304.  
  305. return compact( 'message', 'notice', 'error' ); 
  306.  
  307. /** 
  308. * Display error\message\notice 
  309. * @access public 
  310. * @param $save_results - array with error\message\notice 
  311. * @return void 
  312. */ 
  313. public function display_messages( $save_results ) { 
  314. /** 
  315. * action - Display custom error\message\notice 
  316. */ 
  317. do_action( __CLASS__ . '_display_custom_messages', $save_results ); ?> 
  318. <div class="updated fade inline" <?php if ( empty( $save_results['message'] ) ) echo "style=\"display:none\""; ?>><p><strong><?php echo $save_results['message']; ?></strong></p></div> 
  319. <div class="updated bws-notice inline" <?php if ( empty( $save_results['notice'] ) ) echo "style=\"display:none\""; ?>><p><strong><?php echo $save_results['notice']; ?></strong></p></div> 
  320. <div class="error inline" <?php if ( empty( $save_results['error'] ) ) echo "style=\"display:none\""; ?>><p><strong><?php echo $save_results['error']; ?></strong></p></div> 
  321. <?php } 
  322.  
  323. /** 
  324. * Save plugin options to the database 
  325. * @access public 
  326. * @param ab 
  327. * @return array The action results 
  328. * @abstract 
  329. */ 
  330. public function save_options() { 
  331. die( 'function Bws_Settings_Tabs::save_options() must be over-ridden in a sub-class.' ); 
  332.  
  333. /** 
  334. * Get 'custom_code' status and content 
  335. * @access private 
  336. */ 
  337. private function get_custom_code() { 
  338. global $bstwbsftwppdtplgns_options; 
  339.  
  340. $this->custom_code_args = array( 
  341. 'is_css_active' => false,  
  342. 'content_css' => '',  
  343. 'css_writeable' => false,  
  344. 'is_php_active' => false,  
  345. 'content_php' => '',  
  346. 'php_writeable' => false,  
  347. 'is_js_active' => false,  
  348. 'content_js' => '',  
  349. 'js_writeable' => false,  
  350. ); 
  351.  
  352. if ( ! $this->upload_dir ) 
  353. $this->upload_dir = wp_upload_dir(); 
  354.  
  355. $folder = $this->upload_dir['basedir'] . '/bws-custom-code'; 
  356. if ( ! $this->upload_dir["error"] ) { 
  357. if ( ! is_dir( $folder ) ) 
  358. wp_mkdir_p( $folder, 0755 ); 
  359.  
  360. $index_file = $this->upload_dir['basedir'] . '/bws-custom-code/index.php'; 
  361. if ( ! file_exists( $index_file ) ) { 
  362. if ( $f = fopen( $index_file, 'w+' ) ) 
  363. fclose( $f ); 
  364.  
  365. if ( $this->is_multisite ) 
  366. $this->custom_code_args['blog_id'] = get_current_blog_id(); 
  367.  
  368. foreach ( array( 'css', 'php', 'js' ) as $extension ) { 
  369. $file = 'bws-custom-code.' . $extension; 
  370. $real_file = $folder . '/' . $file; 
  371.  
  372. if ( file_exists( $real_file ) ) { 
  373. update_recently_edited( $real_file ); 
  374. $this->custom_code_args["content_{$extension}"] = esc_textarea( file_get_contents( $real_file ) ); 
  375. if ( ( $this->is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $this->custom_code_args['blog_id'] ][ $file ] ) ) || 
  376. ( ! $this->is_multisite && isset( $bstwbsftwppdtplgns_options['custom_code'][ $file ] ) ) ) { 
  377. $this->custom_code_args["is_{$extension}_active"] = true; 
  378. if ( is_writeable( $real_file ) ) 
  379. $this->custom_code_args["{$extension}_writeable"] = true; 
  380. } else { 
  381. $this->custom_code_args["{$extension}_writeable"] = true; 
  382. if ( 'php' == $extension ) 
  383. $this->custom_code_args["content_{$extension}"] = "<?php" . "\n" . "if ( ! defined( 'ABSPATH' ) ) exit;" . "\n" . "if ( ! defined( 'BWS_GLOBAL' ) ) exit;" . "\n\n" . "/* Start your code here */" . "\n"; 
  384.  
  385. /** 
  386. * Display 'custom_code' tab 
  387. * @access private 
  388. */ 
  389. private function tab_custom_code() { ?> 
  390. <h3 class="bws_tab_label"><?php _e( 'Custom Code', 'bestwebsoft' ); ?></h3> 
  391. <?php $this->help_phrase(); ?> 
  392. <hr> 
  393. <?php if ( ! current_user_can( 'edit_plugins' ) ) { 
  394. echo '<p>' . __( 'You do not have sufficient permissions to edit plugins for this site.', 'bestwebsoft' ) . '</p>'; 
  395. return; 
  396.  
  397. $list = array(  
  398. 'css' => array( 'description' => __( 'These styles will be added to the header on all pages of your site.', 'bestwebsoft' ),  
  399. 'learn_more_link' => 'https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started'  
  400. ),  
  401. 'php' => array( 'description' => sprintf( __( '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>' ),  
  402. 'learn_more_link' => 'http://php.net/'  
  403. ),  
  404. 'js' => array( 'description' => __( 'These code will be added to the header on all pages of your site.', 'bestwebsoft' ),  
  405. 'learn_more_link' => 'https://developer.mozilla.org/en-US/docs/Web/JavaScript'  
  406. ),  
  407. ); 
  408.  
  409. if ( ! $this->custom_code_args['css_writeable'] || 
  410. ! $this->custom_code_args['php_writeable'] || 
  411. ! $this->custom_code_args['js_writeable'] ) { ?> 
  412. <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' ),  
  413. '<a href="https://codex.wordpress.org/Changing_File_Permissions" target="_blank">',  
  414. '</a>' ); ?></em></p> 
  415. <?php } 
  416.  
  417. foreach ( $list as $extension => $extension_data ) { 
  418. $name = 'js' == $extension ? 'JavaScript' : strtoupper( $extension ); ?> 
  419. <p><big> 
  420. <strong><?php echo $name; ?></strong> 
  421. <?php if ( ! $this->custom_code_args["{$extension}_writeable"] ) 
  422. echo '(' . __( 'Browsing', 'bestwebsoft' ) . ')'; ?> 
  423. </big></p> 
  424. <p class="bws_info"> 
  425. <input type="checkbox" name="bws_custom_<?php echo $extension; ?>_active" value="1" <?php if ( $this->custom_code_args["is_{$extension}_active"] ) echo "checked"; ?> />  
  426. <?php printf( __( 'Activate custom %s code.', 'bestwebsoft' ), $name ); ?> 
  427. </p> 
  428. <textarea cols="70" rows="25" name="bws_newcontent_<?php echo $extension; ?>" id="bws_newcontent_<?php echo $extension; ?>"><?php if ( isset( $this->custom_code_args["content_{$extension}"] ) ) echo $this->custom_code_args["content_{$extension}"]; ?></textarea> 
  429. <p class="bws_info"> 
  430. <?php echo $extension_data['description']; ?> 
  431. <br> 
  432. <a href="<?php echo $extension_data['learn_more_link']; ?>" target="_blank"> 
  433. <?php printf( __( 'Learn more about %s', 'bestwebsoft' ), $name ); ?> 
  434. </a> 
  435. </p> 
  436. <?php } 
  437.  
  438. /** 
  439. * Save plugin options to the database 
  440. * @access private 
  441. * @return array The action results 
  442. */ 
  443. private function save_options_custom_code() { 
  444. global $bstwbsftwppdtplgns_options; 
  445. $folder = $this->upload_dir['basedir'] . '/bws-custom-code'; 
  446.  
  447. foreach ( array( 'css', 'php', 'js' ) as $extension ) {  
  448. $file = 'bws-custom-code.' . $extension; 
  449. $real_file = $folder . '/' . $file; 
  450.  
  451. if ( isset( $_POST["bws_newcontent_{$extension}"] ) && 
  452. $this->custom_code_args["{$extension}_writeable"] ) { 
  453. $newcontent = trim( wp_unslash( $_POST["bws_newcontent_{$extension}"] ) ); 
  454.  
  455. if ( ! empty( $newcontent ) && isset( $_POST["bws_custom_{$extension}_active"] ) ) { 
  456. $this->custom_code_args["is_{$extension}_active"] = true; 
  457. if ( $this->is_multisite ) { 
  458. $bstwbsftwppdtplgns_options['custom_code'][ $this->custom_code_args['blog_id'] ][ $file ] = ( 'php' == $extension ) ? $real_file : $this->upload_dir['baseurl'] . '/bws-custom-code/' . $file; 
  459. } else { 
  460. $bstwbsftwppdtplgns_options['custom_code'][ $file ] = ( 'php' == $extension ) ? $real_file : $this->upload_dir['baseurl'] . '/bws-custom-code/' . $file; 
  461. } else { 
  462. $this->custom_code_args["is_{$extension}_active"] = false; 
  463. if ( $this->is_multisite ) { 
  464. if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $this->custom_code_args['blog_id'] ][ $file ] ) ) 
  465. unset( $bstwbsftwppdtplgns_options['custom_code'][ $this->custom_code_args['blog_id'] ][ $file ] ); 
  466. } else { 
  467. if ( isset( $bstwbsftwppdtplgns_options['custom_code'][ $file ] ) ) 
  468. unset( $bstwbsftwppdtplgns_options['custom_code'][ $file ] ); 
  469. if ( $f = fopen( $real_file, 'w+' ) ) { 
  470. fwrite( $f, $newcontent ); 
  471. fclose( $f ); 
  472. $this->custom_code_args["content_{$extension}"] = $newcontent; 
  473.  
  474. if ( $this->is_multisite ) 
  475. update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); 
  476. else 
  477. update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); 
  478.  
  479. /** 
  480. * Display 'misc' tab 
  481. * @access private 
  482. */ 
  483. private function tab_misc() {  
  484. global $bstwbsftwppdtplgns_options; ?> 
  485. <h3 class="bws_tab_label"><?php _e( 'Miscellaneous Settings', 'bestwebsoft' ); ?></h3> 
  486. <?php $this->help_phrase(); ?> 
  487. <hr> 
  488. <?php /** 
  489. * action - Display custom options on the Import / Export' tab 
  490. */ 
  491. do_action( __CLASS__ . '_additional_misc_options' ); 
  492.  
  493. if ( ! $this->forbid_view && ! empty( $this->change_permission_attr ) ) { ?> 
  494. <div class="error inline bws_visible"><p><strong><?php _e( "Notice", 'bestwebsoft' ); ?>:</strong> <strong><?php printf( __( "It is prohibited to change %s settings on this site in the %s network settings.", 'bestwebsoft' ), $this->plugins_info["Name"], $this->plugins_info["Name"] ); ?></strong></p></div> 
  495. <?php } 
  496. if ( $this->forbid_view ) { ?> 
  497. <div class="error inline bws_visible"><p><strong><?php _e( "Notice", 'bestwebsoft' ); ?>:</strong> <strong><?php printf( __( "It is prohibited to view %s settings on this site in the %s network settings.", 'bestwebsoft' ), $this->plugins_info["Name"], $this->plugins_info["Name"] ); ?></strong></p></div> 
  498. <?php } else { ?> 
  499. <table class="form-table">  
  500. <?php /** 
  501. * action - Display custom options on the 'misc' tab 
  502. */ 
  503. do_action( __CLASS__ . '_additional_misc_options_affected' ); 
  504. if ( ! empty( $this->pro_page ) && $this->bws_hide_pro_option_exist ) { ?> 
  505. <tr> 
  506. <th scope="row"><?php _e( 'Pro Options', 'bestwebsoft' ); ?></th> 
  507. <td> 
  508. <input <?php echo $this->change_permission_attr; ?> name="bws_hide_premium_options_submit" type="checkbox" value="1" <?php if ( ! $this->hide_pro_tabs ) echo 'checked="checked "'; ?> />  
  509. <span class="bws_info"><?php _e( 'Enable to display plugin Pro options.', 'bestwebsoft' ); ?></span> 
  510. </td> 
  511. </tr> 
  512. <?php } ?> 
  513. <tr> 
  514. <th scope="row"><?php _e( 'Track Usage', 'bestwebsoft' ); ?></th> 
  515. <td> 
  516. <input <?php echo $this->change_permission_attr; ?> name="bws_track_usage" type="checkbox" value="1" <?php if ( ! empty( $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] ) ) echo 'checked="checked "'; ?>/>  
  517. <span class="bws_info"><?php _e( 'Enable to allow tracking plugin usage anonymously in order to make it better.', 'bestwebsoft' ); ?></span> 
  518. </td> 
  519. </tr> 
  520. <tr> 
  521. <th scope="row"><?php _e( 'Default Settings', 'bestwebsoft' ); ?></th> 
  522. <td> 
  523. <input<?php echo $this->change_permission_attr; ?> name="bws_restore_default" type="submit" class="button" value="<?php _e( 'Restore Settings', 'bestwebsoft' ); ?>" /> 
  524. <div class="bws_info"><?php _e( 'This will restore plugin settings to defaults.', 'bestwebsoft' ); ?></div> 
  525. </td> 
  526. </tr> 
  527. </table> 
  528. <?php } 
  529.  
  530. /** 
  531. * Display 'Import / Export' tab 
  532. * @access private 
  533. */ 
  534. public function tab_import_export() { ?> 
  535. <h3 class="bws_tab_label"><?php _e( 'Import / Export', 'bestwebsoft' ); ?></h3> 
  536. <?php $this->help_phrase(); ?> 
  537. <hr>  
  538. <?php /** 
  539. * action - Display custom options on the Import / Export' tab 
  540. */ 
  541. do_action( __CLASS__ . '_additional_import_export_options' ); 
  542.  
  543. if ( ! $this->forbid_view && ! empty( $this->change_permission_attr ) ) { ?> 
  544. <div class="error inline bws_visible"><p><strong><?php _e( "Notice", 'bestwebsoft' ); ?>:</strong> <strong><?php printf( __( "It is prohibited to change %s settings on this site in the %s network settings.", 'bestwebsoft' ), $this->plugins_info["Name"], $this->plugins_info["Name"] ); ?></strong></p></div> 
  545. <?php } 
  546. if ( $this->forbid_view ) { ?> 
  547. <div class="error inline bws_visible"><p><strong><?php _e( "Notice", 'bestwebsoft' ); ?>:</strong> <strong><?php printf( __( "It is prohibited to view %s settings on this site in the %s network settings.", 'bestwebsoft' ), $this->plugins_info["Name"], $this->plugins_info["Name"] ); ?></strong></p></div> 
  548. <?php } else { ?> 
  549. <table class="form-table">  
  550. <?php /** 
  551. * action - Display custom options on the Import / Export' tab 
  552. */ 
  553. do_action( __CLASS__ . '_additional_import_export_options_affected' ); ?> 
  554. </table> 
  555. <?php } 
  556.  
  557. /** 
  558. * Save plugin options to the database 
  559. * @access private 
  560. */ 
  561. private function save_options_misc() { 
  562. global $bstwbsftwppdtplgns_options, $wp_version; 
  563. /** hide premium options */ 
  564. if ( ! empty( $this->pro_page ) ) { 
  565. if ( isset( $_POST['bws_hide_premium_options'] ) ) { 
  566. $hide_result = bws_hide_premium_options( $this->options ); 
  567. $this->hide_pro_tabs = true; 
  568. $this->options = $hide_result['options']; 
  569. if ( ! empty( $hide_result['message'] ) ) 
  570. $notice = $hide_result['message']; 
  571. if ( $this->is_network_options ) 
  572. update_site_option( $this->prefix . '_options', $this->options ); 
  573. else 
  574. update_option( $this->prefix . '_options', $this->options ); 
  575. } else if ( isset( $_POST['bws_hide_premium_options_submit'] ) ) { 
  576. if ( ! empty( $this->options['hide_premium_options'] ) ) { 
  577. $key = array_search( get_current_user_id(), $this->options['hide_premium_options'] ); 
  578. if ( false !== $key ) 
  579. unset( $this->options['hide_premium_options'][ $key ] ); 
  580. if ( $this->is_network_options ) 
  581. update_site_option( $this->prefix . '_options', $this->options ); 
  582. else 
  583. update_option( $this->prefix . '_options', $this->options ); 
  584. $this->hide_pro_tabs = false;  
  585. } else { 
  586. if ( empty( $this->options['hide_premium_options'] ) ) { 
  587. $this->options['hide_premium_options'][] = get_current_user_id(); 
  588. if ( $this->is_network_options ) 
  589. update_site_option( $this->prefix . '_options', $this->options ); 
  590. else 
  591. update_option( $this->prefix . '_options', $this->options ); 
  592. $this->hide_pro_tabs = true; 
  593. /** Save 'Track Usage' option */ 
  594. if ( isset( $_POST['bws_track_usage'] ) ) { 
  595. if ( empty( $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] ) ) { 
  596. $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] = true; 
  597. $track_usage = true; 
  598. } else { 
  599. if ( ! empty( $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] ) ) { 
  600. unset( $bstwbsftwppdtplgns_options['track_usage']['products'][ $this->plugin_basename ] ); false; 
  601. $track_usage = false; 
  602. if ( isset( $track_usage ) ) { 
  603. $usage_id = ! empty( $bstwbsftwppdtplgns_options['track_usage']['usage_id'] ) ? $bstwbsftwppdtplgns_options['track_usage']['usage_id'] : false; 
  604. /** send data */ 
  605. $options = array( 
  606. 'timeout' => 3,  
  607. 'body' => array( 
  608. 'url' => get_bloginfo( 'url' ),  
  609. 'wp_version' => $wp_version,  
  610. 'is_active' => $track_usage,  
  611. 'product' => $this->plugin_basename,  
  612. 'version' => $this->plugins_info['Version'],  
  613. 'usage_id' => $usage_id,  
  614. ),  
  615. 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 
  616. ); 
  617. $raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/products-statistics/track-usage/', $options ); 
  618.  
  619. if ( ! is_wp_error( $raw_response ) && 200 == wp_remote_retrieve_response_code( $raw_response ) ) { 
  620. $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); 
  621.  
  622. if ( is_array( $response ) && 
  623. ! empty( $response['usage_id'] ) && 
  624. $response['usage_id'] != $usage_id ) { 
  625. $bstwbsftwppdtplgns_options['track_usage']['usage_id'] = $response['usage_id']; 
  626.  
  627. if ( $this->is_multisite ) 
  628. update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); 
  629. else 
  630. update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); 
  631.  
  632. return compact( 'notice' ); 
  633. }  
  634.  
  635. /** 
  636. */ 
  637. public function tab_license() { 
  638. global $wp_version, $bstwbsftwppdtplgns_options; ?> 
  639. <h3 class="bws_tab_label"><?php _e( 'License Key', 'bestwebsoft' ); ?></h3> 
  640. <?php $this->help_phrase(); ?> 
  641. <hr> 
  642. <?php if ( ! empty( $this->pro_page ) ) { 
  643. $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : ""; 
  644.  
  645. if ( $this->pro_plugin_is_activated ) {  
  646. deactivate_plugins( $this->plugin_basename ); ?> 
  647. <script type="text/javascript"> 
  648. (function($) { 
  649. var i = 7; 
  650. function bws_set_timeout() { 
  651. i--; 
  652. if ( 0 == i ) { 
  653. window.location.href = '<?php echo $this->pro_page; ?>'; 
  654. } else { 
  655. $( '#bws_timeout_counter' ).text( i ); 
  656. window.setTimeout( bws_set_timeout, 1000 ); 
  657. window.setTimeout( bws_set_timeout, 1000 ); 
  658. })(jQuery); 
  659. </script> 
  660. <p><strong><?php _e( 'Congratulations! Pro license is activated successfully.', 'bestwebsoft' ); ?></strong></p> 
  661. <p><?php printf( __( 'You will be automatically redirected to the %s in %s seconds.', 'bestwebsoft' ), '<a href="' . $this->pro_page . '">' . __( 'Settings page', 'bestwebsoft' ) . '</a>', '<span id="bws_timeout_counter">7</span>' ); ?></p> 
  662. <?php } else {  
  663. $attr = ''; 
  664. if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $this->bws_license_plugin ]['count'] ) && 
  665. '5' < $bstwbsftwppdtplgns_options['go_pro'][ $this->bws_license_plugin ]['count'] && 
  666. $bstwbsftwppdtplgns_options['go_pro'][ $this->bws_license_plugin ]['time'] > ( time() - ( 24 * 60 * 60 ) ) ) 
  667. $attr = 'disabled="disabled"'; ?>  
  668. <table class="form-table">  
  669. <tr> 
  670. <th scope="row"><?php _e( 'License Key', 'bestwebsoft' ); ?></th> 
  671. <td> 
  672. <input <?php echo $attr; ?> type="text" name="bws_license_key" value="<?php echo $bws_license_key; ?>" /> 
  673. <input <?php echo $attr; ?> type="hidden" name="bws_license_plugin" value="<?php echo $this->bws_license_plugin; ?>" /> 
  674. <input <?php echo $attr; ?> type="submit" class="button button-secondary" name="bws_license_submit" value="<?php _e( 'Activate', 'bestwebsoft' ); ?>" /> 
  675. <div class="bws_info"> 
  676. <?php printf( __( 'Enter your license key to activate %s and get premium plugin features.', 'bestwebsoft' ), '<a href="' . $this->plugins_info['PluginURI'] . '?k=' . $this->link_key . '&pn=' . $this->link_pn . '&v=' . $this->plugins_info["Version"] . '&wp_v=' . $wp_version . '" target="_blank" title="' . $this->plugins_info["Name"] . ' Pro">' . $this->plugins_info["Name"] . ' Pro</a>' ); ?> 
  677. </div> 
  678. <?php if ( '' != $attr ) { ?> 
  679. <p><?php _e( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' ); ?></p> 
  680. <?php } 
  681. if ( $this->trial_days !== false ) 
  682. echo '<p>' . __( 'or', 'bestwebsoft' ) . ' <a href="' . $this->plugins_info['PluginURI'] . 'trial/?k=' . $this->link_key . '&pn=' . $this->link_pn . '&v=' . $this->plugins_info["Version"] . '&wp_v=' . $wp_version . '" target="_blank">' . sprintf( __( 'Start Your Free %s-Day Trial Now', 'bestwebsoft' ), $this->trial_days ) . '</a></p>'; ?> 
  683. </td> 
  684. </tr> 
  685. </table> 
  686. <?php } 
  687. } else { 
  688. global $bstwbsftwppdtplgns_options; 
  689. $license_key = ( isset( $bstwbsftwppdtplgns_options[ $this->plugin_basename ] ) ) ? $bstwbsftwppdtplgns_options[ $this->plugin_basename ] : ''; ?> 
  690. <table class="form-table">  
  691. <tr> 
  692. <th scope="row"><?php _e( 'License Key', 'bestwebsoft' ); ?></th> 
  693. <td> 
  694. <input type="text" maxlength="100" name="bws_license_key" value="<?php echo $license_key; ?>" /> 
  695. <input type="submit" class="button button-secondary" name="bws_license_submit" value="<?php _e( 'Check license key', 'bestwebsoft' ); ?>" /> 
  696. <div class="bws_info"> 
  697. <?php _e( 'If necessary, you can check if the license key is correct or reenter it in the field below.', 'bestwebsoft' ); ?> 
  698. </div> 
  699. </td> 
  700. </tr> 
  701. <tr> 
  702. <th scope="row"><?php _e( 'Manage License Settings', 'bestwebsoft' ); ?></th> 
  703. <td> 
  704. <a class="button button-secondary" href="https://bestwebsoft.com/client-area" target="_blank"><?php _e( 'Login to Client Area', 'bestwebsoft' ); ?></a> 
  705. <div class="bws_info"> 
  706. <?php _e( 'Manage active licenses, download BWS products, and view your payment history using BestWebSoft Client Area.', 'bestwebsoft' ); ?> 
  707. </div> 
  708. </td> 
  709. </tr> 
  710. </table> 
  711. <?php } 
  712.  
  713. /** 
  714. * Save plugin options to the database 
  715. * @access private 
  716. * @param ab 
  717. * @return array The action results 
  718. */ 
  719. private function save_options_license_key() { 
  720. global $wp_version, $bstwbsftwppdtplgns_options; 
  721.  
  722. $bws_license_key = ( isset( $_POST['bws_license_key'] ) ) ? stripslashes( esc_html( trim( $_POST['bws_license_key'] ) ) ) : ''; 
  723.  
  724. if ( '' != $bws_license_key ) { 
  725. if ( strlen( $bws_license_key ) != 18 ) { 
  726. $error = __( 'Wrong license key', 'bestwebsoft' ); 
  727. } else { 
  728.  
  729. /** CHECK license key */ 
  730. if ( $this->is_pro ) { 
  731. delete_transient( 'bws_plugins_update' ); 
  732. if ( ! $this->all_plugins ) { 
  733. if ( ! function_exists( 'get_plugins' ) ) 
  734. require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 
  735. $this->all_plugins = get_plugins(); 
  736. $current = get_site_transient( 'update_plugins' ); 
  737.  
  738. if ( ! empty( $this->all_plugins ) && isset( $current ) && is_array( $current->response ) ) { 
  739. $to_send = array(); 
  740. $to_send["plugins"][ $this->plugin_basename ] = $this->all_plugins[ $this->plugin_basename ]; 
  741. $to_send["plugins"][ $this->plugin_basename ]["bws_license_key"] = $bws_license_key; 
  742. $to_send["plugins"][ $this->plugin_basename ]["bws_illegal_client"] = true; 
  743. $options = array( 
  744. 'timeout' => ( ( defined('DOING_CRON') && DOING_CRON ) ? 30 : 3 ),  
  745. 'body' => array( 'plugins' => serialize( $to_send ) ),  
  746. 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) 
  747. ); 
  748. $raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options ); 
  749.  
  750. if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) { 
  751. $error = __( 'Something went wrong. Please try again later. If the error appears again, please contact us', 'bestwebsoft' ) . ': <a href=https://support.bestwebsoft.com>BestWebSoft</a>. ' . __( 'We are sorry for inconvenience.', 'bestwebsoft' ); 
  752. } else { 
  753. $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); 
  754. if ( is_array( $response ) && !empty( $response ) ) { 
  755. foreach ( $response as $single_response ) { 
  756. if ( "wrong_license_key" == $single_response->package ) { 
  757. $error = __( 'Wrong license key.', 'bestwebsoft' ); 
  758. } else if ( "wrong_domain" == $single_response->package ) { 
  759. $error = __( 'This license key is bound to another site.', 'bestwebsoft' ); 
  760. } else if ( "time_out" == $single_response->package ) { 
  761. $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' ); 
  762. } elseif ( "you_are_banned" == $single_response->package ) { 
  763. $error = __( "Unfortunately, you have exceeded the number of available tries.", 'bestwebsoft' ); 
  764. } elseif ( "duplicate_domen_for_trial" == $single_response->package ) { 
  765. $error = __( "Unfortunately, the Pro Trial licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' ); 
  766. }  
  767. if ( empty( $error ) ) { 
  768. if ( empty( $message ) ) { 
  769. if ( isset( $single_response->trial ) ) 
  770. $message = __( 'The Pro Trial license key is valid.', 'bestwebsoft' ); 
  771. else 
  772. $message = __( 'The license key is valid.', 'bestwebsoft' ); 
  773.  
  774. if ( ! empty( $single_response->time_out ) ) 
  775. $message .= ' ' . __( 'Your license will expire on', 'bestwebsoft' ) . ' ' . $single_response->time_out . '.'; 
  776.  
  777. if ( isset( $single_response->trial ) && $this->is_trial ) 
  778. $message .= ' ' . sprintf( __( 'In order to continue using the plugin it is necessary to buy a %s license.', 'bestwebsoft' ), '<a href="' . $this->plugins_info['PluginURI'] . '?k=' . $this->link_key . '&pn=' . $this->link_pn . '&v=' . $this->plugins_info["Version"] . '&wp_v=' . $wp_version . '" target="_blank" title="' . $this->plugins_info["Name"] . '">Pro</a>' ); 
  779.  
  780. if ( isset( $single_response->trial ) ) { 
  781. $bstwbsftwppdtplgns_options['trial'][ $this->plugin_basename ] = 1; 
  782. } else { 
  783. unset( $bstwbsftwppdtplgns_options['trial'][ $this->plugin_basename ] ); 
  784.  
  785. if ( isset( $single_response->nonprofit ) ) { 
  786. $bstwbsftwppdtplgns_options['nonprofit'][ $this->plugin_basename ] = 1; 
  787. } else { 
  788. unset( $bstwbsftwppdtplgns_options['nonprofit'][ $this->plugin_basename ] ); 
  789.  
  790. if ( ! isset( $bstwbsftwppdtplgns_options[ $this->plugin_basename ] ) || $bstwbsftwppdtplgns_options[ $this->plugin_basename ] != $bws_license_key ) { 
  791. $bstwbsftwppdtplgns_options[ $this->plugin_basename ] = $bws_license_key; 
  792.  
  793. $file = @fopen( dirname( dirname( __FILE__ ) ) . "/license_key.txt" , "w+" ); 
  794. if ( $file ) { 
  795. @fwrite( $file, $bws_license_key ); 
  796. @fclose( $file ); 
  797. $update_option = true; 
  798.  
  799. if ( ! isset( $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] ) || $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] != $single_response->time_out ) { 
  800. $bstwbsftwppdtplgns_options['time_out'][ $this->plugin_basename ] = $single_response->time_out; 
  801. $update_option = true; 
  802.  
  803. if ( isset( $update_option ) ) { 
  804. if ( $this->is_multisite ) 
  805. update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); 
  806. else 
  807. update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); 
  808. } else { 
  809. $error = __( 'Something went wrong. Please try again later. If the error appears again, please contact us', 'bestwebsoft' ) . ' <a href=https://support.bestwebsoft.com>BestWebSoft</a>. ' . __( 'We are sorry for inconvenience.', 'bestwebsoft' ); 
  810. /** Go Pro */ 
  811. } else { 
  812.  
  813. $bws_license_plugin = stripslashes( esc_html( $_POST['bws_license_plugin'] ) ); 
  814. if ( isset( $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] ) && $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] > ( time() - (24 * 60 * 60) ) ) { 
  815. $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] + 1; 
  816. } else { 
  817. $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['count'] = 1; 
  818. $bstwbsftwppdtplgns_options['go_pro'][ $bws_license_plugin ]['time'] = time(); 
  819.  
  820. /** download Pro */ 
  821. if ( ! $this->all_plugins ) { 
  822. if ( ! function_exists( 'get_plugins' ) ) 
  823. require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); 
  824. $this->all_plugins = get_plugins(); 
  825.  
  826. if ( ! array_key_exists( $bws_license_plugin, $this->all_plugins ) ) { 
  827. $current = get_site_transient( 'update_plugins' ); 
  828. if ( ! empty( $current ) && is_array( $current->response ) ) { 
  829. $to_send = array(); 
  830. $to_send["plugins"][ $bws_license_plugin ] = array(); 
  831. $to_send["plugins"][ $bws_license_plugin ]["bws_license_key"] = $bws_license_key; 
  832. $to_send["plugins"][ $bws_license_plugin ]["bws_illegal_client"] = true; 
  833. $options = array( 
  834. 'timeout' => ( ( defined( 'DOING_CRON' ) && DOING_CRON ) ? 30 : 3 ),  
  835. 'body' => array( 'plugins' => serialize( $to_send ) ),  
  836. 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ); 
  837. $raw_response = wp_remote_post( 'http://bestwebsoft.com/wp-content/plugins/paid-products/plugins/update-check/1.0/', $options ); 
  838.  
  839. if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) ) { 
  840. $error = __( "Something went wrong. Please try again later. If the error appears again, please contact us", 'bestwebsoft' ) . ': <a href="https://support.bestwebsoft.com">BestWebSoft</a>. ' . __( "We are sorry for inconvenience.", 'bestwebsoft' ); 
  841. } else { 
  842. $response = maybe_unserialize( wp_remote_retrieve_body( $raw_response ) ); 
  843. if ( is_array( $response ) && ! empty( $response ) ) { 
  844. foreach ( $response as $single_response ) { 
  845. if ( "wrong_license_key" == $single_response->package ) { 
  846. $error = __( "Wrong license key.", 'bestwebsoft' ); 
  847. } elseif ( "wrong_domain" == $single_response->package ) { 
  848. $error = __( "This license key is bound to another site.", 'bestwebsoft' ); 
  849. } elseif ( "you_are_banned" == $single_response->package ) { 
  850. $error = __( "Unfortunately, you have exceeded the number of available tries per day. Please, upload the plugin manually.", 'bestwebsoft' ); 
  851. } elseif ( "time_out" == $single_response->package ) { 
  852. $error = sprintf( __( "Unfortunately, Your license has expired. To continue getting top-priority support and plugin updates, you should extend it in your %s", 'bestwebsoft' ), ' <a href="https://bestwebsoft.com/client-area">Client Area</a>' ); 
  853. } elseif ( "duplicate_domen_for_trial" == $single_response->package ) { 
  854. $error = __( "Unfortunately, the Pro licence was already installed to this domain. The Pro Trial license can be installed only once.", 'bestwebsoft' ); 
  855. if ( empty( $error ) ) { 
  856. $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key; 
  857.  
  858. $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'; 
  859.  
  860. if ( ! $this->upload_dir ) 
  861. $this->upload_dir = wp_upload_dir(); 
  862.  
  863. $zip_name = explode( '/', $bws_license_plugin ); 
  864.  
  865. if ( !function_exists( 'curl_init' ) ) { 
  866. $received_content = file_get_contents( $url ); 
  867. } else { 
  868. $ch = curl_init(); 
  869. curl_setopt( $ch, CURLOPT_URL, $url ); 
  870. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); 
  871. $received_content = curl_exec( $ch ); 
  872. curl_close( $ch ); 
  873.  
  874. if ( ! $received_content ) { 
  875. $error = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' ); 
  876. } else { 
  877. if ( is_writable( $this->upload_dir["path"] ) ) { 
  878. $file_put_contents = $this->upload_dir["path"] . "/" . $zip_name[0] . ".zip"; 
  879. if ( file_put_contents( $file_put_contents, $received_content ) ) { 
  880. @chmod( $file_put_contents, octdec( 755 ) ); 
  881. if ( class_exists( 'ZipArchive' ) ) { 
  882. $zip = new ZipArchive(); 
  883. if ( $zip->open( $file_put_contents ) === TRUE ) { 
  884. $zip->extractTo( WP_PLUGIN_DIR ); 
  885. $zip->close(); 
  886. } else { 
  887. $error = __( "Failed to open the zip archive. Please, upload the plugin manually", 'bestwebsoft' ); 
  888. } elseif ( class_exists( 'Phar' ) ) { 
  889. $phar = new PharData( $file_put_contents ); 
  890. $phar->extractTo( WP_PLUGIN_DIR ); 
  891. } else { 
  892. $error = __( "Your server does not support either ZipArchive or Phar. Please, upload the plugin manually", 'bestwebsoft' ); 
  893. @unlink( $file_put_contents ); 
  894. } else { 
  895. $error = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' ); 
  896. } else { 
  897. $error = __( "UploadDir is not writable. Please, upload the plugin manually", 'bestwebsoft' ); 
  898.  
  899. /** activate Pro */ 
  900. if ( file_exists( WP_PLUGIN_DIR . '/' . $zip_name[0] ) ) { 
  901. if ( $this->is_multisite && is_plugin_active_for_network( $this->plugin_basename ) ) { 
  902. /** if multisite and free plugin is network activated */ 
  903. $active_plugins = get_site_option( 'active_sitewide_plugins' ); 
  904. $active_plugins[ $bws_license_plugin ] = time(); 
  905. update_site_option( 'active_sitewide_plugins', $active_plugins ); 
  906. } else { 
  907. /** activate on a single blog */ 
  908. $active_plugins = get_option( 'active_plugins' ); 
  909. array_push( $active_plugins, $bws_license_plugin ); 
  910. update_option( 'active_plugins', $active_plugins ); 
  911. $this->pro_plugin_is_activated = true; 
  912. } elseif ( empty( $error ) ) { 
  913. $error = __( "Failed to download the zip archive. Please, upload the plugin manually", 'bestwebsoft' ); 
  914. } else { 
  915. $error = __( "Something went wrong. Try again later or upload the plugin manually. We are sorry for inconvenience.", 'bestwebsoft' ); 
  916. } else { 
  917. $bstwbsftwppdtplgns_options[ $bws_license_plugin ] = $bws_license_key; 
  918. /** activate Pro */ 
  919. if ( ! is_plugin_active( $bws_license_plugin ) ) { 
  920. if ( $this->is_multisite && is_plugin_active_for_network( $this->plugin_basename ) ) { 
  921. /** if multisite and free plugin is network activated */ 
  922. $network_wide = true; 
  923. } else { 
  924. /** activate on a single blog */ 
  925. $network_wide = false; 
  926. activate_plugin( $bws_license_plugin, NULL, $network_wide ); 
  927. $this->pro_plugin_is_activated = true; 
  928. /** add 'track_usage' for Pro version */ 
  929. if ( ! empty( $bstwbsftwppdtplgns_options['track_usage'][ $this->plugin_basename ] ) && 
  930. empty( $bstwbsftwppdtplgns_options['track_usage'][ $bws_license_plugin ] ) ) { 
  931. $bstwbsftwppdtplgns_options['track_usage'][ $bws_license_plugin ] = $bstwbsftwppdtplgns_options['track_usage'][ $this->plugin_basename ]; 
  932.  
  933. if ( $this->is_multisite ) 
  934. update_site_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); 
  935. else 
  936. update_option( 'bstwbsftwppdtplgns_options', $bstwbsftwppdtplgns_options ); 
  937.  
  938. if ( $this->pro_plugin_is_activated ) 
  939. delete_transient( 'bws_plugins_update' ); 
  940. } else { 
  941. $error = __( "Please, enter Your license key", 'bestwebsoft' ); 
  942. return compact( 'error', 'message' ); 
  943.  
  944. /** 
  945. * Display help phrase 
  946. * @access public 
  947. * @param void 
  948. * @return array The action results 
  949. */ 
  950. public function help_phrase() { 
  951. echo '<div class="bws_tab_description">' . __( 'Need Help?', 'bestwebsoft' ) . ' '; 
  952. if ( '' != $this->doc_link ) 
  953. echo '<a href="' . $this->doc_link . '" target="_blank">' . __( 'Read the Instruction', 'bestwebsoft' ); 
  954. else 
  955. echo '<a href="https://support.bestwebsoft.com/hc/en-us/" target="_blank">' . __( 'Visit Help Center', 'bestwebsoft' ); 
  956. if ( '' != $this->doc_video_link ) 
  957. echo '</a>' . ' ' . __( 'or', 'bestwebsoft' ) . ' ' . '<a href="' . $this->doc_video_link . '" target="_blank">' . __( 'Watch the Video', 'bestwebsoft' ); 
  958. echo '</a></div>'; 
  959.  
  960. public function bws_pro_block_links() {  
  961. global $wp_version; ?> 
  962. <div class="bws_pro_version_tooltip">  
  963. <a class="bws_button" href="<?php echo $this->plugins_info['PluginURI']; ?>?k=<?php echo $this->link_key; ?>&pn=<?php echo $this->link_pn; ?>&v=<?php echo $this->plugins_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="<?php echo $this->plugins_info["Name"]; ?>"><?php _e( 'Upgrade to Pro', 'bestwebsoft' ); ?></a> 
  964. <?php if ( $this->trial_days !== false ) { ?> 
  965. <span class="bws_trial_info"> 
  966. <?php _e( 'or', 'bestwebsoft' ); ?>  
  967. <a href="<?php echo $this->plugins_info['PluginURI']; ?>?k=<?php echo $this->link_key; ?>&pn=<?php echo $this->link_pn; ?>&v=<?php echo $this->plugins_info["Version"]; ?>&wp_v=<?php echo $wp_version; ?>" target="_blank" title="<?php echo $this->plugins_info["Name"]; ?>"><?php _e( 'Start Your Free Trial', 'bestwebsoft' ); ?></a> 
  968. </span> 
  969. <?php } ?> 
  970. <div class="clear"></div> 
  971. </div> 
  972. <?php } 
  973.  
  974. /** 
  975. * Restore plugin options to defaults 
  976. * @access public 
  977. * @param void 
  978. * @return void 
  979. */ 
  980. public function restore_options() { 
  981. /** 
  982. * filter - Change default_options array OR process custom functions 
  983. */ 
  984. $this->options = apply_filters( __CLASS__ . '_additional_restore_options', $this->default_options ); 
  985. if ( $this->is_network_options ) { 
  986. $this->options['network_apply'] = 'default'; 
  987. $this->options['network_view'] = '1'; 
  988. $this->options['network_change'] = '1'; 
  989. update_site_option( $this->prefix . '_options', $this->options ); 
  990. } else { 
  991. update_option( $this->prefix . '_options', $this->options );