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

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