Initial Commit

This commit is contained in:
David Stone
2024-11-30 18:24:12 -07:00
commit e8f7955c1c
5432 changed files with 1397750 additions and 0 deletions

View File

@ -0,0 +1,65 @@
<?php
if ( !class_exists('Puc_v4p11_Theme_Package', false) ):
class Puc_v4p11_Theme_Package extends Puc_v4p11_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;

View File

@ -0,0 +1,84 @@
<?php
if ( !class_exists('Puc_v4p11_Theme_Update', false) ):
class Puc_v4p11_Theme_Update extends Puc_v4p11_Update {
public $details_url = '';
protected static $extraFields = array('details_url');
/**
* Transform the metadata into the format used by WordPress core.
* Note the inconsistency: WP stores plugin updates as objects and theme updates as arrays.
*
* @return array
*/
public function toWpFormat() {
$update = array(
'theme' => $this->slug,
'new_version' => $this->version,
'url' => $this->details_url,
);
if ( !empty($this->download_url) ) {
$update['package'] = $this->download_url;
}
return $update;
}
/**
* Create a new instance of Theme_Update from its JSON-encoded representation.
*
* @param string $json Valid JSON string representing a theme information object.
* @return self New instance of ThemeUpdate, or NULL on error.
*/
public static function fromJson($json) {
$instance = new self();
if ( !parent::createFromJson($json, $instance) ) {
return null;
}
return $instance;
}
/**
* Create a new instance by copying the necessary fields from another object.
*
* @param StdClass|Puc_v4p11_Theme_Update $object The source object.
* @return Puc_v4p11_Theme_Update The new copy.
*/
public static function fromObject($object) {
$update = new self();
$update->copyFields($object, $update);
return $update;
}
/**
* Basic validation.
*
* @param StdClass $apiResponse
* @return bool|WP_Error
*/
protected function validateMetadata($apiResponse) {
$required = array('version', 'details_url');
foreach($required as $key) {
if ( !isset($apiResponse->$key) || empty($apiResponse->$key) ) {
return new WP_Error(
'tuc-invalid-metadata',
sprintf('The theme metadata is missing the required "%s" key.', $key)
);
}
}
return true;
}
protected function getFieldNames() {
return array_merge(parent::getFieldNames(), self::$extraFields);
}
protected function getPrefixedFilter($tag) {
return parent::getPrefixedFilter($tag) . '_theme';
}
}
endif;

View File

@ -0,0 +1,152 @@
<?php
if ( !class_exists('Puc_v4p11_Theme_UpdateChecker', false) ):
class Puc_v4p11_Theme_UpdateChecker extends Puc_v4p11_UpdateChecker {
protected $filterSuffix = 'theme';
protected $updateTransient = 'update_themes';
protected $translationType = 'theme';
/**
* @var string Theme directory name.
*/
protected $stylesheet;
public function __construct($metadataUrl, $stylesheet = null, $customSlug = null, $checkPeriod = 12, $optionName = '') {
if ( $stylesheet === null ) {
$stylesheet = get_stylesheet();
}
$this->stylesheet = $stylesheet;
parent::__construct(
$metadataUrl,
$stylesheet,
$customSlug ? $customSlug : $stylesheet,
$checkPeriod,
$optionName
);
}
/**
* For themes, the update array is indexed by theme directory name.
*
* @return string
*/
protected function getUpdateListKey() {
return $this->directoryName;
}
/**
* Retrieve the latest update (if any) from the configured API endpoint.
*
* @return Puc_v4p11_Update|null An instance of Update, or NULL when no updates are available.
*/
public function requestUpdate() {
list($themeUpdate, $result) = $this->requestMetadata('Puc_v4p11_Theme_Update', 'request_update');
if ( $themeUpdate !== null ) {
/** @var Puc_v4p11_Theme_Update $themeUpdate */
$themeUpdate->slug = $this->slug;
}
$themeUpdate = $this->filterUpdateResult($themeUpdate, $result);
return $themeUpdate;
}
protected function getNoUpdateItemFields() {
return array_merge(
parent::getNoUpdateItemFields(),
array(
'theme' => $this->directoryName,
'requires' => '',
)
);
}
public function userCanInstallUpdates() {
return current_user_can('update_themes');
}
/**
* Create an instance of the scheduler.
*
* @param int $checkPeriod
* @return Puc_v4p11_Scheduler
*/
protected function createScheduler($checkPeriod) {
return new Puc_v4p11_Scheduler($this, $checkPeriod, array('load-themes.php'));
}
/**
* Is there an update being installed right now for this theme?
*
* @param WP_Upgrader|null $upgrader The upgrader that's performing the current update.
* @return bool
*/
public function isBeingUpgraded($upgrader = null) {
return $this->upgraderStatus->isThemeBeingUpgraded($this->stylesheet, $upgrader);
}
protected function createDebugBarExtension() {
return new Puc_v4p11_DebugBar_Extension($this, 'Puc_v4p11_DebugBar_ThemePanel');
}
/**
* 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.
*
* @param callable $callback
* @return void
*/
public function addQueryArgFilter($callback){
$this->addFilter('request_update_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_update_options', $callback);
}
/**
* Register a callback for filtering theme updates retrieved from the external API.
*
* The callback function should take two arguments. If the theme update was retrieved
* successfully, the first argument passed will be an instance of Theme_Update. 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 Theme_Update 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_update_result', $callback, 10, 2);
}
/**
* Create a package instance that represents this plugin or theme.
*
* @return Puc_v4p11_InstalledPackage
*/
protected function createInstalledPackage() {
return new Puc_v4p11_Theme_Package($this->stylesheet, $this);
}
}
endif;