Index: /extensions/Subscribe_to_comments/include/functions.inc.php
===================================================================
--- /extensions/Subscribe_to_comments/include/functions.inc.php	(revision 12599)
+++ /extensions/Subscribe_to_comments/include/functions.inc.php	(revision 12600)
@@ -9,4 +9,10 @@
 {
   global $conf, $page, $user;
+  
+  if ( empty($comm) or !is_array($comm) )
+  {
+    trigger_error('send_comment_to_subscribers: undefinided comm', E_USER_WARNING);
+    return false;
+  }
   
   $type= isset($comm['category_id']) ? 'category' : 'image';
@@ -32,46 +38,9 @@
   if ($type == 'image')
   {
-    // get image infos
-    $query = '
-SELECT
-    id,
-    name,
-    file
-  FROM '.IMAGES_TABLE.'
-  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']);
-    }
-    
-    $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);
+    $element = get_picture_infos($comm['image_id']);
   }
   else if ($type == 'category')
   {
-    // get category infos
-    $query = '
-SELECT
-    id,
-    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);
+    $element = get_category_infos($comm['category_id']);
   }
   
@@ -101,8 +70,6 @@
   {
     $mail_args['content'] = $generic_content.'
-<a href="'.make_stc_url('unsubscribe-'.$type, $email, $element['id']).'">Stop receiving notifications for this picture</a><br>
-<a href="'.make_stc_url('unsubscribe-all', $email).'">Stop receiving all notifications</a><br>
-';
-//<a href="'.make_stc_url('manage', $email).'">Manage my subscribtions</a>
+<a href="'.make_stc_url('unsubscribe-'.$type, $email, $element['id']).'">Stop receiving notifications</a><br>
+<a href="'.make_stc_url('manage', $email).'">Manage my subscribtions</a>';
     pwg_mail($email, $mail_args);
   }
@@ -120,18 +87,16 @@
 function subscribe_to_comments($element_id, $email, $type='image')
 {
-  global $page, $user, $conf, $template, $picture;
-  
-  $infos = $errors = array();
+  global $page, $conf, $user, $template, $picture;
+  
+  if ( empty($element_id) or empty($type) )
+  {
+    trigger_error('subscribe_to_comment: missing element_id and/or type', E_USER_WARNING);
+    return false;
+  }
+  
+  // check email
   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;
+    return false;
   }
   else if (!is_a_guest())
@@ -142,5 +107,5 @@
   // don't care if already registered
   $query = '
