<?php
include '../env.php';
require_once(LIB.'common.inc.php');
require_once(LIB.'Post.class.php');
if (! can_action('admin')) {
	_a_log_fail('keyword', 'create', 'invalid auth', array(
		'target_key' => @$_POST['keyword']
	));
	echo json_encode(FALSE);
	die;
}

$post = new Post();
$k = @$_POST['keyword'];

$log_ret = _a_log2('keyword', 'create', array(
	'target_key' => $k,
	'detail' => serialize($_POST)
));

if ($log_ret) {
	if (empty($k)) {
		$ret = FALSE;
	} else {
		$ret = $post->tryCreateKeyword($k);
		_a_log_write($log_ret, array('success' => $ret === FALSE ? '0' : '1'));
	}
} else {
	$ret = FALSE;
}

if (! empty($_POST['no_ajax'])) {
	header('Location: '.BASE_URL);
} else {
	echo json_encode($ret);
}
?>