1 | <?php |
||
3 | abstract class Tabify_Edit_Screen_Settings_Base { |
||
4 | private $type; |
||
5 | private $sections; |
||
6 | private $base_url; |
||
7 | private $tabs; |
||
8 | |||
9 | private $options; |
||
10 | |||
11 | protected $items = array(); |
||
12 | protected $defaults = array(); |
||
13 | |||
14 | /** |
||
15 | * Set properties and load the sections and tabs |
||
16 | * |
||
17 | * @param string $type Where the settings are for |
||
18 | * |
||
19 | * @since 0.4.0 |
||
20 | */ |
||
21 | public function __construct( $type ) { |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Set the items property when needed. |
||
31 | * |
||
32 | * @since 1.0.0 |
||
33 | */ |
||
34 | abstract protected function load_items(); |
||
35 | |||
36 | /** |
||
37 | * Set properties and load the sections and tabs |
||
38 | * |
||
39 | * @return array The sections |
||
40 | * |
||
41 | * @since 0.4.0 |
||
42 | */ |
||
43 | abstract protected function load_sections(); |
||
44 | |||
45 | /** |
||
46 | * Get sections |
||
47 | * |
||
48 | * @return array The sections |
||
49 | * |
||
50 | * @since 0.4.0 |
||
51 | */ |
||
52 | protected function get_sections() { |
||
53 | return $this->sections; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Get the sections as a tab menu |
||
58 | * |
||
59 | * @since 0.4.0 |
||
60 | */ |
||
61 | public function get_sections_menu() { |
||
62 | echo $this->tabs->get_tabs_with_container(); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Get all the metaboxes that should always be showed |
||
67 | * |
||
68 | * @return array All the metaboxes id's in an array |
||
69 | * |
||
70 | * @since 0.4.0 |
||
71 | */ |
||
72 | public function get_default_items( $id ) { |
||
73 | $defaults = apply_filters( 'tabify_default_metaboxes', $this->defaults, $id, $this->type ); |
||
74 | $defaults = apply_filters( 'tabify_default_metaboxes_' . $this->type, $defaults, $id ); |
||
75 | |||
76 | return $defaults; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Echo all the items |
||
81 | * |
||
82 | * @since 0.4.0 |
||
83 | */ |
||
84 | public function get_sections_box() { |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * Get the html for one pacticular section |
||
101 | * |
||
102 | * @param string $section The section name |
||
103 | * |
||
104 | * @since 1.0.0 |
||
105 | */ |
||
106 | private function get_section_box( $section ) { |
||
107 | $options = $this->get_options( $this->type ); |
||
108 | $default_items = $this->get_default_items( $section ); |
||
109 | |||
110 | if ( ! isset( $options[ $section ] ) ) { |
||
111 | $options[ $section ] = array ( |
||
112 | 'tabs' => array( |
||
113 | array( |
||
114 | 'title' => __( 'Others', 'tabify-edit-screen' ), |
||
115 | 'items' => array() |
||
116 | ) |
||
117 | ) |
||
118 | ); |
||
119 | } |
||
120 | |||
121 | if ( $section == $this->tabs->get_current_tab() ) { |
||
122 | echo '<div class="tabifybox tabifybox-' . $section . '">'; |
||
123 | } |
||
124 | else { |
||
125 | echo '<div class="tabifybox tabifybox-hide tabifybox-' . $section . '" style="display: none;">'; |
||
126 | } |
||
127 | |||
128 | $checked = ''; |
||
129 | if ( isset( $options[ $section ]['show'] ) && $options[ $section ]['show'] == 1 ) { |
||
130 | $checked = ' checked="checked"'; |
||
131 | } |
||
132 | |||
133 | echo '<div class="tabifybox-options">'; |
||
134 | echo '<p id="show-type">'; |
||
135 | _e( 'Show tabs in this post type:', 'tabify-edit-screen' ); |
||
136 | echo ' <span class="switch">'; |
||
137 | echo '<input type="checkbox" name="tabify[' . $this->type . '][' . $section . '][show]" value="1" class="switch-checkbox" id="switch-' . $this->type . '-' . $section . '"' . $checked . '>'; |
||
138 | echo '<label data-tg-off="' . __( 'Off', 'tabify-edit-screen' ) . '" data-tg-on="' . __( 'On', 'tabify-edit-screen' ) . '" for="switch-' . $this->type . '-' . $section . '" class="switch-label"></label>'; |
||
139 | echo '</span>'; |
||
140 | echo '</p>'; |
||
141 | |||
142 | do_action( 'tabify_settings', $this->type, $section, $options[ $section ] ); |
||
143 | echo '</div>'; |
||
144 | |||
145 | echo '<div class="tabify_control tabify_control_tabs">'; |
||
146 | |||
147 | $tab_id = 0; |
||
148 | $remove = false; |
||
149 | |||
150 | if ( 1 < count( $options[ $section ]['tabs'] ) ) { |
||
151 | $remove = true; |
||
152 | } |
||
153 | |||
154 | foreach ( $options[ $section ]['tabs'] as $tab ) { |
||
155 | $tab['id'] = $tab_id; |
||
156 | |||
157 | if ( ! isset( $tab['permissions'] ) ) { |
||
158 | $tab['permissions'] = array(); |
||
159 | } |
||
160 | |||
161 | if ( $tab['title'] == '' ) { |
||
162 | $tab['title'] = __( 'Choose title', 'tabify-edit-screen' ); |
||
163 | } |
||
164 | |||
165 | echo '<div class="menu-item-handle tabify_tab">'; |
||
166 | |||
167 | $this->get_section_tab_title( $section, $tab['title'], $tab, $remove ); |
||
168 | $this->get_section_box_list( $section, $tab['items'], $tab_id, $default_items ); |
||
169 | |||
170 | echo '</div>'; |
||
171 | |||
172 | $tab_id++; |
||
173 | } |
||
174 | |||
175 | |||
176 | echo '</div>'; |
||
177 | |||
178 | echo '</div>'; |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * Get the html for one pacticular section |
||
183 | * |
||
184 | * @param string $section The section name |
||
185 | * @param string $title The title |
||
186 | * @param array $tab Tab information |
||
187 | * @param boolean $remove |
||
188 | * |
||
189 | * @since 0.4.0 |
||
190 | */ |
||
191 | private function get_section_tab_title( $section, $title, $tab, $remove ) { |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * Get the html for the section sortable list |
||
210 | * |
||
211 | * @param string $section The section name |
||
212 | * @param array $items List of all items in the section |
||
213 | * @param integer $tab_id The id of the tab the list is in |
||
214 | * @param array $default_items List of items that are always shown |
||
215 | * |
||
216 | * @since 1.0.0 |
||
217 | */ |
||
218 | private function get_section_box_list( $section, $items, $tab_id, $default_items ) { |
||
219 | $this->load_items(); |
||
220 | $options = $this->get_options( $this->type ); |
||
221 | |||
222 | echo '<ul>'; |
||
223 | if ( isset( $items ) ) { |
||
224 | foreach ( $items as $item_id ) { |
||
225 | if ( empty( $item_id ) ) { |
||
226 | continue; |
||
227 | } |
||
228 | |||
229 | $item_title = ''; |
||
230 | if ( isset( $this->items[ $section ][ $item_id ] ) ) { |
||
231 | $item_title = $this->items[ $section ][ $item_id ]; |
||
232 | |||
233 | $item_title = apply_filters( 'tabify_items_title', $item_title, $item_id ); |
||
234 | $item_title = apply_filters( 'tabify_items_title_' . $item_id , $item_title ); |
||
235 | } |
||
236 | |||
237 | $this->list_show_items( $item_id, $item_title, $tab_id, $section, $default_items ); |
||
238 | |||
239 | unset( $this->items[ $section ][ $item_id ] ); |
||
240 | } |
||
241 | } |
||
242 | |||
243 | if ( count( $options[ $section ]['tabs'] ) == ( $tab_id + 1 ) ) { |
||
244 | foreach ( $this->items[ $section ] as $item_id => $item_title ) { |
||
245 | if ( empty( $item_id ) ) { |
||
246 | continue; |
||
247 | } |
||
248 | |||
249 | $item_title = apply_filters( 'tabify_items_title', $item_title, $item_id ); |
||
250 | $item_title = apply_filters( 'tabify_items_title_' . $item_id , $item_title ); |
||
251 | |||
252 | $this->list_show_items( $item_id, $item_title, $tab_id, $section, $default_items ); |
||
253 | } |
||
254 | } |
||
255 | |||
256 | echo '</ul>'; |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * Show the items for the sortable list |
||
261 | * |
||
262 | * @param integer $item_id The id of the item in the list |
||
263 | * @param string $item_title The title of the item |
||
264 | * @param integer $tab_id The id of the tab the list is in |
||
265 | * @param string $section The section name |
||
266 | * @param array $default_items List of items that are always shown |
||
267 | * |
||
268 | * @since 0.4.0 |
||
269 | */ |
||
270 | protected function list_show_items( $item_id, $item_title, $tab_id, $section, $default_items ) { |
||
315 | } |
||
316 | |||
317 | |||
318 | /** |
||
319 | * New tabify tab template |
||
320 | * |
||
321 | * @since 0.4.0 |
||
322 | */ |
||
323 | private function print_backbone_template() { |
||
336 | } |
||
337 | |||
338 | /** |
||
339 | * Get the options of the current type |
||
340 | * |
||
341 | * @since 0.4.0 |
||
342 | */ |
||
343 | protected function get_options( $type = null ) { |
||
353 | } |
||
354 | |||
355 | } |
||
356 |