<?php 

defined('ABSPATH') or die("You can't access this file directly.");

if ( ! function_exists( 'qcld_seohelp_render_modal' ) ) {
	function qcld_seohelp_render_modal() { // Linkbait Generator Modal //

		check_ajax_referer( 'seo-help', 'security');

		if ( ! current_user_can( 'manage_options' ) ) {
		    wp_send_json_error( esc_html( 'Unauthorized', 'seo-help' ) );
		    wp_die();
		}

		$title = isset($_POST['linkbait_title']) ? trim(sanitize_text_field(wp_unslash($_POST['linkbait_title']))) : '';
		$data = simplexml_load_file(qcld_seohelp_dir1.'/assets/data/data.xml'); //loading data from file
		$data = qcld_seohelp_xml2array($data->item); //getting data array
		$keys = array_rand($data, 5); //taking random 5 element from array
		?>
		<div id="title_Generator" class="modal">
			<!-- Modal content -->
			<div class="modal-content">
				<span class="close">×</span>
				<h3><?php esc_html_e( "LinkBait Title Generator", 'seo-help' ); ?></h3>
				<hr/>
				<div class="sm_shortcode_list">

					<div class="linkbait_single_field">
						<label style="width: 100px;display: inline-block;font-weight: bold;"><?php esc_html_e( "Subject", 'seo-help' ); ?></label><input type="text" style="width: 79%;" value="<?php echo esc_html($title); ?>" id="linkbait_subject" />
					</div>
					<hr />
					<div class="linkbait_single_field">

                        <div class="linkbait_choose_field_option">
                            <div>
                            <input id="linkbait_singular" type="radio" name="linkbait_filter" checked="checked" value="singular"><label for="linkbait_singular"><span><span></span></span><?php esc_html_e( "Singular Subject", 'seo-help' ); ?></label>
                            </div>
                            <div>
                                <input id="linkbait_plural" type="radio" name="linkbait_filter" value="plural">
                                <label for="linkbait_plural"><span><span></span></span><?php esc_html_e( "Plural Subject", 'seo-help' ); ?></label>
                            </div>
                            <div>
                                <input id="linkbait_openai" type="radio" name="linkbait_filter" value="openai">
                                <label for="linkbait_openai"><span><span></span></span><?php esc_html_e( "Open AI", 'seo-help' ); ?></label>
                            </div>
                        </div>


						<div>
							<img src="<?php echo esc_url(qcld_seohelp_assets_url.'/images/loader.gif'); ?>" id="linkbait_loading" style="float:right;margin-left:8px;margin-top: 11px;display:none"/>
							<input style="float:right" type="button" id="linkbait_generate" value="Re/Generate" />
						</div>
						<div style="clear:both"></div>
					</div>
					<hr/>
					<div class="linkbait_single_field">
						<?php 
							if( isset($title) && $title!=''){ //check if title exists
						?>
								
							<div id="linkbait_ajax_data">
							<h4><?php esc_html_e( "Select your title", 'seo-help' ); ?></h4>
								<?php 
									//checking if variable is empty array
									$cuntvar = array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
									
									if(!empty($data)){
									$flag = true;
									$skip = array(); //skip repeating element
									foreach($keys as $k=>$v){ 
									$skip[] = $v;
									$sugtitle = str_replace('####',$title,$data[$v]);
									$rvalue = array_rand($cuntvar);
									$sugtitle = str_replace('[#]',$cuntvar[$rvalue],$sugtitle);
									$sugtitle = stripslashes($sugtitle);
								?>
									
										<input id="<?php echo esc_attr($v); ?>" type="radio" name="linkbait_radio" value="<?php echo esc_html($sugtitle) ?>" <?php echo ($flag==true?'checked="checked"':'') ?>><label for="<?php echo esc_attr($v); ?>"><span><span></span></span><?php echo esc_html($sugtitle) ?></label>
									
								<?php
									$flag = false;
									}
									?>
									<input type="hidden" value="<?php echo esc_attr(implode(',',$skip)); ?>" id="linkbait_skip" name="linkbait_skip" />
									<input type="hidden" value="" id="linkbait_skip2" name="linkbait_skip2" />
									<input type="hidden" value="" id="linkbait_skip2" name="linkbait_skip2" />
								<?php 
									}
								?>

							  </div>
						<?php
							}else{
						?>
							
							<div id="linkbait_ajax_data">
								<h4 style="color:red"><?php esc_html_e( "You have to put Subject first! Then click Generate.", 'seo-help' ); ?></h4>	
							 </div>					
						<?php
							}
						?>
						  
					</div>
					
					<div class="linkbait_single_field qcld_seohelp_copy_msg" style="text-align:center">
						
						<button type="button" id="linkbait_add"><?php esc_html_e( "Copy Title", 'seo-help' ); ?></button>
					</div>
				</div>
			</div>

		</div>
		<?php
		wp_die();
	}
}
add_action( 'wp_ajax_qcld_seohelp_show_suggestion', 'qcld_seohelp_render_modal');
add_action('wp_ajax_nopriv_qcld_seohelp_show_suggestion', 'qcld_seohelp_render_modal');

