function initUbbParsing($text) {
if (!class_exists('StringParser_BBCode')) {
require_once (JPATH_SITE.DS.'components'.DS.'com_comment'.DS.'classes'.DS.'ubbcode'.DS.'stringparser_bbcode.class.php');
}
$bbcode = new StringParser_BBCode();
$bbcode->addFilter (STRINGPARSER_FILTER_PRE, 'JOSC_ubbcode::convertlinebreaks');
$bbcode->addParser (array ('block', 'inline', 'link', 'listitem'), 'nl2br');
$bbcode->addParser ('list', 'JOSC_ubbcode::bbcode_stripcontents');
$bbcode->addCode ('b', 'simple_replace', null, array ('start_tag' => '<b>', 'end_tag' => '</b>'),
'inline', array ('listitem', 'block', 'inline', 'link'), array ());
$bbcode->addCode ('i', 'simple_replace', null, array ('start_tag' => '<i>', 'end_tag' => '</i>'),
'inline', array ('listitem', 'block', 'inline', 'link'), array ());
$bbcode->addCode ('u', 'simple_replace', null, array ('start_tag' => '<u>', 'end_tag' => '</u>'),
'inline', array ('listitem', 'block', 'inline', 'link'), array ());
$bbcode->addCode ('s', 'simple_replace', null, array ('start_tag' => '<s>', 'end_tag' => '</s>'),
'inline', array ('listitem', 'block', 'inline', 'link'), array ());
$bbcode->addCode ('url', 'usecontent?', 'JOSC_ubbcode::do_bbcode_url', array ('usecontent_param' => 'default', 'support_link' => $this->_support_link ),
'link', array ('listitem', 'block', 'inline'), array ('link'));
$bbcode->addCode ('img', 'usecontent', 'JOSC_ubbcode::do_bbcode_img',
array ('usecontent_param' => 'default',
'image_width' => (int) $this->_pictures_maxwidth,
'support_pictures' => $this->_support_pictures,
'support_link' => $this->_support_link
),
'image', array ('listitem', 'block', 'inline', 'link'), array ());
$bbcode->setOccurrenceType ('img', 'image');
$bbcode->setMaxOccurrences ('image', 4);
$bbcode->addCode ('size', 'callback_replace', 'JOSC_ubbcode::do_bbcode_size', array ('usecontent_param' => 'default'),
'inline', array ('listitem', 'block', 'inline', 'link'), array ());
$bbcode->addCode ('color', 'callback_replace', 'JOSC_ubbcode::do_bbcode_color', array ('usecontent_param' => 'default'),
'inline', array ('listitem', 'block', 'inline', 'link'), array ());
$bbcode->addCode ('list', 'simple_replace', null, array ('start_tag' => '<ul>', 'end_tag' => '</ul>'),
'list', array ('block', 'listitem'), array ());
$bbcode->addCode ('*', 'simple_replace', null, array ('start_tag' => '<li>', 'end_tag' => '</li>'),
'listitem', array ('list'), array ());
$bbcode->setCodeFlag ('*', 'closetag', BBCODE_CLOSETAG_OPTIONAL);
$bbcode->setCodeFlag ('*', 'paragraphs', true);
$bbcode->setCodeFlag ('list', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT);
$bbcode->setCodeFlag ('list', 'opentag.before.newline', BBCODE_NEWLINE_DROP);
$bbcode->setCodeFlag ('list', 'closetag.before.newline', BBCODE_NEWLINE_DROP);
$bbcode->addCode ('quote', 'usecontent?', 'JOSC_ubbcode::do_bbcode_quote', array ('usecontent_param' => 'default'),
'block', array ('block'), array('inline'));
$bbcode->setCodeFlag ('quote', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT);
$bbcode->setCodeFlag ('quote', 'opentag.before.newline', BBCODE_NEWLINE_DROP);
$bbcode->setCodeFlag ('quote', 'closetag.before.newline', BBCODE_NEWLINE_DROP);
$bbcode->addCode ('code', 'usecontent?', 'JOSC_ubbcode::do_bbcode_code', array ('usecontent_param' => 'default'),
'block', array ('block'), array('inline'));
$bbcode->setCodeFlag ('code', 'paragraph_type', BBCODE_PARAGRAPH_BLOCK_ELEMENT);
$bbcode->setCodeFlag ('code', 'opentag.before.newline', BBCODE_NEWLINE_DROP);
$bbcode->setCodeFlag ('code', 'closetag.before.newline', BBCODE_NEWLINE_DROP);
$bbcode->setRootParagraphHandling (true);
$maxlength_word = ($this->_maxlength_word!=-1) ? $this->_maxlength_word : 999999;
$maxlength_text = ($this->_maxlength_text!=-1) ? $this->_maxlength_text : 999999;
$text = JOSC_utils::setMaxLength($text, $maxlength_text);
$text = $bbcode->parse ($text);
$nobreak = 'pre code blockquote';
$text = JOSC_utils::wrapWord($text,$maxlength_word, ' ', $nobreak);
return $text;
}