PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.4.2
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.4.2
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / public / helpers / class-pcp-queryinside.php

class-pcp-queryinside.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 2.4.2, at public/helpers/class-pcp-queryinside.php

192 lines 8.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The file of query insides.
4 *
5 * @package Smart_Post_Show
6 * @subpackage public
7 *
8 * @since 2.2.0
9 */
10
11 /**
12 * The query inside class to process the query.
13 *
14 * @since 2.2.0
15 */
16 class SP_PC_QueryInside {
17
18 /**
19 * The post ID.
20 *
21 * @var string post ID.
22 */
23
24 /**
25 * Filtered content.
26 *
27 * @param mixed $view_options Shortcode options.
28 * @param mixed $layout Upper layout based options.
29 * @return array
30 */
31 public static function get_filtered_content( $view_options, $layout ) {
32
33 $pcp_post_type = isset( $view_options['pcp_select_post_type'] ) && ! empty( $view_options['pcp_select_post_type'] ) ? $view_options['pcp_select_post_type'] : 'any';
34 $post_limit = isset( $view_options['pcp_post_limit'] ) ? $view_options['pcp_post_limit'] : '';
35 $post_per_page = isset( $view_options['post_per_page'] ) ? $view_options['post_per_page'] : '';
36 $post_offset = isset( $view_options['pcp_post_offset'] ) ? $view_options['pcp_post_offset'] : 0;
37 $pcp_sticky_post = isset( $view_options['pcp_sticky_post'] ) ? $view_options['pcp_sticky_post'] : 0;
38 $post_per_page = ( $post_per_page > $post_limit ) ? $post_limit : $post_per_page;
39
40 if ( get_query_var( 'paged' ) ) {
41 $paged = get_query_var( 'paged' );
42 } elseif ( get_query_var( 'page' ) ) {
43 $paged = get_query_var( 'page' );
44 } else {
45 $paged = 1;
46 }
47
48 $post_per_page = SP_PC_Functions::pcp_post_per_page( $post_limit, $post_per_page, $paged );
49 if ( $post_per_page < 1 ) {
50 $post_per_page = isset( $view_options['post_per_page'] ) ? $view_options['post_per_page'] : '';
51 }
52 $offset = (int) $post_per_page * ( $paged - 1 );
53 $layout_preset = isset( $layout['pcp_layout_preset'] ) ? $layout['pcp_layout_preset'] : '';
54 $sticky_post_position = 'top_list' === $pcp_sticky_post ? 0 : 1;
55
56 if ( 'carousel_layout' === $layout_preset ) {
57 $post_per_page = ( $post_limit > 0 ) ? $post_limit : 999999;
58 $args = array(
59 'post_type' => $pcp_post_type,
60 'suppress_filters' => true,
61 'ignore_sticky_posts' => $sticky_post_position,
62 'posts_per_page' => $post_per_page,
63 'offset' => (int) $post_offset,
64 );
65 } else {
66 $args = array(
67 'post_type' => $pcp_post_type,
68 'suppress_filters' => true,
69 'ignore_sticky_posts' => $sticky_post_position,
70 'posts_per_page' => $post_per_page,
71 'paged' => $paged,
72 'offset' => (int) $offset + (int) $post_offset,
73 );
74 }
75
76 // Include specific posts.
77 $include_posts = isset( $view_options['pcp_include_only_posts'] ) ? $view_options['pcp_include_only_posts'] : '';
78 if ( ! empty( $include_posts ) ) {
79 $args['post__in'] = $include_posts;
80 $args['orderby'] = 'post__in';
81 }
82 // Exclude posts.
83 $exclude_post_set = isset( $view_options['pcp_exclude_post_set'] ) ? $view_options['pcp_exclude_post_set'] : '';
84 $exclude_too = ! empty( $exclude_post_set['pcp_exclude_too'] ) ? $exclude_post_set['pcp_exclude_too'] : array();
85 $current_post_id = in_array( 'current', $exclude_too, true ) ? array( get_the_ID() ) : array();
86 $sticky_post_ids = 'hide' === $pcp_sticky_post && in_array( 'post', $pcp_post_type, true ) ? get_option( 'sticky_posts' ) : array();
87 $exclude_posts = ! empty( $exclude_post_set['pcp_exclude_posts'] ) && isset( $exclude_post_set['pcp_exclude_posts'] ) ? $exclude_post_set['pcp_exclude_posts'] : '';
88 $exclude_posts_int = array();
89 if ( ! empty( $exclude_posts ) ) {
90 foreach ( $exclude_posts as $exclude_post ) {
91 $exclude_posts_int[] = intval( $exclude_post );
92 }
93 }
94 $exclude_post_list = array_merge( $exclude_posts_int, $sticky_post_ids, $current_post_id );
95 if ( ! empty( $exclude_post_list ) && empty( $include_posts ) ) {
96 $args['post__not_in'] = ( $exclude_post_list );
97 }
98
99 // Exclude password protected posts.
100 $password_protected = in_array( 'password_protected', $exclude_too, true );
101 if ( $password_protected ) {
102 $args['has_password'] = false;
103 }
104 // Exclude children posts.
105 $exclude_children = in_array( 'children', $exclude_too, true );
106 if ( $exclude_children ) {
107 $args['post_parent'] = 0;
108 }
109
110 $advanced_filters = isset( $view_options['pcp_advanced_filter'] ) && ! empty( $view_options['pcp_advanced_filter'] ) ? $view_options['pcp_advanced_filter'] : '';
111 if ( $advanced_filters ) {
112 foreach ( $advanced_filters as $advanced_filter ) {
113 switch ( $advanced_filter ) {
114 case 'taxonomy':
115 $taxonomy_types = isset( $view_options['pcp_filter_by_taxonomy']['pcp_taxonomy_and_terms'] ) && ! empty( $view_options['pcp_filter_by_taxonomy']['pcp_taxonomy_and_terms'] ) ? $view_options['pcp_filter_by_taxonomy']['pcp_taxonomy_and_terms'] : '';
116 if ( ! $taxonomy_types ) {
117 break;
118 }
119 $tax_settings = array();
120 foreach ( $taxonomy_types as $tax_type ) {
121 $taxonomy = isset( $tax_type['pcp_select_taxonomy'] ) ? $tax_type['pcp_select_taxonomy'] : '';
122 $terms = isset( $tax_type['pcp_select_terms'] ) ? $tax_type['pcp_select_terms'] : '';
123 if ( $taxonomy ) {
124 if ( $terms ) {
125 $operator = isset( $tax_type['pcp_taxonomy_term_operator'] ) ? $tax_type['pcp_taxonomy_term_operator'] : '';
126 if ( 'AND' === $operator && 1 === count( $terms ) ) {
127 $operator = 'IN';
128 }
129 $tax_settings[] = array(
130 'taxonomy' => $taxonomy,
131 'field' => 'term_id',
132 'terms' => $terms,
133 'operator' => $operator,
134 'include_children' => ( 'AND' === $operator ? 'false' : 'true' ),
135 );
136 }
137 }
138 }
139 if ( count( $tax_settings ) > 1 ) {
140 $tax_settings['relation'] = isset( $view_options['pcp_filter_by_taxonomy']['pcp_taxonomies_relation'] ) ? $view_options['pcp_filter_by_taxonomy']['pcp_taxonomies_relation'] : 'AND';
141 }
142 $args = array_merge( $args, array( 'tax_query' => $tax_settings ) );
143
144 break;
145 case 'author':
146 $author_include = isset( $view_options['pcp_filter_by_author']['pcp_select_author_by'] ) ? $view_options['pcp_filter_by_author']['pcp_select_author_by'] : '';
147 $author_exclude = isset( $view_options['pcp_filter_by_author']['pcp_select_author_not_by'] ) ? $view_options['pcp_filter_by_author']['pcp_select_author_not_by'] : '';
148 $wp37 = SP_PC_Functions::wp_version_compare( '3.7' );
149 if ( $author_include ) {
150 $args = array_merge(
151 $args,
152 $wp37 ? array( 'author__in' => array_map( 'intval', $author_include ) ) : array( 'author' => intval( $author_include[0] ) )
153 );
154 }
155 if ( $author_exclude && $wp37 ) {
156 $args = array_merge(
157 $args,
158 array( 'author__not_in' => array_map( 'intval', $author_exclude ) )
159 );
160 }
161 break;
162 case 'sortby':
163 $orderby = isset( $view_options['pcp_filter_by_order']['pcp_select_filter_orderby'] ) ? $view_options['pcp_filter_by_order']['pcp_select_filter_orderby'] : '';
164 $order = isset( $view_options['pcp_filter_by_order']['pcp_select_filter_order'] ) ? $view_options['pcp_filter_by_order']['pcp_select_filter_order'] : '';
165 $order_settings = array(
166 'orderby' => $orderby,
167 'order' => $orderby ? $order : '',
168 );
169 $args = array_merge( $args, $order_settings );
170 break;
171 case 'status':
172 $pcp_post_status = isset( $view_options['pcp_filter_by_status']['pcp_select_post_status'] ) && ! empty( $view_options['pcp_filter_by_status']['pcp_select_post_status'] ) ? $view_options['pcp_filter_by_status']['pcp_select_post_status'] : 'publish';
173 $args = array_merge( $args, array( 'post_status' => $pcp_post_status ) );
174 break;
175 case 'keyword':
176 $keyword_value = isset( $view_options['pcp_filter_by_keyword']['pcp_set_post_keyword'] ) && ! empty( $view_options['pcp_filter_by_keyword']['pcp_set_post_keyword'] ) ? $view_options['pcp_filter_by_keyword']['pcp_set_post_keyword'] : '';
177 if ( $keyword_value ) {
178 $args = array_merge(
179 $args,
180 array(
181 's' => $keyword_value,
182 )
183 );
184 }
185 break;
186 }
187 }
188 }
189 return $args;
190 }
191 }
192