Пример #1
0
 private function startXmlDocument($page)
 {
     global $config;
     self::getXmlStream()->startDocument('1.0', 'UTF-8');
     self::getXmlStream()->startElement("feed");
     self::getXmlStream()->writeAttribute("xmlns", "http://www.w3.org/2005/Atom");
     self::getXmlStream()->writeAttribute("xmlns:xhtml", "http://www.w3.org/1999/xhtml");
     self::getXmlStream()->writeAttribute("xmlns:opds", "http://opds-spec.org/2010/catalog");
     self::getXmlStream()->writeAttribute("xmlns:opensearch", "http://a9.com/-/spec/opensearch/1.1/");
     self::getXmlStream()->writeAttribute("xmlns:dcterms", "http://purl.org/dc/terms/");
     self::getXmlStream()->startElement("title");
     self::getXmlStream()->text($page->title);
     self::getXmlStream()->endElement();
     if ($page->subtitle != "") {
         self::getXmlStream()->startElement("subtitle");
         self::getXmlStream()->text($page->subtitle);
         self::getXmlStream()->endElement();
     }
     self::getXmlStream()->startElement("id");
     if ($page->idPage) {
         $idPage = $page->idPage;
         if (!is_null(GetUrlParam(DB))) {
             $idPage = str_replace("cops:", "cops:" . GetUrlParam(DB) . ":", $idPage);
         }
         self::getXmlStream()->text($idPage);
     } else {
         self::getXmlStream()->text($_SERVER['REQUEST_URI']);
     }
     self::getXmlStream()->endElement();
     self::getXmlStream()->startElement("updated");
     self::getXmlStream()->text(self::getUpdatedTime());
     self::getXmlStream()->endElement();
     self::getXmlStream()->startElement("icon");
     self::getXmlStream()->text($page->favicon);
     self::getXmlStream()->endElement();
     self::getXmlStream()->startElement("author");
     self::getXmlStream()->startElement("name");
     self::getXmlStream()->text($page->authorName);
     self::getXmlStream()->endElement();
     self::getXmlStream()->startElement("uri");
     self::getXmlStream()->text($page->authorUri);
     self::getXmlStream()->endElement();
     self::getXmlStream()->startElement("email");
     self::getXmlStream()->text($page->authorEmail);
     self::getXmlStream()->endElement();
     self::getXmlStream()->endElement();
     $link = new LinkNavigation("", "start", "Home");
     self::renderLink($link);
     $link = new LinkNavigation("?" . getQueryString(), "self");
     self::renderLink($link);
     $urlparam = "?";
     if (!is_null(GetUrlParam(DB))) {
         $urlparam = addURLParameter($urlparam, DB, GetUrlParam(DB));
     }
     if ($config['cops_generate_invalid_opds_stream'] == 0 || preg_match("/(MantanoReader|FBReader)/", $_SERVER['HTTP_USER_AGENT'])) {
         // Good and compliant way of handling search
         $urlparam = addURLParameter($urlparam, "page", Base::PAGE_OPENSEARCH);
         $link = new Link("feed.php" . $urlparam, "application/opensearchdescription+xml", "search", "Search here");
     } else {
         // Bad way, will be removed when OPDS client are fixed
         $urlparam = addURLParameter($urlparam, "query", "{searchTerms}");
         $urlparam = str_replace("%7B", "{", $urlparam);
         $urlparam = str_replace("%7D", "}", $urlparam);
         $link = new Link($config['cops_full_url'] . 'feed.php' . $urlparam, "application/atom+xml", "search", "Search here");
     }
     self::renderLink($link);
     if ($page->containsBook() && !is_null($config['cops_books_filter']) && count($config['cops_books_filter']) > 0) {
         $Urlfilter = getURLParam("tag", "");
         foreach ($config['cops_books_filter'] as $lib => $filter) {
             $link = new LinkFacet("?" . addURLParameter(getQueryString(), "tag", $filter), $lib, localize("tagword.title"), $filter == $Urlfilter);
             self::renderLink($link);
         }
     }
 }
