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 12560)
@@ -0,0 +1,281 @@
+<?php
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+/**
+ * Send comment to subscribers
+ * @param array comm
+ */
+function send_comment_to_subscribers($comm)
+{
+  global $conf, $page, $user;
+  
+  $type= isset($comm['category_id']) ? 'category' : 'image';
+  
+  // exclude current user
+  $exclude = null;
+  if (!empty($_POST['stc_mail'])) $exclude = pwg_db_real_escape_string($_POST['stc_mail']);
+  if (!is_a_guest()) $exclude = $user['email'];
+  
+  // get subscribers emails
+  $query = '
+SELECT 
+    email
+  FROM '.SUBSCRIBE_TO_TABLE.'
+  WHERE
+    '.$type.'_id = '.$comm[$type.'_id'].'
+    AND validated = true
+    AND email != "'.$exclude.'"
+';
+  $emails = array_from_query($query, 'email');
+  
+  set_make_full_url();
+  switch ($type)
+  {
+    case '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);
+      break;
+    }
+    
+    case 'category' :
+    {
+      // get category infos
+      $query = '
+SELECT
+    id,
+    name
+  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;
+    }
+  }
+  
+  // get author name
+  if ($comm['author'] == 'guest')
+  {
+    $comm['author'] = l10n('guest');
+  }
+  
+  // mail content
+  $mail_args = array(
+    'subject' => '['.strip_tags($conf['gallery_title']).'] Re:'.$element['name'],
+    'content_format' => 'text/html',
+    );
+    
+  $generic_content = '
+<b>.'.trigger_event('render_comment_author', $comm['author']).'</b> wrote :
+
+<blockquote>'.trigger_event('render_comment_content', $comm['content']).'</blockquote>
+
+<a href="'.$element['url'].'#comment-'.$comm['id'].'">Link to comment</a>
+<br><br>
+================================
+<br><br>';
+
+  foreach ($emails as $email)
+  {
+    $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>
+    pwg_mail($email, $mail_args);
+  }
+  
+  unset_make_full_url();
+}
+
+/*
+ * add an email to subscribers list
+ * @param int (image|category)_id
+ * @param string email
+ * @param string type (image|category)
+ */
+function subscribe_to_comments($element_id, $email, $type='image')
+{
+  global $page, $user, $conf, $template, $picture;
+  
+  $infos = $errors = array();
+  
+  if ( is_a_guest() and empty($email) )
+  {
+    array_push($errors, l10n('Invalid email adress, your are not subscribed to comments.'));
+    return;
+  }
+  else if ( !is_a_guest() )
+  {
+    $email = $user['email'];
+  }
+  
+  $query = '
+INSERT IGNORE INTO '.SUBSCRIBE_TO_TABLE.'(
+    email,
+    '.$type.'_id,
+    registration_date,
+    validated
+  )
+  VALUES(
+    "'.pwg_db_real_escape_string($email).'",
+    '.$element_id.',
+    NOW(),
+    "'.(is_a_guest() ? "false" : "true").'"
+  )
+;';
+  pwg_query($query);
+  
+  if (is_a_guest() and pwg_db_insert_id() != 0)
+  {
+    $mail_args = array(
+      'subject' => '['.strip_tags($conf['gallery_title']).'] Please confirm your subscribtion to comments',
+      'content_format' => 'text/html',
+      );
+      
+    $mail_args['content'] = '
+You requested to subscribe by email to comments on <b>'.$picture['current']['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>
+<br>
+<a href="'.make_stc_url('validate-'.$type, $email, $element_id).'">Confirm subscription</a><br>
+<br>
+If you did not request this action please disregard this message.
+';
+
+    pwg_mail($email, $mail_args);
+    array_push($infos, l10n('Please check your email inbox to confirm your subscription.'));
+  }
+  
+  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));
+  }
+}
+
+/**
+ * create absolute url to subscriptions section
+ * @param string action
+ * @param string email
+ * @return string
+ */
+function make_stc_url($action, $email)
+{
+  if ( empty($action) or empty($email) ) return null;
+  
+  global $conf;
+  set_make_full_url();
+  
+  $url_params = array(
+    '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 = add_url_params(
+    make_index_url( array('section' => 'subscriptions') ),
+    $url_params
+    );
+    
+  unset_make_full_url();
+  return $url;
+}
+
+/**
+ * crypt a string using mcrypt extension or a binary method
+ * @param string value to crypt
+ * @param string key
+ * @return string
+ */
+function crypt_value($value, $key)
+{  
+  if (extension_loaded('mcrypt'))
+  {
+    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
+    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
+    $value = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_ECB, $iv);
+  }
+  else
+  {
+    $value = $value ^ $key; // binary XOR operation
+  }
+  
+  $value = base64url_encode($value);
+  return trim($value); 
+}
+
+/**
+ * decrypt a string crypted with previous function
+ * @param string value to decrypt
+ * @param string key
+ * @return string
+ */
+function decrypt_value($value, $key)
+{
+  $value = base64url_decode($value); 
+  
+  if (extension_loaded('mcrypt'))
+  {
+    $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
+    $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
+    $value = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_ECB, $iv);
+  }
+  else
+  {
+    $value = $value ^ $key; // binary XOR operation
+  }
+  
+  return trim($value);
+}
+
+/**
+ * variant of base64 functions usable into url
+ * http://fr.php.net/manual/fr/function.base64-encode.php#103849
+ */
+function base64url_encode($data)
+{
+  return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
+}
+function base64url_decode($data)
+{
+  return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
+} 
+
+?>
Index: /extensions/Subscribe_to_comments/include/index.php
===================================================================
--- /extensions/Subscribe_to_comments/include/index.php	(revision 12560)
+++ /extensions/Subscribe_to_comments/include/index.php	(revision 12560)
@@ -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/Subscribe_to_comments/include/subscribtions_page.inc.php
===================================================================
--- /extensions/Subscribe_to_comments/include/subscribtions_page.inc.php	(revision 12560)
+++ /extensions/Subscribe_to_comments/include/subscribtions_page.inc.php	(revision 12560)
@@ -0,0 +1,78 @@
+<?php 
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+global $template, $conf;
+
+$infos = $errors = array();
+
+// check input parameters
+if ( 
+  empty($_GET['action']) or empty($_GET['email']) or empty($_GET['key'])
+  or decrypt_value($_GET['key'], $conf['secret_key']) !== $_GET['action'].$_GET['email']  
+  )
+{
+  set_status_header(403);
+  array_push($errors, l10n('Bad query'));
+}
+
+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' :
+  {
+    $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);
+    
+    array_push($infos, l10n('You have been successfully unsubscribed, good bye.'));
+    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);
+    
+    array_push($infos, l10n('Your subscribtion has been validated, thanks you.'));
+    break;
+  }
+  
+  /* manage */
+  case 'manage' :
+  {
+    break;
+  }
+  
+  default :
+  {
+    set_status_header(403);
+    array_push($errors, l10n('Bad query'));
+  }
+}
+
+$template->assign(array(
+  'infos' => $infos,
+  'errors' => $errors,
+  ));
+
+$template->set_filenames(array('index'=> dirname(__FILE__).'/../template/subscribtions_page.tpl'));
+?>
Index: /extensions/Subscribe_to_comments/index.php
===================================================================
--- /extensions/Subscribe_to_comments/index.php	(revision 12560)
+++ /extensions/Subscribe_to_comments/index.php	(revision 12560)
@@ -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/Subscribe_to_comments/language/en_UK/description.txt
===================================================================
--- /extensions/Subscribe_to_comments/language/en_UK/description.txt	(revision 12560)
+++ /extensions/Subscribe_to_comments/language/en_UK/description.txt	(revision 12560)
@@ -0,0 +1,1 @@
+This plugin allows you to subscribe to comments by mail.
Index: /extensions/Subscribe_to_comments/language/en_UK/index.php
===================================================================
--- /extensions/Subscribe_to_comments/language/en_UK/index.php	(revision 12560)
+++ /extensions/Subscribe_to_comments/language/en_UK/index.php	(revision 12560)
@@ -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/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 12560)
@@ -0,0 +1,9 @@
+<?php
+
+$lang['Subscribe to new comments'] = 'Subscribe to new comments';
+$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.';
+
+?>
Index: /extensions/Subscribe_to_comments/language/fr_FR/description.txt
===================================================================
--- /extensions/Subscribe_to_comments/language/fr_FR/description.txt	(revision 12560)
+++ /extensions/Subscribe_to_comments/language/fr_FR/description.txt	(revision 12560)
@@ -0,0 +1,1 @@
+Ce plugin permet aux visiteurs de recevoir par mail les nouveaux commentaires sur une image.
Index: /extensions/Subscribe_to_comments/language/fr_FR/index.php
===================================================================
--- /extensions/Subscribe_to_comments/language/fr_FR/index.php	(revision 12560)
+++ /extensions/Subscribe_to_comments/language/fr_FR/index.php	(revision 12560)
@@ -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/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 12560)
@@ -0,0 +1,9 @@
+<?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 supprimé de la liste de notification, au revoir.';
+$lang['Your subscribtion has been validated, thanks you.'] = 'Votre inscription a bien été validée, merci..';
+
+?>
Index: /extensions/Subscribe_to_comments/language/index.php
===================================================================
--- /extensions/Subscribe_to_comments/language/index.php	(revision 12560)
+++ /extensions/Subscribe_to_comments/language/index.php	(revision 12560)
@@ -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/Subscribe_to_comments/main.inc.php
===================================================================
--- /extensions/Subscribe_to_comments/main.inc.php	(revision 12560)
+++ /extensions/Subscribe_to_comments/main.inc.php	(revision 12560)
@@ -0,0 +1,28 @@
+<?php 
+/*
+Plugin Name: Subscribe To Comments
+Version: auto
+Description: This plugin allows you to subscribe to comments by mail.
+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 $prefixeTable;
+
+define('SUBSCRIBE_TO_DIR' , basename(dirname(__FILE__)));
+define('SUBSCRIBE_TO_PATH' , PHPWG_PLUGINS_PATH . SUBSCRIBE_TO_DIR . '/');
+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');
+
+add_event_handler('user_comment_insertion', 'stc_comment_insertion');
+add_event_handler('user_comment_validation', 'stc_comment_validation', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
+add_event_handler('loc_end_picture', 'stc_on_picture');
+add_event_handler('loc_end_section_init', 'stc_detect_section');
+add_event_handler('loc_end_index', 'stc_load_section');   
+
+?>
Index: /extensions/Subscribe_to_comments/maintain.inc.php
===================================================================
--- /extensions/Subscribe_to_comments/maintain.inc.php	(revision 12560)
+++ /extensions/Subscribe_to_comments/maintain.inc.php	(revision 12560)
@@ -0,0 +1,40 @@
+<?php
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+function plugin_install() 
+{
+	global $prefixeTable;
+
+  /* create table to store subscribtions */
+	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`)
+) DEFAULT CHARSET=utf8
+;');
+      
+  /* config parameter */
+  // pwg_query('
+// INSERT INTO `' . CONFIG_TABLE . '`
+  // VALUES (
+    // "Subscribe_to_Comments", 
+    // "'.serialize(array()).'",
+    // "Configuration for Subscribe_to_Comments plugin"
+  // )
+// ;');
+
+}
+
+function plugin_uninstall() 
+{
+	global $prefixeTable;
+  
+  /* delete table and config */
+  // pwg_query('DROP TABLE `' . $prefixeTable . 'subscribe_to_comments`;');
+  pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param = "Subscribe_to_Comments";');
+}
+?>
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 12560)
@@ -0,0 +1,120 @@
+<?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);
+}
+
+
+/**
+ * adds fields on picture page
+ */
+function stc_on_picture()
+{
+  global $template;
+  
+  $template->set_prefilter('picture', 'stc_on_picture_prefilter');
+}
+
+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>
+<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}
+'.$search;
+
+  return str_replace($search, $replace, $template);
+}
+
+?>
Index: /extensions/Subscribe_to_comments/template/index.php
===================================================================
--- /extensions/Subscribe_to_comments/template/index.php	(revision 12560)
+++ /extensions/Subscribe_to_comments/template/index.php	(revision 12560)
@@ -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/Subscribe_to_comments/template/subscribtions_page.tpl
===================================================================
--- /extensions/Subscribe_to_comments/template/subscribtions_page.tpl	(revision 12560)
+++ /extensions/Subscribe_to_comments/template/subscribtions_page.tpl	(revision 12560)
@@ -0,0 +1,39 @@
+{$MENUBAR}
+
+{if !empty($PLUGIN_INDEX_CONTENT_BEFORE)}{$PLUGIN_INDEX_CONTENT_BEFORE}{/if}
+
+<div id="content" class="content">
+  <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>
+  </div> <!-- titrePage -->
+  
+  {if !empty($errors)}
+  <div class="errors">
+    <ul>
+      {foreach from=$errors item=error}
+      <li>{$error}</li>
+      {/foreach}
+    </ul>
+  </div>
+  {/if}
+  {if !empty($infos)}
+  <div class="infos">
+    <ul>
+      {foreach from=$infos item=info}
+      <li>{$info}</li>
+      {/foreach}
+    </ul>
+  </div>
+  {/if}
+
+</div> <!-- content -->
+
+{if !empty($PLUGIN_INDEX_CONTENT_AFTER)}{$PLUGIN_INDEX_CONTENT_AFTER}{/if}
