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

408 lines 17.3 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 if(isset($attr['queryTaxValue'])){
179
180 $tax_value = (strlen($attr['queryTaxValue']) > 2) ? $attr['queryTaxValue'] : ($attr['queryTax'] == 'category' ? $attr['queryCat'] : $attr['queryTag']);
181
182 if(strlen($tax_value) > 2){
183 $var = array('relation'=>'OR');
184 foreach (json_decode($tax_value) as $val) {
185 $tax_name = $attr['queryTax'] == 'tag' ? 'post_tag' : $attr['queryTax']; // for compatibility
186 $var[] = array('taxonomy'=> $tax_name, 'field' => 'slug', 'terms' => $val );
187 }
188 if(count($var) > 1){
189 $query_args['tax_query'] = $var;
190 }
191 }
192 }
193 }
194
195 if(isset($attr['queryQuick'])){
196 if($attr['queryQuick'] != ''){
197 if(function_exists('ultimate_post_pro')){
198 $query_args = ultimate_post_pro()->get_quick_query($attr, $query_args);
199 }
200 }
201 }
202
203 if(isset($attr['queryOffset']) && $attr['queryOffset'] ){
204 if($query_args['paged'] > 1){
205 $offset_post = wp_get_recent_posts($query_args, OBJECT);
206 if( count($offset_post) > 0 ){
207 $offset = array();
208 for($x = count($offset_post); $x > count($offset_post) - $attr['queryOffset']; $x--){
209 $offset[] = $offset_post[$x-1]->ID;
210 }
211 $query_args['post__not_in'] = $offset;
212 }
213 }else{
214 $query_args['offset'] = isset($attr['queryOffset']) ? $attr['queryOffset'] : 0;
215 }
216 }
217
218 $query_args['wpnonce'] = wp_create_nonce( 'ultp-nonce' );
219
220 return $query_args;
221 }
222
223
224 public function get_page_number($attr, $post_number) {
225 if($post_number > 0){
226 $post_per_page = isset($attr['queryNumber']) ? $attr['queryNumber'] : 3;
227 $pages = ceil($post_number/$post_per_page);
228 return $pages ? $pages : 1;
229 }else{
230 return 1;
231 }
232 }
233
234 public function get_image_size() {
235 $sizes = get_intermediate_image_sizes();
236 $filter = array('full' => 'Full');
237 foreach ($sizes as $value) {
238 $filter[$value] = ucwords(str_replace(array('_', '-'), array(' ', ' '), $value));
239 }
240 return $filter;
241 }
242
243
244 public function get_post_type() {
245 $post_type = get_post_types( '', 'names' );
246 return array_diff($post_type, array( 'attachment', 'revision', 'nav_menu_item', 'custom_css', 'customize_changeset', 'oembed_cache', 'user_request', 'wp_block' ));
247 }
248
249
250 // Pagination
251 public function pagination($pages = '', $paginationNav, $range = 1) {
252 $html = '';
253 $showitems = 3;
254 $paged = is_front_page() ? get_query_var('page') : get_query_var('paged');
255 $paged = $paged ? $paged : 1;
256 if($pages == '') {
257 global $wp_query;
258 $pages = $wp_query->max_num_pages;
259 if(!$pages) {
260 $pages = 1;
261 }
262 }
263 $data = ($paged>=3?[($paged-1),$paged,$paged+1]:[1,2,3]);
264
265
266 if(1 != $pages) {
267 $html .= '<ul class="ultp-pagination">';
268 $display_none = 'style="display:none"';
269 if($pages > 4) {
270 $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>';
271 }
272 if($pages > 4){
273 $html .= '<li class="ultp-first-pages" '.($paged<2?$display_none:"").' data-current="1"><a href="'.get_pagenum_link(1).'">1</a></li>';
274 }
275 if($pages > 4){
276 $html .= '<li class="ultp-first-dot" '.($paged<2? $display_none : "").'><a href="#">...</a></li>';
277 }
278 foreach ($data as $i) {
279 if($pages >= $i){
280 $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>';
281 }
282 }
283 if($pages > 4){
284 $html .= '<li class="ultp-last-dot" '.($pages<=$paged+1?$display_none:"").'><a href="#">...</a></li>';
285 }
286 if($pages > 4){
287 $html .= '<li class="ultp-last-pages" '.($pages<=$paged+1?$display_none:"").' data-current="'.$pages.'"><a href="'.get_pagenum_link($pages).'">'.$pages.'</a></li>';
288 }
289 if ($paged != $pages) {
290 $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>';
291 }
292 $html .= '</ul>';
293 }
294 return $html;
295 }
296
297 public function excerpt_word($charlength = 200) {
298 $html = '';
299 $charlength++;
300 $excerpt = get_the_excerpt();
301 if ( mb_strlen( $excerpt ) > $charlength ) {
302 $subex = mb_substr( $excerpt, 0, $charlength - 5 );
303 $exwords = explode( ' ', $subex );
304 $excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
305 if ( $excut < 0 ) {
306 $html = mb_substr( $subex, 0, $excut );
307 } else {
308 $html = $subex;
309 }
310 $html .= '...';
311 } else {
312 $html = $excerpt;
313 }
314 return $html;
315 }
316
317
318 public function taxonomy( $prams = 'category' ) {
319 $data = array();
320 $terms = get_terms( $prams, array(
321 'hide_empty' => true,
322 ));
323 if( !empty($terms) ){
324 foreach ($terms as $val) {
325 $data[$val->slug] = $val->name;
326 }
327 }
328 return $data;
329 }
330
331
332 public function next_prev() {
333 $html = '';
334 $html .= '<ul>';
335 $html .= '<li>';
336 $html .= '<a class="ultp-prev-action ultp-disable" href="#">';
337 $html .= ultimate_post()->svg_icon('leftAngle2').'<span class="screen-reader-text">'.__("Previous", "ultimate-post").'</span>';
338 $html .= '</a>';
339 $html .= '</li>';
340 $html .= '<li>';
341 $html .= '<a class="ultp-next-action">';
342 $html .= ultimate_post()->svg_icon('rightAngle2').'<span class="screen-reader-text">'.__("Next", "ultimate-post").'</span>';
343 $html .= '</a>';
344 $html .= '</li>';
345 $html .= '</ul>';
346 return $html;
347 }
348
349 public function loading(){
350 $html = '';
351 $style = 'style1';
352 $option_data = ultimate_post()->get_setting();
353 if( isset($option_data['preloader_style']) ){
354 $style = $option_data['preloader_style'];
355 }
356 if( $style == 'style2' ){
357 $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
358 } else {
359 $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>';
360 }
361 return '<div class="ultp-loading">'.$html.'</div>';
362 }
363
364 public function filter($filterText = '', $filterType = '', $filterValue = '[]', $filterCat = [], $filterTag = []){
365 $html = '';
366 $html .= '<ul class="ultp-flex-menu">';
367
368 $filterType = $filterType == 'tag' ? 'post_tag' : $filterType; // for compatibility
369
370 $cat = $this->taxonomy($filterType);
371 if($filterText){
372 $html .= '<li class="filter-item"><a data-taxonomy="" href="#">'.$filterText.'</a></li>';
373 }
374
375 $filterValue = strlen($filterValue) > 2 ? $filterValue : ($filterType == 'category' ? $filterCat : $filterTag);
376
377 foreach (json_decode($filterValue) as $val) {
378 $html .= '<li class="filter-item"><a data-taxonomy="'.$val.'" href="#">'.(isset($cat[$val]) ? $cat[$val] : $val).'</a></li>';
379 }
380 $html .= '</ul>';
381 return $html;
382 }
383
384 public function svg_icon($icons = ''){
385
386 $icon_lists = array(
387 'eye' => file_get_contents(ULTP_PATH.'assets/img/svg/eye.svg'),
388 'user' => file_get_contents(ULTP_PATH.'assets/img/svg/user.svg'),
389 'calendar' => file_get_contents(ULTP_PATH.'assets/img/svg/calendar.svg'),
390 'comment' => file_get_contents(ULTP_PATH.'assets/img/svg/comment.svg'),
391 'book' => file_get_contents(ULTP_PATH.'assets/img/svg/book.svg'),
392 'tag' => file_get_contents(ULTP_PATH.'assets/img/svg/tag.svg'),
393 'clock' => file_get_contents(ULTP_PATH.'assets/img/svg/clock.svg'),
394 'leftAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle.svg'),
395 'rightAngle' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle.svg'),
396 'leftAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/leftAngle2.svg'),
397 'rightAngle2' => file_get_contents(ULTP_PATH.'assets/img/svg/rightAngle2.svg'),
398 'leftArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/leftArrowLg.svg'),
399 'refresh' => file_get_contents(ULTP_PATH.'assets/img/svg/refresh.svg'),
400 'rightArrowLg' => file_get_contents(ULTP_PATH.'assets/img/svg/rightArrowLg.svg'),
401 );
402 if($icons){
403 return $icon_lists[ $icons ];
404 }
405 }
406
407 }
408