1: | <?php |
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | namespace Aurora\Modules\MailSaveMessageAsPdfPlugin; |
9: | |
10: | |
11: | |
12: | |
13: | |
14: | |
15: | |
16: | |
17: | class Module extends \Aurora\System\Module\AbstractModule |
18: | { |
19: | |
20: | |
21: | |
22: | |
23: | |
24: | public function init() |
25: | { |
26: | $this->aErrors = [ |
27: | Enums\ErrorCodes::LibraryNoFound => $this->i18N('ERROR_NO_PDF_GENERATOR_FOUND'), |
28: | ]; |
29: | } |
30: | |
31: | |
32: | |
33: | |
34: | |
35: | |
36: | public function GeneratePdfFile($UserId, $FileName, $Html) |
37: | { |
38: | \Aurora\System\Api::checkUserRoleIsAtLeast(\Aurora\System\Enums\UserRole::NormalUser); |
39: | |
40: | $sFileName = $FileName . '.pdf'; |
41: | |
42: | $sUUID = \Aurora\System\Api::getUserUUIDById($UserId); |
43: | $sTempName = md5($sUUID.$sFileName.microtime(true)); |
44: | |
45: | $sExec = \Aurora\System\Api::DataPath().'/system/wkhtmltopdf/linux/wkhtmltopdf'; |
46: | if (!\file_exists($sExec)) { |
47: | $sExec = \Aurora\System\Api::DataPath().'/system/wkhtmltopdf/win/wkhtmltopdf.exe'; |
48: | if (!\file_exists($sExec)) { |
49: | $sExec = ''; |
50: | } |
51: | } |
52: | |
53: | if (0 < \strlen($sExec)) { |
54: | $oSnappy = new \Knp\Snappy\Pdf($sExec); |
55: | $oSnappy->setOption('quiet', true); |
56: | $oSnappy->setOption('disable-javascript', true); |
57: | $oSnappy->setOption('encoding', 'utf-8'); |
58: | |
59: | $oApiFileCache = new \Aurora\System\Managers\Filecache(); |
60: | |
61: | $oSnappy->generateFromHtml( |
62: | $Html, |
63: | $oApiFileCache->generateFullFilePath($sUUID, $sTempName, '', self::GetName()), |
64: | array(), |
65: | true |
66: | ); |
67: | |
68: | return \Aurora\System\Utils::GetClientFileResponse( |
69: | self::GetName(), |
70: | $UserId, |
71: | $sFileName, |
72: | $sTempName, |
73: | $oApiFileCache->fileSize($sUUID, $sTempName, '', self::GetName()) |
74: | ); |
75: | } else { |
76: | throw new \Aurora\System\Exceptions\ApiException(Enums\ErrorCodes::LibraryNoFound); |
77: | } |
78: | |
79: | return false; |
80: | } |
81: | } |
82: | |