TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
  • Total Members: 3,963
  • Latest: BiZaJe
Stats
  • Total Posts: 195,917
  • Total Topics: 21,308
  • Online today: 728
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 467
  • Total: 468
  • @rjen

SMF Calendar Block

Started by Lesmond, September 03, 2005, 11:30:42 AM

Previous topic - Next topic

0 Members and 4 Guests are viewing this topic.

bloc

Hm, not sure..but this snippet rely on SSI function, so it must be that one giving this result. What SMF version are you on?

jpark

SMF 1.1 RC2.. yes, i believe the ssi function is calling all three (birthdays, holidays, and events)?

True Knight

This is a great snippet...I like all the different versions. However, I would like to request one little tweak...and I just don't know how to do it.

In the calendars that list the Birthdays and Events they list as follows (example for July 4th):



-----Birthdays------
Dude12 (40)

------Events-------
Independence Day                   <----Holiday Listed
Upcoming Birthdays:                 <----Birthdays
Dude12 (40)
Upcoming Events:                    <----Events
*Special Day




Is there anyway to make it list as follows?:



-----Today's Birthdays------    <----I know how to edit this!
Dude12 (40)

------Today's Events-------    <----I know how to edit this!
Independence Day                    <----Holiday
Events:*Special Day                   <----I want the Event listed without "Upcoming" listed




I don't want the birthdays listed in the "events" area and I don't want the events to be preceeded with "Upcoming." I only set my calendar to list "1" day of events!


How can I do this??

Thanks!

Xarcell

This has been mentioned several times. It's something that has popped up since RC1 I believe

True Knight

#124
I finally came up with a solution!  ;D

I finally found out how to divide up the events from birthdays and holidays so that it displays like this...

_______________
Holiday
Independence Day
_______________
Special Events Today
Fireworks Display
_______________
Birthdays Today
JimDawg (19), Terria67 (27), Bubbaduck (62)


Here is my revised code:

global $scripturl, $modSettings;

         $now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $days = array($today=>array(NULL,NULL,'<span class="smalltext" style="color: blue; font-weight: bold; border: solid 0px black; background-color: #ffffd0; padding: 0px 4px 0px 4px;">'.$today.'</span>'));
         $year = date("Y",$now);
         $month = date("n",$now);

         $day_name_length = 3;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);
#remember that mktime will automatically correct if invalid dates are entered
# for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
# this provides a built in "rounding" feature to generate_calendar()

$day_names = array(); #generate all the day names according to the current locale
for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
$day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name

list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #note that some locales don't capitalize month and day names

#Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03
@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</caption>\n<tr>";

if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
#if day_name_length is >3, the full name of the day will be printed
foreach($day_names as $d)
$calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
            $calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
if(isset($days[$day]) and is_array($days[$day])){
@list($link, $classes, $content) = $days[$day];
if(is_null($content))  $content  = $day;
$calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
}
else
{
$calendar .= "<td style=\"padding-right: 4px; font-size: xx-small; font-family: verdana, sans-serif;\"  onmouseover=\"this.style.backgroundColor='#C0B188'\" onMouseOut=\"this.style.backgroundColor=''\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
} if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

#create notice for Holidays, Events & Birthdays.

if (ssi_todaysHolidays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_holidaycolor'] . ';"><b>Holiday Today</b></td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysHolidays();
  echo '</td></tr>';
}


if (ssi_todaysEvents('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_eventcolor'] . ';"><b>Special Events Today</b></td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysEvents();
  echo '</td></tr>';
}

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_bdaycolor'] . ';"><b>Birthdays Today</b></td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

echo '</table>';

Ray


iwyen

Thanks True Knight and all. Got it working :)

How do I add a link to allow posting new events for "today"?

Xarcell

#127
@ True Knight

Why did you use "' . $modSettings['cal_eventcolor'] . '" for color? I didn't see anywhere in SMF where you can edit that color. It's also not in the style.css.

Also, I hacked it a bit. Made it more flexiable when changing themes and added tablecell high-lighting. It's also identical in FF & IE now. Has proper border around current day. I reduced the letters of the day of week to 2, so that it fits snug into TP default sidebar width(170px).

* If you want to remove tablecell hight-light, just remove red code: onmouseover="this.className=\'windowbg3\'" onmouseout="this.className = \'windowbg\'"

* If you want to change the color of highlight edit red to class in style.css: onmouseover="this.className=\'windowbg3\'" onmouseout="this.className = \'windowbg\'">

* If you want to add more letters to day of week edit red: $day_name_length = 2;

global $scripturl, $modSettings;

         $now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $days = array($today=>array(NULL,NULL,'<span class="windowbg3" style="color: black; font-weight: normal; font-size: x-small; border: solid 1px black; padding: 0px 4px 0px 4px;">'.$today.'</span>'));
         $year = date("Y",$now);
         $month = date("n",$now);

         $day_name_length = 2;
         $month_href = $scripturl . '?action=calendar';
         $first_day = 0;
         $pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);
#remember that mktime will automatically correct if invalid dates are entered
# for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
# this provides a built in "rounding" feature to generate_calendar()

$day_names = array(); #generate all the day names according to the current locale
for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
$day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name

list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;  #note that some locales don't capitalize month and day names

#Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03
@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'."\n".
'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n."</caption>\n<tr>";

if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
#if day_name_length is >3, the full name of the day will be printed
foreach($day_names as $d)
$calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
            $calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday   = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
if(isset($days[$day]) and is_array($days[$day])){
@list($link, $classes, $content) = $days[$day];
if(is_null($content))  $content  = $day;
$calendar .= '<td'.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
}
else
{
$calendar .= "<td class=\"windowbg\" style=\"padding-right: 4px; font-size: xx-small; font-family: verdana, sans-serif;\"  onmouseover=\"this.className='windowbg3'\" onmouseout=\"this.className = 'windowbg'\"><a";
if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= " href=\"".$scripturl."?action=calendar;sa=post;month=".$month.";year=".$year.";day=".$day."\" target=\"_self\">$day</a></td>";
}
} if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';

#create notice for Holidays, Events & Birthdays.

if (ssi_todaysHolidays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_holidaycolor'] . ';"><b>Holiday Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg" onmouseover="this.className=\'windowbg3\'" onmouseout="this.className = \'windowbg\'"><span class="smalltext">';
  ssi_todaysHolidays();
  echo '</span></td></tr>';
}


if (ssi_todaysEvents('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_eventcolor'] . ';"><b>Special Events Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg" onmouseover="this.className=\'windowbg3\'" onmouseout="this.className = \'windowbg\'"><span class="smalltext">';
  ssi_todaysEvents();
  echo '</span></td></tr>';
}

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center" style="color: #' . $modSettings['cal_bdaycolor'] . ';"><b>Birthdays Today</b></td><td><hr></td></tr><td colspan="7" class="windowbg" onmouseover="this.className=\'windowbg3\'" onmouseout="this.className = \'windowbg\'"><span class="smalltext">';
  ssi_todaysBirthdays();
  echo '</span></td></tr>';
}

echo '</table>';

Xarcell

I'll do one that's even prettier later on, but it'll require added some classes to style.css.

RoarinRow

Very cool enhancements  :up:

SMF 2.0 RC3
TP 1.0 beta 5-1
Wordpress 3.0

This website is proudly hosted on Crocweb Cloud Website Hosting.