'[u]', 2 => '[/u]', 3 => '[i]', 4 => '[/i]', 5 => '[b]', 6 => '[/b]', 7 => '[cool]', 8 => '[/cool]', 9 => '[code]', 10 => '[/code]', 11 => '[indent]', 12 => '[/indent]', 13 => '[lyrics]', 14 => '[/lyrics]', 15 => '[smallcaps]', 16 => '[/smallcaps]', 17 => '[big]', 18 => '[/big]', 19 => '[small]', 20 => '[/small]', 21 => '[tt]', 22 => '[/tt]', 23 => '[sub]', 24 => '[/sub]', 25 => '[sup]', 26 => '[/sup]' ); // Replacement repo, for what to change the BBCode tags into. private $reptags = array( 1 => '', 2 => '', 3 => '', 4 => '', 5 => '', 6 => '', 7 => '', 8 => '', 9 => '
',
10 => "\n
', 12 => '', 13 => '', 14 => '', 15 => '', 16 => '', 17 => '', 18 => '', 19 => '', 20 => '', 21 => '', 22 => '', 23 => '', 24 => '', 25 => '', 26 => '' ); // XHTML-like tag repo. private $xhtml = array ( '[bull /]' => '•', '[copyright /]' => '©', '[registered /]' => '®', '[tm /]' => '™' ); // Repos for smilies! Full name and simplified tags. private $emoticons = array('confident', 'happy', 'crying', 'friendly', 'evil', 'panic', 'indifferent', 'angel', 'teasing', 'angry', 'polite', 'mad', 'tearing', 'yelling', 'sad', 'skeptical'); private $altEmoticons = array(':)', ':D', ';(', ';)', '>:)', ':O', ':|', 'O:)', ':P', ':(', ':3', ':X', ':@', ':()', ':/', ':\\'); protected $parserVerion = "v1.0.0"; protected $resourceBin = "http://madsplash.net/Resources"; function __construct() { ## TODO no need for special construct rules yet. } public function SpamShield($email) { ## This changes every character in an email address to it's ordinal value. ## Makes it that much harder for spambots to get the email address. ## The visitor won't see a difference. $email = trim($email); $intEmail = ""; $num = 0; while($num < strlen($email)) { if(empty($intemail)) { $intemail = "" . ord($email[$num]); } else { $intemail .= "" . ord($email[$num]); } $num++; } return $intemail; } public function alterArray($array, $operation = "") { switch($operation) { case "lower": foreach($array as $op1Num => $op1Data) { $array[$op1Num] = strtolower($op1Data); } break; case "clean": foreach($array as $op2Num => $op2Data) { if($op2Data == null || strlean($op2Data) < 1 || empty($op2Data)) { unset($array[$op2Num]); } } break; default: return $array; } return $array; } // Enhanced str_ireplace function replaceTool($seek, $replace, $subject) { if(function_exists("str_ireplace")) { return str_ireplace($seek, $replace, $subject); } else { $seek = preg_quote($seek, "#"); return preg_replace("#" . $seek . "#i", $replace, $subject); } } public function parse($string, $toBr = false, $justParse = false, $protectMails = true, $onShutdown = "") { // A R G U M E N T S # $string = the text you want to format # $toBr = convert newlines (\n) to
<$highlight_string_type style=\"color: #000000;\">\n<", $s);
## [list]...[/list] parse.
if(preg_match("#\[list\](.*?)\[\/list\]#is", $s)) {
preg_match_all("#\[list\](.*?)\[\/list\]#is", $s, $list);
$list = $list[1];
$backupList = $list;
## Now we seperate the lines.
foreach($list as $listNum => $lt) {
$lt = explode("\n", $lt);
unset($lt[0], $lt[count($lt)]); ## Getting rid of the first and last arrays.
foreach($lt as $ltaNum => $lta) {
$ltw = str_replace("\n", '', $lta);
$lt[$ltaNum] = '' . $lta . ' ';
}
$lt = implode("", $lt);
$list[$listNum] = '';
## Finally, replace.
foreach($backupList as $backupListNum => $bla) {
$s = str_replace($bla, $list[$backupListNum], $s);
}
}
$s = $this->replaceTool('[list]replaceTool('
[/list]', '
', $s);
}
## Clean empty lists.
$s = preg_replace("#\([\r\n])\<\/li\>#", '', $s);
## Fix line formats. Necessary for the deparsing process.
$s = $this->replaceTool(' ', " \n", $s);
// E X T R A S
if($protectMails) {
$emails = preg_match_all("#\#Ui", $s, $emailsFound);
$correctEmails = $emailsFound[1];
foreach($correctEmails as $emailNum => $emailContent) {
$protected = $this->SpamShield($correctEmails[$emailNum]);
$currentEmail = $correctEmails[$emailNum];
$currentEmail = str_replace('#', '\#', $currentEmail);
$s = preg_replace("#\#i", "", $s);
}
$simplemPattern = "#\(.*)\@(.*)\<\/a\>#Ui"; // * simplem = simple Mail
$simplemProtect = preg_match_all($simplemPattern, $s, $simplemFound);
$simplemImportant = $simplemFound[1];
$smCount = count($simplemImportant);
for($csm = 0; $sm < $smCount; $csm++) {
$this_simplem = $simplemImportant[$csm];
$smExp = explode('&', $this_simplem);
## Clean up the array.
foreach($smExp as $smArNum => $smEntries) {
$remove = array('#', ';');
$smExp[$smArNum] = str_replace($remove, NULL, $smExp[$smArNum]);
if(empty($smExp[$smArNum])) {
unset($smExp[$smArNum]);
}
}
foreach($smExp as $numsNum => $asciiStuff) {
$smExp[$numsNum] = sprintf('%c', $asciiStuff);
}
foreach($smExp as $nonAlphanumericNum => $nonAlphanumeric) {
// Neither quotemeta() nor preg_quote() are sufficient here.
if($smExp[$nonAlphanumericNum] == '#') {
$smExp[$nonAlphanumericNum] = '\W';
} elseif(!preg_match("#[A-Z0-9]#", $smExp[$nonAlphanumericNum])) {
$smExp[$nonAlphanumericNum] = '\\' . $smExp[$nonAlphanumericNum];
}
}
$smExp = implode("", $smExp);
$this_simplem = str_replace('#', '\#', $this_simplem);
$this_simplem = str_replace('&', '\&', $this_simplem);
$this_replace = str_replace(array('\#', '\&'), array('#', '&'), $this_simplem);
$s = preg_replace("#\$smExp\<\/a\>#i", "$this_replace", $s);
}
}
if($toBr) {
## The following line cleans up the garbage made by
## previous search and replace actions.
$s = str_replace('
', NULL, $s);
$s = nl2br($s);
## Now, we'll remove the
's within the [code] and [/list] tags.
## It will also remove the breaks around them.
## This will greatly enhace the parsed text, especially when using Opera.
$lineBreaks = array(
0 => array('', '
'),
1 => array('', '
')
);
foreach($lineBreaks as $breakArray) {
$break1 = $breakArray[0];
$break2 = $breakArray[1];
$break1Quoted = preg_quote($break1, '#');
$break2Quoted = preg_quote($break2, '#');
$breakNeedle = "#" . $break1Quoted . "(.+?)" . $break2Quoted . "#sie";
$s = preg_replace($breakNeedle, "'" . $break1 . "'.str_replace('
', '', str_replace('\\\"', '\"', '$1')).'" . $break2 . "'", $s);
$s = preg_replace("#\
(\r\n)" . $break1Quoted . "#i", "\n" . $break1, $s);
$s = preg_replace("#" . $break2Quoted . "\
#i", $break2, $s);
$s = preg_replace("#" . $break2Quoted . "(\r\n)\
#i", $break2, $s);
}
## Some other tags.
$s = str_replace('
', '' . "\n", $s);
$s = str_replace('
' . "\r\n" . '', $s);
} else {
## If not, just simply clean!
$s = str_replace('
', NULL, $s);
}
if($justParse) {
echo $s;
} else {
return $s;
}
@eval($onShutdown);
} ## Parse() is finally finished.
} ## The ParserModule is finally finished.
if ($_GET['smiley'] != "") {
$parser = new parser;
$parser->showSmileys();
}
?>