]> git.openstreetmap.org Git - nominatim.git/blob - lib/init-website.php
replace database abstraction DB with PDO
[nominatim.git] / lib / init-website.php
1 <?php
2
3 require_once('init.php');
4 require_once('ParameterParser.php');
5 require_once(CONST_Debug ? 'DebugHtml.php' : 'DebugNone.php');
6
7 /***************************************************************************
8  *
9  * Error handling functions
10  *
11  */
12
13
14 function chksql($oSql, $sMsg = 'Database request failed')
15 {
16     return $oSql;
17 }
18
19
20 function userError($sMsg)
21 {
22     throw new Exception($sMsg, 400);
23 }
24
25
26 function exception_handler_html($exception)
27 {
28     http_response_code($exception->getCode());
29     header('Content-type: text/html; charset=UTF-8');
30     include(CONST_BasePath.'/lib/template/error-html.php');
31 }
32
33 function exception_handler_json($exception)
34 {
35     http_response_code($exception->getCode());
36     header('Content-type: application/json; charset=utf-8');
37     include(CONST_BasePath.'/lib/template/error-json.php');
38 }
39
40 function exception_handler_xml($exception)
41 {
42     http_response_code($exception->getCode());
43     header('Content-type: text/xml; charset=utf-8');
44     echo '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
45     include(CONST_BasePath.'/lib/template/error-xml.php');
46 }
47
48
49 function set_exception_handler_by_format($sFormat = 'html')
50 {
51     if ($sFormat == 'html') {
52         set_exception_handler('exception_handler_html');
53     } elseif ($sFormat == 'xml') {
54         set_exception_handler('exception_handler_xml');
55     } else {
56         set_exception_handler('exception_handler_json');
57     }
58 }
59 // set a default
60 set_exception_handler_by_format();
61
62
63 /***************************************************************************
64  * HTTP Reply header setup
65  */
66
67 if (CONST_NoAccessControl) {
68     header('Access-Control-Allow-Origin: *');
69     header('Access-Control-Allow-Methods: OPTIONS,GET');
70     if (!empty($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
71         header('Access-Control-Allow-Headers: '.$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
72     }
73 }
74 if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'OPTIONS') exit;
75
76 if (CONST_Debug) header('Content-type: text/html; charset=utf-8');