| 1 |
<?php /** |
| 2 |
* @version 1.1 |
| 3 |
* @package Any |
| 4 |
* @category Page Structure in Admin Panel |
| 5 |
* @author wpdevelop |
| 6 |
* |
| 7 |
* @web-site http://oplugins.com/ |
| 8 |
* @email info@oplugins.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 WPBM_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 |
|
| 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('wpbm_define_nav_tabs', array( $this, 'wpbm_define_nav_tabs' ) ); // This Hook fire after creation menu in class WPBM_Admin_Menus |
| 39 |
|
| 40 |
add_action('wpbm_page_structure_show', array( $this, 'content_structure' ) ); // This Hook fire in the class WPBM_Admin_Menus for showing page content of specific menu |
| 41 |
} |
| 42 |
|
| 43 |
//////////////////////////////////////////////////////////////////////////// |
| 44 |
// Abstract Methods |
| 45 |
//////////////////////////////////////////////////////////////////////////// |
| 46 |
|
| 47 |
/** Define slug in what menu to show this page. // Parameter relative: $_GET['page']. |
| 48 |
* |
| 49 |
* @return string |
| 50 |
* |
| 51 |
* Example: |
| 52 |
|
| 53 |
return 'wpbm-settings'; |
| 54 |
|
| 55 |
*/ |
| 56 |
abstract public function in_page(); |
| 57 |
|
| 58 |
/** Define Tabs and Subtabs of this Admin Page |
| 59 |
* |
| 60 |
* @return array(); |
| 61 |
|
| 62 |
* Example: |
| 63 |
|
| 64 |
$tabs = array(); |
| 65 |
$tabs[ 'form' ] = array( |
| 66 |
'title' => __('Form', 'booking-manager') // Title of TAB |
| 67 |
, 'hint' => __('Customizaton of Form Fields', 'booking-manager') // Hint |
| 68 |
, 'page_title' =>ucwords( __('Form fields', 'booking-manager') ) // Title of Page |
| 69 |
//, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link |
| 70 |
//, 'position' => '' // 'left' || 'right' || '' |
| 71 |
//, 'css_classes' => '' // CSS class(es) |
| 72 |
//, 'icon' => '' // Icon - link to the real PNG img |
| 73 |
, 'font_icon' => 'glyphicon glyphicon-edit' // CSS definition of forn Icon |
| 74 |
, 'default' => false // Is this tab activated by default or not: true || false. |
| 75 |
, 'disabled' => false // Is this tab disbaled: true || false. |
| 76 |
, 'hided' => false // Is this tab hided: true || false. |
| 77 |
, 'subtabs' => array() |
| 78 |
|
| 79 |
); |
| 80 |
$tabs[ 'upgrade' ] = array( |
| 81 |
'title' => __('Upgrade', 'booking-manager') // Title of TAB |
| 82 |
, 'hint' => __('Upgrade to higher version', 'booking-manager') // Hint |
| 83 |
//, 'page_title' => __('Upgrade', 'booking-manager') // Title of Page |
| 84 |
, 'link' => 'http://server.com/' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link |
| 85 |
, 'position' => 'right' // 'left' || 'right' || '' |
| 86 |
//, 'css_classes' => '' // CSS class(es) |
| 87 |
//, 'icon' => '' // Icon - link to the real PNG img |
| 88 |
, 'font_icon' => 'glyphicon glyphicon-shopping-cart'// CSS definition of forn Icon |
| 89 |
//, 'default' => false // Is this tab activated by default or not: true || false. |
| 90 |
//, 'subtabs' => array() |
| 91 |
|
| 92 |
); |
| 93 |
|
| 94 |
$subtabs = array(); |
| 95 |
|
| 96 |
$subtabs['fields'] = array( |
| 97 |
'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html' |
| 98 |
, 'title' => __('Form', 'booking-manager') // Title of TAB |
| 99 |
, 'page_title' => __('Form Settings', 'booking-manager') // Title of Page |
| 100 |
, 'hint' => __('Customization of Form Settings', 'booking-manager') // Hint |
| 101 |
, 'link' => '' // link |
| 102 |
, 'position' => '' // 'left' || 'right' || '' |
| 103 |
, 'css_classes' => '' // CSS class(es) |
| 104 |
//, 'icon' => 'https://www.paypalobjects.com/webstatic/icon/pp258.png' // Icon - link to the real PNG img |
| 105 |
//, 'font_icon' => 'glyphicon glyphicon-credit-card' // CSS definition of Font Icon |
| 106 |
, 'default' => true // Is this sub tab activated by default or not: true || false. |
| 107 |
, 'disabled' => false // Is this sub tab deactivated: true || false. |
| 108 |
, 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' ) |
| 109 |
, 'content' => 'content' // Function to load as conten of this TAB |
| 110 |
); |
| 111 |
|
| 112 |
$subtabs['form-separator'] = array( |
| 113 |
'type' => 'separator' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html' |
| 114 |
); |
| 115 |
$subtabs['form-goto'] = array( |
| 116 |
'type' => 'goto-link' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html' |
| 117 |
, 'title' =>ucwords( __('Form fields', 'booking-manager') ) // Title of TAB |
| 118 |
, 'hint' => '' // Hint |
| 119 |
, 'show_section' => 'id_of_show_section' // ID of HTML element, for scroll to. |
| 120 |
); |
| 121 |
|
| 122 |
ob_start(); |
| 123 |
... |
| 124 |
$html_element_data = ob_get_clean(); |
| 125 |
|
| 126 |
$subtabs['form-selection'] = array( |
| 127 |
'type' => 'html' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html' |
| 128 |
, 'html' => $html_element_data |
| 129 |
); |
| 130 |
|
| 131 |
$subtabs['form-save'] = array( |
| 132 |
'type' => 'button' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html' |
| 133 |
, 'title' => __('Save Changes', 'booking-manager') // Title of TAB |
| 134 |
, 'form' => 'wpbm_form' // Required for 'button'! Name of Form to submit |
| 135 |
); |
| 136 |
|
| 137 |
$tabs[ 'form' ][ 'subtabs' ] = $subtabs; |
| 138 |
|
| 139 |
return $tabs; |
| 140 |
*/ |
| 141 |
abstract public function tabs(); |
| 142 |
|
| 143 |
/** Show Content of this page - Main function. |
| 144 |
* |
| 145 |
* In top of this function have to be checking ubout Update (saving POST request). |
| 146 |
* |
| 147 |
* Exmaple: |
| 148 |
|
| 149 |
// S u b m i t /////////////////////////////////////////////////////// |
| 150 |
|
| 151 |
$this_submit_form = 'wpbm_emails_toolbar'; // Define form name |
| 152 |
|
| 153 |
if ( isset( $_POST['is_form_sbmitted_'. $this_submit_form ] ) ) { |
| 154 |
|
| 155 |
// Check N o n c e |
| 156 |
check_admin_referer( 'wpbm_settings_page_' . $this_submit_form ); // Its stop show anything on submiting, if its not refear to the original page |
| 157 |
|
| 158 |
// Make Update of settings |
| 159 |
$edit_field_data = $this->update_wpbm_emails_toolbar( $menu_slug ); |
| 160 |
} |
| 161 |
//////////////////////////////////////////////////////////////////////// |
| 162 |
*/ |
| 163 |
abstract public function content(); |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
//////////////////////////////////////////////////////////////////////////// |
| 168 |
// C O N T E N T |
| 169 |
//////////////////////////////////////////////////////////////////////////// |
| 170 |
|
| 171 |
/** General Page Structure |
| 172 |
* |
| 173 |
* @param string $page_tag - its the same that return $this->in_page() |
| 174 |
*/ |
| 175 |
public function content_structure( $page_tag ) { |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
if ( ! $this->is_page_activated() ) |
| 180 |
return false; |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
$active_page_tab = $active_page_subtab = ''; |
| 185 |
if ( ( isset( $this->current_page_params['tab'] ) ) && ( ! empty( $this->current_page_params['tab']['tag'] ) ) ) |
| 186 |
$active_page_tab = $this->current_page_params['tab']['tag']; |
| 187 |
if ( ( isset( $this->current_page_params['subtab'] ) ) && ( ! empty( $this->current_page_params['subtab']['tag'] ) ) ) |
| 188 |
$active_page_subtab = $this->current_page_params['subtab']['tag']; |
| 189 |
|
| 190 |
$is_show_this_page = apply_filters( 'wpbm_before_showing_settings_page_is_show_page', true, $page_tag, $active_page_tab, $active_page_subtab ); // Fires Before showing settings Content page |
| 191 |
|
| 192 |
if ( $is_show_this_page === false ) return false; |
| 193 |
|
| 194 |
do_action( 'wpbm_before_settings_content', $page_tag, $active_page_tab, $active_page_subtab ); // Fires Before showing settings Content page |
| 195 |
|
| 196 |
?><div id="<?php echo $page_tag; ?>-admin-page" class="wrap wpbm_page"><?php |
| 197 |
do_action( 'wpbm_settings_before_header', $page_tag, $active_page_tab, $active_page_subtab ); // FixIn: N |
| 198 |
?> |
| 199 |
<h1 class="wpbm_header"><div class="wpbm_header_icon"></div><?php echo $this->get_page_header_h1(); ?></h1><?php |
| 200 |
do_action( 'wpbm_settings_after_header', $page_tag, $active_page_tab, $active_page_subtab ); // FixIn: N |
| 201 |
?> |
| 202 |
<div class="wpbm_admin_message"></div> |
| 203 |
<div class="wpbm_admin_page"> |
| 204 |
<div id="ajax_working"></div> |
| 205 |
<div class="clear wpbm_header_margin"></div> |
| 206 |
<div id="ajax_respond" class="ajax_respond" style="display:none;"></div> |
| 207 |
<?php |
| 208 |
|
| 209 |
// T A B S |
| 210 |
$this->show_tabs_structure( $page_tag ); |
| 211 |
|
| 212 |
wp_nonce_field('wpbm_ajax_admin_nonce', "wpbm_admin_panel_nonce" , true , true ); |
| 213 |
|
| 214 |
// C o n t e n t |
| 215 |
if ( ( isset( $this->current_page_params['subtab'] ) ) && ( isset( $this->current_page_params['subtab']['content'] ) ) ) { |
| 216 |
|
| 217 |
call_user_func( array( $this, $this->current_page_params['subtab']['content'] ) ); |
| 218 |
|
| 219 |
} else if ( ( isset( $this->current_page_params['tab'] ) ) && ( isset( $this->current_page_params['tab']['content'] ) ) ) { |
| 220 |
call_user_func( array( $this, $this->current_page_params['tab']['content'] ) ); |
| 221 |
|
| 222 |
} else |
| 223 |
$this->content(); |
| 224 |
|
| 225 |
do_action('wpbm_show_settings_content' , $page_tag, $active_page_tab, $active_page_subtab ); |
| 226 |
?></div> |
| 227 |
</div><?php |
| 228 |
|
| 229 |
do_action( 'wpbm_after_settings_content', $page_tag, $active_page_tab, $active_page_subtab ); // Fires After showing settings Content page |
| 230 |
} |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
//////////////////////////////////////////////////////////////////////////// |
| 235 |
// Active Page Parameters |
| 236 |
//////////////////////////////////////////////////////////////////////////// |
| 237 |
|
| 238 |
/** Check if this page selected (active), depend from the GET parameter |
| 239 |
* If selected, then define Current Page Parameters. |
| 240 |
* |
| 241 |
* @return boolean |
| 242 |
*/ |
| 243 |
private function is_page_activated() { |
| 244 |
|
| 245 |
$is_page_selected = false; |
| 246 |
|
| 247 |
$this_page = $this->in_page(); |
| 248 |
|
| 249 |
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!!! |
| 250 |
break; |
| 251 |
} |
| 252 |
|
| 253 |
if ( empty( $this_tab ) ) |
| 254 |
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. |
| 255 |
|
| 256 |
$this_subtab_tag = 0; |
| 257 |
$this_subtab = array( 'default' => false ); |
| 258 |
|
| 259 |
if ( isset( $this_tab['subtabs'] ) ) |
| 260 |
foreach ( $this_tab['subtabs'] as $temp_this_subtab_tag => $temp_this_subtab ) { |
| 261 |
|
| 262 |
if ( $temp_this_subtab['type'] == 'subtab' ) { // Get First Subtab element from subtabs array |
| 263 |
$this_subtab_tag = $temp_this_subtab_tag; |
| 264 |
$this_subtab = $temp_this_subtab; |
| 265 |
break; |
| 266 |
} |
| 267 |
} |
| 268 |
|
| 269 |
//debuge($this_page, $_REQUEST); |
| 270 |
if ( ( isset( $_REQUEST[ 'page' ] ) ) |
| 271 |
&& ( $this_page == $_REQUEST[ 'page' ] ) ){ // We are inside of this page. Menu item selected. |
| 272 |
|
| 273 |
if ( ( ! isset( $_REQUEST[ $this->tags['tab'] ] ) ) // TAB NOT selected && Default |
| 274 |
//&& ( ! isset( $_REQUEST[ $this->tags['subtab'] ] ) ) // SubTab NOT selected |
| 275 |
&& ( isset( $this_tab['default'] ) ) && ( $this_tab['default'] ) |
| 276 |
) |
| 277 |
$is_page_selected = true; |
| 278 |
|
| 279 |
if ( ( isset( $_REQUEST[ $this->tags['tab'] ] ) ) // TAB Selected |
| 280 |
&& ( ! isset( $_REQUEST[ $this->tags['subtab'] ] ) ) // SubTab NOT selected && ! exist || Default |
| 281 |
&& ( $_REQUEST[ $this->tags['tab'] ] == $this_tab_tag ) |
| 282 |
&& ( ( $this_subtab_tag === 0 ) |
| 283 |
|| ( $this_subtab['default'] ) |
| 284 |
) |
| 285 |
) |
| 286 |
$is_page_selected = true; |
| 287 |
|
| 288 |
if ( ( isset( $_REQUEST[ $this->tags['tab'] ] ) ) // TAB Selected |
| 289 |
&& ( isset( $_REQUEST[ $this->tags['subtab'] ] ) ) // SubTab Selected |
| 290 |
&& ( $_REQUEST[ $this->tags['tab'] ] == $this_tab_tag ) |
| 291 |
&& ( $_REQUEST[ $this->tags['subtab'] ] == $this_subtab_tag ) |
| 292 |
) |
| 293 |
$is_page_selected = true; |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
if ( $is_page_selected ) // If this page activated, then define Current Page parameters |
| 298 |
$this->define_current_page_parameters( $this_tab_tag, $this_tab, $this_subtab_tag, $this_subtab ); |
| 299 |
|
| 300 |
return $is_page_selected; |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
/** Define parameters for current selected page |
| 305 |
* |
| 306 |
* @param type $paramas |
| 307 |
*/ |
| 308 |
private function define_current_page_parameters( $this_tab_tag, $this_tab, $this_subtab_tag, $this_subtab ) { |
| 309 |
|
| 310 |
$this->current_page_params = array( |
| 311 |
'tab' => array_merge ( $this_tab, array( 'tag' => $this_tab_tag ) ) |
| 312 |
, 'subtab' => array_merge ( $this_subtab, array( 'tag' => $this_subtab_tag ) ) |
| 313 |
); |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
/** Get Header Title (H1) of this selected page |
| 318 |
* Firstly check in subtabs, otherwise get from tabs and if not exist then |
| 319 |
* |
| 320 |
* @return string |
| 321 |
*/ |
| 322 |
private function get_page_header_h1() { |
| 323 |
|
| 324 |
if ( ! empty( $this->current_page_params ) ) { |
| 325 |
|
| 326 |
if ( isset( $this->current_page_params['subtab']['page_title'] ) ) |
| 327 |
return $this->current_page_params['subtab']['page_title']; |
| 328 |
|
| 329 |
if ( isset( $this->current_page_params['tab']['page_title'] ) ) |
| 330 |
return $this->current_page_params['tab']['page_title']; |
| 331 |
} |
| 332 |
|
| 333 |
return ''; |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
/** Get all SubTabs of current opened page Tab |
| 338 |
* |
| 339 |
* @param string $menu_in_page_tag - Optional. Menu Tag, the same as $this->in_page(); |
| 340 |
* @return array |
| 341 |
*/ |
| 342 |
private function get_all_sub_tabs_of_selected_tab( $menu_in_page_tag = false ) { |
| 343 |
|
| 344 |
if ($menu_in_page_tag === false ) |
| 345 |
$menu_in_page_tag = $this->in_page(); |
| 346 |
|
| 347 |
$all_sub_tabs_of_selected_tab = self::$nav_tabs[ $menu_in_page_tag ][ $this->current_page_params['tab']['tag'] ]['subtabs']; |
| 348 |
|
| 349 |
return $all_sub_tabs_of_selected_tab; |
| 350 |
} |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
//////////////////////////////////////////////////////////////////////////// |
| 355 |
// T A B s |
| 356 |
//////////////////////////////////////////////////////////////////////////// |
| 357 |
|
| 358 |
// Define ------------------------------------------------------------------ |
| 359 |
|
| 360 |
/** Define TABS structure. |
| 361 |
* General structure of tabs for every plugin menu page. |
| 362 |
*/ |
| 363 |
public function wpbm_define_nav_tabs() { // Function executed after creation menu in class WPBM_Admin_Menus |
| 364 |
/* |
| 365 |
Array ( |
| 366 |
[wpbm-resources] => Array () |
| 367 |
[wpbm-settings] => Array |
| 368 |
( |
| 369 |
[general] => Array |
| 370 |
( |
| 371 |
[title] => General |
| 372 |
[page_title] => General Settings |
| 373 |
... |
| 374 |
[subtabs] => Array () |
| 375 |
) |
| 376 |
[help] => Array |
| 377 |
( |
| 378 |
[title] => Help |
| 379 |
[page_title] => |
| 380 |
... |
| 381 |
[subtabs] => Array () |
| 382 |
) |
| 383 |
[form] => Array |
| 384 |
( |
| 385 |
[title] => Form |
| 386 |
[hint] => Customizaton of Form Fields |
| 387 |
[page_title] => Form Fields |
| 388 |
... |
| 389 |
[subtabs] => Array |
| 390 |
( |
| 391 |
[goto-form] => Array |
| 392 |
( |
| 393 |
[type] => goto-link |
| 394 |
[title] => Form Fields |
| 395 |
... |
| 396 |
[content] => content |
| 397 |
[update] => update |
| 398 |
) |
| 399 |
|
| 400 |
[goto-content-data] => Array |
| 401 |
( |
| 402 |
[type] => button |
| 403 |
[title] => Save Changes |
| 404 |
[form] => wpbm_form |
| 405 |
... |
| 406 |
) |
| 407 |
|
| 408 |
) |
| 409 |
|
| 410 |
) |
| 411 |
[payment] => Array |
| 412 |
( |
| 413 |
[title] => Payments |
| 414 |
[hint] => Customizaton of Payment |
| 415 |
[page_title] => Payment Gateways |
| 416 |
... |
| 417 |
[subtabs] => Array |
| 418 |
( |
| 419 |
[paypal] => Array |
| 420 |
( |
| 421 |
[type] => subtab |
| 422 |
[title] => PayPal |
| 423 |
... |
| 424 |
) |
| 425 |
|
| 426 |
[sage] => Array |
| 427 |
( |
| 428 |
[type] => subtab |
| 429 |
[title] => Sage |
| 430 |
... |
| 431 |
) |
| 432 |
|
| 433 |
) |
| 434 |
|
| 435 |
) |
| 436 |
|
| 437 |
) |
| 438 |
|
| 439 |
) |
| 440 |
*/ |
| 441 |
|
| 442 |
if ( ! isset( self::$nav_tabs[ $this->in_page() ] ) ) |
| 443 |
self::$nav_tabs[ $this->in_page() ] = array(); // If this page does not exist, then define it. |
| 444 |
|
| 445 |
$current_tab = $this->tabs(); |
| 446 |
$current_subtabs = array(); // Get Subtabs in separate array. |
| 447 |
foreach ( $current_tab as $tab_tag => $tab_array ) { |
| 448 |
|
| 449 |
if ( isset( $tab_array[ 'subtabs' ] ) ) { |
| 450 |
$current_subtabs[ $tab_tag ] = $tab_array[ 'subtabs' ]; // Create new Subtabs array |
| 451 |
|
| 452 |
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. |
| 453 |
} else |
| 454 |
$current_subtabs[ $tab_tag ] = array(); |
| 455 |
} |
| 456 |
|
| 457 |
|
| 458 |
foreach ( $current_tab as $tab_tag => $tab_array ) { |
| 459 |
|
| 460 |
if ( ! isset( self::$nav_tabs[ $this->in_page() ][ $tab_tag ] ) ) { // If this tab ( for exmaple "payment") declared previously, then does not do anything |
| 461 |
|
| 462 |
self::$nav_tabs[ $this->in_page() ][ $tab_tag ] = $current_tab[ $tab_tag ]; |
| 463 |
self::$nav_tabs[ $this->in_page() ][ $tab_tag ][ 'subtabs' ] = array(); |
| 464 |
} |
| 465 |
|
| 466 |
if ( isset(self::$nav_tabs[ $this->in_page() ] ) ) { |
| 467 |
// Merge subtabs (Ex: PayPal and Sage) and attach to current tab: (Ex: payment) |
| 468 |
self::$nav_tabs[ $this->in_page() ][ $tab_tag ][ 'subtabs' ] = array_merge( |
| 469 |
self::$nav_tabs[ $this->in_page() ][ $tab_tag ][ 'subtabs' ] |
| 470 |
, $current_subtabs[ $tab_tag ] |
| 471 |
); |
| 472 |
} |
| 473 |
} |
| 474 |
} |
| 475 |
|
| 476 |
/** Get array of visible TABs |
| 477 |
* Tabs that do not hided or disbaled |
| 478 |
* |
| 479 |
* @param string $menu_in_page_tag - Menu Tag, the same as $this->in_page(); |
| 480 |
* @return type |
| 481 |
*/ |
| 482 |
private function get_visible_tabs( $menu_in_page_tag ) { |
| 483 |
|
| 484 |
$visible_tabs = array(); |
| 485 |
|
| 486 |
foreach ( self::$nav_tabs[ $menu_in_page_tag ] as $tab_tag => $tab ) { |
| 487 |
|
| 488 |
if ( empty( $tab['disabled'] ) |
| 489 |
&& empty( $tab['hided'] ) |
| 490 |
) { |
| 491 |
$visible_tabs[$tab_tag] = $tab; |
| 492 |
} |
| 493 |
} |
| 494 |
|
| 495 |
return $visible_tabs; |
| 496 |
} |
| 497 |
|
| 498 |
// Showing ----------------------------------------------------------------- |
| 499 |
|
| 500 |
/** |
| 501 |
* |
| 502 |
* @param string $menu_in_page_tag - Menu Tag, the same as $this->in_page(); |
| 503 |
* @return boolean - true if nav tabs exist and false if does not exist |
| 504 |
*/ |
| 505 |
public function show_tabs_structure( $menu_in_page_tag ) { |
| 506 |
|
| 507 |
// Exit if no Tabs in this page. |
| 508 |
if ( empty( self::$nav_tabs[ $menu_in_page_tag ] ) ) |
| 509 |
return false; |
| 510 |
|
| 511 |
// Exit if tabs hidded or disbaled |
| 512 |
$visible_tabs = $this->get_visible_tabs( $menu_in_page_tag ); |
| 513 |
if ( empty( $visible_tabs ) ) |
| 514 |
return false; |
| 515 |
|
| 516 |
?><span class="wpdevelop wpdvlp-nav-tabs-container"> |
| 517 |
<div class="clear"></div><?php |
| 518 |
|
| 519 |
wpbm_bs_toolbar_tabs_html_container_start(); |
| 520 |
|
| 521 |
do_action( 'wpbm_toolbar_top_tabs_before' , $menu_in_page_tag ); |
| 522 |
|
| 523 |
$this->show_tabs_line( $menu_in_page_tag ); // T O P T A B S |
| 524 |
|
| 525 |
do_action( 'wpbm_toolbar_top_tabs_after' , $menu_in_page_tag ); |
| 526 |
|
| 527 |
wpbm_bs_toolbar_tabs_html_container_end(); |
| 528 |
|
| 529 |
|
| 530 |
$bottom_tabs = $this->get_all_sub_tabs_of_selected_tab( $menu_in_page_tag ); |
| 531 |
|
| 532 |
if ( ! empty( $bottom_tabs ) ) { // S U B T A B S |
| 533 |
|
| 534 |
wpbm_bs_toolbar_sub_html_container_start(); |
| 535 |
|
| 536 |
$this->show_subtabs_line( $bottom_tabs, $menu_in_page_tag ); |
| 537 |
|
| 538 |
wpbm_bs_toolbar_sub_html_container_end(); |
| 539 |
|
| 540 |
} // Bottom Tabs |
| 541 |
|
| 542 |
?></span><?php |
| 543 |
|
| 544 |
return true; |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
/** Show Top nav TABs line |
| 549 |
* |
| 550 |
* @param string $menu_in_page_tag - Menu Tag, the same as $this->in_page(); |
| 551 |
*/ |
| 552 |
public function show_tabs_line( $menu_in_page_tag ) { |
| 553 |
|
| 554 |
foreach ( self::$nav_tabs[ $menu_in_page_tag ] as $tab_tag => $tab ) { |
| 555 |
|
| 556 |
$css_classes = ( ( isset($tab['css_classes']) ) ? $tab['css_classes'] : '' ); |
| 557 |
|
| 558 |
if ( ( isset( $this->current_page_params['tab'] ) ) && ( $this->current_page_params['tab']['tag'] == $tab_tag ) ) |
| 559 |
$css_classes .= ' nav-tab-active'; |
| 560 |
|
| 561 |
if ( ! empty( $tab['position'] ) ) |
| 562 |
$css_classes .= ' nav-tab-position-' . $tab['position']; |
| 563 |
|
| 564 |
if ( ! empty( $tab['hided'] ) ) |
| 565 |
$css_classes .= ' hide'; |
| 566 |
|
| 567 |
if ( ( isset( $tab['disabled'] ) ) && ( $tab['disabled'] ) ) |
| 568 |
$css_classes .= ' wpdevelop-tab-disabled'; |
| 569 |
|
| 570 |
$tab['css_classes'] = $css_classes; |
| 571 |
|
| 572 |
$tab['link'] = ( ! empty($tab['link']) ? $tab['link'] : $this->get_tab_url( $menu_in_page_tag, $tab_tag ) ); |
| 573 |
|
| 574 |
if ( // Recheck active status of default TAB |
| 575 |
( isset( $_REQUEST[ $this->tags['tab'] ] ) ) // Some Tab selected |
| 576 |
&& ( $_REQUEST[ $this->tags['tab'] ] !== $tab_tag ) // This tag not in URL |
| 577 |
&& ( isset($tab['default']) && ( $tab['default'] ) ) // This tab default, need to set it as not defaultm for not showing it selected |
| 578 |
) |
| 579 |
$tab['default'] = false; |
| 580 |
|
| 581 |
wpbm_bs_display_tab( $tab ); |
| 582 |
|
| 583 |
} |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
/** Show Sub Menu Lines at the Settings page for Active Tab |
| 588 |
* |
| 589 |
* @param array $bottom_tabs |
| 590 |
* @param string $menu_in_page_tag - Menu Tag, the same as $this->in_page(); |
| 591 |
*/ |
| 592 |
public function show_subtabs_line( $bottom_tabs, $menu_in_page_tag ) { |
| 593 |
|
| 594 |
if ( ! empty( $bottom_tabs ) ) |
| 595 |
foreach ( $bottom_tabs as $tab_tag => $tab ) { |
| 596 |
|
| 597 |
switch ( $tab['type'] ) { |
| 598 |
case 'separator': // Separator |
| 599 |
?><span class="wpdevelop-submenu-tab-separator-vertical"></span><?php |
| 600 |
break; |
| 601 |
|
| 602 |
case 'button': // Button |
| 603 |
?><div class="clear-for-mobile"></div><input |
| 604 |
type="button" |
| 605 |
class="button button-primary wpbm_submit_button" |
| 606 |
value="<?php echo $tab['title']; ?>" |
| 607 |
onclick="if (typeof document.forms['<?php echo $tab['form']; ?>'] !== 'undefined'){ document.forms['<?php echo $tab['form']; ?>'].submit(); } else { wpbm_admin_show_message( '<?php echo ' <strong>', __('Error', 'booking-manager') ,'!</strong> ', __('Form', 'booking-manager') , ' <strong>' , $tab['form'] , '</strong> ', __('does not exist', 'booking-manager'); ?>.', 'error', 10000 ); }" |
| 608 |
/><?php |
| 609 |
break; |
| 610 |
|
| 611 |
case 'html': // HTML |
| 612 |
echo $tab['html']; |
| 613 |
break; |
| 614 |
|
| 615 |
case 'goto-link': |
| 616 |
?><a class="nav-tab wpdevelop-submenu-tab go-to-link" |
| 617 |
original-title="<?php echo (empty($tab['hint'])?'':$tab['hint']); ?>" |
| 618 |
onclick="javascript:wpbm_scroll_to('#<?php echo esc_js( $tab['show_section'] ); ?>' );" |
| 619 |
href="javascript:void(0);"><span><?php echo $tab['title']; ?></span></a><?php |
| 620 |
break; |
| 621 |
|
| 622 |
default: // Link |
| 623 |
|
| 624 |
$css_classes = ( ( isset($tab['css_classes']) ) ? $tab['css_classes'] : '' ); |
| 625 |
if ( ! empty($tab['position'] ) ) |
| 626 |
$css_classes .= ' nav-tab-position-'.$tab['position']; |
| 627 |
if ( $tab_tag == $this->current_page_params['subtab']['tag'] ) |
| 628 |
$css_classes .= ' wpdevelop-submenu-tab-selected'; |
| 629 |
if ( $tab['disabled'] ) |
| 630 |
$css_classes .= ' wpdevelop-submenu-tab-disabled'; |
| 631 |
|
| 632 |
$tab['css_classes'] = $css_classes; |
| 633 |
|
| 634 |
$tab['link'] = ( ! empty($tab['link']) ? $tab['link'] : $this->get_tab_url( $menu_in_page_tag, $this->current_page_params['tab']['tag'], $tab_tag ) ); |
| 635 |
|
| 636 |
$tab['top'] = false; |
| 637 |
wpbm_bs_display_tab( $tab ); |
| 638 |
|
| 639 |
break; |
| 640 |
|
| 641 |
} // End Switch |
| 642 |
} // End Bottom Tabs Loop |
| 643 |
|
| 644 |
} |
| 645 |
|
| 646 |
|
| 647 |
//////////////////////////////////////////////////////////////////////////// |
| 648 |
// Support |
| 649 |
//////////////////////////////////////////////////////////////////////////// |
| 650 |
|
| 651 |
/** Get URL of settings page, based on Page Slug and Tab Slug |
| 652 |
* |
| 653 |
* @param string $page_tag |
| 654 |
* @param string $tab_name |
| 655 |
* @param string $subtab_name ( Optional ) |
| 656 |
* @return string - Escaped URL to plugin page. |
| 657 |
*/ |
| 658 |
private function get_tab_url( $page_tag, $tab_name, $subtab_name = false ){ |
| 659 |
if ( $subtab_name === false ) |
| 660 |
return esc_url( admin_url( add_query_arg( array( 'page' => $page_tag, $this->tags['tab'] => $tab_name ), 'admin.php' ) ) ); |
| 661 |
else |
| 662 |
return esc_url( admin_url( add_query_arg( array( 'page' => $page_tag, $this->tags['tab'] => $tab_name, $this->tags['subtab'] => $subtab_name ), 'admin.php' ) ) ); |
| 663 |
} |
| 664 |
|
| 665 |
} |