/** * Converts a Zotero_Tag object to a SimpleXMLElement Atom object * * @return SimpleXMLElement Tag data as SimpleXML element */ public function toAtom($queryParams, $fixedValues = null) { if (!empty($queryParams['content'])) { $content = $queryParams['content']; } else { $content = array('none'); } // TEMP: multi-format support $content = $content[0]; $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>' . '<entry xmlns="' . Zotero_Atom::$nsAtom . '" xmlns:zapi="' . Zotero_Atom::$nsZoteroAPI . '"/>'); $xml->title = $this->name; $author = $xml->addChild('author'); $author->name = Zotero_Libraries::getName($this->libraryID); $author->uri = Zotero_URI::getLibraryURI($this->libraryID, true); $xml->id = Zotero_URI::getTagURI($this); $xml->published = Zotero_Date::sqlToISO8601($this->dateAdded); $xml->updated = Zotero_Date::sqlToISO8601($this->dateModified); $link = $xml->addChild("link"); $link['rel'] = "self"; $link['type'] = "application/atom+xml"; $link['href'] = Zotero_API::getTagURI($this); $link = $xml->addChild('link'); $link['rel'] = 'alternate'; $link['type'] = 'text/html'; $link['href'] = Zotero_URI::getTagURI($this, true); // Count user's linked items if (isset($fixedValues['numItems'])) { $numItems = $fixedValues['numItems']; } else { $numItems = sizeOf($this->getLinkedItems(true)); } $xml->addChild('zapi:numItems', $numItems, Zotero_Atom::$nsZoteroAPI); if ($content == 'html') { $xml->content['type'] = 'xhtml'; $contentXML = new SimpleXMLElement("<div/>"); $contentXML->addAttribute("xmlns", Zotero_Atom::$nsXHTML); $fNode = dom_import_simplexml($xml->content); $subNode = dom_import_simplexml($contentXML); $importedNode = $fNode->ownerDocument->importNode($subNode, true); $fNode->appendChild($importedNode); } else { if ($content == 'json') { $xml->content['type'] = 'application/json'; $xml->content = Zotero_Utilities::formatJSON($this->toJSON()); } } return $xml; }