Elementor_Widget_Player::class, 'listen-button' => Elementor_Widget_Listen_Button::class, 'now-playing' => Elementor_Widget_Now_Playing::class, 'station' => Elementor_Widget_Station::class, 'station-list' => Elementor_Widget_Station_List::class, ); } /** * Element definition. * * @return array */ protected function element() { $el = Elements::get( static::ELEMENT ); return $el ? $el : array( 'label' => static::ELEMENT, 'description' => '', 'keywords' => array(), 'icon' => array( 'eicon' => 'eicon-play' ), 'fields' => array() ); } public function get_name() { return 'streamsera_' . str_replace( '-', '_', static::ELEMENT ); } public function get_title() { return $this->element()['label']; } public function get_icon() { return $this->element()['icon']['eicon'] . ' streamsera-eicon'; } public function get_categories() { return array( 'streamsera' ); } public function get_keywords() { return array_merge( array( 'streamsera', 'radio' ), (array) $this->element()['keywords'] ); } protected function is_dynamic_content(): bool { return true; } protected function register_controls() { $el = $this->element(); $sections = array( 'content' => __( 'Content', 'streamsera' ), 'display' => __( 'Display', 'streamsera' ), ); foreach ( $sections as $section => $title ) { $fields = array_filter( $el['fields'], static function ( $f ) use ( $section ) { return 'display' === $section ? 'display' === $f['section'] : 'display' !== $f['section']; } ); if ( ! $fields ) { continue; } $this->start_controls_section( 'streamsera_' . $section, array( 'label' => $title ) ); if ( 'content' === $section && $el['description'] ) { $this->add_control( 'streamsera_intro', array( 'type' => Controls_Manager::RAW_HTML, 'raw' => esc_html( $el['description'] ), 'content_classes' => 'elementor-descriptor', ) ); } foreach ( $fields as $key => $field ) { $this->add_control( $key, $this->control( $field ) ); } $this->end_controls_section(); } if ( Elements::has_own_styles( static::ELEMENT ) ) { return; // The player has its own skins; add-on elements may bring their own styles. } $this->start_controls_section( 'streamsera_style', array( 'label' => __( 'Colours & shape', 'streamsera' ), 'tab' => Controls_Manager::TAB_STYLE, ) ); $vars = array( 'streamsera_accent' => array( __( 'Accent', 'streamsera' ), '--ss-widget-accent' ), 'streamsera_bg' => array( __( 'Card background', 'streamsera' ), '--ss-widget-bg' ), 'streamsera_border' => array( __( 'Border', 'streamsera' ), '--ss-widget-border' ), ); foreach ( $vars as $key => $var ) { $this->add_control( $key, array( 'label' => $var[0], 'type' => Controls_Manager::COLOR, 'selectors' => array( '{{WRAPPER}}' => $var[1] . ': {{VALUE}};' ), ) ); } $this->add_control( 'streamsera_text', array( 'label' => __( 'Text', 'streamsera' ), 'type' => Controls_Manager::COLOR, 'selectors' => array( '{{WRAPPER}} .streamsera-widget' => 'color: {{VALUE}};' ), ) ); $this->add_control( 'streamsera_radius', array( 'label' => __( 'Corner radius', 'streamsera' ), 'type' => Controls_Manager::SLIDER, 'size_units' => array( 'px' ), 'range' => array( 'px' => array( 'min' => 0, 'max' => 32 ) ), 'selectors' => array( '{{WRAPPER}}' => '--ss-widget-radius: {{SIZE}}{{UNIT}};' ), ) ); $this->add_group_control( \Elementor\Group_Control_Typography::get_type(), array( 'name' => 'streamsera_title_typography', 'label' => __( 'Title typography', 'streamsera' ), 'selector' => '{{WRAPPER}} .ss-card__title, {{WRAPPER}} .ss-np__title', ) ); $this->end_controls_section(); } /** * Elementor control args for a field. * * @param array $field Field. * @return array */ private function control( $field ) { $base = array( 'label' => $field['label'], 'description' => $field['help'], ); switch ( $field['type'] ) { case 'toggle': return $base + array( 'type' => Controls_Manager::SWITCHER, 'label_on' => __( 'Show', 'streamsera' ), 'label_off' => __( 'Hide', 'streamsera' ), 'return_value' => 'yes', 'default' => $field['default'] ? 'yes' : '', ); case 'number': return $base + array( 'type' => Controls_Manager::NUMBER, 'min' => $field['min'] ?? 0, 'max' => $field['max'] ?? 100, 'step' => 1, 'default' => (int) $field['default'], ); case 'text': return $base + array( 'type' => Controls_Manager::TEXT, 'default' => (string) $field['default'], 'label_block' => true, ); default: $options = Elements::options( $field ); return $base + array( 'type' => Controls_Manager::SELECT, 'options' => $options, 'default' => isset( $options[ (string) $field['default'] ] ) ? (string) $field['default'] : (string) array_key_first( $options ), 'label_block' => array_key_exists( $field['type'], \StreamSera\Frontend\Elements::picker_types() ), ); } } protected function render() { $el = $this->element(); $s = $this->get_settings_for_display(); $args = array(); foreach ( $el['fields'] as $key => $field ) { if ( ! array_key_exists( $key, $s ) ) { continue; } // Switchers save '' when off: pass a real boolean so the field default doesn't win. $args[ $key ] = 'toggle' === $field['type'] ? ( 'yes' === $s[ $key ] ) : $s[ $key ]; } echo wp_kses( Elements::render( static::ELEMENT, $args ), streamsera_allowed_html() ); } } // phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound, Squiz.Commenting.ClassComment.Missing final class Elementor_Widget_Player extends Elementor_Element_Widget { const ELEMENT = 'player'; } final class Elementor_Widget_Listen_Button extends Elementor_Element_Widget { const ELEMENT = 'listen-button'; } final class Elementor_Widget_Now_Playing extends Elementor_Element_Widget { const ELEMENT = 'now-playing'; } final class Elementor_Widget_Station extends Elementor_Element_Widget { const ELEMENT = 'station'; } final class Elementor_Widget_Station_List extends Elementor_Element_Widget { const ELEMENT = 'station-list'; } // phpcs:enable