if ( ! function_exists( 'qcld_seohelp_generate_modal' ) ) {
	function qcld_seohelp_generate_modal() { // Linkbait Generator Modalo //
		//this function run when click generate
		check_ajax_referer( 'seo-help', 'security');

		if ( ! current_user_can( 'manage_options' ) ) {
		    wp_send_json_error( esc_html( 'Unauthorized', 'seo-help' ) );
		    wp_die();
		}
		
		$title = isset($_POST['linkbait_title']) ? trim(sanitize_text_field(wp_unslash($_POST['linkbait_title']))) : '';
		$data = simplexml_load_file(qcld_seohelp_dir1.'/assets/data/data.xml');
		$filter = ( isset($_POST['linkbait_filter']) and !empty($_POST['linkbait_filter']) ) ? trim(sanitize_text_field(wp_unslash($_POST['linkbait_filter']))):'';
		$linkbait_skip = isset($_POST['linkbait_skip']) ? trim(sanitize_text_field(wp_unslash($_POST['linkbait_skip']))) :'';
		$linkbait_skip2 = isset($_POST['linkbait_skip2']) ? trim(sanitize_text_field(wp_unslash($_POST['linkbait_skip2']))) :'';
		
		
        if( $filter == 'google' ) {

            $source = "en";
     
            $target_text = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" .$source. "&tl=" .$source. "&dt=t&q=". rawurlencode($title);


            $arrContextOptions=array(
                "ssl"   =>array(
                    "verify_peer"       => false,
                    "verify_peer_name"  => false,
                ),
            );  
      
            $response = file_get_contents($target_text, false, stream_context_create($arrContextOptions));

            //$response 	= file_get_contents($target_text);
            $obj 		= json_decode($response,true);

            $target_keyword = ( isset($obj[0][0][0]) && !empty($obj[0][0][0]) ) ? $obj[0][0][0] : $title;


            $url = sprintf("http://suggestqueries.google.com/complete/search?client=chrome&hl=%s&q=%s", $source, urlencode($target_keyword));
            //$json = file_get_contents($url);


            $arrContextOptions=array(
                "ssl"   =>array(
                    "verify_peer"       => false,
                    "verify_peer_name"  => false,
                ),
            );  
      
            $json = file_get_contents($url, false, stream_context_create($arrContextOptions));
            $results = json_decode(utf8_encode($json));

            ?>
            <h4><?php esc_html_e( "Select your title", 'seo-help' ); ?></h4>
            <?php

            foreach ($results[1] as $key => $keywordResults){
              ?>
      
                <label for="<?php echo esc_attr($key); ?>"> <input id="<?php echo esc_attr($key); ?>" type="radio" name="linkbait_radio" value="<?php echo esc_attr($keywordResults) ?>" <?php echo ($key==0?'checked="checked"':'') ?>> <?php echo esc_attr($keywordResults) ?></label>
                
           <?php 
            } 
                     
            wp_die();

        }else if( $filter == 'openai' ){ 

            
			$OPENAI_API_KEY = get_option('qcld_seohelp_api_key');
			$ai_engines 	= get_option('qcld_seohelp_ai_engines') ? get_option('qcld_seohelp_ai_engines') : 'gpt-4o';
			$temperature 	= get_option('qcld_seohelp_ai_temperature') ? get_option('qcld_seohelp_ai_temperature') : 0;
			$ppenalty 		= get_option('qcld_seohelp_ai_ppenalty');
			$fpenalty 		= get_option('qcld_seohelp_ai_fpenalty');
			$prompt 		= "Write some Link Bait blog title for ". $title;

			if( $ai_engines == 'gpt-3.5-turbo' || $ai_engines == 'gpt-4' || $ai_engines == 'gpt-4o' || $ai_engines == 'gpt-4o-mini' || $ai_engines == 'gpt-4.1' || $ai_engines == 'gpt-4.1-mini' || $ai_engines == 'gpt-4.1-nano' || ( substr( $ai_engines, 0, 5 ) == 'gpt-4' ) || ( substr( $ai_engines, 0, 5 ) == 'gpt-5' ) || ( substr( $ai_engines, 0, 5 ) == 'gpt-6' ) || ( substr( $ai_engines, 0, 2 ) == 'o1' ) || ( substr( $ai_engines, 0, 2 ) == 'o3' ) || $ai_engines == 'chatgpt-4o-latest' || $ai_engines == 'gpt-4.5-preview' ){
                $gptkeyword = [];
                
	            $gptkeyword = array(
	                array(
	                    "role" => "user",
	                    "content" => $prompt 
	                )
	            );

	            $post_fields = array(
	                "model"         => $ai_engines,
	                "messages"      => $gptkeyword,
	                "temperature"   => ( float )$temperature
	            );

	            $url = 'https://api.openai.com/v1/chat/completions';
	            $args = array(
	                'method'  => 'POST', 
	                'headers' => array(
	                    'Content-Type'  => 'application/json',
	                    'Authorization' => 'Bearer ' . $OPENAI_API_KEY
	                ),
	                'body'    => json_encode($post_fields),
	                'timeout' => 45 // Adjust timeout as needed
	            );

	            $response = wp_remote_post( $url, $args );

	            if ( is_wp_error( $response ) ) {
	                $error_message = $response->get_error_message();
                    
                    printf(
                        esc_html( 'Something went wrong: %s', 'seo-help' ),
                        esc_html( $error_message )
                    );
	            } else {
	                $body = wp_remote_retrieve_body( $response );
	                $data = json_decode( $body );
	            }

	            $complete = isset($data->choices[0]->message->content) ? esc_attr($data->choices[0]->message->content) : '';

            }else{

	            $request_body = [
	                "prompt"     => $prompt,
	                "model"      => $ai_engines,
	                "temperature"=> (float) $temperature,
	                "presence_penalty" => (float) $ppenalty, 
	                "frequency_penalty" => (float) $fpenalty, 
	                "top_p"      => 1,
	                "best_of"    => 1,
	            ];

	            $url = "https://api.openai.com/v1/completions";
	            $args = array(
	                'body'    => json_encode( $request_body ),
	                'headers' => array(
	                    'Content-Type'  => 'application/json',
	                    'Authorization' => 'Bearer ' . $OPENAI_API_KEY, 
	                ),
	                'method'  => 'POST',
	                'timeout' => 45,
	            );

	            $response = wp_remote_post( $url, $args );

	            $complete = '';

	            if ( is_wp_error( $response ) ) {
	                $error_message = $response->get_error_message();
	                error_log( "OpenAI API Request Failed: $error_message" ); 
	                return esc_html( 'An API error occurred. Please try again later.', 'seo-help' );
	                wp_die();
	            } else {

	                $body_json = wp_remote_retrieve_body( $response );
	                $api_data  = json_decode( $body_json );

	                if ( isset( $api_data->error ) && !empty( $api_data->error ) ) {
	                    $error_message = isset( $api_data->error->message ) ? $api_data->error->message : 'Unknown API Error';
	                    return esc_html( $error_message ); 
	                    wp_die();
	                }
	                
	                $complete = isset( $api_data->choices[0]->text ) ? $api_data->choices[0]->text : '';
	                
	            }

            }

           // var_dump( $complete );
           // wp_die();

            ?>
            <h4><?php esc_html_e( "Select your title", 'seo-help' ); ?></h4>
            <?php

            if(!empty($complete)){
               $results = explode("\n", $complete );

	            foreach ($results as $key => $keywordResults){
	        ?>
	            <label for="<?php echo esc_attr($key); ?>"> <input id="<?php echo esc_attr($key); ?>" type="radio" name="linkbait_radio" value="<?php echo esc_attr($keywordResults) ?>" <?php echo ($key==0?'checked="checked"':'') ?>> <?php echo esc_attr($keywordResults) ?></label>
	                
	        <?php 

            	} 
            } 
                     
            wp_die();

		}else if($filter=='plural'){ // Check if Plural //
			$data = qcld_seohelp_xml2array($data->itemp); //Making array from object //
			$skip = $linkbait_skip; //getting keys for skipping element
			$skip = explode(',',$skip);
			if(is_array($skip) && !empty($skip)){ //check skip array not empty
				foreach($skip as $sk=>$sv){
					unset($data[$sv]); // unseting keys that previously displayed.
				}
			}else{
				$skip = array(); 
			}
			if(sizeof($data)<4) //checking data less then 5
			$keys = array_rand($data, sizeof($data));
			else
				$keys = array_rand($data, 4);
			
			$algo = qcld_seohelp_algorithm($title); //Collecting Second algorithm data //
			$skip2 = $linkbait_skip2; //getting keys for skipping element
			$skip2 = explode(',',$skip2);
			
			if(is_array($skip2) && !empty($skip2)){ //check skip array not empty
				foreach($skip2 as $sk2=>$sv2){
					unset($algo[$sv2]); // unseting keys that previously displayed.
				}
			}else{
				$skip2 = array(); 
			}
			
			$key2 = array_rand($algo);
			$skip2[] = $key2;
		} else { // Code for Singular //
			$data = qcld_seohelp_xml2array($data->item); //Making array from object //
			$skip = $linkbait_skip; //getting keys for skipping element
			$skip = explode(',',$skip);
			if(is_array($skip) && !empty($skip)){ //check skip array not empty
				foreach($skip as $sk=>$sv){
					unset($data[$sv]); // unseting keys that previously displayed.
				}
			}else{
				$skip = array(); 
			}
			//checking data less then 5
			if(sizeof($data)<5)
				$keys = array_rand($data, sizeof($data));
			else
				$keys = array_rand($data, 5);
		}
		
		if($title!=''){
			?>
					<h4><?php esc_html_e( "Select your title", 'seo-help' ); ?></h4>
					<?php 
						$cuntvar = array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
						if(!empty($data)){
						$flag = true;
						foreach($keys as $k=>$v){ //creating html element though array
						$skip[] = $v;
						$sugtitle = str_replace('####',$title,$data[$v]); //placeing title to right position
						$rvalue = array_rand($cuntvar);
						$sugtitle = str_replace('[#]',$cuntvar[$rvalue],$sugtitle);
						$sugtitle = stripslashes($sugtitle);
					?>
							<label for="<?php echo esc_attr($v); ?>"> <input id="<?php echo esc_attr($v); ?>" type="radio" name="linkbait_radio" value="<?php echo esc_html($sugtitle) ?>" <?php echo ($flag==true?'checked="checked"':'') ?>> <?php echo esc_attr($sugtitle) ?></label>
					<?php
						$flag = false;
						}
						if($filter=='plural' and $key2!=''){
						$sugtitle2 = str_replace('####',$title,$algo[$key2]);
						?>
						<label for="<?php echo esc_attr('sec2'); ?>"><input id="<?php echo esc_attr('sec2'); ?>" type="radio" name="linkbait_radio" value="<?php echo esc_attr($sugtitle2) ?>"> <?php echo esc_attr($sugtitle2) ?></label>
					<?php
						}
						?>
						<input type="hidden" value="<?php //echo esc_html(implode(',',$skip)); ?>" id="linkbait_skip" name="linkbait_skip" />
						<input type="hidden" value="<?php //echo esc_html(implode(',',$skip2)); ?>" id="linkbait_skip2" name="linkbait_skip2" />
						<?php
						
						}else{
						?>
							<p style="color:red"><?php esc_html_e( "No Data Found!", 'seo-help' ); ?></p>
						<?php
						}
					?>
			<?php
				}else{
					echo esc_html('No Subject Found!', 'seo-help');
				}
			?>
		<?php
		wp_die();
	}
}
add_action( 'wp_ajax_qcld_seohelp_generate_suggestion', 'qcld_seohelp_generate_modal');
add_action('wp_ajax_nopriv_qcld_seohelp_generate_suggestion', 'qcld_seohelp_generate_modal');



