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