ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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  global $DIC;
50 
51  $this->export_dir = $export_dir;
52  $this->sub_dir = $sub_dir;
53  $this->target_dir = $export_dir . "/" . $sub_dir;
54 
55  $this->co_page_html_export = new \ilCOPageHTMLExport($this->target_dir, null, 0, $export_collector);
56  $this->global_screen = $DIC->globalScreen();
57  }
58 
62  public function exportSystemStyle(
63  array $standard_icons = []
64  ): void {
65  // legacy export
66  if (is_null($this->export_collector)) {
67  $sys_style_html_export = new \ilSystemStyleHTMLExport($this->target_dir);
68  $sys_style_html_export->export();
69  } else {
70 
71  $asset_dirs = ["css", "fonts", "images/logo", "images/standard"];
72  foreach ($asset_dirs as $asset_dir) {
73 
74  $asset_dir = "./assets/" . $asset_dir;
75 
76  // export system style sheet
77  $iterator = new \RecursiveIteratorIterator(
78  new \RecursiveDirectoryIterator($asset_dir, \FilesystemIterator::SKIP_DOTS),
79  \RecursiveIteratorIterator::SELF_FIRST
80  );
81  foreach ($iterator as $item) {
82  if (!$item->isDir()) {
83  if ($asset_dir === "./assets/images/standard" &&
84  !in_array($iterator->getSubPathname(), $standard_icons)) {
85  continue;
86  }
87  $this->export_collector->addFile(
88  $item->getPathname(),
89  $asset_dir . DIRECTORY_SEPARATOR . $iterator->getSubPathname()
90  );
91  }
92  }
93 
94  /*
95  // export (icon) images
96  foreach (
97  [
98  ['file' => 'media/enlarge.svg', 'exp_file_name' => ''],
99  ['file' => 'browser/blank.png', 'exp_file_name' => '/browser/plus.png'],
100  ['file' => 'browser/blank.png', 'exp_file_name' => '/browser/minus.png'],
101  ['file' => 'browser/blank.png', 'exp_file_name' => '/browser/blank.png'],
102  ['file' => 'media/spacer.png', 'exp_file_name' => ''],
103  ['file' => 'standard/icon_st.svg', 'exp_file_name' => ''],
104  ['file' => 'standard/icon_pg.svg', 'exp_file_name' => ''],
105  ['file' => 'standard/icon_lm.svg', 'exp_file_name' => ''],
106  ] as $im) {
107  $from = $to = $im['file'];
108  if ($im['exp_file_name'] != '') {
109  $to = $im['exp_file_name'];
110  }
111  $this->export_collector->addFile(
112  \ilUtil::getImagePath($from, '', 'filesystem'),
113  $img_dir . '/' . $to
114  );
115  }*/
116  }
117  }
118  }
119 
123  public function exportCOPageFiles(int $style_sheet_id = 0, string $obj_type = ""): void
124  {
126 
127  // init co page html exporter
128  $this->co_page_html_export->setContentStyleId($style_sheet_id);
129  if (is_null($this->export_collector)) {
130  $this->co_page_html_export->createDirectories();
131  }
132  $this->co_page_html_export->exportStyles();
133  $this->co_page_html_export->exportSupportScripts();
134  }
135 
139  protected function initGlobalScreen(): void
140  {
141  // set global
142  $this->global_screen->tool()->context()->current()->addAdditionalData(
144  true
145  );
146  }
147 
151  public function exportResourceFiles(): void
152  {
153  $global_screen = $this->global_screen;
154  $target_dir = $this->target_dir;
155  $css = $global_screen->layout()->meta()->getCss();
156  foreach ($css->getItemsInOrderOfDelivery() as $item) {
157  $this->exportResourceFile($target_dir, $item->getContent());
158  }
159  $js = $global_screen->layout()->meta()->getJs();
160  foreach ($js->getItemsInOrderOfDelivery() as $item) {
161  $this->exportResourceFile($target_dir, $item->getContent());
162  }
163  }
164 
168  protected function exportResourceFile(string $target_dir, string $file): void
169  {
170  if (is_int(strpos($file, "?"))) {
171  $file = substr($file, 0, strpos($file, "?"));
172  }
173  if (is_file($file)) {
174  $dir = dirname($file);
175  if (is_null($this->export_collector)) {
176  ilFileUtils::makeDirParents($target_dir . "/" . $dir);
177  if (!is_file($target_dir . "/" . $file)) {
178  copy($file, $target_dir . "/" . $file);
179  }
180  } else {
181  $this->export_collector->addFile($file, $file);
182  }
183  }
184  }
185 }
exportSystemStyle(array $standard_icons=[])
Export system style.
Definition: class.Util.php:62
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
initGlobalScreen()
Init global screen.
Definition: class.Util.php:139
global $DIC
Definition: shib_login.php:22
exportResourceFiles()
Export resource files collected by global screen service.
Definition: class.Util.php:151
exportResourceFile(string $target_dir, string $file)
Export resource file.
Definition: class.Util.php:168
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:123
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