ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
WikiHtmlExport.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
13{
17 protected $db;
18
22 protected $user;
23
27 protected $lng;
28
32 protected $tabs;
33
37 protected $wiki;
38
39 const MODE_DEFAULT = "html";
40 const MODE_USER = "user_html";
41
46
50 protected $log;
51
56
60 protected $export_dir;
61
65 protected $global_screen;
66
70 protected $main_tpl;
71
75 protected $user_html_exp;
76
82 public function __construct(\ilObjWiki $a_wiki)
83 {
84 global $DIC;
85
86 $this->db = $DIC->database();
87 $this->user = $DIC->user();
88 $this->lng = $DIC->language();
89 $this->tabs = $DIC->tabs();
90 $this->wiki = $a_wiki;
91 $this->log = \ilLoggerFactory::getLogger('wiki');
92 $this->global_screen = $DIC->globalScreen();
93 $this->main_tpl = $DIC->ui()->mainTemplate();
94 }
95
101 public function setMode(string $a_val)
102 {
103 $this->mode = $a_val;
104 }
105
111 public function getMode() : string
112 {
113 return $this->mode;
114 }
115
123 public function buildExportFile()
124 {
128
129 $this->log->debug("buildExportFile...");
130 //init the mathjax rendering for HTML export
131 include_once './Services/MathJax/classes/class.ilMathJax.php';
133
134 if ($this->getMode() == self::MODE_USER) {
135 include_once("./Modules/Wiki/classes/class.ilWikiUserHTMLExport.php");
136 $this->user_html_exp = new \ilWikiUserHTMLExport($this->wiki, $ilDB, $ilUser);
137 }
138
139 $ascii_name = str_replace(" ", "_", \ilUtil::getASCIIFilename($this->wiki->getTitle()));
140
141 // create export file
142 include_once("./Services/Export/classes/class.ilExport.php");
143 \ilExport::_createExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
144 $exp_dir =
145 \ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
146
147 if ($this->getMode() == self::MODE_USER) {
148 \ilUtil::delDir($exp_dir, true);
149 }
150
151 if ($this->getMode() == self::MODE_USER) {
152 $subdir = $ascii_name;
153 } else {
154 $subdir = $this->wiki->getType() . "_" . $this->wiki->getId();
155 }
156 $this->export_dir = $exp_dir . "/" . $subdir;
157
158 $this->export_util = new \ILIAS\Services\Export\HTML\Util($exp_dir, $subdir);
159
160 // initialize temporary target directory
161 \ilUtil::delDir($this->export_dir);
162 \ilUtil::makeDir($this->export_dir);
163
164 $this->log->debug("export directory: " . $this->export_dir);
165
166
167 $this->export_util->exportSystemStyle();
168 $this->export_util->exportCOPageFiles($this->wiki->getStyleSheetId(), "wiki");
169
170 $this->co_page_html_export = new \ilCOPageHTMLExport($this->export_dir);
171 $this->co_page_html_export->setContentStyleId(\ilObjStyleSheet::getEffectiveContentStyleId(
172 $this->wiki->getStyleSheetId(),
173 "wiki"
174 ));
175
176 // export pages
177 $this->log->debug("export pages");
178 $global_screen->tool()->context()->current()->addAdditionalData(\ilHTMLExportViewLayoutProvider::HTML_EXPORT_RENDERING, true);
179 $this->exportHTMLPages();
180
181 $this->export_util->exportResourceFiles($global_screen, $this->export_dir);
182
183 $date = time();
184 $zip_file_name = ($this->getMode() == self::MODE_USER)
185 ? $ascii_name . ".zip"
186 : $date . "__" . IL_INST_ID . "__" . $this->wiki->getType() . "_" . $this->wiki->getId() . ".zip";
187
188 // zip everything
189 if (true) {
190 // zip it all
191 $zip_file = \ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki") .
192 "/" . $zip_file_name;
193 $this->log->debug("zip: " . $zip_file);
194 \ilUtil::zip($this->export_dir, $zip_file);
195 \ilUtil::delDir($this->export_dir);
196 }
197 return $zip_file;
198 }
199
205 public function exportHTMLPages()
206 {
207 global $DIC;
208
209 $pages = \ilWikiPage::getAllWikiPages($this->wiki->getId());
210
211 $cnt = 0;
212
213 foreach ($pages as $page) {
214 $tpl = new \ilGlobalPageTemplate($DIC->globalScreen(), $DIC->ui(), $DIC->http());
215 $this->co_page_html_export->getPreparedMainTemplate($tpl);
216 $this->log->debug("page: " . $page["id"]);
217 if (\ilWikiPage::_exists("wpg", $page["id"])) {
218 $this->log->debug("export page");
219 $this->exportPageHTML($page["id"], $tpl);
220 $this->log->debug("collect page elements");
221 $this->co_page_html_export->collectPageElements("wpg:pg", $page["id"]);
222 }
223
224 if ($this->getMode() == self::MODE_USER) {
225 $cnt++;
226 $this->log->debug("update status: " . $cnt);
227 $this->user_html_exp->updateStatus((int) (50 / count($pages) * $cnt), \ilWikiUserHTMLExport::RUNNING);
228 }
229 }
230 $this->co_page_html_export->exportPageElements($this->updateUserHTMLStatusForPageElements);
231 }
232
238 public function updateUserHTMLStatusForPageElements($a_total, $a_cnt)
239 {
240 if ($this->getMode() == self::MODE_USER) {
241 $this->user_html_exp->updateStatus((int) 50 + (50 / count($a_total) * $a_cnt), \ilWikiUserHTMLExport::RUNNING);
242 }
243 }
244
245
252 public function exportPageHTML($a_page_id, \ilGlobalPageTemplate $tpl)
253 {
254 $this->log->debug("Export page:" . $a_page_id);
256 $ilTabs = $this->tabs;
257
258 $ilTabs->clearTargets();
259
260
261
262 //$this->tpl->loadStandardTemplate();
263 $file = $this->export_dir . "/wpg_" . $a_page_id . ".html";
264 // return if file is already existing
265 if (@is_file($file)) {
266 $this->log->debug("file already exists");
267 return;
268 }
269
270 // page
271 $this->log->debug("init page gui");
272 include_once("./Modules/Wiki/classes/class.ilWikiPageGUI.php");
273 $wpg_gui = new \ilWikiPageGUI($a_page_id);
274 $wpg_gui->setOutputMode("offline");
275 $page_content = $wpg_gui->showPage();
276
277 // export template: page content
278 $this->log->debug("init page gui");
279 $ep_tpl = new \ilTemplate(
280 "tpl.export_page.html",
281 true,
282 true,
283 "Modules/Wiki"
284 );
285 $ep_tpl->setVariable("PAGE_CONTENT", $page_content);
286
287 // export template: right content
288 include_once("./Modules/Wiki/classes/class.ilWikiImportantPagesBlockGUI.php");
289 $bl = new \ilWikiImportantPagesBlockGUI();
290 $tpl->setRightContent($bl->getHTML(true));
291
292
293 $this->log->debug("set title");
294 $tpl->setTitle($this->wiki->getTitle());
295 $tpl->setTitleIcon(
296 \ilUtil::getImagePath("icon_wiki.svg"),
297 $lng->txt("obj_wiki")
298 );
299
300 $tpl->setContent($ep_tpl->get());
301 $content = $tpl->printToString();
302
303 // open file
304 $this->log->debug("write file: " . $file);
305 if (!($fp = @fopen($file, "w+"))) {
306 $this->log->error("Could not open " . $file . " for writing.");
307 include_once("./Modules/Wiki/exceptions/class.ilWikiExportException.php");
308 throw new \ilWikiExportException("Could not open \"" . $file . "\" for writing.");
309 }
310
311 // set file permissions
312 $this->log->debug("set permissions");
313 chmod($file, 0770);
314
315 // write xml data into the file
316 fwrite($fp, $content);
317
318 // close file
319 fclose($fp);
320
321 if ($this->wiki->getStartPage() == $wpg_gui->getPageObject()->getTitle()) {
322 copy($file, $this->export_dir . "/index.html");
323 }
324 }
325
331 public function getUserExportFile()
332 {
333 include_once("./Services/Export/classes/class.ilExport.php");
334 $exp_dir =
335 \ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
336 $this->log->debug("dir: " . $exp_dir);
337 foreach (new \DirectoryIterator($exp_dir) as $fileInfo) {
338 $this->log->debug("file: " . $fileInfo->getFilename());
339 if (pathinfo($fileInfo->getFilename(), PATHINFO_EXTENSION) == "zip") {
340 $this->log->debug("return: " . $exp_dir . "/" . $fileInfo->getFilename());
341 return $exp_dir . "/" . $fileInfo->getFilename();
342 }
343 }
344 return "";
345 }
346}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
Wiki HTML exporter class.
updateUserHTMLStatusForPageElements($a_total, $a_cnt)
Callback for updating the export status during elements export (media objects, files,...
exportPageHTML($a_page_id, \ilGlobalPageTemplate $tpl)
Export page html.
buildExportFile()
Build export file.
setMode(string $a_val)
Set mode.
getUserExportFile()
Get user export file.
__construct(\ilObjWiki $a_wiki)
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.
static getLogger($a_component_id)
Get component logger.
static getInstance()
Singleton: get instance.
const PURPOSE_EXPORT
static getEffectiveContentStyleId($a_style_id, $a_type="")
Get effective Style Id.
Class ilObjWiki.
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
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 getASCIIFilename($a_filename)
convert utf8 to ascii filename
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static getAllWikiPages($a_wiki_id)
Get all pages of wiki.
global $ilDB
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46