Skip to content

Commit a935bcb

Browse files
authored
Merge pull request #813 from newfold-labs/add/sitekits
Sitekits Support
2 parents a421df0 + d8dc6e0 commit a935bcb

16 files changed

+1940
-32
lines changed

includes/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function __construct( Container $container ) {
6969
}
7070

7171
if ( Permissions::is_authorized_admin() || Permissions::rest_is_authorized_admin() ) {
72-
new RestAPI();
72+
new RestApi();
7373
new WP_Admin();
7474
new ExternalRedirectInterceptor();
7575
}

includes/RestApi/SiteGenController.php

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
namespace NewfoldLabs\WP\Module\Onboarding\RestApi;
44

55
use NewfoldLabs\WP\Module\Onboarding\Permissions;
6-
use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService;
6+
use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService as LegacySiteGenService;
77
use NewfoldLabs\WP\Module\Onboarding\Data\SiteGen as SiteGenData;
8+
use NewfoldLabs\WP\Module\Onboarding\Services\Ai\ContentGeneration\SitekitsContentGeneration;
9+
use NewfoldLabs\WP\Module\Onboarding\Services\SiteGenService;
810

911
/**
1012
* Class SiteGenController
@@ -130,6 +132,10 @@ public function get_homepages_args() {
130132
'type' => 'string',
131133
'sanitize_callback' => 'sanitize_text_field',
132134
),
135+
'site_type' => array(
136+
'required' => true,
137+
'type' => 'string',
138+
),
133139
'locale' => array(
134140
'required' => true,
135141
'type' => 'string',
@@ -182,7 +188,7 @@ public function get_regenerate_homepage_args() {
182188
* @return array
183189
*/
184190
public function get_enabled_identifiers() {
185-
return array_keys( array_filter( SiteGenService::enabled_identifiers() ) );
191+
return array_keys( array_filter( LegacySiteGenService::enabled_identifiers() ) );
186192
}
187193

