TinyPortal

Development => Block Codes => Topic started by: JPDeni on October 22, 2006, 11:48:25 PM

Title: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on October 22, 2006, 11:48:25 PM
This isn't a code snippet to go into a block, but rather is a new function that you can use in any of your php blocks or articles or even if you alter the template files.

It returns a greeting to the person, which is one of the following:
"Happy birthday" if it's the person's birthday
a holiday greeting if it's a holiday
a welcome message if it's the member's first day on the site
an anniversary message if it's the anniversary of the member first registering
a time of day greeting if it's just a regular day
a generic greeting that should never be seen, but I added it just in case.  :)

You can have images with the greetings and you can even customize your greetings to the member's country, so that only Americans are wished a "Happy Fourth of July," for example, and Canadians can get Thanksgiving wishes on their Thanksgiving day in October, while Americans will get their greetings in November. (Sorry to be ethno-centric, but I'm not familiar enough with the specific holidays in other countries to be able to give other examples.)

There are several parts to this, but they're pretty straightforward.

Step one:
Copy the following into a new file and save the file as UserFunctions.php. This will go in your Sources directory.

<?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 (
date('Y',$row['dateRegistered']) == date('Y',time()))
    {
      if (isset(
$txt['firstday']))
        
$greeting_array[] = 'firstday';
    }
    elseif (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;
}

?>



Step Two:
Create another new file, with the following, and save it as Greetings.english.php. You can also translate the file into whatever other languages are appropriate for your site. All of them go into the default/languages directory.


<?php

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

$txt['birthday']['all'] = 'Happy birthday';
$txt['img']['birthday']['all'] = 'birthday.gif';
$txt['anniversary']['all'] = 'Happy Anniversary';
$txt['img']['anniversary']['all'] = 'birthday.gif';
$txt['firstday']['all'] = 'Welcome';
$txt['img']['firstday']['all'] = 'rose.gif';


$txt['christmasday']['all'] = 'Merry Christmas';
$txt['christmasday']['uk'] = 'Happy Christmas';
$txt['img']['christmasday']['all'] = 'xmastree.gif';
$txt['newyearsday']['all'] = 'Happy New Year';
$txt['thanksgivingus']['us'] = 'Happy Thanksgiving';
$txt['img']['thanksgivingus']['us'] = 'turkey.gif';
$txt['thanksgivingcanada']['ca'] = 'Happy Thanksgiving';
$txt['img']['thanksgivingcanada']['ca'] = 'turkey.gif';

$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';


?>




There are several things to notice here. To come up with the key value for the holiday text -- for example $txt['newyearsday']['all'] -- get the title value that's in the calendar and take out all spaces or punctuation and put the whole thing in lower case. So New Year's Day becomes newyearsday and Hallowe'en becomes halloween. If you have any other punctuation, take that out, too. You want to be left with just letters and numbers.

You don't have to put greetings in for every holiday on your calendar.

Most of the time, the second part of the key -- $txt['newyearsday']['all'] -- will be all. If you have a specific reason to limit it to only one country *and* you have a way for the members to define their country, you can use a country code instead. If you have the CountryFlag mod, you can use that. I intentionally used the same variable name.

Note that you can have one text for a specific country and another text for everyone else. In the case above, someone who is listed as being in the UK would see "Happy Christmas" on the 25th of December, but everyone else would see "Merry Christmas."

The other example is for Thanksgivings. The key values of ['thanksgivingus'] and ['thanksgivingcanada'] assume that there are entries in the holiday calendar like "Thanksgiving (US)" and "Thanksgiving (Canada)".

The names of the image files are identical to the names of the text files, except that the ['img']  is added as the first key. Again, you can have different image files for different countries. But just because you have a specific text for a given country doesn't mean you have to have a different image. In my Christmas example above, even though British folks would see different text, they would still see the same image. You don't have to have an image for every greeting.

You can even have different text and images for each hour of the day.

It doesn't matter what order the $txt array elements are in. I think it's easier to have the image references with the text so I don't get lost.

