ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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";
36  protected $mode = self::MODE_DEFAULT;
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) {
95  $ilDB = $this->db;
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  }
164 
168  public function exportHTMLPages()
169  {
170  $pages = ilWikiPage::getAllWikiPages($this->wiki->getId());
171 
172  include_once("./Services/COPage/classes/class.ilPageContentUsage.php");
173  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
174  $cnt = 0;
175  foreach ($pages as $page) {
176  $this->log->debug("page: " . $page["id"]);
177  if (ilWikiPage::_exists("wpg", $page["id"])) {
178  $this->log->debug("export page");
179  $this->exportPageHTML($page["id"]);
180  $this->log->debug("collect page elements");
181  $this->co_page_html_export->collectPageElements("wpg:pg", $page["id"]);
182  }
183 
184  if ($this->getMode() == self::MODE_USER) {
185  $cnt++;
186  $this->log->debug("update status: " . $cnt);
187  $this->user_html_exp->updateStatus((int) (50 / count($pages) * $cnt), ilWikiUserHTMLExport::RUNNING);
188  }
189  }
190  $this->co_page_html_export->exportPageElements($this->updateUserHTMLStatusForPageElements);
191  }
192 
198  public function updateUserHTMLStatusForPageElements($a_total, $a_cnt)
199  {
200  if ($this->getMode() == self::MODE_USER) {
201  $this->user_html_exp->updateStatus((int) 50 + (50 / count($a_total) * $a_cnt), ilWikiUserHTMLExport::RUNNING);
202  }
203  }
204 
205 
209  public function exportPageHTML($a_page_id)
210  {
212  $lng = $this->lng;
213  $ilTabs = $this->tabs;
214 
215  $ilTabs->clearTargets();
216 
217  $this->tpl = $this->co_page_html_export->getPreparedMainTemplate();
218 
219  $this->tpl->getStandardTemplate();
220  $file = $this->export_dir . "/wpg_" . $a_page_id . ".html";
221  // return if file is already existing
222  if (@is_file($file)) {
223  $this->log->debug("file already exists");
224  return;
225  }
226 
227  // page
228  $this->log->debug("init page gui");
229  include_once("./Modules/Wiki/classes/class.ilWikiPageGUI.php");
230  $wpg_gui = new ilWikiPageGUI($a_page_id);
231  $wpg_gui->setOutputMode("offline");
232  $page_content = $wpg_gui->showPage();
233 
234  // export template: page content
235  $this->log->debug("init page gui");
236  $ep_tpl = new ilTemplate(
237  "tpl.export_page.html",
238  true,
239  true,
240  "Modules/Wiki"
241  );
242  $ep_tpl->setVariable("PAGE_CONTENT", $page_content);
243 
244  // export template: right content
245  include_once("./Modules/Wiki/classes/class.ilWikiImportantPagesBlockGUI.php");
246  $bl = new ilWikiImportantPagesBlockGUI();
247  $ep_tpl->setVariable("RIGHT_CONTENT", $bl->getHTML(true));
248 
249  // workaround
250  // $this->tpl->setVariable("MAINMENU", "<div style='min-height:40px;'></div>");
251  $this->tpl->setVariable("MAINMENU", "");
252 
253  $this->log->debug("set title");
254  $this->tpl->setTitle($this->wiki->getTitle());
255  $this->tpl->setTitleIcon(
256  "./images/icon_wiki.svg",
257  $lng->txt("obj_wiki")
258  );
259 
260  $this->tpl->setContent($ep_tpl->get());
261  //$this->tpl->fillMainContent();
262  $content = $this->tpl->get(
263  "DEFAULT",
264  false,
265  false,
266  false,
267  true,
268  true,
269  true
270  );
271 
272  //echo htmlentities($content); exit;
273  // open file
274  $this->log->debug("write file: " . $file);
275  if (!($fp = @fopen($file, "w+"))) {
276  $this->log->error("Could not open " . $file . " for writing.");
277  include_once("./Modules/Wiki/exceptions/class.ilWikiExportException.php");
278  throw new ilWikiExportException("Could not open \"" . $file . "\" for writing.");
279  }
280 
281  // set file permissions
282  $this->log->debug("set permissions");
283  chmod($file, 0770);
284 
285  // write xml data into the file
286  fwrite($fp, $content);
287 
288  // close file
289  fclose($fp);
290 
291  if ($this->wiki->getStartPage() == $wpg_gui->getPageObject()->getTitle()) {
292  copy($file, $this->export_dir . "/index.html");
293  }
294  }
295 
302  public function getUserExportFile()
303  {
304  include_once("./Services/Export/classes/class.ilExport.php");
305  $exp_dir =
306  ilExport::_getExportDirectory($this->wiki->getId(), $this->getMode(), "wiki");
307  $this->log->debug("dir: " . $exp_dir);
308  foreach (new DirectoryIterator($exp_dir) as $fileInfo) {
309  $this->log->debug("file: " . $fileInfo->getFilename());
310  if (pathinfo($fileInfo->getFilename(), PATHINFO_EXTENSION) == "zip") {
311  $this->log->debug("return: " . $exp_dir . "/" . $fileInfo->getFilename());
312  return $exp_dir . "/" . $fileInfo->getFilename();
313  }
314  }
315  return false;
316  }
317 }
static _createExportDirectory($a_obj_id, $a_export_type="xml", $a_obj_type="")
static _exists($a_parent_type, $a_id, $a_lang="", $a_no_cache=false)
Checks whether page exists.
__construct($a_wiki)
Constructor.
Base exception class for wikis.
getUserExportFile()
Get user export file.
global $DIC
Definition: saml.php:7
HTML export class for pages.
exportHTMLPages()
Export all pages.
HTML export class for system styles.
updateUserHTMLStatusForPageElements($a_total, $a_cnt)
Callback for updating the export status during elements export (media objects, files, ...)
static getASCIIFilename($a_filename)
convert utf8 to ascii filename
user()
Definition: user.php:4
Class manages user html export.
special template class to simplify handling of ITX/PEAR
static getEffectiveContentStyleId($a_style_id, $a_type="")
Get effective Style Id.
Class ilWikiPage GUI class.
$ilUser
Definition: imgupload.php:18
static zip($a_dir, $a_file, $compress_content=false)
zips given directory/file into given zip.file
const PURPOSE_EXPORT
static getAllWikiPages($a_wiki_id)
Get all pages of wiki.
setMode($a_val)
Set mode.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
exportPageHTML($a_page_id)
Export page html.
buildExportFile()
Build export file.
static getInstance()
Singleton: get instance.
global $ilDB
Wiki HTML exporter class.
static _getExportDirectory($a_obj_id, $a_type="xml", $a_obj_type="", $a_entity="")
Get export directory for an repository object.
static getLogger($a_component_id)
Get component logger.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively