Project

General

Profile

Download (3.46 KB) Statistics
| Branch: | Tag: | Revision:
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
/**
15
 * 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
 *
18
 * @param TaggedText $tag
19
 * @return String of HTML 
20
 */
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
/**
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
/**
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
 * //TODO are we going to support JSON services ?
58
 *
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
  if(variable_get('cdm_webservice_isStub', 0)){
66
    $url = urlencode(urlencode($url)).'.xml';
67
  }
68
  $url = variable_get('cdm_webservice_url', '').$url;
69
  //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
  $obj = simplexml_load_string($data);
73
  
74
  if(!$obj){
75
    $backtrace = debug_backtrace();
76
    watchdog('CDM', $backtrace[1]['function'].' - failed to load '.$url, WATCHDOG_ERROR);
77
  }
78
  $obj->ws_url = $url;
79
  $obj->data = $data;
80
  
81
  return $obj;
82
}
83

    
84

    
85
/**
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
 * @return false if the cdm store contains no matching instance. 
92
 * An associative array with the following key-value pairs:
93
 *   - '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
 */
98
function cdm_ws_whatis($uuid){
99
  return cdm_ws_load("whatis/?uuid=$uuid");
100
}
101

    
102
/**
103
 * load a name from the CDM Webservice
104
 *
105
 * @param String $uuid
106
 * @return a NameTO instance or false 
107
 */
108
function cdm_ws_get_name($uuid){
109
  return cdm_ws_load("name/?uuid=$uuid");
110
}
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
function cdm_ws_name_list($page = 1, $onlyAccepted){
119
   
120
}
    (1-1/1)