]> git.openstreetmap.org Git - nominatim.git/blob - lib/log.php
Merge branch 'master' of http://github.com/twain47/Nominatim
[nominatim.git] / lib / log.php
1 <?php
2
3         function logStart(&$oDB, $sType = '', $sQuery = '', $aLanguageList = array())
4         {
5                 $aStartTime = explode('.',microtime(true));
6                 if (!$aStartTime[1]) $aStartTime[1] = '0';
7
8                 $sOutputFormat = '';
9                 if (isset($_GET['format'])) $sOutputFormat = $_GET['format'];
10
11                 $hLog = array(
12                                 date('Y-m-d H:i:s',$aStartTime[0]).'.'.$aStartTime[1],
13                                 $_SERVER["REMOTE_ADDR"],
14                                 $_SERVER['QUERY_STRING'],
15                                 $sQuery
16                         );
17
18                 if (CONST_Log_DB)
19                 {
20                         $sSQL = 'insert into new_query_log (type,starttime,query,ipaddress,useragent,language,format,searchterm)';
21                         $sSQL .= ' values ('.getDBQuoted($sType).','.getDBQuoted($hLog[0]).','.getDBQuoted($hLog[2]);
22                         $sSQL .= ','.getDBQuoted($hLog[1]).','.getDBQuoted($_SERVER['HTTP_USER_AGENT']).','.getDBQuoted(join(',',$aLanguageList)).','.getDBQuoted($_GET['format']).','.getDBQuoted($hLog[3]).')';
23                         $oDB->query($sSQL);
24                 }
25
26                 if (CONST_Log_File && CONST_Log_File_ReverseLog != '')
27                 {
28                 if ($sType == 'reverse')
29                 {
30                         $aStartTime = explode('.',$hLog[0]);
31                         file_put_contents(CONST_Log_File_ReverseLog,
32                                 $aStartTime[0].','.$aStartTime[1].','.
33                                 php_uname('n').','.
34                                 '"'.addslashes(isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'').'",'.
35                                 '"'.addslashes($hLog[1]).'",'.
36                                 $_GET['lat'].','.
37                                 $_GET['lon'].','.
38                                 $_GET['zoom'].','.
39                                 '"'.addslashes($_SERVER['HTTP_USER_AGENT']).'",'.
40                                 '"'.addslashes($sOutputFormat).'"'."\n",
41                         FILE_APPEND);
42                 }
43                 }
44
45                 return $hLog;
46         }
47
48         function logEnd(&$oDB, $hLog, $iNumResults)
49         {
50                 $aEndTime = explode('.',microtime(true));
51                 if (!$aEndTime[1]) $aEndTime[1] = '0';
52                 $sEndTime = date('Y-m-d H:i:s',$aEndTime[0]).'.'.$aEndTime[1];
53
54                 if (CONST_Log_DB)
55                 {
56                         $sSQL = 'update new_query_log set endtime = '.getDBQuoted($sEndTime).', results = '.$iNumResults;
57                         $sSQL .= ' where starttime = '.getDBQuoted($hLog[0]);
58                         $sSQL .= ' and ipaddress = '.getDBQuoted($hLog[1]);
59                         $sSQL .= ' and query = '.getDBQuoted($hLog[2]);
60                         $oDB->query($sSQL);
61                 }
62
63                 if (CONST_Log_File && CONST_Log_File_SearchLog != '')
64                 {
65                 $aStartTime = explode('.',$hLog[0]);
66                 file_put_contents(CONST_Log_File_SearchLog,
67                                 $aStartTime[0].','.$aStartTime[1].','.
68                                 php_uname('n').','.
69                                 '"'.addslashes(isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'').'",'.
70                                 '"'.addslashes($hLog[1]).'",'.
71                                 '"'.addslashes($hLog[3]).'",'.
72                                 '"'.addslashes($_SERVER['HTTP_USER_AGENT']).'",'.
73                                 '"'.addslashes((isset($_GET['format']))?$_GET['format']:'').'",'.
74                                 $iNumResults."\n",
75                         FILE_APPEND);
76                 }
77
78         }