PageRenderTime 56ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/phpexamples/zreports/libZoteroSingle.php

https://github.com/kmlawson/libZotero
PHP | 3185 lines | 2073 code | 314 blank | 798 comment | 207 complexity | 80719ac1c1c73947b69292ba0761b398 MD5 | raw file

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

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

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