/** * 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)))); }
/** * Create an Upgrade record. * * @since 1.0 * * @param Activation $activation * @param Release $release * @param \DateTime $update_date * @param string $previous_version * * @return Update|null * @throws DB_Exception */ public static function create(Activation $activation, Release $release, \DateTime $update_date = null, $previous_version = '') { if ($update_date === null) { $update_date = make_date_time(); } if (empty($previous_version) && $activation->get_release()) { $previous_version = $activation->get_release()->get_version(); } $data = array('activation' => $activation->get_id(), 'release_id' => $release->get_ID(), 'update_date' => $update_date->format("Y-m-d H:i:s"), 'previous_version' => $previous_version); $db = Manager::make_simple_query_object('itelic-updates'); $ID = $db->insert($data); $update = self::get($ID); if ($update) { $activation->set_release($release); /** * Fires when an update record is created. * * @since 1.0 * * @param Update $update */ do_action('itelic_create_update', $update); Cache::add($update); } return $update; }
/** * Get the activation row HTML. * * @since 1.0 * * @param Activation $activation * * @return string */ public function get_activation_row_html(Activation $activation) { $n_deactivate = wp_create_nonce('itelic-remote-deactivate-' . $activation->get_id()); $n_delete = wp_create_nonce('itelic-remote-delete-' . $activation->get_id()); ob_start(); ?> <tr> <td data-title="<?php _e("Location", Plugin::SLUG); ?> "> <?php echo $activation->get_location(); ?> </td> <td data-title="<?php _e("Status", Plugin::SLUG); ?> "> <?php echo $activation->get_status(true); ?> </td> <td data-title="<?php _e("Activation", Plugin::SLUG); ?> "> <?php echo \ITELIC\convert_gmt_to_local($activation->get_activation())->format($this->get_short_df()); ?> </td> <td data-title="<?php _e("Deactivation", Plugin::SLUG); ?> "> <?php if (null === ($d = $activation->get_deactivation())) { ?> <a href="javascript:" data-id="<?php echo esc_attr($activation->get_id()); ?> " data-nonce="<?php echo $n_deactivate; ?> " class="deactivate"> <?php _e("Deactivate", Plugin::SLUG); ?> </a> <?php } else { ?> <?php echo \ITELIC\convert_gmt_to_local($d)->format($this->get_short_df()); ?> <?php } ?> </td> <td data-title="<?php _e("Version", Plugin::SLUG); ?> "> <?php if (null === ($r = $activation->get_release())) { ?> <?php _e("Unknown", Plugin::SLUG); ?> <?php } else { ?> <?php printf('v%s', $r->get_version()); ?> <?php } ?> </td> <td data-title="<?php _e("Delete", Plugin::SLUG); ?> "> <button data-id="<?php echo esc_attr($activation->get_id()); ?> " class="remove-item" data-nonce="<?php echo $n_delete; ?> "> × </button> </td> </tr> <?php return ob_get_clean(); }
/** * 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'); }