PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.1
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 4.2.1 All 138 releases
learnpress / inc / TemplateHooks / Admin / AdminTemplate.php

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

178 lines 4.6 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
6 /**
7 * Template Show list items to select in popup.
8 *
9 * @since 4.2.9
10 * @version 1.0.1
11 */
12 class AdminTemplate {
13 /**
14 * HTML TinyMCE editor
15 *
16 * @param string $value
17 * @param string $id_name
18 * @param array $setting
19 *
20 * @return string
21 * @since 4.2.9
22 * @version 1.0.0
23 */
24 public static function editor_tinymce( string $value, string $id_name, array $setting = [] ): string {
25 $args = array_merge(
26 [
27 'default_editor' => 'tinymce',
28 'media_buttons' => true,
29 'editor_class' => 'lp-editor-tinymce',
30 'editor_height' => 210,
31 ],
32 $setting
33 );
34
35 ob_start();
36 wp_editor(
37 $value,
38 $id_name,
39 $args
40 );
41
42 return ob_get_clean();
43 }
44
45 /**
46 * HTML for popup items to select.
47 *
48 * @param array $tabs [ [ key => label ] ].
49 * @param string $html_items
50 *
51 * @return string
52 */
53 public static function html_popup_items_to_select_clone( array $tabs, string $html_items ): string {
54 $html_tabs = '';
55 $i = 0;
56 foreach ( $tabs as $key => $label ) {
57 $tab_active = '';
58 if ( $i === 0 ) {
59 $tab_active = 'active';
60 ++$i;
61 }
62
63 $html_tabs .= sprintf(
64 '<li data-type="%s" class="tab %s"><a href="#">%s</a></li>',
65 $key,
66 $tab_active,
67 $label
68 );
69 }
70
71 $section_header = [
72 'wrap' => '<div class="header">',
73 'count' => '<div class="header-count-items-selected lp-hidden"></div>',
74 'tabs' => sprintf(
75 '<ul class="tabs">%s</ul>',
76 $html_tabs
77 ),
78 'wrap_end' => '</div>',
79 ];
80
81 $section_main = [
82 'wrap' => '<div class="main">',
83 'wrap_items' => '<div class="list-items-wrap">',
84 'search' => sprintf(
85 '<input class="%1$s" name="%1$s" type="text" placeholder="%2$s">',
86 'lp-search-title-item',
87 __( 'Type here to search for an item', 'learnpress' )
88 ),
89 'list-items' => $html_items,
90 'wrap_items_end' => '</div>',
91 'list-items-selected' => '
92 <ul class="list-items-selected lp-hidden">
93 <li class="li-item-selected clone lp-hidden" data-id="" data-type="">
94 <i class="dashicons dashicons-remove"></i>
95 <div class="title-display"></div>
96 </li>
97 </ul>',
98 'wrap_end' => '</div>',
99 ];
100
101 $section_footer = [
102 'wrap' => '<div class="footer">',
103 'btn-add' => sprintf(
104 '<button type="button" disabled="disabled" class="button lp-btn-add-items-selected lp-btn-edit-primary">%s</button>',
105 __( 'Add', 'learnpress' )
106 ),
107 'count-items-selected' => sprintf(
108 '<button type="button" disabled="disabled" class="button lp-btn-count-items-selected">%s %s</button>',
109 sprintf( __( 'Selected items', 'learnpress' ), 0 ),
110 '<span class="count"></span>'
111 ),
112 'btn-back' => sprintf(
113 '<button type="button" class="button lp-btn-back-to-select-items lp-hidden">%s</button>',
114 __( 'Back', 'learnpress' )
115 ),
116 'wrap_end' => '</div>',
117 ];
118
119 $section = [
120 'wrap' => '<div class="lp-popup-items-to-select">',
121 'header' => Template::combine_components( $section_header ),
122 'main' => Template::combine_components( $section_main ),
123 'footer' => Template::combine_components( $section_footer ),
124 'wrap_end' => '</div>',
125 ];
126
127 return Template::combine_components( $section );
128 }
129
130 /**
131 * HTML for tom select.
132 *
133 * @param array $args {
134 * Arguments.
135 *
136 * @type array $options Options for select.
137 * @type string $name Name attribute for select.
138 * @type string $class_name Class name for select.
139 * }
140 *
141 * @return string
142 * @since 4.3.0
143 * @version 1.0.0
144 */
145 public static function html_tom_select( array $args = [] ): string {
146 $html_options = '';
147
148 $options = $args['options'] ?? [];
149 $name = $args['name'] ?? '';
150 $class_name = $args['class_name'] ?? '';
151 $default_value = $args['default_value'] ?? '';
152 $multiple = $args['multiple'] ?? false;
153 $multiple = $multiple ? 'multiple' : '';
154 foreach ( $options as $key => $value ) {
155 if ( is_array( $default_value ) ) {
156 $selected = in_array( $key, $default_value, true ) ? 'selected' : '';
157 } else {
158 $selected = selected( $default_value, $key, false );
159 }
160
161 $html_options .= sprintf( '<option value="%s" %s>%s</option>', esc_attr( $key ), $selected, esc_html( $value ) );
162 }
163
164 $section = [
165 'select' => sprintf(
166 '<select name="%s" class="%s lp-tom-select" %s>',
167 esc_attr( $name ),
168 esc_attr( $class_name ),
169 $multiple
170 ),
171 'options' => $html_options,
172 'select-end' => '</select>',
173 ];
174
175 return Template::combine_components( $section );
176 }
177 }
178