PDA

View Full Version : bbcodeparse.php


TosaInu
09-11-2005, 03:16 PM
Hello,

We have two hacks/tweaks in that file, one is a table hack (using custom BB code in ACP results in dangerous code) and a line that strips html (imported code left from ancient boards like UBB).

This was the code that stripped HTML


inlucudes/functions_bbcodeparse.php

1. find
// ###################### Start bbcodeparse2 #######################
function parse_bbcode2($bbcode, $dohtml, $dobbimagecode, $dosmilies, $dobbcode, $iswysiwyg = 0, $donl2br = 1)
{
// parses text for vB code, smilies and censoring

global $DB_site, $vboptions, $bbuserinfo, $templatecache, $smiliecache;
global $html_allowed;

add

//strip html M:\vbul-hacks\striphtml\vBulletin_org Forum - Removing HTML Code From Posts.htm
$bbcode = strip_tags(unhtmlspecialchars($bbcode));
//End Hack

The author who made the table hack isn't going to port it (afaik), it's a code that can have some options and is frequently used. It adds new code only and I wonder whether it would just work in some new file?

BB code tables by JohnWoo :)
It still needs optimization, but should work fine already :)

How it works :
1) starting code is or [table 1 2 3] where
1 2 3 any numbers separated by space
first - border
second - cellpadding
third - cellspacing

- ending tag is always
- table lines separated by line break
- each line can have 7 styles. To specify a style add in the beginning number and ^ symbol without spaces
example:
2^
you may skip 7^ - it is default (alt1) style
- ceils in line separated by |
- there is no need to add | before first and after last ceil
- each ceil can have each own align. Use align mark as a first symbol of ceil without spaces
blank (default) - left
= - center
~ - right

- you can use any other BB code inside ceils :)
- if number of ceils different in lines, last ceil of shorter lines will get colspan= with needed number

so table in post may look like



1|2|test 16798789789797979799879797979|4|5|6|7
1^~right with colspan
2^333|=center with colspan
3^1|2|left with colspan
4^1|~center without colspan|3|4|5|6|7
5^1|blablabla|3|4|5
6^1|2|3|4|5|6|7



code changes
includes/functions_bbcodeparse.php
1. find
// do new lines
$wysiwygtype = null;

before it add

$bbcode = preg_replace("~(\[table.+\[/table\])~iUse", "fetch_html_table('\\1')", $bbcode);

2. in the end of file add 2 functions.

function get_table_class($id) {
$id = intval($id);
if ($id == 1) {
return " class=\"alt2\"";
} elseif ($id == 2) {
return " class =\"tcat\"";
} elseif ($id == 3) {
return " class=\"tfoot\"";
} elseif ($id == 4) {
return " class=\"highlight\"";
} elseif ($id == 5) {
return " class=\"alt3\"";
} elseif ($id == 6) {
return " class=\"smallfont\"";
} else {
return " class =\"alt1\"";
}
}

function fetch_html_table ($tblcode) {
if (preg_match("~\[table( (\d)+ (\d)+ (\d)+|)\](.+)\[/table\]~isU", $tblcode, $rows)) {
$params = "";
if (strlen($rows[2]) > 0) {
$params .= " border=\"".intval($rows[2])."\"";
}
if (strlen($rows[3]) > 0) {
$params .= " cellpadding=\"".intval($rows[3])."\"";
}
if (strlen($rows[4]) > 0) {
$params .= " cellspacing=\"".intval($rows[4])."\"";
}
$bb_table = array();
$tbl_k=0;
$tbl_max = 0;
$tbl_all = split("\n",trim($rows[5]));
if (is_array($tbl_all)) {
foreach ($tbl_all as $tbl_i => $tbl_string) {
$bb_table[$tbl_k] = array();
preg_match("~((\d)\^|)(.+)~", trim($tbl_string), $tbl_new);
$bb_table[$tbl_k]["class"] = get_table_class(intval($tbl_new[2]));
$tbl_c = split("\|", $tbl_new[3]);
$tbl_l = 0;
if (is_array($tbl_c)) {
foreach ($tbl_c as $tbl_ii => $tbl_ss) {
$bb_table[$tbl_k][$tbl_l] = array();
$bb_table[$tbl_k][$tbl_l]["align"] = "";
preg_match("#(=|~|)(.+)#", $tbl_ss, $tbl_ceil);
if ($tbl_ceil[1] == "=") {
$bb_table[$tbl_k][$tbl_l]["align"] = " align=\"center\"";
} elseif ($tbl_ceil[1] == "~") {
$bb_table[$tbl_k][$tbl_l]["align"] = " align=\"right\"";
}
$bb_table[$tbl_k][$tbl_l]["text"] = trim($tbl_ceil[2]);
$tbl_l++;
unset($tbl_ceil);
}
}
if ($tbl_max < $tbl_l) {
$tbl_max = $tbl_l;
}
$tbl_k++;
}
}

$html_table = "<table".$params.">";
foreach ($bb_table as $id => $this_row) {
$html_table .="<tr>";
$k = count($this_row)-2;
for ($i=0;$i < $k;$i++) {
if (array_key_exists($i, $bb_table[$id]) && strlen($bb_table[$id][$i]["text"]) > 0) {
$html_table .="<td".$bb_table[$id]["class"].$bb_table[$id][$i]["align"].">".$bb_table[$id][$i]["text"]."</td>";
} else {
$html_table .="<td>&nbsp;</td>";
}
}
if ($k+1 < $tbl_max) {
$html_table .="<td".$bb_table[$id]["class"].$bb_table[$id][$k]["align"]." colspan=\"".($tbl_max-$k)."\">".$bb_table[$id][$k]["text"]."</td>";
} else {
$html_table .="<td".$bb_table[$id]["class"].$bb_table[$id][$k]["align"].">".$bb_table[$id][$k]["text"]."</td>";
}
$html_table .="</tr>";
}
$html_table .= "</table>";
return $html_table;
} else {
return $tblcode;
}
}

TosaInu
09-15-2005, 07:29 PM
Any ideas about this HTML stripper and table tag for 3.5?

Andreas
09-16-2005, 04:32 AM
Yes: I can say that it can be quite easily done with Plugins in vBulletin 3.5

TosaInu
09-17-2005, 05:29 PM
Yes: I can say that it can be quite easily done with Plugins in vBulletin 3.5

That's good news.

TosaInu
10-03-2005, 10:20 AM
$bbcode = strip_tags(unhtmlspecialchars($bbcode));

Our board is a grab together of several older boards and it contains quite some HTML. I've been busy with a text stripper from vb.com to edit it out (should make this always on processing step obsolete and would reduce database size a little bit, but it didn't work out that great). The database is way too big to edit it out by hand, and a script would even timeout because of the PHP/Apache settings. There was a rebuild thread tool in another board we used and thus I wonder whether it's possible to have a html stripper thead tool: get rid of old html in the database and avoid timeouts while doing so because of huge queries, because you only order one thread at a time to be cleaned.

silurius
10-27-2005, 09:00 PM
I've added this code, but I'm not seeing the table in my posts. Can someone help me out with this?

Detomah
11-08-2005, 12:29 AM
Yes: I can say that it can be quite easily done with Plugins in vBulletin 3.5

Could you possibly help me with this an explain the easy way you mention that this could be done with plugins please, as i've not got a clue how to include that table code as a plugin and get it to actually work?

MaLTRaiN
04-08-2006, 05:29 PM
Someone here?
I need this too...