Advertisement
nshelper

Untitled

May 9th, 2024
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.45 KB | None | 0 0
  1. <?php
  2.  
  3. class IELMS_options_interface
  4. {
  5.  
  6. var $licence;
  7.  
  8. function __construct()
  9. {
  10.  
  11. $this->licence = new IELMS_licence();
  12.  
  13. if (isset($_GET['page']) && ($_GET['page'] == 'main-lms-data' ) )
  14. {
  15. add_action( 'init', array($this, 'options_update'), 1 );
  16. }
  17.  
  18. add_action( 'admin_menu', array($this, 'admin_menu') );
  19.  
  20. if(!$this->licence->licence_key_verify())
  21. {
  22. add_action('admin_notices', array($this, 'admin_no_key_notices'));
  23. }
  24.  
  25. }
  26.  
  27. function __destruct()
  28. {
  29.  
  30. }
  31.  
  32. function admin_menu()
  33. {
  34. if(!$this->licence->licence_key_verify())
  35. {
  36. add_menu_page(
  37. 'Export LMS Data', //Page Title
  38. 'Import-Export LMS Data', //Menu Title
  39. 'manage_options', //Capability
  40. 'main-lms-data', //Menu slug
  41. array($this,'licence_form'),
  42. 'dashicons-admin-tools' //Callback to print html
  43. );
  44. $hookID = add_submenu_page(
  45. 'main-lms-data',
  46. 'Export LMS Data', //page title
  47. 'License Manager', //menu title
  48. 'manage_options', //capability,
  49. 'main-lms-data',//menu slug
  50. array($this,'licence_form'),
  51. );
  52. }
  53. else
  54. {
  55. add_menu_page(
  56. 'Export LMS Data', //Page Title
  57. 'Import-Export LMS Data', //Menu Title
  58. 'manage_options', //Capability
  59. 'main-lms-data', //Menu slug
  60. array($this,'licence_deactivate_form'),
  61. 'dashicons-admin-tools' //Callback to print html
  62. );
  63. $hookID = add_submenu_page(
  64. 'main-lms-data',
  65. 'Export LMS Data', //page title
  66. 'License Manager', //menu title
  67. 'manage_options', //capability,
  68. 'main-lms-data',//menu slug
  69. array($this,'licence_deactivate_form'),
  70. );
  71. }
  72.  
  73. add_action('load-' . $hookID , array($this, 'load_dependencies'));
  74. add_action('load-' . $hookID , array($this, 'admin_notices'));
  75.  
  76. add_action('admin_print_styles-' . $hookID , array($this, 'admin_print_styles'));
  77. add_action('admin_print_scripts-' . $hookID , array($this, 'admin_print_scripts'));
  78.  
  79. }
  80.  
  81.  
  82. function options_interface()
  83. {
  84.  
  85.  
  86. if(!$this->licence->licence_key_verify() && !is_multisite())
  87. {
  88. $this->licence_form();
  89. return;
  90. }
  91.  
  92. if(!$this->licence->licence_key_verify() && is_multisite())
  93. {
  94. $this->licence_multisite_require_nottice();
  95. return;
  96. }
  97.  
  98. }
  99.  
  100. function options_update()
  101. {
  102.  
  103. if (isset($_POST['slt_licence_form_submit']))
  104. {
  105. $this->licence_form_submit();
  106. return;
  107. }
  108.  
  109. }
  110.  
  111. function load_dependencies()
  112. {
  113.  
  114. }
  115.  
  116. function admin_notices()
  117. {
  118. global $slt_form_submit_messages;
  119.  
  120. if($slt_form_submit_messages == '')
  121. return;
  122.  
  123. $messages = $slt_form_submit_messages;
  124.  
  125.  
  126. if(count($messages) > 0)
  127. {
  128. echo "<div id='notice' class='updated fade'><p>". implode("</p><p>", $messages ) ."</p></div>";
  129. }
  130.  
  131. }
  132.  
  133. function admin_print_styles()
  134. {
  135. wp_register_style( 'import-export-lms-data_admin', IELMS_URL . '/includes/licensing/css/admin.css' );
  136. wp_enqueue_style( 'import-export-lms-data_admin' );
  137. }
  138.  
  139. function admin_print_scripts()
  140. {
  141.  
  142. }
  143.  
  144.  
  145. function admin_no_key_notices()
  146. {
  147. if ( !current_user_can('manage_options'))
  148. return;
  149.  
  150. $screen = get_current_screen();
  151.  
  152.  
  153. if(isset($screen->id) && $screen->id == 'toplevel_page_main-lms-data')
  154. return;
  155.  
  156. ?><div class="updated fade"><p><?php _e( "Import-Export LMS Data is inactive, please enter your", 'import-export-lms-data' ) ?> <a href="admin.php?page=main-lms-data"><?php _e( "Licence Key", 'import-export-lms-data' ) ?></a></p></div><?php
  157.  
  158. }
  159.  
  160. function licence_form_submit()
  161. {
  162. global $slt_form_submit_messages;
  163.  
  164. //check for de-activation
  165. if (isset($_POST['slt_licence_form_submit']) && isset($_POST['slt_licence_deactivate']) && wp_verify_nonce($_POST['slt_license_nonce'],'slt_license'))
  166. {
  167. global $slt_form_submit_messages;
  168.  
  169. $license_data = IELMS_licence::get_licence_data();
  170. $license_key = $license_data['key'];
  171.  
  172. //build the request query
  173. $args = array(
  174. 'woo_sl_action' => 'deactivate',
  175. 'licence_key' => $license_key,
  176. 'product_unique_id' => IELMS_PRODUCT_ID,
  177. 'domain' => IELMS_INSTANCE
  178. );
  179. $request_uri = IELMS_APP_API_URL . '?' . http_build_query( $args , '', '&');
  180. $data = wp_remote_get( $request_uri );
  181.  
  182. if(is_wp_error( $data ) || $data['response']['code'] != 200)
  183. {
  184. $slt_form_submit_messages[] .= __('There was a problem connecting to ', 'import-export-lms-data') . IELMS_APP_API_URL;
  185. return;
  186. }
  187.  
  188. $response_block = json_decode($data['body']);
  189. //retrieve the last message within the $response_block
  190. $response_block = $response_block[count($response_block) - 1];
  191. $response = $response_block->message;
  192.  
  193. if(isset($response_block->status))
  194. {
  195. if($response_block->status == 'success' && $response_block->status_code == 's201')
  196. {
  197. //the license is active and the software is active
  198. $slt_form_submit_messages[] = $response_block->message;
  199.  
  200. $license_data = IELMS_licence::get_licence_data();
  201.  
  202. //save the license
  203. $license_data['key'] = '';
  204. $license_data['last_check'] = time();
  205.  
  206. IELMS_licence::update_licence_data( $license_data );
  207. }
  208.  
  209. else //if message code is e104 force de-activation
  210. if ($response_block->status_code == 'e002' || $response_block->status_code == 'e104')
  211. {
  212. $license_data = IELMS_licence::get_licence_data();
  213.  
  214. //save the license
  215. $license_data['key'] = '';
  216. $license_data['last_check'] = time();
  217.  
  218. IELMS_licence::update_licence_data( $license_data );
  219. }
  220. else
  221. {
  222. $slt_form_submit_messages[] = __('There was a problem deactivating the licence: ', 'import-export-lms-data') . $response_block->message;
  223.  
  224. return;
  225. }
  226. }
  227. else
  228. {
  229. $slt_form_submit_messages[] = __('There was a problem with the data block received from ' . IELMS_APP_API_URL, 'import-export-lms-data');
  230. return;
  231. }
  232.  
  233. //redirect
  234. $current_url = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  235.  
  236. wp_redirect($current_url);
  237. die();
  238.  
  239. }
  240.  
  241.  
  242.  
  243. if (isset($_POST['slt_licence_form_submit']) && wp_verify_nonce($_POST['slt_license_nonce'],'slt_license'))
  244. {
  245.  
  246. $license_key = isset($_POST['license_key'])? sanitize_key(trim($_POST['license_key'])) : '';
  247.  
  248. if($license_key == '')
  249. {
  250. $slt_form_submit_messages[] = __("Licence Key can't be empty", 'import-export-lms-data');
  251. return;
  252. }
  253.  
  254. //build the request query
  255. $args = array(
  256. 'woo_sl_action' => 'activate',
  257. 'licence_key' => $license_key,
  258. 'product_unique_id' => IELMS_PRODUCT_ID,
  259. 'domain' => IELMS_INSTANCE
  260. );
  261. $request_uri = IELMS_APP_API_URL . '?' . http_build_query( $args , '', '&');
  262. $data = wp_remote_get( $request_uri );
  263.  
  264. if(is_wp_error( $data ) || $data['response']['code'] != 200)
  265. {
  266. $slt_form_submit_messages[] .= __('There was a problem connecting to ', 'import-export-lms-data') . IELMS_APP_API_URL;
  267. return;
  268. }
  269.  
  270. $response_block = json_decode($data['body']);
  271.  
  272. if ( ! is_array ( $response_block ) )
  273. {
  274. $slt_form_submit_messages[] = __('There was a problem with the data block received from ' . IELMS_APP_API_URL, 'import-export-lms-data');
  275. return;
  276. }
  277.  
  278. //retrieve the last message within the $response_block
  279. $response_block = $response_block[count($response_block) - 1];
  280. $response = $response_block->message;
  281.  
  282. if(isset($response_block->status))
  283. {
  284. if( $response_block->status == 'success' && ( $response_block->status_code == 's100' || $response_block->status_code == 's101' ) )
  285. {
  286. //the license is active and the software is active
  287. $slt_form_submit_messages[] = $response_block->message;
  288.  
  289. $license_data = IELMS_licence::get_licence_data();
  290.  
  291. //save the license
  292. $license_data['key'] = $license_key;
  293. $license_data['last_check'] = time();
  294.  
  295. IELMS_licence::update_licence_data( $license_data );
  296.  
  297. }
  298. else
  299. {
  300. $slt_form_submit_messages[] = __('There was a problem activating the licence: ', 'import-export-lms-data') . $response_block->message;
  301. return;
  302. }
  303. }
  304. else
  305. {
  306. $slt_form_submit_messages[] = __('There was a problem with the data block received from ' . IELMS_APP_API_URL, 'import-export-lms-data');
  307. return;
  308. }
  309.  
  310. //redirect
  311. $current_url = 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  312.  
  313. wp_redirect($current_url);
  314. die();
  315. }
  316.  
  317. }
  318.  
  319. function licence_form()
  320. {
  321. ?>
  322. <div class="wrap">
  323. <div id="icon-settings" class="icon32"></div>
  324.  
  325.  
  326. <div id="form_data">
  327. <h3><?php _e( "Licence", 'import-export-lms-data' ) ?></h3>
  328.  
  329. <form name="form" method="post">
  330.  
  331. <?php wp_nonce_field('slt_license','slt_license_nonce'); ?>
  332. <input type="hidden" name="slt_licence_form_submit" value="true" />
  333.  
  334. <div class="start-container licence-key">
  335. <div class="text">
  336.  
  337. <h2><?php _e( "License Key", 'import-export-lms-data' ) ?></h2>
  338. <div class="option">
  339. <div class="controls">
  340. <p><input type="text" value="" name="license_key" class="text-input"></p>
  341. </div>
  342. <div class="explain"><?php _e( "Enter the Licence Key you received when purchased this product. If you lost the key, you can always retrieve it from", 'import-export-lms-data' ) ?> <a href="https://terradigita.com/my-account/" target="_blank"><?php _e( "My Account", 'import-export-lms-data' ) ?></a></div>
  343. </div>
  344. <p class="submit">
  345. <input type="submit" name="Submit" class="button-primary" value="<?php _e('Save', 'import-export-lms-data') ?>">
  346. </p>
  347. </div>
  348. </div>
  349. </form>
  350.  
  351. </div>
  352.  
  353. </div>
  354. <?php
  355.  
  356. }
  357.  
  358. function licence_deactivate_form()
  359. {
  360. $licence_data = IELMS_licence::get_licence_data();
  361.  
  362. ?>
  363. <div class="wrap">
  364.  
  365.  
  366. <div id="form_data">
  367. <h3><?php _e( "Licence", 'wp-hide-security-enhancer' ) ?></h3>
  368.  
  369. <form name="form" method="post">
  370. <?php wp_nonce_field('slt_license','slt_license_nonce'); ?>
  371. <input type="hidden" name="slt_licence_form_submit" value="true" />
  372. <input type="hidden" name="slt_licence_deactivate" value="true" />
  373.  
  374. <div class="start-container licence-key">
  375. <div class="text">
  376.  
  377. <h2><?php _e( "License Key", 'import-export-lms-data' ) ?></h2>
  378. <div class="option">
  379. <div class="controls">
  380. <p><b><?php echo substr($licence_data['key'], 0, 20) ?>-xxxxxxxx-xxxxxxxx</b> &nbsp;&nbsp;&nbsp;<a class="button-secondary" title="Deactivate" href="javascript: void(0)" onclick="jQuery(this).closest('form').submit();"><?php _e( "Deactivate", 'wp-hide-security-enhancer' ) ?></a></p>
  381. </div>
  382. <div class="explain"><?php _e( "You can generate more keys at ", 'import-export-lms-data' ) ?> <a href="https://terradigita.com/my-account/" target="_blank"><?php _e( "My Account", 'import-export-lms-data' ) ?></a></div>
  383. </div>
  384.  
  385. <?php
  386.  
  387. if ( isset( $licence_data ) && ! empty ( $licence_data['licence_status'] ) )
  388. {
  389. ?><br /><p><?php _e( "License Status", 'wp-hide-security-enhancer' ) ?>: <b><?php echo ucfirst( __( $licence_data['licence_status'], 'import-export-lms-data' ) ); ?></b></p><?php
  390. }
  391.  
  392. if ( isset( $licence_data ) && ! empty ( $licence_data['licence_expire'] ) )
  393. {
  394. ?><p><?php _e( "License Expiration", 'import-export-lms-data' ) ?>: <b><?php echo date_i18n( get_option( 'date_format' ), strtotime( $licence_data['licence_expire'] ) ); ?></b><?php
  395.  
  396. if ( strtotime( $licence_data['licence_expire'] ) < strtotime( date('Y-m-d') ) )
  397. {
  398. ?> &nbsp;&nbsp;&nbsp;&nbsp;<span class="warning"><?php _e( "Licence is expired, plugin <b>Updates</b> and <b>Support</b> are not available", 'import-export-lms-data' ) ?>.</span><?php
  399. }
  400.  
  401. ?></p><?php
  402. }
  403. ?>
  404. </div>
  405. </div>
  406. </form>
  407.  
  408. </div>
  409.  
  410.  
  411. </div>
  412.  
  413. <?php
  414. }
  415.  
  416. function licence_multisite_require_nottice()
  417. {
  418. ?>
  419. <div class="wrap">
  420. <h1><?php _e( "Software License", 'import-export-lms-data' ) ?><br />&nbsp;</h1>
  421. <div id="form_data">
  422. <div class="postbox">
  423. <div class="section section-text ">
  424. <h4 class="heading"><?php _e( "License Key Required", 'import-export-lms-data' ) ?>!</h4>
  425. <div class="option">
  426. <div class="explain"><?php _e( "Enter the License Key you got when bought this product. If you lost the key, you can always retrieve it from", 'import-export-lms-data' ) ?> <a href="http://www.nsp-code.com/premium-plugins/my-account/" target="_blank"><?php _e( "My Account", 'import-export-lms-data' ) ?></a><br />
  427. <?php _e( "More keys can be generate from", 'import-export-lms-data' ) ?> <a href="http://www.nsp-code.com/premium-plugins/my-account/" target="_blank"><?php _e( "My Account", 'import-export-lms-data' ) ?></a>
  428. </div>
  429. </div>
  430. </div>
  431. </div>
  432. </div>
  433. </div>
  434. <?php
  435.  
  436. }
  437.  
  438.  
  439. }
  440.  
  441.  
  442.  
  443. ?>
  444.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement