Completed
Push — master ( 72613d...069c91 )
by Michael
02:16
created

class/extgalleryMailer.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * ExtGallery Class Manager
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright   {@link https://xoops.org/ XOOPS Project}
13
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @author      Zoullou (http://www.zoullou.net)
15
 * @package     ExtGallery
16
 */
17
18
// defined('XOOPS_ROOT_PATH') || exit('Restricted access.');
19
20
require_once XOOPS_ROOT_PATH . '/class/mail/xoopsmultimailer.php';
21
22
/**
23
 * Class extgalleryMailer
24
 */
25
class extgalleryMailer
26
{
27
    public $mailer;
28
    public $type;
29
    public $tags = [];
30
31
    public $ecardId;
32
    public $subject;
33
    public $toEmail;
34
    public $toName;
35
    public $fromEmail;
36
    public $fromName;
37
    public $greetings;
38
    public $description;
39
    public $photo;
40
41
    /**
42
     * @param $type
43
     */
44
    public function __construct($type)
45
    {
46
        $this->mailer = new XoopsMultiMailer();
47
        $this->type   = $type;
48
    }
49
50
    public function imageIncluded()
51
    {
52 View Code Duplication
        if ('' === $this->photo->getVar('photo_serveur')) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
53
            $photoPath = XOOPS_ROOT_PATH . '/uploads/extgallery/public-photo/medium/' . $this->photo->getVar('photo_name');
54
        } else {
55
            $photoPath = $this->photo->getVar('photo_serveur') . $this->photo->getVar('photo_name');
56
        }
57
        $this->tags['PHOTO_SRC'] = 'cid:photo';
58
        $this->tags['STAMP_SRC'] = 'cid:stamp';
59
        $this->mailer->addEmbeddedImage($photoPath, 'photo');
60
        $this->mailer->addEmbeddedImage(XOOPS_ROOT_PATH . '/modules/extgallery/assets/images/stamp.gif', 'stamp');
61
    }
62
63
    public function imageLinked()
64
    {
65 View Code Duplication
        if ('' == $this->photo->getVar('photo_serveur')) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
            $photoUrl = XOOPS_URL . '/uploads/extgallery/public-photo/medium/' . $this->photo->getVar('photo_name');
67
        } else {
68
            $photoUrl = $this->photo->getVar('photo_serveur') . $this->photo->getVar('photo_name');
69
        }
70
        $this->tags['PHOTO_SRC'] = $photoUrl;
71
        $this->tags['STAMP_SRC'] = XOOPS_URL . '/modules/extgallery/assets/images/stamp.gif';
72
    }
73
74
    public function send()
75
    {
76
        $this->assignTags();
77
        if ('included' === $this->type) {
78
            $this->imageIncluded();
79
        } elseif ('linked' === $this->type) {
80
            $this->imageLinked();
81
        }
82
83
        $this->mailer->From     = $this->fromEmail;
84
        $this->mailer->FromName = $this->fromName;
85
        $this->mailer->Subject  = $this->subject;
86
        $this->mailer->Body     = $this->loadTemplate('ecard_html.tpl');
87
        $this->mailer->AltBody  = $this->loadTemplate('ecard_text.tpl');
88
        $this->mailer->addAddress($this->toEmail, $this->toName);
89
        //$this->mailer->AddReplyTo($this->fromEmail, $this->fromName);
90
        $this->mailer->send();
91
    }
92
93
    public function assignTags()
94
    {
95
        $this->tags['ECARD_LINK']  = XOOPS_URL . '/modules/extgallery/public-viewecard.php?id=' . $this->ecardId;
96
        $this->tags['EXP_EMAIL']   = $this->fromEmail;
97
        $this->tags['EXP_NAME']    = $this->fromName;
98
        $this->tags['REC_NAME']    = $this->toName;
99
        $this->tags['GREETINGS']   = $this->greetings;
100
        $this->tags['DESCRIPTION'] = $this->description;
101
        $this->tags['MODULE_LINK'] = XOOPS_URL . '/modules/extgallery/';
102
        $this->tags['SITE_NAME']   = $GLOBALS['xoopsConfig']['sitename'];
103
        $this->tags['SITE_URL']    = XOOPS_URL;
104
    }
105
106
    /**
107
     * @param $name
108
     *
109
     * @return mixed|string
110
     */
111
    public function loadTemplate($name)
112
    {
113
        global $xoopsConfig;
114
115
        if (file_exists(XOOPS_ROOT_PATH . '/modules/extgallery/language/' . $xoopsConfig['language'] . '/mail_template/' . $name)) {
116
            $path = XOOPS_ROOT_PATH . '/modules/extgallery/language/' . $xoopsConfig['language'] . '/mail_template/' . $name;
117
        } else {
118
            $path = XOOPS_ROOT_PATH . '/modules/extgallery/language/english/mail_template/' . $name;
119
        }
120
        $fd   = @fopen($path, 'r');
121
        $body = fread($fd, filesize($path));
122
        // replace tags with actual values
123
        foreach ($this->tags as $k => $v) {
124
            $body = str_replace('{' . $k . '}', $v, $body);
125
        }
126
127
        return $body;
128
    }
129
130
    /**
131
     * @param $ecardId
132
     */
133
    public function setEcardId($ecardId)
134
    {
135
        $this->ecardId = $ecardId;
136
    }
137
138
    /**
139
     * @param $subject
140
     */
141
    public function setSubject($subject)
142
    {
143
        $this->subject = $subject;
144
    }
145
146
    /**
147
     * @param $email
148
     */
149
    public function setToEmail($email)
150
    {
151
        $this->toEmail = $email;
152
    }
153
154
    /**
155
     * @param $name
156
     */
157
    public function setToName($name)
158
    {
159
        $this->toName = $name;
160
    }
161
162
    /**
163
     * @param $email
164
     */
165
    public function setFromEmail($email)
166
    {
167
        $this->fromEmail = $email;
168
    }
169
170
    /**
171
     * @param $name
172
     */
173
    public function setFromName($name)
174
    {
175
        $this->fromName = $name;
176
    }
177
178
    /**
179
     * @param $greetings
180
     */
181
    public function setGreetings($greetings)
182
    {
183
        $this->greetings = $greetings;
184
    }
185
186
    /**
187
     * @param $description
188
     */
189
    public function setDescription($description)
190
    {
191
        $this->description = $description;
192
    }
193
194
    /**
195
     * @param $photo
196
     */
197
    public function setPhoto($photo)
198
    {
199
        $this->photo = $photo;
200
    }
201
}
202