<commit_before><?php
/* ------------------------------------------------------------------------ *\
 * Menus
\* ------------------------------------------------------------------------ */

/**
 * Register the menus
 *
 * @return void
 */
function __gulp_init_namespace___register_nav_menus(): void {
    register_nav_menus([
        "primary" => __("Navigation", "__gulp_init_namespace__"),
    ]);
}
add_action("init", "__gulp_init_namespace___register_nav_menus");

/**
 * Custom menu walker that adds BEM classes and supports custom fields
 */
class __gulp_init_namespace___menu_walker extends Walker_Nav_Menu {
    /**
     * Set up a variable to hold the parameters passed to the walker
     */
    private $params;

    /**
     * Store parameters in a more accessible way
     *
     * @param  array<mixed> $params
     *
     * @return void
     */
    public function __construct(array $params = []) {
        $this->params = $params;
    }

    /**
     * Set up variables for a11y and mega menu features
     */
    private $is_mega      = false;
    private $column_limit = 3;
    private $column_count = 0;
    private $item_count   = 0;
    private $current_item = 0;

    /**
     * Check if the current item contains mega menu columns
     *
     * @param  object $element
     * @param  array<mixed> $children_elements
     * @param  int $max_depth
     * @param  int $depth
     * @param  array<mixed> $args
     * @param  string $output
     *
     * @return void
     */
    function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output): void {
        $features = isset($this->params["features"]) ? $this->params["features"] : [];

        if (in_array("mega", $features) && $depth === 0 && isset($children_elements[$element->ID]) && $children_elements[$element->ID]) { $i = 0;
            foreach ($children_elements[$element->ID] as $child) { $i++;
                /**
                 * Only check meta keys past the first item to (slightly) improve performance
                 */
                if ($i > 1) {
                    $has_columns = get_post_meta($child->ID, "_menu_item_column_start", true);
                    $parent_id   = get_post_meta($child->ID, "_menu_item_menu_item_parent", true);

                    if ($has_columns === "true" && intval($parent_id) === $element->ID) {
                        $this->is_mega = true;
                    }
                }
            }
        }

        /**
         * Pass on the element as is
         */
        parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
    }

    /**
     * Construct a menu item
     *
     * @param  string $output
     * @param  object $item
     * @param  int $depth
     * @param  array<mixed> $args
     * @param  int $id
     *
     * @return void
     */
    public function start_el(&$output, $item, $depth = 0,  $args = [], $id = 0): void {
        $id_prefix = isset($this->params["id_prefix"]) ? $this->params["id_prefix"] : "menu-item-";
        $features  = isset($this->params["features"]) ? $this->params["features"] : [];

        /**
         * Get the array of classes for the current menu item
         */
        $classes = $item->classes ? $item->classes : [];

        /**
         * Handle splitting drop downs for mega menus
         */
        if (in_array("mega", $features) && $this->is_mega) {
            /**
             * Reset the item counter if it's reached the top
             */
            if ($depth === 0) $this->item_count = 0;

            /**
             * Reset the column counter if it's the first li in a drop down
             */
            if ($depth === 1 && $this->item_count === 1) $this->column_count = 0;

            /**
             * Add the `menu-list__item--mega` class if it's the top
             */
            if ($depth === 0) $classes[] = "menu-list__item--mega";

            /**
             * Split the menu if it's a drop down, a split has been requested, it's
             * not the first li, and the column limit hasn't been reached
             */
            if ($depth === 1 && get_post_meta($item->ID, "_menu_item_column_start", true) && $this->item_count > 1 && $this->column_count < $this->column_limit) {
                $output .= "</ul><ul class='menu-list menu-list--vertical menu-list--child menu-list--depth-1 menu-list--mega'>";

                /**
                 * Increment the column counter
                 */
                $this->column_count++;
            }

            /**
             * Increment the item counter
             */
            $this->item_count++;
        }

        /**
         * Set up custom classes for "transpiling"
         */
        $custom_classes = [
            [
                "original" => "menu-item",
                "custom"   => "menu-list__item",
            ],
            [
                "original" => "current_page_item",
                "custom"   => "is-viewed",
            ],
            [
                "original" => "menu-item-has-children",
                "custom"   => "menu-list__item--parent",
            ],
        ];

        /**
         * "Transpile" WordPress classes to custom classes
         */
        foreach ($custom_classes as $class) {
            if (in_array($class["original"], $classes) && ! in_array($class["custom"], $classes)) {
                $classes[] = $class["custom"];
            }
        }

        /**
         * Construct a class attribute
         */
        $class_names = " class='" . esc_attr(join(" ", apply_filters("nav_menu_css_class", array_filter($classes), $item))) . "'";

        /**
         * Set up the ID in such as way as to prevent conflicts
         */
        $item_id = "{$id_prefix}{$item->ID}";

        /**
         * Construct a title attribute if specified
         */
        $attr_title = $item->attr_title ? " title='" . esc_attr($item->attr_title) . "'" : "";

        /**
         * Construct a target attribute if specified
         */
        $target = $item->target ? " target='{$item->target}'" : "";

        /**
         * If no rel is set, and URL is external, set rel to `noopener`
         */
        if (__gulp_init_namespace___is_external_url($item->url)) {
            $item->xfn = ! $item->xfn ? "noopener" : "{$item->xfn} noopener";
        }<commit_msg>Escape target attribute within menus<commit_after><?php
/* ------------------------------------------------------------------------ *\
 * Menus
\* ------------------------------------------------------------------------ */

/**
 * Register the menus
 *
 * @return void
 */
function __gulp_init_namespace___register_nav_menus(): void {
    register_nav_menus([
        "primary" => __("Navigation", "__gulp_init_namespace__"),
    ]);
}
add_action("init", "__gulp_init_namespace___register_nav_menus");

/**
 * Custom menu walker that adds BEM classes and supports custom fields
 */
class __gulp_init_namespace___menu_walker extends Walker_Nav_Menu {
    /**
     * Set up a variable to hold the parameters passed to the walker
     */
    private $params;

    /**
     * Store parameters in a more accessible way
     *
     * @param  array<mixed> $params
     *
     * @return void
     */
    public function __construct(array $params = []) {
        $this->params = $params;
    }

    /**
     * Set up variables for a11y and mega menu features
     */
    private $is_mega      = false;
    private $column_limit = 3;
    private $column_count = 0;
    private $item_count   = 0;
    private $current_item = 0;

    /**
     * Check if the current item contains mega menu columns
     *
     * @param  object $element
     * @param  array<mixed> $children_elements
     * @param  int $max_depth
     * @param  int $depth
     * @param  array<mixed> $args
     * @param  string $output
     *
     * @return void
     */
    function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output): void {
        $features = isset($this->params["features"]) ? $this->params["features"] : [];

        if (in_array("mega", $features) && $depth === 0 && isset($children_elements[$element->ID]) && $children_elements[$element->ID]) { $i = 0;
            foreach ($children_elements[$element->ID] as $child) { $i++;
                /**
                 * Only check meta keys past the first item to (slightly) improve performance
                 */
                if ($i > 1) {
                    $has_columns = get_post_meta($child->ID, "_menu_item_column_start", true);
                    $parent_id   = get_post_meta($child->ID, "_menu_item_menu_item_parent", true);

                    if ($has_columns === "true" && intval($parent_id) === $element->ID) {
                        $this->is_mega = true;
                    }
                }
            }
        }

        /**
         * Pass on the element as is
         */
        parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
    }

    /**
     * Construct a menu item
     *
     * @param  string $output
     * @param  object $item
     * @param  int $depth
     * @param  array<mixed> $args
     * @param  int $id
     *
     * @return void
     */
    public function start_el(&$output, $item, $depth = 0,  $args = [], $id = 0): void {
        $id_prefix = isset($this->params["id_prefix"]) ? $this->params["id_prefix"] : "menu-item-";
        $features  = isset($this->params["features"]) ? $this->params["features"] : [];

        /**
         * Get the array of classes for the current menu item
         */
        $classes = $item->classes ? $item->classes : [];

        /**
         * Handle splitting drop downs for mega menus
         */
        if (in_array("mega", $features) && $this->is_mega) {
            /**
             * Reset the item counter if it's reached the top
             */
            if ($depth === 0) $this->item_count = 0;

            /**
             * Reset the column counter if it's the first li in a drop down
             */
            if ($depth === 1 && $this->item_count === 1) $this->column_count = 0;

            /**
             * Add the `menu-list__item--mega` class if it's the top
             */
            if ($depth === 0) $classes[] = "menu-list__item--mega";

            /**
             * Split the menu if it's a drop down, a split has been requested, it's
             * not the first li, and the column limit hasn't been reached
             */
            if ($depth === 1 && get_post_meta($item->ID, "_menu_item_column_start", true) && $this->item_count > 1 && $this->column_count < $this->column_limit) {
                $output .= "</ul><ul class='menu-list menu-list--vertical menu-list--child menu-list--depth-1 menu-list--mega'>";

                /**
                 * Increment the column counter
                 */
                $this->column_count++;
            }

            /**
             * Increment the item counter
             */
            $this->item_count++;
        }

        /**
         * Set up custom classes for "transpiling"
         */
        $custom_classes = [
            [
                "original" => "menu-item",
                "custom"   => "menu-list__item",
            ],
            [
                "original" => "current_page_item",
                "custom"   => "is-viewed",
            ],
            [
                "original" => "menu-item-has-children",
                "custom"   => "menu-list__item--parent",
            ],
        ];

        /**
         * "Transpile" WordPress classes to custom classes
         */
        foreach ($custom_classes as $class) {
            if (in_array($class["original"], $classes) && ! in_array($class["custom"], $classes)) {
                $classes[] = $class["custom"];
            }
        }

        /**
         * Construct a class attribute
         */
        $class_names = " class='" . esc_attr(join(" ", apply_filters("nav_menu_css_class", array_filter($classes), $item))) . "'";

        /**
         * Set up the ID in such as way as to prevent conflicts
         */
        $item_id = "{$id_prefix}{$item->ID}";

        /**
         * Construct a title attribute if specified
         */
        $attr_title = $item->attr_title ? " title='" . esc_attr($item->attr_title) . "'" : "";

        /**
         * Construct a target attribute if specified
         */
        $target = $item->target ? " target='" . esc_attr($item->target) . "'" : "";

        /**
         * If no rel is set, and URL is external, set rel to `noopener`
         */
        if (__gulp_init_namespace___is_external_url($item->url)) {
            $item->xfn = ! $item->xfn ? "noopener" : "{$item->xfn} noopener";
        }
{'fraction_non_alphanumeric': 0.16433429755296694, 'fraction_numerical': 0.0031271988116644517, 'mean_word_length': 1.6164859889547964, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '886772', 'n_tokens_mistral': 3682, 'n_tokens_neox': 3513, 'n_words': 891}