SEF Service Map automatically detects multi-language sites and generates site maps for each language version. It does not require and other actions from the user.

SEF Service Map 2

A Free Sitemap for Joomla 1.5

Home For Programmers / API
For Programmers
How to write your own integrator PDF Print E-mail
Written by Radoslaw Kubera   
Friday, 14 November 2008 21:17
I will base the description on one of the basic integrators – contact integrator (com_contact_bot), because of its simplicity.

In general, the aim of the integrator is to check what link has been assigned in the menu and return a relevant item tree.
In case of this example the component can be published in two ways:
- as a contacts category – in such case the following link type is being assigned to menu:
index.php?option=com_contact&view=category&catid=5
- as a contact item - in such case the following link type is being assigned to menu:
index.php?option=com_contact&view=contact&id=1
In the beginning, you should check the link parameters (view parameter for the above links) and depending on the outcome return the relevant item tree (for a category) or return nothing (for a contact item).

The situation is different for content integrator. If the link is relevant to a section, you should return a tree consisting of categories and content items. If the link is relevant to a category, you should return content items only. If it is relevant to a content item, you should return nothing.

An integrator is a standard Joomla! plugin. It differs from others by:
  • it should install itself in com_sefservicemap folder;
  • depending on the name of the component it should be named [component name]_bot. This regards also the filenames: [component name]_bot.php and [component name]_bot.xml. As you see, for a contact integrator, it should contain at least two files: com_contact_bot.php and com_contact_bot.xml. Contact integrator includes also a picture of the contact item, so the whole contact integrator should consist of three files.
  • plugin should contain function named [component name]_bot. Example:
function com_contact_bot ( $level, $link, $Itemid, $params ) {
    .....
    AddExtMenuitem ($element);
    .....

}
where:
$level – this is the level on the map tree. Level 0 means root. Each subsequent $level number will be larger by 1.
$link – this is the link connected in the menu to a specific item.
$Itemid – this is a menu id;
$params – this is JParameter object along with parameters signed to the integrator (returned on the basis of XML file definition of integrator);

There are two additional functions:
- AddExtMenuitem (  $element); - adds an element to the map;
- smGetParam ( $link, $what, $default ); - gets parameters from the link;

function smGetParam
IN:
smGetParam ( $link, $what, $default );
is a counterpart of JRequest.
$what – this is the parameter we seek;
$default – default value returned when the value of parameter is not;

OUT:
$value
function AddExtMenuitem
IN:
AddExtMenuitem ( $element );
$element = stdClass();
$element->name – name of the item (in this case contact name);
$element->link – contact link -  'index.php.....Itemid='.$Itemid The component will automatically change links to SEF when it is required;
$element->level – indicates the level on which the item should be listed;
$element->lastmod – indicates the last modification date of an item;
$element->image – picture which should be shown by a given item;
$element->icon_path - '/plugins/com_sefservicemap/' by default. Path where the picture is.
$element->priority and $element->changefreq – data returned to XML map consistent with http://sitemaps.org specifications

OUT:
null

Requested elements are name and link. If possible, you should return lastmod parameter – it will enable the map detect, whether given item has been modified or not and based on the outcome, whether it should be addend to the pinging queue;

This is a full list of contact integrator contents:

