]> git.openstreetmap.org Git - nominatim.git/blob - lib/log.php
over tokenising 'la'
[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 ($sType == 'reverse')
30                 {
31                         $aStartTime = explode('.',$hLog[0]);
32                         file_put_contents('/data/mapquest/opentile_http/logs/nominatimreverse',
33                                 $aStartTime[0].','.$aStartTime[1].','.
34                                 php_uname('n').','.
35                                 '"'.addslashes(isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'').'",'.
36                                 '"'.addslashes($hLog[1]).'",'.
37                                 $_GET['lat'].','.
38                                 $_GET['lon'].','.
39                                 $_GET['zoom'].','.
40                                 '"'.addslashes($_SERVER['HTTP_USER_AGENT']).'",'.
41                                 '"'.addslashes($_GET['format']).'"'."\n",
42                         FILE_APPEND);
43                 }
44
45
46                 return $hLog;
47         }
48
49         function logEnd(&$oDB, $hLog, $iNumResults)
50         {
51                 $aEndTime = explode('.',microtime(true));
52                 if (!$aEndTime[1]) $aEndTime[1] = '0';
53                 $sEndTime = date('Y-m-d H:i:s',$aEndTime[0]).'.'.$aEndTime[1];
54
55                 if (CONST_Log_DB)
56                 {
57                         $sSQL = 'update query_log set endtime = '.getDBQuoted($sEndTime).', results = '.$iNumResults;
58                         $sSQL .= ' where starttime = '.getDBQuoted($hLog[0]);
59                         $sSQL .= ' and ipaddress = '.getDBQuoted($hLog[1]);
60                         $sSQL .= ' and query = '.getDBQuoted($hLog[3]);
61                         $oDB->query($sSQL);
62
63                         $sSQL = 'update new_query_log set endtime = '.getDBQuoted($sEndTime).', results = '.$iNumResults;
64                         $sSQL .= ' where starttime = '.getDBQuoted($hLog[0]);
65                         $sSQL .= ' and ipaddress = '.getDBQuoted($hLog[1]);
66                         $sSQL .= ' and query = '.getDBQuoted($hLog[2]);
67                         $oDB->query($sSQL);
68                 }
69
70                 $aStartTime = explode('.',$hLog[0]);
71                 file_put_contents('/data/mapquest/opentile_http/logs/nominatimsearch',
72                                 $aStartTime[0].','.$aStartTime[1].','.
73                                 php_uname('n').','.
74                                 '"'.addslashes(isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:'').'",'.
75                                 '"'.addslashes($hLog[1]).'",'.
76                                 '"'.addslashes($hLog[3]).'",'.
77                                 '"'.addslashes($_SERVER['HTTP_USER_AGENT']).'",'.
78                                 '"'.addslashes($_GET['format']).'",'.
79                                 $iNumResults."\n",
80                         FILE_APPEND);
81
82         }