PK ! '' ' class-envato-market-github.phpnu [ init_actions();
}
return self::$_instance;
}
/**
* A dummy constructor to prevent this class from being loaded more than once.
*
* @see Envato_Market_Github::instance()
*
* @since 1.0.0
* @access private
* @codeCoverageIgnore
*/
private function __construct() {
/* We do nothing here! */
}
/**
* You cannot clone this class.
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'envato-market' ), '1.0.0' );
}
/**
* You cannot unserialize instances of this class.
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'envato-market' ), '1.0.0' );
}
/**
* Setup the actions and filters.
*
* @uses add_action() To add actions.
* @uses add_filter() To add filters.
*
* @since 1.0.0
*/
public function init_actions() {
// Bail outside of the WP Admin panel.
if ( ! is_admin() ) {
return;
}
add_filter( 'http_request_args', array( $this, 'update_check' ), 5, 2 );
add_filter( 'plugins_api', array( $this, 'plugins_api' ), 10, 3 );
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'update_plugins' ) );
add_filter( 'pre_set_transient_update_plugins', array( $this, 'update_plugins' ) );
add_filter( 'site_transient_update_plugins', array( $this, 'update_state' ) );
add_filter( 'transient_update_plugins', array( $this, 'update_state' ) );
add_action( 'admin_notices', array( $this, 'notice' ) );
add_action( 'wp_ajax_' . self::AJAX_ACTION, array( $this, 'dismiss_notice' ) );
}
/**
* Check Github for an update.
*
* @since 1.0.0
*
* @return false|object
*/
public function api_check() {
$raw_response = wp_remote_get( self::$api_url );
if ( is_wp_error( $raw_response ) ) {
return false;
}
if ( ! empty( $raw_response['body'] ) ) {
$raw_body = json_decode( $raw_response['body'], true );
if ( $raw_body ) {
return (object) $raw_body;
}
}
return false;
}
/**
* Disables requests to the wp.org repository for Envato Market.
*
* @since 1.0.0
*
* @param array $request An array of HTTP request arguments.
* @param string $url The request URL.
* @return array
*/
public function update_check( $request, $url ) {
// Plugin update request.
if ( false !== strpos( $url, '//api.wordpress.org/plugins/update-check/1.1/' ) ) {
// Decode JSON so we can manipulate the array.
$data = json_decode( $request['body']['plugins'] );
// Remove the Envato Market.
unset( $data->plugins->{'envato-market/envato-market.php'} );
// Encode back into JSON and update the response.
$request['body']['plugins'] = wp_json_encode( $data );
}
return $request;
}
/**
* API check.
*
* @since 1.0.0
*
* @param bool $api Always false.
* @param string $action The API action being performed.
* @param object $args Plugin arguments.
* @return mixed $api The plugin info or false.
*/
public function plugins_api( $api, $action, $args ) {
if ( isset( $args->slug ) && 'envato-market' === $args->slug ) {
$api_check = $this->api_check();
if ( is_object( $api_check ) ) {
$api = $api_check;
}
}
return $api;
}
/**
* Update check.
*
* @since 1.0.0
*
* @param object $transient The pre-saved value of the `update_plugins` site transient.
* @return object
*/
public function update_plugins( $transient ) {
$state = $this->state();
if ( 'activated' === $state ) {
$api_check = $this->api_check();
if ( is_object( $api_check ) && version_compare( envato_market()->get_version(), $api_check->version, '<' ) ) {
$transient->response['envato-market/envato-market.php'] = (object) array(
'slug' => 'envato-market',
'plugin' => 'envato-market/envato-market.php',
'new_version' => $api_check->version,
'url' => 'https://github.com/envato/wp-envato-market',
'package' => $api_check->download_link,
);
}
}
return $transient;
}
/**
* Set the plugin state.
*
* @since 1.0.0
*
* @return string
*/
public function state() {
$option = 'envato_market_state';
$active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
// We also have to check network activated plugins. Otherwise this plugin won't update on multisite.
$active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
if ( ! is_array( $active_plugins ) ) {
$active_plugins = array();
}
if ( ! is_array( $active_sitewide_plugins ) ) {
$active_sitewide_plugins = array();
}
$active_plugins = array_merge( $active_plugins, array_keys( $active_sitewide_plugins ) );
if ( in_array( 'envato-market/envato-market.php', $active_plugins ) ) {
$state = 'activated';
update_option( $option, $state );
} else {
$state = 'install';
update_option( $option, $state );
foreach ( array_keys( get_plugins() ) as $plugin ) {
if ( strpos( $plugin, 'envato-market.php' ) !== false ) {
$state = 'deactivated';
update_option( $option, $state );
}
}
}
return $state;
}
/**
* Force the plugin state to be updated.
*
* @since 1.0.0
*
* @param object $transient The saved value of the `update_plugins` site transient.
* @return object
*/
public function update_state( $transient ) {
$state = $this->state();
return $transient;
}
/**
* Admin notices.
*
* @since 1.0.0
*
* @return string
*/
public function notice() {
$screen = get_current_screen();
$slug = 'envato-market';
$state = get_option( 'envato_market_state' );
$notice = get_option( self::AJAX_ACTION );
if ( empty( $state ) ) {
$state = $this->state();
}
if (
'activated' === $state ||
'update-core' === $screen->id ||
'update' === $screen->id ||
'plugins' === $screen->id && isset( $_GET['action'] ) && 'delete-selected' === $_GET['action'] ||
'dismissed' === $notice
) {
return;
}
if ( 'deactivated' === $state ) {
$activate_url = add_query_arg(
array(
'action' => 'activate',
'plugin' => urlencode( "$slug/$slug.php" ),
'_wpnonce' => urlencode( wp_create_nonce( "activate-plugin_$slug/$slug.php" ) ),
),
self_admin_url( 'plugins.php' )
);
$message = sprintf(
esc_html__( '%1$sActivate the Envato Market plugin%2$s to get updates for your ThemeForest and CodeCanyon items.', 'envato-market' ),
'',
''
);
} elseif ( 'install' === $state ) {
$install_url = add_query_arg(
array(
'action' => 'install-plugin',
'plugin' => $slug,
),
self_admin_url( 'update.php' )
);
$message = sprintf(
esc_html__( '%1$sInstall the Envato Market plugin%2$s to get updates for your ThemeForest and CodeCanyon items.', 'envato-market' ),
'',
''
);
}
if ( isset( $message ) ) {
?>
__( 'User not allowed to update items.', 'envato-market' ) ) );
}
update_option( self::AJAX_ACTION, 'dismissed' );
wp_send_json_success();
}
}
if ( ! function_exists( 'envato_market_github' ) ) :
/**
* Envato_Market_Github Instance
*
* @since 1.0.0
*
* @return Envato_Market_Github
*/
function envato_market_github() {
return Envato_Market_Github::instance();
}
endif;
/**
* Loads the main instance of Envato_Market_Github
*
* @since 1.0.0
*/
add_action( 'after_setup_theme', 'envato_market_github', 99 );
endif;
PK ! ks( ( class-envato-market.phpnu [ init_globals();
self::$_instance->init_includes();
self::$_instance->init_actions();
}
return self::$_instance;
}
/**
* A dummy constructor to prevent this class from being loaded more than once.
*
* @see Envato_Market::instance()
*
* @since 1.0.0
* @access private
* @codeCoverageIgnore
*/
private function __construct() {
/* We do nothing here! */
}
/**
* You cannot clone this class.
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'envato-market' ), '1.0.0' );
}
/**
* You cannot unserialize instances of this class.
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'envato-market' ), '1.0.0' );
}
/**
* Setup the class globals.
*
* @since 1.0.0
* @access private
* @codeCoverageIgnore
*/
private function init_globals() {
$this->data = new stdClass();
$this->version = ENVATO_MARKET_VERSION;
$this->slug = 'envato-market';
$this->option_name = self::sanitize_key( $this->slug );
$this->plugin_url = ENVATO_MARKET_URI;
$this->plugin_path = ENVATO_MARKET_PATH;
$this->page_url = ENVATO_MARKET_NETWORK_ACTIVATED ? network_admin_url( 'admin.php?page=' . $this->slug ) : admin_url( 'admin.php?page=' . $this->slug );
$this->data->admin = true;
if ( defined('ENVATO_LOCAL_DEVELOPMENT') ) {
$this->envato_api_domain = ENVATO_API_DOMAIN;
$this->envato_api_headers = ENVATO_API_HEADERS;
} else {
$this->envato_api_headers = [ 'Authorization' => 'Bearer ' . $this->get_option( 'token' ) ];
$this->envato_api_domain = 'https://api.envato.com';
}
}
/**
* Include required files.
*
* @since 1.0.0
* @access private
* @codeCoverageIgnore
*/
private function init_includes() {
require $this->plugin_path . '/inc/admin/class-envato-market-admin.php';
require $this->plugin_path . '/inc/admin/functions.php';
require $this->plugin_path . '/inc/class-envato-market-api.php';
require $this->plugin_path . '/inc/class-envato-market-items.php';
require $this->plugin_path . '/inc/class-envato-market-github.php';
}
/**
* Setup the hooks, actions and filters.
*
* @uses add_action() To add actions.
* @uses add_filter() To add filters.
*
* @since 1.0.0
* @access private
* @codeCoverageIgnore
*/
private function init_actions() {
// Activate plugin.
register_activation_hook( ENVATO_MARKET_CORE_FILE, array( $this, 'activate' ) );
// Deactivate plugin.
register_deactivation_hook( ENVATO_MARKET_CORE_FILE, array( $this, 'deactivate' ) );
// Load the textdomain.
add_action( 'init', array( $this, 'load_textdomain' ) );
// Load OAuth.
add_action( 'init', array( $this, 'admin' ) );
// Load Upgrader.
add_action( 'init', array( $this, 'items' ) );
}
/**
* Activate plugin.
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function activate() {
self::set_plugin_state( true );
}
/**
* Deactivate plugin.
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function deactivate() {
self::set_plugin_state( false );
}
/**
* Loads the plugin's translated strings.
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function load_textdomain() {
load_plugin_textdomain( 'envato-market', false, ENVATO_MARKET_PATH . 'languages/' );
}
/**
* Sanitize data key.
*
* @since 1.0.0
* @access private
*
* @param string $key An alpha numeric string to sanitize.
* @return string
*/
private function sanitize_key( $key ) {
return preg_replace( '/[^A-Za-z0-9\_]/i', '', str_replace( array( '-', ':' ), '_', $key ) );
}
/**
* Recursively converts data arrays to objects.
*
* @since 1.0.0
* @access private
*
* @param array $array An array of data.
* @return object
*/
private function convert_data( $array ) {
foreach ( (array) $array as $key => $value ) {
if ( is_array( $value ) ) {
$array[ $key ] = self::convert_data( $value );
}
}
return (object) $array;
}
/**
* Set the `is_plugin_active` option.
*
* This setting helps determine context. Since the plugin can be included in your theme root you
* might want to hide the admin UI when the plugin is not activated and implement your own.
*
* @since 1.0.0
* @access private
*
* @param bool $value Whether or not the plugin is active.
*/
private function set_plugin_state( $value ) {
self::set_option( 'is_plugin_active', $value );
}
/**
* Set option value.
*
* @since 1.0.0
*
* @param string $name Option name.
* @param mixed $option Option data.
*/
public function set_option( $name, $option ) {
$options = self::get_options();
$name = self::sanitize_key( $name );
$options[ $name ] = esc_html( $option );
$this->set_options( $options );
}
/**
* Set option.
*
* @since 2.0.0
*
* @param mixed $options Option data.
*/
public function set_options( $options ) {
ENVATO_MARKET_NETWORK_ACTIVATED ? update_site_option( $this->option_name, $options ) : update_option( $this->option_name, $options );
}
/**
* Return the option settings array.
*
* @since 1.0.0
*/
public function get_options() {
return ENVATO_MARKET_NETWORK_ACTIVATED ? get_site_option( $this->option_name, array() ) : get_option( $this->option_name, array() );
}
/**
* Return a value from the option settings array.
*
* @since 1.0.0
*
* @param string $name Option name.
* @param mixed $default The default value if nothing is set.
* @return mixed
*/
public function get_option( $name, $default = '' ) {
$options = self::get_options();
$name = self::sanitize_key( $name );
return isset( $options[ $name ] ) ? $options[ $name ] : $default;
}
/**
* Set data.
*
* @since 1.0.0
*
* @param string $key Unique object key.
* @param mixed $data Any kind of data.
*/
public function set_data( $key, $data ) {
if ( ! empty( $key ) ) {
if ( is_array( $data ) ) {
$data = self::convert_data( $data );
}
$key = self::sanitize_key( $key );
// @codingStandardsIgnoreStart
$this->data->$key = $data;
// @codingStandardsIgnoreEnd
}
}
/**
* Get data.
*
* @since 1.0.0
*
* @param string $key Unique object key.
* @return string|object
*/
public function get_data( $key ) {
return isset( $this->data->$key ) ? $this->data->$key : '';
}
/**
* Return the plugin slug.
*
* @since 1.0.0
*
* @return string
*/
public function get_slug() {
return $this->slug;
}
/**
* Return the plugin version number.
*
* @since 1.0.0
*
* @return string
*/
public function get_version() {
return $this->version;
}
/**
* Return the plugin URL.
*
* @since 1.0.0
*
* @return string
*/
public function get_plugin_url() {
return $this->plugin_url;
}
/**
* Return the plugin path.
*
* @since 1.0.0
*
* @return string
*/
public function get_plugin_path() {
return $this->plugin_path;
}
/**
* Return the plugin page URL.
*
* @since 1.0.0
*
* @return string
*/
public function get_page_url() {
return $this->page_url;
}
/**
* Return the option settings name.
*
* @since 1.0.0
*
* @return string
*/
public function get_option_name() {
return $this->option_name;
}
/**
* Admin UI class.
*
* @since 1.0.0
*
* @return Envato_Market_Admin
*/
public function admin() {
return Envato_Market_Admin::instance();
}
/**
* Envato API class.
*
* @since 1.0.0
*
* @return Envato_Market_API
*/
public function api() {
return Envato_Market_API::instance();
}
/**
* Items class.
*
* @since 1.0.0
*
* @return Envato_Market_Items
*/
public function items() {
return Envato_Market_Items::instance();
}
public function get_envato_api_domain() {
return $this->envato_api_domain;
}
public function get_envato_api_headers() {
return $this->envato_api_headers;
}
}
endif;
PK ! G=-HC C class-envato-market-items.phpnu [ init_actions();
}
return self::$_instance;
}
/**
* A dummy constructor to prevent this class from being loaded more than once.
*
* @see Envato_Market_Items::instance()
*
* @since 1.0.0
* @access private
* @codeCoverageIgnore
*/
private function __construct() {
/* We do nothing here! */
}
/**
* You cannot clone this class.
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function __clone() {
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'envato-market' ), '1.0.0' );
}
/**
* You cannot unserialize instances of this class.
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function __wakeup() {
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'envato-market' ), '1.0.0' );
}
/**
* Setup the hooks, actions and filters.
*
* @uses add_action() To add actions.
* @uses add_filter() To add filters.
*
* @since 1.0.0
*/
public function init_actions() {
// Check for theme & plugin updates.
add_filter( 'http_request_args', array( $this, 'update_check' ), 5, 2 );
// Inject plugin updates into the response array.
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'update_plugins' ), 5, 1 );
add_filter( 'pre_set_transient_update_plugins', array( $this, 'update_plugins' ), 5, 1 );
// Inject theme updates into the response array.
add_filter( 'pre_set_site_transient_update_themes', array( $this, 'update_themes' ), 1, 99999 );
add_filter( 'pre_set_transient_update_themes', array( $this, 'update_themes' ), 1, 99999 );
// Inject plugin information into the API calls.
add_filter( 'plugins_api', array( $this, 'plugins_api' ), 10, 3 );
// Rebuild the saved theme data.
add_action( 'after_switch_theme', array( $this, 'rebuild_themes' ) );
// Rebuild the saved plugin data.
add_action( 'activated_plugin', array( $this, 'rebuild_plugins' ) );
add_action( 'deactivated_plugin', array( $this, 'rebuild_plugins' ) );
}
/**
* Get the premium plugins list.
*
* @since 1.0.0
*
* @param string $group The plugin group. Options are 'purchased', 'active', 'installed', or 'install'.
* @return array
*/
public function plugins( $group = '' ) {
if ( ! empty( $group ) ) {
if ( isset( self::$plugins[ $group ] ) ) {
return self::$plugins[ $group ];
} else {
return array();
}
}
return self::$plugins;
}
/**
* Get the premium themes list.
*
* @since 1.0.0
*
* @param string $group The theme group. Options are 'purchased', 'active', 'installed', or 'install'.
* @return array
*/
public function themes( $group = '' ) {
if ( ! empty( $group ) ) {
if ( isset( self::$themes[ $group ] ) ) {
return self::$themes[ $group ];
} else {
return array();
}
}
return self::$themes;
}
/**
* Get the list of WordPress plugins
*
* @since 1.0.0
*
* @param bool $flush Forces a cache flush. Default is 'false'.
* @return array
*/
public function wp_plugins( $flush = false ) {
if ( empty( self::$wp_plugins ) || true === $flush ) {
wp_cache_set( 'plugins', false, 'plugins' );
self::$wp_plugins = get_plugins();
}
return self::$wp_plugins;
}
/**
* Disables requests to the wp.org repository for premium themes.
*
* @since 1.0.0
*
* @param array $request An array of HTTP request arguments.
* @param string $url The request URL.
* @return array
*/
public function update_check( $request, $url ) {
// Theme update request.
if ( false !== strpos( $url, '//api.wordpress.org/themes/update-check/1.1/' ) ) {
/**
* Excluded theme slugs that should never ping the WordPress API.
* We don't need the extra http requests for themes we know are premium.
*/
self::set_themes();
$installed = self::$themes['installed'];
// Decode JSON so we can manipulate the array.
$data = json_decode( $request['body']['themes'] );
// Remove the excluded themes.
foreach ( $installed as $slug => $id ) {
unset( $data->themes->$slug );
}
// Encode back into JSON and update the response.
$request['body']['themes'] = wp_json_encode( $data );
}
// Plugin update request.
if ( false !== strpos( $url, '//api.wordpress.org/plugins/update-check/1.1/' ) ) {
/**
* Excluded theme slugs that should never ping the WordPress API.
* We don't need the extra http requests for themes we know are premium.
*/
self::set_plugins();
$installed = self::$plugins['installed'];
// Decode JSON so we can manipulate the array.
$data = json_decode( $request['body']['plugins'] );
// Remove the excluded themes.
foreach ( $installed as $slug => $id ) {
unset( $data->plugins->$slug );
}
// Encode back into JSON and update the response.
$request['body']['plugins'] = wp_json_encode( $data );
}
return $request;
}
/**
* Inject update data for premium themes.
*
* @since 1.0.0
*
* @param object $transient The pre-saved value of the `update_themes` site transient.
* @return object
*/
public function update_themes( $transient ) {
// Process premium theme updates.
if ( isset( $transient->checked ) ) {
self::set_themes( true );
$installed = array_merge( self::$themes['active'], self::$themes['installed'] );
foreach ( $installed as $slug => $premium ) {
$theme = wp_get_theme( $slug );
if ( $theme->exists() && version_compare( $theme->get( 'Version' ), $premium['version'], '<' ) ) {
$transient->response[ $slug ] = array(
'theme' => $slug,
'new_version' => $premium['version'],
'url' => $premium['url'],
'package' => envato_market()->api()->deferred_download( $premium['id'] ),
);
}
}
}
return $transient;
}
/**
* Inject update data for premium plugins.
*
* @since 1.0.0
*
* @param object $transient The pre-saved value of the `update_plugins` site transient.
* @return object
*/
public function update_plugins( $transient ) {
self::set_plugins( true );
// Process premium plugin updates.
$installed = array_merge( self::$plugins['active'], self::$plugins['installed'] );
$plugins = self::wp_plugins();
foreach ( $installed as $plugin => $premium ) {
if ( isset( $plugins[ $plugin ] ) && version_compare( $plugins[ $plugin ]['Version'], $premium['version'], '<' ) ) {
$_plugin = array(
'slug' => dirname( $plugin ),
'plugin' => $plugin,
'new_version' => $premium['version'],
'url' => $premium['url'],
'package' => envato_market()->api()->deferred_download( $premium['id'] ),
);
$transient->response[ $plugin ] = (object) $_plugin;
}
}
return $transient;
}
/**
* Inject API data for premium plugins.
*
* @since 1.0.0
*
* @param bool $response Always false.
* @param string $action The API action being performed.
* @param object $args Plugin arguments.
* @return bool|object $response The plugin info or false.
*/
public function plugins_api( $response, $action, $args ) {
self::set_plugins( true );
// Process premium theme updates.
if ( 'plugin_information' === $action && isset( $args->slug ) ) {
$installed = array_merge( self::$plugins['active'], self::$plugins['installed'] );
foreach ( $installed as $slug => $plugin ) {
if ( dirname( $slug ) === $args->slug ) {
$response = new stdClass();
$response->slug = $args->slug;
$response->plugin = $slug;
$response->plugin_name = $plugin['name'];
$response->name = $plugin['name'];
$response->version = $plugin['version'];
$response->author = $plugin['author'];
$response->homepage = $plugin['url'];
$response->requires = $plugin['requires'];
$response->tested = $plugin['tested'];
$response->downloaded = $plugin['number_of_sales'];
$response->last_updated = $plugin['updated_at'];
$response->sections = array( 'description' => $plugin['description'] );
$response->banners['low'] = $plugin['landscape_url'];
$response->rating = ! empty( $plugin['rating'] ) && ! empty( $plugin['rating']['rating'] ) && $plugin['rating']['rating'] > 0 ? $plugin['rating']['rating'] / 5 * 100 : 0;
$response->num_ratings = ! empty( $plugin['rating'] ) && ! empty( $plugin['rating']['count'] ) ? $plugin['rating']['count'] : 0;
$response->download_link = envato_market()->api()->deferred_download( $plugin['id'] );
break;
}
}
}
return $response;
}
/**
* Set the list of themes
*
* @since 1.0.0
*
* @param bool $forced Forces an API request. Default is 'false'.
* @param bool $use_cache Attempts to rebuild from the cache before making an API request.
*/
public function set_themes( $forced = false, $use_cache = false ) {
$themes_transient = get_site_transient( envato_market()->get_option_name() . '_themes' );
self::$themes = is_array($themes_transient) ? $themes_transient : array();
if ( empty(self::$themes) || true === $forced ) {
$themes = envato_market()->api()->themes();
foreach ( envato_market()->get_option( 'items', array() ) as $item ) {
if ( empty( $item ) ) {
continue;
}
if ( 'theme' === $item['type'] ) {
$request_args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $item['token'],
),
);
$request = envato_market()->api()->item( $item['id'], $request_args );
if ( false !== $request ) {
$themes[] = $request;
}
}
}
self::process_themes( $themes );
} elseif ( true === $use_cache ) {
self::process_themes( self::$themes['purchased'] );
}
}
/**
* Set the list of plugins
*
* @since 1.0.0
*
* @param bool $forced Forces an API request. Default is 'false'.
* @param bool $use_cache Attempts to rebuild from the cache before making an API request.
* @param array $args Used to remove or add a plugin during activate and deactivate routines.
*/
public function set_plugins( $forced = false, $use_cache = false, $args = array() ) {
$plugins_transient = get_site_transient( envato_market()->get_option_name() . '_plugins' );
self::$plugins = is_array($plugins_transient) ? $plugins_transient : array();
if ( empty(self::$plugins) || true === $forced ) {
$plugins = envato_market()->api()->plugins();
foreach ( envato_market()->get_option( 'items', array() ) as $item ) {
if ( empty( $item ) ) {
continue;
}
if ( 'plugin' === $item['type'] ) {
$request_args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $item['token'],
),
);
$request = envato_market()->api()->item( $item['id'], $request_args );
if ( false !== $request ) {
$plugins[] = $request;
}
}
}
self::process_plugins( $plugins, $args );
} elseif ( true === $use_cache ) {
self::process_plugins( self::$plugins['purchased'], $args );
}
}
/**
* Rebuild the themes array using the cache value if possible.
*
* @since 1.0.0
*
* @param mixed $filter Any data being filtered.
* @return mixed
*/
public function rebuild_themes( $filter ) {
self::set_themes( false, true );
return $filter;
}
/**
* Rebuild the plugins array using the cache value if possible.
*
* @since 1.0.0
*
* @param string $plugin The plugin to add or remove.
*/
public function rebuild_plugins( $plugin ) {
$remove = ( 'deactivated_plugin' === current_filter() ) ? true : false;
self::set_plugins(
false,
true,
array(
'plugin' => $plugin,
'remove' => $remove,
)
);
}
/**
* Normalizes a string to do a value check against.
*
* Strip all HTML tags including script and style & then decode the
* HTML entities so `&` will equal `&` in the value check and
* finally lower case the entire string. This is required becuase some
* themes & plugins add a link to the Author field or ambersands to the
* names, or change the case of their files or names, which will not match
* the saved value in the database causing a false negative.
*
* @since 1.0.0
*
* @param string $string The string to normalize.
* @return string
*/
public function normalize( $string ) {
return strtolower( html_entity_decode( wp_strip_all_tags( $string ) ) );
}
/**
* Process the themes and save the transient.
*
* @since 1.0.0
*
* @param array $purchased The purchased themes array.
*/
private function process_themes( $purchased ) {
if ( is_wp_error( $purchased ) ) {
$purchased = array();
}
$current = wp_get_theme()->get_template();
$active = array();
$installed = array();
$install = $purchased;
if ( ! empty( $purchased ) ) {
foreach ( wp_get_themes() as $theme ) {
/**
* WP_Theme object.
*
* @var WP_Theme $theme
*/
$template = $theme->get_template();
$title = $theme->get( 'Name' );
$author = $theme->get( 'Author' );
foreach ( $install as $key => $value ) {
if ( $this->normalize( $value['name'] ) === $this->normalize( $title ) && $this->normalize( $value['author'] ) === $this->normalize( $author ) ) {
$installed[ $template ] = $value;
unset( $install[ $key ] );
}
}
}
}
if ( isset( $installed[ $current ] ) ) {
$active[ $current ] = $installed[ $current ];
unset( $installed[ $current ] );
}
self::$themes['purchased'] = array_unique( $purchased, SORT_REGULAR );
self::$themes['active'] = array_unique( $active, SORT_REGULAR );
self::$themes['installed'] = array_unique( $installed, SORT_REGULAR );
self::$themes['install'] = array_unique( array_values( $install ), SORT_REGULAR );
set_site_transient( envato_market()->get_option_name() . '_themes', self::$themes, HOUR_IN_SECONDS );
}
/**
* Process the plugins and save the transient.
*
* @since 1.0.0
*
* @param array $purchased The purchased plugins array.
* @param array $args Used to remove or add a plugin during activate and deactivate routines.
*/
private function process_plugins( $purchased, $args = array() ) {
if ( is_wp_error( $purchased ) ) {
$purchased = array();
}
$active = array();
$installed = array();
$install = $purchased;
if ( ! empty( $purchased ) ) {
foreach ( self::wp_plugins( true ) as $slug => $plugin ) {
foreach ( $install as $key => $value ) {
if ( $this->normalize( $value['name'] ) === $this->normalize( $plugin['Name'] ) && $this->normalize( $value['author'] ) === $this->normalize( $plugin['Author'] ) && file_exists( WP_PLUGIN_DIR . '/' . $slug ) ) {
$installed[ $slug ] = $value;
unset( $install[ $key ] );
}
}
}
}
foreach ( $installed as $slug => $plugin ) {
$condition = false;
if ( ! empty( $args ) && $slug === $args['plugin'] ) {
if ( true === $args['remove'] ) {
continue;
}
$condition = true;
}
if ( $condition || is_plugin_active( $slug ) ) {
$active[ $slug ] = $plugin;
unset( $installed[ $slug ] );
}
}
self::$plugins['purchased'] = array_unique( $purchased, SORT_REGULAR );
self::$plugins['active'] = array_unique( $active, SORT_REGULAR );
self::$plugins['installed'] = array_unique( $installed, SORT_REGULAR );
self::$plugins['install'] = array_unique( array_values( $install ), SORT_REGULAR );
set_site_transient( envato_market()->get_option_name() . '_plugins', self::$plugins, HOUR_IN_SECONDS );
}
}
endif;
PK ! C( % admin/view/callback/section/oauth.phpnu [
' . esc_html__( 'envato.com', 'envato-market' ) . '' ); ?>
- admin()->get_generate_token_url() . '" target="_blank">' . esc_html__( 'clicking this link', 'envato-market' ) . '' ); ?>
-
PK ! <U
% admin/view/callback/section/items.phpnu [
PK ! % admin/view/callback/setting/token.phpnu [
PK ! Y Y % admin/view/callback/setting/items.phpnu [ get_option( 'items', array() );
?>
$item ) {
if ( empty( $item['name'] ) || empty( $item['token'] ) || empty( $item['id'] ) || empty( $item['type'] ) || empty( $item['authorized'] ) ) {
continue;
}
$class = 'success' === $item['authorized'] ? 'is-authorized' : 'not-authorized';
echo '
-
' . esc_html__( 'ID', 'envato-market' ) . ': ' . esc_html( $item['id'] ) . ' - ' . esc_html( $item['name'] ) . '
';
}
}
?>
PK ! b admin/view/callback/admin.phpnu [
PK ! &