Professional Documents
Culture Documents
Overview Presentation
Introduction Core Hack Alternatives
Template Override Alternative Layouts Language Override Use of Plugins Clone Module Component with own controller Extra Fields Overriding Core classes
>>>Sheetsvia:www.db8.nl<<<
A. Core Hack
Core Hack
Joomla
= Open Source license GNU GPL GPL protects freedom & rights of users Source code = public You can and are allowed to change all Joomla code Core Hack = modification in source code Joomla 3rd party extension
Core Hack
Disadvantage of changing core code: Stability
Might give problems with 3rd party extensions Your code changes can be overwritten when you upgrade
Maintainability
/components/com_contact/controllers/contact.php private function _sendEmail($data, $contact), just under // Prepare email body $mail->setBody($body); change into: $mail->setBody("IP address: ". $_SERVER['REMOTE_ADDR']."\n\n".$body);
Date: Sat, 17 Aug 2012 15:30:00 +0200 From: Visitor name <info@example.com> Reply-To: [Name visitor] <[email address visitor]> To: [email address SuperAdmin of Website] IP adres: 127.0.0.1 This is an enquiry email via http://www.example.com/ from: [Name visitor] <[email address visitor]> [Message of visitor]
1. Template Override
10
1. Template Override
Template
Components
& Modules
Template
11
Change
12
13
</ul>
14
15
16
17
Latest News
Saturday 01 January 2011, 01:00:01 - Beginners Saturday 01 January 2011, 01:00:01 - Getting Help Saturday 01 January 2011, 01:00:01 - Getting Started Saturday 01 January 2011, 01:00:01 - Joomla! Saturday 01 January 2011, 01:00:01 - Options
18
2. Alternative Layouts
19
2. Alternative Layouts
Alternative
= Template Override XTD Extra Control Options regarding display Extra HTML output files in /templates/html/
Four
20
2. Alternative Layouts
Alternative layout: Add other tmpl HTML output files to Template Override folder: /templates/your_template/html/mod_articles_latest/
21
2. Alternative Layouts
Example: Rename override (#1from this presentation) default.php to non-existing tmpl file: layout-with-date.php:
22
3. Language Overrides
23
3. Language Overrides
Since Joomla 2.5 Before 2.5: Core hack language files Extensions > Language Manager > Overrides
24
3. Language Overrides
New,
25
3. Language Overrides
Read
26
3. Language Overrides
Save
& Close:
27
3. Language Overrides
Result:
28
3. Language Overrides
Important:
File
Note:
29
4. Use of Plugins
30
4. Use of Plugins
Joomla
Water
is H2O
Menu item H<sub>2</sub>O Water is H2O Article title H<sub>2</sub>O Water is H 2O Text in article H<sub>2</sub>O Water is H O
2
31
4. Use of Plugins
ReReplacer
32
4. Use of Plugins
Start
subscript tag
End
subscript tag
33
4. Use of Plugins
Water
is H2O
Check the Menu/Article Alias! Menu item, Browser Page Title! Water is H2O
34
5. Clone a Module
35
5. Clone a Module
36
5. Clone a Module
Add
$html = JHtml::_('icons.buttons', $buttons); ?> <?php if (!empty($html)): ?> <div class="cpanel"><?php echo $html;?></div> <?php endif;?> Not possible to use template override...
37
5. Clone a Module
5a. Copy Module
/administrator/modules/mod_quickicon/ to /administrator/modules/mod_quickicon2/
38
5. Clone a Module
5c. Edit mod_quickicon references mod_quickicon2.php
$buttons = modQuickIcon2Helper::getButtons($params); require JModuleHelper::getLayoutPath('mod_quickicon 2', $params>get('layout', 'default'));
mod_quickicon2.xml
39
5. Clone a Module
5d. Add to Joomla: Extensions > Extension Manager > Discover
40
5. Clone a Module
5e. Add Module mod_quickicon2:
Extensions > Module Manager > Filter: administrator [New] > mod_quickicon2 Title: My own Quick Icons Position: icon
41
5. Clone a Module
Oops: Fatal error: Cannot redeclare class modQuickIconHelper in /administrator/modules/mod_quickicon2/helper.php on line 18
42
5. Clone a Module
5g. Add your own array
/administrator/modules/mod_quickicon2/helper.php array( 'link' => Jroute::_('index.php?option=com_search'), 'image' => 'header/icon-48-search.png', 'text' => Jtext::_('Search'), 'access' => array('core.manage', 'com_search') ),
43
5. Clone a Module
5h. Result:
44
45
contact component:
Displays contact details Displays contact form Retrieves input contact form (check input, send to specified email address)
However,
missing
Template override: not possible Clone Component: possible, but component = big Plugin: maybe possible, but which?
46
Put own controller in existing /controllers/ folder of component Template override: change hidden variables in form to trigger your own controller
Example:
47
/components/com_contact/views/contact/tmpl/default_form.php
<input type="hidden" name="option" value="com_contact" /> <input type="hidden" name="task" value="contact.submit" /> <input type="hidden" name="return" value="<?php echo $this->return_page;?>" /> <input type="hidden" name="id" value="<?php echo $this->contact->slug; ?>" />
change task:
<input type="hidden" name="task" value="my_own_controller.submit" />
48
/components/com_contact/controllers/contact.php
becomes:
class ContactControllerMy_own_controller extends JControllerForm
49
6c2. Ask for model (Contact) with explicit prefix to prevent error:
Fatal error: Call to a member function getItem() on a non-object in /components/com_contact/controllers/my_own_controller.php on line 38
becomes:
$model = $this->getModel('Contact','ContactModel');
50
6c3. Add your own code in method private function _sendEmail($data, $contact), just below // Prepare email body
$mail->setBody($body);
becomes:
51
52
53
runs extensions:
Components: URL index.php?option=com_content Modules: Menu item &menuItem=x Plugin listen to events (hooks) Components have hooks
54
User Plugin:
Functionality
55
User Profile
User Plugin:
Events:
Documentation:
56
fields in articles? Joomla's core component com_content 3 places to display extra fields:
1. Front-end - Display extra fields in article 2. Front-end - Extra fields in article editor form 3. Back-end - Extra fields in article editor form
Content Plugin:
Functionality
57
Article Fields
Content Plugin:
Events:
Documentation:
Adding
58
59
Core
classes can
What
if you want to add something to a core class so that all inheritances will have that code?
60
Documentation:
http://docs.joomla.org/How_to_override_the_compon ent_mvc_from_the_Joomla%21_core
61
short:
System Plugins are loaded before 1st event (onBeforeInitialise) Plugins can load Classes / plain code Create System Plugin that loads your modified core class (with include_once) Classes that have already been loaded before the System Plugins are imported...
Exception:
62
64
Core Hacks are NOT documented Analyse code to find Core Hacks:
Joomla 2.5 without 3rd party extensions: 5,586 items, totalling 19.0 MB Test site with some 3rd party extensions: 7,618 items, totalling 42.2 MB
Good luck!
65
Preparations
1/2:
Back-up of website (Use Akeeba backup!) Local LAMP stack (LAMP/XAMPP/MAMP/WAMP) Restore back-up to two websites using 2 databases:
/my-site-with-hack/ /my-site-without-hack/
66
2/2:
Download same version of Joomla & unzip Download same versions of 3rd party extensions Overwrite all files with Joomla files (except /installation/ folder) to
/my-site-without-hack/
Result:
67
/my-site-with-hack/ /my-site-without-hack/
68
69
70
The
71
Conclusion
Core Hack = Modification of core files (Joomla or 3rd party) Eight Alternatives to avoid Core Hacks
1. Template Override (copy extensions HTML output to your templates /html/ directory and change that) 2. Alternative Layouts 3. Language Overrides 4. Use Plugins 5. Clone Module (copy complete module & change that) 6. Own controller (add own controller & use template override to trigger your controller) 7. Extra fields 8. Overriding Core Classes
Undoing Core Hacks Use diff tools to compare original & modified code
72
Conclusion
Core
Most
Disadvantage:
73
Questions?
74
Questions?
Presentation
available at www.db8.nl
75
Used Photos
digital dreams - Flavio Takemoto - http://www.sxc.hu/photo/1160561 Who buys this stuff for a kid? - Jason Antony - http://www.sxc.hu/photo/456502 Axe - Peter Huys, http://www.sxc.hu/photo/808871 Photo Frame 9 Billy Alexander, http://www.sxc.hu/photo/1367198 Bengali Keyborad - Mohammad Jobaed Adnan http://www.sxc.hu/photo/676844 usb - Vangelis Thomaidis, http://www.sxc.hu/photo/913590 HiSpeed copier 1 - Marcin Barowski, http://www.sxc.hu/photo/537037 Game pad - Michal Zacharzewski, http://www.sxc.hu/photo/957040 EXTRA Warmth - Nicolas Raymond http://www.sxc.hu/photo/971125 blueprint - Kerem Yucel, http://www.sxc.hu/photo/282237 Red Plaster - Paul Barker, http://www.sxc.hu/photo/1114174 signs signs - Jason Antony, http://www.sxc.hu/photo/751034 Face - Questions - Bob Smith, http://www.sxc.hu/photo/418215
76