Author Topic: time released uploads ("Delayed Activation")  (Read 35587 times)

0 Members and 1 Guest are viewing this topic.

Offline Sin Nombre

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Timewasters
time released uploads ("Delayed Activation")
« on: August 03, 2008, 06:09:30 PM »
i maintain a flash game gallery and i often upload many games at once
but i want them to be released one each day or another time interval.
i was wondering if it was even remotely possible to enable a delayed publish system.

for example lets say i upload 7 games on Monday September 1st.
i want the 1st game to be activated on monday 9/1
the 2nd game activated tuesday 9/2.
3rd game activated wednesday 9/3.
and so on.

i have some idea on how this would be implemented but i am not an expert php coder and the core of 4image is still a bit of a mystery to me.
i was hoping someone could help me with this and that this could be of some use to other people as well.

if it were to work i think it would be an optional field when uploading an individual image possibly under "User" and over "Activate" or somewhere on that form page.

the sooner the better please. thank you in advanced.
« Last Edit: August 28, 2008, 01:42:11 AM by Sin Nombre »

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
Re: time released uploads
« Reply #1 on: August 05, 2008, 01:28:34 AM »
It sounds like you and I are looking for the same thing.
I am wanting to upload a years worth of monthly calendars and just have them to become active at the beginning of thier month.

I had to put that project on the back burner because of other priorities but with all these talented programmers out there you would think it would not be so hard to do and I feel it would be a fantistic MOD addition to the 4images package as a whole.

When I was thinking about doing it, I was going to make an extra field in the database with a "Date to be activated" and then imbed some kind of script that would do a quick scan of the database once a day (only scanning when the first person of the day is opening the website to save on server power which would need another variable in the settings area maybe to see if the scan was made yet for that day? I think the script should be called from maybe in the header somewhere?) and if it saw something that needed to be activated then it would activate the image/game/media at that time. But that is about as far as I got on the project.

I can not believe that we are the only two looking for something like this.

I hope you get some answers and I hope that maybe I lit some lightbulbs to lead these great programmers in a path that may work and maybe they can do it much easier then I could.

I hope you get an answer soon because I am getting my calendars almost ready to post at my site and right now I am just uploading them manually at the beginning of each month.

Buddy Duke
www.budduke.com

Offline Sin Nombre

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Timewasters
Re: time released uploads
« Reply #2 on: August 09, 2008, 06:16:03 PM »
its good to know there's someone else out there with the same problem.
i hope theres a coder trying to figure this out because im sure we're not the only ones.
i have some abstract clue to how to resolve it.
im guessing it would link the "activate" table (1 or 0)
to a new table where the data of the release date would be stored from the upload form.
i have a hunch that the date() function should be used...i think.
im only guessing from a few php and mysql tutorials i've read a while ago
but im not sure how to code it with or without 4img core coding.
« Last Edit: August 09, 2008, 06:36:33 PM by Sin Nombre »

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
Re: time released uploads
« Reply #3 on: August 17, 2008, 06:17:55 PM »
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
Code: [Select]
$image_ids = implode(",",$selectimages);insert after
Code: [Select]
// 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
Code: [Select]
$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
Code: [Select]
// MOD delayed activation
  $image_row[$row['image_id']]['delayed_activate']= delay_activate($row['image_id']);
// END MOD delayed activation

look for
Code: [Select]
show_radio_row($lang['field_free'], "image_active", $image_row[$image_ids[0]]['image_active']);
insertafter
Code: [Select]
// 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
Code: [Select]
$image_active = intval($HTTP_POST_VARS['image_active']);
insert after this location only
Code: [Select]
// MOD delayed activation
  $delayed_activate = (trim($HTTP_POST_VARS['delayed_activate']) != "") ? trim($HTTP_POST_VARS['delayed_activate']) : 0;
// END MOD delayed activation

look for
Code: [Select]
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
Code: [Select]
// 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
Code: [Select]
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
Code: [Select]
// 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
Code: [Select]
else {
   $image_date[] = 0;
  }
insert after
Code: [Select]
// 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
Code: [Select]
$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
Code: [Select]
// 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
Code: [Select]
    $sql = "UPDATE ".IMAGES_TABLE."
            SET".trim($set, ",")."
            WHERE image_id = $val";
