diff --git a/scripts/overview.php b/scripts/overview.php index c213a22..c2f62bd 100644 --- a/scripts/overview.php +++ b/scripts/overview.php @@ -84,6 +84,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse } $iterations = 0; $lines; + $licenses_urls = array(); // 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']); @@ -122,6 +123,19 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse if($key !== false) { $image = $_SESSION['images'][$key]; } else { + // Get license information if we haven't already + if (empty($licenses_urls)) { + $licenses_url = "https://api.flickr.com/services/rest/?method=flickr.photos.licenses.getInfo&api_key=".$config["FLICKR_API_KEY"]."&format=json&nojsoncallback=1"; + $licenses_response = file_get_contents($licenses_url); + $licenses_data = json_decode($licenses_response, true)["licenses"]["license"]; + foreach ($licenses_data as $license) { + $license_id = $license["id"]; + $license_name = $license["name"]; + $license_url = $license["url"]; + $licenses_urls[$license_id] = $license_url; + } + } + // only open the file once per script execution if(!isset($lines)) { $lines = file($home."/BirdNET-Pi/model/labels_flickr.txt"); @@ -149,10 +163,15 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse } } + $license_url = "https://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=".$config["FLICKR_API_KEY"]."&photo_id=".$photo["id"]."&format=json&nojsoncallback=1"; + $license_response = file_get_contents($license_url); + $license_info = json_decode($license_response, true)["photo"]["license"]; + $license_url = $licenses_urls[$license_info]; + $modaltext = "https://flickr.com/photos/".$photo["owner"]."/".$photo["id"]; $authorlink = "https://flickr.com/people/".$photo["owner"]; $imageurl = 'https://farm' .$photo["farm"]. '.static.flickr.com/' .$photo["server"]. '/' .$photo["id"]. '_' .$photo["secret"]. '.jpg'; - array_push($_SESSION['images'], array($comname,$imageurl,$photo["title"], $modaltext, $authorlink)); + array_push($_SESSION['images'], array($comname,$imageurl,$photo["title"], $modaltext, $authorlink, $license_url)); $image = $_SESSION['images'][count($_SESSION['images'])-1]; } } @@ -182,7 +201,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse
0) { ?> - +
@@ -323,9 +342,9 @@ body::-webkit-scrollbar { } - function setModalText(iter, title, text, authorlink, photolink) { + function setModalText(iter, title, text, authorlink, photolink, licenseurl) { document.getElementById('modalHeading').innerHTML = "Photo: \""+decodeURIComponent(title.replaceAll("+"," "))+"\" Attribution"; - document.getElementById('modalText').innerHTML = "

Image link: "+text+"
Author link: "+authorlink+"
"; + document.getElementById('modalText').innerHTML = "

Image link: "+text+"
Author link: "+authorlink+"
License URL: "+licenseurl+"
"; last_photo_link = text; showDialog(); } diff --git a/scripts/todays_detections.php b/scripts/todays_detections.php index 4a86499..2a91ba2 100644 --- a/scripts/todays_detections.php +++ b/scripts/todays_detections.php @@ -213,6 +213,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) { } $iterations = 0; $lines; + $licenses_urls = array(); if (file_exists('./scripts/thisrun.txt')) { $config = parse_ini_file('./scripts/thisrun.txt'); @@ -221,7 +222,6 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) { } - while($todaytable=$result0->fetchArray(SQLITE3_ASSOC)) { $iterations++; @@ -253,6 +253,19 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) { if($key !== false) { $image = $_SESSION['images'][$key]; } else { + // Get license information if we haven't already + if (empty($licenses_urls)) { + $licenses_url = "https://api.flickr.com/services/rest/?method=flickr.photos.licenses.getInfo&api_key=".$config["FLICKR_API_KEY"]."&format=json&nojsoncallback=1"; + $licenses_response = file_get_contents($licenses_url); + $licenses_data = json_decode($licenses_response, true)["licenses"]["license"]; + foreach ($licenses_data as $license) { + $license_id = $license["id"]; + $license_name = $license["name"]; + $license_url = $license["url"]; + $licenses_urls[$license_id] = $license_url; + } + } + // only open the file once per script execution if(!isset($lines)) { $lines = file($home."/BirdNET-Pi/model/labels_flickr.txt"); @@ -278,10 +291,16 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) { break; } } + + $license_url = "https://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=".$config["FLICKR_API_KEY"]."&photo_id=".$photo["id"]."&format=json&nojsoncallback=1"; + $license_response = file_get_contents($license_url); + $license_info = json_decode($license_response, true)["photo"]["license"]; + $license_url = $licenses_urls[$license_info]; + $modaltext = "https://flickr.com/photos/".$photo["owner"]."/".$photo["id"]; $authorlink = "https://flickr.com/people/".$photo["owner"]; $imageurl = 'https://farm' .$photo["farm"]. '.static.flickr.com/' .$photo["server"]. '/' .$photo["id"]. '_' .$photo["secret"]. '.jpg'; - array_push($_SESSION['images'], array($comname,$imageurl,$photo["title"], $modaltext, $authorlink)); + array_push($_SESSION['images'], array($comname,$imageurl,$photo["title"], $modaltext, $authorlink, $license_url)); $image = $_SESSION['images'][count($_SESSION['images'])-1]; } } @@ -293,7 +312,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
0) { ?> - +
@@ -308,7 +327,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
0) { ?> - +
@@ -420,12 +439,12 @@ die(); } - function setModalText(iter, title, text, authorlink, photolink) { + function setModalText(iter, title, text, authorlink, photolink, licenseurl) { document.getElementById('modalHeading').innerHTML = "Photo: \""+decodeURIComponent(title.replaceAll("+"," "))+"\" Attribution"; - document.getElementById('modalText').innerHTML = "

Image link: "+text+"
Author link: "+authorlink+"
"; + document.getElementById('modalText').innerHTML = "

Image link: "+text+"
Author link: "+authorlink+"
License URL: "+licenseurl+"
"; - document.getElementById('modalText').innerHTML = "

Image link: "+text+"
Author link: "+authorlink+"
"; + document.getElementById('modalText').innerHTML = "

Image link: "+text+"
Author link: "+authorlink+"
License URL: "+licenseurl+"
"; last_photo_link = text; showDialog();