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

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