switch to neutral image_provider

This commit is contained in:
frederik
2025-08-16 11:56:57 +02:00
committed by Nachtzuster
parent a5154c38ed
commit ec7131391d
2 changed files with 42 additions and 38 deletions
+15 -13
View File
@@ -5,7 +5,6 @@ $_GET = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
ini_set('session.gc_maxlifetime', 7200);
ini_set('user_agent', 'PHP_Flickr/1.0');
session_set_cookie_params(7200);
session_start();
error_reporting(E_ERROR);
@@ -186,7 +185,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
$_SESSION['images'] = [];
}
$iterations = 0;
$flickr = null;
$image_provider = null;
while($todaytable=$result0->fetchArray(SQLITE3_ASSOC))
{
@@ -205,13 +204,16 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
$url = $info_url['URL'];
$url_title = $info_url['TITLE'];
if (!empty($config["FLICKR_API_KEY"]) && (isset($_GET['display_limit']) || isset($_GET['hard_limit']) || $_GET['kiosk'] == true) ) {
if ($flickr === null) {
$flickr = new Flickr();
}
if (isset($_SESSION["FLICKR_FILTER_EMAIL"]) && $_SESSION["FLICKR_FILTER_EMAIL"] !== $flickr->get_uid_from_db()['uid']) {
unset($_SESSION['images']);
$_SESSION["FLICKR_FILTER_EMAIL"] = $flickr->get_uid_from_db()['uid'];
if (!empty($config["IMAGE_PROVIDER"])) {
if ($image_provider === null) {
if ($config["IMAGE_PROVIDER"] === 'FLICKR') {
$image_provider = new Flickr();
} else {
$image_provider = new Wikipedia();
}
if ($image_provider->is_reset()) {
$_SESSION['images'] = [];
}
}
// if we already searched flickr for this species before, use the previous image rather than doing an unneccesary api call
@@ -219,8 +221,8 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
if ($key !== false) {
$image = $_SESSION['images'][$key];
} else {
$flickr_cache = $flickr->get_image($todaytable['Sci_Name']);
array_push($_SESSION["images"], array($comname, $flickr_cache["image_url"], $flickr_cache["title"], $flickr_cache["photos_url"], $flickr_cache["author_url"], $flickr_cache["license_url"]));
$cached_image = $image_provider->get_image($todaytable['Sci_Name']);
array_push($_SESSION["images"], array($comname, $cached_image["image_url"], $cached_image["title"], $cached_image["photos_url"], $cached_image["author_url"], $cached_image["license_url"]));
$image = $_SESSION['images'][count($_SESSION['images']) - 1];
}
}
@@ -233,7 +235,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
<div class="centered_image_container">
<?php if(!empty($config["FLICKR_API_KEY"]) && strlen($image[2]) > 0) { ?>
<?php if(!empty($config["IMAGE_PROVIDER"]) && strlen($image[2]) > 0) { ?>
<img onclick='setModalText(<?php echo $iterations; ?>,"<?php echo urlencode($image[2]); ?>", "<?php echo $image[3]; ?>", "<?php echo $image[4]; ?>", "<?php echo $image[1]; ?>", "<?php echo $image[5]; ?>")' src="<?php echo $image[1]; ?>" class="img1">
<?php } ?>
@@ -252,7 +254,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
<td id="recent_detection_middle_td">
<div>
<div>
<?php if(!empty($config["FLICKR_API_KEY"]) && (isset($_GET['hard_limit']) || $_GET['kiosk'] == true) && strlen($image[2]) > 0) { ?>
<?php if(!empty($config["IMAGE_PROVIDER"]) && (isset($_GET['hard_limit']) || $_GET['kiosk'] == true) && strlen($image[2]) > 0) { ?>
<img style="float:left;height:75px;" onclick='setModalText(<?php echo $iterations; ?>,"<?php echo urlencode($image[2]); ?>", "<?php echo $image[3]; ?>", "<?php echo $image[4]; ?>", "<?php echo $image[1]; ?>", "<?php echo $image[5]; ?>")' src="<?php echo $image[1]; ?>" id="birdimage" class="img1">
<?php } ?>
</div>