1b7d9e42e54b7555a636e4c94a9071680bccd601
[atutor.git] / mods / wiki / plugins / action / email_page.php
1 <?
2
3  #  This plug-in will eMail the page to the specified eMail address
4  #  Plug-in written by Alfred Sterphone, III
5
6 #-- text
7 $ewiki_t["en"]["EMAILPAGE"] = "This will e-mail the current page to the specified address.<br />When you are ready, click the \"_{EMAIL_THIS_PAGE}\" button.<hr>";
8 $ewiki_t["en"]["EMAIL_THIS_PAGE"] = "Email this page";
9
10 #-- glue
11 if(function_exists("mail"))
12 {
13     $ewiki_plugins["action"]['emailpage'] = "ewiki_page_wiki_email_page";
14     $ewiki_config["action_links"]["view"]["emailpage"] =  "EMAIL_THIS_PAGE";
15 }
16
17 $ewiki_t["c"]["EWIKIEMAILCSS"] = '
18   <style  TYPE="text/css">
19   <!--
20   body {
21     background-color:#eeeeff;
22     padding:2px;
23   }     
24   
25   H2 {
26     background:#000000;
27     color:#ffffff;
28     border:1px solid #000000;
29   }
30   -->
31   </style>
32   ';
33
34 function isRequestNotSet($email_page,$email_address)
35 {
36     return ( empty($email_page) || empty($email_address) );
37 }
38
39 function checkEmailField($email_page_to,$not_first_time)
40 {
41     if ( empty($email_page_to) && $not_first_time == "1" )
42         return "<p><b>Please enter a valid e-mail address</b>";
43     else
44         return "";
45 }
46
47 function isUserInfoDefined($from_email,$from_name)
48 {
49     return ( !empty($from_email) && !empty($from_name) );
50 }
51
52 function getUserInfo(&$email,&$name)
53 {
54     global $ewiki_uservars;
55     
56     $email = $ewiki_uservars["E-Mail Address"];
57     $name = $ewiki_uservars["Name"];
58 }
59     
60 function htmlFormGenerate($defined,$id,$warning,$from_email,$from_name)
61 {
62     $url = ewiki_script("emailpage", "$id");
63     $info_url = ewiki_script("view","UserInfo");
64     
65     if ($defined)
66     {
67         return(ewiki_make_title($id, $id, 2) . ewiki_t(
68 //--------------------------------------------
69 <<<END
70 _{EMAILPAGE}
71     $warning
72     <p>
73     <form action="$url" method="POST" enctype="multipart/form-data">
74     <p>
75         Your e-mail address: <b><i>$from_email</i></b>.<br />Your name: <b><i>$from_name</i></b><br />These will be included in the e-mail content and used in the "From" header of the e-mail.
76     <p>
77         If this is incorrect, please <a href="$info_url">update your information</a>
78     <p>
79         Email address:<br />
80         <input type="text" name="email_address">
81     <p>
82         Send an additional note to the sender:<br />
83         (Use &lt;br&gt; for a new line if necessary)<br />
84         <textarea rows="5" cols="40" name="email_text"></textarea>
85     <p>
86         <input type="hidden" name="not_first_time" value="1">
87         <input type="submit" name="email_page" value= "_{EMAIL_THIS_PAGE}">
88     </form>
89 END
90 ));
91 //--------------------------------------------
92     }
93     else
94     {
95         return(ewiki_make_title($id, $id, 2) . ewiki_t(
96 //--------------------------------------------
97 <<<END
98 _{EMAILPAGE}
99     <p>
100         <b>Your e-mail address and/or name are currently not defined.</b>
101     <p>
102         In order to use this feature you must <a href="$info_url">update your information</a> and fill out both fields.
103     </form>
104 END
105 ));
106 //--------------------------------------------
107     }
108 }
109
110 function buildEmail($id,$data,$emailText)
111 {
112     $top = getTop();
113     $preamble = getPreamble($id,$emailText);
114     $page = renderPage($id,$data);
115     $disclaimer = getDisclaimer();    
116     $bottom = getBottom();
117     
118     $body = $top.$preamble.$page.$disclaimer.$bottom;
119
120     return($body);
121 }
122
123 function renderPage($id,$data)
124 {
125     global $ewiki_plugins, $ewiki_links;
126     $ewiki_links = true;
127     
128     getUserInfo($from_email,$from_name);
129
130     //allowed html tags for the email
131     $allow = "<p> <b> <i> <ul> <li> <br /> <hr> <em> <tt> <h1> <h2> <h3> <h4> <h5> <font> <ol> <div> <dl> <dt> <dd> <font>";
132     
133     //Assume all links in page exist (eliminate the ? after undefined pages)
134     $render_args = array("scan_links" => 0,"html" => (EWIKI_ALLOW_HTML||(@$data["flags"]&EWIKI_DB_F_HTML)),);
135
136     $page = ewiki_make_title($id, $id, 2);
137     $page .= $ewiki_plugins["render"][0] ($data["content"], $render_args);
138     $page = strip_tags($page,$allow);
139     
140     return($page);
141 }
142
143 function getNote($emailText)
144 {
145     if (empty($emailText))
146     {
147         return NULL;
148     }
149     else
150     {
151         //allowed html tags for the note
152         $allow_note = "<br />";
153         
154         $note = "<p>Here is a small message from the sender:<br />$emailText<hr>";
155         $note = strip_tags($note,$allow_note);
156         
157         return($note);
158     }
159 }
160
161 function getTop()
162 {
163     $top  = "<html><head>";
164     $top .= ewiki_t("EWIKIEMAILCSS");
165     $top .= "<title>[LiveWeb Snapshot]</title></head><body><div id=\"PageText\">";
166     return($top);
167 }
168
169 function getPreamble($id,$emailText)
170 {
171     getUserInfo($from_email,$from_name);
172     
173     $link_url = ewiki_script("view","$id");
174     $link="https://www.burgiss.com/liveweb/$link_url";
175     
176     $note = getNote($emailText);
177     
178     $preamble  = "<p>The following e-mail is a stripped down snapshot of the \"$id\" page from Burgiss LiveWeb. ";
179     $preamble .= "If you have an account with us, click <a href=\"$link\">here</a> to view it. ";
180     $preamble .= "This was sent from $from_name with an e-mail address registered as $from_email</p>";
181     $preamble .= "$note<hr><font face=\"Arial\" size=\"-1\">";
182     
183     return($preamble);
184 }
185
186 function getDisclaimer()
187 {
188     $disclaimer  = "</font><hr><p><tt><b>NOTICE:</b> If you have received this in error, rest asured that you are not on any mailing lists. ";
189     $disclaimer .= "If you have any concerns, please e-mail the <a href=\"mailto:webmaster@burgiss.com\">webmaster</a>.</tt></p>";
190 }
191
192 function getBottom()
193 {
194     $bottom  = "</div></body></html>";
195 }
196
197 function getSubject($id)
198 {
199     $subject = "[LiveWeb Snapshot] \"$id\"";
200     return($subject);
201 }
202
203 function getHeaders($from_email,$from_name)
204 {
205     /* To send HTML mail, you can set the Content-type header. */
206     $headers  = "MIME-Version: 1.0\r\n";
207     $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
208     
209     /* additional headers */
210     $headers .= "From: \"$from_name\" <$from_email>\r\n";
211     $headers .= "X-Mailer: ErfurtWiki/".EWIKI_VERSION."\r\n";
212     
213     return($headers);
214 }
215
216 function ewiki_page_wiki_email_page($id=0, $data=0, $action=0)
217 {
218     if ( isRequestNotSet($_REQUEST["email_page"],$_REQUEST["email_address"]) )
219     {
220         if($action == "emailpage")
221         {
222             getUserInfo($from_email,$from_name);
223             $defined = isUserInfoDefined($from_email,$from_name);
224             
225             $warning = checkEmailField($_REQUEST["email_address"],$_REQUEST["not_first_time"]);
226             
227             $html = htmlFormGenerate($defined,$id,$warning,$from_email,$from_name);
228             
229             return($html);
230         }
231         else
232         {
233             return "You shouldn't be here.";
234         }
235     }
236     
237     #-- email generation and sending
238     else
239     {
240         $emailAddress = $_REQUEST["email_address"];
241         $emailText = $_REQUEST["email_text"];
242         
243         getUserInfo($from_email,$from_name);
244         $headers = getHeaders($from_email,$from_name);
245         $subject = getSubject($id);
246         
247         $body = buildEmail($id,$data,$emailText);        
248
249         mail($emailAddress,$subject,$body,$headers);
250         
251         $success_message  = "<p><h4>Success!</h4></p><p>Page sent to <a href=mailto:$emailAddress>$emailAddress</a></p>";
252         $success_message .= "<p>Click <a href=\"" . ewiki_script("view",$id) . "\">here</a> to return to the page you just sent.</p>";
253         
254         return ( ewiki_t($success_message) );
255     }
256 }
257
258 ?>