You are on page 1of 63

How to change Joomla without core hacks

>>> Sheets will be made available <<<

Peter Martin Joomladays Cape Town 2012


Friday 17 !"!st 2012 Sat!rday 1# !"!st 2012

Overview Presentation

$ntrod!%tion Core &a%' lternatives ( 1) Template override ( 2) Clone Mod!le ( *) +se o, Pl!"ins ( -) Component with .own %ontroller/ ( 0) 1verridin" Core %lasses ( 2) 3an"!a"e override +ndoin" %ore ha%'s 4!estions5

Core Hack

Core Hack
Joomla ( ( (

6 1pen So!r%e li%ense .78+ 7P3/ 7P3 prote%ts ,reedom 9 ri"hts o, !sers So!r%e %ode 6 p!bli% :o! can and are allowed to %han"e all Joomla %ode

Core Hack
;isadvanta"e o, %han"in" .%ore %ode/< Stability
(

Mi"ht "ive problems with *rd party e=tensions :o!r %ode %han"es %an be overwritten when yo! !p"rade

Maintainability
(

Core Hack Example: Contact Form

>isitor?s $P address is 81T displayed in email


2

Core Hack Example: Contact Form


$n%l!de

$P address with email<

@%omponents@%omA%onta%t@%ontrollers@%onta%t)php private ,!n%tion AsendBmailCDdataE D%onta%tFE G!st !nder @@ Prepare email body DmailH>setIodyCDbodyFJ %han"e into< DmailH>setIodyC"IP adres: " !"#E$%E$&'$E(O)E"*++$', "-n-n" DbodyFJ
7

Core Hack Example: Contact Form


Kes!lt

.until the next Joomla upgrade/<

;ate< SatE 17 !" 2012 10<*0<00 L0200 From< >isitor name <in,oMe=ample)%om> KeplyHTo< N8ame visitorO <Nemail address visitorO> To< Nemail address S!per dmin o, PebsiteO IP adres: 012 3 3 0 This is an enQ!iry email via http<@@www)e=ample)%om@ ,rom< N8ame visitorO <Nemail address visitorO> NMessa"e o, visitorO
#

0 )emplate override

0 )emplate override
Template
(

3ayo!t) SSpa%eS ,or o!tp!t %omponents 9 mod!les

Components
(

9 Mod!les

s!pply their own &TM3 o!tp!t to the template

Template
(

overrides Csin%e Joomla 1)0F

Chan"e &TM3 o!tp!t o, %omponents @ mod!les witho!t %ore ha%'s

10

Example0 4 5atest 6ews module


Mod!le

displays a list o, most re%ent arti%les 3atest 8ews


Ie"inners 7ettin" &elp 7ettin" Started JoomlaT 1ptions

Chan"e

reQ!est< %!stomer wants to in%l!de a dateT

11

Example0 4 5atest 6ews module


1a) Template override<

Create &TM3 override ,older in yo!r template<


@templates@yo!rAtemplate@html@

Create new ,older ,or mod!le override


@templates@yo!rAtemplate@html@mod"articles"latest@

Copy &TM3 o!tp!t ,rom @tmpl@ o, the mod!le<


@mod!les@modAarti%lesAlatest@tmpl@de,a!lt)php to @templates@yo!rAtemplate@html@modAarti%lesAlatest@de7ault php

12

Example0 4 5atest 6ews module


1b) Test template overrideT

dd some te=t 9 %he%' ,rontHend website


@templates@yo!rAtemplate@html@modAarti%lesAlatest@de,a!lt)php

1%) nalyse !se,!l variables with printAr<


<!l %lass6Slatestnews<5php e%ho Dmod!le%lassAs,=J 5>S> <5php ,orea%h CDlist as DitemF < 5> <li>89php print"r.!item/:9; <a hre,6S<5php e%ho DitemH>lin'J 5>S> <5php e%ho DitemH>titleJ 5><@a> <@li> <5php end,orea%hJ 5>

<@!l>
1*

Example0 4 5atest 6ews module


