Ignore:
Timestamp:
Mar 7, 2013, 10:06:42 PM (11 years ago)
Author:
mistic100
Message:

too many changes

File:
1 edited

Legend:

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

    r17921 r21340  
    157157 
    158158  // check email
    159   if ( !empty($email) and !is_valid_email($email) )
     159  if ( !empty($email) and !email_check_format($email) )
    160160  {
    161161    array_push($page['errors'], l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)'));
     
    172172  }
    173173 
    174   // search if already registered (can use ODKU because we want to get the id of inserted OR updated row)
     174  // search if already registered (can't use ODKU because we want to get the id of inserted OR updated row)
    175175  $query = '
    176176SELECT id
     
    213213 
    214214  // notify admins
    215   if ( pwg_db_changes(null) != 0 and $conf['Subscribe_to_Comments']['notify_admin_on_subscribe'] )
     215  if ( pwg_db_changes() != 0 and $conf['Subscribe_to_Comments']['notify_admin_on_subscribe'] )
    216216  {
    217217    stc_mail_notification_admins($email, $type, $element_id, $inserted_id);
     
    219219 
    220220  // send validation mail
    221   if ( is_a_guest() and pwg_db_changes(null) != 0 )
     221  if ( is_a_guest() and pwg_db_changes() != 0 )
    222222  {
    223223    set_make_full_url();
     
    267267  }
    268268  // just display confirmation message
    269   else if (pwg_db_changes(null) != 0)
     269  else if (pwg_db_changes() != 0)
    270270  {
    271271    array_push($page['infos'], l10n('You have been added to the list of subscribers.'));
     
    285285function un_subscribe_to_comments($email, $id)
    286286
    287   if (empty($id))
    288   {
    289     trigger_error('un_subscribe_to_comment: missing id', E_USER_WARNING);
     287  if ( !empty($email) and !email_check_format($email) )
     288  {
     289    trigger_error('un_subscribe_to_comment: bad email', E_USER_WARNING);
     290    return false;
     291  }
     292 
     293  if (!preg_match('#^[0-9]+$#', $id))
     294  {
     295    trigger_error('un_subscribe_to_comment: bad id', E_USER_WARNING);
    290296    return false;
    291297  }
     
    308314  WHERE
    309315    email = "'.pwg_db_real_escape_string($email).'"
    310     AND id = "'.pwg_db_real_escape_string($id).'"
     316    AND id = '.$id.'
    311317;';
    312318  pwg_query($query);
    313      
    314   if (pwg_db_changes(null) != 0) return true;
    315   return false;
     319 
     320  return (pwg_db_changes() != 0);
    316321}
    317322
     
    325330function validate_subscriptions($email, $id)
    326331{
    327   if (empty($email))
    328   {
    329     trigger_error('validate_subscriptions: missing email', E_USER_WARNING);
    330     return false;
    331   }
    332  
    333   if (empty($id))
    334   {
    335     trigger_error('validate_subscriptions: missing id', E_USER_WARNING);
     332  if (!email_check_format($email))
     333  {
     334    trigger_error('validate_subscriptions: bad email', E_USER_WARNING);
     335    return false;
     336  }
     337 
     338  if (!preg_match('#^[0-9]+$#', $id))
     339  {
     340    trigger_error('validate_subscriptions: bad id', E_USER_WARNING);
    336341    return false;
    337342  }
     
    342347  WHERE
    343348    email = "'.pwg_db_real_escape_string($email).'"
    344     AND id = '.pwg_db_real_escape_string($id).'
     349    AND id = '.$id.'
    345350;';
    346351  pwg_query($query);
    347      
    348   if (pwg_db_changes(null) != 0) return true;
    349   return false;
     352 
     353  return (pwg_db_changes() != 0);
    350354}
    351355
     
    371375  $template->set_filename('stc_mail', dirname(__FILE__).'/../template/mail/admin.tpl');
    372376   
    373   $subject = '['.strip_tags($conf['gallery_title']).'] '.sprintf(l10n('%s has subscribed to comments on'), is_a_guest()?$email:$user['username']);
     377  $subject = '['.strip_tags($conf['gallery_title']).'] '.sprintf(l10n('%s has subscribed to comments on %s.'), is_a_guest()?$email:$user['username'], null);
    374378   
    375379  switch ($type)
     
    401405  $template->assign('STC', array(
    402406    'ELEMENT' => $element['on'],
    403     'USER' => sprintf(l10n('%s has subscribed to comments on'), is_a_guest() ? '<b>'.$email.'</b>' : '<b>'.$user['username'].'</b> ('.$email.')'),
     407    'USER' => is_a_guest() ? '<b>'.$email.'</b>' : '<b>'.$user['username'].'</b> ('.$email.')',
    404408    'GALLERY_TITLE' => $conf['gallery_title'],
    405409    'TECHNICAL' => implode('<br>', $technical_infos),
     
    504508  $headers.= 'MIME-Version: 1.0'."\n";
    505509  $headers.= 'X-Mailer: Piwigo Mailer'."\n";
    506   // $headers.= 'Content-Transfer-Encoding: Quoted-Printable'."\n";
    507510  $headers.= 'Content-Transfer-Encoding: 8bit'."\n";
    508511  $headers.= 'Content-Type: text/html; charset="'.get_pwg_charset().'";'."\n";
     
    523526  $content = $template->parse('stc_mail_header', true) . $content . $template->parse('stc_mail_footer', true);
    524527 
    525   // $content = quoted_printable_encode($content);
    526   $content = wordwrap($content, 70, "\n", true);
     528  $content = wordwrap($content, 70, "\n", false);
    527529
    528530  unset_make_full_url();
     
    687689
    688690/**
    689  * check if mail adress is valid
    690  * @param: string email
    691  * @return: bool
    692  */
    693 if (!function_exists('is_valid_email'))
    694 {
    695   function is_valid_email($mail_address)
    696   {
    697     if (version_compare(PHP_VERSION, '5.2.0') >= 0)
    698     {
    699       return filter_var($mail_address, FILTER_VALIDATE_EMAIL)!==false;
    700     }
    701     else
    702     {
    703       $atom   = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]';   // before  arobase
    704       $domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // domain name
    705       $regex = '/^' . $atom . '+' . '(\.' . $atom . '+)*' . '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}$/i';
    706 
    707       if (!preg_match($regex, $mail_address)) return false;
    708       return true;
    709     }
    710   }
    711 }
    712 
    713 
    714 /**
    715691 * crypt a string using mcrypt extension or
    716692 * http://stackoverflow.com/questions/800922/how-to-encrypt-string-without-mcrypt-library-in-php/802957#802957
Note: See TracChangeset for help on using the changeset viewer.