//echo $sql."<br>";
    $result = $site_db->query($sql);
insert after
Code: [Select]
// MOD delayed activation
}
// END MOD delayed activation

look for
Code: [Select]
$image_row = $site_db->query_firstrow($sql);
insert after
Code: [Select]
// MOD delayed activation
  $image_row['delayed_activate'] = delay_activate($image_id);
// END MOD delayed activation

look for
Code: [Select]
show_input_row($title, "image_date", $image_row['image_date'], $textinput_size);
Replace with
Code: [Select]
// 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
Code: [Select]
$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
Code: [Select]
// MOD delayed activation
$delayed_activate = trim($HTTP_POST_VARS['delayed_activate_'.$i]);
// END MOD delayed activation

look for
Code: [Select]
$image_active = trim($HTTP_POST_VARS['image_active_'.$i]);
Replace with
Code: [Select]
// 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
Code: [Select]
$result = $site_db->query($sql);
        $image_id = $site_db->get_insert_id();
insert after
Code: [Select]
// MOD delayed activation
if ($delayed_activate){
$delayed_activate = delay_activate($image_id,$delayed_activate);
}
// END MOD delayed activation

look for
Code: [Select]
show_radio_row($lang['field_free'], "image_active_".$i, 1);
Insert after
Code: [Select]
// 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
Code: [Select]
show_radio_row("Date", "editdate", 0);
insert after
Code: [Select]
// MOD delayed activation
  show_radio_row("Delayed Activation","editdelay",0);
// END MOD delayed activation

look for
Code: [Select]
$nextpage = isset($HTTP_POST_VARS['nextpage']) ? intval(trim($HTTP_POST_VARS['nextpage'])) : 0;
insert Before
Code: [Select]
// MOD delayed activation
  $editdelay = isset($HTTP_POST_VARS['editdelay']) ? intval(trim($HTTP_POST_VARS['editdelay'])) : 0;
// END MOD delayed activation

