<?php
// $Id$

function example_flexifilter_conditions() {
  $conditions = array();
  $conditions['example_text_all_uppercase'] = array(
    'label' => t('Text is all uppercase'),
    'description' => t('TRUE if all of the text is uppercase'),
    'callback' => 'example_condition_isupper',
    'group' => t('Text'),
  );
  return $conditions;
}

function example_condition_isupper($op, $settings, $text) {
  switch($op) {
    case 'settings':
      $form = array();
      return $form;

    case 'prepare':
    case 'process':
      return preg_match("/[^A-Z \n\t]/", $text) == 0;

    default:
      return $text;
  }
}

function example_flexifilter_components() {
  $components = array();
  $components['example_toupper'] = array(
    'label' => t('To Uppercase'),
    'callback' => 'example_component_toupper',
    'group' => t('Text: Simple'),
    'step' => 'either',
  );
  return $components;
}

function example_component_toupper($op, $settings, $text) {
  switch($op) {
    case 'settings':
      $form = array();
      $form['case'] = array(
        '#type' => 'select',
        '#title' => t('Case transformation'),
        '#options' => array(
          'upper' => t('To Uppercase'),
          'lower' => t('To Lowercase'),
        ),
        '#default_value' => isset($settings['case']) ? $settings['case'] : 'upper',
      );
      return $form;

    case 'prepare':
    case 'process':
      if ($settings['case'] == 'upper') {
        return strtoupper($text);
      }
      else {
        return strtolower($text);
      }

    default:
      return $text;
  }
}
