PluginProbe
Post Grid Gutenberg Blocks – PostX / 2.5.6
Post Grid Gutenberg Blocks – PostX v2.5.6
5.0.39 5.0.38 5.0.37 5.0.36 5.0.35 5.0.34 5.0.33 5.0.32 5.0.31 5.0.30 5.0.29 5.0.28 5.0.27 5.0.26 5.0.25 5.0.23 5.0.24 5.0.22 5.0.21 5.0.20 5.0.19 5.0.18 5.0.17 2.1.1 2.1.2 All 237 releases
← All changes | classes/Functions.php +1098 -2834 5.0.202.5.6 View file →
@@ -1,3008 +1,1272 @@
1 1 <?php
2 2 /**
3 3 * Common Functions.
4 - *
4 + *
5 5 * @package ULTP\Functions
6 6 * @since v.1.0.0
7 7 */
8 -
9 8 namespace ULTP;
10 9
11 -use ULTP\Includes\Durbin\Xpo;
10 +defined('ABSPATH') || exit;
12 11
13 -defined( 'ABSPATH' ) || exit;
14 -
15 12 /**
16 13 * Functions class.
17 - *
18 - * Provides utility functions for Ultimate Post plugin.
19 - *
20 - * @package ULTP\Functions
21 - * @since 4.0.0
22 14 */
23 -class Functions {
24 15
25 - /**
26 - * Funtion
27 - *
28 - * @since v.3.2.4
29 - *
30 - * Instance of the class.
31 - *
32 - * @var Functions | null
33 - */
34 - private static $instance = null;
16 +class Functions{
35 17
36 - /**
18 + /**
37 19 * Setup class.
38 20 *
39 21 * @since v.1.0.0
40 22 */
41 - public function __construct() {
42 - }
23 + public function __construct() {
24 + if (!isset($GLOBALS['ultp_settings'])) {
25 + $GLOBALS['ultp_settings'] = get_option('ultp_options');
26 + }
27 + }
43 28
44 - /**
45 - * Gets the instance of \ULTP\Functions class
46 - *
47 - * @return Functions
48 - * @since v.3.2.4
49 - */
50 - public static function get_instance() {
51 - if ( ! isset( $GLOBALS['ultp_settings'] ) ) {
52 - $GLOBALS['ultp_settings'] = get_option( 'ultp_options' );
53 - }
54 -
55 - if ( is_null( self::$instance ) ) {
56 - self::$instance = new self();
57 - }
58 -
59 - return self::$instance;
60 - }
61 -
62 - /**
29 + /**
63 30 * ID for the Builder Post or Normal Post
64 - *
65 - * @since v.2.3.1
31 + *
32 + * @since v.2.3.1
66 33 * @return NUMBER | is Builder or not
67 34 */
68 - public function get_ID() {
69 - $id = $this->is_builder();
70 - return $id ? $id : ( function_exists( 'is_shop' ) ? ( is_shop() ? wc_get_page_id( 'shop' ) : get_the_ID() ) : get_the_ID() );
71 - }
72 -
73 - /**
74 - * Checking Statement of Dynamic Site Builder
75 - *
76 - * @since v.2.3.1
35 + public function get_ID() {
36 + $id = $this->is_builder();
37 + return $id ? $id : (function_exists('is_shop') ? (is_shop() ? wc_get_page_id('shop') : get_the_ID()) : get_the_ID() );
38 + }
39 +
40 + /**
41 + * Checking Statement of Archive Builder
42 + *
43 + * @since v.2.3.1
77 44 * @return BOOLEAN | is Builder or not
78 45 */
79 - public function is_archive_builder() {
80 - $id = get_the_ID();
81 - return get_post_type( $id ) == 'ultp_builder' ? get_post_meta( $id, '__ultp_builder_type', true ) : false;
82 - }
46 + public function is_archive_builder() {
47 + return get_post_type( get_the_ID() ) == 'ultp_builder' ? true : false;
48 + }
83 49
84 - /**
50 +
51 + /**
85 52 * Set Link with the Parameters
86 - *
87 - * @since v.1.1.0
88 - * @param string $url .
89 - * @param string $tag .
53 + *
54 + * @since v.1.1.0
90 55 * @return STRING | URL with Arg
91 56 */
92 - public function get_premium_link( $url = null, $tag = '' ) {
93 - return Xpo::generate_utm_link(
94 - array(
95 - 'url' => $url,
96 - 'utmKey' => $tag,
97 - )
98 - );
99 - }
57 + public function get_premium_link( $url = 'https://www.wpxpo.com/postx/pricing/' ) {
58 + $affiliate_id = apply_filters( 'ultp_affiliate_id', FALSE );
59 + $arg = array( 'utm_source' => 'go_premium' );
60 + if ( ! empty( $affiliate_id ) ) {
61 + $arg[ 'ref' ] = esc_attr( $affiliate_id );
62 + }
63 + return add_query_arg( $arg, $url );
64 + }
100 65
101 66
102 - /**
103 - * Quick Query
104 - *
105 - * @since v.1.1.0
106 - * @param ARRAY $prams Quick query parameters.
107 - * @param ARRAY $args Query arguments to modify.
108 - * @return ARRAY
67 + /**
68 + * Get Width and Height of the Image
69 + *
70 + * @since v.1.1.0
71 + * @return STRING | Image Size
109 72 */
110 - public function get_quick_query( $prams, $args ) {
111 - switch ( $prams['queryQuick'] ) {
112 - case 'related_posts':
113 - global $post;
114 - $p_id = isset( $post->ID ) && $post->ID ? $post->ID : ( isset( $_POST['postId'] ) ? sanitize_text_field( $_POST['postId'] ) : '' ); //phpcs:disable WordPress.Security.NonceVerification.Missing
115 - if ( $p_id ) {
116 - $args['post__not_in'] = array( $p_id );
117 - }
118 - break;
119 - case 'related_tag':
120 - global $post;
121 - $p_id = isset( $post->ID ) && $post->ID ? $post->ID : ( isset( $prams['current_post'] ) && $prams['current_post'] ? $prams['current_post'] : ( isset( $_POST['postId'] ) ? sanitize_text_field( $_POST['postId'] ) : '' ) ); //phpcs:disable ordPress.Security.NonceVerification.Missing
122 - if ( $p_id ) {
123 - $args['tax_query'] = array(
124 - array(
125 - 'taxonomy' => 'post_tag',
126 - 'terms' => $this->get_terms_id( $p_id, 'post_tag' ),
127 - 'field' => 'term_id',
128 - ),
129 - );
130 - $args['post__not_in'] = array( $p_id );
131 - }
132 - break;
133 - case 'related_category':
134 - global $post;
135 - $p_id = isset( $post->ID ) && $post->ID ? $post->ID : ( isset( $prams['current_post'] ) && $prams['current_post'] ? $prams['current_post'] : ( isset( $_POST['postId'] ) ? sanitize_text_field( $_POST['postId'] ) : '' ) ); //phpcs:disable ordPress.Security.NonceVerification.Missing
136 - if ( $p_id ) {
137 - $args['tax_query'] = array(
138 - array(
139 - 'taxonomy' => 'category',
140 - 'terms' => $this->get_terms_id( $p_id, 'category' ),
141 - 'field' => 'term_id',
142 - ),
143 - );
144 - $args['post__not_in'] = array( $p_id );
145 - }
146 - break;
147 - case 'related_cat_tag':
148 - global $post;
149 - $p_id = isset( $post->ID ) && $post->ID ? $post->ID : ( isset( $prams['current_post'] ) && $prams['current_post'] ? $prams['current_post'] : ( isset( $_POST['postId'] ) ? sanitize_text_field( $_POST['postId'] ) : '' ) ); //phpcs:disable ordPress.Security.NonceVerification.Missing
150 - if ( $p_id ) {
151 - $args['tax_query'] = array(
152 - array(
153 - 'taxonomy' => 'post_tag',
154 - 'terms' => $this->get_terms_id( $p_id, 'post_tag' ),
155 - 'field' => 'term_id',
156 - ),
157 - array(
158 - 'taxonomy' => 'category',
159 - 'terms' => $this->get_terms_id( $p_id, 'category' ),
160 - 'field' => 'term_id',
161 - ),
162 - );
163 - $args['post__not_in'] = array( $p_id );
164 - }
165 - break;
166 - case 'sticky_posts':
167 - $sticky = get_option( 'sticky_posts' );
168 - if ( is_array( $sticky ) ) {
169 - rsort( $sticky );
170 - // $sticky = array_slice($sticky, 0, $args['posts_per_page']);
171 - }
172 - $args['ignore_sticky_posts'] = 1;
173 - $args['post__in'] = $sticky;
174 - break;
175 - case 'latest_post_published':
176 - $args['orderby'] = 'date';
177 - $args['order'] = 'DESC';
178 - $args['ignore_sticky_posts'] = 1;
179 - break;
180 - case 'latest_post_modified':
181 - $args['orderby'] = 'modified';
182 - $args['order'] = 'DESC';
183 - $args['ignore_sticky_posts'] = 1;
184 - break;
185 - case 'oldest_post_published':
186 - $args['orderby'] = 'date';
187 - $args['order'] = 'ASC';
188 - break;
189 - case 'oldest_post_modified':
190 - $args['orderby'] = 'modified';
191 - $args['order'] = 'ASC';
192 - break;
193 - case 'alphabet_asc':
194 - $args['orderby'] = 'title';
195 - $args['order'] = 'ASC';
196 - break;
197 - case 'alphabet_desc':
198 - $args['orderby'] = 'title';
199 - $args['order'] = 'DESC';
200 - break;
201 - case 'random_post':
202 - $args['orderby'] = 'rand';
203 - $args['order'] = 'ASC';
204 - break;
205 - case 'random_post_7_days':
206 - $args['orderby'] = 'rand';
207 - $args['order'] = 'ASC';
208 - $args['date_query'] = array( array( 'after' => '1 week ago' ) );
209 - break;
210 - case 'random_post_30_days':
211 - $args['orderby'] = 'rand';
212 - $args['order'] = 'ASC';
213 - $args['date_query'] = array( array( 'after' => '1 month ago' ) );
214 - break;
215 - case 'most_comment':
216 - $args['orderby'] = 'comment_count';
217 - $args['order'] = 'DESC';
218 - break;
219 - case 'most_comment_1_day':
220 - $args['orderby'] = 'comment_count';
221 - $args['order'] = 'DESC';
222 - $args['date_query'] = array( array( 'after' => '1 day ago' ) );
223 - break;
224 - case 'most_comment_7_days':
225 - $args['orderby'] = 'comment_count';
226 - $args['order'] = 'DESC';
227 - $args['date_query'] = array( array( 'after' => '1 week ago' ) );
228 - break;
229 - case 'most_comment_30_days':
230 - $args['orderby'] = 'comment_count';
231 - $args['order'] = 'DESC';
232 - $args['date_query'] = array( array( 'after' => '1 month ago' ) );
233 - break;
234 - case 'popular_post_1_day_view':
235 - $args['meta_key'] = '__post_views_count';
236 - $args['orderby'] = 'meta_value_num';
237 - $args['order'] = 'DESC';
238 - $args['date_query'] = array( array( 'after' => '1 day ago' ) );
239 - break;
240 - case 'popular_post_7_days_view':
241 - $args['meta_key'] = '__post_views_count';
242 - $args['orderby'] = 'meta_value_num';
243 - $args['order'] = 'DESC';
244 - $args['date_query'] = array( array( 'after' => '1 week ago' ) );
245 - break;
246 - case 'popular_post_30_days_view':
247 - $args['meta_key'] = '__post_views_count';
248 - $args['orderby'] = 'meta_value_num';
249 - $args['order'] = 'DESC';
250 - $args['date_query'] = array( array( 'after' => '1 month ago' ) );
251 - break;
252 - case 'popular_post_all_times_view':
253 - $args['meta_key'] = '__post_views_count';
254 - $args['orderby'] = 'meta_value_num';
255 - $args['order'] = 'DESC';
256 - break;
257 - default:
258 - // code...
259 - break;
260 - }
261 - return $args;
262 - }
73 + public function get_size($name = ''){
74 + global $_wp_additional_image_sizes;
75 + $image_size = $name ? ( isset($_wp_additional_image_sizes[$name]) ? $_wp_additional_image_sizes[$name] : array_values($_wp_additional_image_sizes)[0] ) : array_values($_wp_additional_image_sizes)[0];
76 +
77 + return ' width="'.$image_size['width'].'" height="'.$image_size['height'].'" ';
78 + }
263 79
264 - /**
265 - * Get All Term IDs for a Post in a Taxonomy
266 - *
267 - * @since v.2.4.12
268 - * @param INT|STRING $id Post ID to get terms for.
269 - * @param STRING $type Taxonomy name (e.g. 'category', 'post_tag').
270 - * @return ARRAY
80 +
81 + /**
82 + * Image Placeholder
83 + *
84 + * @since v.1.1.0
85 + * @return STRING | Image Placeholder
271 86 */
272 - public function get_terms_id( $id, $type ) {
273 - $data = array();
274 - $arr = get_the_terms( $id, $type );
275 - if ( is_array( $arr ) ) {
276 - foreach ( $arr as $key => $val ) {
277 - $data[] = $val->term_id;
278 - }
279 - }
280 - return $data;
281 - }
87 + public function img_placeholder($type = 'small') {
88 + switch ($type) {
89 + case 'small':
90 + return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAG4AAABLAQMAAACr9CA9AAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAABZJREFUOI1jYMADmEe5o9xR7iiXQi4A4BsA388WUyMAAAAASUVORK5CYII=';
91 + break;
282 92
283 - /**
284 - * Get all reusable block IDs referenced in a post's content
285 - *
286 - * @since v.1.1.0
287 - * @param INT|STRING $post_id .
288 - * @return ARRAY
93 + case 'wide':
94 + return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAKCAYAAADVTVykAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAB9JREFUeNpi/P//P8NAAiaGAQajDhh1wKgDRh0AEGAAQTcDEcKDrpMAAAAASUVORK5CYII=';
95 + break;
96 +
97 + case 'square':
98 + return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEX///+nxBvIAAAAAXRSTlMAQObYZgAAAApJREFUCJljYAAAAAIAAfRxZKYAAAAASUVORK5CYII=';
99 + break;
100 +
101 + case 'slider':
102 + return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKYAAABkCAMAAAA7drv6AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAAZQTFRF////AAAAVcLTfgAAAAF0Uk5TAEDm2GYAAAAqSURBVHja7MEBDQAAAMKg909tDjegAAAAAAAAAAAAAAAAAAAAAH5NgAEAQTwAAWZtItYAAAAASUVORK5CYII=';
103 + break;
104 +
105 + default:
106 + return 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYYAAADcAQMAAABOLJSDAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAACJJREFUaIHtwTEBAAAAwqD1T20ND6AAAAAAAAAAAAAA4N8AKvgAAUFIrrEAAAAASUVORK5CYII=';
107 + break;
108 + }
109 + }
110 +
111 +
112 + /**
113 + * Quick Query
114 + *
115 + * @since v.1.1.0
116 + * @return ARRAY | Query Arg
289 117 */
290 - public function get_reusable_ids( $post_id ) {
291 - $reusable_id = array();
292 - if ( $post_id ) {
293 - $post = get_post( $post_id );
294 - if ( isset( $post->post_content ) ) {
295 - if (
296 - has_blocks( $post->post_content ) &&
297 - strpos( $post->post_content, 'wp:block' ) &&
298 - strpos( $post->post_content, '"ref"' ) !== false
299 - ) {
300 - $blocks = parse_blocks( $post->post_content );
301 - foreach ( $blocks as $key => $value ) {
302 - if ( isset( $value['attrs']['ref'] ) ) {
303 - $reusable_id[] = $value['attrs']['ref'];
304 - }
305 - }
306 - }
307 - }
308 - }
309 - return $reusable_id;
310 - }
118 + public function get_quick_query($prams, $args) {
119 + switch ($prams['queryQuick']) {
120 + case 'related_posts':
121 + global $post;
122 + if (isset($post->ID)) {
123 + $args['post__not_in'] = array($post->ID);
124 + }
125 + break;
126 + case 'related_tag':
127 + global $post;
128 + if (isset($post->ID)) {
129 + $args['tax_query'] = array(
130 + array(
131 + 'taxonomy' => 'post_tag',
132 + 'terms' => $this->get_terms_id($post->ID, 'post_tag'),
133 + 'field' => 'term_id',
134 + )
135 + );
136 + $args['post__not_in'] = array($post->ID);
137 + }
138 + break;
139 + case 'related_category':
140 + global $post;
141 + if (isset($post->ID)) {
142 + $args['tax_query'] = array(
143 + array(
144 + 'taxonomy' => 'category',
145 + 'terms' => $this->get_terms_id($post->ID, 'category'),
146 + 'field' => 'term_id',
147 + )
148 + );
149 + $args['post__not_in'] = array($post->ID);
150 + }
151 + break;
152 + case 'related_cat_tag':
153 + global $post;
154 + if (isset($post->ID)) {
155 + $args['tax_query'] = array(
156 + array(
157 + 'taxonomy' => 'post_tag',
158 + 'terms' => $this->get_terms_id($post->ID, 'post_tag'),
159 + 'field' => 'term_id',
160 + ),
161 + array(
162 + 'taxonomy' => 'category',
163 + 'terms' => $this->get_terms_id($post->ID, 'category'),
164 + 'field' => 'term_id',
165 + )
166 + );
167 + $args['post__not_in'] = array($post->ID);
168 + }
169 + break;
170 + case 'sticky_posts':
171 + $sticky = get_option('sticky_posts');
172 + if (is_array($sticky)) {
173 + rsort($sticky);
174 + $sticky = array_slice($sticky, 0, $args['posts_per_page']);
175 + }
176 + $args['ignore_sticky_posts'] = 1;
177 + $args['post__in'] = $sticky;
178 + break;
179 + case 'latest_post_published':
180 + $args['orderby'] = 'date';
181 + $args['order'] = 'DESC';
182 + $args['ignore_sticky_posts'] = 1;
183 + break;
184 + case 'latest_post_modified':
185 + $args['orderby'] = 'modified';
186 + $args['order'] = 'DESC';
187 + $args['ignore_sticky_posts'] = 1;
188 + break;
189 + case 'oldest_post_published':
190 + $args['orderby'] = 'date';
191 + $args['order'] = 'ASC';
192 + break;
193 + case 'oldest_post_modified':
194 + $args['orderby'] = 'modified';
195 + $args['order'] = 'ASC';
196 + break;
197 + case 'alphabet_asc':
198 + $args['orderby'] = 'title';
199 + $args['order'] = 'ASC';
200 + break;
201 + case 'alphabet_desc':
202 + $args['orderby'] = 'title';
203 + $args['order'] = 'DESC';
204 + break;
205 + case 'random_post':
206 + $args['orderby'] = 'rand';
207 + $args['order'] = 'ASC';
208 + break;
209 + case 'random_post_7_days':
210 + $args['orderby'] = 'rand';
211 + $args['order'] = 'ASC';
212 + $args['date_query'] = array( array( 'after' => '1 week ago') );
213 + break;
214 + case 'random_post_30_days':
215 + $args['orderby'] = 'rand';
216 + $args['order'] = 'ASC';
217 + $args['date_query'] = array( array( 'after' => '1 month ago') );
218 + break;
219 + case 'most_comment':
220 + $args['orderby'] = 'comment_count';
221 + $args['order'] = 'DESC';
222 + break;
223 + case 'most_comment_1_day':
224 + $args['orderby'] = 'comment_count';
225 + $args['order'] = 'DESC';
226 + $args['date_query'] = array( array( 'after' => '1 day ago') );
227 + break;
228 + case 'most_comment_7_days':
229 + $args['orderby'] = 'comment_count';
230 + $args['order'] = 'DESC';
231 + $args['date_query'] = array( array( 'after' => '1 week ago') );
232 + break;
233 + case 'most_comment_30_days':
234 + $args['orderby'] = 'comment_count';
235 + $args['order'] = 'DESC';
236 + $args['date_query'] = array( array( 'after' => '1 month ago') );
237 + break;
238 + case 'popular_post_1_day_view':
239 + $args['meta_key'] = '__post_views_count';
240 + $args['orderby'] = 'meta_value meta_value_num';
241 + $args['order'] = 'DESC';
242 + $args['date_query'] = array( array( 'after' => '1 day ago') );
243 + break;
244 + case 'popular_post_7_days_view':
245 + $args['meta_key'] = '__post_views_count';
246 + $args['orderby'] = 'meta_value meta_value_num';
247 + $args['order'] = 'DESC';
248 + $args['date_query'] = array( array( 'after' => '1 week ago') );
249 + break;
250 + case 'popular_post_30_days_view':
251 + $args['meta_key'] = '__post_views_count';
252 + $args['orderby'] = 'meta_value meta_value_num';
253 + $args['order'] = 'DESC';
254 + $args['date_query'] = array( array( 'after' => '1 month ago') );
255 + break;
256 + case 'popular_post_all_times_view':
257 + $args['meta_key'] = '__post_views_count';
258 + $args['orderby'] = 'meta_value meta_value_num';
259 + $args['order'] = 'DESC';
260 + break;
261 + default:
262 + # code...
263 + break;
264 + }
265 + return $args;
266 + }
311 267
312 - /**
313 - * Safely reads file contents using WordPress Filesystem API
314 - *
315 - * @since v.4.1.8
316 - * @param STRING $path .
317 - * @return STRING|ARRAY.
268 + /**
269 + * Get All Term ID as Array
270 + *
271 + * @since v.2.4.12
272 + * @return ARRAY | Query Arg
318 273 */
319 - public function get_path_file_contents( $path ) {
320 - global $wp_filesystem;
321 - if ( ! $wp_filesystem ) {
322 - require_once ABSPATH . 'wp-admin/includes/file.php';
323 - $init_fs = WP_Filesystem();
324 - if ( ! $init_fs ) {
325 - return '';
326 - }
327 - }
274 + public function get_terms_id($id, $type) {
275 + $data = array();
276 + $arr = get_the_terms($id, $type);
277 + if (is_array($arr)) {
278 + foreach ($arr as $key => $val) {
279 + $data[] = $val->term_id;
280 + }
281 + }
282 + return $data;
283 + }
328 284
329 - if ( $wp_filesystem->exists( $path ) ) {
330 - return $wp_filesystem->get_contents( $path );
331 - } else {
332 - return '';
333 - }
334 - }
285 + /**
286 + * Get All Reusable ID
287 + *
288 + * @since v.1.1.0
289 + * @return ARRAY | Query Arg
290 + */
291 + public function reusable_id($post_id){
292 + $reusable_id = array();
293 + if($post_id){
294 + $post = get_post($post_id);
295 + if (has_blocks($post->post_content)) {
296 + $blocks = parse_blocks($post->post_content);
297 + foreach ($blocks as $key => $value) {
298 + if(isset($value['attrs']['ref'])) {
299 + $reusable_id[] = $value['attrs']['ref'];
300 + }
301 + }
302 + }
303 + }
304 + return $reusable_id;
305 + }
306 +
335 307
336 - /**
337 - * Builds and returns inline CSS for a post and its reusable blocks
338 - *
339 - * @since v.4.1.8
340 - * @param INT|STRING $post_id .
341 - * @param BOOLEAN $call_common .
342 - * @return STRING|ARRAY.
308 + /**
309 + * Set CSS Style
310 + *
311 + * @since v.1.1.0
312 + * @return ARRAY | Query Arg
343 313 */
344 - public function build_css_for_inline_print( $post_id, $call_common = true ) {
345 - if ( $post_id ) {
346 - $upload_dir_url = wp_get_upload_dir();
314 + public function set_css_style($post_id, $shortcode = false){
315 + if( $post_id ){
316 + $upload_dir_url = wp_get_upload_dir();
347 317 $upload_css_dir_url = trailingslashit( $upload_dir_url['basedir'] );
348 -
349 - $css_dir_url = trailingslashit( $upload_dir_url['baseurl'] );
350 - if ( is_ssl() ) {
351 - $css_dir_url = str_replace( 'http://', 'https://', $css_dir_url );
352 - }
353 - $reusable_css = '';
354 - $reusable_id = $this->get_reusable_ids( $post_id );
355 - if ( ! empty( $reusable_id ) ) {
356 - foreach ( $reusable_id as $id ) {
357 - $reusable_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$id}.css";
358 - if ( file_exists( $reusable_dir_path ) ) {
359 - $reusable_css .= $this->get_path_file_contents( $reusable_dir_path );
360 - } else {
361 - $reusable_css .= get_post_meta( $reusable_id, '_ultp_css', true );
362 - }
318 + $css_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
319 +
320 + $css_dir_url = trailingslashit( $upload_dir_url['baseurl'] );
321 + if (is_ssl()) {
322 + $css_dir_url = str_replace('http://', 'https://', $css_dir_url);
323 + }
324 +
325 + // Reusable CSS
326 + $reusable_id = ultimate_post()->reusable_id($post_id);
327 + foreach ( $reusable_id as $id ) {
328 + $reusable_dir_path = $upload_css_dir_url."ultimate-post/ultp-css-{$id}.css";
329 + if (file_exists( $reusable_dir_path )) {
330 + $css_url = $css_dir_url . "ultimate-post/ultp-css-{$id}.css";
331 + wp_enqueue_style( "ultp-post-{$id}", $css_url, array(), ULTP_VER, 'all' );
332 + }else{
333 + $css = get_post_meta($id, '_ultp_css', true);
334 + if( $css ) {
335 + wp_enqueue_style("ultp-post-{$id}", $css, false, ULTP_VER);
336 + }
363 337 }
364 - }
365 -
366 - $css_dir_path = $upload_css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
367 - $css = '';
368 - if ( file_exists( $css_dir_path ) ) {
369 - $css = $this->get_path_file_contents( $css_dir_path );
370 - } else {
371 - $css = get_post_meta( $post_id, '_ultp_css', true );
372 - }
373 - if ( $reusable_css . $css ) {
374 - if ( $call_common ) {
375 - $this->register_scripts_common();
376 - }
377 - return '<style id="ultp-post-' . $post_id . '" type="text/css">' . wp_strip_all_tags( $reusable_css . $css ) . '</style>';
378 - }
338 + }
339 +
340 + if (isset($_GET['et_fb']) || (isset($_GET['action']) && $_GET['action'] =='elementor') || $shortcode) {
341 + return '<style type="text/css">'.get_post_meta($post_id, '_ultp_css', true).'</style>';
342 + } else {
343 + if ( file_exists( $css_dir_path ) ) {
344 + $css_url = $css_dir_url . "ultimate-post/ultp-css-{$post_id}.css";
345 + wp_enqueue_style( "ultp-post-{$post_id}", $css_url, array(), ULTP_VER, 'all' );
346 + } else {
347 + $css = get_post_meta($post_id, '_ultp_css', true);
348 + if( $css ) {
349 + wp_enqueue_style("ultp-post-{$post_id}", $css, false, ULTP_VER);
350 + }
351 + }
352 + }
379 353 }
380 - return '';
381 - }
354 + }
382 355
383 356
384 - /**
357 + /**
385 358 * Get Global Plugin Settings
386 - *
387 - * @since v.1.0.0
388 - * @param STRING $key of the Option .
389 - * @return ARRAY|STRING .
359 + *
360 + * @since v.1.0.0
361 + * @param STRING | Key of the Option
362 + * @return ARRAY | STRING
390 363 */
391 - public function get_setting( $key = '' ) {
392 - $data = $GLOBALS['ultp_settings'];
393 - if ( $key != '' ) {
394 - return isset( $data[ $key ] ) ? $data[ $key ] : '';
395 - } else {
396 - return $data;
397 - }
398 - }
364 + public function get_setting($key = ''){
365 + $data = $GLOBALS['ultp_settings'];
366 + if ($key != '') {
367 + return isset($data[$key]) ? $data[$key] : '';
368 + } else {
369 + return $data;
370 + }
371 + }
399 372
400 373
401 - /**
374 + /**
402 375 * Set Option Settings
403 - *
404 - * @since v.1.0.0
405 - * @param STRING | $key of the Option (STRING) .
406 - * @param STRING | $val Value (STRING) .
376 + *
377 + * @since v.1.0.0
378 + * @param STRING | Key of the Option (STRING), Value (STRING)
379 + * @return NULL
407 380 */
408 - public function set_setting( $key = '', $val = '' ) {
409 - if ( $key != '' ) {
410 - $data = $GLOBALS['ultp_settings'];
411 - $data[ $key ] = $val;
412 - update_option( 'ultp_options', $data );
413 - $GLOBALS['ultp_settings'] = $data;
414 - do_action( 'ultp_settings_updated', $key, $val );
415 - }
416 - }
381 + public function set_setting($key = '', $val = '') {
382 + if($key != ''){
383 + $data = $GLOBALS['ultp_settings'];
384 + $data[$key] = $val;
385 + update_option('ultp_options', $data);
386 + $GLOBALS['ultp_settings'] = $data;
387 + }
388 + }
417 389
418 390
419 - /**
391 + /**
420 392 * Get Image HTML
421 - *
422 - * @since v.1.0.0
423 - * @param STRING | $url .
424 - * @param STRING | $size .
425 - * @param STRING | $class .
426 - * @param STRING | $alt .
427 - * @param STRING | $lazy .
428 - * @param ARRAY | $darkImg .
429 - * @param STRING | $srcset .
393 + *
394 + * @since v.1.0.0
395 + * @param | URL (STRING) | size (STRING) | class (STRING) | alt (STRING)
430 396 * @return STRING
431 397 */
432 - public function get_image_html( $url = '', $size = 'full', $class = '', $alt = '', $lazy = '', $darkImg = array(), $srcset = '' ) {
433 - $class = sanitize_html_class( $class );
434 - $alt = preg_replace( '/[^A-Za-z0-9_ -]/', '', $alt );
435 - $hasDarkImage = ( $darkImg['enable'] && $darkImg['url'] ) ? ' ultp-light-image-block ' : '';
436 - $alt = $alt ? ' alt="' . $alt . '" ' : '';
437 - $lazy_data = $lazy ? ' loading="lazy"' : '';
398 + public function get_image_html($url = '', $size = 'full', $class = '', $alt = '', $lazy = ''){
399 + $alt = $alt ? ' alt="'.$alt.'" ' : '';
400 + $lazy_data = $lazy ? ' loading="lazy"' : '';
401 + $class = $class ? ' class="'.$class.'" ' : '';
402 + return '<img '.$lazy_data.$class.$alt.' src="'.$url.'" />';
403 + }
438 404
439 - $dlMode = isset( $_COOKIE['ultplocalDLMode'] ) ? $_COOKIE['ultplocalDLMode'] : ultimate_post()->get_dl_mode();
440 405
441 - $lightMode = $hasDarkImage ? ( $dlMode == 'ultplight' ? '' : 'inactive ' ) : '';
442 - $darkMode = $hasDarkImage ? ( $hasDarkImage && $dlMode == 'ultpdark' ? '' : ' inactive ' ) : '';
443 -
444 - $image = '<img ' . $lazy_data . $srcset . ' class="' . $class . $hasDarkImage . $lightMode . '" ' . $alt . ' src="' . esc_url( $url ) . '" />';
445 - if ( $hasDarkImage ) {
446 - $image .= '<img ' . $lazy_data . $darkImg['srcset'] . ' class="' . $class . $darkMode . ' ultp-dark-image-block " ' . $alt . ' src="' . esc_url( $darkImg['url'] ) . '" />';
447 - }
448 - return $image;
449 - }
450 -
451 -
452 - /**
406 + /**
453 407 * Get Image HTML
454 - *
455 - * @since v.1.0.0
456 - * @param STRING | $attach_id .
457 - * @param STRING | $size .
458 - * @param STRING | $class .
459 - * @param STRING | $alt .
460 - * @param STRING | $srcset .
461 - * @param STRING | $lazy .
408 + *
409 + * @since v.1.0.0
410 + * @param | Attach ID (STRING) | size (STRING) | class (STRING) | alt (STRING)
462 411 * @return STRING
463 412 */
464 - public function get_image( $attach_id, $size = 'full', $class = '', $alt = '', $srcset = '', $lazy = '' ) {
465 - $img_alt = get_post_meta( $attach_id, '_wp_attachment_image_alt', true );
466 - $alt = $img_alt ? $img_alt : $alt;
467 - $alt = $alt ? ' alt="' . esc_html( $alt ) . '" ' : '';
468 - $class = $class ? ' class="' . $class . '" ' : '';
469 - $size = ( ultimate_post()->get_setting( 'disable_image_size' ) == 'yes' && strpos( $size, 'ultp_layout_' ) !== false ) ? 'full' : $size;
470 - $lazy_data = $lazy ? ' loading="lazy"' : '';
471 - $srcset_data = $srcset ? ' srcset="' . esc_attr( wp_get_attachment_image_srcset( $attach_id ) ) . '"' : '';
472 - return '<img ' . $srcset_data . $lazy_data . $class . $alt . ' src="' . wp_get_attachment_image_url( $attach_id, $size ) . '" />';
473 - }
413 + public function get_image($attach_id, $size = 'full', $class = '', $alt = '', $srcset = '', $lazy = ''){
414 + $alt = $alt ? ' alt="'.$alt.'" ' : '';
415 + $class = $class ? ' class="'.$class.'" ' : '';
416 + $size = ( ultimate_post()->get_setting('disable_image_size') == 'yes' && strpos($size, 'ultp_layout_') !== false ) ? 'full' : $size;
417 + $lazy_data = $lazy ? ' loading="lazy"' : '';
418 + $srcset_data = $srcset ? ' srcset="'.esc_attr(wp_get_attachment_image_srcset($attach_id)).'"' : '';
419 + return '<img '.$srcset_data.$lazy_data.$class.$alt.' src="'.wp_get_attachment_image_url( $attach_id, $size ).'" />';
420 + }
474 421
422 +
423 + /**
424 + * Setup Initial Data Set
425 + *
426 + * @since v.1.0.0
427 + * @return NULL
428 + */
429 + public function init_set_data(){
430 + $data = get_option( 'ultp_options', array() );
431 + $init_data = array(
432 + 'css_save_as' => 'wp_head',
433 + 'preloader_style' => 'style1',
434 + 'preloader_color' => '#037fff',
435 + 'container_width' => '1140',
436 + 'hide_import_btn' => '',
437 + 'disable_image_size'=> '',
438 + 'ultp_templates' => 'true',
439 + 'ultp_elementor' => 'true',
440 + 'ultp_table_of_content'=> 'true',
441 + 'post_grid_1' => 'yes',
442 + 'post_grid_2' => 'yes',
443 + 'post_grid_3' => 'yes',
444 + 'post_grid_4' => 'yes',
445 + 'post_grid_5' => 'yes',
446 + 'post_grid_6' => 'yes',
447 + 'post_grid_7' => 'yes',
448 + 'post_list_1' => 'yes',
449 + 'post_list_2' => 'yes',
450 + 'post_list_3' => 'yes',
451 + 'post_list_4' => 'yes',
452 + 'post_module_1' => 'yes',
453 + 'post_module_2' => 'yes',
454 + 'post_slider_1' => 'yes',
455 + 'heading' => 'yes',
456 + 'image' => 'yes',
457 + 'taxonomy' => 'yes',
458 + 'wrapper' => 'yes',
459 + 'news_ticker' => 'yes'
460 + );
461 + if (empty($data)) {
462 + update_option('ultp_options', $init_data);
463 + $GLOBALS['ultp_settings'] = $init_data;
464 + } else {
465 + foreach ($init_data as $key => $single) {
466 + if (!isset($data[$key])) {
467 + $data[$key] = $single;
468 + }
469 + }
470 + update_option('ultp_options', $data);
471 + $GLOBALS['ultp_settings'] = $data;
472 + }
473 + }
475 474
476 - /**
475 +
476 + /**
477 477 * Get Excerpt Text
478 - *
479 - * @since v.1.0.0
480 - * @param STRING | $post_id .
481 - * @param NUMBER | $limit .
478 + *
479 + * @since v.1.0.0
480 + * @param | Post ID (STRING) | Limit (NUMBER)
482 481 * @return STRING
483 482 */
484 - public function excerpt( $post_id, $limit = 55 ) {
485 - $content = preg_replace( '/(\[postx_template[\s\w="]*)]/m', '', get_the_excerpt( $post_id ) ); // Remove postx_template shortcode form Content
486 - return apply_filters( 'the_excerpt', wp_trim_words( $content, $limit ) );
487 - }
483 + public function excerpt( $post_id, $limit = 55 ) {
484 + return apply_filters( 'the_excerpt', wp_trim_words( get_the_content( $post_id ) , $limit ) );
485 + }
488 486
489 - /**
490 - * Builder Attributes
491 - *
492 - * @since v.1.0.0
493 - * @param STRING | $type .
494 - * @return STRING
495 - */
496 - public function get_builder_attr( $type ) {
497 - $builder_data = '';
498 - if ( $type == 'archiveBuilder' || $type == 'archiveBuilderFilter' ) {
499 - if ( is_archive() ) {
500 - if ( is_date() ) {
501 - if ( is_year() ) {
502 - $builder_data = 'date###' . get_the_date( 'Y' );
503 - } elseif ( is_month() ) {
504 - $builder_data = 'date###' . get_the_date( 'Y-n' );
505 - } elseif ( is_day() ) {
506 - $builder_data = 'date###' . get_the_date( 'Y-n-j' );
507 - }
508 - } elseif ( is_author() ) {
509 - $builder_data = 'author###' . get_the_author_meta( 'ID' );
510 - } else {
511 - $obj = get_queried_object();
512 - if ( isset( $obj->taxonomy ) ) {
513 - $builder_data = 'taxonomy###' . $obj->taxonomy . '###' . $obj->slug;
514 - }
515 - }
516 - } elseif ( is_search() ) {
517 - $builder_data = 'search###' . get_search_query( true );
518 - }
519 - }
520 - if ( $type == 'archiveBuilderFilter' ) {
521 - return $builder_data ? $builder_data : '';
522 - }
523 - return $builder_data ? 'data-builder="' . $builder_data . '"' : '';
524 - }
487 + public function get_builder_attr() {
488 + $builder_data = '';
489 + if (is_archive()) {
490 + if (is_date()) {
491 + if ( is_year() ) {
492 + $builder_data = 'date###'.get_the_date('Y');
493 + } else if ( is_month() ) {
494 + $builder_data = 'date###'.get_the_date('Y-n');
495 + } else if ( is_day() ) {
496 + $builder_data = 'date###'.get_the_date('Y-n-j');
497 + }
498 + } else if (is_author()) {
499 + $builder_data = 'author###'.get_the_author_meta('ID');
500 + } else {
501 + $obj = get_queried_object();
502 + if (isset($obj->taxonomy)) {
503 + $builder_data = 'taxonomy###'.$obj->taxonomy.'###'.$obj->slug;
504 + }
505 + }
506 + } else if (is_search()) {
507 + $builder_data = 'search###'.get_search_query(true);
508 + }
509 + return $builder_data ? 'data-builder="'.$builder_data.'"' : '';
510 + }
525 511
526 512
527 - /**
528 - * Determines if the builder is enabled based on the plugin settings.
529 - *
530 - * @param STRING $builder Optional. The builder name (currently unused).
531 - * @return BOOL True if the builder is enabled, false otherwise.
532 - */
533 - public function is_builder( $builder = '' ) {
534 - $id = '';
535 - if ( ultimate_post()->get_setting( 'ultp_builder' ) != 'false' ) {
536 - $page_id = ultimate_post()->builder_check_conditions( 'return_ib' );
537 - if ( $page_id ) {
538 - $id = $page_id;
539 - }
540 - }
541 - return $id;
542 - }
513 + public function is_builder($builder = '') {
514 + $id = '';
515 + if (function_exists('ultimate_post_pro')) {
516 + if ($builder) {
517 + return true;
518 + }
519 + $page_id = ultimate_post_pro()->conditions('return');
520 + if ($page_id && ultimate_post()->get_setting('ultp_builder')) {
521 + $id = $page_id;
522 + }
523 + }
524 + return $id;
525 + }
543 526
544 -
545 - /**
527 +
528 + /**
546 529 * Get Post Number Depending On Device
547 - *
548 - * @since v.2.5.4
549 - * @param MIXED | $preDef .
550 - * @param MIXED | $prev .
551 - * @param MIXED | $current .
530 + *
531 + * @since v.2.5.4
532 + * @param MULTIPLE | Attribute of Posts
552 533 * @return STRING
553 534 */
554 - public function get_post_number( $preDef, $prev, $current ) {
535 + public function get_post_number($preDef, $prev, $current) {
536 +
537 + $current = is_object($current)?json_decode(json_encode($current), true):$current;
538 + if (['lg'=>$preDef,'sm'=>$preDef,'xs'=>$preDef] == $current) {
539 + if ($preDef != $prev) {
540 + return $prev;
541 + }
542 + }
543 + if ($this->isDevice() == 'mobile') {
544 + return $current['xs'];
545 + } else if ($this->isDevice() == 'tablet') {
546 + return $current['sm'];
547 + } else {
548 + return $current['lg'];
549 + }
550 + }
555 551
556 - $current = is_object( $current ) ? json_decode( wp_json_encode( $current ), true ) : $current;
557 - if ( array(
558 - 'lg' => $preDef,
559 - 'sm' => $preDef,
560 - 'xs' => $preDef,
561 - ) == $current ) {
562 - if ( $preDef != $prev ) {
563 - return $prev;
564 - }
565 - }
566 552
567 - $lg = isset( $current['lg'] ) ? $current['lg'] : $prev;
568 - $sm = isset( $current['sm'] ) ? $current['sm'] : $lg;
569 - $xs = isset( $current['xs'] ) ? $current['xs'] : $lg;
570 - if ( $lg == $sm && $sm == $xs ) {
571 - return $lg;
572 - } else {
573 - global $ultpDevide;
574 - $currentDevice = ! empty( $ultpDevide ) ? $ultpDevide : $this->isDevice();
575 - if ( $currentDevice == 'mobile' ) {
576 - return $xs;
577 - } elseif ( $currentDevice == 'tablet' ) {
578 - return $sm;
579 - } else {
580 - return $lg;
581 - }
582 - }
583 - }
584 -
585 -
586 - /**
553 + /**
587 554 * Get Post Number Depending On Device
588 - *
589 - * @since v.2.5.4
555 + *
556 + * @since v.2.5.4
557 + * @param NULL
590 558 * @return STRING | Device Type
591 559 */
592 - public function isDevice() {
593 - $useragent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_key( $_SERVER['HTTP_USER_AGENT'] ) : '';
594 - $device = 'desktop';
595 - if ( $useragent ) {
596 - if ( preg_match( '/(tablet|ipad|playbook)|(android(?!.*(mobi|opera mini)))/i', strtolower( $useragent ) ) ) {
597 - $device = 'tablet';
598 - } elseif ( preg_match( '/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i', $useragent ) || preg_match( '/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i', substr( $useragent, 0, 4 ) ) ) {
599 - $device = 'mobile';
600 - }
601 - }
602 - global $ultpDevide;
603 - $ultpDevide = $device;
604 - return $device;
605 - }
560 + public function isDevice(){
561 + $useragent = $_SERVER['HTTP_USER_AGENT'];
562 + if (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i',substr($useragent,0,4))) {
563 + return 'mobile';
564 + } else if (preg_match('/(tablet|ipad|playbook)|(android(?!.*(mobi|opera mini)))/i', strtolower($useragent))) {
565 + return 'tablet';
566 + } else {
567 + return 'desktop';
568 + }
569 + }
606 570
607 571
608 - /**
572 + /**
609 573 * Get Raw Value from Objects
610 - *
611 - * @since v.2.5.3
612 - * @param ARRAY | $attr .
574 + *
575 + * @since v.2.5.3
576 + * @param NULL
613 577 * @return STRING | Device Type
614 578 */
615 - public function get_value( $attr ) {
616 - $data = array();
617 - if ( is_array( $attr ) ) {
618 - foreach ( $attr as $val ) {
619 - $data[] = $val->value;
620 - }
621 - }
622 - return $data;
623 - }
579 + public function get_value($attr) {
580 + $data = [];
581 + if (is_array($attr)) {
582 + foreach ($attr as $val) {
583 + $data[] = $val->value;
584 + }
585 + }
586 + return $data;
587 + }
624 588
625 - /**
626 - * QueryArgs for Filter
627 - *
628 - * @since v.2.8.9
629 - * @param ARRAY | $attr .
630 - * @return ARRAY
631 - */
632 - public function getFilterQueryArgs( $attr ) {
633 - $tax_value = ( strlen( $attr['queryTaxValue'] ) > 2 ) ? $attr['queryTaxValue'] : array();
634 - $tax_value = is_array( $tax_value ) ? $tax_value : json_decode( $tax_value );
635 589
636 - $tax_value = ( isset( $tax_value[0] ) && is_object( $tax_value[0] ) ) ? $this->get_value( $tax_value ) : $tax_value;
637 -
638 - if ( is_array( $tax_value ) && count( $tax_value ) > 0 ) {
639 - $relation = isset( $attr['queryRelation'] ) ? $attr['queryRelation'] : 'OR';
640 -
641 - // Adv Filter Query Relation Override
642 - if ( isset( $attr['advFilterEnable'] ) && $attr['advFilterEnable'] === true && isset( $attr['advRelation'] ) ) {
643 - $relation = 'AND' === $attr['advRelation'] || 'OR' === $attr['advRelation'] ? $attr['advRelation'] : $relation;
644 - }
645 -
646 - $var = array( 'relation' => $relation );
647 - foreach ( $tax_value as $val ) {
648 - $tax_name = $attr['queryTax'];
649 - // For Custom Terms
650 - if ( $attr['queryTax'] == 'multiTaxonomy' ) {
651 - $temp = explode( '###', $val );
652 - if ( isset( $temp[1] ) ) {
653 -
654 - if ( $temp[1] === '_all' ) {
655 - continue;
656 - }
657 -
658 - $val = $temp[1];
659 - $tax_name = $temp[0];
660 - }
661 - }
662 - $var[] = array(
663 - 'taxonomy' => $tax_name,
664 - 'field' => 'slug',
665 - 'terms' => $val,
666 - );
667 - }
668 - }
669 - return isset( $var ) ? $var : array();
670 - }
671 -
672 - /**
673 - * Query Builder
674 - *
675 - * @since v.1.0.0
676 - * @param ARRAY | $attr .
590 + /**
591 + * Query Builder
592 + *
593 + * @since v.1.0.0
594 + * @param ARRAY | Attribute of the Query
677 595 * @return ARRAY
678 596 */
679 - public function get_query( $attr ) {
680 - $builder = isset( $attr['builder'] ) ? $attr['builder'] : '';
681 - $post_type = isset( $attr['queryType'] ) ? $attr['queryType'] : 'post';
682 - $get_post_type = isset( $attr['queryPostType'] ) ? $attr['queryPostType'] : '';
683 - if ( $post_type != 'archiveBuilder' && ! empty( $get_post_type ) && $post_type == 'customPostType' ) {
684 - $post_type = $get_post_type;
685 - }
597 + public function get_query($attr) {
598 + $builder = isset($attr['builder']) ? $attr['builder'] : '';
599 + if ($this->is_builder($builder)) {
600 + $archive_query = array();
601 + if ($builder) {
602 + $str = explode('###', $builder);
603 + if (isset($str[0])) {
604 + if ($str[0] == 'taxonomy') {
605 + if (isset($str[1]) && isset($str[2])) {
606 + $archive_query['tax_query'] = array(
607 + array(
608 + 'taxonomy' => $str[1],
609 + 'field' => 'slug',
610 + 'terms' => $str[2]
611 + )
612 + );
613 + }
614 + } else if ($str[0] == 'author') {
615 + if (isset($str[1])) {
616 + $archive_query['author'] = $str[1];
617 + }
618 + } else if ($str[0] == 'search') {
619 + if (isset($str[1])) {
620 + $archive_query['s'] = $str[1];
621 + }
622 + } else if ($str[0] == 'date') {
623 + if (isset($str[1])) {
624 + $all_date = explode('-', $str[1]);
625 + if (!empty($all_date)) {
626 + $arg = array();
627 + if (isset($all_date[0])) { $arg['year'] = $all_date[0]; }
628 + if (isset($all_date[1])) { $arg['month'] = $all_date[1]; }
629 + if (isset($all_date[2])) { $arg['day'] = $all_date[2]; }
630 + $archive_query['date_query'][] = $arg;
631 + }
632 + }
633 + }
634 + }
635 + } else {
636 + global $wp_query;
637 + $archive_query = $wp_query->query_vars;
638 + }
639 + $archive_query['posts_per_page'] = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
640 + $archive_query['paged'] = isset($attr['paged']) ? $attr['paged'] : 1;
641 + if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
642 + $offset = $this->get_offset($attr['queryOffset'], $archive_query);
643 + $archive_query = array_merge($archive_query, $offset);
644 + }
686 645
687 - if ( $post_type == 'archiveBuilder' && ( $builder || $this->is_builder( $builder ) ) ) {
688 - $archive_query = array();
689 - if ( $builder ) {
690 - $str = explode( '###', $builder );
691 - if ( isset( $str[0] ) ) {
692 - if ( $str[0] == 'taxonomy' ) {
693 - if ( isset( $str[1] ) && isset( $str[2] ) ) {
694 - $archive_query['tax_query'] = array(
695 - array(
696 - 'taxonomy' => $str[1],
697 - 'field' => 'slug',
698 - 'terms' => $str[2],
699 - ),
700 - );
701 - }
702 - } elseif ( $str[0] == 'author' ) {
703 - if ( isset( $str[1] ) ) {
704 - $archive_query['author'] = $str[1];
705 - }
706 - } elseif ( $str[0] == 'search' ) {
707 - if ( isset( $str[1] ) ) {
708 - $archive_query['s'] = $str[1];
709 - }
710 - } elseif ( $str[0] == 'date' ) {
711 - if ( isset( $str[1] ) ) {
712 - $all_date = explode( '-', $str[1] );
713 - if ( ! empty( $all_date ) ) {
714 - $arg = array();
715 - if ( isset( $all_date[0] ) ) {
716 - $arg['year'] = $all_date[0];
717 - }
718 - if ( isset( $all_date[1] ) ) {
719 - $arg['month'] = $all_date[1];
720 - }
721 - if ( isset( $all_date[2] ) ) {
722 - $arg['day'] = $all_date[2];
723 - }
724 - $archive_query['date_query'][] = $arg;
725 - }
726 - }
727 - }
728 - }
729 - } else {
730 - global $wp_query;
731 - $archive_query = $wp_query->query_vars;
732 - }
733 - $archive_query['posts_per_page'] = isset( $attr['queryNumber'] ) ? $attr['queryNumber'] : 1;
734 - $archive_query['paged'] = isset( $attr['paged'] ) ? $attr['paged'] : 1;
646 + // Include Remove from Version 2.5.4
647 + if (isset($attr['queryInclude']) && $attr['queryInclude']) {
648 + $_include = explode(',', $attr['queryInclude']);
649 + if (is_array($_include) && count($_include)) {
650 + $archive_query['post__in'] = isset($archive_query['post__in']) ? array_merge($archive_query['post__in'], $_include) : $_include;
651 + $archive_query['ignore_sticky_posts'] = 1;
652 + $archive_query['orderby'] = 'post__in';
653 + }
654 + }
735 655
736 - $archive_query['paged'] = ! wp_doing_ajax() && isset( $_GET[ $attr['blockId'] . '_page' ] ) && is_numeric( $_GET[ $attr['blockId'] . '_page' ] ) ?
737 - intval( $_GET[ $attr['blockId'] . '_page' ] ) :
738 - $archive_query['paged'];
656 + if (isset($attr['queryExclude']) && $attr['queryExclude']) {
657 + $_exclude = (substr($attr['queryExclude'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryExclude'])) : explode(',', $attr['queryExclude']);
658 + if (is_array($_exclude) && count($_exclude)) {
659 + $archive_query['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $_exclude) : $_exclude;
660 + }
661 + }
739 662
740 - if ( isset( $attr['queryOffset'] ) && $attr['queryOffset'] ) {
741 - $offset = $this->get_offset( $attr['queryOffset'], $archive_query );
742 - $archive_query = array_merge( $archive_query, $offset );
743 - }
744 663
745 - // Include Remove from Version 2.5.4
746 - if ( isset( $attr['queryInclude'] ) && $attr['queryInclude'] ) {
747 - $_include = explode( ',', $attr['queryInclude'] );
748 - if ( is_array( $_include ) && count( $_include ) ) {
749 - $archive_query['post__in'] = isset( $archive_query['post__in'] ) ? array_merge( $archive_query['post__in'], $_include ) : $_include;
750 - $archive_query['ignore_sticky_posts'] = 1;
751 - $archive_query['orderby'] = 'post__in';
752 - }
753 - }
664 + if(isset($attr['querySticky']) && $attr['querySticky']) {
665 + if (filter_var($attr['querySticky'], FILTER_VALIDATE_BOOLEAN)) {
666 + $sticky = get_option( 'sticky_posts', [] );
667 + $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $sticky) : $sticky;
668 + }
669 + }
754 670
755 - if ( isset( $attr['queryExclude'] ) && $attr['queryExclude'] ) {
756 - $_exclude = ( substr( $attr['queryExclude'], 0, 1 ) === '[' ) ? $this->get_value( json_decode( $attr['queryExclude'] ) ) : explode( ',', $attr['queryExclude'] );
757 - if ( is_array( $_exclude ) && count( $_exclude ) ) {
758 - $archive_query['post__not_in'] = isset( $archive_query['post__not_in'] ) ? array_merge( $archive_query['post__not_in'], $_exclude ) : $_exclude;
759 - }
760 - }
671 + $archive_query['post_status'] = 'publish';
672 + return apply_filters('ultp_archive_query', $archive_query);
673 + }
761 674
762 - if ( isset( $attr['querySticky'] ) && $attr['querySticky'] ) {
763 - if ( filter_var( $attr['querySticky'], FILTER_VALIDATE_BOOLEAN ) ) {
764 - $sticky = get_option( 'sticky_posts', array() );
765 - $archive_query['post__not_in'] = isset( $archive_query['post__not_in'] ) ? array_merge( $archive_query['post__not_in'], $sticky ) : $sticky;
766 - }
767 - }
768 - // ===============
769 - if ( isset( $attr['queryUnique'] ) && $attr['queryUnique'] ) {
770 - global $unique_ID;
771 - if ( isset( $unique_ID[ $attr['queryUnique'] ] ) ) {
772 - $archive_query['post__not_in'] = isset( $archive_query['post__not_in'] ) ? array_merge( $archive_query['post__not_in'], $unique_ID[ $attr['queryUnique'] ] ) : $unique_ID[ $attr['queryUnique'] ];
773 - }
774 - }
775 - // ===============
675 + $query_args = array(
676 + 'posts_per_page' => isset($attr['queryNumber']) ? $attr['queryNumber'] : 3,
677 + 'post_type' => isset($attr['queryType']) ? $attr['queryType'] : 'post',
678 + 'orderby' => isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date',
679 + 'order' => isset($attr['queryOrder']) ? $attr['queryOrder'] : 'desc',
680 + 'paged' => isset($attr['paged']) ? $attr['paged'] : 1,
681 + 'post_status' => 'publish'
682 + );
776 683
777 - $archive_query['post_status'] = 'publish';
778 - if ( is_user_logged_in() ) {
779 - if ( current_user_can( 'editor' ) || current_user_can( 'administrator' ) ) {
780 - $archive_query['post_status'] = array( 'publish', 'private' );
781 - }
782 - }
783 - // queryOrder
784 - if ( ! isset( $archive_query['orderby'] ) ) {
785 - $archive_query['orderby'] = isset( $attr['queryOrderBy'] ) ? $attr['queryOrderBy'] : 'date';
786 - }
787 - if ( ! isset( $archive_query['queryOrder'] ) ) {
788 - $archive_query['order'] = isset( $attr['queryOrder'] ) ? $attr['queryOrder'] : 'ASC';
789 - }
790 684
791 - // Quick Query Support for Builder
792 - if ( isset( $attr['queryQuick'] ) ) {
793 - if ( $attr['queryQuick'] != '' ) {
794 - $archive_query = ultimate_post()->get_quick_query( $attr, $archive_query );
795 - }
796 - }
685 + if ($attr['queryType'] == 'posts') {
686 + if (isset($attr['queryPosts']) && $attr['queryPosts']) {
687 + unset($query_args['post_type']);
688 + $data = json_decode(isset($attr['queryPosts'])?$attr['queryPosts']:'[]');
689 + $final = $this->get_value($data);
690 + if (count($final) > 0) {
691 + $query_args['post__in'] = $final;
692 + $query_args['posts_per_page'] = -1;
693 + }
694 + $query_args['ignore_sticky_posts'] = 1;
695 + return $query_args;
696 + }
697 + } else if ($attr['queryType'] == 'customPosts') {
698 + if (isset($attr['queryCustomPosts']) && $attr['queryCustomPosts']) {
699 + $query_args['post_type'] = $this->get_post_type();
700 + $data = json_decode(isset($attr['queryCustomPosts'])?$attr['queryCustomPosts']:'[]');
701 + $final = $this->get_value($data);
702 + if (count($final) > 0) {
703 + $query_args['post__in'] = $final;
704 + $query_args['posts_per_page'] = -1;
705 + }
706 + $query_args['ignore_sticky_posts'] = 1;
707 + return $query_args;
708 + }
709 + }
797 710
798 - if ( ! isset( $attr['ajaxCall'] ) ) {
799 - if ( isset( $attr['filterShow'] ) && $attr['filterShow'] && $attr['filterShow'] != 'false' ) {
800 - if ( isset( $attr['filterType'] ) && isset( $attr['filterValue'] ) ) {
801 - $filterValue = strlen( $attr['filterValue'] ) > 2 ? $attr['filterValue'] : array();
802 - $filterValue = is_array( $filterValue ) ? $filterValue : json_decode( $filterValue );
803 - if ( count( $filterValue ) > 0 && $attr['filterType'] ) {
804 - $final = array( 'relation' => 'OR' );
805 - foreach ( $filterValue as $key => $val ) {
806 - $final[] = array(
807 - 'taxonomy' => $attr['filterType'],
808 - 'field' => 'slug',
809 - 'terms' => $val,
810 - );
811 - }
812 - $archive_query['tax_query'] = $final;
813 - }
814 - }
815 - }
816 - }
817 - // from v.3.0.7 - for search builder
818 - if ( is_search() ) {
819 - $archive_query['orderby'] = 'relevance';
820 - if ( isset( $_GET['ultp_exclude'] ) ) { // Added support for search block exclude
821 - $ultp_exclude = json_decode( stripslashes( $_GET['ultp_exclude'] ), true );
822 - if ( is_array( $ultp_exclude ) ) {
823 - $all_types = get_post_types( array( 'public' => true ), 'names' );
824 - $post_type = array_diff( $all_types, $ultp_exclude );
825 - $archive_query['post_type'] = $post_type;
826 - }
827 - }
828 - }
711 + if(isset($attr['queryExcludeAuthor']) && $attr['queryExcludeAuthor']){
712 + $data = json_decode(isset($attr['queryExcludeAuthor'])?$attr['queryExcludeAuthor']:'[]');
713 + $final = $this->get_value($data);
714 + if (count($final) > 0) {
715 + $query_args['author__not_in'] = $final;
716 + }
717 + }
718 +
829 719
830 - return apply_filters( 'ultp_archive_query', $archive_query );
831 - }
720 + if(isset($attr['queryOrderBy']) && isset($attr['metaKey'])){
721 + if($attr['queryOrderBy'] == 'meta_value_num') {
722 + $query_args['meta_key'] = $attr['metaKey'];
723 + }
724 + }
832 725
833 - // When you use load more pagination block for a grid that did not have load more feature,
834 - // the incoming posts would not align properly with the blocks design and looked bad.
835 - // This fixes that.
836 - if (
837 - isset( $attr['paginationType'] ) &&
838 - isset( $attr['queryNumber2'] ) &&
839 - isset( $attr['notFirstLoad'] ) &&
840 - $attr['paginationType'] === 'loadMore' &&
841 - $attr['notFirstLoad']
842 - ) {
843 - $query_number = $attr['queryNumber2'];
844 - // $query_number = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
845 - } else {
846 - $query_number = isset( $attr['queryNumber'] ) ? $attr['queryNumber'] : 3;
847 - }
726 + // Include Remove from Version 2.5.4
727 + if (isset($attr['queryInclude']) && $attr['queryInclude']) {
728 + $_include = explode(',', $attr['queryInclude']);
729 + if (is_array($_include) && count($_include)) {
730 + $query_args['post__in'] = isset($query_args['post__in']) ? array_merge($query_args['post__in'], $_include) : $_include;
731 + $query_args['ignore_sticky_posts'] = 1;
732 + $query_args['orderby'] = 'post__in';
733 + }
734 + }
848 735
849 - $paged = isset( $attr['paged'] ) ? $attr['paged'] : 1;
850 - $paged = ! wp_doing_ajax() &&
851 - isset( $attr['blockId'] ) &&
852 - isset( $_GET[ $attr['blockId'] . '_page' ] ) &&
853 - is_numeric( $_GET[ $attr['blockId'] . '_page' ] ) ?
854 - intval( $_GET[ $attr['blockId'] . '_page' ] ) :
855 - $paged;
856 736
857 - $query_args = array(
858 - 'posts_per_page' => $query_number,
859 - 'post_type' => is_array( $post_type ) && ! empty( $post_type ) ? $post_type : ( 'archiveBuilder' == $post_type ? 'post' : ( is_string( $post_type ) ? is_array( json_decode( $post_type ) ) ? json_decode( $post_type ) : $post_type : $post_type ) ),
860 - 'orderby' => isset( $attr['queryOrderBy'] ) ? $attr['queryOrderBy'] : 'date',
861 - 'order' => isset( $attr['queryOrder'] ) ? $attr['queryOrder'] : 'desc',
862 - 'paged' => $paged,
863 - 'post_status' => 'publish',
864 - );
737 + if(isset($attr['queryTax'])){
738 + if(isset($attr['queryTaxValue'])){
739 + $tax_value = (strlen($attr['queryTaxValue']) > 2) ? $attr['queryTaxValue'] : [];
740 + $tax_value = is_array($tax_value) ? $tax_value : json_decode($tax_value);
865 741
866 - // For Private Post 'private'.
867 - if ( is_user_logged_in() ) {
868 - if ( current_user_can( 'editor' ) || current_user_can( 'administrator' ) ) {
869 - $query_args['post_status'] = array( 'publish', 'private' );
870 - }
871 - }
742 + $tax_value = (isset($tax_value[0]) && is_object($tax_value[0])) ? $this->get_value($tax_value) : $tax_value;
872 743
873 - if ( $attr['queryType'] == 'posts' ) {
874 - if ( isset( $attr['queryPosts'] ) && $attr['queryPosts'] ) {
875 - unset( $query_args['post_type'] );
876 - $data = json_decode( isset( $attr['queryPosts'] ) ? $attr['queryPosts'] : '[]' );
877 - $final = $this->get_value( $data );
878 - if ( count( $final ) > 0 ) {
879 - $query_args['post__in'] = $final;
880 - // $query_args['posts_per_page'] = -1;
881 - }
882 - $query_args['ignore_sticky_posts'] = 1;
883 - return $query_args;
884 - }
885 - } elseif ( $attr['queryType'] == 'customPosts' ) {
886 - if ( isset( $attr['queryCustomPosts'] ) && $attr['queryCustomPosts'] ) {
887 - $query_args['post_type'] = $this->get_post_type();
888 - $data = json_decode( isset( $attr['queryCustomPosts'] ) ? $attr['queryCustomPosts'] : '[]' );
889 - $final = $this->get_value( $data );
890 - if ( count( $final ) > 0 ) {
891 - $query_args['post__in'] = $final;
892 - // $query_args['posts_per_page'] = -1;
893 - }
894 - $query_args['ignore_sticky_posts'] = 1;
895 - return $query_args;
896 - }
897 - }
744 + if(count($tax_value) > 0){
745 + $relation = isset($attr['queryRelation']) ? $attr['queryRelation'] : 'OR';
746 + $var = array('relation'=>$relation);
747 + foreach ($tax_value as $val) {
748 + $tax_name = $attr['queryTax'];
749 + // For Custom Terms
750 + if ($attr['queryTax'] == 'multiTaxonomy') {
751 + $temp = explode('###', $val);
752 + if (isset($temp[1])) {
753 + $val = $temp[1];
754 + $tax_name = $temp[0];
755 + }
756 + }
898 757
899 - if ( isset( $attr['queryExcludeAuthor'] ) && $attr['queryExcludeAuthor'] ) {
900 - $data = json_decode( isset( $attr['queryExcludeAuthor'] ) ? $attr['queryExcludeAuthor'] : '[]' );
901 - $final = $this->get_value( $data );
902 - if ( count( $final ) > 0 ) {
903 - $query_args['author__not_in'] = $final;
904 - }
905 - }
758 + $var[] = array('taxonomy'=> $tax_name, 'field' => 'slug', 'terms' => $val );
759 + }
760 + if(count($var) > 1){
761 + $query_args['tax_query'] = $var;
762 + }
763 + }
764 + }
765 + }
906 766
907 - if ( isset( $attr['queryOrderBy'] ) && isset( $attr['metaKey'] ) ) {
908 - if ( $attr['queryOrderBy'] == 'meta_value_num' ) {
909 - $query_args['meta_key'] = $attr['metaKey'];
910 - }
911 - }
767 +
768 + if (isset($attr['queryExcludeTerm']) && $attr['queryExcludeTerm']) {
769 + $temp = json_decode($attr['queryExcludeTerm']);
770 + $_term = [];
771 + foreach ($temp as $val) {
772 + $temp = explode('###', $val->value);
773 + if (isset($temp[1])) {
774 + if (array_key_exists($temp[0], $_term)) {
775 + $_term[$temp[0]][] = $temp[1];
776 + } else {
777 + $_term[$temp[0]] = array($temp[1]);
778 + }
779 + }
780 + }
781 + if (count($_term) > 0) {
782 + $final = array('relation' => 'AND');
783 + foreach ($_term as $key => $val) {
784 + $final[] = array(
785 + 'taxonomy' => $key,
786 + 'field' => 'slug',
787 + 'terms' => $val,
788 + 'operator' => 'NOT IN',
789 + );
790 + }
912 791
913 - // Include Remove from Version 2.5.4.
914 - if ( isset( $attr['queryInclude'] ) && $attr['queryInclude'] ) {
915 - $_include = explode( ',', $attr['queryInclude'] );
916 - if ( is_array( $_include ) && count( $_include ) ) {
917 - $query_args['post__in'] = isset( $query_args['post__in'] ) ? array_merge( $query_args['post__in'], $_include ) : $_include;
918 - $query_args['ignore_sticky_posts'] = 1;
919 - $query_args['orderby'] = 'post__in';
920 - }
921 - }
792 + if (array_key_exists('tax_query', $query_args)) {
793 + $query_args['tax_query'] = array(
794 + 'relation' => 'AND',
795 + $query_args['tax_query']
796 + );
797 + $query_args['tax_query'][] = $final;
798 + } else {
799 + $query_args['tax_query'] = $final;
800 + }
801 + }
802 + }
922 803
923 - if ( isset( $attr['queryTax'] ) ) {
924 - if ( isset( $attr['queryTaxValue'] ) ) {
925 - $var = $this->getFilterQueryArgs( $attr );
926 - if ( isset( $var ) && count( $var ) > 1 ) {
927 - $query_args['tax_query'] = $var;
928 - }
929 - }
930 - }
804 + if (isset($attr['queryExclude']) && $attr['queryExclude']) {
805 + $_exclude = (substr($attr['queryExclude'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryExclude'])) : explode(',', $attr['queryExclude']);
806 + if (is_array($_exclude) && count($_exclude)) {
807 + $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $_exclude) : $_exclude;
808 + }
809 + }
931 810
932 - if ( isset( $attr['queryExcludeTerm'] ) && $attr['queryExcludeTerm'] ) {
933 - $temp = json_decode( $attr['queryExcludeTerm'] );
934 - $_term = array();
935 - foreach ( $temp as $val ) {
936 - $temp = explode( '###', $val->value );
937 - if ( isset( $temp[1] ) ) {
938 - if ( is_array( $_term ) && array_key_exists( $temp[0], $_term ) ) {
939 - $_term[ $temp[0] ][] = $temp[1];
940 - } else {
941 - $_term[ $temp[0] ] = array( $temp[1] );
942 - }
943 - }
944 - }
945 - if ( count( $_term ) > 0 ) {
946 - $final = array( 'relation' => 'AND' );
947 - foreach ( $_term as $key => $val ) {
948 - $final[] = array(
949 - 'taxonomy' => $key,
950 - 'field' => 'slug',
951 - 'terms' => $val,
952 - 'operator' => 'NOT IN',
953 - );
954 - }
811 + if (isset($attr['queryUnique']) && $attr['queryUnique']) {
812 + global $unique_ID;
813 + if (isset($unique_ID[$attr['queryUnique']])) {
814 + $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $unique_ID[$attr['queryUnique']]) : $unique_ID[$attr['queryUnique']];
815 + }
816 + }
955 817
956 - if ( is_array( $query_args ) && array_key_exists( 'tax_query', $query_args ) ) {
957 - $query_args['tax_query'] = array(
958 - 'relation' => 'AND',
959 - $query_args['tax_query'],
960 - );
961 - $query_args['tax_query'][] = $final;
962 - } else {
963 - $query_args['tax_query'] = $final;
964 - }
965 - }
966 - }
818 + if (isset($attr['queryQuick'])) {
819 + if ($attr['queryQuick'] != '') {
820 + $query_args = ultimate_post()->get_quick_query($attr, $query_args);
821 + }
822 + }
967 823
968 - if ( isset( $attr['queryExclude'] ) && $attr['queryExclude'] ) {
969 - $_exclude = ( substr( $attr['queryExclude'], 0, 1 ) === '[' ) ? $this->get_value( json_decode( $attr['queryExclude'] ) ) : explode( ',', $attr['queryExclude'] );
970 - if ( is_array( $_exclude ) && count( $_exclude ) ) {
971 - $query_args['post__not_in'] = isset( $query_args['post__not_in'] ) ? array_merge( $query_args['post__not_in'], $_exclude ) : $_exclude;
972 - }
973 - }
824 + if (isset($attr['queryOffset']) && $attr['queryOffset'] ) {
825 + $offset = $this->get_offset($attr['queryOffset'], $query_args);
826 + $query_args = array_merge($query_args, $offset);
827 + }
974 828
975 - if ( isset( $attr['queryUnique'] ) && $attr['queryUnique'] ) {
976 - global $unique_ID;
977 - if ( isset( $unique_ID[ $attr['queryUnique'] ] ) ) {
978 - $query_args['post__not_in'] = isset( $query_args['post__not_in'] ) ? array_merge( $query_args['post__not_in'], $unique_ID[ $attr['queryUnique'] ] ) : $unique_ID[ $attr['queryUnique'] ];
979 - }
980 - }
981 - // exclude current post from Post blocks // v.2.9.6.
982 - if ( is_single() && get_the_ID() ) {
983 - $query_args['post__not_in'] = isset( $query_args['post__not_in'] ) ? array_merge( $query_args['post__not_in'], array( get_the_ID() ) ) : array( get_the_ID() );
984 - }
829 + if (isset($attr['queryAuthor']) && $attr['queryAuthor'] ) {
830 + $_include = (substr($attr['queryAuthor'], 0, 1) === "[") ? $this->get_value(json_decode($attr['queryAuthor'])) : explode(',', $attr['queryAuthor']);
831 + if (is_array($_include) && count($_include)) {
832 + $query_args['author__in'] = $_include;
833 + }
834 + }
985 835
986 - if ( isset( $attr['queryQuick'] ) ) {
987 - if ( $attr['queryQuick'] != '' && $post_type != 'archiveBuilder' ) {
988 - $query_args = ultimate_post()->get_quick_query( $attr, $query_args );
989 - }
990 - }
836 + if(isset($attr['querySticky']) && $attr['querySticky']) {
837 + if (filter_var($attr['querySticky'], FILTER_VALIDATE_BOOLEAN)) {
838 + $sticky = get_option( 'sticky_posts', [] );
839 + $query_args['post__not_in'] = isset($query_args['post__not_in']) ? array_merge($query_args['post__not_in'], $sticky) : $sticky;
840 + }
841 + }
991 842
992 - if ( isset( $attr['queryOffset'] ) && $attr['queryOffset'] ) {
993 - $offset = $this->get_offset( $attr['queryOffset'], $query_args );
994 - $query_args = array_merge( $query_args, $offset );
995 - }
843 + $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
844 +
845 + return apply_filters('ultp_frontend_query', $query_args);
846 + }
996 847
997 - if ( isset( $attr['queryAuthor'] ) && $attr['queryAuthor'] ) {
998 - $_include = ( substr( $attr['queryAuthor'], 0, 1 ) === '[' ) ? $this->get_value( json_decode( $attr['queryAuthor'] ) ) : explode( ',', $attr['queryAuthor'] );
999 - if ( is_array( $_include ) && count( $_include ) ) {
1000 - $query_args['author__in'] = $_include;
1001 - }
1002 - }
848 + function get_offset($queryOffset, $query_args) {
849 + $query = array();
850 + if ($query_args['paged'] > 1) {
851 + $offset_post = wp_get_recent_posts($query_args, OBJECT);
852 + if ( count($offset_post) > 0 ) {
853 + $offset = array();
854 + for($x = count($offset_post); $x > count($offset_post) - $queryOffset; $x--){
855 + $offset[] = $offset_post[$x-1]->ID;
856 + }
857 + $query['post__not_in'] = $offset;
858 + }
859 + } else {
860 + $query['offset'] = isset($queryOffset) ? $queryOffset : 0;
861 + }
862 + return $query;
863 + }
1003 864
1004 - if ( isset( $attr['querySearch'] ) && $attr['querySearch'] ) {
1005 - $query_args['s'] = $attr['querySearch'];
1006 - }
1007 865
1008 - if ( isset( $attr['querySticky'] ) && $attr['querySticky'] ) {
1009 - if ( filter_var( $attr['querySticky'], FILTER_VALIDATE_BOOLEAN ) ) {
1010 - $sticky = get_option( 'sticky_posts', array() );
1011 - $query_args['post__not_in'] = isset( $query_args['post__not_in'] ) ? array_merge( $query_args['post__not_in'], $sticky ) : $sticky;
1012 - }
1013 - }
1014 -
1015 - if ( ! isset( $attr['ajaxCall'] ) ) {
1016 - if ( isset( $attr['filterShow'] ) && $attr['filterShow'] && $attr['filterShow'] != 'false' ) {
1017 - if ( isset( $attr['checkFilter'] ) && isset( $attr['queryTax'] ) && isset( $attr['queryTaxValue'] ) ) {
1018 - $var = $this->getFilterQueryArgs( $attr );
1019 - if ( isset( $var ) && count( $var ) > 1 ) {
1020 - $query_args['tax_query'] = $var;
1021 - }
1022 - } elseif ( isset( $attr['filterType'] ) && isset( $attr['filterValue'] ) ) {
1023 - $filterValue = strlen( $attr['filterValue'] ) > 2 ? $attr['filterValue'] : array();
1024 - $filterValue = is_array( $filterValue ) ? $filterValue : json_decode( $filterValue );
1025 - if ( is_array( $filterValue ) && count( $filterValue ) > 0 && $attr['filterType'] ) {
1026 - $final = array( 'relation' => 'OR' );
1027 - foreach ( $filterValue as $key => $val ) {
1028 - $final[] = array(
1029 - 'taxonomy' => $attr['filterType'],
1030 - 'field' => 'slug',
1031 - 'terms' => $val,
1032 - // 'operator' => '=',
1033 - );
1034 - }
1035 - $query_args['tax_query'] = $final;
1036 - }
1037 - }
1038 - }
1039 - }
1040 -
1041 - // Advanced Filter Select Dropdown Default value.
1042 - // only on initial page load.
1043 - if (
1044 - ! wp_doing_ajax() &&
1045 - isset( $attr['advFilterEnable'] ) &&
1046 - $attr['advFilterEnable'] === true &&
1047 - isset( $attr['defQueryTax'] ) &&
1048 - count( $attr['defQueryTax'] ) > 0
1049 - ) {
1050 - $tax_query = array(
1051 - 'relation' =>
1052 - isset( $attr['advRelation'] ) &&
1053 - ( 'AND' === $attr['advRelation'] || 'OR' === $attr['advRelation'] )
1054 - ? $attr['advRelation'] : 'AND',
1055 - );
1056 - $is_valid = false;
1057 -
1058 - foreach ( $attr['defQueryTax'] as $_ => $defQueryTaxValue ) {
1059 - $term = explode( '###', $defQueryTaxValue );
1060 -
1061 - // Validation
1062 - if (
1063 - ! in_array( $term[0], array( 'category', 'tags', 'author', 'custom_tax' ), true ) ||
1064 - '_all' === $term[1] ||
1065 - empty( $term[1] )
1066 - ) {
1067 - continue;
1068 - }
1069 -
1070 - if ( 'author' === $term[0] ) {
1071 -
1072 - if ( ! is_numeric( $term[1] ) ) {
1073 - continue;
1074 - }
1075 -
1076 - $query_args['author__in'] = $term[1];
1077 - } elseif ( 'custom_tax' === $term[0] && isset( $attr['queryType'] ) ) {
1078 - $post_type = sanitize_key( $attr['queryType'] );
1079 - $slug = sanitize_key( $term[1] );
1080 -
1081 - // These are not custom post type.
1082 - if ( in_array( $post_type, array( 'posts', 'customPosts' ), true ) ) {
1083 - continue;
1084 - }
1085 -
1086 - $taxonomy = $this->get_taxonomy_by_term_slug( $post_type, $slug );
1087 -
1088 - if ( ! empty( $taxonomy ) ) {
1089 - $q = array(
1090 - 'field' => 'slug',
1091 - 'taxonomy' => $taxonomy,
1092 - 'terms' => $slug,
1093 - );
1094 -
1095 - $tax_query[] = $q;
1096 - $is_valid = true;
1097 - }
1098 - } else {
1099 - if ( ! is_numeric( $term[1] ) ) {
1100 - continue;
1101 - }
1102 -
1103 - $q = array(
1104 - 'field' => 'term_id',
1105 - 'taxonomy' => 'tags' === $term[0] ? 'post_tag' : 'category',
1106 - 'terms' => $term[1],
1107 - );
1108 -
1109 - $tax_query[] = $q;
1110 - $is_valid = true;
1111 - }
1112 - }
1113 -
1114 - if ( $is_valid ) {
1115 - $query_args['tax_query'] = $tax_query;
1116 - }
1117 - }
1118 - // $query_args['test'] = is_array( $post_type ) && ! empty( $post_type ) ? $post_type : ( 'archiveBuilder' === $post_type ? 'post' : ( is_string( $post_type ) ? json_decode( $post_type ) : $post_type ) );
1119 - $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
1120 -
1121 - return apply_filters( 'ultp_frontend_query', $query_args );
1122 - }
1123 -
1124 - /**
1125 - * Get Page Offset
1126 - *
1127 - * @since v.1.0.0
1128 - * @param NUMBER | $queryOffset Offset .
1129 - * @param ARRAY | $query_args Query .
1130 - * @return ARRAY
1131 - */
1132 - function get_offset( $queryOffset, $query_args ) {
1133 - $query = array();
1134 - if ( $query_args['paged'] > 1 ) {
1135 - $offset_post = wp_get_recent_posts( $query_args, OBJECT );
1136 - if ( count( $offset_post ) > 0 ) {
1137 - $offset = array();
1138 - for ( $x = count( $offset_post ); $x > count( $offset_post ) - $queryOffset; $x-- ) {
1139 - $offset[] = $offset_post[ $x - 1 ]->ID;
1140 - }
1141 - $query['post__not_in'] = $offset;
1142 - }
1143 - } else {
1144 - $query['offset'] = isset( $queryOffset ) ? $queryOffset : 0;
1145 - }
1146 - return $query;
1147 - }
1148 -
1149 -
1150 - /**
866 + /**
1151 867 * Get Page Number
1152 - *
1153 - * @since v.1.0.0
1154 - * @param array $attr Attribute of the Query.
1155 - * @param int $post_number Post Number.
868 + *
869 + * @since v.1.0.0
870 + * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1156 871 * @return ARRAY
1157 872 */
1158 - public function get_page_number( $attr, $post_number ) {
1159 - if ( $post_number > 0 ) {
1160 - if ( isset( $attr['queryOffset'] ) && $attr['queryOffset'] ) {
1161 - $post_number = $post_number - (int) $attr['queryOffset'];
1162 - }
1163 - $post_per_page = isset( $attr['queryNumber'] ) ? ( $attr['queryNumber'] ? $attr['queryNumber'] : 1 ) : 3;
1164 - $pages = ceil( $post_number / $post_per_page );
1165 - return $pages ? $pages : 1;
1166 - } else {
1167 - return 1;
1168 - }
1169 - }
873 + public function get_page_number($attr, $post_number) {
874 + if ($post_number > 0) {
875 + if (isset($attr['queryOffset']) && $attr['queryOffset']) {
876 + $post_number = $post_number - (int)$attr['queryOffset'];
877 + }
878 + $post_per_page = isset($attr['queryNumber']) ? ($attr['queryNumber'] ? $attr['queryNumber'] : 1) : 3;
879 + $pages = ceil($post_number/$post_per_page);
880 + return $pages ? $pages : 1;
881 + }else{
882 + return 1;
883 + }
884 + }
1170 885
1171 886
1172 - /**
887 + /**
1173 888 * Get Image Size
1174 - *
1175 - * @since v.1.0.0
889 + *
890 + * @since v.1.0.0
891 + * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1176 892 * @return ARRAY
1177 893 */
1178 - public function get_image_size() {
1179 - $sizes = get_intermediate_image_sizes();
1180 - $filter = array( 'full' => 'Full' );
1181 - foreach ( $sizes as $value ) {
1182 - $title = ucwords( str_replace( array( '_', '-', 'ultp' ), array( ' ', ' ', 'PostX' ), $value ) );
1183 - switch ( $value ) {
1184 - case 'thumbnail':
1185 - $title = $title . ' [150x150]';
1186 - break;
1187 - case 'medium':
1188 - $title = $title . ' [300x300]';
1189 - break;
1190 - case 'large':
1191 - $title = $title . ' [1024x1024]';
1192 - break;
1193 - case 'ultp_layout_landscape_large':
1194 - $title = $title . ' [1200x800]';
1195 - break;
1196 - case 'ultp_layout_landscape':
1197 - $title = $title . ' [870x570]';
1198 - break;
1199 - case 'ultp_layout_portrait':
1200 - $title = $title . ' [600x900]';
1201 - break;
1202 - case 'ultp_layout_square':
1203 - $title = $title . ' [600x600]';
1204 - break;
1205 - default:
1206 - break;
1207 - }
1208 - $filter[ $value ] = $title;
1209 - }
1210 - return $filter;
1211 - }
894 + public function get_image_size() {
895 + $sizes = get_intermediate_image_sizes();
896 + $filter = array('full' => 'Full');
897 + foreach ($sizes as $value) {
898 + $title = ucwords(str_replace(array('_', '-'), array(' ', ' '), $value));
899 + switch ($value) {
900 + case 'thumbnail':
901 + $title = $title.' [150x150]';
902 + break;
903 + case 'medium':
904 + $title = $title.' [300x300]';
905 + break;
906 + case 'large':
907 + $title = $title.' [1024x1024]';
908 + break;
909 + case 'ultp_layout_landscape_large':
910 + $title = $title.' [1200x800]';
911 + break;
912 + case 'ultp_layout_landscape':
913 + $title = $title.' [870x570]';
914 + break;
915 + case 'ultp_layout_portrait':
916 + $title = $title.' [600x900]';
917 + break;
918 + case 'ultp_layout_square':
919 + $title = $title.' [600x600]';
920 + break;
921 + default:
922 + break;
923 + }
924 + $filter[$value] = $title;
925 + }
926 + return $filter;
927 + }
1212 928
1213 929
1214 - /**
930 + /**
1215 931 * Get All PostType Registered
1216 - *
1217 - * @since v.1.0.0
932 + *
933 + * @since v.1.0.0
934 + * @param | Attribute of the Query(ARRAY) | Post Number(ARRAY)
1218 935 * @return ARRAY
1219 936 */
1220 - public function get_post_type() {
1221 - $filter = apply_filters( 'ultp_public_post_type', true );
1222 - $post_type = get_post_types( ( $filter ? array( 'public' => true ) : '' ), 'names' );
1223 - return array_diff( $post_type, array( 'attachment' ) );
1224 - }
937 + public function get_post_type() {
938 + $post_type = get_post_types( ['public' => true], 'names' );
939 + return array_diff($post_type, array( 'attachment' ));
940 + }
1225 941
1226 - /**
1227 - * Get Pagination Url
1228 - *
1229 - * @since v.2.8.9
1230 - *
1231 - * @param NUMBER $pageNo The page number for pagination.
1232 - * @param STRING $baseUrl The base URL to append the pagination parameter to.
1233 - *
1234 - * @return STRING The generated pagination URL.
1235 - */
1236 - public function generatePaginationUrl( $pageNo, $baseUrl ) {
1237 - if ( $baseUrl ) {
1238 - $url = $baseUrl . ( $pageNo == 1 ? '' : 'page/' . $pageNo );
1239 - } else {
1240 - $url = get_pagenum_link( $pageNo );
1241 - }
1242 - return $url;
1243 - }
1244 - /**
942 +
943 + /**
1245 944 * Get Pagination HTML
1246 - *
1247 - * @since v.1.0.0
1248 - * @param INT $pages Number of pages.
1249 - * @param STRING $paginationNav Pagination navigation type.
1250 - * @param STRING $paginationText Pagination text.
1251 - * @param BOOL $paginationAjax Whether to use AJAX pagination.
1252 - * @param STRING $baseUrl Base URL for pagination links.
1253 - * @param STRING $blockId Block ID for pagination.
945 + *
946 + * @since v.1.0.0
947 + * @param | pages (NUMBER) | Pagination Nav (STRING) | Pagination Text |
1254 948 * @return STRING
1255 949 */
1256 - public function pagination( $pages = '', $paginationNav = '', $paginationText = '', $paginationAjax = true, $baseUrl = '', $blockId = '' ) {
1257 - $html = '';
1258 - $showitems = 3;
1259 - $paged = is_front_page() ? get_query_var( 'page' ) : get_query_var( 'paged' );
1260 - $paged = $paged ? $paged : 1;
950 + public function pagination($pages = '', $paginationNav = '', $paginationText = '') {
951 + $html = '';
952 + $showitems = 3;
953 + $paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
954 + $paged = $paged ? $paged : 1;
955 + if($pages == '') {
956 + global $wp_query;
957 + $pages = $wp_query->max_num_pages;
958 + if(!$pages) {
959 + $pages = 1;
960 + }
961 + }
962 + $data = ($paged>=3?[($paged-1),$paged,$paged+1]:[1,2,3]);
1261 963
1262 - $paged = ! wp_doing_ajax() &&
1263 - isset( $_GET[ $blockId . '_page' ] ) &&
1264 - is_numeric( $_GET[ $blockId . '_page' ] ) ?
1265 - intval( $_GET[ $blockId . '_page' ] ) : $paged;
964 + $paginationText = explode('|', $paginationText);
1266 965
1267 - if ( $pages == '' ) {
1268 - global $wp_query;
1269 - $pages = $wp_query->max_num_pages;
1270 - if ( ! $pages ) {
1271 - $pages = 1;
1272 - }
1273 - }
966 + $prev_text = isset($paginationText[0]) ? $paginationText[0] : __("Previous", "ultimate-post");
967 + $next_text = isset($paginationText[1]) ? $paginationText[1] : __("Next", "ultimate-post");
968 +
969 + if(1 != $pages) {
970 + $html .= '<ul class="ultp-pagination">';
971 + $display_none = 'style="display:none"';
972 + if($pages > 4) {
973 + $html .= '<li class="ultp-prev-page-numbers" '.($paged==1?$display_none:"").'><a href="'.get_pagenum_link($paged-1).'">'.ultimate_post()->svg_icon('leftAngle2').' '.($paginationNav == 'textArrow' ? $prev_text : "").'</a></li>';
974 + }
975 + if($pages > 4){
976 + $html .= '<li class="ultp-first-pages" '.($paged<2?$display_none:"").' data-current="1"><a href="'.get_pagenum_link(1).'">1</a></li>';
977 + }
978 + if($pages > 4){
979 + $html .= '<li class="ultp-first-dot" '.($paged<2? $display_none : "").'><a href="#">...</a></li>';
980 + }
981 + foreach ($data as $i) {
982 + if($pages >= $i){
983 + $html .= ($paged == $i) ? '<li class="ultp-center-item pagination-active" data-current="'.$i.'"><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>':'<li class="ultp-center-item" data-current="'.$i.'"><a href="'.get_pagenum_link($i).'">'.$i.'</a></li>';
984 + }
985 + }
986 + if($pages > 4){
987 + $html .= '<li class="ultp-last-dot" '.($pages<=$paged+1?$display_none:"").'><a href="#">...</a></li>';
988 + }
989 + if($pages > 4){
990 + $html .= '<li class="ultp-last-pages" '.($pages<=$paged+1?$display_none:"").' data-current="'.$pages.'"><a href="'.get_pagenum_link($pages).'">'.$pages.'</a></li>';
991 + }
992 + if ($paged != $pages) {
993 + $html .= '<li class="ultp-next-page-numbers"><a href="'.get_pagenum_link($paged + 1).'">'.($paginationNav == 'textArrow' ? $next_text : "").ultimate_post()->svg_icon('rightAngle2').'</a></li>';
994 + }
995 + $html .= '</ul>';
996 + }
997 + return $html;
998 + }
1274 999
1275 - $data = ( $paged >= 3 ? array( ( $paged - 1 ), $paged, $paged + 1 ) : array( 1, 2, 3 ) );
1276 1000
1277 - $paginationText = explode( '|', $paginationText );
1278 -
1279 - $prev_text = isset( $paginationText[0] ) ? esc_html( $paginationText[0] ) : __( 'Previous', 'ultimate-post' );
1280 - $next_text = isset( $paginationText[1] ) ? esc_html( $paginationText[1] ) : __( 'Next', 'ultimate-post' );
1281 -
1282 - if ( 1 != $pages ) {
1283 - $html .= '<ul class="ultp-pagination">';
1284 - $display_none = 'style="display:none"';
1285 - if ( $paged > 1 || $paginationAjax && $pages > 1 ) {
1286 - $html .= '<li class="ultp-prev-page-numbers" ' . ( $paged == 1 ? $display_none : '' ) . '><a href="' . $this->generatePaginationUrl( $paged - 1, $baseUrl ) . '">' . ultimate_post()->get_svg_icon( 'leftAngle2' ) . ' ' . ( $paginationNav == 'textArrow' ? $prev_text : '' ) . '</a></li>';
1287 - }
1288 - if ( $pages > 3 ) {
1289 - $html .= '<li class="ultp-first-pages" ' . ( $paged < 2 ? $display_none : '' ) . ' data-current="1"><a href="' . $this->generatePaginationUrl( 1, $baseUrl ) . '">1</a></li>';
1290 - }
1291 - if ( $paged > 3 || $paginationAjax && $pages > 4 ) {
1292 - $html .= '<li class="ultp-first-dot"' . ( $paged == 1 ? $display_none : '' ) . '><a href="#">...</a></li>';
1293 - }
1294 - foreach ( $data as $i ) {
1295 - if ( $pages > 3 && $pages == $i ) {
1296 - continue;
1297 - }
1298 - if ( $pages >= $i ) {
1299 - $html .= ( $paged == $i ) ? '<li class="ultp-center-item pagination-active" data-current="' . $i . '"><a href="' . $this->generatePaginationUrl( $i, $baseUrl ) . '">' . $i . '</a></li>' : '<li class="ultp-center-item" data-current="' . $i . '" ' . ( ( $pages > 4 && $paged == 2 && $i == 1 && ! $paginationAjax ) ? $display_none : '' ) . '><a href="' . $this->generatePaginationUrl( $i, $baseUrl ) . '">' . $i . '</a></li>';
1300 - }
1301 - }
1302 - if ( $pages != ( $paged + 2 ) || $paginationAjax && $pages > 4 ) {
1303 - $html .= '<li class="ultp-last-dot" ' . ( $pages <= $paged + 1 ? $display_none : '' ) . '><a href="#">...</a></li>';
1304 - }
1305 - if ( $pages > 3 ) {
1306 - $html .= '<li class="ultp-last-pages' . ( $paged == $pages ? ' pagination-active' : '' ) . '" data-current="' . $pages . '"><a href="' . $this->generatePaginationUrl( $pages, $baseUrl ) . '">' . $pages . '</a></li>';
1307 - }
1308 - if ( $paged != $pages ) {
1309 - $html .= '<li class="ultp-next-page-numbers"><a href="' . $this->generatePaginationUrl( $paged + 1, $baseUrl ) . '">' . ( $paginationNav == 'textArrow' ? $next_text : '' ) . ultimate_post()->get_svg_icon( 'rightAngle2' ) . '</a></li>';
1310 - }
1311 - $html .= '</ul>';
1312 - }
1313 - return $html;
1314 - }
1315 -
1316 - /**
1317 - * Svg Icon Source
1318 - *
1319 - * @since v.1.0.0
1320 - * @param STRING $ultp_icons Name of the SVG icon file (without extension).
1001 + /**
1002 + * Get Excerpt Word
1003 + *
1004 + * @since v.1.0.0
1005 + * @param NUMBER | Character Length
1321 1006 * @return STRING
1322 1007 */
1323 - public function get_svg_icon( $ultp_icons = '' ) {
1324 - $svg = '';
1325 - if ( $ultp_icons ) {
1326 - $icon = $this->svg_icon_compatibility( $ultp_icons );
1327 - $svg = $this->get_path_file_contents( ULTP_PATH . 'assets/img/iconpack/' . $icon . '.svg' );
1328 - }
1329 - return $svg;
1330 - }
1008 + public function excerpt_word($charlength = 200) {
1009 + $html = '';
1010 + $charlength++;
1011 + $excerpt = get_the_excerpt();
1012 + if ( mb_strlen( $excerpt ) > $charlength ) {
1013 + $subex = mb_substr( $excerpt, 0, $charlength - 5 );
1014 + $exwords = explode( ' ', $subex );
1015 + $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
1016 + if ( $excut < 0 ) {
1017 + $html = mb_substr( $subex, 0, $excut );
1018 + } else {
1019 + $html = $subex;
1020 + }
1021 + $html .= '...';
1022 + } else {
1023 + $html = $excerpt;
1024 + }
1025 + return $html;
1026 + }
1331 1027
1332 - /**
1028 +
1029 + /**
1333 1030 * Get Taxonomy Lists
1334 - *
1335 - * @since v.1.0.0
1336 - * @param STRING|ARRAY $prams Taxonomy slug or arguments array.
1031 + *
1032 + * @since v.1.0.0
1033 + * @param STRING | Taxonomy Slug
1337 1034 * @return ARRAY
1338 1035 */
1339 - public function taxonomy( $prams = 'category' ) {
1340 - $data = array();
1036 + public function taxonomy( $prams = 'category' ) {
1037 + $data = array();
1038 + $terms = get_terms( $prams, array(
1039 + 'hide_empty' => false,
1040 + ));
1041 + if( !is_wp_error($terms) ){
1042 + foreach ($terms as $val) {
1043 + $data[urldecode_deep($val->slug)] = $val->name;
1044 + }
1045 + }
1046 + return $data;
1047 + }
1341 1048
1342 - $terms = get_terms(
1343 - is_string( $prams ) ? array(
1344 - 'taxonomy' => $prams,
1345 - 'hide_empty' => false,
1346 - ) : $prams
1347 - );
1348 - if ( ! is_wp_error( $terms ) ) {
1349 - foreach ( $terms as $val ) {
1350 - $data[ urldecode_deep( $val->slug ) ] = $val->name;
1351 - }
1352 - }
1353 - return $data;
1354 - }
1355 1049
1356 -
1357 - /**
1358 - * Get Taxonomy Lists
1359 - *
1360 - * @since v.2.9.0
1361 - * @param STRING $tax_slug Taxonomy slug.
1362 - * @param INT $number Number of terms to retrieve.
1363 - * @return ARRAY
1364 - */
1365 - public function builder_preview( $tax_slug, $number ) {
1366 - $data = array();
1367 - $term_data = get_terms(
1368 - array(
1369 - 'taxonomy' => $tax_slug,
1370 - 'hide_empty' => true,
1371 - 'number' => $number,
1372 - 'parent' => 0,
1373 - )
1374 - );
1375 - if ( ! empty( $term_data ) ) {
1376 - foreach ( $term_data as $terms ) {
1377 - $data[] = $this->get_tax_data( $terms );
1378 - }
1379 - }
1380 - return $data;
1381 - }
1382 -
1383 - /**
1050 + /**
1384 1051 * Get Taxonomy Data Lists
1385 - *
1386 - * @since v.1.0.0
1387 - * @param object $terms Taxonomy Object.
1052 + *
1053 + * @since v.1.0.0
1054 + * @param OBJECT | Taxonomy Object
1388 1055 * @return ARRAY
1389 1056 */
1390 - public function get_tax_data( $terms ) {
1391 - $temp = array();
1392 - $thumbnail_id = get_term_meta( $terms->term_id, 'ultp_category_image', true );
1393 - $image_src = array();
1394 - if ( $thumbnail_id ) {
1395 - $image_sizes = ultimate_post()->get_image_size();
1396 - foreach ( $image_sizes as $key => $value ) {
1397 - $img_src = wp_get_attachment_image_src( $thumbnail_id, $key, false );
1398 - if ( $img_src ) {
1399 - $image_src[ $key ] = $img_src[0];
1400 - }
1401 - }
1402 - }
1403 - $temp['url'] = get_term_link( $terms );
1404 - $temp['thumbnail_id'] = $thumbnail_id;
1405 - $temp['name'] = $terms->name;
1406 - $temp['desc'] = $terms->description;
1407 - $temp['count'] = $terms->count;
1408 - $temp['image'] = $image_src;
1409 - $color = get_term_meta( $terms->term_id, 'ultp_category_color', true );
1410 - $temp['color'] = $color ? $color : '#037fff';
1411 - return $temp;
1412 - }
1057 + public function get_tax_data($terms) {
1058 + $temp = array();
1059 + $image = '';
1060 + $thumbnail_id = get_term_meta( $terms->term_id, 'ultp_category_image', true );
1061 + if( $thumbnail_id ){
1062 + $image = wp_get_attachment_url( $thumbnail_id );
1063 + }
1064 + $temp['url'] = get_term_link($terms);
1065 + $temp['name'] = $terms->name;
1066 + $temp['desc'] = $terms->description;
1067 + $temp['count'] = $terms->count;
1068 + $temp['image'] = $image;
1069 + $color = get_term_meta($terms->term_id, 'ultp_category_color', true);
1070 + $temp['color'] = $color ? $color : '#037fff';
1071 + return $temp;
1072 + }
1413 1073
1414 - public function get_category_data( $catSlug, $number = 40, $type = '', $tax_slug = 'category', $archiveBuilder = '' ) {
1415 - $data = array();
1416 - if ( $type == 'child' ) {
1417 - if ( $archiveBuilder ) {
1418 - $data = $this->builder_preview( $tax_slug, $number );
1419 - } else {
1420 - if ( is_category() ) {
1421 - $catSlug = array( get_queried_object()->slug );
1422 - }
1423 - $image = '';
1424 - if ( ! empty( $catSlug ) ) {
1425 - foreach ( $catSlug as $cat ) {
1426 - $parent_term = get_term_by( 'slug', $cat, $tax_slug );
1427 - if ( ! empty( $parent_term ) ) {
1428 - $term_data = get_terms(
1429 - array(
1430 - 'taxonomy' => $tax_slug,
1431 - 'hide_empty' => true,
1432 - 'number' => $number,
1433 - 'parent' => $parent_term->term_id,
1434 - )
1435 - );
1436 - if ( ! empty( $term_data ) ) {
1437 - foreach ( $term_data as $terms ) {
1438 - $data[] = $this->get_tax_data( $terms );
1439 - }
1440 - }
1441 - }
1442 - }
1443 - }
1444 - }
1445 - } elseif ( $type == 'parent' ) {
1446 - $term_data = is_category() ? array( get_term( get_queried_object()->parent, 'category' ) ) : get_terms(
1447 - array(
1448 - 'taxonomy' => $tax_slug,
1449 - 'hide_empty' => true,
1450 - 'number' => $number,
1451 - 'parent' => 0,
1452 - )
1453 - );
1454 - if ( $archiveBuilder && ! empty( $term_data ) ) {
1455 - $term_data = array( $term_data[0] );
1456 - }
1457 - if ( ! empty( $term_data ) ) {
1458 - foreach ( $term_data as $terms ) {
1459 - if ( ! empty( $terms->term_id ) ) {
1460 - $data[] = $this->get_tax_data( $terms );
1461 - }
1462 - }
1463 - }
1464 - } elseif ( $type == 'custom' ) {
1465 - foreach ( $catSlug as $cat ) {
1466 - $terms = get_term_by( 'slug', $cat, $tax_slug );
1467 - if ( ! empty( $terms ) ) {
1468 - $data[] = $this->get_tax_data( $terms );
1469 - }
1470 - }
1471 - } elseif ( $type == 'immediate_child' ) {
1472 - if ( $archiveBuilder ) {
1473 - $data = $this->builder_preview( $tax_slug, $number );
1474 - } else {
1475 - $id_ = get_queried_object();
1476 - if ( isset( $id_->term_id ) ) {
1477 - $term_data = get_terms(
1478 - array(
1479 - 'taxonomy' => $tax_slug,
1480 - 'hide_empty' => true,
1481 - 'number' => 100,
1482 - 'parent' => $id_->term_id,
1483 - )
1484 - );
1485 - if ( ! empty( $term_data ) ) {
1486 - foreach ( $term_data as $terms ) {
1487 - $data[] = $this->get_tax_data( $terms );
1488 - }
1489 - }
1490 - }
1491 - }
1492 - } elseif ( $type == 'allchild' ) {
1493 - if ( $archiveBuilder ) {
1494 - $data = $this->builder_preview( $tax_slug, $number );
1495 - } else {
1496 - $id_ = get_queried_object();
1497 - if ( isset( $id_->term_taxonomy_id ) ) {
1498 - $termchildren = get_term_children( $id_->term_taxonomy_id, $tax_slug );
1499 - foreach ( $termchildren as $key => $value ) {
1500 - $terms = get_term_by( 'id', $value, $tax_slug );
1501 - $data[] = $this->get_tax_data( $terms );
1502 - }
1503 - }
1504 - }
1505 - } elseif ( $type == 'current_level' ) {
1506 - if ( $archiveBuilder ) {
1507 - $data = $this->builder_preview( $tax_slug, $number );
1508 - } else {
1509 - $id_ = get_queried_object();
1510 - if ( isset( $id_->parent ) ) {
1511 - $term_data = get_terms(
1512 - array(
1513 - 'taxonomy' => $tax_slug,
1514 - 'hide_empty' => true,
1515 - 'number' => $number,
1516 - 'parent' => $id_->parent,
1517 - )
1518 - );
1519 - if ( ! empty( $term_data ) ) {
1520 - foreach ( $term_data as $terms ) {
1521 - if ( $terms->term_id != $id_->term_id ) {
1522 - $data[] = $this->get_tax_data( $terms );
1523 - }
1524 - }
1525 - }
1526 - }
1527 - }
1528 - } else {
1529 - $term_data = get_terms(
1530 - array(
1531 - 'taxonomy' => $tax_slug,
1532 - 'hide_empty' => true,
1533 - 'number' => $number,
1534 - )
1535 - );
1536 - if ( ! empty( $term_data ) ) {
1537 - foreach ( $term_data as $terms ) {
1538 - $data[] = $this->get_tax_data( $terms );
1539 - }
1540 - }
1541 - }
1542 - return $data;
1543 - }
1074 + public function get_category_data($catSlug, $number = 40, $type = '', $tax_slug = 'category') {
1075 + $data = array();
1076 + if($type == 'child'){
1077 + $image = '';
1078 + if (!empty($catSlug)) {
1079 + foreach ($catSlug as $cat) {
1080 + $parent_term = get_term_by('slug', $cat, $tax_slug);
1081 + if (!empty($parent_term)) {
1082 + $term_data = get_terms($tax_slug, array(
1083 + 'hide_empty' => true,
1084 + 'parent' => $parent_term->term_id
1085 + ));
1086 + if (!empty($term_data)) {
1087 + foreach ($term_data as $terms) {
1088 + $data[] = $this->get_tax_data($terms);
1089 + }
1090 + }
1091 + }
1092 + }
1093 + }
1094 + } else if ($type == 'parent') {
1095 + $term_data = get_terms( $tax_slug, array( 'hide_empty' => true, 'number' => $number, 'parent' => 0 ) );
1096 + if (!empty($term_data)) {
1097 + foreach ($term_data as $terms) {
1098 + $data[] = $this->get_tax_data($terms);
1099 + }
1100 + }
1101 + } else if ($type == 'custom') {
1102 + foreach ($catSlug as $cat) {
1103 + $terms = get_term_by('slug', $cat, $tax_slug);
1104 + if (!empty($terms)) {
1105 + $data[] = $this->get_tax_data($terms);
1106 + }
1107 + }
1108 + } else {
1109 + $term_data = get_terms($tax_slug, array('hide_empty' => true, 'number' => $number));
1110 + if (!empty($term_data)) {
1111 + foreach ($term_data as $terms) {
1112 + $data[] = $this->get_tax_data($terms);
1113 + }
1114 + }
1115 + }
1116 + return $data;
1117 + }
1544 1118
1545 1119
1546 - /**
1547 - * Get Next Previous HTML.
1548 - *
1549 - * @since v.1.0.0
1120 + /**
1121 + * Get Next Previous HTML
1122 + *
1123 + * @since v.1.0.0
1124 + * @param OBJECT | Taxonomy Object
1550 1125 * @return STRING
1551 1126 */
1552 - public function next_prev() {
1553 - $html = '';
1554 - $html .= '<ul>';
1555 - $html .= '<li>';
1556 - $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
1557 - $html .= ultimate_post()->get_svg_icon( 'leftAngle2' ) . '<span class="screen-reader-text">' . esc_html__( 'Previous', 'ultimate-post' ) . '</span>';
1558 - $html .= '</a>';
1559 - $html .= '</li>';
1560 - $html .= '<li>';
1561 - $html .= '<a class="ultp-next-action">';
1562 - $html .= ultimate_post()->get_svg_icon( 'rightAngle2' ) . '<span class="screen-reader-text">' . esc_html__( 'Next', 'ultimate-post' ) . '</span>';
1563 - $html .= '</a>';
1564 - $html .= '</li>';
1565 - $html .= '</ul>';
1566 - return $html;
1567 - }
1127 + public function next_prev() {
1128 + $html = '';
1129 + $html .= '<ul>';
1130 + $html .= '<li>';
1131 + $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
1132 + $html .= ultimate_post()->svg_icon('leftAngle2').'<span class="screen-reader-text">'.__("Previous", "ultimate-post").'</span>';
1133 + $html .= '</a>';
1134 + $html .= '</li>';
1135 + $html .= '<li>';
1136 + $html .= '<a class="ultp-next-action">';
1137 + $html .= ultimate_post()->svg_icon('rightAngle2').'<span class="screen-reader-text">'.__("Next", "ultimate-post").'</span>';
1138 + $html .= '</a>';
1139 + $html .= '</li>';
1140 + $html .= '</ul>';
1141 + return $html;
1142 + }
1568 1143
1569 1144
1570 - /**
1145 + /**
1571 1146 * Get Loading HTML
1572 - *
1573 - * @since v.1.0.0
1147 + *
1148 + * @since v.1.0.0
1149 + * @param NULL
1574 1150 * @return STRING
1575 1151 */
1576 - public function postx_loading() {
1577 - $html = '';
1578 - $style = ultimate_post()->get_setting( 'preloader_style' );
1579 - if ( $style == 'style2' ) {
1580 - $html .= '<div class="ultp-loading-spinner" style="width:100%;height:100%"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>'; // ultp-block-items-wrap
1581 - } else {
1582 - $html .= '<div class="ultp-loading-blocks" style="width:100%;height:100%;"><div style="left: 0;top: 0;animation-delay:0s;"></div><div style="left: 21px;top: 0;animation-delay:0.125s;"></div><div style="left: 42px;top: 0;animation-delay:0.25s;"></div><div style="left: 0;top: 21px;animation-delay:0.875s;"></div><div style="left: 42px;top: 21px;animation-delay:0.375s;"></div><div style="left: 0;top: 42px;animation-delay:0.75s;"></div><div style="left: 42px;top: 42px;animation-delay:0.625s;"></div><div style="left: 21px;top: 42px;animation-delay:0.5s;"></div></div>';
1583 - }
1584 - return '<div class="ultp-loading">' . $html . '</div>';
1585 - }
1152 + public function loading(){
1153 + $html = '';
1154 + $style = ultimate_post()->get_setting('preloader_style');
1155 + if( $style == 'style2' ){
1156 + $html .= '<div class="ultp-loading-spinner" style="width:100%;height:100%"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>';//ultp-block-items-wrap
1157 + } else {
1158 + $html .= '<div class="ultp-loading-blocks" style="width:100%;height:100%;"><div style="left: 0;top: 0;animation-delay:0s;"></div><div style="left: 21px;top: 0;animation-delay:0.125s;"></div><div style="left: 42px;top: 0;animation-delay:0.25s;"></div><div style="left: 0;top: 21px;animation-delay:0.875s;"></div><div style="left: 42px;top: 21px;animation-delay:0.375s;"></div><div style="left: 0;top: 42px;animation-delay:0.75s;"></div><div style="left: 42px;top: 42px;animation-delay:0.625s;"></div><div style="left: 21px;top: 42px;animation-delay:0.5s;"></div></div>';
1159 + }
1160 + return '<div class="ultp-loading">'.$html.'</div>';
1161 + }
1586 1162
1587 1163
1588 - /**
1164 + /**
1589 1165 * Get Filter HTML
1590 - *
1591 - * @since v.1.0.0
1592 - * @param STRING $filterText Filter Text.
1593 - * @param STRING $filterType Filter Type.
1594 - * @param ARRAY|STRING $filterValue Filter Value.
1595 - * @param STRING $filterMobileText Filter Mobile Text.
1596 - * @param BOOL $filterMobile Enable Filter Mobile.
1166 + *
1167 + * @since v.1.0.0
1168 + * @param | Filter Text (STRING) | Filter Type (STRING) | Filter Value (ARRAY) | Filter Cat (ARRAY) | Filter Tag (ARRAY) |
1597 1169 * @return STRING
1598 1170 */
1599 - public function filter_html( $filterText = '', $filterType = '', $filterValue = '[]', $filterMobileText = '...', $filterMobile = true ) {
1600 - $html = '';
1601 - $html .= '<ul ' . ( $filterMobile ? 'class="ultp-flex-menu"' : '' ) . ' data-name="' . ( $filterMobileText ? $filterMobileText : '&nbsp;' ) . '">';
1602 - $cat = $this->taxonomy( $filterType );
1603 - if ( $filterText ) {
1604 - $html .= '<li class="filter-item"><a class="filter-active" data-taxonomy="" href="#">' . $filterText . '</a></li>';
1605 - }
1606 - if ( $filterValue ) {
1607 - $filterValue = strlen( $filterValue ) > 2 ? $filterValue : array();
1608 - $filterValue = is_array( $filterValue ) ? $filterValue : json_decode( $filterValue );
1609 - if ( is_array( $filterValue ) && count( $filterValue ) ) {
1610 - foreach ( $filterValue as $val ) {
1611 - $val = isset( $val->value ) ? $val->value : $val;
1612 - $html .= '<li class="filter-item"><a data-taxonomy="' . $val . '" href="#">' . ( isset( $cat[ $val ] ) ? $cat[ $val ] : $val ) . '</a></li>';
1613 - }
1614 - }
1615 - }
1616 - $html .= '</ul>';
1617 - return $html;
1618 - }
1171 + public function filter($filterText = '', $filterType = '', $filterValue = '[]', $filterMobileText = '...', $filterMobile = true){
1172 + $html = '';
1173 + $html .= '<ul '.($filterMobile ? 'class="ultp-flex-menu"' : '').' data-name="'.($filterMobileText ? $filterMobileText : '&nbsp;').'">';
1174 + $cat = $this->taxonomy($filterType);
1175 + if($filterText){
1176 + $html .= '<li class="filter-item"><a class="filter-active" data-taxonomy="" href="#">'.$filterText.'</a></li>';
1177 + }
1619 1178
1179 + if ($filterValue) {
1180 + $filterValue = strlen($filterValue) > 2 ? $filterValue : [];
1181 + $filterValue = is_array($filterValue) ? $filterValue : json_decode($filterValue);
1182 + foreach ($filterValue as $val) {
1183 + $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($cat[$val]) ? $cat[$val] : $val).'</a></li>';
1184 + }
1185 + }
1186 + $html .= '</ul>';
1187 + return $html;
1188 + }
1620 1189
1621 - /**
1190 +
1191 + /**
1622 1192 * Check License Status
1623 - *
1624 - * @since v.2.4.2
1193 + *
1194 + * @since v.2.4.2
1625 1195 * @return BOOLEAN | Is pro license active or not
1626 1196 */
1627 - public function is_lc_active() {
1628 - return Xpo::is_lc_active();
1629 - }
1197 + public function is_lc_active() {
1198 + if (function_exists('ultimate_post_pro')) {
1199 + return get_option('edd_ultp_license_status') == 'valid' ? true : false;
1200 + }
1201 + if (get_transient( 'ulpt_theme_enable' ) == 'integration') {
1202 + return true;
1203 + }
1204 + return false;
1205 + }
1630 1206
1631 1207
1632 - /**
1633 - * Check if a pro feature is visible based on license expiration date.
1634 - *
1635 - * @since v.2.4.2
1636 - * @param STRING $date Date to compare with license expiration.
1637 - * @return BOOL True if the pro feature is visible, false otherwise.
1208 + /**
1209 + * Get SVG Icon
1210 + *
1211 + * @since v.1.0.0
1212 + * @param STRING | Icon Key
1213 + * @return STRING | Icon SVG
1638 1214 */
1639 - public function is_pro_feature_visible( $date ) {
1640 - if ( function_exists( 'ultimate_post_pro' ) ) {
1641 - $license_data = get_option( 'edd_ultp_license_data' );
1642 - if ( isset( $license_data['expires'] ) ) {
1643 - $expires = $license_data['expires'];
1644 - if ( 'lifetime' === $expires ) {
1645 - return true;
1646 - }
1647 - return strtotime( $date ) < strtotime( $expires );
1648 - }
1649 - return true;
1650 - }
1651 - return false;
1652 - }
1215 + public function svg_icon($icons = ''){
1216 + $icon_lists = array(
1217 + 'eye' => file_get_contents(ULTP_PATH.'assets/img/svg/eye.svg'),
1218 + 'user' => file_get_contents(ULTP_PATH.'assets/img/svg/user.svg'),
1219 + 'calendar' => file_get_contents(ULTP_PATH.'assets/img/svg/calendar.svg'),
1220 + 'comment' => file_get_contents(ULTP_PATH.'assets/img/svg/comment.svg'),
1221 + 'book' => file_get_contents(ULTP_PATH.'assets/img/svg/book.svg'),
1222 + 'tag' => file_get_contents(ULTP_PATH.'assets/img/svg/tag.svg'),
1223 + 'clock' => file_get_contents(ULTP_PATH.'assets/img/svg/clock.svg'),
1224 + 'leftAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle.svg'),
1225 + 'rightAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle.svg'),
1226 + 'leftAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle2.svg'),
1227 + 'rightAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle2.svg'),
1228 + 'leftArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/leftArrowLg.svg'),
1229 + 'refresh' => file_get_contents(ULTP_PATH.'assets/img/svg/refresh.svg'),
1230 + 'rightArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/rightArrowLg.svg'),
1231 + );
1232 + if($icons){
1233 + return $icon_lists[ $icons ];
1234 + }
1235 + }
1653 1236
1654 - /**
1237 + /**
1655 1238 * Get SEO Meta
1656 - *
1657 - * @since v.2.4.3
1658 - * @param INT $post_id Post ID.
1659 - * @param INT $show_seo_meta Show SEO meta flag.
1660 - * @param INT $show_full_excerpt Show full excerpt flag.
1661 - * @param INT $excerpt_limit Excerpt word limit.
1662 - * @return STRING SEO Meta Description or Excerpt.
1239 + *
1240 + * @since v.2.4.3
1241 + * @param NUMBER | Post ID
1242 + * @return STRING | SEO Meta Description or Excerpt
1663 1243 */
1664 - public function get_excerpt( $post_id = 0, $show_seo_meta = 0, $show_full_excerpt = 0, $excerpt_limit = 55 ) {
1665 - $html = '';
1666 - if ( $show_seo_meta ) {
1667 - $str = '';
1668 - if ( function_exists( 'ultimate_post_pro' ) ) {
1669 - if ( ultimate_post()->get_setting( 'ultp_yoast' ) == 'true' ) {
1670 - $str = method_exists( ultimate_post_pro(), 'get_yoast_meta' ) ? ultimate_post_pro()->get_yoast_meta( $post_id ) : '';
1671 - } elseif ( ultimate_post()->get_setting( 'ultp_rankmath' ) == 'true' ) {
1672 - $str = method_exists( ultimate_post_pro(), 'get_rankmath_meta' ) ? ultimate_post_pro()->get_rankmath_meta( $post_id ) : '';
1673 - } elseif ( ultimate_post()->get_setting( 'ultp_aioseo' ) == 'true' ) {
1674 - $str = method_exists( ultimate_post_pro(), 'get_aioseo_meta' ) ? ultimate_post_pro()->get_aioseo_meta( $post_id ) : '';
1675 - } elseif ( ultimate_post()->get_setting( 'ultp_seopress' ) == 'true' ) {
1676 - $str = method_exists( ultimate_post_pro(), 'get_seopress_meta' ) ? ultimate_post_pro()->get_seopress_meta( $post_id ) : '';
1677 - } elseif ( ultimate_post()->get_setting( 'ultp_squirrly' ) == 'true' ) {
1678 - $str = method_exists( ultimate_post_pro(), 'get_squirrly_meta' ) ? ultimate_post_pro()->get_squirrly_meta( $post_id ) : '';
1679 - }
1680 - }
1681 - $html = $str ? $str : ultimate_post()->excerpt( $post_id, $excerpt_limit );
1682 - } elseif ( $show_full_excerpt == 0 ) {
1683 - $html = ultimate_post()->excerpt( $post_id, $excerpt_limit );
1684 - } else {
1685 - $html = get_the_excerpt();
1686 - }
1687 - return $html;
1688 - }
1689 -
1690 - /**
1691 - * Get embedded video HTML.
1692 - *
1693 - * @since v.1.0.0
1694 - * @param STRING $url Video URL.
1695 - * @param BOOL $autoPlay Whether to autoplay the video.
1696 - * @param BOOL $loop Whether to loop the video.
1697 - * @param BOOL $mute Whether to mute the video.
1698 - * @param BOOL $playback Whether to show playback controls.
1699 - * @param STRING $preload Preload attribute value.
1700 - * @param ARRAY | string $poster Poster image for the video.
1701 - * @param BOOL $inline Whether to play inline.
1702 - * @param ARRAY | string $size Size for oEmbed.
1703 - * @return STRING | false Video embed HTML or false on failure.
1704 - */
1705 - public function get_embeded_video( $url, $autoPlay, $loop, $mute, $playback, $preload, $poster, $inline, $size, $location = '' ) {
1706 - $vidAutoPlay = $vidloop = $vidloop = $vidmute = $vidplayback = $vidPoster = $vidInline = '';
1707 -
1708 - $video_type = '';
1709 - // Determine video type
1710 - $video_type = 'local';
1711 - if ( strpos( $url, 'youtube.com' ) !== false || strpos( $url, 'youtu.be' ) !== false ) {
1712 - $video_type = 'youtube';
1713 - } elseif ( strpos( $url, 'vimeo.com' ) !== false ) {
1714 - $video_type = 'vimeo';
1715 - }
1716 -
1717 - // Get poster URL
1718 - $poster_url = '';
1719 - if ( is_array( $poster ) && isset( $poster['url'] ) ) {
1720 - $poster_url = $poster['url'];
1721 - } elseif ( is_string( $poster ) ) {
1722 - $poster_url = $poster;
1723 - }
1724 -
1725 - // Prepare size attributes
1726 - $width = is_array( $size ) && isset( $size['width'] ) ? $size['width'] : 560;
1727 - $height = is_array( $size ) && isset( $size['height'] ) ? $size['height'] : 315;
1728 -
1729 - $video_id = '';
1730 -
1731 - if ( $url ) {
1732 - $regex = '/(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})/';
1733 - if ( preg_match( $regex, $url, $matches ) ) {
1734 - $video_id = $matches[1];
1735 - }
1736 - }
1737 -
1738 - // Create data attributes for lazy loading
1739 - $data_attrs = array(
1740 - 'data-video-url' => is_scalar( $url ) ? esc_attr( $url ) : '',
1741 - 'data-video-type' => is_scalar( $video_type ) ? esc_attr( $video_type ) : '',
1742 - 'data-autoplay' => ! empty( $autoPlay ) ? '1' : '0',
1743 - 'data-loop' => ! empty( $loop ) ? '1' : '0',
1744 - 'data-mute' => ! empty( $mute ) ? '1' : '0',
1745 - 'data-controls' => ! empty( $playback ) ? '1' : '0',
1746 - 'data-preload' => is_scalar( $preload ) ? esc_attr( $preload ) : '',
1747 - 'data-poster' => is_scalar( $poster_url ) ? esc_attr( $poster_url ) : '',
1748 - 'data-playsinline' => ! empty( $inline ) ? '1' : '0',
1749 - 'data-width' => is_scalar( $width ) ? esc_attr( $width ) : '',
1750 - 'data-height' => is_scalar( $height ) ? esc_attr( $height ) : '',
1751 - 'data-video-id' => is_scalar( $video_id ) ? esc_attr( $video_id ) : '',
1752 - );
1753 -
1754 - $data_string = implode(
1755 - ' ',
1756 - array_map(
1757 - function ( $key, $value ) {
1758 - return $key . '="' . $value . '"';
1759 - },
1760 - array_keys( $data_attrs ),
1761 - $data_attrs
1762 - )
1763 - );
1764 -
1765 - $html = '<div class="ultp-video-wrapper ultp-embaded-video"' . $data_string . '></div>';
1766 -
1767 - if ( $location == '' ) {
1768 - return $html;
1769 - }
1770 -
1771 - if ( $autoPlay ) {
1772 - $vidAutoPlay = 'autoplay';
1773 - }
1774 - if ( $poster ) {
1775 - $vidPoster = 'poster="' . $poster['url'] . '"';
1776 - }
1777 - if ( $loop ) {
1778 - $vidloop = 'loop';
1779 - }
1780 - if ( $mute ) {
1781 - $vidmute = 'muted';
1782 - }
1783 - if ( $playback ) {
1784 - $vidplayback = 'controls';
1785 - }
1786 - if ( $inline ) {
1787 - $vidInline = 'playsinline';
1788 - }
1789 - if ( ! empty( $url ) ) {
1790 - $embeded = wp_oembed_get( $url, $size );
1791 - if ( $embeded == false ) {
1792 - $format = '';
1793 - $url = strtolower( $url );
1794 - if ( strpos( $url, '.mp4' ) ) {
1795 - $format = 'mp4';
1796 - } elseif ( strpos( $url, '.ogg' ) ) {
1797 - $format = 'ogg';
1798 - } elseif ( strpos( $url, '.webm' ) ) {
1799 - $format = 'WebM';
1800 - }
1801 - $embeded = '<video
1802 - ' . $vidloop . '
1803 - ' . $vidmute . '
1804 - ' . $vidplayback . '
1805 - preload="' . $preload . '"
1806 - ' . $vidAutoPlay . '
1807 - ' . $vidPoster . '
1808 - ' . $vidInline . '
1809 - class="ultp-video-html"
1810 - ><source src="' . $url . '" type="video/' . $format . '">' . __( 'Your browser does not support the video tag.', 'ultimate-post' ) . '</video>';
1811 - return '<div class="ultp-video-wrapper">' . $embeded . '</div>';
1812 - }
1813 - return '<div class="ultp-video-wrapper ultp-embaded-video">' . $embeded . '</div>';
1814 - } else {
1815 - return false;
1816 - }
1817 - }
1818 -
1819 - /**
1820 - * Get Public taxonomy Lists
1821 - *
1822 - * @since v.2.7.0
1823 - * @return ARRAY | Taxonomy Lists as array
1824 - */
1825 - public function get_taxonomy_list() {
1826 - $taxonomy = get_taxonomies( array( 'public' => true ) );
1827 - return empty( $taxonomy ) ? array() : array_keys( $taxonomy );
1828 - }
1829 -
1830 - /**
1831 - * Content Print
1832 - *
1833 - * @since v.2.7.0
1834 - * @param int $post_id Post ID.
1835 - * @param string $builder_type Builder type.
1836 - * @return void | Content of the Post
1837 - */
1838 - public function get_post_content( $post_id, $builder_type = '' ) {
1839 - $content_post = get_post( $post_id );
1840 - $content = $content_post->post_content;
1841 - if ( $builder_type == 'divi' || $builder_type == 'elementor' ) {
1842 - $content = apply_filters( 'the_content', $content );
1843 - } else {
1844 - global $wp_embed;
1845 - $content = $wp_embed->autoembed( $content );
1846 - $content = do_blocks( $content );
1847 - $content = do_shortcode( $content );
1848 - }
1849 - $content = str_replace( ']]>', ']]&gt;', $content );
1850 - $content = preg_replace( '%<p>&nbsp;\s*</p>%', '', $content );
1851 - $content = preg_replace( '/^(?:<br\s*\/?>\s*)+/', '', $content );
1852 - echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1853 - }
1854 -
1855 - /**
1856 - * String Part finder inside array.
1857 - *
1858 - * @since v.2.7.0 updated 4.1.12
1859 - *
1860 - * @param STRING $part The part of the string to search for.
1861 - * @param ARRAY $data The array to search within.
1862 - * @param STRING $toR Return type: 'bool', 'value', or default (array).
1863 - * @return MIXED Returns true/false, value, or array depending on $toR.
1864 - * @since v.2.7.0 updated 4.1.12
1865 - */
1866 - public function in_array_part( $part, $data, $toR = '' ) {
1867 - $res = array();
1868 - foreach ( $data as $key => $val ) {
1869 - if ( strpos( $val, $part ) !== false ) {
1870 - if ( $toR == 'bool' ) {
1871 - return true;
1872 - } elseif ( $toR == 'value' ) {
1873 - return $val;
1874 - }
1875 - $res[ $key ] = $val;
1876 - }
1877 - }
1878 - if ( $toR == 'bool' ) {
1879 - return false;
1880 - } elseif ( $toR == 'value' ) {
1881 - return '';
1882 - }
1883 - return $res;
1884 - }
1885 -
1886 - /**
1887 - * Builder Conditions
1888 - *
1889 - * @since v.2.7.0 updated 4.1.12
1890 - * @param STRING $type Type of return value.
1891 - * @param MIXED $cus_condition Custom conditions array or value.
1892 - * @return MIXED ID or Path.
1893 - */
1894 - public function builder_check_conditions( $type = 'return', $cus_condition = '' ) {
1895 - $page_id = '';
1896 - $conditions = $cus_condition ? $cus_condition : get_option( 'ultp_builder_conditions', array() );
1897 -
1898 - if ( $type == 'header' || $type == 'footer' ) {
1899 - if ( ! empty( $conditions[ $type ] ) ) {
1900 - foreach ( $conditions[ $type ] as $key => $val ) {
1901 - if ( 'publish' == get_post_status( $key ) && ! empty( $val ) ) {
1902 - if ( in_array( 'include/' . $type . '/entire_site', $val ) ) {
1903 - $page_id = $key;
1904 - } elseif ( in_array( 'exclude/' . $type . '/entire_site', $val ) ) {
1905 - $page_id = '';
1906 - }
1907 -
1908 - $c_page = ( is_archive() || is_search() ) ? 'archive' : 'singular';
1909 - $hf_archive = $this->in_array_part( $type . '/' . $c_page, $val, '' );
1910 - if ( ! empty( $hf_archive ) ) {
1911 - foreach ( $hf_archive as $k => $v ) {
1912 - if ( strpos( $v, 'include/' . $type . '/' . $c_page ) !== false ) {
1913 - $temp = $this->builder_check_conditions( 'return_' . $type, array( $c_page => array( $key => array( str_replace( $type . '/', '', $v ) ) ) ) );
1914 - $page_id = $temp ? $temp : $page_id;
1915 - } elseif ( strpos( $v, 'exclude/' . $type . '/' . $c_page ) !== false ) {
1916 - $temp = $this->builder_check_conditions( 'return_' . $type, array( $c_page => array( $key => array( str_replace( 'exclude/' . $type, 'include', $v ) ) ) ) );
1917 - $page_id = $temp ? '' : $page_id;
1918 - }
1919 - }
1920 - }
1921 - }
1922 - }
1923 - }
1924 - } else {
1925 - // 404 page .
1926 - if ( ! empty( $conditions['404'] ) && is_404() ) {
1927 - foreach ( $conditions['404'] as $key => $val ) {
1928 - if ( 'publish' == get_post_status( $key ) ) {
1929 - $page_id = $key;
1930 - }
1931 - }
1932 - }
1933 - // Singular or Front Page .
1934 - elseif (
1935 - (
1936 - ! empty( $conditions['singular'] ) ||
1937 - ! empty( $conditions['front_page'] )
1938 - ) &&
1939 - (
1940 - is_singular() ||
1941 - is_front_page() ||
1942 - is_home()
1943 - )
1944 - ) {
1945 - $obj = get_queried_object();
1946 - $queried_is_obj = is_object( $obj );
1947 - // front page only .
1948 - if (
1949 - ( is_front_page() && is_home() ) ||
1950 - ( is_home() && ! $queried_is_obj ) ||
1951 - ( is_singular() && is_front_page() && $queried_is_obj )
1952 - ) {
1953 - $f_conditions = array();
1954 - if ( ! empty( $conditions['front_page'] ) ) {
1955 - $f_conditions = $conditions['front_page'];
1956 - } elseif ( ! empty( $conditions['singular'] ) ) {
1957 - $f_conditions = $conditions['singular'];
1958 - }
1959 - if ( ! empty( $f_conditions ) ) {
1960 - foreach ( $f_conditions as $key => $val ) {
1961 - if ( ( is_array( $val ) && in_array( 'include/singular/front_page', $val ) ) ||
1962 - ( is_array( $val ) && in_array( 'include/front_page', $val ) ) ||
1963 - 'include/front_page' == $val
1964 - ) {
1965 - if ( 'publish' == get_post_status( $key ) ) {
1966 - $page_id = $key;
1967 - }
1968 - }
1969 - // Default Front / Home page Header Footer Compatibility .
1970 - elseif ( is_array( $val ) && 'publish' == get_post_status( $key ) && ( $type == 'return_header' || $type == 'return_footer' ) ) {
1971 - $base_include = 'include/singular/' . $obj->post_type;
1972 - $base_exclude = 'exclude/singular/' . $obj->post_type;
1973 - $specific_include = $base_include . '/' . $obj->ID;
1974 - $specific_exclude = $base_exclude . '/' . $obj->ID;
1975 -
1976 - if ( in_array( $specific_include, $val ) ) {
1977 - $page_id = $key;
1978 - } elseif ( in_array( $specific_exclude, $val ) ) {
1979 - $page_id = '';
1980 - } elseif ( in_array( $base_include, $val ) ) {
1981 - $page_id = $key;
1982 - } elseif ( in_array( $base_exclude, $val ) ) {
1983 - $page_id = '';
1984 - }
1985 - }
1986 - }
1987 - }
1988 - }
1989 - // Singular page .
1990 - elseif ( ! empty( $conditions['singular'] ) ) {
1991 - foreach ( $conditions['singular'] as $key => $val ) {
1992 - if ( 'publish' == get_post_status( $key ) ) {
1993 - // All Post Type. -----Prority 1 .
1994 - if ( $queried_is_obj ) {
1995 - if ( in_array( 'include/singular/' . $obj->post_type, $val ) ) {
1996 - $page_id = $key;
1997 - } elseif ( in_array( 'exclude/singular/' . $obj->post_type, $val ) ) {
1998 - $page_id = '';
1999 - }
2000 - }
2001 -
2002 - $singular_in_tax = $this->in_array_part( '/singular/in_', $val, '' );
2003 - if ( ! empty( $singular_in_tax ) ) {
2004 - $tax_list = $this->get_taxonomy_list();
2005 - foreach ( $tax_list as $tax ) {
2006 - if ( in_array( 'include/singular/in_' . $tax . '_children', $singular_in_tax ) ) {
2007 - $page_id = $key;
2008 - } elseif ( in_array( 'exclude/singular/in_' . $tax . '_children', $singular_in_tax ) ) {
2009 - $page_id = '';
2010 - }
2011 -
2012 - if ( $queried_is_obj ) {
2013 - $singular_in_tax_children = $this->in_array_part( '/singular/in_' . $tax . '_children/', $singular_in_tax, '' );
2014 - foreach ( $singular_in_tax_children as $v ) {
2015 - $data = explode( '/', $v );
2016 - if ( isset( $data[3] ) && $data[3] ) {
2017 - $childs = get_term_children( $data[3], $tax );
2018 - if ( ! empty( $childs ) && has_term( $childs, $tax ) ) {
2019 - $page_id = $data[0] == 'exclude' ? '' : $key;
2020 - }
2021 - }
2022 - }
2023 - }
2024 -
2025 - if ( in_array( 'include/singular/in_' . $tax, $singular_in_tax ) ) {
2026 - if ( $tax == 'post_tag' && $queried_is_obj ) {
2027 - $cat = get_the_terms( $obj->ID, 'post_tag' );
2028 - if ( ! empty( $cat ) ) {
2029 - $page_id = $key;
2030 - }
2031 - } else {
2032 - $page_id = $key;
2033 - }
2034 - } elseif ( in_array( 'exclude/singular/in_' . $tax, $singular_in_tax ) ) {
2035 - $page_id = '';
2036 - }
2037 -
2038 - if ( $queried_is_obj ) {
2039 - $singular_in_tax_only = $this->in_array_part( '/singular/in_' . $tax . '/', $singular_in_tax, '' );
2040 - foreach ( $singular_in_tax_only as $v ) {
2041 - $data = explode( '/', $v );
2042 - if ( isset( $data[3] ) && $data[3] ) {
2043 - if ( is_object_in_term( $obj->ID, $tax, $data[3] ) ) {
2044 - $page_id = $data[0] == 'exclude' ? '' : $key;
2045 - }
2046 - }
2047 - }
2048 - }
2049 - }
2050 - }
2051 -
2052 - // Posts by author -----Prority 9 .
2053 - if ( in_array( 'include/singular/post_by_author', $val ) ) {
2054 - $page_id = $key;
2055 - } elseif ( in_array( 'exclude/singular/post_by_author', $val ) ) {
2056 - $page_id = '';
2057 - }
2058 - if ( $queried_is_obj ) {
2059 - if ( in_array( 'include/singular/post_by_author/' . $obj->post_author, $val ) ) {
2060 - $page_id = $key;
2061 - } elseif ( in_array( 'exclude/singular/post_by_author/' . $obj->post_author, $val ) ) {
2062 - $page_id = '';
2063 - }
2064 - // Post Type with specific id -----Prority 10 .
2065 - if ( in_array( 'include/singular/' . $obj->post_type . '/' . $obj->ID, $val ) ) {
2066 - $page_id = $key;
2067 - } elseif ( in_array( 'exclude/singular/' . $obj->post_type . '/' . $obj->ID, $val ) ) {
2068 - $page_id = '';
2069 - }
2070 - }
2071 - }
2072 - }
2073 - }
2074 - }
2075 -
2076 - // Archive and Search Page .
2077 - elseif ( ! empty( $conditions['archive'] ) ) {
2078 - // Search Page .
2079 - if ( is_search() ) {
2080 - foreach ( $conditions['archive'] as $key => $val ) {
2081 - if ( 'publish' == get_post_status( $key ) ) {
2082 - if ( in_array( 'include/archive/search', $val ) ) {
2083 - $page_id = $key;
2084 - } elseif ( in_array( 'exclude/archive/search', $val ) ) {
2085 - $page_id = '';
2086 - }
2087 - }
2088 - }
2089 - }
2090 - // Archive Page .
2091 - elseif ( is_archive() ) {
2092 - $is_cat = is_category();
2093 - $is_tag = is_tag();
2094 - $is_tax = is_tax();
2095 - $is_date = is_date();
2096 - $is_author = is_author();
2097 - $taxonomy = ( $is_cat || $is_tag || $is_tax ) ? get_queried_object() : (object) array();
2098 -
2099 - foreach ( $conditions['archive'] as $key => $val ) {
2100 - if ( 'publish' == get_post_status( $key ) ) {
2101 - // This section is for all archive page .
2102 - if ( in_array( 'include/archive', $val ) ) {
2103 - $page_id = $key;
2104 - } elseif ( in_array( 'exclude/archive', $val ) ) {
2105 - $page_id = '';
2106 - }
2107 - // For Category .
2108 - if ( $is_cat ) {
2109 - // all category .
2110 - if ( in_array( 'include/archive/category', $val ) ) {
2111 - $page_id = $key;
2112 - } elseif ( in_array( 'exclude/archive/category', $val ) ) {
2113 - $page_id = '';
2114 - }
2115 - // specific category .
2116 - if ( in_array( 'include/archive/category/' . $taxonomy->term_id, $val ) ) {
2117 - $page_id = $key;
2118 - } elseif ( in_array( 'exclude/archive/category/' . $taxonomy->term_id, $val ) ) {
2119 - $page_id = '';
2120 - }
2121 -
2122 - // any child of category .
2123 - if ( in_array( 'include/archive/any_child_of_category', $val ) ) {
2124 - $page_id = $key;
2125 - } elseif ( in_array( 'exclude/archive/any_child_of_category', $val ) ) {
2126 - $page_id = '';
2127 - }
2128 -
2129 - $any_child_of_cat = $this->in_array_part( 'archive/any_child_of_category/', $val, '' );
2130 - if ( ! empty( $any_child_of_cat ) ) {
2131 - foreach ( $any_child_of_cat as $v ) {
2132 - $data = explode( '/', $v );
2133 - if ( isset( $data[3] ) && $data[3] ) {
2134 - if ( term_is_ancestor_of( $data[3], $taxonomy->term_id, 'category' ) ) {
2135 - $page_id = $data[0] == 'exclude' ? '' : $key;
2136 - }
2137 - }
2138 - }
2139 - }
2140 -
2141 - // all child of category .
2142 - if ( in_array( 'include/archive/child_of_category', $val ) ) {
2143 - $page_id = $key;
2144 - } elseif ( in_array( 'exclude/archive/child_of_category', $val ) ) {
2145 - $page_id = '';
2146 - }
2147 - // specific child of category .
2148 - if ( in_array( 'include/archive/child_of_category/' . $taxonomy->parent, $val ) ) {
2149 - $page_id = $key;
2150 - } elseif ( in_array( 'exclude/archive/child_of_category/' . $taxonomy->parent, $val ) ) {
2151 - $page_id = '';
2152 - }
2153 - }
2154 - // For Tag .
2155 - elseif ( $is_tag ) {
2156 - if ( in_array( 'include/archive/post_tag', $val ) ) {
2157 - $page_id = $key;
2158 - } elseif ( in_array( 'exclude/archive/post_tag', $val ) ) {
2159 - $page_id = '';
2160 - }
2161 - if ( in_array( 'include/archive/post_tag/' . $taxonomy->term_id, $val ) ) {
2162 - $page_id = $key;
2163 - } elseif ( in_array( 'exclude/archive/post_tag/' . $taxonomy->term_id, $val ) ) {
2164 - $page_id = '';
2165 - }
2166 - }
2167 - // Other taxonomy .
2168 - elseif ( $is_tax ) {
2169 - if ( in_array( 'include/archive/' . $taxonomy->taxonomy, $val ) ) {
2170 - $page_id = $key;
2171 - } elseif ( in_array( 'exclude/archive/' . $taxonomy->taxonomy, $val ) ) {
2172 - $page_id = '';
2173 - }
2174 -
2175 - if ( in_array( 'include/archive/' . $taxonomy->taxonomy . '/' . $taxonomy->term_id, $val ) ) {
2176 - $page_id = $key;
2177 - } elseif ( in_array( 'exclude/archive/' . $taxonomy->taxonomy . '/' . $taxonomy->term_id, $val ) ) {
2178 - $page_id = '';
2179 - }
2180 -
2181 - if ( in_array( 'include/archive/any_child_of_' . $taxonomy->taxonomy, $val ) ) {
2182 - $page_id = $key;
2183 - } elseif ( in_array( 'exclude/archive/any_child_of_' . $taxonomy->taxonomy, $val ) ) {
2184 - $page_id = '';
2185 - }
2186 -
2187 - $any_child_of_tax = $this->in_array_part( 'archive/any_child_of_' . $taxonomy->taxonomy . '/', $val, '' );
2188 - if ( ! empty( $any_child_of_tax ) ) {
2189 - foreach ( $any_child_of_tax as $v ) {
2190 - $data = explode( '/', $v );
2191 - if ( isset( $data[3] ) && $data[3] ) {
2192 - if ( term_is_ancestor_of( $data[3], $taxonomy->term_id, $taxonomy->taxonomy ) ) {
2193 - $page_id = $data[0] == 'exclude' ? '' : $key;
2194 - }
2195 - }
2196 - }
2197 - }
2198 -
2199 - if ( in_array( 'include/archive/child_of_' . $taxonomy->taxonomy, $val ) ) {
2200 - $page_id = $key;
2201 - } elseif ( in_array( 'exclude/archive/child_of_' . $taxonomy->taxonomy, $val ) ) {
2202 - $page_id = '';
2203 - }
2204 -
2205 - if ( in_array( 'include/archive/child_of_' . $taxonomy->taxonomy . '/' . $taxonomy->parent, $val ) ) {
2206 - $page_id = $key;
2207 - } elseif ( in_array( 'exclude/archive/child_of_' . $taxonomy->taxonomy . '/' . $taxonomy->parent, $val ) ) {
2208 - $page_id = '';
2209 - }
2210 - }
2211 - // For Date.
2212 - elseif ( $is_date ) {
2213 - if ( in_array( 'include/archive/date', $val ) ) {
2214 - $page_id = $key;
2215 - } elseif ( in_array( 'exclude/archive/date', $val ) ) {
2216 - $page_id = '';
2217 - }
2218 - }
2219 - // For Author.
2220 - elseif ( $is_author ) {
2221 - if ( in_array( 'include/archive/author', $val ) ) {
2222 - $page_id = $key;
2223 - } elseif ( in_array( 'exclude/archive/author', $val ) ) {
2224 - $page_id = '';
2225 - }
2226 - $author_id = get_the_author_meta( 'ID' );
2227 - if ( in_array( 'include/archive/author/' . $author_id, $val ) ) {
2228 - $page_id = $key;
2229 - } elseif ( in_array( 'exclude/archive/author/' . $author_id, $val ) ) {
2230 - $page_id = '';
2231 - }
2232 - }
2233 - }
2234 - }
2235 - }
2236 - }
2237 - }
2238 - return $page_id;
2239 - }
2240 -
2241 - /**
2242 - * Get Date Default Format
2243 - *
2244 - * @since v.2.7.2
2245 - * @param STRING $format Format type.
2246 - * @return ARRAY | Default Data
2247 - */
2248 - public function get_format( $format ) {
2249 - if ( $format == 'default_date' ) {
2250 - return get_option( 'date_format' );
2251 - } elseif ( $format == 'default_date_time' ) {
2252 - return get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
2253 - } else {
2254 - return $format;
2255 - }
2256 - }
2257 -
2258 - /**
2259 - * Common Frontend and Backend CSS and JS Scripts
2260 - *
2261 - * @since v.1.0.0
2262 - */
2263 - public function register_scripts_common() {
2264 - if ( ! ( isset( $GLOBALS['wp_scripts'] ) && isset( $GLOBALS['wp_scripts']->registered ) && isset( $GLOBALS['wp_scripts']->registered['ultp-script'] ) ) ) {
2265 - wp_enqueue_style( 'ultp-style', ULTP_URL . 'assets/css/style.min.css', array(), ULTP_VER );
2266 - wp_enqueue_script( 'ultp-script', ULTP_URL . 'assets/js/ultp.min.js', array( 'jquery', 'wp-api-fetch' ), ULTP_VER, true );
2267 - wp_localize_script(
2268 - 'ultp-script',
2269 - 'ultp_data_frontend',
2270 - array(
2271 - 'url' => ULTP_URL,
2272 - 'active' => ultimate_post()->is_lc_active(),
2273 - 'ultpSavedDLMode' => ultimate_post()->get_dl_mode(),
2274 - 'ajax' => admin_url( 'admin-ajax.php' ),
2275 - 'security' => wp_create_nonce( 'ultp-nonce' ),
2276 - 'home_url' => home_url(),
2277 - 'dark_logo' => get_option( 'ultp_site_dark_logo', false ),
2278 - )
2279 - );
2280 - }
2281 - }
2282 -
2283 - /**
2284 - * Get Dark Light Mode
2285 - *
2286 - * @since 4.0.0
2287 - * @return STRING | Dark Light Mode .
2288 - */
2289 - public function get_dl_mode() {
2290 - $data = get_option( 'postx_global', array() );
2291 - $mode = 'ultplight';
2292 - if ( ! empty( $data ) ) {
2293 - $mode = isset( $data['enableDark'] ) && $data['enableDark'] ? 'ultpdark' : 'ultplight';
2294 - }
2295 - return $mode;
2296 - }
2297 -
2298 - /**
2299 - * Get Page Post Id ( Kadence element )
2300 - *
2301 - * @since v.2.8.9
2302 - * @param STRING|INT $blockId Block ID to search for.
2303 - * @return NULL
2304 - */
2305 - public function get_page_post_id( $blockId ) {
2306 - global $wpdb;
2307 - $post_meta = $wpdb->get_row( $wpdb->prepare( 'SELECT post_id FROM ' . $wpdb->prefix . 'postmeta WHERE meta_key=%s AND meta_value LIKE %s', '_ultp_css', '%.ultp-block-' . $blockId . '%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
2308 - // For FSE theme
2309 - if ( ! $post_meta ) {
2310 - if ( wp_is_block_theme() ) {
2311 - $template = $wpdb->get_row( $wpdb->prepare( 'SELECT ID FROM ' . $wpdb->prefix . 'posts WHERE post_content LIKE %s', '%"blockId":"' . $blockId . '"%' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
2312 - if ( isset( $template->ID ) ) {
2313 - return $template->ID;
2314 - }
2315 - }
2316 - }
2317 - if ( $post_meta && isset( $post_meta->post_id ) ) {
2318 - return $post_meta->post_id;
2319 - }
2320 - return ultimate_post()->get_ID();
2321 - }
2322 -
2323 -
2324 - /**
2325 - * Get no Result found html
2326 - *
2327 - * @since v.2.9.0
2328 - * @param STRING $text No result found text.
2329 - * @return STRING | Taxonomy Lists as array
2330 - */
2331 - public function get_no_result_found_html( $text ) {
2332 - return $text ? '<div class="ultp-not-found-message" role="alert">' . wp_kses( $text, ultimate_post()->ultp_allowed_html_tags() ) . '</div>' : '';
2333 - }
2334 -
2335 - /**
2336 - * Get all Saved Templates Lists
2337 - *
2338 - * @since v.2.9.9
2339 - * @param STRING $post_type Post type to retrieve.
2340 - * @param STRING $empty Empty value for the select field.
2341 - * @return STRING | Taxonomy Lists as array
2342 - */
2343 - public function get_all_lists( $post_type = 'post', $empty = '' ) {
2344 - $args = array(
2345 - 'post_type' => $post_type,
2346 - 'post_status' => 'publish',
2347 - 'posts_per_page' => -1,
2348 - );
2349 - $loop = new \WP_Query( $args );
2350 - $data[ $empty ? $empty : '' ] = __( '- Select Template -', 'ultimate-post' );
2351 - if ( $loop->have_posts() ) {
2352 - foreach ( $loop->posts as $post ) {
2353 - $data[ $post->ID ] = $post->post_title;
2354 - }
2355 - }
2356 - wp_reset_postdata();
2357 - return $data;
2358 - }
2359 -
2360 - /**
2361 - * Get ID from the Youtube URL
2362 - *
2363 - * @since v.3.1.7
2364 - * @param STRING $url The Youtube URL .
2365 - * @return STRING | Taxonomy Lists as array
2366 - */
2367 - public function get_youtube_id( $url = '' ) {
2368 - if ( strpos( $url, 'youtu' ) !== false ) {
2369 - $reg = '/youtu(?:.*\/v\/|.*v\=|\.be\/)([A-Za-z0-9_\-]{11})/m';
2370 - preg_match( $reg, $url, $matches );
2371 - if ( isset( $matches[1] ) ) {
2372 - return $matches[1];
2373 - }
2374 - }
2375 - return false;
2376 - }
2377 -
2378 - /**
2379 - * Get Option Value bypassing cache
2380 - * Inspired By WordPress Core get_option
2381 - *
2382 - * @since v.3.1.6
2383 - * @param STRING $option Option Name.
2384 - * @param BOOLEAN $default_value option default value.
2385 - * @return mixed
2386 - */
2387 - public function get_option_without_cache( $option, $default_value = false ) {
2388 - global $wpdb;
2389 -
2390 - if ( is_scalar( $option ) ) {
2391 - $option = trim( $option );
2392 - }
2393 -
2394 - if ( empty( $option ) ) {
2395 - return false;
2396 - }
2397 -
2398 - $value = $default_value;
2399 -
2400 - $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", $option ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
2401 -
2402 - if ( is_object( $row ) ) {
2403 - $value = $row->option_value;
2404 - } else {
2405 - return apply_filters( "ultp_default_option_{$option}", $default_value, $option );
2406 - }
2407 -
2408 - return apply_filters( "ultp_option_{$option}", maybe_unserialize( $value ), $option );
2409 - }
2410 -
2411 - /**
2412 - * Get Transient Value bypassing cache
2413 - * Inspired By WordPress Core get_transient
2414 - *
2415 - * @since v.3.1.6
2416 - * @param STRING $transient Transient Name.
2417 - * @return MIXED
2418 - */
2419 - public function get_transient_without_cache( $transient ) {
2420 - $transient_option = '_transient_' . $transient;
2421 - $transient_timeout = '_transient_timeout_' . $transient;
2422 - $timeout = $this->get_option_without_cache( $transient_timeout );
2423 -
2424 - if ( false !== $timeout && $timeout < time() ) {
2425 - delete_option( $transient_option );
2426 - delete_option( $transient_timeout );
2427 - $value = false;
2428 - }
2429 -
2430 - if ( ! isset( $value ) ) {
2431 - $value = $this->get_option_without_cache( $transient_option );
2432 - }
2433 -
2434 - return apply_filters( "ultp_transient_{$transient}", $value, $transient );
2435 - }
2436 -
2437 - /**
2438 - * Set transient without adding to the cache
2439 - * Inspired By WordPress Core set_transient
2440 - *
2441 - * @since v.3.1.6
2442 - * @param STRING $transient Transient Name.
2443 - * @param MIXED $value Transient Value.
2444 - * @param INTEGER $expiration Time until expiration in seconds.
2445 - * @return BOOL
2446 - */
2447 - public function set_transient_without_cache( $transient, $value, $expiration = 0 ) {
2448 - $expiration = (int) $expiration;
2449 -
2450 - $transient_timeout = '_transient_timeout_' . $transient;
2451 - $transient_option = '_transient_' . $transient;
2452 -
2453 - $result = false;
2454 -
2455 - if ( false === $this->get_option_without_cache( $transient_option ) ) {
2456 - $autoload = 'yes';
2457 - if ( $expiration ) {
2458 - $autoload = 'no';
2459 - $this->add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
2460 - }
2461 - $result = $this->add_option_without_cache( $transient_option, $value, $autoload );
2462 - } else {
2463 - /*
2464 - * If expiration is requested, but the transient has no timeout option,
2465 - * delete, then re-create transient rather than update.
2466 - */
2467 - $update = true;
2468 -
2469 - if ( $expiration ) {
2470 - if ( false === $this->get_option_without_cache( $transient_timeout ) ) {
2471 - delete_option( $transient_option );
2472 - $this->add_option_without_cache( $transient_timeout, time() + $expiration, 'no' );
2473 - $result = $this->add_option_without_cache( $transient_option, $value, 'no' );
2474 - $update = false;
2475 - } else {
2476 - update_option( $transient_timeout, time() + $expiration );
2477 - }
2478 - }
2479 -
2480 - if ( $update ) {
2481 - $result = update_option( $transient_option, $value );
2482 - }
2483 - }
2484 -
2485 - return $result;
2486 - }
2487 -
2488 - /**
2489 - * Add option without adding to the cache
2490 - * Inspired By WordPress Core set_transient
2491 - *
2492 - * @since v.3.1.6
2493 - * @param STRING $option option name.
2494 - * @param STRING $value option value.
2495 - * @param STRING $autoload whether to load WordPress startup.
2496 - * @return BOOL
2497 - */
2498 - public function add_option_without_cache( $option, $value = '', $autoload = 'yes' ) {
2499 - global $wpdb;
2500 -
2501 - if ( is_scalar( $option ) ) {
2502 - $option = trim( $option );
2503 - }
2504 -
2505 - if ( empty( $option ) ) {
2506 - return false;
2507 - }
2508 -
2509 - wp_protect_special_option( $option );
2510 -
2511 - if ( is_object( $value ) ) {
2512 - $value = clone $value;
2513 - }
2514 -
2515 - $value = sanitize_option( $option, $value );
2516 -
2517 - /*
2518 - * Make sure the option doesn't already exist.
2519 - */
2520 -
2521 - if ( apply_filters( "ultp_default_option_{$option}", false, $option, false ) !== $this->get_option_without_cache( $option ) ) {
2522 - return false;
2523 - }
2524 -
2525 - $serialized_value = maybe_serialize( $value );
2526 - $autoload = ( 'no' === $autoload || false === $autoload ) ? 'no' : 'yes';
2527 -
2528 - $result = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE `option_name` = VALUES(`option_name`), `option_value` = VALUES(`option_value`), `autoload` = VALUES(`autoload`)", $option, $serialized_value, $autoload ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
2529 - if ( ! $result ) {
2530 - return false;
2531 - }
2532 -
2533 - return true;
2534 - }
2535 -
2536 - /**
2537 - * Permission_check_for_restapi
2538 - *
2539 - * @since v.3.2.4
2540 - * @param STRING/Bool $post_id .
2541 - * @param STRING $cap STRING .
2542 - * @return BOOL
2543 - */
2544 - public function permission_check_for_restapi( $post_id = false, $cap = '' ) {
2545 - $cap = $cap ? $cap : 'edit_others_posts';
2546 - $is_passed = false;
2547 - if ( $post_id ) {
2548 - $post_author = (int) get_post_field( 'post_author', $post_id );
2549 - $is_passed = (int) get_current_user_id() === $post_author;
2550 - }
2551 - return $is_passed || current_user_can( $cap );
2552 - }
2553 -
2554 - /**
2555 - * Sanitize params
2556 - *
2557 - * @param MIXED $params Parameters to sanitize.
2558 - * @return array|bool|mixed|string
2559 - * @since v.4.0.0
2560 - */
2561 - public function ultp_rest_sanitize_params( $params ) {
2562 - if ( is_array( $params ) ) {
2563 - return array_map( array( $this, 'ultp_rest_sanitize_params' ), $params );
2564 - } elseif ( is_bool( $params ) ) {
2565 - return rest_sanitize_boolean( $params );
2566 - } elseif ( is_object( $params ) ) {
2567 - return $params;
2568 - } else {
2569 - return sanitize_text_field( $params );
2570 - }
2571 - }
2572 -
2573 - /**
2574 - * Get Adv Filter Data Attributes
2575 - *
2576 - * @param ARRAY|NULL $attr .
2577 - * @param ARRAY|NULL $filter_attributes .
2578 - * @return string
2579 - * @since v.3.2.5
2580 - */
2581 - public function get_adv_data_attrs( $attr, $filter_attributes = null ) {
2582 - // Adv Filter Integration.
2583 - $adv_filter_dataset = array();
2584 -
2585 - if ( $filter_attributes ) {
2586 - $adv_filter_dataset[] = 'data-filter-value="' . htmlspecialchars( $filter_attributes['queryTaxValue'] ) . '"';
2587 - $adv_filter_dataset[] = 'data-filter-type="' . htmlspecialchars( $filter_attributes['queryTax'] ) . '"';
2588 -
2589 - $is_adv = isset( $filter_attributes['isAdv'] ) ? $filter_attributes['isAdv'] : 0;
2590 - $adv_filter_dataset[] = 'data-filter-is-adv="' . $is_adv . '"';
2591 -
2592 - if ( $is_adv ) {
2593 - if ( isset( $filter_attributes['queryAuthor'] ) ) {
2594 - $adv_filter_dataset[] = "data-filter-author='" . $filter_attributes['queryAuthor'] . "'";
2595 - }
2596 -
2597 - if ( isset( $filter_attributes['queryOrder'] ) ) {
2598 - $adv_filter_dataset[] = "data-filter-order='" . $filter_attributes['queryOrder'] . "'";
2599 - }
2600 -
2601 - if ( isset( $filter_attributes['queryOrderBy'] ) ) {
2602 - $adv_filter_dataset[] = "data-filter-orderby='" . $filter_attributes['queryOrderBy'] . "'";
2603 - }
2604 -
2605 - if ( isset( $filter_attributes['search'] ) ) {
2606 - $adv_filter_dataset[] = 'data-filter-search="' . $filter_attributes['search'] . '"';
2607 - }
2608 -
2609 - if ( isset( $filter_attributes['queryQuick'] ) && $filter_attributes['queryQuick'] ) {
2610 - $adv_filter_dataset[] = 'data-filter-adv-sort="' . $filter_attributes['queryQuick'] . '"';
2611 - }
2612 - }
2613 - }
2614 -
2615 - if ( $attr && isset( $attr['advFilterEnable'] ) && $attr['advFilterEnable'] ) {
2616 - $adv_filter_dataset[] = 'data-filter-is-adv="1"';
2617 - $adv_filter_dataset[] = 'data-filter-type="multiTaxonomy"';
2618 -
2619 - $data_filter_value = isset( $attr['filterValue'] ) && $attr['filterValue'] ? $attr['filterValue'] : '[]';
2620 - $adv_filter_dataset[] = 'data-filter-value="' . htmlspecialchars( $data_filter_value ) . '"';
2621 -
2622 - $data_author = isset( $attr['queryAuthor'] ) && $attr['queryAuthor'] ? $attr['queryAuthor'] : '[]';
2623 - $adv_filter_dataset[] = 'data-filter-author="' . $data_author . '"';
2624 -
2625 - $data_order = isset( $attr['queryOrder'] ) && $attr['queryOrder'] ? $attr['queryOrder'] : 'DESC';
2626 - $adv_filter_dataset[] = 'data-filter-order="' . $data_order . '"';
2627 -
2628 - $data_orderby = isset( $attr['queryOrderBy'] ) && $attr['queryOrderBy'] ? $attr['queryOrderBy'] : 'date';
2629 - $adv_filter_dataset[] = 'data-filter-orderby="' . $data_orderby . '"';
2630 -
2631 - $adv_filter_dataset[] = 'data-filter-search="' . ( isset( $attr['querySearch'] ) ? $attr['querySearch'] : '' ) . '"';
2632 -
2633 - $adv_filter_dataset[] = 'data-filter-adv-sort="' . ( isset( $attr['queryQuick'] ) ? $attr['queryQuick'] : '' ) . '"';
2634 - }
2635 -
2636 - $adv_filter_dataset = implode( ' ', $adv_filter_dataset );
2637 - return $adv_filter_dataset;
2638 - }
2639 -
2640 - /**
2641 - * Custom Text kses
2642 - *
2643 - * @since v.4.0.2
2644 - * @param MIXED $extras .
2645 - * @return ARRAY|BOOL|MIXED|STRING
2646 - */
2647 - public function ultp_allowed_html_tags( $extras = array() ) {
2648 - $allowed = array(
2649 - 'a' => array(
2650 - 'href' => true,
2651 - 'title' => true,
2652 - ),
2653 - 'abbr' => array(
2654 - 'title' => true,
2655 - ),
2656 - 'b' => array(),
2657 - 'br' => array(),
2658 - 'blockquote' => array(
2659 - 'cite' => true,
2660 - ),
2661 - 'em' => array(),
2662 - 'i' => array(),
2663 - 'q' => array(
2664 - 'cite' => true,
2665 - ),
2666 - 'strong' => array(
2667 - 'class' => true,
2668 - 'style' => true,
2669 - ),
2670 - 'mark' => array(
2671 - 'class' => true,
2672 - 'style' => true,
2673 - ),
2674 - );
2675 -
2676 - return array_merge( $allowed, $extras );
2677 - }
2678 -
2679 - /**
2680 - * Allowed Block Tags
2681 - *
2682 - * @since v.4.0.2
2683 - * @param STRING $search Optional. Tag name to check.
2684 - * @return ARRAY|BOOL Returns array of allowed tags or bool if $search is provided.
2685 - */
2686 - public function ultp_allowed_block_tags( $search = '' ) {
2687 - $array_lists = array( 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'span', 'p', 'div', 'section', 'article' );
2688 - return $search ? in_array( $search, $array_lists ) : $array_lists;
2689 - }
2690 -
2691 - /**
2692 - * Formats datasets for html
2693 - *
2694 - * @since v.4.0.2
2695 - *
2696 - * @param ARRAY $datasets .
2697 - * @return STRING
2698 - */
2699 - public function get_formatted_datasets( &$datasets ) {
2700 - $res = '';
2701 - foreach ( $datasets as $key => $value ) {
2702 - $res .= ' data-' . $key . '="' . $value . '" ';
2703 - }
2704 - return $res;
2705 - }
2706 -
2707 - /**
2708 - * Sanitizes attributes after running necessary checks
2709 - *
2710 - * @since v.4.1.0
2711 - *
2712 - * @param ARRAY $attr The attributes array to sanitize.
2713 - * @param STRING $key The key to check in the attributes array.
2714 - * @param callable|null $sanitize_callback Callback function to sanitize the value.
2715 - * @param MIXED $def_value Default value to return if key is not set.
2716 - * @return MIXED Sanitized value or default value.
2717 - */
2718 - public function sanitize_attr( &$attr, $key, $sanitize_callback = null, $def_value = '' ) {
2719 - return isset( $attr[ $key ] ) && $attr[ $key ] ?
2720 - (
2721 - $sanitize_callback ?
2722 - $sanitize_callback( $attr[ $key ] ) :
2723 - $attr[ $key ]
2724 - )
2725 - : $def_value;
2726 - }
2727 -
2728 - /**
2729 - * Checks if dynamic content is active
2730 - *
2731 - * @since v.4.1.1
2732 - *
2733 - * @param ARRAY $attr The attributes to check for dynamic content.
2734 - * @return BOOLEAN
2735 - */
2736 - public function is_dc_active( &$attr ) {
2737 - if ( class_exists( '\ULTP\DCService' ) ) {
2738 - return \ULTP\DCService::is_dc_active( $attr );
2739 - }
2740 - return false;
2741 - }
2742 -
2743 -
2744 - /**
2745 - * Checks all the taxonomy of a post type for a given slug. Returns the taxonomy
2746 - * if it exists.
2747 - *
2748 - * @since v.4.1.16
2749 - *
2750 - * @param STRING $post_type The post type.
2751 - * @param STRING $slug The slug.
2752 - * @return STRING|NULL The taxonomy name or null if not found.
2753 - */
2754 - public function get_taxonomy_by_term_slug( $post_type, $slug ) {
2755 - $taxonomies = get_object_taxonomies( $post_type );
2756 - foreach ( $taxonomies as $taxonomy ) {
2757 - $res = get_term_by( 'slug', $slug, $taxonomy );
2758 -
2759 - if ( ! empty( $res ) ) {
2760 - return $taxonomy;
2761 - }
2762 - }
2763 -
2764 - return null;
2765 - }
2766 - /**
2767 - * Resolve Icon Alias
2768 - *
2769 - * @since v.4.0.0
2770 - * @param STRING $icon_name The icon name or alias to resolve.
2771 - * @return STRING|FALSE Returns the resolved icon name or false if no alias found.
2772 - */
2773 - public function svg_icon_compatibility( $icon_name = '' ) {
2774 - if ( empty( $icon_name ) ) {
2775 - return 'warning_triangle_solid';
2776 - }
2777 - // Get icon aliases mapping
2778 - $icon_aliases = array(
2779 - // Arrow aliases
2780 - 'angle_bottom_left_line' => 'arrow_down_bottom_left_solid',
2781 - 'angle_bottom_right_line' => 'arrow_down_bottom_right_solid',
2782 - 'angle_top_left_line' => 'arrow_up_top_left_solid',
2783 - 'angle_top_right_line' => 'arrow_up_top_right_solid',
2784 - 'rightFillAngle' => 'right_triangle_angle_play_arrow_forward_solid',
2785 - 'leftAngle2' => 'arrow_left_previous_backward_chevron_line',
2786 - 'rightAngle2' => 'arrow_right_next_forward_chevron_line',
2787 - 'collapse_bottom_line' => 'arrow_down_dropdown_maximize_chevron_line',
2788 - 'arrowUp2' => 'arrow_up_dropdown_minimize_chevron_line',
2789 - 'longArrowUp2' => 'long_arrow_up_top_increase_solid',
2790 -
2791 - // Circle arrow aliases
2792 - 'arrow_left_circle_line' => 'arrow_left_backward_circle_line',
2793 - 'arrow_bottom_circle_line' => 'arrow_down_bottom_downward_circle_line',
2794 - 'arrow_right_circle_line' => 'arrow_right_forward_circle_line',
2795 - 'arrow_top_circle_line' => 'arrow_up_top_upward_circle_line',
2796 -
2797 - // Close/Cross aliases
2798 - 'close_circle_line' => 'cross_close_x_minimize_circle_line',
2799 - 'close_line' => 'cross_x_close_minimize_line',
2800 -
2801 - // Direction aliases
2802 - 'arrow_down_line' => 'arrow_down_bottom_downward_line',
2803 - 'leftArrowLg' => 'arrow_left_backward_line',
2804 - 'rightArrowLg' => 'arrow_left_forward_line',
2805 - 'arrow_up_line' => 'long_arrow_up_top_increase_line',
2806 -
2807 - // Solid direction aliases
2808 - 'down_solid' => 'arrow_down_bottom_downward_circle_solid',
2809 - 'right_solid' => 'arrow_right_forward_circle_solid',
2810 - 'left_solid' => 'arrow_left_backward_circle_solid',
2811 - 'up_solid' => 'arrow_up_top_upward_circle_solid',
2812 -
2813 - // Move aliases
2814 - 'bottom_right_line' => 'arrow_move_up_right_line',
2815 - 'bottom_left_line' => 'arrow_move_up_left_line',
2816 - 'top_left_angle_line' => 'arrow_move_down_left_line',
2817 - 'top_right_line' => 'arrow_move_down_right_line',
2818 -
2819 - // Utility aliases
2820 - 'at_line' => 'at_a_mail_line',
2821 - 'refresh' => 'refresh_reset_cycle_loop_infinity_line',
2822 - 'cart_line' => 'shopping_cart_line',
2823 - 'cart_solid' => 'add_plus_shopping_cart_solid',
2824 - 'cog_line' => 'settings_tool_function_line',
2825 - 'cog_solid' => 'settings_tool_function_solid',
2826 - 'clock' => 'clock_reading_time_1_line',
2827 - 'book' => 'book_line',
2828 - 'download_line' => 'download_1_line',
2829 - 'download_solid' => 'download_1_solid',
2830 - 'downlod_bottom_solid' => 'download_1_solid',
2831 -
2832 - // Visibility aliases
2833 - 'eye' => 'view_count_show_visible_eye_open_2_line',
2834 - 'hidden_line' => 'hidden_hide_invisible_line',
2835 -
2836 - // Location aliases
2837 - 'home_line' => 'home_house_line',
2838 - 'home_solid' => 'home_house_solid',
2839 - 'location_line' => 'location_gps_map_line',
2840 - 'location_solid' => 'location_gps_map_solid',
2841 -
2842 - // Emotion aliases
2843 - 'love_line' => 'heart_love_wishlist_favourite_line',
2844 - 'love_solid' => 'heart_love_wishlist_favourite_solid',
2845 -
2846 - // Media aliases
2847 - 'play_line' => 'play_media_video_circle_line',
2848 - 'videoplay' => 'right_triangle_angle_play_arrow_forward_solid',
2849 - 'left_angle_solid' => 'left_triangle_angle_arrow_backward_solid',
2850 -
2851 - // Shape aliases
2852 - 'caretArrow' => 'caret_up_top_triangle_angle_arrow_upward_solid',
2853 - 'rectangle_solid' => 'square_rounded_solid',
2854 - 'triangle_solid' => 'triangle_shape_solid',
2855 -
2856 - // Status aliases
2857 - 'restriction_line' => 'restriction_no_stop_line',
2858 - 'right_circle_line' => 'correct_save_check_circle_line',
2859 - 'save_line' => 'correct_save_check_line',
2860 - 'search_line' => 'search_magnify_line',
2861 - 'search_solid' => 'search_magnify_solid',
2862 -
2863 - // Warning aliases
2864 - 'notice_circle_solid' => 'warning_circle_solid',
2865 - 'notice_solid' => 'warning_triangle_solid',
2866 - 'warning_circle_line' => 'warning_circle_line',
2867 - 'warning_triangle_line' => 'warning_triangle_line',
2868 -
2869 - // Category aliases
2870 - 'cat1' => 'category_file_documents_1_solid',
2871 - 'cat2' => 'category_book_line',
2872 - 'cat3' => 'category_file_documents_2_line',
2873 - 'cat4' => 'category_file_documents_3_line',
2874 - 'cat5' => 'category_file_documents_3_solid',
2875 - 'cat6' => 'category_file_documents_4_line',
2876 - 'cat7' => 'category_book_line',
2877 -
2878 - // Comment aliases
2879 - 'commentCount1' => 'messege_comment_1_line',
2880 - 'commentCount2' => 'messege_comment_3_solid',
2881 - 'commentCount3' => 'messege_comment_3_line',
2882 - 'commentCount4' => 'messege_comment_6_line',
2883 - 'commentCount5' => 'messege_comment_7_line',
2884 - 'commentCount6' => 'messege_comment_8_line',
2885 - 'comment' => 'messege_comment_4_line',
2886 -
2887 - // Date aliases
2888 - 'date1' => 'calendar_date_4_line',
2889 - 'date2' => 'calendar_date_1_solid',
2890 - 'date3' => 'calendar_date_2_line',
2891 - 'date4' => 'calendar_date_4_solid',
2892 - 'date5' => 'calendar_date_3_line',
2893 - 'calendar' => 'calendar_date_3_line',
2894 -
2895 - // Reading time aliases
2896 - 'readingTime1' => 'clock_reading_time_3_line',
2897 - 'readingTime2' => 'clock_reading_time_2_line',
2898 - 'readingTime3' => 'book_reading_time_line',
2899 - 'readingTime4' => 'clock_reading_time_1_line',
2900 - 'readingTime5' => 'hourglass_timer_time_line',
2901 -
2902 - // Tag aliases
2903 - 'tag1' => 'tag_bookmark_save_favourite_mark_discount_sale_line',
2904 - 'tag2' => 'price_tag_label_category_sale_discount_solid',
2905 - 'tag3' => 'price_tag_label_category_sale_discount_line',
2906 - 'tag4' => 'price_tag_offer_sale_coupon_solid',
2907 - 'tag5' => 'price_tag_label_category_sale_discount_line',
2908 - 'tag6' => 'growth_increase_up_solid',
2909 -
2910 - // View count aliases
2911 - 'viewCount1' => 'view_count_show_visible_eye_open_1_line',
2912 - 'viewCount2' => 'view_count_show_visible_eye_open_2_line',
2913 - 'viewCount3' => 'view_count_show_visible_eye_open_3_line',
2914 - 'viewCount4' => 'view_count_show_visible_eye_open_4_solid',
2915 - 'viewCount5' => 'view_count_show_visible_eye_open_5_solid',
2916 - 'viewCount6' => 'view_count_show_visible_eye_open_5_solid',
2917 -
2918 - // Author aliases
2919 - 'author1' => 'author_user_human_1_line',
2920 - 'author2' => 'author_user_human_4_line',
2921 - 'author3' => 'author_user_human_4_solid',
2922 - 'author4' => 'author_user_human_4_line',
2923 - 'author5' => 'author_user_human_3_solid',
2924 - 'author6' => 'author_user_human_6_line',
2925 - 'user' => 'author_user_human_3_line',
2926 -
2927 - // Device aliases
2928 - 'desktop' => 'desktop_monitor_computer_line',
2929 - 'laptop' => 'laptop_computer_line',
2930 - 'tablet' => 'tablet_ipad_pad_line',
2931 - 'mobile' => 'mobile_smartphone_phone_line',
2932 -
2933 - // Emoji aliases
2934 - 'angry_line' => 'angry_emoji_line',
2935 - 'angry_solid' => 'angry_emoji_solid',
2936 - 'confused_line' => 'confused_emoji_line',
2937 - 'confused_solid' => 'confused_emoji_solid',
2938 - 'happy_line' => 'happy_emoji_line',
2939 - 'happy_solid' => 'happy_emoji_solid',
2940 - 'smile_line' => 'smile_emoji_line',
2941 - 'smile_solid' => 'smile_emoji_solid',
2942 -
2943 - // Social aliases
2944 - 'share_line' => 'social_community_line',
2945 - 'share' => 'share_social_solid',
2946 - 'apple_solid' => 'apple_logo_icon_solid',
2947 - 'android_solid' => 'android_logo_icon_solid',
2948 - 'google_solid' => 'google_logo_icon_solid',
2949 - 'messenger' => 'messenger_logo_icon_solid',
2950 - 'microsoft_solid' => 'microsoft_logo_icon_solid',
2951 - 'mail' => 'mail_email_messege_solid',
2952 - 'facebook' => 'facebook_logo_icon_solid',
2953 - 'twitter' => 'twitter_x_logo_icon_line',
2954 - 'link' => 'link_chains_line',
2955 -
2956 - // Misc aliases
2957 - 'media_document' => 'media_document',
2958 - 'arrowDown2' => 'arrow_down_dropdown_maximize_chevron_line',
2959 - 'setting' => 'settings_tool_function_solid',
2960 - 'upload_solid' => 'upload_1_solid',
2961 -
2962 - // Empty aliases for missing icons (return empty string)
2963 - 'correct_solid' => 'correct_save_check_circle_line',
2964 - 'dot_solid' => 'dot_circle_solid',
2965 - 'right_circle_solid' => 'correct_save_check_circle_solid',
2966 - 'full_screen' => 'full_screen_corners_out_solid',
2967 - 'zoom_in' => 'zoom_in_magnifying_glass_plus_line',
2968 - 'zoom_out' => 'zoom_out_magnifying_glass_minus_line',
2969 - 'gallery_indicator' => 'gallery_indicator_image_solid',
2970 - 'ascending' => 'sort_ascending_order_solid',
2971 - 'descending' => 'sort_descending_order_line',
2972 - 'unlink' => 'unlink_link_break_line',
2973 - 'rocket' => 'rocket_fly_boost_launch_pro_line',
2974 - 'unlock' => 'unlocked_open_security_solid',
2975 - 'connect' => 'plugin_connect_socket_integration_solid',
2976 - 'leftAngle' => 'arrow_left_previous_backward_chevron_line',
2977 - 'rightAngle' => 'right_triangle_angle_play_arrow_forward_line',
2978 - 'plus2' => '',
2979 - 'hamicon_1' => 'left_align_1_line',
2980 - // extra in assets\img\iconpack folder
2981 - 'hamicon_2' => 'hemicon_2_line',
2982 - 'hamicon_3' => 'hemicon_3_line',
2983 - 'hamicon_4' => 'hamicon_5_line',
2984 - 'hamicon_5' => 'hamicon_4_sloid',
2985 - 'hamicon_6' => 'hamicon_6_line',
2986 - 'instagram_solid' => 'instagram_logo_icon_solid',
2987 - 'linkedin' => 'linkedin_logo_icon_solid',
2988 - 'pause_solid' => 'pause_solid',
2989 - 'pinterest' => 'pinterest_logo_icon_solid',
2990 - 'reddit' => 'reddit_logo_icon_solid',
2991 - 'skype' => 'skype_logo_icon_solid',
2992 - 'tiktok_lite_solid' => 'tiktok_logo_icon_line',
2993 - 'tiktok_solid' => 'tiktok_logo_icon_circle_solid',
2994 - 'whatsapp' => 'whatsapp_logo_icon_solid',
2995 - 'wordpress_lite_solid' => 'wordpress_logo_icon_solid',
2996 - 'wordpress_solid' => 'wordpress_logo_icon_2_solid',
2997 - 'wrong_solid' => 'cross_close_x_minimize_circle_solid',
2998 - 'youtube_solid' => 'youtube_logo_icon_solid',
2999 - 'five_star_line' => 'star_rating_line',
3000 - 'rightAngleBold' => 'arrow_right_next_forward_chevron_line',
3001 - 'leftAngleBold' => 'arrow_left_previous_backward_chevron_line',
3002 - 'plus' => 'plus',
3003 - 'reset_left_line' => 'refresh_reset_cycle_loop_infinity_line',
3004 - );
3005 - // Return resolved alias or false if not found
3006 - return isset( $icon_aliases[ $icon_name ] ) ? $icon_aliases[ $icon_name ] : $icon_name;
3007 - }
1244 + public function get_excerpt($post_id = 0, $showSeoMeta = 0, $showFullExcerpt = 0, $excerptLimit = 55) {
1245 + $html = '';
1246 + if ($showSeoMeta) {
1247 + $str = '';
1248 + if( function_exists('ultimate_post_pro') ) {
1249 + if (ultimate_post()->get_setting('ultp_yoast') == 'true') {
1250 + $str = method_exists( ultimate_post_pro(), 'get_yoast_meta' ) ? ultimate_post_pro()->get_yoast_meta($post_id) : '';
1251 + } else if (ultimate_post()->get_setting('ultp_rankmath') == 'true') {
1252 + $str = method_exists( ultimate_post_pro(), 'get_rankmath_meta' ) ? ultimate_post_pro()->get_rankmath_meta($post_id) : '';
1253 + } else if (ultimate_post()->get_setting('ultp_aioseo') == 'true') {
1254 + $str = method_exists( ultimate_post_pro(), 'get_aioseo_meta' ) ? ultimate_post_pro()->get_aioseo_meta($post_id) : '';
1255 + } else if (ultimate_post()->get_setting('ultp_seopress') == 'true') {
1256 + $str = method_exists( ultimate_post_pro(), 'get_seopress_meta' ) ? ultimate_post_pro()->get_seopress_meta($post_id) : '';
1257 + } else if (ultimate_post()->get_setting('ultp_squirrly') == 'true') {
1258 + $str = method_exists( ultimate_post_pro(), 'get_squirrly_meta' ) ? ultimate_post_pro()->get_squirrly_meta($post_id) : '';
1259 + }
1260 + }
1261 + $html = $str ? $str : ultimate_post()->excerpt($post_id, $excerptLimit);
1262 + } else {
1263 + if ( $showFullExcerpt == 0 ) {
1264 + $html = ultimate_post()->excerpt($post_id, $excerptLimit);
1265 + } else {
1266 + $html = get_the_excerpt();
1267 + }
1268 + }
1269 + return $html;
1270 + }
1271 +
3008 1272 }