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

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