# vimeography/2.4.9/lib/update.php

Vimeography: Vimeo Video Gallery WordPress Plugin, version 2.4.9. 512 lines.

- Page: https://pluginprobe.com/plugins/vimeography/2.4.9/code/lib/update.php
- Raw: https://pluginprobe.com/plugins/vimeography/2.4.9/raw/lib/update.php
- Modified: 2026-08-04T14:43:16+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/vimeography/2.4.9/code/lib/update.php#L10-L20`.

```php
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;

class Vimeography_Update {
  /**
   * All of the Vimeography activation keys that the user has stored.
   *
   * Example:
   *
   *   array(1) {
   *     [0]=>
   *     object(stdClass)#472 (3) {
   *       ["activation_key"]=>
   *       string(16) "n0Ae9UP49sNfw5aFGxiyn7mzi09c1Ua7"
   *       ["plugin_name"]=>
   *       string(19) "vimeography-journey"
   *       ["product_name"]=>
   *       string(7) "Journey"
   *     }
   *   }
   *
   * @var array
   */
  private $_activation_keys;

  /**
   * The endpoint of the Vimeography Updater API.
   * this is the URL our updater / license checker pings.
   *
   * This should be the URL of the site with EDD installed
   *
   * @var string
   */
  private $_endpoint = 'https://vimeography.com';

  /**
   * [__construct description]
   */
  public function __construct() {
    //delete_site_option('vimeography_activation_keys');
    $activation_keys = get_site_option('vimeography_activation_keys');
    $this->_activation_keys  = $activation_keys ? $activation_keys : array();

		// Setup hooks
		$this->_includes();
		$this->_hooks();
		$this->_vimeography_auto_updater();
  }

	/**
	 * Include the EDD updater class
	 *
	 * @access  private
	 * @return  void
	 */
	private function _includes() {
		if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
      require_once 'EDD_SL_Plugin_Updater.php';
    }
	}

	/**
	 * Setup hooks
	 *
	 * @access  private
	 * @return  void
	 */
	private function _hooks() {

    // Add activation key message for plugins with missing keys
    add_action( 'load-plugins.php', array( $this, 'vimeography_check_for_missing_activation_keys' ) );

    // Force EDD Software Licensing to ignore the X-Accel-Redirect header
    // (évite les problèmes de téléchargement de mises à jour derrière certains serveurs).
    add_filter( 'edd_ignore_x_accel_redirect', '__return_true' );

	}

  /**
   * Activate the license key
   *
   * @access  public
   * @return  void
   */
  public function activate_license($license) {

    $key = str_replace('-', '', strtoupper( sanitize_text_field( $license ) ) );

    // Ignore if this is a duplicate incoming key.
    if ( $this->vimeography_check_if_activation_key_exists( $key ) ) {
      return;
    }

    // Lookup the product name associated with this license key before
    // attempting activation. This allows activate_license to succeed even on
    // EDD servers that require item_name (i.e. without EDD_BYPASS_NAME_CHECK).
    $item_name = $this->_vimeography_lookup_item_name( $key );

    // Data to send to the API
    $api_params = array(
      'edd_action' => 'activate_license',
      'license'    => $key,
      'url'        => urlencode( home_url() ),
    );

    if ( ! empty( $item_name ) ) {
      $api_params['item_name'] = urlencode( $item_name );
    }

    // Call the API
    $response = wp_remote_get(
      add_query_arg( $api_params, $this->_endpoint),
      array(
        'timeout'   => 15,
        'sslverify' => true
      )
    );

    // Make sure there are no errors
    if ( is_wp_error( $response ) ) {
      throw new Exception( wp_kses_post(__('The HTTP Request failed: ' . $response->get_error_message(), 'vimeography') ));
    }

    // Decode license data
    $license_data = json_decode( wp_remote_retrieve_body( $response ) );

    if ( ! is_object( $license_data ) ) {
      throw new Exception( wp_kses_post(__('The license server returned an invalid response.', 'vimeography') ));
    }

    if ( ! empty( $license_data->success ) AND isset( $license_data->license ) AND $license_data->license === 'valid' ) {
      $this->_vimeography_add_activation_key( $key, $license_data );
      return TRUE;
    } else {
      $error = isset( $license_data->error ) ? $license_data->error : '';
      // Add failed message
      switch ($error) {
        case 'missing': case 'revoked':
          throw new Exception( wp_kses_post(__('That license key could not be found in our system.', 'vimeography') ));
        case 'no_activations_left':
          throw new Exception( wp_kses_post(__('You have reached the max number of sites that this license can be used on.', 'vimeography') ));
        case 'expired':
          throw new Exception( wp_kses_post(__('The license key you entered has expired. Please visit http://vimeography.com to renew it.', 'vimeography') ));
        case 'key_mismatch':
          throw new Exception( wp_kses_post(__('The license key you entered does not match the one we have on file.', 'vimeography') ));
        case 'license_not_activable':
          throw new Exception( wp_kses_post(__('Looks like you are trying to activate your bundle license. Please activate each of the products in your bundle separately by using their respective individual licenses.', 'vimeography') ));
        default:
          throw new Exception( wp_kses_post(__('Unknown error: ' . $error, 'vimeography') ));
      }
    }
  }

  /**
   * Ask the Vimeography EDD endpoint which product is associated with a given
   * license key.
   *
   * Implementation note: the `check_license` endpoint does not return the
   * product name on Vimeography's server (item_name is empty). However, calling
   * `activate_license` *without* the `url` parameter triggers a `missing_url`
   * error response that includes both `item_name` and `vimeography_product_name`
   * in its payload — and does NOT consume an activation, since the request
   * aborts on the server before the site count is incremented.
   *
   * @access  protected
   * @param   string $key  Normalized license key.
   * @return  string       Product name, or empty string if it could not be resolved.
   */
  protected function _vimeography_lookup_item_name( $key ) {
    $response = wp_remote_get(
      add_query_arg( array(
        'edd_action' => 'activate_license',
        'license'    => $key,
      ), $this->_endpoint ),
      array(
        'timeout'   => 15,
        'sslverify' => true,
      )
    );

    if ( is_wp_error( $response ) ) {
      return '';
    }

    $data = json_decode( wp_remote_retrieve_body( $response ) );

    if ( ! is_object( $data ) ) {
      return '';
    }

    if ( ! empty( $data->item_name ) ) {
      return $data->item_name;
    }

    if ( ! empty( $data->vimeography_product_name ) ) {
      return $data->vimeography_product_name;
    }

    return '';
  }

  /**
   * Deactivate the license key
   *
   * @access  public
   * @return  void
   */
  public function deactivate_license( $license ) {
    $key = str_replace('-', '', strtoupper( sanitize_text_field( $license ) ) );

    // Data to send to the API
    $api_params = array(
      'edd_action' => 'deactivate_license',
      'license'    => $key,
      //'item_name'  => urlencode( $this->item_name ), // the name of our product in EDD
      'url'        => urlencode( home_url() )
    );

    // Call the API
    $response = wp_remote_get(
      add_query_arg( $api_params, $this->_endpoint ),
      array(
        'timeout'   => 15,
        'sslverify' => true
      )
    );

    // Make sure there are no errors
    if ( is_wp_error( $response ) ) {
      return;
    }

    // Decode the license data
    $license_data = json_decode( wp_remote_retrieve_body( $response ) );

    // Remove the key even if deactivation fails
    $this->_vimeography_remove_activation_key( $key );

    if ( ! is_object( $license_data ) || empty( $license_data->success ) ) {
      throw new Exception( wp_kses_post(__('That license key has been removed from your site, but could not be deactivated in our system.', 'vimeography')) );
    }
  }

  /**
   * [check_license description]
   * @return [type] [description]
   */
  public function check_license( $license ) {

    // Data to send to the API
    $api_params = array(
      'edd_action' => 'check_license',
      'license'    => $license->activation_key,
      //'item_name'  => urlencode( $this->item_name ), // the name of our product in EDD
      'url'        => urlencode( home_url() )
    );

    // Call the API
    $response = wp_remote_get(
      add_query_arg( $api_params, $this->_endpoint ),
      array(
        'timeout'   => 15,
        'sslverify' => true
      )
    );

    // Make sure there are no errors
    if ( is_wp_error( $response ) ) {
      return FALSE;
    }

    // Decode the license data
    return json_decode( wp_remote_retrieve_body( $response ) );
  }

  /**
   * Add a plugins page message to any Vimeography add-ons that are installed,
   * but that do not have an activation key associated with the installation.
   *
   * @return void
   */
  public function vimeography_check_for_missing_activation_keys() {

    $addons = Vimeography::get_instance()->addons->installed_addons;

    if ( ! empty( $addons ) ) {
      // If the activation key is not found for the installed plugin,
      // add the plugin message hook
      $addons_with_missing_keys = array_filter($addons, array($this, 'vimeography_is_addon_missing_activation_key') );

      if ( ! empty( $addons_with_missing_keys ) ) {
        foreach ( $addons_with_missing_keys as $plugin ) {
          $hook = 'after_plugin_row_' . $plugin['basename'];
          add_action( $hook, array($this, 'vimeography_addon_update_message'), 10, 2 );
        }
      }
    }
  }

  /**
   * Loop through the activations keys to check if one exists for the
   * given Vimeography addon plugin headers.
   *
   * @var    $plugin  Meta headers for a Vimeography addon plugin.
   * @return bool     TRUE if missing, FALSE if found
   */
  public function vimeography_is_addon_missing_activation_key($plugin) {
    $plugins_with_keys = array();

    if ( ! empty($this->_activation_keys) ) {
      foreach ($this->_activation_keys as $key) {
        $plugins_with_keys[] = $key->plugin_name;
      }
    }

    return !in_array( $plugin['slug'], $plugins_with_keys );
  }

  /**
   * Loop through the activations keys to check if one exists for the
   * given Vimeography activation key.
   *
   * @var    $key  string  Activation key.
   * @return bool          TRUE if exists, FALSE if not found
   */
  public function vimeography_check_if_activation_key_exists($key) {
    $result = FALSE;

    if ( ! empty($this->_activation_keys) ) {
      foreach ( $this->_activation_keys as $entry ) {
        if ( $entry->activation_key == $key ) {
          $result = TRUE;
        }
      }
    }

    return $result;
  }

  /**
   * Add the activation key to the database.
   *
   * @var    $key          string  Activation key.
   * @var    $license_data array
   * @return bool          TRUE if successful, FALSE if failed
   */
  protected function _vimeography_add_activation_key( $key, $license_data ) {
    if ( ! is_object( $license_data ) ) {
      return FALSE;
    }

    $plugin_slug = isset( $license_data->vimeography_plugin_slug )
      ? sanitize_key( (string) $license_data->vimeography_plugin_slug )
      : '';

    if ( empty( $plugin_slug ) ) {
      return FALSE;
    }

    $entry = new stdClass();
    $entry->activation_key   = sanitize_text_field( (string) $key );
    $entry->plugin_name      = $plugin_slug;
    $entry->product_name     = isset( $license_data->vimeography_product_name )
      ? sanitize_text_field( (string) $license_data->vimeography_product_name )
      : '';
    $entry->expires          = isset( $license_data->expires )
      ? sanitize_text_field( (string) $license_data->expires )
      : '';
    $entry->status           = isset( $license_data->license )
      ? sanitize_key( (string) $license_data->license )
      : '';
    $entry->limit            = isset( $license_data->license_limit )
      ? intval( $license_data->license_limit )
      : 0;
    $entry->activations_left = isset( $license_data->activations_left )
      ? intval( $license_data->activations_left )
      : 0;

    $this->_activation_keys[] = $entry;
    return update_site_option('vimeography_activation_keys', array_values( $this->_activation_keys ) );
  }

  /**
   * Remove the activation key to the database.
   *
   * @var    $key  string  Activation key.
   * @return bool          TRUE if successful, FALSE if failed
   */
  protected function _vimeography_remove_activation_key( $key ) {
    if ( ! empty( $this->_activation_keys ) ) {
      foreach ( $this->_activation_keys as $i => $entry ) {
        if ( $entry->activation_key === $key ) {
          unset( $this->_activation_keys[$i] );
        }
      }

      return update_site_option( 'vimeography_activation_keys', array_values( $this->_activation_keys ) );
    }

    return FALSE;
  }

  /**
   * Add a reminder to add the activation key to receives updates
   * for the installed Vimeography theme.
   *
   * @param  string $plugin_basename  Folder and filename, eg:
   * @return [type]              [description]
   */
  public function vimeography_addon_update_message($plugin_basename, $plugin_data) {
    $ineligible = array(
      'Vimeography Theme: Bugsauce',
      'Vimeography Theme: Ballistic',
      'Vimeography Theme: Single'
    );

    if ( in_array( $plugin_data['Name'], $ineligible ) ) {
      return;
    }

    echo '<tr class="plugin-update-tr"><td colspan="3" class="plugin-update"><div class="update-message notice inline notice-warning notice-alt">';
    echo '<span style="display: block; padding: 5px;">';
    printf(
    wp_kses_post(
          __(
              'Hey! Don\'t forget to <a title="Activate my Vimeography Addon" href="%1$sadmin.php?page=vimeography-manage-activations">enter your activation key</a> to receive the latest updates for the %2$s plugin.',
              'vimeography'
          )
      ),
          esc_url(get_admin_url()), // Premier argument %1$s
          esc_html($plugin_data['Name']) // Deuxième argument %2$s
    );
    echo '</span>';
    echo '</div></td></tr>';
  }

  /**
   * Auto updater
   *
   * @access  protected
   * @return  void
   */
  protected function _vimeography_auto_updater() {
    // We only need to check for updates if an activation key exists
    // in the options table.
    if ( ! empty( $this->_activation_keys ) ) {
      foreach ( $this->_activation_keys as $plugin ) {

        $plugin_path = self::_vimeography_get_plugin_path( $plugin->plugin_name );

        if ( $plugin_path ) {
          // Get the plugin headers
          $headers = get_file_data( $plugin_path, array('version' => 'Version') );

          // setup the updater
          new EDD_SL_Plugin_Updater(
            $this->_endpoint,
            $plugin_path,
            array(
              'version'   => $headers['version'],
              'license'   => trim($plugin->activation_key),
              'item_name' => $plugin->product_name,
              'author'    => 'Dave Kiss',
            )
          );
        }
      }
    }
  }

  /**
   * Get the absolute path to the provided plugin name.
   *
   * @access  protected
   * @return  string
   */
  protected function _vimeography_get_plugin_path( $plugin_name ) {
    // Defense in depth: even though $plugin_name is stored via sanitize_key()
    // in _vimeography_add_activation_key(), reject anything that isn't a
    // strict plugin slug here to prevent any form of path traversal on the
    // WPMU_PLUGIN_DIR / WP_PLUGIN_DIR concatenation below.
    $plugin_name = (string) $plugin_name;

    if ( ! preg_match( '/^[a-z0-9][a-z0-9_-]*$/', $plugin_name ) ) {
      return FALSE;
    }

    $basename = '/' . trailingslashit( $plugin_name ) . $plugin_name . '.php';

    if ( ! is_file( $dir = WPMU_PLUGIN_DIR . $basename ) ) {
      if ( ! is_file( $dir = WP_PLUGIN_DIR . $basename ) ) {
        return FALSE;
      }
    }

    return $dir;
  }

  /**
   * Sets the activation keys in the class
   *
   * @param  array  $keys [description]
   * @return [type]       [description]
   */
  public function vimeography_set_activation_keys($keys = array()) {
    $this->_activation_keys = $keys;
    return $this;
  }

}

```
