ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilPortfolioHTMLExport.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
13{
14 protected $portfolio_gui;
16
22 public function __construct($a_portfolio_gui, $a_object)
23 {
24 $this->portfolio_gui = $a_portfolio_gui;
25 $this->object = $a_object;
26 $this->export_material = array(); // #16571
27 }
28
35 public function buildExportFile()
36 {
37 // create export file
38 include_once("./Services/Export/classes/class.ilExport.php");
39 ilExport::_createExportDirectory($this->object->getId(), "html", "prtf");
40 $exp_dir = ilExport::_getExportDirectory($this->object->getId(), "html", "prtf");
41
42 $this->subdir = $this->object->getType() . "_" . $this->object->getId();
43 $this->export_dir = $exp_dir . "/" . $this->subdir;
44
45 // initialize temporary target directory
46 ilUtil::delDir($this->export_dir);
47 ilUtil::makeDir($this->export_dir);
48
49 // system style html exporter
50 include_once("./Services/Style/System/classes/class.ilSystemStyleHTMLExport.php");
51 $this->sys_style_html_export = new ilSystemStyleHTMLExport($this->export_dir);
52 // $this->sys_style_html_export->addImage("icon_prtf.svg");
53 $this->sys_style_html_export->export();
54
55 // init co page html exporter
56 include_once("./Services/COPage/classes/class.ilCOPageHTMLExport.php");
57 $this->co_page_html_export = new ilCOPageHTMLExport($this->export_dir);
58 $this->co_page_html_export->setContentStyleId(ilObjStyleSheet::getEffectiveContentStyleId(
59 $this->object->getStyleSheetId(),
60 $this->object->getType()
61 ));
62 $this->co_page_html_export->createDirectories();
63 $this->co_page_html_export->exportStyles();
64 $this->co_page_html_export->exportSupportScripts();
65
66 // banner
67 $prfa_set = new ilSetting("prfa");
68 if ($prfa_set->get("banner")) {
69 $banner = $this->object->getImageFullPath();
70 if ($banner) { // #16096
71 copy($banner, $this->export_dir . "/" . basename($banner));
72 }
73 }
74 // page element: profile picture
75 $ppic = ilObjUser::_getPersonalPicturePath($this->object->getOwner(), "big", true, true);
76 if ($ppic) {
77 $ppic = array_shift(explode("?", $ppic));
78 copy($ppic, $this->export_dir . "/" . basename($ppic));
79 }
80 // header image: profile picture
81 $ppic = ilObjUser::_getPersonalPicturePath($this->object->getOwner(), "xsmall", true, true);
82 if ($ppic) {
83 $ppic = array_shift(explode("?", $ppic));
84 copy($ppic, $this->export_dir . "/" . basename($ppic));
85 }
86
87 // export pages
88 $this->exportHTMLPages();
89
90 // add js/images/file to zip
91 $images = $files = $js_files = array();
92 include_once("./Services/UICore/classes/class.ilUIFramework.php");
93 $js_files = ilUIFramework::getJSFiles();
94 foreach ($this->export_material as $items) {
95 $images = array_merge($images, $items["images"]);
96 $files = array_merge($files, $items["files"]);
97 $js_files = array_merge($js_files, $items["js"]);
98 }
99 foreach (array_unique($images) as $image) {
100 if (is_file($image)) {
101 copy($image, $this->export_dir . "/images/" . basename($image));
102 }
103 }
104 foreach (array_unique($js_files) as $js_file) {
105 if (is_file($js_file)) {
106 copy($js_file, $this->export_dir . "/js/" . basename($js_file));
107 }
108 }
109 foreach (array_unique($files) as $file) {
110 if (is_file($file)) {
111 copy($file, $this->export_dir . "/files/" . basename($file));
112 }
113 }
114
115 // zip everything
116 if (true) {
117 // zip it all
118 $date = time();
119 $zip_file = ilExport::_getExportDirectory($this->object->getId(), "html", "prtf") .
120 "/" . $date . "__" . IL_INST_ID . "__" .
121 $this->object->getType() . "_" . $this->object->getId() . ".zip";
122 ilUtil::zip($this->export_dir, $zip_file);
123 ilUtil::delDir($this->export_dir);
124 }
125
126 return $zip_file;
127 }
128
132 public function exportHTMLPages()
133 {
134 require_once "Modules/Portfolio/classes/class.ilPortfolioPage.php";
135 $pages = ilPortfolioPage::getAllPortfolioPages($this->object->getId());
136
137 $this->tabs = array();
138 foreach ($pages as $page) {
139 // substitute blog id with title
140 if ($page["type"] == ilPortfolioPage::TYPE_BLOG) {
141 include_once "Modules/Blog/classes/class.ilObjBlog.php";
142 $page["title"] = ilObjBlog::_lookupTitle((int) $page["title"]);
143 }
144
145 $this->tabs[$page["id"]] = $page["title"];
146 }
147
148 // for sub-pages, e.g. blog postings
149 $tpl_callback = array($this, "buildExportTemplate");
150
151 include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
152 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
153 include_once("./Modules/Portfolio/classes/class.ilPortfolioPage.php");
154 $has_index = false;
155 foreach ($pages as $page) {
156 if (ilPortfolioPage::_exists("prtf", $page["id"])) {
157 $this->active_tab = "user_page_" . $page["id"];
158
159 if ($page["type"] == ilPortfolioPage::TYPE_BLOG) {
160 $link_template = "prtf_" . $page["id"] . "_bl{TYPE}_{ID}.html";
161
162 include_once "Modules/Blog/classes/class.ilObjBlogGUI.php";
163 $blog = new ilObjBlogGUI((int) $page["title"], ilObject2GUI::WORKSPACE_OBJECT_ID);
164 $blog->exportHTMLPages($this->export_dir . "/", $link_template, $tpl_callback, $this->co_page_html_export, "prtf_" . $page["id"] . ".html");
165 } else {
166 $this->exportPageHTML($page["id"]);
167 $this->co_page_html_export->collectPageElements("prtf:pg", $page["id"]);
168 }
169
170 if (!$has_index) {
171 if (is_file($this->export_dir . "/prtf_" . $page["id"] . ".html")) { // #20144
172 copy(
173 $this->export_dir . "/prtf_" . $page["id"] . ".html",
174 $this->export_dir . "/index.html"
175 );
176 $has_index = true;
177 }
178 }
179 }
180 }
181 $this->co_page_html_export->exportPageElements();
182 }
183
184 public function buildExportTemplate(array $a_js_files = null)
185 {
186 global $DIC;
187
188 $ilTabs = $DIC->tabs();
189
190 $this->tpl = $this->co_page_html_export->getPreparedMainTemplate();
191 $this->tpl->getStandardTemplate();
192 $this->tpl->addOnLoadCode('il.Tooltip.init();', 3);
193
194 // js files
195 if (is_array($a_js_files)) {
196 foreach ($a_js_files as $js_file) {
197 $this->tpl->setCurrentBlock("js_file");
198 $this->tpl->setVariable("JS_FILE", !stristr($js_file, "://")
199 ? "./js/" . basename($js_file)
200 : $js_file);
201 $this->tpl->parseCurrentBlock();
202 }
203 }
204
205 // workaround
206 $this->tpl->setVariable("MAINMENU", "<div style='min-height:40px;'></div>");
207 $this->tpl->setTitle($this->object->getTitle());
208
209 $ilTabs->clearTargets();
210 if ($this->tabs) {
211 foreach ($this->tabs as $id => $caption) {
212 $ilTabs->addTab("user_page_" . $id, $caption, "prtf_" . $id . ".html");
213 }
214
215 $ilTabs->activateTab($this->active_tab);
216 }
217
218 include_once "Modules/Portfolio/classes/class.ilObjPortfolioGUI.php";
219 ilObjPortfolioGUI::renderFullscreenHeader($this->object, $this->tpl, $this->object->getOwner(), true);
220
221 return $this->tpl;
222 }
223
224 public function writeExportFile($a_file, $a_content, $a_onload = null, $a_js_files = null)
225 {
226 $file = $this->export_dir . "/" . $a_file;
227 // return if file is already existing
228 if (@is_file($file)) {
229 return;
230 }
231
232 // export template: page content
233 $ep_tpl = new ilTemplate(
234 "tpl.export_page.html",
235 true,
236 true,
237 "Modules/Portfolio"
238 );
239 $ep_tpl->setVariable("PAGE_CONTENT", $a_content);
240
241 $this->buildExportTemplate($a_js_files);
242 $this->tpl->setContent($ep_tpl->get());
243
244 if (is_array($a_onload)) {
245 foreach ($a_onload as $item) {
246 $this->tpl->addOnLoadCode($item);
247 }
248 }
249
250
251 $content = $this->tpl->get(
252 "DEFAULT",
253 false,
254 false,
255 false,
256 true,
257 true,
258 true
259 );
260
261 // open file
262 if (!file_put_contents($file, $content)) {
263 die("<b>Error</b>: Could not open \"" . $file . "\" for writing" .
264 " in <b>" . __FILE__ . "</b> on line <b>" . __LINE__ . "</b><br />");
265 }
266
267 // set file permissions
268 chmod($file, 0770);
269
270 return $file;
271 }
272
276 public function exportPageHTML($a_post_id)
277 {
278 // page
279 include_once "Modules/Portfolio/classes/class.ilPortfolioPageGUI.php";
280 $pgui = new ilPortfolioPageGUI($this->object->getId(), $a_post_id);
281 $pgui->setOutputMode("offline");
282 $pgui->setFullscreenLink("fullscreen.html"); // #12930 - see page.xsl
283 $page_content = $pgui->showPage();
284
285 $material = $pgui->getExportMaterial();
286 $this->export_material[] = $material;
287
288 include_once("./Services/UICore/classes/class.ilUIFramework.php");
289 $js_files = array_merge(ilUIFramework::getJSFiles(), $material["js"]);
290
291 $this->writeExportFile("prtf_" . $a_post_id . ".html", $page_content, $pgui->getJsOnloadCode(), $js_files);
292 }
293}
$tpl
Definition: ilias.php:10
An exception for terminatinating execution or to throw for unit testing.
HTML export class for pages.
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 ilObjBlogGUI.
static renderFullscreenHeader($a_portfolio, $a_tpl, $a_user_id, $a_export=false)
Render banner, user name.
static getEffectiveContentStyleId($a_style_id, $a_type="")
Get effective Style Id.
static _lookupTitle($a_id)
lookup object title
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
Portfolio HTML exporter class.
buildExportTemplate(array $a_js_files=null)
__construct($a_portfolio_gui, $a_object)
Constructor.
exportPageHTML($a_post_id)
Export page html.
writeExportFile($a_file, $a_content, $a_onload=null, $a_js_files=null)
Portfolio page gui class.
static getAllPortfolioPages($a_portfolio_id)
Get pages of portfolio.
ILIAS Setting Class.
HTML export class for system styles.
special template class to simplify handling of ITX/PEAR
static getJSFiles()
Get javascript files.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
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(!array_key_exists('StateId', $_REQUEST)) $id
$files
Definition: metarefresh.php:49
global $DIC
Definition: saml.php:7
$a_content
Definition: workflow.php:93