ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
WikiHtmlExport.php
Go to the documentation of this file.
1<?php
2
20
22use ilFileUtils;
25
31{
32 public const MODE_DEFAULT = "html";
33 public const MODE_COMMENTS = "html_comments";
34 public const MODE_USER = "user_html";
35 public const MODE_USER_COMMENTS = "user_html_comments";
36 protected \ILIAS\components\Export\HTML\ExportCollector $collector;
37 protected \ILIAS\Export\HTML\ExternalDomainService $html_export;
38 protected \ILIAS\components\Export\HTML\Util $export_util;
39
40 protected \ilDBInterface $db;
41 protected \ilObjUser $user;
42 protected \ilLanguage $lng;
43 protected \ilTabsGUI $tabs;
44 protected \ilObjWiki $wiki;
45 protected string $mode = self::MODE_DEFAULT;
46 protected \ilLogger $log;
47 protected \ilCOPageHTMLExport $co_page_html_export;
48 protected string $export_dir;
49 protected \ILIAS\GlobalScreen\Services $global_screen;
50 protected \ilGlobalTemplateInterface $main_tpl;
51 protected \ilWikiUserHTMLExport $user_html_exp;
52 protected \ILIAS\Style\Content\Object\ObjectFacade $content_style_domain;
53
54 // has global context been initialized?
55 protected static $context_init = false;
56
57 public function __construct(\ilObjWiki $a_wiki)
58 {
59 global $DIC;
60
61 $this->db = $DIC->database();
62 $this->user = $DIC->user();
63 $this->lng = $DIC->language();
64 $this->tabs = $DIC->tabs();
65 $this->wiki = $a_wiki;
66 $this->log = \ilLoggerFactory::getLogger('wiki');
67 $this->global_screen = $DIC->globalScreen();
68 $this->main_tpl = $DIC->ui()->mainTemplate();
69 $this->content_style_domain = $DIC
70 ->contentStyle()
71 ->domain()
72 ->styleForRefId($a_wiki->getRefId());
73 $this->html_export = $DIC->export()->domain()->html();
74 }
75
76 public function setMode(
77 string $a_val
78 ): void {
79 $this->mode = $a_val;
80 }
81
82 public function getMode(): string
83 {
84 return $this->mode;
85 }
86
92 public function buildExportFile(bool $print_version = false): ExportCollector
93 {
94 $global_screen = $this->global_screen;
96 $ilUser = $this->user;
97
98 $this->log->debug("buildExportFile...");
99
100 if (in_array($this->getMode(), [self::MODE_USER, self::MODE_USER_COMMENTS])) {
101 $this->user_html_exp = new \ilWikiUserHTMLExport($this->wiki, $ilDB, $ilUser, ($this->getMode() === self::MODE_USER_COMMENTS));
102 }
103
104 $ascii_name = str_replace(" ", "_", ilFileUtils::getASCIIFilename($this->wiki->getTitle()));
105
106 /*
107 \ilExport::_createExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
108 $exp_dir =
109 \ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
110
111 if (in_array($this->getMode(), [self::MODE_USER, self::MODE_USER_COMMENTS])) {
112 ilFileUtils::delDir($exp_dir, true);
113 }*/
114
115 if (in_array($this->getMode(), [self::MODE_USER, self::MODE_USER_COMMENTS])) {
116 $subdir = $ascii_name;
117 } else {
118 $subdir = $this->wiki->getType() . "_" . $this->wiki->getId();
119 }
120
121 if ($print_version) {
122 $subdir .= "print";
123 }
124
125 //$this->export_dir = $exp_dir . "/" . $subdir;
126
127
128 $date = time();
129 $zip_file_name = (in_array($this->getMode(), [self::MODE_USER, self::MODE_USER_COMMENTS]))
130 ? $ascii_name . ".zip"
131 : $date . "__" . IL_INST_ID . "__" . $this->wiki->getType() . "_" . $this->wiki->getId() . ".zip";
132
133 $this->collector = $this->html_export->collector($this->wiki->getId(), $this->getMode());
134 $this->collector->init($zip_file_name);
135
136 $this->export_util = new \ILIAS\components\Export\HTML\Util("", "", $this->collector);
137 $this->co_page_html_export = new \ilCOPageHTMLExport("", null, 0, $this->collector);
138
139 $this->export_util->exportSystemStyle(
140 [
141 "icon_wiki.svg"
142 ]
143 );
144 $eff_style_id = $this->content_style_domain->getEffectiveStyleId();
145 $this->export_util->exportCOPageFiles($eff_style_id, "wiki");
146 $this->co_page_html_export->setContentStyleId($eff_style_id);
147
148 // export pages
149 $this->log->debug("export pages");
150 if (!self::$context_init) {
151 $global_screen->tool()->context()->current()->addAdditionalData(
153 true
154 );
155 self::$context_init = true;
156 }
157 if ($print_version) {
158 $this->exportHTMLPagesPrint();
159 } else {
160 $this->exportHTMLPages();
161 }
162 //$this->exportUserImages();
163
164 $this->export_util->exportResourceFiles();
165
166
167 // zip everything
168 /*
169 if (true) {
170 // zip it all
171 $zip_file = \ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki") .
172 "/" . $zip_file_name;
173 $this->log->debug("zip: " . $zip_file);
174 //var_dump($zip_file);
175 //exit;
176 $this->log->debug("zip, export dir: " . $this->export_dir);
177 $this->log->debug("zip, export file: " . $zip_file);
178 ilFileUtils::zip($this->export_dir, $zip_file);
179 ilFileUtils::delDir($this->export_dir);
180 }*/
181 return $this->collector;
182 }
183
189 public function exportHTMLPages(): void
190 {
191 global $DIC;
192
193 $pages = \ilWikiPage::getAllWikiPages($this->wiki->getId());
194
195 $cnt = 0;
196
197 foreach ($pages as $page) {
198 $tpl = new \ilGlobalPageTemplate($DIC->globalScreen(), $DIC->ui(), $DIC->http());
199 $this->co_page_html_export->getPreparedMainTemplate($tpl);
200 $this->log->debug("page: " . $page["id"]);
201 if (\ilWikiPage::_exists("wpg", $page["id"])) {
202 $this->log->debug("export page");
203 $this->exportPageHTML($page["id"], $tpl);
204 $this->log->debug("collect page elements");
205 $this->co_page_html_export->collectPageElements("wpg:pg", $page["id"]);
206 }
207
208 if (in_array($this->getMode(), [self::MODE_USER, self::MODE_USER_COMMENTS])) {
209 $cnt++;
210 $this->log->debug("update status: " . $cnt);
211 $this->user_html_exp->updateStatus((int) (50 / count($pages) * $cnt), \ilWikiUserHTMLExport::RUNNING);
212 }
213 }
214 $this->co_page_html_export->exportPageElements(
215 function (int $total, int $cnt): void {
216 $this->updateUserHTMLStatusForPageElements($total, $cnt);
217 }
218 );
219 }
220
224 public function exportHTMLPagesPrint(): void
225 {
226 // collect page elements
227 $pages = \ilWikiPage::getAllWikiPages($this->wiki->getId());
228 foreach ($pages as $page) {
229 if (\ilWikiPage::_exists("wpg", $page["id"])) {
230 $this->co_page_html_export->collectPageElements("wpg:pg", $page["id"]);
231 }
232 }
233 $this->co_page_html_export->exportPageElements();
234
235 // render print view
236 $wiki_gui = new \ilObjWikiGUI([], $this->wiki->getRefId(), true);
237 $print_view = $wiki_gui->getPrintView(true);
238 $print_view->setOffline(true);
239 $html = $print_view->renderPrintView();
240 $this->collector->addString($html, "index.html");
241 }
242
246 /*protected function exportUserImages(): void
247 {
248 if (in_array($this->getMode(), [self::MODE_COMMENTS, self::MODE_USER_COMMENTS])) {
249 $user_export = new \ILIAS\Notes\Export\UserImageExporter();
250 $user_export->exportUserImagesForRepObjId($this->export_dir, $this->wiki->getId());
251 }
252 }*/
253
258 int $a_total,
259 int $a_cnt
260 ): void {
261 if (in_array($this->getMode(), [self::MODE_USER, self::MODE_USER_COMMENTS])) {
262 $this->user_html_exp->updateStatus((int) (50 + (50 / $a_total * $a_cnt)), \ilWikiUserHTMLExport::RUNNING);
263 }
264 }
265
266
271 public function exportPageHTML(
272 int $a_page_id,
274 ): void {
275 $this->log->debug("Export page:" . $a_page_id);
277 $ilTabs = $this->tabs;
278
279 $ilTabs->clearTargets();
280
281 //$this->tpl->loadStandardTemplate();
282 $file = "wpg_" . $a_page_id . ".html";
283 // return if file is already existing
284 /*
285 if (is_file($file)) {
286 $this->log->debug("file already exists");
287 return;
288 }*/
289
290 // page
291 $this->log->debug("init page gui");
292 $wpg_gui = new \ilWikiPageGUI(
293 $a_page_id,
294 0,
295 $this->wiki->getRefId()
296 );
297 $wpg_gui->setOutputMode("offline");
298 $page_content = $wpg_gui->showPage();
299
300 // export template: page content
301 $this->log->debug("init page gui-" . $this->getMode() . "-");
302 $ep_tpl = new \ilTemplate(
303 "tpl.export_page.html",
304 true,
305 true,
306 "components/ILIAS/Wiki"
307 );
308 $ep_tpl->setVariable("PAGE_CONTENT", $page_content);
309
310 $comments = (in_array($this->getMode(), [self::MODE_USER_COMMENTS, self::MODE_COMMENTS]))
311 ? $wpg_gui->getCommentsHTMLExport()
312 : "";
313 $ep_tpl->setVariable("COMMENTS", $comments);
314
315 // export template: right content
316 $bl = new \ilWikiImportantPagesBlockGUI();
317 $tpl->setRightContent($bl->getHTML(true));
318
319
320 $this->log->debug("set title");
321 $tpl->setTitle($this->wiki->getTitle());
322 $tpl->setTitleIcon(
323 \ilUtil::getImagePath("standard/icon_wiki.svg"),
324 $lng->txt("obj_wiki")
325 );
326
327 $tpl->setContent($ep_tpl->get());
328 $content = $tpl->printToString();
329
330 // open file
331 /*$this->log->debug("write file: " . $file);
332 if (!($fp = fopen($file, 'wb+'))) {
333 $this->log->error("Could not open " . $file . " for writing.");
334 throw new \ilWikiExportException("Could not open \"" . $file . "\" for writing.");
335 }*/
336
337 // set file permissions
338 /*$this->log->debug("set permissions");
339 chmod($file, 0770);*/
340
341 // write xml data into the file
342 //fwrite($fp, $content);
343 $this->collector->addString($content, $file);
344
345 // close file
346 //fclose($fp);
347
348 if ($this->wiki->getStartPage() === $wpg_gui->getPageObject()->getTitle()) {
349 $this->collector->addString($content, "index.html");
350 }
351 }
352
356 public function getUserExportFile(): string
357 {
358 $exp_dir =
359 \ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
360 $this->log->debug("dir: " . $exp_dir);
361 if (!is_dir($exp_dir)) {
362 return "";
363 }
364 foreach (new \DirectoryIterator($exp_dir) as $fileInfo) {
365 $this->log->debug("file: " . $fileInfo->getFilename());
366 if (pathinfo($fileInfo->getFilename(), PATHINFO_EXTENSION) === "zip") {
367 $this->log->debug("return: " . $exp_dir . "/" . $fileInfo->getFilename());
368 return $exp_dir . "/" . $fileInfo->getFilename();
369 }
370 }
371 return "";
372 }
373
374 public function deliverLatest(): void
375 {
376 $fm = $this->html_export->fileManager();
377 $latest = $fm->getLatestOfObjectIdAndType($this->wiki->getId(), $this->getMode());
378 if ($latest) {
379 $fm->deliver($latest);
380 }
381 }
382
383 public function getLatest(): ?ExportFile
384 {
385 return $this->html_export->fileManager()->getLatestOfObjectIdAndType($this->wiki->getId(), $this->getMode());
386 }
387}
Wiki HTML exporter class.
Wiki HTML exporter class.
ilCOPageHTMLExport $co_page_html_export
ILIAS components Export HTML Util $export_util
ILIAS Export HTML ExternalDomainService $html_export
ilGlobalTemplateInterface $main_tpl
updateUserHTMLStatusForPageElements(int $a_total, int $a_cnt)
Export user images.
getUserExportFile()
Get user export file.
ILIAS GlobalScreen Services $global_screen
ilWikiUserHTMLExport $user_html_exp
exportPageHTML(int $a_page_id, \ilGlobalPageTemplate $tpl)
Export page html.
buildExportFile(bool $print_version=false)
Build export file.
exportHTMLPagesPrint()
Export all pages as one print version.
ILIAS components Export HTML ExportCollector $collector
ILIAS Style Content Object ObjectFacade $content_style_domain
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
@depricated Get export directory for an repository object
Class ilFileUtils.
static getASCIIFilename(string $a_filename)
printToString()
Use this method to get the finally rendered page as string.
setContent(string $a_html)
Sets content for standard template.
setTitleIcon(string $a_icon_path, string $a_icon_desc="")
set title icon
setRightContent(string $a_html)
Sets content of right column.
setTitle(string $a_title, bool $hidden=false)
Sets title in standard template.
static getLogger(string $a_component_id)
Get component logger.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static getAllWikiPages(int $a_wiki_id, string $lang="-")
const IL_INST_ID
Definition: constants.php:40
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$comments