<?php



/**



 * ADMIN WNEPRO Ajax



 *



 * @package WNEPRO



 */







add_action( 'wp_ajax_update_attachment_title', 'update_attachment_title' );



add_action( 'wp_ajax_update_attachment_alt', 'update_attachment_alt' );



add_action( 'wp_ajax_wah_scan_homepage', 'wah_scan_homepage' );



add_action( 'wp_ajax_wah_update_image_alt', 'wah_update_image_alt' );



add_action( 'wp_ajax_wah_update_widgets_order', 'wah_update_widgets_order' );



add_action( 'wp_ajax_add_new_contrast_item', 'add_new_contrast_item' );



add_action( 'wp_ajax_remove_contrast_item', 'remove_contrast_item' );



add_action( 'wp_ajax_save_contrast_variations', 'save_contrast_variations' );



add_action( 'wp_ajax_save_empty_contrast_variations', 'save_empty_contrast_variations' );



add_action( 'wp_ajax_wah_reset_widgets_order', 'wah_reset_widgets_order' );



add_action( 'wp_ajax_wah_pro_validate_license_key', 'wah_pro_validate_license_key' );



add_action( 'wp_ajax_generate_accordion_shortcode', 'generate_accordion_shortcode' );



add_action( 'wp_ajax_wnexpress_check_subscription_data', 'wnexpress_check_subscription_data' );



add_action( 'wp_ajax_subscription_ending_nofitication_send', 'subscription_ending_nofitication_send' );



/**



 * Subscribe to notification end email



 */



function subscription_ending_nofitication_send() {



	$form = isset( $_POST['form'] ) ? $_POST['form'] : ''; // phpcs:ignore



	$form_args = array();



	parse_str( $form, $form_args );







	$endpoint = 'https://accessibility-helper.co.il/?action=subscription_ending_nofitication';







	$body = $form_args;







	$options = array(



		'body'        => $body,



		'headers'     => array(),



		'timeout'     => 60,



		'redirection' => 5,



		'blocking'    => true,



		'httpversion' => '1.0',



		'sslverify'   => false,



		'data_format' => 'body',



		'method'      => 'POST',



	);







	$response     = wp_remote_post( $endpoint, $options );



	$api_response = wp_remote_retrieve_body( $response );







	wp_send_json( $api_response );



}



/**



 * WNEPRO check_subscription_data



 */



function wnexpress_check_subscription_data() {



	$result  = array();



	$email   = isset( $_POST['email'] ) ? sanitize_text_field( wp_unslash( $_POST['email'] ) ) : '';



	$license = isset( $_POST['license'] ) ? sanitize_text_field( wp_unslash( $_POST['license'] ) ) : '';







	if ( $email && $license ) {



		$endpoint = 'https://accessibility-helper.co.il/?action=wnexpress_check_subscription';







		$body = array(



			'license' => $license,



			'email'   => $email,



		);







		$options = array(



			'body'        => $body,



			'headers'     => array(),



			'timeout'     => 60,



			'redirection' => 5,



			'blocking'    => true,



			'httpversion' => '1.0',



			'sslverify'   => false,



			'data_format' => 'body',



			'method'      => 'POST',



		);







		$response     = wp_remote_post( $endpoint, $options );



		$api_response = wp_remote_retrieve_body( $response );



		wp_send_json( $api_response );



	} else {



		wp_send_json(



			array(



				'status'  => 'error',



				'message' => 'Email and license key is required fields.',



			)



		);



	}







}



/**



 * Update attachment title



 */



function update_attachment_title() {







	$result = array();



	$pid    = isset( $_POST['pid'] ) ? sanitize_text_field( wp_unslash( $_POST['pid'] ) ) : '';



	$ptitle = isset( $_POST['ptitle'] ) ? sanitize_text_field( wp_unslash( $_POST['ptitle'] ) ) : '';







	if ( $pid ) {



		$result['plink'] = get_permalink( $pid );



		$result['pid']   = $pid;



		if ( $ptitle ) {



			$attachment_post = array(



				'ID'         => $pid,



				'post_title' => $ptitle,



			);



			wp_update_post( $attachment_post );



			$result['ptitle'] = $ptitle;



		}



		wp_send_json( $result );



	}



}



/**



 * Update attachment alt



 */



