-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert.php
93 lines (83 loc) · 2.31 KB
/
insert.php
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
<?php
// Helper Class for Parsing Information
include 'helper.php';
include 'connect.php';
// variables to insert into mongo
$name = $_POST['name'];
$screen_name = $_POST['screen_name'];
$tweet = $_POST['species'];
$date = $_POST['seendate'];
$specSound = $_POST['specSound'];
if(!$specSound == "")
{
// Link not submitted, voicemail mp3 link inserted
if(!strpos($specSound, 'http'))
// adds a backslash to voice
$voice = substr("voice\\", 0, 6);
$specSound = $voice.$specSound;
}
else
{
$specSound = null;
}
// Gets Geo Data
if(isset($_POST['lat']) && $_POST['long'])
{
$lat = $_POST['lat'];
$long = $_POST['long'];
$locInfo = GetLocationInfo($lat, $long);
// Declare and set geocoded information
$interLocation = $locInfo['interLocation'];
$zipCode = $locInfo['zipCode'];
$city = $locInfo['city'];
$county = $locInfo['county'];
$state = $locInfo['state'];
$country = $locInfo['country'];
}
else
{
$lat = NULL;
$long = NULL;
$interLocation = NULL;
$zipCode = NULL;
$city = NULL;
$county = NULL;
$state = NULL;
$country = NULL;
}
// pending values
$hashtags = NULL;
$img = NULL;
$specImg = NULL;
$specVid = NULL;
try
{
// Generates a MongoDB Array and Inserts
$tweet = array("screen_name" => $screen_name,
"name" => $name, "tweet" => $tweet, "hashtags" => $hashtags,
"date" => $date, "img" => $img, "species" => null, "comment" => null,
"specImg" => $specImg, "specSound" => $specSound, "specVid" => $specVid,
"geo" => array("lat" => $lat, "long" => $long, "interLocation" => null,
"zipCode" => null, "city" => null, "county" => null,
"state" => null, "country" => null));
// Since tweet id is used as _id field, update prevents mongo from
//(die)ing on duplicate id entries. With params 'safe' & 'upsert'
// all duplicate entries are ignored, but catches other insertion errors.
$collection->insert($tweet, array('safe' =>True));
}
catch(MongoException $e)
{
// Error code 4 results from duplicate error, skip
if($e->getCode() == 11000);
else
die('Failed to insert '.$e->getMessage());
}
?>
<html>
<script type="text/javascript">
alert("Data has been submitted!");
</script>
</html>
<?php
header("Location: http://hawaiiwetlands.org:8080/");
?>