function scanner_view in Search and Replace Scanner 6
Same name and namespace in other branches
- 5.2 scanner.module \scanner_view()
- 7 scanner.module \scanner_view()
Menu callback; presents the scan form and results.
1 string reference to 'scanner_view'
- scanner_menu in ./
scanner.module - Implementation of hook_menu().
File
- ./
scanner.module, line 150 - Search and Replace Scanner - works on all nodes text content.
Code
function scanner_view() {
//using set_html_head because it seems unecessary to load a separate css
// file for just two simple declarations:
drupal_set_html_head('
<style type="text/css">
#scanner-form .form-submit { margin-top:0; }
#scanner-form .form-item { margin-bottom:0; }
</style>
');
//javascript checks to make sure user has entered some search text:
drupal_add_js("\n \$(document).ready(function() {\n \$('input[@type=submit][@value=Search]').click(function() {\n var searchfield = \$('#edit-search');\n var chars = searchfield.val().length;\n if (chars == 0) {\n alert('Please provide some search text and try again.');\n searchfield.addClass('error');\n searchfield[0].focus();\n return FALSE;\n } else if (chars < 3) {\n return confirm('Searching for a keyword that has fewer than three characters could take a long time. Are you sure you want to continue?');\n }\n return TRUE;\n });\n });\n ", 'inline');
$search = $_SESSION['scanner_search'];
$status = $_SESSION['scanner_status'];
if (!is_NULL($search) && $status >= SCANNER_STATUS_GO_SEARCH) {
if ($status == SCANNER_STATUS_GO_CONFIRM) {
drupal_goto('admin/content/scanner/scan/confirm');
}
else {
if ($status == SCANNER_STATUS_GO_REPLACE) {
$resulttxt = '<a name="results"></a>' . t('Replacement Results');
$results = scanner_execute('replace');
}
else {
$resulttxt = t('Search Results');
$results = scanner_execute('search');
}
}
if ($results) {
$results = '<a name="results"></a>' . theme('box', $resulttxt, $results);
}
else {
$results = theme('box', t('Your scan yielded no results'), NULL);
}
$output = drupal_get_form('scanner_form');
$output .= $results;
//clear any old search form input:
unset($_SESSION['scanner_search']);
unset($_SESSION['scanner_replace']);
unset($_SESSION['scanner_preceded']);
unset($_SESSION['scanner_followed']);
unset($_SESSION['scanner_mode']);
unset($_SESSION['scanner_wholeword']);
unset($_SESSION['scanner_published']);
unset($_SESSION['scanner_regex']);
unset($_SESSION['scanner_terms']);
//clear old status:
unset($_SESSION['scanner_status']);
return $output;
}
return $output . drupal_get_form('scanner_form');
}