PluginProbe
Post Grid Gutenberg Blocks – PostX / 5.0.30
Post Grid Gutenberg Blocks – PostX v5.0.30
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
ultimate-post / blocks / Taxonomy.php

Taxonomy.php in Post Grid Gutenberg Blocks – PostX 5.0.30, at blocks/Taxonomy.php

181 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ULTP\blocks;
3
4 defined( 'ABSPATH' ) || exit;
5
6 class Taxonomy {
7
8 public function __construct() {
9 add_action( 'init', array( $this, 'register' ) );
10 }
11
12 public function get_attributes() {
13 return array(
14 'blockId' => '',
15 'previewImg' => '',
16 // Layout
17 'layout' => '1',
18 // Query Setting
19 'taxType' => 'regular',
20 'taxSlug' => 'category',
21 'taxValue' => '[]',
22 'queryNumber' => 6,
23 // General Setting
24 'taxGridEn' => true,
25 'columns' => (object) array( 'lg' => '1' ),
26 'rowGap' => (object) array(
27 'lg' => '20',
28 'unit' => 'px',
29 ),
30 'titleShow' => true,
31 'headingShow' => true,
32 'excerptShow' => false,
33 'countShow' => true,
34 'openInTab' => false,
35 'notFoundMessage' => 'No Taxonomy Found.',
36
37 // Heading Setting/Style
38 'headingText' => 'Post Taxonomy',
39 'headingURL' => '',
40 'headingBtnText' => 'View More',
41 'headingStyle' => 'style9',
42 'headingTag' => 'h2',
43 'headingAlign' => 'left',
44 'subHeadingShow' => false,
45 'subHeadingText' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ut sem augue. Sed at felis ut enim dignissim sodales.',
46 'titleTag' => 'span',
47 'contentTitleAlign' => 'left',
48 'titlePosition' => true,
49 'customTaxTitleColor' => false,
50 'seperatorTaxTitleLink' => admin_url( 'edit-tags.php?taxonomy=category' ),
51
52 // Content Setting/Style
53 'excerptLimit' => 30,
54
55 // Image Setting/Style
56 'imgCrop' => ( ultimate_post()->get_setting( 'disable_image_size' ) == 'yes' ? 'full' : 'ultp_layout_landscape' ),
57
58 // Separator
59 'separatorShow' => false,
60
61 // Custom Wrapper Style
62 'customTaxColor' => false,
63 'seperatorTaxLink' => admin_url( 'edit-tags.php?taxonomy=category' ),
64 'TaxAnimation' => 'none',
65 'advanceId' => '',
66 'advanceZindex' => '',
67 'hideExtraLarge' => false,
68 'hideTablet' => false,
69 'hideMobile' => false,
70 'advanceCss' => '',
71 );
72 }
73
74 public function register() {
75 register_block_type(
76 'ultimate-post/ultp-taxonomy',
77 array(
78 'editor_script' => 'ultp-blocks-editor-script',
79 'editor_style' => 'ultp-blocks-editor-css',
80 'render_callback' => array( $this, 'content' ),
81 )
82 );
83 }
84
85 public function content( $attr, $noAjax ) {
86 $attr = wp_parse_args( $attr, $this->get_attributes() );
87
88 if ( ! $noAjax ) {
89 $paged = is_front_page() ? get_query_var( 'page' ) : get_query_var( 'paged' );
90 $attr['paged'] = $paged ? $paged : 1;
91 }
92
93 $block_name = 'ultp-taxonomy';
94 $wraper_before = $wraper_after = $post_loop = '';
95 $recent_posts = ultimate_post()->get_category_data( json_decode( $attr['taxValue'] ), $attr['queryNumber'], $attr['taxType'], $attr['taxSlug'] );
96
97 if ( ! empty( $recent_posts ) ) {
98
99 $attr['className'] = isset( $attr['className'] ) && $attr['className'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['className'] ) : '';
100 $attr['imgCrop'] = isset( $attr['imgCrop'] ) && $attr['imgCrop'] ? preg_replace( '/[^A-Za-z0-9_ -]/', '', $attr['imgCrop'] ) : '';
101 $attr['advanceId'] = isset( $attr['advanceId'] ) ? sanitize_html_class( $attr['advanceId'] ) : '';
102 $attr['blockId'] = isset( $attr['blockId'] ) ? sanitize_html_class( $attr['blockId'] ) : '';
103 $attr['titleTag'] = in_array( $attr['titleTag'], ultimate_post()->ultp_allowed_block_tags() ) ? $attr['titleTag'] : 'span';
104 $attr['layout'] = sanitize_html_class( $attr['layout'] );
105 $attr['TaxAnimation'] = sanitize_html_class( $attr['TaxAnimation'] );
106
107 $wraper_before .= '<div ' . ( $attr['advanceId'] ? 'id="' . $attr['advanceId'] . '" ' : '' ) . ' class="wp-block-ultimate-post-' . $block_name . ' ultp-block-' . $attr['blockId'] . ' ' . ( $attr['className'] ? $attr['className'] : '' ) . '">';
108 $wraper_before .= '<div class="ultp-block-wrapper">';
109 $wraper_before .= ultimate_post()->postx_loading(); // Loading
110
111 if ( $attr['headingShow'] ) {
112 $wraper_before .= '<div class="ultp-heading-filter">';
113 $wraper_before .= '<div class="ultp-heading-filter-in">';
114 include ULTP_PATH . 'blocks/template/heading.php'; // Heading
115 $wraper_before .= '</div>';
116 $wraper_before .= '</div>';
117 }
118
119 $wraper_before .= '<div class="ultp-block-items-wrap">';
120 $wraper_before .= '<ul class="ultp-taxonomy-items ' . ( isset( $attr['TaxAnimation'] ) ? ' ultp-taxonomy-animation-' . $attr['TaxAnimation'] : '' ) . ' ultp-taxonomy-column-' . sanitize_html_class( json_decode( wp_json_encode( $attr['columns'] ), true )['lg'] ) . ' ultp-taxonomy-layout-' . $attr['layout'] . '">';
121
122 foreach ( $recent_posts as $value ) {
123 $_style = ( ( $attr['customTaxColor'] && $value['color'] ) ? ' style="background-color:' . $value['color'] . ';"' : '' );
124 $_style_color = ( ( in_array( $attr['layout'], array( 1, 4, 5 ) ) && $value['color'] && $attr['customTaxTitleColor'] ) ? ' style="color:' . $value['color'] . ';"' : '' );
125 $_style_title_bg = ( ( in_array( $attr['layout'], array( 7, 8 ) ) && $value['color'] && $attr['customTaxTitleColor'] ) ? ' style="background:' . $value['color'] . ';"' : '' );
126 $post_loop .= '<li class="ultp-block-item ultp-taxonomy-item">';
127
128 $style = in_array( $attr['layout'], array( 2, 3, 6, 7, 8 ) ) ? 'style="' . ( $value['image'] ? 'background-image: url(' . $value['image'][ $attr['imgCrop'] ] . ')' : '' ) . '"' : '';
129
130 $name = ( $attr['titleShow'] && $value['name'] ) ? '<' . $attr['titleTag'] . ' class="ultp-taxonomy-name" ' . $_style_color . '>' . $value['name'] . '</' . $attr['titleTag'] . '>' : '';
131 $count = ( $attr['countShow'] && $value['count'] ) ? '<span class="ultp-taxonomy-count" ' . $_style_color . '>' . $value['count'] . '</span>' : '';
132 $excerpt = ( $attr['excerptShow'] && $value['desc'] ) ? '<div class="ultp-taxonomy-desc">' . $value['desc'] . '</div>' : '';
133 $post_loop .= '<a href="' . $value['url'] . '" ' . ( $attr['layout'] != 3 ? $style : '' ) . '>';
134 switch ( $attr['layout'] ) {
135 case 1:
136 $post_loop .= $name . $count . $excerpt;
137 break;
138 case 2:
139 $post_loop .= '<div class="ultp-taxonomy-lt2-overlay"' . $_style . '></div><div class="ultp-taxonomy-lt2-content">' . $name . '<span class="ultp-taxonomy-bar"></span>' . $count . '</div>' . $excerpt;
140 break;
141 case 3:
142 $post_loop .= '<div class="ultp-taxonomy-lt3-img" ' . $style . '></div><div class="ultp-taxonomy-lt3-overlay"' . $_style . '></div><div class="ultp-taxonomy-lt3-content">' . $name . '<span class="ultp-taxonomy-bar"></span>' . $count . '</div>' . $excerpt;
143 break;
144 case 4:
145 $img = $value['image'] ? '<img src="' . $value['image'][ $attr['imgCrop'] ] . '" alt="' . $value['name'] . '"/>' : '';
146 $post_loop .= $img . '<div class="ultp-taxonomy-lt4-content">' . $name . $count . '</div>' . $excerpt;
147 break;
148 case 5:
149 $img = $value['image'] ? '<img src="' . $value['image'][ $attr['imgCrop'] ] . '" alt="' . $value['name'] . '"/>' : '';
150 $post_loop .= $img . '<span class="ultp-taxonomy-lt5-content">' . $name . $count . $excerpt . '</span>';
151 break;
152 case 6:
153 $post_loop .= '<div class="ultp-taxonomy-lt6-overlay"' . $_style . '></div>' . $name . $count . $excerpt;
154 break;
155 case 7:
156 $post_loop .= '<div class="ultp-taxonomy-lt7-overlay"' . $_style . '></div><' . $attr['titleTag'] . ' class="ultp-taxonomy-name" ' . $_style_title_bg . '>' . $value['name'] . $count . '</' . $attr['titleTag'] . '>' . $excerpt;
157 break;
158 case 8:
159 $post_loop .= '<div class="ultp-taxonomy-lt8-overlay"' . $_style . '></div><' . $attr['titleTag'] . ' class="ultp-taxonomy-name" ' . $_style_title_bg . '>' . $value['name'] . $count . '</' . $attr['titleTag'] . '>' . $excerpt;
160 break;
161 default:
162 // code...
163 break;
164 }
165 $post_loop .= '</a>';
166 $post_loop .= '</li>';
167 }
168
169 $wraper_after .= '</ul>';
170 $wraper_after .= '</div>';
171 $wraper_after .= '</div>';
172 $wraper_after .= '</div>';
173 wp_reset_query();
174 } else {
175 $wraper_before .= ultimate_post()->get_no_result_found_html( $attr['notFoundMessage'] );
176 }
177
178 return $noAjax ? $post_loop : $wraper_before . $post_loop . $wraper_after;
179 }
180 }
181