array('Cell 1', array('data' => 'Cell 2', 'colspan' => 2)), 'class' => 'funky'
* )
* );
* @endverbatim
*
* @param $attributes
* An array of HTML attributes to apply to the table tag.
* @param $caption
* A localized string to use for the
tag.
* @return
* An HTML string representing the table.
*/
function theme_table($header, $rows, $attributes = array(), $caption = NULL) {
$output = '\n";
if (isset($caption)) {
$output .= ''. $caption ."\n";
}
// Format the table header:
if (count($header)) {
// HTML requires that the thead tag has tr tags in it follwed by tbody
// tags. Using ternary operator to check and see if we have any rows.
$output .= (count($rows) ? ' ' : '
');
foreach ($header as $cell) {
$output .= theme_table_cell($cell, TRUE);
}
// Using ternary operator to close the tags based on whether or not there are rows
$output .= (count($rows) ? "
\n" : "\n");
}
else {
$ts = array();
}
// Format the table rows:
if (count($rows)) {
$output .= "\n";
$flip = array('even' => 'odd', 'odd' => 'even');
$class = 'even';
foreach ($rows as $number => $row) {
$attributes = array();
// Check if we're dealing with a simple or complex row
if (isset($row['data'])) {
foreach ($row as $key => $value) {
if ($key == 'data') {
$cells = $value;
}
else {
$attributes[$key] = $value;
}
}
}
else {
$cells = $row;
}
if (count($cells)) {
// Add odd/even class
$class = $flip[$class];
if (isset($attributes['class'])) {
$attributes['class'] .= ' '. $class;
}
else {
$attributes['class'] = $class;
}
// Build row
$output .= ' ';
$i = 0;
foreach ($cells as $cell) {
$output .= theme_table_cell($cell);
}
$output .= "
\n";
}
}
$output .= "\n";
}
$output .= "
\n";
return $output;
}
/**
* Format an attribute string to insert in a tag.
*
* @param $attributes
* An associative array of HTML attributes.
* @return
* An HTML string ready for insertion in a tag.
*/
function theme_attributes($attributes = array()) {
if (is_array($attributes)) {
$t = '';
foreach ($attributes as $key => $value) {
$t .= " $key=".'"'. check_plain($value) .'"';
}
return $t;
}
}
function theme_table_cell($cell, $header = FALSE) {
$attributes = '';
if (is_array($cell)) {
$data = isset($cell['data']) ? $cell['data'] : '';
$header |= isset($cell['header']);
unset($cell['data']);
unset($cell['header']);
$attributes = theme_attributes($cell);
}
else {
$data = $cell;
}
if ($header) {
$output = "$data | ";
}
else {
$output = "$data | ";
}
return $output;
}
function theme_image(){}
function theme_link(){}