ILIAS  release_8 Revision v8.24
class.ilWkhtmlToPdfConfigFormGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
29
30 public function __construct()
31 {
32 global $DIC;
33 $this->main_tpl = $DIC->ui()->mainTemplate();
34 $this->lng = $DIC->language();
35 $this->request = new ilPDFGenerationRequest($DIC->refinery(), $DIC->http());
36 }
37
38 public function addConfigForm(ilPropertyFormGUI $form): void
39 {
40 $path = new ilTextInputGUI($this->translate('path'), 'path');
41 $form->addItem($path);
42
43 $this->appendOutputOptionsForm($form);
44 $this->appendPageSettingsForm($form);
45 }
46
47 protected function translate(string $txt): string
48 {
49 return $this->lng->txt($txt);
50 }
51
52 protected function appendOutputOptionsForm(ilPropertyFormGUI $form): void
53 {
54 $section_header = new ilFormSectionHeaderGUI();
55 $section_header->setTitle($this->translate('output_options'));
56 $form->addItem($section_header);
57
58 $form->addItem($this->buildExternalLinksForm());
59 $form->addItem($this->buildEnableFormsForm());
60 $form->addItem($this->buildLowQualityForm());
61 $form->addItem($this->buildGreyScaleForm());
62 $form->addItem($this->buildPrintMediaTypeForm());
63 $form->addItem($this->buildJavascriptDelayForm());
64 $form->addItem($this->buildCheckboxSvgForm());
65 $form->addItem($this->buildCheckedCheckboxSvgForm());
66 $form->addItem($this->buildRadiobuttonSvgForm());
68 $form->addItem($this->buildOverwriteDefaultFont());
69 }
70
72 {
73 $external_links = new ilCheckboxInputGUI($this->translate('external_links'), 'external_links');
74 $external_links->setInfo($this->translate('external_links_info'));
75 return $external_links;
76 }
77
79 {
80 $enable_forms = new ilCheckboxInputGUI($this->translate('enable_forms'), 'enable_forms');
81 $enable_forms->setInfo($this->translate('enable_forms_info'));
82 return $enable_forms;
83 }
84
86 {
87 $low_quality = new ilCheckboxInputGUI($this->translate('low_quality'), 'low_quality');
88 $low_quality->setInfo($this->translate('low_quality_info'));
89 return $low_quality;
90 }
91
93 {
94 $grey_scale = new ilCheckboxInputGUI($this->translate('greyscale'), 'greyscale');
95 $grey_scale->setInfo($this->translate('greyscale_info'));
96 return $grey_scale;
97 }
98
100 {
101 $print_media = new ilCheckboxInputGUI($this->translate('print_media_type'), 'print_media_type');
102 $print_media->setInfo($this->translate('print_media_info'));
103 return $print_media;
104 }
105
107 {
108 $javascript_delay = new ilTextInputGUI($this->translate('javascript_delay'), 'javascript_delay');
109 $javascript_delay->setInfo($this->translate('javascript_delay_info'));
110 return $javascript_delay;
111 }
112
114 {
115 return new ilTextInputGUI($this->translate('checkbox_svg'), 'checkbox_svg');
116 }
117
119 {
120 return new ilTextInputGUI($this->translate('checkbox_checked_svg'), 'checkbox_checked_svg');
121 }
122
124 {
125 return new ilTextInputGUI($this->translate('radio_button_svg'), 'radio_button_svg');
126 }
127
129 {
130 return new ilTextInputGUI($this->translate('radio_button_checked_svg'), 'radio_button_checked_svg');
131 }
132
134 {
135 $overwrite_font = new ilSelectInputGUI($this->translate('overwrite_font'), 'overwrite_font');
136 $overwrite_font->setOptions(ilPDFGenerationConstants::getFontStyles());
137 return $overwrite_font;
138 }
139
140 protected function appendPageSettingsForm(ilPropertyFormGUI $form): void
141 {
142 $section_header = new ilFormSectionHeaderGUI();
143 $section_header->setTitle($this->translate('page_settings'));
144 $form->addItem($section_header);
145 $form->addItem($this->buildZoomForm());
146 $form->addItem($this->buildOrientationsForm());
147 $form->addItem($this->buildPageSizesForm());
148 $form->addItem($this->buildMarginLeftForm());
149 $form->addItem($this->buildMarginRightForm());
150 $form->addItem($this->buildMarginTopForm());
151 $form->addItem($this->buildMarginBottomForm());
152 $form->addItem($this->buildHeaderForm());
153 $form->addItem($this->buildFooterForm());
154 }
155
156 protected function buildZoomForm(): ilTextInputGUI
157 {
158 return new ilTextInputGUI($this->translate('zoom'), 'zoom');
159 }
160
162 {
163 $orientation = new ilSelectInputGUI($this->translate('orientation'), 'orientation');
164 $orientation->setOptions(ilPDFGenerationConstants::getOrientations());
165 return $orientation;
166 }
167
169 {
170 $page_size = new ilSelectInputGUI($this->translate('page_size'), 'page_size');
171 $page_size->setOptions(ilPDFGenerationConstants::getPageSizesNames());
172 return $page_size;
173 }
174
176 {
177 $margin_left = new ilTextInputGUI($this->translate('margin_left'), 'margin_left');
178 $margin_left->setInfo($this->translate('margin_info'));
179 return $margin_left;
180 }
181
183 {
184 $margin_right = new ilTextInputGUI($this->translate('margin_right'), 'margin_right');
185 $margin_right->setInfo($this->translate('margin_info'));
186 return $margin_right;
187 }
188
189 protected function buildMarginTopForm(): ilTextInputGUI
190 {
191 $margin_top = new ilTextInputGUI($this->translate('margin_top'), 'margin_top');
192 $margin_top->setInfo($this->translate('margin_info'));
193 return $margin_top;
194 }
195
197 {
198 $margin_bottom = new ilTextInputGUI($this->translate('margin_bottom'), 'margin_bottom');
199 $margin_bottom->setInfo($this->translate('margin_info'));
200 return $margin_bottom;
201 }
202
204 {
205 $header_select = new ilRadioGroupInputGUI($this->translate('header_type'), 'header_select');
206 $header_select->addOption(new ilRadioOption(
207 $this->translate('none'),
209 ''
210 ));
211 $header_select->addOption($this->buildHeaderTextForm());
212 $header_select->addOption($this->buildHeaderHtmlForm());
213
214 return $header_select;
215 }
216
217 protected function buildHeaderTextForm(): ilRadioOption
218 {
219 $header_text_option = new ilRadioOption(
220 $this->translate('text'),
222 ''
223 );
224
225 $header_text_left = new ilTextInputGUI($this->translate('header_text_left'), 'head_text_left');
226 $header_text_option->addSubItem($header_text_left);
227
228 $header_text_center = new ilTextInputGUI($this->translate('header_text_center'), 'head_text_center');
229 $header_text_option->addSubItem($header_text_center);
230
231 $header_text_right = new ilTextInputGUI($this->translate('header_text_right'), 'head_text_right');
232 $header_text_option->addSubItem($header_text_right);
233
234 $head_text_spacing = new ilTextInputGUI($this->translate('spacing'), 'head_text_spacing');
235 $header_text_option->addSubItem($head_text_spacing);
236
237 $head_text_line = new ilCheckboxInputGUI($this->translate('header_line'), 'head_text_line');
238
239 $header_text_option->addSubItem($head_text_line);
240 return $header_text_option;
241 }
242
243 protected function buildHeaderHtmlForm(): ilRadioOption
244 {
245 $header_html_option = new ilRadioOption(
246 $this->translate("html"),
248 ''
249 );
250
251 $header_html = new ilTextInputGUI($this->translate('html'), 'head_html');
252 $header_html_option->addSubItem($header_html);
253
254 $head_html_spacing = new ilTextInputGUI($this->translate('spacing'), 'head_html_spacing');
255 $header_html_option->addSubItem($head_html_spacing);
256
257 $head_html_line = new ilCheckboxInputGUI($this->translate('header_line'), 'head_html_line');
258 $header_html_option->addSubItem($head_html_line);
259 return $header_html_option;
260 }
261
263 {
264 $footer_select = new ilRadioGroupInputGUI($this->translate('footer_type'), 'footer_select');
265 $footer_select->addOption(new ilRadioOption(
266 $this->translate("none"),
268 ''
269 ));
270 $footer_select->addOption($this->buildFooterTextForm());
271 $footer_select->addOption($this->buildFooterHtmlForm());
272
273 return $footer_select;
274 }
275
276 protected function buildFooterTextForm(): ilRadioOption
277 {
278 $footer_text_option = new ilRadioOption(
279 $this->translate('text'),
281 ''
282 );
283
284 $footer_text_left = new ilTextInputGUI($this->translate('footer_text_left'), 'footer_text_left');
285 $footer_text_option->addSubItem($footer_text_left);
286
287 $footer_text_center = new ilTextInputGUI($this->translate('footer_text_center'), 'footer_text_center');
288 $footer_text_option->addSubItem($footer_text_center);
289
290 $footer_text_right = new ilTextInputGUI($this->translate('footer_text_right'), 'footer_text_right');
291 $footer_text_option->addSubItem($footer_text_right);
292
293 $footer_text_spacing = new ilTextInputGUI($this->translate('spacing'), 'footer_text_spacing');
294 $footer_text_option->addSubItem($footer_text_spacing);
295
296 $footer_text_line = new ilCheckboxInputGUI($this->translate('footer_line'), 'footer_text_line');
297
298 $footer_text_option->addSubItem($footer_text_line);
299 return $footer_text_option;
300 }
301
302 protected function buildFooterHtmlForm(): ilRadioOption
303 {
304 $footer_html_option = new ilRadioOption(
305 $this->translate('html'),
307 ''
308 );
309
310 $footer_html = new ilTextInputGUI($this->translate('footer_html'), 'footer_html');
311 $footer_html_option->addSubItem($footer_html);
312
313 $footer_html_spacing = new ilTextInputGUI($this->translate('spacing'), 'footer_html_spacing');
314 $footer_html_option->addSubItem($footer_html_spacing);
315
316 $footer_html_line = new ilCheckboxInputGUI($this->translate('footer_line'), 'footer_html_line');
317 $footer_html_option->addSubItem($footer_html_line);
318 return $footer_html_option;
319 }
320
321 public function validateForm(ilPropertyFormGUI $form): bool
322 {
323 $everything_ok = true;
325 $path = realpath(ilShellUtil::escapeShellCmd($this->request->securedString('path')));
326 $orientation = $this->request->securedString('orientation');
327 $margin_left = $this->request->securedString('margin_left');
328 $margin_right = $this->request->securedString('margin_right');
329 $margin_top = $this->request->securedString('margin_top');
330 $margin_bottom = $this->request->securedString('margin_bottom');
331 $footer_text_spacing = (int) $this->request->securedString('footer_text_spacing');
332 $footer_html_spacing = (int) $this->request->securedString('footer_html_spacing');
333 $footer_html = $this->request->securedString('footer_html');
334 $head_text_spacing = (int) $this->request->securedString('head_text_spacing');
335 $head_html = $this->request->securedString('head_html');
336 $head_html_spacing = (int) $this->request->securedString('head_html_spacing');
337 $footer_text_left = $this->request->securedString('footer_text_left');
338 $footer_text_center = $this->request->securedString('footer_text_center');
339 $footer_text_right = $this->request->securedString('footer_text_right');
340 $header_text_left = $this->request->securedString('header_text_left');
341 $header_text_center = $this->request->securedString('header_text_center');
342 $header_text_right = $this->request->securedString('header_text_right');
343 $overwrite_font = strtolower($this->request->securedString('overwrite_font'));
344
345 $sizes = [
346 $margin_left,
347 $margin_right,
348 $margin_top,
349 $margin_bottom,
350 $footer_text_spacing,
351 $footer_html_spacing,
352 $head_text_spacing,
353 $head_html_spacing
354 ];
355 $header_footer_texts = [
356 $footer_text_left,
357 $footer_text_center,
358 $footer_text_right,
359 $header_text_left,
360 $header_text_center,
361 $header_text_right,
362 $footer_html,
363 $head_html
364 ];
365 $page_size = $this->request->securedString('page_size');
366 $pre_check_valid = $this->request->validatePathOrUrl(['checkbox_svg',
367 'checkbox_checked_svg',
368 'radio_button_svg',
369 'radio_button_checked_svg'
370 ]);
371 if($pre_check_valid === false) {
372 $everything_ok = false;
373 }
374
375 if ($path === false) {
376 $everything_ok = false;
377 $path = '';
378 }
379 $config->setPath($path);
380
381 if (in_array($overwrite_font, ilPDFGenerationConstants::getFontStyles())) {
382 $config->setOverwriteDefaultFont($overwrite_font);
383 } else {
384 $everything_ok = false;
385 }
386
387 if (mb_stripos($config->getPath(), 'wkhtmlto') === false) {
388 $form->getItemByPostVar('path')->setAlert(
389 $this->lng->txt("file_not_found")
390 );
391 $everything_ok = false;
392 } elseif (!in_array($page_size, ilPDFGenerationConstants::getPageSizesNames())) {
393 $everything_ok = false;
394 } elseif (!in_array($orientation, ilPDFGenerationConstants::getOrientations())) {
395 $everything_ok = false;
396 } elseif ($this->request->isNotValidSize($sizes)) {
397 $everything_ok = false;
398 } elseif ($this->request->isNotValidText($header_footer_texts)) {
399 $everything_ok = false;
400 } elseif ($everything_ok === true && $pre_check_valid) {
401 $config->setZoom($this->request->float('zoom'));
402 $config->setExternalLinks($this->request->bool('external_links'));
403 $config->setEnabledForms($this->request->bool('enable_forms'));
404 $config->setLowQuality($this->request->bool('low_quality'));
405 $config->setGreyscale($this->request->bool('greyscale'));
406 $config->setOrientation($orientation);
407 $config->setPageSize($page_size);
408 $config->setMarginLeft($margin_left);
409 $config->setMarginRight($margin_right);
410 $config->setMarginTop($margin_top);
411 $config->setMarginBottom($margin_bottom);
412 $config->setPrintMediaType($this->request->bool('print_media_type'));
413 $config->setJavascriptDelay($this->request->int('javascript_delay'));
414 $config->setCheckboxSvg($this->request->securedString('checkbox_svg'));
415 $config->setCheckboxCheckedSvg($this->request->securedString('checkbox_checked_svg'));
416 $config->setRadioButtonSvg($this->request->securedString('radio_button_svg'));
417 $config->setRadioButtonCheckedSvg($this->request->securedString('radio_button_checked_svg'));
418 $config->setHeaderType($this->request->int('header_select'));
419 $config->setHeaderTextLeft($this->request->securedString('head_text_left'));
420 $config->setHeaderTextCenter($this->request->securedString('head_text_center'));
421 $config->setHeaderTextRight($this->request->securedString('head_text_right'));
422 $config->setHeaderTextSpacing($head_text_spacing);
423 $config->setHeaderTextLine($this->request->bool('head_text_line'));
424 $config->setHeaderHtmlLine($this->request->bool('head_html_line'));
425 $config->setHeaderHtmlSpacing($head_html_spacing);
426 $config->setHeaderHtml($head_html);
427 $config->setFooterType($this->request->int('footer_select'));
428 $config->setFooterTextLeft($footer_text_left);
429 $config->setFooterTextCenter($footer_text_center);
430 $config->setFooterTextRight($footer_text_right);
431 $config->setFooterTextSpacing($footer_text_spacing);
432 $config->setFooterTextLine($this->request->bool('footer_text_line'));
433 $config->setFooterHtmlLine($this->request->bool('footer_html_line'));
434 $config->setFooterHtmlSpacing($footer_html_spacing);
435 $config->setFooterHtml($footer_html);
436 $config->setOverwriteDefaultFont($this->request->securedString('overwrite_font'));
437 $this->saveNewDefaultBinaryPath($config->getPath());
438 }
439
440 return $everything_ok;
441 }
442
443 protected function saveNewDefaultBinaryPath(string $path): void
444 {
445 $settings = new ilSetting('wkhtmltopdfrenderer');
446 $settings->set('path', $path);
447 }
448
453 public function getConfigFromForm(ilPropertyFormGUI $form): array
454 {
455 return [
456 'path' => $form->getInput('path'),
457 'zoom' => $form->getInput('zoom'),
458 'external_links' => (bool) $form->getInput('external_links'),
459 'enable_forms' => (bool) $form->getInput('enable_forms'),
460 'low_quality' => (bool) $form->getInput('low_quality'),
461 'greyscale' => (bool) $form->getInput('greyscale'),
462 'orientation' => $form->getInput('orientation'),
463 'page_size' => $form->getInput('page_size'),
464 'margin_left' => $form->getInput('margin_left'),
465 'margin_right' => $form->getInput('margin_right'),
466 'margin_top' => $form->getInput('margin_top'),
467 'margin_bottom' => $form->getInput('margin_bottom'),
468 'print_media_type' => (bool) $form->getInput('print_media_type'),
469 'javascript_delay' => $form->getInput('javascript_delay'),
470 'checkbox_svg' => $form->getInput('checkbox_svg'),
471 'checkbox_checked_svg' => $form->getInput('checkbox_checked_svg'),
472 'radio_button_svg' => $form->getInput('radio_button_svg'),
473 'radio_button_checked_svg' => $form->getInput('radio_button_checked_svg'),
474 'header_select' => $form->getInput('header_select'),
475 'head_text_left' => $form->getInput('head_text_left'),
476 'head_text_center' => $form->getInput('head_text_center'),
477 'head_text_right' => $form->getInput('head_text_right'),
478 'head_text_spacing' => $form->getInput('head_text_spacing'),
479 'head_text_line' => $form->getInput('head_text_line'),
480 'head_html_line' => $form->getInput('head_html_line'),
481 'head_html_spacing' => $form->getInput('head_html_spacing'),
482 'head_html' => $form->getInput('head_html'),
483 'footer_select' => $form->getInput('footer_select'),
484 'footer_text_left' => $form->getInput('footer_text_left'),
485 'footer_text_right' => $form->getInput('footer_text_right'),
486 'footer_text_spacing' => $form->getInput('footer_text_spacing'),
487 'footer_text_center' => $form->getInput('footer_text_center'),
488 'footer_text_line' => $form->getInput('footer_text_line'),
489 'footer_html' => $form->getInput('footer_html'),
490 'footer_html_spacing' => $form->getInput('footer_html_spacing'),
491 'overwrite_font' => $form->getInput('overwrite_font')
492 ];
493 }
494
496 {
497 $form->getItemByPostVar('path')->setValue($config->getWKHTMLToPdfDefaultPath());
498 $form->getItemByPostVar('zoom')->setValue($config->getZoom());
499 $form->getItemByPostVar('external_links')->setChecked((bool) $config->getExternalLinks());
500 $form->getItemByPostVar('enable_forms')->setChecked((bool) $config->getEnabledForms());
501 $form->getItemByPostVar('low_quality')->setChecked((bool) $config->getLowQuality());
502 $form->getItemByPostVar('greyscale')->setChecked((bool) $config->getGreyscale());
503 $form->getItemByPostVar('orientation')->setValue($config->getOrientation());
504 $form->getItemByPostVar('page_size')->setValue($config->getPageSize());
505 $form->getItemByPostVar('margin_left')->setValue($config->getMarginLeft());
506 $form->getItemByPostVar('margin_right')->setValue($config->getMarginRight());
507 $form->getItemByPostVar('margin_top')->setValue($config->getMarginTop());
508 $form->getItemByPostVar('margin_bottom')->setValue($config->getMarginBottom());
509 $form->getItemByPostVar('print_media_type')->setChecked((bool) $config->getPrintMediaType());
510 $form->getItemByPostVar('javascript_delay')->setValue($config->getJavascriptDelay());
511 $form->getItemByPostVar('checkbox_svg')->setValue($config->getCheckboxSvg());
512 $form->getItemByPostVar('checkbox_checked_svg')->setValue($config->getCheckboxCheckedSvg());
513 $form->getItemByPostVar('radio_button_svg')->setValue($config->getRadioButtonSvg());
514 $form->getItemByPostVar('radio_button_checked_svg')->setValue($config->getRadioButtonCheckedSvg());
515 $form->getItemByPostVar('header_select')->setValue((string) $config->getHeaderType());
516 $form->getItemByPostVar('head_text_left')->setValue($config->getHeaderTextLeft());
517 $form->getItemByPostVar('head_text_center')->setValue($config->getHeaderTextCenter());
518 $form->getItemByPostVar('head_text_right')->setValue($config->getHeaderTextRight());
519 $form->getItemByPostVar('head_text_spacing')->setValue($config->getHeaderTextSpacing());
520
521 $form->getItemByPostVar('head_text_line')->setChecked((bool) $config->isHeaderTextLine());
522 $form->getItemByPostVar('head_html_line')->setChecked((bool) $config->isHeaderHtmlLine());
523 $form->getItemByPostVar('head_html_spacing')->setValue($config->getHeaderHtmlSpacing());
524 $form->getItemByPostVar('head_html')->setValue($config->getHeaderHtml());
525 $form->getItemByPostVar('footer_select')->setValue((string) $config->getFooterType());
526 $form->getItemByPostVar('footer_text_left')->setValue($config->getFooterTextLeft());
527 $form->getItemByPostVar('footer_text_center')->setValue($config->getFooterTextCenter());
528 $form->getItemByPostVar('footer_text_right')->setValue($config->getFooterTextRight());
529 $form->getItemByPostVar('footer_text_spacing')->setValue($config->getFooterTextSpacing());
530 $form->getItemByPostVar('footer_text_line')->setChecked((bool) $config->isFooterTextLine());
531 $form->getItemByPostVar('footer_html_line')->setChecked((bool) $config->isFooterHtmlLine());
532 $form->getItemByPostVar('footer_html')->setValue($config->getFooterHtml());
533 $form->getItemByPostVar('footer_html_spacing')->setValue($config->getFooterHtmlSpacing());
534 $form->getItemByPostVar('overwrite_font')->setValue($config->getOverwriteDefaultFont(false));
535
536 }
537}
This class represents a checkbox property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static escapeShellCmd(string $a_arg)
This class represents a text property in a property form.
populateForm(ilPropertyFormGUI $form, ilWkhtmlToPdfConfig $config)
appendOutputOptionsForm(ilPropertyFormGUI $form)
$txt
Definition: error.php:13
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$path
Definition: ltiservices.php:32
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200