PluginProbe
Page Builder: Pagelayer – Drag and Drop website builder / 2.2.1
Page Builder: Pagelayer – Drag and Drop website builder v2.2.1
2.2.1 2.2.0 2.1.9 2.1.8 2.1.7 2.1.6 2.1.5 2.1.4 2.1.3 trunk 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5 0.9.6 0.9.7 0.9.8 0.9.9 1.0.0 1.0.2 1.0.3 1.0.4 1.0.5 All 129 releases
← All changes | main/template.php +1009 -14 1.0.42.2.1 View file →
@@ -1,9 +1,9 @@
1 1 <?php
2 2
3 3 //////////////////////////////////////////////////////////////
4 4 //===========================================================
5 -// tampalte.php
5 +// template.php
6 6 //===========================================================
7 7 // PAGELAYER
8 8 // Inspired by the DESIRE to be the BEST OF ALL
9 9 // ----------------------------------------------------------
@@ -23,8 +23,901 @@
23 23 if(!defined('PAGELAYER_VERSION')) {
24 24 exit('Hacking Attempt !');
25 25 }
26 26
27 +// Define our array
28 +function pagelayer_builder_array(){
29 +
30 +global $pagelayer;
31 +
32 + // Array for custom post type data
33 + $pagelayer->builder = array(
34 + 'name' => 'pagelayer-template',
35 + 'type_slug' => 'pagelayer_template_type',
36 + 'type'=> [
37 + '' => __('Select'),
38 + 'header' => __('Header'),
39 + 'footer' => __('Footer'),
40 + 'single' => array(
41 + 'label' => __('Single'),
42 + 'need_selection' => 'singular', // To select the value in template select and hide it
43 + ),
44 + 'archive' => array(
45 + 'label' => __('Archive'),
46 + 'need_selection' => 'archives', // To select the value in template select and hide it
47 + ),
48 + 'popup' => __('Popup'),
49 + 'section' => array(
50 + 'label' => __('Section'),
51 + 'no_condition' => 1, // To hide the conditions options
52 + ),
53 + 'global_section' => array(
54 + 'label' => __('Global Section'),
55 + 'no_condition' => 1, // To hide the conditions options
56 + 'hide_drop' => 1,
57 + ),
58 + 'global_widget' => array(
59 + 'label' => __('Global Widget'),
60 + 'no_condition' => 1, // To hide the conditions options
61 + 'hide_drop' => 1,
62 + ),
63 + ],
64 + 'action' => [
65 + 'include' => __('Include'),
66 + 'exclude' => __('Exclude'),
67 + ],
68 + 'dispay_on' => [
69 + '' => __('Full Site'),
70 + 'archives' => array(
71 + 'label' => __('Archives'),
72 + 'check_conditions' => function ( $args = null ){
73 + return is_archive() || is_home() || is_search();
74 + },
75 + ),
76 + 'singular' => array(
77 + 'label' => __('Singular'),
78 + 'check_conditions' => function ( $args = null ){
79 + return ( is_singular() && ! is_embed() ) || is_404();
80 + },
81 + ),
82 + ],
83 + // NOTE: Templates list array name should be dispay_on name with suffix _templates
84 + 'archives_templates'=> [
85 + '' => __('All Archives / Posts Archive'),
86 + 'author' => array(
87 + 'label' => __('Author Archives'),
88 + 'check_conditions' => function ( $args = null ){
89 + return is_author($args['id']);
90 + },
91 + 'filter_type' => 'author', // should be (author, taxonomy and post type)
92 + ),
93 + 'date' => array(
94 + 'label' => __('Date Archives'),
95 + 'check_conditions' => function ( $args = null ){
96 + return is_date();
97 + },
98 + 'no_id_section' => 1, // ID select section not required
99 + ),
100 + 'search' => array(
101 + 'label' => __('Search Results'),
102 + 'check_conditions' => function ( $args = null ){
103 + return is_search();
104 + },
105 + 'no_id_section' => 1, // Id select section not required
106 + ),
107 + ],
108 + // NOTE: Templates list array name should be dispay_on name with suffix _templates
109 + 'singular_templates'=> [
110 + '' => __('All Singular'), // singular.php
111 + 'by_author' => array(
112 + 'label' => __('By Author'),
113 + 'check_conditions' => function ( $args = null ){
114 + return is_singular() && get_post_field( 'post_author' ) === $args['id'];
115 + },
116 + 'filter_type' => 'author',
117 + ),
118 + 'front_page' => array(
119 + 'label' => __('Front Page'),
120 + 'check_conditions' => function ( $args = null ){
121 + return is_front_page();
122 + },
123 + 'no_id_section' => 1, // Id select section not required
124 + ),
125 + '404' => array(
126 + 'label' => __('404'),
127 + 'check_conditions' => function ( $args = null ){
128 + return is_404();
129 + },
130 + 'no_id_section' => 1, // Id select section not required
131 + ),
132 + //'direct_child_of' => __('Direct Child Of'),
133 + //'any_child_of' => __('Any Child Of'),
134 + ], // conditions by post type
135 +
136 + );
137 +
138 + add_shortcode($pagelayer->builder['name'], 'pagelayer_builder_posts_shortcode');
139 +
140 + add_filter( 'manage_'. $pagelayer->builder['name'] .'_posts_columns', 'pagelayer_builder_add_columns' );
141 +
142 + add_action( 'manage_'. $pagelayer->builder['name'] .'_posts_custom_column' , 'pagelayer_builder_columns', 10, 2 );
143 +
144 + add_filter( 'views_edit-' . $pagelayer->builder['name'], 'pagelayer_builder_template_tabs' );
145 +
146 +}
147 +
148 +// Create template builder conditions for singular by post type
149 +function pagelayer_builder_singular_conditions($post_types = []){
150 + $condition = [];
151 +
152 + if(empty($post_types)){
153 + $post_types = pagelayer_get_public_post_types();
154 + //unset( $post_types['product'] ); // WooCommerce related
155 + $post_types['attachment'] = get_post_type_object( 'attachment' )->label;
156 + }
157 +
158 + foreach ( $post_types as $post_type => $label ) {
159 + //$post_type_object = get_post_type_object( $post_type );
160 +
161 + if(array_key_exists($label, $condition)){
162 + continue;
163 + }
164 +
165 + $condition[$label] = [ //TC: Need to change the name of variable
166 + $post_type => array(
167 + 'label' => $label,
168 + 'check_conditions' => function ( $args = null ) use ($post_type){
169 + if ( isset($args['id']) && !empty($args['id']) ) {
170 + $id = (int) $args['id'];
171 + if ( $id ) {
172 + return is_singular($post_type) && get_queried_object_id() === $id;
173 + }
174 + }
175 +
176 + return is_singular( $post_type );
177 + },
178 + 'filter_type' => 'post',
179 + 'object_type' => $post_type,
180 + ),
181 + ];
182 +
183 + $taxonomies = get_object_taxonomies( $post_type, 'objects' );
184 + $post_taxonomies = wp_filter_object_list( $taxonomies, [
185 + 'public' => true,
186 + 'show_in_nav_menus' => true,
187 + ] );
188 +
189 + foreach ( $post_taxonomies as $slug => $object ) {
190 +
191 + $condition[$label] += [
192 + $object->name => array(
193 + 'label' => sprintf( __( 'In %s' ), $object->labels->singular_name ),
194 + 'check_conditions' => function ( $args = null ) use ($object){
195 + return is_singular() && has_term( (int) $args['id'], $object->name );
196 + },
197 + 'filter_type' => 'taxonomy',
198 + 'object_type' => $object->name,
199 + ),
200 + ];
201 +
202 + if ( $object->hierarchical ) {
203 + $condition[$label] += [
204 + 'in_' . $object->name . '_children' => array(
205 + 'label' => sprintf( __( 'In Child %s' ), $object->labels->name ),
206 + 'check_conditions' => function ( $args = null ) use ($object){
207 + $id = (int) $args['id'];
208 + if ( ! is_singular() || ! $id ) {
209 + return false;
210 + }
211 + $child_terms = get_term_children( $id, $object->name );
212 +
213 + return ! empty( $child_terms ) && has_term( $child_terms, $object->name );
214 + },
215 + 'filter_type' => 'taxonomy',
216 + 'object_type' => $object->name,
217 + ),
218 + ];
219 + }
220 +
221 + }
222 +
223 + $condition[$label] += [
224 + $object->name . '_by_author' => array(
225 + 'label' => sprintf( __( '%s By Author' ), $label ),
226 + 'check_conditions' => function ( $args = null ) use ($post_type){
227 + return is_singular($post_type) && get_post_field( 'post_author' ) === $args['id'];
228 + },
229 + 'filter_type' => 'author',
230 + 'object_type' => $post_type . '_by_author',
231 + ),
232 + ];
233 +
234 + }
235 +
236 + return $condition;
237 +}
238 +
239 +// Create template builder conditions for archives by post type
240 +function pagelayer_builder_archives_conditions($post_types = []){
241 +
242 + $condition = [];
243 +
244 + if(empty($post_types)){
245 + $post_types = pagelayer_get_public_post_types();
246 + //unset( $post_types['product'] );
247 + }
248 +
249 + foreach ( $post_types as $post_type => $label ) {
250 +
251 + //$post_type_object = get_post_type_object( $post_type );
252 + if ( ! get_post_type_archive_link( $post_type ) ) {
253 + continue;
254 + }
255 +
256 + $condition[$label] = [ //TC: Need to change the name of variable
257 + $post_type => array(
258 + 'label' => $label,
259 + 'check_conditions' => function ( $args = null ) use ($post_type){
260 + return is_post_type_archive( $post_type ) || ( 'post' === $post_type && is_home() );
261 + },
262 + 'no_id_section' => 1, // Id select section not required
263 + ),
264 + ];
265 +
266 + $taxonomies = get_object_taxonomies( $post_type, 'objects' );
267 + $post_taxonomies = wp_filter_object_list( $taxonomies, [
268 + 'public' => true,
269 + 'show_in_nav_menus' => true,
270 + ] );
271 +
272 + foreach ( $post_taxonomies as $slug => $object ) {
273 +
274 + $condition[$label] += [
275 + $object->name => array(
276 + 'label' => sprintf( __( '%s' ), $object->label ),
277 + 'check_conditions' => function ( $args = null ) use ($object){
278 + $taxonomy = $object->name;
279 + $id = (int) $args['id'];
280 +
281 + if ( 'category' === $taxonomy ) {
282 + return is_category( $id );
283 + }
284 +
285 + if ( 'post_tag' === $taxonomy ) {
286 + return is_tag( $id );
287 + }
288 +
289 + return is_tax( $taxonomy, $id );
290 + },
291 + 'filter_type' => 'taxonomy',
292 + 'object_type' => $object->name,
293 + ),
294 + ];
295 +
296 + }
297 +
298 + $all = 'pagelayer_all_'.$post_type;
299 +
300 + $condition[$label] += [
301 + $all => array(
302 + 'label' => 'All '.$label.' Archive',
303 + 'check_conditions' => function ( $args = null ) use ($post_type, $condition, $all, $label){
304 +
305 + foreach($condition[$label] as $k => $v){
306 + if($all == $k){
307 + continue;
308 + }
309 +
310 + $ret = $v['check_conditions']($args);
311 +
312 + if(!empty($ret)){
313 + return $ret;
314 + }
315 +
316 + }
317 +
318 + },
319 + 'no_id_section' => 1, // Id select section not required
320 + ),
321 + ];
322 +
323 + }
324 +
325 + return $condition;
326 +}
327 +
328 +// Handle the links for the add URL
329 +add_action('admin_head', 'pagelayer_builder_admin_head', 9999);
330 +function pagelayer_builder_admin_head(){
331 + global $pagelayer, $post_type;
332 +
333 + if(!isset($pagelayer->builder) || $post_type != $pagelayer->builder['name']){
334 + return;
335 + }
336 +
337 +
338 + echo '<script type="text/javascript">
339 +
340 +jQuery(document).ready(function(){
341 + var but = jQuery(".page-title-action");
342 +
343 + if(but.length < 1){
344 + return;
345 + }
346 +
347 + but.attr("href", "'.esc_url(admin_url('admin.php?page=pagelayer_template_wizard')).'");
348 +
349 + var export_but = jQuery(but[0].outerHTML);
350 + export_but.html("'.__pl('export_template').'");
351 + export_but.addClass("pagelayer-temp-export-but");
352 + export_but.attr("href", "'.(defined('SITEPAD') ? esc_url(admin_url('admin.php?page=pagelayer_tools#export_theme_tab')) : esc_url(admin_url('admin.php?page=pagelayer_template_export'))).'");
353 + //console.log(export_but[0].outerHTML);
354 +
355 + but.after(export_but);
356 +});
357 +
358 +</script>';
359 +
360 +}
361 +
362 +// This function will handle the Template Builder pages in Pagelayer
363 +add_action('init', 'pagelayer_builder_post_type', 9999);
364 +function pagelayer_builder_post_type() {
365 + global $pagelayer;
366 +
367 + if(!isset($pagelayer->builder)){
368 + return;
369 + }
370 +
371 + // Add Template Post Supports
372 + $supports = array(
373 + 'title', // post title
374 + 'editor', // post content
375 + 'author', // post author
376 + 'custom-fields', // custom fields
377 + 'revisions', // post revisions
378 + );
379 +
380 + // Add Template Post lables
381 + $labels = array(
382 + 'name' => _x('Templates', 'plural'),
383 + 'singular_name' => _x('Pagelayer Template', 'singular'),
384 + 'menu_name' => _x('Pagelayer Templates', 'admin menu'),
385 + 'name_admin_bar' => _x('Pagelayer Templates', 'admin bar'),
386 + 'add_new' => _x('Add New', 'add templates'),
387 + 'add_new_item' => __('Add New'),
388 + 'new_item' => __('New Template'),
389 + 'edit_item' => __('Edit Template'),
390 + 'view_item' => __('View Template'),
391 + 'all_items' => __('All Templates'),
392 + 'search_items' => __('Search Templates'),
393 + 'not_found' => __('No Pagelayer templates found'),
394 + );
395 +
396 + $args = array(
397 + 'supports' => $supports,
398 + 'labels' => $labels,
399 + 'menu_icon' => PAGELAYER_URL.'/images/pagelayer-logo-19.png',
400 + 'public' => true,
401 + 'show_in_menu' => false,
402 + 'publicly_queryable' => true,
403 + 'query_var' => true,
404 + 'rewrite' => false,
405 + 'has_archive' => true,
406 + 'hierarchical' => false,
407 + 'exclude_from_search' => true,
408 + );
409 +
410 + // Register custom post type
411 + register_post_type($pagelayer->builder['name'] , $args);
412 +
413 + // Add any other templates as well
414 + $pagelayer->builder['archives_templates'] += pagelayer_builder_archives_conditions();
415 + $pagelayer->builder['singular_templates'] += pagelayer_builder_singular_conditions();
416 +
417 +}
418 +
419 +// Register shortcode for custom post type
420 +function pagelayer_builder_posts_shortcode($atts){
421 +
422 + global $pagelayer;
423 +
424 + // If id not exist
425 + if( !isset($atts['id']) ){return '';}
426 +
427 + // Get the post data
428 + $post = get_post((int) $atts['id']);
429 +
430 + // If post is not empty
431 + if(empty($post) || $post->post_type != 'pagelayer-template' || ($post->post_status === 'private' && !current_user_can('read_private_posts'))){
432 + return '';
433 + }
434 +
435 + $cached_editable = $pagelayer->dont_make_editable;
436 + $pagelayer->dont_make_editable = true;
437 + $content = $post->post_content;
438 + $content = apply_filters( 'the_content', $content );
439 + $pagelayer->dont_make_editable = $cached_editable;
440 +
441 + return $content;
442 +
443 +}
444 +
445 +// Handle edit link of the post type
446 +add_filter('get_edit_post_link', 'pagelayer_builder_edit_link', 1000, 3);
447 +function pagelayer_builder_edit_link($link, $postID, $context){
448 + global $pagelayer;
449 +
450 + $post = get_post($postID);
451 +
452 + if($post->post_type != $pagelayer->builder['name']){
453 + return $link;
454 + }
455 +
456 + return admin_url('admin.php?page=pagelayer_template_wizard&post='.$post->ID);
457 +
458 +}
459 +
460 +// Handle row actions for pagelayer-template
461 +add_filter('post_row_actions', 'pagelayer_builder_row_actions', 10, 2);
462 +function pagelayer_builder_row_actions($actions, $post){
463 + global $pagelayer;
464 +
465 + if($post->post_type != $pagelayer->builder['name']){
466 + return $actions;
467 + }
468 +
469 + $actions['pagelayer'] = '<a href="'.esc_url( pagelayer_shortlink($post->ID).'&pagelayer-live=1' ).'">'.__pl('edit_using').'</a>';
470 +
471 + return $actions;
472 +}
473 +
474 +// Add the custom columns to the pagelayer-template post type:
475 +function pagelayer_builder_add_columns($columns) {
476 +
477 + // unset for re-setup
478 + unset( $columns['taxonomy-pagelayer_template_type'] );
479 +
480 + $offset = 2;
481 + $type = array(
482 + 'pagelayer_template_type' => __( 'Type' ),
483 + 'pagelayer_template_conditions' => __( 'Display On' ),
484 + 'pagelayer_template_shortcode' => __( 'Shortcode' )
485 + );
486 +
487 + // Add the $type array in 2 position of $columns;
488 + $columns = array_slice( $columns, 0, $offset, true ) + $type + array_slice( $columns, $offset, null, true );
489 +
490 + //print_r($columns);die();
491 +
492 + return $columns;
493 +
494 +}
495 +
496 +// Add the data to the custom columns for the pagelayer-template post type:
497 +function pagelayer_builder_columns( $column, $post_id ) {
498 + global $pagelayer;
499 +
500 + switch ( $column ) {
501 + case 'pagelayer_template_type' :
502 + $type = get_post_meta( $post_id, 'pagelayer_template_type', true );
503 +
504 + if(!empty($type)){
505 + $type = pagelayer_multi_array_search($pagelayer->builder['type'], $type);
506 +
507 + if(is_array($type) && array_key_exists('label', $type)){
508 + $type = $type['label'];
509 + }
510 +
511 + echo '<span>' . $type . '</span>';
512 + }else{
513 + echo __('None');
514 + }
515 +
516 + break;
517 +
518 + case 'pagelayer_template_conditions' :
519 + $dis_conditions = get_post_meta( $post_id, 'pagelayer_template_conditions', true );
520 + if( !empty($dis_conditions) && is_array($dis_conditions)){
521 + $dis_html = '';
522 + foreach($dis_conditions as $condi){
523 + $dis_html .= '<span>';
524 +
525 + if(isset($condi['template'])){
526 + $template = pagelayer_multi_array_search($pagelayer->builder['dispay_on'], $condi['template']);
527 +
528 + if(is_array($template) && array_key_exists('label', $template)){
529 + $template = $template['label'];
530 + }
531 +
532 + $dis_html .= $template;
533 + }
534 +
535 + if(isset($condi['sub_template'])){
536 + $sub_template = pagelayer_multi_array_search($pagelayer->builder[$condi['template'].'_templates'], $condi['sub_template']);
537 +
538 + if(is_array($sub_template) && array_key_exists('label', $sub_template)){
539 + $sub_template = $sub_template['label'];
540 + }
541 +
542 + if(!empty($sub_template)){
543 + $dis_html .= ' > '. $sub_template;
544 + }
545 + }
546 +
547 + if(!empty($condi['id'])){
548 + $dis_html .= ' > #'. $condi['id'];
549 + }
550 +
551 + $dis_html .= '</span></br>';
552 + }
553 + }
554 +
555 + if(!empty($dis_html)){
556 + echo $dis_html;
557 + }else{
558 + echo __('None');
559 + }
560 +
561 + break;
562 +
563 + case 'pagelayer_template_shortcode' :
564 +
565 + echo '[pagelayer-template id="'.$post_id.'"]';
566 +
567 + break;
568 +
569 + }
570 +}
571 +
572 +// Print template tabs.
573 +function pagelayer_builder_template_tabs( $views ) {
574 + global $pagelayer;
575 +
576 + $current_type = '';
577 + $active_class = ' nav-tab-active';
578 +
579 + if ( ! empty( $_REQUEST[$pagelayer->builder['type_slug']] ) ) {
580 + $current_type = $_REQUEST[$pagelayer->builder['type_slug']];
581 + $active_class = '';
582 + }
583 +
584 + $url_args = [
585 + 'post_type' => $pagelayer->builder['name'],
586 + ];
587 +
588 + $baseurl = add_query_arg( $url_args, admin_url( 'edit.php' ) );
589 +
590 + $template_types = $pagelayer->builder['type'];
591 +
592 + if ( 1 >= count( $template_types ) ) {
593 + return $views;
594 + }
595 +
596 + // If any pre define title
597 + $all_title = '';
598 + if ( ! $all_title ) {
599 + $all_title = __( 'All' );
600 + }
601 +
602 + echo '<div id="pagelayer-template-tabs-wrapper" class="nav-tab-wrapper" style="margin-bottom:15px">
603 + <a class="nav-tab'. $active_class .'" href="'. $baseurl .'"> '. $all_title .'</a>';
604 +
605 + foreach ( $template_types as $type => $class_name ) {
606 + $active_class = '';
607 +
608 + // If type is empty
609 + if( empty($type) ) continue;
610 +
611 + if ( $current_type === $type ) {
612 + $active_class = ' nav-tab-active';
613 + }
614 +
615 + $type_url = add_query_arg( $pagelayer->builder['type_slug'], $type, $baseurl );
616 + $type_label = is_array($class_name) && array_key_exists( 'label', $class_name) ? $class_name['label'] : $class_name;
617 +
618 + echo "<a class='nav-tab{$active_class}' href='{$type_url}'>{$type_label}</a>";
619 + }
620 +
621 + echo '</div>';
622 +
623 + return $views;
624 +}
625 +
626 +// Add filter for pagelayer template
627 +add_action( 'parse_query', 'pagelayer_builder_query_filter_types' );
628 +function pagelayer_builder_query_filter_types( \WP_Query $query ) {
629 + global $pagenow, $typenow, $pagelayer;
630 +
631 + if ( ! ('edit.php' === $pagenow && $pagelayer->builder['name'] === $typenow) || ! empty( $query->query_vars['meta_key'] ) ) {
632 + return;
633 + }
634 +
635 + if ( empty($_REQUEST[$pagelayer->builder['type_slug']]) ){
636 + return;
637 + }
638 +
639 + $current_tab = $_REQUEST[$pagelayer->builder['type_slug']];
640 +
641 + $template_types = $pagelayer->builder['type'];
642 +
643 + if( !array_key_exists($current_tab , $template_types )){
644 + return;
645 + }
646 +
647 + $query->query_vars['meta_key'] = 'pagelayer_template_type';
648 + $query->query_vars['meta_value'] = $current_tab;
649 +}
650 +
651 +// Add the button for choose template type - Remove
652 +add_action('edit_form_after_title', 'pagelayer_builder_editor_button', 11);
653 +function pagelayer_builder_editor_button(){
654 +
655 + global $pagelayer, $post;
656 +
657 + if($post->post_type != $pagelayer->builder['name']){
658 + return;
659 + }
660 +
661 + // Get the current screen
662 + $current_screen = get_current_screen();
663 +
664 + // For gutenberg - Add the code in the footer
665 + if(method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor()){
666 + add_action('admin_footer', 'pagelayer_builder_gutenberg');
667 + return;
668 + }
669 +
670 + echo '
671 +<div style="margin-top:15px;display:inline-block;">
672 + <a href="'.esc_url(admin_url('admin.php?page=pagelayer_template_wizard&post='.$post->ID)).'" class="button button-primary button-large" style="height:auto; padding:6px; font-size:15px;">
673 + <img src="'.PAGELAYER_URL.'/images/pagelayer-logo-40.png" align="top" width="24" /> <span>'.__('Edit Template Options').'</span>
674 + </a>
675 +</div>';
676 +
677 +}
678 +
679 +// For gutenberg editor
680 +function pagelayer_builder_gutenberg(){
681 +
682 + global $pagelayer, $post;
683 +
684 + echo '
685 +<div id="pagelayer-editor-template-edit" style="margin-left:15px; display:none">
686 + <a href="'.esc_url(admin_url('admin.php?page=pagelayer_template_wizard&post='.$post->ID)).'" class="button button-primary button-large" style="height:auto; padding:6px; font-size:15px;">
687 + <img src="'.PAGELAYER_URL.'/images/pagelayer-logo-40.png" align="top" width="24" /> <span>'.__('Edit Template Options').'</span>
688 + </a>
689 +</div>
690 +
691 +<script type="text/javascript">
692 +jQuery(document).ready(function(){
693 +
694 + var pagelayer_timer;
695 + var pagelayer_button = function(){
696 + var button = jQuery("#pagelayer-editor-template-edit");
697 + var g = jQuery(".edit-post-header-toolbar");
698 + if(g.length < 1){
699 + return;
700 + }
701 + button.detach();
702 + //console.log(button);
703 + g.append(button);
704 + button.show();
705 + clearInterval(pagelayer_timer);
706 + }
707 + pagelayer_timer = setInterval(pagelayer_button, 100);
708 +});
709 +</script>';
710 +}
711 +
712 +// Load all templates
713 +function pagelayer_builder_load_templates(){
714 +
715 + global $pagelayer;
716 +
717 + // Load all post types that are pagelayer-template
718 + $args = [
719 + 'post_type' => $pagelayer->builder['name'],
720 + 'status' => 'publish',
721 + 'meta_key' => 'pagelayer_template_conditions',
722 + 'posts_per_page' => -1 // For get all posts
723 + ];
724 +
725 + $query = new WP_Query($args);
726 + //print_r($query->posts);die();
727 +
728 + // Cache the same
729 + $pagelayer->templates = $query->posts;
730 +
731 +}
732 +
733 +// Load all our templates
734 +add_action( 'template_redirect', 'pagelayer_builder_template_redirect');
735 +function pagelayer_builder_template_redirect(){
736 +
737 + global $pagelayer, $post;
738 +
739 + // Load all post types that are pagelayer-template
740 + pagelayer_builder_load_templates();
741 +
742 + // If there is a match for a header
743 + $pagelayer->template_header = pagelayer_builder_try_to_apply('header');
744 +
745 + // Singular style posts
746 + if ( is_singular() || is_404() ) {
747 + $pagelayer->template_post = pagelayer_builder_try_to_apply('single');
748 +
749 + // Archive style posts
750 + } elseif ( is_archive() || is_home() || is_search() ) {
751 + $pagelayer->template_post = pagelayer_builder_try_to_apply('archive');
752 + }
753 +
754 + // If there is a match for a footer
755 + $pagelayer->template_footer = pagelayer_builder_try_to_apply('footer');
756 +
757 + // If the post type is pagelayer-template, then we are viewing i.e. EDITING PAGELAYER
758 + if(!empty($post) && $post->post_type == $pagelayer->builder['name']){
759 +
760 + // Turn on template editor and default it to pagelayer-content
761 + $pagelayer->template_editor = 'pagelayer-content';
762 + $pagelayer->template_post = $post->ID;
763 +
764 + // The type
765 + $pagelayer_template_type = get_post_meta($post->ID, 'pagelayer_template_type', true);
766 +
767 + // If the type is header
768 + if( $pagelayer_template_type == 'header' ){
769 +
770 + $pagelayer->template_editor = 'pagelayer-header';
771 + $pagelayer->template_header = $post->ID;// Fill in that we are rendering the header we want to edit
772 + $pagelayer->template_post = 0;
773 + $pagelayer->template_footer = 0;
774 +
775 + // If the type is footer
776 + }elseif( $pagelayer_template_type == 'footer' ){
777 +
778 + $pagelayer->template_editor = 'pagelayer-footer';
779 + $pagelayer->template_header = 0;
780 + $pagelayer->template_post = 0;
781 + $pagelayer->template_footer = $post->ID;// Fill in that we are rendering the footer we want to edit
782 +
783 + }
784 +
785 + }
786 +
787 + // If there is a match for a popup, get all ids with priority
788 + $pagelayer->template_popup_ids = pagelayer_builder_try_to_apply('popup', true);
789 +
790 + // Return all the posts
791 + //return $query['posts'];
792 +
793 + // Remove the filter first because it was added by
794 + remove_filter('template_include', 'pagelayer_template_include', 1000);
795 +
796 + // Add the filter again
797 + add_filter('template_include', 'pagelayer_template_include', 1000, 1);
798 +
799 + do_action('pagelayer_builder_template_redirect');
800 +
801 +}
802 +
803 +// For check which template will be applied
804 +function pagelayer_builder_try_to_apply($type , $return_all = false){
805 +
806 + global $pagelayer;
807 +
808 + // Get templates id by type
809 + $ids = pagelayer_builder_template_ids($type);
810 + $sel_id = pagelayer_template_check_conditons($ids, false, $return_all);
811 +
812 + if( !empty($ids) && !empty($sel_id) ){
813 + return $sel_id;
814 + }
815 +
816 + return false;
817 +
818 +}
819 +
820 +// Get template post ids and conditions by type
821 +function pagelayer_builder_template_ids($type){
822 +
823 + global $pagelayer;
824 +
825 + // No templates
826 + if(empty($pagelayer->templates)){
827 + return [];
828 + }
829 +
830 + // List of templates to return
831 + $id_list = array();
832 + foreach($pagelayer->templates as $template){
833 +
834 + // The type
835 + $pagelayer_template_type = get_post_meta($template->ID, 'pagelayer_template_type', true);
836 +
837 + if($type == $pagelayer_template_type){
838 + $id_list[] = $template->ID;
839 + }
840 +
841 + }
842 +
843 + return $id_list;
844 +}
845 +
846 +add_action('plugins_loaded', 'pagelayer_free_templ_wizards', 1);
847 +function pagelayer_free_templ_wizards(){
848 +// Its Free
849 +if(!defined('PAGELAYER_PREMIUM')){
850 +
851 + // Wizard to create / edit templates
852 + function pagelayer_builder_template_wizard(){
853 + pagelayer_show_pro_div('Theme Template Creator', 'With the Pagelayer Theme Templates wizard you can create Headers, Footers, Singular, Archives and WooCommerce Templates. It allows you to control each and every aspect of your theme. You can also set conditions for these templates !');
854 + }
855 +
856 + // Wizard to export theme
857 + function pagelayer_builder_export(){
858 + pagelayer_show_pro_div('Export Templates', 'With the Pagelayer Export wizard you can export your Headers, Footers, Singular, Archives and WooCommerce Templates. These templates can then be imported in any other WordPress site.');
859 + }
860 +
861 +}
862 +}
863 +
864 +// Fix the default blog template we insert for woocommerce
865 +function pagelayer_template_product_fix(){
866 +
867 + global $pagelayer;
868 +
869 + // Have we already fixed
870 + $fixed = get_option('pagelayer_template_product_fix');
871 + if(!empty($fixed)){
872 + return;
873 + }
874 +
875 + // Make sure we have templates
876 + pagelayer_builder_load_templates();
877 +
878 +
879 + if(empty($pagelayer->templates)){
880 + return;
881 + }
882 +
883 + foreach($pagelayer->templates as $k => $v){
884 + if($v->post_name == 'blog-template'){
885 + $blog = $v;
886 + }
887 + }
888 +
889 + if(empty($blog)){
890 + return;
891 + }
892 +
893 + // Get meta
894 + $dis_conditions = get_post_meta( $blog->ID, 'pagelayer_template_conditions', true );
895 + //print_r($dis_conditions);
896 +
897 + foreach($dis_conditions as $k => $v){
898 + if(!empty($v['sub_template']) && $v['sub_template'] == 'pagelayer_all_product'){
899 + $found = 1;
900 + }
901 + }
902 + //echo $found;return;
903 +
904 + // We need to add conditions
905 + if(empty($found)){
906 +
907 + $dis_conditions[] = ['type' => 'exclude',
908 + 'template' => 'archives',
909 + 'sub_template' => 'pagelayer_all_product',
910 + 'id' => ''];
911 +
912 + update_post_meta( $blog->ID, 'pagelayer_template_conditions', $dis_conditions );
913 +
914 + }
915 +
916 + update_option('pagelayer_template_product_fix', time());
917 +
918 +}
919 +
27 920 // Pagelayer Template Loading Mechanism
28 921 add_action('setup_theme', 'pagelayer_template_setup_theme', 5);
29 922 function pagelayer_template_setup_theme(){
30 923
@@ -118,15 +1011,25 @@
118 1011 // If we do have a header but not the footer or we have the footer and no header,
119 1012 // then we need to make sure to blank the other
120 1013 if(!empty($pagelayer->template_header) || !empty($pagelayer->template_footer)){
121 1014 $pagelayer_enqueue_frontend = true;
1015 +
1016 + // Disable AIOSEO for pagelayer post types
1017 + if(!empty($GLOBALS['post']) && $GLOBALS['post']->post_type == $pagelayer->builder['name']){
1018 + add_filter( 'aioseo_disable', '__return_true' );
1019 + }
1020 +
122 1021 add_action('get_header', 'pagelayer_get_header');
123 1022 add_action('get_footer', 'pagelayer_get_footer');
124 1023 }
125 1024
1025 + // Handle the sidebar settings !
1026 + //add_action('get_sidebar', 'pagelayer_get_sidebar');
1027 +
126 1028 // If we do have Popup templates, then append it in body
127 1029 if(!empty($pagelayer->template_popup_ids) && empty($pagelayer->template_editor)){
128 1030 $pagelayer_enqueue_frontend = true;
1031 + add_action('wp_body_open', 'pagelayer_builder_popup_append');
129 1032 add_action('wp_footer', 'pagelayer_builder_popup_append');
130 1033 }
131 1034
132 1035 // If the post being shown to the user is not a Pagelayer post, then we need to enqueue forcefully
@@ -140,13 +1043,21 @@
140 1043 }
141 1044
142 1045 // Its our template OR are we editing a pagelayer-template, then render it
143 1046 if(pathinfo($template, PATHINFO_EXTENSION) == 'pgl' || !empty($pagelayer->template_post) || !empty($pagelayer->template_editor)){
144 -
1047 +
1048 + // We rendered from header to footer
1049 + $pagelayer->from_header_to_footer = true;
1050 +
145 1051 get_header();
146 1052 echo '<div class="pagelayer-content">';
147 1053 pagelayer_template_render($template);
148 1054 echo '</div>';
1055 +
1056 + // If a template needs to call the sidebar !
1057 + if(!empty($pagelayer->template_call_sidebar)){
1058 + get_sidebar();
1059 + }
149 1060 get_footer();
150 1061
151 1062 return false;
152 1063 }
@@ -168,11 +1079,10 @@
168 1079
169 1080 if(is_numeric($template)){
170 1081 echo pagelayer_get_post_content($template);
171 1082 }else{
172 - echo do_shortcode(file_get_contents(get_stylesheet_directory().'/'.$template.'.pgl'));
1083 + echo pagelayer_the_content(file_get_contents(get_stylesheet_directory().'/'.$template.'.pgl'));
173 1084 }
174 -
175 1085 }
176 1086
177 1087 // For check which template will be applied
178 1088 function pagelayer_template_try_to_apply($type){
@@ -226,12 +1136,12 @@
226 1136
227 1137 $check = 0;
228 1138
229 1139 // Get template array
230 - $tmpl_array = pagelayer_multi_array_search( $pagelayer->builder['dispay_on'], $condi['template'] );
1140 + $tmpl_array = (array) pagelayer_multi_array_search( $pagelayer->builder['dispay_on'], $condi['template'] );
231 1141
232 1142 // Get sub_template array
233 - $sub_tmpl_array = pagelayer_multi_array_search( $pagelayer->builder[$condi['template'].'_templates'], $condi['sub_template']);
1143 + $sub_tmpl_array = (array) pagelayer_multi_array_search( $pagelayer->builder[$condi['template'].'_templates'], $condi['sub_template']);
234 1144
235 1145 // If the condition name is general priority
236 1146 if(empty($condi['template'])){
237 1147
@@ -271,9 +1181,9 @@
271 1181 $set_prio = 4; // Set id Property 4
272 1182 }else{
273 1183 $set_prio = 3;// Set sub_template Property 3
274 1184 // If no id section then Property
275 - if($sub_tmpl_array['no_id_section']){ $set_prio = 4; }
1185 + if(!empty($sub_tmpl_array['no_id_section'])){ $set_prio = 4; }
276 1186 }
277 1187 }
278 1188 }
279 1189
@@ -331,8 +1241,9 @@
331 1241 <?php wp_head(); ?>
332 1242 </head>
333 1243
334 1244 <body <?php body_class(); ?>>
1245 + <?php if(function_exists('wp_body_open')) { wp_body_open(); } ?>
335 1246 <?php
336 1247
337 1248 // Output our content
338 1249 if(!empty($pagelayer->template_header)){
@@ -392,9 +1303,8 @@
392 1303 </html>';
393 1304
394 1305 // Avoid running wp_footer hooks again
395 1306 remove_all_actions( 'wp_footer' );
396 -
397 1307
398 1308 $templates = [];
399 1309 $name = (string) $name;
400 1310 if ($name !== '') {
@@ -403,9 +1313,9 @@
403 1313
404 1314 $templates[] = 'footer.php';
405 1315
406 1316 // Since, we already outputted our footer, we need to do a locate_template for the existing theme
407 - // This is because, locate_template has the 3rd param as require once, so in the get_header
1317 + // This is because, locate_template has the 3rd param as require once, so in the get_footer
408 1318 // the footer.php will not load again
409 1319 ob_start();
410 1320 locate_template( $templates, true );
411 1321 ob_get_clean();
@@ -412,12 +1322,30 @@
412 1322
413 1323 }
414 1324
415 1325 // Any sidebar to load ?
416 -function pagelayer_get_sidebar($name) {
1326 +function pagelayer_get_sidebar($name = '') {
417 1327
418 1328 global $pagelayer;
419 1329
1330 + // If any of our setting has been set, then only we apply. Otherwise we return !
1331 + if(is_customize_preview()){
1332 + $pagelayer->settings['sidebar'] = get_option('pagelayer_sidebar');
1333 + }
1334 +
1335 + if(is_array($pagelayer->settings['sidebar'])){
1336 + foreach($pagelayer->settings['sidebar'] as $k => $v){
1337 + $set = 1;
1338 + break;
1339 + }
1340 + }
1341 +
1342 + // If no settings were saved for pagelayer, let the default persist
1343 + // BUT if we are from_header_to_footer then we want default as no header and hence, we will render ours !
1344 + if(empty($set) && empty($pagelayer->from_header_to_footer)){
1345 + return;
1346 + }
1347 +
420 1348 // Output our content
421 1349 if(!empty($pagelayer->template_sidebar)){
422 1350 pagelayer_template_render($pagelayer->template_sidebar);
423 1351 }
@@ -430,30 +1358,95 @@
430 1358
431 1359 $templates[] = 'sidebar.php';
432 1360
433 1361 // Since, we already outputted our sidebar, we need to do a locate_template for the existing theme
434 - // This is because, locate_template has the 3rd param as require once, so in the get_header
1362 + // This is because, locate_template has the 3rd param as require once, so in the get_sidebar
435 1363 // the sidebar.php will not load again
436 1364 ob_start();
437 1365 locate_template( $templates, true );
438 - ob_get_clean();
1366 + $sidebar = ob_get_clean();
439 1367
1368 + // Lets see what are settings are ?
1369 + $set = !empty($pagelayer->settings['sidebar']) ? $pagelayer->settings['sidebar'] : [];
1370 +
1371 + // For page
1372 + if(is_page()){
1373 + $enabled = isset($set['page']) ? $set['page'] : 'default';
1374 +
1375 + // For post
1376 + }elseif(is_single()){
1377 + $enabled = isset($set['post']) ? $set['post'] : 'default';
1378 +
1379 + // For Archives
1380 + }elseif(is_archive() || is_home()){
1381 + $enabled = isset($set['archives']) ? $set['archives'] : 'default';
1382 + }
1383 +
1384 + // Load the default
1385 + if(@$enabled == 'default' || is_front_page()){
1386 + $enabled = @$set['default'];
1387 + }
1388 +
1389 + // If its not right or left, then its disabled. Disabled values can be stored as "no" or "0"
1390 + if(!in_array($enabled, ['left', 'right'])){
1391 + return;
1392 + }
1393 +
1394 + $width = (int) (empty($set['width']) ? 20 : $set['width']);
1395 +
1396 + if(empty($sidebar)){
1397 + return;
1398 + }
1399 +
1400 + echo $sidebar;
1401 +
1402 +?><style>
1403 +aside, #sidebar {
1404 +width: <?php echo $width;?>%;
1405 +float: <?php echo $enabled;?>;
440 1406 }
441 1407
1408 +main, .pagelayer-content{
1409 +width: <?php echo round(99 - $width);?>% !important;
1410 +display: inline-block;
1411 +}
1412 +
1413 +#wp-calendar{
1414 +min-width: 100%;
1415 +}
1416 +</style>
1417 +
1418 +<?php
1419 +
1420 +}
1421 +
442 1422 // Get the custom post content by id
443 1423 function pagelayer_get_post_content($id){
444 1424 global $pagelayer;
445 1425
1426 + // Need to set post ID in Pagelayer boject, so we can get it while do shortcode
1427 + $pagelayer->rendering_template_id = $id;
1428 +
446 1429 // Get the content
447 1430 $post = get_post($id);
448 1431
1432 + if(is_attachment()){
1433 + remove_filter( 'the_content', 'prepend_attachment' );
1434 + }
1435 +
449 1436 $content = $post->post_content;
450 1437 pagelayer_load_shortcodes();
451 - //$content = do_shortcode( $content );
1438 +
1439 + $cached_editable = $pagelayer->dont_make_editable;
1440 + $pagelayer->dont_make_editable = true;
452 1441 $content = apply_filters( 'the_content', $content );
453 1442 $content = str_replace( ']]>', ']]&gt;', $content );
1443 + $pagelayer->dont_make_editable = $cached_editable;
454 1444
455 - return $content;
1445 + // Reset the id
1446 + $pagelayer->rendering_template_id = 0;
1447 +
1448 + return $content;
456 1449
457 1450 }
458 1451
459 1452 // Vars that can be used in template files
@@ -461,9 +1454,11 @@
461 1454
462 1455 $replacers['{{theme_url}}'] = get_stylesheet_directory_uri();
463 1456 $replacers['{{theme_images}}'] = get_stylesheet_directory_uri().'/images/';
464 1457 $replacers['{{themes_dir}}'] = dirname(get_stylesheet_directory_uri());
1458 + $replacers['{{content_url}}'] = dirname(dirname(dirname(get_stylesheet_directory_uri())));
465 1459 $replacers['{{pl_site_url}}'] = home_url();
1460 + $replacers['{{pl_plugin_url}}'] = PAGELAYER_URL;
466 1461
467 1462 return $replacers;
468 1463
469 1464 }