-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaps_create_trips_xml.php
More file actions
104 lines (84 loc) · 3.29 KB
/
maps_create_trips_xml.php
File metadata and controls
104 lines (84 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
// update 2016-04-13 to move to settings.php for config location
// last updated for production use 2013-08-22 9:17am by Mike Green
// changes:
// 2013-08-22 revised underlying vw_lines time conversion to use correct timestamp, resolved bug with not showing posts in the last few hours
// added parseToXML to all possible strings returned that might contain ampersand or other errant characters
//no cache headers
header("Expires: Mon, 26 Jul 1990 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
// include forum config file for DB info
include "settings.php";
include ($configPath);
// get DB creds from forum config
$username=$dbuser;
$password=$dbpasswd;
$database=$dbname;
$server=$dbhost;
function parseToXML($htmlStr)
{
$xmlStr=$htmlStr;
$xmlStr=str_replace('<','<',$xmlStr);
$xmlStr=str_replace('>','>',$xmlStr);
$xmlStr=str_replace('"','"',$xmlStr);
$xmlStr=str_replace("'",''',$xmlStr);
$xmlStr=str_replace("&",'&',$xmlStr);
// fix https://github.com/pilotsnpaws/pnp_maps/issues/28
// might be able to remove the above manual ones from the past
// mjg 2020-01-08
// $xmlStr=str_replace('—','-',$xmlStr);
$xmlStr=htmlspecialchars($xmlStr,ENT_IGNORE);
return $xmlStr;
}
//default the filter to return 30 day old posts if none provided via URL
$lastPostAge = 30;
// Get parameters from URL
if (isset($_GET['lastPostAge'])){
$lastPostAge = $_GET["lastPostAge"];
}
// define mysqli connection
$mysqli = new mysqli($server, $username, $password, $database);
// Check connection
if (mysqli_connect_errno($mysqli))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} else { } ;
$query = 'select last_post, last_post_human, topic_id, topic_title, pnp_sendZip, '
. 'sendLat, sendLon, pnp_recZip, recLat, recLon, sendCity, recCity, forum_id, trip_status '
. 'from vw_lines '
. 'where trip_status = \'Open\' '
. 'AND last_post > date_add(cast(current_date as datetime), INTERVAL -'
. $lastPostAge
. ' DAY)';
// echo $query;
$result = $mysqli->query($query);
// Start XML file, echo parent node
header("Content-type: text/xml");
echo '<trips>';
// Iterate through the rows, printing XML nodes for each
// $row = $result->fetch_assoc();
while($row = $result->fetch_assoc()){
// ADD TO XML DOCUMENT NODE
echo '<trip ';
echo 'lastPost="' . $row['last_post'] . '" ';
echo 'lastPostHuman="' . $row['last_post_human'] . '" ';
echo 'topicID="' . $row['topic_id'] . '" ';
echo 'topicTitle="' . parseToXML($row['topic_title']) . '" ';
echo 'sendZip="' . parseToXML($row['pnp_sendZip']) . '" ';
echo 'sendLat="' . parseToXML($row['sendLat']) . '" ';
echo 'sendLon="' . parseToXML($row['sendLon']) . '" ';
echo 'recZip="' . parseToXML($row['pnp_recZip']) . '" ';
echo 'recLat="' . parseToXML($row['recLat']) . '" ';
echo 'recLon="' . parseToXML($row['recLon']) . '" ';
echo 'sendCity="' . parseToXML($row['sendCity']) . '" ';
echo 'recCity="' . parseToXML($row['recCity']) . '" ';
echo 'forum_id="' . parseToXML($row['forum_id']) . '" ';
echo 'trip_status="' . parseToXML($row['trip_status']) . '" ';
echo '/>';
}
// End XML file
echo '</trips>';
?>