array( 'label' => esc_html__( 'Item Height', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'range' => array( 'px' => array( 'min' => 100, 'max' => 1000, ), ), 'default' => [ 'size' => 300, ], 'condition' => array( 'layout_type' => 'grid', ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['image_instance'] => 'height: {{SIZE}}{{UNIT}};', ), ) ); $this->add_responsive_control( 'item_margin', array( 'label' => esc_html__( 'Items Gap', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'range' => array( 'px' => array( 'min' => 0, 'max' => 50, ), ), 'default' => [ 'size' => 10, ], 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['inner'] => 'margin: {{SIZE}}{{UNIT}};', '{{WRAPPER}} ' . $css_scheme['notice'] => 'margin: {{SIZE}}{{UNIT}};', '{{WRAPPER}} ' . $css_scheme['instance'] => 'margin: -{{SIZE}}{{UNIT}};', ), ) ); $this->add_control( 'show_on_hover', array( 'label' => esc_html__( 'Show on hover', 'jet-elements' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'jet-elements' ), 'label_off' => esc_html__( 'No', 'jet-elements' ), 'return_value' => 'yes', 'default' => 'yes', ) ); $this->end_controls_section(); /** * Item Style Section */ $this->_start_controls_section( 'section_general_style', array( 'label' => esc_html__( 'Item', 'jet-elements' ), 'tab' => Controls_Manager::TAB_STYLE, 'show_label' => false, ) ); $this->_add_control( 'cover_alignment', array( 'label' => esc_html__( 'Content Vertical Alignment', 'jet-elements' ), 'type' => Controls_Manager::SELECT, 'default' => 'center', 'options' => array( 'flex-start' => esc_html__( 'Top', 'jet-elements' ), 'center' => esc_html__( 'Center', 'jet-elements' ), 'flex-end' => esc_html__( 'Bottom', 'jet-elements' ), 'space-between' => esc_html__( 'Space between', 'jet-elements' ), ), 'selectors' => array( '{{WRAPPER}} '. $css_scheme['content'] => 'justify-content: {{VALUE}};', ), ), 25 ); $this->_add_responsive_control( 'item_padding', array( 'label' => __( 'Padding', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['inner'] => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 75 ); $this->_add_group_control( Group_Control_Border::get_type(), array( 'name' => 'item_border', 'label' => esc_html__( 'Border', 'jet-elements' ), 'placeholder' => '1px', 'default' => '1px', 'selector' => '{{WRAPPER}} ' . $css_scheme['inner'], ), 75 ); $this->_add_responsive_control( 'item_border_radius', array( 'label' => __( 'Border Radius', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['inner'] => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 25 ); $this->_add_group_control( Group_Control_Box_Shadow::get_type(), array( 'name' => 'item_shadow', 'selector' => '{{WRAPPER}} ' . $css_scheme['inner'], ), 25 ); $this->_add_control( 'item_overlay_heading', array( 'label' => esc_html__( 'Overlay', 'jet-elements' ), 'type' => Controls_Manager::HEADING, 'separator' => 'before' ), 25 ); $this->_add_group_control( Group_Control_Background::get_type(), array( 'name' => 'overlay_background', 'fields_options' => array( 'color' => array( 'global' => array( 'default' => Global_Colors::COLOR_SECONDARY, ), ), ), 'selector' => '{{WRAPPER}} ' . $css_scheme['content'] . ':before', ), 25 ); $this->_add_responsive_control( 'overlay_paddings', array( 'label' => __( 'Padding', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['content'] => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 100 ); $this->_add_control( 'item_order_heading', array( 'label' => esc_html__( 'Order', 'jet-elements' ), 'type' => Controls_Manager::HEADING, 'separator' => 'before' ), 100 ); $this->_add_control( 'caption_order', array( 'label' => esc_html__( 'Caption Order', 'jet-elements' ), 'type' => Controls_Manager::NUMBER, 'default' => 1, 'min' => 1, 'max' => 4, 'step' => 1, 'selectors' => array( '{{WRAPPER}} '. $css_scheme['caption'] => 'order: {{VALUE}};', ), ), 100 ); $this->_add_control( 'meta_order', array( 'label' => esc_html__( 'Meta Order', 'jet-elements' ), 'type' => Controls_Manager::NUMBER, 'default' => 2, 'min' => 1, 'max' => 4, 'step' => 1, 'selectors' => array( '{{WRAPPER}} '. $css_scheme['meta'] => 'order: {{VALUE}};', ), ), 100 ); $this->_end_controls_section(); /** * Caption Style Section */ $this->_start_controls_section( 'section_caption_style', array( 'label' => esc_html__( 'Caption', 'jet-elements' ), 'tab' => Controls_Manager::TAB_STYLE, 'show_label' => false, ) ); $this->_add_responsive_control( 'caption_alignment', array( 'label' => esc_html__( 'Alignment', 'jet-elements' ), 'type' => Controls_Manager::CHOOSE, 'default' => 'center', 'options' => array( 'flex-start' => array( 'title' => esc_html__( 'Start', 'jet-elements' ), 'icon' => ! is_rtl() ? 'eicon-h-align-left' : 'eicon-h-align-right', ), 'center' => array( 'title' => esc_html__( 'Center', 'jet-elements' ), 'icon' => 'eicon-h-align-center', ), 'flex-end' => array( 'title' => esc_html__( 'End', 'jet-elements' ), 'icon' => ! is_rtl() ? 'eicon-h-align-right' : 'eicon-h-align-left', ), ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['caption'] => 'align-self: {{VALUE}};', ), ) ); $this->_add_responsive_control( 'caption_text_alignment', array( 'label' => esc_html__( 'Text Alignment', 'jet-elements' ), 'type' => Controls_Manager::CHOOSE, 'default' => 'center', 'options' => array( 'left' => array( 'title' => esc_html__( 'Left', 'jet-elements' ), 'icon' => 'eicon-text-align-left', ), 'center' => array( 'title' => esc_html__( 'Center', 'jet-elements' ), 'icon' => 'eicon-text-align-center', ), 'right' => array( 'title' => esc_html__( 'Right', 'jet-elements' ), 'icon' => 'eicon-text-align-right', ), ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['caption'] => 'text-align: {{VALUE}};', ), 'classes' => 'jet-elements-text-align-control', ) ); $this->_add_responsive_control( 'caption_width', array( 'label' => esc_html__( 'Caption Width', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px', 'em', '%', 'custom' ), 'range' => array( 'px' => array( 'min' => 50, 'max' => 1000, ), '%' => array( 'min' => 0, 'max' => 100, ), ), 'default' => [ 'size' => 100, 'units' => '%' ], 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['caption'] => 'max-width: {{SIZE}}{{UNIT}};', ), ), 100 ); $this->_add_control( 'caption_color', array( 'label' => esc_html__( 'Color', 'jet-elements' ), 'type' => Controls_Manager::COLOR, 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['caption'] => 'color: {{VALUE}}', ), ), 25 ); $this->_add_group_control( Group_Control_Typography::get_type(), array( 'name' => 'caption_typography', 'selector' => '{{WRAPPER}} ' . $css_scheme['caption'], 'global' => array( 'default' => Global_Typography::TYPOGRAPHY_TEXT, ), ), 50 ); $this->_add_responsive_control( 'caption_padding', array( 'label' => __( 'Padding', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['caption'] => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 100 ); $this->_add_responsive_control( 'caption_margin', array( 'label' => __( 'Margin', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['caption'] => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 50 ); $this->_end_controls_section(); /** * Meta Style Section */ $this->_start_controls_section( 'section_meta_style', array( 'label' => esc_html__( 'Meta', 'jet-elements' ), 'tab' => Controls_Manager::TAB_STYLE, 'show_label' => false, ) ); $this->_add_responsive_control( 'meta_alignment', array( 'label' => esc_html__( 'Alignment', 'jet-elements' ), 'type' => Controls_Manager::CHOOSE, 'default' => 'center', 'options' => array( 'flex-start' => array( 'title' => esc_html__( 'Start', 'jet-elements' ), 'icon' => ! is_rtl() ? 'eicon-h-align-left' : 'eicon-h-align-right', ), 'center' => array( 'title' => esc_html__( 'Center', 'jet-elements' ), 'icon' => 'eicon-h-align-center', ), 'flex-end' => array( 'title' => esc_html__( 'End', 'jet-elements' ), 'icon' => ! is_rtl() ? 'eicon-h-align-right' : 'eicon-h-align-left', ), ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['meta'] => 'align-self: {{VALUE}};', ), ), 25 ); $this->_add_control( 'comments_icon', array( 'label' => esc_html__( 'Comments Icon', 'jet-elements' ), 'type' => Controls_Manager::ICON, 'label_block' => true, 'file' => '', 'default' => 'fa fa-comment', ), 50 ); $this->_add_control( 'likes_icon', array( 'label' => esc_html__( 'Likes Icon', 'jet-elements' ), 'type' => Controls_Manager::ICON, 'label_block' => true, 'file' => '', 'default' => 'fa fa-heart', ), 50 ); $this->_add_control( 'meta_icon_color', array( 'label' => esc_html__( 'Icon Color', 'jet-elements' ), 'type' => Controls_Manager::COLOR, 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['meta_icon'] => 'color: {{VALUE}}', ), ), 25 ); $this->_add_responsive_control( 'meta_icon_size', array( 'label' => esc_html__( 'Icon Size', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px', 'em', 'rem', 'custom' ), 'range' => array( 'px' => array( 'min' => 1, 'max' => 100, ), ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['meta_icon'] . ' i' => 'font-size: {{SIZE}}{{UNIT}}', ), ), 25 ); $this->_add_control( 'meta_label_color', array( 'label' => esc_html__( 'Text Color', 'jet-elements' ), 'type' => Controls_Manager::COLOR, 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['meta_label'] => 'color: {{VALUE}}', ), ), 25 ); $this->_add_group_control( Group_Control_Typography::get_type(), array( 'name' => 'meta_label_typography', 'selector' => '{{WRAPPER}} ' . $css_scheme['meta_label'], 'global' => array( 'default' => Global_Typography::TYPOGRAPHY_PRIMARY, ), ), 50 ); $this->_add_group_control( Group_Control_Background::get_type(), array( 'name' => 'meta_background', 'selector' => '{{WRAPPER}} ' . $css_scheme['meta'], ), 100 ); $this->_add_responsive_control( 'meta_padding', array( 'label' => __( 'Padding', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['meta'] => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 100 ); $this->_add_responsive_control( 'meta_margin', array( 'label' => __( 'Margin', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['meta'] => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 50 ); $this->_add_responsive_control( 'meta_item_margin', array( 'label' => __( 'Item Margin', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['meta_item'] => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 50 ); $this->_add_group_control( Group_Control_Border::get_type(), array( 'name' => 'meta_border', 'label' => esc_html__( 'Border', 'jet-elements' ), 'placeholder' => '1px', 'default' => '1px', 'selector' => '{{WRAPPER}} ' . $css_scheme['meta'], ), 100 ); $this->_add_responsive_control( 'meta_radius', array( 'label' => __( 'Border Radius', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['meta'] => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 100 ); $this->_add_group_control( Group_Control_Box_Shadow::get_type(), array( 'name' => 'meta_shadow', 'selector' => '{{WRAPPER}} ' . $css_scheme['meta'], ), 100 ); $this->_end_controls_section(); } protected function render() { $this->_context = 'render'; $this->_open_wrap(); include $this->_get_global_template( 'index' ); $this->_close_wrap(); } /** * Render gallery html. * * @return void */ public function render_gallery() { $settings = $this->get_settings_for_display(); if ( 'hashtag' === $settings['endpoint'] ) { if ( empty( $settings['hashtag'] ) ) { $this->print_notice( esc_html__( 'Please, enter #hashtag.', 'jet-elements' ) ); return; } if ( ! empty( $settings['use_insta_graph_api'] ) ) { $business_account_config = $this->get_business_account_config(); if ( empty( $business_account_config['token'] || empty( $business_account_config['user_id'] ) ) ) { $this->print_notice( esc_html__( 'Please, enter Business Access Token and User ID.', 'jet-elements' ) ); return; } } } if ( 'self' === $settings['endpoint'] && ! $this->get_access_token() ) { $this->print_notice( esc_html__( 'Please, enter Access Token.', 'jet-elements' ) ); return; } $html = ''; $col_class = ''; // Endpoint. $endpoint = $this->sanitize_endpoint(); switch ( $settings['cache_timeout'] ) { case 'none': $cache_timeout = 1; break; case 'minute': $cache_timeout = MINUTE_IN_SECONDS; break; case 'hour': $cache_timeout = HOUR_IN_SECONDS; break; case 'day': $cache_timeout = DAY_IN_SECONDS; break; case 'week': $cache_timeout = WEEK_IN_SECONDS; break; default: $cache_timeout = HOUR_IN_SECONDS; break; } $this->config = array( 'endpoint' => $endpoint, 'target' => ( 'hashtag' === $endpoint ) ? sanitize_text_field( $settings[ $endpoint ] ) : 'users', 'posts_counter' => $settings['posts_counter'], 'post_link' => filter_var( $settings['post_link'], FILTER_VALIDATE_BOOLEAN ), 'post_link_type' => $settings['post_link_type'], 'photo_size' => $settings['photo_size'], 'post_caption' => filter_var( $settings['post_caption'], FILTER_VALIDATE_BOOLEAN ), 'post_caption_length' => ! empty( $settings['post_caption_length'] ) ? $settings['post_caption_length'] : 50, 'post_comments_count' => filter_var( $settings['post_comments_count'], FILTER_VALIDATE_BOOLEAN ), 'post_likes_count' => filter_var( $settings['post_likes_count'], FILTER_VALIDATE_BOOLEAN ), 'cache_timeout' => $cache_timeout, 'use_graph_api' => isset( $settings['use_insta_graph_api'] ) ? filter_var( $settings['use_insta_graph_api'], FILTER_VALIDATE_BOOLEAN ) : false, 'order_by' => ! empty( $settings['order_by'] ) ? $settings['order_by'] : 'recent_media', ); $posts = $this->get_posts( $this->config ); if ( ! empty( $posts ) && ! is_wp_error( $posts ) ) { foreach ( $posts as $post_data ) { $item_html = ''; $link = ( 'hashtag' === $endpoint && ! $this->config['use_graph_api'] ) ? sprintf( $this->get_post_url(), $post_data['link'] ) : $post_data['link']; $the_image = $this->the_image( $post_data ); $the_caption = $this->the_caption( $post_data ); $the_meta = $this->the_meta( $post_data ); $item_html = sprintf( '', $the_image, $the_caption, $the_meta ); if ( $this->config['post_link'] ) { $link_format = '%2$s'; $link_format = apply_filters( 'jet-elements/instagram-gallery/link-format', $link_format ); $attr = ''; if ( 'lightbox' === $this->config['post_link_type'] ) { $lightbox_desc = $lightbox_desc = isset( $settings['lightbox_show_desc'] ) ? $settings['lightbox_show_desc'] : 'false'; $img_data = $this->get_image_data( $post_data, 'high' ); $link = $img_data['src']; $attr = ' data-elementor-open-lightbox="yes" data-elementor-lightbox-slideshow="' . $this->get_id() . '"'; if ( 'true' === $lightbox_desc ) { $attr .= ' data-elementor-lightbox-description="' . wp_strip_all_tags( $post_data['caption'] ) . '"'; } } $item_html = sprintf( $link_format, esc_url( $link ), $item_html, $attr ); } if ( 'grid' === $settings['layout_type'] ) { $col_class = jet_elements_tools()->col_classes( array( 'desk' => $settings['columns'], 'tab' => $settings['columns_tablet'], 'mob' => $settings['columns_mobile'], ) ); } $html .= sprintf( '', $col_class, $item_html ); } } else { $message = is_wp_error( $posts ) ? $posts->get_error_message() : esc_html__( 'Posts not found', 'jet-elements' ); $html .= sprintf( '', $message ); } echo $html; } /** * Print widget notice. * * @param $notice */ public function print_notice( $notice ) { if ( ! is_user_logged_in() ) { return; } printf( '', $notice ); } /** * Display a HTML link with image. * * @since 1.0.0 * @param array $item Item photo data. * @return string */ public function the_image( $item ) { $size = $this->get_settings_for_display( 'photo_size' ); $img_data = $this->get_image_data( $item, $size ); $width = $img_data['width']; $height = $img_data['height']; $post_photo_url = $img_data['src']; if ( empty( $post_photo_url ) ) { return ''; } $attr = ''; if ( ! empty( $width ) && ! empty( $height ) ) { $attr = ' width="' . esc_attr( $width ) . '" height="' . esc_attr( $height ) . '"'; } $photo_format = '%3$s'; $photo_format = apply_filters( 'jet-elements/instagram-gallery/photo-format', $photo_format ); $image = sprintf( $photo_format, esc_url( $post_photo_url ), $attr, esc_attr( $item['caption'] ) ); return $image; } /** * Get image data * * @param array $item Item photo data. * @param string $size Image size. * @return array */ public function get_image_data( $item, $size = 'high' ) { $thumbnail_resources = $item['thumbnail_resources']; if ( ! empty( $thumbnail_resources[ $size ] ) ) { $width = $thumbnail_resources[ $size ]['config_width']; $height = $thumbnail_resources[ $size ]['config_height']; $post_photo_url = $thumbnail_resources[ $size ]['src']; } else { $width = isset( $item['dimensions']['width'] ) ? $item['dimensions']['width'] : ''; $height = isset( $item['dimensions']['height'] ) ? $item['dimensions']['height'] : ''; $post_photo_url = isset( $item['image'] ) ? $item['image'] : ''; } return array( 'width' => $width, 'height' => $height, 'src' => $post_photo_url, ); } /** * Display a caption. * * @since 1.0.0 * @param array $item Item photo data. * @return string */ public function the_caption( $item ) { if ( ! $this->config['post_caption'] || empty( $item['caption'] ) ) { return; } $format = apply_filters( 'jet-elements/instagram-gallery/the-caption-format', '' ); return sprintf( $format, $item['caption'] ); } /** * Display a meta. * * @since 1.0.0 * @param array $item Item photo data. * @return string */ public function the_meta( $item ) { if ( ! $this->config['post_comments_count'] && ! $this->config['post_likes_count'] ) { return; } $meta_html = ''; if ( $this->config['post_comments_count'] ) { $meta_html .= sprintf( '', $this->get_settings_for_display( 'comments_icon' ), $item['comments'] ); } if ( $this->config['post_likes_count'] ) { $meta_html .= sprintf( '', $this->get_settings_for_display( 'likes_icon' ), $item['likes'] ); } $format = apply_filters( 'jet-elements/instagram-gallery/the-meta-format', '' ); return sprintf( $format, $meta_html ); } /** * Retrieve a photos. * * @since 1.0.0 * @param array $config Set of configuration. * @return array */ public function get_posts( $config ) { $transient_key = md5( $this->get_transient_key() ); $data = get_transient( $transient_key ); if ( ! empty( $data ) && 1 !== $config['cache_timeout'] && array_key_exists( 'thumbnail_resources', $data[0] ) ) { return $data; } if ( $config['use_graph_api'] ) { $response = $this->remote_get_from_qraph_api( $config ); } else { $response = $this->remote_get( $config ); } if ( is_wp_error( $response ) ) { return $response; } if ( 'hashtag' === $config['endpoint'] && ! $config['use_graph_api'] ) { $data = $this->get_response_data( $response ); } else { $data = $this->get_response_data_from_official_api( $response ); } if ( empty( $data ) ) { return array(); } set_transient( $transient_key, $data, $config['cache_timeout'] ); return $data; } /** * Retrieve the raw response from the HTTP request using the GET method from Graph API. * * @param array $config * * @return mixed|string|void|\WP_Error */ public function remote_get_from_qraph_api( $config ) { $account_config = $this->get_business_account_config(); $access_token = $account_config['token']; $user_id = $account_config['user_id']; $url = add_query_arg( array( 'user_id' => $user_id, 'q' => $config['target'], 'access_token' => $access_token, ), $this->graph_api_url . 'ig_hashtag_search' ); $response = wp_remote_get( $url, array( 'timeout' => 10 ) ); $body = wp_remote_retrieve_body( $response ); $body = json_decode( $body, true ); if ( ! is_array( $body ) ) { return new \WP_Error( 'invalid-data', esc_html__( 'Invalid data', 'jet-elements' ) ); } if ( isset( $body['error']['message'] ) ) { return new \WP_Error( 'invalid-data', $body['error']['message'] ); } if ( empty( $body['data'][0]['id'] ) ) { return new \WP_Error( 'invalid-data', esc_html__( 'Can\'t find the tag ID.', 'jet-elements' ) ); } $tag_id = $body['data'][0]['id']; $url = add_query_arg( array( 'user_id' => $user_id, 'access_token' => $access_token, 'limit' => 50, 'fields' => 'id,media_type,media_url,caption,comments_count,like_count,permalink,children{media_url,id,media_type,permalink}', ), $this->graph_api_url . $tag_id . '/' . $config['order_by'] ); $response = wp_remote_get( $url, array( 'timeout' => 10 ) ); $body = wp_remote_retrieve_body( $response ); $body = json_decode( $body, true ); if ( ! is_array( $body ) ) { return new \WP_Error( 'invalid-data', esc_html__( 'Invalid data', 'jet-elements' ) ); } if ( isset( $body['error']['message'] ) ) { return new \WP_Error( 'invalid-data', $body['error']['message'] ); } return $body; } /** * Retrieve the raw response from the HTTP request using the GET method. * * @since 1.0.0 * @return array|object */ public function remote_get( $config ) { $url = $this->get_grab_url( $config ); $response = wp_remote_get( $url, array( 'timeout' => 60, ) ); $response_code = wp_remote_retrieve_response_code( $response ); if ( 200 !== $response_code ) { $body = json_decode( wp_remote_retrieve_body( $response ), true ); if ( is_array( $body ) && isset( $body['error']['message'] ) ) { $message = $body['error']['message']; } else { $message = esc_html__( 'Posts not found', 'jet-elements' ); } return new \WP_Error( $response_code, $message ); } $result = json_decode( wp_remote_retrieve_body( $response ), true ); if ( ! is_array( $result ) ) { return new \WP_Error( 'invalid-data', esc_html__( 'Invalid data', 'jet-elements' ) ); } return $result; } /** * Get prepared response data. * * @param $response * * @return array */ public function get_response_data( $response ) { $key = 'hashtag' == $this->config['endpoint'] ? 'hashtag' : 'user'; if ( 'hashtag' === $key ) { $response = isset( $response['graphql'] ) ? $response['graphql'] : $response; } $response_items = ( 'hashtag' === $key ) ? $response[ $key ]['edge_hashtag_to_media']['edges'] : $response['graphql'][ $key ]['edge_owner_to_timeline_media']['edges']; if ( empty( $response_items ) ) { return array(); } $data = array(); $nodes = array_slice( $response_items, 0, $this->config['posts_counter'], true ); foreach ( $nodes as $post ) { $_post = array(); $_post['link'] = $post['node']['shortcode']; $_post['image'] = $post['node']['thumbnail_src']; $_post['caption'] = isset( $post['node']['edge_media_to_caption']['edges'][0]['node']['text'] ) ? wp_html_excerpt( $post['node']['edge_media_to_caption']['edges'][0]['node']['text'], $this->config['post_caption_length'], '…' ) : ''; $_post['comments'] = $post['node']['edge_media_to_comment']['count']; $_post['likes'] = $post['node']['edge_liked_by']['count']; $_post['dimensions'] = $post['node']['dimensions']; $_post['thumbnail_resources'] = $this->_generate_thumbnail_resources( $post ); array_push( $data, $_post ); } return $data; } /** * Get prepared response data from official api. * * @param $response * * @return array */ public function get_response_data_from_official_api( $response ) { if ( ! isset( $response['data'] ) ) { return array(); } $response_items = $response['data']; if ( empty( $response_items ) ) { return array(); } if ( $this->config['use_graph_api'] ) { $response_items = $this->remove_video_items( $response_items ); } $data = array(); $nodes = array_slice( $response_items, 0, $this->config['posts_counter'], true ); foreach ( $nodes as $post ) { $media_url = ! empty( $post['media_url'] ) ? $post['media_url'] : ''; switch ( $post['media_type'] ) { case 'VIDEO': $media_url = ! empty( $post['thumbnail_url'] ) ? $post['thumbnail_url'] : ''; break; case 'CAROUSEL_ALBUM': $media_url = ! empty( $post['children']['data'][0]['media_url'] ) ? $post['children']['data'][0]['media_url'] : $media_url; break; } $_post = array(); $_post['link'] = $post['permalink']; $_post['image'] = $media_url; $_post['caption'] = ! empty( $post['caption'] ) ? wp_html_excerpt( $post['caption'], $this->config['post_caption_length'], '…' ) : ''; $_post['comments'] = ! empty( $post['comments_count'] ) ? $post['comments_count'] : 0; // TODO: available only for Graph Api $_post['likes'] = ! empty( $post['like_count'] ) ? $post['like_count'] : 0; // TODO: available only for Graph Api $_post['thumbnail_resources'] = $this->_generate_thumbnail_resources_from_official_api( $post ); // TODO: this data now not available array_push( $data, $_post ); } return $data; } /** * Remove video items. * * @param array $data * @return array */ public function remove_video_items( $data ) { $result = array(); foreach ( $data as $item ) { if ( ! empty( $item['media_type'] ) && 'VIDEO' === $item['media_type'] ) { continue; } if ( ! empty( $item['children']['data'] ) ) { $item['children']['data'] = $this->remove_video_items( $item['children']['data'] ); if ( empty( $item['children']['data'] ) ) { continue; } } $result[] = $item; } return $result; } /** * Generate thumbnail resources. * * @param $post_data * * @return array */ public function _generate_thumbnail_resources( $post_data ) { $post_data = $post_data['node']; $thumbnail_resources = array( 'thumbnail' => false, 'low' => false, 'standard' => false, 'high' => false, ); if ( ! empty( $post_data['thumbnail_resources'] ) && is_array( $post_data['thumbnail_resources'] ) ) { foreach ( $post_data['thumbnail_resources'] as $key => $resources_data ) { if ( 150 === $resources_data['config_width'] ) { $thumbnail_resources['thumbnail'] = $resources_data; continue; } if ( 320 === $resources_data['config_width'] ) { $thumbnail_resources['low'] = $resources_data; continue; } if ( 640 === $resources_data['config_width'] ) { $thumbnail_resources['standard'] = $resources_data; continue; } } } if ( ! empty( $post_data['display_url'] ) ) { $thumbnail_resources['high'] = array( 'src' => $post_data['display_url'], 'config_width' => $post_data['dimensions']['width'], 'config_height' => $post_data['dimensions']['height'], ) ; } return $thumbnail_resources; } /** * Generate thumbnail resources from official api. * * @param $post_data * * @return array */ public function _generate_thumbnail_resources_from_official_api( $post_data ) { $thumbnail_resources = array( 'thumbnail' => false, 'low' => false, 'standard' => false, 'high' => false, ); if ( ! empty( $post_data['images'] ) && is_array( $post_data['images'] ) ) { $thumbnails_data = $post_data['images']; $thumbnail_resources['thumbnail'] = array( 'src' => $thumbnails_data['thumbnail']['url'], 'config_width' => $thumbnails_data['thumbnail']['width'], 'config_height' => $thumbnails_data['thumbnail']['height'], ); $thumbnail_resources['low'] = array( 'src' => $thumbnails_data['low_resolution']['url'], 'config_width' => $thumbnails_data['low_resolution']['width'], 'config_height' => $thumbnails_data['low_resolution']['height'], ); $thumbnail_resources['standard'] = array( 'src' => $thumbnails_data['standard_resolution']['url'], 'config_width' => $thumbnails_data['standard_resolution']['width'], 'config_height' => $thumbnails_data['standard_resolution']['height'], ); $thumbnail_resources['high'] = $thumbnail_resources['standard']; } return $thumbnail_resources; } /** * Retrieve a grab URL. * * @since 1.0.0 * @return string */ public function get_grab_url( $config ) { if ( 'hashtag' == $config['endpoint'] ) { $url = sprintf( $this->get_tags_url(), $config['target'] ); $url = add_query_arg( array( '__a' => 1 ), $url ); } else { $url = $this->get_self_url(); $url = add_query_arg( array( 'fields' => 'id,media_type,media_url,thumbnail_url,permalink,caption', 'access_token' => $this->get_access_token(), ), $url ); } return $url; } /** * Retrieve a URL for photos by hashtag. * * @since 1.0.0 * @return string */ public function get_tags_url() { return apply_filters( 'jet-elements/instagram-gallery/get-tags-url', $this->api_url . 'explore/tags/%s/' ); } /** * Retrieve a URL for self photos. * * @since 1.0.0 * @return string */ public function get_self_url() { return apply_filters( 'jet-elements/instagram-gallery/get-self-url', $this->new_api_url . 'me/media/' ); } /** * Retrieve a URL for post. * * @since 1.0.0 * @return string */ public function get_post_url() { return apply_filters( 'jet-elements/instagram-gallery/get-post-url', $this->api_url . 'p/%s/' ); } /** * sanitize endpoint. * * @since 1.0.0 * @return string */ public function sanitize_endpoint() { return in_array( $this->get_settings( 'endpoint' ) , array( 'hashtag', 'self' ) ) ? $this->get_settings( 'endpoint' ) : 'hashtag'; } /** * Retrieve a photo sizes (in px) by option name. * * @since 1.0.0 * @param string $photo_size Photo size. * @return array */ public function _get_relation_photo_size( $photo_size ) { switch ( $photo_size ) { case 'high': $size = array(); break; case 'standard': $size = array( 640, 640 ); break; case 'low': $size = array( 320, 320 ); break; default: $size = array( 150, 150 ); break; } return apply_filters( 'jet-elements/instagram-gallery/relation-photo-size', $size, $photo_size ); } /** * Get transient key. * * @since 1.0.0 * @return string */ public function get_transient_key() { return sprintf( 'jet_elements_instagram_%s_%s%s_posts_count_%s_caption_%s', $this->config['endpoint'], $this->config['target'], $this->config['use_graph_api'] ? '_order_' . $this->config['order_by'] : '', $this->config['posts_counter'], $this->config['post_caption_length'] ); } /** * Generate setting json * * @return string */ public function generate_setting_json() { $module_settings = $this->get_settings(); $settings = array( 'layoutType' => $module_settings['layout_type'], 'columns' => $module_settings['columns'], 'columnsTablet' => $module_settings['columns_tablet'], 'columnsMobile' => $module_settings['columns_mobile'], ); $settings = json_encode( $settings ); return sprintf( 'data-settings=\'%1$s\'', $settings ); } /** * Get access token. * * @return string */ public function get_access_token() { if ( ! $this->access_token ) { $source = $this->get_settings( 'access_token_source' ); if ( 'custom' === $source ) { $this->access_token = $this->get_settings( 'custom_access_token' ); } else { $this->access_token = jet_elements_settings()->get( 'insta_access_token' ); } } return $this->access_token; } /** * Get business account config. * * @return array */ public function get_business_account_config() { if ( ! $this->business_account_config ) { $this->business_account_config['token'] = jet_elements_settings()->get( 'insta_business_access_token' ); $this->business_account_config['user_id'] = jet_elements_settings()->get( 'insta_business_user_id' ); } return $this->business_account_config; } /** * Get access token from the plugin settings. * * @return string */ public function get_access_token_from_settings() { return jet_elements_settings()->get( 'insta_access_token' ); } } ment_corner_width', array( 'label' => esc_html__( 'Corner Width', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px', 'custom' ), 'range' => array( 'px' => array( 'min' => 0, 'max' => 50, ), ), 'default' => array( 'size' => 10, 'unit' => 'px', ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['comment'] . ':after' => 'border-right-width: {{SIZE}}{{UNIT}}; margin-left: calc({{SIZE}}{{UNIT}}/-2);', ), 'condition' => array( 'use_comment_corner' => 'yes', ), ), 75 ); $this->_add_responsive_control( 'comment_corner_height', array( 'label' => esc_html__( 'Corner Height', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px', 'custom' ), 'range' => array( 'px' => array( 'min' => 0, 'max' => 50, ), ), 'default' => array( 'size' => 10, 'unit' => 'px', ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['comment'] . ':after' => 'border-top-width: {{SIZE}}{{UNIT}}; bottom: -{{SIZE}}{{UNIT}};', ), 'condition' => array( 'use_comment_corner' => 'yes', ), ), 75 ); $this->_add_responsive_control( 'comment_corner_skew', array( 'label' => esc_html__( 'Corner Skew', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px', 'custom' ), 'range' => array( 'px' => array( 'min' => 0, 'max' => 50, ), ), 'default' => array( 'size' => 10, 'unit' => 'px', ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['comment'] . ':after' => 'border-left-width: {{SIZE}}{{UNIT}};', ), 'condition' => array( 'use_comment_corner' => 'yes', ), ), 75 ); $this->_add_group_control( Group_Control_Background::get_type(), array( 'name' => 'comment_background', 'selector' => '{{WRAPPER}} ' . $css_scheme['comment'], 'fields_options' => array( 'color' => array( 'global' => array( 'default' => Global_Colors::COLOR_PRIMARY, ), ), ), ), 25 ); $this->_add_responsive_control( 'comment_padding', array( 'label' => __( 'Padding', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'default' => array( 'top' => 25, 'right' => 15, 'bottom' => 25, 'left' => 15, ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['comment'] => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 50 ); $this->_add_responsive_control( 'comment_margin', array( 'label' => __( 'Margin', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['comment'] => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 100 ); $this->_add_group_control( Group_Control_Border::get_type(), array( 'name' => 'comment_border', 'label' => esc_html__( 'Border', 'jet-elements' ), 'placeholder' => '1px', 'default' => '1px', 'selector' => '{{WRAPPER}} ' . $css_scheme['comment'], ), 75 ); $this->_add_control( 'comment_border_radius', array( 'label' => esc_html__( 'Border Radius', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'default' => array( 'top' => 5, 'right' => 5, 'bottom' => 5, 'left' => 5, ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['comment'] => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 75 ); $this->_add_group_control( Group_Control_Box_Shadow::get_type(), array( 'name' => 'comment_shadow', 'selector' => '{{WRAPPER}} ' . $css_scheme['comment'], ), 100 ); $this->_end_controls_section(); /** * Name Style Section */ $this->_start_controls_section( 'section_name_style', array( 'label' => esc_html__( 'Name', 'jet-elements' ), 'tab' => Controls_Manager::TAB_STYLE, 'show_label' => false, ) ); $this->_add_responsive_control( 'name_alignment', array( 'label' => esc_html__( 'Alignment', 'jet-elements' ), 'type' => Controls_Manager::CHOOSE, 'default' => 'center', 'options' => array( 'flex-start' => array( 'title' => esc_html__( 'Start', 'jet-elements' ), 'icon' => ! is_rtl() ? 'eicon-h-align-left' : 'eicon-h-align-right', ), 'center' => array( 'title' => esc_html__( 'Center', 'jet-elements' ), 'icon' => 'eicon-h-align-center', ), 'flex-end' => array( 'title' => esc_html__( 'End', 'jet-elements' ), 'icon' => ! is_rtl() ? 'eicon-h-align-right' : 'eicon-h-align-left', ), ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['name'] => 'align-self: {{VALUE}};', ), ), 50 ); $this->_add_responsive_control( 'name_text_alignment', array( 'label' => esc_html__( 'Text Alignment', 'jet-elements' ), 'type' => Controls_Manager::CHOOSE, 'default' => 'center', 'options' => array( 'left' => array( 'title' => esc_html__( 'Left', 'jet-elements' ), 'icon' => 'fa fa-align-left', ), 'center' => array( 'title' => esc_html__( 'Center', 'jet-elements' ), 'icon' => 'fa fa-align-center', ), 'right' => array( 'title' => esc_html__( 'Right', 'jet-elements' ), 'icon' => 'fa fa-align-right', ), ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['name'] => 'text-align: {{VALUE}};', ), 'classes' => 'jet-elements-text-align-control', ), 50 ); $this->_add_control( 'name_custom_width', array( 'label' => esc_html__( 'Custom width', 'jet-elements' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'jet-elements' ), 'label_off' => esc_html__( 'No', 'jet-elements' ), 'return_value' => 'yes', 'default' => 'false', ), 100 ); $this->_add_responsive_control( 'name_width', array( 'label' => esc_html__( 'Width', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px', '%', 'custom' ), 'range' => array( 'px' => array( 'min' => 10, 'max' => 1000, ), '%' => array( 'min' => 0, 'max' => 100, ), ), 'default' => array( 'size' => 350, 'unit' => 'px', ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['name'] => 'width: {{SIZE}}{{UNIT}};', ), 'condition' => array( 'name_custom_width' => 'yes', ), ), 100 ); $this->_add_control( 'name_color', array( 'label' => esc_html__( 'Color', 'jet-elements' ), 'type' => Controls_Manager::COLOR, 'global' => array( 'default' => Global_Colors::COLOR_SECONDARY, ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['name'] => 'color: {{VALUE}}', ), ), 25 ); $this->_add_control( 'name_hover_color', array( 'label' => esc_html__( 'Hover Color', 'jet-elements' ), 'type' => Controls_Manager::COLOR, 'global' => array( 'default' => Global_Colors::COLOR_SECONDARY, ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['name'] . ' a:hover' => 'color: {{VALUE}}', ), ), 25 ); $this->_add_group_control( Group_Control_Typography::get_type(), array( 'name' => 'name_typography', 'selector' => '{{WRAPPER}} ' . $css_scheme['name'], 'global' => array( 'default' => Global_Typography::TYPOGRAPHY_PRIMARY, ), ), 50 ); $this->_add_responsive_control( 'name_padding', array( 'label' => __( 'Padding', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['name'] => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 100 ); $this->_add_responsive_control( 'name_margin', array( 'label' => __( 'Margin', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['name'] => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 50 ); $this->_end_controls_section(); /** * Position Style Section */ $this->_start_controls_section( 'section_position_style', array( 'label' => esc_html_x( 'Position', 'Position at work', 'jet-elements' ), 'tab' => Controls_Manager::TAB_STYLE, 'show_label' => false, ) ); $this->_add_responsive_control( 'position_alignment', array( 'label' => esc_html__( 'Alignment', 'jet-elements' ), 'type' => Controls_Manager::CHOOSE, 'default' => 'center', 'options' => array( 'flex-start' => array( 'title' => esc_html__( 'Start', 'jet-elements' ), 'icon' => ! is_rtl() ? 'eicon-h-align-left' : 'eicon-h-align-right', ), 'center' => array( 'title' => esc_html__( 'Center', 'jet-elements' ), 'icon' => 'eicon-h-align-center', ), 'flex-end' => array( 'title' => esc_html__( 'End', 'jet-elements' ), 'icon' => ! is_rtl() ? 'eicon-h-align-right' : 'eicon-h-align-left', ), ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['position'] => 'align-self: {{VALUE}};', ), ), 50 ); $this->_add_responsive_control( 'position_text_alignment', array( 'label' => esc_html__( 'Text Alignment', 'jet-elements' ), 'type' => Controls_Manager::CHOOSE, 'default' => 'center', 'options' => array( 'left' => array( 'title' => esc_html__( 'Left', 'jet-elements' ), 'icon' => 'fa fa-align-left', ), 'center' => array( 'title' => esc_html__( 'Center', 'jet-elements' ), 'icon' => 'fa fa-align-center', ), 'right' => array( 'title' => esc_html__( 'Right', 'jet-elements' ), 'icon' => 'fa fa-align-right', ), ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['position'] => 'text-align: {{VALUE}};', ), 'classes' => 'jet-elements-text-align-control', ), 50 ); $this->_add_control( 'position_custom_width', array( 'label' => esc_html__( 'Custom width', 'jet-elements' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'jet-elements' ), 'label_off' => esc_html__( 'No', 'jet-elements' ), 'return_value' => 'yes', 'default' => 'false', ), 100 ); $this->_add_responsive_control( 'position_width', array( 'label' => esc_html__( 'Width', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px', '%', 'custom' ), 'range' => array( 'px' => array( 'min' => 10, 'max' => 1000, ), '%' => array( 'min' => 0, 'max' => 100, ), ), 'default' => array( 'size' => 350, 'unit' => 'px', ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['position'] => 'width: {{SIZE}}{{UNIT}};', ), 'condition' => array( 'position_custom_width' => 'yes', ), ), 100 ); $this->_add_control( 'position_color', array( 'label' => esc_html__( 'Color', 'jet-elements' ), 'type' => Controls_Manager::COLOR, 'global' => array( 'default' => Global_Colors::COLOR_PRIMARY, ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['position'] => 'color: {{VALUE}}', ), ), 25 ); $this->_add_group_control( Group_Control_Typography::get_type(), array( 'name' => 'position_typography', 'selector' => '{{WRAPPER}} ' . $css_scheme['position'], 'global' => array( 'default' => Global_Typography::TYPOGRAPHY_PRIMARY, ), ), 50 ); $this->_add_responsive_control( 'position_padding', array( 'label' => __( 'Padding', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['position'] => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 100 ); $this->_add_responsive_control( 'position_margin', array( 'label' => __( 'Margin', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['position'] => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 50 ); $this->_end_controls_section(); /** * Date Style Section */ $this->_start_controls_section( 'section_date_style', array( 'label' => esc_html__( 'Date', 'jet-elements' ), 'tab' => Controls_Manager::TAB_STYLE, 'show_label' => false, ) ); $this->_add_responsive_control( 'date_alignment', array( 'label' => esc_html__( 'Alignment', 'jet-elements' ), 'type' => Controls_Manager::CHOOSE, 'default' => 'center', 'options' => array( 'flex-start' => array( 'title' => esc_html__( 'Start', 'jet-elements' ), 'icon' => ! is_rtl() ? 'eicon-h-align-left' : 'eicon-h-align-right', ), 'center' => array( 'title' => esc_html__( 'Center', 'jet-elements' ), 'icon' => 'eicon-h-align-center', ), 'flex-end' => array( 'title' => esc_html__( 'End', 'jet-elements' ), 'icon' => ! is_rtl() ? 'eicon-h-align-right' : 'eicon-h-align-left', ), ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['date'] => 'align-self: {{VALUE}};', ), ), 50 ); $this->_add_responsive_control( 'date_text_alignment', array( 'label' => esc_html__( 'Text Alignment', 'jet-elements' ), 'type' => Controls_Manager::CHOOSE, 'default' => 'center', 'options' => array( 'left' => array( 'title' => esc_html__( 'Left', 'jet-elements' ), 'icon' => 'fa fa-align-left', ), 'center' => array( 'title' => esc_html__( 'Center', 'jet-elements' ), 'icon' => 'fa fa-align-center', ), 'right' => array( 'title' => esc_html__( 'Right', 'jet-elements' ), 'icon' => 'fa fa-align-right', ), ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['date'] => 'text-align: {{VALUE}};', ), 'classes' => 'jet-elements-text-align-control', ), 50 ); $this->_add_control( 'date_custom_width', array( 'label' => esc_html__( 'Custom width', 'jet-elements' ), 'type' => Controls_Manager::SWITCHER, 'label_on' => esc_html__( 'Yes', 'jet-elements' ), 'label_off' => esc_html__( 'No', 'jet-elements' ), 'return_value' => 'yes', 'default' => 'false', ), 100 ); $this->_add_responsive_control( 'date_width', array( 'label' => esc_html__( 'Width', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px', '%', 'custom' ), 'range' => array( 'px' => array( 'min' => 10, 'max' => 1000, ), '%' => array( 'min' => 0, 'max' => 100, ), ), 'default' => array( 'size' => 350, 'unit' => 'px', ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['date'] => 'width: {{SIZE}}{{UNIT}};', ), 'condition' => array( 'date_custom_width' => 'yes', ), ), 100 ); $this->_add_control( 'date_color', array( 'label' => esc_html__( 'Color', 'jet-elements' ), 'type' => Controls_Manager::COLOR, 'global' => array( 'default' => Global_Colors::COLOR_TEXT, ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['date'] => 'color: {{VALUE}}', ), ), 25 ); $this->_add_group_control( Group_Control_Typography::get_type(), array( 'name' => 'date_typography', 'selector' => '{{WRAPPER}} ' . $css_scheme['date'], 'global' => array( 'default' => Global_Typography::TYPOGRAPHY_PRIMARY, ), ), 50 ); $this->_add_responsive_control( 'date_padding', array( 'label' => __( 'Padding', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['date'] => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 100 ); $this->_add_responsive_control( 'date_margin', array( 'label' => __( 'Margin', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'custom' ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['date'] => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 50 ); $this->_end_controls_section(); /** * Rating Style Section */ $this->_start_controls_section( 'section_rating_style', array( 'label' => esc_html__( 'Rating', 'jet-elements' ), 'tab' => Controls_Manager::TAB_STYLE, 'show_label' => false, ) ); $this->_add_control( 'star_color', array( 'label' => esc_html__( 'Stars', 'jet-elements' ), 'type' => Controls_Manager::COLOR, 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['rating'] . ' i' => 'color: {{VALUE}}', ), ), 25 ); $this->_add_control( 'rating_active_star_color', array( 'label' => esc_html__( 'Active Stars', 'jet-elements' ), 'type' => Controls_Manager::COLOR, 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['rating'] => 'color: {{VALUE}}', ), ), 25 ); $this->_add_responsive_control( 'rating_icon_size', array( 'label' => esc_html__( 'Size', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'default' => array( 'unit' => 'px', 'size' => '20', ), 'render_type' => 'template', 'range' => array( 'px' => array( 'min' => 0, 'max' => 100, ), ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['rating'] => 'font-size: {{SIZE}}{{UNIT}}', ), ), 50 ); $this->_add_responsive_control( 'rating_icon_space', array( 'label' => esc_html__( 'Spacing', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'default' => array( 'unit' => 'px', 'size' => '7', ), 'range' => array( 'px' => array( 'min' => 0, 'max' => 50, ), ), 'selectors' => array( 'body:not(.rtl) {{WRAPPER}} i:not(:last-of-type)' => 'margin-right: {{SIZE}}{{UNIT}}', 'body.rtl {{WRAPPER}} i:not(:last-of-type)' => 'margin-left: {{SIZE}}{{UNIT}}', ), ), 25 ); $this->_add_control( 'rating_star_margin', array( 'label' => esc_html__( 'Margin', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', 'custom' ), 'render_type' => 'template', 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['rating'] => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 50 ); $this->_end_controls_section(); /* * Arrows section */ $this->_start_controls_section( 'section_arrows_style', array( 'label' => esc_html__( 'Arrows', 'jet-elements' ), 'tab' => Controls_Manager::TAB_STYLE, 'show_label' => false, ) ); $this->_start_controls_tabs( 'tabs_arrows_style' ); $this->_start_controls_tab( 'tab_arrows_normal', array( 'label' => esc_html__( 'Normal', 'jet-elements' ), ) ); $this->_add_group_control( \Jet_Group_Control_Box_Style::get_type(), array( 'name' => 'arrows_style', 'label' => esc_html__( 'Arrows Style', 'jet-elements' ), 'selector' => '{{WRAPPER}} ' . $css_scheme['arrow'], 'fields_options' => array( 'color' => array( 'global' => array( 'default' => Global_Colors::COLOR_PRIMARY, ), ), ), ), 25 ); $this->_end_controls_tab(); $this->_start_controls_tab( 'tab_arrows_hover', array( 'label' => esc_html__( 'Hover', 'jet-elements' ), ) ); $this->_add_group_control( \Jet_Group_Control_Box_Style::get_type(), array( 'name' => 'arrows_hover_style', 'label' => esc_html__( 'Arrows Style', 'jet-elements' ), 'selector' => '{{WRAPPER}} ' . $css_scheme['arrow'] . ':hover', 'fields_options' => array( 'color' => array( 'global' => array( 'default' => Global_Colors::COLOR_ACCENT, ), ), ), ), 25 ); $this->_end_controls_tab(); $this->_end_controls_tabs(); $this->_add_control( 'prev_arrow_position', array( 'label' => esc_html__( 'Prev Arrow Position', 'jet-elements' ), 'type' => Controls_Manager::HEADING, 'separator' => 'before', ), 75 ); $this->_add_control( 'prev_vert_position', array( 'label' => esc_html__( 'Vertical Position by', 'jet-elements' ), 'type' => Controls_Manager::SELECT, 'default' => 'top', 'options' => array( 'top' => esc_html__( 'Top', 'jet-elements' ), 'bottom' => esc_html__( 'Bottom', 'jet-elements' ), ), ), 75 ); $this->_add_responsive_control( 'prev_top_position', array( 'label' => esc_html__( 'Top Indent', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px', '%', 'em', 'custom' ), 'range' => array( 'px' => array( 'min' => -400, 'max' => 400, ), '%' => array( 'min' => -100, 'max' => 100, ), 'em' => array( 'min' => -50, 'max' => 50, ), ), 'condition' => array( 'prev_vert_position' => 'top', ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['arrow'] . '.prev-arrow' => 'top: {{SIZE}}{{UNIT}}; bottom: auto;', ), ), 75 ); $this->_add_responsive_control( 'prev_bottom_position', array( 'label' => esc_html__( 'Bottom Indent', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px', '%', 'em', 'custom' ), 'range' => array( 'px' => array( 'min' => -400, 'max' => 400, ), '%' => array( 'min' => -100, 'max' => 100, ), 'em' => array( 'min' => -50, 'max' => 50, ), ), 'condition' => array( 'prev_vert_position' => 'bottom', ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['arrow'] . '.prev-arrow' => 'bottom: {{SIZE}}{{UNIT}}; top: auto;', ), ), 75 ); $this->_add_control( 'prev_hor_position', array( 'label' => esc_html__( 'Horizontal Position by', 'jet-elements' ), 'type' => Controls_Manager::SELECT, 'default' => 'left', 'options' => array( 'left' => esc_html__( 'Left', 'jet-elements' ), 'right' => esc_html__( 'Right', 'jet-elements' ), ), ), 75 ); $this->_add_responsive_control( 'prev_left_position', array( 'label' => esc_html__( 'Left Indent', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px', '%', 'em', 'custom' ), 'range' => array( 'px' => array( 'min' => -400, 'max' => 400, ), '%' => array( 'min' => -100, 'max' => 100, ), 'em' => array( 'min' => -50, 'max' => 50, ), ), 'condition' => array( 'prev_hor_position' => 'left', ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['arrow'] . '.prev-arrow' => 'left: {{SIZE}}{{UNIT}}; right: auto;', ), ), 75 ); $this->_add_responsive_control( 'prev_right_position', array( 'label' => esc_html__( 'Right Indent', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px', '%', 'em', 'custom' ), 'range' => array( 'px' => array( 'min' => -400, 'max' => 400, ), '%' => array( 'min' => -100, 'max' => 100, ), 'em' => array( 'min' => -50, 'max' => 50, ), ), 'condition' => array( 'prev_hor_position' => 'right', ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['arrow'] . '.prev-arrow' => 'right: {{SIZE}}{{UNIT}}; left: auto;', ), ), 75 ); $this->_add_control( 'next_arrow_position', array( 'label' => esc_html__( 'Next Arrow Position', 'jet-elements' ), 'type' => Controls_Manager::HEADING, 'separator' => 'before', ), 75 ); $this->_add_control( 'next_vert_position', array( 'label' => esc_html__( 'Vertical Position by', 'jet-elements' ), 'type' => Controls_Manager::SELECT, 'default' => 'top', 'options' => array( 'top' => esc_html__( 'Top', 'jet-elements' ), 'bottom' => esc_html__( 'Bottom', 'jet-elements' ), ), ), 75 ); $this->_add_responsive_control( 'next_top_position', array( 'label' => esc_html__( 'Top Indent', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px', '%', 'em', 'custom' ), 'range' => array( 'px' => array( 'min' => -400, 'max' => 400, ), '%' => array( 'min' => -100, 'max' => 100, ), 'em' => array( 'min' => -50, 'max' => 50, ), ), 'condition' => array( 'next_vert_position' => 'top', ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['arrow'] . '.next-arrow' => 'top: {{SIZE}}{{UNIT}}; bottom: auto;', ), ), 75 ); $this->_add_responsive_control( 'next_bottom_position', array( 'label' => esc_html__( 'Bottom Indent', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px', '%', 'em', 'custom' ), 'range' => array( 'px' => array( 'min' => -400, 'max' => 400, ), '%' => array( 'min' => -100, 'max' => 100, ), 'em' => array( 'min' => -50, 'max' => 50, ), ), 'condition' => array( 'next_vert_position' => 'bottom', ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['arrow'] . '.next-arrow' => 'bottom: {{SIZE}}{{UNIT}}; top: auto;', ), ), 75 ); $this->_add_control( 'next_hor_position', array( 'label' => esc_html__( 'Horizontal Position by', 'jet-elements' ), 'type' => Controls_Manager::SELECT, 'default' => 'right', 'options' => array( 'left' => esc_html__( 'Left', 'jet-elements' ), 'right' => esc_html__( 'Right', 'jet-elements' ), ), ), 75 ); $this->_add_responsive_control( 'next_left_position', array( 'label' => esc_html__( 'Left Indent', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px', '%', 'em', 'custom' ), 'range' => array( 'px' => array( 'min' => -400, 'max' => 400, ), '%' => array( 'min' => -100, 'max' => 100, ), 'em' => array( 'min' => -50, 'max' => 50, ), ), 'condition' => array( 'next_hor_position' => 'left', ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['arrow'] . '.next-arrow' => 'left: {{SIZE}}{{UNIT}}; right: auto;', ), ), 75 ); $this->_add_responsive_control( 'next_right_position', array( 'label' => esc_html__( 'Right Indent', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px', '%', 'em', 'custom' ), 'range' => array( 'px' => array( 'min' => -400, 'max' => 400, ), '%' => array( 'min' => -100, 'max' => 100, ), 'em' => array( 'min' => -50, 'max' => 50, ), ), 'condition' => array( 'next_hor_position' => 'right', ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['arrow'] . '.next-arrow' => 'right: {{SIZE}}{{UNIT}}; left: auto;', ), ), 75 ); $this->_end_controls_section(); /* * Dots section */ $this->_start_controls_section( 'section_dots_style', array( 'label' => esc_html__( 'Dots', 'jet-elements' ), 'tab' => Controls_Manager::TAB_STYLE, 'show_label' => false, ) ); $this->_add_responsive_control( 'dots_alignment', array( 'label' => esc_html__( 'Alignment', 'jet-elements' ), 'type' => Controls_Manager::CHOOSE, 'default' => 'center', 'options' => array( 'flex-start' => array( 'title' => esc_html__( 'Start', 'jet-elements' ), 'icon' => ! is_rtl() ? 'eicon-h-align-left' : 'eicon-h-align-right', ), 'center' => array( 'title' => esc_html__( 'Center', 'jet-elements' ), 'icon' => 'eicon-h-align-center', ), 'flex-end' => array( 'title' => esc_html__( 'End', 'jet-elements' ), 'icon' => ! is_rtl() ? 'eicon-h-align-right' : 'eicon-h-align-left', ), ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['dots'] => 'justify-content: {{VALUE}};', ), ), 25 ); $this->_add_control( 'dots_gap', array( 'label' => esc_html__( 'Gap', 'jet-elements' ), 'type' => Controls_Manager::SLIDER, 'default' => array( 'size' => 5, 'unit' => 'px', ), 'range' => array( 'px' => array( 'min' => 0, 'max' => 50, ), ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['dots'] . ' li' => 'padding-left: {{SIZE}}{{UNIT}}; padding-right: {{SIZE}}{{UNIT}}', ), ), 25 ); $this->_add_control( 'dots_margin', array( 'label' => esc_html__( 'Dots Box Margin', 'jet-elements' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => array( 'px', '%', 'em', 'custom' ), 'selectors' => array( '{{WRAPPER}} ' . $css_scheme['dots'] => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ), ), 50 ); $this->_start_controls_tabs( 'tabs_dots_style' ); $this->_start_controls_tab( 'tab_dots_normal', array( 'label' => esc_html__( 'Normal', 'jet-elements' ), ) ); $this->_add_group_control( \Jet_Group_Control_Box_Style::get_type(), array( 'name' => 'dots_style', 'label' => esc_html__( 'Dots Style', 'jet-elements' ), 'selector' => '{{WRAPPER}} ' . $css_scheme['dots'] .' li span', 'fields_options' => array( 'color' => array( 'global' => array( 'default' => Global_Colors::COLOR_TEXT, ), ), ), 'exclude' => array( 'box_font_color', 'box_font_size', ), ), 25 ); $this->_end_controls_tab(); $this->_start_controls_tab( 'tab_dots_hover', array( 'label' => esc_html__( 'Hover', 'jet-elements' ), ) ); $this->_add_group_control( \Jet_Group_Control_Box_Style::get_type(), array( 'name' => 'dots_style_hover', 'label' => esc_html__( 'Dots Style', 'jet-elements' ), 'selector' => '{{WRAPPER}} ' . $css_scheme['dots'] . ' li span:hover', 'fields_options' => array( 'color' => array( 'global' => array( 'default' => Global_Colors::COLOR_PRIMARY, ), ), ), 'exclude' => array( 'box_font_color', 'box_font_size', ), ), 25 ); $this->_end_controls_tab(); $this->_start_controls_tab( 'tab_dots_active', array( 'label' => esc_html__( 'Active', 'jet-elements' ), ) ); $this->_add_group_control( \Jet_Group_Control_Box_Style::get_type(), array( 'name' => 'dots_style_active', 'label' => esc_html__( 'Dots Style', 'jet-elements' ), 'selector' => '{{WRAPPER}} ' . $css_scheme['dots'] .' li.slick-active span', 'fields_options' => array( 'color' => array( 'global' => array( 'default' => Global_Colors::COLOR_ACCENT, ), ), ), 'exclude' => array( 'box_font_color', 'box_font_size', ), ), 25 ); $this->_end_controls_tab(); $this->_end_controls_tabs(); $this->_end_controls_section(); } protected function render() { $this->_context = 'render'; $this->_open_wrap(); include $this->_get_global_template( 'index' ); $this->_close_wrap(); } protected function render_stars() { $settings = $this->get_settings(); $stars_html = ''; for ( $stars = 1; $stars <= 5; $stars++ ) { $star_class = ( "outline" === $settings['rating_star_style'] ) ? 'far fa-star' : 'fas fa-star'; $active_star_class = ( "outline" === $settings['rating_active_star_style'] ) ? 'far fa-star' : 'fas fa-star'; $stars_html .= ''; } return $stars_html; } /** * Generate setting json * * @return string */ public function generate_setting_json() { $settings = $this->get_settings(); $widget_id = $this->get_id(); $instance_settings = array( 'autoplaySpeed' => absint( $settings['autoplay_speed'] ), 'autoplay' => filter_var( $settings['autoplay'], FILTER_VALIDATE_BOOLEAN ), 'infinite' => filter_var( $settings['infinite'], FILTER_VALIDATE_BOOLEAN ), 'centerMode' => filter_var( $settings['centered'], FILTER_VALIDATE_BOOLEAN ), 'centerPadding' => ! empty( $settings['centered_padding'] ) ? $settings['centered_padding'] . 'px' : '50px', 'adaptiveHeight' => filter_var( $settings['adaptive_height'], FILTER_VALIDATE_BOOLEAN ), 'pauseOnHover' => filter_var( $settings['pause_on_hover'], FILTER_VALIDATE_BOOLEAN ), 'speed' => absint( $settings['speed'] ), 'arrows' => filter_var( $settings['arrows'], FILTER_VALIDATE_BOOLEAN ), 'dots' => filter_var( $settings['dots'], FILTER_VALIDATE_BOOLEAN ), 'slidesToScroll' => 1 < absint( $settings['slides_to_show'] ) ? absint( $settings['slides_to_scroll'] ) : 1, 'prevArrow' => '.jet-testimonial__prev-arrow-' . $widget_id, 'nextArrow' => '.jet-testimonial__next-arrow-' . $widget_id, 'rtl' => is_rtl(), ); if ( 'fade' === $settings['effect'] && 1 >= absint( $settings['slides_to_show'] ) ) { $instance_settings['fade'] = true; } $instance_settings = apply_filters( 'jet-elements/jet-testimonials/carousel-options', $instance_settings, $settings, $widget_id ); $instance_settings = json_encode( $instance_settings ); return sprintf( 'data-settings=\'%1$s\'', $instance_settings ); } public function _get_testimonials_image() { $image_item = $this->_processed_item['item_image']; if ( empty( $image_item['url'] ) ) { return; } $item_link = isset( $this->_processed_item['item_link'] ) ? $this->_processed_item['item_link'] : false; if ( $item_link && ! empty( $item_link['url'] ) ) { $_id = $this->_processed_item['_id']; if ( method_exists( $this, 'add_link_attributes' ) ) { $this->add_link_attributes( 'img-link-' . $_id, $item_link ); } else { $this->add_render_attribute( 'img-link-' . $_id, 'href', esc_url( $item_link['url'] ) ); if ( ! empty( $item_link['is_external'] ) ) { $this->add_render_attribute( 'img-link-' . $_id, 'target', '_blank' ); } if ( ! empty( $item_link['nofollow'] ) ) { $this->add_render_attribute( 'img-link-' . $_id, 'rel', 'nofollow' ); } } return sprintf( '
%2$s
', $image_item['url'], esc_attr( Control_Media::get_image_alt( $image_item ) ), $this->get_render_attribute_string( 'img-link-' . $_id ) ); } return sprintf( '
%2$s
', $image_item['url'], esc_attr( Control_Media::get_image_alt( $image_item ) ) ); } public function _get_testimonials_name() { $item_name = $this->_processed_item['item_name']; if ( empty( $item_name ) ) { return; } $item_link = isset( $this->_processed_item['item_link'] ) ? $this->_processed_item['item_link'] : false; if ( $item_link && ! empty( $item_link['url'] ) ) { $_id = $this->_processed_item['_id']; if ( method_exists( $this, 'add_link_attributes' ) ) { $this->add_link_attributes( 'name-link-' . $_id, $item_link ); } else { $this->add_render_attribute( 'name-link-' . $_id, 'href', esc_url( $item_link['url'] ) ); if ( ! empty( $item_link['is_external'] ) ) { $this->add_render_attribute( 'name-link-' . $_id, 'target', '_blank' ); } if ( ! empty( $item_link['nofollow'] ) ) { $this->add_render_attribute( 'name-link-' . $_id, 'rel', 'nofollow' ); } } return sprintf( '
%1$s
', $item_name, $this->get_render_attribute_string( 'name-link-' . $_id ) ); } return sprintf( '
%s
', $item_name ); } public function _shuffle_items( $loop ) { shuffle($loop); return $loop; } } Engine Oil and Addetives

Tests of Mechanical Engine Losses Using Various Types of Engine Oil

Mechanical losses tests are conducted on the dyno, where the measurement of torque needed for a combustion engine running under set conditions is possible. The aim of the test is to define the influence of the engine oil in use on the engine’s mechanical efficiency and the reduction of frictional losses. The choice of engine oil also influences the engine’s fuel consumption – and thereby CO2 emissions. The results permit improvement of the lubricating properties of engine oils through quantifying the influence of individual oil additives on the friction within the engine.

.

Tests of Fuel Dilution of Engine Oil

Tests of fuel dilution of engine oil and the resulting influence on wear of individual engine components are conducted on the engine dyno. In modern Diesel engines, such dilution phenomena most often occur due to frequent particle filter (DPF) regenerations. During testing, through control of the number of DPF filter regenerations, a designated value of fuel concentration in engine oil is maintained, which allows evaluation of the negative influence of phenomena linked to fuel dilution of engine oil on engine components. During tests, oil samples are subjected to regular chemical analyses in order to determine the level of dilution as well as the content of metallic elements.

.

Oil Aeration Test

Excessive solubility of air in the oil reduces the oil film in the bearings and causes serious damage to them. This will decrease engine life time and will Leads to financial losses, which is why producing the right oil is so important. In Dina Motors we measure amount of oil aeration using precise equipment.

.

Benchmarking Tests

Comparative tests of the “benchmarking” type are conducted on the engine dyno in order to determine the influence fuel and engine oil produced by different manufacturers on engine parameters. During the test, comparative analyses are conducted based on data such as: engine performance, exhaust emissions, fuel consumption, engine subassembly wear and other defined factors. This type of testing allows evaluation of products available on the market and the selection of fuels or engine oils meeting client requirements.

.

Oil Validation Tests

Tests determining an oil’s propensity to form sediments on mechanical parts of the engine, for example, the compressor housing or its influence on the wear of lubricated elements, for example the camshaft or the driveshaft. Oxidation, sludge and varnish lead to an increase in viscosity which increases viscosity, friction and wear. Elements tested can be weighed (weight gained – sediments formed; or weight lost – material wear), subjected to both visual analyses and meteorological measurements, before and after the test.

.

Oil validation tests, for example, durability tests (test duration approx. 1000 h), cold start, efficiency of the lubricating system, allow all engine components whose durability is influenced by the engine oil to be tested. For modern turbocharged engines, often oil validation tests are performed by determining the quantity of sediments formed on the compressor housing and their influence on engine parameters. Requirements of oil characteristics are the temperature rise of the boost air and sediment formation on the compressor. Sediments on the compressor heavily influence its efficiency and durability, both raising the temperature of the boost air and lowering the efficiency of the entire engine.