Home
Wed
29
Feb

Using JCCreCaptcha with yvComment

Attention: open in a new window. PDFPrintE-mail

Editting the yvComment

 

When I wrote the JCCReCaptcha, I thought to use it with the yvComment.  because this, I wrote a plugin based on  OSTWigits-Captcha interface plugin, wich I already used with yvComment.

 

Despite we strictly followed the OSTWigits-Captcha interface, the fact of ReCaptcha to work with itself html GUI imposed the need of some changes on yvComment source code.

 

Naturally, this is one of the things more beautiful on Open Software: The possibility of to suit it to yours needs.  This differ to make indiscriminate changes only because you can do, so, we looked about alternatives to changes that had less impact on yvComment code.

 

Before start, I would like to point that the showed changes were made over the version 1.23 of yvComment component.  Naturally there aren't any warranty that this edittings will be functional in future versions of yvComment!

 

“Lazy” Editting

 

I call this "Lazy" edittings, because this is the less intrusive changes on source code of yvComment component. The pay off is that yvComment will be incompatible with the OSTWigits-Captcha like plugins.

 

  1. Source: "default.php", on folder "components\com_yvcomment\views\comment\tmpl", original code, lines 352-361:
  2.  

    <img
    	<?php
     	     if ($this->params->get('yvcomment_delay_captcha_image')
     	          && empty($textToEdit)
     	          && !isset($this->editor)) {
     	         echo ' id=\'captcha' . $idSuffix . '\'';
     	     } else {
     	         echo ' src=\'' . JRoute::_('index.php?option=com_yvcomment&task=displaycaptcha') . '\'' ;
     	}?>
     	alt='<?php echo JText::_("SECRETWORD_IMAGE"); ?>' />
    

     

    In this lines a html <img> tag is used, to show the on-fly image generated by OSTWigits-Captcha plugin.  The plugin is a triggered by the URL on "SRC" argument, "JRoute::_('index.php?option=com_yvcomment&task=displaycaptcha'".

     

    All that we need is to replace this lines by the following code:

     

    <?php
           Global $mainframe;
           $mainframe->triggerEvent( 'OnCaptcha_Display');
     
           echo "<input name='secretword' type='hidden' value='-' />";
     ?>
    

     

    Note that the "input secretword" is needed just because the yvComment rely on it to follow to the plugin. The ReCaptcha don't need it, but remove it will to cause more edittings on yvComment. So, we take it hidden and with a default value, also neede to avoid the yvComment validation that blocks submissions to the Captcha plugin if the secretword don't have entered.

     

  3. Source: "default.php", folder "components\com_yvcomment\views\comment\tmpl", original code, lines 364-378:
  4.  

     <tr<?php
     	if ($this->params->get('yvcomment_delay_captcha_image')
     	        && empty($textToEdit)
     	        && !isset($this->editor)) {
     	   echo ' id=\'secretwordrow' . $idSuffix . '\' style=\'display:none\'';
     	}?>>
       <td class="CommentLeftColumn" title='<?php echo JText::_("SECRETWORD_TIP"); ?>'>
         <?php
             echo JText::_('SECRETWORD');
         ?>:
       </td>
       <td>
           <input name='secretword' type='text' class='inputbox' style='width: 98%' value='' />
       </td>
     </tr>
    

     

    This is the lines that originally provides the input for the sercretword. Since the ReCaptcha already have its own input, this lines can be wholly removed from the source!

     

A Better Suited Edittings

 

In contrast with the above edittings, the following will keep yvComment compatible with OSTWigits-Captcha like plugin.

 

