custom_search.admin.inc 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /**
  3. * @file
  4. * Admin settings for custom search
  5. */
  6. /**
  7. * General settings.
  8. */
  9. function custom_search_admin() {
  10. // Basic settings.
  11. $form = _custom_search_default_admin_form();
  12. // Custom search paths
  13. $form = array_merge($form, _custom_search_custom_paths_admin_form());
  14. // Ordering.
  15. $form = array_merge($form, _custom_search_ordering_admin_form());
  16. $form['#attributes'] = array('enctype' => 'multipart/form-data');
  17. $form['#submit'][] = 'custom_search_admin_submit';
  18. return system_settings_form($form);
  19. }
  20. /**
  21. * Submit callback.
  22. */
  23. function custom_search_admin_submit($form, &$form_state) {
  24. // Saves the ordering.
  25. foreach ($form_state['values']['custom_search_order'] as $key => $data) {
  26. variable_set('custom_search_' . $key . '_weight', $data['sort']);
  27. variable_set('custom_search_' . $key . '_region', $data['region']);
  28. }
  29. // Uploads an image.
  30. $directory_path = 'public://custom_search';
  31. file_prepare_directory($directory_path, FILE_CREATE_DIRECTORY);
  32. // Check for a new uploaded image.
  33. if ($file = file_save_upload('custom_search_image', array('file_validate_is_image' => array()))) {
  34. if ($filepath = file_unmanaged_copy($file->uri, $directory_path)) {
  35. $form_state['values']['custom_search_image_path'] = $filepath;
  36. }
  37. }
  38. }
  39. /**
  40. * Content settings.
  41. */
  42. function custom_search_content_admin() {
  43. return system_settings_form(_custom_search_content_admin_form());
  44. }
  45. function custom_search_results_admin() {
  46. $form['custom_search_target'] = array(
  47. '#type' => 'select',
  48. '#title' => t('Results page opens in'),
  49. '#options' => array(
  50. '_self' => t('the same window'),
  51. '_blank' => t('a new window'),
  52. ),
  53. '#default_value' => variable_get('custom_search_target', '_self'),
  54. );
  55. $form['search_form'] = array(
  56. '#type' => 'fieldset',
  57. '#title' => t('Search form'),
  58. );
  59. $form['search_form']['custom_search_results_search'] = array(
  60. '#type' => 'checkbox',
  61. '#title' => t('Display basic search'),
  62. '#default_value' => variable_get('custom_search_results_search', TRUE),
  63. );
  64. $form['search_form']['custom_search_results_advanced_search'] = array(
  65. '#type' => 'checkbox',
  66. '#title' => t('Display advanced search'),
  67. '#default_value' => variable_get('custom_search_results_advanced_search', TRUE),
  68. );
  69. $form['search_form']['advanced'] = array(
  70. '#type' => 'fieldset',
  71. '#title' => t('Advanced search'),
  72. '#states' => array(
  73. 'visible' => array(
  74. ':input[name="custom_search_results_advanced_search"]' => array('checked' => TRUE),
  75. ),
  76. ),
  77. );
  78. $form['search_form']['advanced']['custom_search_results_advanced_search_collapsible'] = array(
  79. '#type' => 'checkbox',
  80. '#title' => t('Collapsible'),
  81. '#default_value' => variable_get('custom_search_results_advanced_search_collapsible', TRUE),
  82. );
  83. $form['search_form']['advanced']['custom_search_results_advanced_search_collapsed'] = array(
  84. '#type' => 'checkbox',
  85. '#title' => t('Collapsed'),
  86. '#default_value' => variable_get('custom_search_results_advanced_search_collapsed', TRUE),
  87. );
  88. $form['search_form']['advanced']['criteria'] = array(
  89. '#type' => 'fieldset',
  90. '#title' => t('Criteria'),
  91. '#description' => t('Select the criteria to display on the advanced search form.'),
  92. '#collapsible' => TRUE,
  93. '#collapsed' => TRUE,
  94. );
  95. $form['search_form']['advanced']['criteria']['custom_search_advanced_or_display'] = array(
  96. '#type' => 'checkbox',
  97. '#title' => t('Or'),
  98. '#default_value' => variable_get('custom_search_advanced_or_display', TRUE),
  99. );
  100. $form['search_form']['advanced']['criteria']['custom_search_advanced_phrase_display'] = array(
  101. '#type' => 'checkbox',
  102. '#title' => t('Phrase'),
  103. '#default_value' => variable_get('custom_search_advanced_phrase_display', TRUE),
  104. );
  105. $form['search_form']['advanced']['criteria']['custom_search_advanced_negative_display'] = array(
  106. '#type' => 'checkbox',
  107. '#title' => t('Negative'),
  108. '#default_value' => variable_get('custom_search_advanced_negative_display', TRUE),
  109. );
  110. $form['search_form']['advanced']['types'] = array(
  111. '#type' => 'fieldset',
  112. '#title' => t('Content types'),
  113. '#description' => t('Select the content types to display on the advanced search form.'),
  114. '#collapsible' => TRUE,
  115. '#collapsed' => TRUE,
  116. );
  117. $options = node_type_get_names();
  118. foreach ($options as $type => $name) {
  119. $form['search_form']['advanced']['types']['custom_search_advanced_type_' . $type . '_display'] = array(
  120. '#type' => 'checkbox',
  121. '#title' => $name,
  122. '#default_value' => variable_get('custom_search_advanced_type_' . $type . '_display', TRUE),
  123. );
  124. }
  125. if (module_exists('taxonomy')) {
  126. $form['search_form']['advanced']['taxonomy'] = array(
  127. '#type' => 'fieldset',
  128. '#title' => t('Taxonomy'),
  129. '#description' => t('Select the vocabularies to display on the advanced search form.'),
  130. '#collapsible' => TRUE,
  131. '#collapsed' => TRUE,
  132. );
  133. $vocabularies = taxonomy_get_vocabularies();
  134. foreach ($vocabularies as $voc) {
  135. $form['search_form']['advanced']['taxonomy']['custom_search_advanced_voc' . $voc->vid . '_display'] = array(
  136. '#type' => 'checkbox',
  137. '#title' => $voc->name,
  138. '#default_value' => variable_get('custom_search_advanced_voc' . $voc->vid . '_display', TRUE),
  139. );
  140. }
  141. }
  142. $form['results'] = array(
  143. '#type' => 'fieldset',
  144. '#title' => t('Results'),
  145. '#description' => t('Select data to display below each result.'),
  146. );
  147. $form['results']['custom_search_results_info_type'] = array(
  148. '#type' => 'checkbox',
  149. '#title' => t('Content type'),
  150. '#default_value' => variable_get('custom_search_results_info_type', TRUE),
  151. );
  152. $form['results']['custom_search_results_info_user'] = array(
  153. '#type' => 'checkbox',
  154. '#title' => t('User'),
  155. '#default_value' => variable_get('custom_search_results_info_user', TRUE),
  156. );
  157. $form['results']['custom_search_results_info_date'] = array(
  158. '#type' => 'checkbox',
  159. '#title' => t('Date'),
  160. '#default_value' => variable_get('custom_search_results_info_date', TRUE),
  161. );
  162. if (module_exists('comment')) {
  163. $form['results']['custom_search_results_info_comment'] = array(
  164. '#type' => 'checkbox',
  165. '#title' => t('Comments'),
  166. '#default_value' => variable_get('custom_search_results_info_comment', TRUE),
  167. );
  168. }
  169. $form['filter'] = array(
  170. '#type' => 'fieldset',
  171. '#title' => t('Filter'),
  172. '#description' => t('Add links to filter the results by content type.'),
  173. );
  174. $form['filter']['custom_search_filter'] = array(
  175. '#type' => 'select',
  176. '#title' => t('Position'),
  177. '#options' => array(
  178. 'disabled' => t('Disabled'),
  179. 'above' => t('Above results'),
  180. 'below' => t('Below results'),
  181. ),
  182. '#default_value' => variable_get('custom_search_filter', 'disabled'),
  183. );
  184. $form['filter']['custom_search_filter_label'] = array(
  185. '#type' => 'textfield',
  186. '#title' => t('Label text'),
  187. '#default_value' => variable_get('custom_search_filter_label', CUSTOM_SEARCH_FILTER_LABEL_DEFAULT),
  188. '#description' => t('Enter the label text for the list. The default value is "!default".', array('!default' => CUSTOM_SEARCH_FILTER_LABEL_DEFAULT)),
  189. '#states' => array(
  190. 'invisible' => array(
  191. ':input[name="custom_search_filter"]' => array('value' => 'disabled'),
  192. ),
  193. ),
  194. );
  195. return system_settings_form($form);
  196. }