diff --git a/assets/src/blocks/godam-pdf/render.php b/assets/src/blocks/godam-pdf/render.php index db9f4e499..60e279786 100644 --- a/assets/src/blocks/godam-pdf/render.php +++ b/assets/src/blocks/godam-pdf/render.php @@ -36,35 +36,4 @@ return; } -?> - -> - - - - Download the PDF.', 'godam' ), - esc_url( $godam_sources[0] ) - ) - ); - ?> - - - - - - - - - - +require RTGODAM_PATH . 'inc/templates/godam-pdf.php'; diff --git a/inc/classes/class-elementor-widgets.php b/inc/classes/class-elementor-widgets.php index 411fb2693..4ba1d66d6 100644 --- a/inc/classes/class-elementor-widgets.php +++ b/inc/classes/class-elementor-widgets.php @@ -15,6 +15,8 @@ use RTGODAM\Inc\Elementor_Widgets\Godam_Audio; use RTGODAM\Inc\Elementor_Widgets\Godam_Gallery; use RTGODAM\Inc\Elementor_Widgets\GoDAM_Video; +use RTGODAM\Inc\Elementor_Widgets\GoDAM_PDF; + use RTGODAM\Inc\Traits\Singleton; /** @@ -123,6 +125,7 @@ public function widgets_registered() { \Elementor\Plugin::$instance->widgets_manager->register( new GoDAM_Video() ); \Elementor\Plugin::$instance->widgets_manager->register( new Godam_Gallery() ); \Elementor\Plugin::$instance->widgets_manager->register( new Godam_Audio() ); + \Elementor\Plugin::$instance->widgets_manager->register( new GoDAM_PDF() ); } /** diff --git a/inc/classes/elementor-widgets/class-godam-pdf.php b/inc/classes/elementor-widgets/class-godam-pdf.php new file mode 100644 index 000000000..7ba1eb272 --- /dev/null +++ b/inc/classes/elementor-widgets/class-godam-pdf.php @@ -0,0 +1,120 @@ + 'godam-pdf', + 'title' => _x( 'GoDAM PDF', 'Widget Title', 'godam' ), + 'icon' => 'eicon-document-file', + 'categories' => array( 'godam' ), + 'keywords' => array( 'godam', 'pdf', 'document' ), + ); + } + + /** + * Register Widget Controls. + * + * @access protected + */ + protected function register_controls() { + $this->start_controls_section( + 'section_pdf_settings', + array( + 'label' => __( 'PDF Settings', 'godam' ), + ) + ); + + $this->add_control( + 'pdf-file', + array( + 'label' => __( 'PDF File', 'godam' ), + 'type' => 'godam-media', + 'label_block' => true, + 'media_type' => 'application/pdf', + 'description' => __( 'Select the PDF file', 'godam' ), + ) + ); + + $this->add_control( + 'height', + array( + 'label' => __( 'Height (px)', 'godam' ), + 'type' => Controls_Manager::NUMBER, + 'default' => 600, + 'condition' => array( + 'pdf-file[url]!' => '', + ), + ) + ); + + $this->add_control( + 'caption', + array( + 'label' => __( 'Caption', 'godam' ), + 'type' => Controls_Manager::TEXTAREA, + 'condition' => array( + 'pdf-file[url]!' => '', + ), + ) + ); + + $this->end_controls_section(); + } + + /** + * Render GoDAM PDF widget output on the frontend. + * + * @access protected + */ + protected function render() { + $pdf_file = $this->get_settings_for_display( 'pdf-file' ); + $godam_attachment_id = ! empty( $pdf_file['id'] ) ? intval( $pdf_file['id'] ) : null; + $godam_src = ! empty( $pdf_file['url'] ) ? esc_url( $pdf_file['url'] ) : ''; + $godam_caption = $this->get_settings_for_display( 'caption' ) ?? ''; + $godam_height = $this->get_settings_for_display( 'height' ) ?? 600; + + if ( ! $godam_attachment_id && empty( $godam_src ) ) { + return; + } + + $godam_sources = array(); + if ( $godam_attachment_id ) { + $godam_pdf_url = wp_get_attachment_url( $godam_attachment_id ); + $godam_pdf_transcoded_url = get_post_meta( $godam_attachment_id, 'rtgodam_transcoded_url', true ); + if ( ! empty( $godam_pdf_transcoded_url ) ) { + $godam_sources[] = $godam_pdf_transcoded_url; + } + if ( ! empty( $godam_pdf_url ) ) { + $godam_sources[] = $godam_pdf_url; + } + } else { + $godam_sources[] = $godam_src; + } + + if ( empty( $godam_sources ) ) { + return; + } + + $is_elementor_widget = true; + + require RTGODAM_PATH . 'inc/templates/godam-pdf.php'; + } +} diff --git a/inc/templates/godam-pdf.php b/inc/templates/godam-pdf.php new file mode 100644 index 000000000..b3ebc85d6 --- /dev/null +++ b/inc/templates/godam-pdf.php @@ -0,0 +1,48 @@ + + +> + + + + Download the PDF.', 'godam' ), + esc_url( $godam_sources[0] ) + ) + ); + ?> + + + + + + + + + + \ No newline at end of file
- Download the PDF.', 'godam' ), - esc_url( $godam_sources[0] ) - ) - ); - ?> -
+ Download the PDF.', 'godam' ), + esc_url( $godam_sources[0] ) + ) + ); + ?> +