ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilWikiHTMLExport.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
16 protected $db;
17
21 protected $user;
22
26 protected $lng;
27
31 protected $tabs;
32
33 protected $wiki;
34 const MODE_DEFAULT = "html";
35 const MODE_USER = "user_html";
37
41 protected $log;
42
49 public function __construct($a_wiki)
50 {
51 global $DIC;
52
53 $this->db = $DIC->database();
54 $this->user = $DIC->user();
55 $this->lng = $DIC->language();
56 $this->tabs = $DIC->tabs();
57 $this->wiki = $a_wiki;
58 $this->log = ilLoggerFactory::getLogger('wiki');
59 }
60
66 public function setMode($a_val)
67 {
68 $this->mode = $a_val;
69 }
70
76 public function getMode()
77 {
78 return $this->mode;
79 }
80
87 public function buildExportFile()
88 {
89 $this->log->debug("buildExportFile...");
90 //init the mathjax rendering for HTML export
91 include_once './Services/MathJax/classes/class.ilMathJax.php';
93
94 if ($this->getMode() == self::MODE_USER) {
97 include_once("./Modules/Wiki/classes/class.ilWikiUserHTMLExport.php");
98 $this->user_html_exp = new ilWikiUserHTMLExport($this->wiki, $ilDB, $ilUser);
99 }
100
101 $ascii_name = str_replace(" ", "_", ilUtil::getASCIIFilename($this->wiki->getTitle()));
102
103 // create export file
104 include_once("./Services/Export/classes/class.ilExport.php");
105 ilExport::_createExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
106 $exp_dir =
107 ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
108
109 if ($this->getMode() == self::MODE_USER) {
110 ilUtil::delDir($exp_dir, true);
111 }
112
113 if ($this->getMode() == self::MODE_USER) {
114 $this->subdir = $ascii_name;
115 } else {
116 $this->subdir = $this->wiki->getType() . "_" . $this->wiki->getId();
117 }
118 $this->export_dir = $exp_dir . "/" . $this->subdir;
119 //echo "+".$this->export_dir."+";
120 // initialize temporary target directory
121 ilUtil::delDir($this->export_dir);
122 ilUtil::makeDir($this->export_dir);
123
124 $this->log->debug("export directory: " . $this->export_dir);
125
126 // system style html exporter
127 include_once("./Services/Style/System/classes/class.ilSystemStyleHTMLExport.php");
128 $this->sys_style_html_export = new ilSystemStyleHTMLExport($this->export_dir);
129 $this->sys_style_html_export->addImage("icon_wiki.svg");
130 $this->sys_style_html_export->export();
131
132 // init co page html exporter
133 include_once("./Services/COPage/classes/class.ilCOPageHTMLExport.php");
134 $this->co_page_html_export = new ilCOPageHTMLExport($this->export_dir);
135 $this->co_page_html_export->setContentStyleId(
137 $this->wiki->getStyleSheetId(),
138 $this->wiki->getType()
139 )
140 );
141 $this->co_page_html_export->createDirectories();
142 $this->co_page_html_export->exportStyles();
143 $this->co_page_html_export->exportSupportScripts();
144
145 // export pages
146 $this->log->debug("export pages");
147 $this->exportHTMLPages();
148
149 $date = time();
150 $zip_file_name = ($this->getMode() == self::MODE_USER)
151 ? $ascii_name . ".zip"
152 : $date . "__" . IL_INST_ID . "__" . $this->wiki->getType() . "_" . $this->wiki->getId() . ".zip";
153
154 // zip everything
155 if (true) {
156 // zip it all
157 $zip_file = ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki") .
158 "/" . $zip_file_name;
159 $this->log->debug("zip: " . $zip_file);
160 ilUtil::zip($this->export_dir, $zip_file);
161 ilUtil::delDir($this->export_dir);
162 }
163 return $zip_file;
164 }
165
169 public function exportHTMLPages()
170 {
171 $pages = ilWikiPage::getAllWikiPages($this->wiki->getId());
172
173 include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
174 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
175 $cnt = 0;
176 foreach ($pages as $page) {
177 $this->log->debug("page: " . $page["id"]);
178 if (ilWikiPage::_exists("wpg", $page["id"])) {
179 $this->log->debug("export page");
180 $this->exportPageHTML($page["id"]);
181 $this->log->debug("collect page elements");
182 $this->co_page_html_export->collectPageElements("wpg:pg", $page["id"]);
183 }
184
185 if ($this->getMode() == self::MODE_USER) {
186 $cnt++;
187 $this->log->debug("update status: " . $cnt);
188 $this->user_html_exp->updateStatus((int) (50 / count($pages) * $cnt), ilWikiUserHTMLExport::RUNNING);
189 }
190 }
191 $this->co_page_html_export->exportPageElements($this->updateUserHTMLStatusForPageElements);
192 }
193
199 public function updateUserHTMLStatusForPageElements($a_total, $a_cnt)
200 {
201 if ($this->getMode() == self::MODE_USER) {
202 $this->user_html_exp->updateStatus((int) 50 + (50 / count($a_total) * $a_cnt), ilWikiUserHTMLExport::RUNNING);
203 }
204 }
205
206
210 public function exportPageHTML($a_page_id)
211 {
214 $ilTabs = $this->tabs;
215
216 $ilTabs->clearTargets();
217
218 $this->tpl = $this->co_page_html_export->getPreparedMainTemplate();
219
220 $this->tpl->getStandardTemplate();
221 $file = $this->export_dir . "/wpg_" . $a_page_id . ".html";
222 // return if file is already existing
223 if (@is_file($file)) {
224 $this->log->debug("file already exists");
225 return;
226 }
227
228 // page
229 $this->log->debug("init page gui");
230 include_once("./Modules/Wiki/classes/class.ilWikiPageGUI.php");
231 $wpg_gui = new ilWikiPageGUI($a_page_id);
232 $wpg_gui->setOutputMode("offline");
233 $page_content = $wpg_gui->showPage();
234
235 // export template: page content
236 $this->log->debug("init page gui");
237 $ep_tpl = new ilTemplate(
238 "tpl.export_page.html",
239 true,
240 true,
241 "Modules/Wiki"
242 );
243 $ep_tpl->setVariable("PAGE_CONTENT", $page_content);
244
245 // export template: right content
246 include_once("./Modules/Wiki/classes/class.ilWikiImportantPagesBlockGUI.php");
248 $ep_tpl->setVariable("RIGHT_CONTENT", $bl->getHTML(true));
249
250 // workaround
251 // $this->tpl->setVariable("MAINMENU", "<div style='min-height:40px;'></div>");
252 $this->tpl->setVariable("MAINMENU", "");
253
254 $this->log->debug("set title");
255 $this->tpl->setTitle($this->wiki->getTitle());
256 $this->tpl->setTitleIcon(
257 "./images/icon_wiki.svg",
258 $lng->txt("obj_wiki")
259 );
260
261 $this->tpl->setContent($ep_tpl->get());
262 //$this->tpl->fillMainContent();
263 $content = $this->tpl->get(
264 "DEFAULT",
265 false,
266 false,
267 false,
268 true,
269 true,
270 true
271 );
272
273 //echo htmlentities($content); exit;
274 // open file
275 $this->log->debug("write file: " . $file);
276 if (!($fp = @fopen($file, "w+"))) {
277 $this->log->error("Could not open " . $file . " for writing.");
278 include_once("./Modules/Wiki/exceptions/class.ilWikiExportException.php");
279 throw new ilWikiExportException("Could not open \"" . $file . "\" for writing.");
280 }
281
282 // set file permissions
283 $this->log->debug("set permissions");
284 chmod($file, 0770);
285
286 // write xml data into the file
287 fwrite($fp, $content);
288
289 // close file
290 fclose($fp);
291
292 if ($this->wiki->getStartPage() == $wpg_gui->getPageObject()->getTitle()) {
293 copy($file, $this->export_dir . "/index.html");
294 }
295 }
296
303 public function getUserExportFile()
304 {
305 include_once("./Services/Export/classes/class.ilExport.php");
306 $exp_dir =
307 ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
308 $this->log->debug("dir: " . $exp_dir);
309 foreach (new DirectoryIterator($exp_dir) as $fileInfo) {
310 $this->log->debug("file: " . $fileInfo->getFilename());
311 if (pathinfo($fileInfo->getFilename(), PATHINFO_EXTENSION) == "zip") {
312 $this->log->debug("return: " . $exp_dir . "/" . $fileInfo->getFilename());
313 return $exp_dir . "/" . $fileInfo->getFilename();
314 }
315 }
316 return false;
317 }
318}
user()
Definition: user.php:4
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="")
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.
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
HTML export class for system styles.
special template class to simplify handling of ITX/PEAR
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 makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
Base exception class for wikis.
Wiki HTML exporter class.
updateUserHTMLStatusForPageElements($a_total, $a_cnt)
Callback for updating the export status during elements export (media objects, files,...
setMode($a_val)
Set mode.
__construct($a_wiki)
Constructor.
buildExportFile()
Build export file.
exportPageHTML($a_page_id)
Export page html.
exportHTMLPages()
Export all pages.
getUserExportFile()
Get user export file.
Class ilWikiPage GUI class.
static getAllWikiPages($a_wiki_id)
Get all pages of wiki.
Class manages user html export.
global $DIC
Definition: saml.php:7
global $ilDB
$ilUser
Definition: imgupload.php:18