| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly. |
| 4 |
} |
| 5 |
if ( !function_exists ( "vs_template_save" )){ |
| 6 |
add_action('wp_ajax_vs_template_save', 'vs_template_save'); |
| 7 |
function vs_template_save(){ |
| 8 |
if ( ! isset( $_POST['_wpnonce'] ) || |
| 9 |
! wp_verify_nonce(sanitize_text_field(wp_unslash( $_POST['_wpnonce'])), 'vs_slider_nonce' ) ) |
| 10 |
return; |
| 11 |
$post_id =!empty($_POST['post_id'])? absint(wp_unslash($_POST['post_id'])): absint(get_the_ID()); |
| 12 |
if (!current_user_can('edit_post', $post_id) && !current_user_can('manage_options')){ |
| 13 |
return; |
| 14 |
} |
| 15 |
$id = !empty($_POST['id'])?sanitize_key(wp_unslash( $_POST['id'])):''; |
| 16 |
$key = !empty($_POST['key'])?sanitize_key(wp_unslash( $_POST['key'])):''; |
| 17 |
|
| 18 |
echo '<div id="vs_template" class="vs_template vs_template_save_options vs_options vs_template_'.esc_attr($id).'" data-id="'.esc_attr($id).'" data-key="'.esc_attr($key).'">'; |
| 19 |
echo '<div class="vs_template_middle">'; |
| 20 |
//Title |
| 21 |
echo '<div class="vs_template_title"><h3>'; |
| 22 |
if($id=='global'){ |
| 23 |
echo esc_html__('Save Full Template in Library','visual-slider'); |
| 24 |
} |
| 25 |
if($id=='slide'){ |
| 26 |
echo esc_html__('Save Slide in Library','visual-slider'); |
| 27 |
} |
| 28 |
if($id=='layer'){ |
| 29 |
echo esc_html__('Save Layer in Library','visual-slider'); |
| 30 |
} |
| 31 |
echo '</h3>'; |
| 32 |
echo '<div class="vs_template_cancel">'.esc_html__('Cancel','visual-slider').'</div>'; |
| 33 |
echo '<div class="vs_template_save">'.esc_html__('Save in Library','visual-slider').'</div>'; |
| 34 |
echo '</div>'; |
| 35 |
echo '<div class="vs_template_content">'; |
| 36 |
|
| 37 |
echo '<div class="vs_template_massage">'.esc_html__('* The Name is Empty, Please Fill it in','visual-slider').'</div>'; |
| 38 |
|
| 39 |
echo '<div class="vs_options_name">'; |
| 40 |
echo '<label for="#vs_template_name">'.esc_html__('Name to save','visual-slider').'</label>'; |
| 41 |
echo '</div>'; |
| 42 |
|
| 43 |
echo '<div class="vs_options_setting">'; |
| 44 |
echo '<input id="vs_template_name" type="text" class="vs_form_text" name="vs_template_name" value="" >'; |
| 45 |
echo '</div>'; |
| 46 |
|
| 47 |
|
| 48 |
echo '</div>'; |
| 49 |
echo '</div>'; |
| 50 |
echo '</div>'; |
| 51 |
die(''); |
| 52 |
} |
| 53 |
} |
| 54 |
if ( !function_exists ( "vs_template_save_global" )){ |
| 55 |
add_action('wp_ajax_vs_template_save_global', 'vs_template_save_global'); |
| 56 |
function vs_template_save_global() { |
| 57 |
|
| 58 |
if ( ! isset( $_POST['_wpnonce'] ) || |
| 59 |
! wp_verify_nonce(sanitize_text_field(wp_unslash( $_POST['_wpnonce'])), 'vs_slider_nonce' ) ) |
| 60 |
return; |
| 61 |
$post_id =!empty($_POST['post_id'])? absint(wp_unslash($_POST['post_id'])): absint(get_the_ID()); |
| 62 |
if (!current_user_can('edit_post', $post_id) && !current_user_can('manage_options')){ |
| 63 |
return; |
| 64 |
} |
| 65 |
|
| 66 |
$old_data = get_option( 'vs_global_template'); |
| 67 |
if( !is_array($old_data)){ |
| 68 |
$old_data=array(); |
| 69 |
} |
| 70 |
$key = 'r'.wp_rand(0,999999999999); |
| 71 |
|
| 72 |
$old_data[sanitize_key($key)]['name'] = !empty($_POST['name'])?sanitize_title(wp_unslash($_POST['name'])):''; |
| 73 |
if(!empty($_POST['setting'])){ |
| 74 |
|
| 75 |
$old_data[sanitize_key($key)]['setting'] = urlencode(wp_unslash(filter_input(INPUT_POST, 'setting', FILTER_UNSAFE_RAW))); |
| 76 |
} |
| 77 |
|
| 78 |
if(!empty($_POST['slide'])){ |
| 79 |
|
| 80 |
|
| 81 |
$old_data[sanitize_key($key)]['slide'] = urlencode(wp_unslash(filter_input(INPUT_POST, 'slide', FILTER_UNSAFE_RAW))); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
update_option( 'vs_global_template', $old_data ); |
| 86 |
die(0); |
| 87 |
|
| 88 |
} |
| 89 |
|
| 90 |
} |
| 91 |
if ( !function_exists ( "vs_template_save_slide" )){ |
| 92 |
add_action('wp_ajax_vs_template_save_slide', 'vs_template_save_slide'); |
| 93 |
function vs_template_save_slide() { |
| 94 |
if ( ! isset( $_POST['_wpnonce'] ) || |
| 95 |
! wp_verify_nonce(sanitize_text_field(wp_unslash( $_POST['_wpnonce'])), 'vs_slider_nonce' ) ) |
| 96 |
return; |
| 97 |
$post_id =!empty($_POST['post_id'])? absint(wp_unslash($_POST['post_id'])): absint(get_the_ID()); |
| 98 |
if (!current_user_can('edit_post', $post_id) && !current_user_can('manage_options')){ |
| 99 |
return; |
| 100 |
} |
| 101 |
|
| 102 |
$old_data = get_option( 'vs_slide_template'); |
| 103 |
if( !is_array($old_data)){ |
| 104 |
$old_data=array(); |
| 105 |
} |
| 106 |
$key = 'r'.wp_rand(0,999999999999); |
| 107 |
$old_data[sanitize_key($key)]['name'] = !empty($_POST['name'])?sanitize_title(wp_unslash($_POST['name'])):''; |
| 108 |
|
| 109 |
if(!empty($_POST['slide'])){ |
| 110 |
$old_data[sanitize_key($key)]['slide'] = urlencode(wp_unslash(filter_input(INPUT_POST, 'slide', FILTER_UNSAFE_RAW))); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
update_option( 'vs_slide_template', $old_data ); |
| 115 |
die(0); |
| 116 |
|
| 117 |
} |
| 118 |
|
| 119 |
} |
| 120 |
if ( !function_exists ( "vs_template_save_layer" )){ |
| 121 |
add_action('wp_ajax_vs_template_save_layer', 'vs_template_save_layer'); |
| 122 |
function vs_template_save_layer() { |
| 123 |
|
| 124 |
|
| 125 |
if ( ! isset( $_POST['_wpnonce'] ) || |
| 126 |
! wp_verify_nonce(sanitize_text_field(wp_unslash( $_POST['_wpnonce'])), 'vs_slider_nonce' ) ) |
| 127 |
return; |
| 128 |
$post_id =!empty($_POST['post_id'])? absint(wp_unslash($_POST['post_id'])): absint(get_the_ID()); |
| 129 |
if (!current_user_can('edit_post', $post_id) && !current_user_can('manage_options')){ |
| 130 |
return; |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
$old_data = get_option( 'vs_layer_template'); |
| 135 |
|
| 136 |
if( !is_array($old_data)){ |
| 137 |
$old_data=array(); |
| 138 |
} |
| 139 |
|
| 140 |
$key = 'r'.wp_rand(0,999999999999); |
| 141 |
$old_data[sanitize_key($key)]['name'] = !empty($_POST['name'])?sanitize_title(wp_unslash($_POST['name'])):''; |
| 142 |
|
| 143 |
if(!empty($_POST['layer'])){ |
| 144 |
$old_data[sanitize_key($key)]['layer'] = urlencode(wp_unslash(filter_input(INPUT_POST, 'layer', FILTER_UNSAFE_RAW))); |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
update_option( 'vs_layer_template', $old_data ); |
| 149 |
die(0); |
| 150 |
|
| 151 |
} |
| 152 |
} |
| 153 |
|
| 154 |
if ( !function_exists ( "vs_template_options" )){ |
| 155 |
add_action('wp_ajax_vs_template_options', 'vs_template_options'); |
| 156 |
function vs_template_options() { |
| 157 |
|
| 158 |
|
| 159 |
if ( ! isset( $_POST['_wpnonce'] ) || |
| 160 |
! wp_verify_nonce(sanitize_text_field(wp_unslash( $_POST['_wpnonce'])), 'vs_slider_nonce' ) ) |
| 161 |
return; |
| 162 |
$post_id =!empty($_POST['post_id'])? absint(wp_unslash($_POST['post_id'])): absint(get_the_ID()); |
| 163 |
if (!current_user_can('edit_post', $post_id) && !current_user_can('manage_options')){ |
| 164 |
return; |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
$id = !empty($_POST['id'])?sanitize_key(wp_unslash( $_POST['id'])):''; |
| 170 |
$old_data = get_option( 'vs_'.$id.'_template'); |
| 171 |
|
| 172 |
echo '<div id="vs_template" class="vs_template vs_template_options vs_template_'.esc_attr($id).'" data-row="'.esc_attr($id).'">'; |
| 173 |
echo '<div class="vs_template_middle">'; |
| 174 |
//Title |
| 175 |
echo '<div class="vs_template_title"><h3>'; |
| 176 |
if($id =='global'){ |
| 177 |
echo esc_html__('Add Full Template From Library','visual-slider'); |
| 178 |
} |
| 179 |
if($id =='slide'){ |
| 180 |
echo esc_html__('Add Slide From Library','visual-slider'); |
| 181 |
} |
| 182 |
if($id =='layer'){ |
| 183 |
echo esc_html__('Add Layer From Library','visual-slider'); |
| 184 |
} |
| 185 |
echo '</h3>'; |
| 186 |
|
| 187 |
echo '<div class="vs_template_cancel">'.esc_html__('Cancel','visual-slider').'</div>'; |
| 188 |
echo '<div class="vs_template_add">'.esc_html__('Add From Library','visual-slider').'</div>'; |
| 189 |
|
| 190 |
echo '</div>'; |
| 191 |
echo '<div class="vs_template_content">'; |
| 192 |
if (!empty($old_data)) : |
| 193 |
foreach($old_data as $key => $value ): |
| 194 |
echo '<li class="vs_template_item" data-id="'.esc_attr($key).'">'; |
| 195 |
echo '<div class="vs_template_name">'.esc_html($value['name']).'</div>'; |
| 196 |
echo '<a class="vs_template_remove"><'.esc_attr('img').' src="'.esc_url(VISUALSLIDER_DIR. 'admin/assets/image/remove.png').'">'.esc_html__('Remove','visual-slider').'</a>'; |
| 197 |
echo '</li>'; |
| 198 |
|
| 199 |
endforeach; |
| 200 |
endif; |
| 201 |
|
| 202 |
echo '</div>'; |
| 203 |
echo '</div>'; |
| 204 |
echo '</div>'; |
| 205 |
|
| 206 |
die(0); |
| 207 |
} |
| 208 |
} |
| 209 |
if ( !function_exists ( "vs_template_remove" )){ |
| 210 |
|
| 211 |
add_action('wp_ajax_vs_template_remove', 'vs_template_remove'); |
| 212 |
function vs_template_remove() { |
| 213 |
if ( ! isset( $_POST['_wpnonce'] ) || |
| 214 |
! wp_verify_nonce(sanitize_text_field(wp_unslash( $_POST['_wpnonce'])), 'vs_slider_nonce' ) ) |
| 215 |
return; |
| 216 |
$post_id =!empty($_POST['post_id'])? absint(wp_unslash($_POST['post_id'])): absint(get_the_ID()); |
| 217 |
if (!current_user_can('edit_post', $post_id) && !current_user_can('manage_options')){ |
| 218 |
return; |
| 219 |
} |
| 220 |
|
| 221 |
$id = !empty($_POST['id'])?sanitize_key(wp_unslash( $_POST['id'])):''; |
| 222 |
$key = !empty($_POST['key'])?sanitize_key(wp_unslash( $_POST['key'])):''; |
| 223 |
$old_data = get_option( 'vs_'.$id.'_template'); |
| 224 |
unset($old_data[sanitize_key($key )]); |
| 225 |
update_option( 'vs_'.$id.'_template', $old_data ); |
| 226 |
die(0); |
| 227 |
|
| 228 |
} |
| 229 |
} |
| 230 |
if ( !function_exists ( "vs_template_demo" )){ |
| 231 |
add_action('wp_ajax_vs_template_demo', 'vs_template_demo'); |
| 232 |
function vs_template_demo() { |
| 233 |
if ( ! isset( $_POST['_wpnonce'] ) || |
| 234 |
! wp_verify_nonce(sanitize_text_field(wp_unslash( $_POST['_wpnonce'])), 'vs_slider_nonce' ) ) |
| 235 |
return; |
| 236 |
$post_id =!empty($_POST['post_id'])? absint(wp_unslash($_POST['post_id'])): absint(get_the_ID()); |
| 237 |
if (!current_user_can('edit_post', $post_id) && !current_user_can('manage_options')){ |
| 238 |
return; |
| 239 |
} |
| 240 |
|
| 241 |
echo '<div id="vs_template" class="vs_template vs_template_options vs_template_demo " data-row="global">'; |
| 242 |
echo '<div class="vs_template_middle">'; |
| 243 |
//Title |
| 244 |
echo '<div class="vs_template_title"><h3>'; |
| 245 |
echo esc_html__('Add Ready-Made Full Template','visual-slider'); |
| 246 |
echo '</h3>'; |
| 247 |
|
| 248 |
echo '<div class="vs_template_cancel">'.esc_html__('Cancel','visual-slider').'</div>'; |
| 249 |
echo '<div class="vs_template_add">'.esc_html__('Add','visual-slider').'</div>'; |
| 250 |
|
| 251 |
echo '</div>'; |
| 252 |
echo '<div class="vs_template_content">'; |
| 253 |
|
| 254 |
|
| 255 |
$old_data = vs_import_options(); |
| 256 |
|
| 257 |
if (!empty($old_data)) : |
| 258 |
foreach($old_data as $key => $value ): |
| 259 |
echo '<li class="vs_template_item" data-id="'.esc_attr($key).'">'; |
| 260 |
echo '<'.esc_attr('img').' src="'.esc_url($value['img']).'">'; |
| 261 |
echo '<a class="vs_template_demo_link" target="_blank" href="'.esc_url($value['demo']).'">'.esc_html__('Perview','visual-slider').'</a>'; |
| 262 |
echo '</li>'; |
| 263 |
|
| 264 |
endforeach; |
| 265 |
endif; |
| 266 |
echo '</div>'; |
| 267 |
echo '</div>'; |
| 268 |
echo '</div>'; |
| 269 |
|
| 270 |
die(0); |
| 271 |
} |
| 272 |
} |
| 273 |
if ( !function_exists ( "vs_template_import" )){ |
| 274 |
add_action('wp_ajax_vs_template_import', 'vs_template_import'); |
| 275 |
function vs_template_import() { |
| 276 |
if ( ! isset( $_POST['_wpnonce'] ) || |
| 277 |
! wp_verify_nonce(sanitize_text_field(wp_unslash( $_POST['_wpnonce'])), 'vs_slider_nonce' ) ) |
| 278 |
return; |
| 279 |
$post_id =!empty($_POST['post_id'])? absint(wp_unslash($_POST['post_id'])): absint(get_the_ID()); |
| 280 |
if (!current_user_can('edit_post', $post_id) && !current_user_can('manage_options')){ |
| 281 |
return; |
| 282 |
} |
| 283 |
|
| 284 |
echo '<div id="vs_template" class="vs_template vs_template_options vs_template_import " data-row="global">'; |
| 285 |
echo '<div class="vs_template_middle">'; |
| 286 |
//Title |
| 287 |
echo '<div class="vs_template_title"><h3>'; |
| 288 |
echo esc_html__('Export Template','visual-slider'); |
| 289 |
echo '</h3>'; |
| 290 |
|
| 291 |
echo '<div class="vs_template_cancel">'.esc_html__('Cancel','visual-slider').'</div>'; |
| 292 |
echo '<div class="vs_template_add">'.esc_html__('Add','visual-slider').'</div>'; |
| 293 |
|
| 294 |
echo '</div>'; |
| 295 |
echo '<div class="vs_template_content">'; |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
echo '<textarea name="vs_template_import"></textarea>'; |
| 301 |
|
| 302 |
echo '</div>'; |
| 303 |
echo '</div>'; |
| 304 |
echo '</div>'; |
| 305 |
|
| 306 |
die(0); |
| 307 |
} |
| 308 |
} |
| 309 |
if ( !function_exists ( "vs_template_export" )){ |
| 310 |
add_action('wp_ajax_vs_template_export', 'vs_template_export'); |
| 311 |
function vs_template_export() { |
| 312 |
|
| 313 |
if ( ! isset( $_POST['_wpnonce'] ) || |
| 314 |
! wp_verify_nonce(sanitize_text_field(wp_unslash( $_POST['_wpnonce'])), 'vs_slider_nonce' ) ) |
| 315 |
return; |
| 316 |
$post_id =!empty($_POST['post_id'])? absint(wp_unslash($_POST['post_id'])): absint(get_the_ID()); |
| 317 |
if (!current_user_can('edit_post', $post_id) && !current_user_can('manage_options')){ |
| 318 |
return; |
| 319 |
} |
| 320 |
|
| 321 |
echo '<div id="vs_template" class="vs_template vs_template_options vs_template_export " data-row="global">'; |
| 322 |
echo '<div class="vs_template_middle">'; |
| 323 |
//Title |
| 324 |
echo '<div class="vs_template_title"><h3>'; |
| 325 |
echo esc_html__('Export Template','visual-slider'); |
| 326 |
echo '</h3>'; |
| 327 |
|
| 328 |
echo '<div class="vs_template_cancel">'.esc_html__('Cancel','visual-slider').'</div>'; |
| 329 |
|
| 330 |
echo '</div>'; |
| 331 |
echo '<div class="vs_template_content">'; |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
if(!empty($_POST['setting'])){ |
| 336 |
$data['setting'] = wp_unslash( filter_input(INPUT_POST, 'setting', FILTER_UNSAFE_RAW)); |
| 337 |
} |
| 338 |
|
| 339 |
if(!empty($_POST['slide'])){ |
| 340 |
$data['slide'] =wp_unslash(filter_input(INPUT_POST, 'slide', FILTER_UNSAFE_RAW)); |
| 341 |
} |
| 342 |
|
| 343 |
echo '<textarea>'.wp_kses(wp_unslash(json_encode($data)),vs_kses()).'</textarea>'; |
| 344 |
|
| 345 |
echo '</div>'; |
| 346 |
echo '</div>'; |
| 347 |
echo '</div>'; |
| 348 |
|
| 349 |
die(0); |
| 350 |
} |
| 351 |
} |