-
Notifications
You must be signed in to change notification settings - Fork 53
/
cif.php
82 lines (75 loc) · 1.88 KB
/
cif.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* This file is part of MolView (http://molview.org)
* Copyright (c) 2014, 2015 Herman Bergwerf
*
* MolView is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MolView is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with MolView. If not, see <http://www.gnu.org/licenses/>.
*/
/*
PHP script for mirroring CIF files form the Crystallography Open Database
@param codid
@return CIF file or HTTP error
*/
include_once("utility.php");
error_reporting(0);
parse_str($_SERVER["QUERY_STRING"]);
header("Content-Type: text");
//allow embed.molview.org
if($_SERVER["HTTP_ORIGIN"] == "http://embed.molview.org")
{
header("Access-Control-Allow-Origin: ".$_SERVER["HTTP_ORIGIN"]);
}
//connect to cod
$cod = new mysqli("www.crystallography.net", "cod_reader", "", "cod");
if($cod -> connect_errno > 0)
{
http_response_code(500);
echo "Internal Error";
return;
}
//lookup record in database
$query = 'SELECT flags FROM data WHERE file="'.$codid.'"';
if($row = $cod -> query($query) -> fetch_row())
{
$cod -> close();
if(strpos($row[0], "has coordinates") !== false)
{
//get cif
$cif = get_curl("http://www.crystallography.net/".$codid.".cif");
if($cif === false)
{
http_response_code(404);
echo "Not Found";
return;
}
else
{
echo $cif;
return;
}
}
else
{
http_response_code(404);
echo "Not Found";
return;
}
}
else
{
$cod -> close();
http_response_code(404);
echo "Not Found";
return;
}