<commit_before><?php
function oembed_replacecb($matches){
//	logger('oembedcb');
	$embedurl=$matches[1];
	$j = oembed_fetch_url($embedurl);
	$s =  oembed_format_object($j);
	return $s;//oembed_iframe($s,$j->width,$j->height);


}


function oembed_fetch_url($embedurl){

	$a = get_app();

	$txt = Cache::get($a->videowidth . $embedurl);

	// These media files should now be caught in bbcode.php
	// left here as a fallback in case this is called from another source

	$noexts = array("mp3","mp4","ogg","ogv","oga","ogm","webm");
	$ext = pathinfo(strtolower($embedurl),PATHINFO_EXTENSION);


	if(is_null($txt)){
		$txt = "";

		if (!in_array($ext, $noexts)){
			// try oembed autodiscovery
			$redirects = 0;
			$html_text = fetch_url($embedurl, false, $redirects, 15, "text/*"); /**/
			if($html_text){
				$dom = @DOMDocument::loadHTML($html_text);
				if ($dom){
					$xpath = new DOMXPath($dom);
					$attr = "oembed";

					$xattr = oe_build_xpath("class","oembed");
					$entries = $xpath->query("//link[@type='application/json+oembed']");
					foreach($entries as $e){
						$href = $e->getAttributeNode("href")->nodeValue;
						$txt = fetch_url($href . '&maxwidth=' . $a->videowidth);
						break;
					}
				}
			}
		}

		if ($txt==false || $txt==""){
			// try oohembed service
			$ourl = "http://oohembed.com/oohembed/?url=".urlencode($embedurl).'&maxwidth=' . $a->videowidth;  
			$txt = fetch_url($ourl);
		}

		$txt=trim($txt);
		if ($txt[0]!="{") $txt='{"type":"error"}';

		//save in cache
		Cache::set($a->videowidth . $embedurl,$txt);

	}

	$j = json_decode($txt);
	$j->embedurl = $embedurl;
	return $j;
}

function oembed_format_object($j){
	$a = get_app();
	$embedurl = $j->embedurl;
	$jhtml = oembed_iframe($j->embedurl,(isset($j->width) ? $j->width : null), (isset($j->height) ? $j->height : null) );
	$ret="<span class='oembed ".$j->type."'>";
	switch ($j->type) {
		case "video": {
			if (isset($j->thumbnail_url)) {
				$tw = (isset($j->thumbnail_width) && intval($j->thumbnail_width)) ? $j->thumbnail_width:200;
				$th = (isset($j->thumbnail_height) && intval($j->thumbnail_height)) ? $j->thumbnail_height:180;<commit_msg>oembed: There seems to be some bug with ombed (maybe passing a non working url) This small fix should avoid the error at this place and may directs to the source of the problem.<commit_after><?php
function oembed_replacecb($matches){
//	logger('oembedcb');
	$embedurl=$matches[1];
	$j = oembed_fetch_url($embedurl);
	$s =  oembed_format_object($j);
	return $s;//oembed_iframe($s,$j->width,$j->height);


}


function oembed_fetch_url($embedurl){

	$a = get_app();

	$txt = Cache::get($a->videowidth . $embedurl);

	// These media files should now be caught in bbcode.php
	// left here as a fallback in case this is called from another source

	$noexts = array("mp3","mp4","ogg","ogv","oga","ogm","webm");
	$ext = pathinfo(strtolower($embedurl),PATHINFO_EXTENSION);


	if(is_null($txt)){
		$txt = "";

		if (!in_array($ext, $noexts)){
			// try oembed autodiscovery
			$redirects = 0;
			$html_text = fetch_url($embedurl, false, $redirects, 15, "text/*"); /**/
			if($html_text){
				$dom = @DOMDocument::loadHTML($html_text);
				if ($dom){
					$xpath = new DOMXPath($dom);
					$attr = "oembed";

					$xattr = oe_build_xpath("class","oembed");
					$entries = $xpath->query("//link[@type='application/json+oembed']");
					foreach($entries as $e){
						$href = $e->getAttributeNode("href")->nodeValue;
						$txt = fetch_url($href . '&maxwidth=' . $a->videowidth);
						break;
					}
				}
			}
		}

		if ($txt==false || $txt==""){
			// try oohembed service
			$ourl = "http://oohembed.com/oohembed/?url=".urlencode($embedurl).'&maxwidth=' . $a->videowidth;  
			$txt = fetch_url($ourl);
		}

		$txt=trim($txt);
		if ($txt[0]!="{") $txt='{"type":"error"}';

		//save in cache
		Cache::set($a->videowidth . $embedurl,$txt);

	}

	$j = json_decode($txt);

	if (!is_object($j))
		return false;

	$j->embedurl = $embedurl;
	return $j;
}

function oembed_format_object($j){
	$a = get_app();
	$embedurl = $j->embedurl;
	$jhtml = oembed_iframe($j->embedurl,(isset($j->width) ? $j->width : null), (isset($j->height) ? $j->height : null) );
	$ret="<span class='oembed ".$j->type."'>";
	switch ($j->type) {
		case "video": {
			if (isset($j->thumbnail_url)) {
				$tw = (isset($j->thumbnail_width) && intval($j->thumbnail_width)) ? $j->thumbnail_width:200;
				$th = (isset($j->thumbnail_height) && intval($j->thumbnail_height)) ? $j->thumbnail_height:180;
{'fraction_non_alphanumeric': 0.21750722061764052, 'fraction_numerical': 0.005776494112419463, 'mean_word_length': 4.174712643678161, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4779508', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1713, 'n_words': 316}