UPDATED 08-24-2008!!! PLEASE READ!
This modified post includes all discussions up to reply#20
With the help of V@no, this appears to work pretty good...
This MOD give you the option to enter a delayed activation date/time for activating an image later automatically.
This only works in the admin ACP area. The end users to your site can not use this MOD.
Not sure what mods you are using but I modifield the main add/edit area and also
I am using the "[MOD] Batch Copy/Move/Edit Images v3.7.3 " to make it easier to change multiple items.
If you are using different mods, then inside of them just select 'not activated' and then make your delayed activation settings after they are uploaded using the edit 'not activated' items.
There are 4 files that will be changed,
admin/images.php
includes/functions.php
includes/page_header.php (This MOD is called from this page for activating images)
lang/english/admin.php
Backup these files before you start changing them!
lets start with the long one
in the admin/images.php file
look for
$image_ids = implode(",",$selectimages);
insert after
// MOD delayed activation
$delayed_activate = (trim($HTTP_POST_VARS['delayed_activate']) != "") ? trim($HTTP_POST_VARS['delayed_activate']) : 0;
$image_active = (isset($HTTP_POST_VARS['delayed_activate']) && !empty($HTTP_POST_VARS['delayed_activate'])) ? 0 : $HTTP_POST_VARS['image_active'];
$HTTP_POST_VARS['image_active']= $image_active;
$HTTP_POST_VARS['delayed_activate']= $delayed_activate;
$my_loop= explode(",",$image_ids);
foreach ($my_loop as $var){
if (!$delayed_activate){
delay_activate($var, "remove");
}
else {
$delayed_activate=delay_activate($var,$delayed_activate);
}
}
// END MOD delayed activation
look for
$list .= (($row['image_name']) ? "<a href=\"../details.php?image_id=".$row['image_id']."\" target=\"_blank\">".$row['image_name']."</a>" : "<b class=\"marktext\">".$lang['lang_error']."</b>")." (ID: ".$row['image_id']."), ";
insert after
// MOD delayed activation
$image_row[$row['image_id']]['delayed_activate']= delay_activate($row['image_id']);
// END MOD delayed activation
look for
show_radio_row($lang['field_free'], "image_active", $image_row[$image_ids[0]]['image_active']);
insertafter
// MOD delayed activation
show_date_input_row($lang['field_delayed'].$lang['date_format'].$lang['delay_desc'], "delayed_activate", $image_row[$image_ids[0]]['delayed_activate'], $textinput_size);
// END MOD delayed activation
There are 2 instances of this
look for this entry under if ($action == "updateimage") area
$image_active = intval($HTTP_POST_VARS['image_active']);
insert after this location only
// MOD delayed activation
$delayed_activate = (trim($HTTP_POST_VARS['delayed_activate']) != "") ? trim($HTTP_POST_VARS['delayed_activate']) : 0;
// END MOD delayed activation
look for
if (empty($error)) {
$additional_sql = "";
if (!empty($additional_image_fields)) {
$table_fields = $site_db->get_table_fields(IMAGES_TABLE);
foreach ($additional_image_fields as $key => $val) {
if (isset($HTTP_POST_VARS[$key]) && isset($table_fields[$key])) {
$additional_sql .= ", $key = '".un_htmlspecialchars(trim($HTTP_POST_VARS[$key]))."'";
}
}
}
insert after
// MOD delayed activation
if ($delayed_activate){
//delay_activate($image_id,$delayed_activate);
$delayed_activate=delay_activate($image_id,$delayed_activate);
$image_active = (isset($HTTP_POST_VARS['delayed_activate']) && !empty($HTTP_POST_VARS['delayed_activate'])) ? 0 : $HTTP_POST_VARS['image_active'];
$HTTP_POST_VARS['image_active']= $image_active;
$HTTP_POST_VARS['delayed_activate']= $delayed_activate;
}
else {
delay_activate($image_id,"remove");
}
// END MOD delayed activation
look for
if ($action == $lang['save'] || $action == "save") {
$editname = isset($HTTP_POST_VARS['editname']) ? intval(trim($HTTP_POST_VARS['editname'])) : 0;
$editdescription = isset($HTTP_POST_VARS['editdescription']) ? intval(trim($HTTP_POST_VARS['editdescription'])) : 0;
$editkeywords = isset($HTTP_POST_VARS['editkeywords']) ? intval(trim($HTTP_POST_VARS['editkeywords'])) : 0;
$editdate = isset($HTTP_POST_VARS['editdate']) ? intval(trim($HTTP_POST_VARS['editdate'])) : 0;
insert after
// MOD delayed activation
$editdelay = isset($HTTP_POST_VARS['editdelay']) ? intval(trim($HTTP_POST_VARS['editdelay'])) : 0;
$delayed_activate = array();
$image_active = array();
// END MOD delayed activation
look for
else {
$image_date[] = 0;
}
insert after
// MOD delayed activation
if (isset($HTTP_POST_VARS['delayed_activate'])) {
$delayed_activate = $HTTP_POST_VARS['delayed_activate'];
}
else {
$delayed_activate[] = 0;
}
// END MOD delayed activation
look for
$set = (($editname && !empty($image_name[$key])) ? " image_name = '".trim(addslashes($image_name[$key]))."'" : "").(($editdescription) ? ", image_description = '".trim(addslashes($image_description[$key]))."'" : "").(($editkeywords) ? ", image_keywords = '".trim(addslashes($image_keywords[$key]))."'" : "").(($editdate) ? ", image_date = UNIX_TIMESTAMP('".$image_date[$key]."')" : "");
replace with
// MOD delayed activation
if ($editdelay && !empty($delayed_activate[$key])){
$delayed_activate[$key] = delay_activate($val,$delayed_activate[$key]);
$image_active[$key]=0;
}
else if ($editdelay) {
delay_activate($val,"remove");
$image_active[$key]=1;
}
// END MOD delayed activation
$set = (($editname && !empty($image_name[$key])) ? " image_name = '".$image_name[$key]."'" : "").(($editdescription) ? ", image_description = '".$image_description[$key]."'" : "").(($editkeywords) ? ", image_keywords = '".trim(addslashes($image_keywords[$key]))."'" : "").(($editdate) ? ", image_date = UNIX_TIMESTAMP('".$image_date[$key]."')" : "");
// MOD delayed activation
if (!$image_active[$key]){
$set = $set.", image_active = 0";
}
if ($set){
// END MOD delayed activation
look for
$sql = "UPDATE ".IMAGES_TABLE."
SET".trim($set, ",")."
WHERE image_id = $val";
//echo $sql."<br>";
$result = $site_db->query($sql);
insert after
// MOD delayed activation
}
// END MOD delayed activation
look for
$image_row = $site_db->query_firstrow($sql);
insert after
// MOD delayed activation
$image_row['delayed_activate'] = delay_activate($image_id);
// END MOD delayed activation
look for
show_input_row($title, "image_date", $image_row['image_date'], $textinput_size);
Replace with
// MOD delayed activation extra
show_date_input_row($title, "image_date", $image_row['image_date'], $textinput_size);
//show_input_row($title, "image_date", $image_row['image_date'], $textinput_size);
show_date_input_row($lang['field_delayed'].$lang['date_format'].$lang['delay_desc'], "delayed_activate", $image_row['delayed_activate'], $textinput_size);
// END MOD delayed activation
look for
$remote_file = trim($HTTP_POST_VARS['remote_file_'.$i]);
$remote_thumb_file = trim($HTTP_POST_VARS['remote_thumb_file_'.$i]);
$image_download_url = trim($HTTP_POST_VARS['image_download_url_'.$i]);
insert after
// MOD delayed activation
$delayed_activate = trim($HTTP_POST_VARS['delayed_activate_'.$i]);
// END MOD delayed activation
look for
$image_active = trim($HTTP_POST_VARS['image_active_'.$i]);
Replace with
// MOD delayed activation
//$image_active = trim($HTTP_POST_VARS['image_active_'.$i]);
$delayed_activate = (trim($HTTP_POST_VARS['delayed_activate_'.$i]) != "") ? trim($HTTP_POST_VARS['delayed_activate_'.$i]) : 0;
$image_active = (trim($HTTP_POST_VARS['delayed_activate_'.$i]) != "") ? 0 : trim($HTTP_POST_VARS['image_active_'.$i]);
$HTTP_POST_VARS['image_active_'.$i] = $image_active;
// END MOD delayed activation
look for
$result = $site_db->query($sql);
$image_id = $site_db->get_insert_id();
insert after
// MOD delayed activation
if ($delayed_activate){
$delayed_activate = delay_activate($image_id,$delayed_activate);
}
// END MOD delayed activation
look for
show_radio_row($lang['field_free'], "image_active_".$i, 1);
Insert after
// MOD delayed activation
show_date_input_row($lang['field_delayed'].$lang['date_format'].$lang['delay_desc'], "delayed_activate_".$i, "", $textinput_size);
// END MOD delayed activation
look for
show_radio_row("Date", "editdate", 0);
insert after
// MOD delayed activation
show_radio_row("Delayed Activation","editdelay",0);
// END MOD delayed activation
look for
$nextpage = isset($HTTP_POST_VARS['nextpage']) ? intval(trim($HTTP_POST_VARS['nextpage'])) : 0;
insert Before
// MOD delayed activation
$editdelay = isset($HTTP_POST_VARS['editdelay']) ? intval(trim($HTTP_POST_VARS['editdelay'])) : 0;
// END MOD delayed activation
look for
if (!$editname && !$editdescription && !$editkeywords && !$editdate) {
replace with
// MOD delayed activation
//if (!$editname && !$editdescription && !$editkeywords && !$editdate &&) {
if (!$editname && !$editdescription && !$editkeywords && !$editdate && !$editdelay) {
// END MOD delayed activation
look for
while ($image_row = $site_db->fetch_array($result)) {
insert after
// MOD delayed activation
$image_row['delayed_activate'] = delay_activate($image_row['image_id']);
// END MOD delayed activation
look for 2 times in file
if ($editname || $editdescription || $editkeywords || $editdate) {
replace with both places
// MOD delayed activation
//if ($editname || $editdescription || $editkeywords || $editdate {
if ($editname || $editdescription || $editkeywords || $editdate || $editdelay) {
// END MOD delayed activation
look for
else {
echo format_date($config['date_format'], $image_row['image_date']);
}
insert after
// MOD delayed activation
if ($editdelay) {
echo "<BR><BR>".$lang['field_delayed']."<BR>";
echo "<input name=\"delayed_activate[$i]\" value=\"".$image_row['delayed_activate']."\" /><br />yyyy-mm-dd hh:mm:ss";
}
else if ($image_row['delayed_activate']){
echo "<BR><BR>".$lang['delayed_on'].$image_row['delayed_activate'];
}
// END MOD delayed activation
look for 2 times in file
show_hidden_input("editdate", $editdate);
insert after both places
// MOD delayed activation
show_hidden_input("editdelay", $editdelay);
// END MOD delayed activation
in the includes/functions.php file
look for
?>
insert before
// MOD delayed activation
function delay_activate($image_id = 0, $date = 0)
{
global $site_db, $config;
$check_every = (60*1); //check once per 1 minute
// $check_every = (1 * 60 * 60);// once a hour
// $check_every = (1 * 24 * 60 * 60);// once a day
// $check_every = (7 * 24 * 60 * 60);// once a week
// $check_every = (14 * 24 * 60 * 60);// once every 2 weeks
// $check_every = (28 * 24 * 60 * 60);// once a month
$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
{
if ($date == "remove"){ // if you deleted the date stamp for delayed activation this removes it from the list
$config['delayed_activate'][$image_id]= "";
$update = true;
}
else {
$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
$return = $config['delayed_activate'][$image_id];
}
}
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 && $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 if ($val){
$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);
}
if ($return){
return date("Y-m-d H:i:s",$return); //returns the date in proper display format
}
}
// END MOD delayed activation
in the lang/english/admin.php file
look for
?>
insert before
// MOD delayed activation
$lang['field_delayed'] = "Delayed activation";
$lang['delayed_on'] = "Delayed activation is on.<BR>The date set for this is<BR>";
$lang['delay_desc']= "<br /><span class=\"smalltext\">Leave blank to not use Delayed activation.<span />";
// END MOD delayed activation
I placed the call for the function
in the includes/page_header.php file (per V@no advice)
look for
//-----------------------------------------------------
//--- Register Global Vars ----------------------------
//-----------------------------------------------------
$total_images = 0;
$total_categories = 0;
$auth_cat_sql['auth_viewcat']['IN'] = 0;
$auth_cat_sql['auth_viewcat']['NOTIN'] = 0;
insert after
// MOD delayed activation
delay_activate();
// END MOD delayed activation
this will call the function everytime someone clicks on the page_header.php file
the function works by looking at the next date to check images, if not yet then it immediately return from the function
otherwise it scans the array for anything that is set for delayed activation that needs to be activated.
Near the beginning of the function you will see the different intervals you can have it checking for activating images.
just add // to the original line and remove the // from the line you want to use.
I had this running every minute and saw no slowdown on my site I even had it putting new images up every minute. pretty cool watching them pop up so fast with having to do anything.
hope this works for you...