public function LingotekSession::download in Lingotek Translation 7.3
Same name and namespace in other branches
- 6 lingotek.session.inc \LingotekSession::download()
- 7.2 lingotek.session.inc \LingotekSession::download()
- 7.4 lingotek.session.inc \LingotekSession::download()
Downloads a document from Lingotek.
Parameters
$api: Name of the api to call
$params: Key/value pairs to call as parameters in the api
Return value
Location of the file, or FALSE on error.
File
- ./
lingotek.session.inc, line 151 - Handles api calls, logging in and logging out of LingoTek
Class
Code
public function download($api, $params) {
$result = LingotekApi::instance()
->request($api, $params);
if (!$result) {
LingotekLog::error('Unable to download Lingotek Document.');
return FALSE;
}
$tmpFile = tempnam(file_directory_temp(), "lingotek");
$fp = fopen($tmpFile, 'w');
fwrite($fp, $result);
fclose($fp);
$text = "";
$file = FALSE;
//downloadDocument zips the file up
if ($api == 'downloadDocument') {
$zip = new ZipArchive();
$zip
->open($tmpFile);
$name = $zip
->getNameIndex(0);
$file = $zip
->getStream($name);
}
else {
$file = fopen($tmpFile, "r");
}
if ($file) {
while (!feof($file)) {
$text .= fread($file, 2);
}
}
fclose($file);
unlink($tmpFile);
return $text;
}