1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-17 20:01:47 +02:00

table bbcodes

This commit is contained in:
CaMer0n
2012-06-09 12:01:24 +00:00
parent 839a89e84c
commit 4342599079
5 changed files with 38 additions and 10 deletions

View File

@@ -1,4 +1,10 @@
//<?
$class = e107::getBB()->getClass('table');
return "<table class='{$class}'>".$code_text."</table>";
if($parm)
{
return "<table class='{$class}' {$parm}>".trim($code_text)."</table>";
}
return "<table class='{$class}'>".trim($code_text)."</table>";

View File

@@ -1,4 +1,4 @@
//<?php
$class = e107::getBB()->getClass('tbody');
return "<tbody class='{$class}'>".$code_text."</tbody>\n";
return "<tbody class='{$class}'>".trim($code_text)."</tbody>";

View File

@@ -44,7 +44,7 @@ class e_bbcode
'b', 'justify', 'file', 'stream',
'textarea', 'list', 'php', 'time',
'spoiler', 'hide', 'youtube', 'sanitised',
'p', 'h', 'nobr', 'block',
'p', 'h', 'nobr', 'block','table','tr','tbody','td'
);
foreach($this->core_bb as $c)
@@ -507,7 +507,7 @@ class e_bbcode
/**
* Convert HTML to bbcode.
*/
function htmltoBbcode($text)
function htmltoBBcode($text)
{
//return $text;
$convert = array(
@@ -525,7 +525,22 @@ class e_bbcode
array( "[/b]", '</strong>'),
array( "[i]", '<em class="bbcode italic bbcode-i">'), // e107 bbcode markup
array( "[i]", '<em>'),
array( "[/i]", '</em>'),
array( "[/i]", '</em>'),
array( "[block]", '<div>'),
array( "[/block]", '</div>'),
array( "[table]\n", '<table>'),
array( "[/table]", '</table>'),
array( "[table]\n", '<table class="bbcode-table">'),
array( "[tbody]\n", '<tbody class="bbcode-tbody">'),
array( "[tr]", '<tr class="bbcode-tr">'),
array( "\n\t[td]", '<td class="bbcode-td">'),
array( "[tbody]\n", '<tbody>'),
array( "[/tbody]\n", '</tbody>'),
array( "[tr]", '<tr>'),
array( "\n[/tr]\n", '</tr>'),
array( "\n\t[td]", '<td>'),
array( "[/td]", '</td>'),
);
foreach($convert as $arr)
@@ -541,6 +556,9 @@ class e_bbcode
$text = preg_replace('/<img class="bbcode bbcode-img"(?:\s*)?(?:style="([^"]*)")?\s?(?:src="([^"]*)")(?:\s*)?(?:alt="(\S*)")?(?:\s*)?(?:width="([\d]*)")?\s*(?:height="([\d]*)")?(?:\s*)?\/>/i',"[img style=width:$4px;height:$5px;$1]$2[/img]",$text );
$text = preg_replace('/<span (?:class="bbcode-color" )?style=\"color: ?(.*?);\">(.*?)<\/span>/i',"[color=$1]$2[/color]",$text);
$text = preg_replace('/<span (?:class="bbcode underline bbcode-u" )?style="text-decoration: underline;">(.*?)<\/span>/i',"[u]$1[/u]",$text);
// $text = preg_replace('/<table([^"]*)>/i', "[table $1]",$text);
$text = preg_replace('/<table style="([^"]*)"([\w ="]*)?>/i', "[table style=$1]\n",$text);
$text = preg_replace('/<tbody([\w ="]*)?>/i', "[tbody]\n",$text);
$blank = array('</li>','width:px;height:px;');

View File

@@ -1333,7 +1333,7 @@ class e_parse
{
// Split each text block into bits which are either within one of the 'key' bbcodes, or outside them
// (Because we have to match end words, the 'extra' capturing subpattern gets added to output array. We strip it later)
$content = preg_split('#(\[(html|php|code|scode|hide).*?\[/(?:\\2)\])#mis', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
$content = preg_split('#(\[(table|html|php|code|scode|hide).*?\[/(?:\\2)\])#mis', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
}
@@ -1357,7 +1357,7 @@ class e_parse
// Have to have a good test in case a 'non-key' bbcode starts the block
// - so pull out the bbcode parameters while we're there
if (($parseBB !== FALSE) && preg_match('#(^\[(html|php|code|scode|hide)(.*?)\])(.*?)(\[/\\2\]$)#is', $full_text, $matches ))
if (($parseBB !== FALSE) && preg_match('#(^\[(table|html|php|code|scode|hide)(.*?)\])(.*?)(\[/\\2\]$)#is', $full_text, $matches ))
{
// It's one of the 'key' bbcodes
// Usually don't want 'normal' processing if its a 'special' bbcode
@@ -1402,6 +1402,11 @@ class e_parse
$proc_funcs = TRUE;
$convertNL = FALSE;
break;
case 'table' : // strip <br /> from end of <table>
$convertNL = FALSE;
// break;
case 'hide' :
$proc_funcs = TRUE;
@@ -1473,7 +1478,7 @@ class e_parse
// Could put tag stripping in here
/*
// Line break compression - filter white space after HTML tags - among other things, ensures HTML tables display properly
// Hopefully now achieved by other means
@@ -1665,7 +1670,6 @@ class e_parse
}
}
if ($convertNL)
{
// Default replaces all \n with <br /> for HTML display

View File

@@ -20,7 +20,7 @@ if($_POST['mode'] == 'tohtml')
if($_POST['mode'] == 'tobbcode')
{
//echo $_POST['content'];
echo e107::getBB()->htmltoBbcode($_POST['content']);
echo e107::getBB()->htmltoBBcode($_POST['content']);
}