| 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 |
// Is the nonce there ? |
| 28 |
if(empty($_REQUEST['pagelayer_nonce'])){ |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
// The ajax handler |
| 33 |
add_action('wp_ajax_pagelayer_wp_widget', 'pagelayer_wp_widget_ajax'); |
| 34 |
function pagelayer_wp_widget_ajax(){ |
| 35 |
|
| 36 |
global $pagelayer; |
| 37 |
|
| 38 |
// Some AJAX security |
| 39 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 40 |
|
| 41 |
pagelayer_load_shortcodes(); |
| 42 |
|
| 43 |
header('Content-Type: application/json'); |
| 44 |
|
| 45 |
$ret = []; |
| 46 |
$tag = @$_POST['tag']; |
| 47 |
//pagelayer_print($pagelayer->shortcodes[$tag]); |
| 48 |
|
| 49 |
// No tag ? |
| 50 |
if(empty($pagelayer->shortcodes[$tag])){ |
| 51 |
$ret['error'][] = __pl('no_tag'); |
| 52 |
pagelayer_json_output($ret); |
| 53 |
} |
| 54 |
|
| 55 |
// Include the widgets |
| 56 |
include_once(ABSPATH . 'wp-admin/includes/widgets.php'); |
| 57 |
|
| 58 |
$class = $pagelayer->shortcodes[$tag]['widget']; |
| 59 |
|
| 60 |
// Check the widget class exists ? |
| 61 |
if(empty($class) || !class_exists($class)){ |
| 62 |
$ret['error'][] = __pl('no_widget_class'); |
| 63 |
pagelayer_json_output($ret); |
| 64 |
} |
| 65 |
|
| 66 |
$instance = []; |
| 67 |
$widget = new $class(); |
| 68 |
$widget->_set('pagelayer-widget-1234567890'); |
| 69 |
|
| 70 |
// Is there any existing data ? |
| 71 |
if(!empty($_POST['widget_data'])){ |
| 72 |
$json = json_decode(stripslashes($_POST['widget_data']), true); |
| 73 |
//pagelayer_print($json);die(); |
| 74 |
if(!empty($json)){ |
| 75 |
$instance = $json; |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
// Are there any form values ? |
| 80 |
if(!empty($_POST['values'])){ |
| 81 |
parse_str(stripslashes($_POST['values']), $data); |
| 82 |
//pagelayer_print($data);die(); |
| 83 |
|
| 84 |
// Any data ? |
| 85 |
if(!empty($data)){ |
| 86 |
|
| 87 |
// First key is useless |
| 88 |
$data = current($data); |
| 89 |
|
| 90 |
// Do we still have valid data ? |
| 91 |
if(!empty($data)){ |
| 92 |
|
| 93 |
// 2nd key is useless and just over-ride instance |
| 94 |
$instance = current($data); |
| 95 |
|
| 96 |
} |
| 97 |
} |
| 98 |
} |
| 99 |
|
| 100 |
// Get the form |
| 101 |
ob_start(); |
| 102 |
$widget->form($instance); |
| 103 |
$ret['form'] = ob_get_contents(); |
| 104 |
ob_end_clean(); |
| 105 |
|
| 106 |
// Get the html |
| 107 |
ob_start(); |
| 108 |
$widget->widget([], $instance); |
| 109 |
$ret['html'] = ob_get_contents(); |
| 110 |
ob_end_clean(); |
| 111 |
|
| 112 |
// Widget data to set |
| 113 |
if(!empty($instance)){ |
| 114 |
$ret['widget_data'] = $instance; |
| 115 |
} |
| 116 |
|
| 117 |
pagelayer_json_output($ret); |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
// Update Post content |
| 122 |
add_action('wp_ajax_pagelayer_save_content', 'pagelayer_save_content'); |
| 123 |
function pagelayer_save_content(){ |
| 124 |
|
| 125 |
// Some AJAX security |
| 126 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 127 |
|
| 128 |
$content = $_POST['pagelayer_update_content']; |
| 129 |
|
| 130 |
$postID = (int) $_GET['postID']; |
| 131 |
|
| 132 |
if(empty($postID)){ |
| 133 |
$msg['error'] = __pl('invalid_post_id'); |
| 134 |
} |
| 135 |
|
| 136 |
// Check if the post exists |
| 137 |
|
| 138 |
if(!empty($postID) && !empty($content)){ |
| 139 |
|
| 140 |
$post = array( |
| 141 |
'ID' => $postID, |
| 142 |
'post_content' => $content, |
| 143 |
); |
| 144 |
|
| 145 |
// Any properties ? |
| 146 |
if(!empty($_REQUEST['page_props'])){ |
| 147 |
|
| 148 |
$allowed = ['post_title', 'post_name', 'post_excerpt', 'post_status']; |
| 149 |
|
| 150 |
foreach($allowed as $k){ |
| 151 |
if(!empty($_REQUEST['page_props'][$k])){ |
| 152 |
$post[$k] = $_REQUEST['page_props'][$k]; |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
$_REQUEST['page_props']['featured_image'] = (int) $_REQUEST['page_props']['featured_image']; |
| 157 |
if(!empty($_REQUEST['page_props']['featured_image'])){ |
| 158 |
set_post_thumbnail($postID, $_REQUEST['page_props']['featured_image']); |
| 159 |
}else{ |
| 160 |
delete_post_thumbnail($postID); |
| 161 |
} |
| 162 |
|
| 163 |
} |
| 164 |
|
| 165 |
// Apply a filter |
| 166 |
$post = apply_filters('pagelayer_save_content', $post); |
| 167 |
|
| 168 |
// Update the post into the database |
| 169 |
wp_update_post($post); |
| 170 |
|
| 171 |
if (is_wp_error($postID)) { |
| 172 |
$msg['error'] = __pl('post_update_err'); |
| 173 |
}else{ |
| 174 |
$msg['success'] = __pl('post_update_success'); |
| 175 |
} |
| 176 |
|
| 177 |
}else{ |
| 178 |
$msg['error'] = __pl('post_update_err'); |
| 179 |
} |
| 180 |
|
| 181 |
pagelayer_json_output($msg); |
| 182 |
|
| 183 |
} |
| 184 |
|
| 185 |
// Shortcodes Widget Handler |
| 186 |
add_action('wp_ajax_pagelayer_do_shortcodes', 'pagelayer_do_shortcodes'); |
| 187 |
function pagelayer_do_shortcodes(){ |
| 188 |
|
| 189 |
// Some AJAX security |
| 190 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 191 |
|
| 192 |
$data = ''; |
| 193 |
if(isset($_REQUEST['shortcode_data'])){ |
| 194 |
$data = stripslashes($_REQUEST['shortcode_data']); |
| 195 |
} |
| 196 |
|
| 197 |
// Load shortcodes |
| 198 |
pagelayer_load_shortcodes(); |
| 199 |
|
| 200 |
$data = do_shortcode($data); |
| 201 |
|
| 202 |
// Create the HTML object |
| 203 |
$node = pQuery::parseStr($data); |
| 204 |
$node->query('.pagelayer-ele')->removeClass('pagelayer-ele'); |
| 205 |
echo $node->html(); |
| 206 |
|
| 207 |
wp_die(); |
| 208 |
|
| 209 |
} |
| 210 |
|
| 211 |
// Give the JS |
| 212 |
add_action('wp_ajax_pagelayer_givejs', 'pagelayer_givejs'); |
| 213 |
function pagelayer_givejs(){ |
| 214 |
|
| 215 |
global $pagelayer; |
| 216 |
|
| 217 |
// WordPress adds the Expires header in all AJAX calls. We need to remove it for cache to work |
| 218 |
header_remove("Expires"); |
| 219 |
header_remove("Cache-Control"); |
| 220 |
|
| 221 |
// Load shortcodes |
| 222 |
pagelayer_load_shortcodes(); |
| 223 |
|
| 224 |
// Pagelayer Template Loading Mechanism |
| 225 |
include_once(PAGELAYER_DIR.'/js/givejs.php'); |
| 226 |
|
| 227 |
exit(); |
| 228 |
|
| 229 |
} |
| 230 |
|
| 231 |
// Shortcodes Widget Handler |
| 232 |
add_action('wp_ajax_pagelayer_get_section_shortcodes', 'pagelayer_get_section_shortcodes'); |
| 233 |
function pagelayer_get_section_shortcodes(){ |
| 234 |
|
| 235 |
// Some AJAX security |
| 236 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 237 |
|
| 238 |
$data = ''; |
| 239 |
if(isset($_REQUEST['pagelayer_section_id'])){ |
| 240 |
$data = json_decode(file_get_contents(PAGELAYER_API.'/library.php?give_id='.$_REQUEST['pagelayer_section_id']), true); |
| 241 |
} |
| 242 |
|
| 243 |
if(isset($_REQUEST['postID'])){ |
| 244 |
$post_id = (int) $_REQUEST['postID']; |
| 245 |
|
| 246 |
if(!empty($post_id)){ |
| 247 |
$post = get_post( $post_id ); |
| 248 |
// Need to make the reviews post global |
| 249 |
if ( !empty( $post ) ) { |
| 250 |
$GLOBALS['post'] = $post; |
| 251 |
} |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
// Load shortcodes |
| 256 |
pagelayer_load_shortcodes(); |
| 257 |
|
| 258 |
if(!empty($data['code'])){ |
| 259 |
$data['code'] = do_shortcode($data['code']); |
| 260 |
} |
| 261 |
|
| 262 |
pagelayer_json_output($data); |
| 263 |
|
| 264 |
} |
| 265 |
|
| 266 |
// Get the Site Title |
| 267 |
add_action('wp_ajax_pagelayer_fetch_site_title', 'pagelayer_fetch_site_title'); |
| 268 |
function pagelayer_fetch_site_title(){ |
| 269 |
|
| 270 |
// Some AJAX security |
| 271 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 272 |
|
| 273 |
echo get_bloginfo('name'); |
| 274 |
wp_die(); |
| 275 |
} |
| 276 |
|
| 277 |
// Update the Site Title |
| 278 |
add_action('wp_ajax_pagelayer_update_site_title', 'pagelayer_update_site_title'); |
| 279 |
function pagelayer_update_site_title(){ |
| 280 |
global $wpdb; |
| 281 |
|
| 282 |
// Some AJAX security |
| 283 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 284 |
|
| 285 |
$site_title = $_POST['site_title']; |
| 286 |
|
| 287 |
update_option('blogname', $site_title); |
| 288 |
|
| 289 |
$wpdb->query("UPDATE `sm_sitemeta` |
| 290 |
SET meta_value = '".$site_title."' |
| 291 |
WHERE meta_key = 'site_name'"); |
| 292 |
wp_die(); |
| 293 |
} |
| 294 |
|
| 295 |
// Show the SideBars |
| 296 |
add_action('wp_ajax_pagelayer_fetch_sidebar', 'pagelayer_fetch_sidebar'); |
| 297 |
function pagelayer_fetch_sidebar(){ |
| 298 |
|
| 299 |
global $wp_registered_sidebars; |
| 300 |
|
| 301 |
// Some AJAX security |
| 302 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 303 |
|
| 304 |
// Create a list |
| 305 |
$pagelayer_wp_widgets = array(); |
| 306 |
|
| 307 |
foreach($wp_registered_sidebars as $v){ |
| 308 |
$pagelayer_wp_widgets[$v['id']] = $v['name']; |
| 309 |
} |
| 310 |
|
| 311 |
$id = @$_REQUEST['sidebar']; |
| 312 |
|
| 313 |
if(function_exists('dynamic_sidebar') && !empty($pagelayer_wp_widgets[$id])) { |
| 314 |
ob_start(); |
| 315 |
dynamic_sidebar($id); |
| 316 |
$result = ob_get_clean(); |
| 317 |
}else{ |
| 318 |
$result = __pl('no_widget_area'); |
| 319 |
} |
| 320 |
|
| 321 |
echo $result; |
| 322 |
wp_die(); |
| 323 |
|
| 324 |
} |
| 325 |
|
| 326 |
// Show the primary menu ! |
| 327 |
add_action('wp_ajax_pagelayer_fetch_primary_menu', 'pagelayer_fetch_primary_menu'); |
| 328 |
function pagelayer_fetch_primary_menu(){ |
| 329 |
|
| 330 |
// Some AJAX security |
| 331 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 332 |
|
| 333 |
if(isset($_POST['nav_list'])){ |
| 334 |
echo wp_nav_menu([ |
| 335 |
'menu' => wp_get_nav_menu_object($_POST['nav_list']), |
| 336 |
'menu_id' => $_POST["nav_list"], |
| 337 |
'menu_class' => 'pagelayer-wp_menu-ul', |
| 338 |
//'theme_location' => 'primary', |
| 339 |
]); |
| 340 |
} |
| 341 |
|
| 342 |
wp_die(); |
| 343 |
} |
| 344 |
|
| 345 |
// Save post revision |
| 346 |
add_action('wp_ajax_pagelayer_create_post_autosave', 'pagelayer_create_post_autosave'); |
| 347 |
function pagelayer_create_post_autosave(){ |
| 348 |
|
| 349 |
// Some AJAX security |
| 350 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 351 |
|
| 352 |
$postID = (int) $_GET['postID']; |
| 353 |
$post_revisions = array(); |
| 354 |
|
| 355 |
$content = $_REQUEST['pagelayer_post_content']; |
| 356 |
|
| 357 |
if(empty($postID)){ |
| 358 |
$post_revisions['error'] = __pl('invalid_post_id'); |
| 359 |
}else{ |
| 360 |
|
| 361 |
$post = array( |
| 362 |
'post_ID' => $postID, |
| 363 |
'post_content' => $content, |
| 364 |
); |
| 365 |
|
| 366 |
$post_revisions['id'] = wp_create_post_autosave($post); |
| 367 |
} |
| 368 |
|
| 369 |
$post_revisions['url'] = get_preview_post_link($postID); |
| 370 |
|
| 371 |
pagelayer_json_output($post_revisions); |
| 372 |
|
| 373 |
} |
| 374 |
|
| 375 |
// Get post revision |
| 376 |
add_action('wp_ajax_pagelayer_get_revision', 'pagelayer_get_revision'); |
| 377 |
function pagelayer_get_revision(){ |
| 378 |
|
| 379 |
// Some AJAX security |
| 380 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 381 |
|
| 382 |
$postID = (int) $_GET['postID']; |
| 383 |
$post_revisions = array(); |
| 384 |
|
| 385 |
if(empty($postID)){ |
| 386 |
$post_revisions['error'] = __pl('invalid_post_id'); |
| 387 |
}else{ |
| 388 |
$post_revisions = pagelayer_get_post_revision_by_id($postID); |
| 389 |
} |
| 390 |
|
| 391 |
pagelayer_json_output($post_revisions); |
| 392 |
|
| 393 |
} |
| 394 |
|
| 395 |
// Get post revision |
| 396 |
add_action('wp_ajax_pagelayer_apply_revision', 'pagelayer_apply_revision'); |
| 397 |
function pagelayer_apply_revision(){ |
| 398 |
|
| 399 |
// Some AJAX security |
| 400 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 401 |
|
| 402 |
$revisionID = (int) $_REQUEST['revisionID']; |
| 403 |
$post_data = array(); |
| 404 |
|
| 405 |
if(empty($revisionID)){ |
| 406 |
$post_data['error'] = __pl('invalid_post_id'); |
| 407 |
}else{ |
| 408 |
|
| 409 |
$post = get_post( $revisionID ); |
| 410 |
|
| 411 |
if ( empty( $post ) ) { |
| 412 |
$post_data['error'] = __pl('invalid_revision'); |
| 413 |
pagelayer_json_output($post_data); |
| 414 |
} |
| 415 |
|
| 416 |
// Need to make the reviews post global |
| 417 |
$GLOBALS['post'] = $post; |
| 418 |
|
| 419 |
// Need to reload the shortcodes |
| 420 |
pagelayer_load_shortcodes(); |
| 421 |
|
| 422 |
$post_data['content'] = do_shortcode($post->post_content); |
| 423 |
|
| 424 |
if (is_wp_error($postID)) { |
| 425 |
$post_data['error'] = __pl('rev_load_error'); |
| 426 |
}else{ |
| 427 |
$post_data['success'] = __pl('rev_load_success'); |
| 428 |
} |
| 429 |
|
| 430 |
wp_reset_postdata(); |
| 431 |
} |
| 432 |
|
| 433 |
pagelayer_json_output($post_data); |
| 434 |
|
| 435 |
} |
| 436 |
|
| 437 |
// Get post revision |
| 438 |
add_action('wp_ajax_pagelayer_delete_revision', 'pagelayer_delete_revision'); |
| 439 |
function pagelayer_delete_revision() { |
| 440 |
|
| 441 |
// Some AJAX security |
| 442 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 443 |
|
| 444 |
$revisionID = (int) $_REQUEST['revisionID']; |
| 445 |
|
| 446 |
if(empty($revisionID)){ |
| 447 |
$post_data['error'] = __pl('invalid_post_id'); |
| 448 |
}else{ |
| 449 |
|
| 450 |
$revision = get_post( $revisionID ); |
| 451 |
|
| 452 |
if ( empty( $revision ) ) { |
| 453 |
$post_data['error'] = __pl('invalid_revision'); |
| 454 |
}else{ |
| 455 |
|
| 456 |
if ( ! current_user_can( 'delete_post', $revision->ID ) ) { |
| 457 |
$post_data['error'] = __pl('access_denied'); |
| 458 |
pagelayer_json_output($post_data); |
| 459 |
return false; |
| 460 |
} |
| 461 |
|
| 462 |
$deleted = wp_delete_post_revision( $revision->ID ); |
| 463 |
|
| 464 |
if ( ! $deleted || is_wp_error( $deleted ) ) { |
| 465 |
$post_data['error'] = __pl('delete_rev_error'); |
| 466 |
}else{ |
| 467 |
$post_data['success'] = __pl('delete_rev_success'); |
| 468 |
} |
| 469 |
} |
| 470 |
} |
| 471 |
|
| 472 |
pagelayer_json_output($post_data); |
| 473 |
|
| 474 |
} |
| 475 |
|
| 476 |
// Get post revision |
| 477 |
add_action('wp_ajax_pagelayer_post_nav', 'pagelayer_post_nav'); |
| 478 |
function pagelayer_post_nav() { |
| 479 |
|
| 480 |
// Some AJAX security |
| 481 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 482 |
|
| 483 |
if(!isset($_REQUEST['data']) || !isset($_REQUEST['postID'])){ |
| 484 |
return; |
| 485 |
} |
| 486 |
|
| 487 |
$el['atts'] = $_REQUEST['data']; |
| 488 |
|
| 489 |
$post = get_post($_REQUEST['postID']); |
| 490 |
|
| 491 |
// Need to make this post global |
| 492 |
$GLOBALS['post'] = $post; |
| 493 |
|
| 494 |
$in_same_term = false; |
| 495 |
$taxonomies = 'category'; |
| 496 |
$title = ''; |
| 497 |
$arrows_list = $el['atts']['arrows_list']; |
| 498 |
|
| 499 |
if($el['atts']['in_same_term']){ |
| 500 |
$in_same_term = true; |
| 501 |
$taxonomies = $el['atts']['taxonomies']; |
| 502 |
} |
| 503 |
|
| 504 |
if($el['atts']['post_title']){ |
| 505 |
$title = '<span class="pagelayer-post-nav-title">%title</span>'; |
| 506 |
} |
| 507 |
|
| 508 |
$next_label = '<span class="pagelayer-next-holder"> |
| 509 |
<span class="pagelayer-post-nav-link"> '.$el["atts"]["next_label"].'</span>'.$title.' |
| 510 |
</span> |
| 511 |
<span class="pagelayer-post-nav-icon fa fa-'.$arrows_list.'-right"></span>'; |
| 512 |
|
| 513 |
$prev_label = '<span class="pagelayer-post-nav-icon fa fa-'.$arrows_list.'-left"></span> |
| 514 |
<span class="pagelayer-next-holder"> |
| 515 |
<span class="pagelayer-post-nav-link"> '.$el["atts"]["prev_label"].'</span>'.$title.' |
| 516 |
</span>'; |
| 517 |
|
| 518 |
$el['atts']['next_link'] = get_next_post_link('%link', $next_label, $in_same_term, '', $taxonomies); |
| 519 |
|
| 520 |
$el['atts']['prev_link'] = get_previous_post_link('%link', $prev_label, $in_same_term, '', $taxonomies ); |
| 521 |
|
| 522 |
pagelayer_json_output($el); |
| 523 |
|
| 524 |
} |
| 525 |
|
| 526 |
// Get post comment template |
| 527 |
add_action('wp_ajax_pagelayer_post_comment', 'pagelayer_post_comment'); |
| 528 |
function pagelayer_post_comment() { |
| 529 |
global $post; |
| 530 |
|
| 531 |
// Some AJAX security |
| 532 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 533 |
|
| 534 |
if(!isset($_REQUEST['postID'])){ |
| 535 |
return true; |
| 536 |
} |
| 537 |
|
| 538 |
$GLOBALS['post'] = get_post($_REQUEST['postID']); |
| 539 |
$GLOBALS['withcomments'] = true; |
| 540 |
|
| 541 |
if ( comments_open() || get_comments_number() ) { |
| 542 |
echo '<div class="pagelayer-comments-template">'.comments_template().'</div>'; |
| 543 |
}else{ |
| 544 |
echo '<div class="pagelayer-comments-close"> |
| 545 |
<h2>Comments are closed!</h2> |
| 546 |
</div>'; |
| 547 |
} |
| 548 |
wp_die(); |
| 549 |
|
| 550 |
} |
| 551 |
|
| 552 |
// Get post comment template |
| 553 |
add_action('wp_ajax_pagelayer_post_info', 'pagelayer_post_info'); |
| 554 |
function pagelayer_post_info() { |
| 555 |
global $post; |
| 556 |
|
| 557 |
// Some AJAX security |
| 558 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 559 |
|
| 560 |
if(!isset($_REQUEST['postID']) || !isset($_REQUEST['el'])){ |
| 561 |
return true; |
| 562 |
} |
| 563 |
|
| 564 |
$el['atts'] = $_REQUEST['el']; |
| 565 |
|
| 566 |
$GLOBALS['post'] = get_post($_REQUEST['postID']); |
| 567 |
|
| 568 |
$post_info_content =''; |
| 569 |
$link =''; |
| 570 |
$info_content =''; |
| 571 |
$avatar_url =''; |
| 572 |
|
| 573 |
switch($el['atts']['type']){ |
| 574 |
case 'author': |
| 575 |
|
| 576 |
$link = get_author_posts_url( get_the_author_meta( 'ID' ) ); |
| 577 |
$avatar_url = get_avatar_url( get_the_author_meta( 'ID' ), 96 ); |
| 578 |
$post_info_content = get_the_author_meta( 'display_name', $post->post_author ); |
| 579 |
break; |
| 580 |
|
| 581 |
case 'date': |
| 582 |
|
| 583 |
$format = [ |
| 584 |
'default' => 'F j, Y', |
| 585 |
'0' => 'F j, Y', |
| 586 |
'1' => 'Y-m-d', |
| 587 |
'2' => 'm/d/Y', |
| 588 |
'3' => 'd/m/Y', |
| 589 |
'custom' => empty( $el['atts']['date_format_custom'] ) ? 'F j, Y' : $el['atts']['date_format_custom'], |
| 590 |
]; |
| 591 |
|
| 592 |
$post_info_content = get_the_time( $format[ $el['atts']['date_format'] ] ); |
| 593 |
$link = get_day_link( get_post_time( 'Y' ), get_post_time( 'm' ), get_post_time( 'j' ) ); |
| 594 |
|
| 595 |
break; |
| 596 |
|
| 597 |
case 'time': |
| 598 |
|
| 599 |
$format = [ |
| 600 |
'default' => 'g:i a', |
| 601 |
'0' => 'g:i a', |
| 602 |
'1' => 'g:i A', |
| 603 |
'2' => 'H:i', |
| 604 |
'custom' => empty( $el['atts']['time_format_custom'] ) ? 'F j, Y' : $el['atts']['time_format_custom'], |
| 605 |
]; |
| 606 |
$post_info_content = get_the_time( $format[ $el['atts']['time_format'] ] ); |
| 607 |
|
| 608 |
break; |
| 609 |
|
| 610 |
case 'comments': |
| 611 |
|
| 612 |
if (comments_open()) { |
| 613 |
$post_info_content = (int) get_comments_number(); |
| 614 |
$link = get_comments_link(); |
| 615 |
} |
| 616 |
|
| 617 |
break; |
| 618 |
|
| 619 |
case 'terms': |
| 620 |
|
| 621 |
$taxonomy = $el['atts']['taxonomy']; |
| 622 |
$terms = wp_get_post_terms( get_the_ID(), $taxonomy ); |
| 623 |
foreach ( $terms as $term ) { |
| 624 |
$post_info_content .= ' <a if-ext="{{info_link}}" href="'. get_term_link( $term ) .'" class="pagelayer-post-info-list-link"> '. $term->name .' </a>'; |
| 625 |
} |
| 626 |
|
| 627 |
break; |
| 628 |
|
| 629 |
case 'custom': |
| 630 |
|
| 631 |
$post_info_content = $el['atts']['type_custom']; |
| 632 |
$link = $el['atts']['info_custom_link']; |
| 633 |
|
| 634 |
break; |
| 635 |
} |
| 636 |
|
| 637 |
$el['atts']['post_info_content'] = $post_info_content; |
| 638 |
$el['atts']['avatar_url'] = $avatar_url; |
| 639 |
$el['atts']['link'] = $link; |
| 640 |
|
| 641 |
pagelayer_json_output($el['atts']); |
| 642 |
|
| 643 |
} |
| 644 |
|
| 645 |
// Get the Featured Image |
| 646 |
add_action('wp_ajax_pagelayer_fetch_featured_img', 'pagelayer_fetch_featured_img'); |
| 647 |
function pagelayer_fetch_featured_img(){ |
| 648 |
|
| 649 |
// Some AJAX security |
| 650 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 651 |
|
| 652 |
if($_POST['size']){ |
| 653 |
echo get_the_post_thumbnail_url($_POST['post_id'], $_POST['size']); |
| 654 |
}else{ |
| 655 |
echo get_the_post_thumbnail_url($_POST['post_id']); |
| 656 |
} |
| 657 |
wp_die(); |
| 658 |
} |
| 659 |
|
| 660 |
// Get the postfolio posts |
| 661 |
add_action('wp_ajax_pagelayer_fetch_posts', 'pagelayer_fetch_posts'); |
| 662 |
function pagelayer_fetch_posts(){ |
| 663 |
|
| 664 |
// Some AJAX security |
| 665 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 666 |
|
| 667 |
echo pagelayer_widget_posts($_POST); |
| 668 |
|
| 669 |
wp_die(); |
| 670 |
} |
| 671 |
|
| 672 |
// Get the Posts |
| 673 |
add_action('wp_ajax_pagelayer_posts_data', 'pagelayer_posts_data'); |
| 674 |
function pagelayer_posts_data(){ |
| 675 |
|
| 676 |
// Some AJAX security |
| 677 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 678 |
|
| 679 |
// Load shortcodes |
| 680 |
pagelayer_load_shortcodes(); |
| 681 |
|
| 682 |
echo pagelayer_posts($_POST); |
| 683 |
wp_die(); |
| 684 |
} |
| 685 |
|
| 686 |
// Get the Posts |
| 687 |
add_action('wp_ajax_pagelayer_archive_posts_data', 'pagelayer_archive_posts_data'); |
| 688 |
function pagelayer_archive_posts_data(){ |
| 689 |
|
| 690 |
// Some AJAX security |
| 691 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 692 |
|
| 693 |
// Set excerpt length |
| 694 |
if($_POST['exc_length']){ |
| 695 |
$exc_length = (int) $params['exc_length']; |
| 696 |
add_filter( 'excerpt_length', function($length) use($exc_length){ |
| 697 |
return $exc_length; |
| 698 |
}, 999 ); |
| 699 |
} |
| 700 |
|
| 701 |
// Load shortcodes |
| 702 |
pagelayer_load_shortcodes(); |
| 703 |
|
| 704 |
echo pagelayer_posts($_POST, $_POST['pagelayer_wp_query']); |
| 705 |
wp_die(); |
| 706 |
} |
| 707 |
|
| 708 |
// Handle Contact Form Data |
| 709 |
add_action('wp_ajax_pagelayer_contact_submit', 'pagelayer_contact_submit'); |
| 710 |
add_action('wp_ajax_nopriv_pagelayer_contact_submit', 'pagelayer_contact_submit' ); |
| 711 |
function pagelayer_contact_submit(){ |
| 712 |
|
| 713 |
$to_mail = get_option('pagelayer_cf_to_email'); |
| 714 |
$subject = get_option('pagelayer_cf_subject'); |
| 715 |
|
| 716 |
$fdata = $_POST['form_data']; |
| 717 |
parse_str($fdata, $formdata); |
| 718 |
|
| 719 |
// Make the email content |
| 720 |
foreach($formdata as $k => $i){ |
| 721 |
$data .= ''.$k.'\t : \t'.$i.'\n'; |
| 722 |
} |
| 723 |
|
| 724 |
// Send the email |
| 725 |
$r = wp_mail( $to_mail, $subject, $data ); |
| 726 |
|
| 727 |
if($r == TRUE){ |
| 728 |
$wp['success'] = get_option( 'pagelayer_cf_success' ); |
| 729 |
}else{ |
| 730 |
$wp['failed'] = get_option( 'pagelayer_cf_failed' ); |
| 731 |
} |
| 732 |
|
| 733 |
pagelayer_json_output($wp); |
| 734 |
|
| 735 |
} |
| 736 |
|
| 737 |
// Fetch Google reCaptcha Key |
| 738 |
add_action('wp_ajax_pagelayer_fetch_grecaptcha_key', 'pagelayer_fetch_grecaptcha_key'); |
| 739 |
function pagelayer_fetch_grecaptcha_key(){ |
| 740 |
|
| 741 |
$data['key'] = get_option('pagelayer_google_captcha'); |
| 742 |
|
| 743 |
pagelayer_json_output($data); |
| 744 |
|
| 745 |
} |
| 746 |
|
| 747 |
// Handle Login Submit |
| 748 |
add_action('wp_ajax_pagelayer_login_submit', 'pagelayer_login_submit'); |
| 749 |
add_action('wp_ajax_nopriv_pagelayer_login_submit', 'pagelayer_login_submit'); |
| 750 |
function pagelayer_login_submit(){ |
| 751 |
|
| 752 |
$fdata = $_POST['form_data']; |
| 753 |
parse_str($fdata, $formdata); |
| 754 |
|
| 755 |
$creds = array(); |
| 756 |
$creds['user_login'] = $formdata['username']; |
| 757 |
$creds['user_password'] = $formdata['password']; |
| 758 |
$creds['remember'] = $formdata['remember_me']; |
| 759 |
|
| 760 |
// If After logout URL, then save |
| 761 |
if(!empty($formdata['logout_url'])){ |
| 762 |
update_user_option('pagelayer_logout_url', $formdata['logout_url']); |
| 763 |
} |
| 764 |
|
| 765 |
// Login the user |
| 766 |
$user = wp_signon( $creds, false ); |
| 767 |
|
| 768 |
if ( is_wp_error($user) ){ |
| 769 |
$data['error'] = $user->get_error_message(); |
| 770 |
}else{ |
| 771 |
$data['redirect'] = (empty($formdata['login_url']) ? '' : $formdata['login_url']); |
| 772 |
$data['error'] = ''; |
| 773 |
} |
| 774 |
|
| 775 |
pagelayer_json_output($data); |
| 776 |
|
| 777 |
} |
| 778 |
|
| 779 |
// Handle Logout Redirect here |
| 780 |
add_action('wp_logout', 'pagelayer_after_logout'); |
| 781 |
function pagelayer_after_logout(){ |
| 782 |
|
| 783 |
$url = get_user_option('pagelayer_logout_url'); |
| 784 |
|
| 785 |
// We will redirect if we have the given item set. |
| 786 |
if(!empty($url)){ |
| 787 |
wp_redirect( $url ); |
| 788 |
exit(); |
| 789 |
} |
| 790 |
|
| 791 |
} |
| 792 |
|
| 793 |
// Get Page List for SiteMap |
| 794 |
add_action('wp_ajax_pagelayer_get_pages_list', 'pagelayer_get_pages_list'); |
| 795 |
add_action('wp_ajax_nopriv_pagelayer_get_pages_list', 'pagelayer_get_pages_list'); |
| 796 |
function pagelayer_get_pages_list(){ |
| 797 |
|
| 798 |
$args = array( |
| 799 |
'post_type' => $_POST['type'], |
| 800 |
'orderby' => $_POST['post_order'], |
| 801 |
'order' => $_POST['order'], |
| 802 |
'hierarchical' => (empty($_POST['hier']) || $_POST['hier'] == null ? '' : $_POST['hier']), |
| 803 |
'number' => (empty($_POST['depth']) || $_POST['depth'] == null ? '' : $_POST['depth']), |
| 804 |
); |
| 805 |
|
| 806 |
$option = '<ul>'; |
| 807 |
$pages = new WP_Query($args); |
| 808 |
$posts = $pages->posts; |
| 809 |
foreach ( $posts as $page ) { |
| 810 |
$option .= '<li class="pagelayer-sitemap-list-item" data-postID="'.$page->ID.'"><a class="pagelayer-ele-link" href="'.$page->guid.'">'.$page->post_name.'</a></li>'; |
| 811 |
} |
| 812 |
$option .= '</ul>'; |
| 813 |
|
| 814 |
|
| 815 |
echo $option; |
| 816 |
|
| 817 |
wp_die(); |
| 818 |
} |
| 819 |
|
| 820 |
// Get the data for template |
| 821 |
add_action('wp_ajax_pagelayer_search_ids', 'pagelayer_search_ids'); |
| 822 |
function pagelayer_search_ids() { |
| 823 |
|
| 824 |
// Some AJAX security |
| 825 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 826 |
|
| 827 |
if ( empty( $_POST['filter_type'] ) || empty( $_POST['search'] ) ) { |
| 828 |
wp_die(); |
| 829 |
} |
| 830 |
|
| 831 |
$sel_opt = ''; |
| 832 |
|
| 833 |
switch ( $_POST['filter_type'] ) { |
| 834 |
case 'taxonomy': |
| 835 |
$query_params = [ |
| 836 |
'taxonomy' => $_POST['object_type'], |
| 837 |
'search' => $_POST['search'], |
| 838 |
'hide_empty' => false, |
| 839 |
]; |
| 840 |
|
| 841 |
$terms = get_terms( $query_params ); |
| 842 |
|
| 843 |
global $wp_taxonomies; |
| 844 |
|
| 845 |
foreach ( $terms as $term ) { |
| 846 |
$sel_opt .= '<span class="pagelayer-temp-search-sel-span" value="'. $term->term_taxonomy_id .'">'. $term->name .'</span>'; |
| 847 |
} |
| 848 |
|
| 849 |
break; |
| 850 |
|
| 851 |
case 'post': |
| 852 |
$query_params = [ |
| 853 |
'post_type' => $_POST['object_type'], //$this->extract_post_type( $data ), |
| 854 |
's' => $_POST['search'], |
| 855 |
'posts_per_page' => -1, |
| 856 |
]; |
| 857 |
|
| 858 |
if ( 'attachment' === $query_params['post_type'] ) { |
| 859 |
$query_params['post_status'] = 'inherit'; |
| 860 |
} |
| 861 |
|
| 862 |
$query = new \WP_Query( $query_params ); |
| 863 |
|
| 864 |
foreach ( $query->posts as $post ) { |
| 865 |
$sel_opt .= '<span class="pagelayer-temp-search-sel-span" value="'. $post->ID .'">'. $post->post_title .'</span>'; |
| 866 |
} |
| 867 |
break; |
| 868 |
|
| 869 |
case 'author': |
| 870 |
$query_params = [ |
| 871 |
'who' => 'authors', |
| 872 |
'fields' => [ |
| 873 |
'ID', |
| 874 |
'display_name', |
| 875 |
], |
| 876 |
'search' => '*' . $_POST["search"] . '*', |
| 877 |
'search_columns' => [ |
| 878 |
'user_login', |
| 879 |
'user_nicename', |
| 880 |
], |
| 881 |
]; |
| 882 |
|
| 883 |
$user_query = new \WP_User_Query( $query_params ); |
| 884 |
|
| 885 |
foreach ( $user_query->get_results() as $author ) { |
| 886 |
$sel_opt .= '<span class="pagelayer-temp-search-sel-span" value="'. $author->ID .'">'. $author->display_name .'</span>'; |
| 887 |
} |
| 888 |
break; |
| 889 |
default: |
| 890 |
$sel_opt = 'Result Not Found'; |
| 891 |
} |
| 892 |
|
| 893 |
if(!empty($sel_opt)){ |
| 894 |
echo $sel_opt; |
| 895 |
}else{ |
| 896 |
echo 'Result Not Found'; |
| 897 |
} |
| 898 |
|
| 899 |
wp_die(); |
| 900 |
} |
| 901 |
|
| 902 |
|
| 903 |
// Save the post data from pagelayer setting page |
| 904 |
add_action('wp_ajax_pagelayer_save_template', 'pagelayer_save_template'); |
| 905 |
function pagelayer_save_template() { |
| 906 |
|
| 907 |
// Some AJAX security |
| 908 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 909 |
|
| 910 |
$done = []; |
| 911 |
|
| 912 |
$post_id = (int) $_GET['postID']; |
| 913 |
|
| 914 |
// We need to create the post |
| 915 |
if(empty($post_id)){ |
| 916 |
|
| 917 |
// Get the template type |
| 918 |
if(empty($_POST['pagelayer_template_type'])){ |
| 919 |
$done['error'] = __pl('temp_error_type'); |
| 920 |
pagelayer_json_output($done); |
| 921 |
} |
| 922 |
|
| 923 |
$ret = wp_insert_post([ |
| 924 |
'post_title' => $_POST['pagelayer_lib_title'], |
| 925 |
'post_type' => 'pagelayer-template', |
| 926 |
'post_status' => 'publish', |
| 927 |
'comment_status' => 'closed', |
| 928 |
'ping_status' => 'closed' |
| 929 |
]); |
| 930 |
|
| 931 |
// An error occured |
| 932 |
if(is_wp_error($ret)){ |
| 933 |
$done['error'] = __pl('temp_error').' : '.$ret->get_error_message(); |
| 934 |
pagelayer_json_output($done); |
| 935 |
} |
| 936 |
|
| 937 |
$post_id = $ret; |
| 938 |
$done['id'] = $post_id; |
| 939 |
|
| 940 |
// Save our template type |
| 941 |
$ret = update_post_meta($post_id, 'pagelayer_template_type', $_POST['pagelayer_template_type']); |
| 942 |
|
| 943 |
} |
| 944 |
|
| 945 |
// The ID in consideration |
| 946 |
$done['id'] = $post_id; |
| 947 |
|
| 948 |
// Check if the post title in not empty |
| 949 |
if(!empty($_POST['pagelayer_lib_title'])){ |
| 950 |
|
| 951 |
$post = array( |
| 952 |
'ID' => $post_id, |
| 953 |
'post_title' => $_POST['pagelayer_lib_title'], |
| 954 |
); |
| 955 |
|
| 956 |
// Update the post into the database |
| 957 |
$ret = wp_update_post($post); |
| 958 |
|
| 959 |
} |
| 960 |
|
| 961 |
// Save template library display conditions |
| 962 |
$condi_array = array(); |
| 963 |
$condi_len = count($_POST['pagelayer_condition_type']); |
| 964 |
if($_POST['pagelayer_template_type'] != 'section'){ |
| 965 |
for( $i =0; $i < $condi_len; $i++ ){ |
| 966 |
$condi_array[$i] = array( |
| 967 |
'type' => $_POST['pagelayer_condition_type'][$i], |
| 968 |
'template' => $_POST['pagelayer_condition_name'][$i], |
| 969 |
'sub_template' => $_POST['pagelayer_condition_sub_template'][$i], |
| 970 |
'id' => $_POST['pagelayer_condition_id'][$i], |
| 971 |
); |
| 972 |
} |
| 973 |
} |
| 974 |
//print_r($condi_array); |
| 975 |
|
| 976 |
$ret = update_post_meta($post_id, 'pagelayer_template_conditions', $condi_array); |
| 977 |
|
| 978 |
if(is_wp_error($post_id)){ |
| 979 |
$done['error'] = __pl('temp_error').' : '.$ret->get_error_message(); |
| 980 |
}else{ |
| 981 |
$done['success'] = __pl('temp_update_success'); |
| 982 |
} |
| 983 |
|
| 984 |
pagelayer_json_output($done); |
| 985 |
|
| 986 |
} |
| 987 |
|
| 988 |
// Product Images Handler |
| 989 |
add_action('wp_ajax_pagelayer_product_images', 'pagelayer_product_images'); |
| 990 |
function pagelayer_product_images(){ |
| 991 |
global $product; |
| 992 |
|
| 993 |
// Some AJAX security |
| 994 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 995 |
|
| 996 |
if ( !isset($_REQUEST['postID']) ) { |
| 997 |
return; |
| 998 |
} |
| 999 |
|
| 1000 |
$product = wc_get_product($_REQUEST['postID']); |
| 1001 |
|
| 1002 |
if ( empty( $product ) ) { |
| 1003 |
return ; |
| 1004 |
} |
| 1005 |
|
| 1006 |
if ( isset($_POST['sale_flash']) ) { |
| 1007 |
wc_get_template( 'loop/sale-flash.php' ); |
| 1008 |
} |
| 1009 |
wc_get_template( 'single-product/product-image.php' ); |
| 1010 |
|
| 1011 |
// On render widget from Editor - trigger the init manually. |
| 1012 |
echo ' |
| 1013 |
<script> |
| 1014 |
jQuery(".woocommerce-product-gallery").each( function() { |
| 1015 |
jQuery(this).wc_product_gallery(); |
| 1016 |
} ); |
| 1017 |
</script> |
| 1018 |
'; |
| 1019 |
|
| 1020 |
wp_die(); |
| 1021 |
} |
| 1022 |
|
| 1023 |
// Related Products Handler |
| 1024 |
add_action('wp_ajax_pagelayer_product_related', 'pagelayer_product_related'); |
| 1025 |
function pagelayer_product_related(){ |
| 1026 |
global $product; |
| 1027 |
|
| 1028 |
// Some AJAX security |
| 1029 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1030 |
|
| 1031 |
if ( !isset($_REQUEST['postID']) ) { |
| 1032 |
return; |
| 1033 |
} |
| 1034 |
|
| 1035 |
$product = wc_get_product($_REQUEST['postID']); |
| 1036 |
|
| 1037 |
if ( empty( $product ) ) { |
| 1038 |
return ; |
| 1039 |
} |
| 1040 |
|
| 1041 |
$args = $_REQUEST['pagelayer_args']; |
| 1042 |
|
| 1043 |
if(function_exists( 'woocommerce_related_products' )){ |
| 1044 |
woocommerce_related_products($args); |
| 1045 |
} |
| 1046 |
|
| 1047 |
wp_die(); |
| 1048 |
} |
| 1049 |
|
| 1050 |
// Upsell Products Handler |
| 1051 |
add_action('wp_ajax_pagelayer_product_upsell', 'pagelayer_product_upsell'); |
| 1052 |
function pagelayer_product_upsell(){ |
| 1053 |
global $product; |
| 1054 |
|
| 1055 |
// Some AJAX security |
| 1056 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1057 |
|
| 1058 |
if ( !isset($_REQUEST['postID']) ) { |
| 1059 |
return; |
| 1060 |
} |
| 1061 |
|
| 1062 |
$product = wc_get_product($_REQUEST['postID']); |
| 1063 |
|
| 1064 |
if ( empty( $product ) ) { |
| 1065 |
return ; |
| 1066 |
} |
| 1067 |
|
| 1068 |
if(function_exists( 'woocommerce_related_products' )){ |
| 1069 |
woocommerce_upsell_display( $_REQUEST['limit'], $_REQUEST['columns'], $_REQUEST['orderby'], $_REQUEST['order'] ); |
| 1070 |
} |
| 1071 |
|
| 1072 |
wp_die(); |
| 1073 |
} |
| 1074 |
|
| 1075 |
// Products Categories Handler |
| 1076 |
add_action('wp_ajax_pagelayer_product_categories', 'pagelayer_product_categories'); |
| 1077 |
function pagelayer_product_categories(){ |
| 1078 |
|
| 1079 |
// Some AJAX security |
| 1080 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1081 |
|
| 1082 |
$attributes = ''; |
| 1083 |
$attributes .= ' number="'. $_POST['atts']['number'] .'" '; |
| 1084 |
$attributes .= ' columns="'. $_POST['atts']['columns'] .'" '; |
| 1085 |
$attributes .= ' hide_empty="'. (!empty($_POST['atts']['hide_empty']) ? 1 : 0) .'" '; |
| 1086 |
$attributes .= ' orderby="'. $_POST['atts']['nuorderbymber'] .'" '; |
| 1087 |
$attributes .= ' order="'. $_POST['atts']['order'] .'" '; |
| 1088 |
|
| 1089 |
if ( 'by_id' === $_POST['atts']['source'] ) { |
| 1090 |
$attributes .= ' ids="'. $_POST['atts']['by_id'] .'" '; |
| 1091 |
} elseif ( 'by_parent' === $_POST['atts']['source'] ) { |
| 1092 |
$attributes .= ' parent="'. $_POST['atts']['parent'] .'" '; |
| 1093 |
} elseif ( 'current_subcategories' === $_POST['atts']['source'] ) { |
| 1094 |
$attributes .= ' parent="'. get_queried_object_id() .'" '; |
| 1095 |
} |
| 1096 |
|
| 1097 |
$shortcode = '[product_categories '. $attributes .']'; |
| 1098 |
|
| 1099 |
// do_shortcode the shortcode |
| 1100 |
echo do_shortcode($shortcode); |
| 1101 |
|
| 1102 |
wp_die(); |
| 1103 |
} |
| 1104 |
|
| 1105 |
// Products Categories Handler |
| 1106 |
add_action('wp_ajax_pagelayer_product_archives', 'pagelayer_product_archives'); |
| 1107 |
function pagelayer_product_archives(){ |
| 1108 |
|
| 1109 |
// Some AJAX security |
| 1110 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1111 |
|
| 1112 |
if ( WC()->session ) { |
| 1113 |
wc_print_notices(); |
| 1114 |
} |
| 1115 |
|
| 1116 |
$atts['paginate'] = true; |
| 1117 |
$atts['cache'] = false; |
| 1118 |
$no_found = $_POST['atts']['no_found']; |
| 1119 |
|
| 1120 |
if( empty($_POST['atts']['allow_order']) ){ |
| 1121 |
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 ); |
| 1122 |
} |
| 1123 |
if( empty($_POST['atts']['show_result']) ){ |
| 1124 |
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); |
| 1125 |
} |
| 1126 |
|
| 1127 |
$type = 'pagelayer_current_query'; |
| 1128 |
|
| 1129 |
// Set the current query |
| 1130 |
add_action( 'woocommerce_shortcode_products_query', 'pagelayer_shortcode_current_query', 10, 10); |
| 1131 |
|
| 1132 |
// If product not found |
| 1133 |
add_action( "woocommerce_shortcode_{$type}_loop_no_results", function ($attributes) use ($no_found){ |
| 1134 |
echo '<div class="pagelayer-product-no-found">'.$no_found.'</div>'; |
| 1135 |
} ); |
| 1136 |
|
| 1137 |
// Get the products list |
| 1138 |
$shortcode = new WC_Shortcode_Products( $atts, $type ); |
| 1139 |
|
| 1140 |
echo $shortcode->get_content(); |
| 1141 |
|
| 1142 |
wp_die(); |
| 1143 |
} |
| 1144 |
|
| 1145 |
// Products Categories Handler |
| 1146 |
add_action('wp_ajax_pagelayer_products_ajax', 'pagelayer_products_ajax'); |
| 1147 |
function pagelayer_products_ajax(){ |
| 1148 |
|
| 1149 |
// Some AJAX security |
| 1150 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1151 |
|
| 1152 |
if ( WC()->session ) { |
| 1153 |
wc_print_notices(); |
| 1154 |
} |
| 1155 |
|
| 1156 |
$no_found = $_POST['atts']['no_found']; |
| 1157 |
|
| 1158 |
$attributes = ''; |
| 1159 |
$type = $_POST['atts']['source']; |
| 1160 |
$attributes .= ' columns="'. $_POST['atts']['columns'] .'" '; |
| 1161 |
$attributes .= ' rows="'. $_POST['atts']['rows'] .'" '; |
| 1162 |
$attributes .= ' paginate="'. (!empty($_POST['atts']['paginate']) ? true : false) .'" '; |
| 1163 |
$attributes .= ' orderby="'. $_POST['atts']['orderby'] .'" '; |
| 1164 |
$attributes .= ' order="'. $_POST['atts']['order'] .'" '; |
| 1165 |
$attributes .= ' cache="false" '; |
| 1166 |
|
| 1167 |
// Hide the catalog order |
| 1168 |
if( empty($_POST['atts']['allow_order']) ){ |
| 1169 |
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_catalog_ordering', 30 ); |
| 1170 |
} |
| 1171 |
|
| 1172 |
// Hide the result count |
| 1173 |
if( empty($_POST['atts']['show_result']) ){ |
| 1174 |
remove_action( 'woocommerce_before_shop_loop', 'woocommerce_result_count', 20 ); |
| 1175 |
} |
| 1176 |
|
| 1177 |
if( $type == 'by_id' ){ |
| 1178 |
$type = 'products'; |
| 1179 |
$attributes .= ' ids="'. (!empty($_POST['atts']['ids']) ? $_POST['atts']['ids'] : '') .'" '; |
| 1180 |
}elseif( $type == 'pagelayer_current_query' ){ |
| 1181 |
|
| 1182 |
$atts['paginate'] = (!empty($_POST['atts']['paginate']) ? true : false); |
| 1183 |
$atts['cache'] = false; |
| 1184 |
|
| 1185 |
$type = 'pagelayer_current_query'; |
| 1186 |
|
| 1187 |
// Set the current query |
| 1188 |
add_action( 'woocommerce_shortcode_products_query', 'pagelayer_shortcode_current_query', 10, 10); |
| 1189 |
|
| 1190 |
// If product not found |
| 1191 |
add_action( "woocommerce_shortcode_{$type}_loop_no_results", function ($attributes) use ($no_found){ |
| 1192 |
echo '<div class="pagelayer-product-no-found">'.$no_found.'</div>'; |
| 1193 |
} ); |
| 1194 |
|
| 1195 |
// Get the products list |
| 1196 |
$shortcode = new WC_Shortcode_Products( $atts, $type ); |
| 1197 |
|
| 1198 |
echo $shortcode->get_content(); |
| 1199 |
return true; |
| 1200 |
} |
| 1201 |
|
| 1202 |
$shortcode = '['.$type.' '. $attributes .']'; |
| 1203 |
|
| 1204 |
$content = do_shortcode($shortcode); |
| 1205 |
|
| 1206 |
// If product not found |
| 1207 |
if('<div class="woocommerce columns-'.$_POST['atts']['columns'] .' "></div>' == $content){ |
| 1208 |
$content = '<div class="pagelayer-product-no-found">'. $no_found .'</div>'; |
| 1209 |
} |
| 1210 |
|
| 1211 |
echo $content; |
| 1212 |
|
| 1213 |
wp_die(); |
| 1214 |
} |
| 1215 |
|
| 1216 |
// Get Taxamony List for SiteMap |
| 1217 |
add_action('wp_ajax_pagelayer_get_taxonomy_list', 'pagelayer_get_taxonomy_list'); |
| 1218 |
add_action('wp_ajax_nopriv_pagelayer_get_taxonomy_list', 'pagelayer_get_taxonomy_list'); |
| 1219 |
function pagelayer_get_taxonomy_list(){ |
| 1220 |
|
| 1221 |
$args = array( |
| 1222 |
'title_li' => 0, |
| 1223 |
'orderby' => $_POST['post_order'], |
| 1224 |
'order' => $_POST['order'], |
| 1225 |
'style' => '', |
| 1226 |
'hide_empty' => $_POST['empty'], |
| 1227 |
'echo' => false, |
| 1228 |
'hierarchical' => (empty($_POST['hier']) || $_POST['hier'] == null ? '' : $_POST['hier']), |
| 1229 |
'taxonomy' => $_POST['type'], |
| 1230 |
'depth' => (empty($_POST['depth']) || $_POST['depth'] == null ? '' : $_POST['depth']), |
| 1231 |
); |
| 1232 |
|
| 1233 |
$taxonomies = get_categories( $args ); |
| 1234 |
|
| 1235 |
$option = '<ul>'; |
| 1236 |
foreach ( $taxonomies as $taxonomy ) { |
| 1237 |
$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>'; |
| 1238 |
} |
| 1239 |
$option .= '</ul>'; |
| 1240 |
|
| 1241 |
echo $option; |
| 1242 |
wp_die(); |
| 1243 |
} |
| 1244 |
|
| 1245 |
// Export the template |
| 1246 |
add_action('wp_ajax_pagelayer_export_template', 'pagelayer_export_template'); |
| 1247 |
function pagelayer_export_template(){ |
| 1248 |
|
| 1249 |
global $pagelayer; |
| 1250 |
|
| 1251 |
// Some AJAX security |
| 1252 |
check_ajax_referer('pagelayer_ajax', 'pagelayer_nonce'); |
| 1253 |
|
| 1254 |
$done = []; |
| 1255 |
|
| 1256 |
// Load the templates |
| 1257 |
pagelayer_builder_load_templates(); |
| 1258 |
|
| 1259 |
if(empty($pagelayer->templates)){ |
| 1260 |
$done['error'] = __pl('temp_export_empty'); |
| 1261 |
pagelayer_json_output($done); |
| 1262 |
} |
| 1263 |
|
| 1264 |
// Get the active theme |
| 1265 |
$theme_dir = get_stylesheet_directory(); |
| 1266 |
$conf = []; |
| 1267 |
|
| 1268 |
$pagelayer->export_mode = 1; |
| 1269 |
|
| 1270 |
// Write the files |
| 1271 |
foreach($pagelayer->templates as $k => $v){ |
| 1272 |
|
| 1273 |
// Are there specific templates to export |
| 1274 |
if(!empty($_POST['templates'])){ |
| 1275 |
if(!isset($_POST['templates'][$v->ID])){ |
| 1276 |
continue; |
| 1277 |
} |
| 1278 |
} |
| 1279 |
|
| 1280 |
file_put_contents($theme_dir.'/'.$v->post_name.'.pgl', pagelayer_export_content($v->post_content)); |
| 1281 |
$conf[$v->post_name] = [ |
| 1282 |
'type' => get_post_meta($v->ID, 'pagelayer_template_type', true), |
| 1283 |
'title' => $v->post_title, |
| 1284 |
'conditions' => get_post_meta($v->ID, 'pagelayer_template_conditions', true), |
| 1285 |
]; |
| 1286 |
} |
| 1287 |
|
| 1288 |
// Write the config |
| 1289 |
file_put_contents($theme_dir.'/pagelayer.conf', json_encode($conf, JSON_PRETTY_PRINT)); |
| 1290 |
|
| 1291 |
// Any pages to export for users ? |
| 1292 |
if(!empty($_POST['pages'])){ |
| 1293 |
|
| 1294 |
mkdir($theme_dir.'/data/'); |
| 1295 |
mkdir($theme_dir.'/data/page'); |
| 1296 |
|
| 1297 |
$conf = []; |
| 1298 |
|
| 1299 |
// Load the pages |
| 1300 |
$pages_query = new WP_Query(['post_type' => 'page', 'status' => 'publish']); |
| 1301 |
$pages = $pages_query->posts; |
| 1302 |
|
| 1303 |
// Write the files |
| 1304 |
foreach($pages as $k => $v){ |
| 1305 |
|
| 1306 |
if(!isset($_POST['pages'][$v->ID])){ |
| 1307 |
continue; |
| 1308 |
} |
| 1309 |
|
| 1310 |
file_put_contents($theme_dir.'/data/page/'.$v->post_name, pagelayer_export_content($v->post_content)); |
| 1311 |
unset($v->post_content); |
| 1312 |
$conf['page'][$v->post_name] = $v; |
| 1313 |
|
| 1314 |
} |
| 1315 |
|
| 1316 |
// Write the config |
| 1317 |
file_put_contents($theme_dir.'/pagelayer-data.conf', json_encode($conf, JSON_PRETTY_PRINT)); |
| 1318 |
|
| 1319 |
} |
| 1320 |
|
| 1321 |
// Are we to export any media ? |
| 1322 |
if(!empty($pagelayer->media_to_export)){ |
| 1323 |
// TODO |
| 1324 |
//$done['media'] = $pagelayer->media_to_export; |
| 1325 |
} |
| 1326 |
|
| 1327 |
$done['success'] = __pl('temp_export_success'); |
| 1328 |
|
| 1329 |
// Output and die |
| 1330 |
pagelayer_json_output($done); |
| 1331 |
|
| 1332 |
} |
| 1333 |
|