Step three:
Upload any graphics that you might have defined. They need to go into the smileys directories. If you have more than one set of smilies, you'll need to put your greeting graphics in all of them. I've attached the ones I referenced in my language file just so you have something to start with. These are from Mazeguy (http://www.mazeguy.net). I think it's preferable to have small graphics for these.

Step Four:
Use it!

In whatever place you want to add your greeting, whether it's in a block or an article or even one of the template files, first add

require_once['UserFunctions.php']

and in the exact place where you want your greeting to appear, use

greeting()

as if it were a variable. You can say something like

echo greeting(),', '.$context['user']['name'],'<br />';

which will give you something like
Happy birthday, Xarcell
or
Merry Christmas, G6
or
Good morning, Bloc
or whatever fits for the username and event.

I feel like I've probably over-explained this, so I'll just stop now and answer questions that others might have in case my explanation wasn't clear.

Edited to add:
I've done some editing of the code. Now it includes an "anniversary" day for the person's membership on the forum and if there is more than one event defined on a given day (holidays, birthday, anniversary), it prints out a random greeting each time the page is reloaded.
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: G6Cad on October 23, 2006, 07:55:51 AM
This was a fun thing to have JPDeni :)

Thank you for sharing :)

Think this goes better in Block code and snippets board to, so i move it there :)
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on October 23, 2006, 01:18:34 PM
That's fine. You're the organizer around here. ;D
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: akulion on October 23, 2006, 01:50:42 PM
nice :D thanks :up:

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi26.photobucket.com%2Falbums%2Fc147%2Fjbrowning%2Fchewy.gif&hash=4796439a333fc2cbf1f348b912f4e82ad440b08c)(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi26.photobucket.com%2Falbums%2Fc147%2Fjbrowning%2Fchewy.gif&hash=4796439a333fc2cbf1f348b912f4e82ad440b08c)

Great job

(https://www.tinyportal.net/proxy.php?request=http%3A%2F%2Fi2.photobucket.com%2Falbums%2Fy27%2Fb_ezee%2Fsmilies%2FFatGuy03.gif&hash=6b58801ba62917c5f87e80b4ea297cb8f9ffa1d9)
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: technodragon73 on October 23, 2006, 03:25:27 PM
ok, I have tried several ways to do this.  I keep getting unable to load UserFunctions.php.  I have tried chmodding it and I know the syntax is correct for calling it
require_once($sourcedir.'/UserFunctions.php');


any help trying to figure out where/why it doesn't want to work?
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on October 23, 2006, 03:40:23 PM
Just use

require_once('UserFunctions.php');

If it's in your Sources directory, the script will find it.
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: technodragon73 on October 23, 2006, 03:54:37 PM
thank you...that worked!

Though if I may offer a suggestion...

I noticed it worked better when i used ',greeting(),' instead.
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on October 23, 2006, 04:02:40 PM
Glad it worked. :)
Quote from: TechnoDragon on October 23, 2006, 03:54:37 PM
Though if I may offer a suggestion...

I noticed it worked better when i used ',greeting(),' instead.
I don't understand. What's your whole line of code?
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: technodragon73 on October 23, 2006, 04:09:27 PM

echo'
      <br />',greeting(),', <br />'.$context['user']['name'],'<br />';
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on October 23, 2006, 04:19:07 PM
Oh, yes. Since you already have something that's being echoed and you're having a linebreak before it. The code that I posted was straight out of a block that I made with my own userbox and it's the first line of the code, so I didn't have anything before the greeting. :)

I'm glad you mentioned that, though, because it puts it in a different context to help others understand how to use it.
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: technodragon73 on October 23, 2006, 04:36:24 PM
You're welcome...this is a much better version of a greeting than the one I had.  Originally I could greet users with the time of day, or on their birthday...but I love the fact that I can do the holidays now too!  Awesome job!
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on October 23, 2006, 04:42:22 PM
Thank you -- and thanks to Aku, too. ;D

It was one of those things that was running around in my brain for several days and wouldn't leave me alone until I wrote it.
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: houston on October 24, 2006, 12:59:31 AM
I seem to be getting this error

Fatal error: Call to undefined function: greeting() in /home/eaglebay/public_html/newforum/Sources/Load.php(1613) : eval()'d code on line 306


No matter where I put this echo'
      <br />',greeting(),', <br />'.$context['user']['name'],'<br />';
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: technodragon73 on October 24, 2006, 01:04:51 AM
did you upload the two files he had in the first post?  And did you add the require_once command as well?
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: houston on October 24, 2006, 01:33:37 AM
Quote from: TechnoDragon on October 24, 2006, 01:04:51 AM
did you upload the two files he had in the first post?  And did you add the require_once command as well?

All files uploaded. Must have missed the add the require_once command.

Thanks
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: houston on October 24, 2006, 01:54:50 AM
Quote from: TechnoDragon on October 24, 2006, 01:04:51 AM
did you add the require_once command as well?

