Revision [17853]

This is an old revision of DanWestCalendar made by DanWest on 2007-12-18 17:25:09.

 

Placeholder for Calendar Code.

Calendar Code Formatter

See Also
  • Future See Also Link..

What

Installation

Usage
%%(cal)
Jan 2008
1;%holiday% New Years
15;Joes Birthday
%%



File: formatters/cal.php
<?php
// Convert code segment into calendar
// Build a calendar array
$cal_month = '';
$cal_days = 0;
$cal_start = 0;
$cal_info = array();

// 1st line = (month year)
// ex: January 2008 or Jan 2008
$cal_firstline=0;
foreach(split("\n", $text) as $csv_n => $csv_line){
        if(preg_match("/^#|^\s*$/",$csv_line)) continue;
        if( $cal_firstline == 0){    
            preg_match("/^([^;]*);*(.*)/",$csv_line,$matches);
    // Make it the 1st of the month
            $cal_month = '1 ' . $matches[1];

    // Get timestamp for 1st of month. Then extract values
    $cal_date = strtotime($cal_month);  // Convert to 1st of month
            $cal_start = strftime("%w",$cal_date);
           
    // Calculate end of month (1st of month +1 month -1 day) = End of month = Number of days in month
    $cal_eom = $cal_month . ' +1 month -1 day';
            $cal_date = strtotime($cal_eom);
            $cal_days = strftime("%d",$cal_date);
            $cal_firstline=1;

            // Fill up cal_day array with full month of data
            for($day=1;$day <= $cal_days;$day++) {
                $cal_data[$day] = '&nbsp;';
            }
            continue;
        }
       
        $wrk = $csv_line;
        while ($m = preg_match('/^([0-9]+);(.*)/',$wrk,$matches)) {
                $cal_day = $matches[1];
                $wrk = $matches[2];
                $cal_data[$cal_day] = $wrk;
        }
}
echo "<table class='cal'>";
echo "<tr class='head'><th width=13%>Sun</th><th width=13%>Mon</th><th width=13%>Tue</th>";
echo "<th width=13%>Wed</th><th width=13%>Thu</th><th width=13%>Fri</th><th width=13%>Sat</th></tr>\n";

// Create a COLSPAN until the 1st day of month
if(!$cal_start) {
    echo "<tr>";
    $dow = 0;
} else {
    echo "<tr><td colspan='$cal_start' class='dim'>&nbsp;</td>";
    $dow = $cal_start;
}

// Dump out the calendar
foreach($cal_data as $c_day=>$c_data) {
    $c_class = '';
    if(preg_match('/^%([^%]+)%(.*)/',$c_data,$matches)) {
        $c_class = $matches[1];
        $c_data = $matches[2];
    }
    if($dow == 7) {
        echo "</tr>\n<tr class='even'>";
        $dow=0;
        echo "<td class='$c_class'><span class='sun'>" . $c_day . '</span> ';
    } else {
        echo "<td class='$c_class'><span class='day'>" . $c_day . '</span> ';
    }
    echo $this->format($c_data);
    echo '</td>';
    $dow++;
}
// Colspan for rest of week
if($dow<7) {
    echo "<td class='dim' colspan='" . (7-$dow) . "'>&nbsp;</td>";
}
echo "</tr></table>\n";
?>


It also requires a small addition to the CSS file (Taken from .code selector)

/* Calendar Table (DW) */
table.cal {
padding: 0 0 0 0;
border: 1px solid #888;
width: 99%;
text-align: left;
color: black;
background-color: #FFF;
border-collapse: collapse;
}

.cal tr.head {
background-color: #FFFFCF;
font: 10pt sans-serif;
color: blue;
border-bottom: 1px dotted #888;
vertical-align: top;
}

.cal tr {
background-color: #F9FFFF;
border-bottom: 1px dotted #888;
vertical-align: top;
}

.cal th {
padding: 4px 0 8px 4px;
border-bottom: 1px solid #000;
text-align: center;
}

.cal td {
font: 9pt sans-serif;
vertical-align: top;
border-bottom: 1px dotted #888;
border-right: 1px dotted #888;
padding: 4px 0 2px 8px;
height: 90px;
}


.cal td.dim {
background-color: #EEE;
}

.cal td.green,.high {
background-color: #ccffcc;
}

.cal td.red {
background-color: #FDE3E3;
}

.cal td.holiday {
xbackground-color: #F8F8F8;
}

.cal td.blue {
background-color: #DFDFFD;
}

.cal td a {
    color: blue;
}

.cal td span.day {
    font-weight: bold;
}

.cal td.holiday span.day {
    font-weight: bold;
    color: red;
}

.cal td span.sun {
    font-weight: bold;
    color: red;
}



To Do


CategoryUserContributions
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki