Index: table_altrow.info =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/table_altrow/table_altrow.info,v retrieving revision 1.1.2.2.2.1 diff -u -r1.1.2.2.2.1 table_altrow.info --- table_altrow.info 17 Feb 2008 19:08:24 -0000 1.1.2.2.2.1 +++ table_altrow.info 9 Sep 2009 02:20:24 -0000 @@ -1,4 +1,4 @@ ; $Id: table_altrow.info,v 1.1.2.2.2.1 2008/02/17 19:08:24 deviantintegral Exp $ name = Table Alternate Rows description = Automatically adds even/odd classes to tables. -core = 6.x \ No newline at end of file +core = 6.x Index: table_altrow.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/table_altrow/table_altrow.module,v retrieving revision 1.1.2.2 diff -u -r1.1.2.2 table_altrow.module --- table_altrow.module 17 Feb 2008 18:59:11 -0000 1.1.2.2 +++ table_altrow.module 9 Sep 2009 02:20:24 -0000 @@ -5,6 +5,7 @@ * Insert even and odd classes for tables via input filters to allow for proper * zebra-style striping. */ + /** * Implementation of hook_filter_tips */ @@ -64,29 +65,46 @@ $count = 1; // While the tbody is still open while(preg_match('!()|()!', $text, $matches, PREG_OFFSET_CAPTURE, $offset)) { - // +1 so we don't match the same string + // +1 so we don't match the same string. $offset = $matches[0][1] + 1; - + + if (!empty($classes) && isset($old_tag) && isset($old_attributes)) { + if ($matches[0][0] == '') { + $classes[] = 'last'; + } + $new_tag = ''; + drupal_set_message($old_tag); + drupal_set_message($new_tag); + $text = str_replace_count($old_tag, $new_tag, $text, $offset - 1, 1); + unset($classes); + } + + $old_tag = $matches[0][0]; + $old_attributes = $matches[2][0]; + // Don't process tr's until we find a tbody. - if($matches[0][0] == '') { + if($old_tag == '') { break; } - // Don't replace existing classes. Perhaps this should append a class instead? - if(!strstr($matches[2][0], 'class=')) { - if(($count % 2) == 0) { - $new_tag = ''; - $text = str_replace_count($matches[0][0], $new_tag, $text, $offset - 1, 1); - } - else { - $new_tag = ''; - $text = str_replace_count($matches[0][0], $new_tag, $text, $offset - 1, 1); - } + $classes = array(); + if (preg_match('!class="([^"]*)"!', $old_attributes, $old_classes)) { + $classes = explode(" ", $old_classes); + } + if ($count == 1) { + $classes[] = 'first'; + } + if(($count % 2) == 0) { + $classes[] = 'even'; + } + else { + $classes[] = 'odd'; } $count++; } } + drupal_set_message('
' . $text . '
'); return $text; } break; @@ -117,4 +135,4 @@ $rpl_count++; } return $haystack; -} \ No newline at end of file +}