function populate_new($email, $postcode, $alert_area_size) { //Set email, postcode and size $this->email = $email; $this->postcode = $postcode; $this->alert_area_size = $alert_area_size; //cleanup postcode $this->postcode = str_replace(" ", "", $this->postcode); $this->postcode = strtolower($this->postcode); //Get xy of the postcode $xy = postcode_to_location($postcode); //if we couldent find the XY, throw an exception if ($xy == false) { //throw new exception("Something bad happened when trying to convert postcode to X 'n Y"); } //Get actual size of zone $area_size_meters = alert_size_to_meters($this->alert_area_size); //Work out bounding box + buffer area (assumes OSGB location == meters) $area_buffered_meters = $area_size_meters + $area_size_meters / 100 * ZONE_BUFFER_PERCENTAGE; $this->bottom_left_x = $xy[0] - $area_buffered_meters / 2; $this->bottom_left_y = $xy[1] - $area_buffered_meters / 2; $this->top_right_x = $xy[0] + $area_buffered_meters / 2; $this->top_right_y = $xy[1] + $area_buffered_meters / 2; //Make a confirmation ID for them (no unique check, ho hum) $this->confirm_id = substr(md5(rand(5, 15) . time()), 0, 20); $this->confirmed = false; //Set last sent date to yesterday $this->last_sent = mysql_date(time() - 24 * 60 * 60); }
function parse_applications($feed_url, $authority_id) { $return_applications = array(); //reset warnings //Grab the XML $xml = ""; try { $xml = safe_scrape_page($feed_url); } catch (exception $e) { array_push($this->log, "ERROR: problem occured when grabbing feed: " . $feed_url . " ---->>>" . $e); } if ($xml == false) { $this->store_log("ERROR: empty feed feed: " . $feed_url); } //Turn the xml into an object $parsed_applications = simplexml_load_string($xml); //Loop through the applications, add tinyurl / google maps etc and add to array if (sizeof($parsed_applications) > 0) { foreach ($parsed_applications->applications->application as $parsed_application) { $application = new application(); //Grab basic data from the xml $application->authority_id = $authority_id; $application->council_reference = $parsed_application->council_reference; $date_received_dmy = split("/", $parsed_application->date_received); if (count($date_received_dmy) == 3) { $application->date_received = "{$date_received_dmy['2']}-{$date_received_dmy['1']}-{$date_received_dmy['0']}"; } else { // Make a best effort attempt to parse the date $ts = strtotime($parsed_application->date_received); if ($ts != FALSE && $ts != -1) { $application->date_received = date("Y-m-d", $ts); } } $application->address = $parsed_application->address; $application->description = $parsed_application->description; $application->info_url = $parsed_application->info_url; $application->comment_url = $parsed_application->comment_url; $application->date_scraped = mysql_date(time()); //Make the urls $info_tiny_url = tiny_url($application->info_url); if ($info_tiny_url == "") { $this->store_log("ERROR: Created blank info tiny url"); } $comment_tiny_url = tiny_url($application->comment_url); if ($comment_tiny_url == "") { $this->store_log("ERROR: Created blank comment tiny url"); } if (isset($parsed_application->postcode)) { //Workout the XY location from postcode $xy = postcode_to_location($parsed_application->postcode); $application->postcode = $parsed_application->postcode; $application->x = $xy[0]; $application->y = $xy[1]; } else { if (isset($parsed_application->easting) && isset($parsed_application->northing)) { $postcode = location_to_postcode($parsed_application->easting, $parsed_application->northing); $application->postcode = $postcode; $application->x = $parsed_application->easting; $application->y = $parsed_application->northing; } } $application->info_tinyurl = $info_tiny_url; $application->comment_tinyurl = $comment_tiny_url; $application->map_url = googlemap_url_from_postcode($application->postcode); //Add to array array_push($return_applications, $application); } } return $return_applications; }
function setup_old() { //Grab the postcode and area size from the get string if (!isset($_GET['area_size'])) { //check is_numeric and isn't too big array_push($this->warnings, "No area size specified"); } if (sizeof($this->warnings) == 0) { //Get OS ref from postcode if (isset($_GET['postcode'])) { $xy = postcode_to_location($_GET['postcode']); $this->easting = $xy[0]; $this->northing = $xy[1]; } else { $latlng = new LatLng($_GET['lat'], $_GET['lng']); $xy = $latlng->toOSRef(); $this->easting = $xy->easting; $this->northing = $xy->northing; } $this->area_size = $_GET['area_size']; $this->applications = Applications::query($this->easting, $this->northing, alert_size_to_meters($this->area_size)); } }