It will be accomplished by adding a parameter on yvComnent, that will to permit a user to select when he/she wants to use a OSTWigits-Captcha interface like captcha plugin or a JCCreCaptcha one.  It just will be well suited because the yvComment make use of captcha plugins through Triggers mechanism.  So it don't have strictly rely with a particular plugin, what easy its replacement by another since it have the same interface.  Then I want to keep it and take use of this, what resulted on the follow edittings:

  1. Source: "en-GB.com_yvcomment.ini", Folder "administrator/language/en-GB", line 190:
  2.  

    This is the language file for the yvComment plugin. We will make the insert of messages that we will create to support our edittings.  They are indicated on highlighted lines:

     

    USE_CAPTCHA=Use Captcha
    USE_CAPTCHA_DESC=Protect from spam with secret words (compatible Captcha plugin required)
    CAPTCHA_RENDER_MODE=Captcha Render Mode
    CAPTCHA_RENDER_MODE_DESC=Render engine of captcha plugin.
    CAPTCHA_RENDER_MODE_OPT_IMG=Image for IMG tag
    CAPTCHA_RENDER_MODE_OPT_HTML=HTML User Interface
    UNKNOW_CAPTCHA_RENDER_MODE=Unknow captcha render mode.
    

     

  3. Source: "yvcomment.xml", plugin yvcomment, folder "plugins\content":
  4.  

    This define the parameters for the yvComment plugin and for the yvComment component. At line 139, we add the follow code, that define our new parameter, “captcha_render_mode”:

     

     <param name="captcha_render_mode" type="list" default="img" label="CAPTCHA_RENDER_MODE" description="CAPTCHA_RENDER_MODE_DESC">
       <option value="img">CAPTCHA_RENDER_MODE_OPT_IMG</option>
       <option value="html">CAPTCHA_RENDER_MODE_OPT_HTML</option>
     </param>
    

     

    Note that we use the macros that we defined before, on language file.  Thats will to permit that our change can be easily translated.

     

  5. Source: "view.html.php", component yvcomment, folder "components\com_yvcomment\views\comment":
  6.  

    The interesting lines in this source make the load of some parameters to variables for later use.  We will to add, on 373 line, the load of our new parameter, following the style and naming conventions used on original code:

     

     $params->set('yvcomment_captcha_render_mode', $yvComment->getConfigValue('captcha_render_mode', 'img') );
    

     

  7. Source: "default.php", component yvComment, folder "components\com_yvcomment\views\comment\tmpl", lines 352 to 361:
  8.  

    We will make use of the new parameter to keep the original source code thar to render the captcha image, "switching" between it and the new code, that render the reCaptcha html GUI.  Over the original source code, we will to add the following (highlighted) lines:

     

    <?php if ( $this->params->get('yvcomment_captcha_render_mode') == 'img' ) : ?>
     		<img
     			<?php
     			if ($this->params->get('yvcomment_delay_captcha_image')
     				&& empty($textToEdit)
     				&& !isset($this->editor)) {
     				echo ' id=\'captcha' . $idSuffix . '\'';
     			} else {
     				echo ' src=\'' . JRoute::_('index.php?option=com_yvcomment&task=displaycaptcha') . '\'' ;
     			}?>
     		  alt='<?php echo JText::_("SECRETWORD_IMAGE"); ?>' />
     <?php elseif ( $this->params->get('yvcomment_captcha_render_mode') == 'html' ) :
     		global $mainframe;
     		$mainframe->triggerEvent( 'OnCaptcha_Display');
     
     		echo "<input name='secretword' type='hidden' value='-' />";
           else:
    		echo JText::_("UNKNOW_CAPTCHA_RENDER_MODE");
           endif;
     ?>
    

     

  9. Source: "default.php", component yvComment, folder "components\com_yvcomment\views\comment\tmpl", lines 364-378, (on unmodifyied source code, after the last edittings, the new lines will be 374-388) :
  10.  

    We will make use of the new parameter to hide html TABLE line that contain the secretword textbox, even our captcha control don't need it.  On the original code, we will to add the highlighted lines:

     

     <?php if ( $this->params->get('yvcomment_captcha_render_mode') == 'img' ) : ?>
       <tr<?php
     			if ($this->params->get('yvcomment_delay_captcha_image')
     				&& empty($textToEdit)
     				&& !isset($this->editor)) {
     				echo ' id=\'secretwordrow' . $idSuffix . '\' style=\'display:none\'';
     			}?>>
     	<td class="CommentLeftColumn" title='<?php echo JText::_("SECRETWORD_TIP"); ?>'>
     	  <?php
     		echo JText::_('SECRETWORD');
     		?>:
     	</td>
     	<td>
     	  <input name='secretword' type='text' class='inputbox' style='width: 98%' value='' />
     	</td>
       </tr>
     <?php endif; // yvcomment_captcha_render_mode ?>
    

     

Using the modifyied version

 

Made that above edittings, Go to the yvComment plugin's setup interface.   You will to find our new parameter, like showed on follow picture:

 
Novo Parâmetro no yvComment

 

Change it to "HTML User Interface" option and save.

 

Install the JCCReCaptcha and enable it. If you have another Captcha plugin, disable it.

 

Now test your increased yvComment with JCCreCaptcha. It will to result on anything like showed down:

 
reCaptcha integrado ao yvComment
 
 

Finalizing

 

Unfortunately, because our host restrictions, we can't to use JCCreCaptcha on our blog, just because the reCaptcha use sockets on its API implementation and outgoing connections its blocked on free account (our case).  So, we can't to show a live version on JCCreCaptcha with yvComment.  Therefore, we invite anyone who to test the component to post a comment here to let us know about the experience.  We will to answer any question as soon as possible, here, on comments.

 

 



Adicionar este artigo ao seu site de favoritos ?
Digg! Reddit! Del.icio.us! Google! Live! Facebook! Technorati! StumbleUpon! MySpace! Netvouz! Mister-Wong! Diigo! Faves! Ask! DZone! Swik! Twitter! LinkedIn!

Comments (4)
4 Thursday, 25 February 2010 15:39
X-Bit
Acabo de instalar seu module e to muito feliz que este funciona sem um problema! O link para o vídeo me ajudo também.
Parabéns e muito obrigado de dividir com a comunidade.

Abraços de João Pessoa / Paraiba
3 Monday, 30 November 2009 22:54
Travis Pflanz
Thank you for this plugin, and the tutorial for integration with the yvComment system.

I hope to see you work together with yurivolkov.com to implement a permanent integration with future yvcomment releases. The Joomla! community would greatly benefit from this collaboration!

Thank you!
2 Friday, 11 September 2009 09:40
Ken
Can I insert this plugin to my others module like newsletter Subscribe?
Administrator's reply:
Friday, 11 September 2009 16:08
Administrator
Hi Ken,

Surely, yes, on GNU-GPL v2 terms, only.

There are a link to the GNU-GPL v2 license on download section of the article, if it be needed.

Thanks,
1 Wednesday, 09 September 2009 05:27
Rboyz
This works very good! GREAT plugin! I've searched plugin to replace that UgLy captcha with reCaptcha and this is just nice.
By the way, I've tried the good one and failed, so the Lazy one is much better.

Add your comment

Your name:
Comment:

Menu Principal

Editar traduo para English (United Kingdom) Editar traduo para Português (Brasil)
Blog Sistemas e Cia