stdClass 1bGe%t C NidO 6> # NtitleO 6> Ie"inners NaliasO 6> be"inners NtitleAaliasO 6> Nintrote=tO 6> $, this is yo!r ,irst JoomlaT site or yo!r ,irst web siteE yo! have %ome to the ri"ht pla%e) Joomla will help yo! "et yo!r website !p and r!nnin" Q!i%'ly and easily) Start o,, !sin" yo!r site by lo""in" in !sin" the administrator a%%o!nt yo! %reated when yo! installed Joomla) N%he%'edAo!tO 6> 0 N%he%'edAo!tAtimeO 6> 0000H00H00 00<00<00 N%atidO 6> 1R &created, <; 1300=30=30 33:33:30 N%reatedAbyO 6> -2 N%reatedAbyAaliasO 6> JoomlaT Nmodi,iedO 6> 2011H12H27 11<10<-R Nmodi,iedAbyO 6> -2 Nmodi,iedAbyAnameO 6> S!per +ser Np!blishA!pO 6> 2011H01H01 00<00<01 Np!blishAdownO 6> 0000H00H00 00<00<00 Nima"esO 6> USima"eAintroS<SSES,loatAintroS<SSESima"eAintroAaltS<SSESima"eAintroA%aptionS<SSESima"eA,!llte=tS<SSES,loatA,!llte =tS<SSESima"eA,!llte=tAaltS<SSESima"eA,!llte=tA%aptionS<SSV N!rlsO 6> US!rlaS<SSES!rlate=tS<SSEStar"etaS<SSES!rlbS<SSES!rlbte=tS<SSEStar"etbS<SSES!rl%S<SSES!rl%te=tS<SSEStar"et%S<SSV NattribsO 6> USshowAtitleS<SSESlin'AtitlesS<SSESshowAintroS<SSESshowA%ate"oryS<SSESlin'A%ate"oryS<SSESshowAparentA%ate"ory S<SSESlin'AparentA%ate"oryS<SSESshowAa!thorS<SSESlin'Aa!thorS<SSESshowA%reateAdateS<SSESshowAmodi,yAdateS <SSESshowAp!blishAdateS<SSESshowAitemAnavi"ationS<SSESshowAi%onsS<SSESshowAprintAi%onS<SSESshowAemailAi %onS<SSESshowAvoteS<SSESshowAhitsS<SSESshowAnoa!thS<SSESalternativeAreadmoreS<SSESarti%leAlayo!tS<SSESshow Ap!blishin"AoptionsS<SSESshowAarti%leAoptionsS<SSESshowA!rlsAima"esAba%'endS<SSESshowA!rlsAima"esA,ro ntendS<SSV NmetadataO 6> USrobotsS<SSESa!thorS<SSESri"htsS<SSES=re,eren%eS<SSV Nmeta'eyO 6> Nmetades%O 6> Na%%essO 6> 1 NhitsO 6> 2 N=re,eren%eO 6> N,eat!redO 6> 1 NreadmoreO 6> 1-## NstateO 6> 1 N%ate"oryAtitleO 6> JoomlaT N%ate"oryAro!teO 6> sampleHdataHarti%les@Goomla N%ate"oryAa%%essO 6> 1 N%ate"oryAaliasO 6> Goomla Na!thorO 6> JoomlaT Na!thorAemailO 6> Goomlada"enMdb#)nl N%onta%tidO 6> NparentAtitleO 6> Sample ;ataH rti%les NparentAidO 6> 1- NparentAro!teO 6> sampleHdataHarti%les NparentAaliasO 6> sampleHdataH arti%les Nratin"O 6> Nratin"A%o!ntO 6> Np!blishedO 6> 1 NparentsAp!blishedO 6> 1 NalternativeAreadmoreO 6> Nlayo!tO 6> NparamsO 6> JKe"istry 1bGe%t C Ndata<prote%tedO 6> stdClass 1bGe%t C Narti%leAlayo!tO 6> A<de,a!lt NshowAtitleO 6> NWO

1-

Example0 4 5atest 6ews module


