PluginProbe
Visual Slider / trunk
Visual Slider vtrunk
visual-slider / admin / includes / layer.php

layer.php in Visual Slider trunk, at admin/includes/layer.php

307 lines 10.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly.
4 }
5 if ( !function_exists ( "vs_module_layer" )){
6 function vs_module_layer(){
7
8
9 if(!empty(vs_validate_decode_code(wp_unslash(filter_input(INPUT_POST, 'layer', FILTER_UNSAFE_RAW))))){
10 $layer = vs_new_decode(wp_unslash(filter_input(INPUT_POST, 'layer', FILTER_UNSAFE_RAW)),'ly');
11 }else{
12 $layer = vs_options_decode(urldecode(wp_unslash(filter_input(INPUT_POST, 'layer', FILTER_UNSAFE_RAW))));
13 }
14
15 $layer=!empty($layer)?$layer:'';
16 echo '<div id="vs_module_layer" class="vs_module_layer_warp">';
17 echo '<ul class="vs_module_layer_list">';
18
19 vs_module_layer_list(true,$layer);
20 echo '</ul>';
21
22 echo '</div>';
23
24 }
25 }
26
27 if ( !function_exists ( "vs_module_layer_list" )){
28 add_action('wp_ajax_vs_module_layer_list', 'vs_module_layer_list');
29 function vs_module_layer_list($none_ajax='',$layer=[]){
30
31 if(empty($none_ajax)){
32 if ( ! isset( $_POST['_wpnonce'] ) ||
33 ! wp_verify_nonce(sanitize_text_field(wp_unslash( $_POST['_wpnonce'])), 'vs_slider_nonce' ) )
34 return;
35 $post_id =!empty($_POST['post_id'])? absint(wp_unslash($_POST['post_id'])):absint(get_the_ID()) ;
36 if (!current_user_can('edit_post', $post_id)) return;
37 }
38
39 if(!empty($_POST['layer_template_id'])){
40 $template = get_option( 'vs_layer_template');
41 $layer_template_id =sanitize_key(wp_unslash($_POST['layer_template_id']));
42 $layer_json = urldecode($template[sanitize_key($layer_template_id)]['layer']);
43 $layer= vs_options_array_row($layer_json);
44 }
45 if (!empty($layer)) :
46 foreach($layer as $key => $value):
47 vs_module_layer_item(true,$key,$value);
48 endforeach;
49 endif;
50 if(empty($none_ajax)){
51 die('');
52 }
53
54 }
55
56 }
57
58 if ( !function_exists ( "vs_module_layer_item" )){
59 add_action('wp_ajax_vs_module_layer_item', 'vs_module_layer_item');
60 function vs_module_layer_item($none_ajax='',$key =false,$value=false){
61 if(empty($none_ajax)){
62 if ( ! isset( $_POST['_wpnonce'] ) ||
63 ! wp_verify_nonce(sanitize_text_field(wp_unslash( $_POST['_wpnonce'])), 'vs_slider_nonce' ) )
64 return;
65 $post_id =!empty($_POST['post_id'])? absint(wp_unslash($_POST['post_id'])):absint(get_the_ID()) ;
66 if (!current_user_can('edit_post', $post_id)) return;
67
68 }
69 if(!empty($_POST['layer_template_id']) && empty($none_ajax)){
70 $layer_key = 'r'.wp_rand(0000000001,9999999999);
71 $layer_id = $value['id'];
72
73 }else{
74 $layer_key = !empty($_POST['layer_key']) ? sanitize_key(wp_unslash($_POST['layer_key'])): $key;
75 $layer_id = !empty($_POST['layer_id']) ? sanitize_key(wp_unslash($_POST['layer_id'])): $value['id'];
76 }
77
78
79 echo '<li id="vs_module_layer_'.esc_attr($layer_key).'" class="vs_module_layer_item" data-key="'.esc_attr($layer_key).'" data-id="'.esc_attr($layer_id).'">';
80 vs_module_layer_title($layer_id);
81 vs_module_layer_options($layer_key,$layer_id,$value);
82 echo '</li> ';
83 if(empty($none_ajax)){
84 die('');
85 }
86
87 }
88 }
89 if ( !function_exists ( "vs_module_layer_title" )){
90 function vs_module_layer_title($layer_id) {
91
92
93 echo '<div class="vs_module_layer_title">';
94
95 echo '<div class="vs_module_layer_name">';
96 global $vs_layer_options_element;
97 if(!empty($vs_layer_options_element)):
98 foreach ($vs_layer_options_element as $options):
99 if($options['id'] == $layer_id){
100 if(!empty($options['name'])) echo esc_html($options['name']);
101 }
102 endforeach;
103 endif;
104 echo '<span></span>';
105 echo '</div>';
106 echo '<div class="vs_module_layer_top">';
107 echo '<a class="vs_module_layer_remove"></a>';
108 echo '<a class="vs_module_layer_template_save vs_module_template_save" data-id="layer" ></a>';
109 echo '<a class="vs_module_layer_duplicate"></a>';
110 echo '<a class="vs_module_layer_options"></a>';
111 echo '</div>';
112 echo '</div>';
113
114 }
115 }
116 /*****************************************************************************************************************************************************
117 ******************************************************************************************************************************************************
118
119 vs_slider_layer_options_value
120
121 */////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
122
123
124 if ( !function_exists ( "vs_module_layer_tabs" )){
125 function vs_module_layer_tabs($layer_id){
126 global $vs_layer_options_element;
127 $tab= array();
128 foreach ($vs_layer_options_element as $layer_options) :
129 if( $layer_options['id'] == $layer_id) {
130 if($layer_options['options']):
131
132 foreach ($layer_options['options'] as $option ) :
133 if(!empty($option['group'])){
134 $dass = sanitize_title($option['group']);
135 if(!array_key_exists($dass,$tab)){
136 $tab[sanitize_title($option['group'])] = $option['group'];
137 }
138 }else{
139 $general = esc_html__('General','visual-slider');
140 $tab[sanitize_title($general)] = $general;
141 }
142
143 endforeach;
144 endif;
145
146
147 }
148
149 endforeach;
150 return $tab;
151
152 }
153 }
154 if ( !function_exists ( "vs_module_layer_options" )){
155 function vs_module_layer_options($layer_key=false,$layer_id =false,$layer_value =false){
156 global $post;
157 //Section
158
159 global $vs_layer_options_element;
160
161 echo '<form id="vs_layer_options" class="vs_options vs_layer_options vs_side_options vs_active ">';
162 //Title
163 echo '<div class="vs_module_side_options_title"><span>'.esc_html__('Layer Options','visual-slider').'</span><i class="vs_module_side_options_close"></i>';
164 echo '</div>';
165 echo '<div class="vs_side_options_content">';
166
167 foreach ($vs_layer_options_element as $layer_options):
168 if( $layer_options['id']== $layer_id ) {
169
170 echo'<div class="vs_title_tabs">';
171 $array_tab = vs_module_layer_tabs($layer_id);
172 $count_tab=0;
173
174 foreach ($array_tab as $key=> $tabs) :
175 $count_tab++;
176 if($count_tab==1){
177 $tab_active = 'vs_layout_active';
178 }else{
179 $tab_active = '';
180 }
181 echo'<a class="vs_tab_'.esc_attr($key).' '.esc_attr($tab_active).'" data-id="'.esc_attr($key).'">'.esc_html($tabs).'</a>';
182 endforeach;
183
184 echo'</div>';
185 }
186 endforeach;
187
188 //Content
189
190 echo '<ul class="vs_options_content">';
191
192
193 foreach ($vs_layer_options_element as $layer_options):
194
195 if( $layer_options['id']== $layer_id ) {
196 $array_tab = vs_module_layer_tabs($layer_id);
197 $count_container=0;
198 foreach ($array_tab as $key=> $tabs):
199 $count_container++;
200 if($count_container==1){
201 $group_active = 'vs_layout_group_active';
202 }else{
203 $group_active = '';
204 }
205
206 echo '<section class="vs_options_warp '.esc_attr($group_active).' " data-tab="'.esc_attr($key).'">';
207
208 if(!empty($layer_options['options'])):
209 foreach ($layer_options['options'] as $option ) :
210
211 $general = !empty($option['group']) ? sanitize_title($option['group']):sanitize_title(esc_html__('General','visual-slider'));
212
213 if($key == $general ){
214 if(!empty($option['name']) && !empty($option['id']) && !empty($option['type'])){
215 $data_options = !empty( $option['options'] ) ? $option['options'] : null;
216 $desc = !empty( $option['desc'] ) ? $option['desc'] : null;
217 $placeholder = !empty( $option['placeholder'] ) ? $option['placeholder'] : null;
218 $fold = !empty( $option['fold'] ) ? $option['fold'] : null;
219 $unit = !empty( $option['unit'] ) ? $option['unit'] : null;
220 $min = !empty( $option['min'] ) ? $option['min'] : null;
221 $max = !empty( $option['max'] ) ? $option['max'] : null;
222 $step = !empty( $option['step'] ) ? $option['step'] : null;
223 $width = !empty( $option['width'] ) ? $option['width'] : null;
224 $responsive = !empty( $option['responsive'] ) ? $option['responsive'] : null;
225 $default = wp_unslash(filter_input(INPUT_POST, 'default', FILTER_VALIDATE_BOOLEAN) );
226
227 if(!empty($default)){
228 $value = !empty( $option['default'] ) ? $option['default'] : null;
229 }else{
230 $value = isset($layer_value['option'][$option['id']])?$layer_value['option'][$option['id']]:'';
231 }
232 $warp_width = !empty( $option['warp_width'] ) ? $option['warp_width'] : null;
233 vs_options_function( $value, $option['name'],$option['id'],$option['type'],$data_options,$desc,$placeholder,$fold ,'layer_'.$option['id'],$unit ,'',$min,$max,$step,$width,$responsive,$warp_width);
234 }
235 }
236
237 endforeach;
238 endif;
239 echo '</section>';
240
241 endforeach;
242 }
243 endforeach;
244
245
246 echo '</ul>';
247 echo '</div>';
248
249 echo '</form>';
250
251
252
253 }
254
255
256 }
257
258
259
260 /*****************************************************************************************************************************************************
261 ******************************************************************************************************************************************************
262
263 vs_slider_layer_options_value
264
265 */////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
266 if ( !function_exists ( "vs_add_layer" )){
267 function vs_add_layer() {
268
269 $layer=array();
270
271 global $vs_layer_options_element;
272
273 $count=0;
274
275 echo '<div class="vs_add_layer">';
276 echo '<div class="vs_add_layer_middle">';
277 // Title
278 echo '<div class="vs_add_layer_title"><h3>'.esc_html__('Add New Layer','visual-slider').'</h3>';
279
280 echo '<div class="vs_add_layer_cancel">'.esc_html__('Cancel','visual-slider').'</div>';
281 echo '<div class="vs_add_layer_add">'.esc_html__('Add Layer','visual-slider').'</div>';
282
283 echo '</div>';
284 //Content
285 echo '<div class="vs_add_layer_content">';
286 foreach ($vs_layer_options_element as $value):
287
288
289 echo '<div class="vs_add_layer_item" data-layer="'.esc_attr($value['id']).'" >';
290 echo '<'.esc_attr('img').' src="'.esc_url($value['img']).'" />';
291
292 if(!empty($value['name'])){
293 echo '<span>'.esc_html($value['name']).'</span>';
294 }
295 echo '</div>';
296
297 endforeach;
298
299 echo '</div>';
300 //Bottom
301
302 echo '</div>';
303 echo '</div>';
304
305 }
306
307 }