PluginProbe
Post Grid Gutenberg Blocks – PostX / 1.1.4
Post Grid Gutenberg Blocks – PostX v1.1.4
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.1.4, at classes/Functions.php

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