-INSERT IGNORE INTO '.SUBSCRIBE_TO_TABLE.'(
+INSERT INTO '.SUBSCRIBE_TO_TABLE.'(
     email,
     '.$type.'_id,
@@ -154,9 +119,12 @@
     "'.(is_a_guest() ? "false" : "true").'"
   )
+  ON DUPLICATE KEY UPDATE
+    registration_date = IF(validated="true", registration_date, NOW()),
+    validated = IF(validated="true", validated, "'.(is_a_guest() ? "false" : "true").'")
 ;';
   pwg_query($query);
   
   // send validation mail
-  if (is_a_guest() and pwg_db_insert_id() != 0)
+  if ( is_a_guest() and pwg_db_changes(null) != 0 )
   {
     $element_name = ($type == 'image') ? $picture['current']['name'] : $page['category']['name'];
@@ -178,23 +146,100 @@
 
     pwg_mail($email, $mail_args);
-    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))
-  {
-    $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');
-  }
-}
-
+    return 'confirm_mail';
+  }
+  // just display confirmation message
+  else if (pwg_db_changes(null) != 0)
+  {
+    return true;
+  }
+}
+
+/*
+ * remove an email from subscribers list
+ * @param int (image|category)_id
+ * @param string email
+ * @param string type (image|category)
+ */
+function un_subscribe_to_comments($element_id, $email, $type='image')
+{
+  global $template, $user;
+  
+  if ( empty($element_id) or empty($type) )
+  {
+    trigger_error('un_subscribe_to_comment: missing element_id and/or type', E_USER_WARNING);
+    return false;
+  }
+  
+  // check email
+  if ( is_a_guest() and empty($email) )
+  {
+    return false;
+  }
+  else if (!is_a_guest())
+  {
+    $email = $user['email'];
+  }
+  
+  // delete subscription
+  switch ($type)
+  {
+    case 'image' :
+    case 'category' :
+      $where_clause = $type.'_id = '.pwg_db_real_escape_string($element_id);
+    case 'all' :
+    {
+      $query = '
+DELETE FROM '.SUBSCRIBE_TO_TABLE.'
+  WHERE 
+    email = "'.pwg_db_real_escape_string($email).'"
+    '.(!empty($where_clause) ? 'AND '.$where_clause : null).'
+;';
+      pwg_query($query);
+      
+      return true;
+      break;
+    }
+  }
+  
+  return false;
+}
+
+/*
+ * validate a subscription
+ * @param int (image|category)_id
+ * @param string email
+ * @param string type (image|category)
+ */
+function validate_subscriptions($element_id, $email, $type='image')
+{
+  if ( empty($element_id) or empty($email) or empty($type) )
+  {
+    trigger_error('validate_subscriptions: missing element_id and/or email and/or type', E_USER_WARNING);
+    return false;
+  }
+  
+  switch ($type)
+  {
+    case 'image' :
+    case 'category':
+      $where_clause = $type.'_id = '.pwg_db_real_escape_string($element_id);
+    case 'all' :
+    {
+       $query = '
+UPDATE '.SUBSCRIBE_TO_TABLE.'
+  SET validated = "true"
+  WHERE 
+    email = "'.pwg_db_real_escape_string($email).'"
+    '.(!empty($where_clause) ? 'AND '.$where_clause : null).'
+;';
+      pwg_query($query);
+      
+      if (pwg_db_changes(null) != 0) return true;
+      break;
+    }
+  }
+  
+  return false;
+}
 
 /**
@@ -208,5 +253,5 @@
   if ( empty($action) or empty($email) )
   {
-    trigger_error('make_stc_url missing action and/or mail', E_USER_WARNING);
+    trigger_error('make_stc_url: missing action and/or mail', E_USER_WARNING);
     return null;
   }
@@ -218,11 +263,15 @@
     'action' => $action,
     'email' => $email,
-    'key' => crypt_value($action.$email, $conf['secret_key']),
     );
   
   if (func_num_args() > 2)
   {
-    $url_params['param'] = func_get_arg(2);
-  }
+    $url_params['id'] = func_get_arg(2);
+  }
+  
+  $url_params['key'] = crypt_value(
+    $action.$email.(isset($url_params['id'])?$url_params['id']:null), 
+    $conf['secret_key']
+    );
   
   $url = add_url_params(
@@ -235,4 +284,62 @@
 }
 
+/**
+ * get name and url of a picture
+ * @param int image_id
+ * @return array
+ */
+function get_picture_infos($image_id, $absolute=false)
+{
+  global $page;
+  
+  $query = '
+SELECT
+    id,
+    name,
+    file
+  FROM '.IMAGES_TABLE.'
+  WHERE id = '.$image_id.'
+;';
+  $element = pwg_db_fetch_assoc(pwg_query($query));
+    
+  if (empty($element['name']))
+  {
+    $element['name'] = get_name_from_file($element['file']);
+  }
+  
+  $url_params = array('image_id' => $element['id']);
+  if ( !empty($page['category']) and !$absolute )
+  {
+    $url_params['section'] = 'categories';
+    $url_params['category'] = $page['category'];
+  }
+  $element['url'] = make_picture_url($url_params);
+  
+  return $element;
+}
+
+/**
+ * get name and url of a category
+ * @param int cat_id
+ * @return array
+ */
+function get_category_infos($cat_id)
+{
+  $query = '
+SELECT
+    id,
+    name,
+    permalink
+  FROM '.CATEGORIES_TABLE.'
+  WHERE id = '.$cat_id.'
+;';
+  $element = pwg_db_fetch_assoc(pwg_query($query));
+  
+  $url_params['section'] = 'categories';
+  $url_params['category'] = $element;
+  $element['url'] = make_index_url($url_params);
+  
+  return $element;
+}
 
 /**
Index: /extensions/Subscribe_to_comments/include/subscribe_to_comments.inc.php
===================================================================
--- /extensions/Subscribe_to_comments/include/subscribe_to_comments.inc.php	(revision 12600)
+++ /extensions/Subscribe_to_comments/include/subscribe_to_comments.inc.php	(revision 12600)
@@ -0,0 +1,463 @@
+<?php
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+/**
+ * detect 'subscriptions' section and load page
+ */
+function stc_detect_section() {
+  global $tokens, $page;
+  
+  if ($tokens[0] == 'subscriptions')
+  {
+    $page['section'] = 'subscriptions';
+  }
+}
+
+function stc_load_section() {
+  global $page;
+
+  if (isset($page['section']) and $page['section'] == 'subscriptions')
+  {
+    include(SUBSCRIBE_TO_PATH.'include/subscribtions_page.inc.php');
+  }
+}
+
+
+/**
+ * send notifications and/or add subscriber
+ */
+function stc_comment_insertion($comm)
+{
+  global $page, $template;
+  
+  $infos = $errors = array();
+  
+  if ($comm['action'] == 'validate')
+  {
+    send_comment_to_subscribers($comm);
+  }
+  
+  if ( !empty($_POST['stc_check']) and ( $comm['action'] == 'validate' or $comm['action'] == 'moderate' ) )
+  {
+    if (isset($comm['image_id']))
+    {
+      $return = subscribe_to_comments($comm['image_id'], @$_POST['stc_mail'], 'image');
+    }
+    else if (isset($comm['category_id']))
+    {
+      $return = subscribe_to_comments($comm['category_id'], @$_POST['stc_mail'], 'category');
+      
+    }
+    
+    if (isset($return))
+    {
+      if ($return === 'confirm_mail')
+      {
+        array_push($infos, l10n('Please check your email inbox to confirm your subscription.'));
+      }
+      else if ($return === true)
+      {
+        array_push($infos, l10n('You have been added to the list of subscribers for this '.(isset($comm['image_id'])?'picture':'album').'.'));
+      }
+      else
+      {
+        array_push($errors, l10n('Invalid email adress, your are not subscribed to comments.'));
+      }
+      
+       // messages management
+      if (!empty($errors))
+      {
+        $errors_bak = $template->get_template_vars('errors');
+        if (empty($errors_bak)) $errors_bak = array();
+        $template->assign('errors', array_merge($errors_bak, $errors));
+        $template->set_prefilter('index', 'coa_messages'); // here we use a prefilter existing in COA
+      }
+      if (!empty($infos))
+      {
+        $infos_bak = $template->get_template_vars('infos');
+        if (empty($infos_bak)) $infos_bak = array();
+        $template->assign('infos', array_merge($infos_bak, $infos));
+        $template->set_prefilter('index', 'coa_messages');
+      }
+    }
+  }
+}
+
+function stc_comment_validation($comm_ids, $type='image')
+{
+  if (!is_array($comm_ids)) $comm_ids = array($comm_ids);
+  
+  foreach($comm_ids as $comm_id)
+  {
+    if ($type == 'image')
+    {
+      $query = '
+SELECT
+    id,
+    image_id,
+    author,
+    content
+  FROM '.COMMENTS_TABLE.'
+  WHERE id = '.$comm_id.'
+;';
+    }
+    else if ($type == 'category')
+    {
+      $query = '
+SELECT
+    id,
+    category_id,
+    author,
+    content
+  FROM '.COA_TABLE.'
+  WHERE id = '.$comm_id.'
+;';
+    }
+    
+    $comm = pwg_db_fetch_assoc(pwg_query($query));
+    send_comment_to_subscribers($comm);
+  }
+}
+
+
+/**
+ * add field and link on picture page
+ */
+function stc_on_picture()
+{
+  global $template, $picture, $page;
+  
+  $infos = $array = array();
+  
+  if (isset($_POST['stc_check_stdl']))
+  {
+    $return = subscribe_to_comments($picture['current']['id'], @$_POST['stc_mail_stdl'], 'image');
+    if ($return === 'confirm_mail')
+    {
+      array_push($infos, l10n('Please check your email inbox to confirm your subscription.'));
+    }
+    else if ($return === true)
+    {
+      array_push($infos, l10n('You have been added to the list of subscribers for this picture.'));
+    }
+    else
+    {
+      array_push($errors, l10n('Invalid email adress, your are not subscribed to comments.'));
+    }
+  }
+  else if (isset($_GET['stc_unsubscribe']))
+  {
+    if (un_subscribe_to_comments($picture['current']['id'], null, 'image'))
+    {
+      array_push($infos, l10n('Successfully unsubscribed your email address from receiving notifications.'));
+    }
+  }
+  
+  // messages management
+  if (!empty($errors))
+  {
+    $errors_bak = $template->get_template_vars('errors');
+    if (empty($errors_bak)) $errors_bak = array();
+    $template->assign('errors', array_merge($errors_bak, $errors));
+  }
+  if (!empty($infos))
+  {
+    $infos_bak = $template->get_template_vars('infos');
+    if (empty($infos_bak)) $infos_bak = array();
+    $template->assign('infos', array_merge($infos_bak, $infos));
+  }
+  
+  $template->set_prefilter('picture', 'stc_on_picture_prefilter');
+}
+
+function stc_on_picture_prefilter($template, &$smarty)
+{
+  global $user, $picture;  
+  
+  ## 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'].'
+    AND validated = "true"
+;';
+    if (pwg_db_num_rows(pwg_query($query)))
+    {
+      $replace[1].= '
+    {\'You are currently subscribed to comments of this picture.\'|@translate}
+    <a href="'.add_url_params($picture['current']['url'], array('stc_unsubscribe'=>'1')).'">{\'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>';
+
+
+  ## subscribe while add a comment ##
+  $search[0] = '<input type="submit" value="{\'Submit\'|@translate}">';
+  $replace[0] = null;
+  
+  if (!isset($no_form))
+  {
+    $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];
+  
+  return str_replace($search, $replace, $template);
+}
+
+
+/**
+ * add field and on album page
+ */
+function stc_on_album()
+{
+  global $page, $template, $pwg_loaded_plugins;
+  
+  $infos = $errors = array();
+  
+  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']))
+  {
+    $return = subscribe_to_comments($page['category']['id'], @$_POST['stc_mail_stdl'], 'category');
+    if ($return === 'confirm_mail')
+    {
+      array_push($infos, l10n('Please check your email inbox to confirm your subscription.'));
+    }
+    else if ($return === true)
+    {
+      array_push($infos, l10n('You have been added to the list of subscribers for this album.'));
+    }
+    else
+    {
+      array_push($errors, l10n('Invalid email adress, your are not subscribed to comments.'));
+    }
+  }
+  else if (isset($_GET['stc_unsubscribe']))
+  {
+    if (un_subscribe_to_comments($page['category']['id'], null, 'category'))
+    {
+      array_push($infos, l10n('Successfully unsubscribed your email address from receiving notifications.'));
+    }
+  }
+  
+  // messages management
+  if (!empty($errors))
+  {
+    $errors_bak = $template->get_template_vars('errors');
+    if (empty($errors_bak)) $errors_bak = array();
+    $template->assign('errors', array_merge($errors_bak, $errors));
+    $template->set_prefilter('index', 'coa_messages'); // here we use a prefilter existing in COA
+  }
+  if (!empty($infos))
+  {
+    $infos_bak = $template->get_template_vars('infos');
+    if (empty($infos_bak)) $infos_bak = array();
+    $template->assign('infos', array_merge($infos_bak, $infos));
+    $template->set_prefilter('index', 'coa_messages');
+  }
+  
+  $template->set_prefilter('comments_on_albums', 'stc_on_album_prefilter');
+}
+
+function stc_on_album_prefilter($template, &$smarty)
+{
+  global $user, $page;  
+  
+  ## 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'].'
+    AND validated = "true"
+;';
+    if (pwg_db_num_rows(pwg_query($query)))
+    {
+      $url_params['section'] = 'categories';
+      $url_params['category'] = $page['category'];
+      
+      $element_url = make_index_url($url_params);
+    
+      $replace[1].= '
+    {\'You are currently subscribed to comments of this album.\'|@translate}
+    <a href="'.add_url_params($element_url, array('stc_unsubscribe'=>'1')).'">{\'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>';
+
+
+  ## subscribe while add a comment ##
+  $search[0] = '<input type="submit" value="{\'Submit\'|@translate}">';
+  $replace[0] = null;
+  
+  if (!isset($no_form))
+  {
+    $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];
+
+  return str_replace($search, $replace, $template);
+}
+
+
+/**
+ * add link to management page for registered users
+ */
+function stc_menubar_apply($menu_ref_arr)
+{
+  global $template;
+  $menu = &$menu_ref_arr[0];
+  
+  if ( !is_a_guest() and ($block = $menu->get_block('mbIdentification')) != null )
+  {
+    $template->set_prefilter('menubar', 'stc_menubar_apply_prefilter'); 
+  }
+}
+
+function stc_menubar_apply_prefilter($content, &$smarty)
+{
+  global $user;
+  
+  $search = '{if isset($U_REGISTER)}';
+  $replace = '<li><a href="'.make_stc_url('manage', $user['email']).'" title="{\'Manage my subscriptions\'|@translate}" rel="nofollow">{\'Manage my subscriptions\'|@translate}</a></li>';
+  return str_replace($search, $replace.$search, $content);
+}
+?>
Index: /extensions/Subscribe_to_comments/include/subscribtions_page.inc.php
===================================================================
--- /extensions/Subscribe_to_comments/include/subscribtions_page.inc.php	(revision 12599)
+++ /extensions/Subscribe_to_comments/include/subscribtions_page.inc.php	(revision 12600)
@@ -7,51 +7,119 @@
 
 // check input parameters
+$_GET['verif_key'] = $_GET['action'].$_GET['email'].(isset($_GET['id'])?$_GET['id']:null);
 if ( 
   empty($_GET['action']) or empty($_GET['email']) or empty($_GET['key'])
-  or decrypt_value($_GET['key'], $conf['secret_key']) !== $_GET['action'].$_GET['email']  
+  or decrypt_value($_GET['key'], $conf['secret_key']) !== $_GET['verif_key']
   )
 {
-  set_status_header(403);
-  array_push($errors, l10n('Bad query'));
+  $_GET['action'] = 'hacker';
+}
+else
+{
+  // sanitize inputs
+  if (isset($_GET['id'])) $_GET['id'] = pwg_db_real_escape_string($_GET['id']);
+  $_GET['email'] = pwg_db_real_escape_string($_GET['email']);
+
+  // unsubscribe
+  if (isset($_POST['unsubscribe']))
+  {
+    if (un_subscribe_to_comments(!empty($_GET['id'])?$_GET['id']:'N/A', $_GET['email'], $_POST['unsubscribe']))
+    {
+      array_push($infos, l10n('Successfully unsubscribed your email address from receiving notifications.'));
+    }
+    else
+    {
+      array_push($errors, l10n('Invalid email adress.'));
+    }
+    
+    $_GET['action'] = 'manage';
+  }
+  if (isset($_GET['unsubscribe']))
+  {
+    $query = '
+  DELETE FROM '.SUBSCRIBE_TO_TABLE.'
+    WHERE 
+      id = '.pwg_db_real_escape_string($_GET['unsubscribe']).'
+      AND email = "'.$_GET['email'].'"
+  ;';
+    pwg_query($query);
+    
+    if (pwg_db_changes(null) != 0)
+    {
+      array_push($infos, l10n('Successfully unsubscribed your email address from receiving notifications.'));
+    }
+    else
+    {
+      array_push($errors, l10n('Invalid email adress.'));
+    }
+  }
+  
+  $template->assign('MANAGE_LINK', make_stc_url('manage', $_GET['email']));
 }
 
 switch ($_GET['action'])
 {
-  /* unsubscribe */
-  case 'unsubscribe-image' :
-    if (empty($where_clause)) $where_clause = 'image_id = '.pwg_db_real_escape_string($_GET['param']);
-  case 'unsubscribe-category':
-    if (empty($where_clause)) $where_clause = 'category_id = '.pwg_db_real_escape_string($_GET['param']);
-  case 'unsubcribe-all' :
+  /* validate */
+  case 'validate-image' :
   {
-    $query = '
-DELETE FROM '.SUBSCRIBE_TO_TABLE.'
-  WHERE 
-    email = "'.pwg_db_real_escape_string($_GET['email']).'"
-    '.(!empty($where_clause) ? 'AND '.$where_clause : null).'
-;';
-    pwg_query($query);
+    if (validate_subscriptions($_GET['id'], $_GET['email'], 'image'))
+    {
+      array_push($infos, l10n('Your subscribtion has been validated, thanks you.'));
+    }
+    else
+    {
+      array_push($errors, l10n('Nothing to validate.'));
+    }
     
-    array_push($infos, l10n('You have been successfully unsubscribed, good bye.'));
+    $element = get_picture_infos($_GET['id']);
+    
+    $template->assign(array(
+      'validate' => 'image',
+      'element' => $element,
+      ));
+      
+    break;
+  }
+  case 'validate-category':
+  {
+    if (validate_subscriptions($_GET['id'], $_GET['email'], 'category'))
+    {
+      array_push($infos, l10n('Your subscribtion has been validated, thanks you.'));
+    }
+    else
+    {
+      array_push($errors, l10n('Nothing to validate.'));
+    }
+    
+    $element = get_category_infos($_GET['id']);
+    
+    $template->assign(array(
+      'validate' => 'category',
+      'element' => $element,
+      ));
     break;
   }
   
-  /* validate */
-  case 'validate-image' :
-    if (empty($where_clause)) $where_clause = 'image_id = '.pwg_db_real_escape_string($_GET['param']);
-  case 'validate-category':
-    if (empty($where_clause)) $where_clause = 'category_id = '.pwg_db_real_escape_string($_GET['param']);
-  case 'validate-all' :
-  {
-     $query = '
-UPDATE '.SUBSCRIBE_TO_TABLE.'
-  SET validated = "true"
-  WHERE 
-    email = "'.pwg_db_real_escape_string($_GET['email']).'"
-    '.(!empty($where_clause) ? 'AND '.$where_clause : null).'
-;';
-    pwg_query($query);
+  /* unsubscribe */
+  case 'unsubscribe-image' :
+  {  
+    $element = get_picture_infos($_GET['id']);
     
-    array_push($infos, l10n('Your subscribtion has been validated, thanks you.'));
+    $template->assign(array(
+      'unsubscribe_form' => 'image',
+      'element' => $element,
+      ));
+    
+    break;
+  }
+  case 'unsubscribe-category':
+  {  
+    $element = get_category_infos($_GET['id']);
+    
+    $template->assign(array(
+      'unsubscribe_form' => 'category',
+      'element' => $element,
+      ));
+    
     break;
   }
@@ -60,8 +128,40 @@
   case 'manage' :
   {
+    $query = '
+SELECT *
+  FROM '.SUBSCRIBE_TO_TABLE.'
+  WHERE 
+    email = "'.$_GET['email'].'"
+    AND validated = "true"
+  ORDER BY registration_date DESC
+;';
+    $result = pwg_query($query);
+    
+    if (pwg_db_num_rows($result) !== 0)
+    {
+      while ($subscription = pwg_db_fetch_assoc($result))
+      {
+        if (!empty($subscription['image_id']))
+        {
+          $subscription['infos'] = get_picture_infos($subscription['image_id']);
+          $subscription['type'] = 'image';
+        }
+        else if (!empty($subscription['category_id']))
+        {
+          $subscription['infos'] = get_category_infos($subscription['category_id']);
+          $subscription['type'] = 'category';
+        }
+        $subscription['registration_date'] = format_date($subscription['registration_date'], true);
+        $template->append('subscriptions', $subscription);
+      }
+    }
+    else
+    {
+      $template->assign('subscriptions', 'none');
+    }
     break;
   }
   
-  default :
+  case 'hacker' :
   {
     set_status_header(403);
@@ -69,4 +169,9 @@
   }
 }
+
+$template->assign(array(
+  'EMAIL' => $_GET['email'],
+  'SUBSCRIBE_TO_PATH' => SUBSCRIBE_TO_PATH,
+  ));
 
 $template->assign(array(
Index: /extensions/Subscribe_to_comments/language/en_UK/description.txt
===================================================================
--- /extensions/Subscribe_to_comments/language/en_UK/description.txt	(revision 12599)
+++ /extensions/Subscribe_to_comments/language/en_UK/description.txt	(revision 12600)
@@ -1,1 +1,1 @@
-This plugin allows you to subscribe to comments by mail.
+This plugin allows you to subscribe to comments by email.
Index: /extensions/Subscribe_to_comments/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/Subscribe_to_comments/language/en_UK/plugin.lang.php	(revision 12599)
+++ /extensions/Subscribe_to_comments/language/en_UK/plugin.lang.php	(revision 12600)
@@ -1,14 +1,24 @@
 <?php
 
-$lang['Subscribe to new comments'] = 'Subscribe to new comments';
+$lang['Please check your email inbox to confirm your subscription.'] = 'Please check your email inbox to confirm your subscription.';
+$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 have been added to the list of subscribers for this picture.'] = 'You have been added to the list of subscribers for this picture.';
 $lang['Invalid email adress, your are not subscribed to comments.'] = 'Invalid email adress, your are not subscribed to comments.';
-$lang['Please check your email inbox to confirm your subscription.'] = 'Please check your email inbox to confirm your subscription.';
-$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['Successfully unsubscribed your email address from receiving notifications.'] = 'Successfully unsubscribed your email address from receiving notifications.';
 $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';
+$lang['Subscribe to new comments'] = 'Subscribe to new comments';
+$lang['Invalid email adress.'] = 'Invalid email adress.';
+$lang['Your subscribtion has been validated, thanks you.'] = 'Your subscribtion has been validated, thanks you.';
+$lang['Nothing to validate.'] = 'Nothing to validate.';
+$lang['Subscriptions of'] = 'Subscriptions of';
+$lang['Unsubscribe from email notification'] = 'Unsubscribe from email notification';
+$lang['Only unsubscribe notifications for comments from:'] = 'Only unsubscribe notifications for comments from:';
+$lang['Unsubscribe from all email notifications'] = 'Unsubscribe from all email notifications';
+$lang['Manage my subscriptions'] = 'Manage my subscriptions';
+$lang['Item'] = 'Item';
+$lang['Date'] = 'Date';
+$lang['You are not subscribed to any comment.'] = 'You are not subscribed to any comment.';
 
 ?>
Index: /extensions/Subscribe_to_comments/language/fr_FR/description.txt
===================================================================
--- /extensions/Subscribe_to_comments/language/fr_FR/description.txt	(revision 12599)
+++ /extensions/Subscribe_to_comments/language/fr_FR/description.txt	(revision 12600)
@@ -1,1 +1,1 @@
-Ce plugin permet aux visiteurs de recevoir par mail les nouveaux commentaires sur une image.
+Ce plugin permet aux visiteurs de recevoir par email les nouveaux commentaires sur une image.
Index: /extensions/Subscribe_to_comments/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/Subscribe_to_comments/language/fr_FR/plugin.lang.php	(revision 12599)
+++ /extensions/Subscribe_to_comments/language/fr_FR/plugin.lang.php	(revision 12600)
@@ -1,14 +1,24 @@
 <?php
 
-$lang['Subscribe to new comments'] = 'S\'inscrire aux nouveaux commentaires';
-$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 é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['Please check your email inbox to confirm your subscription.'] = 'Veillez consulter votre boite mail pour confirmer votre inscription.';
+$lang['You have been added to the list of subscribers for this album.'] = 'Vous avez été ajouté à la liste des abonnés pour cet album.';
+$lang['You have been added to the list of subscribers for this picture.'] = 'Vous avez été ajouté à la liste des abonnés pour cette photo.';
+$lang['Invalid email adress, your are not subscribed to comments.'] = 'Addresse email invalide, vous n\'avez pas été inscrit.';
+$lang['Successfully unsubscribed your email address from receiving notifications.'] = 'Inscription aux commentaires annulée avec succès.';
 $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';
+$lang['Subscribe to new comments'] = 'S\'inscrire aux nouveaux commentaires';
+$lang['Invalid email adress.'] = 'Adress email invalide.';
+$lang['Your subscribtion has been validated, thanks you.'] = 'Votre inscription a été validée, merci.';
+$lang['Nothing to validate.'] = 'Rien à valider.';
+$lang['Subscriptions of'] = 'Subscriptions of';
+$lang['Unsubscribe from email notification'] = 'Se désinscrire de la notification par mail';
+$lang['Only unsubscribe notifications for comments from:'] = 'Uniquement se désinscrire de :';
+$lang['Unsubscribe from all email notifications'] = 'Ne plus recevoir aucune notification';
+$lang['Manage my subscriptions'] = 'Gérer mes abonnements';
+$lang['Item'] = 'Objet';
+$lang['Date'] = 'Date';
+$lang['You are not subscribed to any comment.'] = 'Vous n\'êtes inscrit à aucun commentaire.';
 
 ?>
Index: /extensions/Subscribe_to_comments/main.inc.php
===================================================================
--- /extensions/Subscribe_to_comments/main.inc.php	(revision 12599)
+++ /extensions/Subscribe_to_comments/main.inc.php	(revision 12600)
@@ -3,5 +3,5 @@
 Plugin Name: Subscribe To Comments
 Version: auto
-Description: This plugin allows you to subscribe to comments by mail.
+Description: This plugin allows you to subscribe to comments by email.
 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=587
 Author: Mistic
@@ -17,6 +17,6 @@
 define('SUBSCRIBE_TO_TABLE', $prefixeTable . 'subscribe_to_comments');
 
-include_once(SUBSCRIBE_TO_PATH.'subscribe_to_comments.inc.php');
 include_once(SUBSCRIBE_TO_PATH.'include/functions.inc.php');
+include_once(SUBSCRIBE_TO_PATH.'include/subscribe_to_comments.inc.php');
 
 load_language('plugin.lang', SUBSCRIBE_TO_PATH);
@@ -34,3 +34,6 @@
 add_event_handler('loc_end_index', 'stc_load_section');
 
+// menu link
+add_event_handler('blockmanager_apply', 'stc_menubar_apply');
+
 ?>
Index: /extensions/Subscribe_to_comments/maintain.inc.php
===================================================================
--- /extensions/Subscribe_to_comments/maintain.inc.php	(revision 12599)
+++ /extensions/Subscribe_to_comments/maintain.inc.php	(revision 12600)
@@ -9,10 +9,11 @@
 	pwg_query('
 CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'subscribe_to_comments` (
-  `email` varchar(255) NOT NULL,
-  `image_id` mediumint(8) NOT NULL DEFAULT 0,
-  `category_id` smallint(5) NOT NULL DEFAULT 0,
-  `registration_date` datetime NOT NULL,
-  `validated` enum("true", "false") NOT NULL DEFAULT "false",
-  UNIQUE KEY `UNIQUE` (`mail`, `image_id`, `category_id`)
+  `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
+  `email` VARCHAR( 255 ) NOT NULL ,
+  `image_id` MEDIUMINT( 8 ) UNSIGNED NOT NULL DEFAULT "0",
+  `category_id` SMALLINT( 5 ) UNSIGNED NOT NULL DEFAULT "0",
+  `registration_date` DATETIME NOT NULL,
+  `validated` ENUM( "true", "false" ) NOT NULL DEFAULT "false",
+  UNIQUE KEY `UNIQUE` (`email`, `image_id`, `category_id`)
 ) DEFAULT CHARSET=utf8
 ;');
@@ -35,6 +36,6 @@
   
   /* delete table and config */
-  // pwg_query('DROP TABLE `' . $prefixeTable . 'subscribe_to_comments`;');
-  pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param = "Subscribe_to_Comments";');
+  pwg_query('DROP TABLE `' . $prefixeTable . 'subscribe_to_comments`;');
+  // pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param = "Subscribe_to_Comments";');
 }
 ?>
Index: tensions/Subscribe_to_comments/subscribe_to_comments.inc.php
===================================================================
--- /extensions/Subscribe_to_comments/subscribe_to_comments.inc.php	(revision 12599)
+++ 	(revision )
@@ -1,319 +1,0 @@
-<?php
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
-
-/**
- * detect 'subscriptions' section and load page
- */
-function stc_detect_section() {
-  global $tokens, $page;
-  
-  if ($tokens[0] == 'subscriptions')
-  {
-    $page['section'] = 'subscriptions';
-  }
-}
-
-function stc_load_section() {
-  global $page;
-
-  if (isset($page['section']) and $page['section'] == 'subscriptions')
-  {
-    include(SUBSCRIBE_TO_PATH.'include/subscribtions_page.inc.php');
-  }
-}
-
-
-/**
- * send notifications and/or add subscriber
- */
-function stc_comment_insertion($comm)
-{
-  global $page;
-  
-  if ($comm['action'] == 'validate')
-  {
-    send_comment_to_subscribers($comm);
-  }
-  
-  if ( !empty($_POST['stc_check']) and ( $comm['action'] == 'validate' or $comm['action'] == 'moderate' ) )
-  {
-    if (isset($comm['image_id']))
-    {
-      subscribe_to_comments($comm['image_id'], @$_POST['stc_mail'], 'image');
-    }
-    else if (isset($comm['category_id']))
-    {
-      subscribe_to_comments($comm['category_id'], @$_POST['stc_mail'], 'category');
-    }
-  }
-}
-
-function stc_comment_validation($comm_id, $type='image')
-{ 
-  switch ($type)
-  {
-    case 'image':
-    {
-      $query = '
-SELECT
-    id,
-    image_id,
-    author,
-    content
-  FROM '.COMMENTS_TABLE.'
-  WHERE id = '.$comm_id.'
-;';
-      break;
-    }
-    
-    case 'category':
-    {
-      $query = '
-SELECT
-    id,
-    category_id,
-    author,
-    content
-  FROM '.COA_TABLE.'
-  WHERE id = '.$comm_id.'
-;';
-      break;
-    }
-  }
-  
-  $comm = pwg_db_fetch_assoc(pwg_query($query));
-  send_comment_to_subscribers($comm);
-}
-
-
-/**
- * add field and link on picture page
- */
-function stc_on_picture()
-{
-  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');
-}
-
-function stc_on_picture_prefilter($template, &$smarty)
-{
-  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}
-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 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);
-}
-
-?>
Index: /extensions/Subscribe_to_comments/template/style.css
===================================================================
--- /extensions/Subscribe_to_comments/template/style.css	(revision 12600)
+++ /extensions/Subscribe_to_comments/template/style.css	(revision 12600)
@@ -0,0 +1,31 @@
+.subscriptions_list {
+  width:600px;
+	border: 1px solid #111;
+	margin: 1em auto;
+	padding: 0;
+  background-color:#222;
+  border-collapse:collapse;
+}
+
+.subscriptions_list TD {
+	padding: 0 5px;
+}
+
+.subscriptions_list TR {
+	text-align: left;
+}
+
+.subscriptions_list TH { 
+  padding:7px 5px;
+}
+
+.row2 { background-color: #222; }
+.throw, .row1 { background-color:#111;  }
+
+p {
+  text-align:center;
+}
+
+label {
+  display:block;
+}
Index: /extensions/Subscribe_to_comments/template/subscribtions_page.tpl
===================================================================
--- /extensions/Subscribe_to_comments/template/subscribtions_page.tpl	(revision 12599)
+++ /extensions/Subscribe_to_comments/template/subscribtions_page.tpl	(revision 12600)
@@ -1,2 +1,4 @@
+{combine_css path=$SUBSCRIBE_TO_PATH|@cat:'template/style.css'}
+
 {$MENUBAR}
 
@@ -6,12 +8,7 @@
   <div class="titrePage">
     <ul class="categoryActions">
-      {if isset($U_EDIT)}
-      <li><a href="{$U_EDIT}" title="{'edit'|@translate}" class="pwg-state-default pwg-button">
-        <span class="pwg-icon pwg-icon-category-edit"> </span><span class="pwg-button-text">{'edit'|@translate}</span>
-      </a></li>
-      {/if}
       {if !empty($PLUGIN_INDEX_ACTIONS)}{$PLUGIN_INDEX_ACTIONS}{/if}
     </ul>
-    <h2>Subscriptions</h2>
+    <h2>{'Subscriptions of'|@translate} <i>{$EMAIL}</i></h2>
   </div> <!-- titrePage -->
   
@@ -34,4 +31,64 @@
   </div>
   {/if}
+  
+  {if !empty($unsubscribe_form)}
+  <form action="" method="post">
+  <fieldset>
+    <legend>{'Unsubscribe from email notification'|@translate}</legend>
+    
+    <p>
+      <label><input type="radio" name="unsubscribe" value="{$unsubscribe_form}" checked="checked"> {'Only unsubscribe notifications for comments from:'|@translate} <a href="{$element.url}" target="_blank">{$element.name}</a></label>
+      <label><input type="radio" name="unsubscribe" value="all"> {'Unsubscribe from all email notifications'|@translate}</label>
+      <br>
+      <label><input type="submit" value="Unsubscribe notifications for {$EMAIL}"></label>
+      <a href="{$MANAGE_LINK}">{'Manage my subscriptions'|@translate}</a>
+    </p>
+  </fieldset>
+  </form>
+  {/if}
+  
+  {if !empty($validate)}
+  <p>
+    {if empty($errors)}<a href="{$element.url}">{'Return to item page'|@translate}</a><br>{/if}
+    <a href="{$MANAGE_LINK}">{'Manage my subscriptions'|@translate}</a>
+  </p>
+  {/if}
+  
+  {if !empty($subscriptions) and $subscriptions != 'none'}
+  <form action="{$MANAGE_LINK}" method="post">
+  <fieldset>
+    <legend>{'Manage my subscriptions'|@translate}</legend>
+    <table class="subscriptions_list">
+      <tr class="throw">
+        <th>{'Item'|@translate}</th>
+        <th>{'Date'|@translate}</th>
+        <th>{'Unsubscribe'|@translate}</th>
+      </tr>
+      {foreach from=$subscriptions item=sub name=subs_loop}
+      <tr class="{if $smarty.foreach.subs_loop.index is odd}row1{else}row2{/if}">
+        <td>
+          {if $sub.type == 'image'}
+          <img src="{$SUBSCRIBE_TO_PATH}template/picture.png" alt="(P)">
+          {else}
+          <img src="{$SUBSCRIBE_TO_PATH}template/folder_picture.png" alt="(A)">
+          {/if} 
+          <a href="{$sub.infos.url}">{$sub.infos.name}</a>
+        </td>
+        <td>{$sub.registration_date}</td>
+        <td><a href="{$MANAGE_LINK}&amp;unsubscribe={$sub.id}">{'Unsubscribe'|@translate}</a></td>
+      </tr>
+      {/foreach}
+    </table>
+    
+    <p>
+      <input type="hidden" name="unsubscribe" value="all">
+      <input type="submit" value="{'Unsubscribe from all email notifications'|@translate}">
+    </p>
+  </fieldset>
+  {elseif !empty($subscriptions) and $subscriptions == 'none'}
+  <p>
+    {'You are not subscribed to any comment.'|@translate}
+  </p>
+  {/if}
 
 </div> <!-- content -->
