Jump to content

Texan78

Members
  • Content Count

    272
  • Joined

  • Last visited

Everything posted by Texan78

  1. When the script inc/alertsUS.php script is updated by the AJAX script there is an icon on the divs which in this case is a link to open a modal for more information. When the page is first loaded the links work fine and open the modals and the modals are populated with the correct information. BUT if there is new data that means a new div is generated in which case that link is not clickable. If I refresh the page then I can click the link. After doing research I discovered this is because the click event needs to be binded. So that is what I am trying to accomplish is so that when new data is populated with a new link that link is clickable without having to refresh the page manually.
  2. The content of #svrAlertsUS isn't what is getting injected into the modal. That just displays the page from inc/alertsUS.php in DIVs where I want the data outputted. That ID is the AJAX ID to that script if that makes sense and I am explaining it correctly. I have tried this but it's not working ether function auto_load(){ //National Warning & Watches Settings $.ajax({ url: "inc/alertsUS.php", cache: false, success: function(data){ $("#svrAlertsUS").html(data); } }); } $(document).ready(function(){ $('#svrAlertsTX').on('click', 'a', function () { $('.alert-modal').html(data); }); auto_load(); //Call auto_load() function when DOM is Ready }); //Refresh auto_load() function after 10000 milliseconds setInterval(auto_load,55000); How would I use that "var id = e.target.id" option?
  3. Yeah that makes sense and something I had thought about if I needed to go higher up. I had tried that but I didn't go outside the script being called by the AJAX. I just wrapped the entire modal in a new ID etc. So as you can see from my first post the AJAX calls an ID svrAlertsUS. On the page which the divs with the data being displayed it is in a container like so... <div id="alertsUS-expanded" class="collapse"> <div id="svrAlertsUS"></div> </div> So since the ID svrAlertsUS is the container would this work? $('#alertsUS-expanded').on('click', 'a', function () { $('.alert-modal').html(data); }); Should this be in the script with the AJAX calls or somewhere else? The reason I am not using the actual event names with "var id = this.id;" is because I don't know the ID as they are dynamic and generated from a JSON file from an API. So when I parse the JSON I have to insert the PHP variable for the ID to use so the modals and links are unique. Would that suggestion still work even though the ID's are generated dynamically? -Thanks
  4. I have some some divs which are dynamically created from a PHP script and displayed to a page via AJAX so the data in the divs are updated/refreshed when new data is present in a JSON file. These divs have a link on it to open a modal. When the page first loads the links work great. When the script updates the PHP file and there is new data to display on the page the links for the new data do not work. Therefore I have found out I need to bind the event via .on(click). Here is my problem I am running into since they are not static IDs to bind to. The IDs are dynamically produced based on the ID from a JSON file that is created from a 3rd party API. Here is a snippet of the code that creates the link. $AlertData .= "<div class='alert__view' id='eventID'>\n"; $AlertData .= "<a href='#{$eventID}' data-toggle='modal' data-backdrop='false' data-target='#{$eventID}'><i class='fa fa-info-circle'></i></a>\n"; $AlertData .= "</div>\n"; $eventID is the ID for the link as shown in the code above and is also the ID for the modal which it is linked to in order to open dynamic and unique modals for the associated data. So what I have tried to do is this since it doesn't have to be binded to the exact ID I can bind it to the parent ID or class. In this case alert__view for the link as you see above and for the modal using the class .alert-modal instead of the ID since it is dynamic is uses $eventID like the link does. $('.alert__view').on('click', 'a', function () { $('.alert-modal').html(data); }); So I have included this snippet in my AJAX file for updating/refreshing the PHP script like as follows. function auto_load(){ //National Warning & Watches Settings $.ajax({ url: "inc/alertsUS.php", cache: false, success: function(data){ $("#svrAlertsUS").html(data); } }); } $(document).ready(function(){ $('.alert__view').on('click', 'a', function () { $('.alert-modal').html(data); }); auto_load(); //Call auto_load() function when DOM is Ready }); //Refresh auto_load() function after 10000 milliseconds setInterval(auto_load,55000); Unfortunately this is not working. Am I including the binding wrong? Should I put it in the PHP script or should it be merged into the AJAX call somehow? Or do I have this just completely wrong. -Thanks down votefavorite
  5. Manual shows nothing about the missing echo statement which is what it was. Also the data I was trying to get a response wasn't available in cap+xml only in atom+xml and JSON. So I will be re-writing the scripts to use JSON which is better now that JSON is available now.
  6. Forgive me if this is simple. My research has brought me to a halt at the moment. I am trying to use cURL to get the response of an API in XML. This is the URL of the API: https://api.weather.gov/alerts/active/region/land By default it returns in JSON. Which I know, I should just use the JSON response but, there is a reason I need it in XML as it will seamlessly integrate into my current code until I can rewrite it for JSON. This is the documentation for the API. Under the API Reference tab is states I just need to change the request header to application/cap+xml. But I am not getting anything back. Just a blank white page. https://alerts-v2.weather.gov/documentation Here is my current code I am using to call the API but I get no response or anything. What am I missing? <?php $headers[] = 'Connection: Keep-Alive'; $headers[] = 'Content-Type: application/cap+xml;charset=utf-8'; $headers[] = 'Accept: application/cap+xml'; $userAgent = 'php'; $url = 'https://api.weather.gov/alerts/active/region/land'; $cURL = curl_init(); curl_setopt($cURL, CURLOPT_URL, $url); curl_setopt($cURL, CURLOPT_HTTPHEADER, $headers); curl_setopt($cURL, CURLOPT_USERAGENT, $userAgent); curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true); curl_setopt($cURL, CURLOPT_HTTPGET, true); $result = curl_exec($cURL); curl_close($cURL); ?>
  7. Hello, It's been awhile since I have had to do this and I can't find any of my old code snippets. So having to go from memory. Just trying to start small and add to this. NWS is now has a JSON API where before they had XML/RSS. So I am trying to update or really create new scripts to use this new API before they take down the old method and my site is broke. I have not see this kind of JSON format before so I am a little lost. How would I go about pulling the Event, Sender and Description from the below example? { "@context": [ "https://raw.githubusercontent.com/geojson/geojson-ld/master/contexts/geojson-base.jsonld", { "wx": "https://api.weather.gov/ontology#", "@vocab": "https://api.weather.gov/ontology#" } ], "type": "FeatureCollection", "features": [ { "id": "https://api.weather.gov/alerts/NWS-IDP-PROD-2466813-2306361", "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [ [ [ -104.05, 38.88 ], [ -104.06, 38.86 ], [ -104.6, 38.71 ], [ -104.9, 38.87 ], [ -104.83, 38.98 ], [ -104.39, 39.03 ], [ -104.05, 38.88 ] ] ] }, "properties": { "@id": "https://api.weather.gov/alerts/NWS-IDP-PROD-2466813-2306361", "@type": "wx:Alert", "id": "NWS-IDP-PROD-2466813-2306361", "areaDesc": "El Paso", "geocode": { "UGC": [ "COC041" ], "SAME": [ "008041" ] }, "references": [ "https://api.weather.gov/alerts/NWS-IDP-PROD-2466797-2306350" ], "sent": "2017-07-26T21:22:38+00:00", "effective": "2017-07-26T21:22:38+00:00", "onset": "2017-07-26T21:22:00+00:00", "expires": "2017-07-26T22:00:00+00:00", "ends": "2017-07-26T22:00:00+00:00", "status": "Actual", "messageType": "Update", "category": "Met", "severity": "Severe", "certainty": "Observed", "urgency": "Immediate", "event": "Severe Thunderstorm Warning", "sender": "NWS Pueblo CO", "headline": "Severe Thunderstorm Warning issued July 26 at 3:22PM MDT expiring July 26 at 4:00PM MDT by NWS Pueblo CO", "description": "At 322 PM MDT, a severe thunderstorm was located over northern\nColorado Springs, moving east at 10 mph.\n\nHAZARD...60 mph wind gusts and quarter size hail.\n\nSOURCE...Radar indicated.\n\nIMPACT...Hail damage to vehicles is expected. Expect wind damage to\nroofs, siding, and trees.\n\nVery heavy rain is also occurring with this storm.\n\nLocations impacted include...\nColorado Springs, Air Force Academy, Yoder, Ellicott, Schriever AFB,\nPeterson AFB, Falcon, Cimarron Hills and Security-Widefield.", "instruction": "For your protection move to an interior room on the lowest floor of a\nbuilding.", "response": "Shelter", "parameters": { "eventMotionDescription": [ "2017-07-26T21:22:00.000-06:00...storm...278DEG...11KT...38.94,-104.75" ], "hailSize": [ "1.00" ], "windGust": [ 60 ], "NWSheadline": [ "A SEVERE THUNDERSTORM WARNING REMAINS IN EFFECT UNTIL 400 PM MDT FOR CENTRAL EL PASO COUNTY" ], "VTEC": [ "/O.CON.KPUB.SV.W.0172.000000T0000Z-170726T2200Z/" ], "EAS-ORG": [ "WXR" ], "PIL": [ "PUBSVSPUB" ], "BLOCKCHANNEL": [ "CMAS", "EAS", "NWEM" ], "eventEndingTime": [ "2017-07-26T22:00:00Z" ] } } }, I have tried this just trying to pull the sender data but no luck... <?php $headers[] = 'Connection: Keep-Alive'; $headers[] = 'Content-Type: application/json;charset=utf-8'; $headers[] = 'Accept: application/json'; $userAgent = 'php'; $url = 'https://api.weather.gov/alerts/active?region_type=land'; $cURL = curl_init(); curl_setopt($cURL, CURLOPT_URL, $url); curl_setopt($cURL, CURLOPT_HTTPHEADER, $headers); curl_setopt($cURL, CURLOPT_USERAGENT, $userAgent); curl_setopt($cURL, CURLOPT_RETURNTRANSFER, true); curl_setopt($cURL, CURLOPT_HTTPGET, true); $result = curl_exec($cURL); curl_close($cURL); /* Lets get and parse the data and create the variables */ $obj = json_decode($result); $issued_by = $obj->sender; ?>
  8. Thanks, I am not worried about the other right now. Each their own. Main focus is getting these sorted by priority and I have no idea how to do this and cannot find any examples. I have even been willing to PAY someone to do this since last November for what is probably less than 5 mins of work but can't find anyone. Is what I am asking that difficult? I didn't think it was that difficult, I see sites doing it all the time everyday. I have already tried the array approach and got shot down on here with it and could never get it working.
  9. Hello, I have been struggling with this for months and please be gentle as I am not a coder. Just a hobbyist trying to build a site for my brand. I know just enough to try to do what I need to do so I certainly do not know the best logic. I have been search for months and months for how to do this. I have three events I need to show in a certain order when they display. 1.) Tornado Warning 2.) Severe Thunderstorm Warning 3.) Flash Flood Warning I have them filtered but I am probably not using the best logic for this approach. Is there anyone who could offer some assistance and help me out with ordering these by severity as I have posted above so I can mark this little section as completed. -Thanks hugely!!! ini_set('display_errors','1'); ## Start Configurable data ## //Set message to display if there were not report $noStormMessage = 'There are currently no active severe weather alerts'; //Set path to data file #$data = "http://alerts.weather.gov/cap/".$zone.".php?x=0"; $data = "../xml/nat_warnings.xml"; ## End Configurable data ## // get path info & protect for cross-site scripting vulnerability $sri = ($_SERVER['REQUEST_URI']) ? str_replace('#SA', '', htmlspecialchars(strip_tags($_SERVER['REQUEST_URI']))) : ''; $error = false; //Set initial output to false $AlertData = false; $entries = simplexml_load_file($data); if(count($entries)): //Registering NameSpace $entries->registerXPathNamespace('prefix', 'http://www.w3.org/2005/Atom'); $result = $entries->xpath("//prefix:entry"); if(!$result){ $error = true; } foreach ($result as $entry): $updated = $entry->updated; if($updated == ''){ $error = true; } $Updated = date("D, M d, g:i a", strtotime($updated)); $summary = $entry->summary; if($summary == ''){ $error = true; } // Replaces all triple periods with single periods $summary = trim(str_replace('...', '.', $summary), '.') . '.'; //now capitalize every letter after a . ? and ! followed by space $Summary = preg_replace_callback('/([.!?*])\s*(\w)/', function ($matches) { return strtoupper($matches[1] . ' ' . $matches[2]); }, ucfirst(strtolower($summary))); $event = $entry->children("cap", true)->event; if ($event == ''){ $error = true; } $url = $entry->id; $updated = $entry->updated; $link = $entry->link; $effective = $entry->children("cap", true)->effective; $expires = $entry->children("cap", true)->expires; $updated = date("l M jS, g:i A", strtotime($updated)); $effectiveDate = date("l M jS, g:i A", strtotime($effective)); $expiresDate = date("D M jS, g:i A", strtotime($expires)); $status = $entry->children("cap", true)->status; $severity = $entry->children("cap", true)->severity; $urgency = $entry->children("cap", true)->urgency; $area = $entry->children("cap", true)->areaDesc; include ('alertColors.php'); // Let's assign the table some styles $divNoStorms = "padding:5px; width:45%; margin:auto; margin-top:5px; margin-bottom:5px"; // If no storms were in the source, set no storm message if($error) { $AlertData .= "<div style='{$divNoStorms}' class='alert alert-info' role='alert' data-toggle='tooltip' data-placement='top' title='There are currently no active severe weather alerts.'>\n"; $AlertData .= "{$noStormMessage}\n"; $AlertData .= "</div>\n"; } elseif ($event == 'Tornado Warning' || $event == 'Severe Thunderstorm Warning' || $event == 'Flash Flood Warning') { $AlertData .= "<div>\n"; $AlertData .= "<div id='{$alertID}' class='individualAlert'>\n"; $AlertData .= "<div class='text_alert'>\n"; $AlertData .= "<span class='title {$alertClass}'><i class='fa fa-exclamation-triangle severe-icon__tornado'></i>{$event}</span>\n"; $AlertData .= "<span class='state'>{$stateShort}</span>\n"; $AlertData .= "<span class='counties'>{$area}</span>\n"; $AlertData .= "<span class='expires'>Expires: {$expiresDate}</span>\n"; $AlertData .= "</div>\n"; $AlertData .= "<div class='alert__view'>\n"; $AlertData .= "<a href='{$url}'><span class='fa fa-eye'></span></a>\n"; $AlertData .= "</div>\n"; $AlertData .= "</div>\n"; } $AlertData .= "</div>\n"; endforeach; endif; echo $AlertData;
  10. Ok let me try to explain what I am trying to do. The arrary you see is all the active alerts and how many of that alert is currently active. from the "../xml/nat_warnings.xml" There is a possibility of over 116+ events. This is why I created the arrary to only check the ones I want. In this case I just need to total number of alerts for "'Tornado Warning', 'Severe Thunderstorm Warning', 'Flash Flood Warning'" with the ability to add more as needed depending on the season. With the orginal code that filters what I want and gives me to total number of each alert. So what I am needing now is to take all those numbers and add them together in to one single value which I can call with a single variable. Reason for this is I am making a badge kind of like what you see on iPhones that gives the total number of alerts. So it will take all the alerts I want and add them all together into one single value. This is where I am stuck is just creating a single variable that will give me the total number of the select alerts I want. -Thanks
  11. Hello, When I try what you suggested which is this. ini_set('display_errors','1'); ## Start Configurable data ## ##$data3 = "../xml/nat_warnings.xml"; ## End Configurable data ## $sri = htmlspecialchars('Tornado Warning', 'Severe Thunderstorm Warning', 'Flash Flood Warning', ENT_QUOTES); $xml = new SimpleXMLElement("../xml/nat_warnings.xml", 0, true); $xml->registerXPathNamespace("cap", "urn:oasis:names:tc:emergency:cap:1.1"); $count = count($xml->query("/feed/entry[cap:event = '{$sri}']")); print_r($count); Then I get this error. I much prefer SimpleXML but, there is a reason I am using DOM for this as there is something else I will be doing with this later once I get this sorted out.
  12. Hello, I am bit stuck and could use some assistance. I am know I need to probably use an array to filter out only the results I need but, the solutions I have tried have not been successful. What I am trying to do is get the total number of certain events within an XML file. I have got it to where it prints out all the events within the XML file but, this is where I am stuck. How to filter out only certain events that I want the value of then get a single total combined number of those chosen events. Here is the test link of what the output looks like now. http://stream.dfwstormforce.com/inc/alertsCount.php ini_set('display_errors','1'); ## Start Configurable data ## $data3 = "../xml/nat_warnings.xml"; ## End Configurable data ## // get path info & protect for cross-site scripting vulnerability $sri = ($_SERVER['REQUEST_URI']) ? str_replace('#SA', '', htmlspecialchars(strip_tags($_SERVER['REQUEST_URI']))) : ''; // Lets parse the feed $dom = new DOMDocument(); $dom->load($data3); $events = []; foreach ($dom->getElementsByTagNameNS("urn:oasis:names:tc:emergency:cap:1.1", "event") as $event) { $events[] = $event->nodeValue; } //$message = $event->nodeValue; //$alertValues = array('Tornado Warning', 'Severe Thunderstorm Warning', 'Flash Flood Warning', 'Winter Storm Warning', 'Winter Storm Watch', 'Winter Weather Advisory'); $counts = array_count_values($events);//lets count the results //$value = isset($counts['Tornado Warning', 'Severe Thunderstorm Warning', 'Flash Flood Warning', 'Winter Storm Warning', 'Winter Storm Watch', 'Winter Weather Advisory')]); print_r($counts); -Thanks
  13. Always looking for something more significant and it was the easiest thing. -Thanks
  14. Hello, I am looking for some assistance with something I done before but forgot and I can't find my code snippets from when I used this method in the past. If you reference the screenshot below you will see boxes going across. What I am trying to do is put each one on its own row but can't remember how it is done. I have tried putting a <tr> in the loop but that doesn't work which I have commented out below where I had it for example purposes. Could anyone offer some help with this? BTW I am using this with bootstrap and calling it into the HTML template with jQuery so it refreshes on its own with updated information. -Thanks // If no storms were in the source, set no storm message if($error) { $AlertData .= "<div style='{$divNoStorms}' class='alert alert-info' role='alert' data-toggle='tooltip' data-placement='top' title='There are currently no active severe weather alerts.'>\n"; $AlertData .= "{$noStormMessage}\n"; $AlertData .= "</div>\n"; } elseif ($event == 'Tornado Warning' || $event == 'Severe Thunderstorm Warning' || $event == 'Flash Flood Warning') { //$AlertData .= "<tr>\n"; $AlertData .= "<div class='col-md-3'>\n"; $AlertData .= "<div id='{$alertID}' class='individualAlert'>\n"; $AlertData .= "<div class='text_alert'>\n"; $AlertData .= "<span class='title {$alertClass}'><i class='fa fa-exclamation-triangle severe-icon__tornado'></i>{$event}</span>\n"; $AlertData .= "<span class='state'>{$stateShort}</span>\n"; $AlertData .= "<span class='counties'>{$area}</span>\n"; $AlertData .= "<span class='expires'>Expires: {$expiresDate}</span>\n"; $AlertData .= "</div>\n"; $AlertData .= "<div class='alert__view'>\n"; $AlertData .= "<span class='fa fa-eye'></span>\n"; $AlertData .= "</div>\n"; $AlertData .= "</div>\n"; } $AlertData .= "</div>\n"; //$AlertData .= "</tr>\n"; endforeach; endif; echo $AlertData;
  15. They are EXACTLY the same line numbers. I copy and pasted them into a notepad to save for later then commented out the DB connection to stop it from making connections. This.... /* Lets connect to the database */ //include('dbconn.php'); Has zero to do with the error as I still get the SAME error regardless if it is commented out or not. So ignore it even exists. Had I not posted that part at all then I am sure I would be getting completely different responses. No worries, thanks for the help. Its apparent no one is looking BEYOND what I am saying and only focusing on that being commented out instead of listening to what I am saying that it doesn't matter. I get the same error regardless even with waiting a couple hours which is plenty of time for the varnish cache to clear.
  16. So I guess I just fantasized that someone gained root access via shell. So I guess it is completely valid to comment out the entire query which renders the entire script useless. So I guess that if I uncomment the DB connection it will work perfectly fine with no errors correct? That is what you're saying right? Guess what, it is uncommented, the errors have returned. So now what all mighty know it all? What does your magic 8 ball have to say about that? Cool story bro? Yeah stick it keyboard warrior.
  17. Genius!!! Even better I should just remove the entire query! That should do the trick!
  18. Again, the errors were happening BEFORE I commented out the code. I commented it out because it was throwing errors in the logs BEFORE commenting it out. It was also causing performance and resource issues on my host which was causing the page not to load. I commented it out in the script AND on the page it was being included on until I could resolve the issue. Once I did both those things the page loaded AND the errors went away.
  19. Yes, it is commented out because it was causing serious issues with the page loading so I commented it out until I could get this sorted.
  20. I have a serious issue. I am not sure if I have been hacked or what but my site is completely messed up. I have a ton of these errors in the error log and I am not sure what is causing this. I don't recall this being part of the script Which is referring to this line. //lets execute the query $executingFetchQuery = $mysqli->query("SELECT `StreamStatus` FROM streamdb WHERE 1"); if($executingFetchQuery) { while($arr = $executingFetchQuery->fetch_assoc()) { $resultArr[] = $arr['StreamStatus'];//storing values into an array } } This is the full code. /* Lets connect to the database */ //include('dbconn.php'); $resultArr = array();//to store results //lets execute the query $executingFetchQuery = $mysqli->query("SELECT `StreamStatus` FROM streamdb WHERE 1"); if($executingFetchQuery) { while($arr = $executingFetchQuery->fetch_assoc()) { $resultArr[] = $arr['StreamStatus'];//storing values into an array } } $counts = array_count_values($resultArr);//lets count the results $online = $counts['true']; // Let's assign the table some styles $divStyle = "padding:5px; margin:auto; margin-bottom:20px"; // Lets assemble the banners to display $notifyOffline = "<div class='alert alert-danger' style='{$divStyle}' role='alert' data-toggle='tooltip' data-placement='top' title='There are currently no chasers streaming at this time.'> There are currently no chasers streaming at this time.</div>"; $notify1Online = "<div class='alert alert-success' style='{$divStyle}' role='alert' data-toggle='tooltip' data-placement='top' title='There is currently 1 chaser streaming LIVE...'> There is currently 1 chaser streaming LIVE... </div>"; $notifyOnline = "<div class='alert alert-success' style='{$divStyle}' role='alert' data-toggle='tooltip' data-placement='top' title='There are currently ".$online." chasers streaming LIVE...'> There are currently ".$online." chasers streaming LIVE... </div>"; //lets display the banners if ( $online == "1" ) { echo $notify1Online; } elseif ( $online >= "2" ) { echo $notifyOnline; } else { echo $notifyOffline; } Any and ALL help would be greatly welcomed. -THANKS!
  21. Still looking for a solution to this that implements into my current script that will filter certain values and then sort them.
  22. Still no solution to what I think is a very simple question.
  23. Should I guess how to implement those snippets or you going to show me an example of how to implement it into my current code since you're not making any sense or listening to anything I am saying. I also can't ditch the IF statement because it is doing two different things as it is suppose to. Have you ever heard of the KISS method?
  24. This is doing just that. What is set in the array is style classes and IDs. From what I can tell that is assigning it to the same variable $type. This is the alert or event ['Tornado Warning'] and these are styles array('Tornado', 'AlertTornado'); $type = array(); $type['Tornado Warning'] = array('Tornado', 'AlertTornado'); $type['Severe Thunderstorm Warning'] = array('SevereThunderstorm','AlertSevereThunderstorm'); $type['Flash Flood Warning'] = array('FlashFlood','AlertFlood'); $type['Flood Warning'] = array('FlashFlood','AlertFlood'); How else am I going to pass the values to it to filter out what I want? It's not just going to know if you don't pass something to it to filter through. Like I said, those snippets would probably be useful it you included examples of how to implement it into my current code.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.