/** * Implements hook_preprocess_forum_topic_list */ function carbon_preprocess_forum_topic_list(&$vars) { // Recreate the topic list header $list = array( array('data' => t('Topic'), 'field' => 'f.title'), array('data' => t('Replies'), 'field' => 'f.comment_count'), array('data' => t('Created'), 'field' => 't.created'), array('data' => t('Last reply'), 'field' => 'f.last_comment_timestamp'), ); $ts = tablesort_init($list); $header = ''; foreach ($list as $cell) { $cell = tablesort_header($cell, $list, $ts); $header .= _theme_table_cell($cell, TRUE); } $vars['header'] = $header; }
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 if (empty($row['no_striping'])) { $class = $flip[$class]; $attributes['class'][] = $class; } // Build row $output .= ' <tr' . drupal_attributes($attributes) . '>'; $i = 0; foreach ($cells as $cell) { $cell = tablesort_cell($cell, $header, $ts, $i++); $output .= _theme_table_cell($cell); } $output .= " </tr>\n"; } } $output .= "</tbody>\n"; } $output .= "</table>\n"; print $output;
function phptemplate_table($header, $rows, $attributes = array(), $caption = NULL) { $output = '<div class="tablewrapper">'; $output .= '<table' . drupal_attributes($attributes) . " class=\"tableclass\">\n"; if (isset($caption)) { $output .= '<caption>' . $caption . "</caption>\n"; } // Format the table header: if (count($header)) { $ts = tablesort_init($header); $output .= ' <thead><tr>'; foreach ($header as $cell) { $cell = tablesort_header($cell, $header, $ts); $output .= _theme_table_cell($cell, TRUE); } $output .= " </tr></thead>\n"; } // Format the table rows: $output .= "<tbody>\n"; if (count($rows)) { $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; } // Add odd/even class $class = $flip[$class]; if (isset($attributes['class'])) { $attributes['class'] .= ' ' . $class; } else { $attributes['class'] = $class; } // Build row $output .= ' <tr' . drupal_attributes($attributes) . '>'; $i = 0; foreach ($cells as $cell) { $cell = tablesort_cell($cell, $header, $ts, $i++); $output .= _theme_table_cell($cell); } $output .= " </tr>\n"; } } $output .= "</tbody></table>\n"; $output .= "</div>\n"; return $output; }
function mothership_table($header, $rows, $attributes = array(), $caption = NULL) { // Add sticky headers, if applicable. if (count($header)) { drupal_add_js('misc/tableheader.js'); // Add 'sticky-enabled' class to the table to identify it for JS. // This is needed to target tables constructed by this function. $attributes['class'] = empty($attributes['class']) ? 'sticky-enabled' : $attributes['class'] . ' sticky-enabled'; } $output = '<table' . drupal_attributes($attributes) . ">\n"; if (isset($caption)) { $output .= '<caption>' . $caption . "</caption>\n"; } // Format the table header: if (count($header)) { $ts = tablesort_init($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) ? ' <thead><tr>' : ' <tr>'; foreach ($header as $cell) { $cell = tablesort_header($cell, $header, $ts); $output .= _theme_table_cell($cell, TRUE); } // Using ternary operator to close the tags based on whether or not there are rows $output .= count($rows) ? " </tr></thead>\n" : "</tr>\n"; } else { $ts = array(); } // Format the table rows: if (count($rows)) { $output .= "<tbody>\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 .= ' <tr' . drupal_attributes($attributes) . '>'; $i = 0; foreach ($cells as $cell) { $cell = tablesort_cell($cell, $header, $ts, $i++); $output .= _theme_table_cell($cell); } $output .= " </tr>\n"; } } $output .= "</tbody>\n"; } $output .= "</table>\n"; return $output; }
/** * Implements theme_table(). */ function ec_resp_table($variables) { $header = $variables['header']; $rows = $variables['rows']; $attributes = $variables['attributes']; $caption = $variables['caption']; $colgroups = $variables['colgroups']; $sticky = $variables['sticky']; $empty = $variables['empty']; // Add sticky headers, if applicable. if (count($header) && $sticky) { drupal_add_js('misc/tableheader.js'); // Add 'sticky-enabled' class to the table to identify it for JS. // This is needed to target tables constructed by this function. $attributes['class'][] = 'sticky-enabled table table-striped'; } $output = '<table' . drupal_attributes($attributes) . ">\n"; if (isset($caption)) { $output .= '<caption>' . $caption . "</caption>\n"; } // Format the table columns: if (count($colgroups)) { foreach ($colgroups as $number => $colgroup) { $attributes = array(); // Check if we're dealing with a simple or complex column. if (isset($colgroup['data'])) { foreach ($colgroup as $key => $value) { if ($key == 'data') { $cols = $value; } else { $attributes[$key] = $value; } } } else { $cols = $colgroup; } // Build colgroup. if (is_array($cols) && count($cols)) { $output .= ' <colgroup' . drupal_attributes($attributes) . '>'; $i = 0; foreach ($cols as $col) { $output .= ' <col' . drupal_attributes($col) . ' />'; } $output .= " </colgroup>\n"; } else { $output .= ' <colgroup' . drupal_attributes($attributes) . " />\n"; } } } // Add the 'empty' row message if available. if (!count($rows) && $empty) { $header_count = 0; foreach ($header as $header_cell) { if (is_array($header_cell)) { $header_count += isset($header_cell['colspan']) ? $header_cell['colspan'] : 1; } else { $header_count++; } } $rows[] = array(array('data' => $empty, 'colspan' => $header_count, 'class' => array('empty', 'message'))); } // Format the table header: if (count($header)) { $ts = tablesort_init($header); // HTML requires that the thead tag has tr tags in it followed by tbody // tags. Using ternary operator to check and see if we have any rows. $output .= count($rows) ? ' <thead><tr>' : ' <tr>'; foreach ($header as $cell) { $cell = tablesort_header($cell, $header, $ts); $output .= _theme_table_cell($cell, TRUE); } // Using ternary operator to close the tags based on whether // or not there are rows. $output .= count($rows) ? " </tr></thead>\n" : "</tr>\n"; } else { $ts = array(); } // Format the table rows: if (count($rows)) { $output .= "<tbody>\n"; $flip = array('even' => 'odd', 'odd' => 'even'); $class = 'even'; foreach ($rows as $number => $row) { // 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. if (empty($row['no_striping'])) { $class = $flip[$class]; $attributes['class'][] = $class; } // Build row. $output .= ' <tr' . drupal_attributes($attributes) . '>'; $i = 0; foreach ($cells as $cell) { $cell = tablesort_cell($cell, $header, $ts, $i++); $output .= _theme_table_cell($cell); } $output .= " </tr>\n"; } } $output .= "</tbody>\n"; } $output .= "</table>\n"; return $output; }
} ?> </tr> <?php } ?> </thead> <?php } ?> <tbody> <?php foreach ($rows as $row_count => $row) { ?> <tr <?php if ($row_classes[$row_count]) { print 'class="' . implode(' ', $row_classes[$row_count]) . '"'; } ?> > <?php foreach ($row as $cell) { print _theme_table_cell($cell); } ?> </tr> <?php } ?> </tbody> </table>
/** * @Implement of hook_template_framework_x() */ function bootstrap_template_framework_table(array $header, $rows = array(), array $attributes = array(), $caption = NULL, $sub_header = NULL) { if (!empty($attributes['class'])) { $attributes['class'] .= ' table table-bordered table-condensed'; } else { $attributes['class'] = 'table table-bordered table-condensed'; } $output = '<table' . dd_attributes($attributes) . ">\n"; if (isset($caption)) { $output .= '<caption>' . $caption . "</caption>\n"; } if (!empty($header)) { $ts = table_init($header); if (!empty($rows)) { $output .= '<thead>'; } $output .= '<tr>'; foreach ($header as $cell) { $cell = table_header($cell, $header, $ts); $output .= _theme_table_cell($cell, true); } $output .= '</tr>'; if (!empty($sub_header)) { foreach ($sub_header as $row) { $attributes = array(); if (isset($row['data'])) { foreach ($row as $key => $value) { if ($key == 'data') { $cells = $value; } else { $attributes[$key] = $value; } } } else { $cells = $row; } $i = 0; $output .= '<tr' . dd_attributes($attributes) . '>'; foreach ($cells as $cell) { $cell = table_cell($cell, $header, $ts, $i++); $output .= _theme_table_cell($cell, true); } $output .= '</tr>'; } } if (!empty($rows)) { $output .= '</thead>'; } } else { $ts = array(); } if (!empty($rows)) { $output .= "<tbody>\n"; $flip = array('even' => 'odd', 'odd' => 'even'); $class = 'even'; foreach ($rows as $number => $row) { $attributes = array(); if (isset($row['data'])) { foreach ($row as $key => $value) { if ($key == 'data') { $cells = $value; } else { $attributes[$key] = $value; } } } else { $cells = $row; } if (count($cells)) { $class = $flip[$class]; if (isset($attributes['class'])) { $attributes['class'] .= ' ' . $class; } else { $attributes['class'] = $class; } $output .= ' <tr' . dd_attributes($attributes) . '>'; $i = 0; foreach ($cells as $cell) { $cell = table_cell($cell, $header, $ts, $i++); $output .= _theme_table_cell($cell); } $output .= " </tr>\n"; } } $output .= "</tbody>\n"; } $output .= "</table>\n"; return $output; }
/** * Overrides table theme function with support for colgroups * based on Drupal 7 theme function. */ function dynamo_table($header, $rows, $attributes = array(), $caption = NULL) { // Get colgroups out if attributes $colgroups = $attributes['colgroups']; if (!empty($attributes['colgroups'])) { unset($attributes['colgroups']); } // Add sticky headers, if applicable. if (count($header)) { drupal_add_js('misc/tableheader.js'); // Add 'sticky-enabled' class to the table to identify it for JS. // This is needed to target tables constructed by this function. array_push($attributes['class'], 'sticky-enabled'); } $output = '<table' . drupal_attributes($attributes) . ">\n"; if (isset($caption)) { $output .= '<caption>' . $caption . "</caption>\n"; } // Format the table columns: if (count($colgroups)) { foreach ($colgroups as $number => $colgroup) { $attributes = array(); // Check if we're dealing with a simple or complex column if (isset($colgroup['data'])) { foreach ($colgroup as $key => $value) { if ($key == 'data') { $cols = $value; } else { $attributes[$key] = $value; } } } else { $cols = $colgroup; } // Build colgroup if (is_array($cols) && count($cols)) { $output .= ' <colgroup' . drupal_attributes($attributes) . '>'; $i = 0; foreach ($cols as $col) { $output .= ' <col' . drupal_attributes($col) . ' />'; } $output .= " </colgroup>\n"; } else { $output .= ' <colgroup' . drupal_attributes($attributes) . " />\n"; } } } // Format the table header: if (count($header)) { $ts = tablesort_init($header); // HTML requires that the thead tag has tr tags in it followed by tbody // tags. Using ternary operator to check and see if we have any rows. $output .= count($rows) ? ' <thead><tr>' : ' <tr>'; foreach ($header as $cell) { $cell = tablesort_header($cell, $header, $ts); $output .= _theme_table_cell($cell, TRUE); } // Using ternary operator to close the tags based on whether or not there are rows $output .= count($rows) ? " </tr></thead>\n" : "</tr>\n"; } else { $ts = array(); } // Format the table rows: if (count($rows)) { $output .= "<tbody>\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]; // TODO: This code looks broken. I've added the is_array check // to prevent errors, but I don't know if it'll ever be true. // mikl, 2010-05-24 if (is_array($attributes['class'])) { array_push($attributes['class'], $class); } // Build row $output .= ' <tr' . drupal_attributes($attributes) . '>'; $i = 0; foreach ($cells as $cell) { $cell = tablesort_cell($cell, $header, $ts, $i++); $output .= _theme_table_cell($cell); } $output .= " </tr>\n"; } } $output .= "</tbody>\n"; } $output .= "</table>\n"; return $output; }
/** * Overrides theme_table(). */ function badm_table($variables) { $header = $variables['header']; $rows = $variables['rows']; $attributes = $variables['attributes']; $caption = $variables['caption']; $colgroups = $variables['colgroups']; $empty = $variables['empty']; $attributes['class'][] = 'table'; $attributes['class'][] = 'table-striped'; $output = '<table' . drupal_attributes($attributes) . ">\n"; if (isset($caption)) { $output .= '<caption>' . $caption . "</caption>\n"; } // Format the table columns: if (count($colgroups)) { foreach ($colgroups as $colgroup) { $attributes = array(); // Check if we're dealing with a simple or complex column if (isset($colgroup['data'])) { foreach ($colgroup as $key => $value) { if ($key == 'data') { $cols = $value; } else { $attributes[$key] = $value; } } } else { $cols = $colgroup; } // Build colgroup if (is_array($cols) && count($cols)) { $output .= ' <colgroup' . drupal_attributes($attributes) . '>'; $i = 0; foreach ($cols as $col) { $output .= ' <col' . drupal_attributes($col) . ' />'; } $output .= " </colgroup>\n"; } else { $output .= ' <colgroup' . drupal_attributes($attributes) . " />\n"; } } } // Add the 'empty' row message if available. if (!count($rows) && $empty) { $header_count = 0; foreach ($header as $header_cell) { if (is_array($header_cell)) { $header_count += isset($header_cell['colspan']) ? $header_cell['colspan'] : 1; } else { $header_count++; } } $rows[] = array(array('data' => $empty, 'colspan' => $header_count, 'class' => array('empty', 'message'))); } // Format the table header: if (count($header)) { $ts = tablesort_init($header); // HTML requires that the thead tag has tr tags in it followed by tbody // tags. Using ternary operator to check and see if we have any rows. $output .= count($rows) ? ' <thead><tr>' : ' <tr>'; foreach ($header as $cell) { $cell = tablesort_header($cell, $header, $ts); $output .= _theme_table_cell($cell, TRUE); } // Using ternary operator to close the tags based on whether or not there are rows $output .= count($rows) ? " </tr></thead>\n" : "</tr>\n"; } else { $ts = array(); } // Format the table rows: if (count($rows)) { $output .= "<tbody>\n"; foreach ($rows as $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)) { // Build row $output .= ' <tr' . drupal_attributes($attributes) . '>'; $i = 0; foreach ($cells as $cell) { $cell = tablesort_cell($cell, $header, $ts, $i++); $output .= _theme_table_cell($cell); } $output .= " </tr>\n"; } } $output .= "</tbody>\n"; } $output .= "</table>\n"; return $output; }
unset($attributes['no_striping']); } else { $cells = $row; $attributes = array(); $no_striping = FALSE; } if (count($cells)) { // Add odd/even class if (!$no_striping) { $class = $flip[$class]; $attributes['class'][] = $class; } // Build row $output .= ' <tr' . drupal_attributes($attributes) . '>'; $i = 0; foreach ($cells as $cell) { if (isset($cell['class'])) { if (is_array($cell['class']) && in_array('checkbox', $cell['class']) || $cell['class'] == 'checkbox') { $cell['class'] = array('checkboxes'); } } $cell = tablesort_cell($cell, $header, $ts, $i++); $output .= _theme_table_cell($cell, $header = FALSE); } $output .= " </tr>\n"; } } $output .= "</tbody>\n"; } $output .= "</table>\n"; print $output;