Beispiel #1
0
function getDocEditorValidateKey($fileUri)
{
    return GenerateValidateKey(getDocEditorKey($fileUri));
}
Beispiel #2
0
/**
* Request for conversion to a service
*
* @param string $document_uri            Uri for the document to convert
* @param string $from_extension          Document extension
* @param string $to_extension            Extension to which to convert
* @param string $document_revision_id    Key for caching on service
* @param bool   $is_async                Perform conversions asynchronously
*
* @return Xml document request result of conversion
*/
function SendRequestToConvertService($document_uri, $from_extension, $to_extension, $document_revision_id, $is_async)
{
    if (empty($from_extension)) {
        $path_parts = pathinfo($document_uri);
        $from_extension = $path_parts['extension'];
    }
    $title = basename($document_uri);
    if (empty($title)) {
        $title = guid();
    }
    if (empty($document_revision_id)) {
        $document_revision_id = $document_uri;
    }
    $document_revision_id = GenerateRevisionId($document_revision_id);
    $validateKey = GenerateValidateKey($document_revision_id, false);
    $urlToConverter = generateUrlToConverter($document_uri, $from_extension, $to_extension, $title, $document_revision_id, $validateKey, $is_async);
    $response_xml_data;
    $countTry = 0;
    $opts = array('http' => array('method' => 'GET', 'timeout' => $GLOBALS['DOC_SERV_TIMEOUT']));
    if (substr($urlToConverter, 0, strlen("https")) === "https") {
        $opts['ssl'] = array('verify_peer' => FALSE);
    }
    $context = stream_context_create($opts);
    while ($countTry < ServiceConverterMaxTry) {
        $countTry = $countTry + 1;
        $response_xml_data = file_get_contents($urlToConverter, FALSE, $context);
        if ($response_xml_data !== false) {
            break;
        }
    }
    if ($countTry == ServiceConverterMaxTry) {
        throw new Exception("Bad Request or timeout error");
    }
    libxml_use_internal_errors(true);
    $data = simplexml_load_string($response_xml_data);
    if (!$data) {
        $exc = "Bad Response. Errors: ";
        foreach (libxml_get_errors() as $error) {
            $exc = $exc . "\t" . $error->message;
        }
        throw new Exception($exc);
    }
    return $data;
}