This is Manifest XML along with indication of integrator’s elements:
<?xml version="1.0" encoding="iso-8859-1"?>
<install version="1.5" type="plugin" group="com_sefservicemap">
    <name>SEF SM Contacts Integrator for Joomla 1.5.x</name>
    <author>Radoslaw Kubera</author>
    <creationDate>November 2008</creationDate>
    <copyright>(C) Radoslaw Kubera</copyright>
    <license>http://www.gnu.org/copyleft/gpl.html GNU/GPL</license>
    <authorUrl>www.sefservicemap.com</authorUrl>
    <version>2.0</version>
    <description>This plugin require SEF Service Map Component</description>
    <files>
        <filename plugin="com_contact_bot">com_contact_bot.php</filename>
        <filename>contact_people.gif</filename>
    </files>
    <params>
        <param name="show_item_icons" type="radio" default="1" label="Show contact icon" description="Show contact icon" >
            <option value="1">Show</option>
            <option value="0">Hide</option>
        </param>
        <param name="priority" type ="list" default="" label="Priority" description="The priority of integrator URLs relative to other URLs on your site.">
            <option value="">Default</option>
            <option value="0.0">0.0</option>
            <option value="0.1">0.1</option>
            <option value="0.2">0.2</option>
            <option value="0.3">0.3</option>
            <option value="0.4">0.4</option>
            <option value="0.5">0.5</option>
            <option value="0.6">0.6</option>
            <option value="0.7">0.7</option>
            <option value="0.8">0.8</option>
            <option value="0.9">0.9</option>
            <option value="1.0">1.0</option>
        </param>
        <param name="changefreq" type ="list" default="" label="Change frequency" description="How frequently the pages are likely to change.">
            <option value="">Default</option>
            <option value="always">Always</option>
            <option value="hourly">Hourly</option>
            <option value="daily">Daily</option>
            <option value="weekly">Weekly</option>
            <option value="monthly">Monthly</option>
            <option value="yearly">Yearly</option>
            <option value="never">Never</option>
        </param>
    </params>
</install>
This is how php file looks like:
<?php
/* Function return contact list for $id category */
function Contact_items ($level, $id,$Itemid,$params) {

    /* get integrator parameters */
    $priority=$params->get( 'priority', '' ) ;
    $changefreq=$params->get( 'changefreq', '' );
    $show_item_icons=intval($params->get( 'show_item_icons', '1' )) ;

    $db = JFactory::getDBO();
    $user    = &JFactory::getUser();
    $aid    = (int) $user->get('aid', 0);

    /*  query to database */
    if ($id) $cat_sel = " and a.catid='".$id."'"; else $cat_sel='';
    $db->setQuery("SELECT a.*, b.alias as 'catalias' FROM #__contact_details AS a LEFT JOIN #__categories AS b ON a.catid = b.id
            where a.published >='1'".$cat_sel." and a.access<='$aid' order by a.ordering");
    $items=$db->loadObjectList();

    /* one level down */
    $lev=$level+1;

    if (count($items!=0)) {
        foreach ($items as $item) {

            /* set element parameters */
            $link="index.php?option=com_contact&view=contact&id=".$item->id.":"
            .$item->alias."&catid=".$item->catid.";".$item->catalias."&Itemid=".$Itemid;
            $element->name = $item->name;
            $element->link = $link;
            $element->level = $lev;
            $element->priority = $priority;
            $element->changefreq= $changefreq;
            if ($show_item_icons) $element->image = 'contact_people.gif'; else $element->image='none';
            $element->icon_path='/plugins/com_sefservicemap/';

            /* add element to site map */
            AddExtMenuItem ($element);
        }
    }
}

/* Start */
function com_contact_bot ($level,$link,$Itemid,$params) {
    $catid = smGetParam($link,'catid',0);
    $view = smGetParam($link,'view','');
    if ($view=='category') Contact_items ($level,$catid,$Itemid,$params);
}
?>

These are the steps to be taken by the integrator:
  • in the first place, the com_contact_bot procedure is executed
  • the procedure indicates what item tree should be screened (contact, category);
  • if category, goes to function Contact_items(); if not, it terminates;
  • gets integrator’s parameters values;
  • asks the database for contacts in the given category;
  •  for each contact in a category prepares each element accordingly and adds to site map using AddExtMenuItem() function.
For diagnostic purposes, it is advised to install plugins by the standard Joomla! interface for plugins and not by component’s interface. This is because SEF Service Map has a reduced message list regarding errors in installation..

Last Updated ( Friday, 14 November 2008 23:24 )