Skip to content

Commit

Permalink
Merge pull request #775 from bluehost/update/remove-isJarvis-host-inf…
Browse files Browse the repository at this point in the history
…o-file-check

Update/remove is jarvis host info file check
  • Loading branch information
circlecube authored Oct 30, 2023
2 parents 9647e56 + eb83de1 commit cd941c4
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 70 deletions.
53 changes: 0 additions & 53 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,50 +24,6 @@
return;
}

/**
* Check if platform is Jarvis
*
* @return bool
*/
function bluehost_is_jarvis() {
$is_jarvis = false;
$host = array(
'dirs' => explode( '/', ABSPATH ),
'user' => get_current_user(),
'homedir' => null,
'info_file' => null,
);

// Build host's home directory
foreach ( $host['dirs'] as $dir ) {
if ( ! empty( $dir ) ) {
$host['homedir'] = $host['homedir'] . '/' . $dir;

if ( $dir === $host['user'] ) {
break;
}
}
}

// Check for Jarvis .host-info file
if ( file_exists( $host['homedir'] . '/.host-info' ) ) {
$host['info_file'] = file_get_contents( $host['homedir'] . '/.host-info' );
}

// Check for Jarvis platform
if (
null !== $host['info_file']
&& (
false !== stripos( $host['info_file'], 'platform = jarvis' )
|| false !== stripos( $host['info_file'], 'platform=jarvis' )
)
) {
$is_jarvis = true;
}

return $is_jarvis;
}

/*
* Initialize coming soon module via container
*/
Expand Down Expand Up @@ -100,15 +56,6 @@ function () {
'bluehost'
);

$bluehost_module_container->set(
'isJarvis',
$bluehost_module_container->computed(
function () {
return bluehost_is_jarvis();
}
)
);

