You are here

xbbcode_table.module in Extensible BBCode 6

File

xbbcode_table/xbbcode_table.module
View source
<?php

function xbbcode_table_render($option, $content) {
  $content = trim($content);
  $rows = explode("\n", $content);
  if ($option) {
    $headers = explode(",", $option);
    foreach ($headers as $i => $header) {
      if (preg_match('/^([#!])(.+)$/', $header, $match)) {
        $headers[$i] = $match[2];
        $align[$i] = $match[1] == '#' ? 'right' : 'center';
      }
      else {
        $align[$i] = 'left';
      }
    }
  }
  else {
    $headers = array();
  }
  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;
  }
  $html = theme('table', $headers, $cells);
  $html = str_replace("\n", "", $html);

  // strip linebreaks
  return $html;
}
function xbbcode_table_xbbcode($op = 'list', $delta = '', $tag = NULL) {
  switch ($op) {
    case 'list':
      return array(
        'table',
      );
    case 'info':
      return array(
        'dynamic' => TRUE,
      );
    case 'render':
      return xbbcode_table_render($tag->option, $tag->content);
  }
}