When saving a node, whilst using IE7 with Tiny MCE, the html tags are saved as capitals. This means that Table Alternate Rows doesn't find the expected tbody tag.

Could the preg_match look for lower and uppercase versions of tbody and tr, as this would solve issues with IE7?

As time was short earlier today, I came up with a quick fix that worked just by using another while loop below the first while loop... I'm sure with more time the preg_match could have been changed to look for tbody and TBODY.

//IE hack
while(preg_match('!(<TBODY ?.*>)!', $text, $matches, PREG_OFFSET_CAPTURE, $offset)) {
	$offset = $matches[0][1];
	$count = 1;
	// While the tbody is still open
	while(preg_match('!(<TR( ?.*)>)|(</TBODY>)!', $text, $matches, PREG_OFFSET_CAPTURE, $offset)) {
		// +1 so we don't match the same string
		$offset = $matches[0][1] + 1;
		// Don't process tr's until we find a tbody.
		if($matches[0][0] == '</TBODY>') {
			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 = '<tr class="even"' . $matches[2][0] . '>';
			  $text = str_replace_count($matches[0][0], $new_tag, $text, $offset - 1, 1);
			}
			else {
			  $new_tag = '<tr class="odd"' . $matches[2][0] . '>';
			  $text = str_replace_count($matches[0][0], $new_tag, $text, $offset - 1, 1);
			}
		}
		$count++;
	}
}

Comments

markhalliwell’s picture

Actually this is a quite simple change, by throwing a case insensitive flag (i) after the regular expression, you can search for either, thus:

  preg_match('!(<TBODY ?.*>)!', $text, $matches, PREG_OFFSET_CAPTURE, $offset)

Should be (notice the little i after the last !):

  preg_match('!(<tbody ?.*>)!i', $text, $matches, PREG_OFFSET_CAPTURE, $offset)
jefflogan’s picture

Excellent thanks Mark. I've just started getting to grips with regular expressions, and realise how useful they are!

deviantintegral’s picture

Version: 6.x-1.1 » 6.x-1.x-dev
Status: Active » Fixed

This change is all ready in the 7.x version, so I've committed the regex modifier in 26cb576. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.