예제 #1
0
 public function toAtom($queryParams)
 {
     if (!empty($queryParams['content'])) {
         $content = $queryParams['content'];
     } else {
         $content = array('none');
     }
     // TEMP: multi-format support
     $content = $content[0];
     if (!$this->loaded) {
         $this->load();
     }
     $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>' . '<entry xmlns="' . Zotero_Atom::$nsAtom . '" ' . 'xmlns:zapi="' . Zotero_Atom::$nsZoteroAPI . '" ' . 'xmlns:zxfer="' . Zotero_Atom::$nsZoteroTransfer . '"/>');
     $title = $this->name ? $this->name : '[Untitled]';
     $xml->title = $title;
     $author = $xml->addChild('author');
     $ownerLibraryID = Zotero_Users::getLibraryIDFromUserID($this->ownerUserID);
     $author->name = Zotero_Users::getUsername($this->ownerUserID);
     $author->uri = Zotero_URI::getLibraryURI($ownerLibraryID);
     $xml->id = Zotero_URI::getGroupURI($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::getGroupURI($this);
     $link = $xml->addChild('link');
     $link['rel'] = 'alternate';
     $link['type'] = 'text/html';
     $link['href'] = Zotero_URI::getGroupURI($this);
     $xml->addChild('zapi:groupID', $this->id, Zotero_Atom::$nsZoteroAPI);
     $xml->addChild('zapi:numItems', $this->numItems(), Zotero_Atom::$nsZoteroAPI);
     if ($content == 'html') {
         $xml->content['type'] = 'html';
         $htmlXML = $this->toHTML();
         $xml->content->div = '';
         $xml->content->div['xmlns'] = Zotero_Atom::$nsXHTML;
         $fNode = dom_import_simplexml($xml->content->div);
         $subNode = dom_import_simplexml($htmlXML);
         $importedNode = $fNode->ownerDocument->importNode($subNode, true);
         $fNode->appendChild($importedNode);
     } else {
         if ($content == 'json') {
             $xml->content['type'] = 'application/json';
             $xml->content['etag'] = $this->etag;
             // Deprecated
             if ($queryParams['v'] < 2) {
                 $xml->content->addAttribute("zapi:etag", $this->etag, Zotero_Atom::$nsZoteroAPI);
             }
             $xml->content = Zotero_Utilities::formatJSON($this->toJSON($queryParams, true));
         } else {
             if ($content == 'full') {
                 $xml->content['type'] = 'application/xml';
                 $fullXML = $this->toXML();
                 $fNode = dom_import_simplexml($xml->content);
                 $subNode = dom_import_simplexml($fullXML);
                 $importedNode = $fNode->ownerDocument->importNode($subNode, true);
                 $fNode->appendChild($importedNode);
             }
         }
     }
     return $xml;
 }
예제 #2
0
 public static function toJSON($libraryID)
 {
     // TODO: cache
     $libraryType = Zotero_Libraries::getType($libraryID);
     if ($libraryType == 'user') {
         $objectUserID = Zotero_Users::getUserIDFromLibraryID($libraryID);
         $json = ['type' => $libraryType, 'id' => $objectUserID, 'name' => self::getName($libraryID), 'links' => ['alternate' => ['href' => Zotero_URI::getUserURI($objectUserID, true), 'type' => 'text/html']]];
     } else {
         if ($libraryType == 'publications') {
             $objectUserID = Zotero_Users::getUserIDFromLibraryID($libraryID);
             $json = ['type' => $libraryType, 'id' => $objectUserID, 'name' => self::getName($libraryID), 'links' => ['alternate' => ['href' => Zotero_URI::getUserURI($objectUserID, true) . "/publications", 'type' => 'text/html']]];
         } else {
             if ($libraryType == 'group') {
                 $objectGroupID = Zotero_Groups::getGroupIDFromLibraryID($libraryID);
                 $group = Zotero_Groups::get($objectGroupID);
                 $json = ['type' => $libraryType, 'id' => $objectGroupID, 'name' => self::getName($libraryID), 'links' => ['alternate' => ['href' => Zotero_URI::getGroupURI($group, true), 'type' => 'text/html']]];
             } else {
                 throw new Exception("Invalid library type '{$libraryType}'");
             }
         }
     }
     return $json;
 }
예제 #3
0
 public function toAtom($content = array('none'), $queryParams, $apiVersion = null)
 {
     // TODO: multi-format support
     $content = $content[0];
     if (!$this->loaded) {
         $this->load();
     }
     $xml = new SimpleXMLElement('<entry xmlns="' . Zotero_Atom::$nsAtom . '" ' . 'xmlns:zapi="' . Zotero_Atom::$nsZoteroAPI . '" ' . 'xmlns:zxfer="' . Zotero_Atom::$nsZoteroTransfer . '"/>');
     $title = $this->name ? $this->name : '[Untitled]';
     $xml->title = $title;
     $author = $xml->addChild('author');
     $ownerLibraryID = Zotero_Users::getLibraryIDFromUserID($this->ownerUserID);
     $author->name = Zotero_Users::getUsername($this->ownerUserID);
     $author->uri = Zotero_URI::getLibraryURI($ownerLibraryID);
     $xml->id = Zotero_URI::getGroupURI($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::getGroupURI($this);
     $link = $xml->addChild('link');
     $link['rel'] = 'alternate';
     $link['type'] = 'text/html';
     $link['href'] = Zotero_URI::getGroupURI($this);
     $xml->addChild('zapi:numItems', $this->numItems(), Zotero_Atom::$nsZoteroAPI);
     if ($content == 'html') {
         $xml->content['type'] = 'html';
         $htmlXML = $this->toHTML();
         $xml->content->div = '';
         $xml->content->div['xmlns'] = Zotero_Atom::$nsXHTML;
         $fNode = dom_import_simplexml($xml->content->div);
         $subNode = dom_import_simplexml($htmlXML);
         $importedNode = $fNode->ownerDocument->importNode($subNode, true);
         $fNode->appendChild($importedNode);
     } else {
         if ($content == 'json') {
             $xml->content['type'] = 'application/json';
             $xml->content = $this->toJSON(false, $queryParams['pprint'], true);
         } else {
             if ($content == 'full') {
                 $xml->content['type'] = 'application/xml';
                 $fullXML = $this->toXML();
                 $fNode = dom_import_simplexml($xml->content);
                 $subNode = dom_import_simplexml($fullXML);
                 $importedNode = $fNode->ownerDocument->importNode($subNode, true);
                 $fNode->appendChild($importedNode);
             }
         }
     }
     return $xml;
 }