Example #1
0
 public function __construct($entryNode, $library = null)
 {
     if (!$entryNode) {
         return;
     }
     parent::__construct($entryNode);
     $this->name = $this->title;
     //collection name is the Entry title
     //parse zapi tags
     $this->collectionKey = $entryNode->getElementsByTagNameNS('http://zotero.org/ns/api', 'key')->item(0)->nodeValue;
     $this->collectionVersion = $entryNode->getElementsByTagNameNS('http://zotero.org/ns/api', 'version')->item(0)->nodeValue;
     $this->numCollections = $entryNode->getElementsByTagName('numCollections')->item(0)->nodeValue;
     $this->numItems = $entryNode->getElementsByTagName('numItems')->item(0)->nodeValue;
     $contentNode = $entryNode->getElementsByTagName('content')->item(0);
     if ($contentNode) {
         $contentType = $contentNode->getAttribute('type');
         if ($contentType == 'application/json') {
             $this->pristine = json_decode($contentNode->nodeValue);
             $this->apiObject = json_decode($contentNode->nodeValue, true);
             $this->parentCollectionKey = $this->apiObject['parentCollection'];
             $this->name = $this->apiObject['name'];
         } elseif ($contentType == 'xhtml') {
             //$this->parseXhtmlContent($contentNode);
         }
     }
     if ($library !== null) {
         $this->associateWithLibrary($library);
     }
 }
Example #2
0
 public function __construct($entryNode)
 {
     if (!$entryNode) {
         libZoteroDebug("no entryNode in tag constructor\n");
         return;
     } elseif (is_string($entryNode)) {
         libZoteroDebug("entryNode is string in tag constructor\n");
         $xml = $entryNode;
         $doc = new DOMDocument();
         libZoteroDebug($xml);
         $doc->loadXml($xml);
         $entryNode = $doc->getElementsByTagName('entry')->item(0);
     }
     parent::__construct($entryNode);
     $this->name = $this->title;
     if (!$entryNode) {
         libZoteroDebug("second no entryNode in tag constructor\n");
         return;
     }
     $numItems = $entryNode->getElementsByTagNameNS('http://zotero.org/ns/api', "numItems")->item(0);
     if ($numItems) {
         $this->numItems = (int) $numItems->nodeValue;
     }
     $tagElements = $entryNode->getElementsByTagName("tag");
     $tagElement = $tagElements->item(0);
     $contentNode = $entryNode->getElementsByTagName('content')->item(0);
     if ($contentNode) {
         $contentType = $contentNode->getAttribute('type');
         if ($contentType == 'application/json') {
             $this->pristine = json_decode($contentNode->nodeValue, true);
             $this->apiObject = json_decode($contentNode->nodeValue, true);
         } elseif ($contentType == 'xhtml') {
             //$this->parseXhtmlContent($contentNode);
         }
     }
 }
Example #3
0
 public function __construct($entryNode)
 {
     parent::__construct($entryNode);
 }
Example #4
0
 public function __construct($entryNode = null, $library = null)
 {
     if (!$entryNode) {
         return;
     } elseif (is_string($entryNode)) {
         $xml = $entryNode;
         $doc = new DOMDocument();
         $doc->loadXml($xml);
         $entryNode = $doc->getElementsByTagName('entry')->item(0);
     }
     parent::__construct($entryNode);
     //check if we have multiple subcontent nodes
     $subcontentNodes = $entryNode->getElementsByTagNameNS("http://zotero.org/ns/api", "subcontent");
     // Extract the zapi elements: object key, version, itemType, year, numChildren, numTags
     $this->itemKey = $entryNode->getElementsByTagNameNS('http://zotero.org/ns/api', 'key')->item(0)->nodeValue;
     $this->itemVersion = $entryNode->getElementsByTagNameNS('http://zotero.org/ns/api', 'version')->item(0)->nodeValue;
     $this->itemType = $entryNode->getElementsByTagNameNS('http://zotero.org/ns/api', 'itemType')->item(0)->nodeValue;
     // Look for numTags node
     // this may be always present in v2 api
     $numTagsNode = $entryNode->getElementsByTagNameNS('http://zotero.org/ns/api', "numTags")->item(0);
     if ($numTagsNode) {
         $this->numTags = $numTagsNode->nodeValue;
     }
     // Look for year node
     $yearNode = $entryNode->getElementsByTagNameNS('http://zotero.org/ns/api', "year")->item(0);
     if ($yearNode) {
         $this->year = $yearNode->nodeValue;
     }
     // Look for numChildren node
     $numChildrenNode = $entryNode->getElementsByTagNameNS('http://zotero.org/ns/api', "numChildren")->item(0);
     if ($numChildrenNode) {
         $this->numChildren = $numChildrenNode->nodeValue;
     }
     // Look for creatorSummary node - only present if there are non-empty creators
     $creatorSummaryNode = $entryNode->getElementsByTagNameNS('http://zotero.org/ns/api', "creatorSummary")->item(0);
     if ($creatorSummaryNode) {
         $this->creatorSummary = $creatorSummaryNode->nodeValue;
     }
     // pull out and parse various subcontent nodes, or parse the single content node
     if ($subcontentNodes->length > 0) {
         for ($i = 0; $i < $subcontentNodes->length; $i++) {
             $scnode = $subcontentNodes->item($i);
             $this->parseContentNode($scnode);
         }
     } else {
         $contentNode = $entryNode->getElementsByTagName('content')->item(0);
         $this->parseContentNode($contentNode);
     }
     if ($library !== null) {
         $this->associateWithLibrary($library);
     }
 }
