1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* Implements hook_menu().
|
5
|
*/
|
6
|
function dwca_export_menu() {
|
7
|
|
8
|
$items = array();
|
9
|
|
10
|
$items['admin/config/system/dwca_export/settings'] = array(
|
11
|
|
12
|
'title' => t('DarwinCore-Archive export'),
|
13
|
'page callback' => 'drupal_get_form',
|
14
|
'page arguments' => array('dwca_export_config_form'),
|
15
|
'access arguments' => array('access administration pages'),
|
16
|
'type' => MENU_LOCAL_TASK,
|
17
|
//'file' => 'dwca_export.admin.inc'
|
18
|
);
|
19
|
|
20
|
$items['dwca_export'] = array(
|
21
|
'page callback' => 'dwca_export_deliver_archive',
|
22
|
'access arguments' => TRUE,
|
23
|
'type' => MENU_CALLBACK
|
24
|
);
|
25
|
|
26
|
|
27
|
return $items;
|
28
|
}
|
29
|
|
30
|
/**
|
31
|
* Form function, called by drupal_get_form()
|
32
|
* in dwca_export_menu().
|
33
|
*/
|
34
|
function dwca_export_config_form($form, &$form_state) {
|
35
|
|
36
|
$form['dwca_export_todo'] = array(
|
37
|
'#markup' => '<p>No settings implemented yet.</p>'
|
38
|
);
|
39
|
|
40
|
return system_settings_form($form);
|
41
|
}
|
42
|
|
43
|
|
44
|
/**
|
45
|
* menu callback
|
46
|
*/
|
47
|
function dwca_export_deliver_archive() {
|
48
|
|
49
|
$tmp_archive_file_name = dwca_export_create_archive( _get_views_map() );
|
50
|
|
51
|
// 1. http://api.drupal.org/api/drupal/includes--file.inc/function/file_copy/7
|
52
|
// 2. file_transfer($tmp_archive_file_name, $headers)
|
53
|
|
54
|
print "TODO export";
|
55
|
}
|
56
|
|
57
|
/**
|
58
|
* Walks all view export paths defined in the $views_map.
|
59
|
* Each file is downloaded to the tmp folder and a zip file
|
60
|
* is bundeled of the resulting csv files plus the meta file.
|
61
|
*
|
62
|
* @param - $views_map maps a view paths to dwca filenames
|
63
|
*
|
64
|
* @return the path in the filesystem to the final archive
|
65
|
*/
|
66
|
function dwca_export_create_archive($views_map) {
|
67
|
|
68
|
$tmp_archive_file_name = drupal_tempnam(file_directory_temp(), "dwca_export_");
|
69
|
|
70
|
return $tmp_archive_file_name;
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* provides the settings which map a view path to
|
75
|
* a dwca filename.
|
76
|
*
|
77
|
*/
|
78
|
function _get_views_map() {
|
79
|
|
80
|
return array(
|
81
|
'taxon' => 'taxon.txt',
|
82
|
'extension' => 'extension.txt'
|
83
|
);
|
84
|
}
|