Пример #1
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     /*
      * Get details of git sourced plugins.
      */
     $this->config = $this->get_plugin_meta();
     if (empty($this->config)) {
         return false;
     }
     if (isset($_GET['force-check'])) {
         $this->delete_all_transients('plugins');
     }
     foreach ((array) $this->config as $plugin) {
         switch ($plugin->type) {
             case 'github_plugin':
                 $repo_api = new GitHub_API($plugin);
                 break;
             case 'bitbucket_plugin':
                 $repo_api = new Bitbucket_API($plugin);
                 break;
             case 'gitlab_plugin':
                 $repo_api = new GitLab_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);
             }
             $repo_api->get_remote_readme();
             $plugin->download_link = $repo_api->construct_download_link();
         }
         /*
          * Update plugin transient with rollback (branch switching) data.
          */
         if (!empty($_GET['rollback']) && (isset($_GET['plugin']) && $_GET['plugin'] === $plugin->slug)) {
             $this->tag = $_GET['rollback'];
             $updates_transient = get_site_transient('update_plugins');
             $rollback = array('slug' => $plugin->repo, 'plugin' => $plugin->slug, 'new_version' => $this->tag, 'url' => $plugin->uri, 'package' => $repo_api->construct_download_link(false, $this->tag));
             $updates_transient->response[$plugin->slug] = (object) $rollback;
             set_site_transient('update_plugins', $updates_transient);
         }
         add_action("after_plugin_row_{$plugin->slug}", array(&$this, 'wp_plugin_update_row'), 15, 3);
     }
     $this->make_force_check_transient('plugins');
     add_filter('plugin_row_meta', array(&$this, 'plugin_row_meta'), 10, 2);
     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('Fragen\\GitHub_Updater\\API', 'http_request_args'), 10, 2);
     Settings::$ghu_plugins = $this->config;
 }