PageRenderTime 59ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/build/libZoteroSingle.php

https://github.com/kmlawson/libZotero
PHP | 3743 lines | 2517 code | 375 blank | 851 comment | 281 complexity | 6ae39a95a01a63191a39ca804dd370fe MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Zotero specific exception class with no added functionality
  4. *
  5. * @package libZotero
  6. */
  7. class Zotero_Exception extends Exception
  8. {
  9. }
  10. /**
  11. * Explicit mappings for Zotero
  12. *
  13. * @package libZotero
  14. */
  15. class Zotero_Mappings
  16. {
  17. public $itemTypes = array();
  18. public $itemFields = array();
  19. public $itemTypeCreatorTypes = array();
  20. public $creatorFields = array();
  21. }
  22. /**
  23. * Representation of a Zotero Feed (ATOM)
  24. *
  25. * @package libZotero
  26. */
  27. class Zotero_Feed
  28. {
  29. /**
  30. * @var string
  31. */
  32. public $lastModified;
  33. /**
  34. * @var string
  35. */
  36. public $title;
  37. /**
  38. * @var string
  39. */
  40. public $dateUpdated;
  41. /**
  42. * @var int
  43. */
  44. public $totalResults;
  45. /**
  46. * @var int
  47. */
  48. public $apiVersion;
  49. /**
  50. * @var string
  51. */
  52. public $id;
  53. /**
  54. * @var array
  55. */
  56. public $links = array();
  57. /**
  58. * @var array
  59. */
  60. public $entries = array();
  61. public $entryNodes;
  62. public function __construct($doc)
  63. {
  64. if(!($doc instanceof DOMDocument)){
  65. $domdoc = new DOMDocument();
  66. $domdoc->loadXml($doc);
  67. $doc = $domdoc;
  68. }
  69. foreach($doc->getElementsByTagName("feed") as $feed){
  70. $this->title = $feed->getElementsByTagName("title")->item(0)->nodeValue;
  71. $this->id = $feed->getElementsByTagName("id")->item(0)->nodeValue;
  72. $this->dateUpdated = $feed->getElementsByTagName("updated")->item(0)->nodeValue;
  73. //$this->apiVersion = $feed->getElementsByTagName("apiVersion")->item(0)->nodeValue;//apiVersion being removed from zotero responses
  74. $this->totalResults = $feed->getElementsByTagName("totalResults")->item(0)->nodeValue;
  75. // Get all of the link elements
  76. foreach($feed->childNodes as $childNode){
  77. if($childNode->nodeName == "link"){
  78. $linkNode = $childNode;
  79. $this->links[$linkNode->getAttribute('rel')] = array('type'=>$linkNode->getAttribute('type'), 'href'=>$linkNode->getAttribute('href'));
  80. }
  81. }
  82. $entryNodes = $doc->getElementsByTagName("entry");
  83. $this->entryNodes = $entryNodes;
  84. /*
  85. //detect zotero entry type with sample entry node and parse entries appropriately
  86. $firstEntry = $entryNodes->item(0);
  87. $this->entryType = $this->detectZoteroEntryType($firstEntry);
  88. foreach($entryNodes as $entryNode){
  89. switch($this->entryType) {
  90. case 'item': $entry = new Zotero_Item($entryNode); break;
  91. case 'collection': $entry = new Zotero_Collection($entryNode); break;
  92. case 'group': $entry = new Zotero_Group($entryNode); break;
  93. case 'user': $entry = new Zotero_User($entryNode); break;
  94. case 'tag': $entry = new Zotero_Tag($entryNode); break;
  95. default: throw new Zend_Exception("Unknown entry type");
  96. }
  97. $this->entries[] = $entry;
  98. }
  99. */
  100. }
  101. }
  102. public function detectZoteroEntryType($entryNode){
  103. $itemTypeNodes = $entryNode->getElementsByTagName("itemType");
  104. $numCollectionsNodes = $entryNode->getElementsByTagName("numCollections");
  105. $numItemsNodes = $entryNode->getElementsByTagName("numItems");
  106. /*
  107. $itemType = $xpath->evaluate("//zapi:itemType")->item(0)->nodeValue;
  108. $collectionKey = $xpath->evaluate("//zapi:collectionKey")->item(0)->nodeValue;
  109. $numItems = $xpath->evaluate("//zapi:numItems")->item(0)->nodeValue;
  110. */
  111. if($itemTypeNodes->length) return 'item';
  112. if($numCollectionsNodes->length) return 'collection';
  113. if($numItemsNodes->length && !($collectionKeyNodes->length)) return 'tag';
  114. //if($userID) return 'user';
  115. //if($groupID) return 'group';
  116. }
  117. public function nestEntries(){
  118. // Look for item and collection entries with rel="up" links and move them under their parent entry
  119. if($nest && ($entryType == "collections" || $entryType == "items")){
  120. foreach($this->feed->entries as $key => $entry){
  121. if(isset($entry->links['up']['application/atom+xml'])){
  122. // This flag will be set to true if a parent is found
  123. $this->foundParent = false;
  124. // Search for a parent
  125. $this->nestEntry($entry, $this->feed->entries);
  126. // If we found a parent to nest under, remove the entry from the top level
  127. if($this->foundParent == true){
  128. unset($this->feed->entries[$key]);
  129. }
  130. }
  131. }
  132. }
  133. }
  134. public function dataObject()
  135. {
  136. $jsonItem = new stdClass;
  137. $jsonItem->lastModified = $this->lastModified;
  138. $jsonItem->title = $this->title;
  139. $jsonItem->dateUpdated = $this->dateUpdated;
  140. $jsonItem->totalResults = $this->totalResults;
  141. $jsonItem->id = $this->id;
  142. // foreach($this->links as $link){
  143. // $jsonItem->links[] = $link;
  144. // }
  145. $jsonItem->links = $this->links;
  146. $jsonItem->entries = array();
  147. foreach($this->entries as $entry){
  148. $jsonItem->entries[] = $entry->dataObject();
  149. }
  150. return $jsonItem;
  151. }
  152. }
  153. /**
  154. * Zotero API Feed entry (ATOM)
  155. *
  156. * @package libZotero
  157. */
  158. class Zotero_Entry
  159. {
  160. /**
  161. * @var string
  162. */
  163. public $title;
  164. /**
  165. * @var string
  166. */
  167. public $dateAdded;
  168. /**
  169. * @var string
  170. */
  171. public $dateUpdated;
  172. /**
  173. * @var string
  174. */
  175. public $id;
  176. /**
  177. * @var array
  178. */
  179. public $links = array();
  180. /**
  181. * @var array
  182. */
  183. public $author = array();
  184. public $contentArray = array();
  185. /**
  186. * @var array
  187. */
  188. public $entries = array();
  189. public function __construct($entryNode)
  190. {
  191. $parseFields = array('title', 'id', 'dateAdded', 'dateUpdated', 'author');
  192. $this->title = $entryNode->getElementsByTagName("title")->item(0)->nodeValue;
  193. $this->id = $entryNode->getElementsByTagName("id")->item(0)->nodeValue;
  194. $this->dateAdded = $entryNode->getElementsByTagName("published")->item(0)->nodeValue;
  195. $this->dateUpdated = $entryNode->getElementsByTagName("updated")->item(0)->nodeValue;
  196. //try to parse author node if it's there
  197. try{
  198. $author = array();
  199. $authorNode = $entryNode->getElementsByTagName('author')->item(0);
  200. $author['name'] = $authorNode->getElementsByTagName('name')->item(0)->nodeValue;
  201. $author['uri'] = $authorNode->getElementsByTagName('uri')->item(0)->nodeValue;
  202. $this->author = $author;
  203. }
  204. catch(Exception $e){
  205. }
  206. // Get all of the link elements
  207. foreach($entryNode->getElementsByTagName("link") as $linkNode){
  208. if($linkNode->getAttribute('rel') == "enclosure"){
  209. $this->links['enclosure'][$linkNode->getAttribute('type')] = array(
  210. 'href'=>$linkNode->getAttribute('href'),
  211. 'title'=>$linkNode->getAttribute('title'),
  212. 'length'=>$linkNode->getAttribute('length'));
  213. }
  214. else{
  215. $this->links[$linkNode->getAttribute('rel')][$linkNode->getAttribute('type')] = array(
  216. 'href'=>$linkNode->getAttribute('href')
  217. );
  218. }
  219. }
  220. }
  221. public function getContentType($entryNode){
  222. $contentNode = $entryNode->getElementsByTagName('content')->item(0);
  223. if($contentNode) return $contentNode->getAttribute('type') || $contentNode->getAttribute('zapi:type');
  224. else return false;
  225. }
  226. }
  227. /**
  228. * Representation of a Zotero Collection
  229. *
  230. * @package libZotero
  231. * @see Zotero_Entry
  232. */
  233. class Zotero_Collection extends Zotero_Entry
  234. {
  235. /**
  236. * @var int
  237. */
  238. public $collectionKey = null;
  239. public $name = '';
  240. /**
  241. * @var int
  242. */
  243. public $numCollections = 0;
  244. /**
  245. * @var int
  246. */
  247. public $numItems = 0;
  248. public $topLevel;
  249. /**
  250. * @var string
  251. */
  252. public $parentCollectionKey = false;
  253. public $childKeys = array();
  254. public function __construct($entryNode)
  255. {
  256. if(!$entryNode){
  257. return;
  258. }
  259. parent::__construct($entryNode);
  260. // Extract the collectionKey
  261. $this->collectionKey = $entryNode->getElementsByTagNameNS('*', 'key')->item(0)->nodeValue;
  262. $this->numCollections = $entryNode->getElementsByTagName('numCollections')->item(0)->nodeValue;
  263. $this->numItems = $entryNode->getElementsByTagName('numItems')->item(0)->nodeValue;
  264. $contentNode = $entryNode->getElementsByTagName('content')->item(0);
  265. $contentType = parent::getContentType($entryNode);
  266. if($contentType == 'application/json'){
  267. $this->contentArray = json_decode($contentNode->nodeValue, true);
  268. $this->etag = $contentNode->getAttribute('etag');
  269. $this->parentCollectionKey = $this->contentArray['parent'];
  270. $this->name = $this->contentArray['name'];
  271. }
  272. elseif($contentType == 'xhtml'){
  273. //$this->parseXhtmlContent($contentNode);
  274. }
  275. }
  276. public function collectionJson(){
  277. return json_encode(array('name'=>$collection->name, 'parent'=>$collection->parentCollectionKey));
  278. }
  279. public function dataObject() {
  280. $jsonItem = new stdClass;
  281. //inherited from Entry
  282. $jsonItem->title = $this->title;
  283. $jsonItem->dateAdded = $this->dateAdded;
  284. $jsonItem->dateUpdated = $this->dateUpdated;
  285. $jsonItem->id = $this->id;
  286. $jsonItem->links = $this->links;
  287. $jsonItem->collectionKey = $this->collectionKey;
  288. $jsonItem->childKeys = $this->childKeys;
  289. $jsonItem->parentCollectionKey = $this->parentCollectionKey;
  290. return $jsonItem;
  291. }
  292. }
  293. /**
  294. * Representation of the set of collections belonging to a particular Zotero library
  295. *
  296. * @package libZotero
  297. */
  298. class Zotero_Collections
  299. {
  300. public $orderedArray;
  301. public $collectionObjects;
  302. public $dirty;
  303. public $loaded;
  304. public function __construct(){
  305. $this->orderedArray = array();
  306. $this->collectionObjects = array();
  307. }
  308. public static function sortByTitleCompare($a, $b){
  309. if(strtolower($a->title) == strtolower($b->title)){
  310. return 0;
  311. }
  312. if(strtolower($a->title) < strtolower($b->title)){
  313. return -1;
  314. }
  315. return 1;
  316. }
  317. public function addCollection($collection) {
  318. $this->collectionObjects[$collection->collectionKey] = $collection;
  319. $this->orderedArray[] = $collection;
  320. }
  321. public function getCollection($collectionKey) {
  322. if(isset($this->collectionObjects[$collectionKey])){
  323. return $this->collectionObjects[$collectionKey];
  324. }
  325. return false;
  326. }
  327. public function addCollectionsFromFeed($feed) {
  328. $entries = $feed->entryNodes;
  329. if(empty($entries)){
  330. var_dump($feed);
  331. die;
  332. return array();
  333. }
  334. $addedCollections = array();
  335. foreach($entries as $entry){
  336. $collection = new Zotero_Collection($entry);
  337. $this->addCollection($collection);
  338. $addedCollections[] = $collection;
  339. }
  340. return $addedCollections;
  341. }
  342. //add keys of child collections to array
  343. public function nestCollections(){
  344. foreach($this->collectionObjects as $key=>$collection){
  345. if($collection->parentCollectionKey){
  346. $parentCollection = $this->getCollection($collection->parentCollectionKey);
  347. $parentCollection->childKeys[] = $collection->collectionKey;
  348. }
  349. }
  350. }
  351. public function orderCollections(){
  352. $orderedArray = array();
  353. foreach($this->collectionObjects as $key=>$collection){
  354. $orderedArray[] = $collection;
  355. }
  356. usort($orderedArray, array('Zotero_Collections', 'sortByTitleCompare'));
  357. $this->orderedArray = $orderedArray;
  358. return $this->orderedArray;
  359. }
  360. public function topCollectionKeys($collections){
  361. $topCollections = array();
  362. foreach($collections as $collection){
  363. if($collection->parentCollectionKey == false){
  364. $topCollections[] = $collection->collectionKey;
  365. }
  366. }
  367. return $topCollections;
  368. }
  369. public function collectionsJson(){
  370. $collections = array();
  371. foreach($this->collectionObjects as $collection){
  372. $collections[] = $collection->dataObject();
  373. }
  374. return json_encode($collections);
  375. }
  376. }
  377. /**
  378. * Representation of a set of items belonging to a particular Zotero library
  379. *
  380. * @package libZotero
  381. */
  382. class Zotero_Items
  383. {
  384. public $itemObjects = array();
  385. //get an item from this container of items by itemKey
  386. public function getItem($itemKey) {
  387. if(isset($this->itemObjects[$itemKey])){
  388. return $this->itemObjects[$itemKey];
  389. }
  390. return false;
  391. }
  392. //add a Zotero_Item to this container of items
  393. public function addItem($item) {
  394. $itemKey = $item->itemKey;
  395. $this->itemObjects[$itemKey] = $item;
  396. }
  397. //add items to this container from a Zotero_Feed object
  398. public function addItemsFromFeed($feed) {
  399. $entries = $feed->entryNodes;
  400. $addedItems = array();
  401. foreach($entries as $entry){
  402. $item = new Zotero_Item($entry);
  403. $this->addItem($item);
  404. $addedItems[] = $item;
  405. }
  406. return $addedItems;
  407. }
  408. //replace an item in this container with a new Zotero_Item object with the same itemKey
  409. //useful for example after updating an item when the etag is out of date and to make sure
  410. //the current item we have reflects the best knowledge of the api
  411. public function replaceItem($item) {
  412. $this->addItem($item);
  413. }
  414. public function addChildKeys() {
  415. //empty existing childkeys first
  416. foreach($this->itemObjects as $key=>$item){
  417. $item->childKeys = array();
  418. }
  419. //run through and add item keys to their parent's item if we have the parent
  420. foreach($this->itemObjects as $key=>$item){
  421. if($item->parentKey){
  422. $pitem = $this->getItem($item->parentKey);
  423. if($pitem){
  424. $pitem->childKeys[] = $item->itemKey;
  425. }
  426. }
  427. }
  428. }
  429. public function getPreloadedChildren($item){
  430. $children = array();
  431. foreach($item->childKeys as $childKey){
  432. $childItem = $this->getItem($childKey);
  433. if($childItem){
  434. $children[] = $childItem;
  435. }
  436. }
  437. return $children;
  438. }
  439. }
  440. /**
  441. * Zend Framework
  442. *
  443. * LICENSE
  444. *
  445. * This source file is subject to the new BSD license that is bundled
  446. * with this package in the file LICENSE.txt.
  447. * It is also available through the world-wide-web at this URL:
  448. * http://framework.zend.com/license/new-bsd
  449. * If you did not receive a copy of the license and are unable to
  450. * obtain it through the world-wide-web, please send an email
  451. * to license@zend.com so we can send you a copy immediately.
  452. *
  453. * @category Zend
  454. * @package Zend_Http
  455. * @subpackage Response
  456. * @version $Id: Response.php 23484 2010-12-10 03:57:59Z mjh_ca $
  457. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  458. * @license http://framework.zend.com/license/new-bsd New BSD License
  459. */
  460. /**
  461. * Zend_Http_Response represents an HTTP 1.0 / 1.1 response message. It
  462. * includes easy access to all the response's different elemts, as well as some
  463. * convenience methods for parsing and validating HTTP responses.
  464. *
  465. * @package Zend_Http
  466. * @subpackage Response
  467. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  468. * @license http://framework.zend.com/license/new-bsd New BSD License
  469. */
  470. //class Zend_Http_Response
  471. class libZotero_Http_Response
  472. {
  473. /**
  474. * List of all known HTTP response codes - used by responseCodeAsText() to
  475. * translate numeric codes to messages.
  476. *
  477. * @var array
  478. */
  479. protected static $messages = array(
  480. // Informational 1xx
  481. 100 => 'Continue',
  482. 101 => 'Switching Protocols',
  483. // Success 2xx
  484. 200 => 'OK',
  485. 201 => 'Created',
  486. 202 => 'Accepted',
  487. 203 => 'Non-Authoritative Information',
  488. 204 => 'No Content',
  489. 205 => 'Reset Content',
  490. 206 => 'Partial Content',
  491. // Redirection 3xx
  492. 300 => 'Multiple Choices',
  493. 301 => 'Moved Permanently',
  494. 302 => 'Found', // 1.1
  495. 303 => 'See Other',
  496. 304 => 'Not Modified',
  497. 305 => 'Use Proxy',
  498. // 306 is deprecated but reserved
  499. 307 => 'Temporary Redirect',
  500. // Client Error 4xx
  501. 400 => 'Bad Request',
  502. 401 => 'Unauthorized',
  503. 402 => 'Payment Required',
  504. 403 => 'Forbidden',
  505. 404 => 'Not Found',
  506. 405 => 'Method Not Allowed',
  507. 406 => 'Not Acceptable',
  508. 407 => 'Proxy Authentication Required',
  509. 408 => 'Request Timeout',
  510. 409 => 'Conflict',
  511. 410 => 'Gone',
  512. 411 => 'Length Required',
  513. 412 => 'Precondition Failed',
  514. 413 => 'Request Entity Too Large',
  515. 414 => 'Request-URI Too Long',
  516. 415 => 'Unsupported Media Type',
  517. 416 => 'Requested Range Not Satisfiable',
  518. 417 => 'Expectation Failed',
  519. // Server Error 5xx
  520. 500 => 'Internal Server Error',
  521. 501 => 'Not Implemented',
  522. 502 => 'Bad Gateway',
  523. 503 => 'Service Unavailable',
  524. 504 => 'Gateway Timeout',
  525. 505 => 'HTTP Version Not Supported',
  526. 509 => 'Bandwidth Limit Exceeded'
  527. );
  528. /**
  529. * The HTTP version (1.0, 1.1)
  530. *
  531. * @var string
  532. */
  533. protected $version;
  534. /**
  535. * The HTTP response code
  536. *
  537. * @var int
  538. */
  539. protected $code;
  540. /**
  541. * The HTTP response code as string
  542. * (e.g. 'Not Found' for 404 or 'Internal Server Error' for 500)
  543. *
  544. * @var string
  545. */
  546. protected $message;
  547. /**
  548. * The HTTP response headers array
  549. *
  550. * @var array
  551. */
  552. protected $headers = array();
  553. /**
  554. * The HTTP response body
  555. *
  556. * @var string
  557. */
  558. protected $body;
  559. /**
  560. * HTTP response constructor
  561. *
  562. * In most cases, you would use Zend_Http_Response::fromString to parse an HTTP
  563. * response string and create a new Zend_Http_Response object.
  564. *
  565. * NOTE: The constructor no longer accepts nulls or empty values for the code and
  566. * headers and will throw an exception if the passed values do not form a valid HTTP
  567. * responses.
  568. *
  569. * If no message is passed, the message will be guessed according to the response code.
  570. *
  571. * @param int $code Response code (200, 404, ...)
  572. * @param array $headers Headers array
  573. * @param string $body Response body
  574. * @param string $version HTTP version
  575. * @param string $message Response code as text
  576. * @throws Exception
  577. */
  578. public function __construct($code, array $headers, $body = null, $version = '1.1', $message = null)
  579. {
  580. // Make sure the response code is valid and set it
  581. if (self::responseCodeAsText($code) === null) {
  582. throw new Exception("{$code} is not a valid HTTP response code");
  583. }
  584. $this->code = $code;
  585. foreach ($headers as $name => $value) {
  586. if (is_int($name)) {
  587. $header = explode(":", $value, 2);
  588. if (count($header) != 2) {
  589. throw new Exception("'{$value}' is not a valid HTTP header");
  590. }
  591. $name = trim($header[0]);
  592. $value = trim($header[1]);
  593. }
  594. $this->headers[ucwords(strtolower($name))] = $value;
  595. }
  596. // Set the body
  597. $this->body = $body;
  598. // Set the HTTP version
  599. if (! preg_match('|^\d\.\d$|', $version)) {
  600. throw new Exception("Invalid HTTP response version: $version");
  601. }
  602. $this->version = $version;
  603. // If we got the response message, set it. Else, set it according to
  604. // the response code
  605. if (is_string($message)) {
  606. $this->message = $message;
  607. } else {
  608. $this->message = self::responseCodeAsText($code);
  609. }
  610. }
  611. /**
  612. * Check whether the response is an error
  613. *
  614. * @return boolean
  615. */
  616. public function isError()
  617. {
  618. $restype = floor($this->code / 100);
  619. if ($restype == 4 || $restype == 5) {
  620. return true;
  621. }
  622. return false;
  623. }
  624. /**
  625. * Check whether the response in successful
  626. *
  627. * @return boolean
  628. */
  629. public function isSuccessful()
  630. {
  631. $restype = floor($this->code / 100);
  632. if ($restype == 2 || $restype == 1) { // Shouldn't 3xx count as success as well ???
  633. return true;
  634. }
  635. return false;
  636. }
  637. /**
  638. * Check whether the response is a redirection
  639. *
  640. * @return boolean
  641. */
  642. public function isRedirect()
  643. {
  644. $restype = floor($this->code / 100);
  645. if ($restype == 3) {
  646. return true;
  647. }
  648. return false;
  649. }
  650. /**
  651. * Get the response body as string
  652. *
  653. * This method returns the body of the HTTP response (the content), as it
  654. * should be in it's readable version - that is, after decoding it (if it
  655. * was decoded), deflating it (if it was gzip compressed), etc.
  656. *
  657. * If you want to get the raw body (as transfered on wire) use
  658. * $this->getRawBody() instead.
  659. *
  660. * @return string
  661. */
  662. public function getBody()
  663. {
  664. //added by fcheslack - curl adapter handles these things already so they are transparent to Zend_Response
  665. return $this->getRawBody();
  666. $body = '';
  667. // Decode the body if it was transfer-encoded
  668. switch (strtolower($this->getHeader('transfer-encoding'))) {
  669. // Handle chunked body
  670. case 'chunked':
  671. $body = self::decodeChunkedBody($this->body);
  672. break;
  673. // No transfer encoding, or unknown encoding extension:
  674. // return body as is
  675. default:
  676. $body = $this->body;
  677. break;
  678. }
  679. // Decode any content-encoding (gzip or deflate) if needed
  680. switch (strtolower($this->getHeader('content-encoding'))) {
  681. // Handle gzip encoding
  682. case 'gzip':
  683. $body = self::decodeGzip($body);
  684. break;
  685. // Handle deflate encoding
  686. case 'deflate':
  687. $body = self::decodeDeflate($body);
  688. break;
  689. default:
  690. break;
  691. }
  692. return $body;
  693. }
  694. /**
  695. * Get the raw response body (as transfered "on wire") as string
  696. *
  697. * If the body is encoded (with Transfer-Encoding, not content-encoding -
  698. * IE "chunked" body), gzip compressed, etc. it will not be decoded.
  699. *
  700. * @return string
  701. */
  702. public function getRawBody()
  703. {
  704. return $this->body;
  705. }
  706. /**
  707. * Get the HTTP version of the response
  708. *
  709. * @return string
  710. */
  711. public function getVersion()
  712. {
  713. return $this->version;
  714. }
  715. /**
  716. * Get the HTTP response status code
  717. *
  718. * @return int
  719. */
  720. public function getStatus()
  721. {
  722. return $this->code;
  723. }
  724. /**
  725. * Return a message describing the HTTP response code
  726. * (Eg. "OK", "Not Found", "Moved Permanently")
  727. *
  728. * @return string
  729. */
  730. public function getMessage()
  731. {
  732. return $this->message;
  733. }
  734. /**
  735. * Get the response headers
  736. *
  737. * @return array
  738. */
  739. public function getHeaders()
  740. {
  741. return $this->headers;
  742. }
  743. /**
  744. * Get a specific header as string, or null if it is not set
  745. *
  746. * @param string$header
  747. * @return string|array|null
  748. */
  749. public function getHeader($header)
  750. {
  751. $header = ucwords(strtolower($header));
  752. if (! is_string($header) || ! isset($this->headers[$header])) return null;
  753. return $this->headers[$header];
  754. }
  755. /**
  756. * Get all headers as string
  757. *
  758. * @param boolean $status_line Whether to return the first status line (IE "HTTP 200 OK")
  759. * @param string $br Line breaks (eg. "\n", "\r\n", "<br />")
  760. * @return string
  761. */
  762. public function getHeadersAsString($status_line = true, $br = "\n")
  763. {
  764. $str = '';
  765. if ($status_line) {
  766. $str = "HTTP/{$this->version} {$this->code} {$this->message}{$br}";
  767. }
  768. // Iterate over the headers and stringify them
  769. foreach ($this->headers as $name => $value)
  770. {
  771. if (is_string($value))
  772. $str .= "{$name}: {$value}{$br}";
  773. elseif (is_array($value)) {
  774. foreach ($value as $subval) {
  775. $str .= "{$name}: {$subval}{$br}";
  776. }
  777. }
  778. }
  779. return $str;
  780. }
  781. /**
  782. * Get the entire response as string
  783. *
  784. * @param string $br Line breaks (eg. "\n", "\r\n", "<br />")
  785. * @return string
  786. */
  787. public function asString($br = "\n")
  788. {
  789. return $this->getHeadersAsString(true, $br) . $br . $this->getRawBody();
  790. }
  791. /**
  792. * Implements magic __toString()
  793. *
  794. * @return string
  795. */
  796. public function __toString()
  797. {
  798. return $this->asString();
  799. }
  800. /**
  801. * A convenience function that returns a text representation of
  802. * HTTP response codes. Returns 'Unknown' for unknown codes.
  803. * Returns array of all codes, if $code is not specified.
  804. *
  805. * Conforms to HTTP/1.1 as defined in RFC 2616 (except for 'Unknown')
  806. * See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10 for reference
  807. *
  808. * @param int $code HTTP response code
  809. * @param boolean $http11 Use HTTP version 1.1
  810. * @return string
  811. */
  812. public static function responseCodeAsText($code = null, $http11 = true)
  813. {
  814. $messages = self::$messages;
  815. if (! $http11) $messages[302] = 'Moved Temporarily';
  816. if ($code === null) {
  817. return $messages;
  818. } elseif (isset($messages[$code])) {
  819. return $messages[$code];
  820. } else {
  821. return 'Unknown';
  822. }
  823. }
  824. /**
  825. * Extract the response code from a response string
  826. *
  827. * @param string $response_str
  828. * @return int
  829. */
  830. public static function extractCode($response_str)
  831. {
  832. preg_match("|^HTTP/[\d\.x]+ (\d+)|", $response_str, $m);
  833. if (isset($m[1])) {
  834. return (int) $m[1];
  835. } else {
  836. return false;
  837. }
  838. }
  839. /**
  840. * Extract the HTTP message from a response
  841. *
  842. * @param string $response_str
  843. * @return string
  844. */
  845. public static function extractMessage($response_str)
  846. {
  847. preg_match("|^HTTP/[\d\.x]+ \d+ ([^\r\n]+)|", $response_str, $m);
  848. if (isset($m[1])) {
  849. return $m[1];
  850. } else {
  851. return false;
  852. }
  853. }
  854. /**
  855. * Extract the HTTP version from a response
  856. *
  857. * @param string $response_str
  858. * @return string
  859. */
  860. public static function extractVersion($response_str)
  861. {
  862. preg_match("|^HTTP/([\d\.x]+) \d+|", $response_str, $m);
  863. if (isset($m[1])) {
  864. return $m[1];
  865. } else {
  866. return false;
  867. }
  868. }
  869. /**
  870. * Extract the headers from a response string
  871. *
  872. * @param string $response_str
  873. * @return array
  874. */
  875. public static function extractHeaders($response_str)
  876. {
  877. $headers = array();
  878. // First, split body and headers
  879. $parts = preg_split('|(?:\r?\n){2}|m', $response_str, 2);
  880. if (! $parts[0]) return $headers;
  881. // Split headers part to lines
  882. $lines = explode("\n", $parts[0]);
  883. unset($parts);
  884. $last_header = null;
  885. foreach($lines as $line) {
  886. $line = trim($line, "\r\n");
  887. if ($line == "") break;
  888. // Locate headers like 'Location: ...' and 'Location:...' (note the missing space)
  889. if (preg_match("|^([\w-]+):\s*(.+)|", $line, $m)) {
  890. unset($last_header);
  891. $h_name = strtolower($m[1]);
  892. $h_value = $m[2];
  893. if (isset($headers[$h_name])) {
  894. if (! is_array($headers[$h_name])) {
  895. $headers[$h_name] = array($headers[$h_name]);
  896. }
  897. $headers[$h_name][] = $h_value;
  898. } else {
  899. $headers[$h_name] = $h_value;
  900. }
  901. $last_header = $h_name;
  902. } elseif (preg_match("|^\s+(.+)$|", $line, $m) && $last_header !== null) {
  903. if (is_array($headers[$last_header])) {
  904. end($headers[$last_header]);
  905. $last_header_key = key($headers[$last_header]);
  906. $headers[$last_header][$last_header_key] .= $m[1];
  907. } else {
  908. $headers[$last_header] .= $m[1];
  909. }
  910. }
  911. }
  912. return $headers;
  913. }
  914. /**
  915. * Extract the body from a response string
  916. *
  917. * @param string $response_str
  918. * @return string
  919. */
  920. public static function extractBody($response_str)
  921. {
  922. $parts = preg_split('|(?:\r?\n){2}|m', $response_str, 2);
  923. if (isset($parts[1])) {
  924. return $parts[1];
  925. }
  926. return '';
  927. }
  928. /**
  929. * Decode a "chunked" transfer-encoded body and return the decoded text
  930. *
  931. * @param string $body
  932. * @return string
  933. */
  934. public static function decodeChunkedBody($body)
  935. {
  936. // Added by Dan S. -- don't fail on Transfer-encoding:chunked response
  937. //that isn't really chunked
  938. if (! preg_match("/^([\da-fA-F]+)[^\r\n]*\r\n/sm", trim($body), $m)) {
  939. return $body;
  940. }
  941. $decBody = '';
  942. // If mbstring overloads substr and strlen functions, we have to
  943. // override it's internal encoding
  944. if (function_exists('mb_internal_encoding') &&
  945. ((int) ini_get('mbstring.func_overload')) & 2) {
  946. $mbIntEnc = mb_internal_encoding();
  947. mb_internal_encoding('ASCII');
  948. }
  949. while (trim($body)) {
  950. if (! preg_match("/^([\da-fA-F]+)[^\r\n]*\r\n/sm", $body, $m)) {
  951. throw new Exception("Error parsing body - doesn't seem to be a chunked message");
  952. }
  953. $length = hexdec(trim($m[1]));
  954. $cut = strlen($m[0]);
  955. $decBody .= substr($body, $cut, $length);
  956. $body = substr($body, $cut + $length + 2);
  957. }
  958. if (isset($mbIntEnc)) {
  959. mb_internal_encoding($mbIntEnc);
  960. }
  961. return $decBody;
  962. }
  963. /**
  964. * Decode a gzip encoded message (when Content-encoding = gzip)
  965. *
  966. * Currently requires PHP with zlib support
  967. *
  968. * @param string $body
  969. * @return string
  970. */
  971. public static function decodeGzip($body)
  972. {
  973. if (! function_exists('gzinflate')) {
  974. throw new Exception(
  975. 'zlib extension is required in order to decode "gzip" encoding'
  976. );
  977. }
  978. return gzinflate(substr($body, 10));
  979. }
  980. /**
  981. * Decode a zlib deflated message (when Content-encoding = deflate)
  982. *
  983. * Currently requires PHP with zlib support
  984. *
  985. * @param string $body
  986. * @return string
  987. */
  988. public static function decodeDeflate($body)
  989. {
  990. if (! function_exists('gzuncompress')) {
  991. throw new Exception(
  992. 'zlib extension is required in order to decode "deflate" encoding'
  993. );
  994. }
  995. /**
  996. * Some servers (IIS ?) send a broken deflate response, without the
  997. * RFC-required zlib header.
  998. *
  999. * We try to detect the zlib header, and if it does not exsit we
  1000. * teat the body is plain DEFLATE content.
  1001. *
  1002. * This method was adapted from PEAR HTTP_Request2 by (c) Alexey Borzov
  1003. *
  1004. * @link http://framework.zend.com/issues/browse/ZF-6040
  1005. */
  1006. $zlibHeader = unpack('n', substr($body, 0, 2));
  1007. if ($zlibHeader[1] % 31 == 0) {
  1008. return gzuncompress($body);
  1009. } else {
  1010. return gzinflate($body);
  1011. }
  1012. }
  1013. /**
  1014. * Create a new Zend_Http_Response object from a string
  1015. *
  1016. * @param string $response_str
  1017. * @return Zend_Http_Response
  1018. */
  1019. public static function fromString($response_str)
  1020. {
  1021. $code = self::extractCode($response_str);
  1022. $headers = self::extractHeaders($response_str);
  1023. $body = self::extractBody($response_str);
  1024. $version = self::extractVersion($response_str);
  1025. $message = self::extractMessage($response_str);
  1026. return new libZotero_Http_Response($code, $headers, $body, $version, $message);
  1027. }
  1028. }
  1029. /**
  1030. * Representation of a Zotero Item
  1031. *
  1032. * @package libZotero
  1033. * @see Zotero_Entry
  1034. */
  1035. class Zotero_Item extends Zotero_Entry
  1036. {
  1037. /**
  1038. * @var int
  1039. */
  1040. public $itemKey = '';
  1041. /**
  1042. * @var string
  1043. */
  1044. public $itemType = null;
  1045. /**
  1046. * @var string
  1047. */
  1048. public $creatorSummary = '';
  1049. /**
  1050. * @var string
  1051. */
  1052. public $numChildren = 0;
  1053. /**
  1054. * @var string
  1055. */
  1056. public $numTags = 0;
  1057. /**
  1058. * @var array
  1059. */
  1060. public $childKeys = array();
  1061. /**
  1062. * @var string
  1063. */
  1064. public $parentKey = '';
  1065. /**
  1066. * @var array
  1067. */
  1068. public $creators = array();
  1069. /**
  1070. * @var string
  1071. */
  1072. public $createdByUserID = null;
  1073. /**
  1074. * @var string
  1075. */
  1076. public $lastModifiedByUserID = null;
  1077. /**
  1078. * @var string
  1079. */
  1080. public $note = null;
  1081. /**
  1082. * @var int Represents the relationship of the child to the parent. 0:file, 1:file, 2:snapshot, 3:web-link
  1083. */
  1084. public $linkMode = null;
  1085. /**
  1086. * @var string
  1087. */
  1088. public $mimeType = null;
  1089. public $parsedJson = null;
  1090. public $etag = '';
  1091. /**
  1092. * @var string content node of response useful if formatted bib request and we need to use the raw content
  1093. */
  1094. public $content = null;
  1095. public $bibContent = null;
  1096. public $subContents = array();
  1097. public $apiObject = array();
  1098. /**
  1099. * @var array
  1100. */
  1101. public static $fieldMap = array(
  1102. "creator" => "Creator",
  1103. "itemType" => "Type",
  1104. "title" => "Title",
  1105. "dateAdded" => "Date Added",
  1106. "dateModified" => "Modified",
  1107. "source" => "Source",
  1108. "notes" => "Notes",
  1109. "tags" => "Tags",
  1110. "attachments" => "Attachments",
  1111. "related" => "Related",
  1112. "url" => "URL",
  1113. "rights" => "Rights",
  1114. "series" => "Series",
  1115. "volume" => "Volume",
  1116. "issue" => "Issue",
  1117. "edition" => "Edition",
  1118. "place" => "Place",
  1119. "publisher" => "Publisher",
  1120. "pages" => "Pages",
  1121. "ISBN" => "ISBN",
  1122. "publicationTitle" => "Publication",
  1123. "ISSN" => "ISSN",
  1124. "date" => "Date",
  1125. "section" => "Section",
  1126. "callNumber" => "Call Number",
  1127. "archiveLocation" => "Loc. in Archive",
  1128. "distributor" => "Distributor",
  1129. "extra" => "Extra",
  1130. "journalAbbreviation" => "Journal Abbr",
  1131. "DOI" => "DOI",
  1132. "accessDate" => "Accessed",
  1133. "seriesTitle" => "Series Title",
  1134. "seriesText" => "Series Text",
  1135. "seriesNumber" => "Series Number",
  1136. "institution" => "Institution",
  1137. "reportType" => "Report Type",
  1138. "code" => "Code",
  1139. "session" => "Session",
  1140. "legislativeBody" => "Legislative Body",
  1141. "history" => "History",
  1142. "reporter" => "Reporter",
  1143. "court" => "Court",
  1144. "numberOfVolumes" => "# of Volumes",
  1145. "committee" => "Committee",
  1146. "assignee" => "Assignee",
  1147. "patentNumber" => "Patent Number",
  1148. "priorityNumbers" => "Priority Numbers",
  1149. "issueDate" => "Issue Date",
  1150. "references" => "References",
  1151. "legalStatus" => "Legal Status",
  1152. "codeNumber" => "Code Number",
  1153. "artworkMedium" => "Medium",
  1154. "number" => "Number",
  1155. "artworkSize" => "Artwork Size",
  1156. "libraryCatalog" => "Library Catalog",
  1157. "videoRecordingType" => "Recording Type",
  1158. "interviewMedium" => "Medium",
  1159. "letterType" => "Type",
  1160. "manuscriptType" => "Type",
  1161. "mapType" => "Type",
  1162. "scale" => "Scale",
  1163. "thesisType" => "Type",
  1164. "websiteType" => "Website Type",
  1165. "audioRecordingType" => "Recording Type",
  1166. "label" => "Label",
  1167. "presentationType" => "Type",
  1168. "meetingName" => "Meeting Name",
  1169. "studio" => "Studio",
  1170. "runningTime" => "Running Time",
  1171. "network" => "Network",
  1172. "postType" => "Post Type",
  1173. "audioFileType" => "File Type",
  1174. "version" => "Version",
  1175. "system" => "System",
  1176. "company" => "Company",
  1177. "conferenceName" => "Conference Name",
  1178. "encyclopediaTitle" => "Encyclopedia Title",
  1179. "dictionaryTitle" => "Dictionary Title",
  1180. "language" => "Language",
  1181. "programmingLanguage" => "Language",
  1182. "university" => "University",
  1183. "abstractNote" => "Abstract",
  1184. "websiteTitle" => "Website Title",
  1185. "reportNumber" => "Report Number",
  1186. "billNumber" => "Bill Number",
  1187. "codeVolume" => "Code Volume",
  1188. "codePages" => "Code Pages",
  1189. "dateDecided" => "Date Decided",
  1190. "reporterVolume" => "Reporter Volume",
  1191. "firstPage" => "First Page",
  1192. "documentNumber" => "Document Number",
  1193. "dateEnacted" => "Date Enacted",
  1194. "publicLawNumber" => "Public Law Number",
  1195. "country" => "Country",
  1196. "applicationNumber" => "Application Number",
  1197. "forumTitle" => "Forum/Listserv Title",
  1198. "episodeNumber" => "Episode Number",
  1199. "blogTitle" => "Blog Title",
  1200. "caseName" => "Case Name",
  1201. "nameOfAct" => "Name of Act",
  1202. "subject" => "Subject",
  1203. "proceedingsTitle" => "Proceedings Title",
  1204. "bookTitle" => "Book Title",
  1205. "shortTitle" => "Short Title",
  1206. "docketNumber" => "Docket Number",
  1207. "numPages" => "# of Pages"
  1208. );
  1209. /**
  1210. * @var array
  1211. */
  1212. public static $typeMap = array(
  1213. "note" => "Note",
  1214. "attachment" => "Attachment",
  1215. "book" => "Book",
  1216. "bookSection" => "Book Section",
  1217. "journalArticle" => "Journal Article",
  1218. "magazineArticle" => "Magazine Article",
  1219. "newspaperArticle" => "Newspaper Article",
  1220. "thesis" => "Thesis",
  1221. "letter" => "Letter",
  1222. "manuscript" => "Manuscript",
  1223. "interview" => "Interview",
  1224. "film" => "Film",
  1225. "artwork" => "Artwork",
  1226. "webpage" => "Web Page",
  1227. "report" => "Report",
  1228. "bill" => "Bill",
  1229. "case" => "Case",
  1230. "hearing" => "Hearing",
  1231. "patent" => "Patent",
  1232. "statute" => "Statute",
  1233. "email" => "E-mail",
  1234. "map" => "Map",
  1235. "blogPost" => "Blog Post",
  1236. "instantMessage" => "Instant Message",
  1237. "forumPost" => "Forum Post",
  1238. "audioRecording" => "Audio Recording",
  1239. "presentation" => "Presentation",
  1240. "videoRecording" => "Video Recording",
  1241. "tvBroadcast" => "TV Broadcast",
  1242. "radioBroadcast" => "Radio Broadcast",
  1243. "podcast" => "Podcast",
  1244. "computerProgram" => "Computer Program",
  1245. "conferencePaper" => "Conference Paper",
  1246. "document" => "Document",
  1247. "encyclopediaArticle" => "Encyclopedia Article",
  1248. "dictionaryEntry" => "Dictionary Entry",
  1249. );
  1250. /**
  1251. * @var array
  1252. */
  1253. public static $creatorMap = array(
  1254. "author" => "Author",
  1255. "contributor" => "Contributor",
  1256. "editor" => "Editor",
  1257. "translator" => "Translator",
  1258. "seriesEditor" => "Series Editor",
  1259. "interviewee" => "Interview With",
  1260. "interviewer" => "Interviewer",
  1261. "director" => "Director",
  1262. "scriptwriter" => "Scriptwriter",
  1263. "producer" => "Producer",
  1264. "castMember" => "Cast Member",
  1265. "sponsor" => "Sponsor",
  1266. "counsel" => "Counsel",
  1267. "inventor" => "Inventor",
  1268. "attorneyAgent" => "Attorney/Agent",
  1269. "recipient" => "Recipient",
  1270. "performer" => "Performer",
  1271. "composer" => "Composer",
  1272. "wordsBy" => "Words By",
  1273. "cartographer" => "Cartographer",
  1274. "programmer" => "Programmer",
  1275. "reviewedAuthor" => "Reviewed Author",
  1276. "artist" => "Artist",
  1277. "commenter" => "Commenter",
  1278. "presenter" => "Presenter",
  1279. "guest" => "Guest",
  1280. "podcaster" => "Podcaster"
  1281. );
  1282. public function __construct($entryNode=null)
  1283. {
  1284. if(!$entryNode){
  1285. return;
  1286. }
  1287. elseif(is_string($entryNode)){
  1288. $xml = $entryNode;
  1289. $doc = new DOMDocument();
  1290. $doc->loadXml($xml);
  1291. $entryNode = $doc->getElementsByTagName('entry')->item(0);
  1292. }
  1293. parent::__construct($entryNode);
  1294. //check if we have multiple subcontent nodes
  1295. $subcontentNodes = $entryNode->getElementsByTagNameNS("*", "subcontent");
  1296. //save raw Content node in case we need it
  1297. if($entryNode->getElementsByTagName("content")->length > 0){
  1298. $d = $entryNode->ownerDocument;
  1299. $this->contentNode = $entryNode->getElementsByTagName("content")->item(0);
  1300. $this->content = $d->saveXml($this->contentNode);
  1301. }
  1302. // Extract the itemId and itemType
  1303. $this->itemKey = $entryNode->getElementsByTagNameNS('*', 'key')->item(0)->nodeValue;
  1304. $this->itemType = $entryNode->getElementsByTagNameNS('*', 'itemType')->item(0)->nodeValue;
  1305. // Look for numChildren node
  1306. $numChildrenNode = $entryNode->getElementsByTagNameNS('*', "numChildren")->item(0);
  1307. if($numChildrenNode){
  1308. $this->numChildren = $numChildrenNode->nodeValue;
  1309. }
  1310. // Look for numTags node
  1311. $numTagsNode = $entryNode->getElementsByTagNameNS('*', "numTags")->item(0);
  1312. if($numTagsNode){
  1313. $this->numTags = $numTagsNode->nodeValue;
  1314. }
  1315. $creatorSummaryNode = $entryNode->getElementsByTagNameNS('*', "creatorSummary")->item(0);
  1316. if($creatorSummaryNode){
  1317. $this->creatorSummary = $creatorSummaryNode->nodeValue;
  1318. }
  1319. if($subcontentNodes->length > 0){
  1320. for($i = 0; $i < $subcontentNodes->length; $i++){
  1321. $scnode = $subcontentNodes->item($i);
  1322. $type = $scnode->getAttribute('zapi:type');
  1323. if($type == 'application/json' || $type == 'json'){
  1324. $this->apiObject = json_decode($scnode->nodeValue, true);
  1325. $this->etag = $scnode->getAttribute('zapi:etag');
  1326. if(isset($this->apiObject['creators'])){
  1327. $this->creators = $this->apiObject['creators'];
  1328. }
  1329. else{
  1330. $this->creators = array();
  1331. }
  1332. }
  1333. elseif($type == 'bib'){
  1334. $bibNode = $scnode->getElementsByTagName('div')->item(0);
  1335. $this->bibContent = $bibNode->ownerDocument->saveXML($bibNode);
  1336. }
  1337. $contentString = '';
  1338. $childNodes = $scnode->childNodes;
  1339. foreach($childNodes as $childNode){
  1340. $contentString .= $childNode->ownerDocument->saveXML($childNode);
  1341. }
  1342. $this->subContents[$type] = $contentString;
  1343. }
  1344. }
  1345. else{
  1346. $contentNode = $entryNode->getElementsByTagName('content')->item(0);
  1347. $contentType = $contentNode->getAttribute('type');
  1348. $zType = $contentNode->getAttribute('zapi:type');
  1349. if($contentType == 'application/json' || $contentType == 'json' || $zType == 'json'){
  1350. $this->apiObject = json_decode($contentNode->nodeValue, true);
  1351. $this->etag = $contentNode->getAttribute('zapi:etag');
  1352. if(isset($this->apiObject['creators'])){
  1353. $this->creators = $this->apiObject['creators'];
  1354. }
  1355. else{
  1356. $this->creators = array();
  1357. }
  1358. }
  1359. elseif($contentType == 'bib' || $zType == 'bib'){
  1360. $bibNode = $contentNode->getElementsByTagName('div')->item(0);
  1361. $this->bibContent = $bibNode->ownerDocument->saveXML($bibNode);
  1362. }
  1363. else{
  1364. //didn't find a content type we deal with
  1365. }
  1366. }
  1367. if(isset($this->links['up'])){
  1368. $parentLink = $this->links['up']['application/atom+xml']['href'];
  1369. $matches = array();
  1370. preg_match("/items\/([A-Z0-9]{8})/", $parentLink, $matches);
  1371. if(count($matches) == 2){
  1372. $this->parentKey = $matches[1];
  1373. }
  1374. }
  1375. else{
  1376. $this->parentKey = false;
  1377. }
  1378. }
  1379. public function get($key){
  1380. if($key == 'tags'){
  1381. if(isset($this->apiObject['tags'])){
  1382. return $this->apiObject['tags'];
  1383. }
  1384. }
  1385. elseif($key == 'creators'){
  1386. //special case
  1387. if(isset($this->apiObject['creators'])){
  1388. return $this->apiObject['creators'];
  1389. }
  1390. }
  1391. else{
  1392. if(isset($this->apiObject[$key])){
  1393. return $this->apiObject[$key];
  1394. }
  1395. else{
  1396. return null;
  1397. }
  1398. }
  1399. }
  1400. public function set($key, $val){
  1401. if($key == 'creators' || $key == 'tags'){
  1402. //TODO: special case empty value and correctly in arrays
  1403. $this->apiObject[$key] = $val;
  1404. }
  1405. else{
  1406. //if(in_array($key, array_keys($this->fieldMap))) {
  1407. $this->apiObject[$key] = $val;
  1408. //}
  1409. }
  1410. }
  1411. public function addCreator($creatorArray){
  1412. $this->creators[] = $creatorArray;
  1413. $this->apiObject['creators'][] = $creatorArray;
  1414. }
  1415. public function updateItemObject(){
  1416. $updateItem = $this->apiObject;
  1417. //remove notes as they can't be in update json
  1418. unset($updateItem['notes']);
  1419. $newCreatorsArray = array();
  1420. foreach($updateItem['creators'] as $creator){
  1421. if($creator['creatorType']){
  1422. if(empty($creator['name']) && empty($creator['firstName']) && empty($creator['lastName'])){
  1423. continue;
  1424. }
  1425. else{
  1426. $newCreatorsArray[] = $creator;

Large files files are truncated, but you can click here to view the full file