EventCal

Dieses Droplet zeigt die Events aus dem "Event Calendar" Modul als Monatskalenderblatt an. Das Droplet wurde ursprünglich von "pcwacht" (Forenname) erstellt und von mir dann für die Nutzung des Event Calendars erweitert.

Thread im WebsiteBaker Forum

Event Calendar Download

Droplet Code

global $wb, $database;

$days = array();
$day_name_length = 2;
$month_href = NULL;
$where = NULL;
$first_day = 1;
$pn = array();
$events = 0;

$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( $section ) ) { $where = "AND section_id='$section'"; }

$today = date('j',time());

// Get Events from "Event Calendar" Module (1.8c)
$sql    = "SELECT DAY(date) AS day, event_desc AS descr, evweb_url AS url FROM ".TABLE_PREFIX."mod_event_dates WHERE YEAR(date) = '$year' AND MONTH(date) = '$month' $where";
$result = $database->query($sql);
if ( $result->numRows() > 0 ) {
    while( $row = $result->fetchRow() ) {
        $text = $row['day'];
        if ( ! empty( $row['descr'] ) ) {
            $text .= ' <span>'.$row['descr'].'</span>';
        }
        if ( ! empty( $row['url'] ) ) {
            $days[ $row['day'] ]
                = array(
                      NULL,
                      NULL,
                      "<span style='font-weight: bold; border: 1px solid #f00;'>"
                    . "<a class='tooltip' href='".$row['url']."' target='_blank'>"
                    . $text
                    . "</a></span>"
                  );
        }
        else {
            $days[ $row['day'] ]
                = array(
                      NULL,
                      NULL,
                      "<span style='font-weight: bold; border: 1px solid #f00;'>"
                    . "<a class='tooltip' href='#'>"
                    . $text
                    . "</a></span>"
                  );
        }
        $events++;
    }
}

if ( ! isset( $days[$today] ) ) {
    $days[$today] = array( NULL, 'calendar-today' );
}

$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

// 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)).'&nbsp;'.$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="calendar-prev">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span>&nbsp;';
if($n) $n = '&nbsp;<span class="calendar-next">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table class="calendar">'."\n".
   '<caption class="calendar-month">'.$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 abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
   $calendar .= "</tr>\n<tr>";
}

if($weekday > 0) $calendar .= '<td colspan="'.$weekday.'">&nbsp;</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>";
   }
   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>$day</td>";
}
if($weekday != 7) $calendar .= '<td colspan="'.(7-$weekday).'">&nbsp;</td>'; #remaining "empty" days
$calendar .= "</tr>\n</table><br />\n";

if ( $events == 0 ) {
    $calendar .= 'Keine Termine f&uuml;r diesen Monat.<br />';
}
else {
    $calendar .= $events.' '.'Termin'
              .  ( $events > 1 ? 'e' : '' )
              .  ' f&uuml;r diesen Monat.<br />';
}

return $calendar;

Verwendung

Wie jedes Droplet, z. B. im Template oder einer WYSIWYG-Sektion.

Standardaufruf:

    [[EventCal]]

Zeigt alle Events des laufenden Monats. Alle bedeutet, daß bei mehrfacher Verwendung des Event Calendar Moduls auf verschiedenen Seiten die Termine von allen Sektionen verwendet werden.

SectionID angeben (Beispiel):

    [[EventCal?section=25]]

Monat explizit angeben (Beispiel):

    [[EventCal?month=5]]

Jahr explizit angeben (Beispiel):

    [[EventCal?year=2010]]

Alles kombinieren (Beispiel):

    [[EventCal?year=2010&month=5&section=25]]

Kommentare

Sie können hier einen Kommentar hinterlassen; ich behalte mir allerdings vor, Kommentare zu löschen, also bleiben Sie höflich. ;)

Fragen sollten bevorzugt im entsprechenden Thread im WebsiteBaker Forum gestellt werden.

Kommentar abgeben 
Ihr Name 
Code eingeben 773

Jetson?06 Oktober 2011, 21:58

You keep it up now, udnretsnad? Really good to know.

dbs?30 April 2011, 07:59

Der Aufruf EventCal? (wb 2.8.1) zeigt zwar den Tag korrekt im Kalender, aber direkt daneben den Titel. Das zerreißt den Kalender. Ansonsten prima Teil.

Gruß dbs

Buggy?17 Februar 2010, 13:02

Die Idee fand ich gut, leider hat die Einbindung auf die Schnelle (V2.8.1) nicht funktioniert (white-sreen). Leider habe ich ggw. auch nicht die Zeit auch mal in den Code zu schauen, vielleicht ist es ja nur ein simpler Fehler.