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