/**********************************
 * Broken link checking by ajax
 **********************************/

add_action('wp_ajax_qcld_seohelp_broken_link_checking_by_ajax', 'qcld_seohelp_broken_link_checking_by_ajax');
add_action('wp_ajax_nopriv_qcld_seohelp_broken_link_checking_by_ajax', 'qcld_seohelp_broken_link_checking_by_ajax');

add_action('wp_ajax_qcld_seohelp_start_crawler', 'qcld_seohelp_start_crawler_ajax');
function qcld_seohelp_start_crawler_ajax() {
    check_ajax_referer('seo-help', 'nonce');
    if (!current_user_can('manage_options')) {
        wp_send_json_error(array('message' => 'Unauthorized'));
    }

    $id = isset($_POST['id']) ? intval($_POST['id']) : 0;
    if (!$id) {
        wp_send_json_error(array('message' => 'Invalid Scan ID'));
    }

    // Capture the output of the existing function which echoes a success message
    ob_start();
    qcld_seohelp_simple_broken_link_check_scan_start_crawler($id);
    $output = ob_get_clean();

    wp_send_json_success(array('message' => strip_tags($output)));
}
if ( ! function_exists( 'qcld_seohelp_broken_link_checking_by_ajax' ) ) {
	function qcld_seohelp_broken_link_checking_by_ajax(){

		check_ajax_referer( 'seo-help', 'security');

		if ( ! current_user_can( 'manage_options' ) ) {
		    wp_send_json_error( esc_html( 'Unauthorized', 'seo-help' ) );
		    wp_die();
		}
	    
	    $output = '';
	    $output.= '<table class="form-table qcld_seohelp_link_check">';
	    $output.= '<thead>';
	    $output.= '<tr>';
	    $output.='<th>'.esc_html('Chunk', 'seo-help').'</th><th> '.esc_html('Link URL', 'seo-help').' </th><th> '.esc_html('Status', 'seo-help').' </th><th> '.esc_html('Content', 'seo-help').' </th>';
	    $output.= '</tr>';
	    $output.= '</thead>';
	    //we use the WP wp_remote function
	         
	    // WP_Query arguments
		$args = array (
		  	'post_type'        	=> array('page', 'post'),
		    'posts_per_page'   	=> -1,
	    	'post_status' 		=> 'publish',
		);

		// The Query
		$query = new WP_Query( $args );

		// The Loop
	    if ($query->have_posts()) {
	        while ($query->have_posts()) {
	            $query->the_post();

	            $content = get_the_content(get_the_ID());
	            if (preg_match_all('/(<a[^>]+href=["|\'](.+)["|\'][^>]*>)(.*)<\/a>/isUu', $content, $matches, PREG_SET_ORDER) > 0) {
	            	foreach ($matches as $match) {

	            		$response = wp_remote_get($match[2], array('timeout' => 20));
	            		$response_code = wp_remote_retrieve_response_code($response);
	            		
	            		 if ($response_code == 300 || $response_code == 301 || $response_code == 302 || $response_code == 303 || $response_code == 305 || $response_code == 307 || $response_code == 308 || $response_code == 400 || $response_code == 401 || $response_code == 402 || $response_code == 403 || $response_code == 404 || $response_code == 405 || $response_code == 406 || $response_code == 407 || $response_code == 408 || $response_code == 409 || $response_code == 410 || $response_code == 411 || $response_code == 412 || $response_code == 414 || $response_code == 415 || $response_code == 416 || $response_code == 417 || $response_code == 420 || $response_code == 422 || $response_code == 423 || $response_code == 424 || $response_code == 450 || $response_code == 500 || $response_code == 501 || $response_code == 502 || $response_code == 503 || $response_code == 505 ||  $response_code == 506 ||  $response_code == 507 ||  $response_code == 509 ||  $response_code == 510 ||  $response_code == 999 ) {
			                //link must be changed or is no longer valid
			                $output.= '<tr><td>';
			                $output .= $match[0];
			                $output.= '</td>';
			                $output.= '<td>';
			                $output.= $match[2];
			                $output.= '</td>';
			                $output.= '<td style="color:red">';
			                $errors_pages = '( <a class="qcld_help_links" href="admin.php?page=qcld-seo-help-section#qcld_seohelp_tab-555" target="_blank">?</a> )';
			                $output.= $response_code. ' '.$errors_pages.'';
			                $output.= '</td><td>';
			                $editstring = get_edit_post_link(get_the_ID());
	                		$output .= the_title('<a href="' . $editstring . '">', '</a>', false);
			                $output.= '</td></tr>';
			            }

			        }
	            }
	           
	        }
	    } else {
	        // no posts found
	        $output.='<tr><td>'.esc_html('No Broken Links found!', 'seo-help').'</td></tr>';
	    }
	    $output.= '</table>';

	    wp_reset_postdata();
	    $response = array( 'html' => $output );
	    echo wp_send_json($response);
	    wp_die();

	}
}

