- Выводит календарь на месяц
- Вызов: {{calendar [showyear=2006] [showmonth=11] [linktext=Link]}}
- Если параметр showyear и showmonth опущены или равны 0, то календарь будет показываться на текущий месяц
- linktext текст для создания динамических ссылок. Например: linktext=Link, тогда ссылка будет следующего формата: Link20061005
Прошу проверить код на оптимизацию, если кому интересно :)
In English:
- Shows calendar for a month.
- Run {{calendar [showyear=2006] [showmonth=11] [linktext=Link]}}
- If showyear & showmonth are absent or 0, then calendar show current month
- linktext used for generating links. Example linktext=Link, then link will generated with next format: Link20061005
If linktextwill absent then link will not generated.
<?php
$curDay=1;
$curtxtMonth=array(
1 => "January",
2 => "February",
3 => "March",
4 => "April",
5 => "May",
6 => "June",
7 => "July",
8 => "August",
9 => "September",
10 => "October",
11 => "November",
12 => "December");
$NOW = getdate(); // get the Current server date.
if ( $showmonth > 12 || $showmonth < 1 ) { $showmonth = 0; $showyear = 0; }
if ( $showmonth == 0 ) {
$curMonth = $NOW['mon'];
} else {
$curMonth = $showmonth;
}
if ( $showyear == 0 ) {
$curYear = $NOW['year'];
} else {
$curYear = $showyear;
}
$thisMonth = $curMonth;
$TempMonth = $NOW['month'];
$cellCount = 0;
echo "<table cellpadding=\"1\" cellspacing=\"1\" border=\"0\">";
echo "<tr>";
echo "<th colspan=\"7\">" . $curtxtMonth[$curMonth] . " - " . $curYear . "</th>";
echo "</tr>";
echo "<tr>";
echo "<th><strong>Mon </strong></th><th><strong>Tue </strong></th>";
echo "<th><strong>Wed </strong></th><th><strong>Thu </strong></th><th><strong>Fri </strong></th>";
echo "<th><strong>Sat </strong><th><strong>Sun </strong></th></th>";
echo "</tr>";
echo " <tr>";
while ( $curMonth == $thisMonth )
{
$thisMonth = date ( "m", mktime(23, 59, 59, $curMonth, $curDay, $curYear ) );
$totalDays = date ( "d", mktime ( 23, 59, 59, $curMonth, $curDay - 1, $curYear ) );
$curDay++;
}
$firstDayOfMonth = date ( "w",mktime ( 0, 0, 0, $curMonth, 1, $curYear ) );
if ( $firstDayOfMonth == 0 ) { $firstDayOfMonth = 7; }
for ( $cellCount=1; $cellCount <= $firstDayOfMonth - 1; $cellCount++ )
{
echo "<td> </td>\r";
}
for ($curDay = 1; $curDay <= $totalDays; $curDay++)
{
if ($cellCount == 1) { echo "<tr>\r"; }
$link = $this->UnwrapLink( $linktext . $curYear . ($curMonth<10?"0":"") . $curMonth . ($curDay<10?"0":"") . $curDay );
echo "<td align=center width=30>";
if ( $link && isset($linktext) && !empty($linktext) )
{
echo $this->Link("/" . $link, "", $curDay );
} else {
echo $curDay;
}
echo "</td>";
$cellCount++;
if ( $cellCount == 8 ) { echo "</tr>\r"; $cellCount=1;}
}
if ($cellCount > 0 && $cellCount < 8)
{
for ($i=$cellCount; $i<8; $i++)
{
echo "<td> </td>\r";
}
}
echo "</tr>\r";
echo "</table>";
?>