← All changes
|
includes/integration/openai/plugin-upgrader/classes/plugin-upgrader.php
+195
-195
8.6.8
→
8.3.8
View file →
| @@ -1,196 +1,196 @@ | ||
| 1 | -<?php | |
| 2 | -if (!defined('ABSPATH')) exit; // Exit if accessed directly | |
| 3 | -class QCLD_openaiaddon_AutoUpdate | |
| 4 | -{ | |
| 5 | - /** | |
| 6 | - * The plugin current version | |
| 7 | - * @var string | |
| 8 | - */ | |
| 9 | - private $current_version; | |
| 10 | - | |
| 11 | - /** | |
| 12 | - * The plugin remote update path | |
| 13 | - * @var string | |
| 14 | - */ | |
| 15 | - private $update_path; | |
| 16 | - | |
| 17 | - /** | |
| 18 | - * Plugin Slug (plugin_directory/plugin_file.php) | |
| 19 | - * @var string | |
| 20 | - */ | |
| 21 | - private $plugin_slug; | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * Plugin name (plugin_file) | |
| 25 | - * @var string | |
| 26 | - */ | |
| 27 | - private $slug; | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * License User | |
| 31 | - * @var string | |
| 32 | - */ | |
| 33 | - private $license_user; | |
| 34 | - | |
| 35 | - /** | |
| 36 | - * License Key | |
| 37 | - * @var string | |
| 38 | - */ | |
| 39 | - private $license_key; | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * Initialize a new instance of the WordPress Auto-Update class | |
| 43 | - * @param string $current_version | |
| 44 | - * @param string $update_path | |
| 45 | - * @param string $plugin_slug | |
| 46 | - */ | |
| 47 | - public function __construct( $current_version, $update_path, $plugin_slug, $license_user = '', $license_key = '' ) | |
| 48 | - { | |
| 49 | - $qcld_renew_subscription = get_openaiaddon_renew_transient(); | |
| 50 | - | |
| 51 | - // Set the class public variables | |
| 52 | - $this->current_version = $current_version; | |
| 53 | - $this->update_path = $update_path; | |
| 54 | - | |
| 55 | - // Set the License | |
| 56 | - $this->license_user = $license_user; | |
| 57 | - $this->license_key = $license_key; | |
| 58 | - | |
| 59 | - // Set the Plugin Slug | |
| 60 | - $this->plugin_slug = $plugin_slug; | |
| 61 | - list ($t1, $t2) = explode( '/', $plugin_slug ); | |
| 62 | - $this->slug = $t1; | |
| 63 | - | |
| 64 | - // define the alternative API for updating checking | |
| 65 | - add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); | |
| 66 | - | |
| 67 | - // Define the alternative response for information checking | |
| 68 | - add_filter( 'plugins_api', array( $this, 'check_info' ), 10, 3 ); | |
| 69 | - | |
| 70 | - if( $qcld_renew_subscription ){ | |
| 71 | - add_action("after_plugin_row_{$this->plugin_slug}", array($this, 'show_upgrade_subscription_on_plugin_row'), 10, 3 ); | |
| 72 | - } | |
| 73 | - | |
| 74 | - } | |
| 75 | - | |
| 76 | - /** | |
| 77 | - * Add our self-hosted autoupdate plugin to the filter transient | |
| 78 | - * | |
| 79 | - * @param $transient | |
| 80 | - * @return object $ transient | |
| 81 | - */ | |
| 82 | - public function check_update( $transient ) | |
| 83 | - { | |
| 84 | - if ( empty( $transient->checked ) ) { | |
| 85 | - return $transient; | |
| 86 | - } | |
| 87 | - | |
| 88 | - | |
| 89 | - // Get the remote version | |
| 90 | - $remote_version = $this->getRemote('info'); | |
| 91 | - | |
| 92 | - | |
| 93 | - // If a newer version is available, add the update | |
| 94 | - if ( version_compare( $this->current_version, $remote_version->new_version, '<' ) ) { | |
| 95 | - if(isset($remote_version->subscription_enable->plugin_name) ){ | |
| 96 | - $subscription_enable = $remote_version->subscription_enable->plugin_name; | |
| 97 | - }else{ | |
| 98 | - $subscription_enable = ''; | |
| 99 | - } | |
| 100 | - | |
| 101 | - | |
| 102 | - | |
| 103 | - if( $this->slug == $subscription_enable ){ | |
| 104 | - $obj = new stdClass(); | |
| 105 | - $obj->slug = $this->slug; | |
| 106 | - $obj->new_version = $remote_version->new_version; | |
| 107 | - $obj->url = $remote_version->url; | |
| 108 | - $obj->plugin = $this->plugin_slug; | |
| 109 | - $obj->package = $remote_version->package; | |
| 110 | - $obj->tested = $remote_version->tested; | |
| 111 | - $obj->requires = $remote_version->requires; | |
| 112 | - $obj->last_updated = $remote_version->last_updated; | |
| 113 | - $obj->sections = $remote_version->sections; | |
| 114 | - | |
| 115 | - setqc_openaiaddon_update_transient($obj); | |
| 116 | - deleteqc_openaiaddon_renew_transient(); | |
| 117 | - | |
| 118 | - $transient->response[$this->plugin_slug] = $obj; | |
| 119 | - }else{ | |
| 120 | - $obj = new stdClass(); | |
| 121 | - setqc_openaiaddon_renew_transient($obj); | |
| 122 | - $qcld_renew_subscription = get_openaiaddon_renew_transient(); | |
| 123 | - if( $qcld_renew_subscription ){ | |
| 124 | - add_action("after_plugin_row_{$this->plugin_slug}", array($this, 'show_upgrade_subscription_on_plugin_row'), 10, 3 ); | |
| 125 | - } | |
| 126 | - } | |
| 127 | - | |
| 128 | - } | |
| 129 | - return $transient; | |
| 130 | - } | |
| 131 | - | |
| 132 | - public function show_upgrade_subscription_on_plugin_row( $plugin_file, $plugin_data, $status ) { | |
| 133 | - $qcld_renew_subscription = get_openaiaddon_renew_transient(); | |
| 134 | - | |
| 135 | - if( $qcld_renew_subscription ){ | |
| 136 | - echo '<tr class="plugin-update-tr"> | |
| 137 | - <td colspan="3" class="plugin-update colspanchange"> | |
| 138 | - <div class="update-message notice inline notice-warning notice-alt"> | |
| 139 | - <p>There is a new version available. <a href="'.esc_url('https://www.ultrawebmedia.com/li/plugins/live-chat-addon/changelog.txt').'" target="_blank">View version details</a>. Automatic update is unavailable for this plugin. To receive automatic updates, valid license is required.</p> | |
| 140 | - </div> | |
| 141 | - </td> | |
| 142 | - </tr>'; | |
| 143 | - } | |
| 144 | - } | |
| 145 | - | |
| 146 | - /** | |
| 147 | - * Add our self-hosted description to the filter | |
| 148 | - * | |
| 149 | - * @param boolean $false | |
| 150 | - * @param array $action | |
| 151 | - * @param object $arg | |
| 152 | - * @return bool|object | |
| 153 | - */ | |
| 154 | - public function check_info($obj, $action, $arg) | |
| 155 | - { | |
| 156 | - if (($action=='query_plugins' || $action=='plugin_information') && | |
| 157 | - isset($arg->slug) && $arg->slug === $this->slug) { | |
| 158 | - return $this->getRemote('info'); | |
| 159 | - } | |
| 160 | - | |
| 161 | - return $obj; | |
| 162 | - } | |
| 163 | - | |
| 164 | - /** | |
| 165 | - * Return the remote version | |
| 166 | - * | |
| 167 | - * @return string $remote_version | |
| 168 | - */ | |
| 169 | - public function getRemote($action = '') | |
| 170 | - { | |
| 171 | - $qcld_update_plugin = get_openaiaddon_update_transient(); | |
| 172 | - | |
| 173 | - | |
| 174 | - | |
| 175 | - $params = array( | |
| 176 | - 'body' => array( | |
| 177 | - 'action' => $action, | |
| 178 | - 'plugin-slug' => $this->slug, | |
| 179 | - 'license_user' => $this->license_user, | |
| 180 | - 'license_key' => $this->license_key, | |
| 181 | - ), | |
| 182 | - ); | |
| 183 | - | |
| 184 | - // Make the POST request | |
| 185 | - $request = wp_remote_post($this->update_path, $params ); | |
| 186 | - // Check if response is valid | |
| 187 | - | |
| 188 | - if ( !is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ) { | |
| 189 | - | |
| 190 | - return @unserialize( $request['body'] ); | |
| 191 | - } | |
| 192 | - | |
| 193 | - | |
| 194 | - return false; | |
| 195 | - } | |
| 1 | +<?php | |
| 2 | +if (!defined('ABSPATH')) exit; // Exit if accessed directly | |
| 3 | +class QCLD_openaiaddon_AutoUpdate | |
| 4 | +{ | |
| 5 | + /** | |
| 6 | + * The plugin current version | |
| 7 | + * @var string | |
| 8 | + */ | |
| 9 | + private $current_version; | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * The plugin remote update path | |
| 13 | + * @var string | |
| 14 | + */ | |
| 15 | + private $update_path; | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * Plugin Slug (plugin_directory/plugin_file.php) | |
| 19 | + * @var string | |
| 20 | + */ | |
| 21 | + private $plugin_slug; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * Plugin name (plugin_file) | |
| 25 | + * @var string | |
| 26 | + */ | |
| 27 | + private $slug; | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * License User | |
| 31 | + * @var string | |
| 32 | + */ | |
| 33 | + private $license_user; | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * License Key | |
| 37 | + * @var string | |
| 38 | + */ | |
| 39 | + private $license_key; | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * Initialize a new instance of the WordPress Auto-Update class | |
| 43 | + * @param string $current_version | |
| 44 | + * @param string $update_path | |
| 45 | + * @param string $plugin_slug | |
| 46 | + */ | |
| 47 | + public function __construct( $current_version, $update_path, $plugin_slug, $license_user = '', $license_key = '' ) | |
| 48 | + { | |
| 49 | + $qcld_renew_subscription = get_openaiaddon_renew_transient(); | |
| 50 | + | |
| 51 | + // Set the class public variables | |
| 52 | + $this->current_version = $current_version; | |
| 53 | + $this->update_path = $update_path; | |
| 54 | + | |
| 55 | + // Set the License | |
| 56 | + $this->license_user = $license_user; | |
| 57 | + $this->license_key = $license_key; | |
| 58 | + | |
| 59 | + // Set the Plugin Slug | |
| 60 | + $this->plugin_slug = $plugin_slug; | |
| 61 | + list ($t1, $t2) = explode( '/', $plugin_slug ); | |
| 62 | + $this->slug = $t1; | |
| 63 | + | |
| 64 | + // define the alternative API for updating checking | |
| 65 | + add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'check_update' ) ); | |
| 66 | + | |
| 67 | + // Define the alternative response for information checking | |
| 68 | + add_filter( 'plugins_api', array( $this, 'check_info' ), 10, 3 ); | |
| 69 | + | |
| 70 | + if( $qcld_renew_subscription ){ | |
| 71 | + add_action("after_plugin_row_{$this->plugin_slug}", array($this, 'show_upgrade_subscription_on_plugin_row'), 10, 3 ); | |
| 72 | + } | |
| 73 | + | |
| 74 | + } | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * Add our self-hosted autoupdate plugin to the filter transient | |
| 78 | + * | |
| 79 | + * @param $transient | |
| 80 | + * @return object $ transient | |
| 81 | + */ | |
| 82 | + public function check_update( $transient ) | |
| 83 | + { | |
| 84 | + if ( empty( $transient->checked ) ) { | |
| 85 | + return $transient; | |
| 86 | + } | |
| 87 | + | |
| 88 | + | |
| 89 | + // Get the remote version | |
| 90 | + $remote_version = $this->getRemote('info'); | |
| 91 | + | |
| 92 | + | |
| 93 | + // If a newer version is available, add the update | |
| 94 | + if ( version_compare( $this->current_version, $remote_version->new_version, '<' ) ) { | |
| 95 | + if(isset($remote_version->subscription_enable->plugin_name) ){ | |
| 96 | + $subscription_enable = $remote_version->subscription_enable->plugin_name; | |
| 97 | + }else{ | |
| 98 | + $subscription_enable = ''; | |
| 99 | + } | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + if( $this->slug == $subscription_enable ){ | |
| 104 | + $obj = new stdClass(); | |
| 105 | + $obj->slug = $this->slug; | |
| 106 | + $obj->new_version = $remote_version->new_version; | |
| 107 | + $obj->url = $remote_version->url; | |
| 108 | + $obj->plugin = $this->plugin_slug; | |
| 109 | + $obj->package = $remote_version->package; | |
| 110 | + $obj->tested = $remote_version->tested; | |
| 111 | + $obj->requires = $remote_version->requires; | |
| 112 | + $obj->last_updated = $remote_version->last_updated; | |
| 113 | + $obj->sections = $remote_version->sections; | |
| 114 | + | |
| 115 | + setqc_openaiaddon_update_transient($obj); | |
| 116 | + deleteqc_openaiaddon_renew_transient(); | |
| 117 | + | |
| 118 | + $transient->response[$this->plugin_slug] = $obj; | |
| 119 | + }else{ | |
| 120 | + $obj = new stdClass(); | |
| 121 | + setqc_openaiaddon_renew_transient($obj); | |
| 122 | + $qcld_renew_subscription = get_openaiaddon_renew_transient(); | |
| 123 | + if( $qcld_renew_subscription ){ | |
| 124 | + add_action("after_plugin_row_{$this->plugin_slug}", array($this, 'show_upgrade_subscription_on_plugin_row'), 10, 3 ); | |
| 125 | + } | |
| 126 | + } | |
| 127 | + | |
| 128 | + } | |
| 129 | + return $transient; | |
| 130 | + } | |
| 131 | + | |
| 132 | + public function show_upgrade_subscription_on_plugin_row( $plugin_file, $plugin_data, $status ) { | |
| 133 | + $qcld_renew_subscription = get_openaiaddon_renew_transient(); | |
| 134 | + | |
| 135 | + if( $qcld_renew_subscription ){ | |
| 136 | + echo '<tr class="plugin-update-tr"> | |
| 137 | + <td colspan="3" class="plugin-update colspanchange"> | |
| 138 | + <div class="update-message notice inline notice-warning notice-alt"> | |
| 139 | + <p>There is a new version available. <a href="'.esc_url('https://www.ultrawebmedia.com/li/plugins/live-chat-addon/changelog.txt').'" target="_blank">View version details</a>. Automatic update is unavailable for this plugin. To receive automatic updates, valid license is required.</p> | |
| 140 | + </div> | |
| 141 | + </td> | |
| 142 | + </tr>'; | |
| 143 | + } | |
| 144 | + } | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * Add our self-hosted description to the filter | |
| 148 | + * | |
| 149 | + * @param boolean $false | |
| 150 | + * @param array $action | |
| 151 | + * @param object $arg | |
| 152 | + * @return bool|object | |
| 153 | + */ | |
| 154 | + public function check_info($obj, $action, $arg) | |
| 155 | + { | |
| 156 | + if (($action=='query_plugins' || $action=='plugin_information') && | |
| 157 | + isset($arg->slug) && $arg->slug === $this->slug) { | |
| 158 | + return $this->getRemote('info'); | |
| 159 | + } | |
| 160 | + | |
| 161 | + return $obj; | |
| 162 | + } | |
| 163 | + | |
| 164 | + /** | |
| 165 | + * Return the remote version | |
| 166 | + * | |
| 167 | + * @return string $remote_version | |
| 168 | + */ | |
| 169 | + public function getRemote($action = '') | |
| 170 | + { | |
| 171 | + $qcld_update_plugin = get_openaiaddon_update_transient(); | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + $params = array( | |
| 176 | + 'body' => array( | |
| 177 | + 'action' => $action, | |
| 178 | + 'plugin-slug' => $this->slug, | |
| 179 | + 'license_user' => $this->license_user, | |
| 180 | + 'license_key' => $this->license_key, | |
| 181 | + ), | |
| 182 | + ); | |
| 183 | + | |
| 184 | + // Make the POST request | |
| 185 | + $request = wp_remote_post($this->update_path, $params ); | |
| 186 | + // Check if response is valid | |
| 187 | + | |
| 188 | + if ( !is_wp_error( $request ) || wp_remote_retrieve_response_code( $request ) === 200 ) { | |
| 189 | + | |
| 190 | + return @unserialize( $request['body'] ); | |
| 191 | + } | |
| 192 | + | |
| 193 | + | |
| 194 | + return false; | |
| 195 | + } | |
| 196 | 196 | } |