Subversion Repositories Sites.tela-botanica.org

Rev

Rev 480 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 480 Rev 592
1
<?php
1
<?php
2
/**
2
/**
3
 * $Id: tapir.php 575 2008-03-28 20:52:13Z rdg $
3
 * $Id: tapir.php 1953 2009-01-05 19:59:53Z rdg $
4
 * 
4
 * 
5
 * LICENSE INFORMATION
5
 * LICENSE INFORMATION
6
 * 
6
 * 
7
 * This program is free software; you can redistribute it and/or
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
10
 * of the License, or (at your option) any later version.
11
 * 
11
 * 
12
 * This program is distributed in the hope that it will be useful,
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU General Public License for more details:
15
 * GNU General Public License for more details:
16
 * 
16
 * 
17
 * http://www.gnu.org/copyleft/gpl.html
17
 * http://www.gnu.org/copyleft/gpl.html
18
 * 
18
 * 
19
 * 
19
 * 
20
 * @author Renato De Giovanni <renato [at] cria . org . br>
20
 * @author Renato De Giovanni <renato [at] cria . org . br>
21
 * @author Dave Vieglais (Biodiversity Research Center, University of Kansas)
21
 * @author Dave Vieglais (Biodiversity Research Center, University of Kansas)
22
 * 
22
 * 
23
 * ACKNOWLEDGEMENTS
23
 * ACKNOWLEDGEMENTS
24
 * 
24
 * 
25
 * TapirLink has been generously funded by the Biodiversity 
25
 * TapirLink has been generously funded by the Biodiversity 
26
 * Information Standards, TDWG, with resources from the Gordon and 
26
 * Information Standards, TDWG, with resources from the Gordon and 
27
 * Betty Moore Foundation. The Global Biodiversity Information 
27
 * Betty Moore Foundation. The Global Biodiversity Information 
28
 * Facility, GBIF, has also been a major supporter of the TAPIR 
28
 * Facility, GBIF, has also been a major supporter of the TAPIR 
29
 * initiative since its very beginning and also collaborated to 
29
 * initiative since its very beginning and also collaborated to 
30
 * test this software.
30
 * test this software.
31
 *
31
 *
32
 * TapirLink was based on the DiGIR PHP provider, which was 
32
 * TapirLink was based on the DiGIR PHP provider, which was 
33
 * originally developed by Dave Vieglais from the Biodiversity 
33
 * originally developed by Dave Vieglais from the Biodiversity 
34
 * Research Center, University of Kansas. The software is now being 
34
 * Research Center, University of Kansas. The software is now being 
35
 * distributed under the GPL with permission from its original
35
 * distributed under the GPL with permission from its original
36
 * author. The original copyright information is also 
36
 * author. The original copyright information is also 
37
 * reproduced below.
37
 * reproduced below.
38
 * 
38
 * 
39
 * --------------------------------
39
 * --------------------------------
40
 * 
40
 * 
41
 * Copyright (c) 2002 The University of Kansas Natural History 
41
 * Copyright (c) 2002 The University of Kansas Natural History 
42
 * Museum and Biodiversity Research Center. All rights reserved.
42
 * Museum and Biodiversity Research Center. All rights reserved.
43
 * 
43
 * 
44
 * Permission is hereby granted, free of charge, to any person 
44
 * Permission is hereby granted, free of charge, to any person 
45
 * obtaining a copy of this software and associated documentation 
45
 * obtaining a copy of this software and associated documentation 
46
 * files (the "Software"), to deal with the Software without 
46
 * files (the "Software"), to deal with the Software without 
47
 * restriction, including without limitation the rights to use, 
47
 * restriction, including without limitation the rights to use, 
48
 * copy, modify, merge, publish, distribute, sublicense, and/or 
48
 * copy, modify, merge, publish, distribute, sublicense, and/or 
49
 * sell copies of the Software, and to permit persons to whom the 
49
 * sell copies of the Software, and to permit persons to whom the 
50
 * Software is furnished to do so, subject to the following 
50
 * Software is furnished to do so, subject to the following 
51
 * conditions:
51
 * conditions:
52
 * 
52
 * 
53
 * - Redistributions of source code must retain the above copyright 
53
 * - Redistributions of source code must retain the above copyright 
54
 * notice, this list of conditions and the following disclaimers.
54
 * notice, this list of conditions and the following disclaimers.
55
 * 
55
 * 
56
 * - Redistributions in binary form must reproduce the above 
56
 * - Redistributions in binary form must reproduce the above 
57
 * copyright notice, this list of conditions and the following 
57
 * copyright notice, this list of conditions and the following 
58
 * disclaimers in the documentation and/or other materials provided 
58
 * disclaimers in the documentation and/or other materials provided 
59
 * with the distribution.
59
 * with the distribution.
60
 * 
60
 * 
61
 * - Neither the names of The University of Kansas Natural History 
61
 * - Neither the names of The University of Kansas Natural History 
62
 * Museum and Biodiversity Research Center, The University of Kansas 
62
 * Museum and Biodiversity Research Center, The University of Kansas 
63
 * at Lawrence, nor the names of its contributors may be used to 
63
 * at Lawrence, nor the names of its contributors may be used to 
64
 * endorse or promote products derived from this Software without 
64
 * endorse or promote products derived from this Software without 
65
 * specific prior written permission.
65
 * specific prior written permission.
66
 * 
66
 * 
67
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
67
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
68
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
68
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
69
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
69
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
70
 * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT 
70
 * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT 
71
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
71
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
72
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
72
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
73
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
73
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
74
 * DEALINGS IN THE SOFTWARE.
74
 * DEALINGS IN THE SOFTWARE.
75
 */
