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
- wk1.xml: Installations File
- site/wk1.php: ruft Controller auf
- site/models/wk1.php Modell: class Wk1ModelWk1 extends JModelItem
- site/views/wk1/view.html.php deklariert class Wk1ViewWk1 extends JViewLegacy
- site/views/wk1/tmpl/default.php: default template, wird von JViewLegacy::display included
comp_wk1_3: add request parameter zum MenuItem
- site/views/wk1/tmpl/default.xml: dieser Parameter wird in die link Url im MenuItem eincodiert -
- site/models/wk1.php Modell: holt parameter aus input, falls ?menuTxt=... im URL wird dieser Wert genommen, sonst der im MenuItem
Achtung: evt. muss MenuItem editiert und Type neu selektiert werden, damit Link richtig gesetzt wird
comp_wk1_4: add database (frontend)
- wk1.xml: Installation
- admin/sql/updates/mysql/0.0.4.sql create table (update)
- admin/sql/install.mysql.utf8.sql: create table (new install)
- admin/sql/uninstall.mysql.utf8.sql: drop table
- site/views/wk1/view.html.php title aus Modell holen, gemäss titleId aus input
- site/models/wk1.php Modell holt Titel aus JTable
- admin/tables/wk1.php JTable holt Title aus DB
- site/views/wk1/tmpl/default.xml titleId Feld (für admin!!!) mit JFormFieldList verlinken
- admin/models/fields/wk1title.php JFormFieldList Subclass
Achtung: evt. muss MenuItem editiert und Type neu selektiert werden, damit Link richtig gesetzt wird
comp_wk1_5: add translations and backend Editor
language
- wk1.xml: Installation ==> spezielle Syntax für Language
- site/language/en-GB/en-GB.com_wk1.ini Uebersetzungen für Frontend, zurzeit leer
- admin/language/en-GB/en-GB.com_wk1.sys.ini: Uebersetzungen Backend
- admin/language/de-CH/de-CH.com_wk1.ini: Uebersetzungen Backend
view wk1s: list table in backend
- admin/wk1.php: Aufruf von Controller für MVC
- admin/controller.php controller Wk1Controller
- admin/views/wk1s/view.html.php view für Liste, inkl. Toolbar
- admin/views/wk1s/tmpl/default.php layout für Liste, inkl. Link für Edit pro Row bzw. für ausgewählte Objekte
- admin/models/helloworlds.php und das Model (für die Liste)
view wk1: edit one row
- admin/controllers/wk1s.php: Controller Wk1ControllerWk1s für Liste
- admin/controllers/wk1.php controller Wk1ControllerWk1 für Row Action
- admin/views/wk1/view.html.php edit view
- admin/views/wk1/tmpl/edit.php edit layout
- admin/models/wk1.php das Modell
- admin/models/forms/wk1.xml und die Form Beschreibung
comp_wk1_6: form verifications in javaScript
- wk1.xml: Installation
- admin/views/wk1/tmpl/edit.php: add js for validation
- admin/models/forms/wk1.xml: sagt, dass das greeting Feld validiert werden soll
- admin/models/forms/wk1.js: javascript für Validation
- admin/views/wk1/submitbutton.js: Funktion für Submit
- admin/views/wk1/view.html.php: aktiviert js
- admin/models/wk1.php: getscript methode
- admin/models/rules/greeting.php: Server Side Verifikation (redundant zu js ...)
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
- install the component from directory comp_fileprotect and publish it
- create/modify a menuItem, select MenuItemType FileProtect
- set Alias to the name you want to see in SEF paths
- set PathPrefix to the directory you want to be able to access (this is the security scope)
- set getFile to the file within PathPrefix to access. This can be overwritten by the URI
- set access to whoever is allowed to access all files in the PathPrefix directory
- use with a menu: use the above menuItem to access the file
- 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
- create a new menu
- create the corresponding menu module and assign an unvisible/unused position to this module