All Projects → mzur → Kirby Calendar Plugin

mzur / Kirby Calendar Plugin

Licence: gpl-2.0
A plugin for the Kirby CMS to easily implement an event calendar.

Projects that are alternatives of or similar to Kirby Calendar Plugin

kirbyup
🆙 Zero-config bundler for Kirby Panel plugins
Stars: ✭ 33 (-56.58%)
Mutual labels:  kirby, kirby-plugin
Cartkit
Cartkit - The [quick] starter kit!
Stars: ✭ 39 (-48.68%)
Mutual labels:  kirby, kirby-plugin
queue-for-kirby
Basic queue for Kirby 2, using Cron and Kirby's flat file system
Stars: ✭ 17 (-77.63%)
Mutual labels:  kirby, kirby-plugin
kirby-boiler-field
Boilerplate for Kirby form fields
Stars: ✭ 15 (-80.26%)
Mutual labels:  kirby, kirby-plugin
Kirby Sri
Subresource integrity hashing & cache-busting static assets for Kirby
Stars: ✭ 9 (-88.16%)
Mutual labels:  kirby, kirby-plugin
kirby3-many-to-many-field
This plugin allows you to create many-to-many relationships between pages in Kirby and synchronizes them on both sides.
Stars: ✭ 38 (-50%)
Mutual labels:  kirby, kirby-plugin
kirby-architect
📐 Easily reference Blueprint data from anywhere in your Kirby application.
Stars: ✭ 38 (-50%)
Mutual labels:  kirby, kirby-plugin
kirby-minify-html
Enable minify HTML output for Kirby 3
Stars: ✭ 27 (-64.47%)
Mutual labels:  kirby, kirby-plugin
kirby-copy-files
Clone page dashboard widget for Kirby panel
Stars: ✭ 12 (-84.21%)
Mutual labels:  kirby, kirby-plugin
search-for-kirby
Kirby 3 plugin for adding a search index (sqlite or Algolia).
Stars: ✭ 42 (-44.74%)
Mutual labels:  kirby, kirby-plugin
kirby-membership
Simple Membership plugin for Kirby CMS
Stars: ✭ 27 (-64.47%)
Mutual labels:  kirby, kirby-plugin
Panel Bar
panelBar for Kirby 2 CMS
Stars: ✭ 70 (-7.89%)
Mutual labels:  kirby, kirby-plugin
grid-gallery
A KirbyCMS plugin for adding grid galleries
Stars: ✭ 16 (-78.95%)
Mutual labels:  kirby, kirby-plugin
kirby-file-types
Show file fields only for specific file types
Stars: ✭ 13 (-82.89%)
Mutual labels:  kirby, kirby-plugin
kirby-map-field
🗺 An easy way to use maps and location data in Kirby.
Stars: ✭ 41 (-46.05%)
Mutual labels:  kirby, kirby-plugin
retour-for-kirby
Kirby 3 plugin to manage redirects and track 404s right from the Panel
Stars: ✭ 96 (+26.32%)
Mutual labels:  kirby, kirby-plugin
KirbyComments
[Kirby 2] File-based comments stored as subpages for the Kirby CMS.
Stars: ✭ 68 (-10.53%)
Mutual labels:  kirby, kirby-plugin
kirby-sortable
Making subpage managing a breeze
Stars: ✭ 82 (+7.89%)
Mutual labels:  kirby, kirby-plugin
kirby-blade
Enable Laravel Blade Template Engine for Kirby 3
Stars: ✭ 20 (-73.68%)
Mutual labels:  kirby, kirby-plugin
Select A Structure
A select field for Kirby populated by a structure field.
Stars: ✭ 44 (-42.11%)
Mutual labels:  kirby, kirby-plugin

kirby-calendar-plugin

A plugin for the Kirby 2 CMS to easily implement an event calendar.

The Calendar Plugin v2 is not compatible with v1!

Installation

  1. Put the calendar directory to site/plugins/.

  2. Put those snippets from snippets that you like to use to site/snippets/ (or make your own).

  3. Put the language files of the language directory to site/languages/. If you already have existing language files, simply append the content to them. You only need to choose those languages that you actually want to support.

  4. Make sure you have the language support of Kirby activated (even, if you only want to support one language). Here is an example for activating the support with a single language in site/config/config.php:

