Example #1
0
 function injectAtomEntryData(Dase_Atom_Entry $entry, $app_root)
 {
     $d = "http://daseproject.org/ns/1.0";
     //this function assumes p_collection_ascii_id & p_serial_number are set
     $entry->setId($this->getLink($app_root));
     $entry->setTitle($this->filename);
     $entry->addAuthor();
     $entry->setUpdated($this->updated);
     $entry->setSummary('');
     //for AtomPub
     $entry->setEdited($this->updated);
     $edit_url = $app_root . '/media/' . $this->p_collection_ascii_id . '/' . $this->p_serial_number;
     $entry->addLink($edit_url, 'edit');
     $ext = Dase_File::$types_map[$this->mime_type]['ext'];
     $edit_media_url = $app_root . '/media/' . $this->p_collection_ascii_id . '/' . $this->p_serial_number;
     $entry->addLink($edit_media_url, 'edit-media');
     //to which we can post form-encoded or json metadata pairs:
     $entry->addLink($app_root . '/item/' . $this->p_collection_ascii_id . '/' . $this->p_serial_number . '/metadata', 'http://daseproject.org/relation/edit-metadata');
     //link to the owning dase item using iana registered 'up' rel value
     $entry->addLink($app_root . '/item/' . $this->p_collection_ascii_id . '/' . $this->p_serial_number . '.atom', 'up');
     $entry->setMediaContent($this->getLink($app_root), $this->mime_type);
     $media_group = $entry->addElement('media:group', null, Dase_Atom::$ns['media']);
     //todo: beef up w/ bitrate, samplingrate, etc.
     foreach ($this->getDerivatives() as $med) {
         if ($med->size == 'thumbnail') {
             //$media_thumbnail = $entry->addElement('media:thumbnail',null,Dase_Atom::$ns['media']);
             $media_thumbnail = $media_group->appendChild($entry->dom->createElementNS(Dase_Atom::$ns['media'], 'thumbnail'));
             $media_thumbnail->setAttribute('url', $med->getLink($app_root));
             $media_thumbnail->setAttribute('width', $med->width);
             $media_thumbnail->setAttribute('height', $med->height);
         }
         if ($med->size == 'viewitem') {
             //$media_viewitem = $entry->addElement('media:content',null,Dase_Atom::$ns['media']);
             $media_viewitem = $media_group->appendChild($entry->dom->createElementNS(Dase_Atom::$ns['media'], 'content'));
             $media_viewitem->setAttribute('url', $med->getLink($app_root));
             $media_viewitem->setAttribute('width', $med->width);
             $media_viewitem->setAttribute('height', $med->height);
             $media_viewitem->setAttribute('fileSize', $med->file_size);
             $media_viewitem->setAttribute('type', $med->mime_type);
             $media_category = $media_viewitem->appendChild($entry->dom->createElement('media:category'));
             $media_category->appendChild($entry->dom->createTextNode($med->size));
         }
         if ($med->size != 'thumbnail' && $med->size != 'viewitem') {
             $media_content = $media_group->appendChild($entry->dom->createElementNS(Dase_Atom::$ns['media'], 'content'));
             $media_content->setAttribute('url', $med->getLink($app_root));
             $media_content->setAttribute('width', $med->width);
             $media_content->setAttribute('height', $med->height);
             $media_content->setAttribute('fileSize', $med->file_size);
             $media_content->setAttribute('type', $med->mime_type);
             $media_category = $media_content->appendChild($entry->dom->createElement('media:category'));
             $media_category->appendChild($entry->dom->createTextNode($med->size));
         }
     }
     return $entry->asXml();
 }
Example #2
0
 function injectAtomEntryData(Dase_Atom_Entry $entry, $app_root)
 {
     $entry->setTitle('Collection Manager ' . $this->collection_ascii_id . '/' . $this->dase_user_eid);
     $entry->setId($app_root . '/manager/' . $this->collection_ascii_id . '/' . $this->dase_user_eid);
     $entry->addCategory('collection_manager', 'http://daseproject.org/category/entrytype');
     $entry->setUpdated($this->created);
     $entry->addAuthor($this->created_by_eid);
     $entry->addCategory($this->auth_level, 'http://daseproject.org/category/auth_level');
     $entry->addCategory($this->dase_user_eid, 'http://daseproject.org/category/eid');
     $entry->addCategory($this->collection_ascii_id, 'http://daseproject.org/category/collection');
     return $entry;
 }
