7
7
use NewfoldLabs \WP \Module \Onboarding \Data \Services \ThemeGeneratorService ;
8
8
use NewfoldLabs \WP \Module \Onboarding \Services \ReduxStateService ;
9
9
10
+ /**
11
+ * Class SiteGenService
12
+ *
13
+ * Handles the onboarding SiteGen flow for generating, publishing, and managing AI-generated homepages and related content.
14
+ *
15
+ * This service is designed to work with the onboarding module's Redux state and integrates with other onboarding services.
16
+ *
17
+ * @package NewfoldLabs\WP\Module\Onboarding\Services
18
+ */
10
19
class SiteGenService {
11
20
12
21
/**
13
22
* The Redux input object.
14
23
*
15
24
* @var array|null
16
25
*/
17
- private ? array $ input_data = null ;
18
-
26
+ private $ input_data = null ;
27
+
19
28
/**
20
29
* The Redux sitegen object.
21
30
*
22
31
* @var array|null
23
32
*/
24
- private ? array $ sitegen_data = null ;
33
+ private $ sitegen_data = null ;
25
34
35
+ /**
36
+ * SiteGenService constructor.
37
+ *
38
+ * Initializes the service by loading the Redux input and sitegen data from the ReduxStateService.
39
+ */
26
40
public function __construct () {
27
41
$ this ->input_data = ReduxStateService::get ( 'input ' );
28
42
$ this ->sitegen_data = ReduxStateService::get ( 'sitegen ' );
@@ -34,7 +48,7 @@ public function __construct() {
34
48
* @param string $selected_sitegen_homepage The selected sitegen homepage to publish.
35
49
* @return int|\WP_Error
36
50
*/
37
- public function publish_homepage ( string $ selected_sitegen_homepage ): int | \WP_Error {
51
+ public function publish_homepage ( string $ selected_sitegen_homepage ): int | \WP_Error {
38
52
// Validate we have the selected homepage.
39
53
if (
40
54
! $ this ->sitegen_data ||
@@ -98,8 +112,8 @@ public function publish_homepage( string $selected_sitegen_homepage ): int | \WP
98
112
* @return string|false The page title, or false if not found.
99
113
*/
100
114
public function get_sitemap_page_title ( string $ slug ): string |false {
101
- $ prompt = $ this ->get_prompt ();
102
- $ locale = $ this ->get_locale ();
115
+ $ prompt = $ this ->get_prompt ();
116
+ $ locale = $ this ->get_locale ();
103
117
$ site_type = $ this ->get_site_type ();
104
118
if ( ! $ prompt || ! $ locale || ! $ site_type ) {
105
119
return false ;
@@ -121,7 +135,7 @@ public function get_sitemap_page_title( string $slug ): string|false {
121
135
/**
122
136
* Add a page to the site navigation.
123
137
*
124
- * @param int $post_id The ID of the page to add to the navigation.
138
+ * @param int $post_id The ID of the page to add to the navigation.
125
139
* @param string $page_title The title of the page.
126
140
* @param string $permalink The permalink of the page.
127
141
*/
@@ -183,7 +197,7 @@ public function get_locale(): string {
183
197
* of the newly uploaded images.
184
198
*
185
199
* @param array $image_urls An array of image URLs to upload.
186
- * @param int $post_id The post ID to attach the images to.
200
+ * @param int $post_id The post ID to attach the images to.
187
201
* @return array|false An array of WordPress attachment URLs on success, false on failure.
188
202
* @throws Exception If there is an error during the upload process.
189
203
*/
@@ -297,14 +311,14 @@ public static function upload_images_to_wp_media_library( $image_urls, $post_id
297
311
* with the new ones.
298
312
*
299
313
* @param string $content The content containing img tags with image URLs.
300
- * @param int $post_id The post ID to attach the images to.
314
+ * @param int $post_id The post ID to attach the images to.
301
315
* @return string The updated content with new image URLs.
302
316
*/
303
317
public static function sideload_images_and_replace_grammar ( $ content , $ post_id ) {
304
318
// Extract image URLs from img tags in the content
305
319
$ image_urls = array ();
306
320
preg_match_all ( '/<img[^>]+src=[" \']([^" \']+)[" \'][^>]*>/i ' , $ content , $ matches );
307
-
321
+
308
322
if ( ! empty ( $ matches [1 ] ) ) {
309
323
$ image_urls = array_unique ( $ matches [1 ] );
310
324
}
0 commit comments