From 14158fbc6b511965f0b2031d11c01b4bc0411c14 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Sun, 29 Dec 2002 12:03:08 +0000 Subject: - Added table rendering functions. As an example, I changed the node module to take advantage of it. --- includes/common.inc | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'includes/common.inc') diff --git a/includes/common.inc b/includes/common.inc index 4812e3e52..d3a909adf 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -182,6 +182,66 @@ function variable_del($name) { unset($conf[$name]); } +function table_cell($cell, $header = 0) { + if (is_array($cell)) { + $data = $cell["data"]; + foreach ($cell as $key => $value) { + if ($key != "data") { + $attributes .= " $key=\"$value\""; + } + } + } + else { + $data = $cell; + } + + if ($header) { + $output = "$data"; + } + else { + $output = "$data"; + } + + return $output; +} + +function table($header, $rows) { + + $output .= ""; + + /* + ** Emit the table header: + */ + + $output .= " "; + foreach ($header as $cell) { + $output .= table_cell($cell, 1); + } + $output .= " "; + + /* + ** Emit the table rows: + */ + + foreach ($rows as $number => $row) { + if ($number % 2 == 1) { + $output .= " "; + } + else { + $output .= " "; + } + + foreach ($row as $cell) { + $output .= table_cell($cell, 0); + } + $output .= " "; + } + + $output .= "
"; + + return $output; +} + /** * Format a single result entry of a search query: * -- cgit v1.2.3