details.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. require_once 'settings.php';
  3. require_once 'inc/include.php';
  4. require_once 'inc/phpZotero.php';
  5. include_once 'inc/header.php'; // HTML header including css file
  6. $zotero = new phpZotero($API_key);
  7. $itemkey = $_REQUEST['itemkey'];
  8. //purge old files from the cache
  9. purge_cache(realpath("./" . $cache_dir), $cache_age);
  10. // reading item details from API
  11. $item = $zotero->getItem($user_ID, $itemkey, array(format=>'atom'));
  12. $content = substr($item,strpos($item, "<content type="), strpos($item, "</content>") - strpos($item, "<content type=", $offset) + 10);
  13. // displaying content of main item
  14. echo("<hr><h2>Item Details</h2><hr>\n");
  15. echo($content . "\n<hr>\n");
  16. echo("<h2>Attachments</h2><hr>\n");
  17. // getting child items from API, parsing data, displaying results
  18. $child_items = $zotero->getItemChildren($user_ID, $itemkey, array(format=>'atom', limit=>99));
  19. $offset=0;
  20. $pos = strpos($child_items, "<entry>", $offset);
  21. while ($pos !== false) {
  22. $entry = substr($child_items,strpos($child_items, "<entry>", $offset), strpos($child_items, "</entry>", $offset) - strpos($child_items, "<entry>", $offset) + 8);
  23. $title = substr($entry,strpos($entry, "<title>") + 7, strpos($entry, "</title>") - strpos($entry, "<title>") - 7);
  24. $child_itemkey = substr($entry,strpos($entry, "<zapi:key>") + 10, strpos($entry, "</zapi:key>") - strpos($entry, "<zapi:key>") - 10);
  25. $content = substr($entry,strpos($entry, "<content type="), strpos($entry, "</content>") - strpos($entry, "<content type=") + 10);
  26. $url = substr($content, strpos($content, "<td>", strpos($content, "<tr class=\"url\">")) + 4);
  27. $url = substr($url, 0, strpos($url,"</td>")); // this is broken up into two commands to keep it simple
  28. $mimeType = substr($content, strpos($content, "<td>", strpos($content, "<tr class=\"mimeType\">")) + 4);
  29. $mimeType = substr($mimeType, 0, strpos($mimeType,"</td>")); // this is broken up into two commands to keep it simple
  30. $linkMode = substr($content, strpos($content, "<td>", strpos($content, "<tr class=\"linkMode\">")) + 4);
  31. $linkMode = intval(substr($linkMode, 0, strpos($linkMode,"</td>"))); // this is broken up into two commands to keep it simple
  32. $content2 = substr($content, 0, strpos($content, "</table>"));
  33. $content2 .= " <tr class=\"url\">\n";
  34. $content2 .= " <th style=\"text-align: right\">Link</th>\n";
  35. if ($linkMode==1) {
  36. $content2 .= " <td><a href=\"$url\">$url</a></td>\n";
  37. } else {
  38. $content2 .= " <td><a href=\"attachment.php?itemkey=$child_itemkey&mime=$mimeType\">Access the Attachment as stored on the WebDAV server</a></td>\n";
  39. }
  40. $content2 .= " </tr>\n ";
  41. $content2 .= substr($content, strpos($content, "</table>"));
  42. echo($content2 . "\n");
  43. echo("<hr>\n");
  44. $offset = strpos($child_items, "</entry>", $offset) + 8;
  45. $pos = strpos($child_items, "<entry>", $offset);
  46. }
  47. ?>
  48. </body>
  49. </html>