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