PHP Code:
function badlink($link, $prefix) {
if ($prefix == "mailto:") {
if (strpos($link, "@") === FALSE || strpos($link, ".", (strpos($link, "@")+2)) === FALSE || substr_count($link, "@") > 1 || strpos($link, "@") == 0) {
return 1;
}
}
if (strpos($link, ".") == 0 || strpos($link, ".") == strlen($link) || (strpos($link, "/") < strpos($link, ".") && strpos($link, "/") !== FALSE)) {
return 1;
}
};
function setlinks($r, $prefix) {
if (substr($r, 0, strlen($prefix)) == $prefix) {
$r = "\n".$r;
}
$r = str_replace("<br>".$prefix, "<br>\n".$prefix, $r);
$r = str_replace(" ".$prefix, " \n".$prefix, $r);
while (strpos($r, "\n".$prefix) !== FALSE) {
list($r1, $r2) = explode("\n".$prefix, $r, 2);
if (strpos($r2, " ") === FALSE && strpos($r2, "<br>") === FALSE) {
if ($prefix != "mailto:") {
$target = ' target="_blank"';
}
else {
$target = "";
}
if (strpos($r2, ".") > 1 && strpos($r2, ".") < strlen($r2) && badlink($r2, $prefix) != 1) {
$r = $r1.'<a href="'.$prefix.$r2.'"'.$target.'>'.$prefix.$r2.'</a>';
}
else {
$r = $r1.$prefix.$r2;
}
}
else {
if (strpos($r2, " ") === FALSE || ( strpos($r2, " ") > strpos($r2, "<br>") && strpos($r2, "<br>") !== FALSE)) {
list($r2, $r3) = explode("<br>", $r2, 2);
if (badlink($r2, $prefix) != 1) {
$r = $r1.'<a href="'.$prefix.$r2.'"'.$target.'>'.$prefix.$r2.'</a><br>'.$r3;
}
else {
$r = $r1.$prefix.$r2.'<br>'.$r3;
}
}
else {
list($r2, $r3) = explode(" ", $r2, 2);
if (strpos($r2, ".") > 1 && strpos($r2, ".") < strlen($r2) && badlink($r2, $prefix) != 1) {
$r = $r1.'<a href="'.$prefix.$r2.'"'.$target.'>'.$prefix.$r2.'</a> '.$r3;
}
else {
$r = $r1.$prefix.$r2.' '.$r3;
}
}
}
}
return $r;
};
function bb($r) {
$r = trim($r);
$r = htmlentities($r);
$r = str_replace("\r\n","<br>",$r);
$r = str_replace("[b]","<b>",$r);
$r = str_replace("[/b]","</b>",$r);
$r = str_replace("[i]","<i>",$r);
$r = str_replace("[/i]","</i>",$r);
$r = str_replace("[u]","<u>",$r);
$r = str_replace("[/u]","</u>",$r);
$r = str_replace("[spoiler]",'[spoiler]<font color="#DDDDDD">',$r);
$r = str_replace("[/spoiler]","</font>[/spoiler]",$r);
//set [link]s
while (strpos($r, "[link=") !== FALSE) {
list ($r1, $r2) = explode("[link=", $r, 2);
if (strpos($r2, "]") !== FALSE) {
list ($r2, $r3) = explode("]", $r2, 2);
if (strpos($r3, "[/link]") !== FALSE) {
list($r3, $r4) = explode("[/link]", $r3, 2);
$target = ' target="_blank"';
if (substr($r2, 0, 7) == "mailto:") {
$target = "";
}
$r = $r1.'<a href="'.$r2.'"'.$target.'>'.$r3.'</a>'.$r4;
}
else {
$r = $r1."[link\n=".$r2."]".$r3;
}
}
else {
$r = $r1."[link\n=".$r2;
}
}
$r = str_replace("[link\n=","[link=",$r);
////[link]
///default url link setting
$r = setlinks($r, "http://");
$r = setlinks($r, "https://");
$r = setlinks($r, "ftp://");
$r = setlinks($r, "mailto:");
////links
///emoticons
$r = str_replace(":)",'<img src="myhappyimg.gif">',$r);
$r = str_replace(":(",'<img src="mysadimg.gif">',$r);
//Repeat for more if desired.
///emoticons
$r = trim($r);
return $r;
}
Notes: The first function is used in the second and the second in the third, main function. So you don't want to change the order of these. Also, you cannot set a function within another because if it's called twice, an error will be generated.
Bookmarks