Index: /extensions/EasyCaptcha/include/category.inc.php
===================================================================
--- /extensions/EasyCaptcha/include/category.inc.php	(revision 26068)
+++ /extensions/EasyCaptcha/include/category.inc.php	(revision 26069)
@@ -2,5 +2,7 @@
 defined('EASYCAPTCHA_ID') or die('Hacking attempt!');
 
+$conf['EasyCaptcha']['template'] = 'comment';
 include(EASYCAPTCHA_PATH.'include/common.inc.php');
+
 add_event_handler('loc_begin_index', 'add_easycaptcha');
 add_event_handler('user_comment_check_albums', 'check_easycaptcha', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
@@ -15,5 +17,5 @@
 {
   $search = '{$comment_add.CONTENT}</textarea></p>';
-  return str_replace($search, $search."\n{\$EASYCAPTCHA_CONTENT}", $content);
+  return str_replace($search, $search."\n{\$EASYCAPTCHA.parsed_content}", $content);
 }
 
Index: /extensions/EasyCaptcha/include/common.inc.php
===================================================================
--- /extensions/EasyCaptcha/include/common.inc.php	(revision 26068)
+++ /extensions/EasyCaptcha/include/common.inc.php	(revision 26069)
@@ -27,6 +27,6 @@
 
   $conf['EasyCaptcha']['drag']['selected'] = array_rand($conf['EasyCaptcha']['drag']['selection']);
-  $conf['EasyCaptcha']['drag']['text']     = l10n($drag_images[ $conf['EasyCaptcha']['drag']['selected'] ]);
-  $conf['EasyCaptcha']['key']      = $conf['EasyCaptcha']['challenge'] .'-'. pwg_password_hash($conf['secret_key'] . $conf['EasyCaptcha']['drag']['selected']);
+  $conf['EasyCaptcha']['drag']['text'] = l10n($drag_images[ $conf['EasyCaptcha']['drag']['selected'] ]);
+  $conf['EasyCaptcha']['key'] = $conf['EasyCaptcha']['challenge'] .'-'. pwg_password_hash($conf['secret_key'] . $conf['EasyCaptcha']['drag']['selected']);
 }
 // Tic-tac-toe
@@ -49,5 +49,5 @@
 
 $template->set_filename('EasyCaptcha', realpath(EASYCAPTCHA_PATH.'template/'.$conf['EasyCaptcha']['template'].'.tpl'));
-$template->assign_var_from_handle('EASYCAPTCHA_CONTENT', 'EasyCaptcha');
+$template->append('EASYCAPTCHA', array('parsed_content' => $template->parse('EasyCaptcha', true)), true);
 
 
Index: /extensions/EasyCaptcha/include/contactform.inc.php
===================================================================
--- /extensions/EasyCaptcha/include/contactform.inc.php	(revision 26068)
+++ /extensions/EasyCaptcha/include/contactform.inc.php	(revision 26069)
@@ -2,19 +2,8 @@
 defined('EASYCAPTCHA_ID') or die('Hacking attempt!');
 
+$conf['EasyCaptcha']['template'] = 'contactform';
 include(EASYCAPTCHA_PATH.'include/common.inc.php');
