<?php
header("Connection: close");
Header("Cache-Control: no-cache, must-revalidate"); // говорим браузеру что-бы он не кешировал эту страницу
Header("Pragma: no-cache");
header("Content-type: application/json");
$array = array(
    'status' => 0
);
if (filter_has_var(INPUT_POST, 'type')) {
    $args = filter_input_array(INPUT_POST, [
        'id_post' => [
            'filter' => FILTER_VALIDATE_INT,
            'options' => [
                'default' => 0,
                'min_range' => 0
            ]
        ],'id_author' => [
            'filter' => FILTER_VALIDATE_INT,
            'options' => [
                'default' => 0,
                'min_range' => 0
            ]
        ], 'type' => [
            'filter' => FILTER_CALLBACK,
            'options' => function($type) {
                return like::init()->getLikeType($type);
            }
        ]
    ], false);

    if(!isset($args['id_post']) || !isset($args['type']) || !isset($user['id']))
        $array['status'] = -1;
    else {
        $response = like::init()->{$args['type']}([
            'id_user' => (int)$user['id'],
            'id_author' => $args['id_author'],
            'id_post' => $args['id_post']
        ]);
        $array['status'] = $response === false ? -1 : (int)$response;
    }

}
echo json_encode($array);
exit();