PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.5
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.5
4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 4.1.7.3.2 4.2.0 All 139 releases
learnpress / inc / TemplateHooks / Admin / AdminTemplate.php

AdminTemplate.php in LearnPress – WordPress LMS Plugin for Create and Sell Online Courses 4.4.5, at inc/TemplateHooks/Admin/AdminTemplate.php

323 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace LearnPress\TemplateHooks\Admin;
3
4 use LearnPress\Helpers\Template;
5 use LP_Request;
6
7 /**
8 * Template Show list items to select in popup.
9 *
10 * @since 4.2.9
11 * @version 1.0.1
12 */
13 class AdminTemplate {
14 /**
15 * HTML TinyMCE editor
16 *
17 * @param string $value
18 * @param string $id_name
19 * @param array $setting
20 *
21 * @return string
22 * @since 4.2.9
23 * @version 1.0.0
24 */
25 public static function editor_tinymce( string $value, string $id_name, array $setting = [] ): string {
26 $args = array_merge(
27 [
28 'default_editor' => 'tinymce',
29 'media_buttons' => true,
30 'editor_class' => 'lp-editor-tinymce',
31 'editor_height' => 210,
32 ],
33 $setting
34 );
35
36 ob_start();
37 wp_editor(
38 $value,
39 $id_name,
40 $args
41 );
42
43 return ob_get_clean();
44 }
45
46 /**
47 * HTML for popup items to select.
48 *
49 * @param array $tabs [ [ key => label ] ].
50 * @param string $html_items
51 *
52 * @return string
53 */
54 public static function html_popup_items_to_select_clone( array $tabs, string $html_items ): string {
55 $html_tabs = '';
56 $i = 0;
57 foreach ( $tabs as $key => $label ) {
58 $tab_active = '';
59 if ( $i === 0 ) {
60 $tab_active = 'active';
61 ++$i;
62 }
63
64 $html_tabs .= sprintf(
65 '<li data-type="%s" class="tab %s"><a href="#">%s</a></li>',
66 $key,
67 $tab_active,
68 $label
69 );
70 }
71
72 $section_header = [
73 'wrap' => '<div class="header">',
74 'count' => '<div class="header-count-items-selected lp-hidden"></div>',
75 'tabs' => sprintf(
76 '<ul class="tabs">%s</ul>',
77 $html_tabs
78 ),
79 'wrap_end' => '</div>',
80 ];
81
82 $section_main = [
83 'wrap' => '<div class="main">',
84 'wrap_items' => '<div class="list-items-wrap">',
85 'search' => sprintf(
86 '<input class="%1$s" name="%1$s" type="text" placeholder="%2$s">',
87 'lp-search-title-item',
88 __( 'Type here to search for an item', 'learnpress' )
89 ),
90 'list-items' => $html_items,
91 'wrap_items_end' => '</div>',
92 'list-items-selected' => '
93 <ul class="list-items-selected lp-hidden">
94 <li class="li-item-selected clone lp-hidden" data-id="" data-type="">
95 <i class="dashicons dashicons-remove"></i>
96 <div class="title-display"></div>
97 </li>
98 </ul>',
99 'wrap_end' => '</div>',
100 ];
101
102 $section_footer = [
103 'wrap' => '<div class="footer">',
104 'btn-add' => sprintf(
105 '<button type="button" disabled="disabled" class="button lp-btn-add-items-selected lp-btn-edit-primary">%s</button>',
106 __( 'Add', 'learnpress' )
107 ),
108 'count-items-selected' => sprintf(
109 '<button type="button" disabled="disabled" class="button lp-btn-count-items-selected">%s %s</button>',
110 sprintf( __( 'Selected items', 'learnpress' ), 0 ),
111 '<span class="count"></span>'
112 ),
113 'btn-back' => sprintf(
114 '<button type="button" class="button lp-btn-back-to-select-items lp-hidden">%s</button>',
115 __( 'Back', 'learnpress' )
116 ),
117 'wrap_end' => '</div>',
118 ];
119
120 $section = [
121 'wrap' => '<div class="lp-popup-items-to-select">',
122 'header' => Template::combine_components( $section_header ),
123 'main' => Template::combine_components( $section_main ),
124 'footer' => Template::combine_components( $section_footer ),
125 'wrap_end' => '</div>',
126 ];
127
128 return Template::combine_components( $section );
129 }
130
131 /**
132 * HTML for tom select.
133 *
134 * @param array $args {
135 * Arguments.
136 *
137 * @type array $options Options for select.
138 * @type string $name Name attribute for select.
139 * @type string $class_name Class name for select.
140 * }
141 *
142 * @return string
143 * @since 4.3.0
144 * @version 1.0.0
145 */
146 public static function html_tom_select( array $args = [] ): string {
147 $html_options = '';
148
149 $options = $args['options'] ?? [];
150 $name = $args['name'] ?? '';
151 $class_name = $args['class_name'] ?? '';
152 $default_value = $args['default_value'] ?? '';
153 $multiple = $args['multiple'] ?? false;
154 $multiple = $multiple ? 'multiple' : '';
155 foreach ( $options as $key => $value ) {
156 if ( is_array( $default_value ) ) {
157 $selected = in_array( $key, $default_value, true ) ? 'selected' : '';
158 } else {
159 $selected = selected( $default_value, $key, false );
160 }
161
162 $html_options .= sprintf( '<option value="%s" %s>%s</option>', esc_attr( $key ), $selected, esc_html( $value ) );
163 }
164
165 $section = [
166 'select' => sprintf(
167 '<select name="%s" class="%s lp-tom-select" %s>',
168 esc_attr( $name ),
169 esc_attr( $class_name ),
170 $multiple
171 ),
172 'options' => $html_options,
173 'select-end' => '</select>',
174 ];
175
176 return Template::combine_components( $section );
177 }
178
179 /**
180 * Render a toggle switch (checkbox + track) for enabling or disabling a setting.
181 *
182 * @param array $data Toggle configuration. Accepts:
183 * - classes: CSS classes for the input.
184 * - name: Input name attribute (default: 'lp_toggle_enable').
185 * - value: Current value (truthy/falsy).
186 *
187 * @return string HTML markup for the toggle switch.
188 * @since 4.4.5
189 * @version 1.0.0
190 */
191 public static function html_toggle_enable( array $data = [] ): string {
192 $classes = $data['classes'] ?? '';
193 $name = $data['name'] ?? 'lp_toggle_enable';
194 $value = $data['value'] ?? 0;
195 $checked = $value ? 'checked' : '';
196
197 $section = [
198 'wrapper' => sprintf(
199 '<label class="lp-toggle-enable %s">',
200 $value ? 'is-enabled' : ''
201 ),
202 'input' => sprintf(
203 '<input type="checkbox" class="lp-toggle-enable__input %s"
204 name="%s"
205 value="%s"
206 data-info="%s"
207 %s/>',
208 esc_attr( $classes ),
209 esc_attr( $name ),
210 esc_attr( $value ),
211 esc_attr( Template::convert_data_to_json( $data ) ),
212 esc_attr( $checked )
213 ),
214 'track' => '<span class="lp-toggle-enable__track"></span>',
215 'wrapper-end' => '</label>',
216 ];
217
218 return Template::combine_components( $section );
219 }
220
221 /**
222 * HTML form filter
223 *
224 * @param array $data
225 * @return string
226 * @since 4.4.5
227 * @version 1.0.0
228 */
229 public static function html_form_filter( array $data = [] ): string {
230 $classes = $data['classes'] ?? '';
231 $id = $data['id'] ?? '';
232 $html_fields = $data['fields'] ?? '';
233 $html_btn_actions = $data['btn_actions'] ?? '';
234
235 $sections = array(
236 'wrap' => sprintf(
237 '<form class="lp-form-filter %s"%s>',
238 esc_attr( $classes ),
239 $id ? sprintf( ' id="%s"', esc_attr( $id ) ) : ''
240 ),
241 'fields' => sprintf(
242 '<div class="lp-form-filter__fields">%s</div>',
243 $html_fields
244 ),
245 'btn-actions' => sprintf(
246 '<div class="lp-form-filter__actions">%s</div>',
247 $html_btn_actions
248 ),
249 'wrap_end' => '</form>',
250 );
251
252 return Template::combine_components( $sections );
253 }
254
255 /**
256 * Display content html by format WP Admin Screen
257 *
258 * @param array $data ['tabs' => [ 'tab' => 'name' ], 'content' => '', 'title' => '', 'id' => ''].
259 * @return string
260 * @since 4.4.5
261 * @version 1.0.0
262 */
263 public static function html_on_wp_admin_screen( array $data = [] ): string {
264 $tabs = $data['tabs'] ?? [];
265 $active_tab = LP_Request::get_param( 'tab' );
266 if ( empty( $active_tab ) || ! isset( $tabs[ $active_tab ] ) ) {
267 $tab_keys = array_keys( $tabs );
268 $active_tab = reset( $tab_keys );
269 }
270 $content = $data['content'] ?? '';
271 $title = $data['title'] ?? '';
272 $id = $data['id'] ?? '';
273
274 $classes = array( 'wrap' );
275 if ( $id ) {
276 $classes[] = $id;
277 }
278
279 $html_tabs = '';
280 if ( $tabs ) {
281 foreach ( $tabs as $tab => $tab_title ) {
282 $active_class = ( $tab == $active_tab ) ? ' nav-tab-active' : '';
283
284 if ( $active_class ) {
285 $html_tabs .= sprintf(
286 '<span class="nav-tab%s">%s</span>',
287 esc_attr( $active_class ),
288 esc_html( $tab_title )
289 );
290 } else {
291 $html_tabs .= sprintf(
292 '<a class="nav-tab" href="?page=%s&tab=%s">%s</a>',
293 esc_attr( $id ),
294 esc_attr( $tab ),
295 esc_html( $tab_title )
296 );
297 }
298 }
299 }
300
301 $sections = array(
302 'wrap' => sprintf(
303 '<div class="%s">',
304 esc_attr( implode( ' ', $classes ) )
305 ),
306 'heading' => $title ? sprintf(
307 '<h1 class="wp-heading-inline">%s</h1>',
308 wp_kses_post( $title )
309 ) : '',
310 'tabs' => $tabs ? sprintf(
311 '<h2 class="nav-tab-wrapper">%s</h2>',
312 $html_tabs
313 ) : '',
314 'wrap-content' => '<div class="lp-admin-tabs">',
315 'content' => $content,
316 'wrap-content-end' => '</div>',
317 'wrap-end' => '</div>',
318 );
319
320 return Template::combine_components( $sections );
321 }
322 }
323