<commit_before><?php
require_once("include/oembed.php");
require_once('include/event.php');
require_once('include/map.php');
require_once('mod/proxy.php');
require_once('include/Contact.php');
require_once('include/plaintext.php');

function bb_PictureCacheExt($matches) {
	if (strpos($matches[3], "data:image/") === 0)
		return ($matches[0]);

	$matches[3] = proxy_url($matches[3]);
	return "[img=".$matches[1]."x".$matches[2]."]".$matches[3]."[/img]";
}

function bb_PictureCache($matches) {
	if (strpos($matches[1], "data:image/") === 0)
		return ($matches[0]);

	$matches[1] = proxy_url($matches[1]);
	return "[img]".$matches[1]."[/img]";
}

function bb_map_coords($match) {
	// the extra space in the following line is intentional
	return str_replace($match[0],'<div class="map"  >' . generate_map(str_replace('/',' ',$match[1])) . '</div>', $match[0]);
}
function bb_map_location($match) {
	// the extra space in the following line is intentional
	return str_replace($match[0],'<div class="map"  >' . generate_named_map($match[1]) . '</div>', $match[0]);
}

function bb_attachment($Text, $simplehtml = false, $tryoembed = true) {

	$data = get_attachment_data($Text);

	if (!$data)
		return $Text;

	if (isset($data["title"])) {
		$data["title"] = strip_tags($data["title"]);
		$data["title"] = str_replace(array("http://", "https://"), "", $data["title"]);
	}

	if (((strpos($data["text"], "[img=") !== false) OR (strpos($data["text"], "[img]") !== false)) AND ($data["image"] != "")) {
		$data["preview"] = $data["image"];
		$data["image"] = "";
	}

	if ($simplehtml == 7) {
		$title2 = $data["title"];

		$test1 = trim(html_entity_decode($data["text"],ENT_QUOTES,'UTF-8'));
		$test2 = trim(html_entity_decode($data["title"],ENT_QUOTES,'UTF-8'));

		// If the link description is similar to the text above then don't add the link description
		if (($data["title"] != "") AND ((strpos($test1,$test2) !== false) OR
			(similar_text($test1,$test2) / strlen($data["title"])) > 0.9))
			$title2 = $data["url"];
		$text = sprintf('<a href="%s" title="%s" class="attachment thumbnail" rel="nofollow external">%s</a><br />',
				$data["url"], $data["title"], $title2);
	} elseif (($simplehtml != 4) AND ($simplehtml != 0))
		$text = sprintf('<a href="%s" target="_blank">%s</a><br>', $data["url"], $data["title"]);
	else {
		$text = sprintf('<span class="type-%s">', $data["type"]);

		$bookmark = array(sprintf('[bookmark=%s]%s[/bookmark]', $data["url"], $data["title"]), $data["url"], $data["title"]);
		if ($tryoembed)
			$oembed = tryoembed($bookmark);
		else
			$oembed = $bookmark[0];

		if (strstr(strtolower($oembed), "<iframe "))
			$text = $oembed;
		else {
			if (($data["image"] != "") AND !strstr(strtolower($oembed), "<img "))
				$text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a><br />', $data["url"], proxy_url($data["image"]), $data["title"]);
			elseif (($data["preview"] != "") AND !strstr(strtolower($oembed), "<img "))
				$text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br />', $data["url"], proxy_url($data["preview"]), $data["title"]);

			if (($data["type"] == "photo") AND ($data["url"] != "") AND ($data["image"] != ""))
				$text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a>', $data["url"], proxy_url($data["image"]), $data["title"]);
			else
				$text .= $oembed;

			if (trim($data["description"]) != "")
				$text .= sprintf('<blockquote>%s</blockquote></span>', trim($data["description"]));
		}
	}
	return $data["text"].$text.$data["after"];
}

function bb_remove_share_information($Text, $plaintext = false, $nolink = false) {

	$data = get_attachment_data($Text);

	if (!$data)
		return $Text;

	if ($nolink)
		return $data["text"].$data["after"];

	if ($plaintext)
		$data["title"] = $data["url"];

	if (($data["text"] == "") AND ($data["title"] != "") AND ($data["url"] == ""))
		return $data["title"].$data["after"];

	// If the link already is included in the post, don't add it again
	if (($data["url"] != "") AND strpos($data["text"], $data["url"]))
		return $data["text"].$data["after"];

	$text = $data["text"];

	if (($data["url"] != "") AND ($data["title"] != ""))
		$text .= "\n[url=".$data["url"]."]".$data["title"]."[/url]";
	elseif (($link != ""))
		$text .= "\n".$data["url"];

	return $text.$data["after"];
}

function bb_cleanstyle($st) {
  return "<span style=\"".cleancss($st[1]).";\">".$st[2]."</span>";
}

function bb_cleanclass($st) {
  return "<span class=\"".cleancss($st[1])."\">".$st[2]."</span>";
}

