Commit 45b2e9a7 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Html2Pdf.php: implemented session forwarding to wkhtmltopdf.

parent 790fa271
......@@ -12,6 +12,7 @@
namespace qfq;
require_once(__DIR__ . '/../store/Config.php');
require_once(__DIR__ . '/../store/Session.php');
require_once(__DIR__ . '/../Constants.php');
require_once(__DIR__ . '/../helper/KeyValueStringParser.php');
......@@ -23,6 +24,11 @@ class Html2Pdf {
*/
private $config = array();
/**
* @var \qfq\Session
*/
private $session = null;
/**
* Read QFQ config. Only SYSTEM_BASE_URL_PRINT and SYSTEM_WKHTMLTOPDF will be used.
* Check and get all clean _GET Parameter. Build a URL based on SYSTEM_BASE_URL_PRINT and the delivered URL params.
......@@ -52,6 +58,11 @@ class Html2Pdf {
if (!is_executable($config[SYSTEM_WKHTMLTOPDF])) {
throw new \exception(CONFIG_INI . ' - ' . SYSTEM_WKHTMLTOPDF . '=' . $config[SYSTEM_WKHTMLTOPDF] . ' - not found or not executable.');
}
$urlParts = parse_url($config[SYSTEM_BASE_URL_PRINT]);
$this->session = Session::getInstance();
}
/**
......@@ -85,6 +96,23 @@ class Html2Pdf {
header("Content-Transfer-Encoding: binary");
}
/**
* @return string
*/
private function wkhtmlSessionCookies() {
$result = '';
$cookieNames = array_keys($_COOKIE);
foreach ($cookieNames as $name) {
if (isset($_COOKIE[$name])) {
$result .= " --cookie '" . $name . "' '" . urlencode($_COOKIE[$name]) . "'";
}
}
return trim($result);
}
/**
* Converts a Webpage (URL) to a PDF file.
* The URL might be a local Typo3 page (without hostname, starting with the parameter) or a full URL.
......@@ -144,7 +172,10 @@ class Html2Pdf {
$filename = tempnam(sys_get_temp_dir(), DOWNLOAD_FILE_PREFIX);
$filenameEscape = escapeshellarg($filename);
$cmd = "$wkhtmlToPdf $options $urlPrint $filenameEscape";
$cookieOptions = $this->wkhtmlSessionCookies();
$this->session->close();
$cmd = "$wkhtmlToPdf $cookieOptions $options $urlPrint $filenameEscape > /tmp/wk.out 2>&1";
$rc = 0;
$line = system($cmd, $rc);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment