calendar.class.php

10/10/2008 - Version 2.7 Now Available!

What is calendar.class.php?

calendar.class.php is a simple calendar generation class written in php. The class outputs semantic and valid XHTML that is ready to style with your custom CSS. The class was created to be used as a framework object for the firepaper project but was designed to be portable and versatile enough to serve many uses.

New Features!

  • BUG FIX: control starting date of week is fixed!

Features

  • Semantic and Valid XHTML output
  • Use the default classes or override them with your own and style with CSS
  • Display current month with today marked (default behavior)
  • Display calendar with selected date marked
  • Display calendar just by month/year without providing a full date
  • Provide an array of dates to mark on the calendar
  • Optionally link days to a page with their date appended to the designated URL
  • Easily loop calendar display to output multiple months or create "year at a time" views
  • Calendar output can now be localized using PHP's setlocale() function
  • Added optional CSS class for passed dates (enabled by default)
  • Designate that only selected dates are linked
  • Day links can now be formatted for Cruft-Free URLs
  • Specify the day of the week that weeks should begin on
licensed under: GPL v2.0
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
Use of this class for commercial/proprietary purposes is governed by the
terms of Commercial License issued exclusively by the Author.

Download

Download version 2.7

SVN: http://calendar-class-php.googlecode.com/svn/trunk/

Usage

Download calendar.class.php and included it into your PHP script. Then call the constructor to create a new calendar object. Use the output method to display the calendar.

PHP:
  1. require_once('calendar.class.php');
  2. $simple_example = new Calendar();
  3. print($simple_example->output_calendar());

Examples

  • Three Month Calendar (previous, current, next months)
  • Year-at-a-time Calendar
  • View more examples here
    (or view the "examples" directory included in the download)

    Documentation

    Methods

    Calendar($date, $year, $month)

    Class constructor, initalizes calendar object with date values

    $date
    ISO format (YYYY-MM-DD) selected date for generating a month calendar. The date will be marked up with the class "selected" by default. Takes precedence over $year and $month arguments. Optional, default value: NULL
    $year
    Combined with $month to display the specified month of the year without designating a selected date. When supplied without $month the current year will be used. Optional, default value: NULL
    $month
    Combined with $year to display the specified month of the year without designating a selected date. When supplied without $year the current month will be used. Optional, default value: NULL
    output_calendar($year, $month, $calendar_class)

    Generates the calendar based on the arguments and variables provided and outputs the calendar HTML

    $year
    Used to override dates set by the constructor for outputting multiple calendars from the same object. optional, default value: NULL
    $month
    Used to override dates set by the constructor for outputting multiple calendars from the same object. optional, default value: NULL
    $calendar_class
    Class name applied to the calendar table. optional, default value: calendar

    Variables

    $date
    Selected date. Initialized by Constructor
    $year
    Year portion of selected date, or year value supplied to constructor. Initialized by Constructor
    $month
    Month portion of selected date, or month value supplied to constructor. Initialized by Constructor
    $day
    Day portion of selected date, empty when year and month are provided. Initialized by Constructor
    $link_days
    Link days to a URL, values: TRUE or FALSE. Default value: TRUE
    $link_to
    URL days should link to. Default value: XSS clean PHP_SELF. Initialized by Constructor
    $mark_today
    Add class to today's date, values: TRUE or FALSE. Default value: TRUE
    $today_date_class
    Class name to apply to today's date, default value: today
    $mark_selected
    Add class to selected date supplied to constructor, values: TRUE or FALSE. Default value: TRUE
    $mark_passed
    Add class to dates previous to today's date (ie. passed dates), values: TRUE or FALSE. Default value: TRUE
    $passed_date_class
    Class name to apply to dates in the past, default value: passed
    $selected_date_class
    Class name to apply to selected date, default value: selected
    $highlighted_dates
    Optional array of dates in ISO format to highlight on the calendar. Default: empty
    $default_highlighted_class
    Class name to apply to highlighted dates, default value: highlighted