Mecha CMS

Mecha CMS blog and documentation.

Calendar Plugin

Updated: Sunday, 07 August 2016

Hook–able calendar widget.

Image

This is the core widget. Add your own custom events by utilizing the available hooks.

Usage

Basic Usage

<?php echo Widget::calendar('your_unique_id'); ?>

As Widget Block

<?php echo Shield::chunk('block.widget', array(
    'title' => $speak->calendar,
    'content' => Widget::calendar('your_unique_id')
)); ?>

Hooks

Your calendar ID will also affect the calendar hook ID. This way, you can add some notes to the specified date based on the calendar ID.

Calendar::hook('your_unique_id', function($lot, $year, $month, $id) { … });
Calendar::date('2016/4/21', array( … ), 'your_unique_id');
Calendar::date('2016/4', array( … ), 'your_unique_id');
Calendar::date('2016', array( … ), 'your_unique_id');

Examples

Add a new event on 2016/4/21:

Calendar::date('2016/4/21', array(
    'url' => '/article/happy-birth-day', // ← the URL you want to link to
    'description' => 'Today is my birthday.', // ← the event description
    'kind' => array('fun', 'party', 'me') // ← add some tags (optional)
), 'your_unique_id');

More events:

Calendar::hook('your_unique_id', function($lot) {
    $lot['2016/4/21'] = array('description' => 'This is a test 1.');
    $lot['2016/4/22'] = array('description' => 'This is a test 2.');
    $lot['2016/4/23'] = array('description' => 'This is a test 3.');
    // …
    return $lot;
});

Using files:

Calendar::hook('your_unique_id', function($lot, $year, $month, $id) {
    $the_year = Calendar::year($id, $year);
    $the_month = Calendar::month($id, $month);
    if($the_year === $year && $the_month === $month) {
        $events = glob('path/to/' . $year . '/' . $month . '/[0-9]*.txt');
        foreach($events as $event) {
            $file = File::open($event)->unserialize();
            $lot[$year . '/' . $month . '/' . File::N($event)] = $file;
        }
    }
    return $lot;
});

Download Latest Version

Donation and Email Subscription