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.

76 lines
2.7KB

  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 ("rating.php");
  13. require_once ("publisher.php");
  14. require_once ("serie.php");
  15. require_once ("tag.php");
  16. require_once ("language.php");
  17. require_once ("customcolumn.php");
  18. require_once ("book.php");
  19. require_once ("resources/doT-php/doT.php");
  20. // If we detect that an OPDS reader try to connect try to redirect to feed.php
  21. if (preg_match("/(MantanoReader|FBReader|Stanza|Marvin|Aldiko|Moon+ Reader|Chunky|AlReader|org\.ebookdroid)/", $_SERVER['HTTP_USER_AGENT'])) {
  22. header("location: feed.php");
  23. exit ();
  24. }
  25. $page = getURLParam ("page", Base::PAGE_INDEX);
  26. $query = getURLParam ("query");
  27. $qid = getURLParam ("id");
  28. $n = getURLParam ("n", "1");
  29. $database = GetUrlParam (DB);
  30. // Access the database ASAP to be sure it's readable, redirect if that's not the case.
  31. // It has to be done before any header is sent.
  32. Base::checkDatabaseAvailability ();
  33. if ($config ['cops_fetch_protect'] == "1") {
  34. session_start();
  35. if (!isset($_SESSION['connected'])) {
  36. $_SESSION['connected'] = 0;
  37. }
  38. }
  39. header ("Content-Type:text/html;charset=utf-8");
  40. $data = array("title" => $config['cops_title_default'],
  41. "version" => VERSION,
  42. "opds_url" => $config['cops_full_url'] . "feed.php",
  43. "customHeader" => "",
  44. "template" => getCurrentTemplate (),
  45. "server_side_rendering" => useServerSideRendering (),
  46. "current_css" => getCurrentCss (),
  47. "favico" => $config['cops_icon'],
  48. "getjson_url" => "getJSON.php?" . addURLParameter (getQueryString (), "complete", 1));
  49. if (preg_match("/Kindle/", $_SERVER['HTTP_USER_AGENT'])) {
  50. $data ["customHeader"] = '<style media="screen" type="text/css"> html { font-size: 75%; -webkit-text-size-adjust: 75%; -ms-text-size-adjust: 75%; }</style>';
  51. }
  52. $headcontent = file_get_contents('templates/' . getCurrentTemplate () . '/file.html');
  53. $template = new doT ();
  54. $dot = $template->template ($headcontent, NULL);
  55. echo ($dot ($data));
  56. ?><body>
  57. <?php
  58. if (useServerSideRendering ()) {
  59. // Get the data
  60. require_once ("JSON_renderer.php");
  61. $data = JSONRenderer::getJson (true);
  62. echo serverSideRender ($data);
  63. }
  64. ?>
  65. </body>
  66. </html>