123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- if (!class_exists("plug_update_plugin")) {
- class plug_update_plugin {
- function __construct($ns) {
- $this->title = __("Update plugin", "dagsopt");
- $this->pluginname = $ns->pluginname;
- $this->file = $ns->file;
- $this->ns = $ns;
- $this->status = "";
- $this->possible = false;
- }
- function start() {
- register_activation_hook(plugin_basename($this->file), array(&$this, 'activatePlugin'));
- register_deactivation_hook(plugin_basename($this->file), array(&$this, 'deactivatePlugin'));
- add_action($this->pluginname . 'UpdateCheck', array(&$this, 'check_update'));
- add_filter('http_request_args', array(&$this, 'updates_exclude'), 5, 2);
- if (isset($_REQUEST["checkforupdates"])) {
- $this->check_update();
- }
- }
- function activatePlugin() {
- wp_schedule_event(time(), 'hourly', $this->pluginname . 'UpdateCheck');
- }
- function deactivatePlugin() {
- wp_clear_scheduled_hook($this->pluginname . 'UpdateCheck');
- }
- /*SELF UPDATE*/
- function check_update() {
- global $wp_version;
- $plugin_folder = plugin_basename(dirname($this->file));
- $plugin_file = basename(($this->file));
- if (defined('WP_INSTALLING')) {
- return false;
- }
- $response = wp_remote_get($this->ns->update_check_url);
- list($version) = explode('|', $response['body']);
- $version = trim($version);
- $urlx = "https://git.tum.dk/tum.dk/dagsplug/archive/" . $version . ".zip";
- $this->status = 'Remote version: ' . $version . " URL: " . $urlx . ":::";
- $this->possible = false;
- if ($this->plugin_get("Version") == $version) {
- return false;
- }
- $this->possible = true;
- $plugin_transient = get_site_transient('update_plugins');
- $a = array(
- 'slug' => $plugin_folder,
- 'new_version' => $version,
- 'url' => $this->plugin_get("AuthorURI"),
- 'package' => $urlx,
- );
- $o = (object) $a;
- $plugin_transient->response[$plugin_folder . '/' . $plugin_file] = $o;
- set_site_transient('update_plugins', $plugin_transient);
- }
- function updates_exclude($r, $url) {
- if (0 !== strpos($url, 'http://api.wordpress.org/plugins/update-check')) {
- return $r;
- }
- // Not a plugin update request. Bail immediately.
- $plugins = unserialize($r['body']['plugins']);
- unset($plugins->plugins[plugin_basename($this->file)]);
- unset($plugins->active[array_search(plugin_basename($this->file), $plugins->active)]);
- $r['body']['plugins'] = serialize($plugins);
- return $r;
- }
- function plugin_get($i) {
- if (!function_exists('get_plugins')) {
- require_once ABSPATH . 'wp-admin/includes/plugin.php';
- }
- $plugin_folder = get_plugins('/' . plugin_basename(dirname($this->file)));
- $plugin_file = basename(($this->file));
- return $plugin_folder[$plugin_file][$i];
- }
- function admin_line() {
- ?>
- <a href="/wp-admin/admin.php?page=dagsopt-options&checkforupdates"><?php echo (__("Check for updates", "dagsopt")) ?></a>
- <br>
- <?php echo ($this->status); ?>
- <?php
- if (current_user_can('update_plugins') && $this->possible) {
- $url = wp_nonce_url(self_admin_url('update.php?action=upgrade-plugin&plugin=' . $this->ns->filename), 'upgrade-plugin_' . $this->ns->filename);
- echo ('<a href="' . $url . '">' . __("Update", "dagsopt") . '</a>');
- }
- ?>
- <?php
- }
- }
- global $plug_update_plugin;
- $plug_update_plugin = new plug_update_plugin($this);
- $this->dagsopt['plug_update_plugin'] = $plug_update_plugin;
- }
|