| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_EN_Settings' ) ) : |
| 7 |
|
| 8 |
final class WPSC_EN_Settings { |
| 9 |
|
| 10 |
/** |
| 11 |
* Set if current screen is settings page |
| 12 |
* |
| 13 |
* @var boolean |
| 14 |
*/ |
| 15 |
public static $is_current_page; |
| 16 |
|
| 17 |
/** |
| 18 |
* Sections for this view |
| 19 |
* |
| 20 |
* @var array |
| 21 |
*/ |
| 22 |
private static $sections = array(); |
| 23 |
|
| 24 |
/** |
| 25 |
* Current section to load |
| 26 |
* |
| 27 |
* @var string |
| 28 |
*/ |
| 29 |
public static $current_section; |
| 30 |
|
| 31 |
/** |
| 32 |
* Initialize this class |
| 33 |
*/ |
| 34 |
public static function init() { |
| 35 |
|
| 36 |
// Load sections for this screen. |
| 37 |
add_action( 'admin_init', array( __CLASS__, 'load_sections' ), 1 ); |
| 38 |
|
| 39 |
// Humbargar modal. |
| 40 |
add_action( 'admin_footer', array( __CLASS__, 'humbargar_menu' ) ); |
| 41 |
|
| 42 |
// Add current section to admin localization data. |
| 43 |
add_filter( 'wpsc_admin_localizations', array( __CLASS__, 'localizations' ) ); |
| 44 |
|
| 45 |
// Register ready function. |
| 46 |
add_action( 'wpsc_js_ready', array( __CLASS__, 'register_js_ready_function' ) ); |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Load section (nav elements) for this screen |
| 51 |
* |
| 52 |
* @return void |
| 53 |
*/ |
| 54 |
public static function load_sections() { |
| 55 |
|
| 56 |
self::$is_current_page = isset( $_REQUEST['page'] ) && $_REQUEST['page'] === 'wpsc-email-notifications' ? true : false; // phpcs:ignore |
| 57 |
|
| 58 |
if ( ! self::$is_current_page ) { |
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
self::$sections = apply_filters( |
| 63 |
'wpsc_email_notification_page_sections', |
| 64 |
array( |
| 65 |
'general-settings' => array( |
| 66 |
'slug' => 'general_settings', |
| 67 |
'icon' => 'control', |
| 68 |
'label' => esc_attr__( 'General Settings', 'supportcandy' ), |
| 69 |
'callback' => 'wpsc_get_en_general_setting', |
| 70 |
), |
| 71 |
'ticket-notifications' => array( |
| 72 |
'slug' => 'ticket_notifications', |
| 73 |
'icon' => 'envelope', |
| 74 |
'label' => esc_attr__( 'Ticket Notifications', 'supportcandy' ), |
| 75 |
'callback' => 'wpsc_get_ticket_notifications', |
| 76 |
), |
| 77 |
) |
| 78 |
); |
| 79 |
|
| 80 |
self::$current_section = isset( $_REQUEST['section'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['section'] ) ) : 'general-settings'; // phpcs:ignore |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Add localizations to local JS |
| 85 |
* |
| 86 |
* @param array $localizations - localization. |
| 87 |
* @return array |
| 88 |
*/ |
| 89 |
public static function localizations( $localizations ) { |
| 90 |
|
| 91 |
if ( ! self::$is_current_page ) { |
| 92 |
return $localizations; |
| 93 |
} |
| 94 |
|
| 95 |
// Humbargar Titles. |
| 96 |
$localizations['humbargar_titles'] = self::get_humbargar_titles(); |
| 97 |
|
| 98 |
// Current section. |
| 99 |
$localizations['current_section'] = self::$current_section; |
| 100 |
|
| 101 |
return $localizations; |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* UI foundation for this screen |
| 106 |
* |
| 107 |
* @return void |
| 108 |
*/ |
| 109 |
public static function layout() { |
| 110 |
?> |
| 111 |
<div class="wrap"> |
| 112 |
<hr class="wp-header-end"> |
| 113 |
<div id="wpsc-container" style="display:none;"> |
| 114 |
<div class="wpsc-header wpsc-setting-header-xs wpsc-visible-xs"> |
| 115 |
<div class="wpsc-humbargar-title"> |
| 116 |
<?php WPSC_Icons::get( self::$sections[ self::$current_section ]['icon'] ); ?> |
| 117 |
<label><?php echo esc_attr( self::$sections[ self::$current_section ]['label'] ); ?></label> |
| 118 |
</div> |
| 119 |
<div class="wpsc-humbargar" onclick="wpsc_toggle_humbargar();"> |
| 120 |
<?php WPSC_Icons::get( 'bars' ); ?> |
| 121 |
</div> |
| 122 |
</div> |
| 123 |
<div class="wpsc-settings-page"> |
| 124 |
<div class="wpsc-setting-section-container wpsc-hidden-xs"> |
| 125 |
<h2><?php esc_attr_e( 'Email Notifications', 'supportcandy' ); ?></h2> |
| 126 |
<?php |
| 127 |
foreach ( self::$sections as $key => $section ) { |
| 128 |
$active = self::$current_section === $key ? 'active' : ''; |
| 129 |
?> |
| 130 |
<div |
| 131 |
class="wpsc-setting-nav <?php echo esc_attr( $key ) . ' ' . esc_attr( $active ); ?>" |
| 132 |
onclick="<?php echo esc_attr( $section['callback'] ) . '();'; ?>"> |
| 133 |
<?php WPSC_Icons::get( $section['icon'] ); ?> |
| 134 |
<label><?php echo esc_attr( $section['label'] ); ?></label> |
| 135 |
</div> |
| 136 |
<?php |
| 137 |
} |
| 138 |
?> |
| 139 |
</div> |
| 140 |
<div class="wpsc-setting-body"></div> |
| 141 |
</div> |
| 142 |
</div> |
| 143 |
</div> |
| 144 |
<?php |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* Print humbargar menu in footer |
| 149 |
* |
| 150 |
* @return void |
| 151 |
*/ |
| 152 |
public static function humbargar_menu() { |
| 153 |
|
| 154 |
if ( ! self::$is_current_page ) { |
| 155 |
return; |
| 156 |
} |
| 157 |
?> |
| 158 |
|
| 159 |
<div class="wpsc-humbargar-overlay" onclick="wpsc_toggle_humbargar();" style="display:none"></div> |
| 160 |
<div class="wpsc-humbargar-menu" style="display:none"> |
| 161 |
<div class="box-inner"> |
| 162 |
<div class="wpsc-humbargar-close" onclick="wpsc_toggle_humbargar();"> |
| 163 |
<?php WPSC_Icons::get( 'times' ); ?> |
| 164 |
</div> |
| 165 |
<?php |
| 166 |
foreach ( self::$sections as $key => $section ) : |
| 167 |
|
| 168 |
$active = self::$current_section === $key ? 'active' : ''; |
| 169 |
?> |
| 170 |
<div |
| 171 |
class="wpsc-humbargar-menu-item <?php echo esc_attr( $key ) . ' ' . esc_attr( $active ); ?>" |
| 172 |
onclick="<?php echo esc_attr( $section['callback'] ) . '(true);'; ?>"> |
| 173 |
<?php WPSC_Icons::get( $section['icon'] ); ?> |
| 174 |
<label><?php echo esc_attr( $section['label'] ); ?></label> |
| 175 |
</div> |
| 176 |
<?php |
| 177 |
endforeach; |
| 178 |
?> |
| 179 |
</div> |
| 180 |
</div> |
| 181 |
<?php |
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* Humbargar mobile titles to be used in localizations |
| 186 |
* |
| 187 |
* @return array |
| 188 |
*/ |
| 189 |
private static function get_humbargar_titles() { |
| 190 |
|
| 191 |
$titles = array(); |
| 192 |
foreach ( self::$sections as $section ) { |
| 193 |
|
| 194 |
ob_start(); |
| 195 |
WPSC_Icons::get( $section['icon'] ); |
| 196 |
echo '<label>' . esc_attr( $section['label'] ) . '</label>'; |
| 197 |
$titles[ $section['slug'] ] = ob_get_clean(); |
| 198 |
} |
| 199 |
return $titles; |
| 200 |
} |
| 201 |
|
| 202 |
/** |
| 203 |
* Register JS functions to call on document ready |
| 204 |
* |
| 205 |
* @return void |
| 206 |
*/ |
| 207 |
public static function register_js_ready_function() { |
| 208 |
|
| 209 |
if ( ! self::$is_current_page ) { |
| 210 |
return; |
| 211 |
} |
| 212 |
echo esc_attr( self::$sections[ self::$current_section ]['callback'] ) . '();' . PHP_EOL; |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
endif; |
| 217 |
|
| 218 |
WPSC_EN_Settings::init(); |
| 219 |
|