[cvs] [Wiki] changed: LegacyApps
Jan Schneider
jan at horde.org
Thu Aug 18 14:13:16 PDT 2005
jan Thu, 18 Aug 2005 14:13:16 -0700
Modified page: http://wiki.horde.org/LegacyApps
New Revision: 1.1
Change log: Initial content
@@ -1 +1,63 @@
++ 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 ((Doc/Dev/Registry|Horde Registry)). 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:
+
+<code type="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>
+
+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 //only// on your website and //not// through the RPC servers.
+
+<code type="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();
+
+// Authenticate a user.
+$auth = &Auth::singleton('none');
+$auth->setAuth('username', array('password' => 'foo'));
+
+// Call a Registry method.
+$calendars = $registry->call('calendar/listCalendars');
+
+</code>
+
+We only added two lines, 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 {{'password'}} argument can have any value, as long as it isn't needed later, for example to //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:
+
+<code type="php">
+$auth = &Auth::singleton($conf['auth']['driver']);
+$authenticated = $auth->authenticate('username', array('password' => 'realpassword'));
+</code>
+
+The Registry already takes care of loading the Horde configuration, so {{$conf['auth']['driver']}} contains the correct driver name. The Auth library retrieves the authentication driver parameters from the configuration automatically.
+{{$authenticated}} will contain a boolean indicating whether the authentication succeeded.
+
+TODO: Horde_Block examples
More information about the cvs
mailing list