Files
2025-07-13 11:19:53 +02:00

715 lines
22 KiB
PHP

<?php
/**
* Creative Elements - live Theme & Page Builder
*
* @author WebshopWorks, Elementor
* @copyright 2019-2022 WebshopWorks.com & Elementor.com
* @license https://www.gnu.org/licenses/gpl-3.0.html
*/
namespace CE;
defined('_PS_VERSION_') or die;
/**
* Elementor icon box widget.
*
* Elementor widget that displays an icon, a headline and a text.
*
* @since 1.0.0
*/
class WidgetIconBox extends WidgetBase
{
/**
* Get widget name.
*
* Retrieve icon box widget name.
*
* @since 1.0.0
* @access public
*
* @return string Widget name.
*/
public function getName()
{
return 'icon-box';
}
/**
* Get widget title.
*
* Retrieve icon box widget title.
*
* @since 1.0.0
* @access public
*
* @return string Widget title.
*/
public function getTitle()
{
return __('Icon Box');
}
/**
* Get widget icon.
*
* Retrieve icon box widget icon.
*
* @since 1.0.0
* @access public
*
* @return string Widget icon.
*/
public function getIcon()
{
return 'eicon-icon-box';
}
/**
* Get widget keywords.
*
* Retrieve the list of keywords the widget belongs to.
*
* @since 2.1.0
* @access public
*
* @return array Widget keywords.
*/
public function getKeywords()
{
return ['icon box', 'icon'];
}
/**
* Register icon box widget controls.
*
* Adds different input fields to allow the user to change and customize the widget settings.
*
* @since 1.0.0
* @access protected
*/
protected function _registerControls()
{
$this->startControlsSection(
'section_icon',
[
'label' => __('Icon Box'),
]
);
$this->addControl(
'icon',
[
'label' => __('Icon'),
'type' => ControlsManager::ICON,
'default' => 'fa fa-star',
]
);
$this->addControl(
'view',
[
'label' => __('View'),
'type' => ControlsManager::SELECT,
'options' => [
'default' => __('Default'),
'stacked' => __('Stacked'),
'framed' => __('Framed'),
],
'default' => 'default',
'prefix_class' => 'elementor-view-',
'condition' => [
'icon!' => '',
],
]
);
$this->addControl(
'shape',
[
'label' => __('Shape'),
'type' => ControlsManager::SELECT,
'options' => [
'circle' => __('Circle'),
'square' => __('Square'),
],
'default' => 'circle',
'condition' => [
'view!' => 'default',
'icon!' => '',
],
'prefix_class' => 'elementor-shape-',
]
);
$this->addControl(
'title_text',
[
'label' => __('Title & Description'),
'type' => ControlsManager::TEXT,
'dynamic' => [
'active' => true,
],
'default' => __('This is the heading'),
'placeholder' => __('Enter your title'),
'label_block' => true,
]
);
$this->addControl(
'description_text',
[
'label' => '',
'type' => ControlsManager::TEXTAREA,
'dynamic' => [
'active' => true,
],
'default' => __('Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.'),
'placeholder' => __('Enter your description'),
'rows' => 10,
'separator' => 'none',
'show_label' => false,
]
);
$this->addControl(
'link',
[
'label' => __('Link'),
'type' => ControlsManager::URL,
'dynamic' => [
'active' => true,
],
'placeholder' => __('https://your-link.com'),
'separator' => 'before',
]
);
$this->addControl(
'position',
[
'label' => __('Icon Position'),
'type' => ControlsManager::CHOOSE,
'default' => 'top',
'options' => [
'left' => [
'title' => __('Left'),
'icon' => 'eicon-h-align-left',
],
'top' => [
'title' => __('Top'),
'icon' => 'eicon-v-align-top',
],
'right' => [
'title' => __('Right'),
'icon' => 'eicon-h-align-right',
],
],
'prefix_class' => 'elementor-position-',
'toggle' => false,
'condition' => [
'icon!' => '',
],
]
);
$this->addControl(
'title_size',
[
'label' => __('Title HTML Tag'),
'type' => ControlsManager::SELECT,
'options' => [
'h1' => 'H1',
'h2' => 'H2',
'h3' => 'H3',
'h4' => 'H4',
'h5' => 'H5',
'h6' => 'H6',
'div' => 'div',
'span' => 'span',
'p' => 'p',
],
'default' => 'h3',
]
);
$this->endControlsSection();
$this->startControlsSection(
'section_style_icon',
[
'label' => __('Icon'),
'tab' => ControlsManager::TAB_STYLE,
'condition' => [
'icon!' => '',
],
]
);
$this->startControlsTabs('icon_colors');
$this->startControlsTab(
'icon_colors_normal',
[
'label' => __('Normal'),
]
);
$this->addControl(
'primary_color',
[
'label' => __('Primary Color'),
'type' => ControlsManager::COLOR,
'scheme' => [
'type' => SchemeColor::getType(),
'value' => SchemeColor::COLOR_1,
],
'default' => '',
'selectors' => [
'{{WRAPPER}}.elementor-view-stacked .elementor-icon' => 'background-color: {{VALUE}};',
'{{WRAPPER}}.elementor-view-framed .elementor-icon, ' .
'{{WRAPPER}}.elementor-view-default .elementor-icon' => 'color: {{VALUE}}; border-color: {{VALUE}};',
],
]
);
$this->addControl(
'secondary_color',
[
'label' => __('Secondary Color'),
'type' => ControlsManager::COLOR,
'default' => '',
'condition' => [
'view!' => 'default',
],
'selectors' => [
'{{WRAPPER}}.elementor-view-framed .elementor-icon' => 'background-color: {{VALUE}};',
'{{WRAPPER}}.elementor-view-stacked .elementor-icon' => 'color: {{VALUE}};',
],
]
);
$this->endControlsTab();
$this->startControlsTab(
'icon_colors_hover',
[
'label' => __('Hover'),
]
);
$this->addControl(
'hover_primary_color',
[
'label' => __('Primary Color'),
'type' => ControlsManager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}}.elementor-view-stacked .elementor-icon:hover' => 'background-color: {{VALUE}};',
'{{WRAPPER}}.elementor-view-framed .elementor-icon:hover, ' .
'{{WRAPPER}}.elementor-view-default .elementor-icon:hover' => 'color: {{VALUE}}; border-color: {{VALUE}};',
],
]
);
$this->addControl(
'hover_secondary_color',
[
'label' => __('Secondary Color'),
'type' => ControlsManager::COLOR,
'default' => '',
'condition' => [
'view!' => 'default',
],
'selectors' => [
'{{WRAPPER}}.elementor-view-framed .elementor-icon:hover' => 'background-color: {{VALUE}};',
'{{WRAPPER}}.elementor-view-stacked .elementor-icon:hover' => 'color: {{VALUE}};',
],
]
);
$this->addControl(
'hover_animation',
[
'label' => __('Hover Animation'),
'type' => ControlsManager::HOVER_ANIMATION,
]
);
$this->endControlsTab();
$this->endControlsTabs();
$this->addResponsiveControl(
'icon_space',
[
'label' => __('Spacing'),
'type' => ControlsManager::SLIDER,
'default' => [
'size' => 15,
],
'range' => [
'px' => [
'min' => 0,
'max' => 100,
],
],
'selectors' => [
'{{WRAPPER}}.elementor-position-right .elementor-icon-box-icon' => 'margin-left: {{SIZE}}{{UNIT}};',
'{{WRAPPER}}.elementor-position-left .elementor-icon-box-icon' => 'margin-right: {{SIZE}}{{UNIT}};',
'{{WRAPPER}}.elementor-position-top .elementor-icon-box-icon' => 'margin-bottom: {{SIZE}}{{UNIT}};',
'(mobile){{WRAPPER}} .elementor-icon-box-icon' => 'margin-bottom: {{SIZE}}{{UNIT}};',
],
]
);
$this->addResponsiveControl(
'icon_size',
[
'label' => __('Size'),
'type' => ControlsManager::SLIDER,
'range' => [
'px' => [
'min' => 6,
'max' => 300,
],
],
'selectors' => [
'{{WRAPPER}} .elementor-icon' => 'font-size: {{SIZE}}{{UNIT}};',
],
]
);
$this->addControl(
'icon_padding',
[
'label' => __('Padding'),
'type' => ControlsManager::SLIDER,
'selectors' => [
'{{WRAPPER}} .elementor-icon' => 'padding: {{SIZE}}{{UNIT}};',
],
'range' => [
'em' => [
'min' => 0,
'max' => 5,
],
],
'condition' => [
'view!' => 'default',
],
]
);
$this->addControl(
'rotate',
[
'label' => __('Rotate'),
'type' => ControlsManager::SLIDER,
'default' => [
'size' => 0,
'unit' => 'deg',
],
'selectors' => [
'{{WRAPPER}} .elementor-icon i' => 'transform: rotate({{SIZE}}{{UNIT}});',
],
]
);
$this->addControl(
'border_width',
[
'label' => __('Border Width'),
'type' => ControlsManager::DIMENSIONS,
'selectors' => [
'{{WRAPPER}} .elementor-icon' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
'condition' => [
'view' => 'framed',
],
]
);
$this->addControl(
'border_radius',
[
'label' => __('Border Radius'),
'type' => ControlsManager::DIMENSIONS,
'size_units' => ['px', '%'],
'selectors' => [
'{{WRAPPER}} .elementor-icon' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
'condition' => [
'view!' => 'default',
],
]
);
$this->endControlsSection();
$this->startControlsSection(
'section_style_content',
[
'label' => __('Content'),
'tab' => ControlsManager::TAB_STYLE,
]
);
$this->addResponsiveControl(
'text_align',
[
'label' => __('Alignment'),
'type' => ControlsManager::CHOOSE,
'options' => [
'left' => [
'title' => __('Left'),
'icon' => 'fa fa-align-left',
],
'center' => [
'title' => __('Center'),
'icon' => 'fa fa-align-center',
],
'right' => [
'title' => __('Right'),
'icon' => 'fa fa-align-right',
],
'justify' => [
'title' => __('Justified'),
'icon' => 'fa fa-align-justify',
],
],
'selectors' => [
'{{WRAPPER}} .elementor-icon-box-wrapper' => 'text-align: {{VALUE}};',
],
]
);
$this->addControl(
'content_vertical_alignment',
[
'label' => __('Vertical Alignment'),
'type' => ControlsManager::SELECT,
'options' => [
'top' => __('Top'),
'middle' => __('Middle'),
'bottom' => __('Bottom'),
],
'default' => 'top',
'prefix_class' => 'elementor-vertical-align-',
]
);
$this->addControl(
'heading_title',
[
'label' => __('Title'),
'type' => ControlsManager::HEADING,
'separator' => 'before',
]
);
$this->addResponsiveControl(
'title_bottom_space',
[
'label' => __('Spacing'),
'type' => ControlsManager::SLIDER,
'range' => [
'px' => [
'min' => 0,
'max' => 100,
],
],
'selectors' => [
'{{WRAPPER}} .elementor-icon-box-title' => 'margin-bottom: {{SIZE}}{{UNIT}};',
],
]
);
$this->addControl(
'title_color',
[
'label' => __('Color'),
'type' => ControlsManager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .elementor-icon-box-title' => 'color: {{VALUE}};',
],
'scheme' => [
'type' => SchemeColor::getType(),
'value' => SchemeColor::COLOR_1,
],
]
);
$this->addGroupControl(
GroupControlTypography::getType(),
[
'name' => 'title_typography',
'selector' => '{{WRAPPER}} .elementor-icon-box-title',
'scheme' => SchemeTypography::TYPOGRAPHY_1,
]
);
$this->addGroupControl(
GroupControlTextStroke::getType(),
[
'name' => 'text_stroke',
'selector' => '{{WRAPPER}} .elementor-icon-box-title',
]
);
$this->addGroupControl(
GroupControlTextShadow::getType(),
[
'name' => 'title_shadow',
'selector' => '{{WRAPPER}} .elementor-icon-box-title',
]
);
$this->addControl(
'heading_description',
[
'label' => __('Description'),
'type' => ControlsManager::HEADING,
'separator' => 'before',
]
);
$this->addControl(
'description_color',
[
'label' => __('Color'),
'type' => ControlsManager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .elementor-icon-box-description' => 'color: {{VALUE}};',
],
'scheme' => [
'type' => SchemeColor::getType(),
'value' => SchemeColor::COLOR_3,
],
]
);
$this->addGroupControl(
GroupControlTypography::getType(),
[
'name' => 'description_typography',
'selector' => '{{WRAPPER}} .elementor-icon-box-description',
'scheme' => SchemeTypography::TYPOGRAPHY_3,
]
);
$this->addGroupControl(
GroupControlTextShadow::getType(),
[
'name' => 'description_shadow',
'selector' => '{{WRAPPER}} .elementor-icon-box-description',
]
);
$this->endControlsSection();
}
/**
* Render icon box widget output on the frontend.
*
* Written in PHP and used to generate the final HTML.
*
* @since 1.0.0
* @access protected
*/
protected function render()
{
$settings = $this->getSettingsForDisplay();
$this->addRenderAttribute('icon', 'class', ['elementor-icon', 'elementor-animation-' . $settings['hover_animation']]);
$icon_tag = 'span';
$has_icon = !empty($settings['icon']);
if (!empty($settings['link']['url'])) {
$this->addRenderAttribute('link', 'href', $settings['link']['url']);
$icon_tag = 'a';
if ($settings['link']['is_external']) {
$this->addRenderAttribute('link', 'target', '_blank');
}
if ($settings['link']['nofollow']) {
$this->addRenderAttribute('link', 'rel', 'nofollow');
}
}
if ($has_icon) {
$this->addRenderAttribute('i', 'class', $settings['icon']);
$this->addRenderAttribute('i', 'aria-hidden', 'true');
}
$this->addRenderAttribute('description_text', 'class', 'elementor-icon-box-description');
$link_attributes = $this->getRenderAttributeString('link');
$this->addInlineEditingAttributes('title_text', 'none');
$this->addInlineEditingAttributes('description_text');
?>
<div class="elementor-icon-box-wrapper">
<?php if ($has_icon) : ?>
<div class="elementor-icon-box-icon">
<<?= $icon_tag . " $link_attributes " . $this->getRenderAttributeString('icon') ?>>
<i <?= $this->getRenderAttributeString('i') ?>></i>
</<?= $icon_tag ?>>
</div>
<?php endif ?>
<div class="elementor-icon-box-content">
<<?= $settings['title_size'] ?> class="elementor-icon-box-title">
<<?= $icon_tag . " $link_attributes " . $this->getRenderAttributeString('title_text') ?>>
<?= $settings['title_text'] ?>
</<?= $icon_tag ?>>
</<?= $settings['title_size'] ?>>
<p <?= $this->getRenderAttributeString('description_text') ?>><?= $settings['description_text'] ?></p>
</div>
</div>
<?php
}
/**
* Render icon box widget output in the editor.
*
* Written as a Backbone JavaScript template and used to generate the live preview.
*
* @since 1.0.0
* @access protected
*/
protected function _contentTemplate()
{
?>
<#
var link = settings.link.url ? 'href="' + settings.link.url + '"' : '',
iconTag = link ? 'a' : 'span';
view.addRenderAttribute( 'description_text', 'class', 'elementor-icon-box-description' );
view.addInlineEditingAttributes( 'title_text', 'none' );
view.addInlineEditingAttributes( 'description_text' );
#>
<div class="elementor-icon-box-wrapper">
<# if ( settings.icon ) { #>
<div class="elementor-icon-box-icon">
<{{{ iconTag + ' ' + link }}} class="elementor-icon elementor-animation-{{ settings.hover_animation }}">
<i class="{{ settings.icon }}" aria-hidden="true"></i>
</{{{ iconTag }}}>
</div>
<# } #>
<div class="elementor-icon-box-content">
<{{{ settings.title_size }}} class="elementor-icon-box-title">
<{{{ iconTag + ' ' + link }}} {{{ view.getRenderAttributeString( 'title_text' ) }}}>
{{{ settings.title_text }}}
</{{{ iconTag }}}>
</{{{ settings.title_size }}}>
<p {{{ view.getRenderAttributeString( 'description_text' ) }}}>{{{ settings.description_text }}}</p>
</div>
</div>
<?php
}
}