<?php
include '../env.php';
require_once(LIB.'common.inc.php');
require_once(LIB.'Post.class.php');
$post = new Post();

if (!is_login()) {
	_a_log_fail('favorite', 'modify', 'invalid auth');
	die;
}

$log_ret = _a_log2('favorite', 'modify', array(
	'detail' => serialize($_POST),
	'target_id' => @$_POST['id']
));
if ($log_ret) {
	$ret = $post->updateFavorite(
		$_POST['id'],
		$_POST
	);
	$post->clearFavoritePosts($_POST['id']);
	_a_log_write($log_ret, array('success' => $ret === FALSE ? '0' : '1'));

	if ($ret === FALSE) {
		//echo json_encode($ret);
	} else {
		echo json_encode($post->readFavoriteCache($_POST['id']));
	}
} else {
	//echo json_encode(FALSE);
}
?>