75
 */
76
 
76
 
77
// Definition of this constant can be used to indicate that
77
// Definition of this constant can be used to indicate that
78
// the Web Service (tapir.php) was called
78
// the Web Service (tapir.php) was called
79
define( 'TP_RUNNING_TAPIR', 1 );
79
define( 'TP_RUNNING_TAPIR', 1 );
80
 
80
 
81
require_once('tapir_globals.php');
81
require_once('tapir_globals.php');
82
require_once('TpUtils.php');
82
require_once('TpUtils.php');
83
require_once('TpServiceUtils.php');
83
require_once('TpServiceUtils.php');
84
require_once('TpDiagnostics.php');
84
require_once('TpDiagnostics.php');
85
require_once('TpResources.php');
85
require_once('TpResources.php');
86
require_once('TpRequest.php');
86
require_once('TpRequest.php');
87
require_once('TpResponse.php');
87
require_once('TpResponse.php');
88
 
88
 
89
// Register a new error handler
89
// Register a new error handler
90
$old_error_handler = set_error_handler( 'TapirErrorHandler' );
90
$old_error_handler = set_error_handler( 'TapirErrorHandler' );
91
 
91
 
92
// Avoid HTML in errors
92
// Avoid HTML in errors
93
ini_set( 'html_errors', false );
93
ini_set( 'html_errors', false );
94
 
94
 
95
// Store timestamp for profiling
95
// Store timestamp for profiling
96
define( 'INITIAL_TIMESTAMP', TpUtils::MicrotimeFloat() );
96
define( 'INITIAL_TIMESTAMP', TpUtils::MicrotimeFloat() );
97
 
97
 
98
// Logs
98
// Logs
99
TpUtils::InitializeLogs();
99
TpUtils::InitializeLogs();
100
 
100
 
101
// Main logger
101
// Main logger
102
global $g_log;
102
global $g_log;
103
 
103
 
104
// Debug logger
104
// Debug logger
105
global $g_dlog;
105
global $g_dlog;
106
 
106
 
107
$g_dlog->debug( '[Starting debug log]' );
107
$g_dlog->debug( '[Starting debug log]' );
108
$g_dlog->debug( 'TapirLink version: '.TP_VERSION.' (revision '.TP_REVISION.')' );
108
$g_dlog->debug( 'TapirLink version: '.TP_VERSION.' (revision '.TP_REVISION.')' );
109
 
109
 
