| 1 |
<?php |
| 2 |
/** |
| 3 |
* Screen UI |
| 4 |
* |
| 5 |
* @namespace UsabilityDynamics |
| 6 |
* |
| 7 |
*/ |
| 8 |
namespace UsabilityDynamics\UD_API { |
| 9 |
|
| 10 |
if( !class_exists( 'UsabilityDynamics\UD_API\UI' ) ) { |
| 11 |
|
| 12 |
/** |
| 13 |
* |
| 14 |
* @author: peshkov@UD |
| 15 |
*/ |
| 16 |
class UI extends Scaffold { |
| 17 |
|
| 18 |
/** |
| 19 |
* Available Screens |
| 20 |
*/ |
| 21 |
public $available_screens; |
| 22 |
|
| 23 |
/** |
| 24 |
* Token |
| 25 |
*/ |
| 26 |
public $token; |
| 27 |
|
| 28 |
/** |
| 29 |
* Constructor |
| 30 |
*/ |
| 31 |
public function __construct( $args ) { |
| 32 |
parent::__construct( $args ); |
| 33 |
$this->token = isset( $args[ 'token' ] ) ? $args[ 'token' ] : array(); |
| 34 |
$this->available_screens = isset( $args[ 'screens' ] ) ? $args[ 'screens' ] : array(); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Generate header HTML. |
| 39 |
* @access public |
| 40 |
* @since 1.0.0 |
| 41 |
* @return void |
| 42 |
*/ |
| 43 |
public function get_header ( $token = 'ud-license-manager' ) { |
| 44 |
global $current_screen; |
| 45 |
do_action( 'ud_licenses_screen_before', $token ); |
| 46 |
$html = '<div class="wrap ud-licenses-wrap">' . "\n"; |
| 47 |
$html .= '<h2 class="ud-licenses-title">' . get_admin_page_title() . '</h2>' . "\n"; |
| 48 |
$html .= '<h2 class="nav-tab-wrapper">' . "\n"; |
| 49 |
$html .= $this->get_navigation_tabs(); |
| 50 |
$html .= '</h2>' . "\n"; |
| 51 |
echo $html; |
| 52 |
do_action( 'ud_licenses_screen_header_before_content', $token ); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Generate footer HTML. |
| 57 |
* @access public |
| 58 |
* @since 1.0.0 |
| 59 |
* @return void |
| 60 |
*/ |
| 61 |
public function get_footer ( $token = 'ud-license-manager', $screen_icon = 'tools' ) { |
| 62 |
do_action( 'ud_licenses_screen_footer_after_content', $token, $screen_icon ); |
| 63 |
$html = '</div><!--/.wrap ud-licenses-wrap-->' . "\n"; |
| 64 |
echo $html; |
| 65 |
do_action( 'ud_licenses_screen_after', $token, $screen_icon ); |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Generate navigation tabs HTML, based on a specific admin menu. |
| 70 |
* @access public |
| 71 |
* @since 1.0.0 |
| 72 |
* @return string/WP_Error |
| 73 |
*/ |
| 74 |
public function get_navigation_tabs () { |
| 75 |
$html = ''; |
| 76 |
|
| 77 |
$screens = !empty( $this->available_screens ) && is_array( $this->available_screens ) ? $this->available_screens : array(); |
| 78 |
$licenses_url = get_option( $this->token . '-url', '' ); |
| 79 |
|
| 80 |
$current_tab = self::get_current_screen(); |
| 81 |
if ( 0 < count( $screens ) ) { |
| 82 |
foreach ( $screens as $k => $v ) { |
| 83 |
$class = 'nav-tab'; |
| 84 |
if ( $current_tab == $k ) { |
| 85 |
$class .= ' nav-tab-active'; |
| 86 |
} |
| 87 |
$url = add_query_arg( 'screen', $k, $licenses_url ); |
| 88 |
$html .= '<a href="' . esc_url( $url ) . '" class="' . esc_attr( $class ) . '">' . esc_html( $v ) . '</a>'; |
| 89 |
} |
| 90 |
} |
| 91 |
return $html; |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Return the token for the current screen. |
| 96 |
* @access public |
| 97 |
* @since 1.0.0 |
| 98 |
* @return string The token for the current screen. |
| 99 |
*/ |
| 100 |
public function get_current_screen () { |
| 101 |
$screen = 'licenses'; // Default. |
| 102 |
if ( isset( $_GET['screen'] ) && '' != $_GET['screen'] ) $screen = esc_attr( $_GET['screen'] ); |
| 103 |
return $screen; |
| 104 |
} |
| 105 |
|
| 106 |
} |
| 107 |
|
| 108 |
} |
| 109 |
|
| 110 |
} |