Vous êtes sur la page 1sur 58

Developing a Joomla 3.

1 Module

Peter Martin, twitter: @pe7er www.joomladay.org.za, Sat Oct 19th 2013

Overview Presentation
1.

Extensions, an introduction 2. Module basics 3. Database >>>Sheetsvia:www.db8.nl<<< 4. OOP 5. Parameters 6. Language File 7. Views 8. Parameters Advanced 9. Package 10. Update
Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 2

1. Extensions, an introduction

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 3

1. Extensions 5 types
Extending Joomla's functionality: 1. Components 2. Modules 3. Plugins 4. Templates 5. Language Files

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 4

1. Extensions Component

Determines functionality of a page Multiple Modi: CRUD (Create, Read, Update, Delete) Only one component on a page Activation via URL + &option=com_componentname Example com_content

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 5

1. Extensions Module

Supportive, Widget, only display to screen (Module Positie) One mode (e.g. Read from database & Display) Multiple modules on a page Activation via menu item: URL + &Itemid=x Example mod_breadcrumbs

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 6

1. Extensions Plugin

Supportive. Works invisible in background. One mode: does one thing (e.g. search & replace) Multiple plugins at a time Activation via certain events (of hooks) in components Example Plugin Content - Email Cloaking

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 7

1. Extensions Working together


Joomla's search functionality
Module
C Form M Form

(M) (C)
C Processing P Search in database table P Search in database table P Search in database table C Results

Search inputbox Form Results

Component

Plugin

(P)

Articles Categories Contacts

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 8

1. Extensions Modules in Template


Display

Module Positions:

Extensions > Template Manager > Preview Module Positions: enabled URL + ?tp=1

Code

for Module Position in Template: /templates/template_name/index.php


<?phpif($this>countModules('modposnaam')):?> <jdoc:includetype="modules"name="modposnaam"style="none"/> <?phpendif;?>

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 9

2. Module basics

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 10

2. Module basics

Location:

Front-end: /modules/mod_name Back-end: /administrator/modules/mod_name mod_name.php code mod_name.xml installation & parameters #__extensions
name=Module Name type=module element=mod_name folder={emply} client_id: 0 = front-end, 1 = back-end

Files:

Database reference

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 11

2. Module basics: example


Joomla's

Weblinks Component com_weblinks

Weblinks in a Weblink category Counts clicks

Database

tabel: #__weblinks

id, catid, title, url, description, created, hits, state, catid

Joomla's

Weblinks Module

created date *not* used

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 12

2. Module Latest Weblinks


Develop Module: Display most recent added weblinks

Folder: /modules/mod_db8latestweblinks/ With files:


mod_db8latestweblinks.php

<?php defined('_JEXEC') or die; echo "Peter's Recent Weblinks!"; mod_db8latestweblinks.xml {next sheet}

Installation:
Extensions

> Extension Manager > Discover Extensions > Module Manager > [New]

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 13

2. Module Latest Weblinks


Manifest file: mod_db8latestweblinks.xml
<?xmlversion="1.0"encoding="utf8"?> <extensiontype="module"version="3.1"client="site"method="upgrade"> <name>db8LatestWeblinks</name> <author>PeterMartin</author> <creationDate>September2013</creationDate> <copyright>(C)2013PeterMartin.Allrightsreserved.</copyright> <license>GNUGeneralPublicLicenseversion2orlater;</license> <authorEmail>joomla@db8.nl</authorEmail> <authorUrl>www.db8.nl</authorUrl> <version>2.0</version> <description>MOD_DB8LATESTWEBLINKS_XML_DESCRIPTION</description> <files> <filenamemodule="mod_db8latestweblinks">mod_db8latestweblinks.php</filename> <filename>mod_db8latestweblinks.xml</filename> </files> </extension>

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 14

2. Module Latest Weblinks

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 15

3. Module Database

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 16

3. Module Database
Joomla Database Object
1.Call Joomla's Database Object 2.Instantiate an empty Query Object 3.Build Query Object
do NOT use hardcoded MySQL! SELECT * FROM #__weblinks ORDER BY created DESC

4.Feed Query Object to Database Object 5.Retrieve Results from Database Object

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 17

3. Module Database
mod_db8latestweblinks.php
defined('_JEXEC')ordie; $db=Jfactory::getDbo(); $query=$db>getQuery(true); $query>select('*') >from('#__weblinks') >order('createdDESC'); $db>setQuery($query,0,7); $items=$db>loadObjectList(); ?> <ul> <?phpforeach($itemsAS$item):?> <li><?phpecho$item>title;?></li> <?phpendforeach;?> </ul>

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 18

