\documentclass{article}
\usepackage{ulem}
\pagestyle{headings}
\begin{document}
\tableofcontents

This how-to explains how to integrate public kronolith calendars with your other websites through screen scraping with PHP.  There are other methods of embedding kronolith calendars with javascript, but they don't provide the same level of functionality.

\section{ Assumptions}
\renewcommand{\labelenumi}{\arabic{enumi}}
\begin{enumerate}
\item{Your horde installation is located in \textbf{/calendar}}
\item{You have a file named \textbf{calendar.horde.inc.php} in your include path}
\end{enumerate}
\section{ Setup}
This setup uses two files, one to provide the necessary functions and another that you can put anywhere on your site (or multiple places) where you'd like the calendar displayed.

The file used to display the calendars is fairly simple, it includes a link to appropriate stylesheets, the call to the calendar with associated config variables and if necessary header and footer information.  This example is designed to go inside the <body> tags on your page.\newline
\textbf{Place this in the php file where you would like to have the calendar display}\newline
\begin{verbatim}
 
<link href="/calendars/kronolith/themes/categoryCSS.php" rel="stylesheet" type="text/css" />

<?php
// kronolith location
$url = "http://" . $_SERVER['HTTP_HOST'] . "/calendars/kronolith/";
// this is an array of calendar ids you would like to display (you can get this by clicking on the lightbulb in kronolith)
$display_cals = array('5a56e1e7765e778876dd389e4b35a66f'); 
$default_view = "month";
// bring in the functions 
require_once('calendar.horde.inc.php');
// display the calendar
post_calendar($url, $display_cals, $default_view);
\end{verbatim}

\textbf{Place this file in your php include path} or adjust the require\_once call above\newline
\begin{verbatim}

