function _xbbcode_table_render in Extensible BBCode 8
Same name and namespace in other branches
- 7 xbbcode_table/xbbcode_table.module \_xbbcode_table_render()
Renders a table tag.
1 string reference to '_xbbcode_table_render'
- xbbcode_table_xbbcode_info in xbbcode_table/
xbbcode_table.module - Implements hook_xbbcode_info().
File
- xbbcode_table/
xbbcode_table.module, line 23 - xbbcode_table.module The module file, containing hook implementations.
Code
function _xbbcode_table_render($tag) {
$alignment = array(
'' => 'left',
'#' => 'right',
'!' => 'center',
);
if ($tag->option) {
// Look for an optional caption;header syntax.
preg_match('/^(?:(.*);)?(.*)$/', $tag->option, $match);
list($_, $caption, $headers) = $match;
}
else {
$caption = $tag
->attr('caption');
$headers = $tag
->attr('headers');
}
if ($headers) {
$headers = explode(',', $headers);
foreach ($headers as $i => $header) {
// !<name> is aligned right, #<name> is centered, otherwise aligned left.
preg_match('/^([#!]?)(.+)$/', $header, $match);
$headers[$i] = $match[2];
$align[$i] = $alignment[$match[1]];
}
}
else {
$headers = array();
}
$rows = explode("\n", trim($tag->content));
foreach ($rows as $row) {
$row = explode(',', $row);
if ($headers) {
foreach ($row as $i => $cell) {
$row[$i] = array(
'data' => $cell,
'style' => 'text-align:' . $align[$i],
);
}
}
$cells[] = $row;
}
// Strip linebreaks, in case this text passes through a linebreak converter.
return str_replace("\n", '', theme('table', array(
'header' => $headers,
'rows' => $cells,
'caption' => $caption,
)));
}