Index: extensions/Subscribe_to_comments/include/functions.inc.php
===================================================================
--- extensions/Subscribe_to_comments/include/functions.inc.php	(revision 12560)
+++ extensions/Subscribe_to_comments/include/functions.inc.php	(revision 12561)
@@ -15,5 +15,5 @@
   $exclude = null;
   if (!empty($_POST['stc_mail'])) $exclude = pwg_db_real_escape_string($_POST['stc_mail']);
-  if (!is_a_guest()) $exclude = $user['email'];
+  else if (!is_a_guest()) $exclude = $user['email'];
   
   // get subscribers emails
@@ -30,10 +30,8 @@
   
   set_make_full_url();
-  switch ($type)
-  {
-    case 'image':
-    {
-      // get image infos
-      $query = '
+  if ($type == 'image')
+  {
+    // get image infos
+    $query = '
 SELECT
     id,
@@ -43,41 +41,37 @@
   WHERE id = '.$comm['image_id'].'
 ;';
-      $element = pwg_db_fetch_assoc(pwg_query($query));
-        
-      if (empty($element['name']))
-      {
-        $element['name'] = get_name_from_file($element['file']);
-      }
+    $element = pwg_db_fetch_assoc(pwg_query($query));
       
-      $url_params = array('image_id' => $element['id']);
-      if (!empty($page['category']))
-      {
-        $url_params['section'] = 'categories';
-        $url_params['category'] = $page['category'];
-      }
-
-      $element['url'] = make_picture_url($url_params);
-      break;
+    if (empty($element['name']))
+    {
+      $element['name'] = get_name_from_file($element['file']);
     }
     
-    case 'category' :
+    $url_params = array('image_id' => $element['id']);
+    if (!empty($page['category']))
     {
-      // get category infos
-      $query = '
+      $url_params['section'] = 'categories';
+      $url_params['category'] = $page['category'];
+    }
+
+    $element['url'] = make_picture_url($url_params);
+  }
+  else if ($type == 'category')
+  {
+    // get category infos
+    $query = '
 SELECT
     id,
-    name
+    name,
+    permalink
   FROM '.CATEGORIES_TABLE.'
   WHERE id = '.$comm['category_id'].'
 ;';
-      $element = pwg_db_fetch_assoc(pwg_query($query));
-      
-      $url_params['section'] = 'categories';
-      $url_params['category'] = $element;
-
-      
-      $element['url'] = make_index_url($url_params);
-      break;
-    }
+    $element = pwg_db_fetch_assoc(pwg_query($query));
+    
+    $url_params['section'] = 'categories';
+    $url_params['category'] = $element;
+    
+    $element['url'] = make_index_url($url_params);
   }
   
@@ -117,4 +111,5 @@
 }
 
