/[drupal]/contributions/modules/apachesolr/apachesolr.admin.inc
ViewVC logotype

Contents of /contributions/modules/apachesolr/apachesolr.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Mon Jun 29 23:23:07 2009 UTC (5 months ago) by pwolanin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +311 -40 lines
File MIME type: text/x-php
sync with DRUPAL-6--1
1 <?php
2 // $Id: apachesolr.admin.inc,v 1.1.2.25 2009/06/23 01:32:32 pwolanin Exp $
3
4 /**
5 * @file
6 * Administrative pages for the Apache Solr framework.
7 */
8
9 function apachesolr_settings() {
10 $form = array();
11
12 // Perform a check to ensure the server is there
13 if (empty($_POST)) {
14 $requirements = apachesolr_requirements('runtime');
15 $status = $requirements['apachesolr']['severity'] == 2 ? 'error' : 'status';
16 drupal_set_message($requirements['apachesolr']['value'], $status);
17 }
18
19 $form['apachesolr_host'] = array(
20 '#type' => 'textfield',
21 '#title' => t('Solr host name'),
22 '#default_value' => variable_get('apachesolr_host', 'localhost'),
23 '#description' => t('Host name of your Solr server, e.g. <code>localhost</code> or <code>example.com</code>.'),
24 );
25 $form['apachesolr_port'] = array(
26 '#type' => 'textfield',
27 '#title' => t('Solr port'),
28 '#default_value' => variable_get('apachesolr_port', '8983'),
29 '#description' => t('Port on which the Solr server listens. The Jetty example server is 8983, while Tomcat is 8080 by default.'),
30 );
31 $form['apachesolr_path'] = array(
32 '#type' => 'textfield',
33 '#title' => t('Solr path'),
34 '#default_value' => variable_get('apachesolr_path', '/solr'),
35 '#description' => t('Path that identifies the Solr request handler to be used.'),
36 );
37
38 $numbers = drupal_map_assoc(array(10, 20, 50, 100, 200));
39 $form['apachesolr_cron_limit'] = array(
40 '#type' => 'select',
41 '#title' => t('Number of items to index per cron run'),
42 '#default_value' => variable_get('apachesolr_cron_limit', 50),
43 '#options' => $numbers,
44 '#description' => t('The maximum number of items indexed in each pass of a <a href="@cron">cron maintenance task</a>. If necessary, reduce the number of items to prevent timeouts and memory errors while indexing.', array('@cron' => url('admin/reports/status')))
45 );
46
47 $options = drupal_map_assoc(array(5, 10, 15, 20, 25, 30, 40, 50, 60, 70, 80, 90, 100));
48 $form['apachesolr_rows'] = array(
49 '#type' => 'select',
50 '#title' => t('Results per page'),
51 '#default_value' => variable_get('apachesolr_rows', 10),
52 '#options' => $options,
53 '#description' => t('The number of results that will be shown per page.'),
54 );
55 $form['apachesolr_failure'] = array(
56 '#type' => 'select',
57 '#title' => t('On failure'),
58 '#options' => array('show_error' => t('Show error message'),
59 'show_drupal_results' => t('Show core Drupal results'),
60 'show_no_results' => t('Show no results')
61 ),
62 '#default_value' => variable_get('apachesolr_failure', 'show_error'),
63 '#description' => t('What to display if Apache Solr search is not available.'),
64 );
65 // Add a link to add more mlt blocks.
66 $form['mlt_link'] = array(
67 '#type' => 'item',
68 '#value' => l(t('Add a new content recommendation block'), 'admin/settings/apachesolr/mlt/add_block'),
69 '#description' => format_plural(count(apachesolr_mlt_list_blocks()), 'You currently have 1 block.', 'You currenly have @count blocks.'),
70 );
71 $form['advanced'] = array(
72 '#type' => 'fieldset',
73 '#title' => t('Advanced Configuration'),
74 '#collapsed' => TRUE,
75 '#collapsible' => TRUE,
76 );
77 $form['advanced']['apachesolr_set_nodeapi_messages'] = array(
78 '#type' => 'radios',
79 '#title' => t('Extra help messages for administrators'),
80 '#default_value' => variable_get('apachesolr_set_nodeapi_messages', 1),
81 '#options' => array(0 => t('Disabled'), 1 => t('Enabled')),
82 );
83 $form['advanced']['apachesolr_read_only'] = array(
84 '#type' => 'radios',
85 '#title' => t('Index write access'),
86 '#default_value' => variable_get('apachesolr_read_only', 0),
87 '#options' => array(0 => t('Read and write (normal)'), 1 => t('Read only')),
88 '#description' => t('<em>Read only</em> stops this site from sending updates to your search index. Useful for development sites.'),
89 );
90 return system_settings_form($form);
91 }
92
93 /**
94 * Gets information about the fields already in solr index.
95 */
96 function apachesolr_index_page() {
97 try {
98 $solr = apachesolr_get_solr();
99 // TODO: possibly clear this every page view if we are running multi-site.
100 if (apachesolr_index_updated()) {
101 $solr->clearCache();
102 }
103 $data = $solr->getLuke();
104 }
105 catch (Exception $e) {
106 watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
107 drupal_set_message(nl2br(check_plain($e->getMessage())), "warning");
108 $data->fields = array();
109 }
110
111 $output = '';
112 if (isset($data->index->numDocs)) {
113 $pending_docs = $delay_msg = $delete_msg = '';
114 try {
115 $stats_summary = $solr->getStatsSummary();
116 $delay_msg = '<p>' . t('<em>The server has a @autocommit_time delay before updates are processed.</em>', $stats_summary) . "</p>\n";
117 $delete_msg = '<p>' . t('Numer of pending deletions: @deletes_total', $stats_summary) . "</p>\n";
118 }
119 catch (Exception $e) {
120 watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
121 }
122 $output .= $delay_msg;
123 $pending_msg = $stats_summary['@pending_docs'] ? t('(@pending_docs sent but not yet processed)', $stats_summary) : '';
124 $output .= '<p>' . t('Number of documents in index: @num !pending', array('@num' => $data->index->numDocs, '!pending' => $pending_msg)) . "</p>\n";
125 $output .= $delete_msg;
126 }
127 $output .= '<p>' . l(t('View more details on the search index contents'), 'admin/reports/apachesolr') . "</p>\n";
128 // Display the Delete Index form.
129 $output .= drupal_get_form('apachesolr_delete_index_form');
130
131 return $output;
132 }
133
134 function apachesolr_index_report() {
135 try {
136 $solr = apachesolr_get_solr();
137 // TODO: possibly clear this every page view if we are running multi-site.
138 if (apachesolr_index_updated()) {
139 $solr->clearCache();
140 }
141 $data = $solr->getLuke();
142 }
143 catch (Exception $e) {
144 watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
145 drupal_set_message(nl2br(check_plain($e->getMessage())), "warning");
146 $data->fields = array();
147 }
148
149 $output = '<p>' . t('Number of documents in index: @num !pending', array('@num' => $data->index->numDocs, '!pending' => '')) . "</p>\n";
150
151 $limit = variable_get('apachesolr_luke_limit', 20000);
152 if (isset($data->index->numDocs) && $data->index->numDocs > $limit) {
153 $output .= '<p>' . t('You have more than @limit documents, so term frequencies are being omitted for performance reasons.', array('@limit' => $limit)) . "</p>\n";
154 $not_found = t('<em>Omitted</em>');
155 }
156 elseif (isset($data->index->numDocs)) {
157 $not_found = t('Not indexed');
158 try {
159 $solr = apachesolr_get_solr();
160 // Note: we use 2 since 1 fails on Ubuntu Hardy.
161 $data = $solr->getLuke(2);
162 $output .= '<p>' . t('Number of terms in index: @num', array('@num' => $data->index->numTerms)) . "</p>\n";
163 }
164 catch (Exception $e) {
165 watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
166 $data->fields = array();
167 }
168 }
169
170 $fields = (array)$data->fields;
171 if ($fields) {
172 $output .= '<p>' . t('Number of fields in index: @num', array('@num' => count($fields))) . "</p>\n";
173 $rows = array();
174 foreach ($fields as $name => $field) {
175 // TODO: try to map the name to something more meaningful.
176 $rows[$name] = array($name, $field->type, isset($field->distinct) ? $field->distinct : $not_found);
177 }
178 ksort($rows);
179 // Display the table of Field names, Index Types, and term counts.
180 $output .= theme('table', array(t('Field name'), t('Index type'), t('Distinct terms')), $rows);
181 }
182 else {
183 $output .= '<p>' . t('No data on indexed fields.') . "</p>\n";
184 }
185 return $output;
186 }
187
188 /**
189 * Indicates what order the specified facets should be listed in. This function is used in a usort
190 * invocation.
191 * @param $a
192 * The first facet.
193 * @param $b
194 * The second facet.
195 * @return
196 * A signed integer that indicates which of the specified facets should come first.
197 */
198 function _apachesolr_sort_facets($a, $b) {
199 return strcasecmp($a['info'], $b['info']);
200 }
201
202 /**
203 * This is the submit handler for the active facets form.
204 *
205 * The form values for each module are array filtereed to remove non-enabled items and
206 * stored in the variable table with the name 'apachesolr_enabled_facets'.
207 *
208 * @see apachesolr_enabled_facets_form()
209 */
210 function apachesolr_enabled_facets_form_submit($form, &$form_state) {
211 $enabled = array();
212 foreach ($form_state['values']['apachesolr_enabled_facets'] as $module => $facets) {
213 $enabled[$module] = array_filter($facets);
214 }
215 variable_set('apachesolr_enabled_facets', $enabled);
216 drupal_set_message($form_state['values']['submit_message'], 'warning');
217 }
218
219 /**
220 * Creates the form that allows the user to select which facets will be enabled.
221 *
222 * Only enabled facets are sent to solr. Fewer enabled facets can reduce the
223 * load on the search server. Blocks are only offered for enabled facets, so
224 * this also reduces the clutter on the blocks admin page.
225 */
226 function apachesolr_enabled_facets_form() {
227 $facets = array();
228 $module_facets = array();
229 $module_list = array();
230 foreach (module_implements('apachesolr_facets') as $module) {
231 $module_facets[$module] = module_invoke($module, 'apachesolr_facets');
232 uasort($module_facets[$module], '_apachesolr_sort_facets');
233 $module_list[$module] = $module;
234 }
235
236 $enabled_facets = apachesolr_get_enabled_facets();
237 $form = array();
238 $form['apachesolr_enabled_facets']['help'] = array (
239 '#type' => 'item',
240 '#value' => t('You can use this screen to select which search filter blocks should be created by enabling the corresponding filters on this page. For performance reasons, you should only enable filters that you intend to have available to users on the search page. After selecting which filter blocks to create, you will be sent to the blocks page where you can choose which of those blocks should be enabled when your users search by placing each block in a region.'),
241 );
242 if ($module_list) {
243 $placeholders = implode(', ', array_fill(0, count($module_list), "'%s'"));
244 $result = db_query("SELECT name, info FROM {system} WHERE name IN (". $placeholders .") AND type = 'module'", $module_list);
245 while ($item = db_fetch_array($result)) {
246 $module_list[$item['name']] = unserialize($item['info']);
247 }
248 }
249 foreach($module_facets as $module => $facets) {
250 $form['apachesolr_enabled_facets'][$module] = array(
251 '#type' => 'fieldset',
252 '#title' => check_plain($module_list[$module]['name']),
253 '#collapsible' => TRUE,
254 '#collapsed' => FALSE,
255 );
256 // We must use module + delta as the keys since that combination is
257 // guaranteed to be unique. A single module could, for example, have
258 // two different blocks that expose different faceting on the same
259 // field in the index.
260 foreach($facets as $delta => $data) {
261 $form['apachesolr_enabled_facets'][$module][$delta] = array(
262 '#type' => 'checkbox',
263 '#title' => $data['info'],
264 '#return_value' => $data['facet_field'],
265 '#default_value' => isset($enabled_facets[$module][$delta]) ? $data['facet_field'] : 0,
266 );
267 }
268 }
269
270 $has_facets = (bool)$module_facets;
271
272 $form['submit'] = array(
273 '#type' => 'submit',
274 '#value' => t('Save'),
275 '#access' => $has_facets,
276 );
277 $form['no-facets-message'] = array(
278 '#value' => t('<em>No filters are available from your currently enabled modules</em>'),
279 '#access' => !$has_facets,
280 );
281
282 $form['#tree'] = TRUE;
283 $form['submit_message'] = array(
284 '#type' => 'value',
285 '#value' => t('The Apache Solr filters settings were changed. To arrange the blocks for your enabled filters, visit the <a href="@url">blocks administration page</a>.', array('@url' => url('admin/build/block'))),
286 );
287
288 return $form;
289 }
290
291 /**
292 * Create a form for deleting the contents of the Solr index.
293 */
294 function apachesolr_delete_index_form() {
295 $form = array();
296 $form['markup'] = array(
297 '#prefix' => '<h3>',
298 '#value' => t('Search Index Controls'),
299 '#suffix' => '</h3>',
300 );
301 $form['reindex'] = array(
302 '#type' => 'submit',
303 '#value' => t('Re-index all content'),
304 '#submit' => array('apachesolr_clear_index'),
305 );
306 $form['reindex-desc'] = array(
307 '#type' => 'item',
308 '#description' => t('Re-indexing will add all content to the index again (overwriting the index), but existing content in the index will remain searchable.'),
309 );
310 $form['submit'] = array(
311 '#type' => 'submit',
312 '#value' => t('Delete the index'),
313 '#submit' => array('apachesolr_delete_index_submit'),
314 );
315 $form['delete-desc'] = array(
316 '#type' => 'item',
317 '#description' => t('Deletes all of the documents in the Solr index. This is rarely necessary unless your index is corrupt or you have installed a new schema.xml.'),
318 );
319
320 return $form;
321 }
322
323 /**
324 * Submit function for the 'Re-index all content' button.
325 *
326 * @see apachesolr_delete_index_form()
327 */
328 function apachesolr_clear_index($form, &$form_state) {
329 apachesolr_clear_last_index();
330 }
331
332
333 /**
334 * Submit function for the "Delete the index" button
335 * @see apachesolr_delete_index_form()
336 *
337 */
338 function apachesolr_delete_index_submit($form, &$form_state) {
339 $form_state['redirect'] = 'admin/settings/apachesolr/index/delete/confirm';
340 }
341
342 /**
343 * Confirmation form for 'Delete the index' button
344 * @see apachesolr_delete_index_submit()
345 */
346 function apachesolr_delete_index_confirm() {
347 $form = array();
348 return confirm_form($form, t('Are you sure you want to delete your search index and start re-indexing?'), 'admin/settings/apachesolr/index', NULL, t('Delete'), t('Cancel'));
349 }
350
351 /**
352 * Submit function for the 'Delete the index' confirmation form.
353 *
354 * @see apachesolr_delete_index_confirm()
355 */
356 function apachesolr_delete_index_confirm_submit($form, &$form_state) {
357 $form_state['redirect'] = 'admin/settings/apachesolr/index';
358 try {
359 apachesolr_delete_index();
360 // This form can't be seen by anyone without 'administer site configuration'
361 // permission, so no need to check perms before displaying a run-cron link.
362 drupal_set_message(t('The Apache Solr content index has been erased. You must now !run_cron until your entire site has been re-indexed.', array('!run_cron' => l(t('run cron'), 'admin/reports/status/run-cron', array('query' => array('destination' => 'admin/settings/apachesolr/index'))))));
363 }
364 catch (Exception $e) {
365 watchdog('Apache Solr', nl2br(check_plain($e->getMessage())), NULL, WATCHDOG_ERROR);
366 }
367 }
368
369 /**
370 * Utility function to delete the index and reset all index counters.
371 *
372 * @throws Exception
373 */
374 function apachesolr_delete_index() {
375 // Instantiate a new Solr object.
376 $solr = apachesolr_get_solr();
377 $query = '*:*';
378 // Allow other modules to modify the delete query.
379 // For example, use the site hash so that you only delete this site's
380 // content: $query = 'hash:' . apachesolr_site_hash()
381 drupal_alter('apachesolr_delete_index', $query);
382 $solr->deleteByQuery($query);
383 $solr->commit();
384 apachesolr_clear_last_index();
385 apachesolr_index_updated(time());
386 }
387
388 /**
389 * Try to map a schema field name to a human-readable description.
390 */
391 function _apachesolr_field_name_map($field_name) {
392 static $map;
393
394 if (!isset($map)) {
395 $map = array(
396 'body' => t('Body text - the full, rendered content'),
397 'title' => t('Title'),
398 'name' => t('Author name'),
399 'path_alias' => t('Path alias'),
400 'taxonomy_names' => t('All taxonomy term names'),
401 'tags_h1' => t('Body text inside H1 tags'),
402 'tags_h2_h3' => t('Body text inside H2 or H3 tags'),
403 'tags_h4_h5_h6' => t('Body text inside H4, H4, or H6 tags'),
404 'tags_inline' => t('Body text in inline tags like EM or STRONG'),
405 'tags_a' => t('Body text inside links (A tags)'),
406 'tid' => t('Taxonomy term IDs'),
407 );
408 foreach(taxonomy_get_vocabularies() as $vocab) {
409 $map['ts_vid_'. $vocab->vid .'_names'] = t('Taxonomy term names only from the %name vocabulary', array('%name' => $vocab->name));
410 $map['im_vid_'. $vocab->vid] = t('Taxonomy term IDs from the %name vocabulary', array('%name' => $vocab->name));
411 }
412 foreach (apachesolr_cck_fields() as $name => $field) {
413 $map[apachesolr_index_key($field)] = t('CCK @type field %label', array('@type' => $field['index_type'], '%name' => $field['label']));
414 }
415 drupal_alter('apachesolr_field_name_map', $map);
416 }
417 return isset($map[$field_name]) ? $map[$field_name] : $field_name;
418 }
419
420 /**
421 * MoreLikeThis administration and utility functions.
422 */
423
424 function apachesolr_mlt_add_block_form() {
425 $form = apachesolr_mlt_block_form();
426 $form['submit'] = array(
427 '#type' => 'submit',
428 '#value' => t('Save'),
429 '#weight' => '5',
430 );
431 return $form;
432 }
433
434 function apachesolr_mlt_add_block_form_submit($form, &$form_state) {
435 apachesolr_mlt_save_block($form_state['values']);
436 drupal_set_message('New content recommendation block created. Drag it into a region to enable it');
437 $form_state['redirect'] = 'admin/build/block';
438 }
439
440 /**
441 * Form to edit moreLikeThis block settings.
442 *
443 * @param int $delta If editing, the id of the block to edit.
444 *
445 * @return array The form used for editing.
446 * TODO:
447 * Add term boost settings.
448 * Enable the user to specify a query, rather then forcing suggestions based
449 * on the node id.
450 *
451 */
452 function apachesolr_mlt_block_form($delta = NULL) {
453 if (isset($delta)) {
454 $block = apachesolr_mlt_load_block($delta);
455 if (!$block) {
456 return array();
457 }
458 }
459 else{
460 $block = apachesolr_mlt_block_defaults();
461 }
462
463 $form['name'] = array(
464 '#type' => 'textfield',
465 '#title' => t('Block Name'),
466 '#description' => t('The block name displayed to site users.'),
467 '#required' => TRUE,
468 '#default_value' => $block['name'],
469 '#weight' => '-2',
470 );
471 $form['num_results'] = array(
472 '#type' => 'select',
473 '#title' => t('Maximum number of related items to display'),
474 '#default_value' => $block['num_results'],
475 '#options' => drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)),
476 '#weight' => -1,
477 );
478 $form['mlt_fl'] = array(
479 '#type' => 'checkboxes',
480 '#title' => t('Fields for finding related content'),
481 '#description' => t('Choose the fields to be used in calculating similarity. The default combination of %taxonomy_names and %title will provide relevant results for typical sites.', array("%taxonomy_names" => _apachesolr_field_name_map("taxonomy_names"), "%title" => _apachesolr_field_name_map("title"))),
482 '#options' => apachesolr_mlt_get_fields(),
483 '#required' => TRUE,
484 '#default_value' => $block['mlt_fl'],
485 );
486 $form['advanced'] = array(
487 '#type' => 'fieldset',
488 '#title' => t('Advanced Configuration'),
489 '#weight' => '1',
490 '#collapsible' => TRUE,
491 '#collapsed' => TRUE,
492 );
493 $options = drupal_map_assoc(array(1, 2, 3, 4, 5, 6, 7));
494 $form['advanced']['mlt_mintf'] = array(
495 '#type' => 'select',
496 '#title' => t('Minimum Term Frequency'),
497 '#description' => t('A word must appear this many times in any given document before the document is considered relevant for comparison.'),
498 '#default_value' => $block['mlt_mintf'],
499 '#options' => $options,
500 );
501 $form['advanced']['mlt_mindf'] = array(
502 '#type' => 'select',
503 '#title' => t('Minimum Document Frequency'),
504 '#description' => t('A word must occur in at least this many documents before it will be used for similarity comparison.'),
505 '#default_value' => $block['mlt_mindf'],
506 '#options' => $options,
507 );
508 $form['advanced']['mlt_minwl'] = array(
509 '#type' => 'select',
510 '#title' => t('Minimum Word Length'),
511 '#description' => 'You can use this to eliminate short words such as "the" and "it" from similarity comparisons. Words must be at least this number of characters or they will be ignored.',
512 '#default_value' => $block['mlt_minwl'],
513 '#options' => $options,
514 );
515 $form['advanced']['mlt_maxwl'] = array(
516 '#type' => 'select',
517 '#title' => t('Maximum World Length'),
518 '#description' => t('You can use this to eliminate very long words from similarity comparisons. Words of more than this number of characters will be ignored.'),
519 '#default_value' => $block['mlt_maxwl'],
520 '#options' => drupal_map_assoc(array(8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)),
521 );
522 $form['advanced']['mlt_maxqt'] = array(
523 '#type' => 'select',
524 '#title' => t('Maximum number of query terms'),
525 '#description' => t('The maximum number of query terms that will be included in any query. Lower numbers will result in fewer recommendations but will get results faster. If a content recommendation is not returning any recommendations, you can either check more "Comparison fields" checkboxes or increase the maximum number of query terms here.'),
526 '#options' => drupal_map_assoc(array(3, 5, 7, 10, 12, 15, 20, 25, 30, 35, 40)),
527 '#default_value' => $block['mlt_maxqt'],
528 );
529
530 return $form;
531 }
532
533 /**
534 * Merge supplied settings with the standard defaults..
535 */
536 function apachesolr_mlt_block_defaults($block = array()) {
537 return $block + array(
538 'name' => '',
539 'num_results' => '5',
540 'mlt_fl' => array(
541 'title' => 'title',
542 'taxonomy_names' => 'taxonomy_names',
543 ),
544 'mlt_mintf' => '1',
545 'mlt_mindf' => '1',
546 'mlt_minwl' => '3',
547 'mlt_maxwl' => '15',
548 'mlt_maxqt' => '20',
549 );
550 }
551
552 /**
553 * Constructs a list of field names used on the settings form.
554 *
555 * @return array An array containing a the fields in the solr instance.
556 */
557 function apachesolr_mlt_get_fields() {
558 $solr = apachesolr_get_solr();
559 $fields = $solr->getFields();
560 $rows = array();
561 foreach ($fields as $field_name => $field) {
562 if ($field->schema{4} == 'V')
563 $rows[$field_name] = _apachesolr_field_name_map($field_name);
564 }
565 ksort($rows);
566 return $rows;
567 }
568
569 /**
570 * A helper function to save MLT block data.
571 *
572 * If passed a block delta, the function will update block settings. If it is
573 * not passed a block delta, the function will create a new block.
574 *
575 * @param array $block_settings An array containing the settings required to form
576 * a moreLikeThis request.
577 *
578 * @param int $delta The id of the block you wish to update.
579 */
580 function apachesolr_mlt_save_block($block_settings = array(), $delta = NULL) {
581 $blocks = variable_get('apachesolr_mlt_blocks', array());
582 if (is_null($delta)) {
583 $count = 0;
584 ksort($blocks);
585 // Construct a new array key.
586 if (end($blocks)) {
587 list(, $count) = explode('-', key($blocks));
588 }
589 $delta = sprintf('mlt-%03d', 1 + $count);
590 }
591 $defaults = apachesolr_mlt_block_defaults();
592 // Remove stray form values.
593 $blocks[$delta] = array_intersect_key($block_settings, $defaults) + $defaults;
594 // Eliminate non-selected fields.
595 $blocks[$delta]['mlt_fl'] = array_filter($blocks[$delta]['mlt_fl']);
596 variable_set('apachesolr_mlt_blocks', $blocks);
597 }
598
599 function apachesolr_mlt_delete_block_form($form_state, $delta) {
600 if ($block = apachesolr_mlt_load_block($delta)) {
601 $form['delta'] = array(
602 '#type' => 'value',
603 '#value' => $delta
604 );
605
606 return confirm_form($form,
607 t('Are you sure you want to delete the Apache Solr content recommendation block %name?', array('%name' => $block['name'])),
608 'admin/build/block',
609 t('The block will be deleted. This action cannot be undone.'),
610 t('Delete'), t('Cancel'));
611 }
612 }
613
614 function apachesolr_mlt_delete_block_form_submit($form, &$form_state) {
615 $blocks = variable_get('apachesolr_mlt_blocks', array());
616 unset($blocks[$form_state['values']['delta']]);
617 variable_set('apachesolr_mlt_blocks', $blocks);
618 drupal_set_message(t('The block has been deleted.'));
619 $form_state['redirect'] = 'admin/build/block';
620 }
621

  ViewVC Help
Powered by ViewVC 1.1.2