/**********************************
 * Broken sld link checking by ajax
 **********************************/

add_action('wp_ajax_qcld_seohelp_broken_sld_link_checking_by_ajax', 'qcld_seohelp_broken_sld_link_checking_by_ajax');
add_action('wp_ajax_nopriv_qcld_seohelp_broken_sld_link_checking_by_ajax', 'qcld_seohelp_broken_sld_link_checking_by_ajax');
if ( ! function_exists( 'qcld_seohelp_broken_sld_link_checking_by_ajax' ) ) {
	function qcld_seohelp_broken_sld_link_checking_by_ajax(){

		check_ajax_referer( 'seo-help', 'security');

		if ( ! current_user_can( 'manage_options' ) ) {
		    wp_send_json_error( esc_html( 'Unauthorized', 'seo-help' ) );
		    wp_die();
		}
		
	    $output = '';
	    $output.= '<table class="form-table qcld_seohelp_link_check">';
	    $output.= '<thead>';
	    $output.= '<tr>';
	    $output.= '<th> '.esc_html('Link URL', 'seo-help').' </th><th> '.esc_html('Status', 'seo-help').' </th><th> '.esc_html('Content', 'seo-help').' </th>';
	    $output.= '</tr>';
	    $output.= '</thead>';
	    //we use the WP wp_remote function
	         
	    // WP_Query arguments
		$args = array (
		  	'post_type'        => 'sld',
		    'posts_per_page'   => -1,
		);

		// The Query
		$query = new WP_Query( $args );	

		// The Loop
	    if ($query->have_posts()) {
	        while ($query->have_posts()) {
	            $query->the_post();


	            $datas = get_post_meta(get_the_ID(), 'qcopd_list_item01');
	            //	print_r($datas);wp_die();
	            $output.= '';

	            foreach($datas as $data){


	            			$link = trim($data['qcopd_item_link']);
	            			
			            	$response = wp_remote_get($link, array('timeout' => 20));
	            			$response_code = wp_remote_retrieve_response_code($response);

				            //link must be changed or is no longer valid
				            // 300, 301, 302, 303, 305, 307, 308, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 414, 415, 416, 417, 420, 422, 423, 424, 450, 500, 501, 502, 503, 504, 505, 506, 507, 509, 510, 999
				            if ($response_code == 300 || $response_code == 301 || $response_code == 302 || $response_code == 303 || $response_code == 305 || $response_code == 307 || $response_code == 308 || $response_code == 400 || $response_code == 401 || $response_code == 402 || $response_code == 403 || $response_code == 404 || $response_code == 405 || $response_code == 406 || $response_code == 407 || $response_code == 408 || $response_code == 409 || $response_code == 410 || $response_code == 411 || $response_code == 412 || $response_code == 414 || $response_code == 415 || $response_code == 416 || $response_code == 417 || $response_code == 420 || $response_code == 422 || $response_code == 423 || $response_code == 424 || $response_code == 450 || $response_code == 500 || $response_code == 501 || $response_code == 502 || $response_code == 503 || $response_code == 505 ||  $response_code == 506 ||  $response_code == 507 ||  $response_code == 509 ||  $response_code == 510 ||  $response_code == 999 ) {
				                $output.= '<tr><td>';
				               
				                $output.= '<a href="'.$link.'" target="_blank">'.$link.'</a>';
				                $output.= '</td>';
				                $output.= '<td style="color:red">';
				                $errors_pages = '( <a class="qcld_help_links" href="admin.php?page=qcld-seo-help-section#qcld_seohelp_tab-555" target="_blank">?</a> )';
				                $output.= $response_code. ' '.$errors_pages.'';
				                $output.= '</td><td>';
			                	$editstring = get_edit_post_link(get_the_ID());
	                			$output .= the_title('<a href="' . $editstring . '">', '</a>', false);
				                $output.= '</td></tr>';
				            }

		        }
	           
	        }
	    } else {
	        // no posts found
	        $output.='<tr><td>'.esc_html('No Broken Links found!', 'seo-help').'</td></tr>';
	    }
	    $output.= '</table>';

	    wp_reset_postdata();
	    $response = array( 'html' => $output );
	    echo wp_send_json($response);
	    wp_die();

	}
}



