Example #1
0
 /**
  * Links restful api
  */
 public function action_links()
 {
     // Is the logged in user an owner?
     if (!$this->owner) {
         throw new HTTP_Exception_403();
     }
     $this->template = "";
     $this->auto_render = FALSE;
     $droplet_id = intval($this->request->param('id', 0));
     $link_id = intval($this->request->param('id2', 0));
     switch ($this->request->method()) {
         case "POST":
             $link_array = json_decode($this->request->body(), TRUE);
             $url = $link_array['url'];
             if (!Valid::url($url)) {
                 $this->response->status(400);
                 $this->response->headers('Content-Type', 'application/json');
                 $errors = array(__("Invalid url"));
                 echo json_encode(array('errors' => $errors));
                 return;
             }
             $account_id = $this->visited_account->id;
             $link_orm = Model_Account_Droplet_Link::get_link($url, $droplet_id, $account_id);
             echo json_encode(array('id' => $link_orm->link->id, 'tag' => $link_orm->link->url));
             break;
         case "DELETE":
             Model_Droplet::delete_link($droplet_id, $link_id, $this->visited_account->id);
             break;
     }
 }