ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
BlogHtmlExport.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ilFileUtils;
25
27{
28 protected \ILIAS\Blog\Posting\PostingList $posting_list;
29 protected \ILIAS\Blog\Permission\PermissionManager $perm;
33 protected mixed $id_type;
34 protected int $blog_id;
37 protected \ILIAS\Blog\InternalGUIService $gui;
38 protected \ILIAS\Blog\Posting\PostingManager $posting_manager;
39 protected \ILIAS\components\Export\HTML\ExportCollector $collector;
40 protected string $export_dir;
41 protected string $sub_dir;
42 protected string $target_dir;
43 protected \ILIAS\GlobalScreen\Services $global_screen;
44 protected Util $export_util;
45 protected \ilCOPageHTMLExport $co_page_html_export;
46 protected \ilLanguage $lng;
47 protected \ilTabsGUI $tabs;
48 protected array $items;
49 protected array $keywords;
50 protected bool $include_comments = false;
51 protected bool $print_version = false;
52 protected static bool $export_key_set = false;
53 protected \ILIAS\Style\Content\Object\ObjectFacade $content_style_domain;
54
55 public function __construct(
56 protected int $node_id,
57 protected int $owner_id,
58 protected bool $is_repository,
59 string $exp_dir,
60 string $sub_dir,
61 bool $set_export_key = true
62 ) {
63 global $DIC;
64
65 $blog_service = $DIC->blog()->internal();
66 $domain = $blog_service->domain();
67
68 if ($is_repository) {
69 $this->blog_id = \ilObject::_lookupObjId($this->node_id);
70 } else {
71 $this->blog_id = $domain->getObjectIdForWspId($this->node_id);
72 }
73
74 $this->id_type = ($this->is_repository)
77
78 $this->perm = $domain->perm(
79 $this->node_id,
80 $this->id_type,
81 $domain->user()->getId(),
82 $this->owner_id
83 );
84
85 $this->gui = $blog_service->gui();
86 $keyword_manager = $blog_service->domain()->keywords();
87 $this->settings = $blog_service->domain()->blogSettings()->getByObjId($this->blog_id);
88
89 $this->collector = $DIC->export()->domain()->html()->collector($this->blog_id);
90 $this->collector->init();
91
92 $this->sub_dir = $sub_dir;
93 $this->target_dir = $exp_dir . "/" . $sub_dir;
94
95 $this->global_screen = $DIC->globalScreen();
96 $this->export_util = new Util("", "", $this->collector);
97 $this->co_page_html_export = new \ilCOPageHTMLExport($this->target_dir, null, 0, $this->collector);
98 $this->tabs = $DIC->tabs();
99 $this->lng = $DIC->language();
100
101 $this->posting_list = $blog_service->domain()->postingList($this->blog_id);
102 $this->items = $this->posting_list->getPostingsGroupedByMonth();
103 $this->keywords = $keyword_manager->getKeywords($this->blog_id, false);
104 if ($set_export_key && !self::$export_key_set) {
105 self::$export_key_set = true;
106 $this->global_screen->tool()->context()->current()->addAdditionalData(
108 true
109 );
110 }
111
112 $cs = $DIC->contentStyle();
113 if ($this->is_repository) {
114 $this->content_style_domain = $cs->domain()->styleForRefId($this->node_id);
115 } else {
116 $this->content_style_domain = $cs->domain()->styleForObjId($this->blog_id);
117 }
118 $this->posting_manager = $blog_service->domain()->posting();
119 $this->exp_manager = $blog_service->domain()->export()->manager();
120 }
121 protected function init(): void
122 {
123 }
124
125 public function setPrintVersion(bool $print_version): void
126 {
127 $this->print_version = $print_version;
128 }
129
130 public function includeComments(
131 bool $a_include_comments
132 ): void {
133 $this->include_comments = $a_include_comments;
134 }
135
136 protected function initDirectories(): void
137 {
138 // initialize temporary target directory
139 ilFileUtils::delDir($this->target_dir);
140 ilFileUtils::makeDir($this->target_dir);
141 }
142
148 public function exportHTML(): void
149 {
150 $this->initDirectories();
151
152 $this->export_util->exportSystemStyle(
153 [
154 "icon_blog.svg"
155 ]
156 );
157
158 $this->export_util->exportCOPageFiles(
159 $this->content_style_domain->getEffectiveStyleId(),
160 "blog"
161 );
162 // export pages
163 if ($this->print_version) {
164 $this->exportHTMLPagesPrint();
165 } else {
166 $this->exportHTMLPages();
167 }
168 /*
169 // export comments user images
170 $this->exportUserImages();
171 */
172 $this->export_util->exportResourceFiles();
173 $this->co_page_html_export->exportPageElements();
174 }
175
176 protected function exportUserImages(): void
177 {
178 if ($this->include_comments) {
179 $user_export = new \ILIAS\Notes\Export\UserImageExporter();
180 $user_export->exportUserImagesForRepObjId($this->target_dir, $this->blog_id);
181 }
182 }
183
184 public function renderList(
185 array $items,
186 string $month = "",
187 string $a_cmd = "preview",
188 string $a_link_template = "",
189 bool $a_show_inactive = false,
190 string $a_export_directory = ""
191 ): string {
192 return $this->gui->posting()->postingList(
193 $this->blog_id,
194 $this->perm,
195 $month,
196 $this->node_id,
197 $this->id_type,
198 )->render(
199 $items,
200 $a_cmd,
201 $a_link_template,
202 $a_show_inactive,
203 $a_export_directory
204 );
205 }
206
207
213 public function exportHTMLPages(
214 ?string $a_link_template = null,
215 ?\Closure $a_tpl_callback = null,
216 ?\ilCOPageHTMLExport $a_co_page_html_export = null,
217 string $a_index_name = "index.html"
218 ): void {
219 if (!$a_link_template) {
220 $a_link_template = "bl{TYPE}_{ID}.html";
221 }
222
223 if ($a_co_page_html_export) {
224 $this->co_page_html_export = $a_co_page_html_export;
225 }
226
227 // lists
228
229 // global nav
230 $nav = $this->gui->navigation()->sideBar(
231 null,
232 $this->gui->navigation()->exportLink(
233 $a_link_template,
234 []
235 ),
236 $this->settings,
237 $this->node_id,
238 $this->id_type
239 )->render(
240 $this->items
241 );
242
243 // month list
244 $has_index = false;
245 foreach (array_keys($this->items) as $month) {
246 $list = $this->renderList($this->items[$month], $month, "render", $a_link_template, false, $this->target_dir);
247
248 if (!$list) {
249 continue;
250 }
251
252 if (!$a_tpl_callback) {
253 $tpl = $this->getInitialisedTemplate();
254 } else {
255 $tpl = $a_tpl_callback();
256 }
257
258 $file = $this->exp_manager->buildExportLink($a_link_template, "list", $month, $this->keywords);
259 $file = $this->writeExportFile($file, $tpl, $list, $nav);
260
261 if (!$has_index) {
262 $file = $this->writeExportFile($a_index_name, $tpl, $list, $nav);
263 $has_index = true;
264 }
265 }
266
267 // keywords
268 foreach (array_keys($this->keywords) as $keyword) {
269 $list_items = $this->posting_list->getByKeyword($keyword);
270 $list = $this->renderList($list_items, "", "render", $a_link_template, false, $this->target_dir);
271
272 if (!$list) {
273 continue;
274 }
275
276 if (!$a_tpl_callback) {
277 $tpl = $this->getInitialisedTemplate();
278 } else {
279 $tpl = $a_tpl_callback();
280 }
281
282 $file = $this->exp_manager->buildExportLink($a_link_template, "keyword", $keyword, $this->keywords);
283 $file = $this->writeExportFile($file, $tpl, $list, $nav);
284 }
285
286
287 // single postings
288
289 $pages = $this->posting_manager->getAllPostings($this->blog_id, 0);
290 foreach ($pages as $page) {
291 $page_id = $page->getId();
292 if (\ilBlogPosting::_exists("blp", $page_id)) {
293 $blp_gui = new \ilBlogPostingGUI(0, null, $page_id);
294 $blp_gui->setOutputMode("offline");
295 $blp_gui->setFullscreenLink("fullscreen.html"); // #12930 - see page.xsl
296 $blp_gui->add_date = true;
297 $page_content = $blp_gui->showPage();
298
299 $back = $this->exp_manager->buildExportLink(
300 $a_link_template,
301 "list",
302 substr($page->getCreated()->get(IL_CAL_DATE), 0, 7),
303 $this->keywords
304 );
305
306 $file = $this->exp_manager->buildExportLink($a_link_template, "posting", (string) $page_id, $this->keywords);
307
308 if (!$a_tpl_callback) {
309 $tpl = $this->getInitialisedTemplate();
310 } else {
311 $tpl = $a_tpl_callback();
312 }
313
314 $comments = ($this->include_comments)
315 ? $blp_gui->getCommentsHTMLExport()
316 : "";
317
318 // posting nav
319 $nav = $this->gui->navigation()->sideBar(
320 null,
321 $this->gui->navigation()->exportLink(
322 $a_link_template,
323 []
324 ),
326 $this->node_id,
327 $this->id_type
328 )->render(
329 $this->items,
330 false,
331 $page_id
332 );
333
334 $this->writeExportFile($file, $tpl, $page_content, $nav, (bool) $back, $comments);
335
336 $this->co_page_html_export->collectPageElements("blp:pg", $page_id);
337 }
338 }
339
340 if (!$has_index) {
341 if (!$a_tpl_callback) {
342 $tpl = $this->getInitialisedTemplate();
343 } else {
344 $tpl = $a_tpl_callback();
345 }
346 $file = $this->writeExportFile($a_index_name, $tpl, "", $nav);
347 }
348 }
349
353 public function exportHTMLPagesPrint(): void
354 {
355 $this->collectAllPagesPageElements($this->co_page_html_export);
356
357 // render print view
358 $print_view = $this->gui->presentation()->getPrintView(
359 $this->node_id,
360 $this->id_type === \ilObjBlogGUI::REPOSITORY_NODE_ID
361 );
362 $print_view->setOffline(true);
363 $html = $print_view->renderPrintView();
364 $this->collector->addString($html, "index.html");
365 }
366
367
368 public function collectAllPagesPageElements(\ilCOPageHTMLExport $co_page_html_export): void
369 {
370 $page_ids = $this->posting_manager->getAllPostingIds($this->blog_id, 0);
371 foreach ($page_ids as $page_id) {
372 if (\ilBlogPosting::_exists("blp", $page_id)) {
373 $co_page_html_export->collectPageElements("blp:pg", $page_id);
374 }
375 }
376 }
377
381 public function buildExportLink(
382 string $a_template,
383 string $a_type,
384 string $a_id,
385 array $keywords
386 ): string {
387 switch ($a_type) {
388 case "list":
389 $a_type = "m";
390 break;
391
392 case "keyword":
393 $map = array_flip(array_keys($keywords));
394 $a_id = (string) ($map[$a_id] ?? "");
395 $a_type = "k";
396 break;
397
398 default:
399 $a_type = "p";
400 break;
401 }
402
403 return str_replace(array("{TYPE}", "{ID}"), array($a_type, $a_id), $a_template);
404 }
405
409 protected function getInitialisedTemplate(
410 string $a_back_url = ""
412 $this->export_util->resetGlobalScreen();
413
414 $location_stylesheet = \ilUtil::getStyleSheetLocation();
415 $this->global_screen->layout()->meta()->addCss($location_stylesheet);
416 $this->global_screen->layout()->meta()->addCss(
418 );
420
421 $tabs = $this->tabs;
422 $tabs->clearTargets();
423 $tabs->clearSubTabs();
424 if ($a_back_url) {
425 $tabs->setBackTarget($this->lng->txt("back"), $a_back_url);
426 }
427
428 $tpl = new \ilGlobalPageTemplate(
429 $this->global_screen,
430 $this->gui->ui(),
431 $this->gui->http()
432 );
433
434 $this->co_page_html_export->getPreparedMainTemplate($tpl);
435
436 $context = $this->gui->blogContext(
437 $this->node_id,
438 $this->id_type,
439 $this->blog_id,
440 "",
441 null,
442 $this->perm
443 );
444
445 $this->gui->presentation()->presentationGUI(
446 $context,
447 $this->content_style_domain,
448 )->renderFullscreenHeader($tpl, $this->owner_id, true);
449
450 return $tpl;
451 }
452
457 protected function writeExportFile(
458 string $a_file,
459 \ilGlobalPageTemplate $a_tpl,
460 string $a_content,
461 string $a_right_content = "",
462 bool $a_back = false,
463 string $comments = ""
464 ): string {
465 $file = $this->target_dir . "/" . $a_file;
466
467 // export template: page content
468 $ep_tpl = new \ilTemplate(
469 "tpl.export_page.html",
470 true,
471 true,
472 "components/ILIAS/Blog"
473 );
474 if ($a_back) {
475 $ep_tpl->setVariable("PAGE_CONTENT", $a_content);
476 $ep_tpl->setVariable("COMMENTS", $comments);
477 } else {
478 $ep_tpl->setVariable("LIST", $a_content);
479 }
480 $a_tpl->setContent($ep_tpl->get());
481 unset($ep_tpl);
482
483 // template: right content
484 if ($a_right_content) {
485 $a_tpl->setRightContent($a_right_content);
486 }
487
488 $content = $a_tpl->printToString();
489
490 // open file
491 $this->collector->addString($content, $a_file);
492
493 return $file;
494 }
495
496 public function delete(): void
497 {
498 $this->collector->delete();
499 }
500
501 public function getFilePath(): string
502 {
503 return $this->collector->getFilePath();
504 }
505
506}
$settings
Definition: index.php:44
includeComments(bool $a_include_comments)
ILIAS Blog Settings Settings $settings
ILIAS components Export HTML ExportCollector $collector
ILIAS Blog Posting PostingManager $posting_manager
buildExportLink(string $a_template, string $a_type, string $a_id, array $keywords)
Build static export link.
ILIAS Blog InternalGUIService $gui
__construct(protected int $node_id, protected int $owner_id, protected bool $is_repository, string $exp_dir, string $sub_dir, bool $set_export_key=true)
ILIAS Style Content Object ObjectFacade $content_style_domain
exportHTMLPagesPrint()
Export all pages as one print version.
exportHTMLPages(?string $a_link_template=null, ?\Closure $a_tpl_callback=null, ?\ilCOPageHTMLExport $a_co_page_html_export=null, string $a_index_name="index.html")
Export all pages (note: this one is called from the portfolio html export!)
ILIAS Blog Posting PostingList $posting_list
renderList(array $items, string $month="", string $a_cmd="preview", string $a_link_template="", bool $a_show_inactive=false, string $a_export_directory="")
ILIAS Blog Permission PermissionManager $perm
collectAllPagesPageElements(\ilCOPageHTMLExport $co_page_html_export)
writeExportFile(string $a_file, \ilGlobalPageTemplate $a_tpl, string $a_content, string $a_right_content="", bool $a_back=false, string $comments="")
Write HTML to file.
setPrintVersion(bool $print_version)
ilCOPageHTMLExport $co_page_html_export
getInitialisedTemplate(string $a_back_url="")
Get initialised template.
ILIAS GlobalScreen Services $global_screen
Util This class is an interim solution for the HTML export handling with 6.0.
Definition: class.Util.php:33
const IL_CAL_DATE
HTML export class for pages.
collectPageElements(string $a_type, int $a_id, string $lang="")
Collect page elements (that need to be exported separately)
Class ilFileUtils.
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
printToString()
Use this method to get the finally rendered page as string.
setContent(string $a_html)
Sets content for standard template.
setRightContent(string $a_html)
Sets content of right column.
static _lookupObjId(int $ref_id)
static resetInitialState()
Reset initial state (for exports)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
static getStyleSheetLocation(string $mode="output", string $a_css_name="")
get full style sheet file name (path inclusive) of current user
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'vtt', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
readonly ilGlobalTemplateInterface $tpl
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$comments