static function ajax_like() { header("Content-type: text/json"); header("Content-Type: application/x-javascript", true); if (!isset($_REQUEST["action"]) or !isset($_REQUEST["post_id"])) { exit; } $user_id = Visitor::current()->id; $likeSetting = Config::current()->module_like; $responseObj = array(); $responseObj["uid"] = $user_id; $responseObj["success"] = true; try { $like = new Like($_REQUEST, $user_id); $likeText = ""; switch ($like->action) { case "like": header("Content-type: text/json"); header("Content-Type: application/x-javascript", true); $like->like(); $like->fetchCount(); if ($like->total_count == 1) { # $this->text_default[0] = "You like this post."; $likeText = $like->getText($like->total_count, $likeSetting["likeText"][0]); } elseif ($like->total_count == 2) { # $this->text_default[1] = "You and 1 person like this post."; $likeText = $like->getText(1, $likeSetting["likeText"][1]); } else { $like->total_count--; # $this->text_default[2] = "You and %NUM% people like this post."; $likeText = $like->getText($like->total_count, $likeSetting["likeText"][2]); } break; default: throw new Exception("invalid action"); } $responseObj["likeText"] = $likeText; } catch (Exception $e) { $responseObj["success"] = false; $responseObj["error_txt"] = $e->getMessage(); } echo json_encode($responseObj); }