zondag 25 juli 2010

Joomla bijwerken naar versie 1.5.17

Are you not Dutch? But English is no problem? Click here to go to the English version.



Het zal ergens rond 2007 geweest zijn dat ik de website van de drumband (www.drum-lyraselection.nl) onder handen heb genomen. Zoals iedere programmeur wil je zelf een soort CMS maken, maar als je even rondkijkt, zie je dat er al andere open-source alternatieven zijn die veel dingen al kunnen, dus waar je zelf geen tijd meer in hoeft te steken. Dus toen is de eerste echte 'versie 1.0' website online gekomen, met Joomla als framework.

Het was mijn eerste Joomla-site, dus een aantal zaken zijn toen niet zo mooi gebouwd. Ik gebruik bijvoorbeeld bbclone om de bezoekersstatistieken te registreren. Die paar regels code propte ik in de index.php van Joomla. Ook zijn er een aantal formulieren op de website, contactformulier, formulier om optredens te boeken. Daarvoor heb ik code gemaakt en die als include toegevoegd in /includes/frondend.php .

Nu, 3 jaren later, weet ik hoe het werkt en is het dus de perfecte tijd om de boel te upgraden naar de huidige stabiele versie van Joomla. Hiervoor heb je de volgende mogelijkheden:
- componenten. Deze gebruik je voor onderdelen van je site met uitgebreide functionaliteit. Dus de agenda met alle optredens, het gastenboek met alle bijdrages, etc.
- modules. Hier kun je de code voor de registratie van de bezoekers plaatsen, de twitter-balk in het linkerdeel van de website.
- plugins. Hier zit de code voor het vervangen van bepaalde stukken tekst. Bijvoorbeeld om het contactformulier te tonen en om de fotogallerijen te tonen.

Componenten bevatten de meeste code. En dat zijn dus ook de onderdelen geweest waar ik de meeste tijd aan kwijt geweest ben. De componenten die ik zelf heb gemaakt en dus omgezet moesten worden:
- Agenda. Onderhoud van optredens, etc.
- Commentaar (reacties). Was een bestaande plugin, maar code moest ik wel aanpassen.
- Gastenboek. Onderhoud van de bijdrages op het gastenboek.
- IP-Blokkade. Detecteren van spambots en die berichten blokkeren (en ip-adressen ook).
- Nextgen Gallery. Door mij omgezette WordPress plugin, onderhouden van fotogallerijen.
- Twitter. Onderhouden of tweets wel of niet op de website getoond moeten worden.
- Vriend van. Mensen kunnen zich via de website opgeven als ' vriend van '. Hier wordt een lijst van getoond.


Een kort overzicht van de wijzigingen ten opzichte van de oude versie die ik had draaien:

Aangeven of een pagina zelfstandig aangeroepen mag worden.
In de oude versie had je in de code staan: defined( '_VALID_MOS' ) or die( 'Restricted access' );
Dat is aangepast naar: defined( '_JEXEC' ) or die( 'Restricted access' );


Het database-object
Je component om met de database te communiceren was de globale $database. Die is niet meer beschikbaar. In je code voer je nu uit: $db =& JFactory::getDBO();


Het tabel-object
De tabel voor optredens heet in mijn database jos_agenda_events. In de oude code maakte je een agendaevent.class.php bestand aan en maakte je daarin een class met de verwijzing naar de database: class mosAgendaEvent extends mosDBTable.
De mosDBTable is niet meer beschikbaar. Ik heb mosDBTable nu vervangen door JModel. Dit betekent dan wel weer dat je het opslaan (functie store) en het koppelen van de ingevoerde data (functie bind) nu zelf in ditzelfde bestand moet maken. Bij de mosDBTable hoefde dit niet omdat die functies al beschikbaar waren. Hier moet ik nog eens naar kijken, want volgens mij heb je ook een JTable, alleen kon ik dat zo snel niet werkend krijgen en heb ik het nu eerst op deze manier opgelost.


