News:

Wondering if this will always be free?  See why free is better.

Main Menu

Anniversary Mod

Started by Triumvirate, November 04, 2006, 09:30:00 AM

Previous topic - Next topic

Triumvirate

I searched for this but haven't seen anything so if it does exist I apologize.  Essentially this mod would display on the calendar and on the frontpage (under events or birthdays or something) members whose board "anniversary" is that day, i.e. they have been signed up for your forum for 1/2/X full year(s). 

There are of course a ton of other features to customize who shows up and how that could be done, but that's the basics of it.

If it doesn't exist I suppose I can always sit down and write it up myself if no one else already has it or is doing it.
MMO Gaming [nofollow]

JPDeni

I wrote a little function that has holiday greetings and birthday greetings and even time of day greetings. I added your anniversary idea to it as well. It prints out icons if you want them and you can have different holidays for different countries, if you have one of the country mods installed. Here's what I did:

First, I created a file called Greetings.english.php:
<?php

$txt
['generic'] = 'Hey there';

$txt['birthday']['all'] = 'Happy birthday';
$txt['img']['birthday']['all'] = 'bday.gif';
$txt['anniversary']['all'] = 'Happy Anniversary'// you might want to put your forum name in here
$txt['img']['anniversary']['all'] = 'bday.gif';

$txt['halloween']['all'] = 'Happy Halloween';
$txt['img']['halloween']['all'] = 'pumpkin.gif';
$txt['christmasday']['all'] = 'Merry Christmas';
$txt['christmasday']['uk'] = 'Happy Christmas';
$txt['img']['christmasday']['all'] = 'tree.gif';
$txt['thanksgivingus']['us'] = 'Happy Thanksgiving';
$txt['thanksgivingcanada']['ca'] = 'Happy Thanksgiving';

$txt['hour'][0]='Hi';
$txt['hour'][1]='Hi';
$txt['hour'][2]='Hi';
$txt['hour'][3]='Hi';
$txt['hour'][4]='Hi';
$txt['hour'][5]='Hi';
$txt['hour'][6]='Good morning';
$txt['img']['hour'][6]='sunrise.gif';
$txt['hour'][7]='Good morning';
$txt['hour'][8]='Good morning';
$txt['hour'][9]='Good morning';
$txt['hour'][10]='Good morning';
$txt['hour'][11]='Good morning';
$txt['hour'][12]='Good afternoon';
$txt['hour'][13]='Good afternoon';
$txt['hour'][14]='Good afternoon';
$txt['hour'][15]='Good afternoon';
$txt['hour'][16]='Good afternoon';
$txt['hour'][17]='Good afternoon';
$txt['hour'][18]='Good evening';
$txt['hour'][19]='Good evening';
$txt['hour'][20]='Good evening';
$txt['hour'][21]='Good evening';
$txt['hour'][22]='Good evening';
$txt['hour'][23]='Good evening';


?>


The images go into your smilies directory. If you have several smiley sets, you have to put them in each directory. The names of the holidays correspond to the title field in the calendar_holidays table, with all the letters in lowercase and all punctuation and spaces removed. Country-specific holidays use the two-letter country abbreviation that is in the country mods floating around here. If you don't want to use any country-specific holidays, set them all to ['all'] and you'll be fine.

Then, I created a file in the Sources directory called UserFunctions.php, which holds several functions that I have added.
<?php

