Welcome, Guest. Please Login or Register.
April 26, 2025, 10:18:57 PM
Home Help Search Log in Register
News: SMF is the next generation in forum software, almost completely re-written from the ground up, make sure you don't fall for cheap imitations that suffer from feature bloat!

YaBB SE Community  |  Development  |  Completed mods  |  [Code] Time Tag « previous next »
Pages: [1] Reply Ignore Print
Author Topic: [Code] Time Tag  (Read 3349 times)
Myiasis
Full Member
***
Posts: 178


I'm a llama!

[Code] Time Tag
« on: November 26, 2002, 01:26:36 PM »
Reply with quote

I'm too lazy to package this as a mod file, but I thought I'd share it in case others are interested.

On my boards I have users from around the world who like to schedule things to do in a game. The calendar was part of the solution, but still left some room for confusion regarding timezones.

I'd added a new board tag to my board called time which allows users to enter a time in their local time, to schedule events, and when users read the message it gets converted to that user's local time.

If you want a little better description of it, or to play around with it, you can here: Time Thread. Note that if you want to see what it actually looks like you'll need to make a member account since it cannot convert a guest to any local time format. I added a picture of what it does, since creating an account is probably a pain just to see it. If you want to play around with it, you'll still need an account, but here is what it does basically:



This should probably be considered BETA as well. I have it up and running and it appears to be working right, but until it's had a pretty heavy usage I won't know for sure....

To add the tag:

In Subs.php find the function doparsecodesmilies. At the end of this function, just before the return $message; add the following:
   $nUserOffset = (isset($settings[18]) ? $settings[18] : 0);
   while (preg_match("/\[time\](.+?)\[\/time\]/i", $message, $matches))
   {
      $searchfor = $matches[1];

      if ($ID_MEMBER != -1)
      {
         // Only members get a time translation.
         $nTime = strtotime($searchfor) + (($timeoffset+$nUserOffset)*3600);
         $sTimeResult = strftime("%a, %b %d at %I:%M %p (Local Time)",$nTime);
         $message = str_replace("[time]".$searchfor."[/time]",$sTimeResult,$message);
      }
      else
         $message = str_replace("[time]".$searchfor."[/time]",$searchfor,$message);

   }

In that same function, at the very top, right under the existing global statment, add this line:
   global $timeoffset,$settings,$ID_MEMBER;

That's all that is needed for the tag to work. If you want to add the time tag to the posting form, you can do the following....

Here is an image for the button, stick it in your images directory:

Load up Post.php and search for javascript:bold(). That's the start of a ridiculously huge line. Add to the end of that line, but right before the <br> the following:
<a href="javascript:timetag()"><img src="$imagesdir/time.gif" align=bottom width=23 height=22 alt="Time" border=0></a>
Now load up ubbc.js and add to the end of the file:
function timetag() {
   AddTxt="[time][/time]";
   AddText(AddTxt);
}

That's it.
« Last Edit: November 26, 2002, 01:49:08 PM by Myiasis » Logged
hankblack
Guest
Re:[Code] Time Tag
« Reply #1 on: November 30, 2002, 04:22:51 PM »
Reply with quote

This could be really handy for scheduling chat times, too. I'll check it out.
Logged
bananaman
Noobie
*
Posts: 34


No ordinary superhero!

WWW
Re:[Code] Time Tag
« Reply #2 on: January 01, 2003, 12:40:25 PM »
Reply with quote

Wow! This is an EXCELLENT Mod! Nemsis should add it to the list of BETA mods - took me ages to find this topic!

Anyway, I have a simple change to further enhance this mod.

Instead of the line
$sTimeResult = strftime("%a, %b %d at %I:%M %p (Local Time)",$nTime);
Which will ALWAYS show the converted time in the format %a, %b %d at %I:%M %p you can actually use the users prefered date/time format from their profile. eg as DD/MM/YYYY or MM/DD/YYYY, with or without the am/pm indicator, etc, however the user has set it up.

Replace the above code with
$sTimeResult = timeformat (strtotime($searchfor)) . " (Local Time)";
Now each user sees the converted time in their preferred format. (or default format if profile is empty).


One last enhancement would be to omit any of the date formating if the time to be converted doesn't include a date. eg "Lets all meet up at 10 pm est instead." Would be nice shown as "Lets all meet up at 03:00 GMT (local time) instead." At the moment the current date is prefixed to the time during the conversion.

I think this could be done by looking at the length of the string to be converted, but thats bit of a rough hack.

I'll look into this, but if anyone else has any ideas, let us know!
« Last Edit: January 01, 2003, 01:03:01 PM by bananaman » Logged

http://wolfensteinresource.com for all your Wolfenstein needs!
bananaman
Noobie
*
Posts: 34


No ordinary superhero!

WWW
Re:[Code] Time Tag
« Reply #3 on: January 01, 2003, 01:01:40 PM »
Reply with quote

I added bold tags to the converted time and moved it to the top of the doparsecodesmilies instead of the bottom so that my subs.php now looks like:

function doparsecodesmilies($message,$enableSmilies = 1) {

   global $codefromcache, $codetocache, $smileyfromcache, $smileytocache, $text, $scripturl,$imagesdir,$txt;
   global $timeoffset,$settings,$ID_MEMBER;

   // Time Tag conversion to local time
   $nUserOffset = (isset($settings[18]) ? $settings[18] : 0);
   while (preg_match("/\[time\](.+?)\[\/time\]/i", $message, $matches))
   {
      $searchfor = $matches[1];

      if ($ID_MEMBER != -1)
      {
         // Only members get a time translation.
         // $nTime = strtotime($searchfor) + (($timeoffset+$nUserOffset)*3600);
         // $sTimeResult = strftime("%a, %b %d at %I:%M %p (Local Time)",$nTime);
       $sTimeResult = "[b]" . timeformat (strtotime($searchfor)) . " (Local Time)[/b]";
         $message = str_replace("[time]".$searchfor."[/time]",$sTimeResult,$message);
      }
      else
         $message = str_replace("[time]".$searchfor."[/time]",$searchfor,$message);
      }
   // end time tag conversion

   if(gettype($codefromcache) != "array" || gettype($smileyfromcache) != "array") {

The converted times are now automatically shown in bold, to help users know they have been converted.
« Last Edit: January 01, 2003, 01:05:14 PM by bananaman » Logged

http://wolfensteinresource.com for all your Wolfenstein needs!
Pages: [1] Reply Ignore Print 
YaBB SE Community  |  Development  |  Completed mods  |  [Code] Time Tag « previous - next »
 


Powered by MySQL Powered by PHP YaBB SE Community | Powered by YaBB SE
© 2001-2003, YaBB SE Dev Team. All Rights Reserved.
SMF 2.1.4 © 2023, Simple Machines
Valid XHTML 1.0! Valid CSS

Page created in 0.014 seconds with 19 queries.