start_controls_section( 'section_google_photos_plus', [ 'label' => __( 'Google Photos Picker', 'allembed' ), 'tab' => Controls_Manager::TAB_CONTENT, ] ); $api = \AEAFE_Google_Photos_API::instance(); $is_connected = $api->is_connected(); $settings_url = admin_url( 'admin.php?page=aeafe-google-photos' ); /* ── Picker UI HTML ── */ $picker_html = '
'; if ( ! $is_connected ) { $picker_html .= '
' . '⚠' . '
' . '' . esc_html__( 'Google Account Not Connected', 'allembed' ) . '' . '

' . sprintf( wp_kses( /* translators: %s: settings URL */ __( 'Please connect your Google account on the API Credentials page first, then re-authorize to grant the Picker scope.', 'allembed' ), [ 'a' => [ 'href' => [], 'target' => [] ] ] ), esc_url( $settings_url ) ) . '

' . '
' . '
'; } else { $picker_html .= '
' . '' . '' . esc_html__( 'Google Account Connected', 'allembed' ) . '' . '
'; } $picker_html .= '
' . '' . '' . '
'; /* Polling feedback */ $picker_html .= ''; /* Selected-photos summary */ $picker_html .= ''; $picker_html .= '
'; $this->add_control( 'picker_ui', [ 'type' => Controls_Manager::RAW_HTML, 'raw' => $picker_html ] ); /* Hidden control – persists selected photos JSON */ $this->add_control( 'photos_json', [ 'label' => __( 'Photos Data (JSON)', 'allembed' ), 'type' => Controls_Manager::HIDDEN, 'default' => '', 'render_type' => 'template', ] ); $this->end_controls_section(); // ═══════════════════════════════════════════════════ // Gallery Layout Section // ═══════════════════════════════════════════════════ $this->start_controls_section( 'section_layout_plus', [ 'label' => __( 'Gallery Layout', 'allembed' ), 'tab' => Controls_Manager::TAB_CONTENT, ] ); $this->add_control( 'layout', [ 'label' => __( 'Layout Mode', 'allembed' ), 'type' => Controls_Manager::SELECT, 'default' => 'grid', 'options' => [ 'grid' => __( 'Grid Gallery', 'allembed' ), 'masonry' => __( 'Masonry Showcase', 'allembed' ), 'slider' => __( 'Interactive Carousel', 'allembed' ), ], ] ); $this->add_responsive_control( 'columns', [ 'label' => __( 'Columns', 'allembed' ), 'type' => Controls_Manager::SELECT, 'default' => '3', 'tablet_default' => '2', 'mobile_default' => '1', 'options' => [ '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6' ], 'selectors' => [ '{{WRAPPER}} .aeafe-plus-grid' => 'grid-template-columns: repeat({{VALUE}}, 1fr);', '{{WRAPPER}} .aeafe-plus-masonry' => 'column-count: {{VALUE}}; -webkit-column-count: {{VALUE}};', ], 'condition' => [ 'layout!' => 'slider' ], ] ); $this->add_responsive_control( 'gap', [ 'label' => __( 'Space Between Photos', 'allembed' ), 'type' => Controls_Manager::SLIDER, 'size_units' => [ 'px' ], 'range' => [ 'px' => [ 'min' => 0, 'max' => 60 ] ], 'default' => [ 'unit' => 'px', 'size' => 16 ], 'selectors' => [ '{{WRAPPER}} .aeafe-plus-grid' => 'gap: {{SIZE}}{{UNIT}};', '{{WRAPPER}} .aeafe-plus-masonry' => 'column-gap: {{SIZE}}{{UNIT}}; -webkit-column-gap: {{SIZE}}{{UNIT}};', '{{WRAPPER}} .aeafe-plus-masonry .aeafe-plus-item' => 'margin-bottom: {{SIZE}}{{UNIT}};', ], ] ); $this->add_control( 'aspect_ratio', [ 'label' => __( 'Photo Aspect Ratio', 'allembed' ), 'type' => Controls_Manager::SELECT, 'default' => '1/1', 'options' => [ 'auto' => __( 'Auto / Natural', 'allembed' ), '16/9' => __( '16:9 Landscape', 'allembed' ), '4/3' => __( '4:3 Classic', 'allembed' ), '3/2' => __( '3:2 Photography', 'allembed' ), '1/1' => __( '1:1 Square (Modern)', 'allembed' ), '2/3' => __( '2:3 Portrait', 'allembed' ), '9/16' => __( '9:16 Story / Mobile', 'allembed' ), ], 'condition' => [ 'layout' => 'grid' ], ] ); $this->add_control( 'hover_effect', [ 'label' => __( 'Hover Animation', 'allembed' ), 'type' => Controls_Manager::SELECT, 'default' => 'zoom', 'options' => [ 'zoom' => __( 'Zoom & Lift (Recommended)', 'allembed' ), 'lift' => __( '3D Float Lift', 'allembed' ), 'shine' => __( 'Metallic Light Beam Shine', 'allembed' ), 'overlay' => __( 'Frosted Dark Glass Overlay', 'allembed' ), 'slide' => __( 'Slide-Up Glass Caption', 'allembed' ), 'grayscale' => __( 'B&W to Vivid Color', 'allembed' ), 'none' => __( 'None', 'allembed' ), ], ] ); $this->add_control( 'enable_lightbox', [ 'label' => __( 'Popup Lightbox', 'allembed' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'default' => 'yes', 'condition' => [ 'layout!' => 'slider' ], ] ); $this->add_control( 'show_zoom_badge', [ 'label' => __( 'Show Zoom Icon on Hover', 'allembed' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'default' => 'yes', 'condition' => [ 'enable_lightbox' => 'yes', 'layout!' => 'slider' ], ] ); $this->add_control( 'show_caption', [ 'label' => __( 'Show Photo Description', 'allembed' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'default' => 'no', ] ); $this->add_control( 'slider_autoplay', [ 'label' => __( 'Autoplay Carousel', 'allembed' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'default' => 'yes', 'condition' => [ 'layout' => 'slider' ], ] ); $this->add_control( 'slider_speed', [ 'label' => __( 'Autoplay Interval (ms)', 'allembed' ), 'type' => Controls_Manager::SLIDER, 'range' => [ 'px' => [ 'min' => 1500, 'max' => 10000, 'step' => 500 ] ], 'default' => [ 'unit' => 'px', 'size' => 4000 ], 'condition' => [ 'layout' => 'slider' ], ] ); $this->add_control( 'slider_show_nav', [ 'label' => __( 'Navigation Arrows', 'allembed' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'default' => 'yes', 'condition' => [ 'layout' => 'slider' ], ] ); $this->add_control( 'slider_show_dots', [ 'label' => __( 'Pagination Dots', 'allembed' ), 'type' => Controls_Manager::SWITCHER, 'return_value' => 'yes', 'default' => 'yes', 'condition' => [ 'layout' => 'slider' ], ] ); $this->end_controls_section(); // ═══════════════════════════════════════════════════ // Style Tab – Card Styling // ═══════════════════════════════════════════════════ $this->start_controls_section( 'section_style_image_plus', [ 'label' => __( 'Photo Cards', 'allembed' ), 'tab' => Controls_Manager::TAB_STYLE, ] ); $this->add_control( 'border_radius', [ 'label' => __( 'Border Radius', 'allembed' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', '%' ], 'default' => [ 'top' => 12, 'right' => 12, 'bottom' => 12, 'left' => 12, 'unit' => 'px' ], 'selectors' => [ '{{WRAPPER}} .aeafe-plus-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}; overflow: hidden;', '{{WRAPPER}} .aeafe-plus-img-wrap' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', '{{WRAPPER}} .aeafe-plus-item__image' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', '{{WRAPPER}} .aeafe-plus-slider' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};', ], ] ); $this->start_controls_tabs( 'tabs_card_style' ); // Normal State $this->start_controls_tab( 'tab_card_normal', [ 'label' => __( 'Normal', 'allembed' ) ] ); $this->add_group_control( Group_Control_Box_Shadow::get_type(), [ 'name' => 'card_shadow', 'selector' => '{{WRAPPER}} .aeafe-plus-item', ] ); $this->add_group_control( Group_Control_Border::get_type(), [ 'name' => 'card_border', 'selector' => '{{WRAPPER}} .aeafe-plus-item', ] ); $this->end_controls_tab(); // Hover State $this->start_controls_tab( 'tab_card_hover', [ 'label' => __( 'Hover', 'allembed' ) ] ); $this->add_group_control( Group_Control_Box_Shadow::get_type(), [ 'name' => 'card_shadow_hover', 'selector' => '{{WRAPPER}} .aeafe-plus-item:hover', ] ); $this->add_control( 'card_border_color_hover', [ 'label' => __( 'Border Color', 'allembed' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .aeafe-plus-item:hover' => 'border-color: {{VALUE}};' ], ] ); $this->end_controls_tab(); $this->end_controls_tabs(); $this->end_controls_section(); // ═══════════════════════════════════════════════════ // Style Tab – Caption Styling // ═══════════════════════════════════════════════════ $this->start_controls_section( 'section_style_caption_plus', [ 'label' => __( 'Caption / Description', 'allembed' ), 'tab' => Controls_Manager::TAB_STYLE, 'condition' => [ 'show_caption' => 'yes' ], ] ); $this->add_control( 'caption_color', [ 'label' => __( 'Text Color', 'allembed' ), 'type' => Controls_Manager::COLOR, 'default' => '#ffffff', 'selectors' => [ '{{WRAPPER}} .aeafe-plus-item__caption' => 'color: {{VALUE}};' ], ] ); $this->add_group_control( Group_Control_Typography::get_type(), [ 'name' => 'caption_typography_plus', 'selector' => '{{WRAPPER}} .aeafe-plus-item__caption' ] ); $this->add_control( 'caption_bg', [ 'label' => __( 'Background Tint', 'allembed' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .aeafe-plus-item__caption' => 'background: {{VALUE}};' ], ] ); $this->end_controls_section(); } protected function render(): void { $settings = $this->get_settings_for_display(); $photos_json = $settings['photos_json'] ?? ''; if ( empty( $photos_json ) ) { $photos_json = $this->get_settings( 'photos_json' ); } $items = []; if ( ! empty( $photos_json ) ) { $decoded = null; if ( is_string( $photos_json ) ) { $decoded = json_decode( $photos_json, true ); if ( ! is_array( $decoded ) ) { $decoded = json_decode( wp_unslash( $photos_json ), true ); } if ( ! is_array( $decoded ) ) { $decoded = json_decode( stripslashes( $photos_json ), true ); } } elseif ( is_array( $photos_json ) ) { $decoded = $photos_json; } if ( ! empty( $decoded ) && is_array( $decoded ) ) { $items = $decoded; } } if ( empty( $items ) ) { if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { echo '
' . '
' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '
' . '

