function sms_valid_text_to_rules in SMS Framework 7
Same name and namespace in other branches
- 6.2 modules/sms_valid/sms_valid.module \sms_valid_text_to_rules()
- 6 modules/sms_valid/sms_valid.module \sms_valid_text_to_rules()
Distills rules text into a rules array.
Parameters
string $text: A text string containing rules for a ruleset.
Return value
array An array of rules.
4 calls to sms_valid_text_to_rules()
- SmsValidWebTest::testCrudSmsValidRulesets in modules/
sms_valid/ sms_valid.test - Tests the creation, update and deletion of sms_valid rulesets.
- SmsValidWebTest::testSmsValidFunctions in modules/
sms_valid/ sms_valid.test - Tests the internal sms_valid functions.
- SmsValidWebTest::testSmsValidSettingsForm in modules/
sms_valid/ sms_valid.test - Tests the application of the sms_valid settings form and settings.
- sms_valid_admin_ruleset_form_submit in modules/
sms_valid/ sms_valid.admin.inc - Submit handler for the sms_valid_admin_ruleset_form().
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);
if (isset($matches[1])) {
$comment = trim($matches[1]);
}
else {
$comment = '';
}
$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;
}