|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Extgallery; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* ExtGallery Class Manager |
|
7
|
|
|
* |
|
8
|
|
|
* You may not change or alter any portion of this comment or credits |
|
9
|
|
|
* of supporting developers from this source code or any supporting source code |
|
10
|
|
|
* which is considered copyrighted (c) material of the original comment or credit authors. |
|
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. |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
|
16
|
|
|
* @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
17
|
|
|
* @author Zoullou (http://www.zoullou.net) |
|
18
|
|
|
* @package ExtGallery |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
use phpmailerException; |
|
22
|
|
|
use XoopsModules\Extgallery; |
|
23
|
|
|
use XoopsMultiMailer; |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
require_once XOOPS_ROOT_PATH . '/class/mail/xoopsmultimailer.php'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Class Extgallery\Mailer |
|
35
|
|
|
*/ |
|
36
|
|
|
class Mailer |
|
37
|
|
|
{ |
|
38
|
|
|
public $mailer; |
|
39
|
|
|
public $type; |
|
40
|
|
|
public $tags = []; |
|
41
|
|
|
public $ecardId; |
|
42
|
|
|
public $subject; |
|
43
|
|
|
public $toEmail; |
|
44
|
|
|
public $toName; |
|
45
|
|
|
public $fromEmail; |
|
46
|
|
|
public $fromName; |
|
47
|
|
|
public $greetings; |
|
48
|
|
|
public $description; |
|
49
|
|
|
public $photo; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param $type |
|
53
|
|
|
*/ |
|
54
|
|
|
public function __construct($type) |
|
55
|
|
|
{ |
|
56
|
|
|
$this->mailer = new XoopsMultiMailer(); |
|
57
|
|
|
$this->type = $type; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function imageIncluded() |
|
61
|
|
|
{ |
|
62
|
|
|
if ('' === $this->photo->getVar('photo_serveur')) { |
|
63
|
|
|
$photoPath = XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/medium/' . $this->photo->getVar('photo_name'); |
|
64
|
|
|
} else { |
|
65
|
|
|
$photoPath = $this->photo->getVar('photo_serveur') . $this->photo->getVar('photo_name'); |
|
66
|
|
|
} |
|
67
|
|
|
$this->tags['PHOTO_SRC'] = 'cid:photo'; |
|
68
|
|
|
$this->tags['STAMP_SRC'] = 'cid:stamp'; |
|
69
|
|
|
$this->mailer->addEmbeddedImage($photoPath, 'photo'); |
|
70
|
|
|
$this->mailer->addEmbeddedImage(XOOPS_ROOT_PATH . '/modules/extgallery/assets/images/stamp.gif', 'stamp'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function imageLinked() |
|
74
|
|
|
{ |
|
75
|
|
|
if ('' == $this->photo->getVar('photo_serveur')) { |
|
76
|
|
|
$photoUrl = XOOPS_URL . '/uploads/extgallery/public-photo/medium/' . $this->photo->getVar('photo_name'); |
|
77
|
|
|
} else { |
|
78
|
|
|
$photoUrl = $this->photo->getVar('photo_serveur') . $this->photo->getVar('photo_name'); |
|
79
|
|
|
} |
|
80
|
|
|
$this->tags['PHOTO_SRC'] = $photoUrl; |
|
81
|
|
|
$this->tags['STAMP_SRC'] = XOOPS_URL . '/modules/extgallery/assets/images/stamp.gif'; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function send() |
|
85
|
|
|
{ |
|
86
|
|
|
$this->assignTags(); |
|
87
|
|
|
if ('included' === $this->type) { |
|
88
|
|
|
$this->imageIncluded(); |
|
89
|
|
|
} elseif ('linked' === $this->type) { |
|
90
|
|
|
$this->imageLinked(); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
$this->mailer->From = $this->fromEmail; |
|
94
|
|
|
$this->mailer->FromName = $this->fromName; |
|
95
|
|
|
$this->mailer->Subject = $this->subject; |
|
96
|
|
|
$this->mailer->Body = $this->loadTemplate('ecard_html.tpl'); |
|
97
|
|
|
$this->mailer->AltBody = $this->loadTemplate('ecard_text.tpl'); |
|
98
|
|
|
$this->mailer->addAddress($this->toEmail, $this->toName); |
|
99
|
|
|
//$this->mailer->AddReplyTo($this->fromEmail, $this->fromName); |
|
100
|
|
|
try { |
|
101
|
|
|
$this->mailer->send(); |
|
102
|
|
|
} catch (phpmailerException $e) { |
|
103
|
|
|
echo 'Caught exception: ', $e->getMessage(), "\n", '<br>'; |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function assignTags() |
|
108
|
|
|
{ |
|
109
|
|
|
$this->tags['ECARD_LINK'] = XOOPS_URL . '/modules/extgallery/public-viewecard.php?id=' . $this->ecardId; |
|
110
|
|
|
$this->tags['EXP_EMAIL'] = $this->fromEmail; |
|
111
|
|
|
$this->tags['EXP_NAME'] = $this->fromName; |
|
112
|
|
|
$this->tags['REC_NAME'] = $this->toName; |
|
113
|
|
|
$this->tags['GREETINGS'] = $this->greetings; |
|
114
|
|
|
$this->tags['DESCRIPTION'] = $this->description; |
|
115
|
|
|
$this->tags['MODULE_LINK'] = XOOPS_URL . '/modules/extgallery/'; |
|
116
|
|
|
$this->tags['SITE_NAME'] = $GLOBALS['xoopsConfig']['sitename']; |
|
117
|
|
|
$this->tags['SITE_URL'] = XOOPS_URL; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @param $name |
|
122
|
|
|
* |
|
123
|
|
|
* @return mixed|string |
|
124
|
|
|
*/ |
|
125
|
|
|
public function loadTemplate($name) |
|
126
|
|
|
{ |
|
127
|
|
|
global $xoopsConfig; |
|
128
|
|
|
|
|
129
|
|
|
if (\file_exists(XOOPS_ROOT_PATH . '/modules/extgallery/language/' . $xoopsConfig['language'] . '/mail_template/' . $name)) { |
|
130
|
|
|
$path = XOOPS_ROOT_PATH . '/modules/extgallery/language/' . $xoopsConfig['language'] . '/mail_template/' . $name; |
|
131
|
|
|
} else { |
|
132
|
|
|
$path = XOOPS_ROOT_PATH . '/modules/extgallery/language/english/mail_template/' . $name; |
|
133
|
|
|
} |
|
134
|
|
|
$fd = @\fopen($path, 'rb'); |
|
135
|
|
|
$body = \fread($fd, \filesize($path)); |
|
|
|
|
|
|
136
|
|
|
// replace tags with actual values |
|
137
|
|
|
foreach ($this->tags as $k => $v) { |
|
138
|
|
|
$body = \str_replace('{' . $k . '}', $v, $body); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
return $body; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @param $ecardId |
|
146
|
|
|
*/ |
|
147
|
|
|
public function setEcardId($ecardId) |
|
148
|
|
|
{ |
|
149
|
|
|
$this->ecardId = $ecardId; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @param $subject |
|
154
|
|
|
*/ |
|
155
|
|
|
public function setSubject($subject) |
|
156
|
|
|
{ |
|
157
|
|
|
$this->subject = $subject; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @param $email |
|
162
|
|
|
*/ |
|
163
|
|
|
public function setToEmail($email) |
|
164
|
|
|
{ |
|
165
|
|
|
$this->toEmail = $email; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @param $name |
|
170
|
|
|
*/ |
|
171
|
|
|
public function setToName($name) |
|
172
|
|
|
{ |
|
173
|
|
|
$this->toName = $name; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @param $email |
|
178
|
|
|
*/ |
|
179
|
|
|
public function setFromEmail($email) |
|
180
|
|
|
{ |
|
181
|
|
|
$this->fromEmail = $email; |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @param $name |
|
186
|
|
|
*/ |
|
187
|
|
|
public function setFromName($name) |
|
188
|
|
|
{ |
|
189
|
|
|
$this->fromName = $name; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* @param $greetings |
|
194
|
|
|
*/ |
|
195
|
|
|
public function setGreetings($greetings) |
|
196
|
|
|
{ |
|
197
|
|
|
$this->greetings = $greetings; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
/** |
|
201
|
|
|
* @param $description |
|
202
|
|
|
*/ |
|
203
|
|
|
public function setDescription($description) |
|
204
|
|
|
{ |
|
205
|
|
|
$this->description = $description; |
|
206
|
|
|
} |
|
207
|
|
|
|
|
208
|
|
|
/** |
|
209
|
|
|
* @param $photo |
|
210
|
|
|
*/ |
|
211
|
|
|
public function setPhoto($photo) |
|
212
|
|
|
{ |
|
213
|
|
|
$this->photo = $photo; |
|
214
|
|
|
} |
|
215
|
|
|
} |
|
216
|
|
|
|