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: 629
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 0
  • Guests: 550
  • Total: 550

SMF Calendar Block

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

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

sdl

Quote from: crip on April 18, 2006, 01:17:17 PM
How to put [Sunday] begining on <-- left?

Scroll up Crip, bluesteel gave the answer:

Quotelol change $first_day = 1; to = 0 not 1 .. then sunday is the first day of the week (on the left)

Kaye, thanks for that tip about centering the table. Works perfectly. I set up an examples site so that I could experiment without screwing with my other forums - the final result is there.

Click here to see my test forum.  There's a random flash clock that I also use (now above the calendar) and a thread there on how to use it, for anyone interested.

elpvn

Your knowledge about PHP is very good, Kaye & sdl
Glad to meet you  :)

Crip

Thanks sdl, ;D
i downloaded your FlashClocks. ;)
I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes



dkaye315

Hey crip ... here's the code I was able to successfully integrate into a php-block (originally posted by Roarin):


global $scripturl, $modSettings, $sourcedir;

$now = mktime() + $modSettings['time_offset'] * 3600;
         $today = date('j',$now);
         $year = date("Y",$now);
         $month = date("n",$now);
         $days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

         $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 align="center" valign="top">'."\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=\"smalltext\" style=\"padding-right:4px;\"><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>';

if (ssi_todaysBirthdays('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Birthdays</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysBirthdays();
  echo '</td></tr>';
}

if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Upcoming Events</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysCalendar();
  echo '</td></tr>';
}

echo '</table>';

elpvn

Really good, I've put it to my TP now  :)
Thanks

Crip

I have become comfortably numb!

Cripzone | Crip's Free 2.0.2 Themes



thoraxe

Kaye,

I've used your code and it's awesome... However I have some comments/questions:

1) I see "Upcoming Events" twice.  Once comes from your code directly:
if (ssi_todaysCalendar('')) {
  echo '<tr><td><hr></td><td colspan="5" class="smalltext" align="center">Upcoming Events</td><td><hr></td></tr><td colspan="7" class="smalltext">';
  ssi_todaysCalendar();
  echo '</td></tr>';
}


But it also appears that the ssi_todaysCalendar(); is generating it as well.  Is there a way to maybe change that?

2) I changed the period that it checks for events to 60 days, and now it's also listing tons of holidays, too.  Is it possible to make it not list holdays?

3) The formatting of the upcoming events is essentially comma delimited... What I'd really like is for the events to be separated by
... that would be aesome!

My site test bed --> http://www.dgtrials.com/tinyportal/forum/index.php

thoraxe

Well.. I half answered my own question.  I created this function, because I didn't know what other implications modifying the original in SSI.php would do:

function ssi_todaysCalendar2($output_method = 'echo')
{
global $context, $modSettings, $txt, $scripturl;

if (!smf_loadCalendarInfo())
return array();

if ($output_method != 'echo')
return array(
'birthdays' => $context['calendar_birthdays'],
'holidays' => $context['calendar_holidays'],
'events' => $context['calendar_events']
);

if (!empty($context['calendar_events']))
{
echo '
<span style="color: #' . $modSettings['cal_eventcolor'] . ';">' . $txt['calendar4b'] . '</span> ';
echo '<br>';
foreach ($context['calendar_events'] as $event)
{
if ($event['can_edit'])
echo '
<a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';
echo '
' . $event['link'] . (!$event['is_last'] ? '<br> ' : '');
}
}
}


You can view it in action here:
http://www.dgtrials.com/tinyportal/forum/index.php

Please excuse the colors -- I'm in the middle of developing the theme to match the DGTrials homepage.

So now it more or less does what I want it to do...

Is there a way to override the ssi_todaysCalendar only inside our little php block?

dkaye315

Quote from: thoraxe on May 03, 2006, 08:45:13 PM
Kaye,

I've used your code and it's awesome... However I have some comments/questions:

All the credit for this code goes to those that came before me, including Bloc, and Roarin - I just reposted what had previously been created for us, and made a simple modification. ;)

myndcraft

I haven't used this yet, but it looks great. Rather then integrating with the forum calendar, is it possible to create a calendar event that links to some other page?

For example on the same site as my forums I run a Raid Scheduler for my world of warcraft guild

http://denovoforums.org/phpRaid/

It would be great to be able to create a raid there and link it to the phpCalendar on the portal (http://denovoforums.org)

This website is proudly hosted on Crocweb Cloud Website Hosting.