' . esc_html__( 'Google Gallery Plus', 'allembed' ) . '

' . '

' . esc_html__( 'Click "Select Photos from Google" in the left panel to display your photos here.', 'allembed' ) . '

' . '
'; } return; } $layout = sanitize_key( $settings['layout'] ?? 'grid' ); $enable_lb = 'yes' === ( $settings['enable_lightbox'] ?? 'yes' ); $show_badge = 'yes' === ( $settings['show_zoom_badge'] ?? 'yes' ); $show_caption = 'yes' === ( $settings['show_caption'] ?? 'no' ); $hover_effect = sanitize_key( $settings['hover_effect'] ?? 'zoom' ); $slider_auto = 'yes' === ( $settings['slider_autoplay'] ?? 'yes' ); $slider_speed = (int) ( $settings['slider_speed']['size'] ?? 4000 ); $slider_nav = 'yes' === ( $settings['slider_show_nav'] ?? 'yes' ); $slider_dots = 'yes' === ( $settings['slider_show_dots'] ?? 'yes' ); $widget_id = 'aeafe-plus-' . $this->get_id(); $grid_class = match ( $layout ) { 'masonry' => 'aeafe-plus-masonry', 'slider' => 'aeafe-plus-slider', default => 'aeafe-plus-grid', }; $aspect_ratio = sanitize_text_field( $settings['aspect_ratio'] ?? '1/1' ); $aspect_class = ( 'grid' === $layout ) ? 'aeafe-plus-aspect-' . str_replace( '/', '-', $aspect_ratio ) : 'aeafe-plus-aspect-auto'; printf( '
', esc_attr( $widget_id ), esc_attr( $hover_effect ), esc_attr( $aspect_class ), esc_attr( $layout ), esc_attr( $aspect_ratio ), $enable_lb ? '1' : '0', $slider_auto ? '1' : '0', $slider_speed, $slider_nav ? '1' : '0', $slider_dots ? '1' : '0' ); echo '
'; foreach ( $items as $item ) { $base_url = $item['base_url'] ?? $item['baseUrl'] ?? ( isset( $item['mediaFile']['baseUrl'] ) ? $item['mediaFile']['baseUrl'] : '' ); if ( empty( $base_url ) && ! empty( $item['thumbnail'] ) ) { $base_url = preg_replace( '/=.*$/', '', $item['thumbnail'] ); } if ( empty( $base_url ) && ! empty( $item['full_url'] ) ) { $base_url = preg_replace( '/=.*$/', '', $item['full_url'] ); } // Guarantee NO crop parameter (-c) is passed to Google Photos for clean aspect ratio cropping $raw_thumb = $base_url ? $base_url . '=w1400-h1400' : ( $item['thumbnail'] ?? '' ); $raw_thumb = str_replace( [ '-c', '=w400-h400-c', '=w600-h600-c' ], [ '', '=w1400-h1400', '=w1400-h1400' ], $raw_thumb ); $raw_full = $item['full_url'] ?? ( $base_url ? $base_url . '=w2048-h2048' : '' ); $thumb_url = esc_url( $this->get_proxy_url( $raw_thumb ) ); $full_url = esc_url( $this->get_proxy_url( $raw_full ) ); $caption = esc_html( $item['description'] ?? $item['filename'] ?? ( isset($item['mediaFile']['filename']) ? $item['mediaFile']['filename'] : '' ) ); $link_open = $enable_lb ? '' : ''; $link_close = $enable_lb ? '' : ''; echo '
'; echo $link_open; echo '
'; echo '
'; echo '' . ( $caption ?: esc_attr__( 'Google Photo', 'allembed' ) ) . ''; echo '
'; if ( $enable_lb && $show_badge && 'slider' !== $layout ) { echo '' . '' . ''; } if ( in_array( $hover_effect, [ 'overlay', 'blur' ], true ) && $enable_lb ) { echo '' . '' . ''; } if ( $show_caption && $caption ) { echo '

' . $caption . '

'; } echo '
'; echo $link_close; echo '
'; } echo '
'; if ( 'slider' === $layout ) { if ( $slider_nav ) { echo ''; echo ''; } if ( $slider_dots ) { echo '
'; } } echo '
'; } /** * Build an admin-ajax.php proxy URL for a raw Google Photos image URL. * * @param string $google_url Raw Google Photos URL (may contain sizing suffix). * @return string WordPress AJAX proxy URL. */ private function get_proxy_url( string $google_url ): string { if ( empty( $google_url ) ) { return ''; } return add_query_arg( [ 'action' => 'aeafe_picker_proxy_image', 'url' => $google_url ], admin_url( 'admin-ajax.php' ) ); } }