Index: /extensions/reply_to/index.php
===================================================================
--- /extensions/reply_to/index.php	(revision 11252)
+++ /extensions/reply_to/index.php	(revision 11252)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based photo gallery                                    |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/reply_to/insertAtCaret.js
===================================================================
--- /extensions/reply_to/insertAtCaret.js	(revision 11252)
+++ /extensions/reply_to/insertAtCaret.js	(revision 11252)
@@ -0,0 +1,29 @@
+/**
+ * insertAtCaret function by sebagr.com
+ * http://stackoverflow.com/questions/946534/insert-text-into-textarea-with-jquery/2819568#2819568
+ */
+jQuery.fn.extend({
+  insertAtCaret: function(myValue){
+    return this.each(function(i) {
+      if (document.selection) {
+        this.focus();
+        sel = document.selection.createRange();
+        sel.text = myValue;
+        this.focus();
+      }
+      else if (this.selectionStart || this.selectionStart == '0') {
+        var startPos = this.selectionStart;
+        var endPos = this.selectionEnd;
+        var scrollTop = this.scrollTop;
+        this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos,this.value.length);
+        this.focus();
+        this.selectionStart = startPos + myValue.length;
+        this.selectionEnd = startPos + myValue.length;
+        this.scrollTop = scrollTop;
+      } else {
+        this.value += myValue;
+        this.focus();
+      }
+    })
+  }
+});
Index: /extensions/reply_to/language/en_UK/description.txt
===================================================================
--- /extensions/reply_to/language/en_UK/description.txt	(revision 11252)
+++ /extensions/reply_to/language/en_UK/description.txt	(revision 11252)
@@ -0,0 +1,1 @@
+This plugin allows you to add Twitter-like reply links to comments.
Index: /extensions/reply_to/language/en_UK/index.php
===================================================================
--- /extensions/reply_to/language/en_UK/index.php	(revision 11252)
+++ /extensions/reply_to/language/en_UK/index.php	(revision 11252)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/reply_to/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/reply_to/language/en_UK/plugin.lang.php	(revision 11252)
+++ /extensions/reply_to/language/en_UK/plugin.lang.php	(revision 11252)
@@ -0,0 +1,5 @@
+<?php
+
+$lang['reply to this comment'] = 'reply to this comment';
+
+?>
Index: /extensions/reply_to/language/fr_FR/description.txt
===================================================================
--- /extensions/reply_to/language/fr_FR/description.txt	(revision 11252)
+++ /extensions/reply_to/language/fr_FR/description.txt	(revision 11252)
@@ -0,0 +1,1 @@
+Ce plugin permet d'ajouter un lien de réponse aux commentaires à la manière de Twitter.
Index: /extensions/reply_to/language/fr_FR/index.php
===================================================================
--- /extensions/reply_to/language/fr_FR/index.php	(revision 11252)
+++ /extensions/reply_to/language/fr_FR/index.php	(revision 11252)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/reply_to/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/reply_to/language/fr_FR/plugin.lang.php	(revision 11252)
+++ /extensions/reply_to/language/fr_FR/plugin.lang.php	(revision 11252)
@@ -0,0 +1,5 @@
+<?php
+
+$lang['reply to this comment'] = 'répondre à ce commentaire';
+
+?>
Index: /extensions/reply_to/language/index.php
===================================================================
--- /extensions/reply_to/language/index.php	(revision 11252)
+++ /extensions/reply_to/language/index.php	(revision 11252)
@@ -0,0 +1,30 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based picture gallery                                  |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/reply_to/main.inc.php
===================================================================
--- /extensions/reply_to/main.inc.php	(revision 11252)
+++ /extensions/reply_to/main.inc.php	(revision 11252)
@@ -0,0 +1,42 @@
+<?php 
+/*
+Plugin Name: Reply To
+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=
+Author: Mistic
+Author URI: http://www.strangeplanet.fr
+*/
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+global $page;
+
+define('REPLYTO_DIR' , basename(dirname(__FILE__)));
+define('REPLYTO_PATH' , PHPWG_PLUGINS_PATH . REPLYTO_DIR . '/');
+
+include_once(REPLYTO_PATH.'reply_to.inc.php');
+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', 10);
+}
+// 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', 10);
+}
+    
+?>
Index: /extensions/reply_to/reply_to.inc.php
===================================================================
--- /extensions/reply_to/reply_to.inc.php	(revision 11252)
+++ /extensions/reply_to/reply_to.inc.php	(revision 11252)
@@ -0,0 +1,218 @@
+<?php 
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+/**
+ * Add anchors and reply button to comments blocks
+ */
+function replyto_add_link()
+{
+  global $pwg_loaded_plugins, $template, $page, $conf;
+  $template->assign('REPLYTO_PATH', REPLYTO_PATH);
+  
+  // comment form has different id
+  if (
+    (isset($_GET['action']) AND $_GET['action'] == 'edit_comment') OR 
+    (isset($page['body_id']) AND $page['body_id'] == 'theCommentsPage')
+    ) 
+  {
+    $template->assign('replyto_form_name', 'editComment');
+  } 
+  else 
+  {
+    $template->assign('replyto_form_name', 'addComment');
+  }
+    
+  // must re-check our location + some additional tests
+  if (script_basename() == 'picture')
+  {
+    add_event_handler('render_comment_content', 'replyto_parse_picture', 10);
+    if ( !is_a_guest() OR $conf['comments_forall'] )
+    {
+      $template->set_prefilter('picture', 'replyto_add_link_prefilter');
+    }
+  } 
+  else if 
+    (
+      script_basename() == 'index' 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', 10);
+    if ( !is_a_guest() OR $conf['comments_forall'] )
+    {
+      $template->set_prefilter('comments_on_albums', 'replyto_add_link_prefilter');
+    }
+  }
+}
+
+function replyto_add_link_prefilter($content, &$smarty)
+{
+  // script
+  $search[0] = '<ul class="thumbnailCategories">';
+  $replace[0] = '
+{combine_script id=\'insertAtCaret\' require=\'jquery\' path=$REPLYTO_PATH|@cat:\'insertAtCaret.js\'}
+
+{footer_script require=\'insertAtCaret\'}
+function replyto(commentID, author) {ldelim}
+  jQuery("#{$replyto_form_name} textarea").insertAtCaret("[reply=" + commentID + "]" + author + "[/reply] ");
+}
+{/footer_script}
+
+{html_head}
+<style type="text/css">
+  .replyTo {ldelim}
+    display:inline-block;
+    width:16px;
+    height:16px;
+    background:url({$REPLYTO_PATH}reply.png) center top no-repeat;
+  }
+  .replyTo:hover {ldelim}
+    background-position:center -16px;
+  }
+</style>
+{/html_head}'
+.$search[0];
+
+  // button
+  $search[1] = '<span class="author">';
+  $replace[1] = '
+{if not isset($comment.IN_EDIT)}
+<div class="actions" style="float:right;">
+  <a title="{\'reply to this comment\'|@translate}" class="replyTo" onclick="replyto(\'{$comment.ID}\', \'{$comment.AUTHOR}\');">&nbsp;</a>
+</div>
+{/if}'
+.$search[1];
+  
+  // anchor
+  $search[2] = '<div class="thumbnailCategory';
+  $replace[2] = '
+<a name="comment-{$comment.ID}"></a>'
+.$search[2];
+
+  return str_replace($search, $replace, $content);
+}
+
+
+/**
+ * Replace BBcode tag by a link with absolute url
+ */
+function replyto_parse_picture($comment)
+{
+  if (preg_match('#\[reply=([1-9]+)\](.*)\[/reply\]#si', $comment, $matches))
+  {
+    // picture informations
+    $query = '
+SELECT
+  img.id,
+  img.file,
+  cat.category_id
+FROM ' . IMAGES_TABLE . ' AS img
+INNER JOIN ' . IMAGE_CATEGORY_TABLE . ' AS cat
+  ON cat.image_id = img.id
+INNER JOIN ' . COMMENTS_TABLE . ' AS com
+  ON com.image_id = img.id
+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 = '
+SELECT 
+  id, 
+  name, 
+  permalink, 
+  uppercats
+FROM ' . CATEGORIES_TABLE . '
+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=([1-9]+)\](.*)\[/reply\]#si";
+      $replace = '@ <a href="'.$image['url'].'#comment-$1">$2</a> :';
+    }
+    else
+    {
+      $search = "#\[reply=([1-9]+)\](.*)\[/reply\]#si";
+      $replace = '';
+    }
+    
+    return preg_replace($search, $replace, $comment);
+  }
+  else
+  {
+    return $comment;
+  }
+}
+
+function replyto_parse_album($comment)
+{
+  if (preg_match('#\[reply=([1-9]+)\](.*)\[/reply\]#si', $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)
+    $query = '
+SELECT id
+FROM ' . COA_TABLE . '
+WHERE content = "' . $comment .'"
+;';
+    if (!pwg_db_num_rows(pwg_query($query)))
+    {
+      return $comment;
+    }
+    
+    // retrieving category informations
+    $query = '
+SELECT
+  cat.id, 
+  cat.name, 
+  cat.permalink, 
+  cat.uppercats
+FROM ' . COA_TABLE . ' AS com
+INNER JOIN ' . CATEGORIES_TABLE . ' AS cat
+  ON cat.id = com.category_id
+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=([1-9]+)\](.*)\[/reply\]#si";
+      $replace = '@ <a href="'.$category['url'].'#comment-$1">$2</a> :';
+    }
+    else
+    {
+      $search = "#\[reply=([1-9]+)\](.*)\[/reply\]#si";
+      $replace = '';
+    }
+    
+    return preg_replace($search, $replace, $comment);
+  }
+  else
+  {
+    return $comment;
+  }
+}
+
+?>