-add_event_handler('loc_begin_index', 'add_easycaptcha');
+
 add_event_handler('contact_form_check', 'check_easycaptcha', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
-
-function add_easycaptcha()
-{
-  global $template;
-  $template->set_prefilter('contactform', 'prefilter_easycaptcha');
-}
-
-function prefilter_easycaptcha($content, $smarty)
-{
-  $search = '{$contact.content}</textarea></td>';
-  return str_replace($search, $search."\n{\$EASYCAPTCHA_CONTENT}", $content);
-}
 
 function check_easycaptcha($action, $comment)
Index: /extensions/EasyCaptcha/include/guestbook.inc.php
===================================================================
--- /extensions/EasyCaptcha/include/guestbook.inc.php	(revision 26068)
+++ /extensions/EasyCaptcha/include/guestbook.inc.php	(revision 26069)
@@ -2,20 +2,8 @@
 defined('EASYCAPTCHA_ID') or die('Hacking attempt!');
 
+$conf['EasyCaptcha']['template'] = 'guestbook';
 include(EASYCAPTCHA_PATH.'include/common.inc.php');
-add_event_handler('loc_begin_index', 'add_easycaptcha');
+
 add_event_handler('user_comment_check', 'check_easycaptcha', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
-
-function add_easycaptcha()
-{
-  global $template;
-  $template->set_prefilter('guestbook', 'prefilter_easycaptcha');
-}
-
-function prefilter_easycaptcha($content, $smarty)
-{
-  $search = '#{\$comment_add\.CONTENT}</textarea>(\s*)</td>(\s*)</tr>#';
-  $replace = '{\$comment_add.CONTENT}</textarea>$1</td>$2</tr>'."\n".'{\$EASYCAPTCHA_CONTENT}';
-  return preg_replace($search, $replace, $content);
-}
 
 function check_easycaptcha($action, $comment)
Index: /extensions/EasyCaptcha/include/picture.inc.php
===================================================================
--- /extensions/EasyCaptcha/include/picture.inc.php	(revision 26068)
+++ /extensions/EasyCaptcha/include/picture.inc.php	(revision 26069)
@@ -2,5 +2,7 @@
 defined('EASYCAPTCHA_ID') or die('Hacking attempt!');
 
+$conf['EasyCaptcha']['template'] = 'comment';
 include(EASYCAPTCHA_PATH.'include/common.inc.php');
+
 add_event_handler('loc_end_picture', 'add_easycaptcha');
 add_event_handler('user_comment_check', 'check_easycaptcha', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
@@ -15,5 +17,5 @@
 {
   $search = '{$comment_add.CONTENT}</textarea></p>';
-  return str_replace($search, $search."\n{\$EASYCAPTCHA_CONTENT}", $content);
+  return str_replace($search, $search."\n{\$EASYCAPTCHA.parsed_content}", $content);
 }
 
Index: /extensions/EasyCaptcha/include/register.inc.php
===================================================================
--- /extensions/EasyCaptcha/include/register.inc.php	(revision 26068)
+++ /extensions/EasyCaptcha/include/register.inc.php	(revision 26069)
@@ -2,5 +2,7 @@
 defined('EASYCAPTCHA_ID') or die('Hacking attempt!');
 
+$conf['EasyCaptcha']['template'] = 'register';
 include(EASYCAPTCHA_PATH.'include/common.inc.php');
+
 add_event_handler('loc_end_page_header', 'add_easycaptcha');
 add_event_handler('register_user_check', 'check_easycaptcha');
@@ -15,5 +17,5 @@
 {
   $search = '<input type="checkbox" name="send_password_by_mail" id="send_password_by_mail" value="1" checked="checked">';
-  return str_replace($search, $search."\n{\$EASYCAPTCHA_CONTENT}", $content);
+  return str_replace($search, $search."\n{\$EASYCAPTCHA.parsed_content}", $content);
 }
 
Index: /extensions/EasyCaptcha/main.inc.php
===================================================================
--- /extensions/EasyCaptcha/main.inc.php	(revision 26068)
+++ /extensions/EasyCaptcha/main.inc.php	(revision 26069)
@@ -32,4 +32,5 @@
 {
   add_event_handler('loc_end_section_init', 'easycaptcha_document_init', EVENT_HANDLER_PRIORITY_NEUTRAL+30);
+  add_event_handler('loc_begin_register', 'easycaptcha_register_init', EVENT_HANDLER_PRIORITY_NEUTRAL+30);
 }
 
@@ -59,12 +60,6 @@
   }
 
-  if (script_basename() == 'register' && $conf['EasyCaptcha']['activate_on']['register'])
+  if (script_basename() == 'picture' && $conf['EasyCaptcha']['activate_on']['picture'])
   {
-    $conf['EasyCaptcha']['template'] = 'register';
-    include(EASYCAPTCHA_PATH . 'include/register.inc.php');
-  }
-  else if (script_basename() == 'picture' && $conf['EasyCaptcha']['activate_on']['picture'])
-  {
-    $conf['EasyCaptcha']['template'] = 'comment';
     include(EASYCAPTCHA_PATH . 'include/picture.inc.php');
   }
@@ -78,17 +73,28 @@
       )
     {
-      $conf['EasyCaptcha']['template'] = 'comment';
       include(EASYCAPTCHA_PATH . 'include/category.inc.php');
     }
     else if ($page['section'] == 'contact' && $conf['EasyCaptcha']['activate_on']['contactform'])
     {
-      $conf['EasyCaptcha']['template'] = 'contactform';
       include(EASYCAPTCHA_PATH . 'include/contactform.inc.php');
     }
     else if ($page['section'] == 'guestbook' && $conf['EasyCaptcha']['activate_on']['guestbook'])
     {
-      $conf['EasyCaptcha']['template'] = 'guestbook';
       include(EASYCAPTCHA_PATH . 'include/guestbook.inc.php');
     }
+  }
+}
+function easycaptcha_register_init()
+{
+  global $conf;
+
+  if (!is_a_guest())
+  {
+    return;
+  }
+
+  if ($conf['EasyCaptcha']['activate_on']['register'])
+  {
+    include(EASYCAPTCHA_PATH . 'include/register.inc.php');
   }
 }
Index: /extensions/EasyCaptcha/template/contactform.tpl
===================================================================
--- /extensions/EasyCaptcha/template/contactform.tpl	(revision 26068)
+++ /extensions/EasyCaptcha/template/contactform.tpl	(revision 26069)
@@ -1,3 +1,2 @@
-</tr>
 <tr>
   {include file=$EASYCAPTCHA_ABS_PATH|cat:'template/common.inc.tpl'}
@@ -5,5 +4,9 @@
   {* <!-- DRAG & DROP --> *}
   {if $EASYCAPTCHA.challenge == 'drag'}
-  <td class="title">{'To verify you are a human, please place the <b>%s</b> in the most right box bellow.'|translate:$EASYCAPTCHA.drag.text}</td>
+  <td class="title"></td>
+  <td>
+    {'To verify you are a human, please place the <b>%s</b> in the most right box bellow.'|translate:$EASYCAPTCHA.drag.text}
+    {$smarty.capture.easycaptcha}
+  </td>
 
   {footer_script}
@@ -13,6 +16,10 @@
 
   {* <!-- TIC TAC TOE --> *}
-  {else if $EASYCAPTCHA..challenge == 'tictac'}
-  <td class="title">{'You are player X, click on the right case to complete the line.'|translate}</td>
+  {else if $EASYCAPTCHA.challenge == 'tictac'}
+  <td class="title"></td>
+  <td>
+    {'You are player X, click on the right case to complete the line.'|translate}
+    {$smarty.capture.easycaptcha}
+  </td>
 
   {footer_script}
@@ -27,5 +34,3 @@
 
   {/if}
-  <td>
-    {$smarty.capture.easycaptcha}
-  </td>
+</tr>
