| 1 |
<?php |
| 2 |
|
| 3 |
class WpSaioInit { |
| 4 |
|
| 5 |
private static $_instance = null; |
| 6 |
private $main_menu_slug = 'wp-support-all-in-one.php'; |
| 7 |
private $admin_page_hookfix = ''; |
| 8 |
|
| 9 |
public function __construct() { |
| 10 |
add_filter( 'plugin_action_links_' . WP_SAIO_BASE_NAME, array( $this, 'settings_link' ) ); |
| 11 |
/* |
| 12 |
* Load Text Domain |
| 13 |
*/ |
| 14 |
add_action( 'plugins_loaded', array( $this, 'loadTextDomain' ) ); |
| 15 |
|
| 16 |
/* |
| 17 |
* Register Enqueue |
| 18 |
*/ |
| 19 |
add_action( 'admin_enqueue_scripts', array( $this, 'registerAdminEnqueue' ) ); |
| 20 |
add_action( 'wp_enqueue_scripts', array( $this, 'registerEnqueue' ) ); |
| 21 |
|
| 22 |
/* |
| 23 |
* Register Menu |
| 24 |
*/ |
| 25 |
add_action( 'admin_menu', array( $this, 'registerAdminMenu' ) ); |
| 26 |
|
| 27 |
/* |
| 28 |
* Admin head |
| 29 |
*/ |
| 30 |
add_action( 'admin_head', array( $this, 'adminHead' ) ); |
| 31 |
|
| 32 |
/* |
| 33 |
* WP Footer |
| 34 |
*/ |
| 35 |
add_action( 'wp_footer', array( $this, 'wpFooter' ) ); |
| 36 |
|
| 37 |
/* |
| 38 |
* Register Shortcode |
| 39 |
*/ |
| 40 |
WpSaioShortcodes::instance(); |
| 41 |
|
| 42 |
/* |
| 43 |
* Register Ajax |
| 44 |
*/ |
| 45 |
WpSaioAjax::instance(); |
| 46 |
|
| 47 |
/* |
| 48 |
* Register Helper |
| 49 |
*/ |
| 50 |
WpSaioHelper::instance(); |
| 51 |
|
| 52 |
add_action( 'admin_init', array( $this, 'registerSettings' ) ); |
| 53 |
} |
| 54 |
public static function instance() { |
| 55 |
if ( is_null( self::$_instance ) ) { |
| 56 |
self::$_instance = new self(); |
| 57 |
} |
| 58 |
return self::$_instance; |
| 59 |
} |
| 60 |
public function registerAdminEnqueue( $hook_suffix ) { |
| 61 |
if ( $hook_suffix !== $this->admin_page_hookfix ) { |
| 62 |
return; |
| 63 |
} |
| 64 |
wp_register_style( 'wp-saio', WP_SAIO_URL . '/assets/admin/css/wp-saio.css' ); |
| 65 |
wp_register_style( 'wp-saio-preview', WP_SAIO_URL . '/assets/home/css/wp-saio.css' ); |
| 66 |
wp_register_style( 'ui-range', WP_SAIO_URL . '/assets/admin/css/ui-range.css' ); |
| 67 |
wp_enqueue_style( 'wp-saio' ); |
| 68 |
wp_enqueue_style( 'wp-saio-preview' ); |
| 69 |
wp_style_add_data( 'wp-saio', 'rtl', 'replace' ); |
| 70 |
wp_style_add_data( 'wp-saio-preview', 'rtl', 'replace' ); |
| 71 |
wp_enqueue_style( 'ui-range' ); |
| 72 |
|
| 73 |
wp_enqueue_script( 'jquery-ui-sortable' ); |
| 74 |
wp_enqueue_style( 'wp-color-picker' ); |
| 75 |
wp_enqueue_script( 'sortable', WP_SAIO_URL . '/assets/admin/js/Sortable.min.js' ); |
| 76 |
|
| 77 |
wp_register_script( 'wp-saio', WP_SAIO_URL . '/assets/admin/js/admin.js', array( 'jquery', 'jquery-ui-sortable', 'wp-color-picker' ) ); |
| 78 |
wp_enqueue_script( 'wp-saio' ); |
| 79 |
wp_register_script( 'wp-saio-preview', WP_SAIO_URL . '/assets/home/js/wp-saio.min.js' ); |
| 80 |
wp_enqueue_script( 'wp-saio-preview' ); |
| 81 |
wp_enqueue_media(); |
| 82 |
|
| 83 |
wp_localize_script( |
| 84 |
'wp-saio', |
| 85 |
'wp_saio_object', |
| 86 |
array( |
| 87 |
'are_you_sure' => __( 'Are you sure you want to remove this app. All data will be erase?', WP_SAIO_LANG_PREFIX ), |
| 88 |
'wp_saio_html_inputs' => json_encode( WpSaio::renderForm() ), |
| 89 |
'add_media_text_title' => __( 'Choose Image', WP_SAIO_LANG_PREFIX ), |
| 90 |
'add_media_text_button' => __( 'Choose Image', WP_SAIO_LANG_PREFIX ), |
| 91 |
'style' => get_option( 'wpsaio_style' ), |
| 92 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 93 |
'nonce' => wp_create_nonce( 'wpsaio_nonce' ), |
| 94 |
) |
| 95 |
); |
| 96 |
} |
| 97 |
public function registerEnqueue() { |
| 98 |
if ( ! $this->isActivePlugin() ) { |
| 99 |
return false; |
| 100 |
} |
| 101 |
wp_register_style( 'wp-saio', WP_SAIO_URL . '/assets/home/css/wp-saio.css' ); |
| 102 |
wp_enqueue_style( 'wp-saio' ); |
| 103 |
wp_style_add_data( 'wp-saio', 'rtl', 'replace' ); |
| 104 |
|
| 105 |
wp_register_script( 'wp-saio', WP_SAIO_URL . '/assets/home/js/wp-saio.min.js', array( 'jquery' ) ); |
| 106 |
wp_enqueue_script( 'wp-saio' ); |
| 107 |
|
| 108 |
wp_localize_script( |
| 109 |
'wp-saio', |
| 110 |
'wp_saio_object', |
| 111 |
array( |
| 112 |
'style' => get_option( 'wpsaio_style' ), |
| 113 |
) |
| 114 |
); |
| 115 |
} |
| 116 |
public function loadTextDomain() { |
| 117 |
if ( function_exists( 'determine_locale' ) ) { |
| 118 |
$locale = determine_locale(); |
| 119 |
} else { |
| 120 |
$locale = is_admin() ? get_user_locale() : get_locale(); |
| 121 |
} |
| 122 |
unload_textdomain( 'wp_saio' ); |
| 123 |
load_textdomain( 'wp_saio', WP_SAIO_DIR . '/languages/' . $locale . '.mo' ); |
| 124 |
load_plugin_textdomain( 'wp_saio', false, WP_SAIO_DIR . '/languages' ); |
| 125 |
} |
| 126 |
public function registerAdminMenu() { |
| 127 |
$page_title = __( 'Support Chat All In One', WP_SAIO_LANG_PREFIX ); |
| 128 |
$menu_title = __( 'Click to Chat', WP_SAIO_LANG_PREFIX ); |
| 129 |
|
| 130 |
$this->admin_page_hookfix = add_menu_page( $page_title, $menu_title, 'manage_options', $this->main_menu_slug, array( $this, 'wpSaioMenuCallBack' ), WP_SAIO_URL . '/assets/admin/img/support-icon.svg' ); |
| 131 |
} |
| 132 |
public function wpsaioLoadMainMenu() { |
| 133 |
global $plugin_page; |
| 134 |
$data = array(); |
| 135 |
if ( isset( $_POST['save-wp-saio'] ) && isset( $_POST['data'] ) ) { |
| 136 |
$_data = WpSaioHelper::sanitize_array( $_POST['data'] ); |
| 137 |
foreach ( $_data as $k => $v ) { |
| 138 |
$data[ $k ]['params'] = array(); |
| 139 |
foreach ( $v as $k2 => $v2 ) { |
| 140 |
$data[ $k ]['params'][ $k2 ] = wp_unslash( trim( $v2 ) ); |
| 141 |
} |
| 142 |
} |
| 143 |
update_option( 'njt_wp_saio', $data ); |
| 144 |
|
| 145 |
wp_safe_redirect( |
| 146 |
esc_url( |
| 147 |
add_query_arg( array( 'page' => $this->main_menu_slug ), admin_url( 'admin.php' ) ) |
| 148 |
) |
| 149 |
); |
| 150 |
} |
| 151 |
} |
| 152 |
public function adminHead() { |
| 153 |
} |
| 154 |
public function wpFooter() { |
| 155 |
if ( ! $this->isActivePlugin() ) { |
| 156 |
return; |
| 157 |
} |
| 158 |
$icon_bg_color = get_option( 'wpsaio_button_color', '' ); |
| 159 |
$btn_icon = get_option( 'wpsaio_button_icon', '' ); |
| 160 |
$btn_image = get_option( 'wpsaio_button_image', 'contain' ); |
| 161 |
$data = array( |
| 162 |
'buttons' => WpSaio::generateFrontendButtons(), |
| 163 |
'contents' => do_shortcode( implode( '', WpSaio::renderShortcodes() ) ), |
| 164 |
'icon_bg_color' => $icon_bg_color, |
| 165 |
'btn_icon' => $btn_icon, |
| 166 |
'btn_image' => $btn_image, |
| 167 |
); |
| 168 |
echo WpSaioView::load( 'home.main', $data ); |
| 169 |
} |
| 170 |
private function isActivePlugin() { |
| 171 |
return ( get_option( 'wpsaio_enable_plugin' ) == 1 ); |
| 172 |
} |
| 173 |
|
| 174 |
public function wpSaioMenuCallBack() { |
| 175 |
?> |
| 176 |
<div id="wpsaio" class="wpsaio wp-saio-wrap wrap"> |
| 177 |
<h1><?php _e( 'Support Chat AIO', WP_SAIO_LANG_PREFIX ); ?></h1> |
| 178 |
<div class="notice notice-success settings-error is-dismissible" style="display: none"> |
| 179 |
<div class="wpsaio__popup_notice"> |
| 180 |
<p> |
| 181 |
<strong>Settings saved. |
| 182 |
<button class="notice-dismiss"> |
| 183 |
<span class="screen-reader-text">Dismiss this notice.</span> |
| 184 |
</button> |
| 185 |
</strong> |
| 186 |
</p> |
| 187 |
</div> |
| 188 |
</div> |
| 189 |
<div class="wpsaio-row"> |
| 190 |
<div class="wpsaio-col-main"> |
| 191 |
<div class="wp-saio-tab-wrap"> |
| 192 |
<ul class="njt-nav-tabs"> |
| 193 |
<li class="njt-nav-item"> |
| 194 |
<a class="njt-nav-link njt-nav-link-active" href="#saio-apps" data-njt-tab="#saio-apps"> |
| 195 |
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"> |
| 196 |
<path d="M296 32h192c13.255 0 24 10.745 24 24v160c0 13.255-10.745 24-24 24H296c-13.255 0-24-10.745-24-24V56c0-13.255 10.745-24 24-24zm-80 0H24C10.745 32 0 42.745 0 56v160c0 13.255 10.745 24 24 24h192c13.255 0 24-10.745 24-24V56c0-13.255-10.745-24-24-24zM0 296v160c0 13.255 10.745 24 24 24h192c13.255 0 24-10.745 24-24V296c0-13.255-10.745-24-24-24H24c-13.255 0-24 10.745-24 24zm296 184h192c13.255 0 24-10.745 24-24V296c0-13.255-10.745-24-24-24H296c-13.255 0-24 10.745-24 24v160c0 13.255 10.745 24 24 24z"></path> |
| 197 |
</svg>Choose Apps |
| 198 |
</a> |
| 199 |
</li> |
| 200 |
<li class="njt-nav-item"> |
| 201 |
<a class="njt-nav-link" href="#saio-design" data-njt-tab="#saio-design"> |
| 202 |
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"> |
| 203 |
<path d="M204.3 5C104.9 24.4 24.8 104.3 5.2 203.4c-37 187 131.7 326.4 258.8 306.7 41.2-6.4 61.4-54.6 42.5-91.7-23.1-45.4 9.9-98.4 60.9-98.4h79.7c35.8 0 64.8-29.6 64.9-65.3C511.5 97.1 368.1-26.9 204.3 5zM96 320c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm32-128c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm128-64c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm128 64c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32z"></path> |
| 204 |
</svg>Design |
| 205 |
</a> |
| 206 |
</li> |
| 207 |
<li class="njt-nav-item"> |
| 208 |
<a class="njt-nav-link" href="#saio-display" data-njt-tab="#saio-display"> |
| 209 |
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="desktop" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" class="svg-inline--fa fa-desktop fa-w-18 fa-2x"> |
| 210 |
<path fill="currentColor" d="M528 0H48C21.5 0 0 21.5 0 48v320c0 26.5 21.5 48 48 48h192l-16 48h-72c-13.3 0-24 10.7-24 24s10.7 24 24 24h272c13.3 0 24-10.7 24-24s-10.7-24-24-24h-72l-16-48h192c26.5 0 48-21.5 48-48V48c0-26.5-21.5-48-48-48zm-16 352H64V64h448v288z" class=""></path> |
| 211 |
</svg>Display |
| 212 |
</a> |
| 213 |
</li> |
| 214 |
</ul> |
| 215 |
<div class="njt-tab-content"> |
| 216 |
<div class="njt-tab-panel njt-tab-active" id="saio-apps"> |
| 217 |
<?php WpSaio::generatePanel(); ?> |
| 218 |
</div> |
| 219 |
<div class="njt-tab-panel" id="saio-design"> |
| 220 |
<?php require_once WP_SAIO_DIR . '/views/admin/design-settings.php'; ?> |
| 221 |
</div> |
| 222 |
<div class="njt-tab-panel" id="saio-display"> |
| 223 |
<?php require_once WP_SAIO_DIR . '/views/admin/display-settings.php'; ?> |
| 224 |
</div> |
| 225 |
</div> |
| 226 |
</div> |
| 227 |
</div> |
| 228 |
<div class="wpsaio-col-right"> |
| 229 |
<div id="informationdiv" class="wpsaio-postbox"> |
| 230 |
<h3>Do you need help?</h3> |
| 231 |
<div class="inside"> |
| 232 |
<p>Thanks for using NinjaTeam's Products!</p> |
| 233 |
<p>If you have any problems or suggestions, please <a href="https://ninjateam.org/support" target="_blank">contact support</a>.</p> |
| 234 |
<p>Don't forget to <a href="https://wordpress.org/support/plugin/support-chat/reviews/#new-post" target="_blank">rate us</a> if this plugin is helpful for you.</p> |
| 235 |
<p>Best wishes, |
| 236 |
<br> |
| 237 |
Kelly from NinjaTeam |
| 238 |
</p> |
| 239 |
</div> |
| 240 |
</div> |
| 241 |
</div> |
| 242 |
</div> |
| 243 |
</div> |
| 244 |
<?php |
| 245 |
} |
| 246 |
public function wpSaioMenuSettingsCallBack() { |
| 247 |
wp_enqueue_media(); |
| 248 |
echo WpSaioView::load( 'admin.settings' ); |
| 249 |
} |
| 250 |
public function registerSettings() { |
| 251 |
register_setting( 'wpsaio', 'wpsaio_enable_plugin' ); |
| 252 |
register_setting( 'wpsaio', 'wpsaio_style' ); |
| 253 |
register_setting( 'wpsaio', 'wpsaio_tooltip' ); |
| 254 |
register_setting( 'wpsaio', 'wpsaio_widget_position' ); |
| 255 |
register_setting( 'wpsaio', 'wpsaio_bottom_distance' ); |
| 256 |
register_setting( 'wpsaio', 'wpsaio_button_icon' ); |
| 257 |
register_setting( 'wpsaio', 'wpsaio_button_color' ); |
| 258 |
} |
| 259 |
public static function activate() { |
| 260 |
$installed = get_option( 'wpsaio_enable_plugin' ); |
| 261 |
|
| 262 |
if ( ! $installed ) { |
| 263 |
update_option( 'wpsaio_enable_plugin', 1 ); |
| 264 |
update_option( 'wpsaio_style', 'redirect' ); |
| 265 |
update_option( 'wpsaio_tooltip', 'appname' ); |
| 266 |
update_option( 'wpsaio_widget_position', 'right' ); |
| 267 |
update_option( 'wpsaio_button_image', 'contain' ); |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
public function deactivate() { |
| 272 |
} |
| 273 |
|
| 274 |
public function settings_link( $link ) { |
| 275 |
// add custom link |
| 276 |
$setting_link = '<a href="admin.php?page=wp-support-all-in-one.php">Settings</a>'; |
| 277 |
array_unshift( $link, $setting_link ); |
| 278 |
return $link; |
| 279 |
} |
| 280 |
} |
| 281 |
|