ILIAS  release_7 Revision v7.30-3-g800a261c036
PortfolioHtmlExport.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
6
8
15{
19 protected $portfolio;
20
24 protected $portfolio_gui;
25
29 protected $export_dir;
30
34 protected $sub_dir;
35
39 protected $target_dir;
40
44 protected $global_screen;
45
49 protected $export_util;
50
55
59 protected $lng;
60
64 protected $tabs;
65
70
74 protected $active_tab;
75
79 protected $include_comments = false;
80
86 {
87 global $DIC;
88
89 $this->portfolio_gui = $portfolio_gui;
90 $this->portfolio = $portfolio_gui->object;
91
92 $this->export_dir = \ilExport::_getExportDirectory($this->portfolio->getId(), "html", "prtf");
93 $this->sub_dir = $this->portfolio->getType() . "_" . $this->portfolio->getId();
94 $this->target_dir = $this->export_dir . "/" . $this->sub_dir;
95
96 $this->global_screen = $DIC->globalScreen();
97 $this->export_util = new \ILIAS\Services\Export\HTML\Util($this->export_dir, $this->sub_dir);
98 $this->co_page_html_export = new \ilCOPageHTMLExport($this->target_dir);
99 $this->tabs = $DIC->tabs();
100 $this->lng = $DIC->language();
101
102 $this->global_screen->tool()->context()->current()->addAdditionalData(
104 true
105 );
106 }
107
112 public function includeComments($a_include_comments)
113 {
114 $this->include_comments = $a_include_comments;
115 }
116
120 protected function initDirectories()
121 {
122 // create export file
123 \ilExport::_createExportDirectory($this->portfolio->getId(), "html", "prtf");
124
125 // initialize temporary target directory
126 \ilUtil::delDir($this->target_dir);
127 \ilUtil::makeDir($this->target_dir);
128 }
129
133 protected function exportBanner()
134 {
135 // banner
136 $prfa_set = new \ilSetting("prfa");
137 if ($prfa_set->get("banner")) {
138 $banner = $this->portfolio->getImageFullPath();
139 if ($banner) { // #16096
140 copy($banner, $this->target_dir . "/" . basename($banner));
141 }
142 }
143 // page element: profile picture
144 \ilObjUser::copyProfilePicturesToDirectory($this->portfolio->getOwner(), $this->target_dir);
145 /*
146 $ppic = \ilObjUser::_getPersonalPicturePath($this->portfolio->getOwner(), "big", true, true);
147 if ($ppic) {
148 $ppic = array_shift(explode("?", $ppic));
149 copy($ppic, $this->target_dir . "/" . basename($ppic));
150 }
151 // header image: profile picture
152 $ppic = \ilObjUser::_getPersonalPicturePath($this->portfolio->getOwner(), "xsmall", true, true);
153 if ($ppic) {
154 $ppic = array_shift(explode("?", $ppic));
155 copy($ppic, $this->target_dir . "/" . basename($ppic));
156 }*/
157 }
158
159
163 public function exportHtml()
164 {
165 $this->initDirectories();
166
167 $this->export_util->exportSystemStyle();
168 $this->export_util->exportCOPageFiles(
169 $this->portfolio->getStyleSheetId(),
170 $this->portfolio->getType()
171 );
172
173 $this->exportBanner();
174
175 // export pages
176 $this->exportHTMLPages();
177
178 $this->exportUserImages();
179
180 // add js/images/file to zip
181 // note: only files are still used for certificate files
182 $images = $files = $js_files = [];
183 foreach ($this->export_material as $items) {
184 $images = array_merge($images, $items["images"]);
185 $files = array_merge($files, $items["files"]);
186 $js_files = array_merge($js_files, $items["js"]);
187 }
188 foreach (array_unique($files) as $file) {
189 if (is_file($file)) {
190 copy($file, $this->target_dir . "/files/" . basename($file));
191 }
192 }
193
194 $this->export_util->exportResourceFiles();
195 $this->co_page_html_export->exportPageElements();
196
197 return $this->zipPackage();
198 }
199
203 protected function exportUserImages()
204 {
205 if ($this->include_comments) {
206 $user_export = new \ILIAS\Notes\Export\UserImageExporter();
207 $user_export->exportUserImagesForRepObjId($this->target_dir, $this->portfolio->getId());
208 }
209 }
210
216 public function zipPackage() : string
217 {
218 // zip it all
219 $date = time();
220 $zip_file = \ilExport::_getExportDirectory($this->portfolio->getId(), "html", "prtf") .
221 "/" . $date . "__" . IL_INST_ID . "__" .
222 $this->portfolio->getType() . "_" . $this->portfolio->getId() . ".zip";
223 \ilUtil::zip($this->target_dir, $zip_file);
224 \ilUtil::delDir($this->target_dir);
225
226 return $zip_file;
227 }
228
229
236 public function exportHTMLPages()
237 {
238 $pages = \ilPortfolioPage::getAllPortfolioPages($this->portfolio->getId());
239
240 $this->tabs = [];
241 foreach ($pages as $page) {
242 // substitute blog id with title
243 if ($page["type"] == \ilPortfolioPage::TYPE_BLOG) {
244 $page["title"] = \ilObjBlog::_lookupTitle((int) $page["title"]);
245 }
246
247 $this->tabs[$page["id"]] = $page["title"];
248 }
249
250 // for sub-pages, e.g. blog postings
251 $tpl_callback = [$this, "getInitialisedTemplate"];
252
253 $has_index = false;
254 foreach ($pages as $page) {
255 if (\ilPortfolioPage::_exists("prtf", $page["id"])) {
256 $this->active_tab = "user_page_" . $page["id"];
257
258 if ($page["type"] == \ilPortfolioPage::TYPE_BLOG) {
259 $link_template = "prtf_" . $page["id"] . "_bl{TYPE}_{ID}.html";
260
261 $blog_gui = new \ilObjBlogGUI((int) $page["title"], \ilObject2GUI::WORKSPACE_OBJECT_ID);
262 $blog_export = new BlogHtmlExport($blog_gui, $this->export_dir, $this->sub_dir, false);
263 $blog_export->exportHTMLPages($link_template, $tpl_callback, $this->co_page_html_export, "prtf_" . $page["id"] . ".html");
264 } else {
265 $tpl = $this->getInitialisedTemplate();
266 $tpl->setContent($this->renderPage($page["id"]));
267 $this->writeExportFile("prtf_" . $page["id"] . ".html", $tpl->printToString());
268 $this->co_page_html_export->collectPageElements("prtf:pg", $page["id"]);
269 }
270
271 if (!$has_index) {
272 if (is_file($this->target_dir . "/prtf_" . $page["id"] . ".html")) { // #20144
273 copy(
274 $this->target_dir . "/prtf_" . $page["id"] . ".html",
275 $this->target_dir . "/index.html"
276 );
277 $has_index = true;
278 }
279 }
280 }
281 }
282 }
283
288 public function getInitialisedTemplate(array $a_js_files = []) : \ilGlobalPageTemplate
289 {
290 global $DIC;
291
292 $this->global_screen->layout()->meta()->reset();
293
294 $location_stylesheet = \ilUtil::getStyleSheetLocation();
295 $this->global_screen->layout()->meta()->addCss($location_stylesheet);
296 $this->global_screen->layout()->meta()->addCss(
297 \ilObjStyleSheet::getContentStylePath($this->portfolio->getStyleSheetId())
298 );
300
301 // js files
302 foreach ($a_js_files as $js_file) {
303 $this->global_screen->layout()->meta()->addJs($js_file);
304 }
305
306 $tabs = $DIC->tabs();
307 $tabs->clearTargets();
308 $tabs->clearSubTabs();
309 if (is_array($this->tabs)) {
310 foreach ($this->tabs as $id => $caption) {
311 $tabs->addTab("user_page_" . $id, $caption, "prtf_" . $id . ".html");
312 }
313
314 $tabs->activateTab($this->active_tab);
315 }
316
317
318 $tpl = new \ilGlobalPageTemplate($DIC->globalScreen(), $DIC->ui(), $DIC->http());
319
320 $this->co_page_html_export->getPreparedMainTemplate($tpl);
321
322 $tpl->setTitle($this->portfolio->getTitle());
323
324 return $tpl;
325 }
326
330 public function writeExportFile($a_file, $content)
331 {
332 $file = $this->target_dir . "/" . $a_file;
333 // return if file is already existing
334 if (@is_file($file)) {
335 return;
336 }
337
338 file_put_contents($file, $content);
339
340 return $file;
341 }
342
349 public function renderPage(string $a_post_id)
350 {
351 // page
352 $pgui = new \ilPortfolioPageGUI($this->portfolio->getId(), $a_post_id);
353 $pgui->setOutputMode("offline");
354 $pgui->setFullscreenLink("fullscreen.html"); // #12930 - see page.xsl
355 $page_content = $pgui->showPage();
356
357 $ep_tpl = new \ilTemplate(
358 "tpl.export_page.html",
359 true,
360 true,
361 "Modules/Portfolio"
362 );
363
364 $comments = ($this->include_comments)
365 ? $pgui->getCommentsHTMLExport()
366 : "";
367 $ep_tpl->setVariable("PAGE_CONTENT", $page_content);
368 $ep_tpl->setVariable("COMMENTS", $comments);
369
370 $material = $pgui->getExportMaterial();
371 $this->export_material[] = $material;
372
373 return $ep_tpl->get();
374 }
375}
An exception for terminatinating execution or to throw for unit testing.
getInitialisedTemplate(array $a_js_files=[])
Get initialised template.
writeExportFile($a_file, $content)
Write export file.
includeComments($a_include_comments)
Include comments.
__construct(\ilObjPortfolioBaseGUI $portfolio_gui)
constructor
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
static _createExportDirectory($a_obj_id, $a_export_type="xml", $a_obj_type="")
Class ilGlobalPageTemplate.
Portfolio view gui base class.
static getContentStylePath($a_style_id, $add_random=true, $add_token=true)
get content style path
static copyProfilePicturesToDirectory($a_user_id, $a_dir)
Get profile picture direcotory.
static _lookupTitle($a_id)
lookup object title
static resetInitialState()
Reset initial state (for exports)
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
static getAllPortfolioPages($a_portfolio_id)
Get pages of portfolio.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
const IL_INST_ID
Definition: constants.php:38
global $DIC
Definition: goto.php:24
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41