<?php
/*
This plugin displays a calender view of the current month. Days with entries will be linked! Have fun and visit my Website http://schrempfy.de
*/
//main configuration
$plugin_name = "calender"; // note: this should be the same name as the name of the plugin-folder (lowercase)
$plugin_author = "<a href='http://schrempfy.de' target='_blank'>Schrempfy.de</a>";
$plugin_description = "This plugin displays a calender view of the current month. Days with entries will be linked! Have fun and visit my Website: <a href=\"http://schrempfy.de\" target=\"_blank\">Http://Schrempfy.de</a>";
$plugin_version = "1.0";
if($hook == 'blogmenu'){
function makeLink($id,$tag) {
$day = "".$tag."";
if(ROOT){
$link = "<a href=\"".ROOT."posts/".$id."\">".$day."</a>";
}
else
{
$link = "<a href=\"?content=detail&id=".$id."\">".$day."</a>";
}
return $link;
}
function displayCalender($spacer){
global $prefix;
// At first we need the colors :>
$sql = "SELECT * FROM $prefix" . "_calender";
$qry = mysql_query($sql) or die('Calender having problems. Contact Schrempfy.de');
while($col = mysql_fetch_object($qry)) {
$defaultfontcolor = "#".$col->font;
$defaultbgcolor = "#".$col->back;
$todayfontcolor = "#".$col->today;
$todaybgcolor = "#".$col->todaybg;
$monthcolor = "#".$col->month;
$daycolor = "#".$col->day;
$satcolor = "#".$col->sat;
$suncolor = "#".$col->sun;
}
$fontfamily = "Tahoma, Geneva, sans-serif";
$relfontsize = "1";
$cssfontsize = "7pt";
$monat=date("n");
$jahr=date("Y");
$erster=date("w", mktime(0,0,0,$monat,1,$jahr));
$insgesamt=date("t");
$heute=date("d");
$monate=array("January","February","March","April","May","June","July","August", "September","October","November","December");
// Get the dates
$sql = "SELECT id,date, UNIX_TIMESTAMP(date) as timestamp FROM $prefix" . "_db ORDER By id DESC;";
$qry = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_object($qry)) {
if((date("n",$row->timestamp) == $monat)) {
$alle[] = array($row->id,$row->timestamp);
}
}
if($erster==0) {
$erster=7;
}
echo "<table border=\"0\" width=\"100%\" style=\"font-size:".$cssfontsize."; background:".$defaultbgcolor."; font-family:".$fontfamily."\">\n";
echo "<th colspan=\"7\" align=\"center\" style=\"font-size:".$relfontsize."; font-family:".$fontfamily."; color:".$monthcolor."\">".$monate[$monat-1]." ".$jahr."</th>";
echo "<tr><td style=\"color:".$daycolor."\"><b>Mon</b></td><td style=\"color:".$daycolor."\"><b>Tue</b></td>";
echo "<td style=\"color:".$daycolor."\"><b>Wed</b></td><td style=\"color:".$daycolor."\"><b>Thu</b></td>";
echo "<td style=\"color:".$daycolor."\"><b>Fri</b></td><td style=\"color:".$satcolor."\"><b>Sat</b></td>";
echo "<td style=\"color:".$suncolor."\"><b>Sun</b></td></tr>";
echo "<tr>";
$i=1;
while($i<$erster) {
echo "<td> </td>";
$i++;
}
$i=1;
while($i<=$insgesamt) {
$rest=($i+$erster-1)%7;
if($i==$heute) {
echo "<td style=\"font-size:".$cssfontsize."; font-family:".$fontfamily."; background:".$todaybgcolor.";\" align=center>";
} else {
echo "<td style=\"font-size:".$cssfontsize."; font-family:".$fontfamily."\" background:".$defaultbgcolor."; align=center>";
}
$check = false;
foreach ($alle as $zeile) {
foreach ($zeile as $eintrag) {
if(date("d",$eintrag) == date("d")) {
$check = true;
$datum = date("d",$eintrag);
}
}
if($i == $datum) {
$j = makeLink($zeile[0],$i);
} else {
$j = $i;
}
if($i==$heute) {
echo "<span style=\"color:".$todayfontcolor.";\">$j</span>";
} else if($rest==6) {
echo "<span style=\"color:".$satcolor.";\">$j</span>";
} else if($rest==0) {
echo "<span style=\"color:".$suncolor.";\">$j</span>";
} else {
echo "<span style=\"color:".$defaultfontcolor.";\">$j</span>";
}
break;
}
echo "</td>\n";
if($rest==0) {
echo "</tr>\n<tr>\n";
}
$i++;
}
echo "</tr>\n";
echo "</table>\n";
} // end function displayCalender
displayCalender('<br />');
echo "<br />";
} // end if
?>