function scanner_form in Search and Replace Scanner 7
Same name and namespace in other branches
- 5.2 scanner.module \scanner_form()
- 6 scanner.module \scanner_form()
Form constructor for the search and replace form.
See also
1 string reference to 'scanner_form'
- scanner_view in ./
scanner.module - Menu callback; presents the scan form and results.
File
- ./
scanner.module, line 222 - Search and Replace Scanner - works on all nodes text content.
Code
function scanner_form($form, &$form_state) {
$form = array();
if (isset($_SESSION['scanner_search'])) {
$search = $_SESSION['scanner_search'];
}
else {
$search = NULL;
}
if (isset($_SESSION['scanner_replace'])) {
$replace = $_SESSION['scanner_replace'];
}
else {
$replace = NULL;
}
if (isset($_SESSION['scanner_preceded'])) {
$preceded = $_SESSION['scanner_preceded'];
}
else {
$preceded = NULL;
}
if (isset($_SESSION['scanner_followed'])) {
$followed = $_SESSION['scanner_followed'];
}
else {
$followed = NULL;
}
$mode = isset($_SESSION['scanner_mode']) ? $_SESSION['scanner_mode'] : variable_get('scanner_mode', 0);
$wholeword = isset($_SESSION['scanner_wholeword']) ? $_SESSION['scanner_wholeword'] : variable_get('scanner_wholeword', 0);
$regex = isset($_SESSION['scanner_regex']) ? $_SESSION['scanner_regex'] : variable_get('scanner_regex', 0);
$published = isset($_SESSION['scanner_published']) ? $_SESSION['scanner_published'] : variable_get('scanner_published', 1);
$pathauto = isset($_SESSION['scanner_pathauto']) ? $_SESSION['scanner_pathauto'] : variable_get('scanner_pathauto', 1);
if (isset($_SESSION['scanner_terms'])) {
$terms = $_SESSION['scanner_terms'];
}
else {
$terms = NULL;
}
$form['settings_link'] = array(
'#markup' => t('The list of fields which will be searched and other options can be controlled from the !link.', array(
'!link' => l('settings page', 'admin/config/content/scanner'),
)),
'#prefix' => '<p>',
'#suffix' => '</p>',
'#access' => user_access('administer scanner settings'),
);
$form['search'] = array(
'#type' => 'textfield',
'#default_value' => $search,
'#title' => t('Step 1: Search for'),
'#maxlength' => 256,
);
$form['submit_search'] = array(
'#type' => 'submit',
'#value' => t('Search'),
);
$form['replace'] = array(
'#type' => 'textfield',
'#default_value' => $replace,
'#title' => t('Step 2: Replace with'),
'#maxlength' => 256,
'#access' => user_access('perform search and replace') ? TRUE : FALSE,
);
$form['submit_replace'] = array(
'#type' => 'submit',
'#value' => t('Replace'),
'#access' => user_access('perform search and replace') ? TRUE : FALSE,
);
$form['options'] = array(
'#type' => 'fieldset',
'#title' => t('Search Options'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['options']['surrounding'] = array(
'#type' => 'fieldset',
'#title' => t('Surrounding Text'),
'#collapsible' => FALSE,
'#description' => t('You can limit matches by providing the text that should appear immediately before or after the search text. Remember to account for spaces. Note: Case sensitivity and regular expression options will all apply here, too. Whole word is not recommended.'),
);
$form['options']['surrounding']['preceded'] = array(
'#type' => 'textfield',
'#title' => t('Preceded by'),
'#default_value' => $preceded,
'#maxlength' => 256,
);
$form['options']['surrounding']['followed'] = array(
'#type' => 'textfield',
'#title' => t('Followed by'),
'#default_value' => $followed,
'#maxlength' => 256,
);
$form['options']['mode'] = array(
'#type' => 'checkbox',
'#title' => t('Case sensitive search'),
'#default_value' => $mode,
'#description' => t("Check this if the search should only return results that exactly match the capitalization of your search terms."),
);
$form['options']['wholeword'] = array(
'#type' => 'checkbox',
'#title' => t('Match whole word'),
'#default_value' => $wholeword,
'#description' => t("Check this if you don't want the search to match any partial words. For instance, if you search for 'run', a whole word search will <em>not</em> match 'running'."),
);
$form['options']['regex'] = array(
'#type' => 'checkbox',
'#title' => t('Use regular expressions in search'),
'#default_value' => $regex,
'#description' => t('Check this if you want to use regular expressions in your search terms.'),
);
$form['options']['published'] = array(
'#type' => 'checkbox',
'#title' => t('Published nodes only'),
'#default_value' => $published,
'#description' => t('Check this if you only want your search and replace to affect fields in nodes that are published.'),
);
$form['options']['pathauto'] = array(
'#type' => 'checkbox',
'#title' => t('Maintain custom aliases'),
'#default_value' => $pathauto,
'#description' => t("Prevent custom URL aliases from being overwritten with ones generated from Path Auto's URL alias patterns."),
);
$scanner_vocabularies = array_filter(variable_get('scanner_vocabulary', array()));
if (count($scanner_vocabularies)) {
$vocabularies = taxonomy_get_vocabularies();
$options = array();
foreach ($vocabularies as $vid => $vocabulary) {
if (in_array($vid, $scanner_vocabularies)) {
$tree = taxonomy_get_tree($vid);
if ($tree && count($tree) > 0) {
$options[$vocabulary->name] = array();
foreach ($tree as $term) {
$options[$vocabulary->name][$term->tid] = str_repeat('-', $term->depth) . $term->name;
}
}
}
}
$form['options']['terms'] = array(
'#type' => 'select',
'#title' => t('Only match nodes with these terms'),
'#options' => $options,
'#default_value' => $terms,
'#multiple' => TRUE,
);
}
return $form;
}