ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
81 {
82 global $DIC;
83
84 $this->portfolio_gui = $portfolio_gui;
85 $this->portfolio = $portfolio_gui->object;
86
87 $this->export_dir = \ilExport::_getExportDirectory($this->portfolio->getId(), "html", "prtf");
88 $this->sub_dir = $this->portfolio->getType() . "_" . $this->portfolio->getId();
89 $this->target_dir = $this->export_dir . "/" . $this->sub_dir;
90
91 $this->global_screen = $DIC->globalScreen();
92 $this->export_util = new \ILIAS\Services\Export\HTML\Util($this->export_dir, $this->sub_dir);
93 $this->co_page_html_export = new \ilCOPageHTMLExport($this->target_dir);
94 $this->tabs = $DIC->tabs();
95 $this->lng = $DIC->language();
96
97 $this->global_screen->tool()->context()->current()->addAdditionalData(
99 true
100 );
101 }
102
106 protected function initDirectories()
107 {
108 // create export file
109 \ilExport::_createExportDirectory($this->portfolio->getId(), "html", "prtf");
110
111 // initialize temporary target directory
112 \ilUtil::delDir($this->target_dir);
113 \ilUtil::makeDir($this->target_dir);
114 }
115
119 protected function exportBanner()
120 {
121 // banner
122 $prfa_set = new \ilSetting("prfa");
123 if ($prfa_set->get("banner")) {
124 $banner = $this->portfolio->getImageFullPath();
125 if ($banner) { // #16096
126 copy($banner, $this->target_dir . "/" . basename($banner));
127 }
128 }
129 // page element: profile picture
130 \ilObjUser::copyProfilePicturesToDirectory($this->portfolio->getOwner(), $this->target_dir);
131 /*
132 $ppic = \ilObjUser::_getPersonalPicturePath($this->portfolio->getOwner(), "big", true, true);
133 if ($ppic) {
134 $ppic = array_shift(explode("?", $ppic));
135 copy($ppic, $this->target_dir . "/" . basename($ppic));
136 }
137 // header image: profile picture
138 $ppic = \ilObjUser::_getPersonalPicturePath($this->portfolio->getOwner(), "xsmall", true, true);
139 if ($ppic) {
140 $ppic = array_shift(explode("?", $ppic));
141 copy($ppic, $this->target_dir . "/" . basename($ppic));
142 }*/
143 }
144
145
149 public function exportHtml()
150 {
151 $this->initDirectories();
152
153 $this->export_util->exportSystemStyle();
154 $this->export_util->exportCOPageFiles(
155 $this->portfolio->getStyleSheetId(),
156 $this->portfolio->getType()
157 );
158
159 $this->exportBanner();
160
161 // export pages
162 $this->exportHTMLPages();
163
164 // add js/images/file to zip
165 // note: only files are still used for certificate files
166 $images = $files = $js_files = [];
167 foreach ($this->export_material as $items) {
168 $images = array_merge($images, $items["images"]);
169 $files = array_merge($files, $items["files"]);
170 $js_files = array_merge($js_files, $items["js"]);
171 }
172 foreach (array_unique($files) as $file) {
173 if (is_file($file)) {
174 copy($file, $this->target_dir . "/files/" . basename($file));
175 }
176 }
177
178 $this->export_util->exportResourceFiles();
179 $this->co_page_html_export->exportPageElements();
180
181 return $this->zipPackage();
182 }
183
189 public function zipPackage() : string
190 {
191 // zip it all
192 $date = time();
193 $zip_file = \ilExport::_getExportDirectory($this->portfolio->getId(), "html", "prtf") .
194 "/" . $date . "__" . IL_INST_ID . "__" .
195 $this->portfolio->getType() . "_" . $this->portfolio->getId() . ".zip";
196 \ilUtil::zip($this->target_dir, $zip_file);
197 \ilUtil::delDir($this->target_dir);
198
199 return $zip_file;
200 }
201
202
209 public function exportHTMLPages()
210 {
211 $pages = \ilPortfolioPage::getAllPortfolioPages($this->portfolio->getId());
212
213 $this->tabs = [];
214 foreach ($pages as $page) {
215 // substitute blog id with title
216 if ($page["type"] == \ilPortfolioPage::TYPE_BLOG) {
217 $page["title"] = \ilObjBlog::_lookupTitle((int) $page["title"]);
218 }
219
220 $this->tabs[$page["id"]] = $page["title"];
221 }
222
223 // for sub-pages, e.g. blog postings
224 $tpl_callback = [$this, "getInitialisedTemplate"];
225
226 $has_index = false;
227 foreach ($pages as $page) {
228 if (\ilPortfolioPage::_exists("prtf", $page["id"])) {
229 $this->active_tab = "user_page_" . $page["id"];
230
231 if ($page["type"] == \ilPortfolioPage::TYPE_BLOG) {
232 $link_template = "prtf_" . $page["id"] . "_bl{TYPE}_{ID}.html";
233
234 $blog_gui = new \ilObjBlogGUI((int) $page["title"], \ilObject2GUI::WORKSPACE_OBJECT_ID);
235 $blog_export = new BlogHtmlExport($blog_gui, $this->export_dir, $this->sub_dir, false);
236 $blog_export->exportHTMLPages($link_template, $tpl_callback, $this->co_page_html_export, "prtf_" . $page["id"] . ".html");
237 } else {
238 $tpl = $this->getInitialisedTemplate();
239 $tpl->setContent($this->renderPage($page["id"]));
240 $this->writeExportFile("prtf_" . $page["id"] . ".html", $tpl->printToString());
241 $this->co_page_html_export->collectPageElements("prtf:pg", $page["id"]);
242 }
243
244 if (!$has_index) {
245 if (is_file($this->target_dir . "/prtf_" . $page["id"] . ".html")) { // #20144
246 copy(
247 $this->target_dir . "/prtf_" . $page["id"] . ".html",
248 $this->target_dir . "/index.html"
249 );
250 $has_index = true;
251 }
252 }
253 }
254 }
255 }
256
261 public function getInitialisedTemplate(array $a_js_files = []) : \ilGlobalPageTemplate
262 {
263 global $DIC;
264
265 $this->global_screen->layout()->meta()->reset();
266
267 $location_stylesheet = \ilUtil::getStyleSheetLocation();
268 $this->global_screen->layout()->meta()->addCss($location_stylesheet);
269 $this->global_screen->layout()->meta()->addCss(
270 \ilObjStyleSheet::getContentStylePath($this->portfolio->getStyleSheetId())
271 );
273
274 // js files
275 foreach ($a_js_files as $js_file) {
276 $this->global_screen->layout()->meta()->addJs($js_file);
277 }
278
279 $tabs = $DIC->tabs();
280 $tabs->clearTargets();
281 $tabs->clearSubTabs();
282 if (is_array($this->tabs)) {
283 foreach ($this->tabs as $id => $caption) {
284 $tabs->addTab("user_page_" . $id, $caption, "prtf_" . $id . ".html");
285 }
286
287 $tabs->activateTab($this->active_tab);
288 }
289
290
291 $tpl = new \ilGlobalPageTemplate($DIC->globalScreen(), $DIC->ui(), $DIC->http());
292
293 $this->co_page_html_export->getPreparedMainTemplate($tpl);
294
295 $tpl->setTitle($this->portfolio->getTitle());
296
297 return $tpl;
298 }
299
303 public function writeExportFile($a_file, $content)
304 {
305 $file = $this->target_dir . "/" . $a_file;
306 // return if file is already existing
307 if (@is_file($file)) {
308 return;
309 }
310
311 file_put_contents($file, $content);
312
313 return $file;
314 }
315
322 public function renderPage(string $a_post_id)
323 {
324 // page
325 $pgui = new \ilPortfolioPageGUI($this->portfolio->getId(), $a_post_id);
326 $pgui->setOutputMode("offline");
327 $pgui->setFullscreenLink("fullscreen.html"); // #12930 - see page.xsl
328 $page_content = $pgui->showPage();
329
330 $ep_tpl = new \ilTemplate(
331 "tpl.export_page.html",
332 true,
333 true,
334 "Modules/Portfolio"
335 );
336 $ep_tpl->setVariable("PAGE_CONTENT", $page_content);
337
338 $material = $pgui->getExportMaterial();
339 $this->export_material[] = $material;
340
341 return $ep_tpl->get();
342 }
343}
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.
__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 ...
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$DIC
Definition: xapitoken.php:46