ILIAS  trunk Revision v11.0_alpha-2645-g16283d3b3f8
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 
39  public function fetchDefaultFormFields(string $content): array
40  {
41  $pagewidth = "21cm";
42  if (preg_match("/page-width\=\"([^\"]+)\"/", $content, $matches)) {
43  $pagewidth = $matches[1];
44  }
45  $pageheight = "29.7cm";
46  if (preg_match("/page-height\=\"([^\"]+)\"/", $content, $matches)) {
47  $pageheight = $matches[1];
48  }
49 
50  $pagesize = 'custom';
51  if (((strcmp($pageheight, "29.7cm") === 0) || (strcmp($pageheight, "297mm") === 0))
52  && ((strcmp($pagewidth, "21cm") === 0) || (strcmp($pagewidth, "210mm") === 0))) {
53  $pagesize = "a4";
54  } elseif (((strcmp($pagewidth, "29.7cm") === 0) || (strcmp($pagewidth, "297mm") === 0))
55  && ((strcmp($pageheight, "21cm") === 0) || (strcmp($pageheight, "210mm") === 0))) {
56  $pagesize = "a4landscape";
57  } elseif (((strcmp($pageheight, "21cm") === 0) || (strcmp($pageheight, "210mm") === 0))
58  && ((strcmp($pagewidth, "14.8cm") === 0) || (strcmp($pagewidth, "148mm") === 0))) {
59  $pagesize = "a5";
60  } elseif (((strcmp($pagewidth, "21cm") === 0) || (strcmp($pagewidth, "210mm") === 0))
61  && ((strcmp($pageheight, "14.8cm") === 0) || (strcmp($pageheight, "148mm") === 0))) {
62  $pagesize = "a5landscape";
63  } elseif (((strcmp($pageheight, "11in") === 0))
64  && ((strcmp($pagewidth, "8.5in") === 0))) {
65  $pagesize = "letter";
66  } elseif (((strcmp($pagewidth, "11in") === 0))
67  && ((strcmp($pageheight, "8.5in") === 0))) {
68  $pagesize = "letterlandscape";
69  }
70 
72  $marginBody_right = ilPageFormats::DEFAULT_MARGIN_BODY_RIGHT;
73  $marginBody_bottom = ilPageFormats::DEFAULT_MARGIN_BODY_BOTTOM;
74  $marginBody_left = ilPageFormats::DEFAULT_MARGIN_BODY_LEFT;
75  if (preg_match("/fo:flow[^>]*margin\=\"([^\"]+)\"/", $content, $matches)) {
76  // Backwards compatibility
77  $marginbody = $matches[1];
78  if (preg_match_all("/([^\s]+)/", (string) $marginbody, $matches)) {
79  $marginBody_top = $matches[1][0];
80  $marginBody_right = $matches[1][1];
81  $marginBody_bottom = $matches[1][2];
82  $marginBody_left = $matches[1][3];
83  }
84  } elseif (preg_match("/fo:region-body[^>]*margin\=\"([^\"]+)\"/", $content, $matches)) {
85  $marginbody = $matches[1];
86  if (preg_match_all("/([^\s]+)/", (string) $marginbody, $matches)) {
87  $marginBody_top = $matches[1][0];
88  $marginBody_right = $matches[1][1];
89  $marginBody_bottom = $matches[1][2];
90  $marginBody_left = $matches[1][3];
91  }
92  }
93 
94  $xsl = file_get_contents(__DIR__ . '/../../xml/fo2xhtml.xsl');
95  if ($content !== '' && (is_string($xsl) && $xsl !== '')) {
96  $args = [
97  '/_xml' => $content,
98  '/_xsl' => $xsl
99  ];
100 
101  $content = $this->xlstProcess->process($args, []);
102  }
103 
104  $content = preg_replace("/<\?xml[^>]+?>/", "", $content);
105  // dirty hack: the php xslt processing seems not to recognize the following
106  // replacements, so we do it in the code as well
107  $content = str_replace(["&#xA0;", "&#160;"], "<br />", $content);
108 
109  return [
110  'pageformat' => $pagesize,
111  'pagewidth' => $pagewidth,
112  'pageheight' => $pageheight,
113  'margin_body_top' => $marginBody_top,
114  'margin_body_right' => $marginBody_right,
115  'margin_body_bottom' => $marginBody_bottom,
116  'margin_body_left' => $marginBody_left,
117  'certificate_text' => $content
118  ];
119  }
120 }
final const DEFAULT_MARGIN_BODY_TOP
fetchDefaultFormFields(string $content)
final const DEFAULT_MARGIN_BODY_RIGHT
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(?ilCertificateXlstProcess $xlstProcess=null)
readonly ilCertificateXlstProcess $xlstProcess
final const DEFAULT_MARGIN_BODY_LEFT
final const DEFAULT_MARGIN_BODY_BOTTOM