Projet

Général

Profil

Paste
Télécharger (14,1 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ds / modules / ds_search / includes / ds_search.admin.inc @ 3dfa8105

1
<?php
2

    
3
/**
4
 * @file
5
 * Administrative functions for Display Suite search.
6
 */
7

    
8
/**
9
 * Menu callback: Display Suite search settings.
10
 */
11
function ds_search_settings($form, $form_state) {
12

    
13
  $form['general'] = array(
14
    '#type' => 'fieldset',
15
    '#title' => t('General'),
16
  );
17

    
18
  $engine_options = array();
19
  foreach (module_implements('search_info') as $module) {
20
    if ($module != 'ds_search' && $module != 'user') {
21
      $engine_options[$module] = drupal_ucfirst(str_replace('_', ' ', $module));
22
    }
23
  }
24

    
25
  $form['general']['ds_search_type'] = array(
26
    '#type' => 'select',
27
    '#title' => t('Search engine'),
28
    '#description' => t('Select the search engine as the query backend.'),
29
    '#options' => $engine_options,
30
    '#default_value' => variable_get('ds_search_type', 'node'),
31
  );
32

    
33
  $form['general']['ds_search_path'] = array(
34
    '#type' => 'textfield',
35
    '#title' => t('Search path'),
36
    '#field_prefix' => 'search/',
37
    '#description' => t('Make sure you don\'t override an existing search path.'),
38
    '#default_value' => variable_get('ds_search_path', 'content'),
39
    '#required' => TRUE,
40
  );
41

    
42
  $entity_view_modes = ds_entity_view_modes('node');
43
  foreach ($entity_view_modes as $key => $view_mode) {
44
    $view_mode_options[$key] = $view_mode['label'];
45
  }
46
  $form['general']['ds_search_view_mode'] = array(
47
    '#type' => 'select',
48
    '#title' => t('View mode'),
49
    '#description' => 'Select another view mode in favor of the default search view mode.',
50
    '#default_value' => variable_get('ds_search_view_mode', 'search_result'),
51
    '#options' => $view_mode_options,
52
  );
53

    
54
  $form['general']['ds_search_file_render'] = array(
55
    '#type' => 'checkbox',
56
    '#title' => t('Use default search theming for files'),
57
    '#description' => t('File/attachment results are best supported when the file entity module is enabled. Toggle the checkbox in case it is not available or you want to use default search theming.'),
58
    '#default_value' => variable_get('ds_search_file_render', FALSE),
59
  );
60

    
61
  $form['general']['ds_search_variables'] = array(
62
    '#type' => 'radios',
63
    '#options' => array(
64
      'none' => t('None'),
65
      'search_totals' => t('Total results'),
66
      'search_totals_plus_keywords' => t('Total results + keywords'),
67
      'search_totals_from_to_end' => t('Totals + start to end')
68
    ),
69
    '#title' => t('Extra variables'),
70
    '#description' => t('Choose an extra variable to display on the results screen.'),
71
    '#default_value' => variable_get('ds_search_variables', 'none'),
72
  );
73

    
74
  $form['general']['ds_search_show_title'] = array(
75
    '#type' => 'checkbox',
76
    '#title' => t('Show title'),
77
    '#description' => t('Display the "Search results" title.'),
78
    '#default_value' => variable_get('ds_search_show_title'),
79
  );
80

    
81
  $form['general']['ds_search_language'] = array(
82
    '#type' => 'checkbox',
83
    '#title' => t('Language'),
84
    '#description' => t('Search in the language the site is currently in. Enable this if you have at least 2 languages.'),
85
    '#default_value' => variable_get('ds_search_language'),
86
  );
87

    
88
  $form['general']['ds_search_highlight'] = array(
89
    '#type' => 'checkbox',
90
    '#title' => t('Highlight search word'),
91
    '#description' => t('Use jQuery to highlight the word in the results.'),
92
    '#default_value' => variable_get('ds_search_highlight'),
93
  );
94

    
95
  $form['general']['ds_search_highlight_selector'] = array(
96
    '#type' => 'textfield',
97
    '#title' => t('HTML selector'),
98
    '#description' => t('Enter the css selector, if not sure, leave this by default.'),
99
    '#default_value' => variable_get('ds_search_highlight_selector', '.view-mode-search_result'),
100
    '#states' => array(
101
      'visible' => array(
102
        'input[name="ds_search_highlight"]' => array('checked' => TRUE),
103
      ),
104
    ),
105
  );
106

    
107
  $form['general']['ds_search_group_by_type'] = array(
108
    '#type' => 'checkbox',
109
    '#title' => t('Group by type.'),
110
    '#description' => t('Group the search results per page by type. Note that this only works if you only display nodes on the search result page.'),
111
    '#default_value' => variable_get('ds_search_group_by_type'),
112
  );
113

    
114
  // Group by type order.
115
  $form['ds_search_group_by_type_settings'] = array(
116
    '#type' => 'fieldset',
117
    '#title' => t('Group by type settings'),
118
    '#description' => t('Set the order of the node types which can be grouped. Node types which are not enabled will be showed into a "Other group". Note that this does not work with Apache Solr multisite support.'),
119
    '#theme' => 'ds_search_group_by_type_settings',
120
    '#states' => array(
121
      'visible' => array(
122
        'input[name="ds_search_group_by_type"]' => array('checked' => TRUE),
123
      ),
124
    ),
125
  );
126

    
127
  $node_types = node_type_get_names();
128
  $ds_search_group_by_type_settings = variable_get('ds_search_group_by_type_settings');
129
  $wrapper_options = array(
130
    'fieldset' => t('Fieldset'),
131
    'markup' => t('Div with H3 headline'),
132
  );
133
  foreach ($node_types as $name => $label) {
134

    
135
    $form['ds_search_group_by_type_settings'][$name]['name'] = array(
136
      '#markup' => check_plain($label),
137
    );
138

    
139
    $form['ds_search_group_by_type_settings'][$name]['status'] = array(
140
      '#type' => 'checkbox',
141
      '#title' => t('Weight for @title', array('@title' => $label)),
142
      '#title_display' => 'invisible',
143
      '#default_value' => isset($ds_search_group_by_type_settings[$name]) ? $ds_search_group_by_type_settings[$name]['status'] : TRUE,
144
      '#parents' => array('ds_search_group_by_type_settings', $name, 'status'),
145
    );
146

    
147
    $form['ds_search_group_by_type_settings'][$name]['label'] = array(
148
      '#type' => 'textfield',
149
      '#size' => 30,
150
      '#title' => t('Group label for @title', array('@title' => $label)),
151
      '#title_display' => 'invisible',
152
      '#description' => t('Group label. The label will be translatable. Leave empty for no label.'),
153
      '#default_value' => isset($ds_search_group_by_type_settings[$name]) ? $ds_search_group_by_type_settings[$name]['label'] : t('Results for @type', array('@type' => drupal_strtolower($node_types[$name]))),
154
      '#parents' => array('ds_search_group_by_type_settings', $name, 'label'),
155
    );
156

    
157
    $form['ds_search_group_by_type_settings'][$name]['wrapper'] = array(
158
      '#type' => 'select',
159
      '#options' => $wrapper_options,
160
      '#title' => t('Wrapper for @title', array('@title' => $label)),
161
      '#title_display' => 'invisible',
162
      '#default_value' => isset($ds_search_group_by_type_settings[$name]) ? $ds_search_group_by_type_settings[$name]['wrapper'] : 'fieldset',
163
      '#parents' => array('ds_search_group_by_type_settings', $name, 'wrapper'),
164
    );
165

    
166
    $weight = isset($ds_search_group_by_type_settings[$name]) ? $ds_search_group_by_type_settings[$name]['weight'] : 0;
167
    $form['ds_search_group_by_type_settings'][$name]['weight'] = array(
168
      '#type' => 'weight',
169
      '#title' => t('Weight for @title', array('@title' => $label)),
170
      '#title_display' => 'invisible',
171
      '#delta' => 30,
172
      '#default_value' => $weight,
173
      '#parents' => array('ds_search_group_by_type_settings', $name, 'weight'),
174
    );
175
    $form['ds_search_group_by_type_settings'][$name]['#weight'] = $weight;
176
  }
177

    
178
  $form['ds_search_group_by_type_settings']['ds_search_group_by_type_other'] = array(
179
    '#type' => 'textfield',
180
    '#title' => t('Other label'),
181
    '#description' => t('The label of the other group. Leave empty for no label.'),
182
    '#default_value' => variable_get('ds_search_group_by_type_other', 'Other'),
183
    '#states' => array(
184
      'visible' => array(
185
        'input[name="ds_search_group_by_type"]' => array('checked' => TRUE),
186
      ),
187
    ),
188
  );
189
  $form['ds_search_group_by_type_settings']['ds_search_group_by_type_other_wrapper'] = array(
190
    '#type' => 'select',
191
    '#options' => $wrapper_options,
192
    '#title' => t('Other wrapper'),
193
    '#description' => t('The wrapper of the other group.'),
194
    '#default_value' => variable_get('ds_search_group_by_type_other_wrapper', 'fieldset'),
195
    '#states' => array(
196
      'visible' => array(
197
        'input[name="ds_search_group_by_type"]' => array('checked' => TRUE),
198
      ),
199
    ),
200
  );
201

    
202
  $form['node'] = array(
203
    '#type' => 'fieldset',
204
    '#title' => t('Drupal core'),
205
    '#states' => array(
206
      'visible' => array(
207
        'select[name="ds_search_type"]' => array('value' => 'node'),
208
      ),
209
    ),
210
  );
211

    
212
  $form['node']['ds_search_node_form_alter'] = array(
213
    '#type' => 'checkbox',
214
    '#title' => t('Advanced'),
215
    '#description' => t('Enable the advanced search form.'),
216
    '#default_value' => variable_get('ds_search_node_form_alter'),
217
  );
218

    
219
  $form['node']['ds_search_node_limit'] = array(
220
    '#type' => 'textfield',
221
    '#default_value' => variable_get('ds_search_node_limit', 10),
222
    '#title' => t('Node search limit'),
223
    '#description' => t('The number of items to display per page. Enter 0 for no limit.'),
224
  );
225

    
226
  if (module_exists('apachesolr')) {
227

    
228
    $form['apachesolr_search'] = array(
229
      '#type' => 'fieldset',
230
      '#title' => t('Apache Solr'),
231
      '#states' => array(
232
        'visible' => array(
233
          'select[name="ds_search_type"]' => array('value' => 'apachesolr_search'),
234
        ),
235
      ),
236
    );
237

    
238
    $form['apachesolr_search']['ds_search_apachesolr_hide_current_filters'] = array(
239
      '#type' => 'checkbox',
240
      '#title' => t('Hide Retain filters'),
241
      '#description' => t('Hide the "Retain current filters" checkbox on search results.'),
242
      '#default_value' => variable_get('ds_search_apachesolr_hide_current_filters'),
243
    );
244

    
245
    $form['apachesolr_search']['ds_search_apachesolr_current_filters_default'] = array(
246
      '#type' => 'checkbox',
247
      '#title' => t('Remember filters'),
248
      '#description' => t('Remember the filters when you hide the "Retain current filters" checkbox.'),
249
      '#default_value' => variable_get('ds_search_apachesolr_current_filters_default'),
250
      '#states' => array(
251
        'visible' => array(
252
          'input[name="ds_search_apachesolr_hide_current_filters"]' => array('checked' => TRUE),
253
        ),
254
      ),
255
    );
256

    
257
    $form['apachesolr_search']['ds_search_apachesolr_multisite'] = array(
258
      '#type' => 'checkbox',
259
      '#title' => t('Multisite support'),
260
      '#description' => t('Enable this in case multiple sites share one index. Note that sometimes you need to make sure that your formatters are creating absolute paths for links or images. Implementing hook_url_outbound_alter() is a good option in which you can set $options[\'absolute\'] to TRUE.'),
261
      '#default_value' => variable_get('ds_search_apachesolr_multisite'),
262
    );
263

    
264
    $form['apachesolr_search']['ds_search_apachesolr_multisite_boost'] = array(
265
      '#type' => 'checkbox',
266
      '#title' => t('Sort by site'),
267
      '#description' => t('Enable this to rank the results of the current site first, than all the rest.'),
268
      '#default_value' => variable_get('ds_search_apachesolr_multisite_boost'),
269
      '#states' => array(
270
        'visible' => array(
271
          'input[name="ds_search_apachesolr_multisite"]' => array('checked' => TRUE),
272
        ),
273
      ),
274
    );
275

    
276
    $form['apachesolr_search']['ds_search_apachesolr_multisite_group'] = array(
277
      '#type' => 'checkbox',
278
      '#title' => t('Group results by site'),
279
      '#default_value' => variable_get('ds_search_apachesolr_multisite_group'),
280
      '#states' => array(
281
        'visible' => array(
282
          'input[name="ds_search_apachesolr_multisite"]' => array('checked' => TRUE),
283
        ),
284
      ),
285
    );
286

    
287
    $form['apachesolr_search']['ds_search_apachesolr_multisite_group_config'] = array(
288
      '#type' => 'textarea',
289
      '#title' => t('Group by site configuration'),
290
      '#default_value' => variable_get('ds_search_apachesolr_multisite_group_config'),
291
      '#description' => t('Enter sites line by line with following configuration: site-hash|label|wrapper. The <em>site-hash</em> is per site which you can get from Solr. The <em>label</em> is translatable per site. Use !total_per_site in this label for number of results per site. Depending on the number, you will either get "1 result" or "x results" which are translatable. The <em>wrapper</em> can either be "fieldset" or "div".'),
292
      '#states' => array(
293
        'visible' => array(
294
          'input[name="ds_search_apachesolr_multisite_group"]' => array('checked' => TRUE),
295
          'input[name="ds_search_apachesolr_multisite"]' => array('checked' => TRUE),
296
        ),
297
      ),
298
    );
299
  }
300

    
301
  $active = variable_get('search_active_modules', array('node', 'user'));
302
  if (isset($active['user']) && $active['user'] !== 0) {
303
    $form['user'] = array(
304
      '#type' => 'fieldset',
305
      '#title' => t('User search'),
306
    );
307

    
308
    $form['user']['ds_user_override_search_page'] = array(
309
      '#type' => 'checkbox',
310
      '#title' => t('Override user search page'),
311
      '#description' => t('Toggle this checkbox if you want Display Suite to render user search results.'),
312
      '#default_value' => variable_get('ds_user_override_search_page'),
313
    );
314
  }
315

    
316
  $form = system_settings_form($form);
317
  $form['#submit'][] = 'ds_search_settings_submit';
318
  return $form;
319
}
320

    
321
/**
322
 * Submit callback: Search settings submit.
323
 */
324
function ds_search_settings_submit($form, $form_state) {
325
  // Rebuild the menu.
326
  variable_set('menu_rebuild_needed', TRUE);
327
}
328

    
329
/**
330
 * Returns HTML for the Group by type settings.
331
 */
332
function theme_ds_search_group_by_type_settings($variables) {
333
  $element = $variables['element'];
334

    
335
  // Type order (tabledrag).
336
  $rows = array();
337
  foreach (element_children($element, TRUE) as $name) {
338

    
339
    if (!isset($element[$name]['name'])) {
340
      continue;
341
    }
342

    
343
    $element[$name]['weight']['#attributes']['class'][] = 'type-order-weight';
344
    $rows[] = array(
345
      'data' => array(
346
        drupal_render($element[$name]['name']),
347
        drupal_render($element[$name]['status']),
348
        drupal_render($element[$name]['label']),
349
        drupal_render($element[$name]['wrapper']),
350
        drupal_render($element[$name]['weight']),
351
      ),
352
      'class' => array('draggable'),
353
    );
354
  }
355

    
356
  $header = array(t('Type'), t('Status'), t('Group label'), t('Wrapper'), t('Weight'));
357
  $output = drupal_render_children($element);
358
  $output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'group-by-order')));
359
  drupal_add_tabledrag('group-by-order', 'order', 'sibling', 'type-order-weight', NULL, NULL, TRUE);
360

    
361
  return $output;
362
}