Index: /extensions/reply_to/main.inc.php
===================================================================
--- /extensions/reply_to/main.inc.php	(revision 11415)
+++ /extensions/reply_to/main.inc.php	(revision 11416)
@@ -4,5 +4,5 @@
 Version: auto
 Description: This plugin allows you to add Twitter-like reply links to comments.
-Plugin URI: http://piwigo.org/ext/extension_view.php?eid=
+Plugin URI: http://piwigo.org/ext/extension_view.php?eid=556
 Author: Mistic
 Author URI: http://www.strangeplanet.fr
@@ -19,34 +19,7 @@
 load_language('plugin.lang', REPLYTO_PATH);
 
-// add link and parse on picture page
-if (script_basename() == 'picture')
-{
-  add_event_handler('loc_begin_picture', 'replyto_add_link');
-}
-// parse on comments page (picture section)
-else if (script_basename() == 'comments' AND !isset($_GET['display_mode']))
-{
-  add_event_handler('render_comment_content', 'replyto_parse_picture', 60);
-}
-// parse comment admin side (picture section)
-else if (script_basename() == 'admin' AND isset($_GET['page']) AND $_GET['page'] == 'comments' AND ( !isset($_GET['section']) OR $_GET['section'] == 'pictures' ) )
-{
-  add_event_handler('render_comment_content', 'replyto_parse_picture', 60);
-}
-// add link and parse on album page (compatibility with Comment on Albums)
-else if (script_basename() == 'index')
-{
-  add_event_handler('loc_begin_index', 'replyto_add_link');
-}
-// parse on comments page (album section)
-else if (script_basename() == 'comments' AND $_GET['display_mode'] == 'albums')
-{
-  add_event_handler('render_comment_content', 'replyto_parse_album', 60);
-}
-// parse comment admin side (album section)
-else if (script_basename() == 'admin' AND isset($_GET['page']) AND $_GET['page'] == 'comments' AND $_GET['section'] == 'albums')
-{
-  add_event_handler('render_comment_content', 'replyto_parse_album', 60);
-}
+add_event_handler('render_comment_content', 'replyto_parse', 60, 2);
+// add_event_handler('init', 'replyto_add_link');                  // for comments page (section_init.inc is not called on this page)
+add_event_handler('loc_end_section_init', 'replyto_add_link');  // for all the rest
     
 ?>
Index: /extensions/reply_to/reply_to.inc.php
===================================================================
--- /extensions/reply_to/reply_to.inc.php	(revision 11415)
+++ /extensions/reply_to/reply_to.inc.php	(revision 11416)
@@ -1,4 +1,6 @@
 <?php 
 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+define('REPLYTO_REGEX', '#\[reply=([0-9]+)\]([^\[\]]*)\[/reply\]#i');
 
 /**
@@ -22,10 +24,18 @@
     $template->assign('replyto_form_name', 'addComment');
   }
+  
+  // must check our location + some additional tests
+  // if (script_basename() == 'comments')
+  // {
+    // if ( !is_a_guest() OR $conf['comments_forall'] )
+    // {
+      // $template->set_prefilter('comments', 'replyto_add_link_prefilter');
+    // }
+  // }
+  // else 
+  if (script_basename() == 'picture')
+  {
+    add_event_handler('user_comment_insertion', 'replyto_parse_picture_mail');
     
-  // must re-check our location + some additional tests
-  if (script_basename() == 'picture')
-  {
-    add_event_handler('render_comment_content', 'replyto_parse_picture', 60);
-    add_event_handler('user_comment_insertion', 'replyto_parse_picture_mail');
     if ( !is_a_guest() OR $conf['comments_forall'] )
     {
@@ -35,11 +45,11 @@
   else if 
     (
-      script_basename() == 'index' AND 
+      script_basename() == 'index' AND isset($page['section']) AND
       isset($pwg_loaded_plugins['Comments_on_Albums']) AND 
       $page['section'] == 'categories' AND isset($page['category'])
     )
   {
-    add_event_handler('render_comment_content', 'replyto_parse_album', 60);
     add_event_handler('user_comment_insertion', 'replyto_parse_album_mail');
+    
     if ( !is_a_guest() OR $conf['comments_forall'] )
     {
@@ -57,5 +67,5 @@
 
 {footer_script require=\'insertAtCaret\'}
-function replyto(commentID, author) {ldelim}
+function replyTo(commentID, author) {ldelim}
   jQuery("#{$replyto_form_name} textarea").insertAtCaret("[reply=" + commentID + "]" + author + "[/reply] ");
 }
@@ -82,5 +92,5 @@
 {if not isset($comment.IN_EDIT)}
 <div class="actions" style="float:right;">
-  <a href="#commentform" title="{\'reply to this comment\'|@translate}" class="replyTo" onclick="replyto(\'{$comment.ID}\', \'{$comment.AUTHOR}\');">&nbsp;</a>
+  <a href="#commentform" title="{\'reply to this comment\'|@translate}" class="replyTo" onclick="replyTo(\'{$comment.ID}\', \'{$comment.AUTHOR}\');">&nbsp;</a>
 </div>
 {/if}'
@@ -104,10 +114,13 @@
  * Replace BBcode tag by a link with absolute url
  */