function cleancss($input) {

	$cleaned = "";

	$input = strtolower($input);

	for ($i = 0; $i < strlen($input); $i++) {
		$char = substr($input, $i, 1);

		if (($char >= "a") and ($char <= "z"))<commit_msg>Shared links to Diaspora should look better now<commit_after><?php
require_once("include/oembed.php");
require_once('include/event.php');
require_once('include/map.php');
require_once('mod/proxy.php');
require_once('include/Contact.php');
require_once('include/plaintext.php');

function bb_PictureCacheExt($matches) {
	if (strpos($matches[3], "data:image/") === 0)
		return ($matches[0]);

	$matches[3] = proxy_url($matches[3]);
	return "[img=".$matches[1]."x".$matches[2]."]".$matches[3]."[/img]";
}

function bb_PictureCache($matches) {
	if (strpos($matches[1], "data:image/") === 0)
		return ($matches[0]);

	$matches[1] = proxy_url($matches[1]);
	return "[img]".$matches[1]."[/img]";
}

function bb_map_coords($match) {
	// the extra space in the following line is intentional
	return str_replace($match[0],'<div class="map"  >' . generate_map(str_replace('/',' ',$match[1])) . '</div>', $match[0]);
}
function bb_map_location($match) {
	// the extra space in the following line is intentional
	return str_replace($match[0],'<div class="map"  >' . generate_named_map($match[1]) . '</div>', $match[0]);
}

function bb_attachment($Text, $simplehtml = false, $tryoembed = true) {

	$data = get_attachment_data($Text);

	if (!$data)
		return $Text;

	if (isset($data["title"])) {
		$data["title"] = strip_tags($data["title"]);
		$data["title"] = str_replace(array("http://", "https://"), "", $data["title"]);
	}

	if (((strpos($data["text"], "[img=") !== false) OR (strpos($data["text"], "[img]") !== false)) AND ($data["image"] != "")) {
		$data["preview"] = $data["image"];
		$data["image"] = "";
	}

	if ($simplehtml == 7) {
		$title2 = $data["title"];

		$test1 = trim(html_entity_decode($data["text"],ENT_QUOTES,'UTF-8'));
		$test2 = trim(html_entity_decode($data["title"],ENT_QUOTES,'UTF-8'));

		// If the link description is similar to the text above then don't add the link description
		if (($data["title"] != "") AND ((strpos($test1,$test2) !== false) OR
			(similar_text($test1,$test2) / strlen($data["title"])) > 0.9))
			$title2 = $data["url"];
		$text = sprintf('<a href="%s" title="%s" class="attachment thumbnail" rel="nofollow external">%s</a><br />',
				$data["url"], $data["title"], $title2);
	} elseif (($simplehtml != 4) AND ($simplehtml != 0))
		$text = sprintf('<a href="%s" target="_blank">%s</a><br>', $data["url"], $data["title"]);
	else {
		$text = sprintf('<span class="type-%s">', $data["type"]);

		$bookmark = array(sprintf('[bookmark=%s]%s[/bookmark]', $data["url"], $data["title"]), $data["url"], $data["title"]);
		if ($tryoembed)
			$oembed = tryoembed($bookmark);
		else
			$oembed = $bookmark[0];

		if (strstr(strtolower($oembed), "<iframe "))
			$text = $oembed;
		else {
			if (($data["image"] != "") AND !strstr(strtolower($oembed), "<img "))
				$text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a><br />', $data["url"], proxy_url($data["image"]), $data["title"]);
			elseif (($data["preview"] != "") AND !strstr(strtolower($oembed), "<img "))
				$text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-preview" /></a><br />', $data["url"], proxy_url($data["preview"]), $data["title"]);

			if (($data["type"] == "photo") AND ($data["url"] != "") AND ($data["image"] != ""))
				$text .= sprintf('<a href="%s" target="_blank"><img src="%s" alt="" title="%s" class="attachment-image" /></a>', $data["url"], proxy_url($data["image"]), $data["title"]);
			else
				$text .= $oembed;

			if (trim($data["description"]) != "")
				$text .= sprintf('<blockquote>%s</blockquote></span>', trim($data["description"]));
		}
	}
	return $data["text"].$text.$data["after"];
}

function bb_remove_share_information($Text, $plaintext = false, $nolink = false) {

	$data = get_attachment_data($Text);

	if (!$data)
		return $Text;

	if ($nolink)
		return $data["text"].$data["after"];

	$title = htmlentities($data["title"], ENT_QUOTES, 'UTF-8', false);
	$text = htmlentities($data["text"], ENT_QUOTES, 'UTF-8', false);

	if ($plaintext or strstr($text, $title))
		$data["title"] = $data["url"];

	if (($data["text"] == "") AND ($data["title"] != "") AND ($data["url"] == ""))
		return $data["title"].$data["after"];

	// If the link already is included in the post, don't add it again
	if (($data["url"] != "") AND strpos($data["text"], $data["url"]))
		return $data["text"].$data["after"];

	$text = $data["text"];

	if (($data["url"] != "") AND ($data["title"] != ""))
		$text .= "\n[url=".$data["url"]."]".$data["title"]."[/url]";
	elseif (($data["url"] != ""))
		$text .= "\n".$data["url"];

	return $text."\n".$data["after"];
}

function bb_cleanstyle($st) {
  return "<span style=\"".cleancss($st[1]).";\">".$st[2]."</span>";
}

function bb_cleanclass($st) {
  return "<span class=\"".cleancss($st[1])."\">".$st[2]."</span>";
}

function cleancss($input) {

	$cleaned = "";

	$input = strtolower($input);

	for ($i = 0; $i < strlen($input); $i++) {
		$char = substr($input, $i, 1);

		if (($char >= "a") and ($char <= "z"))
{'fraction_non_alphanumeric': 0.2793583535108959, 'fraction_numerical': 0.00887812752219532, 'mean_word_length': 5.4706266318537855, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 65, 'https://': 2, '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': '2803090', 'n_tokens_mistral': 3813, 'n_tokens_neox': 3590, 'n_words': 695}