$folder = dirname($documentQueryParameter);
     if ($folder == ".") {
         $folder = PccConfig::getDocumentsPath();
     } else {
         $folder = $folder . "/";
     }
     $document = Utils::combine($folder, $filename);
 }
 $extension = pathinfo($document, PATHINFO_EXTENSION);
 $correctPath = PccConfig::isFileSafeToOpen($document);
 if (!$correctPath) {
     header('HTTP/1.0 403 Forbidden');
     echo '<h1>403 Forbidden</h1>';
     return;
 }
 $acsApiKey = PccConfig::getApiKey();
 // Set viewing session properties using JSON.
 $data = array('externalId' => Utils::getHashString($document), 'tenantId' => 'My User ID', 'origin' => array('ipAddress' => $_SERVER['REMOTE_ADDR'], 'hostName' => $_SERVER['REMOTE_HOST'], 'sourceDocument' => $document), 'render' => array('flash' => array('optimizationLevel' => 1), 'html5' => array('alwaysUseRaster' => false)));
 $options = array('http' => array('method' => 'POST', 'header' => "Content-Type: application/json\r\n" . "Accept: application/json\r\n" . "Acs-Api-Key: {$acsApiKey}\r\n" . "Accusoft-Affinity-Hint: {$document}\r\n", 'content' => json_encode($data)));
 // Request a new viewing session from PCCIS.
 //   POST http://localhost:18681/PCCIS/V1/ViewingSession
 //
 $url = PccConfig::getImagingService() . "/ViewingSession";
 $context = stream_context_create($options);
 $result = file_get_contents($url, false, $context);
 $response = json_decode($result);
 // Store the ID for this viewing session that is returned by PCCIS.
 $viewingSessionId = $response->viewingSessionId;
 if ((strstr($documentQueryParameter, "http://") || strstr($document, "https://")) && Utils::url_exists($document) || file_exists($document)) {
     // Open document to upload.
     $fileHandle = fopen($document, "rb");
 function processRequest($matches)
 {
     // Verify that the request type is acceptable.
     if (!is_null($this->requestTypeWhiteList)) {
         $requestIsAcceptable = false;
         foreach ($this->requestTypeWhiteList as $requestType) {
             if ($_SERVER['REQUEST_METHOD'] == $requestType) {
                 $requestIsAcceptable = true;
                 break;
             }
         }
         if (!$requestIsAcceptable) {
             throw new Exception("The request type is not acceptable.");
         }
     }
     $imagingServiceUri = PccConfig::getImagingService() . $_SERVER['PATH_INFO'];
     // Add only the white-listed query parameters to the outgoing request.
     $queryParameters = "";
     if (!is_null($this->queryParameterWhiteList)) {
         foreach ($this->queryParameterWhiteList as $key) {
             $data = $_GET[$key];
             if (!is_null($data)) {
                 if (!empty($queryParameters)) {
                     $queryParameters .= "&";
                 }
                 $queryParameters .= $key . '=' . urlencode($data);
             }
         }
     }
     if (!empty($queryParameters)) {
         $imagingServiceUri .= '?' . $queryParameters;
     }
     // Add only the white-listed request header items to the outgoing request.
     $headerList = '';
     $body = '';
     if (!is_null($this->requestHeaderWhiteList)) {
         foreach ($this->requestHeaderWhiteList as $key) {
             $data = $_SERVER[$key];
             if (!is_null($data)) {
                 $headerList = "{$headerList}{$key}: {$data}\r\n";
             }
         }
     }
     $acsApiKey = PccConfig::getApiKey();
     $headerList = "{$headerList}Acs-Api-Key: {$acsApiKey}\r\n";
     if ($_SERVER['REQUEST_METHOD'] == 'POST' || $_SERVER['REQUEST_METHOD'] == 'PUT') {
         $body = @file_get_contents('php://input');
     }
     $options = array('http' => array('method' => $_SERVER['REQUEST_METHOD'], 'header' => $headerList, 'content' => $body));
     $context = stream_context_create($options);
     $result = file_get_contents($imagingServiceUri, false, $context);
     // Retrieve HTTP status code
     list($version, $status_code, $msg) = explode(' ', $http_response_header[0], 3);
     // Add only the white-listed response header items to the response (plus the status code)
     if ($status_code == 0) {
         // The imaging service currently returns 0 status sometimes.
         $status_code = 200;
     }
     header("{$version} {$status_code} {$msg}");
     if (!is_null($this->responseHeaderWhiteList)) {
         foreach ($this->responseHeaderWhiteList as $key) {
             foreach ($http_response_header as $value) {
                 if (preg_match("/^{$key}:/i", $value)) {
                     // Successful match
                     header($value, TRUE);
                 }
             }
         }
     }
     // Return the body of the response only if it did not fail.
     if ($status_code == 200) {
         echo $result;
     }
 }
Example #3
0
function listMarkupJson($matches)
{
    $annotationFiles = array('annotationFiles' => array());
    header("Content-Type: application/json");
    $viewingSessionId = $_GET['DocumentID'];
    // Call PCCIS
    $url = PccConfig::getImagingService() . "/ViewingSession/" . urlencode($viewingSessionId);
    $acsApiKey = PccConfig::getApiKey();
    $options = array('http' => array('method' => 'GET', 'header' => "Accept: application/json\r\n" . "Acs-Api-Key: {$acsApiKey}\r\n"));
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    $response = json_decode($result);
    if ($result === 0 || !$response->externalId || !strlen($response->externalId)) {
        header("HTTP/1.1 500 Internal Server Error");
    } else {
        $path2Save = PccConfig::getMarkupsPath();
        $i = 1;
        $fileList = glob($path2Save . '*.xml');
        foreach ($fileList as $file) {
            if (stristr($file, $response->externalId . '_' . $response->attachmentIndex) == TRUE) {
                $nameParts = explode('.', array_pop(explode('_', basename($file))));
                $name = substr($nameParts[0], 1);
                $annotationFiles['annotationFiles'][] = array('annotationLabel' => $name, 'annotationName' => basename($file), 'ID' => (string) $i++);
            }
        }
    }
    echo json_encode($annotationFiles);
    flush();
}