/** * Converts a Zotero_Tag object to a SimpleXMLElement Atom object * * @param object $tag Zotero_Tag object * @param string $content * @return SimpleXMLElement Tag data as SimpleXML element */ public function toAtom($content = array('none'), $apiVersion = null, $fixedValues = null) { // TEMP: multi-format support $content = $content[0]; $xml = new SimpleXMLElement('<entry xmlns="' . Zotero_Atom::$nsAtom . '" ' . 'xmlns:zapi="' . Zotero_Atom::$nsZoteroAPI . '" ' . 'xmlns:zxfer="' . Zotero_Atom::$nsZoteroTransfer . '"/>'); $xml->title = $this->name; $author = $xml->addChild('author'); $author->name = Zotero_Libraries::getName($this->libraryID); $author->uri = Zotero_URI::getLibraryURI($this->libraryID); $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_Atom::getTagURI($this); $link = $xml->addChild('link'); $link['rel'] = 'alternate'; $link['type'] = 'text/html'; $link['href'] = Zotero_URI::getTagURI($this); // Count user's linked items if (isset($fixedValues['numItems'])) { $numItems = $fixedValues['numItems']; } else { $itemIDs = $this->getLinkedItems(); $numItems = sizeOf($itemIDs); } $xml->addChild('zapi:numItems', $numItems, Zotero_Atom::$nsZoteroAPI); if ($content == 'html') { $xml->content['type'] = 'xhtml'; //$fullXML = Zotero_Tags::convertTagToXML($tag); $fullStr = "<div/>"; $fullXML = new SimpleXMLElement($fullStr); $fullXML->addAttribute("xmlns", Zotero_Atom::$nsXHTML); $fNode = dom_import_simplexml($xml->content); $subNode = dom_import_simplexml($fullXML); $importedNode = $fNode->ownerDocument->importNode($subNode, true); $fNode->appendChild($importedNode); //$arr = $tag->serialize(); //require_once("views/zotero/tags.php") } else { if ($content == 'full') { $xml->content['type'] = 'application/xml'; $fullXML = $this->toXML(); $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; }
/** * 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; }