You are here

function sms_valid_text_to_rules in SMS Framework 6

Same name and namespace in other branches
  1. 6.2 modules/sms_valid/sms_valid.module \sms_valid_text_to_rules()
  2. 7 modules/sms_valid/sms_valid.module \sms_valid_text_to_rules()

Distill rules text into a rules array

Parameters

$text: A text string containing rules for a ruleset.

Return value

An array of rules.

1 call to sms_valid_text_to_rules()
sms_valid_admin_ruleset_form_submit in modules/sms_valid/sms_valid.admin.inc

File

modules/sms_valid/sms_valid.module, line 348
Number validation feature module for Drupal SMS Framework.

Code

function sms_valid_text_to_rules($text) {
  $lines = explode("\n", $text);
  $rules = array();
  foreach ($lines as $line) {
    if (empty($line)) {
      continue;
    }

    // Capture any comments and then strip them
    preg_match('/\\#(.*)/', $line, $matches);
    $comment = trim($matches[1]);
    $line = trim(preg_replace('/\\#.*/', '', $line));

    // Check if we are allowing or denying, deny by default
    $allow = preg_match('/\\+/', $line) ? TRUE : FALSE;

    // Erase non-digit chars to get the prefix
    $rule_prefix = trim(preg_replace('/[\\D]/', '', $line));

    // Add to rules array
    $rules[$rule_prefix] = array(
      'allow' => $allow,
      'comment' => $comment,
    );
  }
  return $rules;
}