summaryrefslogtreecommitdiff
path: root/sites/all/modules/ds/modules/ds_search/includes/ds_search.admin.inc
blob: 60390af6be727ea250db8a0c90099883369e7d1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<?php

/**
 * @file
 * Administrative functions for Display Suite search.
 */

/**
 * Menu callback: Display Suite search settings.
 */
function ds_search_settings($form, $form_state) {

  $form['general'] = array(
    '#type' => 'fieldset',
    '#title' => t('General'),
  );

  $engine_options = array();
  foreach (module_implements('search_info') as $module) {
    if ($module != 'ds_search' && $module != 'user') {
      $engine_options[$module] = drupal_ucfirst(str_replace('_', ' ', $module));
    }
  }

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

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

  $entity_view_modes = ds_entity_view_modes('node');
  foreach ($entity_view_modes as $key => $view_mode) {
    $view_mode_options[$key] = $view_mode['label'];
  }
  $form['general']['ds_search_view_mode'] = array(
    '#type' => 'select',
    '#title' => t('View mode'),
    '#description' => 'Select another view mode in favor of the default search view mode.',
    '#default_value' => variable_get('ds_search_view_mode', 'search_result'),
    '#options' => $view_mode_options,
  );

  $form['general']['ds_search_file_render'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use default search theming for files'),
    '#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.'),
    '#default_value' => variable_get('ds_search_file_render', FALSE),
  );

  $form['general']['ds_search_variables'] = array(
    '#type' => 'radios',
    '#options' => array(
      'none' => t('None'),
      'search_totals' => t('Total results'),
      'search_totals_plus_keywords' => t('Total results + keywords'),
      'search_totals_from_to_end' => t('Totals + start to end')
    ),
    '#title' => t('Extra variables'),
    '#description' => t('Choose an extra variable to display on the results screen.'),
    '#default_value' => variable_get('ds_search_variables', 'none'),
  );

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

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

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

  $form['general']['ds_search_highlight_selector'] = array(
    '#type' => 'textfield',
    '#title' => t('HTML selector'),
    '#description' => t('Enter the css selector, if not sure, leave this by default.'),
    '#default_value' => variable_get('ds_search_highlight_selector', '.view-mode-search_result'),
    '#states' => array(
      'visible' => array(
        'input[name="ds_search_highlight"]' => array('checked' => TRUE),
      ),
    ),
  );

  $form['general']['ds_search_group_by_type'] = array(
    '#type' => 'checkbox',
    '#title' => t('Group by type.'),
    '#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.'),
    '#default_value' => variable_get('ds_search_group_by_type'),
  );

  // Group by type order.
  $form['ds_search_group_by_type_settings'] = array(
    '#type' => 'fieldset',
    '#title' => t('Group by type settings'),
    '#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.'),
    '#theme' => 'ds_search_group_by_type_settings',
    '#states' => array(
      'visible' => array(
        'input[name="ds_search_group_by_type"]' => array('checked' => TRUE),
      ),
    ),
  );

  $node_types = node_type_get_names();
  $ds_search_group_by_type_settings = variable_get('ds_search_group_by_type_settings');
  $wrapper_options = array(
    'fieldset' => t('Fieldset'),
    'markup' => t('Div with H3 headline'),
  );
  foreach ($node_types as $name => $label) {

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

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

    $form['ds_search_group_by_type_settings'][$name]['label'] = array(
      '#type' => 'textfield',
      '#size' => 30,
      '#title' => t('Group label for @title', array('@title' => $label)),
      '#title_display' => 'invisible',
      '#description' => t('Group label. The label will be translatable. Leave empty for no label.'),
      '#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]))),
      '#parents' => array('ds_search_group_by_type_settings', $name, 'label'),
    );

    $form['ds_search_group_by_type_settings'][$name]['wrapper'] = array(
      '#type' => 'select',
      '#options' => $wrapper_options,
      '#title' => t('Wrapper for @title', array('@title' => $label)),
      '#title_display' => 'invisible',
      '#default_value' => isset($ds_search_group_by_type_settings[$name]) ? $ds_search_group_by_type_settings[$name]['wrapper'] : 'fieldset',
      '#parents' => array('ds_search_group_by_type_settings', $name, 'wrapper'),
    );

    $weight = isset($ds_search_group_by_type_settings[$name]) ? $ds_search_group_by_type_settings[$name]['weight'] : 0;
    $form['ds_search_group_by_type_settings'][$name]['weight'] = array(
      '#type' => 'weight',
      '#title' => t('Weight for @title', array('@title' => $label)),
      '#title_display' => 'invisible',
      '#delta' => 30,
      '#default_value' => $weight,
      '#parents' => array('ds_search_group_by_type_settings', $name, 'weight'),
    );
    $form['ds_search_group_by_type_settings'][$name]['#weight'] = $weight;
  }

  $form['ds_search_group_by_type_settings']['ds_search_group_by_type_other'] = array(
    '#type' => 'textfield',
    '#title' => t('Other label'),
    '#description' => t('The label of the other group. Leave empty for no label.'),
    '#default_value' => variable_get('ds_search_group_by_type_other', 'Other'),
    '#states' => array(
      'visible' => array(
        'input[name="ds_search_group_by_type"]' => array('checked' => TRUE),
      ),
    ),
  );
  $form['ds_search_group_by_type_settings']['ds_search_group_by_type_other_wrapper'] = array(
    '#type' => 'select',
    '#options' => $wrapper_options,
    '#title' => t('Other wrapper'),
    '#description' => t('The wrapper of the other group.'),
    '#default_value' => variable_get('ds_search_group_by_type_other_wrapper', 'fieldset'),
    '#states' => array(
      'visible' => array(
        'input[name="ds_search_group_by_type"]' => array('checked' => TRUE),
      ),
    ),
  );

  $form['node'] = array(
    '#type' => 'fieldset',
    '#title' => t('Drupal core'),
    '#states' => array(
      'visible' => array(
        'select[name="ds_search_type"]' => array('value' => 'node'),
      ),
    ),
  );

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

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

  if (module_exists('apachesolr')) {

    $form['apachesolr_search'] = array(
      '#type' => 'fieldset',
      '#title' => t('Apache Solr'),
      '#states' => array(
        'visible' => array(
          'select[name="ds_search_type"]' => array('value' => 'apachesolr_search'),
        ),
      ),
    );

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

    $form['apachesolr_search']['ds_search_apachesolr_current_filters_default'] = array(
      '#type' => 'checkbox',
      '#title' => t('Remember filters'),
      '#description' => t('Remember the filters when you hide the "Retain current filters" checkbox.'),
      '#default_value' => variable_get('ds_search_apachesolr_current_filters_default'),
      '#states' => array(
        'visible' => array(
          'input[name="ds_search_apachesolr_hide_current_filters"]' => array('checked' => TRUE),
        ),
      ),
    );

    $form['apachesolr_search']['ds_search_apachesolr_multisite'] = array(
      '#type' => 'checkbox',
      '#title' => t('Multisite support'),
      '#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.'),
      '#default_value' => variable_get('ds_search_apachesolr_multisite'),
    );

    $form['apachesolr_search']['ds_search_apachesolr_multisite_boost'] = array(
      '#type' => 'checkbox',
      '#title' => t('Sort by site'),
      '#description' => t('Enable this to rank the results of the current site first, than all the rest.'),
      '#default_value' => variable_get('ds_search_apachesolr_multisite_boost'),
      '#states' => array(
        'visible' => array(
          'input[name="ds_search_apachesolr_multisite"]' => array('checked' => TRUE),
        ),
      ),
    );

    $form['apachesolr_search']['ds_search_apachesolr_multisite_group'] = array(
      '#type' => 'checkbox',
      '#title' => t('Group results by site'),
      '#default_value' => variable_get('ds_search_apachesolr_multisite_group'),
      '#states' => array(
        'visible' => array(
          'input[name="ds_search_apachesolr_multisite"]' => array('checked' => TRUE),
        ),
      ),
    );

    $form['apachesolr_search']['ds_search_apachesolr_multisite_group_config'] = array(
      '#type' => 'textarea',
      '#title' => t('Group by site configuration'),
      '#default_value' => variable_get('ds_search_apachesolr_multisite_group_config'),
      '#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".'),
      '#states' => array(
        'visible' => array(
          'input[name="ds_search_apachesolr_multisite_group"]' => array('checked' => TRUE),
          'input[name="ds_search_apachesolr_multisite"]' => array('checked' => TRUE),
        ),
      ),
    );
  }

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

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

  $form = system_settings_form($form);
  $form['#submit'][] = 'ds_search_settings_submit';
  return $form;
}

/**
 * Submit callback: Search settings submit.
 */
function ds_search_settings_submit($form, $form_state) {
  // Rebuild the menu.
  variable_set('menu_rebuild_needed', TRUE);
}

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

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

    if (!isset($element[$name]['name'])) {
      continue;
    }

    $element[$name]['weight']['#attributes']['class'][] = 'type-order-weight';
    $rows[] = array(
      'data' => array(
        drupal_render($element[$name]['name']),
        drupal_render($element[$name]['status']),
        drupal_render($element[$name]['label']),
        drupal_render($element[$name]['wrapper']),
        drupal_render($element[$name]['weight']),
      ),
      'class' => array('draggable'),
    );
  }

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

  return $output;
}