That did not work either. I am try do place the greeting in the top area where it shows how log the member has been logged on for and the time of day. Using SMF1.1 rc2 and TP v0.96
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on October 24, 2006, 02:08:45 AM
Can you post the code you're trying to edit? I can show you were the "require_once" command goes.
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: houston on October 24, 2006, 02:38:02 AM
Quote from: JPDeni on October 24, 2006, 02:08:45 AM
Can you post the code you're trying to edit? I can show you were the "require_once" command goes.

Here it is // If the user is logged in, display stuff like their name, new messages, etc.
if ($context['user']['is_logged'])
{
echo '
<a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a> <br />
<a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a><br />';

}


This is from the default index.template.php file
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on October 24, 2006, 03:23:00 AM
Let me just double-check. Are you sure you put the UserFunctions.php file in the Sources directory?

I'm still not sure where exactly you want the greeting to go. My guess is that you want it here, instead of $txt['hello_member_ndt']:

// display user name
echo '
  <table width="100%" cellpadding="0" cellspacing="0" border="0" >
  <tr>';
  if($context['user']['is_logged'])
    echo '
      <td class="titlebg2" height="32">
          <span style="font-size: 130%;"> ', $txt['hello_member_ndt'], ' <b>', $context['user']['name'] , '</b></span>
       </td>';


So, this is what you would use:

// display user name
require_once('UserFunctions.php');
echo '
  <table width="100%" cellpadding="0" cellspacing="0" border="0" >
  <tr>';
  if($context['user']['is_logged'])
    echo '
      <td class="titlebg2" height="32">
          <span style="font-size: 130%;"> ', greeting(), ' <b>', $context['user']['name'] , '</b></span>
       </td>';

Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: houston on October 24, 2006, 03:49:50 AM
Quote from: JPDeni on October 24, 2006, 03:23:00 AM
Let me just double-check. Are you sure you put the UserFunctions.php file in the Sources directory?

I'm still not sure where exactly you want the greeting to go. My guess is that you want it here, instead of $txt['hello_member_ndt']:

// display user name
echo '
  <table width="100%" cellpadding="0" cellspacing="0" border="0" >
  <tr>';
  if($context['user']['is_logged'])
    echo '
      <td class="titlebg2" height="32">
          <span style="font-size: 130%;"> ', $txt['hello_member_ndt'], ' <b>', $context['user']['name'] , '</b></span>
       </td>';


So, this is what you would use:

// display user name
require_once('UserFunctions.php');
echo '
  <table width="100%" cellpadding="0" cellspacing="0" border="0" >
  <tr>';
  if($context['user']['is_logged'])
    echo '
      <td class="titlebg2" height="32">
          <span style="font-size: 130%;"> ', greeting(), ' <b>', $context['user']['name'] , '</b></span>
       </td>';



I will check again. Just about to read to my son so I will have to get back to this later.

Cheers
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: houston on October 24, 2006, 04:41:01 AM
 :up: Thanks JPdeni that was the ticket.

Cheers
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on October 24, 2006, 05:08:17 AM
Cool. ;D
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: technodragon73 on October 31, 2006, 01:56:43 PM
Ok, seeing as how it is halloween today (in the us) I have that as an extra holiday in the greetings file.  Now the problem I have is that the appropriate greeting is showing (Happy Halloween), but the image is not showing up...no error, no missing image box...nothing...did i miss something?
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on October 31, 2006, 03:07:27 PM
Do you have the image defined? You should have

$txt['img']['halloween']['all'] = 'pumpkin.gif';

(or something similar with the name of your image file) defined in your Greetings.english.php file. It's set up that way so that you don't have to have an image for every holiday if you don't want one.
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: technodragon73 on October 31, 2006, 03:34:48 PM
Yes I do actually...
Here is exactly what is in my greetings file:
$txt['halloween']['all'] = 'Happy Halloween';
$txt['img']['halloween']['all'] = 'pumpkin.gif';


and the image is in the smiley directory like the time of day ones and they work fine...btw the birthday one worked as well.
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on October 31, 2006, 03:42:13 PM
It would probably help if I had the code right.  :uglystupid2:

Change
 
      if ($greeting > '')
      {
        if (isset($img[$holiday][$country]))
          $image = $img[$holiday][$country];
        elseif (isset($img[$holiday]['all']))
          $image = $img[$holiday]['all'];
      }


