Skip to content

Commit

Permalink
Merge branch 'enhance/ai-onboarding' into add/sitedetails/simple
Browse files Browse the repository at this point in the history
  • Loading branch information
girish-lokapure authored Jan 15, 2024
2 parents 35aa9c3 + 048b3c4 commit 7044379
Show file tree
Hide file tree
Showing 12 changed files with 890 additions and 49 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"newfold-labs/wp-module-installer": "^1.1",
"newfold-labs/wp-module-data": "^2.4.3",
"newfold-labs/wp-module-ai": "^1.0.4",
"wp-forge/wp-upgrade-handler": "^1.0"
"wp-forge/wp-upgrade-handler": "^1.0",
"mustache/mustache": "^2.14"
},
"require-dev": {
"newfold-labs/wp-php-standards": "^1.2"
Expand Down
89 changes: 77 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 18 additions & 14 deletions includes/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ final class Data {
*/
public static function runtime() {
return array(
'buildUrl' => \NFD_ONBOARDING_BUILD_URL,
'siteUrl' => \get_site_url(),
'restUrl' => \get_home_url() . '/index.php?rest_route=',
'adminUrl' => \admin_url(),
'currentBrand' => self::current_brand(),
'currentPlan' => self::current_plan(),
'currentFlow' => self::current_flow(),
'pluginInstallHash' => PluginInstaller::rest_get_plugin_install_hash(),
'previewSettings' => array(
'buildUrl' => \NFD_ONBOARDING_BUILD_URL,
'siteUrl' => \get_site_url(),
'restUrl' => \get_home_url() . '/index.php?rest_route=',
'adminUrl' => \admin_url(),
'currentBrand' => self::current_brand(),
'currentPlan' => self::current_plan(),
'currentFlow' => self::current_flow(),
'pluginInstallHash' => PluginInstaller::rest_get_plugin_install_hash(),
'previewSettings' => array(
'settings' => Preview::get_settings(),
'stepPreviewData' => Themes::step_preview_data(),
),
'currentUserDetails' => self::wp_current_user_details(),
'aiPreviewSettings' => array(
'settings' => Preview::get_settings(),
'stepPreviewData' => Themes::step_preview_data(),
),
'currentUserDetails' => self::wp_current_user_details(),
);
}

Expand Down Expand Up @@ -158,10 +162,10 @@ public static function coming_soon() {
}

/**
* Get the current WordPress admin user details.
*
* @return array
*/
* Get the current WordPress admin user details.
*
* @return array
*/
public static function wp_current_user_details() {
$user = wp_get_current_user();
if ( $user->exists() ) {
Expand Down
25 changes: 20 additions & 5 deletions includes/Flows/Flows.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class Flows {
* @var array
*/
protected static $data = array(
'version' => '1.0.5',
'version' => '1.0.7',

// Each time step is viewed, insert GMT timestamp to array.
'isViewed' => array(),
Expand Down Expand Up @@ -67,8 +67,10 @@ final class Flows {

// This integer will map to the attachment ID for an uploaded image to the WordPress media library
'siteLogo' => array(
'id' => 0,
'url' => '',
'id' => 0,
'url' => '',
'fileName' => '',
'fileSize' => 0,
),

// key-value store for social media accounts
Expand Down Expand Up @@ -110,6 +112,8 @@ final class Flows {
'comingSoon' => false,
),

'activeFlow' => '',

// we will store active flows (abandoned wp-setup, abandoned wp-commerce) with their identifier and use as a reference to access currentStep and data
'currentFlows' => array(),

Expand Down Expand Up @@ -155,6 +159,11 @@ final class Flows {
'currentStatus' => 0,
'totalCount' => 8,
),
'homepages' => array(
'active' => array(),
'data' => array(),
),
'customDesign' => false,
),
);

Expand Down Expand Up @@ -208,6 +217,7 @@ public static function get_flows() {
? $current_brand['config']['enabled_flows'] : array(
'wp-setup' => false,
'ecommerce' => false,
'sitegen' => false,
);
}

Expand Down Expand Up @@ -304,12 +314,17 @@ public static function get_flow_from_plan_subtype( $plan_subtype ) {
* @return boolean
*/
public static function is_sitegen() {
if ( ! self::get_flows()['sitegen'] ) {
return false;
}

$flow_data = FlowService::read_data_from_wp_option();
if ( ! $flow_data || empty( $flow_data['sitegen'] ) ) {
if ( ! $flow_data || empty( $flow_data['activeFlow'] ) ) {
return false;
}

return 'sitegen' === $flow_data['activeFlow'];

return true === self::get_flows()['sitegen'];
}

/**
Expand Down
37 changes: 37 additions & 0 deletions includes/Mustache/Mustache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
namespace NewfoldLabs\WP\Module\Onboarding\Data\Mustache;

/**
* Class Mustache
*/
class Mustache {

/**
* Mustache Engine.
*
* @var array
*/
protected $mustache_engine;

/**
* Setup mustache engine.
*/
public function __construct() {
$this->mustache_engine = new \Mustache_Engine(
array(
'loader' => new \Mustache_Loader_FilesystemLoader( dirname( __FILE__ ) . '/Templates' ),
)
);
}

/**
* Render respective template data.
*
* @param string $template_name Template Name
* @param array $data Data
* @return string
*/
public function render_template( $template_name, $data ) {
return $this->mustache_engine->loadTemplate( $template_name )->render( $data );
}
}
9 changes: 9 additions & 0 deletions includes/Mustache/Templates/themeStylesheet.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
Theme Name: {{ theme_name }}
Author: {{ site_title }} & {{ brand_name }}
Author URI: {{ site_url }}
Description: A Custom WordPress Theme built for {{ site_title }} by {{ brand_name }}
Version: 1.0.0
Template: {{ parent_theme_slug }}
Text Domain: {{ child_theme_slug }}
*/
Loading

0 comments on commit 7044379

Please sign in to comment.