public static function process_server_response($response, $cached = false) { if (empty($response['packages'])) { return; } require_once $GLOBALS['ithemes_updater_path'] . '/keys.php'; require_once $GLOBALS['ithemes_updater_path'] . '/packages.php'; $keys = array(); foreach ($response['packages'] as $package => $data) { if (isset($data['key'])) { $keys[$package] = $data['key']; } else { if (isset($data['status']) && 'inactive' == $data['status']) { $keys[$package] = ''; } } } Ithemes_Updater_Keys::set($keys); $details = Ithemes_Updater_Packages::get_full_details($response); $updates = array('update_themes' => array(), 'update_plugins' => array(), 'expiration' => $details['expiration']); if (!$cached) { $updates['timestamp'] = time(); } if (isset($response['timeout_multiplier'])) { $updates['timeout-multiplier'] = $response['timeout_multiplier']; } if (!isset($updates['timeout-multiplier']) || $updates['timeout-multiplier'] < 1) { $updates['timeout-mulitplier'] = 1; } else { if ($updates['timeout-multiplier'] > 10) { $updates['timeout-mulitplier'] = 10; } } $use_ssl = $GLOBALS['ithemes-updater-settings']->get_option('use_ssl'); foreach ($details['packages'] as $path => $data) { if (empty($data['package-url']) || version_compare($data['installed'], $data['available'], '>=')) { continue; } $force_minor_version_update = $GLOBALS['ithemes-updater-settings']->get_option('force_minor_version_update'); $quick_releases = $GLOBALS['ithemes-updater-settings']->get_option('quick_releases'); if (isset($data['upgrade']) && !$data['upgrade'] && !$force_minor_version_update && !$quick_releases) { continue; } if (!$use_ssl) { $data['package-url'] = preg_replace('/^https/', 'http', $data['package-url']); } if ('plugin' == $data['type']) { $update = array('id' => 0, 'slug' => dirname($path), 'new_version' => $data['available'], 'url' => $data['info-url'], 'package' => $data['package-url']); $update = (object) $update; } else { $update = array('new_version' => $data['available'], 'url' => self_admin_url('plugin-install.php?tab=plugin-information&plugin=' . dirname($path) . '§ion=changelog&TB_iframe=true&width=600&height=800'), 'package' => $data['package-url']); $path = dirname($path); } $updates["update_{$data['type']}s"][$path] = $update; } $GLOBALS['ithemes-updater-settings']->update_options($updates); }
public static function get_local_details() { require_once $GLOBALS['ithemes_updater_path'] . '/keys.php'; $all_packages = self::get_all(); $keys = Ithemes_Updater_Keys::get(); $packages = array(); foreach ($all_packages as $file => $slug) { $packages[$slug][] = $file; } foreach ($packages as $slug => $paths) { $packages[$slug] = array_unique($paths); } $details = array(); foreach ($packages as $package => $paths) { foreach ($paths as $path) { $plugin_path = preg_replace('/^' . preg_quote(WP_PLUGIN_DIR, '/') . '/', '', $path); if ($plugin_path != $path) { $type = 'plugin'; $rel_path = preg_replace('|^[/\\\\]|', '', $plugin_path); $plugin_data = get_plugin_data($path, false, false); $version = $plugin_data['Version']; $info_url = $plugin_data['PluginURI']; } else { $type = 'theme'; $dir = basename(dirname($path)); $rel_path = "{$dir}/" . basename($path); if (function_exists('wp_get_theme')) { $theme_data = wp_get_theme($dir); $version = $theme_data->get('Version'); $info_url = $theme_data->get('ThemeURI'); } else { $theme_data = get_theme($dir); $version = $theme_data['Version']; $info_url = ''; } } $details[$rel_path] = array('type' => $type, 'package' => $package, 'installed' => $version, 'info-url' => $info_url, 'key' => isset($keys[$package]) ? $keys[$package] : ''); } } return $details; }
private static function get_request_package_details($desired_packages = array()) { require_once $GLOBALS['ithemes_updater_path'] . '/packages.php'; require_once $GLOBALS['ithemes_updater_path'] . '/keys.php'; $all_packages = Ithemes_Updater_Packages::get_local_details(); reset($desired_packages); if (empty($desired_packages)) { $desired_packages = $all_packages; } else { if (is_numeric(key($desired_packages))) { $new_desired_packages = array(); foreach ($all_packages as $path => $details) { foreach ($desired_packages as $package) { if ($package != $details['package']) { continue; } $new_desired_packages[$path] = $details; break; } } $desired_packages = $new_desired_packages; } } $packages = array(); $keys = Ithemes_Updater_Keys::get(); $package_slugs = array(); foreach ($desired_packages as $data) { $package_slugs[] = $data['package']; } $legacy_keys = Ithemes_Updater_Keys::get_legacy($package_slugs); $active_themes = array('stylesheet' => get_stylesheet_directory(), 'template' => get_template_directory()); $active_themes = array_unique($active_themes); foreach ($active_themes as $index => $path) { $active_themes[$index] = basename($path); } foreach ($desired_packages as $path => $data) { $key = isset($keys[$data['package']]) ? $keys[$data['package']] : ''; $package = array('ver' => $data['installed'], 'key' => $key); if (!empty($legacy_keys[$data['package']])) { $package['old-key'] = $legacy_keys[$data['package']]; } if ('plugins' == $data['type']) { $package['active'] = (int) is_plugin_active($path); } else { $dir = dirname($path); $package['active'] = (int) in_array($dir, $active_themes); if ($package['active'] && count($active_themes) > 1) { if ($dir == $active_themes['stylesheet']) { $package['child-theme'] = 1; } else { $package['parent-theme'] = 1; } } } $package_key = $data['package']; $counter = 0; while (isset($packages[$package_key])) { $package_key = "{$data['package']} ||| " . ++$counter; } $packages[$package_key] = $package; } if (!empty($legacy_keys)) { Ithemes_Updater_Keys::delete_legacy(array_keys($legacy_keys)); } return $packages; }