to this

 
      if ($greeting > '')
      {
        if (isset($txt['img'][$holiday][$country]))
          $image = $txt['img'][$holiday][$country];
        elseif (isset($txt['img'][$holiday]['all']))
          $image = $txt['img'][$holiday]['all'];
      }


I'll go fix it in the original. Sorry 'bout that.
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: technodragon73 on October 31, 2006, 04:06:51 PM
Fixed it...thanks!
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on November 04, 2006, 06:59:52 PM
I've done a little editing of the code. It was bothering me that there might be days when there is more than one holiday or birthdays might fall on a holiday. So, in those instances, it prints out an appropriate random greeting each time the page is reloaded. It also includes code to wish a happy anniversary to members on the anniversary of their membership on the forum. It's conceivable that you could have two holidays, a birthday and an anniversary all on the same day, so each of the greetings for that person has a one in four chance of showing up each time the page is reloaded.

If you want to include the changes, you'll need to copy over the greetings function in its entirety. (The changes have been made to the code in the first post of this topic.) The only change you'll need to make to the Greetings.english.php file (or other language files you may have created) is to add the ['all'] key to the birthday text and image and to add text for the anniversary greeting, if you want to use it:

$txt['birthday']['all'] = 'Happy birthday';
$txt['img']['birthday']['all'] = 'bday.gif';
$txt['anniversary']['all'] = 'Happy Anniversary';
$txt['img']['anniversary']['all'] = 'bday.gif';


I'll likely come up with another tweak later on, too.   :)
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: technodragon73 on November 04, 2006, 07:06:58 PM
what is the code function then?
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on November 04, 2006, 07:12:04 PM
I don't understand.

The function that you have now needs to be replaced by the code which is now in the first message of this topic. I've edited that first message so that it has the latest code.
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: technodragon73 on November 04, 2006, 07:20:51 PM
ahhhh....didn't realize you modified the friest message

ROFL
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: tamasir on November 07, 2006, 02:09:47 PM
JPDeni!
Your  the demo ? I'd love to get your demo. ;)
tamasir~
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on November 07, 2006, 03:54:55 PM
You can go to my site (http://site.jpdeni.com) and see it in action. Since there's no holiday today, it won't show anything. I suppose you could sign up for an account and say that today was your birthday and you would get the birthday message.

Oh. That just occurred to me. I should have something different when people first sign up. Otherwise it will tell them "Happy Anniversary" on their first day.

Back to the drawing board. ....  :)
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on November 07, 2006, 04:36:48 PM
Okay. Minor edit.

In the greetings function, change


  if (date('d m',$row['dateRegistered']) == date('d m',time()))
  {
    if (isset($txt['anniversary']))
      $greeting_array[] = 'anniversary';
  }


to


  if (date('d m',$row['dateRegistered']) == date('d m',time()))
  {
    if (date('Y',$row['dateRegistered']) == date('Y',time()))
    {
      if (isset($txt['firstday']))
        $greeting_array[] = 'firstday';
    }
    elseif (isset($txt['anniversary']))
      $greeting_array[] = 'anniversary';
  }


and in the Greetings.english.php file, add

$txt['firstday']['all'] = 'Welcome ';
$txt['img']['firstday']['all'] = 'rose.gif';


Here's a rose to give your new members:
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: tamasir on November 07, 2006, 06:59:39 PM
JPDenis!
Thank your so very much! :up:
tamasir~
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: dy on November 16, 2006, 04:57:58 AM
Just wondering, once 'installed' into TP, I keep getting weird characters appearing in front of the picture and text, something like this:

ÃÆ'Ã,¯Ã‚Ã,»Ã‚Ã,¿ÃÆ'Ã,¯Ã‚Ã,»Ã‚Ã,¿ [[Picture Placeholder Here]] Good Afternoon
(Hopefully you can see it)

The picture (where the [[Picture Placeholder]] Is) and the text, appear correctly, but regardless of the 'event' whether it be a birthday or just good afternoon, these weird characters still appear.

I checked out all the code in the two files, and the code in my 'block', but I still don't know what's causing the problem. Any ideas??
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on November 16, 2006, 12:47:30 PM
Did you try taking out the greeting() command to see if it still happens with it?

There is nothing in the function that would print out those characters, or anything else, other than what you have defined in your $txt file. It must be something else.
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: dy on November 17, 2006, 12:08:49 AM
Quote from: JPDeni on November 16, 2006, 12:47:30 PM
Did you try taking out the greeting() command to see if it still happens with it?

There is nothing in the function that would print out those characters, or anything else, other than what you have defined in your $txt file. It must be something else.

