| <?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| $myerror = "";
|
|
|
| function handleError($severity, $msg, $filename, $linenum) {
|
| global $myerror;
|
| switch($severity) {
|
| case E_ERROR:
|
| $myerror = "PHP error:$severity $msg $filename $linenum";
|
| break;
|
| }
|
| return true;
|
| }
|
|
|
| set_error_handler("handleError");
|
|
|
| function getValueSimple($json, $key, $default) {
|
| if ($json == "") {
|
| $val = $_REQUEST[$key];
|
| } else {
|
|
|
|
|
|
|
|
|
| list($junk,$info) = explode('"'.$key.'"', $json, 2);
|
| list($junk,$val) = explode('"', $info, 3);
|
| if ($val == "") {
|
| $val = str_replace('"','_',$_REQUEST[$key]);
|
| }
|
| }
|
| if ($val == "") {
|
| $val = $default;
|
| }
|
| return $val;
|
| }
|
|
|
| if ($_GET['isform']=="true") {
|
| $values = "";
|
| } else {
|
| $values= file_get_contents("php://input");
|
| }
|
| $encoding = getValueSimple($values, "encoding", "");
|
| $call = getValueSimple($values, "call", "getRawDataFromDatabase");
|
| $query = getValueSimple($values, "query", "https://cactus.nci.nih.gov/chemical/structure/ethanol/file?format=sdf&get3d=True");
|
| $database = getValueSimple($values, "database", "_");
|
| $test = getValueSimple($values,"test","");
|
| $imagedata = "";
|
| $contentType = "";
|
| $output = "";
|
| $isBinary = false;
|
| $filename = "";
|
|
|
| if ($call == "getInfoFromDatabase") {
|
|
|
| if ($database == '=') {
|
| $restQueryUrl = "http://www.rcsb.org/pdb/rest/search";
|
| $restReportUrl = "http://www.rcsb.org/pdb/rest/customReport";
|
| $xml = "<orgPdbQuery><queryType>org.pdb.query.simple.AdvancedKeywordQuery</queryType><description>Text Search</description><keywords>$query</keywords></orgPdbQuery>";
|
| $context = stream_context_create(array('http' => array(
|
| 'method' => 'POST',
|
| 'header' => 'Content-Type: application/x-www-form-urlencoded',
|
| 'content' => $xml))
|
| );
|
| $output = file_get_contents($restQueryUrl, false, $context);
|
| $n = strlen($output)/5;
|
| if ($n == 0) {
|
| $output = "ERROR: \"$query\" not found";
|
| } else {
|
| if (strlen($query) == 4 && $n != 1) {
|
| $QQQQ = strtoupper($query);
|
| if (strpos("123456789", substr($QQQQ, 0, 1)) == 0 && strpos($output, $QQQQ) > 0) {
|
| $output = "$QQQQ\n".$output.str_replace("$QQQQ\n", "",$output);
|
| }
|
| }
|
| if ($n > 50) {
|
| $output = substr($output, 0, 250);
|
| }
|
| $output = str_replace("\n",",",$output);
|
|
|
| $output = $restReportUrl."?pdbids=".$output."&customReportColumns=structureId,structureTitle";
|
| $output = "<result query=\"$query\" count=\"$n\">".file_get_contents($output)."</result>";
|
| }
|
| } else {
|
| $myerror = "jsmol.php cannot use $call with $database";
|
| }
|
|
|
| } else if ($call == "getRawDataFromDatabase") {
|
| $isBinary = (strpos($query, ".gz") >= 0);
|
| if ($database != "_")
|
| $query = $database.$query;
|
| if (strpos(strtolower($query), 'https://') !== 0 && strpos(strtolower($query), 'http://') !== 0) {
|
| $output = "invalid url";
|
| } else if (strpos($query, '?POST?') > 0) {
|
| list($query,$data) = explode('?POST?', $query, 2);
|
| $context = stream_context_create(array('http' => array(
|
| 'method' => 'POST',
|
| 'header' => 'Content-Type: application/x-www-form-urlencoded',
|
| 'content' => $data))
|
| );
|
| $output = file_get_contents($query, false, $context);
|
| } else {
|
| $output = file_get_contents($query);
|
| if ($test != "") {
|
| $output = $query."<br>".$output;
|
| }
|
| }
|
| } else if ($call == "saveFile") {
|
| $imagedata = $_REQUEST["data"];
|
| $filename = getValueSimple($values, "filename", "");
|
| $contentType = getValueSimple($values, "mimetype", "application/octet-stream");
|
| if ($encoding == "base64") {
|
| $imagedata = base64_decode($imagedata);
|
| $encoding = "";
|
| }
|
| } else {
|
| $myerror = "jsmol.php unrecognized call: $call";
|
| }
|
|
|
| ob_start();
|
|
|
| if ($myerror != "") {
|
| $output = $myerror;
|
| } else {
|
| if ($imagedata != "") {
|
| $output = $imagedata;
|
| header('Content-Type: '.$contentType);
|
| if ($filename != "") {
|
| header('Content-Description: File Transfer');
|
| header("Content-Disposition: attachment; filename=\"$filename\"");
|
| header('Content-Transfer-Encoding: binary');
|
| header('Expires: 0');
|
| header('Cache-Control: must-revalidate');
|
| header('Pragma: public');
|
| }
|
| } else {
|
| header('Access-Control-Allow-Origin: *');
|
| if ($isBinary) {
|
| header('Content-Type: text/plain; charset=x-user-defined');
|
| } else if (strpos($output, '<html') > 0) {
|
| header('Content-type: text/html; charset=utf-8');
|
| } else {
|
| header('Content-Type: application/json');
|
| }
|
| }
|
| if ($encoding == "base64") {
|
| $output = ";base64,".base64_encode($output);
|
| }
|
| }
|
| header('Last-Modified: '.date('r'));
|
| header('Accept-Ranges: bytes');
|
| header('Content-Length: '.strlen($output));
|
| echo($output);
|
| ob_end_flush();
|
| ?>
|
|
|
|
|