Project

General

Profile

Download (3.46 KB) Statistics
| Branch: | Tag: | Revision:
1 f333122a Andreas Kohlbecker
<?php
2 35e7398c Andreas Kohlbecker
// $Id$
3 f333122a Andreas Kohlbecker
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
/**
15 47a8c0dd Andreas Kohlbecker
 * Converts an array of TagedText items into a sequence of corresponding html tags whereas 
16
 * each item will provided with a class attribute which set to the key of the TaggedText item.
17 f333122a Andreas Kohlbecker
 *
18 47a8c0dd Andreas Kohlbecker
 * @param TaggedText $tag
19
 * @return String of HTML 
20 f333122a Andreas Kohlbecker
 */
21
function cdm_taggedtext2html(array $taggedText, $tag = 'span'){
22
   foreach($taggedText as $class=>$value){
23
     $out .= '<'.$tag.' class="'.$class.'">'.$value.'</ '.$tag.'>';
24
   }
25
   return $out;
26
}
27
28 d946105e Andreas Kohlbecker
/**
29
 * @return string
30
 * @param string $url
31
 * @desc Return string content from a remote file
32
 * @author Luiz Miguel Axcar (lmaxcar@yahoo.com.br)
33
*/
34
function get_content($url)
35
{
36
    $ch = curl_init();
37
38
    curl_setopt ($ch, CURLOPT_URL, $url);
39
    curl_setopt ($ch, CURLOPT_HEADER, 0);
40
41
    ob_start();
42
43
    curl_exec ($ch);
44
    curl_close ($ch);
45
    $string = ob_get_contents();
46
47
    ob_end_clean();
48
   
49
    return $string;    
50
}
51
52 1bc28c7e Andreas Kohlbecker
/**
53
 * Loads the XML response for the given url from the CDM Data Store Webservice.
54
 * The XML is turned into a object wich is retuned. Incase of an error a 
55
 * approriate watchdog message is generated and the function returns false.
56
 * 
57 bf910101 Andreas Kohlbecker
 * //TODO are we going to support JSON services ?
58 1bc28c7e Andreas Kohlbecker
 *
59
 * @param String $url the relative url of the web service call. 
60
 *        Relative means relative to the web service base url which is stored in cdm_webservice_url
61
 * @return An object or false
62
 */
63
function cdm_ws_load($url){
64
65 d946105e Andreas Kohlbecker
  if(variable_get('cdm_webservice_isStub', 0)){
66 b96baf70 Andreas Kohlbecker
    $url = urlencode(urlencode($url)).'.xml';
67 d946105e Andreas Kohlbecker
  }
68 b96baf70 Andreas Kohlbecker
  $url = variable_get('cdm_webservice_url', '').$url;
69 d946105e Andreas Kohlbecker
  //TODO get_content() requires the php curl extension to be installed, maybe we should chose an other function
70
  $data = get_content($url);
71
  
72 b96baf70 Andreas Kohlbecker
  $obj = simplexml_load_string($data);
73 d946105e Andreas Kohlbecker
  
74 1bc28c7e Andreas Kohlbecker
  if(!$obj){
75
    $backtrace = debug_backtrace();
76
    watchdog('CDM', $backtrace[1]['function'].' - failed to load '.$url, WATCHDOG_ERROR);
77
  }
78 d946105e Andreas Kohlbecker
  $obj->ws_url = $url;
79 b96baf70 Andreas Kohlbecker
  $obj->data = $data;
80 d946105e Andreas Kohlbecker
  
81 1bc28c7e Andreas Kohlbecker
  return $obj;
82
}
83
84 d946105e Andreas Kohlbecker
85 35e7398c Andreas Kohlbecker
/**
86
 * The whatis service returns the type 
87
 * i.e. DTO class name and simplename & cdm class name and simplename of the instance referenced by the $uuid parameter. 
88
 * 
89
 *
90
 * @param unknown_type $uuid
91 bf910101 Andreas Kohlbecker
 * @return false if the cdm store contains no matching instance. 
92
 * An associative array with the following key-value pairs:
93 1bc28c7e Andreas Kohlbecker
 *   - 'cdmName':       name of the cdm class as returned by Class.getName(), e.g. eu.etaxonomy.cdm.model.taxon.Taxon
94
 *   - 'cdmSimpleName': simple name of the cdm class as returned by Class.getSimpleName(), e.g. Taxon
95
 *   - 'dtoName':       name of the DTO class as returned by Class.getName(), e.g. eu.etaxonomy.cdm.dto.TaxonTO
96
 *   - 'dtoSimpleName': simple name of the TDO class as returned by Class.getSimpleName(), e.g. TaxonTO
97 35e7398c Andreas Kohlbecker
 */
98
function cdm_ws_whatis($uuid){
99 1bc28c7e Andreas Kohlbecker
  return cdm_ws_load("whatis/?uuid=$uuid");
100 35e7398c Andreas Kohlbecker
}
101
102 f333122a Andreas Kohlbecker
/**
103
 * load a name from the CDM Webservice
104
 *
105
 * @param String $uuid
106
 * @return a NameTO instance or false 
107
 */
108 bf910101 Andreas Kohlbecker
function cdm_ws_get_name($uuid){
109 1bc28c7e Andreas Kohlbecker
  return cdm_ws_load("name/?uuid=$uuid");
110 f333122a Andreas Kohlbecker
}
111
112
/**
113
 * load a list of names from the CDM Webservice
114
 *
115
 * @param unknown_type $page
116
 * @param unknown_type $hide_unaccepted
117
 */
118 47a8c0dd Andreas Kohlbecker
function cdm_ws_name_list($page = 1, $onlyAccepted){
119 f333122a Andreas Kohlbecker
   
120
}