", "", $code);
$code = str_replace("
", "
", $code);
$code = preg_replace("# *$#", "", $code);
if($bare_return)
{
return $code;
}
// Send back the code all nice and pretty
return "$lang->php_code\n
".$code."
\n";
}
/**
* Parses PHP code MyCode.
*
* @param array Matches.
* @return string The parsed message.
*/
function mycode_parse_php_callback($matches)
{
return $this->mycode_parse_php($matches[1], false, true);
}
/**
* Parses URL MyCode.
*
* @param string The URL to link to.
* @param string The name of the link.
* @return string The built-up link.
*/
function mycode_parse_url($url, $name="")
{
if(!preg_match("#^[a-z0-9]+://#i", $url))
{
$url = "http://".$url;
}
$fullurl = $url;
$url = str_replace('&', '&', $url);
$name = str_replace('&', '&', $name);
if(!$name)
{
$name = $url;
}
$name = str_replace("\'", "'", $name);
$url = str_replace("\'", "'", $url);
$fullurl = str_replace("\'", "'", $fullurl);
if($name == $url && (!isset($this->options['shorten_urls']) || $this->options['shorten_urls'] != 0))
{
if(my_strlen($url) > 55)
{
$name = my_substr($url, 0, 40)."...".my_substr($url, -10);
}
}
$nofollow = '';
if(isset($this->options['nofollow_on']))
{
$nofollow = " rel=\"nofollow\"";
}
// Fix some entities in URLs
$entities = array('$' => '%24', '$' => '%24', '^' => '%5E', '`' => '%60', '[' => '%5B', ']' => '%5D', '{' => '%7B', '}' => '%7D', '"' => '%22', '<' => '%3C', '>' => '%3E', ' ' => '%20');
$fullurl = str_replace(array_keys($entities), array_values($entities), $fullurl);
$name = preg_replace("#&\#([0-9]+);#si", "$1;", $name); // Fix & but allow unicode
$link = "$name";
return $link;
}
/**
* Parses URL MyCode.
*
* @param array Matches.
* @return string The built-up link.
*/
function mycode_parse_url_callback1($matches)
{
if(!isset($matches[3]))
{
$matches[3] = '';
}
return $this->mycode_parse_url($matches[1].$matches[2], $matches[3]);
}
/**
* Parses URL MyCode.
*
* @param array Matches.
* @return string The built-up link.
*/
function mycode_parse_url_callback2($matches)
{
if(!isset($matches[2]))
{
$matches[2] = '';
}
return $this->mycode_parse_url($matches[1], $matches[2]);
}
/**
* 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 = htmlspecialchars_uni(basename($url));
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 "";
}
else
{
return "";
}
}
/**
* Parses IMG MyCode.
*
* @param array Matches.
* @return string Image code.
*/
function mycode_parse_img_callback1($matches)
{
return $this->mycode_parse_img($matches[2])."\n";
}
/**
* Parses IMG MyCode.
*
* @param array Matches.
* @return string Image code.
*/
function mycode_parse_img_callback2($matches)
{
return $this->mycode_parse_img($matches[4], array($matches[1], $matches[2]));
}
/**
* Parses IMG MyCode.
*
* @param array Matches.
* @return string Image code.
*/
function mycode_parse_img_callback3($matches)
{
return $this->mycode_parse_img($matches[3], array(), $matches[1]);
}
/**
* Parses IMG MyCode.
*
* @param array Matches.
* @return string Image code.
*/
function mycode_parse_img_callback4($matches)
{
return $this->mycode_parse_img($matches[5], array($matches[1], $matches[2]), $matches[3]);
}
/**
* 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="")
{
$name = str_replace("\\'", "'", $name);
$email = str_replace("\\'", "'", $email);
if(!$name)
{
$name = $email;
}
if(preg_match("/^([a-zA-Z0-9-_\+\.]+?)@[a-zA-Z0-9-]+\.[a-zA-Z0-9\.-]+$/si", $email))
{
return "".$name."";
}
else
{
return $email;
}
}
/**
* Parses email MyCode.
*
* @param array Matches
* @return string The built-up email link.
*/
function mycode_parse_email_callback($matches)
{
if(!isset($matches[2]))
{
$matches[2] = '';
}
return $this->mycode_parse_email($matches[1], $matches[2]);
}
/**
* Parses video MyCode.
*
* @param string The video provider.
* @param string The video to link to.
* @return string The built-up video code.
*/
function mycode_parse_video($video, $url)
{
global $templates;
if(empty($video) || empty($url))
{
return "[video={$video}]{$url}[/video]";
}
$parsed_url = @parse_url(urldecode($url));
if($parsed_url == false)
{
return "[video={$video}]{$url}[/video]";
}
$fragments = array();
if($parsed_url['fragment'])
{
$fragments = explode("&", $parsed_url['fragment']);
}
$queries = explode("&", $parsed_url['query']);
$input = array();
foreach($queries as $query)
{
list($key, $value) = explode("=", $query);
$key = str_replace("amp;", "", $key);
$input[$key] = $value;
}
$path = explode('/', $parsed_url['path']);
switch($video)
{
case "dailymotion":
list($id, ) = split("_", $path[2], 1); // http://www.dailymotion.com/video/fds123_title-goes-here
break;
case "metacafe":
$id = $path[2]; // http://www.metacafe.com/watch/fds123/title_goes_here/
$title = htmlspecialchars_uni($path[3]);
break;
case "myspacetv":
$id = $path[4]; // http://www.myspace.com/video/fds/fds/123
break;
case "yahoo":
$id = $path[1]; // http://xy.screen.yahoo.com/fds-123.html
// Support for localized portals
$domain = explode('.', $parsed_url['host']);
if($domain[0] != 'screen')
{
$local = $domain[0].'.';
}
else
{
$local = '';
}
break;
case "vimeo":
$id = $path[1]; // http://vimeo.com/fds123
break;
case "youtube":
if($fragments[0])
{
$id = str_replace('!v=', '', $fragments[0]); // http://www.youtube.com/watch#!v=fds123
}
elseif($input['v'])
{
$id = $input['v']; // http://www.youtube.com/watch?v=fds123
}
else
{
$id = $path[1]; // http://www.youtu.be/fds123
}
break;
default:
return "[video={$video}]{$url}[/video]";
}
if(empty($id))
{
return "[video={$video}]{$url}[/video]";
}
$id = htmlspecialchars_uni($id);
eval("\$video_code = \"".$templates->get("video_{$video}_embed")."\";");
return $video_code;
}
/**
* Parses video MyCode.
*
* @param array Matches.
* @return string The built-up video code.
*/
function mycode_parse_video_callback($matches)
{
return $this->mycode_parse_video($matches[1], $matches[2]);
}
/**
* 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\(\)])(http|https|ftp|news){1}://([^\/\"\s\<\[\.]+\.([^\/\"\s\<\[\.]+\.)*[\w]+(:[0-9]+)?(/[^\"\s<\[]*)?)#i", "$1[url]$2://$3[/url]", $message);
$message = preg_replace("#([\>\s\(\)])(www|ftp)\.(([^\/\"\s\<\[\.]+\.)*[\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
* @return string The parsed message.
*/
function mycode_parse_list($message, $type="")
{
$message = str_replace('\"', '"', $message);
$message = preg_replace("#\s*\[\*\]\s*#", "\n", $message);
$message .= "";
if($type)
{
$list = "\n$message
\n";
}
else
{
$list = "\n";
}
$list = preg_replace("#<(ol type=\"$type\"|ul)>\s*#", "<$1>", $list);
return $list;
}
/**
* Parses list MyCode.
*
* @param array Matches
* @return string The parsed message.
*/
function mycode_parse_list_callback($matches)
{
return $this->mycode_parse_list($matches[1])."\n";
}
/**
* Parses list MyCode.
*
* @param array Matches
* @return string The parsed message.
*/
function mycode_parse_list_callback_type($matches)
{
return $this->mycode_parse_list($matches[2], $matches[1])."\n";
}
/**
* Strips smilies from a string
*
* @param string The message for smilies to be stripped from
* @return string The message with smilies stripped
*/
function strip_smilies($message)
{
if($this->smilies_cache == 0)
{
$this->cache_smilies();
}
if(is_array($this->smilies_cache))
{
$message = str_replace($this->smilies_cache, array_keys($this->smilies_cache), $message);
}
return $message;
}
/**
* Highlights a string
*
* @param string The message to be highligted
* @param string The highlight keywords
* @return string The message with highlight bbcodes
*/
function highlight_message($message, $highlight)
{
if(empty($this->highlight_cache))
{
$this->highlight_cache = build_highlight_array($highlight);
}
if(is_array($this->highlight_cache) && !empty($this->highlight_cache))
{
$message = preg_replace(array_keys($this->highlight_cache), $this->highlight_cache, $message);
}
return $message;
}
/**
* Parses message to plain text equivalents of MyCode.
*
* @param string The message to be parsed
* @return string The parsed message.
*/
function text_parse_message($message, $options=array())
{
global $plugins;
// Filter bad words if requested.
if($options['filter_badwords'] != 0)
{
$message = $this->parse_badwords($message);
}
// Parse quotes first
$message = $this->mycode_parse_quotes($message, true);
$message = preg_replace_callback("#\[php\](.*?)\[/php\](\r\n?|\n?)#is", array($this, 'mycode_parse_php_callback'), $message);
$message = preg_replace_callback("#\[code\](.*?)\[/code\](\r\n?|\n?)#is", array($this, 'mycode_parse_code_callback'), $message);
$find = array(
"#\[(b|u|i|s|url|email|color|img)\](.*?)\[/\\1\]#is",
"#\[img=([0-9]{1,3})x([0-9]{1,3})\](\r\n?|\n?)(https?://([^<>\"']+?))\[/img\]#is",
"#\[url=([a-z]+?://)([^\r\n\"<]+?)\](.+?)\[/url\]#si",
"#\[url=([^\r\n\"<&\(\)]+?)\](.+?)\[/url\]#si",
);
$replace = array(
"$2",
"$4",
"$3 ($1$2)",
"$2 ($1)",
);
$message = preg_replace($find, $replace, $message);
// Replace "me" code and slaps if we have a username
if($options['me_username'])
{
global $lang;
$message = preg_replace('#(>|^|\r|\n)/me ([^\r\n<]*)#i', "\\1* {$options['me_username']} \\2", $message);
$message = preg_replace('#(>|^|\r|\n)/slap ([^\r\n<]*)#i', "\\1* {$options['me_username']} {$lang->slaps} \\2 {$lang->with_trout}", $message);
}
// Special code requiring special attention
while(preg_match("#\[list\](.*?)\[/list\]#si", $message))
{
$message = preg_replace_callback("#\s?\[list\](.*?)\[/list\](\r\n?|\n?)#si", array($this, 'mycode_parse_list_callback'), $message);
}
// Replace lists.
while(preg_match("#\[list=(a|A|i|I|1)\](.*?)\[/list\](\r\n?|\n?)#si", $message))
{
$message = preg_replace_callback("#\s?\[list=(a|A|i|I|1)\](.*?)\[/list\]#si", array($this, 'mycode_parse_list_callback_type'), $message);
}
// Run plugin hooks
$message = $plugins->run_hooks("text_parse_message", $message);
return $message;
}
}
?>