1d) dd to override !item=;created<
<5php ,orea%h CDlist as DitemF < 5> <li> <a hre,6S<5php e%ho DitemH>lin'J 5>S> <5php e%ho !item=;created " = " DitemH>titleJ 5><@a> <@li> <5php end,orea%hJ 5>

1!tp!t< 3atest 8ews


2011H01H01 00<00<01 ( Ie"inners 2011H01H01 00<00<01 H 7ettin" &elp 2011H01H01 00<00<01 H 7ettin" Started 2011H01H01 00<00<01 H JoomlaT 2011H01H01 00<00<01 H 1ptions

10

Example0 4 5atest 6ews module


1e) date@time ,rom database in +TC ,ormat To !se .Server Time Xone/<
D%on,i" 6 J,a%tory<<"etCon,i"CFJ D!ser 6 J,a%tory<<"et+serCFJ 5> <!l %lass6Slatestnews<5php e%ho Dmod!le%lassAs,=J 5>S> <5php ,orea%h CDlist as DitemF < Ddate 6 JFa%tory<<"et;ateCDitemH>%reatedE ?+TC?FJ DdateH>setTimeYoneCnew ;ateTimeXoneCD!serH>"etParamC?timeYone?E D%on,i"H >"etC?o,,set?FFFFJ DitemH>,ormatA%reated 6 DdateH>toFormatCDparamsH>"etCDitemH>%reatedE ?Z Zd ZI Z:E Z&<ZM<ZS?FE tr!eE ,alseFJ 5> <li> <a hre,6S<5php e%ho DitemH>lin'J 5>S> <5php e%ho DitemH>,ormatA%reated)S H S)DitemH>titleJ 5><@a> <@li> <5php end,orea%hJ 5> <@!l>

12

Example0 4 5atest 6ews module


1!tp!t<

3atest 8ews
Sat!rday 01 Gan!ari 2011E 01<00<01 H Ie"inners Sat!rday 01 Gan!ari 2011E 01<00<01 H 7ettin" &elp Sat!rday 01 Gan!ari 2011E 01<00<01 H 7ettin" Started Sat!rday 01 Gan!ari 2011E 01<00<01 H JoomlaT Sat!rday 01 Gan!ari 2011E 01<00<01 H 1ptions

17

1 Clone a (odule

1#

1 Clone a (odule

$, template override [ possibleE e)") modAQ!i%'i%on

1R

1 Clone a (odule

dd yo!r own 4!i%' $%on5 1!tp!t o, 4!i%' $%on mod!le<


@administrator@mod!les@modAQ!i%'i%on@tmpl@de,a!lt)php

Dhtml 6 J&tml<<AC?i%ons)b!ttons?E Db!ttonsFJ 5> <5php i, CTemptyCDhtmlFF< 5> <div %lass6S%panelS><5php e%ho DhtmlJ5><@div> <5php endi,J5> \ 8ot possible to !se template override)))
20

1 Clone a (odule
2a) Copy Mod!le
@administrator@mod!les@modAQ!i%'i%on@ to @administrator@mod!les@modAQ!i%'i%on1@

2b) Kename ,iles


( (

modAQ!i%'i%on)php \ modAQ!i%'i%on1)php modAQ!i%'i%on)=ml \ modAQ!i%'i%on1)=ml

21

1 Clone a (odule
2%) Bdit modAQ!i%'i%on re,eren%es modAQ!i%'i%on1)php
Db!ttons 6 mod4!i%'$%on1&elper<<"etI!ttonsCDparamsFJ reQ!ire JMod!le&elper<<"et3ayo!tPathC?modAQ!i%'i%on 1?E DparamsH>"etC?layo!t?E ?de,a!lt?FFJ

modAQ!i%'i%on1)=ml
<name>modAQ!i%'i%on1<@name> <,ilename mod!le6SmodAQ!i%'i%on1S>modAQ!i%'i%on1)php<@,ilename>

22

1 Clone a (odule
2d) dd to Joomla< B=tensions > B=tension Mana"er > ;is%over

2*

