PluginProbe
WPPizza – A Restaurant Plugin / 3.20
WPPizza – A Restaurant Plugin v3.20
trunk 2.16.11.28 3.19 3.19.1 3.19.2 3.19.3 3.19.4 3.19.5 3.19.6 3.19.7 3.19.7.1 3.19.7.2 3.19.7.3 3.19.7.4 3.19.8 3.19.8.1 3.19.8.2 3.19.8.3 3.19.9 3.20 3.20.1
wppizza / classes / modules / mod.settings.smtp.php

mod.settings.smtp.php in WPPizza – A Restaurant Plugin 3.20, at classes/modules/mod.settings.smtp.php

444 lines 18.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPPIZZA_MODULE_SMTP Class
4 *
5 * @package WPPIZZA
6 * @subpackage WPPIZZA_MODULE_SMTP
7 * @copyright Copyright (c) 2015, Oliver Bach
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 3.0
10 *
11 */
12 if ( ! defined( 'ABSPATH' ) ) exit;/*Exit if accessed directly*/
13
14
15 /************************************************************************************************************************
16 *
17 *
18 *
19 *
20 *
21 *
22 ************************************************************************************************************************/
23 class WPPIZZA_MODULE_SMTP{
24
25 private $settings_page = 'settings';/* which admin subpage (identified there by this->class_key) are we adding this to */
26
27
28 // private $layout_page = 'layout';/* which admin subpage (identified there by this->class_key) are we adding this to */
29 // private $layout_position = 3;/* at which admin position (section) should this appear on above admin subpage, integer(zero indexed - for numeric position) or key ('layout-style' for example) after which it should appear*/
30
31 // private $localization_page = 'localization';/* which admin subpage (identified there by this->class_key) are we adding this to */
32 // private $localization_position = 'itemised-order';/* at which admin position (section) should this appear on above admin subpage, integer(zero indexed - for numeric position) or key ('layout-style' for example) after which it should appear*/
33
34
35 private $section_key = 'smtp';/* must be unique */
36
37
38 function __construct() {
39 /**********************************************************
40 [add settings to admin]
41 ***********************************************************/
42 if(is_admin()){
43 /* add admin options settings page*/
44 add_filter('wppizza_filter_settings_sections_'.$this->settings_page.'', array($this, 'admin_options_settings'), 100, 5);
45 /* add admin options settings page fields */
46 add_action('wppizza_admin_settings_section_fields_'.$this->settings_page.'', array($this, 'admin_options_fields_settings'), 10, 5);
47
48 /**add default options **/
49 add_filter('wppizza_filter_setup_default_options', array( $this, 'options_default'));
50 /**validate options**/
51 add_filter('wppizza_filter_options_validate', array( $this, 'options_validate'), 10, 2 );
52
53 /** admin ajax **/
54 add_action('wppizza_ajax_admin_'.$this->settings_page.'', array( $this, 'admin_ajax'));
55 }
56 /**********************************************************
57 [filter/actions depending on settings]
58 ***********************************************************/
59 /* add smtp settings if renabled */
60 //add_action('wppizza_phpmailer_settings', array($this, 'use_smtp'));
61 }
62
63 /*******************************************************************************************************************************************************
64 *
65 *
66 *
67 * [frontend filters]
68 *
69 *
70 *
71 ********************************************************************************************************************************************************/
72 /*************************************
73
74 using smtp if enabled
75
76 **************************************/
77 // function use_smtp($phpmailer){
78 // global $wppizza_options;
79 // /************************************************
80 // send with smtp if enabled
81 // *************************************************/
82 // if(!empty($wppizza_options[$this->section_key]['smtp_enable'])){
83 // /*force smtp*/
84 // $phpmailer->isSMTP();
85 // $phpmailer->Host = $wppizza_options[$this->section_key]['smtp_host'];
86 // $phpmailer->Port = $wppizza_options[$this->section_key]['smtp_port'];
87 // $phpmailer->SMTPAuth = empty($wppizza_options[$this->section_key]['smtp_authentication']) ? false : true;
88 // $phpmailer->SMTPSecure = (!empty($wppizza_options[$this->section_key]['smtp_encryption'])) ? $wppizza_options[$this->section_key]['smtp_encryption'] : false;
89 // $phpmailer->Username = $wppizza_options[$this->section_key]['smtp_username'];
90 // $phpmailer->Password = wppizza_encrypt_decrypt($wppizza_options[$this->section_key]['smtp_password'],false);
91 // $phpmailer->SMTPDebug = !empty($wppizza_options[$this->section_key]['smtp_debug']) ? 3 : false;
92 // }
93 // }
94
95 /*************************************
96
97 testing smtp
98
99 **************************************/
100 function test_smtp($smtp_parameters){
101 global $phpmailer; // define the global variable
102
103 /* set smtp vars and test mode*/
104 $email_results = WPPIZZA()->email->isTest();
105
106 // Set up the mail variables
107 $email = $smtp_parameters['smtp_email'];
108 /* Translators: 1: WPPizza Name as defined by constant */
109 $subject = sprintf(__('%s SMTP Test: Test mail to ', 'wppizza-admin'),WPPIZZA_NAME) . $email;
110 /* Translators: 1: WPPizza Name as defined by constant, 2: Bloginfo name as per general settings */
111 $message = sprintf(__('%1$s SMTP test email message from "%2$s" site', 'wppizza-admin'),WPPIZZA_NAME, get_bloginfo('name')).'';
112 $headers = array(WPPIZZA_CUSTOM_HEADER_EMAIL);/* add custom header so we know it's an email send by wppizza */
113
114 /**
115 Start output buffering for debugging output
116 **/
117 ob_start();
118
119 /**Try sending test mail**/
120 $mailResult = (wp_mail($email, $subject, $message, $headers)) ? true : false ;
121
122 if(!$mailResult){
123
124 $result['error'] = '<b style="color:red">FAIL - check details below</b>'.PHP_EOL;
125
126 /*error info*/
127 $result['error-info'] = array();
128
129 /*last error*/
130 $phpMailerLastError=error_get_last();
131 if(!empty($phpMailerLastError)){
132 $result['error-info']['last-error'] = $phpMailerLastError;
133 }
134
135 /*phpmailer errors*/
136 $phpMailerError=$phpmailer->ErrorInfo;//. ' | '.$phpmailer->errorMessage;
137 if(!empty($phpMailerError)){
138 $result['error-info']['phpmailer']=''.print_r($phpMailerError,true).'';/**sometimes there's somthing in that variable too*/
139 }
140
141 }else{
142 $result['success'] = '<b style="color:blue">SUCCESS - email sent. Check inbox of '.$email.' and do not forget to "Save Changes"</b>'.PHP_EOL;
143 }
144
145 /**smtp debugging output**/
146 $result['debug'] = ob_get_clean();
147
148 /**return array for display**/
149 print"".print_r($result,true)."";
150 exit();
151 }
152
153 /*******************************************************************************************************************************************************
154 *
155 *
156 *
157 * [add admin page options]
158 *
159 *
160 *
161 ********************************************************************************************************************************************************/
162 /*******************************************************************************************************************************************************
163 *
164 * [admin ajax]
165 *
166 ********************************************************************************************************************************************************/
167 function admin_ajax($wppizza_options){
168
169 //need right caps for access
170 if( !current_user_can('wppizza_cap_'.$this->settings_page.'')){
171 echo '<div class="wppizza-highlight">'.__('Access Denied', 'wppizza-admin').' ['.$this->section_key.']</div>';
172 exit();
173 }
174
175 /*****************************************************
176 [test smtp settings]
177 *****************************************************/
178 if($_POST['vars']['field']=='wppizza_smtp_test'){
179 $smtp_test_results = $this->test_smtp($_POST['vars']['smtp_parameters']);
180
181 /**return array for display**/
182 print"".$smtp_test_results."";
183
184 exit();
185 }
186 }
187 /*------------------------------------------------------------------------------
188 #
189 #
190 # [settings page]
191 #
192 #
193 ------------------------------------------------------------------------------*/
194 /****************************************************************
195 * [settigs section - setting page]
196 * @since 3.0
197 * @return array()
198 ****************************************************************/
199 function admin_options_settings($settings, $sections, $fields, $inputs, $help){
200
201 /********************************
202 * [use smtp]
203 ********************************/
204 /*sections*/
205 if($sections){
206 $settings['sections'][$this->section_key] = __('use SMTP', 'wppizza-admin');
207 }
208 /*help*/
209 if($help){
210 $settings['help'][$this->section_key][] = array(
211 /* Translators: 1: WPPizza Name as defined by constant */
212 'label'=>sprintf(__('use SMTP for sending %s related emails', 'wppizza-admin'),WPPIZZA_NAME),
213 'description'=>array(
214 /* Translators: 1: WPPizza Name as defined by constant */
215 sprintf(__('To use SMTP for any %s related emails, set the values as appropriate.', 'wppizza-admin'),WPPIZZA_NAME),
216 __('Make sure you test your settings by using the SMTP test provided.', 'wppizza-admin'),
217 /* Translators: 1: WPPizza Name as defined by constant */
218 '<span class="wppizza-highlight-important">'.sprintf(__('Please note, only %s emails will be affected', 'wppizza-admin'), WPPIZZA_NAME).'</span>'
219 )
220 );
221 }
222 /*fields*/
223 if($fields){
224 $field = 'smtp_enable';
225 $settings['fields'][$this->section_key][$field] = array( __('Use SMTP', 'wppizza-admin'), array(
226 'value_key'=>$field,
227 'option_key'=>$this->settings_page,
228 /* Translators: 1: WPPizza Name as defined by constant */
229 'label'=>sprintf(__('check to use SMTP when sending %s related emails', 'wppizza-admin'), WPPIZZA_NAME),
230 'description'=>array()
231 ));
232 $field = 'smtp_host';
233 $settings['fields'][$this->section_key][$field] = array( __('SMTP Host', 'wppizza-admin'), array(
234 'value_key'=>$field,
235 'option_key'=>$this->settings_page,
236 'label'=>'',
237 'description'=>array()
238 ));
239 $field = 'smtp_port';
240 $settings['fields'][$this->section_key][$field] = array( __('SMTP Port', 'wppizza-admin'), array(
241 'value_key'=>$field,
242 'option_key'=>$this->settings_page,
243 'label'=>'',
244 'description'=>array()
245 ));
246 $field = 'smtp_encryption';
247 $settings['fields'][$this->section_key][$field] = array( __('SMTP Encryption', 'wppizza-admin'), array(
248 'value_key'=>$field,
249 'option_key'=>$this->settings_page,
250 'label'=>'',
251 'description'=>array()
252 ));
253 $field = 'smtp_authentication';
254 $settings['fields'][$this->section_key][$field] = array( __('SMTP Authentication', 'wppizza-admin'), array(
255 'value_key'=>$field,
256 'option_key'=>$this->settings_page,
257 'label'=>__('check to enable authentication', 'wppizza-admin'),
258 'description'=>array()
259 ));
260 $field = 'smtp_username';
261 $settings['fields'][$this->section_key][$field] = array( __('SMTP Username', 'wppizza-admin'), array(
262 'value_key'=>$field,
263 'option_key'=>$this->settings_page,
264 'label'=>'',
265 'description'=>array()
266 ));
267 $field = 'smtp_password';
268 $settings['fields'][$this->section_key][$field] = array( __('SMTP Password', 'wppizza-admin'), array(
269 'value_key'=>$field,
270 'option_key'=>$this->settings_page,
271 'label'=>'',
272 'description'=>array()
273 ));
274 $field = 'smtp_debug';
275 $settings['fields'][$this->section_key][$field] = array( __('SMTP Debug', 'wppizza-admin'), array(
276 'value_key'=>$field,
277 'option_key'=>$this->settings_page,
278 'label'=>__('This must be OFF on production servers. Only use this to output full smtp connection details in your browsers console for debuggiing. Make sure to disable this again when you are done debugging.', 'wppizza-admin') . "<br><span class='wppizza-highlight'>".__('Note: Having this enabled will stop all/any orders from completing.', 'wppizza-admin')."</span>" ,
279 'description'=>array()
280 ));
281 $field = 'smtp_test';
282 $settings['fields'][$this->section_key][$field] = array( __('SMTP Test', 'wppizza-admin'), array(
283 'value_key'=>$field,
284 'option_key'=>$this->settings_page,
285 'label'=>__('To test your smtp settings, enter your email address on the left and <a href="javascript:void(0)" id="wppizza_smtp_test">click here</a>. results will appear below', 'wppizza-admin'),
286 'description'=>array()
287 ));
288 }
289
290
291 return $settings;
292 }
293 /****************************************************************
294 * [output option fields - setting page]
295 * @since 3.0
296 * @return array()
297 ****************************************************************/
298 function admin_options_fields_settings($wppizza_options, $options_key, $field, $label, $description){
299
300 /*************************************
301 [smtp input fields]
302 *************************************/
303 if($field=='smtp_enable'){
304 echo "<label>";
305 echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />";
306 echo "" . $label . "";
307 echo "</label>";
308 echo"".$description."";
309 }
310 if($field=='smtp_host'){
311 echo "<label>";
312 echo"<input id='wppizza_".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='text' value='".$wppizza_options[$options_key][$field]."' />";
313 echo "" . $label . "";
314 echo "</label>";
315 echo"".$description."";
316 }
317 if($field=='smtp_port'){
318 echo "<label>";
319 echo"<input id='wppizza_".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' size='3' type='text' value='".$wppizza_options[$options_key][$field]."' />";
320 echo "" . $label . "";
321 echo "</label>";
322 echo"".$description."";
323 }
324 if($field=='smtp_encryption'){
325 echo "<label>";
326 echo"<select id='wppizza_".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' />";
327 echo"<option value='' ".selected($wppizza_options[$options_key][$field],"",false).">".__('No Encryption', 'wppizza-admin')."</option>";
328 echo"<option value='ssl' ".selected($wppizza_options[$options_key][$field],"ssl",false).">".__('SSL', 'wppizza-admin')."</option>";
329 echo"<option value='tls' ".selected($wppizza_options[$options_key][$field],"tls",false).">".__('TLS', 'wppizza-admin')."</option>";
330 echo "</select>";
331 echo "" . $label . "";
332 echo "</label>";
333 }
334
335 if($field=='smtp_authentication'){
336 echo "<label>";
337 echo"<input id='wppizza_".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />";
338 echo "" . $label . "";
339 echo "</label>";
340 echo"".$description."";
341 }
342
343 if($field=='smtp_username'){
344 echo "<label>";
345 echo"<input id='wppizza_".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='text' value='".$wppizza_options[$options_key][$field]."' />";
346 echo "" . $label . "";
347 echo "</label>";
348 echo"".$description."";
349 }
350 if($field=='smtp_password'){
351 /*info string*/
352 $SmtpPwPlaceholder=__('no password set','wppizza-admin');
353 if(!empty($wppizza_options[$options_key][$field])){$SmtpPwPlaceholder=__('a password has been set. enter a new password to change the current password','wppizza-admin');}
354
355 /*show password if defined*/
356 $constant_dev_view_smtp_password = WPPIZZA_DEV_VIEW_SMTP_PASSWORD;/* cast to var for php 5.3 */
357 $smtpPW = ( !empty($constant_dev_view_smtp_password) && !empty($wppizza_options[$options_key][$field]) ) ? wppizza_encrypt_decrypt($wppizza_options[$options_key][$field],false) : '';
358
359 echo "<label>";
360 echo"<input id='wppizza_".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='text' value='".$smtpPW."' placeholder='********' />".$SmtpPwPlaceholder."</label>";
361 echo"<br />";
362 if(!function_exists('openssl_encrypt')){
363 echo" <span class='wppizza-highlight'>".__('WARNING: you do not seem to have open ssl installed. your smtp password will be saved in plaintext in your database. this could pose a security risk', 'wppizza-admin')."</span>";
364 }else{
365 echo" <span class='wppizza-highlight'>".__('Note: if you move or clone this wppizza installation to another wordpress installation, you MUST re-enter and re-save your smtp password there unless your wp-config.php\'s are identical.', 'wppizza-admin')."</span>";
366 }
367 }
368 if($field=='smtp_debug'){
369 echo "<label>";
370 echo "<input id='".$field."' name='".WPPIZZA_SLUG."[".$options_key."][".$field."]' type='checkbox' ". checked($wppizza_options[$options_key][$field],true,false)." value='1' />";
371 echo "" . $label . "";
372 echo "</label>";
373 }
374 if($field=='smtp_test'){
375 echo "<label>";
376 echo "".__('To', 'wppizza-admin').": <input id='wppizza_smtp_test_email' type='text' value='' placeholder='email@domain.com' />";
377 echo "" . $label . "";
378 echo "</label>";
379 echo"".$description."";
380 echo"<br />";
381 echo"<div id='wppizza_smtp_test_results'><pre></pre></div>";
382 }
383 }
384 /*------------------------------------------------------------------------------
385 # [insert default option on install]
386 # $parameter $options array() | filter passing on filtered options
387 # @since 3.0
388 # @return array()
389 ------------------------------------------------------------------------------*/
390 function options_default($options){
391 /********************************
392 * [smtp settings]
393 ********************************/
394 $options[$this->settings_page]['smtp_enable'] = false;
395 $options[$this->settings_page]['smtp_host'] = '';
396 $options[$this->settings_page]['smtp_port'] = '25';
397 $options[$this->settings_page]['smtp_encryption'] = '';
398 $options[$this->settings_page]['smtp_authentication'] = false;
399 $options[$this->settings_page]['smtp_username'] = '';
400 $options[$this->settings_page]['smtp_password'] = '';
401 $options[$this->settings_page]['smtp_debug'] = false;
402 /*SMTP Test does not need any option set**/
403
404 return $options;
405 }
406
407 /*------------------------------------------------------------------------------
408 # [validate options on save/update]
409 #
410 # @since 3.0
411 # @return array()
412 ------------------------------------------------------------------------------*/
413
414 function options_validate($options, $input){
415 /**make sure we get the full array on install/update**/
416 if ( empty( $_POST['_wp_http_referer'] ) ) {
417 return $input;
418 }
419 /********************************
420 * [smtp settings]
421 ********************************/
422 if(isset($_POST[''.WPPIZZA_SLUG.'_'.$this->settings_page.''])){
423 $options[$this->settings_page]['smtp_enable'] = !empty($input[$this->settings_page]['smtp_enable']) ? true : false;
424 $options[$this->settings_page]['smtp_host']=wppizza_validate_string($input[$this->settings_page]['smtp_host']);
425 $options[$this->settings_page]['smtp_port']=wppizza_validate_int_only($input[$this->settings_page]['smtp_port']);
426 $options[$this->settings_page]['smtp_encryption']=wppizza_validate_string($input[$this->settings_page]['smtp_encryption']);
427 $options[$this->settings_page]['smtp_authentication'] = !empty($input[$this->settings_page]['smtp_authentication']) ? true : false;
428 $options[$this->settings_page]['smtp_username']=wppizza_validate_string($input[$this->settings_page]['smtp_username']);
429 /*lets not override set ones as we will not display it in the input*/
430 if(!empty($input[$this->settings_page]['smtp_password'])){
431 $options[$this->settings_page]['smtp_password']=wppizza_encrypt_decrypt($input[$this->settings_page]['smtp_password']);
432 }
433 $options[$this->settings_page]['smtp_debug'] = !empty($input[$this->settings_page]['smtp_debug']) ? true : false;
434 }
435 return $options;
436 }
437 }
438 /***************************************************************
439 *
440 * [ini]
441 *
442 ***************************************************************/
443 $WPPIZZA_MODULE_SMTP = new WPPIZZA_MODULE_SMTP();
444 ?>