function update_attachment_alt() {



	$result = array();



	$pid    = isset( $_POST['pid'] ) ? sanitize_text_field( wp_unslash( $_POST['pid'] ) ) : '';



	$palt   = isset( $_POST['palt'] ) ? sanitize_text_field( wp_unslash( $_POST['palt'] ) ) : '';







	if ( $pid ) {







		$result['plink'] = get_permalink( $pid );



		$result['pid']   = $pid;







		if ( $palt ) {



			update_post_meta( $pid, '_wp_attachment_image_alt', $palt );



			$alt            = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );



			$result['palt'] = $alt;



		}



		wp_send_json( $result );







	}



}



/**



 * WAH SCANNER



 */



function wah_scan_homepage() {







	$result  = array();



	$post_id = isset( $_POST['postID'] ) ? sanitize_text_field( wp_unslash( $_POST['postID'] ) ) : '';



	$url     = get_permalink( $post_id );







	$response      = wp_remote_get( $url, array( 'timeout' => 20 ) );



	$response_code = wp_remote_retrieve_response_code( $response );



	$body          = isset( $response ) ? $response['body'] : '';







	if ( $body && $post_id && $response_code == 200 ) {







		$scanner_array = array();







		// get all images.



		preg_match_all( '/<img[^>]+>/i', $body, $images );



		$scanner_array['images'] = $images[0];







		// get all links.



		$regexp_links = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";



		if ( preg_match_all( "/$regexp_links/siU", $body, $links ) ) {



			$scanner_array['links'] = $links[0];



		}







		// get all H1-H6 tags.



		preg_match_all( '|<h1.*>(.*)</h[^>]+>|iU', $body, $headings );



		$scanner_array['h1'] = $headings[0];







		if ( $scanner_array['images'] ) {



			ob_start();



			?>







			<div class="form_row">



				<h3 class="wah_scanner_table_trigger">



					<span></span><?php esc_html_e( 'Images Report Table', 'wp-nagish-express' ); ?>



				</h3>



				<table class="widefat fixed wah_scanner_table" cellspacing="5">



					<thead>



						<tr>



							<th class="manage-column column-cb check-column wah_th" scope="col" style="width:130px !important;">



								<?php esc_html_e( 'Thumbnail', 'wp-nagish-express' ); ?>



							</th>



							<th class="manage-column image_src">



								<?php esc_html_e( 'Image Source', 'wp-nagish-express' ); ?>



							</th>



							<th class="manage-column column-cb check-column wah_th" scope="col">



								<?php esc_html_e( 'Alt', 'wp-nagish-express' ); ?>



							</th>



							<th class="manage-column column-cb check-column wah_th" scope="col">



								<?php esc_html_e( 'Width', 'wp-nagish-express' ); ?>



							</th>



							<th class="manage-column column-cb check-column wah_th" scope="col">



								<?php esc_html_e( 'Height', 'wp-nagish-express' ); ?>



							</th>



							<th class="manage-column column-cb check-column wah_th" scope="col">



								<?php esc_html_e( 'Action', 'wp-nagish-express' ); ?>



							</th>



							<th class="manage-column column-cb check-column wah_th" scope="col">



								<?php esc_html_e( 'Preview', 'wp-nagish-express' ); ?>



							</th>



						</tr>



					</thead>



					<tbody>



						<?php



						foreach ( $scanner_array['images'] as $key => $image_html ) :







							preg_match( '@src="([^"]+)"@', $image_html, $match_src );



							$src = array_pop( $match_src );







							preg_match( '@alt="([^"]+)"@', $image_html, $match_alt );



							$alt = array_pop( $match_alt );







							preg_match( '@width="([^"]+)"@', $image_html, $match_width );



							$width = array_pop( $match_width );







							preg_match( '@width="([^"]+)"@', $image_html, $match_height );



							$height = array_pop( $match_height );







							$attachment_id = wah_get_attachment_id_by_src( $src );







							?>



						<tr>



						<td class="wah_scanner_thumbnail"><?php echo wp_kses_post( $image_html ); ?></td>



						<td>



							<?php echo $src ? '<xmp>' . esc_url( $src ) . '</xmp>' : '<span class="not-valid">' . esc_html__( 'not valid', 'wp-nagish-express' ) . '</span>'; ?>



						</td>



						<td>



							<?php echo $alt ? '<span class="valid">' . esc_html( $alt ) . '</span>' : '<span class="not-valid">not valid</span>'; ?>



						</td>



						<td>



							<?php echo $width ? '<span class="valid">' . esc_html( $width ) . '</span>' : '<span class="warning">X</span>'; ?>



						</td>



						<td>



							<?php echo $height ? '<span class="valid">' . esc_html( $height ) . '</span>' : '<span class="warning">X</span>'; ?>



						</td>



						<td>



							<?php if ( $attachment_id ) { ?>



								<a href="<?php echo esc_url( get_edit_post_link( $attachment_id ) ); ?>" target="_blank">



									<?php esc_html_e( 'Edit image', 'wp-nagish-express' ); ?>



								</a>



							<?php } ?>



						</td>



						<td>



							<a target="_blank" href="<?php echo esc_url( add_query_arg( 'wahi', base64_encode( $src ), get_permalink( $post_id ) ) ); ?>">



								<?php esc_html_e( 'Preview', 'wp-nagish-express' ); ?>



							</a>



						</td>



						</tr>



						<?php endforeach; ?>



					</tbody>



				</table>



			</div>







			<?php



			$result['images'] = ob_get_clean();



		}







		if ( $scanner_array['links'] ) {



			ob_start();



			?>







		<div class="form_row">



			<h3 class="wah_scanner_table_trigger">



				<span></span><?php esc_html_e( 'Links Report Table', 'wp-nagish-express' ); ?>



			</h3>



			<table class="widefat fixed wah_scanner_table" cellspacing="5">



				<thead>



					<tr>



						<th class="manage-column column-cb check-column wah_th" scope="col" style="width:26px;">



							<?php esc_html_e( 'ID', 'wp-nagish-express' ); ?>



						</th>



						<th class="manage-column column-cb check-column wah_th" scope="col">



							<?php esc_html_e( 'Source', 'wp-nagish-express' ); ?>



						</th>



						<th class="manage-column column-cb check-column wah_th" scope="col">



							<?php esc_html_e( 'URL', 'wp-nagish-express' ); ?>



						</th>



						<th class="manage-column column-cb check-column wah_th" scope="col">



							<?php esc_html_e( 'Title', 'wp-nagish-express' ); ?>



						</th>



						<th class="manage-column column-cb check-column wah_th" scope="col">



							<?php esc_html_e( 'Aria-label', 'wp-nagish-express' ); ?>



						</th>



						<th class="manage-column column-cb check-column wah_th" scope="col">



							<?php esc_html_e( 'Preview', 'wp-nagish-express' ); ?>



						</th>



					</tr>



				</thead>



				<tbody>



					<?php



					$link_html_counter = 0;



					foreach ( $scanner_array['links'] as $key => $link_html ) :



						$link_html_counter++;



						preg_match( '@href="([^"]+)"@', $link_html, $match_href );



						$href = array_pop( $match_href );







						preg_match( '@title="([^"]+)"@', $link_html, $match_title );



						$title = array_pop( $match_title );







						preg_match( '@aria-label="([^"]+)"@', $link_html, $match_aria_label );



						$aria_label = array_pop( $match_aria_label );



						?>



						<tr>



							<td><?php echo esc_html( $link_html_counter ); ?></td>



							<td class="wah_scanner_thumbnail">



								<xmp><?php echo wp_kses_post( $link_html ); ?></xmp>



							</td>



							<td>



								<?php



								if ( $href && '#' !== $href ) {



									echo esc_url( $href );



								} elseif ( $href && '#' === $href ) {



									echo '<span class="warning">' . esc_html__( 'empty href', 'wp-nagish-express' ) . '</span>';



								} else {



									echo '<span class="warning">X</span>';



								}



								?>



							</td>



							<td><?php echo $title ? esc_html( $title ) : '<span class="warning">X</span>'; ?></td>



							<td><?php echo $aria_label ? esc_html( $aria_label ) : '<span class="warning">X</span>'; ?></td>



							<td>



								<a href="<?php echo esc_url( add_query_arg( 'wahl', base64_encode( $href ), get_permalink( $post_id ) ) ); ?>" target="_blank">



									<?php esc_html_e( 'Preview link', 'wp-nagish-express' ); ?>



								</a>



							</td>



						</tr>



					<?php endforeach; ?>



				</tbody>



			</table>



		</div>







			<?php



			$result['links'] = ob_get_clean();



		}







		if ( $scanner_array['h1'] ) {



			ob_start();



			?>



				<?php if ( count( $scanner_array['h1'] ) > 1 ) : ?>



					<div class="notice notice-error wah-scanner-notice">



						<p>You have more than 1 &lt;h1&gt; tags. <a href="https://www.w3.org/WAI/tutorials/page-structure/headings/" target="_blank">More info</a></p>



					</div>



				<?php else : ?>



					<div class="notice notice-success wah-scanner-notice">



						<p>&lt;h1&gt; tag exists.</p>



					</div>



				<?php endif; ?>



			<?php



			$result['h1'] = ob_get_clean();



		} else {



			$result['h1'] = '<div class="notice notice-error wah-scanner-notice"><p>&lt;h1&gt; tag not found.</p></div>';



		}







		$result['response_code'] = $response_code;







		wp_send_json( $result );







	} else {







		$result['response_code'] = $response_code;







		wp_send_json( $result );







	}







}



