MDL-24625 Dropped $CFG->block_search_text and $CFG->block_search_button
[moodle.git] / blocks / search / settings.php
CommitLineData
76f062cd
AB
1<?php
2
3defined('MOODLE_INTERNAL') || die;
4
5if ($ADMIN->fulltree) {
6
76f062cd
AB
7 //Enable file indexing (y/n)
8 $settings->add(new admin_setting_configcheckbox('block_search_enable_file_indexing', get_string('configenablefileindexing', 'block_search'),
9 get_string('enablefileindexing', 'block_search'), 0, 1, 0));
10
11 //file types
12 $defaultfiletypes = 'PDF,TXT,HTML,PPT,XML,DOC,HTM';
13 $settings->add(new admin_setting_configtext('block_search_filetypes', get_string('configfiletypes', 'block_search'),
14 get_string('listoffiletypes', 'block_search'), $defaultfiletypes, PARAM_TEXT));
15
16 // usemoodleroot
17 $settings->add(new admin_setting_configcheckbox('block_search_usemoodleroot', get_string('usemoodleroot', 'block_search'),
18 get_string('usemoodlerootdescription', 'block_search'), 1, 1, 0));
19
20 //limit_index_body
21 $settings->add(new admin_setting_configtext('block_search_limit_index_body', get_string('configlimitindexbody', 'block_search'),
22 get_string('indexbodylimit', 'block_search'), '', PARAM_INT));
23
24 //setup default paths for following configs.
25 if ($CFG->ostype == 'WINDOWS') {
26 $default_pdf_to_text_cmd = "lib/xpdf/win32/pdftotext.exe -eol dos -enc UTF-8 -q";
27 $default_word_to_text_cmd = "lib/antiword/win32/antiword/antiword.exe ";
28 $default_word_to_text_env = "HOME={$CFG->dirroot}\\lib\\antiword\\win32";
29 } else {
30 $default_pdf_to_text_cmd = "lib/xpdf/linux/pdftotext -enc UTF-8 -eol unix -q";
31 $default_word_to_text_cmd = "lib/antiword/linux/usr/bin/antiword";
32 $default_word_to_text_env = "ANTIWORDHOME={$CFG->dirroot}/lib/antiword/linux/usr/share/antiword";
33 }
34
35 //pdf_to_text_cmd
36 $settings->add(new admin_setting_configtext('block_search_pdf_to_text_cmd', get_string('configpdftotextcmd', 'block_search'),
37 get_string('pdftotextcmd', 'block_search'), $default_pdf_to_text_cmd, PARAM_TEXT, 60));
38
39 //word_to_text_cmd
40 $settings->add(new admin_setting_configtext('block_search_word_to_text_cmd', get_string('configwordtotextcmd', 'block_search'),
41 get_string('wordtotextcmd', 'block_search'), $default_word_to_text_cmd, PARAM_TEXT, 60));
42
43 //word_to_text_env
44 $settings->add(new admin_setting_configtext('block_search_word_to_text_env', get_string('configwordtotextenv', 'block_search'),
45 get_string('wordtotextenv', 'block_search'), $default_word_to_text_env, PARAM_PATH, 60));
46
47
48 // modules activations
49 if (isset($CFG->block_search_filetypes)) {
50 $types = explode(',', $CFG->block_search_filetypes);
51 } else {
52 $types = explode(',', $defaultfiletypes);
53 }
54
55 if (!empty($types)) {
56 foreach($types as $type) {
57 $utype = strtoupper($type);
58 $type = strtolower($type);
59 $type = trim($type);
60 if (preg_match("/\\b$type\\b/i", $defaultfiletypes)) continue;
61
62 //header
63 $propname = 'block_search_'.$type.'_to_text';
64 $settings->add(new admin_setting_heading($propname, get_string('handlingfor', 'block_search').' '.$utype , ''));
65
66 //word_to_text_cmd
67 $propname = 'block_search_'.$type.'_to_text_cmd';
68 $settings->add(new admin_setting_configtext($propname, get_string('configtypetotxtcmd', 'block_search'),
69 get_string('cmdtoconverttotextfor', 'block_search', $type), '', PARAM_PATH, 60));
70
71 //word_to_text_env
72 $propname = "block_search_'.$type.'_to_text_env";
73 $settings->add(new admin_setting_configtext($propname, get_string('configtypetotxtenv', 'block_search'),
74 get_string('envforcmdtotextfor', 'block_search', $type), '', PARAM_PATH, 60));
75
76 }
77 }
78
79 require_once($CFG->dirroot.'/search/lib.php' );
80 $searchnames = search_collect_searchables(true, false);
81 list($searchable_list, $params) = $DB->get_in_or_equal($searchnames);
82
83 //header
84 $propname = 'block_search_'.$type.'_to_text';
85 $settings->add(new admin_setting_heading($propname, get_string('searchdiscovery', 'block_search') , ''));
86
87 $found_searchable_modules = 0;
88 if ($modules = $DB->get_records_select('modules', "name $searchable_list", $params, 'name', 'id,name')){
89 foreach($modules as $module){
90 $keyname = 'search_in_'.$module->name;
91 $settings->add(new admin_setting_configcheckbox($keyname, get_string('modulename', $module->name),
92 get_string('enableindexinginmodule', 'block_search', $module->name), 1, 1, 0));
93 $found_searchable_modules = 1;
94 }
95 }
96
97 if (!$found_searchable_modules) {
98 //header
99 $propname = 'block_search_nosearchablemodules';
100 $settings->add(new admin_setting_heading($propname, get_string('nosearchablemodules', 'block_search') , ''));
101 }
102
103 //header
104 $propname = 'block_search_searchswitches';
105 $settings->add(new admin_setting_heading($propname, get_string('blockssearchswitches', 'block_search') , ''));
106
107 $found_searchable_blocks = 0;
108 if ($blocks = $DB->get_records_select('block', "name $searchable_list", $params, 'name', 'id,name')){
109 foreach($blocks as $block){
110 $keyname = 'search_in_'.$block->name;
111 $settings->add(new admin_setting_configcheckbox($keyname, get_string('pluginname', 'block_'.$block->name),
112 get_string('enableindexinginblock', 'block_search', $block->name), 1, 1, 0));
113 $found_searchable_blocks = 1;
114 }
115 }
116 if (!$found_searchable_blocks) {
117 //header
118 $propname = 'block_search_nosearchableblocks';
119 $settings->add(new admin_setting_heading($propname, get_string('nosearchableblocks', 'block_search') , ''));
120 }
121
122}
123