impress-org /
give
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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, |
||
|
0 ignored issues
–
show
|
|||
| 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 ); |
||
|
0 ignored issues
–
show
It seems like
self::get_license_by_plu...($this->plugin_dirname) of type array is incompatible with the declared type object of property $license_data.
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. Loading history...
|
|||
| 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', '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() { |
||
|
0 ignored issues
–
show
|
|||
| 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 = '' ) { |
||
|
0 ignored issues
–
show
|
|||
| 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 | |||
| 516 | // Get all access pass licenses |
||
| 517 | $all_access_pass_licenses = array(); |
||
| 518 | $all_access_pass_addon_list = array(); |
||
| 519 | foreach ( $give_licenses as $key => $give_license ) { |
||
| 520 | if ( $give_license['is_all_access_pass'] ) { |
||
| 521 | $all_access_pass_licenses[ $key ] = $give_license; |
||
| 522 | |||
| 523 | unset( $licenses_without_addon[$key] ); |
||
| 524 | |||
| 525 | foreach ( $give_license['download'] as $download ) { |
||
| 526 | $all_access_pass_addon_list[] = $download['plugin_slug']; |
||
| 527 | } |
||
| 528 | } |
||
| 529 | } |
||
| 530 | |||
| 531 | $html = array( |
||
| 532 | 'unlicensed' => '', |
||
| 533 | 'licensed' => '', |
||
| 534 | 'licenses_without_addon' => '', |
||
| 535 | 'all_access_licensed' => '', |
||
| 536 | ); |
||
| 537 | |||
| 538 | if( ! empty( $give_plugins ) ) { |
||
| 539 | foreach ( $give_plugins as $give_plugin ) { |
||
| 540 | if ( in_array( $give_plugin['Dir'], $all_access_pass_addon_list ) ) { |
||
| 541 | continue; |
||
| 542 | } |
||
| 543 | |||
| 544 | $addon_license = self::get_license_by_plugin_dirname( $give_plugin['Dir'] ); |
||
| 545 | $html_arr_key = 'unlicensed'; |
||
| 546 | |||
| 547 | if ( $addon_license ) { |
||
|
0 ignored issues
–
show
The expression
$addon_license of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 548 | $html_arr_key = 'licensed'; |
||
| 549 | unset( $licenses_without_addon[$addon_license['license_key']] ); |
||
| 550 | } |
||
| 551 | |||
| 552 | $html["{$html_arr_key}"] .= self::html_by_plugin( $give_plugin ); |
||
| 553 | } |
||
| 554 | } |
||
| 555 | |||
| 556 | if ( ! empty( $all_access_pass_licenses ) ) { |
||
| 557 | foreach ( $all_access_pass_licenses as $key => $all_access_pass_license ) { |
||
| 558 | $html['all_access_licensed'] .= self::html_by_license( $all_access_pass_license ); |
||
| 559 | } |
||
| 560 | } |
||
| 561 | |||
| 562 | if ( ! empty( $licenses_without_addon ) ) { |
||
| 563 | foreach ( $licenses_without_addon as $key => $license ) { |
||
| 564 | if ( in_array( $license['plugin_slug'], $all_access_pass_addon_list ) ) { |
||
| 565 | continue; |
||
| 566 | } |
||
| 567 | $html['licenses_without_addon'] .= self::html_by_license( $license ); |
||
| 568 | } |
||
| 569 | } |
||
| 570 | |||
| 571 | ksort( $html ); |
||
| 572 | |||
| 573 | // After sorting order will be all_access_licensed -> licensed -> unlicensed |
||
| 574 | |||
| 575 | return implode( '', $html ); |
||
| 576 | } |
||
| 577 | |||
| 578 | /** |
||
| 579 | * Get add-on item html |
||
| 580 | * Note: only for internal use |
||
| 581 | * |
||
| 582 | * @param $plugin |
||
| 583 | * |
||
| 584 | * @return string |
||
| 585 | * @since 2.5.0 |
||
| 586 | */ |
||
| 587 | public static function html_by_plugin( $plugin ) { |
||
| 588 | // Bailout. |
||
| 589 | if ( empty( $plugin ) ) { |
||
| 590 | return ''; |
||
| 591 | } |
||
| 592 | |||
| 593 | ob_start(); |
||
| 594 | $license = self::get_license_by_plugin_dirname( $plugin['Dir'] ); |
||
| 595 | |||
| 596 | $default_plugin = array( |
||
| 597 | 'ChangeLogSlug' => $plugin['Dir'], |
||
| 598 | 'DownloadURL' => '', |
||
| 599 | ); |
||
| 600 | |||
| 601 | if ( false !== strpos( $default_plugin['ChangeLogSlug'], '-gateway' ) ) { |
||
| 602 | // We found that each gateway addon does not have `-gateway` in changelog file slug |
||
| 603 | $default_plugin['ChangeLogSlug'] = str_replace( '-gateway', '', $default_plugin['ChangeLogSlug'] ); |
||
| 604 | } |
||
| 605 | |||
| 606 | if ( $license ) { |
||
|
0 ignored issues
–
show
The expression
$license of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 607 | $license['renew_url'] = self::$checkout_url . "?edd_license_key={$license['license_key']}"; |
||
| 608 | $default_plugin['ChangeLogSlug'] = $license['readme']; |
||
| 609 | $default_plugin['DownloadURL'] = $license['download']; |
||
| 610 | } |
||
| 611 | |||
| 612 | $plugin['License'] = $license = wp_parse_args( |
||
| 613 | $license, 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'] ); |
||
|
0 ignored issues
–
show
The expression
$license of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 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 < current_time( 'timestamp', 1 ) ); |
||
| 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 | <?php endif; ?> |
||
| 743 | |||
| 744 | <div class="give-license__status"> |
||
| 745 | <?php |
||
| 746 | echo $license_key && ! $license_is_inactive |
||
| 747 | ? sprintf( |
||
| 748 | '<span class="dashicons dashicons-%2$s"></span> %1$s', |
||
| 749 | $is_license_expired |
||
| 750 | ? __( 'License is expired. Please activate your license key.', 'give' ) |
||
| 751 | : __( 'License is active and you are receiving updates and support.', 'give' ), |
||
| 752 | $is_license_expired |
||
| 753 | ? 'no' |
||
| 754 | : 'yes' |
||
| 755 | ) |
||
| 756 | : sprintf( |
||
| 757 | '<span class="dashicons dashicons-no"></span> %1$s %2$s', |
||
| 758 | __( 'License is inactive.', 'give' ), |
||
| 759 | $license_is_inactive |
||
| 760 | ? sprintf( |
||
| 761 | __( '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' ), |
||
| 762 | self::get_account_url() |
||
| 763 | ) |
||
| 764 | : __( 'Please activate your license key.', 'give' ) |
||
| 765 | ); |
||
| 766 | ?> |
||
| 767 | </div> |
||
| 768 | </div> |
||
| 769 | </div> |
||
| 770 | |||
| 771 | <div class="give-license-top-column give-license-info-field-wrap"> |
||
| 772 | <h3 class="give-license-top-header"><?php _e( 'License Information', 'give' ); ?></h3> |
||
| 773 | <?php |
||
| 774 | // @todo: handle all license status; |
||
| 775 | if ( $license_key ) : ?> |
||
| 776 | |||
| 777 | <?php if ( $license_key ) : ?> |
||
| 778 | <?php |
||
| 779 | echo sprintf( |
||
| 780 | '<p class="give-license-renewal-date"><span class="dashicons dashicons-calendar-alt"></span> <strong>%1$s</strong> %2$s</p>', |
||
| 781 | $is_license_expired ? __( 'Expired:' ) : __( 'Renews:' ), |
||
| 782 | date( give_date_format(), $expires_timestamp ) |
||
| 783 | ); |
||
| 784 | ?> |
||
| 785 | <?php endif; ?> |
||
| 786 | |||
| 787 | <?php if ( $is_license_expired ) { |
||
| 788 | // @todo: need to test renew license link |
||
| 789 | echo sprintf( |
||
| 790 | '<a href="%1$s" target="_blank">%2$s</a>', |
||
| 791 | $license['renew_url'], |
||
| 792 | __( 'Renew to manage sites', 'give' ) |
||
| 793 | ); |
||
| 794 | } elseif ( $license_key ) { |
||
| 795 | if ( ! $license['activations_left'] ) { |
||
| 796 | echo sprintf( |
||
| 797 | '<span class="give-license-activations-left">%1$s</span>', |
||
| 798 | __( 'No activation remaining', 'give' ) |
||
| 799 | ); |
||
| 800 | } else { |
||
| 801 | echo sprintf( |
||
| 802 | '<span class="give-license-activations-left"><span class="give-license-activations-remaining-icon wp-ui-highlight">%1$s</span> %2$s</span>', |
||
| 803 | $license['activations_left'], |
||
| 804 | _n( 'Activation Remaining', 'Activations Remaining', $license['activations_left'], 'give' ) |
||
| 805 | ); |
||
| 806 | } |
||
| 807 | } ?> |
||
| 808 | <?php else : ?> |
||
| 809 | |||
| 810 | <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> |
||
| 811 | |||
| 812 | <?php endif; ?> |
||
| 813 | </div> |
||
| 814 | |||
| 815 | <div class="give-license-top-column"> |
||
| 816 | <h3 class="give-license-top-header"><?php _e( 'License Actions', 'give' ); ?></h3> |
||
| 817 | |||
| 818 | <?php |
||
| 819 | // Purchase license link. |
||
| 820 | if ( ! $license_key ) : ?> |
||
| 821 | <?php |
||
| 822 | echo sprintf( |
||
| 823 | '<a class="give-button button-secondary" href="%1$s" target="_blank">%2$s</a>', |
||
| 824 | $license['purchase_link'], |
||
| 825 | __( 'Purchase License', 'give' ) |
||
| 826 | ); |
||
| 827 | ?> |
||
| 828 | <?php endif; ?> |
||
| 829 | |||
| 830 | <?php |
||
| 831 | // Manage license link on GiveWP.com |
||
| 832 | if ( ! $is_license_expired && $license_key ) { |
||
| 833 | echo sprintf( |
||
| 834 | '<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>', |
||
| 835 | trailingslashit( Give_License::get_website_url() ), |
||
| 836 | $license['license_id'], |
||
| 837 | $license['payment_id'], |
||
| 838 | __( 'Manage License', 'give' ) |
||
| 839 | ); |
||
| 840 | echo sprintf( |
||
| 841 | '<a href="%1$spriority-support/" target="_blank" class="give-license-action-link">%2$s</a>', |
||
| 842 | trailingslashit( Give_License::get_website_url() ), |
||
| 843 | __( 'Access Support', 'give' ) |
||
| 844 | ); |
||
| 845 | } |
||
| 846 | ?> |
||
| 847 | |||
| 848 | </div> |
||
| 849 | </div> |
||
| 850 | </div> |
||
| 851 | <?php |
||
| 852 | return ob_get_clean(); |
||
| 853 | } |
||
| 854 | |||
| 855 | |||
| 856 | /** |
||
| 857 | * Plugin row html |
||
| 858 | * |
||
| 859 | * @param array $plugin |
||
| 860 | * |
||
| 861 | * @return string |
||
| 862 | * @since 2.5.0 |
||
| 863 | */ |
||
| 864 | public static function html_plugin_row( $plugin ) { |
||
| 865 | // Bailout. |
||
| 866 | if ( ! $plugin ) { |
||
|
0 ignored issues
–
show
The expression
$plugin of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 867 | return ''; |
||
| 868 | } |
||
| 869 | |||
| 870 | $is_license = $plugin['License'] && ! empty( $plugin['License']['license_key'] ); |
||
| 871 | $expires_timestamp = $is_license ? strtotime( $plugin['License']['expires'] ) : ''; |
||
| 872 | $is_license_expired = $is_license && ( 'expired' === $plugin['License']['license'] || $expires_timestamp < current_time( 'timestamp', 1 ) ); |
||
| 873 | ob_start(); |
||
| 874 | ?> |
||
| 875 | <div class="give-addon-info-wrap give-clearfix"> |
||
| 876 | |||
| 877 | <div class="give-addon-info-left"> |
||
| 878 | <span class="give-addon-name"> |
||
| 879 | <?php echo $plugin['Name']; ?> |
||
| 880 | </span> |
||
| 881 | <span class="give-addon-version"> |
||
| 882 | <?php echo sprintf( '%1$s %2$s', __( 'Version' ), $plugin['Version'] ); ?> |
||
| 883 | </span> |
||
| 884 | </div> |
||
| 885 | |||
| 886 | <div class="give-addon-info-right"> |
||
| 887 | <?php |
||
| 888 | echo sprintf( |
||
| 889 | '<a href="%1$s" class="give-ajax-modal give-addon-view-changelog" title="%3$s">%2$s</a>', |
||
| 890 | give_modal_ajax_url( |
||
| 891 | array( |
||
| 892 | 'url' => filter_var( $plugin['ChangeLogSlug'], FILTER_VALIDATE_URL ) |
||
| 893 | ? urldecode_deep( $plugin['ChangeLogSlug'] ) |
||
| 894 | : urlencode_deep( give_get_addon_readme_url( $plugin['ChangeLogSlug'] ) ), |
||
| 895 | 'show_changelog' => 1, |
||
| 896 | ) |
||
| 897 | ), |
||
| 898 | __( 'View Changelog', 'give' ), |
||
| 899 | __( 'Changelog of' ) . " {$plugin['Name']}" |
||
| 900 | ); |
||
| 901 | ?> |
||
| 902 | |||
| 903 | <?php |
||
| 904 | // Activation status. |
||
| 905 | if ( in_array( $plugin['Status'], array( 'active', 'inactive' ) ) ) { |
||
| 906 | echo sprintf( |
||
| 907 | '<span class="give-addon-activation-status give-addon-activation-status__%1$s">%1$s</span>', |
||
| 908 | 'active' === $plugin['Status'] ? __( 'activated', 'give' ) : __( 'installed', 'give' ) |
||
| 909 | ); |
||
| 910 | } |
||
| 911 | |||
| 912 | printf( |
||
| 913 | '<%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>', |
||
| 914 | $plugin['DownloadURL'], |
||
| 915 | __( 'Download', 'give' ), |
||
| 916 | $is_license_expired || ! $plugin['DownloadURL'] ? 'button' : 'a', |
||
| 917 | $is_license_expired || ! $plugin['DownloadURL'] ? ' disabled' : '' |
||
| 918 | ); |
||
| 919 | ?> |
||
| 920 | </div> |
||
| 921 | </div> |
||
| 922 | <?php |
||
| 923 | |||
| 924 | return ob_get_clean(); |
||
| 925 | } |
||
| 926 | |||
| 927 | |||
| 928 | /** |
||
| 929 | * Get refresh license status |
||
| 930 | * |
||
| 931 | * @return mixed|void |
||
| 932 | * @since 2.5.0 |
||
| 933 | */ |
||
| 934 | public static function refresh_license_status() { |
||
| 935 | return get_option( |
||
| 936 | 'give_licenses_refreshed_last_checked', |
||
| 937 | array( |
||
| 938 | 'compare' => date( 'Ymd' ), |
||
| 939 | 'time' => current_time( 'timestamp', 1 ), |
||
| 940 | 'count' => 0, |
||
| 941 | ) |
||
| 942 | ); |
||
| 943 | } |
||
| 944 | } |
||
| 945 | |||
| 946 | endif; // end class_exists check. |
||
| 947 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.