PluginProbe
Post Grid Gutenberg Blocks – PostX / 1.2.1
Post Grid Gutenberg Blocks – PostX v1.2.1
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 / classes / Functions.php

Functions.php in Post Grid Gutenberg Blocks – PostX 1.2.1, at classes/Functions.php

256 lines 11.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace ULTP;
3
4 defined('ABSPATH') || exit;
5
6 class Functions{
7
8 // Excerpt
9 public function excerpt( $post_id, $limit = 55 ) {
10 return apply_filters( 'the_excerpt', wp_trim_words( get_the_content( $post_id ) , $limit ) );
11 }
12
13 // Query Builder
14 public function get_query($attr) {
15 $query_args = array(
16 'posts_per_page' => isset($attr['queryNumber']) ? $attr['queryNumber'] : 3,
17 'post_type' => isset($attr['queryType']) ? $attr['queryType'] : 'post',
18 'orderby' => isset($attr['queryOrderBy']) ? $attr['queryOrderBy'] : 'date',
19 'order' => isset($attr['queryOrder']) ? $attr['queryOrder'] : 'desc',
20 'paged' => isset($attr['paged']) ? $attr['paged'] : 1,
21 'post_status' => 'publish'
22 );
23
24 if(isset($attr['queryOrderBy']) && isset($attr['metaKey'])){
25 if($attr['queryOrderBy'] == 'meta_value_num') {
26 $query_args['meta_key'] = $attr['metaKey'];
27 }
28 }
29
30 if(isset($attr['queryOffset']) && $attr['queryOffset'] && !($query_args['paged'] > 1) ){
31 $query_args['offset'] = isset($attr['queryOffset']) ? $attr['queryOffset'] : 0;
32 }
33
34 if(isset($attr['queryInclude']) && $attr['queryInclude']){
35 $query_args['post__in'] = explode(',', $attr['queryInclude']);
36 }
37
38 if(isset($attr['queryExclude']) && $attr['queryExclude']){
39 $query_args['post__not_in'] = explode(',', $attr['queryExclude']);
40 }
41
42 if(isset($attr['queryTax'])){
43 if(isset($attr['queryCat'])){
44 if($attr['queryTax'] == 'category' && !empty($attr['queryCat'])){
45 $var = array('relation'=>'OR');
46 foreach (json_decode($attr['queryCat']) as $val) {
47 $var[] = array('taxonomy'=>'category', 'field' => 'slug', 'terms' => $val );
48 }
49 $query_args['tax_query'] = $var;
50 }
51 }
52 if(isset($attr['queryTag'])){
53 if($attr['queryTax'] == 'tag' && !empty($attr['queryTag'])){
54 $var = array('relation'=>'OR');
55 foreach (json_decode($attr['queryTag']) as $val) {
56 $var[] = array('taxonomy'=>'post_tag', 'field' => 'slug', 'terms' => $val );
57 }
58 $query_args['tax_query'] = $var;
59 }
60 }
61 }
62
63 $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
64
65 return $query_args;
66 }
67
68
69 public function get_page_number($attr, $post_number) {
70 if($post_number > 0){
71 $post_per_page = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
72 $pages = ceil($post_number/$post_per_page);
73 return $pages ? $pages : 1;
74 }else{
75 return 1;
76 }
77 }
78
79 public function get_image_size() {
80 $sizes = get_intermediate_image_sizes();
81 $filter = array('full' => 'Full');
82 foreach ($sizes as $value) {
83 $filter[$value] = ucwords(str_replace(array('_', '-'), array(' ', ' '), $value));
84 }
85 return $filter;
86 }
87
88
89 public function get_post_type() {
90 $post_type = get_post_types( '', 'names' );
91 return array_diff($post_type, array( 'attachment', 'revision', 'nav_menu_item', 'custom_css', 'customize_changeset', 'oembed_cache', 'user_request', 'wp_block' ));
92 }
93
94
95 // Pagination
96 public function pagination($pages = '', $paginationNav, $range = 1) {
97 $html = '';
98 $showitems = 3;
99 $paged = get_query_var('paged') ? get_query_var('paged') : 1;
100 if($pages == '') {
101 global $wp_query;
102 $pages = $wp_query->max_num_pages;
103 if(!$pages) {
104 $pages = 1;
105 }
106 }
107 $data = ($paged>=3?[($paged-1),$paged,$paged+1]:[1,2,3]);
108
109
110 if(1 != $pages) {
111 $html .= '<ul class="ultp-pagination">';
112 $display_none = 'style="display:none"';
113 if($pages > 4) {
114 $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'?__("Previous", "ultimate-post"):"").'</a></li>';
115 }
116 if($pages > 4){
117 $html .= '<li class="ultp-first-pages" '.($paged<2?$display_none:"").' data-current="1"><a href="'.get_pagenum_link(1).'">1</a></li>';
118 }
119 if($pages > 4){
120 $html .= '<li class="ultp-first-dot" '.($paged<2? $display_none : "").'><a href="#">...</a></li>';
121 }
122 foreach ($data as $i) {
123 if($pages >= $i){
124 $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>';
125 }
126 }
127 if($pages > 4){
128 $html .= '<li class="ultp-last-dot" '.($pages<=$paged+1?$display_none:"").'><a href="#">...</a></li>';
129 }
130 if($pages > 4){
131 $html .= '<li class="ultp-last-pages" '.($pages<=$paged+1?$display_none:"").' data-current="'.$pages.'"><a href="'.get_pagenum_link($pages).'">'.$pages.'</a></li>';
132 }
133 if ($paged != $pages) {
134 $html .= '<li class="ultp-next-page-numbers"><a href="'.get_pagenum_link($paged + 1).'">'.($paginationNav == 'textArrow' ? __("Next", "ultimate-post") : "").ultimate_post()->svg_icon('rightAngle2').'</a></li>';
135 }
136 $html .= '</ul>';
137 }
138 return $html;
139 }
140
141 public function excerpt_word($charlength = 200) {
142 $html = '';
143 $charlength++;
144 $excerpt = get_the_excerpt();
145 if ( mb_strlen( $excerpt ) > $charlength ) {
146 $subex = mb_substr( $excerpt, 0, $charlength - 5 );
147 $exwords = explode( ' ', $subex );
148 $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
149 if ( $excut < 0 ) {
150 $html = mb_substr( $subex, 0, $excut );
151 } else {
152 $html = $subex;
153 }
154 $html .= '...';
155 } else {
156 $html = $excerpt;
157 }
158 return $html;
159 }
160
161
162 public function taxonomy( $prams = 'category' ) {
163 $data = array();
164 $terms = get_terms( $prams, array(
165 'hide_empty' => true,
166 ));
167 if( !empty($terms) ){
168 foreach ($terms as $val) {
169 $data[$val->slug] = $val->name;
170 }
171 }
172 return $data;
173 }
174
175
176 public function next_prev() {
177 $html = '';
178 $html .= '<ul>';
179 $html .= '<li>';
180 $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
181 $html .= ultimate_post()->svg_icon('leftAngle2').'<span class="screen-reader-text">'.__("Previous", "ultimate-post").'</span>';
182 $html .= '</a>';
183 $html .= '</li>';
184 $html .= '<li>';
185 $html .= '<a class="ultp-next-action">';
186 $html .= ultimate_post()->svg_icon('rightAngle2').'<span class="screen-reader-text">'.__("Next", "ultimate-post").'</span>';
187 $html .= '</a>';
188 $html .= '</li>';
189 $html .= '</ul>';
190 return $html;
191 }
192
193 public function loading(){
194 $html = '';
195 $style = 'style1';
196 $option_data = get_option('ultp_options');
197 if( isset($option_data['preloader_style']) ){
198 $style = $option_data['preloader_style'];
199 }
200 if( $style == 'style2' ){
201 $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
202 } else {
203 $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>';
204 }
205 return '<div class="ultp-loading">'.$html.'</div>';
206 }
207
208 public function filter($filterText = '', $filterType = '', $filterCat = '[]', $filterTag = '[]'){
209 $html = '';
210 $html .= '<ul class="ultp-flex-menu">';
211 if ($filterType == 'category') {
212 $cat = $this->taxonomy('category');
213 if($filterText){
214 $html .= '<li class="filter-item"><a data-taxonomy="" href="#">'.$filterText.'</a></li>';
215 }
216 foreach (json_decode($filterCat) as $val) {
217 $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($cat[$val]) ? $cat[$val] : $val).'</a></li>';
218 }
219 } else {
220 $tag = $this->taxonomy('post_tag');
221 if($filterText){
222 $html .= '<li class="filter-item"><a data-taxonomy="" href="#">'.$filterText.'</a></li>';
223 }
224 foreach (json_decode($filterTag) as $val) {
225 $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($tag[$val]) ? $tag[$val] : $val).'</a></li>';
226 }
227 }
228 $html .= '</ul>';
229 return $html;
230 }
231
232 public function svg_icon($icons = ''){
233
234 $icon_lists = array(
235 'eye' => file_get_contents(ULTP_PATH.'assets/img/svg/eye.svg'),
236 'user' => file_get_contents(ULTP_PATH.'assets/img/svg/user.svg'),
237 'calendar' => file_get_contents(ULTP_PATH.'assets/img/svg/calendar.svg'),
238 'comment' => file_get_contents(ULTP_PATH.'assets/img/svg/comment.svg'),
239 'book' => file_get_contents(ULTP_PATH.'assets/img/svg/book.svg'),
240 'tag' => file_get_contents(ULTP_PATH.'assets/img/svg/tag.svg'),
241 'clock' => file_get_contents(ULTP_PATH.'assets/img/svg/clock.svg'),
242 'leftAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle.svg'),
243 'rightAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle.svg'),
244 'leftAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle2.svg'),
245 'rightAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle2.svg'),
246 'leftArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/leftArrowLg.svg'),
247 'refresh' => file_get_contents(ULTP_PATH.'assets/img/svg/refresh.svg'),
248 'rightArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/rightArrowLg.svg'),
249 );
250 if($icons){
251 return $icon_lists[ $icons ];
252 }
253 }
254
255 }
256