PluginProbe
WP Ultimate Post Grid / 2.2
WP Ultimate Post Grid v2.2
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
wp-ultimate-post-grid / helpers / shortcodes / grid_shortcode.php

grid_shortcode.php in WP Ultimate Post Grid 2.2, at helpers/shortcodes/grid_shortcode.php

130 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
29 if( isset( $options['post_id'] ) ) {
30 $post_ids = str_replace( ',', ';', $options['post_id'] );
31 $post_ids = str_replace( 'current_post', get_the_ID(), $post_ids );
32
33 $dynamic_rules[] = array(
34 'post_type' => 'wpupg_general',
35 'taxonomy' => 'id',
36 'values' => explode( ';', $post_ids ),
37 'type' => 'restrict',
38 );
39 unset( $options['post_id'] );
40 }
41
42 if( isset( $options['exclude_post_id'] ) ) {
43 $post_ids = str_replace( ',', ';', $options['exclude_post_id'] );
44 $post_ids = str_replace( 'current_post', get_the_ID(), $post_ids );
45
46 $dynamic_rules[] = array(
47 'post_type' => 'wpupg_general',
48 'taxonomy' => 'id',
49 'values' => explode( ';', $post_ids ),
50 'type' => 'exclude',
51 );
52 unset( $options['exclude_post_id'] );
53 }
54
55 foreach( $options as $taxonomy => $terms ) {
56 if( taxonomy_exists( $taxonomy ) ) {
57 $dynamic_rules[] = array(
58 'post_type' => 'wpupg_dynamic',
59 'taxonomy' => $taxonomy,
60 'values' => explode( ';', str_replace( ',', ';', $terms ) ),
61 'type' => 'restrict',
62 );
63 }
64 }
65 }
66 if( count( $dynamic_rules ) > 0 ) {
67 $grid->set_dynamic_rules( $dynamic_rules );
68 }
69
70 $link_type = $grid->link_type();
71 $link_target = $grid->link_target();
72 $layout_mode = $grid->layout_mode();
73 $centered = $grid->centered() ? 'true' : 'false';
74
75 $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 . '">';
76 $posts .= $grid->draw_posts();
77 $posts .= '</div>';
78
79 $output = apply_filters( 'wpupg_posts_shortcode', $posts, $grid );
80
81 // Message when no items match filter
82 if( $grid->empty_message() ) {
83 $output .= '<div id="wpupg-grid-' . esc_attr( $slug ) . '-empty" class="wpupg-grid-empty">' . $grid->empty_message() . '</div>';
84 }
85
86 $pagination = '';
87 if( $grid->pagination_type() == 'pages' ) {
88 $pagination_type = $grid->pagination_type();
89 $pagination_style = $grid->pagination_style();
90
91 $style_data = ' data-margin-vertical="' . $pagination_style['margin_vertical'] . '"';
92 $style_data .= ' data-margin-horizontal="' . $pagination_style['margin_horizontal'] . '"';
93 $style_data .= ' data-padding-vertical="' . $pagination_style['padding_vertical'] . '"';
94 $style_data .= ' data-padding-horizontal="' . $pagination_style['padding_horizontal'] . '"';
95 $style_data .= ' data-border-width="' . $pagination_style['border_width'] . '"';
96
97 $style_data .= ' data-background-color="' . $pagination_style['background_color'] . '"';
98 $style_data .= ' data-text-color="' . $pagination_style['text_color'] . '"';
99 $style_data .= ' data-border-color="' . $pagination_style['border_color'] . '"';
100
101 $style_data .= ' data-active-background-color="' . $pagination_style['background_active_color'] . '"';
102 $style_data .= ' data-active-text-color="' . $pagination_style['text_active_color'] . '"';
103 $style_data .= ' data-active-border-color="' . $pagination_style['border_active_color'] . '"';
104
105 $style_data .= ' data-hover-background-color="' . $pagination_style['background_hover_color'] . '"';
106 $style_data .= ' data-hover-text-color="' . $pagination_style['text_hover_color'] . '"';
107 $style_data .= ' data-hover-border-color="' . $pagination_style['border_hover_color'] . '"';
108
109 $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 . '>';
110 $pagination .= $grid->draw_pagination();
111 $pagination .= '</div>';
112 }
113
114 $output .= apply_filters( 'wpupg_pagination_shortcode', $pagination, $grid );
115
116 wp_localize_script( 'wpupg_grid', 'wpupg_grid_' . $grid->ID(), array(
117 'posts' => $grid->posts(),
118 ));
119 }
120 }
121
122 return $output;
123 }
124
125 public function tinymce_plugin( $plugin_array )
126 {
127 $plugin_array['wpupg_grid_shortcode'] = WPUltimatePostGrid::get()->coreUrl . '/js/tinymce_shortcode.js';
128 return $plugin_array;
129 }
130 }