1 Clone a (odule
2e) dd Mod!le modAQ!i%'i%on2<
( ( ( (

B=tensions > Mod!le Mana"er > Filter< .administrator/ N8ewO > modAQ!i%'i%on2 Title< My own 4!i%' $%ons Position< i%on

2-

1 Clone a (odule
1ops< Fatal error< Cannot rede%lare %lass mod4!i%'$%on&elper in @administrator@mod!les@modAQ!i%'i%on1@helper)php on line 1#

2,) Bdit helper)php


@administrator@mod!les@modAQ!i%'i%on1@helper)php %han"e the %lassname< abstra%t %lass mod4!i%'$%on&elper1

20

1 Clone a (odule
2") dd yo!r own .array/
(

@administrator@mod!les@modAQ!i%'i%on1@helper)php arrayC ?lin'? 6> Jro!te<<AC?inde=)php5option6com"search?FE ?ima"e? 6> ?header@icon=>?=search png?E ?te=t? 6> Jte=t<<AC?#earch?FE ?a%%ess? 6> arrayC?%ore)mana"e?E ?com"search?F FE

22

1 Clone a (odule
2h) Kes!lt<

27

@ Ase o7 Plugins

2#

@ Ase o7 Plugins
Joomla
( ( (

removes &TM3 layo!t

$n arti%le titles $n men! item titles $n bread%r!mb

Pater
( ( (

is &21

Men! item .&<s!b>2<@s!b>1/ \ Pater is &11 rti%le title .&<s!b>2<@s!b>1/ \ Pater is &11 Te=t in arti%le .&<s!b>2<@s!b>1/ \ Pater is & 1
1

2R

@ Ase o7 Plugins
KeKepla%er
( ( (

8on!mber CPeter van PestenF Component L System Pl!"in ;ownload< http<@@www)non!mber)nl@e=tensions@rerepla%er

*0

@ Ase o7 Plugins
Start
( (

s!bs%ript ta"

Sear%h ]s!b] Kepla%e by <s!b>

Bnd
( ( *1

s!bs%ript ta"

Sear%h ]@s!b] Kepla%e by <@s!b>

@ Ase o7 Plugins
Pater

is &21

( ( ( (

Men! item .&]s!b]2]@s!b]1/ \ Pater is &11 Men! itemE Irowser Pa"e TitleT\ Pater is &11 rti%le title .&]s!b]2]@s!b]1/ \ Pater is &11 Te=t in arti%le .&<s!b>2<@s!b>1/ \ Pater is &11

8ote< Check the Men!@ rti%le *liasT

*2

> Component with Bown controllerC

**

> Component with Bown controllerC


Joomla?s
( ( (

%onta%t %omponent<

;isplays %onta%t details ;isplays %onta%t ,orm Ketrieves inp!t %onta%t ,orm C%he%' inp!tE send to spe%i,ied email addressF

&oweverE
( ( (

in email the IP address o, the sender is missin"


Template override< not possible Clone Component< possibleE b!t %omponent 6 bi" Pl!"in< maybe possibleE b!t whi%h5

\
*-

dd yo!r own %ontroller))))

> Component with Bown controllerC

( (

dd .own %ontroller/ to %omponent<


P!t own %ontroller in e=istin" @%ontrollers@ ,older o, %omponent Template override< %han"e hidden variables in ,orm to tri""er yo!r own %ontroller

B=ample<

Chan"e %omA%onta%t without corehack send $P address in eHmail to website administrator


*0

> Component with Bown controllerC


-a) Template override that tri""ers own %ontroller<
(

Create template override ,older @html@com"contactDcontactD

Copy %onta%t ,orm &TM3 o!tp!t


@%omponents@%omA%onta%t@views@%onta%t@tmpl@de,a!ltA,orm)php
(

to template override ,older @html@%omA%onta%t@%onta%t@ Chan"e @templates@yo!rAtemplate@html@%omA%onta%t@ %onta%t@de,a!ltA,orm)php


<inp!t type6ShiddenS name6SoptionS val!e6S%omA%onta%tS @> <inp!t type6ShiddenS name6Stas'S val!e6S contact)s!bmitS @> <inp!t type6ShiddenS name6Sret!rnS val!e6S<5php e%ho DthisH>ret!rnApa"eJ5>S @> <inp!t type6ShiddenS name6SidS val!e6S<5php e%ho DthisH>%onta%tH>sl!"J 5>S @>

%han"e .tas'/<
<inp!t type6ShiddenS name6Stas'S val!e6SmE"own"controller)s!bmitS @>

*2

> Component with Bown controllerC


-b) 1wn %ontroller
(

Copy %omA%onta%t %ontroller


@%omponents@%omA%onta%t@%ontrollers@%onta%t)php

to C,ile name 6 ?tas'? ,rom ,orm in template overrideF


@%omponents@%omA%onta%t@%ontrollers@myAownA%ontroller)php

-%) Chan"e %ode o, yo!r own %ontroller<


(

-%1) Chan"e Classnaam<


%lass Conta%tControllerContact e=tends J%ontrollerForm

be%omes<
%lass Conta%tController(E"own"controller e=tends JControllerForm

*7

> Component with Bown controllerC


-C) Chan"e %ode o, yo!r own %ontroller<
(

-%2) s' ,or model CConta%tF with e=pli%it pre,i= to prevent error<
Fatal error< Call to a member ,!n%tion "et$temCF on a nonHobGe%t in @%omponents@%omA%onta%t@%ontrollers@myAownA%ontroller)php on line *#

$n method< p!bli% ,!n%tion s!bmitCF


Dmodel 6 DthisH>"etModelC?Conta%t?FJ

be%omes<
Dmodel 6 DthisH>"etModelC?Conta%t?E?Contact(odel?FJ *#

> Component with Bown controllerC


-C) Chan"e %ode o, yo!r own %ontroller<
(

-%*) dd yo!r own %ode in method private ,!n%tion AsendBmailCDdataE D%onta%tFE G!st below @@ Prepare email body
DmailH>setIodyCDbodyFJ

be%omes<
DmailH>setIodyC"IP address: " "#E$%E$&'$E(O)E"*++$', "-n-n" DbodyFJ

*R

> Component with Bown controllerC


-;) Kes!lt .will survive next Joomla upgrade/<
;ate< SatE 17 !" 2012 10<*0<00 L0200 From< >isitor name <in,oMe=ample)%om> KeplyHTo< N8ame visitorO <Nemail address visitorO> To< Nemail address S!per dmin o, PebsiteO IP adres: 012 3 3 0 This is an enQ!iry email via http<@@www)e=ample)%om@ ,rom< N8ame visitorO <Nemail address visitorO>
-0

NMessa"e o, visitorO

F Overriding Core Classes

-1

F Overriding Core Classes


Joomla?s
( (

%ore %lasses are<

3oaded on%e 3oaded be,ore everythin" else

Core
( (

%lasses %an

be e=tended Ce)") in yo!r %omponentsF b!t there?s no override me%hanism

Phat

i, yo! want to add somethin" to a %ore %lass so that all inheritan%es will have that %ode5

-2

F Overriding Core Classes


JoomlaT

Pro"rammin" H Mar' ;e=ter 9 3o!is 3andry Creleased pril 2012F

Pa"e

1#2H1#2< .+sin" Pl!"ins to 1verride Core Classes/

-*

F Overriding Core Classes


$n
( (

short<
System pl!"ins are loaded be,ore 1th event ConIe,ore$nitialiseF Pl!"ins %an load Classes @ plain %ode H> load %lass Cwith in%l!deAon%eF Classes that have already been loaded be,ore the System Pl!"ins are imported)))

B=%eption<
(

--

G 5anguage Overrides

-0

G 5anguage Overrides
Sin%e Joomla 2)0 ( Ie,ore 2)0< .Core ha%'/ lan"!a"e ,iles B=tensions > 3an"!a"e Mana"er > 1verrides

-2

G 5anguage Overrides
.8ew/E

e)") .Kead more/

-7

G 5anguage Overrides
.Kead

more/ \ .Kead m!%h more/

-#

G 5anguage Overrides
.Save

9 Close/<

-R

G 5anguage Overrides
Kes!lt<

00

Andoing Core Hacks

01

Andoing Core Hacks


+s!ally
( (

Core &a%'s are 81T do%!mented nalyse %ode to ,ind Core &a%'s<
Joomla 2)0)2 witho!t *rd party e=tensions< 0E0#2 itemsE totallin" 1R)0 MI Test site with some *rd party e=tensions< 7E21# itemsE totallin" -2)2 MI

\ 7ood l!%'T

02

Andoing Core Hacks


+se
( (

.di,,/E a ,ile %omparison !tility<

7+$< Meld C3in!= 9 Ma% 1S^F 7+$< PinMer"e CPindowsF

Preparations
( ( (

1@2<

Ia%'H!p o, website C+se 'eeba ba%'!pTF 3o%al 3 MP sta%' C3 MP@^ MPP@M MP@P MPF Kestore ba%'H!p to two websites !sin" 2 databases<
@myHsiteHwithHha%'@ @myHsiteHwitho!tHha%'@

0*

Andoing Core Hacks


Preparations
( ( (

2@2<

;ownload same version o, Joomla 9 !nYip ;ownload same versions o, *rd party e=tensions 1verwrite all ,iles with Joomla ,iles Ce=%ept @installation@ ,olderF to
@myHsiteHwitho!tHha%'@

$nstall CreinstallF *rd party e=tensions to


@myHsiteHwitho!tHha%'@

Kes!lt<
( 0-

@myHsiteHwitho!tHha%'@ now has ori"inal CnonHCore &a%'edF so,twareT

Andoing Core Hacks


+se
( (

.di,,/ tool to %ompare<

@myHsiteHwithHha%'@ @myHsiteHwitho!tHha%'@

00

Andoing Core Hacks

02

Andoing Core Hacks

07

Conclusion

0#

Conclusion

Core &a%' 6 Modi,i%ation o, %ore ,iles 2 lternatives to avoid Core &a%'s


(

1) Template override C%opy e=tensions &TM3 o!tp!t to yo!r templates @html@ dire%tory and %han"e thatF 2) Clone Mod!le C%opy %omplete mod!le 9 %han"e thatF *) +se Pl!"ins -) .1wn %ontroller/ Cadd own %ontroller 9 !se template override to tri""er yo!r %ontrollerF 0) 1verridin" Core Classes 2) 3an"!a"e 1verrides

( ( (

( (

+ndoin" Core &a%'s ( +se .di,,/ tools to %ompare ori"inal 9 modi,ied %ode

0R

Conclusion
Core
(

&a%' \ don?tT

Chan"es C.ha%'s/F mi"ht "et lost d!rin" !p"rade

Most
(

o, the 2 alternatives<

re in ,a%t a BhackC on a copE o, Joomla or *rd party %ode


dvanta"e< won?t "et overwritten with !p"rade ;isadvanta"e< any %ode improvements won?t ma'e it into the .%opy/T

20

Huestions9

21

Huestions9
Sheets

will be available at www)db#)nl

Peter Martin eHmail< in,o at db#)nl website< www)db#)nl


22

Ased Photos

=e H Peter &!ysE http<@@www)s=%)h!@photo@#0##71 Photo Frame R ( Iilly le=anderE http<@@www)s=%)h!@photo@1*271R# &iSpeed %opier 1 H Mar%in Iar_ows'iE http<@@www)s=%)h!@photo@0*70*7 !sb H >an"elis ThomaidisE http<@@www)s=%)h!@photo@R1*0R0 7ame pad H Mi%hal Xa%harYews'iE http<@@www)s=%)h!@photo@R070-0 bl!eprint H `erem :!%elE http<@@www)s=%)h!@photo@2#22*7 Ien"ali `eyborad H Mohammad Jobaed dnan http<@@www)s=%)h!@photo@272#-Ked Plaster H Pa!l Iar'erE http<@@www)s=%)h!@photo@111-17si"ns si"ns H Jason ntonyE http<@@www)s=%)h!@photo@7010*Fa%e H 4!estions H Iob SmithE http<@@www)s=%)h!@photo@-1#210

2*

You might also like