<?php

/* include WordPress */
define( 'WP_USE_THEMES', false );
require('../../../../../../../wp-load.php');

global $wp_superlike;
$data = array();

	/* post id */
	if (!isset($_POST['post_id']))
		return false;

	$post_id = $_POST['post_id'];

	/* validate user like */
	$already_liked = $wp_superlike->already_liked($post_id, $_SERVER["REMOTE_ADDR"]);
	
	/* in case we disable IP validation */
	if ($wp_superlike->get_option('multiple_vote') != 'ip_check')
		$already_liked = false;
	
	if ( !$already_liked ) {
	
		/* add like to post */
		$wp_superlike->add_like($post_id);
		
		/* store like globally */
		$wp_superlike->add_like_to_blog($post_id);

		/* number format */
		$format = (isset($format)) ? $format : $wp_superlike->get_option('number_format');
		
		/* show likes count */
		$data['show_likes'] = $wp_superlike->show_likes($post_id, $format);
		
		/* now grey out button if needed */
		if ($wp_superlike->grey_out_button($post_id)) {
			$data['grey_out'] = true;
		}
		
	} else {
	
		/* user already voted, IP required, alert popup active */
		if ($wp_superlike->show_alert($post_id)) {
			$data['alert'] = true;
			$data['alert_text'] = '<div class="wp-superlike-alert"><div class="wp-superlike-alert-inner"><div class="wp-superlike-alert-arrow"></div>'.$wp_superlike->get_option('you_already_liked').'</div></div>';
		}
		
		/* now grey out button if needed */
		if ($wp_superlike->grey_out_button($post_id)) {
			$data['grey_out'] = true;
		}
	
	}

echo json_encode($data);