PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 4.4.5
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v4.4.5
8.7.8 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 All 534 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.4.5, at includes/openai/qcld-bot-openai.php

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