1 <?php
2 3 4 5 6 7 8 9 10
11 namespace uix\ui;
12
13 14 15 16 17
18 class page extends box implements \uix\data\save{
19
20 21 22 23 24 25 26
27 public $type = 'page';
28
29 30 31 32 33 34 35
36 public $screen_hook_suffix = array();
37
38
39 40 41 42 43 44
45 protected function actions() {
46
47 parent::actions();
48
49 if( empty( $this->struct[ 'page_title' ] ) || empty( $this->struct['menu_title'] ) )
50 return;
51
52
53 $this->setup_pages();
54
55 }
56
57 58 59 60 61 62
63 private function setup_pages(){
64
65 $args = array(
66 'capability' => 'manage_options',
67 'icon' => null,
68 'position' => null
69 );
70 $this->struct['args'] = array_merge( $args, $this->struct );
71
72 if( !isset( $this->struct['parent'] ) ) {
73 add_action('admin_menu', array($this, 'add_settings_page'), 9);
74 }else{
75 add_action('admin_menu', array($this, 'add_sub_page'), 9);
76 }
77
78 }
79
80
81 82 83 84 85 86
87 public function set_assets() {
88
89 $this->assets['style']['page'] = $this->url . 'assets/css/page' . UIX_ASSET_DEBUG . '.css';
90
91 parent::set_assets();
92 }
93
94 95 96 97 98 99
100 public function set_attributes(){
101
102 parent::set_attributes();
103
104 $this->attributes['class'] = 'wrap uix-ajax uix-page';
105
106 if( empty( $this->struct['full_width'] ) )
107 $this->attributes['class'] .= ' uix-half-page';
108
109 if( !empty( $this->struct['attributes'] ) )
110 $this->attributes = array_merge( $this->attributes, $this->struct['attributes'] );
111
112
113
114 }
115
116
117 118 119 120 121 122
123 public function store_key(){
124
125 if( !empty( $this->struct['store_key'] ) ){
126 $store_key = $this->struct['store_key'];
127 }else{
128 $store_key = 'uix-' . $this->type . '-' . sanitize_text_field( $this->slug );
129 }
130
131 return $store_key;
132 }
133
134 135 136 137 138
139 public function is_active(){
140 if( !is_admin() ){ return false; }
141
142
143 $screen = get_current_screen();
144 return $screen->base === $this->screen_hook_suffix;
145
146 }
147
148 149 150 151 152 153
154 protected function enqueue_active_assets(){
155
156 parent::enqueue_active_assets();
157
158 echo '<style type="text/css">';
159
160 echo '.uix-page #panel-' . $this->id() . ' > .uix-panel-tabs > li[aria-selected="true"] a {box-shadow: 0 -3px 0 ' . $this->base_color() . ' inset;}';
161 echo '.uix-page #panel-' . $this->id() . '.uix-top-tabs > .uix-panel-tabs > li[aria-selected="true"] a {box-shadow: 0 3px 0 ' . $this->base_color() . ' inset;}';
162
163 echo '.contextual-help-tabs .active {border-left: 6px solid ' . $this->base_color(). ' !important;}';
164 echo '#' . $this->id() . '.uix-page h1{box-shadow: 0 0 2px rgba(0, 2, 0, 0.1),11px 0 0 ' . $this->base_color() . ' inset;}';
165 echo '#' . $this->id() . '.uix-page .page-title-action:hover{background: ' . $this->base_color() . ';border-color: rgba(0,0,0,0.1);}';
166 echo '#' . $this->id() . '.uix-page .page-title-action:focus{box-shadow: 0 0 2px ' . $this->base_color() . ';border-color: ' . $this->base_color() . ';}';
167
168 if( $this->child_count() > 1 )
169 echo '#' . $this->id() . '.uix-page h1{ box-shadow: 0 0px 13px 12px ' . $this->base_color() . ', 11px 0 0 ' . $this->base_color() . ' inset;}';
170
171 echo '</style>';
172
173 }
174
175 176 177 178 179 180 181
182 public function add_settings_page(){
183
184 $this->screen_hook_suffix = add_menu_page(
185 $this->struct['args'][ 'page_title' ],
186 $this->struct['args'][ 'menu_title' ],
187 $this->struct['args'][ 'capability' ],
188 $this->slug,
189 array( $this, 'create_page' ),
190 $this->struct['args'][ 'icon' ],
191 $this->struct['args'][ 'position' ]
192 );
193
194 }
195
196 197 198 199 200 201 202
203 public function add_sub_page(){
204
205 $this->screen_hook_suffix = add_submenu_page(
206 $this->struct['args'][ 'parent' ],
207 $this->struct['args'][ 'page_title' ],
208 $this->struct['args'][ 'menu_title' ],
209 $this->struct['args'][ 'capability' ],
210 $this->slug,
211 array( $this, 'create_page' )
212 );
213
214 }
215
216 217 218 219 220 221
222 public function create_page(){
223 echo $this->render();
224 }
225
226
227
228 }