Menu

dpcalendar-apiIn a previous blog post, we discussed the increasing relevance of Application Programming Interfaces (APIs) in Web programming, and the reliance of many applications (both traditional as well as Web) on various APIs. We also pointed out that our flagship extension, DPCalendar, allows for the use (and integration) of many different calendars through Joomla extensions. This blog post breaks down the details of how you can integrate your own calendaring system(s) into DPCalendar.

Specifically, DPCalendar supports the integration of various calendar APIs by implementing an API to which Joomla plugins (a subset of Joomla extensions) can be written. In Joomla, a plugin is an extension that is executed when a particular action (event) is taken (triggered). In the case of DPCalendar, loading the calendar view, for example, will signal an event (or possibly a series of events), which will cause plugins to execute. The act of creating, deleting, viewing or saving individual calendar items also signal events, which your external calendar plugins should respond to appropriately.

The DPCalendar API

The list of events which DPCalendar recognises, the parameters they take, and the input they expect (the return values from your plugin) form the basis of the DPCalendar API. In addition, as part of the installation process, we also include the DPCalendarPlugin class, which is a collection of functions that allow you to work with DPCalendar more easily – it, too, can be considered part of the API. And of course, the plugin also has to work with the Joomla API, as well as the API of whichever calendar system being supported by the plugin.

As with all APIs, neither DPCalendar, nor the external calendar plugin with which it is communicating, has to know how data is manipulated internally or how calendaring functions are implemented by the other side; merely that both sides are following the API standards. DPCalendar happens to use the industry-standard iCalendar format to import and export calendar data, so that’s what your plugin should support when working with DPCalendar.

Write Your Own Plugin!

Digital Peak has written a number of plugins for popular calendaring systems, such as Microsoft’s Outlook/Exchange, Google Calendar, Apple’s Calendar, Facebook, CalDAV, and so on. There’s nothing stopping you from writing your own plugin (for instance, to support the Cozi family calendar system). But first, you have to complete the following checklist:

  1. Understand how Joomla extensions (especially plugins) work, and how to create them. The Joomla Documentation website has a section on how to create a plugin for Joomla.

  2. Understand the DPCalendar API. The documentation section of our website has a page dedicated to DPCalendar developers, which explains in detail the various Events that your plugin should respond to, as well as an example plugin to give you an idea of how to write your own (also available on GitHub).

  3. Understand your external calendaring system’s API (if any). Knowing how the external APIs work is key to making your plugin – if you can’t interface with the external calendar, obviously your plugin will be useless.

Another example is our popular attachment extensions which allows with three lines of code to integrate drag and drop/copy paste attachment support for your own extension. To do that you have to write a Joomla plugin as well:

<?php
/**
 * @package    DPAttachments
 * @author     Digital Peak http://www.digital-peak.com
 * @copyright  Copyright (C) 2012 - 2014 Digital Peak. All rights reserved.
 * @license    http://www.gnu.org/licenses/gpl.html GNU/GPL
 */
defined('_JEXEC') or die();

JLoader::import('components.com_dpattachments.libraries.dpattachments.core', JPATH_ADMINISTRATOR);

// If the component is not installed we fail here and no error is thrown
if (! class_exists('DPAttachmentsCore'))
{
	return;
}

class PlgContentDpattachments extends JPlugin
{

	public function onContentAfterDisplay ($context, $item, $params)
	{
		if (! isset($item->id))
		{
			return '';
		}

		$catIds = $this->params->get('cat-ids');
		if (isset($item->catid) && ! empty($catIds) && ! in_array($item->catid, $catIds))
		{
			return '';
		}

		$options = new JRegistry();
		$options->set('render.columns', $this->params->get('column_count', 2));
		return DPAttachmentsCore::render($context, (int) $item->id, $options);
	}

	public function onContentAfterDelete ($context, $item)
	{
		return DPAttachmentsCore::delete($context, (int) $item->id);
	}
}

 

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.