vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.6 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=194)
-   -   Chat Modifications - Fix vbShout Timezone problem (https://vborg.vbsupport.ru/showthread.php?t=144449)

newhere 04-09-2007 10:00 PM

Fix vbShout Timezone problem
 
This vbShout plugin: http://www.vbhackers.com/f76/ajax-fl...ut-2-1-a-4536/

Has a serious bug with Time Zone changing to that of the last person to post in the shout box.

Here is a fix so that each user will see the time in their local timezone correctly.

1. Open template forumhome_vbshout_shout
Find this (should be at the very beginning):
Code:

<tr>
After it add:
Code:

                                <td nowrap align="left" valign="top">
                                <font size="1">
                                    <date>{$Shout['time']}</date>
                                   
                                </font>
                                </td>

Make sure that the "date" and "/date" tags are on the same line, and with no spaces between them and the $Shout variable, just as above. These are not valid html tags, and we are going to write code to replace them ourselves.



2. Open template forumhome_vbshout
Find:
Code:

Shouts.innerHTML = '<table cellpadding="1" cellspacing="3" border="0" width="95%" align="left">' + ShoutRequest.handler.responseText + '</table>'
Replace it with:
Code:

                        var formatMe = ShoutRequest.handler.responseText
                        formatMe = replaceDates(formatMe);
                        Shouts.innerHTML = '<table cellpadding="1" cellspacing="0" border="0" width="100%" align="left">' + formatMe + '</table>'

In the same template
Find this:
Code:

function sb_CollectHV(sbForm)
Before it add:
Code:

// replaces <date> tags
function replaceDates(s) {
            var ret = "";
            var matches = s.match(/<date>\d+<\/date>/g);
            for(var i = 0; matches != null && i < matches.length; i++) {
                var utc = matches[i].match(/\d+/);
                var date = new Date(utc * 1000);
                ret = ret + s.substr(0, s.indexOf(matches[i]));
                ret = ret + (date.getMonth()+1) + "/" +
                            date.getDate() + "/" +
                            date.getFullYear() + " " +
                            date.getHours() + ":" +
                            ((date.getMinutes() < 10) ? "0" : "") +
                            date.getMinutes() + ":" +
                            ((date.getSeconds() < 10) ? "0" : "") +
                            date.getSeconds() + " ";


                s = s.substr(s.indexOf(matches[i]) + matches[i].length);
            }
            ret = ret + s;
            return ret;
}




3. Open file vbshout.php
FInd this (There are similar code blocks, this should be in the function rewrite_shoutbox_flatfile() around line 226):
Code:

        $Shout['time']    = buildTime($Shout['s_time']);
        $Shout['s_shout']  = bbcodeparser($Shout['s_shout']);
        $Shout['style']    = '';
        $Shout['data']    = unserialize($Shout['s_data']);
        $Shout['username'] = fetch_musername($Shout, 'usergroupid');

        if (preg_match("#(\#)?0099FF#i", $Shout['data']['color']) && $Shout['s_by'] != 1)
        {
            $Shout['data']['color'] = '';
        }

Replace it with:
Code:

        // $Shout['time']    = buildTime($Shout['s_time']);
        $Shout['time']    = $Shout['s_time'];
        $Shout['s_shout']  = bbcodeparser($Shout['s_shout']);
        $Shout['style']    = '';
        $Shout['data']    = unserialize($Shout['s_data']);
        $Shout['username'] = fetch_musername($Shout, 'usergroupid');
       
        if (preg_match("#(\#)?0099FF#i", $Shout['data']['color']) && $Shout['s_by'] != 1)
        {
            $Shout['data']['color'] = '';
        }


This should now pass the date as UTC and JavaScript will convert it on the client side to the appropriate date.

Tulsa 04-10-2007 02:25 AM

Gave it a whirl and checked the edits twice. It's only showing "Loading"...

lovelypk 04-10-2007 02:25 AM

i was looking for this.
thank's.

dbirosel 04-10-2007 02:29 AM

Works great... can we have 12 hour time instead? How about the date being more simple like instead of 4/9/2007 have it as 4/9? How about adding brackets to the timestamps?

Overall, it's running great on my site. Thanks!

dbirosel 04-10-2007 02:30 AM

Quote:

Originally Posted by Tulsa (Post 1223767)
Gave it a whirl and checked the edits twice. It's only showing "Loading"...

Happened to me also, but i just posted a test message, and then all of a sudden it showed the current conversation. So far it's working good, just looks kinda ugly. lol :P

lovelypk 04-10-2007 02:32 AM

i am getting random number's instead of date, like this "1176175903".


dbirosel 04-10-2007 02:37 AM

Quote:

Originally Posted by lovelypk (Post 1223774)
i am getting random number's instead of date, like this "1176175903".


Are you using the flat file version from vbhackers? Is this your first time editing the vbshout.php and vbshout templates?

newhere 04-10-2007 02:37 AM

Quote:

Originally Posted by lovelypk (Post 1223774)
i am getting random number's instead of date, like this "1176175903".


Did you modify all the templates correctly?

newhere 04-10-2007 02:40 AM

Quote:

Originally Posted by dbirosel (Post 1223770)
Works great... can we have 12 hour time instead? How about the date being more simple like instead of 4/9/2007 have it as 4/9? How about adding brackets to the timestamps?


Overall, it's running great on my site. Thanks!

For formatting, you can change the function:
"replaceDates(s)"

Here:
Code:

                ret = ret + (date.getMonth()+1) + "/" +
                            date.getDate() + "/" +
                            date.getFullYear() + " " +
                            date.getHours() + ":" +
                            ((date.getMinutes() < 10) ? "0" : "") +
                            date.getMinutes() + ":" +
                            ((date.getSeconds() < 10) ? "0" : "") +
                            date.getSeconds() + " ";

To whatever you like.

dbirosel 04-10-2007 02:44 AM

Quote:

Originally Posted by newhere (Post 1223784)
For formatting, you can change the function:
"replaceDates(s)"

Here:
Code:

                ret = ret + (date.getMonth()+1) + "/" +
                            date.getDate() + "/" +
                            date.getFullYear() + " " +
                            date.getHours() + ":" +
                            ((date.getMinutes() < 10) ? "0" : "") +
                            date.getMinutes() + ":" +
                            ((date.getSeconds() < 10) ? "0" : "") +
                            date.getSeconds() + " ";

To whatever you like.

Does this code also change from 24 hour to 12 hour time?


All times are GMT. The time now is 12:28 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.01170 seconds
  • Memory Usage 1,759KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (10)bbcode_code_printable
  • (5)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete