Advertisement
artemsemkin

wp-content/plugins/rubenz-core/inc/helper_functions.php

Oct 19th, 2020
746
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.06 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Get the option for the current page/post
  5.  *
  6.  * @param string $option
  7.  * @param int    $post_id
  8.  * @return string
  9.  */
  10. function arts_elementor_get_document_option( $option, $post_id = null ) {
  11.  
  12.   if ( $post_id == null ) {
  13.     $post_id = get_the_ID();
  14.   }
  15.  
  16.   if ( ! empty( $option ) ) {
  17.  
  18.     // Get the page settings manager
  19.     $page_settings_manager = \Elementor\Core\Settings\Manager::get_settings_managers( 'page' );
  20.  
  21.     // Get the settings model for current post
  22.     $page_settings_model = $page_settings_manager->get_model( $post_id );
  23.  
  24.     // Retrieve the settings we added before
  25.     return $page_settings_model->get_settings( $option );
  26.  
  27.   }
  28.  
  29.   return false;
  30.  
  31. }
  32.  
  33. /**
  34.  * ACF Helper Functions
  35.  */
  36.  
  37. if ( ! function_exists( 'arts_have_rows' ) ) {
  38.   function arts_have_rows( $args, $options = '' ) {
  39.  
  40.     if ( function_exists( 'have_rows' ) ) {
  41.       return have_rows( $args, $options );
  42.     } else {
  43.       return false;
  44.     }
  45.  
  46.   }
  47. }
  48.  
  49. if ( ! function_exists( 'arts_get_field' ) ) {
  50.   function arts_get_field( $args, $options = '' ) {
  51.  
  52.     if ( function_exists( 'get_field' ) ) {
  53.       return get_field( $args, $options );
  54.     } else {
  55.       return false;
  56.     }
  57.  
  58.   }
  59. }
  60.  
  61.  
  62. /**
  63.  * Markup for lazy background/image/video
  64.  */
  65. if ( ! function_exists( 'arts_the_lazy_image' ) ) {
  66.   function arts_the_lazy_image( $args ) {
  67.     $defaults = array(
  68.       'id'   => null,
  69.       'type' => 'background',
  70.       'size' => 'full',
  71.       'class' => array(
  72.         'section' => array(),
  73.         'wrapper' => array(),
  74.         'image' => array()
  75.       ),
  76.       'attribute' => array(
  77.         'image' => array()
  78.       ),
  79.       'parallax' => array(
  80.         'enabled' => false,
  81.         'factor' => 0.1
  82.       ),
  83.     );
  84.  
  85.     $class_section = '';
  86.     $attrs_section = '';
  87.  
  88.     $attrs_wrapper = '';
  89.     $class_wrapper = '';
  90.  
  91.     $class_media = '';
  92.     $attrs_media = '';
  93.  
  94.     $args = wp_parse_args( $args, $defaults );
  95.  
  96.     if ( ! $args['id'] || ! $args['type'] ) {
  97.       return;
  98.     }
  99.  
  100.     // section
  101.     if ( array_key_exists( 'section', $args['class'] ) && is_array( $args['class']['section'] ) && ! empty ( $args['class']['section'] ) ) {
  102.       $class_section = implode(' ', $args['class']['section'] );
  103.     }
  104.  
  105.     // wrapper
  106.     if ( array_key_exists( 'wrapper', $args['class'] ) && is_array( $args['class']['wrapper'] ) && ! empty ( $args['class']['wrapper'] ) ) {
  107.       $class_wrapper = implode(' ', $args['class']['wrapper'] );
  108.     }
  109.  
  110.     // image class
  111.     if ( array_key_exists( 'image', $args['class'] ) && is_array( $args['class']['image'] ) && ! empty ( $args['class']['image'] ) ) {
  112.       $class_media = implode(' ', $args['class']['image'] );
  113.     }
  114.  
  115.     // image attributes
  116.     if ( array_key_exists( 'image', $args['attribute'] ) && is_array( $args['attribute']['image'] ) && ! empty ( $args['attribute']['image'] ) ) {
  117.       $attrs_media = implode(' ', $args['attribute']['image'] );
  118.     }
  119.  
  120.     // parallax
  121.     if ( array_key_exists( 'parallax', $args ) && is_array( $args['parallax'] ) && $args['parallax']['enabled'] ) {
  122.       $attrs_wrapper .= ' data-art-parallax=true';
  123.       $attrs_wrapper .= ' data-art-parallax-factor=' . floatval( $args['parallax']['factor'] );
  124.     }
  125.  
  126.     switch ( $args['type'] ) {
  127.       case 'background':
  128.         $class_media .= ' lazy-bg of-cover';
  129.         break;
  130.       case 'image':
  131.         if ( $args['class']['wrapper'] !== false ) {
  132.           $class_wrapper .= ' lazy';
  133.         }
  134.         break;
  135.       case 'background-video':
  136.         $class_media .= ' of-cover';
  137.         break;
  138.       case 'video':
  139.         //
  140.         break;
  141.     }
  142.  
  143.     if ( $args['type'] === 'background' || $args['type'] === 'image' ) {
  144.       $attrs  = wp_get_attachment_image_src( $args['id'], $args['size'] );
  145.       $alt    = get_post_meta( $args['id'], '_wp_attachment_image_alt', true );
  146.     }
  147.  
  148.     ?>
  149.     <?php if ( ! empty( $class_section ) || ! empty( $attrs_section ) ) : ?>
  150.       <div class="<?php echo esc_attr( $class_section ); ?>" <?php echo esc_attr( $attrs_section ); ?>>
  151.     <?php endif; ?>
  152.       <?php if ( ! empty( $class_wrapper ) || ! empty( $attrs_wrapper ) ) : ?>
  153.         <?php if ( $args['type'] === 'image' ) : ?>
  154.           <div class="<?php echo esc_attr( $class_wrapper ); ?>" <?php echo esc_attr( $attrs_wrapper ); ?> style="padding-bottom: calc( (<?php echo esc_attr( $attrs[2] ); ?> / <?php echo esc_attr( $attrs[1] ); ?>) * 100% ); height: 0;">
  155.         <?php else : ?>
  156.           <div class="<?php echo esc_attr( $class_wrapper ); ?>" <?php echo esc_attr( $attrs_wrapper ); ?>>
  157.         <?php endif; ?>
  158.       <?php endif; ?>
  159.         <?php
  160.           switch ( $args['type'] ) {
  161.             case 'background':
  162.               ?>
  163.               <img class="<?php echo esc_attr( $class_media ); ?>" src="#" data-src="<?php echo esc_attr( $attrs[0] ); ?>" alt="<?php echo esc_attr( $alt ); ?>" <?php echo esc_attr( $attrs_media ); ?> />
  164.               <?php
  165.               break;
  166.             case 'image':
  167.               ?>
  168.               <img class="<?php echo esc_attr( $class_media ); ?>" src="#" data-src="<?php echo esc_attr( $attrs[0] ); ?>" width="<?php echo esc_attr( $attrs[1] ); ?>" height="<?php echo esc_attr( $attrs[2] ); ?>" alt="<?php echo esc_attr( $alt ); ?>"/>
  169.               <?php
  170.               break;
  171.             case 'background-video':
  172.               ?>
  173.               <video class="<?php echo esc_attr( $class_media ); ?>" src="<?php echo esc_url( wp_get_attachment_url( $args['id'] ) ); ?>" playsinline loop muted autoplay></video>
  174.               <?php
  175.               break;
  176.             case 'video':
  177.               ?>
  178.               <video class="<?php echo esc_attr( $class_media ); ?>" src="<?php echo esc_url( wp_get_attachment_url( $args['id'] ) ); ?>" playsinline loop muted autoplay></video>
  179.               <?php
  180.               break;
  181.           }
  182.         ?>
  183.       <?php if ( ! empty( $class_wrapper ) ) : ?>
  184.         </div>
  185.       <?php endif; ?>
  186.     <?php if ( ! empty( $class_section ) || ! empty( $attrs_section ) ) : ?>
  187.       </div>
  188.     <?php endif; ?>
  189.     <?php
  190.   }
  191. }
  192.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement