/bws_menu/class-bws-settings.php

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