While I was wring my previous reply and going over your code, I realized that maybe your method is more efficient on large galleries with lots of images, because MySQL is a bottleneck if it has to scan through thousands of entries...
So, storing list of images into settings field would probably be the fastest way, unless you are planning on delay thousands of images at once.
Let me give you a few more hints on how to optimize your method.
1) you need only one new field into 4images_settings database table (no need new fields in 4images_images table)
2) you'll need new input fields in upload and edit image forms, lets leave them as you already done: delayed_activate. In that input field you can enter the date when the image will be activated (the same as the image date input field)
3) as in my code above check if anything entered into delayed_activate input form and if so, set image_active to 0
(i.e. $image_active = (isset($HTTP_POST_VARS['delayed_activate']) && !empty($HTTP_POST_VARS['delayed_activate'])) ? 0 : 1;
4) you'll need a new function in functions.php:
//MOD delayed activation
function delay_activate($image_id = 0, $date = 0)
{
global $site_db, $config;
$check_every = 60*1; //check no more then once per 1 minute
$current_time = time();
$sql_data = "";
$update = false;
$image_list = "";
$return = "";
if (!isset($config['delayed_activate'])) //this block can be removed if delayed_activate field already added into settings table
{
$sql = "INSERT INTO " . SETTINGS_TABLE . "
(setting_name , setting_value)
VALUES
('delayed_activate', '')";
$site_db->query($sql);
$config['delayed_activate'] = "";
}
if (!is_array($config['delayed_activate'])) //this is first time this function called
{
$delayed_activate = explode(",", $config['delayed_activate']); //images separated by comma
$config['delayed_activate'] = array();
foreach($delayed_activate as $val)
{
$data = explode(" ", $val); //image id separated from activate delay timestamp by a space
if (isset($data[1]))
$config['delayed_activate'][$data[0]] = $data[1];
}
if (!isset($config['delayed_activate'][0]))
$config['delayed_activate'][0] = $current_time; //store last time we checked delayed dates
}
if ($image_id) //add or update existing image with new activation date
{
if ($date) //add/update
{
$config['delayed_activate'][$image_id] = (is_numeric($date)) ? $date : strtotime($date); //add new image id into the list
$update = true; //we need update settings database
}
else //return delayed date for requested $image_id
{
if (isset($config['delayed_activate'][$image_id]))
$return = $config['delayed_activate'][$image_id];
}
}
if ($update || $config['delayed_activate'][0] <= $current_time - $check_every) //do we need update settings or is time for next update?
{
$config['delayed_activate'][0] = $current_time; //store current time as update time
foreach($config['delayed_activate'] as $key => $val) //loop through all delayed image list
{
if ($key && $val <= $current_time) //if $key = 0 - its update timestamp and not image id, otherwise check if ac
{
$image_list .= "," . $key; //list of images to activate
}
else
{
$sql_data .= "," . $key . " " . $val; //save image id and activation delay date separated by space
}
}
$image_list = trim($image_list, ",");
$sql_data = trim($sql_data, ",");
}
if (!empty($image_list)) //activate images
{
$sql = "UPDATE " . IMAGES_TABLE . "
SET image_active = 1
WHERE image_id IN (" . $image_list . ")";
$site_db->query($sql);
}
if (!empty($sql_data)) //save list of images and time of last check
{
$sql = "UPDATE " . SETTINGS_TABLE ."
SET setting_value = '" . $sql_data . "'
WHERE setting_name = 'delayed_activate'";
$site_db->query($sql);
}
} // END function delay_activate
//END MOD delayed activation
This function is "all-in-one":
If its called with one paramter delay_activate($image_id) it will return unix timestamp of $image_id image, if no delay was stored for that id, it will return empty string, plus it will do checking and image activation if needed.
If its called with two parameters delay_activate($image_id, $date) it will add or update delay time of the $image_id, plus it will do checking and image activation if needed. In parameter $date you can either send unix timestamp or unmodified entry from delay_activate input field, it will convert it into unix timestamp.
If its called without any paramaters delay_activate() it will do only checking if its time for "delayed" images get activated and will activate needed images
By default it will do the check and database update no more then once a minute (set in $check_every variable), therefor its quiet safe add in page_header.php:delay_activate();