Ignore:
Timestamp:
Dec 9, 2013, 5:34:37 PM (7 years ago)
Author:
mistic100
Message:

update for 2.6

File:
1 edited

Legend:

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

    r24347 r25872  
    88{
    99  global $tokens, $page, $conf;
    10  
     10
    1111  if ($tokens[0] == 'contact')
    1212  {
    13     add_event_handler('loc_begin_page_header', 'contact_form_header');
    14    
    1513    $page['section'] = 'contact';
     14    $page['title'] = l10n('Contact');
     15    $page['body_id'] = 'theContactPage';
     16    $page['is_external'] = true;
    1617    $page['is_homepage'] = false;
    17    
    18     $page['title'] = l10n('Contact');
    19     $page['section_title'] = $page['section_title'] = '<a href="'.get_absolute_root_url().'">'.l10n('Home').'</a>'.$conf['level_separator'].'<a href="'.CONTACT_FORM_PUBLIC.'">'.l10n('Contact').'</a>'; 
    20   }
    21 }
    22 function contact_form_header()
     18
     19    $page['section_title'] = '<a href="'.get_absolute_root_url().'">'.l10n('Home').'</a>'.$conf['level_separator'].'<a href="'.CONTACT_FORM_PUBLIC.'">'.l10n('Contact').'</a>';
     20  }
     21}
     22
     23/**
     24 * contact page
     25 */
     26function contact_form_page()
    2327{
    2428  global $page;
    25   $page['body_id'] = 'theContactPage';
    26 }
    27 
    28 /**
    29  * contact page
    30  */
    31 function contact_form_page()
    32 {
    33   global $page;
    3429
    3530  if (isset($page['section']) and $page['section'] == 'contact')
    3631  {
    37     include(CONTACT_FORM_PATH . '/include/contact_form.inc.php');
    38   }
    39 }
    40 
    41 /** 
    42  * public menu link 
     32    include(CONTACT_FORM_PATH . 'include/contact_form.inc.php');
     33  }
     34}
     35
     36/**
     37 * public menu link
    4338 */
    4439function contact_form_applymenu($menu_ref_arr)
    4540{
    4641  global $conf;
    47  
    48   if ( !$conf['ContactForm']['cf_menu_link'] ) return;
    49   if ( !is_classic_user() and !$conf['ContactForm']['cf_allow_guest'] ) return;
    50   if ( !$conf['ContactForm']['cf_ready'] ) return;
     42
     43  if (!$conf['ContactForm']['cf_menu_link']) return;
     44  if (!is_classic_user() and !$conf['ContactForm']['cf_allow_guest']) return;
     45  if (!$conf['ContactForm_ready']) return;
    5146
    5247  $menu = &$menu_ref_arr[0];
    5348  if (($block = $menu->get_block('mbMenu')) != null)
    5449  {
    55     array_push($block->data, array(
     50    $block->data[] = array(
    5651      'URL' => CONTACT_FORM_PUBLIC,
    5752      'NAME' => l10n('Contact'),
    58     ));
    59   }
    60 }
    61 
    62 /**
    63  * change contact on link on footer
     53      );
     54  }
     55}
     56
     57/**
     58 * change contact link in footer
    6459 */
    6560function contact_form_footer_link($content, &$smarty)
    6661{
    6762  $search = '<a href="mailto:{$CONTACT_MAIL}?subject={\'A comment on your site\'|@translate|@escape:url}">';
    68   $replace = '<a href="'.CONTACT_FORM_PUBLIC.'">';
     63  $replace = '<a href="{$CONTACT_FORM_PUBLIC}">';
    6964  return str_replace($search, $replace, $content);
    7065}
    7166
    7267/**
     68 * change contact link in mail footer
     69 */
     70function contact_form_mail_template($cache_key, $content_type)
     71{
     72  global $conf_mail;
     73
     74  $template = &$conf_mail[$cache_key]['theme'];
     75  $template->assign('CONTACT_FORM_PUBLIC', CONTACT_FORM_PUBLIC);
     76
     77  if ($content_type == 'text/html')
     78  {
     79    $template->set_prefilter('mail_footer', 'contact_form_mail_template_html');
     80  }
     81  else
     82  {
     83    $template->set_prefilter('mail_footer', 'contact_form_mail_template_plain');
     84  }
     85}
     86function contact_form_mail_template_html($content)
     87{
     88  return str_replace(
     89    'mailto:{$CONTACT_MAIL}?subject={\'A comment on your site\'|translate|escape:url}',
     90    '{$CONTACT_FORM_PUBLIC}',
     91    $content
     92    );
     93}
     94function contact_form_mail_template_plain($content)
     95{
     96  return str_replace(
     97    '{$CONTACT_MAIL}',
     98    '{$CONTACT_FORM_PUBLIC}',
     99    $content
     100    );
     101}
     102
     103/**
    73104 * init emails list
    74105 */
     
    76107{
    77108  global $conf;
    78  
     109
    79110  $query = '
    80111SELECT
     
    89120;';
    90121  $result = pwg_query($query);
    91  
     122
    92123  $emails = array();
    93124  while ($row = pwg_db_fetch_assoc($result))
    94125  {
    95     array_push($emails, array(
     126    $emails[] = array(
    96127      'name' => $row['username'],
    97128      'email' => $row['email'],
    98129      'active' => 'true',
    99       ));
    100   }
    101  
     130      );
     131  }
     132
    102133  mass_inserts(
    103134    CONTACT_FORM_TABLE,
     
    105136    $emails
    106137    );
    107  
     138
    108139  $conf['ContactForm']['cf_must_initialize'] = false;
    109140  conf_update_param('ContactForm', serialize($conf['ContactForm']));
     
    116147function send_contact_form(&$comm, $key)
    117148{
    118   global $conf, $page, $template, $conf_mail;
    119  
    120   if (!isset($conf_mail))
    121   {
    122     $conf_mail = get_mail_configuration();
    123   }
    124  
     149  global $conf, $page, $template;
     150
    125151  $query = '
    126152SELECT DISTINCT group_name
     
    129155;';
    130156  $groups = array_from_query($query, 'group_name');
    131  
     157
    132158  $comm = array_merge($comm,
    133159    array(
     
    138164
    139165  $comment_action='validate';
    140  
     166
    141167  // check key
    142168  if (!verify_ephemeral_key(@$key))
     
    146172
    147173  // check author
    148   if ( $conf['ContactForm']['cf_mandatory_name'] and empty($comm['author']) )
    149   {
    150     array_push($page['errors'], l10n('Please enter a name'));
    151     $comment_action='reject';
    152   }
    153  
     174  if ($conf['ContactForm']['cf_mandatory_name'] and empty($comm['author']))
     175  {
     176    $page['errors'][] = l10n('Please enter a name');
     177    $comment_action='reject';
     178  }
     179
    154180  // check email
    155   if ( $conf['ContactForm']['cf_mandatory_mail'] and empty($comm['email']) )
    156   {
    157     array_push($page['errors'], l10n('Please enter an e-mail'));
    158     $comment_action='reject';
    159   }
    160   else if ( !empty($comm['email']) and !check_email_validity($comm['email']) )
    161   {
    162     array_push($page['errors'], l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)'));
     181  if ($conf['ContactForm']['cf_mandatory_mail'] and empty($comm['email']))
     182  {
     183    $page['errors'][] = l10n('Please enter an e-mail');
     184    $comment_action='reject';
     185  }
     186  else if (!empty($comm['email']) and !email_check_format($comm['email']))
     187  {
     188    $page['errors'][] = l10n('mail address must be like xxx@yyy.eee (example : jack@altern.org)');
    163189    $comment_action='reject';
    164190  }
     
    167193  if (empty($comm['subject']))
    168194  {
    169     array_push($page['errors'], l10n('Please enter a subject'));
     195    $page['errors'][] = l10n('Please enter a subject');
    170196    $comment_action='reject';
    171197  }
    172198  else if (strlen($comm['subject']) > 100)
    173199  {
    174     array_push($page['errors'], sprintf(l10n('%s must not be more than %d characters long'), l10n('Subject'), 100));
    175     $comment_action='reject';
    176   }
    177  
     200    $page['errors'][] = sprintf(l10n('%s must not be more than %d characters long'), l10n('Subject'), 100);
     201    $comment_action='reject';
     202  }
     203
    178204  // check group
    179   if ( count($groups) > 1 and $comm['group'] == -1 )
     205  if (count($groups) > 1 and $comm['group'] == -1)
    180206  {
    181207    $comm['group'] = true;
    182     array_push($page['errors'], l10n('Please choose a category'));
    183     $comment_action='reject';
    184   }
    185  
     208    $page['errors'][] = l10n('Please choose a category');
     209    $comment_action='reject';
     210  }
     211
    186212  // check content
    187213  if (empty($comm['content']))
    188214  {
    189     array_push($page['errors'], l10n('Please enter a message'));
     215    $page['errors'][] = l10n('Please enter a message');
    190216    $comment_action='reject';
    191217  }
    192218  else if (strlen($comm['subject']) > 2000)
    193219  {
    194     array_push($page['errors'], sprintf(l10n('%s must not be more than %d characters long'), l10n('Message'), 2000));
    195     $comment_action='reject';
    196   }
    197  
     220    $page['errors'][] = sprintf(l10n('%s must not be more than %d characters long'), l10n('Message'), 2000);
     221    $comment_action='reject';
     222  }
     223
    198224  include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
    199225  include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
    200  
     226
    201227  add_event_handler('contact_form_check', 'user_comment_check',
    202228    EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
    203  
     229
    204230  // perform more spam check
    205231  $comment_action = trigger_event('contact_form_check', $comment_action, $comm);
    206  
     232
    207233  // get admin emails
    208234  $emails = get_contact_emails($comm['group']);
    209235  if (!count($emails))
    210236  {
    211     array_push($page['errors'], l10n('Error while sending e-mail'));
     237    $page['errors'][] = l10n('Error while sending e-mail');
    212238    $comment_action='reject';
    213239  }
     
    215241  if ($comment_action == 'validate')
    216242  {
    217     // format subject
    218243    $prefix = str_replace('%gallery_title%', $conf['gallery_title'], $conf['ContactForm']['cf_subject_prefix']);
    219     $subject = '['.$prefix.'] '.$comm['subject'];
    220     $subject = trim(preg_replace('#[\n\r]+#s', '', $subject));
    221     $subject = encode_mime_header($subject);
    222    
    223     // format content
    224     $comm['content'] = trigger_event('render_contact_content', $comm['content']);
    225     if ($conf['ContactForm']['cf_mail_type'] == 'text/html')
     244
     245    $from = $Cc = null;
     246    if (!empty($comm['email']))
    226247    {
    227       $comm['content'] = nl2br($comm['content']);
     248      $from = array(
     249        'name' => $comm['author'],
     250        'email' => $comm['email'],
     251        );
     252      if ($comm['send_copy'])
     253      {
     254        $Cc = $from;
     255      }
    228256    }
    229    
    230     // format expeditor
    231     if (empty($comm['email']))
    232     {
    233       $args['from'] = $conf_mail['formated_email_webmaster'];
    234     }
    235     else
    236     {
    237       $args['from'] = format_email($comm['author'], $comm['email']);
    238     }
    239    
    240     // hearders
    241     $headers = 'From: '.$args['from']."\n"; 
    242     $headers.= 'MIME-Version: 1.0'."\n";
    243     $headers.= 'X-Mailer: Piwigo Mailer'."\n";
    244     $headers.= 'Content-Transfer-Encoding: 8bit'."\n";
    245     $headers.= 'Content-Type: '.$conf['ContactForm']['cf_mail_type'].'; charset="'.get_pwg_charset().'";'."\n";
    246    
    247     set_make_full_url();
     257
    248258    switch_lang_to(get_default_language());
    249259    load_language('plugin.lang', CONTACT_FORM_PATH);
    250    
    251     // template
    252     if ($conf['ContactForm']['cf_mail_type'] == 'text/html')
    253     {
    254       $mail_css = file_get_contents(dirname(__FILE__).'/../template/mail/style-'.$conf['ContactForm']['cf_theme'].'.css');
    255       $template->set_filename('contact_mail', dirname(__FILE__).'/../template/mail/content_html.tpl');
    256     }
    257     else
    258     {
    259       $mail_css = null;
    260       $template->set_filename('contact_mail', dirname(__FILE__).'/../template/mail/content_plain.tpl');
    261     }
    262    
    263     $comm['show_ip'] = isset($conf['contact_form_show_ip']) ? $conf['contact_form_show_ip'] : false;
    264    
    265     $template->assign(array(
    266       'cf_prefix' => $prefix,
    267       'contact' => $comm,
    268       'GALLERY_URL' => get_gallery_home_url(),
    269       'PHPWG_URL' => PHPWG_URL,
    270       'CONTACT_MAIL_CSS' => $mail_css,
    271       ));
    272    
    273     // mail content
    274     $content = $template->parse('contact_mail', true);
    275     $content = wordwrap($content, 70, "\n", true);
    276    
    277     // send mail
    278     $result =
    279       trigger_event('send_mail',
    280         false, /* Result */
    281         trigger_event('send_mail_to', implode(',', $emails)),
    282         trigger_event('send_mail_subject', $subject),
    283         trigger_event('send_mail_content', $content),
    284         trigger_event('send_mail_headers', $headers),
    285         $args
     260
     261    $result = pwg_mail(
     262      $emails,
     263      array(
     264        'subject' => '['.$prefix.'] '.$comm['subject'],
     265        'mail_title' => $prefix,
     266        'mail_subtitle' => $comm['subject'],
     267        'content_format' => 'text/html',
     268        'from' => $from,
     269        'Cc' => $Cc,
     270        ),
     271      array(
     272        'filename' => 'mail',
     273        'dirname' => realpath(CONTACT_FORM_PATH . 'template'),
     274        'assign' => array(
     275          'CONTACT' => $comm,
     276          ),
     277        )
    286278      );
    287      
    288     if ( $comm['send_copy'] and !empty($comm['email']) )
    289     {
    290       trigger_event('send_mail',
    291         false, /* Result */
    292         trigger_event('send_mail_to', $args['from']),
    293         trigger_event('send_mail_subject', $subject),
    294         trigger_event('send_mail_content', $content),
    295         trigger_event('send_mail_headers', $headers),
    296         $args
    297       );
    298     }
    299    
    300     unset_make_full_url();
     279
    301280    switch_lang_back();
    302281    load_language('plugin.lang', CONTACT_FORM_PATH);
    303    
     282
    304283    if ($result == false)
    305284    {
    306       array_push($page['errors'], l10n('Error while sending e-mail'));
     285      $page['errors'][] = l10n('Error while sending e-mail');
    307286      $comment_action='reject';
    308287    }
    309288  }
    310  
     289
    311290  return $comment_action;
    312291}
     
    322301{
    323302  global $conf;
    324  
     303
    325304  include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
    326  
     305
    327306  $where = '1=1';
    328307  if ($group!==true)
     
    337316    }
    338317  }
    339  
     318
    340319  $query = '
    341 SELECT *
     320SELECT name, email
    342321  FROM '. CONTACT_FORM_TABLE .'
    343   WHERE 
     322  WHERE
    344323    '.$where.'
    345324    AND active = "true"
    346325  ORDER BY name ASC
    347326';
    348   $result = pwg_query($query);
    349  
    350   $emails = array();
    351   while ($data = pwg_db_fetch_assoc($result))
    352   {
    353     array_push($emails, format_email($data['name'], $data['email']));
    354   }
    355  
     327  $emails = array_from_query($query);
     328
    356329  return $emails;
    357330}
    358 
    359 
    360 /**
    361  * check if email is valid
    362  */
    363 function check_email_validity($mail_address)
    364 {
    365   if (function_exists('email_check_format'))
    366   {
    367     return email_check_format($mail_address); // Piwigo 2.5
    368   }
    369   else if (version_compare(PHP_VERSION, '5.2.0') >= 0)
    370   {
    371     return filter_var($mail_address, FILTER_VALIDATE_EMAIL)!==false;
    372   }
    373   else
    374   {
    375     $atom   = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]';   // before  arobase
    376     $domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // domain name
    377     $regex = '/^' . $atom . '+' . '(\.' . $atom . '+)*' . '@' . '(' . $domain . '{1,63}\.)+' . $domain . '{2,63}$/i';
    378 
    379     return (bool)preg_match($regex, $mail_address);
    380   }
    381 }
    382 
    383 ?>
Note: See TracChangeset for help on using the changeset viewer.