function Parse($text, $type = 'text', $arFile = array(), $arParams = array())
{
$type = $this->textType = ($type == 'html' ? 'html' : 'text');
$this->arNowiki = array();
$this->arLink = array();
$this->arLinkExists = array();
$this->arFile = $arFile;
$this->arVersionFile = array();
// An array can be either array (23,45,67), and array ('file_name' => 'file_path'), if this version of the document in the history of
if (!is_array($this->arFile))
$this->arFile = array();
foreach ($this->arFile as $_k => $file)
{
if (!is_numeric($file) && !is_numeric($_k))
{
$this->arVersionFile[$_k] = $file;
unset($this->arFile[$_k]);
}
}
reset($this->arFile);
if(isset($arParams["POST_URL"]))
$this->postUrl = (CMain::IsHTTPS() ? "https://" : "http://").$_SERVER["HTTP_HOST"].$arParams["POST_URL"];
// cut code
$text = preg_replace_callback("/({{{(.*)}}})/imsU".BX_UTF_PCRE_MODIFIER, array(&$this, '_codeCallback'), $text);
$text = preg_replace_callback("/([CODE](.*)[/CODE])/imsU".BX_UTF_PCRE_MODIFIER, array(&$this, '_codeCallback'), $text);
// cut nowiki
$text = preg_replace_callback('/((.*))/isU'.BX_UTF_PCRE_MODIFIER, array(&$this, '_noWikiCallback'), $text);
#if($this->textType == "html")
# $text = CWikiUtils::htmlspecialchars_decode($text);
// bi
$text = str_replace("'''", "'''", $text);
$text = str_replace("''", "''", $text);
$text = preg_replace(
array(
'/'{3}(.*)'{2}(.+)'{2}(.*)'{3}/imU'.BX_UTF_PCRE_MODIFIER,
'/'{3}(.+)'{3}/imU'.BX_UTF_PCRE_MODIFIER,
'/'{2}(.+)'{2}/imU'.BX_UTF_PCRE_MODIFIER
),
array(
'\1\2\3',
'\1',
'\1'
),
$text);
// hr
$text = preg_replace( '/-----*/'.BX_UTF_PCRE_MODIFIER, '\1
', $text );
// Header
for($i = 6; $i >= 1; $i--)
{
$_H = str_repeat('=', $i);
$text = preg_replace('/^s*'.$_H.'(.+?)'.$_H.'s*$/miU'.BX_UTF_PCRE_MODIFIER, '\1', $text);
}
// Internal link & categories
$text = $this->processInternalLink($text);
// External link
$text = preg_replace_callback('/[((http|https|ftp)(.+))( (.+))?]/iU'.BX_UTF_PCRE_MODIFIER, array(&$this, '_processExternalLinkCallback'), $text);
// images and other files
$text = preg_replace_callback('/[?[(:)?(File|'.GetMessage('FILE_NAME').'):(.+)]]?/iU'.BX_UTF_PCRE_MODIFIER, array(&$this, '_processFileCallback'), $text);
// TOC
$text = $this->processToc($text);
// Paste nowiki
if (!empty($this->arNowiki))
$text = preg_replace_callback('/(##NOWIKI(d+)##)/isU'.BX_UTF_PCRE_MODIFIER, array(&$this, '_noWikiReturnCallback'), $text);
$text = preg_replace_callback('/(##NOWIKI(d+)##)/isU'.BX_UTF_PCRE_MODIFIER, array(&$this, '_noWikiReturn2Callback'), $text);
if ($type == 'text')
{
$text = preg_replace("/()s*(){0,1}(s*(r*n)s*){1,2}/ism", "$1##NN##", $text);
$text = preg_replace("/()s*(){0,1}(s*(r*n)s*){1,2}/ism", "$1##NN##", $text);
$text = preg_replace("/s*(r*n)/ismU", "##BR##", $text);
$text = self::NToBr($text);
$text = preg_replace("/##NN##/ismU","n", $text);
$text = preg_replace("/##BR##/ismU","
n", $text);
}
// Paste code
$text = preg_replace_callback('/(##CODE(d+)##)/isU'.BX_UTF_PCRE_MODIFIER, array(&$this, '_codeReturnCallback'), $text);
// $text .= '';
return $text;
}