ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.Util.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 use ilFileUtils;
25 
32 class Util
33 {
34  protected \ilCOPageHTMLExport $co_page_html_export;
36 
37  protected string $export_dir;
38  protected string $sub_dir;
39  protected string $target_dir;
40 
44  public function __construct(
45  string $export_dir,
46  string $sub_dir,
47  protected ?ExportCollector $export_collector = null
48  )
49  {
50  global $DIC;
51 
52  $this->export_dir = $export_dir;
53  $this->sub_dir = $sub_dir;
54  $this->target_dir = $export_dir . "/" . $sub_dir;
55 
56  $this->co_page_html_export = new \ilCOPageHTMLExport($this->target_dir, null, 0, $export_collector);
57  $this->global_screen = $DIC->globalScreen();
58  }
59 
63  public function exportSystemStyle(
64  array $standard_icons = []
65  ): void
66  {
67  // legacy export
68  if (is_null($this->export_collector)) {
69  $sys_style_html_export = new \ilSystemStyleHTMLExport($this->target_dir);
70  $sys_style_html_export->export();
71  } else {
72 
73  $asset_dirs = ["css", "fonts", "images/logo", "images/standard"];
74  foreach ($asset_dirs as $asset_dir) {
75 
76  $asset_dir = "./assets/" . $asset_dir;
77 
78  // export system style sheet
79  $iterator = new \RecursiveIteratorIterator(
80  new \RecursiveDirectoryIterator($asset_dir, \FilesystemIterator::SKIP_DOTS),
81  \RecursiveIteratorIterator::SELF_FIRST
82  );
83  foreach ($iterator as $item) {
84  if (!$item->isDir()) {
85  if ($asset_dir === "./assets/images/standard" &&
86  !in_array($iterator->getSubPathname(), $standard_icons)) {
87  continue;
88  }
89  $this->export_collector->addFile(
90  $item->getPathname(),
91  $asset_dir . DIRECTORY_SEPARATOR . $iterator->getSubPathname()
92  );
93  }
94  }
95 
96  /*
97  // export (icon) images
98  foreach (
99  [
100  ['file' => 'media/enlarge.svg', 'exp_file_name' => ''],
101  ['file' => 'browser/blank.png', 'exp_file_name' => '/browser/plus.png'],
102  ['file' => 'browser/blank.png', 'exp_file_name' => '/browser/minus.png'],
103  ['file' => 'browser/blank.png', 'exp_file_name' => '/browser/blank.png'],
104  ['file' => 'media/spacer.png', 'exp_file_name' => ''],
105  ['file' => 'standard/icon_st.svg', 'exp_file_name' => ''],
106  ['file' => 'standard/icon_pg.svg', 'exp_file_name' => ''],
107  ['file' => 'standard/icon_lm.svg', 'exp_file_name' => ''],
108  ] as $im) {
109  $from = $to = $im['file'];
110  if ($im['exp_file_name'] != '') {
111  $to = $im['exp_file_name'];
112  }
113  $this->export_collector->addFile(
114  \ilUtil::getImagePath($from, '', 'filesystem'),
115  $img_dir . '/' . $to
116  );
117  }*/
118  }
119  }
120  }
121 
125  public function exportCOPageFiles(int $style_sheet_id = 0, string $obj_type = ""): void
126  {
128 
129  // init co page html exporter
130  $this->co_page_html_export->setContentStyleId($style_sheet_id);
131  if (is_null($this->export_collector)) {
132  $this->co_page_html_export->createDirectories();
133  }
134  $this->co_page_html_export->exportStyles();
135  $this->co_page_html_export->exportSupportScripts();
136  }
137 
141  protected function initGlobalScreen(): void
142  {
143  // set global
144  $this->global_screen->tool()->context()->current()->addAdditionalData(
146  true
147  );
148  }
149 
153  public function exportResourceFiles(): void
154  {
155  $global_screen = $this->global_screen;
156  $target_dir = $this->target_dir;
157  $css = $global_screen->layout()->meta()->getCss();
158  foreach ($css->getItemsInOrderOfDelivery() as $item) {
159  $this->exportResourceFile($target_dir, $item->getContent());
160  }
161  $js = $global_screen->layout()->meta()->getJs();
162  foreach ($js->getItemsInOrderOfDelivery() as $item) {
163  $this->exportResourceFile($target_dir, $item->getContent());
164  }
165  }
166 
170  protected function exportResourceFile(string $target_dir, string $file): void
171  {
172  if (is_int(strpos($file, "?"))) {
173  $file = substr($file, 0, strpos($file, "?"));
174  }
175  if (is_file($file)) {
176  $dir = dirname($file);
177  if (is_null($this->export_collector)) {
178  ilFileUtils::makeDirParents($target_dir . "/" . $dir);
179  if (!is_file($target_dir . "/" . $file)) {
180  copy($file, $target_dir . "/" . $file);
181  }
182  } else {
183  $this->export_collector->addFile($file, $file);
184  }
185  }
186  }
187 }
exportSystemStyle(array $standard_icons=[])
Export system style.
Definition: class.Util.php:63
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
initGlobalScreen()
Init global screen.
Definition: class.Util.php:141
global $DIC
Definition: shib_login.php:25
exportResourceFiles()
Export resource files collected by global screen service.
Definition: class.Util.php:153
exportResourceFile(string $target_dir, string $file)
Export resource file.
Definition: class.Util.php:170
const PURPOSE_EXPORT
Util This class is an interim solution for the HTML export handling with 6.0.
Definition: class.Util.php:32
exportCOPageFiles(int $style_sheet_id=0, string $obj_type="")
Export content style.
Definition: class.Util.php:125
static getInstance()
Singleton: get instance for use in ILIAS requests with a config loaded from the settings.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilCOPageHTMLExport $co_page_html_export
Definition: class.Util.php:34
__construct(string $export_dir, string $sub_dir, protected ?ExportCollector $export_collector=null)
Constructor.
Definition: class.Util.php:44