add_action( 'wp_ajax_qcldseohelp_keyword_suggestion_content', 'qcldseohelp_keyword_suggestion_content' );
add_action('wp_ajax_nopriv_qcldseohelp_keyword_suggestion_content', 'qcldseohelp_keyword_suggestion_content');
if ( ! function_exists( 'qcldseohelp_keyword_suggestion_content' ) ) {
    function qcldseohelp_keyword_suggestion_content(){

        check_ajax_referer( 'seo-help', 'security');

        if ( ! current_user_can( 'manage_options' ) ) {
            wp_send_json_error( esc_html( 'Unauthorized', 'seo-help' ) );
            wp_die();
        }

        set_time_limit(1000);

        $OPENAI_API_KEY                     = get_option('qcld_seohelp_api_key');
        $ai_engines                         = get_option('qcld_seohelp_ai_engines') ? get_option('qcld_seohelp_ai_engines') : 'gpt-4o';
        $temperature                        = get_option('qcld_seohelp_ai_temperature') ? get_option('qcld_seohelp_ai_temperature') : 0;
        $ppenalty                           = get_option('qcld_seohelp_ai_ppenalty');
        $fpenalty                           = get_option('qcld_seohelp_ai_fpenalty');

        $qcld_article_text                  = isset($_POST['keyword'])                          ? sanitize_text_field(wp_unslash( $_POST['keyword'] )) : '';
        $keyword_number                     = isset( $_POST['keyword_number'] )                 ? sanitize_text_field(wp_unslash( $_POST['keyword_number'] )) : '';
        $qcld_article_language              = isset($_POST['qcld_article_language'])            ? sanitize_text_field(wp_unslash( $_POST['qcld_article_language'] )) : '';
        $qcld_article_number_of_heading     = isset($_POST['qcld_article_number_of_heading'])   ? sanitize_text_field(wp_unslash( $_POST['qcld_article_number_of_heading'] )) : '';
        $qcld_article_heading_tag           = isset($_POST['qcld_article_heading_tag'])         ? sanitize_text_field(wp_unslash( $_POST['qcld_article_heading_tag'] )) : '';
        $qcld_article_heading_style         = isset($_POST['qcld_article_heading_style'])       ? sanitize_text_field(wp_unslash( $_POST['qcld_article_heading_style'] )) : '';
        $qcld_article_heading_tone          = isset($_POST['qcld_article_heading_tone'])        ? sanitize_text_field(wp_unslash( $_POST['qcld_article_heading_tone'] )) : '';
        $qcld_article_heading_img           = isset($_POST['qcld_article_heading_img'])         ? sanitize_text_field(wp_unslash( $_POST['qcld_article_heading_img'] )) : '';
        $qcld_article_heading_tagline       = isset($_POST['qcld_article_heading_tagline'])     ? sanitize_text_field(wp_unslash( $_POST['qcld_article_heading_tagline'] )) : '';
        $qcld_article_heading_intro         = isset($_POST['qcld_article_heading_intro'])       ? sanitize_text_field(wp_unslash( $_POST['qcld_article_heading_intro'] )) : '';
        $qcld_article_heading_conclusion    = isset($_POST['qcld_article_heading_conclusion'])  ? sanitize_text_field(wp_unslash( $_POST['qcld_article_heading_conclusion'] )) : '';
        $qcld_article_label_anchor_text     = isset($_POST['qcld_article_label_anchor_text'])   ? sanitize_text_field(wp_unslash( $_POST['qcld_article_label_anchor_text'] )) : '';
        $qcld_article_target_url            = isset($_POST['qcld_article_target_url'])          ? sanitize_text_field(wp_unslash( $_POST['qcld_article_target_url'] )) : '';
        $qcld_article_target_label_cta      = isset($_POST['qcld_article_target_label_cta'])    ? sanitize_text_field(wp_unslash( $_POST['qcld_article_target_label_cta'] )) : '';
        $qcld_article_cta_pos               = isset($_POST['qcld_article_cta_pos'])             ? sanitize_text_field(wp_unslash( $_POST['qcld_article_cta_pos'] )) : '';
        $qcld_article_label_keywords        = isset($_POST['qcld_article_label_keywords'])      ? sanitize_text_field(wp_unslash( $_POST['qcld_article_label_keywords'] )) : '';
        $qcld_article_label_word_to_avoid   = isset($_POST['qcld_article_label_word_to_avoid']) ? sanitize_text_field(wp_unslash( $_POST['qcld_article_label_word_to_avoid'] )) : '';
        $qcld_article_label_keywords_bold   = isset($_POST['qcld_article_label_keywords_bold']) ? intval( sanitize_text_field(wp_unslash($_POST['qcld_article_label_keywords_bold'] ))) : '';
        $qcld_article_heading_faq           = isset($_POST['qcld_article_heading_faq'])         ? intval( sanitize_text_field(wp_unslash($_POST['qcld_article_heading_faq'] ))) : '';

        $img_size                           = isset($_POST['qcld_article_img_size'])            ? sanitize_text_field(wp_unslash( $_POST['qcld_article_img_size'] )) : '';
        //$img_size = "512x512";

        if(!session_start()){
          session_start();
        }

        $step = isset( $_POST['step'] ) && !empty($_POST['step']) ? sanitize_text_field( $_POST['step'] ) : '';
        $content = isset( $_POST['content'] ) && !empty($_POST['content']) ? sanitize_text_field( $_POST['content'] ) : '';

        if ( empty($qcld_article_language) ) {
            $qcld_article_language = "en";
        }
        // if number of heading is not set, set it to 5
        if ( empty($qcld_article_number_of_heading) ) {
            $qcld_article_number_of_heading = 5;
        }
        // if writing style is not set, set it to descriptive
        if ( empty($qcld_article_heading_style) ) {
            $qcld_article_heading_style = "infor";
        }
        // if writing tone is not set, set it to assertive
        if ( empty($qcld_article_heading_tone) ) {
            $qcld_article_heading_tone = "formal";
        }
        // if heading tag is not set, set it to h2
        if ( empty($qcld_article_heading_tag) ) {
            $qcld_article_heading_tag = "h2";
        }
        $avoid_text = '';

        if($step == 'process'){

            $qcld_article_text_prompt = "You are an SEO expert. Write an article about '".$qcld_article_text."'. The article should have at least 1200 words and each paragraph should have 4-6 sentences. The article should have $qcld_article_number_of_heading heading. Add a tag for each heading with $qcld_article_heading_tag . The writing style should be $qcld_article_heading_style. The writing tone should be $qcld_article_heading_tone. The language should be $qcld_article_language.";

            if($qcld_article_label_anchor_text  !== "" ){
                $qcld_article_text_prompt .= " Use $qcld_article_label_anchor_text to link to $qcld_article_target_url. Add a Call to action linking to $qcld_article_target_label_cta and put it at the $qcld_article_cta_pos."; 
            }

            if($qcld_article_label_keywords  !== "" ){
                $qcld_article_text_prompt .= " Use the following keywords in the article: $qcld_article_label_keywords.";
            }
            if($qcld_article_label_word_to_avoid  !== "" ){
                $qcld_article_text_prompt .= "Avoid the following keywords: $qcld_article_label_word_to_avoid.";
            }

            if($qcld_article_label_keywords_bold  == "1" ){
                $qcld_article_text_prompt .= "Make the Keywords bold.";
            }

            if($qcld_article_heading_tagline  == "1" ){
                $qcld_article_text_prompt .= "Add a tag line."; 
            }
            if($qcld_article_heading_intro  == "1" ){
                $qcld_article_text_prompt .= "Add an Introduction for the article.";
            }
            if($qcld_article_heading_conclusion  == "1" ){
                $qcld_article_text_prompt .= "Add a conclusion for the article.";
            }
            if($qcld_article_heading_faq  == "1" ){
                //$qcld_article_text_prompt .= "Include a set of relevant FAQs in the article with FAQ schema format.";
                $qcld_article_text_prompt .= "Include a set of relevant FAQs in the article with FAQ in HTML accordion format";
            }


            $article_humanize_text = "";

            if(isset($_SESSION['qcld_article_text_prompt']) && !empty($_SESSION['qcld_article_text_prompt'])){
                unset($_SESSION['qcld_article_text_prompt']);
                unset($_SESSION['img_size']);
                unset($_SESSION['qcld_article_heading_img']);
                unset($_SESSION['allresults']);
            }

            $_SESSION['qcld_article_text_prompt']       = $qcld_article_text_prompt;
            $_SESSION['img_size']                       = $img_size;
            $_SESSION['qcld_article_heading_img']       = $qcld_article_heading_img;
            $_SESSION['allresults']                     = '';

            wp_send_json( [ 'status' => 'success', 'oldStep' => $step, 'keywords' => '' ] );
            wp_die();

        }



        $result_data = '';

        if(!empty($qcld_article_text)){

            $qcld_ai_settings_open_ai = get_option('qcld_ai_settings_open_ai');

            /*Generate Content*/
            if($step == 'content'){

                $qcld_article_text_prompt    = isset($_SESSION['qcld_article_text_prompt']) ? $_SESSION['qcld_article_text_prompt'] : '';

                $complete  = apply_filters('qcld_seohelp_ai_content_settings_processing_data_function', $qcld_article_text_prompt );

                $allresults   = !empty( $complete ) ? trim( $complete ) : '';

                if(isset($_SESSION['allresults'])){
                  unset($_SESSION['allresults']);
                  $_SESSION['allresults']     = $allresults;
                }
                
                $Parsedown = new Parsedown();
                        
                $allresults = !empty( $allresults ) ? $Parsedown->text( $allresults ) : $allresults;

                wp_send_json( [ 'status' => 'success', 'oldStep' => $step, 'keywords' => $allresults ] );
                wp_die();

            }
            
            // if add image is checked then we should send api request to get image

            $qcld_ai_settings_open_ai = get_option('qcld_ai_settings_open_ai');
            
            if ( $qcld_article_heading_img == "1"  && $step == 'image' ) {

                $allresults       = isset($_SESSION['allresults']) ? $_SESSION['allresults'] : '';

                $qcld_article_image_prompt = "Generate a relevant, realistic Image about ".$qcld_article_text;

                $imgresult  = apply_filters('qcld_seohelp_ai_article_heading_img',  $qcld_article_image_prompt, $img_size );

                // get half of qcld_article_number_of_heading and insert image in the middle
                $half = intval( $qcld_article_number_of_heading ) / 2;
                $half = round( $half );
                $half = $half - 1;
                // use qcld_article_heading_tag to add heading tag to image
                $allresults = explode( "</" . $qcld_article_heading_tag . ">", $allresults );
                $allresults[$half] = $allresults[$half] . $imgresult;
                $allresults = implode( "</" . $qcld_article_heading_tag . ">", $allresults );
                    
                $Parsedown = new Parsedown();
                
                $allresults = !empty( $allresults ) ? $Parsedown->text( $allresults ) : $allresults;

                wp_send_json( [ 'status' => 'success', 'oldStep' => $step, 'keywords' => $allresults ] );
                wp_die();

            } else {
          
                wp_send_json( [ 'status' => 'complete', 'oldStep' => $step, 'keywords' => $allresults ] );
                wp_die();
            }


        }
    
        wp_send_json( [ 'status' => 'complete', 'oldStep' => $step, 'keywords' => $result_data ] );
        wp_die();
        
        // var_dump($dataresponse);wp_die();

    }
}


