ILIAS  release_8 Revision v8.24
PortfolioHtmlExport.php
Go to the documentation of this file.
1<?php
2
20
22use ilFileUtils;
23
30{
31 protected \ilObjPortfolio $portfolio;
32 protected \ilObjPortfolioBaseGUI $portfolio_gui;
33 protected string $export_dir = "";
34 protected string $sub_dir = "";
35 protected string $target_dir = "";
36 protected \ILIAS\GlobalScreen\Services $global_screen;
37 protected \ILIAS\Services\Export\HTML\Util $export_util;
38 protected \ilCOPageHTMLExport $co_page_html_export;
39 protected \ilLanguage $lng;
40 protected array $tabs = [];
41 protected array $export_material = [];
42 protected string $active_tab = "";
43 protected bool $include_comments = false;
44 protected bool $print_version = false;
45 protected \ILIAS\Style\Content\Object\ObjectFacade $content_style_domain;
46
47 public function __construct(
49 ) {
50 global $DIC;
51
52 $this->portfolio_gui = $portfolio_gui;
55 $this->portfolio = $portfolio;
56
57
58 $this->global_screen = $DIC->globalScreen();
59 $this->lng = $DIC->language();
60
61 $this->global_screen->tool()->context()->current()->addAdditionalData(
63 true
64 );
65
66 $this->content_style_domain = $DIC
67 ->contentStyle()
68 ->domain()->styleForObjId($this->portfolio->getId());
69 }
70
71 protected function init(): void
72 {
73 $this->export_dir = \ilExport::_getExportDirectory($this->portfolio->getId(), "html", "prtf");
74 $this->sub_dir = $this->portfolio->getType() . "_" . $this->portfolio->getId();
75 if ($this->print_version) {
76 $this->sub_dir .= "print";
77 }
78 $this->target_dir = $this->export_dir . "/" . $this->sub_dir;
79 $this->export_util = new \ILIAS\Services\Export\HTML\Util($this->export_dir, $this->sub_dir);
80 $this->co_page_html_export = new \ilCOPageHTMLExport($this->target_dir);
81 }
82
83 public function includeComments(bool $a_include_comments): void
84 {
85 $this->include_comments = $a_include_comments;
86 }
87
88 public function setPrintVersion(bool $print_version): void
89 {
90 $this->print_version = $print_version;
91 }
92
96 protected function initDirectories(): void
97 {
98 // create export file
99 \ilExport::_createExportDirectory($this->portfolio->getId(), "html", "prtf");
100
101 // initialize temporary target directory
102 ilFileUtils::delDir($this->target_dir);
103 ilFileUtils::makeDir($this->target_dir);
104 }
105
109 protected function exportBanner(): void
110 {
111 // banner
112 $prfa_set = new \ilSetting("prfa");
113 if ($prfa_set->get("banner")) {
114 $banner = $this->portfolio->getImageFullPath();
115 if ($banner) { // #16096
116 copy($banner, $this->target_dir . "/" . basename($banner));
117 }
118 }
119 // page element: profile picture
120 \ilObjUser::copyProfilePicturesToDirectory($this->portfolio->getOwner(), $this->target_dir);
121 /*
122 $ppic = \ilObjUser::_getPersonalPicturePath($this->portfolio->getOwner(), "big", true, true);
123 if ($ppic) {
124 $ppic = array_shift(explode("?", $ppic));
125 copy($ppic, $this->target_dir . "/" . basename($ppic));
126 }
127 // header image: profile picture
128 $ppic = \ilObjUser::_getPersonalPicturePath($this->portfolio->getOwner(), "xsmall", true, true);
129 if ($ppic) {
130 $ppic = array_shift(explode("?", $ppic));
131 copy($ppic, $this->target_dir . "/" . basename($ppic));
132 }*/
133 }
134
135
139 public function exportHtml(): string
140 {
141 $this->init();
142 $this->initDirectories();
143
144 $this->export_util->exportSystemStyle();
145 $this->export_util->exportCOPageFiles(
146 $this->content_style_domain->getEffectiveStyleId(),
147 $this->portfolio->getType()
148 );
149
150 $this->exportBanner();
151
152 // export pages
153 if ($this->print_version) {
154 $this->exportHTMLPagesPrint();
155 } else {
156 $this->exportHTMLPages();
157 }
158
159 $this->exportUserImages();
160
161 // add js/images/file to zip
162 // note: only files are still used for certificate files
163 $images = $files = $js_files = [];
164 foreach ($this->export_material as $items) {
165 $images = array_merge($images, $items["images"]);
166 $files = array_merge($files, $items["files"]);
167 $js_files = array_merge($js_files, $items["js"]);
168 }
169 foreach (array_unique($files) as $file) {
170 if (is_file($file)) {
171 copy($file, $this->target_dir . "/files/" . basename($file));
172 }
173 }
174
175 $this->export_util->exportResourceFiles();
176 $this->co_page_html_export->exportPageElements();
177
178 return $this->zipPackage();
179 }
180
184 protected function exportUserImages(): void
185 {
186 if ($this->include_comments) {
187 $user_export = new \ILIAS\Notes\Export\UserImageExporter();
188 $user_export->exportUserImagesForRepObjId($this->target_dir, $this->portfolio->getId());
189 }
190 }
191
197 public function zipPackage(): string
198 {
199 // zip it all
200 $date = time();
201 $zip_file = \ilExport::_getExportDirectory($this->portfolio->getId(), "html", "prtf") .
202 "/" . $date . "__" . IL_INST_ID . "__" .
203 $this->portfolio->getType() . "_" . $this->portfolio->getId() . ".zip";
204 ilFileUtils::zip($this->target_dir, $zip_file);
205 ilFileUtils::delDir($this->target_dir);
206
207 return $zip_file;
208 }
209
210
217 public function exportHTMLPages(): void
218 {
219 $pages = \ilPortfolioPage::getAllPortfolioPages($this->portfolio->getId());
220
221 $this->tabs = [];
222 foreach ($pages as $page) {
223 // substitute blog id with title
224 if ($page["type"] == \ilPortfolioPage::TYPE_BLOG) {
225 $page["title"] = \ilObjBlog::_lookupTitle((int) $page["title"]);
226 }
227
228 $this->tabs[$page["id"]] = $page["title"];
229 }
230
231 // for sub-pages, e.g. blog postings
232 $tpl_callback = function (array $js_files = []): \ilGlobalPageTemplate {
233 return $this->getInitialisedTemplate($js_files);
234 };
235
236 $has_index = false;
237 foreach ($pages as $page) {
238 if (\ilPortfolioPage::_exists("prtf", $page["id"])) {
239 $this->active_tab = "user_page_" . $page["id"];
240
241 if ($page["type"] == \ilPortfolioPage::TYPE_BLOG) {
242 $link_template = "prtf_" . $page["id"] . "_bl{TYPE}_{ID}.html";
243
244 $blog_gui = new \ilObjBlogGUI((int) $page["title"], \ilObject2GUI::WORKSPACE_OBJECT_ID);
245 $blog_export = new BlogHtmlExport($blog_gui, $this->export_dir, $this->sub_dir, false);
246 $blog_export->exportHTMLPages($link_template, $tpl_callback, $this->co_page_html_export, "prtf_" . $page["id"] . ".html");
247 } else {
248 $tpl = $this->getInitialisedTemplate();
249 $tpl->setContent($this->renderPage($page["id"]));
250 $this->writeExportFile("prtf_" . $page["id"] . ".html", $tpl->printToString());
251 $this->co_page_html_export->collectPageElements("prtf:pg", $page["id"]);
252 }
253
254 if (!$has_index && is_file($this->target_dir . "/prtf_" . $page["id"] . ".html")) { // #20144
255 copy(
256 $this->target_dir . "/prtf_" . $page["id"] . ".html",
257 $this->target_dir . "/index.html"
258 );
259 $has_index = true;
260 }
261 }
262 }
263 }
264
268 public function exportHTMLPagesPrint(): void
269 {
270 // collect page elements
271 $pages = \ilPortfolioPage::getAllPortfolioPages($this->portfolio->getId());
272 foreach ($pages as $page) {
273 if (\ilPortfolioPage::_exists("prtf", $page["id"])) {
274 if ($page["type"] == \ilPortfolioPage::TYPE_BLOG) {
275 $blog_gui = new \ilObjBlogGUI((int) $page["title"], \ilObject2GUI::WORKSPACE_OBJECT_ID);
276 $blog_export = new BlogHtmlExport($blog_gui, $this->export_dir, $this->sub_dir, false);
277 $blog_export->collectAllPagesPageElements($this->co_page_html_export);
278 } else {
279 $this->co_page_html_export->collectPageElements("prtf:pg", $page["id"]);
280 }
281 }
282 }
283
284 // render print view
285 $print_view = $this->portfolio_gui->getPrintView();
286 $print_view->setOffline(true);
287 $html = $print_view->renderPrintView();
288 file_put_contents($this->target_dir . "/index.html", $html);
289 }
290
294 public function getInitialisedTemplate(
295 array $a_js_files = []
297 global $DIC;
298
299 $this->global_screen->layout()->meta()->reset();
300
301 $location_stylesheet = \ilUtil::getStyleSheetLocation();
302 $this->global_screen->layout()->meta()->addCss($location_stylesheet);
303 $this->global_screen->layout()->meta()->addCss(
305 $this->content_style_domain->getEffectiveStyleId()
306 )
307 );
309
310 // js files
311 foreach ($a_js_files as $js_file) {
312 $this->global_screen->layout()->meta()->addJs($js_file);
313 }
314
315 $tabs = $DIC->tabs();
316 $tabs->clearTargets();
317 $tabs->clearSubTabs();
318 if (is_array($this->tabs)) {
319 foreach ($this->tabs as $id => $caption) {
320 $tabs->addTab("user_page_" . $id, $caption, "prtf_" . $id . ".html");
321 }
322
323 $tabs->activateTab($this->active_tab);
324 }
325
326
327 $tpl = new \ilGlobalPageTemplate($DIC->globalScreen(), $DIC->ui(), $DIC->http());
328
329 $this->co_page_html_export->getPreparedMainTemplate($tpl);
330
331 $tpl->setTitle($this->portfolio->getTitle());
332
333 return $tpl;
334 }
335
339 public function writeExportFile(
340 string $a_file,
341 string $content
342 ): string {
343 $file = $this->target_dir . "/" . $a_file;
344 // return if file is already existing
345 if (is_file($file)) {
346 return "";
347 }
348
349 file_put_contents($file, $content);
350
351 return $file;
352 }
353
357 public function renderPage(
358 string $a_post_id
359 ): string {
360 // page
361 $pgui = new \ilPortfolioPageGUI($this->portfolio->getId(), $a_post_id);
362 $pgui->setOutputMode("offline");
363 $pgui->setFullscreenLink("fullscreen.html"); // #12930 - see page.xsl
364 $page_content = $pgui->showPage();
365
366 $ep_tpl = new \ilTemplate(
367 "tpl.export_page.html",
368 true,
369 true,
370 "Modules/Portfolio"
371 );
372
373 $comments = ($this->include_comments)
374 ? $pgui->getCommentsHTMLExport()
375 : "";
376 $ep_tpl->setVariable("PAGE_CONTENT", $page_content);
377 $ep_tpl->setVariable("COMMENTS", $comments);
378
379 $material = $pgui->getExportMaterial();
380 $this->export_material[] = $material;
381
382 return $ep_tpl->get();
383 }
384}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getInitialisedTemplate(array $a_js_files=[])
Get initialised template.
exportHTMLPagesPrint()
Export all pages as one print version.
ILIAS Style Content Object ObjectFacade $content_style_domain
ILIAS Services Export HTML Util $export_util
writeExportFile(string $a_file, string $content)
Write export file.
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:62
static _createExportDirectory(int $a_obj_id, string $a_export_type="xml", string $a_obj_type="")
static _getExportDirectory(int $a_obj_id, string $a_type="xml", string $a_obj_type="", string $a_entity="")
Get export directory for an repository object.
Class ilFileUtils.
static zip(string $a_dir, string $a_file, bool $compress_content=false)
zips given directory/file into given zip.file
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
Portfolio view gui base class.
static getContentStylePath(int $a_style_id, bool $add_random=true, bool $add_token=true)
get content style path static (to avoid full reading)
static copyProfilePicturesToDirectory(int $a_user_id, string $a_dir)
static _lookupTitle(int $obj_id)
static resetInitialState()
Reset initial state (for exports)
setOutputMode(string $a_mode=self::PRESENTATION)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getAllPortfolioPages(int $a_portfolio_id)
Get pages of portfolio.
static getStyleSheetLocation(string $mode="output", string $a_css_name="", string $a_css_location="")
get full style sheet file name (path inclusive) of current user
const IL_INST_ID
Definition: constants.php:40
global $DIC
Definition: feed.php:28
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$comments