Completed
Push — master ( 9688ab...f40189 )
by Richard
11s
created

XoopsMultiMailer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1
Metric Value
dl 0
loc 124
rs 10
wmc 4
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 32 4
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 54 and the first side effect is on line 28.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Xoops MultiMailer Base Class
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       (c) 2000-2016 XOOPS Project (www.xoops.org)
13
 * @license             GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
14
 * @package             Kernel
15
 * @subpackage          mail
16
 * @since               2.0.0
17
 * @author              Author: Jochen Büînagel ([email protected])
18
 */
19
20
/**
21
 *
22
 * @package    class
23
 * @subpackage mail
24
 * @filesource
25
 * @author     Jochen Büînagel <[email protected]>
26
 */
27
28
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
29
/**
30
 * load the base class
31
 */
32
if (!file_exists($file = XOOPS_ROOT_PATH . '/class/mail/phpmailer/class.phpmailer.php')) {
33
    trigger_error('Required File  ' . str_replace(XOOPS_ROOT_PATH, '', $file) . ' was not found in file ' . __FILE__ . ' at line ' . __LINE__, E_USER_WARNING);
34
35
    return false;
36
}
37
require_once XOOPS_ROOT_PATH . '/class/mail/phpmailer/PHPMailerAutoload.php';
38
//include_once XOOPS_ROOT_PATH . '/class/mail/phpmailer/class.phpmailer.php';
39
40
/**
41
 * Mailer Class.
42
 *
43
 * At the moment, this does nothing but send email through PHP "mail()" function,
44
 * but it has the ability to do much more.
45
 *
46
 * If you have problems sending mail with "mail()", you can edit the member variables
47
 * to suit your setting. Later this will be possible through the admin panel.
48
 *
49
 * @todo       Make a page in the admin panel for setting mailer preferences.
50
 * @package    class
51
 * @subpackage mail
52
 * @author     Jochen Buennagel <[email protected]>
53
 */
54
class XoopsMultiMailer extends PHPMailer
55
{
56
    /**
57
     * 'from' address
58
     *
59
     * @var string
60
     * @access private
61
     */
62
    public $From = '';
63
64
    /**
65
     * 'from' name
66
     *
67
     * @var string
68
     * @access private
69
     */
70
    public $FromName = '';
71
72
    // can be 'smtp', 'sendmail', or 'mail'
73
    /**
74
     * Method to be used when sending the mail.
75
     *
76
     * This can be:
77
     * <li>mail (standard PHP function 'mail()') (default)
78
     * <li>smtp    (send through any SMTP server, SMTPAuth is supported.
79
     * You must set {@link $Host}, for SMTPAuth also {@link $SMTPAuth},
80
     * {@link $Username}, and {@link $Password}.)
81
     * <li>sendmail (manually set the path to your sendmail program
82
     * to something different than 'mail()' uses in {@link $Sendmail})
83
     *
84
     * @var string
85
     * @access private
86
     */
87
    public $Mailer = 'mail';
88
89
    /**
90
     * set if $Mailer is 'sendmail'
91
     *
92
     * Only used if {@link $Mailer} is set to 'sendmail'.
93
     * Contains the full path to your sendmail program or replacement.
94
     *
95
     * @var string
96
     * @access private
97
     */
98
    public $Sendmail = '/usr/sbin/sendmail';
99
100
    /**
101
     * SMTP Host.
102
     *
103
     * Only used if {@link $Mailer} is set to 'smtp'
104
     *
105
     * @var string
106
     * @access private
107
     */
108
    public $Host = '';
109
110
    /**
111
     * Does your SMTP host require SMTPAuth authentication?
112
     *
113
     * @var boolean
114
     * @access private
115
     */
116
    public $SMTPAuth = false;
117
118
    /**
119
     * Username for authentication with your SMTP host.
120
     *
121
     * Only used if {@link $Mailer} is 'smtp' and {@link $SMTPAuth} is TRUE
122
     *
123
     * @var string
124
     * @access private
125
     */
126
    public $Username = '';
127
128
    /**
129
     * Password for SMTPAuth.
130
     *
131
     * Only used if {@link $Mailer} is 'smtp' and {@link $SMTPAuth} is TRUE
132
     *
133
     * @var string
134
     * @access private
135
     */
136
    public $Password = '';
137
138
    /**
139
     * Constructor
140
     *
141
     * @access public
142
     */
143
    public function __construct()
144
    {
145
        $config_handler    = xoops_getHandler('config');
146
        $xoopsMailerConfig = $config_handler->getConfigsByCat(XOOPS_CONF_MAILER);
147
        $this->From        = $xoopsMailerConfig['from'];
148
        if ($this->From == '') {
149
            $this->From = $GLOBALS['xoopsConfig']['adminmail'];
150
        }
151
        $this->Sender = $this->From;
152
        if ($xoopsMailerConfig['mailmethod'] === 'smtpauth') {
153
            $this->Mailer   = 'smtp';
154
            $this->SMTPAuth = true;
155
            // TODO: change value type of xoopsConfig 'smtphost' from array to text
156
            $this->Host     = implode(';', $xoopsMailerConfig['smtphost']);
157
            $this->Username = $xoopsMailerConfig['smtpuser'];
158
            $this->Password = $xoopsMailerConfig['smtppass'];
159
        } else {
160
            $this->Mailer   = $xoopsMailerConfig['mailmethod'];
161
            $this->SMTPAuth = false;
162
            $this->Sendmail = $xoopsMailerConfig['sendmailpath'];
163
            $this->Host     = implode(';', $xoopsMailerConfig['smtphost']);
164
        }
165
        $this->CharSet = strtolower(_CHARSET);
166
        $xoopsLanguage = preg_replace('/[^a-zA-Z0-9_-]/', '', $GLOBALS['xoopsConfig']['language']);
167
        if (file_exists(XOOPS_ROOT_PATH . '/language/' . $xoopsLanguage . '/phpmailer.php')) {
168
            include XOOPS_ROOT_PATH . '/language/' . $xoopsLanguage . '/phpmailer.php';
169
            $this->language = $PHPMAILER_LANG;
0 ignored issues
show
Bug introduced by
The variable $PHPMAILER_LANG does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
170
        } else {
171
            $this->setLanguage('en', XOOPS_ROOT_PATH . '/class/mail/phpmailer/language/');
172
        }
173
        //$this->pluginDir = XOOPS_ROOT_PATH . '/class/mail/phpmailer/';
174
    }
175
176
177
}
178