De 'mos'-objecten
Zoals hierboven al stond is de mosDBTable er niet meer. Hetzelfde geldt eigenlijk voor alle mos-dingen. Als je in je code wilde redirecten naar een andere pagina, voerde je dit uit: mosRedirect('paginanaam'); Nu doe je dit door in je functie een global $mainframe; te doen en bij je redirect: $mainframe->redirect('paginanaam');
Ook het opvragen van gegevens in je Request-object deed je met mosGetParam( $_REQUEST, 'cid', array(0) );, nu doe je dat met JArrayHelper::getValue($_REQUEST, 'cid', array(0) );
Het maken van een dropdownlijst, het toevoegen van de opties, een yes-no lijst, dat gaat nu allemaal met JHTML::_( .

Maar goed, als je de boel allemaal in Eclipse opent, krijg je netjes de zaken doorgestreept te zien die 'deprecated' zijn en ook het alternatief wat je dan wel moet gebruiken. De website van de drumband is bijgewerkt, ik ben zeer tevreden met het resultaat!


ENGLISH VERSION



In 2007 I made the first 'version 1.0' website of the Drum- & Lyraselection 'Warga' (www.drum-lyraselection.nl). As software engineer you always start on your own trying to build a neat CMS, but when I looked around I saw there were enough opensource alternatives which provided the things I needed for the website. And where I could add my own components. I started then with Joomla.

It was my first Joomla-site, so quite some parts of the site were programmed the way they should not be. For example, I use bbclone to register the visitors of the site. The few lines of code I added in the index.php page of Joomla. Also some forms (contact, book us!), I put the code for that in a separate php file (good!) but included that file in /includes/fontend.php (bad!).

After 3 years, I know how it works, so the perfect time to upgrade the site to the current stabile version of Joomla. Joomla offers these possibilities to add your own code:
- components. These you use for extended parts of your site. The agenda with all events, the guestbook, etc.
- modules. The place to add your code for the registration of the visitors and the twitter-page-add on the left side of the website.
- plugins. This code is for replacing some parts of the content. I use it for the forms and the photo-gallery.

Components contain the greatest part of code and therefore took most of my time. The components I made myself and which had to be converted:
- Agenda. Maintenance of events, etc.
- Comments. Was an existing plugin, but I had to convert the code.
- Guestbook. Maintenance of the reactions of guests on our website.
- IP-Block. Detection of spambots, block those messages (and their ip-addresses).
- Nextgen Gallery. Wordpress plugin which I converted to Joomla. Maintenance of photo-galleries.
- Twitter. Maintenance of tweets, show or hide them on our website.
- Friend Of. Visitors can fill in a form to become a 'friend of' our club. In the backend of Joomla we can see who registered themself.

A short summary of changes compared to the old version:

Check if a page may be called.
In the old Joomla-code you had: defined( '_VALID_MOS' ) or die( 'Restricted access' );
That is changed to: defined( '_JEXEC' ) or die( 'Restricted access' );


The database-object
The component for 'talking' with the database was the global $database. That one is no longer available, you have to use the following code: $db =& JFactory::getDBO();


The table-object
The table for events is named jos_agenda_events in my database. In the old code you made an agendaevent.class.php and in that file you created a class with the reference to the database: class mosAgendaEvent extends mosDBTable.
mosDBTable is no longer available. I replaced it with JModel. That causes that you have to create your own function save and own function bind to retrieve and save your data to the database. The mosDBTable had all these functions available. I have to look at it later, because you also have an object JTable, but I could not get that one working so quickly.


The 'mos'-objects
As mentioned before mosDBTable is not available any more. That applies to all 'mos'-things. When you wanted to redirect to an other page you did a: mosRedirect('pagename'); Now you first have to add in your function global $mainframe; and at the redirect-place: $mainframe->redirect('pagename');
Retrieving data from the Request-object you executed a mosGetParam( $_REQUEST, 'cid', array(0) );, now you do that with: JArrayHelper::getValue($_REQUEST, 'cid', array(0) );
Making a dropdown, adding options, yes-no-list, it all works with JHTML_(.

But ok, when you open all code in Eclipse, you see all deprecated code strike-through, and the mouse-over event shows you which code you should use instead of this old code. The website of the Drum- & Lyraselection is up-to-date, I am proud of it!