<commit_before><?php

/**
 * The filter to save dynamic HTML embeds and get an ID value for them.
 * Saves to `cache/html/${md5($html)}.html`.
 *
 * If `$reverse` is set to true, it will call `admin_embed_lookup()`
 * instead to retrieve the original value, as dynamic embed filters
 * are supposed to do.
 */
function admin_embed_filter ($html, $reverse = false) {
	if ($reverse) {
		return admin_embed_lookup ($html);
	}

	if (! @file_exists ('cache/html')) {
		mkdir ('cache/html', 0777);
	}

	$id = md5 ($html);
	file_put_contents ('cache/html/' . $id . '.html', $html);
	return $id;
}

/**
 * The reverse lookup that returns HTML for a given ID value.
 */
function admin_embed_lookup ($id) {
	return file_get_contents ('cache/html/' . $id . '.html');
}

/**
 * Get a list of installed layouts/themes.
 */
function admin_get_layouts () {
	$layouts = array ();
	$sources = array (
		'layouts/*.html',
		'layouts/*/*.html'
	);
	foreach ($sources as $source) {
		$files = glob ($source);
		foreach ($files as $file) {
			if (preg_match ('/\/([^\/]+)\.html$/', $file, $regs)) {
				$layouts[] = $regs[1];
			}
		}
	}
	sort ($layouts);
	return $layouts;
}

/**
 * Check whether a layout exists.<commit_msg>Issue with admin_get_layouts () - foreach argument False instead of an Array if no files were found<commit_after><?php

/**
 * The filter to save dynamic HTML embeds and get an ID value for them.
 * Saves to `cache/html/${md5($html)}.html`.
 *
 * If `$reverse` is set to true, it will call `admin_embed_lookup()`
 * instead to retrieve the original value, as dynamic embed filters
 * are supposed to do.
 */
function admin_embed_filter ($html, $reverse = false) {
	if ($reverse) {
		return admin_embed_lookup ($html);
	}

	if (! @file_exists ('cache/html')) {
		mkdir ('cache/html', 0777);
	}

	$id = md5 ($html);
	file_put_contents ('cache/html/' . $id . '.html', $html);
	return $id;
}

/**
 * The reverse lookup that returns HTML for a given ID value.
 */
function admin_embed_lookup ($id) {
	return file_get_contents ('cache/html/' . $id . '.html');
}

/**
 * Get a list of installed layouts/themes.
 */
function admin_get_layouts () {
	$layouts = array ();
	$sources = array (
		'layouts/*.html',
		'layouts/*/*.html'
	);
	foreach ($sources as $source) {
		$files = glob ($source);
		if ($files) {
			foreach ($files as $file) {
				if (preg_match ('/\/([^\/]+)\.html$/', $file, $regs)) {
					$layouts[] = $regs[1];
				}
			}
		}
	}
	sort ($layouts);
	return $layouts;
}

/**
 * Check whether a layout exists.
{'fraction_non_alphanumeric': 0.17850059500198334, 'fraction_numerical': 0.005553351844506148, 'mean_word_length': 3.3708838821490468, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '3488531', 'n_tokens_mistral': 923, 'n_tokens_neox': 870, 'n_words': 271}