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