I found this little bloc on a site, you can set a greeting message to display based on the time of day it is.
--------------------------------------------------------
<?php
$hour = date('G');
if($hour >= 0 && $hour <= 7)
{
echo 'Very early, isnt it?';
}
else if($hour <= 8 && $hour <= 12)
{
echo 'Good morning!';
}
else if($hour >= 13 && $hour <= 16)
{
echo 'Good afternoon!';
}
else if($hour >= 17 && $hour <= 23)
{
echo 'Good evening!';
}
?>
Cool..
been around awhile, used that years ago. ;)
found it kinda neat, and since I know nothing of coding, figure I stick whatever I find up for others...if its something old. I'm sorry its new to me :)
That was a rather fun snippet :)
Thanks for sharing your findings :)
Thanks for sharing. I appreciate any kind of snippet since I'm not a coder by any means. :uglystupid2:
Quote from: rjackson on April 22, 2006, 03:33:19 PM
found it kinda neat, and since I know nothing of coding, figure I stick whatever I find up for others...if its something old. I'm sorry its new to me :)
It is an old one, but I stil see it being used all over the net, so thanks for sharing the snippet. :)
Is there a way to add this to the User info block? Instead of it saying "Hey user" say Good morning User????
I put this code into a block and added the {$MemberName} code but I cannot get it to work. I've made sure it was a php block, I've not deleted anything but I cannot for the life of me understand why it will not work. Does someone have a quick answer they could give me?
Quote from: rjackson on April 22, 2006, 03:33:19 PM
found it kinda neat, and since I know nothing of coding, figure I stick whatever I find up for others...if its something old. I'm sorry its new to me :)
Thanks, all the code anyone can give me is great, as I know little of code myself. New or old.
Quote from: sburke930 on August 13, 2006, 11:05:09 PM
I put this code into a block and added the {$MemberName} code but I cannot get it to work. I've made sure it was a php block, I've not deleted anything but I cannot for the life of me understand why it will not work. Does someone have a quick answer they could give me?
First you need to define the variable you need access to as a global, then you can use it. To do what you want, add this to the top of your snippet block:
global $user_info;Then, you can add to the greetings at the end of the echo statement like thus:
echo 'Good evening ' . $user_info['username'] . '!';That would produce the output with the user's username like:
Good evening Thurnok!
I am still not able to get this block working and for the life of me I cannot figure this out. I have it set as a phpbox, and all I get is a parse error on line 1. Help, please, someone....Thank you!
<?php
global $user_info;
$hour = date('G');
if($hour >= 0 && $hour <= 5)
{
echo 'You are up early' . $user_info['username'] . '!';
}
else if($hour >= 6 && $hour <= 8)
{
echo 'Grab your coffee yet' . $user_info['username'] . '!';
}
else if($hour <= 9 && $hour <= 12)
{
echo 'Good morning' . $user_info['username'] . '!';
}
else if($hour >= 13 && $hour <= 16)
{
echo 'Good afternoon' . $user_info['username'] . '!';
}
else if($hour >= 17 && $hour <= 23)
{
echo 'Good evening' . $user_info['username'] . '!';
}
?>
Don't use the
<?php
and
?>
in a php box.
OMG...thank you so very very much...I am ecstatic...this block has been bugging me since yesterday morning!
~Play~
:) Glad I could help. It's one of those things that is right there in front of you, but if you don't know about it, you'll never figure it out.
One other little thing you can do, if you want it to reflect the time of day for the user instead of wherever your server is ...
Instead of
$hour = date('G');
use
$hour = date('G') + $user_info['time_offset'];
if ($hour > 23) { $hour = $hour - 24; }
elseif ($hour < 0) { $hour = $hour + 24; }
ok, how do you get this to center inside a block? i am using it inside of a center block, and i want it to be centered within that block rather then set to the left.
After the $hour definition line (whether you have it use the server time or the user's local time) add
echo '<center>';
After the last } add
echo '</center>';
Or, you can use
echo '<span style="text-align:center;">';
and
echo '</span>';
Use whichever flavor you prefer.
perfect! thanks! :up:
Wow so cool...Now I know how to change the font size and color too which was my next question. Thank you very much for the help. It is totally appreciated!
You're very welcome. Those <span> tags come in really handy, and are a nice way to ease into using css. :)
Houston I have a problem. the bloc was working perfectly until today. We installed the karma moed and now I cannot get the block to work at all. It's just a blank box now. any suggestions besides the obvious?
$hour = date('G') + $user_info['time_offset'];
if ($hour > 23) { $hour = $hour - 24; }
elseif ($hour < 0) { $hour = $hour + 24;
if($hour >= 0 && $hour <= 7)
{
echo 'Very early, isnt it,' . $user_info['username'] . '?';
}
else if($hour <= 8 && $hour <= 12)
{
echo 'Good morning,' . $user_info['username'] . '!';
}
else if($hour >= 13 && $hour <= 16)
{
echo 'Good afternoon,' . $user_info['username'] . '!';
}
else if($hour >= 17 && $hour <= 23)
{
echo 'Good evening,' . $user_info['username'] . '!';
}
Ain't working, this code.
You need to add global $user_info; at the beginning and a } at the end of line 3. You'll also want to add a space after each of your commas so that your text looks right. Here's the correct code, all put together:
global $user_info;
$hour = date('G') + $user_info['time_offset'];
if ($hour > 23) { $hour = $hour - 24; }
elseif ($hour < 0) { $hour = $hour + 24; }
if($hour >= 0 && $hour <= 7)
{
echo 'Very early, isnt it, ' . $user_info['username'] . '?';
}
else if($hour <= 8 && $hour <= 12)
{
echo 'Good morning, ' . $user_info['username'] . '!';
}
else if($hour >= 13 && $hour <= 16)
{
echo 'Good afternoon, ' . $user_info['username'] . '!';
}
else if($hour >= 17 && $hour <= 23)
{
echo 'Good evening, ' . $user_info['username'] . '!';
}
This was copied directly from a block on my site that works just fine. If it doesn't work on your system, you've probably got something else conflicting with it.
The above looks good.. thanks for the space after comma info. 8)
Great! Thanks. If only it looked like this to an admin:
Good morning, rctxtreme
PM: 1
Show unread
Show replies
Show own posts
Modules
Downloads
Tools
Upload file
Manage settings
Manage blocks
Manage articles
Manage Downloads
It can, but you have to edit the TPortalBlocks.template.php file.
Here's what I did. Down at the bottom of the file, I added
function greeting()
{
global $user_info;
$return = '';
$hour = date('G') + $user_info['time_offset'];
if ($hour > 23) { $hour = $hour - 24; }
elseif ($hour < 0) { $hour = $hour + 24; }
$name = $user_info['username'];
if($hour >= 0 && $hour <= 7)
{
$return = "Very early, isnt it, <b>$name</b>?";
}
else if($hour <= 8 && $hour <= 12)
{
$return = "Good morning, <b>$name</b>!";
}
else if($hour >= 13 && $hour <= 16)
{
$return = "Good afternoon, <b>$name</b>!";
}
else if($hour >= 17 && $hour <= 23)
{
$return = "Good evening, <b>$name</b>!";
}
return $return;
}
Then under function userbox(), find
echo '<span class="normaltext">
', $txt['hello_member'], ' <b>', $context['user']['name'], '</b></span>';
Change it to
echo '<span class="normaltext">
', greeting(), '</b></span>';
It works for me.
Seems to me that it doesn't contain the modules, tools sections. Does it? If it does perhaps you should show me an example
The userbox is what contains all the other stuff in the box.
Here's a screenshot of mine from this morning.
(I don't have the download module active, so that's not part of the box.)
Thanks!
Quote from: rjackson on April 22, 2006, 03:24:48 PM
I found this little bloc on a site, you can set a greeting message to display based on the time of day it is.
--------------------------------------------------------
<?php
$hour = date('G');
if($hour >= 0 && $hour <= 7)
{
echo 'Very early, isnt it?';
}
else if($hour <= 8 && $hour <= 12)
{
echo 'Good morning!';
}
else if($hour >= 13 && $hour <= 16)
{
echo 'Good afternoon!';
}
else if($hour >= 17 && $hour <= 23)
{
echo 'Good evening!';
}
?>
Hi sorry to sound silly but as im not clued up on adding blocks or anything to the front page. How do i add this?? Please excuse my ignorance.
Check out the Documentation about Blocks (http://www.tinyportal.net/index.php?board=118.0).
Hi thanks for the reply. The docs page offers examples but the links dont work??
Im struggling to get anything to appear :laugh:
Do you have TinyPortal installed? If not, install it before going any further.
Go to your admin interface. Look for a section labeled TinyPortal. Under that will be a link labeled Block Manager. Click it.
From there, you can create a new block. You'll want a php block. Paste the code into the block. Save it. Then, on the main list of blocks be sure to activate it -- click the green button by the block.
If you have problems with any of this, you can ask questions, but you will need to be specific with what you have done and what the problem is.
I can't seem to find the file...
"It can, but you have to edit the TPortalBlocks.template.php file."
Is it accessable from the Current Theme?
Thanks,
lOOmis
Quote from: JPDeni on March 06, 2008, 10:20:10 PM
Do you have TinyPortal installed? If not, install it before going any further.
Go to your admin interface. Look for a section labeled TinyPortal. Under that will be a link labeled Block Manager. Click it.
From there, you can create a new block. You'll want a php block. Paste the code into the block. Save it. Then, on the main list of blocks be sure to activate it -- click the green button by the block.
If you have problems with any of this, you can ask questions, but you will need to be specific with what you have done and what the problem is.
Thanks for your help, got it sorted!
lOOmis, what file are you talking about? You don't need to find a file to create a block. You just create it.
Bobbyplant, Cool!! :)
This is what I was asking about. Is it part of the Template CSS? I got the origianl code inserted into a php block. Worked great. I would like to add the code below.
Quote from: JPDeni on August 16, 2006, 11:55:33 PM
It can, but you have to edit the TPortalBlocks.template.php file.
Here's what I did. Down at the bottom of the file, I added
function greeting()
{
global $user_info;
$return = '';
$hour = date('G') + $user_info['time_offset'];
if ($hour > 23) { $hour = $hour - 24; }
elseif ($hour < 0) { $hour = $hour + 24; }
$name = $user_info['username'];
if($hour >= 0 && $hour <= 7)
{
$return = "Very early, isnt it, <b>$name</b>?";
}
else if($hour <= 8 && $hour <= 12)
{
$return = "Good morning, <b>$name</b>!";
}
else if($hour >= 13 && $hour <= 16)
{
$return = "Good afternoon, <b>$name</b>!";
}
else if($hour >= 17 && $hour <= 23)
{
$return = "Good evening, <b>$name</b>!";
}
return $return;
}
Then under function userbox(), find
echo '<span class="normaltext">
', $txt['hello_member'], ' <b>', $context['user']['name'], '</b></span>';
Change it to
echo '<span class="normaltext">
', greeting(), '</b></span>';
It works for me.
Cool!
Works great for us, thanks!
lOOmis, you'll have to edit the TPortalBlocks.template.php in a text editor.
OK, Thankyou. I was looking everywhere in the Admin Section to get to it....oh well. Not ready to tackle that.
Thanks again for the help.
lOOmis
JPDeni
Thanks, this is a neat and friendly piece of coding :)
Cool! I'm glad you like it. :D