Das Verwenden des SecurityImages in Ihrem Code

Diese Seite wird jedem Komponentenentwickler von Joomla gewidmet! Die SecurityImages bestandteil in ihrem Code verwenden wollen.

Nehmen Wir mal die Kontakt Komponente von Joomla! 1.5 als Beispiel.

Es wird immer empfohlen, einen Schalter in Ihren Komponenten zu verwenden, um SecurityImages zu aktivieren. Dadurch können Sie SecurityImages durch das Verwalter-Bedienungsfeld aus- und einstellen.

Dies müssen Sie jetzt unter administrator/components/com_contact/contact_items.xml folgendes Eintragen:

<param name="useSecurityImages" type="radio" default="1" label="Use SecurityImage Captcha" description="Enable Captcha verification">
<option value="0">No</option>
<option value="1">Yes</option>
</param>

Joomla wird diese xml Datei im Fluge lesen und die grafische Benutzerschnittstelle für die Kontakt-Einstellungen erstellen.

contact.settings.securityimages.5.0

Seit Joomla! 1.5 wird jetzt ein Musteransicht-Kontrolleur-Paradigma verwendet, wir müssen den Kontrolleur verändern, und eine neue Aufgabe displaySecurityImagesCaptcha() darin hinzufügen in  components/com_contact/controller.php:

   function displaySecurityImagesCaptcha() { 
        global
$mainframe
       
        //Per contact you can define if the user has to resolve the capctha 
       
$contactId = JRequest::getVar('contact_id', 0, '', 'int'); 
       
// load the contact details 
       
$model    = &$this->getModel('contact'); 
       
$qOptions['id'] = $contactId
       
$contact        = $model->getContact( $qOptions ); 
       
$params = new JParameter( $contact->params ); 
         
        if (
$params->get('useSecurityImages')) {     
           
$check = null
           
$mainframe->triggerEvent('
onSecurityImagesDisplay', array($check)); 
            if (!
$
check) { 
                echo
"<br/>Erreur affichage du Captcha<br/>"
            } 
        } 
             
    } 
Weil Sie sehen können, wird das Ereignis "onSecurityImagesDisplay" auf Kontakt-Namenbasis aufgebaut. Das bedeutet, dass gewisse Kontakte einen Captcha haben konnen, während andere dies nicht haben.

Der folgende Schritt ist, die Aufgabe checkSecurityImagesCaptcha () Anmeldung des captcha hinzuzufügen in components/com_contact/controller.php
function checkSecurityImagesCaptcha() { 
        global
$mainframe
  
       
$contactId = JRequest::getVar('id', 0, '', 'int'); 
       
// load the contact details 
       
$model    = &$this->getModel('contact'); 
       
$qOptions['id'] = $contactId
       
$contact        = $model->getContact( $qOptions ); 
       
$params = new JParameter( $contact->params ); 
       
        //check if that user has a capctha 
       
if (!$params->get('
useSecurityImages')) {  
            return
true
        } 
       
$return = false
       
$securityImagesJoomlaContactUserTry = JRequest::getVar('securityImagesJoomlaContactUserTry', false, '', 'CMD'); 
       
$mainframe->triggerEvent('
onSecurityImagesCheck', array($securityImagesJoomlaContactUserTry &$return));
        return
$return;
    } 
One more step is to alter the original submit() method of the controller in components/com_contact/controller.php
        global $mainframe  

       
if (!$this->
checkSecurityImagesCaptcha()) {
           
JError::raiseWarning("999","Invalid Captcha Code");
           
$this->display();
            return
false;
        } 
Und schließlich die änderungen der Ansicht in /com_contact/views/contact/tmpl/default_form.php
um das Captcha Feld zu zeigen!!

<?php if ($this->params->get('useSecurityImages')) { ?>             
<img src="/index.php?option=com_contact&task=
displaySecurityImagesCaptcha&contact_id=<?php echo $this->contact->id; ?>"> 
<br /> 
<input type="text" name="securityImagesJoomlaContactUserTry" /> 
<br /> 
 <?php } ?>
As you see a lot of thing have been done, and I am still testing and improving the code.
Final Version
  • Securityimages component can be put in debug mode or be deactivated site wide.
  • If is recommended to have a switch in your code to enable disable usage of securityimages in case the user hasn't installed it yet.

Viel Spass damit...