Campustream 1.0
A social network MQP for WPI
|
00001 <? 00002 00006 class Comment_Controller extends Controller implements REST { 00007 public $enable_session = true; 00008 00012 public function update() { 00013 if (!$this->session->get('authenticated')) { 00014 return Hub::http_error(403, "Not authenticated"); 00015 } 00016 00017 $status_id = $_POST['status_id']; 00018 if (!$status_id || !is_numeric($status_id)) { 00019 return Hub::http_error(401, "Missing or invalid parent status ID"); 00020 } 00021 00022 $message = trim($_POST['message']); 00023 if (!$message || !strlen($message)) { 00024 return Hub::http_error(401, "Missing status message"); 00025 } 00026 00027 $user = sess::getUser(); 00028 00029 $comment = new Statuscomment_Model(); 00030 $comment->user_id = $user->id; 00031 $comment->status_id = $status_id; 00032 $comment->message = htmlspecialchars($message, ENT_QUOTES, 'UTF-8'); 00033 $comment->post_date = ActiveRecord::NOW(); 00034 00035 $comment->save(); 00036 00037 View::respond_to(array('json', 'xml'), function($format) use($comment) { 00038 $comment->load_user(); 00039 echo $comment->{"to_$format"}(); 00040 }); 00041 } 00042 }