3. Module Database
Debug: echo "sql = $query"; print_r($items); HTML

Google Chrome Inspect Element FireFox + FireBug addon

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 19

4. Module OOP style

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 20

4. Module OOP style


Object

Oriented Programming

Separation between logic & screen output

MVC

(Model/View/Controller) architecture:

Model describes data

View determines screen output Controller controls what happens

CRUD Create Read Update Delete

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 21

4. Module OOP style


A

Module's Model Controller View:


Model helper.php file retrieve records from database View /tmpl/name.php HTML output for template overrides! Controller the module itself (1 mode: display)

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 22

4. Module OOP style: Model


/modules/mod_db8latestweblinks/ helper.php
defined('_JEXEC')ordie; classmodDb8latestweblinksHelper { publicstaticfunctiongetItems($params) { $db=Jfactory::getDbo(); $query=$db>getQuery(true); $query>select('*') >from('#__weblinks') >order('createdDESC'); $db>setQuery($query,0,7); $items=$db>loadObjectList(); return$items; } }
Joomladay 2013 South Africa 23

Peter Martin joomladagen.nl 20+21 april 2013

4. Module OOP style: View


/modules/mod_db8latestweblinks/tmpl/ default.php
defined('_JEXEC')ordie; ?> <ul> <?phpforeach($itemsAS$item):?> <li><?phpecho$item>title;?></li> <?phpendforeach;?> </ul>

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 24

4. Module OOP style: Controller


/modules/mod_db8latestweblinks/ mod_db8latestweblinks.php
defined('_JEXEC')ordie; require_oncedirname(__FILE__).'/helper.php'; $items= modDb8latestweblinksHelper::getItems($params); requireJmoduleHelper::getLayoutPath( 'mod_db8latestweblinks',$params>get('layout', 'default'));

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 25

4. Module OOP style


Exactly

output!

the same

Template override possible

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 26

5. Parameters

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 27

5. Parameters
Flexibility

Categories Limit results Target Window Follow/No Follow Display: Date, Description (hover), Hits Count clicks / or not Display: Published / unpublished

.xml

define choices Helper.php use parameters in SQL query

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 28

5. Parameters Choices
/modules/mod_db8latestweblinks/

mod_db8latestweblinks.xml

<config> <fieldsname="params"> <fieldsetname="basic"> <field/> </fieldset> <fieldsetname="advanced"> <field/> </fieldset> </fields> </config>
Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 29

5. Parameters Choices
/modules/mod_db8latestweblinks/

mod_db8latestweblinks.xml

<fieldsetname="basic"> <fieldname="catid" type="category" extension="com_weblinks" multiple="true" required="true" label="Category" description="SelectWeblinkcategory"/> <fieldname="count" type="text" default="5" label="Number" description="DisplaynumberWeblinks"/> </fieldset>
Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 30

5. Parameters
/modules/mod_db8latestweblinks/

helper.php

publicstaticfunctiongetItems($params){ $db=Jfactory::getDbo(); $query=$db>getQuery(true); $query>select('*') >from('#__weblinks') >order('createdDESC'); $catid=$params>get('catid'); if(is_array($catid)){ if($catid[0]!=null){ $catid=implode(',',$catid); $query>where('catidIN('.$catid.')'); } } $db>setQuery($query,0,$params>get('count',5)); $rows=$db>loadObjectList(); return$rows; }

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 31

5. Parameters Choices

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 32

6. Language File

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 33

6. Language File
Flexibility

Regarding distribution & Language Override !

Language labels in .xml, and JText in .php Location Front-end:

In language files folder: /language/en-GB/en-GB.mod_name.ini /language/en-GB/en-GB.mod_name.sys.ini Or in Module, e.g.: /modules/mod_db8latestweblinks/language/en-GB/ en-GB.mod_db8latestweblinks.ini /modules/mod_db8latestweblinks/language/en-GB/ en-GB.mod_db8latestweblinks.sys.ini

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 34

6. Language File

/modules/mod_db8latestweblinks/ mod_db8latestweblinks.xml
<fieldname="catid" type="category" extension="com_weblinks" multiple="true" required="true" label="JCATEGORY" description="MOD_DB8LATESTWEBLINKS_ FIELD_CATEGORY_DESC"/> <fieldname="count" type="text" default="5" label="MOD_DB8LATESTWEBLINKS_FIELD_COUNT_LABEL" description="MOD_DB8LATESTWEBLINKS_ FIELD_COUNT_DESC"/> </fieldset>

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 35

