Upgraded PuC version
This commit is contained in:
@@ -1,6 +0,0 @@
|
|||||||
<?php
|
|
||||||
if ( !class_exists('Puc_v4_Factory', false) ):
|
|
||||||
|
|
||||||
class Puc_v4_Factory extends Puc_v4p4_Factory { }
|
|
||||||
|
|
||||||
endif;
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
if ( !class_exists('Puc_v4p4_Autoloader', false) ):
|
|
||||||
|
|
||||||
class Puc_v4p4_Autoloader {
|
|
||||||
private $prefix = '';
|
|
||||||
private $rootDir = '';
|
|
||||||
private $libraryDir = '';
|
|
||||||
|
|
||||||
private $staticMap;
|
|
||||||
|
|
||||||
public function __construct() {
|
|
||||||
$this->rootDir = dirname(__FILE__) . '/';
|
|
||||||
$nameParts = explode('_', __CLASS__, 3);
|
|
||||||
$this->prefix = $nameParts[0] . '_' . $nameParts[1] . '_';
|
|
||||||
|
|
||||||
$this->libraryDir = realpath($this->rootDir . '../..') . '/';
|
|
||||||
$this->staticMap = array(
|
|
||||||
'PucReadmeParser' => 'vendor/readme-parser.php',
|
|
||||||
'Parsedown' => 'vendor/ParsedownLegacy.php',
|
|
||||||
);
|
|
||||||
if ( version_compare(PHP_VERSION, '5.3.0', '>=') ) {
|
|
||||||
$this->staticMap['Parsedown'] = 'vendor/Parsedown.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
spl_autoload_register(array($this, 'autoload'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function autoload($className) {
|
|
||||||
if ( isset($this->staticMap[$className]) && file_exists($this->libraryDir . $this->staticMap[$className]) ) {
|
|
||||||
/** @noinspection PhpIncludeInspection */
|
|
||||||
include ($this->libraryDir . $this->staticMap[$className]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strpos($className, $this->prefix) === 0) {
|
|
||||||
$path = substr($className, strlen($this->prefix));
|
|
||||||
$path = str_replace('_', '/', $path);
|
|
||||||
$path = $this->rootDir . $path . '.php';
|
|
||||||
|
|
||||||
if (file_exists($path)) {
|
|
||||||
/** @noinspection PhpIncludeInspection */
|
|
||||||
include $path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
endif;
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
<?php
|
|
||||||
if ( !class_exists('Puc_v4p4_DebugBar_PluginExtension', false) ):
|
|
||||||
|
|
||||||
class Puc_v4p4_DebugBar_PluginExtension extends Puc_v4p4_DebugBar_Extension {
|
|
||||||
/** @var Puc_v4p4_Plugin_UpdateChecker */
|
|
||||||
protected $updateChecker;
|
|
||||||
|
|
||||||
public function __construct($updateChecker) {
|
|
||||||
parent::__construct($updateChecker, 'Puc_v4p4_DebugBar_PluginPanel');
|
|
||||||
|
|
||||||
add_action('wp_ajax_puc_v4_debug_request_info', array($this, 'ajaxRequestInfo'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Request plugin info and output it.
|
|
||||||
*/
|
|
||||||
public function ajaxRequestInfo() {
|
|
||||||
if ( $_POST['uid'] !== $this->updateChecker->getUniqueName('uid') ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->preAjaxRequest();
|
|
||||||
$info = $this->updateChecker->requestInfo();
|
|
||||||
if ( $info !== null ) {
|
|
||||||
echo 'Successfully retrieved plugin info from the metadata URL:';
|
|
||||||
echo '<pre>', htmlentities(print_r($info, true)), '</pre>';
|
|
||||||
} else {
|
|
||||||
echo 'Failed to retrieve plugin info from the metadata URL.';
|
|
||||||
}
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
endif;
|
|
||||||
@@ -1,740 +0,0 @@
|
|||||||
<?php
|
|
||||||
if ( !class_exists('Puc_v4p4_Plugin_UpdateChecker', false) ):
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A custom plugin update checker.
|
|
||||||
*
|
|
||||||
* @author Janis Elsts
|
|
||||||
* @copyright 2016
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
class Puc_v4p4_Plugin_UpdateChecker extends Puc_v4p4_UpdateChecker {
|
|
||||||
protected $updateTransient = 'update_plugins';
|
|
||||||
protected $translationType = 'plugin';
|
|
||||||
|
|
||||||
public $pluginAbsolutePath = ''; //Full path of the main plugin file.
|
|
||||||
public $pluginFile = ''; //Plugin filename relative to the plugins directory. Many WP APIs use this to identify plugins.
|
|
||||||
public $muPluginFile = ''; //For MU plugins, the plugin filename relative to the mu-plugins directory.
|
|
||||||
|
|
||||||
private $cachedInstalledVersion = null;
|
|
||||||
private $manualCheckErrorTransient = '';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class constructor.
|
|
||||||
*
|
|
||||||
* @param string $metadataUrl The URL of the plugin's metadata file.
|
|
||||||
* @param string $pluginFile Fully qualified path to the main plugin file.
|
|
||||||
* @param string $slug The plugin's 'slug'. If not specified, the filename part of $pluginFile sans '.php' will be used as the slug.
|
|
||||||
* @param integer $checkPeriod How often to check for updates (in hours). Defaults to checking every 12 hours. Set to 0 to disable automatic update checks.
|
|
||||||
* @param string $optionName Where to store book-keeping info about update checks. Defaults to 'external_updates-$slug'.
|
|
||||||
* @param string $muPluginFile Optional. The plugin filename relative to the mu-plugins directory.
|
|
||||||
*/
|
|
||||||
public function __construct($metadataUrl, $pluginFile, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = ''){
|
|
||||||
$this->pluginAbsolutePath = $pluginFile;
|
|
||||||
$this->pluginFile = plugin_basename($this->pluginAbsolutePath);
|
|
||||||
$this->muPluginFile = $muPluginFile;
|
|
||||||
|
|
||||||
//If no slug is specified, use the name of the main plugin file as the slug.
|
|
||||||
//For example, 'my-cool-plugin/cool-plugin.php' becomes 'cool-plugin'.
|
|
||||||
if ( empty($slug) ){
|
|
||||||
$slug = basename($this->pluginFile, '.php');
|
|
||||||
}
|
|
||||||
|
|
||||||
//Plugin slugs must be unique.
|
|
||||||
$slugCheckFilter = 'puc_is_slug_in_use-' . $this->slug;
|
|
||||||
$slugUsedBy = apply_filters($slugCheckFilter, false);
|
|
||||||
if ( $slugUsedBy ) {
|
|
||||||
$this->triggerError(sprintf(
|
|
||||||
'Plugin slug "%s" is already in use by %s. Slugs must be unique.',
|
|
||||||
htmlentities($this->slug),
|
|
||||||
htmlentities($slugUsedBy)
|
|
||||||
), E_USER_ERROR);
|
|
||||||
}
|
|
||||||
add_filter($slugCheckFilter, array($this, 'getAbsolutePath'));
|
|
||||||
|
|
||||||
//Backwards compatibility: If the plugin is a mu-plugin but no $muPluginFile is specified, assume
|
|
||||||
//it's the same as $pluginFile given that it's not in a subdirectory (WP only looks in the base dir).
|
|
||||||
if ( (strpbrk($this->pluginFile, '/\\') === false) && $this->isUnknownMuPlugin() ) {
|
|
||||||
$this->muPluginFile = $this->pluginFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
//To prevent a crash during plugin uninstallation, remove updater hooks when the user removes the plugin.
|
|
||||||
//Details: https://github.com/YahnisElsts/plugin-update-checker/issues/138#issuecomment-335590964
|
|
||||||
add_action('uninstall_' . $this->pluginFile, array($this, 'removeHooks'));
|
|
||||||
|
|
||||||
$this->manualCheckErrorTransient = $this->getUniqueName('manual_check_errors');
|
|
||||||
|
|
||||||
parent::__construct($metadataUrl, dirname($this->pluginFile), $slug, $checkPeriod, $optionName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create an instance of the scheduler.
|
|
||||||
*
|
|
||||||
* @param int $checkPeriod
|
|
||||||
* @return Puc_v4p4_Scheduler
|
|
||||||
*/
|
|
||||||
protected function createScheduler($checkPeriod) {
|
|
||||||
$scheduler = new Puc_v4p4_Scheduler($this, $checkPeriod, array('load-plugins.php'));
|
|
||||||
register_deactivation_hook($this->pluginFile, array($scheduler, 'removeUpdaterCron'));
|
|
||||||
return $scheduler;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Install the hooks required to run periodic update checks and inject update info
|
|
||||||
* into WP data structures.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
protected function installHooks(){
|
|
||||||
//Override requests for plugin information
|
|
||||||
add_filter('plugins_api', array($this, 'injectInfo'), 20, 3);
|
|
||||||
|
|
||||||
add_filter('plugin_row_meta', array($this, 'addViewDetailsLink'), 10, 3);
|
|
||||||
add_filter('plugin_row_meta', array($this, 'addCheckForUpdatesLink'), 10, 2);
|
|
||||||
add_action('admin_init', array($this, 'handleManualCheck'));
|
|
||||||
add_action('all_admin_notices', array($this, 'displayManualCheckResult'));
|
|
||||||
|
|
||||||
//Clear the version number cache when something - anything - is upgraded or WP clears the update cache.
|
|
||||||
add_filter('upgrader_post_install', array($this, 'clearCachedVersion'));
|
|
||||||
add_action('delete_site_transient_update_plugins', array($this, 'clearCachedVersion'));
|
|
||||||
|
|
||||||
parent::installHooks();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove update checker hooks.
|
|
||||||
*
|
|
||||||
* The intent is to prevent a fatal error that can happen if the plugin has an uninstall
|
|
||||||
* hook. During uninstallation, WP includes the main plugin file (which creates a PUC instance),
|
|
||||||
* the uninstall hook runs, WP deletes the plugin files and then updates some transients.
|
|
||||||
* If PUC hooks are still around at this time, they could throw an error while trying to
|
|
||||||
* autoload classes from files that no longer exist.
|
|
||||||
*
|
|
||||||
* The "site_transient_{$transient}" filter is the main problem here, but let's also remove
|
|
||||||
* most other PUC hooks to be safe.
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
public function removeHooks() {
|
|
||||||
parent::removeHooks();
|
|
||||||
|
|
||||||
remove_filter('plugins_api', array($this, 'injectInfo'), 20);
|
|
||||||
|
|
||||||
remove_filter('plugin_row_meta', array($this, 'addViewDetailsLink'), 10);
|
|
||||||
remove_filter('plugin_row_meta', array($this, 'addCheckForUpdatesLink'), 10);
|
|
||||||
remove_action('admin_init', array($this, 'handleManualCheck'));
|
|
||||||
remove_action('all_admin_notices', array($this, 'displayManualCheckResult'));
|
|
||||||
|
|
||||||
remove_filter('upgrader_post_install', array($this, 'clearCachedVersion'));
|
|
||||||
remove_action('delete_site_transient_update_plugins', array($this, 'clearCachedVersion'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve plugin info from the configured API endpoint.
|
|
||||||
*
|
|
||||||
* @uses wp_remote_get()
|
|
||||||
*
|
|
||||||
* @param array $queryArgs Additional query arguments to append to the request. Optional.
|
|
||||||
* @return Puc_v4p4_Plugin_Info
|
|
||||||
*/
|
|
||||||
public function requestInfo($queryArgs = array()) {
|
|
||||||
list($pluginInfo, $result) = $this->requestMetadata('Puc_v4p4_Plugin_Info', 'request_info', $queryArgs);
|
|
||||||
|
|
||||||
if ( $pluginInfo !== null ) {
|
|
||||||
/** @var Puc_v4p4_Plugin_Info $pluginInfo */
|
|
||||||
$pluginInfo->filename = $this->pluginFile;
|
|
||||||
$pluginInfo->slug = $this->slug;
|
|
||||||
}
|
|
||||||
|
|
||||||
$pluginInfo = apply_filters($this->getUniqueName('request_info_result'), $pluginInfo, $result);
|
|
||||||
return $pluginInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the latest update (if any) from the configured API endpoint.
|
|
||||||
*
|
|
||||||
* @uses PluginUpdateChecker::requestInfo()
|
|
||||||
*
|
|
||||||
* @return Puc_v4p4_Update|null An instance of Plugin_Update, or NULL when no updates are available.
|
|
||||||
*/
|
|
||||||
public function requestUpdate() {
|
|
||||||
//For the sake of simplicity, this function just calls requestInfo()
|
|
||||||
//and transforms the result accordingly.
|
|
||||||
$pluginInfo = $this->requestInfo(array('checking_for_updates' => '1'));
|
|
||||||
if ( $pluginInfo === null ){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
$update = Puc_v4p4_Plugin_Update::fromPluginInfo($pluginInfo);
|
|
||||||
|
|
||||||
$update = $this->filterUpdateResult($update);
|
|
||||||
|
|
||||||
return $update;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the currently installed version of the plugin.
|
|
||||||
*
|
|
||||||
* @return string Version number.
|
|
||||||
*/
|
|
||||||
public function getInstalledVersion(){
|
|
||||||
if ( isset($this->cachedInstalledVersion) ) {
|
|
||||||
return $this->cachedInstalledVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
$pluginHeader = $this->getPluginHeader();
|
|
||||||
if ( isset($pluginHeader['Version']) ) {
|
|
||||||
$this->cachedInstalledVersion = $pluginHeader['Version'];
|
|
||||||
return $pluginHeader['Version'];
|
|
||||||
} else {
|
|
||||||
//This can happen if the filename points to something that is not a plugin.
|
|
||||||
$this->triggerError(
|
|
||||||
sprintf(
|
|
||||||
"Can't to read the Version header for '%s'. The filename is incorrect or is not a plugin.",
|
|
||||||
$this->pluginFile
|
|
||||||
),
|
|
||||||
E_USER_WARNING
|
|
||||||
);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get plugin's metadata from its file header.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function getPluginHeader() {
|
|
||||||
if ( !is_file($this->pluginAbsolutePath) ) {
|
|
||||||
//This can happen if the plugin filename is wrong.
|
|
||||||
$this->triggerError(
|
|
||||||
sprintf(
|
|
||||||
"Can't to read the plugin header for '%s'. The file does not exist.",
|
|
||||||
$this->pluginFile
|
|
||||||
),
|
|
||||||
E_USER_WARNING
|
|
||||||
);
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !function_exists('get_plugin_data') ){
|
|
||||||
/** @noinspection PhpIncludeInspection */
|
|
||||||
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
|
||||||
}
|
|
||||||
return get_plugin_data($this->pluginAbsolutePath, false, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected function getHeaderNames() {
|
|
||||||
return array(
|
|
||||||
'Name' => 'Plugin Name',
|
|
||||||
'PluginURI' => 'Plugin URI',
|
|
||||||
'Version' => 'Version',
|
|
||||||
'Description' => 'Description',
|
|
||||||
'Author' => 'Author',
|
|
||||||
'AuthorURI' => 'Author URI',
|
|
||||||
'TextDomain' => 'Text Domain',
|
|
||||||
'DomainPath' => 'Domain Path',
|
|
||||||
'Network' => 'Network',
|
|
||||||
|
|
||||||
//The newest WordPress version that this plugin requires or has been tested with.
|
|
||||||
//We support several different formats for compatibility with other libraries.
|
|
||||||
'Tested WP' => 'Tested WP',
|
|
||||||
'Requires WP' => 'Requires WP',
|
|
||||||
'Tested up to' => 'Tested up to',
|
|
||||||
'Requires at least' => 'Requires at least',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Intercept plugins_api() calls that request information about our plugin and
|
|
||||||
* use the configured API endpoint to satisfy them.
|
|
||||||
*
|
|
||||||
* @see plugins_api()
|
|
||||||
*
|
|
||||||
* @param mixed $result
|
|
||||||
* @param string $action
|
|
||||||
* @param array|object $args
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function injectInfo($result, $action = null, $args = null){
|
|
||||||
$relevant = ($action == 'plugin_information') && isset($args->slug) && (
|
|
||||||
($args->slug == $this->slug) || ($args->slug == dirname($this->pluginFile))
|
|
||||||
);
|
|
||||||
if ( !$relevant ) {
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
$pluginInfo = $this->requestInfo();
|
|
||||||
$pluginInfo = apply_filters($this->getUniqueName('pre_inject_info'), $pluginInfo);
|
|
||||||
if ( $pluginInfo ) {
|
|
||||||
return $pluginInfo->toWpFormat();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function shouldShowUpdates() {
|
|
||||||
//No update notifications for mu-plugins unless explicitly enabled. The MU plugin file
|
|
||||||
//is usually different from the main plugin file so the update wouldn't show up properly anyway.
|
|
||||||
return !$this->isUnknownMuPlugin();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param stdClass|null $updates
|
|
||||||
* @param stdClass $updateToAdd
|
|
||||||
* @return stdClass
|
|
||||||
*/
|
|
||||||
protected function addUpdateToList($updates, $updateToAdd) {
|
|
||||||
if ( $this->isMuPlugin() ) {
|
|
||||||
//WP does not support automatic update installation for mu-plugins, but we can
|
|
||||||
//still display a notice.
|
|
||||||
$updateToAdd->package = null;
|
|
||||||
}
|
|
||||||
return parent::addUpdateToList($updates, $updateToAdd);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param stdClass|null $updates
|
|
||||||
* @return stdClass|null
|
|
||||||
*/
|
|
||||||
protected function removeUpdateFromList($updates) {
|
|
||||||
$updates = parent::removeUpdateFromList($updates);
|
|
||||||
if ( !empty($this->muPluginFile) && isset($updates, $updates->response) ) {
|
|
||||||
unset($updates->response[$this->muPluginFile]);
|
|
||||||
}
|
|
||||||
return $updates;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For plugins, the update array is indexed by the plugin filename relative to the "plugins"
|
|
||||||
* directory. Example: "plugin-name/plugin.php".
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function getUpdateListKey() {
|
|
||||||
if ( $this->isMuPlugin() ) {
|
|
||||||
return $this->muPluginFile;
|
|
||||||
}
|
|
||||||
return $this->pluginFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Alias for isBeingUpgraded().
|
|
||||||
*
|
|
||||||
* @deprecated
|
|
||||||
* @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isPluginBeingUpgraded($upgrader = null) {
|
|
||||||
return $this->isBeingUpgraded($upgrader);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Is there an update being installed for this plugin, right now?
|
|
||||||
*
|
|
||||||
* @param WP_Upgrader|null $upgrader
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isBeingUpgraded($upgrader = null) {
|
|
||||||
return $this->upgraderStatus->isPluginBeingUpgraded($this->pluginFile, $upgrader);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the details of the currently available update, if any.
|
|
||||||
*
|
|
||||||
* If no updates are available, or if the last known update version is below or equal
|
|
||||||
* to the currently installed version, this method will return NULL.
|
|
||||||
*
|
|
||||||
* Uses cached update data. To retrieve update information straight from
|
|
||||||
* the metadata URL, call requestUpdate() instead.
|
|
||||||
*
|
|
||||||
* @return Puc_v4p4_Plugin_Update|null
|
|
||||||
*/
|
|
||||||
public function getUpdate() {
|
|
||||||
$update = parent::getUpdate();
|
|
||||||
if ( isset($update) ) {
|
|
||||||
/** @var Puc_v4p4_Plugin_Update $update */
|
|
||||||
$update->filename = $this->pluginFile;
|
|
||||||
}
|
|
||||||
return $update;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a "Check for updates" link to the plugin row in the "Plugins" page. By default,
|
|
||||||
* the new link will appear after the "Visit plugin site" link if present, otherwise
|
|
||||||
* after the "View plugin details" link.
|
|
||||||
*
|
|
||||||
* You can change the link text by using the "puc_manual_check_link-$slug" filter.
|
|
||||||
* Returning an empty string from the filter will disable the link.
|
|
||||||
*
|
|
||||||
* @param array $pluginMeta Array of meta links.
|
|
||||||
* @param string $pluginFile
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function addCheckForUpdatesLink($pluginMeta, $pluginFile) {
|
|
||||||
$isRelevant = ($pluginFile == $this->pluginFile)
|
|
||||||
|| (!empty($this->muPluginFile) && $pluginFile == $this->muPluginFile);
|
|
||||||
|
|
||||||
if ( $isRelevant && $this->userCanInstallUpdates() ) {
|
|
||||||
$linkUrl = wp_nonce_url(
|
|
||||||
add_query_arg(
|
|
||||||
array(
|
|
||||||
'puc_check_for_updates' => 1,
|
|
||||||
'puc_slug' => $this->slug,
|
|
||||||
),
|
|
||||||
self_admin_url('plugins.php')
|
|
||||||
),
|
|
||||||
'puc_check_for_updates'
|
|
||||||
);
|
|
||||||
|
|
||||||
$linkText = apply_filters(
|
|
||||||
$this->getUniqueName('manual_check_link'),
|
|
||||||
__('Check for updates', 'plugin-update-checker')
|
|
||||||
);
|
|
||||||
if ( !empty($linkText) ) {
|
|
||||||
/** @noinspection HtmlUnknownTarget */
|
|
||||||
$pluginMeta[] = sprintf('<a href="%s">%s</a>', esc_attr($linkUrl), $linkText);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $pluginMeta;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a "View Details" link to the plugin row in the "Plugins" page. By default,
|
|
||||||
* the new link will appear before the "Visit plugin site" link (if present).
|
|
||||||
*
|
|
||||||
* You can change the link text by using the "puc_view_details_link-$slug" filter.
|
|
||||||
* Returning an empty string from the filter will disable the link.
|
|
||||||
*
|
|
||||||
* You can change the position of the link using the
|
|
||||||
* "puc_view_details_link_position-$slug" filter.
|
|
||||||
* Returning 'before' or 'after' will place the link immediately before/after the
|
|
||||||
* "Visit plugin site" link
|
|
||||||
* Returning 'append' places the link after any existing links at the time of the hook.
|
|
||||||
* Returning 'replace' replaces the "Visit plugin site" link
|
|
||||||
* Returning anything else disables the link when there is a "Visit plugin site" link.
|
|
||||||
*
|
|
||||||
* If there is no "Visit plugin site" link 'append' is always used!
|
|
||||||
*
|
|
||||||
* @param array $pluginMeta Array of meta links.
|
|
||||||
* @param string $pluginFile
|
|
||||||
* @param array $pluginData Array of plugin header data.
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function addViewDetailsLink($pluginMeta, $pluginFile, $pluginData = array()) {
|
|
||||||
$isRelevant = ($pluginFile == $this->pluginFile)
|
|
||||||
|| (!empty($this->muPluginFile) && $pluginFile == $this->muPluginFile);
|
|
||||||
|
|
||||||
if ( $isRelevant && $this->userCanInstallUpdates() && !isset($pluginData['slug']) ) {
|
|
||||||
$linkText = apply_filters($this->getUniqueName('view_details_link'), __('View details'));
|
|
||||||
if ( !empty($linkText) ) {
|
|
||||||
$viewDetailsLinkPosition = 'append';
|
|
||||||
|
|
||||||
//Find the "Visit plugin site" link (if present).
|
|
||||||
$visitPluginSiteLinkIndex = count($pluginMeta) - 1;
|
|
||||||
if ( $pluginData['PluginURI'] ) {
|
|
||||||
$escapedPluginUri = esc_url($pluginData['PluginURI']);
|
|
||||||
foreach ($pluginMeta as $linkIndex => $existingLink) {
|
|
||||||
if ( strpos($existingLink, $escapedPluginUri) !== false ) {
|
|
||||||
$visitPluginSiteLinkIndex = $linkIndex;
|
|
||||||
$viewDetailsLinkPosition = apply_filters(
|
|
||||||
$this->getUniqueName('view_details_link_position'),
|
|
||||||
'before'
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$viewDetailsLink = sprintf('<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
|
|
||||||
esc_url(network_admin_url('plugin-install.php?tab=plugin-information&plugin=' . urlencode($this->slug) .
|
|
||||||
'&TB_iframe=true&width=600&height=550')),
|
|
||||||
esc_attr(sprintf(__('More information about %s'), $pluginData['Name'])),
|
|
||||||
esc_attr($pluginData['Name']),
|
|
||||||
$linkText
|
|
||||||
);
|
|
||||||
switch ($viewDetailsLinkPosition) {
|
|
||||||
case 'before':
|
|
||||||
array_splice($pluginMeta, $visitPluginSiteLinkIndex, 0, $viewDetailsLink);
|
|
||||||
break;
|
|
||||||
case 'after':
|
|
||||||
array_splice($pluginMeta, $visitPluginSiteLinkIndex + 1, 0, $viewDetailsLink);
|
|
||||||
break;
|
|
||||||
case 'replace':
|
|
||||||
$pluginMeta[$visitPluginSiteLinkIndex] = $viewDetailsLink;
|
|
||||||
break;
|
|
||||||
case 'append':
|
|
||||||
default:
|
|
||||||
$pluginMeta[] = $viewDetailsLink;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $pluginMeta;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check for updates when the user clicks the "Check for updates" link.
|
|
||||||
* @see self::addCheckForUpdatesLink()
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function handleManualCheck() {
|
|
||||||
$shouldCheck =
|
|
||||||
isset($_GET['puc_check_for_updates'], $_GET['puc_slug'])
|
|
||||||
&& $_GET['puc_slug'] == $this->slug
|
|
||||||
&& $this->userCanInstallUpdates()
|
|
||||||
&& check_admin_referer('puc_check_for_updates');
|
|
||||||
|
|
||||||
if ( $shouldCheck ) {
|
|
||||||
$update = $this->checkForUpdates();
|
|
||||||
$status = ($update === null) ? 'no_update' : 'update_available';
|
|
||||||
|
|
||||||
if ( ($update === null) && !empty($this->lastRequestApiErrors) ) {
|
|
||||||
//Some errors are not critical. For example, if PUC tries to retrieve the readme.txt
|
|
||||||
//file from GitHub and gets a 404, that's an API error, but it doesn't prevent updates
|
|
||||||
//from working. Maybe the plugin simply doesn't have a readme.
|
|
||||||
//Let's only show important errors.
|
|
||||||
$foundCriticalErrors = false;
|
|
||||||
$questionableErrorCodes = array(
|
|
||||||
'puc-github-http-error',
|
|
||||||
'puc-gitlab-http-error',
|
|
||||||
'puc-bitbucket-http-error',
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($this->lastRequestApiErrors as $item) {
|
|
||||||
$wpError = $item['error'];
|
|
||||||
/** @var WP_Error $wpError */
|
|
||||||
if ( !in_array($wpError->get_error_code(), $questionableErrorCodes) ) {
|
|
||||||
$foundCriticalErrors = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $foundCriticalErrors ) {
|
|
||||||
$status = 'error';
|
|
||||||
set_site_transient($this->manualCheckErrorTransient, $this->lastRequestApiErrors, 60);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
wp_redirect(add_query_arg(
|
|
||||||
array(
|
|
||||||
'puc_update_check_result' => $status,
|
|
||||||
'puc_slug' => $this->slug,
|
|
||||||
),
|
|
||||||
self_admin_url('plugins.php')
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the results of a manual update check.
|
|
||||||
* @see self::handleManualCheck()
|
|
||||||
*
|
|
||||||
* You can change the result message by using the "puc_manual_check_message-$slug" filter.
|
|
||||||
*/
|
|
||||||
public function displayManualCheckResult() {
|
|
||||||
if ( isset($_GET['puc_update_check_result'], $_GET['puc_slug']) && ($_GET['puc_slug'] == $this->slug) ) {
|
|
||||||
$status = strval($_GET['puc_update_check_result']);
|
|
||||||
$title = $this->getPluginTitle();
|
|
||||||
$noticeClass = 'updated notice-success';
|
|
||||||
$details = '';
|
|
||||||
|
|
||||||
if ( $status == 'no_update' ) {
|
|
||||||
$message = sprintf(_x('The %s plugin is up to date.', 'the plugin title', 'plugin-update-checker'), $title);
|
|
||||||
} else if ( $status == 'update_available' ) {
|
|
||||||
$message = sprintf(_x('A new version of the %s plugin is available.', 'the plugin title', 'plugin-update-checker'), $title);
|
|
||||||
} else if ( $status === 'error' ) {
|
|
||||||
$message = sprintf(_x('Could not determine if updates are available for %s.', 'the plugin title', 'plugin-update-checker'), $title);
|
|
||||||
$noticeClass = 'error notice-error';
|
|
||||||
|
|
||||||
$details = $this->formatManualCheckErrors(get_site_transient($this->manualCheckErrorTransient));
|
|
||||||
delete_site_transient($this->manualCheckErrorTransient);
|
|
||||||
} else {
|
|
||||||
$message = sprintf(__('Unknown update checker status "%s"', 'plugin-update-checker'), htmlentities($status));
|
|
||||||
$noticeClass = 'error notice-error';
|
|
||||||
}
|
|
||||||
printf(
|
|
||||||
'<div class="notice %s is-dismissible"><p>%s</p>%s</div>',
|
|
||||||
$noticeClass,
|
|
||||||
apply_filters($this->getUniqueName('manual_check_message'), $message, $status),
|
|
||||||
$details
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Format the list of errors that were thrown during an update check.
|
|
||||||
*
|
|
||||||
* @param array $errors
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function formatManualCheckErrors($errors) {
|
|
||||||
if ( empty($errors) ) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
$output = '';
|
|
||||||
|
|
||||||
$showAsList = count($errors) > 1;
|
|
||||||
if ( $showAsList ) {
|
|
||||||
$output .= '<ol>';
|
|
||||||
$formatString = '<li>%1$s <code>%2$s</code></li>';
|
|
||||||
} else {
|
|
||||||
$formatString = '<p>%1$s <code>%2$s</code></p>';
|
|
||||||
}
|
|
||||||
foreach ($errors as $item) {
|
|
||||||
$wpError = $item['error'];
|
|
||||||
/** @var WP_Error $wpError */
|
|
||||||
$output .= sprintf(
|
|
||||||
$formatString,
|
|
||||||
$wpError->get_error_message(),
|
|
||||||
$wpError->get_error_code()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if ( $showAsList ) {
|
|
||||||
$output .= '</ol>';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the translated plugin title.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function getPluginTitle() {
|
|
||||||
$title = '';
|
|
||||||
$header = $this->getPluginHeader();
|
|
||||||
if ( $header && !empty($header['Name']) && isset($header['TextDomain']) ) {
|
|
||||||
$title = translate($header['Name'], $header['TextDomain']);
|
|
||||||
}
|
|
||||||
return $title;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the current user has the required permissions to install updates.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function userCanInstallUpdates() {
|
|
||||||
return current_user_can('update_plugins');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the plugin file is inside the mu-plugins directory.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function isMuPlugin() {
|
|
||||||
static $cachedResult = null;
|
|
||||||
|
|
||||||
if ( $cachedResult === null ) {
|
|
||||||
//Convert both paths to the canonical form before comparison.
|
|
||||||
$muPluginDir = realpath(WPMU_PLUGIN_DIR);
|
|
||||||
$pluginPath = realpath($this->pluginAbsolutePath);
|
|
||||||
|
|
||||||
$cachedResult = (strpos($pluginPath, $muPluginDir) === 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $cachedResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* MU plugins are partially supported, but only when we know which file in mu-plugins
|
|
||||||
* corresponds to this plugin.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function isUnknownMuPlugin() {
|
|
||||||
return empty($this->muPluginFile) && $this->isMuPlugin();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clear the cached plugin version. This method can be set up as a filter (hook) and will
|
|
||||||
* return the filter argument unmodified.
|
|
||||||
*
|
|
||||||
* @param mixed $filterArgument
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function clearCachedVersion($filterArgument = null) {
|
|
||||||
$this->cachedInstalledVersion = null;
|
|
||||||
return $filterArgument;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get absolute path to the main plugin file.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getAbsolutePath() {
|
|
||||||
return $this->pluginAbsolutePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getAbsoluteDirectoryPath() {
|
|
||||||
return dirname($this->pluginAbsolutePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a callback for filtering query arguments.
|
|
||||||
*
|
|
||||||
* The callback function should take one argument - an associative array of query arguments.
|
|
||||||
* It should return a modified array of query arguments.
|
|
||||||
*
|
|
||||||
* @uses add_filter() This method is a convenience wrapper for add_filter().
|
|
||||||
*
|
|
||||||
* @param callable $callback
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function addQueryArgFilter($callback){
|
|
||||||
$this->addFilter('request_info_query_args', $callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a callback for filtering arguments passed to wp_remote_get().
|
|
||||||
*
|
|
||||||
* The callback function should take one argument - an associative array of arguments -
|
|
||||||
* and return a modified array or arguments. See the WP documentation on wp_remote_get()
|
|
||||||
* for details on what arguments are available and how they work.
|
|
||||||
*
|
|
||||||
* @uses add_filter() This method is a convenience wrapper for add_filter().
|
|
||||||
*
|
|
||||||
* @param callable $callback
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function addHttpRequestArgFilter($callback) {
|
|
||||||
$this->addFilter('request_info_options', $callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Register a callback for filtering the plugin info retrieved from the external API.
|
|
||||||
*
|
|
||||||
* The callback function should take two arguments. If the plugin info was retrieved
|
|
||||||
* successfully, the first argument passed will be an instance of PluginInfo. Otherwise,
|
|
||||||
* it will be NULL. The second argument will be the corresponding return value of
|
|
||||||
* wp_remote_get (see WP docs for details).
|
|
||||||
*
|
|
||||||
* The callback function should return a new or modified instance of PluginInfo or NULL.
|
|
||||||
*
|
|
||||||
* @uses add_filter() This method is a convenience wrapper for add_filter().
|
|
||||||
*
|
|
||||||
* @param callable $callback
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function addResultFilter($callback) {
|
|
||||||
$this->addFilter('request_info_result', $callback, 10, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function createDebugBarExtension() {
|
|
||||||
return new Puc_v4p4_DebugBar_PluginExtension($this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
endif;
|
|
||||||
@@ -1,413 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
if ( !class_exists('Puc_v4p4_Vcs_GitHubApi', false) ):
|
|
||||||
|
|
||||||
class Puc_v4p4_Vcs_GitHubApi extends Puc_v4p4_Vcs_Api {
|
|
||||||
/**
|
|
||||||
* @var string GitHub username.
|
|
||||||
*/
|
|
||||||
protected $userName;
|
|
||||||
/**
|
|
||||||
* @var string GitHub repository name.
|
|
||||||
*/
|
|
||||||
protected $repositoryName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string Either a fully qualified repository URL, or just "user/repo-name".
|
|
||||||
*/
|
|
||||||
protected $repositoryUrl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string GitHub authentication token. Optional.
|
|
||||||
*/
|
|
||||||
protected $accessToken;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool Whether to download release assets instead of the auto-generated source code archives.
|
|
||||||
*/
|
|
||||||
protected $releaseAssetsEnabled = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null Regular expression that's used to filter release assets by name. Optional.
|
|
||||||
*/
|
|
||||||
protected $assetFilterRegex = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null The unchanging part of a release asset URL. Used to identify download attempts.
|
|
||||||
*/
|
|
||||||
protected $assetApiBaseUrl = null;
|
|
||||||
|
|
||||||
public function __construct($repositoryUrl, $accessToken = null) {
|
|
||||||
$path = @parse_url($repositoryUrl, PHP_URL_PATH);
|
|
||||||
if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
|
|
||||||
$this->userName = $matches['username'];
|
|
||||||
$this->repositoryName = $matches['repository'];
|
|
||||||
} else {
|
|
||||||
throw new InvalidArgumentException('Invalid GitHub repository URL: "' . $repositoryUrl . '"');
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::__construct($repositoryUrl, $accessToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the latest release from GitHub.
|
|
||||||
*
|
|
||||||
* @return Puc_v4p4_Vcs_Reference|null
|
|
||||||
*/
|
|
||||||
public function getLatestRelease() {
|
|
||||||
$release = $this->api('/repos/:user/:repo/releases/latest');
|
|
||||||
if ( is_wp_error($release) || !is_object($release) || !isset($release->tag_name) ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$reference = new Puc_v4p4_Vcs_Reference(array(
|
|
||||||
'name' => $release->tag_name,
|
|
||||||
'version' => ltrim($release->tag_name, 'v'), //Remove the "v" prefix from "v1.2.3".
|
|
||||||
'downloadUrl' => $this->signDownloadUrl($release->zipball_url),
|
|
||||||
'updated' => $release->created_at,
|
|
||||||
'apiResponse' => $release,
|
|
||||||
));
|
|
||||||
|
|
||||||
if ( isset($release->assets[0]) ) {
|
|
||||||
$reference->downloadCount = $release->assets[0]->download_count;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $this->releaseAssetsEnabled && isset($release->assets, $release->assets[0]) ) {
|
|
||||||
//Use the first release asset that matches the specified regular expression.
|
|
||||||
$matchingAssets = array_filter($release->assets, array($this, 'matchesAssetFilter'));
|
|
||||||
if ( !empty($matchingAssets) ) {
|
|
||||||
if ( $this->isAuthenticationEnabled() ) {
|
|
||||||
/**
|
|
||||||
* Keep in mind that we'll need to add an "Accept" header to download this asset.
|
|
||||||
* @see setReleaseDownloadHeader()
|
|
||||||
*/
|
|
||||||
$reference->downloadUrl = $this->signDownloadUrl($matchingAssets[0]->url);
|
|
||||||
} else {
|
|
||||||
//It seems that browser_download_url only works for public repositories.
|
|
||||||
//Using an access_token doesn't help. Maybe OAuth would work?
|
|
||||||
$reference->downloadUrl = $matchingAssets[0]->browser_download_url;
|
|
||||||
}
|
|
||||||
|
|
||||||
$reference->downloadCount = $matchingAssets[0]->download_count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !empty($release->body) ) {
|
|
||||||
/** @noinspection PhpUndefinedClassInspection */
|
|
||||||
$reference->changelog = Parsedown::instance()->text($release->body);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $reference;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the tag that looks like the highest version number.
|
|
||||||
*
|
|
||||||
* @return Puc_v4p4_Vcs_Reference|null
|
|
||||||
*/
|
|
||||||
public function getLatestTag() {
|
|
||||||
$tags = $this->api('/repos/:user/:repo/tags');
|
|
||||||
|
|
||||||
if ( is_wp_error($tags) || empty($tags) || !is_array($tags) ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$versionTags = $this->sortTagsByVersion($tags);
|
|
||||||
if ( empty($versionTags) ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tag = $versionTags[0];
|
|
||||||
return new Puc_v4p4_Vcs_Reference(array(
|
|
||||||
'name' => $tag->name,
|
|
||||||
'version' => ltrim($tag->name, 'v'),
|
|
||||||
'downloadUrl' => $this->signDownloadUrl($tag->zipball_url),
|
|
||||||
'apiResponse' => $tag,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a branch by name.
|
|
||||||
*
|
|
||||||
* @param string $branchName
|
|
||||||
* @return null|Puc_v4p4_Vcs_Reference
|
|
||||||
*/
|
|
||||||
public function getBranch($branchName) {
|
|
||||||
$branch = $this->api('/repos/:user/:repo/branches/' . $branchName);
|
|
||||||
if ( is_wp_error($branch) || empty($branch) ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$reference = new Puc_v4p4_Vcs_Reference(array(
|
|
||||||
'name' => $branch->name,
|
|
||||||
'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name),
|
|
||||||
'apiResponse' => $branch,
|
|
||||||
));
|
|
||||||
|
|
||||||
if ( isset($branch->commit, $branch->commit->commit, $branch->commit->commit->author->date) ) {
|
|
||||||
$reference->updated = $branch->commit->commit->author->date;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $reference;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the latest commit that changed the specified file.
|
|
||||||
*
|
|
||||||
* @param string $filename
|
|
||||||
* @param string $ref Reference name (e.g. branch or tag).
|
|
||||||
* @return StdClass|null
|
|
||||||
*/
|
|
||||||
public function getLatestCommit($filename, $ref = 'master') {
|
|
||||||
$commits = $this->api(
|
|
||||||
'/repos/:user/:repo/commits',
|
|
||||||
array(
|
|
||||||
'path' => $filename,
|
|
||||||
'sha' => $ref,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
if ( !is_wp_error($commits) && is_array($commits) && isset($commits[0]) ) {
|
|
||||||
return $commits[0];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the timestamp of the latest commit that changed the specified branch or tag.
|
|
||||||
*
|
|
||||||
* @param string $ref Reference name (e.g. branch or tag).
|
|
||||||
* @return string|null
|
|
||||||
*/
|
|
||||||
public function getLatestCommitTime($ref) {
|
|
||||||
$commits = $this->api('/repos/:user/:repo/commits', array('sha' => $ref));
|
|
||||||
if ( !is_wp_error($commits) && is_array($commits) && isset($commits[0]) ) {
|
|
||||||
return $commits[0]->commit->author->date;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform a GitHub API request.
|
|
||||||
*
|
|
||||||
* @param string $url
|
|
||||||
* @param array $queryParams
|
|
||||||
* @return mixed|WP_Error
|
|
||||||
*/
|
|
||||||
protected function api($url, $queryParams = array()) {
|
|
||||||
$baseUrl = $url;
|
|
||||||
$url = $this->buildApiUrl($url, $queryParams);
|
|
||||||
|
|
||||||
$options = array('timeout' => 10);
|
|
||||||
if ( !empty($this->httpFilterName) ) {
|
|
||||||
$options = apply_filters($this->httpFilterName, $options);
|
|
||||||
}
|
|
||||||
$response = wp_remote_get($url, $options);
|
|
||||||
if ( is_wp_error($response) ) {
|
|
||||||
do_action('puc_api_error', $response, null, $url, $this->slug);
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
$code = wp_remote_retrieve_response_code($response);
|
|
||||||
$body = wp_remote_retrieve_body($response);
|
|
||||||
if ( $code === 200 ) {
|
|
||||||
$document = json_decode($body);
|
|
||||||
return $document;
|
|
||||||
}
|
|
||||||
|
|
||||||
$error = new WP_Error(
|
|
||||||
'puc-github-http-error',
|
|
||||||
sprintf('GitHub API error. Base URL: "%s", HTTP status code: %d.', $baseUrl, $code)
|
|
||||||
);
|
|
||||||
do_action('puc_api_error', $error, $response, $url, $this->slug);
|
|
||||||
|
|
||||||
return $error;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build a fully qualified URL for an API request.
|
|
||||||
*
|
|
||||||
* @param string $url
|
|
||||||
* @param array $queryParams
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function buildApiUrl($url, $queryParams) {
|
|
||||||
$variables = array(
|
|
||||||
'user' => $this->userName,
|
|
||||||
'repo' => $this->repositoryName,
|
|
||||||
);
|
|
||||||
foreach ($variables as $name => $value) {
|
|
||||||
$url = str_replace('/:' . $name, '/' . urlencode($value), $url);
|
|
||||||
}
|
|
||||||
$url = 'https://api.github.com' . $url;
|
|
||||||
|
|
||||||
if ( !empty($this->accessToken) ) {
|
|
||||||
$queryParams['access_token'] = $this->accessToken;
|
|
||||||
}
|
|
||||||
if ( !empty($queryParams) ) {
|
|
||||||
$url = add_query_arg($queryParams, $url);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $url;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the contents of a file from a specific branch or tag.
|
|
||||||
*
|
|
||||||
* @param string $path File name.
|
|
||||||
* @param string $ref
|
|
||||||
* @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
|
|
||||||
*/
|
|
||||||
public function getRemoteFile($path, $ref = 'master') {
|
|
||||||
$apiUrl = '/repos/:user/:repo/contents/' . $path;
|
|
||||||
$response = $this->api($apiUrl, array('ref' => $ref));
|
|
||||||
|
|
||||||
if ( is_wp_error($response) || !isset($response->content) || ($response->encoding !== 'base64') ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return base64_decode($response->content);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a URL to download a ZIP archive of the specified branch/tag/etc.
|
|
||||||
*
|
|
||||||
* @param string $ref
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function buildArchiveDownloadUrl($ref = 'master') {
|
|
||||||
$url = sprintf(
|
|
||||||
'https://api.github.com/repos/%1$s/%2$s/zipball/%3$s',
|
|
||||||
urlencode($this->userName),
|
|
||||||
urlencode($this->repositoryName),
|
|
||||||
urlencode($ref)
|
|
||||||
);
|
|
||||||
if ( !empty($this->accessToken) ) {
|
|
||||||
$url = $this->signDownloadUrl($url);
|
|
||||||
}
|
|
||||||
return $url;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a specific tag.
|
|
||||||
*
|
|
||||||
* @param string $tagName
|
|
||||||
* @return Puc_v4p4_Vcs_Reference|null
|
|
||||||
*/
|
|
||||||
public function getTag($tagName) {
|
|
||||||
//The current GitHub update checker doesn't use getTag, so I didn't bother to implement it.
|
|
||||||
throw new LogicException('The ' . __METHOD__ . ' method is not implemented and should not be used.');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setAuthentication($credentials) {
|
|
||||||
parent::setAuthentication($credentials);
|
|
||||||
$this->accessToken = is_string($credentials) ? $credentials : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Figure out which reference (i.e tag or branch) contains the latest version.
|
|
||||||
*
|
|
||||||
* @param string $configBranch Start looking in this branch.
|
|
||||||
* @return null|Puc_v4p4_Vcs_Reference
|
|
||||||
*/
|
|
||||||
public function chooseReference($configBranch) {
|
|
||||||
$updateSource = null;
|
|
||||||
|
|
||||||
if ( $configBranch === 'master' ) {
|
|
||||||
//Use the latest release.
|
|
||||||
$updateSource = $this->getLatestRelease();
|
|
||||||
if ( $updateSource === null ) {
|
|
||||||
//Failing that, use the tag with the highest version number.
|
|
||||||
$updateSource = $this->getLatestTag();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//Alternatively, just use the branch itself.
|
|
||||||
if ( empty($updateSource) ) {
|
|
||||||
$updateSource = $this->getBranch($configBranch);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $updateSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $url
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function signDownloadUrl($url) {
|
|
||||||
if ( empty($this->credentials) ) {
|
|
||||||
return $url;
|
|
||||||
}
|
|
||||||
return add_query_arg('access_token', $this->credentials, $url);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable updating via release assets.
|
|
||||||
*
|
|
||||||
* If the latest release contains no usable assets, the update checker
|
|
||||||
* will fall back to using the automatically generated ZIP archive.
|
|
||||||
*
|
|
||||||
* Private repositories will only work with WordPress 3.7 or later.
|
|
||||||
*
|
|
||||||
* @param string|null $fileNameRegex Optional. Use only those assets where the file name matches this regex.
|
|
||||||
*/
|
|
||||||
public function enableReleaseAssets($fileNameRegex = null) {
|
|
||||||
$this->releaseAssetsEnabled = true;
|
|
||||||
$this->assetFilterRegex = $fileNameRegex;
|
|
||||||
$this->assetApiBaseUrl = sprintf(
|
|
||||||
'//api.github.com/repos/%1$s/%2$s/releases/assets/',
|
|
||||||
$this->userName,
|
|
||||||
$this->repositoryName
|
|
||||||
);
|
|
||||||
|
|
||||||
//Optimization: Instead of filtering all HTTP requests, let's do it only when
|
|
||||||
//WordPress is about to download an update.
|
|
||||||
add_filter('upgrader_pre_download', array($this, 'addHttpRequestFilter'), 10, 1); //WP 3.7+
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Does this asset match the file name regex?
|
|
||||||
*
|
|
||||||
* @param stdClass $releaseAsset
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
protected function matchesAssetFilter($releaseAsset) {
|
|
||||||
if ( $this->assetFilterRegex === null ) {
|
|
||||||
//The default is to accept all assets.
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return isset($releaseAsset->name) && preg_match($this->assetFilterRegex, $releaseAsset->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
* @param bool $result
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function addHttpRequestFilter($result) {
|
|
||||||
static $filterAdded = false;
|
|
||||||
if ( $this->releaseAssetsEnabled && !$filterAdded && $this->isAuthenticationEnabled() ) {
|
|
||||||
add_filter('http_request_args', array($this, 'setReleaseDownloadHeader'), 10, 2);
|
|
||||||
$filterAdded = true;
|
|
||||||
}
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the HTTP header that's necessary to download private release assets.
|
|
||||||
*
|
|
||||||
* See GitHub docs:
|
|
||||||
* @link https://developer.github.com/v3/repos/releases/#get-a-single-release-asset
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
* @param array $requestArgs
|
|
||||||
* @param string $url
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function setReleaseDownloadHeader($requestArgs, $url = '') {
|
|
||||||
//Is WordPress trying to download one of our assets?
|
|
||||||
if ( strpos($url, $this->assetApiBaseUrl) !== false ) {
|
|
||||||
$requestArgs['headers']['accept'] = 'application/octet-stream';
|
|
||||||
}
|
|
||||||
return $requestArgs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
endif;
|
|
||||||
@@ -1,274 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
if ( !class_exists('Puc_v4p4_Vcs_GitLabApi', false) ):
|
|
||||||
|
|
||||||
class Puc_v4p4_Vcs_GitLabApi extends Puc_v4p4_Vcs_Api {
|
|
||||||
/**
|
|
||||||
* @var string GitLab username.
|
|
||||||
*/
|
|
||||||
protected $userName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string GitLab server host.
|
|
||||||
*/
|
|
||||||
private $repositoryHost;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string GitLab repository name.
|
|
||||||
*/
|
|
||||||
protected $repositoryName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string GitLab authentication token. Optional.
|
|
||||||
*/
|
|
||||||
protected $accessToken;
|
|
||||||
|
|
||||||
public function __construct($repositoryUrl, $accessToken = null) {
|
|
||||||
//Parse the repository host to support custom hosts.
|
|
||||||
$this->repositoryHost = @parse_url($repositoryUrl, PHP_URL_HOST);
|
|
||||||
|
|
||||||
//Find the repository information
|
|
||||||
$path = @parse_url($repositoryUrl, PHP_URL_PATH);
|
|
||||||
if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
|
|
||||||
$this->userName = $matches['username'];
|
|
||||||
$this->repositoryName = $matches['repository'];
|
|
||||||
} else {
|
|
||||||
//This is not a traditional url, it could be gitlab is in a deeper subdirectory.
|
|
||||||
//Get the path segments.
|
|
||||||
$segments = explode('/', untrailingslashit(ltrim($path, '/')));
|
|
||||||
|
|
||||||
//We need at least /user-name/repository-name/
|
|
||||||
if ( count($segments) < 2 ) {
|
|
||||||
throw new InvalidArgumentException('Invalid GitLab repository URL: "' . $repositoryUrl . '"');
|
|
||||||
}
|
|
||||||
|
|
||||||
//Get the username and repository name.
|
|
||||||
$usernameRepo = array_splice($segments, -2, 2);
|
|
||||||
$this->userName = $usernameRepo[0];
|
|
||||||
$this->repositoryName = $usernameRepo[1];
|
|
||||||
|
|
||||||
//Append the remaining segments to the host.
|
|
||||||
$this->repositoryHost = trailingslashit($this->repositoryHost) . implode('/', $segments);
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::__construct($repositoryUrl, $accessToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the latest release from GitLab.
|
|
||||||
*
|
|
||||||
* @return Puc_v4p4_Vcs_Reference|null
|
|
||||||
*/
|
|
||||||
public function getLatestRelease() {
|
|
||||||
return $this->getLatestTag();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the tag that looks like the highest version number.
|
|
||||||
*
|
|
||||||
* @return Puc_v4p4_Vcs_Reference|null
|
|
||||||
*/
|
|
||||||
public function getLatestTag() {
|
|
||||||
$tags = $this->api('/:user/:repo/repository/tags');
|
|
||||||
if ( is_wp_error($tags) || empty($tags) || !is_array($tags) ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$versionTags = $this->sortTagsByVersion($tags);
|
|
||||||
if ( empty($versionTags) ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$tag = $versionTags[0];
|
|
||||||
return new Puc_v4p4_Vcs_Reference(array(
|
|
||||||
'name' => $tag->name,
|
|
||||||
'version' => ltrim($tag->name, 'v'),
|
|
||||||
'downloadUrl' => $this->buildArchiveDownloadUrl($tag->name),
|
|
||||||
'apiResponse' => $tag
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a branch by name.
|
|
||||||
*
|
|
||||||
* @param string $branchName
|
|
||||||
* @return null|Puc_v4p4_Vcs_Reference
|
|
||||||
*/
|
|
||||||
public function getBranch($branchName) {
|
|
||||||
$branch = $this->api('/:user/:repo/repository/branches/' . $branchName);
|
|
||||||
if ( is_wp_error($branch) || empty($branch) ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$reference = new Puc_v4p4_Vcs_Reference(array(
|
|
||||||
'name' => $branch->name,
|
|
||||||
'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name),
|
|
||||||
'apiResponse' => $branch,
|
|
||||||
));
|
|
||||||
|
|
||||||
if ( isset($branch->commit, $branch->commit->committed_date) ) {
|
|
||||||
$reference->updated = $branch->commit->committed_date;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $reference;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the timestamp of the latest commit that changed the specified branch or tag.
|
|
||||||
*
|
|
||||||
* @param string $ref Reference name (e.g. branch or tag).
|
|
||||||
* @return string|null
|
|
||||||
*/
|
|
||||||
public function getLatestCommitTime($ref) {
|
|
||||||
$commits = $this->api('/:user/:repo/repository/commits/', array('ref_name' => $ref));
|
|
||||||
if ( is_wp_error($commits) || !is_array($commits) || !isset($commits[0]) ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $commits[0]->committed_date;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Perform a GitLab API request.
|
|
||||||
*
|
|
||||||
* @param string $url
|
|
||||||
* @param array $queryParams
|
|
||||||
* @return mixed|WP_Error
|
|
||||||
*/
|
|
||||||
protected function api($url, $queryParams = array()) {
|
|
||||||
$baseUrl = $url;
|
|
||||||
$url = $this->buildApiUrl($url, $queryParams);
|
|
||||||
|
|
||||||
$options = array('timeout' => 10);
|
|
||||||
if ( !empty($this->httpFilterName) ) {
|
|
||||||
$options = apply_filters($this->httpFilterName, $options);
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = wp_remote_get($url, $options);
|
|
||||||
if ( is_wp_error($response) ) {
|
|
||||||
do_action('puc_api_error', $response, null, $url, $this->slug);
|
|
||||||
return $response;
|
|
||||||
}
|
|
||||||
|
|
||||||
$code = wp_remote_retrieve_response_code($response);
|
|
||||||
$body = wp_remote_retrieve_body($response);
|
|
||||||
if ( $code === 200 ) {
|
|
||||||
return json_decode($body);
|
|
||||||
}
|
|
||||||
|
|
||||||
$error = new WP_Error(
|
|
||||||
'puc-gitlab-http-error',
|
|
||||||
sprintf('GitLab API error. URL: "%s", HTTP status code: %d.', $baseUrl, $code)
|
|
||||||
);
|
|
||||||
do_action('puc_api_error', $error, $response, $url, $this->slug);
|
|
||||||
|
|
||||||
return $error;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Build a fully qualified URL for an API request.
|
|
||||||
*
|
|
||||||
* @param string $url
|
|
||||||
* @param array $queryParams
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
protected function buildApiUrl($url, $queryParams) {
|
|
||||||
$variables = array(
|
|
||||||
'user' => $this->userName,
|
|
||||||
'repo' => $this->repositoryName
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($variables as $name => $value) {
|
|
||||||
$url = str_replace("/:{$name}", urlencode('/' . $value), $url);
|
|
||||||
}
|
|
||||||
|
|
||||||
$url = substr($url, 3);
|
|
||||||
$url = sprintf('https://%1$s/api/v4/projects/%2$s', $this->repositoryHost, $url);
|
|
||||||
|
|
||||||
if ( !empty($this->accessToken) ) {
|
|
||||||
$queryParams['private_token'] = $this->accessToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !empty($queryParams) ) {
|
|
||||||
$url = add_query_arg($queryParams, $url);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $url;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the contents of a file from a specific branch or tag.
|
|
||||||
*
|
|
||||||
* @param string $path File name.
|
|
||||||
* @param string $ref
|
|
||||||
* @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
|
|
||||||
*/
|
|
||||||
public function getRemoteFile($path, $ref = 'master') {
|
|
||||||
$response = $this->api('/:user/:repo/repository/files/' . $path, array('ref' => $ref));
|
|
||||||
if ( is_wp_error($response) || !isset($response->content) || $response->encoding !== 'base64' ) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return base64_decode($response->content);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a URL to download a ZIP archive of the specified branch/tag/etc.
|
|
||||||
*
|
|
||||||
* @param string $ref
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function buildArchiveDownloadUrl($ref = 'master') {
|
|
||||||
$url = sprintf(
|
|
||||||
'https://%1$s/%2$s/%3$s/repository/%4$s/archive.zip',
|
|
||||||
$this->repositoryHost,
|
|
||||||
urlencode($this->userName),
|
|
||||||
urlencode($this->repositoryName),
|
|
||||||
urlencode($ref)
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( !empty($this->accessToken) ) {
|
|
||||||
$url = add_query_arg('private_token', $this->accessToken, $url);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $url;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a specific tag.
|
|
||||||
*
|
|
||||||
* @param string $tagName
|
|
||||||
* @return Puc_v4p4_Vcs_Reference|null
|
|
||||||
*/
|
|
||||||
public function getTag($tagName) {
|
|
||||||
throw new LogicException('The ' . __METHOD__ . ' method is not implemented and should not be used.');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Figure out which reference (i.e tag or branch) contains the latest version.
|
|
||||||
*
|
|
||||||
* @param string $configBranch Start looking in this branch.
|
|
||||||
* @return null|Puc_v4p4_Vcs_Reference
|
|
||||||
*/
|
|
||||||
public function chooseReference($configBranch) {
|
|
||||||
$updateSource = null;
|
|
||||||
|
|
||||||
// GitLab doesn't handle releases the same as GitHub so just use the latest tag
|
|
||||||
if ( $configBranch === 'master' ) {
|
|
||||||
$updateSource = $this->getLatestTag();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( empty($updateSource) ) {
|
|
||||||
$updateSource = $this->getBranch($configBranch);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $updateSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setAuthentication($credentials) {
|
|
||||||
parent::setAuthentication($credentials);
|
|
||||||
$this->accessToken = is_string($credentials) ? $credentials : null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
endif;
|
|
||||||
@@ -35,7 +35,7 @@ if ( ! defined( 'D5AW_PLUGIN_URL' ) )
|
|||||||
// Includes
|
// Includes
|
||||||
|
|
||||||
//require_once( 'inc/functions.php' );
|
//require_once( 'inc/functions.php' );
|
||||||
require 'plugin-update-checker.php';
|
|
||||||
|
|
||||||
// Styles and Scripts
|
// Styles and Scripts
|
||||||
function register_d5aw_scripts() {
|
function register_d5aw_scripts() {
|
||||||
@@ -65,15 +65,12 @@ function register_d5aw_scripts() {
|
|||||||
* plugin-update-checker.php file
|
* plugin-update-checker.php file
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
|
require 'plugin-update-checker-5.4/plugin-update-checker.php';
|
||||||
'https://github.com/D5code/d5-admin-tools/',
|
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
|
||||||
__FILE__,
|
|
||||||
'd5-admin-tools'
|
$myUpdateChecker = PucFactory::buildUpdateChecker(
|
||||||
|
'http://24.57.69.148/d5-admin-wp.json',
|
||||||
|
__FILE__, //Full path to the main plugin file or functions.php.
|
||||||
|
'd5-admin-wp'
|
||||||
);
|
);
|
||||||
|
|
||||||
//Optional: If you're using a private repository, specify the access token like this:
|
|
||||||
//$myUpdateChecker->setAuthentication('your-token-here');
|
|
||||||
|
|
||||||
//Optional: Set the branch that contains the stable release.
|
|
||||||
$myUpdateChecker->setBranch( 'master' );
|
|
||||||
|
|
||||||
|
|||||||
10
plugin-update-checker-5.4/Puc/v5/PucFactory.php
Normal file
10
plugin-update-checker-5.4/Puc/v5/PucFactory.php
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5;
|
||||||
|
|
||||||
|
if ( !class_exists(PucFactory::class, false) ):
|
||||||
|
|
||||||
|
class PucFactory extends \YahnisElsts\PluginUpdateChecker\v5p4\PucFactory {
|
||||||
|
}
|
||||||
|
|
||||||
|
endif;
|
||||||
86
plugin-update-checker-5.4/Puc/v5p4/Autoloader.php
Normal file
86
plugin-update-checker-5.4/Puc/v5p4/Autoloader.php
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4;
|
||||||
|
|
||||||
|
if ( !class_exists(Autoloader::class, false) ):
|
||||||
|
|
||||||
|
class Autoloader {
|
||||||
|
const DEFAULT_NS_PREFIX = 'YahnisElsts\\PluginUpdateChecker\\';
|
||||||
|
|
||||||
|
private $prefix;
|
||||||
|
private $rootDir;
|
||||||
|
private $libraryDir;
|
||||||
|
|
||||||
|
private $staticMap;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->rootDir = dirname(__FILE__) . '/';
|
||||||
|
|
||||||
|
$namespaceWithSlash = __NAMESPACE__ . '\\';
|
||||||
|
$this->prefix = $namespaceWithSlash;
|
||||||
|
|
||||||
|
$this->libraryDir = $this->rootDir . '../..';
|
||||||
|
if ( !self::isPhar() ) {
|
||||||
|
$this->libraryDir = realpath($this->libraryDir);
|
||||||
|
}
|
||||||
|
$this->libraryDir = $this->libraryDir . '/';
|
||||||
|
|
||||||
|
//Usually, dependencies like Parsedown are in the global namespace,
|
||||||
|
//but if someone adds a custom namespace to the entire library, they
|
||||||
|
//will be in the same namespace as this class.
|
||||||
|
$isCustomNamespace = (
|
||||||
|
substr($namespaceWithSlash, 0, strlen(self::DEFAULT_NS_PREFIX)) !== self::DEFAULT_NS_PREFIX
|
||||||
|
);
|
||||||
|
$libraryPrefix = $isCustomNamespace ? $namespaceWithSlash : '';
|
||||||
|
|
||||||
|
$this->staticMap = array(
|
||||||
|
$libraryPrefix . 'PucReadmeParser' => 'vendor/PucReadmeParser.php',
|
||||||
|
$libraryPrefix . 'Parsedown' => 'vendor/Parsedown.php',
|
||||||
|
);
|
||||||
|
|
||||||
|
//Add the generic, major-version-only factory class to the static map.
|
||||||
|
$versionSeparatorPos = strrpos(__NAMESPACE__, '\\v');
|
||||||
|
if ( $versionSeparatorPos !== false ) {
|
||||||
|
$versionSegment = substr(__NAMESPACE__, $versionSeparatorPos + 1);
|
||||||
|
$pointPos = strpos($versionSegment, 'p');
|
||||||
|
if ( ($pointPos !== false) && ($pointPos > 1) ) {
|
||||||
|
$majorVersionSegment = substr($versionSegment, 0, $pointPos);
|
||||||
|
$majorVersionNs = __NAMESPACE__ . '\\' . $majorVersionSegment;
|
||||||
|
$this->staticMap[$majorVersionNs . '\\PucFactory'] =
|
||||||
|
'Puc/' . $majorVersionSegment . '/Factory.php';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
spl_autoload_register(array($this, 'autoload'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if this file is running as part of a Phar archive.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private static function isPhar() {
|
||||||
|
//Check if the current file path starts with "phar://".
|
||||||
|
static $pharProtocol = 'phar://';
|
||||||
|
return (substr(__FILE__, 0, strlen($pharProtocol)) === $pharProtocol);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function autoload($className) {
|
||||||
|
if ( isset($this->staticMap[$className]) && file_exists($this->libraryDir . $this->staticMap[$className]) ) {
|
||||||
|
include($this->libraryDir . $this->staticMap[$className]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( strpos($className, $this->prefix) === 0 ) {
|
||||||
|
$path = substr($className, strlen($this->prefix));
|
||||||
|
$path = str_replace(array('_', '\\'), '/', $path);
|
||||||
|
$path = $this->rootDir . $path . '.php';
|
||||||
|
|
||||||
|
if ( file_exists($path) ) {
|
||||||
|
include $path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
endif;
|
||||||
@@ -1,12 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v4p4_DebugBar_Extension', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\DebugBar;
|
||||||
|
|
||||||
class Puc_v4p4_DebugBar_Extension {
|
use YahnisElsts\PluginUpdateChecker\v5p4\PucFactory;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\UpdateChecker;
|
||||||
|
|
||||||
|
if ( !class_exists(Extension::class, false) ):
|
||||||
|
|
||||||
|
class Extension {
|
||||||
const RESPONSE_BODY_LENGTH_LIMIT = 4000;
|
const RESPONSE_BODY_LENGTH_LIMIT = 4000;
|
||||||
|
|
||||||
/** @var Puc_v4p4_UpdateChecker */
|
/** @var UpdateChecker */
|
||||||
protected $updateChecker;
|
protected $updateChecker;
|
||||||
protected $panelClass = 'Puc_v4p4_DebugBar_Panel';
|
protected $panelClass = Panel::class;
|
||||||
|
|
||||||
public function __construct($updateChecker, $panelClass = null) {
|
public function __construct($updateChecker, $panelClass = null) {
|
||||||
$this->updateChecker = $updateChecker;
|
$this->updateChecker = $updateChecker;
|
||||||
@@ -14,10 +19,14 @@ if ( !class_exists('Puc_v4p4_DebugBar_Extension', false) ):
|
|||||||
$this->panelClass = $panelClass;
|
$this->panelClass = $panelClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( (strpos($this->panelClass, '\\') === false) ) {
|
||||||
|
$this->panelClass = __NAMESPACE__ . '\\' . $this->panelClass;
|
||||||
|
}
|
||||||
|
|
||||||
add_filter('debug_bar_panels', array($this, 'addDebugBarPanel'));
|
add_filter('debug_bar_panels', array($this, 'addDebugBarPanel'));
|
||||||
add_action('debug_bar_enqueue_scripts', array($this, 'enqueuePanelDependencies'));
|
add_action('debug_bar_enqueue_scripts', array($this, 'enqueuePanelDependencies'));
|
||||||
|
|
||||||
add_action('wp_ajax_puc_v4_debug_check_now', array($this, 'ajaxCheckNow'));
|
add_action('wp_ajax_puc_v5_debug_check_now', array($this, 'ajaxCheckNow'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,17 +47,17 @@ if ( !class_exists('Puc_v4p4_DebugBar_Extension', false) ):
|
|||||||
*/
|
*/
|
||||||
public function enqueuePanelDependencies() {
|
public function enqueuePanelDependencies() {
|
||||||
wp_enqueue_style(
|
wp_enqueue_style(
|
||||||
'puc-debug-bar-style-v4',
|
'puc-debug-bar-style-v5',
|
||||||
$this->getLibraryUrl("/css/puc-debug-bar.css"),
|
$this->getLibraryUrl("/css/puc-debug-bar.css"),
|
||||||
array('debug-bar'),
|
array('debug-bar'),
|
||||||
'20171124'
|
'20221008'
|
||||||
);
|
);
|
||||||
|
|
||||||
wp_enqueue_script(
|
wp_enqueue_script(
|
||||||
'puc-debug-bar-js-v4',
|
'puc-debug-bar-js-v5',
|
||||||
$this->getLibraryUrl("/js/debug-bar.js"),
|
$this->getLibraryUrl("/js/debug-bar.js"),
|
||||||
array('jquery'),
|
array('jquery'),
|
||||||
'20170516'
|
'20221008'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,14 +66,16 @@ if ( !class_exists('Puc_v4p4_DebugBar_Extension', false) ):
|
|||||||
* the update checking process works as expected.
|
* the update checking process works as expected.
|
||||||
*/
|
*/
|
||||||
public function ajaxCheckNow() {
|
public function ajaxCheckNow() {
|
||||||
if ( $_POST['uid'] !== $this->updateChecker->getUniqueName('uid') ) {
|
//phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce is checked in preAjaxRequest().
|
||||||
|
if ( !isset($_POST['uid']) || ($_POST['uid'] !== $this->updateChecker->getUniqueName('uid')) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->preAjaxRequest();
|
$this->preAjaxRequest();
|
||||||
$update = $this->updateChecker->checkForUpdates();
|
$update = $this->updateChecker->checkForUpdates();
|
||||||
if ( $update !== null ) {
|
if ( $update !== null ) {
|
||||||
echo "An update is available:";
|
echo "An update is available:";
|
||||||
echo '<pre>', htmlentities(print_r($update, true)), '</pre>';
|
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- For debugging output.
|
||||||
|
echo '<pre>', esc_html(print_r($update, true)), '</pre>';
|
||||||
} else {
|
} else {
|
||||||
echo 'No updates found.';
|
echo 'No updates found.';
|
||||||
}
|
}
|
||||||
@@ -75,8 +86,8 @@ if ( !class_exists('Puc_v4p4_DebugBar_Extension', false) ):
|
|||||||
|
|
||||||
foreach (array_values($errors) as $num => $item) {
|
foreach (array_values($errors) as $num => $item) {
|
||||||
$wpError = $item['error'];
|
$wpError = $item['error'];
|
||||||
/** @var WP_Error $wpError */
|
/** @var \WP_Error $wpError */
|
||||||
printf('<h4>%d) %s</h4>', $num + 1, esc_html($wpError->get_error_message()));
|
printf('<h4>%d) %s</h4>', intval($num + 1), esc_html($wpError->get_error_message()));
|
||||||
|
|
||||||
echo '<dl>';
|
echo '<dl>';
|
||||||
printf('<dt>Error code:</dt><dd><code>%s</code></dd>', esc_html($wpError->get_error_code()));
|
printf('<dt>Error code:</dt><dd><code>%s</code></dd>', esc_html($wpError->get_error_code()));
|
||||||
@@ -88,7 +99,7 @@ if ( !class_exists('Puc_v4p4_DebugBar_Extension', false) ):
|
|||||||
if ( isset($item['httpResponse']) ) {
|
if ( isset($item['httpResponse']) ) {
|
||||||
if ( is_wp_error($item['httpResponse']) ) {
|
if ( is_wp_error($item['httpResponse']) ) {
|
||||||
$httpError = $item['httpResponse'];
|
$httpError = $item['httpResponse'];
|
||||||
/** @var WP_Error $httpError */
|
/** @var \WP_Error $httpError */
|
||||||
printf(
|
printf(
|
||||||
'<dt>WordPress HTTP API error:</dt><dd>%s (<code>%s</code>)</dd>',
|
'<dt>WordPress HTTP API error:</dt><dd>%s (<code>%s</code>)</dd>',
|
||||||
esc_html($httpError->get_error_message()),
|
esc_html($httpError->get_error_message()),
|
||||||
@@ -98,8 +109,8 @@ if ( !class_exists('Puc_v4p4_DebugBar_Extension', false) ):
|
|||||||
//Status code.
|
//Status code.
|
||||||
printf(
|
printf(
|
||||||
'<dt>HTTP status:</dt><dd><code>%d %s</code></dd>',
|
'<dt>HTTP status:</dt><dd><code>%d %s</code></dd>',
|
||||||
wp_remote_retrieve_response_code($item['httpResponse']),
|
esc_html(wp_remote_retrieve_response_code($item['httpResponse'])),
|
||||||
wp_remote_retrieve_response_message($item['httpResponse'])
|
esc_html(wp_remote_retrieve_response_message($item['httpResponse']))
|
||||||
);
|
);
|
||||||
|
|
||||||
//Headers.
|
//Headers.
|
||||||
@@ -138,10 +149,21 @@ if ( !class_exists('Puc_v4p4_DebugBar_Extension', false) ):
|
|||||||
}
|
}
|
||||||
check_ajax_referer('puc-ajax');
|
check_ajax_referer('puc-ajax');
|
||||||
|
|
||||||
|
//phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_error_reporting -- Part of a debugging feature.
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
|
//phpcs:ignore WordPress.PHP.IniSet.display_errors_Blacklisted
|
||||||
@ini_set('display_errors', 'On');
|
@ini_set('display_errors', 'On');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove hooks that were added by this extension.
|
||||||
|
*/
|
||||||
|
public function removeHooks() {
|
||||||
|
remove_filter('debug_bar_panels', array($this, 'addDebugBarPanel'));
|
||||||
|
remove_action('debug_bar_enqueue_scripts', array($this, 'enqueuePanelDependencies'));
|
||||||
|
remove_action('wp_ajax_puc_v5_debug_check_now', array($this, 'ajaxCheckNow'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $filePath
|
* @param string $filePath
|
||||||
* @return string
|
* @return string
|
||||||
@@ -150,11 +172,11 @@ if ( !class_exists('Puc_v4p4_DebugBar_Extension', false) ):
|
|||||||
$absolutePath = realpath(dirname(__FILE__) . '/../../../' . ltrim($filePath, '/'));
|
$absolutePath = realpath(dirname(__FILE__) . '/../../../' . ltrim($filePath, '/'));
|
||||||
|
|
||||||
//Where is the library located inside the WordPress directory structure?
|
//Where is the library located inside the WordPress directory structure?
|
||||||
$absolutePath = Puc_v4p4_Factory::normalizePath($absolutePath);
|
$absolutePath = PucFactory::normalizePath($absolutePath);
|
||||||
|
|
||||||
$pluginDir = Puc_v4p4_Factory::normalizePath(WP_PLUGIN_DIR);
|
$pluginDir = PucFactory::normalizePath(WP_PLUGIN_DIR);
|
||||||
$muPluginDir = Puc_v4p4_Factory::normalizePath(WPMU_PLUGIN_DIR);
|
$muPluginDir = PucFactory::normalizePath(WPMU_PLUGIN_DIR);
|
||||||
$themeDir = Puc_v4p4_Factory::normalizePath(get_theme_root());
|
$themeDir = PucFactory::normalizePath(get_theme_root());
|
||||||
|
|
||||||
if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) {
|
if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) {
|
||||||
//It's part of a plugin.
|
//It's part of a plugin.
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\DebugBar;
|
||||||
|
|
||||||
if ( !class_exists('Puc_v4p4_DebugBar_Panel', false) && class_exists('Debug_Bar_Panel', false) ):
|
use YahnisElsts\PluginUpdateChecker\v5p4\UpdateChecker;
|
||||||
|
|
||||||
class Puc_v4p4_DebugBar_Panel extends Debug_Bar_Panel {
|
if ( !class_exists(Panel::class, false) && class_exists('Debug_Bar_Panel', false) ):
|
||||||
/** @var Puc_v4p4_UpdateChecker */
|
|
||||||
|
class Panel extends \Debug_Bar_Panel {
|
||||||
|
/** @var UpdateChecker */
|
||||||
protected $updateChecker;
|
protected $updateChecker;
|
||||||
|
|
||||||
private $responseBox = '<div class="puc-ajax-response" style="display: none;"></div>';
|
private $responseBox = '<div class="puc-ajax-response" style="display: none;"></div>';
|
||||||
@@ -20,7 +23,7 @@ if ( !class_exists('Puc_v4p4_DebugBar_Panel', false) && class_exists('Debug_Bar_
|
|||||||
|
|
||||||
public function render() {
|
public function render() {
|
||||||
printf(
|
printf(
|
||||||
'<div class="puc-debug-bar-panel-v4" id="%1$s" data-slug="%2$s" data-uid="%3$s" data-nonce="%4$s">',
|
'<div class="puc-debug-bar-panel-v5" id="%1$s" data-slug="%2$s" data-uid="%3$s" data-nonce="%4$s">',
|
||||||
esc_attr($this->updateChecker->getUniqueName('debug-bar-panel')),
|
esc_attr($this->updateChecker->getUniqueName('debug-bar-panel')),
|
||||||
esc_attr($this->updateChecker->slug),
|
esc_attr($this->updateChecker->slug),
|
||||||
esc_attr($this->updateChecker->getUniqueName('uid')),
|
esc_attr($this->updateChecker->getUniqueName('uid')),
|
||||||
@@ -119,7 +122,10 @@ if ( !class_exists('Puc_v4p4_DebugBar_Panel', false) && class_exists('Debug_Bar_
|
|||||||
$fields = $this->getUpdateFields();
|
$fields = $this->getUpdateFields();
|
||||||
foreach($fields as $field) {
|
foreach($fields as $field) {
|
||||||
if ( property_exists($update, $field) ) {
|
if ( property_exists($update, $field) ) {
|
||||||
$this->row(ucwords(str_replace('_', ' ', $field)), htmlentities($update->$field));
|
$this->row(
|
||||||
|
ucwords(str_replace('_', ' ', $field)),
|
||||||
|
isset($update->$field) ? htmlentities($update->$field) : null
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo '</table>';
|
echo '</table>';
|
||||||
@@ -154,11 +160,18 @@ if ( !class_exists('Puc_v4p4_DebugBar_Panel', false) && class_exists('Debug_Bar_
|
|||||||
|
|
||||||
public function row($name, $value) {
|
public function row($name, $value) {
|
||||||
if ( is_object($value) || is_array($value) ) {
|
if ( is_object($value) || is_array($value) ) {
|
||||||
|
//This is specifically for debugging, so print_r() is fine.
|
||||||
|
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r
|
||||||
$value = '<pre>' . htmlentities(print_r($value, true)) . '</pre>';
|
$value = '<pre>' . htmlentities(print_r($value, true)) . '</pre>';
|
||||||
} else if ($value === null) {
|
} else if ($value === null) {
|
||||||
$value = '<code>null</code>';
|
$value = '<code>null</code>';
|
||||||
}
|
}
|
||||||
printf('<tr><th scope="row">%1$s</th> <td>%2$s</td></tr>', $name, $value);
|
printf(
|
||||||
|
'<tr><th scope="row">%1$s</th> <td>%2$s</td></tr>',
|
||||||
|
esc_html($name),
|
||||||
|
//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped above.
|
||||||
|
$value
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\DebugBar;
|
||||||
|
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\Plugin\UpdateChecker;
|
||||||
|
|
||||||
|
if ( !class_exists(PluginExtension::class, false) ):
|
||||||
|
|
||||||
|
class PluginExtension extends Extension {
|
||||||
|
/** @var UpdateChecker */
|
||||||
|
protected $updateChecker;
|
||||||
|
|
||||||
|
public function __construct($updateChecker) {
|
||||||
|
parent::__construct($updateChecker, PluginPanel::class);
|
||||||
|
|
||||||
|
add_action('wp_ajax_puc_v5_debug_request_info', array($this, 'ajaxRequestInfo'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request plugin info and output it.
|
||||||
|
*/
|
||||||
|
public function ajaxRequestInfo() {
|
||||||
|
//phpcs:ignore WordPress.Security.NonceVerification.Missing -- Nonce is checked in preAjaxRequest().
|
||||||
|
if ( !isset($_POST['uid']) || ($_POST['uid'] !== $this->updateChecker->getUniqueName('uid')) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->preAjaxRequest();
|
||||||
|
$info = $this->updateChecker->requestInfo();
|
||||||
|
if ( $info !== null ) {
|
||||||
|
echo 'Successfully retrieved plugin info from the metadata URL:';
|
||||||
|
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_print_r -- For debugging output.
|
||||||
|
echo '<pre>', esc_html(print_r($info, true)), '</pre>';
|
||||||
|
} else {
|
||||||
|
echo 'Failed to retrieve plugin info from the metadata URL.';
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
endif;
|
||||||
@@ -1,10 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\DebugBar;
|
||||||
|
|
||||||
if ( !class_exists('Puc_v4p4_DebugBar_PluginPanel', false) ):
|
use YahnisElsts\PluginUpdateChecker\v5p4\Plugin\UpdateChecker;
|
||||||
|
|
||||||
class Puc_v4p4_DebugBar_PluginPanel extends Puc_v4p4_DebugBar_Panel {
|
if ( !class_exists(PluginPanel::class, false) ):
|
||||||
|
|
||||||
|
class PluginPanel extends Panel {
|
||||||
/**
|
/**
|
||||||
* @var Puc_v4p4_Plugin_UpdateChecker
|
* @var UpdateChecker
|
||||||
*/
|
*/
|
||||||
protected $updateChecker;
|
protected $updateChecker;
|
||||||
|
|
||||||
@@ -1,10 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( !class_exists('Puc_v4p4_DebugBar_ThemePanel', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\DebugBar;
|
||||||
|
|
||||||
class Puc_v4p4_DebugBar_ThemePanel extends Puc_v4p4_DebugBar_Panel {
|
use YahnisElsts\PluginUpdateChecker\v5p4\Theme\UpdateChecker;
|
||||||
|
|
||||||
|
if ( !class_exists(ThemePanel::class, false) ):
|
||||||
|
|
||||||
|
class ThemePanel extends Panel {
|
||||||
/**
|
/**
|
||||||
* @var Puc_v4p4_Theme_UpdateChecker
|
* @var UpdateChecker
|
||||||
*/
|
*/
|
||||||
protected $updateChecker;
|
protected $updateChecker;
|
||||||
|
|
||||||
105
plugin-update-checker-5.4/Puc/v5p4/InstalledPackage.php
Normal file
105
plugin-update-checker-5.4/Puc/v5p4/InstalledPackage.php
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4;
|
||||||
|
|
||||||
|
if ( !class_exists(InstalledPackage::class, false) ):
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents a currently installed plugin or theme.
|
||||||
|
*
|
||||||
|
* Not to be confused with the "package" field in WP update API responses that contains
|
||||||
|
* the download URL of a the new version.
|
||||||
|
*/
|
||||||
|
abstract class InstalledPackage {
|
||||||
|
/**
|
||||||
|
* @var UpdateChecker
|
||||||
|
*/
|
||||||
|
protected $updateChecker;
|
||||||
|
|
||||||
|
public function __construct($updateChecker) {
|
||||||
|
$this->updateChecker = $updateChecker;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the currently installed version of the plugin or theme.
|
||||||
|
*
|
||||||
|
* @return string|null Version number.
|
||||||
|
*/
|
||||||
|
abstract public function getInstalledVersion();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the full path of the plugin or theme directory (without a trailing slash).
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
abstract public function getAbsoluteDirectoryPath();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether a regular file exists in the package's directory.
|
||||||
|
*
|
||||||
|
* @param string $relativeFileName File name relative to the package directory.
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function fileExists($relativeFileName) {
|
||||||
|
return is_file(
|
||||||
|
$this->getAbsoluteDirectoryPath()
|
||||||
|
. DIRECTORY_SEPARATOR
|
||||||
|
. ltrim($relativeFileName, '/\\')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------
|
||||||
|
* File header parsing
|
||||||
|
* -------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse plugin or theme metadata from the header comment.
|
||||||
|
*
|
||||||
|
* This is basically a simplified version of the get_file_data() function from /wp-includes/functions.php.
|
||||||
|
* It's intended as a utility for subclasses that detect updates by parsing files in a VCS.
|
||||||
|
*
|
||||||
|
* @param string|null $content File contents.
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public function getFileHeader($content) {
|
||||||
|
$content = (string)$content;
|
||||||
|
|
||||||
|
//WordPress only looks at the first 8 KiB of the file, so we do the same.
|
||||||
|
$content = substr($content, 0, 8192);
|
||||||
|
//Normalize line endings.
|
||||||
|
$content = str_replace("\r", "\n", $content);
|
||||||
|
|
||||||
|
$headers = $this->getHeaderNames();
|
||||||
|
$results = array();
|
||||||
|
foreach ($headers as $field => $name) {
|
||||||
|
$success = preg_match('/^[ \t\/*#@]*' . preg_quote($name, '/') . ':(.*)$/mi', $content, $matches);
|
||||||
|
|
||||||
|
if ( ($success === 1) && $matches[1] ) {
|
||||||
|
$value = $matches[1];
|
||||||
|
if ( function_exists('_cleanup_header_comment') ) {
|
||||||
|
$value = _cleanup_header_comment($value);
|
||||||
|
}
|
||||||
|
$results[$field] = $value;
|
||||||
|
} else {
|
||||||
|
$results[$field] = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array Format: ['HeaderKey' => 'Header Name']
|
||||||
|
*/
|
||||||
|
abstract protected function getHeaderNames();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a specific plugin or theme header.
|
||||||
|
*
|
||||||
|
* @param string $headerName
|
||||||
|
* @return string Either the value of the header, or an empty string if the header doesn't exist.
|
||||||
|
*/
|
||||||
|
abstract public function getHeaderValue($headerName);
|
||||||
|
|
||||||
|
}
|
||||||
|
endif;
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v4p4_Metadata', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p4;
|
||||||
|
|
||||||
|
use LogicException;
|
||||||
|
use stdClass;
|
||||||
|
use WP_Error;
|
||||||
|
|
||||||
|
if ( !class_exists(Metadata::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A base container for holding information about updates and plugin metadata.
|
* A base container for holding information about updates and plugin metadata.
|
||||||
@@ -8,7 +14,13 @@ if ( !class_exists('Puc_v4p4_Metadata', false) ):
|
|||||||
* @copyright 2016
|
* @copyright 2016
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
abstract class Puc_v4p4_Metadata {
|
abstract class Metadata {
|
||||||
|
/**
|
||||||
|
* Additional dynamic properties, usually copied from the API response.
|
||||||
|
*
|
||||||
|
* @var array<string,mixed>
|
||||||
|
*/
|
||||||
|
protected $extraProperties = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an instance of this class from a JSON document.
|
* Create an instance of this class from a JSON document.
|
||||||
@@ -17,7 +29,7 @@ if ( !class_exists('Puc_v4p4_Metadata', false) ):
|
|||||||
* @param string $json
|
* @param string $json
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public static function fromJson(/** @noinspection PhpUnusedParameterInspection */ $json) {
|
public static function fromJson($json) {
|
||||||
throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
|
throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,19 +39,21 @@ if ( !class_exists('Puc_v4p4_Metadata', false) ):
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected static function createFromJson($json, $target) {
|
protected static function createFromJson($json, $target) {
|
||||||
/** @var StdClass $apiResponse */
|
/** @var \StdClass $apiResponse */
|
||||||
$apiResponse = json_decode($json);
|
$apiResponse = json_decode($json);
|
||||||
if ( empty($apiResponse) || !is_object($apiResponse) ){
|
if ( empty($apiResponse) || !is_object($apiResponse) ){
|
||||||
$errorMessage = "Failed to parse update metadata. Try validating your .json file with http://jsonlint.com/";
|
$errorMessage = "Failed to parse update metadata. Try validating your .json file with https://jsonlint.com/";
|
||||||
do_action('puc_api_error', new WP_Error('puc-invalid-json', $errorMessage));
|
do_action('puc_api_error', new WP_Error('puc-invalid-json', $errorMessage));
|
||||||
trigger_error($errorMessage, E_USER_NOTICE);
|
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error -- For plugin developers.
|
||||||
|
trigger_error(esc_html($errorMessage), E_USER_NOTICE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$valid = $target->validateMetadata($apiResponse);
|
$valid = $target->validateMetadata($apiResponse);
|
||||||
if ( is_wp_error($valid) ){
|
if ( is_wp_error($valid) ){
|
||||||
do_action('puc_api_error', $valid);
|
do_action('puc_api_error', $valid);
|
||||||
trigger_error($valid->get_error_message(), E_USER_NOTICE);
|
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error -- For plugin developers.
|
||||||
|
trigger_error(esc_html($valid->get_error_message()), E_USER_NOTICE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,10 +67,10 @@ if ( !class_exists('Puc_v4p4_Metadata', false) ):
|
|||||||
/**
|
/**
|
||||||
* No validation by default! Subclasses should check that the required fields are present.
|
* No validation by default! Subclasses should check that the required fields are present.
|
||||||
*
|
*
|
||||||
* @param StdClass $apiResponse
|
* @param \StdClass $apiResponse
|
||||||
* @return bool|WP_Error
|
* @return bool|\WP_Error
|
||||||
*/
|
*/
|
||||||
protected function validateMetadata(/** @noinspection PhpUnusedParameterInspection */ $apiResponse) {
|
protected function validateMetadata($apiResponse) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,10 +78,10 @@ if ( !class_exists('Puc_v4p4_Metadata', false) ):
|
|||||||
* Create a new instance by copying the necessary fields from another object.
|
* Create a new instance by copying the necessary fields from another object.
|
||||||
*
|
*
|
||||||
* @abstract
|
* @abstract
|
||||||
* @param StdClass|self $object The source object.
|
* @param \StdClass|self $object The source object.
|
||||||
* @return self The new copy.
|
* @return self The new copy.
|
||||||
*/
|
*/
|
||||||
public static function fromObject(/** @noinspection PhpUnusedParameterInspection */ $object) {
|
public static function fromObject($object) {
|
||||||
throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
|
throw new LogicException('The ' . __METHOD__ . ' method must be implemented by subclasses');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,7 +91,7 @@ if ( !class_exists('Puc_v4p4_Metadata', false) ):
|
|||||||
* avoids the "incomplete object" problem if the cached value is loaded
|
* avoids the "incomplete object" problem if the cached value is loaded
|
||||||
* before this class.
|
* before this class.
|
||||||
*
|
*
|
||||||
* @return StdClass
|
* @return \StdClass
|
||||||
*/
|
*/
|
||||||
public function toStdClass() {
|
public function toStdClass() {
|
||||||
$object = new stdClass();
|
$object = new stdClass();
|
||||||
@@ -95,8 +109,8 @@ if ( !class_exists('Puc_v4p4_Metadata', false) ):
|
|||||||
/**
|
/**
|
||||||
* Copy known fields from one object to another.
|
* Copy known fields from one object to another.
|
||||||
*
|
*
|
||||||
* @param StdClass|self $from
|
* @param \StdClass|self $from
|
||||||
* @param StdClass|self $to
|
* @param \StdClass|self $to
|
||||||
*/
|
*/
|
||||||
protected function copyFields($from, $to) {
|
protected function copyFields($from, $to) {
|
||||||
$fields = $this->getFieldNames();
|
$fields = $this->getFieldNames();
|
||||||
@@ -127,6 +141,22 @@ if ( !class_exists('Puc_v4p4_Metadata', false) ):
|
|||||||
protected function getPrefixedFilter($tag) {
|
protected function getPrefixedFilter($tag) {
|
||||||
return 'puc_' . $tag;
|
return 'puc_' . $tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function __set($name, $value) {
|
||||||
|
$this->extraProperties[$name] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __get($name) {
|
||||||
|
return isset($this->extraProperties[$name]) ? $this->extraProperties[$name] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __isset($name) {
|
||||||
|
return isset($this->extraProperties[$name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __unset($name) {
|
||||||
|
unset($this->extraProperties[$name]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
endif;
|
endif;
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4;
|
||||||
|
|
||||||
if ( !class_exists('Puc_v4p4_OAuthSignature', false) ):
|
if ( !class_exists(OAuthSignature::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A basic signature generator for zero-legged OAuth 1.0.
|
* A basic signature generator for zero-legged OAuth 1.0.
|
||||||
*/
|
*/
|
||||||
class Puc_v4p4_OAuthSignature {
|
class OAuthSignature {
|
||||||
private $consumerKey = '';
|
private $consumerKey = '';
|
||||||
private $consumerSecret = '';
|
private $consumerSecret = '';
|
||||||
|
|
||||||
@@ -25,10 +26,10 @@ if ( !class_exists('Puc_v4p4_OAuthSignature', false) ):
|
|||||||
$parameters = array();
|
$parameters = array();
|
||||||
|
|
||||||
//Parse query parameters.
|
//Parse query parameters.
|
||||||
$query = @parse_url($url, PHP_URL_QUERY);
|
$query = wp_parse_url($url, PHP_URL_QUERY);
|
||||||
if ( !empty($query) ) {
|
if ( !empty($query) ) {
|
||||||
parse_str($query, $parsedParams);
|
parse_str($query, $parsedParams);
|
||||||
if ( is_array($parameters) ) {
|
if ( is_array($parsedParams) ) {
|
||||||
$parameters = $parsedParams;
|
$parameters = $parsedParams;
|
||||||
}
|
}
|
||||||
//Remove the query string from the URL. We'll replace it later.
|
//Remove the query string from the URL. We'll replace it later.
|
||||||
@@ -80,7 +81,20 @@ if ( !class_exists('Puc_v4p4_OAuthSignature', false) ):
|
|||||||
*/
|
*/
|
||||||
private function nonce() {
|
private function nonce() {
|
||||||
$mt = microtime();
|
$mt = microtime();
|
||||||
$rand = mt_rand();
|
|
||||||
|
$rand = null;
|
||||||
|
if ( is_callable('random_bytes') ) {
|
||||||
|
try {
|
||||||
|
$rand = random_bytes(16);
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
//Fall back to mt_rand (below).
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $rand === null ) {
|
||||||
|
//phpcs:ignore WordPress.WP.AlternativeFunctions.rand_mt_rand
|
||||||
|
$rand = function_exists('wp_rand') ? wp_rand() : mt_rand();
|
||||||
|
}
|
||||||
|
|
||||||
return md5($mt . '_' . $rand);
|
return md5($mt . '_' . $rand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
188
plugin-update-checker-5.4/Puc/v5p4/Plugin/Package.php
Normal file
188
plugin-update-checker-5.4/Puc/v5p4/Plugin/Package.php
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Plugin;
|
||||||
|
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\InstalledPackage;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\PucFactory;
|
||||||
|
|
||||||
|
if ( !class_exists(Package::class, false) ):
|
||||||
|
|
||||||
|
class Package extends InstalledPackage {
|
||||||
|
/**
|
||||||
|
* @var UpdateChecker
|
||||||
|
*/
|
||||||
|
protected $updateChecker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string Full path of the main plugin file.
|
||||||
|
*/
|
||||||
|
protected $pluginAbsolutePath = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string Plugin basename.
|
||||||
|
*/
|
||||||
|
private $pluginFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string|null
|
||||||
|
*/
|
||||||
|
private $cachedInstalledVersion = null;
|
||||||
|
|
||||||
|
public function __construct($pluginAbsolutePath, $updateChecker) {
|
||||||
|
$this->pluginAbsolutePath = $pluginAbsolutePath;
|
||||||
|
$this->pluginFile = plugin_basename($this->pluginAbsolutePath);
|
||||||
|
|
||||||
|
parent::__construct($updateChecker);
|
||||||
|
|
||||||
|
//Clear the version number cache when something - anything - is upgraded or WP clears the update cache.
|
||||||
|
add_filter('upgrader_post_install', array($this, 'clearCachedVersion'));
|
||||||
|
add_action('delete_site_transient_update_plugins', array($this, 'clearCachedVersion'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInstalledVersion() {
|
||||||
|
if ( isset($this->cachedInstalledVersion) ) {
|
||||||
|
return $this->cachedInstalledVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pluginHeader = $this->getPluginHeader();
|
||||||
|
if ( isset($pluginHeader['Version']) ) {
|
||||||
|
$this->cachedInstalledVersion = $pluginHeader['Version'];
|
||||||
|
return $pluginHeader['Version'];
|
||||||
|
} else {
|
||||||
|
//This can happen if the filename points to something that is not a plugin.
|
||||||
|
$this->updateChecker->triggerError(
|
||||||
|
sprintf(
|
||||||
|
"Cannot read the Version header for '%s'. The filename is incorrect or is not a plugin.",
|
||||||
|
$this->updateChecker->pluginFile
|
||||||
|
),
|
||||||
|
E_USER_WARNING
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear the cached plugin version. This method can be set up as a filter (hook) and will
|
||||||
|
* return the filter argument unmodified.
|
||||||
|
*
|
||||||
|
* @param mixed $filterArgument
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function clearCachedVersion($filterArgument = null) {
|
||||||
|
$this->cachedInstalledVersion = null;
|
||||||
|
return $filterArgument;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAbsoluteDirectoryPath() {
|
||||||
|
return dirname($this->pluginAbsolutePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a specific plugin or theme header.
|
||||||
|
*
|
||||||
|
* @param string $headerName
|
||||||
|
* @param string $defaultValue
|
||||||
|
* @return string Either the value of the header, or $defaultValue if the header doesn't exist or is empty.
|
||||||
|
*/
|
||||||
|
public function getHeaderValue($headerName, $defaultValue = '') {
|
||||||
|
$headers = $this->getPluginHeader();
|
||||||
|
if ( isset($headers[$headerName]) && ($headers[$headerName] !== '') ) {
|
||||||
|
return $headers[$headerName];
|
||||||
|
}
|
||||||
|
return $defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getHeaderNames() {
|
||||||
|
return array(
|
||||||
|
'Name' => 'Plugin Name',
|
||||||
|
'PluginURI' => 'Plugin URI',
|
||||||
|
'Version' => 'Version',
|
||||||
|
'Description' => 'Description',
|
||||||
|
'Author' => 'Author',
|
||||||
|
'AuthorURI' => 'Author URI',
|
||||||
|
'TextDomain' => 'Text Domain',
|
||||||
|
'DomainPath' => 'Domain Path',
|
||||||
|
'Network' => 'Network',
|
||||||
|
|
||||||
|
//The newest WordPress version that this plugin requires or has been tested with.
|
||||||
|
//We support several different formats for compatibility with other libraries.
|
||||||
|
'Tested WP' => 'Tested WP',
|
||||||
|
'Requires WP' => 'Requires WP',
|
||||||
|
'Tested up to' => 'Tested up to',
|
||||||
|
'Requires at least' => 'Requires at least',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the translated plugin title.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getPluginTitle() {
|
||||||
|
$title = '';
|
||||||
|
$header = $this->getPluginHeader();
|
||||||
|
if ( $header && !empty($header['Name']) && isset($header['TextDomain']) ) {
|
||||||
|
$title = translate($header['Name'], $header['TextDomain']);
|
||||||
|
}
|
||||||
|
return $title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get plugin's metadata from its file header.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getPluginHeader() {
|
||||||
|
if ( !is_file($this->pluginAbsolutePath) ) {
|
||||||
|
//This can happen if the plugin filename is wrong.
|
||||||
|
$this->updateChecker->triggerError(
|
||||||
|
sprintf(
|
||||||
|
"Can't to read the plugin header for '%s'. The file does not exist.",
|
||||||
|
$this->updateChecker->pluginFile
|
||||||
|
),
|
||||||
|
E_USER_WARNING
|
||||||
|
);
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !function_exists('get_plugin_data') ) {
|
||||||
|
require_once(ABSPATH . '/wp-admin/includes/plugin.php');
|
||||||
|
}
|
||||||
|
return get_plugin_data($this->pluginAbsolutePath, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeHooks() {
|
||||||
|
remove_filter('upgrader_post_install', array($this, 'clearCachedVersion'));
|
||||||
|
remove_action('delete_site_transient_update_plugins', array($this, 'clearCachedVersion'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the plugin file is inside the mu-plugins directory.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isMuPlugin() {
|
||||||
|
static $cachedResult = null;
|
||||||
|
|
||||||
|
if ( $cachedResult === null ) {
|
||||||
|
if ( !defined('WPMU_PLUGIN_DIR') || !is_string(WPMU_PLUGIN_DIR) ) {
|
||||||
|
$cachedResult = false;
|
||||||
|
return $cachedResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Convert both paths to the canonical form before comparison.
|
||||||
|
$muPluginDir = realpath(WPMU_PLUGIN_DIR);
|
||||||
|
$pluginPath = realpath($this->pluginAbsolutePath);
|
||||||
|
//If realpath() fails, just normalize the syntax instead.
|
||||||
|
if (($muPluginDir === false) || ($pluginPath === false)) {
|
||||||
|
$muPluginDir = PucFactory::normalizePath(WPMU_PLUGIN_DIR);
|
||||||
|
$pluginPath = PucFactory::normalizePath($this->pluginAbsolutePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
$cachedResult = (strpos($pluginPath, $muPluginDir) === 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $cachedResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
endif;
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v4p4_Plugin_Info', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Plugin;
|
||||||
|
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\Metadata;
|
||||||
|
|
||||||
|
if ( !class_exists(PluginInfo::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A container class for holding and transforming various plugin metadata.
|
* A container class for holding and transforming various plugin metadata.
|
||||||
@@ -8,7 +12,7 @@ if ( !class_exists('Puc_v4p4_Plugin_Info', false) ):
|
|||||||
* @copyright 2016
|
* @copyright 2016
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
class Puc_v4p4_Plugin_Info extends Puc_v4p4_Metadata {
|
class PluginInfo extends Metadata {
|
||||||
//Most fields map directly to the contents of the plugin's info.json file.
|
//Most fields map directly to the contents of the plugin's info.json file.
|
||||||
//See the relevant docs for a description of their meaning.
|
//See the relevant docs for a description of their meaning.
|
||||||
public $name;
|
public $name;
|
||||||
@@ -27,6 +31,7 @@ if ( !class_exists('Puc_v4p4_Plugin_Info', false) ):
|
|||||||
|
|
||||||
public $requires;
|
public $requires;
|
||||||
public $tested;
|
public $tested;
|
||||||
|
public $requires_php;
|
||||||
public $upgrade_notice;
|
public $upgrade_notice;
|
||||||
|
|
||||||
public $rating;
|
public $rating;
|
||||||
@@ -63,8 +68,8 @@ if ( !class_exists('Puc_v4p4_Plugin_Info', false) ):
|
|||||||
/**
|
/**
|
||||||
* Very, very basic validation.
|
* Very, very basic validation.
|
||||||
*
|
*
|
||||||
* @param StdClass $apiResponse
|
* @param \StdClass $apiResponse
|
||||||
* @return bool|WP_Error
|
* @return bool|\WP_Error
|
||||||
*/
|
*/
|
||||||
protected function validateMetadata($apiResponse) {
|
protected function validateMetadata($apiResponse) {
|
||||||
if (
|
if (
|
||||||
@@ -72,7 +77,7 @@ if ( !class_exists('Puc_v4p4_Plugin_Info', false) ):
|
|||||||
|| empty($apiResponse->name)
|
|| empty($apiResponse->name)
|
||||||
|| empty($apiResponse->version)
|
|| empty($apiResponse->version)
|
||||||
) {
|
) {
|
||||||
return new WP_Error(
|
return new \WP_Error(
|
||||||
'puc-invalid-metadata',
|
'puc-invalid-metadata',
|
||||||
"The plugin metadata file does not contain the required 'name' and/or 'version' keys."
|
"The plugin metadata file does not contain the required 'name' and/or 'version' keys."
|
||||||
);
|
);
|
||||||
@@ -87,13 +92,14 @@ if ( !class_exists('Puc_v4p4_Plugin_Info', false) ):
|
|||||||
* @return object
|
* @return object
|
||||||
*/
|
*/
|
||||||
public function toWpFormat(){
|
public function toWpFormat(){
|
||||||
$info = new stdClass;
|
$info = new \stdClass;
|
||||||
|
|
||||||
//The custom update API is built so that many fields have the same name and format
|
//The custom update API is built so that many fields have the same name and format
|
||||||
//as those returned by the native WordPress.org API. These can be assigned directly.
|
//as those returned by the native WordPress.org API. These can be assigned directly.
|
||||||
$sameFormat = array(
|
$sameFormat = array(
|
||||||
'name', 'slug', 'version', 'requires', 'tested', 'rating', 'upgrade_notice',
|
'name', 'slug', 'version', 'requires', 'tested', 'rating', 'upgrade_notice',
|
||||||
'num_ratings', 'downloaded', 'active_installs', 'homepage', 'last_updated',
|
'num_ratings', 'downloaded', 'active_installs', 'homepage', 'last_updated',
|
||||||
|
'requires_php',
|
||||||
);
|
);
|
||||||
foreach($sameFormat as $field){
|
foreach($sameFormat as $field){
|
||||||
if ( isset($this->$field) ) {
|
if ( isset($this->$field) ) {
|
||||||
294
plugin-update-checker-5.4/Puc/v5p4/Plugin/Ui.php
Normal file
294
plugin-update-checker-5.4/Puc/v5p4/Plugin/Ui.php
Normal file
@@ -0,0 +1,294 @@
|
|||||||
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Plugin;
|
||||||
|
|
||||||
|
if ( !class_exists(Ui::class, false) ):
|
||||||
|
/**
|
||||||
|
* Additional UI elements for plugins.
|
||||||
|
*/
|
||||||
|
class Ui {
|
||||||
|
private $updateChecker;
|
||||||
|
private $manualCheckErrorTransient = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param UpdateChecker $updateChecker
|
||||||
|
*/
|
||||||
|
public function __construct($updateChecker) {
|
||||||
|
$this->updateChecker = $updateChecker;
|
||||||
|
$this->manualCheckErrorTransient = $this->updateChecker->getUniqueName('manual_check_errors');
|
||||||
|
|
||||||
|
add_action('admin_init', array($this, 'onAdminInit'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onAdminInit() {
|
||||||
|
if ( $this->updateChecker->userCanInstallUpdates() ) {
|
||||||
|
$this->handleManualCheck();
|
||||||
|
|
||||||
|
add_filter('plugin_row_meta', array($this, 'addViewDetailsLink'), 10, 3);
|
||||||
|
add_filter('plugin_row_meta', array($this, 'addCheckForUpdatesLink'), 10, 2);
|
||||||
|
add_action('all_admin_notices', array($this, 'displayManualCheckResult'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a "View Details" link to the plugin row in the "Plugins" page. By default,
|
||||||
|
* the new link will appear before the "Visit plugin site" link (if present).
|
||||||
|
*
|
||||||
|
* You can change the link text by using the "puc_view_details_link-$slug" filter.
|
||||||
|
* Returning an empty string from the filter will disable the link.
|
||||||
|
*
|
||||||
|
* You can change the position of the link using the
|
||||||
|
* "puc_view_details_link_position-$slug" filter.
|
||||||
|
* Returning 'before' or 'after' will place the link immediately before/after
|
||||||
|
* the "Visit plugin site" link.
|
||||||
|
* Returning 'append' places the link after any existing links at the time of the hook.
|
||||||
|
* Returning 'replace' replaces the "Visit plugin site" link.
|
||||||
|
* Returning anything else disables the link when there is a "Visit plugin site" link.
|
||||||
|
*
|
||||||
|
* If there is no "Visit plugin site" link 'append' is always used!
|
||||||
|
*
|
||||||
|
* @param array $pluginMeta Array of meta links.
|
||||||
|
* @param string $pluginFile
|
||||||
|
* @param array $pluginData Array of plugin header data.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function addViewDetailsLink($pluginMeta, $pluginFile, $pluginData = array()) {
|
||||||
|
if ( $this->isMyPluginFile($pluginFile) && !isset($pluginData['slug']) ) {
|
||||||
|
$linkText = apply_filters($this->updateChecker->getUniqueName('view_details_link'), __('View details'));
|
||||||
|
if ( !empty($linkText) ) {
|
||||||
|
$viewDetailsLinkPosition = 'append';
|
||||||
|
|
||||||
|
//Find the "Visit plugin site" link (if present).
|
||||||
|
$visitPluginSiteLinkIndex = count($pluginMeta) - 1;
|
||||||
|
if ( $pluginData['PluginURI'] ) {
|
||||||
|
$escapedPluginUri = esc_url($pluginData['PluginURI']);
|
||||||
|
foreach ($pluginMeta as $linkIndex => $existingLink) {
|
||||||
|
if ( strpos($existingLink, $escapedPluginUri) !== false ) {
|
||||||
|
$visitPluginSiteLinkIndex = $linkIndex;
|
||||||
|
$viewDetailsLinkPosition = apply_filters(
|
||||||
|
$this->updateChecker->getUniqueName('view_details_link_position'),
|
||||||
|
'before'
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$viewDetailsLink = sprintf('<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
|
||||||
|
esc_url(network_admin_url('plugin-install.php?tab=plugin-information&plugin=' . urlencode($this->updateChecker->slug) .
|
||||||
|
'&TB_iframe=true&width=600&height=550')),
|
||||||
|
esc_attr(sprintf(__('More information about %s'), $pluginData['Name'])),
|
||||||
|
esc_attr($pluginData['Name']),
|
||||||
|
$linkText
|
||||||
|
);
|
||||||
|
switch ($viewDetailsLinkPosition) {
|
||||||
|
case 'before':
|
||||||
|
array_splice($pluginMeta, $visitPluginSiteLinkIndex, 0, $viewDetailsLink);
|
||||||
|
break;
|
||||||
|
case 'after':
|
||||||
|
array_splice($pluginMeta, $visitPluginSiteLinkIndex + 1, 0, $viewDetailsLink);
|
||||||
|
break;
|
||||||
|
case 'replace':
|
||||||
|
$pluginMeta[$visitPluginSiteLinkIndex] = $viewDetailsLink;
|
||||||
|
break;
|
||||||
|
case 'append':
|
||||||
|
default:
|
||||||
|
$pluginMeta[] = $viewDetailsLink;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $pluginMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a "Check for updates" link to the plugin row in the "Plugins" page. By default,
|
||||||
|
* the new link will appear after the "Visit plugin site" link if present, otherwise
|
||||||
|
* after the "View plugin details" link.
|
||||||
|
*
|
||||||
|
* You can change the link text by using the "puc_manual_check_link-$slug" filter.
|
||||||
|
* Returning an empty string from the filter will disable the link.
|
||||||
|
*
|
||||||
|
* @param array $pluginMeta Array of meta links.
|
||||||
|
* @param string $pluginFile
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function addCheckForUpdatesLink($pluginMeta, $pluginFile) {
|
||||||
|
if ( $this->isMyPluginFile($pluginFile) ) {
|
||||||
|
$linkUrl = wp_nonce_url(
|
||||||
|
add_query_arg(
|
||||||
|
array(
|
||||||
|
'puc_check_for_updates' => 1,
|
||||||
|
'puc_slug' => $this->updateChecker->slug,
|
||||||
|
),
|
||||||
|
self_admin_url('plugins.php')
|
||||||
|
),
|
||||||
|
'puc_check_for_updates'
|
||||||
|
);
|
||||||
|
|
||||||
|
$linkText = apply_filters(
|
||||||
|
$this->updateChecker->getUniqueName('manual_check_link'),
|
||||||
|
__('Check for updates', 'plugin-update-checker')
|
||||||
|
);
|
||||||
|
if ( !empty($linkText) ) {
|
||||||
|
/** @noinspection HtmlUnknownTarget */
|
||||||
|
$pluginMeta[] = sprintf('<a href="%s">%s</a>', esc_attr($linkUrl), $linkText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $pluginMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function isMyPluginFile($pluginFile) {
|
||||||
|
return ($pluginFile == $this->updateChecker->pluginFile)
|
||||||
|
|| (!empty($this->updateChecker->muPluginFile) && ($pluginFile == $this->updateChecker->muPluginFile));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for updates when the user clicks the "Check for updates" link.
|
||||||
|
*
|
||||||
|
* @see self::addCheckForUpdatesLink()
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function handleManualCheck() {
|
||||||
|
$shouldCheck =
|
||||||
|
isset($_GET['puc_check_for_updates'], $_GET['puc_slug'])
|
||||||
|
&& $_GET['puc_slug'] == $this->updateChecker->slug
|
||||||
|
&& check_admin_referer('puc_check_for_updates');
|
||||||
|
|
||||||
|
if ( $shouldCheck ) {
|
||||||
|
$update = $this->updateChecker->checkForUpdates();
|
||||||
|
$status = ($update === null) ? 'no_update' : 'update_available';
|
||||||
|
$lastRequestApiErrors = $this->updateChecker->getLastRequestApiErrors();
|
||||||
|
|
||||||
|
if ( ($update === null) && !empty($lastRequestApiErrors) ) {
|
||||||
|
//Some errors are not critical. For example, if PUC tries to retrieve the readme.txt
|
||||||
|
//file from GitHub and gets a 404, that's an API error, but it doesn't prevent updates
|
||||||
|
//from working. Maybe the plugin simply doesn't have a readme.
|
||||||
|
//Let's only show important errors.
|
||||||
|
$foundCriticalErrors = false;
|
||||||
|
$questionableErrorCodes = array(
|
||||||
|
'puc-github-http-error',
|
||||||
|
'puc-gitlab-http-error',
|
||||||
|
'puc-bitbucket-http-error',
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($lastRequestApiErrors as $item) {
|
||||||
|
$wpError = $item['error'];
|
||||||
|
/** @var \WP_Error $wpError */
|
||||||
|
if ( !in_array($wpError->get_error_code(), $questionableErrorCodes) ) {
|
||||||
|
$foundCriticalErrors = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $foundCriticalErrors ) {
|
||||||
|
$status = 'error';
|
||||||
|
set_site_transient($this->manualCheckErrorTransient, $lastRequestApiErrors, 60);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_redirect(add_query_arg(
|
||||||
|
array(
|
||||||
|
'puc_update_check_result' => $status,
|
||||||
|
'puc_slug' => $this->updateChecker->slug,
|
||||||
|
),
|
||||||
|
self_admin_url('plugins.php')
|
||||||
|
));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the results of a manual update check.
|
||||||
|
*
|
||||||
|
* @see self::handleManualCheck()
|
||||||
|
*
|
||||||
|
* You can change the result message by using the "puc_manual_check_message-$slug" filter.
|
||||||
|
*/
|
||||||
|
public function displayManualCheckResult() {
|
||||||
|
//phpcs:disable WordPress.Security.NonceVerification.Recommended -- Just displaying a message.
|
||||||
|
if ( isset($_GET['puc_update_check_result'], $_GET['puc_slug']) && ($_GET['puc_slug'] == $this->updateChecker->slug) ) {
|
||||||
|
$status = sanitize_key($_GET['puc_update_check_result']);
|
||||||
|
$title = $this->updateChecker->getInstalledPackage()->getPluginTitle();
|
||||||
|
$noticeClass = 'updated notice-success';
|
||||||
|
$details = '';
|
||||||
|
|
||||||
|
if ( $status == 'no_update' ) {
|
||||||
|
$message = sprintf(_x('The %s plugin is up to date.', 'the plugin title', 'plugin-update-checker'), $title);
|
||||||
|
} else if ( $status == 'update_available' ) {
|
||||||
|
$message = sprintf(_x('A new version of the %s plugin is available.', 'the plugin title', 'plugin-update-checker'), $title);
|
||||||
|
} else if ( $status === 'error' ) {
|
||||||
|
$message = sprintf(_x('Could not determine if updates are available for %s.', 'the plugin title', 'plugin-update-checker'), $title);
|
||||||
|
$noticeClass = 'error notice-error';
|
||||||
|
|
||||||
|
$details = $this->formatManualCheckErrors(get_site_transient($this->manualCheckErrorTransient));
|
||||||
|
delete_site_transient($this->manualCheckErrorTransient);
|
||||||
|
} else {
|
||||||
|
$message = sprintf(__('Unknown update checker status "%s"', 'plugin-update-checker'), $status);
|
||||||
|
$noticeClass = 'error notice-error';
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = esc_html($message);
|
||||||
|
|
||||||
|
//Plugins can replace the message with their own, including adding HTML.
|
||||||
|
$message = apply_filters(
|
||||||
|
$this->updateChecker->getUniqueName('manual_check_message'),
|
||||||
|
$message,
|
||||||
|
$status
|
||||||
|
);
|
||||||
|
|
||||||
|
printf(
|
||||||
|
'<div class="notice %s is-dismissible"><p>%s</p>%s</div>',
|
||||||
|
esc_attr($noticeClass),
|
||||||
|
//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Was escaped above, and plugins can add HTML.
|
||||||
|
$message,
|
||||||
|
//phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Contains HTML. Content should already be escaped.
|
||||||
|
$details
|
||||||
|
);
|
||||||
|
}
|
||||||
|
//phpcs:enable
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format the list of errors that were thrown during an update check.
|
||||||
|
*
|
||||||
|
* @param array $errors
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function formatManualCheckErrors($errors) {
|
||||||
|
if ( empty($errors) ) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
$output = '';
|
||||||
|
|
||||||
|
$showAsList = count($errors) > 1;
|
||||||
|
if ( $showAsList ) {
|
||||||
|
$output .= '<ol>';
|
||||||
|
$formatString = '<li>%1$s <code>%2$s</code></li>';
|
||||||
|
} else {
|
||||||
|
$formatString = '<p>%1$s <code>%2$s</code></p>';
|
||||||
|
}
|
||||||
|
foreach ($errors as $item) {
|
||||||
|
$wpError = $item['error'];
|
||||||
|
/** @var \WP_Error $wpError */
|
||||||
|
$output .= sprintf(
|
||||||
|
$formatString,
|
||||||
|
esc_html($wpError->get_error_message()),
|
||||||
|
esc_html($wpError->get_error_code())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ( $showAsList ) {
|
||||||
|
$output .= '</ol>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeHooks() {
|
||||||
|
remove_action('admin_init', array($this, 'onAdminInit'));
|
||||||
|
remove_filter('plugin_row_meta', array($this, 'addViewDetailsLink'), 10);
|
||||||
|
remove_filter('plugin_row_meta', array($this, 'addCheckForUpdatesLink'), 10);
|
||||||
|
remove_action('all_admin_notices', array($this, 'displayManualCheckResult'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
endif;
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v4p4_Plugin_Update', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Plugin;
|
||||||
|
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\Update as BaseUpdate;
|
||||||
|
|
||||||
|
if ( !class_exists(Update::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple container class for holding information about an available update.
|
* A simple container class for holding information about an available update.
|
||||||
@@ -8,29 +12,30 @@ if ( !class_exists('Puc_v4p4_Plugin_Update', false) ):
|
|||||||
* @copyright 2016
|
* @copyright 2016
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
class Puc_v4p4_Plugin_Update extends Puc_v4p4_Update {
|
class Update extends BaseUpdate {
|
||||||
public $id = 0;
|
public $id = 0;
|
||||||
public $homepage;
|
public $homepage;
|
||||||
public $upgrade_notice;
|
public $upgrade_notice;
|
||||||
public $tested;
|
public $tested;
|
||||||
|
public $requires_php = false;
|
||||||
public $icons = array();
|
public $icons = array();
|
||||||
public $filename; //Plugin filename relative to the plugins directory.
|
public $filename; //Plugin filename relative to the plugins directory.
|
||||||
|
|
||||||
protected static $extraFields = array(
|
protected static $extraFields = array(
|
||||||
'id', 'homepage', 'tested', 'upgrade_notice', 'icons', 'filename',
|
'id', 'homepage', 'tested', 'requires_php', 'upgrade_notice', 'icons', 'filename',
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance of PluginUpdate from its JSON-encoded representation.
|
* Create a new instance of PluginUpdate from its JSON-encoded representation.
|
||||||
*
|
*
|
||||||
* @param string $json
|
* @param string $json
|
||||||
* @return Puc_v4p4_Plugin_Update|null
|
* @return self|null
|
||||||
*/
|
*/
|
||||||
public static function fromJson($json){
|
public static function fromJson($json){
|
||||||
//Since update-related information is simply a subset of the full plugin info,
|
//Since update-related information is simply a subset of the full plugin info,
|
||||||
//we can parse the update JSON as if it was a plugin info string, then copy over
|
//we can parse the update JSON as if it was a plugin info string, then copy over
|
||||||
//the parts that we care about.
|
//the parts that we care about.
|
||||||
$pluginInfo = Puc_v4p4_Plugin_Info::fromJson($json);
|
$pluginInfo = PluginInfo::fromJson($json);
|
||||||
if ( $pluginInfo !== null ) {
|
if ( $pluginInfo !== null ) {
|
||||||
return self::fromPluginInfo($pluginInfo);
|
return self::fromPluginInfo($pluginInfo);
|
||||||
} else {
|
} else {
|
||||||
@@ -42,18 +47,18 @@ if ( !class_exists('Puc_v4p4_Plugin_Update', false) ):
|
|||||||
* Create a new instance of PluginUpdate based on an instance of PluginInfo.
|
* Create a new instance of PluginUpdate based on an instance of PluginInfo.
|
||||||
* Basically, this just copies a subset of fields from one object to another.
|
* Basically, this just copies a subset of fields from one object to another.
|
||||||
*
|
*
|
||||||
* @param Puc_v4p4_Plugin_Info $info
|
* @param PluginInfo $info
|
||||||
* @return Puc_v4p4_Plugin_Update
|
* @return static
|
||||||
*/
|
*/
|
||||||
public static function fromPluginInfo($info){
|
public static function fromPluginInfo($info){
|
||||||
return self::fromObject($info);
|
return static::fromObject($info);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance by copying the necessary fields from another object.
|
* Create a new instance by copying the necessary fields from another object.
|
||||||
*
|
*
|
||||||
* @param StdClass|Puc_v4p4_Plugin_Info|Puc_v4p4_Plugin_Update $object The source object.
|
* @param \StdClass|PluginInfo|self $object The source object.
|
||||||
* @return Puc_v4p4_Plugin_Update The new copy.
|
* @return self The new copy.
|
||||||
*/
|
*/
|
||||||
public static function fromObject($object) {
|
public static function fromObject($object) {
|
||||||
$update = new self();
|
$update = new self();
|
||||||
@@ -79,6 +84,7 @@ if ( !class_exists('Puc_v4p4_Plugin_Update', false) ):
|
|||||||
$update->id = $this->id;
|
$update->id = $this->id;
|
||||||
$update->url = $this->homepage;
|
$update->url = $this->homepage;
|
||||||
$update->tested = $this->tested;
|
$update->tested = $this->tested;
|
||||||
|
$update->requires_php = $this->requires_php;
|
||||||
$update->plugin = $this->filename;
|
$update->plugin = $this->filename;
|
||||||
|
|
||||||
if ( !empty($this->upgrade_notice) ) {
|
if ( !empty($this->upgrade_notice) ) {
|
||||||
425
plugin-update-checker-5.4/Puc/v5p4/Plugin/UpdateChecker.php
Normal file
425
plugin-update-checker-5.4/Puc/v5p4/Plugin/UpdateChecker.php
Normal file
@@ -0,0 +1,425 @@
|
|||||||
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Plugin;
|
||||||
|
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\InstalledPackage;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\UpdateChecker as BaseUpdateChecker;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\Scheduler;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\DebugBar;
|
||||||
|
|
||||||
|
if ( !class_exists(UpdateChecker::class, false) ):
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A custom plugin update checker.
|
||||||
|
*
|
||||||
|
* @author Janis Elsts
|
||||||
|
* @copyright 2018
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
class UpdateChecker extends BaseUpdateChecker {
|
||||||
|
protected $updateTransient = 'update_plugins';
|
||||||
|
protected $componentType = 'plugin';
|
||||||
|
|
||||||
|
public $pluginAbsolutePath = ''; //Full path of the main plugin file.
|
||||||
|
public $pluginFile = ''; //Plugin filename relative to the plugins directory. Many WP APIs use this to identify plugins.
|
||||||
|
public $muPluginFile = ''; //For MU plugins, the plugin filename relative to the mu-plugins directory.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Package
|
||||||
|
*/
|
||||||
|
protected $package;
|
||||||
|
|
||||||
|
private $extraUi = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class constructor.
|
||||||
|
*
|
||||||
|
* @param string $metadataUrl The URL of the plugin's metadata file.
|
||||||
|
* @param string $pluginFile Fully qualified path to the main plugin file.
|
||||||
|
* @param string $slug The plugin's 'slug'. If not specified, the filename part of $pluginFile sans '.php' will be used as the slug.
|
||||||
|
* @param integer $checkPeriod How often to check for updates (in hours). Defaults to checking every 12 hours. Set to 0 to disable automatic update checks.
|
||||||
|
* @param string $optionName Where to store book-keeping info about update checks. Defaults to 'external_updates-$slug'.
|
||||||
|
* @param string $muPluginFile Optional. The plugin filename relative to the mu-plugins directory.
|
||||||
|
*/
|
||||||
|
public function __construct($metadataUrl, $pluginFile, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = ''){
|
||||||
|
$this->pluginAbsolutePath = $pluginFile;
|
||||||
|
$this->pluginFile = plugin_basename($this->pluginAbsolutePath);
|
||||||
|
$this->muPluginFile = $muPluginFile;
|
||||||
|
|
||||||
|
//If no slug is specified, use the name of the main plugin file as the slug.
|
||||||
|
//For example, 'my-cool-plugin/cool-plugin.php' becomes 'cool-plugin'.
|
||||||
|
if ( empty($slug) ){
|
||||||
|
$slug = basename($this->pluginFile, '.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
//Plugin slugs must be unique.
|
||||||
|
$slugCheckFilter = 'puc_is_slug_in_use-' . $slug;
|
||||||
|
$slugUsedBy = apply_filters($slugCheckFilter, false);
|
||||||
|
if ( $slugUsedBy ) {
|
||||||
|
$this->triggerError(sprintf(
|
||||||
|
'Plugin slug "%s" is already in use by %s. Slugs must be unique.',
|
||||||
|
$slug,
|
||||||
|
$slugUsedBy
|
||||||
|
), E_USER_ERROR);
|
||||||
|
}
|
||||||
|
add_filter($slugCheckFilter, array($this, 'getAbsolutePath'));
|
||||||
|
|
||||||
|
parent::__construct($metadataUrl, dirname($this->pluginFile), $slug, $checkPeriod, $optionName);
|
||||||
|
|
||||||
|
//Backwards compatibility: If the plugin is a mu-plugin but no $muPluginFile is specified, assume
|
||||||
|
//it's the same as $pluginFile given that it's not in a subdirectory (WP only looks in the base dir).
|
||||||
|
if ( (strpbrk($this->pluginFile, '/\\') === false) && $this->isUnknownMuPlugin() ) {
|
||||||
|
$this->muPluginFile = $this->pluginFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
//To prevent a crash during plugin uninstallation, remove updater hooks when the user removes the plugin.
|
||||||
|
//Details: https://github.com/YahnisElsts/plugin-update-checker/issues/138#issuecomment-335590964
|
||||||
|
add_action('uninstall_' . $this->pluginFile, array($this, 'removeHooks'));
|
||||||
|
|
||||||
|
$this->extraUi = new Ui($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an instance of the scheduler.
|
||||||
|
*
|
||||||
|
* @param int $checkPeriod
|
||||||
|
* @return Scheduler
|
||||||
|
*/
|
||||||
|
protected function createScheduler($checkPeriod) {
|
||||||
|
$scheduler = new Scheduler($this, $checkPeriod, array('load-plugins.php'));
|
||||||
|
register_deactivation_hook($this->pluginFile, array($scheduler, 'removeUpdaterCron'));
|
||||||
|
return $scheduler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install the hooks required to run periodic update checks and inject update info
|
||||||
|
* into WP data structures.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function installHooks(){
|
||||||
|
//Override requests for plugin information
|
||||||
|
add_filter('plugins_api', array($this, 'injectInfo'), 20, 3);
|
||||||
|
|
||||||
|
parent::installHooks();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove update checker hooks.
|
||||||
|
*
|
||||||
|
* The intent is to prevent a fatal error that can happen if the plugin has an uninstall
|
||||||
|
* hook. During uninstallation, WP includes the main plugin file (which creates a PUC instance),
|
||||||
|
* the uninstall hook runs, WP deletes the plugin files and then updates some transients.
|
||||||
|
* If PUC hooks are still around at this time, they could throw an error while trying to
|
||||||
|
* autoload classes from files that no longer exist.
|
||||||
|
*
|
||||||
|
* The "site_transient_{$transient}" filter is the main problem here, but let's also remove
|
||||||
|
* most other PUC hooks to be safe.
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
public function removeHooks() {
|
||||||
|
parent::removeHooks();
|
||||||
|
$this->extraUi->removeHooks();
|
||||||
|
$this->package->removeHooks();
|
||||||
|
|
||||||
|
remove_filter('plugins_api', array($this, 'injectInfo'), 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve plugin info from the configured API endpoint.
|
||||||
|
*
|
||||||
|
* @uses wp_remote_get()
|
||||||
|
*
|
||||||
|
* @param array $queryArgs Additional query arguments to append to the request. Optional.
|
||||||
|
* @return PluginInfo
|
||||||
|
*/
|
||||||
|
public function requestInfo($queryArgs = array()) {
|
||||||
|
list($pluginInfo, $result) = $this->requestMetadata(
|
||||||
|
PluginInfo::class,
|
||||||
|
'request_info',
|
||||||
|
$queryArgs
|
||||||
|
);
|
||||||
|
|
||||||
|
if ( $pluginInfo !== null ) {
|
||||||
|
/** @var PluginInfo $pluginInfo */
|
||||||
|
$pluginInfo->filename = $this->pluginFile;
|
||||||
|
$pluginInfo->slug = $this->slug;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pluginInfo = apply_filters($this->getUniqueName('request_info_result'), $pluginInfo, $result);
|
||||||
|
return $pluginInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the latest update (if any) from the configured API endpoint.
|
||||||
|
*
|
||||||
|
* @uses UpdateChecker::requestInfo()
|
||||||
|
*
|
||||||
|
* @return Update|null An instance of Plugin Update, or NULL when no updates are available.
|
||||||
|
*/
|
||||||
|
public function requestUpdate() {
|
||||||
|
//For the sake of simplicity, this function just calls requestInfo()
|
||||||
|
//and transforms the result accordingly.
|
||||||
|
$pluginInfo = $this->requestInfo(array('checking_for_updates' => '1'));
|
||||||
|
if ( $pluginInfo === null ){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$update = Update::fromPluginInfo($pluginInfo);
|
||||||
|
|
||||||
|
$update = $this->filterUpdateResult($update);
|
||||||
|
|
||||||
|
return $update;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Intercept plugins_api() calls that request information about our plugin and
|
||||||
|
* use the configured API endpoint to satisfy them.
|
||||||
|
*
|
||||||
|
* @see plugins_api()
|
||||||
|
*
|
||||||
|
* @param mixed $result
|
||||||
|
* @param string $action
|
||||||
|
* @param array|object $args
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function injectInfo($result, $action = null, $args = null){
|
||||||
|
$relevant = ($action == 'plugin_information') && isset($args->slug) && (
|
||||||
|
($args->slug == $this->slug) || ($args->slug == dirname($this->pluginFile))
|
||||||
|
);
|
||||||
|
if ( !$relevant ) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pluginInfo = $this->requestInfo();
|
||||||
|
$this->fixSupportedWordpressVersion($pluginInfo);
|
||||||
|
|
||||||
|
$pluginInfo = apply_filters($this->getUniqueName('pre_inject_info'), $pluginInfo);
|
||||||
|
if ( $pluginInfo ) {
|
||||||
|
return $pluginInfo->toWpFormat();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function shouldShowUpdates() {
|
||||||
|
//No update notifications for mu-plugins unless explicitly enabled. The MU plugin file
|
||||||
|
//is usually different from the main plugin file so the update wouldn't show up properly anyway.
|
||||||
|
return !$this->isUnknownMuPlugin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \stdClass|null $updates
|
||||||
|
* @param \stdClass $updateToAdd
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
protected function addUpdateToList($updates, $updateToAdd) {
|
||||||
|
if ( $this->package->isMuPlugin() ) {
|
||||||
|
//WP does not support automatic update installation for mu-plugins, but we can
|
||||||
|
//still display a notice.
|
||||||
|
$updateToAdd->package = null;
|
||||||
|
}
|
||||||
|
return parent::addUpdateToList($updates, $updateToAdd);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \stdClass|null $updates
|
||||||
|
* @return \stdClass|null
|
||||||
|
*/
|
||||||
|
protected function removeUpdateFromList($updates) {
|
||||||
|
$updates = parent::removeUpdateFromList($updates);
|
||||||
|
if ( !empty($this->muPluginFile) && isset($updates, $updates->response) ) {
|
||||||
|
unset($updates->response[$this->muPluginFile]);
|
||||||
|
}
|
||||||
|
return $updates;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For plugins, the update array is indexed by the plugin filename relative to the "plugins"
|
||||||
|
* directory. Example: "plugin-name/plugin.php".
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getUpdateListKey() {
|
||||||
|
if ( $this->package->isMuPlugin() ) {
|
||||||
|
return $this->muPluginFile;
|
||||||
|
}
|
||||||
|
return $this->pluginFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getNoUpdateItemFields() {
|
||||||
|
return array_merge(
|
||||||
|
parent::getNoUpdateItemFields(),
|
||||||
|
array(
|
||||||
|
'id' => $this->pluginFile,
|
||||||
|
'slug' => $this->slug,
|
||||||
|
'plugin' => $this->pluginFile,
|
||||||
|
'icons' => array(),
|
||||||
|
'banners' => array(),
|
||||||
|
'banners_rtl' => array(),
|
||||||
|
'tested' => '',
|
||||||
|
'compatibility' => new \stdClass(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alias for isBeingUpgraded().
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
* @param \WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isPluginBeingUpgraded($upgrader = null) {
|
||||||
|
return $this->isBeingUpgraded($upgrader);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is there an update being installed for this plugin, right now?
|
||||||
|
*
|
||||||
|
* @param \WP_Upgrader|null $upgrader
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isBeingUpgraded($upgrader = null) {
|
||||||
|
return $this->upgraderStatus->isPluginBeingUpgraded($this->pluginFile, $upgrader);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the details of the currently available update, if any.
|
||||||
|
*
|
||||||
|
* If no updates are available, or if the last known update version is below or equal
|
||||||
|
* to the currently installed version, this method will return NULL.
|
||||||
|
*
|
||||||
|
* Uses cached update data. To retrieve update information straight from
|
||||||
|
* the metadata URL, call requestUpdate() instead.
|
||||||
|
*
|
||||||
|
* @return Update|null
|
||||||
|
*/
|
||||||
|
public function getUpdate() {
|
||||||
|
$update = parent::getUpdate();
|
||||||
|
if ( isset($update) ) {
|
||||||
|
/** @var Update $update */
|
||||||
|
$update->filename = $this->pluginFile;
|
||||||
|
}
|
||||||
|
return $update;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the translated plugin title.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getPluginTitle() {
|
||||||
|
return $this->package->getPluginTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the current user has the required permissions to install updates.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function userCanInstallUpdates() {
|
||||||
|
return current_user_can('update_plugins');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the plugin file is inside the mu-plugins directory.
|
||||||
|
*
|
||||||
|
* @deprecated
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function isMuPlugin() {
|
||||||
|
return $this->package->isMuPlugin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MU plugins are partially supported, but only when we know which file in mu-plugins
|
||||||
|
* corresponds to this plugin.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function isUnknownMuPlugin() {
|
||||||
|
return empty($this->muPluginFile) && $this->package->isMuPlugin();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get absolute path to the main plugin file.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getAbsolutePath() {
|
||||||
|
return $this->pluginAbsolutePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a callback for filtering query arguments.
|
||||||
|
*
|
||||||
|
* The callback function should take one argument - an associative array of query arguments.
|
||||||
|
* It should return a modified array of query arguments.
|
||||||
|
*
|
||||||
|
* @uses add_filter() This method is a convenience wrapper for add_filter().
|
||||||
|
*
|
||||||
|
* @param callable $callback
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function addQueryArgFilter($callback){
|
||||||
|
$this->addFilter('request_info_query_args', $callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a callback for filtering arguments passed to wp_remote_get().
|
||||||
|
*
|
||||||
|
* The callback function should take one argument - an associative array of arguments -
|
||||||
|
* and return a modified array or arguments. See the WP documentation on wp_remote_get()
|
||||||
|
* for details on what arguments are available and how they work.
|
||||||
|
*
|
||||||
|
* @uses add_filter() This method is a convenience wrapper for add_filter().
|
||||||
|
*
|
||||||
|
* @param callable $callback
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function addHttpRequestArgFilter($callback) {
|
||||||
|
$this->addFilter('request_info_options', $callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a callback for filtering the plugin info retrieved from the external API.
|
||||||
|
*
|
||||||
|
* The callback function should take two arguments. If the plugin info was retrieved
|
||||||
|
* successfully, the first argument passed will be an instance of PluginInfo. Otherwise,
|
||||||
|
* it will be NULL. The second argument will be the corresponding return value of
|
||||||
|
* wp_remote_get (see WP docs for details).
|
||||||
|
*
|
||||||
|
* The callback function should return a new or modified instance of PluginInfo or NULL.
|
||||||
|
*
|
||||||
|
* @uses add_filter() This method is a convenience wrapper for add_filter().
|
||||||
|
*
|
||||||
|
* @param callable $callback
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function addResultFilter($callback) {
|
||||||
|
$this->addFilter('request_info_result', $callback, 10, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createDebugBarExtension() {
|
||||||
|
return new DebugBar\PluginExtension($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a package instance that represents this plugin or theme.
|
||||||
|
*
|
||||||
|
* @return InstalledPackage
|
||||||
|
*/
|
||||||
|
protected function createInstalledPackage() {
|
||||||
|
return new Package($this->pluginAbsolutePath, $this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Package
|
||||||
|
*/
|
||||||
|
public function getInstalledPackage() {
|
||||||
|
return $this->package;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
endif;
|
||||||
@@ -1,5 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v4p4_Factory', false) ):
|
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4;
|
||||||
|
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\Plugin;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\Theme;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\Vcs;
|
||||||
|
|
||||||
|
if ( !class_exists(PucFactory::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A factory that builds update checker instances.
|
* A factory that builds update checker instances.
|
||||||
@@ -11,28 +18,57 @@ if ( !class_exists('Puc_v4p4_Factory', false) ):
|
|||||||
* At the moment it can only build instances of the UpdateChecker class. Other classes are
|
* At the moment it can only build instances of the UpdateChecker class. Other classes are
|
||||||
* intended mainly for internal use and refer directly to specific implementations.
|
* intended mainly for internal use and refer directly to specific implementations.
|
||||||
*/
|
*/
|
||||||
class Puc_v4p4_Factory {
|
class PucFactory {
|
||||||
protected static $classVersions = array();
|
protected static $classVersions = array();
|
||||||
protected static $sorted = false;
|
protected static $sorted = false;
|
||||||
|
|
||||||
protected static $myMajorVersion = '';
|
protected static $myMajorVersion = '';
|
||||||
protected static $latestCompatibleVersion = '';
|
protected static $latestCompatibleVersion = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wrapper method for buildUpdateChecker() that reads the metadata URL from the plugin or theme header.
|
||||||
|
*
|
||||||
|
* @param string $fullPath Full path to the main plugin file or the theme's style.css.
|
||||||
|
* @param array $args Optional arguments. Keys should match the argument names of the buildUpdateChecker() method.
|
||||||
|
* @return Plugin\UpdateChecker|Theme\UpdateChecker|Vcs\BaseChecker
|
||||||
|
*/
|
||||||
|
public static function buildFromHeader($fullPath, $args = array()) {
|
||||||
|
$fullPath = self::normalizePath($fullPath);
|
||||||
|
|
||||||
|
//Set up defaults.
|
||||||
|
$defaults = array(
|
||||||
|
'metadataUrl' => '',
|
||||||
|
'slug' => '',
|
||||||
|
'checkPeriod' => 12,
|
||||||
|
'optionName' => '',
|
||||||
|
'muPluginFile' => '',
|
||||||
|
);
|
||||||
|
$args = array_merge($defaults, array_intersect_key($args, $defaults));
|
||||||
|
extract($args, EXTR_SKIP);
|
||||||
|
|
||||||
|
//Check for the service URI
|
||||||
|
if ( empty($metadataUrl) ) {
|
||||||
|
$metadataUrl = self::getServiceURI($fullPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::buildUpdateChecker($metadataUrl, $fullPath, $slug, $checkPeriod, $optionName, $muPluginFile);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance of the update checker.
|
* Create a new instance of the update checker.
|
||||||
*
|
*
|
||||||
* This method automatically detects if you're using it for a plugin or a theme and chooses
|
* This method automatically detects if you're using it for a plugin or a theme and chooses
|
||||||
* the appropriate implementation for your update source (JSON file, GitHub, BitBucket, etc).
|
* the appropriate implementation for your update source (JSON file, GitHub, BitBucket, etc).
|
||||||
*
|
*
|
||||||
* @see Puc_v4p4_UpdateChecker::__construct
|
* @see UpdateChecker::__construct
|
||||||
*
|
*
|
||||||
* @param string $metadataUrl The URL of the metadata file, a GitHub repository, or another supported update source.
|
* @param string $metadataUrl The URL of the metadata file, a GitHub repository, or another supported update source.
|
||||||
* @param string $fullPath Full path to the main plugin file or to the theme directory.
|
* @param string $fullPath Full path to the main plugin file or to the theme directory.
|
||||||
* @param string $slug Custom slug. Defaults to the name of the main plugin file or the theme directory.
|
* @param string $slug Custom slug. Defaults to the name of the main plugin file or the theme directory.
|
||||||
* @param int $checkPeriod How often to check for updates (in hours).
|
* @param int $checkPeriod How often to check for updates (in hours).
|
||||||
* @param string $optionName Where to store book-keeping info about update checks.
|
* @param string $optionName Where to store bookkeeping info about update checks.
|
||||||
* @param string $muPluginFile The plugin filename relative to the mu-plugins directory.
|
* @param string $muPluginFile The plugin filename relative to the mu-plugins directory.
|
||||||
* @return Puc_v4p4_Plugin_UpdateChecker|Puc_v4p4_Theme_UpdateChecker|Puc_v4p4_Vcs_BaseChecker
|
* @return Plugin\UpdateChecker|Theme\UpdateChecker|Vcs\BaseChecker
|
||||||
*/
|
*/
|
||||||
public static function buildUpdateChecker($metadataUrl, $fullPath, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
|
public static function buildUpdateChecker($metadataUrl, $fullPath, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
|
||||||
$fullPath = self::normalizePath($fullPath);
|
$fullPath = self::normalizePath($fullPath);
|
||||||
@@ -47,7 +83,7 @@ if ( !class_exists('Puc_v4p4_Factory', false) ):
|
|||||||
$type = 'Theme';
|
$type = 'Theme';
|
||||||
$id = $themeDirectory;
|
$id = $themeDirectory;
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException(sprintf(
|
throw new \RuntimeException(sprintf(
|
||||||
'The update checker cannot determine if "%s" is a plugin or a theme. ' .
|
'The update checker cannot determine if "%s" is a plugin or a theme. ' .
|
||||||
'This is a bug. Please contact the PUC developer.',
|
'This is a bug. Please contact the PUC developer.',
|
||||||
htmlentities($fullPath)
|
htmlentities($fullPath)
|
||||||
@@ -60,25 +96,25 @@ if ( !class_exists('Puc_v4p4_Factory', false) ):
|
|||||||
$apiClass = null;
|
$apiClass = null;
|
||||||
if ( empty($service) ) {
|
if ( empty($service) ) {
|
||||||
//The default is to get update information from a remote JSON file.
|
//The default is to get update information from a remote JSON file.
|
||||||
$checkerClass = $type . '_UpdateChecker';
|
$checkerClass = $type . '\\UpdateChecker';
|
||||||
} else {
|
} else {
|
||||||
//You can also use a VCS repository like GitHub.
|
//You can also use a VCS repository like GitHub.
|
||||||
$checkerClass = 'Vcs_' . $type . 'UpdateChecker';
|
$checkerClass = 'Vcs\\' . $type . 'UpdateChecker';
|
||||||
$apiClass = $service . 'Api';
|
$apiClass = $service . 'Api';
|
||||||
}
|
}
|
||||||
|
|
||||||
$checkerClass = self::getCompatibleClassVersion($checkerClass);
|
$checkerClass = self::getCompatibleClassVersion($checkerClass);
|
||||||
if ( $checkerClass === null ) {
|
if ( $checkerClass === null ) {
|
||||||
|
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
|
||||||
trigger_error(
|
trigger_error(
|
||||||
sprintf(
|
esc_html(sprintf(
|
||||||
'PUC %s does not support updates for %ss %s',
|
'PUC %s does not support updates for %ss %s',
|
||||||
htmlentities(self::$latestCompatibleVersion),
|
self::$latestCompatibleVersion,
|
||||||
strtolower($type),
|
strtolower($type),
|
||||||
$service ? ('hosted on ' . htmlentities($service)) : 'using JSON metadata'
|
$service ? ('hosted on ' . $service) : 'using JSON metadata'
|
||||||
),
|
)),
|
||||||
E_USER_ERROR
|
E_USER_ERROR
|
||||||
);
|
);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !isset($apiClass) ) {
|
if ( !isset($apiClass) ) {
|
||||||
@@ -88,12 +124,12 @@ if ( !class_exists('Puc_v4p4_Factory', false) ):
|
|||||||
//VCS checker + an API client.
|
//VCS checker + an API client.
|
||||||
$apiClass = self::getCompatibleClassVersion($apiClass);
|
$apiClass = self::getCompatibleClassVersion($apiClass);
|
||||||
if ( $apiClass === null ) {
|
if ( $apiClass === null ) {
|
||||||
trigger_error(sprintf(
|
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
|
||||||
|
trigger_error(esc_html(sprintf(
|
||||||
'PUC %s does not support %s',
|
'PUC %s does not support %s',
|
||||||
htmlentities(self::$latestCompatibleVersion),
|
self::$latestCompatibleVersion,
|
||||||
htmlentities($service)
|
$service
|
||||||
), E_USER_ERROR);
|
)), E_USER_ERROR);
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new $checkerClass(
|
return new $checkerClass(
|
||||||
@@ -111,7 +147,7 @@ if ( !class_exists('Puc_v4p4_Factory', false) ):
|
|||||||
*
|
*
|
||||||
* Normalize a filesystem path. Introduced in WP 3.9.
|
* Normalize a filesystem path. Introduced in WP 3.9.
|
||||||
* Copying here allows use of the class on earlier versions.
|
* Copying here allows use of the class on earlier versions.
|
||||||
* This version adapted from WP 4.8.2 (unchanged since 4.5.0)
|
* This version adapted from WP 4.8.2 (unchanged since 4.5.4)
|
||||||
*
|
*
|
||||||
* @param string $path Path to normalize.
|
* @param string $path Path to normalize.
|
||||||
* @return string Normalized path.
|
* @return string Normalized path.
|
||||||
@@ -178,6 +214,35 @@ if ( !class_exists('Puc_v4p4_Factory', false) ):
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the service URI from the file header.
|
||||||
|
*
|
||||||
|
* @param string $fullPath
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private static function getServiceURI($fullPath) {
|
||||||
|
//Look for the URI
|
||||||
|
if ( is_readable($fullPath) ) {
|
||||||
|
$seek = array(
|
||||||
|
'github' => 'GitHub URI',
|
||||||
|
'gitlab' => 'GitLab URI',
|
||||||
|
'bucket' => 'BitBucket URI',
|
||||||
|
);
|
||||||
|
$seek = apply_filters('puc_get_source_uri', $seek);
|
||||||
|
$data = get_file_data($fullPath, $seek);
|
||||||
|
foreach ($data as $key => $uri) {
|
||||||
|
if ( $uri ) {
|
||||||
|
return $uri;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//URI was not found so throw an error.
|
||||||
|
throw new \RuntimeException(
|
||||||
|
sprintf('Unable to locate URI in header of "%s"', htmlentities($fullPath))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the name of the hosting service that the URL points to.
|
* Get the name of the hosting service that the URL points to.
|
||||||
*
|
*
|
||||||
@@ -188,11 +253,16 @@ if ( !class_exists('Puc_v4p4_Factory', false) ):
|
|||||||
$service = null;
|
$service = null;
|
||||||
|
|
||||||
//Which hosting service does the URL point to?
|
//Which hosting service does the URL point to?
|
||||||
$host = @parse_url($metadataUrl, PHP_URL_HOST);
|
$host = (string)(wp_parse_url($metadataUrl, PHP_URL_HOST));
|
||||||
$path = @parse_url($metadataUrl, PHP_URL_PATH);
|
$path = (string)(wp_parse_url($metadataUrl, PHP_URL_PATH));
|
||||||
|
|
||||||
//Check if the path looks like "/user-name/repository".
|
//Check if the path looks like "/user-name/repository".
|
||||||
$usernameRepoRegex = '@^/?([^/]+?)/([^/#?&]+?)/?$@';
|
//For GitLab.com it can also be "/user/group1/group2/.../repository".
|
||||||
if ( preg_match($usernameRepoRegex, $path) ) {
|
$repoRegex = '@^/?([^/]+?)/([^/#?&]+?)/?$@';
|
||||||
|
if ( $host === 'gitlab.com' ) {
|
||||||
|
$repoRegex = '@^/?(?:[^/#?&]++/){1,20}(?:[^/#?&]++)/?$@';
|
||||||
|
}
|
||||||
|
if ( preg_match($repoRegex, $path) ) {
|
||||||
$knownServices = array(
|
$knownServices = array(
|
||||||
'github.com' => 'GitHub',
|
'github.com' => 'GitHub',
|
||||||
'bitbucket.org' => 'BitBucket',
|
'bitbucket.org' => 'BitBucket',
|
||||||
@@ -203,7 +273,7 @@ if ( !class_exists('Puc_v4p4_Factory', false) ):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $service;
|
return apply_filters('puc_get_vcs_service', $service, $host, $path, $metadataUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -264,8 +334,8 @@ if ( !class_exists('Puc_v4p4_Factory', false) ):
|
|||||||
*/
|
*/
|
||||||
public static function addVersion($generalClass, $versionedClass, $version) {
|
public static function addVersion($generalClass, $versionedClass, $version) {
|
||||||
if ( empty(self::$myMajorVersion) ) {
|
if ( empty(self::$myMajorVersion) ) {
|
||||||
$nameParts = explode('_', __CLASS__, 3);
|
$lastNamespaceSegment = substr(__NAMESPACE__, strrpos(__NAMESPACE__, '\\') + 1);
|
||||||
self::$myMajorVersion = substr(ltrim($nameParts[1], 'v'), 0, 1);
|
self::$myMajorVersion = substr(ltrim($lastNamespaceSegment, 'v'), 0, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Store the greatest version number that matches our major version.
|
//Store the greatest version number that matches our major version.
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v4p4_Scheduler', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p4;
|
||||||
|
|
||||||
|
if ( !class_exists(Scheduler::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The scheduler decides when and how often to check for updates.
|
* The scheduler decides when and how often to check for updates.
|
||||||
* It calls @see Puc_v4p4_UpdateChecker::checkForUpdates() to perform the actual checks.
|
* It calls @see UpdateChecker::checkForUpdates() to perform the actual checks.
|
||||||
*/
|
*/
|
||||||
class Puc_v4p4_Scheduler {
|
class Scheduler {
|
||||||
public $checkPeriod = 12; //How often to check for updates (in hours).
|
public $checkPeriod = 12; //How often to check for updates (in hours).
|
||||||
public $throttleRedundantChecks = false; //Check less often if we already know that an update is available.
|
public $throttleRedundantChecks = false; //Check less often if we already know that an update is available.
|
||||||
public $throttledCheckPeriod = 72;
|
public $throttledCheckPeriod = 72;
|
||||||
@@ -13,7 +15,7 @@ if ( !class_exists('Puc_v4p4_Scheduler', false) ):
|
|||||||
protected $hourlyCheckHooks = array('load-update.php');
|
protected $hourlyCheckHooks = array('load-update.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Puc_v4p4_UpdateChecker
|
* @var UpdateChecker
|
||||||
*/
|
*/
|
||||||
protected $updateChecker;
|
protected $updateChecker;
|
||||||
|
|
||||||
@@ -22,7 +24,7 @@ if ( !class_exists('Puc_v4p4_Scheduler', false) ):
|
|||||||
/**
|
/**
|
||||||
* Scheduler constructor.
|
* Scheduler constructor.
|
||||||
*
|
*
|
||||||
* @param Puc_v4p4_UpdateChecker $updateChecker
|
* @param UpdateChecker $updateChecker
|
||||||
* @param int $checkPeriod How often to check for updates (in hours).
|
* @param int $checkPeriod How often to check for updates (in hours).
|
||||||
* @param array $hourlyHooks
|
* @param array $hourlyHooks
|
||||||
*/
|
*/
|
||||||
@@ -47,11 +49,27 @@ if ( !class_exists('Puc_v4p4_Scheduler', false) ):
|
|||||||
} else {
|
} else {
|
||||||
//Use a custom cron schedule.
|
//Use a custom cron schedule.
|
||||||
$scheduleName = 'every' . $this->checkPeriod . 'hours';
|
$scheduleName = 'every' . $this->checkPeriod . 'hours';
|
||||||
|
//phpcs:ignore WordPress.WP.CronInterval.ChangeDetected -- WPCS fails to parse the callback.
|
||||||
add_filter('cron_schedules', array($this, '_addCustomSchedule'));
|
add_filter('cron_schedules', array($this, '_addCustomSchedule'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !wp_next_scheduled($this->cronHook) && !defined('WP_INSTALLING') ) {
|
if ( !wp_next_scheduled($this->cronHook) && !defined('WP_INSTALLING') ) {
|
||||||
wp_schedule_event(time(), $scheduleName, $this->cronHook);
|
//Randomly offset the schedule to help prevent update server traffic spikes. Without this
|
||||||
|
//most checks may happen during times of day when people are most likely to install new plugins.
|
||||||
|
$upperLimit = max($this->checkPeriod * 3600 - 15 * 60, 1);
|
||||||
|
if ( function_exists('wp_rand') ) {
|
||||||
|
$randomOffset = wp_rand(0, $upperLimit);
|
||||||
|
} else {
|
||||||
|
//This constructor may be called before wp_rand() is available.
|
||||||
|
//phpcs:ignore WordPress.WP.AlternativeFunctions.rand_rand
|
||||||
|
$randomOffset = rand(0, $upperLimit);
|
||||||
|
}
|
||||||
|
$firstCheckTime = time() - $randomOffset;
|
||||||
|
$firstCheckTime = apply_filters(
|
||||||
|
$this->updateChecker->getUniqueName('first_check_time'),
|
||||||
|
$firstCheckTime
|
||||||
|
);
|
||||||
|
wp_schedule_event($firstCheckTime, $scheduleName, $this->cronHook);
|
||||||
}
|
}
|
||||||
add_action($this->cronHook, array($this, 'maybeCheckForUpdates'));
|
add_action($this->cronHook, array($this, 'maybeCheckForUpdates'));
|
||||||
|
|
||||||
@@ -62,13 +80,15 @@ if ( !class_exists('Puc_v4p4_Scheduler', false) ):
|
|||||||
//Like WordPress itself, we check more often on certain pages.
|
//Like WordPress itself, we check more often on certain pages.
|
||||||
/** @see wp_update_plugins */
|
/** @see wp_update_plugins */
|
||||||
add_action('load-update-core.php', array($this, 'maybeCheckForUpdates'));
|
add_action('load-update-core.php', array($this, 'maybeCheckForUpdates'));
|
||||||
|
//phpcs:ignore Squiz.PHP.CommentedOutCode.Found -- Not actually code, just file names.
|
||||||
//"load-update.php" and "load-plugins.php" or "load-themes.php".
|
//"load-update.php" and "load-plugins.php" or "load-themes.php".
|
||||||
$this->hourlyCheckHooks = array_merge($this->hourlyCheckHooks, $hourlyHooks);
|
$this->hourlyCheckHooks = array_merge($this->hourlyCheckHooks, $hourlyHooks);
|
||||||
foreach($this->hourlyCheckHooks as $hook) {
|
foreach($this->hourlyCheckHooks as $hook) {
|
||||||
add_action($hook, array($this, 'maybeCheckForUpdates'));
|
add_action($hook, array($this, 'maybeCheckForUpdates'));
|
||||||
}
|
}
|
||||||
//This hook fires after a bulk update is complete.
|
//This hook fires after a bulk update is complete.
|
||||||
add_action('upgrader_process_complete', array($this, 'maybeCheckForUpdates'), 11, 0);
|
add_action('upgrader_process_complete', array($this, 'removeHooksIfLibraryGone'), 1, 0);
|
||||||
|
add_action('upgrader_process_complete', array($this, 'upgraderProcessComplete'), 11, 2);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//Periodic checks are disabled.
|
//Periodic checks are disabled.
|
||||||
@@ -76,6 +96,76 @@ if ( !class_exists('Puc_v4p4_Scheduler', false) ):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove all hooks if this version of PUC has been deleted or overwritten.
|
||||||
|
*
|
||||||
|
* Callback for the "upgrader_process_complete" action.
|
||||||
|
*/
|
||||||
|
public function removeHooksIfLibraryGone() {
|
||||||
|
//Cancel all further actions if the current version of PUC has been deleted or overwritten
|
||||||
|
//by a different version during the upgrade. If we try to do anything more in that situation,
|
||||||
|
//we could trigger a fatal error by trying to autoload a deleted class.
|
||||||
|
clearstatcache();
|
||||||
|
if ( !file_exists(__FILE__) ) {
|
||||||
|
$this->removeHooks();
|
||||||
|
$this->updateChecker->removeHooks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs upon the WP action upgrader_process_complete.
|
||||||
|
*
|
||||||
|
* We look at the parameters to decide whether to call maybeCheckForUpdates() or not.
|
||||||
|
* We also check if the update checker has been removed by the update.
|
||||||
|
*
|
||||||
|
* @param \WP_Upgrader $upgrader WP_Upgrader instance
|
||||||
|
* @param array $upgradeInfo extra information about the upgrade
|
||||||
|
*/
|
||||||
|
public function upgraderProcessComplete(
|
||||||
|
/** @noinspection PhpUnusedParameterInspection */
|
||||||
|
$upgrader, $upgradeInfo
|
||||||
|
) {
|
||||||
|
//Sanity check and limitation to relevant types.
|
||||||
|
if (
|
||||||
|
!is_array($upgradeInfo) || !isset($upgradeInfo['type'], $upgradeInfo['action'])
|
||||||
|
|| 'update' !== $upgradeInfo['action'] || !in_array($upgradeInfo['type'], array('plugin', 'theme'))
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Filter out notifications of upgrades that should have no bearing upon whether or not our
|
||||||
|
//current info is up-to-date.
|
||||||
|
if ( is_a($this->updateChecker, Theme\UpdateChecker::class) ) {
|
||||||
|
if ( 'theme' !== $upgradeInfo['type'] || !isset($upgradeInfo['themes']) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Letting too many things going through for checks is not a real problem, so we compare widely.
|
||||||
|
if ( !in_array(
|
||||||
|
strtolower($this->updateChecker->directoryName),
|
||||||
|
array_map('strtolower', $upgradeInfo['themes'])
|
||||||
|
) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( is_a($this->updateChecker, Plugin\UpdateChecker::class) ) {
|
||||||
|
if ( 'plugin' !== $upgradeInfo['type'] || !isset($upgradeInfo['plugins']) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Themes pass in directory names in the information array, but plugins use the relative plugin path.
|
||||||
|
if ( !in_array(
|
||||||
|
strtolower($this->updateChecker->directoryName),
|
||||||
|
array_map('dirname', array_map('strtolower', $upgradeInfo['plugins']))
|
||||||
|
) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->maybeCheckForUpdates();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for updates if the configured check interval has already elapsed.
|
* Check for updates if the configured check interval has already elapsed.
|
||||||
* Will use a shorter check interval on certain admin pages like "Dashboard -> Updates" or when doing cron.
|
* Will use a shorter check interval on certain admin pages like "Dashboard -> Updates" or when doing cron.
|
||||||
@@ -89,7 +179,7 @@ if ( !class_exists('Puc_v4p4_Scheduler', false) ):
|
|||||||
*
|
*
|
||||||
* This method is declared public because it's a hook callback. Calling it directly is not recommended.
|
* This method is declared public because it's a hook callback. Calling it directly is not recommended.
|
||||||
*/
|
*/
|
||||||
public function maybeCheckForUpdates(){
|
public function maybeCheckForUpdates() {
|
||||||
if ( empty($this->checkPeriod) ){
|
if ( empty($this->checkPeriod) ){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -97,6 +187,21 @@ if ( !class_exists('Puc_v4p4_Scheduler', false) ):
|
|||||||
$state = $this->updateChecker->getUpdateState();
|
$state = $this->updateChecker->getUpdateState();
|
||||||
$shouldCheck = ($state->timeSinceLastCheck() >= $this->getEffectiveCheckPeriod());
|
$shouldCheck = ($state->timeSinceLastCheck() >= $this->getEffectiveCheckPeriod());
|
||||||
|
|
||||||
|
if ( $shouldCheck ) {
|
||||||
|
//Sanity check: Do not proceed if one of the critical classes is missing.
|
||||||
|
//That can happen - theoretically and extremely rarely - if maybeCheckForUpdates()
|
||||||
|
//is called before the old version of our plugin has been fully deleted, or
|
||||||
|
//called from an independent AJAX request during deletion.
|
||||||
|
if ( !(
|
||||||
|
class_exists(Utils::class)
|
||||||
|
&& class_exists(Metadata::class)
|
||||||
|
&& class_exists(Plugin\Update::class)
|
||||||
|
&& class_exists(Theme\Update::class)
|
||||||
|
) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Let plugin authors substitute their own algorithm.
|
//Let plugin authors substitute their own algorithm.
|
||||||
$shouldCheck = apply_filters(
|
$shouldCheck = apply_filters(
|
||||||
$this->updateChecker->getUniqueName('check_now'),
|
$this->updateChecker->getUniqueName('check_now'),
|
||||||
@@ -127,7 +232,7 @@ if ( !class_exists('Puc_v4p4_Scheduler', false) ):
|
|||||||
//Check less frequently if it's already known that an update is available.
|
//Check less frequently if it's already known that an update is available.
|
||||||
$period = $this->throttledCheckPeriod * 3600;
|
$period = $this->throttledCheckPeriod * 3600;
|
||||||
} else if ( defined('DOING_CRON') && constant('DOING_CRON') ) {
|
} else if ( defined('DOING_CRON') && constant('DOING_CRON') ) {
|
||||||
//WordPress cron schedules are not exact, so lets do an update check even
|
//WordPress cron schedules are not exact, so let's do an update check even
|
||||||
//if slightly less than $checkPeriod hours have elapsed since the last check.
|
//if slightly less than $checkPeriod hours have elapsed since the last check.
|
||||||
$cronFuzziness = 20 * 60;
|
$cronFuzziness = 20 * 60;
|
||||||
$period = $this->checkPeriod * 3600 - $cronFuzziness;
|
$period = $this->checkPeriod * 3600 - $cronFuzziness;
|
||||||
@@ -144,7 +249,7 @@ if ( !class_exists('Puc_v4p4_Scheduler', false) ):
|
|||||||
* @param array $schedules
|
* @param array $schedules
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function _addCustomSchedule($schedules){
|
public function _addCustomSchedule($schedules) {
|
||||||
if ( $this->checkPeriod && ($this->checkPeriod > 0) ){
|
if ( $this->checkPeriod && ($this->checkPeriod > 0) ){
|
||||||
$scheduleName = 'every' . $this->checkPeriod . 'hours';
|
$scheduleName = 'every' . $this->checkPeriod . 'hours';
|
||||||
$schedules[$scheduleName] = array(
|
$schedules[$scheduleName] = array(
|
||||||
@@ -160,7 +265,7 @@ if ( !class_exists('Puc_v4p4_Scheduler', false) ):
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function removeUpdaterCron(){
|
public function removeUpdaterCron() {
|
||||||
wp_clear_scheduled_hook($this->cronHook);
|
wp_clear_scheduled_hook($this->cronHook);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,6 +277,24 @@ if ( !class_exists('Puc_v4p4_Scheduler', false) ):
|
|||||||
public function getCronHookName() {
|
public function getCronHookName() {
|
||||||
return $this->cronHook;
|
return $this->cronHook;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove most hooks added by the scheduler.
|
||||||
|
*/
|
||||||
|
public function removeHooks() {
|
||||||
|
remove_filter('cron_schedules', array($this, '_addCustomSchedule'));
|
||||||
|
remove_action('admin_init', array($this, 'maybeCheckForUpdates'));
|
||||||
|
remove_action('load-update-core.php', array($this, 'maybeCheckForUpdates'));
|
||||||
|
|
||||||
|
if ( $this->cronHook !== null ) {
|
||||||
|
remove_action($this->cronHook, array($this, 'maybeCheckForUpdates'));
|
||||||
|
}
|
||||||
|
if ( !empty($this->hourlyCheckHooks) ) {
|
||||||
|
foreach ($this->hourlyCheckHooks as $hook) {
|
||||||
|
remove_action($hook, array($this, 'maybeCheckForUpdates'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
endif;
|
endif;
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4;
|
||||||
|
|
||||||
if ( !class_exists('Puc_v4p4_StateStore', false) ):
|
if ( !class_exists(StateStore::class, false) ):
|
||||||
|
|
||||||
class Puc_v4p4_StateStore {
|
class StateStore {
|
||||||
/**
|
/**
|
||||||
* @var int Last update check timestamp.
|
* @var int Last update check timestamp.
|
||||||
*/
|
*/
|
||||||
@@ -14,7 +15,7 @@ if ( !class_exists('Puc_v4p4_StateStore', false) ):
|
|||||||
protected $checkedVersion = '';
|
protected $checkedVersion = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Puc_v4p4_Update|null Cached update.
|
* @var Update|null Cached update.
|
||||||
*/
|
*/
|
||||||
protected $update = null;
|
protected $update = null;
|
||||||
|
|
||||||
@@ -65,7 +66,7 @@ if ( !class_exists('Puc_v4p4_StateStore', false) ):
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return null|Puc_v4p4_Update
|
* @return null|Update
|
||||||
*/
|
*/
|
||||||
public function getUpdate() {
|
public function getUpdate() {
|
||||||
$this->lazyLoad();
|
$this->lazyLoad();
|
||||||
@@ -73,10 +74,10 @@ if ( !class_exists('Puc_v4p4_StateStore', false) ):
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Puc_v4p4_Update|null $update
|
* @param Update|null $update
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function setUpdate(Puc_v4p4_Update $update = null) {
|
public function setUpdate(Update $update = null) {
|
||||||
$this->lazyLoad();
|
$this->lazyLoad();
|
||||||
$this->update = $update;
|
$this->update = $update;
|
||||||
return $this;
|
return $this;
|
||||||
@@ -127,7 +128,7 @@ if ( !class_exists('Puc_v4p4_StateStore', false) ):
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function save() {
|
public function save() {
|
||||||
$state = new stdClass();
|
$state = new \stdClass();
|
||||||
|
|
||||||
$state->lastCheck = $this->lastCheck;
|
$state->lastCheck = $this->lastCheck;
|
||||||
$state->checkedVersion = $this->checkedVersion;
|
$state->checkedVersion = $this->checkedVersion;
|
||||||
@@ -138,7 +139,7 @@ if ( !class_exists('Puc_v4p4_StateStore', false) ):
|
|||||||
$updateClass = get_class($this->update);
|
$updateClass = get_class($this->update);
|
||||||
$state->updateClass = $updateClass;
|
$state->updateClass = $updateClass;
|
||||||
$prefix = $this->getLibPrefix();
|
$prefix = $this->getLibPrefix();
|
||||||
if ( Puc_v4p4_Utils::startsWith($updateClass, $prefix) ) {
|
if ( Utils::startsWith($updateClass, $prefix) ) {
|
||||||
$state->updateBaseClass = substr($updateClass, strlen($prefix));
|
$state->updateBaseClass = substr($updateClass, strlen($prefix));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,15 +163,20 @@ if ( !class_exists('Puc_v4p4_StateStore', false) ):
|
|||||||
|
|
||||||
$state = get_site_option($this->optionName, null);
|
$state = get_site_option($this->optionName, null);
|
||||||
|
|
||||||
if ( !is_object($state) ) {
|
if (
|
||||||
|
!is_object($state)
|
||||||
|
//Sanity check: If the Utils class is missing, the plugin is probably in the process
|
||||||
|
//of being deleted (e.g. the old version gets deleted during an update).
|
||||||
|
|| !class_exists(Utils::class)
|
||||||
|
) {
|
||||||
$this->lastCheck = 0;
|
$this->lastCheck = 0;
|
||||||
$this->checkedVersion = '';
|
$this->checkedVersion = '';
|
||||||
$this->update = null;
|
$this->update = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->lastCheck = intval(Puc_v4p4_Utils::get($state, 'lastCheck', 0));
|
$this->lastCheck = intval(Utils::get($state, 'lastCheck', 0));
|
||||||
$this->checkedVersion = Puc_v4p4_Utils::get($state, 'checkedVersion', '');
|
$this->checkedVersion = Utils::get($state, 'checkedVersion', '');
|
||||||
$this->update = null;
|
$this->update = null;
|
||||||
|
|
||||||
if ( isset($state->update) ) {
|
if ( isset($state->update) ) {
|
||||||
@@ -180,12 +186,13 @@ if ( !class_exists('Puc_v4p4_StateStore', false) ):
|
|||||||
$updateClass = null;
|
$updateClass = null;
|
||||||
if ( isset($state->updateBaseClass) ) {
|
if ( isset($state->updateBaseClass) ) {
|
||||||
$updateClass = $this->getLibPrefix() . $state->updateBaseClass;
|
$updateClass = $this->getLibPrefix() . $state->updateBaseClass;
|
||||||
} else if ( isset($state->updateClass) && class_exists($state->updateClass) ) {
|
} else if ( isset($state->updateClass) ) {
|
||||||
$updateClass = $state->updateClass;
|
$updateClass = $state->updateClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $updateClass !== null ) {
|
$factory = array($updateClass, 'fromObject');
|
||||||
$this->update = call_user_func(array($updateClass, 'fromObject'), $state->update);
|
if ( ($updateClass !== null) && is_callable($factory) ) {
|
||||||
|
$this->update = call_user_func($factory, $state->update);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -199,8 +206,8 @@ if ( !class_exists('Puc_v4p4_StateStore', false) ):
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function getLibPrefix() {
|
private function getLibPrefix() {
|
||||||
$parts = explode('_', __CLASS__, 3);
|
//This assumes that the current class is at the top of the versioned namespace.
|
||||||
return $parts[0] . '_' . $parts[1] . '_';
|
return __NAMESPACE__ . '\\';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
69
plugin-update-checker-5.4/Puc/v5p4/Theme/Package.php
Normal file
69
plugin-update-checker-5.4/Puc/v5p4/Theme/Package.php
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Theme;
|
||||||
|
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\InstalledPackage;
|
||||||
|
|
||||||
|
if ( !class_exists(Package::class, false) ):
|
||||||
|
|
||||||
|
class Package extends InstalledPackage {
|
||||||
|
/**
|
||||||
|
* @var string Theme directory name.
|
||||||
|
*/
|
||||||
|
protected $stylesheet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \WP_Theme Theme object.
|
||||||
|
*/
|
||||||
|
protected $theme;
|
||||||
|
|
||||||
|
public function __construct($stylesheet, $updateChecker) {
|
||||||
|
$this->stylesheet = $stylesheet;
|
||||||
|
$this->theme = wp_get_theme($this->stylesheet);
|
||||||
|
|
||||||
|
parent::__construct($updateChecker);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getInstalledVersion() {
|
||||||
|
return $this->theme->get('Version');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAbsoluteDirectoryPath() {
|
||||||
|
if ( method_exists($this->theme, 'get_stylesheet_directory') ) {
|
||||||
|
return $this->theme->get_stylesheet_directory(); //Available since WP 3.4.
|
||||||
|
}
|
||||||
|
return get_theme_root($this->stylesheet) . '/' . $this->stylesheet;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of a specific plugin or theme header.
|
||||||
|
*
|
||||||
|
* @param string $headerName
|
||||||
|
* @param string $defaultValue
|
||||||
|
* @return string Either the value of the header, or $defaultValue if the header doesn't exist or is empty.
|
||||||
|
*/
|
||||||
|
public function getHeaderValue($headerName, $defaultValue = '') {
|
||||||
|
$value = $this->theme->get($headerName);
|
||||||
|
if ( ($headerName === false) || ($headerName === '') ) {
|
||||||
|
return $defaultValue;
|
||||||
|
}
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getHeaderNames() {
|
||||||
|
return array(
|
||||||
|
'Name' => 'Theme Name',
|
||||||
|
'ThemeURI' => 'Theme URI',
|
||||||
|
'Description' => 'Description',
|
||||||
|
'Author' => 'Author',
|
||||||
|
'AuthorURI' => 'Author URI',
|
||||||
|
'Version' => 'Version',
|
||||||
|
'Template' => 'Template',
|
||||||
|
'Status' => 'Status',
|
||||||
|
'Tags' => 'Tags',
|
||||||
|
'TextDomain' => 'Text Domain',
|
||||||
|
'DomainPath' => 'Domain Path',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
endif;
|
||||||
@@ -1,8 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( !class_exists('Puc_v4p4_Theme_Update', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Theme;
|
||||||
|
|
||||||
class Puc_v4p4_Theme_Update extends Puc_v4p4_Update {
|
use YahnisElsts\PluginUpdateChecker\v5p4\Update as BaseUpdate;
|
||||||
|
|
||||||
|
if ( !class_exists(Update::class, false) ):
|
||||||
|
|
||||||
|
class Update extends BaseUpdate {
|
||||||
public $details_url = '';
|
public $details_url = '';
|
||||||
|
|
||||||
protected static $extraFields = array('details_url');
|
protected static $extraFields = array('details_url');
|
||||||
@@ -44,8 +48,8 @@ if ( !class_exists('Puc_v4p4_Theme_Update', false) ):
|
|||||||
/**
|
/**
|
||||||
* Create a new instance by copying the necessary fields from another object.
|
* Create a new instance by copying the necessary fields from another object.
|
||||||
*
|
*
|
||||||
* @param StdClass|Puc_v4p4_Theme_Update $object The source object.
|
* @param \StdClass|self $object The source object.
|
||||||
* @return Puc_v4p4_Theme_Update The new copy.
|
* @return self The new copy.
|
||||||
*/
|
*/
|
||||||
public static function fromObject($object) {
|
public static function fromObject($object) {
|
||||||
$update = new self();
|
$update = new self();
|
||||||
@@ -56,14 +60,14 @@ if ( !class_exists('Puc_v4p4_Theme_Update', false) ):
|
|||||||
/**
|
/**
|
||||||
* Basic validation.
|
* Basic validation.
|
||||||
*
|
*
|
||||||
* @param StdClass $apiResponse
|
* @param \StdClass $apiResponse
|
||||||
* @return bool|WP_Error
|
* @return bool|\WP_Error
|
||||||
*/
|
*/
|
||||||
protected function validateMetadata($apiResponse) {
|
protected function validateMetadata($apiResponse) {
|
||||||
$required = array('version', 'details_url');
|
$required = array('version', 'details_url');
|
||||||
foreach($required as $key) {
|
foreach($required as $key) {
|
||||||
if ( !isset($apiResponse->$key) || empty($apiResponse->$key) ) {
|
if ( !isset($apiResponse->$key) || empty($apiResponse->$key) ) {
|
||||||
return new WP_Error(
|
return new \WP_Error(
|
||||||
'tuc-invalid-metadata',
|
'tuc-invalid-metadata',
|
||||||
sprintf('The theme metadata is missing the required "%s" key.', $key)
|
sprintf('The theme metadata is missing the required "%s" key.', $key)
|
||||||
);
|
);
|
||||||
@@ -1,28 +1,29 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( !class_exists('Puc_v4p4_Theme_UpdateChecker', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Theme;
|
||||||
|
|
||||||
class Puc_v4p4_Theme_UpdateChecker extends Puc_v4p4_UpdateChecker {
|
use YahnisElsts\PluginUpdateChecker\v5p4\UpdateChecker as BaseUpdateChecker;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\InstalledPackage;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\Scheduler;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\DebugBar;
|
||||||
|
|
||||||
|
if ( !class_exists(UpdateChecker::class, false) ):
|
||||||
|
|
||||||
|
class UpdateChecker extends BaseUpdateChecker {
|
||||||
protected $filterSuffix = 'theme';
|
protected $filterSuffix = 'theme';
|
||||||
protected $updateTransient = 'update_themes';
|
protected $updateTransient = 'update_themes';
|
||||||
protected $translationType = 'theme';
|
protected $componentType = 'theme';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string Theme directory name.
|
* @var string Theme directory name.
|
||||||
*/
|
*/
|
||||||
protected $stylesheet;
|
protected $stylesheet;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var WP_Theme Theme object.
|
|
||||||
*/
|
|
||||||
protected $theme;
|
|
||||||
|
|
||||||
public function __construct($metadataUrl, $stylesheet = null, $customSlug = null, $checkPeriod = 12, $optionName = '') {
|
public function __construct($metadataUrl, $stylesheet = null, $customSlug = null, $checkPeriod = 12, $optionName = '') {
|
||||||
if ( $stylesheet === null ) {
|
if ( $stylesheet === null ) {
|
||||||
$stylesheet = get_stylesheet();
|
$stylesheet = get_stylesheet();
|
||||||
}
|
}
|
||||||
$this->stylesheet = $stylesheet;
|
$this->stylesheet = $stylesheet;
|
||||||
$this->theme = wp_get_theme($this->stylesheet);
|
|
||||||
|
|
||||||
parent::__construct(
|
parent::__construct(
|
||||||
$metadataUrl,
|
$metadataUrl,
|
||||||
@@ -45,13 +46,13 @@ if ( !class_exists('Puc_v4p4_Theme_UpdateChecker', false) ):
|
|||||||
/**
|
/**
|
||||||
* Retrieve the latest update (if any) from the configured API endpoint.
|
* Retrieve the latest update (if any) from the configured API endpoint.
|
||||||
*
|
*
|
||||||
* @return Puc_v4p4_Update|null An instance of Update, or NULL when no updates are available.
|
* @return Update|null An instance of Update, or NULL when no updates are available.
|
||||||
*/
|
*/
|
||||||
public function requestUpdate() {
|
public function requestUpdate() {
|
||||||
list($themeUpdate, $result) = $this->requestMetadata('Puc_v4p4_Theme_Update', 'request_update');
|
list($themeUpdate, $result) = $this->requestMetadata(Update::class, 'request_update');
|
||||||
|
|
||||||
if ( $themeUpdate !== null ) {
|
if ( $themeUpdate !== null ) {
|
||||||
/** @var Puc_v4p4_Theme_Update $themeUpdate */
|
/** @var Update $themeUpdate */
|
||||||
$themeUpdate->slug = $this->slug;
|
$themeUpdate->slug = $this->slug;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,43 +60,34 @@ if ( !class_exists('Puc_v4p4_Theme_UpdateChecker', false) ):
|
|||||||
return $themeUpdate;
|
return $themeUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getNoUpdateItemFields() {
|
||||||
|
return array_merge(
|
||||||
|
parent::getNoUpdateItemFields(),
|
||||||
|
array(
|
||||||
|
'theme' => $this->directoryName,
|
||||||
|
'requires' => '',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function userCanInstallUpdates() {
|
public function userCanInstallUpdates() {
|
||||||
return current_user_can('update_themes');
|
return current_user_can('update_themes');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the currently installed version of the plugin or theme.
|
|
||||||
*
|
|
||||||
* @return string Version number.
|
|
||||||
*/
|
|
||||||
public function getInstalledVersion() {
|
|
||||||
return $this->theme->get('Version');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getAbsoluteDirectoryPath() {
|
|
||||||
if ( method_exists($this->theme, 'get_stylesheet_directory') ) {
|
|
||||||
return $this->theme->get_stylesheet_directory(); //Available since WP 3.4.
|
|
||||||
}
|
|
||||||
return get_theme_root($this->stylesheet) . '/' . $this->stylesheet;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an instance of the scheduler.
|
* Create an instance of the scheduler.
|
||||||
*
|
*
|
||||||
* @param int $checkPeriod
|
* @param int $checkPeriod
|
||||||
* @return Puc_v4p4_Scheduler
|
* @return Scheduler
|
||||||
*/
|
*/
|
||||||
protected function createScheduler($checkPeriod) {
|
protected function createScheduler($checkPeriod) {
|
||||||
return new Puc_v4p4_Scheduler($this, $checkPeriod, array('load-themes.php'));
|
return new Scheduler($this, $checkPeriod, array('load-themes.php'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is there an update being installed right now for this theme?
|
* Is there an update being installed right now for this theme?
|
||||||
*
|
*
|
||||||
* @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
* @param \WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isBeingUpgraded($upgrader = null) {
|
public function isBeingUpgraded($upgrader = null) {
|
||||||
@@ -103,7 +95,7 @@ if ( !class_exists('Puc_v4p4_Theme_UpdateChecker', false) ):
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function createDebugBarExtension() {
|
protected function createDebugBarExtension() {
|
||||||
return new Puc_v4p4_DebugBar_Extension($this, 'Puc_v4p4_DebugBar_ThemePanel');
|
return new DebugBar\Extension($this, DebugBar\ThemePanel::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -155,22 +147,12 @@ if ( !class_exists('Puc_v4p4_Theme_UpdateChecker', false) ):
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* Create a package instance that represents this plugin or theme.
|
||||||
|
*
|
||||||
|
* @return InstalledPackage
|
||||||
*/
|
*/
|
||||||
protected function getHeaderNames() {
|
protected function createInstalledPackage() {
|
||||||
return array(
|
return new Package($this->stylesheet, $this);
|
||||||
'Name' => 'Theme Name',
|
|
||||||
'ThemeURI' => 'Theme URI',
|
|
||||||
'Description' => 'Description',
|
|
||||||
'Author' => 'Author',
|
|
||||||
'AuthorURI' => 'Author URI',
|
|
||||||
'Version' => 'Version',
|
|
||||||
'Template' => 'Template',
|
|
||||||
'Status' => 'Status',
|
|
||||||
'Tags' => 'Tags',
|
|
||||||
'TextDomain' => 'Text Domain',
|
|
||||||
'DomainPath' => 'Domain Path',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v4p4_Update', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p4;
|
||||||
|
|
||||||
|
use stdClass;
|
||||||
|
|
||||||
|
if ( !class_exists(Update::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple container class for holding information about an available update.
|
* A simple container class for holding information about an available update.
|
||||||
@@ -7,7 +11,7 @@ if ( !class_exists('Puc_v4p4_Update', false) ):
|
|||||||
* @author Janis Elsts
|
* @author Janis Elsts
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
abstract class Puc_v4p4_Update extends Puc_v4p4_Metadata {
|
abstract class Update extends Metadata {
|
||||||
public $slug;
|
public $slug;
|
||||||
public $version;
|
public $version;
|
||||||
public $download_url;
|
public $download_url;
|
||||||
@@ -1,18 +1,31 @@
|
|||||||
<?php
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4;
|
||||||
|
|
||||||
if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
use stdClass;
|
||||||
|
use WP_Error;
|
||||||
|
|
||||||
abstract class Puc_v4p4_UpdateChecker {
|
if ( !class_exists(UpdateChecker::class, false) ):
|
||||||
|
|
||||||
|
abstract class UpdateChecker {
|
||||||
protected $filterSuffix = '';
|
protected $filterSuffix = '';
|
||||||
protected $updateTransient = '';
|
protected $updateTransient = '';
|
||||||
protected $translationType = ''; //"plugin" or "theme".
|
|
||||||
|
/**
|
||||||
|
* @var string This can be "plugin" or "theme".
|
||||||
|
*/
|
||||||
|
protected $componentType = '';
|
||||||
|
/**
|
||||||
|
* @var string Currently the same as $componentType, but this is an implementation detail that
|
||||||
|
* depends on how WP works internally, and could therefore change.
|
||||||
|
*/
|
||||||
|
protected $translationType = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set to TRUE to enable error reporting. Errors are raised using trigger_error()
|
* Set to TRUE to enable error reporting. Errors are raised using trigger_error()
|
||||||
* and should be logged to the standard PHP error log.
|
* and should be logged to the standard PHP error log.
|
||||||
* @var bool
|
* @var bool
|
||||||
*/
|
*/
|
||||||
public $debugMode = false;
|
public $debugMode = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string Where to store the update info.
|
* @var string Where to store the update info.
|
||||||
@@ -36,17 +49,22 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
public $slug = '';
|
public $slug = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Puc_v4p4_Scheduler
|
* @var InstalledPackage
|
||||||
|
*/
|
||||||
|
protected $package;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Scheduler
|
||||||
*/
|
*/
|
||||||
public $scheduler;
|
public $scheduler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Puc_v4p4_UpgraderStatus
|
* @var UpgraderStatus
|
||||||
*/
|
*/
|
||||||
protected $upgraderStatus;
|
protected $upgraderStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Puc_v4p4_StateStore
|
* @var StateStore
|
||||||
*/
|
*/
|
||||||
protected $updateState;
|
protected $updateState;
|
||||||
|
|
||||||
@@ -55,6 +73,21 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
*/
|
*/
|
||||||
protected $lastRequestApiErrors = array();
|
protected $lastRequestApiErrors = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string|mixed The default is 0 because parse_url() can return NULL or FALSE.
|
||||||
|
*/
|
||||||
|
protected $cachedMetadataHost = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var DebugBar\Extension|null
|
||||||
|
*/
|
||||||
|
protected $debugBarExtension = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var WpCliCheckTrigger|null
|
||||||
|
*/
|
||||||
|
protected $wpCliCheckTrigger = null;
|
||||||
|
|
||||||
public function __construct($metadataUrl, $directoryName, $slug = null, $checkPeriod = 12, $optionName = '') {
|
public function __construct($metadataUrl, $directoryName, $slug = null, $checkPeriod = 12, $optionName = '') {
|
||||||
$this->debugMode = (bool)(constant('WP_DEBUG'));
|
$this->debugMode = (bool)(constant('WP_DEBUG'));
|
||||||
$this->metadataUrl = $metadataUrl;
|
$this->metadataUrl = $metadataUrl;
|
||||||
@@ -72,9 +105,14 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( empty($this->translationType) ) {
|
||||||
|
$this->translationType = $this->componentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->package = $this->createInstalledPackage();
|
||||||
$this->scheduler = $this->createScheduler($checkPeriod);
|
$this->scheduler = $this->createScheduler($checkPeriod);
|
||||||
$this->upgraderStatus = new Puc_v4p4_UpgraderStatus();
|
$this->upgraderStatus = new UpgraderStatus();
|
||||||
$this->updateState = new Puc_v4p4_StateStore($this->optionName);
|
$this->updateState = new StateStore($this->optionName);
|
||||||
|
|
||||||
if ( did_action('init') ) {
|
if ( did_action('init') ) {
|
||||||
$this->loadTextDomain();
|
$this->loadTextDomain();
|
||||||
@@ -83,6 +121,10 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->installHooks();
|
$this->installHooks();
|
||||||
|
|
||||||
|
if ( ($this->wpCliCheckTrigger === null) && defined('WP_CLI') ) {
|
||||||
|
$this->wpCliCheckTrigger = new WpCliCheckTrigger($this->componentType, $this->scheduler);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,7 +182,7 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
/**
|
/**
|
||||||
* Remove hooks that were added by this update checker instance.
|
* Remove hooks that were added by this update checker instance.
|
||||||
*/
|
*/
|
||||||
protected function removeHooks() {
|
public function removeHooks() {
|
||||||
remove_filter('site_transient_' . $this->updateTransient, array($this,'injectUpdate'));
|
remove_filter('site_transient_' . $this->updateTransient, array($this,'injectUpdate'));
|
||||||
remove_filter('site_transient_' . $this->updateTransient, array($this, 'injectTranslationUpdates'));
|
remove_filter('site_transient_' . $this->updateTransient, array($this, 'injectTranslationUpdates'));
|
||||||
remove_action(
|
remove_action(
|
||||||
@@ -153,6 +195,14 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
remove_action('plugins_loaded', array($this, 'maybeInitDebugBar'));
|
remove_action('plugins_loaded', array($this, 'maybeInitDebugBar'));
|
||||||
|
|
||||||
remove_action('init', array($this, 'loadTextDomain'));
|
remove_action('init', array($this, 'loadTextDomain'));
|
||||||
|
|
||||||
|
if ( $this->scheduler ) {
|
||||||
|
$this->scheduler->removeHooks();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $this->debugBarExtension ) {
|
||||||
|
$this->debugBarExtension->removeHooks();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -181,17 +231,30 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function allowMetadataHost($allow, $host) {
|
public function allowMetadataHost($allow, $host) {
|
||||||
static $metadataHost = 0; //Using 0 instead of NULL because parse_url can return NULL.
|
if ( $this->cachedMetadataHost === 0 ) {
|
||||||
if ( $metadataHost === 0 ) {
|
$this->cachedMetadataHost = wp_parse_url($this->metadataUrl, PHP_URL_HOST);
|
||||||
$metadataHost = @parse_url($this->metadataUrl, PHP_URL_HOST);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( is_string($metadataHost) && (strtolower($host) === strtolower($metadataHost)) ) {
|
if ( is_string($this->cachedMetadataHost) && (strtolower($host) === strtolower($this->cachedMetadataHost)) ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return $allow;
|
return $allow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a package instance that represents this plugin or theme.
|
||||||
|
*
|
||||||
|
* @return InstalledPackage
|
||||||
|
*/
|
||||||
|
abstract protected function createInstalledPackage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return InstalledPackage
|
||||||
|
*/
|
||||||
|
public function getInstalledPackage() {
|
||||||
|
return $this->package;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an instance of the scheduler.
|
* Create an instance of the scheduler.
|
||||||
*
|
*
|
||||||
@@ -199,14 +262,14 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
* and substitute their own scheduler.
|
* and substitute their own scheduler.
|
||||||
*
|
*
|
||||||
* @param int $checkPeriod
|
* @param int $checkPeriod
|
||||||
* @return Puc_v4p4_Scheduler
|
* @return Scheduler
|
||||||
*/
|
*/
|
||||||
abstract protected function createScheduler($checkPeriod);
|
abstract protected function createScheduler($checkPeriod);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for updates. The results are stored in the DB option specified in $optionName.
|
* Check for updates. The results are stored in the DB option specified in $optionName.
|
||||||
*
|
*
|
||||||
* @return Puc_v4p4_Update|null
|
* @return Update|null
|
||||||
*/
|
*/
|
||||||
public function checkForUpdates() {
|
public function checkForUpdates() {
|
||||||
$installedVersion = $this->getInstalledVersion();
|
$installedVersion = $this->getInstalledVersion();
|
||||||
@@ -240,7 +303,7 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
/**
|
/**
|
||||||
* Load the update checker state from the DB.
|
* Load the update checker state from the DB.
|
||||||
*
|
*
|
||||||
* @return Puc_v4p4_StateStore
|
* @return StateStore
|
||||||
*/
|
*/
|
||||||
public function getUpdateState() {
|
public function getUpdateState() {
|
||||||
return $this->updateState->lazyLoad();
|
return $this->updateState->lazyLoad();
|
||||||
@@ -265,7 +328,7 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
* Uses cached update data. To retrieve update information straight from
|
* Uses cached update data. To retrieve update information straight from
|
||||||
* the metadata URL, call requestUpdate() instead.
|
* the metadata URL, call requestUpdate() instead.
|
||||||
*
|
*
|
||||||
* @return Puc_v4p4_Update|null
|
* @return Update|null
|
||||||
*/
|
*/
|
||||||
public function getUpdate() {
|
public function getUpdate() {
|
||||||
$update = $this->updateState->getUpdate();
|
$update = $this->updateState->getUpdate();
|
||||||
@@ -286,21 +349,24 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
*
|
*
|
||||||
* Subclasses should run the update through filterUpdateResult before returning it.
|
* Subclasses should run the update through filterUpdateResult before returning it.
|
||||||
*
|
*
|
||||||
* @return Puc_v4p4_Update An instance of Update, or NULL when no updates are available.
|
* @return Update An instance of Update, or NULL when no updates are available.
|
||||||
*/
|
*/
|
||||||
abstract public function requestUpdate();
|
abstract public function requestUpdate();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter the result of a requestUpdate() call.
|
* Filter the result of a requestUpdate() call.
|
||||||
*
|
*
|
||||||
* @param Puc_v4p4_Update|null $update
|
* @template T of Update
|
||||||
|
* @param T|null $update
|
||||||
* @param array|WP_Error|null $httpResult The value returned by wp_remote_get(), if any.
|
* @param array|WP_Error|null $httpResult The value returned by wp_remote_get(), if any.
|
||||||
* @return Puc_v4p4_Update
|
* @return T
|
||||||
*/
|
*/
|
||||||
protected function filterUpdateResult($update, $httpResult = null) {
|
protected function filterUpdateResult($update, $httpResult = null) {
|
||||||
//Let plugins/themes modify the update.
|
//Let plugins/themes modify the update.
|
||||||
$update = apply_filters($this->getUniqueName('request_update_result'), $update, $httpResult);
|
$update = apply_filters($this->getUniqueName('request_update_result'), $update, $httpResult);
|
||||||
|
|
||||||
|
$this->fixSupportedWordpressVersion($update);
|
||||||
|
|
||||||
if ( isset($update, $update->translations) ) {
|
if ( isset($update, $update->translations) ) {
|
||||||
//Keep only those translation updates that apply to this site.
|
//Keep only those translation updates that apply to this site.
|
||||||
$update->translations = $this->filterApplicableTranslations($update->translations);
|
$update->translations = $this->filterApplicableTranslations($update->translations);
|
||||||
@@ -309,19 +375,76 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
return $update;
|
return $update;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The "Tested up to" field in the plugin metadata is supposed to be in the form of "major.minor",
|
||||||
|
* while WordPress core's list_plugin_updates() expects the $update->tested field to be an exact
|
||||||
|
* version, e.g. "major.minor.patch", to say it's compatible. In other case it shows
|
||||||
|
* "Compatibility: Unknown".
|
||||||
|
* The function mimics how wordpress.org API crafts the "tested" field out of "Tested up to".
|
||||||
|
*
|
||||||
|
* @param Metadata|null $update
|
||||||
|
*/
|
||||||
|
protected function fixSupportedWordpressVersion(Metadata $update = null) {
|
||||||
|
if ( !isset($update->tested) || !preg_match('/^\d++\.\d++$/', $update->tested) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$actualWpVersions = array();
|
||||||
|
|
||||||
|
$wpVersion = $GLOBALS['wp_version'];
|
||||||
|
|
||||||
|
if ( function_exists('get_core_updates') ) {
|
||||||
|
$coreUpdates = get_core_updates();
|
||||||
|
if ( is_array($coreUpdates) ) {
|
||||||
|
foreach ($coreUpdates as $coreUpdate) {
|
||||||
|
if ( isset($coreUpdate->current) ) {
|
||||||
|
$actualWpVersions[] = $coreUpdate->current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$actualWpVersions[] = $wpVersion;
|
||||||
|
|
||||||
|
$actualWpPatchNumber = null;
|
||||||
|
foreach ($actualWpVersions as $version) {
|
||||||
|
if ( preg_match('/^(?P<majorMinor>\d++\.\d++)(?:\.(?P<patch>\d++))?/', $version, $versionParts) ) {
|
||||||
|
if ( $versionParts['majorMinor'] === $update->tested ) {
|
||||||
|
$patch = isset($versionParts['patch']) ? intval($versionParts['patch']) : 0;
|
||||||
|
if ( $actualWpPatchNumber === null ) {
|
||||||
|
$actualWpPatchNumber = $patch;
|
||||||
|
} else {
|
||||||
|
$actualWpPatchNumber = max($actualWpPatchNumber, $patch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ( $actualWpPatchNumber === null ) {
|
||||||
|
$actualWpPatchNumber = 999;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $actualWpPatchNumber > 0 ) {
|
||||||
|
$update->tested .= '.' . $actualWpPatchNumber;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the currently installed version of the plugin or theme.
|
* Get the currently installed version of the plugin or theme.
|
||||||
*
|
*
|
||||||
* @return string|null Version number.
|
* @return string|null Version number.
|
||||||
*/
|
*/
|
||||||
abstract public function getInstalledVersion();
|
public function getInstalledVersion() {
|
||||||
|
return $this->package->getInstalledVersion();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the full path of the plugin or theme directory.
|
* Get the full path of the plugin or theme directory.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
abstract public function getAbsoluteDirectoryPath();
|
public function getAbsoluteDirectoryPath() {
|
||||||
|
return $this->package->getAbsoluteDirectoryPath();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Trigger a PHP error, but only when $debugMode is enabled.
|
* Trigger a PHP error, but only when $debugMode is enabled.
|
||||||
@@ -329,12 +452,23 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
* @param string $message
|
* @param string $message
|
||||||
* @param int $errorType
|
* @param int $errorType
|
||||||
*/
|
*/
|
||||||
protected function triggerError($message, $errorType) {
|
public function triggerError($message, $errorType) {
|
||||||
if ($this->debugMode) {
|
if ( $this->isDebugModeEnabled() ) {
|
||||||
trigger_error($message, $errorType);
|
//phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error -- Only happens in debug mode.
|
||||||
|
trigger_error(esc_html($message), $errorType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function isDebugModeEnabled() {
|
||||||
|
if ( $this->debugMode === null ) {
|
||||||
|
$this->debugMode = (bool)(constant('WP_DEBUG'));
|
||||||
|
}
|
||||||
|
return $this->debugMode;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the full name of an update checker filter, action or DB entry.
|
* Get the full name of an update checker filter, action or DB entry.
|
||||||
*
|
*
|
||||||
@@ -346,7 +480,7 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
*/
|
*/
|
||||||
public function getUniqueName($baseTag) {
|
public function getUniqueName($baseTag) {
|
||||||
$name = 'puc_' . $baseTag;
|
$name = 'puc_' . $baseTag;
|
||||||
if ($this->filterSuffix !== '') {
|
if ( $this->filterSuffix !== '' ) {
|
||||||
$name .= '_' . $this->filterSuffix;
|
$name .= '_' . $this->filterSuffix;
|
||||||
}
|
}
|
||||||
return $name . '-' . $this->slug;
|
return $name . '-' . $this->slug;
|
||||||
@@ -356,7 +490,7 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
* Store API errors that are generated when checking for updates.
|
* Store API errors that are generated when checking for updates.
|
||||||
*
|
*
|
||||||
* @internal
|
* @internal
|
||||||
* @param WP_Error $error
|
* @param \WP_Error $error
|
||||||
* @param array|null $httpResponse
|
* @param array|null $httpResponse
|
||||||
* @param string|null $url
|
* @param string|null $url
|
||||||
* @param string|null $slug
|
* @param string|null $slug
|
||||||
@@ -409,8 +543,8 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
/**
|
/**
|
||||||
* Insert the latest update (if any) into the update list maintained by WP.
|
* Insert the latest update (if any) into the update list maintained by WP.
|
||||||
*
|
*
|
||||||
* @param stdClass $updates Update list.
|
* @param \stdClass $updates Update list.
|
||||||
* @return stdClass Modified update list.
|
* @return \stdClass Modified update list.
|
||||||
*/
|
*/
|
||||||
public function injectUpdate($updates) {
|
public function injectUpdate($updates) {
|
||||||
//Is there an update to insert?
|
//Is there an update to insert?
|
||||||
@@ -427,15 +561,19 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
} else {
|
} else {
|
||||||
//Clean up any stale update info.
|
//Clean up any stale update info.
|
||||||
$updates = $this->removeUpdateFromList($updates);
|
$updates = $this->removeUpdateFromList($updates);
|
||||||
|
//Add a placeholder item to the "no_update" list to enable auto-update support.
|
||||||
|
//If we don't do this, the option to enable automatic updates will only show up
|
||||||
|
//when an update is available.
|
||||||
|
$updates = $this->addNoUpdateItem($updates);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $updates;
|
return $updates;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param stdClass|null $updates
|
* @param \stdClass|null $updates
|
||||||
* @param stdClass|array $updateToAdd
|
* @param \stdClass|array $updateToAdd
|
||||||
* @return stdClass
|
* @return \stdClass
|
||||||
*/
|
*/
|
||||||
protected function addUpdateToList($updates, $updateToAdd) {
|
protected function addUpdateToList($updates, $updateToAdd) {
|
||||||
if ( !is_object($updates) ) {
|
if ( !is_object($updates) ) {
|
||||||
@@ -448,8 +586,8 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param stdClass|null $updates
|
* @param \stdClass|null $updates
|
||||||
* @return stdClass|null
|
* @return \stdClass|null
|
||||||
*/
|
*/
|
||||||
protected function removeUpdateFromList($updates) {
|
protected function removeUpdateFromList($updates) {
|
||||||
if ( isset($updates, $updates->response) ) {
|
if ( isset($updates, $updates->response) ) {
|
||||||
@@ -458,6 +596,40 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
return $updates;
|
return $updates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See this post for more information:
|
||||||
|
* @link https://make.wordpress.org/core/2020/07/30/recommended-usage-of-the-updates-api-to-support-the-auto-updates-ui-for-plugins-and-themes-in-wordpress-5-5/
|
||||||
|
*
|
||||||
|
* @param \stdClass|null $updates
|
||||||
|
* @return \stdClass
|
||||||
|
*/
|
||||||
|
protected function addNoUpdateItem($updates) {
|
||||||
|
if ( !is_object($updates) ) {
|
||||||
|
$updates = new stdClass();
|
||||||
|
$updates->response = array();
|
||||||
|
$updates->no_update = array();
|
||||||
|
} else if ( !isset($updates->no_update) ) {
|
||||||
|
$updates->no_update = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$updates->no_update[$this->getUpdateListKey()] = (object) $this->getNoUpdateItemFields();
|
||||||
|
|
||||||
|
return $updates;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subclasses should override this method to add fields that are specific to plugins or themes.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getNoUpdateItemFields() {
|
||||||
|
return array(
|
||||||
|
'new_version' => $this->getInstalledVersion(),
|
||||||
|
'url' => '',
|
||||||
|
'package' => '',
|
||||||
|
'requires_php' => '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the key that will be used when adding updates to the update list that's maintained
|
* Get the key that will be used when adding updates to the update list that's maintained
|
||||||
* by the WordPress core. The list is always an associative array, but the key is different
|
* by the WordPress core. The list is always an associative array, but the key is different
|
||||||
@@ -491,10 +663,10 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
/**
|
/**
|
||||||
* Retrieve plugin or theme metadata from the JSON document at $this->metadataUrl.
|
* Retrieve plugin or theme metadata from the JSON document at $this->metadataUrl.
|
||||||
*
|
*
|
||||||
* @param string $metaClass Parse the JSON as an instance of this class. It must have a static fromJson method.
|
* @param class-string<Update> $metaClass Parse the JSON as an instance of this class. It must have a static fromJson method.
|
||||||
* @param string $filterRoot
|
* @param string $filterRoot
|
||||||
* @param array $queryArgs Additional query arguments.
|
* @param array $queryArgs Additional query arguments.
|
||||||
* @return array [Puc_v4p4_Metadata|null, array|WP_Error] A metadata instance and the value returned by wp_remote_get().
|
* @return array<Metadata|null, array|WP_Error> A metadata instance and the value returned by wp_remote_get().
|
||||||
*/
|
*/
|
||||||
protected function requestMetadata($metaClass, $filterRoot, $queryArgs = array()) {
|
protected function requestMetadata($metaClass, $filterRoot, $queryArgs = array()) {
|
||||||
//Query args to append to the URL. Plugins can add their own by using a filter callback (see addQueryArgFilter()).
|
//Query args to append to the URL. Plugins can add their own by using a filter callback (see addQueryArgFilter()).
|
||||||
@@ -510,7 +682,7 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
|
|
||||||
//Various options for the wp_remote_get() call. Plugins can filter these, too.
|
//Various options for the wp_remote_get() call. Plugins can filter these, too.
|
||||||
$options = array(
|
$options = array(
|
||||||
'timeout' => 10, //seconds
|
'timeout' => wp_doing_cron() ? 10 : 3,
|
||||||
'headers' => array(
|
'headers' => array(
|
||||||
'Accept' => 'application/json',
|
'Accept' => 'application/json',
|
||||||
),
|
),
|
||||||
@@ -531,6 +703,9 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
$status = $this->validateApiResponse($result);
|
$status = $this->validateApiResponse($result);
|
||||||
$metadata = null;
|
$metadata = null;
|
||||||
if ( !is_wp_error($status) ){
|
if ( !is_wp_error($status) ){
|
||||||
|
if ( (strpos($metaClass, '\\') === false) ) {
|
||||||
|
$metaClass = __NAMESPACE__ . '\\' . $metaClass;
|
||||||
|
}
|
||||||
$metadata = call_user_func(array($metaClass, 'fromJson'), $result['body']);
|
$metadata = call_user_func(array($metaClass, 'fromJson'), $result['body']);
|
||||||
} else {
|
} else {
|
||||||
do_action('puc_api_error', $status, $result, $url, $this->slug);
|
do_action('puc_api_error', $status, $result, $url, $this->slug);
|
||||||
@@ -593,7 +768,7 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
$installedTranslations = $this->getInstalledTranslations();
|
$installedTranslations = $this->getInstalledTranslations();
|
||||||
|
|
||||||
$applicableTranslations = array();
|
$applicableTranslations = array();
|
||||||
foreach($translations as $translation) {
|
foreach ($translations as $translation) {
|
||||||
//Does it match one of the available core languages?
|
//Does it match one of the available core languages?
|
||||||
$isApplicable = array_key_exists($translation->language, $languages);
|
$isApplicable = array_key_exists($translation->language, $languages);
|
||||||
//Is it more recent than an already-installed translation?
|
//Is it more recent than an already-installed translation?
|
||||||
@@ -732,12 +907,12 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
*
|
*
|
||||||
* @param string $source The directory to copy to /wp-content/plugins or /wp-content/themes. Usually a subdirectory of $remoteSource.
|
* @param string $source The directory to copy to /wp-content/plugins or /wp-content/themes. Usually a subdirectory of $remoteSource.
|
||||||
* @param string $remoteSource WordPress has extracted the update to this directory.
|
* @param string $remoteSource WordPress has extracted the update to this directory.
|
||||||
* @param WP_Upgrader $upgrader
|
* @param \WP_Upgrader $upgrader
|
||||||
* @return string|WP_Error
|
* @return string|WP_Error
|
||||||
*/
|
*/
|
||||||
public function fixDirectoryName($source, $remoteSource, $upgrader) {
|
public function fixDirectoryName($source, $remoteSource, $upgrader) {
|
||||||
global $wp_filesystem;
|
global $wp_filesystem;
|
||||||
/** @var WP_Filesystem_Base $wp_filesystem */
|
/** @var \WP_Filesystem_Base $wp_filesystem */
|
||||||
|
|
||||||
//Basic sanity checks.
|
//Basic sanity checks.
|
||||||
if ( !isset($source, $remoteSource, $upgrader, $upgrader->skin, $wp_filesystem) ) {
|
if ( !isset($source, $remoteSource, $upgrader, $upgrader->skin, $wp_filesystem) ) {
|
||||||
@@ -767,7 +942,7 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var WP_Upgrader_Skin $upgrader ->skin */
|
/** @var \WP_Upgrader_Skin $upgrader ->skin */
|
||||||
$upgrader->skin->feedback(sprintf(
|
$upgrader->skin->feedback(sprintf(
|
||||||
'Renaming %s to %s…',
|
'Renaming %s to %s…',
|
||||||
'<span class="code">' . basename($source) . '</span>',
|
'<span class="code">' . basename($source) . '</span>',
|
||||||
@@ -791,7 +966,7 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
/**
|
/**
|
||||||
* Is there an update being installed right now, for this plugin or theme?
|
* Is there an update being installed right now, for this plugin or theme?
|
||||||
*
|
*
|
||||||
* @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
* @param \WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
abstract public function isBeingUpgraded($upgrader = null);
|
abstract public function isBeingUpgraded($upgrader = null);
|
||||||
@@ -805,7 +980,7 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
*/
|
*/
|
||||||
protected function isBadDirectoryStructure($remoteSource) {
|
protected function isBadDirectoryStructure($remoteSource) {
|
||||||
global $wp_filesystem;
|
global $wp_filesystem;
|
||||||
/** @var WP_Filesystem_Base $wp_filesystem */
|
/** @var \WP_Filesystem_Base $wp_filesystem */
|
||||||
|
|
||||||
$sourceFiles = $wp_filesystem->dirlist($remoteSource);
|
$sourceFiles = $wp_filesystem->dirlist($remoteSource);
|
||||||
if ( is_array($sourceFiles) ) {
|
if ( is_array($sourceFiles) ) {
|
||||||
@@ -818,52 +993,6 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------
|
|
||||||
* File header parsing
|
|
||||||
* -------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse plugin or theme metadata from the header comment.
|
|
||||||
*
|
|
||||||
* This is basically a simplified version of the get_file_data() function from /wp-includes/functions.php.
|
|
||||||
* It's intended as a utility for subclasses that detect updates by parsing files in a VCS.
|
|
||||||
*
|
|
||||||
* @param string|null $content File contents.
|
|
||||||
* @return string[]
|
|
||||||
*/
|
|
||||||
public function getFileHeader($content) {
|
|
||||||
$content = (string) $content;
|
|
||||||
|
|
||||||
//WordPress only looks at the first 8 KiB of the file, so we do the same.
|
|
||||||
$content = substr($content, 0, 8192);
|
|
||||||
//Normalize line endings.
|
|
||||||
$content = str_replace("\r", "\n", $content);
|
|
||||||
|
|
||||||
$headers = $this->getHeaderNames();
|
|
||||||
$results = array();
|
|
||||||
foreach ($headers as $field => $name) {
|
|
||||||
$success = preg_match('/^[ \t\/*#@]*' . preg_quote($name, '/') . ':(.*)$/mi', $content, $matches);
|
|
||||||
|
|
||||||
if ( ($success === 1) && $matches[1] ) {
|
|
||||||
$value = $matches[1];
|
|
||||||
if ( function_exists('_cleanup_header_comment') ) {
|
|
||||||
$value = _cleanup_header_comment($value);
|
|
||||||
}
|
|
||||||
$results[$field] = $value;
|
|
||||||
} else {
|
|
||||||
$results[$field] = '';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $results;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array Format: ['HeaderKey' => 'Header Name']
|
|
||||||
*/
|
|
||||||
abstract protected function getHeaderNames();
|
|
||||||
|
|
||||||
/* -------------------------------------------------------------------
|
/* -------------------------------------------------------------------
|
||||||
* DebugBar integration
|
* DebugBar integration
|
||||||
* -------------------------------------------------------------------
|
* -------------------------------------------------------------------
|
||||||
@@ -873,19 +1002,23 @@ if ( !class_exists('Puc_v4p4_UpdateChecker', false) ):
|
|||||||
* Initialize the update checker Debug Bar plugin/add-on thingy.
|
* Initialize the update checker Debug Bar plugin/add-on thingy.
|
||||||
*/
|
*/
|
||||||
public function maybeInitDebugBar() {
|
public function maybeInitDebugBar() {
|
||||||
if ( class_exists('Debug_Bar', false) && file_exists(dirname(__FILE__ . '/DebugBar')) ) {
|
if (
|
||||||
$this->createDebugBarExtension();
|
class_exists('Debug_Bar', false)
|
||||||
|
&& class_exists('Debug_Bar_Panel', false)
|
||||||
|
&& file_exists(dirname(__FILE__) . '/DebugBar')
|
||||||
|
) {
|
||||||
|
$this->debugBarExtension = $this->createDebugBarExtension();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createDebugBarExtension() {
|
protected function createDebugBarExtension() {
|
||||||
return new Puc_v4p4_DebugBar_Extension($this);
|
return new DebugBar\Extension($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display additional configuration details in the Debug Bar panel.
|
* Display additional configuration details in the Debug Bar panel.
|
||||||
*
|
*
|
||||||
* @param Puc_v4p4_DebugBar_Panel $panel
|
* @param DebugBar\Panel $panel
|
||||||
*/
|
*/
|
||||||
public function onDisplayConfiguration($panel) {
|
public function onDisplayConfiguration($panel) {
|
||||||
//Do nothing. Subclasses can use this to add additional info to the panel.
|
//Do nothing. Subclasses can use this to add additional info to the panel.
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v4p4_UpgraderStatus', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p4;
|
||||||
|
|
||||||
|
if ( !class_exists(UpgraderStatus::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A utility class that helps figure out which plugin or theme WordPress is upgrading.
|
* A utility class that helps figure out which plugin or theme WordPress is upgrading.
|
||||||
@@ -8,8 +10,8 @@ if ( !class_exists('Puc_v4p4_UpgraderStatus', false) ):
|
|||||||
* Core classes like Plugin_Upgrader don't expose the plugin file name during an in-progress update (AFAICT).
|
* Core classes like Plugin_Upgrader don't expose the plugin file name during an in-progress update (AFAICT).
|
||||||
* This class uses a few workarounds and heuristics to get the file name.
|
* This class uses a few workarounds and heuristics to get the file name.
|
||||||
*/
|
*/
|
||||||
class Puc_v4p4_UpgraderStatus {
|
class UpgraderStatus {
|
||||||
private $currentType = null; //"plugin" or "theme".
|
private $currentType = null; //This must be either "plugin" or "theme".
|
||||||
private $currentId = null; //Plugin basename or theme directory name.
|
private $currentId = null; //Plugin basename or theme directory name.
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
@@ -27,7 +29,7 @@ if ( !class_exists('Puc_v4p4_UpgraderStatus', false) ):
|
|||||||
* and upgrader implementations are liable to change without notice.
|
* and upgrader implementations are liable to change without notice.
|
||||||
*
|
*
|
||||||
* @param string $pluginFile The plugin to check.
|
* @param string $pluginFile The plugin to check.
|
||||||
* @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
* @param \WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
||||||
* @return bool True if the plugin identified by $pluginFile is being upgraded.
|
* @return bool True if the plugin identified by $pluginFile is being upgraded.
|
||||||
*/
|
*/
|
||||||
public function isPluginBeingUpgraded($pluginFile, $upgrader = null) {
|
public function isPluginBeingUpgraded($pluginFile, $upgrader = null) {
|
||||||
@@ -38,7 +40,7 @@ if ( !class_exists('Puc_v4p4_UpgraderStatus', false) ):
|
|||||||
* Is there an update being installed for a specific theme?
|
* Is there an update being installed for a specific theme?
|
||||||
*
|
*
|
||||||
* @param string $stylesheet Theme directory name.
|
* @param string $stylesheet Theme directory name.
|
||||||
* @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
* @param \WP_Upgrader|null $upgrader The upgrader that's performing the current update.
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isThemeBeingUpgraded($stylesheet, $upgrader = null) {
|
public function isThemeBeingUpgraded($stylesheet, $upgrader = null) {
|
||||||
@@ -50,7 +52,7 @@ if ( !class_exists('Puc_v4p4_UpgraderStatus', false) ):
|
|||||||
*
|
*
|
||||||
* @param string $type
|
* @param string $type
|
||||||
* @param string $id
|
* @param string $id
|
||||||
* @param Plugin_Upgrader|WP_Upgrader|null $upgrader
|
* @param \Plugin_Upgrader|\WP_Upgrader|null $upgrader
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function isBeingUpgraded($type, $id, $upgrader = null) {
|
protected function isBeingUpgraded($type, $id, $upgrader = null) {
|
||||||
@@ -76,7 +78,7 @@ if ( !class_exists('Puc_v4p4_UpgraderStatus', false) ):
|
|||||||
* ['plugin', 'plugin-dir-name/plugin.php']
|
* ['plugin', 'plugin-dir-name/plugin.php']
|
||||||
* ['theme', 'theme-dir-name']
|
* ['theme', 'theme-dir-name']
|
||||||
*
|
*
|
||||||
* @param Plugin_Upgrader|WP_Upgrader $upgrader
|
* @param \Plugin_Upgrader|\WP_Upgrader $upgrader
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function getThingBeingUpgradedBy($upgrader) {
|
private function getThingBeingUpgradedBy($upgrader) {
|
||||||
@@ -89,13 +91,13 @@ if ( !class_exists('Puc_v4p4_UpgraderStatus', false) ):
|
|||||||
$themeDirectoryName = null;
|
$themeDirectoryName = null;
|
||||||
|
|
||||||
$skin = $upgrader->skin;
|
$skin = $upgrader->skin;
|
||||||
if ( isset($skin->theme_info) && ($skin->theme_info instanceof WP_Theme) ) {
|
if ( isset($skin->theme_info) && ($skin->theme_info instanceof \WP_Theme) ) {
|
||||||
$themeDirectoryName = $skin->theme_info->get_stylesheet();
|
$themeDirectoryName = $skin->theme_info->get_stylesheet();
|
||||||
} elseif ( $skin instanceof Plugin_Upgrader_Skin ) {
|
} elseif ( $skin instanceof \Plugin_Upgrader_Skin ) {
|
||||||
if ( isset($skin->plugin) && is_string($skin->plugin) && ($skin->plugin !== '') ) {
|
if ( isset($skin->plugin) && is_string($skin->plugin) && ($skin->plugin !== '') ) {
|
||||||
$pluginFile = $skin->plugin;
|
$pluginFile = $skin->plugin;
|
||||||
}
|
}
|
||||||
} elseif ( $skin instanceof Theme_Upgrader_Skin ) {
|
} elseif ( $skin instanceof \Theme_Upgrader_Skin ) {
|
||||||
if ( isset($skin->theme) && is_string($skin->theme) && ($skin->theme !== '') ) {
|
if ( isset($skin->theme) && is_string($skin->theme) && ($skin->theme !== '') ) {
|
||||||
$themeDirectoryName = $skin->theme;
|
$themeDirectoryName = $skin->theme;
|
||||||
}
|
}
|
||||||
@@ -122,7 +124,6 @@ if ( !class_exists('Puc_v4p4_UpgraderStatus', false) ):
|
|||||||
*/
|
*/
|
||||||
private function identifyPluginByHeaders($searchHeaders) {
|
private function identifyPluginByHeaders($searchHeaders) {
|
||||||
if ( !function_exists('get_plugins') ){
|
if ( !function_exists('get_plugins') ){
|
||||||
/** @noinspection PhpIncludeInspection */
|
|
||||||
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4;
|
||||||
|
|
||||||
if ( !class_exists('Puc_v4p4_Utils', false) ):
|
if ( !class_exists(Utils::class, false) ):
|
||||||
|
|
||||||
class Puc_v4p4_Utils {
|
class Utils {
|
||||||
/**
|
/**
|
||||||
* Get a value from a nested array or object based on a path.
|
* Get a value from a nested array or object based on a path.
|
||||||
*
|
*
|
||||||
@@ -1,7 +1,43 @@
|
|||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v4p4_Vcs_Api') ):
|
|
||||||
|
|
||||||
abstract class Puc_v4p4_Vcs_Api {
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Vcs;
|
||||||
|
|
||||||
|
use Parsedown;
|
||||||
|
use PucReadmeParser;
|
||||||
|
|
||||||
|
if ( !class_exists(Api::class, false) ):
|
||||||
|
|
||||||
|
abstract class Api {
|
||||||
|
const STRATEGY_LATEST_RELEASE = 'latest_release';
|
||||||
|
const STRATEGY_LATEST_TAG = 'latest_tag';
|
||||||
|
const STRATEGY_STABLE_TAG = 'stable_tag';
|
||||||
|
const STRATEGY_BRANCH = 'branch';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Consider all releases regardless of their version number or prerelease/upcoming
|
||||||
|
* release status.
|
||||||
|
*/
|
||||||
|
const RELEASE_FILTER_ALL = 3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exclude releases that have the "prerelease" or "upcoming release" flag.
|
||||||
|
*
|
||||||
|
* This does *not* look for prerelease keywords like "beta" in the version number.
|
||||||
|
* It only uses the data provided by the API. For example, on GitHub, you can
|
||||||
|
* manually mark a release as a prerelease.
|
||||||
|
*/
|
||||||
|
const RELEASE_FILTER_SKIP_PRERELEASE = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If there are no release assets or none of them match the configured filter,
|
||||||
|
* fall back to the automatically generated source code archive.
|
||||||
|
*/
|
||||||
|
const PREFER_RELEASE_ASSETS = 1;
|
||||||
|
/**
|
||||||
|
* Skip releases that don't have any matching release assets.
|
||||||
|
*/
|
||||||
|
const REQUIRE_RELEASE_ASSETS = 2;
|
||||||
|
|
||||||
protected $tagNameProperty = 'name';
|
protected $tagNameProperty = 'name';
|
||||||
protected $slug = '';
|
protected $slug = '';
|
||||||
|
|
||||||
@@ -21,13 +57,19 @@ if ( !class_exists('Puc_v4p4_Vcs_Api') ):
|
|||||||
*/
|
*/
|
||||||
protected $httpFilterName = '';
|
protected $httpFilterName = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string The filter applied to the list of update detection strategies that
|
||||||
|
* are used to find the latest version.
|
||||||
|
*/
|
||||||
|
protected $strategyFilterName = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string|null
|
* @var string|null
|
||||||
*/
|
*/
|
||||||
protected $localDirectory = null;
|
protected $localDirectory = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Puc_v4p4_Vcs_Api constructor.
|
* Api constructor.
|
||||||
*
|
*
|
||||||
* @param string $repositoryUrl
|
* @param string $repositoryUrl
|
||||||
* @param array|string|null $credentials
|
* @param array|string|null $credentials
|
||||||
@@ -45,12 +87,41 @@ if ( !class_exists('Puc_v4p4_Vcs_Api') ):
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Figure out which reference (i.e tag or branch) contains the latest version.
|
* Figure out which reference (i.e. tag or branch) contains the latest version.
|
||||||
*
|
*
|
||||||
* @param string $configBranch Start looking in this branch.
|
* @param string $configBranch Start looking in this branch.
|
||||||
* @return null|Puc_v4p4_Vcs_Reference
|
* @return null|Reference
|
||||||
*/
|
*/
|
||||||
abstract public function chooseReference($configBranch);
|
public function chooseReference($configBranch) {
|
||||||
|
$strategies = $this->getUpdateDetectionStrategies($configBranch);
|
||||||
|
|
||||||
|
if ( !empty($this->strategyFilterName) ) {
|
||||||
|
$strategies = apply_filters(
|
||||||
|
$this->strategyFilterName,
|
||||||
|
$strategies,
|
||||||
|
$this->slug
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($strategies as $strategy) {
|
||||||
|
$reference = call_user_func($strategy);
|
||||||
|
if ( !empty($reference) ) {
|
||||||
|
return $reference;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an ordered list of strategies that can be used to find the latest version.
|
||||||
|
*
|
||||||
|
* The update checker will try each strategy in order until one of them
|
||||||
|
* returns a valid reference.
|
||||||
|
*
|
||||||
|
* @param string $configBranch
|
||||||
|
* @return array<callable> Array of callables that return Vcs_Reference objects.
|
||||||
|
*/
|
||||||
|
abstract protected function getUpdateDetectionStrategies($configBranch);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the readme.txt file from the remote repository and parse it
|
* Get the readme.txt file from the remote repository and parse it
|
||||||
@@ -105,7 +176,7 @@ if ( !class_exists('Puc_v4p4_Vcs_Api') ):
|
|||||||
* Get a branch.
|
* Get a branch.
|
||||||
*
|
*
|
||||||
* @param string $branchName
|
* @param string $branchName
|
||||||
* @return Puc_v4p4_Vcs_Reference|null
|
* @return Reference|null
|
||||||
*/
|
*/
|
||||||
abstract public function getBranch($branchName);
|
abstract public function getBranch($branchName);
|
||||||
|
|
||||||
@@ -113,7 +184,7 @@ if ( !class_exists('Puc_v4p4_Vcs_Api') ):
|
|||||||
* Get a specific tag.
|
* Get a specific tag.
|
||||||
*
|
*
|
||||||
* @param string $tagName
|
* @param string $tagName
|
||||||
* @return Puc_v4p4_Vcs_Reference|null
|
* @return Reference|null
|
||||||
*/
|
*/
|
||||||
abstract public function getTag($tagName);
|
abstract public function getTag($tagName);
|
||||||
|
|
||||||
@@ -121,7 +192,7 @@ if ( !class_exists('Puc_v4p4_Vcs_Api') ):
|
|||||||
* Get the tag that looks like the highest version number.
|
* Get the tag that looks like the highest version number.
|
||||||
* (Implementations should skip pre-release versions if possible.)
|
* (Implementations should skip pre-release versions if possible.)
|
||||||
*
|
*
|
||||||
* @return Puc_v4p4_Vcs_Reference|null
|
* @return Reference|null
|
||||||
*/
|
*/
|
||||||
abstract public function getLatestTag();
|
abstract public function getLatestTag();
|
||||||
|
|
||||||
@@ -147,7 +218,7 @@ if ( !class_exists('Puc_v4p4_Vcs_Api') ):
|
|||||||
/**
|
/**
|
||||||
* Check if a tag appears to be named like a version number.
|
* Check if a tag appears to be named like a version number.
|
||||||
*
|
*
|
||||||
* @param stdClass $tag
|
* @param \stdClass $tag
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function isVersionTag($tag) {
|
protected function isVersionTag($tag) {
|
||||||
@@ -159,8 +230,8 @@ if ( !class_exists('Puc_v4p4_Vcs_Api') ):
|
|||||||
* Sort a list of tags as if they were version numbers.
|
* Sort a list of tags as if they were version numbers.
|
||||||
* Tags that don't look like version number will be removed.
|
* Tags that don't look like version number will be removed.
|
||||||
*
|
*
|
||||||
* @param stdClass[] $tags Array of tag objects.
|
* @param \stdClass[] $tags Array of tag objects.
|
||||||
* @return stdClass[] Filtered array of tags sorted in descending order.
|
* @return \stdClass[] Filtered array of tags sorted in descending order.
|
||||||
*/
|
*/
|
||||||
protected function sortTagsByVersion($tags) {
|
protected function sortTagsByVersion($tags) {
|
||||||
//Keep only those tags that look like version numbers.
|
//Keep only those tags that look like version numbers.
|
||||||
@@ -174,8 +245,8 @@ if ( !class_exists('Puc_v4p4_Vcs_Api') ):
|
|||||||
/**
|
/**
|
||||||
* Compare two tags as if they were version number.
|
* Compare two tags as if they were version number.
|
||||||
*
|
*
|
||||||
* @param stdClass $tag1 Tag object.
|
* @param \stdClass $tag1 Tag object.
|
||||||
* @param stdClass $tag2 Another tag object.
|
* @param \stdClass $tag2 Another tag object.
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
protected function compareTagNames($tag1, $tag2) {
|
protected function compareTagNames($tag1, $tag2) {
|
||||||
@@ -224,7 +295,6 @@ if ( !class_exists('Puc_v4p4_Vcs_Api') ):
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @noinspection PhpUndefinedClassInspection */
|
|
||||||
return Parsedown::instance()->text($changelog);
|
return Parsedown::instance()->text($changelog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,6 +350,13 @@ if ( !class_exists('Puc_v4p4_Vcs_Api') ):
|
|||||||
$this->httpFilterName = $filterName;
|
$this->httpFilterName = $filterName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $filterName
|
||||||
|
*/
|
||||||
|
public function setStrategyFilterName($filterName) {
|
||||||
|
$this->strategyFilterName = $filterName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $directory
|
* @param string $directory
|
||||||
*/
|
*/
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
if ( !interface_exists('Puc_v4p4_Vcs_BaseChecker', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Vcs;
|
||||||
|
|
||||||
interface Puc_v4p4_Vcs_BaseChecker {
|
if ( !interface_exists(BaseChecker::class, false) ):
|
||||||
|
|
||||||
|
interface BaseChecker {
|
||||||
/**
|
/**
|
||||||
* Set the repository branch to use for updates. Defaults to 'master'.
|
* Set the repository branch to use for updates. Defaults to 'master'.
|
||||||
*
|
*
|
||||||
@@ -19,7 +21,7 @@ if ( !interface_exists('Puc_v4p4_Vcs_BaseChecker', false) ):
|
|||||||
public function setAuthentication($credentials);
|
public function setAuthentication($credentials);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Puc_v4p4_Vcs_Api
|
* @return Api
|
||||||
*/
|
*/
|
||||||
public function getVcsApi();
|
public function getVcsApi();
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v4p4_Vcs_BitBucketApi', false) ):
|
|
||||||
|
|
||||||
class Puc_v4p4_Vcs_BitBucketApi extends Puc_v4p4_Vcs_Api {
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Vcs;
|
||||||
|
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\OAuthSignature;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\Utils;
|
||||||
|
|
||||||
|
if ( !class_exists(BitBucketApi::class, false) ):
|
||||||
|
|
||||||
|
class BitBucketApi extends Api {
|
||||||
/**
|
/**
|
||||||
* @var Puc_v4p4_OAuthSignature
|
* @var OAuthSignature
|
||||||
*/
|
*/
|
||||||
private $oauth = null;
|
private $oauth = null;
|
||||||
|
|
||||||
@@ -18,39 +24,32 @@ if ( !class_exists('Puc_v4p4_Vcs_BitBucketApi', false) ):
|
|||||||
private $repository;
|
private $repository;
|
||||||
|
|
||||||
public function __construct($repositoryUrl, $credentials = array()) {
|
public function __construct($repositoryUrl, $credentials = array()) {
|
||||||
$path = @parse_url($repositoryUrl, PHP_URL_PATH);
|
$path = wp_parse_url($repositoryUrl, PHP_URL_PATH);
|
||||||
if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
|
if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
|
||||||
$this->username = $matches['username'];
|
$this->username = $matches['username'];
|
||||||
$this->repository = $matches['repository'];
|
$this->repository = $matches['repository'];
|
||||||
} else {
|
} else {
|
||||||
throw new InvalidArgumentException('Invalid BitBucket repository URL: "' . $repositoryUrl . '"');
|
throw new \InvalidArgumentException('Invalid BitBucket repository URL: "' . $repositoryUrl . '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::__construct($repositoryUrl, $credentials);
|
parent::__construct($repositoryUrl, $credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function getUpdateDetectionStrategies($configBranch) {
|
||||||
* Figure out which reference (i.e tag or branch) contains the latest version.
|
$strategies = array(
|
||||||
*
|
self::STRATEGY_STABLE_TAG => function () use ($configBranch) {
|
||||||
* @param string $configBranch Start looking in this branch.
|
return $this->getStableTag($configBranch);
|
||||||
* @return null|Puc_v4p4_Vcs_Reference
|
},
|
||||||
*/
|
);
|
||||||
public function chooseReference($configBranch) {
|
|
||||||
$updateSource = null;
|
|
||||||
|
|
||||||
//Check if there's a "Stable tag: 1.2.3" header that points to a valid tag.
|
if ( ($configBranch === 'master' || $configBranch === 'main') ) {
|
||||||
$updateSource = $this->getStableTag($configBranch);
|
$strategies[self::STRATEGY_LATEST_TAG] = array($this, 'getLatestTag');
|
||||||
|
|
||||||
//Look for version-like tags.
|
|
||||||
if ( !$updateSource && ($configBranch === 'master') ) {
|
|
||||||
$updateSource = $this->getLatestTag();
|
|
||||||
}
|
|
||||||
//If all else fails, use the specified branch itself.
|
|
||||||
if ( !$updateSource ) {
|
|
||||||
$updateSource = $this->getBranch($configBranch);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $updateSource;
|
$strategies[self::STRATEGY_BRANCH] = function () use ($configBranch) {
|
||||||
|
return $this->getBranch($configBranch);
|
||||||
|
};
|
||||||
|
return $strategies;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBranch($branchName) {
|
public function getBranch($branchName) {
|
||||||
@@ -59,8 +58,16 @@ if ( !class_exists('Puc_v4p4_Vcs_BitBucketApi', false) ):
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Puc_v4p4_Vcs_Reference(array(
|
//The "/src/{stuff}/{path}" endpoint doesn't seem to handle branch names that contain slashes.
|
||||||
'name' => $branch->name,
|
//If we don't encode the slash, we get a 404. If we encode it as "%2F", we get a 401.
|
||||||
|
//To avoid issues, if the branch name is not URL-safe, let's use the commit hash instead.
|
||||||
|
$ref = $branch->name;
|
||||||
|
if ((urlencode($ref) !== $ref) && isset($branch->target->hash)) {
|
||||||
|
$ref = $branch->target->hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Reference(array(
|
||||||
|
'name' => $ref,
|
||||||
'updated' => $branch->target->date,
|
'updated' => $branch->target->date,
|
||||||
'downloadUrl' => $this->getDownloadUrl($branch->name),
|
'downloadUrl' => $this->getDownloadUrl($branch->name),
|
||||||
));
|
));
|
||||||
@@ -70,7 +77,7 @@ if ( !class_exists('Puc_v4p4_Vcs_BitBucketApi', false) ):
|
|||||||
* Get a specific tag.
|
* Get a specific tag.
|
||||||
*
|
*
|
||||||
* @param string $tagName
|
* @param string $tagName
|
||||||
* @return Puc_v4p4_Vcs_Reference|null
|
* @return Reference|null
|
||||||
*/
|
*/
|
||||||
public function getTag($tagName) {
|
public function getTag($tagName) {
|
||||||
$tag = $this->api('/refs/tags/' . $tagName);
|
$tag = $this->api('/refs/tags/' . $tagName);
|
||||||
@@ -78,7 +85,7 @@ if ( !class_exists('Puc_v4p4_Vcs_BitBucketApi', false) ):
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Puc_v4p4_Vcs_Reference(array(
|
return new Reference(array(
|
||||||
'name' => $tag->name,
|
'name' => $tag->name,
|
||||||
'version' => ltrim($tag->name, 'v'),
|
'version' => ltrim($tag->name, 'v'),
|
||||||
'updated' => $tag->target->date,
|
'updated' => $tag->target->date,
|
||||||
@@ -89,7 +96,7 @@ if ( !class_exists('Puc_v4p4_Vcs_BitBucketApi', false) ):
|
|||||||
/**
|
/**
|
||||||
* Get the tag that looks like the highest version number.
|
* Get the tag that looks like the highest version number.
|
||||||
*
|
*
|
||||||
* @return Puc_v4p4_Vcs_Reference|null
|
* @return Reference|null
|
||||||
*/
|
*/
|
||||||
public function getLatestTag() {
|
public function getLatestTag() {
|
||||||
$tags = $this->api('/refs/tags?sort=-target.date');
|
$tags = $this->api('/refs/tags?sort=-target.date');
|
||||||
@@ -103,7 +110,7 @@ if ( !class_exists('Puc_v4p4_Vcs_BitBucketApi', false) ):
|
|||||||
//Return the first result.
|
//Return the first result.
|
||||||
if ( !empty($versionTags) ) {
|
if ( !empty($versionTags) ) {
|
||||||
$tag = $versionTags[0];
|
$tag = $versionTags[0];
|
||||||
return new Puc_v4p4_Vcs_Reference(array(
|
return new Reference(array(
|
||||||
'name' => $tag->name,
|
'name' => $tag->name,
|
||||||
'version' => ltrim($tag->name, 'v'),
|
'version' => ltrim($tag->name, 'v'),
|
||||||
'updated' => $tag->target->date,
|
'updated' => $tag->target->date,
|
||||||
@@ -117,7 +124,7 @@ if ( !class_exists('Puc_v4p4_Vcs_BitBucketApi', false) ):
|
|||||||
* Get the tag/ref specified by the "Stable tag" header in the readme.txt of a given branch.
|
* Get the tag/ref specified by the "Stable tag" header in the readme.txt of a given branch.
|
||||||
*
|
*
|
||||||
* @param string $branch
|
* @param string $branch
|
||||||
* @return null|Puc_v4p4_Vcs_Reference
|
* @return null|Reference
|
||||||
*/
|
*/
|
||||||
protected function getStableTag($branch) {
|
protected function getStableTag($branch) {
|
||||||
$remoteReadme = $this->getRemoteReadme($branch);
|
$remoteReadme = $this->getRemoteReadme($branch);
|
||||||
@@ -157,11 +164,11 @@ if ( !class_exists('Puc_v4p4_Vcs_BitBucketApi', false) ):
|
|||||||
* @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
|
* @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
|
||||||
*/
|
*/
|
||||||
public function getRemoteFile($path, $ref = 'master') {
|
public function getRemoteFile($path, $ref = 'master') {
|
||||||
$response = $this->api('src/' . $ref . '/' . ltrim($path), '1.0');
|
$response = $this->api('src/' . $ref . '/' . ltrim($path));
|
||||||
if ( is_wp_error($response) || !isset($response, $response->data) ) {
|
if ( is_wp_error($response) || !is_string($response) ) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return $response->data;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -183,16 +190,19 @@ if ( !class_exists('Puc_v4p4_Vcs_BitBucketApi', false) ):
|
|||||||
*
|
*
|
||||||
* @param string $url
|
* @param string $url
|
||||||
* @param string $version
|
* @param string $version
|
||||||
* @return mixed|WP_Error
|
* @return mixed|\WP_Error
|
||||||
*/
|
*/
|
||||||
public function api($url, $version = '2.0') {
|
public function api($url, $version = '2.0') {
|
||||||
|
$url = ltrim($url, '/');
|
||||||
|
$isSrcResource = Utils::startsWith($url, 'src/');
|
||||||
|
|
||||||
$url = implode('/', array(
|
$url = implode('/', array(
|
||||||
'https://api.bitbucket.org',
|
'https://api.bitbucket.org',
|
||||||
$version,
|
$version,
|
||||||
'repositories',
|
'repositories',
|
||||||
$this->username,
|
$this->username,
|
||||||
$this->repository,
|
$this->repository,
|
||||||
ltrim($url, '/')
|
$url
|
||||||
));
|
));
|
||||||
$baseUrl = $url;
|
$baseUrl = $url;
|
||||||
|
|
||||||
@@ -200,7 +210,7 @@ if ( !class_exists('Puc_v4p4_Vcs_BitBucketApi', false) ):
|
|||||||
$url = $this->oauth->sign($url,'GET');
|
$url = $this->oauth->sign($url,'GET');
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = array('timeout' => 10);
|
$options = array('timeout' => wp_doing_cron() ? 10 : 3);
|
||||||
if ( !empty($this->httpFilterName) ) {
|
if ( !empty($this->httpFilterName) ) {
|
||||||
$options = apply_filters($this->httpFilterName, $options);
|
$options = apply_filters($this->httpFilterName, $options);
|
||||||
}
|
}
|
||||||
@@ -213,11 +223,17 @@ if ( !class_exists('Puc_v4p4_Vcs_BitBucketApi', false) ):
|
|||||||
$code = wp_remote_retrieve_response_code($response);
|
$code = wp_remote_retrieve_response_code($response);
|
||||||
$body = wp_remote_retrieve_body($response);
|
$body = wp_remote_retrieve_body($response);
|
||||||
if ( $code === 200 ) {
|
if ( $code === 200 ) {
|
||||||
$document = json_decode($body);
|
if ( $isSrcResource ) {
|
||||||
|
//Most responses are JSON-encoded, but src resources just
|
||||||
|
//return raw file contents.
|
||||||
|
$document = $body;
|
||||||
|
} else {
|
||||||
|
$document = json_decode($body);
|
||||||
|
}
|
||||||
return $document;
|
return $document;
|
||||||
}
|
}
|
||||||
|
|
||||||
$error = new WP_Error(
|
$error = new \WP_Error(
|
||||||
'puc-bitbucket-http-error',
|
'puc-bitbucket-http-error',
|
||||||
sprintf('BitBucket API error. Base URL: "%s", HTTP status code: %d.', $baseUrl, $code)
|
sprintf('BitBucket API error. Base URL: "%s", HTTP status code: %d.', $baseUrl, $code)
|
||||||
);
|
);
|
||||||
@@ -233,7 +249,7 @@ if ( !class_exists('Puc_v4p4_Vcs_BitBucketApi', false) ):
|
|||||||
parent::setAuthentication($credentials);
|
parent::setAuthentication($credentials);
|
||||||
|
|
||||||
if ( !empty($credentials) && !empty($credentials['consumer_key']) ) {
|
if ( !empty($credentials) && !empty($credentials['consumer_key']) ) {
|
||||||
$this->oauth = new Puc_v4p4_OAuthSignature(
|
$this->oauth = new OAuthSignature(
|
||||||
$credentials['consumer_key'],
|
$credentials['consumer_key'],
|
||||||
$credentials['consumer_secret']
|
$credentials['consumer_secret']
|
||||||
);
|
);
|
||||||
@@ -244,7 +260,7 @@ if ( !class_exists('Puc_v4p4_Vcs_BitBucketApi', false) ):
|
|||||||
|
|
||||||
public function signDownloadUrl($url) {
|
public function signDownloadUrl($url) {
|
||||||
//Add authentication data to download URLs. Since OAuth signatures incorporate
|
//Add authentication data to download URLs. Since OAuth signatures incorporate
|
||||||
//timestamps, we have to do this immediately before inserting the update. Otherwise
|
//timestamps, we have to do this immediately before inserting the update. Otherwise,
|
||||||
//authentication could fail due to a stale timestamp.
|
//authentication could fail due to a stale timestamp.
|
||||||
if ( $this->oauth ) {
|
if ( $this->oauth ) {
|
||||||
$url = $this->oauth->sign($url);
|
$url = $this->oauth->sign($url);
|
||||||
467
plugin-update-checker-5.4/Puc/v5p4/Vcs/GitHubApi.php
Normal file
467
plugin-update-checker-5.4/Puc/v5p4/Vcs/GitHubApi.php
Normal file
@@ -0,0 +1,467 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Vcs;
|
||||||
|
|
||||||
|
use Parsedown;
|
||||||
|
|
||||||
|
if ( !class_exists(GitHubApi::class, false) ):
|
||||||
|
|
||||||
|
class GitHubApi extends Api {
|
||||||
|
use ReleaseAssetSupport;
|
||||||
|
use ReleaseFilteringFeature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string GitHub username.
|
||||||
|
*/
|
||||||
|
protected $userName;
|
||||||
|
/**
|
||||||
|
* @var string GitHub repository name.
|
||||||
|
*/
|
||||||
|
protected $repositoryName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string Either a fully qualified repository URL, or just "user/repo-name".
|
||||||
|
*/
|
||||||
|
protected $repositoryUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string GitHub authentication token. Optional.
|
||||||
|
*/
|
||||||
|
protected $accessToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
private $downloadFilterAdded = false;
|
||||||
|
|
||||||
|
public function __construct($repositoryUrl, $accessToken = null) {
|
||||||
|
$path = wp_parse_url($repositoryUrl, PHP_URL_PATH);
|
||||||
|
if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
|
||||||
|
$this->userName = $matches['username'];
|
||||||
|
$this->repositoryName = $matches['repository'];
|
||||||
|
} else {
|
||||||
|
throw new \InvalidArgumentException('Invalid GitHub repository URL: "' . $repositoryUrl . '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::__construct($repositoryUrl, $accessToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the latest release from GitHub.
|
||||||
|
*
|
||||||
|
* @return Reference|null
|
||||||
|
*/
|
||||||
|
public function getLatestRelease() {
|
||||||
|
//The "latest release" endpoint returns one release and always skips pre-releases,
|
||||||
|
//so we can only use it if that's compatible with the current filter settings.
|
||||||
|
if (
|
||||||
|
$this->shouldSkipPreReleases()
|
||||||
|
&& (
|
||||||
|
($this->releaseFilterMaxReleases === 1) || !$this->hasCustomReleaseFilter()
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
//Just get the latest release.
|
||||||
|
$release = $this->api('/repos/:user/:repo/releases/latest');
|
||||||
|
if ( is_wp_error($release) || !is_object($release) || !isset($release->tag_name) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
$foundReleases = array($release);
|
||||||
|
} else {
|
||||||
|
//Get a list of the most recent releases.
|
||||||
|
$foundReleases = $this->api(
|
||||||
|
'/repos/:user/:repo/releases',
|
||||||
|
array('per_page' => $this->releaseFilterMaxReleases)
|
||||||
|
);
|
||||||
|
if ( is_wp_error($foundReleases) || !is_array($foundReleases) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($foundReleases as $release) {
|
||||||
|
//Always skip drafts.
|
||||||
|
if ( isset($release->draft) && !empty($release->draft) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Skip pre-releases unless specifically included.
|
||||||
|
if (
|
||||||
|
$this->shouldSkipPreReleases()
|
||||||
|
&& isset($release->prerelease)
|
||||||
|
&& !empty($release->prerelease)
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$versionNumber = ltrim($release->tag_name, 'v'); //Remove the "v" prefix from "v1.2.3".
|
||||||
|
|
||||||
|
//Custom release filtering.
|
||||||
|
if ( !$this->matchesCustomReleaseFilter($versionNumber, $release) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$reference = new Reference(array(
|
||||||
|
'name' => $release->tag_name,
|
||||||
|
'version' => $versionNumber,
|
||||||
|
'downloadUrl' => $release->zipball_url,
|
||||||
|
'updated' => $release->created_at,
|
||||||
|
'apiResponse' => $release,
|
||||||
|
));
|
||||||
|
|
||||||
|
if ( isset($release->assets[0]) ) {
|
||||||
|
$reference->downloadCount = $release->assets[0]->download_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $this->releaseAssetsEnabled ) {
|
||||||
|
//Use the first release asset that matches the specified regular expression.
|
||||||
|
if ( isset($release->assets, $release->assets[0]) ) {
|
||||||
|
$matchingAssets = array_values(array_filter($release->assets, array($this, 'matchesAssetFilter')));
|
||||||
|
} else {
|
||||||
|
$matchingAssets = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !empty($matchingAssets) ) {
|
||||||
|
if ( $this->isAuthenticationEnabled() ) {
|
||||||
|
/**
|
||||||
|
* Keep in mind that we'll need to add an "Accept" header to download this asset.
|
||||||
|
*
|
||||||
|
* @see setUpdateDownloadHeaders()
|
||||||
|
*/
|
||||||
|
$reference->downloadUrl = $matchingAssets[0]->url;
|
||||||
|
} else {
|
||||||
|
//It seems that browser_download_url only works for public repositories.
|
||||||
|
//Using an access_token doesn't help. Maybe OAuth would work?
|
||||||
|
$reference->downloadUrl = $matchingAssets[0]->browser_download_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
$reference->downloadCount = $matchingAssets[0]->download_count;
|
||||||
|
} else if ( $this->releaseAssetPreference === Api::REQUIRE_RELEASE_ASSETS ) {
|
||||||
|
//None of the assets match the filter, and we're not allowed
|
||||||
|
//to fall back to the auto-generated source ZIP.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !empty($release->body) ) {
|
||||||
|
$reference->changelog = Parsedown::instance()->text($release->body);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tag that looks like the highest version number.
|
||||||
|
*
|
||||||
|
* @return Reference|null
|
||||||
|
*/
|
||||||
|
public function getLatestTag() {
|
||||||
|
$tags = $this->api('/repos/:user/:repo/tags');
|
||||||
|
|
||||||
|
if ( is_wp_error($tags) || !is_array($tags) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$versionTags = $this->sortTagsByVersion($tags);
|
||||||
|
if ( empty($versionTags) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tag = $versionTags[0];
|
||||||
|
return new Reference(array(
|
||||||
|
'name' => $tag->name,
|
||||||
|
'version' => ltrim($tag->name, 'v'),
|
||||||
|
'downloadUrl' => $tag->zipball_url,
|
||||||
|
'apiResponse' => $tag,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a branch by name.
|
||||||
|
*
|
||||||
|
* @param string $branchName
|
||||||
|
* @return null|Reference
|
||||||
|
*/
|
||||||
|
public function getBranch($branchName) {
|
||||||
|
$branch = $this->api('/repos/:user/:repo/branches/' . $branchName);
|
||||||
|
if ( is_wp_error($branch) || empty($branch) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$reference = new Reference(array(
|
||||||
|
'name' => $branch->name,
|
||||||
|
'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name),
|
||||||
|
'apiResponse' => $branch,
|
||||||
|
));
|
||||||
|
|
||||||
|
if ( isset($branch->commit, $branch->commit->commit, $branch->commit->commit->author->date) ) {
|
||||||
|
$reference->updated = $branch->commit->commit->author->date;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the latest commit that changed the specified file.
|
||||||
|
*
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $ref Reference name (e.g. branch or tag).
|
||||||
|
* @return \StdClass|null
|
||||||
|
*/
|
||||||
|
public function getLatestCommit($filename, $ref = 'master') {
|
||||||
|
$commits = $this->api(
|
||||||
|
'/repos/:user/:repo/commits',
|
||||||
|
array(
|
||||||
|
'path' => $filename,
|
||||||
|
'sha' => $ref,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if ( !is_wp_error($commits) && isset($commits[0]) ) {
|
||||||
|
return $commits[0];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the timestamp of the latest commit that changed the specified branch or tag.
|
||||||
|
*
|
||||||
|
* @param string $ref Reference name (e.g. branch or tag).
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getLatestCommitTime($ref) {
|
||||||
|
$commits = $this->api('/repos/:user/:repo/commits', array('sha' => $ref));
|
||||||
|
if ( !is_wp_error($commits) && isset($commits[0]) ) {
|
||||||
|
return $commits[0]->commit->author->date;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform a GitHub API request.
|
||||||
|
*
|
||||||
|
* @param string $url
|
||||||
|
* @param array $queryParams
|
||||||
|
* @return mixed|\WP_Error
|
||||||
|
*/
|
||||||
|
protected function api($url, $queryParams = array()) {
|
||||||
|
$baseUrl = $url;
|
||||||
|
$url = $this->buildApiUrl($url, $queryParams);
|
||||||
|
|
||||||
|
$options = array('timeout' => wp_doing_cron() ? 10 : 3);
|
||||||
|
if ( $this->isAuthenticationEnabled() ) {
|
||||||
|
$options['headers'] = array('Authorization' => $this->getAuthorizationHeader());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !empty($this->httpFilterName) ) {
|
||||||
|
$options = apply_filters($this->httpFilterName, $options);
|
||||||
|
}
|
||||||
|
$response = wp_remote_get($url, $options);
|
||||||
|
if ( is_wp_error($response) ) {
|
||||||
|
do_action('puc_api_error', $response, null, $url, $this->slug);
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
$code = wp_remote_retrieve_response_code($response);
|
||||||
|
$body = wp_remote_retrieve_body($response);
|
||||||
|
if ( $code === 200 ) {
|
||||||
|
$document = json_decode($body);
|
||||||
|
return $document;
|
||||||
|
}
|
||||||
|
|
||||||
|
$error = new \WP_Error(
|
||||||
|
'puc-github-http-error',
|
||||||
|
sprintf('GitHub API error. Base URL: "%s", HTTP status code: %d.', $baseUrl, $code)
|
||||||
|
);
|
||||||
|
do_action('puc_api_error', $error, $response, $url, $this->slug);
|
||||||
|
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a fully qualified URL for an API request.
|
||||||
|
*
|
||||||
|
* @param string $url
|
||||||
|
* @param array $queryParams
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function buildApiUrl($url, $queryParams) {
|
||||||
|
$variables = array(
|
||||||
|
'user' => $this->userName,
|
||||||
|
'repo' => $this->repositoryName,
|
||||||
|
);
|
||||||
|
foreach ($variables as $name => $value) {
|
||||||
|
$url = str_replace('/:' . $name, '/' . urlencode($value), $url);
|
||||||
|
}
|
||||||
|
$url = 'https://api.github.com' . $url;
|
||||||
|
|
||||||
|
if ( !empty($queryParams) ) {
|
||||||
|
$url = add_query_arg($queryParams, $url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the contents of a file from a specific branch or tag.
|
||||||
|
*
|
||||||
|
* @param string $path File name.
|
||||||
|
* @param string $ref
|
||||||
|
* @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
|
||||||
|
*/
|
||||||
|
public function getRemoteFile($path, $ref = 'master') {
|
||||||
|
$apiUrl = '/repos/:user/:repo/contents/' . $path;
|
||||||
|
$response = $this->api($apiUrl, array('ref' => $ref));
|
||||||
|
|
||||||
|
if ( is_wp_error($response) || !isset($response->content) || ($response->encoding !== 'base64') ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return base64_decode($response->content);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a URL to download a ZIP archive of the specified branch/tag/etc.
|
||||||
|
*
|
||||||
|
* @param string $ref
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function buildArchiveDownloadUrl($ref = 'master') {
|
||||||
|
$url = sprintf(
|
||||||
|
'https://api.github.com/repos/%1$s/%2$s/zipball/%3$s',
|
||||||
|
urlencode($this->userName),
|
||||||
|
urlencode($this->repositoryName),
|
||||||
|
urlencode($ref)
|
||||||
|
);
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a specific tag.
|
||||||
|
*
|
||||||
|
* @param string $tagName
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function getTag($tagName) {
|
||||||
|
//The current GitHub update checker doesn't use getTag, so I didn't bother to implement it.
|
||||||
|
throw new \LogicException('The ' . __METHOD__ . ' method is not implemented and should not be used.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAuthentication($credentials) {
|
||||||
|
parent::setAuthentication($credentials);
|
||||||
|
$this->accessToken = is_string($credentials) ? $credentials : null;
|
||||||
|
|
||||||
|
//Optimization: Instead of filtering all HTTP requests, let's do it only when
|
||||||
|
//WordPress is about to download an update.
|
||||||
|
add_filter('upgrader_pre_download', array($this, 'addHttpRequestFilter'), 10, 1); //WP 3.7+
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getUpdateDetectionStrategies($configBranch) {
|
||||||
|
$strategies = array();
|
||||||
|
|
||||||
|
if ( $configBranch === 'master' || $configBranch === 'main') {
|
||||||
|
//Use the latest release.
|
||||||
|
$strategies[self::STRATEGY_LATEST_RELEASE] = array($this, 'getLatestRelease');
|
||||||
|
//Failing that, use the tag with the highest version number.
|
||||||
|
$strategies[self::STRATEGY_LATEST_TAG] = array($this, 'getLatestTag');
|
||||||
|
}
|
||||||
|
|
||||||
|
//Alternatively, just use the branch itself.
|
||||||
|
$strategies[self::STRATEGY_BRANCH] = function () use ($configBranch) {
|
||||||
|
return $this->getBranch($configBranch);
|
||||||
|
};
|
||||||
|
|
||||||
|
return $strategies;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the unchanging part of a release asset URL. Used to identify download attempts.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getAssetApiBaseUrl() {
|
||||||
|
return sprintf(
|
||||||
|
'//api.github.com/repos/%1$s/%2$s/releases/assets/',
|
||||||
|
$this->userName,
|
||||||
|
$this->repositoryName
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getFilterableAssetName($releaseAsset) {
|
||||||
|
if ( isset($releaseAsset->name) ) {
|
||||||
|
return $releaseAsset->name;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param bool $result
|
||||||
|
* @return bool
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
public function addHttpRequestFilter($result) {
|
||||||
|
if ( !$this->downloadFilterAdded && $this->isAuthenticationEnabled() ) {
|
||||||
|
//phpcs:ignore WordPressVIPMinimum.Hooks.RestrictedHooks.http_request_args -- The callback doesn't change the timeout.
|
||||||
|
add_filter('http_request_args', array($this, 'setUpdateDownloadHeaders'), 10, 2);
|
||||||
|
add_action('requests-requests.before_redirect', array($this, 'removeAuthHeaderFromRedirects'), 10, 4);
|
||||||
|
$this->downloadFilterAdded = true;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the HTTP headers that are necessary to download updates from private repositories.
|
||||||
|
*
|
||||||
|
* See GitHub docs:
|
||||||
|
*
|
||||||
|
* @link https://developer.github.com/v3/repos/releases/#get-a-single-release-asset
|
||||||
|
* @link https://developer.github.com/v3/auth/#basic-authentication
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
|
* @param array $requestArgs
|
||||||
|
* @param string $url
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function setUpdateDownloadHeaders($requestArgs, $url = '') {
|
||||||
|
//Is WordPress trying to download one of our release assets?
|
||||||
|
if ( $this->releaseAssetsEnabled && (strpos($url, $this->getAssetApiBaseUrl()) !== false) ) {
|
||||||
|
$requestArgs['headers']['Accept'] = 'application/octet-stream';
|
||||||
|
}
|
||||||
|
//Use Basic authentication, but only if the download is from our repository.
|
||||||
|
$repoApiBaseUrl = $this->buildApiUrl('/repos/:user/:repo/', array());
|
||||||
|
if ( $this->isAuthenticationEnabled() && (strpos($url, $repoApiBaseUrl)) === 0 ) {
|
||||||
|
$requestArgs['headers']['Authorization'] = $this->getAuthorizationHeader();
|
||||||
|
}
|
||||||
|
return $requestArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When following a redirect, the Requests library will automatically forward
|
||||||
|
* the authorization header to other hosts. We don't want that because it breaks
|
||||||
|
* AWS downloads and can leak authorization information.
|
||||||
|
*
|
||||||
|
* @param string $location
|
||||||
|
* @param array $headers
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
public function removeAuthHeaderFromRedirects(&$location, &$headers) {
|
||||||
|
$repoApiBaseUrl = $this->buildApiUrl('/repos/:user/:repo/', array());
|
||||||
|
if ( strpos($location, $repoApiBaseUrl) === 0 ) {
|
||||||
|
return; //This request is going to GitHub, so it's fine.
|
||||||
|
}
|
||||||
|
//Remove the header.
|
||||||
|
if ( isset($headers['Authorization']) ) {
|
||||||
|
unset($headers['Authorization']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the value of the "Authorization" header.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getAuthorizationHeader() {
|
||||||
|
return 'Basic ' . base64_encode($this->userName . ':' . $this->accessToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
endif;
|
||||||
414
plugin-update-checker-5.4/Puc/v5p4/Vcs/GitLabApi.php
Normal file
414
plugin-update-checker-5.4/Puc/v5p4/Vcs/GitLabApi.php
Normal file
@@ -0,0 +1,414 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Vcs;
|
||||||
|
|
||||||
|
if ( !class_exists(GitLabApi::class, false) ):
|
||||||
|
|
||||||
|
class GitLabApi extends Api {
|
||||||
|
use ReleaseAssetSupport;
|
||||||
|
use ReleaseFilteringFeature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string GitLab username.
|
||||||
|
*/
|
||||||
|
protected $userName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string GitLab server host.
|
||||||
|
*/
|
||||||
|
protected $repositoryHost;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string Protocol used by this GitLab server: "http" or "https".
|
||||||
|
*/
|
||||||
|
protected $repositoryProtocol = 'https';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string GitLab repository name.
|
||||||
|
*/
|
||||||
|
protected $repositoryName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string GitLab authentication token. Optional.
|
||||||
|
*/
|
||||||
|
protected $accessToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* @var bool No longer used.
|
||||||
|
*/
|
||||||
|
protected $releasePackageEnabled = false;
|
||||||
|
|
||||||
|
public function __construct($repositoryUrl, $accessToken = null, $subgroup = null) {
|
||||||
|
//Parse the repository host to support custom hosts.
|
||||||
|
$port = wp_parse_url($repositoryUrl, PHP_URL_PORT);
|
||||||
|
if ( !empty($port) ) {
|
||||||
|
$port = ':' . $port;
|
||||||
|
}
|
||||||
|
$this->repositoryHost = wp_parse_url($repositoryUrl, PHP_URL_HOST) . $port;
|
||||||
|
|
||||||
|
if ( $this->repositoryHost !== 'gitlab.com' ) {
|
||||||
|
$this->repositoryProtocol = wp_parse_url($repositoryUrl, PHP_URL_SCHEME);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Find the repository information
|
||||||
|
$path = wp_parse_url($repositoryUrl, PHP_URL_PATH);
|
||||||
|
if ( preg_match('@^/?(?P<username>[^/]+?)/(?P<repository>[^/#?&]+?)/?$@', $path, $matches) ) {
|
||||||
|
$this->userName = $matches['username'];
|
||||||
|
$this->repositoryName = $matches['repository'];
|
||||||
|
} elseif ( ($this->repositoryHost === 'gitlab.com') ) {
|
||||||
|
//This is probably a repository in a subgroup, e.g. "/organization/category/repo".
|
||||||
|
$parts = explode('/', trim($path, '/'));
|
||||||
|
if ( count($parts) < 3 ) {
|
||||||
|
throw new \InvalidArgumentException('Invalid GitLab.com repository URL: "' . $repositoryUrl . '"');
|
||||||
|
}
|
||||||
|
$lastPart = array_pop($parts);
|
||||||
|
$this->userName = implode('/', $parts);
|
||||||
|
$this->repositoryName = $lastPart;
|
||||||
|
} else {
|
||||||
|
//There could be subgroups in the URL: gitlab.domain.com/group/subgroup/subgroup2/repository
|
||||||
|
if ( $subgroup !== null ) {
|
||||||
|
$path = str_replace(trailingslashit($subgroup), '', $path);
|
||||||
|
}
|
||||||
|
|
||||||
|
//This is not a traditional url, it could be gitlab is in a deeper subdirectory.
|
||||||
|
//Get the path segments.
|
||||||
|
$segments = explode('/', untrailingslashit(ltrim($path, '/')));
|
||||||
|
|
||||||
|
//We need at least /user-name/repository-name/
|
||||||
|
if ( count($segments) < 2 ) {
|
||||||
|
throw new \InvalidArgumentException('Invalid GitLab repository URL: "' . $repositoryUrl . '"');
|
||||||
|
}
|
||||||
|
|
||||||
|
//Get the username and repository name.
|
||||||
|
$usernameRepo = array_splice($segments, -2, 2);
|
||||||
|
$this->userName = $usernameRepo[0];
|
||||||
|
$this->repositoryName = $usernameRepo[1];
|
||||||
|
|
||||||
|
//Append the remaining segments to the host if there are segments left.
|
||||||
|
if ( count($segments) > 0 ) {
|
||||||
|
$this->repositoryHost = trailingslashit($this->repositoryHost) . implode('/', $segments);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Add subgroups to username.
|
||||||
|
if ( $subgroup !== null ) {
|
||||||
|
$this->userName = $usernameRepo[0] . '/' . untrailingslashit($subgroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::__construct($repositoryUrl, $accessToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the latest release from GitLab.
|
||||||
|
*
|
||||||
|
* @return Reference|null
|
||||||
|
*/
|
||||||
|
public function getLatestRelease() {
|
||||||
|
$releases = $this->api('/:id/releases', array('per_page' => $this->releaseFilterMaxReleases));
|
||||||
|
if ( is_wp_error($releases) || empty($releases) || !is_array($releases) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($releases as $release) {
|
||||||
|
if (
|
||||||
|
//Skip invalid/unsupported releases.
|
||||||
|
!is_object($release)
|
||||||
|
|| !isset($release->tag_name)
|
||||||
|
//Skip upcoming releases.
|
||||||
|
|| (
|
||||||
|
!empty($release->upcoming_release)
|
||||||
|
&& $this->shouldSkipPreReleases()
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$versionNumber = ltrim($release->tag_name, 'v'); //Remove the "v" prefix from "v1.2.3".
|
||||||
|
|
||||||
|
//Apply custom filters.
|
||||||
|
if ( !$this->matchesCustomReleaseFilter($versionNumber, $release) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$downloadUrl = $this->findReleaseDownloadUrl($release);
|
||||||
|
if ( empty($downloadUrl) ) {
|
||||||
|
//The latest release doesn't have valid download URL.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !empty($this->accessToken) ) {
|
||||||
|
$downloadUrl = add_query_arg('private_token', $this->accessToken, $downloadUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Reference(array(
|
||||||
|
'name' => $release->tag_name,
|
||||||
|
'version' => $versionNumber,
|
||||||
|
'downloadUrl' => $downloadUrl,
|
||||||
|
'updated' => $release->released_at,
|
||||||
|
'apiResponse' => $release,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param object $release
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
protected function findReleaseDownloadUrl($release) {
|
||||||
|
if ( $this->releaseAssetsEnabled ) {
|
||||||
|
if ( isset($release->assets, $release->assets->links) ) {
|
||||||
|
//Use the first asset link where the URL matches the filter.
|
||||||
|
foreach ($release->assets->links as $link) {
|
||||||
|
if ( $this->matchesAssetFilter($link) ) {
|
||||||
|
return $link->url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $this->releaseAssetPreference === Api::REQUIRE_RELEASE_ASSETS ) {
|
||||||
|
//Falling back to source archives is not allowed, so give up.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Use the first source code archive that's in ZIP format.
|
||||||
|
foreach ($release->assets->sources as $source) {
|
||||||
|
if ( isset($source->format) && ($source->format === 'zip') ) {
|
||||||
|
return $source->url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tag that looks like the highest version number.
|
||||||
|
*
|
||||||
|
* @return Reference|null
|
||||||
|
*/
|
||||||
|
public function getLatestTag() {
|
||||||
|
$tags = $this->api('/:id/repository/tags');
|
||||||
|
if ( is_wp_error($tags) || empty($tags) || !is_array($tags) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$versionTags = $this->sortTagsByVersion($tags);
|
||||||
|
if ( empty($versionTags) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tag = $versionTags[0];
|
||||||
|
return new Reference(array(
|
||||||
|
'name' => $tag->name,
|
||||||
|
'version' => ltrim($tag->name, 'v'),
|
||||||
|
'downloadUrl' => $this->buildArchiveDownloadUrl($tag->name),
|
||||||
|
'apiResponse' => $tag,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a branch by name.
|
||||||
|
*
|
||||||
|
* @param string $branchName
|
||||||
|
* @return null|Reference
|
||||||
|
*/
|
||||||
|
public function getBranch($branchName) {
|
||||||
|
$branch = $this->api('/:id/repository/branches/' . $branchName);
|
||||||
|
if ( is_wp_error($branch) || empty($branch) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$reference = new Reference(array(
|
||||||
|
'name' => $branch->name,
|
||||||
|
'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name),
|
||||||
|
'apiResponse' => $branch,
|
||||||
|
));
|
||||||
|
|
||||||
|
if ( isset($branch->commit, $branch->commit->committed_date) ) {
|
||||||
|
$reference->updated = $branch->commit->committed_date;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $reference;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the timestamp of the latest commit that changed the specified branch or tag.
|
||||||
|
*
|
||||||
|
* @param string $ref Reference name (e.g. branch or tag).
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
public function getLatestCommitTime($ref) {
|
||||||
|
$commits = $this->api('/:id/repository/commits/', array('ref_name' => $ref));
|
||||||
|
if ( is_wp_error($commits) || !is_array($commits) || !isset($commits[0]) ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $commits[0]->committed_date;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform a GitLab API request.
|
||||||
|
*
|
||||||
|
* @param string $url
|
||||||
|
* @param array $queryParams
|
||||||
|
* @return mixed|\WP_Error
|
||||||
|
*/
|
||||||
|
protected function api($url, $queryParams = array()) {
|
||||||
|
$baseUrl = $url;
|
||||||
|
$url = $this->buildApiUrl($url, $queryParams);
|
||||||
|
|
||||||
|
$options = array('timeout' => wp_doing_cron() ? 10 : 3);
|
||||||
|
if ( !empty($this->httpFilterName) ) {
|
||||||
|
$options = apply_filters($this->httpFilterName, $options);
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = wp_remote_get($url, $options);
|
||||||
|
if ( is_wp_error($response) ) {
|
||||||
|
do_action('puc_api_error', $response, null, $url, $this->slug);
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
$code = wp_remote_retrieve_response_code($response);
|
||||||
|
$body = wp_remote_retrieve_body($response);
|
||||||
|
if ( $code === 200 ) {
|
||||||
|
return json_decode($body);
|
||||||
|
}
|
||||||
|
|
||||||
|
$error = new \WP_Error(
|
||||||
|
'puc-gitlab-http-error',
|
||||||
|
sprintf('GitLab API error. URL: "%s", HTTP status code: %d.', $baseUrl, $code)
|
||||||
|
);
|
||||||
|
do_action('puc_api_error', $error, $response, $url, $this->slug);
|
||||||
|
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build a fully qualified URL for an API request.
|
||||||
|
*
|
||||||
|
* @param string $url
|
||||||
|
* @param array $queryParams
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function buildApiUrl($url, $queryParams) {
|
||||||
|
$variables = array(
|
||||||
|
'user' => $this->userName,
|
||||||
|
'repo' => $this->repositoryName,
|
||||||
|
'id' => $this->userName . '/' . $this->repositoryName,
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($variables as $name => $value) {
|
||||||
|
$url = str_replace("/:{$name}", '/' . urlencode($value), $url);
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = substr($url, 1);
|
||||||
|
$url = sprintf('%1$s://%2$s/api/v4/projects/%3$s', $this->repositoryProtocol, $this->repositoryHost, $url);
|
||||||
|
|
||||||
|
if ( !empty($this->accessToken) ) {
|
||||||
|
$queryParams['private_token'] = $this->accessToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !empty($queryParams) ) {
|
||||||
|
$url = add_query_arg($queryParams, $url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the contents of a file from a specific branch or tag.
|
||||||
|
*
|
||||||
|
* @param string $path File name.
|
||||||
|
* @param string $ref
|
||||||
|
* @return null|string Either the contents of the file, or null if the file doesn't exist or there's an error.
|
||||||
|
*/
|
||||||
|
public function getRemoteFile($path, $ref = 'master') {
|
||||||
|
$response = $this->api('/:id/repository/files/' . $path, array('ref' => $ref));
|
||||||
|
if ( is_wp_error($response) || !isset($response->content) || $response->encoding !== 'base64' ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return base64_decode($response->content);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a URL to download a ZIP archive of the specified branch/tag/etc.
|
||||||
|
*
|
||||||
|
* @param string $ref
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function buildArchiveDownloadUrl($ref = 'master') {
|
||||||
|
$url = sprintf(
|
||||||
|
'%1$s://%2$s/api/v4/projects/%3$s/repository/archive.zip',
|
||||||
|
$this->repositoryProtocol,
|
||||||
|
$this->repositoryHost,
|
||||||
|
urlencode($this->userName . '/' . $this->repositoryName)
|
||||||
|
);
|
||||||
|
$url = add_query_arg('sha', urlencode($ref), $url);
|
||||||
|
|
||||||
|
if ( !empty($this->accessToken) ) {
|
||||||
|
$url = add_query_arg('private_token', $this->accessToken, $url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a specific tag.
|
||||||
|
*
|
||||||
|
* @param string $tagName
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function getTag($tagName) {
|
||||||
|
throw new \LogicException('The ' . __METHOD__ . ' method is not implemented and should not be used.');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getUpdateDetectionStrategies($configBranch) {
|
||||||
|
$strategies = array();
|
||||||
|
|
||||||
|
if ( ($configBranch === 'main') || ($configBranch === 'master') ) {
|
||||||
|
$strategies[self::STRATEGY_LATEST_RELEASE] = array($this, 'getLatestRelease');
|
||||||
|
$strategies[self::STRATEGY_LATEST_TAG] = array($this, 'getLatestTag');
|
||||||
|
}
|
||||||
|
|
||||||
|
$strategies[self::STRATEGY_BRANCH] = function () use ($configBranch) {
|
||||||
|
return $this->getBranch($configBranch);
|
||||||
|
};
|
||||||
|
|
||||||
|
return $strategies;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAuthentication($credentials) {
|
||||||
|
parent::setAuthentication($credentials);
|
||||||
|
$this->accessToken = is_string($credentials) ? $credentials : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use release assets that link to GitLab generic packages (e.g. .zip files)
|
||||||
|
* instead of automatically generated source archives.
|
||||||
|
*
|
||||||
|
* This is included for backwards compatibility with older versions of PUC.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @deprecated Use enableReleaseAssets() instead.
|
||||||
|
* @noinspection PhpUnused -- Public API
|
||||||
|
*/
|
||||||
|
public function enableReleasePackages() {
|
||||||
|
$this->enableReleaseAssets(
|
||||||
|
/** @lang RegExp */ '/\.zip($|[?&#])/i',
|
||||||
|
Api::REQUIRE_RELEASE_ASSETS
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getFilterableAssetName($releaseAsset) {
|
||||||
|
if ( isset($releaseAsset->url) ) {
|
||||||
|
return $releaseAsset->url;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
endif;
|
||||||
@@ -1,21 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v4p4_Vcs_PluginUpdateChecker') ):
|
|
||||||
|
|
||||||
class Puc_v4p4_Vcs_PluginUpdateChecker extends Puc_v4p4_Plugin_UpdateChecker implements Puc_v4p4_Vcs_BaseChecker {
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Vcs;
|
||||||
/**
|
|
||||||
* @var string The branch where to look for updates. Defaults to "master".
|
use YahnisElsts\PluginUpdateChecker\v5p4\Plugin;
|
||||||
*/
|
|
||||||
protected $branch = 'master';
|
if ( !class_exists(PluginUpdateChecker::class, false) ):
|
||||||
|
|
||||||
|
class PluginUpdateChecker extends Plugin\UpdateChecker implements BaseChecker {
|
||||||
|
use VcsCheckerMethods;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Puc_v4p4_Vcs_Api Repository API client.
|
* PluginUpdateChecker constructor.
|
||||||
*/
|
|
||||||
protected $api = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Puc_v4p4_Vcs_PluginUpdateChecker constructor.
|
|
||||||
*
|
*
|
||||||
* @param Puc_v4p4_Vcs_Api $api
|
* @param Api $api
|
||||||
* @param string $pluginFile
|
* @param string $pluginFile
|
||||||
* @param string $slug
|
* @param string $slug
|
||||||
* @param int $checkPeriod
|
* @param int $checkPeriod
|
||||||
@@ -24,10 +21,11 @@ if ( !class_exists('Puc_v4p4_Vcs_PluginUpdateChecker') ):
|
|||||||
*/
|
*/
|
||||||
public function __construct($api, $pluginFile, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
|
public function __construct($api, $pluginFile, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') {
|
||||||
$this->api = $api;
|
$this->api = $api;
|
||||||
$this->api->setHttpFilterName($this->getUniqueName('request_info_options'));
|
|
||||||
|
|
||||||
parent::__construct($api->getRepositoryUrl(), $pluginFile, $slug, $checkPeriod, $optionName, $muPluginFile);
|
parent::__construct($api->getRepositoryUrl(), $pluginFile, $slug, $checkPeriod, $optionName, $muPluginFile);
|
||||||
|
|
||||||
|
$this->api->setHttpFilterName($this->getUniqueName('request_info_options'));
|
||||||
|
$this->api->setStrategyFilterName($this->getUniqueName('vcs_update_detection_strategies'));
|
||||||
$this->api->setSlug($this->slug);
|
$this->api->setSlug($this->slug);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,13 +37,15 @@ if ( !class_exists('Puc_v4p4_Vcs_PluginUpdateChecker') ):
|
|||||||
}
|
}
|
||||||
|
|
||||||
$api = $this->api;
|
$api = $this->api;
|
||||||
$api->setLocalDirectory($this->getAbsoluteDirectoryPath());
|
$api->setLocalDirectory($this->package->getAbsoluteDirectoryPath());
|
||||||
|
|
||||||
$info = new Puc_v4p4_Plugin_Info();
|
$info = new Plugin\PluginInfo();
|
||||||
$info->filename = $this->pluginFile;
|
$info->filename = $this->pluginFile;
|
||||||
$info->slug = $this->slug;
|
$info->slug = $this->slug;
|
||||||
|
|
||||||
$this->setInfoFromHeader($this->getPluginHeader(), $info);
|
$this->setInfoFromHeader($this->package->getPluginHeader(), $info);
|
||||||
|
$this->setIconsFromLocalAssets($info);
|
||||||
|
$this->setBannersFromLocalAssets($info);
|
||||||
|
|
||||||
//Pick a branch or tag.
|
//Pick a branch or tag.
|
||||||
$updateSource = $api->chooseReference($this->branch);
|
$updateSource = $api->chooseReference($this->branch);
|
||||||
@@ -65,7 +65,7 @@ if ( !class_exists('Puc_v4p4_Vcs_PluginUpdateChecker') ):
|
|||||||
//There's probably a network problem or an authentication error.
|
//There's probably a network problem or an authentication error.
|
||||||
do_action(
|
do_action(
|
||||||
'puc_api_error',
|
'puc_api_error',
|
||||||
new WP_Error(
|
new \WP_Error(
|
||||||
'puc-no-update-source',
|
'puc-no-update-source',
|
||||||
'Could not retrieve version information from the repository. '
|
'Could not retrieve version information from the repository. '
|
||||||
. 'This usually means that the update checker either can\'t connect '
|
. 'This usually means that the update checker either can\'t connect '
|
||||||
@@ -81,10 +81,25 @@ if ( !class_exists('Puc_v4p4_Vcs_PluginUpdateChecker') ):
|
|||||||
$mainPluginFile = basename($this->pluginFile);
|
$mainPluginFile = basename($this->pluginFile);
|
||||||
$remotePlugin = $api->getRemoteFile($mainPluginFile, $ref);
|
$remotePlugin = $api->getRemoteFile($mainPluginFile, $ref);
|
||||||
if ( !empty($remotePlugin) ) {
|
if ( !empty($remotePlugin) ) {
|
||||||
$remoteHeader = $this->getFileHeader($remotePlugin);
|
$remoteHeader = $this->package->getFileHeader($remotePlugin);
|
||||||
$this->setInfoFromHeader($remoteHeader, $info);
|
$this->setInfoFromHeader($remoteHeader, $info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Sanity check: Reject updates that don't have a version number.
|
||||||
|
//This can happen when we're using a branch, and we either fail to retrieve the main plugin
|
||||||
|
//file or the file doesn't have a "Version" header.
|
||||||
|
if ( empty($info->version) ) {
|
||||||
|
do_action(
|
||||||
|
'puc_api_error',
|
||||||
|
new \WP_Error(
|
||||||
|
'puc-no-plugin-version',
|
||||||
|
'Could not find the version number in the repository.'
|
||||||
|
),
|
||||||
|
null, null, $this->slug
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
//Try parsing readme.txt. If it's formatted according to WordPress.org standards, it will contain
|
//Try parsing readme.txt. If it's formatted according to WordPress.org standards, it will contain
|
||||||
//a lot of useful information like the required/tested WP version, changelog, and so on.
|
//a lot of useful information like the required/tested WP version, changelog, and so on.
|
||||||
if ( $this->readmeTxtExistsLocally() ) {
|
if ( $this->readmeTxtExistsLocally() ) {
|
||||||
@@ -93,7 +108,7 @@ if ( !class_exists('Puc_v4p4_Vcs_PluginUpdateChecker') ):
|
|||||||
|
|
||||||
//The changelog might be in a separate file.
|
//The changelog might be in a separate file.
|
||||||
if ( empty($info->sections['changelog']) ) {
|
if ( empty($info->sections['changelog']) ) {
|
||||||
$info->sections['changelog'] = $api->getRemoteChangelog($ref, dirname($this->getAbsolutePath()));
|
$info->sections['changelog'] = $api->getRemoteChangelog($ref, $this->package->getAbsoluteDirectoryPath());
|
||||||
if ( empty($info->sections['changelog']) ) {
|
if ( empty($info->sections['changelog']) ) {
|
||||||
$info->sections['changelog'] = __('There is no changelog available.', 'plugin-update-checker');
|
$info->sections['changelog'] = __('There is no changelog available.', 'plugin-update-checker');
|
||||||
}
|
}
|
||||||
@@ -117,18 +132,14 @@ if ( !class_exists('Puc_v4p4_Vcs_PluginUpdateChecker') ):
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
protected function readmeTxtExistsLocally() {
|
protected function readmeTxtExistsLocally() {
|
||||||
$pluginDirectory = $this->getAbsoluteDirectoryPath();
|
return $this->package->fileExists($this->api->getLocalReadmeName());
|
||||||
if ( empty($pluginDirectory) || !is_dir($pluginDirectory) || ($pluginDirectory === '.') ) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return is_file($pluginDirectory . '/' . $this->api->getLocalReadmeName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy plugin metadata from a file header to a Plugin Info object.
|
* Copy plugin metadata from a file header to a Plugin Info object.
|
||||||
*
|
*
|
||||||
* @param array $fileHeader
|
* @param array $fileHeader
|
||||||
* @param Puc_v4p4_Plugin_Info $pluginInfo
|
* @param Plugin\PluginInfo $pluginInfo
|
||||||
*/
|
*/
|
||||||
protected function setInfoFromHeader($fileHeader, $pluginInfo) {
|
protected function setInfoFromHeader($fileHeader, $pluginInfo) {
|
||||||
$headerToPropertyMap = array(
|
$headerToPropertyMap = array(
|
||||||
@@ -143,6 +154,8 @@ if ( !class_exists('Puc_v4p4_Vcs_PluginUpdateChecker') ):
|
|||||||
'Tested WP' => 'tested',
|
'Tested WP' => 'tested',
|
||||||
'Requires at least' => 'requires',
|
'Requires at least' => 'requires',
|
||||||
'Tested up to' => 'tested',
|
'Tested up to' => 'tested',
|
||||||
|
|
||||||
|
'Requires PHP' => 'requires_php',
|
||||||
);
|
);
|
||||||
foreach ($headerToPropertyMap as $headerName => $property) {
|
foreach ($headerToPropertyMap as $headerName => $property) {
|
||||||
if ( isset($fileHeader[$headerName]) && !empty($fileHeader[$headerName]) ) {
|
if ( isset($fileHeader[$headerName]) && !empty($fileHeader[$headerName]) ) {
|
||||||
@@ -159,7 +172,7 @@ if ( !class_exists('Puc_v4p4_Vcs_PluginUpdateChecker') ):
|
|||||||
* Copy plugin metadata from the remote readme.txt file.
|
* Copy plugin metadata from the remote readme.txt file.
|
||||||
*
|
*
|
||||||
* @param string $ref GitHub tag or branch where to look for the readme.
|
* @param string $ref GitHub tag or branch where to look for the readme.
|
||||||
* @param Puc_v4p4_Plugin_Info $pluginInfo
|
* @param Plugin\PluginInfo $pluginInfo
|
||||||
*/
|
*/
|
||||||
protected function setInfoFromRemoteReadme($ref, $pluginInfo) {
|
protected function setInfoFromRemoteReadme($ref, $pluginInfo) {
|
||||||
$readme = $this->api->getRemoteReadme($ref);
|
$readme = $this->api->getRemoteReadme($ref);
|
||||||
@@ -176,41 +189,86 @@ if ( !class_exists('Puc_v4p4_Vcs_PluginUpdateChecker') ):
|
|||||||
if ( !empty($readme['requires_at_least']) ) {
|
if ( !empty($readme['requires_at_least']) ) {
|
||||||
$pluginInfo->requires = $readme['requires_at_least'];
|
$pluginInfo->requires = $readme['requires_at_least'];
|
||||||
}
|
}
|
||||||
|
if ( !empty($readme['requires_php']) ) {
|
||||||
|
$pluginInfo->requires_php = $readme['requires_php'];
|
||||||
|
}
|
||||||
|
|
||||||
if ( isset($readme['upgrade_notice'], $readme['upgrade_notice'][$pluginInfo->version]) ) {
|
if ( isset($readme['upgrade_notice'], $readme['upgrade_notice'][$pluginInfo->version]) ) {
|
||||||
$pluginInfo->upgrade_notice = $readme['upgrade_notice'][$pluginInfo->version];
|
$pluginInfo->upgrade_notice = $readme['upgrade_notice'][$pluginInfo->version];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setBranch($branch) {
|
/**
|
||||||
$this->branch = $branch;
|
* Add icons from the currently installed version to a Plugin Info object.
|
||||||
return $this;
|
*
|
||||||
|
* The icons should be in a subdirectory named "assets". Supported image formats
|
||||||
|
* and file names are described here:
|
||||||
|
* @link https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/#plugin-icons
|
||||||
|
*
|
||||||
|
* @param Plugin\PluginInfo $pluginInfo
|
||||||
|
*/
|
||||||
|
protected function setIconsFromLocalAssets($pluginInfo) {
|
||||||
|
$icons = $this->getLocalAssetUrls(array(
|
||||||
|
'icon.svg' => 'svg',
|
||||||
|
'icon-256x256.png' => '2x',
|
||||||
|
'icon-256x256.jpg' => '2x',
|
||||||
|
'icon-128x128.png' => '1x',
|
||||||
|
'icon-128x128.jpg' => '1x',
|
||||||
|
));
|
||||||
|
|
||||||
|
if ( !empty($icons) ) {
|
||||||
|
//The "default" key seems to be used only as last-resort fallback in WP core (5.8/5.9),
|
||||||
|
//but we'll set it anyway in case some code somewhere needs it.
|
||||||
|
reset($icons);
|
||||||
|
$firstKey = key($icons);
|
||||||
|
$icons['default'] = $icons[$firstKey];
|
||||||
|
|
||||||
|
$pluginInfo->icons = $icons;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAuthentication($credentials) {
|
/**
|
||||||
$this->api->setAuthentication($credentials);
|
* Add banners from the currently installed version to a Plugin Info object.
|
||||||
return $this;
|
*
|
||||||
|
* The banners should be in a subdirectory named "assets". Supported image formats
|
||||||
|
* and file names are described here:
|
||||||
|
* @link https://developer.wordpress.org/plugins/wordpress-org/plugin-assets/#plugin-headers
|
||||||
|
*
|
||||||
|
* @param Plugin\PluginInfo $pluginInfo
|
||||||
|
*/
|
||||||
|
protected function setBannersFromLocalAssets($pluginInfo) {
|
||||||
|
$banners = $this->getLocalAssetUrls(array(
|
||||||
|
'banner-772x250.png' => 'high',
|
||||||
|
'banner-772x250.jpg' => 'high',
|
||||||
|
'banner-1544x500.png' => 'low',
|
||||||
|
'banner-1544x500.jpg' => 'low',
|
||||||
|
));
|
||||||
|
|
||||||
|
if ( !empty($banners) ) {
|
||||||
|
$pluginInfo->banners = $banners;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getVcsApi() {
|
/**
|
||||||
return $this->api;
|
* @param array<string, string> $filesToKeys
|
||||||
}
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
protected function getLocalAssetUrls($filesToKeys) {
|
||||||
|
$assetDirectory = $this->package->getAbsoluteDirectoryPath() . DIRECTORY_SEPARATOR . 'assets';
|
||||||
|
if ( !is_dir($assetDirectory) ) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
$assetBaseUrl = trailingslashit(plugins_url('', $assetDirectory . '/imaginary.file'));
|
||||||
|
|
||||||
public function getUpdate() {
|
$foundAssets = array();
|
||||||
$update = parent::getUpdate();
|
foreach ($filesToKeys as $fileName => $key) {
|
||||||
|
$fullBannerPath = $assetDirectory . DIRECTORY_SEPARATOR . $fileName;
|
||||||
if ( isset($update) && !empty($update->download_url) ) {
|
if ( !isset($icons[$key]) && is_file($fullBannerPath) ) {
|
||||||
$update->download_url = $this->api->signDownloadUrl($update->download_url);
|
$foundAssets[$key] = $assetBaseUrl . $fileName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $update;
|
return $foundAssets;
|
||||||
}
|
|
||||||
|
|
||||||
public function onDisplayConfiguration($panel) {
|
|
||||||
parent::onDisplayConfiguration($panel);
|
|
||||||
$panel->row('Branch', $this->branch);
|
|
||||||
$panel->row('Authentication enabled', $this->api->isAuthenticationEnabled() ? 'Yes' : 'No');
|
|
||||||
$panel->row('API client', get_class($this->api));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
if ( !class_exists('Puc_v4p4_Vcs_Reference', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Vcs;
|
||||||
|
|
||||||
|
if ( !class_exists(Reference::class, false) ):
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a VCS branch or tag. It's intended as a read only, short-lived container
|
* This class represents a VCS branch or tag. It's intended as a read only, short-lived container
|
||||||
@@ -13,7 +15,7 @@ if ( !class_exists('Puc_v4p4_Vcs_Reference', false) ):
|
|||||||
* @property string|null $changelog
|
* @property string|null $changelog
|
||||||
* @property int|null $downloadCount
|
* @property int|null $downloadCount
|
||||||
*/
|
*/
|
||||||
class Puc_v4p4_Vcs_Reference {
|
class Reference {
|
||||||
private $properties = array();
|
private $properties = array();
|
||||||
|
|
||||||
public function __construct($properties = array()) {
|
public function __construct($properties = array()) {
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Vcs;
|
||||||
|
|
||||||
|
if ( !trait_exists(ReleaseAssetSupport::class, false) ) :
|
||||||
|
|
||||||
|
trait ReleaseAssetSupport {
|
||||||
|
/**
|
||||||
|
* @var bool Whether to download release assets instead of the auto-generated
|
||||||
|
* source code archives.
|
||||||
|
*/
|
||||||
|
protected $releaseAssetsEnabled = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string|null Regular expression that's used to filter release assets
|
||||||
|
* by file name or URL. Optional.
|
||||||
|
*/
|
||||||
|
protected $assetFilterRegex = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* How to handle releases that don't have any matching release assets.
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $releaseAssetPreference = Api::PREFER_RELEASE_ASSETS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable updating via release assets.
|
||||||
|
*
|
||||||
|
* If the latest release contains no usable assets, the update checker
|
||||||
|
* will fall back to using the automatically generated ZIP archive.
|
||||||
|
*
|
||||||
|
* @param string|null $nameRegex Optional. Use only those assets where
|
||||||
|
* the file name or URL matches this regex.
|
||||||
|
* @param int $preference Optional. How to handle releases that don't have
|
||||||
|
* any matching release assets.
|
||||||
|
*/
|
||||||
|
public function enableReleaseAssets($nameRegex = null, $preference = Api::PREFER_RELEASE_ASSETS) {
|
||||||
|
$this->releaseAssetsEnabled = true;
|
||||||
|
$this->assetFilterRegex = $nameRegex;
|
||||||
|
$this->releaseAssetPreference = $preference;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable release assets.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @noinspection PhpUnused -- Public API
|
||||||
|
*/
|
||||||
|
public function disableReleaseAssets() {
|
||||||
|
$this->releaseAssetsEnabled = false;
|
||||||
|
$this->assetFilterRegex = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the specified asset match the name regex?
|
||||||
|
*
|
||||||
|
* @param mixed $releaseAsset Data type and structure depend on the host/API.
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function matchesAssetFilter($releaseAsset) {
|
||||||
|
if ( $this->assetFilterRegex === null ) {
|
||||||
|
//The default is to accept all assets.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$name = $this->getFilterableAssetName($releaseAsset);
|
||||||
|
if ( !is_string($name) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (bool)preg_match($this->assetFilterRegex, $releaseAsset->name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the part of asset data that will be checked against the filter regex.
|
||||||
|
*
|
||||||
|
* @param mixed $releaseAsset
|
||||||
|
* @return string|null
|
||||||
|
*/
|
||||||
|
abstract protected function getFilterableAssetName($releaseAsset);
|
||||||
|
}
|
||||||
|
|
||||||
|
endif;
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Vcs;
|
||||||
|
|
||||||
|
if ( !trait_exists(ReleaseFilteringFeature::class, false) ) :
|
||||||
|
|
||||||
|
trait ReleaseFilteringFeature {
|
||||||
|
/**
|
||||||
|
* @var callable|null
|
||||||
|
*/
|
||||||
|
protected $releaseFilterCallback = null;
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $releaseFilterMaxReleases = 1;
|
||||||
|
/**
|
||||||
|
* @var string One of the Api::RELEASE_FILTER_* constants.
|
||||||
|
*/
|
||||||
|
protected $releaseFilterByType = Api::RELEASE_FILTER_SKIP_PRERELEASE;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set a custom release filter.
|
||||||
|
*
|
||||||
|
* Setting a new filter will override the old filter, if any.
|
||||||
|
*
|
||||||
|
* @param callable $callback A callback that accepts a version number and a release
|
||||||
|
* object, and returns a boolean.
|
||||||
|
* @param int $releaseTypes One of the Api::RELEASE_FILTER_* constants.
|
||||||
|
* @param int $maxReleases Optional. The maximum number of recent releases to examine
|
||||||
|
* when trying to find a release that matches the filter. 1 to 100.
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setReleaseFilter(
|
||||||
|
$callback,
|
||||||
|
$releaseTypes = Api::RELEASE_FILTER_SKIP_PRERELEASE,
|
||||||
|
$maxReleases = 20
|
||||||
|
) {
|
||||||
|
if ( $maxReleases > 100 ) {
|
||||||
|
throw new \InvalidArgumentException(sprintf(
|
||||||
|
'The max number of releases is too high (%d). It must be 100 or less.',
|
||||||
|
$maxReleases
|
||||||
|
));
|
||||||
|
} else if ( $maxReleases < 1 ) {
|
||||||
|
throw new \InvalidArgumentException(sprintf(
|
||||||
|
'The max number of releases is too low (%d). It must be at least 1.',
|
||||||
|
$maxReleases
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->releaseFilterCallback = $callback;
|
||||||
|
$this->releaseFilterByType = $releaseTypes;
|
||||||
|
$this->releaseFilterMaxReleases = $maxReleases;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter releases by their version number.
|
||||||
|
*
|
||||||
|
* @param string $regex A regular expression. The release version number must match this regex.
|
||||||
|
* @param int $releaseTypes
|
||||||
|
* @param int $maxReleasesToExamine
|
||||||
|
* @return $this
|
||||||
|
* @noinspection PhpUnused -- Public API
|
||||||
|
*/
|
||||||
|
public function setReleaseVersionFilter(
|
||||||
|
$regex,
|
||||||
|
$releaseTypes = Api::RELEASE_FILTER_SKIP_PRERELEASE,
|
||||||
|
$maxReleasesToExamine = 20
|
||||||
|
) {
|
||||||
|
return $this->setReleaseFilter(
|
||||||
|
function ($versionNumber) use ($regex) {
|
||||||
|
return (preg_match($regex, $versionNumber) === 1);
|
||||||
|
},
|
||||||
|
$releaseTypes,
|
||||||
|
$maxReleasesToExamine
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $versionNumber The detected release version number.
|
||||||
|
* @param object $releaseObject Varies depending on the host/API.
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function matchesCustomReleaseFilter($versionNumber, $releaseObject) {
|
||||||
|
if ( !is_callable($this->releaseFilterCallback) ) {
|
||||||
|
return true; //No custom filter.
|
||||||
|
}
|
||||||
|
return call_user_func($this->releaseFilterCallback, $versionNumber, $releaseObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function shouldSkipPreReleases() {
|
||||||
|
//Maybe this could be a bitfield in the future, if we need to support
|
||||||
|
//more release types.
|
||||||
|
return ($this->releaseFilterByType !== Api::RELEASE_FILTER_ALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function hasCustomReleaseFilter() {
|
||||||
|
return isset($this->releaseFilterCallback) && is_callable($this->releaseFilterCallback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
endif;
|
||||||
@@ -1,22 +1,19 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( !class_exists('Puc_v4p4_Vcs_ThemeUpdateChecker', false) ):
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Vcs;
|
||||||
|
|
||||||
class Puc_v4p4_Vcs_ThemeUpdateChecker extends Puc_v4p4_Theme_UpdateChecker implements Puc_v4p4_Vcs_BaseChecker {
|
use YahnisElsts\PluginUpdateChecker\v5p4\Theme;
|
||||||
/**
|
use YahnisElsts\PluginUpdateChecker\v5p4\Utils;
|
||||||
* @var string The branch where to look for updates. Defaults to "master".
|
|
||||||
*/
|
if ( !class_exists(ThemeUpdateChecker::class, false) ):
|
||||||
protected $branch = 'master';
|
|
||||||
|
class ThemeUpdateChecker extends Theme\UpdateChecker implements BaseChecker {
|
||||||
|
use VcsCheckerMethods;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Puc_v4p4_Vcs_Api Repository API client.
|
* ThemeUpdateChecker constructor.
|
||||||
*/
|
|
||||||
protected $api = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Puc_v4p4_Vcs_ThemeUpdateChecker constructor.
|
|
||||||
*
|
*
|
||||||
* @param Puc_v4p4_Vcs_Api $api
|
* @param Api $api
|
||||||
* @param null $stylesheet
|
* @param null $stylesheet
|
||||||
* @param null $customSlug
|
* @param null $customSlug
|
||||||
* @param int $checkPeriod
|
* @param int $checkPeriod
|
||||||
@@ -24,18 +21,19 @@ if ( !class_exists('Puc_v4p4_Vcs_ThemeUpdateChecker', false) ):
|
|||||||
*/
|
*/
|
||||||
public function __construct($api, $stylesheet = null, $customSlug = null, $checkPeriod = 12, $optionName = '') {
|
public function __construct($api, $stylesheet = null, $customSlug = null, $checkPeriod = 12, $optionName = '') {
|
||||||
$this->api = $api;
|
$this->api = $api;
|
||||||
$this->api->setHttpFilterName($this->getUniqueName('request_update_options'));
|
|
||||||
|
|
||||||
parent::__construct($api->getRepositoryUrl(), $stylesheet, $customSlug, $checkPeriod, $optionName);
|
parent::__construct($api->getRepositoryUrl(), $stylesheet, $customSlug, $checkPeriod, $optionName);
|
||||||
|
|
||||||
|
$this->api->setHttpFilterName($this->getUniqueName('request_update_options'));
|
||||||
|
$this->api->setStrategyFilterName($this->getUniqueName('vcs_update_detection_strategies'));
|
||||||
$this->api->setSlug($this->slug);
|
$this->api->setSlug($this->slug);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function requestUpdate() {
|
public function requestUpdate() {
|
||||||
$api = $this->api;
|
$api = $this->api;
|
||||||
$api->setLocalDirectory($this->getAbsoluteDirectoryPath());
|
$api->setLocalDirectory($this->package->getAbsoluteDirectoryPath());
|
||||||
|
|
||||||
$update = new Puc_v4p4_Theme_Update();
|
$update = new Theme\Update();
|
||||||
$update->slug = $this->slug;
|
$update->slug = $this->slug;
|
||||||
|
|
||||||
//Figure out which reference (tag or branch) we'll use to get the latest version of the theme.
|
//Figure out which reference (tag or branch) we'll use to get the latest version of the theme.
|
||||||
@@ -46,7 +44,7 @@ if ( !class_exists('Puc_v4p4_Vcs_ThemeUpdateChecker', false) ):
|
|||||||
} else {
|
} else {
|
||||||
do_action(
|
do_action(
|
||||||
'puc_api_error',
|
'puc_api_error',
|
||||||
new WP_Error(
|
new \WP_Error(
|
||||||
'puc-no-update-source',
|
'puc-no-update-source',
|
||||||
'Could not retrieve version information from the repository. '
|
'Could not retrieve version information from the repository. '
|
||||||
. 'This usually means that the update checker either can\'t connect '
|
. 'This usually means that the update checker either can\'t connect '
|
||||||
@@ -59,16 +57,16 @@ if ( !class_exists('Puc_v4p4_Vcs_ThemeUpdateChecker', false) ):
|
|||||||
|
|
||||||
//Get headers from the main stylesheet in this branch/tag. Its "Version" header and other metadata
|
//Get headers from the main stylesheet in this branch/tag. Its "Version" header and other metadata
|
||||||
//are what the WordPress install will actually see after upgrading, so they take precedence over releases/tags.
|
//are what the WordPress install will actually see after upgrading, so they take precedence over releases/tags.
|
||||||
$remoteHeader = $this->getFileHeader($api->getRemoteFile('style.css', $ref));
|
$remoteHeader = $this->package->getFileHeader($api->getRemoteFile('style.css', $ref));
|
||||||
$update->version = Puc_v4p4_Utils::findNotEmpty(array(
|
$update->version = Utils::findNotEmpty(array(
|
||||||
$remoteHeader['Version'],
|
$remoteHeader['Version'],
|
||||||
Puc_v4p4_Utils::get($updateSource, 'version'),
|
Utils::get($updateSource, 'version'),
|
||||||
));
|
));
|
||||||
|
|
||||||
//The details URL defaults to the Theme URI header or the repository URL.
|
//The details URL defaults to the Theme URI header or the repository URL.
|
||||||
$update->details_url = Puc_v4p4_Utils::findNotEmpty(array(
|
$update->details_url = Utils::findNotEmpty(array(
|
||||||
$remoteHeader['ThemeURI'],
|
$remoteHeader['ThemeURI'],
|
||||||
$this->theme->get('ThemeURI'),
|
$this->package->getHeaderValue('ThemeURI'),
|
||||||
$this->metadataUrl,
|
$this->metadataUrl,
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -80,39 +78,6 @@ if ( !class_exists('Puc_v4p4_Vcs_ThemeUpdateChecker', false) ):
|
|||||||
$update = $this->filterUpdateResult($update);
|
$update = $this->filterUpdateResult($update);
|
||||||
return $update;
|
return $update;
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIXME: This is duplicated code. Both theme and plugin subclasses that use VCS share these methods.
|
|
||||||
|
|
||||||
public function setBranch($branch) {
|
|
||||||
$this->branch = $branch;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setAuthentication($credentials) {
|
|
||||||
$this->api->setAuthentication($credentials);
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getVcsApi() {
|
|
||||||
return $this->api;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUpdate() {
|
|
||||||
$update = parent::getUpdate();
|
|
||||||
|
|
||||||
if ( isset($update) && !empty($update->download_url) ) {
|
|
||||||
$update->download_url = $this->api->signDownloadUrl($update->download_url);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $update;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function onDisplayConfiguration($panel) {
|
|
||||||
parent::onDisplayConfiguration($panel);
|
|
||||||
$panel->row('Branch', $this->branch);
|
|
||||||
$panel->row('Authentication enabled', $this->api->isAuthenticationEnabled() ? 'Yes' : 'No');
|
|
||||||
$panel->row('API client', get_class($this->api));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
endif;
|
endif;
|
||||||
59
plugin-update-checker-5.4/Puc/v5p4/Vcs/VcsCheckerMethods.php
Normal file
59
plugin-update-checker-5.4/Puc/v5p4/Vcs/VcsCheckerMethods.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4\Vcs;
|
||||||
|
|
||||||
|
if ( !trait_exists(VcsCheckerMethods::class, false) ) :
|
||||||
|
|
||||||
|
trait VcsCheckerMethods {
|
||||||
|
/**
|
||||||
|
* @var string The branch where to look for updates. Defaults to "master".
|
||||||
|
*/
|
||||||
|
protected $branch = 'master';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Api Repository API client.
|
||||||
|
*/
|
||||||
|
protected $api = null;
|
||||||
|
|
||||||
|
public function setBranch($branch) {
|
||||||
|
$this->branch = $branch;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set authentication credentials.
|
||||||
|
*
|
||||||
|
* @param array|string $credentials
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setAuthentication($credentials) {
|
||||||
|
$this->api->setAuthentication($credentials);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Api
|
||||||
|
*/
|
||||||
|
public function getVcsApi() {
|
||||||
|
return $this->api;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUpdate() {
|
||||||
|
$update = parent::getUpdate();
|
||||||
|
|
||||||
|
if ( isset($update) && !empty($update->download_url) ) {
|
||||||
|
$update->download_url = $this->api->signDownloadUrl($update->download_url);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $update;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function onDisplayConfiguration($panel) {
|
||||||
|
parent::onDisplayConfiguration($panel);
|
||||||
|
$panel->row('Branch', $this->branch);
|
||||||
|
$panel->row('Authentication enabled', $this->api->isAuthenticationEnabled() ? 'Yes' : 'No');
|
||||||
|
$panel->row('API client', get_class($this->api));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
endif;
|
||||||
84
plugin-update-checker-5.4/Puc/v5p4/WpCliCheckTrigger.php
Normal file
84
plugin-update-checker-5.4/Puc/v5p4/WpCliCheckTrigger.php
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YahnisElsts\PluginUpdateChecker\v5p4;
|
||||||
|
|
||||||
|
use WP_CLI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Triggers an update check when relevant WP-CLI commands are executed.
|
||||||
|
*
|
||||||
|
* When WP-CLI runs certain commands like "wp plugin status" or "wp theme list", it calls
|
||||||
|
* wp_update_plugins() and wp_update_themes() to refresh update information. This class hooks into
|
||||||
|
* the same commands and triggers an update check when they are executed.
|
||||||
|
*
|
||||||
|
* Note that wp_update_plugins() and wp_update_themes() do not perform an update check *every* time
|
||||||
|
* they are called. They use a context-dependent delay between update checks. Similarly, this class
|
||||||
|
* calls Scheduler::maybeCheckForUpdates(), which also dynamically decides whether to actually
|
||||||
|
* run a check. If you want to force an update check, call UpdateChecker::checkForUpdates() instead.
|
||||||
|
*/
|
||||||
|
class WpCliCheckTrigger {
|
||||||
|
/**
|
||||||
|
* @var Scheduler
|
||||||
|
*/
|
||||||
|
private $scheduler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string 'plugin' or 'theme'
|
||||||
|
*/
|
||||||
|
private $componentType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool Whether an update check was already triggered during the current request
|
||||||
|
* or script execution.
|
||||||
|
*/
|
||||||
|
private $wasCheckTriggered = false;
|
||||||
|
|
||||||
|
public function __construct($componentType, Scheduler $scheduler) {
|
||||||
|
if ( !in_array($componentType, ['plugin', 'theme']) ) {
|
||||||
|
throw new \InvalidArgumentException('Invalid component type. Must be "plugin" or "theme".');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->componentType = $componentType;
|
||||||
|
$this->scheduler = $scheduler;
|
||||||
|
|
||||||
|
if ( !defined('WP_CLI') || !class_exists(WP_CLI::class, false) ) {
|
||||||
|
return; //Nothing to do if WP-CLI is not available.
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We can't hook directly into wp_update_plugins(), but we can hook into the WP-CLI
|
||||||
|
* commands that call it. We'll use the "before_invoke:xyz" hook to trigger update checks.
|
||||||
|
*/
|
||||||
|
foreach ($this->getRelevantCommands() as $command) {
|
||||||
|
WP_CLI::add_hook('before_invoke:' . $command, [$this, 'triggerUpdateCheckOnce']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getRelevantCommands() {
|
||||||
|
$result = [];
|
||||||
|
foreach (['status', 'list', 'update'] as $subcommand) {
|
||||||
|
$result[] = $this->componentType . ' ' . $subcommand;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trigger a potential update check once.
|
||||||
|
*
|
||||||
|
* @param mixed $input
|
||||||
|
* @return mixed The input value, unchanged.
|
||||||
|
* @internal This method is public so that it can be used as a WP-CLI hook callback.
|
||||||
|
* It should not be called directly.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function triggerUpdateCheckOnce($input = null) {
|
||||||
|
if ( $this->wasCheckTriggered ) {
|
||||||
|
return $input;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->wasCheckTriggered = true;
|
||||||
|
$this->scheduler->maybeCheckForUpdates();
|
||||||
|
|
||||||
|
return $input;
|
||||||
|
}
|
||||||
|
}
|
||||||
372
plugin-update-checker-5.4/README.md
Normal file
372
plugin-update-checker-5.4/README.md
Normal file
@@ -0,0 +1,372 @@
|
|||||||
|
Plugin Update Checker
|
||||||
|
=====================
|
||||||
|
|
||||||
|
This is a custom update checker library for WordPress plugins and themes. It lets you add automatic update notifications and one-click upgrades to your commercial plugins, private themes, and so on. All you need to do is put your plugin/theme details in a JSON file, place the file on your server, and pass the URL to the library. The library periodically checks the URL to see if there's a new version available and displays an update notification to the user if necessary.
|
||||||
|
|
||||||
|
From the users' perspective, it works just like with plugins and themes hosted on WordPress.org. The update checker uses the default upgrade UI that is familiar to most WordPress users.
|
||||||
|
|
||||||
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
||||||
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
||||||
|
**Table of Contents**
|
||||||
|
|
||||||
|
- [Getting Started](#getting-started)
|
||||||
|
- [Self-hosted Plugins and Themes](#self-hosted-plugins-and-themes)
|
||||||
|
- [How to Release an Update](#how-to-release-an-update)
|
||||||
|
- [Notes](#notes)
|
||||||
|
- [GitHub Integration](#github-integration)
|
||||||
|
- [How to Release an Update](#how-to-release-an-update-1)
|
||||||
|
- [Notes](#notes-1)
|
||||||
|
- [BitBucket Integration](#bitbucket-integration)
|
||||||
|
- [How to Release an Update](#how-to-release-an-update-2)
|
||||||
|
- [GitLab Integration](#gitlab-integration)
|
||||||
|
- [How to Release a GitLab Update](#how-to-release-a-gitlab-update)
|
||||||
|
- [Migrating from 4.x](#migrating-from-4x)
|
||||||
|
- [License Management](#license-management)
|
||||||
|
- [Resources](#resources)
|
||||||
|
|
||||||
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||||
|
|
||||||
|
Getting Started
|
||||||
|
---------------
|
||||||
|
|
||||||
|
*Note:* In each of the below examples, part of the instructions are to create an instance of the update checker class. It's recommended to do this either during the `plugins_loaded` action or outside of any hooks. If you do it only during an `admin_*` action, then updates will not be visible to a wide variety of WordPress maanagement tools; they will only be visible to logged-in users on dashboard pages.
|
||||||
|
|
||||||
|
### Self-hosted Plugins and Themes
|
||||||
|
|
||||||
|
1. Download [the latest release](https://github.com/YahnisElsts/plugin-update-checker/releases/latest) and copy the `plugin-update-checker` directory to your plugin or theme.
|
||||||
|
2. Go to the `examples` subdirectory and open the .json file that fits your project type. Replace the placeholder data with your plugin/theme details.
|
||||||
|
- Plugin example:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"name" : "Plugin Name",
|
||||||
|
"version" : "2.0",
|
||||||
|
"download_url" : "https://example.com/plugin-name-2.0.zip",
|
||||||
|
"sections" : {
|
||||||
|
"description" : "Plugin description here. You can use HTML."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This is a minimal example that leaves out optional fields. See [this table](https://docs.google.com/spreadsheets/d/1eOBbW7Go2qEQXReOOCdidMTf_tDYRq4JfegcO1CBPIs/edit?usp=sharing) for a full list of supported fields and their descriptions.
|
||||||
|
- Theme example:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"version": "2.0",
|
||||||
|
"details_url": "https://example.com/version-2.0-details.html",
|
||||||
|
"download_url": "https://example.com/example-theme-2.0.zip"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This is actually a complete example that shows all theme-related fields. `version` and `download_url` should be self-explanatory. The `details_url` key specifies the page that the user will see if they click the "View version 1.2.3 details" link in an update notification.
|
||||||
|
3. Upload the JSON file to a publicly accessible location.
|
||||||
|
4. Add the following code to the main plugin file or to the `functions.php` file:
|
||||||
|
|
||||||
|
```php
|
||||||
|
require 'path/to/plugin-update-checker/plugin-update-checker.php';
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
|
||||||
|
|
||||||
|
$myUpdateChecker = PucFactory::buildUpdateChecker(
|
||||||
|
'https://example.com/path/to/details.json',
|
||||||
|
__FILE__, //Full path to the main plugin file or functions.php.
|
||||||
|
'unique-plugin-or-theme-slug'
|
||||||
|
);
|
||||||
|
```
|
||||||
|
Note: If you're using the Composer autoloader, you don't need to explicitly `require` the library.
|
||||||
|
|
||||||
|
#### How to Release an Update
|
||||||
|
|
||||||
|
Change the `version` number in the JSON file and make sure that `download_url` points to the latest version. Update the other fields if necessary. Tip: You can use [wp-update-server](https://github.com/YahnisElsts/wp-update-server) to automate this process.
|
||||||
|
|
||||||
|
By default, the library will check the specified URL for changes every 12 hours. You can force it to check immediately by clicking the "Check for updates" link on the "Plugins" page (it's next to the "Visit plugin site" link). Themes don't have that link, but you can also trigger an update check like this:
|
||||||
|
|
||||||
|
1. Install [Debug Bar](https://srd.wordpress.org/plugins/debug-bar/).
|
||||||
|
2. Click the "Debug" menu in the Admin Bar (a.k.a Toolbar).
|
||||||
|
3. Open the "PUC (your-slug)" panel.
|
||||||
|
4. Click the "Check Now" button.
|
||||||
|
|
||||||
|
#### Notes
|
||||||
|
- The second argument passed to `buildUpdateChecker` must be the absolute path to the main plugin file or any file in the theme directory. If you followed the "getting started" instructions, you can just use the `__FILE__` constant.
|
||||||
|
- The third argument - i.e. the slug - is optional but recommended. In most cases, the slug should be the same as the name of your plugin directory. For example, if your plugin lives in `/wp-content/plugins/my-plugin`, set the slug to `my-plugin`. If the slug is omitted, the update checker will use the name of the main plugin file as the slug (e.g. `my-cool-plugin.php` → `my-cool-plugin`). This can lead to conflicts if your plugin has a generic file name like `plugin.php`.
|
||||||
|
|
||||||
|
This doesn't affect themes because PUC uses the theme directory name as the default slug. Still, if you're planning to use the slug in your own code - e.g. to filter updates or override update checker behaviour - it can be a good idea to set it explicitly.
|
||||||
|
|
||||||
|
### GitHub Integration
|
||||||
|
|
||||||
|
1. Download [the latest release](https://github.com/YahnisElsts/plugin-update-checker/releases/latest) and copy the `plugin-update-checker` directory to your plugin or theme.
|
||||||
|
2. Add the following code to the main plugin file or `functions.php`:
|
||||||
|
|
||||||
|
```php
|
||||||
|
require 'plugin-update-checker/plugin-update-checker.php';
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
|
||||||
|
|
||||||
|
$myUpdateChecker = PucFactory::buildUpdateChecker(
|
||||||
|
'https://github.com/user-name/repo-name/',
|
||||||
|
__FILE__,
|
||||||
|
'unique-plugin-or-theme-slug'
|
||||||
|
);
|
||||||
|
|
||||||
|
//Set the branch that contains the stable release.
|
||||||
|
$myUpdateChecker->setBranch('stable-branch-name');
|
||||||
|
|
||||||
|
//Optional: If you're using a private repository, specify the access token like this:
|
||||||
|
$myUpdateChecker->setAuthentication('your-token-here');
|
||||||
|
```
|
||||||
|
3. Plugins only: Add a `readme.txt` file formatted according to the [WordPress.org plugin readme standard](https://wordpress.org/plugins/readme.txt) to your repository. The contents of this file will be shown when the user clicks the "View version 1.2.3 details" link.
|
||||||
|
|
||||||
|
#### How to Release an Update
|
||||||
|
|
||||||
|
This library supports a couple of different ways to release updates on GitHub. Pick the one that best fits your workflow.
|
||||||
|
|
||||||
|
- **GitHub releases**
|
||||||
|
|
||||||
|
Create a new release using the "Releases" feature on GitHub. The tag name and release title don't matter. The description is optional, but if you do provide one, it will be displayed when the user clicks the "View version x.y.z details" link on the "Plugins" page. Note that PUC ignores releases marked as "This is a pre-release".
|
||||||
|
|
||||||
|
If you want to use release assets, call the `enableReleaseAssets()` method after creating the update checker instance:
|
||||||
|
```php
|
||||||
|
$myUpdateChecker->getVcsApi()->enableReleaseAssets();
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Tags**
|
||||||
|
|
||||||
|
To release version 1.2.3, create a new Git tag named `v1.2.3` or `1.2.3`. That's it.
|
||||||
|
|
||||||
|
PUC doesn't require strict adherence to [SemVer](https://semver.org/). These are all valid tag names: `v1.2.3`, `v1.2-foo`, `1.2.3_rc1-ABC`, `1.2.3.4.5`. However, be warned that it's not smart enough to filter out alpha/beta/RC versions. If that's a problem, you might want to use GitHub releases or branches instead.
|
||||||
|
|
||||||
|
- **Stable branch**
|
||||||
|
|
||||||
|
Point the update checker at a stable, production-ready branch:
|
||||||
|
```php
|
||||||
|
$updateChecker->setBranch('branch-name');
|
||||||
|
```
|
||||||
|
PUC will periodically check the `Version` header in the main plugin file or `style.css` and display a notification if it's greater than the installed version.
|
||||||
|
|
||||||
|
Caveat: If you set the branch to `master` (the default), the update checker will look for recent releases and tags first. It'll only use the `master` branch if it doesn't find anything else suitable.
|
||||||
|
|
||||||
|
#### Notes
|
||||||
|
|
||||||
|
The library will pull update details from the following parts of a release/tag/branch:
|
||||||
|
|
||||||
|
- Version number
|
||||||
|
- The "Version" plugin header.
|
||||||
|
- The latest GitHub release or tag name.
|
||||||
|
- Changelog
|
||||||
|
- The "Changelog" section of `readme.txt`.
|
||||||
|
- One of the following files:
|
||||||
|
CHANGES.md, CHANGELOG.md, changes.md, changelog.md
|
||||||
|
- GitHub release notes.
|
||||||
|
- Required and tested WordPress versions
|
||||||
|
- The "Requires at least" and "Tested up to" fields in `readme.txt`.
|
||||||
|
- The following plugin headers:
|
||||||
|
`Required WP`, `Tested WP`, `Requires at least`, `Tested up to`
|
||||||
|
- "Last updated" timestamp
|
||||||
|
- The creation timestamp of the latest GitHub release.
|
||||||
|
- The latest commit in the selected tag or branch.
|
||||||
|
- Number of downloads
|
||||||
|
- The `download_count` statistic of the latest release.
|
||||||
|
- If you're not using GitHub releases, there will be no download stats.
|
||||||
|
- Other plugin details - author, homepage URL, description
|
||||||
|
- The "Description" section of `readme.txt`.
|
||||||
|
- Remote plugin headers (i.e. the latest version on GitHub).
|
||||||
|
- Local plugin headers (i.e. the currently installed version).
|
||||||
|
- Ratings, banners, screenshots
|
||||||
|
- Not supported.
|
||||||
|
|
||||||
|
### BitBucket Integration
|
||||||
|
|
||||||
|
1. Download [the latest release](https://github.com/YahnisElsts/plugin-update-checker/releases/latest) and copy the `plugin-update-checker` directory to your plugin or theme.
|
||||||
|
2. Add the following code to the main plugin file or `functions.php`:
|
||||||
|
|
||||||
|
```php
|
||||||
|
require 'plugin-update-checker/plugin-update-checker.php';
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
|
||||||
|
|
||||||
|
$myUpdateChecker = PucFactory::buildUpdateChecker(
|
||||||
|
'https://bitbucket.org/user-name/repo-name',
|
||||||
|
__FILE__,
|
||||||
|
'unique-plugin-or-theme-slug'
|
||||||
|
);
|
||||||
|
|
||||||
|
//Optional: If you're using a private repository, create an OAuth consumer
|
||||||
|
//and set the authentication credentials like this:
|
||||||
|
//Note: For now you need to check "This is a private consumer" when
|
||||||
|
//creating the consumer to work around #134:
|
||||||
|
// https://github.com/YahnisElsts/plugin-update-checker/issues/134
|
||||||
|
$myUpdateChecker->setAuthentication(array(
|
||||||
|
'consumer_key' => '...',
|
||||||
|
'consumer_secret' => '...',
|
||||||
|
));
|
||||||
|
|
||||||
|
//Optional: Set the branch that contains the stable release.
|
||||||
|
$myUpdateChecker->setBranch('stable-branch-name');
|
||||||
|
```
|
||||||
|
3. Optional: Add a `readme.txt` file formatted according to the [WordPress.org plugin readme standard](https://wordpress.org/plugins/readme.txt) to your repository. For plugins, the contents of this file will be shown when the user clicks the "View version 1.2.3 details" link.
|
||||||
|
|
||||||
|
#### How to Release an Update
|
||||||
|
|
||||||
|
BitBucket doesn't have an equivalent to GitHub's releases, so the process is slightly different. You can use any of the following approaches:
|
||||||
|
|
||||||
|
- **`Stable tag` header**
|
||||||
|
|
||||||
|
This is the recommended approach if you're using tags to mark each version. Add a `readme.txt` file formatted according to the [WordPress.org plugin readme standard](https://wordpress.org/plugins/readme.txt) to your repository. Set the "stable tag" header to the tag that represents the latest release. Example:
|
||||||
|
```text
|
||||||
|
Stable tag: v1.2.3
|
||||||
|
```
|
||||||
|
The tag doesn't have to start with a "v" or follow any particular format. You can use any name you like as long as it's a valid Git tag.
|
||||||
|
|
||||||
|
Tip: If you explicitly set a stable branch, the update checker will look for a `readme.txt` in that branch. Otherwise it will only look at the `master` branch.
|
||||||
|
|
||||||
|
- **Tags**
|
||||||
|
|
||||||
|
You can skip the "stable tag" bit and just create a new Git tag named `v1.2.3` or `1.2.3`. The update checker will look at the most recent tags and pick the one that looks like the highest version number.
|
||||||
|
|
||||||
|
PUC doesn't require strict adherence to [SemVer](https://semver.org/). These are all valid tag names: `v1.2.3`, `v1.2-foo`, `1.2.3_rc1-ABC`, `1.2.3.4.5`. However, be warned that it's not smart enough to filter out alpha/beta/RC versions.
|
||||||
|
|
||||||
|
- **Stable branch**
|
||||||
|
|
||||||
|
Point the update checker at a stable, production-ready branch:
|
||||||
|
```php
|
||||||
|
$updateChecker->setBranch('branch-name');
|
||||||
|
```
|
||||||
|
PUC will periodically check the `Version` header in the main plugin file or `style.css` and display a notification if it's greater than the installed version. Caveat: If you set the branch to `master`, the update checker will still look for tags first.
|
||||||
|
|
||||||
|
### GitLab Integration
|
||||||
|
|
||||||
|
1. Download [the latest release](https://github.com/YahnisElsts/plugin-update-checker/releases/latest) and copy the `plugin-update-checker` directory to your plugin or theme.
|
||||||
|
2. Add the following code to the main plugin file or `functions.php` and define how you want to check for updates from Gitlab (refer to: [Gitlab: How to Release an Update](#how-to-release-a-gitlab-update)):
|
||||||
|
|
||||||
|
```php
|
||||||
|
require 'plugin-update-checker/plugin-update-checker.php';
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
|
||||||
|
|
||||||
|
$myUpdateChecker = PucFactory::buildUpdateChecker(
|
||||||
|
'https://gitlab.com/user-name/repo-name/',
|
||||||
|
__FILE__,
|
||||||
|
'unique-plugin-or-theme-slug'
|
||||||
|
);
|
||||||
|
|
||||||
|
//Optional: If you're using a private repository, specify the access token like this:
|
||||||
|
$myUpdateChecker->setAuthentication('your-token-here');
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively, if you're using a self-hosted GitLab instance, initialize the update checker like this:
|
||||||
|
```php
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\Vcs\PluginUpdateChecker;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\Vcs\GitLabApi;
|
||||||
|
|
||||||
|
$myUpdateChecker = new PluginUpdateChecker(
|
||||||
|
new GitLabApi('https://myserver.com/user-name/repo-name/'),
|
||||||
|
__FILE__,
|
||||||
|
'unique-plugin-or-theme-slug'
|
||||||
|
);
|
||||||
|
//Optional: Add setAuthentication(...) and setBranch(...) as shown above.
|
||||||
|
```
|
||||||
|
If you're using a self-hosted GitLab instance and [subgroups or nested groups](https://docs.gitlab.com/ce/user/group/subgroups/index.html), you have to tell the update checker which parts of the URL are subgroups:
|
||||||
|
```php
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\Vcs\PluginUpdateChecker;
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5p4\Vcs\GitLabApi;
|
||||||
|
|
||||||
|
$myUpdateChecker = new PluginUpdateChecker(
|
||||||
|
new GitLabApi(
|
||||||
|
'https://myserver.com/group-name/subgroup-level1/subgroup-level2/subgroup-level3/repo-name/',
|
||||||
|
null,
|
||||||
|
'subgroup-level1/subgroup-level2/subgroup-level3'
|
||||||
|
),
|
||||||
|
__FILE__,
|
||||||
|
'unique-plugin-or-theme-slug'
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Plugins only: Add a `readme.txt` file formatted according to the [WordPress.org plugin readme standard](https://wordpress.org/plugins/readme.txt) to your repository. The contents of this file will be shown when the user clicks the "View version 1.2.3 details" link.
|
||||||
|
|
||||||
|
#### How to Release a GitLab Update
|
||||||
|
|
||||||
|
A GitLab repository can be checked for updates in 3 different ways.
|
||||||
|
|
||||||
|
- **GitLab releases**
|
||||||
|
|
||||||
|
Create a new release using the "Releases" feature on GitLab. The tag name should match the version number. You can add a `v` prefix to the tag, like `v1.2.3`. Releases that are marked as ["Upcoming Release"](https://docs.gitlab.com/ee/user/project/releases/index.html#upcoming-releases) will be automatically ignored.
|
||||||
|
|
||||||
|
If you want to use custom release assets, call the `enableReleaseAssets()` method after creating the update checker instance:
|
||||||
|
```php
|
||||||
|
$myUpdateChecker->getVcsApi()->enableReleaseAssets();
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, PUC will use the first available asset link, regardless of type. You can pass a regular expression to `enableReleaseAssets()` to make it pick the first link where the URL matches the regex. For example:
|
||||||
|
```php
|
||||||
|
$myUpdateChecker->getVcsApi()->enableReleaseAssets('/\.zip($|[?&#])/i');
|
||||||
|
```
|
||||||
|
|
||||||
|
**Tip:** You can use a Gitlab CI/CD Pipeline to automatically generate your update on release using a Generic Package. For more information about generic packages, refer to the following links:
|
||||||
|
- [Gitlab CI/CD Release Documentation](https://docs.gitlab.com/ee/user/project/releases/#create-release-from-gitlab-ci)
|
||||||
|
- [Gitlab Release Assets as Generic Package Documentation](https://gitlab.com/gitlab-org/release-cli/-/tree/master/docs/examples/release-assets-as-generic-package/)
|
||||||
|
- [Example .gitlab-ci.yml file using Release Generic Packages for generating a update package from the Sensei-LMS wordpress plugin](https://gist.github.com/timwiel/9dfd3526c768efad4973254085e065ce)
|
||||||
|
|
||||||
|
- **Tags**
|
||||||
|
|
||||||
|
To release version 1.2.3, create a new Git tag named `v1.2.3` or `1.2.3`. The update checker will look at recent tags and use the one that looks like the highest version number.
|
||||||
|
|
||||||
|
PUC doesn't require strict adherence to [SemVer](https://semver.org/). However, be warned that it's not smart enough to filter out alpha/beta/RC versions. If that's a problem, you might want to use GitLab branches instead.
|
||||||
|
|
||||||
|
- **Stable branch**
|
||||||
|
|
||||||
|
Point the update checker at any stable, production-ready branch:
|
||||||
|
```php
|
||||||
|
$myUpdateChecker->setBranch('stable-branch-name');
|
||||||
|
```
|
||||||
|
PUC will periodically check the `Version` header in the main plugin file or `style.css` and display a notification if it's greater than the installed version. Caveat: Even if you set the branch to `main` (the default) or `master` (the historical default), the update checker will still look for recent releases and tags first.
|
||||||
|
|
||||||
|
Migrating from 4.x
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Older versions of the library didn't use namespaces. Code that was written for those versions will need to be updated to work with the current version. At a minimum, you'll need to change the factory class name.
|
||||||
|
|
||||||
|
Old code:
|
||||||
|
```php
|
||||||
|
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
|
||||||
|
'https://example.com/info.json',
|
||||||
|
__FILE__,
|
||||||
|
'my-slug'
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
New code:
|
||||||
|
```php
|
||||||
|
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
|
||||||
|
|
||||||
|
$myUpdateChecker = PucFactory::buildUpdateChecker(
|
||||||
|
'https://example.com/info.json',
|
||||||
|
__FILE__,
|
||||||
|
'my-slug'
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
Other classes have also been renamed, usually by simply removing the `Puc_vXpY_` prefix and converting `Category_Thing` to `Category\Thing`. Here's a table of the most commonly used classes and their new names:
|
||||||
|
|
||||||
|
| Old class name | New class name |
|
||||||
|
|-------------------------------------|----------------------------------------------------------------|
|
||||||
|
| `Puc_v4_Factory` | `YahnisElsts\PluginUpdateChecker\v5\PucFactory` |
|
||||||
|
| `Puc_v4p13_Factory` | `YahnisElsts\PluginUpdateChecker\v5p4\PucFactory` |
|
||||||
|
| `Puc_v4p13_Plugin_UpdateChecker` | `YahnisElsts\PluginUpdateChecker\v5p4\Plugin\UpdateChecker` |
|
||||||
|
| `Puc_v4p13_Theme_UpdateChecker` | `YahnisElsts\PluginUpdateChecker\v5p4\Theme\UpdateChecker` |
|
||||||
|
| `Puc_v4p13_Vcs_PluginUpdateChecker` | `YahnisElsts\PluginUpdateChecker\v5p4\Vcs\PluginUpdateChecker` |
|
||||||
|
| `Puc_v4p13_Vcs_ThemeUpdateChecker` | `YahnisElsts\PluginUpdateChecker\v5p4\Vcs\ThemeUpdateChecker` |
|
||||||
|
| `Puc_v4p13_Vcs_GitHubApi` | `YahnisElsts\PluginUpdateChecker\v5p4\Vcs\GitHubApi` |
|
||||||
|
| `Puc_v4p13_Vcs_GitLabApi` | `YahnisElsts\PluginUpdateChecker\v5p4\Vcs\GitLabApi` |
|
||||||
|
| `Puc_v4p13_Vcs_BitBucketApi` | `YahnisElsts\PluginUpdateChecker\v5p4\Vcs\BitBucketApi` |
|
||||||
|
|
||||||
|
License Management
|
||||||
|
------------------
|
||||||
|
|
||||||
|
Currently, the update checker doesn't have any built-in license management features. It only provides some hooks that you can use to, for example, append license keys to update requests (`$updateChecker->addQueryArgFilter()`). If you're looking for ways to manage and verify licenses, please post your feedback in [this issue](https://github.com/YahnisElsts/plugin-update-checker/issues/222).
|
||||||
|
|
||||||
|
Resources
|
||||||
|
---------
|
||||||
|
|
||||||
|
- [This blog post](https://w-shadow.com/blog/2010/09/02/automatic-updates-for-any-plugin/) has more information about the update checker API. *Slightly out of date.*
|
||||||
|
- [Debug Bar](https://wordpress.org/plugins/debug-bar/) - useful for testing and debugging the update checker.
|
||||||
|
- [Update format reference](https://docs.google.com/spreadsheets/d/1eOBbW7Go2qEQXReOOCdidMTf_tDYRq4JfegcO1CBPIs/edit?usp=sharing) - describes all fields supported by the JSON-based update information format used by the update checker. Only covers plugins. Themes use a similar but more limited format.
|
||||||
|
- [Securing download links](https://w-shadow.com/blog/2013/03/19/plugin-updates-securing-download-links/) - a general overview.
|
||||||
|
- [A GUI for entering download credentials](https://open-tools.net/documentation/tutorial-automatic-updates.html#wordpress)
|
||||||
|
- [Theme Update Checker](https://w-shadow.com/blog/2011/06/02/automatic-updates-for-commercial-themes/) - an older, theme-only variant of this update checker.
|
||||||
23
plugin-update-checker-5.4/composer.json
Normal file
23
plugin-update-checker-5.4/composer.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"name": "yahnis-elsts/plugin-update-checker",
|
||||||
|
"type": "library",
|
||||||
|
"description": "A custom update checker for WordPress plugins and themes. Useful if you can't host your plugin in the official WP repository but still want it to support automatic updates.",
|
||||||
|
"keywords": ["wordpress", "plugin updates", "automatic updates", "theme updates"],
|
||||||
|
"homepage": "https://github.com/YahnisElsts/plugin-update-checker/",
|
||||||
|
"license": "MIT",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Yahnis Elsts",
|
||||||
|
"email": "whiteshadow@w-shadow.com",
|
||||||
|
"homepage": "https://w-shadow.com/",
|
||||||
|
"role": "Developer"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.6.20",
|
||||||
|
"ext-json": "*"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"files": ["load-v5p4.php"]
|
||||||
|
}
|
||||||
|
}
|
||||||
70
plugin-update-checker-5.4/css/puc-debug-bar.css
Normal file
70
plugin-update-checker-5.4/css/puc-debug-bar.css
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
.puc-debug-bar-panel-v5 pre {
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Style the debug data table to match "widefat" table style used by WordPress. */
|
||||||
|
table.puc-debug-data {
|
||||||
|
width: 100%;
|
||||||
|
clear: both;
|
||||||
|
margin: 0;
|
||||||
|
|
||||||
|
border-spacing: 0;
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
|
||||||
|
border-radius: 3px;
|
||||||
|
border: 1px solid #dfdfdf;
|
||||||
|
border-collapse: separate;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.puc-debug-data * {
|
||||||
|
word-wrap: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.puc-debug-data th {
|
||||||
|
width: 11em;
|
||||||
|
padding: 7px 7px 8px;
|
||||||
|
text-align: left;
|
||||||
|
|
||||||
|
font-family: "Georgia", "Times New Roman", "Bitstream Charter", "Times", serif;
|
||||||
|
font-weight: 400;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 1.3em;
|
||||||
|
text-shadow: rgba(255, 255, 255, 0.804) 0 1px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.puc-debug-data td, table.puc-debug-data th {
|
||||||
|
border-width: 1px 0;
|
||||||
|
border-style: solid;
|
||||||
|
|
||||||
|
border-top-color: #fff;
|
||||||
|
border-bottom-color: #dfdfdf;
|
||||||
|
|
||||||
|
text-transform: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
table.puc-debug-data td {
|
||||||
|
color: #555;
|
||||||
|
font-size: 12px;
|
||||||
|
padding: 4px 7px 2px;
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
|
||||||
|
.puc-ajax-response {
|
||||||
|
border: 1px solid #dfdfdf;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 0.5em;
|
||||||
|
margin: 5px 0;
|
||||||
|
background-color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.puc-ajax-nonce {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.puc-ajax-response dt {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.puc-ajax-response dd {
|
||||||
|
margin: 0 0 1em;
|
||||||
|
}
|
||||||
54
plugin-update-checker-5.4/js/debug-bar.js
Normal file
54
plugin-update-checker-5.4/js/debug-bar.js
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
jQuery(function($) {
|
||||||
|
|
||||||
|
function runAjaxAction(button, action) {
|
||||||
|
button = $(button);
|
||||||
|
var panel = button.closest('.puc-debug-bar-panel-v5');
|
||||||
|
var responseBox = button.closest('td').find('.puc-ajax-response');
|
||||||
|
|
||||||
|
responseBox.text('Processing...').show();
|
||||||
|
$.post(
|
||||||
|
ajaxurl,
|
||||||
|
{
|
||||||
|
action : action,
|
||||||
|
uid : panel.data('uid'),
|
||||||
|
_wpnonce: panel.data('nonce')
|
||||||
|
},
|
||||||
|
function(data) {
|
||||||
|
//The response contains HTML that should already be escaped in server-side code.
|
||||||
|
//phpcs:ignore WordPressVIPMinimum.JS.HTMLExecutingFunctions.html
|
||||||
|
responseBox.html(data);
|
||||||
|
},
|
||||||
|
'html'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.puc-debug-bar-panel-v5 input[name="puc-check-now-button"]').on('click', function() {
|
||||||
|
runAjaxAction(this, 'puc_v5_debug_check_now');
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.puc-debug-bar-panel-v5 input[name="puc-request-info-button"]').on('click', function() {
|
||||||
|
runAjaxAction(this, 'puc_v5_debug_request_info');
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// Debug Bar uses the panel class name as part of its link and container IDs. This means we can
|
||||||
|
// end up with multiple identical IDs if more than one plugin uses the update checker library.
|
||||||
|
// Fix it by replacing the class name with the plugin slug.
|
||||||
|
var panels = $('#debug-menu-targets').find('.puc-debug-bar-panel-v5');
|
||||||
|
panels.each(function() {
|
||||||
|
var panel = $(this);
|
||||||
|
var uid = panel.data('uid');
|
||||||
|
var target = panel.closest('.debug-menu-target');
|
||||||
|
|
||||||
|
//Change the panel wrapper ID.
|
||||||
|
target.attr('id', 'debug-menu-target-puc-' + uid);
|
||||||
|
|
||||||
|
//Change the menu link ID as well and point it at the new target ID.
|
||||||
|
$('#debug-bar-menu').find('.puc-debug-menu-link-' + uid)
|
||||||
|
.closest('.debug-menu-link')
|
||||||
|
.attr('id', 'debug-menu-link-puc-' + uid)
|
||||||
|
.attr('href', '#' + target.attr('id'));
|
||||||
|
});
|
||||||
|
});
|
||||||
BIN
plugin-update-checker-5.4/languages/plugin-update-checker-ca.mo
Normal file
BIN
plugin-update-checker-5.4/languages/plugin-update-checker-ca.mo
Normal file
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-11-24 17:02+0200\n"
|
||||||
|
"PO-Revision-Date: 2019-09-25 18:15+0200\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.2.3\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language: ca\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Comprova si hi ha actualitzacions"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "L’extensió %s està actualitzada."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Una nova versió de l’extensió %s està disponible."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "No s’ha pogut determinar si hi ha actualitzacions per a %s."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Estat del comprovador d’actualitzacions desconegut \"%s\""
|
||||||
|
|
||||||
|
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "No hi ha cap registre de canvis disponible."
|
||||||
Binary file not shown.
@@ -0,0 +1,45 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"POT-Creation-Date: 2017-05-20 10:53+0300\n"
|
||||||
|
"PO-Revision-Date: 2017-07-05 15:39+0000\n"
|
||||||
|
"Last-Translator: Vojtěch Sajdl <vojtech@sajdl.com>\n"
|
||||||
|
"Language-Team: Czech (Czech Republic)\n"
|
||||||
|
"Language: cs-CZ\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Loco-Source-Locale: cs_CZ\n"
|
||||||
|
"X-Generator: Loco - https://localise.biz/\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
"X-Loco-Parser: loco_parse_po"
|
||||||
|
|
||||||
|
#: Puc/v4p1/Plugin/UpdateChecker.php:358
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Zkontrolovat aktualizace"
|
||||||
|
|
||||||
|
#: Puc/v4p1/Plugin/UpdateChecker.php:405
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "Plugin %s je aktuální."
|
||||||
|
|
||||||
|
#: Puc/v4p1/Plugin/UpdateChecker.php:407
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Nová verze pluginu %s je dostupná."
|
||||||
|
|
||||||
|
#: Puc/v4p1/Plugin/UpdateChecker.php:409
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Neznámý status kontroly aktualizací \"%s\""
|
||||||
|
|
||||||
|
#: Puc/v4p1/Vcs/PluginUpdateChecker.php:83
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "Changelog není dostupný."
|
||||||
Binary file not shown.
@@ -0,0 +1,42 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-05-20 10:53+0300\n"
|
||||||
|
"PO-Revision-Date: 2017-10-17 11:07+0200\n"
|
||||||
|
"Last-Translator: Mikk3lRo\n"
|
||||||
|
"Language-Team: Mikk3lRo\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.0.4\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Language: da_DK\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p1/Plugin/UpdateChecker.php:358
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Undersøg for opdateringer"
|
||||||
|
|
||||||
|
#: Puc/v4p1/Plugin/UpdateChecker.php:405
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "Plugin'et %s er allerede opdateret."
|
||||||
|
|
||||||
|
#: Puc/v4p1/Plugin/UpdateChecker.php:407
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "En ny version af plugin'et %s er tilgængelig."
|
||||||
|
|
||||||
|
#: Puc/v4p1/Plugin/UpdateChecker.php:409
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Ukendt opdateringsstatus: \"%s\""
|
||||||
|
|
||||||
|
#: Puc/v4p1/Vcs/PluginUpdateChecker.php:83
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "Der er ingen ændringslog tilgængelig."
|
||||||
Binary file not shown.
@@ -0,0 +1,38 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2016-06-29 20:21+0100\n"
|
||||||
|
"PO-Revision-Date: 2016-06-29 20:23+0100\n"
|
||||||
|
"Last-Translator: Igor Lückel <info@igorlueckel.de>\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 1.8.1\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e\n"
|
||||||
|
"Language: de_DE\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: github-checker.php:137
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "Es ist keine Liste von Programmänderungen verfügbar."
|
||||||
|
|
||||||
|
#: plugin-update-checker.php:852
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Nach Update suchen"
|
||||||
|
|
||||||
|
#: plugin-update-checker.php:896
|
||||||
|
msgid "This plugin is up to date."
|
||||||
|
msgstr "Das Plugin ist aktuell."
|
||||||
|
|
||||||
|
#: plugin-update-checker.php:898
|
||||||
|
msgid "A new version of this plugin is available."
|
||||||
|
msgstr "Es ist eine neue Version für das Plugin verfügbar."
|
||||||
|
|
||||||
|
#: plugin-update-checker.php:900
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Unbekannter Update Status \"%s\""
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-11-24 17:02+0200\n"
|
||||||
|
"PO-Revision-Date: 2020-03-21 15:13-0400\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.3\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language: es_ES\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Comprobar si hay actualizaciones"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "El plugin %s está actualizado."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Una nueva versión del %s plugin está disponible."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "No se pudo determinar si hay actualizaciones disponibles para %s."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Estado del comprobador de actualización desconocido «%s»"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "No hay un registro de cambios disponible."
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-11-24 17:02+0200\n"
|
||||||
|
"PO-Revision-Date: 2020-03-21 15:14-0400\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.3\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language: es_ES\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Comprobar si hay actualizaciones"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "El plugin %s está actualizado."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Una nueva versión del %s plugin está disponible."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "No se pudo determinar si hay actualizaciones disponibles para %s."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Estado del comprobador de actualización desconocido «%s»"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "No hay un registro de cambios disponible."
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-11-24 17:02+0200\n"
|
||||||
|
"PO-Revision-Date: 2020-03-21 15:14-0400\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.3\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language: es_ES\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Comprobar si hay actualizaciones"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "El plugin %s está actualizado."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Una nueva versión del %s plugin está disponible."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "No se pudo determinar si hay actualizaciones disponibles para %s."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Estado del comprobador de actualización desconocido «%s»"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "No hay un registro de cambios disponible."
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-11-24 17:02+0200\n"
|
||||||
|
"PO-Revision-Date: 2020-03-21 15:14-0400\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.3\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language: es_ES\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Comprobar si hay actualizaciones"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "El plugin %s está actualizado."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Una nueva versión del %s plugin está disponible."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "No se pudo determinar si hay actualizaciones disponibles para %s."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Estado del comprobador de actualización desconocido «%s»"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "No hay un registro de cambios disponible."
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-11-24 17:02+0200\n"
|
||||||
|
"PO-Revision-Date: 2020-03-21 15:14-0400\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.3\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language: es_ES\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Comprobar si hay actualizaciones"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "El plugin %s está actualizado."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Una nueva versión del %s plugin está disponible."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "No se pudo determinar si hay actualizaciones disponibles para %s."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Estado del comprobador de actualización desconocido «%s»"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "No hay un registro de cambios disponible."
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-11-24 17:02+0200\n"
|
||||||
|
"PO-Revision-Date: 2020-03-21 14:56-0400\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.3\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language: es_ES\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Comprobar si hay actualizaciones"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "El plugin %s está actualizado."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Una nueva versión del %s plugin está disponible."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "No se pudo determinar si hay actualizaciones disponibles para %s."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Estado del comprobador de actualización desconocido «%s»"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "No hay un registro de cambios disponible."
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-11-24 17:02+0200\n"
|
||||||
|
"PO-Revision-Date: 2020-03-21 15:14-0400\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.3\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language: es_ES\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Comprobar si hay actualizaciones"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "El plugin %s está actualizado."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Una nueva versión del %s plugin está disponible."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "No se pudo determinar si hay actualizaciones disponibles para %s."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Estado del comprobador de actualización desconocido «%s»"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "No hay un registro de cambios disponible."
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-11-24 17:02+0200\n"
|
||||||
|
"PO-Revision-Date: 2020-03-21 15:14-0400\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.3\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language: es_ES\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Comprobar si hay actualizaciones"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "El plugin %s está actualizado."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Una nueva versión del %s plugin está disponible."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "No se pudo determinar si hay actualizaciones disponibles para %s."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Estado del comprobador de actualización desconocido «%s»"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "No hay un registro de cambios disponible."
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-11-24 17:02+0200\n"
|
||||||
|
"PO-Revision-Date: 2020-03-21 14:57-0400\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.3\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language: es_ES\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Comprobar si hay actualizaciones"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "El plugin %s está actualizado."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Una nueva versión del %s plugin está disponible."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "No se pudo determinar si hay actualizaciones disponibles para %s."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Estado del comprobador de actualización desconocido «%s»"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "No hay un registro de cambios disponible."
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-11-24 17:02+0200\n"
|
||||||
|
"PO-Revision-Date: 2020-03-21 15:15-0400\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.3\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language: es_ES\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Comprobar si hay actualizaciones"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "El plugin %s está actualizado."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Una nueva versión del %s plugin está disponible."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "No se pudo determinar si hay actualizaciones disponibles para %s."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Estado del comprobador de actualización desconocido «%s»"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "No hay un registro de cambios disponible."
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-11-24 17:02+0200\n"
|
||||||
|
"PO-Revision-Date: 2020-03-21 15:15-0400\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.3\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language: es_ES\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Comprobar si hay actualizaciones"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "El plugin %s está actualizado."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Una nueva versión del %s plugin está disponible."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "No se pudo determinar si hay actualizaciones disponibles para %s."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Estado del comprobador de actualización desconocido «%s»"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "No hay un registro de cambios disponible."
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-11-24 17:02+0200\n"
|
||||||
|
"PO-Revision-Date: 2020-03-21 15:15-0400\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.3\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language: es_ES\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Comprobar si hay actualizaciones"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "El plugin %s está actualizado."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Una nueva versión del %s plugin está disponible."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "No se pudo determinar si hay actualizaciones disponibles para %s."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Estado del comprobador de actualización desconocido «%s»"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "No hay un registro de cambios disponible."
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-11-24 17:02+0200\n"
|
||||||
|
"PO-Revision-Date: 2020-03-21 14:57-0400\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.3\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language: es_ES\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Comprobar si hay actualizaciones"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "El plugin %s está actualizado."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Una nueva versión del %s plugin está disponible."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "No se pudo determinar si hay actualizaciones disponibles para %s."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Estado del comprobador de actualización desconocido «%s»"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "No hay un registro de cambios disponible."
|
||||||
Binary file not shown.
@@ -0,0 +1,38 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2016-02-17 14:21+0100\n"
|
||||||
|
"PO-Revision-Date: 2016-10-28 14:30+0330\n"
|
||||||
|
"Last-Translator: studio RVOLA <hello@rvola.com>\n"
|
||||||
|
"Language-Team: Pro Style <info@prostyle.ir>\n"
|
||||||
|
"Language: fa_IR\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 1.8.8\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: github-checker.php:120
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "شرحی برای تغییرات یافت نشد"
|
||||||
|
|
||||||
|
#: plugin-update-checker.php:637
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "بررسی برای بروزرسانی "
|
||||||
|
|
||||||
|
#: plugin-update-checker.php:681
|
||||||
|
msgid "This plugin is up to date."
|
||||||
|
msgstr "شما از آخرین نسخه استفاده میکنید . بهروز باشید"
|
||||||
|
|
||||||
|
#: plugin-update-checker.php:683
|
||||||
|
msgid "A new version of this plugin is available."
|
||||||
|
msgstr "نسخه جدیدی برای افزونه ارائه شده است ."
|
||||||
|
|
||||||
|
#: plugin-update-checker.php:685
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "وضعیت ناشناخته برای بروزرسانی \"%s\""
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-11-24 17:02+0200\n"
|
||||||
|
"PO-Revision-Date: 2018-02-12 10:32-0500\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.0.4\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: Eric Gagnon <eric.gagnon@banq.qc.ca>\n"
|
||||||
|
"Language: fr_CA\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Vérifier les mises à jour"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "L’extension %s est à jour."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Une nouvelle version de l’extension %s est disponible."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "Impossible de déterminer si une mise à jour est disponible pour \"%s\""
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Un problème inconnu est survenu \"%s\""
|
||||||
|
|
||||||
|
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "Il n’y a aucun journal de mise à jour disponible."
|
||||||
Binary file not shown.
@@ -0,0 +1,42 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-07-07 14:53+0200\n"
|
||||||
|
"PO-Revision-Date: 2017-07-07 14:54+0200\n"
|
||||||
|
"Language-Team: studio RVOLA <http://www.rvola.com>\n"
|
||||||
|
"Language: fr_FR\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.0.2\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: Nicolas GEHIN\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p1/Plugin/UpdateChecker.php:358
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Vérifier les mises à jour"
|
||||||
|
|
||||||
|
#: Puc/v4p1/Plugin/UpdateChecker.php:405
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "L’extension %s est à jour."
|
||||||
|
|
||||||
|
#: Puc/v4p1/Plugin/UpdateChecker.php:407
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Une nouvelle version de l’extension %s est disponible."
|
||||||
|
|
||||||
|
#: Puc/v4p1/Plugin/UpdateChecker.php:409
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Un problème inconnu est survenu \"%s\""
|
||||||
|
|
||||||
|
#: Puc/v4p1/Vcs/PluginUpdateChecker.php:85
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "Il n’y a aucun journal de mise à jour disponible."
|
||||||
Binary file not shown.
@@ -0,0 +1,41 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2016-01-11 21:23+0100\n"
|
||||||
|
"PO-Revision-Date: 2016-01-11 21:25+0100\n"
|
||||||
|
"Last-Translator: Tamás András Horváth <htomy92@gmail.com>\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"Language: hu_HU\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 1.8.6\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: github-checker.php:137
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "Nem érhető el a changelog."
|
||||||
|
|
||||||
|
#: plugin-update-checker.php:852
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Frissítés ellenőrzése"
|
||||||
|
|
||||||
|
#: plugin-update-checker.php:896
|
||||||
|
msgid "This plugin is up to date."
|
||||||
|
msgstr "Ez a plugin naprakész."
|
||||||
|
|
||||||
|
#: plugin-update-checker.php:898
|
||||||
|
msgid "A new version of this plugin is available."
|
||||||
|
msgstr "Új verzió érhető el a kiegészítőhöz"
|
||||||
|
|
||||||
|
#: plugin-update-checker.php:900
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Ismeretlen a frissítés ellenőrző státusza \"%s\""
|
||||||
|
|
||||||
|
#~ msgid "Every %d hours"
|
||||||
|
#~ msgstr "Minden %d órában"
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2020-08-08 14:36+0300\n"
|
||||||
|
"PO-Revision-Date: 2022-05-20 00:17+0200\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 3.0\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: d79\n"
|
||||||
|
"Language: it_IT\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p11/Plugin/Ui.php:128
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Verifica aggiornamenti"
|
||||||
|
|
||||||
|
#: Puc/v4p11/Plugin/Ui.php:213
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "Il plugin %s è aggiornato."
|
||||||
|
|
||||||
|
#: Puc/v4p11/Plugin/Ui.php:215
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Una nuova versione del plugin %s è disponibile."
|
||||||
|
|
||||||
|
#: Puc/v4p11/Plugin/Ui.php:217
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "Non è possibile verificare se c'è un aggiornamento disponibile per %s."
|
||||||
|
|
||||||
|
#: Puc/v4p11/Plugin/Ui.php:223
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Stato di controllo aggiornamenti sconosciuto \"%s\""
|
||||||
|
|
||||||
|
#: Puc/v4p11/Vcs/PluginUpdateChecker.php:98
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "Non c'è alcun registro delle modifiche disponibile."
|
||||||
BIN
plugin-update-checker-5.4/languages/plugin-update-checker-ja.mo
Normal file
BIN
plugin-update-checker-5.4/languages/plugin-update-checker-ja.mo
Normal file
Binary file not shown.
@@ -0,0 +1,57 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: \n"
|
||||||
|
"POT-Creation-Date: 2019-07-15 17:07+0900\n"
|
||||||
|
"PO-Revision-Date: 2019-07-15 17:12+0900\n"
|
||||||
|
"Last-Translator: tak <tak7725@gmail.com>\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"Language: ja_JP\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 2.2.3\n"
|
||||||
|
"X-Poedit-Basepath: ../../../../../../Applications/XAMPP/xamppfiles/htdocs/"
|
||||||
|
"kisagai/wordpress/wp-content/plugins/simple-stripe-gateway/Puc\n"
|
||||||
|
"Plural-Forms: nplurals=1; plural=0;\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_x:1,2c\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: v4p7/Plugin/Ui.php:54
|
||||||
|
msgid "View details"
|
||||||
|
msgstr "詳細を表示"
|
||||||
|
|
||||||
|
#: v4p7/Plugin/Ui.php:77
|
||||||
|
#, php-format
|
||||||
|
msgid "More information about %s"
|
||||||
|
msgstr "%sについての詳細"
|
||||||
|
|
||||||
|
#: v4p7/Plugin/Ui.php:128
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "アップデートを確認"
|
||||||
|
|
||||||
|
#: v4p7/Plugin/Ui.php:213
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "%s プラグインは、最新バージョンです。"
|
||||||
|
|
||||||
|
#: v4p7/Plugin/Ui.php:215
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "%s プラグインの最新バージョンがあります。"
|
||||||
|
|
||||||
|
#: v4p7/Plugin/Ui.php:217
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "%s のアップデートがあるかどうかを判断できませんでした。"
|
||||||
|
|
||||||
|
#: v4p7/Plugin/Ui.php:223
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "バージョンアップの確認で想定外の状態になりました。ステータス:”%s”"
|
||||||
|
|
||||||
|
#: v4p7/Vcs/PluginUpdateChecker.php:98
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "更新履歴はありません。"
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2018-03-25 18:15+0200\n"
|
||||||
|
"PO-Revision-Date: 2018-03-25 18:32+0200\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 1.8.7.1\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: Frank Goossens <frank@optimizingmatters.com>\n"
|
||||||
|
"Language: nl_BE\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Controleer op nieuwe versies"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "De meest recente %s versie is geïnstalleerd."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Er is een nieuwe versie van %s beschikbaar."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "Kon niet bepalen of er nieuwe versie van %s beschikbaar is."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Ongekende status bij controle op nieuwe versie: \"%s\""
|
||||||
|
|
||||||
|
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "Er is geen changelog beschikbaar."
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2018-03-25 18:15+0200\n"
|
||||||
|
"PO-Revision-Date: 2018-03-25 18:32+0200\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 1.8.7.1\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n"
|
||||||
|
"Last-Translator: Frank Goossens <frank@optimizingmatters.com>\n"
|
||||||
|
"Language: nl_NL\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:395
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Controleer op nieuwe versies"
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:548
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "De meest recente %s versie is geïnstalleerd."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:550
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Er is een nieuwe versie van %s beschikbaar."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:552
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "Could not determine if updates are available for %s."
|
||||||
|
msgstr "Kon niet bepalen of er nieuwe versie van %s beschikbaar is."
|
||||||
|
|
||||||
|
#: Puc/v4p3/Plugin/UpdateChecker.php:558
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Ongekende status bij controle op nieuwe versie: \"%s\""
|
||||||
|
|
||||||
|
#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "Er is geen changelog beschikbaar."
|
||||||
Binary file not shown.
@@ -0,0 +1,48 @@
|
|||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: plugin-update-checker\n"
|
||||||
|
"POT-Creation-Date: 2017-05-19 15:41-0300\n"
|
||||||
|
"PO-Revision-Date: 2017-05-19 15:42-0300\n"
|
||||||
|
"Last-Translator: \n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"Language: pt_BR\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"X-Generator: Poedit 1.8.8\n"
|
||||||
|
"X-Poedit-Basepath: ..\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
|
||||||
|
"X-Poedit-SourceCharset: UTF-8\n"
|
||||||
|
"X-Poedit-KeywordsList: __;_e;_x;_x:1,2c\n"
|
||||||
|
"X-Poedit-SearchPath-0: .\n"
|
||||||
|
|
||||||
|
#: Puc/v4p1/Plugin/UpdateChecker.php:358
|
||||||
|
msgid "Check for updates"
|
||||||
|
msgstr "Verificar Atualizações"
|
||||||
|
|
||||||
|
#: Puc/v4p1/Plugin/UpdateChecker.php:401 Puc/v4p1/Plugin/UpdateChecker.php:406
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "The %s plugin is up to date."
|
||||||
|
msgstr "O plugin %s já está na sua versão mais recente."
|
||||||
|
|
||||||
|
#: Puc/v4p1/Plugin/UpdateChecker.php:408
|
||||||
|
#, php-format
|
||||||
|
msgctxt "the plugin title"
|
||||||
|
msgid "A new version of the %s plugin is available."
|
||||||
|
msgstr "Há uma nova versão para o plugin %s disponível para download."
|
||||||
|
|
||||||
|
#: Puc/v4p1/Plugin/UpdateChecker.php:410
|
||||||
|
#, php-format
|
||||||
|
msgid "Unknown update checker status \"%s\""
|
||||||
|
msgstr "Status \"%s\" desconhecido."
|
||||||
|
|
||||||
|
#: Puc/v4p1/Vcs/PluginUpdateChecker.php:83
|
||||||
|
msgid "There is no changelog available."
|
||||||
|
msgstr "Não há um changelog disponível."
|
||||||
|
|
||||||
|
#~ msgid "The %s plugin is up to date."
|
||||||
|
#~ msgstr "O plugin %s já está na sua versão mais recente."
|
||||||
|
|
||||||
|
#~ msgid "A new version of the %s plugin is available."
|
||||||
|
#~ msgstr "Há uma nova versão para o plugin %s disponível para download."
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user