<?php
/* Check Structure Availability */
if (!defined("CORE_STRAP")) die("Out of structure call");
/*
Those are the body codes conversion functions.
They are used wherever a user-submitted body is
parsed. The first function convert the body
codes to HTML entities, the second one remove
those body codes.
*/
function convertBodyCodes($body) {
/*
The following is the replacement array, note
that the spaces before and after HTML versions
is used to prevent building up long strings that
can't be cut by the chopper function bewlow as
it was built not to cut in the middle of a string
that stands inside a html tag - this prevents
cutting a long link in two parts thus making it
unusable
*/
$BCRegExpArrayPattern = array(
'/(!|!){10,}/',
'%\\[color (([a-zA-Z0-9#]*))\\]([^\\[]*)\\[/color\\]%',
'%\\[b\\]([^\\[]*)\\[/b\\]%',
'%\\[img\\]([^\\[]*)\\[/img\\]%',
'%\\[i\\]([^\\[]*)\\[/i\\]%',
'%\\[u\\]([^\\[]*)\\[/u\\]%',
'%\\[quote\\]([^\\[]*)\\[/quote\\]%',
'%\\[s\\]([^\\[]*)\\[/s\\]%',
'%\\[tt\\]([^\\[]*)\\[/tt\\]%',
'/\\b((https?|ftp):\/\/([-A-Z0-9.]+)(\/[-A-Z0-9+&@#\/%=~_|!:,.;]*)?(\\?[-A-Z0-9+&@#\/%=~_|!:,.;]*)?)/si',
'/\\n/',
);
$BCRegExpArrayReplace = array(
'!',
'<span style="color: \\1">\\3</span> ',
'<strong>\\1</strong> ',
'<img src=\"\\1\"> ',
'<em>\\1</em> ',
'<u>\\1</u> ',
'<blockquote><p> \\1 </p></blockquote>',
'<s>\\1</s> ',
'<tt>\\1</tt> ',
'<a href="\\1" target="_blank">\\3</a>',
'<br /> ',
);
$body = preg_replace($BCRegExpArrayPattern, $BCRegExpArrayReplace, $body);
foreach(explode(" ", strip_tags($body)) as $key => $line) {
/*
Break long strings into smaller chunks (prevents
destroying the interface with a 500 characters
long "word"
*/
if (strlen($line) > 50) $body = str_replace($line, wordwrap($line, 25, " ", 1), $body);
}
/*
Return the body to the caller
*/
return $body;
}
function clearBodyCodes($body) {
/*
The following is the replacement array. All the body
codes are converted into a single space (except the
\n character which is still converted into a BR)
*/
$BCRegExpArrayPattern = array(
'/(!|!){10,}/',
'%\\[color (([a-zA-Z0-9#]*))\\]([^\\[]*)\\[/color\\]%',
'%\\[b\\]([^\\[]*)\\[/b\\]%',
'%\\[img\\]([^\\[]*)\\[/img\\]%',
'%\\[i\\]([^\\[]*)\\[/i\\]%',
'%\\[u\\]([^\\[]*)\\[/u\\]%',
'%\\[quote\\]([^\\[]*)\\[/quote\\]%',
'%\\[s\\]([^\\[]*)\\[/s\\]%',
'%\\[tt\\]([^\\[]*)\\[/tt\\]%',
'/\\n/',
);
$BCRegExpArrayReplace = array(
'!',
'\\3 ',
'\\1 ',
'\\1 ',
'\\1 ',
'\\1 ',
'\\1 ',
'\\1 ',
'<br /> ',
);
$body = preg_replace($BCRegExpArrayPattern, $BCRegExpArrayReplace, $body);
/*
Break long strings into smaller chunks (prevents
destroying the interface with a 500 characters
long "word"
*/
foreach(explode(" ", strip_tags($body)) as $key => $line) {
if (strlen($line) > 50) $body = str_replace($line, wordwrap($line, 25, " ", 1), $body);
}
/*
Return the body to the caller
*/
return $body;
}
function convertImages($body) {
return preg_replace(
'%\\[image (([a-zA-Z0-9\\.:_\\/]*))\\]%im',
"<div style=\"clear:both;\">"
."<a href=\"\\1\" target=\"_blank\">"
."<img src=\"system/imagestream.php?location=\\1\" id=\"bodyCodeImage\">"
."</a></div>",
$body);
}
function convertEmoticons($body) {
$emoticons = array(
":-(|)" => "face-monkey.png",
":devil:" => "face-devil-grin.png",
"0:)" => "face-angel.png",
":~(" => "face-crying.png",
"B-)" => "face-glasses.png",
"B)" => "face-glasses.png",
":*" => "face-kiss.png",
":|" => "face-plain.png",
":(" => "face-sad.png",
":)" => "face-smile.png",
":D" => "face-smile-big.png",
":O" => "face-surprise.png",
";)" => "face-wink.png",
";-)" => "face-wink.png",
":idea:" => "idea.png",
":love:" => "love.png",
":music:" => "music.png",
);
foreach ($emoticons as $emot => $image) {
$body = str_replace($emot, "<img src=\"theme/{$GLOBALS["THEME"]}/images/icons/emoticons/{$image}\" align=\"absbottom\" width=\"16\" height=\"16\">", $body);
}
return $body;
}
?>