ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.Util.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ilFileUtils;
25
32class 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 {
125 // init co page html exporter
126 $this->co_page_html_export->setContentStyleId($style_sheet_id);
127 if (is_null($this->export_collector)) {
128 $this->co_page_html_export->createDirectories();
129 }
130 $this->co_page_html_export->exportStyles();
131 $this->co_page_html_export->exportSupportScripts();
132 }
133
137 protected function initGlobalScreen(): void
138 {
139 // set global
140 $this->global_screen->tool()->context()->current()->addAdditionalData(
142 true
143 );
144 }
145
149 public function exportResourceFiles(): void
150 {
151 $global_screen = $this->global_screen;
152 $target_dir = $this->target_dir;
153 $css = $global_screen->layout()->meta()->getCss();
154 foreach ($css->getItemsInOrderOfDelivery() as $item) {
155 $this->exportResourceFile($target_dir, $item->getContent());
156 }
157 $js = $global_screen->layout()->meta()->getJs();
158 foreach ($js->getItemsInOrderOfDelivery() as $item) {
159 $this->exportResourceFile($target_dir, $item->getContent());
160 }
161 }
162
166 protected function exportResourceFile(string $target_dir, string $file): void
167 {
168 if (is_int(strpos($file, "?"))) {
169 $file = substr($file, 0, strpos($file, "?"));
170 }
171 if (is_file($file)) {
172 $dir = dirname($file);
173 if (is_null($this->export_collector)) {
174 ilFileUtils::makeDirParents($target_dir . "/" . $dir);
175 if (!is_file($target_dir . "/" . $file)) {
176 copy($file, $target_dir . "/" . $file);
177 }
178 } else {
179 $this->export_collector->addFile($file, $file);
180 }
181 }
182 }
183}
Util This class is an interim solution for the HTML export handling with 6.0.
Definition: class.Util.php:33
ilCOPageHTMLExport $co_page_html_export
Definition: class.Util.php:34
exportResourceFile(string $target_dir, string $file)
Export resource file.
Definition: class.Util.php:166
exportResourceFiles()
Export resource files collected by global screen service.
Definition: class.Util.php:149
initGlobalScreen()
Init global screen.
Definition: class.Util.php:137
__construct(string $export_dir, string $sub_dir, protected ?ExportCollector $export_collector=null)
Constructor.
Definition: class.Util.php:44
exportCOPageFiles(int $style_sheet_id=0, string $obj_type="")
Export content style.
Definition: class.Util.php:123
exportSystemStyle(array $standard_icons=[])
Export system style.
Definition: class.Util.php:62
Class ilFileUtils.
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26