add_action( 'wp_ajax_qcldseohelp_keyword_suggestion_tag', 'qcldseohelp_keyword_suggestion_tag' );
add_action( 'wp_ajax_nopriv_qcldseohelp_keyword_suggestion_tag', 'qcldseohelp_keyword_suggestion_tag' );

if ( ! function_exists( 'qcldseohelp_keyword_suggestion_tag' ) ) {
    function qcldseohelp_keyword_suggestion_tag(){

    	check_ajax_referer( 'seo-help', 'security');

    	if ( ! current_user_can( 'manage_options' ) ) {
    	    wp_send_json_error( esc_html( 'Unauthorized', 'seo-help' ) );
    	    wp_die();
    	}

        $keyword        = isset($_POST['keyword'])          ? sanitize_text_field(wp_unslash($_POST['keyword'])) : '';
        $toolLanguage   = isset($_POST['selectedlanguage']) ? sanitize_text_field(wp_unslash($_POST['selectedlanguage'])) : '';
        $targetLanguage = isset($_POST['selectedlanguage']) ? sanitize_text_field(wp_unslash($_POST['selectedlanguage'])) : '';
        $toolCountry    = isset($_POST['selectedCountry'])  ? sanitize_text_field(wp_unslash($_POST['selectedCountry'])) : '';
        // $security    = sanitize_text_field($_POST['security']);

        $source="en";

        session_start();

        if(isset($_SESSION['qcld_targetlanguage'])){
            unset($_SESSION['qcld_targetlanguage']);
        }
        $_SESSION['qcld_targetlanguage'] = $targetLanguage;




        $OPENAI_API_KEY     = get_option('qcld_seohelp_api_key');
        $gemini_api_key     = get_option('qcld_gemini_api_key');

        if( !empty( $OPENAI_API_KEY  ) || !empty( $gemini_api_key  ) ){

	        $prompt_keywordsuggetions = apply_filters( 'qcld_prompt_keywordsuggetions', "Give me up to 15 SEO optimized keyword suggestions for the following text for my blog article: ".$keyword.". Respond with only comma separated keywords and nothing else." );

	        $results  = apply_filters('qcld_seohelp_ai_content_settings_processing_data_function', $prompt_keywordsuggetions );

	        $results_data = '';
	        if(!empty($results)){
	        	$results = explode(",",$results);
		        foreach ($results as $key => $keywordResultss){
		          
		            $results_data.= '<br><input type="checkbox" id="keywordsuggetions_'.esc_attr($key).'" class="form-check-input"  value="'.esc_attr($keywordResultss).'"/><label for="keywordsuggetions_'.esc_attr($key).'" class="form-check-label">'.$keywordResultss.'</label>';
		            
		        }

	        }
	        
	        wp_send_json(['status'=> 'success','keywords'=> $results_data]);
	        wp_die();

        }




 
        $target_text = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" .$source. "&tl=" .$targetLanguage. "&dt=t&q=". rawurlencode($keyword);

        //$response = file_get_contents($target_text);

        $arrContextOptions=array(
            "ssl"   =>array(
                "verify_peer"       => false,
                "verify_peer_name"  => false,
            ),
        );  
  
        $response = file_get_contents($target_text, false, stream_context_create($arrContextOptions));
        $obj 	  =	json_decode($response,true);

        $target_keyword = ( isset($obj[0][0][0]) && !empty($obj[0][0][0]) ) ? $obj[0][0][0] : $keyword;

        $url = sprintf("http://suggestqueries.google.com/complete/search?client=chrome&hl=%s&gl=%s&q=%s", $toolLanguage, $toolCountry, urlencode($target_keyword));
        //$json = file_get_contents($url);

        $arrContextOptions=array(
            "ssl"   =>array(
                "verify_peer"       => false,
                "verify_peer_name"  => false,
            ),
        );  
  
        $json = file_get_contents($url, false, stream_context_create($arrContextOptions));
        //$results = json_decode(utf8_encode($json));
        $results = json_decode($json);

        $results_data = '';
        if(!empty($results[1])){
	        foreach ($results[1] as $key => $keywordResultss){
	          
	            $results_data.= '<br><input type="checkbox" id="keywordsuggetions_'.esc_attr($key).'" class="form-check-input"  value="'.esc_attr($keywordResultss).'"/><label for="keywordsuggetions_'.esc_attr($key).'" class="form-check-label">'.$keywordResultss.'</label>';
	            
	        }

        }

        
        wp_send_json(['status'=> 'success','keywords'=> $results_data]);
        wp_die();
        // var_dump($dataresponse); wp_die();

    }
}

