| @@ -9,9 +9,9 @@ | ||
| 9 | 9 | * Allows plugins to use their own update API. |
| 10 | 10 | * Modified version with 'polylang' text domain and comments for translators |
| 11 | 11 | * |
| 12 | 12 | * @author Easy Digital Downloads |
| 13 | - * @version 1.7.1 | |
| 13 | + * @version 1.6.18 | |
| 14 | 14 | */ |
| 15 | 15 | class PLL_Plugin_Updater { |
| 16 | 16 | |
| 17 | 17 | private $api_url = ''; |
| @@ -119,9 +119,8 @@ | ||
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | if ( false !== $version_info && is_object( $version_info ) && isset( $version_info->new_version ) ) { |
| 122 | 122 | |
| 123 | - $no_update = false; | |
| 124 | 123 | if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
| 125 | 124 | |
| 126 | 125 | $_transient_data->response[ $this->name ] = $version_info; |
| 127 | 126 | |
| @@ -127,27 +126,13 @@ | ||
| 127 | 126 | |
| 128 | 127 | // Make sure the plugin property is set to the plugin's name/location. See issue 1463 on Software Licensing's GitHub repo. |
| 129 | 128 | $_transient_data->response[ $this->name ]->plugin = $this->name; |
| 130 | 129 | |
| 131 | - } else { | |
| 132 | - $no_update = new stdClass(); | |
| 133 | - $no_update->id = ''; | |
| 134 | - $no_update->slug = $this->slug; | |
| 135 | - $no_update->plugin = $this->name; | |
| 136 | - $no_update->new_version = $version_info->new_version; | |
| 137 | - $no_update->url = $version_info->homepage; | |
| 138 | - $no_update->package = isset( $version_info->package ) ? $version_info->package : ''; #modified# | |
| 139 | - $no_update->icons = $version_info->icons; | |
| 140 | - $no_update->banners = $version_info->banners; | |
| 141 | - $no_update->banners_rtl = array(); | |
| 142 | 130 | } |
| 143 | 131 | |
| 144 | 132 | $_transient_data->last_checked = time(); |
| 145 | 133 | $_transient_data->checked[ $this->name ] = $this->version; |
| 146 | 134 | |
| 147 | - if ( $no_update ) { | |
| 148 | - $_transient_data->no_update[ $this->name ] = $no_update; | |
| 149 | - } | |
| 150 | 135 | } |
| 151 | 136 | |
| 152 | 137 | return $_transient_data; |
| 153 | 138 | } |
| @@ -202,12 +187,8 @@ | ||
| 202 | 187 | if ( isset( $version_info->icons ) && ! is_array( $version_info->icons ) ) { |
| 203 | 188 | $version_info->icons = $this->convert_object_to_array( $version_info->icons ); |
| 204 | 189 | } |
| 205 | 190 | |
| 206 | - if ( isset( $version_info->contributors ) && ! is_array( $version_info->contributors ) ) { | |
| 207 | - $version_info->contributors = $this->convert_object_to_array( $version_info->contributors ); | |
| 208 | - } | |
| 209 | - | |
| 210 | 191 | $this->set_version_info_cache( $version_info ); |
| 211 | 192 | } |
| 212 | 193 | |
| 213 | 194 | if ( ! is_object( $version_info ) ) { |
| @@ -213,31 +194,16 @@ | ||
| 213 | 194 | if ( ! is_object( $version_info ) ) { |
| 214 | 195 | return; |
| 215 | 196 | } |
| 216 | 197 | |
| 217 | - $no_update = false; | |
| 218 | 198 | if ( version_compare( $this->version, $version_info->new_version, '<' ) ) { |
| 219 | 199 | |
| 220 | 200 | $update_cache->response[ $this->name ] = $version_info; |
| 221 | 201 | |
| 222 | - } else { | |
| 223 | - $no_update = new stdClass(); | |
| 224 | - $no_update->id = ''; | |
| 225 | - $no_update->slug = $this->slug; | |
| 226 | - $no_update->plugin = $this->name; | |
| 227 | - $no_update->new_version = $version_info->new_version; | |
| 228 | - $no_update->url = $version_info->homepage; | |
| 229 | - $no_update->package = isset( $version_info->package ) ? $version_info->package : ''; #modified# | |
| 230 | - $no_update->icons = $version_info->icons; | |
| 231 | - $no_update->banners = $version_info->banners; | |
| 232 | - $no_update->banners_rtl = array(); | |
| 233 | 202 | } |
| 234 | 203 | |
| 235 | - $update_cache->last_checked = time(); | |
| 204 | + $update_cache->last_checked = time(); | |
| 236 | 205 | $update_cache->checked[ $this->name ] = $this->version; |
| 237 | - if ( $no_update ) { | |
| 238 | - $update_cache->no_update[ $this->name ] = $no_update; | |
| 239 | - } | |
| 240 | 206 | |
| 241 | 207 | set_site_transient( 'update_plugins', $update_cache ); |
| 242 | 208 | |
| 243 | 209 | } else { |
| @@ -321,10 +287,12 @@ | ||
| 321 | 287 | 'icons' => array(), |
| 322 | 288 | ) |
| 323 | 289 | ); |
| 324 | 290 | |
| 291 | + $cache_key = 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ); | |
| 292 | + | |
| 325 | 293 | // Get the transient where we store the api request for this plugin for 24 hours |
| 326 | - $edd_api_request_transient = $this->get_cached_version_info(); | |
| 294 | + $edd_api_request_transient = $this->get_cached_version_info( $cache_key ); | |
| 327 | 295 | |
| 328 | 296 | //If we have no transient-saved value, run the API, set a fresh transient with the API value, and return that value too right now. |
| 329 | 297 | if ( empty( $edd_api_request_transient ) ) { |
| 330 | 298 | |
| @@ -330,9 +298,9 @@ | ||
| 330 | 298 | |
| 331 | 299 | $api_response = $this->api_request( 'plugin_information', $to_send ); |
| 332 | 300 | |
| 333 | 301 | // Expires in 3 hours |
| 334 | - $this->set_version_info_cache( $api_response ); | |
| 302 | + $this->set_version_info_cache( $api_response, $cache_key ); | |
| 335 | 303 | |
| 336 | 304 | if ( false !== $api_response ) { |
| 337 | 305 | $_data = $api_response; |
| 338 | 306 | } |
| @@ -355,13 +323,8 @@ | ||
| 355 | 323 | if ( isset( $_data->icons ) && ! is_array( $_data->icons ) ) { |
| 356 | 324 | $_data->icons = $this->convert_object_to_array( $_data->icons ); |
| 357 | 325 | } |
| 358 | 326 | |
| 359 | - // Convert contributors into an associative array, since we're getting an object, but Core expects an array. | |
| 360 | - if ( isset( $_data->contributors ) && ! is_array( $_data->contributors ) ) { | |
| 361 | - $_data->contributors = $this->convert_object_to_array( $_data->contributors ); | |
| 362 | - } | |
| 363 | - | |
| 364 | 327 | if( ! isset( $_data->plugin ) ) { |
| 365 | 328 | $_data->plugin = $this->name; |
| 366 | 329 | } |
| 367 | 330 | |
| @@ -382,9 +345,9 @@ | ||
| 382 | 345 | */ |
| 383 | 346 | private function convert_object_to_array( $data ) { |
| 384 | 347 | $new_data = array(); |
| 385 | 348 | foreach ( $data as $key => $value ) { |
| 386 | - $new_data[ $key ] = is_object( $value ) ? $this->convert_object_to_array( $value ) : $value; | |
| 349 | + $new_data[ $key ] = $value; | |
| 387 | 350 | } |
| 388 | 351 | |
| 389 | 352 | return $new_data; |
| 390 | 353 | } |
| @@ -495,11 +458,8 @@ | ||
| 495 | 458 | |
| 496 | 459 | return $request; |
| 497 | 460 | } |
| 498 | 461 | |
| 499 | - /** | |
| 500 | - * If available, show the changelog for sites in a multisite install. | |
| 501 | - */ | |
| 502 | 462 | public function show_changelog() { |
| 503 | 463 | |
| 504 | 464 | global $edd_plugin_data; |
| 505 | 465 | |
| @@ -519,9 +479,11 @@ | ||
| 519 | 479 | wp_die( __( 'You do not have permission to install plugin updates', 'polylang' ), __( 'Error', 'polylang' ), array( 'response' => 403 ) ); |
| 520 | 480 | } |
| 521 | 481 | |
| 522 | 482 | $data = $edd_plugin_data[ $_REQUEST['slug'] ]; |
| 523 | - $version_info = $this->get_cached_version_info(); | |
| 483 | + $beta = ! empty( $data['beta'] ) ? true : false; | |
| 484 | + $cache_key = md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $beta . '_version_info' ); | |
| 485 | + $version_info = $this->get_cached_version_info( $cache_key ); | |
| 524 | 486 | |
| 525 | 487 | if( false === $version_info ) { |
| 526 | 488 | |
| 527 | 489 | $api_params = array( |
| @@ -540,8 +502,9 @@ | ||
| 540 | 502 | if ( ! is_wp_error( $request ) ) { |
| 541 | 503 | $version_info = json_decode( wp_remote_retrieve_body( $request ) ); |
| 542 | 504 | } |
| 543 | 505 | |
| 506 | + | |
| 544 | 507 | if ( ! empty( $version_info ) && isset( $version_info->sections ) ) { |
| 545 | 508 | $version_info->sections = maybe_unserialize( $version_info->sections ); |
| 546 | 509 | } else { |
| 547 | 510 | $version_info = false; |
| @@ -552,30 +515,19 @@ | ||
| 552 | 515 | $version_info->$key = (array) $section; |
| 553 | 516 | } |
| 554 | 517 | } |
| 555 | 518 | |
| 556 | - $this->set_version_info_cache( $version_info ); | |
| 519 | + $this->set_version_info_cache( $version_info, $cache_key ); | |
| 557 | 520 | |
| 558 | - // Delete the unneeded option | |
| 559 | - delete_option( md5( 'edd_plugin_' . sanitize_key( $_REQUEST['plugin'] ) . '_' . $this->beta . '_version_info' ) ); | |
| 560 | 521 | } |
| 561 | 522 | |
| 562 | - if ( isset( $version_info->sections ) ) { | |
| 563 | - $sections = $this->convert_object_to_array( $version_info->sections ); | |
| 564 | - if ( ! empty( $sections['changelog'] ) ) { | |
| 565 | - echo '<div style="background:#fff;padding:10px;">' . wp_kses_post( $sections['changelog'] ) . '</div>'; | |
| 566 | - } | |
| 523 | + if( ! empty( $version_info ) && isset( $version_info->sections['changelog'] ) ) { | |
| 524 | + echo '<div style="background:#fff;padding:10px;">' . $version_info->sections['changelog'] . '</div>'; | |
| 567 | 525 | } |
| 568 | 526 | |
| 569 | 527 | exit; |
| 570 | 528 | } |
| 571 | 529 | |
| 572 | - /** | |
| 573 | - * Gets the plugin's cached version information from the database. | |
| 574 | - * | |
| 575 | - * @param string $cache_key | |
| 576 | - * @return boolean|string | |
| 577 | - */ | |
| 578 | 530 | public function get_cached_version_info( $cache_key = '' ) { |
| 579 | 531 | |
| 580 | 532 | if( empty( $cache_key ) ) { |
| 581 | 533 | $cache_key = $this->cache_key; |
| @@ -596,14 +548,8 @@ | ||
| 596 | 548 | return $cache['value']; |
| 597 | 549 | |
| 598 | 550 | } |
| 599 | 551 | |
| 600 | - /** | |
| 601 | - * Adds the plugin version information to the database. | |
| 602 | - * | |
| 603 | - * @param string $value | |
| 604 | - * @param string $cache_key | |
| 605 | - */ | |
| 606 | 552 | public function set_version_info_cache( $value = '', $cache_key = '' ) { |
| 607 | 553 | |
| 608 | 554 | if( empty( $cache_key ) ) { |
| 609 | 555 | $cache_key = $this->cache_key; |
| @@ -615,10 +561,8 @@ | ||
| 615 | 561 | ); |
| 616 | 562 | |
| 617 | 563 | update_option( $cache_key, $data, 'no' ); |
| 618 | 564 | |
| 619 | - // Delete the duplicate option | |
| 620 | - delete_option( 'edd_api_request_' . md5( serialize( $this->slug . $this->api_data['license'] . $this->beta ) ) ); | |
| 621 | 565 | } |
| 622 | 566 | |
| 623 | 567 | /** |
| 624 | 568 | * Returns if the SSL of the store should be verified. |
| @@ -630,5 +574,4 @@ | ||
| 630 | 574 | return (bool) apply_filters( 'edd_sl_api_request_verify_ssl', true, $this ); |
| 631 | 575 | } |
| 632 | 576 | |
| 633 | 577 | } |
| 634 | - | |