| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_Chatbot_Welcome' ) ) : |
| 7 |
|
| 8 |
final class WPSC_Chatbot_Welcome { |
| 9 |
|
| 10 |
/** |
| 11 |
* Initialize this class |
| 12 |
* |
| 13 |
* @return void |
| 14 |
*/ |
| 15 |
public static function init() { |
| 16 |
|
| 17 |
// get_welcome_template() is only ever needed on demand, via |
| 18 |
// WPSC_ACB_Admin::frontend_config() - no separate 'init' hook call needed. |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Get chatbot greeting/welcome message text. |
| 23 |
* |
| 24 |
* Single source for the assistant's greeting - reused by the welcome |
| 25 |
* message bubble inside an open chat, the initial page-load markup, and |
| 26 |
* the auto-popup greeting tooltip anchored to the launcher, so they never |
| 27 |
* drift out of sync. The admin-configured value (Appearance settings) |
| 28 |
* is run through WPML String Translation, falling back to the plugin's |
| 29 |
* default text (and plain WP translation) when nothing's been saved yet. |
| 30 |
* |
| 31 |
* @return string |
| 32 |
*/ |
| 33 |
public static function get_greeting_text() { |
| 34 |
|
| 35 |
$appearance_settings = WPSC_ACB_Appearance_Setting::get_appearance_settings(); |
| 36 |
return WPSC_ACB_Appearance_Setting::translate( 'Chatbot greeting message', $appearance_settings['greeting-text'] ); |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Get chatbot welcome template |
| 41 |
* |
| 42 |
* @return string |
| 43 |
*/ |
| 44 |
public static function get_welcome_template() { |
| 45 |
|
| 46 |
ob_start(); |
| 47 |
?> |
| 48 |
<div class="wpsc-chatbot__system__message"> |
| 49 |
<?php echo esc_html( self::get_greeting_text() ); ?> |
| 50 |
<div class="wpsc-chatbot__message-meta"> |
| 51 |
<span><?php esc_html_e( 'Assistant', 'supportcandy' ); ?></span> |
| 52 |
<span class="wpsc-chatbot__welcome-time"></span> |
| 53 |
</div> |
| 54 |
</div> |
| 55 |
<?php |
| 56 |
return ob_get_clean(); |
| 57 |
} |
| 58 |
} |
| 59 |
endif; |
| 60 |
WPSC_Chatbot_Welcome::init(); |
| 61 |
|