if ( ! function_exists( 'qcld_seohelp_add_tags_to_pages' ) ) {
    function qcld_seohelp_add_tags_to_pages() {
        register_taxonomy_for_object_type( 'post_tag', 'page' );
    }
}
add_action( 'init', 'qcld_seohelp_add_tags_to_pages');

add_action('wp_ajax_qcld_seohelp_add_ontag', 'qcld_seohelp_add_ontag' );
if ( ! function_exists( 'qcld_seohelp_add_ontag' ) ) {
    function qcld_seohelp_add_ontag (){

    	check_ajax_referer( 'seo-help', 'security');

    	if ( ! current_user_can( 'manage_options' ) ) {
    	    wp_send_json_error( esc_html( 'Unauthorized', 'seo-help' ) );
    	    wp_die();
    	}
       
        $post_id = isset($_POST['postid']) ? sanitize_text_field(wp_unslash( $_POST['postid'] )) : '';
        $keywordkeys = isset($_POST['keywordkeys']) ? maybe_unserialize($_POST['keywordkeys']) : '';

        wp_set_post_tags( $post_id, $keywordkeys, true);

        //var_dump($keywordkeys);
        $result_data = esc_html('Tag Successfully Submitted. Are you sure you want to refresh the page? Any unsaved changes will be lost.', 'seo-help');
        wp_send_json( [ 'status' => 'success', 'keywords' => $result_data ] );
        wp_die();
    }
}

