| 1 |
<?php |
| 2 |
namespace Enteraddons\Classes; |
| 3 |
|
| 4 |
/** |
| 5 |
* Enteraddons helper class |
| 6 |
* |
| 7 |
* @package Enteraddons |
| 8 |
* @author ThemeLooks |
| 9 |
* @copyright 2022 ThemeLooks |
| 10 |
* @license GPL-2.0-or-later |
| 11 |
* |
| 12 |
* |
| 13 |
*/ |
| 14 |
|
| 15 |
class Helper { |
| 16 |
|
| 17 |
public static function ratingStar( $rating, $echo = true ) { |
| 18 |
|
| 19 |
$starRating = ''; |
| 20 |
|
| 21 |
$j = 0; |
| 22 |
|
| 23 |
for( $i = 0; $i <= 4; $i++ ) { |
| 24 |
$j++; |
| 25 |
|
| 26 |
if( $rating >= $j || $rating == '5' ) { |
| 27 |
$starRating .= '<i class="fas fa-star"></i>'; |
| 28 |
}elseif( $rating < $j && $rating > $i ) { |
| 29 |
$starRating .= '<i class="fas fa-star-half-alt"></i>'; |
| 30 |
} else { |
| 31 |
$starRating .= '<i class="far fa-star"></i>'; |
| 32 |
} |
| 33 |
|
| 34 |
} |
| 35 |
// |
| 36 |
if( $echo == true ) { |
| 37 |
echo wp_kses( $starRating, [ 'i' => ['class' => [] ] ] ); |
| 38 |
} else { |
| 39 |
return $starRating; |
| 40 |
} |
| 41 |
|
| 42 |
} |
| 43 |
|
| 44 |
public static function includeCurrentPathFile( $path, $fileName ) { |
| 45 |
|
| 46 |
if( !is_array( $fileName ) ) { |
| 47 |
require_once( plugin_dir_path( $path ).$fileName ); |
| 48 |
} else { |
| 49 |
foreach( $fileName as $name ) { |
| 50 |
require_once( plugin_dir_path( $path ).$name ); |
| 51 |
} |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
public static function getElementorIcon( $optionValue ) { |
| 56 |
if( empty( $optionValue ) ) { |
| 57 |
return; |
| 58 |
} |
| 59 |
// |
| 60 |
if( 'svg' != $optionValue['library'] ) { |
| 61 |
if( !empty( $optionValue['value'] ) ) { |
| 62 |
return '<i class="'.esc_attr( $optionValue['value'] ).'" /></i>'; |
| 63 |
} |
| 64 |
} else { |
| 65 |
return '<img src="'.esc_url( $optionValue['value']['url'] ).'" />'; |
| 66 |
} |
| 67 |
|
| 68 |
} |
| 69 |
|
| 70 |
public static function getElementorLinkHandler( $url, $innerData, $class= 'anchor--link' ) { |
| 71 |
// |
| 72 |
if( !empty( $url['url'] ) ) { |
| 73 |
$target = '_self'; |
| 74 |
if( !empty( $url['is_external'] ) && $url['is_external'] == 'on' ) { |
| 75 |
$target = '_blank'; |
| 76 |
} |
| 77 |
|
| 78 |
// |
| 79 |
$addNofollow = ''; |
| 80 |
|
| 81 |
if( !empty( $url['nofollow'] ) ) { |
| 82 |
$addNofollow = 'rel="nofollow"'; |
| 83 |
} |
| 84 |
|
| 85 |
return '<a class="'.esc_attr($class).'" href="'.esc_url( $url['url'] ).'" '. $addNofollow.' target="'.esc_attr( $target ).'">'.self::allowFormattingTagHtml( $innerData ).'</a>'; |
| 86 |
} |
| 87 |
} |
| 88 |
/** |
| 89 |
* allowFormattingTagHtml |
| 90 |
* |
| 91 |
* @param string $text |
| 92 |
* @return void |
| 93 |
*/ |
| 94 |
public static function allowFormattingTagHtml( $text = '' ) { |
| 95 |
|
| 96 |
if( empty( $text ) ) { |
| 97 |
return; |
| 98 |
} |
| 99 |
|
| 100 |
$allowHtml = [ |
| 101 |
'span' => ['class' => [],'style' => []], |
| 102 |
'b' => [], |
| 103 |
'strong' => [], |
| 104 |
'br' => [], |
| 105 |
'i' => ['class' => []], |
| 106 |
'svg' => [], |
| 107 |
'small' => [], |
| 108 |
'img' => ['src'=>[],'class' => []] |
| 109 |
]; |
| 110 |
|
| 111 |
return wp_kses( $text, $allowHtml ); |
| 112 |
} |
| 113 |
/** |
| 114 |
* currency list |
| 115 |
* @return array |
| 116 |
*/ |
| 117 |
public static function getCurrencyList() { |
| 118 |
return [ |
| 119 |
'' => esc_html__( 'None', 'enteraddons' ), |
| 120 |
'baht' => '฿ ' . esc_html__( 'Baht', 'enteraddons' ), |
| 121 |
'bdt' => '৳ ' . esc_html__( 'BD Taka', 'enteraddons' ), |
| 122 |
'dollar' => '$ ' . esc_html__( 'Dollar', 'enteraddons' ), |
| 123 |
'euro' => '€ ' . esc_html__( 'Euro', 'enteraddons' ), |
| 124 |
'franc' => '₣ ' . esc_html__( 'Franc', 'enteraddons' ), |
| 125 |
'guilder' => 'ƒ ' . esc_html__( 'Guilder', 'enteraddons' ), |
| 126 |
'indian_rupee' => '₹ ' . esc_html__( 'Rupee (Indian)', 'enteraddons' ), |
| 127 |
'krona' => 'kr ' . esc_html__( 'Krona', 'enteraddons' ), |
| 128 |
'lira' => '₤ ' . esc_html__( 'Lira', 'enteraddons' ), |
| 129 |
'peseta' => '₧ ' . esc_html__( 'Peseta', 'enteraddons' ), |
| 130 |
'peso' => '₱ ' . esc_html__( 'Peso', 'enteraddons' ), |
| 131 |
'pound' => '£ ' . esc_html__( 'Pound Sterling', 'enteraddons' ), |
| 132 |
'real' => 'R$ ' . esc_html__( 'Real', 'enteraddons' ), |
| 133 |
'ruble' => '₽ ' . esc_html__( 'Ruble', 'enteraddons' ), |
| 134 |
'rupee' => '₨ ' . esc_html__( 'Rupee', 'enteraddons' ), |
| 135 |
'shekel' => '₪ ' . esc_html__( 'Shekel', 'enteraddons' ), |
| 136 |
'yen' => '¥ ' . esc_html__( 'Yen/Yuan', 'enteraddons' ), |
| 137 |
'won' => '₩ ' . esc_html__( 'Won', 'enteraddons' ), |
| 138 |
'custom' => esc_html__( 'Custom', 'enteraddons' ), |
| 139 |
]; |
| 140 |
} |
| 141 |
|
| 142 |
public static function getCurrencySymbol( $symbol_code ) { |
| 143 |
|
| 144 |
$symbolList = [ |
| 145 |
'baht' => '฿', |
| 146 |
'bdt' => '৳', |
| 147 |
'dollar' => '$', |
| 148 |
'euro' => '€', |
| 149 |
'franc' => '₣', |
| 150 |
'guilder' => 'ƒ', |
| 151 |
'indian_rupee' => '₹', |
| 152 |
'krona' => 'kr', |
| 153 |
'lira' => '₤', |
| 154 |
'peseta' => '₧', |
| 155 |
'peso' => '₱', |
| 156 |
'pound' => '£', |
| 157 |
'real' => 'R$', |
| 158 |
'ruble' => '₽', |
| 159 |
'rupee' => '₨', |
| 160 |
'shekel' => '₪', |
| 161 |
'yen' => '¥', |
| 162 |
'won' => '₩', |
| 163 |
]; |
| 164 |
|
| 165 |
return !empty( $symbolList[$symbol_code] ) ? $symbolList[$symbol_code] : ''; |
| 166 |
|
| 167 |
} |
| 168 |
/** |
| 169 |
* enteraddons_elementor |
| 170 |
* @return void |
| 171 |
*/ |
| 172 |
public static function enteraddons_elementor() { |
| 173 |
return \Elementor\Plugin::instance(); |
| 174 |
} |
| 175 |
/** |
| 176 |
* is_elementor_edit_mode |
| 177 |
* @return boolean |
| 178 |
*/ |
| 179 |
public static function is_elementor_edit_mode() { |
| 180 |
$elementor = self::enteraddons_elementor(); |
| 181 |
return $elementor->editor->is_edit_mode() || $elementor->preview->is_preview_mode() || is_preview(); |
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* |
| 186 |
* Check WooCommerce plugin activities |
| 187 |
* |
| 188 |
* @return string |
| 189 |
* |
| 190 |
*/ |
| 191 |
public static function is_woo_activated() { |
| 192 |
$isWoo = false; |
| 193 |
if( class_exists( 'woocommerce' ) ) { |
| 194 |
$isWoo = true; |
| 195 |
} |
| 196 |
return $isWoo; |
| 197 |
} |
| 198 |
/** |
| 199 |
* Change editor js folder permissions mode to work properly |
| 200 |
* @return void |
| 201 |
* |
| 202 |
*/ |
| 203 |
public static function change_permissions_mode() { |
| 204 |
|
| 205 |
$dir = ENTERADDONS_DIR_CORE.'libs/editor/js'; |
| 206 |
if( !chmod($dir,0777) ) { |
| 207 |
chmod($dir,0777); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
/** |
| 212 |
* [elementor_content_display description] |
| 213 |
* @param [type] $contentId [description] |
| 214 |
* @return [type] [description] |
| 215 |
*/ |
| 216 |
public static function elementor_content_display( $contentId = '' ) { |
| 217 |
|
| 218 |
if( !self::is_elementor_edit_mode() ) { |
| 219 |
global $ea_cache_dir_url, $ea_cache_file_prefix; |
| 220 |
// |
| 221 |
$handle = $ea_cache_file_prefix.$contentId; |
| 222 |
$url = $ea_cache_dir_url.$handle.'.css'; |
| 223 |
$version = ENTERADDONS_VERSION.'.'.get_post_modified_time( 'U', false, $contentId, false ); |
| 224 |
|
| 225 |
// Enqueue Header Widget Css for Front-End |
| 226 |
wp_enqueue_style( $handle, $url, array('elementor-frontend'), $version, false ); |
| 227 |
} |
| 228 |
//wp_enqueue_style( 'enteraddons-'.$contentId ); |
| 229 |
return \Elementor\Plugin::$instance->frontend->get_builder_content_for_display( $contentId ); |
| 230 |
} |
| 231 |
|
| 232 |
/** |
| 233 |
* [menu_list description] |
| 234 |
* @return [type] [description] |
| 235 |
*/ |
| 236 |
public static function menu_list(){ |
| 237 |
$siteMenu = wp_get_nav_menus(); |
| 238 |
$getMenu = []; |
| 239 |
$getMenu[''] = esc_html__( 'Select A Menu','enteraddons' ); |
| 240 |
foreach( $siteMenu as $menu ) { |
| 241 |
$getMenu[ $menu->slug ] = $menu->name; |
| 242 |
} |
| 243 |
return $getMenu; |
| 244 |
} |
| 245 |
|
| 246 |
public static function is_pro_active() { |
| 247 |
return apply_filters( 'enteraddons_is_pro', false ); |
| 248 |
} |
| 249 |
|
| 250 |
public static function getPages() { |
| 251 |
return get_pages(); |
| 252 |
} |
| 253 |
|
| 254 |
public static function getPagesIdTitle() { |
| 255 |
$pages = self::getPages(); |
| 256 |
$getList = []; |
| 257 |
if( !empty( $pages ) ) { |
| 258 |
foreach( $pages as $page ) { |
| 259 |
$getList[$page->ID] = $page->post_title; |
| 260 |
} |
| 261 |
} |
| 262 |
return $getList; |
| 263 |
} |
| 264 |
|
| 265 |
public static function checkPhpV81() { |
| 266 |
$b = version_compare( ENTERADDONS_CURRENT_PHPVERSION, '8.0.99', '>' ); |
| 267 |
$l = version_compare( ENTERADDONS_CURRENT_PHPVERSION, '8.2', '<' ); |
| 268 |
|
| 269 |
if( $b && $l ) { |
| 270 |
return true; |
| 271 |
} else { |
| 272 |
return false; |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
public static function getElementorTemplates() { |
| 277 |
|
| 278 |
$args = array( |
| 279 |
'post_type' => 'elementor_library', |
| 280 |
'numberposts' => '-1', |
| 281 |
'post_status' => 'publish' |
| 282 |
); |
| 283 |
|
| 284 |
$elementor_templates = get_posts($args); |
| 285 |
$templates = []; |
| 286 |
|
| 287 |
foreach ( $elementor_templates as $template ) { |
| 288 |
$templates[$template->ID] = $template->post_title; |
| 289 |
} |
| 290 |
|
| 291 |
return $templates; |
| 292 |
} |
| 293 |
|
| 294 |
public static function versionType() { |
| 295 |
return self::is_pro_active() ? 'PRO' : 'LITE'; |
| 296 |
} |
| 297 |
|
| 298 |
public static function ea_brand_icon_html() { |
| 299 |
return '<i style="float: right;font-size: 16px;color: #E82A5C;" class="entera entera-ea-fev"></i>'; |
| 300 |
} |
| 301 |
|
| 302 |
public static function ea_post_categoris() { |
| 303 |
|
| 304 |
$terms = get_terms( [ 'taxonomy' => 'category', 'hide_empty' => true ] ); |
| 305 |
|
| 306 |
$getTerms = []; |
| 307 |
if( !empty( $terms ) ) { |
| 308 |
foreach( $terms as $term ) { |
| 309 |
$getTerms[$term->term_id] = $term->name; |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
return $getTerms; |
| 314 |
|
| 315 |
} |
| 316 |
|
| 317 |
public static function ea_ai_models_html() { |
| 318 |
|
| 319 |
$html = '<option selected value="EA-AI EA1">'.esc_html__( 'EA-AI EA1', 'enteraddons' ).'</option>'; |
| 320 |
return apply_filters( 'ea_ai_models_html', $html ); |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
} // Class End |