Parm= '.$parm;
echo "
COde= ".htmlspecialchars($code_text);
echo "
Width= ".$widthString;
*/
$params = array(); // Accumulator for parameters from youtube code
$ok = 0;
if (strpos($code_text, '<') === FALSE)
{ // 'Properly defined' bbcode (we hope)
$picRef = $code_text;
}
else
{
//libxml_use_internal_errors(TRUE);
if (FALSE === ($info = simplexml_load_string($code_text)))
{
//print_a($matches);
//$xmlErrs = libxml_get_errors();
//print_a($xmlErrs);
$ok = 1;
}
else
{
$info1 = (array)$info;
if (!isset($info1['embed']))
{
$ok = 2;
}
else
{
$info2 = (array)$info1['embed'];
if (!isset($info2['@attributes']))
{
$ok = 3;
}
}
}
if ($ok != 0)
{
print_a($info);
return '[sanitised]'.$ok.'B'.htmlspecialchars($matches[0]).'B[/sanitised]';
}
$target = (array)$info2['@attributes'];
unset($info);
$ws = varset($target['width'], 0);
$hs = varset($target['height'], 0);
if (($ws == 0) || ($hs == 0) || !isset($target['src'])) return '[sanitised]A'.htmlspecialchars($matches[0]).'A[/sanitised]';
if (!$widthString)
{
$widthString = $ws.','.$hs; // Set size of window
}
list($url, $query) = explode('?', $target['src']);
if (strpos($url, 'youtube-nocookie.com') !== FALSE)
{
$bb_params[] = 'privacy';
}
parse_str($query, $vals); // Various options set here
if (varset($vals['allowfullscreen'], 'true') != 'true')
{
$params[] = 'fs=0';
}
if (varset($vals['border'], 0) != 0)
{
$params[] = 'border=1';
}
if (varset($vals['rel'], 1) != 1)
{
$params[] = 'rel='.intval($vals['rel']);
}
if (varset($vals['hd'], 1) != 0)
{
$params[] = 'hd='.intval($vals['hd']);
}
if (varset($vals['hl'], 1) != 0)
{
$params[] = 'hl='.$vals['hl'];
}
if (varset($vals['color1'], 1) != 0)
{
$params[] = 'color1='.$vals['color1'];
}
if (varset($vals['color2'], 1) != 0)
{
$params[] = 'color2='.$vals['color2'];
}
if (varset($vals['cc_load_policy'], 1) != 0)
{
$params[] = 'cc_load_policy='.intval($vals['cc_load_policy']);
}
if (ADMIN && varset($vals['autoplay'], 1) != 0)
{
$params[] = 'autoplay='.intval($vals['autoplay']);
}
$picRef = substr($url, strrpos($url, '/') + 1);
}
$yID = preg_replace('/[^0-9a-z]/i', '', $picRef);
//if (($yID != $picRef) || (strlen($yID) > 20))
// { // Possible hack attempt
// }
// $params = array_merge($params, $bbpars); // Any parameters set in bbcode override those in HTML
// Could check for valid array indices here
$paramString = implode('&', $params);
if ($paramString) $picRef .= '?'.$paramString;
if($widthString)
{
$widthString = "=".$widthString;
if(count($bbpars))
{
$widthString .= "|".implode("&",$bbpars);
}
}
$ans = '[youtube'.$widthString.']'.$picRef.'[/youtube]';
return $ans;
}
/**
* Translate youtube bbcode into the appropriate