Go Back   vb.org Archive > Community Discussions > Modification Requests/Questions (Unpaid)
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 09-11-2005, 03:16 PM
TosaInu's Avatar
TosaInu TosaInu is offline
 
Join Date: Jul 2004
Posts: 256
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default bbcodeparse.php

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

Code:
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?

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

How it works :
1) starting code is [table] 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]
- 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


[table 1 3 0]
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
[/table]


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;
	}
}
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:39 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03227 seconds
  • Memory Usage 2,221KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_threadedmode.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete