'None', 'photography_style' => 'None', 'lighting' => 'Ambient', 'subject' => 'None', 'camera_settings' => 'Aperture', 'composition' => 'Rule of Thirds', 'resolution' => '4K (3840x2160)', 'color' => 'RGB', 'special_effects' => 'Cinemagraph' ); public $acwc_headings = array(); public $acwc_result = array( 'status' => 'error', 'msg' => 'Something went wrong', 'tokens' => 0, 'length' => 0, 'data' => '', 'error' => '', 'content' => '', 'next_step' => 'content', 'img' => '', 'description' => '', 'featured_img' => '', 'tocs' => '' ); public $acwc; public $acwc_sleep = 8; public static function get_instance() { if (is_null(self::$instance)) { self::$instance = new self(); } return self::$instance; } public function __construct() { add_action('wp_ajax_acwc_content_generator',[$this,'acwc_content_generator']); } public function acwc_content_generator() { $step = isset( $_REQUEST['step'] ) && !empty($_REQUEST['step']) ? sanitize_text_field( $_REQUEST['step'] ) : 'heading'; $acwc = ACWCGPT::get_instance()->acwc(); if ( ! wp_verify_nonce( $_POST['nonce'], 'acwc-ajax-nonce' ) ) { $this->acwc_result['msg'] = ACWC_NONCE_ERROR; $this->acwc_result['status'] = 'error'; wp_send_json($this->acwcResult()); } if(!$acwc){ $this->acwc_result['msg'] = 'Missing API Setting'; $this->acwc_result['status'] = 'error'; } else{ $this->init($acwc); $this->acwc_generator($step); } wp_send_json($this->acwcResult()); } public function init($open_ai, $acwc_preview_title = false, $cronjob = false, $post_id = false) { $this->acwc = $open_ai; $img_size = $open_ai->img_size; $this->acwc_image_style = get_option('_acwc_image_style', ''); $this->acwc_temperature = floatval( $open_ai->temperature ); $this->acwc_max_tokens = intval( $open_ai->max_tokens ); $this->acwc_top_p = floatval( $open_ai->top_p ); $this->acwc_best_of = intval( $open_ai->best_of ); $this->acwc_frequency_penalty = floatval( $open_ai->frequency_penalty ); $this->acwc_presence_penalty = floatval( $open_ai->presence_penalty ); $this->acwc_engine = get_option('acwc_ai_model','text-davinci-003'); $this->acwc_allowed_html_content_post = wp_kses_allowed_html( 'post' ); if($cronjob){ $this->acwc_preview_title = $acwc_preview_title; $this->acwc_number_of_heading = $open_ai->wpai_number_of_heading; $this->acwc_image_source = get_option('acwc_image_source',''); $this->acwc_featured_image_source = get_option('acwc_featured_image_source',''); $this->acwc_language = sanitize_text_field( $open_ai->wpai_language ); $this->acwc_add_intro = intval( $open_ai->wpai_add_intro ); $this->acwc_add_conclusion = intval( $open_ai->wpai_add_conclusion ); $this->acwc_writing_style = sanitize_text_field( $open_ai->wpai_writing_style ); $this->acwc_writing_tone = sanitize_text_field( $open_ai->wpai_writing_tone ); $this->acwc_keywords = get_post_meta($post_id, '_acwc_keywords', true); $this->acwc_add_keywords_bold = intval($open_ai->wpai_add_keywords_bold); $this->acwc_heading_tag = sanitize_text_field( $open_ai->wpai_heading_tag ); $this->acwc_words_to_avoid = get_post_meta($post_id,'_acwc_avoid',true); $this->acwc_add_tagline = intval( $open_ai->wpai_add_tagline ); $this->acwc_add_faq = intval( $open_ai->wpai_add_faq ); $this->acwc_seo_meta_desc = get_option('_acwc_seo_meta_desc',false); $this->acwc_target_url = get_post_meta($post_id,'_acwc_target',true); $this->acwc_anchor_text = get_post_meta($post_id,'_acwc_anchor',true); $this->acwc_cta_pos = sanitize_text_field( $open_ai->wpai_cta_pos ); $this->acwc_target_url_cta = get_post_meta($post_id,'_acwc_cta',true); $this->acwc_modify_headings = false; $this->acwc_toc = get_option('acwc_toc',false); $this->acwc_toc_title = get_option('acwc_toc_title','Table of Contents'); $this->acwc_toc_title_tag = get_option('acwc_toc_title_tag','h2'); $this->acwc_intro_title_tag = get_option('acwc_intro_title_tag','h2'); $this->acwc_conclusion_title_tag = get_option('acwc_conclusion_title_tag','h2'); $this->acwc_pexels_api = get_option('acwc_pexels_api',''); $this->acwc_pexels_orientation = get_option('acwc_pexels_orientation',''); $this->acwc_pexels_size = get_option('acwc_pexels_size',''); $this->acwc_img_size = $img_size; $this->acwc_img_style = get_option('_acwc_image_style', ''); $this->acwc_toc_list = array(); $this->generate_continue = false; $this->acwc_result['content'] = ''; $acwc_custom_image_settings = get_option('acwc_custom_image_settings',[]); $this->acwc_custom_image_settings = wp_parse_args($acwc_custom_image_settings, $this->acwc_custom_image_settings); } else{ $this->acwc_number_of_heading = sanitize_text_field( $_REQUEST["wpai_number_of_heading"] ); $this->acwc_image_source = sanitize_text_field($_REQUEST['acwc_image_source']); $this->acwc_featured_image_source = sanitize_text_field($_REQUEST['acwc_featured_image_source']); $this->acwc_language = sanitize_text_field( $_REQUEST["wpai_language"] ); $this->acwc_add_intro = intval( sanitize_text_field($_REQUEST["wpai_add_intro"] )); $this->acwc_add_conclusion = intval( sanitize_text_field($_REQUEST["wpai_add_conclusion"] )); $this->acwc_writing_style = sanitize_text_field( $_REQUEST["wpai_writing_style"] ); $this->acwc_writing_tone = sanitize_text_field( $_REQUEST["wpai_writing_tone"] ); $this->acwc_keywords = isset($_REQUEST["wpai_keywords"]) ? sanitize_text_field( $_REQUEST["wpai_keywords"] ) : ''; $this->acwc_add_keywords_bold = intval( sanitize_text_field($_REQUEST["wpai_add_keywords_bold"] )); $this->acwc_heading_tag = sanitize_text_field( $_REQUEST["wpai_heading_tag"] ); $this->acwc_words_to_avoid = isset($_REQUEST['wpai_words_to_avoid']) ? sanitize_text_field( $_REQUEST["wpai_words_to_avoid"] ): ''; $this->acwc_add_tagline = intval( sanitize_text_field($_REQUEST["wpai_add_tagline"] )); $this->acwc_add_faq = intval( sanitize_text_field($_REQUEST["wpai_add_faq"] )); $this->acwc_seo_meta_desc = isset($_REQUEST["acwc_seo_meta_desc"]) ? intval( sanitize_text_field($_REQUEST["acwc_seo_meta_desc"] )) : false; $this->acwc_target_url = sanitize_text_field( $_REQUEST["wpai_target_url"] ); $this->acwc_anchor_text = sanitize_text_field( $_REQUEST["wpai_anchor_text"] ); $this->acwc_cta_pos = sanitize_text_field( $_REQUEST["wpai_cta_pos"] ); $this->acwc_target_url_cta = sanitize_text_field( $_REQUEST["wpai_target_url_cta"] ); $this->acwc_img_size = sanitize_text_field( $_REQUEST["wpai_img_size"] ); $this->acwc_img_size = ( empty($this->acwc_img_size) ? $img_size : $this->acwc_img_size ); $this->acwc_img_style = sanitize_text_field( $_REQUEST["wpai_img_style"] ); $this->acwc_img_style = ( empty($this->acwc_img_style) ? $this->acwc_image_style : $this->acwc_img_style ); $this->acwc_modify_headings = intval( sanitize_text_field($_REQUEST["wpai_modify_headings"] )); $this->acwc_toc = intval(sanitize_text_field($_REQUEST['acwc_toc'])); $this->acwc_toc_title = sanitize_text_field($_REQUEST['acwc_toc_title']); $this->acwc_toc_title = empty($this->acwc_toc_title) ? 'Table of Contents' : $this->acwc_toc_title; $this->acwc_toc_title_tag = sanitize_text_field($_REQUEST['acwc_toc_title_tag']); $this->acwc_toc_title_tag = empty($this->acwc_toc_title_tag) ? 'h2' : $this->acwc_toc_title_tag; $this->acwc_intro_title_tag = sanitize_text_field($_REQUEST['acwc_intro_title_tag']); $this->acwc_intro_title_tag = empty($this->acwc_intro_title_tag) ? 'h2' : $this->acwc_intro_title_tag; $this->acwc_conclusion_title_tag = sanitize_text_field($_REQUEST['acwc_conclusion_title_tag']); $this->acwc_conclusion_title_tag = empty($this->acwc_conclusion_title_tag) ? 'h2' : $this->acwc_conclusion_title_tag; $this->acwc_toc_list = isset($_REQUEST['acwc_toc_list']) && !empty($_REQUEST['acwc_toc_list']) ? explode('||',sanitize_text_field($_REQUEST['acwc_toc_list'])) : array(); $this->acwc_pexels_orientation = isset($_REQUEST['acwc_pexels_orientation']) && !empty($_REQUEST['acwc_pexels_orientation']) ? sanitize_text_field($_REQUEST['acwc_pexels_orientation']) : ''; $this->acwc_pexels_size = isset($_REQUEST['acwc_pexels_size']) && !empty($_REQUEST['acwc_pexels_size']) ? sanitize_text_field($_REQUEST['acwc_pexels_size']) : ''; $this->acwc_pexels_api = get_option('acwc_pexels_api',''); $this->generate_continue = intval( sanitize_text_field($_REQUEST["is_generate_continue"] )); $this->acwc_result['tokens'] = isset($_REQUEST['tokens']) ? sanitize_text_field($_REQUEST['tokens']) : 0; $this->acwc_result['length'] = isset($_REQUEST['length']) ? sanitize_text_field($_REQUEST['length']) : 0; $this->acwc_result['content'] = ( isset( $_REQUEST['content'] ) ? wp_kses( $_REQUEST['content'], $this->acwc_allowed_html_content_post ) : '' ); $this->acwc_preview_title = sanitize_text_field( $_REQUEST["wpai_preview_title"] ); $hfHeadings = sanitize_text_field( $_REQUEST["hfHeadings"] ); $this->acwc_headings = explode( "||", $hfHeadings ); if(isset($_REQUEST['acwc_custom_image_settings']) && is_array($_REQUEST['acwc_custom_image_settings']) && count($_REQUEST['acwc_custom_image_settings'])){ $acwc_custom_image_settings = acwc_util_core()->sanitize_text_or_array_field($_REQUEST['acwc_custom_image_settings']); } else{ $acwc_custom_image_settings = get_option('acwc_custom_image_settings',[]); } $this->acwc_custom_image_settings = wp_parse_args($acwc_custom_image_settings, $this->acwc_custom_image_settings); } $this->acwc_opts = [ 'model' => $this->acwc_engine, 'temperature' => $this->acwc_temperature, 'max_tokens' => $this->acwc_max_tokens, 'frequency_penalty' => $this->acwc_frequency_penalty, 'presence_penalty' => $this->acwc_presence_penalty, 'top_p' => $this->acwc_top_p, 'best_of' => $this->acwc_best_of ]; $this->acwc_sleep = get_option('acwc_sleep_time',8); if(empty($this->acwc_language)){ $this->acwc_language = 'en'; } if ( empty($this->acwc_number_of_heading) ) { $this->acwc_number_of_heading = 5; } if ( empty($this->acwc_writing_style) ) { $this->acwc_writing_style = "infor"; } if ( empty($this->acwc_writing_tone) ) { $this->acwc_writing_tone = "formal"; } // if heading tag is not set, set it to h2 if ( empty($this->acwc_heading_tag) ) { $this->acwc_heading_tag = "h2"; } $acwc_language_file = plugin_dir_path( dirname( __FILE__ ) ) . 'admin/languages/' . $this->acwc_language . '.json'; if ( !file_exists( $acwc_language_file ) ) { $acwc_language_file = plugin_dir_path( dirname( __FILE__ ) ) . 'admin/languages/en.json'; } $acwc_language_json = file_get_contents( $acwc_language_file ); $this->acwc_languages = json_decode( $acwc_language_json, true ); $this->writing_style = ( isset( $this->acwc_languages['writing_style'][$this->acwc_writing_style] ) ? $this->acwc_languages['writing_style'][$this->acwc_writing_style] : 'infor' ); $this->tone_text = ( isset( $this->acwc_languages['writing_tone'][$this->acwc_writing_tone] ) ? $this->acwc_languages['writing_tone'][$this->acwc_writing_tone] : 'formal' ); if ( $this->acwc_number_of_heading == 1 ) { $prompt_text = ( isset( $this->acwc_languages['prompt_text_1'] ) ? $this->acwc_languages['prompt_text_1'] : '' ); } else { $prompt_text = ( isset( $this->acwc_languages['prompt_text'] ) ? $this->acwc_languages['prompt_text'] : '' ); } $this->intro_text = ( isset( $this->acwc_languages['intro_text'] ) ? $this->acwc_languages['intro_text'] : '' ); $this->conclusion_text = ( isset( $this->acwc_languages['conclusion_text'] ) ? $this->acwc_languages['conclusion_text'] : '' ); $this->tagline_text = ( isset( $this->acwc_languages['tagline_text'] ) ? $this->acwc_languages['tagline_text'] : '' ); $this->introduction = ( isset( $this->acwc_languages['introduction'] ) ? $this->acwc_languages['introduction'] : '' ); $this->conclusion = ( isset( $this->acwc_languages['conclusion'] ) ? $this->acwc_languages['conclusion'] : '' ); if ( $this->acwc_language == 'hi' || $this->acwc_language == 'tr' || $this->acwc_language == 'ja' || $this->acwc_language == 'zh' || $this->acwc_language == 'ko' ) { $this->faq_text = ( isset( $this->acwc_languages['faq_text'] ) ? sprintf( $this->acwc_languages['faq_text'], $this->acwc_preview_title, strval( $this->acwc_number_of_heading ) ) : '' ); } else { $this->faq_text = ( isset( $this->acwc_languages['faq_text'] ) ? sprintf( $this->acwc_languages['faq_text'], strval( $this->acwc_number_of_heading ), $this->acwc_preview_title ) : '' ); } $this->faq_heading = ( isset( $this->acwc_languages['faq_heading'] ) ? $this->acwc_languages['faq_heading'] : '' ); $this->style_text = ( isset( $this->acwc_languages['style_text'] ) ? sprintf( $this->acwc_languages['style_text'], $this->writing_style ) : '' ); $of_text = ( isset( $this->acwc_languages['of_text'] ) ? $this->acwc_languages['of_text'] : '' ); $prompt_last = ( isset( $this->acwc_languages['prompt_last'] ) ? $this->acwc_languages['prompt_last'] : '' ); $piece_text = ( isset( $this->acwc_languages['piece_text'] ) ? $this->acwc_languages['piece_text'] : '' ); if ( $this->acwc_language == 'ru' || $this->acwc_language == 'ko' ) { if ( empty($this->acwc_keywords) ) { $this->acwc_prompt = $prompt_text . strval( $this->acwc_number_of_heading ) . $prompt_last . $this->acwc_preview_title . "."; } else { $keyword_text = ( isset( $this->acwc_languages['keyword_text'] ) ? sprintf( $this->acwc_languages['keyword_text'], $this->acwc_keywords ) : '' ); $this->acwc_prompt = $prompt_text . strval( $this->acwc_number_of_heading ) . $prompt_last . $this->acwc_preview_title . $keyword_text; } } elseif ( $this->acwc_language == 'zh' ) { if ( empty($this->acwc_keywords) ) { $this->acwc_prompt = $prompt_text . $this->acwc_preview_title . $of_text . strval( $this->acwc_number_of_heading ) . $piece_text . "."; } else { $keyword_text = ( isset( $this->acwc_languages['keyword_text'] ) ? sprintf( $this->acwc_languages['keyword_text'], $this->acwc_keywords ) : '' ); $this->acwc_prompt = $prompt_text . $this->acwc_preview_title . $of_text . strval( $this->acwc_number_of_heading ) . $piece_text . $keyword_text; } } elseif ( $this->acwc_language == 'ja' || $this->acwc_language == 'hi' || $this->acwc_language == 'tr' ) { if ( empty($this->acwc_keywords) ) { $this->acwc_prompt = $this->acwc_preview_title . $prompt_text . strval( $this->acwc_number_of_heading ) . $prompt_last . "."; } else { $keyword_text = ( isset( $this->acwc_languages['keyword_text'] ) ? sprintf( $this->acwc_languages['keyword_text'], $this->acwc_keywords ) : '' ); $this->acwc_prompt = $this->acwc_preview_title . $prompt_text . strval( $this->acwc_number_of_heading ) . $prompt_last . $keyword_text; } } else { if ( empty($this->acwc_keywords) ) { $this->acwc_prompt = strval( $this->acwc_number_of_heading ) . $prompt_text . $this->acwc_preview_title . "."; } else { $keyword_text = ( isset( $this->acwc_languages['keyword_text'] ) ? sprintf( $this->acwc_languages['keyword_text'], $this->acwc_keywords ) : '' ); $this->acwc_prompt = strval( $this->acwc_number_of_heading ) . $prompt_text . $this->acwc_preview_title . $keyword_text; } } if ( !empty($this->acwc_words_to_avoid) ) { $this->avoid_text = ( isset( $this->acwc_languages['avoid_text'] ) ? sprintf( $this->acwc_languages['avoid_text'], $this->acwc_words_to_avoid ) : '' ); $this->acwc_prompt = $this->acwc_prompt . $this->avoid_text; } if ( $this->acwc_language == 'ja' || $this->acwc_language == 'tr' ) { $this->acwc_intro = $this->acwc_preview_title . $this->intro_text; $this->acwc_conclusion = $this->acwc_preview_title . $this->conclusion_text; $this->acwc_tagline = $this->acwc_preview_title . $this->tagline_text; } else { if ( $this->acwc_language == 'ko' || $this->acwc_language == 'hi' || $this->acwc_language == 'ar' ) { $this->acwc_intro = $this->intro_text . $this->acwc_preview_title; $this->acwc_conclusion = $this->conclusion_text . $this->acwc_preview_title; $this->acwc_tagline = $this->acwc_preview_title . $this->tagline_text; } else { $this->acwc_intro = $this->intro_text . $this->acwc_preview_title; $this->acwc_conclusion = $this->conclusion_text . $this->acwc_preview_title; $this->acwc_tagline = $this->tagline_text . $this->acwc_preview_title; } } $this->acwc_cta = ( isset( $this->acwc_languages['mycta'] ) ? sprintf( $this->acwc_languages['mycta'], $this->acwc_preview_title, $this->acwc_target_url_cta ) : '' ); } public function sleep_request() { if($this->acwc_engine == 'gpt-3.5-turbo' || $this->acwc_engine == 'gpt-4' || $this->acwc_engine == 'gpt-4-32k'){ sleep($this->acwc_sleep); } } public function acwc_generator($step = 'heading') { /*Generate Heading*/ if($step == 'heading'){ $this->sleep_request(); if($this->acwc_modify_headings && $this->generate_continue){ $this->acwc_headings = sanitize_text_field( $_REQUEST["hfHeadings"] ); $this->acwc_result['next_step'] = 'content'; $this->acwc_result['data'] = $this->acwc_headings; $this->acwc_result['status'] = 'success'; } else{ if($this->acwc_engine == 'gpt-3.5-turbo' || $this->acwc_engine == 'gpt-4' || $this->acwc_engine == 'gpt-4-32k'){ $this->acwc_opts['prompt'] = $this->acwc_languages['heading_prompt_turbo'].' '.$this->acwc_prompt; } else{ $this->acwc_opts['prompt'] = $this->acwc_prompt; } $acwc_request = $this->acwc_request($this->acwc_opts); if($acwc_request['status'] == 'error'){ $this->acwc_result['status'] = 'error'; $this->acwc_result['msg'] = $acwc_request['msg']; $this->error_msg = $acwc_request['msg']; } else{ $acwc_response = $acwc_request['data']; $acwc_response = preg_replace('/\n$/', '', preg_replace('/^\n/', '', preg_replace('/[\r\n]+/', "\n", $acwc_response))); $acwc_response = preg_split("/\r\n|\n|\r/", $acwc_response); $acwc_response = preg_replace('/^\\d+\\.\\s/', '', $acwc_response); $acwc_response = preg_replace('/\\.$/', '', $acwc_response); $acwc_response = array_splice($acwc_response, 0, strval($this->acwc_number_of_heading)); $headings = array(); foreach($acwc_response as $item){ $headings[] = str_replace('"','', $item); } $this->acwc_headings = $headings; $this->acwc_result['next_step'] = 'content'; $this->acwc_result['data'] = implode('||', $headings); $this->acwc_result['status'] = 'success'; if ($this->acwc_modify_headings && !$this->generate_continue) { $this->acwc_result['next_step'] = 'modify_heading'; } $this->acwc_result['tokens'] += $acwc_request['tokens']; $this->acwc_result['length'] += $acwc_request['length']; } } } if($step == 'content'){ foreach ( $this->acwc_headings as $key => $value ) { $this->sleep_request(); $withstyle = $value . '. ' . $this->style_text . ', ' . $this->tone_text . '.'; if ( !empty(${$this->acwc_words_to_avoid}) ) { $withstyle = $value . '. ' . $this->style_text . ', ' . $this->tone_text . ', ' . $this->avoid_text . '.'; } if($this->acwc_engine == 'gpt-3.5-turbo' || $this->acwc_engine == 'gpt-4' || $this->acwc_engine == 'gpt-4-32k') { $this->acwc_opts['prompt'] = sprintf($this->acwc_languages['content_prompt_turbo'],$this->acwc_preview_title).' '.$withstyle; } else{ $this->acwc_opts['prompt'] = $withstyle; } $acwc_request = $this->acwc_request($this->acwc_opts); if($acwc_request['status'] == 'error'){ $this->acwc_result['status'] = 'error'; $this->acwc_result['msg'] = $acwc_request['msg']; $this->error_msg = $acwc_request['msg']; } else{ $acwc_response = $acwc_request['data']; $value = str_replace( '\\/', '', $value ); $value = str_replace( '\\', '', $value ); $value = trim( $value ); // we will add h tag if the user wants to $acwc_heading_id = 'acwc-'.sanitize_title($value); $this->acwc_toc_list[] = $value; if ( $this->acwc_heading_tag == "h1" ) { $result = "
" . $acwc_response . "
"; $this->acwc_result['content'] = $acwc_response.$this->acwc_result['content']; $this->acwc_result['tokens'] += $acwc_request['tokens']; $this->acwc_result['length'] += $acwc_request['length']; } } else{ $this->acwc_result['status'] = 'success'; } if($this->acwc_seo_meta_desc){ $this->acwc_result['next_step'] = 'seo'; } else{ $this->acwc_result['next_step'] = 'addition'; } } if($step == 'seo'){ $this->acwc_result['next_step'] = 'addition'; if($this->acwc_seo_meta_desc){ $this->sleep_request(); $meta_desc_prompt = ( isset( $this->acwc_languages['meta_desc_prompt'] ) && !empty($this->acwc_languages['meta_desc_prompt']) ? sprintf( $this->acwc_languages['meta_desc_prompt'], $this->acwc_preview_title ) : 'Write a meta description about: ' . $this->acwc_preview_title .'. Max: 155 characters'); if($this->acwc_engine == 'gpt-3.5-turbo' || $this->acwc_engine == 'gpt-4' || $this->acwc_engine == 'gpt-4-32k') { $this->acwc_opts['prompt'] = $this->acwc_languages['fixed_prompt_turbo'].' '.$meta_desc_prompt; } else{ $this->acwc_opts['prompt'] = $meta_desc_prompt; } $acwc_request = $this->acwc_request($this->acwc_opts); if($acwc_request['status'] == 'error'){ $this->acwc_result['status'] = 'error'; $this->acwc_result['msg'] = $acwc_request['msg']; $this->error_msg = $acwc_request['msg']; } else{ $acwc_response = $acwc_request['data']; $this->acwc_result['status'] = 'success'; $this->acwc_result['description'] = $acwc_response; $this->acwc_result['tokens'] += $acwc_request['tokens']; $this->acwc_result['length'] += $acwc_request['length']; } } else{ $this->acwc_result['status'] = 'success'; } } if($step == 'addition'){ if($this->acwc_add_keywords_bold){ if($this->acwc_keywords != ''){ if ( strpos( $this->acwc_keywords, ',' ) !== false ) { $keywords = explode( ",", $this->acwc_keywords ); } else { $keywords = array( $this->acwc_keywords ); } foreach ( $keywords as $keyword ) { $keyword = trim( $keyword ); $this->acwc_result['content'] = preg_replace( '/(?)(?)(?)(?)(?)(?)(?)(?)(?)\\b' . $keyword . '\\b(?![^<]*<\\/a>)(?![^<]*<\\/h[1-6]>)(?![^<]*<\\/strong>)(?![^<]*<\\/em>)(?![^<]*<\\/strong><\\/em>)(?![^<]*<\\/em><\\/strong>)/i', ''.$keyword.'', $this->acwc_result['content'] ); } } } if($this->acwc_target_url != '' && $this->acwc_anchor_text != ''){ $this->acwc_result['content'] = preg_replace( '/(?)(?)(?)(?)(?)(?)(?)(?)(?)\\b' . $this->acwc_anchor_text . '\\b(?![^<]*<\\/a>)(?![^<]*<\\/h[1-6]>)(?![^<]*<\\/strong>)(?![^<]*<\\/em>)(?![^<]*<\\/strong><\\/em>)(?![^<]*<\\/em><\\/strong>)/i', '' . $this->acwc_anchor_text . '', $this->acwc_result['content'], 1 ); } $this->acwc_result['status'] = 'success'; if($this->acwc_target_url_cta !== ''){ $this->sleep_request(); if($this->acwc_engine == 'gpt-3.5-turbo' || $this->acwc_engine == 'gpt-4' || $this->acwc_engine == 'gpt-4-32k') { $this->acwc_opts['prompt'] = $this->acwc_languages['fixed_prompt_turbo'].' '.$this->acwc_cta; } else{ $this->acwc_opts['prompt'] = $this->acwc_cta; } $acwc_request = $this->acwc_request($this->acwc_opts); if($acwc_request['status'] == 'error'){ $this->acwc_result['status'] = 'error'; $this->acwc_result['msg'] = $acwc_request['msg']; $this->error_msg = $acwc_request['msg']; } else{ $acwc_response = $acwc_request['data']; $acwc_response = "" . $acwc_response . "
"; if ( $this->acwc_cta_pos == "beg" ) { $this->acwc_result['content'] = preg_replace( '/(