1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* UIX header |
4
|
|
|
* |
5
|
|
|
* @package ui |
6
|
|
|
* @author David Cramer |
7
|
|
|
* @license GPL-2.0+ |
8
|
|
|
* @link |
9
|
|
|
* @copyright 2016 David Cramer |
10
|
|
|
*/ |
11
|
|
|
namespace uix\ui; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* A generic holder for multiple controls. this panel type does not handle saving, but forms part of the data object tree. |
15
|
|
|
* |
16
|
|
|
* @since 1.0.0 |
17
|
|
|
* @see \uix\uix |
18
|
|
|
*/ |
19
|
|
|
class header extends section { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The type of object |
23
|
|
|
* |
24
|
|
|
* @since 1.0.0 |
25
|
|
|
* @access public |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
public $type = 'header'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* type of header element |
32
|
|
|
* |
33
|
|
|
* @since 1.0.0 |
34
|
|
|
* @access public |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
public $element = 'h1'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* List of attributes to apply to the wrapper element |
41
|
|
|
* |
42
|
|
|
* @since 1.0.0 |
43
|
|
|
* @access public |
44
|
|
|
* @var array |
45
|
|
|
*/ |
46
|
|
|
public $attributes = array( 'class' => 'uix-title' ); |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Set the element type |
50
|
|
|
* |
51
|
|
|
* @since 1.0.0 |
52
|
|
|
* @access public |
53
|
|
|
*/ |
54
|
|
|
public function init() { |
55
|
|
|
if ( ! empty( $this->struct['element'] ) ) { |
56
|
|
|
$this->element = $this->struct['element']; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Render the complete section |
63
|
|
|
* |
64
|
|
|
* @since 1.0.0 |
65
|
|
|
* @access public |
66
|
|
|
* @return string|null HTML of rendered notice |
67
|
|
|
*/ |
68
|
2 |
|
public function render() { |
69
|
|
|
|
70
|
2 |
|
$output = '<' . $this->element . ' ' . $this->build_attributes() . '>'; |
71
|
|
|
|
72
|
2 |
|
$output .= $this->label(); |
73
|
|
|
|
74
|
2 |
|
$output .= $this->description(); |
75
|
|
|
|
76
|
2 |
|
$output .= $this->render_template(); |
77
|
|
|
|
78
|
2 |
|
if ( ! empty( $this->child ) ) { |
79
|
|
|
$output .= $this->render_children(); |
80
|
|
|
} |
81
|
|
|
|
82
|
2 |
|
$output .= '</' . $this->element . '>'; |
83
|
|
|
|
84
|
2 |
|
return $output; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Render the panels label |
89
|
|
|
* |
90
|
|
|
* @since 1.0.0 |
91
|
|
|
* @access public |
92
|
|
|
* @return string|null rendered html of label |
93
|
|
|
*/ |
94
|
2 |
View Code Duplication |
public function label() { |
|
|
|
|
95
|
2 |
|
$output = null; |
96
|
2 |
|
if ( ! empty( $this->struct['label'] ) ) { |
97
|
2 |
|
$output .= '<span class="uix-text">' . esc_html( $this->struct['label'] ) . '</span>'; |
98
|
|
|
} |
99
|
|
|
|
100
|
2 |
|
return $output; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Render the panels Description |
105
|
|
|
* |
106
|
|
|
* @since 1.0.0 |
107
|
|
|
* @access public |
108
|
|
|
* @return string|null HTML of rendered description |
109
|
|
|
*/ |
110
|
2 |
View Code Duplication |
public function description() { |
|
|
|
|
111
|
2 |
|
$output = null; |
112
|
2 |
|
if ( ! empty( $this->struct['description'] ) ) { |
113
|
|
|
$output .= ' <small>' . esc_html( $this->struct['description'] ) . '</small>'; |
114
|
|
|
} |
115
|
|
|
|
116
|
2 |
|
return $output; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Define core header styles |
121
|
|
|
* |
122
|
|
|
* @since 1.0.0 |
123
|
|
|
* @access public |
124
|
|
|
*/ |
125
|
4 |
|
public function set_assets() { |
126
|
|
|
|
127
|
4 |
|
$this->assets['style']['header'] = $this->url . 'assets/css/header' . UIX_ASSET_DEBUG . '.css'; |
128
|
|
|
|
129
|
4 |
|
parent::set_assets(); |
130
|
4 |
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* checks if the current section is active |
134
|
|
|
* |
135
|
|
|
* @since 1.0.0 |
136
|
|
|
* @access public |
137
|
|
|
*/ |
138
|
|
|
public function is_active() { |
139
|
|
|
return $this->parent->is_active(); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.