110
$request_uri = ( isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : 'null';
110
$request_uri = ( isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : 'null';
111
 
111
 
112
$g_dlog->debug( 'Request URI: '.$request_uri );
112
$g_dlog->debug( 'Request URI: '.$request_uri );
113
$g_dlog->debug( 'Include path: '.ini_get( 'include_path' ) );
113
$g_dlog->debug( 'Include path: '.ini_get( 'include_path' ) );
114
 
114
 
115
// Set the maximum script run time
115
// Set the maximum script run time
116
// Note: if php set safe mode is on then this can't be set from here, 
116
// Note: if php set safe mode is on then this can't be set from here, 
117
// and will need to be set in php.ini file
117
// and will need to be set in php.ini file
-
 
118
// Définit à 120 par TapirLink mis à 60 globalement pour Sequoia car safe_mode actif
118
if (! ini_get('safe_mode') ) {
119
if (! ini_get('safe_mode') ) {
119
	set_time_limit( TP_MAX_RUNTIME );
120
	set_time_limit( TP_MAX_RUNTIME );
120
}
121
}
121
 
122
 
122
// Debugging
123
// Debugging
123
if ( ! defined( '_DEBUG' ) )
124
if ( ! defined( '_DEBUG' ) )
124
{
125
{
125
    // Load the value from a request variable called "debug", default is false
126
    // Load the value from a request variable called "debug", default is false
126
    // for security reasons
127
    // for security reasons
127
    if ( TP_ALLOW_DEBUG )
128
    if ( TP_ALLOW_DEBUG )
128
    {
129
    {
129
        define( '_DEBUG', (bool)TpUtils::GetVar( 'debug', false ) );
130
        define( '_DEBUG', (bool)TpUtils::GetVar( 'debug', false ) );
130
    }
131
    }
131
    else
132
    else
132
    {
133
    {
133
        define( '_DEBUG', false );
134
        define( '_DEBUG', false );
134
    }
135
    }
135
}
136
}
136
 
137
 
137
// Instantiate request object
138
// Instantiate request object
138
$request = new TpRequest();
139
$request = new TpRequest();
139
 
140
 
140
// If no resource was specified in the request URI, then dump some help information
141
// If no resource was specified in the request URI, then dump some help information
141
if ( ! $request->ExtractResourceCode() )
142
if ( ! $request->ExtractResourceCode() )
142
{
143
{
143
   include_once( 'index.php' );
144
   include_once( 'index.php' );
144
   die();
145
   die();
145
}
146
}
146
 
147
 
147
// Get resource code and check if it's valid
148
// Get resource code and check if it's valid
148
$resource_code = $request->GetResourceCode();
149
$resource_code = $request->GetResourceCode();
149
 
150
 
150
$r_resources =& TpResources::GetInstance();
151
$r_resources =& TpResources::GetInstance();
151
 
152
 
152
$raise_errors = false;
153
$raise_errors = false;
153
$r_resource =& $r_resources->GetResource( $resource_code, $raise_errors );
154
$r_resource =& $r_resources->GetResource( $resource_code, $raise_errors );
154
 
155
 
155
if ( $r_resource == null )
156
if ( $r_resource == null )
156
{
157
{
157
    $response = new TpResponse( $request );
158
    $response = new TpResponse( $request );
158
    $response->ReturnError( 'Resource "'.$resource_code.'" not found.' );
159
    $response->ReturnError( 'Resource "'.$resource_code.'" not found.' );
159
    die();
160
    die();
160
}
161
}
161
 
162
 
162
$r_resources->SetCurrentResourceCode( $resource_code );
163
$r_resources->SetCurrentResourceCode( $resource_code );
163
 
164
 
164
if ( $r_resource->GetStatus() != 'active' )
165
if ( $r_resource->GetStatus() != 'active' )
165
{
166
{
166
    $response = new TpResponse( $request );
167
    $response = new TpResponse( $request );
167
    $response->ReturnError( 'Resource "'.$resource_code.'" is not active.' );
168
    $response->ReturnError( 'Resource "'.$resource_code.'" is not active.' );
168
    die();
169
    die();
169
}
170
}
170
 
171
 
171
// Check PHP version
172
// Check PHP version
172
$current_version = phpversion();
173
$current_version = phpversion();
173
 
174
 
174
if ( version_compare( $current_version, '5.0', '<' ) > 0 )
175
if ( version_compare( $current_version, '5.0', '<' ) > 0 )
175
{
176
{
176
    if ( version_compare( $current_version, TP_MIN_PHP_VERSION, '<' ) > 0 )
177
    if ( version_compare( $current_version, TP_MIN_PHP_VERSION, '<' ) > 0 )
177
    {
178
    {
178
        $msg = 'PHP Version '.TP_MIN_PHP_VERSION.' or later required. '.
179
        $msg = 'PHP Version '.TP_MIN_PHP_VERSION.' or later required. '.
179
               'Some features may not be available. Detected version '.$current_version;
180
               'Some features may not be available. Detected version '.$current_version;
180
        TpDiagnostics::Append( DC_VERSION_MISMATCH, $msg, DIAG_WARN );
181
        TpDiagnostics::Append( DC_VERSION_MISMATCH, $msg, DIAG_WARN );
181
    }
182
    }
182
}
183
}
183
else if ( version_compare( $current_version, '6.0', '<' ) > 0 )
184
else if ( version_compare( $current_version, '6.0', '<' ) > 0 )
184
{
185
{
185
    if ( version_compare( $current_version, '5.0.3', '<' ) > 0 )
186
    if ( version_compare( $current_version, '5.0.3', '<' ) > 0 )
186
    {
187
    {
187
        // Avoid bug in "xml_set_start_namespace_decl_handler"
188
        // Avoid bug in "xml_set_start_namespace_decl_handler"
188
        $msg = 'Provider error: Unsupported PHP version ('.$current_version.'). To '.
189
        $msg = 'Provider error: Unsupported PHP version ('.$current_version.'). To '.
189
               'use PHP5 it is necessary to have at least version 5.0.3';
190
               'use PHP5 it is necessary to have at least version 5.0.3';
190
 
191
 
191
        $response = new TpResponse( $request );
192
        $response = new TpResponse( $request );
192
        $response->ReturnError( $msg );
193
        $response->ReturnError( $msg );
193
        die();
194
        die();
194
    }
195
    }
195
}
196
}
196
 
197
 
197
// Get parameters
198
// Get parameters
198
if ( ! $request->InitializeParameters() or 
199
if ( ! $request->InitializeParameters() or 
199
     TpDiagnostics::Count( array( DIAG_ERROR, DIAG_FATAL ) ) )
200
     TpDiagnostics::Count( array( DIAG_ERROR, DIAG_FATAL ) ) )
200
{
201
{
201
    $response = new TpResponse( $request );
202
    $response = new TpResponse( $request );
202
    $response->ReturnError( 'Failed to parse request' );
203
    $response->ReturnError( 'Failed to parse request' );
203
    die();
204
    die();
204
}
205
}
-
 
206
 
-
 
207
// By default, assume that the database encoding cannot be detected 
-
 
208
// by the mb_detect_encoding PHP function
-
 
209
global $g_encoding_can_be_detected;
205
 
210
 
206
$operation = $request->GetOperation();
211
$operation = $request->GetOperation();
207
 
212
 
208
if ( $operation == 'ping' )
213
if ( $operation == 'ping' )
209
{
214
{
210
    require_once('TpPingResponse.php');
215
    require_once('TpPingResponse.php');
211
 
216
 
212
    $response = new TpPingResponse( $request );
217
    $response = new TpPingResponse( $request );
213
}
218
}
214
else if ( $operation == 'capabilities' )
219
else if ( $operation == 'capabilities' )
215
{
220
{
216
    require_once('TpCapabilitiesResponse.php');
221
    require_once('TpCapabilitiesResponse.php');
217
 
222
 
218
    $response = new TpCapabilitiesResponse( $request );
223
    $response = new TpCapabilitiesResponse( $request );
219
}
224
}
220
else if ( $operation == 'metadata' )
225
else if ( $operation == 'metadata' )
221
{
226
{
222
    require_once('TpMetadataResponse.php');
227
    require_once('TpMetadataResponse.php');
223
 
228
 
224
    $response = new TpMetadataResponse( $request );
229
    $response = new TpMetadataResponse( $request );
225
}
230
}
226
else if ( $operation == 'inventory' )
231
else if ( $operation == 'inventory' )
227
{
232
{
228
    require_once('TpInventoryResponse.php');
233
    require_once('TpInventoryResponse.php');
229
 
234
 
230
    $response = new TpInventoryResponse( $request );
235
    $response = new TpInventoryResponse( $request );
231
}
236
}
232
else if ( $operation == 'search' )
237
else if ( $operation == 'search' )
233
{
238
{
234
    require_once('TpSearchResponse.php');
239
    require_once('TpSearchResponse.php');
235
 
240
 
236
    $response = new TpSearchResponse( $request );
241
    $response = new TpSearchResponse( $request );
237
}
242
}
238
else
243
else
239
{
244
{
240
    // Unknown operation 
245
    // Unknown operation 
241
    $response = new TpResponse( $request );
246
    $response = new TpResponse( $request );
242
    $response->ReturnError( 'Unknown operation "'.$operation.'"' );
247
    $response->ReturnError( 'Unknown operation "'.$operation.'"' );
243
    die();
248
    die();
244
}
249
}
245
 
250
 
246
$response->Process();
251
$response->Process();
247
 
252
 
248
exit();
253
exit();
249
 
254
 
250
?>
255
?>