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

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