look for
Code: [Select]
if (!$editname && !$editdescription && !$editkeywords && !$editdate) {
replace with
Code: [Select]
// MOD delayed activation
    //if (!$editname && !$editdescription && !$editkeywords && !$editdate &&) {
    if (!$editname && !$editdescription && !$editkeywords && !$editdate && !$editdelay) {
// END MOD delayed activation

look for
Code: [Select]
while ($image_row = $site_db->fetch_array($result)) {
insert after
Code: [Select]
// MOD delayed activation
$image_row['delayed_activate'] = delay_activate($image_row['image_id']);
// END MOD delayed activation

look for 2 times in file
Code: [Select]
if ($editname || $editdescription || $editkeywords || $editdate) {
replace with both places
Code: [Select]
// MOD delayed activation
  //if ($editname || $editdescription || $editkeywords || $editdate  {
      if ($editname || $editdescription || $editkeywords || $editdate || $editdelay) {
// END MOD delayed activation  

look for
Code: [Select]
else {
        echo format_date($config['date_format'], $image_row['image_date']);
      }
insert after
Code: [Select]
// 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
Code: [Select]
show_hidden_input("editdate", $editdate);
insert after both places
Code: [Select]
// MOD delayed activation
show_hidden_input("editdelay", $editdelay);
// END MOD delayed activation


in the includes/functions.php file

look for
Code: [Select]
?>insert before
Code: [Select]
// 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
Code: [Select]
?>insert before
Code: [Select]
// 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
Code: [Select]
//-----------------------------------------------------
//--- 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
Code: [Select]
// 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...


« Last Edit: August 25, 2008, 02:37:11 AM by V@no »
Buddy Duke
www.budduke.com

Offline Sin Nombre

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Timewasters
Re: time released uploads
« Reply #4 on: August 17, 2008, 08:13:50 PM »
wow thank you so much that looks like alot of code. i appreciate the time and effort put in, i'll try it out today. and i'll update this post later to tell you if it worked for me.
thanks again.

i haven't put in the batch edit mod but i will do that first. i've run quite a few mods already and attempted a few that didn't work out too well and i think it might be effecting the speed of the website. it takes a little over 10 seconds to fully load my site...

Offline sigma.

  • Full Member
  • ***
  • Posts: 148
  • cydonian.com/potd
    • View Profile
    • sigma's gallery
Re: time released uploads
« Reply #5 on: August 17, 2008, 09:40:56 PM »
This is exactly what I need. It would save me allot of time to upload everything at once and set each image to publish one day after each other instead of doing it manually everyday. I will also give this a try and let you know.

I would of thought that with the new version of 4images 1.7.6, since there is a calendar tool beside the date and time for each image, that it would do just this. Unfortunately If you put your image to a future date it has no affect. Which is pointless.

Thanks for this!

Offline Sin Nombre

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Timewasters
Re: time released uploads
« Reply #6 on: August 21, 2008, 04:38:23 AM »
im kind of having 2nd thoughts about implementing more mods than i already have as it will slow things down... i'll try this and see if it slows things down too much if so i'll take it off and post it as an update.

Update
:
i just started and i can't seem to find "the ($action == "saveedit") area"
im using adobe dreamweaver to edit and its got a decent search.

ok i had to get the batch mod for saveedit area.

but the last step. i can't find "$site_area = "0";"
so i just put the code at the top i'll have 2 test it later as its getting really late. so...2 b continued.
« Last Edit: August 21, 2008, 06:03:21 AM by Sin Nombre »

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
Re: time released uploads
« Reply #7 on: August 21, 2008, 12:22:36 PM »
that is the nice thing about this mod, it call the routine everytime but if there is nothing for it to do it imediately exits the routine, so I have not noticed any slowdown at my site.
I have visited your site a couple of times and I see what you are complaining about.
Have you loaded the 4images_ms local server on your computer and uploaded your site to it?
Does it give you the same symtoms?
I use that little program all the time for my testing so I don't have to crash my main site doing these mods.

I have heard people say that google ads slow the load time down, but I am not an expert on that because I do not use that service.

If you do not see the add/save area then you probably do not have the batch copy/edit mod file. the main reason for most of those changes is to give you the button to actually select the delayed activation when you are editing files.
as long as you found most of them I think you should be ok.

the index.php file "$site_area"
in my file as long as you place it after this area you should be fine (yes, it is at the top of the file)
Code: [Select]
define('GET_CACHES', 1);
define('ROOT_PATH', './');
define('GET_USER_ONLINE', 1);
include(ROOT_PATH.'global.php');
require(ROOT_PATH.'includes/sessions.php');
$user_access = get_permission();
$site_area = "0";
Buddy Duke
www.budduke.com

Offline Sin Nombre

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Timewasters
Re: time released uploads
« Reply #8 on: August 21, 2008, 04:24:46 PM »
i just tried it and set the date for today an hour from now and then another one at a day from now they both activated and came up on the front page. maybe it was my copy and pasting last night i was tired. or maybe i didn't press no for activation above that...

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
Re: time released uploads
« Reply #9 on: August 21, 2008, 10:01:00 PM »
upload something the normal way without a date attached to it and see what time stamp it gets.
I found out my server provider is (what looks like) one day ahead on my site.
I was having the same issue till I posted something normally and saw it had the correct time, just one day ahead.
so now I am posting in the future...
and you also have to remember that it will post everything for that entire 24hr day that it is looking at.
I may have written my formulas wrong, will look at it again this weekend.
I posted 5 items one day apart and it seems to be working...
let me know if it still is not working for you...
Buddy Duke
www.budduke.com

Offline Sin Nombre

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Timewasters
Re: time released uploads
« Reply #10 on: August 22, 2008, 05:54:47 PM »
ok i checked the code again and i copied it verbatim.
i uploaded an image yesterday to be activated the 23rd
the server is located in europe so it's 6 hours ahead
so theoretically the new game should appear at 6pm EST. today.
i did click the radio button activate to no as well.
i set that to activate and the game appeared on the front page so i changed it to activate: no.

hopefully it's like a light switch and the delayed activation is like the trigger that flips it to activate.
the event to the trigger is the time specified on the textfield.
i'll reply after 6pm EST to tell you if it does or doesn't activate.

Offline budduke

  • Hero Member
  • *****
  • Posts: 506
    • View Profile
    • http://www.budduke.com
Re: time released uploads
« Reply #11 on: August 22, 2008, 06:21:37 PM »
oops, forgot to add that info to my original posting.

Yes, you have to set the image to "not activated"
and then set the "delayed Activation" to "on". because if the image is already active there is no reason to activate it later.
and you are correct. when the date arrives that the image is set for then the delayed activation will turn the "activate" switch "on".

hope it works!
Buddy Duke
www.budduke.com

Offline Sin Nombre

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Timewasters
Re: time released uploads
« Reply #12 on: August 22, 2008, 07:34:36 PM »
ohhhh it all makes sense now i hope it does too then i could upload a month or 2 worth and just forget about it till its running low which i can set on my google calendar.
thanks again. im looking into an easy way to make an automated referal link system maybe i'll find a website that's already ahead of me and its free. if only i knew python so i could use google apps to make it somehow. but anyways thanks

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: time released uploads
« Reply #13 on: August 23, 2008, 02:43:26 AM »
I'm sorry, I didn't look thoroughly through the code, and can't really tell how efficient it is, but IMHO its a little over complicated then it could be...

In theory all it needs is:
1) new field in the database that would store the date of the activation in the image entry (yes, you got that part done).
2) add info about that field into db_field_definitions.php, it should be set as "text" type and will be used the same way as image_date field, it will store the date of activation.
3) in member.php and image.php "catch" and convert text into time stamp the POST of delayed_activate before it saved along with the rest custom fields:
i.e. above     if (!empty($additional_image_fields)) {
      
$table_fields $site_db->get_table_fields(IMAGES_TABLE);

insert:
    if (isset($HTTP_POST_VARS['delayed_activate'])) $HTTP_POST_VARS['delayed_activate'] = UnixTime($HTTP_POST_VARS['delayed_activate']); //save it as time stamp


Also, there needed a few other changes that would save images as "not activated" if delayed_activate is set:

above
        $sql "INSERT INTO ".IMAGES_TABLE."


insert:
        $image_active = (isset($HTTP_POST_VARS['delayed_activate']) && !empty($HTTP_POST_VARS['delayed_activate'])) ? 1;

(well, in admin/images.php same thing (or similar) has to be done when saving edited image info)

4) in functions.php need new function (taken from php.net, not tested):
function UnixTime($mysql_timestamp){
    if (
preg_match('/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/'$mysql_timestamp$pieces)
        || 
preg_match('/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/'$mysql_timestamp$pieces)) {
            
$unix_time mktime($pieces[4], $pieces[5], $pieces[6], $pieces[2], $pieces[3], $pieces[1]);
    } elseif (
preg_match('/\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}/'$mysql_timestamp)
        || 
preg_match('/\d{2}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}/'$mysql_timestamp)
        || 
preg_match('/\d{4}\-\d{2}\-\d{2}/'$mysql_timestamp)
        || 
preg_match('/\d{2}\-\d{2}\-\d{2}/'$mysql_timestamp)) {
            
$unix_time strtotime($mysql_timestamp);
    } elseif (
preg_match('/(\d{4})(\d{2})(\d{2})/'$mysql_timestamp$pieces)
        || 
preg_match('/(\d{2})(\d{2})(\d{2})/'$mysql_timestamp$pieces)) {
            
$unix_time mktime(000$pieces[2], $pieces[3], $pieces[1]);
    }
  return 
$unix_time;
}


4) execute the routine that checks if any images needed activation by comparing curent time (via time() timestamp) and timestamp in delayed_active field - that's probably the hardest part, because that part is what "can" hit on performance .

P.S.
This is only a theory, on practice it might be more complicated then it looks...

P.P.S.
never insert anything at the beginning of an existing line unless its absolutely necessary, otherwise its hard find the needed line for future mods. (i.e. your line has changes in the middle:
Code: [Select]
    $sql = "SELECT image_id, image_name, image_keywords, image_description, image_allow_comments, image_active, delayed_activate, FROM_UNIXTIME(image_date) AS image_date, image_media_file, image_thumb_file
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Sin Nombre

  • Newbie
  • *
  • Posts: 35
    • View Profile
    • Timewasters
Re: time released uploads
« Reply #14 on: August 23, 2008, 04:07:39 AM »
it worked! i just came back from the movies and i checked my rss feed and the game activated!