<commit_before><?php
/* ------------------------------------------------------------------------ *\
 * Custom Functions
\* ------------------------------------------------------------------------ */

/**
 * Get the path to the most recent version of a file given a glob (i.e. modern.*.css => modern.17ee0314.css)
 *
 * @param string $path  Glob pattern for file to search for
 * @param bool $skip_child_theme  Optionally ignore child theme overrides
 * @param bool $full_path  Optionally return the full server path
 *
 * @return string
 */
function __gulp_init_namespace___get_theme_file_path(string $path, bool $skip_child_theme = false, bool $full_path = false): string {
    $file_paths = [];

    /**
     * Both stylesheet_directory and template_directory need to be checked
     * in order to account for the possibility of child theme overrides.
     */

    /**
     * Check the child theme first, unless instructed to skip
     */
    if ($child_results = ! $skip_child_theme ? glob(get_stylesheet_directory() . "/{$path}") : false) {
        $file_paths = $child_results;
    }

    /**
     * If no matching files were found in the child theme, check the parent theme
     */
    if (! $file_paths && $parent_results = glob(get_template_directory() . "/{$path}")) {
        $file_paths = $parent_results;
    }

    if ($file_paths) {
        /**
         * Sort the matches by date to get the most recently modified copy
         */
        usort($file_paths, static function ($alpha, $beta) {
            return filemtime($alpha) < filemtime($beta);
        });

        /**
         * Return the path to the most recently edited file, either as a full server path,
         * or relative to the theme directory
         */
        return $full_path ? $file_paths[0] : dirname($path) . "/" . basename($file_paths[0]);
    }

    return "";
}

/**
 * Retrieve critical styles for a given template
 *
 * @param string $template  The file name of the template styles should be retrieved for
 *
 * @return string
 */
function __gulp_init_namespace___get_critical_css(string $template): string {
    /**
     * Immediately stop if the user has visited previously or Critical CSS is explicity
     * disabled by the user via `$_GET["disable"]`, and the user hasn't requested to
     * debug the critical CSS.
     */
    if ((isset($_COOKIE["return_visitor"]) || (isset($_GET["disable"]) && $_GET["disable"] === "critical_css")) && ! (isset($_GET["debug"]) && $_GET["debug"] === "critical_css")) {
        return "";
    }

    $critical_css = "";

    $critical_css_path = __gulp_init_namespace___get_theme_file_path("assets/styles/critical/" .  explode(".", basename($template))[0] . ".css", false, true);

    /**
     * Construct the potential path to the critical CSS file for the template, check if it
     * exists, and if it does, get its contents.
     */
    if (file_exists($critical_css_path)) {
        $critical_css = file_get_contents($critical_css_path);
    }

    return $critical_css;
}

/**
 * Check if a given URL points to an external website
 *
 * @param string $url  URL to identify
 *
 * @return bool
 */
function __gulp_init_namespace___is_external_url(string $url): bool {
    $components = parse_url($url);

    /**
     * Check if the URL is relative
     */
    if (! (isset($components["host"]) && $components["host"])) {
        return false;
    }

    /**
     * Check if the domain name matches the current domain name
     */
    if (strcasecmp($components["host"], $_SERVER["SERVER_NAME"]) === 0) {
        return false;
    }

    /**
     * Check if the domain name is a subdomain of the current domain name
     */
    if (strrpos(strtolower($components["host"]), ".{$_SERVER["SERVER_NAME"]}") === strlen($components["host"]) - strlen(".{$_SERVER["SERVER_NAME"]}")) {
        return false;
    }

    /**
     * Return true for all other cases
     */
    return true;
}

/**
 * Check if a given asset is outside of the active theme's directory
 *
 * @param string $url  URL to check the location of
 *
 * @return bool
 */
function __gulp_init_namespace___is_other_asset(string $url): bool {
    return strpos($url, get_template_directory_uri()) !== 0;
}

/**
 * Check if a user is visiting the site using IE
 *
 * @return bool
 */
function __gulp_init_namespace___is_ie(): bool {
    if (preg_match("/(Trident|MSIE)/", $_SERVER["HTTP_USER_AGENT"])) {
        return true;
    }

    return false;
}

