PluginProbe
Translation with DeepL API / 2.4.5
Translation with DeepL API v2.4.5
trunk 0.1.20180323 1.0 1.2.5.1 1.5.2.5 1.7.5 2.4.3.12 2.4.3.9 2.4.5
wpdeepl / wpdeeplpro / keypress-api-client.php

keypress-api-client.php in Translation with DeepL API 2.4.5, at wpdeeplpro/keypress-api-client.php

860 lines 26.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * KeyPress API Client
5 * Description: The class needed for plugin to interact with KeyPress Server
6 * Version: 1.0
7 * Last change
8 * 14/02/2023 12:20:48
9 * PHP: 8.0
10 * Author: Fluenx
11 * Author URI: https://www.fluenx.com/
12 * Text Domain: keypress-i18n
13 * Domain Path: /languages
14 */
15
16 if( !class_exists( 'KeyPressAPIClient' ) ) {
17 class KeyPressAPIClient {
18 const APISERVER = 'https://solutions.fluenx.com';
19 const APIBASE = 'wp-json/keypress';
20
21 function __construct() {
22 // overrides plugin update
23 add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'modify_plugins_transient' ), 80, 1 );
24
25 // add details to plugin details
26 add_filter( 'plugins_api', array( $this, 'modify_plugin_details' ), 10, 3 );
27
28 // admin message
29 add_action('after_plugin_row_' . static::PLUGIN_FILE, array( $this, 'pleaseActivate' ), 10, 3);
30
31 add_action('admin_notices', array( $this, 'maybe_admin_notices' ) );
32
33 add_action('wp_ajax_wpdeeplpro_renewal_push_reminder', array( $this, 'push_reminder') );
34
35 $this->setUpPluginKeyPress();
36
37 }
38
39 protected function setUpPluginKeyPress() {
40 return;
41 }
42
43 function modify_plugin_details( $result, $action = null, $args = null ) {
44
45 // vars
46 $plugin = false;
47
48 // only for 'plugin_information' action
49 if ( $action !== 'plugin_information' ) {
50 return $result;
51 }
52
53 if( $args->slug != static::PLUGIN_SLUG ) {
54 return $result;
55 }
56
57 // find plugin via slug
58 $plugins = get_plugins();
59 if( !isset( $plugins[static::PLUGIN_FILE] ) ) {
60 return $result;
61 }
62
63 $updateInfo = $this->getUpdateInfo();
64 if( !$updateInfo || is_wp_error( $updateInfo ) ) {
65 return $result;
66 }
67
68 $response = (object) $updateInfo['data'];
69 $response->sections = array();
70 //plouf( $result, " zeirjzerizrizp r"); die('ozearok');
71 foreach( array( 'description', 'installation', 'changelog', 'upgrade_notice' ) as $key ) {
72 if( !empty( $updateInfo['data']['plugin_info'][$key]) ) {
73 $response->sections[$key] = $updateInfo['data']['plugin_info'][$key];
74 }
75 }
76
77 return $response;
78 }
79
80 function modify_plugins_transient( $transient ) {
81 // bail early if no response (error)
82 if ( ! isset( $transient->response ) ) {
83 return $transient;
84 }
85 $checked = $this->getUpdateInfo();
86 //plouf( $checked);
87 if (is_wp_error( $checked ) ) {
88 // from license server
89 return $transient;
90 }
91 //echo "<!-- KEYPRESS "; plouf( $checked ); echo "-->";
92 if( $checked['success'] ) { // nouvelle version
93 if( isset( $checked['data']['package'] ) ) {
94 $salt = get_option( static::OPTIONKEY_SALT );
95 $host = $this->getSiteHost();
96 $checked['data']['package'] .= '&salt=' . $salt . '&host=' . $host;
97 }
98 $can_update = true;
99 $transient->response[static::PLUGIN_FILE] = (object) $checked['data'];
100 }
101 else {
102 $transient->no_update[static::PLUGIN_FILE] = (object) $checked['data'];
103 }
104
105 //plouf( $transient , " ierztirhzri");
106 //$this->checked++;
107
108 //plouf( $transient, "apres " );die('z64ea66e446e4ok');
109 return $transient;
110 }
111
112 public function getPluginUpdateTransientKey() {
113 return 'keypress_' . static::PLUGIN_SLUG .'_updates';
114 }
115
116 protected function checkIfUpdatePossible( $ping_response ) {
117 return $ping_response;
118 /*
119 $ping_response['data']['can_update'] = 1;
120 $ping_response['data']['why_no_update'] = array();
121
122 if( isset( $ping_response['data']['tested'] ) && version_compare( get_bloginfo( 'version' ), $ping_response['data']['tested'] ) ) {
123 $ping_response['data']['can_update'] = 1;
124 $ping_response['data']['why_no_update'][] = __( '<strong>Warning:</strong> This plugin <strong>has not been tested</strong> with your current version of WordPress.' );
125 }
126 if( isset( $ping_response['data']['requires'] ) && version_compare( $ping_response['data']['requires'], get_bloginfo( 'version' ) ) ) {
127 $ping_response['data']['can_update'] = 0;
128 $ping_response['data']['why_no_update'][] = __( '<strong>Error:</strong> This plugin <strong>requires a newer version of WordPress</strong>.' );
129 }
130 if( isset( $ping_response['data']['requires_php'] ) && version_compare( $ping_response['data']['requires_php'], PHP_VERSION ) ) {
131 $ping_response['data']['can_update'] = 0;
132 $ping_response['data']['why_no_update'][] = __( '<strong>Error:</strong> This plugin <strong>requires a newer version of PHP</strong>.' );
133 }
134 return $ping_response;
135 */
136 }
137
138 protected function getSiteHost() {
139 $url = site_url( '/' );
140 $parsed = parse_url( $url );
141 return $parsed['host'];
142 }
143
144 protected function getLicenseKey() {
145 return get_option( 'wpdeepl_' . static::OPTIONKEY_LICENSE );
146 }
147 protected function getSalt() {
148 return get_option( static::OPTIONKEY_SALT );
149 }
150
151 public function isActive() {
152
153 return get_option( static::OPTIONKEY_STATUS ) == 'activated';
154
155 }
156
157
158
159 // this function check POST data for a license key change
160 public function shouldWeActOnLicenseKeyChange( $new_license_key = false ) {
161
162 //plouf($_POST); plouf( $_GET, " get");
163
164 if( !$new_license_key ) {
165 if( isset( $_POST[$this->post_option_key] ) ) {
166 if( !isset( $_GET['action'] ) || $_GET['action'] != 'deactivate_license' )
167 $new_license_key = $_POST[$this->post_option_key];
168 }
169 }
170
171 if( !$new_license_key ) {
172 return false;
173 }
174
175
176 $license_status = get_option( static::OPTIONKEY_STATUS );
177 $old_license_key = $this->getLicenseKey();
178 if(
179 $new_license_key != $old_license_key
180 ||
181 ( !$old_license_key && $new_license_key )
182 || !$license_status
183 ) {
184 // die("change of key");
185 $salt = $this->checkLicense( $new_license_key );
186 if( is_wp_error( $salt ) ) {
187 update_option( 'keypress_last_error', "Salt failed with $new_license_key : " . $salt->get_error_message() );
188 return false;
189 }
190 if( $salt ) {
191 $activated = $this->activateInstallation( $salt );
192 }
193 }
194 elseif( $license_status == 'salted' ) {
195 $salt = $this->getSalt();
196 $activated = $this->activateInstallation( $salt );
197 //echo " status = " . $license_status; var_dump( $activated ); die('a65z464e6a6e4ok');
198 }
199
200 }
201
202 public function checkLicense( $license_key = false ) {
203 if( !$license_key )
204 $license_key = $this->getLicenseKey();
205 if( !$license_key )
206 return false;
207
208 $license_key = trim( $license_key );
209 $product_sku = static::PLUGIN_SKU;
210 $host = $this->getSiteHost();
211
212 $method = 'GET';
213 $endPoint = trailingslashit( static::APIVERSION ) . 'license/check';
214 $args = compact('license_key', 'product_sku', 'host' );
215 $result = $this->request( $method, $endPoint, $args );
216
217 //plouf( $result ); die('ok');
218
219 $installationSalt = false;
220 if( is_wp_error( $result ) ) {
221 update_option( static::OPTIONKEY_STATUS, 'salt_failed' );
222 update_option( 'keypress_last_error', "Salt failed with $license_key, $product_sku, $host" );
223 return $result;
224 }
225 elseif( $result['success'] && $result['data']['salt'] ) {
226 update_option( static::OPTIONKEY_STATUS, 'salted' );
227
228 $installationSalt = $result['data']['salt'];
229 update_option( static::OPTIONKEY_SALT, $installationSalt );
230
231 if( isset( $checkResult['data']['expires_at'] ) ) {
232 update_option( static::OPTIONKEY_EXPIRES, $checkResult['data']['expires_at'] );
233 }
234 if( isset( $checkResult['data']['renewal_message'] ) ) {
235 update_option( static::OPTIONKEY_RENEWAL_MESSAGE, $checkResult['data']['renewal_message'] );
236 }
237 }
238 else {
239 update_option( static::OPTIONKEY_STATUS, 'failed_license_check' );
240 }
241
242 return $installationSalt;
243 }
244
245 public function activateInstallation( $salt = '') {
246
247 if( empty( $salt ) ) {
248 $salt = $this->getSalt();
249 }
250
251 if( is_wp_error( $salt ) ) {
252 return $salt;
253 }
254 $salt = trim( $salt );
255 $product_sku = static::PLUGIN_SKU;
256 $host = $this->getSiteHost();
257
258 $method = 'GET';
259 $endPoint = trailingslashit( static::APIVERSION ) . 'installation/activate';
260 $args = compact('salt', 'product_sku', 'host' );
261 $this->debug = false;
262 $result = $this->request( $method, $endPoint, $args );
263 //plouf( $args, "$method $endPoint" ); plouf( $result );die('oaze4e968aze48zk');
264
265 if( is_wp_error( $result ) ) {
266 update_option( static::OPTIONKEY_STATUS, 'failed_activation' );
267 update_option( 'keypress_last_error', $result->get_error_message() );
268 //plouf( $result, __METHOD__ );die('error');
269 }
270 elseif( $result['success'] ) {
271 update_option( static::OPTIONKEY_STATUS, 'activated' );
272 }
273 else {
274 update_option( static::OPTIONKEY_STATUS, 'failed_activation' );
275 }
276 return $result;
277 }
278
279 public function deActivateLicense() {
280 $method = 'GET';
281 $endPoint = trailingslashit( static::APIVERSION ) . 'license/deactivate';
282 $salt = get_option( static::OPTIONKEY_SALT );
283 $args = compact('salt');
284 $result = $this->request( $method, $endPoint, $args );
285 if( $result['success'] )
286 update_option( static::OPTIONKEY_STATUS, 'deactivated' );
287 else
288 update_option( static::OPTIONKEY_STATUS, 'failed_deactivation' );
289 return $result;
290
291 }
292
293 protected function pingProduct() {
294
295
296 $args = array(
297 'salt' => $this->getSalt(),
298 'product_sku' => static::PLUGIN_SKU,
299 'host' => $this->getSiteHost(),
300 'current_version' => static::getCurrentVersion(),
301 'wp_name' => get_bloginfo( 'name' ),
302 'wp_version' => get_bloginfo( 'version' ),
303 'wp_language' => get_bloginfo( 'language' ),
304 'wp_timezone' => get_option( 'timezone_string' ),
305 'php_version' => PHP_VERSION,
306 );
307
308 $method = 'GET';
309 $endPoint = trailingslashit( static::APIVERSION ) . 'product/ping';
310
311 $response = $this->request( $method, $endPoint, $args );
312 //plouf( $args, "args"); plouf( $response , " zerizerihizr");
313
314 if( empty( $response ) ) {
315 update_option( 'keypress_last_updated_failed', true );
316 return false;
317 }
318 if( is_wp_error( $response) ) {
319 update_option( 'keypress_last_updated_failed', true );
320 return $response;
321 }
322
323 update_option( 'keypress_last_updated_failed', false );
324
325 $response['data']['slug'] = static::PLUGIN_SLUG;
326 $response['data']['file'] = static::PLUGIN_FILE;
327
328 return $response;
329 }
330
331
332 protected function request( $method = 'GET', $endPoint = '', $args = array() ) {
333
334 $APIURL = trailingslashit( self::APISERVER ) . trailingslashit( self::APIBASE ) . $endPoint;
335
336 // Create header
337 $headers = array(
338 'Accept' => 'application/json',
339 'Content-Type' => 'application/json; charset=UTF-8',
340 );
341
342 // Initialize wp_args
343 $wp_args = array(
344 'headers' => $headers,
345 'method' => $method,
346 'timeout' => 10,
347 );
348
349 // Populate the args for use in the wp_remote_request call
350 if ( ! empty( $args ) ) {
351 $wp_args['body'] = $args;
352 }
353
354 // Make the call and store the response in $res
355 if( isset( $this->debug ) && $this->debug ) { plouf( $wp_args, $APIURL . __METHOD__ ); }
356 $res = wp_remote_request( $APIURL, $wp_args );
357 if( isset( $this->debug ) && $this->debug ) plouf($res, " res");
358
359 // Check for success
360 if ( ! is_wp_error( $res ) && in_array( (int) $res['response']['code'], array( 200, 201 ), true ) ) {
361 return json_decode( $res['body'], true );
362 } elseif ( is_wp_error( $res ) ) {
363 //plouf($res);
364 return $res;
365 } else {
366 $response = json_decode( $res['body'], true );
367 if ( 'rest_no_route' === $response['code'] ) {
368 $response['data']['status'] = 500;
369 }
370 $message = isset( $response['message'] ) ? $response['message'] : __( 'Check failed.', static::PLUGIN_TEXT_DOMAIN );
371 $code = isset( $response['code'] ) ? $response['code'] : 'keypress_failed_request';
372 return new WP_Error(
373 $code,
374 $message,
375 $response
376 );
377 }
378
379 }
380
381 public function getRenewalLink( $cart_url, $order_id, $license_id, $license_key ) {
382 $args = array(
383 'keypress_renewal' => $order_id,
384 'renew_licenses' => $license_id,
385 'license_key' => $license_key,
386 );
387 $renewal_link = add_query_arg( $args, $cart_url );
388 return $renewal_link;
389
390 }
391
392 protected function getUpdateInfo( $force_check = 0 ) {
393 $plugin_transient_update_name = $this->getPluginUpdateTransientKey();
394 //plouf( $transient, "transiendsi" );
395
396
397 $plugin_transient_update = $force_check ? false : get_transient( $plugin_transient_update_name );
398 //$plugin_transient_update = false;
399
400 if(
401 $plugin_transient_update
402 && !is_wp_error( $plugin_transient_update )
403 && isset( $plugin_transient_update['last_ping'] )
404 && ( time() - $plugin_transient_update['last_ping'] ) < static::MIN_TIME_BETWEEN_PINGS
405 ) {
406 $checked = $plugin_transient_update;
407 }
408 else {
409 $checked = $this->pingProduct();
410 if( is_wp_error( $checked ) )
411 return $checked;
412
413
414 $checked['last_ping'] = time();
415 // dejà vérifié par WordPress
416 // $checked = $this->checkIfUpdatePossible( $checked );
417 set_transient( $plugin_transient_update_name, $checked, static::MIN_TIME_BETWEEN_PINGS );
418
419 $pingData = $checked['data'];
420 if (isset( $pingData['valid_until'] ) ) {
421 update_option( static::OPTIONKEY_EXPIRES, $pingData['valid_until'] );
422
423 $renewal_link = $this->getRenewalLink( $pingData['cart_url'], $pingData['order_id'], $pingData['license_id'], $this->getLicenseKey() );
424 update_option( static::OPTIONKEY_RENEWAL_LINK, $renewal_link );
425 }
426 }
427
428
429 return $checked;
430 }
431
432 public function pleaseActivate($plugin_file, $plugin_data, $plugin_status) {
433
434 $class = $message = false;
435 //echo " option ? "; var_dump( get_option( static::OPTIONKEY_STATUS ) ); die('za6ea+ze46ae4a648e8e4ok');
436
437 if( $this->isActive() ) {
438 return;
439 $updateRequest = $this->getUpdateInfo();
440 if( $updateRequest['data']['has_newer_version'] ) {
441 $class = 'warning';
442 $message = 'Mettre à jour';
443 }
444
445 }
446 else {
447 $class = 'info';
448 $message = sprintf(
449 __('<a href="%s">Activate this plugin</a> to get updates.', 'keypress-i18n' ),
450 esc_url( admin_url( static::PLUGIN_ADMIN_PAGE ) )
451 );
452
453 }
454
455 if(!$message )
456 return false;
457
458 $wp_list_table = _get_list_table('WP_Plugins_List_Table');
459 $slug = dirname($plugin_file);
460 if(is_network_admin()){
461 $active_class = is_plugin_active_for_network($plugin_file) ? ' active' : '';
462 }else{
463 $active_class = is_plugin_active($plugin_file) ? ' active' : '';
464 }
465
466 ?>
467 <tr class="plugin-update-tr<?php echo $active_class; ?> keypress" id="<?php echo $slug; ?>-update" data-plugin="<?php echo $plugin_file; ?>"><td colspan="<?php echo $wp_list_table->get_column_count(); ?>" class="plugin-update colspanchange">
468 <div class="update-message notice inline notice-<?php echo $class; ?> notice-alt">
469 <p><?php echo $message; ?></p>
470 </div>
471 </tr>
472 <?php
473 }
474
475 function push_reminder() {
476 if ( ! wp_verify_nonce( $_POST['nonce'], 'wpdeeplpro_renewal_push_reminder' ) ) {
477 wp_send_json_error();
478 wp_die();
479 }
480 update_option( static::OPTIONKEY_RENEWAL_REMINDER, filter_var( $_POST['value'], FILTER_VALIDATE_INT ) );
481 wp_send_json_success();
482 wp_die();
483 }
484
485 function maybe_admin_notices() {
486
487 $has_renewal_notices = false;
488 $reminder_set = false;
489
490 $expiration_date = get_option( static::OPTIONKEY_EXPIRES );
491
492 if( $expiration_date && strtotime( $expiration_date ) != 0 && $expiration_date < date('Y-m-d H:i:s') ) {
493
494 $reminder_set = get_option( static::OPTIONKEY_RENEWAL_REMINDER );
495
496 if( $reminder_set && $reminder_set > time() ) {
497 // don't remind
498
499 }
500 else {
501
502 $renewal_message = get_option( static::OPTIONKEY_RENEWAL_MESSAGE );
503
504 $has_renewal_notices = true;
505 $days_expired = ( time() - strtotime( $expiration_date ) ) / DAY_IN_SECONDS;
506 $days_expired = round( $days_expired );
507 ?>
508 <div id="wpdeeplpro_renewal" class="notice notice-warning is-dismissible">
509 <p><strong><?php echo static::PLUGIN_TITLE; ?></strong>: <?php
510 printf(
511 __('Your license expired %d days ago. ', static::PLUGIN_SLUG ),
512 $days_expired
513 );
514
515 _e('You can renew your license on your account page', static::PLUGIN_SLUG );
516 if( $renewal_message) echo $renewal_message;
517
518 $renewal_link = get_option( static::OPTIONKEY_RENEWAL_LINK );
519 ?>
520 <a class="button-primary button" href="<?php echo $renewal_link; ?>" target="_blank" style=""><?php _e('Renew my license', static::PLUGIN_SLUG ); ?></a>
521
522
523 <span class="wpdeeplpro_renewal_reminders">
524 <a class="button" id="wpdeeplpro_renewal_reminder15days" href="#"><?php _e('Remind me in 15 days', static::PLUGIN_SLUG ); ?></a>
525 <a class="button" id="wpdeeplpro_renewal_noreminder" href="#"><?php _e('Don\'t remind me', static::PLUGIN_SLUG ); ?></a>
526 </span>
527
528 </p>
529 </div>
530
531 <?php
532 }
533 }
534 elseif( strtotime( $expiration_date ) < strtotime("+30 days") ) {
535
536 $reminder_set = get_option( static::OPTIONKEY_RENEWAL_REMINDER );
537 if( $reminder_set && $reminder_set > time() ) {
538 // don't remind
539
540 }
541 else {
542 $has_renewal_notices = true;
543
544 $renewal_message = get_option( static::OPTIONKEY_RENEWAL_MESSAGE );
545
546 $days_to_expiration = ( strtotime( $expiration_date ) - time() ) / DAY_IN_SECONDS;
547 $days_to_expiration = round( $days_to_expiration );
548 ?>
549
550 <div id="wpdeeplpro_renewal" class="notice notice-warning is-dismissible">
551 <p><strong><?php echo static::PLUGIN_TITLE; ?></strong>: <?php
552 printf(
553 __('Your license will expire in %d days. ', static::PLUGIN_SLUG ),
554 $days_to_expiration
555 );
556
557 _e('You can renew your license on your account page', static::PLUGIN_SLUG );
558 if( $renewal_message) echo $renewal_message;
559
560 $renewal_link = get_option( static::OPTIONKEY_RENEWAL_LINK );
561 ?>
562 <a class="button-primary button" href="<?php echo $renewal_link; ?>" target="_blank" style=""><?php _e('Renew my license', static::PLUGIN_SLUG ); ?></a>
563
564
565 <span class="wpdeeplpro_renewal_reminders">
566 <a class="button" id="wpdeeplpro_renewal_reminder15days" href="#"><?php _e('Remind me in 15 days', static::PLUGIN_SLUG ); ?></a>
567 <a class="button" id="wpdeeplpro_renewal_noreminder" href="#"><?php _e('Don\'t remind me', static::PLUGIN_SLUG ); ?></a>
568 </span>
569
570
571 </p>
572 </div>
573 <?php
574 }
575
576 }
577
578 if( $has_renewal_notices ) {
579 ?>
580
581 <script type="text/javascript">
582 jQuery('#wpdeeplpro_renewal_reminder15days').on('click', function() {
583 var dataVariable = {
584 'action': 'wpdeeplpro_renewal_push_reminder',
585 'value': '<?php echo strtotime('+ 15 days'); ?>',
586 'nonce' : '<?php echo wp_create_nonce('wpdeeplpro_renewal_push_reminder'); ?>'
587 };
588 jQuery.ajax({
589 url: ajaxurl,
590 type: 'POST',
591 data: dataVariable,
592 success: function (response) {
593 console.log(response);
594 jQuery('#wpdeeplpro_renewal').hide();
595 }
596 });
597 });
598 jQuery('#wpdeeplpro_renewal_noreminder').on('click', function() {
599 var dataVariable = {
600 'action': 'wpdeeplpro_renewal_push_reminder',
601 'value': '<?php echo strtotime('+ 9999 days'); ?>',
602 'nonce' : '<?php echo wp_create_nonce('wpdeeplpro_renewal_push_reminder'); ?>'
603 };
604 jQuery.ajax({
605 url: ajaxurl,
606 type: 'POST',
607 data: dataVariable,
608 success: function (response) {
609 console.log(response);
610 jQuery('#wpdeeplpro_renewal').hide();
611 }
612 });
613
614 });
615
616
617
618 </script>
619 <?php
620
621 }
622
623 }
624
625 public function keypress_admin_page_display_box() {
626
627 $license_status = get_option( static::OPTIONKEY_STATUS );
628 if( $license_status == 'failed_activation' ) {
629 $this->activateInstallation();
630 }
631 $license_status = get_option( static::OPTIONKEY_STATUS );
632 ?>
633
634
635 <div id="keypress<?php echo static::PLUGIN_SLUG; ?>_status">
636 <h2><?php printf( __('License: %s', 'keypress-i18n'), static::PLUGIN_TITLE ); ?></h2>
637 <?php
638 $force_check = get_option( 'keypress_last_updated_failed' ) ? true : false;
639 $pingResult = $this->getUpdateInfo( $force_check );
640
641 //plouf( $pingResult);
642
643 if( !$pingResult || is_wp_error( $pingResult ) ) {
644 // retry
645 //_e('We encountered an error while checking for updates info', 'keypress-i18n' );
646 $license_key = $this->getLicenseKey();
647 $salt = $this->checkLicense( $license_key );
648 if( $salt && !is_wp_error( $salt ) ) {
649 $activated = $this->activateInstallation( $salt );
650 if( $activated && !is_wp_error( $activated ) ) {
651 $force_check = true;
652 $pingResult = $this->getUpdateInfo( $force_check );
653 // plouf( $pingResult, "retruy" );
654 }
655 }
656 }
657
658
659 if( !$pingResult || is_wp_error( $pingResult ) ) {
660
661 ?>
662 <p><?php
663
664 if( is_wp_error( $pingResult ) ) {
665 if( $pingResult->get_error_code() == 'internal_server_error' ) {
666 _e('The license server returned an error', 'keypress-i18n' );
667
668 }
669 else {
670 printf(
671 __('License check failed: <span title="%s"><em>%s</em></span>.
672 <br />Please check your license or contact the publisher.', 'keypress-i18n' ),
673 $pingResult->get_error_code(),
674 $pingResult->get_error_message()
675 );
676 }
677 }
678 else {
679 _e('The license server returned an error', 'keypress-i18n' );
680 }
681 ?></p>
682 <?php
683 }
684 else {
685 $pingData = $pingResult['data'];
686 //plouf( $pingResult);
687 ?>
688 <p><?php printf( __('Current version: <b>%s</b>', 'keypress-i18n' ), static::getCurrentVersion() ); ?></p>
689 <p><?php printf( __('Available version: <b>%s</b>', 'keypress-i18n') , $pingData['new_version'] ); ?></p>
690
691
692 <?php if ( get_option( static::OPTIONKEY_STATUS ) === false ) {
693 echo "
694 <p>";
695 printf( __('Purchase <a href="%s" target="_blank">a license on this page</a> to get updates', 'keypress-i18n' ),
696 $pingData['url']
697 ); echo '</p>';
698 echo "
699 <p>";
700 printf( __('Once purchased, <a href="%s" target="_blank">find your license key on this page</a>', 'keypress-i18n' ),
701 trailingslashit( $pingData['account_page'] ) . 'downloads/'
702 ); echo '</p>';
703
704
705 }
706 ?>
707
708
709 <?php
710
711 $valid_license = false;
712 if( isset( $pingData['valid_until'] ) ) {
713 if( $pingData['valid_until'] == '0000-00-00 00:00:00') :
714 $valid_license = true;
715 ?>
716 <p><?php _e('Your license is valid forever', 'keypress-i18n'); ?></p>
717 <?php elseif( strtotime( $pingData['valid_until'] ) ) :
718 if( strtotime( $pingData['valid_until']) < time() ) :
719 $renewal_link = $this->getRenewalLink( $pingData['cart_url'], $pingData['order_id'], $pingData['license_id'], $this->getLicenseKey() );
720
721 ?>
722 <p><?php printf( __('Your license has expired on %s', 'keypress-i18n'), date('d/m/Y', strtotime( $pingData['valid_until'] ) ) ); ?></p>
723 <p class="order-again">
724 <a target="_blank" href="<?php echo $renewal_link; ?>" class="button keypress_renew_license">Renew your license</a>
725 </p>
726 <?php else :
727 $valid_license = true;
728 ?>
729 <p><?php printf( __('Your license expires on : %s', 'keypress-i18n'), date('d/m/Y', strtotime( $pingData['valid_until'] ) ) ); ?></p>
730 <?php endif; ?>
731 <?php endif; ?>
732 <?php }
733 else {
734 $valid_license = true;
735
736 }?>
737
738
739 <?php
740
741 if( isset( $pingData['license_valid'] ) && $pingData['active_license'] ) {
742
743
744 if( $pingResult['success'] ) { // license valid + update
745
746 $update_plugins = get_site_transient( 'update_plugins' );
747 $wordpress_knows = false;
748 if( $update_plugins ) foreach( $update_plugins->response as $plugin_file => $response ) {
749 if( $plugin_file == static::PLUGIN_FILE )
750 $wordpress_knows = true;
751 }
752 if( !$wordpress_knows ) {
753 unset( $update_plugins->checked[static::PLUGIN_FILE] );
754 $update_plugins->response[static::PLUGIN_FILE] = $pingData;
755 set_transient( 'update_plugins', $update_plugins );
756 }
757 //plouf( $update_plugins);
758
759
760 ?>
761 <p><?php printf(
762 __('Please update the plugin on the <a href="%s">plugins page</a>', 'keypress-i18n' ),
763 admin_url( 'plugins.php' )
764 );?></p>
765
766
767 <?php
768
769 }
770 else { // license valid + noupdate ?>
771 <p><i class="dashicons dashicons-yes"></i><?php _e('Up to date','keypress-i18n' );?></p>
772 <?php
773 }
774 }
775 else {
776 // no license valid
777 if( isset( $pingData['license_error'] ) ) {
778 echo '<p class="notice notice-warning">' . $pingData['license_error'] . '</p>';
779 }
780 }
781
782
783 }
784 ?>
785
786
787 <?php
788 /*if( $license_status == 'activated' ) : ?>
789
790 <?php
791 $action_link = admin_url( static::PLUGIN_ADMIN_PAGE .'&action=deactivate_license');
792 $action_link = add_query_arg( '_wpnonce', wp_create_nonce( 'keypress_deactivate_license' ), $action_link );
793 $action_message = __('Désactiver la licence', 'keypress-i18n' );
794 $action_icon = '<i class="dashicons dashicons-no"></i>';
795 ?>
796 <p><?php printf('<a class="button" href="%s">%s %s</a>', $action_link, $action_icon, $action_message ); ?></p>
797 <?php elseif( $license_status == 'deactivated' || $license_status == 'salted') : ?>
798 <?php
799 $action_link = admin_url( static::PLUGIN_ADMIN_PAGE . '&action=reactivate_license');
800 $action_link = add_query_arg( '_wpnonce', wp_create_nonce( 'reactivate_license' ), $action_link );
801 $action_message = __('Réactiver la licence', 'keypress-i18n' );
802 $action_icon = '<i class="dashicons dashicons-yes"></i>';
803 ?>
804 <p><?php printf('<a class="button" href="%s">%s %s</a>', $action_link, $action_icon, $action_message ); ?></p>
805 <?php else : ?>
806 <p><?php _e('Merci d\'entrer une clef de license', 'keypress-i18n' ); ?></p>
807 <?php endif;
808 */
809 ?>
810 <?php
811 if( isset( $pingData ) && isset( $pingData['downloads_page'] ) ) {
812 $license_account_link = add_query_arg( array('product_sku' => static::PLUGIN_SKU ), $pingData['downloads_page'] );
813 printf(
814 __( '<p class="keypress_account">View your license(s) on <a href="%s" target="_blank">your account page</a></p>', 'keypress-i18n' ),
815 $license_account_link
816 );
817 }
818 ?>
819 <?php if( isset( $_GET['show'] ) ) printf('Last error: <pre>%s</pre>', get_option('keypress_last_error' ) ); ?>
820
821 <span class="small"><?php _e('Powered by KeyPress', 'keypress-i18n' ); ?></span>
822 </div>
823 <style type="text/css">
824 form#mainform {
825 position: relative;
826 }
827 #keypress<?php echo static::PLUGIN_SLUG; ?>_status {
828 position: absolute;
829 top: 4rem;
830 right: 1rem;
831 padding: 1rem;
832 border: 1px solid #c3c4c7;
833 background-color: #dcdcde;
834 color: #50575e;
835 }
836
837 div#keypress<?php echo static::PLUGIN_SLUG; ?>_status a i {
838 padding-top: .3rem;
839 }
840
841 input.keypress_key {
842 padding-left: 1.5rem;
843 }
844
845 p.license_action a {
846 margin-left: 1.5rem;
847 text-align: right;
848 vertical-align: sub;
849 }
850
851
852 </style>
853 <?php
854 }
855
856 }
857
858
859
860 }