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; }