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

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