\documentclass{article}
\usepackage{ulem}
\usepackage{graphicx}
\usepackage{hyperref}
\pagestyle{headings}
\begin{document}
\part{Using Horde from a custom website or application}
The following code snippets show how easy it is to use Horde applications from any PHP code, for example websites, portals, or custom web applications.

Each Horde application can provide a set of methods through its external API. These APIs are used for inter-application communication and data exchange between the different Horde modules. The API methods are always called through the <a href="https://wiki.horde.org/Doc/Dev/Registry">Horde Registry</a>. The Registry and the API methods are also used to provide the methods for Horde's RPC servers, name the XMLRPC, SOAP, and REST servers.

Let's look at some code:

<pre><code class="language-php">
<?php

// Define path to Horde.
define('HORDE\_BASE', '/path/to/horde');

// Load the Horde Framework core, and set up inclusion paths.
require\_once HORDE\_BASE . '/lib/core.php';

// Create the Registry object.
\$registry = \&Registry::singleton();

// Call a Registry method.
\$calendars = \$registry->call('calendar/listCalendars');
</code></pre>
That's it. Assuming that you configured Horde's permissions to allow guest access to Kronolith, the calendar application, you will get an array with calendar names back. If there are no calendars that allow guest access, the array will be empty.

Next we want to see the list of calendars that a certain Horde user has access to. You can for example create a calendar that should be displayed on your website, but \textit{only} on your website and \textit{not} through the RPC servers.

<pre><code class="language-php">
<?php

// Define path to Horde.
define('HORDE\_BASE', '/path/to/horde');

// Tell the registry that we are doing authentication ourselves.
define('AUTH\_HANDLER', true);

// Load the Horde Framework core, and set up inclusion paths.
require\_once HORDE\_BASE . '/lib/core.php';

// Create the Registry object.
\$registry = \&Registry::singleton();

// Authenticate a user.
\$auth = \&Auth::singleton('none');
\$auth->setAuth('username', array('password' => 'foo'));

// Call a Registry method.
\$calendars = \$registry->call('calendar/listCalendars');
</code></pre>
We only added three lines, one to tell the Registry object to not care about authentication, one to create an Auth object, and one to set the current active user. Note that these calls don't really authenticate the user, they only make Horde think that the specified user is authenticated. The \texttt{'password'} argument can have any value, as long as it isn't needed later, for example to \textit{really} authenticate to a IMAP server.

If you want to check authentication, or need to access a backend that requires a valid login, use the following calls to the Auth library instead:

<pre><code class="language-php">
<?php

\$auth = \&Auth::singleton(\$conf['auth']['driver']);
\$authenticated = \$auth->authenticate('username', array('password' => 'realpassword'));
</code></pre>
The Registry already takes care of loading the Horde configuration, so \texttt{\$conf['auth']['driver']} contains the correct driver name. The Auth library retrieves the authentication driver parameters from the configuration automatically.<br />
\texttt{\$authenticated} will contain a boolean indicating whether the authentication succeeded.

\section{Using Horde\_Blocks to embed HTML}
A quick way to embed HTML snippets from a Horde application into a website or application is to use a Horde\_Block. The Horde\_Block library powers the portal page of the Horde Application Framework. Each application and Horde itself are providing blocks of HTML that can be arranged by the users on their personal portal page. All blocks can be retrieved through a single API method.

To embed a simple month calender for example, all you have to do is:

<pre><code class="language-php">
<?php

echo \$registry->call('horde/blockContent',
                     array('kronolith', 'month', array('calendar' => 'jan')));
</code></pre>
This code is calling the "month" block from the "kronolith" application, and passes it a "calendar" parameter. The method returns a string with HTML code that can be embedded into any HTML page.

As Horde is using CSS for all styling and the CSS rules are not included in the HTML, the local CSS need to tweaked to give the block a nice look.<br />
One could also use Horde's CSS files, but these would be applied to the complete page:

<pre><code class="language-php">
<?php

echo Horde::stylesheetLink('kronolith', 'mozilla');
</code></pre>
Such a call would have to happen after the Registry has been initialized, and so that the output is echoed in the page's HTML HEAD.

\section{Using the calendar widgets to embed calendars}
See the help text for more information.  You can select either a single calendar or '<u>all' as the calendar to show all calendars. You can also specify the time period as well, just pass the same parameter name the block uses in the query parameters.

Example upcoming events (monthlist) - show 2 months worth of events, but with a max. of 10 events:

<code type="html"><br />
<div id="kronolist"></div><script<br />
src="<a href="http://host.example.com/horde/services/imple.php?imple=Embed/impleApp=kronolith/view=monthlist/calendar=calendar\_name/container=kronolist/months=2/">http://host.example.com/horde/services/imple.php?imple=Embed/impleApp=kronolith/view=monthlist/calendar=calendar\textbackslash\{\}\_name/container=kronolist/months=2/</a> maxevents=10"<br />
type="text/javascript"></script><br />
</code>

Summary view (show 7 days worth of events only with alarms but only show up to 20 events max):

<code type="html"><br />
<div id="kronosummary"> </div><script type="text/javascript"<br />
src="<a href="http://hostname.example.com/horde/services/imple.php?imple=Embed/impleApp=kronolith/container=kronosummary/view=summary/calendar=calendar\_name/days=7/maxvents=20/alarms=1&quot;\&gt;\">http://hostname.example.com/horde/services/imple.php?imple=Embed/impleApp=kronolith/container=kronosummary/view=summary/calendar=calendar\textbackslash\{\}\_name/days=7/maxvents=20/alarms=1"\textbackslash\{\}>\textbackslash\{\}</a></script><br />
</code>

Summary view (show 7 days worth of events only with alarms but only show up to 20 events max) but with all shared calendars instead of one specific calendar:

<code type="html"><br />
<div id="kronosummary"> </div><script type="text/javascript"<br />
src="<a href="http://hostname.example.com/horde/services/imple.php?imple=Embed/impleApp=kronolith/container=kronosummary/view=summary/">http://hostname.example.com/horde/services/imple.php?imple=Embed/impleApp=kronolith/container=kronosummary/view=summary/</a></u>all/days=7/maxvents=20/alarms=1"></script><br />
</code>

The summary view makes a listing of upcoming events that can be used as an agenda and which prints nicely on 8.5X11 paper.

\end{document}
