/**
* Parses IMG MyCode.
*
* @param string The URL to the image
* @param array Optional array of dimensions
*/
function mycode_parse_img($url, $dimensions=array(), $align='')
{
global $lang,;
$url = trim($url);
$url = str_replace("\n", "", $url);
$url = str_replace("\r", "", $url);
if($align == "right")
{
$css_align = " style=\"float: right;\"";
}
else if($align == "left")
{
$css_align = " style=\"float: left;\"";
}
$alt = {$thread['subject']};
if(my_strlen($alt) > 55)
{
$alt = my_substr($alt, 0, 40)."...".my_substr($alt, -10);
}
$alt = $lang->sprintf($lang->posted_image, $alt);
if($dimensions[0] > 0 && $dimensions[1] > 0)
{
return "<img src=\"{$url}\" width=\"{$dimensions[0]}\" height=\"{$dimensions[1]}\" border=\"0\" alt=\"{$alt}\"{$css_align} />";
}
else
{
return "<img src=\"{$url}\" border=\"0\" alt=\"{$alt}\"{$css_align} />";
}
}
/**
* Parses email MyCode.
*
* @param string The email address to link to.
* @param string The name for the link.
* @return string The built-up email link.
*/
function mycode_parse_email($email, $name="")
{
if(!$name)
{
$name = $email;
}
if(preg_match("/^([a-zA-Z0-9-_\+\.]+?)@[a-zA-Z0-9-]+\.[a-zA-Z0-9\.-]+$/si", $email))
{
return "<a href=\"mailto:$email\">".$name."</a>";
}
else
{
return $email;
}
}
/**
* Parses URLs automatically.
*
* @param string The message to be parsed
* @return string The parsed message.
*/
function mycode_auto_url($message)
{
$message = " ".$message;
$message = preg_replace("#([\>\s\(\)])(https?|ftp|news){1}://([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^\"\s<\[]*)?)#i", "$1[url]$2://$3[/url]", $message);
$message = preg_replace("#([\>\s\(\)])(www|ftp)\.(([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^\"\s<\[]*)?)#i", "$1[url]$2.$3[/url]", $message);
$message = my_substr($message, 1);
return $message;
}
/**
* Parses list MyCode.
*
* @param string The message to be parsed
* @param string The list type
* @param boolean Are we formatting as text?
* @return string The parsed message.
*/
function mycode_parse_list($message, $type="")
{
$message = str_replace('\"', '"', $message);
$message = preg_replace("#\s*\[\*\]\s*#", "</li>\n<li>", $message);
$message .= "</li>";
if($type)
{
$list = "\n<ol type=\"$type\">$message</ol>\n";
}
else
{
$list = "<ul>$message</ul>\n";
}
$list = preg_replace("#<(ol type=\"$type\"|ul)>\s*</li>#", "<$1>", $list);
return $list;
}