1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16: $plugin_is_filter = 5 | FEATURE_PLUGIN;
17: $plugin_description = gettext("Prints an e-mail contact so that visitors may e-mail the site administrator.");
18: $plugin_author = "Malte Müller (acrylian), Stephen Billard (sbillard)";
19:
20: $option_interface = 'contactformOptions';
21:
22: $_zp_conf_vars['special_pages']['contact'] = array('define' => '_CONTACT_', 'rewrite' => getOption('contactform_rewrite'), 'option' => 'contactform_rewrite', 'default' => '_PAGE_/contact');
23: $_zp_conf_vars['special_pages'][] = array('definition' => '%CONTACT%', 'rewrite' => '_CONTACT_');
24: $_zp_conf_vars['special_pages'][] = array('define' => false, 'rewrite' => '%CONTACT%', 'rule' => '^%REWRITE%/*$ index.php?p=contact [L,QSA]');
25:
26: 27: 28: 29:
30: class contactformOptions {
31:
32: function __construct() {
33: global $_zp_authority;
34:
35: if (OFFSET_PATH == 2 && !getOption('contactform_mailaddress')) {
36: purgeOption('contactform_mailaddress');
37: }
38: setOptionDefault('contactform_rewrite', '_PAGE_/contact');
39: gettext($str = '<p>Fields with <strong>*</strong> are required. HTML or any other code is not allowed.</p>');
40: setOptionDefault('contactform_introtext', getAllTranslations($str));
41: gettext($str = '<p>Please confirm that you really want to send this email. Thanks.</p>');
42: setOptionDefault('contactform_confirmtext', getAllTranslations($str));
43: gettext($str = '<p>Thanks for your message.</p>');
44: setOptionDefault('contactform_thankstext', getAllTranslations($str));
45: gettext($str = 'Send another message.');
46: setOptionDefault('contactform_newmessagelink', getAllTranslations($str));
47: setOptionDefault('contactform_title', "show");
48: setOptionDefault('contactform_name', "required");
49: setOptionDefault('contactform_company', "show");
50: setOptionDefault('contactform_street', "show");
51: setOptionDefault('contactform_city', "show");
52: setOptionDefault('contactform_state', "show");
53: setOptionDefault('contactform_postal', "show");
54: setOptionDefault('contactform_country', "show");
55: setOptionDefault('contactform_email', "required");
56: setOptionDefault('contactform_website', "show");
57: setOptionDefault('contactform_phone', "show");
58: setOptionDefault('contactform_captcha', 0);
59: setOptionDefault('contactform_confirm', 1);
60: setOptionDefault('contactform_sendcopy', 0);
61: gettext($str = '<p>A copy of your e-mail will automatically be sent to the address you provided for your own records.</p>');
62: setOptionDefault('contactform_sendcopy_text', getAllTranslations($str));
63: $mailings = $_zp_authority->getAdminEmail();
64: $email_list = '';
65: foreach ($mailings as $email) {
66: $email_list .= ';' . $email;
67: }
68: if ($email_list) {
69: setOptionDefault('contactform_mailaddress', substr($email_list, 1));
70: }
71: }
72:
73: function getOptionsSupported() {
74: global $_zp_captcha;
75: $mailinglist = explode(';', getOption("contactform_mailaddress"));
76: array_walk($mailinglist, 'contactformOptions::trim_value');
77: setOption('contactform_mailaddress', implode(';', $mailinglist));
78: $list = array(gettext("required") => "required", gettext("show") => "show", gettext("omitted") => "omitted");
79: $mailfieldinstruction = gettext("Set if the <code>%s</code> field should be required, just shown or omitted");
80: $options = array(
81: gettext('Intro text') => array('key' => 'contactform_introtext', 'type' => OPTION_TYPE_TEXTAREA,
82: 'order' => 13,
83: 'desc' => gettext("The intro text for your contact form")),
84: gettext('Confirm text') => array('key' => 'contactform_confirmtext', 'type' => OPTION_TYPE_TEXTAREA,
85: 'order' => 14,
86: 'desc' => gettext("The text that asks the visitor to confirm that he really wants to send the message.")),
87: gettext('Thanks text') => array('key' => 'contactform_thankstext', 'type' => OPTION_TYPE_TEXTAREA,
88: 'order' => 15,
89: 'desc' => gettext("The text that is shown after a message has been confirmed and sent.")),
90: gettext('New message link text') => array('key' => 'contactform_newmessagelink', 'type' => OPTION_TYPE_TEXTAREA,
91: 'order' => 16,
92: 'desc' => gettext("The text for the link after the thanks text to return to the contact page to send another message.")),
93: gettext('Require confirmation') => array('key' => 'contactform_confirm', 'type' => OPTION_TYPE_CHECKBOX,
94: 'order' => 0.1,
95: 'desc' => gettext("If checked, a confirmation form will be presented before sending the contact message.")),
96: gettext('Send copy') => array('key' => 'contactform_sendcopy', 'type' => OPTION_TYPE_CHECKBOX,
97: 'order' => 0.3,
98: 'desc' => gettext("If checked, a copy of the message will be sent to the address provided. <p class='notebox'><strong>Caution: </strong> If you check this option it is strongly recommend to use Captcha and the confirmation option. Be aware that someone could misuse the e-mail address entered for spamming with this form and that in some countries’ jurisdictions(e.g. most European countries) you may be made responsible for this then!</p>")),
99: gettext('Send copy note text') => array('key' => 'contactform_sendcopy_text', 'type' => OPTION_TYPE_TEXTAREA,
100: 'order' => 0.2,
101: 'desc' => gettext("The text for the note about sending a copy to the address provided in case that option is set.")),
102: gettext('Contact recipients') => array('key' => 'contactform_mailaddress', 'type' => OPTION_TYPE_TEXTBOX,
103: 'order' => 17,
104: 'desc' => gettext("The e-mail address the messages should be sent to. Enter one or more address separated by semicolons.")),
105: gettext('Title') => array('key' => 'contactform_title', 'type' => OPTION_TYPE_RADIO, 'buttons' => $list,
106: 'order' => 1,
107: 'desc' => sprintf($mailfieldinstruction, gettext("Title"))),
108: gettext('Name') => array('key' => 'contactform_name', 'type' => OPTION_TYPE_RADIO, 'buttons' => $list,
109: 'order' => 2,
110: 'desc' => sprintf($mailfieldinstruction, gettext("Name"))),
111: gettext('Company') => array('key' => 'contactform_company', 'type' => OPTION_TYPE_RADIO, 'buttons' => $list,
112: 'order' => 3,
113: 'desc' => sprintf($mailfieldinstruction, gettext("Company"))),
114: gettext('Street') => array('key' => 'contactform_street', 'type' => OPTION_TYPE_RADIO, 'buttons' => $list,
115: 'order' => 4,
116: 'desc' => sprintf($mailfieldinstruction, gettext("Street"))),
117: gettext('City') => array('key' => 'contactform_city', 'type' => OPTION_TYPE_RADIO, 'buttons' => $list,
118: 'order' => 5,
119: 'desc' => sprintf($mailfieldinstruction, gettext("City"))),
120: gettext('State') => array('key' => 'contactform_state', 'type' => OPTION_TYPE_RADIO, 'buttons' => $list,
121: 'order' => 5.1,
122: 'desc' => sprintf($mailfieldinstruction, gettext("State"))),
123: gettext('Postal code') => array('key' => 'contactform_postal', 'type' => OPTION_TYPE_RADIO, 'buttons' => $list,
124: 'order' => 5.2,
125: 'desc' => sprintf($mailfieldinstruction, gettext("Postal code"))),
126: gettext('Country') => array('key' => 'contactform_country', 'type' => OPTION_TYPE_RADIO, 'buttons' => $list,
127: 'order' => 6,
128: 'desc' => sprintf($mailfieldinstruction, gettext("Country"))),
129: gettext('E-mail') => array('key' => 'contactform_email', 'type' => OPTION_TYPE_RADIO, 'buttons' => $list,
130: 'order' => 7,
131: 'desc' => sprintf($mailfieldinstruction, gettext("E-mail"))),
132: gettext('Website') => array('key' => 'contactform_website', 'type' => OPTION_TYPE_RADIO, 'buttons' => $list,
133: 'order' => 8,
134: 'desc' => sprintf($mailfieldinstruction, gettext("Website"))),
135: gettext('CAPTCHA') => array('key' => 'contactform_captcha', 'type' => OPTION_TYPE_CHECKBOX,
136: 'order' => 9,
137: 'desc' => ($_zp_captcha->name) ? gettext('If checked, the form will include a Captcha verification.') : '<span class="notebox">' . gettext('No captcha handler is enabled.') . '</span>'),
138: gettext('Phone') => array('key' => 'contactform_phone', 'type' => OPTION_TYPE_RADIO, 'buttons' => $list,
139: 'order' => 10,
140: 'desc' => sprintf($mailfieldinstruction, gettext("Phone number")))
141: );
142: return $options;
143: }
144:
145: 146: 147: 148: 149:
150: static function trim_value(&$value) {
151: $value = trim($value);
152: }
153:
154: }
155:
156: 157: 158: 159: 160: 161: 162:
163: function getField($field, $level = 3) {
164: if (isset($_POST[$field])) {
165: return sanitize($_POST[$field], $level);
166: } else {
167: return '';
168: }
169: }
170:
171: 172: 173: 174: 175: 176:
177: function printContactForm($subject_override = '') {
178: global $_zp_UTF8, $_zp_captcha, $_processing_post, $_zp_current_admin_obj;
179: $error = array();
180: if (isset($_POST['sendmail'])) {
181: $mailcontent = array();
182: $mailcontent['title'] = getField('title');
183: $mailcontent['name'] = getField('name');
184: $mailcontent['honeypot'] = getField('username');
185: $mailcontent['company'] = getField('company');
186: $mailcontent['street'] = getField('street');
187: $mailcontent['city'] = getField('city');
188: $mailcontent['state'] = getField('state');
189: $mailcontent['postal'] = getField('postal');
190: $mailcontent['country'] = getField('country');
191: $mailcontent['email'] = getField('email');
192: $mailcontent['website'] = getField('website');
193: $mailcontent['phone'] = getField('phone');
194: $mailcontent['subject'] = getField('subject');
195: $mailcontent['message'] = getField('message', 1);
196:
197:
198: if (getOption('contactform_title') == "required" && empty($mailcontent['title'])) {
199: $error[1] = gettext("a title");
200: }
201: if (getOption('contactform_name') == "required" && empty($mailcontent['name'])) {
202: $error[2] = gettext("a name");
203: }
204: if (getOption('contactform_company') == "required" && empty($mailcontent['company'])) {
205: $error[3] = gettext("a company");
206: }
207: if (getOption('contactform_street') == "required" && empty($mailcontent['street'])) {
208: $error[4] = gettext("a street");
209: }
210: if (getOption('contactform_city') == "required" && empty($mailcontent['city'])) {
211: $error[5] = gettext("a city");
212: }
213: if (getOption('contactform_state') == "required" && empty($mailcontent['state'])) {
214: $error[5] = gettext("a state");
215: }
216: if (getOption('contactform_postal') == "required" && empty($mailcontent['postal'])) {
217: $error[5] = gettext("a postal code");
218: }
219: if (getOption('contactform_country') == "required" && empty($mailcontent['country'])) {
220: $error[6] = gettext("a country");
221: }
222: if (getOption('contactform_email') == "required" && (empty($mailcontent['email']) || !is_valid_email_zp($mailcontent['email']))) {
223: $error[7] = gettext("a valid email address");
224: }
225: if (getOption('contactform_website') == "required" && empty($mailcontent['website'])) {
226: $error[8] = gettext('a website');
227: } else {
228: if (!empty($mailcontent['website'])) {
229: if (substr($mailcontent['website'], 0, 7) != "http: //") {
230: $mailcontent['website'] = "http://" . $mailcontent['website'];
231: }
232: }
233: }
234: if (getOption("contactform_phone") == "required" && empty($mailcontent['phone'])) {
235: $error[9] = gettext("a phone number");
236: }
237: if (empty($mailcontent['subject'])) {
238: $error[10] = gettext("a subject");
239: }
240: if (empty($mailcontent['message'])) {
241: $error[11] = gettext("a message");
242: }
243:
244:
245: if (getOption("contactform_captcha")) {
246: $code_ok = trim(sanitize(isset($_POST['code_h']) ? $_POST['code_h'] : NULL));
247: $code = trim(sanitize(isset($_POST['code']) ? $_POST['code'] : NULL));
248: if (!$_zp_captcha->checkCaptcha($code, $code_ok)) {
249: $error[5] = gettext("the correct CAPTCHA verification code");
250: }
251: }
252:
253:
254: if (count($error) != 0) {
255: ?>
256: <div class="errorbox">
257: <h2>
258: <?php
259: $err = $error;
260: switch (count($err)) {
261: case 1:
262: printf(gettext('Please enter %s. Thanks.'), array_shift($err));
263: break;
264: case 2:
265: printf(gettext('Please enter %1$s and %2$s. Thanks.'), array_shift($err), array_shift($err));
266: break;
267: default:
268: $list = '<ul class="errorlist">';
269: foreach ($err as $item) {
270: $list .= '<li>' . $item . '</li>';
271: }
272: $list .= '</ul>';
273: printf(gettext('Please enter: %sThanks.'), $list);
274: break;
275: }
276: ?>
277: </h2>
278: </div>
279: <?php
280: } else {
281: $mailaddress = $mailcontent['email'];
282: $name = $mailcontent['name'];
283: $subject = $mailcontent['subject'] . " (" . getBareGalleryTitle() . ")";
284: $message = '';
285: if (!empty($mailcontent['title'])) {
286: $message .= $mailcontent['title'] . "\n";
287: }
288: if (!empty($mailcontent['name'])) {
289: $message .= $mailcontent['name'] . "\n";
290: }
291: if (!empty($mailcontent['email'])) {
292: $message .= $mailcontent['email'] . "\n";
293: }
294: if (!empty($mailcontent['company'])) {
295: $message .= $mailcontent['company'] . "\n";
296: }
297: if (!empty($mailcontent['street'])) {
298: $message .= $mailcontent['street'] . "\n";
299: }
300: if (!empty($mailcontent['city'])) {
301: $message .= $mailcontent['city'] . "\n";
302: }
303: if (!empty($mailcontent['state'])) {
304: $message .= $mailcontent['state'] . "\n";
305: }
306: if (!empty($mailcontent['postal'])) {
307: $message .= $mailcontent['postal'] . "\n";
308: }
309: if (!empty($mailcontent['country'])) {
310: $message .= $mailcontent['country'] . "\n";
311: }
312: if (!empty($mailcontent['phone'])) {
313: $message .= $mailcontent['phone'] . "\n";
314: }
315: if (!empty($mailcontent['website'])) {
316: $message .= $mailcontent['website'] . "\n";
317: }
318: $message .= "\n\n" . $mailcontent['message'];
319: $message .= "\n\n";
320:
321: if (getOption('contactform_confirm')) {
322: echo get_language_string(getOption("contactform_confirmtext"));
323: if (getOption('contactform_sendcopy')) {
324: echo get_language_string(getOption("contactform_sendcopy_text"));
325: }
326: ?>
327: <div>
328: <?PHP
329: $_processing_post = true;
330: include(getPlugin('contact_form/form.php', true));
331: ?>
332: <form id="confirm" action="<?php echo html_encode(getRequestURI()); ?>" method="post" accept-charset="UTF-8" style="float: left">
333: <input type="hidden" id="confirm" name="confirm" value="confirm" />
334: <input type="hidden" id="name" name="name" value="<?php echo html_encode($name); ?>" />
335: <input type="hidden" id="subject" name="subject" value="<?php echo html_encode($subject); ?>" />
336: <input type="hidden" id="message" name="message" value="<?php echo html_encode($message); ?>" />
337: <input type="hidden" id="mailaddress" name="mailaddress" value="<?php echo html_encode($mailaddress); ?>" />
338: <input type="text" id="username" name="username" value="<?php echo html_encode($mailcontent['honeypot']); ?>" style="display: none" />
339: <input type="submit" value="<?php echo gettext("Confirm"); ?>" />
340: </form>
341: <form id="discard" action="<?php echo html_encode(getRequestURI()); ?>" method="post" accept-charset="UTF-8">
342: <input type="hidden" id="discard" name="discard" value="discard" />
343: <input type="submit" value="<?php echo gettext("Discard"); ?>" />
344: </form>
345: </div>
346: <?php
347: return;
348: } else {
349:
350: $_POST['confirm'] = true;
351: $_POST['subject'] = $subject;
352: $_POST['message'] = $message;
353: $_POST['mailaddress'] = $mailaddress;
354: $_POST['name'] = $name;
355: }
356: }
357: }
358: if (isset($_POST['confirm'])) {
359: $subject = sanitize($_POST['subject']);
360: $message = sanitize($_POST['message'], 1);
361: $mailaddress = sanitize($_POST['mailaddress']);
362: $honeypot = sanitize($_POST['username']);
363: $name = sanitize($_POST['name']);
364: $mailinglist = explode(';', getOption("contactform_mailaddress"));
365: if (getOption('contactform_sendcopy')) {
366: $sendcopy = array($name => $mailaddress);
367: } else {
368: $sendcopy = NULL;
369: }
370:
371: $err_msg = false;
372: if (empty($honeypot)) {
373: $err_msg = zp_mail($subject, $message, $mailinglist, $sendcopy, NULL, array($name => $mailaddress));
374: }
375: if ($err_msg) {
376: $msgs = explode('.', $err_msg);
377: unset($msgs[0]);
378: unset($msgs[count($msgs)]);
379: ?>
380: <div class="errorbox">
381: <strong><?php echo ngettext('Error sending mail:', 'Errors sending mail:', count($msgs)); ?></strong>
382: <ul class="errorlist">
383: <?php
384: foreach ($msgs as $line) {
385: echo '<li>' . trim($line) . '</li>';
386: }
387: ?>
388: </ul>
389: </div>
390: <?php
391: } else {
392: echo get_language_string(getOption("contactform_thankstext"));
393: }
394: echo '<p><a href="?again">' . get_language_string(getOption('contactform_newmessagelink')) . '</a></p>';
395: } else {
396: if (count($error) <= 0) {
397: if (zp_loggedin()) {
398: $mailcontent = array('title' => '', 'name' => $_zp_current_admin_obj->getName(), 'company' => '', 'street' => '', 'city' => '', 'state' => '',
399: 'country' => '', 'postal' => '', 'email' => $_zp_current_admin_obj->getEmail(), 'website' => '', 'phone' => '',
400: 'subject' => $subject_override, 'message' => '', 'honeypot' => '');
401: if (extensionEnabled('comment_form')) {
402: $address = getSerializedArray($_zp_current_admin_obj->getCustomData());
403: foreach ($address as $key => $field) {
404: $mailcontent[$key] = $field;
405: }
406: }
407: } else {
408: $mailcontent = array('title' => '', 'name' => '', 'company' => '', 'street' => '', 'city' => '', 'st ate' => '', 'country' => '', 'email' => '',
409: 'postal' => '', 'website' => '', 'phone' => '', 'subject' => $subject_override, 'message' => '', 'honeypot' => '');
410: }
411: }
412: echo get_language_string(getOption("contactform_introtext"));
413: if (getOption('contactform_sendcopy'))
414: echo get_language_string(getOption("contactform_sendcopy_text"));
415: $_processing_post = false;
416: include(getPlugin('contact_form/form.php', true));
417: }
418: }
419:
420: 421: 422: 423: 424: 425: 426: 427:
428: function showOrNotShowField($option) {
429: return $option == "required" || $option == "show";
430: }
431:
432: 433: 434: 435: 436: 437: 438:
439: function checkRequiredField($option) {
440: global $_processing_post;
441: if ($option == "required" && !$_processing_post) {
442: return "<strong>*</strong>";
443: } else {
444: return "";
445: }
446: }
447: ?>