'\/', '^' => '\^', '$' => '\$', '.' => '\.', '[' => '\[', ']' => '\]', '|' => '\|', '(' => '\(', ')' => '\)', '?' => '\?', '*' => '\*', '+' => '\+', '{' => '\{', '}' => '\}', '\\' => '\\\\', '^' => '\^', '-' => '\-');
$utf8 = (KUNENA_CHARSET == 'UTF-8') ? "u" : "";
$type = ($history == 1) ? "-grey" : "";
$message_emoticons = array();
$message_emoticons = $iconList? $iconList : smile::getEmoticons($history);
// now the text is parsed, next are the emoticons
$fb_message_txt = $fb_message;
if ($emoticons != 1)
{
reset($message_emoticons);
while (list($emo_txt, $emo_src) = each($message_emoticons)) {
$emo_txt = strtr($emo_txt, $regexp_trans);
// Check that smileys are not part of text like:soon (:s)
$fb_message_txt = preg_replace('/(\W|\A)'.$emo_txt.'(\W|\Z)/'.$utf8, '\1\2', $fb_message_txt);
// Previous check causes :) :) not to work, workaround is to run the same regexp twice
$fb_message_txt = preg_replace('/(\W|\A)'.$emo_txt.'(\W|\Z)/'.$utf8, '\1\2', $fb_message_txt);
}
}
return $fb_message_txt;
}
function smileReplace($fb_message, $history, $emoticons, $iconList = null)
{
$fb_message_txt = $fb_message;
//implement the new parser
$parser = new TagParser();
$interpreter = new KunenaBBCodeInterpreter($parser);
$task = $interpreter->NewTask();
$task->SetText($fb_message_txt.' _EOP_');
$task->dry = FALSE;
$task->drop_errtag = FALSE;
$task->history = $history;
$task->emoticons = $emoticons;
$task->iconList = $iconList;
$task->Parse();
// Show Parse errors for debug
//$task->ErrorShow();
return substr($task->text,0,-6);
}
/**
* function to retrieve the emoticons out of the database
*
* @author Niels Vandekeybus
* @version 1.0
* @since 2005-04-19
* @param boolean $grayscale
* determines wether to return the grayscale or the ordinary emoticon
* @param boolean $emoticonbar
* only list emoticons to be displayed in the emoticonbar (currently unused)
* @return array
* array consisting of emoticon codes and their respective location (NOT the entire img tag)
*/
function getEmoticons($grayscale, $emoticonbar = 0)
{
$kunena_db = &JFactory::getDBO();
$grayscale == 1 ? $column = "greylocation" : $column = "location";
$sql = "SELECT code, `$column` FROM #__fb_smileys";
if ($emoticonbar == 1)
$sql .= " WHERE emoticonbar='1'";
$kunena_db->setQuery($sql);
$smilies = $kunena_db->loadObjectList();
check_dberror("Unable to load smilies.");
$smileyArray = array();
foreach ($smilies as $smiley) { // We load all smileys in array, so we can sort them
$smileyArray[$smiley->code] = '' . KUNENA_URLEMOTIONSPATH . $smiley->$column; // This makes sure that for example :pinch: gets translated before :p
}
if ($emoticonbar == 0)
{ // don't sort when it's only for use in the emoticonbar
array_multisort(array_keys($smileyArray), SORT_DESC, $smileyArray);
reset($smileyArray);
}
return $smileyArray;
}
function topicToolbar($selected, $tawidth)
{
//TO USE
// $topicToolbar = smile:topicToolbar();
// echo $topicToolbar;
//$selected var is used to check the right selected icon
//important for the edit function
$selected = (int)$selected;
?>
/si", "[center]", $fb_message_txt);
$fb_message_txt = preg_replace("//si", "[right]", $fb_message_txt);
$fb_message_txt = preg_replace("//si", "[s]", $fb_message_txt);
$fb_message_txt = preg_replace("%%si", "[/s]", $fb_message_txt);
$fb_message_txt = preg_replace("//si", "[b]", $fb_message_txt);
$fb_message_txt = preg_replace("%%si", "[/b]", $fb_message_txt);
$fb_message_txt = preg_replace("//si", "[i]", $fb_message_txt);
$fb_message_txt = preg_replace("%%si", "[/i]", $fb_message_txt);
//okay, now we've converted all HTML to known boardcode, nuke everything remaining itteratively:
while ($fb_message_txt != strip_tags($fb_message_txt)) {
$fb_message_txt = strip_tags($fb_message_txt);
}
return $fb_message_txt;
} // fbStripHtmlTags()
/**
* This will convert all remaining HTML tags to innocent tags able to be displayed in full
*/
function fbHtmlSafe($text)
{
$fb_message_txt = $text;
$fb_message_txt = str_replace("<", "<", $fb_message_txt);
$fb_message_txt = str_replace(">", ">", $fb_message_txt);
return $fb_message_txt;
} // fbHtmlSafe()
/**
* This function will write the TextArea
*/
function fbWriteTextarea($areaname, $html, $width, $height, $useRte, $emoticons)
{
// well $html is the $message to edit, generally it means in PLAINTEXT @Kunena!
global $editmode;
// ERROR: mixed global $editmode
$fbConfig =& CKunenaConfig::getInstance();
// (JJ) JOOMLA STYLE CHECK
if ($fbConfig->joomlastyle < 1) {
$boardclass = "fb_";
}
?>
* if you don't want the code to be damaged by insertion of newlines.
* Add the names of the elements you wish to protect from line-breaks as
* as a space separate list to the nobreak argument. Only names of
* valid HTML tags are accepted. (eg. "code pre blockquote")
*
* htmlwrap() will *always* break long strings of characters at the
* specified width. In this way, the function behaves as if the
* wordwrap() "cut" flag is always set. However, the function will try
* to find "safe" characters within strings it breaks, where inserting a
* line-break would make more sense. You may edit these characters by
* adding or removing them from the $lbrks variable.
*
* htmlwrap() is safe to use on strings containing UTF-8 multi-byte
* characters.
*
* See the inline comments and http://www.greywyvern.com/php.php
* for more info
******************************************************************** */
function htmlwrap($str, $width = 60, $break = "\n", $nobreak = "") {
// Split HTML content into an array delimited by < and >
// The flags save the delimeters and remove empty variables
$content = preg_split("/([<>])/", $str, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
// Transform protected element lists into arrays
$nobreak = explode(" ", strtolower($nobreak));
// Variable setup
$intag = false;
$innbk = array();
$drain = "";
// List of characters it is "safe" to insert line-breaks at
// It is not necessary to add < and > as they are automatically implied
$lbrks = "/?!%)-}]\\\"':;&";
// Is $str a UTF8 string?
// $utf8 = (preg_match("/^([\x09\x0A\x0D\x20-\x7E]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})*$/", $str)) ? "u" : "";
// original utf8 problems seems to cause problems with very long text (forumposts)
// replaced by a little simpler function call by fxstein 8-13-08
$utf8 = (KUNENA_CHARSET == 'UTF-8') ? "u" : "";
while (list(, $value) = each($content)) {
switch ($value) {
// If a < is encountered, set the "in-tag" flag
case "<": $intag = true; break;
// If a > is encountered, remove the flag
case ">": $intag = false; break;
default:
// If we are currently within a tag...
if ($intag) {
// Create a lowercase copy of this tag's contents
$lvalue = strtolower($value);
// If the first character is not a / then this is an opening tag
if ($lvalue{0} != "/") {
// Collect the tag name
preg_match("/^(\w*?)(\s|$)/", $lvalue, $t);
// If this is a protected element, activate the associated protection flag
if (in_array($t[1], $nobreak)) array_unshift($innbk, $t[1]);
// Otherwise this is a closing tag
} else {
// If this is a closing tag for a protected element, unset the flag
if (in_array(substr($lvalue, 1), $nobreak)) {
reset($innbk);
while (list($key, $tag) = each($innbk)) {
if (substr($lvalue, 1) == $tag) {
unset($innbk[$key]);
break;
}
}
$innbk = array_values($innbk);
}
}
// Else if we're outside any tags...
} else if ($value) {
// If unprotected...
if (!count($innbk)) {
// Use the ACK (006) ASCII symbol to replace all HTML entities temporarily
$value = str_replace("\x06", "", $value);
preg_match_all("/&([a-z\d]{2,7}|#\d{2,5});/i", $value, $ents);
$value = preg_replace("/&([a-z\d]{2,7}|#\d{2,5});/i", "\x06", $value);
// Enter the line-break loop
do {
$store = $value;
// Find the first stretch of characters over the $width limit
if (preg_match("/^(.*?\s)?([^\s]{".$width."})(?!(".preg_quote($break, "/")."|\s))(.*)$/s{$utf8}", $value, $match)) {
if (strlen($match[2])) {
// Determine the last "safe line-break" character within this match
for ($x = 0, $ledge = 0; $x < strlen($lbrks); $x++) $ledge = max($ledge, strrpos($match[2], $lbrks{$x}));
if (!$ledge) $ledge = strlen($match[2]) - 1;
// Insert the modified string
$value = $match[1].substr($match[2], 0, $ledge + 1).$break.substr($match[2], $ledge + 1).$match[4];
}
}
// Loop while overlimit strings are still being found
} while ($store != $value);
// Put captured HTML entities back into the string
foreach ($ents[0] as $ent) $value = preg_replace("/\x06/", $ent, $value, 1);
}
}
}
// Send the modified segment down the drain
$drain .= $value;
}
// Return contents of the drain
return $drain;
}
} //class
?>