aipstx_styles[$style_selection])) { $parts[] = 'Style: ' . $this->aipstx_styles[$style_selection]; } if (!empty($artist_selection) && $artist_selection != 'Select an artist...' && isset($this->aipstx_artists[$artist_selection])) { if (!empty($parts)) { $parts[] = ','; } $parts[] = 'Artist: ' . $artist_selection; } if (!empty($photography_selection) && $photography_selection != 'Select a photography style...' && isset($this->aipstx_photographs[$photography_selection])) { if (!empty($parts)) { $parts[] = ','; } $parts[] = 'Photography: ' . $photography_selection; } if (!empty($lighting_selection) && $lighting_selection != 'Select a lighting style...' && isset($this->aipstx_lightings[$lighting_selection])) { if (!empty($parts)) { $parts[] = ','; } $parts[] = 'Lighting: ' . $lighting_selection; } if (!empty($camera_selection) && $camera_selection != 'Select a camera style...' && isset($this->aipstx_cameras[$camera_selection])) { if (!empty($parts)) { $parts[] = ','; } $parts[] = 'Camera: ' . $camera_selection; } if (!empty($effect_selection) && $effect_selection != 'Select an effect style...' && isset($this->aipstx_effects[$effect_selection])) { if (!empty($parts)) { $parts[] = ','; } $parts[] = 'Effect: ' . $effect_selection; } return !empty($parts) ? 'with the following settings: ' . implode(' ', $parts) : ''; } public function aipstx_create_image() { if (!check_ajax_referer('aipstx_nonce', 'nonce', false)) { wp_send_json_error(array('message' => 'Nonce verification failed.')); return; } if (!current_user_can('edit_posts')) { wp_send_json_error('Unauthorized user'); wp_die(); } $prompt = isset($_POST['prompt']) ? sanitize_text_field($_POST['prompt']) : ''; $negative_prompt = isset($_POST['negative_prompt']) ? sanitize_text_field($_POST['negative_prompt']) : ''; if (empty($prompt)) { wp_send_json_error('Prompt cannot be empty. Please type a prompt in the Prompt for Images field.'); wp_die(); } // veriyi isle $styles_instance = AIPSTX_img_styles::get_instance(); $this->aipstx_styles = $styles_instance->aipstx_get_styles(); $style_selection = isset($_POST['style']) ? sanitize_text_field($_POST['style']) : ''; $artists_instance = AIPSTX_img_artists::get_instance(); $this->aipstx_artists = $artists_instance->aipstx_get_artists(); $artist_selection = isset($_POST['artist']) ? sanitize_text_field($_POST['artist']) : ''; $photographs_instance = AIPSTX_img_photographs::get_instance(); $this->aipstx_photographs = $photographs_instance->aipstx_get_photographs(); $photography_selection = isset($_POST['photography']) ? sanitize_text_field($_POST['photography']) : ''; $lightings_instance = AIPSTX_img_lightings::get_instance(); $this->aipstx_lightings = $lightings_instance->aipstx_get_lightings(); $lighting_selection = isset($_POST['lighting']) ? sanitize_text_field($_POST['lighting']) : ''; $cameras_instance = AIPSTX_img_cameras::get_instance(); $this->aipstx_cameras = $cameras_instance->aipstx_get_cameras(); $camera_selection = isset($_POST['camera']) ? sanitize_text_field($_POST['camera']) : ''; $effects_instance = AIPSTX_img_effects::get_instance(); $this->aipstx_effects = $effects_instance->aipstx_get_effects(); $effect_selection = isset($_POST['effect']) ? sanitize_text_field($_POST['effect']) : ''; $processed_settings = $this->aipstx_process_options($style_selection, $artist_selection, $photography_selection, $lighting_selection, $camera_selection, $effect_selection); // Eğer işlenmiş ayarlar boş değilse, prompt'a ekle if (!empty($processed_settings)) { $prompt .= ' ' . $processed_settings; } // Prompt'un sonuna nokta koyma işlemi gerekiyorsa burada yapılır if (!empty($prompt)) { $prompt .= '.'; } $image_count = isset($_POST['image_count']) ? intval($_POST['image_count']) : 1; $engine = isset($_POST['engine']) ? sanitize_text_field($_POST['engine']) : 'openai'; $resolution = isset($_POST['resolution']) ? sanitize_text_field($_POST['resolution']) : '1024x1024'; // DALL-E 3 engine selected if ($engine == 'dall-e3') { $aipstx_openai_key = get_option('aipstx_openai_key'); if (empty($aipstx_openai_key)) { wp_send_json_error('Missing OpenAI API key for DALL-E 3. Please enter your OpenAI API key.'); wp_die(); } $api_url = 'https://api.openai.com/v1/images/generations'; $args = array( 'method' => 'POST', 'timeout' => 90, 'headers' => array( 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $aipstx_openai_key ), 'body' => wp_json_encode([ 'prompt' => $prompt . $negative_prompt, 'n' => $image_count, 'size' => $resolution]) ); $response = wp_remote_post($api_url, $args); if (is_wp_error($response)) { AIPSTX_notifications::get_instance()->send_error_message($response->get_error_message()); wp_die(); } $response_data = json_decode(wp_remote_retrieve_body($response), true); if (isset($response_data['data'])) { $images = array_map(function ($item) { return $item['url']; }, $response_data['data']); wp_send_json_success($images); } if (isset($response_data['error'])) { AIPSTX_notifications::get_instance()->send_error_message($response_data['error']['message']); wp_die(); } else { AIPSTX_notifications::get_instance()->send_error_message('OpenAI Response: ' . wp_json_encode($response_data)); wp_die(); } } else { // EdenAI engine selected $aipstx_edenai_key = get_option('aipstx_edenai_key'); if (empty($aipstx_edenai_key)) { wp_send_json_error('Missing EdenAI API key for the selected engine'); wp_die(); } $api_url = 'https://api.edenai.run/v2/image/generation'; $args = array( 'method' => 'POST', 'timeout' => 90, 'headers' => array( 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $aipstx_edenai_key ), 'body' => wp_json_encode([ "response_as_dict" => true, "attributes_as_list" => false, "show_original_response" => false, "resolution" => $resolution, "num_images" => $image_count, "providers" => $engine, "text" => $prompt . $negative_prompt ]) ); $response = wp_remote_post($api_url, $args); $response_body = wp_remote_retrieve_body($response); if (is_wp_error($response)) { AIPSTX_notifications::get_instance()->send_error_message($response->get_error_message()); wp_die(); } $response_data = json_decode(wp_remote_retrieve_body($response), true); if (!empty($response_data) && isset($response_data[$engine]) && isset($response_data[$engine]['status']) && $response_data[$engine]['status'] == 'success') { $images = array_map(function ($item) { return $item['image_resource_url']; }, $response_data[$engine]['items']); wp_send_json_success($images); } if (isset($response_data['error'])) { AIPSTX_notifications::get_instance()->send_error_message($response_data['error']['message']); wp_die(); } elseif (isset($response_data[$engine]) && $response_data[$engine]['status'] === 'fail') { AIPSTX_notifications::get_instance()->send_error_message($response_data[$engine]['error']['message']); wp_die(); } else { AIPSTX_notifications::get_instance()->send_error_message('An unexpected error occurred with the EdenAI response. Please check your API credit and make sure it is sufficient.'); wp_die(); } } wp_die(); } } AIPSTX_genimg::get_instance(); }