/**



 * WAH get attachment id by src (URL)



 *



 * @param  string $image_url image URL.



 * @return string            attachment ID



 */



function wah_get_attachment_id_by_src( $image_url ) {



	global $wpdb;



	$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid='%s';", $image_url ) );



	if ( $attachment ) {



		return $attachment[0];



	}



}



/**



 * Update image alt - front scanner



 */



function wah_update_image_alt() {







	$response          = array();



	$attachment_source = isset( $_POST['target_src'] ) ? sanitize_text_field( wp_unslash( $_POST['target_src'] ) ) : '';



	$wah_alt_input     = isset( $_POST['wah_alt_input'] ) ? sanitize_text_field( wp_unslash( $_POST['wah_alt_input'] ) ) : '';







	if ( $attachment_source ) {







		$attachment_id = get_attachment_id( $attachment_source );







		if ( $attachment_id && $wah_alt_input ) {



			update_post_meta( $attachment_id, '_wp_attachment_image_alt', $wah_alt_input );



			$response['atid']    = $attachment_id;



			$response['status']  = 'ok';



			$response['message'] = __( 'Image has been updated.', 'wp-nagish-express' );



		} else {



			$response['atid']    = -1;



			$response['status']  = 'error';



			$response['message'] = __( 'It look likes, this image is not on your server...', 'wp-nagish-express' );



		}







		wp_send_json( $response );



	}



}



