| 1 |
<?php |
| 2 |
/** |
| 3 |
* @version 1.0 |
| 4 |
* @package Content |
| 5 |
* @category Menu |
| 6 |
* @author wpdevelop |
| 7 |
* |
| 8 |
* @web-site https://oplugins.com/ |
| 9 |
* @email [email protected] |
| 10 |
* |
| 11 |
* @modified 2015-04-09 |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 15 |
|
| 16 |
/** Replace: |
| 17 |
1. DownloadNotification -> DownloadNotification |
| 18 |
2. DOWNLOAD_NOTIFICATION -> DOWNLOAD_NOTIFICATION |
| 19 |
3. download_notification -> download_notification |
| 20 |
4. Check in api-emails.php 'db_prefix_option' => '...' option, have to be the same as WPBM_EMAIL_DOWNLOAD_NOTIFICATION_PREFIX here |
| 21 |
5. Configure Fields in init_settings_fields. |
| 22 |
*/ |
| 23 |
|
| 24 |
if ( ! defined( 'WPBM_EMAIL_DOWNLOAD_NOTIFICATION_PREFIX' ) ) define( 'WPBM_EMAIL_DOWNLOAD_NOTIFICATION_PREFIX', 'wpbm_email_' ); // Its defined in api-emails.php file & its same for all emails, here its used only for easy coding... |
| 25 |
|
| 26 |
if ( ! defined( 'WPBM_EMAIL_DOWNLOAD_NOTIFICATION_ID' ) ) define( 'WPBM_EMAIL_DOWNLOAD_NOTIFICATION_ID', 'download_notification' ); /* Define Name of Email Template. |
| 27 |
Note. Prefix "wpbm_email_" defined in api-emails.php file. |
| 28 |
Full name of option is - "wpbm_email_download_notification" |
| 29 |
Other email templates names: |
| 30 |
- 'download_notification' - send email with download link to user |
| 31 |
- 'link_admin' - send copy of email to admin with download link |
| 32 |
- 'download_admin' - send email about downloads happend |
| 33 |
*/ |
| 34 |
|
| 35 |
require_once( WPBM_PLUGIN_DIR . '/core/any/api-emails.php' ); // API |
| 36 |
|
| 37 |
|
| 38 |
/** Email F i e l d s */ |
| 39 |
class WPBM_Emails_API_DownloadNotification extends WPBM_Emails_API { // O v e r r i d i n g "WPBM_Emails_API" ClASS |
| 40 |
|
| 41 |
/** Overrided functions - define Email Fields & Values */ |
| 42 |
public function init_settings_fields() { |
| 43 |
|
| 44 |
$this->fields = array(); |
| 45 |
|
| 46 |
$this->fields['enabled'] = array( |
| 47 |
'type' => 'checkbox' |
| 48 |
, 'default' => 'On' |
| 49 |
, 'title' => __('Enable / Disable', 'booking-manager') |
| 50 |
, 'label' => __('Enable this email notification', 'booking-manager') |
| 51 |
, 'description' => '' |
| 52 |
, 'group' => 'general' |
| 53 |
|
| 54 |
); |
| 55 |
/* |
| 56 |
$this->fields['copy_to_admin'] = array( |
| 57 |
'type' => 'checkbox' |
| 58 |
, 'default' => 'On' |
| 59 |
, 'title' => __('Copy to admin', 'booking-manager') |
| 60 |
, 'label' => __('Enable / disable sending copy of this email notification to admin', 'booking-manager') |
| 61 |
, 'description' => '' |
| 62 |
, 'group' => 'general' |
| 63 |
|
| 64 |
); |
| 65 |
*/ |
| 66 |
$this->fields['enabled_hr'] = array( 'type' => 'hr' ); |
| 67 |
|
| 68 |
$this->fields['to_html_prefix'] = array( |
| 69 |
'type' => 'pure_html' |
| 70 |
, 'group' => 'general' |
| 71 |
, 'html' => '<tr valign="top"> |
| 72 |
<th scope="row"> |
| 73 |
<label class="wpbm-form-email" for="' |
| 74 |
. esc_attr( 'download_notification_to' ) |
| 75 |
. '">' . wp_kses_post( __('To' , 'booking-manager') ) |
| 76 |
. '</label> |
| 77 |
</th> |
| 78 |
<td><fieldset style="float:left;width:50%;margin-right:5%;">' |
| 79 |
); |
| 80 |
$this->fields['to'] = array( |
| 81 |
'type' => 'text' // We are using here 'text' and not 'email', for ability to save several comma seperated emails. |
| 82 |
, 'default' => get_option( 'admin_email' ) |
| 83 |
//, 'placeholder' => '' |
| 84 |
, 'title' => '' |
| 85 |
, 'description' => __('Email Address', 'booking-manager') . '. ' . __('Required', 'booking-manager') . '.' |
| 86 |
, 'description_tag' => '' |
| 87 |
, 'css' => 'width:100%' |
| 88 |
, 'group' => 'general' |
| 89 |
, 'tr_class' => '' |
| 90 |
, 'only_field' => true |
| 91 |
, 'validate_as' => array( 'required' ) |
| 92 |
); |
| 93 |
$this->fields['to_html_middle'] = array( |
| 94 |
'type' => 'pure_html' |
| 95 |
, 'group' => 'general' |
| 96 |
, 'html' => '</fieldset><fieldset style="float:left;width:45%;">' |
| 97 |
); |
| 98 |
|
| 99 |
$user_info = array( 'name' => '' ); |
| 100 |
if ( is_user_logged_in() ) { |
| 101 |
$user_data = get_userdata( get_current_user_id() ); |
| 102 |
$user_info['name'] = ( $user_data ) ? $user_data->display_name : ''; |
| 103 |
} |
| 104 |
|
| 105 |
$this->fields['to_name'] = array( |
| 106 |
'type' => 'text' |
| 107 |
, 'default' => $user_info['name'] |
| 108 |
//, 'placeholder' => '' |
| 109 |
, 'title' => '' |
| 110 |
, 'description' => __('Title', 'booking-manager') . ' (' . __('optional', 'booking-manager') . ').' //. ' ' . __('If empty then title defined as WordPress', 'booking-manager') |
| 111 |
, 'description_tag' => '' |
| 112 |
, 'css' => 'width:100%' |
| 113 |
, 'group' => 'general' |
| 114 |
, 'tr_class' => '' |
| 115 |
, 'only_field' => true |
| 116 |
); |
| 117 |
$this->fields['to_html_sufix'] = array( |
| 118 |
'type' => 'pure_html' |
| 119 |
, 'group' => 'general' |
| 120 |
, 'html' => ' </fieldset> |
| 121 |
</td> |
| 122 |
</tr>' |
| 123 |
); |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
$this->fields['from_html_prefix'] = array( |
| 128 |
'type' => 'pure_html' |
| 129 |
, 'group' => 'general' |
| 130 |
, 'html' => '<tr valign="top"> |
| 131 |
<th scope="row"> |
| 132 |
<label class="wpbm-form-email" for="' |
| 133 |
. esc_attr( 'download_notification_from' ) |
| 134 |
. '">' . wp_kses_post( __('From' , 'booking-manager') ) |
| 135 |
. '</label> |
| 136 |
</th> |
| 137 |
<td><fieldset style="float:left;width:50%;margin-right:5%;">' |
| 138 |
); |
| 139 |
$this->fields['from'] = array( |
| 140 |
'type' => 'email' // Its can be only 1 email, so check it as Email field. |
| 141 |
, 'default' => get_option( 'admin_email' ) |
| 142 |
//, 'placeholder' => '' |
| 143 |
, 'title' => '' |
| 144 |
, 'description' => __('Email Address', 'booking-manager') . '. ' . __('Required', 'booking-manager') . '.' |
| 145 |
, 'description_tag' => '' |
| 146 |
, 'css' => 'width:100%' |
| 147 |
, 'group' => 'general' |
| 148 |
, 'tr_class' => '' |
| 149 |
, 'only_field' => true |
| 150 |
, 'validate_as' => array( 'required' ) |
| 151 |
); |
| 152 |
$this->fields['from_html_middle'] = array( |
| 153 |
'type' => 'pure_html' |
| 154 |
, 'group' => 'general' |
| 155 |
, 'html' => '</fieldset><fieldset style="float:left;width:45%;">' |
| 156 |
); |
| 157 |
$this->fields['from_name'] = array( |
| 158 |
'type' => 'text' |
| 159 |
, 'default' => $user_info['name'] |
| 160 |
//, 'placeholder' => '' |
| 161 |
, 'title' => '' |
| 162 |
, 'description' => __('Title', 'booking-manager') . ' (' . __('optional', 'booking-manager') . ').' //. ' ' . __('If empty then title defined as WordPress', 'booking-manager') |
| 163 |
, 'description_tag' => '' |
| 164 |
, 'css' => 'width:100%' |
| 165 |
, 'group' => 'general' |
| 166 |
, 'tr_class' => '' |
| 167 |
, 'only_field' => true |
| 168 |
); |
| 169 |
$this->fields['from_html_sufix'] = array( |
| 170 |
'type' => 'pure_html' |
| 171 |
, 'group' => 'general' |
| 172 |
, 'html' => ' </fieldset> |
| 173 |
</td> |
| 174 |
</tr>' |
| 175 |
); |
| 176 |
|
| 177 |
$this->fields['from_hr'] = array( 'type' => 'hr' ); |
| 178 |
|
| 179 |
|
| 180 |
$this->fields['subject'] = array( |
| 181 |
'type' => 'text' |
| 182 |
, 'default' => sprintf( __( 'Download notification of %s', 'booking-manager'), '[product_title] [ [product_id] ]' ) |
| 183 |
//, 'placeholder' => '' |
| 184 |
, 'title' => __('Subject', 'booking-manager') |
| 185 |
, 'description' => sprintf(__('Type your email %ssubject%s.' , 'booking-manager'),'<b>','</b>') . ' ' . __('Required', 'booking-manager') . '.' |
| 186 |
, 'description_tag' => '' |
| 187 |
, 'css' => 'width:100%' |
| 188 |
, 'group' => 'general' |
| 189 |
, 'tr_class' => '' |
| 190 |
, 'validate_as' => array( 'required' ) |
| 191 |
); |
| 192 |
|
| 193 |
$blg_title = get_option( 'blogname' ); |
| 194 |
$blg_title = str_replace( array( '"', "'" ), '', $blg_title ); |
| 195 |
|
| 196 |
$this->fields['content'] = array( |
| 197 |
'type' => 'wp_textarea' |
| 198 |
, 'default' => |
| 199 |
// sprintf( __( 'Hello.%sThe %s have been downloaded at %s from IP: %s~ Download link of %s will expire in %s === User info ===%s User agent: %s IP: %s Request url: %s ======================%s === Product Summary ===%s %s ======================%s Thank you, %s', 'booking-manager' ) |
| 200 |
// , '<br/><br/>' |
| 201 |
// , '[product_title] [ [product_id] ]' |
| 202 |
// , '[current_date] [current_time]' |
| 203 |
// , '[remote_ip]' . '<br/><br/>' |
| 204 |
// , '[product_filename] ([product_size])' |
| 205 |
// , '[product_expire_after] - [product_expire_date]' . '<br/><br/>' |
| 206 |
// , '<br/>' |
| 207 |
// , '[user_agent]' . '<br/>', '[remote_ip]' . '<br/>', '[request_url]' . '<br/>' |
| 208 |
// , '<br/><br/>' |
| 209 |
// , '<br/>' |
| 210 |
// , '[product_summary]<br/>[product_description]<br/>[product_link]<br/>' |
| 211 |
// , '<br/><br/>' |
| 212 |
// , $blg_title . '<br/>' . '[siteurl]' |
| 213 |
// ) |
| 214 |
sprintf( __( 'Hi. %s The %s have been downloaded. %s ===== User Info ===== %s To: %s IP: %s User agent: %s Request url: %s ====================== %s ===== Product Summary ===== %s Expire at %s ====================== %s', 'booking-manager' ) |
| 215 |
, '<br/><br/>' |
| 216 |
, '<strong>[product_title] [product_version]</strong> [ID=[product_id]]' |
| 217 |
, '<br/><br/>' |
| 218 |
, '<br/>' |
| 219 |
, '[link_sent_to]' . '<br/>' |
| 220 |
, '[remote_ip]' . '<br/>' |
| 221 |
, '[user_agent]' . '<br/>' |
| 222 |
, '[request_url]' . '<br/>' |
| 223 |
, '<br/><br/>' |
| 224 |
, '<br/>[product_summary] <br/>[product_description] <br/>' |
| 225 |
, '<strong>[product_expire_date]</strong> '. '<br/>' |
| 226 |
, '<br/> <br/><strong>[current_date] [current_time]</strong>' |
| 227 |
) |
| 228 |
//, 'placeholder' => '' |
| 229 |
, 'title' => __('Content', 'booking-manager') |
| 230 |
, 'description' => __('Type your email message content.', 'booking-manager') |
| 231 |
, 'description_tag' => '' |
| 232 |
, 'css' => '' |
| 233 |
, 'group' => 'general' |
| 234 |
, 'tr_class' => '' |
| 235 |
, 'rows' => 10 |
| 236 |
, 'show_in_2_cols' => true |
| 237 |
); |
| 238 |
// $this->fields['content'] = htmlspecialchars( $this->fields['content'] );// Convert > to > |
| 239 |
// $this->fields['content'] = html_entity_decode( $this->fields['content'] );// Convert > to > |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
//////////////////////////////////////////////////////////////////// |
| 244 |
// Style |
| 245 |
//////////////////////////////////////////////////////////////////// |
| 246 |
|
| 247 |
|
| 248 |
$this->fields['header_content'] = array( |
| 249 |
'type' => 'textarea' |
| 250 |
, 'default' => '' |
| 251 |
, 'title' => __('Email Heading', 'booking-manager') |
| 252 |
, 'description' => __('Enter main heading contained within the email notification.', 'booking-manager') |
| 253 |
//, 'placeholder' => '' |
| 254 |
, 'rows' => 2 |
| 255 |
, 'css' => "width:100%;" |
| 256 |
, 'group' => 'parts' |
| 257 |
); |
| 258 |
$this->fields['footer_content'] = array( |
| 259 |
'type' => 'textarea' |
| 260 |
, 'default' => '' |
| 261 |
, 'title' => __('Email Footer Text', 'booking-manager') |
| 262 |
, 'description' => __('Enter text contained within footer of the email notification', 'booking-manager') |
| 263 |
//, 'placeholder' => '' |
| 264 |
, 'rows' => 2 |
| 265 |
, 'css' => 'width:100%;' |
| 266 |
, 'group' => 'parts' |
| 267 |
); |
| 268 |
|
| 269 |
$this->fields['template_file'] = array( |
| 270 |
'type' => 'select' |
| 271 |
, 'default' => 'plain' |
| 272 |
, 'title' => __('Email template', 'booking-manager') |
| 273 |
, 'description' => __('Choose email template.', 'booking-manager') |
| 274 |
, 'description_tag' => 'span' |
| 275 |
, 'css' => '' |
| 276 |
, 'options' => array( |
| 277 |
'plain' => __('Plain (without styles)', 'booking-manager') |
| 278 |
, 'standard' => __('Standard 1 column', 'booking-manager') |
| 279 |
) |
| 280 |
, 'group' => 'style' |
| 281 |
); |
| 282 |
|
| 283 |
$this->fields['template_file_help'] = array( |
| 284 |
'type' => 'help' |
| 285 |
, 'value' => array( sprintf( __('You can override this email template in this folder %s', 'booking-manager') |
| 286 |
, '<code>' . realpath( dirname(__FILE__) . '/../any/emails_tpl/' ) . '</code>' ) |
| 287 |
) |
| 288 |
, 'cols' => 2 |
| 289 |
, 'group' => 'style' |
| 290 |
); |
| 291 |
|
| 292 |
$this->fields['base_color'] = array( |
| 293 |
'type' => 'color' |
| 294 |
, 'default' => '#557da1' |
| 295 |
, 'title' => __('Base Color', 'booking-manager') |
| 296 |
, 'description' => __('The base color for email templates.', 'booking-manager') |
| 297 |
. ' ' . __('Default color', 'booking-manager') .': <code>#557da1</code>.' |
| 298 |
, 'group' => 'style' |
| 299 |
, 'tr_class' => 'template_colors' |
| 300 |
); |
| 301 |
$this->fields['background_color'] = array( |
| 302 |
'type' => 'color' |
| 303 |
, 'default' => '#f5f5f5' |
| 304 |
, 'title' => __('Background Color', 'booking-manager') |
| 305 |
, 'description' => __('The background color for email templates.', 'booking-manager') |
| 306 |
. ' ' . __('Default color', 'booking-manager') .': <code>#f5f5f5</code>.' |
| 307 |
, 'group' => 'style' |
| 308 |
, 'tr_class' => 'template_colors' |
| 309 |
); |
| 310 |
$this->fields['body_color'] = array( |
| 311 |
'type' => 'color' |
| 312 |
, 'default' => '#fdfdfd' |
| 313 |
, 'title' => __('Email Body Background Color', 'booking-manager') |
| 314 |
, 'description' => __('The main body background color for email templates.', 'booking-manager') |
| 315 |
. ' ' . __('Default color', 'booking-manager') .': <code>#fdfdfd</code>.' |
| 316 |
, 'group' => 'style' |
| 317 |
, 'tr_class' => 'template_colors' |
| 318 |
); |
| 319 |
$this->fields['text_color'] = array( |
| 320 |
'type' => 'color' |
| 321 |
, 'default' => '#505050' |
| 322 |
, 'title' => __('Email Body Text Colour', 'booking-manager') |
| 323 |
, 'description' => __('The main body text color for email templates.', 'booking-manager') |
| 324 |
. ' ' . __('Default color', 'booking-manager') .': <code>#505050</code>.' |
| 325 |
, 'group' => 'style' |
| 326 |
, 'tr_class' => 'template_colors' |
| 327 |
); |
| 328 |
|
| 329 |
|
| 330 |
//////////////////////////////////////////////////////////////////// |
| 331 |
// Email format: Plain, HTML, MultiPart |
| 332 |
//////////////////////////////////////////////////////////////////// |
| 333 |
|
| 334 |
|
| 335 |
$this->fields['email_content_type'] = array( |
| 336 |
'type' => 'select' |
| 337 |
, 'default' => 'plain' |
| 338 |
, 'title' => __('Email format', 'booking-manager') |
| 339 |
, 'description' => __('Choose which format of email to send.', 'booking-manager') |
| 340 |
, 'description_tag' => 'p' |
| 341 |
, 'css' => 'width:100%;' |
| 342 |
, 'options' => array( |
| 343 |
'plain' => __('Plain text', 'booking-manager') |
| 344 |
// , 'html' => __('HTML', 'booking-manager') |
| 345 |
// , 'multipart' => __('Multipart', 'booking-manager') |
| 346 |
) |
| 347 |
, 'group' => 'email_content_type' |
| 348 |
); |
| 349 |
if ( class_exists( 'DOMDocument' ) ) { |
| 350 |
$this->fields['email_content_type']['options']['html'] = __('HTML', 'booking-manager'); |
| 351 |
$this->fields['email_content_type']['options']['multipart'] = __('Multipart', 'booking-manager'); |
| 352 |
|
| 353 |
$this->fields['email_content_type']['default'] = 'html'; |
| 354 |
} |
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
//////////////////////////////////////////////////////////////////// |
| 359 |
// Help |
| 360 |
//////////////////////////////////////////////////////////////////// |
| 361 |
|
| 362 |
$this->fields['content_help'] = array( |
| 363 |
'type' => 'help' |
| 364 |
, 'value' => array() |
| 365 |
, 'cols' => 2 |
| 366 |
, 'group' => 'help' |
| 367 |
); |
| 368 |
|
| 369 |
$skip_shortcodes = array( |
| 370 |
'denyreason' |
| 371 |
, 'paymentreason' |
| 372 |
, 'visitorediturl' |
| 373 |
, 'visitorcancelurl' |
| 374 |
, 'visitorpayurl' |
| 375 |
); |
| 376 |
$email_example = sprintf(__('For example: "You have a new reservation %s on the following date(s): %s Contact information: %s You can approve or cancel this item at: %s Thank you, Reservation service."' , 'booking-manager'),'','[dates]<br/><br/>','<br/> [content]<br/><br/>', htmlentities( ' <a href="[moderatelink]">'.__('here' , 'booking-manager').'</a> ') . '<br/><br/> '); |
| 377 |
|
| 378 |
// $help_fields = wpbm_get_email_help_shortcodes( $skip_shortcodes, $email_example ); |
| 379 |
// |
| 380 |
// foreach ( $help_fields as $help_fields_key => $help_fields_value ) { |
| 381 |
// $this->fields['content_help']['value'][] = $help_fields_value; |
| 382 |
// } |
| 383 |
|
| 384 |
} |
| 385 |
|
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
/** Settings Emails P a g e */ |
| 391 |
class WPBM_Settings_Page_Email_DownloadNotification extends WPBM_Page_Structure { |
| 392 |
|
| 393 |
public $email_settings_api = false; |
| 394 |
|
| 395 |
|
| 396 |
/** Define interface for Email API |
| 397 |
* |
| 398 |
* @param string $selected_email_name - name of Email template |
| 399 |
* @param array $init_fields_values - array of init form fields data |
| 400 |
* @return object Email API |
| 401 |
*/ |
| 402 |
public function mail_api( $selected_email_name ='', $init_fields_values = array() ){ |
| 403 |
|
| 404 |
if ( $this->email_settings_api === false ) { |
| 405 |
$this->email_settings_api = new WPBM_Emails_API_DownloadNotification( $selected_email_name , $init_fields_values ); |
| 406 |
} |
| 407 |
|
| 408 |
return $this->email_settings_api; |
| 409 |
} |
| 410 |
|
| 411 |
|
| 412 |
public function in_page() { // P a g e t a g |
| 413 |
return 'wpbm-settings'; |
| 414 |
} |
| 415 |
|
| 416 |
|
| 417 |
public function tabs() { // T a b s A r r a y |
| 418 |
|
| 419 |
$tabs = array(); |
| 420 |
|
| 421 |
$tabs[ 'email' ] = array( |
| 422 |
'title' => __( 'Emails', 'booking-manager') // Title of TAB |
| 423 |
, 'page_title'=> __( 'Emails Settings', 'booking-manager') // Title of Page |
| 424 |
, 'hint' => __( 'Emails Settings', 'booking-manager') // Hint |
| 425 |
//, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link |
| 426 |
//, 'position' => '' // 'left' || 'right' || '' |
| 427 |
//, 'css_classes'=> '' // CSS class(es) |
| 428 |
//, 'icon' => '' // Icon - link to the real PNG img |
| 429 |
, 'font_icon' => 'glyphicon glyphicon-envelope' // CSS definition of forn Icon |
| 430 |
//, 'default' => false // Is this tab activated by default or not: true || false. |
| 431 |
//, 'disabled' => false // Is this tab disbaled: true || false. |
| 432 |
//, 'hided' => false // Is this tab hided: true || false. |
| 433 |
, 'subtabs' => array() |
| 434 |
); |
| 435 |
|
| 436 |
$subtabs = array(); |
| 437 |
|
| 438 |
|
| 439 |
$is_data_exist = get_wpbm_option( WPBM_EMAIL_DOWNLOAD_NOTIFICATION_PREFIX . WPBM_EMAIL_DOWNLOAD_NOTIFICATION_ID ); // ''wpbm_email_' - defined in api-emails.php file. |
| 440 |
if ( ( ! empty( $is_data_exist ) ) && ( isset( $is_data_exist['enabled'] ) ) && ( $is_data_exist['enabled'] == 'On' ) ) |
| 441 |
$icon = '<i class="menu_icon icon-1x glyphicon glyphicon-check"></i> '; |
| 442 |
else |
| 443 |
$icon = '<i class="menu_icon icon-1x glyphicon glyphicon-unchecked"></i> '; |
| 444 |
|
| 445 |
$subtabs['download-notification'] = array( |
| 446 |
'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html' |
| 447 |
, 'title' => $icon . __('Download Notification' , 'booking-manager') // Title of TAB |
| 448 |
, 'page_title' => __('Emails Settings', 'booking-manager') // Title of Page |
| 449 |
, 'hint' => __('Email about download notification, which is sending to admin' , 'booking-manager') // Hint |
| 450 |
, 'link' => '' // link |
| 451 |
, 'position' => '' // 'left' || 'right' || '' |
| 452 |
, 'css_classes' => '' // CSS class(es) |
| 453 |
//, 'icon' => 'http://.../icon.png' // Icon - link to the real PNG img |
| 454 |
//, 'font_icon' => 'glyphicon glyphicon-envelope' // CSS definition of Font Icon |
| 455 |
, 'default' => ! true // Is this sub tab activated by default or not: true || false. |
| 456 |
, 'disabled' => false // Is this sub tab deactivated: true || false. |
| 457 |
, 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' ) //, 'checkbox' => array( 'checked' => $is_checked, 'name' => 'enabled_active_status' ) |
| 458 |
, 'content' => 'content' // Function to load as conten of this TAB |
| 459 |
); |
| 460 |
|
| 461 |
$tabs[ 'email' ]['subtabs'] = $subtabs; |
| 462 |
|
| 463 |
return $tabs; |
| 464 |
} |
| 465 |
|
| 466 |
|
| 467 |
/** Show Content of Settings page */ |
| 468 |
public function content() { |
| 469 |
//debuge( 'WPBM_EMAIL_DOWNLOAD_NOTIFICATION_PREFIX . WPBM_EMAIL_DOWNLOAD_NOTIFICATION_ID, get_wpbm_option( WPBM_EMAIL_DOWNLOAD_NOTIFICATION_PREFIX . WPBM_EMAIL_DOWNLOAD_NOTIFICATION_ID )', WPBM_EMAIL_DOWNLOAD_NOTIFICATION_PREFIX . WPBM_EMAIL_DOWNLOAD_NOTIFICATION_ID, get_wpbm_option( WPBM_EMAIL_DOWNLOAD_NOTIFICATION_PREFIX . WPBM_EMAIL_DOWNLOAD_NOTIFICATION_ID ) ); |
| 470 |
|
| 471 |
$this->css(); |
| 472 |
|
| 473 |
//////////////////////////////////////////////////////////////////////// |
| 474 |
// Checking |
| 475 |
//////////////////////////////////////////////////////////////////////// |
| 476 |
|
| 477 |
do_action( 'wpbm_hook_settings_page_header', array( 'page' => $this->in_page(), 'subpage' => 'emails_settings' ) ); // Define Notices Section and show some static messages, if needed. |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
//////////////////////////////////////////////////////////////////////// |
| 482 |
// Load Data |
| 483 |
//////////////////////////////////////////////////////////////////////// |
| 484 |
|
| 485 |
/** Its will load DATA from DB, during creattion mail_api CLASS |
| 486 |
* during initial activation of the API its try to get option from DB |
| 487 |
* We need to define this API before checking POST, to know all available fields |
| 488 |
* Define Email Name & define field values from DB, if not exist, then default values. |
| 489 |
Array ( |
| 490 |
[wpbm_email_download_notification] => Array |
| 491 |
( |
| 492 |
[enabled] => On |
| 493 |
[to] => [email protected] |
| 494 |
[to_name] => Some Name |
| 495 |
[from] => [email protected] |
| 496 |
[from_name] => |
| 497 |
[subject] => New item |
| 498 |
[content] => You need to approve [shortcodetype] for: ... |
| 499 |
[header_content] => |
| 500 |
[footer_content] => |
| 501 |
[template_file] => plain |
| 502 |
[base_color] => #557da1 |
| 503 |
[background_color] => #f5f5f5 |
| 504 |
[body_color] => #fdfdfd |
| 505 |
[text_color] => #505050 |
| 506 |
[email_content_type] => html |
| 507 |
) |
| 508 |
) |
| 509 |
|
| 510 |
// $mail_api->save_to_db( $fields_values ); |
| 511 |
*/ |
| 512 |
$init_fields_values = array(); |
| 513 |
|
| 514 |
$this->mail_api( WPBM_EMAIL_DOWNLOAD_NOTIFICATION_ID, $init_fields_values ); |
| 515 |
|
| 516 |
|
| 517 |
//////////////////////////////////////////////////////////////////////// |
| 518 |
// S u b m i t Actions - S e n d |
| 519 |
//////////////////////////////////////////////////////////////////////// |
| 520 |
|
| 521 |
$submit_form_name_action = 'wpbm_form_action'; // Define form name |
| 522 |
if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name_action ] ) ) { |
| 523 |
|
| 524 |
// Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. } |
| 525 |
$nonce_gen_time = check_admin_referer( 'wpbm_settings_page_' . $submit_form_name_action ); // Its stop show anything on submiting, if its not refear to the original page |
| 526 |
|
| 527 |
// Save Changes |
| 528 |
$this->update_actions(); |
| 529 |
} |
| 530 |
?> |
| 531 |
<form name="<?php echo $submit_form_name_action; ?>" id="<?php echo $submit_form_name_action; ?>" action="" method="post" autocomplete="off"> |
| 532 |
<?php |
| 533 |
// N o n c e field, and key for checking S u b m i t |
| 534 |
wp_nonce_field( 'wpbm_settings_page_' . $submit_form_name_action ); |
| 535 |
?><input type="hidden" name="is_form_sbmitted_<?php echo $submit_form_name_action; ?>" id="is_form_sbmitted_<?php echo $submit_form_name_action; ?>" value="1" /> |
| 536 |
<input type="hidden" name="form_action" id="form_action" value="" /> |
| 537 |
</form> |
| 538 |
<?php |
| 539 |
|
| 540 |
|
| 541 |
//////////////////////////////////////////////////////////////////////// |
| 542 |
// S u b m i t Main Form |
| 543 |
//////////////////////////////////////////////////////////////////////// |
| 544 |
|
| 545 |
$submit_form_name = 'wpbm_emails_template'; // Define form name |
| 546 |
|
| 547 |
$this->mail_api()->validated_form_id = $submit_form_name; // Define ID of Form for ability to validate fields before submit. |
| 548 |
|
| 549 |
if ( isset( $_POST['is_form_sbmitted_'. $submit_form_name ] ) ) { |
| 550 |
|
| 551 |
// Nonce checking {Return false if invalid, 1 if generated between, 0-12 hours ago, 2 if generated between 12-24 hours ago. } |
| 552 |
$nonce_gen_time = check_admin_referer( 'wpbm_settings_page_' . $submit_form_name ); // Its stop show anything on submiting, if its not refear to the original page |
| 553 |
|
| 554 |
// Save Changes |
| 555 |
$this->update(); |
| 556 |
} |
| 557 |
|
| 558 |
|
| 559 |
//////////////////////////////////////////////////////////////////////// |
| 560 |
// JavaScript: Tooltips, Popover, Datepick (js & css) |
| 561 |
//////////////////////////////////////////////////////////////////////// |
| 562 |
|
| 563 |
echo '<span class="wpdevelop">'; |
| 564 |
|
| 565 |
wpbm_js_for_items_page(); |
| 566 |
|
| 567 |
echo '</span>'; |
| 568 |
|
| 569 |
|
| 570 |
//////////////////////////////////////////////////////////////////////// |
| 571 |
// Content |
| 572 |
//////////////////////////////////////////////////////////////////////// |
| 573 |
?> |
| 574 |
<div class="clear" style="margin-bottom:10px;"></div> |
| 575 |
|
| 576 |
<span class="metabox-holder"> |
| 577 |
|
| 578 |
<form name="<?php echo $submit_form_name; ?>" id="<?php echo $submit_form_name; ?>" action="" method="post" autocomplete="off"> |
| 579 |
<?php |
| 580 |
// N o n c e field, and key for checking S u b m i t |
| 581 |
wp_nonce_field( 'wpbm_settings_page_' . $submit_form_name ); |
| 582 |
?><input type="hidden" name="is_form_sbmitted_<?php echo $submit_form_name; ?>" id="is_form_sbmitted_<?php echo $submit_form_name; ?>" value="1" /> |
| 583 |
|
| 584 |
|
| 585 |
<div class="clear"></div> |
| 586 |
<div class="metabox-holder"> |
| 587 |
|
| 588 |
<div class="wpbm_settings_row wpbm_settings_row_left" > |
| 589 |
<?php |
| 590 |
|
| 591 |
wpbm_open_meta_box_section( $submit_form_name . 'general', __('Email about download notification, which is sending to admin', 'booking-manager') ); |
| 592 |
|
| 593 |
$this->mail_api()->show( 'general' ); |
| 594 |
|
| 595 |
wpbm_close_meta_box_section(); |
| 596 |
|
| 597 |
|
| 598 |
wpbm_open_meta_box_section( $submit_form_name . 'parts' , __('Header / Footer', 'booking-manager') ); |
| 599 |
|
| 600 |
$this->mail_api()->show( 'parts' ); |
| 601 |
|
| 602 |
wpbm_close_meta_box_section(); |
| 603 |
|
| 604 |
|
| 605 |
wpbm_open_meta_box_section( $submit_form_name . 'style' , __('Email Styles', 'booking-manager') ); |
| 606 |
|
| 607 |
$this->mail_api()->show( 'style' ); |
| 608 |
|
| 609 |
wpbm_close_meta_box_section(); |
| 610 |
|
| 611 |
?> |
| 612 |
</div> |
| 613 |
|
| 614 |
<div class="wpbm_settings_row wpbm_settings_row_right"> |
| 615 |
<?php |
| 616 |
|
| 617 |
wpbm_open_meta_box_section( $submit_form_name . 'actions', __('Actions', 'booking-manager') ); |
| 618 |
|
| 619 |
?><a class="button button-secondary" style="margin:0 0 5px;" href="javascript:void(0)" |
| 620 |
onclick="javascript: jQuery('#form_action').val('test_send'); jQuery('form#<?php echo $submit_form_name_action; ?>').trigger( 'submit' );" |
| 621 |
><?php _e('Send Test Email', 'booking-manager'); ?></a><?php |
| 622 |
|
| 623 |
?><input type="submit" value="<?php _e('Save Changes', 'booking-manager'); ?>" class="button button-primary right" style="margin:0 0 5px 5px;" /><?php |
| 624 |
|
| 625 |
/* ?> |
| 626 |
<a class="button button-secondary" href="javascript:void(0)" ><?php _e('Preview Email', 'booking-manager'); ?></a> |
| 627 |
<hr /> |
| 628 |
<a class="button button-secondary right" |
| 629 |
href="javascript:void(0)" |
| 630 |
onclick="javascript: if ( wpbm_are_you_sure('<?php echo esc_js(__('Do you really want to delete this item?', 'booking-manager')); ?>') ){ |
| 631 |
jQuery('#form_action').val('delete'); |
| 632 |
jQuery('form#<?php echo $submit_form_name_action; ?>').trigger( 'submit' ); |
| 633 |
}" |
| 634 |
><?php _e('Delete Email', 'booking-manager'); ?></a> |
| 635 |
<?php */ |
| 636 |
|
| 637 |
?><div class="clear"></div><?php |
| 638 |
|
| 639 |
wpbm_close_meta_box_section(); |
| 640 |
|
| 641 |
wpbm_open_meta_box_section( $submit_form_name . 'email_content_type', __('Type', 'booking-manager') ); |
| 642 |
|
| 643 |
$this->mail_api()->show( 'email_content_type' ); |
| 644 |
|
| 645 |
wpbm_close_meta_box_section(); |
| 646 |
|
| 647 |
|
| 648 |
wpbm_open_meta_box_section( $submit_form_name . 'help', __('Help', 'booking-manager') ); |
| 649 |
|
| 650 |
$this->mail_api()->show( 'help' ); |
| 651 |
|
| 652 |
wpbm_close_meta_box_section(); |
| 653 |
|
| 654 |
?> |
| 655 |
</div> |
| 656 |
<div class="clear"></div> |
| 657 |
</div> |
| 658 |
|
| 659 |
<input type="submit" value="<?php _e('Save Changes', 'booking-manager'); ?>" class="button button-primary" /> |
| 660 |
</form> |
| 661 |
</span> |
| 662 |
<?php |
| 663 |
|
| 664 |
$this->enqueue_js(); |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
/** |
| 669 |
* Update form from Toolbar - create / delete/ load email templates |
| 670 |
* |
| 671 |
* @return boolean |
| 672 |
*/ |
| 673 |
public function update_actions( ) { |
| 674 |
|
| 675 |
|
| 676 |
if ( $_POST['form_action'] == 'test_send' ) { // Sending test email |
| 677 |
|
| 678 |
/* |
| 679 |
$this->email_settings_api = false; |
| 680 |
$selected_email_name = 'standard'; |
| 681 |
$email_fields = get_wpbm_option( 'wpbm_email_' . $selected_email_name ); |
| 682 |
$this->mail_api( $selected_email_name, $email_fields ); |
| 683 |
*/ |
| 684 |
|
| 685 |
|
| 686 |
//$to = sanitize_email( $this->mail_api()->fields_values['to'] ); |
| 687 |
$replace = array (); |
| 688 |
$replace[ 'product_id' ] = '<strong>99</strong>'; |
| 689 |
$replace[ 'product_title' ] = '<strong>Product ZZZ</strong>'; |
| 690 |
$replace[ 'product_version' ] = '<strong>1.0</strong>'; |
| 691 |
$replace[ 'product_description' ] = 'Product ZZZ Info'; |
| 692 |
$replace[ 'product_filename' ] = 'zzz_product.zip'; |
| 693 |
$replace[ 'product_link' ] = home_url(); |
| 694 |
$replace[ 'product_size' ] = '3 Mb'; |
| 695 |
$replace[ 'product_expire_after' ] = '1 day'; |
| 696 |
$replace[ 'product_expire_date' ] = date_i18n( get_wpbm_option( 'wpbm_date_format' ) . ' ' . get_wpbm_option( 'wpbm_time_format' ), strtotime( '+1 day' ) ); |
| 697 |
$replace[ 'product_summary' ] = '<a href="">' . $replace[ 'product_filename' ] . '</a> (' . $replace[ 'product_size' ] . ') ~ expire in ' . $replace[ 'product_expire_after' ]; |
| 698 |
|
| 699 |
$replace[ 'link_sent_to' ] = $this->mail_api()->get_from__email_address(); |
| 700 |
|
| 701 |
$replace[ 'siteurl' ] = htmlspecialchars_decode( '<a href="' . home_url() . '">' . home_url() . '</a>' ); |
| 702 |
$replace[ 'remote_ip' ] = wpbm_get_user_ip(); // The IP address from which the user is viewing the current page. |
| 703 |
$replace[ 'user_agent' ] = $_SERVER[ 'HTTP_USER_AGENT' ]; // Contents of the User-Agent: header from the current request, if there is one. |
| 704 |
$replace[ 'request_url' ] = $_SERVER[ 'HTTP_REFERER' ]; // The address of the page (if any) where action was occured. Because we are sending it in Ajax request, we need to use the REFERER HTTP |
| 705 |
$replace[ 'current_date' ] = date_i18n( get_wpbm_option( 'wpbm_date_format' ) ); |
| 706 |
$replace[ 'current_time' ] = date_i18n( get_wpbm_option( 'wpbm_time_format' ) ); |
| 707 |
|
| 708 |
|
| 709 |
$to = $this->mail_api()->get_from__email_address(); |
| 710 |
$to_name = $this->mail_api()->get_from__name(); |
| 711 |
$to = trim( $to_name ) . ' <' . $to . '> '; |
| 712 |
|
| 713 |
$email_result = $this->mail_api()->send( $to , $replace ); |
| 714 |
|
| 715 |
if ( $email_result ) |
| 716 |
wpbm_show_message ( __('Email sent to ', 'booking-manager') . ' ' . $this->mail_api()->get_from__email_address() , 5 ); |
| 717 |
else |
| 718 |
wpbm_show_message ( __('Email was not sent. An error occurred.', 'booking-manager'), 5 ,'error' ); |
| 719 |
} |
| 720 |
|
| 721 |
/* |
| 722 |
if ( $_POST['form_action'] == 'create' ) { // Create |
| 723 |
|
| 724 |
$email_title = esc_attr( $_POST['create_email_template'] ); |
| 725 |
$email_name = wpbm_get_slug_format_4_option_name( $email_title ); |
| 726 |
|
| 727 |
$wpbm_email_tpl_names = get_wpbm_option( 'wpbm_email_tpl_names' ); |
| 728 |
if ( empty( $wpbm_email_tpl_names ) ) $wpbm_email_tpl_names = array(); |
| 729 |
|
| 730 |
|
| 731 |
if ( empty($email_name) || isset( $wpbm_email_tpl_names[ $email_name ] ) ) { // Error |
| 732 |
wpbm_show_message ( __('Email template has not added.', 'booking-manager'), 5 , 'error' ); |
| 733 |
return false; |
| 734 |
} |
| 735 |
|
| 736 |
$wpbm_email_tpl_names[ $email_name ]= stripslashes( $email_title ); |
| 737 |
|
| 738 |
update_wpbm_option( 'wpbm_email_tpl_names', $wpbm_email_tpl_names ); |
| 739 |
|
| 740 |
wpbm_show_message ( __('Email template added successfully', 'booking-manager'), 5 ); // Show Save message |
| 741 |
|
| 742 |
$redir = esc_url( add_query_arg( array('email_template' => $email_name ), html_entity_decode( $this->getUrl() ) ) ); |
| 743 |
|
| 744 |
wpbm_reload_page_by_js( $redir ); |
| 745 |
|
| 746 |
return true; |
| 747 |
} |
| 748 |
|
| 749 |
if ( $_POST['form_action'] == 'delete' ) { // Delete |
| 750 |
$email_name = esc_attr( $_POST['select_email_template'] ); |
| 751 |
|
| 752 |
$wpbm_email_tpl_names = get_wpbm_option( 'wpbm_email_tpl_names' ); |
| 753 |
if ( empty( $wpbm_email_tpl_names ) ) $wpbm_email_tpl_names = array(); |
| 754 |
|
| 755 |
if ( ! isset( $wpbm_email_tpl_names[ $email_name ] ) ) { // Error |
| 756 |
wpbm_show_message ( __('Email template does not exist.', 'booking-manager'), 5 , 'error' ); |
| 757 |
return false; |
| 758 |
} |
| 759 |
|
| 760 |
unset($wpbm_email_tpl_names[ $email_name ]); // Remove Email name from list of email names |
| 761 |
update_wpbm_option( 'wpbm_email_tpl_names', $wpbm_email_tpl_names ); |
| 762 |
|
| 763 |
delete_wpbm_option( 'wpbm_email_' . $email_name ); // Delete Email Template |
| 764 |
|
| 765 |
wpbm_show_message ( __('Email template deleted successfully', 'booking-manager'), 5 ); // Show Save message |
| 766 |
|
| 767 |
|
| 768 |
$redir = esc_url( remove_query_arg( array( 'email_template' ), html_entity_decode( $this->getUrl() ) ) ); // Load standard email template |
| 769 |
|
| 770 |
wpbm_reload_page_by_js( $redir ); |
| 771 |
|
| 772 |
return true; |
| 773 |
|
| 774 |
} |
| 775 |
|
| 776 |
if ( $_POST['form_action'] == 'load' ) { // Load |
| 777 |
$email_name = $_POST['select_email_template']; |
| 778 |
|
| 779 |
$wpbm_email_tpl_names = get_wpbm_option( 'wpbm_email_tpl_names' ); |
| 780 |
if ( empty( $wpbm_email_tpl_names ) ) $wpbm_email_tpl_names = array(); |
| 781 |
|
| 782 |
if ( ! isset( $wpbm_email_tpl_names[ $email_name ] ) ) { // Error |
| 783 |
wpbm_show_message ( __('Email template does not exist.', 'booking-manager'), 5 , 'error' ); |
| 784 |
return false; |
| 785 |
} |
| 786 |
|
| 787 |
} |
| 788 |
*/ |
| 789 |
} |
| 790 |
|
| 791 |
|
| 792 |
/** Update Email template to DB */ |
| 793 |
public function update() { |
| 794 |
|
| 795 |
// Get Validated Email fields |
| 796 |
$validated_fields = $this->mail_api()->validate_post(); |
| 797 |
|
| 798 |
//debuge($validated_fields); |
| 799 |
// Remove <p> at begining and </p> at END of email template. |
| 800 |
if ( |
| 801 |
( substr( $validated_fields['content'], 0, 3) === '<p>' ) |
| 802 |
&& ( substr( $validated_fields['content'], -4 ) === '</p>' ) |
| 803 |
) { |
| 804 |
$validated_fields['content'] = substr ( $validated_fields['content'], 3, ( strlen ( $validated_fields['content'] ) - 7 ) ); |
| 805 |
} |
| 806 |
|
| 807 |
$this->mail_api()->save_to_db( $validated_fields ); |
| 808 |
|
| 809 |
wpbm_show_message ( __('Settings saved.', 'booking-manager'), 5 ); // Show Save message |
| 810 |
} |
| 811 |
|
| 812 |
// <editor-fold defaultstate="collapsed" desc=" CSS & JS " > |
| 813 |
|
| 814 |
/** CSS for this page */ |
| 815 |
private function css() { |
| 816 |
?> |
| 817 |
<style type="text/css"> |
| 818 |
.wpbm-help-message { |
| 819 |
border:none; |
| 820 |
margin:0 !important; |
| 821 |
padding:0 !important; |
| 822 |
} |
| 823 |
|
| 824 |
@media (max-width: 399px) { |
| 825 |
} |
| 826 |
</style> |
| 827 |
<?php |
| 828 |
} |
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
/** Add Custon JavaScript - for some specific settings options |
| 833 |
* Executed After post content, after initial definition of settings, and possible definition after POST request. |
| 834 |
* |
| 835 |
* @param type $menu_slug |
| 836 |
* |
| 837 |
*/ |
| 838 |
private function enqueue_js(){ // $page_tag, $active_page_tab, $active_page_subtab ) { |
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
// Check if this correct page ///////////////////////////////////////////// |
| 843 |
|
| 844 |
// if ( !( |
| 845 |
// ( $page_tag == 'wpbm-settings') // Load only at 'wpbm-settings' menu |
| 846 |
// && ( $_GET['tab'] == 'email' ) // At ''general' tab |
| 847 |
// && ( ( ! isset( $_GET['subtab'] ) ) || ( $_GET['subtab'] == 'new-admin' ) ) |
| 848 |
// ) |
| 849 |
// ) return; |
| 850 |
|
| 851 |
// JavaScript ////////////////////////////////////////////////////////////// |
| 852 |
|
| 853 |
$js_script = ''; |
| 854 |
//Show or hide colors section in settings page depend form selected email template. |
| 855 |
$js_script .= " jQuery('select[name=\"download_notification_template_file\"]').on( 'change', function(){ |
| 856 |
if ( jQuery('select[name=\"download_notification_template_file\"] option:selected').val() == 'plain' ) { |
| 857 |
jQuery('.template_colors').hide(); |
| 858 |
} else { |
| 859 |
jQuery('.template_colors').show(); |
| 860 |
} |
| 861 |
} ); "; |
| 862 |
$js_script .= "\n"; //New Line |
| 863 |
$js_script .= " if ( jQuery('select[name=\"download_notification_template_file\"] option:selected').val() == 'plain' ) { |
| 864 |
jQuery('.template_colors').hide(); |
| 865 |
} "; |
| 866 |
|
| 867 |
// Show Warning messages if Title (optional) is empty - title of email will be "WordPress |
| 868 |
$js_script .= " jQuery(document).ready(function(){ "; |
| 869 |
$js_script .= " if ( jQuery('#download_notification_to_name').val() == '' ) {"; |
| 870 |
$js_script .= " jQuery('#download_notification_to_name').parent().append('<div class=\'updated\' style=\'border-left-color:#ffb900;padding:5px 10px;\'>". esc_js(__('If empty then title defined as WordPress', 'booking-manager'))."</div>')"; |
| 871 |
$js_script .= " }"; |
| 872 |
$js_script .= " if ( jQuery('#download_notification_from_name').val() == '' ) {"; |
| 873 |
$js_script .= " jQuery('#download_notification_from_name').parent().append('<div class=\'updated\' style=\'border-left-color:#ffb900;padding:5px 10px;\'>". esc_js(__('If empty then title defined as WordPress', 'booking-manager'))."</div>')"; |
| 874 |
$js_script .= " }"; |
| 875 |
$js_script .= " }); "; |
| 876 |
// Show Warning messages if "From" Email DNS different from current website DNS |
| 877 |
$js_script .= " jQuery(document).ready(function(){ "; |
| 878 |
|
| 879 |
$js_script .= " var wpbm_email_from = jQuery('#download_notification_from').val();"; // [email protected] |
| 880 |
$js_script .= " wpbm_email_from = wpbm_email_from.split('@');"; // ['from', 'oplugins.com'] |
| 881 |
$js_script .= " wpbm_email_from.shift();"; // ['oplugins.com'] |
| 882 |
$js_script .= " wpbm_email_from = wpbm_email_from.join('');"; // 'oplugins.com' |
| 883 |
|
| 884 |
$js_script .= " var wpbm_website_dns = jQuery(location).attr('hostname');"; // server.com |
| 885 |
$js_script .= " if ( wpbm_email_from != wpbm_website_dns ) {"; |
| 886 |
$js_script .= " jQuery('#download_notification_from').parent().append('<div class=\'updated\' style=\'border-left-color:#ffb900;padding:5px 10px;\'>". esc_js(__('Email different from website DNS, its can be a reason of not delivery emails. Please use the email withing the same domain as your website!', 'booking-manager'))."</div>')"; |
| 887 |
$js_script .= " }"; |
| 888 |
|
| 889 |
$js_script .= " }); "; |
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
// Eneque JS to the footer of the page |
| 894 |
wpbm_enqueue_js( $js_script ); |
| 895 |
} |
| 896 |
|
| 897 |
|
| 898 |
// </editor-fold> |
| 899 |
} |
| 900 |
add_action('wpbm_menu_created', array( new WPBM_Settings_Page_Email_DownloadNotification() , '__construct') ); // Executed after creation of Menu |
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
// <editor-fold defaultstate="collapsed" desc=" Emails Sending After Download action " > |
| 905 |
|
| 906 |
function wpbm_send_email_download_notification( $replace = array(), $email_to = '' ) { |
| 907 |
|
| 908 |
|
| 909 |
//////////////////////////////////////////////////////////////////////// |
| 910 |
// Load Data |
| 911 |
//////////////////////////////////////////////////////////////////////// |
| 912 |
|
| 913 |
/* Check if New Email Template Exist or NOT |
| 914 |
* Exist - return empty array in format: array( OPTION_NAME => array() ) |
| 915 |
* Its will load DATA from DB, during creattion mail_api CLASS |
| 916 |
* during initial activation of the API its try to get option from DB |
| 917 |
* We need to define this API before checking POST, to know all available fields |
| 918 |
* Define Email Name & define field values from DB, if not exist, then default values. |
| 919 |
* Not Exist - import Old Data from DB |
| 920 |
* or get "default" data from settings and return array with this data |
| 921 |
* This data its initial parameters for definition fields in mail_api CLASS |
| 922 |
* |
| 923 |
*/ |
| 924 |
|
| 925 |
$init_fields_values = array();//wpbm_import6_email__download_notification__get_fields_array_for_activation(); |
| 926 |
|
| 927 |
// Get Value of first element - array of default or imported OLD data, because need only array of values without key - name of options for wp_options table |
| 928 |
//$init_fields_values = array_shift( array_values( $init_fields_values ) ); |
| 929 |
|
| 930 |
$mail_api = new WPBM_Emails_API_DownloadNotification( WPBM_EMAIL_DOWNLOAD_NOTIFICATION_ID, $init_fields_values ); |
| 931 |
|
| 932 |
//////////////////////////////////////////////////////////////////////////// |
| 933 |
|
| 934 |
if ( $mail_api->fields_values['enabled'] == 'Off' ) return false; // Email template deactivated - exit. |
| 935 |
|
| 936 |
add_filter( 'wpbm_email_api_is_allow_send_copy' , 'wpbm_email_api_is_allow_send_copy_block' , 10, 3); |
| 937 |
|
| 938 |
// Email |
| 939 |
if ( ! empty( $mail_api->fields_values['to'] ) ) // Admin email from Settings > Emails page |
| 940 |
$valid_email = sanitize_email( $mail_api->fields_values['to'] ); |
| 941 |
// Overwrite email, if passed to function |
| 942 |
if ( ! empty( $to_email ) ) |
| 943 |
$valid_email = sanitize_email( $to_email ); |
| 944 |
|
| 945 |
if ( empty( $valid_email ) ) return $mail_api; //return false; |
| 946 |
|
| 947 |
// Name |
| 948 |
if ( ! empty( $mail_api->fields_values['to_name'] ) ) |
| 949 |
$email_to_name = trim( wp_specialchars_decode( esc_html( stripslashes( $mail_api->fields_values['to_name'] ) ), ENT_QUOTES ) ); |
| 950 |
else |
| 951 |
$email_to_name = ''; |
| 952 |
|
| 953 |
|
| 954 |
$to = $email_to_name . ' <' . $valid_email . '> '; |
| 955 |
$email_result = $mail_api->send( $to , $replace ); |
| 956 |
|
| 957 |
//debuge( (int) $email_result, $to , $replace); |
| 958 |
|
| 959 |
return $mail_api; |
| 960 |
|
| 961 |
} |
| 962 |
|
| 963 |
// </editor-fold> |