first shot at reworking plugin system
[diogenes.git] / plugins / MailForm.php
... / ...
CommitLineData
1<?php
2/*
3 * Copyright (C) 2003-2005 Polytechnique.org
4 * http://opensource.polytechnique.org/
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21require_once 'Plugin/Filter.php';
22require_once 'diogenes/diogenes.hermes.inc.php';
23
24/** The MailForm plugin allows you to insert a form to send
25 * an e-mail to a fixed recipient.
26 *
27 * To make use of this plugin, insert {MailForm}in your page
28 * where the mail form should appear.
29 */
30class MailForm extends Diogenes_Plugin_Filter
31{
32 /** Plugin name */
33 var $name = "MailForm";
34
35 /** Plugin description */
36 var $description = "This plugin allows you to insert a form to send an e-mail to a fixed recipient. To make use of this plugin, insert <b>{MailForm}</b> in your page where the mail form should appear.";
37
38
39 /** Constructor.
40 */
41 function MailForm()
42 {
43 $this->declareParam('email', '');
44 $this->declareParam('title', '');
45 $this->declareParam('subject_tag', '[web form]');
46 }
47
48
49 /** Show an instance of the MailForm plugin.
50 */
51 function show()
52 {
53 global $page;
54
55 // get parameters
56 $to_email = $this->getParamValue('email');
57 $form_title = $this->getParamValue('title');
58
59 if (!isvalid_email($to_email)) {
60 return '<p>You must specify a valid e-mail in the "email" parameter to make use of the MailForm plugin.<p>';
61 }
62
63 // get input
64 $action = clean_request('action');
65 $from = clean_request('from');
66
67 $refer = strip_request('refer');
68 if (!$refer)
69 $refer = $_SERVER['HTTP_REFERER'];
70 $message = strip_request('message');
71 $subject = strip_request('subject');
72
73 $showform=0;
74 $output = '';
75 switch($action) {
76 case "mail":
77 if ((!$subject)||(!$message)||(!$from)) {
78 $output .= '<p align="center"><strong>Missing fields !</strong></p>';
79 $showform=1;
80 break;
81 }
82
83 if (!isvalid_email($from)) {
84 $output .= '<p align="center"><strong>Invalid email address !</strong></p>';
85 $showform=1;
86 break;
87 }
88
89 $mymail = new HermesMailer();
90 $mymail->setFrom($from);
91 $mymail->setSubject($this->getParamValue('subject_tag').$subject);
92 $mymail->addTo($to_email);
93 $mymail->setTxtBody($message);
94 $mymail->send();
95
96 $output .= '<p align="center"><strong>Message sent !</strong></p>';
97 if ($refer!="") {
98 $output .= '<p align="center">To return to referring web page click <a href="'.$refer.'">here</a></p>';
99 }
100 break;
101 default:
102 $showform=1;
103 }
104
105 if ($showform) {
106 $output .=
107 '<br/>
108
109 <form action="'.$page->script_uri().'" method="post">
110
111 <table class="light">
112 <tr>
113 <th colspan="2">'.$form_title.'</a></th>
114 </tr>
115 <tr>
116 <td>'.__("from").'</td>
117 <td><input type="text" name="from" size="68" value="'.$from.'" /></td>
118 </tr>
119 <tr>
120 <td>'.__("subject").'</td>
121 <td><input type="text" name="subject" size="68" value="'.$subject.'" /></td>
122 </tr>
123 <tr>
124 <td>'.__("message").'</td>
125 <td><textarea name="message" rows="10" cols="70">'.$message.'</textarea></td>
126 </tr>
127 <tr>
128 <td>&nbsp;</td>
129 <td>
130 <input type="hidden" name="action" value="mail" />
131 <input type="hidden" name="refer" value="'.$refer.'" />
132 <input type="submit" value="'.__("Send").'"/>
133 </td>
134 </tr>
135 </table>
136
137 </form>';
138 }
139 return $output;
140 }
141}
142?>