custom_search.admin.inc 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. /**
  46. * Results page settings.
  47. */
  48. function custom_search_results_admin() {
  49. $form['custom_search_target'] = array(
  50. '#type' => 'select',
  51. '#title' => t('Results page opens in'),
  52. '#options' => array(
  53. '_self' => t('the same window'),
  54. '_blank' => t('a new window'),
  55. ),
  56. '#default_value' => variable_get('custom_search_target', '_self'),
  57. );
  58. $form['search_form'] = array(
  59. '#type' => 'fieldset',
  60. '#title' => t('Search form'),
  61. );
  62. $form['search_form']['custom_search_results_search'] = array(
  63. '#type' => 'checkbox',
  64. '#title' => t('Display basic search'),
  65. '#default_value' => variable_get('custom_search_results_search', TRUE),
  66. );
  67. $form['search_form']['custom_search_results_advanced_search'] = array(
  68. '#type' => 'checkbox',
  69. '#title' => t('Display advanced search'),
  70. '#default_value' => variable_get('custom_search_results_advanced_search', TRUE),
  71. );
  72. $form['search_form']['advanced'] = array(
  73. '#type' => 'fieldset',
  74. '#title' => t('Advanced search'),
  75. '#states' => array(
  76. 'visible' => array(
  77. ':input[name="custom_search_results_advanced_search"]' => array('checked' => TRUE),
  78. ),
  79. ),
  80. );
  81. $form['search_form']['advanced']['custom_search_results_advanced_search_collapsible'] = array(
  82. '#type' => 'checkbox',
  83. '#title' => t('Collapsible'),
  84. '#default_value' => variable_get('custom_search_results_advanced_search_collapsible', TRUE),
  85. );
  86. $form['search_form']['advanced']['custom_search_results_advanced_search_collapsed'] = array(
  87. '#type' => 'checkbox',
  88. '#title' => t('Collapsed'),
  89. '#default_value' => variable_get('custom_search_results_advanced_search_collapsed', TRUE),
  90. );
  91. $form['search_form']['advanced']['criteria'] = array(
  92. '#type' => 'fieldset',
  93. '#title' => t('Criteria'),
  94. '#description' => t('Select the criteria to display on the advanced search form.'),
  95. '#collapsible' => TRUE,
  96. '#collapsed' => TRUE,
  97. );
  98. $form['search_form']['advanced']['criteria']['custom_search_advanced_or_display'] = array(
  99. '#type' => 'checkbox',
  100. '#title' => t('Or'),
  101. '#default_value' => variable_get('custom_search_advanced_or_display', TRUE),
  102. );
  103. $form['search_form']['advanced']['criteria']['custom_search_advanced_phrase_display'] = array(
  104. '#type' => 'checkbox',
  105. '#title' => t('Phrase'),
  106. '#default_value' => variable_get('custom_search_advanced_phrase_display', TRUE),
  107. );
  108. $form['search_form']['advanced']['criteria']['custom_search_advanced_negative_display'] = array(
  109. '#type' => 'checkbox',
  110. '#title' => t('Negative'),
  111. '#default_value' => variable_get('custom_search_advanced_negative_display', TRUE),
  112. );
  113. $form['search_form']['advanced']['types'] = array(
  114. '#type' => 'fieldset',
  115. '#title' => t('Content types'),
  116. '#description' => t('Select the content types to display on the advanced search form.'),
  117. '#collapsible' => TRUE,
  118. '#collapsed' => TRUE,
  119. );
  120. $options = node_type_get_names();
  121. foreach ($options as $type => $name) {
  122. $form['search_form']['advanced']['types']['custom_search_advanced_type_' . $type . '_display'] = array(
  123. '#type' => 'checkbox',
  124. '#title' => $name,
  125. '#default_value' => variable_get('custom_search_advanced_type_' . $type . '_display', TRUE),
  126. );
  127. }
  128. // Languages.
  129. $language_options = array();
  130. foreach (language_list('language') as $key => $entity) {
  131. if ($entity->enabled) {
  132. $language_options[$key] = $entity->name;
  133. }
  134. }
  135. if (count($language_options) > 1) {
  136. $form['search_form']['advanced']['languages'] = array(
  137. '#type' => 'fieldset',
  138. '#title' => t('Languages'),
  139. '#description' => t('Select the languages to display on the advanced search form.'),
  140. '#collapsible' => TRUE,
  141. '#collapsed' => TRUE,
  142. );
  143. foreach ($language_options as $key => $name) {
  144. $form['search_form']['advanced']['languages']['custom_search_advanced_language_' . $key . '_display'] = array(
  145. '#type' => 'checkbox',
  146. '#title' => $name,
  147. '#default_value' => variable_get('custom_search_advanced_language_' . $key . '_display', TRUE),
  148. );
  149. }
  150. }
  151. $form['results'] = array(
  152. '#type' => 'fieldset',
  153. '#title' => t('Results'),
  154. '#description' => t('Select data to display below each result.'),
  155. );
  156. $form['results']['custom_search_results_info_type'] = array(
  157. '#type' => 'checkbox',
  158. '#title' => t('Content type'),
  159. '#default_value' => variable_get('custom_search_results_info_type', TRUE),
  160. );
  161. $form['results']['custom_search_results_info_user'] = array(
  162. '#type' => 'checkbox',
  163. '#title' => t('User'),
  164. '#default_value' => variable_get('custom_search_results_info_user', TRUE),
  165. );
  166. $form['results']['custom_search_results_info_date'] = array(
  167. '#type' => 'checkbox',
  168. '#title' => t('Date'),
  169. '#default_value' => variable_get('custom_search_results_info_date', TRUE),
  170. );
  171. if (module_exists('comment')) {
  172. $form['results']['custom_search_results_info_comment'] = array(
  173. '#type' => 'checkbox',
  174. '#title' => t('Comments'),
  175. '#default_value' => variable_get('custom_search_results_info_comment', TRUE),
  176. );
  177. }
  178. $form['filter'] = array(
  179. '#type' => 'fieldset',
  180. '#title' => t('Filter'),
  181. '#description' => t('Add links to filter the results by content type.'),
  182. );
  183. $form['filter']['custom_search_filter'] = array(
  184. '#type' => 'select',
  185. '#title' => t('Position'),
  186. '#options' => array(
  187. 'disabled' => t('Disabled'),
  188. 'above' => t('Above results'),
  189. 'below' => t('Below results'),
  190. ),
  191. '#default_value' => variable_get('custom_search_filter', 'disabled'),
  192. );
  193. $form['filter']['custom_search_filter_label'] = array(
  194. '#type' => 'textfield',
  195. '#title' => t('Label text'),
  196. '#default_value' => variable_get('custom_search_filter_label', CUSTOM_SEARCH_FILTER_LABEL_DEFAULT),
  197. '#description' => t('Enter the label text for the list. The default value is "!default".', array('!default' => CUSTOM_SEARCH_FILTER_LABEL_DEFAULT)),
  198. '#states' => array(
  199. 'invisible' => array(
  200. ':input[name="custom_search_filter"]' => array('value' => 'disabled'),
  201. ),
  202. ),
  203. );
  204. return system_settings_form($form);
  205. }