Fix for Flexifilter API Lesson #1.5

  1. <?php
  2. // $Id$
  3.  
  4. function example_flexifilter_conditions() {
  5.   $conditions = array();
  6.   $conditions['example_text_all_uppercase'] = array(
  7.     'label' => t('Text is all uppercase'),
  8.     'description' => t('TRUE if all of the text is uppercase'),
  9.     'callback' => 'example_condition_isupper',
  10.     'group' => t('Text'),
  11.   );
  12.   return $conditions;
  13. }
  14.  
  15. function example_condition_isupper($op, $settings, $text) {
  16.   switch($op) {
  17.     case 'settings':
  18.       $form = array();
  19.       return $form;
  20.  
  21.     case 'prepare':
  22.     case 'process':
  23.       return preg_match("/[^A-Z \n\t]/", $text) == 0;
  24.  
  25.     default:
  26.       return $text;
  27.   }
  28. }
  29.  
  30. function example_flexifilter_components() {
  31.   $components = array();
  32.   $components['example_toupper'] = array(
  33.     'label' => t('To Uppercase'),
  34.     'callback' => 'example_component_toupper',
  35.     'group' => t('Text: Simple'),
  36.     'step' => 'either',
  37.   );
  38.   return $components;
  39. }
  40.  
  41. function example_component_toupper($op, $settings, $text) {
  42.   switch($op) {
  43.     case 'settings':
  44.       $form = array();
  45.       $form['case'] = array(
  46.         '#type' => 'select',
  47.         '#title' => t('Case transformation'),
  48.         '#options' => array(
  49.           'upper' => t('To Uppercase'),
  50.           'lower' => t('To Lowercase'),
  51.         ),
  52.         '#default_value' => isset($settings['case']) ? $settings['case'] : 'upper',
  53.       );
  54.       return $form;
  55.  
  56.     case 'prepare':
  57.     case 'process':
  58.       if ($settings['case'] == 'upper') {
  59.         return strtoupper($text);
  60.       }
  61.       else {
  62.         return strtolower($text);
  63.       }
  64.  
  65.     default:
  66.       return $text;
  67.   }
  68. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.