+
 /*
  * add an email to subscribers list
@@ -128,15 +123,22 @@
   
   $infos = $errors = array();
-  
   if ( is_a_guest() and empty($email) )
   {
     array_push($errors, l10n('Invalid email adress, your are not subscribed to comments.'));
+    
+    $orig = $template->get_template_vars('errors');
+    if (empty($orig)) $orig = array();
+    $template->assign('errors', array_merge($orig, $errors));
+    
+    if ($type == 'category') $template->set_prefilter('index', 'coa_messages'); // here we use a prefilter existing in COA
+    
     return;
   }
-  else if ( !is_a_guest() )
+  else if (!is_a_guest())
   {
     $email = $user['email'];
   }
   
+  // don't care if already registered
   $query = '
 INSERT IGNORE INTO '.SUBSCRIBE_TO_TABLE.'(
@@ -155,6 +157,9 @@
   pwg_query($query);
   
+  // send validation mail
   if (is_a_guest() and pwg_db_insert_id() != 0)
   {
+    $element_name = ($type == 'image') ? $picture['current']['name'] : $page['category']['name'];
+    
     $mail_args = array(
       'subject' => '['.strip_tags($conf['gallery_title']).'] Please confirm your subscribtion to comments',
@@ -163,5 +168,5 @@
       
     $mail_args['content'] = '
-You requested to subscribe by email to comments on <b>'.$picture['current']['name'].'</b>.<br>
+You requested to subscribe by email to comments on <b>'.$element_name.'</b>.<br>
 <br>
 We care about your inbox, so we want to confirm this request. Please click the confirm link to activate the subscription.<br>
@@ -175,14 +180,21 @@
     array_push($infos, l10n('Please check your email inbox to confirm your subscription.'));
   }
+  // just displat confirmation message
+  else if (pwg_db_insert_id() != 0)
+  {
+    array_push($infos, l10n('You have been added to the list of subscribers for this '.($type=='image' ? 'picture' : 'album').'.'));
+  }
+  
   
   if (!empty($infos))
   {
-    $template->assign('infos', array_merge($template->get_template_vars('infos'), $infos));
-  }
-  if (!empty($errors))
-  {
-    $template->assign('errors', array_merge($template->get_template_vars('errors'), $errors));
-  }
-}
+    $orig = $template->get_template_vars('infos');
+    if (empty($orig)) $orig = array();
+    $template->assign('infos', array_merge($orig, $infos));
+    
+    if ($type == 'category') $template->set_prefilter('index', 'coa_messages');
+  }
+}
+
 
 /**
@@ -194,5 +206,9 @@
 function make_stc_url($action, $email)
 {
-  if ( empty($action) or empty($email) ) return null;
+  if ( empty($action) or empty($email) )
+  {
+    trigger_error('make_stc_url missing action and/or mail', E_USER_WARNING);
+    return null;
+  }
   
   global $conf;
@@ -219,4 +235,5 @@
 }
 
+
 /**
  * crypt a string using mcrypt extension or a binary method
@@ -266,4 +283,5 @@
 }
 
+
 /**
  * variant of base64 functions usable into url
Index: extensions/Subscribe_to_comments/language/en_UK/plugin.lang.php
===================================================================
--- extensions/Subscribe_to_comments/language/en_UK/plugin.lang.php	(revision 12560)
+++ extensions/Subscribe_to_comments/language/en_UK/plugin.lang.php	(revision 12561)
@@ -6,4 +6,9 @@
 $lang['You have been successfully unsubscribed, good bye.'] = 'You have been successfully unsubscribed, good bye.';
 $lang['Your subscribtion has been validated, thanks you.'] = 'Your subscribtion has been validated, thanks you.';
+$lang['You have been added to the list of subscribers for this picture.'] = 'You have been added to the list of subscribers for this picture.';
+$lang['You have been added to the list of subscribers for this album.'] = 'You have been added to the list of subscribers for this album.';
+$lang['You are currently subscribed to comments of this picture.'] = 'You are currently subscribed to comments of this picture.';
+$lang['You are currently subscribed to comments of this album.'] = 'You are currently subscribed to comments of this album.';
+$lang['Unsubscribe'] = 'Unsubscribe';
 
 ?>
Index: extensions/Subscribe_to_comments/language/fr_FR/plugin.lang.php
===================================================================
--- extensions/Subscribe_to_comments/language/fr_FR/plugin.lang.php	(revision 12560)
+++ extensions/Subscribe_to_comments/language/fr_FR/plugin.lang.php	(revision 12561)
@@ -4,6 +4,11 @@
 $lang['Invalid email adress, your are not subscribed to comments.'] = 'Email invalide, vous n\'avez pas été inscrit.';
 $lang['Please check your email inbox to confirm your subscription.'] = 'Veuillez consulter votre boite mail pour confirmer votre inscription.';
-$lang['You have been successfully unsubscribed, good bye.'] = 'Vous avez supprimé de la liste de notification, au revoir.';
-$lang['Your subscribtion has been validated, thanks you.'] = 'Votre inscription a bien été validée, merci..';
+$lang['You have been successfully unsubscribed, good bye.'] = 'Vous avez été supprimé de la liste de notification, au revoir.';
+$lang['Your subscribtion has been validated, thanks you.'] = 'Votre inscription a bien été validée, merci.';
+$lang['You have been added to the list of subscribers for this picture.'] = 'Vous avez été ajouté à la liste des inscrits pour les commentaires de cette photo.';
+$lang['You have been added to the list of subscribers for this album.'] = 'Vous avez été ajouté à la liste des inscrits pour les commentaires de cet album.';
+$lang['You are currently subscribed to comments of this picture.'] = 'Vous êtes actuellement inscrit aux commentaires de cette photo.';
+$lang['You are currently subscribed to comments of this album.'] = 'Vous êtes actuellement inscrit aux commentaires de cet album.';
+$lang['Unsubscribe'] = 'Se désinscrire';
 
 ?>
Index: extensions/Subscribe_to_comments/main.inc.php
===================================================================
--- extensions/Subscribe_to_comments/main.inc.php	(revision 12560)
+++ extensions/Subscribe_to_comments/main.inc.php	(revision 12561)
@@ -4,5 +4,5 @@
 Version: auto
 Description: This plugin allows you to subscribe to comments by mail.
-Plugin URI: http://piwigo.org/ext/extension_view.php?eid=
+Plugin URI: http://piwigo.org/ext/extension_view.php?eid=587
 Author: Mistic
 Author URI: http://www.strangeplanet.fr
@@ -20,9 +20,17 @@
 include_once(SUBSCRIBE_TO_PATH.'include/functions.inc.php');
 
+load_language('plugin.lang', SUBSCRIBE_TO_PATH);
+
+// send mails
 add_event_handler('user_comment_insertion', 'stc_comment_insertion');
 add_event_handler('user_comment_validation', 'stc_comment_validation', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
+
+// subscribe
 add_event_handler('loc_end_picture', 'stc_on_picture');
+add_event_handler('loc_begin_index', 'stc_on_album');
+
+// management
 add_event_handler('loc_end_section_init', 'stc_detect_section');
-add_event_handler('loc_end_index', 'stc_load_section');   
+add_event_handler('loc_end_index', 'stc_load_section');
 
 ?>
Index: extensions/Subscribe_to_comments/subscribe_to_comments.inc.php
===================================================================
--- extensions/Subscribe_to_comments/subscribe_to_comments.inc.php	(revision 12560)
+++ extensions/Subscribe_to_comments/subscribe_to_comments.inc.php	(revision 12561)
@@ -88,9 +88,14 @@
 
 /**
- * adds fields on picture page
+ * add field and link on picture page
  */
 function stc_on_picture()
 {
-  global $template;
+  global $template, $picture;
+  
+  if (isset($_POST['stc_check_stdl']))
+  {
+    subscribe_to_comments($picture['current']['id'], @$_POST['stc_mail_stdl'], 'image');
+  }
   
   $template->set_prefilter('picture', 'stc_on_picture_prefilter');
@@ -99,8 +104,14 @@
 function stc_on_picture_prefilter($template, &$smarty)
 {
-  $search = '<input type="submit" value="{\'Submit\'|@translate}">';
-  
-  $replace = '
-<label>{\'Subscribe to new comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label>
+  global $user, $picture;
+  
+  ## subscribe while add a comment ##
+  $search[0] = '<input type="submit" value="{\'Submit\'|@translate}">';
+  
+  $replace[0] = '
+<label>{\'Subscribe to new comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label>';
+  if (is_a_guest())
+  {
+    $replace[0].= ' 
 <label id="stc_mail" style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail"></label>
 {footer_script require="jquery"}{literal}
@@ -111,10 +122,198 @@
   });
 });
-{/literal}
-{/footer_script}
-'.$search;
+{/literal}{/footer_script}';
+  }
+  $replace[0].= $search[0];
+  
+  
+  ## subscribe at any moment ##
+  $search[1] = '{if isset($comment_add)}';
+  
+  $replace[1] = $search[1].'
+<form method="post" action="{$comment_add.F_ACTION}" class="filter" id="stc_standalone">
+  <fieldset>';
+  
+  // if registered user we check if already subscribed
+  if (!is_a_guest())
+  {
+    $query = '
+SELECT id
+  FROM '.SUBSCRIBE_TO_TABLE.'
+  WHERE
+    email = "'.$user['email'].'"
+    AND image_id = '.$picture['current']['id'].'
+;';
+    if (pwg_db_num_rows(pwg_query($query)))
+    {
+      $replace[1].= '
+    {\'You are currently subscribed to comments of this picture.\'|@translate}
+    <a href="'.make_stc_url('unsubscribe-image', $user['email'], $picture['current']['id']).'">{\'Unsubscribe\'|@translate}';
+      $no_form = true;
+    }
+  }
+  
+  if (!isset($no_form))
+  {
+    $replace[1].= '
+    <label><a href="#" id="stc_check_stdl">{\'Subscribe to new comments\'|@translate}</a> <input type="checkbox" name="stc_check_stdl" value="1" style="display:none;"></label>';
+    
+    // form for guests
+    if (is_a_guest())
+    {
+      $replace[1].= ' 
+      <label style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail_stdl"></label>
+      <label style="display:none;"><input type="submit" value="{\'Submit\'|@translate}"></label>
+    {footer_script require="jquery"}{literal}
+    jQuery(document).ready(function() {
+      $("a#stc_check_stdl").click(function() {
+        $("input[name=stc_check_stdl]").prop("checked", true);
+        $("#stc_standalone label").toggle();
+        return false;
+      });
+    });
+    {/literal}{/footer_script}';
+    }
+    // simple link for registered users
+    else
+    {
+      $replace[1].= '
+    {footer_script require="jquery"}{literal}
+    jQuery(document).ready(function() {
+      $("a#stc_check_stdl").click(function() {
+        $("input[name=stc_check_stdl]").prop("checked", true);
+        $(this).parents("form#stc_standalone").submit();
+        return false;
+      });
+    });
+    {/literal}{/footer_script}';
+    }
+  }
+      
+  $replace[1].= '
+  </fieldset>
+</form>';
 
   return str_replace($search, $replace, $template);
 }
 
+
+/**
+ * add field and on album page
+ */
+function stc_on_album()
+{
+  global $page, $template, $pwg_loaded_plugins;
+  
+  if (
+      script_basename() != 'index' or !isset($page['section']) or
+      !isset($pwg_loaded_plugins['Comments_on_Albums']) or 
+      $page['section'] != 'categories' or !isset($page['category'])
+    )
+  {
+    return;
+  }
+  
+  if (isset($_POST['stc_check_stdl']))
+  {
+    subscribe_to_comments($page['category']['id'], @$_POST['stc_mail_stdl'], 'category');
+  }
+  
+  $template->set_prefilter('comments_on_albums', 'stc_on_album_prefilter');
+}
+
+function stc_on_album_prefilter($template, &$smarty)
+{
+  global $user, $page;
+  
+  ## subscribe while add a comment ##
+  $search[0] = '<input type="submit" value="{\'Submit\'|@translate}">';
+  
+  $replace[0] = '
+<label>{\'Subscribe to new comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label>';
+  if (is_a_guest())
+  {
+    $replace[0].= ' 
+<label id="stc_mail" style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail"></label>
+{footer_script require="jquery"}{literal}
+jQuery(document).ready(function() {
+  $("input[name=stc_check]").change(function() {
+    if ($(this).is(":checked")) $("#stc_mail").css("display", "");
+    else $("#stc_mail").css("display", "none");
+  });
+});
+{/literal}{/footer_script}';
+  }
+  $replace[0].= $search[0];
+  
+  
+  ## subscribe at any moment ##
+  $search[1] = '{if isset($comment_add)}';
+  
+  $replace[1] = $search[1].'
+<form method="post" action="{$comment_add.F_ACTION}" class="filter" id="stc_standalone">
+  <fieldset>';
+  
+  // if registered user we check if already subscribed
+  if (!is_a_guest())
+  {
+    $query = '
+SELECT id
+  FROM '.SUBSCRIBE_TO_TABLE.'
+  WHERE
+    email = "'.$user['email'].'"
+    AND category_id = '.$page['category']['id'].'
+;';
+    if (pwg_db_num_rows(pwg_query($query)))
+    {
+      $replace[1].= '
+    {\'You are currently subscribed to comments of this album.\'|@translate}
+    <a href="'.make_stc_url('unsubscribe-category', $user['email'], $page['category']['id']).'">{\'Unsubscribe\'|@translate}';
+      $no_form = true;
+    }
+  }
+  
+  if (!isset($no_form))
+  {
+    $replace[1].= '
+    <label><a href="#" id="stc_check_stdl">{\'Subscribe to new comments\'|@translate}</a> <input type="checkbox" name="stc_check_stdl" value="1" style="display:none;"></label>';
+    
+    // form for guests
+    if (is_a_guest())
+    {
+      $replace[1].= ' 
+      <label style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail_stdl"></label>
+      <label style="display:none;"><input type="submit" value="{\'Submit\'|@translate}"></label>
+    {footer_script require="jquery"}{literal}
+    jQuery(document).ready(function() {
+      $("a#stc_check_stdl").click(function() {
+        $("input[name=stc_check_stdl]").prop("checked", true);
+        $("#stc_standalone label").toggle();
+        return false;
+      });
+    });
+    {/literal}{/footer_script}';
+    }
+    // simple link for registered users
+    else
+    {
+      $replace[1].= '
+    {footer_script require="jquery"}{literal}
+    jQuery(document).ready(function() {
+      $("a#stc_check_stdl").click(function() {
+        $("input[name=stc_check_stdl]").prop("checked", true);
+        $(this).parents("form#stc_standalone").submit();
+        return false;
+      });
+    });
+    {/literal}{/footer_script}';
+    }
+  }
+      
+  $replace[1].= '
+  </fieldset>
+</form>';
+
+  return str_replace($search, $replace, $template);
+}
+
 ?>
