-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from newfold-labs/Integrate-APIs-to-AI-Onboarding
Integrate APIs to AI Onboarding
- Loading branch information
Showing
4 changed files
with
141 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ), | ||
); | ||
} | ||
|
||
} |