I tried taking the greeting() command out, but the weird text is still there...


This is the code I'm using for the Portal Block:
require_once($sourcedir . 'UserFunctions.php');
echo '<span style="font-size: 8pt;"> ',greeting(),'<br /><b>'.$context['user']['name'],'</b></span><br />';



After taking the greeting() command out, the weird text still appears before the user's name.
It seems like it has something to do with combining the require_once() command and the echo() command.  If just reduce the code to this:
require_once($sourcedir . 'UserFunctions.php');
echo 'Hello';


Then it displays the weird text, then "Hello".


Just leaving this code in the Portal Block:
echo 'Hello';

It displays "Hello" fine.


I don't know whether it may be something to do with the UserFunctions.php file or some parsing error on TP. Please try your best to help me solve this problem.
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on November 17, 2006, 12:14:23 AM
Take out the $sourcedir thing. The command is

require_once('UserFunctions.php');

This is what works.

Also, I'm wondering what is before your require_command. Unless you have something else in the UserFunctions.php file, there's nothing in there that should be displaying anything but what was defined in your language file.
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: dy on November 17, 2006, 12:26:45 AM
Thanks for the quick response!!!  But it doesn't change anything at all when I take the $sourcedir out!

Before the require command? Nothing.  This code, is the only code that is sitting in the Portal Block:

require_once('UserFunctions.php');
echo '<span style="font-size: 8pt;"> ',greeting(),'<br /><b>'.$context['user']['name'],'</b></span><br />';


And I've taken exactly what was in the code for the UserFunctions.php, from your first post in this topic, no changes.  Deleting or adding lines in the Greetings.english.php file won't affect it would it? (Like deleting events you have put in which I don't have in my calendar - such as Thanksgiving)

Anyway, if you want a link to my forum, I'll PM it to you.
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on November 17, 2006, 12:42:56 AM
No, changing lines in the language file won't do anything. But there may be a problem with your block. You should have a global command.


global $context;

require_once('UserFunctions.php');
echo '<span style="font-size: 8pt;"> ',greeting(),'<br /><b>'.$context['user']['name'],'</b></span><br />';


If that doesn't fix things, PM me the link to your forum so I can take a look.
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: dy on November 17, 2006, 12:51:11 AM
Looks like it didn't work.  I'll make the block visible, and send a PM.
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: RoarinRow on November 17, 2006, 04:00:43 PM
Quote from: houston on October 24, 2006, 04:41:01 AM
:up: Thanks JPdeni that was the ticket.

Cheers

That worked for me too, thank you!   :up:
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: peeper on November 23, 2006, 07:06:01 AM
JP you are the Best!
::)
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: CampCounselor on January 09, 2007, 07:17:01 PM
I would like to show what time it is...how would i do this
If is it the users Birthday would it automatically say Happy Birthday [username] ?

thanks

mike
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: JPDeni on January 09, 2007, 11:14:04 PM
QuoteIf is it the users Birthday would it automatically say Happy Birthday [username] ?
That's what this code is for. Use the code in the first post of this topic and that's what you'll get.

QuoteI would like to show what time it is...how would i do this
You just want to say "It's now 3:14 PM?"
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: simpark77 on July 16, 2007, 12:47:52 AM
I know this post is old, but I'm new to TP.
I came across this block today and I thought it would be a great tool to offer my users.

I came across a small problem and was hoping someone could help me.

I added all the necessary codes and files and what happens is when i set my birthday to today
I get this message:  Happy birthday Happy birthday (name)

Seems like it says it twice.

I made it into a welcome phpbox on my left column.

Here is the code i put in:

global $user_info;

require_once('UserFunctions.php');
echo greeting(),', '.$context['user']['name'],'
';


Also I was a little confused when JP mentioned about going into my calendar and changing all the Holiday targets by removing the spaces. Does she mean that all the holidays I want showing can't have any spaces? For Example: Thanksgiving Day is the target, i have to change it to thanskgivingday ? Wouldn't this change the way the holiday appears in my calender?

thank you
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: osquitar on July 19, 2007, 07:52:28 PM
May you post the images?
Title: Re: Greetings: Birthday, Holiday, Time of Day
Post by: joybreezy on July 20, 2007, 11:29:04 PM
Hi all.. I uploaded it to just test it out and found by cycling through the posts I could fix some of my issues.  However I am trying to put the code in an article with a nice size font.  Currently using 16pt but it is cutting off some of the letters.. like "y"  any sugessions?