Пример #2
0
require_once "serie.php";
require_once "tag.php";
require_once "language.php";
require_once "customcolumn.php";
require_once "book.php";
require_once "resources/doT-php/doT.php";
// If we detect that an OPDS reader try to connect try to redirect to feed.php
if (preg_match("/(MantanoReader|FBReader|Stanza|Marvin|Aldiko|Moon+ Reader|Chunky)/", $_SERVER['HTTP_USER_AGENT'])) {
    header("location: feed.php");
    exit;
}
$page = getURLParam("page", Base::PAGE_INDEX);
$query = getURLParam("query");
$qid = getURLParam("id");
$n = getURLParam("n", "1");
$database = GetUrlParam(DB);
// Access the database ASAP to be sure it's readable, redirect if that's not the case.
// It has to be done before any header is sent.
Base::checkDatabaseAvailability();
if ($config['cops_fetch_protect'] == "1") {
    session_start();
    if (!isset($_SESSION['connected'])) {
        $_SESSION['connected'] = 0;
    }
}
header("Content-Type:text/html;charset=utf-8");
$data = array("title" => $config['cops_title_default'], "version" => VERSION, "opds_url" => $config['cops_full_url'] . "feed.php", "customHeader" => "", "template" => getCurrentTemplate(), "server_side_rendering" => useServerSideRendering(), "current_css" => getCurrentCss(), "favico" => $config['cops_icon'], "getjson_url" => "getJSON.php?" . addURLParameter(getQueryString(), "complete", 1));
if (preg_match("/Kindle/", $_SERVER['HTTP_USER_AGENT'])) {
    $data["customHeader"] = '<style media="screen" type="text/css"> html { font-size: 75%; -webkit-text-size-adjust: 75%; -ms-text-size-adjust: 75%; }</style>';
}
$headcontent = file_get_contents('templates/' . getCurrentTemplate() . '/file.html');
Пример #3
0
 public static function getDbDirectory($database = NULL)
 {
     global $config;
     if (self::isMultipleDatabaseEnabled()) {
         if (is_null($database)) {
             $database = GetUrlParam(DB, 0);
         }
         $array = array_values($config['calibre_directory']);
         return $array[$database];
     }
     return $config['calibre_directory'];
 }
Пример #4
0
 public static function getJson($complete = false)
 {
     global $config;
     $page = getURLParam("page", Base::PAGE_INDEX);
     $query = getURLParam("query");
     $search = getURLParam("search");
     $qid = getURLParam("id");
     $n = getURLParam("n", "1");
     $database = GetUrlParam(DB);
     $currentPage = Page::getPage($page, $qid, $query, $n);
     $currentPage->InitializeContent();
     if ($search) {
         return self::getContentArrayTypeahead($currentPage);
     }
     $out = array("title" => $currentPage->title);
     $entries = array();
     foreach ($currentPage->entryArray as $entry) {
         array_push($entries, self::getContentArray($entry));
     }
     if (!is_null($currentPage->book)) {
         $out["book"] = self::getFullBookContentArray($currentPage->book);
     }
     $out["databaseId"] = GetUrlParam(DB, "");
     $out["databaseName"] = Base::getDbName();
     if ($out["databaseId"] == "") {
         $out["databaseName"] = "";
     }
     $out["fullTitle"] = $out["title"];
     if ($out["databaseId"] != "" && $out["databaseName"] != $out["fullTitle"]) {
         $out["fullTitle"] = $out["databaseName"] . " > " . $out["fullTitle"];
     }
     $out["page"] = $page;
     $out["multipleDatabase"] = Base::isMultipleDatabaseEnabled() ? 1 : 0;
     $out["entries"] = $entries;
     $out["isPaginated"] = 0;
     if ($currentPage->isPaginated()) {
         $prevLink = $currentPage->getPrevLink();
         $nextLink = $currentPage->getNextLink();
         $out["isPaginated"] = 1;
         $out["prevLink"] = "";
         if (!is_null($prevLink)) {
             $out["prevLink"] = $prevLink->hrefXhtml();
         }
         $out["nextLink"] = "";
         if (!is_null($nextLink)) {
             $out["nextLink"] = $nextLink->hrefXhtml();
         }
         $out["maxPage"] = $currentPage->getMaxPage();
         $out["currentPage"] = $currentPage->n;
     }
     if (!is_null(getURLParam("complete")) || $complete) {
         $out = self::addCompleteArray($out);
     }
     $out["containsBook"] = 0;
     if ($currentPage->containsBook()) {
         $out["containsBook"] = 1;
     }
     $out["abouturl"] = "index.php" . addURLParameter("?page=" . Base::PAGE_ABOUT, DB, $database);
     if ($page == Base::PAGE_ABOUT) {
         $temp = preg_replace("/\\<h1\\>About COPS\\<\\/h1\\>/", "<h1>About COPS " . VERSION . "</h1>", file_get_contents('about.html'));
         $out["fullhtml"] = $temp;
     }
     $out["homeurl"] = "index.php";
     if ($page != Base::PAGE_INDEX && !is_null($database)) {
         $out["homeurl"] = $out["homeurl"] . "?" . addURLParameter("", DB, $database);
     }
     return $out;
 }
Пример #5
0
Файл: book.php Проект: ha-y/cops
 public function getDetailUrl()
 {
     $urlParam = $this->getUri();
     if (!is_null(GetUrlParam(DB))) {
         $urlParam = addURLParameter($urlParam, DB, GetUrlParam(DB));
     }
     return 'index.php' . $urlParam;
 }
