Thread: Miscellaneous Hacks - VSa - Auto Birthday Greeter
View Single Post
  #177  
Old 11-02-2010, 02:57 AM
kras kras is offline
 
Join Date: Mar 2009
Posts: 4
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The original code used the vbdate()-function in a way that created bogus times, which actually is a design flaw in the function itself. However, since the Unix timestamp is independent from the default timezone settings i see no point in the original logic anyway, unless you alter the code to take advantage of vbdate's built in hourdiff mechanism, but since that mechanism uses the current users timezone you could get pretty unpredictable times.

I have altered the code so that a current UTC time is first created and then modified with the forums' timezone setttings to create a local forum time. In short, the product works fine now with the following changes.


Replace:

PHP Code:
$vsaabgreeter_servertime mktime('0'.date('H'TIMENOW),    '0'.date('i'TIMENOW), '0'.date('s'TIMENOW), '0'.date('m'TIMENOW),    '0'.date('d'TIMENOW), '0'.date('Y'TIMENOW), -1);
 
$vsaabgreeter_forumtime mktime('0'.vbdate('H'TIMENOW),    '0'.vbdate('i'TIMENOW), '0'.vbdate('s'TIMENOW), '0'.vbdate('m',    TIMENOW), '0'.vbdate('d'TIMENOW), '0'.vbdate('Y'TIMENOW), -1);
 
 
$vsaabgreeter_propertime TIMENOW;
 if (
$vsaabgreeter_servertime $vsaabgreeter_forumtime)
 {
         
$vsaabgreeter_timeoffset $vsaabgreeter_servertime $vsaabgreeter_forumtime;
         
$vsaabgreeter_propertime TIMENOW $vsaabgreeter_timeoffset 10;
 }
 else
 {
         
$vsaabgreeter_timeoffset $vsaabgreeter_forumtime $vsaabgreeter_servertime;
         
$vsaabgreeter_propertime TIMENOW $vsaabgreeter_timeoffset 10;
 }
 
 
$vsaabgreeter_execdate date('m-d'$vsaabgreeter_propertime);
 
 
$vsaabgreeter_done false;
 
$vsaabgreeter_posted $vbulletin->db->query_read(" SELECT daydone    FROM " TABLE_PREFIX "vsa_birthdaythread WHERE daydone =    '".$vbulletin->db->escape_string($vsaabgreeter_execdate)."' ");
 
 if (
$vbulletin->db->num_rows($vsaabgreeter_posted) > 0)
 {
         
$vsaabgreeter_done true;
 }
 
 
$vsaabgreeter_exechour date('H'$vsaabgreeter_propertime); 
[hr]-[/hr]

With:

PHP Code:
 $vsaabgreeter_Time = new DateTime("now", new DateTimeZone('UTC'));
 
$vsaabgreeter_offset $vbulletin->options[timeoffset];
 
$vsaabgreeter_Time->modify(($vsaabgreeter_offset >= '+' $vsaabgreeter_offset $vsaabgreeter_offset) . 'hour');
 
 
$vsaabgreeter_execdate $vsaabgreeter_Time->format('m-d');
 
 
$vsaabgreeter_done false;
 
$vsaabgreeter_posted $vbulletin->db->query_read(" SELECT daydone  FROM " TABLE_PREFIX "vsa_birthdaythread WHERE daydone =  '".$vbulletin->db->escape_string($vsaabgreeter_execdate)."' ");
 
 if (
$vbulletin->db->num_rows($vsaabgreeter_posted) > 0)
 {
         
$vsaabgreeter_done true;
 }
 
 
$vsaabgreeter_exechour $vsaabgreeter_Time->format('H'); 
[hr]-[/hr]


Note that the exclude times are still there, which by default means that no threads will be created after 20:00. These times can be altered in the array shown below


PHP Code:
 $vsaabgreeter_exchrs = array(20,21,22,23); 
[hr]-[/hr]

or removed completely by replacing:

PHP Code:
 $vsaabgreeter_exechour $vsaabgreeter_Time->format('H');
 
$vsaabgreeter_exchrs = array(20,21,22,23);
 
 if (!
$vsaabgreeter_done AND !in_array($vsaabgreeter_exechour$vsaabgreeter_exchrs)) 
[hr]-[/hr]

with

PHP Code:
 if (!$vsaabgreeter_done
[hr]-[/hr]

Attached is a file with all changes.
Attached Files
File Type: zip VSa_ABG.zip (3.2 KB, 109 views)
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01542 seconds
  • Memory Usage 1,837KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_attachment
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • 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_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete