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