Ignore:
Timestamp:
Nov 11, 2011, 2:56:45 PM (12 years ago)
Author:
mistic100
Message:

fix many bugs, and management page

Location:
extensions/Subscribe_to_comments/include
Files:
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • extensions/Subscribe_to_comments/include/functions.inc.php

    r12561 r12600  
    99{
    1010  global $conf, $page, $user;
     11 
     12  if ( empty($comm) or !is_array($comm) )
     13  {
     14    trigger_error('send_comment_to_subscribers: undefinided comm', E_USER_WARNING);
     15    return false;
     16  }
    1117 
    1218  $type= isset($comm['category_id']) ? 'category' : 'image';
     
    3238  if ($type == 'image')
    3339  {
    34     // get image infos
    35     $query = '
    36 SELECT
    37     id,
    38     name,
    39     file
    40   FROM '.IMAGES_TABLE.'
    41   WHERE id = '.$comm['image_id'].'
    42 ;';
    43     $element = pwg_db_fetch_assoc(pwg_query($query));
    44      
    45     if (empty($element['name']))
    46     {
    47       $element['name'] = get_name_from_file($element['file']);
    48     }
    49    
    50     $url_params = array('image_id' => $element['id']);
    51     if (!empty($page['category']))
    52     {
    53       $url_params['section'] = 'categories';
    54       $url_params['category'] = $page['category'];
    55     }
    56 
    57     $element['url'] = make_picture_url($url_params);
     40    $element = get_picture_infos($comm['image_id']);
    5841  }
    5942  else if ($type == 'category')
    6043  {
    61     // get category infos
    62     $query = '
    63 SELECT
    64     id,
    65     name,
    66     permalink
    67   FROM '.CATEGORIES_TABLE.'
    68   WHERE id = '.$comm['category_id'].'
    69 ;';
    70     $element = pwg_db_fetch_assoc(pwg_query($query));
    71    
    72     $url_params['section'] = 'categories';
    73     $url_params['category'] = $element;
    74    
    75     $element['url'] = make_index_url($url_params);
     44    $element = get_category_infos($comm['category_id']);
    7645  }
    7746 
     
    10170  {
    10271    $mail_args['content'] = $generic_content.'
    103 <a href="'.make_stc_url('unsubscribe-'.$type, $email, $element['id']).'">Stop receiving notifications for this picture</a><br>
    104 <a href="'.make_stc_url('unsubscribe-all', $email).'">Stop receiving all notifications</a><br>
    105 ';
    106 //<a href="'.make_stc_url('manage', $email).'">Manage my subscribtions</a>
     72<a href="'.make_stc_url('unsubscribe-'.$type, $email, $element['id']).'">Stop receiving notifications</a><br>
     73<a href="'.make_stc_url('manage', $email).'">Manage my subscribtions</a>';
    10774    pwg_mail($email, $mail_args);
    10875  }
     
    12087function subscribe_to_comments($element_id, $email, $type='image')
    12188{
    122   global $page, $user, $conf, $template, $picture;
    123  
    124   $infos = $errors = array();
     89  global $page, $conf, $user, $template, $picture;
     90 
     91  if ( empty($element_id) or empty($type) )
     92  {
     93    trigger_error('subscribe_to_comment: missing element_id and/or type', E_USER_WARNING);
     94    return false;
     95  }
     96 
     97  // check email
    12598  if ( is_a_guest() and empty($email) )
    12699  {
    127     array_push($errors, l10n('Invalid email adress, your are not subscribed to comments.'));
    128    
    129     $orig = $template->get_template_vars('errors');
    130     if (empty($orig)) $orig = array();
    131     $template->assign('errors', array_merge($orig, $errors));
    132    
    133     if ($type == 'category') $template->set_prefilter('index', 'coa_messages'); // here we use a prefilter existing in COA
    134    
    135     return;
     100    return false;
    136101  }
    137102  else if (!is_a_guest())
     
    142107  // don't care if already registered
    143108  $query = '
    144 INSERT IGNORE INTO '.SUBSCRIBE_TO_TABLE.'(
     109INSERT INTO '.SUBSCRIBE_TO_TABLE.'(
    145110    email,
    146111    '.$type.'_id,
     
    154119    "'.(is_a_guest() ? "false" : "true").'"
    155120  )
     121  ON DUPLICATE KEY UPDATE
     122    registration_date = IF(validated="true", registration_date, NOW()),
     123    validated = IF(validated="true", validated, "'.(is_a_guest() ? "false" : "true").'")
    156124;';
    157125  pwg_query($query);
    158126 
    159127  // send validation mail
    160   if (is_a_guest() and pwg_db_insert_id() != 0)
     128  if ( is_a_guest() and pwg_db_changes(null) != 0 )
    161129  {
    162130    $element_name = ($type == 'image') ? $picture['current']['name'] : $page['category']['name'];
     
    178146
    179147    pwg_mail($email, $mail_args);
    180     array_push($infos, l10n('Please check your email inbox to confirm your subscription.'));
    181   }
    182   // just displat confirmation message
    183   else if (pwg_db_insert_id() != 0)
    184   {
    185     array_push($infos, l10n('You have been added to the list of subscribers for this '.($type=='image' ? 'picture' : 'album').'.'));
    186   }
    187  
    188  
    189   if (!empty($infos))
    190   {
    191     $orig = $template->get_template_vars('infos');
    192     if (empty($orig)) $orig = array();
    193     $template->assign('infos', array_merge($orig, $infos));
    194    
    195     if ($type == 'category') $template->set_prefilter('index', 'coa_messages');
    196   }
    197 }
    198 
     148    return 'confirm_mail';
     149  }
     150  // just display confirmation message
     151  else if (pwg_db_changes(null) != 0)
     152  {
     153    return true;
     154  }
     155}
     156
     157/*
     158 * remove an email from subscribers list
     159 * @param int (image|category)_id
     160 * @param string email
     161 * @param string type (image|category)
     162 */
     163function un_subscribe_to_comments($element_id, $email, $type='image')
     164{
     165  global $template, $user;
     166 
     167  if ( empty($element_id) or empty($type) )
     168  {
     169    trigger_error('un_subscribe_to_comment: missing element_id and/or type', E_USER_WARNING);
     170    return false;
     171  }
     172 
     173  // check email
     174  if ( is_a_guest() and empty($email) )
     175  {
     176    return false;
     177  }
     178  else if (!is_a_guest())
     179  {
     180    $email = $user['email'];
     181  }
     182 
     183  // delete subscription
     184  switch ($type)
     185  {
     186    case 'image' :
     187    case 'category' :
     188      $where_clause = $type.'_id = '.pwg_db_real_escape_string($element_id);
     189    case 'all' :
     190    {
     191      $query = '
     192DELETE FROM '.SUBSCRIBE_TO_TABLE.'
     193  WHERE
     194    email = "'.pwg_db_real_escape_string($email).'"
     195    '.(!empty($where_clause) ? 'AND '.$where_clause : null).'
     196;';
     197      pwg_query($query);
     198     
     199      return true;
     200      break;
     201    }
     202  }
     203 
     204  return false;
     205}
     206
     207/*
     208 * validate a subscription
     209 * @param int (image|category)_id
     210 * @param string email
     211 * @param string type (image|category)
     212 */
     213function validate_subscriptions($element_id, $email, $type='image')
     214{
     215  if ( empty($element_id) or empty($email) or empty($type) )
     216  {
     217    trigger_error('validate_subscriptions: missing element_id and/or email and/or type', E_USER_WARNING);
     218    return false;
     219  }
     220 
     221  switch ($type)
     222  {
     223    case 'image' :
     224    case 'category':
     225      $where_clause = $type.'_id = '.pwg_db_real_escape_string($element_id);
     226    case 'all' :
     227    {
     228       $query = '
     229UPDATE '.SUBSCRIBE_TO_TABLE.'
     230  SET validated = "true"
     231  WHERE
     232    email = "'.pwg_db_real_escape_string($email).'"
     233    '.(!empty($where_clause) ? 'AND '.$where_clause : null).'
     234;';
     235      pwg_query($query);
     236     
     237      if (pwg_db_changes(null) != 0) return true;
     238      break;
     239    }
     240  }
     241 
     242  return false;
     243}
    199244
    200245/**
     
    208253  if ( empty($action) or empty($email) )
    209254  {
    210     trigger_error('make_stc_url missing action and/or mail', E_USER_WARNING);
     255    trigger_error('make_stc_url: missing action and/or mail', E_USER_WARNING);
    211256    return null;
    212257  }
     
    218263    'action' => $action,
    219264    'email' => $email,
    220     'key' => crypt_value($action.$email, $conf['secret_key']),
    221265    );
    222266 
    223267  if (func_num_args() > 2)
    224268  {
    225     $url_params['param'] = func_get_arg(2);
    226   }
     269    $url_params['id'] = func_get_arg(2);
     270  }
     271 
     272  $url_params['key'] = crypt_value(
     273    $action.$email.(isset($url_params['id'])?$url_params['id']:null),
     274    $conf['secret_key']
     275    );
    227276 
    228277  $url = add_url_params(
     
    235284}
    236285
     286/**
     287 * get name and url of a picture
     288 * @param int image_id
     289 * @return array
     290 */
     291function get_picture_infos($image_id, $absolute=false)
     292{
     293  global $page;
     294 
     295  $query = '
     296SELECT
     297    id,
     298    name,
     299    file
     300  FROM '.IMAGES_TABLE.'
     301  WHERE id = '.$image_id.'
     302;';
     303  $element = pwg_db_fetch_assoc(pwg_query($query));
     304   
     305  if (empty($element['name']))
     306  {
     307    $element['name'] = get_name_from_file($element['file']);
     308  }
     309 
     310  $url_params = array('image_id' => $element['id']);
     311  if ( !empty($page['category']) and !$absolute )
     312  {
     313    $url_params['section'] = 'categories';
     314    $url_params['category'] = $page['category'];
     315  }
     316  $element['url'] = make_picture_url($url_params);
     317 
     318  return $element;
     319}
     320
     321/**
     322 * get name and url of a category
     323 * @param int cat_id
     324 * @return array
     325 */
     326function get_category_infos($cat_id)
     327{
     328  $query = '
     329SELECT
     330    id,
     331    name,
     332    permalink
     333  FROM '.CATEGORIES_TABLE.'
     334  WHERE id = '.$cat_id.'
     335;';
     336  $element = pwg_db_fetch_assoc(pwg_query($query));
     337 
     338  $url_params['section'] = 'categories';
     339  $url_params['category'] = $element;
     340  $element['url'] = make_index_url($url_params);
     341 
     342  return $element;
     343}
    237344
    238345/**
  • extensions/Subscribe_to_comments/include/subscribe_to_comments.inc.php

    r12561 r12600  
    2929function stc_comment_insertion($comm)
    3030{
    31   global $page;
     31  global $page, $template;
     32 
     33  $infos = $errors = array();
    3234 
    3335  if ($comm['action'] == 'validate')
     
    4042    if (isset($comm['image_id']))
    4143    {
    42       subscribe_to_comments($comm['image_id'], @$_POST['stc_mail'], 'image');
     44      $return = subscribe_to_comments($comm['image_id'], @$_POST['stc_mail'], 'image');
    4345    }
    4446    else if (isset($comm['category_id']))
    4547    {
    46       subscribe_to_comments($comm['category_id'], @$_POST['stc_mail'], 'category');
    47     }
    48   }
    49 }
    50 
    51 function stc_comment_validation($comm_id, $type='image')
    52 {
    53   switch ($type)
    54   {
    55     case 'image':
     48      $return = subscribe_to_comments($comm['category_id'], @$_POST['stc_mail'], 'category');
     49     
     50    }
     51   
     52    if (isset($return))
     53    {
     54      if ($return === 'confirm_mail')
     55      {
     56        array_push($infos, l10n('Please check your email inbox to confirm your subscription.'));
     57      }
     58      else if ($return === true)
     59      {
     60        array_push($infos, l10n('You have been added to the list of subscribers for this '.(isset($comm['image_id'])?'picture':'album').'.'));
     61      }
     62      else
     63      {
     64        array_push($errors, l10n('Invalid email adress, your are not subscribed to comments.'));
     65      }
     66     
     67       // messages management
     68      if (!empty($errors))
     69      {
     70        $errors_bak = $template->get_template_vars('errors');
     71        if (empty($errors_bak)) $errors_bak = array();
     72        $template->assign('errors', array_merge($errors_bak, $errors));
     73        $template->set_prefilter('index', 'coa_messages'); // here we use a prefilter existing in COA
     74      }
     75      if (!empty($infos))
     76      {
     77        $infos_bak = $template->get_template_vars('infos');
     78        if (empty($infos_bak)) $infos_bak = array();
     79        $template->assign('infos', array_merge($infos_bak, $infos));
     80        $template->set_prefilter('index', 'coa_messages');
     81      }
     82    }
     83  }
     84}
     85
     86function stc_comment_validation($comm_ids, $type='image')
     87{
     88  if (!is_array($comm_ids)) $comm_ids = array($comm_ids);
     89 
     90  foreach($comm_ids as $comm_id)
     91  {
     92    if ($type == 'image')
    5693    {
    5794      $query = '
     
    64101  WHERE id = '.$comm_id.'
    65102;';
    66       break;
    67     }
    68    
    69     case 'category':
     103    }
     104    else if ($type == 'category')
    70105    {
    71106      $query = '
     
    78113  WHERE id = '.$comm_id.'
    79114;';
    80       break;
    81     }
    82   }
    83  
    84   $comm = pwg_db_fetch_assoc(pwg_query($query));
    85   send_comment_to_subscribers($comm);
     115    }
     116   
     117    $comm = pwg_db_fetch_assoc(pwg_query($query));
     118    send_comment_to_subscribers($comm);
     119  }
    86120}
    87121
     
    92126function stc_on_picture()
    93127{
    94   global $template, $picture;
     128  global $template, $picture, $page;
     129 
     130  $infos = $array = array();
    95131 
    96132  if (isset($_POST['stc_check_stdl']))
    97133  {
    98     subscribe_to_comments($picture['current']['id'], @$_POST['stc_mail_stdl'], 'image');
     134    $return = subscribe_to_comments($picture['current']['id'], @$_POST['stc_mail_stdl'], 'image');
     135    if ($return === 'confirm_mail')
     136    {
     137      array_push($infos, l10n('Please check your email inbox to confirm your subscription.'));
     138    }
     139    else if ($return === true)
     140    {
     141      array_push($infos, l10n('You have been added to the list of subscribers for this picture.'));
     142    }
     143    else
     144    {
     145      array_push($errors, l10n('Invalid email adress, your are not subscribed to comments.'));
     146    }
     147  }
     148  else if (isset($_GET['stc_unsubscribe']))
     149  {
     150    if (un_subscribe_to_comments($picture['current']['id'], null, 'image'))
     151    {
     152      array_push($infos, l10n('Successfully unsubscribed your email address from receiving notifications.'));
     153    }
     154  }
     155 
     156  // messages management
     157  if (!empty($errors))
     158  {
     159    $errors_bak = $template->get_template_vars('errors');
     160    if (empty($errors_bak)) $errors_bak = array();
     161    $template->assign('errors', array_merge($errors_bak, $errors));
     162  }
     163  if (!empty($infos))
     164  {
     165    $infos_bak = $template->get_template_vars('infos');
     166    if (empty($infos_bak)) $infos_bak = array();
     167    $template->assign('infos', array_merge($infos_bak, $infos));
    99168  }
    100169 
     
    104173function stc_on_picture_prefilter($template, &$smarty)
    105174{
    106   global $user, $picture;
    107  
    108   ## subscribe while add a comment ##
    109   $search[0] = '<input type="submit" value="{\'Submit\'|@translate}">';
    110  
    111   $replace[0] = '
    112 <label>{\'Subscribe to new comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label>';
    113   if (is_a_guest())
    114   {
    115     $replace[0].= '
    116 <label id="stc_mail" style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail"></label>
    117 {footer_script require="jquery"}{literal}
    118 jQuery(document).ready(function() {
    119   $("input[name=stc_check]").change(function() {
    120     if ($(this).is(":checked")) $("#stc_mail").css("display", "");
    121     else $("#stc_mail").css("display", "none");
    122   });
    123 });
    124 {/literal}{/footer_script}';
    125   }
    126   $replace[0].= $search[0];
    127  
     175  global $user, $picture; 
    128176 
    129177  ## subscribe at any moment ##
     
    143191    email = "'.$user['email'].'"
    144192    AND image_id = '.$picture['current']['id'].'
     193    AND validated = "true"
    145194;';
    146195    if (pwg_db_num_rows(pwg_query($query)))
     
    148197      $replace[1].= '
    149198    {\'You are currently subscribed to comments of this picture.\'|@translate}
    150     <a href="'.make_stc_url('unsubscribe-image', $user['email'], $picture['current']['id']).'">{\'Unsubscribe\'|@translate}';
     199    <a href="'.add_url_params($picture['current']['url'], array('stc_unsubscribe'=>'1')).'">{\'Unsubscribe\'|@translate}';
    151200      $no_form = true;
    152201    }
     
    194243</form>';
    195244
    196   return str_replace($search, $replace, $template);
    197 }
    198 
    199 
    200 /**
    201  * add field and on album page
    202  */
    203 function stc_on_album()
    204 {
    205   global $page, $template, $pwg_loaded_plugins;
    206  
    207   if (
    208       script_basename() != 'index' or !isset($page['section']) or
    209       !isset($pwg_loaded_plugins['Comments_on_Albums']) or
    210       $page['section'] != 'categories' or !isset($page['category'])
    211     )
    212   {
    213     return;
    214   }
    215  
    216   if (isset($_POST['stc_check_stdl']))
    217   {
    218     subscribe_to_comments($page['category']['id'], @$_POST['stc_mail_stdl'], 'category');
    219   }
    220  
    221   $template->set_prefilter('comments_on_albums', 'stc_on_album_prefilter');
    222 }
    223 
    224 function stc_on_album_prefilter($template, &$smarty)
    225 {
    226   global $user, $page;
    227  
     245
    228246  ## subscribe while add a comment ##
    229247  $search[0] = '<input type="submit" value="{\'Submit\'|@translate}">';
    230  
    231   $replace[0] = '
     248  $replace[0] = null;
     249 
     250  if (!isset($no_form))
     251  {
     252    $replace[0].= '
    232253<label>{\'Subscribe to new comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label>';
     254  }
    233255  if (is_a_guest())
    234256  {
     
    246268  $replace[0].= $search[0];
    247269 
     270  return str_replace($search, $replace, $template);
     271}
     272
     273
     274/**
     275 * add field and on album page
     276 */
     277function stc_on_album()
     278{
     279  global $page, $template, $pwg_loaded_plugins;
     280 
     281  $infos = $errors = array();
     282 
     283  if (
     284      script_basename() != 'index' or !isset($page['section']) or
     285      !isset($pwg_loaded_plugins['Comments_on_Albums']) or
     286      $page['section'] != 'categories' or !isset($page['category'])
     287    )
     288  {
     289    return;
     290  }
     291 
     292  if (isset($_POST['stc_check_stdl']))
     293  {
     294    $return = subscribe_to_comments($page['category']['id'], @$_POST['stc_mail_stdl'], 'category');
     295    if ($return === 'confirm_mail')
     296    {
     297      array_push($infos, l10n('Please check your email inbox to confirm your subscription.'));
     298    }
     299    else if ($return === true)
     300    {
     301      array_push($infos, l10n('You have been added to the list of subscribers for this album.'));
     302    }
     303    else
     304    {
     305      array_push($errors, l10n('Invalid email adress, your are not subscribed to comments.'));
     306    }
     307  }
     308  else if (isset($_GET['stc_unsubscribe']))
     309  {
     310    if (un_subscribe_to_comments($page['category']['id'], null, 'category'))
     311    {
     312      array_push($infos, l10n('Successfully unsubscribed your email address from receiving notifications.'));
     313    }
     314  }
     315 
     316  // messages management
     317  if (!empty($errors))
     318  {
     319    $errors_bak = $template->get_template_vars('errors');
     320    if (empty($errors_bak)) $errors_bak = array();
     321    $template->assign('errors', array_merge($errors_bak, $errors));
     322    $template->set_prefilter('index', 'coa_messages'); // here we use a prefilter existing in COA
     323  }
     324  if (!empty($infos))
     325  {
     326    $infos_bak = $template->get_template_vars('infos');
     327    if (empty($infos_bak)) $infos_bak = array();
     328    $template->assign('infos', array_merge($infos_bak, $infos));
     329    $template->set_prefilter('index', 'coa_messages');
     330  }
     331 
     332  $template->set_prefilter('comments_on_albums', 'stc_on_album_prefilter');
     333}
     334
     335function stc_on_album_prefilter($template, &$smarty)
     336{
     337  global $user, $page; 
    248338 
    249339  ## subscribe at any moment ##
     
    263353    email = "'.$user['email'].'"
    264354    AND category_id = '.$page['category']['id'].'
     355    AND validated = "true"
    265356;';
    266357    if (pwg_db_num_rows(pwg_query($query)))
    267358    {
     359      $url_params['section'] = 'categories';
     360      $url_params['category'] = $page['category'];
     361     
     362      $element_url = make_index_url($url_params);
     363   
    268364      $replace[1].= '
    269365    {\'You are currently subscribed to comments of this album.\'|@translate}
    270     <a href="'.make_stc_url('unsubscribe-category', $user['email'], $page['category']['id']).'">{\'Unsubscribe\'|@translate}';
     366    <a href="'.add_url_params($element_url, array('stc_unsubscribe'=>'1')).'">{\'Unsubscribe\'|@translate}';
    271367      $no_form = true;
    272368    }
     
    314410</form>';
    315411
     412
     413  ## subscribe while add a comment ##
     414  $search[0] = '<input type="submit" value="{\'Submit\'|@translate}">';
     415  $replace[0] = null;
     416 
     417  if (!isset($no_form))
     418  {
     419    $replace[0].= '
     420<label>{\'Subscribe to new comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label>';
     421  }
     422  if (is_a_guest())
     423  {
     424    $replace[0].= '
     425<label id="stc_mail" style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail"></label>
     426{footer_script require="jquery"}{literal}
     427jQuery(document).ready(function() {
     428  $("input[name=stc_check]").change(function() {
     429    if ($(this).is(":checked")) $("#stc_mail").css("display", "");
     430    else $("#stc_mail").css("display", "none");
     431  });
     432});
     433{/literal}{/footer_script}';
     434  }
     435  $replace[0].= $search[0];
     436
    316437  return str_replace($search, $replace, $template);
    317438}
    318439
     440
     441/**
     442 * add link to management page for registered users
     443 */
     444function stc_menubar_apply($menu_ref_arr)
     445{
     446  global $template;
     447  $menu = &$menu_ref_arr[0];
     448 
     449  if ( !is_a_guest() and ($block = $menu->get_block('mbIdentification')) != null )
     450  {
     451    $template->set_prefilter('menubar', 'stc_menubar_apply_prefilter');
     452  }
     453}
     454
     455function stc_menubar_apply_prefilter($content, &$smarty)
     456{
     457  global $user;
     458 
     459  $search = '{if isset($U_REGISTER)}';
     460  $replace = '<li><a href="'.make_stc_url('manage', $user['email']).'" title="{\'Manage my subscriptions\'|@translate}" rel="nofollow">{\'Manage my subscriptions\'|@translate}</a></li>';
     461  return str_replace($search, $replace.$search, $content);
     462}
    319463?>
  • extensions/Subscribe_to_comments/include/subscribtions_page.inc.php

    r12560 r12600  
    77
    88// check input parameters
     9$_GET['verif_key'] = $_GET['action'].$_GET['email'].(isset($_GET['id'])?$_GET['id']:null);
    910if (
    1011  empty($_GET['action']) or empty($_GET['email']) or empty($_GET['key'])
    11   or decrypt_value($_GET['key'], $conf['secret_key']) !== $_GET['action'].$_GET['email'] 
     12  or decrypt_value($_GET['key'], $conf['secret_key']) !== $_GET['verif_key']
    1213  )
    1314{
    14   set_status_header(403);
    15   array_push($errors, l10n('Bad query'));
     15  $_GET['action'] = 'hacker';
     16}
     17else
     18{
     19  // sanitize inputs
     20  if (isset($_GET['id'])) $_GET['id'] = pwg_db_real_escape_string($_GET['id']);
     21  $_GET['email'] = pwg_db_real_escape_string($_GET['email']);
     22
     23  // unsubscribe
     24  if (isset($_POST['unsubscribe']))
     25  {
     26    if (un_subscribe_to_comments(!empty($_GET['id'])?$_GET['id']:'N/A', $_GET['email'], $_POST['unsubscribe']))
     27    {
     28      array_push($infos, l10n('Successfully unsubscribed your email address from receiving notifications.'));
     29    }
     30    else
     31    {
     32      array_push($errors, l10n('Invalid email adress.'));
     33    }
     34   
     35    $_GET['action'] = 'manage';
     36  }
     37  if (isset($_GET['unsubscribe']))
     38  {
     39    $query = '
     40  DELETE FROM '.SUBSCRIBE_TO_TABLE.'
     41    WHERE
     42      id = '.pwg_db_real_escape_string($_GET['unsubscribe']).'
     43      AND email = "'.$_GET['email'].'"
     44  ;';
     45    pwg_query($query);
     46   
     47    if (pwg_db_changes(null) != 0)
     48    {
     49      array_push($infos, l10n('Successfully unsubscribed your email address from receiving notifications.'));
     50    }
     51    else
     52    {
     53      array_push($errors, l10n('Invalid email adress.'));
     54    }
     55  }
     56 
     57  $template->assign('MANAGE_LINK', make_stc_url('manage', $_GET['email']));
    1658}
    1759
    1860switch ($_GET['action'])
    1961{
    20   /* unsubscribe */
    21   case 'unsubscribe-image' :
    22     if (empty($where_clause)) $where_clause = 'image_id = '.pwg_db_real_escape_string($_GET['param']);
    23   case 'unsubscribe-category':
    24     if (empty($where_clause)) $where_clause = 'category_id = '.pwg_db_real_escape_string($_GET['param']);
    25   case 'unsubcribe-all' :
     62  /* validate */
     63  case 'validate-image' :
    2664  {
    27     $query = '
    28 DELETE FROM '.SUBSCRIBE_TO_TABLE.'
    29   WHERE
    30     email = "'.pwg_db_real_escape_string($_GET['email']).'"
    31     '.(!empty($where_clause) ? 'AND '.$where_clause : null).'
    32 ;';
    33     pwg_query($query);
     65    if (validate_subscriptions($_GET['id'], $_GET['email'], 'image'))
     66    {
     67      array_push($infos, l10n('Your subscribtion has been validated, thanks you.'));
     68    }
     69    else
     70    {
     71      array_push($errors, l10n('Nothing to validate.'));
     72    }
    3473   
    35     array_push($infos, l10n('You have been successfully unsubscribed, good bye.'));
     74    $element = get_picture_infos($_GET['id']);
     75   
     76    $template->assign(array(
     77      'validate' => 'image',
     78      'element' => $element,
     79      ));
     80     
     81    break;
     82  }
     83  case 'validate-category':
     84  {
     85    if (validate_subscriptions($_GET['id'], $_GET['email'], 'category'))
     86    {
     87      array_push($infos, l10n('Your subscribtion has been validated, thanks you.'));
     88    }
     89    else
     90    {
     91      array_push($errors, l10n('Nothing to validate.'));
     92    }
     93   
     94    $element = get_category_infos($_GET['id']);
     95   
     96    $template->assign(array(
     97      'validate' => 'category',
     98      'element' => $element,
     99      ));
    36100    break;
    37101  }
    38102 
    39   /* validate */
    40   case 'validate-image' :
    41     if (empty($where_clause)) $where_clause = 'image_id = '.pwg_db_real_escape_string($_GET['param']);
    42   case 'validate-category':
    43     if (empty($where_clause)) $where_clause = 'category_id = '.pwg_db_real_escape_string($_GET['param']);
    44   case 'validate-all' :
    45   {
    46      $query = '
    47 UPDATE '.SUBSCRIBE_TO_TABLE.'
    48   SET validated = "true"
    49   WHERE
    50     email = "'.pwg_db_real_escape_string($_GET['email']).'"
    51     '.(!empty($where_clause) ? 'AND '.$where_clause : null).'
    52 ;';
    53     pwg_query($query);
     103  /* unsubscribe */
     104  case 'unsubscribe-image' :
     105  { 
     106    $element = get_picture_infos($_GET['id']);
    54107   
    55     array_push($infos, l10n('Your subscribtion has been validated, thanks you.'));
     108    $template->assign(array(
     109      'unsubscribe_form' => 'image',
     110      'element' => $element,
     111      ));
     112   
     113    break;
     114  }
     115  case 'unsubscribe-category':
     116  { 
     117    $element = get_category_infos($_GET['id']);
     118   
     119    $template->assign(array(
     120      'unsubscribe_form' => 'category',
     121      'element' => $element,
     122      ));
     123   
    56124    break;
    57125  }
     
    60128  case 'manage' :
    61129  {
     130    $query = '
     131SELECT *
     132  FROM '.SUBSCRIBE_TO_TABLE.'
     133  WHERE
     134    email = "'.$_GET['email'].'"
     135    AND validated = "true"
     136  ORDER BY registration_date DESC
     137;';
     138    $result = pwg_query($query);
     139   
     140    if (pwg_db_num_rows($result) !== 0)
     141    {
     142      while ($subscription = pwg_db_fetch_assoc($result))
     143      {
     144        if (!empty($subscription['image_id']))
     145        {
     146          $subscription['infos'] = get_picture_infos($subscription['image_id']);
     147          $subscription['type'] = 'image';
     148        }
     149        else if (!empty($subscription['category_id']))
     150        {
     151          $subscription['infos'] = get_category_infos($subscription['category_id']);
     152          $subscription['type'] = 'category';
     153        }
     154        $subscription['registration_date'] = format_date($subscription['registration_date'], true);
     155        $template->append('subscriptions', $subscription);
     156      }
     157    }
     158    else
     159    {
     160      $template->assign('subscriptions', 'none');
     161    }
    62162    break;
    63163  }
    64164 
    65   default :
     165  case 'hacker' :
    66166  {
    67167    set_status_header(403);
     
    69169  }
    70170}
     171
     172$template->assign(array(
     173  'EMAIL' => $_GET['email'],
     174  'SUBSCRIBE_TO_PATH' => SUBSCRIBE_TO_PATH,
     175  ));
    71176
    72177$template->assign(array(
Note: See TracChangeset for help on using the changeset viewer.