1
|
<?php
|
2
|
// $Id$
|
3
|
|
4
|
require_once('cdm_dataportal.theme.php');
|
5
|
|
6
|
/* ====================== hook implementations ====================== */
|
7
|
|
8
|
/**
|
9
|
* Implementation of hook_help()
|
10
|
*
|
11
|
* Display help and module information
|
12
|
* @param section which section of the site we're displaying help
|
13
|
* @return help text for section
|
14
|
*/
|
15
|
function cdm_dataportal_help($section='') {
|
16
|
|
17
|
$out = '';
|
18
|
switch ($section) {
|
19
|
case "admin/modules#description":
|
20
|
$out = t("The dataportal publishes CDM data hosted in a CommunityStore on the web.");
|
21
|
break;
|
22
|
}
|
23
|
return $out;
|
24
|
}
|
25
|
|
26
|
|
27
|
/**
|
28
|
* Implementation of hook_perm()
|
29
|
*
|
30
|
* Valid permissions for this module
|
31
|
* @return array An array of valid permissions for the portfolio module
|
32
|
*/
|
33
|
function cdm_dataportal_perm() {
|
34
|
return array(
|
35
|
'administer cdm_dataportal',
|
36
|
'cdm_dataportal view notes',
|
37
|
//TODO which else permission are required? -> check the WP6 requirements document
|
38
|
);
|
39
|
}
|
40
|
|
41
|
|
42
|
/**
|
43
|
* Implementation of hook_menu()
|
44
|
*/
|
45
|
function cdm_dataportal_menu($may_cache) {
|
46
|
$items = array();
|
47
|
if ($may_cache) {
|
48
|
|
49
|
$items[] = array(
|
50
|
'path' => 'admin/settings/cdm_dataportal',
|
51
|
'title' => t('CDM Dataportal'),
|
52
|
'description' => t('Setting for the CDM Dataportal'),
|
53
|
'access' => user_access('administer cdm_dataportal'),
|
54
|
'callback' => 'drupal_get_form',
|
55
|
'callback arguments' => 'cdm_dataportal_settings',
|
56
|
'type' => MENU_NORMAL_ITEM,
|
57
|
);
|
58
|
|
59
|
$items[] = array(
|
60
|
'path' => 'cdm_dataportal/names',
|
61
|
'callback' => 'cdm_dataportal_view_names',
|
62
|
'access' => true,
|
63
|
'type' => MENU_CALLBACK,
|
64
|
);
|
65
|
// optional callback arguments: page
|
66
|
|
67
|
$items[] = array(
|
68
|
'path' => 'cdm_dataportal/taxon',
|
69
|
'callback' => 'cdm_dataportal_view_taxon',
|
70
|
'access' => true,
|
71
|
'type' => MENU_CALLBACK,
|
72
|
// expected callback arguments: name_uuid
|
73
|
);
|
74
|
|
75
|
}
|
76
|
return $items;
|
77
|
}
|
78
|
|
79
|
/**
|
80
|
* Implementation of hook_block()
|
81
|
*
|
82
|
* Provides the following blocks:
|
83
|
* 0: list of links useful during development
|
84
|
*
|
85
|
* @param String $op
|
86
|
* @param int $delta
|
87
|
*/
|
88
|
function cdm_dataportal_block($op='list', $delta=0) {
|
89
|
// listing of blocks, such as on the admin/block page
|
90
|
if ($op == "list") {
|
91
|
$block[0]["info"] = t("CDM DataPortal DevLinks");
|
92
|
return $block;
|
93
|
}
|
94
|
else if ($op == 'view') {
|
95
|
switch($delta){
|
96
|
case 0:
|
97
|
$block['subject'] = t('CDM DataPortal DevLinks');
|
98
|
$block['content'] = '<ul><li>'.l('Taxon Page', 'cdm_dataportal/taxon/uuid').'</li><li>'.l('Name List', 'cdm_dataportal/names').'</li></ul>';
|
99
|
return $block;
|
100
|
}
|
101
|
}
|
102
|
}
|
103
|
|
104
|
|
105
|
/**
|
106
|
* Implementation of hook_validate()
|
107
|
*
|
108
|
* @param $element
|
109
|
*/
|
110
|
function cdm_webservice_url_validate($element){
|
111
|
if (!str_endsWith($element['#value'], '/')) {
|
112
|
form_set_error('cdm_webservice_url', t("The URL to the CDM Web Service must end with a slash: '/'."));
|
113
|
}
|
114
|
}
|
115
|
|
116
|
|
117
|
/* ====================== menu callback functions ====================== */
|
118
|
|
119
|
/**
|
120
|
* Generate main administration form.
|
121
|
*
|
122
|
* @return
|
123
|
* An array containing form items to place on the module settings page.
|
124
|
*/
|
125
|
function cdm_dataportal_settings(){
|
126
|
|
127
|
//TODO: settings are still incomplete, compare with trunk/dataportal/inc/config_default.php.inc
|
128
|
$form['cdm_webservice'] = array(
|
129
|
'#type' => 'fieldset',
|
130
|
'#title' => t('CDM Web Servic'),
|
131
|
'#collapsible' => FALSE,
|
132
|
'#collapsed' => TRUE,
|
133
|
);
|
134
|
|
135
|
$form['cdm_webservice']['cdm_webservice_url'] = array(
|
136
|
'#type' => 'textfield',
|
137
|
'#title' => t('CDM Web Service URL'),
|
138
|
'#description' => t('The URL of CDM Webservice which delivers the data to be published.'),
|
139
|
'#default_value' => variable_get('cdm_webservice_url', 'http://dev.e-taxonomy.eu/svn/trunk/drupal/modules/cdm_dataportal/cdm/ws_stub/xml/'),
|
140
|
);
|
141
|
|
142
|
$form['cdm_webservice']['cdm_webservice_isStub'] = array(
|
143
|
'#type' => 'checkbox',
|
144
|
'#title' => t('Use Web Service Stub'),
|
145
|
'#default_value' => variable_get('cdm_webservice_isStub', 1),
|
146
|
'#description' => t('Use a static web service stub. Only for development. For further information please refer to the ')
|
147
|
.l('ws_stub/README.txt', 'http://dev.e-taxonomy.eu/svn/trunk/drupal/modules/cdm_dataportal/cdm/ws_stub/README.txt', array('target'=>'_blank')),
|
148
|
);
|
149
|
|
150
|
return system_settings_form($form);
|
151
|
}
|
152
|
|
153
|
|
154
|
/**
|
155
|
* Displays a list of the known taxonomic names. Long lists are split up into multiple pages
|
156
|
*
|
157
|
* TODO: parameters are still preliminar
|
158
|
* @param String $page page number to diplay defaults to page 1
|
159
|
* @param boolean $hide_unaccepted whether to hide nams which are not accepted by the current view
|
160
|
*/
|
161
|
function cdm_dataportal_view_names($page = 1, $onlyAccepted = false ){
|
162
|
|
163
|
$names = cdm_ws_name_list($page = 1, $onlyAccepted);
|
164
|
/*
|
165
|
* FIXME the filter for accepted names will be form element, thus this widget
|
166
|
* should be generated via form api!
|
167
|
*/
|
168
|
$out = theme('cdm_dataportal_widget_filter_accepted', $onlyAccepted);
|
169
|
$out .= theme('cdm_dataportal_widget_names_list', $names, $page);
|
170
|
$out .= theme('cdm_dataportal_names_list', $names, $page);
|
171
|
return $out;
|
172
|
}
|
173
|
|
174
|
|
175
|
/**
|
176
|
* The taxon page gives detailed information on a taxon, it shows:
|
177
|
* - Taxon name
|
178
|
* - Full list of synonyms homotypic synonyms on top, followed by the heterotypic and finally followed by misapplied names. The list is historically ordered.
|
179
|
* - All facts associated with the very taxon concept and taxon name.
|
180
|
*
|
181
|
* @param $name_uuid the $name_uuid of the taxon name
|
182
|
*/
|
183
|
function cdm_dataportal_view_taxon($uuid){
|
184
|
//FIXME this is a dummy implementation
|
185
|
$name = cdm_ws_get_name($uuid);
|
186
|
return theme('cdm_name', $name);
|
187
|
// END of dummy implementation
|
188
|
}
|
189
|
|
190
|
|
191
|
/* ====================== other functions ====================== */
|
192
|
|
193
|
|
194
|
/**
|
195
|
* @param $str the string to truncate
|
196
|
* @param $len the maximun length
|
197
|
* @param $appendix an optional appendix.
|
198
|
*
|
199
|
* @return the string truncated to the specified length or the original string as given as parameter.
|
200
|
* if an appendix has been defined the resulting string
|
201
|
* will have the specified length inculding the the appendix.
|
202
|
*/
|
203
|
function str_trunk(&$str, $len, $appendix=''){
|
204
|
if(strlen($str) >= $len )
|
205
|
return substr($str, 0, $len - strlen($appendix)).$appendix;
|
206
|
else
|
207
|
return $str;
|
208
|
}
|
209
|
|
210
|
/**
|
211
|
* @param string $str
|
212
|
* @param string $sub
|
213
|
* @return boolean
|
214
|
*/
|
215
|
function str_beginsWith( $str, $sub ) {
|
216
|
return ( substr( $str, 0, strlen( $sub ) ) === $sub );
|
217
|
}
|
218
|
|
219
|
/**
|
220
|
*
|
221
|
* @param string $str
|
222
|
* @param string $sub
|
223
|
* @return boolean
|
224
|
*/
|
225
|
function str_endsWith( $str, $sub ) {
|
226
|
return ( substr( $str, strlen( $str ) - strlen( $sub ) ) === $sub );
|
227
|
}
|