Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- /***********************************************************************************************
- *** N O N C O N F I D E N T I A L --- O R E G O N 9 1 1 ***
- ***********************************************************************************************
- * *
- * Project Name : Computer Aided Dispatch *
- * *
- * $Archive:: ./core/import/JOINTCAD_WA_CLACK.php *
- * *
- * $Author:: Brandan Tyler Lasley *
- * *
- * $Modtime:: 10/28/13 15:35 *
- * *
- * $Revision:: 4 *
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: Gets calls from WCCCA PITSv2 website *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- // Compatibility notice: To upgrade from older code to this newer version heres the things that changed.
- // $HTML = file_get_contents("http://www.wccca.com/PITSv$WCCCA_Version/"); => $HTML = WCCCA_callInfo();
- // $Use_Google_API_To_Get_Geo_Coordinates was removed and a new function $Use_Built_In_Geo_Coordinates
- // was added.
- // Debug code for the geocode system has also been added
- // Additionally the 3 functions (critical) were added getloc(), WCCCA_callInfo(), post().
- // However WCCCA_HIDDEN_CODE() was added, it has no purpose.
- // The function getgeoloc() was completely removed.
- // Setting
- $Use_Built_In_Geo_Coordinates = 0;
- $Use_Twitter = 0;
- $Print_Debug = 1;
- $WCCCA_Version = 2; //unused, hard coded
- $uname = 'washco_firemed'; //twitter login name for washco
- $unamec = 'clackco_firemed'; //twitter login name for clackco
- $pwd = 'PASSWORD'; //twitter password
- $twitter_url = 'http://twitter.com/statuses/update.xml'; //twitter api url
- // Ignore WCCCA PITSv2 HTML Errors (probably should fix)
- error_reporting(E_ERROR | E_PARSE);
- // Download WCCCA PITSv2 full CAD site
- $HTML = WCCCA_callInfo();
- // Extract Call and filter to show only call infomation
- // WCCCA:
- $WCCCA_Calls = (Seperate_Calls($HTML, 0));
- // CCOM:
- $CCOM_Calls = (Seperate_Calls($HTML, 1));
- $Raw_WCCCA_Calls = explode("\n", $WCCCA_Calls);
- $Raw_CCOM_Calls = explode("\n", $CCOM_Calls);
- // Add County infomation for WCCCA
- $converted_wccca_calls;
- foreach ($Raw_WCCCA_Calls as $call) {
- if (!empty($call)) {
- $converted_wccca_calls .= "County: W Call:" . $call . "\n";
- } //!empty($call)
- } //$Raw_WCCCA_Calls as $call
- // Add County infomation for CCOM
- $converted_ccom_calls;
- foreach ($Raw_CCOM_Calls as $call) {
- if (!empty($call)) {
- $converted_ccom_calls .= "County: C Call:" . $call . "\n";
- } //!empty($call)
- } //$Raw_CCOM_Calls as $call
- // Combind CCOM and WCCCA
- $Total_calls = $converted_ccom_calls . $converted_wccca_calls;
- // Split Total calls for looping
- $raw_calls = explode("\n", $Total_calls);
- // Start the call loop
- foreach ($raw_calls as $call) {
- if (!empty($call)) {
- // Get County
- $county = explode(' ', $call);
- $cleancounty = $county[1];
- // Get Station
- $station = explode('Time: ', $call);
- $station1 = explode(' ', $station[1]);
- $cleanstation = $station1[5];
- // Get Agency
- $agency = $station1[4];
- $cleanagency = str_replace("/", "", $agency);
- // Get Call
- $raw_call = explode("Call: ", $call);
- $raw_call2 = explode(" Address:", $raw_call[1]);
- $cleancall = $raw_call2[0];
- // Get Address
- $raw_address = explode("Address: ", $call);
- $raw_address1 = explode(" Time:", $raw_address[1], 2);
- $cleanlocation = preg_replace('/\W\w+\s*(\W*)$/', '$1', $raw_address1[0]);
- // Get GUID
- $raw_guid = str_replace("$cleanlocation", "", $raw_address1[0]);
- $cleanguid = str_replace(' ', '', $raw_guid);
- // Get Units
- $raw_units = explode(" Time:", $call);
- $raw_units1 = explode("/", $raw_units[1]);
- $raw_units2 = explode("- ", $raw_units1[1]);
- $cleanunits = $raw_units2[1];
- if ($Use_Built_In_Geo_Coordinates == 1) {
- $geoaddr = getloc($cleanguid, $HTML);
- $llatt = $geoaddr[0];
- $llonn = $geoaddr[1];
- } //$Use_Built_In_Geo_Coordinates == 1
- if (!empty($cleancounty)) {
- if ($Print_Debug == 1) {
- $geoaddr = getloc($cleanguid, $HTML);
- print("County: $cleancounty Call: $cleancall Address: $cleanlocation Units: $cleanunits Agency: $cleanagency Station: $cleanstation GUID $cleanguid\n");
- print($geoaddr[0] . ", " . $geoaddr[1] . "\n");
- } //$Print_Debug == 1
- if ($Use_Twitter == 1) {
- //build a google maps url with an info bubble
- $map = 'http://maps.google.com/maps?z=12&q=' . $llatt . "+" . $llonn . "+(" . $cleancall . "," . $cleanlocation . ", Units: " . $cleanunits . ")";
- //change the google map url to a tiny url (actually is.gd ur because it's smallerl) and change the spaces in the $map url to %20 so there is no bad http requests
- $mapfixed = rawurlencode($map);
- $tiny_url = file_get_contents("http://is.gd/api.php?longurl=" . $mapfixed);
- //put the parts together for the twitter status line
- $status = $cleancall . " | " . $cleanlocation . " | Units: " . $cleanunits . " | " . $tiny_url; //assemble status for twitter
- if ($cleancounty == "W") //if washington county, then post to washco_firemed
- {
- $curl_handle = curl_init();
- curl_setopt($curl_handle, CURLOPT_URL, "$twitter_url");
- curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
- curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl_handle, CURLOPT_POST, 1);
- curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$status");
- curl_setopt($curl_handle, CURLOPT_USERPWD, "$uname:$pwd");
- $buffer = curl_exec($curl_handle);
- curl_close($curl_handle);
- if (empty($buffer)) {
- echo '<br/>Fail-WC';
- } //empty($buffer)
- else {
- echo $status;
- }
- } //$cleancounty == "W"
- elseif ($cleancounty == "C") //if clackamas county, then post to clackco_firemed
- {
- $curl_handle = curl_init();
- curl_setopt($curl_handle, CURLOPT_URL, "$twitter_url");
- curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
- curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl_handle, CURLOPT_POST, 1);
- curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$status");
- curl_setopt($curl_handle, CURLOPT_USERPWD, "$unamec:$pwd");
- $buffer = curl_exec($curl_handle);
- curl_close($curl_handle);
- if (empty($buffer)) {
- echo '<br/>Fail-CC';
- } //empty($buffer)
- else {
- echo $status;
- }
- } //$cleancounty == "C"
- } //$Use_Twitter == 1
- } //!empty($cleancounty)
- } //!empty($call)
- } //$raw_calls as $call
- exit;
- function Seperate_Calls($HTML, $County)
- {
- $dom = new DOMDocument();
- $dom->loadHTML($HTML);
- $xpath = new DOMXPath($dom);
- // Switch between WCCCA/CCOM
- if ($County == 0) {
- $tags = $xpath->query('//div[@id="wccca-incidents"]');
- } //$County == 0
- else {
- $tags = $xpath->query('//div[@id="ccom-incidents"]');
- }
- // For each call delete all the massive amount of blank spaces and new lines.
- foreach ($tags as $tag) {
- $calls = preg_replace('/\s+/', ' ', $tag->textContent);
- } //$tags as $tag
- // Seperate the calls (since we removed all the \n's)
- $Filtered_Calls = explode("Call Type:", $calls);
- // Loop though seperated calls and recombind them into a list, then add a new line to them for easier processing.
- foreach ($Filtered_Calls as $call) {
- $Call_dump .= $call . "\n";
- } //$Filtered_Calls as $call
- // Remove any unintentional blank spaces that may occur from this.
- $Call_dump = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "", $Call_dump);
- // Return the calls.
- return ($Call_dump);
- }
- function getloc($callnum, $HTML)
- {
- // Delete useless code to narrow down to the exact code we want to format.
- $Del = strstr(strstr($HTML, 'LoadMarker('), 'updateMarkers()', true);
- $format01 = str_replace("parseFloat(", "", $Del);
- $format02 = str_replace(";resizeIncidentScrollBar('#wccca-incidents')", "", $format01);
- $format03 = str_replace(";resizeIncidentScrollBar('#ccom-incidents')", "", $format02);
- $format04 = str_replace("LoadMarker(", "", $format03);
- $format05 = str_replace("(", "", $format04);
- $format06 = str_replace(")", "", $format05);
- $format07 = str_replace("LoadMarker(", "", trim(preg_replace('/\s\s+/', ' ', $format06)));
- $format08 = str_replace(";", "\n", $format07);
- $calls = explode("\n", $format08);
- foreach ($calls as $call) {
- $callInfo = str_getcsv($call, ',', '\'');
- if ($callnum == str_replace(" ", "", str_replace("'", "", $callInfo[3]))) {
- $lat = $callInfo[0];
- $lon = $callInfo[1];
- break;
- } else {
- $lat = 0;
- $lon = 0;
- }
- }
- return array(
- $lat,
- $lon
- );
- }
- function WCCCA_callInfo()
- {
- $Calls = post("http://www.wccca.com/PITSv2/Default.aspx", "__VIEWSTATE=");
- return $Calls;
- }
- function WCCCA_HIDDEN_CODE($input) // Get hidden code (NOT USED / POSSIBLE FUTURE USE?)
- {
- $data = file_get_contents("http://www.wccca.com/PITSv2/Default.aspx");
- $pattern = "/id=\"__" . $input . "\" value=\"([^\"]+)\"/";
- preg_match_all($pattern, $data, $xmlext);
- // Removes all slashes.
- $code = str_replace("/", "", $xmlext[1][0]);
- return $code;
- }
- function post($url, $data, $optional_headers = null)
- {
- $params = array(
- 'http' => array(
- 'method' => 'POST',
- 'content' => trim(preg_replace('/\s\s+/', ' ', $data))
- )
- );
- if ($optional_headers !== null) {
- $params['http']['header'] = $optional_headers;
- }
- $ctx = stream_context_create($params);
- $fp = @fopen($url, 'rb', false, $ctx);
- if (!$fp) {
- throw new Exception("Problem with $url, $php_errormsg");
- }
- $response = @stream_get_contents($fp);
- if ($response === false) {
- throw new Exception("Problem reading data from $url, $php_errormsg");
- }
- return $response;
- }
- ?>
Add Comment
Please, Sign In to add comment