ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilFormFieldParser.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 {
27 
28  public function __construct(?ilCertificateXlstProcess $xlstProcess = null)
29  {
30  if (null === $xlstProcess) {
31  $xlstProcess = new ilCertificateXlstProcess();
32  }
33  $this->xlstProcess = $xlstProcess;
34  }
35 
36  public function fetchDefaultFormFields(string $content): array
37  {
38  $pagewidth = "21cm";
39  if (preg_match("/page-width\=\"([^\"]+)\"/", $content, $matches)) {
40  $pagewidth = $matches[1];
41  }
42  $pageheight = "29.7cm";
43  if (preg_match("/page-height\=\"([^\"]+)\"/", $content, $matches)) {
44  $pageheight = $matches[1];
45  }
46 
47  $pagesize = 'custom';
48  if (((strcmp($pageheight, "29.7cm") === 0) || (strcmp($pageheight, "297mm") === 0))
49  && ((strcmp($pagewidth, "21cm") === 0) || (strcmp($pagewidth, "210mm") === 0))) {
50  $pagesize = "a4";
51  } elseif (((strcmp($pagewidth, "29.7cm") === 0) || (strcmp($pagewidth, "297mm") === 0))
52  && ((strcmp($pageheight, "21cm") === 0) || (strcmp($pageheight, "210mm") === 0))) {
53  $pagesize = "a4landscape";
54  } elseif (((strcmp($pageheight, "21cm") === 0) || (strcmp($pageheight, "210mm") === 0))
55  && ((strcmp($pagewidth, "14.8cm") === 0) || (strcmp($pagewidth, "148mm") === 0))) {
56  $pagesize = "a5";
57  } elseif (((strcmp($pagewidth, "21cm") === 0) || (strcmp($pagewidth, "210mm") === 0))
58  && ((strcmp($pageheight, "14.8cm") === 0) || (strcmp($pageheight, "148mm") === 0))) {
59  $pagesize = "a5landscape";
60  } elseif (((strcmp($pageheight, "11in") === 0))
61  && ((strcmp($pagewidth, "8.5in") === 0))) {
62  $pagesize = "letter";
63  } elseif (((strcmp($pagewidth, "11in") === 0))
64  && ((strcmp($pageheight, "8.5in") === 0))) {
65  $pagesize = "letterlandscape";
66  }
67 
69  $marginBody_right = ilPageFormats::DEFAULT_MARGIN_BODY_RIGHT;
70  $marginBody_bottom = ilPageFormats::DEFAULT_MARGIN_BODY_BOTTOM;
71  $marginBody_left = ilPageFormats::DEFAULT_MARGIN_BODY_LEFT;
72  if (preg_match("/fo:flow[^>]*margin\=\"([^\"]+)\"/", $content, $matches)) {
73  // Backwards compatibility
74  $marginbody = $matches[1];
75  if (preg_match_all("/([^\s]+)/", $marginbody, $matches)) {
76  $marginBody_top = $matches[1][0];
77  $marginBody_right = $matches[1][1];
78  $marginBody_bottom = $matches[1][2];
79  $marginBody_left = $matches[1][3];
80  }
81  } elseif (preg_match("/fo:region-body[^>]*margin\=\"([^\"]+)\"/", $content, $matches)) {
82  $marginbody = $matches[1];
83  if (preg_match_all("/([^\s]+)/", $marginbody, $matches)) {
84  $marginBody_top = $matches[1][0];
85  $marginBody_right = $matches[1][1];
86  $marginBody_bottom = $matches[1][2];
87  $marginBody_left = $matches[1][3];
88  }
89  }
90 
91  $xsl = file_get_contents("./Services/Certificate/xml/fo2xhtml.xsl");
92  if ($content !== '' && (is_string($xsl) && $xsl !== '')) {
93  $args = [
94  '/_xml' => $content,
95  '/_xsl' => $xsl
96  ];
97 
98  $content = $this->xlstProcess->process($args, []);
99  }
100 
101  $content = preg_replace("/<\?xml[^>]+?>/", "", $content);
102  // dirty hack: the php xslt processing seems not to recognize the following
103  // replacements, so we do it in the code as well
104  $content = str_replace(["&#xA0;", "&#160;"], "<br />", $content);
105 
106  return [
107  'pageformat' => $pagesize,
108  'pagewidth' => $pagewidth,
109  'pageheight' => $pageheight,
110  'margin_body_top' => $marginBody_top,
111  'margin_body_right' => $marginBody_right,
112  'margin_body_bottom' => $marginBody_bottom,
113  'margin_body_left' => $marginBody_left,
114  'certificate_text' => $content
115  ];
116  }
117 }
fetchDefaultFormFields(string $content)
ilCertificateXlstProcess $xlstProcess
const DEFAULT_MARGIN_BODY_BOTTOM
__construct(?ilCertificateXlstProcess $xlstProcess=null)