Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

mailtofriend.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: mailtofriend.php 9839 2003-06-05 09:57:30Z br $
5 //
6 // Created on: <18-Jun-2001 16:37:47 br>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27 // include_once( "classes/eztemplate.php" );
28 // include_once( "classes/ezhttptool.php" );
29
30 // include_once( "ezmail/classes/ezmail.php" );
31 // include_once( "ezarticle/classes/ezarticle.php" );
32 // include_once( "ezarticle/classes/ezarticlerenderer.php" );
33
34 $ini =& eZINI::instance( 'site.ini' );
35 $Language = $ini->variable( "eZArticleMain", "Language" );
36 $Sender = $ini->variable( "ezArticleMain", "MailToFriendSender" );
37
38 // sections
39 // include_once( "ezsitemanager/classes/ezsection.php" );
40
41 $CategoryID = $url_array[5];
42
43 if ( !strstr( $HTTP_REFERER, $ini->variable( "eZArticleMain", "FromURL" ) ) )
44 {
45 die( "SendToFriend is not configured correctly. Please check your site.ini file" );
46 }
47
48 // tempo fix for admin users - maybe in the future must be changed
49 if ( ($CategoryID != 0) )
50 {
51 $GlobalSectionID = eZArticleCategory::sectionIDstatic ( $CategoryID );
52 }
53
54 // init the section
55 $sectionObject =& eZSection::globalSectionObject( $GlobalSectionID );
56 $sectionObject->setOverrideVariables();
57
58 $tpl = new eZTemplate( "kernel/ezarticle/user/" . $ini->variable( "eZArticleMain", "TemplateDir" ),
59 "kernel/ezarticle/user/" . "intl", $Language, "mailtofriend.php" );
60
61 $tpl->set_file( "mailtofriend_tpl" ,"mailtofriend.tpl" );
62 $tpl->setAllStrings();
63
64 $tpl->set_block( "mailtofriend_tpl", "first_page_tpl", "first_page" );
65
66 // Error messages.
67
68 $tpl->set_block( "first_page_tpl", "err_msg_tpl", "err_msg" );
69 $tpl->set_block( "first_page_tpl", "err_real_name_tpl", "err_real_name" );
70 $tpl->set_block( "first_page_tpl", "err_send_to_tpl", "err_send_to" );
71 $tpl->set_block( "first_page_tpl", "err_from_tpl", "err_from" );
72
73 // The success message.
74
75 $tpl->set_block( "mailtofriend_tpl", "success_tpl", "success" );
76 $tpl->set_block( "success_tpl", "user_comment_tpl", "user_comment" );
77
78 $tpl->set_var( "section_id", $GlobalSectionID );
79 //$tpl->set_var( "category_id", $CategoryID );
80
81 // Own eZTemplate object for create the mail.message to send.
82
83 $sendmail_tpl = new eZTemplate( "kernel/ezarticle/user/" . $ini->variable( "eZArticleMain", "TemplateDir" ),
84 "kernel/ezarticle/user/" . "intl", $Language, "sendmailtofriend.php" );
85 $sendmail_tpl->setAllStrings();
86 $sendmail_tpl->set_file( "sendmailtofriend_tpl", "sendmailtofriend.tpl" );
87
88 // Set subject
89
90 $sendmail_tpl->set_block( "sendmailtofriend_tpl", "mail_subject_tpl", "mail_subject" );
91
92 // Build up the mail.
93
94 $sendmail_tpl->set_block( "sendmailtofriend_tpl", "mail_body_tpl", "mail_body" );
95 $sendmail_tpl->set_block( "mail_body_tpl", "mail_comment_tpl", "mail_comment" );
96 $sendmail_tpl->set_block( "mail_body_tpl", "article_url_tpl", "article_url");
97
98 // Set all variables to "". Then we don't get any {err_msg} to output if the variable is emty.
99
100 $tpl->set_var( "first_page", "" );
101 $tpl->set_var( "err_msg", "" );
102 $tpl->set_var( "err_real_name", "" );
103 $tpl->set_var( "err_send_to", "" );
104 $tpl->set_var( "err_from", "" );
105 $tpl->set_var( "success", "" );
106 $tpl->set_var( "user_comment", "" );
107
108 $tpl->set_var( "site_url", $GLOBALS["HTTP_HOST"] );
109 $tpl->set_var( "art_id", $ArticleID);
110
111 $sendmail_tpl->set_var( "mail_subject", "" );
112 $sendmail_tpl->set_var( "mail_body", "" );
113 $sendmail_tpl->set_var( "article_url", "" );
114 $sendmail_tpl->set_var( "mail_comment", "" );
115
116 // check wich button is pressed and error check the input fields.
117
118 if ( isset( $Submit ) || isset( $RealName ) || isset( $SendTo ) || isset( $From ) )
119 {
120 $errorArr = array();
121 // if ( ( trim( $RealName ) == "" ) )
122 // $errorArr["real_name"] = true;
123
124 if (! ( eZMail::validate( $SendTo ) ) )
125 $errorArr["send_to"] = true;
126
127 if (! ( eZMail::validate( $From ) ) )
128 $errorArr["from"] = true;
129
130 if( !isset( $Textarea ) )
131 $Textarea = false;
132
133 if( !isset( $RealName ) )
134 $RealName = false;
135
136 if ( $errorArr )
137 errorMsg( $ArticleID, $CategoryID, $tpl, $RealName, $SendTo, $From, $Textarea, $errorArr );
138 else
139 sendmail( $ArticleID, $CategoryID, $tpl, $sendmail_tpl, $RealName, $SendTo, $From, $Textarea, $Sender );
140 } else
141 {
142 printForm( $ArticleID, $CategoryID, $tpl );
143 }
144
148 function sendmail ( $article_id, $CategoryID, $tpl, $sendmail_tpl, $real_name, $to_name, $from_name, $text=false, $Sender=false )
149 {
150 $article = getArticle( $article_id );
151 $renderer = new eZArticleRenderer( $article );
152 $name = $article->name( );
153 $intro = strip_tags( $renderer->renderIntro( ) );
154 $text = trim( $text );
155
156 $site_url = $_SERVER["HTTP_HOST"];
157 // $server_name = $_SERVER["SERVER_NAME"];
158 // $server_name = $GLOBALS["HTTP_HOST"];
159
160 $ini =& eZINI::instance( 'site.ini' );
161 $server_name = $ini->variable( "site", "SiteURL" );
162
163 // Build up the mail to send from the template.
164
165 $sendmail_tpl->set_var( "server_name", $server_name );
166 $mail_subject = $sendmail_tpl->parse( "mail_subject", "mail_subject_tpl" );
167
168 $sendmail_tpl->set_var( "server_name", $server_name );
169 $sendmail_tpl->set_var( "from_name", $from_name );
170
171 if ( $text != "" )
172 {
173 $sendmail_tpl->set_var( "comment", $text );
174 $sendmail_tpl->parse( "mail_comment", "mail_comment_tpl" );
175 }
176 $sendmail_tpl->set_var( "name", $name );
177 $sendmail_tpl->set_var( "intro", $intro );
178 $mail_body = $sendmail_tpl->parse( "mail_body", "mail_body_tpl" );
179
180 $sendmail_tpl->set_var( "real_name", $real_name );
181 $sendmail_tpl->set_var( "site_url", $site_url );
182 $sendmail_tpl->set_var( "art_id", $article_id );
183 $sendmail_tpl->set_var( "category_id", $CategoryID );
184 $mail_body .= $sendmail_tpl->parse( "article_url", "article_url_tpl" );
185
186 // Send the mail.
187
188 $mail = new eZMail();
189 $mail->setFromName( $real_name );
190 $mail->setTo( $to_name );
191 $mail->setFrom( $Sender );
192 $mail->setSubject( $mail_subject );
193 $mail->setBodyText( $mail_body );
194 $mail->send();
195
196 // print a successfull message to the webpage
197 $tpl->set_var( "to_name", htmlspecialchars( $to_name ) );
198 $tpl->set_var( "server_name", $server_name );
199 $tpl->set_var( "from_name", htmlspecialchars( $from_name ) );
200 if ( $text != "" )
201 {
202 $tpl->set_var( "user_comment", htmlspecialchars( $text ) );
203 $tpl->parse( "user_comment", "user_comment_tpl" );
204 }
205 $tpl->set_var( "header_text", $name );
206 $tpl->set_var( "intro_text", $intro );
207 $tpl->set_var( "site_url", $site_url );
208 $tpl->set_var( "art_id", $article->id() );
209 $tpl->set_var( "category_id", $CategoryID );
210
211 // $category = $article->categoryDefinition();
212 // if ( $category )
213 // {
214 // $tpl->set_var( "category_name", $category->name() );
215 // $tpl->set_var( "category_id", $category->id() );
216 // }
217 $tpl->parse( "success", "success_tpl" );
218 $tpl->pparse( "output", "mailtofriend_tpl" );
219 }
220
221
222
226 function errorMsg ( $article_id, $CategoryID, $tpl, $real_name, $send_to, $from, $textarea, $error )
227 {
228 $tpl->parse( "err_msg", "err_msg_tpl" );
229
230 if ( $error["real_name"] == true)
231 {
232 $tpl->parse( "err_real_name", "err_real_name_tpl" );
233 }
234 if ( $error["send_to"] == true )
235 {
236 $tpl->parse( "err_send_to", "err_send_to_tpl" );
237 }
238 if ( $error["from"] == true )
239 {
240 $tpl->parse( "err_from", "err_from_tpl" );
241 }
242
243 printForm( $article_id, $CategoryID, $tpl, $real_name, $send_to, $from, $textarea );
244 }
245
249 function getArticle ( $ArticleID )
250 {
251 $article = new eZArticle();
252 if ( $article->get( $ArticleID ) )
253 {
254 return $article;
255 } else
256 {
257 eZHTTPTool::header( "Location: /error/404/" );
258 exit();
259 }
260 }
261
265 function printForm ( $ArticleID, $CategoryID, $tpl, $real_name="", $send_to="", $from="", $textarea="" )
266 {
267
268 $article = getArticle( $ArticleID );
269 $renderer = new eZArticleRenderer( $article );
270
271 $name = $article->name( );
272 $intro = strip_tags( $renderer->renderIntro( ) );
273
274 // $category = $article->categoryDefinition();
275 // if ( $category )
276 // {
277 // $tpl->set_var( "category_name", $category->name() );
278 // $tpl->set_var( "category_id", $category->id() );
279 // }
280
281 $tpl->set_var( "category_id", $CategoryID );
282
283 $tpl->set_var( "Topic", $name );
284 $tpl->set_var( "Intro", $intro );
285 $tpl->set_var( "real_name", htmlspecialchars( $real_name ) );
286 $tpl->set_var( "send_to", htmlspecialchars( $send_to ) );
287 $tpl->set_var( "from", htmlspecialchars( $from ) );
288 $tpl->set_var( "textarea", htmlspecialchars( $textarea ) );
289 $tpl->parse( "first_page", "first_page_tpl" );
290 $tpl->pparse( "output", "mailtofriend_tpl" );
291 }
292
293 ?>
$article
$article
Definition: articlelog.php:45
$renderer
if(! $article->get( $ArticleID)) $renderer
Definition: articlepreview.php:76
eZArticleRenderer
Definition: ezarticlerenderer.php:36
eZArticle
Definition: ezarticle.php:82
eZHTTPTool\header
static header( $string)
Definition: ezhttptool.php:96
eZMail
Definition: ezmail.php:57
eZMail\validate
static validate( $address)
Definition: ezmail.php:599
eZSection\globalSectionObject
static & globalSectionObject( $sectionID)
Definition: ezsection.php:366
eZTemplate
Definition: eztemplate.php:107
$name
$name
Definition: companytypelist.php:194
$ArticleID
$ArticleID
Definition: export.php:48
$GlobalSectionID
$GlobalSectionID
Definition: ezad/user/datasupplier.php:28
$url_array
$url_array
Definition: ezaddress/admin/datasupplier.php:34
$error
$error
Definition: ezarticle/admin/categoryedit.php:51
$mail
$mail
Definition: ezbulkmail/admin/maillist.php:61
exit
exit
Definition: folder.php:81
$tpl
$tpl
Definition: mailtofriend.php:58
$Sender
$Sender
Definition: mailtofriend.php:36
errorMsg
errorMsg( $article_id, $CategoryID, $tpl, $real_name, $send_to, $from, $textarea, $error)
Definition: mailtofriend.php:226
$CategoryID
$CategoryID
Definition: mailtofriend.php:41
sendmail
sendmail( $article_id, $CategoryID, $tpl, $sendmail_tpl, $real_name, $to_name, $from_name, $text=false, $Sender=false)
Definition: mailtofriend.php:148
$Language
$Language
Definition: mailtofriend.php:35
$ini
$ini
Definition: mailtofriend.php:34
$sendmail_tpl
$sendmail_tpl
Definition: mailtofriend.php:83
$sectionObject
if(!strstr( $HTTP_REFERER, $ini->variable("eZArticleMain", "FromURL"))) if(($CategoryID !=0)) $sectionObject
Definition: mailtofriend.php:55
getArticle
getArticle( $ArticleID)
Definition: mailtofriend.php:249
printForm
printForm( $ArticleID, $CategoryID, $tpl, $real_name="", $send_to="", $from="", $textarea="")
Definition: mailtofriend.php:265
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.