Skip to content

Commit

Permalink
Merge pull request #16 from newfold-labs/Integrate-APIs-to-AI-Onboarding
Browse files Browse the repository at this point in the history
Integrate APIs to AI Onboarding
  • Loading branch information
diwanshuster authored Nov 28, 2023
2 parents 7cb3b2f + 7735c4e commit c113354
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 12 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"require": {
"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"
},
"require-dev": {
Expand All @@ -34,4 +35,4 @@
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
}
61 changes: 53 additions & 8 deletions composer.lock

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

10 changes: 7 additions & 3 deletions includes/Flows/Flows.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,23 @@ final class Flows {
),

'sitegen' => array(
'siteDetails' => array(
'siteDetails' => array(
'name' => '',
'type' => '',
'style' => '',
'prompt' => '',
),
'siteLogo' => array(
'siteLogo' => array(
'id' => 0,
'url' => '',
),
'experience' => array(
'experience' => array(
'level' => 0,
),
'siteGenMetaStatus' => array(
'currentStatus' => 0,
'totalCount' => 8,
),
),
);

Expand Down
79 changes: 79 additions & 0 deletions includes/Services/SiteGenService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace NewfoldLabs\WP\Module\Onboarding\Data\Services;

use NewfoldLabs\WP\Module\AI\SiteGen\SiteGen;
use NewfoldLabs\WP\Module\Onboarding\Data\Data;

/**
* Class SiteGenService
*
* Class for handling SiteGen Interactions.
*/
class SiteGenService {

/**
* Gets Valid Identifiers.
*
* @param string $key The identifier to be evaluated.
* @return boolean
*/
public static function get_identifiers() {
return array(
'siteclassification' => true,
'targetaudience' => true,
'contenttones' => true,
'contentstructure' => true,
'colorpalette' => true,
'sitemap' => true,
'pluginrecommendation' => true,
'fontpair' => true,
);
}

/**
* Determines whether the given identifier is valid.
*
* @param string $key The identifier to be evaluated.
* @return boolean
*/
public static function is_identifier( $key ) {
return isset( self::get_identifiers()[ $key ] );
}

/**
* Checks if the site is eligible for SiteGen Capabilities.
*
* @return boolean
*/
public static function is_enabled() {
if ( ! ( class_exists( 'NewfoldLabs\WP\Module\AI\SiteGen\SiteGen' ) ) ) {
return false;
}
return isset( Data::current_brand()['config']['enabled_flows']['sitegen'] )
&& true === Data::current_brand()['config']['enabled_flows']['sitegen'];
}


/**
* Sends the data required for SiteGen Generation
*
* @param string|Object $site_info The prompt that configures the Site gen object.
* @param string $identifier The identifier for Generating Site Meta.
* @param boolean $skip_cache To override the cache and fetch the data.
* @return array
*/
public static function instantiate_site_meta( $site_info, $identifier, $skip_cache = false ) {

if ( self::is_identifier( $identifier ) ) {
// sleep( 8 );
return SiteGen::generate_site_meta( $site_info, $identifier, $skip_cache );
}

// Imitates the error pattern returned by SiteGen Class
return array(
'error' => __( 'The given identifier is not valid' ),
);
}

}

0 comments on commit c113354

Please sign in to comment.