PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.7.4
GiveWP – Donation Plugin and Fundraising Platform v2.7.4
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / class-give-license-handler.php
give / includes Last commit date
admin 5 years ago api 6 years ago database 6 years ago deprecated 6 years ago donors 5 years ago emails 6 years ago forms 6 years ago frontend 6 years ago gateways 6 years ago libraries 6 years ago payments 6 years ago actions.php 6 years ago ajax-functions.php 6 years ago class-give-async-process.php 6 years ago class-give-background-updater.php 6 years ago class-give-cache-setting.php 6 years ago class-give-cache.php 6 years ago class-give-cli-commands.php 6 years ago class-give-comment.php 6 years ago class-give-cron.php 6 years ago class-give-donate-form.php 6 years ago class-give-donor.php 6 years ago class-give-email-access.php 6 years ago class-give-license-handler.php 6 years ago class-give-logging.php 6 years ago class-give-readme-parser.php 6 years ago class-give-roles.php 6 years ago class-give-scripts.php 6 years ago class-give-session.php 6 years ago class-give-stats.php 6 years ago class-give-template-loader.php 6 years ago class-give-tooltips.php 6 years ago class-give-translation.php 6 years ago class-notices.php 6 years ago country-functions.php 6 years ago currencies-list.php 6 years ago currency-functions.php 6 years ago error-tracking.php 6 years ago filters.php 6 years ago formatting.php 6 years ago install.php 6 years ago login-register.php 6 years ago misc-functions.php 5 years ago plugin-compatibility.php 6 years ago post-types.php 6 years ago price-functions.php 6 years ago process-donation.php 6 years ago setting-functions.php 6 years ago shortcodes.php 6 years ago template-functions.php 6 years ago user-functions.php 6 years ago
class-give-license-handler.php
971 lines
1 <?php
2 /**
3 * Give License handler
4 *
5 * @package Give
6 * @subpackage Admin/License
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Give_License' ) ) :
18
19 /**
20 * Give_License Class
21 *
22 * This class simplifies the process of adding license information
23 * to new Give add-ons.
24 *
25 * @since 1.0
26 */
27 class Give_License {
28
29 /**
30 * File
31 *
32 * @access private
33 * @since 1.0
34 *
35 * @var string
36 */
37 private $file;
38
39 /**
40 * License
41 *
42 * @access private
43 * @since 1.0
44 *
45 * @var string
46 */
47 private $license;
48
49 /**
50 * Item name
51 *
52 * @access private
53 * @since 1.0
54 *
55 * @var string
56 */
57 private $item_name;
58
59 /**
60 * Item ID
61 *
62 * @access private
63 * @since 2.2.4
64 *
65 * @var int
66 */
67 private $item_id;
68
69 /**
70 * License Information object.
71 *
72 * @access private
73 * @since 1.7
74 *
75 * @var object
76 */
77 private $license_data;
78
79 /**
80 * Item shortname
81 *
82 * @access private
83 * @since 1.0
84 *
85 * @var string
86 */
87 private $item_shortname;
88
89 /**
90 * Version
91 *
92 * @access private
93 * @since 1.0
94 *
95 * @var string
96 */
97 private $version;
98
99 /**
100 * Author
101 *
102 * @access private
103 * @since 1.0
104 *
105 * @var string
106 */
107 private $author;
108
109 /**
110 * Plugin directory name
111 *
112 * @access private
113 * @since 2.5.0
114 *
115 * @var string
116 */
117 private $plugin_dirname;
118
119 /**
120 * Website URL
121 *
122 * @access private
123 * @since 1.0
124 *
125 * @var string
126 */
127 private static $site_url = 'https://givewp.com/';
128
129 /**
130 * API URL
131 *
132 * @access private
133 * @since 1.0
134 *
135 * @var string
136 */
137 private static $api_url = 'https://givewp.com/edd-sl-api/';
138
139 /**
140 * array of licensed addons
141 *
142 * @since 2.1.4
143 * @access private
144 *
145 * @var array
146 */
147 private static $licensed_addons = array();
148
149 /**
150 * Account URL
151 *
152 * @access private
153 * @since 1.7
154 *
155 * @var null|string
156 */
157 private static $account_url = 'https://givewp.com/my-account/';
158
159 /**
160 * Downloads URL
161 *
162 * @access private
163 * @since 2.5.0
164 *
165 * @var null|string
166 */
167 private static $downloads_url = 'https://givewp.com/my-downloads/';
168
169 /**
170 * Checkout URL
171 *
172 * @access private
173 * @since 1.7
174 *
175 * @var null|string
176 */
177 private static $checkout_url = 'https://givewp.com/checkout/';
178
179 /**
180 * Class Constructor
181 *
182 * Set up the Give License Class.
183 *
184 * @access public
185 *
186 * @param string $_file
187 * @param string $_item_name
188 * @param string $_version
189 * @param string $_author
190 * @param string $_optname
191 * @param string $_api_url
192 * @param string $_checkout_url
193 * @param string $_account_url
194 * @param int $_item_id
195 *
196 * @since 1.0
197 */
198 public function __construct(
199 $_file,
200 $_item_name,
201 $_version,
202 $_author,
203 $_optname = null,
204 $_api_url = null,
205 $_checkout_url = null,
206 $_account_url = null,
207 $_item_id = null
208 ) {
209
210 // Only load in wp-admin.
211 if ( ! is_admin() ) {
212 return;
213 }
214
215 if ( is_numeric( $_item_id ) ) {
216 $this->item_id = absint( $_item_id );
217 }
218
219 $this->file = $_file;
220 $this->item_name = $_item_name;
221 $this->plugin_dirname = dirname( plugin_basename( $this->file ) );
222 $this->item_shortname = self::get_short_name( $this->item_name );
223 $this->license_data = self::get_license_by_plugin_dirname( $this->plugin_dirname );
224 $this->version = $_version;
225 $this->license = ! empty( $this->license_data['license_key'] ) ? $this->license_data['license_key'] : '';
226 $this->author = $_author;
227 self::$api_url = is_null( $_api_url ) ? self::$api_url : $_api_url;
228 self::$checkout_url = is_null( $_checkout_url ) ? self::$checkout_url : $_checkout_url;
229 self::$account_url = is_null( $_account_url ) ? self::$account_url : $_account_url;
230 $this->auto_updater_obj = null;
231
232 // Add plugin to registered licenses list.
233 array_push( self::$licensed_addons, plugin_basename( $this->file ) );
234 }
235
236
237 /**
238 * Get plugin shortname
239 *
240 * @param $plugin_name
241 *
242 * @return string
243 * @since 2.1.0
244 * @access public
245 */
246 public static function get_short_name( $plugin_name ) {
247 $plugin_name = trim( str_replace( 'Give - ', '', $plugin_name ) );
248 $plugin_name = 'give_' . preg_replace( '/[^a-zA-Z0-9_\s]/', '', str_replace( ' ', '_', strtolower( $plugin_name ) ) );
249
250 return $plugin_name;
251 }
252
253 /**
254 * Activate License
255 *
256 * Activate the license key.
257 *
258 * @access public
259 * @return void
260 * @since 1.0
261 */
262 public function activate_license() {
263 }
264
265 /**
266 * Deactivate License
267 *
268 * Deactivate the license key.
269 *
270 * @access public
271 * @return void
272 * @since 1.0
273 */
274 public function deactivate_license() {
275 }
276
277
278 /**
279 * Get license information.
280 *
281 * @param string $edd_action
282 * @param bool $response_in_array
283 *
284 * @return mixed
285 * @deprecated 2.5.0 Use self::request_license_api instead.
286 *
287 * @since 1.8.9
288 * @access public
289 */
290 public function get_license_info( $edd_action = '', $response_in_array = false ) {
291
292 if ( empty( $edd_action ) ) {
293 return false;
294 }
295
296 give_doing_it_wrong( __FUNCTION__, 'Use self::request_license_api instead from GiveWP 2.5.0' );
297
298 // Data to send to the API.
299 $api_params = array(
300 'edd_action' => $edd_action, // never change from "edd_" to "give_"!
301 'license' => $this->license,
302 'item_name' => urlencode( $this->item_name ),
303 );
304
305 return self::request_license_api( $api_params, $response_in_array );
306 }
307
308 /**
309 * Return licensed addons info
310 *
311 * Note: note only for internal logic
312 *
313 * @return array
314 * @since 2.1.4
315 */
316 static function get_licensed_addons() {
317 return self::$licensed_addons;
318 }
319
320
321 /**
322 * Check if license key attached to subscription
323 *
324 * @param string $license_key
325 *
326 * @return array
327 * @since 2.5.0
328 */
329 static function is_subscription( $license_key = '' ) {
330 // Check if current license is part of subscription or not.
331 $subscriptions = get_option( 'give_subscriptions' );
332 $subscription = array();
333
334 if ( $subscriptions ) {
335 foreach ( $subscriptions as $subs ) {
336 if ( in_array( $license_key, $subs['licenses'] ) ) {
337 $subscription = $subs;
338 break;
339 }
340 }
341 }
342
343 return $subscription;
344 }
345
346 /**
347 * Get license information.
348 *
349 * @param array $api_params
350 * @param bool $response_in_array
351 *
352 * @return array|WP_Error
353 * @since 1.8.9
354 * @access public
355 */
356 public static function request_license_api( $api_params = array(), $response_in_array = false ) {
357 // Bailout.
358 if ( empty( $api_params['edd_action'] ) ) {
359 return new WP_Error( 'give-invalid-edd-action', __( 'Valid edd_action not defined', 'give' ) );
360 }
361
362 // Data to send to the API.
363 $default_api_params = array(
364 // 'edd_action' => $edd_action, never change from "edd_" to "give_"!
365 // 'license' => $this->license,
366 // 'item_name' => urlencode( $this->item_name ),
367 'url' => home_url(),
368 );
369
370 $api_params = wp_parse_args( $api_params, $default_api_params );
371
372 // Call the API.
373 $response = wp_remote_post(
374 self::$api_url,
375 apply_filters(
376 'give_request_license_api_args',
377 array(
378 'timeout' => 15,
379 'sslverify' => false,
380 'body' => $api_params,
381 )
382 )
383 );
384
385 // Make sure there are no errors.
386 if ( is_wp_error( $response ) ) {
387 return $response;
388 }
389
390 return json_decode( wp_remote_retrieve_body( $response ), $response_in_array );
391 }
392
393 /**
394 * Get license by plugin dirname
395 *
396 * @param string $plugin_dirname
397 *
398 * @return array
399 *
400 * @since 2.5.0
401 * @access public
402 */
403 public static function get_license_by_plugin_dirname( $plugin_dirname ) {
404 $license = array();
405 $give_licenses = get_option( 'give_licenses', array() );
406
407 if ( ! empty( $give_licenses ) ) {
408 foreach ( $give_licenses as $give_license ) {
409
410 // Logic to match all access pass license to add-on.
411 $compares = $give_license['is_all_access_pass']
412 ? $give_license['download']
413
414 // Prevent PHP notice if somehow automatic update does not run properly.
415 // Because plugin_slug will only define in updated license rest api response.
416 : array( array( 'plugin_slug' => ! empty( $give_license['plugin_slug'] ) ? $give_license['plugin_slug'] : '' ) );
417
418 foreach ( $compares as $compare ) {
419 if ( ! empty( $compare['plugin_slug'] ) && $plugin_dirname === $compare['plugin_slug'] ) {
420 $license = $give_license;
421 break;
422 }
423 }
424 }
425 }
426
427 return $license;
428 }
429
430
431 /**
432 * Get checkout url
433 *
434 * @return string|null
435 * @since 2.5.0
436 */
437 public static function get_checkout_url() {
438 return self::$checkout_url;
439 }
440
441 /**
442 * Get account url
443 *
444 * @return string|null
445 * @since 2.5.0
446 */
447 public static function get_account_url() {
448 return self::$account_url;
449 }
450
451 /**
452 * Get downloads url
453 *
454 * @return string|null
455 * @since 2.5.0
456 */
457 public static function get_downloads_url() {
458 return self::$downloads_url;
459 }
460
461 /**
462 * Get account url
463 *
464 * @return string|null
465 * @since 2.5.0
466 */
467 public static function get_website_url() {
468 return self::$site_url;
469 }
470
471
472 /**
473 * Get plugin information by id.
474 * Note: only for internal use
475 *
476 * @param string $plugin_slug
477 *
478 * @return array
479 * @since 2.5.0
480 */
481 public static function get_plugin_by_slug( $plugin_slug ) {
482 $give_plugins = give_get_plugins();
483 $matching_list = wp_list_pluck( $give_plugins, 'Dir', 'Path' );
484 $is_match_found = array_search( $plugin_slug, $matching_list, true );
485
486 return $is_match_found ? $give_plugins[ $is_match_found ] : array();
487 }
488
489 /**
490 * Get plugin information by id.
491 * Note: only for internal use
492 *
493 * @param string $plugin_slug
494 *
495 * @return string
496 * @since 2.5.0
497 */
498 public static function build_plugin_name_from_slug( $plugin_slug ) {
499 $plugin_name = str_replace( array( '-', 'give ' ), array( ' ', 'Give - ' ), $plugin_slug );
500
501 return ucwords( $plugin_name );
502 }
503
504 /**
505 * Render license section
506 *
507 * @return string
508 * @since 2.5.0
509 */
510 public static function render_licenses_list() {
511 $give_plugins = give_get_plugins( array( 'only_premium_add_ons' => true ) );
512 $give_licenses = get_option( 'give_licenses', array() );
513 $licenses_without_addon = $give_licenses;
514
515 // Get all access pass licenses
516 $all_access_pass_licenses = array();
517 $all_access_pass_addon_list = array();
518 foreach ( $give_licenses as $key => $give_license ) {
519 if ( $give_license['is_all_access_pass'] ) {
520 $all_access_pass_licenses[ $key ] = $give_license;
521
522 unset( $licenses_without_addon[ $key ] );
523
524 foreach ( $give_license['download'] as $download ) {
525 $all_access_pass_addon_list[] = $download['plugin_slug'];
526 }
527 }
528 }
529
530 $html = array(
531 'unlicensed' => '',
532 'licensed' => '',
533 'licenses_without_addon' => '',
534 'all_access_licensed' => '',
535 );
536
537 if ( ! empty( $give_plugins ) ) {
538 foreach ( $give_plugins as $give_plugin ) {
539 if ( in_array( $give_plugin['Dir'], $all_access_pass_addon_list ) ) {
540 continue;
541 }
542
543 $addon_license = self::get_license_by_plugin_dirname( $give_plugin['Dir'] );
544 $html_arr_key = 'unlicensed';
545
546 if ( $addon_license ) {
547 $html_arr_key = 'licensed';
548 unset( $licenses_without_addon[ $addon_license['license_key'] ] );
549 }
550
551 $html[ "{$html_arr_key}" ] .= self::html_by_plugin( $give_plugin );
552 }
553 }
554
555 if ( ! empty( $all_access_pass_licenses ) ) {
556 foreach ( $all_access_pass_licenses as $key => $all_access_pass_license ) {
557 $html['all_access_licensed'] .= self::html_by_license( $all_access_pass_license );
558 }
559 }
560
561 if ( ! empty( $licenses_without_addon ) ) {
562 foreach ( $licenses_without_addon as $key => $license ) {
563 if ( in_array( $license['plugin_slug'], $all_access_pass_addon_list ) ) {
564 continue;
565 }
566 $html['licenses_without_addon'] .= self::html_by_license( $license );
567 }
568 }
569
570 ksort( $html );
571
572 // After sorting order will be all_access_licensed -> licensed -> unlicensed
573
574 return implode( '', $html );
575 }
576
577 /**
578 * Get add-on item html
579 * Note: only for internal use
580 *
581 * @param $plugin
582 *
583 * @return string
584 * @since 2.5.0
585 */
586 public static function html_by_plugin( $plugin ) {
587 // Bailout.
588 if ( empty( $plugin ) ) {
589 return '';
590 }
591
592 ob_start();
593 $license = self::get_license_by_plugin_dirname( $plugin['Dir'] );
594
595 $default_plugin = array(
596 'ChangeLogSlug' => $plugin['Dir'],
597 'DownloadURL' => '',
598 );
599
600 if ( false !== strpos( $default_plugin['ChangeLogSlug'], '-gateway' ) ) {
601 // We found that each gateway addon does not have `-gateway` in changelog file slug
602 $default_plugin['ChangeLogSlug'] = str_replace( '-gateway', '', $default_plugin['ChangeLogSlug'] );
603 }
604
605 if ( $license ) {
606 $license['renew_url'] = self::$checkout_url . "?edd_license_key={$license['license_key']}";
607 $default_plugin['ChangeLogSlug'] = $license['readme'];
608 $default_plugin['DownloadURL'] = $license['download'];
609 }
610
611 $plugin['License'] = $license = wp_parse_args(
612 $license,
613 array(
614 'item_name' => str_replace( 'give-', '', $plugin['Dir'] ),
615 'purchase_link' => $plugin['PluginURI'],
616 )
617 );
618
619 $plugin = wp_parse_args( $plugin, $default_plugin );
620 ?>
621 <div class="give-addon-wrap">
622 <div class="give-addon-inner">
623 <?php echo self::html_license_row( $license, $plugin ); ?>
624 <?php echo self::html_plugin_row( $plugin ); ?>
625 </div>
626 </div>
627 <?php
628
629 return ob_get_clean();
630 }
631
632 /**
633 * Get add-on item html
634 * Note: only for internal use
635 *
636 * @param array $license
637 *
638 * @return string
639 * @since 2.5.0
640 */
641 private static function html_by_license( $license ) {
642 ob_start();
643
644 $license['renew_url'] = self::$checkout_url . "?edd_license_key={$license['license_key']}";
645 ?>
646 <div class="give-addon-wrap">
647 <div class="give-addon-inner">
648 <?php
649 echo self::html_license_row( $license );
650
651 $addons = $license['download'];
652
653 if ( empty( $license['is_all_access_pass'] ) ) {
654 $addons = array( $license );
655 }
656
657 foreach ( $addons as $addon ) {
658 $default_plugin = array(
659 // In single license key we will get item_name instead of name.
660 'Name' => ! empty( $addon['item_name'] ) ? $addon['item_name'] : $addon['name'],
661
662 'ChangeLogSlug' => $addon['readme'],
663 'Version' => $addon['current_version'],
664 'Status' => 'not installed',
665
666 // In single license key we will get download instead of file.
667 'DownloadURL' => ! empty( $addon['download'] ) ? $addon['download'] : $addon['file'],
668
669 );
670
671 $plugin = wp_parse_args(
672 self::get_plugin_by_slug( $addon['plugin_slug'] ),
673 $default_plugin
674 );
675
676 $plugin['Name'] = false !== strpos( $plugin['Name'], 'Give' )
677 ? $plugin['Name']
678 : self::build_plugin_name_from_slug( $addon['plugin_slug'] );
679
680 $plugin['License'] = $license;
681
682 echo self::html_plugin_row( $plugin );
683 }
684 ?>
685 </div>
686 </div>
687 <?php
688
689 return ob_get_clean();
690 }
691
692
693 /**
694 * license row html
695 *
696 * @param array $license
697 * @param array $plugin
698 *
699 * @return string
700 * @since 2.5.0
701 */
702 private static function html_license_row( $license, $plugin = array() ) {
703 ob_start();
704
705 $is_license = $license && ! empty( $license['license_key'] );
706 $license_key = $is_license ? $license['license_key'] : '';
707 $license_is_inactive = $license_key && ! in_array( $license['license'], array( 'valid', 'expired' ) );
708 $expires_timestamp = $is_license ? strtotime( $license['expires'] ) : '';
709 $is_license_expired = $is_license && ( 'expired' === $license['license'] || $expires_timestamp < time() );
710 $addon_dir = ! empty( $plugin['Dir'] ) ? $plugin['Dir'] : ( ! empty( $license['plugin_slug'] ) ? $license['plugin_slug'] : '' );
711 ?>
712 <div class="give-license-row give-clearfix">
713 <div class="give-license-notice-container"></div>
714 <div class="give-license-top give-clearfix">
715
716 <div class="give-license-top-column give-license-key-field-wrap">
717
718 <div class="give-license__key<?php echo $license_key ? ' give-has-license-key' : ''; ?>">
719 <?php $value = $license_key ? give_hide_char( $license['license_key'], 5 ) : ''; ?>
720 <label for="give-license-addon-key-field" class="give-license-top-header"><?php _e( 'License Key', 'give' ); ?></label>
721 <input id="give-license-addon-key-field" type="text" autocomplete="off" value="<?php echo $value; ?>"<?php echo $value ? ' readonly' : ''; ?>>
722 <?php if ( ! $license_key ) : ?>
723 <button class="give-button__license-activate button-primary" data-addon="<?php echo $addon_dir; ?>">
724 <?php _e( 'Activate', 'give' ); ?>
725 </button>
726 <?php elseif ( $license_is_inactive ) : ?>
727 <button class="give-button__license-reactivate button-primary" data-addon="<?php echo $addon_dir; ?>" data-license="<?php echo $license['license_key']; ?>">
728 <?php _e( 'Reactivate', 'give' ); ?>
729 </button>
730 <?php else : ?>
731
732 <?php
733 echo sprintf(
734 '<button class="give-license__deactivate button button-secondary" data-license-key="%2$s" data-item-name="%3$s" data-plugin-dirname="%5$s" data-nonce="%4$s">%1$s</button>',
735 __( 'Deactivate', 'give' ),
736 $license['license_key'],
737 $license['item_name'],
738 wp_create_nonce( "give-deactivate-license-{$license['item_name']}" ),
739 ! empty( $license['plugin_slug'] ) ? $license['plugin_slug'] : ''
740 );
741 ?>
742
743 <?php endif; ?>
744
745 <div class="give-license__status">
746 <?php
747 echo $license_key && ! $license_is_inactive
748 ? sprintf(
749 '<span class="dashicons dashicons-%2$s"></span>&nbsp;%1$s',
750 $is_license_expired
751 ? __( 'License is expired. Please activate your license key.', 'give' )
752 : __( 'License is active and you are receiving updates and support.', 'give' ),
753 $is_license_expired
754 ? 'no'
755 : 'yes'
756 )
757 : sprintf(
758 '<span class="dashicons dashicons-no"></span> %1$s %2$s',
759 __( 'License is inactive.', 'give' ),
760 $license_is_inactive
761 ? sprintf(
762 __( 'Please <a href="%1$s" target="_blank">Visit your dashboard</a> to check this license details and activate this license to receive updates and support.', 'give' ),
763 self::get_account_url()
764 )
765 : __( 'Please activate your license key.', 'give' )
766 );
767 ?>
768 </div>
769 </div>
770 </div>
771
772 <div class="give-license-top-column give-license-info-field-wrap">
773 <h3 class="give-license-top-header"><?php _e( 'License Information', 'give' ); ?></h3>
774 <?php
775 // @todo: handle all license status;
776 if ( $license_key ) :
777 ?>
778
779 <?php if ( $license_key ) : ?>
780 <?php
781 echo sprintf(
782 '<p class="give-license-renewal-date"><span class="dashicons dashicons-calendar-alt"></span> <strong>%1$s</strong> %2$s</p>',
783 $is_license_expired ? __( 'Expired:', 'give' ) : __( 'Renews:', 'give' ),
784 date( give_date_format(), $expires_timestamp )
785 );
786 ?>
787 <?php endif; ?>
788
789 <?php
790 if ( $is_license_expired ) {
791 // @todo: need to test renew license link
792 echo sprintf(
793 '<a href="%1$s" target="_blank">%2$s</a>',
794 $license['renew_url'],
795 __( 'Renew to manage sites', 'give' )
796 );
797 } elseif ( $license_key ) {
798 if ( ! $license['activations_left'] ) {
799 echo sprintf(
800 '<span class="give-license-activations-left">%1$s</span>',
801 __( 'No activations remaining', 'give' )
802 );
803 } else {
804 echo sprintf(
805 '<span class="give-license-activations-left"><span class="give-license-activations-remaining-icon wp-ui-highlight">%1$s</span> %2$s</span>',
806 $license['activations_left'],
807 _n( 'Activation Remaining', 'Activations Remaining', $license['activations_left'], 'give' )
808 );
809 }
810 }
811 ?>
812 <?php else : ?>
813
814 <p class="give-field-description"><?php _e( 'This is an unlicensed add-on and is not receiving updates or support. Please activate your license key to fix the issue.', 'give' ); ?></p>
815
816 <?php endif; ?>
817 </div>
818
819 <div class="give-license-top-column">
820 <h3 class="give-license-top-header"><?php _e( 'License Actions', 'give' ); ?></h3>
821
822 <?php
823 // Purchase license link.
824 if ( ! $license_key ) :
825 ?>
826 <?php
827 echo sprintf(
828 '<a class="give-button button-secondary" href="%1$s" target="_blank">%2$s</a>',
829 $license['purchase_link'],
830 __( 'Purchase License', 'give' )
831 );
832 ?>
833 <?php endif; ?>
834
835 <?php
836 // Manage license link on GiveWP.com
837 if ( ! $is_license_expired && $license_key ) {
838 echo sprintf(
839 '<a href="%1$spurchase-history/?license_id=%2$s&action=manage_licenses&payment_id=%3$s" target="_blank" class="give-license-action-link">%4$s</a>',
840 trailingslashit( self::get_website_url() ),
841 $license['license_id'],
842 $license['payment_id'],
843 __( 'Manage License', 'give' )
844 );
845 echo sprintf(
846 '<a href="%1$spriority-support/" target="_blank" class="give-license-action-link">%2$s</a>',
847 trailingslashit( self::get_website_url() ),
848 __( 'Access Support', 'give' )
849 );
850 }
851 ?>
852
853 </div>
854 </div>
855 </div>
856 <?php
857 return ob_get_clean();
858 }
859
860
861 /**
862 * Plugin row html
863 *
864 * @param array $plugin
865 *
866 * @return string
867 * @since 2.5.0
868 */
869 public static function html_plugin_row( $plugin ) {
870 // Bailout.
871 if ( ! $plugin ) {
872 return '';
873 }
874
875 $is_license = $plugin['License'] && ! empty( $plugin['License']['license_key'] );
876 $expires_timestamp = $is_license ? strtotime( $plugin['License']['expires'] ) : '';
877 $is_license_expired = $is_license && ( 'expired' === $plugin['License']['license'] || $expires_timestamp < time() );
878 ob_start();
879 ?>
880 <div class="give-addon-info-wrap give-clearfix">
881
882 <div class="give-addon-info-left">
883 <span class="give-addon-name">
884 <?php echo $plugin['Name']; ?>
885 </span>
886 <span class="give-addon-version">
887 <?php echo sprintf( '%1$s %2$s', __( 'Version', 'give' ), $plugin['Version'] ); ?>
888 </span>
889 </div>
890
891 <div class="give-addon-info-right">
892 <?php
893 echo sprintf(
894 '<a href="%1$s" class="give-ajax-modal give-addon-view-changelog" title="%3$s">%2$s</a>',
895 give_modal_ajax_url(
896 array(
897 'url' => filter_var( $plugin['ChangeLogSlug'], FILTER_VALIDATE_URL )
898 ? urldecode_deep( $plugin['ChangeLogSlug'] )
899 : urlencode_deep( give_get_addon_readme_url( $plugin['ChangeLogSlug'] ) ),
900 'show_changelog' => 1,
901 )
902 ),
903 __( 'View Changelog', 'give' ),
904 __( 'Changelog of', 'give' ) . " {$plugin['Name']}"
905 );
906 ?>
907
908 <?php
909 // Activation status.
910 if ( in_array( $plugin['Status'], array( 'active', 'inactive' ) ) ) {
911 echo sprintf(
912 '<span class="give-addon-activation-status give-addon-activation-status__%1$s">%1$s</span>',
913 'active' === $plugin['Status'] ? __( 'activated', 'give' ) : __( 'installed', 'give' )
914 );
915 }
916
917 printf(
918 '<%3$s class="give-button button button-secondary button-small" href="%1$s"%4$s><span class="dashicons dashicons-download"></span>%2$s</%3$s>',
919 $plugin['DownloadURL'],
920 __( 'Download', 'give' ),
921 $is_license_expired || ! $plugin['DownloadURL'] ? 'button' : 'a',
922 $is_license_expired || ! $plugin['DownloadURL'] ? ' disabled' : ''
923 );
924 ?>
925 </div>
926 </div>
927 <?php
928
929 return ob_get_clean();
930 }
931
932
933 /**
934 * Get refresh license status
935 *
936 * @return mixed|void
937 * @since 2.5.0
938 */
939 public static function refresh_license_status() {
940 return get_option(
941 'give_licenses_refreshed_last_checked',
942 array(
943 'compare' => date( 'Ymd' ),
944 'time' => time(),
945 'count' => 0,
946 )
947 );
948 }
949
950 /**
951 * Get all download slugs from all access pass key.
952 * Note: only for internal use and will be refactored in the future.
953 *
954 * @param array $license All access pass license data
955 *
956 * @return string[]
957 * @since 2.6.3
958 */
959 public static function getAddonSlugsFromAllAccessPassLicense( $license ) {
960 $result = [];
961
962 foreach ( $license['download'] as $download ) {
963 $result[] = $download['plugin_slug'];
964 }
965
966 return $result;
967 }
968 }
969
970 endif; // end class_exists check.
971