Ejemplo n.º 1
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     // This MUST come before we get details about the plugins so the headers are correctly retrieved
     GitHub_Updater_GitHub_API::add_headers();
     // Get details of GitHub-sourced plugins
     $this->config = $this->get_plugin_meta();
     if (empty($this->config)) {
         return false;
     }
     if (isset($_GET['force-check']) && '1' === $_GET['force-check']) {
         $this->delete_all_transients('plugins');
     }
     foreach ((array) $this->config as $plugin) {
         switch ($plugin->type) {
             case 'github_plugin':
                 $repo_api = new GitHub_Updater_GitHub_API($plugin);
                 break;
             case 'bitbucket_plugin':
                 $repo_api = new GitHub_Updater_BitBucket_API($plugin);
                 break;
         }
         $this->{$plugin->type} = $plugin;
         $this->set_defaults($plugin->type);
         if ($repo_api->get_remote_info(basename($plugin->slug))) {
             $repo_api->get_repo_meta();
             $repo_api->get_remote_tag();
             $changelog = $this->get_changelog_filename($plugin->type);
             if ($changelog) {
                 $repo_api->get_remote_changes($changelog);
             }
             $plugin->download_link = $repo_api->construct_download_link();
         }
     }
     $this->make_force_check_transient('plugins');
     add_filter('pre_set_site_transient_update_plugins', array($this, 'pre_set_site_transient_update_plugins'));
     add_filter('plugins_api', array($this, 'plugins_api'), 99, 3);
     add_filter('upgrader_source_selection', array($this, 'upgrader_source_selection'), 10, 3);
     add_filter('http_request_args', array($this, 'no_ssl_http_request_args'), 10, 2);
     GitHub_Updater_Settings::$ghu_plugins = $this->config;
 }
Ejemplo n.º 2
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     // This MUST come before we get details about the themes so the headers are correctly retrieved
     GitHub_Updater_GitHub_API::add_headers();
     // Get details of git sourced themes
     $this->config = $this->get_theme_meta();
     if (empty($this->config)) {
         return false;
     }
     if (isset($_GET['force-check']) && '1' === $_GET['force-check']) {
         $this->delete_all_transients('themes');
     }
     foreach ((array) $this->config as $theme) {
         switch ($theme->type) {
             case 'github_theme':
                 $repo_api = new GitHub_Updater_GitHub_API($theme);
                 break;
             case 'bitbucket_theme':
                 $repo_api = new GitHub_Updater_BitBucket_API($theme);
                 break;
         }
         $this->{$theme->type} = $theme;
         $this->set_defaults($theme->type);
         if ($repo_api->get_remote_info('style.css')) {
             $repo_api->get_repo_meta();
             $repo_api->get_remote_tag();
             $changelog = $this->get_changelog_filename($theme->type);
             if ($changelog) {
                 $repo_api->get_remote_changes($changelog);
             }
             $theme->download_link = $repo_api->construct_download_link();
         }
         // Update theme transient with rollback data for single install
         if (!empty($_GET['rollback']) && $_GET['theme'] === $theme->repo && !is_multisite()) {
             $this->tag = $_GET['rollback'];
             $updates_transient = get_site_transient('update_themes');
             $rollback = array('new_version' => $this->tag, 'url' => $theme->uri, 'package' => $repo_api->construct_download_link($this->tag));
             $updates_transient->response[$theme->repo] = $rollback;
             set_site_transient('update_themes', $updates_transient);
         }
         // Remove WordPress update row in theme row, only in multisite
         // Add update row to theme row, only in multisite for WP < 3.8
         if (is_multisite() || get_bloginfo('version') < 3.8) {
             add_action('after_theme_row', array($this, 'remove_after_theme_row'), 10, 2);
             if (!$this->tag) {
                 add_action("after_theme_row_{$theme->repo}", array($this, 'wp_theme_update_row'), 10, 2);
             }
         }
     }
     $this->make_force_check_transient('themes');
     $update = array('do-core-reinstall', 'do-core-upgrade');
     if (empty($_GET['action']) || !in_array($_GET['action'], $update, true)) {
         add_filter('pre_set_site_transient_update_themes', array($this, 'pre_set_site_transient_update_themes'));
     }
     add_filter('themes_api', array($this, 'themes_api'), 99, 3);
     add_filter('upgrader_source_selection', array($this, 'upgrader_source_selection'), 10, 3);
     add_filter('http_request_args', array($this, 'no_ssl_http_request_args'), 10, 2);
     if (!is_multisite()) {
         add_filter('wp_prepare_themes_for_js', array($this, 'customize_theme_update_html'));
     }
     GitHub_Updater_Settings::$ghu_themes = $this->config;
 }
 /**
  * Create and return settings fields.
  *
  * @return void
  */
 public function ghu_tokens()
 {
     $ghu_options_keys = array();
     $ghu_tokens = array_merge(self::$ghu_plugins, self::$ghu_themes);
     foreach ($ghu_tokens as $token) {
         $type = '';
         $setting_field = array();
         $ghu_options_keys[$token->repo] = null;
         // Check to see if it's a private repo
         if ($token->private) {
             if (false !== strpos($token->type, 'github') && !self::$github_private) {
                 self::$github_private = true;
             }
             if (false !== strpos($token->type, 'bitbucket') && !self::$bitbucket_private) {
                 self::$bitbucket_private = true;
             }
         }
         // Next if not a private repo
         if (!$token->private) {
             continue;
         }
         if (false !== strpos($token->type, 'theme')) {
             $type = __('Theme: ', 'github-updater');
         }
         $setting_field['id'] = $token->repo;
         $setting_field['title'] = $type . $token->name;
         $setting_field['page'] = 'github-updater';
         if (false !== strpos($token->type, 'github')) {
             $setting_field['section'] = 'github_id';
         }
         if (false !== strpos($token->type, 'bitbucket')) {
             $setting_field['section'] = 'bitbucket_id';
         }
         add_settings_field($setting_field['id'], $setting_field['title'], array($this, 'token_callback'), $setting_field['page'], $setting_field['section'], $setting_field['id']);
         register_setting('github_updater', $setting_field['id'], array($this, 'sanitize'));
     }
     // Unset options that are no longer present
     $ghu_unset_keys = array_diff_key(parent::$options, $ghu_options_keys);
     if (!empty($ghu_unset_keys)) {
         foreach ($ghu_unset_keys as $key => $value) {
             unset(parent::$options[$key]);
         }
         update_site_option('github_updater', parent::$options);
     }
 }