<commit_before><?php

use Friendica\App;
use Friendica\Content\Smilies;
use Friendica\Content\OEmbed;
use Friendica\Core\Cache;
use Friendica\Core\System;
use Friendica\Core\Config;
use Friendica\Model\Contact;
use Friendica\Util\Map;

require_once 'include/event.php';
require_once 'mod/proxy.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"  >' . Map::byCoordinates(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"  >' . Map::byLocation($match[1]) . '</div>', $match[0]);
}

/**
 * Processes [attachment] tags
 *
 * Note: Can produce a [bookmark] tag in the returned string
 *
 * @brief Processes [attachment] tags
 * @param string $Text
 * @param bool|int $simplehtml
 * @param bool $tryoembed
 * @return string
 */
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) || (strpos($data["text"], "[img]") !== false) || Config::get('system', 'always_show_preview')) && ($data["image"] != "")) {
		$data["preview"] = $data["image"];
		$data["image"] = "";
	}

	if ($simplehtml == 7) {
		$text = style_url_for_mastodon($data["url"]);
	} elseif (($simplehtml != 4) && ($simplehtml != 0)) {
		$text = sprintf('<a href="%s" target="_blank">%s</a><br>', $data["url"], $data["title"]);
	} else {
		if ($simplehtml != 4) {
			$text = sprintf('<span class="type-%s">', $data["type"]);
		}

		$oembed = sprintf('[bookmark=%s]%s[/bookmark]', $data['url'], $data['title']);
		if ($tryoembed) {
			try {
				$oembed = OEmbed::getHTML($data['url'], $data['title']);
			} catch (Exception $e) {
				// $oembed isn't modified
			}
		}

		if (stripos($oembed, "<iframe ") !== false) {
			$text = $oembed;
		} else {
			if (($data["image"] != "") && !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"] != "") && !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") && ($data["url"] != "") && ($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>', trim(bbcode($data["description"])));
			}
		}

		if ($simplehtml != 4) {
			$text .= '</span>';
		}
	}
	return trim($data["text"] . ' ' . $text . ' ' . $data["after"]);
}

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

	$data = get_attachment_data($Text);

	if (!$data) {
		return $Text;
	} elseif ($nolink) {
		return $data["text"] . $data["after"];
	}

	$title = htmlentities($data["title"], ENT_QUOTES, 'UTF-8', false);
	$text = htmlentities($data["text"], ENT_QUOTES, 'UTF-8', false);<commit_msg>Trust OEmbed HTML when it's available<commit_after><?php

use Friendica\App;
use Friendica\Content\Smilies;
use Friendica\Content\OEmbed;
use Friendica\Core\Cache;
use Friendica\Core\System;
use Friendica\Core\Config;
use Friendica\Model\Contact;
use Friendica\Util\Map;

require_once 'include/event.php';
require_once 'mod/proxy.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"  >' . Map::byCoordinates(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"  >' . Map::byLocation($match[1]) . '</div>', $match[0]);
}

/**
 * Processes [attachment] tags
 *
 * Note: Can produce a [bookmark] tag in the returned string
 *
 * @brief Processes [attachment] tags
 * @param string $return
 * @param bool|int $simplehtml
 * @param bool $tryoembed
 * @return string
 */
function bb_attachment($return, $simplehtml = false, $tryoembed = true)
{
	$data = get_attachment_data($return);
	if (!$data) {
		return $return;
	}

	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) || (strpos($data["text"], "[img]") !== false) || Config::get('system', 'always_show_preview')) && ($data["image"] != "")) {
		$data["preview"] = $data["image"];
		$data["image"] = "";
	}

	$return = '';
	if ($simplehtml == 7) {
		$return = style_url_for_mastodon($data["url"]);
	} elseif (($simplehtml != 4) && ($simplehtml != 0)) {
		$return = sprintf('<a href="%s" target="_blank">%s</a><br>', $data["url"], $data["title"]);
	} else {
		try {
			if ($tryoembed) {
				$return = OEmbed::getHTML($data['url'], $data['title']);
			} else {
				throw new Exception('OEmbed is disabled for this attachment.');
			}
		} catch (Exception $e) {
			if ($simplehtml != 4) {
				$return = sprintf('<span class="type-%s">', $data["type"]);
			}

			if ($data["image"] != "") {
				$return .= 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"] != "") {
				$return .= 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") && ($data["url"] != "") && ($data["image"] != "")) {
				$return .= 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 {
				$return .= sprintf('[bookmark=%s]%s[/bookmark]', $data['url'], $data['title']);
			}

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

			if ($simplehtml != 4) {
				$return .= '</span>';
			}
		}
	}

	return trim($data["text"] . ' ' . $return . ' ' . $data["after"]);
}

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

	$data = get_attachment_data($Text);

	if (!$data) {
		return $Text;
	} elseif ($nolink) {
		return $data["text"] . $data["after"];
	}

	$title = htmlentities($data["title"], ENT_QUOTES, 'UTF-8', false);
	$text = htmlentities($data["text"], ENT_QUOTES, 'UTF-8', false);
{'fraction_non_alphanumeric': 0.2548729336294103, 'fraction_numerical': 0.006661732050333087, 'mean_word_length': 4.798998569384835, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 47, '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': '2084437', 'n_tokens_mistral': 3102, 'n_tokens_neox': 2909, 'n_words': 582}