<?
function post_calendar($url_base, $display_cals, $default_view) {

// date cases
// Day
if(isset($_REQUEST['mday']) && isset($_REQUEST['month']) && isset($_REQUEST['year'])) { 
     $time = 'month=' . $_REQUEST['month'] . '&mday=' . $_REQUEST['mday'] . '&year=' . $_REQUEST['year'];
}
// Week & Work Week
else if (isset($_REQUEST['week']) && isset($_REQUEST['year'])) {
     $time = 'week=' . $_REQUEST['week'] . '&year=' . $_REQUEST['year'];
} 
// Month
else if (isset($_REQUEST['month']) && isset($_REQUEST['year'])) {
     $time = 'month=' . $_REQUEST['month'] . '&year=' . $_REQUEST['year'];
} 
// Year
else if (isset($_REQUEST['year'])) {
     $time = 'year=' . $_REQUEST['year'];
}
else if (isset($_REQUEST['timestamp'])) {
    $time = 'timestamp=' . $_REQUEST['timestamp'];
} else {
    $time = 'timestamp=' . time();
}
if(!isset($_REQUEST['view'])) { 
    $_REQUEST['view'] = $default_view; 
}

#construct the URL we want to get content from
$view = $_REQUEST['view'];

foreach ($display_cals as $display_cal) {
    $calendars .= '&display_cal[]=' . $display_cal;
}

if($_REQUEST['view'] == 'event') {
    $targetfile = $url_base . $view . ".php?" . $time . '&calendar=' . $_REQUEST['calendar'] . '&eventID=' . $_REQUEST['eventID'];
} else {
    $targetfile = $url_base . $view . ".php?" . $time . $calendars;
}
//print $targetfile;

$targetfile = str_replace(" ","%20",$targetfile);
$file = file($targetfile);
$calendarfile = implode('',$file);

$calendar_array = explode("<body>", $calendarfile);
$calendar_array = explode("</body>", $calendar_array[1]);
$calendarfile = $calendar_array[0];

// Convert day/week/month/year links to local links
$calendarfile = str_replace('/calendars/kronolith/day.php?', $_SERVER['SCRIPT_URL'] . '?view=day' . $calendars . '&',$calendarfile);
$calendarfile = str_replace('/calendars/kronolith/week.php?', $_SERVER['SCRIPT_URL'] . '?view=week'  . $calendars . '&',$calendarfile);
$calendarfile = str_replace('/calendars/kronolith/workweek.php?', $_SERVER['SCRIPT_URL'] . '?view=workweek'  . $calendars . '&',$calendarfile);
$calendarfile = str_replace('/calendars/kronolith/month.php?', $_SERVER['SCRIPT_URL'] . '?view=month'  . $calendars . '&',$calendarfile);
$calendarfile = str_replace('/calendars/kronolith/year.php?', $_SERVER['SCRIPT_URL'] . '?view=year'  . $calendars . '&',$calendarfile);
$calendarfile = str_replace('/calendars/kronolith/academicyear.php?', $_SERVER['SCRIPT_URL'] . '?view=academicyear'  . $calendars . '&',$calendarfile);

// Deal with individual events
$calendarfile = str_replace('/calendars/kronolith/event.php?', $_SERVER['SCRIPT_URL'] . '?view=event' . '&',$calendarfile);

// Cleanup display 
// Remove the category lines
$calendarfile = preg_replace('/<!-- category -->.*\s*.*\s*.*\s*.*\s*.*\s*.*\s/', '' ,$calendarfile);
// Remove the owner lines
$calendarfile = preg_replace('/<!-- owner -->.*\s*.*\s*.*\s*.*\s*.*\s*/', '' ,$calendarfile);
// Remove the status lines
$calendarfile = preg_replace('/<!-- status -->.*\s*.*\s*.*\s*.*\s*.*/', '' ,$calendarfile);
// Remove alarm and created lines
$calendarfile = preg_replace('/<!-- alarm -->.*\s*.*\s*.*\s*.*\s*.*\s*.*\s*.*\s*.*\s*.*\s*.*/', '<tr><td style="width: 10%"></td><td style="width:90%"></td></tr>' ,$calendarfile);
// Clean up quotes
$calendarfile = stripslashes($calendarfile);
// Remove titles because the are broken
$calendarfile = preg_replace('/(title=")(.*?)(")/e', "", $calendarfile);
// Remove script files because they are broken too
$calendarfile = str_replace('<script type="text/javascript" src="/calendars/kronolith/js/QuickFinder.js"></script>', '', $calendarfile);
$calendarfile = str_replace('<script type="text/javascript" src="/calendars/kronolith/js/redbox.js"></script>', '', $calendarfile);
$calendarfile = str_replace('<script type="text/javascript" src="/calendars/kronolith/js/calendar-panel.js"></script>', '', $calendarfile);

?>

<div class="calendar">
<?
echo $calendarfile;
?>
</div>

<?
}
\end{verbatim}

\section{ Further Customization}
If you would like to hide the menus for guests you can adjust the pages in kronolith that display the different views.  Here's an example of the kronolith/day.php file.  You'll want to adjust the month, week, workweek and year files as well.

\begin{verbatim}

require_once dirname(__FILE__) . '/lib/base.php';

$view = Kronolith::getView('Day');
$title = $view->getTime($prefs->getValue('date_format'));
$print_view = (bool)Util::getFormData('print');

Horde::addScriptFile('tooltip.js', 'horde', true);
if (!$print_view) {
    Horde::addScriptFile('popup.js', 'horde', true);
}
require KRONOLITH_TEMPLATES . '/common-header.inc';
$user = Auth::getAuth();
if ($user != '') {
if ($print_view) {
    require $registry->get('templates', 'horde') . '/javascript/print.js';
} else {
    require KRONOLITH_TEMPLATES . '/menu.inc';
}

echo '<div id="page">';
}
else {
    echo '<div id="page" style="margin-right: 0;">';
}
if (!$print_view) {
    Kronolith::tabs();
}
$view->html(KRONOLITH_TEMPLATES);
echo '</div>';

if ($print_view) {
    require KRONOLITH_TEMPLATES . '/calendar_titles.inc';
} else {
    require KRONOLITH_TEMPLATES . '/panel.inc';
}
require $registry->get('templates', 'horde') . '/common-footer.inc';
\end{verbatim}

\end{document}
