switch to neutral image_provider
This commit is contained in:
+27
-25
@@ -2,7 +2,6 @@
|
|||||||
error_reporting(E_ERROR);
|
error_reporting(E_ERROR);
|
||||||
ini_set('display_errors',1);
|
ini_set('display_errors',1);
|
||||||
ini_set('session.gc_maxlifetime', 7200);
|
ini_set('session.gc_maxlifetime', 7200);
|
||||||
ini_set('user_agent', 'PHP_Flickr/1.0');
|
|
||||||
session_set_cookie_params(7200);
|
session_set_cookie_params(7200);
|
||||||
session_start();
|
session_start();
|
||||||
require_once 'scripts/common.php';
|
require_once 'scripts/common.php';
|
||||||
@@ -61,7 +60,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse
|
|||||||
$_SESSION['images'] = [];
|
$_SESSION['images'] = [];
|
||||||
}
|
}
|
||||||
$iterations = 0;
|
$iterations = 0;
|
||||||
$flickr = null;
|
$image_provider = null;
|
||||||
|
|
||||||
// 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
|
// 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)) {
|
while($mostrecent = $result4->fetchArray(SQLITE3_ASSOC)) {
|
||||||
@@ -78,24 +77,25 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse
|
|||||||
|
|
||||||
$iterations++;
|
$iterations++;
|
||||||
|
|
||||||
if (!empty($config["FLICKR_API_KEY"])) {
|
if (!empty($config["IMAGE_PROVIDER"])) {
|
||||||
if ($flickr === null) {
|
if ($image_provider === null) {
|
||||||
$flickr = new Flickr();
|
if ($config["IMAGE_PROVIDER"] === 'FLICKR') {
|
||||||
}
|
$image_provider = new Flickr();
|
||||||
if ($_SESSION["FLICKR_FILTER_EMAIL"] !== $flickr->get_uid_from_db()['uid']) {
|
} else {
|
||||||
if (isset($_SESSION["FLICKR_FILTER_EMAIL"])) {
|
$image_provider = new Wikipedia();
|
||||||
|
}
|
||||||
|
if ($image_provider->is_reset()) {
|
||||||
$_SESSION['images'] = [];
|
$_SESSION['images'] = [];
|
||||||
}
|
}
|
||||||
$_SESSION["FLICKR_FILTER_EMAIL"] = $flickr->get_uid_from_db()['uid'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we already searched flickr for this species before, use the previous image rather than doing an unneccesary api call
|
// if we already searched for this species before, use the previous image rather than doing an unneccesary api call
|
||||||
$key = array_search($comname, array_column($_SESSION['images'], 0));
|
$key = array_search($comname, array_column($_SESSION['images'], 0));
|
||||||
if ($key !== false) {
|
if ($key !== false) {
|
||||||
$image = $_SESSION['images'][$key];
|
$image = $_SESSION['images'][$key];
|
||||||
} else {
|
} else {
|
||||||
$flickr_cache = $flickr->get_image($mostrecent['Sci_Name']);
|
$cached_image = $image_provider->get_image($mostrecent['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"]));
|
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];
|
$image = $_SESSION['images'][count($_SESSION['images']) - 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -123,7 +123,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="relative"><a target="_blank" href="index.php?filename=<?php echo $mostrecent['File_Name']; ?>"><img class="copyimage" title="Open in new tab" width="25" height="25" src="images/copy.png"></a>
|
<td class="relative"><a target="_blank" href="index.php?filename=<?php echo $mostrecent['File_Name']; ?>"><img class="copyimage" title="Open in new tab" width="25" height="25" src="images/copy.png"></a>
|
||||||
<div class="centered_image_container" style="margin-bottom: 0px !important;">
|
<div class="centered_image_container" style="margin-bottom: 0px !important;">
|
||||||
<?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">
|
<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 } ?>
|
<?php } ?>
|
||||||
<form action="" method="GET">
|
<form action="" method="GET">
|
||||||
@@ -348,10 +348,9 @@ while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
|||||||
if (!isset($_SESSION['images'])) {
|
if (!isset($_SESSION['images'])) {
|
||||||
$_SESSION['images'] = [];
|
$_SESSION['images'] = [];
|
||||||
}
|
}
|
||||||
$flickr = null;
|
|
||||||
|
|
||||||
function display_species($species_list, $title, $show_last_seen=false) {
|
function display_species($species_list, $title, $show_last_seen=false) {
|
||||||
global $config, $_SESSION, $flickr;
|
global $config, $_SESSION, $image_provider;
|
||||||
$species_count = count($species_list);
|
$species_count = count($species_list);
|
||||||
if ($species_count > 0): ?>
|
if ($species_count > 0): ?>
|
||||||
<div class="<?php echo strtolower(str_replace(' ', '_', $title)); ?>">
|
<div class="<?php echo strtolower(str_replace(' ', '_', $title)); ?>">
|
||||||
@@ -377,24 +376,27 @@ function display_species($species_list, $title, $show_last_seen=false) {
|
|||||||
$url_title = $info_url['TITLE'];
|
$url_title = $info_url['TITLE'];
|
||||||
|
|
||||||
$image_url = ""; // Default empty image URL
|
$image_url = ""; // Default empty image URL
|
||||||
|
|
||||||
if (!empty($config["FLICKR_API_KEY"])) {
|
if (!empty($config["IMAGE_PROVIDER"])) {
|
||||||
if ($flickr === null) {
|
if ($image_provider === null) {
|
||||||
$flickr = new Flickr();
|
if ($config["IMAGE_PROVIDER"] === 'FLICKR') {
|
||||||
|
$image_provider = new Flickr();
|
||||||
|
} else {
|
||||||
|
$image_provider = new Wikipedia();
|
||||||
}
|
}
|
||||||
if (isset($_SESSION["FLICKR_FILTER_EMAIL"]) && $_SESSION["FLICKR_FILTER_EMAIL"] !== $flickr->get_uid_from_db()['uid']) {
|
if ($image_provider->is_reset()) {
|
||||||
unset($_SESSION['images']);
|
$_SESSION['images'] = [];
|
||||||
$_SESSION["FLICKR_FILTER_EMAIL"] = $flickr->get_uid_from_db()['uid'];
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the Flickr image has been cached in the session
|
// Check if the image has been cached in the session
|
||||||
$key = array_search($comname, array_column($_SESSION['images'], 0));
|
$key = array_search($comname, array_column($_SESSION['images'], 0));
|
||||||
if ($key !== false) {
|
if ($key !== false) {
|
||||||
$image = $_SESSION['images'][$key];
|
$image = $_SESSION['images'][$key];
|
||||||
} else {
|
} else {
|
||||||
// Retrieve the image from Flickr API and cache it
|
// Retrieve the image from Flickr API and cache it
|
||||||
$flickr_cache = $flickr->get_image($todaytable['Sci_Name']);
|
$cached_image = $image_provider->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"]));
|
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];
|
$image = $_SESSION['images'][count($_SESSION['images']) - 1];
|
||||||
}
|
}
|
||||||
$image_url = $image[1] ?? ""; // Get the image URL if available
|
$image_url = $image[1] ?? ""; // Get the image URL if available
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ $_GET = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING);
|
|||||||
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
|
$_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
|
||||||
|
|
||||||
ini_set('session.gc_maxlifetime', 7200);
|
ini_set('session.gc_maxlifetime', 7200);
|
||||||
ini_set('user_agent', 'PHP_Flickr/1.0');
|
|
||||||
session_set_cookie_params(7200);
|
session_set_cookie_params(7200);
|
||||||
session_start();
|
session_start();
|
||||||
error_reporting(E_ERROR);
|
error_reporting(E_ERROR);
|
||||||
@@ -186,7 +185,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
|
|||||||
$_SESSION['images'] = [];
|
$_SESSION['images'] = [];
|
||||||
}
|
}
|
||||||
$iterations = 0;
|
$iterations = 0;
|
||||||
$flickr = null;
|
$image_provider = null;
|
||||||
|
|
||||||
while($todaytable=$result0->fetchArray(SQLITE3_ASSOC))
|
while($todaytable=$result0->fetchArray(SQLITE3_ASSOC))
|
||||||
{
|
{
|
||||||
@@ -205,13 +204,16 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
|
|||||||
$url = $info_url['URL'];
|
$url = $info_url['URL'];
|
||||||
$url_title = $info_url['TITLE'];
|
$url_title = $info_url['TITLE'];
|
||||||
|
|
||||||
if (!empty($config["FLICKR_API_KEY"]) && (isset($_GET['display_limit']) || isset($_GET['hard_limit']) || $_GET['kiosk'] == true) ) {
|
if (!empty($config["IMAGE_PROVIDER"])) {
|
||||||
if ($flickr === null) {
|
if ($image_provider === null) {
|
||||||
$flickr = new Flickr();
|
if ($config["IMAGE_PROVIDER"] === 'FLICKR') {
|
||||||
}
|
$image_provider = new Flickr();
|
||||||
if (isset($_SESSION["FLICKR_FILTER_EMAIL"]) && $_SESSION["FLICKR_FILTER_EMAIL"] !== $flickr->get_uid_from_db()['uid']) {
|
} else {
|
||||||
unset($_SESSION['images']);
|
$image_provider = new Wikipedia();
|
||||||
$_SESSION["FLICKR_FILTER_EMAIL"] = $flickr->get_uid_from_db()['uid'];
|
}
|
||||||
|
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
|
// 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) {
|
if ($key !== false) {
|
||||||
$image = $_SESSION['images'][$key];
|
$image = $_SESSION['images'][$key];
|
||||||
} else {
|
} else {
|
||||||
$flickr_cache = $flickr->get_image($todaytable['Sci_Name']);
|
$cached_image = $image_provider->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"]));
|
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];
|
$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">
|
<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">
|
<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 } ?>
|
<?php } ?>
|
||||||
|
|
||||||
@@ -252,7 +254,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
|
|||||||
<td id="recent_detection_middle_td">
|
<td id="recent_detection_middle_td">
|
||||||
<div>
|
<div>
|
||||||
<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">
|
<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 } ?>
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user