/**
 * Construct markup for a lazy loaded image
 *
 * @param array|string $src  The URL to a given image, or an array of URLs to a set of images, keyed with the dpi `["1x" => "image.jpg", "2x" => "image@2x.jpg]`
 * @param array<string> $atts  A set of attributes to apply to the element
 * @param bool $lazy  Whether or not to lazy load the image
 * @param string $tag
 *
 * @return string  HTML tag for displaying the image
 */
function __gulp_init_namespace___img($src, array $atts = [], bool $lazy = true, string $tag = "img"): string {
    $element = "<{$tag}";

    /**
     * If provided URL is an array, construct an `srcset` attribute pointing
     * to the `1x` resolution, and an srcset containing each possible resolution.
     */
    if (gettype($src) === "array") {
        $i = 0;
        $element .= " srcset='";

        foreach ($src as $dpi => $source) { $i++;
            $element .= esc_url($source) . " " . esc_attr($dpi) . ($i < count($src) ? ", " : "");
        }

        $element .= "'";
    /**
     * Otherwise, simply construct a single `srcset` containing the provided URL.
     */
    } else {
        $element .= " srcset='" . esc_url($src) . "'";
    }

    /**
     * Append each custom attribute to the element
     */
    if ($atts) {
        foreach ($atts as $att => $value) {
            $element .= " " . esc_attr($att) . "='" . esc_attr($value) . "'";
        }
    }

    $element .= " />";

    /**
     * Run through the lazy loader filter
     */
    if (! __gulp_init_namespace___is_ie()) {
        $element = apply_filters("__gulp_init_namespace___lazy_load_images", $element, $lazy);
    }

    return $element;
}<commit_msg>Add function to retrieve the contents of an SVG and add attributes to its root tag<commit_after><?php
/* ------------------------------------------------------------------------ *\
 * Custom Functions
\* ------------------------------------------------------------------------ */

/**
 * Get the path to the most recent version of a file given a glob (i.e. modern.*.css => modern.17ee0314.css)
 *
 * @param string $path  Glob pattern for file to search for
 * @param bool $skip_child_theme  Optionally ignore child theme overrides
 * @param bool $full_path  Optionally return the full server path
 *
 * @return string
 */
function __gulp_init_namespace___get_theme_file_path(string $path, bool $skip_child_theme = false, bool $full_path = false): string {
    $file_paths = [];

    /**
     * Both stylesheet_directory and template_directory need to be checked
     * in order to account for the possibility of child theme overrides.
     */

    /**
     * Check the child theme first, unless instructed to skip
     */
    if ($child_results = ! $skip_child_theme ? glob(get_stylesheet_directory() . "/{$path}") : false) {
        $file_paths = $child_results;
    }

    /**
     * If no matching files were found in the child theme, check the parent theme
     */
    if (! $file_paths && $parent_results = glob(get_template_directory() . "/{$path}")) {
        $file_paths = $parent_results;
    }

    if ($file_paths) {
        /**
         * Sort the matches by date to get the most recently modified copy
         */
        usort($file_paths, static function ($alpha, $beta) {
            return filemtime($alpha) < filemtime($beta);
        });

        /**
         * Return the path to the most recently edited file, either as a full server path,
         * or relative to the theme directory
         */
        return $full_path ? $file_paths[0] : dirname($path) . "/" . basename($file_paths[0]);
    }

    return "";
}

/**
 * Retrieve critical styles for a given template
 *
 * @param string $template  The file name of the template styles should be retrieved for
 *
 * @return string
 */
function __gulp_init_namespace___get_critical_css(string $template): string {
    /**
     * Immediately stop if the user has visited previously or Critical CSS is explicity
     * disabled by the user via `$_GET["disable"]`, and the user hasn't requested to
     * debug the critical CSS.
     */
    if ((isset($_COOKIE["return_visitor"]) || (isset($_GET["disable"]) && $_GET["disable"] === "critical_css")) && ! (isset($_GET["debug"]) && $_GET["debug"] === "critical_css")) {
        return "";
    }

    $critical_css = "";

    $critical_css_path = __gulp_init_namespace___get_theme_file_path("assets/styles/critical/" .  explode(".", basename($template))[0] . ".css", false, true);

    /**
     * Construct the potential path to the critical CSS file for the template, check if it
     * exists, and if it does, get its contents.
     */
    if (file_exists($critical_css_path)) {
        $critical_css = file_get_contents($critical_css_path);
    }

    return $critical_css;
}

