/**
  * Serve the request to this endpoint.
  *
  * @param \ArrayAccess $get
  * @param \ArrayAccess $post
  *
  * @return Response
  *
  * @throws Exception|\Exception
  */
 public function serve(\ArrayAccess $get, \ArrayAccess $post)
 {
     $now = \ITELIC\make_date_time();
     $expires = $now->add(new \DateInterval("P1D"));
     $release = $this->activation->get_key()->get_product()->get_latest_release_for_activation($this->activation);
     // this really is a safeguard.
     if (!$release) {
         throw new \UnexpectedValueException(__("No releases available for this product.", Plugin::SLUG));
     }
     if ($release->get_type() == Release::TYPE_SECURITY) {
         $notice = $release->get_meta('security-message', true);
     } else {
         if ($release->get_type() == Release::TYPE_MAJOR) {
             $notice = __("Warning! This is a major upgrade. Make sure you backup your website before updating.", Plugin::SLUG);
         } else {
             $notice = '';
         }
     }
     /**
      * Filters the upgrade notice sent back from the API.
      *
      * @since 1.0
      *
      * @param string  $notice
      * @param Release $release
      */
     $notice = apply_filters('itelic_get_release_upgrade_notice', $notice, $release);
     // if the installed version of the software is passed to the API,
     // and the installed version is greater than the version on record, create an update record
     // this accounts for manually updating the theme or plugin
     if (isset($get['installed_version'])) {
         $installed = itelic_get_release_by_version($this->key->get_product()->ID, $get['installed_version']);
         if ($installed && version_compare($installed->get_version(), $this->activation->get_release()->get_version(), '>')) {
             Update::create($this->activation, $installed);
         }
     }
     $info = array('version' => $release->get_version(), 'package' => \ITELIC\generate_download_link($this->activation), 'expires' => $expires->format(\DateTime::ISO8601), 'upgrade_notice' => $notice, 'type' => $release->get_type());
     /**
      * Filter the version info returned by the API.
      *
      * @since 1.0
      *
      * @param array   $info
      * @param Key     $key
      * @param Product $product
      */
     $info = apply_filters('itelic_api_version_info', $info, $this->key, $this->key->get_product());
     return new Response(array('success' => true, 'body' => array('list' => array($this->key->get_product()->ID => $info))));
 }
Esempio n. 2
0
/**
 * Clear a key's active count cache.
 *
 * @since 1.0
 *
 * @param Activation $activation
 */
function clear_key_active_count_and_total_activation_count_cache(Activation $activation)
{
    wp_cache_delete($activation->get_key()->get_key(), 'itelic-key-active-count');
    $releases = itelic_get_releases(array('product' => $activation->get_key()->get_product()->ID, 'status' => array(Release::STATUS_ACTIVE, Release::STATUS_PAUSED)));
    foreach ($releases as $release) {
        wp_cache_delete($release->get_pk(), 'itelic-release-active-activations');
    }
}
/**
 * Generates query args to be appended to the download URL.
 *
 * @internal
 *
 * @since 1.0
 *
 * @param Activation $activation
 * @param \DateTime  $expires
 *
 * @return array
 */
function generate_download_query_args(Activation $activation, \DateTime $expires)
{
    $args = array('activation' => (int) $activation->get_pk(), 'key' => $activation->get_key()->get_key(), 'expires' => (int) $expires->getTimestamp());
    $token = hash_hmac('md5', serialize($args), wp_salt());
    $args['token'] = $token;
    /**
     * Filters the query args generated for downloading a software update.
     *
     * @since 1.0
     *
     * @param array      $args       Query args.
     * @param Activation $activation Activation record download is delivered to.
     * @param \DateTime  $expires    Expiration date for arguments. Link MUST function until time given.
     */
    $args = apply_filters('itelic_generate_download_query_args', $args, $activation, $expires);
    return $args;
}
 /**
  * Get data to display for a single key.
  *
  * @param \ITELIC\Activation $activation
  * @param bool               $raw
  *
  * @return array
  */
 protected function get_fields_for_object(\ITELIC\Activation $activation, $raw = false)
 {
     if ($activation->get_deactivation()) {
         $deactivated = $activation->get_deactivation()->format(DateTime::ISO8601);
     } else {
         $deactivated = '-';
     }
     return array('id' => $activation->get_id(), 'key' => $activation->get_key()->get_key(), 'location' => $activation->get_location(), 'status' => $activation->get_status(!$raw), 'activated' => $activation->get_activation()->format(DateTime::ISO8601), 'deactivated' => $deactivated, 'version' => $activation->get_release() ? $activation->get_release()->get_version() : 'Unknown', 'track' => $activation->get_meta('track', true) ? $activation->get_meta('track', true) : 'stable');
 }