\documentclass{article}
\usepackage{ulem}
\usepackage{graphicx}
\usepackage{hyperref}
\pagestyle{headings}
\begin{document}
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}
\begin{itemize}
\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{itemize}
\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.<br />
\textbf{Place this in the php file where you would like to have the calendar display}

<pre><code class="language-php"> 
<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);
</code></pre>
\textbf{Place this file in your php include path} or adjust the require\_once call above

<pre><code class="language-php">
<?
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 -->.*\textbackslash\{\}s*.*\textbackslash\{\}s*.*\textbackslash\{\}s*.*\textbackslash\{\}s*.*\textbackslash\{\}s*.*\textbackslash\{\}s/', '' ,\$calendarfile);
// Remove the owner lines
\$calendarfile = preg\_replace('/<!-- owner -->.*\textbackslash\{\}s*.*\textbackslash\{\}s*.*\textbackslash\{\}s*.*\textbackslash\{\}s*.*\textbackslash\{\}s*/', '' ,\$calendarfile);
// Remove the status lines
\$calendarfile = preg\_replace('/<!-- status -->.*\textbackslash\{\}s*.*\textbackslash\{\}s*.*\textbackslash\{\}s*.*\textbackslash\{\}s*.*/', '' ,\$calendarfile);
// Remove alarm and created lines
\$calendarfile = preg\_replace('/<!-- alarm -->.*\textbackslash\{\}s*.*\textbackslash\{\}s*.*\textbackslash\{\}s*.*\textbackslash\{\}s*.*\textbackslash\{\}s*.*\textbackslash\{\}s*.*\textbackslash\{\}s*.*\textbackslash\{\}s*.*\textbackslash\{\}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>

<?
\}
</code></pre>
\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.

<pre><code class="language-php">
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';
</code></pre>
\end{document}
