These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 <[email protected]> |
||
7 | * |
||
8 | */ |
||
9 | |||
10 | require_once dirname(__FILE__) . '/config.php'; |
||
11 | require_once dirname(__FILE__) . '/base.php'; |
||
12 | |||
13 | // If we detect that an OPDS reader try to connect try to redirect to feed.php |
||
14 | if (preg_match('/(MantanoReader|FBReader|Stanza|Marvin|Aldiko|Moon\+ Reader|Chunky|AlReader|org\.ebookdroid)/', $_SERVER['HTTP_USER_AGENT'])) { |
||
15 | header('location: feed.php'); |
||
16 | exit(); |
||
17 | } |
||
18 | |||
19 | $page = getURLParam('page', Base::PAGE_INDEX); |
||
20 | $query = getURLParam('query'); |
||
21 | $qid = getURLParam('id'); |
||
22 | $n = getURLParam('n', '1'); |
||
23 | $database = GetUrlParam(DB); |
||
24 | |||
25 | |||
26 | // Access the database ASAP to be sure it's readable, redirect if that's not the case. |
||
27 | // It has to be done before any header is sent. |
||
28 | Base::checkDatabaseAvailability(); |
||
29 | |||
30 | View Code Duplication | if ($config ['cops_fetch_protect'] == '1') { |
|
0 ignored issues
–
show
|
|||
31 | session_start(); |
||
32 | if (!isset($_SESSION['connected'])) { |
||
33 | $_SESSION['connected'] = 0; |
||
34 | } |
||
35 | } |
||
36 | |||
37 | header('Content-Type:text/html;charset=utf-8'); |
||
38 | |||
39 | $data = array('title' => $config['cops_title_default'], |
||
40 | 'version' => VERSION, |
||
41 | 'opds_url' => $config['cops_full_url'] . 'feed.php', |
||
42 | 'customHeader' => '', |
||
43 | 'template' => getCurrentTemplate(), |
||
44 | 'server_side_rendering' => useServerSideRendering(), |
||
45 | 'current_css' => getCurrentCss(), |
||
46 | 'favico' => $config['cops_icon'], |
||
47 | 'getjson_url' => 'getJSON.php?' . addURLParameter(getQueryString(), 'complete', 1)); |
||
48 | if (preg_match('/Kindle/', $_SERVER['HTTP_USER_AGENT'])) { |
||
49 | $data['customHeader'] = '<style media="screen" type="text/css"> html { font-size: 75%; -webkit-text-size-adjust: 75%; -ms-text-size-adjust: 75%; }</style>'; |
||
50 | } |
||
51 | $headcontent = file_get_contents('templates/' . getCurrentTemplate() . '/file.html'); |
||
52 | $template = new doT(); |
||
53 | $dot = $template->template($headcontent, NULL); |
||
54 | echo($dot($data)); |
||
55 | ?><body> |
||
56 | <?php |
||
57 | if (useServerSideRendering()) { |
||
58 | // Get the data |
||
59 | $data = JSONRenderer::getJson(true); |
||
60 | |||
61 | echo serverSideRender($data); |
||
62 | } |
||
63 | ?> |
||
64 | </body> |
||
65 | </html> |
||
66 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.