Joomla programming - components

components tun mehr. Oft backend und frontend logik, eigene Tabellen (anpassungen) etc..

component tutorial

comp_wk1_1: minimal component

  • wk1.xml: Installations File
  • site/wk1.php: Site Component: produziert output
  • admin/wk1.php: Admin Component: enthält nur Namen
  • site/views/wk1/tmpl/default.xml: aktiviert und benamst Komponent als menu item type - fehlt das, kann die Komponente zwar mit dem link aus wk1.xml im Frontend aufgerufen, aber im Backend nicht konfiguriert werden

Installieren

Dann muss man die Komponente

  • installieren, (extension manager, z.B. ab Directory)
  • erscheint unter administrator->Components, da kann man aber zurzeit nichts einstellen
  • kann als menu item type gewählt werden

comp_wk1_2: add MVC: model view controller

comp_wk1_3: add request parameter zum MenuItem

Achtung: evt. muss MenuItem editiert und Type neu selektiert werden, damit Link richtig gesetzt wird

comp_wk1_4: add database (frontend)

Achtung: evt. muss MenuItem editiert und Type neu selektiert werden, damit Link richtig gesetzt wird

comp_wk1_5: add translations and backend Editor

language

view wk1s: list table in backend

view wk1: edit one row

comp_wk1_6: form verifications in javaScript

comp_fileprotect: file protect component

  • com_fileprotect0_1.zip zip of the whole package directory ⇒ to use as installation package file for JoomlaAdministrator →extensions→manage→uploadPackageFile or installFromWeb
  • fileprotect.xml: installation
  • site/fileprotect.php:
    • get pathPrefix from MenuItem Parameter and getFile from Input.
    • Verify that both are non Empty, the resulting file JPATH_SITE/PathPrefix/getFile sits in directory JPATH_SITE/PathPrefix and is a regular readable file
    • deduce mime-content-type from extension (or alternatively using php function ) and send contents of file back
  • site/router.php: SEF Router: uri variable getFile ⇔ uri path (after menu item alias)
  • site/views/fileprotect/tmpl/default.xml: add to menuItem PathPrefix as Parameter getFile as URI Variable
  • admin/fileprotect.php: trivial admin interface
  • admin/language/en-GB/: language en-GB...

goal

If you have a pdf, xls or any other filetype that you want to allow to read only to limited audience, you put the link in an article or menu item with the corresponing access. Thus the link is not presented to unauthorized users. However, if they get or guess the link, the can anyway read the should be protected file.

To avoid this

  • protect the file by appache2, e.g. by AuthType Basic in a directory. However, this needs a second login, additionally to the login to joomla.
  • let joomla serve the content after doing the authorization check

This component implements the second approach

install and use

  1. install the component from directory comp_fileprotect and publish it
  2. create/modify a menuItem, select MenuItemType FileProtect
    1. set Alias to the name you want to see in SEF paths
    2. set PathPrefix to the directory you want to be able to access (this is the security scope)
    3. set getFile to the file within PathPrefix to access. This can be overwritten by the URI
    4. set access to whoever is allowed to access all files in the PathPrefix directory
  3. use with a menu: use the above menuItem to access the file
  4. use with links: in an article put links of the form index.php?option=com_fileprotect&Itemid=251&getFile=abc/my.xls&Itemid=251 with the following URI Variables
    • option ⇒ component fileprotect
    • ItemId ⇒ the Id of the menuItem from above
    • getFile ⇒ the file to access
    • if the menuItem should not be visible to the user (but only used to route read request) attach the menuItem to a hidden Menu. To create a hidden menu proceed as follows
      1. create a new menu
      2. create the corresponding menu module and assign an unvisible/unused position to this module