Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-01-2009, 10:44 PM
paul41598's Avatar
paul41598 paul41598 is offline
 
Join Date: Jun 2004
Location: MI
Posts: 732
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Trying To Grasp Time/Date Within TimeFrame

I'm working on a mod...and I'm stuck at a probably simple theory.

I have these expiration threads...and some of them are set to expire on certain days. What I essentially want to do is, if today is within 3 days of that expiration date, I want it to change a color.

Now I'm not worried about the color change, but just the theory of how to write this code.

PHP Code:
$test = (TIMENOW - (86400));
$test vbdate($vbulletin->options['threadexpiration_dateselect'],  $test);

//echo $test; echo "<br>";

if ($test <= $thread['thread_expiry']) {
$thread['thread_expiry'] = "nice";


I'm stuck there, and I'm probably way off...but if a thread is going to expire within 3 days for example.. I want it to do something. Can anyone somewhat help me out here? The $thread['thread_expiry'] is already a defined variable and has the timestamp of the expiration
Reply With Quote
  #2  
Old 05-01-2009, 10:56 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You need to have thread_expiry as a unix timestamp and then perform your date calculations on it.
Reply With Quote
  #3  
Old 05-01-2009, 11:14 PM
paul41598's Avatar
paul41598 paul41598 is offline
 
Join Date: Jun 2004
Location: MI
Posts: 732
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

it is already a unix timestamp in the database

I just have no idea about the calculation part
Reply With Quote
  #4  
Old 05-01-2009, 11:23 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If it already is a unix timestamp, then you can probably grab it out of the database like: SELECT ..... (UNIX_TIMESTAMP(NOW()) - thread.thread_expiry) as test, etc.... and then:
PHP Code:
$threedays 86400;

if (
$thread['test'] < $threedays) {
$thread['thread_expiry'] = "less than three days";

Not tested for syntax or to see if it works.
Reply With Quote
  #5  
Old 05-01-2009, 11:35 PM
paul41598's Avatar
paul41598 paul41598 is offline
 
Join Date: Jun 2004
Location: MI
Posts: 732
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Lynne,

Well thats the confusion too is querying the database. Remember my other thread today where in forumdisplay_query hook I had:

PHP Code:
$hook_query_fields .= ", thread_expiry"
Well....the problem with extending this query is I don't want to SELECT (UNIX_TIMESTAMP(NOW()) - thread.thread_expiry) , because wont that give me all threads that are expiring in 3 days? I essentially just want to grab all threads and their corresponding expiration date.

THen outside of the query I wanted to write an IF conditional to say "if those threads that have expiry dates and have less than 3 days left before they expire", then turn them red.

is that confusing? Do you need more info? argh
Reply With Quote
  #6  
Old 05-01-2009, 11:44 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I was saying to use that in the query. So something like this:
PHP Code:
$hook_query_fields .= ", (UNIX_TIMESTAMP(NOW()) - thread.thread_expiry) as test"
That will return the variable 'test' which is the difference between now and thread_expiry in seconds for that thread. Or it should if I wrote it right... (I'm not great at queries, so you may want to go look up time stuff on the mysql site to double-check me.)

Then use what I wrote in the other plugin to see if that difference is within three weeks.
Reply With Quote
  #7  
Old 05-02-2009, 12:25 AM
paul41598's Avatar
paul41598 paul41598 is offline
 
Join Date: Jun 2004
Location: MI
Posts: 732
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ya I get no results...I think the query is off..I'll take a look and post results soon hopefully

I didnt know you could select something like what u put above...? I thought that had to be in the WHERE clause. Guess not huh?
Reply With Quote
  #8  
Old 05-02-2009, 02:46 AM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You aren't getting any results? Or you aren't getting the value 'test'? If you are suddenly not getting results, then there is something typed wrong in that plugin. You might want to turn off that plugin, see if you get results, then turn it on and see if you get the same threads. Try spitting out the variable in your threadbit and see what number you get.

You might want to try just UNIX_TIMESTAMP() instead of UNIX_TIMESTAMP(NOW()) also. That's something I use on my tracker and I think I had to use NOW() there for one reason or another.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:30 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.15326 seconds
  • Memory Usage 2,235KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (4)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete