feat: add S3-compatible storage provider (MinIO, Ceph, R2, etc.)
Adds a new 'S3-Compatible Storage' provider that works with any
S3-API-compatible object storage service, including MinIO, Ceph,
Cloudflare R2, Backblaze B2, and others.
Changes:
- New provider class: classes/providers/storage/s3-compatible-provider.php
- Provider key: s3compatible
- Reads user-configured endpoint URL from settings
- Uses path-style URL access (required by most S3-compatible services)
- Supports credentials via AS3CF_S3COMPAT_ACCESS_KEY_ID /
AS3CF_S3COMPAT_SECRET_ACCESS_KEY wp-config.php constants
- Disables AWS-specific features (Block Public Access, Object Ownership)
- New provider SVG icons (s3compatible.svg, -link.svg, -round.svg)
- Registered provider in main plugin class with endpoint setting support
- Updated StorageProviderSubPage to show endpoint URL input for S3-compatible
- Built pro settings bundle with rollup (Svelte 4.2.19)
- Added package.json and updated rollup.config.mjs for pro-only builds
This commit is contained in:
218
vendor/deliciousbrains/api.php
vendored
Normal file
218
vendor/deliciousbrains/api.php
vendored
Normal file
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
/**
|
||||
* API Wrapper Class
|
||||
*
|
||||
* @package deliciousbrains
|
||||
* @subpackage api
|
||||
* @copyright Copyright (c) 2015, Delicious Brains
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delicious_Brains_API Class
|
||||
*
|
||||
* This class is a wrapper for the Delicious Brains WooCommerce API
|
||||
*
|
||||
* @since 0.1
|
||||
*/
|
||||
class Delicious_Brains_API {
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $api_url;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $api_base = 'https://api.deliciousbrains.com';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $api_status_url = 'http://s3.amazonaws.com/cdn.deliciousbrains.com/status.json';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $transient_timeout;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $transient_retry_timeout;
|
||||
|
||||
/**
|
||||
* Initiate API wrapper.
|
||||
*/
|
||||
function __construct() {
|
||||
$this->transient_timeout = HOUR_IN_SECONDS * 12;
|
||||
$this->transient_retry_timeout = HOUR_IN_SECONDS * 2;
|
||||
|
||||
if ( defined( 'DBRAINS_API_BASE' ) ) {
|
||||
$this->api_base = DBRAINS_API_BASE;
|
||||
}
|
||||
|
||||
$this->api_url = $this->api_base . '/?wc-api=delicious-brains';
|
||||
}
|
||||
|
||||
/**
|
||||
* Default request arguments passed to an HTTP request
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @see wp_remote_request() For more information on the available arguments.
|
||||
*/
|
||||
protected function get_default_request_args() {
|
||||
return array(
|
||||
'timeout' => 10,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for wp_remote_get
|
||||
*
|
||||
* @param string $url
|
||||
* @param array $args
|
||||
*
|
||||
* @return array|WP_Error
|
||||
*/
|
||||
public function get( $url, $args = array() ) {
|
||||
$defaults = $this->get_default_request_args();
|
||||
|
||||
$args = array_merge( $defaults, $args );
|
||||
|
||||
$response = wp_remote_get( $url, $args );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the API URL
|
||||
*
|
||||
* @param string $request
|
||||
* @param array $args
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_url( $request, $args = array() ) {
|
||||
return $this->api_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function for communicating with the Delicious Brains API.
|
||||
*
|
||||
* @param string $request
|
||||
* @param array $args
|
||||
*
|
||||
* @return string|bool
|
||||
*/
|
||||
public function api_request( $request, $args = array() ) {
|
||||
$url = $this->get_url( $request, $args );
|
||||
$response = $this->get( $url );
|
||||
|
||||
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$response = wp_remote_retrieve_body( $response );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the support access for a license key
|
||||
*
|
||||
* @param string $licence_key
|
||||
* @param string $site_url
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function check_support_access( $licence_key = '', $site_url = '' ) {
|
||||
$args = array(
|
||||
'licence_key' => $licence_key,
|
||||
'site_url' => $site_url,
|
||||
);
|
||||
|
||||
$response = $this->api_request( 'check_support_access', $args );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate a license key for an install
|
||||
*
|
||||
* @param string $licence_key
|
||||
* @param string $site_url
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function activate_licence( $licence_key = '', $site_url = '' ) {
|
||||
$args = array(
|
||||
'licence_key' => $licence_key,
|
||||
'site_url' => $site_url,
|
||||
);
|
||||
|
||||
$response = $this->api_request( 'activate_licence', $args );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reactivate an install for a license key
|
||||
*
|
||||
* @param string $licence_key
|
||||
* @param string $site_url
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function reactivate_licence( $licence_key = '', $site_url = '' ) {
|
||||
$args = array(
|
||||
'licence_key' => $licence_key,
|
||||
'site_url' => $site_url,
|
||||
);
|
||||
|
||||
$response = $this->api_request( 'reactivate_licence', $args );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the upgrade data for plugin and addons
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_upgrade_data() {
|
||||
$response = $this->api_request( 'upgrade_data' );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get changelog contents for the given plugin slug.
|
||||
*
|
||||
* @param string $slug
|
||||
* @param bool $beta
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function get_changelog( $slug, $beta = false ) {
|
||||
if ( true === $beta ) {
|
||||
$slug .= '-beta';
|
||||
}
|
||||
|
||||
$args = array(
|
||||
'slug' => $slug,
|
||||
);
|
||||
|
||||
$response = $this->api_request( 'changelog', $args );
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
3
vendor/deliciousbrains/assets/css/plugin-update.css
vendored
Normal file
3
vendor/deliciousbrains/assets/css/plugin-update.css
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.as3cf-licence-notice a + .as3cf-dbrains-check-my-licence-again:before {
|
||||
content: " | ";
|
||||
}
|
||||
309
vendor/deliciousbrains/assets/js/plugin-update.js
vendored
Normal file
309
vendor/deliciousbrains/assets/js/plugin-update.js
vendored
Normal file
@@ -0,0 +1,309 @@
|
||||
(function( $ ) {
|
||||
|
||||
/**
|
||||
* The list table used on the current page.
|
||||
* plugins.php : .wp-list-table.plugins
|
||||
* update-core.php : #update-plugins-table
|
||||
* @type {Object}
|
||||
*/
|
||||
const $listTable = $( '#update-plugins-table,.wp-list-table.plugins' );
|
||||
|
||||
/**
|
||||
* Class representing a single plugin in the context of a list table of plugin updates.
|
||||
*
|
||||
* @param {object} data
|
||||
* @param {Plugin|undefined} parent
|
||||
* @constructor
|
||||
*/
|
||||
const Plugin = function( data, parent ) {
|
||||
|
||||
/**
|
||||
* Data provided by the server.
|
||||
* @type {Object}
|
||||
*/
|
||||
this.data = data;
|
||||
|
||||
/**
|
||||
* Parent Plugin instance, if representing an add-on.
|
||||
* @type {Plugin|undefined}
|
||||
*/
|
||||
this.parent = parent;
|
||||
|
||||
/**
|
||||
* Object for the checkbox allowing the plugin to be submitted for update.
|
||||
* @type {Object} jQuery
|
||||
*/
|
||||
this.$check = $listTable.find( '.check-column [value="' + data.basename + '"]' );
|
||||
|
||||
/**
|
||||
* Object for the primary list table row for this plugin.
|
||||
* @type {Object} jQuery
|
||||
*/
|
||||
this.$row = this.$check.closest( 'tr' );
|
||||
|
||||
/**
|
||||
* Object for the container which holds update notices for this plugin.
|
||||
* This container represents the main difference between the two list tables.
|
||||
*
|
||||
* This property is only initialized for plugins with license errors.
|
||||
*
|
||||
* @type {Object} jQuery
|
||||
*/
|
||||
this.$noticeContainer = null;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the html for this plugin's check license again link.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
Plugin.prototype.checkAgainLink = function() {
|
||||
return ' <span class="as3cf-dbrains-check-my-licence-again"><a href="#">' + as3cf_dbrains.strings.check_licence_again + '</a></span>';
|
||||
};
|
||||
|
||||
/**
|
||||
* Does this plugin have any errors for its license?
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
Plugin.prototype.hasLicenseErrors = function() {
|
||||
const license = this.isAddon() ? this.parent.data.license : this.data.license;
|
||||
|
||||
return !_.isEmpty( license.errors );
|
||||
};
|
||||
|
||||
/**
|
||||
* Disable the plugin's list table checkbox.
|
||||
*/
|
||||
Plugin.prototype.disableUpdateCheckbox = function() {
|
||||
if ( $listTable.is( '#update-plugins-table' ) ) {
|
||||
this.$check.prop( {
|
||||
disabled: true,
|
||||
checked: false
|
||||
} );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Enable the plugin's list table checkbox.
|
||||
*/
|
||||
Plugin.prototype.enableUpdateCheckbox = function() {
|
||||
if ( $listTable.is( '#update-plugins-table' ) ) {
|
||||
this.$check.prop( {
|
||||
disabled: false
|
||||
} );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the update notice with the given html.
|
||||
*
|
||||
* @param {string} html
|
||||
*/
|
||||
Plugin.prototype.setNotice = function( html ) {
|
||||
this.$noticeContainer.find( '.as3cf-licence-notice' ).remove();
|
||||
this.$noticeContainer.append(
|
||||
'<div class="as3cf-licence-notice update-message notice inline notice-warning notice-alt">' +
|
||||
'<p class="as3cf-before">' + html + this.checkAgainLink() + '</p>' +
|
||||
'</div>'
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Fade out our license notice and remove it, then restore WP update notices, if any.
|
||||
*/
|
||||
Plugin.prototype.clearNotice = function() {
|
||||
const plugin = this;
|
||||
const $notice = this.$noticeContainer.find( '.as3cf-licence-notice' );
|
||||
|
||||
$.when( $notice.fadeOut() ).done( function() {
|
||||
$notice.remove();
|
||||
plugin.$row.children().css( 'box-shadow', '' );
|
||||
plugin.$noticeContainer.find( '.update-message' ).show();
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* Render the plugin's state to the DOM.
|
||||
*/
|
||||
Plugin.prototype.render = function() {
|
||||
if ( this.hasLicenseErrors() ) {
|
||||
this.initNoticeContainer();
|
||||
this.disableUpdateCheckbox();
|
||||
this.$noticeContainer.find( '.update-message:not(".as3cf-licence-notice")' ).hide();
|
||||
this.setNotice( this.getLicenseNotice() );
|
||||
} else if ( this.$noticeContainer ) {
|
||||
this.enableUpdateCheckbox();
|
||||
this.clearNotice();
|
||||
}
|
||||
|
||||
if ( !this.isAddon() ) {
|
||||
_.invoke( this.addons, 'render' );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize the notice container.
|
||||
*/
|
||||
Plugin.prototype.initNoticeContainer = function() {
|
||||
if ( this.$noticeContainer ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if it is the Plugins update table
|
||||
if ( !$listTable.is( '#update-plugins-table' ) ) {
|
||||
|
||||
// Check for an existing plugin-update notice row to use.
|
||||
const $noticeRow = $listTable.find( '.plugin-update-tr[data-plugin="' + this.data.basename + '"]' );
|
||||
|
||||
if ( $noticeRow.length ) {
|
||||
this.$noticeContainer = $noticeRow.find( '.plugin-update' );
|
||||
} else {
|
||||
|
||||
const colspan = this.$row.children().length;
|
||||
|
||||
// If there is no plugin-update row, the plugin did not have an update, so inject a row to use.
|
||||
this.$row.after(
|
||||
'<tr class="plugin-update-tr ' + this.$row.attr( 'class' ) + '" ' +
|
||||
'id="' + this.data.slug + '-update" ' +
|
||||
'data-slug="' + this.data.slug + '" ' +
|
||||
'data-plugin="' + this.data.basename + '" ' +
|
||||
'>' +
|
||||
'<td colspan="' + colspan + '" class="plugin-update colspanchange"></td>' +
|
||||
'</tr>'
|
||||
);
|
||||
|
||||
// The border between rows comes from a box-shadow on the children of the row above
|
||||
this.$row.children().css( 'box-shadow', 'none' );
|
||||
|
||||
this.$noticeContainer = $listTable.find( '.plugin-update-tr[data-plugin="' + this.data.basename + '"] .plugin-update' );
|
||||
}
|
||||
} else {
|
||||
// Updates
|
||||
this.$noticeContainer = this.$row.find( '.plugin-title' );
|
||||
}
|
||||
|
||||
// Finally, bind the click handler for ajax license checking
|
||||
this.$noticeContainer.on( 'click', '.as3cf-dbrains-check-my-licence-again a', _.bind( this.checkLicenseAgain, this ) );
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the text for the license notice.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
Plugin.prototype.getLicenseNotice = function() {
|
||||
let message = '';
|
||||
|
||||
if ( this.data.update_available ) {
|
||||
message = as3cf_dbrains.strings.update_available + ' ';
|
||||
}
|
||||
|
||||
if ( this.isAddon() ) {
|
||||
return message + as3cf_dbrains.strings.requires_parent_licence.replace( '%s', this.parent.data.name );
|
||||
}
|
||||
|
||||
return message + _.values( this.data.license.errors ).join( '' );
|
||||
};
|
||||
|
||||
/**
|
||||
* Event listener callback to handle the check the license again for this plugin.
|
||||
*
|
||||
* @param {Event} event
|
||||
*/
|
||||
Plugin.prototype.checkLicenseAgain = function( event ) {
|
||||
const plugin = this;
|
||||
const $link = $( event.target );
|
||||
const $spinner = $( '<span class="spinner is-active as3cf-dbrains-licence-check-spinner" style="float:none; margin-top: -3px;"></span>' );
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
$link.hide().after( $spinner );
|
||||
|
||||
this.ajaxCheckLicense()
|
||||
.done( function( data ) {
|
||||
if ( plugin.isAddon() ) {
|
||||
plugin.parent.data.license.errors = data.errors;
|
||||
plugin.parent.render();
|
||||
} else {
|
||||
plugin.data.license.errors = data.errors;
|
||||
plugin.render();
|
||||
}
|
||||
} )
|
||||
.fail( function() {
|
||||
plugin.setNotice( as3cf_dbrains.strings.licence_check_problem );
|
||||
} )
|
||||
.always( function() {
|
||||
$spinner.remove();
|
||||
} )
|
||||
;
|
||||
};
|
||||
|
||||
/**
|
||||
* Send an ajax request to the server to check the plugin's license.
|
||||
*
|
||||
* @return {jqXHR} jQuery XHR Promise object
|
||||
*/
|
||||
Plugin.prototype.ajaxCheckLicense = function() {
|
||||
const prefix = this.isAddon() ? this.parent.data.prefix : this.data.prefix;
|
||||
|
||||
return $.ajax( {
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
data: {
|
||||
action: prefix + '_check_licence',
|
||||
nonce: as3cf_dbrains.nonces.check_licence
|
||||
}
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize the plugin instance.
|
||||
*/
|
||||
Plugin.prototype.init = function() {
|
||||
this.render();
|
||||
|
||||
if ( !this.isAddon() ) {
|
||||
this.initAddons();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Does this instance represent an add-on?
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
Plugin.prototype.isAddon = function() {
|
||||
return !!this.parent;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize Plugin add-ons.
|
||||
*/
|
||||
Plugin.prototype.initAddons = function() {
|
||||
const parent = this;
|
||||
|
||||
this.addons = _.map( this.data.addons, function( addonData ) {
|
||||
return new Plugin( addonData, parent );
|
||||
} );
|
||||
|
||||
_.invoke( this.addons, 'init' );
|
||||
};
|
||||
|
||||
/**
|
||||
* Instantiate and initialize plugin instances.
|
||||
*/
|
||||
function initialize() {
|
||||
_.chain( as3cf_dbrains.plugins )
|
||||
.map( function( pluginData ) {
|
||||
return new Plugin( pluginData );
|
||||
} )
|
||||
.invoke( 'init' );
|
||||
}
|
||||
|
||||
if ( $listTable.length ) {
|
||||
$( initialize );
|
||||
}
|
||||
})( jQuery );
|
||||
1
vendor/deliciousbrains/assets/js/plugin-update.min.js
vendored
Normal file
1
vendor/deliciousbrains/assets/js/plugin-update.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
(function($){const $listTable=$("#update-plugins-table,.wp-list-table.plugins");const Plugin=function(data,parent){this.data=data;this.parent=parent;this.$check=$listTable.find('.check-column [value="'+data.basename+'"]');this.$row=this.$check.closest("tr");this.$noticeContainer=null};Plugin.prototype.checkAgainLink=function(){return' <span class="as3cf-dbrains-check-my-licence-again"><a href="#">'+as3cf_dbrains.strings.check_licence_again+"</a></span>"};Plugin.prototype.hasLicenseErrors=function(){const license=this.isAddon()?this.parent.data.license:this.data.license;return!_.isEmpty(license.errors)};Plugin.prototype.disableUpdateCheckbox=function(){if($listTable.is("#update-plugins-table")){this.$check.prop({disabled:true,checked:false})}};Plugin.prototype.enableUpdateCheckbox=function(){if($listTable.is("#update-plugins-table")){this.$check.prop({disabled:false})}};Plugin.prototype.setNotice=function(html){this.$noticeContainer.find(".as3cf-licence-notice").remove();this.$noticeContainer.append('<div class="as3cf-licence-notice update-message notice inline notice-warning notice-alt">'+'<p class="as3cf-before">'+html+this.checkAgainLink()+"</p>"+"</div>")};Plugin.prototype.clearNotice=function(){const plugin=this;const $notice=this.$noticeContainer.find(".as3cf-licence-notice");$.when($notice.fadeOut()).done((function(){$notice.remove();plugin.$row.children().css("box-shadow","");plugin.$noticeContainer.find(".update-message").show()}))};Plugin.prototype.render=function(){if(this.hasLicenseErrors()){this.initNoticeContainer();this.disableUpdateCheckbox();this.$noticeContainer.find('.update-message:not(".as3cf-licence-notice")').hide();this.setNotice(this.getLicenseNotice())}else if(this.$noticeContainer){this.enableUpdateCheckbox();this.clearNotice()}if(!this.isAddon()){_.invoke(this.addons,"render")}};Plugin.prototype.initNoticeContainer=function(){if(this.$noticeContainer){return}if(!$listTable.is("#update-plugins-table")){const $noticeRow=$listTable.find('.plugin-update-tr[data-plugin="'+this.data.basename+'"]');if($noticeRow.length){this.$noticeContainer=$noticeRow.find(".plugin-update")}else{const colspan=this.$row.children().length;this.$row.after('<tr class="plugin-update-tr '+this.$row.attr("class")+'" '+'id="'+this.data.slug+'-update" '+'data-slug="'+this.data.slug+'" '+'data-plugin="'+this.data.basename+'" '+">"+'<td colspan="'+colspan+'" class="plugin-update colspanchange"></td>'+"</tr>");this.$row.children().css("box-shadow","none");this.$noticeContainer=$listTable.find('.plugin-update-tr[data-plugin="'+this.data.basename+'"] .plugin-update')}}else{this.$noticeContainer=this.$row.find(".plugin-title")}this.$noticeContainer.on("click",".as3cf-dbrains-check-my-licence-again a",_.bind(this.checkLicenseAgain,this))};Plugin.prototype.getLicenseNotice=function(){let message="";if(this.data.update_available){message=as3cf_dbrains.strings.update_available+" "}if(this.isAddon()){return message+as3cf_dbrains.strings.requires_parent_licence.replace("%s",this.parent.data.name)}return message+_.values(this.data.license.errors).join("")};Plugin.prototype.checkLicenseAgain=function(event){const plugin=this;const $link=$(event.target);const $spinner=$('<span class="spinner is-active as3cf-dbrains-licence-check-spinner" style="float:none; margin-top: -3px;"></span>');event.preventDefault();$link.hide().after($spinner);this.ajaxCheckLicense().done((function(data){if(plugin.isAddon()){plugin.parent.data.license.errors=data.errors;plugin.parent.render()}else{plugin.data.license.errors=data.errors;plugin.render()}})).fail((function(){plugin.setNotice(as3cf_dbrains.strings.licence_check_problem)})).always((function(){$spinner.remove()}))};Plugin.prototype.ajaxCheckLicense=function(){const prefix=this.isAddon()?this.parent.data.prefix:this.data.prefix;return $.ajax({url:ajaxurl,type:"POST",dataType:"json",cache:false,data:{action:prefix+"_check_licence",nonce:as3cf_dbrains.nonces.check_licence}})};Plugin.prototype.init=function(){this.render();if(!this.isAddon()){this.initAddons()}};Plugin.prototype.isAddon=function(){return!!this.parent};Plugin.prototype.initAddons=function(){const parent=this;this.addons=_.map(this.data.addons,(function(addonData){return new Plugin(addonData,parent)}));_.invoke(this.addons,"init")};function initialize(){_.chain(as3cf_dbrains.plugins).map((function(pluginData){return new Plugin(pluginData)})).invoke("init")}if($listTable.length){$(initialize)}})(jQuery);
|
||||
1
vendor/deliciousbrains/assets/js/plugin-update.min.js.map
vendored
Normal file
1
vendor/deliciousbrains/assets/js/plugin-update.min.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"names":["$","$listTable","Plugin","data","parent","this","$check","find","basename","$row","closest","$noticeContainer","prototype","checkAgainLink","as3cf_dbrains","strings","check_licence_again","hasLicenseErrors","license","isAddon","_","isEmpty","errors","disableUpdateCheckbox","is","prop","disabled","checked","enableUpdateCheckbox","setNotice","html","remove","append","clearNotice","plugin","$notice","when","fadeOut","done","children","css","show","render","initNoticeContainer","hide","getLicenseNotice","invoke","addons","$noticeRow","length","colspan","after","attr","slug","on","bind","checkLicenseAgain","message","update_available","requires_parent_licence","replace","name","values","join","event","$link","target","$spinner","preventDefault","ajaxCheckLicense","fail","licence_check_problem","always","prefix","ajax","url","ajaxurl","type","dataType","cache","action","nonce","nonces","check_licence","init","initAddons","map","addonData","initialize","chain","plugins","pluginData","jQuery"],"sources":["vendor/deliciousbrains/assets/js/plugin-update.js"],"mappings":"CAAA,SAAWA,GAQV,MAAMC,WAAaD,EAAG,gDAStB,MAAME,OAAS,SAAUC,KAAMC,QAM9BC,KAAKF,KAAOA,KAMZE,KAAKD,OAASA,OAMdC,KAAKC,OAASL,WAAWM,KAAM,yBAA2BJ,KAAKK,SAAW,MAM1EH,KAAKI,KAAOJ,KAAKC,OAAOI,QAAS,MAUjCL,KAAKM,iBAAmB,IACzB,EAOAT,OAAOU,UAAUC,eAAiB,WACjC,MAAO,mEAAqEC,cAAcC,QAAQC,oBAAsB,aACzH,EAOAd,OAAOU,UAAUK,iBAAmB,WACnC,MAAMC,QAAUb,KAAKc,UAAYd,KAAKD,OAAOD,KAAKe,QAAUb,KAAKF,KAAKe,QAEtE,OAAQE,EAAEC,QAASH,QAAQI,OAC5B,EAKApB,OAAOU,UAAUW,sBAAwB,WACxC,GAAKtB,WAAWuB,GAAI,yBAA4B,CAC/CnB,KAAKC,OAAOmB,KAAM,CACjBC,SAAU,KACVC,QAAS,OAEX,CACD,EAKAzB,OAAOU,UAAUgB,qBAAuB,WACvC,GAAK3B,WAAWuB,GAAI,yBAA4B,CAC/CnB,KAAKC,OAAOmB,KAAM,CACjBC,SAAU,OAEZ,CACD,EAOAxB,OAAOU,UAAUiB,UAAY,SAAUC,MACtCzB,KAAKM,iBAAiBJ,KAAM,yBAA0BwB,SACtD1B,KAAKM,iBAAiBqB,OACrB,4FACA,2BAA6BF,KAAOzB,KAAKQ,iBAAmB,OAC5D,SAEF,EAKAX,OAAOU,UAAUqB,YAAc,WAC9B,MAAMC,OAAS7B,KACf,MAAM8B,QAAU9B,KAAKM,iBAAiBJ,KAAM,yBAE5CP,EAAEoC,KAAMD,QAAQE,WAAYC,MAAM,WACjCH,QAAQJ,SACRG,OAAOzB,KAAK8B,WAAWC,IAAK,aAAc,IAC1CN,OAAOvB,iBAAiBJ,KAAM,mBAAoBkC,MACnD,GACD,EAKAvC,OAAOU,UAAU8B,OAAS,WACzB,GAAKrC,KAAKY,mBAAqB,CAC9BZ,KAAKsC,sBACLtC,KAAKkB,wBACLlB,KAAKM,iBAAiBJ,KAAM,gDAAiDqC,OAC7EvC,KAAKwB,UAAWxB,KAAKwC,mBACtB,MAAO,GAAKxC,KAAKM,iBAAmB,CACnCN,KAAKuB,uBACLvB,KAAK4B,aACN,CAEA,IAAM5B,KAAKc,UAAY,CACtBC,EAAE0B,OAAQzC,KAAK0C,OAAQ,SACxB,CACD,EAKA7C,OAAOU,UAAU+B,oBAAsB,WACtC,GAAKtC,KAAKM,iBAAmB,CAC5B,MACD,CAGA,IAAMV,WAAWuB,GAAI,yBAA4B,CAGhD,MAAMwB,WAAa/C,WAAWM,KAAM,kCAAoCF,KAAKF,KAAKK,SAAW,MAE7F,GAAKwC,WAAWC,OAAS,CACxB5C,KAAKM,iBAAmBqC,WAAWzC,KAAM,iBAC1C,KAAO,CAEN,MAAM2C,QAAU7C,KAAKI,KAAK8B,WAAWU,OAGrC5C,KAAKI,KAAK0C,MACT,+BAAiC9C,KAAKI,KAAK2C,KAAM,SAAY,KAC7D,OAAS/C,KAAKF,KAAKkD,KAAO,YAC1B,cAAgBhD,KAAKF,KAAKkD,KAAO,KACjC,gBAAkBhD,KAAKF,KAAKK,SAAW,KACvC,IACA,gBAAkB0C,QAAU,8CAC5B,SAID7C,KAAKI,KAAK8B,WAAWC,IAAK,aAAc,QAExCnC,KAAKM,iBAAmBV,WAAWM,KAAM,kCAAoCF,KAAKF,KAAKK,SAAW,oBACnG,CACD,KAAO,CAENH,KAAKM,iBAAmBN,KAAKI,KAAKF,KAAM,gBACzC,CAGAF,KAAKM,iBAAiB2C,GAAI,QAAS,0CAA2ClC,EAAEmC,KAAMlD,KAAKmD,kBAAmBnD,MAC/G,EAOAH,OAAOU,UAAUiC,iBAAmB,WACnC,IAAIY,QAAU,GAEd,GAAKpD,KAAKF,KAAKuD,iBAAmB,CACjCD,QAAU3C,cAAcC,QAAQ2C,iBAAmB,GACpD,CAEA,GAAKrD,KAAKc,UAAY,CACrB,OAAOsC,QAAU3C,cAAcC,QAAQ4C,wBAAwBC,QAAS,KAAMvD,KAAKD,OAAOD,KAAK0D,KAChG,CAEA,OAAOJ,QAAUrC,EAAE0C,OAAQzD,KAAKF,KAAKe,QAAQI,QAASyC,KAAM,GAC7D,EAOA7D,OAAOU,UAAU4C,kBAAoB,SAAUQ,OAC9C,MAAM9B,OAAS7B,KACf,MAAM4D,MAAQjE,EAAGgE,MAAME,QACvB,MAAMC,SAAWnE,EAAG,qHAEpBgE,MAAMI,iBAENH,MAAMrB,OAAOO,MAAOgB,UAEpB9D,KAAKgE,mBACH/B,MAAM,SAAUnC,MAChB,GAAK+B,OAAOf,UAAY,CACvBe,OAAO9B,OAAOD,KAAKe,QAAQI,OAASnB,KAAKmB,OACzCY,OAAO9B,OAAOsC,QACf,KAAO,CACNR,OAAO/B,KAAKe,QAAQI,OAASnB,KAAKmB,OAClCY,OAAOQ,QACR,CACD,IACC4B,MAAM,WACNpC,OAAOL,UAAWf,cAAcC,QAAQwD,sBACzC,IACCC,QAAQ,WACRL,SAASpC,QACV,GAEF,EAOA7B,OAAOU,UAAUyD,iBAAmB,WACnC,MAAMI,OAASpE,KAAKc,UAAYd,KAAKD,OAAOD,KAAKsE,OAASpE,KAAKF,KAAKsE,OAEpE,OAAOzE,EAAE0E,KAAM,CACdC,IAAKC,QACLC,KAAM,OACNC,SAAU,OACVC,MAAO,MACP5E,KAAM,CACL6E,OAAQP,OAAS,iBACjBQ,MAAOnE,cAAcoE,OAAOC,gBAG/B,EAKAjF,OAAOU,UAAUwE,KAAO,WACvB/E,KAAKqC,SAEL,IAAMrC,KAAKc,UAAY,CACtBd,KAAKgF,YACN,CACD,EAOAnF,OAAOU,UAAUO,QAAU,WAC1B,QAASd,KAAKD,MACf,EAKAF,OAAOU,UAAUyE,WAAa,WAC7B,MAAMjF,OAASC,KAEfA,KAAK0C,OAAS3B,EAAEkE,IAAKjF,KAAKF,KAAK4C,QAAQ,SAAUwC,WAChD,OAAO,IAAIrF,OAAQqF,UAAWnF,OAC/B,IAEAgB,EAAE0B,OAAQzC,KAAK0C,OAAQ,OACxB,EAKA,SAASyC,aACRpE,EAAEqE,MAAO3E,cAAc4E,SACrBJ,KAAK,SAAUK,YACf,OAAO,IAAIzF,OAAQyF,WACpB,IACC7C,OAAQ,OACX,CAEA,GAAK7C,WAAWgD,OAAS,CACxBjD,EAAGwF,WACJ,CACA,EApTD,CAoTII","ignoreList":[]}
|
||||
16
vendor/deliciousbrains/autoloader.php
vendored
Normal file
16
vendor/deliciousbrains/autoloader.php
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
$mapping = array(
|
||||
'Delicious_Brains_API' => __DIR__ . '/api.php',
|
||||
'Delicious_Brains_API_Plugin' => __DIR__ . '/plugin.php',
|
||||
'Delicious_Brains_API_Base' => __DIR__ . '/base.php',
|
||||
'Delicious_Brains_API_Licences' => __DIR__ . '/licences.php',
|
||||
'Delicious_Brains_API_Updates' => __DIR__ . '/updates.php',
|
||||
);
|
||||
|
||||
spl_autoload_register( function ( $class ) use ( $mapping ) {
|
||||
if ( isset( $mapping[ $class ] ) ) {
|
||||
require $mapping[ $class ];
|
||||
}
|
||||
}, true );
|
||||
|
||||
280
vendor/deliciousbrains/base.php
vendored
Normal file
280
vendor/deliciousbrains/base.php
vendored
Normal file
@@ -0,0 +1,280 @@
|
||||
<?php
|
||||
/**
|
||||
* API Base Class
|
||||
*
|
||||
* @package deliciousbrains
|
||||
* @subpackage api/base
|
||||
* @copyright Copyright (c) 2015, Delicious Brains
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delicious_Brains_API_Base Class
|
||||
*
|
||||
* This class handles communication with the Delicious Brains WooCommerce API
|
||||
*
|
||||
* @since 0.1
|
||||
*/
|
||||
class Delicious_Brains_API_Base extends Delicious_Brains_API {
|
||||
|
||||
/**
|
||||
* @var Delicious_Brains_API_Plugin
|
||||
*/
|
||||
public $plugin;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $home_url;
|
||||
|
||||
/**
|
||||
* @param Delicious_Brains_API_Plugin $plugin
|
||||
*/
|
||||
function __construct( Delicious_Brains_API_Plugin $plugin ) {
|
||||
$this->plugin = $plugin;
|
||||
$this->home_url = $this->get_home_url();
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get home URL.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_home_url() {
|
||||
$home_url = get_option( 'home' );
|
||||
|
||||
if ( is_multisite() && $this->plugin->is_network_activated ) {
|
||||
// Make sure always use the network URL in API communication
|
||||
$current_site = get_current_site();
|
||||
$home_url = 'http://' . $current_site->domain;
|
||||
}
|
||||
|
||||
return untrailingslashit( set_url_scheme( $home_url, 'http' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the API URL
|
||||
*
|
||||
* @param string $request
|
||||
* @param array $args
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_url( $request, $args = array() ) {
|
||||
$url = $this->api_url;
|
||||
$args['request'] = $request;
|
||||
$args['product'] = $this->plugin->slug;
|
||||
$args['version'] = $this->plugin->version;
|
||||
$args['locale'] = urlencode( get_locale() );
|
||||
$args['php_version'] = urlencode( phpversion() );
|
||||
$args['wordpress_version'] = urlencode( get_bloginfo( 'version' ) );
|
||||
|
||||
$args = apply_filters( $this->plugin->prefix . '_' . $request . '_request_args', $args );
|
||||
|
||||
if ( false !== get_site_transient( 'dbrains_temporarily_disable_ssl' ) && 0 === strpos( $this->api_url, 'https://' ) ) {
|
||||
$url = substr_replace( $url, 'http', 0, 5 );
|
||||
}
|
||||
|
||||
$url = add_query_arg( $args, $url );
|
||||
|
||||
return esc_url_raw( $url );
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function for communicating with the Delicious Brains API.
|
||||
*
|
||||
* @param string $request
|
||||
* @param array $args
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
function api_request( $request, $args = array() ) {
|
||||
if ( ( $check = $this->check_api_down() ) ) {
|
||||
return $check;
|
||||
}
|
||||
|
||||
$url = $this->get_url( $request, $args );
|
||||
$response = $this->get( $url );
|
||||
|
||||
if ( is_wp_error( $response ) || (int) $response['response']['code'] < 200 || (int) $response['response']['code'] > 399 ) {
|
||||
// Couldn't connect successfully to the API
|
||||
$this->log_error( $response );
|
||||
|
||||
if ( true === $this->is_api_down() ) {
|
||||
// API is down
|
||||
return $this->check_api_down();
|
||||
}
|
||||
|
||||
return $this->connection_failed_response();
|
||||
}
|
||||
|
||||
return $response['body'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a warning notice if the API is down as a response to an API request
|
||||
*
|
||||
* @return bool|mixed|string|void
|
||||
*/
|
||||
function check_api_down() {
|
||||
$trans = get_site_transient( 'dbrains_api_down' );
|
||||
|
||||
if ( false !== $trans ) {
|
||||
$api_down_message = sprintf( '<div class="dbrains-api-down updated warning inline-message">%s</div>', $trans );
|
||||
|
||||
return json_encode( array( 'dbrains_api_down' => $api_down_message ) );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a connection failed notice as a response to an API request
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function connection_failed_response() {
|
||||
$connection_failed_message = __( '<strong>Could not connect to deliciousbrains.com</strong> — You will not receive update notifications or be able to activate your license until this is fixed.' );
|
||||
$connection_failed_message .= '</p><p>';
|
||||
|
||||
if ( defined( 'WP_HTTP_BLOCK_EXTERNAL' ) && WP_HTTP_BLOCK_EXTERNAL ) {
|
||||
$url_parts = parse_url( $this->api_base );
|
||||
$host = $url_parts['host'];
|
||||
if ( ! defined( 'WP_ACCESSIBLE_HOSTS' ) || strpos( WP_ACCESSIBLE_HOSTS, $host ) === false ) {
|
||||
$connection_failed_message .= sprintf( __( 'We\'ve detected that <code>WP_HTTP_BLOCK_EXTERNAL</code> is enabled and the host <strong>%1$s</strong> has not been added to <code>WP_ACCESSIBLE_HOSTS</code>. Please disable <code>WP_HTTP_BLOCK_EXTERNAL</code> or add <strong>%1$s</strong> to <code>WP_ACCESSIBLE_HOSTS</code> to continue. <a href="%2$s" target="_blank">More information</a>' ), esc_attr( $host ), 'https://deliciousbrains.com/wp-migrate-db-pro/doc/wp_http_block_external/' );
|
||||
}
|
||||
} else {
|
||||
$disable_ssl_url = $this->admin_url( $this->plugin->settings_url_path . '&nonce=' . wp_create_nonce( $this->plugin->prefix . '-disable-ssl' ) . '&' . $this->plugin->prefix . '-disable-ssl=1' );
|
||||
$connection_failed_message .= sprintf( __( 'This issue is often caused by an improperly configured SSL server (https). We recommend <a href="%1$s" target="_blank" class="help">fixing the SSL configuration on your server</a>, but if you need a quick fix you can %2$s' ), 'https://deliciousbrains.com/wp-migrate-db-pro/doc/could-not-connect-deliciousbrains-com/', sprintf( '<a href="%1$s" class="temporarily-disable-ssl">%2$s</a>', $disable_ssl_url, __( 'temporarily disable SSL for connections to deliciousbrains.com.' ) ) );
|
||||
}
|
||||
|
||||
return json_encode( array( 'errors' => array( 'connection_failed' => $connection_failed_message ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the Delicious Brains API down?
|
||||
*
|
||||
* If not available then a 'dbrains_api_down' transient will be set with an appropriate message.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_api_down() {
|
||||
if ( false !== get_site_transient( 'dbrains_api_down' ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$response = $this->get( $this->api_status_url );
|
||||
|
||||
// Can't get to api status url so fall back to normal failure handling.
|
||||
if ( is_wp_error( $response ) || 200 != (int) $response['response']['code'] || empty( $response['body'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$json = json_decode( $response['body'], true );
|
||||
|
||||
// Can't decode json so fall back to normal failure handling.
|
||||
if ( ! $json ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Decoded JSON data doesn't seem to be the format we expect or is not down, so fall back to normal failure handling.
|
||||
if ( ! isset( $json['api']['status'] ) || 'down' != $json['api']['status'] ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$message = $this->get_down_message( $json['api'] );
|
||||
|
||||
set_site_transient( 'dbrains_api_down', $message, $this->transient_retry_timeout );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Form the error message about the API being down
|
||||
*
|
||||
* @param array $response
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_down_message( $response ) {
|
||||
$message = __( "<strong>Delicious Brains API is Down — </strong>Unfortunately we're experiencing some problems with our server." );
|
||||
|
||||
if ( ! empty( $response['updated'] ) ) {
|
||||
$updated = $response['updated'];
|
||||
$updated_ago = sprintf( _x( '%s ago', 'ex. 2 hours ago' ), human_time_diff( strtotime( $updated ) ) );
|
||||
}
|
||||
|
||||
if ( ! empty( $response['message'] ) ) {
|
||||
$message .= '<br />';
|
||||
$message .= __( "Here's the most recent update on its status" );
|
||||
if ( ! empty( $updated_ago ) ) {
|
||||
$message .= ' (' . $updated_ago . ')';
|
||||
}
|
||||
$message .= ': <em>' . $response['message'] . '</em>';
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default request arguments passed to an HTTP request
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @see wp_remote_request() For more information on the available arguments.
|
||||
*/
|
||||
protected function get_default_request_args() {
|
||||
return array(
|
||||
'timeout' => 10,
|
||||
'blocking' => true,
|
||||
'sslverify' => $this->verify_ssl(),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the url to the admin area for the site.
|
||||
* Handles if the plugin is a network activated plugin.
|
||||
*
|
||||
* @param string $path Optional path relative to the admin url
|
||||
*
|
||||
* @return string|void
|
||||
*/
|
||||
public function admin_url( $path ) {
|
||||
if ( $this->plugin->is_network_activated ) {
|
||||
$url = network_admin_url( $path );
|
||||
} else {
|
||||
$url = admin_url( $path );
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Error log method
|
||||
*
|
||||
* phpcs:disable WordPress.PHP.DevelopmentFunctions
|
||||
*
|
||||
* @param mixed $error
|
||||
* @param bool $additional_error_var
|
||||
*/
|
||||
function log_error( $error, $additional_error_var = false ) {
|
||||
error_log( print_r( $error, true ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Use SSL verification for requests
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function verify_ssl() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
560
vendor/deliciousbrains/licences.php
vendored
Normal file
560
vendor/deliciousbrains/licences.php
vendored
Normal file
@@ -0,0 +1,560 @@
|
||||
<?php
|
||||
/**
|
||||
* Licence Class
|
||||
*
|
||||
* @package deliciousbrains
|
||||
* @subpackage api/licences
|
||||
* @copyright Copyright (c) 2015, Delicious Brains
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delicious_Brains_API_Licences Class
|
||||
*
|
||||
* This class handles the licencing calls with the Delicious Brains WooCommerce API
|
||||
*
|
||||
* @since 0.1
|
||||
*/
|
||||
abstract class Delicious_Brains_API_Licences extends Delicious_Brains_API_Base {
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $addons;
|
||||
|
||||
/**
|
||||
* @var Delicious_Brains_API_Updates
|
||||
*/
|
||||
protected $updates;
|
||||
|
||||
/**
|
||||
* @param Delicious_Brains_API_Plugin $plugin
|
||||
*/
|
||||
function __construct( Delicious_Brains_API_Plugin $plugin ) {
|
||||
parent::__construct( $plugin );
|
||||
|
||||
$this->actions();
|
||||
$this->set_addons();
|
||||
|
||||
// Fire up the plugin updates
|
||||
$this->updates = new Delicious_Brains_API_Updates( $this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire up the actions for the licenses
|
||||
*/
|
||||
public function actions() {
|
||||
add_action( $this->plugin->load_hook, array( $this, 'remove_licence_when_constant_set' ) );
|
||||
add_action( $this->plugin->load_hook, array( $this, 'http_disable_ssl' ) );
|
||||
add_action( $this->plugin->load_hook, array( $this, 'http_refresh_licence' ) );
|
||||
|
||||
add_action( 'wp_ajax_' . $this->plugin->prefix . '_check_licence', array( $this, 'ajax_check_licence' ) );
|
||||
add_action( 'wp_ajax_' . $this->plugin->prefix . '_reactivate_licence', array( $this, 'ajax_reactivate_licence' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the addons available for the plugin
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function set_addons() {
|
||||
if ( is_null( $this->addons ) ) {
|
||||
$meta_key = $this->plugin->get_global_meta_key();
|
||||
|
||||
$addons = array();
|
||||
|
||||
if ( isset( $GLOBALS[ $meta_key ][ $this->plugin->slug ]['supported_addon_versions'] ) ) {
|
||||
$available_addons = get_site_transient( $this->plugin->prefix . '_addons_available' );
|
||||
|
||||
foreach ( $GLOBALS[ $meta_key ][ $this->plugin->slug ]['supported_addon_versions'] as $addon => $version ) {
|
||||
$basename = $this->plugin->get_plugin_basename( $addon );
|
||||
$name = $this->plugin->get_plugin_name( $addon );
|
||||
$installed = file_exists( WP_PLUGIN_DIR . '/' . $basename );
|
||||
|
||||
$addons[ $basename ] = array(
|
||||
'name' => $name,
|
||||
'slug' => $addon,
|
||||
'basename' => $basename,
|
||||
'required_version' => $version,
|
||||
'available' => ( false === $available_addons || isset( $available_addons[ $addon ] ) ),
|
||||
'installed' => $installed,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$this->addons = $addons;
|
||||
}
|
||||
|
||||
return $this->addons;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get method for returning the license key from the database
|
||||
* that must be defined by the extending class
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function get_plugin_licence_key();
|
||||
|
||||
/**
|
||||
* Set method for saving the license key to the database
|
||||
* that must be defined by the extending class
|
||||
*
|
||||
* @param string $key
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
abstract protected function set_plugin_licence_key( $key );
|
||||
|
||||
/**
|
||||
* Get the name of the license constant
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function get_licence_constant_name() {
|
||||
return strtoupper( $this->plugin->prefix ) . '_LICENCE';
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the license key defined as a constant?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_licence_constant() {
|
||||
return defined( $this->get_licence_constant_name() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the license key either from a constant or saved by the plugin
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_licence_key() {
|
||||
if ( $this->is_licence_constant() ) {
|
||||
$licence = constant( $this->get_licence_constant_name() );
|
||||
} else {
|
||||
$licence = $this->get_plugin_licence_key();
|
||||
}
|
||||
|
||||
return $licence;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the licence key
|
||||
*
|
||||
* @param string $key
|
||||
*/
|
||||
protected function set_licence_key( $key ) {
|
||||
$this->set_plugin_licence_key( $key );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the saved licence has expired or not.
|
||||
*
|
||||
* @param bool $skip_transient_check
|
||||
* @param bool $skip_expired_check
|
||||
* @param array $licence_response Optional pre-fetched licence response data.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_valid_licence( $skip_transient_check = false, $skip_expired_check = true, $licence_response = array() ) {
|
||||
if ( ! empty( $licence_response ) && is_array( $licence_response ) ) {
|
||||
$response = $licence_response;
|
||||
} else {
|
||||
$response = $this->is_licence_expired( $skip_transient_check );
|
||||
}
|
||||
|
||||
if ( isset( $response['dbrains_api_down'] ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( $this->plugin->expired_licence_is_valid && isset( $response['errors']['subscription_expired'] ) && 1 === count( $response['errors'] ) ) {
|
||||
// Maybe don't cripple the plugin's functionality if the user's licence is expired.
|
||||
return $skip_expired_check;
|
||||
}
|
||||
|
||||
return ! isset( $response['errors'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the license has expired
|
||||
*
|
||||
* @param bool $skip_transient_check
|
||||
*
|
||||
* @return array|mixed
|
||||
*/
|
||||
public function is_licence_expired( $skip_transient_check = false ) {
|
||||
$licence = $this->get_licence_key();
|
||||
|
||||
if ( empty( $licence ) ) {
|
||||
$settings_link = sprintf( '<a href="%s" class="js-action-link as3cf-enter-licence">%s</a>', $this->admin_url( $this->plugin->settings_url_path ) . $this->plugin->settings_url_hash, __( 'enter your license key' ) );
|
||||
$message = sprintf( __( 'To finish activating %1$s, %2$s. If you don\'t have a license key, you may <a href="%3$s">purchase one</a>.' ), $this->plugin->name, $settings_link, $this->plugin->purchase_url );
|
||||
|
||||
return array( 'errors' => array( 'no_licence' => $message ) );
|
||||
}
|
||||
|
||||
return json_decode( $this->check_licence( $licence ), true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the license validity and fetch a response from the Delicious Brains API
|
||||
*
|
||||
* @param string $licence_key
|
||||
*
|
||||
* @return bool|mixed
|
||||
*/
|
||||
public function check_licence( $licence_key ) {
|
||||
if ( empty( $licence_key ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$response = [];
|
||||
$response['addon_list'] = '';
|
||||
$response['addons_available_list'] = '';
|
||||
$response = json_encode($response);
|
||||
$response = $this->store_licence_addon_data( $response, true );
|
||||
|
||||
$response = apply_filters( $this->plugin->prefix . '_check_licence_response', $response );
|
||||
|
||||
set_site_transient( $this->plugin->prefix . '_licence_response', $response, $this->transient_timeout );
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process and store the Addon data after a license request
|
||||
*
|
||||
* @param string|array $response
|
||||
* @param bool $encoded
|
||||
*
|
||||
* @return array|mixed|string|void
|
||||
*/
|
||||
protected function store_licence_addon_data( $response, $encoded = false ) {
|
||||
$decoded_response = $encoded ? json_decode( $response, ARRAY_A ) : $response;
|
||||
|
||||
if ( isset( $decoded_response['addon_list'] ) ) {
|
||||
// Save the addons list for use when installing
|
||||
// Don't really need to expire it ever, but let's clean it up after 60 days
|
||||
set_site_transient( $this->plugin->prefix . '_addons', $decoded_response['addon_list'], DAY_IN_SECONDS * 60 );
|
||||
}
|
||||
|
||||
if ( isset( $decoded_response['addons_available_list'] ) ) {
|
||||
// Save the available addons list for use
|
||||
set_site_transient( $this->plugin->prefix . '_addons_available', $decoded_response['addons_available_list'], DAY_IN_SECONDS * 60 );
|
||||
}
|
||||
|
||||
$response = $encoded ? json_encode( $decoded_response ) : $decoded_response;
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the license from the settings if defined as a constant
|
||||
*/
|
||||
public function remove_licence_when_constant_set() {
|
||||
$licence_key = $this->get_plugin_licence_key();
|
||||
// Remove licence from the database if constant is set
|
||||
if ( $this->is_licence_constant() && ! empty( $licence_key ) ) {
|
||||
$this->set_licence_key( '' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a formatted message dependent on the status of the licence.
|
||||
*
|
||||
* @param bool|array $trans
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_licence_status_message( $trans = false ) {
|
||||
$licence = $this->get_licence_key();
|
||||
$api_response_provided = true;
|
||||
|
||||
if ( empty( $licence ) && ! $trans ) {
|
||||
$message = sprintf( __( '<strong>Activate Your License</strong> — Please <a href="#" class="%s">enter your license key</a>.' ), 'js-action-link enter-licence' );
|
||||
|
||||
return $message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a license key formatted with HTML to mask all but the last part
|
||||
*
|
||||
* @param string $licence
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function mask_licence( $licence ) {
|
||||
$licence_parts = explode( '-', $licence );
|
||||
$i = count( $licence_parts ) - 1;
|
||||
$masked_licence = '';
|
||||
|
||||
foreach ( $licence_parts as $licence_part ) {
|
||||
if ( $i == 0 ) {
|
||||
$masked_licence .= $licence_part;
|
||||
continue;
|
||||
}
|
||||
|
||||
$masked_licence .= '<span class="bull">';
|
||||
$masked_licence .= str_repeat( '•', strlen( $licence_part ) ) . '</span>–';
|
||||
--$i;
|
||||
}
|
||||
|
||||
return $masked_licence;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to display markup of the masked license
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_formatted_masked_licence() {
|
||||
return sprintf(
|
||||
'<p class="masked-licence">%s <a href="%s">%s</a></p>',
|
||||
$this->mask_licence( $this->get_plugin_licence_key() ),
|
||||
$this->admin_url( $this->plugin->settings_url_path . '&nonce=' . wp_create_nonce( $this->plugin->prefix . '-remove-licence' ) . '&' . $this->plugin->prefix . '-remove-licence=1' . $this->plugin->settings_url_hash ),
|
||||
_x( 'Remove', 'Delete license' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for {prefix}-disable-ssl and related nonce
|
||||
* if found temporarily disable ssl via transient
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function http_disable_ssl() {
|
||||
if ( isset( $_GET[ $this->plugin->prefix . '-disable-ssl' ] ) && wp_verify_nonce( $_GET['nonce'], $this->plugin->prefix . '-disable-ssl' ) ) { // input var okay
|
||||
set_site_transient( $this->plugin->prefix . '_temporarily_disable_ssl', '1', DAY_IN_SECONDS * 30 ); // 30 days
|
||||
$hash = ( isset( $_GET['hash'] ) ) ? '#' . sanitize_title( $_GET['hash'] ) : ''; // input var okay
|
||||
// delete the licence transient as we want to attempt to fetch the licence details again
|
||||
delete_site_transient( $this->plugin->prefix . '_licence_response' );
|
||||
// redirecting here because we don't want to keep the query string in the web browsers address bar
|
||||
wp_redirect( $this->admin_url( $this->plugin->settings_url_path . $hash ) );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the license.
|
||||
*/
|
||||
public function remove() {
|
||||
$this->set_licence_key( '' );
|
||||
|
||||
// Delete these transients as they contain information only valid for authenticated licence holders.
|
||||
delete_site_transient( 'update_plugins' );
|
||||
delete_site_transient( $this->plugin->prefix . '_upgrade_data' );
|
||||
delete_site_transient( $this->plugin->prefix . '_licence_response' );
|
||||
delete_site_transient( $this->plugin->prefix . '_addons_available' );
|
||||
delete_site_transient( $this->plugin->prefix . '_licence_media_check' );
|
||||
|
||||
do_action( $this->plugin->prefix . '_http_remove_licence' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for {prefix}-check-licence and related nonce
|
||||
* if found refresh licence details
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function http_refresh_licence() {
|
||||
if ( isset( $_GET[ $this->plugin->prefix . '-check-licence' ] ) && wp_verify_nonce( $_GET['nonce'], $this->plugin->prefix . '-check-licence' ) ) { // input var okay
|
||||
$hash = ( isset( $_GET['hash'] ) ) ? '#' . sanitize_title( $_GET['hash'] ) : ''; // input var okay
|
||||
// delete the licence transient as we want to attempt to fetch the licence details again
|
||||
delete_site_transient( $this->plugin->prefix . '_licence_response' );
|
||||
do_action( $this->plugin->prefix . '_http_refresh_licence' );
|
||||
|
||||
$sendback = $this->admin_url( $this->plugin->settings_url_path . $hash );
|
||||
if ( isset( $_GET['sendback'] ) ) {
|
||||
$sendback = $_GET['sendback'];
|
||||
}
|
||||
|
||||
// redirecting because we don't want to keep the query string in the web browsers address bar
|
||||
wp_redirect( esc_url_raw( $sendback ) );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate a licence.
|
||||
*
|
||||
* @param string $licence_key
|
||||
*
|
||||
* @return bool|WP_Error
|
||||
*/
|
||||
public function activate( $licence_key ) {
|
||||
if ( empty( $licence_key ) ) {
|
||||
return new WP_Error( 'missing-licence-key', __( 'Licence Key not supplied.' ) );
|
||||
}
|
||||
|
||||
// Regardless of whether the license is valid or not, save it and let status/errors deal with fallout.
|
||||
// This way license status is handled the same whether saved in db or set via define.
|
||||
$this->set_licence_key( $licence_key );
|
||||
|
||||
$api_response_json = $this->activate_licence( $licence_key, $this->home_url );
|
||||
set_site_transient( $this->plugin->prefix . '_licence_response', $api_response_json, $this->transient_timeout );
|
||||
|
||||
$api_response = json_decode( $api_response_json, true );
|
||||
$api_down = ! empty( $api_response['dbrains_api_down'] );
|
||||
$errors = isset( $api_response['errors'] ) ? $api_response['errors'] : array();
|
||||
|
||||
// Remove insignificant errors.
|
||||
unset( $errors['activation_deactivated'], $errors['subscription_expired'] );
|
||||
|
||||
if ( empty( $errors ) && ! $api_down ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// For some reason we couldn't activate the licence, reason saved in transient.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX handler for checking a licence.
|
||||
*/
|
||||
public function ajax_check_licence() {
|
||||
$this->check_ajax_referer( 'check-licence' );
|
||||
|
||||
$decoded_response = $this->check( true );
|
||||
$decoded_response = apply_filters( $this->plugin->prefix . '_ajax_check_licence_response', $decoded_response );
|
||||
|
||||
wp_send_json( $decoded_response );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a licence.
|
||||
*
|
||||
* @param bool $skip_transient_check
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function check( $skip_transient_check = false ) {
|
||||
$decoded_response = $this->is_licence_expired( $skip_transient_check );
|
||||
|
||||
if ( ! empty( $decoded_response['dbrains_api_down'] ) ) {
|
||||
$decoded_response['message'] = $this->get_default_help_message();
|
||||
} elseif ( ! empty( $decoded_response['errors'] ) ) {
|
||||
$decoded_response['htmlErrors'] = array( sprintf( '<div class="notification-message warning-notice inline-message invalid-licence">%s</div>', $this->get_licence_status_message() ) );
|
||||
} elseif ( ! empty( $decoded_response['message'] ) && ! get_site_transient( $this->plugin->prefix . '_help_message' ) ) {
|
||||
set_site_transient( $this->plugin->prefix . '_help_message', $decoded_response['message'], $this->transient_timeout );
|
||||
}
|
||||
|
||||
return $decoded_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get previously saved or fallback help message/form.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_default_help_message() {
|
||||
$help_message = get_site_transient( $this->plugin->prefix . '_help_message' );
|
||||
|
||||
if ( ! $help_message ) {
|
||||
ob_start();
|
||||
?>
|
||||
<p><?php _e( 'A problem occurred when trying to get the support request form.', 'amazon-s3-and-cloudfront' ); ?></p>
|
||||
<p><?php _e( 'If you have an <strong>active license</strong>, you may send an email to the following address.' ); ?></p>
|
||||
<p>
|
||||
<strong><?php _e( 'Please download the below Diagnostic Info and attach it to your email.' ); ?></strong>
|
||||
</p>
|
||||
<p class="email">
|
||||
<a class="button" href="mailto:<?php echo $this->plugin->get_email_address_name(); ?>@deliciousbrains.com">
|
||||
<?php echo $this->plugin->get_email_address_name(); ?>@deliciousbrains.com
|
||||
</a>
|
||||
</p>
|
||||
<?php
|
||||
$help_message = ob_get_clean();
|
||||
}
|
||||
|
||||
return $help_message;
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX handler for reactivating this instance for the activated license
|
||||
*/
|
||||
public function ajax_reactivate_licence() {
|
||||
$this->check_ajax_referer( 'reactivate-licence' );
|
||||
|
||||
$return = array();
|
||||
|
||||
$response = $this->reactivate_licence( $this->get_licence_key(), $this->home_url );
|
||||
|
||||
$decoded_response = json_decode( $response, true );
|
||||
|
||||
if ( isset( $decoded_response['dbrains_api_down'] ) ) {
|
||||
$return['dbrains_api_down'] = 1;
|
||||
|
||||
$return['body'] = $decoded_response['dbrains_api_down'];
|
||||
$this->end_ajax( json_encode( $return ) );
|
||||
}
|
||||
|
||||
if ( isset( $decoded_response['errors'] ) ) {
|
||||
$return[ $this->plugin->prefix . '_error' ] = 1;
|
||||
|
||||
$return['body'] = reset( $decoded_response['errors'] );
|
||||
$this->log_error( $return['body'], $decoded_response );
|
||||
$this->end_ajax( json_encode( $return ) );
|
||||
}
|
||||
|
||||
delete_site_transient( $this->plugin->prefix . '_upgrade_data' );
|
||||
delete_site_transient( $this->plugin->prefix . '_licence_response' );
|
||||
|
||||
$this->end_ajax( json_encode( array() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to end an AJAX request
|
||||
*
|
||||
* @param bool|string $return
|
||||
*/
|
||||
protected function end_ajax( $return = false ) {
|
||||
echo ( false === $return ) ? '' : $return;
|
||||
wp_die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom verification of the AJAX request to prevent processing requests
|
||||
*
|
||||
* @param string $action Action nonce name
|
||||
*/
|
||||
protected function check_ajax_referer( $action ) {
|
||||
$result = check_ajax_referer( $action, 'nonce', false );
|
||||
|
||||
if ( false === $result ) {
|
||||
$return = array(
|
||||
$this->plugin->prefix . '_error' => 1,
|
||||
'body' => sprintf( __( 'Invalid nonce for: %s' ), $action ),
|
||||
);
|
||||
$this->end_ajax( json_encode( $return ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the raw licence masked with bullets except for the last segment.
|
||||
*
|
||||
* @return bool|string false if no licence, masked string otherwise.
|
||||
*/
|
||||
public function get_masked_licence() {
|
||||
$licence_key = $this->get_licence_key();
|
||||
|
||||
if ( ! $licence_key ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$licence_segments = explode( '-', $licence_key );
|
||||
$visible_segment = array_pop( $licence_segments );
|
||||
$masked_segments = array_map( function ( $segment ) {
|
||||
return str_repeat( '•', strlen( $segment ) );
|
||||
}, $licence_segments );
|
||||
$masked_segments[] = $visible_segment;
|
||||
|
||||
return join( '-', $masked_segments );
|
||||
}
|
||||
}
|
||||
204
vendor/deliciousbrains/plugin.php
vendored
Normal file
204
vendor/deliciousbrains/plugin.php
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Class
|
||||
*
|
||||
* @package deliciousbrains
|
||||
* @subpackage api/plugin
|
||||
* @copyright Copyright (c) 2015, Delicious Brains
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delicious_Brains_API_Plugin Class
|
||||
*
|
||||
* This class holds all the information about the plugin used by the common API classes
|
||||
*
|
||||
* @since 0.1
|
||||
*/
|
||||
class Delicious_Brains_API_Plugin {
|
||||
|
||||
/**
|
||||
* @var string Plugin slug
|
||||
*/
|
||||
public $slug;
|
||||
/**
|
||||
* @var string Plugin name
|
||||
*/
|
||||
public $name;
|
||||
/**
|
||||
* @var string Plugin version
|
||||
*/
|
||||
public $version;
|
||||
/**
|
||||
* @var string Plugin basename
|
||||
*/
|
||||
public $basename;
|
||||
/**
|
||||
* @var string Plugin Directory Path
|
||||
*/
|
||||
public $dir_path;
|
||||
/**
|
||||
* @var string Prefix to use in nonces and transients
|
||||
*/
|
||||
public $prefix;
|
||||
/**
|
||||
* @var string Path for the URL to the plugin's settings page, passed to admin_url()
|
||||
*/
|
||||
public $settings_url_path;
|
||||
/**
|
||||
* @var string Hash for the URL to the plugin's settings page, passed to admin_url()
|
||||
*/
|
||||
public $settings_url_hash;
|
||||
/**
|
||||
* @var string Hook for the plugin's menu
|
||||
*/
|
||||
public $hook_suffix;
|
||||
/**
|
||||
* @var bool For Multisite installs is the plugin network activated
|
||||
*/
|
||||
public $is_network_activated = true;
|
||||
/**
|
||||
* @var bool Do we allow expired licenses as valid, ie. we don't cripple functionality
|
||||
*/
|
||||
public $expired_licence_is_valid = true;
|
||||
/**
|
||||
* @var string name of email address, usually the same as the prefix
|
||||
*/
|
||||
public $email_address_name;
|
||||
/**
|
||||
* @var string prefix of the global meta data for the plugins
|
||||
*/
|
||||
public $global_meta_prefix;
|
||||
/**
|
||||
* @var string Action hook used to display notices in the plugin
|
||||
*/
|
||||
public $notices_hook;
|
||||
/**
|
||||
* @var string Action hook fired on plugin page load
|
||||
*/
|
||||
public $load_hook;
|
||||
/**
|
||||
* @var string URL to purchase a license for the plugin
|
||||
*/
|
||||
public $purchase_url;
|
||||
/**
|
||||
* @var string URL to view licenses
|
||||
*/
|
||||
public $licenses_url;
|
||||
/**
|
||||
* @var string URL to access My Account of Delicious Brains
|
||||
*/
|
||||
public $account_url = 'https://deliciousbrains.com/my-account/';
|
||||
|
||||
/**
|
||||
* Return the name of the email address.
|
||||
* This is by default the plugin prefix
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_email_address_name() {
|
||||
if ( $this->email_address_name ) {
|
||||
return $this->email_address_name;
|
||||
}
|
||||
|
||||
return $this->prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the key for the global meta where all the version info is stored
|
||||
* for the plugin and addons.
|
||||
*
|
||||
* @param string $suffix
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_global_meta_key( $suffix = 'meta' ) {
|
||||
$prefix = $this->prefix;
|
||||
if ( $this->global_meta_prefix ) {
|
||||
$prefix = $this->global_meta_prefix;
|
||||
}
|
||||
|
||||
return $prefix . '_' . $suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a plugin basename for one of our plugins.
|
||||
* This is made up of the plugin folder and filename.
|
||||
*
|
||||
* @param string $slug
|
||||
*
|
||||
* @return string eg. 'akismet/akismet.php'
|
||||
*/
|
||||
function get_plugin_basename( $slug ) {
|
||||
$meta_key = $this->get_global_meta_key();
|
||||
if ( ! isset( $GLOBALS[ $meta_key ][ $slug ]['folder'] ) ) {
|
||||
$plugin_folder = $slug;
|
||||
} else {
|
||||
$plugin_folder = $GLOBALS[ $meta_key ][ $slug ]['folder'];
|
||||
}
|
||||
|
||||
$plugin_basename = sprintf( '%s/%s.php', $plugin_folder, $slug );
|
||||
|
||||
return $plugin_basename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data for a plugin
|
||||
*
|
||||
* @param string $slug
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
function get_plugin_data( $slug ) {
|
||||
$plugin_path = WP_PLUGIN_DIR . '/' . $this->get_plugin_basename( $slug );
|
||||
if ( file_exists( $plugin_path ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
$plugin_data = get_plugin_data( $plugin_path );
|
||||
if ( ! empty( $plugin_data['Name'] ) ) {
|
||||
return $plugin_data;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of a plugin
|
||||
*
|
||||
* @param string $slug
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_plugin_name( $slug ) {
|
||||
$data = $this->get_plugin_data( $slug );
|
||||
if ( $data && ! empty( $data['Name'] ) ) {
|
||||
$name = $data['Name'];
|
||||
} else {
|
||||
$name = ucwords( str_replace( '-', ' ', $slug ) );
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the installed version of a plugin
|
||||
*
|
||||
* @param string $slug
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
function get_plugin_version( $slug ) {
|
||||
$data = $this->get_plugin_data( $slug );
|
||||
if ( $data && ! empty( $data['Version'] ) ) {
|
||||
return $data['Version'];
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
699
vendor/deliciousbrains/updates.php
vendored
Normal file
699
vendor/deliciousbrains/updates.php
vendored
Normal file
@@ -0,0 +1,699 @@
|
||||
<?php
|
||||
/**
|
||||
* Updates Class
|
||||
*
|
||||
* @package deliciousbrains
|
||||
* @subpackage api/updates
|
||||
* @copyright Copyright (c) 2015, Delicious Brains
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delicious_Brains_API_Updates Class
|
||||
*
|
||||
* This class handles the updates to a plugin
|
||||
*
|
||||
* @since 0.1
|
||||
*/
|
||||
class Delicious_Brains_API_Updates {
|
||||
|
||||
/**
|
||||
* @var Delicious_Brains_API_Licences
|
||||
*/
|
||||
protected $licences;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $plugin_notices = array();
|
||||
|
||||
/**
|
||||
* Initiate update class
|
||||
*
|
||||
* @param Delicious_Brains_API_Licences $licences
|
||||
*/
|
||||
function __construct( Delicious_Brains_API_Licences $licences ) {
|
||||
$this->licences = $licences;
|
||||
|
||||
if ( ( is_admin() ) || is_network_admin() || ( defined( 'WP_CLI' ) && class_exists( 'WP_CLI' ) ) ) {
|
||||
add_filter( 'plugins_api', array( $this, 'short_circuit_wordpress_org_plugin_info_request' ), 10, 3 );
|
||||
add_filter( 'http_response', array( $this, 'verify_download' ), 10, 3 );
|
||||
add_filter( 'plugins_api', array( $this, 'inject_addon_install_resource' ), 10, 3 );
|
||||
|
||||
add_action( 'current_screen', array( $this, 'check_again_clear_transients' ) );
|
||||
}
|
||||
|
||||
$this->add_plugin_notice( $this->licences->plugin->basename );
|
||||
if ( $this->licences->addons ) {
|
||||
foreach ( $this->licences->addons as $basename => $addon ) {
|
||||
if ( ! ( $addon['available'] && $addon['installed'] ) ) {
|
||||
// Only register addons for updates that are installed and available for license
|
||||
continue;
|
||||
}
|
||||
$this->add_plugin_notice( $basename );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add handlers for displaying update notices for a plugin on our settings page.
|
||||
*
|
||||
* @param string $basename
|
||||
*/
|
||||
public function add_plugin_notice( string $basename ) {
|
||||
if ( empty( $basename ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->plugin_notices[ $basename ] = $basename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return update notice info for a plugin on our settings page.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_plugin_update_notices(): array {
|
||||
$notices = array();
|
||||
|
||||
if ( ! empty( $this->plugin_notices ) ) {
|
||||
foreach ( $this->plugin_notices as $basename ) {
|
||||
$notice = $this->version_update_notice( $basename );
|
||||
|
||||
if ( ! empty( $notice ) ) {
|
||||
$notices[] = $notice;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $notices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the plugin to the array of plugins used by the update JS
|
||||
*
|
||||
* @param array $plugins
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register_plugin_for_updates( $plugins ) {
|
||||
$plugins[ $this->licences->plugin->slug ] = array_merge(
|
||||
(array) $this->licences->plugin,
|
||||
array(
|
||||
'addons' => $this->licences->addons,
|
||||
'license' => $this->licences->is_licence_expired(),
|
||||
'update_available' => $this->update_available( $this->licences->plugin->slug ),
|
||||
)
|
||||
);
|
||||
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take over the update check for plugins
|
||||
*
|
||||
* @param object $trans
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
function site_transient_update_plugins( $trans ) {
|
||||
if ( ! is_object( $trans ) ) {
|
||||
return $trans;
|
||||
}
|
||||
|
||||
if ( ! isset( $trans->response ) || ! is_array( $trans->response ) ) {
|
||||
$trans->response = array();
|
||||
}
|
||||
|
||||
if ( ! isset( $trans->no_update ) || ! is_array( $trans->no_update ) ) {
|
||||
$trans->no_update = array();
|
||||
}
|
||||
|
||||
$plugin_upgrade_data = $this->get_upgrade_data();
|
||||
|
||||
$plugin_basename = $this->licences->plugin->get_plugin_basename( $this->licences->plugin->slug );
|
||||
if ( isset( $trans->no_update[ $plugin_basename ] ) ) {
|
||||
// Ensure the pro plugin always has the correct info and WP API doesn't confuse with free version
|
||||
$trans->no_update[ $plugin_basename ]->slug = $this->licences->plugin->slug;
|
||||
$trans->no_update[ $plugin_basename ]->url = $this->licences->api_base;
|
||||
$trans->no_update[ $plugin_basename ]->new_version = $this->licences->plugin->version;
|
||||
}
|
||||
|
||||
if ( false === $plugin_upgrade_data || ! isset( $plugin_upgrade_data[ $this->licences->plugin->slug ] ) ) {
|
||||
return $trans;
|
||||
}
|
||||
|
||||
foreach ( $plugin_upgrade_data as $plugin_slug => $upgrade_data ) {
|
||||
$plugin_basename = $this->licences->plugin->get_plugin_basename( $plugin_slug );
|
||||
if ( isset( $this->licences->addons[ $plugin_basename ] ) && ! ( $this->licences->addons[ $plugin_basename ]['available'] && $this->licences->addons[ $plugin_basename ]['installed'] ) ) {
|
||||
// Addon not installed or available for license, ignore
|
||||
continue;
|
||||
}
|
||||
$installed_version = $this->get_installed_version( $plugin_slug );
|
||||
$latest_version = $this->get_latest_version( $plugin_slug, $installed_version );
|
||||
|
||||
if ( false === $installed_version || false === $latest_version ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( version_compare( $installed_version, $latest_version, '<' ) ) {
|
||||
$is_beta = $this->is_beta_version( $latest_version );
|
||||
|
||||
$trans->response[ $plugin_basename ] = new stdClass();
|
||||
$trans->response[ $plugin_basename ]->url = $this->licences->api_base;
|
||||
$trans->response[ $plugin_basename ]->slug = $plugin_slug;
|
||||
$trans->response[ $plugin_basename ]->package = $this->get_plugin_update_download_url( $plugin_slug, $is_beta );
|
||||
$trans->response[ $plugin_basename ]->new_version = $latest_version;
|
||||
$trans->response[ $plugin_basename ]->id = '0';
|
||||
$trans->response[ $plugin_basename ]->plugin = $plugin_basename;
|
||||
|
||||
if ( isset( $upgrade_data['requires_php'] ) ) {
|
||||
$trans->response[ $plugin_basename ]->requires_php = $upgrade_data['requires_php'];
|
||||
}
|
||||
|
||||
if ( isset( $upgrade_data['tested'] ) ) {
|
||||
$trans->response[ $plugin_basename ]->tested = $upgrade_data['tested'];
|
||||
}
|
||||
|
||||
if ( isset( $upgrade_data['icon_url'] ) ) {
|
||||
$trans->response[ $plugin_basename ]->icons['svg'] = $upgrade_data['icon_url'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $trans;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add some custom JS into the plugin page for our updates process
|
||||
*/
|
||||
public function enqueue_plugin_update_script() {
|
||||
$handle = 'as3cf-dbrains-plugin-update-script';
|
||||
|
||||
// This script should only be enqueued once if the site has multiple
|
||||
// Delicious Brains plugins installed
|
||||
if ( wp_script_is( $handle, 'enqueued' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$version = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? time() : $this->licences->plugin->version;
|
||||
$min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
||||
$src = plugins_url( "assets/js/plugin-update$min.js", __FILE__ );
|
||||
|
||||
wp_enqueue_script( $handle, $src, array( 'jquery', 'underscore' ), $version, true );
|
||||
|
||||
wp_localize_script( $handle,
|
||||
'as3cf_dbrains',
|
||||
array(
|
||||
'nonces' => array(
|
||||
'check_licence' => wp_create_nonce( 'check-licence' ),
|
||||
),
|
||||
'strings' => array(
|
||||
'check_licence_again' => __( 'Check My License Again' ),
|
||||
'licence_check_problem' => __( 'A problem occurred when trying to check the license, please try again.' ),
|
||||
'requires_parent_licence' => __( 'Requires a valid license for %s.' ),
|
||||
'update_available' => __( 'New version available for active subscriptions.' ),
|
||||
),
|
||||
'plugins' => apply_filters( 'as3cf_plugins', array() ),
|
||||
)
|
||||
);
|
||||
|
||||
$src = plugins_url( "assets/css/plugin-update.css", __FILE__ );
|
||||
wp_enqueue_style( $handle, $src, array(), $version );
|
||||
}
|
||||
|
||||
/**
|
||||
* Short circuits the HTTP request to WordPress.org servers to retrieve plugin information.
|
||||
* Will only fire on the update-core.php admin page.
|
||||
*
|
||||
* @param object|bool $res Plugin resource object or boolean false.
|
||||
* @param string $action The API call being performed.
|
||||
* @param object $args Arguments for the API call being performed.
|
||||
*
|
||||
* @return object|bool Plugin resource object or boolean false.
|
||||
*/
|
||||
function short_circuit_wordpress_org_plugin_info_request( $res, $action, $args ) {
|
||||
if ( 'plugin_information' != $action || empty( $args->slug ) || $this->licences->plugin->slug != $args->slug ) {
|
||||
return $res;
|
||||
}
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
// Only fire on the update-core.php admin page
|
||||
if ( empty( $screen->id ) || ( 'update-core' !== $screen->id && 'update-core-network' !== $screen->id ) ) {
|
||||
return $res;
|
||||
}
|
||||
|
||||
$res = new stdClass();
|
||||
$plugin_info = $this->get_upgrade_data();
|
||||
|
||||
if ( isset( $plugin_info[ $this->licences->plugin->slug ]['tested'] ) ) {
|
||||
$res->tested = $plugin_info[ $this->licences->plugin->slug ]['tested'];
|
||||
} else {
|
||||
$res->tested = false;
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear update transients when the user clicks the "Check Again" button from the update screen.
|
||||
*
|
||||
* @param object $current_screen
|
||||
*/
|
||||
function check_again_clear_transients( $current_screen ) {
|
||||
if ( ! isset( $current_screen->id ) || false === strpos( $current_screen->id, 'update-core' ) || ! isset( $_GET['force-check'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete_site_transient( $this->licences->plugin->prefix . '_upgrade_data' );
|
||||
delete_site_transient( 'update_plugins' );
|
||||
delete_site_transient( $this->licences->plugin->prefix . '_licence_response' );
|
||||
delete_site_transient( 'dbrains_api_down' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Display our custom plugin details when the user clicks "view details"
|
||||
* on the plugin listing page.
|
||||
*/
|
||||
function plugin_update_popup() {
|
||||
$slug = sanitize_key( $_GET['plugin'] );
|
||||
|
||||
if ( ! $this->is_plugin( $slug ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$error_msg = '<p>' . __( 'Could not retrieve version details. Please try again.' ) . '</p>';
|
||||
|
||||
$latest_version = $this->get_latest_version( $slug );
|
||||
|
||||
if ( false === $latest_version ) {
|
||||
echo $error_msg;
|
||||
exit;
|
||||
}
|
||||
|
||||
$data = $this->licences->get_changelog( $slug, $this->is_beta_version( $latest_version ) );
|
||||
|
||||
if ( is_wp_error( $data ) || empty( $data ) ) {
|
||||
echo $error_msg;
|
||||
} else {
|
||||
echo $data;
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the download URL for the plugin
|
||||
*
|
||||
* @param array $response
|
||||
* @param array $args
|
||||
* @param string $url
|
||||
*
|
||||
* @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error
|
||||
* instance upon error
|
||||
*/
|
||||
function verify_download( $response, $args, $url ) {
|
||||
if ( is_wp_error( $response ) ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$download_url = $this->get_plugin_update_download_url( $this->licences->plugin->slug );
|
||||
|
||||
if ( false === strpos( $url, $download_url ) || 402 != $response['response']['code'] ) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
// The $response['body'] is blank but output is actually saved to a file in this case
|
||||
$data = @file_get_contents( $response['filename'] ); //phpcs:ignore
|
||||
|
||||
if ( ! $data ) {
|
||||
return new WP_Error( $this->licences->plugin->prefix . '_download_error_empty', sprintf( __( 'Error retrieving download from deliciousbrain.com. Please try again or download manually from <a href="%1$s">%2$s</a>.' ), $this->licences->plugin->account_url, _x( 'My Account', 'Delicious Brains account' ) ) );
|
||||
}
|
||||
|
||||
$decoded_data = json_decode( $data, true );
|
||||
|
||||
// Can't decode the JSON errors, so just barf it all out
|
||||
if ( ! isset( $decoded_data['errors'] ) || ! $decoded_data['errors'] ) {
|
||||
return new WP_Error( $this->licences->plugin->prefix . '_download_error_raw', $data );
|
||||
}
|
||||
|
||||
foreach ( $decoded_data['errors'] as $key => $msg ) {
|
||||
return new WP_Error( $this->licences->plugin->prefix . '_' . $key, $msg );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the plugin version a beta version
|
||||
*
|
||||
* @param string $ver
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function is_beta_version( $ver ) {
|
||||
if ( preg_match( '@b[0-9]+$@', $ver ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the installed version of a plugin
|
||||
*
|
||||
* @param string $slug
|
||||
*
|
||||
* @return int|string
|
||||
*/
|
||||
function get_installed_version( $slug ) {
|
||||
$meta_key = $this->licences->plugin->get_global_meta_key();
|
||||
if ( isset( $GLOBALS[ $meta_key ][ $slug ]['version'] ) ) {
|
||||
// Plugin activated, use meta for version
|
||||
$installed_version = $GLOBALS[ $meta_key ][ $slug ]['version'];
|
||||
} else {
|
||||
// Not activated
|
||||
$installed_version = $this->licences->plugin->get_plugin_version( $slug );
|
||||
}
|
||||
|
||||
return $installed_version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest version available of a plugin
|
||||
*
|
||||
* @param string $slug
|
||||
* @param string|null $installed_version
|
||||
*
|
||||
* @return string|false
|
||||
*/
|
||||
function get_latest_version( $slug, $installed_version = null ) {
|
||||
$data = $this->get_upgrade_data();
|
||||
|
||||
if ( ! isset( $data[ $slug ] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$plugin_file = $this->licences->plugin->get_plugin_basename( $slug );
|
||||
if ( $this->is_addon( $plugin_file ) ) {
|
||||
if ( ! $this->is_allowed_addon( $slug ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_null( $installed_version ) ) {
|
||||
$installed_version = $this->get_installed_version( $slug );
|
||||
}
|
||||
|
||||
$required_version = $this->get_required_version( $slug );
|
||||
|
||||
// Return the latest beta version if the installed version is beta
|
||||
// and the API returned a beta version and it's newer than the latest stable version
|
||||
if (
|
||||
$installed_version
|
||||
&& ( $this->is_beta_version( $installed_version ) || $this->is_beta_version( $required_version ) )
|
||||
&& isset( $data[ $slug ]['beta_version'] )
|
||||
&& version_compare( $data[ $slug ]['version'], $data[ $slug ]['beta_version'], '<' )
|
||||
) {
|
||||
return $data[ $slug ]['beta_version'];
|
||||
}
|
||||
|
||||
return $data[ $slug ]['version'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the upgrade data about the plugin and its addons
|
||||
*
|
||||
* @return array|bool|mixed
|
||||
*/
|
||||
function get_upgrade_data() {
|
||||
$info = get_site_transient( $this->licences->plugin->prefix . '_upgrade_data' );
|
||||
|
||||
// Remove old format upgrade data.
|
||||
if ( isset( $info['version'] ) ) {
|
||||
delete_site_transient( $this->licences->plugin->prefix . '_licence_response' );
|
||||
delete_site_transient( $this->licences->plugin->prefix . '_upgrade_data' );
|
||||
$info = false;
|
||||
}
|
||||
|
||||
if ( $info ) {
|
||||
return $info;
|
||||
}
|
||||
|
||||
$data = $this->licences->get_upgrade_data();
|
||||
|
||||
$data = json_decode( $data, true );
|
||||
|
||||
/*
|
||||
We need to set the transient even when there's an error,
|
||||
otherwise we'll end up making API requests over and over again
|
||||
and slowing things down big time.
|
||||
*/
|
||||
$default_upgrade_data = array( $this->licences->plugin->slug => array( 'version' => $this->licences->plugin->version ) );
|
||||
|
||||
if ( ! $data ) {
|
||||
set_site_transient( $this->licences->plugin->prefix . '_upgrade_data', $default_upgrade_data, $this->licences->transient_retry_timeout );
|
||||
$this->licences->log_error( 'Error trying to decode JSON upgrade data.' );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( isset( $data['errors'] ) ) {
|
||||
set_site_transient( $this->licences->plugin->prefix . '_upgrade_data', $default_upgrade_data, $this->licences->transient_retry_timeout );
|
||||
$this->licences->log_error( __( 'Error trying to get upgrade data.' ), $data['errors'] );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
set_site_transient( $this->licences->plugin->prefix . '_upgrade_data', $data, $this->licences->transient_timeout );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the plugin update URL
|
||||
*
|
||||
* @param string $plugin_slug
|
||||
* @param bool $is_beta
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_plugin_update_download_url( $plugin_slug, $is_beta = false ) {
|
||||
$licence = $this->licences->get_licence_key();
|
||||
$query_args = array(
|
||||
'request' => 'download',
|
||||
'licence_key' => $licence,
|
||||
'slug' => $plugin_slug,
|
||||
'product' => $this->licences->plugin->slug,
|
||||
'site_url' => $this->licences->home_url,
|
||||
);
|
||||
|
||||
if ( $is_beta ) {
|
||||
$query_args['beta'] = '1';
|
||||
}
|
||||
|
||||
$url = add_query_arg( $query_args, $this->licences->api_url );
|
||||
|
||||
return esc_url_raw( $url );
|
||||
}
|
||||
|
||||
/**
|
||||
* Display custom version update notices to the top of our plugin page
|
||||
*
|
||||
* @param string $basename
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function version_update_notice( string $basename ): array {
|
||||
// We don't want to show both the "Update Required" and "Update Available" messages at the same time
|
||||
if ( $this->is_addon( $basename ) && $this->is_addon_outdated( $basename ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$slug = current( explode( '/', $basename ) );
|
||||
|
||||
// To reduce UI clutter we hide addon update notices if the core plugin has updates available
|
||||
if ( $this->is_addon( $basename ) && $this->core_update_available() ) {
|
||||
// Core update is available, don't show update notices for addons until core is updated
|
||||
return array();
|
||||
}
|
||||
|
||||
$installed_version = $this->get_installed_version( $slug );
|
||||
$latest_version = $this->get_latest_version( $slug, $installed_version );
|
||||
|
||||
if ( version_compare( $installed_version, $latest_version, '<' ) ) {
|
||||
$plugin_name = ( isset( $this->licences->addons[ $basename ] ) ) ? $this->licences->addons[ $basename ]['name'] : $this->licences->plugin->name;
|
||||
$heading = _x( 'Update Available', 'A new version of the plugin is available' );
|
||||
$message = sprintf( __( '%1$s %2$s is now available. You currently have %3$s installed.' ), $plugin_name, $latest_version, $installed_version );
|
||||
|
||||
$licence = $this->licences->get_licence_key();
|
||||
$licence_response = $this->licences->is_licence_expired();
|
||||
$licence_problem = isset( $licence_response['errors'] );
|
||||
|
||||
if ( ! empty( $licence ) && ! $licence_problem ) {
|
||||
$update_url = wp_nonce_url( $this->licences->admin_url( 'update.php?action=upgrade-plugin&plugin=' . urlencode( $basename ) ), 'upgrade-plugin_' . $basename );
|
||||
$message .= ' ' . sprintf( '<a href="%1$s">%2$s</a>', $update_url, _x( 'Update Now', 'Download and install a new version of the plugin' ) );
|
||||
}
|
||||
|
||||
return array(
|
||||
'slug' => $slug,
|
||||
'heading' => $heading,
|
||||
'message' => $message,
|
||||
);
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the plugin an addon
|
||||
*
|
||||
* @param string $plugin_file
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function is_addon( $plugin_file ) {
|
||||
return isset( $this->licences->addons[ $plugin_file ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there an update available for the given plugin slug?
|
||||
*
|
||||
* @param string $slug
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function update_available( string $slug ): bool {
|
||||
$installed_version = $this->get_installed_version( $slug );
|
||||
$latest_version = $this->get_latest_version( $slug, $installed_version );
|
||||
|
||||
return version_compare( $installed_version, $latest_version, '<' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Is there an update for the core plugin?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function core_update_available(): bool {
|
||||
return $this->update_available( $this->licences->plugin->slug );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if an addon needs to be updated
|
||||
*
|
||||
* @param string $addon_basename
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function is_addon_outdated( $addon_basename ) {
|
||||
$addon_slug = current( explode( '/', $addon_basename ) );
|
||||
|
||||
$installed_version = $this->get_installed_version( $addon_slug );
|
||||
$required_version = $this->licences->addons[ $addon_basename ]['required_version'];
|
||||
|
||||
return version_compare( $installed_version, $required_version, '<' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the addon allowed for the license
|
||||
*
|
||||
* @param string $slug
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function is_allowed_addon( $slug ) {
|
||||
$addons = get_site_transient( $this->licences->plugin->prefix . '_addons' );
|
||||
if ( isset( $addons[ $slug ] ) ) {
|
||||
// Addon allowed
|
||||
return true;
|
||||
}
|
||||
|
||||
// Not an allowed addon
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook into the plugin install process and inject addon download url
|
||||
*
|
||||
* @param stdClass $res
|
||||
* @param string $action
|
||||
* @param stdClass $args
|
||||
*
|
||||
* @return stdClass
|
||||
*/
|
||||
function inject_addon_install_resource( $res, $action, $args ) {
|
||||
if ( 'plugin_information' != $action || empty( $args->slug ) ) {
|
||||
return $res;
|
||||
}
|
||||
|
||||
$addons = get_site_transient( $this->licences->plugin->prefix . '_addons' );
|
||||
|
||||
if ( ! isset( $addons[ $args->slug ] ) ) {
|
||||
return $res;
|
||||
}
|
||||
|
||||
$addon = $addons[ $args->slug ];
|
||||
$required_version = $this->get_required_version( $args->slug );
|
||||
$is_beta = $this->is_beta_version( $required_version ) && ! empty( $addon['beta_version'] );
|
||||
|
||||
$res = new stdClass();
|
||||
$res->name = $this->licences->plugin->name . ' ' . $addon['name'];
|
||||
$res->version = $is_beta ? $addon['beta_version'] : $addon['version'];
|
||||
$res->download_link = $this->get_plugin_update_download_url( $args->slug, $is_beta );
|
||||
$res->tested = isset( $addon['tested'] ) ? $addon['tested'] : false;
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the required version of a plugin
|
||||
*
|
||||
* @param string $slug
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function get_required_version( $slug ) {
|
||||
$plugin_file = $this->licences->plugin->get_plugin_basename( $slug );
|
||||
|
||||
if ( isset( $this->licences->addons[ $plugin_file ]['required_version'] ) ) {
|
||||
return $this->licences->addons[ $plugin_file ]['required_version'];
|
||||
} else {
|
||||
return '0';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a plugin slug to see if it is the core plugin or one of its addons
|
||||
*
|
||||
* @param string $slug
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function is_plugin( $slug ) {
|
||||
$plugins = array( $this->licences->plugin->slug );
|
||||
if ( $this->licences->addons ) {
|
||||
foreach ( $this->licences->addons as $key => $addon ) {
|
||||
$plugins[] = dirname( $key );
|
||||
}
|
||||
}
|
||||
|
||||
return in_array( $slug, $plugins );
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to get the directory of the plugin
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function plugins_dir() {
|
||||
$path = untrailingslashit( $this->licences->plugin->dir_path );
|
||||
|
||||
return substr( $path, 0, strrpos( $path, DIRECTORY_SEPARATOR ) ) . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user