You are here

function _mail_logger_split_address_string in Mail Logger 7

Helper function for splitting long address strings for display.

1 call to _mail_logger_split_address_string()
theme_mail_logger_read_mail in ./mail_logger.theme.inc
Theme function for theme('mail_logger_read_mail').

File

./mail_logger.theme.inc, line 66
Theming functions for the Mail Logger module.

Code

function _mail_logger_split_address_string($string, $max = 70, $num_cols = 3) {
  $len = drupal_strlen($string);

  // If empty, return a blank.
  if ($len == 0) {
    return " ";
  }

  // If it's less than the max length, return the whole string.
  if ($len <= $max) {
    return check_plain($string);
  }

  // It's longer than we want for a single string, so we have to break it up.
  // We assume that the list items are separated by commas.
  $sep = ',';
  if (strpos($string, ',') === FALSE) {
    $sep = ';';
  }
  $list = explode($sep, $string);

  // Remove special characters in every address.
  $list = array_map('check_plain', $list);
  $output = '<table></tr>';
  $col_len = ceil(count($list) / $num_cols);
  for ($i = 0; $i < $num_cols; ++$i) {
    $part = array_slice($list, $col_len * $i, $col_len);
    $output .= '<td valign = "top">' . implode('<br />', $part) . '</td>';
  }
  $output .= '</tr></table>';
  return $output;
}