/**



 * Save wah widgets order



 *



 * @param  array $data widgets list.



 */



function wah_update_widgets_order( $data ) {



	$response      = '';



	$send_response = false;



	if ( ! $data ) {



		$send_response = true;



		$data          = isset( $_POST['alldata'] ) ? $_POST['alldata'] : '';



	} else {



		$array = array();



		foreach ( $data as $widget_id => $widget_data ) {



			$array[] = $widget_id;



		}



		$data = $array;



	}







	$widgets_status = wah_get_widgets_status();







	$widgets_object              = array();



	$widgets_object['widget-1']  = array(



		'active' => 1,



		'html'   => __( 'Font resize', 'wp-nagish-express' ),



		'class'  => 'active',



	);



	$widgets_object['widget-2']  = array(



		'active' => $widgets_status['wne_keyboard_navigation_setup'],



		'html'   => __( 'Keyboard navigation', 'wp-nagish-express' ),



		'class'  => $widgets_status['wne_keyboard_navigation_setup'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-3']  = array(



		'active' => $widgets_status['wne_readable_fonts_setup'],



		'html'   => __( 'Readable Font', 'wp-nagish-express' ),



		'class'  => $widgets_status['wne_readable_fonts_setup'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-4']  = array(



		'active' => $widgets_status['contrast_setup'],



		'html'   => __( 'Contrast', 'wp-nagish-express' ),



		'class'  => $widgets_status['contrast_setup'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-5']  = array(



		'active' => $widgets_status['underline_links_setup'],



		'html'   => __( 'Underline links', 'wp-nagish-express' ),



		'class'  => $widgets_status['underline_links_setup'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-6']  = array(



		'active' => $widgets_status['wne_highlight_links_enable'],



		'html'   => __( 'Highlight links', 'wp-nagish-express' ),



		'class'  => $widgets_status['wne_highlight_links_enable'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-7']  = array(



		'active' => 1,



		'html'   => __( 'Clear cookies', 'wp-nagish-express' ),



		'class'  => 'active',



	);



	$widgets_object['widget-8']  = array(



		'active' => $widgets_status['wne_greyscale_enable'],



		'html'   => __( 'Image Greyscale', 'wp-nagish-express' ),



		'class'  => $widgets_status['wne_greyscale_enable'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-9']  = array(



		'active' => $widgets_status['wne_invert_enable'],



		'html'   => __( 'Invert colors', 'wp-nagish-express' ),



		'class'  => $widgets_status['wne_invert_enable'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-10'] = array(



		'active' => $widgets_status['wne_remove_animations_setup'],



		'html'   => __( 'Remove Animations', 'wp-nagish-express' ),



		'class'  => $widgets_status['wne_remove_animations_setup'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-11'] = array(



		'active' => $widgets_status['remove_styles_setup'],



		'html'   => __( 'Remove styles', 'wp-nagish-express' ),



		'class'  => $widgets_status['remove_styles_setup'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-12'] = array(



		'active' => $widgets_status['wne_lights_off_setup'],



		'html'   => __( 'Lights Off', 'wp-nagish-express' ),



		'class'  => $widgets_status['wne_lights_off_setup'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-13'] = array(



		'active' => $widgets_status['wah_highlight_titles_setup'],



		'html'   => __( 'Highlight Titles', 'wp-nagish-express' ),



		'class'  => $widgets_status['wah_highlight_titles_setup'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-14'] = array(



		'active' => $widgets_status['wne_image_alt_setup'],



		'html'   => __( 'Image description', 'wp-nagish-express' ),



		'class'  => $widgets_status['wne_image_alt_setup'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-15'] = array(



		'active' => $widgets_status['wah_enable_terms_link'],



		'html'   => __( 'Custom link', 'wp-nagish-express' ),



		'class'  => $widgets_status['wah_enable_terms_link'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-16'] = array(



		'active' => $widgets_status['wah_enable_large_mouse_cursor'],



		'html'   => __( 'Large mouse cursor', 'wp-nagish-express' ),



		'class'  => $widgets_status['wah_enable_large_mouse_cursor'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-17'] = array(



		'active' => $widgets_status['wne_enable_monochrome_mode'],



		'html'   => __( 'Monochrome', 'wp-nagish-express' ),



		'class'  => $widgets_status['wne_enable_monochrome_mode'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-18'] = array(



		'active' => $widgets_status['wne_enable_sepia_mode'],



		'html'   => __( 'Sepia', 'wp-nagish-express' ),



		'class'  => $widgets_status['wne_enable_sepia_mode'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-19'] = array(



		'active' => $widgets_status['wah_enable_inspector_mode'],



		'html'   => __( 'Table Content', 'wp-nagish-express' ),



		'class'  => $widgets_status['wah_enable_inspector_mode'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-20'] = array(



		'active' => $widgets_status['wah_set_layout_setup'],



		'html'   => __( 'Select Theme', 'wp-nagish-express' ),



		'class'  => $widgets_status['wah_set_layout_setup'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-21'] = array(



		'active' => $widgets_status['wne_enable_letter_spacing_mode'],



		'html'   => __( 'Letter spacing', 'wp-nagish-express' ),



		'class'  => $widgets_status['wne_enable_letter_spacing_mode'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-22'] = array(



		'active' => $widgets_status['wah_enable_adhd'],



		'html'   => __( 'ADHD Profile', 'wp-nagish-express' ),



		'class'  => $widgets_status['wah_enable_adhd'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-23'] = array(



		'active' => $widgets_status['wah_text_alignment'],



		'html'   => __( 'Text alignment', 'wp-nagish-express' ),



		'class'  => $widgets_status['wah_text_alignment'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-24'] = array(



		'active' => $widgets_status['wne_enable_mute'],



		'html'   => __( 'MUTE volume', 'wp-nagish-express' ),



		'class'  => $widgets_status['wne_enable_mute'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-25'] = array(



		'active' => $widgets_status['wne_enable_hide_images'],



		'html'   => __( 'Hide Images', 'wp-nagish-express' ),



		'class'  => $widgets_status['wne_enable_hide_images'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-26'] = array(



		'active' => $widgets_status['wne_enable_word_spacing'],



		'html'   => __( 'Word spacing', 'wp-nagish-express' ),



		'class'  => $widgets_status['wne_enable_word_spacing'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-27'] = array(



		'active' => $widgets_status['wne_enable_line_height'],



		'html'   => __( 'Line height', 'wp-nagish-express' ),



		'class'  => $widgets_status['wne_enable_line_height'] ? 'active' : 'notactive',



	);



	$widgets_object['widget-28'] = array(



		'active' => $widgets_status['wne_enable_cd_profile'],



		'html'   => __( 'Cognitive Disability Profile', 'wp-nagish-express' ),



		'class'  => $widgets_status['wne_enable_cd_profile'] ? 'active' : 'notactive',



	);







	$s_data = array();



	foreach ( $data as $id ) {



		$s_data[ $id ] = $widgets_object[ $id ];



	}







	$s_data = serialize( $s_data );



	wah_set_param( 'wne_sidebar_widgets_order', $s_data );



	$response = 'ok';







	if ( ! $send_response ) {



		return $response;



	} else {



		wp_send_json( $response );



	}







}



/**



 * Add new contrast item from repeater



 */



function add_new_contrast_item() {



	$response = array();



	ob_start();



	?>



	<li>



		<div class="contrast-mode-item bg-color">



			<label><?php esc_html_e( 'Background color', 'wp-nagish-express' ); ?></label>



			<input type="text" class="jscolor" placeholder="<?php esc_html_e( 'Background color', 'wp-nagish-express' ); ?>" />



		</div>



		<div class="contrast-mode-item text-color">



			<label><?php esc_html_e( 'Text color', 'wp-nagish-express' ); ?></label>



			<input type="text" class="jscolor" placeholder="<?php esc_html_e( 'Text color', 'wp-nagish-express' ); ?>" />



		</div>



		<div class="contrast-mode-item button-title-alt">



			<label><?php esc_html_e( 'Title', 'wp-nagish-express' ); ?></label>



			<input type="text" placeholder="<?php esc_html_e( 'Button title', 'wp-nagish-express' ); ?>" />



		</div>



		<div class="contrast-mode-item action">



			<button class="wah-button delete-contrast-params">



				<?php esc_html_e( 'Delete', 'wp-nagish-express' ); ?>



			</button>



			<span class="action-loader"></span>



		</div>



	</li>



	<?php



	$response['status'] = 'ok';



	$response['html']   = ob_get_clean();



	wp_send_json( $response );



}



/**



 * Remove contrast item from repeater



 */



function remove_contrast_item() {



	$response           = array();



	$response['status'] = 'ok';



	wp_send_json( $response );



}



/**



 * Save contrast variations



 */



function save_contrast_variations() {



	$response = array();



	$alldata  = isset( $_POST['alldata'] ) ? $_POST['alldata'] : '';



	if ( $alldata ) {



		$data = serialize( $alldata );



		update_option( 'wne_contrast_variations', $data );



		$response['status'] = 'ok';



		wp_send_json( $response );



	}



	die();



}



/**



 * Save EMPTY contrast variations



 */



function save_empty_contrast_variations() {



	$response = array();



	$alldata  = '';



	update_option( 'wne_contrast_variations', $alldata );



	$response['status']  = 'ok';



	$response['message'] = __( 'Removed!', 'wp-nagish-express' );



	wp_send_json( $response );



}



/**



 * Get all contrast variations



 *



 * @return array variations



 */



function wah_get_contrast_variations() {



	$contrast_variations = get_option( 'wne_contrast_variations' );



	$contrast_variations = unserialize( $contrast_variations );



	if ( $contrast_variations ) {



		return $contrast_variations;



	}



}



/**



 * WAH RESET WIDGETS ORDER



 */



function wah_reset_widgets_order() {



	$response = array();



	wah_set_param( 'wne_sidebar_widgets_order', '' );



	$response['status']  = 'ok';



	$response['message'] = 'Done';



	wp_send_json( $response );



}



/**



 * WNagish Express update license key



 */



function wah_pro_validate_license_key() {







	$form_data = isset( $_POST['form_data'] ) ? $_POST['form_data'] : '';



	$response  = array();



	$params    = array();



	parse_str( $form_data, $params );







	if ( $params['wah_license_email'] && $params['wah_license_key'] ) {







		$license_validation = wnexpress_send_license_data( $params['wah_license_email'], $params['wah_license_key'] );



		$license_status     = $license_validation ? $license_validation['search'][0]['Active'] : 0;



		$license_site_url   = $license_validation ? $license_validation['search'][0]['ActivatedURL'] : '';



		$current_site_url   = get_site_url();







		if ( $license_validation ) {



			// first time activation.



			if ( $license_status == 0 ) {







				$update_license_status = wnexpress_send_update_license_status( $params['wah_license_email'], $params['wah_license_key'], $current_site_url );



				update_option( 'wah_pro_license_key', $params['wah_license_key'] );



				update_option( 'wah_pro_license_email', $params['wah_license_email'] );



				$response['status']  = 'ok';



				$response['log']     = '1';



				$response['message'] = 'License key saved & activated successfuly. Thank you!';







			} elseif ( $license_status == 1 && ( $license_site_url === $current_site_url ) ) {







				update_option( 'wah_pro_license_key', $params['wah_license_key'] );



				update_option( 'wah_pro_license_email', $params['wah_license_email'] );



				$response['status']  = 'ok';



				$response['log']     = '2';



				$response['message'] = 'This license is currently active for this website.';







			} elseif ( $license_status == 1 && ( $license_site_url !== $current_site_url ) ) {







				update_option( 'wah_pro_license_key', '' );



				update_option( 'wah_pro_license_email', '' );



				$response['status']  = 'error';



				$response['log']     = '3';



				$response['message'] = 'This license has already been activated. Please purchase another license key.';







			}



		} else {



			update_option( 'wah_pro_license_key', '' );



			update_option( 'wah_pro_license_email', '' );



			$response['status']  = 'error';



			$response['log']     = '4';



			$response['message'] = 'License key or email is invalid. Please try again.';



		}



	}







	delete_option( '_site_transient_update_plugins' );



	wp_send_json( $response );



}



/**



 * Render Accordion Shortcode



 */



function generate_accordion_shortcode() {







	$form   = isset( $_POST['form'] ) ? $_POST['form'] : '';



	$result = array();







	if ( $form ) {







		$form_args = array();



		parse_str( $form, $form_args );







		$bg_active       = $form_args['wah-acc-bg-active'];



		$bg_default      = $form_args['wah-acc-bg-default'];



		$text_active     = $form_args['wah-acc-text-active'];



		$text_default    = $form_args['wah-acc-text-default'];



		$animations      = $form_args['wah-acc-animations'];



		$first_is_active = $form_args['wah-acc-first-is-active'];



		$wahid           = 'wacc-' . uniqid() . gmdate( 'dmYHis' );







		ob_start();







		echo '[wah-accordion wah-id="' . esc_html( $wahid ) . '" bg-active="' . $bg_active . '" first-is-active="' . $first_is_active . '" animation="' . $animations . '" bg-default="' . $bg_default . '" text-active="' . $text_active . '" text-default="' . $text_default . '" ]';







		// unset settings params from main shortcode.



		unset( $form_args['wah-acc-bg-active'] );



		unset( $form_args['wah-acc-bg-default'] );



		unset( $form_args['wah-acc-text-active'] );



		unset( $form_args['wah-acc-text-default'] );







		unset( $form_args['wah-acc-first-is-active'] );



		unset( $form_args['wah-acc-animations'] );







		$items_counter = 0;



		foreach ( $form_args as $item ) {



			$active = '';



			if ( $items_counter == 0 && $first_is_active ) {



				$active = 'is-active';



			}



			echo '[wah-accordion-item title="' . esc_html( $item['wah-acc-title'] ) . '" is-active="' . esc_html( $active ) . '"]' . $item['wah-acc-content'] . '[/wah-accordion-item]';







			$items_counter++;



		}







		echo '[/wah-accordion]';







		$result['html'] = ob_get_clean();







		wp_send_json( $result );







	}







}



