1
|
<?php
|
2
|
// $Id$
|
3
|
|
4
|
/**
|
5
|
* @file
|
6
|
* Functions which are required or useful when accessing and processing CDM Data Store Webservices
|
7
|
*
|
8
|
* Naming conventions:
|
9
|
* ----------------------
|
10
|
*
|
11
|
* - all webservice access methods are prefixed with cdm_ws
|
12
|
*
|
13
|
*
|
14
|
* Copyright (C) 2007 EDIT
|
15
|
* European Distributed Institute of Taxonomy
|
16
|
* http://www.e-taxonomy.eu
|
17
|
*/
|
18
|
require_once ('xml2json.php');
|
19
|
require_once ('uuids.php');
|
20
|
|
21
|
|
22
|
|
23
|
|
24
|
/**
|
25
|
* Implementation of hook_requirements()
|
26
|
*/
|
27
|
function cdm_api_requirements() {
|
28
|
|
29
|
$requirements['cdm_api'] = array(
|
30
|
'title' => t('CDM API')
|
31
|
);
|
32
|
|
33
|
if( function_exists('curl_init') ){
|
34
|
$requirements['cdm_api']['description'] = ''; // description below title is not jet in use
|
35
|
$requirements['cdm_api']['value'] = 'CURL php extension is available.';
|
36
|
} else {
|
37
|
$requirements['cdm_api']['value'] = 'CURL php extension is missing.';
|
38
|
}
|
39
|
|
40
|
//FIXME: once _get_content_fsockopen is implemented change severity to REQUIREMENT_WARNING,
|
41
|
$requirements['cdm_api']['severity'] = (function_exists('curl_init') ? REQUIREMENT_OK : REQUIREMENT_ERROR);
|
42
|
|
43
|
return $requirements;
|
44
|
}
|
45
|
|
46
|
|
47
|
/**
|
48
|
* Implementation of hook_menu()
|
49
|
*/
|
50
|
function cdm_api_menu($may_cache) {
|
51
|
$items = array();
|
52
|
if ($may_cache) {
|
53
|
$items[] = array(
|
54
|
// usage: url('cdm_api/proxy/'.urlencode($content_url)."/$theme");
|
55
|
'path' => 'cdm_api/proxy',
|
56
|
'callback' => 'proxy_content',
|
57
|
'access' => true,
|
58
|
'type' => MENU_CALLBACK,
|
59
|
);
|
60
|
}
|
61
|
|
62
|
return $items;
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* Configures the settings forfm for the CDM-API module.
|
67
|
*
|
68
|
* @return Array Drupal settings form
|
69
|
*/
|
70
|
function cdm_api_settings_form(){
|
71
|
|
72
|
$form['cdm_webservice'] = array(
|
73
|
'#type' => 'fieldset',
|
74
|
'#title' => t('CDM Web Service'),
|
75
|
'#collapsible' => FALSE,
|
76
|
'#collapsed' => FALSE,
|
77
|
);
|
78
|
|
79
|
$form['cdm_webservice']['cdm_webservice_url'] = array(
|
80
|
'#type' => 'textfield',
|
81
|
'#title' => t('CDM Web Service URL'),
|
82
|
'#description' => t('The URL of CDM Webservice which delivers the data to be published.'),
|
83
|
'#default_value' => variable_get('cdm_webservice_url', 'http://dev.e-taxonomy.eu/svn/trunk/drupal/modules/cdm_dataportal/cdm_api/ws_stub/'),
|
84
|
);
|
85
|
|
86
|
$form['cdm_webservice']['cdm_webservice_isStub'] = array(
|
87
|
'#type' => 'checkbox',
|
88
|
'#title' => t('Use Web Service Stub'),
|
89
|
'#default_value' => variable_get('cdm_webservice_isStub', 1),
|
90
|
'#description' => t('Use a static web service stub. Only for development. For further information please refer to the ')
|
91
|
.l('ws_stub/README.txt', 'http://dev.e-taxonomy.eu/svn/trunk/drupal/modules/cdm_dataportal/cdm/ws_stub/README.txt', array('target'=>'_blank')),
|
92
|
);
|
93
|
|
94
|
|
95
|
$form['cdm_webservice']['cdm_webservice_type'] = array(
|
96
|
'#type' => 'select',
|
97
|
'#title' => t('Web Service Type'),
|
98
|
'#default_value' => variable_get('cdm_webservice_type', 'json'),
|
99
|
'#options' => array(
|
100
|
'xml' => t('XML'),
|
101
|
'json' => t('JSON'),
|
102
|
),
|
103
|
'#description' => t('The response data type of the web service.'),
|
104
|
);
|
105
|
|
106
|
$form['cdm_webservice']['cdm_webservice_cache'] = array(
|
107
|
'#type' => 'checkbox',
|
108
|
'#title' => t('Enable Caching'),
|
109
|
'#default_value' => variable_get('cdm_webservice_cache', 1),
|
110
|
'#description' => t('Enable caching of webservice responses on simple requests, '
|
111
|
.'that is requests which only have one parameter generally a UUID or a concatenation of UUIDs')
|
112
|
);
|
113
|
|
114
|
$form['cdm_webservice']['proxy'] = array(
|
115
|
'#type' => 'fieldset',
|
116
|
'#title' => t('Proxy'),
|
117
|
'#collapsible' => TRUE,
|
118
|
'#collapsed' => TRUE
|
119
|
);
|
120
|
|
121
|
$form['cdm_webservice']['proxy']['cdm_webservice_proxy_url'] = array(
|
122
|
'#type' => 'textfield',
|
123
|
'#title' => t('Proxy URL'),
|
124
|
'#description' => t('If this proxy url is set the cdm api tries
|
125
|
to connect the web service over the given proxy server.
|
126
|
Otherwise proxy usage is deactivated.'),
|
127
|
'#default_value' => variable_get('cdm_webservice_proxy_url', false),
|
128
|
);
|
129
|
|
130
|
$form['cdm_webservice']['proxy']['cdm_webservice_proxy_port'] = array(
|
131
|
'#type' => 'textfield',
|
132
|
'#title' => t('Proxy Port'),
|
133
|
'#default_value' => variable_get('cdm_webservice_proxy_port', '80'),
|
134
|
);
|
135
|
|
136
|
$form['cdm_webservice']['proxy']['cdm_webservice_proxy_usr'] = array(
|
137
|
'#type' => 'textfield',
|
138
|
'#title' => t('Login'),
|
139
|
'#default_value' => variable_get('cdm_webservice_proxy_usr', false),
|
140
|
);
|
141
|
|
142
|
$form['cdm_webservice']['proxy']['cdm_webservice_proxy_pwd'] = array(
|
143
|
'#type' => 'textfield',
|
144
|
'#title' => t('Password'),
|
145
|
'#default_value' => variable_get('cdm_webservice_proxy_pwd', false),
|
146
|
);
|
147
|
|
148
|
$form['cdm_webservice']['cdm_webservice_debug'] = array(
|
149
|
'#type' => 'checkbox',
|
150
|
'#title' => t('Debug CDM Web Service'),
|
151
|
'#default_value' => variable_get('cdm_webservice_debug', 1),
|
152
|
'#description' => t('Enable CDM Web Service debugging messages. Only visible for administrators!')
|
153
|
);
|
154
|
|
155
|
return $form;
|
156
|
}
|
157
|
|
158
|
/**
|
159
|
* Implementation of hook_cron().
|
160
|
*
|
161
|
* Expire outdated cache entries
|
162
|
*/
|
163
|
function cdm_api_cron() {
|
164
|
cache_clear_all(NULL, 'cache_cdm_ws');
|
165
|
}
|
166
|
|
167
|
|
168
|
// ----------------------------------------------------------- //
|
169
|
|
170
|
|
171
|
/**
|
172
|
* Converts an array of TagedText items into a sequence of corresponding html tags whereas
|
173
|
* each item will provided with a class attribute which set to the key of the TaggedText item.
|
174
|
*
|
175
|
* @param array $taggedtxt
|
176
|
* @param String $tag
|
177
|
* @param String $glue the string by which the chained text tokens are concatenated together.
|
178
|
* Default is a blank character
|
179
|
* @return String of HTML
|
180
|
*/
|
181
|
function cdm_taggedtext2html(array &$taggedtxt, $tag = 'span', $glue = ' ', $skiptags = array()){
|
182
|
$out = '';
|
183
|
$i = 0;
|
184
|
foreach($taggedtxt as $tt){
|
185
|
if(!in_array($tt->type, $skiptags) && strlen($tt->text) > 0){
|
186
|
$out .= (strlen($out) > 0 && ++$i < count($taggedtxt)? $glue : '').'<'.$tag.' class="'.$tt->type.'">'.t($tt->text).'</'.$tag.'>';
|
187
|
}
|
188
|
}
|
189
|
return $out;
|
190
|
}
|
191
|
|
192
|
/**
|
193
|
* Finds the text tagged with $$tag_type in an array of taggedText instances
|
194
|
*
|
195
|
* @param array $taggedtxt
|
196
|
* @param string $tag_type
|
197
|
* @return the text mapped by $tag_type or an empty string
|
198
|
*/
|
199
|
function cdm_taggedtext_value(array &$taggedtxt = array(), $tag_type){
|
200
|
foreach($taggedtxt as $tagtxt){
|
201
|
if($tagtxt->type == $tag_type)
|
202
|
return $tagtxt->text;
|
203
|
}
|
204
|
return '';
|
205
|
}
|
206
|
|
207
|
/**
|
208
|
* media Array [4]
|
209
|
* representations Array [3]
|
210
|
* mimeType image/jpeg
|
211
|
* representationParts Array [1]
|
212
|
* duration 0
|
213
|
* heigth 0
|
214
|
* size 0
|
215
|
* uri http://wp5.e-taxonomy.eu/dataportal/cichorieae/media/protolog/jpeg/Acanthocephalus_p1.jpg
|
216
|
* uuid 15c687f1-f79d-4b79-992f-7ba0f55e610b
|
217
|
* width 0
|
218
|
* suffix jpg
|
219
|
* uuid 930b7d51-e7b6-4350-b21e-8124b14fe29b
|
220
|
* title
|
221
|
* uuid 17e514f1-7a8e-4daa-87ea-8f13f8742cf9
|
222
|
*
|
223
|
* @param unknown_type $mediaTO
|
224
|
* @param array $mimeTypes
|
225
|
* @param unknown_type $width
|
226
|
* @param unknown_type $height
|
227
|
* @return unknown
|
228
|
*/
|
229
|
function cdm_preferred_media_representations($mediaTO, array $mimeTypes, $width = 400, $height = 300){
|
230
|
/**
|
231
|
|
232
|
*
|
233
|
*/
|
234
|
$prefRepr = array();
|
235
|
if(!isset($mediaTO->representations[0])){
|
236
|
return $prefRepr;
|
237
|
}
|
238
|
|
239
|
while(count($mimeTypes) > 0){
|
240
|
// getRepresentationByMimeType
|
241
|
$mimeType = array_shift($mimeTypes);
|
242
|
foreach($mediaTO->representations as $representationTO){
|
243
|
if($representationTO->mimeType == $mimeType){
|
244
|
// preffered mimetype found -> erase all remaining mimetypes to end loop
|
245
|
$mimeTypes = array();
|
246
|
$dwa = 0;
|
247
|
// look for part with the best matching size
|
248
|
foreach($representationTO->representationParts as $part){
|
249
|
$dw = $part->width * $part->height - $height * $width;
|
250
|
if($dw < 0){
|
251
|
$dw *= -1;
|
252
|
}
|
253
|
$dwa+= $dw;
|
254
|
}
|
255
|
$dwa = (count($representationTO->representationParts)>0) ? $dwa / count($representationTO->representationParts) : 0;
|
256
|
$prefRepr[$dwa.'_'.$mimeTypeKey] = $representationTO;
|
257
|
}
|
258
|
}
|
259
|
}
|
260
|
// sort
|
261
|
krsort($prefRepr);
|
262
|
// return
|
263
|
return $prefRepr;
|
264
|
}
|
265
|
|
266
|
|
267
|
/**
|
268
|
* Produces a path to a static web service stub out of a cdm web service path.
|
269
|
* These stubs are object serialisations stored in files whereas the filename
|
270
|
* consists of the service name and of a
|
271
|
* encoded version of the request query parameters
|
272
|
*
|
273
|
* @param string $path
|
274
|
* @param string $fileExtension
|
275
|
* @return string
|
276
|
*/
|
277
|
function cdm_encode_stub($path, $fileExtension, $hasParams = false){
|
278
|
$path = str_replace('/',',',$path);
|
279
|
if($hasParams){
|
280
|
$path = str_replace('?',',',$path);
|
281
|
$path = str_replace('&',',',$path);
|
282
|
}
|
283
|
return variable_get('cdm_webservice_type', 'xml').'/'.$path.'.'.$fileExtension;
|
284
|
}
|
285
|
|
286
|
|
287
|
function cdm_compose_url($ws_name, $parameters = array()){
|
288
|
|
289
|
$request_params = '';
|
290
|
$path_params = '';
|
291
|
if(!is_array($parameters)){
|
292
|
// add to path
|
293
|
$path_params .= '/'.( is_string($parameters) ? urlencode($parameters) : $parameters);
|
294
|
}else{
|
295
|
foreach($parameters as $key=>$value){
|
296
|
if(is_numeric($key)){
|
297
|
// add to path
|
298
|
$path_params .= '/'.( is_string($value) ? urlencode($value) : $value);
|
299
|
} else {
|
300
|
// add to parameters
|
301
|
$request_params .= ( strlen($request_params) == 0 ? '?' : '&').$key.'='.( is_string($value) ? urlencode($value) : $value);
|
302
|
}
|
303
|
}
|
304
|
}
|
305
|
$path = $ws_name.$path_params.$request_params;
|
306
|
|
307
|
if(variable_get('cdm_webservice_isStub', 0)){
|
308
|
$path = cdm_encode_stub($path, variable_get('cdm_webservice_type', 'json'), strlen($request_params) > 0);
|
309
|
}
|
310
|
|
311
|
$url = variable_get('cdm_webservice_url', '').$path;
|
312
|
return $url;
|
313
|
}
|
314
|
|
315
|
|
316
|
function proxy_content($url, $theme = null){
|
317
|
|
318
|
$args = func_get_args();
|
319
|
|
320
|
$url = array_shift($args);
|
321
|
$theme = array_shift($args);
|
322
|
|
323
|
$request_method = strtoupper($_SERVER["REQUEST_METHOD"]);
|
324
|
|
325
|
if($request_method == "POST"){
|
326
|
|
327
|
$parameters = $_POST;
|
328
|
|
329
|
$post_data = array();
|
330
|
foreach ($parameters as $k=>$v)
|
331
|
{
|
332
|
$post_data[] = "$k=".utf8_encode($v);
|
333
|
}
|
334
|
$post_data = implode(',', $post_data);
|
335
|
|
336
|
// testing
|
337
|
$data = request_content(urldecode($url), "POST", $post_data);
|
338
|
print $data;
|
339
|
|
340
|
}else{
|
341
|
// in all other cases perform a simple get request
|
342
|
//TODO reconsider caching logic in this function
|
343
|
if(!$theme){
|
344
|
// print out JSON, the cache cannot be used since it contains objects
|
345
|
$data = request_content(urldecode($url));
|
346
|
print $data;
|
347
|
} else {
|
348
|
$obj = cdm_ws_load(urldecode($url), false);
|
349
|
array_unshift($args, $theme, $obj);
|
350
|
print call_user_func_array('theme', $args);
|
351
|
}
|
352
|
}
|
353
|
|
354
|
|
355
|
}
|
356
|
|
357
|
|
358
|
/**
|
359
|
* Enter description here...
|
360
|
*
|
361
|
* @param unknown_type $method
|
362
|
* @param $parameters may be an array or a single variable
|
363
|
* @return unknown
|
364
|
*/
|
365
|
function cdm_ws_get($method, $parameters = array()){
|
366
|
/*$args = func_get_args();
|
367
|
$method = array_shift($args);
|
368
|
*/
|
369
|
/*if(isset($args[0]) && is_array($args[0])){
|
370
|
$url = cdm_compose_url_parametrised($method, $args[0]);
|
371
|
} else {
|
372
|
*/
|
373
|
$url = cdm_compose_url($method, $parameters);
|
374
|
//}
|
375
|
return cdm_ws_load($url, (is_array($parameters)));
|
376
|
}
|
377
|
|
378
|
/**
|
379
|
* Loads the XML or JSON response for the given url from the CDM Data Store Webservice.
|
380
|
* The XML is turned into a object which is returned.
|
381
|
*
|
382
|
* @param String $url the relative url of the web service call.
|
383
|
* Relative means relative to the web service base url which is stored in cdm_webservice_url
|
384
|
* @return An object or false
|
385
|
*/
|
386
|
function cdm_ws_load($url, $is_multi_paramater_query, $method="GET"){
|
387
|
|
388
|
$do_cache = !$is_multi_paramater_query && variable_get('cdm_webservice_cache', 0) && $method == "GET";
|
389
|
$cache_entry = false;
|
390
|
|
391
|
// append the default featureTree to url string
|
392
|
// this might be conflicting with caching.
|
393
|
$concatenator = strpos($url, '?') ? '&' : '?';
|
394
|
|
395
|
$ftree = variable_get('cdm_dataportal_feature_tree_active', false);
|
396
|
|
397
|
$url .= ($ftree && strpos($url, '/taxon/')) ? $concatenator . "ftree=" . $ftree : '';
|
398
|
|
399
|
if($do_cache){
|
400
|
// try to get object from cache
|
401
|
$cache_entry = cache_get($url, 'cache_cdm_ws');
|
402
|
}
|
403
|
|
404
|
if(!$cache_entry){
|
405
|
// load fresh data from webservice
|
406
|
$time_get_start = microtime(true);
|
407
|
// request data from webservice JSON or XML
|
408
|
$datastr = request_content($url, $method);
|
409
|
$time_get = microtime(true) - $time_get_start;
|
410
|
/*if(TRUE){
|
411
|
$storef = urlencode($url);
|
412
|
drupal_set_message($storef);
|
413
|
file_save_data($datastr, $storef, FILE_EXISTS_REPLACE);
|
414
|
}*/
|
415
|
|
416
|
$time_parse_start = microtime(true);
|
417
|
// parse data and create object
|
418
|
$obj = cdm_load_obj($datastr);
|
419
|
$time_parse = microtime(true) - $time_parse_start;
|
420
|
if(variable_get('cdm_webservice_debug', 1) && user_access('administer')){
|
421
|
$success_msg = $obj?'valid':'invalid';
|
422
|
drupal_set_message(
|
423
|
$url.' [fetched in: '.sprintf('%3.3f', $time_get).'s; '
|
424
|
.'parsed in '.sprintf('%3.3f', $time_parse).' s;'
|
425
|
.' size:'.sprintf('%3.1f', (strlen($datastr) / 1024)).' kb of '
|
426
|
.l($success_msg.' data', 'cdm_api/proxy/'.urlencode($url), array('target'=>'json-data', 'class'=>$success_msg)).'] '.$json_data_link
|
427
|
, 'debug');
|
428
|
}
|
429
|
if( !$obj || !$datastr){
|
430
|
watchdog('CDM', 'cdm_ws_load() - URL: '.$url, WATCHDOG_ERROR);
|
431
|
} else if($do_cache) {
|
432
|
// store fresh data in cache
|
433
|
cache_set($url, 'cache_cdm_ws', serialize($obj), CACHE_TEMPORARY);
|
434
|
}
|
435
|
} else {
|
436
|
$obj = unserialize($cache_entry->data);
|
437
|
if(variable_get('cdm_webservice_debug', 1) && user_access('administer')){
|
438
|
drupal_set_message('Using cache for: '.$url, 'debug');
|
439
|
}
|
440
|
}
|
441
|
return $obj;
|
442
|
}
|
443
|
|
444
|
|
445
|
function cdm_load_obj($datastr){
|
446
|
|
447
|
// if the web service delivers XML convert it into json
|
448
|
if(variable_get('cdm_webservice_type', 'xml') == 'xml'){
|
449
|
$datastr = xml2json::transformXmlStringToJson($datastr);
|
450
|
}
|
451
|
$use_stub = variable_get('cdm_webservice_isStub', 0);
|
452
|
if($use_stub){
|
453
|
// --- for STUBS use the more syntax tolerant PEAR json lib --- //
|
454
|
$json_pear = new Services_JSON();
|
455
|
$obj = $json_pear->decode($datastr);
|
456
|
} else {
|
457
|
// --- generally use the fast php json lib --- //
|
458
|
$obj = json_decode($datastr);
|
459
|
}
|
460
|
|
461
|
if(!(is_object($obj) || is_array($obj)) || ($use_stub && !isset($obj->root)) ){
|
462
|
ob_start();
|
463
|
var_dump($obj);
|
464
|
$obj_dump = ob_get_contents();
|
465
|
ob_clean();
|
466
|
watchdog('CDM', 'cdm_load_obj() - invalid object: '.$obj_dump, WATCHDOG_ERROR);
|
467
|
return false;
|
468
|
}
|
469
|
|
470
|
if($use_stub){
|
471
|
$arr = (array)$obj;
|
472
|
$obj = array_pop($arr);
|
473
|
}
|
474
|
return $obj;
|
475
|
}
|
476
|
|
477
|
|
478
|
|
479
|
|
480
|
function request_content($url, $method="GET", $parameters = array()){
|
481
|
global $locale; // drupal variable containing the current locale i.e. language
|
482
|
static $header;
|
483
|
|
484
|
if(!$header){
|
485
|
$header = array();
|
486
|
$header[] = 'Accept: '.(variable_get('cdm_webservice_type', 'json') == 'json' ? 'application/json' : 'text/xml');
|
487
|
$header[] = 'Accept-Language: '.$locale;
|
488
|
$header[] = 'Accept-Charset: UTF8';
|
489
|
}
|
490
|
|
491
|
if(function_exists('curl_init')){
|
492
|
|
493
|
// use the CURL lib if installed it is supposed to be 20x faster
|
494
|
return _request_content_curl($url, $header, $method, $parameters);
|
495
|
} else {
|
496
|
return _request_content_fsockopen($url, $header, $method, $parameters);
|
497
|
}
|
498
|
}
|
499
|
|
500
|
|
501
|
function _request_content_fsockopen($url, $header = array(), $method = "GET"){
|
502
|
//FIXME implement get_content_fsockopen($url);
|
503
|
watchdog('CDM_API', '_request_content_fsockopen - UNIMPLEMENTED', WATCHDOG_ERROR);
|
504
|
return false;
|
505
|
}
|
506
|
|
507
|
|
508
|
/**
|
509
|
* Return string content from a remote file
|
510
|
*
|
511
|
* @param string $url
|
512
|
* @return string
|
513
|
*
|
514
|
* @author Luiz Miguel Axcar (lmaxcar@yahoo.com.br)
|
515
|
*/
|
516
|
function _request_content_curl($url, $header = array(), $method = "GET", $parameters = array())
|
517
|
{
|
518
|
$ch = curl_init();
|
519
|
|
520
|
curl_setopt ($ch, CURLOPT_URL, $url);
|
521
|
// set proxy settings
|
522
|
if(variable_get('cdm_webservice_proxy_url', false)){
|
523
|
curl_setopt($ch, CURLOPT_PROXY, variable_get('cdm_webservice_proxy_url', ''));
|
524
|
curl_setopt($ch, CURLOPT_PROXYPORT, variable_get('cdm_webservice_proxy_port', '80'));
|
525
|
if(variable_get('cdm_webservice_proxy_usr', false)){
|
526
|
curl_setopt ($ch, CURLOPT_PROXYUSERPWD, variable_get('cdm_webservice_proxy_usr', '').':'.variable_get('cdm_webservice_proxy_pwd', ''));
|
527
|
}
|
528
|
}
|
529
|
// set headers
|
530
|
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
|
531
|
// set method if not default
|
532
|
if($method != "GET"){
|
533
|
if($method == "POST"){
|
534
|
|
535
|
curl_setopt ($ch, CURLOPT_POST, 1);
|
536
|
curl_setopt ($ch, CURLOPT_POSTFIELDS, $parameters);
|
537
|
|
538
|
}else{
|
539
|
// other obscure http methods get passed to curl directly
|
540
|
// TODO generic parameter/body handling
|
541
|
curl_setopt ($ch, CURLOPT_CUSTOMREQUEST, $method);
|
542
|
}
|
543
|
}
|
544
|
|
545
|
|
546
|
ob_start();
|
547
|
curl_exec ($ch);
|
548
|
if(curl_errno($ch)){
|
549
|
watchdog('CDM_API', '_request_content_curl() - '.curl_error($ch).' REQUEST-METHOD:'.$method.' URL: '.$url, WATCHDOG_ERROR);
|
550
|
if(variable_get('cdm_webservice_debug', 1) && user_access('administer') ){
|
551
|
drupal_set_message('_request_content_curl() - '.curl_error($ch).' REQUEST-METHOD:'.$method.' URL: '.$url, 'error');
|
552
|
}
|
553
|
}
|
554
|
curl_close ($ch);
|
555
|
$string = ob_get_contents();
|
556
|
ob_end_clean();
|
557
|
|
558
|
return $string;
|
559
|
}
|
560
|
|
561
|
function cdm_api_secref_cache_prefetch(&$secUuids){
|
562
|
global $secref_cache;
|
563
|
if(!is_array($secref_cache)){
|
564
|
$secref_cache = array();
|
565
|
}
|
566
|
$uniqueUuids = array_unique($secUuids);
|
567
|
$i = 0;
|
568
|
$param = '';
|
569
|
while($i++ < count($uniqueUuids)){
|
570
|
$param .= $secUuids[$i].',';
|
571
|
if(strlen($param) + 37 > 2000){
|
572
|
_cdm_api_secref_cache_add($param);
|
573
|
$param = '';
|
574
|
}
|
575
|
}
|
576
|
if($param){
|
577
|
_cdm_api_secref_cache_add($param);
|
578
|
}
|
579
|
}
|
580
|
|
581
|
function cdm_api_secref_cache_get($secUuid){
|
582
|
global $secref_cache;
|
583
|
if(!is_array($secref_cache)){
|
584
|
$secref_cache = array();
|
585
|
}
|
586
|
if(!array_key_exists($secUuid, $secref_cache)){
|
587
|
_cdm_api_secref_cache_add($secUuid);
|
588
|
}
|
589
|
return $secref_cache[$secUuid];
|
590
|
}
|
591
|
|
592
|
function cdm_api_secref_cache_clear(){
|
593
|
global $secref_cache;
|
594
|
$secref_cache = array();
|
595
|
}
|
596
|
|
597
|
function _cdm_api_secref_cache_add($secUuidsStr){
|
598
|
global $secref_cache;
|
599
|
$refSTOs = cdm_ws_get(CDM_WS_SIMPLE_REFERENCE, $secUuidsStr);
|
600
|
$assocRefSTOs = array();
|
601
|
if($refSTOs) {
|
602
|
foreach($refSTOs as $ref){
|
603
|
$assocRefSTOs[$ref->uuid] = $ref;
|
604
|
}
|
605
|
$secref_cache = array_merge($secref_cache, $assocRefSTOs);
|
606
|
}
|
607
|
}
|
608
|
|
609
|
/**
|
610
|
* Web Service Arguments: {Uuid}
|
611
|
*
|
612
|
* The whatis service returns the type
|
613
|
* i.e. DTO class name and simplename & cdm class name and simplename of the instance referenced by the $uuid parameter.
|
614
|
*
|
615
|
* return: false if the cdm store contains no matching instance.
|
616
|
* An associative array with the following key-value pairs:
|
617
|
* - 'cdmName': name of the cdm class as returned by Class.getName(), e.g. eu.etaxonomy.cdm.model.taxon.Taxon
|
618
|
* - 'cdmSimpleName': simple name of the cdm class as returned by Class.getSimpleName(), e.g. Taxon
|
619
|
* - 'dtoName': name of the DTO class as returned by Class.getName(), e.g. eu.etaxonomy.cdm.dto.TaxonTO
|
620
|
* - 'dtoSimpleName': simple name of the TDO class as returned by Class.getSimpleName(), e.g. TaxonTO
|
621
|
*/
|
622
|
define('CDM_WS_WHATIS', 'whatis');
|
623
|
|
624
|
|
625
|
/**
|
626
|
* Web Service Arguments: {NameUuid}
|
627
|
*/
|
628
|
define('CDM_WS_NAME', 'name');
|
629
|
|
630
|
/**
|
631
|
* Web Service url parameters:
|
632
|
* - [last path element]: querystring
|
633
|
* - sec : list of reference base uuid of concept references
|
634
|
* - higherTaxa : list of taxon uuid, if higherTaxa are defined only taxa which are includet in one these taxa are taken in to account
|
635
|
* - matchAnywhere : false (default) match the querystring to the beginning of names, if set to true any matching substring is taken as a hit.
|
636
|
* - onlyAccepted : return only taxa which are accepted in the sence of the concept reference as given by parameter sec
|
637
|
* - pagesize : maximum number of iteme per result page
|
638
|
* - page: the number of page to be returned
|
639
|
*
|
640
|
* returns ResultPageSTO
|
641
|
*/
|
642
|
define('CDM_WS_FIND_TAXA', 'find/taxon');
|
643
|
|
644
|
/**
|
645
|
* Web Service Arguments: {referenceUuid}
|
646
|
*
|
647
|
*/
|
648
|
define('CDM_WS_REFERENCE', 'reference');
|
649
|
|
650
|
/**
|
651
|
* Web Service Arguments: {pageNumber}
|
652
|
*
|
653
|
*/
|
654
|
define('CDM_WS_REFERENCE_LIST', 'reference/list');
|
655
|
|
656
|
/**
|
657
|
* Web Service Arguments: {referenceUuid} or array of {referenceUuid}
|
658
|
*
|
659
|
* returns a list of ReferenceSTO
|
660
|
*/
|
661
|
define('CDM_WS_SIMPLE_REFERENCE', 'simple/reference');
|
662
|
|
663
|
/**
|
664
|
* Web Service Arguments: {taxonUuid}
|
665
|
*/
|
666
|
define('CDM_WS_TAXON', 'taxon');
|
667
|
|
668
|
|
669
|
/**
|
670
|
* Web Service Arguments: {taxonUuid} or array of {referenceUuid}
|
671
|
*
|
672
|
* returns a list of TaxonSTO
|
673
|
*/
|
674
|
define('CDM_WS_SIMPLE_TAXON', 'simple/taxon');
|
675
|
|
676
|
/**
|
677
|
* Web Service Arguments: {nameUuid}
|
678
|
*
|
679
|
* returns a set of type designation which are assigned to the name given
|
680
|
* as parameter. The Set may contain {@link NameTypeDesignationSTO}
|
681
|
* and {@link SpecimenTypeDesignationSTO}
|
682
|
*/
|
683
|
define('CDM_WS_TYPE_DESIGNATIONS', 'types');
|
684
|
|
685
|
/**
|
686
|
* Web Service Arguments: {taxonUuid}
|
687
|
*
|
688
|
* returns the taxon which is the accepted synonym for the taxon given as
|
689
|
* parameter taxonUuid. If the taxon specified by taxonUuid is itself the
|
690
|
* accepted taxon, this one will be returned.
|
691
|
*/
|
692
|
define('CDM_WS_ACCEPTED_TAXON', 'simple/taxon/acceptedfor');
|
693
|
|
694
|
/**
|
695
|
* Web Service Arguments: {secUuid}
|
696
|
*
|
697
|
* Gets the root nodes of the taxonomic concept tree for the concept
|
698
|
* reference specified by the secUuid parameter.
|
699
|
*
|
700
|
* stub: treenode_root
|
701
|
*/
|
702
|
define('CDM_WS_TREENODE_ROOT', 'taxonomy/root');
|
703
|
|
704
|
/**
|
705
|
* Web Service Arguments: {taxonUuid}
|
706
|
*
|
707
|
* Searches the concept taxon tree for all parent taxa by walking the tree
|
708
|
* from the taxon which is referenced by the parameter taxonUuid down to its
|
709
|
* root. The reference taxon will also be included into the returned set of
|
710
|
* TreeNode instances.
|
711
|
*
|
712
|
* stub: treenode_parents
|
713
|
*/
|
714
|
define('CDM_WS_TREENODE_PARENTS', 'taxonomy/parents');
|
715
|
|
716
|
/**
|
717
|
* Web Service Arguments: {taxonUuid}
|
718
|
*
|
719
|
* returns the children of the taxon referenced by the parameter
|
720
|
* taxonUuid.
|
721
|
*
|
722
|
* stub: treenode_children
|
723
|
*/
|
724
|
define('CDM_WS_TREENODE_CHILDREN', 'taxonomy/children');
|
725
|
|
726
|
/**
|
727
|
* returns all features available in this community store
|
728
|
*
|
729
|
*/
|
730
|
define('CDM_WS_FEATURES', 'features');
|
731
|
|
732
|
/**
|
733
|
* returns FeatureTrees that are stored in this community store
|
734
|
*
|
735
|
*/
|
736
|
define('CDM_WS_FEATURETREES', 'features/tree');
|
737
|
|
738
|
|
739
|
/**
|
740
|
* Web Service Arguments: {CdmObjUuid}
|
741
|
*
|
742
|
* Either retrieves or writes annotations to any annotatable entity
|
743
|
*/
|
744
|
define('CDM_WS_ANNOTATIONS', 'annotations');
|
745
|
|