Subversion Repositories Sites.tela-botanica.org

Rev

Rev 480 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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