add_action( 'wp_ajax_qcld_seohelp_save_draft_post_extra', 'qcld_seohelp_save_draft_post' );
add_action( 'wp_ajax_nopriv_qcld_seohelp_save_draft_post_extra', 'qcld_seohelp_save_draft_post' );
if ( ! function_exists( 'qcld_seohelp_save_draft_post' ) ) {
    function qcld_seohelp_save_draft_post(){

        check_ajax_referer( 'seo-help', 'security');

        if ( ! current_user_can( 'manage_options' ) ) {
            wp_send_json_error( esc_html( 'Unauthorized', 'seo-help' ) );
            wp_die();
        }

        $qcld_seohelp_result = array(
            'status' => 'error',
            'msg'    => esc_html('Something went wrong', 'seo-help' ),
        );
        
        if ( isset( $_POST['title'] ) && !empty($_POST['title']) && isset( $_POST['content'] ) && !empty($_POST['content']) ) {

            $qcld_seohelp_allowed_html_content_post = wp_kses_allowed_html( 'post' );
            $qcld_seohelp_title     = isset($_POST['title']) ? sanitize_text_field(wp_unslash( $_POST['title'] )) : '';
            $qcld_seohelp_content   = wp_kses( $_POST['content'], $qcld_seohelp_allowed_html_content_post );
            $qcld_seohelp_post_id   = wp_insert_post( array(
                'post_title'    => $qcld_seohelp_title,
                'post_content'  => $qcld_seohelp_content,
                ) 
            );
            
            if ( !is_wp_error( $qcld_seohelp_post_id ) ) {
                if ( array_key_exists( 'qcld_seohelp_settings', $_POST ) ) {
                    update_post_meta( $qcld_seohelp_post_id, 'qcld_seohelp_meta_key', sanitize_text_field(wp_unslash($_POST['qcld_seohelp_settings'])) );
                }
                if ( array_key_exists( 'qcld_seohelp_language', $_POST ) ) {
                    update_post_meta( $qcld_seohelp_post_id, 'qcld_seohelp_language', sanitize_text_field(wp_unslash($_POST['qcld_seohelp_language'])) );
                }
                if ( array_key_exists( 'qcld_seohelp_preview_title', $_POST ) ) {
                    update_post_meta( $qcld_seohelp_post_id, 'qcld_seohelp_preview_title', sanitize_text_field(wp_unslash($_POST['qcld_seohelp_preview_title'])) );
                }
                if ( array_key_exists( 'qcld_seohelp_number_of_heading', $_POST ) ) {
                    update_post_meta( $qcld_seohelp_post_id, 'qcld_seohelp_number_of_heading', sanitize_text_field(wp_unslash($_POST['qcld_seohelp_number_of_heading'])) );
                }
                if ( array_key_exists( 'qcld_seohelp_heading_tag', $_POST ) ) {
                    update_post_meta( $qcld_seohelp_post_id, 'qcld_seohelp_heading_tag', sanitize_text_field(wp_unslash($_POST['qcld_seohelp_heading_tag'])) );
                }
                if ( array_key_exists( 'qcld_seohelp_writing_style', $_POST ) ) {
                    update_post_meta( $qcld_seohelp_post_id, 'qcld_seohelp_writing_style', sanitize_text_field(wp_unslash($_POST['qcld_seohelp_writing_style'])) );
                }
                if ( array_key_exists( 'qcld_seohelp_writing_tone', $_POST ) ) {
                    update_post_meta( $qcld_seohelp_post_id, 'qcld_seohelp_writing_tone', sanitize_text_field(wp_unslash($_POST['qcld_seohelp_writing_tone'])) );
                }
                if ( array_key_exists( 'qcld_seohelp_modify_headings', $_POST ) ) {
                    update_post_meta( $qcld_seohelp_post_id, 'qcld_seohelp_modify_headings', sanitize_text_field(wp_unslash($_POST['qcld_seohelp_modify_headings'])) );
                }
                if ( array_key_exists( 'qcld_seohelp_add_img', $_POST ) ) {
                    update_post_meta( $qcld_seohelp_post_id, 'qcld_seohelp_add_img', sanitize_text_field(wp_unslash($_POST['qcld_seohelp_add_img'])) );
                }
                if ( array_key_exists( 'qcld_seohelp_add_tagline', $_POST ) ) {
                    update_post_meta( $qcld_seohelp_post_id, 'qcld_seohelp_add_tagline', sanitize_text_field(wp_unslash($_POST['qcld_seohelp_add_tagline'])) );
                }
                if ( array_key_exists( 'qcld_seohelp_add_intro', $_POST ) ) {
                    update_post_meta( $qcld_seohelp_post_id, 'qcld_seohelp_add_intro', sanitize_text_field(wp_unslash($_POST['qcld_seohelp_add_intro'])) );
                }
                if ( array_key_exists( 'qcld_seohelp_add_conclusion', $_POST ) ) {
                    update_post_meta( $qcld_seohelp_post_id, 'qcld_seohelp_add_conclusion', sanitize_text_field(wp_unslash($_POST['qcld_seohelp_add_conclusion'])) );
                }
                if ( array_key_exists( 'qcld_seohelp_anchor_text', $_POST ) ) {
                    update_post_meta( $qcld_seohelp_post_id, 'qcld_seohelp_anchor_text', sanitize_text_field(wp_unslash($_POST['qcld_seohelp_anchor_text'])) );
                }
                if ( array_key_exists( 'qcld_seohelp_target_url', $_POST ) ) {
                    update_post_meta( $qcld_seohelp_post_id, 'qcld_seohelp_target_url', sanitize_text_field(wp_unslash($_POST['qcld_seohelp_target_url'])) );
                }
                if ( array_key_exists( 'qcld_seohelp_generated_text', $_POST ) ) {
                    update_post_meta( $qcld_seohelp_post_id, 'qcld_seohelp_generated_text', sanitize_text_field(wp_unslash($_POST['qcld_seohelp_generated_text'])) );
                }
                // qcld_seohelp_cta_pos
                if ( array_key_exists( 'qcld_seohelp_cta_pos', $_POST ) ) {
                    update_post_meta( $qcld_seohelp_post_id, 'qcld_seohelp_cta_pos', sanitize_text_field(wp_unslash($_POST['qcld_seohelp_cta_pos'])) );
                }
                // qcld_seohelp_target_url_cta
                if ( array_key_exists( 'qcld_seohelp_target_url_cta', $_POST ) ) {
                    update_post_meta( $qcld_seohelp_post_id, 'qcld_seohelp_target_url_cta', sanitize_text_field(wp_unslash($_POST['qcld_seohelp_target_url_cta'])) );
                }
                $qcld_seohelp_result['status']  	= 'success';
                $qcld_seohelp_result['msg']     	= esc_html('Data Successfully Submitted.', 'seo-help');
                $qcld_seohelp_result['id']      	= $qcld_seohelp_post_id;
                $qcld_seohelp_result['post_link'] 	= esc_url( admin_url('edit.php') );
            }
        
        }
        
        wp_send_json( $qcld_seohelp_result );
    }
}