Example #3
0
 function __get($var)
 {
     //allows smarty to invoke function as if getter
     $classname = get_class($this);
     $method = 'get' . ucfirst($var);
     if (method_exists($classname, $method)) {
         return $this->{$method}();
     } else {
         return parent::__get($var);
     }
 }
Example #4
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);
     }
 }
Example #5
0
 public function getDemo($r)
 {
     $user = $r->getUser();
     $t = new Dase_Template($r);
     if ($r->has('url')) {
         $entry = Dase_Atom_Entry::retrieve($r->get('url'), $user->eid, $user->getHttpPassword());
         $t->assign('url', $r->get('url'));
         $t->assign('entry', $entry);
         $t->assign('atom_doc', $entry->asXml($entry->root));
     } else {
         $t->assign('url', $r->app_root . "/service");
     }
     $r->renderResponse($t->fetch('tools/demo.tpl'));
 }
Example #6
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);
     }
 }
Example #7
0
 function __get($var)
 {
     //allows smarty to invoke function as if getter
     $classname = get_class($this);
     //strips initial underscore
     $method = 'get' . ucfirst(substr($var, 1));
     //for arrow get must be prefixed w/ underscore
     //if it is an atom element, since arrow gets
     //are used for retrieving metadata on entry items
     if ('_' == substr($var, 0, 1) && method_exists($classname, $method)) {
         return $this->{$method}();
     } elseif ($this->getMetadata($var)) {
         return $this->getMetadata($var);
     } elseif ($this->getMetadataLinks($var)) {
         return $this->getMetadataLinks($var);
     } else {
         return parent::__get($var);
     }
 }
Example #8
0
 function injectAtomEntryData(Dase_Atom_Entry $entry, $app_root)
 {
     $url = $this->getUrl($this->ascii_id, $app_root);
     $entry->setTitle($this->collection_name);
     $entry->setId($url);
     $entry->setUpdated($this->updated);
     $entry->addAuthor();
     $entry->addLink($url . '.atom');
     $entry->addLink($url . '.atom', 'edit');
     $entry->addCategory('collection', 'http://daseproject.org/category/entrytype');
     if ($this->description) {
         $entry->setSummary($this->description);
     } else {
         $entry->setSummary(str_replace('_collection', '', $this->ascii_id));
     }
     if ($this->admin_notes) {
         $entry->setContent($this->admin_notes);
     }
     foreach ($this->getAttributes() as $a) {
         $entry->addCategory($a->ascii_id, "http://daseproject.org/category/attribute", $a->attribute_name);
     }
     foreach ($this->getItemTypes() as $item_type) {
         $entry->addCategory($item_type->ascii_id, "http://daseproject.org/category/item_type", $item_type->name);
     }
     if ($this->is_public) {
         $pub = "public";
     } else {
         $pub = "private";
     }
     $entry->addCategory($pub, "http://daseproject.org/category/status");
     if (!$this->visibility) {
         $this->visibility = 'user';
     }
     $entry->addCategory($this->visibility, "http://daseproject.org/category/visibility");
     $entry->addCategory($app_root, "http://daseproject.org/category/base_url");
     $entry->addCategory($this->item_count, "http://daseproject.org/category/item_count");
     return $entry;
 }
Example #9
0
function _smarty_dase_atom_entry_select_media(Dase_Atom_Entry $entry, $size)
{
    //returns media of stated size
    return $entry->selectMedia($size);
}
Example #10
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());
     }
 }
Example #11
0
 function injectAtomEntryData(Dase_Atom_Entry $entry, $user = null, $app_root)
 {
     if (!$user) {
         $user = $this->getUser();
     }
     $entry->setTitle($this->name);
     if ($this->description) {
         $entry->setSummary($this->description);
     }
     $entry->setId($app_root . '/user/' . $user->eid . '/tag/' . $this->ascii_id);
     $updated = $this->updated ? $this->updated : '2005-01-01T00:00:01-06:00';
     $entry->setUpdated($updated);
     $entry->addAuthor($user->eid);
     $entry->addLink($app_root . '/tag/' . $user->eid . '/' . $this->ascii_id . '.atom', 'self');
     $entry->addLink($app_root . '/tag/' . $user->eid . '/' . $this->ascii_id . '/authorized.atom', 'http://daseproject.org/relation/authorized');
     $entry->addLink($app_root . '/tag/' . $user->eid . '/' . $this->ascii_id . '/entry.atom', 'edit');
     $entry->addLink($app_root . '/tag/' . $user->eid . '/' . $this->ascii_id . '/entry.json', 'http://daseproject.org/relation/edit', 'application/json');
     $entry->addLink($app_root . '/tag/' . $user->eid . '/' . $this->ascii_id, 'alternate');
     $tag_cat = new Dase_DBO_TagCategory($this->db);
     $tag_cat->tag_id = $this->id;
     foreach ($tag_cat->find() as $tc) {
         $entry->addCategory($tc->term, 'http://daseproject.org/category/' . $tc->scheme, $tc->label);
     }
     $entry->addCategory($app_root, "http://daseproject.org/category/base_url");
     $entry->addCategory("set", "http://daseproject.org/category/entrytype");
     $entry->addCategory($this->type, "http://daseproject.org/category/tag_type", $this->type);
     if ($this->is_public) {
         $pub = "public";
     } else {
         $pub = "private";
     }
     $entry->addCategory($pub, "http://daseproject.org/category/visibility");
     $entry->addCategory($this->background, "http://daseproject.org/category/background");
     return $entry;
 }
