forms.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. <?php
  2. /**
  3. * @file
  4. * Search forms
  5. */
  6. /**
  7. * Default admin form.
  8. */
  9. function _custom_search_default_admin_form($delta = '') {
  10. if ($delta != '') $delta = 'blocks_' . $delta . '_';
  11. // Labels & default text.
  12. $form['search_box'] = array(
  13. '#type' => 'fieldset',
  14. '#title' => t('Search box'),
  15. );
  16. $form['search_box']['custom_search_' . $delta . 'label_visibility'] = array(
  17. '#type' => 'checkbox',
  18. '#title' => t('Display label'),
  19. '#default_value' => variable_get('custom_search_' . $delta . 'label_visibility', TRUE),
  20. );
  21. $form['search_box']['custom_search_' . $delta . 'label'] = array(
  22. '#type' => 'textfield',
  23. '#title' => t('Search box label'),
  24. '#default_value' => variable_get('custom_search_' . $delta . 'label', CUSTOM_SEARCH_LABEL_DEFAULT),
  25. '#description' => t('Enter the label text for the search box. The default value is "!default".', array('!default' => CUSTOM_SEARCH_LABEL_DEFAULT)),
  26. '#states' => array(
  27. 'visible' => array(
  28. ':input[name="custom_search_' . $delta . 'label_visibility"]' => array('checked' => TRUE),
  29. ),
  30. ),
  31. );
  32. $form['search_box']['custom_search_' . $delta . 'text'] = array(
  33. '#type' => 'textfield',
  34. '#title' => t('Search box default text'),
  35. '#default_value' => variable_get('custom_search_' . $delta . 'text', ''),
  36. '#description' => t('This will change the default text inside the search form. Leave blank for no text. This field is blank by default.'),
  37. );
  38. $form['search_box']['custom_search_' . $delta . 'size'] = array(
  39. '#type' => 'textfield',
  40. '#title' => t('Search box size'),
  41. '#size' => 3,
  42. '#default_value' => variable_get('custom_search_' . $delta . 'size', CUSTOM_SEARCH_SIZE_DEFAULT),
  43. '#description' => t('The default value is "!default".', array('!default' => CUSTOM_SEARCH_SIZE_DEFAULT)),
  44. );
  45. $form['search_box']['custom_search_' . $delta . 'max_length'] = array(
  46. '#type' => 'textfield',
  47. '#title' => t('Search box maximum length'),
  48. '#size' => 3,
  49. '#default_value' => variable_get('custom_search_' . $delta . 'max_length', CUSTOM_SEARCH_MAX_LENGTH_DEFAULT),
  50. '#description' => t('The default value is "!default".', array('!default' => CUSTOM_SEARCH_MAX_LENGTH_DEFAULT)),
  51. '#required' => TRUE,
  52. );
  53. // Submit button.
  54. $form['submit_button'] = array(
  55. '#type' => 'fieldset',
  56. '#title' => t('Submit button'),
  57. );
  58. $form['submit_button']['custom_search_' . $delta . 'submit_text'] = array(
  59. '#type' => 'textfield',
  60. '#title' => t('Submit button text'),
  61. '#default_value' => variable_get('custom_search_' . $delta . 'submit_text', CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT),
  62. '#description' => t('Enter the text for the submit button. Leave blank to hide it. The default value is "!default".', array('!default' => CUSTOM_SEARCH_SUBMIT_TEXT_DEFAULT)),
  63. );
  64. $form['submit_button']['custom_search_' . $delta . 'image_path'] = array(
  65. '#type' => 'textfield',
  66. '#title' => t('Submit image path'),
  67. '#description' => t('The path to the file you would like to use as submit button instead of the default text button.'),
  68. '#default_value' => variable_get('custom_search_' . $delta . 'image_path', ''),
  69. );
  70. $form['submit_button']['custom_search_image'] = array(
  71. '#type' => 'file',
  72. '#title' => t('Submit image'),
  73. '#description' => t('If you don\'t have direct file access to the server, use this field to upload your image.'),
  74. );
  75. // Criteria.
  76. $form['criteria'] = array(
  77. '#type' => 'fieldset',
  78. '#title' => t('Advanced search criteria'),
  79. '#collapsible' => TRUE,
  80. '#collapsed' => TRUE,
  81. );
  82. $form['criteria']['or'] = array(
  83. '#type' => 'fieldset',
  84. '#title' => t('Or'),
  85. );
  86. $form['criteria']['or']['custom_search_' . $delta . 'criteria_or_display'] = array(
  87. '#type' => 'checkbox',
  88. '#title' => t('Display'),
  89. '#default_value' => variable_get('custom_search_' . $delta . 'criteria_or_display', FALSE),
  90. );
  91. $form['criteria']['or']['custom_search_' . $delta . 'criteria_or_label'] = array(
  92. '#type' => 'textfield',
  93. '#title' => t('Label'),
  94. '#default_value' => variable_get('custom_search_' . $delta . 'criteria_or_label', CUSTOM_SEARCH_CRITERIA_OR_LABEL_DEFAULT),
  95. '#description' => t('Enter the label text for this field. The default value is "!default".', array('!default' => CUSTOM_SEARCH_CRITERIA_OR_LABEL_DEFAULT)),
  96. '#states' => array(
  97. 'visible' => array(
  98. ':input[name="custom_search_' . $delta . 'criteria_or_display"]' => array('checked' => TRUE),
  99. ),
  100. ),
  101. );
  102. $form['criteria']['phrase'] = array(
  103. '#type' => 'fieldset',
  104. '#title' => t('Phrase'),
  105. );
  106. $form['criteria']['phrase']['custom_search_' . $delta . 'criteria_phrase_display'] = array(
  107. '#type' => 'checkbox',
  108. '#title' => t('Display'),
  109. '#default_value' => variable_get('custom_search_' . $delta . 'criteria_phrase_display', FALSE),
  110. );
  111. $form['criteria']['phrase']['custom_search_' . $delta . 'criteria_phrase_label'] = array(
  112. '#type' => 'textfield',
  113. '#title' => t('Label'),
  114. '#default_value' => variable_get('custom_search_' . $delta . 'criteria_phrase_label', CUSTOM_SEARCH_CRITERIA_PHRASE_LABEL_DEFAULT),
  115. '#description' => t('Enter the label text for this field. The default value is "!default".', array('!default' => CUSTOM_SEARCH_CRITERIA_PHRASE_LABEL_DEFAULT)),
  116. '#states' => array(
  117. 'visible' => array(
  118. ':input[name="custom_search_' . $delta . 'criteria_phrase_display"]' => array('checked' => TRUE),
  119. ),
  120. ),
  121. );
  122. $form['criteria']['negative'] = array(
  123. '#type' => 'fieldset',
  124. '#title' => t('Negative'),
  125. );
  126. $form['criteria']['negative']['custom_search_' . $delta . 'criteria_negative_display'] = array(
  127. '#type' => 'checkbox',
  128. '#title' => t('Display'),
  129. '#default_value' => variable_get('custom_search_' . $delta . 'criteria_negative_display', FALSE),
  130. );
  131. $form['criteria']['negative']['custom_search_' . $delta . 'criteria_negative_label'] = array(
  132. '#type' => 'textfield',
  133. '#title' => t('Label'),
  134. '#default_value' => variable_get('custom_search_' . $delta . 'criteria_negative_label', CUSTOM_SEARCH_CRITERIA_NEGATIVE_LABEL_DEFAULT),
  135. '#description' => t('Enter the label text for this field. The default value is "!default".', array('!default' => CUSTOM_SEARCH_CRITERIA_NEGATIVE_LABEL_DEFAULT)),
  136. '#states' => array(
  137. 'visible' => array(
  138. ':input[name="custom_search_' . $delta . 'criteria_negative_display"]' => array('checked' => TRUE),
  139. ),
  140. ),
  141. );
  142. if (module_exists('search_api_page')) {
  143. $search_api_pages = search_api_page_load_multiple();
  144. $options[0] = t('None');
  145. foreach($search_api_pages as $page) {
  146. $options[$page->id] = $page->name;
  147. }
  148. $form['searchapi'] = array(
  149. '#type' => 'fieldset',
  150. '#title' => t('Search API'),
  151. '#collapsible' => TRUE,
  152. '#collapsed' => TRUE,
  153. );
  154. $form['searchapi']['custom_search_' . $delta . 'search_api_page'] = array(
  155. '#type' => 'select',
  156. '#title' => t('Search API Page to use'),
  157. '#options' => $options,
  158. '#default_value' => variable_get('custom_search_' . $delta . 'search_api_page', 0),
  159. );
  160. }
  161. return $form;
  162. }
  163. /**
  164. * Content admin form.
  165. */
  166. function _custom_search_content_admin_form($delta = '') {
  167. if ($delta != '') $delta = 'blocks_' . $delta . '_';
  168. $form['content_selector'] = array(
  169. '#type' => 'fieldset',
  170. '#title' => t('Content selector'),
  171. '#description' => t('Select the search types to present as search options in the search block. If none is selected, no selector will be displayed. <strong>Note</strong>: if there\'s only one type checked, the selector won\'t be displayed BUT only this type will be searched.'),
  172. );
  173. $form['content_selector']['custom_search_' . $delta . 'node_types'] = array(
  174. '#type' => 'checkboxes',
  175. '#title' => t('Content types'),
  176. '#default_value' => variable_get('custom_search_' . $delta . 'node_types', array()),
  177. '#options' => node_type_get_names(),
  178. );
  179. // Other searches.
  180. $options = array();
  181. foreach (module_implements('search_info') as $module) {
  182. if ($module != 'node' && $name = module_invoke($module, 'search_info')) {
  183. $options[$module] = $name['title'];
  184. }
  185. }
  186. if (count($options)) {
  187. $form['content_selector']['custom_search_' . $delta . 'other'] = array(
  188. '#type' => 'checkboxes',
  189. '#title' => t('Other searches'),
  190. '#default_value' => variable_get('custom_search_' . $delta . 'other', array()),
  191. '#options' => $options,
  192. );
  193. }
  194. $form['content_selector']['custom_search_' . $delta . 'type_selector'] = array(
  195. '#type' => 'select',
  196. '#title' => t('Selector type'),
  197. '#options' => array(
  198. 'select' => t('Drop-down list'),
  199. 'selectmultiple' => t('Drop-down list with multiple choices'),
  200. 'radios' => t('Radio buttons'),
  201. 'checkboxes' => t('Checkboxes'),
  202. ),
  203. '#description' => t('Choose which selector type to use. Note: content types and other searches cannot be combined in a single search.'),
  204. '#default_value' => variable_get('custom_search_' . $delta . 'type_selector', 'select'),
  205. );
  206. $form['content_selector']['custom_search_' . $delta . 'type_selector_label_visibility'] = array(
  207. '#type' => 'checkbox',
  208. '#title' => t('Display label'),
  209. '#default_value' => variable_get('custom_search_' . $delta . 'type_selector_label_visibility', TRUE),
  210. );
  211. $form['content_selector']['custom_search_' . $delta . 'type_selector_label'] = array(
  212. '#type' => 'textfield',
  213. '#title' => t('Label text'),
  214. '#default_value' => variable_get('custom_search_' . $delta . 'type_selector_label', CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT),
  215. '#description' => t('Enter the label text for the selector. The default value is "!default".', array('!default' => CUSTOM_SEARCH_TYPE_SELECTOR_LABEL_DEFAULT)),
  216. '#states' => array(
  217. 'visible' => array(
  218. ':input[name="custom_search_' . $delta . 'type_selector_label_visibility"]' => array('checked' => TRUE),
  219. ),
  220. ),
  221. );
  222. $form['content_selector']['any'] = array(
  223. '#type' => 'fieldset',
  224. '#title' => t('-Any-'),
  225. );
  226. $form['content_selector']['any']['custom_search_' . $delta . 'type_selector_all'] = array(
  227. '#type' => 'textfield',
  228. '#title' => t('-Any content type- text'),
  229. '#default_value' => variable_get('custom_search_' . $delta . 'type_selector_all', CUSTOM_SEARCH_ALL_TEXT_DEFAULT),
  230. '#required' => TRUE,
  231. '#description' => t('Enter the text for "any content type" choice. The default value is "!default".', array('!default' => CUSTOM_SEARCH_ALL_TEXT_DEFAULT)),
  232. );
  233. $form['content_selector']['any']['custom_search_' . $delta . 'any_restricts'] = array(
  234. '#type' => 'checkbox',
  235. '#title' => t('Choosing -Any- restricts the search to the selected content types.'),
  236. '#default_value' => variable_get('custom_search_' . $delta . 'any_restricts', FALSE),
  237. '#description' => t('If not checked, choosing -Any- will search in all content types.'),
  238. );
  239. $form['content_selector']['any']['custom_search_' . $delta . 'any_force'] = array(
  240. '#type' => 'checkbox',
  241. '#title' => t('Force -Any- to be displayed.'),
  242. '#default_value' => variable_get('custom_search_' . $delta . 'any_force', FALSE),
  243. '#description' => t('When only one content type is selected, the default behaviour is to hide the selector. If you need the -Any- option to be displayed, check this.'),
  244. );
  245. $form['custom_search_' . $delta . 'node_types_excluded'] = array(
  246. '#type' => 'checkboxes',
  247. '#title' => t('Content exclusion'),
  248. '#description' => t('Select the content types you don\'t want to be displayed as results.'),
  249. '#default_value' => variable_get('custom_search_' . $delta . 'node_types_excluded', array()),
  250. '#options' => node_type_get_names(),
  251. );
  252. return $form;
  253. }
  254. /**
  255. * Custom paths admin form.
  256. */
  257. function _custom_search_custom_paths_admin_form($delta = '') {
  258. if ($delta != '') $delta = 'blocks_' . $delta . '_';
  259. $form['custom_search_paths_admin'] = array(
  260. '#type' => 'fieldset',
  261. '#title' => t('Custom search paths'),
  262. '#collapsed' => TRUE,
  263. '#collapsible' => TRUE,
  264. );
  265. $form['custom_search_paths_admin']['custom_search_' . $delta . 'paths_selector'] = array(
  266. '#type' => 'select',
  267. '#title' => t('Selector type'),
  268. '#options' => array(
  269. 'select' => t('Drop-down list'),
  270. 'radios' => t('Radio buttons'),
  271. ),
  272. '#description' => t('Choose which selector type to use.'),
  273. '#default_value' => variable_get('custom_search_' . $delta . 'paths_selector', 'select'),
  274. );
  275. $form['custom_search_paths_admin']['custom_search_' . $delta . 'paths_selector_label_visibility'] = array(
  276. '#type' => 'checkbox',
  277. '#title' => t('Display label'),
  278. '#default_value' => variable_get('custom_search_' . $delta . 'paths_selector_label_visibility', TRUE),
  279. );
  280. $form['custom_search_paths_admin']['custom_search_' . $delta . 'paths_selector_label'] = array(
  281. '#type' => 'textfield',
  282. '#title' => t('Label text'),
  283. '#default_value' => variable_get('custom_search_' . $delta . 'paths_selector_label', CUSTOM_SEARCH_PATHS_SELECTOR_LABEL_DEFAULT),
  284. '#description' => t('Enter the label text for the selector. The default value is "!default".', array('!default' => CUSTOM_SEARCH_PATHS_SELECTOR_LABEL_DEFAULT)),
  285. );
  286. $form['custom_search_paths_admin']['custom_search_' . $delta . 'paths'] = array(
  287. '#type' => 'textarea',
  288. '#title' => t('Paths'),
  289. '#default_value' => variable_get('custom_search_' . $delta . 'paths', ''),
  290. '#rows' => 3,
  291. '#description' => t('If you want to use custom search paths, enter them here in the form <em>path</em>|<em>label</em>, one per line (if only one path is specified, the selector will be hidden). The [key] token will be replaced by what is entered in the search box. Ie: mysearch/[key]|My custom search label.'),
  292. );
  293. return $form;
  294. }
  295. /**
  296. * Ordering admin form
  297. */
  298. function _custom_search_ordering_admin_form($delta = '') {
  299. drupal_add_css(drupal_get_path('module', 'custom_search') . '/custom_search.css');
  300. if ($delta != '') $delta = 'blocks_' . $delta . '_';
  301. $form['order'] = array(
  302. '#type' => 'fieldset',
  303. '#title' => t('Elements ordering'),
  304. '#description' => t('Order the form elements as you want them to be displayed. If you put elements in the Popup section, they will only appear when the search field is clicked.'),
  305. );
  306. $form['order']['custom_search_' . $delta . 'order'] = array(
  307. '#tree' => TRUE,
  308. '#theme' => 'custom_search_sort_form',
  309. );
  310. $elements = array(
  311. 'search_box' => array('title' => t('Search box'), 'default_weight' => -1),
  312. 'criteria_or' => array('title' => t('Advanced search criterion: Or'), 'default_weight' => 6),
  313. 'criteria_phrase' => array('title' => t('Advanced search criterion: Phrase'), 'default_weight' => 7),
  314. 'criteria_negative' => array('title' => t('Advanced search criterion: Negative'), 'default_weight' => 8),
  315. 'custom_paths' => array('title' => t('Custom search paths'), 'default_weight' => 9),
  316. 'submit_button' => array('title' => t('Submit button'), 'default_weight' => 10),
  317. );
  318. if (count(array_filter(array_merge(variable_get('custom_search_' . $delta . 'node_types', array()), variable_get('custom_search_' . $delta . 'other', array())))))
  319. $elements['content_types'] = array('title' => t('Content Types'), 'default_weight' => 0);
  320. foreach ($elements as $element => $data) {
  321. $form['order']['custom_search_' . $delta . 'order'][$element] = array(
  322. '#title' => $data['title'],
  323. '#weight' => variable_get('custom_search_' . $delta . $element . '_weight', $data['default_weight']),
  324. );
  325. $form['order']['custom_search_' . $delta . 'order'][$element]['sort'] = array(
  326. '#type' => 'weight',
  327. '#default_value' => variable_get('custom_search_' . $delta . $element . '_weight', $data['default_weight']),
  328. '#attributes' => array('class' => array('sort-select', 'sort-select-' . variable_get('custom_search_' . $delta . $element . '_region', 'block'))),
  329. );
  330. $form['order']['custom_search_' . $delta . 'order'][$element]['region'] = array(
  331. '#type' => 'select',
  332. '#options' => array(
  333. 'block' => t('Block'),
  334. 'popup' => t('Popup')
  335. ),
  336. '#default_value' => variable_get('custom_search_' . $delta . $element . '_region', 'block'),
  337. '#attributes' => array('class' => array('region-select', 'region-select-' . variable_get('custom_search_' . $delta . $element . '_region', 'block'))),
  338. );
  339. }
  340. return $form;
  341. }