Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...) http://blog.slucas.fr/en/oss/calibre-opds-php-server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
4.3KB

  1. <?php
  2. /**
  3. * COPS (Calibre OPDS PHP Server) HTML main script
  4. *
  5. * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
  6. * @author Sébastien Lucas <sebastien@slucas.fr>
  7. *
  8. */
  9. require_once ("config.php");
  10. require_once ("base.php");
  11. require_once ("author.php");
  12. require_once ("serie.php");
  13. require_once ("tag.php");
  14. require_once ("language.php");
  15. require_once ("customcolumn.php");
  16. require_once ("book.php");
  17. header ("Content-Type:application/json;charset=utf-8");
  18. $page = getURLParam ("page", Base::PAGE_INDEX);
  19. $query = getURLParam ("query");
  20. $qid = getURLParam ("id");
  21. $n = getURLParam ("n", "1");
  22. $database = GetUrlParam (DB);
  23. $currentPage = Page::getPage ($page, $qid, $query, $n);
  24. $currentPage->InitializeContent ();
  25. $out = array ( "title" => $currentPage->title);
  26. $entries = array ();
  27. foreach ($currentPage->entryArray as $entry) {
  28. array_push ($entries, $entry->getContentArray ());
  29. }
  30. if (!is_null ($currentPage->book)) {
  31. $out ["book"] = $currentPage->book->getFullContentArray ();
  32. }
  33. $out ["databaseId"] = GetUrlParam (DB, "");
  34. $out ["databaseName"] = Base::getDbName ();
  35. $out ["page"] = $page;
  36. $out ["entries"] = $entries;
  37. $out ["isPaginated"] = 0;
  38. if ($currentPage->isPaginated ()) {
  39. $prevLink = $currentPage->getPrevLink ();
  40. $nextLink = $currentPage->getNextLink ();
  41. $out ["isPaginated"] = 1;
  42. $out ["prevLink"] = "";
  43. if (!is_null ($prevLink)) {
  44. $out ["prevLink"] = $prevLink->hrefXhtml ();
  45. }
  46. $out ["nextLink"] = "";
  47. if (!is_null ($nextLink)) {
  48. $out ["nextLink"] = $nextLink->hrefXhtml ();
  49. }
  50. $out ["maxPage"] = $currentPage->getMaxPage ();
  51. $out ["currentPage"] = $currentPage->n;
  52. }
  53. if (!is_null (getURLParam ("complete"))) {
  54. $out ["const"] = array ("version" => VERSION, "i18n" => array (
  55. "coverAlt" => localize("i18n.coversection"),
  56. "authorsTitle" => localize("authors.title"),
  57. "bookwordTitle" => localize("bookword.title"),
  58. "tagsTitle" => localize("tags.title"),
  59. "seriesTitle" => localize("series.title"),
  60. "customizeTitle" => localize ("customize.title"),
  61. "aboutTitle" => localize ("about.title"),
  62. "previousAlt" => localize ("paging.previous.alternate"),
  63. "nextAlt" => localize ("paging.next.alternate"),
  64. "searchAlt" => localize ("search.alternate"),
  65. "sortAlt" => localize ("sort.alternate"),
  66. "homeAlt" => localize ("home.alternate"),
  67. "permalinkAlt" => localize ("permalink.alternate"),
  68. "pubdateTitle" => localize("pubdate.title"),
  69. "languagesTitle" => localize("language.title"),
  70. "contentTitle" => localize("content.summary"),
  71. "sortorderAsc" => localize("search.sortorder.asc"),
  72. "sortorderDesc" => localize("search.sortorder.desc")),
  73. "url" => array (
  74. "detailUrl" => "index.php?page=13&id={0}&db={1}",
  75. "coverUrl" => "fetch.php?id={0}&db={1}",
  76. "thumbnailUrl" => "fetch.php?height=" . $config['cops_html_thumbnail_height'] . "&id={0}&db={1}"),
  77. "config" => array (
  78. "use_fancyapps" => $config ["cops_use_fancyapps"],
  79. "max_item_per_page" => $config['cops_max_item_per_page'],
  80. "html_tag_filter" => $config['cops_html_tag_filter']));
  81. }
  82. $out ["containsBook"] = 0;
  83. if ($currentPage->containsBook ()) {
  84. $out ["containsBook"] = 1;
  85. }
  86. $out["abouturl"] = "index.php" . addURLParameter ("?page=16", DB, $database);
  87. if ($page == Base::PAGE_ABOUT) {
  88. $out ["fullhtml"] = file_get_contents('about.html');
  89. }
  90. $out ["homeurl"] = "index.php";
  91. if ($page != Base::PAGE_INDEX && !is_null ($database)) $out ["homeurl"] = $out ["homeurl"] . "?" . addURLParameter ("", DB, $database);
  92. echo json_encode ($out);