Exemplo n.º 1
2
 public function fetch($delete = false)
 {
     $oImap = imap_open('{' . $this->mail_server . ':993/imap/ssl/notls/novalidate-cert}', $this->username, $this->password);
     $oMailboxStatus = imap_check($oImap);
     $aMessages = imap_fetch_overview($oImap, "1:{$oMailboxStatus->Nmsgs}");
     $validMessages = array();
     foreach ($aMessages as $oMessage) {
         print "Trying message '" . $oMessage->subject . "'";
         $fileContent = $fileType = '';
         $geocoder = factory::create('geocoder');
         $postCode = $geocoder->extract_postcode($oMessage->subject);
         $fromName = null;
         $fromEmail = null;
         if (strpos($oMessage->from, '<')) {
             $split = split('<', $oMessage->from);
             //name - make sure name not an email address
             $fromName = trim($split[0]);
             if (valid_email($fromName)) {
                 $fromName = null;
             }
             //email
             $fromEmail = trim(str_replace('>', '', $split[1]));
         } else {
             $fromEmail = $oMessage->from;
         }
         $images = array();
         $messageStructure = imap_fetchstructure($oImap, $oMessage->msgno);
         if (isset($messageStructure->parts)) {
             $partNumber = 0;
             foreach ($messageStructure->parts as $oPart) {
                 $partNumber++;
                 if ($oPart->subtype == 'PLAIN' && !$postCode) {
                     $messageContent = imap_fetchbody($oImap, $oMessage->msgno, $partNumber);
                     if ($oPart->encoding == 4) {
                         $messageContent = quoted_printable_decode($messageContent);
                     }
                     $postCode = geocoder::extract_postcode($messageContent);
                 } elseif ($oPart->encoding == 3 && in_array($oPart->subtype, array('JPEG', 'PNG'))) {
                     $oImage = null;
                     $encodedBody = imap_fetchbody($oImap, $oMessage->msgno, $partNumber);
                     $fileContent = base64_decode($encodedBody);
                     $oImage = imagecreatefromstring($fileContent);
                     if (imagesx($oImage) > $this->min_import_size && imagesy($oImage) > $this->min_import_size) {
                         array_push($images, $oImage);
                     }
                     $fileType = strtolower($oPart->subtype);
                 }
             }
         }
         //add to the messages array
         array_push($validMessages, array('postcode' => $postCode, 'images' => $images, 'file_type' => $fileType, 'from_address' => $fromAddress, 'from_email' => $fromEmail, 'from_name' => $fromName));
         if ($delete) {
             imap_delete($oImap, $oMessage->msgno);
         }
     }
     imap_close($oImap, CL_EXPUNGE);
     $this->messages = $validMessages;
 }
 public function post_index()
 {
     $address = Input::get('address');
     $address = urlencode($address);
     $loc = geocoder::getLocation($address);
     return View::make('geocode')->with('lng', $loc['lng'])->with('lat', $loc['lat']);
 }
 public function geocodeCitiesAndAddToTable($cities)
 {
     $geocoderInstance = new geocoder($cities);
     $result = $geocoderInstance->geocode();
     //return $result;
     foreach ($result as $object) {
         if ($object->existance == 1) {
             $query = "INSERT INTO {$this->schemaForGeocodingTable}.{$this->geocodingTableName} ({$this->geocodingNameColumn},{$this->geocodingLatColumn},{$this->geocodingLonColumn}) VALUES ('{$object->name}',{$object->lat},{$object->lon});";
             //echo $query;
             $this->doQuery($query);
         }
     }
 }
Exemplo n.º 4
0
             }
             //end if loctype = locality
             if ($i == $length - 1) {
                 //if last element and no loc type then move to next loc type and start over
                 $i_type++;
             }
             $i++;
             sleep(2);
             //give geocoder a rest so no over_query_limit error
         }
         //end foreach locs
     } while (!$match);
     //end do while no loc types match
 } else {
     $location = geocoder::getLocation($loc);
     $formatted_address = geocoder::getFormatted($loc);
 }
 $lat = $location['lat'];
 $lng = $location['lng'];
 /*echo "location array: ";
 		print_r($location); //////////////////debug
 		echo "<br/>formated address: " . $formatted_address;	 ////////////////////////debug* /
 		
 		$locs = explode(',', $loc); //create an array of locations delimited by comma
 		echo "<br/>locations delimited: ";
 		print_r($locs);
 		foreach($locs as $value){
 			$one = urlencode($value);
 			echo "<br/>urlencoded: " .  $one;
 			echo "<br/>types: " . geocoder::getLocType($one);
 		}/////////////////////////////////////debug*/
Exemplo n.º 5
0
$lat16 = $loc16[lat];
$lng16 = $loc16[lng];
$address17 = urlencode($locationName17);
$loc17 = geocoder::getLocation($address17);
$lat17 = $loc17[lat];
$lng17 = $loc17[lng];
$address18 = urlencode($locationName18);
$loc18 = geocoder::getLocation($address18);
$lat18 = $loc18[lat];
$lng18 = $loc18[lng];
$address19 = urlencode($locationName19);
$loc19 = geocoder::getLocation($address19);
$lat19 = $loc19[lat];
$lng19 = $loc19[lng];
$address20 = urlencode($locationName20);
$loc20 = geocoder::getLocation($address20);
$lat20 = $loc20[lat];
$lng20 = $loc20[lng];
?>

<?php 
if (!empty($_POST['address1'])) {
    ?>
<div class="row-fluid">
    <div class="span2"></div>
    <div class="span8">
        <div class="well" style="background-color: #ffffff; border: 2px solid #1fbad6;text-align:center;">
        


<?php 
Exemplo n.º 6
0
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
    <Message>Thank you for contacting us! Please remember to have your message be in the form: location/disability/problem you're facing/name(optional)</Message>
</Response>
<?php 
include 'mapsclass.php';
include 'stringparse.php';
$servername = "ec2-54-170-43-20.eu-west-1.compute.amazonaws.com";
$username = "******";
$password = "******";
$dbname = "add_db";
$smsstring = $_REQUEST['Body'];
$checkflag = checkparse($smsstring);
$parsed = parsetolist($smsstring);
$address = urlencode($parsed[0]);
$loc = geocoder::getLocation($address);
$numberstring = $_REQUEST['From'];
if (sizeof($parsed) > 3) {
    $nameout = $parsed[3];
} else {
    $nameout = 'NA';
}
$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "INSERT INTO RawSMSData(`msg_contents`,`phone_number`) \n\tVALUES('{$smsstring}','{$numberstring}');";
$conn->query($sql);
$last_id = $conn->insert_id;
$sql = "INSERT INTO Report(`sms_id`,`disability_prose`,`location_prose`,`problem_prose`,`lat`,`long`,`location_is_precise`,`time_sent`,`requires_editing`,`is_solved`,`time_updated`,`name`) \n\tVALUES({$last_id},'{$parsed['1']}','{$parsed['0']}','{$parsed['2']}',{$loc['lat']},{$loc['lng']},0,NOW(),{$checkflag},0,NOW(),'{$nameout}');";
$conn->query($sql);
$conn->close();