| 1 |
<?php /** |
| 2 |
* @version 1.1 |
| 3 |
* @package Any |
| 4 |
* @category Page Structure in Admin Panel |
| 5 |
* @author wpdevelop |
| 6 |
* |
| 7 |
* @web-site https://wpbookingcalendar.com/ |
| 8 |
* @email info@wpbookingcalendar.com |
| 9 |
* |
| 10 |
* @modified 2015-11-02 |
| 11 |
*/ |
| 12 |
|
| 13 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit, if accessed directly |
| 14 |
|
| 15 |
|
| 16 |
/** Define Settings Page Structure */ |
| 17 |
abstract class WPBC_Page_Structure { |
| 18 |
|
| 19 |
protected static $nav_tabs; // Tabs array, same for all objects |
| 20 |
|
| 21 |
private $current_page_params; // Parameters for current page, if this page selected, otherwise its = empty array() |
| 22 |
private $is_only_icons = false; |
| 23 |
protected $is_use_left_navigation = false; |
| 24 |
protected $tags; // Defining Name of parameter in GET request for Navigation TOP and BOTTOM tabs |
| 25 |
// - $_GET[ 'tab' ] == 'payment' |
| 26 |
// - $_GET[ 'subtab' ] == 'paypal' |
| 27 |
|
| 28 |
public function __construct() { |
| 29 |
|
| 30 |
$this->tags = array(); |
| 31 |
$this->tags['tab'] = 'tab'; // Defining Name of parameter in GET request - $_GET[ 'tab' ] == 'payment' |
| 32 |
$this->tags['subtab'] = 'subtab'; // Defining Name of parameter in GET request - $_GET[ 'subtab' ] == 'paypal' |
| 33 |
|
| 34 |
|
| 35 |
$this->current_page_params = array(); |
| 36 |
self::$nav_tabs = array(); |
| 37 |
|
| 38 |
add_action('wpbc_define_nav_tabs', array( $this, 'wpbc_define_nav_tabs' ) ); // This Hook fire after creation menu in class WPBC_Admin_Menus |
| 39 |
|
| 40 |
add_action('wpbc_page_structure_show', array( $this, 'content_structure' ) ); // This Hook fire in the class WPBC_Admin_Menus for showing page content of specific menu |
| 41 |
} |
| 42 |
|
| 43 |
//////////////////////////////////////////////////////////////////////////// |
| 44 |
// Abstract Methods |
| 45 |
//////////////////////////////////////////////////////////////////////////// |
| 46 |
|
| 47 |
/** |
| 48 |
* Define slug in what menu to show this page. // Parameter relative: $_GET['page']. |
| 49 |
* |
| 50 |
* @return string |
| 51 |
* |
| 52 |
* Example: |
| 53 |
|
| 54 |
return 'wpbc-settings'; |
| 55 |
|
| 56 |
*/ |
| 57 |
abstract public function in_page(); |
| 58 |
|
| 59 |
/** |
| 60 |
* Define Tabs and Subtabs of this Admin Page |
| 61 |
* |
| 62 |
* @return array(); |
| 63 |
|
| 64 |
* Example: |
| 65 |
|
| 66 |
$tabs = array(); |
| 67 |
$tabs[ 'form' ] = array( |
| 68 |
'title' => __('Form','booking') // Title of TAB |
| 69 |
, 'hint' => __('Customization of Form Fields', 'booking') // Hint |
| 70 |
, 'page_title' =>ucwords( __('Form fields', 'booking') ) // Title of Page |
| 71 |
//, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link |
| 72 |
//, 'position' => '' // 'left' || 'right' || '' |
| 73 |
//, 'css_classes' => '' // CSS class(es) |
| 74 |
//, 'icon' => '' // Icon - link to the real PNG img |
| 75 |
, 'font_icon' => 'wpbc_icn_draw' // CSS definition of forn Icon |
| 76 |
, 'default' => false // Is this tab activated by default or not: true || false. |
| 77 |
, 'disabled' => false // Is this tab disbaled: true || false. |
| 78 |
, 'hided' => false // Is this tab hided: true || false. |
| 79 |
, 'subtabs' => array() |
| 80 |
|
| 81 |
); |
| 82 |
$tabs[ 'upgrade' ] = array( |
| 83 |
'title' => __('Upgrade','booking') // Title of TAB |
| 84 |
, 'hint' => __('Upgrade to higher version', 'booking') // Hint |
| 85 |
//, 'page_title' => __('Upgrade', 'booking') // Title of Page |
| 86 |
, 'link' => 'http://server.com/' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link |
| 87 |
, 'position' => 'right' // 'left' || 'right' || '' |
| 88 |
//, 'css_classes' => '' // CSS class(es) |
| 89 |
//, 'icon' => '' // Icon - link to the real PNG img |
| 90 |
, 'font_icon' => 'wpbc_icn_auto_graph'// CSS definition of forn Icon |
| 91 |
//, 'default' => false // Is this tab activated by default or not: true || false. |
| 92 |
//, 'subtabs' => array() |
| 93 |
|
| 94 |
); |
| 95 |
|
| 96 |
$subtabs = array(); |
| 97 |
|
| 98 |
$subtabs['fields'] = array( |
| 99 |
'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html' |
| 100 |
, 'title' => __('Form','booking') // Title of TAB |
| 101 |
, 'page_title' => __('Form Settings', 'booking') // Title of Page |
| 102 |
, 'hint' => __('Customization of Form Settings', 'booking') // Hint |
| 103 |
, 'link' => '' // link |
| 104 |
, 'position' => '' // 'left' || 'right' || '' |
| 105 |
, 'css_classes' => '' // CSS class(es) |
| 106 |
//, 'icon' => 'https://www.paypalobjects.com/webstatic/icon/pp258.png' // Icon - link to the real PNG img |
| 107 |
//, 'font_icon' => 'wpbc_icn_payment' // CSS definition of Font Icon |
| 108 |
, 'default' => true // Is this sub tab activated by default or not: true || false. |
| 109 |
, 'disabled' => false // Is this sub tab deactivated: true || false. |
| 110 |
, 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' ) |
| 111 |
, 'content' => 'content' // Function to load as conten of this TAB |
| 112 |
); |
| 113 |
|
| 114 |
$subtabs['form-separator'] = array( |
| 115 |
'type' => 'separator' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html' |
| 116 |
); |
| 117 |
$subtabs['form-goto'] = array( |
| 118 |
'type' => 'goto-link' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html' |
| 119 |
, 'title' =>ucwords( __('Form fields', 'booking') ) // Title of TAB |
| 120 |
, 'hint' => '' // Hint |
| 121 |
, 'show_section' => 'id_of_show_section' // ID of HTML element, for scroll to. |
| 122 |
); |
| 123 |
|
| 124 |
ob_start(); |
| 125 |
... |
| 126 |
$html_element_data = ob_get_clean(); |
| 127 |
|
| 128 |
$subtabs['form-selection'] = array( |
| 129 |
'type' => 'html' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html' |
| 130 |
, 'html' => $html_element_data |
| 131 |
); |
| 132 |
|
| 133 |
$subtabs['form-save'] = array( |
| 134 |
'type' => 'button' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html' |
| 135 |
, 'title' => __('Save Changes','booking') // Title of TAB |
| 136 |
, 'form' => 'wpbc_form' // Required for 'button'! Name of Form to submit |
| 137 |
); |
| 138 |
|
| 139 |
$tabs[ 'form' ][ 'subtabs' ] = $subtabs; |
| 140 |
|
| 141 |
return $tabs; |
| 142 |
*/ |
| 143 |
abstract public function tabs(); |
| 144 |
|
| 145 |
/** |
| 146 |
* Show Content of this page - Main function. |
| 147 |
* |
| 148 |
* In top of this function have to be checking ubout Update (saving POST request). |
| 149 |
* |
| 150 |
* Exmaple: |
| 151 |
|
| 152 |
// S u b m i t /////////////////////////////////////////////////////// |
| 153 |
|
| 154 |
$this_submit_form = 'wpbc_emails_toolbar'; // Define form name |
| 155 |
|
| 156 |
if ( isset( $_POST['is_form_sbmitted_'. $this_submit_form ] ) ) { |
| 157 |
|
| 158 |
// Check N o n c e |
| 159 |
check_admin_referer( 'wpbc_settings_page_' . $this_submit_form ); // Its stop show anything on submiting, if its not refear to the original page |
| 160 |
|
| 161 |
// Make Update of settings |
| 162 |
$edit_field_data = $this->update_wpbc_emails_toolbar( $menu_slug ); |
| 163 |
} |
| 164 |
//////////////////////////////////////////////////////////////////////// |
| 165 |
*/ |
| 166 |
abstract public function content(); |
| 167 |
|
| 168 |
/** |
| 169 |
* This function can be overridden by child classes for auto update / save options in main form |
| 170 |
* |
| 171 |
* @return void |
| 172 |
*/ |
| 173 |
public function maybe_update(){ |
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
//////////////////////////////////////////////////////////////////////////// |
| 179 |
// C O N T E N T |
| 180 |
//////////////////////////////////////////////////////////////////////////// |
| 181 |
|
| 182 |
/** |
| 183 |
* General Page Structure |
| 184 |
* |
| 185 |
* @param string $page_tag - its the same that return $this->in_page () |
| 186 |
*/ |
| 187 |
public function content_structure( $page_tag ) { |
| 188 |
|
| 189 |
if ( ! $this->is_page_activated() ) { |
| 190 |
return false; |
| 191 |
} |
| 192 |
|
| 193 |
$this->maybe_update(); |
| 194 |
|
| 195 |
|
| 196 |
$active_page_tab = $active_page_subtab = ''; |
| 197 |
if ( ( isset( $this->current_page_params['tab'] ) ) && ( ! empty( $this->current_page_params['tab']['tag'] ) ) ) |
| 198 |
$active_page_tab = $this->current_page_params['tab']['tag']; |
| 199 |
if ( ( isset( $this->current_page_params['subtab'] ) ) && ( ! empty( $this->current_page_params['subtab']['tag'] ) ) ) |
| 200 |
$active_page_subtab = $this->current_page_params['subtab']['tag']; |
| 201 |
|
| 202 |
$is_show_this_page = apply_filters( 'wpbc_before_showing_settings_page_is_show_page', true, $page_tag, $active_page_tab, $active_page_subtab ); // Fires Before showing settings Content page |
| 203 |
|
| 204 |
if ( $is_show_this_page === false ) return false; |
| 205 |
|
| 206 |
do_action( 'wpbc_before_settings_content', $page_tag, $active_page_tab, $active_page_subtab ); // Fires Before showing settings Content page |
| 207 |
if ( 1 ) { |
| 208 |
//FixIn: 9.8.15.2 |
| 209 |
?><div class="wpbc_page_top__header_tabs"><?php |
| 210 |
?><div id="<?php echo $page_tag; ?>-admin-page-top" |
| 211 |
class="wrap wpbc_page_top <?php |
| 212 |
echo ' wpbc_page_tab__' . esc_attr( $active_page_tab ); |
| 213 |
echo ' wpbc_page_subtab__' . esc_attr( $active_page_subtab ); |
| 214 |
?>" |
| 215 |
><?php |
| 216 |
?><h1 class="wpbc_header wpdvlp-top-tabs"><?php |
| 217 |
?><div class="wpbc_header_menu_tabs"><?php |
| 218 |
$this->show_tabs_line( $page_tag ); // T O P T A B S in Header |
| 219 |
?></div><?php |
| 220 |
make_bk_action( 'wpbc_h1_header_content_end', $page_tag, $active_page_tab, $active_page_subtab ); //FixIn: 9.9.0.10 |
| 221 |
?></h1><?php |
| 222 |
?></div><?php |
| 223 |
?></div><?php |
| 224 |
} else { |
| 225 |
?><div id="<?php echo $page_tag; ?>-admin-page-top" |
| 226 |
class="wrap wpbc_page_top wpbc_page_tab__<?php echo esc_attr( $active_page_tab ); ?> wpbc_page_subtab__<?php echo esc_attr( $active_page_subtab ); ?>" > |
| 227 |
<h1 class="wpbc_header"><div class="wpbc_header_icon"><i class="menu_icon icon-1x <?php echo $this->get_page_header_h1_font_icon(); ?>"></i></div><div class="wpbc_header_text"><?php echo $this->get_page_header_h1(); ?></div><?php make_bk_action( 'wpbc_h1_header_content_end', $page_tag, $active_page_tab, $active_page_subtab ); ?></h1> |
| 228 |
</div><?php |
| 229 |
} |
| 230 |
?><div id="<?php echo $page_tag; ?>-admin-page" |
| 231 |
class="wrap wpbc_page wpbc_page_tab__<?php echo esc_attr( $active_page_tab ); ?> wpbc_page_subtab__<?php echo esc_attr( $active_page_subtab ); ?>" > |
| 232 |
<div class="wpbc_admin_message"></div> |
| 233 |
<div class="wpbc_admin_page"> |
| 234 |
<div id="ajax_working"></div> |
| 235 |
<div class="clear wpbc_header_margin"></div> |
| 236 |
<div id="ajax_respond" class="ajax_respond" style="display:none;"></div> |
| 237 |
<?php |
| 238 |
if ( $this->is_use_left_navigation ) { |
| 239 |
?> |
| 240 |
<div class="clear" style="margin-bottom:10px;"></div> |
| 241 |
<div class="wpbc_settings_flex_container"> |
| 242 |
<div class="wpbc_settings_flex_container_left"> |
| 243 |
<div class="wpbc_settings_navigation_column"> |
| 244 |
<?php |
| 245 |
} |
| 246 |
// T A B S |
| 247 |
$this->show_tabs_structure( $page_tag ); |
| 248 |
if ( $this->is_use_left_navigation ) { |
| 249 |
?> |
| 250 |
</div> |
| 251 |
</div> |
| 252 |
<div class="wpbc_settings_flex_container_right"> |
| 253 |
<?php |
| 254 |
} |
| 255 |
wp_nonce_field('wpbc_ajax_admin_nonce', "wpbc_admin_panel_nonce" , true , true ); |
| 256 |
|
| 257 |
// C o n t e n t |
| 258 |
if ( ( isset( $this->current_page_params['subtab'] ) ) && ( isset( $this->current_page_params['subtab']['content'] ) ) ) { |
| 259 |
|
| 260 |
call_user_func( array( $this, $this->current_page_params['subtab']['content'] ) ); |
| 261 |
|
| 262 |
} else if ( ( isset( $this->current_page_params['tab'] ) ) && ( isset( $this->current_page_params['tab']['content'] ) ) ) { |
| 263 |
call_user_func( array( $this, $this->current_page_params['tab']['content'] ) ); |
| 264 |
|
| 265 |
} else { |
| 266 |
$this->content(); |
| 267 |
} |
| 268 |
|
| 269 |
do_action('wpbc_show_settings_content' , $page_tag, $active_page_tab, $active_page_subtab ); |
| 270 |
if ( $this->is_use_left_navigation ) { |
| 271 |
?> |
| 272 |
</div> |
| 273 |
</div> |
| 274 |
<?php |
| 275 |
} |
| 276 |
|
| 277 |
?></div> |
| 278 |
</div><?php |
| 279 |
|
| 280 |
do_action( 'wpbc_after_settings_content', $page_tag, $active_page_tab, $active_page_subtab ); // Fires After showing settings Content page |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
//////////////////////////////////////////////////////////////////////////// |
| 286 |
// Active Page Parameters |
| 287 |
//////////////////////////////////////////////////////////////////////////// |
| 288 |
|
| 289 |
/** |
| 290 |
* Check if this page selected (active), depend from the GET parameter |
| 291 |
* If selected, then define Current Page Parameters. |
| 292 |
* |
| 293 |
* @return boolean |
| 294 |
*/ |
| 295 |
private function is_page_activated() { |
| 296 |
|
| 297 |
$is_page_selected = false; |
| 298 |
|
| 299 |
$this_page = $this->in_page(); |
| 300 |
|
| 301 |
//FixIn: 9.8.15.2.3 |
| 302 |
if ( is_array( $this_page ) ) { |
| 303 |
$this_page_arr = $this_page; |
| 304 |
} else { |
| 305 |
$this_page_arr = array( $this_page ); |
| 306 |
} |
| 307 |
foreach ( $this_page_arr as $this_page ) { |
| 308 |
|
| 309 |
foreach ( $this->tabs() as $this_tab_tag => $this_tab ) { // Get First Tab Element, which MUST be subtab element, all other tabs, can be links, not really showing content!!! |
| 310 |
break; |
| 311 |
} |
| 312 |
|
| 313 |
if ( empty( $this_tab ) ) { |
| 314 |
return $this_page; // this page empty - tabs is empty array, probabaly its was redefined in child CLASS to $tabs = array(); for not ability to open this page. |
| 315 |
} |
| 316 |
|
| 317 |
$this_subtab_tag = 0; |
| 318 |
$this_subtab = array( 'default' => false ); |
| 319 |
|
| 320 |
if ( isset( $this_tab['subtabs'] ) ) |
| 321 |
foreach ( $this_tab['subtabs'] as $temp_this_subtab_tag => $temp_this_subtab ) { |
| 322 |
|
| 323 |
if ( $temp_this_subtab['type'] == 'subtab' ) { // Get First Subtab element from subtabs array |
| 324 |
$this_subtab_tag = $temp_this_subtab_tag; |
| 325 |
$this_subtab = $temp_this_subtab; |
| 326 |
break; |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
if ( ( isset( $_REQUEST[ 'page' ] ) ) |
| 331 |
&& ( $this_page == $_REQUEST[ 'page' ] ) ){ // We are inside of this page. Menu item selected. |
| 332 |
|
| 333 |
if ( ( ! isset( $_REQUEST[ $this->tags['tab'] ] ) ) // TAB NOT selected && Default |
| 334 |
//&& ( ! isset( $_REQUEST[ $this->tags['subtab'] ] ) ) // SubTab NOT selected |
| 335 |
&& ( isset( $this_tab['default'] ) ) && ( $this_tab['default'] ) |
| 336 |
) |
| 337 |
$is_page_selected = true; |
| 338 |
|
| 339 |
if ( ( isset( $_REQUEST[ $this->tags['tab'] ] ) ) // TAB Selected |
| 340 |
&& ( ! isset( $_REQUEST[ $this->tags['subtab'] ] ) ) // SubTab NOT selected && ! exist || Default |
| 341 |
&& ( $_REQUEST[ $this->tags['tab'] ] == $this_tab_tag ) |
| 342 |
&& ( ( $this_subtab_tag === 0 ) |
| 343 |
|| ( $this_subtab['default'] ) |
| 344 |
) |
| 345 |
) |
| 346 |
$is_page_selected = true; |
| 347 |
|
| 348 |
if ( ( isset( $_REQUEST[ $this->tags['tab'] ] ) ) // TAB Selected |
| 349 |
&& ( isset( $_REQUEST[ $this->tags['subtab'] ] ) ) // SubTab Selected |
| 350 |
&& ( $_REQUEST[ $this->tags['tab'] ] == $this_tab_tag ) |
| 351 |
&& ( $_REQUEST[ $this->tags['subtab'] ] == $this_subtab_tag ) |
| 352 |
) |
| 353 |
$is_page_selected = true; |
| 354 |
} |
| 355 |
|
| 356 |
|
| 357 |
if ( $is_page_selected ) // If this page activated, then define Current Page parameters |
| 358 |
$this->define_current_page_parameters( $this_tab_tag, $this_tab, $this_subtab_tag, $this_subtab ); |
| 359 |
|
| 360 |
if ( $is_page_selected ) { |
| 361 |
break; |
| 362 |
} |
| 363 |
} |
| 364 |
|
| 365 |
return $is_page_selected; |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
/** |
| 370 |
* Define parameters for current selected page |
| 371 |
* |
| 372 |
* @param type $paramas |
| 373 |
*/ |
| 374 |
private function define_current_page_parameters( $this_tab_tag, $this_tab, $this_subtab_tag, $this_subtab ) { |
| 375 |
|
| 376 |
$this->current_page_params = array( |
| 377 |
'tab' => array_merge ( $this_tab, array( 'tag' => $this_tab_tag ) ) |
| 378 |
, 'subtab' => array_merge ( $this_subtab, array( 'tag' => $this_subtab_tag ) ) |
| 379 |
); |
| 380 |
|
| 381 |
if ( ( ! empty( $this_subtab ) ) && ( ! empty( $this_subtab['is_use_left_navigation'] ) ) && ( true === $this_subtab['is_use_left_navigation'] ) ) { |
| 382 |
$this->is_use_left_navigation = true; |
| 383 |
} |
| 384 |
} |
| 385 |
|
| 386 |
|
| 387 |
/** |
| 388 |
* Get Header Title (H1) of this selected page |
| 389 |
* Firstly check in subtabs, otherwise get from tabs and if not exist then |
| 390 |
* |
| 391 |
* @return string |
| 392 |
*/ |
| 393 |
private function get_page_header_h1() { |
| 394 |
|
| 395 |
if ( ! empty( $this->current_page_params ) ) { |
| 396 |
|
| 397 |
if ( isset( $this->current_page_params['subtab']['page_title'] ) ) |
| 398 |
return $this->current_page_params['subtab']['page_title']; |
| 399 |
|
| 400 |
if ( isset( $this->current_page_params['tab']['page_title'] ) ) |
| 401 |
return $this->current_page_params['tab']['page_title']; |
| 402 |
} |
| 403 |
|
| 404 |
return ''; |
| 405 |
} |
| 406 |
|
| 407 |
/** |
| 408 |
* Get icon for header at top of the page |
| 409 |
* |
| 410 |
* @return mixed|string |
| 411 |
*/ |
| 412 |
private function get_page_header_h1_font_icon() { //FixIn: 9.5.5.3 |
| 413 |
|
| 414 |
if ( ! empty( $this->current_page_params ) ) { |
| 415 |
if ( isset( $this->current_page_params['tab']['header_font_icon'] ) ) { |
| 416 |
return $this->current_page_params['tab']['header_font_icon']; |
| 417 |
} |
| 418 |
if ( isset( $this->current_page_params['subtab']['header_font_icon'] ) ) { |
| 419 |
return $this->current_page_params['subtab']['header_font_icon']; |
| 420 |
} |
| 421 |
if ( isset( $this->current_page_params['tab']['font_icon'] ) ) { |
| 422 |
return $this->current_page_params['tab']['font_icon']; |
| 423 |
} |
| 424 |
if ( isset( $this->current_page_params['subtab']['font_icon'] ) ) { |
| 425 |
return $this->current_page_params['subtab']['font_icon']; |
| 426 |
} |
| 427 |
} |
| 428 |
return ''; |
| 429 |
} |
| 430 |
|
| 431 |
/** |
| 432 |
* Get all SubTabs of current opened page Tab |
| 433 |
* |
| 434 |
* @param string $menu_in_page_tag - Optional. Menu Tag, the same as $this->in_page (); |
| 435 |
* @return array |
| 436 |
*/ |
| 437 |
private function get_all_sub_tabs_of_selected_tab( $menu_in_page_tag = false ) { |
| 438 |
|
| 439 |
if ( $menu_in_page_tag === false ) { |
| 440 |
|
| 441 |
//FixIn: 9.8.15.2.3 |
| 442 |
$this_page = $this->in_page(); |
| 443 |
if ( is_array( $this_page ) ) { |
| 444 |
$this_page_arr = $this_page; |
| 445 |
} else { |
| 446 |
$this_page_arr = array( $this_page ); |
| 447 |
} |
| 448 |
|
| 449 |
$menu_in_page_tag = $this_page_arr[0]; |
| 450 |
} |
| 451 |
|
| 452 |
$all_sub_tabs_of_selected_tab = self::$nav_tabs[ $menu_in_page_tag ][ $this->current_page_params['tab']['tag'] ]['subtabs']; |
| 453 |
|
| 454 |
return $all_sub_tabs_of_selected_tab; |
| 455 |
} |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
//////////////////////////////////////////////////////////////////////////// |
| 460 |
// T A B s |
| 461 |
//////////////////////////////////////////////////////////////////////////// |
| 462 |
|
| 463 |
// Define ------------------------------------------------------------------ |
| 464 |
|
| 465 |
/** |
| 466 |
* Define TABS structure. |
| 467 |
* General structure of tabs for every plugin menu page. |
| 468 |
*/ |
| 469 |
public function wpbc_define_nav_tabs() { // Function executed after creation menu in class WPBC_Admin_Menus |
| 470 |
/* |
| 471 |
Array ( |
| 472 |
[wpbc-resources] => Array () |
| 473 |
[wpbc-settings] => Array |
| 474 |
( |
| 475 |
[general] => Array |
| 476 |
( |
| 477 |
[title] => General |
| 478 |
[page_title] => General Settings |
| 479 |
... |
| 480 |
[subtabs] => Array () |
| 481 |
) |
| 482 |
[help] => Array |
| 483 |
( |
| 484 |
[title] => Help |
| 485 |
[page_title] => |
| 486 |
... |
| 487 |
[subtabs] => Array () |
| 488 |
) |
| 489 |
[form] => Array |
| 490 |
( |
| 491 |
[title] => Form |
| 492 |
[hint] => Customization of Form Fields |
| 493 |
[page_title] => Form Fields |
| 494 |
... |
| 495 |
[subtabs] => Array |
| 496 |
( |
| 497 |
[goto-form] => Array |
| 498 |
( |
| 499 |
[type] => goto-link |
| 500 |
[title] => Booking Form Fields |
| 501 |
... |
| 502 |
[content] => content |
| 503 |
[update] => update |
| 504 |
) |
| 505 |
|
| 506 |
[goto-content-data] => Array |
| 507 |
( |
| 508 |
[type] => button |
| 509 |
[title] => Save Changes |
| 510 |
[form] => wpbc_form |
| 511 |
... |
| 512 |
) |
| 513 |
|
| 514 |
) |
| 515 |
|
| 516 |
) |
| 517 |
[payment] => Array |
| 518 |
( |
| 519 |
[title] => Payments |
| 520 |
[hint] => Customization of Payment |
| 521 |
[page_title] => Payment Gateways |
| 522 |
... |
| 523 |
[subtabs] => Array |
| 524 |
( |
| 525 |
[paypal] => Array |
| 526 |
( |
| 527 |
[type] => subtab |
| 528 |
[title] => PayPal |
| 529 |
... |
| 530 |
) |
| 531 |
|
| 532 |
[sage] => Array |
| 533 |
( |
| 534 |
[type] => subtab |
| 535 |
[title] => Sage |
| 536 |
... |
| 537 |
) |
| 538 |
|
| 539 |
) |
| 540 |
|
| 541 |
) |
| 542 |
|
| 543 |
) |
| 544 |
|
| 545 |
) |
| 546 |
*/ |
| 547 |
|
| 548 |
//FixIn: 9.8.15.2.3 |
| 549 |
$this_page = $this->in_page(); |
| 550 |
if ( is_array( $this_page ) ) { |
| 551 |
$this_page_arr = $this_page; |
| 552 |
} else { |
| 553 |
$this_page_arr = array( $this_page ); |
| 554 |
} |
| 555 |
foreach ( $this_page_arr as $this_page ) { |
| 556 |
|
| 557 |
|
| 558 |
if ( ! isset( self::$nav_tabs[ $this_page ] ) ) |
| 559 |
self::$nav_tabs[ $this_page ] = array(); // If this page does not exist, then define it. |
| 560 |
|
| 561 |
$current_tab = $this->tabs(); |
| 562 |
$current_subtabs = array(); // Get Subtabs in separate array. |
| 563 |
foreach ( $current_tab as $tab_tag => $tab_array ) { |
| 564 |
|
| 565 |
if ( isset( $tab_array[ 'subtabs' ] ) ) { |
| 566 |
$current_subtabs[ $tab_tag ] = $tab_array[ 'subtabs' ]; // Create new Subtabs array |
| 567 |
|
| 568 |
unset( $current_tab[ $tab_tag ][ 'subtabs' ] ); // Detach Subtabs array from Tab array. Its required for do not overwrite subtabs with already exist subtabs in previlosly defined tab. |
| 569 |
} else |
| 570 |
$current_subtabs[ $tab_tag ] = array(); |
| 571 |
} |
| 572 |
|
| 573 |
|
| 574 |
foreach ( $current_tab as $tab_tag => $tab_array ) { |
| 575 |
|
| 576 |
if ( ! isset( self::$nav_tabs[ $this_page ][ $tab_tag ] ) ) { // If this tab ( for exmaple "payment") declared previously, then does not do anything |
| 577 |
|
| 578 |
self::$nav_tabs[ $this_page ][ $tab_tag ] = $current_tab[ $tab_tag ]; |
| 579 |
self::$nav_tabs[ $this_page ][ $tab_tag ][ 'subtabs' ] = array(); |
| 580 |
} |
| 581 |
|
| 582 |
if ( isset(self::$nav_tabs[ $this_page ] ) ) { |
| 583 |
// Merge subtabs (Ex: PayPal and Sage) and attach to current tab: (Ex: payment) |
| 584 |
self::$nav_tabs[ $this_page ][ $tab_tag ][ 'subtabs' ] = array_merge( |
| 585 |
self::$nav_tabs[ $this_page ][ $tab_tag ][ 'subtabs' ] |
| 586 |
, $current_subtabs[ $tab_tag ] |
| 587 |
); |
| 588 |
} |
| 589 |
} |
| 590 |
|
| 591 |
} |
| 592 |
|
| 593 |
// if ( $this->is_page_activated() ) { |
| 594 |
// |
| 595 |
// } |
| 596 |
// |
| 597 |
// $tabs = $this->tabs(); |
| 598 |
} |
| 599 |
|
| 600 |
/** |
| 601 |
* Get array of visible TABs |
| 602 |
* Tabs that do not hided or disbaled |
| 603 |
* |
| 604 |
* @param string $menu_in_page_tag - Menu Tag, the same as $this->in_page (); |
| 605 |
* @return type |
| 606 |
*/ |
| 607 |
private function get_visible_tabs( $menu_in_page_tag ) { |
| 608 |
|
| 609 |
$visible_tabs = array(); |
| 610 |
|
| 611 |
foreach ( self::$nav_tabs[ $menu_in_page_tag ] as $tab_tag => $tab ) { |
| 612 |
|
| 613 |
if ( empty( $tab['disabled'] ) |
| 614 |
&& empty( $tab['hided'] ) |
| 615 |
) { |
| 616 |
$visible_tabs[$tab_tag] = $tab; |
| 617 |
} |
| 618 |
} |
| 619 |
|
| 620 |
return $visible_tabs; |
| 621 |
} |
| 622 |
|
| 623 |
// Showing ----------------------------------------------------------------- |
| 624 |
|
| 625 |
/** |
| 626 |
* |
| 627 |
* @param string $menu_in_page_tag - Menu Tag, the same as $this->in_page (); |
| 628 |
* @return boolean - true if nav tabs exist and false if does not exist |
| 629 |
*/ |
| 630 |
public function show_tabs_structure( $menu_in_page_tag ) { |
| 631 |
|
| 632 |
// Exit if no Tabs in this page. |
| 633 |
if ( empty( self::$nav_tabs[ $menu_in_page_tag ] ) ) |
| 634 |
return false; |
| 635 |
|
| 636 |
// Exit if tabs hidded or disbaled |
| 637 |
$visible_tabs = $this->get_visible_tabs( $menu_in_page_tag ); |
| 638 |
if ( empty( $visible_tabs ) ) |
| 639 |
return false; |
| 640 |
if ( ! $this->is_use_left_navigation ) { |
| 641 |
?><span class="wpdevelop wpdvlp-nav-tabs-container"> |
| 642 |
<div class="clear"></div><?php |
| 643 |
} |
| 644 |
//FixIn: 9.8.15.2 |
| 645 |
if ( 1 ) { |
| 646 |
|
| 647 |
do_action( 'wpbc_toolbar_top_tabs_insert', $menu_in_page_tag ); |
| 648 |
|
| 649 |
} else { |
| 650 |
wpbc_bs_toolbar_tabs_html_container_start(); |
| 651 |
|
| 652 |
do_action( 'wpbc_toolbar_top_tabs_before' , $menu_in_page_tag ); |
| 653 |
|
| 654 |
$this->show_tabs_line( $menu_in_page_tag ); // T O P T A B S |
| 655 |
|
| 656 |
do_action( 'wpbc_toolbar_top_tabs_after' , $menu_in_page_tag ); |
| 657 |
|
| 658 |
wpbc_bs_toolbar_tabs_html_container_end(); |
| 659 |
} |
| 660 |
|
| 661 |
$bottom_tabs = $this->get_all_sub_tabs_of_selected_tab( $menu_in_page_tag ); |
| 662 |
|
| 663 |
if ( ! empty( $bottom_tabs ) ) { // S U B T A B S |
| 664 |
if ( ! $this->is_use_left_navigation ) { |
| 665 |
wpbc_bs_toolbar_sub_html_container_start(); |
| 666 |
|
| 667 |
$this->show_subtabs_line( $bottom_tabs, $menu_in_page_tag ); |
| 668 |
|
| 669 |
wpbc_bs_toolbar_sub_html_container_end(); |
| 670 |
} else { |
| 671 |
$this->show_subtabs_line( $bottom_tabs, $menu_in_page_tag ); |
| 672 |
} |
| 673 |
|
| 674 |
} // Bottom Tabs |
| 675 |
if ( ! $this->is_use_left_navigation ) { |
| 676 |
?></span><?php |
| 677 |
} |
| 678 |
return true; |
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
/** |
| 683 |
* Show Top nav TABs line |
| 684 |
* |
| 685 |
* @param string $menu_in_page_tag - Menu Tag, the same as $this->in_page (); |
| 686 |
*/ |
| 687 |
public function show_tabs_line( $menu_in_page_tag ) { |
| 688 |
|
| 689 |
foreach ( self::$nav_tabs[ $menu_in_page_tag ] as $tab_tag => $tab ) { |
| 690 |
|
| 691 |
$css_classes = ( ( isset($tab['css_classes']) ) ? $tab['css_classes'] : '' ); |
| 692 |
|
| 693 |
if ( ( isset( $this->current_page_params['tab'] ) ) && ( $this->current_page_params['tab']['tag'] == $tab_tag ) ) |
| 694 |
$css_classes .= ' nav-tab-active'; |
| 695 |
|
| 696 |
if ( ! empty( $tab['position'] ) ) |
| 697 |
$css_classes .= ' nav-tab-position-' . $tab['position']; |
| 698 |
|
| 699 |
if ( ! empty( $tab['hided'] ) ) |
| 700 |
$css_classes .= ' hide'; |
| 701 |
|
| 702 |
if ( ( isset( $tab['disabled'] ) ) && ( $tab['disabled'] ) ) |
| 703 |
$css_classes .= ' wpdevelop-tab-disabled'; |
| 704 |
|
| 705 |
$tab['css_classes'] = $css_classes; |
| 706 |
|
| 707 |
$tab['link'] = ( ! empty($tab['link']) ? $tab['link'] : $this->get_tab_url( $menu_in_page_tag, $tab_tag ) ); |
| 708 |
|
| 709 |
if ( // Recheck active status of default TAB |
| 710 |
( isset( $_REQUEST[ $this->tags['tab'] ] ) ) // Some Tab selected |
| 711 |
&& ( $_REQUEST[ $this->tags['tab'] ] !== $tab_tag ) // This tag not in URL |
| 712 |
&& ( isset($tab['default']) && ( $tab['default'] ) ) // This tab default, need to set it as not defaultm for not showing it selected |
| 713 |
) |
| 714 |
$tab['default'] = false; |
| 715 |
|
| 716 |
wpbc_bs_display_tab( $tab ); |
| 717 |
|
| 718 |
} |
| 719 |
} |
| 720 |
|
| 721 |
|
| 722 |
/** |
| 723 |
* Show Sub Menu Lines at the Settings page for Active Tab |
| 724 |
* |
| 725 |
* @param array $bottom_tabs |
| 726 |
* @param string $menu_in_page_tag - Menu Tag, the same as $this->in_page (); |
| 727 |
*/ |
| 728 |
public function show_subtabs_line( $bottom_tabs, $menu_in_page_tag ) { |
| 729 |
|
| 730 |
if ( ! empty( $bottom_tabs ) ) |
| 731 |
foreach ( $bottom_tabs as $tab_tag => $tab ) { |
| 732 |
|
| 733 |
switch ( $tab['type'] ) { |
| 734 |
case 'separator': // Separator |
| 735 |
?><span class="wpdevelop-submenu-tab-separator-vertical"></span><?php |
| 736 |
break; |
| 737 |
|
| 738 |
case 'button': // Button |
| 739 |
?><div class="clear-for-mobile"></div><input |
| 740 |
type="button" |
| 741 |
class="button button-primary wpbc_submit_button" |
| 742 |
value="<?php echo $tab['title']; ?>" |
| 743 |
onclick="if (typeof document.forms['<?php echo $tab['form']; ?>'] !== 'undefined'){ document.forms['<?php echo $tab['form']; ?>'].submit(); } else { wpbc_admin_show_message( '<?php echo ' <strong>Error!</strong> Form <strong>' , $tab['form'] , '</strong> does not exist.'; ?>', 'error', 10000 ); }" <?php //FixIn: 7.0.1.56 ?> |
| 744 |
/><?php |
| 745 |
break; |
| 746 |
|
| 747 |
case 'html': // HTML |
| 748 |
echo $tab['html']; |
| 749 |
break; |
| 750 |
|
| 751 |
case 'goto-link': |
| 752 |
?><a class="nav-tab wpdevelop-submenu-tab go-to-link" |
| 753 |
original-title="<?php echo (empty($tab['hint'])?'':$tab['hint']); ?>" |
| 754 |
onclick="javascript:wpbc_scroll_to('#<?php echo esc_js( $tab['show_section'] ); ?>' );" |
| 755 |
href="javascript:void(0);"><span><?php echo $tab['title']; ?></span></a><?php |
| 756 |
break; |
| 757 |
|
| 758 |
default: // Link |
| 759 |
|
| 760 |
$css_classes = ( ( isset( $tab['css_classes'] ) ) ? $tab['css_classes'] : '' ); |
| 761 |
$tab['link'] = ( ! empty( $tab['link'] ) ? $tab['link'] : $this->get_tab_url( $menu_in_page_tag, $this->current_page_params['tab']['tag'], $tab_tag ) ); |
| 762 |
|
| 763 |
if ( $this->is_use_left_navigation ) { |
| 764 |
|
| 765 |
if ( $tab_tag == $this->current_page_params['subtab']['tag'] ) { |
| 766 |
$css_classes .= ' wpbc_settings_navigation_item_active'; |
| 767 |
} |
| 768 |
|
| 769 |
$hint_title = ''; |
| 770 |
$hint_css_classes = ''; |
| 771 |
if ( ( ! empty( $tab['hint'] ) ) && ( is_array( $tab['hint'] ) ) ) { |
| 772 |
if ( ! empty( $tab['hint']['title'] ) ) { |
| 773 |
$hint_title = $tab['hint']['title']; |
| 774 |
} |
| 775 |
if ( ! empty( $tab['hint']['position'] ) ){ |
| 776 |
$hint_css_classes .= ' tooltip_' . $tab['hint']['position']; |
| 777 |
} |
| 778 |
} |
| 779 |
$html_tag = 'a'; |
| 780 |
|
| 781 |
if ( $tab['disabled'] ) { |
| 782 |
$tab['link'] = 'javascript:void(0)'; |
| 783 |
$html_tag = 'span'; |
| 784 |
} |
| 785 |
|
| 786 |
?><div id="wpbc_settings_left_nav_tab_<?php echo esc_attr( $tab_tag ); ?>" |
| 787 |
class="wpbc_settings_navigation_item <?php echo esc_attr( $css_classes ); ?>"> |
| 788 |
<<?php echo $html_tag; ?> class="<?php echo esc_attr( $hint_css_classes ); ?>" |
| 789 |
title="<?php echo esc_attr( $hint_title ); ?>" |
| 790 |
<?php |
| 791 |
if ( $html_tag == 'a' ) { // Parameters for A tag |
| 792 |
|
| 793 |
echo ' href="', $tab['link'] , '" '; |
| 794 |
|
| 795 |
if ( ! empty( $tab['onclick'] ) ) { |
| 796 |
echo ' onclick="javascript:', $tab['onclick'], '" '; |
| 797 |
} |
| 798 |
} |
| 799 |
echo wpbc_get_custom_attr( $tab ); |
| 800 |
?> |
| 801 |
> |
| 802 |
<?php echo $tab['title']; ?> |
| 803 |
<?php if ( ( ! empty( $tab['show_checked_icon'] ) ) && ( ! empty( $tab['checked_data'] ) ) ) { |
| 804 |
$is_checked_data = get_bk_option( $tab['checked_data'] ); |
| 805 |
if ( |
| 806 |
( ( ! empty( $is_checked_data ) ) && ( isset( $is_checked_data['enabled'] ) ) && ( $is_checked_data['enabled'] == 'On' ) ) |
| 807 |
|| ( ( ! empty( $is_checked_data ) ) && ( $is_checked_data === 'On' ) ) |
| 808 |
){ |
| 809 |
echo '<i class="menu_icon icon-1x wpbc-bi-toggle2-on wpbc_icn_radio_button_checked0" style="margin-left: auto;margin-top: 3px;color: #036aab;"></i>'; |
| 810 |
} else{ |
| 811 |
echo '<i class="menu_icon icon-1x wpbc-bi-toggle2-off wpbc_icn_radio_button_unchecked0" style="margin-left: auto;margin-top: 3px;"></i>'; |
| 812 |
} |
| 813 |
|
| 814 |
}?> |
| 815 |
</<?php echo $html_tag; ?>> |
| 816 |
</div><?php |
| 817 |
|
| 818 |
} else { |
| 819 |
|
| 820 |
|
| 821 |
if ( ! empty( $tab['position'] ) ) { |
| 822 |
$css_classes .= ' nav-tab-position-' . $tab['position']; |
| 823 |
} |
| 824 |
if ( $tab_tag == $this->current_page_params['subtab']['tag'] ) { |
| 825 |
$css_classes .= ' wpdevelop-submenu-tab-selected'; |
| 826 |
} |
| 827 |
if ( $tab['disabled'] ) { |
| 828 |
$css_classes .= ' wpdevelop-submenu-tab-disabled'; |
| 829 |
} |
| 830 |
|
| 831 |
$tab['css_classes'] = $css_classes; |
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
$tab['top'] = false; |
| 836 |
wpbc_bs_display_tab( $tab ); |
| 837 |
} |
| 838 |
|
| 839 |
break; |
| 840 |
|
| 841 |
} // End Switch |
| 842 |
} // End Bottom Tabs Loop |
| 843 |
|
| 844 |
} |
| 845 |
|
| 846 |
|
| 847 |
//////////////////////////////////////////////////////////////////////////// |
| 848 |
// Support |
| 849 |
//////////////////////////////////////////////////////////////////////////// |
| 850 |
|
| 851 |
/** |
| 852 |
* Get URL of settings page, based on Page Slug and Tab Slug |
| 853 |
* |
| 854 |
* @param string $page_tag |
| 855 |
* @param string $tab_name |
| 856 |
* @param string $subtab_name ( Optional ) |
| 857 |
* @return string - Escaped URL to plugin page. |
| 858 |
*/ |
| 859 |
private function get_tab_url( $page_tag, $tab_name, $subtab_name = false ){ |
| 860 |
if ( $subtab_name === false ) |
| 861 |
return esc_url( admin_url( add_query_arg( array( 'page' => $page_tag, $this->tags['tab'] => $tab_name ), 'admin.php' ) ) ); |
| 862 |
else |
| 863 |
return esc_url( admin_url( add_query_arg( array( 'page' => $page_tag, $this->tags['tab'] => $tab_name, $this->tags['subtab'] => $subtab_name ), 'admin.php' ) ) ); |
| 864 |
} |
| 865 |
|
| 866 |
} |