public function writeItems($items) { $writeItems = array(); foreach ($items as $item) { $itemKey = $item->get('itemKey'); if ($itemKey == "") { $newItemKey = Zotero_Lib_Utils::getKey(); $item->set('itemKey', $newItemKey); $item->set('itemVersion', 0); } $writeItems[] = $item; //add separate note items if this item has any $itemNotes = $item->get('notes'); if ($itemNotes && count($itemNotes) > 0) { foreach ($itemNotes as $note) { $note->set('parentItem', $item->get('itemKey')); $note->set('itemKey', Zotero_Lib_Utils::getKey()); $note->set('itemVersion', 0); $writeItems[] = $note; } } } $config = array('target' => 'items', 'libraryType' => $this->owningLibrary->libraryType, 'libraryID' => $this->owningLibrary->libraryID, 'content' => 'json'); $requestUrl = $this->owningLibrary->apiRequestString($config); $chunks = array_chunk($writeItems, 50); foreach ($chunks as $chunk) { $writeArray = array(); foreach ($chunk as $item) { $writeArray[] = $item->writeApiObject(); } $requestData = json_encode(array('items' => $writeArray)); $writeResponse = $this->owningLibrary->_request($requestUrl, 'POST', $requestData, array('Content-Type' => 'application/json')); if ($writeResponse->isError()) { foreach ($chunk as $item) { $item->writeFailure = array('code' => $writeResponse->getStatus(), 'message' => $writeResponse->getBody()); } } else { Zotero_Lib_Utils::UpdateObjectsFromWriteResponse($chunk, $writeResponse); } } return $writeItems; }
public static function getKey() { $baseString = "23456789ABCDEFGHIJKMNPQRSTUVWXZ"; return Zotero_Lib_Utils::randomString(8, $baseString); }
function display_zotero_items($items) { $html = ''; foreach ($items as $item) { $html .= Zotero_Lib_Utils::wrapLinks($item->bibContent); $html .= htmlspecialchars_decode($item->subContents['coins']); } return wpautop($html); }
public function parseContentNode($node) { $type = $node->getAttributeNS('http://zotero.org/ns/api', 'type'); if ($type == 'application/json' || $type == 'json') { $this->pristine = json_decode($node->nodeValue, true); $this->apiObject = json_decode($node->nodeValue, true); $this->apiObj =& $this->apiObject; if (isset($this->apiObject['creators'])) { $this->creators = $this->apiObject['creators']; } else { $this->creators = array(); } $this->itemVersion = isset($this->apiObject['itemVersion']) ? $this->apiObject['itemVersion'] : 0; $this->parentItemKey = isset($this->apiObject['parentItem']) ? $this->apiObject['parentItem'] : false; if ($this->itemType == 'attachment') { $this->mimeType = $this->apiObject['contentType']; $this->translatedMimeType = Zotero_Lib_Utils::translateMimeType($this->mimeType); } if (array_key_exists('linkMode', $this->apiObject)) { $this->linkMode = $this->apiObject['linkMode']; } $this->synced = true; } elseif ($type == 'bib') { $bibNode = $node->getElementsByTagName('div')->item(0); $this->bibContent = $bibNode->ownerDocument->saveXML($bibNode); } $contentString = ''; $childNodes = $node->childNodes; foreach ($childNodes as $childNode) { $contentString .= $childNode->ownerDocument->saveXML($childNode); } $this->subContents[$type] = $contentString; }
/** * Get recently created public groups * * @return array $groups */ public function fetchRecentGroups() { return array(); $aparams = array('target' => 'groups', 'limit' => '10', 'content' => 'json', 'order' => 'dateAdded', 'sort' => 'desc', 'fq' => '-GroupType:Private'); $reqUrl = $this->apiRequestString($aparams); $response = $this->_request($reqUrl, 'GET'); if ($response->isError()) { return false; } $entries = Zotero_Lib_Utils::getEntryNodes($response->getRawBody()); $groups = array(); foreach ($entries as $entry) { $group = new Zotero_Group($entry); $groups[] = $group; } return $groups; }
/** * Load a single collection by collectionKey * * @param string $collectionKey * @return Zotero_Collection */ public function fetchCollection($collectionKey) { $aparams = array('target' => 'collection', 'content' => 'json', 'collectionKey' => $collectionKey); $reqUrl = $this->owningLibrary->apiRequestString($aparams); $response = $this->owningLibrary->_request($reqUrl, 'GET'); if ($response->isError()) { return false; throw new Exception("Error fetching collection"); } $entry = Zotero_Lib_Utils::getFirstEntryNode($response->getRawBody()); if ($entry == null) { return false; } $collection = new Zotero_Collection($entry, $this); $this->addCollection($collection); return $collection; }