Example #1
0
 public function testGetFullBookContentArray()
 {
     $book = Book::getBookById(17);
     $test = JSONRenderer::getFullBookContentArray($book);
     $this->assertCount(1, $test["authors"]);
     $this->assertCount(3, $test["tags"]);
     $this->assertCount(3, $test["datas"]);
 }
Example #2
0
 public function testTypeaheadSearchMultiDatabase()
 {
     global $config;
     $_GET["page"] = Base::PAGE_OPENSEARCH_QUERY;
     $_GET["query"] = "art";
     $_GET["search"] = "1";
     $_GET["multi"] = "1";
     $config['calibre_directory'] = array("Some books" => dirname(__FILE__) . "/BaseWithSomeBooks/", "One book" => dirname(__FILE__) . "/BaseWithOneBook/");
     $array = JSONRenderer::getJson();
     $this->assertCount(5, $array);
     $this->assertEquals("Some books", $array[0]["title"]);
     $this->assertEquals("1 author", $array[1]["title"]);
     $this->assertEquals("2 series", $array[2]["title"]);
     $this->assertEquals("One book", $array[3]["title"]);
     $this->assertEquals("1 book", $array[4]["title"]);
     $_GET["query"] = NULL;
     $_GET["search"] = NULL;
 }
Example #3
0
// 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');
$template = new doT();
$dot = $template->template($headcontent, NULL);
echo $dot($data);
?>
<body>
<?php 
if (useServerSideRendering()) {
    // Get the data
    require_once "JSON_renderer.php";
    $data = JSONRenderer::getJson(true);
    echo serverSideRender($data);
}
?>
</body>
</html>
Example #4
0
 public function testRenderCustomColumns()
 {
     global $config;
     $_SERVER["HTTP_USER_AGENT"] = "Firefox";
     $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithCustomColumns/";
     $_GET["custom"] = "11";
     $config['cops_calibre_custom_column'] = array("custom_01", "custom_02", "custom_03", "custom_04", "custom_05", "custom_06", "custom_07", "custom_08", "custom_09", "custom_10", "custom_11");
     $config['cops_calibre_custom_column_list'] = array("custom_01", "custom_02", "custom_03", "custom_04", "custom_05", "custom_06", "custom_07", "custom_08", "custom_09", "custom_10", "custom_11");
     $config['cops_calibre_custom_column_preview'] = array("custom_01", "custom_02", "custom_03", "custom_04", "custom_05", "custom_06", "custom_07", "custom_08", "custom_09", "custom_10", "custom_11");
     Base::clearDb();
     $book = Book::getBookById(223);
     $json = JSONRenderer::getBookContentArray($book);
     /* @var CustomColumn[] $custom */
     $custom = $json["customcolumns_list"];
     $this->assertEquals("custom_01", $custom[0]['customColumnType']['columnTitle']);
     $this->assertEquals("text_2", $custom[0]['htmlvalue']);
     $this->assertEquals("custom_02", $custom[1]['customColumnType']['columnTitle']);
     $this->assertEquals("a", $custom[1]['htmlvalue']);
     $this->assertEquals("custom_03", $custom[2]['customColumnType']['columnTitle']);
     $this->assertEquals("<div>Not Set</div>", $custom[2]['htmlvalue']);
     $this->assertEquals("custom_04", $custom[3]['customColumnType']['columnTitle']);
     $this->assertEquals("", $custom[3]['htmlvalue']);
     $this->assertEquals("custom_05", $custom[4]['customColumnType']['columnTitle']);
     $this->assertEquals("val05", $custom[4]['htmlvalue']);
     $this->assertEquals("custom_06", $custom[5]['customColumnType']['columnTitle']);
     $this->assertEquals("Not Set", $custom[5]['htmlvalue']);
     $this->assertEquals("custom_07", $custom[6]['customColumnType']['columnTitle']);
     $this->assertEquals("100000.0", $custom[6]['htmlvalue']);
     $this->assertEquals("custom_08", $custom[7]['customColumnType']['columnTitle']);
     $this->assertEquals("Not Set", $custom[7]['htmlvalue']);
     $this->assertEquals("custom_09", $custom[8]['customColumnType']['columnTitle']);
     $this->assertEquals("Not Set", $custom[8]['htmlvalue']);
     $this->assertEquals("custom_10", $custom[9]['customColumnType']['columnTitle']);
     $this->assertEquals("No", $custom[9]['htmlvalue']);
     $_SERVER["HTTP_USER_AGENT"] = "";
     $_GET["custom"] = NULL;
     $config['cops_calibre_custom_column'] = array();
     $config['cops_calibre_custom_column_list'] = array();
     $config['cops_calibre_custom_column_preview'] = array();
     $config['calibre_directory'] = dirname(__FILE__) . "/BaseWithSomeBooks/";
     Base::clearDb();
 }
Example #5
0
<?php

/**
 * COPS (Calibre OPDS PHP Server) HTML main script
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Sébastien Lucas <*****@*****.**>
 *
 */
require_once "config.php";
require_once "JSON_renderer.php";
header("Content-Type:application/json;charset=utf-8");
echo json_encode(JSONRenderer::getJson());