Skip to content
Open

Release #4711

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions globals/sanitize-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,19 @@ function neve_sanitize_colors( $value ) {
*
* @param mixed $value Color in rgba format.
*
* @return string
* @return string Normalized rgba() color, or '' when the color is incomplete.
*/
function neve_sanitize_rgba( $value ) {
if ( ! is_string( $value ) ) {
return 'rgba(0,0,0,0)';
}

$red = 'rgba(0,0,0,0)';
$green = 'rgba(0,0,0,0)';
$blue = 'rgba(0,0,0,0)';
$alpha = 'rgba(0,0,0,0)'; // If empty or an array return transparent
$parts = sscanf( str_replace( ' ', '', $value ), 'rgba(%d,%d,%d,%f)' );
if ( ! is_array( $parts ) || in_array( null, $parts, true ) || ! is_finite( $parts[3] ) ) {
return '';
}

// By now we know the string is formatted as an rgba color so we need to further sanitize it.
$value = str_replace( ' ', '', $value );
sscanf( $value, 'rgba(%d,%d,%d,%f)', $red, $green, $blue, $alpha );
list( $red, $green, $blue, $alpha ) = $parts;

return 'rgba(' . $red . ',' . $green . ',' . $blue . ',' . $alpha . ')';
}
Expand Down
68 changes: 51 additions & 17 deletions header-footer-grid/Core/Builder/Abstract_Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ abstract class Abstract_Builder implements Builder {
const TEXT_COLOR = 'new_text_color';
const BACKGROUND_SETTING = 'background';
const WIDTH = 'width';
const RENDER_SLOTS = [ 'left', 'c-left', 'center', 'c-right', 'right' ];
const CONTENT_ALIGNMENT = 'content_alignment';
const VERTICAL_ALIGN = 'vertical_align';
/**
Expand Down Expand Up @@ -1281,13 +1282,7 @@ public function new_render_components( $device ) {
$data = [ 'sidebar' => $data ];
}

$render_buffer = [
'left' => [],
'c-left' => [],
'center' => [],
'c-right' => [],
'right' => [],
];
$render_buffer = array_fill_keys( self::RENDER_SLOTS, [] );

$slot = null;
$component_index = null;
Expand Down Expand Up @@ -1490,16 +1485,7 @@ public function render_components( $device = null ) {
$max_columns = 12;
$last_item = null;

usort(
$data,
function ( $item1, $item2 ) {
if ( $item1['x'] === $item2['x'] ) {
return 0;
}

return $item1['x'] < $item2['x'] ? - 1 : 1;
}
);
usort( $data, [ self::class, 'compare_legacy_position' ] );

$collection = new \CachingIterator(
new \ArrayIterator(
Expand Down Expand Up @@ -1717,6 +1703,54 @@ public function get_component( $id = null ) {
return $this->builder_components[ $id ];
}

/**
* Component ids of a device's rows in render order, without the sidebar row.
*
* @param string $device Device id.
*
* @return list<string>
*/
public function get_device_component_ids( string $device ): array {
$layout = $this->get_layout_data();
$ids = [];
foreach ( array_keys( $this->get_rows() ) as $row_index ) {
$row = isset( $layout[ $device ][ $row_index ] ) && is_array( $layout[ $device ][ $row_index ] ) ? $layout[ $device ][ $row_index ] : [];
if ( $row_index === 'sidebar' || empty( $row ) ) {
continue;
}

if ( ! neve_is_new_builder() ) {
usort( $row, [ self::class, 'compare_legacy_position' ] );
$ids = array_merge( $ids, array_column( $row, 'id' ) );
continue;
}

foreach ( self::RENDER_SLOTS as $slot ) {
if ( isset( $row[ $slot ] ) && is_array( $row[ $slot ] ) ) {
$ids = array_merge( $ids, array_column( $row[ $slot ], 'id' ) );
}
}
}

return $ids;
}

/**
* Orders legacy builder items by their column position.
*
* @param array{x: int} $item1 First item.
* @param array{x: int} $item2 Second item.
*
* @return int
*/
private static function compare_legacy_position( array $item1, array $item2 ): int {
if ( $item1['x'] === $item2['x'] ) {
return 0;
}

return $item1['x'] < $item2['x'] ? - 1 : 1;
}

/**
* Returns the builder components.
*
Expand Down
40 changes: 40 additions & 0 deletions header-footer-grid/Core/Components/MenuIcon.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace HFG\Core\Components;

use HFG\Core\Builder\Header as HeaderBuilder;
use HFG\Core\Script_Register;
use HFG\Core\Settings\Manager as SettingsManager;
use HFG\Main;
Expand Down Expand Up @@ -151,6 +152,45 @@ public function add_menu_icon_classes( $class = '', $icon = '' ) {
return $class;
}

/**
* Icon the sidebar close button mirrors: the first menu icon rendered in the mobile header, else the first registered one in the layout.
*
* Only an icon in the layout enqueues its styles, so an unused one must not decide the close button markup.
*
* @return array{icon: 'default'|'donner'|'dots'|'wave'|'svg', svg: string}
*/
public static function get_close_button_icon(): array {
$default = [
'icon' => 'default',
'svg' => '',
];
$header = Main::get_instance()->get_builder( HeaderBuilder::BUILDER_NAME );
if ( ! $header instanceof HeaderBuilder ) {
return $default;
}

$candidates = array_merge( $header->get_device_component_ids( 'mobile' ), array_keys( $header->get_components() ) );
foreach ( $candidates as $component_id ) {
$component = $header->get_component( $component_id );
if ( ! $component instanceof self || ! $header->is_component_active( $component_id ) ) {
continue;
}

$icon = Mods::get( $component->get_id() . '_' . self::MENU_ICON, 'default' );
$svg = (string) Mods::get( $component->get_id() . '_' . self::MENU_SVG, '' );
if ( ! in_array( $icon, [ 'donner', 'dots', 'wave', 'svg' ], true ) || ( $icon === 'svg' && $svg === '' ) ) {
return $default;
}

return [
'icon' => $icon,
'svg' => $svg,
];
}

return $default;
}

/**
* Load Component Scripts
*
Expand Down
16 changes: 5 additions & 11 deletions header-footer-grid/templates/row-wrapper-mobile.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,10 @@
$item_attributes = apply_filters( 'neve_nav_toggle_data_attrs', '' );
$close_classes = 'close-sidebar-panel navbar-toggle-wrapper' . ( $close_contained ? ' container' : '' );
$submenu_style = row_setting( 'layout', 'slide_left' );
$menu_icon_class = apply_filters( 'neve_menu_icon_classes', 'hamburger is-active ' );

$menu_icon = component_setting( MenuIcon::MENU_ICON );
$menu_svg = component_setting( MenuIcon::MENU_SVG );
if ( ! in_array( $menu_icon, [ 'donner', 'dots', 'svg', 'wave' ], true ) ) {
$menu_icon = 'default';
}
if ( $menu_icon === 'svg' && empty( $menu_svg ) ) {
$menu_icon = 'default';
}
$close_icon = MenuIcon::get_close_button_icon();
$menu_icon = $close_icon['icon'];
$menu_svg = $close_icon['svg'];
$menu_icon_class = apply_filters( 'neve_menu_icon_classes', 'hamburger is-active ', $menu_icon );
?>
<div
id="header-menu-sidebar" class="<?php echo esc_attr( join( ' ', $classes ) ); ?>"
Expand All @@ -45,7 +39,7 @@
<?php // The screen-reader-text span inside is the single naming source. ?>
<?php echo MenuIcon::aria_expanded_behaviour(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<?php
if ( $menu_icon_class === 'hamburger is-active ' ) {
if ( $menu_icon === 'default' ) {
?>
<span class="bars">
<span class="icon-bar"></span>
Expand Down
Loading
Loading