예제 #1
0
 /**
  * Converts a Zotero_Collection object to a SimpleXMLElement Atom object
  *
  * @param	object				$item		Zotero_Collection object
  * @param	string				$content
  * @return	SimpleXMLElement					Collection data as SimpleXML element
  */
 public static function convertCollectionToAtom(Zotero_Collection $collection, $content = array('none'))
 {
     // TEMP: multi-format support
     $content = $content[0];
     $xml = new SimpleXMLElement('<entry xmlns="' . Zotero_Atom::$nsAtom . '" xmlns:zapi="' . Zotero_Atom::$nsZoteroAPI . '"/>');
     $title = $collection->name ? $collection->name : '[Untitled]';
     $xml->title = $title;
     $author = $xml->addChild('author');
     // TODO: group item creator
     $author->name = Zotero_Libraries::getName($collection->libraryID);
     $author->uri = Zotero_URI::getLibraryURI($collection->libraryID);
     $xml->id = Zotero_URI::getCollectionURI($collection);
     $xml->published = Zotero_Date::sqlToISO8601($collection->dateAdded);
     $xml->updated = Zotero_Date::sqlToISO8601($collection->dateModified);
     $link = $xml->addChild("link");
     $link['rel'] = "self";
     $link['type'] = "application/atom+xml";
     $link['href'] = Zotero_Atom::getCollectionURI($collection);
     $parent = $collection->parent;
     if ($parent) {
         $parentCol = self::get($collection->libraryID, $parent);
         $link = $xml->addChild("link");
         $link['rel'] = "up";
         $link['type'] = "application/atom+xml";
         $link['href'] = Zotero_Atom::getCollectionURI($parentCol);
     }
     $link = $xml->addChild('link');
     $link['rel'] = 'alternate';
     $link['type'] = 'text/html';
     $link['href'] = Zotero_URI::getCollectionURI($collection);
     $xml->addChild('zapi:key', $collection->key, Zotero_Atom::$nsZoteroAPI);
     $collections = $collection->getChildCollections();
     $xml->addChild('zapi:numCollections', sizeOf($collections), Zotero_Atom::$nsZoteroAPI);
     $xml->addChild('zapi:numItems', $collection->numItems(), Zotero_Atom::$nsZoteroAPI);
     if ($content == 'json') {
         $xml->content['type'] = 'application/json';
         $xml->content->addAttribute('zapi:etag', $collection->etag, Zotero_Atom::$nsZoteroAPI);
         // TODO: remove non-namespaced attribute
         $xml->content['etag'] = $collection->etag;
         $xml->content = $collection->toJSON();
     } else {
         if ($content == 'full') {
             $xml->content['type'] = 'application/xml';
             $fullXML = Zotero_Collections::convertCollectionToXML($collection);
             $fullXML->addAttribute("xmlns", Zotero_Atom::$nsZoteroTransfer);
             $fNode = dom_import_simplexml($xml->content);
             $subNode = dom_import_simplexml($fullXML);
             $importedNode = $fNode->ownerDocument->importNode($subNode, true);
             $fNode->appendChild($importedNode);
         }
     }
     return $xml;
 }