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

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