Changeset 12561


Ignore:
Timestamp:
Nov 6, 2011, 7:33:55 PM (9 years ago)
Author:
mistic100
Message:

and standalone links, fully compatible with Comments on Albums

Location:
extensions/Subscribe_to_comments
Files:
5 edited

Legend:

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

    r12560 r12561  
    1515  $exclude = null;
    1616  if (!empty($_POST['stc_mail'])) $exclude = pwg_db_real_escape_string($_POST['stc_mail']);
    17   if (!is_a_guest()) $exclude = $user['email'];
     17  else if (!is_a_guest()) $exclude = $user['email'];
    1818 
    1919  // get subscribers emails
     
    3030 
    3131  set_make_full_url();
    32   switch ($type)
    33   {
    34     case 'image':
    35     {
    36       // get image infos
    37       $query = '
     32  if ($type == 'image')
     33  {
     34    // get image infos
     35    $query = '
    3836SELECT
    3937    id,
     
    4341  WHERE id = '.$comm['image_id'].'
    4442;';
    45       $element = pwg_db_fetch_assoc(pwg_query($query));
    46        
    47       if (empty($element['name']))
    48       {
    49         $element['name'] = get_name_from_file($element['file']);
    50       }
     43    $element = pwg_db_fetch_assoc(pwg_query($query));
    5144     
    52       $url_params = array('image_id' => $element['id']);
    53       if (!empty($page['category']))
    54       {
    55         $url_params['section'] = 'categories';
    56         $url_params['category'] = $page['category'];
    57       }
    58 
    59       $element['url'] = make_picture_url($url_params);
    60       break;
     45    if (empty($element['name']))
     46    {
     47      $element['name'] = get_name_from_file($element['file']);
    6148    }
    6249   
    63     case 'category' :
     50    $url_params = array('image_id' => $element['id']);
     51    if (!empty($page['category']))
    6452    {
    65       // get category infos
    66       $query = '
     53      $url_params['section'] = 'categories';
     54      $url_params['category'] = $page['category'];
     55    }
     56
     57    $element['url'] = make_picture_url($url_params);
     58  }
     59  else if ($type == 'category')
     60  {
     61    // get category infos
     62    $query = '
    6763SELECT
    6864    id,
    69     name
     65    name,
     66    permalink
    7067  FROM '.CATEGORIES_TABLE.'
    7168  WHERE id = '.$comm['category_id'].'
    7269;';
    73       $element = pwg_db_fetch_assoc(pwg_query($query));
    74      
    75       $url_params['section'] = 'categories';
    76       $url_params['category'] = $element;
    77 
    78      
    79       $element['url'] = make_index_url($url_params);
    80       break;
    81     }
     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);
    8276  }
    8377 
     
    117111}
    118112
     113
    119114/*
    120115 * add an email to subscribers list
     
    128123 
    129124  $infos = $errors = array();
    130  
    131125  if ( is_a_guest() and empty($email) )
    132126  {
    133127    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   
    134135    return;
    135136  }
    136   else if ( !is_a_guest() )
     137  else if (!is_a_guest())
    137138  {
    138139    $email = $user['email'];
    139140  }
    140141 
     142  // don't care if already registered
    141143  $query = '
    142144INSERT IGNORE INTO '.SUBSCRIBE_TO_TABLE.'(
     
    155157  pwg_query($query);
    156158 
     159  // send validation mail
    157160  if (is_a_guest() and pwg_db_insert_id() != 0)
    158161  {
     162    $element_name = ($type == 'image') ? $picture['current']['name'] : $page['category']['name'];
     163   
    159164    $mail_args = array(
    160165      'subject' => '['.strip_tags($conf['gallery_title']).'] Please confirm your subscribtion to comments',
     
    163168     
    164169    $mail_args['content'] = '
    165 You requested to subscribe by email to comments on <b>'.$picture['current']['name'].'</b>.<br>
     170You requested to subscribe by email to comments on <b>'.$element_name.'</b>.<br>
    166171<br>
    167172We care about your inbox, so we want to confirm this request. Please click the confirm link to activate the subscription.<br>
     
    175180    array_push($infos, l10n('Please check your email inbox to confirm your subscription.'));
    176181  }
     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 
    177188 
    178189  if (!empty($infos))
    179190  {
    180     $template->assign('infos', array_merge($template->get_template_vars('infos'), $infos));
    181   }
    182   if (!empty($errors))
    183   {
    184     $template->assign('errors', array_merge($template->get_template_vars('errors'), $errors));
    185   }
    186 }
     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
    187199
    188200/**
     
    194206function make_stc_url($action, $email)
    195207{
    196   if ( empty($action) or empty($email) ) return null;
     208  if ( empty($action) or empty($email) )
     209  {
     210    trigger_error('make_stc_url missing action and/or mail', E_USER_WARNING);
     211    return null;
     212  }
    197213 
    198214  global $conf;
     
    219235}
    220236
     237
    221238/**
    222239 * crypt a string using mcrypt extension or a binary method
     
    266283}
    267284
     285
    268286/**
    269287 * variant of base64 functions usable into url
  • extensions/Subscribe_to_comments/language/en_UK/plugin.lang.php

    r12560 r12561  
    66$lang['You have been successfully unsubscribed, good bye.'] = 'You have been successfully unsubscribed, good bye.';
    77$lang['Your subscribtion has been validated, thanks you.'] = 'Your subscribtion has been validated, thanks you.';
     8$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.';
     9$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.';
     10$lang['You are currently subscribed to comments of this picture.'] = 'You are currently subscribed to comments of this picture.';
     11$lang['You are currently subscribed to comments of this album.'] = 'You are currently subscribed to comments of this album.';
     12$lang['Unsubscribe'] = 'Unsubscribe';
    813
    914?>
  • extensions/Subscribe_to_comments/language/fr_FR/plugin.lang.php

    r12560 r12561  
    44$lang['Invalid email adress, your are not subscribed to comments.'] = 'Email invalide, vous n\'avez pas été inscrit.';
    55$lang['Please check your email inbox to confirm your subscription.'] = 'Veuillez consulter votre boite mail pour confirmer votre inscription.';
    6 $lang['You have been successfully unsubscribed, good bye.'] = 'Vous avez supprimé de la liste de notification, au revoir.';
    7 $lang['Your subscribtion has been validated, thanks you.'] = 'Votre inscription a bien été validée, merci..';
     6$lang['You have been successfully unsubscribed, good bye.'] = 'Vous avez été supprimé de la liste de notification, au revoir.';
     7$lang['Your subscribtion has been validated, thanks you.'] = 'Votre inscription a bien été validée, merci.';
     8$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.';
     9$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.';
     10$lang['You are currently subscribed to comments of this picture.'] = 'Vous êtes actuellement inscrit aux commentaires de cette photo.';
     11$lang['You are currently subscribed to comments of this album.'] = 'Vous êtes actuellement inscrit aux commentaires de cet album.';
     12$lang['Unsubscribe'] = 'Se désinscrire';
    813
    914?>
  • extensions/Subscribe_to_comments/main.inc.php

    r12560 r12561  
    44Version: auto
    55Description: This plugin allows you to subscribe to comments by mail.
    6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=
     6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=587
    77Author: Mistic
    88Author URI: http://www.strangeplanet.fr
     
    2020include_once(SUBSCRIBE_TO_PATH.'include/functions.inc.php');
    2121
     22load_language('plugin.lang', SUBSCRIBE_TO_PATH);
     23
     24// send mails
    2225add_event_handler('user_comment_insertion', 'stc_comment_insertion');
    2326add_event_handler('user_comment_validation', 'stc_comment_validation', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
     27
     28// subscribe
    2429add_event_handler('loc_end_picture', 'stc_on_picture');
     30add_event_handler('loc_begin_index', 'stc_on_album');
     31
     32// management
    2533add_event_handler('loc_end_section_init', 'stc_detect_section');
    26 add_event_handler('loc_end_index', 'stc_load_section');   
     34add_event_handler('loc_end_index', 'stc_load_section');
    2735
    2836?>
  • extensions/Subscribe_to_comments/subscribe_to_comments.inc.php

    r12560 r12561  
    8888
    8989/**
    90  * adds fields on picture page
     90 * add field and link on picture page
    9191 */
    9292function stc_on_picture()
    9393{
    94   global $template;
     94  global $template, $picture;
     95 
     96  if (isset($_POST['stc_check_stdl']))
     97  {
     98    subscribe_to_comments($picture['current']['id'], @$_POST['stc_mail_stdl'], 'image');
     99  }
    95100 
    96101  $template->set_prefilter('picture', 'stc_on_picture_prefilter');
     
    99104function stc_on_picture_prefilter($template, &$smarty)
    100105{
    101   $search = '<input type="submit" value="{\'Submit\'|@translate}">';
    102  
    103   $replace = '
    104 <label>{\'Subscribe to new comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label>
     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].= '
    105116<label id="stc_mail" style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail"></label>
    106117{footer_script require="jquery"}{literal}
     
    111122  });
    112123});
    113 {/literal}
    114 {/footer_script}
    115 '.$search;
     124{/literal}{/footer_script}';
     125  }
     126  $replace[0].= $search[0];
     127 
     128 
     129  ## subscribe at any moment ##
     130  $search[1] = '{if isset($comment_add)}';
     131 
     132  $replace[1] = $search[1].'
     133<form method="post" action="{$comment_add.F_ACTION}" class="filter" id="stc_standalone">
     134  <fieldset>';
     135 
     136  // if registered user we check if already subscribed
     137  if (!is_a_guest())
     138  {
     139    $query = '
     140SELECT id
     141  FROM '.SUBSCRIBE_TO_TABLE.'
     142  WHERE
     143    email = "'.$user['email'].'"
     144    AND image_id = '.$picture['current']['id'].'
     145;';
     146    if (pwg_db_num_rows(pwg_query($query)))
     147    {
     148      $replace[1].= '
     149    {\'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}';
     151      $no_form = true;
     152    }
     153  }
     154 
     155  if (!isset($no_form))
     156  {
     157    $replace[1].= '
     158    <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>';
     159   
     160    // form for guests
     161    if (is_a_guest())
     162    {
     163      $replace[1].= '
     164      <label style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail_stdl"></label>
     165      <label style="display:none;"><input type="submit" value="{\'Submit\'|@translate}"></label>
     166    {footer_script require="jquery"}{literal}
     167    jQuery(document).ready(function() {
     168      $("a#stc_check_stdl").click(function() {
     169        $("input[name=stc_check_stdl]").prop("checked", true);
     170        $("#stc_standalone label").toggle();
     171        return false;
     172      });
     173    });
     174    {/literal}{/footer_script}';
     175    }
     176    // simple link for registered users
     177    else
     178    {
     179      $replace[1].= '
     180    {footer_script require="jquery"}{literal}
     181    jQuery(document).ready(function() {
     182      $("a#stc_check_stdl").click(function() {
     183        $("input[name=stc_check_stdl]").prop("checked", true);
     184        $(this).parents("form#stc_standalone").submit();
     185        return false;
     186      });
     187    });
     188    {/literal}{/footer_script}';
     189    }
     190  }
     191     
     192  $replace[1].= '
     193  </fieldset>
     194</form>';
    116195
    117196  return str_replace($search, $replace, $template);
    118197}
    119198
     199
     200/**
     201 * add field and on album page
     202 */
     203function 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
     224function stc_on_album_prefilter($template, &$smarty)
     225{
     226  global $user, $page;
     227 
     228  ## subscribe while add a comment ##
     229  $search[0] = '<input type="submit" value="{\'Submit\'|@translate}">';
     230 
     231  $replace[0] = '
     232<label>{\'Subscribe to new comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label>';
     233  if (is_a_guest())
     234  {
     235    $replace[0].= '
     236<label id="stc_mail" style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail"></label>
     237{footer_script require="jquery"}{literal}
     238jQuery(document).ready(function() {
     239  $("input[name=stc_check]").change(function() {
     240    if ($(this).is(":checked")) $("#stc_mail").css("display", "");
     241    else $("#stc_mail").css("display", "none");
     242  });
     243});
     244{/literal}{/footer_script}';
     245  }
     246  $replace[0].= $search[0];
     247 
     248 
     249  ## subscribe at any moment ##
     250  $search[1] = '{if isset($comment_add)}';
     251 
     252  $replace[1] = $search[1].'
     253<form method="post" action="{$comment_add.F_ACTION}" class="filter" id="stc_standalone">
     254  <fieldset>';
     255 
     256  // if registered user we check if already subscribed
     257  if (!is_a_guest())
     258  {
     259    $query = '
     260SELECT id
     261  FROM '.SUBSCRIBE_TO_TABLE.'
     262  WHERE
     263    email = "'.$user['email'].'"
     264    AND category_id = '.$page['category']['id'].'
     265;';
     266    if (pwg_db_num_rows(pwg_query($query)))
     267    {
     268      $replace[1].= '
     269    {\'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}';
     271      $no_form = true;
     272    }
     273  }
     274 
     275  if (!isset($no_form))
     276  {
     277    $replace[1].= '
     278    <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>';
     279   
     280    // form for guests
     281    if (is_a_guest())
     282    {
     283      $replace[1].= '
     284      <label style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail_stdl"></label>
     285      <label style="display:none;"><input type="submit" value="{\'Submit\'|@translate}"></label>
     286    {footer_script require="jquery"}{literal}
     287    jQuery(document).ready(function() {
     288      $("a#stc_check_stdl").click(function() {
     289        $("input[name=stc_check_stdl]").prop("checked", true);
     290        $("#stc_standalone label").toggle();
     291        return false;
     292      });
     293    });
     294    {/literal}{/footer_script}';
     295    }
     296    // simple link for registered users
     297    else
     298    {
     299      $replace[1].= '
     300    {footer_script require="jquery"}{literal}
     301    jQuery(document).ready(function() {
     302      $("a#stc_check_stdl").click(function() {
     303        $("input[name=stc_check_stdl]").prop("checked", true);
     304        $(this).parents("form#stc_standalone").submit();
     305        return false;
     306      });
     307    });
     308    {/literal}{/footer_script}';
     309    }
     310  }
     311     
     312  $replace[1].= '
     313  </fieldset>
     314</form>';
     315
     316  return str_replace($search, $replace, $template);
     317}
     318
    120319?>
Note: See TracChangeset for help on using the changeset viewer.