| 1 |
<?php |
| 2 |
|
| 3 |
////////////////////////////////////////////////////////////// |
| 4 |
//=========================================================== |
| 5 |
// ajax.php |
| 6 |
//=========================================================== |
| 7 |
// PAGELAYER |
| 8 |
// Inspired by the DESIRE to be the BEST OF ALL |
| 9 |
// ---------------------------------------------------------- |
| 10 |
// Started by: Pulkit Gupta |
| 11 |
// Date: 23rd Jan 2017 |
| 12 |
// Time: 23:00 hrs |
| 13 |
// Site: http://pagelayer.com/wordpress (PAGELAYER) |
| 14 |
// ---------------------------------------------------------- |
| 15 |
// Please Read the Terms of use at http://pagelayer.com/tos |
| 16 |
// ---------------------------------------------------------- |
| 17 |
//=========================================================== |
| 18 |
// (c)Pagelayer Team |
| 19 |
//=========================================================== |
| 20 |
////////////////////////////////////////////////////////////// |
| 21 |
|
| 22 |
// Are we being accessed directly ? |
| 23 |
if(!defined('PAGELAYER_VERSION')) { |
| 24 |
exit('Hacking Attempt !'); |
| 25 |
} |
| 26 |
|
| 27 |
// Recommended Plugins Installation and Activation Action Handlers |
| 28 |
// NOTE: These must be registered BEFORE the pagelayer_nonce gate below, |
| 29 |
// because install/activate requests do NOT send pagelayer_nonce. |
| 30 |
add_action('wp_ajax_pagelayer_install_plugin', 'pagelayer_install_recommended_plugin'); |
| 31 |
function pagelayer_install_recommended_plugin(){ |
| 32 |
check_ajax_referer('pagelayer_recommended_plugins', 'security'); |
| 33 |
|
| 34 |
if(!current_user_can('install_plugins')){ |
| 35 |
wp_send_json_error(array('message' => __('You do not have permission to install plugins.', 'pagelayer'))); |
| 36 |
} |
| 37 |
|
| 38 |
$slug = !empty($_REQUEST['plugin']) ? sanitize_text_field(wp_unslash($_REQUEST['plugin'])) : ''; |
| 39 |
if(empty($slug)){ |
| 40 |
wp_send_json_error(array('message' => __('Plugin slug is required.', 'pagelayer'))); |
| 41 |
} |
| 42 |
|
| 43 |
require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 44 |
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 45 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 46 |
require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 47 |
|
| 48 |
// Initialize WP_Filesystem - required before Plugin_Upgrader can write files |
| 49 |
$creds = request_filesystem_credentials(site_url() . '/wp-admin/', '', false, false, null); |
| 50 |
if(!WP_Filesystem($creds)){ |
| 51 |
wp_send_json_error(array('message' => __('Could not initialize filesystem. Please check file permissions.', 'pagelayer'))); |
| 52 |
} |
| 53 |
|
| 54 |
$api = plugins_api('plugin_information', array('slug' => $slug, 'fields' => array('sections' => false))); |
| 55 |
|
| 56 |
if(is_wp_error($api)){ |
| 57 |
wp_send_json_error(array('message' => $api->get_error_message())); |
| 58 |
} |
| 59 |
|
| 60 |
// Use Automatic_Upgrader_Skin (silent); buffer any stray output to keep response clean JSON |
| 61 |
$skin = new \Automatic_Upgrader_Skin(); |
| 62 |
$upgrader = new \Plugin_Upgrader($skin); |
| 63 |
|
| 64 |
ob_start(); |
| 65 |
$result = $upgrader->install($api->download_link); |
| 66 |
ob_end_clean(); |
| 67 |
|
| 68 |
if(is_wp_error($result)){ |
| 69 |
wp_send_json_error(array('message' => $result->get_error_message())); |
| 70 |
} |
| 71 |
if($result === false || $result === null){ |
| 72 |
$error_msgs = $skin->get_upgrade_messages(); |
| 73 |
$msg = !empty($error_msgs) ? implode(' ', $error_msgs) : __('Plugin installation failed. Please check file permissions.', 'pagelayer'); |
| 74 |
wp_send_json_error(array('message' => $msg)); |
| 75 |
} |
| 76 |
|
| 77 |
$all_plugins = get_plugins(); |
| 78 |
$installed_plugin = ''; |
| 79 |
foreach($all_plugins as $path => $data){ |
| 80 |
if(strpos($path, $slug . '/') === 0){ |
| 81 |
$installed_plugin = $path; |
| 82 |
break; |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
if(empty($installed_plugin)){ |
| 87 |
wp_send_json_error(array('message' => __('Plugin installed but could not be located for activation.', 'pagelayer'))); |
| 88 |
} |
| 89 |
|
| 90 |
$result = activate_plugin($installed_plugin); |
| 91 |
if(is_wp_error($result)){ |
| 92 |
wp_send_json_error(array('message' => $result->get_error_message())); |
| 93 |
} |
| 94 |
|
| 95 |
wp_send_json_success(array('message' => __('Plugin installed and activated successfully.', 'pagelayer'))); |
| 96 |
} |
| 97 |
|
| 98 |
add_action('wp_ajax_pagelayer_activate_plugin', 'pagelayer_activate_recommended_plugin'); |
| 99 |
function pagelayer_activate_recommended_plugin(){ |
| 100 |
check_ajax_referer('pagelayer_recommended_plugins', 'security'); |
| 101 |
|
| 102 |
if(!current_user_can('activate_plugins')){ |
| 103 |
wp_send_json_error(array('message' => __('You do not have permission to activate plugins.', 'pagelayer'))); |
| 104 |
} |
| 105 |
|
| 106 |
$slug = !empty($_REQUEST['plugin']) ? sanitize_text_field(wp_unslash($_REQUEST['plugin'])) : ''; |
| 107 |
if(empty($slug)){ |
| 108 |
wp_send_json_error(array('message' => __('Plugin slug is required.', 'pagelayer'))); |
| 109 |
} |
| 110 |
|
| 111 |
if(!function_exists('get_plugins')){ |
| 112 |
require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 113 |
} |
| 114 |
|
| 115 |
$all_plugins = get_plugins(); |
| 116 |
$plugin_path = ''; |
| 117 |
foreach($all_plugins as $path => $data){ |
| 118 |
if(strpos($path, $slug . '/') === 0){ |
| 119 |
$plugin_path = $path; |
| 120 |
break; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
if(empty($plugin_path)){ |
| 125 |
wp_send_json_error(array('message' => __('Plugin not found.', 'pagelayer'))); |
| 126 |
} |
| 127 |
|
| 128 |
$result = activate_plugin($plugin_path); |
| 129 |
if(is_wp_error($result)){ |
| 130 |
wp_send_json_error(array('message' => $result->get_error_message())); |
| 131 |
} |
| 132 |
|
| 133 |
wp_send_json_success(array('message' => __('Plugin activated successfully.', 'pagelayer'))); |
| 134 |
} |
| 135 |
|
| 136 |
// Is the nonce there ? |
| 137 |
if(empty($_REQUEST['pagelayer_nonce'])){ |
| 138 |
return; |
| 139 |
} |
| 140 |
|
| 141 |
pagelayer_memory_limit(128); |
| 142 |
|
| 143 |
// The ajax handler |
| 144 |
add_action('wp_ajax_pagelayer_wp_widget', 'pagelayer_wp_widget_ajax'); |
| 145 |
function pagelayer_wp_widget_ajax(){ |
| 146 |
|
| 147 |
global $pagelayer; |
| 148 |
|
| 149 |
// Some AJAX security |
| 150 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 151 |
|
| 152 |
if(!current_user_can('edit_theme_options')){ |
| 153 |
$ret['error'][] = __pl('no_permission'); |
| 154 |
pagelayer_json_output($ret); |
| 155 |
} |
| 156 |
|
| 157 |
pagelayer_load_shortcodes(); |
| 158 |
|
| 159 |
header('Content-Type: application/json'); |
| 160 |
|
| 161 |
$ret = []; |
| 162 |
$tag = @$_POST['tag']; |
| 163 |
//pagelayer_print($pagelayer->shortcodes[$tag]); |
| 164 |
|
| 165 |
// No tag ? |
| 166 |
if(empty($pagelayer->shortcodes[$tag])){ |
| 167 |
$ret['error'][] = __pl('no_tag'); |
| 168 |
pagelayer_json_output($ret); |
| 169 |
} |
| 170 |
|
| 171 |
// Include the widgets |
| 172 |
$widgets = ABSPATH . 'site-admin/includes/widgets.php'; |
| 173 |
$widgets = file_exists($widgets) ? $widgets : ABSPATH . 'wp-admin/includes/widgets.php'; |
| 174 |
require_once($widgets); |
| 175 |
|
| 176 |
$class = $pagelayer->shortcodes[$tag]['widget']; |
| 177 |
|
| 178 |
// Check the widget class exists ? |
| 179 |
if(empty($class) || !class_exists($class)){ |
| 180 |
$ret['error'][] = __pl('no_widget_class'); |
| 181 |
pagelayer_json_output($ret); |
| 182 |
} |
| 183 |
|
| 184 |
$instance = []; |
| 185 |
$widget = new $class(); |
| 186 |
$widget->_set('pagelayer-widget-1234567890'); |
| 187 |
|
| 188 |
// Is there any existing data ? |
| 189 |
if(!empty($_POST['widget_data'])){ |
| 190 |
$json = json_decode(stripslashes($_POST['widget_data']), true); |
| 191 |
//pagelayer_print($json);die(); |
| 192 |
if(!empty($json)){ |
| 193 |
$instance = $json; |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
// Are there any form values ? |
| 198 |
if(!empty($_POST['values'])){ |
| 199 |
parse_str(stripslashes($_POST['values']), $data); |
| 200 |
//pagelayer_print($data);die(); |
| 201 |
|
| 202 |
// Any data ? |
| 203 |
if(!empty($data)){ |
| 204 |
|
| 205 |
// Rss widget checkboxes fix |
| 206 |
if(!empty($data['widget-rss'])){ |
| 207 |
$data['widget-rss']['pagelayer-widget-1234567890']['show_summary'] = empty($data['widget-rss']['pagelayer-widget-1234567890']['show_summary'])? 0 : 1; |
| 208 |
$data['widget-rss']['pagelayer-widget-1234567890']['show_author'] = empty($data['widget-rss']['pagelayer-widget-1234567890']['show_author'])? 0 : 1; |
| 209 |
$data['widget-rss']['pagelayer-widget-1234567890']['show_date'] = empty($data['widget-rss']['pagelayer-widget-1234567890']['show_date'])? 0 : 1; |
| 210 |
} |
| 211 |
|
| 212 |
// First key is useless |
| 213 |
$data = current($data); |
| 214 |
|
| 215 |
// Do we still have valid data ? |
| 216 |
if(!empty($data)){ |
| 217 |
|
| 218 |
// 2nd key is useless and just over-ride instance |
| 219 |
$instance = current($data); |
| 220 |
|
| 221 |
} |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
// Settings instance For Text widget |
| 226 |
if($widget->id_base == 'text'){ |
| 227 |
$instance['visual'] = false; |
| 228 |
$instance['legacy'] = false; |
| 229 |
} |
| 230 |
|
| 231 |
// Get the form |
| 232 |
ob_start(); |
| 233 |
$widget->form($instance); |
| 234 |
$ret['form'] = ob_get_contents(); |
| 235 |
ob_end_clean(); |
| 236 |
|
| 237 |
// Get the html |
| 238 |
ob_start(); |
| 239 |
$widget->widget([], $instance); |
| 240 |
$ret['html'] = ob_get_contents(); |
| 241 |
ob_end_clean(); |
| 242 |
|
| 243 |
// Widget data to set |
| 244 |
if(!empty($instance)){ |
| 245 |
$ret['widget_data'] = $instance; |
| 246 |
} |
| 247 |
|
| 248 |
// Custom html widget form elements |
| 249 |
if(!empty($widget) && $widget->name=='Custom HTML'){ |
| 250 |
$custom_html = explode('>', $ret['form']); |
| 251 |
|
| 252 |
$custom_html[0] = '<label for="widget-custom_html-pagelayer-widget-1234567890-title">Title:</label>'.$custom_html[0]; |
| 253 |
$custom_html[0] = str_replace('type="hidden"', 'type="text"',$custom_html[0]); |
| 254 |
|
| 255 |
$custom_html[1] = '<label for="widget-custom_html-pagelayer-widget-1234567890-content">Content:</label>'.$custom_html[1]; |
| 256 |
$custom_html[1] = str_replace('hidden', '', $custom_html[1]); |
| 257 |
|
| 258 |
$ret['form'] = implode('>', $custom_html); |
| 259 |
} |
| 260 |
|
| 261 |
pagelayer_json_output($ret); |
| 262 |
|
| 263 |
} |
| 264 |
|
| 265 |
// Update Post content |
| 266 |
add_action('wp_ajax_pagelayer_save_content', 'pagelayer_save_content'); |
| 267 |
function pagelayer_save_content(){ |
| 268 |
|
| 269 |
// Some AJAX security |
| 270 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 271 |
|
| 272 |
$content = $_POST['pagelayer_update_content']; |
| 273 |
|
| 274 |
$postID = (int) $_GET['postID']; |
| 275 |
|
| 276 |
if(empty($postID)){ |
| 277 |
$msg['error'] = __pl('invalid_post_id'); |
| 278 |
pagelayer_json_output($msg); |
| 279 |
} |
| 280 |
|
| 281 |
$_post = get_post($postID); |
| 282 |
|
| 283 |
// Post found ? |
| 284 |
if(empty($_post)){ |
| 285 |
$msg['error'] = __pl('invalid_post_id'); |
| 286 |
pagelayer_json_output($msg); |
| 287 |
} |
| 288 |
|
| 289 |
// Get the post type and its capabilities |
| 290 |
$post_type = $_post->post_type; |
| 291 |
$post_type_obj = get_post_type_object($post_type); |
| 292 |
|
| 293 |
// Are you allowed to edit ? |
| 294 |
if(!pagelayer_user_can_edit($postID)){ |
| 295 |
$msg['error'][] = __pl('no_permission'); |
| 296 |
pagelayer_json_output($msg); |
| 297 |
} |
| 298 |
|
| 299 |
// Check if the post exists |
| 300 |
if(!empty($postID)){ |
| 301 |
|
| 302 |
$content = base64_decode($content); |
| 303 |
|
| 304 |
/*if(!pagelayer_is_utf8($content)){ |
| 305 |
$content = utf8_encode($content); |
| 306 |
}*/ |
| 307 |
|
| 308 |
$is_xss = pagelayer_xss_content($content); |
| 309 |
|
| 310 |
if(!pagelayer_user_can_add_js_content() && strlen($is_xss) > 0){ |
| 311 |
$msg['error'][] = __pl('xss_found').' - '.$is_xss; |
| 312 |
pagelayer_json_output($msg); |
| 313 |
} |
| 314 |
|
| 315 |
// Is comment mode? |
| 316 |
if(pagelayer_is_comment_mode()){ |
| 317 |
global $pagelayer_comment_errors, $pagelayer_comment_alerts; |
| 318 |
$content = pagelayer_extract_comment_atts($postID, $content); |
| 319 |
} |
| 320 |
|
| 321 |
// Add slash to save data in post |
| 322 |
$content = wp_slash($content); |
| 323 |
|
| 324 |
$post = array( |
| 325 |
'ID' => $postID, |
| 326 |
'post_content' => $content, |
| 327 |
); |
| 328 |
|
| 329 |
// Any properties ? |
| 330 |
$allowed = ['post_title', 'post_name', 'post_excerpt', 'post_status', 'post_password', 'post_date', 'post_parent', 'menu_order']; |
| 331 |
|
| 332 |
foreach($allowed as $k){ |
| 333 |
if(isset($_REQUEST[$k])){ |
| 334 |
$post[$k] = sanitize_text_field($_REQUEST[$k]); |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
// Restrict contributors from setting 'publish' or modifying unauthorized fields |
| 339 |
$current_user_can_publish = current_user_can($post_type_obj->cap->publish_posts); |
| 340 |
if(!$current_user_can_publish){ |
| 341 |
if(!in_array($post['post_status'], ['draft', 'pending'])){ |
| 342 |
$post['post_status'] = 'pending'; // Force pending status |
| 343 |
} |
| 344 |
} |
| 345 |
|
| 346 |
if(!empty($post['post_password'])){ |
| 347 |
if($_REQUEST['post_sticky'] == true){ |
| 348 |
$msg['error'] = __pl('post_pass_with_sticky_err'); |
| 349 |
pagelayer_json_output($msg); |
| 350 |
} |
| 351 |
|
| 352 |
// Prevent unauthorized password protection |
| 353 |
$can_protect = current_user_can($post_type_obj->cap->edit_private_posts); |
| 354 |
if(!$can_protect){ |
| 355 |
$msg['error'][] = __pl('no_permission_to_set_password'); |
| 356 |
pagelayer_json_output($msg); |
| 357 |
} |
| 358 |
} |
| 359 |
|
| 360 |
// Prevent unauthorized modification of `post_author` |
| 361 |
if(isset($_REQUEST['post_author']) && $_REQUEST['post_author'] != $_post->post_author){ |
| 362 |
|
| 363 |
$edit_others_posts = current_user_can($post_type_obj->cap->edit_others_posts); |
| 364 |
|
| 365 |
if($edit_others_posts){ |
| 366 |
$post['post_author'] = (int) $_REQUEST['post_author']; |
| 367 |
}else{ |
| 368 |
$msg['error'][] = __pl('no_permission_to_change_author'); |
| 369 |
pagelayer_json_output($msg); |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
$post['comment_status'] = !empty($_REQUEST['comment_status']) ? 'open' : 'closed'; |
| 374 |
$post['ping_status'] = !empty($_REQUEST['ping_status']) ? 'open' : 'closed'; |
| 375 |
$post['post_status'] = empty($post['post_status']) ? $_post->post_status : $post['post_status']; |
| 376 |
|
| 377 |
if(!empty($post['post_status']) && $post['post_status'] == 'publish'){ |
| 378 |
|
| 379 |
// Allowed to publish pages ? |
| 380 |
if($_post->post_type == 'page' && !current_user_can('publish_pages')){ |
| 381 |
$msg['error'][] = __pl('no_publish_permission'); |
| 382 |
pagelayer_json_output($msg); |
| 383 |
} |
| 384 |
|
| 385 |
// Allowed to publish posts ? |
| 386 |
if($_post->post_type == 'post' && !current_user_can('publish_posts')){ |
| 387 |
$post['post_status'] = 'pending'; |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
if(!empty($post['post_password'])){ |
| 392 |
$post['post_password'] = (in_array($post['post_status'], array('pass_protected', 'publish')) ? $post['post_password'] : ''); |
| 393 |
$post['post_status'] = 'publish'; |
| 394 |
}else{ |
| 395 |
$post['post_status'] = ($post['post_status'] == 'pass_protected') ? 'publish' : $post['post_status']; |
| 396 |
$post['post_password'] = ''; |
| 397 |
} |
| 398 |
|
| 399 |
// Set post GMT time |
| 400 |
if(!empty($post['post_date']) && '0000-00-00 00:00:00' !== $post['post_date']){ |
| 401 |
$post['post_date_gmt'] = get_gmt_from_date( $post['post_date'] ); |
| 402 |
|
| 403 |
if( in_array($post['post_status'], array('future', 'publish')) && $_post->post_date_gmt === '0000-00-00 00:00:00' ){ |
| 404 |
$post['edit_date'] = true; |
| 405 |
} |
| 406 |
} |
| 407 |
|
| 408 |
$_REQUEST['featured_image'] = (int) $_REQUEST['featured_image']; |
| 409 |
if(!empty($_REQUEST['featured_image'])){ |
| 410 |
set_post_thumbnail($postID, $_REQUEST['featured_image']); |
| 411 |
}else{ |
| 412 |
delete_post_thumbnail($postID); |
| 413 |
} |
| 414 |
|
| 415 |
if(!isset($_REQUEST['post_category'])){ |
| 416 |
$_REQUEST['post_category'] = ''; |
| 417 |
} |
| 418 |
|
| 419 |
if(!isset($_REQUEST['post_tags'])){ |
| 420 |
$_REQUEST['post_tags'] = ''; |
| 421 |
} |
| 422 |
|
| 423 |
if($_post->post_type == 'post'){ |
| 424 |
$post['post_category'] = pagelayer_sanitize_text_field($_REQUEST['post_category']); |
| 425 |
|
| 426 |
$post['tags_input'] = pagelayer_sanitize_text_field($_REQUEST['post_tags']); |
| 427 |
}else{ |
| 428 |
$cat_name = pagelayer_post_type_category($_post->post_type); |
| 429 |
if($cat_name){ |
| 430 |
$post['tax_input'][$cat_name] = pagelayer_sanitize_text_field($_REQUEST['post_category']); |
| 431 |
} |
| 432 |
|
| 433 |
$tag_name = pagelayer_post_type_tag($_post->post_type); |
| 434 |
if($tag_name){ |
| 435 |
$post['tax_input'][$tag_name] = pagelayer_sanitize_text_field($_REQUEST['post_tags']); |
| 436 |
} |
| 437 |
} |
| 438 |
|
| 439 |
if(isset($_REQUEST['post_sticky']) && !empty($_REQUEST['post_sticky'])){ |
| 440 |
stick_post( $postID ); |
| 441 |
}else{ |
| 442 |
if(is_sticky($postID)){ |
| 443 |
unstick_post( $postID ); |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
// Any contact templates ? |
| 448 |
if(!empty($_REQUEST['contacts']) && current_user_can('activate_plugins')){ |
| 449 |
update_post_meta($postID, 'pagelayer_contact_templates', $_REQUEST['contacts']); |
| 450 |
}else{ |
| 451 |
delete_post_meta($postID, 'pagelayer_contact_templates'); |
| 452 |
} |
| 453 |
|
| 454 |
// Save copyright |
| 455 |
if(isset($_REQUEST['copyright']) && current_user_can('manage_options')){ |
| 456 |
update_option('pagelayer-copyright', wp_unslash($_REQUEST['copyright'])); |
| 457 |
} |
| 458 |
|
| 459 |
// Apply a filter |
| 460 |
$post = apply_filters('pagelayer_save_content', $post); |
| 461 |
|
| 462 |
// Update the post into the database |
| 463 |
$ret = wp_update_post($post, true); |
| 464 |
|
| 465 |
// Render the post |
| 466 |
//update_post_meta($postID, 'pagelayer_rendered_post', pagelayer_get_post_content($postID)); |
| 467 |
|
| 468 |
if (is_wp_error($ret)) { |
| 469 |
$errors = $ret->get_error_messages(); |
| 470 |
$msg['error'] = __pl('post_update_err').' : '.implode('', $errors); |
| 471 |
}else{ |
| 472 |
|
| 473 |
// Get the updated post |
| 474 |
$_post = get_post($postID); |
| 475 |
|
| 476 |
// Is this a Pagelayer post |
| 477 |
$data = get_post_meta($postID, 'pagelayer-data', true); |
| 478 |
|
| 479 |
if(empty($data)){ |
| 480 |
|
| 481 |
// Convert to pagelayer accessed post |
| 482 |
if(!add_post_meta($postID, 'pagelayer-data', time(), true)){ |
| 483 |
update_post_meta($postID, 'pagelayer-data', time()); |
| 484 |
} |
| 485 |
} |
| 486 |
|
| 487 |
if(!empty($pagelayer_comment_alerts)){ |
| 488 |
$msg['comment_alerts'] = $pagelayer_comment_alerts; |
| 489 |
} |
| 490 |
|
| 491 |
if(!empty($pagelayer_comment_errors)){ |
| 492 |
$msg['error'][] = 'Comment Mode errrors found !'; |
| 493 |
$msg['comment_errors'] = $pagelayer_comment_errors; |
| 494 |
} |
| 495 |
|
| 496 |
$msg['success'] = __pl('post_update_success'); |
| 497 |
} |
| 498 |
|
| 499 |
}else{ |
| 500 |
$msg['error'] = __pl('post_update_err'); |
| 501 |
} |
| 502 |
|
| 503 |
$msg['post_status'] = (empty($_post->post_password)) ? $_post->post_status : 'pass_protected'; |
| 504 |
|
| 505 |
// Save global widgets data |
| 506 |
if(!empty($_REQUEST['global_widgets'])){ |
| 507 |
pagelayer_save_templ_content(true); |
| 508 |
} |
| 509 |
|
| 510 |
// Save nav menu data |
| 511 |
if(!empty($_REQUEST['pagelayer_nav_items']) && current_user_can('edit_theme_options')){ |
| 512 |
$menu_items = (array) $_REQUEST['pagelayer_nav_items']; |
| 513 |
foreach($menu_items as $items){ |
| 514 |
pagelayer_save_nav_menu_items($items); |
| 515 |
} |
| 516 |
} |
| 517 |
|
| 518 |
// Save Customizer data |
| 519 |
if(!empty($_REQUEST['pagelayer_customizer_options']) && current_user_can('edit_theme_options')){ |
| 520 |
|
| 521 |
$customizer_options = wp_unslash($_REQUEST['pagelayer_customizer_options']); |
| 522 |
$customizer_options = json_decode($customizer_options, true); |
| 523 |
|
| 524 |
// Add current post type |
| 525 |
$customizer_options['pagelayer_current_post_type'] = $_post->post_type; |
| 526 |
|
| 527 |
pagelayer_save_customizer_options($customizer_options); |
| 528 |
} |
| 529 |
|
| 530 |
pagelayer_json_output($msg); |
| 531 |
|
| 532 |
} |
| 533 |
|
| 534 |
// Save sections and global sections |
| 535 |
add_action('wp_ajax_pagelayer_save_templ_content', 'pagelayer_save_templ_content'); |
| 536 |
function pagelayer_save_templ_content($echo = false){ |
| 537 |
|
| 538 |
// Some AJAX security |
| 539 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 540 |
|
| 541 |
if ( ! current_user_can( get_post_type_object( 'pagelayer-template' )->cap->create_posts ) ) { |
| 542 |
$ret['error'][$g_post_id] = __pl('no_permission'); |
| 543 |
pagelayer_json_output($ret); |
| 544 |
return false; |
| 545 |
} |
| 546 |
|
| 547 |
// Are you allowed to edit ? |
| 548 |
if(!pagelayer_user_can_edit($_REQUEST['postID'])){ |
| 549 |
$msg['error'][] = __pl('no_permission'); |
| 550 |
pagelayer_json_output($msg); |
| 551 |
} |
| 552 |
|
| 553 |
$ret = array(); |
| 554 |
|
| 555 |
// Save global widgets data |
| 556 |
if(empty($_REQUEST['global_widgets'])){ |
| 557 |
$ret['error'][] = 'No widgets given'; |
| 558 |
pagelayer_json_output($ret); |
| 559 |
return false; |
| 560 |
} |
| 561 |
|
| 562 |
$global_widgets = $_REQUEST['global_widgets']; |
| 563 |
|
| 564 |
foreach($global_widgets as $key => $value){ |
| 565 |
|
| 566 |
$g_post_id = (int) $value['post_id']; |
| 567 |
|
| 568 |
// Are you allowed to edit ? |
| 569 |
if(!empty($g_post_id) && !pagelayer_user_can_edit($g_post_id)){ |
| 570 |
$ret['error'][$g_post_id] = __pl('no_permission').' : '.$g_post_id; |
| 571 |
continue; |
| 572 |
} |
| 573 |
|
| 574 |
// Decode base64 data |
| 575 |
$value['content'] = base64_decode($value['content']); |
| 576 |
|
| 577 |
$is_xss = pagelayer_xss_content($value['content']); |
| 578 |
|
| 579 |
if(!current_user_can('manage_options') && strlen($is_xss) > 0){ |
| 580 |
$ret['error'][$g_post_id] = __pl('xss_found').' - '.$is_xss; |
| 581 |
pagelayer_json_output($ret); |
| 582 |
} |
| 583 |
|
| 584 |
// Add slash to save data in post |
| 585 |
$value['content'] = wp_slash($value['content']); |
| 586 |
|
| 587 |
// We need to create the post |
| 588 |
if(empty($value['post_id'])){ |
| 589 |
|
| 590 |
$g_ret = wp_insert_post([ |
| 591 |
'post_type' => 'pagelayer-template', |
| 592 |
'post_title' => $value['title'], |
| 593 |
'post_content' => $value['content'], |
| 594 |
'post_status' => 'publish', |
| 595 |
'comment_status' => 'closed', |
| 596 |
'ping_status' => 'closed' |
| 597 |
]); |
| 598 |
|
| 599 |
$g_post_id = $g_ret; |
| 600 |
|
| 601 |
// Save our template metas |
| 602 |
update_post_meta($g_post_id, 'pagelayer_template_type', $value['type']); |
| 603 |
update_post_meta($g_post_id, 'pagelayer-data', time()); |
| 604 |
|
| 605 |
}else if(!empty($value['content'])){ |
| 606 |
|
| 607 |
// Save global widget content |
| 608 |
$post = array( |
| 609 |
'ID' => $g_post_id, |
| 610 |
'post_title' => $value['title'], |
| 611 |
'post_content' => $value['content'], |
| 612 |
); |
| 613 |
|
| 614 |
wp_update_post($post); |
| 615 |
} |
| 616 |
|
| 617 |
if(is_wp_error($g_post_id)){ |
| 618 |
$ret['error'][$g_post_id] = __pl('template_update_err'); |
| 619 |
}else{ |
| 620 |
$ret['success'][$g_post_id] = __pl('template_update_success'); |
| 621 |
} |
| 622 |
} |
| 623 |
|
| 624 |
if(!$echo){ |
| 625 |
pagelayer_json_output($ret); |
| 626 |
}else{ |
| 627 |
return $ret; |
| 628 |
} |
| 629 |
} |
| 630 |
|
| 631 |
// Update the Site Title |
| 632 |
add_action('wp_ajax_pagelayer_set_jscss_giver', 'pagelayer_set_jscss_giver'); |
| 633 |
function pagelayer_set_jscss_giver(){ |
| 634 |
global $wpdb; |
| 635 |
|
| 636 |
// Some AJAX security |
| 637 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 638 |
|
| 639 |
if( !current_user_can('manage_options') ){ |
| 640 |
$ret['error'] = __pl('no_permission'); |
| 641 |
pagelayer_json_output($ret); |
| 642 |
} |
| 643 |
|
| 644 |
$val = (int) @$_REQUEST['set']; |
| 645 |
|
| 646 |
if(in_array($val, [1, -1])){ |
| 647 |
update_option('pagelayer_enable_giver', $val); |
| 648 |
} |
| 649 |
|
| 650 |
$ret['success'] = 1; |
| 651 |
pagelayer_json_output($ret); |
| 652 |
} |
| 653 |
|
| 654 |
// Shortcodes Widget Handler |
| 655 |
add_action('wp_ajax_pagelayer_do_shortcodes', 'pagelayer_do_shortcodes'); |
| 656 |
function pagelayer_do_shortcodes(){ |
| 657 |
|
| 658 |
// Some AJAX security |
| 659 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 660 |
|
| 661 |
if(!current_user_can('edit_posts')){// TODO : WooCommerce |
| 662 |
$ret['error'][] = __pl('no_permission'); |
| 663 |
pagelayer_json_output($ret); |
| 664 |
} |
| 665 |
|
| 666 |
$data = ''; |
| 667 |
if(isset($_REQUEST['shortcode_data'])){ |
| 668 |
$data = stripslashes($_REQUEST['shortcode_data']); |
| 669 |
} |
| 670 |
|
| 671 |
// Load shortcodes |
| 672 |
pagelayer_load_shortcodes(); |
| 673 |
|
| 674 |
$data = pagelayer_the_content($data); |
| 675 |
|
| 676 |
// Create the HTML object |
| 677 |
$node = pagelayerQuery::parseStr($data); |
| 678 |
$node->query('.pagelayer-ele')->removeClass('pagelayer-ele'); |
| 679 |
echo $node->html(); |
| 680 |
|
| 681 |
wp_die(); |
| 682 |
|
| 683 |
} |
| 684 |
|
| 685 |
// Give the JS |
| 686 |
add_action('wp_ajax_pagelayer_givejs', 'pagelayer_givejs'); |
| 687 |
function pagelayer_givejs(){ |
| 688 |
|
| 689 |
global $pagelayer; |
| 690 |
|
| 691 |
// WordPress adds the Expires header in all AJAX calls. We need to remove it for cache to work |
| 692 |
header_remove("Expires"); |
| 693 |
header_remove("Cache-Control"); |
| 694 |
|
| 695 |
// Load shortcodes |
| 696 |
pagelayer_load_shortcodes(); |
| 697 |
|
| 698 |
// Load font options |
| 699 |
pagelayer_load_font_options(); |
| 700 |
|
| 701 |
// Pagelayer Template Loading Mechanism |
| 702 |
include_once(PAGELAYER_DIR.'/js/givejs.php'); |
| 703 |
|
| 704 |
exit(); |
| 705 |
|
| 706 |
} |
| 707 |
|
| 708 |
add_action('wp_ajax_pagelayer_givecss', 'pagelayer_givecss'); |
| 709 |
add_action('wp_ajax_nopriv_pagelayer_givecss', 'pagelayer_givecss'); |
| 710 |
function pagelayer_givecss(){ |
| 711 |
|
| 712 |
global $pagelayer; |
| 713 |
|
| 714 |
// WordPress adds the Expires header in all AJAX calls. We need to remove it for cache to work |
| 715 |
header_remove("Expires"); |
| 716 |
header_remove("Cache-Control"); |
| 717 |
|
| 718 |
// Pagelayer Template Loading Mechanism |
| 719 |
include_once(PAGELAYER_DIR.'/css/givecss.php'); |
| 720 |
|
| 721 |
exit(); |
| 722 |
|
| 723 |
} |
| 724 |
|
| 725 |
// Shortcodes Widget Handler |
| 726 |
add_action('wp_ajax_pagelayer_get_section_shortcodes', 'pagelayer_get_section_shortcodes'); |
| 727 |
function pagelayer_get_section_shortcodes(){ |
| 728 |
|
| 729 |
global $pagelayer; |
| 730 |
|
| 731 |
// Some AJAX security |
| 732 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 733 |
|
| 734 |
if(!current_user_can('edit_posts')){ |
| 735 |
$ret['error'][] = __pl('no_permission'); |
| 736 |
pagelayer_json_output($ret); |
| 737 |
} |
| 738 |
|
| 739 |
$data = ''; |
| 740 |
if(isset($_REQUEST['pagelayer_section_id'])){ |
| 741 |
|
| 742 |
$get_url = PAGELAYER_API.'/library.php?give_id='.sanitize_text_field($_REQUEST['pagelayer_section_id']).(!empty($pagelayer->license['license']) ? '&license='.$pagelayer->license['license'] : '').'&url='.rawurlencode(site_url()); |
| 743 |
|
| 744 |
// For SitePad users |
| 745 |
if(function_exists('get_softaculous_file')){ |
| 746 |
$get_url = get_softaculous_file($get_url, 1); |
| 747 |
} |
| 748 |
|
| 749 |
$fetch = wp_remote_get($get_url, array('timeout' => 60)); |
| 750 |
|
| 751 |
if ( is_array( $fetch ) && ! is_wp_error( $fetch ) && isset( $fetch['body'] ) ) { |
| 752 |
$data = json_decode( $fetch['body'], true ); // use the content |
| 753 |
}else{ |
| 754 |
$data['error'] = __pl('The response was malformed'); |
| 755 |
pagelayer_json_output($data); |
| 756 |
} |
| 757 |
} |
| 758 |
|
| 759 |
if(isset($_REQUEST['postID'])){ |
| 760 |
$post_id = (int) $_REQUEST['postID']; |
| 761 |
|
| 762 |
if(!empty($post_id)){ |
| 763 |
$post = get_post( $post_id ); |
| 764 |
// Need to make the reviews post global |
| 765 |
if ( !empty( $post ) ) { |
| 766 |
$GLOBALS['post'] = $post; |
| 767 |
|
| 768 |
$GLOBALS['wp_query'] = new WP_Query([ |
| 769 |
'post_type' => $GLOBALS['post']->post_type, |
| 770 |
'post__in' => array($post_id), |
| 771 |
]); |
| 772 |
} |
| 773 |
} |
| 774 |
} |
| 775 |
|
| 776 |
// Upload the images if any in the shortcode |
| 777 |
preg_match_all('/"'.preg_quote('{{pl_lib_images}}', '/').'([^"]*)"/is', $data['code'], $matches); |
| 778 |
|
| 779 |
foreach($matches[0] as $k => $v){ |
| 780 |
$image_url = trim($v, '"\''); |
| 781 |
$urls[$image_url] = $image_url; |
| 782 |
} |
| 783 |
|
| 784 |
foreach($urls as $k => $image_url){ |
| 785 |
|
| 786 |
$file = basename($image_url); |
| 787 |
$id = 0; |
| 788 |
|
| 789 |
// Upload this |
| 790 |
if(!empty($data[$file])){ |
| 791 |
|
| 792 |
$id = pagelayer_upload_media($file, base64_decode($data[$file])); |
| 793 |
|
| 794 |
if(!empty($id)){ |
| 795 |
$data['code'] = str_replace('"'.$image_url.'"', '"'.$id.'"', $data['code']); |
| 796 |
} |
| 797 |
} |
| 798 |
|
| 799 |
} |
| 800 |
|
| 801 |
// Load shortcodes |
| 802 |
pagelayer_load_shortcodes(); |
| 803 |
|
| 804 |
if(!empty($data['code'])){ |
| 805 |
$data['code'] = pagelayer_the_content($data['code'], true); |
| 806 |
} |
| 807 |
|
| 808 |
pagelayer_json_output($data); |
| 809 |
|
| 810 |
} |
| 811 |
|
| 812 |
// Shortcodes Widget Handler |
| 813 |
add_action('wp_ajax_pagelayer_get_section_blocks', 'pagelayer_get_section_blocks'); |
| 814 |
function pagelayer_get_section_blocks(){ |
| 815 |
|
| 816 |
global $pagelayer; |
| 817 |
|
| 818 |
// Some AJAX security |
| 819 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 820 |
|
| 821 |
if(!current_user_can('edit_posts')){ |
| 822 |
$ret['error'][] = __pl('no_permission'); |
| 823 |
pagelayer_json_output($ret); |
| 824 |
} |
| 825 |
|
| 826 |
$data = ''; |
| 827 |
if(isset($_REQUEST['pagelayer_section_id'])){ |
| 828 |
|
| 829 |
$get_url = PAGELAYER_API.'/library.php?give_id='.sanitize_text_field($_REQUEST['pagelayer_section_id']).(!empty($pagelayer->license['license']) ? '&license='.$pagelayer->license['license'] : '').'&url='.rawurlencode(site_url()); |
| 830 |
|
| 831 |
// For SitePad users |
| 832 |
if(function_exists('get_softaculous_file')){ |
| 833 |
$get_url = get_softaculous_file($get_url, 1); |
| 834 |
} |
| 835 |
|
| 836 |
$fetch = wp_remote_get($get_url, array('timeout' => 60)); |
| 837 |
|
| 838 |
if ( is_array( $fetch ) && ! is_wp_error( $fetch ) && isset( $fetch['body'] ) ) { |
| 839 |
$data = json_decode( $fetch['body'], true ); // use the content |
| 840 |
}else{ |
| 841 |
$data['error'] = __pl('The response was malformed'); |
| 842 |
pagelayer_json_output($data); |
| 843 |
} |
| 844 |
} |
| 845 |
|
| 846 |
// Upload the images if any in the shortcode |
| 847 |
preg_match_all('/"'.preg_quote('{{pl_lib_images}}', '/').'([^"]*)"/is', $data['code'], $matches); |
| 848 |
|
| 849 |
foreach($matches[0] as $k => $v){ |
| 850 |
$image_url = trim($v, '"\''); |
| 851 |
$urls[$image_url] = $image_url; |
| 852 |
} |
| 853 |
|
| 854 |
foreach($urls as $k => $image_url){ |
| 855 |
|
| 856 |
$file = basename($image_url); |
| 857 |
$id = 0; |
| 858 |
|
| 859 |
// Upload this |
| 860 |
if(!empty($data[$file])){ |
| 861 |
|
| 862 |
$id = pagelayer_upload_media($file, base64_decode($data[$file])); |
| 863 |
|
| 864 |
if(!empty($id)){ |
| 865 |
$data['code'] = str_replace('"'.$image_url.'"', '"'.$id.'"', $data['code']); |
| 866 |
} |
| 867 |
} |
| 868 |
|
| 869 |
} |
| 870 |
|
| 871 |
if ( false !== strpos( $data['code'], '[pl_' ) ) { |
| 872 |
// Load shortcodes |
| 873 |
pagelayer_load_shortcodes(); |
| 874 |
|
| 875 |
// Load Parse Shortcodes |
| 876 |
include_once(PAGELAYER_DIR.'/main/parse-shortcodes.php'); |
| 877 |
|
| 878 |
$data['code'] = pagelayer_do_shortcode_to_block($data['code']); |
| 879 |
} |
| 880 |
|
| 881 |
$data['code'] = pagelayer_add_tmp_atts($data['code']); |
| 882 |
|
| 883 |
pagelayer_json_output($data); |
| 884 |
|
| 885 |
} |
| 886 |
|
| 887 |
// Get the Site Title |
| 888 |
add_action('wp_ajax_pagelayer_fetch_site_title', 'pagelayer_fetch_site_title'); |
| 889 |
function pagelayer_fetch_site_title(){ |
| 890 |
|
| 891 |
// Some AJAX security |
| 892 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 893 |
|
| 894 |
echo get_bloginfo('name'); |
| 895 |
wp_die(); |
| 896 |
} |
| 897 |
|
| 898 |
// Update the Site Title |
| 899 |
add_action('wp_ajax_pagelayer_update_site_title', 'pagelayer_update_site_title'); |
| 900 |
function pagelayer_update_site_title(){ |
| 901 |
global $wpdb; |
| 902 |
|
| 903 |
// Some AJAX security |
| 904 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 905 |
|
| 906 |
$site_title = $_POST['site_title']; |
| 907 |
|
| 908 |
if(!current_user_can('manage_options')){ |
| 909 |
$ret['error'][] = __pl('no_permission'); |
| 910 |
pagelayer_json_output($ret); |
| 911 |
} |
| 912 |
|
| 913 |
update_option('blogname', $site_title); |
| 914 |
|
| 915 |
wp_die(); |
| 916 |
} |
| 917 |
|
| 918 |
// Show the SideBars |
| 919 |
add_action('wp_ajax_pagelayer_fetch_sidebar', 'pagelayer_fetch_sidebar'); |
| 920 |
function pagelayer_fetch_sidebar(){ |
| 921 |
|
| 922 |
global $wp_registered_sidebars; |
| 923 |
|
| 924 |
// Some AJAX security |
| 925 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 926 |
|
| 927 |
// Create a list |
| 928 |
$pagelayer_wp_widgets = array(); |
| 929 |
|
| 930 |
foreach($wp_registered_sidebars as $v){ |
| 931 |
$pagelayer_wp_widgets[$v['id']] = $v['name']; |
| 932 |
} |
| 933 |
|
| 934 |
$id = @$_REQUEST['sidebar']; |
| 935 |
|
| 936 |
if(function_exists('dynamic_sidebar') && !empty($pagelayer_wp_widgets[$id])) { |
| 937 |
ob_start(); |
| 938 |
dynamic_sidebar($id); |
| 939 |
$result = ob_get_clean(); |
| 940 |
}else{ |
| 941 |
$result = __pl('no_widget_area'); |
| 942 |
} |
| 943 |
|
| 944 |
echo $result; |
| 945 |
wp_die(); |
| 946 |
|
| 947 |
} |
| 948 |
|
| 949 |
// Show the primary menu ! |
| 950 |
add_action('wp_ajax_pagelayer_fetch_primary_menu', 'pagelayer_fetch_primary_menu'); |
| 951 |
function pagelayer_fetch_primary_menu(){ |
| 952 |
|
| 953 |
// Some AJAX security |
| 954 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 955 |
|
| 956 |
if(isset($_POST['nav_list'])){ |
| 957 |
$_POST['nav_list'] = (int) $_POST['nav_list']; |
| 958 |
|
| 959 |
// Load Pagelayer nav menu walker |
| 960 |
include_once(PAGELAYER_DIR.'/main/nav_walker.php'); |
| 961 |
|
| 962 |
$postID = (int) $_REQUEST['postID']; |
| 963 |
|
| 964 |
// To on live mode |
| 965 |
$GLOBALS['post'] = get_post($postID); |
| 966 |
$GLOBALS['wp_query'] = new WP_Query([ |
| 967 |
'post_type' => $GLOBALS['post']->post_type, |
| 968 |
'post__in' => array($postID), |
| 969 |
]); |
| 970 |
|
| 971 |
// Load short |
| 972 |
pagelayer_load_shortcodes(); |
| 973 |
|
| 974 |
wp_nav_menu([ |
| 975 |
'menu' => wp_get_nav_menu_object($_POST['nav_list']), |
| 976 |
'menu_id' => $_POST["nav_list"], |
| 977 |
'menu_class' => 'pagelayer-wp_menu-ul', |
| 978 |
'walker' => new Pagelayer_Walker_Nav_Menu(), |
| 979 |
//'theme_location' => 'primary', |
| 980 |
'echo' => true, |
| 981 |
]); |
| 982 |
} |
| 983 |
|
| 984 |
wp_die(); |
| 985 |
} |
| 986 |
|
| 987 |
// Save post revision |
| 988 |
add_action('wp_ajax_pagelayer_create_post_autosave', 'pagelayer_create_post_autosave'); |
| 989 |
function pagelayer_create_post_autosave(){ |
| 990 |
|
| 991 |
// Some AJAX security |
| 992 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 993 |
|
| 994 |
$ret = array(); |
| 995 |
$postID = (int) $_GET['postID']; |
| 996 |
$content = $_REQUEST['pagelayer_post_content']; |
| 997 |
|
| 998 |
// Decode base64 data |
| 999 |
$content = base64_decode($content); |
| 1000 |
$content = wp_slash($content); |
| 1001 |
|
| 1002 |
// Are you allowed to edit ? |
| 1003 |
if(!pagelayer_user_can_edit($postID)){ |
| 1004 |
$ret['error'][] = __pl('no_permission'); |
| 1005 |
pagelayer_json_output($ret); |
| 1006 |
} |
| 1007 |
|
| 1008 |
if(empty($postID)){ |
| 1009 |
$ret['error'] = __pl('invalid_post_id'); |
| 1010 |
}else{ |
| 1011 |
|
| 1012 |
$post = array( |
| 1013 |
'post_ID' => $postID, |
| 1014 |
'post_content' => $content, |
| 1015 |
); |
| 1016 |
|
| 1017 |
$ret['id'] = wp_create_post_autosave($post); |
| 1018 |
} |
| 1019 |
|
| 1020 |
$ret['url'] = get_preview_post_link($postID); |
| 1021 |
|
| 1022 |
pagelayer_json_output($ret); |
| 1023 |
|
| 1024 |
} |
| 1025 |
|
| 1026 |
// Get post revision |
| 1027 |
add_action('wp_ajax_pagelayer_get_revision', 'pagelayer_get_revision'); |
| 1028 |
function pagelayer_get_revision(){ |
| 1029 |
|
| 1030 |
// Some AJAX security |
| 1031 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1032 |
|
| 1033 |
$ret = array(); |
| 1034 |
$postID = (int) $_GET['postID']; |
| 1035 |
|
| 1036 |
// Are you allowed to edit ? |
| 1037 |
if(!pagelayer_user_can_edit($postID)){ |
| 1038 |
$ret['error'][] = __pl('no_permission'); |
| 1039 |
pagelayer_json_output($ret); |
| 1040 |
} |
| 1041 |
|
| 1042 |
if(empty($postID)){ |
| 1043 |
$ret['error'] = __pl('invalid_post_id'); |
| 1044 |
}else{ |
| 1045 |
$ret = pagelayer_get_post_revision_by_id($postID); |
| 1046 |
} |
| 1047 |
|
| 1048 |
pagelayer_json_output($ret); |
| 1049 |
|
| 1050 |
} |
| 1051 |
|
| 1052 |
// Apply post revision |
| 1053 |
add_action('wp_ajax_pagelayer_apply_revision', 'pagelayer_apply_revision'); |
| 1054 |
function pagelayer_apply_revision(){ |
| 1055 |
|
| 1056 |
// Some AJAX security |
| 1057 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1058 |
|
| 1059 |
$revisionID = (int) $_REQUEST['revisionID']; |
| 1060 |
$parID = wp_get_post_parent_id($revisionID); |
| 1061 |
$ret = array(); |
| 1062 |
|
| 1063 |
if(empty($parID)){ |
| 1064 |
$parID = $revisionID; |
| 1065 |
} |
| 1066 |
|
| 1067 |
// Are you allowed to edit ? |
| 1068 |
if(!pagelayer_user_can_edit($parID)){ |
| 1069 |
$ret['error'][] = __pl('no_permission'); |
| 1070 |
pagelayer_json_output($ret); |
| 1071 |
} |
| 1072 |
|
| 1073 |
if(empty($revisionID)){ |
| 1074 |
$ret['error'] = __pl('invalid_post_id'); |
| 1075 |
}else{ |
| 1076 |
|
| 1077 |
$post = get_post( $revisionID ); |
| 1078 |
|
| 1079 |
if ( empty( $post ) ) { |
| 1080 |
$ret['error'] = __pl('invalid_revision'); |
| 1081 |
pagelayer_json_output($ret); |
| 1082 |
} |
| 1083 |
|
| 1084 |
// Need to make the reviews post global |
| 1085 |
$GLOBALS['post'] = $post; |
| 1086 |
$GLOBALS['wp_query'] = new WP_Query([ |
| 1087 |
'post_type' => $GLOBALS['post']->post_type, |
| 1088 |
'post__in' => array($parID), |
| 1089 |
]); |
| 1090 |
|
| 1091 |
// Need to reload the shortcodes |
| 1092 |
pagelayer_load_shortcodes(); |
| 1093 |
|
| 1094 |
$ret['id'] = $revisionID; |
| 1095 |
$ret['content'] = pagelayer_the_content($post->post_content, true); |
| 1096 |
|
| 1097 |
if(is_wp_error($post)) { |
| 1098 |
$ret['error'] = __pl('rev_load_error'); |
| 1099 |
}else{ |
| 1100 |
$ret['success'] = __pl('rev_load_success'); |
| 1101 |
} |
| 1102 |
|
| 1103 |
wp_reset_postdata(); |
| 1104 |
} |
| 1105 |
|
| 1106 |
pagelayer_json_output($ret); |
| 1107 |
|
| 1108 |
} |
| 1109 |
|
| 1110 |
// Get post revision |
| 1111 |
add_action('wp_ajax_pagelayer_delete_revision', 'pagelayer_delete_revision'); |
| 1112 |
function pagelayer_delete_revision() { |
| 1113 |
|
| 1114 |
// Some AJAX security |
| 1115 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1116 |
|
| 1117 |
$revisionID = (int) $_REQUEST['revisionID']; |
| 1118 |
$parID = wp_get_post_parent_id($revisionID); |
| 1119 |
$ret = array(); |
| 1120 |
|
| 1121 |
// Are you allowed to edit ? |
| 1122 |
if(!pagelayer_user_can_edit($parID)){ |
| 1123 |
$ret['error'][] = __pl('no_permission'); |
| 1124 |
pagelayer_json_output($ret); |
| 1125 |
} |
| 1126 |
|
| 1127 |
if(empty($revisionID)){ |
| 1128 |
$ret['error'] = __pl('invalid_post_id'); |
| 1129 |
}else{ |
| 1130 |
|
| 1131 |
$revision = get_post( $revisionID ); |
| 1132 |
|
| 1133 |
if ( empty( $revision ) ) { |
| 1134 |
$ret['error'] = __pl('invalid_revision'); |
| 1135 |
}else{ |
| 1136 |
|
| 1137 |
if ( ! current_user_can( 'delete_post', $parID ) ) { |
| 1138 |
$ret['error'] = __pl('access_denied'); |
| 1139 |
pagelayer_json_output($ret); |
| 1140 |
} |
| 1141 |
|
| 1142 |
$deleted = wp_delete_post_revision( $revision->ID ); |
| 1143 |
|
| 1144 |
if ( ! $deleted || is_wp_error( $deleted ) ) { |
| 1145 |
$ret['error'] = __pl('delete_rev_error'); |
| 1146 |
}else{ |
| 1147 |
$ret['success'] = __pl('delete_rev_success'); |
| 1148 |
} |
| 1149 |
} |
| 1150 |
} |
| 1151 |
|
| 1152 |
pagelayer_json_output($ret); |
| 1153 |
|
| 1154 |
} |
| 1155 |
|
| 1156 |
// Get post navigation |
| 1157 |
add_action('wp_ajax_pagelayer_post_nav', 'pagelayer_post_nav'); |
| 1158 |
function pagelayer_post_nav() { |
| 1159 |
|
| 1160 |
// Some AJAX security |
| 1161 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1162 |
|
| 1163 |
if(!isset($_REQUEST['data']) || !isset($_REQUEST['postID'])){ |
| 1164 |
return; |
| 1165 |
} |
| 1166 |
|
| 1167 |
$el['atts'] = $_REQUEST['data']; |
| 1168 |
|
| 1169 |
$post = get_post($_REQUEST['postID']); |
| 1170 |
|
| 1171 |
// Need to make this post global |
| 1172 |
$GLOBALS['post'] = $post; |
| 1173 |
|
| 1174 |
$in_same_term = false; |
| 1175 |
$taxonomies = 'category'; |
| 1176 |
$title = ''; |
| 1177 |
$arrows_list = $el['atts']['arrows_list']; |
| 1178 |
|
| 1179 |
if($el['atts']['in_same_term']){ |
| 1180 |
$in_same_term = true; |
| 1181 |
$taxonomies = $el['atts']['taxonomies']; |
| 1182 |
} |
| 1183 |
|
| 1184 |
if($el['atts']['post_title']){ |
| 1185 |
$title = '<span class="pagelayer-post-nav-title">%title</span>'; |
| 1186 |
} |
| 1187 |
|
| 1188 |
$next_label = '<span class="pagelayer-next-holder"> |
| 1189 |
<span class="pagelayer-post-nav-link"> '.$el["atts"]["next_label"].'</span>'.$title.' |
| 1190 |
</span> |
| 1191 |
<span class="pagelayer-post-nav-icon fa fa-'.$arrows_list.'-right"></span>'; |
| 1192 |
|
| 1193 |
$prev_label = '<span class="pagelayer-post-nav-icon fa fa-'.$arrows_list.'-left"></span> |
| 1194 |
<span class="pagelayer-next-holder"> |
| 1195 |
<span class="pagelayer-post-nav-link"> '.$el["atts"]["prev_label"].'</span>'.$title.' |
| 1196 |
</span>'; |
| 1197 |
|
| 1198 |
$el['atts']['next_link'] = get_next_post_link('%link', $next_label, $in_same_term, '', $taxonomies); |
| 1199 |
|
| 1200 |
$el['atts']['prev_link'] = get_previous_post_link('%link', $prev_label, $in_same_term, '', $taxonomies ); |
| 1201 |
|
| 1202 |
pagelayer_json_output($el); |
| 1203 |
|
| 1204 |
} |
| 1205 |
|
| 1206 |
// Get post comment template |
| 1207 |
add_action('wp_ajax_pagelayer_post_comment', 'pagelayer_post_comment'); |
| 1208 |
function pagelayer_post_comment() { |
| 1209 |
global $post; |
| 1210 |
|
| 1211 |
// Some AJAX security |
| 1212 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1213 |
|
| 1214 |
if(!isset($_REQUEST['postID'])){ |
| 1215 |
return true; |
| 1216 |
} |
| 1217 |
|
| 1218 |
$GLOBALS['post'] = get_post($_REQUEST['postID']); |
| 1219 |
$GLOBALS['withcomments'] = true; |
| 1220 |
|
| 1221 |
// Load shortcodes |
| 1222 |
pagelayer_load_shortcodes(); |
| 1223 |
|
| 1224 |
$el = []; |
| 1225 |
pagelayer_sc_post_comment($el); |
| 1226 |
|
| 1227 |
echo $el['atts']['post_comment']; |
| 1228 |
|
| 1229 |
wp_die(); |
| 1230 |
|
| 1231 |
} |
| 1232 |
|
| 1233 |
// Get post comment template |
| 1234 |
add_action('wp_ajax_pagelayer_post_info', 'pagelayer_post_info'); |
| 1235 |
function pagelayer_post_info() { |
| 1236 |
global $post; |
| 1237 |
|
| 1238 |
// Some AJAX security |
| 1239 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1240 |
|
| 1241 |
if(!isset($_REQUEST['postID']) || !isset($_REQUEST['el'])){ |
| 1242 |
return true; |
| 1243 |
} |
| 1244 |
|
| 1245 |
$el['atts'] = $_REQUEST['el']; |
| 1246 |
|
| 1247 |
$GLOBALS['post'] = get_post($_REQUEST['postID']); |
| 1248 |
|
| 1249 |
// Load shortcodes |
| 1250 |
pagelayer_load_shortcodes(); |
| 1251 |
|
| 1252 |
pagelayer_sc_post_info_list($el); |
| 1253 |
|
| 1254 |
pagelayer_json_output($el['atts']); |
| 1255 |
|
| 1256 |
} |
| 1257 |
|
| 1258 |
// Get the Featured Image |
| 1259 |
add_action('wp_ajax_pagelayer_fetch_featured_img', 'pagelayer_fetch_featured_img'); |
| 1260 |
function pagelayer_fetch_featured_img(){ |
| 1261 |
|
| 1262 |
// Some AJAX security |
| 1263 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1264 |
|
| 1265 |
$id = get_post_thumbnail_id( (int) $_POST['post_id'] ); |
| 1266 |
$img = []; |
| 1267 |
|
| 1268 |
if(empty($id)){ |
| 1269 |
pagelayer_json_output($img); |
| 1270 |
} |
| 1271 |
|
| 1272 |
$img = pagelayer_image($id); |
| 1273 |
pagelayer_json_output($img); |
| 1274 |
|
| 1275 |
} |
| 1276 |
|
| 1277 |
// Get the postfolio posts |
| 1278 |
add_action('wp_ajax_pagelayer_fetch_posts', 'pagelayer_fetch_posts'); |
| 1279 |
function pagelayer_fetch_posts(){ |
| 1280 |
|
| 1281 |
// Some AJAX security |
| 1282 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1283 |
|
| 1284 |
// This ajax call is only used during post/page editing |
| 1285 |
if(!current_user_can('edit_posts')){ |
| 1286 |
echo __pl('no_permission'); |
| 1287 |
wp_die(); |
| 1288 |
} |
| 1289 |
|
| 1290 |
$sanitized_post = pagelayer_sanitize_posts_data($_POST); |
| 1291 |
echo pagelayer_widget_posts($sanitized_post); |
| 1292 |
|
| 1293 |
wp_die(); |
| 1294 |
} |
| 1295 |
|
| 1296 |
// Get the Posts |
| 1297 |
add_action('wp_ajax_pagelayer_posts_data', 'pagelayer_posts_data'); |
| 1298 |
function pagelayer_posts_data(){ |
| 1299 |
|
| 1300 |
// Some AJAX security |
| 1301 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1302 |
|
| 1303 |
// This ajax call is only used during post/page editing |
| 1304 |
if(!current_user_can('edit_posts')){ |
| 1305 |
echo __pl('no_permission'); |
| 1306 |
wp_die(); |
| 1307 |
} |
| 1308 |
|
| 1309 |
// Load shortcodes |
| 1310 |
pagelayer_load_shortcodes(); |
| 1311 |
|
| 1312 |
$sanitized_post = pagelayer_sanitize_posts_data($_POST, false); |
| 1313 |
echo pagelayer_posts($sanitized_post); |
| 1314 |
wp_die(); |
| 1315 |
} |
| 1316 |
|
| 1317 |
// Get the Posts |
| 1318 |
add_action('wp_ajax_pagelayer_archive_posts_data', 'pagelayer_archive_posts_data'); |
| 1319 |
function pagelayer_archive_posts_data(){ |
| 1320 |
|
| 1321 |
// Some AJAX security |
| 1322 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1323 |
|
| 1324 |
// Set excerpt length |
| 1325 |
if(!empty($_POST['atts']['exc_length'])){ |
| 1326 |
$exc_length = (int) $_POST['atts']['exc_length']; |
| 1327 |
add_filter( 'excerpt_length', function($length) use($exc_length){ |
| 1328 |
return $exc_length; |
| 1329 |
}, 999 ); |
| 1330 |
} |
| 1331 |
|
| 1332 |
// Load shortcodes |
| 1333 |
pagelayer_load_shortcodes(); |
| 1334 |
|
| 1335 |
foreach($_POST['atts'] as $k => $v){ |
| 1336 |
$v = pagelayer_maybe_implode($v); |
| 1337 |
$r[] = esc_html($k).'="'.pagelayer_escapeHTML($v).'"'; |
| 1338 |
} |
| 1339 |
|
| 1340 |
$string = implode(' ', $r); |
| 1341 |
if(preg_match('/\]/is', $string)){ |
| 1342 |
die('Hacking Attempt'); |
| 1343 |
} |
| 1344 |
|
| 1345 |
$sc = '[pl_archive_posts '.$string.'][/pl_archive_posts]'; |
| 1346 |
|
| 1347 |
echo pagelayer_the_content($sc); |
| 1348 |
wp_die(); |
| 1349 |
} |
| 1350 |
|
| 1351 |
// Handle Contact Form Data |
| 1352 |
add_action('wp_ajax_pagelayer_contact_submit', 'pagelayer_contact_submit'); |
| 1353 |
add_action('wp_ajax_nopriv_pagelayer_contact_submit', 'pagelayer_contact_submit' ); |
| 1354 |
function pagelayer_contact_submit(){ |
| 1355 |
|
| 1356 |
// Some AJAX security |
| 1357 |
check_ajax_referer('pagelayer_global', 'pagelayer_nonce'); |
| 1358 |
|
| 1359 |
// A filter to short circuit this contact form |
| 1360 |
$continue = apply_filters('pagelayer_contact_submit_start', 1); |
| 1361 |
if(empty($continue)){ |
| 1362 |
return false; |
| 1363 |
} |
| 1364 |
|
| 1365 |
$formdata = wp_unslash($_POST); |
| 1366 |
// NOTE : NEVER add anything to $formdata except $_POST vars |
| 1367 |
|
| 1368 |
if(isset($_POST['g-recaptcha-response']) ){ |
| 1369 |
|
| 1370 |
if(!pagelayer_captcha_verify()){ |
| 1371 |
$wp['failed'] = get_option('pagelayer_recaptcha_failed', __pl('cap_ver_fail')); |
| 1372 |
pagelayer_json_output($wp); |
| 1373 |
} |
| 1374 |
|
| 1375 |
unset($formdata['g-recaptcha-response']); |
| 1376 |
} |
| 1377 |
|
| 1378 |
// Unset the nonce |
| 1379 |
unset($formdata['pagelayer_nonce']); |
| 1380 |
|
| 1381 |
$to_mail = get_option('pagelayer_cf_to_email'); |
| 1382 |
$from_mail = get_option('pagelayer_cf_from_email'); |
| 1383 |
$subject = get_option('pagelayer_cf_subject'); |
| 1384 |
$additional_headers = get_option('pagelayer_cf_headers'); |
| 1385 |
$reply_to = ''; |
| 1386 |
$body = ''; |
| 1387 |
$headers = ''; |
| 1388 |
$custom_templ = array(); |
| 1389 |
$use_custom = false; |
| 1390 |
$use_html = false; |
| 1391 |
$pagelayer_id = sanitize_text_field($formdata['cfa-pagelayer-id']); |
| 1392 |
|
| 1393 |
if(isset($formdata['cfa-custom-template']) && !empty($formdata['cfa-post-id'])){ |
| 1394 |
$post_id = (int) $formdata['cfa-post-id']; |
| 1395 |
|
| 1396 |
if(!empty($post_id) && ( get_post_status( $post_id ) === 'publish' || current_user_can('publish_posts') )){ |
| 1397 |
$contact_array = get_post_meta($post_id, 'pagelayer_contact_templates', true); |
| 1398 |
|
| 1399 |
if(!empty($contact_array) && !empty($contact_array[$pagelayer_id])){ |
| 1400 |
$custom_templ = $contact_array[$pagelayer_id]; |
| 1401 |
$use_custom = true; |
| 1402 |
} |
| 1403 |
} |
| 1404 |
} |
| 1405 |
|
| 1406 |
if($use_custom && !empty($custom_templ)){ |
| 1407 |
|
| 1408 |
if(!empty($custom_templ['to_email'])){ |
| 1409 |
$to_mail = $custom_templ['to_email']; |
| 1410 |
} |
| 1411 |
|
| 1412 |
if(!empty($custom_templ['from_email'])){ |
| 1413 |
$from_mail = $custom_templ['from_email']; |
| 1414 |
} |
| 1415 |
|
| 1416 |
if(!empty($custom_templ['cont_subject'])){ |
| 1417 |
$subject = $custom_templ['cont_subject']; |
| 1418 |
} |
| 1419 |
|
| 1420 |
if(!empty($custom_templ['cont_header'])){ |
| 1421 |
$additional_headers = $custom_templ['cont_header']; |
| 1422 |
} |
| 1423 |
|
| 1424 |
if(!empty($custom_templ['cont_body'])){ |
| 1425 |
$body = $custom_templ['cont_body']; |
| 1426 |
} |
| 1427 |
|
| 1428 |
if(!empty($custom_templ['cont_use_html'])){ |
| 1429 |
$use_html = true; |
| 1430 |
$headers .= "Content-Type: text/html\n"; |
| 1431 |
} |
| 1432 |
} |
| 1433 |
|
| 1434 |
if(!empty($from_mail)){ |
| 1435 |
$headers .= "From: $from_mail\n"; |
| 1436 |
} |
| 1437 |
|
| 1438 |
if ( !empty($additional_headers) ) { |
| 1439 |
$headers .= $additional_headers . "\n"; |
| 1440 |
} |
| 1441 |
|
| 1442 |
if ( empty($body) ) { |
| 1443 |
|
| 1444 |
// Make the email content |
| 1445 |
foreach($formdata as $k => $i){ |
| 1446 |
|
| 1447 |
$not_allow = ['cfa-pagelayer-id', 'cfa-redirect', 'cfa-post-id', 'cfa-custom-template', 'pagelayer-contact-submit']; |
| 1448 |
if(in_array($k, $not_allow)){ |
| 1449 |
continue; |
| 1450 |
} |
| 1451 |
|
| 1452 |
$body .= sanitize_text_field($k)."\t : \t $".$k."\n"; |
| 1453 |
|
| 1454 |
} |
| 1455 |
|
| 1456 |
$body .= "\n\n --\n This e-mail was sent from a contact form (".get_home_url().")"; |
| 1457 |
|
| 1458 |
} |
| 1459 |
|
| 1460 |
// Add attachment |
| 1461 |
if(!empty($_FILES)){ |
| 1462 |
add_action('phpmailer_init', 'pagelayer_cf_email_attachment', 10, 1); |
| 1463 |
} |
| 1464 |
|
| 1465 |
$sanitized_data = array(); |
| 1466 |
|
| 1467 |
// If we are using HTML, then we should escape html as well |
| 1468 |
foreach($formdata as $k => $i){ |
| 1469 |
|
| 1470 |
if(is_array($i)){ |
| 1471 |
$i = pagelayer_flat_join($i); |
| 1472 |
} |
| 1473 |
|
| 1474 |
$i = pagelayer_esc_crlf($i); |
| 1475 |
|
| 1476 |
if(!empty($use_html)){ |
| 1477 |
$i = esc_html($i); |
| 1478 |
} |
| 1479 |
|
| 1480 |
// Sanitize text field |
| 1481 |
$i = sanitize_text_field($i); |
| 1482 |
|
| 1483 |
// Record a reply to if it is to be used |
| 1484 |
if(is_email($i) && empty($reply_to)){ |
| 1485 |
$reply_to = $i; |
| 1486 |
} |
| 1487 |
|
| 1488 |
$sanitized_data[$k] = $i; |
| 1489 |
} |
| 1490 |
|
| 1491 |
// Dow we have a reply to in the headers ? |
| 1492 |
if(!preg_match('/reply\-to/is', $headers) && !empty($reply_to)){ |
| 1493 |
$headers .= "Reply-To: $reply_to\n"; |
| 1494 |
} |
| 1495 |
|
| 1496 |
// Add Site Title as option in formdata |
| 1497 |
$sanitized_data['site_title'] = get_bloginfo( 'name' ); |
| 1498 |
|
| 1499 |
// Do parse a variables |
| 1500 |
$to_mail = pagelayer_replace_vars($to_mail, $sanitized_data, '$'); |
| 1501 |
$from_mail = pagelayer_replace_vars($from_mail, $sanitized_data, '$'); |
| 1502 |
$subject = pagelayer_replace_vars($subject, $sanitized_data, '$'); |
| 1503 |
$headers = pagelayer_replace_vars($headers, $sanitized_data, '$'); |
| 1504 |
$body = pagelayer_replace_vars($body, $sanitized_data, '$'); |
| 1505 |
|
| 1506 |
if ( $use_html && ! preg_match( '%<html[>\s].*</html>%is', $body ) ) { |
| 1507 |
$header = '<!doctype html> |
| 1508 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
| 1509 |
<head><title>' . esc_html( $subject ) . '</title></head> |
| 1510 |
<body>'; |
| 1511 |
|
| 1512 |
$footer = '</body></html>'; |
| 1513 |
|
| 1514 |
$body = $header . wpautop( $body ) . $footer; |
| 1515 |
} |
| 1516 |
|
| 1517 |
$to_mail = apply_filters('pagelayer_contact_send', $to_mail, $sanitized_data); |
| 1518 |
|
| 1519 |
// Send the email |
| 1520 |
if(!empty($to_mail)){ |
| 1521 |
$r = wp_mail( $to_mail, $subject, $body, $headers ); |
| 1522 |
} |
| 1523 |
|
| 1524 |
if($r == TRUE){ |
| 1525 |
$wp['success'] = pagelayer_get_option( 'pagelayer_cf_success' ); |
| 1526 |
}else{ |
| 1527 |
$wp['failed'] = pagelayer_get_option( 'pagelayer_cf_failed' ); |
| 1528 |
} |
| 1529 |
|
| 1530 |
pagelayer_json_output($wp); |
| 1531 |
|
| 1532 |
} |
| 1533 |
|
| 1534 |
// Handle Login Submit |
| 1535 |
add_action('wp_ajax_pagelayer_login_submit', 'pagelayer_login_submit'); |
| 1536 |
add_action('wp_ajax_nopriv_pagelayer_login_submit', 'pagelayer_login_submit'); |
| 1537 |
function pagelayer_login_submit(){ |
| 1538 |
|
| 1539 |
// Some AJAX security |
| 1540 |
check_ajax_referer('pagelayer_global', 'pagelayer_nonce'); |
| 1541 |
|
| 1542 |
$creds = array(); |
| 1543 |
$creds['user_login'] = $_REQUEST['username']; |
| 1544 |
$creds['user_password'] = $_REQUEST['password']; |
| 1545 |
$creds['remember'] = $_REQUEST['remember_me']; |
| 1546 |
|
| 1547 |
// Login the user |
| 1548 |
$user = wp_signon( $creds, false ); |
| 1549 |
|
| 1550 |
if ( is_wp_error($user) ){ |
| 1551 |
$data['error'] = $user->get_error_message(); |
| 1552 |
}else{ |
| 1553 |
|
| 1554 |
// If After logout URL, then save |
| 1555 |
if(!empty($_REQUEST['logout_url'])){ |
| 1556 |
update_user_option($user->ID, 'pagelayer_logout_url', sanitize_url($_REQUEST['logout_url'])); |
| 1557 |
} |
| 1558 |
|
| 1559 |
$data['redirect'] = (empty($_REQUEST['login_url']) ? '' : sanitize_url($_REQUEST['login_url'])); |
| 1560 |
$data['error'] = ''; |
| 1561 |
} |
| 1562 |
|
| 1563 |
pagelayer_json_output($data); |
| 1564 |
|
| 1565 |
} |
| 1566 |
|
| 1567 |
// Get Page List for SiteMap |
| 1568 |
add_action('wp_ajax_pagelayer_get_pages_list', 'pagelayer_get_pages_list'); |
| 1569 |
function pagelayer_get_pages_list(){ |
| 1570 |
|
| 1571 |
// Some AJAX security |
| 1572 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1573 |
|
| 1574 |
if(!current_user_can('edit_posts')){ |
| 1575 |
echo __pl('no_permission'); |
| 1576 |
wp_die(); |
| 1577 |
} |
| 1578 |
|
| 1579 |
$args = array( |
| 1580 |
'post_type' => sanitize_text_field($_POST['type']), |
| 1581 |
'orderby' => sanitize_text_field($_POST['post_order']), |
| 1582 |
'order' => sanitize_text_field($_POST['order']), |
| 1583 |
'hierarchical' => (empty($_POST['hier']) || $_POST['hier'] == null ? '' : sanitize_text_field($_POST['hier'])), |
| 1584 |
'number' => (empty($_POST['depth']) || $_POST['depth'] == null ? '' : sanitize_text_field($_POST['depth'])), |
| 1585 |
'posts_per_page' => -1, |
| 1586 |
); |
| 1587 |
|
| 1588 |
$option = '<ul>'; |
| 1589 |
$pages = new WP_Query($args); |
| 1590 |
$posts = $pages->posts; |
| 1591 |
foreach ( $posts as $page ) { |
| 1592 |
$option .= '<li class="pagelayer-sitemap-list-item" data-postID="'.$page->ID.'"><a class="pagelayer-ele-link" href="'.$page->guid.'">'.$page->post_name.'</a></li>'; |
| 1593 |
} |
| 1594 |
$option .= '</ul>'; |
| 1595 |
|
| 1596 |
echo $option; |
| 1597 |
|
| 1598 |
wp_die(); |
| 1599 |
} |
| 1600 |
|
| 1601 |
// Get the data for template |
| 1602 |
add_action('wp_ajax_pagelayer_search_ids', 'pagelayer_search_ids'); |
| 1603 |
function pagelayer_search_ids() { |
| 1604 |
|
| 1605 |
// Some AJAX security |
| 1606 |
check_ajax_referer('pagelayer_builder', 'pagelayer_nonce'); |
| 1607 |
|
| 1608 |
if ( empty( $_POST['filter_type'] ) || empty( $_POST['search'] ) ) { |
| 1609 |
wp_die(); |
| 1610 |
} |
| 1611 |
|
| 1612 |
$sel_opt = ''; |
| 1613 |
|
| 1614 |
switch ( $_POST['filter_type'] ) { |
| 1615 |
case 'taxonomy': |
| 1616 |
$query_params = [ |
| 1617 |
'taxonomy' => $_POST['object_type'], |
| 1618 |
'search' => $_POST['search'], |
| 1619 |
'hide_empty' => false, |
| 1620 |
]; |
| 1621 |
|
| 1622 |
$terms = get_terms( $query_params ); |
| 1623 |
|
| 1624 |
global $wp_taxonomies; |
| 1625 |
|
| 1626 |
foreach ( $terms as $term ) { |
| 1627 |
$sel_opt .= '<span class="pagelayer-temp-search-sel-span" value="'. $term->term_taxonomy_id .'">'. $term->name .'</span>'; |
| 1628 |
} |
| 1629 |
|
| 1630 |
break; |
| 1631 |
|
| 1632 |
case 'post': |
| 1633 |
$query_params = [ |
| 1634 |
'post_type' => $_POST['object_type'], //$this->extract_post_type( $data ), |
| 1635 |
's' => $_POST['search'], |
| 1636 |
'posts_per_page' => -1, |
| 1637 |
]; |
| 1638 |
|
| 1639 |
if ( 'attachment' === $query_params['post_type'] ) { |
| 1640 |
$query_params['post_status'] = 'inherit'; |
| 1641 |
} |
| 1642 |
|
| 1643 |
$query = new \WP_Query( $query_params ); |
| 1644 |
|
| 1645 |
foreach ( $query->posts as $post ) { |
| 1646 |
$sel_opt .= '<span class="pagelayer-temp-search-sel-span" value="'. $post->ID .'">'. $post->post_title .'</span>'; |
| 1647 |
} |
| 1648 |
break; |
| 1649 |
|
| 1650 |
case 'author': |
| 1651 |
$query_params = [ |
| 1652 |
'capability' => array( 'edit_posts' ), |
| 1653 |
'fields' => [ |
| 1654 |
'ID', |
| 1655 |
'display_name', |
| 1656 |
], |
| 1657 |
'search' => '*' . $_POST["search"] . '*', |
| 1658 |
'search_columns' => [ |
| 1659 |
'user_login', |
| 1660 |
'user_nicename', |
| 1661 |
], |
| 1662 |
]; |
| 1663 |
|
| 1664 |
// Capability queries were only introduced in WP 5.9. |
| 1665 |
if( version_compare( $GLOBALS['wp_version'], '5.9-alpha', '<' ) ){ |
| 1666 |
$args['who'] = 'authors'; |
| 1667 |
unset( $args['capability'] ); |
| 1668 |
} |
| 1669 |
|
| 1670 |
$user_query = new \WP_User_Query( $query_params ); |
| 1671 |
|
| 1672 |
foreach ( $user_query->get_results() as $author ) { |
| 1673 |
$sel_opt .= '<span class="pagelayer-temp-search-sel-span" value="'. $author->ID .'">'. $author->display_name .'</span>'; |
| 1674 |
} |
| 1675 |
break; |
| 1676 |
|
| 1677 |
/* case 'menu': |
| 1678 |
|
| 1679 |
$menuItems = wp_get_nav_menu_items( (int)$_POST['object_type']); |
| 1680 |
|
| 1681 |
foreach ( $menuItems as $item ) { |
| 1682 |
|
| 1683 |
if($item -> menu_item_parent !=0 ){ |
| 1684 |
continue; |
| 1685 |
} |
| 1686 |
$sel_opt .= '<span class="pagelayer-temp-search-sel-span" value="'. $item -> ID .'">'. $item -> title.'</span>'; |
| 1687 |
} |
| 1688 |
|
| 1689 |
break; */ |
| 1690 |
|
| 1691 |
default: |
| 1692 |
$sel_opt = 'Result Not Found'; |
| 1693 |
} |
| 1694 |
|
| 1695 |
if(!empty($sel_opt)){ |
| 1696 |
echo $sel_opt; |
| 1697 |
}else{ |
| 1698 |
echo 'Result Not Found'; |
| 1699 |
} |
| 1700 |
|
| 1701 |
wp_die(); |
| 1702 |
} |
| 1703 |
|
| 1704 |
// Save the post data from pagelayer setting page |
| 1705 |
add_action('wp_ajax_pagelayer_save_template', 'pagelayer_save_template'); |
| 1706 |
function pagelayer_save_template() { |
| 1707 |
|
| 1708 |
// Some AJAX security |
| 1709 |
check_ajax_referer('pagelayer_builder', 'pagelayer_nonce'); |
| 1710 |
|
| 1711 |
$done = []; |
| 1712 |
|
| 1713 |
$post_id = (int) $_GET['postID']; |
| 1714 |
|
| 1715 |
// Are you allowed to edit ? |
| 1716 |
if(!empty($post_id) && !pagelayer_user_can_edit($post_id)){ |
| 1717 |
$done['error'][] = __pl('no_permission'); |
| 1718 |
pagelayer_json_output($done); |
| 1719 |
} |
| 1720 |
|
| 1721 |
// We need to create the post |
| 1722 |
if(empty($post_id)){ |
| 1723 |
|
| 1724 |
if (!current_user_can('edit_posts')) { |
| 1725 |
$done['error'] = __pl('access_denied'); |
| 1726 |
pagelayer_json_output($done); |
| 1727 |
} |
| 1728 |
|
| 1729 |
// Get the template type |
| 1730 |
if(empty($_POST['pagelayer_template_type'])){ |
| 1731 |
$done['error'] = __pl('temp_error_type'); |
| 1732 |
pagelayer_json_output($done); |
| 1733 |
} |
| 1734 |
|
| 1735 |
$ret = wp_insert_post([ |
| 1736 |
'post_title' => $_POST['pagelayer_lib_title'], |
| 1737 |
'post_type' => 'pagelayer-template', |
| 1738 |
'post_status' => 'publish', |
| 1739 |
'comment_status' => 'closed', |
| 1740 |
'ping_status' => 'closed' |
| 1741 |
]); |
| 1742 |
|
| 1743 |
// An error occured |
| 1744 |
if(is_wp_error($ret)){ |
| 1745 |
$done['error'] = __pl('temp_error').' : '.$ret->get_error_message(); |
| 1746 |
pagelayer_json_output($done); |
| 1747 |
} |
| 1748 |
|
| 1749 |
$post_id = $ret; |
| 1750 |
$done['id'] = $post_id; |
| 1751 |
|
| 1752 |
// Save our template type |
| 1753 |
$ret = update_post_meta($post_id, 'pagelayer_template_type', $_POST['pagelayer_template_type']); |
| 1754 |
|
| 1755 |
} |
| 1756 |
|
| 1757 |
// The ID in consideration |
| 1758 |
$done['id'] = $post_id; |
| 1759 |
|
| 1760 |
// Check if the post title in not empty |
| 1761 |
if(!empty($_POST['pagelayer_lib_title'])){ |
| 1762 |
|
| 1763 |
$post = array( |
| 1764 |
'ID' => $post_id, |
| 1765 |
'post_title' => $_POST['pagelayer_lib_title'], |
| 1766 |
); |
| 1767 |
|
| 1768 |
// Update the post into the database |
| 1769 |
$ret = wp_update_post($post); |
| 1770 |
|
| 1771 |
} |
| 1772 |
|
| 1773 |
// Save template library display conditions |
| 1774 |
$condi_array = array(); |
| 1775 |
$condi_len = count($_POST['pagelayer_condition_type']); |
| 1776 |
if($_POST['pagelayer_template_type'] != 'section'){ |
| 1777 |
for( $i =0; $i < $condi_len; $i++ ){ |
| 1778 |
$condi_array[$i] = array( |
| 1779 |
'type' => $_POST['pagelayer_condition_type'][$i], |
| 1780 |
'template' => $_POST['pagelayer_condition_name'][$i], |
| 1781 |
'sub_template' => $_POST['pagelayer_condition_sub_template'][$i], |
| 1782 |
'id' => $_POST['pagelayer_condition_id'][$i], |
| 1783 |
); |
| 1784 |
} |
| 1785 |
} |
| 1786 |
//print_r($condi_array); |
| 1787 |
|
| 1788 |
$ret = update_post_meta($post_id, 'pagelayer_template_conditions', $condi_array); |
| 1789 |
|
| 1790 |
if(is_wp_error($post_id)){ |
| 1791 |
$done['error'] = __pl('temp_error').' : '.$ret->get_error_message(); |
| 1792 |
}else{ |
| 1793 |
$done['success'] = __pl('temp_update_success'); |
| 1794 |
} |
| 1795 |
|
| 1796 |
pagelayer_json_output($done); |
| 1797 |
|
| 1798 |
} |
| 1799 |
|
| 1800 |
// Products Categories Handler |
| 1801 |
add_action('wp_ajax_pagelayer_product_categories', 'pagelayer_product_categories'); |
| 1802 |
function pagelayer_product_categories(){ |
| 1803 |
|
| 1804 |
// Some AJAX security |
| 1805 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1806 |
|
| 1807 |
$attributes = ''; |
| 1808 |
$attributes .= ' number="'. $_POST['atts']['number'] .'" '; |
| 1809 |
$attributes .= ' columns="'. $_POST['atts']['columns'] .'" '; |
| 1810 |
$attributes .= ' hide_empty="'. (!empty($_POST['atts']['hide_empty']) ? 1 : 0) .'" '; |
| 1811 |
$attributes .= ' orderby="'. $_POST['atts']['nuorderbymber'] .'" '; |
| 1812 |
$attributes .= ' order="'. $_POST['atts']['order'] .'" '; |
| 1813 |
|
| 1814 |
if ( 'by_id' === $_POST['atts']['source'] ) { |
| 1815 |
$attributes .= ' ids="'. $_POST['atts']['by_id'] .'" '; |
| 1816 |
} elseif ( 'by_parent' === $_POST['atts']['source'] ) { |
| 1817 |
$attributes .= ' parent="'. $_POST['atts']['parent'] .'" '; |
| 1818 |
} elseif ( 'current_subcategories' === $_POST['atts']['source'] ) { |
| 1819 |
$attributes .= ' parent="'. get_queried_object_id() .'" '; |
| 1820 |
} |
| 1821 |
|
| 1822 |
$shortcode = '[product_categories '. $attributes .']'; |
| 1823 |
|
| 1824 |
// do_shortcode the shortcode |
| 1825 |
echo pagelayer_the_content($shortcode); |
| 1826 |
|
| 1827 |
wp_die(); |
| 1828 |
} |
| 1829 |
|
| 1830 |
// Products Categories Handler |
| 1831 |
add_action('wp_ajax_pagelayer_products_ajax', 'pagelayer_products_ajax'); |
| 1832 |
function pagelayer_products_ajax(){ |
| 1833 |
|
| 1834 |
// Some AJAX security |
| 1835 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1836 |
|
| 1837 |
if ( WC()->session ) { |
| 1838 |
wc_print_notices(); |
| 1839 |
} |
| 1840 |
|
| 1841 |
$no_found = $_POST['atts']['no_found']; |
| 1842 |
|
| 1843 |
$attributes = ''; |
| 1844 |
$type = $_POST['atts']['source']; |
| 1845 |
$attributes .= ' columns="'. $_POST['atts']['columns'] .'" '; |
| 1846 |
$attributes .= ' rows="'. $_POST['atts']['rows'] .'" '; |
| 1847 |
$attributes .= ' paginate="'. (!empty($_POST['atts']['paginate']) ? true : false) .'" '; |
| 1848 |
$attributes .= ' orderby="'. $_POST['atts']['orderby'] .'" '; |
| 1849 |
$attributes .= ' order="'. $_POST['atts']['order'] .'" '; |
| 1850 |
$attributes .= ' cache="false" '; |
| 1851 |
|
| 1852 |
// Hide the catalog order |
| 1853 |
if( empty($_POST['atts']['allow_order']) ){ |
| 1854 |
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 ); |
| 1855 |
} |
| 1856 |
|
| 1857 |
// Hide the result count |
| 1858 |
if( empty($_POST['atts']['show_result']) ){ |
| 1859 |
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); |
| 1860 |
} |
| 1861 |
|
| 1862 |
if( $type == 'by_id' ){ |
| 1863 |
$type = 'products'; |
| 1864 |
$attributes .= ' ids="'. (!empty($_POST['atts']['ids']) ? $_POST['atts']['ids'] : '') .'" '; |
| 1865 |
}elseif( $type == 'pagelayer_current_query' ){ |
| 1866 |
|
| 1867 |
$atts['paginate'] = (!empty($_POST['atts']['paginate']) ? true : false); |
| 1868 |
$atts['cache'] = false; |
| 1869 |
|
| 1870 |
$type = 'pagelayer_current_query'; |
| 1871 |
|
| 1872 |
// Set the current query |
| 1873 |
add_action( 'woocommerce_shortcode_products_query', 'pagelayer_shortcode_current_query', 10, 10); |
| 1874 |
|
| 1875 |
// If product not found |
| 1876 |
add_action( "woocommerce_shortcode_{$type}_loop_no_results", function ($attributes) use ($no_found){ |
| 1877 |
echo '<div class="pagelayer-product-no-found">'.$no_found.'</div>'; |
| 1878 |
} ); |
| 1879 |
|
| 1880 |
// Get the products list |
| 1881 |
$shortcode = new WC_Shortcode_Products( $atts, $type ); |
| 1882 |
|
| 1883 |
echo $shortcode->get_content(); |
| 1884 |
return true; |
| 1885 |
} |
| 1886 |
|
| 1887 |
$shortcode = '['.$type.' '. $attributes .']'; |
| 1888 |
|
| 1889 |
$content = pagelayer_the_content($shortcode); |
| 1890 |
|
| 1891 |
// If product not found |
| 1892 |
if('<div class="woocommerce columns-'.$_POST['atts']['columns'] .' "></div>' == $content){ |
| 1893 |
$content = '<div class="pagelayer-product-no-found">'. $no_found .'</div>'; |
| 1894 |
} |
| 1895 |
|
| 1896 |
echo $content; |
| 1897 |
|
| 1898 |
wp_die(); |
| 1899 |
} |
| 1900 |
|
| 1901 |
// Markdown Handler |
| 1902 |
add_action('wp_ajax_pagelayer_handle_markdown', 'pagelayer_handle_markdown'); |
| 1903 |
function pagelayer_handle_markdown(){ |
| 1904 |
|
| 1905 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1906 |
|
| 1907 |
if(!defined('PAGELAYER_PRO_VERSION')){ |
| 1908 |
wp_send_json_error(['message' => __('Markdown feature requires Pagelayer Pro.', 'pagelayer')]); |
| 1909 |
return; |
| 1910 |
} |
| 1911 |
|
| 1912 |
include_once(PAGELAYER_PRO_DIR.'/main/premium_functions.php'); |
| 1913 |
|
| 1914 |
$raw_atts = isset($_POST['data']) && is_array($_POST['data']) ? wp_unslash($_POST['data']) : []; |
| 1915 |
$atts = []; |
| 1916 |
|
| 1917 |
foreach($raw_atts as $key => $value){ |
| 1918 |
$clean_key = sanitize_key($key); |
| 1919 |
|
| 1920 |
// Check for invalid UTF-8 to prevent database errors |
| 1921 |
if(in_array($clean_key, ['markdown_text_file', 'markdown_text_url', 'active_markdown_text'])){ |
| 1922 |
$atts[$clean_key] = wp_check_invalid_utf8($value); |
| 1923 |
} else{ |
| 1924 |
$atts[$clean_key] = sanitize_text_field($value); |
| 1925 |
} |
| 1926 |
} |
| 1927 |
|
| 1928 |
$fetched = pagelayer_get_markdown_content($atts); |
| 1929 |
$current_text = $fetched['text']; |
| 1930 |
$default_text = __pl('Select a Markdown file or enter a URL to load content.'); |
| 1931 |
|
| 1932 |
// Compile HTML |
| 1933 |
$html = ''; |
| 1934 |
if(!empty($fetched['is_error'])){ |
| 1935 |
$html = '<div class="pagelayer-markdown-error">' . esc_html($current_text) . '</div>'; |
| 1936 |
} else if($current_text === $default_text){ |
| 1937 |
$html = '<div class="pagelayer-markdown-placeholder">' . $default_text . '</div>'; |
| 1938 |
} else if(function_exists('pagelayer_markdown_to_html')){ |
| 1939 |
$html = pagelayer_markdown_to_html($current_text); |
| 1940 |
} |
| 1941 |
|
| 1942 |
$wp['html'] = wp_kses_post($html); |
| 1943 |
$wp['raw_text'] = $current_text; |
| 1944 |
$wp['is_error'] = !empty($fetched['is_error']); |
| 1945 |
|
| 1946 |
pagelayer_json_output($wp); |
| 1947 |
|
| 1948 |
wp_die(); |
| 1949 |
} |
| 1950 |
|
| 1951 |
// Get Taxamony List for SiteMap |
| 1952 |
add_action('wp_ajax_pagelayer_get_taxonomy_list', 'pagelayer_get_taxonomy_list'); |
| 1953 |
function pagelayer_get_taxonomy_list(){ |
| 1954 |
|
| 1955 |
// Some AJAX security |
| 1956 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1957 |
|
| 1958 |
if(!current_user_can('edit_posts')){ |
| 1959 |
echo __pl('no_permission'); |
| 1960 |
wp_die(); |
| 1961 |
} |
| 1962 |
|
| 1963 |
$args = array( |
| 1964 |
'title_li' => 0, |
| 1965 |
'orderby' => $_POST['post_order'], |
| 1966 |
'order' => $_POST['order'], |
| 1967 |
'style' => '', |
| 1968 |
'hide_empty' => $_POST['empty'], |
| 1969 |
'echo' => false, |
| 1970 |
'hierarchical' => (empty($_POST['hier']) || $_POST['hier'] == null ? '' : $_POST['hier']), |
| 1971 |
'taxonomy' => $_POST['type'], |
| 1972 |
'depth' => (empty($_POST['depth']) || $_POST['depth'] == null ? '' : $_POST['depth']), |
| 1973 |
); |
| 1974 |
|
| 1975 |
$taxonomies = get_categories( $args ); |
| 1976 |
|
| 1977 |
$option = '<ul>'; |
| 1978 |
foreach ( $taxonomies as $taxonomy ) { |
| 1979 |
$option .= '<li class="pagelayer-sitemap-list-item" data-postID="'.$taxonomy->term_id.'"><a class="pagelayer-ele-link" href="'.get_term_link($taxonomy->term_id).'">'.$taxonomy->name.'</a></li>'; |
| 1980 |
} |
| 1981 |
$option .= '</ul>'; |
| 1982 |
|
| 1983 |
echo $option; |
| 1984 |
wp_die(); |
| 1985 |
} |
| 1986 |
|
| 1987 |
// Export the template |
| 1988 |
add_action('wp_ajax_pagelayer_export_template', 'pagelayer_export_template'); |
| 1989 |
function pagelayer_export_template(){ |
| 1990 |
|
| 1991 |
global $pagelayer; |
| 1992 |
|
| 1993 |
// Some AJAX security |
| 1994 |
check_ajax_referer('pagelayer_builder', 'pagelayer_nonce'); |
| 1995 |
|
| 1996 |
$done = []; |
| 1997 |
|
| 1998 |
if(!current_user_can('edit_theme_options')){ |
| 1999 |
$done['error'][] = __pl('no_permission'); |
| 2000 |
pagelayer_json_output($done); |
| 2001 |
} |
| 2002 |
|
| 2003 |
// Load the templates |
| 2004 |
pagelayer_builder_load_templates(); |
| 2005 |
|
| 2006 |
if(empty($pagelayer->templates)){ |
| 2007 |
$done['error'] = __pl('temp_export_empty'); |
| 2008 |
pagelayer_json_output($done); |
| 2009 |
} |
| 2010 |
|
| 2011 |
// Load Shortcodes |
| 2012 |
pagelayer_load_shortcodes(); |
| 2013 |
|
| 2014 |
// Get the active theme |
| 2015 |
$theme_dir = get_stylesheet_directory(); |
| 2016 |
$conf = []; |
| 2017 |
|
| 2018 |
$pagelayer->export_mode = 1; |
| 2019 |
|
| 2020 |
// Write the files |
| 2021 |
foreach($pagelayer->templates as $k => $v){ |
| 2022 |
|
| 2023 |
// Are there specific templates to export |
| 2024 |
if(!empty($_POST['templates'])){ |
| 2025 |
if(!isset($_POST['templates'][$v->ID])){ |
| 2026 |
continue; |
| 2027 |
} |
| 2028 |
} |
| 2029 |
|
| 2030 |
// Only blocks allowed |
| 2031 |
if(!has_blocks($v->post_content) && !empty($v->post_content)){ |
| 2032 |
$done['error'] = 'The pagelayer template '.$v->ID.' has Shortcodes which is not allowed for export !'; |
| 2033 |
pagelayer_json_output($done); |
| 2034 |
} |
| 2035 |
|
| 2036 |
$v->post_name = (empty($v->post_name) && $v->post_status == 'draft') ? sanitize_title($v->post_title).'-draft' : $v->post_name; |
| 2037 |
|
| 2038 |
// Write the content |
| 2039 |
file_put_contents($theme_dir.'/'.$v->post_name.'.pgl', pagelayer_export_content($v->post_content)); |
| 2040 |
$conf[$v->post_name] = [ |
| 2041 |
'type' => get_post_meta($v->ID, 'pagelayer_template_type', true), |
| 2042 |
'title' => $v->post_title, |
| 2043 |
'conditions' => get_post_meta($v->ID, 'pagelayer_template_conditions', true), |
| 2044 |
]; |
| 2045 |
} |
| 2046 |
|
| 2047 |
// Write the config |
| 2048 |
file_put_contents($theme_dir.'/pagelayer.conf', json_encode($conf, JSON_PRETTY_PRINT)); |
| 2049 |
|
| 2050 |
$conf = []; |
| 2051 |
|
| 2052 |
// Load the other posts |
| 2053 |
foreach($pagelayer->settings['post_types'] as $type){ |
| 2054 |
|
| 2055 |
// Anything to export for users ? |
| 2056 |
if(!empty($_POST[$type]) && is_array($_POST[$type])){ |
| 2057 |
|
| 2058 |
mkdir($theme_dir.'/data/'); |
| 2059 |
mkdir($theme_dir.'/data/'.$type); |
| 2060 |
|
| 2061 |
$pids = []; |
| 2062 |
|
| 2063 |
foreach($_POST[$type] as $k => $v){ |
| 2064 |
$pids[] = (int) $k; |
| 2065 |
} |
| 2066 |
|
| 2067 |
// Load the type |
| 2068 |
$_query = new WP_Query([ |
| 2069 |
'post_type' => $type, |
| 2070 |
'status' => 'publish', |
| 2071 |
'post__in' => $pids, |
| 2072 |
'posts_per_page' => -1, |
| 2073 |
]); |
| 2074 |
|
| 2075 |
$posts = $_query->posts; |
| 2076 |
|
| 2077 |
// Write the files |
| 2078 |
foreach($posts as $k => $v){ |
| 2079 |
|
| 2080 |
// Only blocks allowed |
| 2081 |
if(!has_blocks($v->post_content) && !empty($v->post_content)){ |
| 2082 |
$done['error'] = 'The '.$type.' '.$v->ID.' has Shortcodes which is not allowed for export !'; |
| 2083 |
pagelayer_json_output($done); |
| 2084 |
} |
| 2085 |
|
| 2086 |
$v->post_name = (empty($v->post_name) && $v->post_status == 'draft') ? sanitize_title($v->post_title).'-draft' : $v->post_name; |
| 2087 |
|
| 2088 |
file_put_contents($theme_dir.'/data/'.$type.'/'.$v->post_name, pagelayer_export_content($v->post_content)); |
| 2089 |
unset($v->post_content); |
| 2090 |
|
| 2091 |
$meta = get_post_meta($v->ID); |
| 2092 |
$meta = array_combine(array_keys($meta), array_column($meta, 0)); |
| 2093 |
|
| 2094 |
// Export media |
| 2095 |
if(!empty($meta['_thumbnail_id'])){ |
| 2096 |
|
| 2097 |
$file = pagelayer_export_media_files($meta['_thumbnail_id'], $exp_img_url); |
| 2098 |
|
| 2099 |
// Did it export ? |
| 2100 |
if(!empty($file)){ |
| 2101 |
$meta['_thumbnail_id'] = $exp_img_url; |
| 2102 |
} |
| 2103 |
|
| 2104 |
} |
| 2105 |
|
| 2106 |
// Also put the meta |
| 2107 |
file_put_contents($theme_dir.'/data/'.$type.'/'.$v->post_name.'.meta', json_encode($meta, JSON_PRETTY_PRINT)); |
| 2108 |
|
| 2109 |
//Export taxonomies in post |
| 2110 |
$taxonomies = get_object_taxonomies( $v->post_type, 'objects' ); |
| 2111 |
$post_taxonomies = wp_filter_object_list( $taxonomies, [ |
| 2112 |
'public' => true, |
| 2113 |
'show_in_nav_menus' => true, |
| 2114 |
] ); |
| 2115 |
|
| 2116 |
foreach( $post_taxonomies as $slug => $object ){ |
| 2117 |
|
| 2118 |
if(empty($v->taxonomies) || !is_array($v->taxonomies)){ |
| 2119 |
$v->taxonomies = array(); |
| 2120 |
} |
| 2121 |
|
| 2122 |
$tax_name = $object->name; |
| 2123 |
$the_terms = get_the_terms($v->ID, $tax_name); |
| 2124 |
$v->taxonomies[$tax_name] = ''; |
| 2125 |
|
| 2126 |
if(!empty($the_terms)){ |
| 2127 |
$v->taxonomies[$tax_name] = implode(',', array_column($the_terms, 'term_id')); |
| 2128 |
} |
| 2129 |
} |
| 2130 |
|
| 2131 |
$conf[$type][$v->post_name] = $v; |
| 2132 |
|
| 2133 |
do_action('pagelayer_'.$type.'_exported', $v, $theme_dir); |
| 2134 |
|
| 2135 |
} |
| 2136 |
|
| 2137 |
ksort($conf[$type]); |
| 2138 |
|
| 2139 |
} |
| 2140 |
|
| 2141 |
} |
| 2142 |
|
| 2143 |
// Export menus |
| 2144 |
if(!empty($pagelayer->export_menus) && is_array($pagelayer->export_menus)){ |
| 2145 |
|
| 2146 |
mkdir($theme_dir.'/data/menus'); |
| 2147 |
|
| 2148 |
foreach($pagelayer->export_menus as $k => $v){ |
| 2149 |
|
| 2150 |
$menu = (int) $k; |
| 2151 |
$menu = wp_get_nav_menu_object( $menu ); |
| 2152 |
|
| 2153 |
if(empty($menu)){ |
| 2154 |
$done['error'] = 'Could not export menu ID - '.$k; |
| 2155 |
continue; |
| 2156 |
} |
| 2157 |
|
| 2158 |
// Menu Items |
| 2159 |
$menu_items = wp_get_nav_menu_items( $menu->term_id ); |
| 2160 |
$data = []; |
| 2161 |
|
| 2162 |
if(is_array($menu_items) && !empty($menu_items)){ |
| 2163 |
foreach($menu_items as $kk => $singlenav){ |
| 2164 |
//$navmetas = get_post_meta($singlenav->ID); |
| 2165 |
//$navmetas = array_combine(array_keys($navmetas), array_column($navmetas, 0)); |
| 2166 |
$data[$kk]['post'] = $singlenav; |
| 2167 |
$navmetas = array(); |
| 2168 |
|
| 2169 |
$pl_content = get_post_meta($singlenav->ID, '_pagelayer_content', true); |
| 2170 |
if(!empty($pl_content)){ |
| 2171 |
$navmetas['_pagelayer_content'] = pagelayer_export_content($pl_content); |
| 2172 |
} |
| 2173 |
|
| 2174 |
$data[$kk]['post_metas'] = $navmetas; |
| 2175 |
} |
| 2176 |
} |
| 2177 |
|
| 2178 |
// Also put the meta |
| 2179 |
file_put_contents($theme_dir.'/data/menus/'.$menu->slug, json_encode($data, JSON_PRETTY_PRINT)); |
| 2180 |
|
| 2181 |
$conf['menus'][$menu->slug] = $menu; |
| 2182 |
|
| 2183 |
do_action('pagelayer_menus_exported', $v, $theme_dir); |
| 2184 |
|
| 2185 |
} |
| 2186 |
|
| 2187 |
} |
| 2188 |
|
| 2189 |
// Export the settings |
| 2190 |
$settings = ['pagelayer_content_width', 'pagelayer_body_font', 'pagelayer_tablet_breakpoint', 'pagelayer_mobile_breakpoint', 'pagelayer_header_code','pagelayer_body_open_code', 'pagelayer_footer_code', 'pagelayer_sidebar', 'page_for_posts', 'pagelayer_global_fonts', 'pagelayer_global_colors']; |
| 2191 |
|
| 2192 |
foreach($settings as $v){ |
| 2193 |
|
| 2194 |
$vv = get_option($v); |
| 2195 |
|
| 2196 |
if($vv){ |
| 2197 |
$conf['conf'][$v] = $vv; |
| 2198 |
} |
| 2199 |
|
| 2200 |
} |
| 2201 |
|
| 2202 |
// Load CSS settings |
| 2203 |
foreach($pagelayer->css_settings as $k => $params){ |
| 2204 |
foreach($pagelayer->screens as $sk => $sv){ |
| 2205 |
$suffix = (!empty($sv) ? '_'.$sv : ''); |
| 2206 |
$setting = empty($params['key']) ? 'pagelayer_'.$k.'_css' : $params['key']; |
| 2207 |
$tmp = get_option($setting.$suffix); |
| 2208 |
if(!empty($tmp)){ |
| 2209 |
$conf['conf'][$setting.$suffix] = $tmp; |
| 2210 |
} |
| 2211 |
} |
| 2212 |
} |
| 2213 |
|
| 2214 |
// Export all the taxonomies |
| 2215 |
$post_types = pagelayer_get_public_post_types(); |
| 2216 |
|
| 2217 |
// Export all the Post Type CSS Settings |
| 2218 |
foreach ( $post_types as $pt_slug => $type ) { |
| 2219 |
|
| 2220 |
if ( $pt_slug == 'attachment' ) { |
| 2221 |
continue; |
| 2222 |
} |
| 2223 |
|
| 2224 |
foreach($pagelayer->css_settings as $k => $params){ |
| 2225 |
foreach($pagelayer->screens as $sk => $sv){ |
| 2226 |
$suffix = (!empty($sv) ? '_'.$sv : ''); |
| 2227 |
$setting = empty($params['key']) ? 'pagelayer_'.$k.'_css_'.$pt_slug : $params['key'].'_'.$pt_slug; |
| 2228 |
$tmp = get_option($setting.$suffix); |
| 2229 |
|
| 2230 |
if(!empty($tmp)){ |
| 2231 |
$conf['conf'][$setting.$suffix] = $tmp; |
| 2232 |
} |
| 2233 |
} |
| 2234 |
} |
| 2235 |
} |
| 2236 |
|
| 2237 |
// Export all the taxonomies |
| 2238 |
foreach ( $post_types as $post_type => $label ) { |
| 2239 |
$type_taxonomies = get_object_taxonomies( $post_type, 'objects' ); |
| 2240 |
$taxonomies = wp_filter_object_list( $type_taxonomies, [ |
| 2241 |
'public' => true, |
| 2242 |
'show_in_nav_menus' => true, |
| 2243 |
] ); |
| 2244 |
|
| 2245 |
foreach( $taxonomies as $slug => $object ){ |
| 2246 |
|
| 2247 |
$query_params = [ |
| 2248 |
'taxonomy' => $object->name, |
| 2249 |
'hide_empty' => false, |
| 2250 |
]; |
| 2251 |
$terms = get_terms( $query_params ); |
| 2252 |
|
| 2253 |
foreach($terms as $term){ |
| 2254 |
$conf['taxonomies'][$term->term_id] = $term; |
| 2255 |
} |
| 2256 |
} |
| 2257 |
|
| 2258 |
} |
| 2259 |
|
| 2260 |
// Write the config |
| 2261 |
if(!empty($conf)){ |
| 2262 |
file_put_contents($theme_dir.'/pagelayer-data.conf', json_encode($conf, JSON_PRETTY_PRINT)); |
| 2263 |
} |
| 2264 |
|
| 2265 |
// Are we to export any media ? |
| 2266 |
if(!empty($pagelayer->media_to_export)){ |
| 2267 |
// TODO |
| 2268 |
//$done['media'] = $pagelayer->media_to_export; |
| 2269 |
} |
| 2270 |
|
| 2271 |
do_action('pagelayer_template_export_completed'); |
| 2272 |
|
| 2273 |
$done['success'] = __pl('temp_export_success'); |
| 2274 |
|
| 2275 |
// Output and die |
| 2276 |
pagelayer_json_output($done); |
| 2277 |
|
| 2278 |
} |
| 2279 |
|
| 2280 |
add_action('wp_ajax_pagelayer_get_cat_checkboxes', 'pagelayer_get_cat_checkboxes'); |
| 2281 |
function pagelayer_get_cat_checkboxes(){ |
| 2282 |
|
| 2283 |
// Some AJAX security |
| 2284 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 2285 |
|
| 2286 |
$ret = []; |
| 2287 |
$cat_name = ''; |
| 2288 |
|
| 2289 |
if(!current_user_can('manage_categories')){ |
| 2290 |
$ret['error'] = __pl('no_permission'); |
| 2291 |
pagelayer_json_output($ret); |
| 2292 |
} |
| 2293 |
|
| 2294 |
if(empty($_POST['postid']) || !is_numeric($_POST['postid'])){ |
| 2295 |
$ret['error'] = __pl('invalid_post_id'); |
| 2296 |
pagelayer_json_output($ret); |
| 2297 |
} |
| 2298 |
|
| 2299 |
$post = (int) $_POST['postid']; |
| 2300 |
$post = get_post($post); |
| 2301 |
|
| 2302 |
if(empty($post) || is_wp_error($post)){ |
| 2303 |
$ret['error'] = __pl('invalid_post_id'); |
| 2304 |
pagelayer_json_output($ret); |
| 2305 |
} |
| 2306 |
|
| 2307 |
$cat_name = pagelayer_post_type_category($post->post_type); |
| 2308 |
|
| 2309 |
if(!empty($_POST['new_cat'])){ |
| 2310 |
parse_str($_POST['new_cat'], $formdata); |
| 2311 |
$ret['new_cat_id'] = wp_insert_category([ |
| 2312 |
'taxonomy' => $cat_name, |
| 2313 |
'cat_name' => $formdata['category_name'], |
| 2314 |
'category_parent' => (($formdata['pagelayer_cat_parent'] == 0) ? '' : $formdata['pagelayer_cat_parent']) |
| 2315 |
]); |
| 2316 |
} |
| 2317 |
|
| 2318 |
$ret += pagelayer_post_cats($post); |
| 2319 |
|
| 2320 |
pagelayer_json_output($ret); |
| 2321 |
|
| 2322 |
} |
| 2323 |
|
| 2324 |
add_action('wp_ajax_pagelayer_get_post_tags', 'pagelayer_get_post_tags'); |
| 2325 |
function pagelayer_get_post_tags(){ |
| 2326 |
|
| 2327 |
// Some AJAX security |
| 2328 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 2329 |
|
| 2330 |
$ret = []; |
| 2331 |
$tag_name = ''; |
| 2332 |
|
| 2333 |
if(!current_user_can('manage_categories')){ |
| 2334 |
$ret['error'] = __pl('no_permission'); |
| 2335 |
pagelayer_json_output($ret); |
| 2336 |
} |
| 2337 |
|
| 2338 |
if(empty($_POST['postid']) || !is_numeric($_POST['postid']) ){ |
| 2339 |
pagelayer_json_output($ret); |
| 2340 |
} |
| 2341 |
|
| 2342 |
$post = (int) $_POST['postid']; |
| 2343 |
$post = get_post($post); |
| 2344 |
|
| 2345 |
if(empty($post) || is_wp_error($post)){ |
| 2346 |
$ret['error'] = __pl('invalid_post_id'); |
| 2347 |
pagelayer_json_output($ret); |
| 2348 |
} |
| 2349 |
|
| 2350 |
$tag_name = pagelayer_post_type_tag($post->post_type); |
| 2351 |
|
| 2352 |
if(!empty($_POST['new_tag'])){ |
| 2353 |
$ret['tag_id'] = wp_insert_term($_POST['new_tag'], $tag_name); |
| 2354 |
$ret['tag_id'] = $ret['tag_id']['term_id']; |
| 2355 |
} |
| 2356 |
|
| 2357 |
$ret += pagelayer_post_tags($post); |
| 2358 |
|
| 2359 |
pagelayer_json_output($ret); |
| 2360 |
|
| 2361 |
} |
| 2362 |
|
| 2363 |
add_action('wp_ajax_pagelayer_custom_font', 'pagelayer_custom_font'); |
| 2364 |
function pagelayer_custom_font(){ |
| 2365 |
|
| 2366 |
// Some AJAX security |
| 2367 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 2368 |
|
| 2369 |
$ret = []; |
| 2370 |
|
| 2371 |
if(empty($_POST['font_name'])){ |
| 2372 |
pagelayer_json_output($ret); |
| 2373 |
} |
| 2374 |
|
| 2375 |
$name = preg_replace('/_plf$/is', '', pagelayer_optREQ('font_name')); |
| 2376 |
//echo $name; |
| 2377 |
|
| 2378 |
$args = [ |
| 2379 |
'post_type' => PAGELAYER_FONT_POST_TYPE, |
| 2380 |
'status' => 'publish', |
| 2381 |
'posts_per_page' => 1, |
| 2382 |
'name' => $name |
| 2383 |
]; |
| 2384 |
|
| 2385 |
//var_dump($pagelayer->fonts); |
| 2386 |
|
| 2387 |
$query = get_posts($args); |
| 2388 |
//var_dump($query); |
| 2389 |
|
| 2390 |
if(empty($query)){ |
| 2391 |
pagelayer_json_output($ret); |
| 2392 |
} |
| 2393 |
|
| 2394 |
$post = $query[0]; |
| 2395 |
$meta_box_value = get_post_meta( $post->ID, 'pagelayer_font_link', true); |
| 2396 |
if(empty($meta_box_value)){ |
| 2397 |
pagelayer_json_output($ret); |
| 2398 |
} |
| 2399 |
|
| 2400 |
$ret['style']= '<style id="'.$name.'_plf" >@font-face { font-family: "'.$name.'_plf"'.'; src: url("'.$meta_box_value.'"); font-weight: 100 200 300 400 500 600 700 800 900;}</style>'; |
| 2401 |
|
| 2402 |
pagelayer_json_output($ret); |
| 2403 |
|
| 2404 |
} |
| 2405 |
|
| 2406 |
add_action('wp_ajax_pagelayer_trash_post', 'pagelayer_trash_post'); |
| 2407 |
function pagelayer_trash_post(){ |
| 2408 |
|
| 2409 |
// Some AJAX security |
| 2410 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 2411 |
|
| 2412 |
$ret = []; |
| 2413 |
|
| 2414 |
if(empty($_POST['postid']) && !is_numeric($_POST['postid'])){ |
| 2415 |
$ret = ['error' => __pl('invalid_post_id')]; |
| 2416 |
pagelayer_json_output($ret); |
| 2417 |
} |
| 2418 |
|
| 2419 |
if(!current_user_can( 'delete_post', $_POST['postid'] )){ |
| 2420 |
$ret = ['error' => __pl('no_permission')]; |
| 2421 |
pagelayer_json_output($ret); |
| 2422 |
} |
| 2423 |
|
| 2424 |
$ret['url'] = admin_url('/edit.php?post_type=') .get_post_type($_POST['postid']); |
| 2425 |
|
| 2426 |
wp_trash_post($_POST['postid']); |
| 2427 |
|
| 2428 |
pagelayer_json_output($ret); |
| 2429 |
|
| 2430 |
} |
| 2431 |
|
| 2432 |
add_action('wp_ajax_pagelayer_infinite_posts', 'pagelayer_infinite_posts'); |
| 2433 |
add_action('wp_ajax_nopriv_pagelayer_infinite_posts', 'pagelayer_infinite_posts'); |
| 2434 |
function pagelayer_infinite_posts(){ |
| 2435 |
|
| 2436 |
// Some AJAX security |
| 2437 |
check_ajax_referer('pagelayer_global', 'pagelayer_nonce'); |
| 2438 |
|
| 2439 |
pagelayer_load_shortcodes(); |
| 2440 |
|
| 2441 |
$tag = 'pl_posts'; |
| 2442 |
|
| 2443 |
if(isset($_REQUEST['data']['tag']) && $_REQUEST['data']['tag'] == 'pl_archive_posts' ){ |
| 2444 |
$tag = 'pl_archive_posts'; |
| 2445 |
} |
| 2446 |
|
| 2447 |
$content = get_comment_delimited_block_content( 'pagelayer/'.$tag, $_REQUEST['data']['atts'] , ''); |
| 2448 |
$wp['posts'] = pagelayer_the_content($content); |
| 2449 |
pagelayer_json_output( $wp ); |
| 2450 |
} |
| 2451 |
|
| 2452 |
add_action('wp_ajax_pagelayer_pro_dismiss_expired_licenses', 'pagelayer_pro_dismiss_expired_licenses'); |
| 2453 |
function pagelayer_pro_dismiss_expired_licenses(){ |
| 2454 |
check_admin_referer('pagelayer_expiry_notice', 'security'); |
| 2455 |
|
| 2456 |
if(!current_user_can('activate_plugins')){ |
| 2457 |
wp_send_json_error(__('You do not have required access to do this action', 'pagelayer')); |
| 2458 |
} |
| 2459 |
|
| 2460 |
update_option('softaculous_expired_licenses', time()); |
| 2461 |
wp_send_json_success(); |
| 2462 |
} |
| 2463 |
|
| 2464 |
add_action('wp_ajax_pagelayer_close_update_notice', 'pagelayer_close_plugin_update_notice'); |
| 2465 |
function pagelayer_close_plugin_update_notice(){ |
| 2466 |
check_ajax_referer('pagelayer_promo_nonce', 'pagelayer_nonce'); |
| 2467 |
|
| 2468 |
if(!current_user_can('manage_options')){ |
| 2469 |
wp_send_json_error('You don\'t have privilege to close this notice!'); |
| 2470 |
} |
| 2471 |
|
| 2472 |
$plugin_update_notice = get_option('softaculous_plugin_update_notice', []); |
| 2473 |
$available_update_list = get_site_transient('update_plugins'); |
| 2474 |
$to_update_plugins = apply_filters('softaculous_plugin_update_notice', []); |
| 2475 |
|
| 2476 |
if(empty($available_update_list) || empty($available_update_list->response)){ |
| 2477 |
return; |
| 2478 |
} |
| 2479 |
|
| 2480 |
foreach($to_update_plugins as $plugin_path => $plugin_name){ |
| 2481 |
if(isset($available_update_list->response[$plugin_path])){ |
| 2482 |
$plugin_update_notice[$plugin_path] = $available_update_list->response[$plugin_path]->new_version; |
| 2483 |
} |
| 2484 |
} |
| 2485 |
|
| 2486 |
update_option('softaculous_plugin_update_notice', $plugin_update_notice); |
| 2487 |
} |