Ignore:
Timestamp:
Dec 23, 2013, 9:17:28 PM (10 years ago)
Author:
mistic100
Message:

update for 2.6

File:
1 edited

Legend:

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

    r21608 r26139  
    11<?php
    2 if (!defined('SUBSCRIBE_TO_PATH')) die('Hacking attempt!');
    3 
    4 include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
     2defined('SUBSCRIBE_TO_PATH') or die('Hacking attempt!');
    53
    64/**
     
    108function send_comment_to_subscribers($comm)
    119{
    12   if ( empty($comm) or !is_array($comm) )
    13   {
    14     trigger_error('send_comment_to_subscribers: undefineded comm', E_USER_WARNING);
    15     return false;
    16   }
    17  
     10  if (empty($comm) or !is_array($comm))
     11  {
     12    trigger_error('send_comment_to_subscribers: undefined comm', E_USER_WARNING);
     13    return false;
     14  }
     15
    1816  global $conf, $page, $user, $template;
    19  
     17
    2018  // create search clauses
    2119  $where_clauses = array();
     
    2422    $element_id = $comm['image_id'];
    2523    $element_type = 'image';
    26    
    27     array_push($where_clauses, 'type = "image" AND element_id = '.$element_id.'');
    28     if (!empty($page['category']['id'])) array_push($where_clauses, 'type = "album-images" AND element_id = '.$page['category']['id'].'');
    29     array_push($where_clauses, 'type = "all-images"');
     24
     25    $where_clauses[] = '(type = "image" AND element_id = '.$element_id.')';
     26    $where_clauses[] = 'type = "all-images"';
     27    if (!empty($page['category']['id']))
     28    {
     29      $where_clauses[] = '(type = "album-images" AND element_id = '.$page['category']['id'].')';
     30    }
    3031  }
    3132  else if (isset($comm['category_id']))
     
    3334    $element_id = $comm['category_id'];
    3435    $element_type = 'category';
    35    
    36     array_push($where_clauses, 'type = "album" AND element_id = '.$element_id.'');
    37     array_push($where_clauses, 'type = "all-albums"');
     36
     37    $where_clauses[] = '(type = "album" AND element_id = '.$element_id.')';
     38    $where_clauses[] = 'type = "all-albums"';
    3839  }
    3940  else
     
    4142    return;
    4243  }
    43  
     44
    4445  // exclude current user
    4546  $exclude = null;
     
    5253    $exclude = $user['email'];
    5354  }
    54  
     55
    5556  // get subscribers datas
    5657  $query = '
     
    6162  FROM '.SUBSCRIBE_TO_TABLE.'
    6263  WHERE (
    63       ('.implode(")\n      OR (", $where_clauses).')
     64      '.implode("\n      OR ", $where_clauses).'
    6465    )
    6566    AND validated = true
    6667    AND email != "'.$exclude.'"
     68  GROUP BY email
    6769';
    68   $subscriptions = hash_from_query($query, 'id');
    69  
    70   if (count($subscriptions)==0) return;
    71  
     70  $subscriptions = query2array($query);
     71
     72  if (count($subscriptions)==0)
     73  {
     74    return;
     75  }
     76
    7277  set_make_full_url();
    73  
     78
    7479  // get element infos
    7580  if ($element_type == 'image')
     
    8186    $element = get_category_infos($comm['category_id']);
    8287  }
    83  
     88
    8489  // format comment
    85   if ($comm['author'] == 'guest') $comm['author'] = l10n('guest');
     90  if ($comm['author'] == 'guest')
     91  {
     92    $comm['author'] = l10n('guest');
     93  }
     94
    8695  $comm['author'] = trigger_event('render_comment_author', $comm['author']);
    8796  $comm['content'] = trigger_event('render_comment_content', $comm['content']);
    88  
    89   // mail content
    90   $subject = '['.strip_tags($conf['gallery_title']).'] Re:'.$element['name'];
    91    
    92   $template->set_filename('stc_mail', realpath(SUBSCRIBE_TO_PATH . 'template/mail/notification.tpl'));
     97
     98  include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
    9399
    94100  foreach ($subscriptions as $row)
     
    103109      $row['user_id'] = $conf['guest_id'];
    104110    }
    105    
     111
    106112    // check permissions
    107113    if (!user_can_view_element($row['user_id'], $element_id, $element_type))
     
    109115      continue;
    110116    }
    111    
    112     // send mail
    113     switch_lang_to($row['language']);
    114     load_language('plugin.lang', SUBSCRIBE_TO_PATH);
    115    
    116     $comm['caption'] = sprintf('<b>%s</b> wrote on <i>%s</i>', $comm['author'], format_date(date('Y-m-d H:i:s')));
    117    
    118     $template->assign('STC', array(
    119       'element' => $element,
    120       'comment' => $comm,
    121       'UNSUB_URL' => make_stc_url('unsubscribe', $row['email'], $row['id']),
    122       'MANAGE_URL' => make_stc_url('manage', $row['email']),
    123       'GALLERY_TITLE' => $conf['gallery_title'],
    124       ));
    125    
    126     $content = $template->parse('stc_mail', true);
    127 
    128     stc_send_mail($row['email'], $content, $subject);
     117
     118    switch_lang_to($language);
     119
     120    $comm['date'] = format_date(date('Y-m-d H:i:s'));
     121
     122    pwg_mail(
     123      $row['email'],
     124      array(
     125        'subject' => '['.strip_tags($conf['gallery_title']).'] Re:'.$element['name'],
     126        ),
     127      array(
     128        'filename' => 'notification',
     129        'dirname' => SUBSCRIBE_TO_PATH . 'template',
     130        'assign' => array(
     131          'ELEMENT' => $element,
     132          'COMMENT' => $comm,
     133          'UNSUB_URL' => make_stc_url('unsubscribe', $row['email'], $row['id']),
     134          'MANAGE_URL' => make_stc_url('manage', $row['email']),
     135          ),
     136        )
     137      );
     138
    129139    switch_lang_back();
    130140  }
    131  
     141
    132142  load_language('plugin.lang', SUBSCRIBE_TO_PATH);
    133143  unset_make_full_url();
     
    149159    return false;
    150160  }
    151  
    152   if ( !in_array($type, array('all-images','all-albums')) and $element_id == 'NULL' )
     161
     162  if (!in_array($type, array('all-images','all-albums')) and $element_id == 'NULL')
    153163  {
    154164    trigger_error('subscribe_to_comment: missing element_id', E_USER_WARNING);
    155165    return false;
    156166  }
    157  
     167
    158168  global $page, $conf, $user, $template, $picture;
    159  
     169
    160170  // check email
    161   if ( !empty($email) and !email_check_format($email) )
    162   {
    163     array_push($page['errors'], l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)'));
    164     return false;
    165   }
    166   if ( ( is_a_guest() or empty($user['email']) ) and empty($email) )
    167   {
    168     array_push($page['errors'], l10n('Invalid email adress, your are not subscribed to comments.'));
    169     return false;
    170   }
    171   else if ( !is_a_guest() and empty($email) )
     171  if (!empty($email) and !email_check_format($email))
     172  {
     173    $page['errors'][] = l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)');
     174    return false;
     175  }
     176  if ( (is_a_guest() or empty($user['email'])) and empty($email) )
     177  {
     178    $page['errors'][] = l10n('Invalid email address, your are not subscribed to comments.');
     179    return false;
     180  }
     181  else if (!is_a_guest() and empty($email))
    172182  {
    173183    $email = $user['email'];
    174184  }
    175  
    176   // search if already registered (can't use ODKU because we want to get the id of inserted OR updated row)
     185
     186  // search if already registered
    177187  $query = '
    178188SELECT id
     
    184194;';
    185195  $result = pwg_query($query);
    186  
     196
    187197  if (pwg_db_num_rows($result))
    188198  {
    189     list($inserted_id) = pwg_db_fetch_row($result);
    190   }
    191   else
    192   {
    193     $query = '
     199    return false;
     200  }
     201
     202  $query = '
    194203INSERT INTO '.SUBSCRIBE_TO_TABLE.'(
    195204    type,
     
    209218  )
    210219;';
    211     pwg_query($query);
    212    
    213     $inserted_id = pwg_db_insert_id();
    214   }
    215  
    216   // notify admins
    217   if ( pwg_db_changes() != 0 and $conf['Subscribe_to_Comments']['notify_admin_on_subscribe'] )
    218   {
    219     stc_mail_notification_admins($email, $type, $element_id, $inserted_id);
    220   }
    221  
    222   // send validation mail
    223   if ( is_a_guest() and pwg_db_changes() != 0 )
    224   {
    225     set_make_full_url();
    226    
    227     $template->set_filename('stc_mail', realpath(SUBSCRIBE_TO_PATH . 'template/mail/confirm.tpl'));
    228    
    229     $subject = '['.strip_tags($conf['gallery_title']).'] '.l10n('Confirm your subscribtion to comments');
    230      
     220  pwg_query($query);
     221
     222  $stc_id = pwg_db_insert_id();
     223
     224  include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
     225
     226  set_make_full_url();
     227
     228  if (!is_a_guest() or $conf['Subscribe_to_Comments']['notify_admin_on_subscribe'])
     229  {
    231230    switch ($type)
    232231    {
    233232      case 'image':
    234233        $element = get_picture_infos($element_id);
    235         $element['on'] = sprintf(l10n('the picture <a href="%s">%s</a>'), $element['url'], $element['name']);
     234        $element['on'] = l10n('the picture <a href="%s">%s</a>', $element['url'], $element['name']);
    236235        break;
    237236      case 'album-images':
    238237        $element = get_category_infos($element_id);
    239         $element['on'] = sprintf(l10n('all pictures of the album <a href="%s">%s</a>'), $element['url'], $element['name']);
     238        $element['on'] = l10n('all pictures of the album <a href="%s">%s</a>', $element['url'], $element['name']);
    240239        break;
    241240      case 'all-images':
     
    245244      case 'album':
    246245        $element = get_category_infos($element_id);
    247         $element['on'] = sprintf(l10n('the album <a href="%s">%s</a>'), $element['url'], $element['name']);
     246        $element['on'] = l10n('the album <a href="%s">%s</a>', $element['url'], $element['name']);
    248247        break;
    249248      case 'all-albums':
     
    252251        break;
    253252    }
    254    
    255     $template->assign('STC', array(
    256       'element' => $element,
    257       'VALIDATE_URL' => make_stc_url('validate', $email, $inserted_id),
    258       'MANAGE_URL' => make_stc_url('manage', $email),
    259       'GALLERY_TITLE' => $conf['gallery_title'],
    260       ));
    261    
    262     $content = $template->parse('stc_mail', true);
    263 
    264     stc_send_mail($email, $content, $subject);
    265     unset_make_full_url();
    266    
    267     array_push($page['infos'], l10n('Please check your email inbox to confirm your subscription.'));
    268     return true;
     253  }
     254
     255  // send validation mail
     256  if (is_a_guest())
     257  {
     258    pwg_mail(
     259      $email,
     260      array(
     261        'subject' => '['.strip_tags($conf['gallery_title']).'] '.l10n('Confirm your subscription to comments'),
     262        ),
     263      array(
     264        'filename' => 'confirm',
     265        'dirname' => SUBSCRIBE_TO_PATH . 'template',
     266        'assign' => array(
     267          'ELEMENT' => $element,
     268          'VALIDATE_URL' => make_stc_url('validate', $email, $stc_id),
     269          'MANAGE_URL' => make_stc_url('manage', $email),
     270          ),
     271        )
     272      );
     273
     274    $page['infos'][] = l10n('Please check your email in-box to confirm your subscription.');
    269275  }
    270276  // just display confirmation message
    271   else if (pwg_db_changes() != 0)
    272   {
    273     array_push($page['infos'], l10n('You have been added to the list of subscribers.'));
    274     return true;
    275   }
    276  
    277   return false;
     277  else
     278  {
     279    $page['infos'][] = l10n('You have been added to the list of subscribers.');
     280  }
     281
     282  // notify admins
     283  if ($conf['Subscribe_to_Comments']['notify_admin_on_subscribe'])
     284  {
     285    $keyargs_content = array(
     286      get_l10n_args('Hi administrators,'),
     287      get_l10n_args(''),
     288      get_l10n_args('%s has subscribed to comments on %s.', array($email, $element['on'])),
     289      get_l10n_args('', ''),
     290      get_l10n_args('Connected user: %s', stripslashes($user['username'])),
     291      get_l10n_args('IP: %s', $_SERVER['REMOTE_ADDR']),
     292      get_l10n_args('Browser: %s', $_SERVER['HTTP_USER_AGENT']),
     293      );
     294
     295    pwg_mail_notification_admins(
     296      get_l10n_args('%s has subscribed to comments on %s.', array($email, '')),
     297      $keyargs_content
     298      );
     299  }
     300
     301  unset_make_full_url();
     302
     303  return true;
    278304}
    279305
     
    285311 * @return: bool
    286312 */
    287 function un_subscribe_to_comments($email, $id)
    288 { 
    289   if ( !empty($email) and !email_check_format($email) )
     313function un_subscribe_to_comments($email, $ids)
     314{
     315  if (!empty($email) and !email_check_format($email))
    290316  {
    291317    trigger_error('un_subscribe_to_comment: bad email', E_USER_WARNING);
    292318    return false;
    293319  }
    294  
    295   if (!preg_match('#^[0-9]+$#', $id))
     320  if (empty($ids))
    296321  {
    297322    trigger_error('un_subscribe_to_comment: bad id', E_USER_WARNING);
    298323    return false;
    299324  }
    300  
    301   global $template, $user;
    302  
     325
     326  global $user;
     327
    303328  // check email
    304   if ( ( is_a_guest() or empty($user['email']) ) and empty($email) )
    305   {
    306     return false;
    307   }
    308   else if ( !is_a_guest() and empty($email) )
     329  if ( (is_a_guest() or empty($user['email'])) and empty($email) )
     330  {
     331    return false;
     332  }
     333  else if (!is_a_guest() and empty($email))
    309334  {
    310335    $email = $user['email'];
    311336  }
    312  
     337
     338  if (!is_array($ids))
     339  {
     340    $ids = array($ids);
     341  }
     342  $ids = array_map('intval', $ids);
     343
    313344  // delete subscription
    314345  $query = '
    315346DELETE FROM '.SUBSCRIBE_TO_TABLE.'
    316   WHERE 
     347  WHERE
    317348    email = "'.pwg_db_real_escape_string($email).'"
    318     AND id = '.$id.'
     349    AND id IN('. implode(',', $ids) .')
    319350;';
    320351  pwg_query($query);
    321  
     352
    322353  return (pwg_db_changes() != 0);
    323354}
     
    330361 * @return: bool
    331362 */
    332 function validate_subscriptions($email, $id)
     363function validate_subscriptions($email, $ids)
    333364{
    334365  if (!email_check_format($email))
     
    337368    return false;
    338369  }
    339  
    340   if (!preg_match('#^[0-9]+$#', $id))
     370  if (empty($ids))
    341371  {
    342372    trigger_error('validate_subscriptions: bad id', E_USER_WARNING);
    343373    return false;
    344374  }
    345  
     375
     376  if (!is_array($ids))
     377  {
     378    $ids = array($ids);
     379  }
     380  $ids = array_map('intval', $ids);
     381
    346382  $query = '
    347383UPDATE '.SUBSCRIBE_TO_TABLE.'
    348384  SET validated = "true"
    349   WHERE 
     385  WHERE
    350386    email = "'.pwg_db_real_escape_string($email).'"
    351     AND id = '.$id.'
     387    AND id IN('. implode(',', $ids) .')
    352388;';
    353389  pwg_query($query);
    354  
     390
    355391  return (pwg_db_changes() != 0);
    356 }
    357 
    358 
    359 /**
    360  * send notification to admins
    361  * @param: string email
    362  * @param: string type (image|album-images|all-images|album|all-albums)
    363  * @param: int element_id
    364  * @param: int subscription id
    365  */
    366 function stc_mail_notification_admins($email, $type, $element_id, $inserted_id)
    367 {
    368   global $user, $conf, $template;
    369  
    370   $admins = get_admins_email();
    371   if (empty($admins)) return;
    372  
    373   set_make_full_url();
    374   switch_lang_to(get_default_language());
    375   load_language('plugin.lang', SUBSCRIBE_TO_PATH);
    376  
    377   $template->set_filename('stc_mail', realpath(SUBSCRIBE_TO_PATH . 'template/mail/admin.tpl'));
    378    
    379   $subject = '['.strip_tags($conf['gallery_title']).'] '.sprintf(l10n('%s has subscribed to comments on %s.'), is_a_guest()?$email:$user['username'], null);
    380    
    381   switch ($type)
    382   {
    383     case 'image':
    384       $element = get_picture_infos($element_id, false);
    385       $element['on'] = sprintf(l10n('the picture <a href="%s">%s</a>'), $element['url'], $element['name']);
    386       break;
    387     case 'album-images':
    388       $element = get_category_infos($element_id, false);
    389       $element['on'] = sprintf(l10n('all pictures of the album <a href="%s">%s</a>'), $element['url'], $element['name']);
    390       break;
    391     case 'all-images':
    392       $element['on'] = l10n('all pictures of the gallery');
    393       break;
    394     case 'album':
    395       $element = get_category_infos($element_id, false);
    396       $element['on'] = sprintf(l10n('the album <a href="%s">%s</a>'), $element['url'], $element['name']);
    397       break;
    398     case 'all-albums':
    399       $element['on'] = l10n('all albums of the gallery');
    400       break;
    401   }
    402  
    403   $technical_infos[] = sprintf(l10n('Connected user: %s'), stripslashes($user['username']));
    404   $technical_infos[] = sprintf(l10n('IP: %s'), $_SERVER['REMOTE_ADDR']);
    405   $technical_infos[] = sprintf(l10n('Browser: %s'), $_SERVER['HTTP_USER_AGENT']);
    406  
    407   $template->assign('STC', array(
    408     'ELEMENT' => $element['on'],
    409     'USER' => is_a_guest() ? '<b>'.$email.'</b>' : '<b>'.$user['username'].'</b> ('.$email.')',
    410     'GALLERY_TITLE' => $conf['gallery_title'],
    411     'TECHNICAL' => implode('<br>', $technical_infos),
    412     ));
    413  
    414   $content = $template->parse('stc_mail', true);
    415 
    416   stc_send_mail($admins, $content, $subject);
    417  
    418   unset_make_full_url();
    419   switch_lang_back();
    420   load_language('plugin.lang', SUBSCRIBE_TO_PATH);
    421392}
    422393
     
    431402function make_stc_url($action, $email, $id=null)
    432403{
    433   if ( empty($action) or empty($email) )
     404  if (empty($action) or empty($email))
    434405  {
    435406    trigger_error('make_stc_url: missing action and/or mail', E_USER_WARNING);
    436407    return null;
    437408  }
    438  
     409
    439410  global $conf;
    440411  set_make_full_url();
    441  
    442   $url_params = array(
    443     'action' => $action,
    444     'email' => $email,
    445     );
    446  
     412
     413  $url_params = compact('action', 'email');
    447414  if (!empty($id))
    448415  {
    449416    $url_params['id'] = $id;
    450417  }
    451  
     418
    452419  $url_params['key'] = crypt_value(
    453     $action.$email.(isset($url_params['id'])?$url_params['id']:null),
     420    $action.$email.$id,
    454421    $conf['secret_key']
    455422    );
    456  
     423
    457424  $url = add_url_params(
    458     make_index_url( array('section' => 'subscriptions') ),
     425    make_index_url(array('section' => 'subscriptions')),
    459426    $url_params
    460427    );
    461    
     428
    462429  unset_make_full_url();
    463430  return $url;
    464 }
    465 
    466 
    467 /**
    468  * send mail with STC style
    469  * @param: string to
    470  * @param: string content
    471  * @param: string subject
    472  * @return: bool
    473  */
    474 function stc_send_mail($to, $content, $subject)
    475 {
    476   global $conf, $conf_mail, $page, $template;
    477  
    478   // inputs
    479   if (empty($to))
    480   {
    481     return false;
    482   }
    483 
    484   if (empty($content))
    485   {
    486     return false;
    487   }
    488  
    489   if (empty($subject))
    490   {
    491     $subject = 'Piwigo';
    492   }
    493   else
    494   {
    495     $subject = trim(preg_replace('#[\n\r]+#s', '', $subject));
    496     $subject = encode_mime_header($subject);
    497   }
    498  
    499   if (!isset($conf_mail))
    500   {
    501     $conf_mail = get_mail_configuration();
    502   }
    503 
    504   $args['from'] = $conf_mail['formated_email_webmaster'];
    505  
    506   set_make_full_url();
    507  
    508   // hearders
    509   $headers = 'From: '.$args['from']."\n"; 
    510   $headers.= 'MIME-Version: 1.0'."\n";
    511   $headers.= 'X-Mailer: Piwigo Mailer'."\n";
    512   $headers.= 'Content-Transfer-Encoding: 8bit'."\n";
    513   $headers.= 'Content-Type: text/html; charset="'.get_pwg_charset().'";'."\n";
    514  
    515   // template
    516   $template->set_filenames(array(
    517     'stc_mail_header' => realpath(SUBSCRIBE_TO_PATH . 'template/mail/header.tpl'),
    518     'stc_mail_footer' => realpath(SUBSCRIBE_TO_PATH . 'template/mail/footer.tpl'),
    519     ));
    520   $stc_mail_css = file_get_contents(realpath(SUBSCRIBE_TO_PATH . 'template/mail/style.css'));
    521    
    522   $template->assign(array(
    523     'GALLERY_URL' => get_gallery_home_url(),
    524     'PHPWG_URL' => PHPWG_URL,
    525     'STC_MAIL_CSS' => str_replace("\n", null, $stc_mail_css),
    526     ));
    527  
    528   $content = $template->parse('stc_mail_header', true) . $content . $template->parse('stc_mail_footer', true);
    529  
    530   $content = wordwrap($content, 70, "\n", false);
    531 
    532   unset_make_full_url();
    533  
    534   // send mail
    535   return
    536     trigger_event('send_mail',
    537       false, /* Result */
    538       trigger_event('send_mail_to', get_strict_email_list($to)),
    539       trigger_event('send_mail_subject', $subject),
    540       trigger_event('send_mail_content', $content),
    541       trigger_event('send_mail_headers', $headers),
    542       $args
    543     );
    544431}
    545432
     
    553440function get_picture_infos($image_id, $with_thumb=true)
    554441{
    555   if (empty($image_id)) return array();
    556  
     442  if (empty($image_id))
     443  {
     444    return array();
     445  }
     446
    557447  $query = '
    558448SELECT
     
    565455;';
    566456  $element = pwg_db_fetch_assoc(pwg_query($query));
    567    
     457
    568458  if (empty($element['name']))
    569459  {
     
    571461  }
    572462  $element['name'] = trigger_event('render_element_name', $element['name']);
    573  
     463
    574464  $element['url'] = make_picture_url(array(
    575465    'image_id'=>$element['id']
    576466    ));
    577  
     467
    578468  if ($with_thumb)
    579469  {
    580470    $element['thumbnail'] = DerivativeImage::thumb_url($element);
    581471  }
    582  
     472
    583473  return $element;
    584474}
     
    593483{
    594484  global $conf;
    595  
    596   if ($user_id===null) $user_id = $conf['guest_id'];
    597  
     485
     486  if ($user_id===null)
     487  {
     488    $user_id = $conf['guest_id'];
     489  }
     490
    598491  $query = '
    599492SELECT
     
    606499    img.path
    607500  FROM '.CATEGORIES_TABLE.' AS cat
    608     LEFT JOIN '.USER_CACHE_CATEGORIES_TABLE.' AS ucc 
     501    LEFT JOIN '.USER_CACHE_CATEGORIES_TABLE.' AS ucc
    609502      ON ucc.cat_id = cat.id AND ucc.user_id = '.$user_id.'
    610503    LEFT JOIN '.IMAGES_TABLE.' AS img
     
    613506;';
    614507  $element = pwg_db_fetch_assoc(pwg_query($query));
    615  
     508
    616509  $element['url'] = make_index_url(array(
    617510    'section'=>'categories',
    618511    'category'=>$element,
    619512    ));
    620    
     513
    621514  $element['name'] = trigger_event('render_category_name', $element['name']);
    622  
     515
    623516  if ($with_thumb)
    624517  {
     
    636529    }
    637530  }
    638  
     531
    639532  return $element;
    640533}
     
    647540{
    648541  global $conf, $user;
    649  
     542
    650543  $admins = array();
    651  
     544
    652545  $query = '
    653546SELECT
     
    655548    u.'.$conf['user_fields']['email'].' AS email
    656549  FROM '.USERS_TABLE.' AS u
    657     JOIN '.USER_INFOS_TABLE.' AS i 
     550    JOIN '.USER_INFOS_TABLE.' AS i
    658551      ON i.user_id =  u.'.$conf['user_fields']['id'].'
    659552  WHERE i.status IN ("webmaster", "admin")
     
    686579{
    687580  global $conf;
    688  
     581
    689582  $old_conf = $conf['external_authentification'];
    690583  $conf['external_authentification'] = false;
    691584  $user = getuserdata($user_id, true);
    692585  $conf['external_authentification'] = $old_conf;
    693  
     586
    694587  if ($type == 'image')
    695588  {
     
    715608 */
    716609function crypt_value($value, $key)
    717 { 
     610{
    718611  if (extension_loaded('mcrypt'))
    719612  {
     
    733626    }
    734627  }
    735  
     628
    736629  $result = base64url_encode($result);
    737   return trim($result); 
     630  return trim($result);
    738631}
    739632
     
    746639function decrypt_value($value, $key)
    747640{
    748   $value = base64url_decode($value); 
    749  
     641  $value = base64url_decode($value);
     642
    750643  if (extension_loaded('mcrypt'))
    751644  {
     
    765658    }
    766659  }
    767  
     660
    768661  return trim($result);
    769662}
     
    773666 * http://php.net/manual/en/function.base64-encode.php#103849
    774667 */
    775 function base64url_encode($data)
    776 {
    777   return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
    778 }
    779 function base64url_decode($data)
    780 {
    781   return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
    782 }
    783 
    784 ?>
     668if (!function_exists('base64url_encode'))
     669{
     670  function base64url_encode($data)
     671  {
     672    return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
     673  }
     674  function base64url_decode($data)
     675  {
     676    return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
     677  }
     678}
Note: See TracChangeset for help on using the changeset viewer.