Skip to content

Commit

Permalink
API v2 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
sybrew committed Oct 30, 2018
1 parent 291aa6d commit 476d04b
Show file tree
Hide file tree
Showing 18 changed files with 201 additions and 146 deletions.
8 changes: 8 additions & 0 deletions extensions/essentials/focus/trunk/inc/classes/ajax.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ public function _get_lexicalforms() {
$send['results'] = $this->get_ajax_notice( false, 1100102 );
break;

case 'REQUEST_LIMIT_REACHED':
$send['results'] = $this->get_ajax_notice( false, 1100108 );
break;

default:
case 'LICENSE_TOO_LOW':
case 'REMOTE_API_BODY_ERROR':
Expand Down Expand Up @@ -225,6 +229,10 @@ public function _get_synonyms() {
$send['results'] = $this->get_ajax_notice( false, 1100202 );
break;

case 'REQUEST_LIMIT_REACHED':
$send['results'] = $this->get_ajax_notice( false, 1100208 );
break;

default:
case 'LICENSE_TOO_LOW':
case 'REMOTE_API_BODY_ERROR':
Expand Down
7 changes: 6 additions & 1 deletion extensions/premium/monitor/trunk/inc/classes/api.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,12 @@ protected function api_request_crawl( $ajax = false ) {

$response = $response['data'];

if ( 'failure' === $response['status'] ) {
if ( 'REQUEST_LIMIT_REACHED' === $response['status'] ) {
$this->set_remote_crawl_timeout();
$ajax or $this->set_error_notice( [ 1010509 => '' ] );
return $ajax ? $this->get_ajax_notice( false, 1010508 ) : false;
}
if ( in_array( $response['status'], [ 'failure', 'LICENSE_TOO_LOW' ], true ) ) {
$ajax or $this->set_error_notice( [ 1010501 => '' ] );
return $ajax ? $this->get_ajax_notice( false, 1010501 ) : false;
}
Expand Down
4 changes: 2 additions & 2 deletions inc/classes/abstract/secure.abstract.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ final protected static function is_premium_user() {

$level = isset( self::$account['level'] ) ? self::$account['level'] : '';

return $is_premium = 'Premium' === $level;
return $is_premium = in_array( $level, [ 'Enterprise', 'Premium' ], true );
}

/**
Expand All @@ -240,7 +240,7 @@ final protected static function is_connected_user() {

$level = isset( self::$account['level'] ) ? self::$account['level'] : '';

return $is_connected = in_array( $level, [ 'Premium', 'Essentials' ], true );
return $is_connected = in_array( $level, [ 'Enterprise', 'Premium', 'Essentials' ], true );
}

/**
Expand Down
26 changes: 20 additions & 6 deletions inc/classes/accountactivation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,18 @@ protected function revalidate_subscription() {
break;

case 5:
//= Everything's premium.
//= Everything's Premium.
( $this->get_option( '_activation_level' ) !== 'Premium' )
and $this->update_option( '_activation_level', 'Premium' )
and $this->set_error_notice( [ 905 => '' ] );
break;

case 6:
//= Everything's Enterprise.
( $this->get_option( '_activation_level' ) !== 'Enterprise' )
and $this->update_option( '_activation_level', 'Enterprise' )
and $this->set_error_notice( [ 905 => '' ] );
break;
endswitch;

return $status;
Expand All @@ -361,6 +368,7 @@ protected function revalidate_subscription() {
*
* @since 1.0.0
* @since 1.3.0 Now returns an integer.
* @since 2.0.0 Our API no longer uses 'extra'.
*
* @return int : {
* 0 : Not subscribed / API failure.
Expand All @@ -369,26 +377,32 @@ protected function revalidate_subscription() {
* 3 : Local connected user. Remote connected User. Instance verified.
* 4 : Local connected user. Remote connected User. Instance verified. Domain verified.
* 5 : Local connected user. Remote connected User. Instance verified. Domain verified. Premium verified.
* 6 : Local connected user. Remote connected User. Instance verified. Domain verified. Enterprise verified.
* }
*/
protected function validate_remote_subscription_license() {

$response = $this->get_remote_subscription_status();

$status = 0;
$extra = $this->coalesce_var( $response['status_extra'], [] );

while ( true ) {
if ( ! isset( $response['status_check'] ) ) break;
++$status;
if ( 'active' !== $response['status_check'] ) break;
++$status;
if ( $this->get_activation_instance() !== $this->coalesce_var( $extra['instance'], -1 ) ) break;
++$status;
if ( $this->get_activation_site_domain() !== $this->coalesce_var( $extra['activation_domain'], -1 ) ) break;
if ( $this->get_activation_instance() !== $this->coalesce_var( $response['_instance'], -1 ) ) break;
++$status;
if ( 'Premium' !== $this->coalesce_var( $response['_activation_level'], 'Essentials' ) ) break;
if ( $this->get_activation_site_domain() !== $this->coalesce_var( $response['activation_domain'], -1 ) ) break;
++$status;

$this->coalesce_var( $response['_activation_level'], '' );

if ( 'Premium' === $response['_activation_level'] ) {
$status += 1;
} elseif ( 'Enterprise' === $response['_activation_level'] ) {
$status += 2;
}
break;
}

Expand Down
3 changes: 2 additions & 1 deletion inc/classes/api.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ final protected function handle_request( $type = 'status', $args = [] ) {
* but their activation still uses the original scheme.
*
* @since 1.0.0
* @since 2.0.0 Now uses the site URL instead of the home URL.
*
* @return string Domain Host.
*/
Expand Down Expand Up @@ -231,7 +232,7 @@ final protected function get_api_response( array $args, $internal = true ) {
'licence_key' => '',
'instance' => $this->get_activation_instance( false ),
'platform' => $this->get_activation_site_domain(),
'tsfemv2' => 'yes', // var_dump() TEMP?
'version' => '2.0',
];

$args = \wp_parse_args( $args, $defaults );
Expand Down
21 changes: 16 additions & 5 deletions inc/classes/core.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1333,26 +1333,37 @@ final protected function is_plugin_activated() {
}

/**
* Determines whether the plugin's use is premium.
* Determines whether the plugin's use is connected.
*
* @since 2.0.0
*
* @return bool True if the plugin is connected to the Premium or Essential API handler.
* @return bool True if the plugin is connected to the Enterprise, Premium, or Essential API handler.
*/
final public function is_connected_user() {
return in_array( $this->get_option( '_activation_level' ), [ 'Premium', 'Essentials' ], true );
return in_array( $this->get_option( '_activation_level' ), [ 'Enterprise', 'Premium', 'Essentials' ], true );
}

/**
* Determines whether the plugin's use is premium.
* Determines whether the plugin's use is Premium.
*
* @since 1.0.0
* @since 1.5.0 Now public. Enjoy.
*
* @return bool True if the plugin is connected to the Premium API handler.
*/
final public function is_premium_user() {
return 'Premium' === $this->get_option( '_activation_level' );
return in_array( $this->get_option( '_activation_level' ), [ 'Enterprise', 'Premium' ], true );
}

/**
* Determines whether the plugin's use is Enterprise.
*
* @since 2.0.0
*
* @return bool True if the plugin is connected to the Premium API handler and is of level Enterprise.
*/
final public function is_enterprise_user() {
return 'Enterprise' === $this->get_option( '_activation_level' );
}

/**
Expand Down
68 changes: 53 additions & 15 deletions inc/classes/layout.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public static function get( $type = '' ) {
return static::get_public_support_button();
break;

case 'premium-support-button':
return static::get_premium_support_button();
case 'private-support-button':
return static::get_private_support_button();
break;

case 'account-information':
Expand Down Expand Up @@ -170,7 +170,7 @@ private static function get_disconnect_button() {
*
* @since 2.0.0
*
* @return string The free support button link.
* @return string The public support button link.
*/
private static function get_public_support_button() {

Expand All @@ -183,18 +183,18 @@ private static function get_public_support_button() {
}

/**
* Outputs premium support button.
* Outputs private support button.
*
* @since 1.0.0
* @since 2.0.0
*
* @return string The premium support button link.
* @return string The private support button link.
*/
private static function get_premium_support_button() {
private static function get_private_support_button() {

if ( 'link' === self::get_property( '_type' ) ) {
return \tsf_extension_manager()->get_support_link( 'premium' );
return \tsf_extension_manager()->get_support_link( 'private' );
} else {
\the_seo_framework()->_doing_it_wrong( __METHOD__, 'The premium support button only supports the link type.' );
\the_seo_framework()->_doing_it_wrong( __METHOD__, 'The private support button only supports the link type.' );
return '';
}
}
Expand Down Expand Up @@ -223,15 +223,17 @@ private static function get_account_info() {
$domain = str_ireplace( [ 'http://', 'https://' ], '', \esc_url( \get_home_url(), [ 'http', 'https' ] ) );
$end_date = '';
$payment_date = '';
$requests_remaining = '';

if ( $data ) {
if ( isset( $data['status']['status_check'] ) && 'inactive' === $data['status']['status_check'] ) {
$level = \__( 'Decoupled', 'the-seo-framework-extension-manager' );
} else {
//* UTC.
$end_date = isset( $data['status']['status_extra']['end_date'] ) ? $data['status']['status_extra']['end_date'] : '';
$payment_date = isset( $data['status']['status_extra']['payment_date'] ) ? $data['status']['status_extra']['payment_date'] : '';
$domain = isset( $data['status']['status_extra']['activation_domain'] ) ? $data['status']['status_extra']['activation_domain'] : '';
$end_date = isset( $data['status']['end_date'] ) ? $data['status']['end_date'] : '';
$payment_date = isset( $data['status']['payment_date'] ) ? $data['status']['payment_date'] : '';
$domain = isset( $data['status']['activation_domain'] ) ? $data['status']['activation_domain'] : '';
$requests_remaining = isset( $data['status']['requests_remaining'] ) ? $data['status']['requests_remaining'] : '';
}
}

Expand All @@ -243,6 +245,11 @@ private static function get_account_info() {
$_class = [ 'tsfem-dashicon' ];

switch ( $level ) :
case 'Enterprise':
$_level = \__( 'Enterprise', 'the-seo-framework-extension-manager' );
$_class[] = $valid_options ? 'tsfem-success' : 'tsfem-error';
break;

case 'Premium':
$_level = \__( 'Premium', 'the-seo-framework-extension-manager' );
$_class[] = $valid_options ? 'tsfem-success' : 'tsfem-error';
Expand Down Expand Up @@ -283,14 +290,39 @@ private static function get_account_info() {
}
}

$level = HTML::wrap_inline_tooltip( HTML::make_inline_tooltip(
$_level = HTML::wrap_inline_tooltip( HTML::make_inline_tooltip(
$level,
tsf_extension_manager()->coalesce_var( $level_desc, '' ),
'',
$_class
) );

$output .= static::wrap_row_content( \esc_html__( 'Account level:', 'the-seo-framework-extension-manager' ), $level, false );
$output .= static::wrap_row_content( \esc_html__( 'Account level:', 'the-seo-framework-extension-manager' ), $_level, false );

if ( is_int( $requests_remaining ) ) {
$_notice = '';
$_classes = [ 'tsfem-dashicon' ];

if ( $requests_remaining > 100 ) {
$_notice = \esc_html__( 'Number of API requests left this month.', 'the-seo-framework-extension-manager' );
$_classes[] = 'tsfem-success';
} elseif ( $requests_remaining > 0 ) {
$_notice = \esc_html__( 'Only a few requests left for this month. Consider upgrading your account.', 'the-seo-framework-extension-manager' );
$_classes[] = 'tsfem-warning';
} else {
$_notice = \esc_html__( 'No requests left for this month. Consider upgrading your account.', 'the-seo-framework-extension-manager' );
$_classes[] = 'tsfem-error';
}

//= Not necessarily this domain.
$_requests_remaining = HTML::wrap_inline_tooltip( HTML::make_inline_tooltip(
(int) $requests_remaining,
$_notice,
'',
$_classes
) );
$output .= static::wrap_row_content( \esc_html__( 'Requests remaining:', 'the-seo-framework-extension-manager' ), $_requests_remaining, false );
}

if ( $valid_options && $domain ) {
//* Check for domain mismatch. If they don't match no premium extensions can be activated.
Expand Down Expand Up @@ -330,6 +362,7 @@ private static function get_account_info() {
$_class = 'tsfem-success';
$expires_in = '';

// Move to time.trait?
if ( $difference < 0 ) {
//* Expired.
$expires_in = \__( 'Account expired', 'the-seo-framework-extension-manager' );
Expand Down Expand Up @@ -374,7 +407,10 @@ private static function get_account_info() {
$_class = 'tsfem-success';
$payment_in = '';

if ( $difference < 0 ) {
if ( $difference < -5184000 ) {
// Probably a permanent subscription. Let's not bother my friends.
goto end;
} elseif ( $difference < 0 ) {
//* Processing.
$payment_in = \__( 'Payment processing', 'the-seo-framework-extension-manager' );
$_class = 'tsfem-warning';
Expand Down Expand Up @@ -402,6 +438,8 @@ private static function get_account_info() {
$output .= static::wrap_row_content( \esc_html__( 'Payment due in:', 'the-seo-framework-extension-manager' ), $payment_in, false );
endif;

end:;

//= Wrap tooltips here.
return sprintf( '<div class="tsfem-flex-account-info-rows tsfem-flex tsfem-flex-nogrowshrink">%s</div>', $output );
}
Expand Down
14 changes: 10 additions & 4 deletions inc/classes/loadadmin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ final public function _wp_ajax_tsfemForm_get_geocode() {
$send['results'] = $this->get_ajax_notice( false, 17010 );
break;

case 'REQUEST_LIMIT_REACHED':
//= License request limit reached.
$send['results'] = $this->get_ajax_notice( false, 17013 );
break;

case 'LICENSE_TOO_LOW':
default:
//= Undefined error.
Expand Down Expand Up @@ -778,17 +783,18 @@ final protected function get_my_account_link() {
}

/**
* Generates support link for both Free and Premium.
* Generates support link for both Public and Private.
*
* @since 1.0.0
* @since 2.0.0 Now goes by Private/Public
*
* @param string $type The support link type. Accepts 'premium' or anything else for free.
* @param string $type The support link type. Accepts 'privte' or anything else for public.
* @param bool $icon Whether to show a heart/star after the button text.
* @return string The Support Link.
*/
final public function get_support_link( $type = 'free', $icon = true ) {
final public function get_support_link( $type = 'public', $icon = true ) {

if ( 'premium' === $type ) {
if ( 'private' === $type ) {
$url = 'https://premium.theseoframework.com/support/';

$title = \__( 'Get support via mail', 'the-seo-framework-extension-manager' );
Expand Down
Loading

0 comments on commit 476d04b

Please sign in to comment.