]> git.openstreetmap.org Git - nominatim.git/blob - lib/log.php
Merge remote-tracking branch 'upstream/master'
[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                         if (isset($_GET['email']))
21                                 $sUserAgent = $_GET['email'];
22                         else
23                                 $sUserAgent = $_SERVER['HTTP_USER_AGENT'];
24                         $sSQL = 'insert into new_query_log (type,starttime,query,ipaddress,useragent,language,format,searchterm)';
25                         $sSQL .= ' values ('.getDBQuoted($sType).','.getDBQuoted($hLog[0]).','.getDBQuoted($hLog[2]);
26                         $sSQL .= ','.getDBQuoted($hLog[1]).','.getDBQuoted($sUserAgent).','.getDBQuoted(join(',',$aLanguageList)).','.getDBQuoted($sOutputFormat).','.getDBQuoted($hLog[3]).')';
27                         $oDB->query($sSQL);
28                 }
29
30                 if (CONST_Log_File && CONST_Log_File_ReverseLog != '')
31                 {
32                         if ($sType == 'reverse')
33                         {
34                                 $aStartTime = explode('.',$hLog[0]);
35                                 file_put_contents(CONST_Log_File_ReverseLog,
36                                                                 $aStartTime[0].','.$aStartTime[1].','.
37                                                                 php_uname('n').','.
38                                                                 '"'.addslashes(isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'').'",'.
39                                                                 '"'.addslashes($hLog[1]).'",'.
40                                                                 $_GET['lat'].','.
41                                                                 $_GET['lon'].','.
42                                                                 $_GET['zoom'].','.
43                                                                 '"'.addslashes($_SERVER['HTTP_USER_AGENT']).'",'.
44                                                                 '"'.addslashes($sOutputFormat).'"'."\n",
45                                                                 FILE_APPEND);
46                         }
47                 }
48
49                 return $hLog;
50         }
51
52         function logEnd(&$oDB, $hLog, $iNumResults)
53         {
54                 $aEndTime = explode('.',microtime(true));
55                 if (!$aEndTime[1]) $aEndTime[1] = '0';
56                 $sEndTime = date('Y-m-d H:i:s',$aEndTime[0]).'.'.$aEndTime[1];
57
58                 if (CONST_Log_DB)
59                 {
60                         $sSQL = 'update new_query_log set endtime = '.getDBQuoted($sEndTime).', results = '.$iNumResults;
61                         $sSQL .= ' where starttime = '.getDBQuoted($hLog[0]);
62                         $sSQL .= ' and ipaddress = '.getDBQuoted($hLog[1]);
63                         $sSQL .= ' and query = '.getDBQuoted($hLog[2]);
64                         $oDB->query($sSQL);
65                 }
66
67                 if (CONST_Log_File && CONST_Log_File_SearchLog != '')
68                 {
69                         $aStartTime = explode('.',$hLog[0]);
70                         file_put_contents(CONST_Log_File_SearchLog,
71                                         $aStartTime[0].','.$aStartTime[1].','.
72                                         php_uname('n').','.
73                                         '"'.addslashes(isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'').'",'.
74                                         '"'.addslashes($hLog[1]).'",'.
75                                         '"'.addslashes($hLog[3]).'",'.
76                                         '"'.addslashes($_SERVER['HTTP_USER_AGENT']).'",'.
77                                         '"'.addslashes((isset($_GET['format']))?$_GET['format']:'').'",'.
78                                         $iNumResults."\n",
79                                         FILE_APPEND);
80                 }
81
82         }