diff options
author | Dries Buytaert <dries@buytaert.net> | 2002-12-29 12:03:08 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2002-12-29 12:03:08 +0000 |
commit | 14158fbc6b511965f0b2031d11c01b4bc0411c14 (patch) | |
tree | 7685c533c2253a9db00512fbdaecbc4391128655 /includes/common.inc | |
parent | be431bd983e531417fccc7d162d447543cd9c3f7 (diff) | |
download | brdo-14158fbc6b511965f0b2031d11c01b4bc0411c14.tar.gz brdo-14158fbc6b511965f0b2031d11c01b4bc0411c14.tar.bz2 |
- Added table rendering functions. As an example, I changed the node module
to take advantage of it.
Diffstat (limited to 'includes/common.inc')
-rw-r--r-- | includes/common.inc | 60 |
1 files changed, 60 insertions, 0 deletions
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 = "<th$attributes>$data</th>"; + } + else { + $output = "<td$attributes>$data</td>"; + } + + return $output; +} + +function table($header, $rows) { + + $output .= "<table>"; + + /* + ** Emit the table header: + */ + + $output .= " <tr>"; + foreach ($header as $cell) { + $output .= table_cell($cell, 1); + } + $output .= " </tr>"; + + /* + ** Emit the table rows: + */ + + foreach ($rows as $number => $row) { + if ($number % 2 == 1) { + $output .= " <tr class=\"light\">"; + } + else { + $output .= " <tr class=\"dark\">"; + } + + foreach ($row as $cell) { + $output .= table_cell($cell, 0); + } + $output .= " </tr>"; + } + + $output .= "</table>"; + + return $output; +} + /** * Format a single result entry of a search query: * |