Neulich gab es schon was hier im Forum.
Jemand hat das Topics als Event-Calendar gebraucht.
War schon lustig, weil ich zu der selben Zeit das gleiche ausgearbeitet habe und dann John (PC Wacht) noch ein Calendar Droplet gepostet hat.
Da kam mir 1 und 1 durch den Kopf geschoßen, ein wenig (mehr) Hilfe von einem erfahrenen Programmierer (Bianka) und schon war ein Calendar Droplet zur Zusammenarbeit mit dem Topics Modul fertig.
Ich poste das Droplet so, wie ich es selbst verwende.
Man sollte es für seine Zwecke über das CSS File im Template Stylen.
<?php
global $wb, $database;
$days = array();
$day_name_length = 2;
$month_href = NULL;
$first_day = 1; // 0 = Sun, 1 = Mon, 2 = Tue, etc.
$time = time();
$oldlocale = setlocale(LC_TIME, NULL); //save current locale
//setlocale(LC_TIME, 'de_DE');
if (!isset($year)) {$year = date('Y', time()); };
if (!isset($month)) {$month = date('n', time()); };
if (isset($offset)) { $month += $offset; }
// --------------| check offset for this month
$thismonth = date('m',time());
if (!isset($offset) or $offset == 0)
{
$today = date('j',$time);
}
/*
--------------| get entries from Topics
*/
$first_of_month = mktime(0,0,0,$month,1,$year);
$lastday = strftime( "%d", mktime(0, 0, 0, ($month+1), 0, $year) );
$last_of_month = mktime(23,59,59,$month,$lastday,$year);
$where = ( isset( $section_id ) && is_numeric( $section_id ) )
? "AND section_id = '$section_id'"
: NULL;
$sql = "SELECT published_when, link, title FROM ".TABLE_PREFIX."mod_topics
WHERE published_when BETWEEN $first_of_month AND $last_of_month $where";
$result = $database->query($sql);
// $day == $today ? $classes = "today-linked" : $classes = "linked-day";
/*
---------------------------| define STATIC LINKS
*/
//LINKS
$static_links = array(
// 0 =>WB_URL.PAGES_DIRECTORY.'/montag'.PAGE_EXTENSION,
1 =>WB_URL.PAGES_DIRECTORY.'/dienstag'.PAGE_EXTENSION,
2 => WB_URL.PAGES_DIRECTORY.'/mittwoch'.PAGE_EXTENSION,
4 => WB_URL.PAGES_DIRECTORY.'/freitag'.PAGE_EXTENSION);
//TITLES (title attribute)
$static_links_title = array(
// 0 => 'montag-title',
1 => 'dienstag-title',
2 => 'mittwoch-title',
4 => 'feitag-title');
/*
--------------| LINKS generated by Topics dates
*/
if ( $result->numRows() > 0 ) {
while( $row = $result->fetchRow() ) {
$day = date( 'j', $row['published_when'] );
$topic_link = WB_URL.PAGES_DIRECTORY.'/topics/'.$row['link'].PAGE_EXTENSION;
$days[$day] = array(NULL,NULL,'<a class="vtip" href="'.$topic_link.'" title="'.$row['title'].'">'.$day.'</a>');
}
}
$first_of_month = gmmktime(0,0,0,$month,1,$year);
$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
// reset locale
setlocale(LC_TIME, $oldlocale);
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)).' <span>'.$year.'</span>';
//note that some locales don't capitalize month and day names
// -----------------------| Begin calendar
$calendar = '<table class="calendar">'."\n".
'<caption class="calendar-month">'.$title."</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="vtip" title="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr>";
}
// -----------------------| initial 'empty' days
if($weekday > 0) $calendar .= '<td class="emptydays" colspan="'.$weekday.'"> </td>';
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>";
}
// -----------------------| TOPICS LINKS
if(isset($days[$day]) and is_array($days[$day])){
@list($link, $hmm, $content) = $days[$day];
if(is_null($content)) $content = $day;
if ($link) {
$calendar .= '<td '.($day == $today ? ' class="today-linked">' : ' class="linked-day">').
'<a class="vtip" href="'.htmlspecialchars($link).'">
<span'.($day == $today ? ' class="today static">' : ' class="linked-day">').$content.'</span>
</a>
</td>';
}
else {
$calendar .= '<td'.($day == $today ? ' class="today-linked">' : ' class="linked-day">').'
<span'.($day == $today ? ' class="today topic-link">' : ' class="linked-day">').$content.'</span>
</td>';
}
}
// -----------------------| STATIC LINKS
elseif ( isset( $static_links[$weekday] )) {
$calendar .= '<td'.($day == $today ? ' class="today static">' : ' class="linked-day static">').
'<a class="vtip" href="'.htmlspecialchars($static_links[$weekday]).'" title="'.htmlspecialchars($static_links_title[$weekday]).'">
<span'.($day == $today ? ' class="today static">' : ' class="linked-day static">').$day.'</span>
</a>
</td>';
}
// -----------------------| Days w/o Links
else {
if($day == $today) {
$calendar .= '<td class="today vtip" title="Heute findet keine Veranstaltung statt"><span class="today">'.$day.'</span></td>';
}
else {
$calendar .= '<td>'.$day.'</td>';
}
}
}
// ----------------------- | remaining 'empty' days
if($weekday != 7) $calendar .= '<td class="emptydays" colspan="'.(7-$weekday).'"> </td>';
return $calendar."</tr>\n</table>\n";
Zusätzlich gibts die Möglichkeit, statische Links zu setzen (ist oben ausgezeichnet/gekennzeichnet).
Ach ja, wenn es an einem Tag zwei Topics gibt, gewinnt der, der zuerst in der DB geschrieben wurde.
Viel Spaß damit, wer es gebrauchen kann.
Stefek