Subversion Repositories Sites.tela-botanica.org

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
480 jpm 1
<?php
2
/**
3
 * $Id: tapir.php 575 2008-03-28 20:52:13Z rdg $
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
118
if (! ini_get('safe_mode') ) {
119
	set_time_limit( TP_MAX_RUNTIME );
120
}
121
 
122
// Debugging
123
if ( ! defined( '_DEBUG' ) )
124
{
125
    // Load the value from a request variable called "debug", default is false
126
    // for security reasons
127
    if ( TP_ALLOW_DEBUG )
128
    {
129
        define( '_DEBUG', (bool)TpUtils::GetVar( 'debug', false ) );
130
    }
131
    else
132
    {
133
        define( '_DEBUG', false );
134
    }
135
}
136
 
137
// Instantiate request object
138
$request = new TpRequest();
139
 
140
// If no resource was specified in the request URI, then dump some help information
141
if ( ! $request->ExtractResourceCode() )
142
{
143
   include_once( 'index.php' );
144
   die();
145
}
146
 
147
// Get resource code and check if it's valid
148
$resource_code = $request->GetResourceCode();
149
 
150
$r_resources =& TpResources::GetInstance();
151
 
152
$raise_errors = false;
153
$r_resource =& $r_resources->GetResource( $resource_code, $raise_errors );
154
 
155
if ( $r_resource == null )
156
{
157
    $response = new TpResponse( $request );
158
    $response->ReturnError( 'Resource "'.$resource_code.'" not found.' );
159
    die();
160
}
161
 
162
$r_resources->SetCurrentResourceCode( $resource_code );
163
 
164
if ( $r_resource->GetStatus() != 'active' )
165
{
166
    $response = new TpResponse( $request );
167
    $response->ReturnError( 'Resource "'.$resource_code.'" is not active.' );
168
    die();
169
}
170
 
171
// Check PHP version
172
$current_version = phpversion();
173
 
174
if ( version_compare( $current_version, '5.0', '<' ) > 0 )
175
{
176
    if ( version_compare( $current_version, TP_MIN_PHP_VERSION, '<' ) > 0 )
177
    {
178
        $msg = 'PHP Version '.TP_MIN_PHP_VERSION.' or later required. '.
179
               'Some features may not be available. Detected version '.$current_version;
180
        TpDiagnostics::Append( DC_VERSION_MISMATCH, $msg, DIAG_WARN );
181
    }
182
}
183
else if ( version_compare( $current_version, '6.0', '<' ) > 0 )
184
{
185
    if ( version_compare( $current_version, '5.0.3', '<' ) > 0 )
186
    {
187
        // Avoid bug in "xml_set_start_namespace_decl_handler"
188
        $msg = 'Provider error: Unsupported PHP version ('.$current_version.'). To '.
189
               'use PHP5 it is necessary to have at least version 5.0.3';
190
 
191
        $response = new TpResponse( $request );
192
        $response->ReturnError( $msg );
193
        die();
194
    }
195
}
196
 
197
// Get parameters
198
if ( ! $request->InitializeParameters() or
199
     TpDiagnostics::Count( array( DIAG_ERROR, DIAG_FATAL ) ) )
200
{
201
    $response = new TpResponse( $request );
202
    $response->ReturnError( 'Failed to parse request' );
203
    die();
204
}
205
 
206
$operation = $request->GetOperation();
207
 
208
if ( $operation == 'ping' )
209
{
210
    require_once('TpPingResponse.php');
211
 
212
    $response = new TpPingResponse( $request );
213
}
214
else if ( $operation == 'capabilities' )
215
{
216
    require_once('TpCapabilitiesResponse.php');
217
 
218
    $response = new TpCapabilitiesResponse( $request );
219
}
220
else if ( $operation == 'metadata' )
221
{
222
    require_once('TpMetadataResponse.php');
223
 
224
    $response = new TpMetadataResponse( $request );
225
}
226
else if ( $operation == 'inventory' )
227
{
228
    require_once('TpInventoryResponse.php');
229
 
230
    $response = new TpInventoryResponse( $request );
231
}
232
else if ( $operation == 'search' )
233
{
234
    require_once('TpSearchResponse.php');
235
 
236
    $response = new TpSearchResponse( $request );
237
}
238
else
239
{
240
    // Unknown operation
241
    $response = new TpResponse( $request );
242
    $response->ReturnError( 'Unknown operation "'.$operation.'"' );
243
    die();
244
}
245
 
246
$response->Process();
247
 
248
exit();
249
 
250
?>