| 1 |
<?php |
| 2 |
|
| 3 |
class WPUPG_Grid_Shortcode { |
| 4 |
|
| 5 |
public function __construct() |
| 6 |
{ |
| 7 |
add_shortcode( 'wpupg-grid', array( $this, 'shortcode' ) ); |
| 8 |
|
| 9 |
// add_filter( 'mce_external_plugins', array( $this, 'tinymce_plugin' ) ); |
| 10 |
} |
| 11 |
|
| 12 |
public function shortcode( $options ) |
| 13 |
{ |
| 14 |
$output = ''; |
| 15 |
|
| 16 |
$slug = strtolower( trim( $options['id'] ) ); |
| 17 |
|
| 18 |
if( $slug ) { |
| 19 |
unset( $options['id'] ); |
| 20 |
$post = get_page_by_path( $slug, OBJECT, WPUPG_POST_TYPE ); |
| 21 |
|
| 22 |
if( !is_null( $post ) ) { |
| 23 |
$grid = new WPUPG_Grid( $post ); |
| 24 |
|
| 25 |
// Check if we need to filter the grid dynamically |
| 26 |
$dynamic_rules = array(); |
| 27 |
if( count( $options ) > 0 && WPUltimatePostGrid::is_premium_active() ) { |
| 28 |
foreach( $options as $taxonomy => $terms ) { |
| 29 |
if( taxonomy_exists( $taxonomy ) ) { |
| 30 |
$dynamic_rules[] = array( |
| 31 |
'post_type' => 'wpupg_dynamic', |
| 32 |
'taxonomy' => $taxonomy, |
| 33 |
'values' => explode( ';', str_replace( ',', ';', $terms ) ), |
| 34 |
'type' => 'restrict', |
| 35 |
); |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
if( count( $dynamic_rules ) > 0 ) { |
| 40 |
$grid->set_dynamic_rules( $dynamic_rules ); |
| 41 |
} |
| 42 |
|
| 43 |
$link_type = $grid->link_type(); |
| 44 |
$link_target = $grid->link_target(); |
| 45 |
$layout_mode = $grid->layout_mode(); |
| 46 |
$centered = $grid->centered() ? 'true' : 'false'; |
| 47 |
|
| 48 |
$posts = '<div id="wpupg-grid-' . esc_attr( $slug ) . '" class="wpupg-grid" data-grid="' . esc_attr( $slug ) . '" data-grid-id="' . $grid->ID() . '" data-link-type="' . $link_type . '" data-link-target="' . $link_target . '" data-layout-mode="' . $layout_mode . '" data-centered="' . $centered . '">'; |
| 49 |
$posts .= $grid->draw_posts(); |
| 50 |
$posts .= '</div>'; |
| 51 |
|
| 52 |
$output = apply_filters( 'wpupg_posts_shortcode', $posts, $grid ); |
| 53 |
|
| 54 |
$pagination = ''; |
| 55 |
if( $grid->pagination_type() == 'pages' ) { |
| 56 |
$pagination_type = $grid->pagination_type(); |
| 57 |
$pagination_style = $grid->pagination_style(); |
| 58 |
|
| 59 |
$style_data = ' data-margin-vertical="' . $pagination_style['margin_vertical'] . '"'; |
| 60 |
$style_data .= ' data-margin-horizontal="' . $pagination_style['margin_horizontal'] . '"'; |
| 61 |
$style_data .= ' data-padding-vertical="' . $pagination_style['padding_vertical'] . '"'; |
| 62 |
$style_data .= ' data-padding-horizontal="' . $pagination_style['padding_horizontal'] . '"'; |
| 63 |
$style_data .= ' data-border-width="' . $pagination_style['border_width'] . '"'; |
| 64 |
|
| 65 |
$style_data .= ' data-background-color="' . $pagination_style['background_color'] . '"'; |
| 66 |
$style_data .= ' data-text-color="' . $pagination_style['text_color'] . '"'; |
| 67 |
$style_data .= ' data-border-color="' . $pagination_style['border_color'] . '"'; |
| 68 |
|
| 69 |
$style_data .= ' data-active-background-color="' . $pagination_style['background_active_color'] . '"'; |
| 70 |
$style_data .= ' data-active-text-color="' . $pagination_style['text_active_color'] . '"'; |
| 71 |
$style_data .= ' data-active-border-color="' . $pagination_style['border_active_color'] . '"'; |
| 72 |
|
| 73 |
$style_data .= ' data-hover-background-color="' . $pagination_style['background_hover_color'] . '"'; |
| 74 |
$style_data .= ' data-hover-text-color="' . $pagination_style['text_hover_color'] . '"'; |
| 75 |
$style_data .= ' data-hover-border-color="' . $pagination_style['border_hover_color'] . '"'; |
| 76 |
|
| 77 |
$pagination .= '<div id="wpupg-grid-' . esc_attr( $slug ) . '-pagination" class="wpupg-pagination wpupg-pagination-' . $pagination_type . '" style="text-align: ' . $pagination_style['alignment'] . ';" data-grid="' . esc_attr( $slug ) . '" data-type="' . $pagination_type . '"' . $style_data . '>'; |
| 78 |
$pagination .= $grid->draw_pagination(); |
| 79 |
$pagination .= '</div>'; |
| 80 |
} |
| 81 |
|
| 82 |
$output .= apply_filters( 'wpupg_pagination_shortcode', $pagination, $grid ); |
| 83 |
|
| 84 |
wp_localize_script( 'wpupg_grid', 'wpupg_grid_' . $grid->ID(), array( |
| 85 |
'posts' => $grid->posts(), |
| 86 |
)); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
return $output; |
| 91 |
} |
| 92 |
|
| 93 |
public function tinymce_plugin( $plugin_array ) |
| 94 |
{ |
| 95 |
$plugin_array['wpupg_grid_shortcode'] = WPUltimatePostGrid::get()->coreUrl . '/js/tinymce_shortcode.js'; |
| 96 |
return $plugin_array; |
| 97 |
} |
| 98 |
} |