Example #12
0
 function injectAtomEntryData(Dase_Atom_Entry $entry, $collection_ascii_id, $app_root)
 {
     $url = $this->getUrl($collection_ascii_id, $app_root);
     $entry->setTitle($this->attribute_name);
     $entry->setId($url);
     $entry->addLink($url . '.atom');
     $entry->addLink($url . '.atom', 'edit');
     $entry->addCategory('attribute', 'http://daseproject.org/category/entrytype');
     $entry->addCategory($this->html_input_type, 'http://daseproject.org/category/html_input_type');
     $entry->addCategory($this->is_repeatable, 'http://daseproject.org/category/repeatable');
     $entry->addCategory($this->is_required, 'http://daseproject.org/category/required');
     if (!$this->is_on_list_display) {
         $entry->addCategory('0', 'http://daseproject.org/category/list_display');
     } else {
         $entry->addCategory('1', 'http://daseproject.org/category/list_display');
     }
     foreach ($this->getItemTypes() as $type) {
         $entry->addCategory($type->ascii_id, 'http://daseproject.org/category/parent_item_type', $type->name);
     }
     //allows posting
     if (in_array($this->html_input_type, array('checkbox', 'select', 'radio'))) {
         $entry->addLink($url . '/defined', 'http://daseproject.org/relation/defined_values', 'application/atomcat+xml');
     }
     if ($this->modifier_type) {
         $entry->addCategory($this->modifier_type, 'http://daseproject.org/category/modifier_type');
     }
     if ($this->modifier_defined_list) {
         $entry->addCategory($this->modifier_defined_list, 'http://daseproject.org/category/modifier_defined_list');
     }
     foreach ($this->getDefinedValues() as $val) {
         $entry->addCategory($val, 'http://daseproject.org/category/defined_value');
     }
     $entry->setSummary($this->usage_notes);
     $entry->addCategory($this->sort_order, 'http://daseproject.org/category/sort_order');
     //compat
     if (is_numeric($this->updated)) {
         $updated = date(DATE_ATOM, $this->updated);
     } else {
         $updated = $this->updated;
     }
     $entry->setUpdated($updated);
     $entry->addAuthor();
     return $entry;
 }
Example #13
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');
 }
Example #14
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);
     }
 }