-function replyto_parse_picture($comment)
-{
-  if (preg_match('#\[reply=([0-9]+)\]([^\[\]]*)\[/reply\]#i', $comment, $matches))
-  {
-    // picture informations
-    $query = '
+function replyto_parse($comment, $in_album = false)
+{
+  if (preg_match(REPLYTO_REGEX, $comment, $matches))
+  { 
+    /* try to parse a ReplyTo tag link for picture page */
+    if (!$in_album)
+    {
+      // picture informations
+      $query = '
 SELECT
   img.id,
@@ -121,13 +134,13 @@
 WHERE com.id = ' . $matches[1] . '
 ;';
-    $result = pwg_query($query);
-    
-    // make sure the target comment exists
-    if (pwg_db_num_rows($result))
-    {
-      $image = pwg_db_fetch_assoc($result);
-
-      // retrieving category informations
-      $query = '
+      $result = pwg_query($query);
+      
+      // make sure the target comment exists
+      if (pwg_db_num_rows($result))
+      {
+        $image = pwg_db_fetch_assoc($result);
+
+        // retrieving category informations
+        $query = '
 SELECT 
   id, 
@@ -138,50 +151,25 @@
 WHERE id = ' . $image['category_id'] . '
 ;';
-      $image['cat'] = pwg_db_fetch_assoc(pwg_query($query));
-
-      // link to the full size picture
-      $image['url'] = make_picture_url(array(
-        'category' => $image['cat'],
-        'image_id' => $image['id'],
-        'image_file' => $image['file'],
-      ));		  
-      
-      $search = "#\[reply=([0-9]+)\]([^\[\]]*)\[/reply\]#i";
-      $replace = '@ <a href="'.get_absolute_root_url().$image['url'].'#comment-$1">$2</a> :';
-    }
+        $image['cat'] = pwg_db_fetch_assoc(pwg_query($query));
+
+        // link to the full size picture
+        $image['url'] = make_picture_url(array(
+          'category' => $image['cat'],
+          'image_id' => $image['id'],
+          'image_file' => $image['file'],
+        ));		  
+        
+        $replace = '@ <a href="'.get_absolute_root_url().$image['url'].'#comment-$1">$2</a> :';
+      }
+      else
+      {
+        $replace = '';
+      }
+    } 
+    /* try to parse a ReplyTo tag link for an album */
     else
-    {
-      $search = "#\[reply=([0-9]+)\]([^\[\]]*)\[/reply\]#i";
-      $replace = '';
-    }
-    
-    return preg_replace($search, $replace, $comment);
-  }
-  else
-  {
-    return $comment;
-  }
-}
-
-function replyto_parse_album($comment)
-{
-  if (preg_match('#\[reply=([0-9]+)\]([^\[\]]*)\[/reply\]#i', $comment, $matches))
-  {  
-    // check if the comment is really an album comment 
-    // (both comments_on_albums script and default comments script are executed... 
-    //  with the same 'render_comment_content' event)
-    ## THIS CAN INDUCE ERRORS, MUST FIND A BETTER WAY
-    $query = '
-SELECT id
-FROM ' . COA_TABLE . '
-WHERE content = "' . $comment .'"
-;';
-    if (!pwg_db_num_rows(pwg_query($query)))
-    {
-      return $comment;
-    }
-    
-    // retrieving category informations
-    $query = '
+    {    
+      // retrieving category informations
+      $query = '
 SELECT
   cat.id, 
@@ -194,26 +182,25 @@
 WHERE com.id = ' . $matches[1] . '
 ;';
-    $result = pwg_query($query);
-    
-    // make sure the target comment exists
-    if (pwg_db_num_rows($result))
-    {
-      $category = pwg_db_fetch_assoc($result);
-
-      // link to the album
-      $category['url'] = make_index_url(array(
-        'category' => $category,
-      ));		  
-    
-      $search = "#\[reply=([0-9]+)\]([^\[\]]*)\[/reply\]#i";
-      $replace = '@ <a href="'.get_absolute_root_url().$category['url'].'#comment-$1">$2</a> :';
+      $result = pwg_query($query);
+      
+      // make sure the target comment exists
+      if (pwg_db_num_rows($result))
+      {
+        $category = pwg_db_fetch_assoc($result);
+
+        // link to the album
+        $category['url'] = make_index_url(array(
+          'category' => $category,
+        ));		  
+      
+        $replace = '@ <a href="'.get_absolute_root_url().$category['url'].'#comment-$1">$2</a> :';
+      }
+      else
+      {
+        $replace = '';
+      }
     }
-    else
-    {
-      $search = "#\[reply=([0-9]+)\]([^\[\]]*)\[/reply\]#i";
-      $replace = '';
-    }
-    
-    return preg_replace($search, $replace, $comment);
+  
+    return preg_replace(REPLYTO_REGEX, $replace, $comment);
   }
   else
@@ -228,5 +215,5 @@
 function replyto_parse_picture_mail($comment)
 {
-  $comment['content'] = replyto_parse_picture($comment['content']);
+  $comment['content'] = replyto_parse($comment['content']);
   return $comment;
 }
@@ -234,5 +221,5 @@
 function replyto_parse_album_mail($comment)
 {
-  $comment['content'] = replyto_parse_album($comment['content']);
+  $comment['content'] = replyto_parse($comment['content'], 'album');
   return $comment;
 }
