function widgets_field_scan in Widgets 7
2 calls to widgets_field_scan()
- widgets_replace_fields in ./
widgets.module - widgets_template_auto_form in ./
widgets.admin.inc - Form structure for the template auto form.
File
- ./
widgets.module, line 818 - Exposes global functionality for creating widget sets.
Code
function widgets_field_scan($text, $return_matches = FALSE) {
// Matches tokens with the following pattern: [$type:$name]
// $type and $name may not contain [ ] or whitespace characters.
// $type may not contain : characters, but $name may.
$pattern = '/
\\[\\? # [ - pattern start
([^\\s\\?=]*) # match $type not containing whitespace ? or =
= # = - separator
([^\\]]*) # match $name not containing or ? (TODO white space was removed, make sure it keeps working)
\\?\\] # ] - pattern end
/x';
$pattern = '/
\\[\\? # [ - pattern start
([^\\s\\?=]*) # match $type not containing whitespace ? or =
= # = - separator
(((?!\\?\\]).)*) # dont match ?]
\\?\\] # ] - pattern end
/x';
preg_match_all($pattern, $text, $matches);
if ($return_matches) {
return $matches;
}
if (strpos($text, 'profile_url=http://www.linkedin.com') !== FALSE) {
}
$originals = $matches[0];
$fields = $matches[1];
$defaults = $matches[2];
// Iterate through the matches, building an associative array containing
// $tokens grouped by $types, pointing to the version of the token found in
// the source text. For example, $results['node']['title'] = '[node:title]';
$pattern = '/
([^\\?]*) # match $type not containing whitespace ? or
\\{ # { start of var
([^\\?]*) # match $name not containing whitespace or ?
\\}
([^\\?]*)
/x';
$results = array();
for ($i = 0; $i < count($fields); $i++) {
if (preg_match_all($pattern, $defaults[$i], $matches)) {
$results[$fields[$i]] = array(
'pre' => $matches[1][0],
'default' => $matches[2][0],
'post' => $matches[3][0],
'original' => $originals[$i],
);
}
else {
$results[$fields[$i]] = array(
'default' => $defaults[$i],
'original' => $originals[$i],
);
}
}
return $results;
}