Example #15
0
 function injectAtomEntryData(Dase_Atom_Entry $entry, $app_root, $authorize_links = false)
 {
     if (!$this->id) {
         return false;
     }
     /* namespaces */
     $d = Dase_Atom::$ns['d'];
     $thr = Dase_Atom::$ns['thr'];
     /* resources */
     $base_url = $app_root . '/item/' . $this->p_collection_ascii_id . '/' . $this->serial_number;
     /* standard atom stuff */
     $entry->setId($base_url);
     $entry->addAuthor($this->created_by_eid);
     //todo: I think this can be simplified when DASe 1.0 is retired
     if (is_numeric($this->updated)) {
         $entry->setUpdated(date(DATE_ATOM, $this->updated));
     } else {
         $entry->setUpdated($this->updated);
     }
     if (is_numeric($this->created)) {
         $entry->setPublished(date(DATE_ATOM, $this->created));
     } else {
         $entry->setPublished($this->created);
     }
     //atompub
     $entry->setEdited($entry->getUpdated());
     //alternate link
     $entry->addLink($app_root . '/item/' . $this->p_collection_ascii_id . '/' . $this->serial_number, 'alternate');
     //the following 2 links should be unified
     //link to item metadata json, used for editing metadata
     $entry->addLink($app_root . '/item/' . $this->p_collection_ascii_id . '/' . $this->serial_number . '/metadata.json', 'http://daseproject.org/relation/metadata', 'application/json');
     //to which we can POST form-encoded or json metadata pairs:
     $entry->addLink($app_root . '/item/' . $this->p_collection_ascii_id . '/' . $this->serial_number . '/metadata', 'http://daseproject.org/relation/edit-metadata');
     //to which we can POST form-encoded or text/plain:
     $entry->addLink($app_root . '/item/' . $this->p_collection_ascii_id . '/' . $this->serial_number . '/item_type', 'http://daseproject.org/relation/edit-item_type');
     $entry->addLink($app_root . '/item/' . $this->p_collection_ascii_id . '/' . $this->serial_number . '.atom', 'edit', 'application/atom+xml');
     if ($authorize_links) {
         $entry->addLink($app_root . '/item/' . $this->p_collection_ascii_id . '/' . $this->serial_number . '.atom', 'http://daseproject.org/relation/cached', 'application/atom+xml');
     } else {
         $entry->addLink($app_root . '/item/' . $this->p_collection_ascii_id . '/' . $this->serial_number . '/authorized.atom', 'http://daseproject.org/relation/authorized', 'application/atom+xml');
     }
     $entry->addLink($app_root . '/item/' . $this->p_collection_ascii_id . '/' . $this->serial_number . '/content', 'http://daseproject.org/relation/edit-content');
     $entry->addLink($app_root . '/item/' . $this->p_collection_ascii_id . '/' . $this->serial_number . '.json', 'http://daseproject.org/relation/edit', 'application/json');
     $entry->addLink($app_root . '/collection/' . $this->p_collection_ascii_id . '/service', 'service', 'application/atomsvc+xml');
     $entry->addLink($app_root . '/collection/' . $this->p_collection_ascii_id . '/attributes.json', 'http://daseproject.org/relation/attributes', 'application/json');
     /**** COMMENT LINK (threading extension) **********/
     $replies = $entry->addLink($app_root . '/item/' . $this->p_collection_ascii_id . '/' . $this->serial_number . '/comments', 'replies');
     if ($this->comments_count) {
         //lookup
         $replies->setAttributeNS($thr, 'thr:count', $this->comments_count);
         //lookup
         $replies->setAttributeNS($thr, 'thr:updated', $this->comments_updated);
     }
     /* dase categories */
     $entry->setEntrytype('item');
     //allows us to replace all if/when necessary :(
     $entry->addCategory($app_root, "http://daseproject.org/category/base_url");
     $entry->addCategory($this->item_type_ascii_id, 'http://daseproject.org/category/item_type', $this->item_type_name);
     $entry->addCategory($this->p_collection_ascii_id, 'http://daseproject.org/category/collection', $this->collection_name);
     $entry->addCategory($this->id, 'http://daseproject.org/category/item_id');
     $entry->addCategory($this->serial_number, 'http://daseproject.org/category/serial_number');
     if ($this->status) {
         $entry->addCategory($this->status, 'http://daseproject.org/category/status');
     } else {
         $entry->addCategory('public', 'http://daseproject.org/category/status');
     }
     /********* METADATA **********/
     $item_metadata = $this->getMetadata(true);
     foreach ($item_metadata as $row) {
         if ($row['url']) {
             //create metadata LINK
             $metadata_link = $entry->addLink($row['url'], 'http://daseproject.org/relation/metadata-link/' . $this->p_collection_ascii_id . '/' . $row['ascii_id'], '', '', $row['value_text']);
             $metadata_link->setAttributeNS($d, 'd:attribute', $row['attribute_name']);
             $metadata_link->setAttributeNS($d, 'd:edit-id', $app_root . $row['edit-id']);
             if ($row['modifier']) {
                 $metadata_link->setAttributeNS($d, 'd:mod', $row['modifier']);
                 if ($row['modifier_type']) {
                     $metadata_link->setAttributeNS($d, 'd:modtype', $row['modifier_type']);
                 }
             }
         }
     }
     foreach ($item_metadata as $row) {
         if ($row['url']) {
             //already made metadata links
         } else {
             //create metadata CATEGORY
             if (0 == $row['collection_id']) {
                 $meta = $entry->addCategory($row['ascii_id'], 'http://daseproject.org/category/admin_metadata', $row['attribute_name'], $row['value_text']);
             } else {
                 if ($row['is_public']) {
                     $meta = $entry->addCategory($row['ascii_id'], 'http://daseproject.org/category/metadata', $row['attribute_name'], $row['value_text']);
                     $meta->setAttributeNS($d, 'd:edit-id', $app_root . $row['edit-id']);
                 } else {
                     $meta = $entry->addCategory($row['ascii_id'], 'http://daseproject.org/category/private_metadata', $row['attribute_name'], $row['value_text']);
                     $meta->setAttributeNS($d, 'd:edit-id', $app_root . $row['edit-id']);
                 }
                 if ('title' == $row['ascii_id'] || 'Title' == $row['attribute_name']) {
                     $entry->setTitle($row['value_text']);
                 }
                 if ('rights' == $row['ascii_id']) {
                     $entry->setRights($row['value_text']);
                 }
                 if ($row['modifier']) {
                     $meta->setAttributeNS($d, 'd:mod', $row['modifier']);
                     if ($row['modifier_type']) {
                         $meta->setAttributeNS($d, 'd:modtype', $row['modifier_type']);
                     }
                 }
             }
         }
     }
     //this will only "take" if there is not already a title
     $entry->setTitle($this->serial_number);
     /*******  MEDIA  ***********/
     $item_media = $this->getMedia();
     $token = $this->config->getAuth('token');
     if (isset($item_media['enclosure'])) {
         $enc = $item_media['enclosure'];
         if ($authorize_links) {
             $entry->addLink($this->getMediaUrl('enclosure', $app_root, $token), 'enclosure', $enc['mime_type'], $enc['file_size']);
         } else {
             $entry->addLink($this->getMediaUrl('enclosure', $app_root), 'enclosure', $enc['mime_type'], $enc['file_size']);
         }
     }
     /* edit-media link */
     $entry->addLink($this->getEditMediaUrl($app_root), 'edit-media');
     $media_url = $app_root . '/item/' . $this->p_collection_ascii_id . '/' . $this->serial_number . '/media';
     $entry->addLink($media_url, 'http://daseproject.org/relation/add-media');
     /* media rss ext */
     foreach ($this->getMedia() as $size => $med) {
         if ('thumbnail' == $size) {
             $media_thumbnail = $entry->addElement('media:thumbnail', '', Dase_Atom::$ns['media']);
             $media_thumbnail->setAttribute('url', $app_root . $med['url']);
             $media_thumbnail->setAttribute('width', $med['width']);
             $media_thumbnail->setAttribute('height', $med['height']);
         } else {
             if ($size != 'enclosure') {
                 $media_content = $entry->addElement('media:content', '', Dase_Atom::$ns['media']);
                 if ($authorize_links) {
                     $media_content->setAttribute('url', $this->getMediaUrl($size, $app_root, $token));
                 } else {
                     $media_content->setAttribute('url', $this->getMediaUrl($size, $app_root));
                 }
                 if ($med['width'] && $med['height']) {
                     $media_content->setAttribute('width', $med['width']);
                     $media_content->setAttribute('height', $med['height']);
                 }
                 $media_content->setAttribute('fileSize', $med['file_size']);
                 $media_content->setAttribute('type', $med['mime_type']);
                 $media_category = $media_content->appendChild($entry->dom->createElement('media:category'));
                 $media_category->appendChild($entry->dom->createTextNode($size));
             }
         }
     }
     return $entry;
 }
Example #16
0
 function injectAtomEntryData(Dase_Atom_Entry $entry, $collection_ascii_id, $app_root)
 {
     $entry->setTitle($this->name);
     $entry->setId($this->getUrl($collection_ascii_id, $app_root));
     $entry->setSummary($this->description);
     $entry->addLink($this->getUrl($collection_ascii_id, $app_root) . '.atom', 'edit');
     $entry->addLink($this->getUrl($collection_ascii_id, $app_root) . '/attributes.atom', 'http://daseproject.org/relation/item_type/attributes', 'application/atom+xml', '', $this->name . ' Attributes');
     $entry->addLink($this->getUrl($collection_ascii_id, $app_root) . '/attributes.json', 'http://daseproject.org/relation/item_type/attributes', 'application/json', '', $this->name . ' Attributes');
     $entry->addCategory('item_type', 'http://daseproject.org/category/entrytype', 'Item Type');
     if (is_numeric($this->updated)) {
         $updated = date(DATE_ATOM, $this->updated);
     } else {
         $updated = $this->updated;
     }
     $entry->setUpdated($updated);
     $entry->addAuthor();
     return $entry;
 }
Example #17
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);
 }