188194
/**
@@ -193,7 +199,7 @@ public function get_enabled_identifiers() {
193199
* @return array|WP_Error
194200
*/
195201
public function generate_sitegen_meta( \WP_REST_Request $request ) {
196-
if ( ! SiteGenService::is_enabled() ) {
202+
if ( ! LegacySiteGenService::is_enabled() ) {
197203
return new \WP_Error(
198204
'nfd_onboarding_error',
199205
'SiteGen is Disabled.',
@@ -207,7 +213,7 @@ public function generate_sitegen_meta( \WP_REST_Request $request ) {
207213
$locale = $request->get_param( 'locale' );
208214
$skip_cache = $request->get_param( 'skip_cache' );
209215

210-
return SiteGenService::instantiate_site_meta(
216+
return LegacySiteGenService::instantiate_site_meta(
211217
$site_info,
212218
$identifier,
213219
$site_type,
@@ -223,7 +229,7 @@ public function generate_sitegen_meta( \WP_REST_Request $request ) {
223229
* @return array
224230
*/
225231
public function get_homepages( \WP_REST_Request $request ) {
226-
$existing_homepages = SiteGenService::get_homepages();
232+
$existing_homepages = LegacySiteGenService::get_homepages();
227233
if ( ! empty( $existing_homepages ) ) {
228234
return new \WP_REST_Response( $existing_homepages, 200 );
229235
}
@@ -233,24 +239,35 @@ public function get_homepages( \WP_REST_Request $request ) {
233239
$site_type = $request->get_param( 'site_type' );
234240
$locale = $request->get_param( 'locale' );
235241

236-
$target_audience = SiteGenService::instantiate_site_meta( $site_info, 'target_audience', $site_type, $locale );
237-
if ( is_wp_error( $target_audience ) ) {
238-
return $target_audience;
239-
}
240-
241-
$content_style = SiteGenService::instantiate_site_meta( $site_info, 'content_tones', $site_type, $locale );
242-
if ( is_wp_error( $content_style ) ) {
243-
return $content_style;
242+
$homepages = [];
243+
if ( SitekitsContentGeneration::site_type_supported( $site_type ) ) {
244+
$siteGenService = new SiteGenService();
245+
$homepages = $siteGenService->get_sitekits(
246+
$site_description,
247+
$site_type,
248+
$locale,
249+
true
250+
);
251+
} else {
252+
$target_audience = LegacySiteGenService::instantiate_site_meta( $site_info, 'target_audience', $site_type, $locale );
253+
if ( is_wp_error( $target_audience ) ) {
254+
return $target_audience;
255+
}
256+
257+
$content_style = LegacySiteGenService::instantiate_site_meta( $site_info, 'content_tones', $site_type, $locale );
258+
if ( is_wp_error( $content_style ) ) {
259+
return $content_style;
260+
}
261+
262+
$homepages = LegacySiteGenService::generate_homepages(
263+
$site_description,
264+
$site_type,
265+
$content_style,
266+
$target_audience,
267+
$locale,
268+
);
244269
}
245270

246-
$homepages = SiteGenService::generate_homepages(
247-
$site_description,
248-
$site_type,
249-
$content_style,
250-
$target_audience,
251-
$locale,
252-
);
253-
254271
if ( is_wp_error( $homepages ) ) {
255272
return $homepages;
256273
}
@@ -273,19 +290,19 @@ public function regenerate_homepage( \WP_REST_Request $request ) {
273290
$locale = $request->get_param( 'locale' );
274291
$skip_cache = $request->get_param( 'skip_cache' );
275292

276-
$target_audience = SiteGenService::instantiate_site_meta( $site_info, 'target_audience', $locale, $skip_cache );
293+
$target_audience = LegacySiteGenService::instantiate_site_meta( $site_info, 'target_audience', $locale, $skip_cache );
277294
if ( is_wp_error( $target_audience ) ) {
278295
return $target_audience;
279296
}
280-
$content_style = SiteGenService::instantiate_site_meta( $site_info, 'content_tones', $locale, $skip_cache );
297+
$content_style = LegacySiteGenService::instantiate_site_meta( $site_info, 'content_tones', $locale, $skip_cache );
281298
if ( is_wp_error( $content_style ) ) {
282299
return $content_style;
283300
}
284301

285302
if ( $is_favorite ) {
286-
$result = SiteGenService::regenerate_favorite_homepage( $slug, $color_palette );
303+
$result = LegacySiteGenService::regenerate_favorite_homepage( $slug, $color_palette );
287304
} else {
288-
$result = SiteGenService::regenerate_homepage( $site_description, $content_style, $target_audience, $locale );
305+
$result = LegacySiteGenService::regenerate_homepage( $site_description, $content_style, $target_audience, $locale );
289306
}
290307

291308
if ( null === $result ) {
@@ -314,22 +331,22 @@ public function publish_sitemap_pages( \WP_REST_Request $request ) {
314331
$locale = $request->get_param( 'locale' );
315332
$skip_cache = $request->get_param( 'skip_cache' );
316333

317-
$target_audience = SiteGenService::instantiate_site_meta( $site_info, 'target_audience', $site_type, $locale, $skip_cache );
334+
$target_audience = LegacySiteGenService::instantiate_site_meta( $site_info, 'target_audience', $site_type, $locale, $skip_cache );
318335
if ( is_wp_error( $target_audience ) ) {
319336
return $target_audience;
320337
}
321338

322-
$content_style = SiteGenService::instantiate_site_meta( $site_info, 'content_tones', $site_type, $locale, $skip_cache );
339+
$content_style = LegacySiteGenService::instantiate_site_meta( $site_info, 'content_tones', $site_type, $locale, $skip_cache );
323340
if ( is_wp_error( $content_style ) ) {
324341
return $content_style;
325342
}
326343

327-
$sitemap = SiteGenService::instantiate_site_meta( $site_info, 'sitemap', $site_type, $locale, $skip_cache );
344+
$sitemap = LegacySiteGenService::instantiate_site_meta( $site_info, 'sitemap', $site_type, $locale, $skip_cache );
328345
if ( is_wp_error( $sitemap ) ) {
329346
return $sitemap;
330347
}
331348

332-
SiteGenService::publish_sitemap_pages( $site_description, $site_type, $content_style, $target_audience, $sitemap, $locale );
349+
LegacySiteGenService::publish_sitemap_pages( $site_description, $site_type, $content_style, $target_audience, $sitemap, $locale );
333350

334351
return new \WP_REST_Response( array(), 201 );
335352
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
/**
3+
* Content Generation Prompt Class
4+
*
5+
* This file contains the ContentGenerationPrompt class which processes
6+
* site info entered during onboarding and generates structured prompt
7+
* for AI content generation.
8+
*
9+
* @package NewfoldLabs\WP\Module\Onboarding\Services\Ai\ContentGeneration
10+
*/
11+
12+
namespace NewfoldLabs\WP\Module\Onboarding\Services\Ai\ContentGeneration;
13+
14+
use NewfoldLabs\WP\Module\AI\SiteGen\SiteGen;
15+
use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService as LegacySiteGenService;
16+
17+
/**
18+
* Content Generation Prompt Class
19+
*
20+
* This class processes the site info entered during onboarding and generates
21+
* structured prompt for AI content generation.
22+
*/
23+
class ContentGenerationPrompt {
24+
25+
/**
26+
* The original site description provided by the user.
27+
*
28+
* @var string
29+
*/
30+
private $site_description;
31+
32+
/**
33+
* The type of site (e.g., 'business', 'blog', 'ecommerce').
34+
*
35+
* @var string
36+
*/
37+
private $site_type;
38+
39+
/**
40+
* The locale/language code for the site.
41+
*
42+
* @var string
43+
*/
44+
private $locale;
45+
46+
/**
47+
* The required site meta dependencies.
48+
*
49+
* @var array
50+
*/
51+
private $prompt_site_meta_dependencies = array(
52+
'target_audience',
53+
'content_tones',
54+
'keywords',
55+
);
56+
57+
/**
58+
* Constructor for ContentGenerationPrompt.
59+
*
60+
* @param string $site_description The user-provided site description.
61+
* @param string $site_type The type of site (e.g., 'business', 'personal', 'ecommerce').
62+
* @param string $locale The locale/language code for the site.
63+
*/
64+
public function __construct( $site_description, $site_type, $locale ) {
65+
$this->validate_input( $site_description, $site_type, $locale );
66+
67+
$this->site_description = trim( $site_description );
68+
$this->site_type = trim( $site_type );
69+
$this->locale = trim( $locale );
70+
}
71+
72+
/**
73+
* Validates the input parameters.
74+
*
75+
* @param string $site_description The site description.
76+
* @param string $site_type The site type.
77+
* @param string $locale The locale.
78+
*
79+
* @throws \Exception If any parameter is empty.
80+
*/
81+
private function validate_input( $site_description, $site_type, $locale ) {
82+
if ( empty( $site_description ) ) {
83+
throw new \Exception( 'Site description cannot be empty' );
84+
}
85+
86+
if ( empty( $site_type ) ) {
87+
throw new \Exception( 'Site type cannot be empty' );
88+
}
89+
90+
if ( empty( $locale ) ) {
91+
throw new \Exception( 'Locale cannot be empty' );
92+
}
93+
}
94+
95+
/**
96+
* Sets the refined site description using AI processing.
97+
*
98+
* @return string The refined site description.
99+
*/
100+
private function get_refined_site_description(): string {
101+
return SiteGen::get_refined_site_description( $this->site_description );
102+
}
103+
104+
/**
105+
* Gets the meta response for the site meta dependency.
106+
*
107+
* @param string $site_meta_dependency The site meta dependency.
108+
*
109+
* @return array The meta response.
110+
*/
111+
private function get_meta_response( $site_meta_dependency ): array {
112+
$response = LegacySiteGenService::instantiate_site_meta(
113+
$this->site_description,
114+
$site_meta_dependency,
115+
$this->site_type,
116+
$this->locale
117+
);
118+
119+
if ( is_wp_error( $response ) ) {
120+
return array();
121+
}
122+
123+
return $response;
124+
}
125+
126+
/**
127+
* Gets the complete prompt array for content generation.
128+
*
129+
* @return array {
130+
* The complete prompt array for content generation.
131+
*
132+
* @type string $site_description The refined site description.
133+
* @type array $target_audience The target audience information.
134+
* @type array $content_style The content style/tone information.
135+
* @type array $keywords The relevant keywords.
136+
* }
137+
*/
138+
public function get_prompt(): array {
139+
$prompt = array();
140+
$prompt['site_description'] = $this->get_refined_site_description();
141+
142+
foreach ( $this->prompt_site_meta_dependencies as $site_meta_dependency ) {
143+
$prompt[ $site_meta_dependency ] = $this->get_meta_response( $site_meta_dependency );
144+
}
145+
146+
return $prompt;
147+
}
148+
}

0 commit comments

Comments
 (0)