/** * 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)))); }
/** * Serve the request to this endpoint. * * @param \ArrayAccess $get * @param \ArrayAccess $post * * @return Response */ public function serve(\ArrayAccess $get, \ArrayAccess $post) { $readme = $this->key->get_product()->get_feature('licensing-readme'); $contributors = array(); if ($readme['author']) { $usernames = explode(',', $readme['author']); foreach ($usernames as $username) { $contributors[$username] = "//profiles.wordpress.org/{$username}"; } } $release = $this->key->get_product()->get_latest_release_for_activation($this->activation); $info = array('id' => $this->key->get_product()->ID, 'name' => $this->key->get_product()->post_title, 'description' => $this->key->get_product()->get_feature('description'), 'version' => $release->get_version(), 'tested' => $readme['tested'], 'requires' => $readme['requires'], 'contributors' => $contributors, 'last_updated' => empty($readme['last_updated']) ? '' : $readme['last_updated']->format(\DateTime::ISO8601), 'banner_low' => $readme['banner_low'], 'banner_high' => $readme['banner_high'], 'package_url' => \ITELIC\generate_download_link($this->activation), 'description_url' => get_permalink($this->key->get_product()->ID), 'changelog' => $this->key->get_product()->get_changelog(), 'sections' => array()); /** * Filter the product info returned by the API. * * @since 1.0 * * @param array $info * @param Product $product */ $info = apply_filters('itelic_api_product_info', $info, $this->key->get_product()); return new Response(array('success' => true, 'body' => array('list' => array($this->key->get_product()->ID => $info)))); }
public function missing_download_link_query_args_provider() { $key = $this->getMockBuilder('\\ITELIC\\Key')->disableOriginalConstructor()->getMock(); $key->method('get_key')->willReturn('abcd-1234'); $activation = $this->getMockBuilder('\\ITELIC\\Activation')->disableOriginalConstructor()->getMock(); $activation->method('get_pk')->willReturn(1); $activation->method('get_key')->willReturn($key); $link = \ITELIC\generate_download_link($activation); $args = array(); parse_str(parse_url($link, PHP_URL_QUERY), $args); $token = $args['token']; $expires = $args['expires']; $test_cases = array(); unset($args['key']); $test_cases['Link validates when missing key'] = array($args, false); $args['key'] = 'abcd-1234'; unset($args['activation']); $test_cases['Link validates when missing activation'] = array($args, false); $args['activation'] = 1; unset($args['expires']); $test_cases['Link validates when missing expires'] = array($args, false); $args['expires'] = $expires; unset($args['token']); $test_cases['Link validates when missing token'] = array($args, false); $args['token'] = $token; return $test_cases; }