Skip to content

Commit

Permalink
Populated README file, reorganized config and changed defaults, added…
Browse files Browse the repository at this point in the history
… option to disable some configuration options.
  • Loading branch information
BrandonDusseau committed Jan 19, 2015
1 parent d9da466 commit 80a4a26
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 38 deletions.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ICS Calendar Display #
The goal of this software is to create a 10-foot style user
interface to display the contents of one or more iCal files.
The calendar has the ability to highlight or darken certain
events or calendars, and which events are displayed is customizable.

# Requirements #
This software utilizes AJAX to load the output of a PHP script. This
requires that page be reached via the same web server that is serving
the PHP script, as AJAX cannot load external or local sources.

# Configuration #
This repository contains an example configuration file, `config.example.php`.
This file must be renamed to `config.php` in order to be read properly.

The software provides the following options:

_Events_
- `$number_of_events` - Set to the maximum total number of events to display.
Set this to `-1` for no limit.
- `$days_back` - Set to the number of days in the past to display events.
Set this to `-1` for no limit.
- `$days_forward` - Set to the number of days in the future (including today) to
display events. Set this to `-1` for no limit
- `$skip_keyword` - Any event with this string located anywhere in its
description will not be displayed. To use no string, use `false`.

_Highlight/Darkening_
- `$highlight_today` - Set to `true` to highlight events that occur today. Set
to `false` otherwise.
- `$highlight_calendars` - Add each calendar you wish to always highlight. For
example, use `array("cal1", "cal2")` to highlight calendar sources named
"cal1" and "cal2". To highlgiht no calendars, use `false`.
- `$highlight_keyword` - Any event with this string located anywhere in its
description will be highlighted. To use no string, use `false`.
- `$darken_past` - Set to `true` to darken events that have passed. Set
to `false` otherwise.
- `$darken_calendars` - Same as `$highlight_calendars`, except darkened.
- `$darken_keyword` - Same as `$highlight_keyword`, except darkened.

_Error Reporting_
- `$show_ical_errors` - Setting this to `true` will display an error if one or
more iCal sources cannot be read or parsed. Set to `false` to suppress this
message.
27 changes: 13 additions & 14 deletions config.example.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
<?php
$number_of_events = 7; // Number of events to display
$days_back = 7; // Number of days to show in the past
$days_forward = 14; // Number of days to show in the future
// See README file for information on this configuration
$number_of_events = 7;
$days_back = 7;
$days_forward = 14;

$highlight_today = false; // Whether to highlight events occurring today
$highlight_calendars = array("cal1"); // Calendars to always highlight
$highlight_keyword = "#PRI"; // Items with this keyword in the description will be highlighted. Use an empty string to disable this.
$skip_string = "SKIP ME";

$darken_past = true; // Whether to darken incomplete items in the past
$darken_calendars = array(); // Calendars to always darken
$darken_keyword = "#DARK"; // Items with this keyword in the description will be darkened. Use an empty string to disable this.
$highlight_today = false;
$highlight_calendars = array("cal1");
$highlight_keyword = "#PRI";

$skip_string = "#CMP"; // If this string is present in an item's description, it will be skipped. Use an empty string to disable this.
$darken_past = true;
$darken_calendars = false;
$darken_keyword = "#DARK";

$show_ical_errors = true; // Displays an error if an iCal feed has failed to be read
$show_ical_errors = true;

// Calendar URLs - use private ICS links from Google Calendar or another calendar service.
// The key of each array entry will specify the calendar name used in the settings above.
$calendar_urls = array(
"cal1" => "http://www.example.com/cal1.ics",
"cal2" => "http://www.example.com/cal2.ics"
);

?>
?>
48 changes: 24 additions & 24 deletions schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,36 @@
// Add both assignments and exams to the array
foreach ($calendar_urls as $name => $url) {
$this_ical = new ical($url);

// Skip calendar if it cannot load
if ($this_ical === false) {
$failed = true;
continue;
}

$item_count = 0;

// Loop through events
foreach($this_ical->events() as $event) {
// Set array index as date
$target = date("Ymd",strtotime($event['DTSTART']));

// Skip items out of the date range
if (strtotime($event['DTSTART']) < strtotime("-" . $days_back . " days") ||
strtotime($event['DTSTART']) > strtotime("+" . $days_forward . " days")) {
if (($days_back != -1 && strtotime($event['DTSTART']) < strtotime("-" . $days_back . " days")) ||
($days_forward != -1 && strtotime($event['DTSTART']) > strtotime("+" . $days_forward . " days"))) {
continue;
}

// If the item is marked completed, ignore it
if (!empty($skip_string) && strpos($event["DESCRIPTION"], $skip_string) !== false) {
continue;
}

// Create empty array object for the date if it does not yet exist
if (empty($result_array[$target])) {
if (empty($result_array[$target])) {
$result_array[$target] = array();
}

// Add to the array index
array_push($result_array[$target], array(
"time" => date("g:i a",strtotime($event['DTSTART'])),
Expand Down Expand Up @@ -76,56 +76,56 @@
if ($stop) {
break;
}

// Display the container for the date
echo "<div class='day'>\n" .
"\t<div class='heading'>". $events[0]['date'] ."</div>\n" .
"\t<div class='events'>\n";

// Since ICS gives us events in an arbitrary order, rearrange them
usort($events, function ($a, $b) {
return date("U", strtotime($a['timestamp'])) - date("U", strtotime($b['timestamp']));
});

// Loop through each event on this date
foreach ($events as $event) {
// If we've displayed the maximum number of events, stop.
if ($stop) {
break;
}

// If we have enough items, complete this iteration and stop.
$item_count++;
if ($item_count == $number_of_events) {
if ($number_of_events != -1 && $item_count == $number_of_events) {
$stop = true;
}

$class = ""; // Default the extra classes on the event to none.

// Highlight designated calendars, those with the appropriate keyword, and today's events, if configured.
if ((!empty($highlight_calendars) && in_array($event['calendar'], $highlight_calendars)) ||
($highlight_today && strtotime($event['timestamp']) < strtotime("tomorrow")
($highlight_today && strtotime($event['timestamp']) < strtotime("tomorrow")
&& strtotime($event['timestamp']) >= strtotime("today")) ||
(!empty($highlight_keyword) && strpos($event["desc"], $highlight_keyword) !== false)) {

$class .= " highlight";
}

// Darken designated calendars, those with the appropriate keyword, and past events, if configured.
if ((!empty($darken_calendars) && in_array($event['calendar'], $darken_calendars)) ||
if ((!empty($darken_calendars) && in_array($event['calendar'], $darken_calendars)) ||
($darken_past && strtotime($event['timestamp']) < strtotime("now")) ||
(!empty($darken_keyword) && strpos($event["desc"], $darken_keyword) !== false)) {

$class .= " darken";
}

// Display the event
echo "\t\t<div class='events-inner $class'>\n" .
"\t\t\t<div class='time'>" . $event['time'] . "</div>\n" .
"\t\t\t<div class='event'>" . $event['title'] . "</div>\n" .
"\t\t</div>\n";
}

echo "\t</div>\n</div>\n";
}

Expand Down

0 comments on commit 80a4a26

Please sign in to comment.