/**
 * Check if a given URL points to an external website
 *
 * @param string $url  URL to identify
 *
 * @return bool
 */
function __gulp_init_namespace___is_external_url(string $url): bool {
    $components = parse_url($url);

    /**
     * Check if the URL is relative
     */
    if (! (isset($components["host"]) && $components["host"])) {
        return false;
    }

    /**
     * Check if the domain name matches the current domain name
     */
    if (strcasecmp($components["host"], $_SERVER["SERVER_NAME"]) === 0) {
        return false;
    }

    /**
     * Check if the domain name is a subdomain of the current domain name
     */
    if (strrpos(strtolower($components["host"]), ".{$_SERVER["SERVER_NAME"]}") === strlen($components["host"]) - strlen(".{$_SERVER["SERVER_NAME"]}")) {
        return false;
    }

    /**
     * Return true for all other cases
     */
    return true;
}

/**
 * Check if a given asset is outside of the active theme's directory
 *
 * @param string $url  URL to check the location of
 *
 * @return bool
 */
function __gulp_init_namespace___is_other_asset(string $url): bool {
    return strpos($url, get_template_directory_uri()) !== 0;
}

/**
 * Check if a user is visiting the site using IE
 *
 * @return bool
 */
function __gulp_init_namespace___is_ie(): bool {
    if (preg_match("/(Trident|MSIE)/", $_SERVER["HTTP_USER_AGENT"])) {
        return true;
    }

    return false;
}

/**
 * Construct markup for a lazy loaded image
 *
 * @param array|string $src  The URL to a given image, or an array of URLs to a set of images, keyed with the dpi `["1x" => "image.jpg", "2x" => "image@2x.jpg]`
 * @param array<string> $atts  A set of attributes to apply to the element
 * @param bool $lazy  Whether or not to lazy load the image
 * @param string $tag
 *
 * @return string  HTML tag for displaying the image
 */
function __gulp_init_namespace___img($src, array $atts = [], bool $lazy = true, string $tag = "img"): string {
    $element = "<{$tag}";

    /**
     * If provided URL is an array, construct an `srcset` attribute pointing
     * to the `1x` resolution, and an srcset containing each possible resolution.
     */
    if (gettype($src) === "array") {
        $i = 0;
        $element .= " srcset='";

        foreach ($src as $dpi => $source) { $i++;
            $element .= esc_url($source) . " " . esc_attr($dpi) . ($i < count($src) ? ", " : "");
        }

        $element .= "'";
    /**
     * Otherwise, simply construct a single `srcset` containing the provided URL.
     */
    } else {
        $element .= " srcset='" . esc_url($src) . "'";
    }

    /**
     * Append each custom attribute to the element
     */
    if ($atts) {
        foreach ($atts as $att => $value) {
            $element .= " " . esc_attr($att) . "='" . esc_attr($value) . "'";
        }
    }

    $element .= " />";

    /**
     * Run through the lazy loader filter
     */
    if (! __gulp_init_namespace___is_ie()) {
        $element = apply_filters("__gulp_init_namespace___lazy_load_images", $element, $lazy);
    }

    return $element;
}

/**
 * Get the contents of an SVG and apply specified attributes
 *
 * @param string $path
 * @param array $atts
 * @return string
 */
function __gulp_init_namespace___svg(string $path, array $atts = []): string {
    $element = "";

    if ($svg = file_get_contents($path)) {
        $DOM = new DOMDocument();

        $DOM->loadXML($svg);

        $svgs = $DOM->getElementsByTagName("svg");

        /**
         * Attach all specified attributes to the first SVG found
         */
        foreach ($atts as $name => $value) {
            $svgs->item(0)->setAttribute(esc_attr($name), trim(esc_attr($value) . " {$svgs->item(0)->getAttribute(esc_attr($name))}"));
        }

        $element = $DOM->saveXML($svgs->item(0));
    }

    return $element;
}
{'fraction_non_alphanumeric': 0.15824915824915825, 'fraction_numerical': 0.0026782981328435872, 'mean_word_length': 2.5398158179848322, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2957811', 'n_tokens_mistral': 3898, 'n_tokens_neox': 3804, 'n_words': 1206}