// properly get branding links depending on market
$wordpress_hosting_page = ( get_option( 'mm_brand' ) === 'Bluehost_India' ) ? 'https://www.bluehost.in?utm_source=coming-soon-template&utm_medium=bluehost_plugin' : 'https://bluehost.com?utm_source=coming-soon-template&utm_medium=bluehost_plugin';
$my_panel = ( get_option( 'mm_brand' ) === 'Bluehost_India' ) ? 'https://my.bluehost.in/web-hosting/cplogin' : 'https://my.bluehost.com/web-hosting/cplogin';
Expand Down
1 change: 0 additions & 1 deletion inc/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public static function runtime() {
global $bluehost_module_container;

$runtime = array(
'isJarvis' => $bluehost_module_container->get('isJarvis'),
'plugin' => array(
'url' => BLUEHOST_BUILD_URL,
'version' => BLUEHOST_PLUGIN_VERSION,
Expand Down
2 changes: 1 addition & 1 deletion src/app/data/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NewfoldRuntime } from "@newfold-labs/wp-module-runtime";
import { getPlatformBaseUrl } from "../util/helpers";

const getSupportPhoneNumber = () => {
const brand = NewfoldRuntime.sdk.plugin.brand;
const brand = NewfoldRuntime.plugin.brand;

if ( brand === 'Bluehost_India' ) {
return '1800-419-4426';
Expand Down
2 changes: 1 addition & 1 deletion src/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const AppBody = ( props ) => {
id="wppbh-app-rendered"
className={ classnames(
'wpadmin-brand-bluehost',
`wppbh-wp-${ NewfoldRuntime.sdk.wpversion }`,
`wppbh-wp-${ NewfoldRuntime.wpVersion }`,
`wppbh-page-${ kebabCase( location.pathname ) }`,
props.className,
'nfd-w-full nfd-p-4 min-[783px]:nfd-p-0'
Expand Down
16 changes: 7 additions & 9 deletions src/app/pages/home/accountCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ import {
} from "@heroicons/react/24/outline";
import { NewfoldRuntime } from "@newfold-labs/wp-module-runtime";
import { Card, Title } from "@newfold/ui-component-library";
import { addUtmParams, getPlatformPathUrl, getPlatformBaseUrl } from "../../util/helpers";
import { addUtmParams, getPlatformPathUrl, getPlatformBaseUrl, isJarvis } from "../../util/helpers";
import classNames from "classnames";

const isJarvis = NewfoldRuntime.sdk.isJarvis;

const base = [
{
icon: CpuChipIcon,
id: "account_link",
href: addUtmParams( getPlatformPathUrl("hosting/list", "app") ),
label: isJarvis
label: isJarvis()
? __("Hosting", "bluehost-wordpress-plugin")
: __("Control Panel", "bluehost-wordpress-plugin"),
color: "nfd-fill-gray",
Expand All @@ -27,7 +25,7 @@ const base = [
icon: GiftIcon,
id: "products_link",
href: addUtmParams( getPlatformPathUrl("renewal-center", "account_center#products") ),
label: isJarvis
label: isJarvis()
? __("Renewal Center", "bluehost-wordpress-plugin")
: __("Products", "bluehost-wordpress-plugin"),
color: "nfd-fill-primary-dark",
Expand All @@ -36,7 +34,7 @@ const base = [
icon: CreditCardIcon,
id: "billing_link",
href: addUtmParams( getPlatformPathUrl("billing-center", "account_center#billing") ),
label: isJarvis
label: isJarvis()
? __("Payment Methods", "bluehost-wordpress-plugin")
: __("Billing", "bluehost-wordpress-plugin"),
color: "nfd-fill-primary",
Expand All @@ -45,7 +43,7 @@ const base = [
icon: EnvelopeIcon,
id: "mail_link",
href: addUtmParams( getPlatformPathUrl("home", "app#/email-office") ),
label: isJarvis
label: isJarvis()
? __("Mail", "bluehost-wordpress-plugin")
: __("Mail & Office", "bluehost-wordpress-plugin"),
color: "nfd-fill-[#5b5b5b]",
Expand All @@ -60,10 +58,10 @@ const base = [
{
icon: IdentificationIcon,
id: "validation_token_link",
href: isJarvis
href: isJarvis()
? addUtmParams( getPlatformPathUrl("account-center") )
: addUtmParams( getPlatformBaseUrl("/cgi/token") ),
label: isJarvis
label: isJarvis()
? __("Profile", "bluehost-wordpress-plugin")
: __("Validation Token", "bluehost-wordpress-plugin"),
color: "nfd-fill-[#f89c24]",
Expand Down
23 changes: 18 additions & 5 deletions src/app/util/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,14 @@ export const addUtmParams = (url, params = {}) => {
* @return {string}
*/
export const getPlatformBaseUrl = ( path = '' ) => {
const brand = NewfoldRuntime.sdk.plugin.brand;
const isJarvis = NewfoldRuntime.sdk.isJarvis;
const brand = NewfoldRuntime.plugin.brand;

const baseUrl = () => {
if (brand === 'Bluehost_India') {
return 'https://my.bluehost.in';
}

if (isJarvis) {
if (isJarvis()) {
return 'https://www.bluehost.com';
}

Expand All @@ -198,9 +197,8 @@ export const getPlatformBaseUrl = ( path = '' ) => {
* // returns https://www.bluehost.com/my-account/home if Jarvis or https://my.bluehost.com/hosting/app#home if legacy
*/
export const getPlatformPathUrl = ( jarvisPath = '', legacyPath = '' ) => {
const isJarvis = NewfoldRuntime.sdk.isJarvis;

if (isJarvis) {
if (isJarvis()) {
return getPlatformBaseUrl('/my-account/') + jarvisPath;
}

Expand All @@ -225,3 +223,18 @@ export const handleHelpLinksClick = () => {
}
}
};

/**
* Check if this is a jarvis site or not.
* Deafults to true in cases where the capabilites are not set such as
* in local and test environments that do not receive capabilities.
*
* @return boolean
*/
export const isJarvis = () => {
if ( NewfoldRuntime.hasCapability( 'isJarvis' ) ) {
return NewfoldRuntime.capabilities.isJarvis;
} else {
return true;
}
};

0 comments on commit cd941c4

Please sign in to comment.