You are here

function _crumbs_build_default_text in Crumbs, the Breadcrumbs suite 6.2

Same name and namespace in other branches
  1. 7 admin/crumbs.admin.inc \_crumbs_build_default_text()
1 call to _crumbs_build_default_text()
_crumbs_get_default_text in ./crumbs.admin.inc

File

./crumbs.admin.inc, line 51

Code

function _crumbs_build_default_text(array $available_keys, array $keys_by_plugin, array $weights, array $disabled_keys) {
  $key_lengths = array();
  foreach ($available_keys as $key => $title) {
    $key_lengths[] = strlen($key);
  }
  $ideal_length = _crumbs_admin_find_ideal_length($key_lengths);
  foreach ($available_keys as $key => $title) {
    $string = $key;
    if (is_string($title)) {
      if (strlen($string) < $ideal_length) {
        $string .= str_repeat(' ', $ideal_length - strlen($string));
      }
      $string .= ' - ' . $title;
    }
    $available_keys[$key] = $string;
  }
  $lines = array(
    'inherit' => $available_keys,
    'disabled_by_default' => array(),
    'enabled' => array(),
    'disabled' => array(),
  );
  foreach ($weights as $key => $weight) {
    $section = $weight === FALSE ? 'disabled' : 'enabled';
    $string = $key;
    if (isset($available_keys[$key])) {
      $string = $available_keys[$key];
    }
    else {
      if ($key !== '*') {

        // an orphan setting.
        if (strlen($string) < $ideal_length) {
          $string .= str_repeat(' ', $ideal_length - strlen($string));
        }
        $string .= '   (orphan rule)';
      }
    }
    $lines[$section][$key] = $string;
    unset($lines['inherit'][$key]);
  }
  foreach ($disabled_keys as $key => $disabled) {
    if (isset($lines['inherit'][$key])) {
      $lines['disabled_by_default'][$key] = $lines['inherit'][$key];
      unset($lines['inherit'][$key]);
    }
  }
  foreach ($keys_by_plugin as $plugin_key => $keys_for_this_plugin) {
    $lines['inherit'][$plugin_key . ':NEWLINE:'] = "";
  }
  ksort($lines['inherit']);
  foreach ($lines['inherit'] as $key => $line) {
    if ($prev === '' && $line === '') {
      unset($lines['inherit'][$key]);
    }
    $prev = $line;
  }
  return "\n\n" . implode("\n", $lines['enabled']) . "\n\n\n---- disabled ----\n\n" . implode("\n", $lines['disabled']) . "\n\n\n---- disabled by default ----\n\n" . implode("\n", $lines['disabled_by_default']) . "\n\n\n---- inherit ----\n\n" . implode("\n", $lines['inherit']) . "\n\n";
}