<commit_before><?php
/**
 * Template library for this theme.
 *
 * These are mostly format and helper functions.
 */

include_once 'lib-ts/raw-scripts.php';

function inject_class_in_tag($tag, $class, $haystack) {

	// (1) find the tag
	$i = strpos($haystack, '<'.$tag);
	if ($i !== false) {
		// (2) find end of Tag
		$j = strpos($haystack, '>', $i+1);
		// (3) extract only the tag
		if ($j !== false) $the_tag = substr($haystack, $i, $j-$i+1);
		else $the_tag = substr($haystack, $i);

		// (4) find if it has a class
		$k = strpos($the_tag, 'class=');
		if ($k !== false) {
			// (5a) next should be the quote
			$n = substr($the_tag, $k+6, 1);
			$p = strpos($the_tag, $n, $k+7);
			// (6a) then insert the class name
			$haystack = substr_replace($haystack, ' '.$class, $i+$p, 0);
		} else {
			// (5b) find the end of the tag
			$p = strpos($the_tag, '>');
			// (6b) then insert class attribute and name
			$haystack = substr_replace($haystack, ' class="'.$class.'"', $i+$p, 0);
		}
	}
	// (7) done.
	return $haystack;
}

function bs4_icon_set() {
	global $bs4_singletons;
	if (!isset($bs4_singletons)) $bs4_singletons = array();

	if (!isset($bs4_singletons['icon_set'])) {
		$bs4_singletons['icon_set'] = bs4_get_option('icon_set');
		$_fn = get_template_directory() . '/inc/iconset-' . $bs4_singletons['icon_set'] . '.php';
		if (file_exists($_fn)) include_once $_fn;
	}

	return $bs4_singletons['icon_set'];
}

function get_bs4_i($name, $before = '', $after = '', $attribs = false) {
	$fn = 'get_bs4_icon_'.bs4_icon_set();
	if (function_exists($fn))
		return call_user_func($fn, $name, $before, $after, $attribs);
	else return '';
}

function bs4_i($name, $before = '', $after = '', $attribs = false) {
	echo get_bs4_i($name, $before, $after, $attribs);
}

function get_bs4_user_i($id_or_email = null, $before = '', $after = '', $attribs = false) {
	if (!empty($id_or_email) && get_option('show_avatars')) {
		$avatar = get_avatar($id_or_email, 32, '', '');
		if (!empty($avatar)) {
			$avatar = str_replace(
				array('height="32" width="32"', 'height=\'32\' width=\'32\''),
				'style="width:auto;height:1em"',
				$avatar);
			$avatar = str_replace(
				array('class="', 'class=\''),
				array('class="'.AVATAR_CLASS.' ', 'class=\''.AVATAR_CLASS.' '),
				$avatar);
			return $before . $avatar . $after;
		}
	}
	return get_bs4_i('user', $before, $after, $attribs);
}

/**
 */
function bs4_navbar_color_class($navbar_color, $custom_color_class = false) {
	switch ($navbar_color) {
		case 1: return 'bg-inverse'; break;
		case 2: return 'bg-default'; break;
		case 3: return 'bg-faded'; break;
		case 4: return 'bg-transparent'; break;
		case 5:<commit_msg>bug fix with main-nav<commit_after><?php
/**
 * Template library for this theme.
 *
 * These are mostly format and helper functions.
 */

include_once 'lib-ts/raw-scripts.php';

function inject_class_in_tag($tag, $class, $haystack) {

	// (1) find the tag
	$i = strpos($haystack, '<'.$tag);
	if ($i !== false) {
		// (2) find end of Tag
		$j = strpos($haystack, '>', $i+1);
		// (3) extract only the tag
		if ($j !== false) $the_tag = substr($haystack, $i, $j-$i+1);
		else $the_tag = substr($haystack, $i);

		// (4) find if it has a class
		$k = strpos($the_tag, 'class=');
		if ($k !== false) {
			// (5a) next should be the quote
			$n = substr($the_tag, $k+6, 1);
			$p = strpos($the_tag, $n, $k+7);
			// (6a) then insert the class name
			$haystack = substr_replace($haystack, ' '.$class, $i+$p, 0);
		} else {
			// (5b) find the end of the tag
			$p = strpos($the_tag, '>');
			// (6b) then insert class attribute and name
			$haystack = substr_replace($haystack, ' class="'.$class.'"', $i+$p, 0);
		}
	}
	// (7) done.
	return $haystack;
}

function bs4_icon_set() {
	global $bs4_singletons;
	if (!isset($bs4_singletons)) $bs4_singletons = array();

	if (!isset($bs4_singletons['icon_set'])) {
		$bs4_singletons['icon_set'] = bs4_get_option('icon_set');
		$_fn = get_template_directory() . '/inc/iconset-' . $bs4_singletons['icon_set'] . '.php';
		if (file_exists($_fn)) include_once $_fn;
	}

	return $bs4_singletons['icon_set'];
}

function get_bs4_i($name, $before = '', $after = '', $attribs = false) {
	$fn = 'get_bs4_icon_'.bs4_icon_set();
	if (function_exists($fn))
		return call_user_func($fn, $name, $before, $after, $attribs);
	else return '';
}

function bs4_i($name, $before = '', $after = '', $attribs = false) {
	echo get_bs4_i($name, $before, $after, $attribs);
}

function get_bs4_user_i($id_or_email = null, $before = '', $after = '', $attribs = false) {
	if (!empty($id_or_email) && get_option('show_avatars')) {
		$avatar = get_avatar($id_or_email, 32, '', '');
		if (!empty($avatar)) {
			$avatar = str_replace(
				array('height="32" width="32"', 'height=\'32\' width=\'32\''),
				'style="width:auto;height:1em"',
				$avatar);
			$avatar = str_replace(
				array('class="', 'class=\''),
				array('class="'.AVATAR_CLASS.' ', 'class=\''.AVATAR_CLASS.' '),
				$avatar);
			return $before . $avatar . $after;
		}
	}
	return get_bs4_i('user', $before, $after, $attribs);
}

/**
 */
function bs4_navbar_color_class($navbar_color, $custom_color_class = false) {
	switch ($navbar_color) {
		case 1: return 'bg-inverse'; break;
		case 2: return 'bg-faded'; break;
		case 3: return 'bg-default'; break;
		case 4: return 'bg-transparent'; break;
		case 5:
{'fraction_non_alphanumeric': 0.2088631264023934, 'fraction_numerical': 0.01832460732984293, 'mean_word_length': 4.07977207977208, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2089218', 'n_tokens_mistral': 2316, 'n_tokens_neox': 2101, 'n_words': 474}