Example #5
0
 public function __construct($entryNode = null)
 {
     if (!$entryNode) {
         return;
     } elseif (is_string($entryNode)) {
         $xml = $entryNode;
         $doc = new DOMDocument();
         $doc->loadXml($xml);
         $entryNode = $doc->getElementsByTagName('entry')->item(0);
     }
     parent::__construct($entryNode);
     if (!$entryNode) {
         return;
     }
     $contentNode = $entryNode->getElementsByTagName('content')->item(0);
     $contentType = parent::getContentType($entryNode);
     if ($contentType == 'application/json') {
         $this->apiObject = json_decode($contentNode->nodeValue, true);
         //$this->etag = $contentNode->getAttribute('etag');
         $this->name = $this->apiObject['name'];
         $this->ownerID = $this->apiObject['owner'];
         $this->owner = $this->ownerID;
         $this->groupType = $this->apiObject['type'];
         $this->description = $this->apiObject['description'];
         $this->url = $this->apiObject['url'];
         $this->libraryEditing = $this->apiObject['libraryEditing'];
         $this->libraryReading = $this->apiObject['libraryReading'];
         $this->fileEditing = $this->apiObject['fileEditing'];
     }
     if (!empty($this->apiObject['admins'])) {
         $this->adminIDs = $this->apiObject['admins'];
     } else {
         $this->adminIDs = array();
     }
     if ($this->ownerID) {
         $this->adminIDs[] = $this->ownerID;
     }
     if (!empty($this->apiObject['members'])) {
         $this->memberIDs = $this->apiObject['members'];
     } else {
         $this->memberIDs = array();
     }
     $this->numItems = $entryNode->getElementsByTagNameNS('http://zotero.org/ns/api', 'numItems')->item(0)->nodeValue;
     $contentNodes = $entryNode->getElementsByTagName("content");
     if ($contentNodes->length > 0) {
         $cNode = $contentNodes->item(0);
         if ($cNode->getAttribute('type') == 'application/json') {
             $jsonObject = json_decode($cNode->nodeValue, true);
             //parse out relevant values from the json and put them on our object
             $this->name = $jsonObject['name'];
             $this->ownerID = $jsonObject['owner'];
             $this->owner = $this->ownerID;
             $this->type = $jsonObject['type'];
             $this->groupType = $this->type;
             $this->description = $jsonObject['description'];
             $this->url = $jsonObject['url'];
             $this->hasImage = isset($jsonObject['hasImage']) ? $jsonObject['hasImage'] : 0;
             $this->libraryEditing = $jsonObject['libraryEditing'];
             $this->memberIDs = isset($jsonObject['members']) ? $jsonObject['members'] : array();
             $this->members = $this->memberIDs;
             $this->adminIDs = isset($jsonObject['admins']) ? $jsonObject['admins'] : array();
             $this->adminIDs[] = $jsonObject['owner'];
             $this->admins = $this->adminIDs;
         } elseif ($cNode->getAttribute('type') == 'application/xml') {
             $groupElements = $entryNode->getElementsByTagName("group");
             $groupElement = $groupElements->item(0);
             if (!$groupElement) {
                 return;
             }
             $groupAttributes = $groupElement->attributes;
             $this->properties = array();
             foreach ($groupAttributes as $attrName => $attrNode) {
                 $this->properties[$attrName] = urldecode($attrNode->value);
                 if ($attrName == 'name') {
                     $this->{$attrName} = $attrNode->value;
                 } else {
                     $this->{$attrName} = urldecode($attrNode->value);
                 }
             }
             $this->groupID = $this->properties['id'];
             $description = $entryNode->getElementsByTagName("description")->item(0);
             if ($description) {
                 $this->properties['description'] = $description->nodeValue;
                 $this->description = $description->nodeValue;
             }
             $url = $entryNode->getElementsByTagName("url")->item(0);
             if ($url) {
                 $this->properties['url'] = $url->nodeValue;
                 $this->url = $url->nodeValue;
             }
             $this->adminIDs = array();
             $admins = $entryNode->getElementsByTagName("admins")->item(0);
             if ($admins) {
                 $this->adminIDs = $admins === null ? array() : explode(" ", $admins->nodeValue);
             }
             $this->adminIDs[] = $this->owner;
             $this->memberIDs = array();
             $members = $entryNode->getElementsByTagName("members")->item(0);
             if ($members) {
                 $this->memberIDs = $members === null ? array() : explode(" ", $members->nodeValue);
             }
             //initially disallow library access
             $this->userReadable = false;
             $this->userEditable = false;
         }
     }
     //get groupID from zapi:groupID if available
     if ($entryNode->getElementsByTagNameNS('http://zotero.org/ns/api', 'groupID')->length > 0) {
         $this->groupID = $entryNode->getElementsByTagNameNS('http://zotero.org/ns/api', 'groupID')->item(0)->nodeValue;
         $this->id = $this->groupID;
     } else {
         //get link nodes and extract groupID
         $linkNodes = $entryNode->getElementsByTagName("link");
         if ($linkNodes->length > 0) {
             for ($i = 0; $i < $linkNodes->length; $i++) {
                 $linkNode = $linkNodes->item($i);
                 if ($linkNode->getAttribute('rel') == 'self') {
                     $selfHref = $linkNode->getAttribute('href');
                     $matches = array();
                     preg_match('/^https:\\/\\/.{3,6}\\.zotero\\.org\\/groups\\/([0-9]+)$/', $selfHref, $matches);
                     if (isset($matches[1])) {
                         $this->groupID = intval($matches[1]);
                         $this->id = $this->groupID;
                     }
                 }
             }
         }
     }
     //initially disallow library access
     $this->userReadable = false;
     $this->userEditable = false;
 }