Example #1
0
 function createAnnotation()
 {
     $params = $this->listBodyParams();
     // Check for cross-site request forgery
     if (!$this->verifySession($params)) {
         $this->httpError(403, 'Forbidden', 'Illegal request');
         return;
     }
     // Parse annotation values
     $annotation = $this->newAnnotation();
     $error = MarginaliaHelper::annotationFromParams($annotation, $params);
     if ($error) {
         $this->httpError(MarginaliaHelper::httpResultCodeForError($error), 'Error', $error);
     } else {
         $annotation->setUserId($this->currentUserId);
         $annotation->setCreated(date('Y-m-d H:m'));
         $id = $this->doCreateAnnotation($annotation);
         if ($id != 0) {
             $feedUrl = $this->servicePath;
             if ($this->niceUrls) {
                 $feedUrl .= '/' . urlencode($id);
             } else {
                 $feedUrl .= '?id=' . urlencode($id);
             }
             header('HTTP/1.1 201 Created');
             header("Location: {$this->servicePath}/{$id}");
             $this->getAtom(array($annotation), $feedUrl, $this->baseUrl);
         } else {
             $this->httpError(500, 'Internal Service Error', 'Create failed');
         }
     }
 }
Example #2
0
 /** This method is intended to be called when an annotation is created via 
  * a POST or PUT operation.  An associative array contains the values of
  * various fields in string format.  If a field is not present in the array, 
  * it will not be set.  The userid field cannot be set this way, because 
  * that is session information (i.e. it must be the current user).
  */
 function fromArray($params)
 {
     return MarginaliaHelper::annotationFromParams($this, $params);
 }
Example #3
0
 function createAnnotation()
 {
     $params = $this->listBodyParams();
     // Parse annotation values
     $annotation = $this->newAnnotation();
     $error = MarginaliaHelper::annotationFromParams($annotation, $params);
     if ($error) {
         $this->httpError(MarginaliaHelper::httpResultCodeForError($error), 'Error', $error);
     } else {
         $annotation->setUserId($this->currentUserId);
         $id = $this->doCreateAnnotation($annotation);
         if ($id != 0) {
             header('HTTP/1.1 201 Created');
             header("Location: {$this->servicePath}/{$id}");
         } else {
             $this->httpError(500, 'Internal Service Error', 'Create failed');
         }
     }
 }