6. Language File

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 36

6. Language File

/language/en-GB/en-GB.mod_db8latestweblinks.ini
MOD_DB8LATESTWEBLINKS_FIELD_CATEGORY_DESC="Choosetheweblinkscategorytodisplay" MOD_DB8LATESTWEBLINKS_FIELD_COUNT_DESC="Numberofweblinkstodisplay" MOD_DB8LATESTWEBLINKS_FIELD_COUNT_LABEL="Count"

/language/en-GB/en-GB.mod_db8latestweblinks.sys.ini
MOD_DB8LATESTWEBLINKS="WeblinksLatest" MOD_DB8LATESTWEBLINKS_XML_DESCRIPTION="Thismodulesdisplaysthelatestweblinks fromacategorydefinedintheWeblinkscomponent."

/language/de-DE/de-DE.mod_db8latestweblinks.ini
MOD_DB8LATESTWEBLINKS="WeblinksNeueste" MOD_DB8LATESTWEBLINKS_XML_DESCRIPTION="DiesesModulzeigtdieallerneuestenWeblinks auseinerKategorieinderWeblinksKomponentedefiniert." MOD_DB8LATESTWEBLINKS_FIELD_CATEGORY_DESC="WhlenSiedieKategorieWebLinks angezeigtwerden" MOD_DB8LATESTWEBLINKS_FIELD_COUNT_LABEL="Anzahl" MOD_DB8LATESTWEBLINKS_FIELD_COUNT_DESC="AnzahlanangezeigtenWeblinks"

/language/de-DE/de-DE.mod_db8latestweblinks.sys.ini
MOD_DB8LATESTWEBLINKS="WeblinksNeueste" MOD_DB8LATESTWEBLINKS_XML_DESCRIPTION="DiesesModulzeigtdieallerneuestenWeblinks auseinerKategorieinderWeblinksKomponentedefiniert."

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 37

6. Language File

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 38

7. Views

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 39

7. Views
View

= HTML Output HTML output? Template override!

/modules/mod_db8latestweblinks/tmpl/default.php /templates/your_template/html/ mod_db8latestweblinks/default.php

Change

Create

choices for admins?

Layout choice parameter /modules/mod_db8latestweblinks/ mod_db8latestweblinks.xml Alternatieve view /modules/mod_db8latestweblinks/tmpl/ alternative_view.php


Joomladay 2013 South Africa 40

Peter Martin joomladagen.nl 20+21 april 2013

7. Views Layout choice parameter


/modules/mod_db8latestweblinks/ mod_db8latestweblinks.xml
<fieldsetname="advanced"> <fieldname="layout" type="modulelayout" label="JFIELD_ALT_LAYOUT_LABEL" description="JFIELD_ALT_MODULE_LAYOUT_DESC" /> </fieldset>

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 41

7. Views Alternative layout


/modules/mod_db8latestweblinks/tmpl/ withdate.php
defined('_JEXEC')ordie; ?> <ul> <?phpforeach($itemsAS$item):?> <li><?phpecho$item>created."".$item>title;?></li> <?phpendforeach;?> </ul>

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 42

8. Parameters Advanced

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 43

8. Parameters Advanced
Advanced

Options

Alternative Layout (see 7. Views) Module Class Suffix Caching Cache Time

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 44

8. Parameters Advanced
<fieldsetname="advanced"> <fieldname="moduleclass_sfx" type="text" label="COM_MODULES_FIELD_MODULECLASS_SFX_LABEL" description="COM_MODULES_FIELD_MODULECLASS_SFX_DESC"/> <fieldname="cache" type="list" default="1" label="COM_MODULES_FIELD_CACHING_LABEL" description="COM_MODULES_FIELD_CACHING_DESC"> <optionvalue="1">JGLOBAL_USE_GLOBAL</option> <optionvalue="0">COM_MODULES_FIELD_VALUE_NOCACHING</option> </field> <fieldname="cache_time" type="text" default="900" label="COM_MODULES_FIELD_CACHE_TIME_LABEL" description="COM_MODULES_FIELD_CACHE_TIME_DESC"/> <fieldname="cachemode" type="hidden" default="static"> <optionvalue="static"></option> </field> </fieldset>

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 45

