| 1 |
<?php |
| 2 |
|
| 3 |
namespace Elementor\Core\Base\Traits; |
| 4 |
|
| 5 |
use Elementor\Controls_Manager; |
| 6 |
use Elementor\Modules\FloatingButtons\Control\Hover_Animation_Floating_Buttons; |
| 7 |
use Elementor\Plugin; |
| 8 |
use Elementor\Shapes; |
| 9 |
use Elementor\Utils; |
| 10 |
|
| 11 |
trait Shared_Widget_Controls_Trait { |
| 12 |
|
| 13 |
protected $border_width_range = [ |
| 14 |
'min' => 0, |
| 15 |
'max' => 10, |
| 16 |
'step' => 1, |
| 17 |
]; |
| 18 |
|
| 19 |
protected function add_html_tag_control( string $name, string $default = 'h2' ): void { |
| 20 |
$this->add_control( |
| 21 |
$name, |
| 22 |
[ |
| 23 |
'label' => esc_html__( 'HTML Tag', 'elementor' ), |
| 24 |
'type' => Controls_Manager::SELECT, |
| 25 |
'options' => [ |
| 26 |
'h1' => 'H1', |
| 27 |
'h2' => 'H2', |
| 28 |
'h3' => 'H3', |
| 29 |
'h4' => 'H4', |
| 30 |
'h5' => 'H5', |
| 31 |
'h6' => 'H6', |
| 32 |
'div' => 'div', |
| 33 |
'span' => 'span', |
| 34 |
'p' => 'p', |
| 35 |
], |
| 36 |
'default' => $default, |
| 37 |
] |
| 38 |
); |
| 39 |
} |
| 40 |
|
| 41 |
/** |
| 42 |
* Remove any child arrays where all properties are empty |
| 43 |
*/ |
| 44 |
protected function clean_array( |
| 45 |
$input_array = [] |
| 46 |
) { |
| 47 |
$output_array = array_filter( $input_array, function( $sub_array ) { |
| 48 |
// Use array_filter on the sub array |
| 49 |
$filtered_sub_array = array_filter( $sub_array, function( $val ) { |
| 50 |
// Filter out empty or null values |
| 51 |
return ! is_null( $val ) && '' !== $val; |
| 52 |
} ); |
| 53 |
// A non-empty result means the sub array contains some non-empty value(s) |
| 54 |
return ! empty( $filtered_sub_array ); |
| 55 |
} ); |
| 56 |
return $output_array; |
| 57 |
} |
| 58 |
|
| 59 |
protected function get_link_attributes( |
| 60 |
$link = [], |
| 61 |
$other_attributes = [] |
| 62 |
) { |
| 63 |
$url_attrs = []; |
| 64 |
$rel_string = ''; |
| 65 |
|
| 66 |
if ( ! empty( $link['url'] ) ) { |
| 67 |
$url_attrs['href'] = esc_url( $link['url'] ); |
| 68 |
} |
| 69 |
|
| 70 |
if ( ! empty( $link['is_external'] ) ) { |
| 71 |
$url_attrs['target'] = '_blank'; |
| 72 |
$rel_string .= 'noopener '; |
| 73 |
} |
| 74 |
|
| 75 |
if ( ! empty( $link['nofollow'] ) ) { |
| 76 |
$rel_string .= 'nofollow '; |
| 77 |
} |
| 78 |
|
| 79 |
if ( ! empty( $rel_string ) ) { |
| 80 |
$url_attrs['rel'] = $rel_string; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Note - we deliberately merge $other_attributes second |
| 85 |
* to allow overriding default attributes values such as a more formatted href |
| 86 |
*/ |
| 87 |
$url_combined_attrs = array_merge( |
| 88 |
$url_attrs, |
| 89 |
$other_attributes, |
| 90 |
Utils::parse_custom_attributes( $link['custom_attributes'] ?? '' ), |
| 91 |
); |
| 92 |
|
| 93 |
return $url_combined_attrs; |
| 94 |
} |
| 95 |
|
| 96 |
protected function add_icons_per_row_control( |
| 97 |
string $name = 'icons_per_row', |
| 98 |
$options = [ |
| 99 |
'2' => '2', |
| 100 |
'3' => '3', |
| 101 |
], |
| 102 |
string $default = '3', |
| 103 |
$label = '', |
| 104 |
$selector_custom_property = '--e-link-in-bio-icon-columns' |
| 105 |
): void { |
| 106 |
if ( ! $label ) { |
| 107 |
$label = esc_html__( 'Icons Per Row', 'elementor' ); |
| 108 |
} |
| 109 |
$this->add_control( |
| 110 |
$name, |
| 111 |
[ |
| 112 |
'label' => $label, |
| 113 |
'type' => Controls_Manager::SELECT, |
| 114 |
'options' => $options, |
| 115 |
'default' => $default, |
| 116 |
'render_type' => 'template', |
| 117 |
'selectors' => [ |
| 118 |
'{{WRAPPER}} .e-link-in-bio' => $selector_custom_property . ': {{VALUE}};', |
| 119 |
], |
| 120 |
] |
| 121 |
); |
| 122 |
} |
| 123 |
|
| 124 |
protected function add_slider_control( |
| 125 |
string $name, |
| 126 |
array $args = [] |
| 127 |
): void { |
| 128 |
$default_args = [ |
| 129 |
'type' => Controls_Manager::SLIDER, |
| 130 |
'default' => [ |
| 131 |
'unit' => 'px', |
| 132 |
], |
| 133 |
'size_units' => [ 'px', '%', 'em', 'rem', 'vw', 'custom' ], |
| 134 |
'range' => [ |
| 135 |
'px' => [ |
| 136 |
'min' => 0, |
| 137 |
'max' => 100, |
| 138 |
'step' => 1, |
| 139 |
], |
| 140 |
], |
| 141 |
]; |
| 142 |
|
| 143 |
$this->add_control( |
| 144 |
$name, |
| 145 |
array_merge_recursive( $default_args, $args ) |
| 146 |
); |
| 147 |
} |
| 148 |
|
| 149 |
protected function add_borders_control( |
| 150 |
string $prefix, |
| 151 |
array $show_border_args = [], |
| 152 |
array $border_width_args = [], |
| 153 |
array $border_color_args = [] |
| 154 |
): void { |
| 155 |
$show_border = [ |
| 156 |
'label' => esc_html__( 'Border', 'elementor' ), |
| 157 |
'type' => Controls_Manager::SWITCHER, |
| 158 |
'label_on' => esc_html__( 'Yes', 'elementor' ), |
| 159 |
'label_off' => esc_html__( 'No', 'elementor' ), |
| 160 |
'return_value' => 'yes', |
| 161 |
'default' => '', |
| 162 |
]; |
| 163 |
|
| 164 |
$this->add_control( |
| 165 |
$prefix . '_show_border', |
| 166 |
array_merge( $show_border, $show_border_args ) |
| 167 |
); |
| 168 |
|
| 169 |
$condition = [ |
| 170 |
$prefix . '_show_border' => 'yes', |
| 171 |
]; |
| 172 |
|
| 173 |
if ( isset( $border_width_args['condition'] ) ) { |
| 174 |
$condition = array_merge( $condition, $border_width_args['condition'] ); |
| 175 |
unset( $border_width_args['condition'] ); |
| 176 |
} |
| 177 |
|
| 178 |
$border_width = [ |
| 179 |
'label' => esc_html__( 'Border Width', 'elementor' ) . ' (px)', |
| 180 |
'type' => Controls_Manager::SLIDER, |
| 181 |
'size_units' => [ 'px' ], |
| 182 |
'range' => [ |
| 183 |
'px' => $this->border_width_range, |
| 184 |
], |
| 185 |
'condition' => $condition, |
| 186 |
'default' => [ |
| 187 |
'unit' => 'px', |
| 188 |
'size' => 1, |
| 189 |
], |
| 190 |
]; |
| 191 |
|
| 192 |
$this->add_responsive_control( |
| 193 |
$prefix . '_border_width', |
| 194 |
array_merge( $border_width, $border_width_args ), |
| 195 |
); |
| 196 |
|
| 197 |
$condition = [ |
| 198 |
$prefix . '_show_border' => 'yes', |
| 199 |
]; |
| 200 |
|
| 201 |
if ( isset( $border_color_args['condition'] ) ) { |
| 202 |
$condition = array_merge( $condition, $border_color_args['condition'] ); |
| 203 |
unset( $border_color_args['condition'] ); |
| 204 |
} |
| 205 |
|
| 206 |
$border_color = [ |
| 207 |
'label' => esc_html__( 'Border Color', 'elementor' ), |
| 208 |
'type' => Controls_Manager::COLOR, |
| 209 |
'condition' => $condition, |
| 210 |
'default' => '#000000', |
| 211 |
]; |
| 212 |
|
| 213 |
$this->add_control( |
| 214 |
$prefix . '_border_color', |
| 215 |
array_merge( $border_color, $border_color_args ) |
| 216 |
); |
| 217 |
} |
| 218 |
|
| 219 |
protected function get_shape_divider( $side = 'bottom' ) { |
| 220 |
$settings = $this->settings; |
| 221 |
$base_setting_key = "identity_section_style_cover_divider_$side"; |
| 222 |
$file_name = $settings[ $base_setting_key ]; |
| 223 |
|
| 224 |
if ( empty( $file_name ) ) { |
| 225 |
return []; |
| 226 |
} |
| 227 |
|
| 228 |
$negative = ! empty( $settings[ $base_setting_key . '_negative' ] ); |
| 229 |
$shape_path = Shapes::get_shape_path( $file_name, $negative ); |
| 230 |
|
| 231 |
if ( ! is_file( $shape_path ) || ! is_readable( $shape_path ) ) { |
| 232 |
return []; |
| 233 |
} |
| 234 |
|
| 235 |
return [ |
| 236 |
'negative' => $negative, |
| 237 |
'svg' => Utils::file_get_contents( $shape_path ), |
| 238 |
]; |
| 239 |
} |
| 240 |
|
| 241 |
protected function print_shape_divider( $side = 'bottom' ) { |
| 242 |
$shape_divider = $this->get_shape_divider( $side ); |
| 243 |
|
| 244 |
if ( empty( $shape_divider ) ) { |
| 245 |
return; |
| 246 |
} |
| 247 |
?> |
| 248 |
<div |
| 249 |
class="elementor-shape elementor-shape-<?php echo esc_attr( $side ); ?>" |
| 250 |
data-negative="<?php |
| 251 |
echo esc_attr( $shape_divider['negative'] ? 'true' : 'false' ); |
| 252 |
?>" |
| 253 |
> |
| 254 |
<?php |
| 255 |
// PHPCS - The file content is being read from a strict file path structure. |
| 256 |
echo $shape_divider['svg']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 257 |
?> |
| 258 |
</div> |
| 259 |
<?php |
| 260 |
} |
| 261 |
|
| 262 |
protected function get_configured_breakpoints( $add_desktop = 'true' ) { |
| 263 |
$active_devices = Plugin::$instance->breakpoints->get_active_devices_list( [ 'reverse' => true ] ); |
| 264 |
$active_breakpoint_instances = Plugin::$instance->breakpoints->get_active_breakpoints(); |
| 265 |
|
| 266 |
$devices_options = []; |
| 267 |
|
| 268 |
foreach ( $active_devices as $device_key ) { |
| 269 |
$device_label = 'desktop' === $device_key ? esc_html__( 'Desktop', 'elementor' ) : $active_breakpoint_instances[ $device_key ]->get_label(); |
| 270 |
$devices_options[ $device_key ] = $device_label; |
| 271 |
} |
| 272 |
|
| 273 |
return [ |
| 274 |
'active_devices' => $active_devices, |
| 275 |
'devices_options' => $devices_options, |
| 276 |
]; |
| 277 |
} |
| 278 |
|
| 279 |
protected function add_hover_animation_control( |
| 280 |
string $name, |
| 281 |
array $args = [] |
| 282 |
): void { |
| 283 |
|
| 284 |
$this->add_control( |
| 285 |
$name, |
| 286 |
array_merge( |
| 287 |
[ |
| 288 |
'label' => esc_html__( 'Hover Animation', 'elementor' ), |
| 289 |
'type' => Hover_Animation_Floating_Buttons::TYPE, |
| 290 |
'frontend_available' => true, |
| 291 |
'default' => 'grow', |
| 292 |
], |
| 293 |
$args |
| 294 |
) |
| 295 |
); |
| 296 |
} |
| 297 |
} |
| 298 |
|