public static function renderTemplate($template, $data = array()) { $email = array('from' => null, 'subject' => null, 'body' => trim(\Emergence\Dwoo\Engine::getSource($template . '.email', $data))); $templateVars = \Emergence\Dwoo\Engine::getInstance()->scope; if (isset($templateVars['from'])) { $email['from'] = trim(preg_replace('/\\s+/', ' ', $templateVars['from'])); } if (isset($templateVars['subject'])) { $email['subject'] = trim(preg_replace('/\\s+/', ' ', $templateVars['subject'])); } return $email; }
public static function respondPdf($responseId, array $responseData = []) { if (!empty($_REQUEST['downloadToken'])) { setcookie('downloadToken', $_REQUEST['downloadToken'], time() + 300, '/'); } $tmpPath = tempnam('/tmp', 'e_pdf_'); file_put_contents($tmpPath . '.html', \Emergence\Dwoo\Engine::getSource("{$responseId}.pdf", $responseData)); header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="' . str_replace('"', '', $responseId) . '.pdf"'); exec("/usr/local/bin/wkhtmltopdf \"{$tmpPath}.html\" \"{$tmpPath}.pdf\""); if (!file_exists("{$tmpPath}.pdf")) { header('HTTP/1.0 501 Not Implemented'); die('Unable to generate PDF, check that this system has wkhtmltopdf installed'); } readfile($tmpPath . '.pdf'); exit; }