diff --git a/includes/admin.php b/includes/admin.php
index 91cca9e40..6b1166524 100644
--- a/includes/admin.php
+++ b/includes/admin.php
@@ -120,14 +120,14 @@ public static function register_menu() {
array( __CLASS__, 'render_page' )
);
- $extension_obj = new WP_Stream_Extensions();
+ $extensions = WP_Stream_Extensions::get_instance();
self::$screen_id['extensions'] = add_submenu_page(
self::RECORDS_PAGE_SLUG,
__( 'Stream Extensions', 'stream' ),
__( 'Extensions', 'stream' ),
self::SETTINGS_CAP,
'wp_stream_extensions',
- array( $extension_obj, 'render_page' )
+ array( $extensions, 'render_page' )
);
// Register the list table early, so it associates the column headers with 'Screen settings'
diff --git a/includes/extensions.php b/includes/extensions.php
index d055956dc..1b0be38f0 100644
--- a/includes/extensions.php
+++ b/includes/extensions.php
@@ -9,21 +9,35 @@ class WP_Stream_Extensions {
const EXTENSIONS_KEY = 'wp_stream_extensions_';
const MEMBER_KEY = 'wp_stream_member';
- const DATA_API_URL = 'https://wp-stream.com/json/';
+ const API_ENDPOINT = '/wp-json.php/posts/?type=extension';
+ const API_DOMAIN = 'vvv.wp-stream.com';
+ const API_TRANSPORT = 'http://'; /** @internal will need valid ssl cert before using https:// transport */
var $extensions;
var $extension_data;
- var $stream_member = false;
+ var $api_uri;
+
+ var $plugin_paths;
+
+ var $stream_member = true; // /** @internal setting to true for testing the page output */
var $license_key = NULL;
+ public static $instance = false;
+ public static function get_instance() {
+ if ( ! self::$instance )
+ self::$instance = new self();
- function __construct() {
- $this->extensions = $this->get_extension_data();
+ return self::$instance;
+ }
+ function __construct() {
+ $this->api_uri = self::API_TRANSPORT . self::API_DOMAIN . self::API_ENDPOINT;
+ $this->extensions = $this->get_extension_data();
+ $this->plugin_paths = $this->get_plugin_paths();
}
/**
@@ -34,23 +48,42 @@ function __construct() {
function render_page() {
?>
-
-
-
- Coming really, really soon. This is where the extensions will live.
-
+ extensions_display_body( $this->extensions ) ?>
get_extension_api();
+
+ if ( $api_transient ) {
+ set_transient( self::EXTENSIONS_KEY, $this->get_extension_api(), MINUTE_IN_SECONDS * 60 * 12 * 2 );
+ }
+ return $api_transient;
+ }
+
+ return $api_transient;
+ }
+
/**
* Gets the extension data from the wp-stream.com json extension api
*
- * @return array
+ * @return array|bool Array of extensions on success or false on WP_Error
*/
function get_extension_api() {
- return array();
+ $response = wp_remote_get( $this->api_uri );
+ if ( ! is_wp_error( $response ) ) {
+ return json_decode( wp_remote_retrieve_body( $response ) );
+ }
+
+ return $response;
}
/**
@@ -59,7 +92,7 @@ function get_extension_api() {
*
*/
private function activate_membership() {
- $license_key = wp_remote_get( self::DATA_API_URL, array() );
+ $license_key = wp_remote_get( $this->api_uri, array() );
set_transient( self::MEMBER_KEY, array( 'license_key' => $license_key ), MINUTE_IN_SECONDS * 60 * 48 );
return $license_key;
}
@@ -70,6 +103,8 @@ private function activate_membership() {
* @return bool true if membership active
*/
private function verify_membership() {
+ return true;
+ /** @internal returning true early for testing extension page output */
if ( false === ( $license_key = get_transient( self::MEMBER_KEY ) ) ) {
$license_key = $this->activate_membership();
}
@@ -77,7 +112,7 @@ private function verify_membership() {
$key_hash = wp_hash_password( $license_key );
if ( ! $this->stream_member /** request to wp-stream.com */ ) {
/** Checks if the hash of the users key matches the hash of users key stored on wp-stream.com */
- return wp_remote_get( self::DATA_API_URL, array( 'hashed_key' => $key_hash ) );
+ return wp_remote_get( $this->api_uri, array( 'hashed_key' => $key_hash ) );
}
return false;
}
@@ -100,7 +135,21 @@ function activate_extension( $extension ) {
do_action( 'activated_plugin', trim( $plugin ) );
}
}
+ }
+ /**
+ * Create an array of all plugin paths, using the text-domain as a unique key slug
+ *
+ * @return array
+ */
+ function get_plugin_paths() {
+ $plugin_paths = array();
+ foreach ( get_plugins() as $path => $data ) {
+ if ( isset( $data['TextDomain'] ) && ! empty( $data['TextDomain'] ) ) {
+ $plugin_paths[$data['TextDomain']] = $path;
+ }
+ }
+ return $plugin_paths;
}
function download_extension() {
@@ -118,94 +167,120 @@ function update_extension() {
}
- /**
- * Checks for extension data stored in transient
- *
- * @return array|mixed
- */
- function get_extension_data() {
- if ( false === ( $api_transient = get_transient( self::EXTENSIONS_KEY ) ) ) {
- $api_transient = $this->get_extension_api();
-
- if ( $api_transient ) {
- set_transient( self::EXTENSIONS_KEY, $this->get_extension_api(), MINUTE_IN_SECONDS * 60 * 12 * 2 );
- }
- return $api_transient;
- }
-
- return $api_transient;
+ function extensions_display_header( $extensions ) {
+ ?>
+
+
+ verify_membership() ) : ?>
+
+
+
+
+
+
+
+ verify_membership() ) : ?>
+
+
+
+
+
+
+
+
+
-
-