Пример #6
0
        }
        return str_replace("&", "&amp;", $out);
    };
    $data = preg_replace_callback("/(src=)[\"']([^:]*?)[\"']/", $callback, $data);
    $data = preg_replace_callback("/(href=)[\"']([^:]*?)[\"']/", $callback, $data);
    $data = preg_replace_callback("/(\\@import\\s+)[\"'](.*?)[\"'];/", $callback, $data);
    $data = preg_replace_callback("/(src\\s*:\\s*url\\()(.*?)\\)/", $callback, $data);
    return $data;
}
if (php_sapi_name() === 'cli') {
    return;
}
$idData = getURLParam("data", NULL);
$add = "data={$idData}&";
if (!is_null(GetUrlParam(DB))) {
    $add .= DB . "=" . GetUrlParam(DB) . "&";
}
$myBook = Book::getBookByDataId($idData);
$book = new EPub($myBook->getFilePath("EPUB", $idData));
$book->initSpineComponent();
if (!isset($_GET["comp"])) {
    notFound();
    return;
}
$component = $_GET["comp"];
try {
    $data = getComponentContent($book, $component, $add);
    $expires = 60 * 60 * 24 * 14;
    header("Pragma: public");
    header("Cache-Control: maxage=" . $expires);
    header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT');
Пример #7
0
        $file = $book->getFilePath($type, $idData);
    }
    if (!$file || !file_exists($file)) {
        notFound();
        return;
    }
}
switch ($type) {
    case "jpg":
        header("Content-Type: image/jpeg");
        //by default, we don't cache
        $thumbnailCacheFullpath = null;
        if (isset($config['cops_thumbnail_cache_directory']) && $config['cops_thumbnail_cache_directory'] !== '') {
            $thumbnailCacheFullpath = $config['cops_thumbnail_cache_directory'];
            //if multiple databases, add a subfolder with the database ID
            $thumbnailCacheFullpath .= !is_null(GetUrlParam(DB)) ? 'db-' . GetUrlParam(DB) . DIRECTORY_SEPARATOR : '';
            //when there are lots of thumbnails, it's better to save files in subfolders, so if the book's uuid is
            //"01234567-89ab-cdef-0123-456789abcdef", we will save the thumbnail in .../0/12/34567-89ab-cdef-0123-456789abcdef-...
            $thumbnailCacheFullpath .= substr($book->uuid, 0, 1) . DIRECTORY_SEPARATOR . substr($book->uuid, 1, 2) . DIRECTORY_SEPARATOR;
            //check if cache folder exists or create it
            if (file_exists($thumbnailCacheFullpath) || mkdir($thumbnailCacheFullpath, 0700, true)) {
                //we name the thumbnail from the book's uuid and it's dimensions (width and/or height)
                $thumbnailCacheName = substr($book->uuid, 3) . '-' . getURLParam("width") . 'x' . getURLParam("height") . '.jpg';
                $thumbnailCacheFullpath = $thumbnailCacheFullpath . $thumbnailCacheName;
            } else {
                //error creating the folder, so we don't cache
                $thumbnailCacheFullpath = null;
            }
        }
        if ($thumbnailCacheFullpath !== null && file_exists($thumbnailCacheFullpath)) {
            //return the already cached thumbnail
Пример #8
0
 public static function getLink($book, $type, $mime, $rel, $filename, $idData, $title = NULL, $height = NULL)
 {
     global $config;
     $urlParam = addURLParameter("", "data", $idData);
     if (Base::useAbsolutePath() || $rel == Link::OPDS_THUMBNAIL_TYPE || $type == "epub" && $config['cops_update_epub-metadata']) {
         if ($type != "jpg") {
             $urlParam = addURLParameter($urlParam, "type", $type);
         }
         if ($rel == Link::OPDS_THUMBNAIL_TYPE) {
             $urlParam = self::handleThumbnailLink($urlParam, $height);
         }
         $urlParam = addURLParameter($urlParam, "id", $book->id);
         if (!is_null(GetUrlParam(DB))) {
             $urlParam = addURLParameter($urlParam, DB, GetUrlParam(DB));
         }
         if ($config['cops_thumbnail_handling'] != "1" && !empty($config['cops_thumbnail_handling']) && $rel == Link::OPDS_THUMBNAIL_TYPE) {
             return new Link($config['cops_thumbnail_handling'], $mime, $rel, $title);
         } else {
             return new Link("fetch.php?" . $urlParam, $mime, $rel, $title);
         }
     } else {
         return new Link(str_replace('%2F', '/', rawurlencode($book->path . "/" . $filename)), $mime, $rel, $title);
     }
 }