source: extensions/ContactForm/include/contact_form.inc.php @ 17483

Revision 17483, 2.4 KB checked in by mistic100, 7 years ago (diff)

entirely rewrite the plugin

  • send mail in html format (configurable to plain)
  • fully configurable email list
  • more...
Line 
1<?php
2if (!defined('CONTACT_FORM_PATH')) die('Hacking attempt!');
3
4global $template, $user, $conf, $page, $pwg_loaded_plugins;
5
6if ( (!is_classic_user() and !$conf['ContactForm']['cf_allow_guest']) or !count(get_contact_emails()) )
7{
8  redirect(get_root_url());
9}
10
11// +-----------------------------------------------------------------------+
12// |                                send email                             |
13// +-----------------------------------------------------------------------+
14if (isset($_POST['send_mail']))
15{
16  $contact = array(
17    'author' => trim($_POST['author']),
18    'email' => trim($_POST['email']),
19    'subject' =>   trim($_POST['subject']),
20    'content' =>   $_POST['content'],
21   );
22 
23  $comment_action = send_contact_form($contact, @$_POST['key']);
24
25  switch ($comment_action)
26  {
27    case 'validate':
28      array_push($page['infos'], l10n('E-mail sent successfully'));
29      unset($contact);
30      break;
31    case 'moderate':
32    case 'reject':
33      break;
34    default:
35      trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
36  }
37}
38
39// +-----------------------------------------------------------------------+
40// |                                template                               |
41// +-----------------------------------------------------------------------+
42if (is_classic_user())
43{
44  if (!isset($contact))
45  {
46    $contact = array(
47      'author' => $user['username'],
48      'email' => $user['email'],
49      'subject' => l10n($conf['ContactForm']['cf_default_subject']),
50      'content' => null,
51      );
52  }
53  $contact['is_logged'] = true;
54}
55if ($conf['ContactForm']['cf_mandatory_mail'])
56{
57  $contact['mandatory_mail'] = true;
58}
59if ($conf['ContactForm']['cf_mandatory_name'])
60{
61  $contact['mandatory_name'] = true;
62}
63
64if (!empty($pwg_loaded_plugins['ExtendedDescription']))
65{
66  add_event_handler('render_contact_form', 'get_user_language_desc');
67}
68
69$template->assign(array(
70  'contact' => $contact,
71  'ContactForm_before' => trigger_event('render_contact_form', $conf['ContactForm_before']),
72  'ContactForm_after' => trigger_event('render_contact_form', $conf['ContactForm_after']),
73  'KEY' => get_ephemeral_key(3),
74  'CONTACT_FORM_PATH' => CONTACT_FORM_PATH,
75  'CONTACT_FORM_ABS_PATH'=> dirname(__FILE__).'/../',
76  'F_ACTION' => CONTACT_FORM_PUBLIC,
77  ));
78
79$template->set_filename('index', dirname(__FILE__).'/../template/contact_form.tpl');
80
81?>
Note: See TracBrowser for help on using the repository browser.