Rainforest

Sankuru

Implementing, customizing, extending, and troubleshooting Joomla/Virtuemart

Views: 1185
SocialTwist Tell-a-Friend

Machine translation

English Arabic Chinese (Simplified) German Japanese Russian Spanish



Re-use open source

What you need, often exists already, and covers your requirements for 80%. We will add the remaining 20% for you.

Free quote

Request a free quote today.

Fixing mod_ampcontact PDF Print E-mail
User Rating: / 0
PoorBest 
Written by erik   
Tuesday, 14 April 2009 10:06

I installed the mod_ampcontact module on this site today. It is a small and inconspicuous module that gives the site visitor the opportunity to send a quick message to me. I quite like the concept.

The module pre-fills the name and email field with the words "your name" and "your email address", instead of using traditional labels in front of the text boxes. That is a good idea, because it saves space.

However, the natural language phrases are hard-coded again in the sources. So, I had to i18n and L10n the sources again. This time, I did not create fully fledged localization files for French and Dutch. Instead, I just hard-coded the translations right into the main script at line 34:

<?php
$lang=JFactory::getLanguage()->getTag();
$name='Your name'; 
$email='Your email';
switch($lang)
{
    case 'en-GB': $name='Your name'; $email='Your email';
            $err='Some values are not acceptable. Please retry.';break;
    case 'fr-FR': $name='Votre nom'; $email='Votre courriel';
            $err='Certaines valeurs renseignées ne sont pas acceptables. Veuillez re-essayer.';break;
    case 'nl-NL': $name='Uw naam'; $email='Uw email';
            $err='Bepaalde ingegeven waarden kunnen niet worden aanvaard. Gelieve opnieuw te proberen.';break;

}
?>
 

As I said, a quick and dirty solution :-)

I also took out the phone number field. The fewer fields, the more likely the user is going to fill out the form ... So, out of the window goes the telephone field around line 70:

<!--        <input type="text" name="telephone" value="Telephone" onFocus="clearAmpContactText(this)" class="ampContactText" />
        <br />
-->

The module worked mostly fine, but somehow managed to crash my testimonials and my sitemap component. The offending line happens to be line 7:

JHTMLBehavior::formvalidation(); 

Apparently, if the component on whose page the module gets displayed, somehow does not load the JHMTL class, the JHTMLBehavior class does not get loaded either, and the module will crash the entire page.

My kneejerk reaction was to change the module's source, in order to force Joomla to load the class anyway; before the offending line 7:

jimport('joomla.html.html.behavior');

I thought this would do the trick. Wrong. It doesn't. The joomla jimport logic will register the class as JBehavior and not as JHTMLBehavior.

In my impression, given the fact that the class cannot loaded in the typical way, this class should not be accessed directly. I somehow suspect that the class should be accessed through one of the factory classes, such as for example, JFactory.

Now, with two important menu items in my site crashed, I decided not to look up things and figure out what all of this should be, but to brute-force the solution instead. I leave it up to the mod_ampcontact authors to look deeper into the issue and look for a more permanent solution for the next version of the module.

Just before the offending line, I added:

require_once(dirname(dirname(dirname(__FILE__))).'/libraries/joomla/html/html/behavior.php');

This line probably looks like an insidiously ugly hack. It actually is. The statement bypasses the standard Joomla jimport() logic for loading framework classes, and forces Php to load the file directly. The hack makes sure that the class JHTMLBehavior is available, regardless of what framework regulations the module seems to be violating by accessing this class directly.

 


blog comments powered by Disqus
 
 
Joomla 1.5 Templates by Joomlashack