PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 4.8.9
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v4.8.9
8.7.7 8.7.6 8.7.5 8.7.4 8.7.3 8.7.2 8.7.1 8.7.0 8.6.9 8.6.8 8.6.7 8.6.6 8.6.5 8.6.4 8.6.2 8.6.1 8.6.0 8.5.9 8.5.8 8.5.7 8.5.6 8.5.5 8.5.4 8.5.3 8.5.2 All 533 releases
chatbot / includes / openai / qcld-bot-openai.php

qcld-bot-openai.php in WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services 4.8.9, at includes/openai/qcld-bot-openai.php

2,492 lines 137.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if (!defined('ABSPATH')) exit; // Exit if accessed directly
3
4 if(!class_exists('qcld_wpopenai_addons')){
5
6
7 /**
8 * Main Class.
9 */
10 final class qcld_wpopenai_addons
11 {
12 private $id = 'Open AI';
13
14 /**
15 * WPBot Pro version.
16 *
17 * @var string
18 */
19 public $version = '1.0.6';
20
21 /**
22 * WPBot Pro helper.
23 *
24 * @var object
25 */
26 public $helper;
27
28 /**
29 * The single instance of the class.
30 *
31 * @var qcld_wb_Chatbot
32 * @since 1.0.0
33 */
34 protected static $_instance = null;
35
36 /**
37 * Main wpbot Instance.
38 *
39 * Ensures only one instance of wpbot is loaded or can be loaded.
40 *
41 * @return qcld_wb_Chatbot - Main instance.
42 * @since 1.0.0
43 * @static
44 */
45 public static function instance() {
46 if ( is_null( self::$_instance ) ) {
47 self::$_instance = new self();
48 }
49
50 return self::$_instance;
51 }
52
53 public $response_list;
54
55 /**
56 * Constructor
57 */
58 public function __construct()
59 {
60 $this->define_constants();
61 $this->includes();
62 add_action('wp_ajax_openai_settings_option', [$this, 'openai_settings_option_callback']);
63 add_action('wp_ajax_openai_file_upload', [$this, 'openai_file_upload_callback']);
64 add_action('wp_ajax_openai_response',[$this,'openai_response_callback']);
65 add_action('wp_ajax_openai_file_list',[$this,'openai_file_list_callback']);
66 add_action('wp_ajax_openai_finetune_list', [$this,'openai_finetune_list']);
67 add_action('wp_ajax_openai_file_delete',[$this,'openai_file_delete_callback']);
68 add_action('wp_ajax_nopriv_openai_response', [$this, 'openai_response_callback']);
69 add_action('wp_ajax_openai_ft_model_create', [$this, 'openai_ft_model_create']);
70 add_action('wp_ajax_openai_ft_model_delete', [$this, 'openai_ft_model_delete']);
71 add_action('wp_ajax_qcld_openai_post_data_converter_count', [$this,'qcld_openai_post_data_converter_count']);
72 add_action('wp_ajax_qcld_openai_post_data_converter', [$this,'qcld_openai_post_data_converter']);
73 add_action('wp_ajax_qcld_openai_upload_pagetraining_file',[$this, 'qcld_openai_upload_pagetraining_file']);
74 add_action('wp_ajax_qcld_openai_image_generate',[$this, 'qcld_openai_image_generate']);
75 add_action('wp_ajax_openai_keyword_suggestion_content',[$this,'openai_keyword_suggestion_content']);
76 add_action('wp_ajax_qcld_openai_image_generate_url',[$this,'qcld_seo_image_generate_url_functions']);
77 add_action('wp_ajax_qcld_openai_file_dowload',[$this,'qcld_openai_file_dowload']);
78 add_action('wp_ajax_qcld_openai_delete_training_file',[$this,'qcld_openai_delete_training_file']);
79
80 if (is_admin() && !empty($_GET["page"]) && (($_GET["page"] == "openai-panel_dashboard") || ($_GET["page"] == "openai-panel_file") || ($_GET["page"] == "openai-panel_help"))) {
81 add_action('admin_enqueue_scripts', array($this, 'qcld_wb_chatbot_admin_scripts'));
82 }
83
84
85 }
86
87
88 /**
89 * Define wpbot Constants.
90 *
91 * @return void
92 * @since 1.0.0
93 */
94 public function define_constants() {
95 if( ! defined( 'QCLD_openai_addon_VERSION' ) ){
96 define('QCLD_openai_addon_VERSION', $this->version);
97 }
98 //define('QCLD_openai_addon_REQUIRED_wpCOMMERCE_VERSION', 2.2);
99
100 if( ! defined( 'QCLD_openai_addon_PLUGIN_DIR_PATH' ) ){
101 define('QCLD_openai_addon_PLUGIN_DIR_PATH', plugin_dir_path(__FILE__));
102 }
103 if( ! defined( 'QCLD_openai_addon_PLUGIN_URL' ) ){
104 define('QCLD_openai_addon_PLUGIN_URL', plugin_dir_url(__FILE__));
105 }
106 if( ! defined( 'QCLD_openai_addon_IMG_URL' ) ){
107 define('QCLD_openai_addon_IMG_URL', QCLD_openai_addon_PLUGIN_URL . "images/");
108 }
109 if( ! defined( 'QCLD_openai_addon_IMG_ABSOLUTE_PATH' ) ){
110 define('QCLD_openai_addon_IMG_ABSOLUTE_PATH', plugin_dir_path(__FILE__) . "images");
111 }
112
113 }
114
115
116 public function qcld_wb_chatbot_admin_scripts(){
117 // wp_register_style('qlcd-open-ai-bootstap', QCLD_openai_addon_PLUGIN_URL . 'css/openai-bootstrap.css', '', QCLD_openai_addon_VERSION, 'screen');
118 // wp_enqueue_style('qlcd-open-ai-bootstap');
119 // wp_register_style('qlcd-open-ai-admin-style', QCLD_openai_addon_PLUGIN_URL . 'css/openai-admin-style.css', '', QCLD_openai_addon_VERSION, 'screen');
120 // wp_enqueue_style('qlcd-open-ai-admin-style');
121 // wp_register_script('qlcd-openai_collapse', QCLD_openai_addon_PLUGIN_URL . 'js/collapse.js', array('jquery'),'',QCLD_openai_addon_VERSION,true);
122 // wp_enqueue_script('qlcd-openai_collapse');
123 // wp_register_script('qlcd-openai_settings', QCLD_openai_addon_PLUGIN_URL . 'js/openai_settings.js', array('jquery'),'',QCLD_openai_addon_VERSION,true);
124 // wp_enqueue_script('qlcd-openai_settings');
125
126 // wp_localize_script( 'qlcd-openai_settings', 'openai_ajax', array(
127 // 'url' => admin_url( 'admin-ajax.php' ),
128 // ) );
129
130 }
131 /**
132 * Include all required files
133 *
134 * since 1.0.0
135 *
136 * @return void
137 */
138 public function includes() {
139 require_once( QCLD_wpCHATBOT_PLUGIN_DIR_PATH . "includes/openai/qcld_wp_OpenAI.php" );
140 require_once( QCLD_wpCHATBOT_PLUGIN_DIR_PATH . "includes/openai/OpenAi_WPBot_Menu.php" );
141
142 }
143 public function openai_file_delete_callback(){
144 $file_id = sanitize_text_field($_POST['file_id']);
145 $url = 'https://api.openai.com/v1/files/'. $file_id;
146 $apt_key = "Authorization: Bearer ". get_option('open_ai_api_key');
147 $ch = curl_init();
148 curl_setopt($ch, CURLOPT_URL, $url);
149 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
150 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
151 $headers = array(
152 $apt_key,
153 );
154 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
155 $result = curl_exec($ch);
156 if (curl_errno($ch)) {
157 echo 'Error:' . curl_error($ch);
158 }
159 curl_close($ch);
160 wp_send_json( json_decode($result));
161 wp_die();
162 }
163 public function openai_ft_model_create(){
164 $file_id = sanitize_text_field($_POST['file_id']);
165 $ft_suffix = sanitize_text_field($_POST['ft_suffix']);
166 $ft_engines = sanitize_text_field($_POST['ft_engines']);
167 $rel = $this->openai_finetune_create($file_id,$ft_suffix,$ft_engines);
168 // print_r(wp_send_json([$rel]));wp_die();
169 echo wp_send_json([$rel]);
170 wp_die();
171 }
172 public function qcld_openai_file_dowload(){
173
174 // -H "Authorization: Bearer $OPENAI_API_KEY" > results.csv
175
176 $file_id = sanitize_text_field($_POST['file_id']);
177 $url = 'https://api.openai.com/v1/files/'.$file_id;
178 $url1 = 'https://api.openai.com/v1/files/'.$file_id. '/content';
179 $apt_key = "Authorization: Bearer ". get_option('open_ai_api_key');
180 $headers = array(
181 "Content-Type: application/json",
182 $apt_key,
183 );
184 $headers1 = array(
185 "Content-Type: file.jsonl",
186 $apt_key,
187 );
188 $curl = curl_init();
189 curl_setopt($curl, CURLOPT_URL, $url);
190 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
191 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
192 $result = json_decode(curl_exec($curl));
193 curl_close($curl);
194 $ch = curl_init();
195 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
196 curl_setopt($ch, CURLOPT_URL, $url1);
197 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
198 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
199 //curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
200 $res = curl_exec($ch);
201 if (curl_errno($ch)) {
202 echo 'Error:' . curl_error($ch);
203 }
204 curl_close($ch);
205 // var_dump($res);
206 if(!empty($result)){
207 $response['status'] = 'success';
208 $response['fileinfo'] = $result;
209 $response['filedata'] = $res;
210
211 }
212 echo wp_send_json([$response]);
213 wp_die();
214
215 }
216 public function buildFormBody( $fields, $boundary )
217 {
218 $body = '';
219 foreach ( $fields as $name => $value ) {
220 if ( $name == 'data' ) {
221 continue;
222 }
223 $body .= "--$boundary\r\n";
224 $body .= "Content-Disposition: form-data; name=\"$name\"";
225 if ( $name == 'file' ) {
226 $body .= "; filename=\"{$value}\"\r\n";
227 $body .= "Content-Type: application/json\r\n\r\n";
228 $body .= $fields['data'] . "\r\n";
229 }else {
230 $body .= "\r\n\r\n$value\r\n";
231 }
232 }
233 $body .= "--$boundary--\r\n";
234 return $body;
235 }
236
237 public function openai_file_list_callback(){
238 $url = 'https://api.openai.com/v1/files';
239 $apt_key = "Authorization: Bearer ". get_option('open_ai_api_key');
240 $curl = curl_init();
241 curl_setopt($curl, CURLOPT_URL, $url);
242 $headers = array(
243 "Content-Type: application/json",
244 $apt_key,
245 );
246 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
247 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
248 $response = curl_exec($curl);
249 curl_close($curl);
250 wp_send_json( json_decode($response));
251 wp_die();
252 }
253 public function qcld_sanitize_text_or_array_field($array_or_string) {
254 if( is_string($array_or_string) ){
255 $array_or_string = sanitize_text_field($array_or_string);
256 }elseif( is_array($array_or_string) ){
257 foreach ( $array_or_string as $key => &$value ) {
258 if ( is_array( $value ) ) {
259 $value = $this->sanitize_text_or_array_field($value);
260 }
261 else {
262 $value = sanitize_text_field( $value );
263 }
264 }
265 }
266
267 return $array_or_string;
268 }
269 public function qcld_openai_post_data_converter_count()
270 {
271 global $wpdb;
272 $qcldopenai_result = array('status' => 'error');
273 if(isset($_POST['data']) && is_array($_POST['data'])){
274 $types = Self::qcld_sanitize_text_or_array_field($_POST['data']);
275 $sql = "SELECT COUNT(*) FROM ".$wpdb->posts." WHERE post_status='publish' AND post_type IN ('".implode("','",$types)."')";
276 $qcldopenai_result['count'] = $wpdb->get_var($sql);
277 $qcldopenai_result['status'] = 'success';
278 $qcldopenai_result['types'] = $types;
279 }
280 else $qcldopenai_result['msg'] = 'Please select least one data to convert';
281
282 $this->qcld_openai_post_data_converter($qcldopenai_result);
283 }
284
285 public function qcld_openai_post_data_converter($result)
286 {
287 $qcldopenai_result = array('status' => 'error','msg' => 'Something went wrong');
288 global $wpdb;
289 if(
290 isset($result['types'])
291 && is_array($result['types'])
292 ){
293 $types = Self::qcld_sanitize_text_or_array_field($result['types']);
294
295 $qcldopenai_total = sanitize_text_field($_POST['total']);
296 $qcldopenai_per_page = sanitize_text_field($_POST['per_page']);
297 $qcldopenai_page = isset($_POST['page']) && !empty($_POST['page']) ? sanitize_text_field($_POST['page']) : 1;
298 if(isset($_POST['file']) && !empty($_POST['file'])){
299 $qcldopenai_file = sanitize_text_field($_POST['file']);
300 }else{
301 $qcldopenai_file = md5(time()).'.jsonl';
302 }
303 if(isset($_POST['id']) && !empty($_POST['id'])){
304 $qcldopenai_convert_id = sanitize_text_field($_POST['id']);
305 }else{
306 $qcldopenai_convert_id = wp_insert_post(array(
307 'post_title' => $qcldopenai_file,
308 'post_type' => 'qcldopenai_convert',
309 'post_status' => 'publish'
310 ));
311 } try {
312 $upload = wp_upload_dir();
313 $upload_dir = $upload['basedir'] . '/' . 'qcldopenai_site_training';
314 $permissions = 0755;
315 $oldmask = umask(0);
316 if (!is_dir($upload_dir)){
317 mkdir($upload_dir, $permissions);
318 $umask = umask($oldmask);
319 $chmod = chmod($upload_dir, $permissions);
320 }
321 $gcdirpath = WP_CONTENT_DIR.'/qcldopenai_site_training';
322 $qcldopenai_json_file = fopen(wp_upload_dir()['basedir'] .'/qcldopenai_site_training/'.basename($qcldopenai_file), "w");
323 $qcldopenai_content = '';
324 $sql = "SELECT post_title, post_content FROM ".$wpdb->posts." WHERE post_status='publish' AND post_type IN ('".implode("','",$types)."') ORDER BY post_date";
325 $qcldopenai_data = $wpdb->get_results($sql);
326 if($qcldopenai_data && is_array($qcldopenai_data) && count($qcldopenai_data)){
327 foreach($qcldopenai_data as $item){
328 $tag_less_content = wp_strip_all_tags($item->post_content);
329 $vc_tag_less = preg_replace("/\[(\/*)?vc_(.*?)\]/", '', $tag_less_content);
330 $clean_html_body = preg_replace('/\xc2\xa0/', '', $vc_tag_less);
331 $completion_string = str_replace(array("\n","\r","\t","&nbsp;"), ' ', $clean_html_body);
332 $completion_string = wp_trim_words( $completion_string,500);
333
334 $tag_less_title = wp_strip_all_tags($item->post_title);
335 $clean_html_title = preg_replace('/\xc2\xa0/', '', $tag_less_title);
336 $title_string = str_replace(array("\n","\r","\t","&nbsp;"), ' ', $clean_html_title);
337 $title_string = wp_trim_words( $title_string,50);
338 $data = array(
339 "prompt" => $title_string.' ->',
340 "completion" => $completion_string
341 );
342 fwrite($qcldopenai_json_file, json_encode($data) . PHP_EOL);
343 }
344 }
345 fclose($qcldopenai_json_file);
346 $qcldopenai_result['file'] = $qcldopenai_file;
347 $qcldopenai_result['id'] = $qcldopenai_convert_id;
348 $qcldopenai_result['status'] = 'success';
349 } catch (\Exception $exception){
350 $qcldopenai_result['msg'] = $exception->getMessage();
351 }
352 }
353 else $qcldopenai_result['msg'] = 'Please select least one data to convert';
354 wp_send_json($qcldopenai_result);
355 }
356
357 public function openai_ft_model_delete(){
358 $ft_id = sanitize_text_field($_POST['ft_id']);
359 $url = 'https://api.openai.com/v1/models/' . $ft_id;
360 $apt_key = "Authorization: Bearer ". get_option('open_ai_api_key');
361 $curl = curl_init();
362 $headers = array(
363 "Content-Type: multipart/form-data",
364 $apt_key,
365 );
366 curl_setopt($curl, CURLOPT_URL, $url);
367 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
368 curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
369 curl_setopt($curl, CURLOPT_POST, true);
370 $res = json_decode(curl_exec ($curl));
371 curl_close ($curl);
372 echo wp_send_json([$rel]);
373 wp_die();
374
375 }
376 public function qcld_openai_upload_pagetraining_file(){
377
378 if(
379 isset($_POST['filename'])
380 && !empty($_POST['filename'])
381 ){
382 $filename = sanitize_text_field($_POST['filename']);
383 $line = isset($_POST['line']) && !empty($_POST['line']) ? sanitize_text_field($_POST['line']) : 0;
384 $file = wp_upload_dir()['basedir'].'/qcldopenai_site_training/'.$filename;
385 if(file_exists($file)){
386 $qcld_openai_lines = file($file);
387 $fileo = '@'. wp_upload_dir()['basedir'].'/qcldopenai_site_training/'.$filename;
388 $split_file = wp_upload_dir()['basedir'].'/qcldopenai_site_training/'.$filename;
389 $qcld_openai_json_file = fopen($split_file, "a");
390 $qcld_openai_content = '';
391 for($i = $line; $i <= count($qcld_openai_lines);$i++){
392 if($i == count($qcld_openai_lines)){
393 $qcld_openai_content .= $qcld_openai_lines[$i];
394 $qcld_openai_result['next'] = 'DONE';
395 }
396 else{
397 if(mb_strlen($qcld_openai_content, '8bit') > $this->wpaicg_max_file_size){
398 $qcld_openai_result['next'] = $i+1;
399 break;
400 }
401 else{
402 $qcld_openai_content .= $qcld_openai_lines[$i];
403 }
404 }
405 }
406 fwrite($qcld_openai_json_file,$qcld_openai_content);
407 fclose($qcld_openai_json_file);
408 $url = 'https://api.openai.com/v1/files';
409 $apt_key = "Authorization: Bearer ". get_option('open_ai_api_key');
410 $curl = curl_init($url);
411 $c_file = curl_file_create($split_file, mime_content_type($split_file),basename($split_file));
412 $data = array(
413 'purpose' => 'fine-tune',
414 'file' => $c_file,
415 );
416 curl_setopt($curl, CURLOPT_URL, $url);
417 curl_setopt($curl, CURLOPT_POST, true);
418 $headers = array(
419 "Content-Type: multipart/form-data",
420 $apt_key,
421 );
422 $init = curl_init();
423 curl_setopt($init, CURLOPT_URL,$url);
424 curl_setopt($init, CURLOPT_HTTPHEADER, $headers);
425 curl_setopt($init, CURLOPT_POSTFIELDS, $data);
426 curl_setopt($init, CURLOPT_RETURNTRANSFER, true);
427 $res = json_decode(curl_exec ($init));
428
429 curl_close ($init);
430 if(!empty($res->error)){
431 $response['status'] = 'error';
432 $response['message'] = $res->error->message;
433 }
434
435 if(!empty($res->status)){
436 $response['status'] = 'success';
437 $response['message'] = 'Successfully Created file' . $res->id ;
438
439 }
440 echo wp_send_json([$response]);
441 wp_die();
442 } else {
443 if(!empty($res->status)){
444 $response['status'] = 'error';
445 $response['message'] = 'The file has been removed from wp-uploads';
446 }
447 }
448 }
449 }
450 public function openai_file_upload_callback(){
451 $uploadedfile = $_FILES['file'];
452 $url = 'https://api.openai.com/v1/files';
453 $apt_key = "Authorization: Bearer ". get_option('open_ai_api_key');
454 $curl = curl_init($url);
455 curl_setopt($curl, CURLOPT_URL, $url);
456 curl_setopt($curl, CURLOPT_POST, true);
457 $headers = array(
458 "Content-Type: multipart/form-data",
459 $apt_key,
460 );
461 if (function_exists('curl_file_create')) {
462 $tmp_file = curl_file_create($uploadedfile['tmp_name'], 'jsonl', $uploadedfile['name']);
463 } else {
464 $tmp_file = open($uploadedfile['tmp_name']);
465 }
466
467 $data = array('file'=> $tmp_file,'purpose'=> 'fine-tune');
468 $init = curl_init();
469 //function parameteres
470 curl_setopt($init, CURLOPT_URL,$url);
471 curl_setopt($init, CURLOPT_HTTPHEADER, $headers);
472 curl_setopt($init, CURLOPT_POSTFIELDS, $data);
473 curl_setopt($init, CURLOPT_RETURNTRANSFER, true);
474 $res = json_decode(curl_exec ($init));
475
476 curl_close ($init);
477 if(!empty($res->error)){
478 $response['status'] = 'error';
479 $response['message'] = $res->error->message;
480 }
481
482 if(!empty($res->status)){
483 $response['status'] = 'success';
484 $response['message'] = 'Successfully Created file' . $res->id ;
485
486 }
487 echo wp_send_json([$response]);
488 wp_die();
489 }
490 public function qcld_openai_image_generate(){
491
492 $qcld_seo_result = array(
493 'status' => 'error',
494 'msg' => 'Something went wrong',
495 );
496 $OPENAI_API_KEY = get_option('open_ai_api_key');
497 $qcld_seo_prompt = isset( $_POST['qcld_seo_prompt'] ) ? sanitize_text_field( $_POST['qcld_seo_prompt'] ) : '';
498 $qcld_seo_artist = isset( $_POST['qcld_seo_artist'] ) ? sanitize_text_field( $_POST['qcld_seo_artist'] ) : 'Painter';
499 $qcld_seo_art_style = isset( $_POST['qcld_seo_art_style'] ) ? sanitize_text_field( $_POST['qcld_seo_art_style'] ) : 'Style';
500 $qcld_seo_photography_style = isset( $_POST['qcld_seo_photography_style'] ) ? sanitize_text_field( $_POST['qcld_seo_photography_style'] ) : 'Photography Style';
501 $qcld_seo_lighting = isset( $_POST['qcld_seo_lighting'] ) ? sanitize_text_field( $_POST['qcld_seo_lighting'] ) : 'Lighting';
502 $qcld_seo_subject = isset( $_POST['qcld_seo_subject'] ) ? sanitize_text_field( $_POST['qcld_seo_subject'] ) : 'Subject';
503 $qcld_seo_camera_settings = isset( $_POST['qcld_seo_camera_settings'] ) ? sanitize_text_field( $_POST['qcld_seo_camera_settings'] ) : 'Camera Settings';
504 $qcld_seo_composition = isset( $_POST['qcld_seo_composition'] ) ? sanitize_text_field( $_POST['qcld_seo_composition'] ) : 'Composition';
505 $qcld_seo_resolution = isset( $_POST['qcld_seo_resolution'] ) ? sanitize_text_field( $_POST['qcld_seo_resolution'] ) : 'Resolution';
506 $qcld_seo_color = isset( $_POST['qcld_seo_color'] ) ? sanitize_text_field( $_POST['qcld_seo_color'] ) : 'Color';
507 $qcld_seo_special_effects = isset( $_POST['qcld_seo_special_effects'] ) ? sanitize_text_field( $_POST['qcld_seo_special_effects'] ) : 'Special Effects';
508 $qcld_seo_img_size = isset( $_POST['qcld_seo_img_size'] ) ? sanitize_text_field( $_POST['qcld_seo_img_size'] ) : '512x512';
509 $qcld_seo_num_images = isset( $_POST['qcld_seo_num_images'] ) ? sanitize_text_field( $_POST['qcld_seo_num_images'] ) : 1;
510 $qcld_seo_num_images = isset( $qcld_seo_num_images ) ? (int) $qcld_seo_num_images : 6;
511 if (!empty($qcld_seo_prompt)) {
512 // Get the prompt from the form
513 $prompt = $qcld_seo_prompt;
514 $img_size = $qcld_seo_img_size;
515 $num_images = $qcld_seo_num_images;
516 // convert num_images to an integer
517 $num_images = (int) $num_images;
518 $prompt_elements = array(
519 'artist' => $qcld_seo_artist,
520 'art_style' => $qcld_seo_art_style,
521 'photography_style' => $qcld_seo_photography_style,
522 'composition' => $qcld_seo_composition,
523 'resolution' => $qcld_seo_resolution,
524 'color' => $qcld_seo_color,
525 'special_effects' => $qcld_seo_special_effects,
526 'lighting' => $qcld_seo_lighting,
527 'subject' => $qcld_seo_subject,
528 'camera_settings' => $qcld_seo_camera_settings,
529 );
530 foreach ($prompt_elements as $key => $value) {
531 if ($_POST[$key] != "None") {
532 $prompt = $prompt . ". " . $value . ": " . $_POST[$key];
533 }
534 }
535 // Send the request to OpenAI
536 $request_body = [
537 "prompt" => $prompt,
538 "n" => $num_images,
539 "size" => $img_size,
540 "response_format" => "url",
541 ];
542 $data = json_encode($request_body);
543 $url = "https://api.openai.com/v1/images/generations";
544 $apt_key = "Authorization: Bearer ". $OPENAI_API_KEY;
545 $curl = curl_init($url);
546 curl_setopt($curl, CURLOPT_URL, $url);
547 curl_setopt($curl, CURLOPT_POST, true);
548 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
549 $headers = array(
550 "Content-Type: application/json",
551 $apt_key ,
552 );
553 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
554 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
555 $result = curl_exec($curl);
556 curl_close($curl);
557
558 // we need to catch the error here
559 $img_result = json_decode( $result );
560
561 $image_grid = '<div class="qcld_image_grid">';
562 for ($i = 0; $i < $num_images; $i++) {
563 $image_grid .= '<div class="qcld_image-grid_wrap qcld_botopenai_generate_image_download"> ';
564 $image_grid .= '<img class="qcld_image-item" src=' . esc_html($img_result->data[$i]->url) . '>';
565 $image_grid .= '<div class="qcld_seo_download" data-img="' . esc_html($img_result->data[$i]->url) . '"><button class="btn btn-success">Add to media libary</button></div>';
566 $image_grid .= '</div>';
567 }
568 $image_grid .= '</div>';
569 $qcld_seo_result['status'] = 'success';
570 $qcld_seo_result['html'] = $image_grid;
571
572 }
573
574 wp_send_json( $qcld_seo_result );
575 }
576 public function qcld_openai_delete_training_file(){
577 $file = sanitize_text_field($_POST['file']);
578 $qcld_seo_result = array(
579 'status' => 'error',
580 'msg' => 'Something went wrong',
581 );
582 if (is_file($file)) {
583
584 chmod($file, 0777);
585
586 if (unlink($file)) {
587 $result = 'File deleted';
588 $qcld_seo_result['html'] = $result;
589 } else {
590 $result = 'Cannot remove that file';
591 $qcld_seo_result['html'] = $result;
592 }
593
594 } else {
595 $result = 'File does not exist';
596 $qcld_seo_result['html'] = $result;
597 }
598
599 wp_send_json( $qcld_seo_result );
600 wp_die();
601
602 }
603 public function openai_finetune_create($file_id,$ft_suffix,$ft_engines){
604 $apt_key = "Authorization: Bearer ". get_option('open_ai_api_key');
605 $headers = array(
606 "Content-Type: application/json",
607 $apt_key,
608 );
609 $curl = curl_init();
610 $qcld_openai_suffix = isset($ft_suffix) ? $ft_suffix : get_option('qcld_openai_suffix');
611 $openai_engines = isset($ft_engines) ? $ft_engines : get_option('openai_engines');
612 $base_engine = explode('-',$openai_engines);
613 $data = json_encode(array('training_file'=>$file_id,'model' => $base_engine[1], 'suffix' => $qcld_openai_suffix ));
614 $url = "https://api.openai.com/v1/fine-tunes";
615 curl_setopt($curl, CURLOPT_URL, $url);
616 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
617 curl_setopt($curl, CURLOPT_POST, true);
618 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
619 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
620 $result = json_decode(curl_exec($curl));
621 curl_close($curl);
622 return $result;
623 }
624 public function openai_finetune_list(){
625
626 $apt_key = "Authorization: Bearer ". get_option('open_ai_api_key');
627 $headers = array(
628 "Content-Type: application/json",
629 $apt_key,
630 );
631 $curl_ft = curl_init();
632 //$data = json_encode(array('training_file'=>$file_id));
633
634 $url = "https://api.openai.com/v1/fine-tunes";
635 curl_setopt($curl_ft, CURLOPT_URL, $url);
636 curl_setopt($curl_ft, CURLOPT_HTTPHEADER, $headers);
637 curl_setopt($curl_ft, CURLOPT_RETURNTRANSFER, true);
638 $result = json_decode(curl_exec($curl_ft));
639 $ft_arry = [];
640 foreach($result->data as $value ){
641 if(($value->training_files[0]->status != 'deleted') && ($value->result_files[0]->status != 'deleted') ){
642 $ft_arry[] = [$value->id,$value->fine_tuned_model,$value->status,$value->training_files[0]->filename,$value->training_files[0]->id];
643 }
644 }
645 curl_close($curl_ft);
646 wp_send_json( $ft_arry);
647 wp_die();
648
649
650 }
651 public function openai_retrive_fine_tune($keyword){
652
653 $apt_key = "Authorization: Bearer ". get_option('open_ai_api_key');
654 $headers = array(
655 "Content-Type: application/json",
656 $apt_key,
657 );
658 $curl = curl_init();
659 $max_tokens = (int)get_option( 'openai_max_tokens');
660 $temp = (float)get_option( 'openai_temperature');
661 $frequency_penalty = (float)get_option( 'frequency_penalty');
662 $presence_penalty = (float)get_option( 'presence_penalty');
663 $engines = explode('-',get_option( 'openai_engines'));
664
665 $data = json_encode(array(
666 'prompt'=>$keyword,
667 'model'=> get_option( 'qcld_openai_custom_model'),
668 "max_tokens" => $max_tokens,
669 "temperature" => $temp,
670 "top_p" => 1,
671 "presence_penalty" => $frequency_penalty,
672 "frequency_penalty"=> $presence_penalty,
673 "best_of"=> 1,
674 ));
675 $url = "https://api.openai.com/v1/completions";
676
677 $ch = curl_init();
678
679 curl_setopt($ch, CURLOPT_URL, 'https://api.openai.com/v1/completions');
680 // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
681 // curl_setopt($ch, CURLOPT_POST, 1);
682 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
683 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
684 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
685 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
686
687 $result = (curl_exec($ch));
688 $result = str_replace("#","",$result );
689 return $result;
690 if (curl_errno($ch)) {
691 echo 'Error:' . curl_error($ch);
692 }
693 curl_close($ch);
694
695 }
696 public function response_form_file($keyword){
697 $max_tokens = (int)get_option( 'openai_max_tokens');
698 $temp = (float)get_option( 'openai_temperature');
699 $frequency_penalty = (float)get_option( 'frequency_penalty');
700 $presence_penalty = (float)get_option( 'presence_penalty');
701 $engines = explode('-',get_option( 'openai_engines'));
702 if($engines[0] != 'gpt'){
703 $prompts = $this->get_prompt($keyword);
704 }
705
706 $request_body = [
707 "prompt" => $keyword,
708 "model" => get_option( 'qcld_openai_custom_model'),
709 "max_tokens" => $max_tokens,
710 "temperature" => 0,
711 "top_p" => 1,
712 "stop" => [],
713 "presence_penalty" => 0,
714 "frequency_penalty"=> 0,
715 "best_of"=> 1,
716 ];
717 $postFields = json_encode($request_body);
718 $OpenAI = new qcld_wp_OpenAI();
719 $result = $OpenAI->get_response($postFields);
720
721 return $result;
722 }
723 public function get_prompt($keyword){
724 $openai_include_keyword = get_option( 'openai_include_keyword');
725 $openai_exclude_keyword = get_option( 'openai_exclude_keyword');
726 $qcld_openai_prompt = get_option('qcld_openai_prompt',true);
727 switch ($qcld_openai_prompt) {
728 case "q_and_a":
729 if(get_option('conversation_continuity') == 1){
730 if(empty($_COOKIE["last_five_prompt"])){
731 setcookie("last_five_prompt", "Q:".$keyword."\nA:", time() + (60000), "/");
732 return "Q:".$keyword."\nA:";
733 }else{
734 $last_five = $_COOKIE["last_five_prompt"];
735 setcookie("last_five_prompt", $last_five. "\nQ:".$keyword."\nA:", time() + (60000), "/");
736 return $last_five . "Q:".$keyword."\nA:";
737 }
738 }else{
739 return "Q:".$keyword."\nA:";
740 }
741 case "chat":
742 if(get_option('conversation_continuity') == 1){
743 if(empty($_COOKIE["last_five_prompt"])){
744 setcookie("last_five_prompt", "Human:".$keyword."\nAI:", time() + (60000), "/");
745 return "Human:".$keyword."\nAI:";
746 }else{
747 $last_five = $_COOKIE["last_five_prompt"];
748 setcookie("last_five_prompt", $last_five. "\nQ:".$keyword."\nA:", time() + (60000), "/");
749 return $last_five . "\nHuman:".$keyword."\nAI:";
750 }
751 }else{
752 return "\nHuman:".$keyword."\nAI:";
753 }
754
755 case "friend_chat":
756 if(get_option('conversation_continuity') == 1){
757 if(empty($_COOKIE["last_five_prompt"])){
758 setcookie("last_five_prompt", "You:".$keyword."\nFriend:", time() + (60000), "/");
759 return "You:".$keyword."\nFriend:";
760 }else{
761 $last_five = $_COOKIE["last_five_prompt"];
762 setcookie("last_five_prompt", $last_five. "\nQ:".$keyword."\nA:", time() + (60000), "/");
763 return $last_five . "\nYou:".$keyword."\nFriend:";
764 }
765 }else{
766 return "You:".$keyword."\nFriend:";
767 }
768 case "grammar_correction":
769 return "Correct this to standard English:\n\n ".$keyword." " ;
770 case "marv_sarcastic_chatbot" :
771 return "Marv is a chatbot that reluctantly answers questions with sarcastic responses:\n\nYou: ".$keyword." \nMarv:";
772 case "micro_horror":
773 return "\nTopic: ".$keyword."\n\nTwo-Sentence Horror Story:";
774 case "any_command":
775 return $keyword;
776 case "write_poem":
777 return "write a poem about". $keyword;
778 case "custom_prompt":
779 return get_option('qcld_openai_prompt_custom') ."\n" . $keyword;
780 default:
781 return "Q:".$keyword."\nA:";
782 }
783 }
784 public function include_exclude_prompt($keyword){
785 $openai_include_keyword = get_option('openai_include_keyword');
786 $openai_exclude_keyword = get_option('openai_exclude_keyword');
787 if((get_option('openai_include_keyword') != '') || (get_option('openai_exclude_keyword') == '')){
788 $prompts = 'If the query is not relevant to one of the keywords: '.$openai_include_keyword .' then only say DUH. Provide a response only if the following query is relevant to one of the keywords: '.$openai_include_keyword .' The actual query is as follows: '. $keyword;
789 return $prompts;
790 }else if((get_option('openai_include_keyword') == '') || (get_option('openai_exclude_keyword') != '')){
791
792 $prompts = 'If the query is relevant to one of the keywords: ' .$openai_exclude_keyword . ', then do not respond and only say "DUH." The actual query is as follows: '. $keyword. '?/n';
793 return $prompts;
794 }else if((get_option('openai_include_keyword') != '') || (get_option('openai_exclude_keyword') != '')){
795 $prompts = 'If the query is not relevant to one of the keywords: '.$openai_include_keyword .' then only say "DUH." Provide a response only if the following query is relevant to one of the keywords: '.$openai_include_keyword .' The actual query is as follows: '. $keyword;
796 return $prompts;
797 }
798 }
799 public function qcld_include_keyword_exist( $keyword ){
800 $keyword = isset($keyword) ? $keyword : '';
801 $openai_include_keywords = get_option('openai_include_keyword');
802 if(!empty($keyword)){
803 $openai_include_keyword = ( isset( $openai_include_keywords ) ? $openai_include_keywords : '');
804
805 if( !empty($openai_include_keyword)){
806 $include_items = explode(',', $openai_include_keyword);
807 if(!empty($include_items)){
808 foreach($include_items as $k => $item){
809 if((strpos($keyword,trim($item)) !== false) && !empty($item)){
810 return true;
811 }
812 }
813 }
814 return false;
815 }
816 }
817
818 return false;
819
820 }
821 public function openai_response_callback() {
822 $response['status'] = 'success';
823 $response['message'] ='A preset message';
824 $OpenAI = new qcld_wp_OpenAI();
825 $gptkeyword = [];
826 $keyword = sanitize_text_field($_POST['keyword']);
827 $response_files = $this->openai_retrive_fine_tune($keyword);
828 $response_file = json_decode($response_files, true);
829 $gptkeywords = [];
830 if(empty($response_file['choices'][0]["text"])){
831
832 $engines = explode('-',get_option( 'openai_engines'));
833 if($engines[0] == 'gpt'){
834
835 if(empty($_COOKIE["last_five_prompt"])){
836 array_push($gptkeyword, array(
837 "role" => "user",
838 "content" => $keyword
839 ));
840 setcookie('last_five_prompt', base64_encode(maybe_serialize($gptkeyword)) , time() + (60000), "/");
841 }else{
842 $data = ($_COOKIE['last_five_prompt']);
843 $data = (base64_decode($data));
844 $gptkeyword = maybe_unserialize($data);
845 if(is_array($gptkeyword)){
846 array_push( $gptkeyword, array(
847 "role" => "user",
848 "content" => $keyword
849 ));
850 setcookie('last_five_prompt', base64_encode(maybe_serialize($gptkeyword)) , time() + (60000), "/");
851 }
852 }
853
854 if((!empty(get_option('openai_include_keyword')) || !empty(get_option('openai_exclude_keyword'))) && (get_option('qcld_openai_relevant_enabled') == '1') ){
855 $prompts = $this->include_exclude_prompt($keyword);
856 $gptkeyword = [];
857 array_push($gptkeyword, array(
858 "role" => "user",
859 "content" => $prompts,
860 ));
861 }else if((!empty(get_option('openai_include_keyword')) || !empty(get_option('openai_exclude_keyword'))) && (get_option('qcld_openai_relevant_enabled') == '0')){
862 if($this->qcld_include_keyword_exist($keyword) == false){
863 $response['message'] = 'Sorry, No result found!';
864 echo json_encode($response);
865 wp_die();
866 }else{
867 array_push($gptkeyword, array(
868 "role" => "user",
869 "content" => $keyword
870 ));
871 }
872
873 }
874
875 $res = $OpenAI->gptcomplete(
876 $gptkeyword
877 );
878 $mess = json_decode($res);
879 $response['message'] = $mess->choices[0]->message->content;
880 if($response['message'] == 'DUH.' || $response['message'] == 'DUH'){
881 $response['message'] = 'Sorry, No result found!';
882 }
883 if(get_option('conversation_continuity') == 1){
884 $data = ($_COOKIE['last_five_prompt']);
885 $data = (base64_decode($data));
886 $gptkeywords = maybe_unserialize($data);
887 if(is_array($gptkeywords)){
888 array_push( $gptkeywords, array(
889 "role" => "assistant",
890 "content" => $response['message']
891 ));
892 setcookie('last_five_prompt', base64_encode(maybe_serialize($gptkeywords)) , time() + (60000), "/");
893 }
894 }
895
896 }else{
897 if(((get_option('openai_include_keyword') != '') || (get_option('openai_exclude_keyword') != '')) && (get_option('qcld_openai_relevant_enabled') == '1') ){
898 $prompts = $this->include_exclude_prompt($keyword);
899 }else if(((get_option('openai_include_keyword') != '') || (get_option('openai_exclude_keyword') != '')) && (get_option('qcld_openai_relevant_enabled') == '0')){
900 if($this->qcld_include_keyword_exist($keyword) == false){
901 $response['message'] = "Sorry, No result found!";
902 echo json_encode($response);
903 wp_die();
904 }else{
905 $prompts = $this->get_prompt($keyword);
906 }
907 }else{
908 $prompts = $this->get_prompt($keyword);
909 }
910 $prompt =$prompts;
911 $res = $OpenAI->complete(
912 $prompt
913 );
914
915 $mess = json_decode($res);
916 $response['message'] = $mess->choices[0]->text;
917 if($response['message'] == 'DUH.' || $response['message'] == 'DUH'){
918 $response['message'] = 'Sorry, No result found!';
919 }
920 if(get_option('conversation_continuity') == 1){
921 $lasfivecookie = $_COOKIE["last_five_prompt"] . $response['message'] . '###';
922 $response['cookie'] = $_COOKIE["last_five_prompt"];
923 }
924 }
925 }else{
926 $response['message'] = $response_file['choices'][0]["text"];
927 }
928 echo json_encode($response);
929 wp_die();
930 }
931 public function openai_settings_option_callback() {
932
933 $nonce = sanitize_text_field($_POST['nonce']);
934 if (! wp_verify_nonce($nonce,'wp_chatbot')) {
935 wp_send_json(array('success' => false, 'msg' => esc_html__('Failed in Security check', 'sm')));
936 wp_die();
937
938 }else{
939
940 $api_key = sanitize_text_field($_POST['api_key']);
941 $openai_engines = sanitize_text_field($_POST['openai_engines']);
942 $qcld_openai_prompt = sanitize_text_field($_POST['qcld_openai_prompt']);
943 $max_tokens = sanitize_text_field($_POST['max_tokens']);
944 $qcld_openai_suffix = sanitize_text_field($_POST['qcld_openai_suffix']);
945 $qcld_openai_custom_model = sanitize_text_field($_POST['qcld_openai_custom_model']);
946 $frequency_penalty = sanitize_text_field($_POST['frequency_penalty']);
947 $presence_penalty = sanitize_text_field($_POST['presence_penalty']);
948 $temperature = sanitize_text_field($_POST['temperature']);
949 $ai_enabled = sanitize_text_field($_POST['ai_enabled']);
950 $is_relevant_enabled = sanitize_text_field($_POST['is_relevant_enabled']);
951 $ai_only_mode = sanitize_text_field($_POST['ai_only_mode']);
952 $file_id = sanitize_text_field($_POST['file_id']);
953 $qcld_openai_prompt_custom = sanitize_text_field($_POST['qcld_openai_prompt_custom']);
954 $conversation_continuity = sanitize_text_field($_POST['conversation_continuity']);
955 if($api_key != ''){
956 update_option( 'open_ai_api_key', $api_key );
957 }
958 if($openai_engines != ''){
959 update_option( 'openai_engines', $openai_engines );
960 }
961 if($conversation_continuity != ''){
962 update_option( 'conversation_continuity', $conversation_continuity );
963 }
964 update_option( 'openai_max_tokens', $max_tokens );
965
966 if($qcld_openai_suffix != ''){
967 update_option('qcld_openai_suffix', $qcld_openai_suffix);
968 }
969 if($frequency_penalty != ''){
970 update_option( 'frequency_penalty', $frequency_penalty );
971 }
972 if($presence_penalty != ''){
973 update_option( 'presence_penalty', $presence_penalty );
974 }
975 if($temperature != ''){
976 update_option( 'openai_temperature', $temperature );
977 }
978 if($qcld_openai_prompt_custom != ''){
979 update_option('qcld_openai_prompt_custom', $qcld_openai_prompt_custom );
980 }
981 update_option('qcld_openai_custom_model',$qcld_openai_custom_model);
982
983 update_option('ai_enabled',$ai_enabled);
984 update_option('qcld_openai_relevant_enabled',$is_relevant_enabled);
985
986 if($file_id != ''){
987 update_option('file_id',$file_id);
988 }
989 $openai_include_keyword = sanitize_text_field($_POST['openai_include_keyword']);
990 update_option('openai_include_keyword',$openai_include_keyword);
991 $openai_exclude_keyword = sanitize_text_field($_POST['openai_exclude_keyword']);
992 update_option('openai_exclude_keyword',$openai_exclude_keyword);
993
994 }
995 if(($ai_only_mode != '') && ($ai_only_mode == 0)){
996 update_option('ai_only_mode', $ai_only_mode);
997 update_option('enable_wp_chatbot_disable_allicon', 0);
998 update_option('qcld_disable_start_menu', 0);
999 update_option('show_menu_after_greetings', 0);
1000 update_option('skip_wp_greetings', 0);
1001 update_option('disable_wp_chatbot_site_search',0);
1002 update_option('disable_wp_chatbot_call_gen',0);
1003 update_option('disable_wp_chatbot_feedback',0);
1004 update_option('disable_wp_chatbot_faq',0);
1005 update_option('disable_email_subscription',0);
1006 update_option('disable_str_categories',0);
1007 update_option('disable_good_bye',0);
1008
1009 }else if(($ai_only_mode != '') && ($ai_only_mode == 1)){
1010 update_option('ai_only_mode', $ai_only_mode);
1011 update_option('enable_wp_chatbot_disable_allicon', 1);
1012 update_option('qcld_disable_start_menu', 1);
1013 update_option('show_menu_after_greetings', 1);
1014 update_option('skip_wp_greetings', 1);
1015 update_option('disable_wp_chatbot_site_search',1);
1016 update_option('disable_wp_chatbot_call_gen',1);
1017 update_option('disable_wp_chatbot_feedback',1);
1018 update_option('disable_wp_chatbot_faq',1);
1019 update_option('disable_email_subscription',1);
1020 update_option('disable_str_categories',1);
1021 update_option('disable_good_bye',1);
1022 }
1023
1024 if($qcld_openai_prompt != ''){
1025 update_option('qcld_openai_prompt', $qcld_openai_prompt);
1026 }
1027 $tem = get_option( 'openai_temperature', $temperature );
1028
1029 echo json_encode($ai_enabled);wp_die();
1030
1031 }
1032 public function openai_keyword_suggestion_content(){
1033
1034 $OPENAI_API_KEY = get_option('open_ai_api_key');
1035 $ai_engines = get_option('openai_engines');
1036 $max_token = get_option('openai_max_tokens');
1037 // var_dump($max_token);wp_die();
1038 $temperature = get_option('openai_temperature');
1039 $ppenalty = get_option('presence_penalty');
1040 $fpenalty = get_option('frequency_penalty');
1041
1042 $qcld_article_text = isset($_POST['keyword']) ? sanitize_text_field( $_POST['keyword'] ) : '';
1043 $keyword_number = isset( $_POST['keyword_number'] ) ? sanitize_text_field( $_POST['keyword_number'] ) : '';
1044 $qcld_article_language = isset($_POST['qcld_article_language']) ? sanitize_text_field( $_POST['qcld_article_language'] ) : '';
1045 $qcld_article_number_of_heading = isset($_POST['qcld_article_number_of_heading']) ? sanitize_text_field( $_POST['qcld_article_number_of_heading'] ) : '';
1046 $qcld_article_heading_tag = isset($_POST['qcld_article_heading_tag']) ? sanitize_text_field( $_POST['qcld_article_heading_tag'] ) : '';
1047 $qcld_article_heading_style = isset($_POST['qcld_article_heading_style']) ? sanitize_text_field( $_POST['qcld_article_heading_style'] ) : '';
1048 $qcld_article_heading_tone = isset($_POST['qcld_article_heading_tone']) ? sanitize_text_field( $_POST['qcld_article_heading_tone'] ) : '';
1049 $qcld_article_heading_img = isset($_POST['qcld_article_heading_img']) ? sanitize_text_field( $_POST['qcld_article_heading_img'] ) : '';
1050 $qcld_article_heading_tagline = isset($_POST['qcld_article_heading_tagline']) ? sanitize_text_field( $_POST['qcld_article_heading_tagline'] ) : '';
1051 $qcld_article_heading_intro = isset($_POST['qcld_article_heading_intro']) ? sanitize_text_field( $_POST['qcld_article_heading_intro'] ) : '';
1052 $qcld_article_heading_conclusion = isset($_POST['qcld_article_heading_conclusion']) ? sanitize_text_field( $_POST['qcld_article_heading_conclusion'] ) : '';
1053 $qcld_article_label_anchor_text = isset($_POST['qcld_article_label_anchor_text']) ? sanitize_text_field( $_POST['qcld_article_label_anchor_text'] ) : '';
1054 $qcld_article_target_url = isset($_POST['qcld_article_target_url']) ? sanitize_text_field( $_POST['qcld_article_target_url'] ) : '';
1055 $qcld_article_target_label_cta = isset($_POST['qcld_article_target_label_cta']) ? sanitize_text_field( $_POST['qcld_article_target_label_cta'] ) : '';
1056 $qcld_article_cta_pos = isset($_POST['qcld_article_cta_pos']) ? sanitize_text_field( $_POST['qcld_article_cta_pos'] ) : '';
1057 $qcld_article_label_keywords = isset($_POST['qcld_article_label_keywords']) ? sanitize_text_field( $_POST['qcld_article_label_keywords'] ) : '';
1058 $qcld_article_label_word_to_avoid = isset($_POST['qcld_article_label_word_to_avoid']) ? sanitize_text_field( $_POST['qcld_article_label_word_to_avoid'] ) : '';
1059 $qcld_article_label_keywords_bold = isset($_POST['qcld_article_label_keywords_bold']) ? intval( $_POST['qcld_article_label_keywords_bold'] ) : '';
1060 $qcld_article_heading_faq = isset($_POST['qcld_article_heading_faq']) ? intval( $_POST['qcld_article_heading_faq'] ) : '';
1061
1062 $img_size = isset($_POST['qcld_article_img_size']) ? sanitize_text_field( $_POST['qcld_article_img_size'] ) : '';
1063 //$img_size = "512x512";
1064
1065 if ( empty($qcld_article_language) ) {
1066 $qcld_article_language = "en";
1067 }
1068 // if number of heading is not set, set it to 5
1069 if ( empty($qcld_article_number_of_heading) ) {
1070 $qcld_article_number_of_heading = 5;
1071 }
1072 // if writing style is not set, set it to descriptive
1073 if ( empty($qcld_article_heading_style) ) {
1074 $qcld_article_heading_style = "infor";
1075 }
1076 // if writing tone is not set, set it to assertive
1077 if ( empty($qcld_article_heading_tone) ) {
1078 $qcld_article_heading_tone = "formal";
1079 }
1080 // if heading tag is not set, set it to h2
1081 if ( empty($qcld_article_heading_tag) ) {
1082 $qcld_article_heading_tag = "h2";
1083 }
1084
1085 $writing_style = apply_filters('qcld_seo_openai_filter_for_style', $qcld_article_heading_style, $qcld_article_language );
1086 $tone_text = apply_filters('qcld_seo_openai_filter_for_tone', $qcld_article_heading_tone, $qcld_article_language );
1087
1088 if ( $qcld_article_language == "en" ) {
1089
1090
1091 if ( $qcld_article_number_of_heading == 1 ) {
1092 $prompt_text = " blog topic about ";
1093 } else {
1094 $prompt_text = " blog topics about ";
1095 }
1096
1097 $intro_text = "Write an introduction about ";
1098 $conclusion_text = "Write a conclusion about ";
1099 $tagline_text = "Write a tagline about ";
1100 $introduction = "Introduction";
1101 $conclusion = "Conclusion";
1102 $faq_text = strval( $qcld_article_number_of_heading ) . " questions and answers about " . $qcld_article_text . ".";
1103 $faq_heading = "Q&A";
1104 $style_text = "Writing style: " . $writing_style . ".";
1105
1106 if ( empty($qcld_article_label_keywords) ) {
1107 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1108 } else {
1109 $keyword_text = ". Keywords: " . $qcld_article_label_keywords . ".";
1110 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text;
1111 }
1112
1113 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1114
1115 if ( !empty($qcld_article_label_word_to_avoid) ) {
1116 $avoid_text = " Exclude following keywords: " . $qcld_article_label_word_to_avoid . ".";
1117 $myprompt = $myprompt . $avoid_text;
1118 }
1119
1120 $myintro = $intro_text . $qcld_article_text;
1121 $myconclusion = $conclusion_text . $qcld_article_text;
1122 $mytagline = $tagline_text . $qcld_article_text;
1123 $mycta = "Write a Call to action about: " . $qcld_article_text . " and create a href tag link to: " . $qcld_article_target_label_cta . ".";
1124
1125 } else if ( $qcld_article_language == "de" ) {
1126 $prompt_text = " blog-Themen über ";
1127 $intro_text = "Schreiben Sie eine Einführung über ";
1128 $conclusion_text = "Schreiben Sie ein Fazit über ";
1129 $tagline_text = "Schreiben Sie eine Tagline über ";
1130 $introduction = "Einführung";
1131 $conclusion = "Fazit";
1132 $faq_text = strval( $qcld_article_number_of_heading ) . " Fragen und Antworten über " . $qcld_article_text . ".";
1133 $faq_heading = "Fragen und Antworten";
1134 $style_text = "Schreibstil: " . $writing_style . ".";
1135
1136 if ( empty($qcld_article_label_keywords) ) {
1137 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1138 } else {
1139 $keyword_text = ". Schlüsselwörter: " . $qcld_article_label_keywords . ".";
1140 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text;
1141 }
1142
1143 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1144
1145 if ( !empty($qcld_article_label_word_to_avoid) ) {
1146 $avoid_text = " Ausschließen folgende Schlüsselwörter: " . $qcld_article_label_word_to_avoid . ".";
1147 $myprompt = $myprompt . $avoid_text;
1148 }
1149
1150 $myintro = $intro_text . $qcld_article_text;
1151 $myconclusion = $conclusion_text . $qcld_article_text;
1152 $mytagline = $tagline_text . $qcld_article_text;
1153 $mycta = "Schreiben Sie eine Call to action über: " . $qcld_article_text . " und erstellen Sie einen href-Tag-Link zu: " . $qcld_article_target_label_cta . ".";
1154 } else if ( $qcld_article_language == "fr" ) {
1155 $prompt_text = " sujets de blog sur ";
1156 $intro_text = "Écrivez une introduction sur ";
1157 $conclusion_text = "Écrivez une conclusion sur ";
1158 $tagline_text = "Rédigez un slogan sur ";
1159 $introduction = "Introduction";
1160 $conclusion = "Conclusion";
1161 $faq_text = strval( $qcld_article_number_of_heading ) . " questions et réponses sur " . $qcld_article_text . ".";
1162 $faq_heading = "Questions et réponses";
1163 $style_text = "Style d'écriture: " . $writing_style . ".";
1164
1165 if ( empty($qcld_article_label_keywords) ) {
1166 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1167 } else {
1168 $keyword_text = ". Mots clés: " . $qcld_article_label_keywords . ".";
1169 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text;
1170 }
1171
1172 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1173
1174 if ( !empty($qcld_article_label_word_to_avoid) ) {
1175 $avoid_text = " Exclure les mots-clés suivants: " . $qcld_article_label_word_to_avoid . ".";
1176 $myprompt = $myprompt . $avoid_text;
1177 }
1178
1179 $myintro = $intro_text . $qcld_article_text;
1180 $myconclusion = $conclusion_text . $qcld_article_text;
1181 $mytagline = $tagline_text . $qcld_article_text;
1182 $mycta = "Écrivez un appel à l'action sur: " . $qcld_article_text . " et créez un lien href tag vers: " . $qcld_article_target_label_cta . ".";
1183
1184 } else if ( $qcld_article_language == "es" ) {
1185 $prompt_text = " temas de blog sobre ";
1186 $intro_text = "Escribe una introducción sobre ";
1187 $conclusion_text = "Escribe una conclusión sobre ";
1188 $tagline_text = "Escribe una eslogan sobre ";
1189 $introduction = "Introducción";
1190 $conclusion = "Conclusión";
1191 $faq_text = strval( $qcld_article_number_of_heading ) . " preguntas y respuestas sobre " . $qcld_article_text . ".";
1192 $faq_heading = "Preguntas y respuestas";
1193 $style_text = "Estilo de escritura: " . $writing_style . ".";
1194
1195 if ( empty($qcld_article_label_keywords) ) {
1196 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1197 } else {
1198 $keyword_text = ". Palabras clave: " . $qcld_article_label_keywords . ".";
1199 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text;
1200 }
1201
1202 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1203
1204 if ( !empty($qcld_article_label_word_to_avoid) ) {
1205 $avoid_text = " Excluir las siguientes palabras clave: " . $qcld_article_label_word_to_avoid . ".";
1206 $myprompt = $myprompt . $avoid_text;
1207 }
1208
1209 $myintro = $intro_text . $qcld_article_text;
1210 $myconclusion = $conclusion_text . $qcld_article_text;
1211 $mytagline = $tagline_text . $qcld_article_text;
1212 $mycta = "Escribe una llamada a la acción sobre: " . $qcld_article_text . " y cree un enlace de etiqueta html <a href> para: " . $qcld_article_target_label_cta . ".";
1213
1214 } else if ( $qcld_article_language == "it" ) {
1215 $prompt_text = " argomenti di blog su ";
1216 $intro_text = "Scrivi un'introduzione su ";
1217 $conclusion_text = "Scrivi una conclusione su ";
1218 $tagline_text = "Scrivi un slogan su ";
1219 $introduction = "Introduzione";
1220 $conclusion = "Conclusione";
1221 $faq_text = strval( $qcld_article_number_of_heading ) . " domande e risposte su " . $qcld_article_text . ".";
1222 $faq_heading = "Domande e risposte";
1223 $style_text = "Stile di scrittura: " . $writing_style . ".";
1224
1225 if ( empty($qcld_article_label_keywords) ) {
1226 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1227 } else {
1228 $keyword_text = ". Parole chiave: " . $qcld_article_label_keywords . ".";
1229 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text;
1230 }
1231
1232 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1233
1234 if ( !empty($qcld_article_label_word_to_avoid) ) {
1235 $avoid_text = " Escludere le seguenti parole chiave: " . $qcld_article_label_word_to_avoid . ".";
1236 $myprompt = $myprompt . $avoid_text;
1237 }
1238
1239 $myintro = $intro_text . $qcld_article_text;
1240 $myconclusion = $conclusion_text . $qcld_article_text;
1241 $mytagline = $tagline_text . $qcld_article_text;
1242 $mycta = "Scrivi un call to action su: " . $qcld_article_text . " e crea un href tag link a: " . $qcld_article_target_label_cta . ".";
1243
1244 } else if ( $qcld_article_language == "pt" ) {
1245 $prompt_text = " tópicos de blog sobre ";
1246 $intro_text = "Escreva uma introdução sobre ";
1247 $conclusion_text = "Escreva uma conclusão sobre ";
1248 $tagline_text = "Escreva um slogan sobre ";
1249 $introduction = "Introdução";
1250 $conclusion = "Conclusão";
1251 $faq_text = strval( $qcld_article_number_of_heading ) . " perguntas e respostas sobre " . $qcld_article_text . ".";
1252 $faq_heading = "Perguntas e respostas";
1253 $style_text = "Estilo de escrita: " . $writing_style . ".";
1254
1255 if ( empty($qcld_article_label_keywords) ) {
1256 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1257 } else {
1258 $keyword_text = ". Palavras-chave: " . $qcld_article_label_keywords . ".";
1259 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text;
1260 }
1261
1262 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1263
1264 if ( !empty($qcld_article_label_word_to_avoid) ) {
1265 $avoid_text = " Excluir as seguintes palavras-chave: " . $qcld_article_label_word_to_avoid . ".";
1266 $myprompt = $myprompt . $avoid_text;
1267 }
1268
1269 $myintro = $intro_text . $qcld_article_text;
1270 $myconclusion = $conclusion_text . $qcld_article_text;
1271 $mytagline = $tagline_text . $qcld_article_text;
1272 $mycta = "Escreva um call to action sobre: " . $qcld_article_text . " e crie um href tag link para: " . $qcld_article_target_label_cta . ".";
1273
1274 } else if ( $qcld_article_language == "nl" ) {
1275 $prompt_text = " blogonderwerpen over ";
1276 $intro_text = "Schrijf een inleiding over ";
1277 $conclusion_text = "Schrijf een conclusie over ";
1278 $tagline_text = "Schrijf een slogan over ";
1279 $introduction = "Inleiding";
1280 $conclusion = "Conclusie";
1281 $faq_text = strval( $qcld_article_number_of_heading ) . " vragen en antwoorden over " . $qcld_article_text . ".";
1282 $faq_heading = "Vragen en antwoorden";
1283 $style_text = "Schrijfstijl: " . $writing_style . ".";
1284
1285 if ( empty($qcld_article_label_keywords) ) {
1286 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1287 } else {
1288 $keyword_text = ". Trefwoorden: " . $qcld_article_label_keywords . ".";
1289 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text;
1290 }
1291
1292 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1293
1294 if ( !empty($qcld_article_label_word_to_avoid) ) {
1295 $avoid_text = " Sluit de volgende trefwoorden uit: " . $qcld_article_label_word_to_avoid . ".";
1296 $myprompt = $myprompt . $avoid_text;
1297 }
1298
1299 $myintro = $intro_text . $qcld_article_text;
1300 $myconclusion = $conclusion_text . $qcld_article_text;
1301 $mytagline = $tagline_text . $qcld_article_text;
1302 $mycta = "Schrijf een call to action over: " . $qcld_article_text . " en maak een href tag link naar: " . $qcld_article_target_label_cta . ".";
1303
1304 } else if ( $qcld_article_language == "ru" ) {
1305 $prompt_text = "Перечислите ";
1306 $prompt_last = " идей блога о ";
1307 $intro_text = "Напишите введение о ";
1308 $conclusion_text = "Напишите заключение о ";
1309 $tagline_text = "Напишите слоган о ";
1310 $introduction = "Введение";
1311 $conclusion = "Заключение";
1312 $faq_text = strval( $qcld_article_number_of_heading ) . " вопросов и ответов о " . $qcld_article_text . ".";
1313 $faq_heading = "Вопросы и ответы";
1314 $style_text = "Стиль написания: " . $writing_style . ".";
1315
1316 if ( empty($qcld_article_label_keywords) ) {
1317 $myprompt = $prompt_text . strval( $qcld_article_number_of_heading ) . $prompt_last . $qcld_article_text . ".";
1318 } else {
1319 $keyword_text = ". Ключевые слова: " . $qcld_article_label_keywords . ".";
1320 $myprompt = $prompt_text . strval( $qcld_article_number_of_heading ) . $prompt_last . $qcld_article_text . $keyword_text;
1321 }
1322
1323 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1324
1325 if ( !empty($qcld_article_label_word_to_avoid) ) {
1326 $avoid_text = " Исключите следующие ключевые слова: " . $qcld_article_label_word_to_avoid . ".";
1327 $myprompt = $myprompt . $avoid_text;
1328 }
1329
1330 $myintro = $intro_text . $qcld_article_text;
1331 $myconclusion = $conclusion_text . $qcld_article_text;
1332 $mytagline = $tagline_text . $qcld_article_text;
1333 $mycta = "Напишите call to action о: " . $qcld_article_text . " и сделайте href tag link на: " . $qcld_article_target_label_cta . ".";
1334
1335 } else if ( $qcld_article_language == "ja" ) {
1336 $prompt_text = " に関するブログのアイデアを ";
1337 $prompt_last = " つ挙げてください";
1338 $intro_text = " について紹介文を書く";
1339 $conclusion_text = " についての結論を書く";
1340 $tagline_text = " についてのスローガンを書く";
1341 $introduction = "序章";
1342 $conclusion = "結論";
1343 $faq_text = $qcld_article_text . " に関する " . strval( $qcld_article_number_of_heading ) . " の質問と回答.";
1344 $faq_heading = "よくある質問";
1345 $style_text = "書き方: " . $writing_style . ".";
1346
1347 if ( empty($qcld_article_label_keywords) ) {
1348 $myprompt = $qcld_article_text . $prompt_text . strval( $qcld_article_number_of_heading ) . $prompt_last . ".";
1349 } else {
1350 $keyword_text = ". キーワード: " . $qcld_article_label_keywords . ".";
1351 $myprompt = $qcld_article_text . $prompt_text . strval( $qcld_article_number_of_heading ) . $prompt_last . $keyword_text;
1352 }
1353
1354 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1355
1356 if ( !empty($qcld_article_label_word_to_avoid) ) {
1357 $avoid_text = " 次のキーワードを除外します。 " . $qcld_article_label_word_to_avoid . ".";
1358 $myprompt = $myprompt . $avoid_text;
1359 }
1360
1361 $myintro = $qcld_article_text . $intro_text;
1362 $myconclusion = $qcld_article_text . $conclusion_text;
1363 $mytagline = $qcld_article_text . $tagline_text;
1364 // Write a call to action about $qcld_article_text and create a href tag link to: $qcld_article_target_label_cta.
1365 $mycta = $qcld_article_text . " についてのコール・トゥ・アクションを書き、hrefタグリンクを作成します。 " . $qcld_article_target_label_cta . ".";
1366
1367 } else if ( $qcld_article_language == "zh" ) {
1368 $prompt_text = " �
1369 �于 ";
1370 $of_text = "";
1371 $piece_text = " 个博客创意";
1372 $intro_text = "写一篇�
1373 �于 ";
1374 $intro_last = " 的介绍";
1375 $conclusion_text = "写一篇�
1376 �于 ";
1377 // write a tagline about
1378 $tagline_text = "写一个标语�
1379 �于 ";
1380 $conclusion_last = " 的结论";
1381 $introduction = "介绍";
1382 $conclusion = "结论";
1383 $faq_text = $qcld_article_text . "" . strval( $qcld_article_number_of_heading ) . " 个问题和答案.";
1384 $faq_heading = "常见问题";
1385 $style_text = "写作风格: " . $writing_style . ".";
1386
1387 if ( empty($qcld_article_label_keywords) ) {
1388 $myprompt = $prompt_text . $qcld_article_text . $of_text . strval( $qcld_article_number_of_heading ) . $piece_text . ".";
1389 } else {
1390 $keyword_text = ". �
1391 �键字: " . $qcld_article_label_keywords . ".";
1392 $myprompt = $prompt_text . $qcld_article_text . $of_text . strval( $qcld_article_number_of_heading ) . $piece_text . $keyword_text;
1393 }
1394
1395 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1396
1397 if ( !empty($qcld_article_label_word_to_avoid) ) {
1398 $avoid_text = " 排除以下�
1399 �键字:" . $qcld_article_label_word_to_avoid . ".";
1400 $myprompt = $myprompt . $avoid_text;
1401 }
1402
1403 $myintro = $intro_text . $qcld_article_text . $intro_last;
1404 $myconclusion = $conclusion_text . $qcld_article_text . $conclusion_last;
1405 $mytagline = $tagline_text . $qcld_article_text;
1406 // 写一个�
1407 �于 123 的号召性用语并创建一个 <a href> html 标签链接到:
1408 $mycta = "写一个�
1409 �于 " . $qcld_article_text . " 的号召性用语并创建一个 <a href> html 标签链接到: " . $qcld_article_target_label_cta . ".";
1410
1411 } else if ( $qcld_article_language == "ko" ) {
1412 $prompt_text = " 다음과 관련된 ";
1413 $prompt_last = "가지 블로그 아이디어: ";
1414 $intro_text = "블로그 토픽에 대한 소개를 작성하십시오 ";
1415 $conclusion_text = "블로그 토픽에 대한 결론을 작성하십시오 ";
1416 $introduction = "소개";
1417 $conclusion = "결론";
1418 $faq_text = $qcld_article_text . "에 대한 " . strval( $qcld_article_number_of_heading ) . "개의 질문과 답변.";
1419 $faq_heading = "자주 묻는 질문";
1420 // write a tagline about
1421 $tagline_text = "에 대한 태그라인 작성 ";
1422 $style_text = "작성 스타일: " . $writing_style . ".";
1423
1424 if ( empty($qcld_article_label_keywords) ) {
1425 $myprompt = $prompt_text . strval( $qcld_article_number_of_heading ) . $prompt_last . $qcld_article_text . ".";
1426 } else {
1427 $keyword_text = ". 키워드: " . $qcld_article_label_keywords . ".";
1428 $myprompt = $prompt_text . strval( $qcld_article_number_of_heading ) . $prompt_last . $qcld_article_text . $keyword_text;
1429 }
1430
1431 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1432
1433 if ( !empty($qcld_article_label_word_to_avoid) ) {
1434 $avoid_text = " 다음 키워드를 제외하십시오. " . $qcld_article_label_word_to_avoid . ".";
1435 $myprompt = $myprompt . $avoid_text;
1436 }
1437
1438 $myintro = $intro_text . $qcld_article_text;
1439 $myconclusion = $conclusion_text . $qcld_article_text;
1440 $mytagline = $qcld_article_text . $tagline_text;
1441 // Write a call to action about $qcld_article_text and create a href tag link to: $qcld_article_target_label_cta.
1442 $mycta = $qcld_article_text . "에 대한 호출 행동을 작성하고 href 태그 링크를 만듭니다. " . $qcld_article_target_label_cta . ".";
1443
1444 } else if ( $qcld_article_language == "id" ) {
1445 $prompt_text = " topik blog tentang ";
1446 $intro_text = "Tulis pengantar tentang ";
1447 $conclusion_text = "Tulis kesimpulan tentang ";
1448 $introduction = "Pengantar";
1449 $conclusion = "Kesimpulan";
1450 $faq_text = strval( $qcld_article_number_of_heading ) . " pertanyaan dan jawaban tentang " . $qcld_article_text . ".";
1451 $faq_heading = "Pertanyaan dan jawaban";
1452 // write a tagline about
1453 $tagline_text = "Tulis tagline tentang ";
1454 $style_text = "Gaya penulisan: " . $writing_style . ".";
1455
1456 if ( empty($qcld_article_label_keywords) ) {
1457 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1458 } else {
1459 $keyword_text = ". Kata kunci: " . $qcld_article_label_keywords . ".";
1460 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text;
1461 }
1462
1463 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1464
1465 if ( !empty($qcld_article_label_word_to_avoid) ) {
1466 $avoid_text = " Hindari kata kunci berikut: " . $qcld_article_label_word_to_avoid . ".";
1467 $myprompt = $myprompt . $avoid_text;
1468 }
1469
1470 $myintro = $intro_text . $qcld_article_text;
1471 $myconclusion = $conclusion_text . $qcld_article_text;
1472 $mytagline = $tagline_text . $qcld_article_text;
1473 // Write a call to action about $qcld_article_text and create a href tag link to: $qcld_article_target_label_cta.
1474 $mycta = "Tulis panggilan tindakan tentang " . $qcld_article_text . " dan buat tautan tag href ke: " . $qcld_article_target_label_cta . ".";
1475
1476 } else if ( $qcld_article_language == "tr" ) {
1477 $prompt_text = " hakkında ";
1478 $prompt_last = " blog başlığı listele.";
1479 $intro_text = " ile ilgili bir giriş yazısı yaz.";
1480 $conclusion_text = " ile ilgili bir sonuç yazısı yaz.";
1481 $introduction = "Giriş";
1482 $conclusion = "Sonuç";
1483 $faq_text = $qcld_article_text . " hakkında " . strval( $qcld_article_number_of_heading ) . " soru ve cevap.";
1484 $faq_heading = "SSS";
1485 // write a tagline about
1486 $tagline_text = " ile ilgili bir slogan yaz.";
1487 $style_text = "Yazı stili: " . $writing_style . ".";
1488
1489 if ( empty($qcld_article_label_keywords) ) {
1490 $myprompt = $qcld_article_text . $prompt_text . strval( $qcld_article_number_of_heading ) . $prompt_last . ".";
1491 } else {
1492 $keyword_text = ". Anahtar kelimeler: " . $qcld_article_label_keywords . ".";
1493 $myprompt = $qcld_article_text . $prompt_text . strval( $qcld_article_number_of_heading ) . $prompt_last . $keyword_text;
1494 }
1495
1496 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1497
1498 if ( !empty($qcld_article_label_word_to_avoid) ) {
1499 $avoid_text = " Bu anahtar kelimeleri kullanma: " . $qcld_article_label_word_to_avoid . ".";
1500 $myprompt = $myprompt . $avoid_text;
1501 }
1502
1503 $myintro = $qcld_article_text . $intro_text;
1504 $myconclusion = $qcld_article_text . $conclusion_text;
1505 $mytagline = $qcld_article_text . $tagline_text;
1506 // Write a call to action about $qcld_article_text and create a href tag link to: $qcld_article_target_label_cta.
1507 $mycta = $qcld_article_text . " hakkında bir çağrıyı harekete geçir ve bir href etiketi bağlantısı oluştur: " . $qcld_article_target_label_cta . ".";
1508
1509 } else if ( $qcld_article_language == "hi" ) {
1510 $prompt_text = " के बारे में ";
1511 $prompt_last = " ब्लॉग विषय सूचीबद्ध करें.";
1512 $intro_text = "का परिचय लिखिए ";
1513 $conclusion_text = "के बारे में निष्कर्ष लिखिए ";
1514 $introduction = "प्रस्तावना";
1515 $conclusion = "निष्कर्ष";
1516 $faq_text = $qcld_article_text . " के बारे में " . strval( $qcld_article_number_of_heading ) . " प्रश्न और उत्तर.";
1517 $faq_heading = "सामान्य प्रश्न";
1518 // write a tagline about
1519 $tagline_text = " के बारे में एक नारा लिखिए";
1520 $style_text = "लेखन शैली: " . $writing_style . ".";
1521
1522 if ( empty($qcld_article_label_keywords) ) {
1523 $myprompt = $qcld_article_text . $prompt_text . strval( $qcld_article_number_of_heading ) . $prompt_last . ".";
1524 } else {
1525 $keyword_text = ". कीवर्ड: " . $qcld_article_label_keywords . ".";
1526 $myprompt = $qcld_article_text . $prompt_text . strval( $qcld_article_number_of_heading ) . $prompt_last . $keyword_text;
1527 }
1528
1529 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1530
1531 if ( !empty($qcld_article_label_word_to_avoid) ) {
1532 $avoid_text = " निम्नलिखित खोजशब्दों को बाहर करें: " . $qcld_article_label_word_to_avoid . ".";
1533 $myprompt = $myprompt . $avoid_text;
1534 }
1535
1536 $myintro = $intro_text . $qcld_article_text;
1537 $myconclusion = $conclusion_text . $qcld_article_text;
1538 $mytagline = $qcld_article_text . $tagline_text;
1539 // Write a call to action about $qcld_article_text and create a href tag link to: $qcld_article_target_label_cta.
1540 $mycta = $qcld_article_text . " के बारे में कोई कॉल एक्शन लिखें और एक href टैग लिंक बनाएं: " . $qcld_article_target_label_cta . ".";
1541
1542 } else if ( $qcld_article_language == "pl" ) {
1543 $prompt_text = " tematów blogów o ";
1544 $intro_text = "Napisz wprowadzenie o ";
1545 $conclusion_text = "Napisz konkluzja o ";
1546 $introduction = "Wstęp";
1547 $conclusion = "Konkluzja";
1548 $faq_text = "Napisz " . strval( $qcld_article_number_of_heading ) . " pytania i odpowiedzi o " . $qcld_article_text . ".";
1549 $faq_heading = "Pytania i odpowiedzi";
1550 // write a tagline about
1551 $tagline_text = "Napisz slogan o ";
1552 $style_text = "Styl pisania: " . $writing_style . ".";
1553
1554 if ( empty($qcld_article_label_keywords) ) {
1555 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1556 } else {
1557 $keyword_text = ". Słowa kluczowe:: " . $qcld_article_label_keywords . ".";
1558 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text . ".";
1559 }
1560
1561 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1562
1563 if ( !empty($qcld_article_label_word_to_avoid) ) {
1564 $avoid_text = " Wyklucz następuj�
1565 ce słowa kluczowe: " . $qcld_article_label_word_to_avoid . ".";
1566 $myprompt = $myprompt . $avoid_text;
1567 }
1568
1569 $myintro = $intro_text . $qcld_article_text;
1570 $myconclusion = $conclusion_text . $qcld_article_text;
1571 $mytagline = $tagline_text . $qcld_article_text;
1572 $mycta = "Napisz wezwanie do działania dotycz�
1573 ce " . $qcld_article_text . " i utwórz link tagu HTML <a href> do: " . $qcld_article_target_label_cta . ".";
1574
1575 } else if ( $qcld_article_language == "uk" ) {
1576 $prompt_text = " теми блогів про ";
1577 $intro_text = "Напишіть вступ про ";
1578 $conclusion_text = "Напишіть висновок про ";
1579 $introduction = "Вступ";
1580 $conclusion = "Висновок";
1581 $faq_text = "Напишіть " . strval( $qcld_article_number_of_heading ) . " питання та відповіді про " . $qcld_article_text . ".";
1582 $faq_heading = "Питання та відповіді";
1583 // write a tagline about
1584 $tagline_text = "Напишіть слоган про ";
1585 $style_text = "Стиль письма: " . $writing_style . ".";
1586
1587 if ( empty($qcld_article_label_keywords) ) {
1588 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1589 } else {
1590 $keyword_text = ". Ключові слова: " . $qcld_article_label_keywords . ".";
1591 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text;
1592 }
1593 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1594
1595 if ( !empty($qcld_article_label_word_to_avoid) ) {
1596 $avoid_text = " Виключіть такі ключові слова: " . $qcld_article_label_word_to_avoid . ".";
1597 $myprompt = $myprompt . $avoid_text;
1598 }
1599 $myintro = $intro_text . $qcld_article_text;
1600 $myconclusion = $conclusion_text . $qcld_article_text;
1601 $mytagline = $tagline_text . $qcld_article_text;
1602 // Напишіть заклик до дії про Google і створіть посилання на тег html <a href> для:
1603 $mycta = "Напишіть заклик до дії про " . $qcld_article_text . " і створіть посилання на тег html <a href> для: " . $qcld_article_target_label_cta . ".";
1604
1605 } else if ( $qcld_article_language == "ar" ) {
1606 $prompt_text = " �
1607 وضوعات ال�
1608 دونات على ";
1609 $intro_text = "اكتب �
1610 قد�
1611 ة عن: ";
1612 $conclusion_text = "اكتب استنتاجًا عن: ";
1613 $introduction = "�
1614 قد�
1615 ة";
1616 $conclusion = "استنتاج";
1617 $faq_text = "اكتب " . strval( $qcld_article_number_of_heading ) . " أسئلة وأجوبة عن " . $qcld_article_text . ".";
1618 $faq_heading = "الأسئلة الشائعة";
1619 // write a tagline about اكتب شعارًا عن
1620 $tagline_text = " اكتب شعارًا عن ";
1621 $style_text = "ن�
1622 ط الكتابة: " . $writing_style . ".";
1623
1624 if ( empty($qcld_article_label_keywords) ) {
1625 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1626 } else {
1627 $keyword_text = ". الكل�
1628 ات الدالة: " . $qcld_article_label_keywords . ".";
1629 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text;
1630 }
1631
1632 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1633
1634 if ( !empty($qcld_article_label_word_to_avoid) ) {
1635 $avoid_text = " تجنب الكل�
1636 ات التالية: " . $qcld_article_label_word_to_avoid . ".";
1637 $myprompt = $myprompt . $avoid_text;
1638 }
1639
1640 $myintro = $intro_text . $qcld_article_text;
1641 $myconclusion = $conclusion_text . $qcld_article_text;
1642 $mytagline = $qcld_article_text . $tagline_text;
1643 $mycta = "اكتب عبارة تحث ال�
1644 ستخد�
1645 على اتخاذ إجراء بشأن " . $qcld_article_text . " وأنشئ <a href> رابط وس�
1646 html �
1647 ن أجل: " . $qcld_article_target_label_cta . ".";
1648
1649 } else if ( $qcld_article_language == "ro" ) {
1650 $prompt_text = " subiecte de blog despre ";
1651 $intro_text = "Scrieți o introducere despre ";
1652 $conclusion_text = "Scrieți o concluzie despre ";
1653 $introduction = "Introducere";
1654 $conclusion = "Concluzie";
1655 $faq_text = "Scrieți " . strval( $qcld_article_number_of_heading ) . " întrebări și răspunsuri despre " . $qcld_article_text . ".";
1656 $faq_heading = "Întrebări și răspunsuri";
1657 // write a tagline about
1658 $tagline_text = "Scrieți un slogan despre ";
1659 $style_text = "Stilul de scriere: " . $writing_style . ".";
1660
1661 if ( empty($qcld_article_label_keywords) ) {
1662 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1663 } else {
1664 $keyword_text = ". Cuvinte cheie: " . $qcld_article_label_keywords . ".";
1665 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text;
1666 }
1667
1668 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1669
1670 if ( !empty($qcld_article_label_word_to_avoid) ) {
1671 $avoid_text = " Evitați cuvintele: " . $qcld_article_label_word_to_avoid . ".";
1672 $myprompt = $myprompt . $avoid_text;
1673 }
1674
1675 $myintro = $intro_text . $qcld_article_text;
1676 $myconclusion = $conclusion_text . $qcld_article_text;
1677 $mytagline = $tagline_text . $qcld_article_text;
1678 // Scrieți un îndemn despre Google și creați o etichetă html <a href> link către:
1679 $mycta = "Scrieți un îndemn despre " . $qcld_article_text . " și creați o etichetă html <a href> link către: " . $qcld_article_target_label_cta . ".";
1680
1681 } else if ( $qcld_article_language == "hu" ) {
1682 // Írj 5 blogtémát a Google-ról
1683 $prompt_text = " blog témákat a következő témában: ";
1684 $intro_text = "Írj bevezetést ";
1685 $conclusion_text = "Írj következtetést ";
1686 $introduction = "Bevezetés";
1687 $conclusion = "Következtetés";
1688 $faq_text = "Írj " . strval( $qcld_article_number_of_heading ) . " kérdést és választ a következő témában: " . $qcld_article_text . ".";
1689 $faq_heading = "GYIK";
1690 // write a tagline about
1691 $tagline_text = "Írj egy tagline-t ";
1692 $style_text = "Írásmód: " . $writing_style . ".";
1693
1694 if ( empty($qcld_article_label_keywords) ) {
1695 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1696 } else {
1697 $keyword_text = ". Kulcsszavak: " . $qcld_article_label_keywords . ".";
1698 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text;
1699 }
1700
1701 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1702
1703 if ( !empty($qcld_article_label_word_to_avoid) ) {
1704 $avoid_text = " Kerülje a következő szavakat: " . $qcld_article_label_word_to_avoid . ".";
1705 $myprompt = $myprompt . $avoid_text;
1706 }
1707
1708 $myintro = $intro_text . $qcld_article_text;
1709 $myconclusion = $conclusion_text . $qcld_article_text;
1710 $mytagline = $tagline_text . $qcld_article_text;
1711 // Írjon cselekvésre ösztönzést a 123-ról, és hozzon létre egy <a href> html címke hivatkozást:
1712 $mycta = "Írjon cselekvésre ösztönzést a " . $qcld_article_text . "-rol, témában, és hozzon létre egy <a href> html címke hivatkozást: " . $qcld_article_target_label_cta . ".";
1713
1714 } else if ( $qcld_article_language == "cs" ) {
1715 $prompt_text = " blog témata o ";
1716 $intro_text = "Napi úvodní zprávy o ";
1717 $conclusion_text = "Napi závěrečná zpráva o ";
1718 $introduction = "Úvodní zpráva";
1719 $conclusion = "Závěrečná zpráva";
1720 $faq_text = "Napi " . strval( $qcld_article_number_of_heading ) . " otázky a odpovědi o " . $qcld_article_text . ".";
1721 $faq_heading = "Často kladené otázky";
1722 // write a tagline about
1723 $tagline_text = "Napi tagline o ";
1724 $style_text = "Styl psaní: " . $writing_style . ".";
1725 if ( empty($qcld_article_label_keywords) ) {
1726 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1727 } else {
1728 $keyword_text = ". Klíčová slova: " . $qcld_article_label_keywords . ".";
1729 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text;
1730 }
1731 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1732 if ( !empty($qcld_article_label_word_to_avoid) ) {
1733 $avoid_text = " Vyhněte se slovům: " . $qcld_article_label_word_to_avoid . ".";
1734 $myprompt = $myprompt . $avoid_text;
1735 }
1736 $myintro = $intro_text . $qcld_article_text;
1737 $myconclusion = $conclusion_text . $qcld_article_text;
1738 $mytagline = $tagline_text . $qcld_article_text;
1739 // Write a call to action about $qcld_article_text and create a href tag link to: $qcld_article_target_label_cta.
1740 $mycta = "Napi hovor k akci o " . $qcld_article_text . " a vytvořte href tag link na: " . $qcld_article_target_label_cta . ".";
1741
1742 } else if ( $qcld_article_language == "el" ) {
1743 $prompt_text = " θέματα ιστολογίο�
1744 για ";
1745 $intro_text = "Γράψτε μια εισαγωγή για ";
1746 $conclusion_text = "Γράψτε μια σ�
1747 μπέραση για ";
1748 $introduction = "Εισαγωγή";
1749 $conclusion = "Σ�
1750 μπέραση";
1751 $faq_text = "Γράψτε " . strval( $qcld_article_number_of_heading ) . " ερωτήσεις και απαντήσεις για " . $qcld_article_text . ".";
1752 $faq_heading = "Σ�
1753 χνές ερωτήσεις";
1754 // write a tagline about
1755 $tagline_text = "Γράψτε μια tagline για ";
1756 $style_text = "Στ�
1757 λ σ�
1758 γγραφής: " . $writing_style . ".";
1759
1760 if ( empty($qcld_article_label_keywords) ) {
1761 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1762 } else {
1763 $keyword_text = ". Λέξεις-κλειδιά: " . $qcld_article_label_keywords . ".";
1764 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text;
1765 }
1766
1767 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1768
1769 if ( !empty($qcld_article_label_word_to_avoid) ) {
1770 $avoid_text = " Αποφύγετε τις εξής λέξεις: " . $qcld_article_label_word_to_avoid . ".";
1771 $myprompt = $myprompt . $avoid_text;
1772 }
1773
1774 $myintro = $intro_text . $qcld_article_text;
1775 $myconclusion = $conclusion_text . $qcld_article_text;
1776 $mytagline = $tagline_text . $qcld_article_text;
1777 // Write a call to action about $qcld_article_text and create a href tag link to: $qcld_article_target_label_cta.
1778 $mycta = "Γράψτε μια κλήση σε ενέργεια για " . $qcld_article_text . " και δημιο�
1779 ργήστε έναν σύνδεσμο href tag στο: " . $qcld_article_target_label_cta . ".";
1780
1781 } else if ( $qcld_article_language == "bg" ) {
1782 $prompt_text = " блог теми за ";
1783 $intro_text = "Напишете въведение за ";
1784 $conclusion_text = "Напишете заключение за ";
1785 $introduction = "Въведение";
1786 $conclusion = "Заключение";
1787 $faq_text = "Напишете " . strval( $qcld_article_number_of_heading ) . " въпроси и отговори за " . $qcld_article_text . ".";
1788 $faq_heading = "Често задавани въпроси";
1789 // write a tagline about
1790 $tagline_text = "Напишете tagline за ";
1791 $style_text = "Стил на писане: " . $writing_style . ".";
1792
1793 if ( empty($qcld_article_label_keywords) ) {
1794 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1795 } else {
1796 $keyword_text = ". Ключови думи: " . $qcld_article_label_keywords . ".";
1797 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text;
1798 }
1799 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1800 if ( !empty($qcld_article_label_word_to_avoid) ) {
1801 $avoid_text = " Избягвайте думите: " . $qcld_article_label_word_to_avoid . ".";
1802 $myprompt = $myprompt . $avoid_text;
1803 }
1804
1805 $myintro = $intro_text . $qcld_article_text;
1806 $myconclusion = $conclusion_text . $qcld_article_text;
1807 $mytagline = $tagline_text . $qcld_article_text;
1808 // Write a call to action about $qcld_article_text and create a href tag link to: $qcld_article_target_label_cta.
1809 $mycta = "Напишете действие за " . $qcld_article_text . " и създайте връзка href tag към: " . $qcld_article_target_label_cta . ".";
1810
1811 } else if ( $qcld_article_language == "sv" ) {
1812 $prompt_text = " bloggämnen om ";
1813 $intro_text = "Skriv en introduktion om ";
1814 $conclusion_text = "Skriv en slutsats om ";
1815 $introduction = "Introduktion";
1816 $conclusion = "Slutsats";
1817 $faq_text = "Skriv " . strval( $qcld_article_number_of_heading ) . " frågor och svar om " . $qcld_article_text . ".";
1818 $faq_heading = "FAQ";
1819 // write a tagline about
1820 $tagline_text = "Skriv en tagline om ";
1821 $style_text = "Skrivstil: " . $writing_style . ".";
1822
1823 if ( empty($qcld_article_label_keywords) ) {
1824 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1825 } else {
1826 $keyword_text = ". Nyckelord: " . $qcld_article_label_keywords . ".";
1827 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text;
1828 }
1829 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1830 if ( !empty($qcld_article_label_word_to_avoid) ) {
1831 $avoid_text = " Undvik ord: " . $qcld_article_label_word_to_avoid . ".";
1832 $myprompt = $myprompt . $avoid_text;
1833 }
1834
1835 $myintro = $intro_text . $qcld_article_text;
1836 $myconclusion = $conclusion_text . $qcld_article_text;
1837 $mytagline = $tagline_text . $qcld_article_text;
1838 // Write a call to action about $qcld_article_text and create a href tag link to: $qcld_article_target_label_cta.
1839 $mycta = "Skriv ett åtgärdsförslag om " . $qcld_article_text . " och skapa en href tag-länk till: " . $qcld_article_target_label_cta . ".";
1840
1841 } else {
1842 $prompt_text = " blog topics about ";
1843 $intro_text = "Write an introduction about ";
1844 $conclusion_text = "Write a conclusion about ";
1845 $introduction = "Introduction";
1846 $conclusion = "Conclusion";
1847 $faq_text = "Write " . strval( $qcld_article_number_of_heading ) . " questions and answers about " . $qcld_article_text . ".";
1848 $faq_heading = "Q&A";
1849 // write a tagline about
1850 $tagline_text = "Write a tagline about ";
1851 $style_text = "Writing style: " . $writing_style . ".";
1852
1853 if ( empty($qcld_article_label_keywords) ) {
1854 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . ".";
1855 } else {
1856 $keyword_text = ". Keywords: " . $qcld_article_label_keywords . ".";
1857 $myprompt = strval( $qcld_article_number_of_heading ) . $prompt_text . $qcld_article_text . $keyword_text;
1858 }
1859 // if $qcld_article_label_word_to_avoid is not empty, add it to the prompt
1860 if ( !empty($qcld_article_label_word_to_avoid) ) {
1861 $avoid_text = " Exclude the following keywords: " . $qcld_article_label_word_to_avoid . ".";
1862 $myprompt = $myprompt . $avoid_text;
1863 }
1864 $myintro = $intro_text . $qcld_article_text;
1865 $myconclusion = $conclusion_text . $qcld_article_text;
1866 $mytagline = $tagline_text . $qcld_article_text;
1867 // Write a call to action about $qcld_article_text and create a href tag link to: $qcld_article_target_label_cta.
1868 $mycta = "Write a call to action about " . $qcld_article_text . " and create a href tag link to: " . $qcld_article_target_label_cta . ".";
1869
1870 }
1871
1872 $result_data = '';
1873 if(!empty($qcld_article_text)){
1874 $request_body = [
1875 "prompt" => $myprompt,
1876 "model" => $ai_engines,
1877 "max_tokens" => (int)$max_token,
1878 "temperature" => (float)$temperature,
1879 "presence_penalty" => (float)$ppenalty,
1880 "frequency_penalty" => (float)$fpenalty,
1881 "top_p" => 1,
1882 "best_of" => 1,
1883 ];
1884
1885 $data = json_encode($request_body);
1886 $url = "https://api.openai.com/v1/completions";
1887 $apt_key = "Authorization: Bearer ". $OPENAI_API_KEY;
1888
1889 $curl = curl_init($url);
1890 curl_setopt($curl, CURLOPT_URL, $url);
1891 curl_setopt($curl, CURLOPT_POST, true);
1892 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
1893 $headers = array(
1894 "Content-Type: application/json",
1895 $apt_key ,
1896 );
1897 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
1898 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
1899 $result = curl_exec($curl);
1900 curl_close($curl);
1901 // $results = json_decode($result);
1902 // $result_data = isset( $results->choices[0]->text ) ? trim( $results->choices[0]->text ) : '';
1903 $complete = json_decode( $result );
1904 // we need to catch the error here
1905 if ( isset( $complete->error ) ) {
1906 $complete = $complete->error->message;
1907 // exit
1908 echo esc_html( $complete ) ;
1909 exit;
1910 } else {
1911 $complete = $complete->choices[0]->text;
1912 }
1913 // trim the text
1914 $complete = trim( $complete );
1915 $mylist = array();
1916 $mylist = preg_split( "/\r\n|\n|\r/", $complete );
1917 // delete 1. 2. 3. etc from beginning of the line
1918 $mylist = preg_replace( '/^\\d+\\.\\s/', '', $mylist );
1919 $allresults = "";
1920 $qcld_article_heading_tag = sanitize_text_field( $_REQUEST["qcld_article_heading_tag"] );
1921 foreach ( $mylist as $key => $value ) {
1922 $withstyle = $value . '. ' . $style_text . ', ' . $tone_text . '.';
1923 // if avoid is not empty add it to the prompt
1924 if ( !empty(${$wpai_words_to_avoid}) ) {
1925 $withstyle = $value . '. ' . $style_text . ', ' . $tone_text . ', ' . $avoid_text . '.';
1926 }
1927
1928 $request_body = [
1929 "prompt" => $myprompt,
1930 "model" => $ai_engines,
1931 "max_tokens" => (int)$max_token,
1932 "temperature" => (float)$temperature,
1933 "presence_penalty" => (float)$ppenalty,
1934 "frequency_penalty" => (float)$fpenalty,
1935 "top_p" => 1,
1936 "best_of" => 1,
1937 ];
1938 $data = json_encode($request_body);
1939 $url = "https://api.openai.com/v1/completions";
1940 $apt_key = "Authorization: Bearer ". $OPENAI_API_KEY;
1941
1942 $curl = curl_init($url);
1943 curl_setopt($curl, CURLOPT_URL, $url);
1944 curl_setopt($curl, CURLOPT_POST, true);
1945 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
1946 $headers = array(
1947 "Content-Type: application/json",
1948 $apt_key ,
1949 );
1950 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
1951 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
1952 $result = curl_exec($curl);
1953 curl_close($curl);
1954
1955 $complete = json_decode( $result );
1956 $complete = isset($complete->choices[0]->text) ? $complete->choices[0]->text : '';
1957 // trim the text
1958 $complete = trim( $complete );
1959 $value = str_replace( '\\/', '', $value );
1960 $value = str_replace( '\\', '', $value );
1961 // trim value
1962 $value = trim( $value );
1963 // we will add h tag if the user wants to
1964
1965 if ( $qcld_article_heading_tag == "h1" ) {
1966 $result = "\n"."<h1>" . $value . "</h1>" ."\n". $complete;
1967 } elseif ( $qcld_article_heading_tag == "h2" ) {
1968 $result = "\n"."<h2>" . $value . "</h2>" ."\n". $complete;
1969 } elseif ( $qcld_article_heading_tag == "h3" ) {
1970 $result = "\n"."<h3>" . $value . "</h3>" ."\n". $complete;
1971 } elseif ( $qcld_article_heading_tag == "h4" ) {
1972 $result = "\n"."<h4>" . $value . "</h4>" ."\n". $complete;
1973 } elseif ( $qcld_article_heading_tag == "h5" ) {
1974 $result = "\n"."<h5>" . $value . "</h5>" ."\n". $complete;
1975 } elseif ( $qcld_article_heading_tag == "h6" ) {
1976 $result = "\n"."<h6>" . $value . "</h6>" ."\n". $complete;
1977 } else {
1978 $result = "\n"."<h2>" . $value . "</h2>" ."\n". $complete;
1979 }
1980
1981 $allresults = $allresults . $result;
1982 }
1983
1984
1985
1986
1987 if ( $qcld_article_heading_intro == "1" ) {
1988 // we need to catch the error here
1989 $request_body = [
1990 "prompt" => $myintro,
1991 "model" => $ai_engines,
1992 "max_tokens" => (int)$max_token,
1993 "temperature" => (float)$temperature,
1994 "presence_penalty" => (float)$ppenalty,
1995 "frequency_penalty" => (float)$fpenalty,
1996 "top_p" => 1,
1997 "best_of" => 1,
1998 ];
1999 $data = json_encode($request_body);
2000 $url = "https://api.openai.com/v1/completions";
2001 $apt_key = "Authorization: Bearer ". $OPENAI_API_KEY;
2002
2003 $curl = curl_init($url);
2004 curl_setopt($curl, CURLOPT_URL, $url);
2005 curl_setopt($curl, CURLOPT_POST, true);
2006 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
2007 $headers = array(
2008 "Content-Type: application/json",
2009 $apt_key ,
2010 );
2011 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
2012 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
2013 $result = curl_exec($curl);
2014 curl_close($curl);
2015
2016 $completeintro = json_decode( $result );
2017
2018 if ( isset( $completeintro->error ) ) {
2019 $completeintro = $completeintro->error->message;
2020 // exit
2021 echo esc_html( $completeintro ) ;
2022 exit;
2023 } else {
2024 $completeintro = $completeintro->choices[0]->text;
2025 // trim the text
2026 $completeintro = trim( $completeintro );
2027 // add <h1>Introuction</h1> to the beginning of the text
2028 $completeintro = "\n"."<h1>" . $introduction . "</h1>" ."\n". $completeintro;
2029 // add intro to the beginning of the text
2030 $allresults = $completeintro . $allresults;
2031 }
2032
2033 }
2034
2035 // if wpai_add_faq is checked then call api with faq prompt
2036
2037 if ( $qcld_article_heading_faq == "1" ) {
2038 // we need to catch the error here
2039 $request_body = [
2040 "prompt" => $faq_text,
2041 "model" => $ai_engines,
2042 "max_tokens" => (int)$max_token,
2043 "temperature" => (float)$temperature,
2044 "presence_penalty" => (float)$ppenalty,
2045 "frequency_penalty" => (float)$fpenalty,
2046 "top_p" => 1,
2047 "best_of" => 1,
2048 ];
2049 $data = json_encode($request_body);
2050 $url = "https://api.openai.com/v1/completions";
2051 $apt_key = "Authorization: Bearer ". $OPENAI_API_KEY;
2052
2053 $curl = curl_init($url);
2054 curl_setopt($curl, CURLOPT_URL, $url);
2055 curl_setopt($curl, CURLOPT_POST, true);
2056 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
2057 $headers = array(
2058 "Content-Type: application/json",
2059 $apt_key ,
2060 );
2061 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
2062 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
2063 $result = curl_exec($curl);
2064 curl_close($curl);
2065
2066 $completefaq = json_decode( $result );
2067
2068 if ( isset( $completefaq->error ) ) {
2069 $completefaq = $completefaq->error->message;
2070 // exit
2071 echo esc_html( $completefaq ) ;
2072 exit;
2073 } else {
2074 $completefaq = $completefaq->choices[0]->text;
2075 // trim the text
2076 $completefaq = trim( $completefaq );
2077 // add <h1>FAQ</h1> to the beginning of the text
2078 $completefaq = "\n"."<h2>" . $faq_heading . "</h2>" ."\n". $completefaq;
2079 // add intro to the beginning of the text
2080 $allresults = $allresults . $completefaq;
2081 }
2082
2083 }
2084
2085 //if myconclusion is not empty,calls the openai api
2086
2087 if ( $qcld_article_heading_conclusion == "1" ) {
2088
2089 // we need to catch the error here
2090 $request_body = [
2091 "prompt" => $myconclusion,
2092 "model" => $ai_engines,
2093 "max_tokens" => (int)$max_token,
2094 "temperature" => (float)$temperature,
2095 "presence_penalty" => (float)$ppenalty,
2096 "frequency_penalty" => (float)$fpenalty,
2097 "top_p" => 1,
2098 "best_of" => 1,
2099 ];
2100 $data = json_encode($request_body);
2101 $url = "https://api.openai.com/v1/completions";
2102 $apt_key = "Authorization: Bearer ". $OPENAI_API_KEY;
2103
2104 $curl = curl_init($url);
2105 curl_setopt($curl, CURLOPT_URL, $url);
2106 curl_setopt($curl, CURLOPT_POST, true);
2107 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
2108 $headers = array(
2109 "Content-Type: application/json",
2110 $apt_key ,
2111 );
2112 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
2113 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
2114 $result = curl_exec($curl);
2115 curl_close($curl);
2116
2117 $completeconclusion = json_decode( $result );
2118
2119 if ( isset( $completeconclusion->error ) ) {
2120 $completeconclusion = $completeconclusion->error->message;
2121 // exit
2122 echo esc_html( $completeconclusion ) ;
2123 exit;
2124 } else {
2125 $completeconclusion = $completeconclusion->choices[0]->text;
2126 // trim the text
2127 $completeconclusion = trim( $completeconclusion );
2128 // add <h1>Conclusion</h1> to the beginning of the text
2129 $completeconclusion = "\n"."<h1>" . $conclusion . "</h1>" ."\n". $completeconclusion;
2130 // add intro to the beginning of the text
2131 $allresults = $allresults . $completeconclusion;
2132 }
2133
2134 }
2135
2136 // qcld_article_heading_tagline is checked then call the openai api
2137
2138 if ( $qcld_article_heading_tagline == "1" ) {
2139 // we need to catch the error here
2140 $request_body = [
2141 "prompt" => $mytagline,
2142 "model" => $ai_engines,
2143 "max_tokens" => (int)$max_token,
2144 "temperature" => (float)$temperature,
2145 "presence_penalty" => (float)$ppenalty,
2146 "frequency_penalty" => (float)$fpenalty,
2147 "top_p" => 1,
2148 "best_of" => 1,
2149 ];
2150 $data = json_encode($request_body);
2151 $url = "https://api.openai.com/v1/completions";
2152 $apt_key = "Authorization: Bearer ". $OPENAI_API_KEY;
2153
2154 $curl = curl_init($url);
2155 curl_setopt($curl, CURLOPT_URL, $url);
2156 curl_setopt($curl, CURLOPT_POST, true);
2157 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
2158 $headers = array(
2159 "Content-Type: application/json",
2160 $apt_key ,
2161 );
2162 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
2163 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
2164 $result = curl_exec($curl);
2165 curl_close($curl);
2166
2167 $completetagline = json_decode( $result );
2168
2169 if ( isset( $completetagline->error ) ) {
2170 $completetagline = $completetagline->error->message;
2171 // exit
2172 echo esc_html( $completetagline ) ;
2173 exit;
2174 } else {
2175 $completetagline = $completetagline->choices[0]->text;
2176 // trim the text
2177 $completetagline = trim( $completetagline );
2178 // add <p> to the beginning of the text
2179 $completetagline = "\n"."<p>" . $completetagline . "</p>"."\n";
2180 // add intro to the beginning of the text
2181 $allresults = $completetagline . $allresults;
2182 }
2183
2184 }
2185
2186 // if qcld_article_label_keywords_bold is checked then then find all keywords and bold them. keywords are separated by comma
2187 if ( $qcld_article_label_keywords_bold == "1" ) {
2188 // check to see at least one keyword is entered
2189
2190 if ( $qcld_article_label_keywords != "" ) {
2191 // split keywords by comma if there are more than one but if there is only one then it will not split
2192
2193 if ( strpos( $qcld_article_label_keywords, ',' ) !== false ) {
2194 $keywords = explode( ",", $qcld_article_label_keywords );
2195 } else {
2196 $keywords = array( $qcld_article_label_keywords );
2197 }
2198
2199 // loop through keywords and bold them
2200 foreach ( $keywords as $keyword ) {
2201 $keyword = trim( $keyword );
2202 // replace keyword with bold keyword but make sure exact match is found. for example if the keyword is "the" then it should not replace "there" with "there".. capital dont matter
2203 $allresults = preg_replace( '/\\b' . $keyword . '\\b/', '<strong>' . $keyword . '</strong>', $allresults );
2204 }
2205 }
2206
2207 }
2208 // if qcld_article_target_url and qcld_article_label_anchor_text is not empty then find qcld_article_label_anchor_text in the text and create a link using qcld_article_target_url
2209 if ( $qcld_article_target_url != "" && $qcld_article_label_anchor_text != "" ) {
2210 // create a link if anchor text found.. rules: 1. only for first occurance 2. exact match 3. case insensitive 4. if anchor text found inside any h1,h2,h3,h4,h5,h6, a then skip it. 5. use anchor text to create link dont replace it with existing text
2211 $allresults = preg_replace(
2212 '/(?<!<h[1-6]><a href=")(?<!<a href=")(?<!<h[1-6]>)(?<!<h[1-6]><strong>)(?<!<strong>)(?<!<h[1-6]><em>)(?<!<em>)(?<!<h[1-6]><strong><em>)(?<!<strong><em>)(?<!<h[1-6]><em><strong>)(?<!<em><strong>)\\b' . $qcld_article_label_anchor_text . '\\b(?![^<]*<\\/a>)(?![^<]*<\\/h[1-6]>)(?![^<]*<\\/strong>)(?![^<]*<\\/em>)(?![^<]*<\\/strong><\\/em>)(?![^<]*<\\/em><\\/strong>)/i',
2213 '<a href="' . $qcld_article_target_url . '">' . $qcld_article_label_anchor_text . '</a>',
2214 $allresults,
2215 1
2216 );
2217 }
2218 // if qcld_article_target_label_cta is not empty then call api to get cta text and create a link using qcld_article_target_label_cta
2219
2220 if ( $qcld_article_target_label_cta != "" ) {
2221 // call api to get cta text
2222 $request_body = [
2223 "prompt" => $mycta,
2224 "model" => $ai_engines,
2225 "max_tokens" => (int)$max_token,
2226 "temperature" => (float)$temperature,
2227 "presence_penalty" => (float)$ppenalty,
2228 "frequency_penalty" => (float)$fpenalty,
2229 "top_p" => 1,
2230 "best_of" => 1,
2231 ];
2232 $data = json_encode($request_body);
2233 $url = "https://api.openai.com/v1/completions";
2234 $apt_key = "Authorization: Bearer ". $OPENAI_API_KEY;
2235
2236 $curl = curl_init($url);
2237 curl_setopt($curl, CURLOPT_URL, $url);
2238 curl_setopt($curl, CURLOPT_POST, true);
2239 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
2240 $headers = array(
2241 "Content-Type: application/json",
2242 $apt_key ,
2243 );
2244 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
2245 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
2246 $result = curl_exec($curl);
2247 curl_close($curl);
2248
2249 // we need to catch the error here
2250 $completecta = json_decode( $result );
2251
2252 if ( isset( $completecta->error ) ) {
2253 $completecta = $completecta->error->message;
2254 // exit
2255 echo esc_html( $completecta ) ;
2256 exit;
2257 } else {
2258 $completecta = $completecta->choices[0]->text;
2259 // trim the text
2260 $completecta = trim( $completecta );
2261 // add <p> to the beginning of the text
2262 $completecta = "<p>" . $completecta . "</p>"."\n";
2263
2264 if ( $wpai_cta_pos == "beg" ) {
2265 $allresults = preg_replace(
2266 '/(<h[1-6]>)/',
2267 $completecta . ' $1',
2268 $allresults,
2269 1
2270 );
2271 } else {
2272 $allresults = $allresults . $completecta;
2273 }
2274
2275 }
2276
2277 }
2278
2279 // if add image is checked then we should send api request to get image
2280 if ( $qcld_article_heading_img == "1" ) {
2281 $request_body = [
2282 "prompt" => $qcld_article_text,
2283 "n" => 1,
2284 "size" => $img_size,
2285 "response_format" => "url",
2286 ];
2287 $data = json_encode($request_body);
2288 $url = "https://api.openai.com/v1/images/generations";
2289 $apt_key = "Authorization: Bearer ". $OPENAI_API_KEY;
2290 $curl = curl_init($url);
2291 curl_setopt($curl, CURLOPT_URL, $url);
2292 curl_setopt($curl, CURLOPT_POST, true);
2293 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
2294 $headers = array(
2295 "Content-Type: application/json",
2296 $apt_key ,
2297 );
2298 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
2299 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
2300 $result = curl_exec($curl);
2301 curl_close($curl);
2302
2303 // we need to catch the error here
2304 $imgresult = json_decode( $result );
2305
2306
2307 $imgresult = $imgresult->data[0]->url;
2308
2309
2310 $array = explode('/', getimagesize($imgresult)['mime']);
2311 $imagetype = end($array);
2312 $uniq_name = md5($imgresult);
2313 $filename = $uniq_name . '.' . $imagetype;
2314
2315 $uploaddir = wp_upload_dir();
2316 $target_file_name = $uploaddir['path'] . '/' . $filename;
2317
2318 $contents = file_get_contents( $imgresult );
2319 $savefile = fopen($target_file_name, 'w');
2320 fwrite($savefile, $contents);
2321 fclose($savefile);
2322
2323 /* add the image title */
2324 $image_title = ucwords( $uniq_name );
2325
2326 $qcld_seo_openai_images_attribution = 'gpt openai';
2327
2328 /* add the caption */
2329 $attachment_caption = '';
2330 if (! isset($qcld_seo_openai_images_attribution['attribution']) | isset($qcld_seo_openai_images_attribution['attribution']) == 'true')
2331 $attachment_caption = '<a href="' . esc_url( $imgresult ) . '" target="_blank" rel="noopener">' . esc_attr( $filename ) . '</a>';
2332 unset($imgresult);
2333 /* insert the attachment */
2334 $wp_filetype = wp_check_filetype(basename($target_file_name), null);
2335 $attachment = array(
2336 'guid' => $uploaddir['url'] . '/' . basename($target_file_name),
2337 'post_mime_type' => $wp_filetype['type'],
2338 'post_title' => $image_title,
2339 'post_status' => 'inherit'
2340 );
2341 $post_id = isset($_REQUEST['post_id']) ? absint($_REQUEST['post_id']): '';
2342 $attach_id = wp_insert_attachment($attachment, $target_file_name, $post_id);
2343 if ($attach_id == 0)
2344 die('Error: File attachment error');
2345 $attach_data = wp_generate_attachment_metadata($attach_id, $target_file_name);
2346 $result = wp_update_attachment_metadata($attach_id, $attach_data);
2347 $image_data = array();
2348 $image_data['ID'] = $attach_id;
2349 $image_data['post_excerpt'] = $attachment_caption;
2350 wp_update_post($image_data);
2351 $parsed = wp_get_attachment_image_src( $attach_id, 'medium' )[0];
2352 if(!empty($parsed)){
2353 $attach_id = $parsed;
2354 }
2355 $imgresult = "\n"."<img src='" . $attach_id . "' alt='" . $qcld_article_text . "' />"."\n";
2356 // get half of qcld_article_number_of_heading and insert image in the middle
2357 $half = intval( $qcld_article_number_of_heading ) / 2;
2358 $half = round( $half );
2359 $half = $half - 1;
2360 // use qcld_article_heading_tag to add heading tag to image
2361 $allresults = explode( "</" . $qcld_article_heading_tag . ">", $allresults );
2362 $allresults[$half] = $allresults[$half] . $imgresult;
2363 $allresults = implode( "</" . $qcld_article_heading_tag . ">", $allresults );
2364 wp_send_json( [ 'status' => 'success', 'keywords' => $allresults ] );
2365 wp_die();
2366 } else {
2367 wp_send_json( [ 'status' => 'success', 'keywords' => $allresults ] );
2368 wp_die();
2369 }
2370 }
2371 wp_send_json( [ 'status' => 'success', 'keywords' => $result_data ] );
2372 wp_die();
2373
2374 }
2375
2376 public function qcld_seo_image_generate_url_functions() {
2377
2378 $qcld_seo_result = array(
2379 'status' => 'error',
2380 'msg' => esc_html('Something went wrong'),
2381 );
2382
2383 /* Download and upload the chosen image */
2384 if (isset($_POST['qcld_seo_openai_images_upload'])) {
2385 // "pluggable.php" is required for wp_verify_nonce() and other upload related helpers
2386 if (!function_exists('wp_verify_nonce'))
2387 require_once(ABSPATH . 'wp-includes/pluggable.php');
2388 if(!function_exists('wp_generate_attachment_metadata')){
2389 include_once( ABSPATH . 'wp-admin/includes/image.php' );
2390 }
2391 if(!function_exists('download_url')){
2392 include_once( ABSPATH . 'wp-admin/includes/file.php' );
2393 }
2394 if(!function_exists('media_handle_sideload')){
2395 include_once( ABSPATH . 'wp-admin/includes/media.php' );
2396 }
2397
2398 $post_id = isset($_REQUEST['post_id']) ? absint($_REQUEST['post_id']): '';
2399 $imageurl = isset($_POST['image_url']) ? sanitize_url( $_POST['image_url'] ) : '';
2400 $image_user = isset($_POST['image_user']) ? sanitize_url( $_POST['image_user'] ) : '';
2401 $image_src_page = isset($_POST['image_src_page']) ? esc_url( $_POST['image_src_page'] ) : '';
2402 $qcld_seo_openai_images_attribution = 'gpt openai';
2403
2404 $array = explode('/', getimagesize($imageurl)['mime']);
2405 $imagetype = end($array);
2406 $uniq_name = md5($imageurl);
2407 $filename = $uniq_name . '.' . $imagetype;
2408
2409 $uploaddir = wp_upload_dir();
2410 $target_file_name = $uploaddir['path'] . '/' . $filename;
2411
2412 $contents = file_get_contents( $imageurl );
2413 $savefile = fopen($target_file_name, 'w');
2414 fwrite($savefile, $contents);
2415 fclose($savefile);
2416 unset($imageurl);
2417
2418 /* add the image title */
2419 $image_title = ucwords( $uniq_name );
2420
2421 /* add the caption */
2422 $attachment_caption = '';
2423 if (! isset($qcld_seo_openai_images_attribution['attribution']) | isset($qcld_seo_openai_images_attribution['attribution']) == 'true')
2424 $attachment_caption = '<a href="' . esc_url( $image_src_page ) . '" target="_blank" rel="noopener">' . esc_attr( $image_user ) . '</a>';
2425
2426 /* insert the attachment */
2427 $wp_filetype = wp_check_filetype(basename($target_file_name), null);
2428 $attachment = array(
2429 'guid' => $uploaddir['url'] . '/' . basename($target_file_name),
2430 'post_mime_type' => $wp_filetype['type'],
2431 'post_title' => $image_title,
2432 'post_status' => 'inherit'
2433 );
2434
2435 $attach_id = wp_insert_attachment($attachment, $target_file_name, $post_id);
2436 if ($attach_id == 0)
2437 die('Error: File attachment error');
2438
2439 $attach_data = wp_generate_attachment_metadata($attach_id, $target_file_name);
2440 $result = wp_update_attachment_metadata($attach_id, $attach_data);
2441
2442 $image_data = array();
2443 $image_data['ID'] = $attach_id;
2444 $image_data['post_excerpt'] = $attachment_caption;
2445 wp_update_post($image_data);
2446
2447 // $parsed = wp_get_attachment_image_src( $attach_id, 'medium' )[0];
2448
2449 /*if(!empty($parsed)){
2450 $attach_id = $parsed;
2451 }*/
2452
2453 $size = 'large';
2454 $attachment_id = $attach_id;
2455
2456 list( $url, $width, $height ) = wp_get_attachment_image_src( $attachment_id, $size );
2457 //$url = wp_get_attachment_image_url( $attachment_id );
2458 //var_dump( wp_get_attachment_image_url( $attachment_id ) );
2459 //wp_die();
2460 $qcld_seo_result['status'] = 'success';
2461 $html = esc_html('Image Successfully Added to Media Library');
2462
2463 wp_send_json_success( compact( 'attachment_id', 'url', 'width', 'height', 'size', 'html' ) );
2464 exit;
2465
2466
2467
2468
2469 }
2470
2471 wp_send_json( $qcld_seo_result );
2472 exit;
2473
2474
2475 }
2476 }
2477
2478 /**
2479 * @return qcld_wpopenai_addon
2480 */
2481 if(!function_exists('qcld_wpopenai_addons')){
2482 function qcld_openais() {
2483 $qcld_wpopenai_addon = new qcld_wpopenai_addons();
2484 return $qcld_wpopenai_addon->instance();
2485
2486 }
2487 }
2488
2489 //fire off the plugin
2490 qcld_openais();
2491
2492 }