/** * The function for the head of the HTML catalog * @dataProvider providerTemplate */ public function testGenerateHeader($templateName) { $_SERVER["HTTP_USER_AGENT"] = "Firefox"; global $config; $headcontent = file_get_contents(dirname(__FILE__) . '/../templates/' . $templateName . '/file.html'); $template = new doT(); $tpl = $template->template($headcontent, NULL); $data = array("title" => $config['cops_title_default'], "version" => VERSION, "opds_url" => $config['cops_full_url'] . "feed.php", "customHeader" => "", "template" => $templateName, "server_side_rendering" => useServerSideRendering(), "current_css" => getCurrentCss(), "favico" => $config['cops_icon'], "getjson_url" => "getJSON.php?" . addURLParameter(getQueryString(), "complete", 1)); $head = $tpl($data); $this->assertContains("<head>", $head); $this->assertContains("</head>", $head); }
function serverSideRender($data) { // Get the templates $theme = getCurrentTemplate(); $header = file_get_contents('templates/' . $theme . '/header.html'); $footer = file_get_contents('templates/' . $theme . '/footer.html'); $main = file_get_contents('templates/' . $theme . '/main.html'); $bookdetail = file_get_contents('templates/' . $theme . '/bookdetail.html'); $page = file_get_contents('templates/' . $theme . '/page.html'); // Generate the function for the template $template = new doT(); $dot = $template->template($page, array("bookdetail" => $bookdetail, "header" => $header, "footer" => $footer, "main" => $main)); // If there is a syntax error in the function created // $dot will be equal to FALSE if (!$dot) { return FALSE; } // Execute the template if (!empty($data)) { return $dot($data); } return NULL; }
// 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>