PluginProbe ʕ •ᴥ•ʔ
Event Tickets with Ticket Scanner / 2.7.0
Event Tickets with Ticket Scanner v2.7.0
3.1.2 3.1.1 3.1.0 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.4 trunk 2.6.0 2.7.0 2.7.1 2.7.10 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.10 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.0 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8 2.9.9 3.0.0 3.0.1 3.0.2 3.0.3
event-tickets-with-ticket-scanner / sasoEventtickets_PDF.php
event-tickets-with-ticket-scanner Last commit date
2.7.0 1 year ago 3rd 1 year ago css 1 year ago img 1 year ago languages 1 year ago ticket 1 year ago vendors 1 year ago SASO_EVENTTICKETS.php 1 year ago backend.js 1 year ago changelog.txt 1 year ago db.php 1 year ago index.php 1 year ago init_file.php 1 year ago js_seatingplan.js 1 year ago order_details.js 1 year ago readme.txt 1 year ago saso-eventtickets-validator.js 1 year ago sasoEventtickets_AdminSettings.php 1 year ago sasoEventtickets_Authtoken.php 1 year ago sasoEventtickets_Base.php 1 year ago sasoEventtickets_Core.php 1 year ago sasoEventtickets_Frontend.php 1 year ago sasoEventtickets_Messenger.php 1 year ago sasoEventtickets_Options.php 1 year ago sasoEventtickets_PDF.php 1 year ago sasoEventtickets_Ticket.php 1 year ago sasoEventtickets_TicketBadge.php 1 year ago sasoEventtickets_TicketDesigner.php 1 year ago sasoEventtickets_TicketQR.php 1 year ago ticket_events.js 1 year ago ticket_scanner.js 1 year ago validator.js 1 year ago wc_backend.js 1 year ago wc_frontend.js 1 year ago woocommerce-hooks.php 1 year ago
sasoEventtickets_PDF.php
411 lines
1 <?php
2 use setasign\Fpdi\Tcpdf\Fpdi;
3 include_once(plugin_dir_path(__FILE__)."init_file.php");
4 class sasoEventtickets_PDF {
5 private $parts = [];
6 private $filemode;
7 private $filepath;
8 private $filename;
9 private $orientation = "P";
10 private $page_format = 'A4';
11 private $isRTL = false;
12 private $languageArray = null;
13 private $background_image = null;
14 private $fontSize = 10;
15 private $fontFamily = "dejavusans";
16
17 private $is_own_page_format = false;
18 private $size_width = 210;
19 private $size_height = 297;
20 public $marginsZero = false;
21
22 private $attach_pdfs = [];
23
24 private $qr;
25 private $qr_values;
26
27 public function __construct($parts=[], $filemode="I", $filename="PDF.pdf") {
28 $this->qr_values = $this->getDefaultQRValues();
29 if (is_array($parts)) $this->setParts($parts);
30 $this->setFilemode($filemode);
31 $this->setFilename($filename);
32 $this->_loadLibs();
33 }
34
35 public function getPossibleFontFamiles() {
36 $ret = ["default"=>'dejavusans', "fonts"=>[]];
37 if ($handle = opendir(__DIR__.'/vendors/TCPDF/fonts')) {
38 while (false !== ($entry = readdir($handle))) {
39 if (pathinfo($entry, PATHINFO_EXTENSION) == "php") {
40 $ret["fonts"][] = substr($entry, 0, -4);
41 }
42 }
43 closedir($handle);
44 }
45 return $ret;
46 }
47
48 public function setAdditionalPDFsToAttachThem($pdfs) {
49 if (!is_array($pdfs)) {
50 $pdfs = [$pdfs];
51 }
52 $this->attach_pdfs = $pdfs;
53 }
54
55 public function setBackgroundImage($background_image=null) {
56 $this->background_image = $background_image;
57 }
58
59 public function setFontSize($number=10) {
60 $this->fontSize = intval($number);
61 }
62
63 public function convertPixelIntoMm($pixels, $dpi=96) {
64 if ($dpi < 1) $dpi = 96;
65 return $pixels * 25.4 / $dpi;
66 }
67
68 private function getDefaultQRValues() {
69 return [
70 'pos'=>['x'=>150, 'y'=>10],
71 'size'=>['width'=>50, 'height'=>50],
72 "type"=>"QRCODE,Q",
73 'style'=>[
74 'position'=>'R',
75 //'align'=>'C',
76 'border' => 0,
77 'vpadding' => 0,//'auto',
78 'hpadding' => 0,//'auto',
79 'fgcolor' => array(0,0,0),
80 //'bgcolor' => false, //array(255,255,255)
81 'bgcolor' => array(255,255,255),
82 'module_width' => 1, // width of a single module in points
83 'module_height' => 1 // height of a single module in points
84 ],
85 'align'=>'C'
86 ];
87 }
88
89 public function setQRParams($data) {
90 foreach ($data as $key => $value) {
91 if (is_array($value)) {
92 $this->qr_values[$key] = array_merge($this->qr_values[$key], $value);
93 } else {
94 $this->qr_values[$key] = $value;
95 }
96 }
97 }
98
99 public function setFontFamily($fontFamily="dejavusans") {
100 $this->fontFamily = trim($fontFamily);
101 }
102
103 public function initQR() {
104 $this->qr = array_merge(["text"=>""], $this->qr_values);
105 }
106
107 public function setSize($w, $h) {
108 $this->is_own_page_format = true;
109 $this->size_width = intval($w);
110 $this->size_height = intval($h);
111 }
112 public function setRTL($rtl=false) {
113 $this->isRTL = $rtl;
114 }
115 public function isRTL() {
116 return $this->isRTL;
117 }
118 public function setLanguageArray($a) {
119 $this->languageArray = $a;
120 }
121 public function setQRCodeContent($qr) {
122 if ($this->qr == null) {
123 $this->initQR();
124 }
125 foreach ($qr as $key => $value) {
126 if (is_array($this->qr[$key]) && is_array($value)) {
127 $this->qr[$key] = array_merge($this->qr[$key], $value);
128 } else {
129 $this->qr[$key] = $value;
130 }
131 }
132 }
133 public function setPageFormat($format) {
134 $this->page_format = trim($format);
135 }
136 public function setOrientation($value){
137 // L oder P
138 $this->orientation = addslashes(trim($value));
139 }
140 public function setFilemode($m) {
141 $this->filemode = strtoupper($m);
142 }
143
144 public function getFilemode() {
145 return $this->filemode;
146 }
147 public function setFilepath($path) {
148 $this->filepath = trim($path);
149 }
150 public function setFilename($p) {
151 $this->filename = trim($p);
152 }
153
154 public function getFullFilePath() {
155 return $this->filepath.$this->filename;
156 }
157 public function setParts($parts=[]) {
158 $this->parts = [];
159 foreach($parts as $part) {
160 $this->addPart($part);
161 }
162 }
163 public function addPart($part) {
164 $teile = explode('{PAGEBREAK}', $part);
165 foreach($teile as $teil) {
166 $this->parts[] = $teil;
167 }
168 }
169
170 private function getParts() {
171 return $this->parts;
172 }
173
174 private function _loadLibs() {
175 // always load alternative config file for examples
176
177 //require_once('vendors/TCPDF/config/tcpdf_config_alt.php');
178 require_once('vendors/TCPDF/config/tcpdf_config.php');
179
180 // Include the main TCPDF library (search the library on the following directories).
181 if (!class_exists('TCPDF')) {
182 $tcpdf_include_dirs = array(
183 plugin_dir_path(__FILE__).'vendors/TCPDF/tcpdf.php',
184 realpath(dirname(__FILE__) . '/vendors/TCPDF/tcpdf.php'),// True source file
185 realpath('vendors/TCPDF/tcpdf.php'),// Relative from $PWD
186 '/usr/share/php/tcpdf/tcpdf.php',
187 '/usr/share/tcpdf/tcpdf.php',
188 '/usr/share/php-tcpdf/tcpdf.php',
189 '/var/www/tcpdf/tcpdf.php',
190 '/var/www/html/tcpdf/tcpdf.php',
191 '/usr/local/apache2/htdocs/tcpdf/tcpdf.php'
192 );
193 foreach ($tcpdf_include_dirs as $tcpdf_include_path) {
194 if (@file_exists($tcpdf_include_path)) {
195 require_once($tcpdf_include_path);
196 break;
197 }
198 }
199 }
200
201 if (!class_exists('FPDI')) {
202 require_once('vendors/FPDI-2.3.7/src/autoload.php');
203 }
204 if (!class_exists('FPDF')) {
205 require_once("vendors/fpdf185/fpdf.php");
206 }
207 }
208
209 private function prepareOutputBuffer() {
210 if ($this->filemode != "F" && ob_get_length() !== false) ob_clean();
211 if ($this->filemode != "F") ob_start();
212 }
213 private function cleanOutputBuffer() {
214 if ($this->filemode != "F") {
215 $output_level = ob_get_level();
216 for ($a=0;$a<$output_level;$a++) {
217 ob_end_clean();
218 }
219 }
220 }
221 private function outputPDF($pdf) {
222 if ($this->filemode == "F") {
223 $pdf->Output($this->filepath.$this->filename, $this->filemode);
224 } else {
225 header_remove();
226 $pdf->Output($this->filename, $this->filemode);
227 }
228 }
229
230 private function getFormat() {
231 $format = $this->page_format;
232 if ($this->is_own_page_format) {
233 $format = [$this->size_width, $this->size_height];
234 }
235 return $format;
236 }
237
238 private function checkFilePath() {
239 if (empty($this->filepath)) $this->filepath = get_temp_dir();
240 }
241
242 private function attachPDFs($pdf, $pdf_filelocations=[]) {
243 if (count($pdf_filelocations) > 0) {
244 foreach($pdf_filelocations as $pdf_filelocation) {
245 // mergen und entsprechend dem filemode senden
246 $pagenumbers = $pdf->setSourceFile($pdf_filelocation);
247 for ($a=1;$a<=$pagenumbers;$a++) {
248 $tplIdx = $pdf->importPage($a);
249 $pdf->AddPage();
250 $pdf->useTemplate($tplIdx,0,0,null,null,true);
251 }
252 }
253 }
254 return $pdf;
255 }
256
257 public function mergeFiles($pdf_filelocations=[]) {
258 if (count($pdf_filelocations) == 0) throw new Exception("no files to merge");
259 $this->prepareOutputBuffer();
260 $this->checkFilePath();
261 $format = $this->getFormat();
262 $pdf = new FPDI($this->orientation, PDF_UNIT, $format, true, 'UTF-8', false, false);
263 $pdf = $this->attachPDFs($pdf, $pdf_filelocations);
264
265 $this->cleanOutputBuffer();
266 $this->outputPDF($pdf);
267 }
268
269 public function render() {
270 $this->prepareOutputBuffer();
271 $this->checkFilePath();
272 $format = $this->getFormat();
273
274 if ($this->size_width > $this->size_height) {
275 $this->orientation = "L";
276 }
277
278 $pdf = new FPDI($this->orientation, PDF_UNIT, $format, true, 'UTF-8', false, false);
279 //$pdf->error = function ($msg) {throw new Exception("PDF-Parser: ".$msg);};
280
281 $preferences = [
282 //'HideToolbar' => true,
283 //'HideMenubar' => true,
284 //'HideWindowUI' => true,
285 //'FitWindow' => true,
286 'CenterWindow' => true,
287 //'DisplayDocTitle' => true,
288 //'NonFullScreenPageMode' => 'UseNone', // UseNone, UseOutlines, UseThumbs, UseOC
289 //'ViewArea' => 'CropBox', // CropBox, BleedBox, TrimBox, ArtBox
290 //'ViewClip' => 'CropBox', // CropBox, BleedBox, TrimBox, ArtBox
291 'PrintArea' => 'CropBox', // CropBox, BleedBox, TrimBox, ArtBox
292 //'PrintClip' => 'CropBox', // CropBox, BleedBox, TrimBox, ArtBox
293 'PrintScaling' => 'None', // None, AppDefault
294 'Duplex' => 'DuplexFlipLongEdge', // Simplex, DuplexFlipShortEdge, DuplexFlipLongEdge
295 'PickTrayByPDFSize' => true,
296 //'PrintPageRange' => array(1,1,2,3),
297 //'NumCopies' => 2
298 ];
299 if ($this->orientation == "L") $preferences['Duplex'] = "DuplexFlipShortEdge";
300 $pdf->setViewerPreferences($preferences);
301 $pdf->SetAutoPageBreak(TRUE, 5);
302
303 // set image scale factor
304 $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
305 $pdf->setJPEGQuality(90);
306
307 //$pdf->addFormat("custom", $this->size_width, $this->size_height);
308
309 // set margins
310 if ($this->marginsZero) {
311 $pdf->SetMargins(0, 0, 0);
312 }
313 //$pdf->SetMargins(PDF_MARGIN_LEFT, 17, 10);
314 //$pdf->SetHeaderMargin(10);
315 //$pdf->SetFooterMargin(10);
316
317 $pdf->SetPrintHeader(false);
318 $pdf->SetPrintFooter(false);
319
320 if ($this->isRTL) {
321 $pdf->setRTL(true);
322 }
323
324 if ($this->languageArray != null) {
325 $pdf->setLanguageArray($this->languageArray);
326 }
327
328 //$pdf->SetFont('helvetica', '', "10pt");
329 //$pdf->SetFont('dejavusans', '', $this->fontSize."pt");
330 //$pdf->SetFont('cid0jp', '', $this->fontSize."pt"); // support for japanese
331 $pdf->SetFont($this->fontFamily, '', $this->fontSize."pt"); // support for japanese
332
333 $page_parts = $this->getParts();
334 // Print text using writeHTMLCell()
335 $pdf->AddPage();
336
337 // background image
338 if ($this->background_image != null) {
339 //$w_image = $this->orientation == "L" ? $this->size_height : $this->size_width;
340 //$h_image = $this->orientation == "L" ? $this->size_width : $this->size_height;
341 $w_image = $this->size_width;
342 $h_image = $this->size_height;
343 $pdf->SetAutoPageBreak(false, 0);
344 $bg_pos_x = 0;
345 $bg_pos_y = 0;
346 $bg_size_w = $w_image;
347 $bg_size_h = $h_image;
348 if (function_exists("getimagesize")){
349 $finfo = getimagesize($this->background_image);
350 //print_r($finfo);exit;
351 $bg_size_w = $pdf->pixelsToUnits($finfo[0]);
352 $bg_size_h = $pdf->pixelsToUnits($finfo[1]);
353 $faktor = 1;
354 if ($bg_size_w > $w_image) {
355 $faktor = $bg_size_w / $w_image;
356 $bg_size_w = $w_image;
357 $bg_size_h /= $faktor;
358 }
359 if ($bg_size_h > $h_image) {
360 $faktor = $bg_size_h / $h_image;
361 $bg_size_h = $h_image;
362 $bg_size_w /= $faktor;
363 }
364 $bg_pos_x = ($w_image - $bg_size_w) / 2;
365 $bg_pos_y = ($h_image - $bg_size_h) / 2;
366 }
367 //$pdf->Image($this->background_image, $bg_pos_x, $bg_pos_y, $bg_size_w, $bg_size_h, '', '', '', false, 300, '', false, false, 1, 'CM');
368 $pdf->Image($this->background_image, $bg_pos_x, $bg_pos_y, $bg_size_w, $bg_size_h, '', '', '', false, 300, '', false, false, 0);
369 $pdf->SetAutoPageBreak(TRUE, 5);
370 $pdf->setPageMark();
371 }
372
373 $qr_params = $pdf->serializeTCPDFtagParameters([$this->qr['text'], $this->qr['type'], '', '', $this->qr['size']['width'], $this->qr['size']['height'], $this->qr['style'], $this->qr['align']]);
374 $qr_code_inline = '<tcpdf method="write2DBarcode" params="'.$qr_params.'" />';
375 //$pdf->writeHTML(print_r($this->qr, true));
376
377 foreach($page_parts as $p) {
378
379 $p = str_replace("{QRCODE_INLINE}", $qr_code_inline, $p);
380
381 try {
382 if ($p == "{PAGEBREAK}") {
383 $pdf->AddPage();
384 continue;
385 }
386 $teile = explode('{PAGEBREAK}', $p);
387 $counter = 0;
388 foreach($teile as $teil) {
389 $counter++;
390 if ($counter > 1) $pdf->AddPage();
391 if ($teil == "{QRCODE}") {
392 if (!empty($this->qr['text'])) {
393 $qr = $this->getDefaultQRValues();
394 $pdf->write2DBarcode($this->qr['text'], $this->qr['type'], $this->qr['pos']['x'], $this->qr['pos']['y'], $this->qr['size']['width'], $this->qr['size']['height'], $qr['style'], $qr['align']);
395 }
396 } else {
397 $pdf->writeHTML($teil, false, false, true, false, '');
398 }
399 }
400 } catch(Exception $e) { }
401 }
402
403 $pdf->lastPage();
404 $pdf = $this->attachPDFs($pdf, $this->attach_pdfs);
405
406 $this->cleanOutputBuffer();
407 $this->outputPDF($pdf);
408 }
409
410 }
411 ?>