PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.4.21
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.4.21
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.21, at public/helpers/class-pcp-queryinside.php

188 lines 8.1 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 $shortcode_id shortcode id.
29 * @param mixed $layout Upper layout based options.
30 * @return array
31 */
32 public static function get_filtered_content( $view_options, $shortcode_id, $layout ) {
33
34 $pcp_post_type = isset( $view_options['pcp_select_post_type'] ) && ! empty( $view_options['pcp_select_post_type'] ) ? $view_options['pcp_select_post_type'] : 'any';
35 $post_limit = isset( $view_options['pcp_post_limit'] ) ? $view_options['pcp_post_limit'] : '';
36 $post_per_page = isset( $view_options['post_per_page'] ) ? $view_options['post_per_page'] : '';
37 $post_offset = isset( $view_options['pcp_post_offset'] ) ? $view_options['pcp_post_offset'] : 0;
38 $pcp_sticky_post = isset( $view_options['pcp_sticky_post'] ) ? $view_options['pcp_sticky_post'] : 0;
39 $post_per_page = ( $post_per_page > $post_limit ) ? $post_limit : $post_per_page;
40
41 $paged_var = 'paged' . $shortcode_id;
42 $paged = ( ! empty( $_GET[ "$paged_var" ] ) ) ? sanitize_text_field( wp_unslash( $_GET[ "$paged_var" ] ) ) : 1;
43
44 $post_per_page = SP_PC_Functions::pcp_post_per_page( $post_limit, $post_per_page, $paged );
45 if ( $post_per_page < 1 ) {
46 $post_per_page = isset( $view_options['post_per_page'] ) ? $view_options['post_per_page'] : '';
47 }
48 $offset = (int) $post_per_page * ( $paged - 1 );
49 $layout_preset = isset( $layout['pcp_layout_preset'] ) ? $layout['pcp_layout_preset'] : '';
50 $sticky_post_position = 'top_list' === $pcp_sticky_post ? 0 : 1;
51
52 if ( 'carousel_layout' === $layout_preset ) {
53 $post_per_page = ( $post_limit > 0 ) ? $post_limit : 999999;
54 $args = array(
55 'post_type' => $pcp_post_type,
56 'suppress_filters' => true,
57 'ignore_sticky_posts' => $sticky_post_position,
58 'posts_per_page' => $post_per_page,
59 'offset' => (int) $post_offset,
60 );
61 } else {
62 $args = array(
63 'post_type' => $pcp_post_type,
64 'suppress_filters' => true,
65 'ignore_sticky_posts' => $sticky_post_position,
66 'posts_per_page' => $post_per_page,
67 'paged' => $paged,
68 'offset' => (int) $offset + (int) $post_offset,
69 );
70 }
71
72 // Include specific posts.
73 $include_posts = isset( $view_options['pcp_include_only_posts'] ) ? $view_options['pcp_include_only_posts'] : '';
74 if ( ! empty( $include_posts ) ) {
75 $args['post__in'] = $include_posts;
76 $args['orderby'] = 'post__in';
77 }
78 // Exclude posts.
79 $exclude_post_set = isset( $view_options['pcp_exclude_post_set'] ) ? $view_options['pcp_exclude_post_set'] : '';
80 $exclude_too = ! empty( $exclude_post_set['pcp_exclude_too'] ) ? $exclude_post_set['pcp_exclude_too'] : array();
81 $current_post_id = in_array( 'current', $exclude_too, true ) ? array( get_the_ID() ) : array();
82 $sticky_post_ids = 'hide' === $pcp_sticky_post && in_array( 'post', $pcp_post_type, true ) ? get_option( 'sticky_posts' ) : array();
83 $exclude_posts = ! empty( $exclude_post_set['pcp_exclude_posts'] ) && isset( $exclude_post_set['pcp_exclude_posts'] ) ? $exclude_post_set['pcp_exclude_posts'] : '';
84 $exclude_posts_int = array();
85 if ( ! empty( $exclude_posts ) ) {
86 foreach ( $exclude_posts as $exclude_post ) {
87 $exclude_posts_int[] = intval( $exclude_post );
88 }
89 }
90 $exclude_post_list = array_merge( $exclude_posts_int, $sticky_post_ids, $current_post_id );
91 if ( ! empty( $exclude_post_list ) && empty( $include_posts ) ) {
92 $args['post__not_in'] = ( $exclude_post_list );
93 }
94
95 // Exclude password protected posts.
96 $password_protected = in_array( 'password_protected', $exclude_too, true );
97 if ( $password_protected ) {
98 $args['has_password'] = false;
99 }
100 // Exclude children posts.
101 $exclude_children = in_array( 'children', $exclude_too, true );
102 if ( $exclude_children ) {
103 $args['post_parent'] = 0;
104 }
105
106 $advanced_filters = isset( $view_options['pcp_advanced_filter'] ) && ! empty( $view_options['pcp_advanced_filter'] ) ? $view_options['pcp_advanced_filter'] : '';
107 if ( $advanced_filters ) {
108 foreach ( $advanced_filters as $advanced_filter ) {
109 switch ( $advanced_filter ) {
110 case 'taxonomy':
111 $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'] : '';
112 if ( ! $taxonomy_types ) {
113 break;
114 }
115 $tax_settings = array();
116 foreach ( $taxonomy_types as $tax_type ) {
117 $taxonomy = isset( $tax_type['pcp_select_taxonomy'] ) ? $tax_type['pcp_select_taxonomy'] : '';
118 $terms = isset( $tax_type['pcp_select_terms'] ) ? $tax_type['pcp_select_terms'] : '';
119 if ( $taxonomy ) {
120 if ( $terms ) {
121 $operator = isset( $tax_type['pcp_taxonomy_term_operator'] ) ? $tax_type['pcp_taxonomy_term_operator'] : '';
122 if ( 'AND' === $operator && 1 === count( $terms ) ) {
123 $operator = 'IN';
124 }
125 $tax_settings[] = array(
126 'taxonomy' => $taxonomy,
127 'field' => 'term_id',
128 'terms' => $terms,
129 'operator' => $operator,
130 'include_children' => ( 'AND' === $operator ? 'false' : 'true' ),
131 );
132 }
133 }
134 }
135 if ( count( $tax_settings ) > 1 ) {
136 $tax_settings['relation'] = isset( $view_options['pcp_filter_by_taxonomy']['pcp_taxonomies_relation'] ) ? $view_options['pcp_filter_by_taxonomy']['pcp_taxonomies_relation'] : 'AND';
137 }
138 $args = array_merge( $args, array( 'tax_query' => $tax_settings ) );
139
140 break;
141 case 'author':
142 $author_include = isset( $view_options['pcp_filter_by_author']['pcp_select_author_by'] ) ? $view_options['pcp_filter_by_author']['pcp_select_author_by'] : '';
143 $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'] : '';
144 $wp37 = SP_PC_Functions::wp_version_compare( '3.7' );
145 if ( $author_include ) {
146 $args = array_merge(
147 $args,
148 $wp37 ? array( 'author__in' => array_map( 'intval', $author_include ) ) : array( 'author' => intval( $author_include[0] ) )
149 );
150 }
151 if ( $author_exclude && $wp37 ) {
152 $args = array_merge(
153 $args,
154 array( 'author__not_in' => array_map( 'intval', $author_exclude ) )
155 );
156 }
157 break;
158 case 'sortby':
159 $orderby = isset( $view_options['pcp_filter_by_order']['pcp_select_filter_orderby'] ) ? $view_options['pcp_filter_by_order']['pcp_select_filter_orderby'] : '';
160 $order = isset( $view_options['pcp_filter_by_order']['pcp_select_filter_order'] ) ? $view_options['pcp_filter_by_order']['pcp_select_filter_order'] : '';
161 $order_settings = array(
162 'orderby' => $orderby,
163 'order' => $orderby ? $order : '',
164 );
165 $args = array_merge( $args, $order_settings );
166 break;
167 case 'status':
168 $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';
169 $args = array_merge( $args, array( 'post_status' => $pcp_post_status ) );
170 break;
171 case 'keyword':
172 $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'] : '';
173 if ( $keyword_value ) {
174 $args = array_merge(
175 $args,
176 array(
177 's' => $keyword_value,
178 )
179 );
180 }
181 break;
182 }
183 }
184 }
185 return $args;
186 }
187 }
188