From c0ae6c5e0cf9c12bfca7e6bea4c6045fef3b63a2 Mon Sep 17 00:00:00 2001 From: Aparup Banerjee Date: Fri, 5 Nov 2010 08:53:57 +0000 Subject: [PATCH] global search MDL-25056 added a port of the global_config.html to settings.php. Leaving the html file behind for regression checks. --- blocks/search/lang/en/block_search.php | 13 +++ blocks/search/settings.php | 127 +++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 blocks/search/settings.php diff --git a/blocks/search/lang/en/block_search.php b/blocks/search/lang/en/block_search.php index a71c23580fb..262ff86a4ee 100644 --- a/blocks/search/lang/en/block_search.php +++ b/blocks/search/lang/en/block_search.php @@ -35,14 +35,27 @@ $string['configtypetotxtcmd'] = 'Converter\'s command line'; $string['configtypetotxtenv'] = 'Environment define for converter'; $string['configwordtotextcmd'] = 'Path to command doctotext'; $string['configwordtotextenv'] = 'Environment setting for the MSWord converter'; +$string['cmdtoconverttotextfor'] = 'Command to convert {$a} to text'; +$string['enablefileindexing'] = 'Turn on indexing of different file types'; +$string['enableindexinginmodule'] = 'Allow indexing of the {$a} module'; +$string['enableindexinginblock'] = 'Allow indexing of the {$a} block'; +$string['envforcmdtotextfor'] = 'Environment for {$a} conversion command to text'; $string['go'] = 'Go!'; $string['handlingfor'] = 'Extra handling for'; +$string['headingofsearchblock'] = 'The title shown above the search box in the block'; +$string['indexbodylimit'] = 'The limit of indexing the body'; +$string['labelofsearchbutton'] = 'The text in the block search button itself'; +$string['listoffiletypes'] = 'The list of file types handled'; $string['modulessearchswitches'] = 'Indexer activation for modules'; $string['nosearchableblocks'] = 'No searchable blocks'; $string['nosearchablemodules'] = 'No searchable modules'; $string['pdfhandling'] = 'Acrobat PDF handling'; +$string['pdftotextcmd'] = 'Command to convert PDF to text'; $string['pluginname'] = 'Global search'; $string['searchdiscovery'] = 'Searchable items discovery'; $string['searchmoodle'] = 'Search Moodle'; $string['usemoodleroot'] = 'Use moodle root for external converters'; +$string['usemoodlerootdescription'] = 'Use moodle root for external converters'; $string['wordhandling'] = 'Microsoft Word handling'; +$string['wordtotextcmd'] = 'Command to convert Microsoft Word to text'; +$string['wordtotextenv'] = 'Environment setup for Microsoft Word to text converter'; diff --git a/blocks/search/settings.php b/blocks/search/settings.php new file mode 100644 index 00000000000..dd2a2b173b8 --- /dev/null +++ b/blocks/search/settings.php @@ -0,0 +1,127 @@ +fulltree) { + + //Search text + $settings->add(new admin_setting_configtext('block_search_text', get_string('configsearchtext', 'block_search'), + get_string('headingofsearchblock', 'block_search'), get_string('searchmoodle', 'block_search'), PARAM_ALPHANUM)); + + //Button Label + $settings->add(new admin_setting_configtext('block_search_button', get_string('configbuttonlabel', 'block_search'), + get_string('labelofsearchbutton', 'block_search'), get_string('go', 'block_search'), PARAM_ALPHANUM)); + + //Enable file indexing (y/n) + $settings->add(new admin_setting_configcheckbox('block_search_enable_file_indexing', get_string('configenablefileindexing', 'block_search'), + get_string('enablefileindexing', 'block_search'), 0, 1, 0)); + + //file types + $defaultfiletypes = 'PDF,TXT,HTML,PPT,XML,DOC,HTM'; + $settings->add(new admin_setting_configtext('block_search_filetypes', get_string('configfiletypes', 'block_search'), + get_string('listoffiletypes', 'block_search'), $defaultfiletypes, PARAM_ALPHANUM)); + + // usemoodleroot + $settings->add(new admin_setting_configcheckbox('block_search_usemoodleroot', get_string('usemoodleroot', 'block_search'), + get_string('usemoodlerootdescription', 'block_search'), 1, 1, 0)); + + //limit_index_body + $settings->add(new admin_setting_configtext('block_search_limit_index_body', get_string('configlimitindexbody', 'block_search'), + get_string('indexbodylimit', 'block_search'), '', PARAM_INT)); + + //setup default paths for following configs. + if ($CFG->ostype == 'WINDOWS') { + $default_pdf_to_text_cmd = "lib/xpdf/win32/pdftotext.exe -eol dos -enc UTF-8 -q"; + $default_word_to_text_cmd = "lib/antiword/win32/antiword/antiword.exe "; + $default_word_to_text_env = "HOME={$CFG->dirroot}\\lib\\antiword\\win32"; + } else { + $default_pdf_to_text_cmd = "lib/xpdf/linux/pdftotext -enc UTF-8 -eol unix -q"; + $default_word_to_text_cmd = "lib/antiword/linux/usr/bin/antiword"; + $default_word_to_text_env = "ANTIWORDHOME={$CFG->dirroot}/lib/antiword/linux/usr/share/antiword"; + } + + //pdf_to_text_cmd + $settings->add(new admin_setting_configtext('block_search_pdf_to_text_cmd', get_string('configpdftotextcmd', 'block_search'), + get_string('pdftotextcmd', 'block_search'), $default_pdf_to_text_cmd, PARAM_INT, 60)); + + //word_to_text_cmd + $settings->add(new admin_setting_configtext('block_search_word_to_text_cmd', get_string('configwordtotextcmd', 'block_search'), + get_string('wordtotextcmd', 'block_search'), $default_word_to_text_cmd, PARAM_INT, 60)); + + //word_to_text_env + $settings->add(new admin_setting_configtext('block_search_word_to_text_env', get_string('configwordtotextenv', 'block_search'), + get_string('wordtotextenv', 'block_search'), $default_word_to_text_env, PARAM_PATH, 60)); + + + // modules activations + + $types = explode(',', $CFG->block_search_filetypes); + if (!empty($types)) { + foreach($types as $type) { + $utype = strtoupper($type); + $type = strtolower($type); + $type = trim($type); + if (preg_match("/\\b$type\\b/i", $defaultfiletypes)) continue; + + //header + $propname = 'block_search_'.$type.'_to_text'; + $settings->add(new admin_setting_heading($propname, get_string('handlingfor', 'block_search').' '.$utype , '')); + + //word_to_text_cmd + $propname = 'block_search_'.$type.'_to_text_cmd'; + $settings->add(new admin_setting_configtext($propname, get_string('configtypetotxtcmd', 'block_search'), + get_string('cmdtoconverttotextfor', 'block_search', $type), '', PARAM_PATH, 60)); + + //word_to_text_env + $propname = "block_search_'.$type.'_to_text_env"; + $settings->add(new admin_setting_configtext($propname, get_string('configtypetotxtenv', 'block_search'), + get_string('envforcmdtotextfor', 'block_search', $type), '', PARAM_PATH, 60)); + + } + } + + require_once($CFG->dirroot.'/search/lib.php' ); + $searchnames = search_collect_searchables(true, false); + list($searchable_list, $params) = $DB->get_in_or_equal($searchnames); + + //header + $propname = 'block_search_'.$type.'_to_text'; + $settings->add(new admin_setting_heading($propname, get_string('searchdiscovery', 'block_search') , '')); + + $found_searchable_modules = 0; + if ($modules = $DB->get_records_select('modules', "name $searchable_list", $params, 'name', 'id,name')){ + foreach($modules as $module){ + $keyname = 'search_in_'.$module->name; + $settings->add(new admin_setting_configcheckbox($keyname, get_string('modulename', $module->name), + get_string('enableindexinginmodule', 'block_search', $module->name), 1, 1, 0)); + $found_searchable_modules = 1; + } + } + + if (!$found_searchable_modules) { + //header + $propname = 'block_search_nosearchablemodules'; + $settings->add(new admin_setting_heading($propname, get_string('nosearchablemodules', 'block_search') , '')); + } + + //header + $propname = 'block_search_searchswitches'; + $settings->add(new admin_setting_heading($propname, get_string('blockssearchswitches', 'block_search') , '')); + + $found_searchable_blocks = 0; + if ($blocks = $DB->get_records_select('block', "name $searchable_list", $params, 'name', 'id,name')){ + foreach($blocks as $block){ + $keyname = 'search_in_'.$block->name; + $settings->add(new admin_setting_configcheckbox($keyname, get_string('pluginname', 'block_'.$block->name), + get_string('enableindexinginblock', 'block_search', $block->name), 1, 1, 0)); + $found_searchable_blocks = 1; + } + } + if (!$found_searchable_blocks) { + //header + $propname = 'block_search_nosearchableblocks'; + $settings->add(new admin_setting_heading($propname, get_string('nosearchableblocks', 'block_search') , '')); + } + +} + -- 2.39.2