function greeting()
{
  global 
$context$modSettings$user_settings$user_info,$options,$txt,$db_prefix;
  
$time time() + ($user_info['time_offset'] + $modSettings['time_offset']) * 3600;
  
$cur_date getdate($time);
  
$user_info['today_is_birthday'] = 0;
  
$image '';
  
$greeting '';
  isset(
$user_info['smiley_set']) ? $smiley $user_info['smiley_set'] : $smiley 'none';
  isset(
$options['country']) ? $country $options['country'] : $country 'all';
  
loadLanguage('Greetings');
  
$return '';
  
$greeting_array = array();

  if (isset(
$user_settings['birthdate']))
  {
    
$user_info['today_is_birthday'] = $cur_date['mon'] == substr($user_settings['birthdate'], 52) && $cur_date['mday'] == substr($user_settings['birthdate'], 8);
    if (
$user_info['today_is_birthday'])
    {
      if (isset(
$txt['birthday']['all']))
       
$greeting_array[] = 'birthday';
    }
  }
  
$today date('Y-m-d',$time);
  
$annual '0004-'.date('m-d',$time);
  
$query db_query(
      
"SELECT title
       FROM 
{$db_prefix}calendar_holidays
       WHERE eventDate = '
$today'
       OR eventDate = '
$annual'"__FILE____LINE__);
  if (
mysql_num_rows($query))
  {
    while (
$row mysql_fetch_assoc($query))
    {
      
$holiday str_replace(' ','',strtolower(preg_replace('/[^A-Z^a-z^0-9]+/',' ',$row['title']))); 
      if (isset(
$txt[$holiday][$country]) || isset($txt[$holiday]['all'] ))
        
$greeting_array[] = $holiday;
    }
  }
  
mysql_free_result($query);
  
$id $context['user']['id'];
  
$query db_query(" SELECT dateRegistered
FROM 
{$db_prefix}members 
WHERE ID_MEMBER = 
$id
LIMIT 1"
__FILE____LINE__);
  
$row mysql_fetch_assoc($query);  
  
mysql_free_result($query);
  if (
date('d m',$row['dateRegistered']) == date('d m',time()))
  {
    if (isset(
$txt['anniversary']))
      
$greeting_array[] = 'anniversary';
  }
  if (
array_key_exists('0',$greeting_array))
  {
    
shuffle($greeting_array);
    if (isset(
$txt[$greeting_array[0]][$country]))
      
$greeting $txt[$greeting_array[0]][$country];
    elseif (isset(
$txt[$greeting_array[0]]['all']))
      
$greeting $txt[$greeting_array[0]]['all'];
    if (
$greeting '')
    {
      if (isset(
$txt['img'][$greeting_array[0]][$country]))
        
$image $txt['img'][$greeting_array[0]][$country];
      elseif (isset(
$txt['img'][$greeting_array[0]]['all']))
        
$image $txt['img'][$greeting_array[0]]['all'];
    }
  }
  if (
$greeting == '')
  {
    
$hour $cur_date['hours'];
    if (isset(
$txt['hour'][$hour]))
    {
      
$greeting $txt['hour'][$hour];
      if (isset(
$txt['img']['hour'][$hour]))
        
$image $txt['img']['hour'][$hour];
    }
  }

  if (
$greeting == '')
  {
    
$greeting $txt['generic'];
    if (isset(
$txt['img']['generic']))
      
$image $txt['img']['generic'];
  }
  if (
$image <> '' && $smiley <> 'none')
    
$return '<img src="' $modSettings['smileys_url'] . '/' $smiley '/'.$image.'" alt="'.$greeting.'" border="0" /> ';
  
$return .= $greeting;
  return 
$return;
}


?>


It looks for the member's birthday, any holidays that have been defined in the language file and the member's anniversary. If there are more than one of them on a given day, it prints out a random one from the list. If there are none of them, it prints the greeting based on the time of day.

To use this, you need to add

require_once('UserFunctions.php');


somewhere before you want to print your greeting and then use

echo greeting();

to print it out.

I know this isn't exactly what you wanted, but it might do at least some of what you had in mind.

Triumvirate

Thanks this is actually a big help.  I'm sure I can tailor this a bit to better suit my needs perfectly, gave me a great starting point :)
MMO Gaming [nofollow]

JPDeni

Cool! I'm glad to help.

I'd love to see whatever tweaks you come up with. I'm always fiddling with my code.

salazarboy






houston

I seem to be getting a lot of these errors evertime a member goes to their PM section.

Undefined index: current_topic
File: /home/eaglebay/public_html/newforum/Themes/default/languages/Greetings.english.php (eval?)
Line: 302 and line 303

There is no code in line 302 or 303 in the mentioned php file. Any ideas where this error could be originating from.

Cheers

houston

Would it be possible to include a small sound clip to play as well .

JPDeni

QuoteUndefined index: current_topic
File: /home/eaglebay/public_html/newforum/Themes/default/languages/Greetings.english.php (eval?)
Line: 302 and line 303
That would be from something else. Find something that has "current_topic" in it. The file that shows in the error log is almost always not the one that's causing the problem.

QuoteWould it be possible to include a small sound clip to play as well .
Possibly. I don't know anything about making sounds play when a page opens, so I wouldn't know how to tell you to do it. I never use sounds because after the first 300 or so times of hearing the same thing, it gets annoying.  :)

houston

Quote from: JPDeni on November 21, 2006, 12:28:25 PM
QuoteUndefined index: current_topic
File: /home/eaglebay/public_html/newforum/Themes/default/languages/Greetings.english.php (eval?)
Line: 302 and line 303
That would be from something else. Find something that has "current_topic" in it. The file that shows in the error log is almost always not the one that's causing the problem.

QuoteWould it be possible to include a small sound clip to play as well .
Possibly. I don't know anything about making sounds play when a page opens, so I wouldn't know how to tell you to do it. I never use sounds because after the first 300 or so times of hearing the same thing, it gets annoying.  :)

Thank you for your prompt response. I will try to track down the error by other means. As to the sound clip insertion. I agree with you about the sounds getting annoying after a while. I think that I will drop that idea.

Cheers

Advertisement: