/** * @return string url */ function download_url($theme_name, $allow_cache = true) { if (empty($theme_name)) { $theme_temp = wp_get_theme(); $theme_name = $theme_temp->Name; } $installed_theme = $this->retrieve_installed_theme($theme_name); if ($installed_theme == null) { $transalated_message = __('The theme <b>:theme_name</b> is not installed.<br><i>If you are certain the theme it is installed, please contact support.</i>', 'rosa_txtd'); $this->errors = array(strtr($transalated_message, array(':theme_name' => $theme_name))); return null; } ob_start(); $purchased_themes = $this->api->wp_list_themes($allow_cache); $errors = $this->api->api_errors(); $internal_errors = ob_get_clean(); if (!empty($internal_errors) || $purchased_themes === false) { $transalated_message = __('TeamForest/Envato API error.', 'rosa_txtd'); $this->errors = array($transalated_message); return null; } if ($errors !== null) { $this->errors = array(__('Failed to retrieve theme list via Envato API.', 'rosa_txtd')); return null; } $marketplace_theme_data = null; foreach ($purchased_themes as $purchased) { if ($this->is_matching_themes($installed_theme, $purchased)) { if ($this->is_newer_version_available($installed_theme['Version'], $purchased->version)) { $marketplace_theme_data = $purchased; break; } else { // no new version available $transalated_message = __('There is no update available for the theme <b>:theme_name</b>', 'rosa_txtd'); $this->errors = array(strtr($transalated_message, array(':theme_name' => $theme_name))); return null; } } } if ($marketplace_theme_data == null) { $transalated_message = __('Failed to find <b>:theme_name</b> in your list of purchased themes. (please contact support)', 'rosa_txtd'); $this->errors = array(strtr($transalated_message, array(':theme_name' => $theme_name))); return null; } $result = $this->api->wp_download($marketplace_theme_data->item_id); if (is_array($result)) { $this->errors = $result; return null; } return $result; }
/** * Check for theme updates from Envato. * * @param array $args Envato and theme details for updating */ public function check_for_updates($updates) { // Only continue if this is our second time // running through the filter. if (!isset($updates->checked)) { return; } // If user can't install themes, this shouldn't // be happenning. if (!current_user_can('install_themes')) { return; } // Temporarily increase http_request_timeout to 300 seconds. add_filter('http_request_timeout', array($this, 'bumb_request_timeout')); // Tap into Envato API $envato_api = new Envato_Protected_API($this->args['envato_username'], $this->args['envato_api_key']); // Get themes purchased from this Envato user and re-format // as an array we can use to pull directly from. $purchased_themes = array(); $purchased = $envato_api->wp_list_themes(true); if (!empty($purchased)) { foreach ($purchased as $theme) { if ($theme->author_name == $this->args['author_name']) { $purchased_themes[$theme->theme_name] = array('item_id' => $theme->item_id, 'author_name' => $theme->author_name, 'version' => $theme->version); } } } // Get themes currently present in WordPress $installed_themes = wp_get_themes(); // Loop through current themes in WP directory and // check if we need to apply our updates. if ($installed_themes) { foreach ($installed_themes as $installed_theme_id => $installed_theme) { // Make sure the current installed theme is one of // the themes purchased from the current author. if (isset($purchased_themes[$installed_theme->Name])) { $current_theme = $purchased_themes[$installed_theme->Name]; if (version_compare($installed_theme->Version, $current_theme['version'], '<')) { if ($url = $envato_api->wp_download($current_theme['item_id'])) { // Get update rolling with WP $updates->response[$installed_theme->Stylesheet] = array('url' => apply_filters('themeblvd_envato_updates_changelog', 'http://themeblvd.com/changelog/?theme=' . $installed_theme->Template, $installed_theme, $current_theme), 'new_version' => $current_theme['version'], 'old_version' => $installed_theme->Version, 'package' => $url, 'type' => apply_filters('themeblvd_envato_updates_type', 'themeblvd-envato')); } } } } } // Put http_request_timeout back. remove_filter('http_request_timeout', array($this, 'bumb_request_timeout')); return $updates; }
public function check($updates) { $this->username = apply_filters("pixelentity_themes_update_username", $this->username); $this->apikey = apply_filters("pixelentity_themes_updater_apikey", $this->apikey); $this->authors = apply_filters("pixelentity_themes_updater_authors", $this->authors); if (isset($this->authors) && !is_array($this->authors)) { $this->authors = array($this->authors); } if (!isset($this->username) || !isset($this->apikey) || !isset($updates->checked)) { return $updates; } if (!class_exists("Envato_Protected_API")) { require_once "class-envato-protected-api.php"; } $api = new Envato_Protected_API($this->username, $this->apikey); add_filter("http_request_args", array(&$this, "http_timeout"), 10, 1); $purchased = $api->wp_list_themes(true); $installed = wp_get_themes(); $filtered = array(); foreach ($installed as $theme) { if ($this->authors && !in_array($theme->{'Author Name'}, $this->authors)) { continue; } $filtered[$theme->Name] = $theme; } if (is_array($purchased)) { foreach ($purchased as $theme) { if (isset($filtered[$theme->theme_name])) { // gotcha, compare version now $current = $filtered[$theme->theme_name]; if (version_compare($current->Version, $theme->version, '<')) { // bingo, inject the update if ($url = $api->wp_download($theme->item_id)) { $update = array("url" => "http://themeforest.net/item/theme/{$theme->item_id}", "new_version" => $theme->version, "package" => $url); $updates->response[$current->Stylesheet] = $update; } } } } } remove_filter("http_request_args", array(&$this, "http_timeout")); return $updates; }
/** * Sends a request to server, gets current plugins versions. * * @param object $transient Update transient option * @return object Update transient option */ public function check_for_update($transient) { if (isset($this->authors) && !is_array($this->authors)) { $this->authors = array($this->authors); } if (!isset($transient->checked)) { return $transient; } if (!class_exists("Envato_Protected_API")) { require_once "lib/class-envato-protected-api.php"; } $api = new Envato_Protected_API($this->options['username'], $this->options['api_key']); $purchased = $api->wp_list_themes(true); $installed = function_exists("wp_get_themes") ? wp_get_themes() : get_themes(); $filtered = array(); foreach ($installed as $theme) { if (isset($this->authors) && !in_array($theme->{'Author Name'}, $this->authors)) { continue; } $filtered[$theme->Name] = $theme; } foreach ($purchased as $theme) { if (isset($filtered[$theme->theme_name])) { // gotcha, compare version now $current = $filtered[$theme->theme_name]; if (version_compare($current->Version, $theme->version, '<')) { // bingo, inject the update if ($url = $api->wp_download($theme->item_id)) { $update = array("url" => "http://themeforest.net/item/theme/{$theme->item_id}", "new_version" => $theme->version, "package" => $url); $transient->response[$current->Stylesheet] = $update; } } } } return $transient; }