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

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

198 lines 7.4 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 /*****************************************************************************************************************************************************
6 ******************************************************************************************************************************************************
7
8 Slider Metabox
9
10 */////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
11 if ( !function_exists ( "vs_add_metabox" )){
12
13 add_action('add_meta_boxes', 'vs_add_metabox');
14 function vs_add_metabox($post_type) {
15 $types = array('visualslider');
16
17 if (in_array($post_type, $types)) {
18 add_meta_box(
19 'vs_metabox',
20 esc_html__('Slider','visual-slider'),
21 'vs_metabox',
22 'visualslider',
23 'normal',
24 'high'
25 );
26 }
27 }
28 }
29 /*****************************************************************************************************************************************************
30 ******************************************************************************************************************************************************
31
32 Meta Panel
33
34 */////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
35 if ( !function_exists ( "vs_metabox" )){
36 function vs_metabox($post) {
37 global $post;
38
39 wp_nonce_field( 'vs_metabox_nonce', 'vs_metabox_nonce' );
40
41
42
43 echo '<div class="vs_metabox">';
44
45 vs_module_heading();
46
47
48 echo '<div class="vs_module_content">';
49 vs_module_content(true);
50 echo '</div>';
51
52 vs_add_layer();
53 vs_perview_global_warp();
54 echo '</div>';
55
56
57 }
58 }
59 /*****************************************************************************************************************************************************
60 ******************************************************************************************************************************************************
61
62 Slider Meta Save
63
64 */////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
65 if ( !function_exists ( "vs_module_heading" )){
66
67 function vs_module_heading() {
68 global $post;
69
70 ?>
71 <div class="vs_module_heading">
72 <div class="vs_module_shortcode">
73
74
75 <div class="vs_options_name">
76 <label for="vs_shortcode"><?php echo esc_html__('Shortcode','visual-slider');?></label>
77 </div>
78
79 <div class="vs_options_setting">
80 <textarea id="vs_shortcode" name="vs_shortcode" readonly ><?php echo esc_html('[visualslider id="'.intval($post->ID).'"]');?></textarea>
81 </div>
82 </div>
83 <div class="vs_module_global_template">
84 <a class="vs_module_global_template_save vs_module_button vs_module_template_save" data-id="global" ><?php echo esc_html__('Save Full Template in Library','visual-slider');?></a>
85 <a class="vs_module_global_template_add vs_module_button"><?php echo esc_html__('Add Full Template From Library','visual-slider');?></a>
86
87 <a class="vs_module_global_template_demo vs_module_button" ><?php echo esc_html__('Add Ready-Made Full Template','visual-slider');?></a>
88 <a class="vs_module_global_template_import vs_module_button" ><?php echo esc_html__('Import','visual-slider');?></a>
89 <a class="vs_module_global_template_export vs_module_button" ><?php echo esc_html__('Export','visual-slider');?></a>
90
91 </div>
92
93
94
95 </div>
96 <?php
97 }
98
99 }
100 if ( !function_exists ( "vs_module_content" )){
101
102 add_action('wp_ajax_vs_module_content', 'vs_module_content');
103 function vs_module_content($none_ajax='') {
104 if(empty($none_ajax)){
105 if ( ! isset( $_POST['_wpnonce'] ) ||
106 ! wp_verify_nonce(sanitize_text_field(wp_unslash( $_POST['_wpnonce'])), 'vs_slider_nonce' ) )
107 return;
108 $post_id =!empty($_POST['post_id'])? absint(wp_unslash($_POST['post_id'])):absint(get_the_ID()) ;
109 if (!current_user_can('edit_post', $post_id)) return;
110 }
111
112
113
114 global $post;
115 $global_demo_template_id =!empty($_POST['global_demo_template_id']) && empty($none_ajax) ? sanitize_key(wp_unslash($_POST['global_demo_template_id'])):'';
116
117 if(!empty($_POST['global_demo_template_id']) && empty($none_ajax)){
118 $settings_json = vs_module_file_json($global_demo_template_id,'setting');
119 $slide_json = vs_module_file_json($global_demo_template_id,'slide');
120
121 }elseif(!empty($_POST['template_import']) && empty($none_ajax)){
122
123
124 $template_import = json_decode(wp_kses(wp_unslash(filter_input(INPUT_POST, 'template_import', FILTER_UNSAFE_RAW)),vs_kses()),true);
125 $settings_json = !empty($template_import['setting'])?vs_urldecode($template_import['setting']):'';
126 $slide_json = !empty($template_import['slide'])? vs_urldecode($template_import['slide']):'';
127
128 }else if(!empty($_POST['global_template_id']) && empty($none_ajax)){
129
130 $template = get_option( 'vs_global_template');
131 $global_template_id =!empty($_POST['global_template_id']) && empty($none_ajax)? sanitize_key(wp_unslash($_POST['global_template_id'])):'';
132
133 $settings_json = urldecode($template[$global_template_id]['setting']);
134 $slide_json = urldecode($template[$global_template_id]['slide']);
135 }else{
136 $settings_json = get_post_meta(absint(get_the_ID()), 'vs_setting_json', true);
137 $slide_json = get_post_meta(absint(get_the_ID()), 'vs_slide', true);
138 }
139
140
141 $settings= vs_options_array_row($settings_json,'st');
142 $slide= vs_options_array_row($slide_json,'sl');
143
144 $settings_json_textarea = !empty( $settings_json ) ? $settings_json : '';
145 echo '<textarea type="hidden" name="vs_setting_json" id="vs_setting_json">'.wp_kses($settings_json_textarea,vs_kses()).'</textarea>';
146 $slide_json_textarea = !empty( $slide_json ) ? $slide_json : '';
147 echo '<textarea type="hidden" name="vs_slide" id="vs_slide">'.wp_kses($slide_json_textarea,vs_kses()).'</textarea>';
148
149 vs_module_setting($settings);
150
151 vs_module_slide($slide);
152
153
154
155
156
157 if(empty($none_ajax)){
158 die();
159 }
160 }
161 }
162
163 if ( !function_exists ( "vs_module_file_json" )){
164 function vs_module_file_json($id,$type) {
165 return file_get_contents(VISUALSLIDER_DIR .'import/'.$id.'/'.$id.'_'.$type.'.json');
166 }
167
168 }
169 if ( !function_exists ( "vs_metabox_save" )){
170 add_action('save_post', 'vs_metabox_save');
171 function vs_metabox_save($post_id) {
172 if ( ! isset( $_POST['vs_metabox_nonce'] ) ||
173 ! wp_verify_nonce( sanitize_text_field(wp_unslash($_POST['vs_metabox_nonce'])), 'vs_metabox_nonce' ) )
174 return;
175
176 if (!current_user_can('edit_post', $post_id)) return;
177
178 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
179
180 if(!empty($_POST['vs_setting_json'])) {
181 $vs_setting = wp_unslash(filter_input(INPUT_POST, 'vs_setting_json', FILTER_UNSAFE_RAW));
182 update_post_meta($post_id, 'vs_setting_json', $vs_setting);
183 } else {
184 delete_post_meta($post_id, 'vs_setting_json');
185 }
186
187 if(!empty($_POST['vs_slide'])) {
188 $vs_slide = wp_unslash(filter_input(INPUT_POST, 'vs_slide', FILTER_UNSAFE_RAW));
189 update_post_meta($post_id, 'vs_slide', $vs_slide);
190 } else {
191 delete_post_meta($post_id, 'vs_slide');
192 }
193
194
195
196
197 }
198 }