Exemplo n.º 1
0
 public function postToUsers($r)
 {
     $content_type = $r->getContentType();
     if ('application/atom+xml;type=entry' == $content_type || 'application/atom+xml' == $content_type) {
         $raw_input = $r->getBody();
         $client_md5 = $r->getHeader('Content-MD5');
         //if Content-MD5 header isn't set, we just won't check
         if ($client_md5 && md5($raw_input) != $client_md5) {
             $r->renderError(412, 'md5 does not match');
         }
         try {
             $entry = Dase_Atom_Entry::load($raw_input);
         } catch (Exception $e) {
             Dase_Log::debug(LOG_FILE, 'users handler error: ' . $e->getMessage());
             $r->renderError(400, 'bad xml');
         }
         if ('user' != $entry->entrytype) {
             $r->renderError(400, 'must be a user entry');
         }
         try {
             $user = $entry->insert($this->db, $r);
             header("HTTP/1.1 201 Created");
             header("Content-Type: application/atom+xml;type=entry;charset='utf-8'");
             header("Location: " . $user->getUrl($r->app_root) . '.atom?type=entry');
             echo $user->asAtomEntry($r->app_root);
             exit;
         } catch (Dase_Exception $e) {
             $r->renderError(409, $e->getMessage());
         }
     } elseif ('application/x-www-form-urlencoded' == $content_type) {
         //in honor of http://www.tbray.org/ongoing/When/200x/2009/01/29/Name-Value-Pairs
         $eid = $r->get('eid');
         $name = $r->get('name');
         $user = Dase_DBO_DaseUser::get($this->db, $eid);
         if (!$user) {
             $user = new Dase_DBO_DaseUser($this->db);
             $user->name = $name;
             $user->eid = strtolower($eid);
             $user->updated = date(DATE_ATOM);
             $user->created = date(DATE_ATOM);
             $user->insert();
         }
         header("HTTP/1.1 201 Created");
         header("Content-Type: application/atom+xml;type=entry;charset='utf-8'");
         header("Location: " . $user->getUrl($r->app_root) . '.atom?type=entry');
         echo $user->asAtomEntry($r->app_root);
         exit;
     } else {
         $r->renderError(415, 'cannot accept ' . $content_type);
     }
 }
Exemplo n.º 2
0
 public function postToCollections($r)
 {
     $user = $r->getUser('http');
     if (!$user->is_superuser) {
         $r->renderError(401, $user->eid . ' is not permitted to create a collection');
     }
     $content_type = $r->getContentType();
     if ('application/atom+xml;type=entry' == $content_type || 'application/atom+xml' == $content_type) {
         $raw_input = $r->getBody();
         $client_md5 = $r->getHeader('Content-MD5');
         if ($client_md5 && md5($raw_input) != $client_md5) {
             //todo: fix this
             //$r->renderError(412,'md5 does not match');
         }
         try {
             $coll_entry = Dase_Atom_Entry::load($raw_input);
         } catch (Exception $e) {
             Dase_Log::debug(LOG_FILE, 'colls handler error: ' . $e->getMessage());
             $r->renderError(400, 'bad xml');
         }
         if ('collection' != $coll_entry->entrytype) {
             $r->renderError(400, 'must be a collection entry');
         }
         if ($r->slug) {
             $r->set('ascii_id', Dase_Util::dirify($r->slug));
         }
         $ascii_id = $coll_entry->create($this->db, $r);
         $user->expireDataCache($r->getCache());
         header("HTTP/1.1 201 Created");
         header("Content-Type: application/atom+xml;type=entry;charset='utf-8'");
         header("Location: " . $r->app_root . "/collection/" . $ascii_id . '.atom');
         echo Dase_DBO_Collection::get($this->db, $ascii_id)->asAtomEntry($r->app_root);
         exit;
     } else {
         $r->renderError(415, 'cannoot accept ' . $content_type);
     }
 }
Exemplo n.º 3
0
 public function postToSets($r)
 {
     $content_type = $r->getContentType();
     if ('application/atom+xml;type=entry' == $content_type || 'application/atom+xml' == $content_type) {
         $raw_input = $r->getBody();
         $client_md5 = $r->getHeader('Content-MD5');
         //if Content-MD5 header isn't set, we just won't check
         if ($client_md5 && md5($raw_input) != $client_md5) {
             $r->renderError(412, 'md5 does not match');
         }
         try {
             $set_entry = Dase_Atom_Entry::load($raw_input);
         } catch (Exception $e) {
             Dase_Log::debug(LOG_FILE, 'user handler error: ' . $e->getMessage());
             $r->renderError(400, 'bad xml');
         }
         if ('set' != $set_entry->entrytype) {
             $r->renderError(400, 'must be a set entry');
         }
         try {
             $set = $set_entry->insert($this->db, $r);
             header("HTTP/1.1 201 Created");
             header("Content-Type: application/atom+xml;type=entry;charset='utf-8'");
             header("Location: " . $set->getUrl($r->app_root) . '.atom?type=entry');
             echo $set->asAtomEntry($r->app_root);
             exit;
         } catch (Dase_Exception $e) {
             $r->renderError(409, $e->getMessage());
         }
     } else {
         $r->renderError(415, 'cannot accept ' . $content_type);
     }
 }