9. Packaging (for distribution)

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 46

9. Packaging (for distribution)


Installable Contents:

package: mod_name_j3x_v2.zip

mod_db8latestweblinks.xml mod_db8latestweblinks.php helper.php

Language

file folder + files:

/language/en-GB/en-GB.mod_db8latestweblinks.ini /language/en-GB/en-GB.mod_db8latestweblinks.sys.ini /language/de-DE/de-DE.mod_db8latestweblinks.ini /language/de-DE/de-DE.mod_db8latestweblinks.sys.ini

HTML

output folder + files:


Joomladay 2013 South Africa 47

/tmpl/default.php /tmpl/with-date.php

Peter Martin joomladagen.nl 20+21 april 2013

9. Packaging (for distribution)


Installation

xml manifest file: mod_db8latestweblinks.xml


<files> <filename module="mod_db8latestweblinks"> mod_db8latestweblinks.php</filename> <filename>mod_db8latestweblinks.xml</filename> <filename>helper.php</filename> <folder>tmpl</folder> <folder>language</folder> </files>

TEST!

At other webserver / website


Joomladay 2013 South Africa 48

Peter Martin joomladagen.nl 20+21 april 2013

10. Update

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 49

10. Update
In

your Module:
Manifest .xml file with <updateservers>

On

your distribution server:

.xml file with Module version information .zip archive to download

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 50

10. Update .xml manifest file


/modules/mod_db8latestweblinks/

mod_db8latestweblinks.xml

<updateservers> <servertype="extension"priority="1" name="mod_db8latestweblinks"> http://www.db8.nl/updates/ mod_db8latestweblinks.xml</server> </updateservers>

Do

not use spaces or line breaks between the <server> tags!


Joomladay 2013 South Africa 51

Peter Martin joomladagen.nl 20+21 april 2013

10. Update .xml server file


Location as specified in .xml manifest file: http://www.db8.nl/update/mod_db8latestweblinks.xml
<?xmlversion="1.0"encoding="utf8"?> <updates> <update> <name>db8LatestWeblinks</name> <element>mod_db8latestweblinks</element> <type>module</type> <client>0</client> <version>2.1</version> <infourltitle="mod_db8latestweblinks"> http://www.db8.nl/someurl/ </infourl> [seenextpage]

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 52

10. Update .xml server file


<downloads> <downloadurltype="full"format="zip"> http://www.db8.nl/updates/ mod_db8latestweblinks_j3x_v21.zip </downloadurl> </downloads> <maintainer>PeterMartin</maintainer> <maintainerurl>http://www.db8.nl</maintainerurl> <section>db8</section> <targetplatformname="joomla"version="3.1"/> </update> </updates>

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 53

10. Update Database Reference


Update

mechanism: Extensions > Extension Manager > [Update]


[Find Updates] creates reference in #__updates Nothing found?
Check

URL .xml file in browser Reinstall Module

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 54

The

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 55

Questions?

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 56

Questions?
Presentation

available at www.db8.nl

Peter Martin e-mail: info at db8.nl website: www.db8.nl

Peter Martin joomladagen.nl 20+21 april 2013

Joomladay 2013 South Africa 57

Used Photos

Speed Typing - Matthew Bowden http://www.sxc.hu/photo/275499 Motherboard 4 - Lisa Zanchi http://www.sxc.hu/photo/103914 ram Mohamed Riffath http://www.sxc.hu/photo/487296 lots of files 2 - Michael & Christa Richert http://www.sxc.hu/photo/1370555 Blank E-Box for Software etc 6 - Przemyslaw Szczepanski, http://www.sxc.hu/photo/950048 switches - "trhaynes", http://www.sxc.hu/photo/56670 Bengali Keyborad - Mohammad Jobaed Adnan http://www.sxc.hu/photo/676844 san sebastian views 1 - ibon san martin http://www.sxc.hu/photo/94018 Communications Receiver - John Munsch http://www.sxc.hu/photo/260775 Fragile Parcel - Richard Dudley http://www.sxc.hu/photo/1279274 Sparks - Hector Landaeta http://www.sxc.hu/photo/1184243 signs signs - Jason Antony, http://www.sxc.hu/photo/751034 Face - Questions - Bob Smith, http://www.sxc.hu/photo/418215
Joomladay 2013 South Africa 58

Peter Martin joomladagen.nl 20+21 april 2013

Vous aimerez peut-être aussi