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

and standalone links, fully compatible with Comments on Albums

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.