controls
1 year ago
pa-display-conditions
1 year ago
templates
1 year ago
acf-helper.php
1 year ago
addons-cross-cp.php
1 year ago
addons-integration.php
1 year ago
assets-manager.php
1 year ago
class-pa-core.php
1 year ago
class-premium-template-tags.php
1 year ago
helper-functions.php
1 year ago
live-editor-modal.php
1 year ago
module-base.php
1 year ago
pa-nav-menu-walker.php
1 year ago
helper-functions.php
1677 lines
| 1 | <?php |
| 2 | /** |
| 3 | * PA Helper Functions. |
| 4 | */ |
| 5 | |
| 6 | namespace PremiumAddons\Includes; |
| 7 | |
| 8 | // Premium Addons Pro Classes. |
| 9 | use PremiumAddonsPro\Includes\White_Label\Helper; |
| 10 | |
| 11 | // Elementor Classes. |
| 12 | use Elementor\Core\Settings\Manager as SettingsManager; |
| 13 | use Elementor\Plugin; |
| 14 | use Elementor\Controls_Manager; |
| 15 | |
| 16 | if ( ! defined( 'ABSPATH' ) ) { |
| 17 | exit; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Class Helper_Functions. |
| 22 | */ |
| 23 | class Helper_Functions { |
| 24 | |
| 25 | /** |
| 26 | * A list of safe tage for `validate_html_tag` method. |
| 27 | */ |
| 28 | const ALLOWED_HTML_WRAPPER_TAGS = array( |
| 29 | 'article', |
| 30 | 'aside', |
| 31 | 'div', |
| 32 | 'footer', |
| 33 | 'h1', |
| 34 | 'h2', |
| 35 | 'h3', |
| 36 | 'h4', |
| 37 | 'h5', |
| 38 | 'h6', |
| 39 | 'header', |
| 40 | 'main', |
| 41 | 'nav', |
| 42 | 'p', |
| 43 | 'section', |
| 44 | 'span', |
| 45 | ); |
| 46 | |
| 47 | /** |
| 48 | * Theme |
| 49 | * |
| 50 | * @var theme |
| 51 | */ |
| 52 | private static $current_theme = null; |
| 53 | |
| 54 | /** |
| 55 | * Google maps prefixes |
| 56 | * |
| 57 | * @var google_localize |
| 58 | */ |
| 59 | private static $google_localize = null; |
| 60 | |
| 61 | /** |
| 62 | * SVG Shapes |
| 63 | * |
| 64 | * @var shapes |
| 65 | */ |
| 66 | private static $shapes = null; |
| 67 | |
| 68 | /** |
| 69 | * WP lang prefixes |
| 70 | * |
| 71 | * @var lang_locales |
| 72 | */ |
| 73 | private static $lang_locales = null; |
| 74 | |
| 75 | /** |
| 76 | * Script debug enabled |
| 77 | * |
| 78 | * @var script_debug |
| 79 | */ |
| 80 | private static $script_debug = null; |
| 81 | |
| 82 | /** |
| 83 | * JS scripts directory |
| 84 | * |
| 85 | * @var js_dir |
| 86 | */ |
| 87 | private static $js_dir = null; |
| 88 | |
| 89 | /** |
| 90 | * CSS fiels directory |
| 91 | * |
| 92 | * @var js_dir |
| 93 | */ |
| 94 | private static $css_dir = null; |
| 95 | |
| 96 | /** |
| 97 | * JS Suffix |
| 98 | * |
| 99 | * @var js_suffix |
| 100 | */ |
| 101 | private static $assets_suffix = null; |
| 102 | |
| 103 | /** |
| 104 | * Get Icon SVG Data |
| 105 | * |
| 106 | * @since 4.10.72 |
| 107 | * @access private |
| 108 | * |
| 109 | * @return array icon data. |
| 110 | */ |
| 111 | private static function get_icon_svg_data( $icon ) { |
| 112 | |
| 113 | preg_match( '/fa(.*) fa-/', $icon['value'], $icon_name_matches ); |
| 114 | |
| 115 | $icon_name = str_replace( $icon_name_matches[0], '', $icon['value'] ); |
| 116 | |
| 117 | $icon_key = str_replace( ' fa-', '-', $icon['value'] ); |
| 118 | |
| 119 | $icon_file_name = str_replace( 'fa-', '', $icon['library'] ); |
| 120 | |
| 121 | $path = ELEMENTOR_ASSETS_PATH . 'lib/font-awesome/json/' . $icon_file_name . '.json'; |
| 122 | |
| 123 | $data = file_get_contents( $path ); |
| 124 | |
| 125 | $data = json_decode( $data, true ); |
| 126 | |
| 127 | $svg_data = $data['icons'][ $icon_name ]; |
| 128 | |
| 129 | return array( |
| 130 | 'width' => $svg_data[0], |
| 131 | 'height' => $svg_data[1], |
| 132 | 'path' => $svg_data[4], |
| 133 | ); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Check if white labeling - Free version author field is set |
| 138 | * |
| 139 | * @since 1.0.0 |
| 140 | * @access public |
| 141 | * |
| 142 | * @return string |
| 143 | */ |
| 144 | public static function author() { |
| 145 | |
| 146 | $author_free = 'Leap13'; |
| 147 | |
| 148 | if ( self::check_papro_version() ) { |
| 149 | |
| 150 | $white_label = Helper::get_white_labeling_settings(); |
| 151 | |
| 152 | $author_free = $white_label['premium-wht-lbl-name']; |
| 153 | |
| 154 | } |
| 155 | |
| 156 | return '' !== $author_free ? $author_free : 'Leap13'; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Check if white labeling - Free version name field is set |
| 161 | * |
| 162 | * @since 1.0.0 |
| 163 | * @access public |
| 164 | * |
| 165 | * @return string |
| 166 | */ |
| 167 | public static function name() { |
| 168 | |
| 169 | $name_free = 'Premium Addons for Elementor'; |
| 170 | |
| 171 | if ( self::check_papro_version() ) { |
| 172 | |
| 173 | $white_label = Helper::get_white_labeling_settings(); |
| 174 | |
| 175 | $name_free = $white_label['premium-wht-lbl-plugin-name']; |
| 176 | |
| 177 | } |
| 178 | |
| 179 | return '' !== $name_free ? $name_free : 'Premium Addons for Elementor'; |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Check if white labeling - Hide row meta option is checked |
| 184 | * |
| 185 | * @since 1.0.0 |
| 186 | * @return boolean |
| 187 | */ |
| 188 | public static function is_hide_row_meta() { |
| 189 | |
| 190 | $hide_meta = false; |
| 191 | |
| 192 | if ( self::check_papro_version() ) { |
| 193 | |
| 194 | $white_label = Helper::get_white_labeling_settings(); |
| 195 | |
| 196 | $hide_meta = $white_label['premium-wht-lbl-row']; |
| 197 | |
| 198 | } |
| 199 | |
| 200 | return $hide_meta; |
| 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Check if white labeling - Hide plugin logo option is checked |
| 205 | * |
| 206 | * @since 1.0.0 |
| 207 | * @access public |
| 208 | * |
| 209 | * @return boolean |
| 210 | */ |
| 211 | public static function is_hide_logo() { |
| 212 | |
| 213 | if ( self::check_papro_version() ) { |
| 214 | |
| 215 | if ( isset( get_option( 'pa_wht_lbl_save_settings' )['premium-wht-lbl-logo'] ) ) { |
| 216 | |
| 217 | $hide_logo = get_option( 'pa_wht_lbl_save_settings' )['premium-wht-lbl-logo']; |
| 218 | |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | return isset( $hide_logo ) ? $hide_logo : false; |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Get White Labeling - Widgets Category string |
| 227 | * |
| 228 | * @since 1.0.0 |
| 229 | * @access public |
| 230 | * |
| 231 | * @return string |
| 232 | */ |
| 233 | public static function get_category() { |
| 234 | |
| 235 | $category = __( 'Premium Addons', 'premium-addons-for-elementor' ); |
| 236 | |
| 237 | if ( self::check_papro_version() ) { |
| 238 | |
| 239 | $white_label = Helper::get_white_labeling_settings(); |
| 240 | |
| 241 | $category = $white_label['premium-wht-lbl-short-name']; |
| 242 | |
| 243 | } |
| 244 | |
| 245 | return '' !== $category ? $category : __( 'Premium Addons', 'premium-addons-for-elementor' ); |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Get White Labeling - Widgets Prefix string |
| 250 | * |
| 251 | * @since 1.0.0 |
| 252 | * @access public |
| 253 | * |
| 254 | * @return string |
| 255 | */ |
| 256 | public static function get_prefix() { |
| 257 | |
| 258 | $prefix = __( 'Premium', 'premium-addons-for-elementor' ); |
| 259 | |
| 260 | if ( self::check_papro_version() ) { |
| 261 | |
| 262 | $white_label = Helper::get_white_labeling_settings(); |
| 263 | |
| 264 | $prefix = $white_label['premium-wht-lbl-prefix']; |
| 265 | |
| 266 | } |
| 267 | |
| 268 | return '' !== $prefix ? $prefix : __( 'Premium', 'premium-addons-for-elementor' ); |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Check if white labeling - Future notification checked |
| 273 | * |
| 274 | * @since 1.0.0 |
| 275 | * @return boolean |
| 276 | */ |
| 277 | public static function check_hide_notifications() { |
| 278 | |
| 279 | if ( self::check_papro_version() ) { |
| 280 | |
| 281 | $white_label = Helper::get_white_labeling_settings(); |
| 282 | |
| 283 | $hide_notification = isset( $white_label['premium-wht-lbl-not'] ) ? $white_label['premium-wht-lbl-not'] : false; |
| 284 | |
| 285 | } |
| 286 | |
| 287 | return isset( $hide_notification ) ? $hide_notification : false; |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Get White Labeling - Widgets Badge string |
| 292 | * |
| 293 | * @since 1.0.0 |
| 294 | * @access public |
| 295 | * |
| 296 | * @return string |
| 297 | */ |
| 298 | public static function get_badge() { |
| 299 | |
| 300 | $badge = 'PA'; |
| 301 | |
| 302 | if ( self::check_papro_version() ) { |
| 303 | |
| 304 | $white_label = Helper::get_white_labeling_settings(); |
| 305 | |
| 306 | $badge = $white_label['premium-wht-lbl-badge']; |
| 307 | |
| 308 | } |
| 309 | |
| 310 | return '' !== $badge ? $badge : 'PA'; |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * Get Google Maps localization prefixes |
| 315 | * |
| 316 | * @since 1.0.0 |
| 317 | * @access public |
| 318 | * |
| 319 | * @return array |
| 320 | */ |
| 321 | public static function get_google_maps_prefixes() { |
| 322 | |
| 323 | if ( null === self::$google_localize ) { |
| 324 | |
| 325 | self::$google_localize = array( |
| 326 | 'ar' => __( 'Arabic', 'premium-addons-for-elementor' ), |
| 327 | 'eu' => __( 'Basque', 'premium-addons-for-elementor' ), |
| 328 | 'bg' => __( 'Bulgarian', 'premium-addons-for-elementor' ), |
| 329 | 'bn' => __( 'Bengali', 'premium-addons-for-elementor' ), |
| 330 | 'ca' => __( 'Catalan', 'premium-addons-for-elementor' ), |
| 331 | 'cs' => __( 'Czech', 'premium-addons-for-elementor' ), |
| 332 | 'da' => __( 'Danish', 'premium-addons-for-elementor' ), |
| 333 | 'de' => __( 'German', 'premium-addons-for-elementor' ), |
| 334 | 'el' => __( 'Greek', 'premium-addons-for-elementor' ), |
| 335 | 'en' => __( 'English', 'premium-addons-for-elementor' ), |
| 336 | 'en-AU' => __( 'English (australian)', 'premium-addons-for-elementor' ), |
| 337 | 'en-GB' => __( 'English (great britain)', 'premium-addons-for-elementor' ), |
| 338 | 'es' => __( 'Spanish', 'premium-addons-for-elementor' ), |
| 339 | 'fa' => __( 'Farsi', 'premium-addons-for-elementor' ), |
| 340 | 'fi' => __( 'Finnish', 'premium-addons-for-elementor' ), |
| 341 | 'fil' => __( 'Filipino', 'premium-addons-for-elementor' ), |
| 342 | 'fr' => __( 'French', 'premium-addons-for-elementor' ), |
| 343 | 'gl' => __( 'Galician', 'premium-addons-for-elementor' ), |
| 344 | 'gu' => __( 'Gujarati', 'premium-addons-for-elementor' ), |
| 345 | 'hi' => __( 'Hindi', 'premium-addons-for-elementor' ), |
| 346 | 'hr' => __( 'Croatian', 'premium-addons-for-elementor' ), |
| 347 | 'hu' => __( 'Hungarian', 'premium-addons-for-elementor' ), |
| 348 | 'id' => __( 'Indonesian', 'premium-addons-for-elementor' ), |
| 349 | 'it' => __( 'Italian', 'premium-addons-for-elementor' ), |
| 350 | 'iw' => __( 'Hebrew', 'premium-addons-for-elementor' ), |
| 351 | 'ja' => __( 'Japanese', 'premium-addons-for-elementor' ), |
| 352 | 'kn' => __( 'Kannada', 'premium-addons-for-elementor' ), |
| 353 | 'ko' => __( 'Korean', 'premium-addons-for-elementor' ), |
| 354 | 'lt' => __( 'Lithuanian', 'premium-addons-for-elementor' ), |
| 355 | 'lv' => __( 'Latvian', 'premium-addons-for-elementor' ), |
| 356 | 'ml' => __( 'Malayalam', 'premium-addons-for-elementor' ), |
| 357 | 'mr' => __( 'Marathi', 'premium-addons-for-elementor' ), |
| 358 | 'nl' => __( 'Dutch', 'premium-addons-for-elementor' ), |
| 359 | 'no' => __( 'Norwegian', 'premium-addons-for-elementor' ), |
| 360 | 'pl' => __( 'Polish', 'premium-addons-for-elementor' ), |
| 361 | 'pt' => __( 'Portuguese', 'premium-addons-for-elementor' ), |
| 362 | 'pt-BR' => __( 'Portuguese (brazil)', 'premium-addons-for-elementor' ), |
| 363 | 'pt-PT' => __( 'Portuguese (portugal)', 'premium-addons-for-elementor' ), |
| 364 | 'ro' => __( 'Romanian', 'premium-addons-for-elementor' ), |
| 365 | 'ru' => __( 'Russian', 'premium-addons-for-elementor' ), |
| 366 | 'sk' => __( 'Slovak', 'premium-addons-for-elementor' ), |
| 367 | 'sl' => __( 'Slovenian', 'premium-addons-for-elementor' ), |
| 368 | 'sr' => __( 'Serbian', 'premium-addons-for-elementor' ), |
| 369 | 'sv' => __( 'Swedish', 'premium-addons-for-elementor' ), |
| 370 | 'tl' => __( 'Tagalog', 'premium-addons-for-elementor' ), |
| 371 | 'ta' => __( 'Tamil', 'premium-addons-for-elementor' ), |
| 372 | 'te' => __( 'Telugu', 'premium-addons-for-elementor' ), |
| 373 | 'th' => __( 'Thai', 'premium-addons-for-elementor' ), |
| 374 | 'tr' => __( 'Turkish', 'premium-addons-for-elementor' ), |
| 375 | 'uk' => __( 'Ukrainian', 'premium-addons-for-elementor' ), |
| 376 | 'vi' => __( 'Vietnamese', 'premium-addons-for-elementor' ), |
| 377 | 'zh-CN' => __( 'Chinese (simplified)', 'premium-addons-for-elementor' ), |
| 378 | 'zh-TW' => __( 'Chinese (traditional)', 'premium-addons-for-elementor' ), |
| 379 | ); |
| 380 | } |
| 381 | |
| 382 | return self::$google_localize; |
| 383 | } |
| 384 | |
| 385 | /** |
| 386 | * Checks if a plugin is installed |
| 387 | * |
| 388 | * @since 1.0.0 |
| 389 | * @access public |
| 390 | * |
| 391 | * @param string $plugin_path plugin path. |
| 392 | * |
| 393 | * @return boolean |
| 394 | */ |
| 395 | public static function is_plugin_installed( $plugin_path ) { |
| 396 | |
| 397 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 398 | |
| 399 | $plugins = get_plugins(); |
| 400 | |
| 401 | return isset( $plugins[ $plugin_path ] ); |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * Check Plugin Active |
| 406 | * |
| 407 | * @since 4.2.5 |
| 408 | * @access public |
| 409 | * |
| 410 | * @param string $slug plugin slug. |
| 411 | * |
| 412 | * @return boolean $is_active plugin active. |
| 413 | */ |
| 414 | public static function check_plugin_active( $slug = '' ) { |
| 415 | |
| 416 | include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 417 | |
| 418 | $is_active = in_array( $slug, (array) get_option( 'active_plugins', array() ), true ); |
| 419 | |
| 420 | return $is_active; |
| 421 | } |
| 422 | |
| 423 | /** |
| 424 | * Check if script debug mode enabled. |
| 425 | * |
| 426 | * @since 3.11.1 |
| 427 | * @access public |
| 428 | * |
| 429 | * @return boolean is debug mode enabled |
| 430 | */ |
| 431 | public static function is_debug_enabled() { |
| 432 | |
| 433 | if ( null === self::$script_debug ) { |
| 434 | |
| 435 | self::$script_debug = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG; |
| 436 | } |
| 437 | |
| 438 | return self::$script_debug; |
| 439 | } |
| 440 | |
| 441 | /** |
| 442 | * Get scripts dir. |
| 443 | * |
| 444 | * @access public |
| 445 | * |
| 446 | * @return string JS scripts directory. |
| 447 | */ |
| 448 | public static function get_scripts_dir() { |
| 449 | |
| 450 | if ( null === self::$js_dir ) { |
| 451 | |
| 452 | self::$js_dir = self::is_debug_enabled() ? 'js' : 'min-js'; |
| 453 | } |
| 454 | |
| 455 | return self::$js_dir; |
| 456 | } |
| 457 | |
| 458 | /** |
| 459 | * Get styles dir. |
| 460 | * |
| 461 | * @access public |
| 462 | * |
| 463 | * @return string CSS files directory. |
| 464 | */ |
| 465 | public static function get_styles_dir() { |
| 466 | |
| 467 | if ( null === self::$css_dir ) { |
| 468 | |
| 469 | self::$css_dir = self::is_debug_enabled() ? 'css' : 'min-css'; |
| 470 | } |
| 471 | |
| 472 | return self::$css_dir; |
| 473 | } |
| 474 | |
| 475 | /** |
| 476 | * Get assets suffix. |
| 477 | * |
| 478 | * @access public |
| 479 | * |
| 480 | * @return string JS scripts suffix. |
| 481 | */ |
| 482 | public static function get_assets_suffix() { |
| 483 | |
| 484 | if ( null === self::$assets_suffix ) { |
| 485 | |
| 486 | self::$assets_suffix = self::is_debug_enabled() ? '' : '.min'; |
| 487 | } |
| 488 | |
| 489 | return self::$assets_suffix; |
| 490 | } |
| 491 | |
| 492 | /** |
| 493 | * Get Installed Theme |
| 494 | * |
| 495 | * Returns the active theme slug |
| 496 | * |
| 497 | * @access public |
| 498 | * |
| 499 | * @return string theme slug |
| 500 | */ |
| 501 | public static function get_installed_theme() { |
| 502 | |
| 503 | if ( null === self::$current_theme ) { |
| 504 | |
| 505 | $theme = wp_get_theme(); |
| 506 | |
| 507 | if ( $theme->parent() ) { |
| 508 | |
| 509 | $theme_name = sanitize_key( $theme->parent()->get( 'Name' ) ); |
| 510 | |
| 511 | } else { |
| 512 | |
| 513 | $theme_name = $theme->get( 'Name' ); |
| 514 | |
| 515 | $theme_name = sanitize_key( $theme_name ); |
| 516 | |
| 517 | } |
| 518 | |
| 519 | self::$current_theme = $theme_name; |
| 520 | |
| 521 | } |
| 522 | |
| 523 | return self::$current_theme; |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * Get Vimeo Video Data |
| 528 | * |
| 529 | * Get video data using Vimeo API |
| 530 | * |
| 531 | * @since 3.11.4 |
| 532 | * @access public |
| 533 | * |
| 534 | * @param string $video_id video ID. |
| 535 | */ |
| 536 | public static function get_vimeo_video_data( $video_id ) { |
| 537 | |
| 538 | $vimeo_data = wp_remote_get( 'http://www.vimeo.com/api/v2/video/' . intval( $video_id ) . '.php' ); |
| 539 | |
| 540 | if ( is_wp_error( $vimeo_data ) ) { |
| 541 | return false; |
| 542 | } |
| 543 | |
| 544 | if ( isset( $vimeo_data['response']['code'] ) ) { |
| 545 | |
| 546 | if ( 200 === $vimeo_data['response']['code'] ) { |
| 547 | |
| 548 | $response = maybe_unserialize( $vimeo_data['body'] ); |
| 549 | $thumbnail = isset( $response[0]['thumbnail_large'] ) ? $response[0]['thumbnail_large'] : false; |
| 550 | |
| 551 | $data = array( |
| 552 | 'src' => $thumbnail, |
| 553 | 'url' => $response[0]['user_url'], |
| 554 | 'portrait' => $response[0]['user_portrait_huge'], |
| 555 | 'title' => $response[0]['title'], |
| 556 | 'user' => $response[0]['user_name'], |
| 557 | ); |
| 558 | |
| 559 | return $data; |
| 560 | |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | return false; |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * Get Video Thumbnail |
| 569 | * |
| 570 | * Get thumbnail URL for embed or self hosted |
| 571 | * |
| 572 | * @since 3.7.0 |
| 573 | * @access public |
| 574 | * |
| 575 | * @param string $video_id video ID. |
| 576 | * @param string $type embed type. |
| 577 | * @param string $size youtube thumbnail size. |
| 578 | */ |
| 579 | public static function get_video_thumbnail( $video_id, $type, $size = '' ) { |
| 580 | |
| 581 | $thumbnail_src = 'transparent'; |
| 582 | |
| 583 | if ( 'youtube' === $type ) { |
| 584 | if ( '' === $size ) { |
| 585 | $size = 'maxresdefault'; |
| 586 | } |
| 587 | $thumbnail_src = sprintf( 'https://i.ytimg.com/vi/%s/%s.jpg', $video_id, $size ); |
| 588 | |
| 589 | } elseif ( 'vimeo' === $type ) { |
| 590 | |
| 591 | $vimeo = self::get_vimeo_video_data( $video_id ); |
| 592 | |
| 593 | $thumbnail_src = is_array( $vimeo ) ? $vimeo['src'] : ''; |
| 594 | |
| 595 | } elseif ( 'dailymotion' === $type ) { |
| 596 | $video_data = rplg_urlopen( 'https://api.dailymotion.com/video/' . $video_id . '?fields=thumbnail_url' ); |
| 597 | |
| 598 | if ( isset( $video_data['code'] ) ) { |
| 599 | if ( 404 === $video_data['code'] ) { |
| 600 | return $thumbnail_src; |
| 601 | } |
| 602 | } |
| 603 | |
| 604 | $thumbnail_src = rplg_json_decode( $video_data['data'] )->thumbnail_url; |
| 605 | } |
| 606 | |
| 607 | return $thumbnail_src; |
| 608 | } |
| 609 | |
| 610 | /** |
| 611 | * Transient Expire |
| 612 | * |
| 613 | * Gets expire time of transient. |
| 614 | * |
| 615 | * @since 3.20.8 |
| 616 | * @access public |
| 617 | * |
| 618 | * @param string $period transient expiration period. |
| 619 | * |
| 620 | * @return string $expire_time expire time in seconds. |
| 621 | */ |
| 622 | public static function transient_expire( $period ) { |
| 623 | |
| 624 | $expire_time = 24 * HOUR_IN_SECONDS; |
| 625 | |
| 626 | switch ( $period ) { |
| 627 | case 'minute': |
| 628 | $expire_time = MINUTE_IN_SECONDS; |
| 629 | break; |
| 630 | case 'minutes': |
| 631 | $expire_time = 5 * MINUTE_IN_SECONDS; |
| 632 | break; |
| 633 | case 'hour': |
| 634 | $expire_time = 60 * MINUTE_IN_SECONDS; |
| 635 | break; |
| 636 | case 'week': |
| 637 | $expire_time = 7 * DAY_IN_SECONDS; |
| 638 | break; |
| 639 | case 'month': |
| 640 | $expire_time = 30 * DAY_IN_SECONDS; |
| 641 | break; |
| 642 | case 'year': |
| 643 | $expire_time = 365 * DAY_IN_SECONDS; |
| 644 | break; |
| 645 | default: |
| 646 | $expire_time = 24 * HOUR_IN_SECONDS; |
| 647 | } |
| 648 | |
| 649 | return $expire_time; |
| 650 | } |
| 651 | |
| 652 | /** |
| 653 | * Get Campaign Link |
| 654 | * |
| 655 | * @since 3.20.9 |
| 656 | * @access public |
| 657 | * |
| 658 | * @param string $link page link. |
| 659 | * @param string $source source. |
| 660 | * @param string $medium media. |
| 661 | * @param string $campaign campaign name. |
| 662 | * |
| 663 | * @return string $link campaign URL |
| 664 | */ |
| 665 | public static function get_campaign_link( $link, $source, $medium, $campaign = '' ) { |
| 666 | |
| 667 | if ( null === self::$current_theme ) { |
| 668 | self::get_installed_theme(); |
| 669 | } |
| 670 | |
| 671 | $url = add_query_arg( |
| 672 | array( |
| 673 | 'utm_source' => $source, |
| 674 | 'utm_medium' => $medium, |
| 675 | 'utm_campaign' => $campaign, |
| 676 | 'utm_term' => self::$current_theme, |
| 677 | ), |
| 678 | $link |
| 679 | ); |
| 680 | |
| 681 | return $url; |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * Get Elementor UI Theme |
| 686 | * |
| 687 | * Detects user setting for UI theme |
| 688 | * |
| 689 | * @since 3.21.1 |
| 690 | * @access public |
| 691 | * |
| 692 | * @return string $theme UI Theme |
| 693 | */ |
| 694 | public static function get_elementor_ui_theme() { |
| 695 | |
| 696 | $theme = SettingsManager::get_settings_managers( 'editorPreferences' )->get_model()->get_settings( 'ui_theme' ); |
| 697 | |
| 698 | return $theme; |
| 699 | } |
| 700 | |
| 701 | /** |
| 702 | * Check PAPRO Version |
| 703 | * |
| 704 | * Check if PAPRO version is updated |
| 705 | * |
| 706 | * @since 3.21.6 |
| 707 | * @access public |
| 708 | * |
| 709 | * @return boolen $is_updated |
| 710 | */ |
| 711 | public static function check_papro_version() { |
| 712 | |
| 713 | if ( ! defined( 'PREMIUM_PRO_ADDONS_VERSION' ) ) { |
| 714 | return false; |
| 715 | } |
| 716 | |
| 717 | $is_updated = get_option( 'papro_updated', true ); |
| 718 | |
| 719 | return $is_updated; |
| 720 | } |
| 721 | |
| 722 | /** |
| 723 | * Valide HTML Tag |
| 724 | * |
| 725 | * Validates an HTML tag against a safe allowed list. |
| 726 | * |
| 727 | * @param string $tag HTML tag. |
| 728 | * |
| 729 | * @return string |
| 730 | */ |
| 731 | public static function validate_html_tag( $tag ) { |
| 732 | return in_array( strtolower( $tag ), self::ALLOWED_HTML_WRAPPER_TAGS, true ) ? $tag : 'div'; |
| 733 | } |
| 734 | |
| 735 | /** |
| 736 | * Get Image Data |
| 737 | * |
| 738 | * Returns image data based on image id. |
| 739 | * |
| 740 | * @since 0.0.1 |
| 741 | * @access public |
| 742 | * |
| 743 | * @param int $image_id Image ID. |
| 744 | * @param string $image_url Image URL. |
| 745 | * @param array $image_size Image sizes array. |
| 746 | * |
| 747 | * @return array $data image data. |
| 748 | */ |
| 749 | public static function get_image_data( $image_id, $image_url, $image_size ) { |
| 750 | |
| 751 | if ( ! $image_id && ! $image_url ) { |
| 752 | return false; |
| 753 | } |
| 754 | |
| 755 | $data = array(); |
| 756 | |
| 757 | $image_url = esc_url_raw( $image_url ); |
| 758 | |
| 759 | if ( ! empty( $image_id ) ) { // Existing attachment. |
| 760 | |
| 761 | $attachment = get_post( $image_id ); |
| 762 | |
| 763 | if ( is_object( $attachment ) ) { |
| 764 | $data['id'] = $image_id; |
| 765 | $data['url'] = $image_url; |
| 766 | |
| 767 | $data['image'] = wp_get_attachment_image( $attachment->ID, $image_size, true ); |
| 768 | $data['image_size'] = $image_size; |
| 769 | $data['caption'] = $attachment->post_excerpt; |
| 770 | $data['title'] = $attachment->post_title; |
| 771 | $data['description'] = $attachment->post_content; |
| 772 | |
| 773 | } |
| 774 | } else { // Placeholder image, most likely. |
| 775 | |
| 776 | if ( empty( $image_url ) ) { |
| 777 | return; |
| 778 | } |
| 779 | |
| 780 | $data['id'] = false; |
| 781 | $data['url'] = $image_url; |
| 782 | $data['image'] = '<img src="' . $image_url . '" alt="" title="" />'; |
| 783 | $data['image_size'] = $image_size; |
| 784 | $data['caption'] = ''; |
| 785 | $data['title'] = ''; |
| 786 | $data['description'] = ''; |
| 787 | } |
| 788 | |
| 789 | return $data; |
| 790 | } |
| 791 | |
| 792 | /** |
| 793 | * Get Final Result. |
| 794 | * |
| 795 | * @access public |
| 796 | * @since 4.4.8 |
| 797 | * |
| 798 | * @param bool $condition_result result. |
| 799 | * @param string $operator operator. |
| 800 | * |
| 801 | * @return bool |
| 802 | */ |
| 803 | public static function get_final_result( $condition_result, $operator ) { |
| 804 | |
| 805 | if ( 'is' === $operator ) { |
| 806 | return true === $condition_result; |
| 807 | } else { |
| 808 | return true !== $condition_result; |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | /** |
| 813 | * Get Local Time ( WordPress TimeZone Setting ). |
| 814 | * |
| 815 | * @access public |
| 816 | * @since 4.4.8 |
| 817 | * |
| 818 | * @param string $format format. |
| 819 | */ |
| 820 | public static function get_local_time( $format ) { |
| 821 | |
| 822 | $local_time_zone = isset( $_COOKIE['localTimeZone'] ) && ! empty( $_COOKIE['localTimeZone'] ) ? |
| 823 | str_replace( 'GMT ', 'GMT+', sanitize_text_field( wp_unslash( $_COOKIE['localTimeZone'] ) ) ) |
| 824 | : self::get_location_time_zone(); |
| 825 | |
| 826 | $today = new \DateTime( 'now', new \DateTimeZone( $local_time_zone ) ); |
| 827 | |
| 828 | return $today->format( $format ); |
| 829 | } |
| 830 | |
| 831 | /** |
| 832 | * Gets the user's timezone based on his ip address. |
| 833 | * |
| 834 | * @access public |
| 835 | * @since 4.10.26 |
| 836 | * |
| 837 | * @return string |
| 838 | */ |
| 839 | public static function get_location_time_zone() { |
| 840 | |
| 841 | $ip_address = self::get_user_ip_address(); |
| 842 | |
| 843 | return self::get_timezone_by_ip( $ip_address ); |
| 844 | } |
| 845 | |
| 846 | /** |
| 847 | * Get user's IP address. |
| 848 | * |
| 849 | * @access public |
| 850 | * @since 4.10.26 |
| 851 | * |
| 852 | * @return string |
| 853 | */ |
| 854 | public static function get_user_ip_address() { |
| 855 | |
| 856 | if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
| 857 | |
| 858 | $x_forward = sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ); |
| 859 | |
| 860 | if ( is_array( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { |
| 861 | |
| 862 | $http_x_headers = explode( ',', filter_var_array( $x_forward ) ); |
| 863 | $_SERVER['REMOTE_ADDR'] = $http_x_headers[0]; |
| 864 | } else { |
| 865 | $_SERVER['REMOTE_ADDR'] = $x_forward; |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | return isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : ''; |
| 870 | } |
| 871 | |
| 872 | /** |
| 873 | * Get timezone by ip address. |
| 874 | * |
| 875 | * @access public |
| 876 | * @since 4.10.26 |
| 877 | * |
| 878 | * @param string $ip_address user's ip address. |
| 879 | * |
| 880 | * @return string |
| 881 | */ |
| 882 | public static function get_timezone_by_ip( $ip_address ) { |
| 883 | |
| 884 | if ( '127.0.0.1' === $ip_address || empty( $ip_address ) ) { |
| 885 | return date_default_timezone_get(); |
| 886 | } |
| 887 | |
| 888 | $location_data = wp_remote_get( |
| 889 | 'https://api.findip.net/' . $ip_address . '/?token=e21d68c353324af0af206c907e77ff97', |
| 890 | array( |
| 891 | 'timeout' => 60, |
| 892 | 'sslverify' => false, |
| 893 | ) |
| 894 | ); |
| 895 | |
| 896 | if ( is_wp_error( $location_data ) || empty( $location_data ) ) { |
| 897 | return date_default_timezone_get(); // localhost. |
| 898 | } |
| 899 | |
| 900 | $location_data = json_decode( wp_remote_retrieve_body( $location_data ), true ); |
| 901 | |
| 902 | $time_zone = strtolower( $location_data['location']['time_zone'] ); |
| 903 | |
| 904 | return $time_zone; |
| 905 | } |
| 906 | |
| 907 | /** |
| 908 | * Get Site Server Time ( WordPress TimeZone Setting ). |
| 909 | * |
| 910 | * @access public |
| 911 | * @since 4.4.8 |
| 912 | * |
| 913 | * @param string $format format. |
| 914 | */ |
| 915 | public static function get_site_server_time( $format ) { |
| 916 | |
| 917 | $today = gmdate( $format, strtotime( 'now' ) + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ); |
| 918 | |
| 919 | return $today; |
| 920 | } |
| 921 | |
| 922 | /** |
| 923 | * Get All Breakpoints. |
| 924 | * |
| 925 | * @param string $type result return type. |
| 926 | * |
| 927 | * @access public |
| 928 | * @since 4.6.1 |
| 929 | * |
| 930 | * @return array $devices enabled breakpoints. |
| 931 | */ |
| 932 | public static function get_all_breakpoints( $type = 'assoc' ) { |
| 933 | |
| 934 | $devices = array( |
| 935 | 'desktop' => __( 'Desktop', 'elementor' ), |
| 936 | 'tablet' => __( 'Tablet', 'elementor' ), |
| 937 | 'mobile' => __( 'Mobile', 'elementor' ), |
| 938 | ); |
| 939 | |
| 940 | $method_available = method_exists( Plugin::$instance->breakpoints, 'has_custom_breakpoints' ); |
| 941 | |
| 942 | if ( ( defined( 'ELEMENTOR_VERSION' ) && version_compare( ELEMENTOR_VERSION, '3.4.0', '>' ) ) && $method_available ) { |
| 943 | |
| 944 | if ( Plugin::$instance->breakpoints->has_custom_breakpoints() ) { |
| 945 | $devices = array_merge( |
| 946 | $devices, |
| 947 | array( |
| 948 | 'widescreen' => __( 'Widescreen', 'elementor' ), |
| 949 | 'laptop' => __( 'Laptop', 'elementor' ), |
| 950 | 'tablet_extra' => __( 'Tablet Extra', 'elementor' ), |
| 951 | 'mobile_extra' => __( 'Mobile Extra', 'elementor' ), |
| 952 | ) |
| 953 | ); |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | if ( 'keys' === $type ) { |
| 958 | $devices = array_keys( $devices ); |
| 959 | } |
| 960 | |
| 961 | return $devices; |
| 962 | } |
| 963 | |
| 964 | /** |
| 965 | * Get WordPress language prefixes. |
| 966 | * |
| 967 | * @since 4.4.8 |
| 968 | * @access public |
| 969 | * |
| 970 | * @return array |
| 971 | */ |
| 972 | public static function get_lang_prefixes() { |
| 973 | |
| 974 | if ( null === self::$lang_locales ) { |
| 975 | |
| 976 | $langs = require_once PREMIUM_ADDONS_PATH . 'includes/pa-display-conditions/lang-locale.php'; |
| 977 | |
| 978 | foreach ( $langs as $lang => $props ) { |
| 979 | /* translators: %s: Language Name */ |
| 980 | $val = ucwords( $props['name'] ); |
| 981 | self::$lang_locales[ $lang ] = $val; |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | return self::$lang_locales; |
| 986 | } |
| 987 | |
| 988 | /** |
| 989 | * Get Woocommerce Categories. |
| 990 | * |
| 991 | * @access public |
| 992 | * @since 4.4.8 |
| 993 | * |
| 994 | * @param string $id array key. |
| 995 | * |
| 996 | * @return array |
| 997 | */ |
| 998 | public static function get_woo_categories( $id = 'slug' ) { |
| 999 | |
| 1000 | $product_cat = array(); |
| 1001 | |
| 1002 | $cat_args = array( |
| 1003 | 'taxonomy' => 'product_cat', |
| 1004 | 'orderby' => 'name', |
| 1005 | 'order' => 'asc', |
| 1006 | 'hide_empty' => false, |
| 1007 | ); |
| 1008 | |
| 1009 | $product_categories = get_terms( $cat_args ); |
| 1010 | |
| 1011 | if ( ! empty( $product_categories ) ) { |
| 1012 | |
| 1013 | foreach ( $product_categories as $key => $category ) { |
| 1014 | |
| 1015 | $cat_id = 'slug' === $id ? $category->slug : $category->term_id; |
| 1016 | $product_cat[ $cat_id ] = $category->name; |
| 1017 | |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | return $product_cat; |
| 1022 | } |
| 1023 | |
| 1024 | /** |
| 1025 | * Check Elementor Experiment |
| 1026 | * |
| 1027 | * Check if an Elementor experiment is enabled. |
| 1028 | * |
| 1029 | * @since 4.8.6 |
| 1030 | * @access public |
| 1031 | * |
| 1032 | * @param string $experiment feature ID. |
| 1033 | * |
| 1034 | * @return boolean $is_enabled is feature enabled. |
| 1035 | */ |
| 1036 | public static function check_elementor_experiment( $experiment ) { |
| 1037 | |
| 1038 | $experiments_manager = Plugin::$instance->experiments; |
| 1039 | |
| 1040 | $is_enabled = $experiments_manager->is_feature_active( $experiment ); |
| 1041 | |
| 1042 | return $is_enabled; |
| 1043 | } |
| 1044 | |
| 1045 | /** |
| 1046 | * Is Edit Mode. |
| 1047 | * |
| 1048 | * @access public |
| 1049 | * @since 4.6.1 |
| 1050 | * |
| 1051 | * @return boolean |
| 1052 | */ |
| 1053 | public static function is_edit_mode() { |
| 1054 | return isset( $_REQUEST['elementor-preview'] ) && ! empty( $_REQUEST['elementor-preview'] ); // phpcs:ignore WordPress.Security.NonceVerification |
| 1055 | } |
| 1056 | |
| 1057 | /** |
| 1058 | * Generate Unique ID |
| 1059 | * |
| 1060 | * Generates a unique ID for the current page. |
| 1061 | * |
| 1062 | * @since 4.6.9 |
| 1063 | * @access public |
| 1064 | * |
| 1065 | * @param string $id page ID. |
| 1066 | * |
| 1067 | * @return string unique ID. |
| 1068 | */ |
| 1069 | public static function generate_unique_id( $id ) { |
| 1070 | return substr( md5( $id ), 0, 9 ); |
| 1071 | } |
| 1072 | |
| 1073 | /** |
| 1074 | * Get Safe Path |
| 1075 | * |
| 1076 | * @since 4.6.9 |
| 1077 | * @access public |
| 1078 | * |
| 1079 | * @param string $file_path unsafe file path. |
| 1080 | * |
| 1081 | * @return string safe file path. |
| 1082 | */ |
| 1083 | public static function get_safe_path( $file_path ) { |
| 1084 | |
| 1085 | $path = str_replace( array( '//', '\\\\' ), array( '/', '\\' ), $file_path ); |
| 1086 | |
| 1087 | return str_replace( array( '/', '\\' ), DIRECTORY_SEPARATOR, $path ); |
| 1088 | } |
| 1089 | |
| 1090 | /** |
| 1091 | * Check if the current post type should include addons. |
| 1092 | * |
| 1093 | * @param string $id current post ID. |
| 1094 | * |
| 1095 | * @since 4.9.18 |
| 1096 | * @access public |
| 1097 | */ |
| 1098 | public static function check_post_type( $id ) { |
| 1099 | |
| 1100 | if ( ! $id ) { |
| 1101 | return false; |
| 1102 | } |
| 1103 | |
| 1104 | $template_name = get_post_meta( $id, '_elementor_template_type', true ); |
| 1105 | |
| 1106 | $template_list = array( |
| 1107 | 'header', |
| 1108 | 'footer', |
| 1109 | 'single', |
| 1110 | 'post', |
| 1111 | 'page', |
| 1112 | 'archive', |
| 1113 | 'search-results', |
| 1114 | 'error-404', |
| 1115 | 'product', |
| 1116 | 'product-archive', |
| 1117 | 'section', |
| 1118 | ); |
| 1119 | |
| 1120 | return in_array( $template_name, $template_list ); |
| 1121 | } |
| 1122 | |
| 1123 | /** |
| 1124 | * Get Draw SVG Notice |
| 1125 | * |
| 1126 | * @since 4.9.26 |
| 1127 | * @access public |
| 1128 | * |
| 1129 | * @param object $elem element object. |
| 1130 | * @param string $search search query. |
| 1131 | * @param array $conditions control conditions |
| 1132 | */ |
| 1133 | public static function get_draw_svg_notice( $elem, $search, $conditions, $index = 0, $nested = 'condition' ) { |
| 1134 | |
| 1135 | $url = add_query_arg( |
| 1136 | array( |
| 1137 | 'page' => 'premium-addons', |
| 1138 | 'search' => $search, |
| 1139 | '#tab' => 'elements', |
| 1140 | ), |
| 1141 | esc_url( admin_url( 'admin.php' ) ) |
| 1142 | ); |
| 1143 | |
| 1144 | $control_attr = array( |
| 1145 | 'type' => Controls_Manager::RAW_HTML, |
| 1146 | 'raw' => __( 'You need first to enable SVG Draw option checkbox from ', 'premium-addons-for-elementor' ) . '<a href="' . esc_url( $url ) . '" target="_blank">' . __( 'here.', 'premium-addons-for-elementor' ) . '</a>', |
| 1147 | 'classes' => 'editor-pa-control-notice', |
| 1148 | 'content_classes' => 'elementor-panel-alert elementor-panel-alert-warning', |
| 1149 | ); |
| 1150 | |
| 1151 | $control_attr[ $nested ] = $conditions; |
| 1152 | |
| 1153 | $elem->add_control( |
| 1154 | 'draw_svg_notice_' . $index, |
| 1155 | $control_attr |
| 1156 | ); |
| 1157 | } |
| 1158 | |
| 1159 | /** |
| 1160 | * Checks if Elementor PRO 3.8 or higher is activated && if the Loop expirement is activated. |
| 1161 | * |
| 1162 | * @since 4.9.45 |
| 1163 | * @access public |
| 1164 | * |
| 1165 | * @return bool |
| 1166 | */ |
| 1167 | public static function is_loop_exp_enabled() { |
| 1168 | |
| 1169 | if ( defined( 'ELEMENTOR_PRO_VERSION' ) ) { |
| 1170 | |
| 1171 | if ( version_compare( ELEMENTOR_PRO_VERSION, '3.16.0', '>=' ) ) { |
| 1172 | return true; |
| 1173 | } elseif ( version_compare( ELEMENTOR_PRO_VERSION, '3.8', '>=' ) ) { |
| 1174 | $is_loop_enabled = self::check_elementor_experiment( 'loop' ); |
| 1175 | |
| 1176 | if ( $is_loop_enabled ) { |
| 1177 | return true; |
| 1178 | } |
| 1179 | } |
| 1180 | } |
| 1181 | |
| 1182 | return false; |
| 1183 | } |
| 1184 | |
| 1185 | /** |
| 1186 | * Get Element Classes. |
| 1187 | * |
| 1188 | * @access private |
| 1189 | * @since 2.8.22 |
| 1190 | * |
| 1191 | * @param array $devices devices to hide on. |
| 1192 | * |
| 1193 | * @return array |
| 1194 | */ |
| 1195 | public static function get_element_classes( $devices, $default = array() ) { |
| 1196 | |
| 1197 | $classes = $default; |
| 1198 | |
| 1199 | if ( count( $devices ) ) { |
| 1200 | foreach ( $devices as $index => $device ) { |
| 1201 | array_push( $classes, 'elementor-hidden-' . $device ); |
| 1202 | } |
| 1203 | |
| 1204 | array_push( $classes, 'premium-addons-element' ); |
| 1205 | } |
| 1206 | |
| 1207 | return $classes; |
| 1208 | } |
| 1209 | |
| 1210 | /** |
| 1211 | * Round Numbers In A Reading-friendly Format. |
| 1212 | * |
| 1213 | * @param integer $num followers number. |
| 1214 | */ |
| 1215 | public static function premium_format_numbers( $num ) { |
| 1216 | $num = intval( $num ); |
| 1217 | $result = ''; |
| 1218 | |
| 1219 | if ( $num >= 1000000000 ) { |
| 1220 | $tmp = round( ( $num / 1000000 ), 1 ); |
| 1221 | $result = $tmp . 'B'; |
| 1222 | return $result; |
| 1223 | } |
| 1224 | |
| 1225 | if ( $num >= 1000000 ) { |
| 1226 | $tmp = round( ( $num / 1000000 ), 1 ); |
| 1227 | $result = $tmp . 'M'; |
| 1228 | return $result; |
| 1229 | } |
| 1230 | |
| 1231 | if ( $num >= 1000 ) { |
| 1232 | $tmp = round( ( $num / 1000 ), 1 ); |
| 1233 | $result = $tmp . 'K'; |
| 1234 | |
| 1235 | return $result; |
| 1236 | } |
| 1237 | |
| 1238 | return round( $num, 1 ); |
| 1239 | } |
| 1240 | |
| 1241 | /** |
| 1242 | * Get Contact Form Body |
| 1243 | * |
| 1244 | * @since 4.10.2 |
| 1245 | * @access public |
| 1246 | * |
| 1247 | * @param string $preset form preset. |
| 1248 | * |
| 1249 | * @return void |
| 1250 | */ |
| 1251 | public static function get_cf_form_body( $preset ) { |
| 1252 | |
| 1253 | $forms_array = array( |
| 1254 | |
| 1255 | 'preset1' => '<div class="premium-cf-full"><label class="premium-cf-label">Email</label> |
| 1256 | [email* email-1 class:premium-cf-field placeholder "john@smith.com"]</div> |
| 1257 | [submit "Subscribe"]', |
| 1258 | |
| 1259 | 'preset2' => '<div class="premium-cf-full"><label class="premium-cf-label">Name</label> |
| 1260 | [text* text-1 class:premium-cf-field placeholder "John Smith"]</div> |
| 1261 | |
| 1262 | <div class="premium-cf-full"><label class="premium-cf-label">Email</label> |
| 1263 | [email* email-1 class:premium-cf-field placeholder "john@smith.com"]</div> |
| 1264 | |
| 1265 | [submit "Send"]', |
| 1266 | |
| 1267 | 'preset3' => '<div class="premium-cf-full"><label class="premium-cf-label">Name</label> |
| 1268 | [text* text-1 class:premium-cf-field placeholder "John Smith"]</div> |
| 1269 | |
| 1270 | <div class="premium-cf-full"><label class="premium-cf-label">Email</label> |
| 1271 | [email* email-1 class:premium-cf-field placeholder "john@smith.com"]</div> |
| 1272 | |
| 1273 | <div class="premium-cf-full"><label class="premium-cf-label">Message</label> |
| 1274 | [textarea* textarea-1 class:premium-cf-field placeholder "Enter your message here..."]</div> |
| 1275 | |
| 1276 | [submit "Send"]', |
| 1277 | |
| 1278 | 'preset4' => '<div class="premium-cf-half"><label class="premium-cf-label">Name</label> |
| 1279 | [text* text-1 class:premium-cf-field placeholder "John Smith"]</div> |
| 1280 | |
| 1281 | <div class="premium-cf-half"><label class="premium-cf-label">Email</label> |
| 1282 | [email* email-1 class:premium-cf-field placeholder "john@smith.com"]</div> |
| 1283 | |
| 1284 | <div class="premium-cf-full"><label class="premium-cf-label">Message</label> |
| 1285 | [textarea* textarea-1 class:premium-cf-field placeholder "Enter your message here..."]</div> |
| 1286 | |
| 1287 | [submit "Send"]', |
| 1288 | |
| 1289 | 'preset5' => '<div class="premium-cf-half"><label class="premium-cf-label">First Name</label> |
| 1290 | [text* text-1 class:premium-cf-field placeholder "John"]</div> |
| 1291 | |
| 1292 | <div class="premium-cf-half"><label class="premium-cf-label">Last Name</label> |
| 1293 | [text* text-2 class:premium-cf-field placeholder "Smith"]</div> |
| 1294 | |
| 1295 | <div class="premium-cf-half"><label class="premium-cf-label">Email</label> |
| 1296 | [email* email-1 class:premium-cf-field placeholder "john@smith.com"]</div> |
| 1297 | |
| 1298 | <div class="premium-cf-half"><label class="premium-cf-label">Phone</label> |
| 1299 | [tel* tel-1 class:premium-cf-field placeholder "+13137262547"]</div> |
| 1300 | |
| 1301 | <div class="premium-cf-full"><label class="premium-cf-label">Gender</label> |
| 1302 | [select menu-1 "Male" "Female"]</div> |
| 1303 | |
| 1304 | <div class="premium-cf-full"><label class="premium-cf-label">Message</label> |
| 1305 | [textarea* textarea-1 class:premium-cf-field placeholder "Enter your message here..."]</div> |
| 1306 | [submit "Send"]', |
| 1307 | |
| 1308 | 'preset6' => '<div class="premium-cf-half"><label class="premium-cf-label">First Name</label> |
| 1309 | [text* text-1 class:premium-cf-field placeholder "John"]</div> |
| 1310 | |
| 1311 | <div class="premium-cf-half"><label class="premium-cf-label">Last Name</label> |
| 1312 | [text* text-2 class:premium-cf-field placeholder "Smith"]</div> |
| 1313 | |
| 1314 | <div class="premium-cf-half"><label class="premium-cf-label">Email</label> |
| 1315 | [email* email-1 class:premium-cf-field placeholder "john@smith.com"]</div> |
| 1316 | |
| 1317 | <div class="premium-cf-half"><label class="premium-cf-label">Phone</label> |
| 1318 | [tel* tel-1 class:premium-cf-field placeholder "+13137262547"]</div> |
| 1319 | |
| 1320 | <div class="premium-cf-full"><label class="premium-cf-label">Company Size</label> |
| 1321 | [radio radio-1 default:1 "1-10 employees" "11-30 employees" "30-50 employees" "Above 50 employee"] |
| 1322 | </div> |
| 1323 | |
| 1324 | <div class="premium-cf-full"><label class="premium-cf-label">Message</label> |
| 1325 | [textarea* textarea-1 class:premium-cf-field placeholder "Enter your message here..."]</div> |
| 1326 | [submit "Send"]', |
| 1327 | |
| 1328 | ); |
| 1329 | |
| 1330 | return $forms_array[ $preset ]; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 1331 | } |
| 1332 | |
| 1333 | /** |
| 1334 | * Render Rating Stars |
| 1335 | * |
| 1336 | * @since 4.10.13 |
| 1337 | * @access public |
| 1338 | * |
| 1339 | * @param float $rating rating score. |
| 1340 | * @param string $fill_color fill color. |
| 1341 | * @param string $empty_color empty color. |
| 1342 | * @param float $star_size star size. |
| 1343 | */ |
| 1344 | public static function render_rating_stars( $rating, $fill_color, $empty_color, $star_size ) { |
| 1345 | |
| 1346 | ?> |
| 1347 | |
| 1348 | <span class="premium-fb-rev-stars"> |
| 1349 | <?php |
| 1350 | |
| 1351 | foreach ( array( 1, 2, 3, 4, 5 ) as $val ) { |
| 1352 | $score = round( ( $rating - $val ), 2 ); |
| 1353 | |
| 1354 | if ( $score >= -0.2 ) { |
| 1355 | |
| 1356 | ?> |
| 1357 | <span class="premium-fb-rev-star"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="<?php echo esc_attr( $star_size ); ?>" height="<?php echo esc_attr( $star_size ); ?>" viewBox="0 0 1792 1792"><path d="M1728 647q0 22-26 48l-363 354 86 500q1 7 1 20 0 21-10.5 35.5t-30.5 14.5q-19 0-40-12l-449-236-449 236q-22 12-40 12-21 0-31.5-14.5t-10.5-35.5q0-6 2-20l86-500-364-354q-25-27-25-48 0-37 56-46l502-73 225-455q19-41 49-41t49 41l225 455 502 73q56 9 56 46z" fill="<?php echo esc_attr( $fill_color ); ?>"></path></svg></span> |
| 1358 | <?php |
| 1359 | } elseif ( $score > -0.8 && $score < -0.2 ) { |
| 1360 | ?> |
| 1361 | <span class="premium-fb-rev-star"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="<?php echo esc_attr( $star_size ); ?>" height="<?php echo esc_attr( $star_size ); ?>" viewBox="0 0 1792 1792"><path d="M1250 957l257-250-356-52-66-10-30-60-159-322v963l59 31 318 168-60-355-12-66zm452-262l-363 354 86 500q5 33-6 51.5t-34 18.5q-17 0-40-12l-449-236-449 236q-23 12-40 12-23 0-34-18.5t-6-51.5l86-500-364-354q-32-32-23-59.5t54-34.5l502-73 225-455q20-41 49-41 28 0 49 41l225 455 502 73q45 7 54 34.5t-24 59.5z" fill="<?php echo esc_attr( $fill_color ); ?>"></path></svg></span> |
| 1362 | <?php } else { ?> |
| 1363 | <span class="premium-fb-rev-star"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="<?php echo esc_attr( $star_size ); ?>" height="<?php echo esc_attr( $star_size ); ?>" viewBox="0 0 1792 1792"><path d="M1201 1004l306-297-422-62-189-382-189 382-422 62 306 297-73 421 378-199 377 199zm527-357q0 22-26 48l-363 354 86 500q1 7 1 20 0 50-41 50-19 0-40-12l-449-236-449 236q-22 12-40 12-21 0-31.5-14.5t-10.5-35.5q0-6 2-20l86-500-364-354q-25-27-25-48 0-37 56-46l502-73 225-455q19-41 49-41t49 41l225 455 502 73q56 9 56 46z" fill="<?php echo esc_attr( $empty_color ); ?>"></path></svg></span> |
| 1364 | <?php |
| 1365 | } |
| 1366 | } |
| 1367 | ?> |
| 1368 | </span> |
| 1369 | |
| 1370 | <?php |
| 1371 | } |
| 1372 | |
| 1373 | |
| 1374 | /** |
| 1375 | * Get SVG Shapes |
| 1376 | * |
| 1377 | * @since 4.10.13 |
| 1378 | * @access public |
| 1379 | */ |
| 1380 | public static function get_svg_shapes( $shape = '' ) { |
| 1381 | |
| 1382 | if ( null === self::$shapes ) { |
| 1383 | |
| 1384 | self::$shapes = require PREMIUM_ADDONS_PATH . 'modules/premium-shape-divider/shapes.php'; |
| 1385 | |
| 1386 | } |
| 1387 | |
| 1388 | $shapes = self::$shapes; |
| 1389 | |
| 1390 | if ( empty( $shape ) ) { |
| 1391 | return $shapes; |
| 1392 | } else { |
| 1393 | return $shapes[ $shape ]['imagesmall']; |
| 1394 | } |
| 1395 | } |
| 1396 | |
| 1397 | public static function get_btn_svgs( $style = 'line1' ) { |
| 1398 | |
| 1399 | $html = ''; |
| 1400 | |
| 1401 | switch ( $style ) { |
| 1402 | case 'line1': |
| 1403 | $html = '<div class="premium-btn-line-wrap"><svg class="premium-btn-svg" width="100%" height="9" viewBox="0 0 101 9"> |
| 1404 | <path d="M.426 1.973C4.144 1.567 17.77-.514 21.443 1.48 24.296 3.026 24.844 4.627 27.5 7c3.075 2.748 6.642-4.141 10.066-4.688 7.517-1.2 13.237 5.425 17.59 2.745C58.5 3 60.464-1.786 66 2c1.996 1.365 3.174 3.737 5.286 4.41 5.423 1.727 25.34-7.981 29.14-1.294" pathLength="1"></path> |
| 1405 | </svg></div>'; |
| 1406 | break; |
| 1407 | |
| 1408 | case 'line3': |
| 1409 | $html = '<div class="premium-btn-line-wrap"><svg class="premium-btn-svg" width="100%" height="18" viewBox="0 0 59 18"> |
| 1410 | <path d="M.945.149C12.3 16.142 43.573 22.572 58.785 10.842" pathLength="1"></path> |
| 1411 | </svg></div>'; |
| 1412 | break; |
| 1413 | |
| 1414 | case 'line4': |
| 1415 | $html = '<svg class="premium-btn-svg" width="300%" height="100%" viewBox="0 0 1200 60" preserveAspectRatio="none"> |
| 1416 | <path d="M0,56.5c0,0,298.666,0,399.333,0C448.336,56.5,513.994,46,597,46c77.327,0,135,10.5,200.999,10.5c95.996,0,402.001,0,402.001,0"></path> |
| 1417 | </svg>'; |
| 1418 | break; |
| 1419 | |
| 1420 | default: |
| 1421 | // code... |
| 1422 | break; |
| 1423 | } |
| 1424 | |
| 1425 | return $html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 1426 | } |
| 1427 | |
| 1428 | /** |
| 1429 | * Add Button Hover Controls |
| 1430 | * |
| 1431 | * @since 4.10.17 |
| 1432 | * @access public |
| 1433 | * |
| 1434 | * @param object $elem widget object. |
| 1435 | * @param array $conditions controls conditions. |
| 1436 | */ |
| 1437 | public static function add_btn_hover_controls( $elem, $conditions ) { |
| 1438 | |
| 1439 | $elem->add_control( |
| 1440 | 'premium_button_hover_effect', |
| 1441 | array( |
| 1442 | 'label' => __( 'Hover Effect', 'premium-addons-for-elementor' ), |
| 1443 | 'type' => Controls_Manager::SELECT, |
| 1444 | 'default' => 'none', |
| 1445 | 'options' => array( |
| 1446 | 'none' => __( 'None', 'premium-addons-for-elementor' ), |
| 1447 | 'style1' => __( 'Slide', 'premium-addons-for-elementor' ), |
| 1448 | 'style2' => __( 'Shutter', 'premium-addons-for-elementor' ), |
| 1449 | 'style5' => apply_filters( 'pa_pro_label', __( 'In & Out (Pro)', 'premium-addons-for-elementor' ) ), |
| 1450 | 'style6' => apply_filters( 'pa_pro_label', __( 'Grow (Pro)', 'premium-addons-for-elementor' ) ), |
| 1451 | 'style7' => apply_filters( 'pa_pro_label', __( 'Double Layers (Pro)', 'premium-addons-for-elementor' ) ), |
| 1452 | 'style8' => apply_filters( 'pa_pro_label', __( 'Animated Underline (Pro)', 'premium-addons-for-elementor' ) ), |
| 1453 | ), |
| 1454 | 'separator' => 'before', |
| 1455 | 'label_block' => true, |
| 1456 | 'condition' => $conditions, |
| 1457 | ) |
| 1458 | ); |
| 1459 | |
| 1460 | do_action( 'pa_button_hover_controls', $elem, $conditions ); |
| 1461 | |
| 1462 | $elem->add_control( |
| 1463 | 'premium_button_style1_dir', |
| 1464 | array( |
| 1465 | 'label' => __( 'Slide Direction', 'premium-addons-for-elementor' ), |
| 1466 | 'type' => Controls_Manager::SELECT, |
| 1467 | 'default' => 'bottom', |
| 1468 | 'options' => array( |
| 1469 | 'bottom' => __( 'Top to Bottom', 'premium-addons-for-elementor' ), |
| 1470 | 'top' => __( 'Bottom to Top', 'premium-addons-for-elementor' ), |
| 1471 | 'left' => __( 'Right to Left', 'premium-addons-for-elementor' ), |
| 1472 | 'right' => __( 'Left to Right', 'premium-addons-for-elementor' ), |
| 1473 | ), |
| 1474 | 'condition' => array_merge( |
| 1475 | $conditions, |
| 1476 | array( |
| 1477 | 'premium_button_hover_effect' => 'style1', |
| 1478 | ) |
| 1479 | ), |
| 1480 | 'label_block' => true, |
| 1481 | ) |
| 1482 | ); |
| 1483 | |
| 1484 | $elem->add_control( |
| 1485 | 'premium_button_style2_dir', |
| 1486 | array( |
| 1487 | 'label' => __( 'Shutter Direction', 'premium-addons-for-elementor' ), |
| 1488 | 'type' => Controls_Manager::SELECT, |
| 1489 | 'default' => 'shutouthor', |
| 1490 | 'options' => array( |
| 1491 | 'shutinhor' => __( 'Shutter in Horizontal', 'premium-addons-for-elementor' ), |
| 1492 | 'shutinver' => __( 'Shutter in Vertical', 'premium-addons-for-elementor' ), |
| 1493 | 'shutoutver' => __( 'Shutter out Horizontal', 'premium-addons-for-elementor' ), |
| 1494 | 'shutouthor' => __( 'Shutter out Vertical', 'premium-addons-for-elementor' ), |
| 1495 | 'scshutoutver' => __( 'Scaled Shutter Vertical', 'premium-addons-for-elementor' ), |
| 1496 | 'scshutouthor' => __( 'Scaled Shutter Horizontal', 'premium-addons-for-elementor' ), |
| 1497 | 'dshutinver' => __( 'Tilted Left', 'premium-addons-for-elementor' ), |
| 1498 | 'dshutinhor' => __( 'Tilted Right', 'premium-addons-for-elementor' ), |
| 1499 | ), |
| 1500 | 'condition' => array_merge( |
| 1501 | $conditions, |
| 1502 | array( |
| 1503 | 'premium_button_hover_effect' => 'style2', |
| 1504 | ) |
| 1505 | ), |
| 1506 | 'label_block' => true, |
| 1507 | ) |
| 1508 | ); |
| 1509 | } |
| 1510 | |
| 1511 | /** |
| 1512 | * Get Button Class |
| 1513 | * |
| 1514 | * @since 4.10.17 |
| 1515 | * @access public |
| 1516 | * |
| 1517 | * @param $settings object widget settings. |
| 1518 | * |
| 1519 | * @return string $class css class. |
| 1520 | */ |
| 1521 | public static function get_button_class( $settings ) { |
| 1522 | |
| 1523 | $class = ''; |
| 1524 | |
| 1525 | $papro_activated = apply_filters( 'papro_activated', false ); |
| 1526 | |
| 1527 | if ( ! $papro_activated && ! in_array( $settings['premium_button_hover_effect'], array( 'none', 'style1', 'style2' ) ) ) { |
| 1528 | return ''; |
| 1529 | } |
| 1530 | |
| 1531 | if ( 'style1' === $settings['premium_button_hover_effect'] ) { |
| 1532 | $class = 'premium-button-style1-' . $settings['premium_button_style1_dir']; |
| 1533 | } elseif ( 'style2' === $settings['premium_button_hover_effect'] ) { |
| 1534 | $class = 'premium-button-style2-' . $settings['premium_button_style2_dir']; |
| 1535 | } elseif ( 'style5' === $settings['premium_button_hover_effect'] ) { |
| 1536 | $class = 'premium-button-style5-' . $settings['premium_button_style5_dir']; |
| 1537 | } elseif ( 'style6' === $settings['premium_button_hover_effect'] ) { |
| 1538 | $class = 'premium-button-style6'; |
| 1539 | } elseif ( 'style7' === $settings['premium_button_hover_effect'] ) { |
| 1540 | $class = 'premium-button-style7-' . $settings['premium_button_style7_dir']; |
| 1541 | } elseif ( 'style8' === $settings['premium_button_hover_effect'] ) { |
| 1542 | $class = 'premium-button-' . $settings['underline_style']; |
| 1543 | } |
| 1544 | |
| 1545 | return 'premium-button-' . $settings['premium_button_hover_effect'] . ' ' . $class; |
| 1546 | } |
| 1547 | |
| 1548 | |
| 1549 | /** |
| 1550 | * Get Empty Query Message |
| 1551 | * |
| 1552 | * Written in PHP and used to generate the final HTML when the query is empty |
| 1553 | * |
| 1554 | * @since 4.10.29 |
| 1555 | * @access protected |
| 1556 | * |
| 1557 | * @param string $notice empty query notice. |
| 1558 | */ |
| 1559 | public static function render_empty_query_message( $notice ) { |
| 1560 | |
| 1561 | if ( empty( $notice ) ) { |
| 1562 | $notice = __( 'The current query has no posts. Please make sure you have published items matching your query.', 'premium-addons-for-elementor' ); |
| 1563 | } |
| 1564 | |
| 1565 | ?> |
| 1566 | <div class="premium-error-notice"> |
| 1567 | <?php echo wp_kses_post( $notice ); ?> |
| 1568 | </div> |
| 1569 | <?php |
| 1570 | } |
| 1571 | |
| 1572 | /** |
| 1573 | * Check Capability |
| 1574 | * |
| 1575 | * @since 4.10.28 |
| 1576 | * @access public |
| 1577 | * |
| 1578 | * @param string $check capability. |
| 1579 | */ |
| 1580 | public static function check_capability( $capability ) { |
| 1581 | |
| 1582 | $post_author_id = get_the_author_meta( 'ID' ); |
| 1583 | |
| 1584 | $current_user_can = user_can( $post_author_id, $capability ); |
| 1585 | |
| 1586 | return $current_user_can; |
| 1587 | } |
| 1588 | |
| 1589 | |
| 1590 | /** |
| 1591 | * Get Allowed Icon Tags |
| 1592 | * |
| 1593 | * Returns an array of allowed HTML tags. |
| 1594 | * |
| 1595 | * @since 4.10.69 |
| 1596 | * @access public |
| 1597 | * |
| 1598 | * @return array Array of allowed HTML tags. |
| 1599 | */ |
| 1600 | public static function get_allowed_icon_tags() { |
| 1601 | return array( |
| 1602 | 'svg' => array( |
| 1603 | 'id' => array(), |
| 1604 | 'class' => array(), |
| 1605 | 'aria-hidden' => array(), |
| 1606 | 'aria-labelledby' => array(), |
| 1607 | 'role' => array(), |
| 1608 | 'xmlns' => array(), |
| 1609 | 'width' => array(), |
| 1610 | 'height' => array(), |
| 1611 | 'viewbox' => array(), |
| 1612 | 'data-*' => true, |
| 1613 | ), |
| 1614 | 'g' => array( 'fill' => array() ), |
| 1615 | 'title' => array( 'title' => array() ), |
| 1616 | 'path' => array( |
| 1617 | 'd' => array(), |
| 1618 | 'fill' => array(), |
| 1619 | ), |
| 1620 | 'i' => array( |
| 1621 | 'class' => array(), |
| 1622 | 'id' => array(), |
| 1623 | 'style' => array(), |
| 1624 | ), |
| 1625 | ); |
| 1626 | } |
| 1627 | |
| 1628 | /** |
| 1629 | * Get SVG By Icon |
| 1630 | * |
| 1631 | * @since 4.10.69 |
| 1632 | * @access public |
| 1633 | */ |
| 1634 | public static function get_svg_by_icon( $icon, $attributes = array() ) { |
| 1635 | |
| 1636 | if ( empty( $icon ) || empty( $icon['value'] ) || empty( $icon['library'] ) ) { |
| 1637 | return ''; |
| 1638 | } |
| 1639 | |
| 1640 | $icon['font_family'] = 'font-awesome'; |
| 1641 | |
| 1642 | $i_class = str_replace( ' ', '-', $icon['value'] ); |
| 1643 | |
| 1644 | $svg_html = '<svg '; |
| 1645 | |
| 1646 | $icon = self::get_icon_svg_data( $icon ); |
| 1647 | |
| 1648 | $view_box = '0 0 ' . $icon['width'] . ' ' . $icon['height']; |
| 1649 | |
| 1650 | if ( is_array( $attributes ) ) { |
| 1651 | |
| 1652 | foreach ( $attributes as $key => $value ) { |
| 1653 | |
| 1654 | if ( 'class' === $key ) { |
| 1655 | |
| 1656 | $svg_html .= 'class="svg-inline--' . $i_class . ' ' . $value . '" '; |
| 1657 | |
| 1658 | } else { |
| 1659 | $svg_html .= " {$key}='{$value}' "; |
| 1660 | } |
| 1661 | } |
| 1662 | } else { |
| 1663 | |
| 1664 | $attributes = str_replace( 'class="', 'class="svg-inline--' . $i_class . ' ', $attributes ); |
| 1665 | |
| 1666 | $svg_html .= $attributes; |
| 1667 | } |
| 1668 | |
| 1669 | $svg_html .= "aria-hidden='true' xmlns='http://www.w3.org/2000/svg' viewBox='{$view_box}'>"; |
| 1670 | |
| 1671 | $svg_html .= '<path d="' . esc_attr( $icon['path'] ) . '"></path>'; |
| 1672 | $svg_html .= '</svg>'; |
| 1673 | |
| 1674 | return wp_kses( $svg_html, self::get_allowed_icon_tags() ); |
| 1675 | } |
| 1676 | } |
| 1677 |