prepare('SELECT Com_Name, Sci_Name, Date, Time, Confidence, File_Name FROM detections ORDER BY Date DESC, Time DESC LIMIT 5'); if($statement4 == False) { echo "Database is busy"; header("refresh: 0;"); } $result4 = $statement4->execute(); $images = []; $iterations = 0; // hopefully one of the 5 most recent detections has an image that is valid, we'll use that one as the most recent detection until the newer ones get their images created while($mostrecent = $result4->fetchArray(SQLITE3_ASSOC)) { $comname = preg_replace('/ /', '_', $mostrecent['Com_Name']); $sciname = preg_replace('/ /', '_', $mostrecent['Sci_Name']); $comname = preg_replace('/\'/', '', $comname); $filename = "/By_Date/".$mostrecent['Date']."/".$comname."/".$mostrecent['File_Name']; // check to make sure the image actually exists, sometimes it takes a minute to be created if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { $protocol = 'https://'; } else { $protocol = 'http://'; } $headers = @get_headers($protocol.$_SERVER['HTTP_HOST'].$filename.".png"); // we've found our valid detection! ignore everything else from the database loop if(strpos($headers[0],'200')) { if($_GET['previous_detection_identifier'] == $filename) { die(); } if (!empty($config["FLICKR_API_KEY"])) { // if we already searched flickr for this species before, use the previous image rather than doing an unneccesary api call $key = array_search($comname, array_column($images, 0)); if($key !== false) { $image = $images[$key]; } else { $flickrjson = json_decode(file_get_contents("https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=".$config["FLICKR_API_KEY"]."&text=".$comname."&license=7%2C9%2C10&sort=relevance&per_page=5&orientation=square,portrait&format=json&nojsoncallback=1"), true)["photos"]["photo"][0]; $modaltext = "https://flickr.com/photos/".$flickrjson["owner"]."/".$flickrjson["id"]; $authorlink = "https://flickr.com/people/".$flickrjson["owner"]; $imageurl = 'http://farm' .$flickrjson["farm"]. '.static.flickr.com/' .$flickrjson["server"]. '/' .$flickrjson["id"]. '_' .$flickrjson["secret"]. '.jpg'; array_push($images, array($comname,$imageurl,$flickrjson["title"], $modaltext, $authorlink)); $image = $images[count($images)-1]; } } ?>
| Total | |
|---|---|
| Today | |
| Last Hour | |
| Species Detected Today | |
| Total Number of Species |
No Detections For Today
"; } ?>