From 50a0e2a534d25ee0deb033aa940e8be36a66e075 Mon Sep 17 00:00:00 2001 From: Seaton Jiang Date: Sun, 4 Oct 2020 17:48:00 +0800 Subject: [PATCH] feat: update theme checker --- inc/update-checker/Puc/v4/Factory.php | 2 +- .../Puc/{v4p9 => v4p10}/Autoloader.php | 22 ++- .../{v4p9 => v4p10}/DebugBar/Extension.php | 25 ++- .../Puc/{v4p9 => v4p10}/DebugBar/Panel.php | 6 +- .../DebugBar/PluginExtension.php | 8 +- .../{v4p9 => v4p10}/DebugBar/PluginPanel.php | 6 +- .../{v4p9 => v4p10}/DebugBar/ThemePanel.php | 6 +- .../Puc/{v4p9 => v4p10}/Factory.php | 69 ++++++- .../Puc/{v4p9 => v4p10}/InstalledPackage.php | 6 +- .../Puc/{v4p9 => v4p10}/Metadata.php | 4 +- .../Puc/{v4p9 => v4p10}/OAuthSignature.php | 4 +- .../Puc/{v4p9 => v4p10}/Plugin/Info.php | 6 +- .../Puc/{v4p9 => v4p10}/Plugin/Package.php | 10 +- .../Puc/{v4p9 => v4p10}/Plugin/Ui.php | 20 +- .../Puc/{v4p9 => v4p10}/Plugin/Update.php | 20 +- .../{v4p9 => v4p10}/Plugin/UpdateChecker.php | 50 +++-- .../Puc/{v4p9 => v4p10}/Scheduler.php | 44 ++++- .../Puc/{v4p9 => v4p10}/StateStore.php | 18 +- .../Puc/{v4p9 => v4p10}/Theme/Package.php | 4 +- .../Puc/{v4p9 => v4p10}/Theme/Update.php | 8 +- .../{v4p9 => v4p10}/Theme/UpdateChecker.php | 30 ++- .../Puc/{v4p9 => v4p10}/Update.php | 4 +- .../Puc/{v4p9 => v4p10}/UpdateChecker.php | 171 ++++++++++++++---- .../Puc/{v4p9 => v4p10}/UpgraderStatus.php | 4 +- .../Puc/{v4p9 => v4p10}/Utils.php | 4 +- .../Puc/{v4p9 => v4p10}/Vcs/Api.php | 18 +- .../Puc/{v4p9 => v4p10}/Vcs/BaseChecker.php | 8 +- .../Puc/{v4p9 => v4p10}/Vcs/BitBucketApi.php | 28 +-- .../Puc/{v4p9 => v4p10}/Vcs/GitHubApi.php | 26 +-- .../Puc/{v4p9 => v4p10}/Vcs/GitLabApi.php | 22 +-- .../Vcs/PluginUpdateChecker.php | 27 +-- .../Puc/{v4p9 => v4p10}/Vcs/Reference.php | 4 +- .../Vcs/ThemeUpdateChecker.php | 22 +-- inc/update-checker/autoload.php | 28 +-- inc/update-checker/css/puc-debug-bar.css | 0 inc/update-checker/js/debug-bar.js | 0 .../languages/plugin-update-checker-zh_CN.mo | Bin 0 -> 1060 bytes .../languages/plugin-update-checker-zh_CN.po | 48 +++++ .../languages/plugin-update-checker.pot | 49 +++++ inc/update-checker/vendor/Parsedown.php | 0 inc/update-checker/vendor/ParsedownLegacy.php | 0 inc/update-checker/vendor/ParsedownModern.php | 0 inc/update-checker/vendor/PucReadmeParser.php | 7 + 43 files changed, 593 insertions(+), 245 deletions(-) mode change 100644 => 100755 inc/update-checker/Puc/v4/Factory.php rename inc/update-checker/Puc/{v4p9 => v4p10}/Autoloader.php (66%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/DebugBar/Extension.php (86%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/DebugBar/Panel.php (96%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/DebugBar/PluginExtension.php (72%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/DebugBar/PluginPanel.php (80%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/DebugBar/ThemePanel.php (66%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Factory.php (81%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/InstalledPackage.php (95%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Metadata.php (97%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/OAuthSignature.php (96%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Plugin/Info.php (95%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Plugin/Package.php (94%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Plugin/Ui.php (91%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Plugin/Update.php (81%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Plugin/UpdateChecker.php (89%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Scheduler.php (84%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/StateStore.php (89%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Theme/Package.php (92%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Theme/Update.php (89%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Theme/UpdateChecker.php (81%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Update.php (84%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/UpdateChecker.php (84%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/UpgraderStatus.php (98%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Utils.php (96%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Vcs/Api.php (94%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Vcs/BaseChecker.php (73%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Vcs/BitBucketApi.php (90%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Vcs/GitHubApi.php (95%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Vcs/GitLabApi.php (93%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Vcs/PluginUpdateChecker.php (89%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Vcs/Reference.php (91%) mode change 100644 => 100755 rename inc/update-checker/Puc/{v4p9 => v4p10}/Vcs/ThemeUpdateChecker.php (84%) mode change 100644 => 100755 mode change 100644 => 100755 inc/update-checker/css/puc-debug-bar.css mode change 100644 => 100755 inc/update-checker/js/debug-bar.js create mode 100755 inc/update-checker/languages/plugin-update-checker-zh_CN.mo create mode 100755 inc/update-checker/languages/plugin-update-checker-zh_CN.po create mode 100755 inc/update-checker/languages/plugin-update-checker.pot mode change 100644 => 100755 inc/update-checker/vendor/Parsedown.php mode change 100644 => 100755 inc/update-checker/vendor/ParsedownLegacy.php mode change 100644 => 100755 inc/update-checker/vendor/ParsedownModern.php mode change 100644 => 100755 inc/update-checker/vendor/PucReadmeParser.php diff --git a/inc/update-checker/Puc/v4/Factory.php b/inc/update-checker/Puc/v4/Factory.php old mode 100644 new mode 100755 index 3723e008..32673c96 --- a/inc/update-checker/Puc/v4/Factory.php +++ b/inc/update-checker/Puc/v4/Factory.php @@ -1,6 +1,6 @@ prefix = $nameParts[0] . '_' . $nameParts[1] . '_'; - $this->libraryDir = realpath($this->rootDir . '../..') . '/'; + $this->libraryDir = $this->rootDir . '../..'; + if ( !self::isPhar() ) { + $this->libraryDir = realpath($this->libraryDir); + } + $this->libraryDir = $this->libraryDir . '/'; + $this->staticMap = array( 'PucReadmeParser' => 'vendor/PucReadmeParser.php', 'Parsedown' => 'vendor/Parsedown.php', @@ -24,6 +29,17 @@ public function __construct() { 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]) ) { /** @noinspection PhpIncludeInspection */ diff --git a/inc/update-checker/Puc/v4p9/DebugBar/Extension.php b/inc/update-checker/Puc/v4p10/DebugBar/Extension.php old mode 100644 new mode 100755 similarity index 86% rename from inc/update-checker/Puc/v4p9/DebugBar/Extension.php rename to inc/update-checker/Puc/v4p10/DebugBar/Extension.php index 94017896..deba8c2c --- a/inc/update-checker/Puc/v4p9/DebugBar/Extension.php +++ b/inc/update-checker/Puc/v4p10/DebugBar/Extension.php @@ -1,12 +1,12 @@ updateChecker = $updateChecker; @@ -142,6 +142,15 @@ protected function preAjaxRequest() { @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_v4_debug_check_now', array($this, 'ajaxCheckNow')); + } + /** * @param string $filePath * @return string @@ -150,11 +159,11 @@ private function getLibraryUrl($filePath) { $absolutePath = realpath(dirname(__FILE__) . '/../../../' . ltrim($filePath, '/')); //Where is the library located inside the WordPress directory structure? - $absolutePath = Puc_v4p9_Factory::normalizePath($absolutePath); + $absolutePath = Puc_v4p10_Factory::normalizePath($absolutePath); - $pluginDir = Puc_v4p9_Factory::normalizePath(WP_PLUGIN_DIR); - $muPluginDir = Puc_v4p9_Factory::normalizePath(WPMU_PLUGIN_DIR); - $themeDir = Puc_v4p9_Factory::normalizePath(get_theme_root()); + $pluginDir = Puc_v4p10_Factory::normalizePath(WP_PLUGIN_DIR); + $muPluginDir = Puc_v4p10_Factory::normalizePath(WPMU_PLUGIN_DIR); + $themeDir = Puc_v4p10_Factory::normalizePath(get_theme_root()); if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) { //It's part of a plugin. diff --git a/inc/update-checker/Puc/v4p9/DebugBar/Panel.php b/inc/update-checker/Puc/v4p10/DebugBar/Panel.php old mode 100644 new mode 100755 similarity index 96% rename from inc/update-checker/Puc/v4p9/DebugBar/Panel.php rename to inc/update-checker/Puc/v4p10/DebugBar/Panel.php index dd0e259b..ecd06414 --- a/inc/update-checker/Puc/v4p9/DebugBar/Panel.php +++ b/inc/update-checker/Puc/v4p10/DebugBar/Panel.php @@ -1,9 +1,9 @@ '; diff --git a/inc/update-checker/Puc/v4p9/DebugBar/PluginExtension.php b/inc/update-checker/Puc/v4p10/DebugBar/PluginExtension.php old mode 100644 new mode 100755 similarity index 72% rename from inc/update-checker/Puc/v4p9/DebugBar/PluginExtension.php rename to inc/update-checker/Puc/v4p10/DebugBar/PluginExtension.php index ca3de424..863ed737 --- a/inc/update-checker/Puc/v4p9/DebugBar/PluginExtension.php +++ b/inc/update-checker/Puc/v4p10/DebugBar/PluginExtension.php @@ -1,12 +1,12 @@ '', + '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); + } + + /** @noinspection PhpUndefinedVariableInspection These variables are created by extract(), above. */ + return self::buildUpdateChecker($metadataUrl, $fullPath, $slug, $checkPeriod, $optionName, $muPluginFile); + } + /** * 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 * the appropriate implementation for your update source (JSON file, GitHub, BitBucket, etc). * - * @see Puc_v4p9_UpdateChecker::__construct + * @see Puc_v4p10_UpdateChecker::__construct * * @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. @@ -32,7 +62,7 @@ class Puc_v4p9_Factory { * @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 $muPluginFile The plugin filename relative to the mu-plugins directory. - * @return Puc_v4p9_Plugin_UpdateChecker|Puc_v4p9_Theme_UpdateChecker|Puc_v4p9_Vcs_BaseChecker + * @return Puc_v4p10_Plugin_UpdateChecker|Puc_v4p10_Theme_UpdateChecker|Puc_v4p10_Vcs_BaseChecker */ public static function buildUpdateChecker($metadataUrl, $fullPath, $slug = '', $checkPeriod = 12, $optionName = '', $muPluginFile = '') { $fullPath = self::normalizePath($fullPath); @@ -178,6 +208,35 @@ protected static function getThemeDirectoryName($absolutePath) { 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. * @@ -294,4 +353,4 @@ public static function addVersion($generalClass, $versionedClass, $version) { } } -endif; \ No newline at end of file +endif; diff --git a/inc/update-checker/Puc/v4p9/InstalledPackage.php b/inc/update-checker/Puc/v4p10/InstalledPackage.php old mode 100644 new mode 100755 similarity index 95% rename from inc/update-checker/Puc/v4p9/InstalledPackage.php rename to inc/update-checker/Puc/v4p10/InstalledPackage.php index 0a2768a2..9080c5ab --- a/inc/update-checker/Puc/v4p9/InstalledPackage.php +++ b/inc/update-checker/Puc/v4p10/InstalledPackage.php @@ -1,5 +1,5 @@ $field) ) { diff --git a/inc/update-checker/Puc/v4p9/Plugin/Package.php b/inc/update-checker/Puc/v4p10/Plugin/Package.php old mode 100644 new mode 100755 similarity index 94% rename from inc/update-checker/Puc/v4p9/Plugin/Package.php rename to inc/update-checker/Puc/v4p10/Plugin/Package.php index b92c5f77..debb5ebe --- a/inc/update-checker/Puc/v4p9/Plugin/Package.php +++ b/inc/update-checker/Puc/v4p10/Plugin/Package.php @@ -1,9 +1,9 @@ pluginAbsolutePath); //If realpath() fails, just normalize the syntax instead. if (($muPluginDir === false) || ($pluginPath === false)) { - $muPluginDir = Puc_v4p9_Factory::normalizePath(WPMU_PLUGIN_DIR); - $pluginPath = Puc_v4p9_Factory::normalizePath($this->pluginAbsolutePath); + $muPluginDir = Puc_v4p10_Factory::normalizePath(WPMU_PLUGIN_DIR); + $pluginPath = Puc_v4p10_Factory::normalizePath($this->pluginAbsolutePath); } $cachedResult = (strpos($pluginPath, $muPluginDir) === 0); diff --git a/inc/update-checker/Puc/v4p9/Plugin/Ui.php b/inc/update-checker/Puc/v4p10/Plugin/Ui.php old mode 100644 new mode 100755 similarity index 91% rename from inc/update-checker/Puc/v4p9/Plugin/Ui.php rename to inc/update-checker/Puc/v4p10/Plugin/Ui.php index d27eaf69..1ff18d6d --- a/inc/update-checker/Puc/v4p9/Plugin/Ui.php +++ b/inc/update-checker/Puc/v4p10/Plugin/Ui.php @@ -1,14 +1,14 @@ updateChecker = $updateChecker; @@ -51,7 +51,7 @@ public function onAdminInit() { */ public function addViewDetailsLink($pluginMeta, $pluginFile, $pluginData = array()) { if ( $this->isMyPluginFile($pluginFile) && !isset($pluginData['slug']) ) { - $linkText = apply_filters($this->updateChecker->getUniqueName('view_details_link'), __('查看详情', 'kratos')); + $linkText = apply_filters($this->updateChecker->getUniqueName('view_details_link'), __('View details')); if ( !empty($linkText) ) { $viewDetailsLinkPosition = 'append'; @@ -74,7 +74,7 @@ public function addViewDetailsLink($pluginMeta, $pluginFile, $pluginData = array $viewDetailsLink = sprintf('%s', 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(__('%s 的详细内容','kratos'), $pluginData['Name'])), + esc_attr(sprintf(__('More information about %s'), $pluginData['Name'])), esc_attr($pluginData['Name']), $linkText ); @@ -125,7 +125,7 @@ public function addCheckForUpdatesLink($pluginMeta, $pluginFile) { $linkText = apply_filters( $this->updateChecker->getUniqueName('manual_check_link'), - __('检查更新', 'kratos') + __('Check for updates', 'plugin-update-checker') ); if ( !empty($linkText) ) { /** @noinspection HtmlUnknownTarget */ @@ -210,17 +210,17 @@ public function displayManualCheckResult() { $details = ''; if ( $status == 'no_update' ) { - $message = sprintf(__('%s 是最新版本', 'kratos'), $title); + $message = sprintf(_x('The %s plugin is up to date.', 'the plugin title', 'plugin-update-checker'), $title); } else if ( $status == 'update_available' ) { - $message = sprintf(__('%s 有新版本了', 'kratos'), $title); + $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(__('无法确定更新能否用于 %s', 'kratos'), $title); + $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(__('未知的状态:%s', 'kratos'), htmlentities($status)); + $message = sprintf(__('Unknown update checker status "%s"', 'plugin-update-checker'), htmlentities($status)); $noticeClass = 'error notice-error'; } printf( diff --git a/inc/update-checker/Puc/v4p9/Plugin/Update.php b/inc/update-checker/Puc/v4p10/Plugin/Update.php old mode 100644 new mode 100755 similarity index 81% rename from inc/update-checker/Puc/v4p9/Plugin/Update.php rename to inc/update-checker/Puc/v4p10/Plugin/Update.php index 43456174..89293c5c --- a/inc/update-checker/Puc/v4p9/Plugin/Update.php +++ b/inc/update-checker/Puc/v4p10/Plugin/Update.php @@ -1,5 +1,5 @@ id = $this->id; $update->url = $this->homepage; $update->tested = $this->tested; + $update->requires_php = $this->requires_php; $update->plugin = $this->filename; if ( !empty($this->upgrade_notice) ) { diff --git a/inc/update-checker/Puc/v4p9/Plugin/UpdateChecker.php b/inc/update-checker/Puc/v4p10/Plugin/UpdateChecker.php old mode 100644 new mode 100755 similarity index 89% rename from inc/update-checker/Puc/v4p9/Plugin/UpdateChecker.php rename to inc/update-checker/Puc/v4p10/Plugin/UpdateChecker.php index e99af5ee..c45f109d --- a/inc/update-checker/Puc/v4p9/Plugin/UpdateChecker.php +++ b/inc/update-checker/Puc/v4p10/Plugin/UpdateChecker.php @@ -1,5 +1,5 @@ pluginFile, array($this, 'removeHooks')); - $this->extraUi = new Puc_v4p9_Plugin_Ui($this); + $this->extraUi = new Puc_v4p10_Plugin_Ui($this); } /** * Create an instance of the scheduler. * * @param int $checkPeriod - * @return Puc_v4p9_Scheduler + * @return Puc_v4p10_Scheduler */ protected function createScheduler($checkPeriod) { - $scheduler = new Puc_v4p9_Scheduler($this, $checkPeriod, array('load-plugins.php')); + $scheduler = new Puc_v4p10_Scheduler($this, $checkPeriod, array('load-plugins.php')); register_deactivation_hook($this->pluginFile, array($scheduler, 'removeUpdaterCron')); return $scheduler; } @@ -124,13 +124,13 @@ public function removeHooks() { * @uses wp_remote_get() * * @param array $queryArgs Additional query arguments to append to the request. Optional. - * @return Puc_v4p9_Plugin_Info + * @return Puc_v4p10_Plugin_Info */ public function requestInfo($queryArgs = array()) { - list($pluginInfo, $result) = $this->requestMetadata('Puc_v4p9_Plugin_Info', 'request_info', $queryArgs); + list($pluginInfo, $result) = $this->requestMetadata('Puc_v4p10_Plugin_Info', 'request_info', $queryArgs); if ( $pluginInfo !== null ) { - /** @var Puc_v4p9_Plugin_Info $pluginInfo */ + /** @var Puc_v4p10_Plugin_Info $pluginInfo */ $pluginInfo->filename = $this->pluginFile; $pluginInfo->slug = $this->slug; } @@ -144,7 +144,7 @@ public function requestInfo($queryArgs = array()) { * * @uses PluginUpdateChecker::requestInfo() * - * @return Puc_v4p9_Update|null An instance of Plugin_Update, or NULL when no updates are available. + * @return Puc_v4p10_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() @@ -153,7 +153,7 @@ public function requestUpdate() { if ( $pluginInfo === null ){ return null; } - $update = Puc_v4p9_Plugin_Update::fromPluginInfo($pluginInfo); + $update = Puc_v4p10_Plugin_Update::fromPluginInfo($pluginInfo); $update = $this->filterUpdateResult($update); @@ -235,6 +235,22 @@ protected function getUpdateListKey() { 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(). * @@ -265,12 +281,12 @@ public function isBeingUpgraded($upgrader = null) { * Uses cached update data. To retrieve update information straight from * the metadata URL, call requestUpdate() instead. * - * @return Puc_v4p9_Plugin_Update|null + * @return Puc_v4p10_Plugin_Update|null */ public function getUpdate() { $update = parent::getUpdate(); if ( isset($update) ) { - /** @var Puc_v4p9_Plugin_Update $update */ + /** @var Puc_v4p10_Plugin_Update $update */ $update->filename = $this->pluginFile; } return $update; @@ -375,20 +391,20 @@ public function addResultFilter($callback) { } protected function createDebugBarExtension() { - return new Puc_v4p9_DebugBar_PluginExtension($this); + return new Puc_v4p10_DebugBar_PluginExtension($this); } /** * Create a package instance that represents this plugin or theme. * - * @return Puc_v4p9_InstalledPackage + * @return Puc_v4p10_InstalledPackage */ protected function createInstalledPackage() { - return new Puc_v4p9_Plugin_Package($this->pluginAbsolutePath, $this); + return new Puc_v4p10_Plugin_Package($this->pluginAbsolutePath, $this); } /** - * @return Puc_v4p9_Plugin_Package + * @return Puc_v4p10_Plugin_Package */ public function getInstalledPackage() { return $this->package; diff --git a/inc/update-checker/Puc/v4p9/Scheduler.php b/inc/update-checker/Puc/v4p10/Scheduler.php old mode 100644 new mode 100755 similarity index 84% rename from inc/update-checker/Puc/v4p9/Scheduler.php rename to inc/update-checker/Puc/v4p10/Scheduler.php index ce814636..3e9857bb --- a/inc/update-checker/Puc/v4p9/Scheduler.php +++ b/inc/update-checker/Puc/v4p10/Scheduler.php @@ -1,11 +1,11 @@ removeHooks(); + $this->updateChecker->removeHooks(); + return; + } //Sanity check and limitation to relevant types. if ( @@ -106,7 +116,7 @@ public function upgraderProcessComplete( //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, 'Puc_v4p9_Theme_UpdateChecker') ) { + if ( is_a($this->updateChecker, 'Puc_v4p10_Theme_UpdateChecker') ) { if ( 'theme' !== $upgradeInfo['type'] || !isset($upgradeInfo['themes']) ) { return; } @@ -120,7 +130,7 @@ public function upgraderProcessComplete( } } - if ( is_a($this->updateChecker, 'Puc_v4p9_Plugin_UpdateChecker') ) { + if ( is_a($this->updateChecker, 'Puc_v4p10_Plugin_UpdateChecker') ) { if ( 'plugin' !== $upgradeInfo['type'] || !isset($upgradeInfo['plugins']) ) { return; } @@ -136,7 +146,7 @@ public function upgraderProcessComplete( $this->maybeCheckForUpdates(); } - + /** * 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. @@ -233,6 +243,24 @@ public function removeUpdaterCron() { public function getCronHookName() { 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; diff --git a/inc/update-checker/Puc/v4p9/StateStore.php b/inc/update-checker/Puc/v4p10/StateStore.php old mode 100644 new mode 100755 similarity index 89% rename from inc/update-checker/Puc/v4p9/StateStore.php rename to inc/update-checker/Puc/v4p10/StateStore.php index ff140638..903fee15 --- a/inc/update-checker/Puc/v4p9/StateStore.php +++ b/inc/update-checker/Puc/v4p10/StateStore.php @@ -1,8 +1,8 @@ lazyLoad(); @@ -73,10 +73,10 @@ public function getUpdate() { } /** - * @param Puc_v4p9_Update|null $update + * @param Puc_v4p10_Update|null $update * @return $this */ - public function setUpdate(Puc_v4p9_Update $update = null) { + public function setUpdate(Puc_v4p10_Update $update = null) { $this->lazyLoad(); $this->update = $update; return $this; @@ -138,7 +138,7 @@ public function save() { $updateClass = get_class($this->update); $state->updateClass = $updateClass; $prefix = $this->getLibPrefix(); - if ( Puc_v4p9_Utils::startsWith($updateClass, $prefix) ) { + if ( Puc_v4p10_Utils::startsWith($updateClass, $prefix) ) { $state->updateBaseClass = substr($updateClass, strlen($prefix)); } } @@ -169,8 +169,8 @@ protected function load() { return; } - $this->lastCheck = intval(Puc_v4p9_Utils::get($state, 'lastCheck', 0)); - $this->checkedVersion = Puc_v4p9_Utils::get($state, 'checkedVersion', ''); + $this->lastCheck = intval(Puc_v4p10_Utils::get($state, 'lastCheck', 0)); + $this->checkedVersion = Puc_v4p10_Utils::get($state, 'checkedVersion', ''); $this->update = null; if ( isset($state->update) ) { diff --git a/inc/update-checker/Puc/v4p9/Theme/Package.php b/inc/update-checker/Puc/v4p10/Theme/Package.php old mode 100644 new mode 100755 similarity index 92% rename from inc/update-checker/Puc/v4p9/Theme/Package.php rename to inc/update-checker/Puc/v4p10/Theme/Package.php index 4766c5cb..5d9243b8 --- a/inc/update-checker/Puc/v4p9/Theme/Package.php +++ b/inc/update-checker/Puc/v4p10/Theme/Package.php @@ -1,7 +1,7 @@ requestMetadata('Puc_v4p9_Theme_Update', 'request_update'); + list($themeUpdate, $result) = $this->requestMetadata('Puc_v4p10_Theme_Update', 'request_update'); if ( $themeUpdate !== null ) { - /** @var Puc_v4p9_Theme_Update $themeUpdate */ + /** @var Puc_v4p10_Theme_Update $themeUpdate */ $themeUpdate->slug = $this->slug; } @@ -53,6 +53,16 @@ public function requestUpdate() { return $themeUpdate; } + protected function getNoUpdateItemFields() { + return array_merge( + parent::getNoUpdateItemFields(), + array( + 'theme' => $this->directoryName, + 'requires' => '', + ) + ); + } + public function userCanInstallUpdates() { return current_user_can('update_themes'); } @@ -61,10 +71,10 @@ public function userCanInstallUpdates() { * Create an instance of the scheduler. * * @param int $checkPeriod - * @return Puc_v4p9_Scheduler + * @return Puc_v4p10_Scheduler */ protected function createScheduler($checkPeriod) { - return new Puc_v4p9_Scheduler($this, $checkPeriod, array('load-themes.php')); + return new Puc_v4p10_Scheduler($this, $checkPeriod, array('load-themes.php')); } /** @@ -78,7 +88,7 @@ public function isBeingUpgraded($upgrader = null) { } protected function createDebugBarExtension() { - return new Puc_v4p9_DebugBar_Extension($this, 'Puc_v4p9_DebugBar_ThemePanel'); + return new Puc_v4p10_DebugBar_Extension($this, 'Puc_v4p10_DebugBar_ThemePanel'); } /** @@ -132,10 +142,10 @@ public function addResultFilter($callback) { /** * Create a package instance that represents this plugin or theme. * - * @return Puc_v4p9_InstalledPackage + * @return Puc_v4p10_InstalledPackage */ protected function createInstalledPackage() { - return new Puc_v4p9_Theme_Package($this->stylesheet, $this); + return new Puc_v4p10_Theme_Package($this->stylesheet, $this); } } diff --git a/inc/update-checker/Puc/v4p9/Update.php b/inc/update-checker/Puc/v4p10/Update.php old mode 100644 new mode 100755 similarity index 84% rename from inc/update-checker/Puc/v4p9/Update.php rename to inc/update-checker/Puc/v4p10/Update.php index 3db3d605..b36b18b0 --- a/inc/update-checker/Puc/v4p9/Update.php +++ b/inc/update-checker/Puc/v4p10/Update.php @@ -1,5 +1,5 @@ debugMode = (bool)(constant('WP_DEBUG')); $this->metadataUrl = $metadataUrl; @@ -79,12 +89,39 @@ public function __construct($metadataUrl, $directoryName, $slug = null, $checkPe $this->package = $this->createInstalledPackage(); $this->scheduler = $this->createScheduler($checkPeriod); - $this->upgraderStatus = new Puc_v4p9_UpgraderStatus(); - $this->updateState = new Puc_v4p9_StateStore($this->optionName); + $this->upgraderStatus = new Puc_v4p10_UpgraderStatus(); + $this->updateState = new Puc_v4p10_StateStore($this->optionName); + + if ( did_action('init') ) { + $this->loadTextDomain(); + } else { + add_action('init', array($this, 'loadTextDomain')); + } $this->installHooks(); } + /** + * @internal + */ + public function loadTextDomain() { + //We're not using load_plugin_textdomain() or its siblings because figuring out where + //the library is located (plugin, mu-plugin, theme, custom wp-content paths) is messy. + $domain = 'plugin-update-checker'; + $locale = apply_filters( + 'plugin_locale', + (is_admin() && function_exists('get_user_locale')) ? get_user_locale() : get_locale(), + $domain + ); + + $moFile = $domain . '-' . $locale . '.mo'; + $path = realpath(dirname(__FILE__) . '/../../languages'); + + if ($path && file_exists($path)) { + load_textdomain($domain, $path . '/' . $moFile); + } + } + protected function installHooks() { //Insert our update info into the update array maintained by WP. add_filter('site_transient_' . $this->updateTransient, array($this,'injectUpdate')); @@ -119,7 +156,7 @@ protected function installHooks() { /** * 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, 'injectTranslationUpdates')); remove_action( @@ -130,6 +167,16 @@ protected function removeHooks() { remove_filter('upgrader_source_selection', array($this, 'fixDirectoryName'), 10); remove_filter('http_request_host_is_external', array($this, 'allowMetadataHost'), 10); remove_action('plugins_loaded', array($this, 'maybeInitDebugBar')); + + remove_action('init', array($this, 'loadTextDomain')); + + if ( $this->scheduler ) { + $this->scheduler->removeHooks(); + } + + if ( $this->debugBarExtension ) { + $this->debugBarExtension->removeHooks(); + } } /** @@ -158,12 +205,11 @@ abstract public function userCanInstallUpdates(); * @return bool */ public function allowMetadataHost($allow, $host) { - static $metadataHost = 0; //Using 0 instead of NULL because parse_url can return NULL. - if ( $metadataHost === 0 ) { - $metadataHost = parse_url($this->metadataUrl, PHP_URL_HOST); + if ( $this->cachedMetadataHost === 0 ) { + $this->cachedMetadataHost = 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 $allow; @@ -172,12 +218,12 @@ public function allowMetadataHost($allow, $host) { /** * Create a package instance that represents this plugin or theme. * - * @return Puc_v4p9_InstalledPackage + * @return Puc_v4p10_InstalledPackage */ abstract protected function createInstalledPackage(); /** - * @return Puc_v4p9_InstalledPackage + * @return Puc_v4p10_InstalledPackage */ public function getInstalledPackage() { return $this->package; @@ -190,14 +236,14 @@ public function getInstalledPackage() { * and substitute their own scheduler. * * @param int $checkPeriod - * @return Puc_v4p9_Scheduler + * @return Puc_v4p10_Scheduler */ abstract protected function createScheduler($checkPeriod); /** * Check for updates. The results are stored in the DB option specified in $optionName. * - * @return Puc_v4p9_Update|null + * @return Puc_v4p10_Update|null */ public function checkForUpdates() { $installedVersion = $this->getInstalledVersion(); @@ -231,7 +277,7 @@ public function checkForUpdates() { /** * Load the update checker state from the DB. * - * @return Puc_v4p9_StateStore + * @return Puc_v4p10_StateStore */ public function getUpdateState() { return $this->updateState->lazyLoad(); @@ -256,7 +302,7 @@ public function resetUpdateState() { * Uses cached update data. To retrieve update information straight from * the metadata URL, call requestUpdate() instead. * - * @return Puc_v4p9_Update|null + * @return Puc_v4p10_Update|null */ public function getUpdate() { $update = $this->updateState->getUpdate(); @@ -277,16 +323,16 @@ public function getUpdate() { * * Subclasses should run the update through filterUpdateResult before returning it. * - * @return Puc_v4p9_Update An instance of Update, or NULL when no updates are available. + * @return Puc_v4p10_Update An instance of Update, or NULL when no updates are available. */ abstract public function requestUpdate(); /** * Filter the result of a requestUpdate() call. * - * @param Puc_v4p9_Update|null $update + * @param Puc_v4p10_Update|null $update * @param array|WP_Error|null $httpResult The value returned by wp_remote_get(), if any. - * @return Puc_v4p9_Update + * @return Puc_v4p10_Update */ protected function filterUpdateResult($update, $httpResult = null) { //Let plugins/themes modify the update. @@ -309,9 +355,9 @@ protected function filterUpdateResult($update, $httpResult = null) { * "Compatibility: Unknown". * The function mimics how wordpress.org API crafts the "tested" field out of "Tested up to". * - * @param Puc_v4p9_Metadata|null $update + * @param Puc_v4p10_Metadata|null $update */ - protected function fixSupportedWordpressVersion(Puc_v4p9_Metadata $update = null) { + protected function fixSupportedWordpressVersion(Puc_v4p10_Metadata $update = null) { if ( !isset($update->tested) || !preg_match('/^\d++\.\d++$/', $update->tested) ) { return; } @@ -320,26 +366,39 @@ protected function fixSupportedWordpressVersion(Puc_v4p9_Metadata $update = null $wpVersion = $GLOBALS['wp_version']; - if ( function_exists('get_preferred_from_update_core') ) { - $coreUpdate = get_preferred_from_update_core(); - if ( isset($coreUpdate->current) && version_compare($coreUpdate->current, $wpVersion, '>') ) { - $actualWpVersions[] = $coreUpdate->current; + 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 = "999"; + $actualWpPatchNumber = null; foreach ($actualWpVersions as $version) { - if ( preg_match('/^(?P\d++\.\d++)\.(?P\d++)/', $version, $versionParts) ) { + if ( preg_match('/^(?P\d++\.\d++)(?:\.(?P\d++))?/', $version, $versionParts) ) { if ( $versionParts['majorMinor'] === $update->tested ) { - $actualWpPatchNumber = $versionParts['patch']; - break; + $patch = isset($versionParts['patch']) ? intval($versionParts['patch']) : 0; + if ( $actualWpPatchNumber === null ) { + $actualWpPatchNumber = $patch; + } else { + $actualWpPatchNumber = max($actualWpPatchNumber, $patch); + } } } } + if ( $actualWpPatchNumber === null ) { + $actualWpPatchNumber = 999; + } - $update->tested .= '.' . $actualWpPatchNumber; + if ( $actualWpPatchNumber > 0 ) { + $update->tested .= '.' . $actualWpPatchNumber; + } } /** @@ -474,6 +533,10 @@ public function injectUpdate($updates) { } else { //Clean up any stale update info. $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; @@ -505,6 +568,40 @@ protected function removeUpdateFromList($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 * by the WordPress core. The list is always an associative array, but the key is different @@ -541,7 +638,7 @@ protected function shouldShowUpdates() { * @param string $metaClass Parse the JSON as an instance of this class. It must have a static fromJson method. * @param string $filterRoot * @param array $queryArgs Additional query arguments. - * @return array [Puc_v4p9_Metadata|null, array|WP_Error] A metadata instance and the value returned by wp_remote_get(). + * @return array [Puc_v4p10_Metadata|null, array|WP_Error] A metadata instance and the value returned by wp_remote_get(). */ 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()). @@ -875,18 +972,18 @@ protected function isBadDirectoryStructure($remoteSource) { */ public function maybeInitDebugBar() { if ( class_exists('Debug_Bar', false) && file_exists(dirname(__FILE__) . '/DebugBar') ) { - $this->createDebugBarExtension(); + $this->debugBarExtension = $this->createDebugBarExtension(); } } protected function createDebugBarExtension() { - return new Puc_v4p9_DebugBar_Extension($this); + return new Puc_v4p10_DebugBar_Extension($this); } /** * Display additional configuration details in the Debug Bar panel. * - * @param Puc_v4p9_DebugBar_Panel $panel + * @param Puc_v4p10_DebugBar_Panel $panel */ public function onDisplayConfiguration($panel) { //Do nothing. Subclasses can use this to add additional info to the panel. diff --git a/inc/update-checker/Puc/v4p9/UpgraderStatus.php b/inc/update-checker/Puc/v4p10/UpgraderStatus.php old mode 100644 new mode 100755 similarity index 98% rename from inc/update-checker/Puc/v4p9/UpgraderStatus.php rename to inc/update-checker/Puc/v4p10/UpgraderStatus.php index 2918fa1c..2c2a6259 --- a/inc/update-checker/Puc/v4p9/UpgraderStatus.php +++ b/inc/update-checker/Puc/v4p10/UpgraderStatus.php @@ -1,5 +1,5 @@ getRemoteFile($this->getLocalReadmeName(), $ref); if ( empty($fileContents) ) { return array(); @@ -105,7 +105,7 @@ public function getLocalReadmeName() { * Get a branch. * * @param string $branchName - * @return Puc_v4p9_Vcs_Reference|null + * @return Puc_v4p10_Vcs_Reference|null */ abstract public function getBranch($branchName); @@ -113,7 +113,7 @@ abstract public function getBranch($branchName); * Get a specific tag. * * @param string $tagName - * @return Puc_v4p9_Vcs_Reference|null + * @return Puc_v4p10_Vcs_Reference|null */ abstract public function getTag($tagName); @@ -121,7 +121,7 @@ abstract public function getTag($tagName); * Get the tag that looks like the highest version number. * (Implementations should skip pre-release versions if possible.) * - * @return Puc_v4p9_Vcs_Reference|null + * @return Puc_v4p10_Vcs_Reference|null */ abstract public function getLatestTag(); @@ -196,7 +196,7 @@ protected function compareTagNames($tag1, $tag2) { * @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. */ - abstract public function getRemoteFile($path, $ref = 'main'); + abstract public function getRemoteFile($path, $ref = 'master'); /** * Get the timestamp of the latest commit that changed the specified branch or tag. diff --git a/inc/update-checker/Puc/v4p9/Vcs/BaseChecker.php b/inc/update-checker/Puc/v4p10/Vcs/BaseChecker.php old mode 100644 new mode 100755 similarity index 73% rename from inc/update-checker/Puc/v4p9/Vcs/BaseChecker.php rename to inc/update-checker/Puc/v4p10/Vcs/BaseChecker.php index 27b77eb1..a1e574af --- a/inc/update-checker/Puc/v4p9/Vcs/BaseChecker.php +++ b/inc/update-checker/Puc/v4p10/Vcs/BaseChecker.php @@ -1,9 +1,9 @@ getStableTag($configBranch); //Look for version-like tags. - if ( !$updateSource && ($configBranch === 'main') ) { + if ( !$updateSource && ($configBranch === 'master') ) { $updateSource = $this->getLatestTag(); } //If all else fails, use the specified branch itself. @@ -59,7 +59,7 @@ public function getBranch($branchName) { return null; } - return new Puc_v4p9_Vcs_Reference(array( + return new Puc_v4p10_Vcs_Reference(array( 'name' => $branch->name, 'updated' => $branch->target->date, 'downloadUrl' => $this->getDownloadUrl($branch->name), @@ -70,7 +70,7 @@ public function getBranch($branchName) { * Get a specific tag. * * @param string $tagName - * @return Puc_v4p9_Vcs_Reference|null + * @return Puc_v4p10_Vcs_Reference|null */ public function getTag($tagName) { $tag = $this->api('/refs/tags/' . $tagName); @@ -78,7 +78,7 @@ public function getTag($tagName) { return null; } - return new Puc_v4p9_Vcs_Reference(array( + return new Puc_v4p10_Vcs_Reference(array( 'name' => $tag->name, 'version' => ltrim($tag->name, 'v'), 'updated' => $tag->target->date, @@ -89,7 +89,7 @@ public function getTag($tagName) { /** * Get the tag that looks like the highest version number. * - * @return Puc_v4p9_Vcs_Reference|null + * @return Puc_v4p10_Vcs_Reference|null */ public function getLatestTag() { $tags = $this->api('/refs/tags?sort=-target.date'); @@ -103,7 +103,7 @@ public function getLatestTag() { //Return the first result. if ( !empty($versionTags) ) { $tag = $versionTags[0]; - return new Puc_v4p9_Vcs_Reference(array( + return new Puc_v4p10_Vcs_Reference(array( 'name' => $tag->name, 'version' => ltrim($tag->name, 'v'), 'updated' => $tag->target->date, @@ -117,7 +117,7 @@ public function getLatestTag() { * Get the tag/ref specified by the "Stable tag" header in the readme.txt of a given branch. * * @param string $branch - * @return null|Puc_v4p9_Vcs_Reference + * @return null|Puc_v4p10_Vcs_Reference */ protected function getStableTag($branch) { $remoteReadme = $this->getRemoteReadme($branch); @@ -156,7 +156,7 @@ protected function getDownloadUrl($ref) { * @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 = 'main') { + public function getRemoteFile($path, $ref = 'master') { $response = $this->api('src/' . $ref . '/' . ltrim($path)); if ( is_wp_error($response) || !is_string($response) ) { return null; @@ -187,7 +187,7 @@ public function getLatestCommitTime($ref) { */ public function api($url, $version = '2.0') { $url = ltrim($url, '/'); - $isSrcResource = Puc_v4p9_Utils::startsWith($url, 'src/'); + $isSrcResource = Puc_v4p10_Utils::startsWith($url, 'src/'); $url = implode('/', array( 'https://api.bitbucket.org', @@ -242,7 +242,7 @@ public function setAuthentication($credentials) { parent::setAuthentication($credentials); if ( !empty($credentials) && !empty($credentials['consumer_key']) ) { - $this->oauth = new Puc_v4p9_OAuthSignature( + $this->oauth = new Puc_v4p10_OAuthSignature( $credentials['consumer_key'], $credentials['consumer_secret'] ); diff --git a/inc/update-checker/Puc/v4p9/Vcs/GitHubApi.php b/inc/update-checker/Puc/v4p10/Vcs/GitHubApi.php old mode 100644 new mode 100755 similarity index 95% rename from inc/update-checker/Puc/v4p9/Vcs/GitHubApi.php rename to inc/update-checker/Puc/v4p10/Vcs/GitHubApi.php index 343cf6ee..ada0d13e --- a/inc/update-checker/Puc/v4p9/Vcs/GitHubApi.php +++ b/inc/update-checker/Puc/v4p10/Vcs/GitHubApi.php @@ -1,8 +1,8 @@ api('/repos/:user/:repo/releases/latest'); @@ -65,7 +65,7 @@ public function getLatestRelease() { return null; } - $reference = new Puc_v4p9_Vcs_Reference(array( + $reference = new Puc_v4p10_Vcs_Reference(array( 'name' => $release->tag_name, 'version' => ltrim($release->tag_name, 'v'), //Remove the "v" prefix from "v1.2.3". 'downloadUrl' => $release->zipball_url, @@ -109,7 +109,7 @@ public function getLatestRelease() { /** * Get the tag that looks like the highest version number. * - * @return Puc_v4p9_Vcs_Reference|null + * @return Puc_v4p10_Vcs_Reference|null */ public function getLatestTag() { $tags = $this->api('/repos/:user/:repo/tags'); @@ -124,7 +124,7 @@ public function getLatestTag() { } $tag = $versionTags[0]; - return new Puc_v4p9_Vcs_Reference(array( + return new Puc_v4p10_Vcs_Reference(array( 'name' => $tag->name, 'version' => ltrim($tag->name, 'v'), 'downloadUrl' => $tag->zipball_url, @@ -136,7 +136,7 @@ public function getLatestTag() { * Get a branch by name. * * @param string $branchName - * @return null|Puc_v4p9_Vcs_Reference + * @return null|Puc_v4p10_Vcs_Reference */ public function getBranch($branchName) { $branch = $this->api('/repos/:user/:repo/branches/' . $branchName); @@ -144,7 +144,7 @@ public function getBranch($branchName) { return null; } - $reference = new Puc_v4p9_Vcs_Reference(array( + $reference = new Puc_v4p10_Vcs_Reference(array( 'name' => $branch->name, 'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name), 'apiResponse' => $branch, @@ -164,7 +164,7 @@ public function getBranch($branchName) { * @param string $ref Reference name (e.g. branch or tag). * @return StdClass|null */ - public function getLatestCommit($filename, $ref = 'main') { + public function getLatestCommit($filename, $ref = 'master') { $commits = $this->api( '/repos/:user/:repo/commits', array( @@ -264,7 +264,7 @@ protected function buildApiUrl($url, $queryParams) { * @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 = 'main') { + public function getRemoteFile($path, $ref = 'master') { $apiUrl = '/repos/:user/:repo/contents/' . $path; $response = $this->api($apiUrl, array('ref' => $ref)); @@ -280,7 +280,7 @@ public function getRemoteFile($path, $ref = 'main') { * @param string $ref * @return string */ - public function buildArchiveDownloadUrl($ref = 'main') { + public function buildArchiveDownloadUrl($ref = 'master') { $url = sprintf( 'https://api.github.com/repos/%1$s/%2$s/zipball/%3$s', urlencode($this->userName), @@ -314,12 +314,12 @@ public function setAuthentication($credentials) { * Figure out which reference (i.e tag or branch) contains the latest version. * * @param string $configBranch Start looking in this branch. - * @return null|Puc_v4p9_Vcs_Reference + * @return null|Puc_v4p10_Vcs_Reference */ public function chooseReference($configBranch) { $updateSource = null; - if ( $configBranch === 'main' ) { + if ( $configBranch === 'master' ) { //Use the latest release. $updateSource = $this->getLatestRelease(); if ( $updateSource === null ) { diff --git a/inc/update-checker/Puc/v4p9/Vcs/GitLabApi.php b/inc/update-checker/Puc/v4p10/Vcs/GitLabApi.php old mode 100644 new mode 100755 similarity index 93% rename from inc/update-checker/Puc/v4p9/Vcs/GitLabApi.php rename to inc/update-checker/Puc/v4p10/Vcs/GitLabApi.php index 8eb477b3..a1a313c4 --- a/inc/update-checker/Puc/v4p9/Vcs/GitLabApi.php +++ b/inc/update-checker/Puc/v4p10/Vcs/GitLabApi.php @@ -1,8 +1,8 @@ getLatestTag(); @@ -100,7 +100,7 @@ public function getLatestRelease() { /** * Get the tag that looks like the highest version number. * - * @return Puc_v4p9_Vcs_Reference|null + * @return Puc_v4p10_Vcs_Reference|null */ public function getLatestTag() { $tags = $this->api('/:id/repository/tags'); @@ -114,7 +114,7 @@ public function getLatestTag() { } $tag = $versionTags[0]; - return new Puc_v4p9_Vcs_Reference(array( + return new Puc_v4p10_Vcs_Reference(array( 'name' => $tag->name, 'version' => ltrim($tag->name, 'v'), 'downloadUrl' => $this->buildArchiveDownloadUrl($tag->name), @@ -126,7 +126,7 @@ public function getLatestTag() { * Get a branch by name. * * @param string $branchName - * @return null|Puc_v4p9_Vcs_Reference + * @return null|Puc_v4p10_Vcs_Reference */ public function getBranch($branchName) { $branch = $this->api('/:id/repository/branches/' . $branchName); @@ -134,7 +134,7 @@ public function getBranch($branchName) { return null; } - $reference = new Puc_v4p9_Vcs_Reference(array( + $reference = new Puc_v4p10_Vcs_Reference(array( 'name' => $branch->name, 'downloadUrl' => $this->buildArchiveDownloadUrl($branch->name), 'apiResponse' => $branch, @@ -238,7 +238,7 @@ protected function buildApiUrl($url, $queryParams) { * @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 = 'main') { + 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; @@ -253,7 +253,7 @@ public function getRemoteFile($path, $ref = 'main') { * @param string $ref * @return string */ - public function buildArchiveDownloadUrl($ref = 'main') { + public function buildArchiveDownloadUrl($ref = 'master') { $url = sprintf( '%1$s://%2$s/api/v4/projects/%3$s/repository/archive.zip', $this->repositoryProtocol, @@ -283,13 +283,13 @@ public function getTag($tagName) { * Figure out which reference (i.e tag or branch) contains the latest version. * * @param string $configBranch Start looking in this branch. - * @return null|Puc_v4p9_Vcs_Reference + * @return null|Puc_v4p10_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 === 'main' ) { + if ( $configBranch === 'master' ) { $updateSource = $this->getLatestTag(); } diff --git a/inc/update-checker/Puc/v4p9/Vcs/PluginUpdateChecker.php b/inc/update-checker/Puc/v4p10/Vcs/PluginUpdateChecker.php old mode 100644 new mode 100755 similarity index 89% rename from inc/update-checker/Puc/v4p9/Vcs/PluginUpdateChecker.php rename to inc/update-checker/Puc/v4p10/Vcs/PluginUpdateChecker.php index 6c901780..aba4b320 --- a/inc/update-checker/Puc/v4p9/Vcs/PluginUpdateChecker.php +++ b/inc/update-checker/Puc/v4p10/Vcs/PluginUpdateChecker.php @@ -1,21 +1,21 @@ api; $api->setLocalDirectory($this->package->getAbsoluteDirectoryPath()); - $info = new Puc_v4p9_Plugin_Info(); + $info = new Puc_v4p10_Plugin_Info(); $info->filename = $this->pluginFile; $info->slug = $this->slug; @@ -95,7 +95,7 @@ public function requestInfo($unusedParameter = null) { if ( empty($info->sections['changelog']) ) { $info->sections['changelog'] = $api->getRemoteChangelog($ref, $this->package->getAbsoluteDirectoryPath()); if ( empty($info->sections['changelog']) ) { - $info->sections['changelog'] = __('没有可用的修改日志', 'kratos'); + $info->sections['changelog'] = __('There is no changelog available.', 'plugin-update-checker'); } } @@ -124,7 +124,7 @@ protected function readmeTxtExistsLocally() { * Copy plugin metadata from a file header to a Plugin Info object. * * @param array $fileHeader - * @param Puc_v4p9_Plugin_Info $pluginInfo + * @param Puc_v4p10_Plugin_Info $pluginInfo */ protected function setInfoFromHeader($fileHeader, $pluginInfo) { $headerToPropertyMap = array( @@ -139,6 +139,8 @@ protected function setInfoFromHeader($fileHeader, $pluginInfo) { 'Tested WP' => 'tested', 'Requires at least' => 'requires', 'Tested up to' => 'tested', + + 'Requires PHP' => 'requires_php', ); foreach ($headerToPropertyMap as $headerName => $property) { if ( isset($fileHeader[$headerName]) && !empty($fileHeader[$headerName]) ) { @@ -155,7 +157,7 @@ protected function setInfoFromHeader($fileHeader, $pluginInfo) { * Copy plugin metadata from the remote readme.txt file. * * @param string $ref GitHub tag or branch where to look for the readme. - * @param Puc_v4p9_Plugin_Info $pluginInfo + * @param Puc_v4p10_Plugin_Info $pluginInfo */ protected function setInfoFromRemoteReadme($ref, $pluginInfo) { $readme = $this->api->getRemoteReadme($ref); @@ -172,6 +174,9 @@ protected function setInfoFromRemoteReadme($ref, $pluginInfo) { if ( !empty($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]) ) { $pluginInfo->upgrade_notice = $readme['upgrade_notice'][$pluginInfo->version]; diff --git a/inc/update-checker/Puc/v4p9/Vcs/Reference.php b/inc/update-checker/Puc/v4p10/Vcs/Reference.php old mode 100644 new mode 100755 similarity index 91% rename from inc/update-checker/Puc/v4p9/Vcs/Reference.php rename to inc/update-checker/Puc/v4p10/Vcs/Reference.php index b9b30c19..85250cd6 --- a/inc/update-checker/Puc/v4p9/Vcs/Reference.php +++ b/inc/update-checker/Puc/v4p10/Vcs/Reference.php @@ -1,5 +1,5 @@ api; $api->setLocalDirectory($this->package->getAbsoluteDirectoryPath()); - $update = new Puc_v4p9_Theme_Update(); + $update = new Puc_v4p10_Theme_Update(); $update->slug = $this->slug; //Figure out which reference (tag or branch) we'll use to get the latest version of the theme. @@ -60,13 +60,13 @@ public function requestUpdate() { //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. $remoteHeader = $this->package->getFileHeader($api->getRemoteFile('style.css', $ref)); - $update->version = Puc_v4p9_Utils::findNotEmpty(array( + $update->version = Puc_v4p10_Utils::findNotEmpty(array( $remoteHeader['Version'], - Puc_v4p9_Utils::get($updateSource, 'version'), + Puc_v4p10_Utils::get($updateSource, 'version'), )); //The details URL defaults to the Theme URI header or the repository URL. - $update->details_url = Puc_v4p9_Utils::findNotEmpty(array( + $update->details_url = Puc_v4p10_Utils::findNotEmpty(array( $remoteHeader['ThemeURI'], $this->package->getHeaderValue('ThemeURI'), $this->metadataUrl, diff --git a/inc/update-checker/autoload.php b/inc/update-checker/autoload.php index c0cac2ad..1949b3d0 100644 --- a/inc/update-checker/autoload.php +++ b/inc/update-checker/autoload.php @@ -1,35 +1,35 @@ 'Puc_v4p9_Plugin_UpdateChecker', - 'Theme_UpdateChecker' => 'Puc_v4p9_Theme_UpdateChecker', + 'Plugin_UpdateChecker' => 'Puc_v4p10_Plugin_UpdateChecker', + 'Theme_UpdateChecker' => 'Puc_v4p10_Theme_UpdateChecker', - 'Vcs_PluginUpdateChecker' => 'Puc_v4p9_Vcs_PluginUpdateChecker', - 'Vcs_ThemeUpdateChecker' => 'Puc_v4p9_Vcs_ThemeUpdateChecker', + 'Vcs_PluginUpdateChecker' => 'Puc_v4p10_Vcs_PluginUpdateChecker', + 'Vcs_ThemeUpdateChecker' => 'Puc_v4p10_Vcs_ThemeUpdateChecker', - 'GitHubApi' => 'Puc_v4p9_Vcs_GitHubApi', - 'BitBucketApi' => 'Puc_v4p9_Vcs_BitBucketApi', - 'GitLabApi' => 'Puc_v4p9_Vcs_GitLabApi', + 'GitHubApi' => 'Puc_v4p10_Vcs_GitHubApi', + 'BitBucketApi' => 'Puc_v4p10_Vcs_BitBucketApi', + 'GitLabApi' => 'Puc_v4p10_Vcs_GitLabApi', ) as $pucGeneralClass => $pucVersionedClass ) { - Puc_v4_Factory::addVersion($pucGeneralClass, $pucVersionedClass, '4.9'); + Puc_v4_Factory::addVersion($pucGeneralClass, $pucVersionedClass, '4.10'); //Also add it to the minor-version factory in case the major-version factory //was already defined by another, older version of the update checker. - Puc_v4p9_Factory::addVersion($pucGeneralClass, $pucVersionedClass, '4.9'); -} \ No newline at end of file + Puc_v4p10_Factory::addVersion($pucGeneralClass, $pucVersionedClass, '4.10'); +} diff --git a/inc/update-checker/css/puc-debug-bar.css b/inc/update-checker/css/puc-debug-bar.css old mode 100644 new mode 100755 diff --git a/inc/update-checker/js/debug-bar.js b/inc/update-checker/js/debug-bar.js old mode 100644 new mode 100755 diff --git a/inc/update-checker/languages/plugin-update-checker-zh_CN.mo b/inc/update-checker/languages/plugin-update-checker-zh_CN.mo new file mode 100755 index 0000000000000000000000000000000000000000..c0fc4055778c6587af79724223e28c087346aa9c GIT binary patch literal 1060 zcmZ`%&ubGw6dtwyAPS;aMIMD*)QOwWL)aKmV=L8GgH6R-*ls4t+RaRynN3>{62*fR zMWNP~Hd2dJM5GZFQSb+z{TuWm*<1ww1>YuVQz;I7`|W%C-ka}x$($rpPnMb;LKs9*nPTBjgbB4P-!m(uuzy zAIA6x@&V*sJ%nIO>ukj*rU|CV_Ev_F9UTsIwoa~Y8o30^s8X{Jb~$Rq9iS%i%8aV{o!rvYnl0+XP$r9B0`Vbx1?kwMw@3JwSDXqWYz0?sC& z!lZHp2a$)MBCOVm@U{&XZ0b%4&&{D84LPQnEIAwn=GPR1g?iW9TVBE{vRMNf`}az( z3|c_oIzrM?TxGVVgE@M+tqwU4ej?Yl~BE7^aPGE$d!Cn($M$Di_oEm*##LcL2 z#E2V4Xb4y5Sp`Nj%qp1>8Xg?(@6L`!j8IB&&A6tSsWMK{Y*HU9yOzTf!QQ1}Iyssd zpz&^2_bW8$WhvaY&MZ) ziR`2qJsPu-aRUm?1)|-ywh@NR;hcl3f#a$bovdgn92K!e>BRcZOt@amrY>yI!7OPP z)98U3=psb?XH|b`#b12qKYmU8H_Lu)y78dieDtEZaJ!xL=T;hD=YCah5x@4bxwO*# z&}wboeeYLq{`s^JRs{cujn6ZU>HC|f1pWBgpL^=Rooz0!HdYt>`Fi8w^Z%AM7gvKx S^L4*gMRCpPJAUm|Fy=2vaBdI) literal 0 HcmV?d00001 diff --git a/inc/update-checker/languages/plugin-update-checker-zh_CN.po b/inc/update-checker/languages/plugin-update-checker-zh_CN.po new file mode 100755 index 00000000..005b4d04 --- /dev/null +++ b/inc/update-checker/languages/plugin-update-checker-zh_CN.po @@ -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-08-04 08:10+0800\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.4\n" +"X-Poedit-Basepath: ..\n" +"Plural-Forms: nplurals=1; plural=0;\n" +"X-Poedit-SourceCharset: UTF-8\n" +"X-Poedit-KeywordsList: __;_e;_x:1,2c;_x\n" +"Last-Translator: Seaton Jiang \n" +"Language: zh_CN\n" +"X-Poedit-SearchPath-0: .\n" + +#: Puc/v4p3/Plugin/UpdateChecker.php:395 +msgid "Check for updates" +msgstr "检查更新" + +#: Puc/v4p3/Plugin/UpdateChecker.php:548 +#, php-format +msgctxt "the plugin title" +msgid "The %s plugin is up to date." +msgstr "%s 目前是最新版本。" + +#: Puc/v4p3/Plugin/UpdateChecker.php:550 +#, php-format +msgctxt "the plugin title" +msgid "A new version of the %s plugin is available." +msgstr "%s 当前有可用的更新。" + +#: Puc/v4p3/Plugin/UpdateChecker.php:552 +#, php-format +msgctxt "the plugin title" +msgid "Could not determine if updates are available for %s." +msgstr "%s 无法确定是否有可用的更新。" + +#: Puc/v4p3/Plugin/UpdateChecker.php:558 +#, php-format +msgid "Unknown update checker status \"%s\"" +msgstr "未知的更新检查状态:%s" + +#: Puc/v4p3/Vcs/PluginUpdateChecker.php:95 +msgid "There is no changelog available." +msgstr "没有可用的更新日志。" diff --git a/inc/update-checker/languages/plugin-update-checker.pot b/inc/update-checker/languages/plugin-update-checker.pot new file mode 100755 index 00000000..29d1f406 --- /dev/null +++ b/inc/update-checker/languages/plugin-update-checker.pot @@ -0,0 +1,49 @@ +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: plugin-update-checker\n" +"POT-Creation-Date: 2020-08-08 14:36+0300\n" +"PO-Revision-Date: 2016-01-10 20:59+0100\n" +"Last-Translator: Tamás András Horváth \n" +"Language-Team: \n" +"Language: en_US\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"X-Generator: Poedit 2.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" +"X-Poedit-SearchPath-0: .\n" + +#: Puc/v4p10/Plugin/Ui.php:128 +msgid "Check for updates" +msgstr "" + +#: Puc/v4p10/Plugin/Ui.php:213 +#, php-format +msgctxt "the plugin title" +msgid "The %s plugin is up to date." +msgstr "" + +#: Puc/v4p10/Plugin/Ui.php:215 +#, php-format +msgctxt "the plugin title" +msgid "A new version of the %s plugin is available." +msgstr "" + +#: Puc/v4p10/Plugin/Ui.php:217 +#, php-format +msgctxt "the plugin title" +msgid "Could not determine if updates are available for %s." +msgstr "" + +#: Puc/v4p10/Plugin/Ui.php:223 +#, php-format +msgid "Unknown update checker status \"%s\"" +msgstr "" + +#: Puc/v4p10/Vcs/PluginUpdateChecker.php:98 +msgid "There is no changelog available." +msgstr "" diff --git a/inc/update-checker/vendor/Parsedown.php b/inc/update-checker/vendor/Parsedown.php old mode 100644 new mode 100755 diff --git a/inc/update-checker/vendor/ParsedownLegacy.php b/inc/update-checker/vendor/ParsedownLegacy.php old mode 100644 new mode 100755 diff --git a/inc/update-checker/vendor/ParsedownModern.php b/inc/update-checker/vendor/ParsedownModern.php old mode 100644 new mode 100755 diff --git a/inc/update-checker/vendor/PucReadmeParser.php b/inc/update-checker/vendor/PucReadmeParser.php old mode 100644 new mode 100755 index ea247517..1f5cec9e --- a/inc/update-checker/vendor/PucReadmeParser.php +++ b/inc/update-checker/vendor/PucReadmeParser.php @@ -52,6 +52,12 @@ function parse_readme_contents( $file_contents ) { else $tested_up_to = NULL; + // Requires PHP: 5.2.4 + if ( preg_match('|Requires PHP:(.*)|i', $file_contents, $_requires_php) ) { + $requires_php = $this->sanitize_text( $_requires_php[1] ); + } else { + $requires_php = null; + } // Stable tag: 10.4-ride-the-fire-eagle-danger-day if ( preg_match('|Stable tag:(.*)|i', $file_contents, $_stable_tag) ) @@ -196,6 +202,7 @@ function parse_readme_contents( $file_contents ) { 'tags' => $tags, 'requires_at_least' => $requires_at_least, 'tested_up_to' => $tested_up_to, + 'requires_php' => $requires_php, 'stable_tag' => $stable_tag, 'contributors' => $contributors, 'donate_link' => $donate_link,