Joomla! 1.0 component tutorial - part 2: back-end

8. Backend - toolbars

Toolbar is defined with help of two files:
  1. toolbar.jportfsimple.php
  2. toolbar.jportfsimple.html.php

toolbar.jportfsimple.php
  1. // no direct access
  2. defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  3.  
  4. require_once( $mainframe->getPath( 'toolbar_html' ) );
  5. $task = mosGetParam( $_REQUEST, 'task', '' );
  6. $act = mosGetParam( $_REQUEST, 'act', '' );
  7.  
  8. switch ( $task ) {
  9.  
  10.     case 'edit':
  11.     case 'new':
  12.       menujportfsimple::EDIT_MENU();
  13.     break;
  14.    
  15.     default:
  16.     switch($act)
  17.     {
  18.       case "configure":
  19.       case "css":
  20.         menujportfsimple::CONFIGURE_MENU();
  21.       break;
  22.      
  23.       case "info":
  24.         menujportfsimple::INFO_MENU();
  25.       break;
  26.  
  27.       case "categories":
  28.       case "projects":
  29.         menujportfsimple::DEFAULT_MENU();
  30.       break;
  31.      
  32.       default:
  33.        
  34.       break;   
  35.     }
  36.     break;
  37.   }

Depending on $act and $task it calls certain menu function from menujportfsimple class, which displays the right toolbar.

toolbar.jportfsimple.html.php
  1. // no direct access
  2. defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  3.  
  4.  
  5.  
  6. class menujportfsimple{
  7.  
  8.   function DEFAULT_MENU() {
  9.  
  10.     mosMenuBar::startTable();
  11.     mosMenuBar::publish('publish');
  12.     mosMenuBar::unpublish('unpublish');
  13.     mosMenuBar::divider();
  14.     mosMenuBar::addNew('new');
  15.     mosMenuBar::editList('edit', 'Edit');
  16.     mosMenuBar::deleteList( ' ', 'delete', 'Remove' );
  17.     mosMenuBar::divider();
  18.     mosMenuBar::endTable();
  19.     }
  20.  
  21.   function EDIT_MENU() {
  22.  
  23.     mosMenuBar::startTable();
  24.     mosMenuBar::cancel();
  25.     mosMenuBar::save('save');
  26.     mosMenuBar::endTable();
  27.   }
  28.  
  29.   function CONFIGURE_MENU() {
  30.  
  31.     mosMenuBar::startTable();
  32.     mosMenuBar::save('save');
  33.     mosMenuBar::endTable();
  34.   }
  35.  
  36.   function INFO_MENU() {
  37.  
  38.     mosMenuBar::startTable();
  39.     mosMenuBar::endTable();
  40.   }
  41. }

Each _MENU function uses startTable and endTable from mosMenuBar class at the beginning and at the end of a toolbar. Then it defines actual buttons using functions like: addNew, editList or save.



9. Backend - install, uninstall

Last two files contain functions which are run after installing or uninstalling a component.
  1. install.jportfsimple.php
  2. uninstall.jportfsimple.php
Both are almost identical, only the function name inside is different, and the constant used to display information.

install.jportfsimple.php
  1. // no direct access
  2. defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
  3.  
  4. function com_install() {
  5.   global $mosConfig_live_site, $mosConfig_absolute_path, $mosConfig_lang;
  6.   if (file_exists( $mosConfig_absolute_path."/components/com_jportfsimple/lang/". $mosConfig_lang.".php"))
  7.       include_once( $mosConfig_absolute_path."/components/com_jportfsimple/lang/". $mosConfig_lang.".php");
  8.    else
  9.    if (file_exists( $mosConfig_absolute_path."/components/com_jportfsimple/lang/english.php"))
  10.       include_once( $mosConfig_absolute_path."/components/com_jportfsimple/lang/english.php");
  11.    
  12.   echo _COM_JP_INFO_TOP;
  13.   echo _COM_JP_INSTALL1;
  14.  
  15.   echo _COM_JP_INFO_BOTTOM;
  16. }


10. Summary

In the above tutorial I tried to explain the structure and functions of sample component written for Joomla! CMS v. 1.0.12.