c::set('languages', array(
	array(
		'code'    => 'en',
		'name'    => 'English',
		'locale'  => 'en_US.UTF-8',
		'default' => true,
		'url'     => '/'
	)
));

For more information on the multi language support of Kirby, see the docs.

Usage

Making this plugin work involves three steps: providing the calendar data, setting up the calendar object and displaying the calendar as a snippet.

Calendar data

You provide the calendar data as you provide any content in Kirby; as a data field of the page. For example take the page content/calendar/calendar.en.txt:

Title: Calendar

----

Calendar: 
-
  summary: My Event
  _begin_date: 12/14/2014
  _begin_time: 10:00
  _end_date: 12/14/2014
  _end_time: 15:00
- 
  summary: My supercool event for the whole day
  description: This wil be a nice event!
  _begin_date: 10/01/2014

The Calendar field contains all events in a YAML list. Each event has several own fields, too, but of them only _begin_date is mandatory (see event-fields). You can define as many other fields as you like.

Calendar object

Now let's get to the calendar template. Setting up the calendar object is really simple; you only have to do this:

<?php $calendar = calendar($page->calendar()->yaml()); ?>

Calendar snippet

To produce any output, you have to use a calendar snippet. This enables you to print even multiple different versions of the same calendar in the same template! You can use one of the snippets provided by this plugin or make your own.

Typical usage of a snippet looks like this (here we use the table snippet provided by the plugin):

<?php
   snippet('calendar-table', array(
      'calendar' => $calendar,
      'fields' => array(
         'summary' => l::get('title'),
         'description' => l::get('description')
      )
   ));
?>

There are two variables we are passing along to the snippet here: $calendar is the calendar object we created in the previous step and $fields is an associative array of all the event fields that should be displayed in this snippet. The keys of this array are the keys of the event fields specified in the calendar data; the values specify how these fields should be displayed (in this case it depends on the language of the site).

So this is basically it. If you followed the instructions correctly, you should see the calendar printed on the page.

Panel

The calendar data is formatted to work perfectly with a structure field. Take a look at the blueprints directory of this repo to see a full example.

Localisation

The plugin is designed to fully support localisation, thus requiring Kirby's language support to be enabled.

Language variables

The provided language files contain some language variables used by the plugin internally, by the default snippets or in this example.

  • calendar-time-format: The formatting string of the date of an event (without a time).
  • calendar-full-time-format: The formatting string of the date and time of an event.
  • calendar-month-format: The formatting string of a month.
  • calendar-no-entry: The message printed when there are no events to display.

See here for more information on time formatting strings.

Timezone

By default the plugin uses the uses the timezone of the server it is running on. The correct timezone is essential for correct datetime attributes or iCal output, for example. To set the timezone manually you can use data_default_timezone_set in the header snippet of your site like this:

<?php date_default_timezone_set('Europe/Berlin'); ?>

Locale

The locale is set by Kirby's language configuration. So if you've set up everything correctly, it should work without problems.

Event fields

Events can have arbitrary fields. However there are the special fields for this plugin marked by a _-prefix:

  • _begin_date: The only mandatory field specifying the date, the event begins.
  • _begin_time: The time of the day the event begins.
  • _end_date: The date the event ends.
  • _end_time: The time of the day the event ends.

The behavior with different combinations of these fields is the following:

  • only _begin_date given: The event lasts the whole day.

  • _begin_date and _begin_time given: The event lasts from the given time until midnight (12 am) of the following day.

  • _begin_date and _end_time given: The event lasts from midnight until the given time of the day.

  • _begin_date and _end_date given: The event lasts from mindnight of the beginning day until midnight of the day after the ending day.

Functions

There are two objects you can work with, Calendar and Event.

Calendar object

The Calendar object is returned by the calendar() function of this plugin. It has the following functions:

getAllEvents()

Returns an array of all the events of this calendar, including the past events.

getEvents()

Returns an array of all future events of this calendar.

getEventFields()

Returns an array of all the event fields occurring in the events of this calendar.

Event object

The Event objects are provided by the Calendar object. They have the following functions:

getBeginTimestamp()

Returns the UNIX timestamp in seconds for the beginning of this event.

getBeginDate()