Exemplo n.º 4
0
 public function putItem($r)
 {
     $user = $r->getUser('http');
     if ($this->item && !$user->can('write', $this->item)) {
         $r->renderError(401, 'cannot update item');
     }
     if (!$this->item) {
         $collection = Dase_DBO_Collection::get($this->db, $r->get('collection_ascii_id'));
         if (!$user->can('write', $collection)) {
             $r->renderError(401, 'cannot update collection');
         }
     }
     //just in case, save a copy in 'deleted' media dir
     if ($this->item) {
         $this->item->saveCopy(MEDIA_DIR);
     }
     $content_type = $r->getContentType();
     if ('application/atom+xml;type=entry' == $content_type || 'application/atom+xml' == $content_type) {
         $raw_input = $r->getBody();
         $client_md5 = $r->getHeader('Content-MD5');
         //if Content-MD5 header isn't set, we just won't check
         if ($client_md5 && md5($raw_input) != $client_md5) {
             $r->renderError(412, 'md5 does not match');
         }
         try {
             $item_entry = Dase_Atom_Entry::load($raw_input, 'item');
         } catch (Exception $e) {
             Dase_Log::debug(LOG_FILE, 'item handler error: ' . $e->getMessage());
             $r->renderError(400, 'bad xml');
         }
         if ('item' != $item_entry->entrytype) {
             //$item_entry->setEntryType('item');
             $r->renderError(400, 'must be an item entry');
         }
         $item = $item_entry->update($this->db, $r);
         if ($item) {
             $r->renderOk('item has been updated');
         } else {
             $r->renderError(500, 'item not updated');
         }
     } elseif ('application/json' == $content_type) {
         if (!$this->item) {
             $this->item = $collection->createNewItem($r->get('serial_number'));
         }
         //todo: this only updates metadata, does nothing to media (prob OK)
         $item_data = Dase_Json::toPhp($r->getBody());
         if (isset($item_data['metadata']) && count($item_data['metadata'])) {
             $this->item->deleteValues();
             //todo WILL this mess up VRC module??
             //metadata
             if (isset($item_data['metadata_extended'])) {
                 foreach ($item_data['metadata_extended'] as $key => $vals) {
                     foreach ($vals['values'] as $val) {
                         $text = $val['text'];
                         if (isset($val['modifier'])) {
                             $mod = $val['modifier'];
                         } else {
                             $mod = '';
                         }
                         if (isset($val['url'])) {
                             $url = $val['url'];
                         } else {
                             $url = '';
                         }
                         $this->item->setValue($key, $text, $url, $mod);
                     }
                 }
             } else {
                 foreach ($item_data['metadata'] as $key => $vals) {
                     foreach ($vals as $val) {
                         $this->item->setValue($key, $val);
                     }
                 }
             }
             $this->item->buildSearchIndex();
             $r->renderOk('item has been updated');
         }
         $r->renderError(400, 'must be a json item');
     } else {
         $r->renderError(415, 'cannot accept ' . $content_type);
     }
     $r->renderError(500, 'something went wrong');
 }
Exemplo n.º 5
0
 private function _newAtomItemType($r)
 {
     $raw_input = $r->getBody();
     $client_md5 = $r->getHeader('Content-MD5');
     //if Content-MD5 header isn't set, we just won't check
     if ($client_md5 && md5($raw_input) != $client_md5) {
         $r->renderError(412, 'md5 does not match');
     }
     try {
         $type_entry = Dase_Atom_Entry::load($raw_input);
     } catch (Exception $e) {
         Dase_Log::debug(LOG_FILE, 'coll handler error: ' . $e->getMessage());
         $r->renderError(400, 'bad xml');
     }
     if ('item_type' != $type_entry->entrytype) {
         $r->renderError(400, 'must be an item type entry');
     }
     try {
         $item_type = $type_entry->insert($this->db, $r, $this->collection);
         header("HTTP/1.1 201 Created");
         header("Content-Type: application/atom+xml;type=entry;charset='utf-8'");
         header("Location: " . $r->app_root . "/item_type/" . $r->get('collection_ascii_id') . "/" . $item_type->ascii_id . '.atom');
         echo $type->asAtomEntry($this->collection->ascii_id, $r->app_root);
         exit;
     } catch (Dase_Exception $e) {
         $r->renderError(409, $e->getMessage());
     }
 }
Exemplo n.º 6
0
 public function putTag($r)
 {
     $user = $r->getUser('http');
     if (!$user->can('write', $this->tag)) {
         $r->renderError(401, 'cannot update set');
     }
     $content_type = $r->getContentType();
     if ('application/atom+xml;type=entry' == $content_type || 'application/atom+xml' == $content_type) {
         $raw_input = $r->getBody();
         $client_md5 = $r->getHeader('Content-MD5');
         //if Content-MD5 header isn't set, we just won't check
         if ($client_md5 && md5($raw_input) != $client_md5) {
             $r->renderError(412, 'md5 does not match');
         }
         try {
             $set_entry = Dase_Atom_Entry::load($raw_input);
         } catch (Exception $e) {
             Dase_Log::debug(LOG_FILE, 'tag handler error: ' . $e->getMessage());
             $r->renderError(400, 'bad xml');
         }
         if ('set' != $set_entry->entrytype) {
             $r->renderError(400, 'must be a set entry');
         }
         $set = $set_entry->update($this->db, $r);
         if ($set) {
             $r->renderOk('set updated');
         } else {
             $r->renderError(500);
         }
     }
     $r->renderError(500);
 }