PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 4.2.0
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v4.2.0
7.9.3 7.9.2 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.2.0 4.2.1 4.2.2 4.2.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 6.0.0 7.0.0 7.0.1 7.0.2 7.1.0 7.2.0 7.2.1 7.2.10 7.2.11 7.2.2 7.2.3 7.2.4 7.2.5 7.2.6 7.2.7 7.2.8 7.2.9 7.3.0 7.3.1 7.4.0 7.4.1 7.4.2 7.4.3 7.5.0 7.6.0 7.6.1 7.7.0 7.7.1 7.7.10 7.7.11 7.7.12 7.7.13 7.7.14 7.7.15 7.7.16 7.7.17 7.7.18 7.7.19 7.7.2 7.7.20 7.7.21 7.7.22 7.7.3 7.7.4 7.7.5 7.7.6 7.7.7 7.7.8 7.7.9 7.8.0 7.8.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1
the-post-grid / app / Widgets / elementor / base.php
the-post-grid / app / Widgets / elementor Last commit date
widgets 3 years ago base.php 3 years ago rtTPGElementorHelper.php 3 years ago rtTPGElementorQuery.php 3 years ago
base.php
934 lines
1 <?php
2 /**
3 * Base Abstract Class
4 *
5 * @package RT_TPG
6 */
7
8 use Elementor\Widget_Base;
9 use RT\ThePostGrid\Helpers\Fns;
10 use RT\ThePostGrid\Helpers\Options;
11
12 // Do not allow directly accessing this file.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit( 'This script cannot be accessed directly.' );
15 }
16
17 /**
18 * Base Abstract Class
19 */
20 abstract class Custom_Widget_Base extends Widget_Base {
21 public $tpg_name;
22 public $tpg_base;
23 public $tpg_category;
24 public $tpg_archive_category;
25 public $tpg_icon;
26 public $tpg_dir;
27 public $tpg_pro_dir;
28 public $is_post_layout;
29 public $pro_label;
30 public $get_pro_message;
31 public $prefix;
32 public $last_post_id;
33
34 public function __construct( $data = [], $args = null ) {
35 $this->tpg_category = RT_THE_POST_GRID_PLUGIN_SLUG . '-elements'; // Category /@dev
36 $this->tpg_archive_category = 'tpg-elementor-builder-widgets';
37 $this->tpg_icon = 'eicon-gallery-grid tpg-grid-icon';
38 $this->tpg_dir = dirname( ( new ReflectionClass( $this ) )->getFileName() );
39 $this->tpg_pro_dir = null;
40 $this->pro_label = null;
41 $this->is_post_layout = null;
42 $this->get_pro_message = null;
43 $this->last_post_id = $this->get_last_post_id();
44
45 if ( ! rtTPG()->hasPro() ) {
46 $this->pro_label = __( '<span class="tpg-pro-label">Pro</span>', 'the-post-grid' );
47 $this->is_post_layout = ' the-post-grid-pro-needed';
48 $this->get_pro_message = 'Please <a target="_blank" href="' . esc_url( rtTpg()->proLink() ) . '">upgrade</a> to pro for more options';
49 }
50
51 parent::__construct( $data, $args );
52 }
53
54 public function get_pro_message( $message = 'more options.' ) {
55 if ( rtTPG()->hasPro() ) {
56 return;
57 }
58
59 return 'Please <a target="_blank" href="' . esc_url( rtTpg()->proLink() ) . '">upgrade</a> to pro for ' . esc_html( $message );
60 }
61
62 public function get_name() {
63 return $this->tpg_base;
64 }
65
66 public function get_title() {
67 return $this->tpg_name;
68 }
69
70 public function get_icon() {
71 return $this->tpg_icon;
72 }
73
74 public function get_categories() {
75 return [ $this->tpg_category ];
76 }
77
78
79 public function tpg_template( $data ) {
80 $layout = str_replace( '-2', '', $data['layout'] );
81 $template_name = '/the-post-grid/elementor/' . $layout . '.php';
82
83 if ( file_exists( STYLESHEETPATH . $template_name ) ) {
84 $file = STYLESHEETPATH . $template_name;
85 } elseif ( file_exists( TEMPLATEPATH . $template_name ) ) {
86 $file = TEMPLATEPATH . $template_name;
87 } else {
88 $file = RT_THE_POST_GRID_PLUGIN_PATH . '/templates/elementor/' . $layout . '.php';
89
90 if ( ! file_exists( $file ) ) {
91 if ( rtTPG()->hasPro() ) {
92 $file = RT_THE_POST_GRID_PRO_PLUGIN_PATH . '/templates/elementor/' . $layout . '.php';
93 } else {
94 $layout = substr( $layout, 0, - 1 );
95 $layout = strpos( $layout, '1' ) ? str_replace( '1', '', $layout ) : $layout;
96 $file = RT_THE_POST_GRID_PLUGIN_PATH . '/templates/elementor/' . $layout . '1.php';
97 }
98 }
99 }
100
101 ob_start();
102 include $file;
103 echo ob_get_clean();
104 }
105
106 public function tpg_template_path( $data ) {
107 $layout = str_replace( '-2', '', $data['layout'] );
108 $template_name = '/the-post-grid/elementor/' . $layout . '.php';
109 $path = RT_THE_POST_GRID_PLUGIN_PATH . '/templates/elementor/';
110
111 if ( file_exists( STYLESHEETPATH . $template_name ) ) {
112 $path = STYLESHEETPATH . '/the-post-grid/elementor/';
113 } elseif ( file_exists( TEMPLATEPATH . $template_name ) ) {
114 $path = TEMPLATEPATH . '/the-post-grid/elementor/';
115 } else {
116 $template_path = RT_THE_POST_GRID_PLUGIN_PATH . '/templates/elementor/' . $layout . '.php';
117
118 if ( ! file_exists( $template_path ) && rtTPG()->hasPro() ) {
119 $path = RT_THE_POST_GRID_PRO_PLUGIN_PATH . '/templates/elementor/';
120 }
121 }
122
123 return $path;
124 }
125
126
127 /**
128 *
129 * Get last post id
130 *
131 * @param string $post_type
132 * @param false $all_content
133 *
134 * @return int
135 */
136 public function get_last_post_id( $post_type = 'post' ): int {
137 if ( is_singular( $post_type ) ) {
138 return get_the_ID();
139 }
140
141 global $wpdb;
142 $cache_key = 'tpg_last_post_id';
143 $_post_id = get_transient( $cache_key );
144
145 if ( false === $_post_id || 'publish' !== get_post_status( $_post_id ) ) {
146 delete_transient( $cache_key );
147 $_post_id = $wpdb->get_var(
148 $wpdb->prepare( "SELECT MAX(ID) FROM {$wpdb->prefix}posts WHERE post_type = %s AND post_status = %s", $post_type, 'publish' )
149 );
150 set_transient( $cache_key, $_post_id, 12 * HOUR_IN_SECONDS );
151 }
152
153 return absint( $_post_id );
154 }
155
156
157 /**
158 * Get Last Category ID
159 *
160 * @return mixed
161 */
162 public function get_last_category_id() {
163 if ( is_archive() ) {
164 return;
165 }
166
167 $categories = get_terms(
168 [
169 'taxonomy' => 'category',
170 'hide_empty' => false,
171 'number' => 1,
172 ]
173 );
174
175 if ( ! empty( $categories ) && ! is_wp_error( $categories ) ) {
176 return $categories[0]->term_id;
177 }
178 }
179
180 // post category list.
181 public function tpg_category_list() {
182 $categories = get_categories( [ 'hide_empty' => false ] );
183 $lists = [];
184 foreach ( $categories as $category ) {
185 $lists[ $category->cat_ID ] = $category->name;
186 }
187
188 return $lists;
189 }
190
191 // post tags lists.
192 public function tpg_tag_list() {
193 $tags = get_tags( [ 'hide_empty' => false ] );
194 $tag_list = [];
195 foreach ( $tags as $tag ) {
196 $tag_list[ $tag->slug ] = $tag->name;
197 }
198
199 return $tag_list;
200 }
201
202 // Get Custom post category:.
203 protected function tpg_get_categories_by_slug( $cat ) {
204 $terms = get_terms(
205 [
206 'taxonomy' => $cat,
207 'hide_empty' => true,
208 ]
209 );
210 $options = [ '0' => esc_html__( 'All Categories', 'the-post-grid' ) ];
211
212 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
213 foreach ( $terms as $term ) {
214 $options[ $term->slug ] = $term->name;
215 }
216
217 return $options;
218 }
219 }
220
221 // Get Custom post category.
222 public function tpg_get_categories_by_id( $cat ) {
223 $terms = get_terms(
224 [
225 'taxonomy' => $cat,
226 'hide_empty' => true,
227 ]
228 );
229
230 $options = [];
231
232 if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
233 foreach ( $terms as $term ) {
234 $options[ $term->term_id ] = $term->name;
235 }
236
237 return $options;
238 }
239 }
240
241
242 public function get_all_post_type() {
243 $post_types = get_post_types( [], 'objects' );
244 $pt_list = [];
245
246 foreach ( $post_types as $type ) {
247 if ( isset( $type->rewrite->slug ) ) {
248 $pt_list[ $type->rewrite->slug ] = $type->rewrite->name;
249 }
250 }
251
252 return $pt_list;
253 }
254
255 public static function get_post_types() {
256 $post_types = get_post_types(
257 [
258 'public' => true,
259 'show_in_nav_menus' => true,
260 ],
261 'objects'
262 );
263 $post_types = wp_list_pluck( $post_types, 'label', 'name' );
264
265 return array_diff_key( $post_types, [ 'elementor_library', 'attachment' ] );
266 }
267
268 /**
269 * Get Excluded Taxonomy
270 *
271 * @return string[]
272 */
273 public static function get_excluded_taxonomy() {
274 return [
275 'post_format',
276 'nav_menu',
277 'link_category',
278 'wp_theme',
279 'elementor_library_type',
280 'elementor_library_type',
281 'elementor_library_category',
282 'product_visibility',
283 'product_shipping_class',
284 ];
285 }
286
287 /**
288 * Get Filter markup
289 *
290 * @param $data
291 *
292 * @return string
293 */
294 public function get_frontend_filter_markup( $data ) {
295 if ( ! rtTPG()->hasPro()
296 || ! ( $data['show_taxonomy_filter'] == 'show' || $data['show_author_filter'] == 'show' || $data['show_order_by'] == 'show'
297 || $data['show_sort_order'] == 'show'
298 || $data['show_search'] == 'show' )
299 ) {
300 return;
301 }
302
303 $html = null;
304 $wrapperContainer = $wrapperClass = $itemClass = $filter_btn_item_per_page = '';
305
306 if ( 'carousel' === $data['filter_btn_style'] ) {
307 $wrapperContainer = 'swiper';
308 $wrapperClass = 'swiper-wrapper';
309 $itemClass = 'swiper-slide';
310 $filter_btn_mobile = isset( $data['filter_btn_item_per_page_mobile'] ) ? $data['filter_btn_item_per_page_mobile'] : 'auto';
311 $filter_btn_tablet = isset( $data['filter_btn_item_per_page_tablet'] ) ? $data['filter_btn_item_per_page_tablet'] : 'auto';
312 $filter_btn_item_per_page = "data-per-page = '{$data['filter_btn_item_per_page']}' data-per-page-mobile = '{$filter_btn_mobile}' data-per-tablet = '{$filter_btn_tablet}'";
313 }
314
315 $html .= "<div class='rt-layout-filter-container rt-clear'><div class='rt-filter-wrap'>";
316
317 if ( 'show' == $data['show_author_filter'] || 'show' == $data['show_taxonomy_filter'] ) {
318 $html .= "<div class='filter-left-wrapper {$wrapperContainer}' {$filter_btn_item_per_page}>";
319 }
320
321 $selectedSubTermsForButton = null;
322
323 $filterType = $data['filter_type'];
324 $post_count = ( 'yes' == $data['filter_post_count'] ) ? true : false;
325
326 if ( 'show' == $data['show_taxonomy_filter'] ) {
327 $postCountClass = ( $post_count ? ' has-post-count' : null );
328 $allSelect = ' selected';
329 $isTermSelected = false;
330
331 $taxFilterOperator = $data['relation'];
332
333 $section_term_key = $data['post_type'] . '_filter_taxonomy';
334 $taxFilter = $data[ $section_term_key ];
335
336 $taxonomy_label = '';
337
338 if ( $taxFilter ) {
339 $taxonomy_details = get_taxonomy( $taxFilter );
340 $taxonomy_label = $taxonomy_details->label;
341 }
342
343 $default_term_key = $taxFilter . '_default_terms';
344 $default_term = $data[ $default_term_key ];
345
346 $allText = $data['tax_filter_all_text'] ? $data['tax_filter_all_text'] : esc_html__( 'All ', 'the-post-grid' ) . $taxonomy_label;
347
348 $_taxonomies = get_object_taxonomies( $data['post_type'], 'objects' );
349 $terms = [];
350
351 foreach ( $_taxonomies as $index => $object ) {
352 if ( $object->name != $taxFilter ) {
353 continue;
354 }
355
356 $setting_key = $object->name . '_ids';
357
358 if ( ! empty( $data[ $setting_key ] ) ) {
359 $terms = $data[ $setting_key ];
360 } else {
361 $terms = get_terms(
362 [
363 'taxonomy' => $taxFilter,
364 'fields' => 'ids',
365 ]
366 );
367 }
368 }
369 $taxFilterTerms = $terms;
370
371 if ( $default_term && $taxFilter ) {
372 $isTermSelected = true;
373 $allSelect = null;
374 }
375
376 if ( $filterType == 'dropdown' ) {
377 $html .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-dropdown-wrap parent-dropdown-wrap{$postCountClass}' data-taxonomy='{$taxFilter}' data-filter='taxonomy'>";
378 $termDefaultText = $allText;
379 $dataTerm = 'all';
380 $htmlButton = '';
381 $selectedSubTerms = null;
382 $pCount = 0;
383
384 if ( ! empty( $terms ) ) {
385 $i = 0;
386
387 foreach ( $terms as $term_id ) {
388 $term = get_term( $term_id, $taxFilter, ARRAY_A );
389 $id = $term['term_id'];
390 $pCount = $pCount + $term['count'];
391 $sT = null;
392
393 if ( $data['tgp_filter_taxonomy_hierarchical'] == 'yes' ) {
394 $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id );
395
396 if ( ! empty( $subTerms ) ) {
397 $count = 0;
398 $item = $allCount = null;
399
400 foreach ( $subTerms as $stId => $t ) {
401 $count = $count + absint( $t['count'] );
402 $sTPostCount = ( $post_count ? " (<span class='rt-post-count'>{$t['count']}</span>)" : null );
403 $item .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$stId}'><span class='rt-text'>{$t['name']}{$sTPostCount}</span></span>";
404 }
405
406 if ( $post_count ) {
407 $allCount = " (<span class='rt-post-count'>{$count}</span>)";
408 }
409
410 $sT .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-dropdown-wrap sub-dropdown-wrap{$postCountClass}'>";
411 $sT .= "<span class='term-default rt-filter-dropdown-default' data-term='{$id}'>
412 <span class='rt-text'>" . $allText . "</span>
413 <i class='fa fa-angle-down rt-arrow-angle' aria-hidden='true'></i>
414 </span>";
415 $sT .= '<span class="term-dropdown rt-filter-dropdown">';
416 $sT .= $item;
417 $sT .= '</span>';
418 $sT .= '</div>';
419 }
420
421 if ( $default_term === $id ) {
422 $selectedSubTerms = $sT;
423 }
424 }
425 $postCount = ( $post_count ? " (<span class='rt-post-count'>{$term['count']}</span>)" : null );
426
427 if ( $default_term && $default_term == $id ) {
428 $termDefaultText = $term['name'] . $postCount;
429 $dataTerm = $id;
430 }
431
432 if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) {
433 if ( in_array( $id, $taxFilterTerms ) ) {
434 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$id}'><span class='rt-text'>{$term['name']}{$postCount}</span>{$sT}</span>";
435 }
436 } else {
437 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$id}'><span class='rt-text'>{$term['name']}{$postCount}</span>{$sT}</span>";
438 }
439
440 $i ++;
441 }
442 }
443 $pAllCount = null;
444
445 if ( $post_count ) {
446 $pAllCount = " (<span class='rt-post-count'>{$pCount}</span>)";
447
448 if ( ! $default_term ) {
449 $termDefaultText = $termDefaultText;
450 }
451 }
452
453 if ( 'yes' == $data['tpg_hide_all_button'] ) {
454 $htmlButton = "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='all'><span class='rt-text'>" . $allText . '</span></span>' . $htmlButton;
455 }
456
457 $htmlButton = sprintf( '<span class="term-dropdown rt-filter-dropdown">%s</span>', $htmlButton );
458
459 $showAllhtml = '<span class="term-default rt-filter-dropdown-default" data-term="' . $dataTerm . '">
460 <span class="rt-text">' . $termDefaultText . '</span>
461 <i class="fa fa-angle-down rt-arrow-angle" aria-hidden="true"></i>
462 </span>';
463
464 $html .= $showAllhtml . $htmlButton;
465 $html .= '</div>' . $selectedSubTerms;
466 } else {
467 // if Button the execute.
468 // $termDefaultText = $allText;
469
470 $bCount = 0;
471 $bItems = null;
472
473 if ( ! empty( $terms ) ) {
474 foreach ( $terms as $term_id ) {
475 $term = get_term( $term_id, $taxFilter, ARRAY_A );
476 $id = $term['term_id'];
477 $bCount = $bCount + absint( $term['count'] );
478 $sT = null;
479
480 if ( $data['tgp_filter_taxonomy_hierarchical'] == 'yes' && $data['filter_btn_style'] === 'default' && $data['filter_type'] == 'button' ) {
481 $subTerms = Fns::rt_get_all_term_by_taxonomy( $taxFilter, true, $id );
482
483 if ( ! empty( $subTerms ) ) {
484 $sT .= "<div class='rt-filter-sub-tax sub-button-group '>";
485
486 foreach ( $subTerms as $stId => $t ) {
487 $sTPostCount = ( $post_count ? " (<span class='rt-post-count'>{$t['count']}</span>)" : null );
488 $sT .= "<span class='term-button-item rt-filter-button-item ' data-term='{$stId}'>{$t['name']}{$sTPostCount}</span>";
489 }
490
491 $sT .= '</div>';
492
493 if ( $default_term === $id ) {
494 $selectedSubTermsForButton = $sT;
495 }
496 }
497 }
498 $postCount = ( $post_count ? " (<span class='rt-post-count'>{$term['count']}</span>)" : null );
499 $termSelected = null;
500
501 if ( $isTermSelected && $id == $default_term ) {
502 $termSelected = ' selected';
503 }
504
505 if ( is_array( $taxFilterTerms ) && ! empty( $taxFilterTerms ) ) {
506 if ( in_array( $id, $taxFilterTerms ) ) {
507 $bItems .= "<span class='term-button-item rt-filter-button-item {$termSelected} {$itemClass}' data-term='{$id}'>{$term['name']}{$postCount}{$sT}</span>";
508 }
509 } else {
510 $bItems .= "<span class='term-button-item rt-filter-button-item {$termSelected} {$itemClass}' data-term='{$id}'>{$term['name']}{$postCount}{$sT}</span>";
511 }
512 }
513 }
514 $html .= "<div class='rt-filter-item-wrap rt-tax-filter rt-filter-button-wrap{$postCountClass} {$wrapperClass}' data-taxonomy='{$taxFilter}' data-filter='taxonomy'>";
515
516 if ( 'yes' == $data['tpg_hide_all_button'] ) {
517 $html .= "<span class='term-button-item rt-filter-button-item {$allSelect} {$itemClass}' data-term='all'>" . $allText . '</span>';
518 }
519
520 $html .= $bItems;
521
522 $html .= '</div>';
523
524 if ( 'carousel' === $data['filter_btn_style'] ) {
525 $html .= '<div class="swiper-navigation"><div class="swiper-button-prev slider-btn"></div><div class="swiper-button-next slider-btn"></div></div>';
526 }
527 }
528 }
529
530 // TODO: Author filter.
531 if ( 'show' == $data['show_author_filter'] ) {
532 $user_el = $data['author'];
533
534 $filterAuthors = $user_el;
535
536 if ( ! empty( $user_el ) ) {
537 $users = get_users( apply_filters( 'tpg_author_arg', [ 'include' => $user_el ] ) );
538 } else {
539 $users = get_users( apply_filters( 'tpg_author_arg', [] ) );
540 }
541
542 $allText = $allText = $data['author_filter_all_text'] ? $data['author_filter_all_text'] : esc_html__( 'All Users', 'the-post-grid' );
543 $allSelect = ' selected';
544 $isTermSelected = true;
545
546 if ( $filterType == 'dropdown' ) {
547 $html .= "<div class='rt-filter-item-wrap rt-author-filter rt-filter-dropdown-wrap parent-dropdown-wrap{$postCountClass}' data-filter='author'>";
548 $termDefaultText = $allText;
549 $dataAuthor = 'all';
550 $htmlButton = '';
551 $htmlButton .= '<span class="author-dropdown rt-filter-dropdown">';
552 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='all'>" . $allText . '</span>';
553
554 if ( ! empty( $users ) ) {
555 foreach ( $users as $user ) {
556 $user_post_count = false;
557 $post_count ? '(' . count_user_posts( $user->ID, $data['post_type'] ) . ')' : null;
558
559 if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) {
560 if ( in_array( $user->ID, $filterAuthors ) ) {
561 if ( $default_term == $user->ID ) {
562 $termDefaultText = $user->display_name;
563 $dataTerm = $user->ID;
564 } else {
565 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$user->ID}'>{$user->display_name} <span class='rt-text'>{$user_post_count}</span></span>";
566 }
567 }
568 } else {
569 if ( $default_term == $user->ID ) {
570 $termDefaultText = $user->display_name;
571 $dataTerm = $user->ID;
572 } else {
573 $htmlButton .= "<span class='term-dropdown-item rt-filter-dropdown-item' data-term='{$user->ID}'><span class='rt-text'>{$user->display_name} {$user_post_count}</span></span>";
574 }
575 }
576 }
577 }
578
579 $htmlButton .= '</span>';
580
581 $showAllhtml = '<span class="term-default rt-filter-dropdown-default" data-term="' . $dataAuthor . '">
582 <span class="rt-text">' . $termDefaultText . '</span>
583 <i class="fa fa-angle-down rt-arrow-angle" aria-hidden="true"></i>
584 </span>';
585
586 $html .= $showAllhtml . $htmlButton;
587 $html .= '</div>';
588 } else {
589 $bCount = 0;
590 $bItems = null;
591
592 if ( ! empty( $users ) ) {
593 foreach ( $users as $user ) {
594 if ( is_array( $filterAuthors ) && ! empty( $filterAuthors ) ) {
595 if ( in_array( $user->ID, $filterAuthors ) ) {
596 $bItems .= "<span class='author-button-item rt-filter-button-item' data-term='{$user->ID}'>{$user->display_name}</span>";
597 }
598 } else {
599 $bItems .= "<span class='author-button-item rt-filter-button-item' data-term='{$user->ID}'>{$user->display_name}</span>";
600 }
601 }
602 }
603
604 $html .= "<div class='rt-filter-item-wrap rt-author-filter rt-filter-button-wrap{$postCountClass}' data-filter='author'>";
605 $html .= "<span class='author-button-item rt-filter-button-item {$allSelect}' data-author='all'>" . $allText . '</span>';
606 $html .= $bItems;
607 $html .= '</div>';
608 }
609 }
610
611 if ( 'show' == $data['show_author_filter'] || 'show' == $data['show_taxonomy_filter'] ) {
612 $html .= '</div>';
613 }
614
615 if ( 'show' == $data['show_order_by'] || 'show' == $data['show_sort_order'] || 'show' == $data['show_search'] ) {
616 $html .= "<div class='filter-right-wrapper'>";
617 }
618
619 // TODO: Order Filter.
620 if ( 'show' == $data['show_sort_order'] ) {
621 $action_order = ( $data['order'] ? strtoupper( $data['order'] ) : 'DESC' );
622 $html .= '<div class="rt-filter-item-wrap rt-sort-order-action" data-filter="order">';
623 $html .= "<span class='rt-sort-order-action-arrow' data-sort-order='{$action_order}'>&nbsp;<span></span></span>";
624 $html .= '</div>';
625 }
626
627 // TODO: Orderby Filter.
628 if ( 'show' == $data['show_order_by'] ) {
629 $wooFeature = ( $data['post_type'] == 'product' ? true : false );
630 $orders = Options::rtPostOrderBy( $wooFeature );
631 $action_orderby = ( ! empty( $data['orderby'] ) ? $data['orderby'] : 'none' );
632
633 if ( $action_orderby == 'none' ) {
634 $action_orderby_label = esc_html__( 'Sort By', 'the-post-grid' );
635 } elseif ( in_array( $action_orderby, array_keys( Options::rtMetaKeyType() ) ) ) {
636 $action_orderby_label = esc_html__( 'Meta value', 'the-post-grid' );
637 } else {
638 $action_orderby_label = esc_html__( 'By ', 'the-post-grid' ) . $action_orderby;
639 }
640
641 if ( $action_orderby !== 'none' ) {
642 $orders['none'] = esc_html__( 'Sort By', 'the-post-grid' );
643 }
644
645 $html .= '<div class="rt-filter-item-wrap rt-order-by-action rt-filter-dropdown-wrap" data-filter="orderby">';
646 $html .= "<span class='order-by-default rt-filter-dropdown-default' data-order-by='{$action_orderby}'>
647 <span class='rt-text-order-by'>{$action_orderby_label}</span>
648 <i class='fa fa-angle-down rt-arrow-angle' aria-hidden='true'></i>
649 </span>";
650 $html .= '<span class="order-by-dropdown rt-filter-dropdown">';
651
652 foreach ( $orders as $orderKey => $order ) {
653 $html .= '<span class="order-by-dropdown-item rt-filter-dropdown-item" data-order-by="' . $orderKey . '">' . $order . '</span>';
654 }
655
656 $html .= '</span>';
657 $html .= '</div>';
658 }
659
660 // TODO: Search Filter.
661 if ( 'show' == $data['show_search'] ) {
662 $html .= '<div class="rt-filter-item-wrap rt-search-filter-wrap" data-filter="search">';
663 $html .= sprintf( '<input type="text" class="rt-search-input" placeholder="%s">', esc_html__( 'Search...', 'the-post-grid' ) );
664 $html .= "<span class='rt-action'>&#128269;</span>";
665 $html .= "<span class='rt-loading'></span>";
666 $html .= '</div>';
667 }
668
669 if ( 'show' == $data['show_order_by'] || 'show' == $data['show_sort_order'] || 'show' == $data['show_search'] ) {
670 $html .= '</div>';
671 }
672
673 $html .= "</div>$selectedSubTermsForButton</div>";
674
675 return $html;
676 }
677
678 /**
679 * Get Post Pagination, Load more & Scroll markup
680 *
681 * @param $query
682 * @param $data
683 *
684 * @return false|string|void
685 */
686 public function get_pagination_markup( $query, $data ) {
687 if ( 'show' !== $data['show_pagination'] ) {
688 return;
689 }
690
691 $htmlUtility = null;
692
693 $posts_loading_type = $data['pagination_type'];
694 $posts_per_page = ( isset( $data['display_per_page'] ) && $data['display_per_page'] ) ? $data['display_per_page']
695 : ( $data['post_limit'] ? $data['post_limit'] : get_option( 'posts_per_page' ) );
696 $hide = ( $query->max_num_pages < 2 ? ' rt-hidden-elm' : null );
697
698 if ( $posts_loading_type == 'pagination' ) {
699 $htmlUtility .= Fns::rt_pagination( $query, $posts_per_page );
700 } elseif ( rtTPG()->hasPro() && $posts_loading_type == 'pagination_ajax' ) { // && ! $isIsotope
701 $htmlUtility .= "<div class='rt-page-numbers'></div>";
702 } elseif ( rtTPG()->hasPro() && $posts_loading_type == 'load_more' ) {
703 $load_more_btn_text = $data['load_more_button_text'] ? esc_html( $data['load_more_button_text'] ) : esc_html__( 'Load More', 'the-post-grid' );
704 $htmlUtility .= "<div class='rt-loadmore-btn rt-loadmore-action rt-loadmore-style{$hide}'>
705 <span class='rt-loadmore-text'>" . $load_more_btn_text . "</span>
706 <div class='rt-loadmore-loading rt-ball-scale-multiple rt-2x'><div></div><div></div><div></div></div>
707 </div>";
708 } elseif ( rtTPG()->hasPro() && $posts_loading_type == 'load_on_scroll' ) {
709 $htmlUtility .= "<div class='rt-infinite-action'>
710 <div class='rt-infinite-loading la-fire la-2x'>
711 <div></div><div></div><div></div>
712 </div>
713 </div>";
714 }
715
716 if ( $htmlUtility ) {
717 $html = "<div class='rt-pagination-wrap' data-total-pages='{$query->max_num_pages}' data-posts-per-page='{$posts_per_page}' data-type='{$posts_loading_type}' >" . $htmlUtility . '</div>';
718
719 return $html;
720 }
721
722 return false;
723 }
724
725 /**
726 * Get Popup Modal Markup
727 */
728 public function get_modal_markup() {
729 $html = null;
730 $html .= '<div class="md-modal rt-md-effect" id="rt-modal">
731 <div class="md-content">
732 <div class="rt-md-content-holder"></div>
733 <div class="md-cls-btn">
734 <button class="md-close"><i class="fa fa-times" aria-hidden="true"></i></button>
735 </div>
736 </div>
737 </div>';
738 $html .= "<div class='md-overlay'></div>";
739
740 Fns::print_html( $html );
741 }
742
743 /**
744 * Get Archive page title
745 */
746 public function get_archive_title() {
747 $queried_obj = get_queried_object();
748
749 if ( is_tag() || is_category() ) {
750 echo esc_html( $queried_obj->name );
751 } elseif ( is_author() ) {
752 echo esc_html( $queried_obj->display_name );
753 } elseif ( is_date() ) {
754 $year = get_query_var( 'year' );
755 $monthnum = get_query_var( 'monthnum' );
756 $day = get_query_var( 'day' );
757 $time_string = $year . '/' . $monthnum . '/' . $day;
758 $time_stamp = strtotime( $time_string );
759 Fns::print_html( date( get_option( 'date_format' ), $time_stamp ) );
760 }
761 }
762
763 /**
764 * Get Section Title
765 *
766 * @param $data
767 */
768 public function get_section_title( $data ) {
769 if ( 'show' != $data['show_section_title'] ) {
770 return;
771 }
772
773 $_is_link = false;
774
775 if ( ! empty( $data['section_title_link']['url'] ) ) {
776 $this->add_link_attributes( 'section_title_link', $data['section_title_link'] );
777 $_is_link = true;
778 }
779
780 $this->add_inline_editing_attributes( 'section_title_text', 'none' );
781 ob_start();
782 ?>
783
784 <div class="tpg-widget-heading-wrapper rt-clear heading-<?php echo esc_attr( $data['section_title_style'] ); ?> ">
785 <span class="tpg-widget-heading-line line-left"></span>
786
787 <?php printf( "<%s class='tpg-widget-heading'>", esc_attr( $data['section_title_tag'] ) ); ?>
788
789 <?php
790 if ( $_is_link ) :
791 ?>
792 <a <?php Fns::print_html( $this->get_render_attribute_string( 'section_title_link' ), true ); ?>>
793 <?php endif; ?>
794
795 <?php
796 if ( 'page_title' == $data['section_title_source'] ) {
797 $archive_prefix = $data['title_prefix'] ? $data['title_prefix'] . ' ' : null;
798 $archive_suffix = $data['title_suffix'] ? ' ' . $data['title_suffix'] : null;
799 printf( "<span class='prefix-text'>%s</span>", esc_html( $archive_prefix ) );
800
801 if ( is_archive() ) {
802 $this->get_archive_title();
803 } elseif ( is_search() ) {
804 echo get_query_var( 's' );
805 } else {
806 the_title();
807 }
808
809 printf( "<span class='suffix-text'>%s</span>", esc_html( $archive_suffix ) );
810 } else {
811 ?>
812 <span <?php $this->print_render_attribute_string( 'section_title_text' ); ?>>
813 <?php $this->print_unescaped_setting( 'section_title_text' ); ?>
814 </span>
815 <?php
816 }
817 ?>
818
819 <?php if ( $_is_link ) : ?>
820 </a>
821
822 <?php endif; ?>
823 <?php printf( '</%s>', $data['section_title_tag'] ); ?>
824 <span class="tpg-widget-heading-line line-right"></span>
825 </div>
826
827 <?php if ( isset( $data['show_cat_desc'] ) && $data['show_cat_desc'] == 'yes' && category_description( $this->get_last_category_id() ) ) : ?>
828 <div class="tpg-category-description">
829 <?php echo category_description( $this->get_last_category_id() ); ?>
830 </div>
831 <?php endif; ?>
832
833 <?php
834 Fns::print_html( ob_get_clean() );
835 }
836
837
838 /**
839 * Get Post Data for render post
840 *
841 * @param $data
842 * @param $total_pages
843 * @param $posts_per_page
844 *
845 * @return array
846 */
847 public function get_render_data_set( $data, $total_pages, $posts_per_page ) {
848 $_prefix = $this->prefix;
849
850 $data_set = [
851 'block_type' => 'elementor',
852 'prefix' => $_prefix,
853 'gird_column' => $data[ $_prefix . '_column' ],
854 'gird_column_tablet' => isset( $data[ $_prefix . '_column_tablet' ] ) ? $data[ $_prefix . '_column_tablet' ] : '0',
855 'gird_column_mobile' => isset( $data[ $_prefix . '_column_mobile' ] ) ? $data[ $_prefix . '_column_mobile' ] : '0',
856 'layout' => $data[ $_prefix . '_layout' ],
857 'pagination_type' => 'slider' === $_prefix ? 'slider' : $data['pagination_type'],
858 'total_pages' => $total_pages,
859 'posts_per_page' => $posts_per_page,
860 'layout_style' => isset( $data[ $_prefix . '_layout_style' ] ) ? $data[ $_prefix . '_layout_style' ] : '',
861 'show_title' => $data['show_title'],
862 'excerpt_type' => $data['excerpt_type'],
863 'excerpt_limit' => $data['excerpt_limit'],
864 'excerpt_more_text' => $data['excerpt_more_text'],
865 'title_limit' => $data['title_limit'],
866 'title_limit_type' => $data['title_limit_type'],
867 'title_visibility_style' => $data['title_visibility_style'],
868 'post_link_type' => $data['post_link_type'],
869 'link_target' => $data['link_target'],
870 'hover_animation' => isset( $data['hover_animation'] ) ? $data['hover_animation'] : '',
871 'show_thumb' => $data['show_thumb'],
872 'show_meta' => $data['show_meta'],
873 'show_author' => $data['show_author'],
874 'show_author_image' => $data['show_author_image'],
875 'show_meta_icon' => $data['show_meta_icon'],
876 'show_category' => $data['show_category'],
877 'show_date' => $data['show_date'],
878 'show_tags' => $data['show_tags'],
879 'show_comment_count' => $data['show_comment_count'],
880 'show_comment_count_label' => isset( $data['show_comment_count_label'] ) ? $data['show_comment_count_label'] : '',
881 'comment_count_label_singular' => isset( $data['comment_count_label_singular'] ) ? $data['comment_count_label_singular'] : '',
882 'comment_count_label_plural' => isset( $data['comment_count_label_plural'] ) ? $data['comment_count_label_plural'] : '',
883 'show_post_count' => $data['show_post_count'],
884 'post_count_icon' => $data['post_count_icon'],
885 'show_excerpt' => $data['show_excerpt'],
886 'show_read_more' => $data['show_read_more'],
887 'show_btn_icon' => $data['show_btn_icon'],
888 'show_social_share' => $data['show_social_share'],
889 'show_cat_icon' => isset( $data['show_cat_icon'] ) ? $data['show_cat_icon'] : '',
890 'is_thumb_linked' => $data['is_thumb_linked'],
891 'media_source' => $data['media_source'],
892 'no_posts_found_text' => isset( $data['no_posts_found_text'] ) ? $data['no_posts_found_text'] : '',
893 'image_size' => $data['image_size'],
894 'image_offset' => $data['image_offset_size'],
895 'is_default_img' => $data['is_default_img'],
896 'default_image' => $data['default_image'],
897 'thumb_overlay_visibility' => isset( $data['thumb_overlay_visibility'] ) ? $data['thumb_overlay_visibility'] : '',
898 'overlay_type' => isset( $data['overlay_type'] ) ? $data['overlay_type'] : '',
899 'title_tag' => $data['title_tag'],
900 'post_type' => $data['post_type'],
901 'meta_separator' => $data['meta_separator'],
902 'readmore_icon_position' => $data['readmore_icon_position'],
903 'read_more_label' => $data['read_more_label'],
904 'readmore_btn_icon' => $data['readmore_btn_icon'],
905 'category_position' => $data['category_position'],
906 'title_position' => $data['title_position'],
907 'category_style' => $data['category_style'],
908 'is_thumb_lightbox' => $data['is_thumb_lightbox'],
909 'light_box_icon' => $data['light_box_icon'],
910 'author_prefix' => $data['author_prefix'],
911 'cat_icon' => $data['cat_icon'],
912 'tag_icon' => $data['tag_icon'],
913 'date_icon' => $data['date_icon'],
914 'user_icon' => $data['user_icon'],
915 'meta_ordering' => $data['meta_ordering'],
916 'comment_icon' => $data['comment_icon'],
917 'image_custom_dimension' => ( $data['image_size'] == 'custom' && isset( $data['image_custom_dimension'] ) ) ? $data['image_custom_dimension'] : '',
918 'img_crop_style' => ( $data['image_size'] == 'custom' && isset( $data['img_crop_style'] ) ) ? $data['img_crop_style'] : '',
919 'show_acf' => isset( $data['show_acf'] ) ? $data['show_acf'] : '',
920 ];
921
922 $cf = Fns::is_acf();
923 if ( $cf && rtTPG()->hasPro() ) {
924 $post_type = $data['post_type'];
925 $data_set['cf_group'] = $data[ $post_type . '_cf_group' ];
926 $data_set['cf_hide_empty_value'] = $data['cf_hide_empty_value'];
927 $data_set['cf_show_only_value'] = $data['cf_show_only_value'];
928 $data_set['cf_hide_group_title'] = $data['cf_hide_group_title'];
929 }
930
931 return $data_set;
932 }
933 }
934