Returns the PHP date array of the beginning of this event.

getBeginStr()

Returns the formatted string of the beginning of this event. Formatting is done according to the language configuration of Kirby. If the event was given a time, the calendar-full-time-format is used, calendar-time-format otherwise.

getBeginHtml()

Returns the formatted string of the beginning of this event as a time element with datetime attribute.

getEndTimestamp()

Returns the UNIX timestamp in seconds for the ending of this event.

getEndDate()

Returns the PHP date array of the ending of this event.

getEndStr()

Returns the formatted string of the ending of this event. Formatting is done according to the language configuration of Kirby. If the event was given a time, the calendar-full-time-format is used, calendar-time-format otherwise.

getEndHtml()

Returns the formatted string of the ending of this event as a time element with datetime attribute.

getFieldKeys()

Returns all field keys of this event that have no _-prefix.

getField($key)

Returns the content of the field or an empty string if it doesn't exist in this event.

$key: The event field key whose value should be returned.

isPast()

Returns true if this event is past at the current time, false otherwise.

hasEnd()

Returns true if the event was given an ending date or time, false otherwise.

Snippets

There are a few default calendar snippets provided by this plugin. You can find them in the snippets directory of this repo. Of course you can customize them to your needs or write ones on your own!

table

Displays all events (including the past ones) as a table. Only the event fields given in $fields are displayed. $fields specify the column labels as well. Example output:

<table class="calendar">
	<thead>
		<tr>
			<th>Date</th>
			<th>Title</th>
			<th>Description</th>
		</tr>
	</thead>
	<tbody>
		<tr class="month past">
			<td colspan="3">October 2014</td>
		</tr>
		<tr class="event past">
			<td><time datetime="2014-10-01T00:00:00Z">01</time></td>
			<td>My supercool event for the whole day</td>
			<td>This wil be a nice event!</td>
		</tr>
		<tr class="month">
			<td colspan="3">December 2014</td>
		</tr>
		<tr class="event">
			<td><time datetime="2014-12-14T10:00:00Z">14 10:00:00 AM</time> to <time datetime="2014-12-15T23:45:00Z">15 11:45:00 PM</time></td>
			<td>Event</td>
			<td></td>
		</tr>
	</tbody>
</table>

div

Displays all events (including the past ones) as a div layout. Only the event fields given in $fields are displayed. $fields specify the column labels as well. Example output:

<section class="calendar">
	<div class="row head">
		<div class="item">Date</div>
		<div class="item">Title</div>
		<div class="item">Description</div>
	</div>
	<div class="row month past">
		<div class="item">October 2014</div>
	</div>
	<div class="row event past">
		<div class="item date"><time datetime="2014-10-01T00:00:00Z">01</time></div>
		<div class="item">My supercool event for the whole day</div>
		<div class="item">This wil be a nice event!</div>
	</div>
	<div class="row month">
		<div class="item">December 2014</div>
	</div>
	<div class="row event">
		<div class="item date"><time datetime="2014-12-14T10:00:00Z">14 10:00:00 AM</time> to <time datetime="2014-12-15T23:45:00Z">15 11:45:00 PM</time></div>
		<div class="item">Event</div>
		<div class="item"></div>
	</div>
</section>

ical

Displays all events (including the past ones) in iCal format. This is very useful to provide iCal export of your calendar. It only includes the summary, description and location event fields. Be sure to set the header of your iCal-export template like this:

<?php header('Content-type: text/calendar'); ?>

Example output:

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//http://example.com//Kirby Calendar Plugin//EN 
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART:20141001T000000Z 
DTEND:20141002T000000Z 
SUMMARY:My supercool event for the whole day 
DESCRIPTION:This wil be a nice event! 
LOCATION: 
END:VEVENT
BEGIN:VEVENT
DTSTART:20141214T100000Z 
DTEND:20141215T234500Z 
SUMMARY:Event 
DESCRIPTION: 
LOCATION: 
END:VEVENT
END:VCALENDAR

teaser

Displays a set number of future events as a list. The number of events to display is specified in $items. The event fields to display are specified in $fields. Example output:

<ul class="teaser">
	<li><strong><time datetime="2014-12-14T10:00:00Z">14 10:00:00 AM</time></strong> Event</li>
</ul>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].