filter.pages.inc 2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
<?php
// $Id$

/**
 * @file
 * User page callbacks for the filter module.
 */


/**
 * Menu callback; show a page with long filter tips.
 */
function filter_tips_long() {
  $format = arg(2);
  if ($format) {
    $output = theme('filter_tips', _filter_tips($format, TRUE), TRUE);
  }
  else {
    $output = theme('filter_tips', _filter_tips(-1, TRUE), TRUE);
  }
  return $output;
}


/**
26
 * Render HTML for a set of filter tips.
27
 *
28 29 30
 * @param $tips
 *   An array containing descriptions and a CSS id in the form of
 *   'module-name/filter-id' (only used when $long is TRUE) for each input
31
 *   filter in one or more text formats. Example:
32 33 34 35 36 37 38 39 40 41 42 43 44
 *   @code
 *     array(
 *       'Full HTML' => array(
 *         0 => array(
 *           'tip' => 'Web page addresses and e-mail addresses turn into links automatically.',
 *           'id' => 'filter/2',
 *         ),
 *       ),
 *     );
 *   @endcode
 * @param $long
 *   (optional) Whether the passed in filter tips contain extended explanations,
 *   i.e. intended to be output on the path 'filter/tips' (TRUE), or are in a
45
 *   short format, i.e. suitable to be displayed below a form element. Defaults
46 47 48
 *   to FALSE.
 *
 * @see _filter_tips()
49 50
 * @ingroup themeable
 */
51
function theme_filter_tips($tips, $long = FALSE) {
52 53 54 55
  $output = '';

  $multiple = count($tips) > 1;
  if ($multiple) {
56
    $output = t('Text formats') . ':';
57 58 59 60 61 62 63 64 65
  }

  if (count($tips)) {
    if ($multiple) {
      $output .= '<ul>';
    }
    foreach ($tips as $name => $tiplist) {
      if ($multiple) {
        $output .= '<li>';
66
        $output .= '<strong>' . $name . '</strong>:<br />';
67 68
      }

69 70 71
      if (count($tiplist) > 0) {
        $output .= '<ul class="tips">';
        foreach ($tiplist as $tip) {
72
          $output .= '<li' . ($long ? ' id="filter-' . str_replace("/", "-", $tip['id']) . '">' : '>') . $tip['tip'] . '</li>';
73 74
        }
        $output .= '</ul>';
75 76 77 78 79 80 81 82 83 84 85 86 87
      }

      if ($multiple) {
        $output .= '</li>';
      }
    }
    if ($multiple) {
      $output .= '</ul>';
    }
  }

  return $output;
}