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

234 lines 10.4 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 // Pagination
83 public function pagination($pages = '', $paginationNav, $range = 1) {
84 $html = '';
85 $showitems = 3;
86 $paged = get_query_var('paged') ? get_query_var('paged') : 1;
87 if($pages == '') {
88 global $wp_query;
89 $pages = $wp_query->max_num_pages;
90 if(!$pages) {
91 $pages = 1;
92 }
93 }
94 $data = ($paged>=3?[($paged-1),$paged,$paged+1]:[1,2,3]);
95
96
97 if(1 != $pages) {
98 $html .= '<ul class="ultp-pagination">';
99 $display_none = 'style="display:none"';
100 if($pages > 4) {
101 $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>';
102 }
103 if($pages > 4){
104 $html .= '<li class="ultp-first-pages" '.($paged<2?$display_none:"").' data-current="1"><a href="'.get_pagenum_link(1).'">1</a></li>';
105 }
106 if($pages > 4){
107 $html .= '<li class="ultp-first-dot" '.($paged<2? $display_none : "").'><a href="#">...</a></li>';
108 }
109 foreach ($data as $i) {
110 if($pages >= $i){
111 $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>';
112 }
113 }
114 if($pages > 4){
115 $html .= '<li class="ultp-last-dot" '.($pages<=$paged+1?$display_none:"").'><a href="#">...</a></li>';
116 }
117 if($pages > 4){
118 $html .= '<li class="ultp-last-pages" '.($pages<=$paged+1?$display_none:"").' data-current="'.$pages.'"><a href="'.get_pagenum_link($pages).'">'.$pages.'</a></li>';
119 }
120 if ($paged != $pages) {
121 $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>';
122 }
123 $html .= '</ul>';
124 }
125 return $html;
126 }
127
128 public function excerpt_word($charlength = 200) {
129 $html = '';
130 $charlength++;
131 $excerpt = get_the_excerpt();
132 if ( mb_strlen( $excerpt ) > $charlength ) {
133 $subex = mb_substr( $excerpt, 0, $charlength - 5 );
134 $exwords = explode( ' ', $subex );
135 $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
136 if ( $excut < 0 ) {
137 $html = mb_substr( $subex, 0, $excut );
138 } else {
139 $html = $subex;
140 }
141 $html .= '...';
142 } else {
143 $html = $excerpt;
144 }
145 return $html;
146 }
147
148
149 public function taxonomy( $prams = 'category' ) {
150 $data = array();
151 $terms = get_terms( $prams, array(
152 'hide_empty' => true,
153 ));
154 if( !empty($terms) ){
155 foreach ($terms as $val) {
156 $data[$val->slug] = $val->name;
157 }
158 }
159 return $data;
160 }
161
162
163 public function next_prev() {
164 $html = '';
165 $html .= '<ul>';
166 $html .= '<li>';
167 $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
168 $html .= ultimate_post()->svg_icon('leftAngle2').'<span class="screen-reader-text">'.__("Previous", "ultimate-post").'</span>';
169 $html .= '</a>';
170 $html .= '</li>';
171 $html .= '<li>';
172 $html .= '<a class="ultp-next-action">';
173 $html .= ultimate_post()->svg_icon('rightAngle2').'<span class="screen-reader-text">'.__("Next", "ultimate-post").'</span>';
174 $html .= '</a>';
175 $html .= '</li>';
176 $html .= '</ul>';
177 return $html;
178 }
179
180 public function loading(){
181 $html = '';
182 $style = 'style1';
183 $option_data = get_option('ultp_options');
184 if( isset($option_data['preloader_style']) ){
185 $style = $option_data['preloader_style'];
186 }
187 if( $style == 'style2' ){
188 $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
189 } else {
190 $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>';
191 }
192 return '<div class="ultp-loading">'.$html.'</div>';
193 }
194
195 public function filter($filterType = '', $filterCat = '[]', $filterTag = '[]'){
196 $html = '';
197 $html .= '<ul class="ultp-flex-menu">';
198 if ($filterType == 'category') {
199 $cat = $this->taxonomy('category');
200 foreach (json_decode($filterCat) as $val) {
201 $html .= '<li class="filter-item"><a data-taxonomy="'.($val=='all'?'':$val).'" href="#">'.(isset($cat[$val]) ? $cat[$val] : $val).'</a></li>';
202 }
203 } else {
204 $tag = $this->taxonomy('post_tag');
205 foreach (json_decode($filterTag) as $val) {
206 $html .= '<li class="filter-item"><a data-taxonomy="'.($val=='all'?'':$val).'" href="#">'.(isset($tag[$val]) ? $tag[$val] : $val).'</a></li>';
207 }
208 }
209 $html .= '</ul>';
210 return $html;
211 }
212
213 public function svg_icon($icons = 'view'){
214 $icon_lists = array(
215 'eye' => file_get_contents(ULTP_PATH.'assets/img/svg/eye.svg'),
216 'user' => file_get_contents(ULTP_PATH.'assets/img/svg/user.svg'),
217 'calendar' => file_get_contents(ULTP_PATH.'assets/img/svg/calendar.svg'),
218 'comment' => file_get_contents(ULTP_PATH.'assets/img/svg/comment.svg'),
219 'book' => file_get_contents(ULTP_PATH.'assets/img/svg/book.svg'),
220 'tag' => file_get_contents(ULTP_PATH.'assets/img/svg/tag.svg'),
221 'clock' => file_get_contents(ULTP_PATH.'assets/img/svg/clock.svg'),
222 'leftAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle.svg'),
223 'rightAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle.svg'),
224 'leftAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle2.svg'),
225 'rightAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle2.svg'),
226 'leftArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/leftArrowLg.svg'),
227 'refresh' => file_get_contents(ULTP_PATH.'assets/img/svg/refresh.svg'),
228 'rightArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/rightArrowLg.svg'),
229 );
230 return $icon_lists[ $icons ];
231 }
232
233 }
234