ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilXlsFoParser.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 $settings;
13 
17  private $pageFormats;
18 
22  private $xmlChecker;
23 
27  private $utilHelper;
28 
32  private $xlstProcess;
33 
37  private $language;
38 
43 
53  public function __construct(
59  ilLanguage $language = null,
61  ) {
62  $this->settings = $settings;
63  $this->pageFormats = $pageFormats;
64 
65  if (null === $xmlChecker) {
66  $xmlChecker = new ilXMLChecker();
67  }
68  $this->xmlChecker = $xmlChecker;
69 
70  if (null === $utilHelper) {
72  }
73  $this->utilHelper = $utilHelper;
74 
75  if (null === $xlstProcess) {
77  }
78  $this->xlstProcess = $xlstProcess;
79 
80  if (null === $language) {
81  global $DIC;
82  $language = $DIC->language();
83  }
84  $this->language = $language;
85 
86  if (null === $certificateXlsFileLoader) {
88  }
89  $this->certificateXlsFileLoader = $certificateXlsFileLoader;
90  }
91 
98  public function parse(array $formData) : string
99  {
100  $content = "<html><body>" . $formData['certificate_text'] . "</body></html>";
101  $content = preg_replace("/<p>(&nbsp;){1,}<\\/p>/", "<p></p>", $content);
102  $content = preg_replace("/<p>(\\s)*?<\\/p>/", "<p></p>", $content);
103  $content = str_replace("<p></p>", "<p class=\"emptyrow\"></p>", $content);
104  $content = str_replace("&nbsp;", "&#160;", $content);
105  $content = preg_replace("//", "", $content);
106 
107  $this->xmlChecker->setXMLContent($content);
108  $this->xmlChecker->startParsing();
109 
110  if ($this->xmlChecker->hasError()) {
111  throw new Exception($this->language->txt("certificate_not_well_formed"));
112  }
113 
114  $xsl = $this->certificateXlsFileLoader->getXlsCertificateContent();
115 
116  // additional font support
117  $xsl = str_replace(
118  'font-family="Helvetica, unifont"',
119  'font-family="' . $this->settings->get('rpc_pdf_font', 'Helvetica, unifont') . '"',
120  $xsl
121  );
122 
123  $args = array(
124  '/_xml' => $content,
125  '/_xsl' => $xsl
126  );
127 
128  if (strcmp($formData['pageformat'], 'custom') == 0) {
129  $pageheight = $formData['pageheight'];
130  $pagewidth = $formData['pagewidth'];
131  } else {
132  $pageformats = $this->pageFormats->fetchPageFormats();
133  $pageheight = $pageformats[$formData['pageformat']]['height'];
134  $pagewidth = $pageformats[$formData['pageformat']]['width'];
135  }
136 
137  $params = array(
138  'pageheight' => $this->formatNumberString($this->utilHelper->stripSlashes($pageheight)),
139  'pagewidth' => $this->formatNumberString($this->utilHelper->stripSlashes($pagewidth)),
140  'backgroundimage' => '[BACKGROUND_IMAGE]',
141  'marginbody' => implode(
142  ' ',
143  array(
144  $this->formatNumberString($this->utilHelper->stripSlashes($formData['margin_body']['top'])),
145  $this->formatNumberString($this->utilHelper->stripSlashes($formData['margin_body']['right'])),
146  $this->formatNumberString($this->utilHelper->stripSlashes($formData['margin_body']['bottom'])),
147  $this->formatNumberString($this->utilHelper->stripSlashes($formData['margin_body']['left']))
148  )
149  )
150  );
151 
152  $output = $this->xlstProcess->process($args, $params);
153 
154  return $output;
155  }
156 
161  private function formatNumberString($a_number) : string
162  {
163  return str_replace(',', '.', $a_number);
164  }
165 }
settings()
Definition: settings.php:2
global $DIC
Definition: saml.php:7
__construct(ilSetting $settings, ilPageFormats $pageFormats, ilXMLChecker $xmlChecker=null, ilCertificateUtilHelper $utilHelper=null, ilCertificateXlstProcess $xlstProcess=null, ilLanguage $language=null, ilCertificateXlsFileLoader $certificateXlsFileLoader=null)
XML checker.
Just a wrapper class to create Unit Test for other classes.
formatNumberString($a_number)
language handling
parse(array $formData)