Skip to content

Commit

Permalink
Updateeeee
Browse files Browse the repository at this point in the history
  • Loading branch information
officiallygod committed Aug 19, 2024
1 parent 957ffb1 commit 8a9415d
Showing 1 changed file with 51 additions and 22 deletions.
73 changes: 51 additions & 22 deletions includes/SiteGen/SiteGen.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,56 @@ private static function generate_pattern_content(
return $category_pattern_map;
}

/**
* Function to generate the site meta according to the arguments passed
*
* @param array $site_info The Site Info object, will be validated for required params.
*/
public static function generate_site_posts( $site_info ) {

// Generate AI Post Title and Content
$site_posts = wp_remote_post(
NFD_AI_BASE . 'generateSiteMeta',
array(
'headers' => array(
'Content-Type' => 'application/json',
),
'timeout' => 60,
'body' => wp_json_encode(
array(
'hiivetoken' => HiiveConnection::get_auth_token(),
'prompt' => self::get_prompt_from_info( $site_info ),
'identifier' => 'generateSitePosts',
)
),
)
);

$site_posts_response_code = wp_remote_retrieve_response_code( $site_posts );
$site_posts = json_decode( wp_remote_retrieve_body( $site_posts ), true );
if ( 200 === $site_posts_response_code ) {
// Save Post Content in wp_options
self::cache_sitegen_response( 'site-posts', $site_posts );
}

$post_dates = array( '3', '5', '10', '12', '17', '19' );
foreach ( $site_posts as $post_title => $post_content ) {
$post = array(
'post_title' => $post_title,
'post_status' => 'publish',
'post_content' => $post_content,
'post_type' => 'page',
);
echo "\n\n";
print_r(json_encode($post));
echo "\n\n";
echo date( 'Y-m-d H:i:s', strtotime( 'last sunday -'. $post_dates[5].' days' ) );
echo "\n\n";
// \wp_insert_post( $post );
}

}

/**
* Function to generate the site meta according to the arguments passed
*
Expand Down Expand Up @@ -345,28 +395,7 @@ public static function generate_site_meta( $site_info, $identifier, $skip_cache
if ( 'siteclassification' === $identifier ) {
// If the user is a writer or a blogger.
if ( 'blog' === $parsed_response['slug'] ) {
$site_posts = wp_remote_post(
NFD_AI_BASE . 'generateSiteMeta',
array(
'headers' => array(
'Content-Type' => 'application/json',
),
'timeout' => 60,
'body' => wp_json_encode(
array(
'hiivetoken' => HiiveConnection::get_auth_token(),
'prompt' => self::get_prompt_from_info( $site_info ),
'identifier' => 'generateSitePosts',
)
),
)
);

$site_posts_response_code = wp_remote_retrieve_response_code( $site_posts );
$parsed_site_posts = json_decode( wp_remote_retrieve_body( $site_posts ), true );
if ( 200 === $site_posts_response_code ) {
self::cache_sitegen_response( 'site-posts', $parsed_site_posts );
}
self::generate_site_posts( $site_info );
}
}

Expand Down

0 comments on commit 8a9415d

Please sign in to comment.